dsh-spec-collab 0.2.0 → 0.2.1
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/README.md +35 -0
- package/lib/client.js +790 -306
- package/lib/index.js +352 -46
- package/lib/types/client/SpecWorkbench.d.ts +17 -0
- package/lib/types/client/SpecWorkbench.d.ts.map +1 -1
- package/lib/types/client/review-anchors.d.ts +18 -0
- package/lib/types/client/review-anchors.d.ts.map +1 -0
- package/lib/types/client/workflow.d.ts +1 -0
- package/lib/types/client/workflow.d.ts.map +1 -1
- package/lib/types/index.d.ts +4 -0
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/prompts.d.ts +18 -0
- package/lib/types/prompts.d.ts.map +1 -0
- package/lib/types/protocol.d.ts +5 -0
- package/lib/types/protocol.d.ts.map +1 -1
- package/lib/types/review-context.d.ts +10 -1
- package/lib/types/review-context.d.ts.map +1 -1
- package/lib/types/review-runtime.d.ts +4 -1
- package/lib/types/review-runtime.d.ts.map +1 -1
- package/lib/types/workspace-context.d.ts +2 -0
- package/lib/types/workspace-context.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/client/SpecWorkbench.tsx +223 -33
- package/src/client/review-anchors.ts +87 -0
- package/src/client/workbench.module.css +112 -36
- package/src/client/workflow.ts +7 -7
- package/src/index.ts +21 -3
- package/src/prompts.ts +100 -0
- package/src/protocol.ts +2 -0
- package/src/review-context.ts +25 -7
- package/src/review-runtime.ts +53 -34
- package/src/tools.ts +3 -3
- package/src/workspace-context.ts +114 -0
package/lib/index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { homedir } from "node:os";
|
|
2
|
-
import { dirname, join, normalize, resolve } from "node:path";
|
|
2
|
+
import { dirname, extname, isAbsolute, join, normalize, relative, resolve } from "node:path";
|
|
3
3
|
import Schema from "schemastery";
|
|
4
4
|
import { createHash, randomUUID } from "node:crypto";
|
|
5
5
|
import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
6
6
|
import { execFileSync } from "node:child_process";
|
|
7
|
+
import { readFile, readdir, stat } from "node:fs/promises";
|
|
7
8
|
import { defineTool } from "@deepseek-ai/dsh-tools";
|
|
8
9
|
//#region src/git-store.ts
|
|
9
10
|
var VersionConflictError = class extends Error {
|
|
@@ -1060,6 +1061,101 @@ function readyMarkdown(view) {
|
|
|
1060
1061
|
].join("\n");
|
|
1061
1062
|
}
|
|
1062
1063
|
//#endregion
|
|
1064
|
+
//#region src/prompts.ts
|
|
1065
|
+
const DEFAULT_REVIEW_PROMPTS = {
|
|
1066
|
+
system: "本机已安装 dsh-spec-collab「AI 需求澄清与 Spec 共创工作台」。产品输入原始需求后,产品 AI 初审并生成结构化 Review Item,产品逐项回应,AI 二次审核并提出候选 patch;产品确认后进入产研与双方 AI 共审,最终通过 Ready 质量门输出 commit 绑定的 Ready Spec。正式 Spec 版本只存 Git+Markdown;AI 只能提出 Review Item、分析回复和候选 patch,不能确认产品/技术语义,也不能直接写 Git 或标记 Ready。该产品严格止于 Ready Spec,不执行代码开发、测试、worktree、部署或发布。使用 spec_list/spec_read 读取,spec_reply/spec_submit_review/spec_propose_patch 参与审核。",
|
|
1067
|
+
workspaceContext: [
|
|
1068
|
+
"## 本次审核必须使用的上下文",
|
|
1069
|
+
"DSH 工作区:`{{WORKSPACE_ID}}`。当前 AI session 必须挂载该工作区,不得创建未分组会话。",
|
|
1070
|
+
"工作区名称:{{WORKSPACE_TITLE}}",
|
|
1071
|
+
"工作区根目录:`{{WORKSPACE_PATH}}`",
|
|
1072
|
+
"",
|
|
1073
|
+
"开始审核前必须先实际读取工作区上下文,不能只读取 Spec:",
|
|
1074
|
+
"1. 检查工作区根目录,并读取存在的 AGENTS.md、CONTEXT.md、README/README.md 和 CONTRIBUTING.md。",
|
|
1075
|
+
"2. 读取存在的项目清单与构建入口,例如 package.json、pyproject.toml、Cargo.toml、go.mod、pom.xml 或构建脚本。",
|
|
1076
|
+
"3. 根据需求关键词定位相关代码、产品文档、测试和 Git 历史;结论引用具体文件路径及 commit 或其他可识别版本。",
|
|
1077
|
+
"4. 不得把“已绑定工作区”等同于“已读取上下文”。无法访问文件或历史时,明确说明并使用 TO_VERIFY。",
|
|
1078
|
+
"",
|
|
1079
|
+
"{{WORKSPACE_SNAPSHOT}}",
|
|
1080
|
+
"",
|
|
1081
|
+
"{{RESOURCE_INSTRUCTIONS}}"
|
|
1082
|
+
].join("\n"),
|
|
1083
|
+
resourceInstructions: ["{{RESOURCE_DETAILS}}", "任何已配置资源若在当前 Agent Preset 中不可用、无权限或读取失败,必须在结论中明确指出该资源并使用 TO_VERIFY;不得假装已经查询或把不可访问内容写成 FACT。"].join("\n"),
|
|
1084
|
+
common: [
|
|
1085
|
+
"所有面向用户的输出必须使用简体中文,包括 Review Item 的陈述、影响、问题、成熟度总结、候选 patch 摘要以及评论分析回复。仅保留代码标识、路径、commit SHA、AC ID、FACT / INFERENCE / ASSUMPTION / TO_VERIFY 等固定枚举为原文。",
|
|
1086
|
+
"You are a review worker for a requirements clarification product. You must not implement code, generate downstream test delivery, create worktrees, deploy, or mark the requirement Ready. AI output is proposal data only and requires human confirmation.",
|
|
1087
|
+
"A FACT must cite an accessible, version-pinned source. If evidence is unavailable, use TO_VERIFY; never invent historical or implementation conflicts.",
|
|
1088
|
+
"Use spec_read to retrieve the exact current data. Do not modify files directly.",
|
|
1089
|
+
"每个 Review Item 默认给出三个 recommendedOptions。每个选项只表达一个决定,使用“选择 + 直接结果”的短句,建议不超过 45 个汉字;三个选项必须有真实差异,不得只是“接受、拒绝、待验证”的同义改写。确有四种独立方案时才允许第四项。",
|
|
1090
|
+
"Review Item 的 question 只问一个可以直接回答的问题,建议不超过 40 个汉字。背景放在 statement,后果放在 impact,不要把背景、问题和多个子问题挤进 question 或选项。",
|
|
1091
|
+
"每个 Review Item 必须提供 sourceAnchors:优先从当前 Spec 原文逐字复制 1 至 3 段能说明问题的短句,并填写所在 heading;不得改写或概括。问题来自正文缺失、没有可引用原文时,sourceAnchors 使用空数组,并通过 affectedSections / affectedAcceptanceIds 指明应补充的位置。",
|
|
1092
|
+
"审核记录与正式文档必须分层:FACT / INFERENCE / ASSUMPTION / TO_VERIFY、commit SHA、run ID 等只用于结构化审核记录,不得堆入候选 Spec 正文。",
|
|
1093
|
+
"候选 Spec 必须使用产品和研发都能直接理解的自然中文。避免行业黑话、审计腔和无必要的英文;英文缩写首次出现时必须同时写出中文含义,例如“行动按钮(CTA)”,后续优先使用中文。无法准确解释的缩写不要使用。",
|
|
1094
|
+
"优先使用这些通俗说法:操作按钮(不用 CTA)、统一风格标识(不用 canonical key)、点赞(不用 like)、提示词(不用 prompt)、测试数据(不用 fixture)、最终判断依据(不用事实源)、完成状态(不用终态)、重复操作结果一致(不用幂等)。Upgrade、Download、Lite、Plus 等确为界面文案或套餐名时可保留,但首次出现要说明中文含义。",
|
|
1095
|
+
"正文不要写“当前唯一可访问来源”“固定于某 commit”“统一记为 TO_VERIFY”这类过程说明。资料不足时,只在“待补充资料”章节按“资料名称:需要补充的内容;负责人(如已知)”列出,不重复背景、不写内部状态枚举。",
|
|
1096
|
+
"每段只表达一个结论,优先使用短句和具体业务语言。删除不影响需求理解、研发实现或验收判断的元信息。",
|
|
1097
|
+
"候选 patch 直接从文档标题开始,不写“本文为候选 patch”“不代表已确认决策”等免责声明。保留清晰的 Markdown 章节;身份与权限差异优先用表格,验收标准使用“前提 / 操作 / 预期结果”,不要使用 Given / When / Then。",
|
|
1098
|
+
"合并重复内容:目标讲用户结果,范围只列做与不做,业务规则只定义规则,验收标准只写可验证场景。同一句规则不要再分别复制到目标、范围、术语、验收和风险章节。"
|
|
1099
|
+
].join("\n"),
|
|
1100
|
+
productFirst: "Perform the initial product review across goal, evidence, history-conflict, current-implementation, scope, semantics, completeness, acceptance, and risk. Submit structured findings with spec_submit_review. If the draft needs changes, also submit a candidate patch with spec_propose_patch. The candidate document must follow the plain-language and audit-metadata separation rules above.",
|
|
1101
|
+
productSecond: "Review product responses against their original Review Items. Do not close vague answers. Submit remaining/new findings with spec_submit_review and a reviewable candidate patch with spec_propose_patch. Rewrite awkward inherited wording instead of copying internal review terminology into the document.",
|
|
1102
|
+
engineeringPrecheck: "Read the product-confirmed Spec and inspect relevant current code/history available in the workspace. Find implementation fact conflicts, affected entries/roles/states, technical ambiguity, compatibility/permission/data boundaries, and unverifiable acceptance criteria. Submit with spec_submit_review and propose a patch only when needed.",
|
|
1103
|
+
changeReview: "Review only the latest saved commit against its parent. Identify materiality, affected sections/ACs, confirmations or decisions that need reconfirmation, and new conflicts. Submit with spec_submit_review; propose a patch only when needed.",
|
|
1104
|
+
comment: "Analyze this substantive comment. First query any code/document facts you can obtain. Then use spec_reply exactly once with your understanding, versioned evidence or TO_VERIFY status, affected sections/ACs, and recommended disposition. Do not silently modify the Spec or choose between conflicting product and engineering positions.",
|
|
1105
|
+
followUp: "请使用简体中文回答以下追问,并继续遵守当前 Spec 审核任务的证据、权限和结构化回写约束。\n\n{{CONTENT}}"
|
|
1106
|
+
};
|
|
1107
|
+
function resolveReviewPrompts(config = {}) {
|
|
1108
|
+
const prompts = {
|
|
1109
|
+
...DEFAULT_REVIEW_PROMPTS,
|
|
1110
|
+
...config
|
|
1111
|
+
};
|
|
1112
|
+
validateTemplate("workspaceContext", prompts.workspaceContext, [
|
|
1113
|
+
"WORKSPACE_ID",
|
|
1114
|
+
"WORKSPACE_TITLE",
|
|
1115
|
+
"WORKSPACE_PATH",
|
|
1116
|
+
"WORKSPACE_SNAPSHOT",
|
|
1117
|
+
"RESOURCE_INSTRUCTIONS"
|
|
1118
|
+
], ["WORKSPACE_SNAPSHOT", "RESOURCE_INSTRUCTIONS"]);
|
|
1119
|
+
validateTemplate("resourceInstructions", prompts.resourceInstructions, [
|
|
1120
|
+
"RESOURCE_DETAILS",
|
|
1121
|
+
"SKILLS",
|
|
1122
|
+
"MCP_SERVERS",
|
|
1123
|
+
"DOCUMENT_PATHS"
|
|
1124
|
+
]);
|
|
1125
|
+
validateTemplate("followUp", prompts.followUp, ["CONTENT"], ["CONTENT"]);
|
|
1126
|
+
for (const name of [
|
|
1127
|
+
"system",
|
|
1128
|
+
"common",
|
|
1129
|
+
"productFirst",
|
|
1130
|
+
"productSecond",
|
|
1131
|
+
"engineeringPrecheck",
|
|
1132
|
+
"changeReview",
|
|
1133
|
+
"comment"
|
|
1134
|
+
]) validateTemplate(name, prompts[name], []);
|
|
1135
|
+
return prompts;
|
|
1136
|
+
}
|
|
1137
|
+
function renderPrompt(template, values) {
|
|
1138
|
+
return template.replace(/\{\{([A-Z_]+)\}\}/g, (placeholder, key) => values[key] ?? placeholder);
|
|
1139
|
+
}
|
|
1140
|
+
function extractPromptValue(rendered, template, placeholder) {
|
|
1141
|
+
const token = `{{${placeholder}}}`;
|
|
1142
|
+
const index = template.indexOf(token);
|
|
1143
|
+
if (index < 0) return void 0;
|
|
1144
|
+
const prefix = template.slice(0, index);
|
|
1145
|
+
const suffix = template.slice(index + token.length);
|
|
1146
|
+
if (!rendered.startsWith(prefix) || !rendered.endsWith(suffix)) return void 0;
|
|
1147
|
+
return rendered.slice(prefix.length, rendered.length - suffix.length);
|
|
1148
|
+
}
|
|
1149
|
+
function validateTemplate(name, template, allowed, requiredOnce = []) {
|
|
1150
|
+
const counts = /* @__PURE__ */ new Map();
|
|
1151
|
+
for (const match of template.matchAll(/\{\{([A-Z_]+)\}\}/g)) {
|
|
1152
|
+
const placeholder = match[1];
|
|
1153
|
+
if (!allowed.includes(placeholder)) throw new Error(`${name} prompt contains unsupported placeholder {{${placeholder}}}`);
|
|
1154
|
+
counts.set(placeholder, (counts.get(placeholder) ?? 0) + 1);
|
|
1155
|
+
}
|
|
1156
|
+
for (const placeholder of requiredOnce) if (counts.get(placeholder) !== 1) throw new Error(`${name} prompt must contain {{${placeholder}}} exactly once`);
|
|
1157
|
+
}
|
|
1158
|
+
//#endregion
|
|
1063
1159
|
//#region src/review-context.ts
|
|
1064
1160
|
const MCP_SERVER = /^[A-Za-z0-9_-]{1,32}$/;
|
|
1065
1161
|
var ReviewContextCatalog = class {
|
|
@@ -1092,14 +1188,29 @@ var ReviewContextCatalog = class {
|
|
|
1092
1188
|
};
|
|
1093
1189
|
}
|
|
1094
1190
|
};
|
|
1095
|
-
function reviewContextPrompt(context) {
|
|
1096
|
-
const
|
|
1191
|
+
function reviewContextPrompt(context, options = {}) {
|
|
1192
|
+
const workspace = options.workspace ?? {
|
|
1193
|
+
title: context.workspaceId,
|
|
1194
|
+
path: "未提供"
|
|
1195
|
+
};
|
|
1196
|
+
const rows = [];
|
|
1097
1197
|
if (context.skills.length > 0) rows.push(`Skills:先调用 skill 工具加载 ${context.skills.map((value) => `\`${value}\``).join("、")},读取完整说明后再分析。`);
|
|
1098
1198
|
if (context.mcpServers.length > 0) rows.push(`MCP:需要事实查询时优先使用 ${context.mcpServers.map((value) => `\`mcp__${value}__*\``).join("、")} namespace 下的工具。`);
|
|
1099
1199
|
if (context.documentPaths.length > 0) rows.push("本地参考文档:分析前先读取与本需求相关的路径;相对路径基于当前 DSH 工作区根目录,引用时必须带具体文件路径和可识别版本。", ...context.documentPaths.map((value) => `- \`${value}\``));
|
|
1100
1200
|
if (context.skills.length === 0 && context.mcpServers.length === 0 && context.documentPaths.length === 0) rows.push("当前未配置额外 Skill、MCP 或本地参考文档。");
|
|
1101
|
-
|
|
1102
|
-
|
|
1201
|
+
const resourceInstructions = renderPrompt(options.resourceTemplate ?? DEFAULT_REVIEW_PROMPTS.resourceInstructions, {
|
|
1202
|
+
RESOURCE_DETAILS: rows.join("\n"),
|
|
1203
|
+
SKILLS: formatValues(context.skills),
|
|
1204
|
+
MCP_SERVERS: formatValues(context.mcpServers.map((value) => `mcp__${value}__*`)),
|
|
1205
|
+
DOCUMENT_PATHS: formatValues(context.documentPaths)
|
|
1206
|
+
});
|
|
1207
|
+
return renderPrompt(options.workspaceTemplate ?? DEFAULT_REVIEW_PROMPTS.workspaceContext, {
|
|
1208
|
+
WORKSPACE_ID: context.workspaceId,
|
|
1209
|
+
WORKSPACE_TITLE: workspace.title,
|
|
1210
|
+
WORKSPACE_PATH: workspace.path,
|
|
1211
|
+
WORKSPACE_SNAPSHOT: options.workspaceSnapshot ?? "工作区快照尚未生成。",
|
|
1212
|
+
RESOURCE_INSTRUCTIONS: resourceInstructions
|
|
1213
|
+
});
|
|
1103
1214
|
}
|
|
1104
1215
|
function normalizeResources(value) {
|
|
1105
1216
|
const skills = cleanList(value?.skills);
|
|
@@ -1120,12 +1231,154 @@ function cleanList(values) {
|
|
|
1120
1231
|
function unique(values) {
|
|
1121
1232
|
return [...new Set(values)];
|
|
1122
1233
|
}
|
|
1234
|
+
function formatValues(values) {
|
|
1235
|
+
return values.length > 0 ? values.map((value) => `\`${value}\``).join("、") : "未配置";
|
|
1236
|
+
}
|
|
1123
1237
|
function resolveDocumentPath(value) {
|
|
1124
1238
|
if (value === "~") return homedir();
|
|
1125
1239
|
if (value.startsWith("~/") || value.startsWith("~\\")) return normalize(resolve(homedir(), value.slice(2)));
|
|
1126
1240
|
return normalize(value);
|
|
1127
1241
|
}
|
|
1128
1242
|
//#endregion
|
|
1243
|
+
//#region src/workspace-context.ts
|
|
1244
|
+
const MAX_FILES = 20;
|
|
1245
|
+
const MAX_FILE_BYTES = 16 * 1024;
|
|
1246
|
+
const MAX_TOTAL_BYTES = 64 * 1024;
|
|
1247
|
+
const MAX_DIRECTORY_DEPTH = 4;
|
|
1248
|
+
const MAX_ROOT_ENTRIES = 80;
|
|
1249
|
+
const PROJECT_CONTEXT_FILES = /* @__PURE__ */ new Set([
|
|
1250
|
+
"agents.md",
|
|
1251
|
+
"context.md",
|
|
1252
|
+
"contributing.md",
|
|
1253
|
+
"package.json",
|
|
1254
|
+
"pyproject.toml",
|
|
1255
|
+
"cargo.toml",
|
|
1256
|
+
"go.mod",
|
|
1257
|
+
"pom.xml",
|
|
1258
|
+
"build.gradle",
|
|
1259
|
+
"build.gradle.kts",
|
|
1260
|
+
"requirements.txt",
|
|
1261
|
+
"gemfile"
|
|
1262
|
+
]);
|
|
1263
|
+
const TEXT_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
1264
|
+
".md",
|
|
1265
|
+
".mdx",
|
|
1266
|
+
".txt",
|
|
1267
|
+
".json",
|
|
1268
|
+
".jsonc",
|
|
1269
|
+
".yaml",
|
|
1270
|
+
".yml",
|
|
1271
|
+
".toml",
|
|
1272
|
+
".xml",
|
|
1273
|
+
".ini",
|
|
1274
|
+
".cfg",
|
|
1275
|
+
".conf",
|
|
1276
|
+
".properties",
|
|
1277
|
+
".gradle",
|
|
1278
|
+
".kts",
|
|
1279
|
+
".mod",
|
|
1280
|
+
".rst",
|
|
1281
|
+
".adoc"
|
|
1282
|
+
]);
|
|
1283
|
+
const SKIP_DIRECTORIES = /* @__PURE__ */ new Set([
|
|
1284
|
+
".git",
|
|
1285
|
+
"node_modules",
|
|
1286
|
+
"dist",
|
|
1287
|
+
"build",
|
|
1288
|
+
"lib",
|
|
1289
|
+
"coverage",
|
|
1290
|
+
".next",
|
|
1291
|
+
".cache"
|
|
1292
|
+
]);
|
|
1293
|
+
async function readWorkspaceSnapshot(workspaceRoot, documentPaths) {
|
|
1294
|
+
const root = resolve(workspaceRoot);
|
|
1295
|
+
const rows = ["## 插件已读取的工作区快照", `工作区根目录:\`${root}\``];
|
|
1296
|
+
const notices = [];
|
|
1297
|
+
const candidates = [];
|
|
1298
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1299
|
+
try {
|
|
1300
|
+
const rootEntries = await readdir(root, { withFileTypes: true });
|
|
1301
|
+
const visibleEntries = rootEntries.filter((entry) => !SKIP_DIRECTORIES.has(entry.name)).sort((left, right) => left.name.localeCompare(right.name)).slice(0, MAX_ROOT_ENTRIES).map((entry) => entry.isDirectory() ? `${entry.name}/` : entry.name);
|
|
1302
|
+
rows.push(`根目录条目:${visibleEntries.join("、") || "空目录"}`);
|
|
1303
|
+
for (const entry of rootEntries) {
|
|
1304
|
+
if (!entry.isFile() || !isProjectContextFile(entry.name)) continue;
|
|
1305
|
+
addCandidate(candidates, seen, resolve(root, entry.name), entry.name);
|
|
1306
|
+
}
|
|
1307
|
+
} catch (error) {
|
|
1308
|
+
rows.push("根目录条目:无法读取");
|
|
1309
|
+
notices.push(`- 工作区根目录无法读取:${errorMessage(error)}`);
|
|
1310
|
+
}
|
|
1311
|
+
for (const configuredPath of documentPaths) {
|
|
1312
|
+
const path = isAbsolute(configuredPath) ? resolve(configuredPath) : resolve(root, configuredPath);
|
|
1313
|
+
const displayPath = displayWorkspacePath(root, path);
|
|
1314
|
+
try {
|
|
1315
|
+
const value = await stat(path);
|
|
1316
|
+
if (value.isFile()) addCandidate(candidates, seen, path, displayPath);
|
|
1317
|
+
else if (value.isDirectory()) await collectDirectory(path, root, candidates, seen, 0);
|
|
1318
|
+
else notices.push(`- 无法读取 \`${displayPath}\`:不是普通文件或目录。`);
|
|
1319
|
+
} catch (error) {
|
|
1320
|
+
notices.push(`- 无法读取 \`${displayPath}\`:${errorMessage(error)}`);
|
|
1321
|
+
}
|
|
1322
|
+
}
|
|
1323
|
+
let totalBytes = 0;
|
|
1324
|
+
let renderedFiles = 0;
|
|
1325
|
+
for (const candidate of candidates) {
|
|
1326
|
+
if (renderedFiles >= MAX_FILES || totalBytes >= MAX_TOTAL_BYTES) break;
|
|
1327
|
+
try {
|
|
1328
|
+
const buffer = await readFile(candidate.path);
|
|
1329
|
+
if (buffer.subarray(0, Math.min(buffer.length, 4096)).includes(0)) {
|
|
1330
|
+
notices.push(`- 跳过二进制文件 \`${candidate.displayPath}\`。`);
|
|
1331
|
+
continue;
|
|
1332
|
+
}
|
|
1333
|
+
const availableBytes = Math.min(MAX_FILE_BYTES, MAX_TOTAL_BYTES - totalBytes);
|
|
1334
|
+
const content = buffer.subarray(0, availableBytes).toString("utf8");
|
|
1335
|
+
const truncated = buffer.length > availableBytes;
|
|
1336
|
+
rows.push("", `### \`${candidate.displayPath}\``, "<workspace-file>", content, truncated ? "\n[内容已截断]" : "", "</workspace-file>");
|
|
1337
|
+
totalBytes += Buffer.byteLength(content);
|
|
1338
|
+
renderedFiles += 1;
|
|
1339
|
+
} catch (error) {
|
|
1340
|
+
notices.push(`- 无法读取 \`${candidate.displayPath}\`:${errorMessage(error)}`);
|
|
1341
|
+
}
|
|
1342
|
+
}
|
|
1343
|
+
if (candidates.length > renderedFiles) notices.push(`- 工作区快照达到上限,仅注入前 ${renderedFiles} 个可读文本文件。`);
|
|
1344
|
+
if (renderedFiles === 0) rows.push("", "未发现可注入的标准项目上下文文件。");
|
|
1345
|
+
if (notices.length > 0) rows.push("", "### 读取说明", ...notices);
|
|
1346
|
+
return rows.join("\n");
|
|
1347
|
+
}
|
|
1348
|
+
async function collectDirectory(directory, root, candidates, seen, depth) {
|
|
1349
|
+
if (depth > MAX_DIRECTORY_DEPTH || candidates.length >= MAX_FILES) return;
|
|
1350
|
+
const entries = await readdir(directory, { withFileTypes: true });
|
|
1351
|
+
for (const entry of entries.sort((left, right) => left.name.localeCompare(right.name))) {
|
|
1352
|
+
if (candidates.length >= MAX_FILES) return;
|
|
1353
|
+
const path = resolve(directory, entry.name);
|
|
1354
|
+
if (entry.isDirectory() && !SKIP_DIRECTORIES.has(entry.name)) await collectDirectory(path, root, candidates, seen, depth + 1);
|
|
1355
|
+
else if (entry.isFile() && isTextFile(entry.name)) addCandidate(candidates, seen, path, displayWorkspacePath(root, path));
|
|
1356
|
+
}
|
|
1357
|
+
}
|
|
1358
|
+
function addCandidate(candidates, seen, path, displayPath) {
|
|
1359
|
+
if (seen.has(path) || candidates.length >= MAX_FILES) return;
|
|
1360
|
+
seen.add(path);
|
|
1361
|
+
candidates.push({
|
|
1362
|
+
path,
|
|
1363
|
+
displayPath
|
|
1364
|
+
});
|
|
1365
|
+
}
|
|
1366
|
+
function isProjectContextFile(name) {
|
|
1367
|
+
const lower = name.toLowerCase();
|
|
1368
|
+
return PROJECT_CONTEXT_FILES.has(lower) || lower === "readme" || lower.startsWith("readme.");
|
|
1369
|
+
}
|
|
1370
|
+
function isTextFile(name) {
|
|
1371
|
+
return isProjectContextFile(name) || TEXT_EXTENSIONS.has(extname(name).toLowerCase());
|
|
1372
|
+
}
|
|
1373
|
+
function displayWorkspacePath(root, path) {
|
|
1374
|
+
const value = relative(root, path);
|
|
1375
|
+
return value !== "" && !value.startsWith("..") ? value : path;
|
|
1376
|
+
}
|
|
1377
|
+
function errorMessage(error) {
|
|
1378
|
+
if (error instanceof Error && "code" in error && typeof error.code === "string") return error.code;
|
|
1379
|
+
return error instanceof Error ? error.message : String(error);
|
|
1380
|
+
}
|
|
1381
|
+
//#endregion
|
|
1129
1382
|
//#region src/review-runtime.ts
|
|
1130
1383
|
function request(payload) {
|
|
1131
1384
|
return {
|
|
@@ -1136,12 +1389,15 @@ function request(payload) {
|
|
|
1136
1389
|
function failure(error) {
|
|
1137
1390
|
return /* @__PURE__ */ new Error(`${error.code}: ${error.message}`);
|
|
1138
1391
|
}
|
|
1392
|
+
const FOLLOW_UP_METADATA = "\n\n<!-- dsh-spec-collab-follow-up:";
|
|
1139
1393
|
var DshReviewCoordinator = class {
|
|
1140
1394
|
api;
|
|
1141
1395
|
contexts;
|
|
1142
|
-
|
|
1396
|
+
prompts;
|
|
1397
|
+
constructor(api, contexts = new ReviewContextCatalog(), prompts = {}) {
|
|
1143
1398
|
this.api = api;
|
|
1144
1399
|
this.contexts = contexts;
|
|
1400
|
+
this.prompts = resolveReviewPrompts(prompts);
|
|
1145
1401
|
}
|
|
1146
1402
|
async reviewWorkspaces() {
|
|
1147
1403
|
const listed = await this.api.workspace.list(request({}));
|
|
@@ -1153,15 +1409,19 @@ var DshReviewCoordinator = class {
|
|
|
1153
1409
|
}));
|
|
1154
1410
|
}
|
|
1155
1411
|
async assertWorkspaceAvailable(workspaceId) {
|
|
1156
|
-
|
|
1412
|
+
await this.resolveWorkspace(workspaceId);
|
|
1157
1413
|
}
|
|
1158
|
-
requestReview(input) {
|
|
1414
|
+
async requestReview(input) {
|
|
1159
1415
|
const context = this.contexts.resolve(input.requirement.workspaceId);
|
|
1160
|
-
|
|
1416
|
+
const workspace = await this.resolveWorkspace(context.workspaceId);
|
|
1417
|
+
const snapshot = await readWorkspaceSnapshot(workspace.path, context.documentPaths);
|
|
1418
|
+
return this.launch(`Spec ${input.run.kind}: ${input.requirement.title}`, reviewPrompt(input.requirement, input.run, context, workspace, snapshot, this.prompts), context.workspaceId, context.agentPreset);
|
|
1161
1419
|
}
|
|
1162
|
-
requestCommentReply(input) {
|
|
1420
|
+
async requestCommentReply(input) {
|
|
1163
1421
|
const context = this.contexts.resolve(input.requirement.workspaceId);
|
|
1164
|
-
|
|
1422
|
+
const workspace = await this.resolveWorkspace(context.workspaceId);
|
|
1423
|
+
const snapshot = await readWorkspaceSnapshot(workspace.path, context.documentPaths);
|
|
1424
|
+
return this.launch(`Spec comment analysis: ${input.requirement.title}`, commentPrompt(input.requirement, input.comment, context, workspace, snapshot, this.prompts), context.workspaceId, context.agentPreset);
|
|
1165
1425
|
}
|
|
1166
1426
|
async conversation(sessionId) {
|
|
1167
1427
|
const history = await this.api.sessions.history(request({ sessionId }));
|
|
@@ -1178,8 +1438,9 @@ var DshReviewCoordinator = class {
|
|
|
1178
1438
|
const message = isObject(value) && "message" in value ? value.message : value;
|
|
1179
1439
|
let messageText = collectText(isObject(message) && "content" in message ? message.content : message).join("\n").trim();
|
|
1180
1440
|
if (entry.event.type === "user/message") {
|
|
1181
|
-
|
|
1182
|
-
|
|
1441
|
+
const followUp = storedFollowUp(messageText) ?? extractPromptValue(messageText, this.prompts.followUp.trim(), "CONTENT") ?? extractPromptValue(messageText, DEFAULT_REVIEW_PROMPTS.followUp, "CONTENT");
|
|
1442
|
+
if (followUp === void 0) continue;
|
|
1443
|
+
messageText = followUp.trim();
|
|
1183
1444
|
}
|
|
1184
1445
|
if (messageText !== "") rows.push({
|
|
1185
1446
|
role: entry.event.type === "user/message" ? "user" : "assistant",
|
|
@@ -1191,18 +1452,19 @@ var DshReviewCoordinator = class {
|
|
|
1191
1452
|
async followUp(sessionId, text) {
|
|
1192
1453
|
const content = text.trim();
|
|
1193
1454
|
if (content === "") throw new Error("追问内容不能为空");
|
|
1455
|
+
const metadata = Buffer.from(content, "utf8").toString("base64url");
|
|
1456
|
+
const promptText = `${renderPrompt(this.prompts.followUp, { CONTENT: content }).trim()}${FOLLOW_UP_METADATA}${metadata} -->`;
|
|
1194
1457
|
const prompted = await this.api.sessions.prompt(request({
|
|
1195
1458
|
sessionId,
|
|
1196
1459
|
mode: "queue",
|
|
1197
1460
|
content: [{
|
|
1198
1461
|
type: "text",
|
|
1199
|
-
text:
|
|
1462
|
+
text: promptText
|
|
1200
1463
|
}]
|
|
1201
1464
|
}));
|
|
1202
1465
|
if (!prompted.result.ok) throw failure(prompted.result.error);
|
|
1203
1466
|
}
|
|
1204
1467
|
async launch(title, promptText, workspaceId, agentPreset) {
|
|
1205
|
-
await this.assertWorkspaceAvailable(workspaceId);
|
|
1206
1468
|
if (agentPreset !== void 0) {
|
|
1207
1469
|
const presets = await this.api.agentPresets.list(request({}));
|
|
1208
1470
|
if (!presets.result.ok) throw failure(presets.result.error);
|
|
@@ -1231,7 +1493,23 @@ var DshReviewCoordinator = class {
|
|
|
1231
1493
|
if (!prompted.result.ok) throw failure(prompted.result.error);
|
|
1232
1494
|
return sessionId;
|
|
1233
1495
|
}
|
|
1496
|
+
async resolveWorkspace(workspaceId) {
|
|
1497
|
+
const workspace = (await this.reviewWorkspaces()).find((item) => item.workspaceId === workspaceId);
|
|
1498
|
+
if (workspace === void 0) throw new Error(`workspace not found: ${workspaceId}`);
|
|
1499
|
+
return workspace;
|
|
1500
|
+
}
|
|
1234
1501
|
};
|
|
1502
|
+
function storedFollowUp(message) {
|
|
1503
|
+
const index = message.lastIndexOf(FOLLOW_UP_METADATA);
|
|
1504
|
+
if (index < 0 || !message.endsWith(" -->")) return void 0;
|
|
1505
|
+
const encoded = message.slice(index + 33, -4);
|
|
1506
|
+
if (!/^[A-Za-z0-9_-]+$/.test(encoded)) return void 0;
|
|
1507
|
+
try {
|
|
1508
|
+
return Buffer.from(encoded, "base64url").toString("utf8");
|
|
1509
|
+
} catch {
|
|
1510
|
+
return;
|
|
1511
|
+
}
|
|
1512
|
+
}
|
|
1235
1513
|
function isObject(value) {
|
|
1236
1514
|
return typeof value === "object" && value !== null;
|
|
1237
1515
|
}
|
|
@@ -1241,52 +1519,46 @@ function collectText(value) {
|
|
|
1241
1519
|
if (value.type === "text" && typeof value.text === "string") return [value.text];
|
|
1242
1520
|
return "content" in value ? collectText(value.content) : [];
|
|
1243
1521
|
}
|
|
1244
|
-
function common(requirement, context) {
|
|
1522
|
+
function common(requirement, context, workspace, workspaceSnapshot, prompts) {
|
|
1245
1523
|
return [
|
|
1246
1524
|
`Requirement ID: ${requirement.id}`,
|
|
1247
1525
|
`Pinned commit: ${requirement.currentCommit}`,
|
|
1248
1526
|
"",
|
|
1249
|
-
reviewContextPrompt(context
|
|
1527
|
+
reviewContextPrompt(context, {
|
|
1528
|
+
workspace,
|
|
1529
|
+
workspaceSnapshot,
|
|
1530
|
+
workspaceTemplate: prompts.workspaceContext,
|
|
1531
|
+
resourceTemplate: prompts.resourceInstructions
|
|
1532
|
+
}),
|
|
1250
1533
|
"",
|
|
1251
|
-
|
|
1252
|
-
"You are a review worker for a requirements clarification product. You must not implement code, generate downstream test delivery, create worktrees, deploy, or mark the requirement Ready. AI output is proposal data only and requires human confirmation.",
|
|
1253
|
-
"A FACT must cite an accessible, version-pinned source. If evidence is unavailable, use TO_VERIFY; never invent historical or implementation conflicts.",
|
|
1254
|
-
"Use spec_read to retrieve the exact current data. Do not modify files directly.",
|
|
1255
|
-
"每个 Review Item 默认给出三个 recommendedOptions。每个选项只表达一个决定,使用“选择 + 直接结果”的短句,建议不超过 45 个汉字;三个选项必须有真实差异,不得只是“接受、拒绝、待验证”的同义改写。确有四种独立方案时才允许第四项。",
|
|
1256
|
-
"Review Item 的 question 只问一个可以直接回答的问题,建议不超过 40 个汉字。背景放在 statement,后果放在 impact,不要把背景、问题和多个子问题挤进 question 或选项。",
|
|
1257
|
-
"审核记录与正式文档必须分层:FACT / INFERENCE / ASSUMPTION / TO_VERIFY、commit SHA、run ID 等只用于结构化审核记录,不得堆入候选 Spec 正文。",
|
|
1258
|
-
"候选 Spec 必须使用产品和研发都能直接理解的自然中文。避免行业黑话、审计腔和无必要的英文;英文缩写首次出现时必须同时写出中文含义,例如“行动按钮(CTA)”,后续优先使用中文。无法准确解释的缩写不要使用。",
|
|
1259
|
-
"优先使用这些通俗说法:操作按钮(不用 CTA)、统一风格标识(不用 canonical key)、点赞(不用 like)、提示词(不用 prompt)、测试数据(不用 fixture)、最终判断依据(不用事实源)、完成状态(不用终态)、重复操作结果一致(不用幂等)。Upgrade、Download、Lite、Plus 等确为界面文案或套餐名时可保留,但首次出现要说明中文含义。",
|
|
1260
|
-
"正文不要写“当前唯一可访问来源”“固定于某 commit”“统一记为 TO_VERIFY”这类过程说明。资料不足时,只在“待补充资料”章节按“资料名称:需要补充的内容;负责人(如已知)”列出,不重复背景、不写内部状态枚举。",
|
|
1261
|
-
"每段只表达一个结论,优先使用短句和具体业务语言。删除不影响需求理解、研发实现或验收判断的元信息。",
|
|
1262
|
-
"候选 patch 直接从文档标题开始,不写“本文为候选 patch”“不代表已确认决策”等免责声明。保留清晰的 Markdown 章节;身份与权限差异优先用表格,验收标准使用“前提 / 操作 / 预期结果”,不要使用 Given / When / Then。",
|
|
1263
|
-
"合并重复内容:目标讲用户结果,范围只列做与不做,业务规则只定义规则,验收标准只写可验证场景。同一句规则不要再分别复制到目标、范围、术语、验收和风险章节。"
|
|
1534
|
+
prompts.common
|
|
1264
1535
|
].join("\n");
|
|
1265
1536
|
}
|
|
1266
|
-
function reviewPrompt(requirement, run, context) {
|
|
1537
|
+
function reviewPrompt(requirement, run, context, workspace, workspaceSnapshot, prompts) {
|
|
1538
|
+
const tasks = {
|
|
1539
|
+
"product-first": prompts.productFirst,
|
|
1540
|
+
"product-second": prompts.productSecond,
|
|
1541
|
+
"engineering-precheck": prompts.engineeringPrecheck,
|
|
1542
|
+
"change-review": prompts.changeReview
|
|
1543
|
+
};
|
|
1267
1544
|
return [
|
|
1268
|
-
common(requirement, context),
|
|
1545
|
+
common(requirement, context, workspace, workspaceSnapshot, prompts),
|
|
1269
1546
|
`Review run ID: ${run.id}`,
|
|
1270
1547
|
`Review kind: ${run.kind}`,
|
|
1271
1548
|
`AI session ID: {{SESSION_ID}}`,
|
|
1272
1549
|
"",
|
|
1273
|
-
|
|
1274
|
-
"product-first": "Perform the initial product review across goal, evidence, history-conflict, current-implementation, scope, semantics, completeness, acceptance, and risk. Submit structured findings with spec_submit_review. If the draft needs changes, also submit a candidate patch with spec_propose_patch. The candidate document must follow the plain-language and audit-metadata separation rules above.",
|
|
1275
|
-
"product-second": "Review product responses against their original Review Items. Do not close vague answers. Submit remaining/new findings with spec_submit_review and a reviewable candidate patch with spec_propose_patch. Rewrite awkward inherited wording instead of copying internal review terminology into the document.",
|
|
1276
|
-
"engineering-precheck": "Read the product-confirmed Spec and inspect relevant current code/history available in the workspace. Find implementation fact conflicts, affected entries/roles/states, technical ambiguity, compatibility/permission/data boundaries, and unverifiable acceptance criteria. Submit with spec_submit_review and propose a patch only when needed.",
|
|
1277
|
-
"change-review": "Review only the latest saved commit against its parent. Identify materiality, affected sections/ACs, confirmations or decisions that need reconfirmation, and new conflicts. Submit with spec_submit_review; propose a patch only when needed."
|
|
1278
|
-
}[run.kind]
|
|
1550
|
+
tasks[run.kind]
|
|
1279
1551
|
].join("\n");
|
|
1280
1552
|
}
|
|
1281
|
-
function commentPrompt(requirement, comment, context) {
|
|
1553
|
+
function commentPrompt(requirement, comment, context, workspace, workspaceSnapshot, prompts) {
|
|
1282
1554
|
return [
|
|
1283
|
-
common(requirement, context),
|
|
1555
|
+
common(requirement, context, workspace, workspaceSnapshot, prompts),
|
|
1284
1556
|
`Comment ID: ${comment.id}`,
|
|
1285
1557
|
`Anchor quote: ${comment.anchor.quote}`,
|
|
1286
1558
|
`Human comment: ${comment.body}`,
|
|
1287
1559
|
`AI session ID: {{SESSION_ID}}`,
|
|
1288
1560
|
"",
|
|
1289
|
-
|
|
1561
|
+
prompts.comment
|
|
1290
1562
|
].join("\n");
|
|
1291
1563
|
}
|
|
1292
1564
|
//#endregion
|
|
@@ -1623,7 +1895,7 @@ function specReadTool(engine) {
|
|
|
1623
1895
|
`commit: ${view.currentCommit}`
|
|
1624
1896
|
];
|
|
1625
1897
|
if (include.has("spec")) rows.push("", "## Spec", view.version.markdown);
|
|
1626
|
-
if (include.has("review-items")) rows.push("", "## Review Items", ...view.reviewItems.map((item) => `- ${item.id} [${item.severity}/${item.status}/${item.epistemicStatus}] ${item.statement}\n Question: ${item.question}\n Recommended options: ${(item.recommendedOptions ?? []).join(" / ") || "none"}\n Evidence: ${item.evidence.map((evidence) => `${evidence.source}${evidence.version ? `@${evidence.version}` : ""}`).join(", ") || "none"}`));
|
|
1898
|
+
if (include.has("review-items")) rows.push("", "## Review Items", ...view.reviewItems.map((item) => `- ${item.id} [${item.severity}/${item.status}/${item.epistemicStatus}] ${item.statement}\n Question: ${item.question}\n Spec anchors: ${(item.sourceAnchors ?? []).map((anchor) => `${anchor.heading ? `${anchor.heading}: ` : ""}${anchor.quote}`).join(" / ") || "none"}\n Recommended options: ${(item.recommendedOptions ?? []).join(" / ") || "none"}\n Evidence: ${item.evidence.map((evidence) => `${evidence.source}${evidence.version ? `@${evidence.version}` : ""}`).join(", ") || "none"}`));
|
|
1627
1899
|
if (include.has("comments")) rows.push("", "## Comments", ...view.comments.map((item) => `- ${item.id} [${item.status}] “${item.anchor.quote}” ${item.author.nickname}: ${item.body}\n Replies: ${item.replies.map((reply) => `${reply.author.nickname}: ${reply.body}`).join(" / ") || "none"}`));
|
|
1628
1900
|
if (include.has("decisions")) rows.push("", "## Decisions", ...view.decisions.map((item) => `- ${item.id} [${item.status}] ${item.question}: ${item.decision}`));
|
|
1629
1901
|
if (include.has("confirmations")) rows.push("", "## Confirmations", ...view.confirmations.map((item) => `- ${item.role}/${item.scope}/${item.scopeId ?? "document"} [${item.status}] ${item.participant.nickname} @ ${item.commit}`));
|
|
@@ -1780,6 +2052,22 @@ function specSubmitReviewTool(engine) {
|
|
|
1780
2052
|
items: { type: "string" },
|
|
1781
2053
|
description: "默认三个、最多四个互有取舍的中文选项;每项只表达一个决定,建议不超过 45 个汉字。"
|
|
1782
2054
|
},
|
|
2055
|
+
sourceAnchors: {
|
|
2056
|
+
type: "array",
|
|
2057
|
+
required: true,
|
|
2058
|
+
description: "直接从当前 Spec 原文复制 1-3 段精确短句;问题来自缺失内容时可为空数组。",
|
|
2059
|
+
items: {
|
|
2060
|
+
type: "object",
|
|
2061
|
+
additionalProperties: false,
|
|
2062
|
+
properties: {
|
|
2063
|
+
quote: {
|
|
2064
|
+
type: "string",
|
|
2065
|
+
required: true
|
|
2066
|
+
},
|
|
2067
|
+
heading: { type: "string" }
|
|
2068
|
+
}
|
|
2069
|
+
}
|
|
2070
|
+
},
|
|
1783
2071
|
affectedSections: {
|
|
1784
2072
|
type: "array",
|
|
1785
2073
|
required: true,
|
|
@@ -1856,6 +2144,10 @@ function specSubmitReviewTool(engine) {
|
|
|
1856
2144
|
impact: item.impact,
|
|
1857
2145
|
question: item.question,
|
|
1858
2146
|
recommendedOptions: item.recommendedOptions,
|
|
2147
|
+
sourceAnchors: item.sourceAnchors.map((anchor) => ({
|
|
2148
|
+
quote: anchor.quote.trim(),
|
|
2149
|
+
...anchor.heading?.trim() ? { heading: anchor.heading.trim() } : {}
|
|
2150
|
+
})).filter((anchor) => anchor.quote),
|
|
1859
2151
|
affectedSections: item.affectedSections,
|
|
1860
2152
|
affectedAcceptanceIds: item.affectedAcceptanceIds,
|
|
1861
2153
|
ownerRole: item.ownerRole,
|
|
@@ -1971,6 +2263,7 @@ const contextFields = () => ({
|
|
|
1971
2263
|
documentPaths: stringList().description("AI 分析前可读取的本地文件或目录路径;相对路径按需求工作区根目录解析。"),
|
|
1972
2264
|
agentPreset: Schema.string().description("实际挂载这些 Skill/MCP 工具的 DSH Agent Preset ID。")
|
|
1973
2265
|
});
|
|
2266
|
+
const promptText = (value, description) => Schema.string().role("textarea").default(value).description(description);
|
|
1974
2267
|
const Config = Schema.object({
|
|
1975
2268
|
dataRoot: Schema.string().description("协作账本数据目录。"),
|
|
1976
2269
|
repositoryPath: Schema.string().description("正式 Spec Git 仓库目录。"),
|
|
@@ -1978,13 +2271,26 @@ const Config = Schema.object({
|
|
|
1978
2271
|
workspaces: Schema.array(Schema.object({
|
|
1979
2272
|
workspaceId: Schema.string().required().description("需要追加项目专属 AI 上下文的 DSH workspaceId。"),
|
|
1980
2273
|
...contextFields()
|
|
1981
|
-
})).default([]).description("按 DSH 工作区追加的 AI 上下文;未列出的工作区仍继承 defaultContext。")
|
|
2274
|
+
})).default([]).description("按 DSH 工作区追加的 AI 上下文;未列出的工作区仍继承 defaultContext。"),
|
|
2275
|
+
prompts: Schema.object({
|
|
2276
|
+
system: promptText(DEFAULT_REVIEW_PROMPTS.system, "注入普通 DSH 会话的插件系统说明。"),
|
|
2277
|
+
workspaceContext: promptText(DEFAULT_REVIEW_PROMPTS.workspaceContext, "工作区上下文模板。必须保留 {{WORKSPACE_SNAPSHOT}} 和 {{RESOURCE_INSTRUCTIONS}};还可使用 {{WORKSPACE_ID}}、{{WORKSPACE_TITLE}}、{{WORKSPACE_PATH}}。"),
|
|
2278
|
+
resourceInstructions: promptText(DEFAULT_REVIEW_PROMPTS.resourceInstructions, "Skill、MCP 和文档资源说明模板。可用变量:{{RESOURCE_DETAILS}}、{{SKILLS}}、{{MCP_SERVERS}}、{{DOCUMENT_PATHS}}。"),
|
|
2279
|
+
common: promptText(DEFAULT_REVIEW_PROMPTS.common, "所有审核和评论分析共享的约束。"),
|
|
2280
|
+
productFirst: promptText(DEFAULT_REVIEW_PROMPTS.productFirst, "产品 AI 初审任务提示词。"),
|
|
2281
|
+
productSecond: promptText(DEFAULT_REVIEW_PROMPTS.productSecond, "产品回复后的二次审核任务提示词。"),
|
|
2282
|
+
engineeringPrecheck: promptText(DEFAULT_REVIEW_PROMPTS.engineeringPrecheck, "研发智能预审任务提示词。"),
|
|
2283
|
+
changeReview: promptText(DEFAULT_REVIEW_PROMPTS.changeReview, "保存新版本后的变更审核任务提示词。"),
|
|
2284
|
+
comment: promptText(DEFAULT_REVIEW_PROMPTS.comment, "正文评论的 AI 分析任务提示词。"),
|
|
2285
|
+
followUp: promptText(DEFAULT_REVIEW_PROMPTS.followUp, "AI 会话追问模板,必须保留 {{CONTENT}}。")
|
|
2286
|
+
}).description("AI 提示词配置;未填写的字段使用插件内置默认值。")
|
|
1982
2287
|
});
|
|
1983
2288
|
function apply(ctx, config = {}) {
|
|
1984
2289
|
const dataRoot = config.dataRoot ?? join(homedir(), ".dsh", "spec-collab");
|
|
1985
2290
|
const contexts = new ReviewContextCatalog(config);
|
|
2291
|
+
const prompts = resolveReviewPrompts(config.prompts);
|
|
1986
2292
|
const engine = new CollaborationEngine(join(dataRoot, "collaboration-v2.json"), new GitRequirementStore(config.repositoryPath ?? join(dataRoot, "repository")));
|
|
1987
|
-
const coordinator = new DshReviewCoordinator(ctx.apiProxy, contexts);
|
|
2293
|
+
const coordinator = new DshReviewCoordinator(ctx.apiProxy, contexts, prompts);
|
|
1988
2294
|
engine.setCoordinator(coordinator);
|
|
1989
2295
|
ctx.effect(() => {
|
|
1990
2296
|
const disposers = makeRoutes(engine, coordinator).map((route) => ctx.webServer.register(route));
|
|
@@ -2001,8 +2307,8 @@ function apply(ctx, config = {}) {
|
|
|
2001
2307
|
ctx.effect(() => ctx.systemPrompt.section({
|
|
2002
2308
|
name: "plugin:spec-collab",
|
|
2003
2309
|
order: 190,
|
|
2004
|
-
text:
|
|
2310
|
+
text: prompts.system
|
|
2005
2311
|
}), "spec-collab: prompt");
|
|
2006
2312
|
}
|
|
2007
2313
|
//#endregion
|
|
2008
|
-
export { Config, apply, inject, name };
|
|
2314
|
+
export { Config, DEFAULT_REVIEW_PROMPTS, apply, inject, name, resolveReviewPrompts };
|
|
@@ -1,7 +1,24 @@
|
|
|
1
1
|
import '@toast-ui/editor/dist/i18n/zh-cn';
|
|
2
|
+
import type { CollaborationAction, ParticipantSnapshot, RequirementView } from '../protocol.ts';
|
|
2
3
|
import type { SpecApi } from './api.ts';
|
|
4
|
+
type ReviewOpenRequest = {
|
|
5
|
+
objectId: string;
|
|
6
|
+
requestId: number;
|
|
7
|
+
};
|
|
3
8
|
export declare function SpecWorkbench({ api, onClose }: {
|
|
4
9
|
api: SpecApi;
|
|
5
10
|
onClose: () => void;
|
|
6
11
|
}): import("react").JSX.Element;
|
|
12
|
+
type Act = (factory: (actor: ParticipantSnapshot) => CollaborationAction) => Promise<boolean>;
|
|
13
|
+
export declare function ReviewPanel({ requirement, act, api, focusedItemId, openRequest, onSelectReview, onLocateSource, onOpenRequestHandled }: {
|
|
14
|
+
requirement: RequirementView;
|
|
15
|
+
act: Act;
|
|
16
|
+
api: SpecApi;
|
|
17
|
+
focusedItemId?: string | undefined;
|
|
18
|
+
openRequest?: ReviewOpenRequest | undefined;
|
|
19
|
+
onSelectReview?: (itemId: string) => void;
|
|
20
|
+
onLocateSource?: (itemId: string) => void;
|
|
21
|
+
onOpenRequestHandled?: (requestId: number) => void;
|
|
22
|
+
}): import("react").JSX.Element;
|
|
23
|
+
export {};
|
|
7
24
|
//# sourceMappingURL=SpecWorkbench.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SpecWorkbench.d.ts","sourceRoot":"","sources":["../../../src/client/SpecWorkbench.tsx"],"names":[],"mappings":"AAGA,OAAO,kCAAkC,CAAA;
|
|
1
|
+
{"version":3,"file":"SpecWorkbench.d.ts","sourceRoot":"","sources":["../../../src/client/SpecWorkbench.tsx"],"names":[],"mappings":"AAGA,OAAO,kCAAkC,CAAA;AAEzC,OAAO,KAAK,EAAE,mBAAmB,EAAoD,mBAAmB,EAAwC,eAAe,EAAoE,MAAM,gBAAgB,CAAA;AACzP,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAsBvC,KAAK,iBAAiB,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAA;AAchE,wBAAgB,aAAa,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE;IAAE,GAAG,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,MAAM,IAAI,CAAA;CAAE,+BAkMpF;AAqID,KAAK,GAAG,GAAG,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,mBAAmB,KAAK,mBAAmB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;AAO7F,wBAAgB,WAAW,CAAC,EAAE,WAAW,EAAE,GAAG,EAAE,GAAG,EAAE,aAAa,EAAE,WAAW,EAAE,cAAc,EAAE,cAAc,EAAE,oBAAoB,EAAE,EAAE;IAAE,WAAW,EAAE,eAAe,CAAC;IAAC,GAAG,EAAE,GAAG,CAAC;IAAC,GAAG,EAAE,OAAO,CAAC;IAAC,aAAa,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAAC,WAAW,CAAC,EAAE,iBAAiB,GAAG,SAAS,CAAC;IAAC,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IAAC,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IAAC,oBAAoB,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAA;CAAE,+BA4B3Z"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ReviewItem } from '../protocol.ts';
|
|
2
|
+
export declare const reviewBlockSelector = "h1, h2, h3, h4, p, li, td, th, blockquote";
|
|
3
|
+
export interface ReviewSourceSnippet {
|
|
4
|
+
key: string;
|
|
5
|
+
label: string;
|
|
6
|
+
markdown: string;
|
|
7
|
+
line?: number;
|
|
8
|
+
}
|
|
9
|
+
export interface ReviewAnchorTerm {
|
|
10
|
+
kind: 'quote' | 'acceptance' | 'section';
|
|
11
|
+
label: string;
|
|
12
|
+
value: string;
|
|
13
|
+
}
|
|
14
|
+
export declare function normalizeReviewText(value: string): string;
|
|
15
|
+
export declare function reviewAnchorTerms(item: ReviewItem): ReviewAnchorTerm[];
|
|
16
|
+
export declare function reviewTargetElements(root: HTMLElement, item: ReviewItem): HTMLElement[];
|
|
17
|
+
export declare function reviewSourceSnippets(markdown: string, item: ReviewItem): ReviewSourceSnippet[];
|
|
18
|
+
//# sourceMappingURL=review-anchors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"review-anchors.d.ts","sourceRoot":"","sources":["../../../src/client/review-anchors.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAGhD,eAAO,MAAM,mBAAmB,8CAA8C,CAAA;AAE9E,MAAM,WAAW,mBAAmB;IAClC,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,CAAC,EAAE,MAAM,CAAA;CACd;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,OAAO,GAAG,YAAY,GAAG,SAAS,CAAA;IACxC,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;CACd;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEzD;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,UAAU,GAAG,gBAAgB,EAAE,CAQtE;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,UAAU,GAAG,WAAW,EAAE,CAWvF;AAED,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,mBAAmB,EAAE,CAwC9F"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow.d.ts","sourceRoot":"","sources":["../../../src/client/workflow.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAElF,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,OAAO,CAAA;AACrD,MAAM,MAAM,eAAe,GACvB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,QAAQ,CAAA;CAAE,
|
|
1
|
+
{"version":3,"file":"workflow.d.ts","sourceRoot":"","sources":["../../../src/client/workflow.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAElF,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,OAAO,CAAA;AACrD,MAAM,MAAM,eAAe,GACvB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,GACnD;IAAE,IAAI,EAAE,gBAAgB,CAAA;CAAE,GAC1B;IAAE,IAAI,EAAE,gBAAgB,CAAC;IAAC,UAAU,EAAE,UAAU,CAAA;CAAE,GAClD;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,GACnB;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,IAAI,EAAE,eAAe,CAAA;CAAE,GAC1C;IAAE,IAAI,EAAE,gBAAgB,CAAA;CAAE,GAC1B;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAA;AAEpB,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,WAAW,EAAE,MAAM,CAAA;IACnB,OAAO,EAAE,eAAe,CAAA;IACxB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB;AAID,wBAAgB,aAAa,CAAC,WAAW,EAAE,eAAe,EAAE,eAAe,EAAE,eAAe,GAAG,aAAa,CAmG3G;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAYzD"}
|