feat(tasks): preserve reviewable original-text drafts and scope agreements
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
# 1.25 接续 C:要求草案与范围约定
|
||||
|
||||
本切片接续已交付1.24.9的手动要求复核与单轮shadow。目标是在现有Task/要求账本内整理原文草案、明确文件用途/禁止事项/待澄清内容,并把诊断与当前目标缺口连接起来。开发期正式仍1.24.9/原PID36552/Provider;未独立发行或升级,不能以开发验证宣称1.25交付。
|
||||
|
||||
## 阶段一:草案与原文契约
|
||||
|
||||
新增本地有界原文分段,保留用户来源实例ID、原范围、SHA和原工件;没有模型调用,不推断文件名的用途或生成通过结论。草案默认全部待澄清;用户审阅后可记为业务要求、参考、禁止或未知。业务要求沿用五类实际证据;参考只记录用途,禁止只记录边界,两者不计工程通过。未知阻止复核完成,明确no-test仍由原Task约定判断,不能从草案或参考文字增权。
|
||||
|
||||
草案与当前Task/Run、要求修订和全来源SHA绑定;重复请求复用原草案,旧来源/运行/修订与篡改拒绝。采用不能静默丢弃原分段,超过24项/20000字符时保留截断和未审阅来源;每Task最多12份草案。显式来源审阅只核销用户选择的来源;手动要求、旧账本和原证据继续兼容。手机及受限worker没有新增要求写入权限。
|
||||
|
||||
首相关21项20通过/1失败:新HTTP用例在宿主尚未重建时返回旧“接口不存在”;原日志`.qa/task-agreement/backend-first.tap`保留。重建宿主后原测试/断言不变,21/21通过,含HTTP实际重启复用、跨Task、全来源变化、原工件篡改、截断、范围分类和旧证据保持。复验日志`backend-recheck.tap`,无真实模型请求。
|
||||
|
||||
阶段回顾:草案是用户审阅的起点,不是语义提取准确率或自主交付证明。禁止事项的文字记录不代表已经验证遵守,既有文件/检查/Git和审批硬门保持。下一完成实际审阅界面、诊断与报告,独立发行/安装/正式保持与最终证据另验。
|
||||
@@ -1,5 +1,11 @@
|
||||
# 汇总发现
|
||||
|
||||
## 1.25接续
|
||||
|
||||
原HTTP测试实际启动dist-server/server.mjs,产品模块改动后须先重建宿主;不能把源码直测与编译HTTP入口混为同一来源。新增草案采用要求逐原范围仍被归类(未知也可)且显式记录来源审阅,参考与禁止仅是范围记录,未知仍阻止完成。原基线证据保持,草案不生成文件/检查操作。
|
||||
|
||||
现有RequirementReview有原文范围/逐项修订/原工件核对及完成/Git门,但用户需手动录入;尚无草案来源身份、范围和禁止事项结构。草案必须可审阅而不自签验收,不能把原文提到的参考文件直接选作交付文件。既有报告可复用要求视图;诊断已有独立purpose,需要保留原目标并显示可行动缺口。
|
||||
|
||||
## A/B发行入口
|
||||
|
||||
本轮封存1089份110593145字节,离线及含manifest的1090份110936169字节Git索引逐原字节通过。12套实际A/B入口、30原快照/150原工件与调用参数/结果SHA配对核对;历史研究/A/B/V/T/R/P/O manifest和目录原字节保持。归档驱动是文本证据,离线验证不重放。自动草案/完整范围约定/诊断闭环与工具surface等仍未完整实现,不能用1.24.9发行代替整个1.25完成。
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
# 统一执行进度
|
||||
|
||||
## 1.25接续
|
||||
|
||||
阶段一草案与范围后端通过:本地原文分段/默认未知/来源SHA/原工件/显式审阅/截断与配额,业务证据与参考/禁止记录分开。首21项20过1失败因HTTP仍旧编译,重建后同断言21/21通过,原日志保留;无模型调用。界面已开始补入现有要求面板,首次完整构建通过,实际流程待验。
|
||||
|
||||
用户要求继续,核对f702b706干净来源与正式1.24.9既有身份,创建feat/task-agreement-1.25。读取计划与要求复核入口,剩余为原文草案/范围约定/诊断回到原目标,复用已有Task/证据硬门。真实模型预算0,不续跑历史失败,不碰真实Key或重启正式。首次宽批读截断和rg目录通配错误已改限定路径,session-catchup无待同步内容。
|
||||
|
||||
## A/B首批能力发行接续
|
||||
|
||||
最终封存通过:1089份110593145字节原材料、manifest SHA316f7d611b0994c0195c2e6405667c42bbf5511593832b25e76aaea451ff1228;首离线验证与Git索引1090份110936169字节全原字节通过,586输入/22编译/591独立输入、12套A/B UI、30原快照/150原工件核对。原研究/A/B/V/T/R/P/O证据无变化。阶段四1366ee32已提交,最终回顾/身份/验证器与证据按范围本地保存,不改发行或正式数据,不推送;整个1.25及真实模型/Purge未知继续保留。
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
import { planHash, planError } from '../../shared/contracts/task-plans.mjs';
|
||||
|
||||
export const REQUIREMENT_ROLES = ['requirement', 'reference', 'prohibition', 'unknown'];
|
||||
export function requirementSources(task) {
|
||||
return [{ kind: 'goal', id: task.id, text: task.goal, at: task.createdAt ?? null },
|
||||
...(task.instructions ?? []).filter(row => row.source !== 'review-action').map(row => ({ kind: 'instruction', id: row.id, text: row.content, at: row.createdAt ?? row.at ?? null }))]
|
||||
.map(row => ({ ...row, sha256: planHash({ kind: row.kind, id: row.id, text: row.text }) }));
|
||||
}
|
||||
export const sourceSetHash = sources => planHash(sources.map(({ kind, id, sha256 }) => ({ kind, id, sha256 })));
|
||||
export function sourceRange(value, sources) {
|
||||
if (!value || Object.keys(value).some(key => !['kind', 'id', 'start', 'end'].includes(key))) throw planError('要求来源字段无效。', 'input', 400);
|
||||
const original = sources.find(row => row.kind === value.kind && row.id === value.id), { start, end } = value;
|
||||
if (!original || !Number.isSafeInteger(start) || !Number.isSafeInteger(end) || start < 0 || end <= start || end > original.text.length)
|
||||
throw planError('要求来源必须是当前Task用户原文的有效范围。', 'input', 400);
|
||||
return { ...value, quote: original.text.slice(start, end), sourceSha256: original.sha256, at: original.at };
|
||||
}
|
||||
|
||||
// Local extraction only segments original user text. It infers neither file
|
||||
// permissions nor evidence or acceptance. Every segment starts unresolved.
|
||||
export function draftSegments(sources, { limit = 24, characters = 20000 } = {}) {
|
||||
const items = [], covered = []; let retained = 0, truncated = false;
|
||||
for (const source of sources) {
|
||||
let complete = true;
|
||||
const chunks = source.text.matchAll(/[^\n;;。]+[;;。]?/gu);
|
||||
for (const match of chunks) {
|
||||
const leading = match[0].length - match[0].trimStart().length;
|
||||
const text = match[0].trim(); if (!text) continue;
|
||||
const start = match.index + leading, end = start + text.length;
|
||||
if (items.length >= limit || retained + text.length > characters) { complete = false; truncated = true; break; }
|
||||
items.push({ key: 'draft_' + planHash({ id: source.id, start, end }).slice(0, 14), role: 'unknown',
|
||||
title: text.slice(0, 100), criterion: text.slice(0, 300),
|
||||
source: sourceRange({ kind: source.kind, id: source.id, start, end }, sources) });
|
||||
retained += text.length;
|
||||
}
|
||||
if (complete) covered.push(source.id);
|
||||
}
|
||||
return { items, covered_source_ids: covered, truncated, retained_characters: retained,
|
||||
note: '仅按原文分段,尚未推断验收范围或文件用途。请逐项审阅;待澄清内容不计为完成。' };
|
||||
}
|
||||
export const draftContract = row => ({ schemaVersion: 1, kind: 'requirement-draft', id: row.id, projectId: row.projectId,
|
||||
sessionId: row.sessionId, taskId: row.taskId, runId: row.runId, expectedRevision: row.expectedRevision,
|
||||
sourceSetSha256: row.sourceSetSha256, sources: row.sources, proposal: row.proposal, createdAt: row.createdAt });
|
||||
@@ -6,6 +6,8 @@ import { taskContract } from '../../shared/contracts/task-control.mjs';
|
||||
import { taskPlanInput, planHash, planError } from '../../shared/contracts/task-plans.mjs';
|
||||
import { readText } from '../../server/files.mjs';
|
||||
import { FileResults } from './file-results.mjs';
|
||||
import { REQUIREMENT_ROLES, requirementSources, sourceRange, sourceSetHash, draftSegments, draftContract } from './requirement-drafts.mjs';
|
||||
export { requirementSources } from './requirement-drafts.mjs';
|
||||
|
||||
const same = (a, b) => planHash(a) === planHash(b);
|
||||
const now = () => new Date().toISOString();
|
||||
@@ -17,28 +19,28 @@ const requiredText = (value, max) => {
|
||||
if (typeof value !== 'string' || !value.trim() || value.length > max || value.includes('\0')) throw planError('请填写有效的要求或复核说明。', 'input', 400);
|
||||
return value.trim();
|
||||
};
|
||||
export function requirementSources(task) {
|
||||
return [{ kind: 'goal', id: task.id, text: task.goal, at: task.createdAt ?? null },
|
||||
...(task.instructions ?? []).filter(row => row.source !== 'review-action').map(row => ({ kind: 'instruction', id: row.id, text: row.content, at: row.createdAt ?? row.at ?? null }))]
|
||||
.map(row => ({ ...row, sha256: planHash({ kind: row.kind, id: row.id, text: row.text }) }));
|
||||
}
|
||||
function itemInput(value, sources) {
|
||||
checkKeys(value, ['key', 'title', 'criterion', 'source', 'kind', 'tools', 'paths', 'checks', 'viewport_width', 'actions', 'method']);
|
||||
checkKeys(value.source, ['kind', 'id', 'start', 'end']);
|
||||
const original = sources.find(row => row.kind === value.source.kind && row.id === value.source.id);
|
||||
const { start, end } = value.source;
|
||||
if (!original || !Number.isSafeInteger(start) || !Number.isSafeInteger(end) || start < 0 || end <= start || end > original.text.length)
|
||||
throw planError('要求来源必须是当前Task用户原文的有效范围。', 'input', 400);
|
||||
checkKeys(value, ['key', 'title', 'criterion', 'source', 'kind', 'tools', 'paths', 'checks', 'viewport_width', 'actions', 'method', 'role']);
|
||||
const originalSource = sourceRange(value.source, sources), role = value.role ?? 'requirement';
|
||||
if (!REQUIREMENT_ROLES.includes(role)) throw planError('要求范围类别无效。', 'input', 400);
|
||||
if (role !== 'requirement') {
|
||||
if (!/^[a-z][a-z0-9_-]{0,39}$/.test(value.key ?? '') || value.method !== 'scope' || value.kind !== 'analysis'
|
||||
|| ['tools', 'paths', 'checks', 'viewport_width', 'actions'].some(key => value[key] !== undefined))
|
||||
throw planError('参考、禁止和待澄清内容只记录范围,不能携带证据或完成状态。', 'input', 400);
|
||||
return { key: value.key, role, title: requiredText(value.title, 100), criterion: requiredText(value.criterion, 300),
|
||||
kind: 'analysis', method: 'scope', source: originalSource };
|
||||
}
|
||||
const method = value.method ?? 'evidence';
|
||||
if (!['evidence', 'user', 'not_requested'].includes(method)) throw planError('复核方式无效。', 'input', 400);
|
||||
const { source, method: ignored, ...fields } = value;
|
||||
const { source, method: ignored, role: ignoredRole, ...fields } = value;
|
||||
// Reuse the existing bounded evidence scopes; a statement alone never passes.
|
||||
const step = taskPlanInput({ expected_revision: 0, steps: [{ ...fields, depends_on: [] }] }).steps[0];
|
||||
if (method === 'not_requested' && step.kind !== 'checks') throw planError('仅检查约定可记录为未执行。', 'input', 400);
|
||||
return { ...step, method, source: { ...source, quote: original.text.slice(start, end), sourceSha256: original.sha256, at: original.at } };
|
||||
return { ...step, ...(value.role ? { role } : {}), method, source: originalSource };
|
||||
}
|
||||
const ledgerContract = row => ({ schemaVersion: 1, kind: 'task-requirements', id: row.id, sessionId: row.sessionId, projectId: row.projectId,
|
||||
taskId: row.taskId, runId: row.runId, revision: row.revision, parentId: row.parentId, items: row.items, sources: row.sources, createdAt: row.createdAt });
|
||||
taskId: row.taskId, runId: row.runId, revision: row.revision, parentId: row.parentId, items: row.items, sources: row.sources, createdAt: row.createdAt,
|
||||
...(row.draftId ? { draftId: row.draftId, draftSha256: row.draftSha256 } : {}) });
|
||||
const proofContract = row => ({ schemaVersion: 1, kind: 'requirement-proof', id: row.id, sessionId: row.sessionId, projectId: row.projectId,
|
||||
taskId: row.taskId, runId: row.runId, key: row.key, requirementSha256: row.requirementSha256, requirementRevision: row.requirementRevision,
|
||||
evidenceId: row.evidenceId, outcome: row.outcome, sourceFingerprint: row.sourceFingerprint, status: row.status, error: row.error,
|
||||
@@ -59,6 +61,25 @@ export class RequirementReview {
|
||||
this.store.core.artifact.set(artifact.id, artifact);
|
||||
return { ...row, contractArtifactId: artifact.id, contractSha256: artifact.sha256 };
|
||||
}
|
||||
createDraft(session, input) { return this.planner.mutate(session, 'user', async () => {
|
||||
checkKeys(input, ['expected_revision', 'source_set_sha256']);
|
||||
const { task, run } = this.planner.task(session), previous = this.current(session), sources = requirementSources(task);
|
||||
if (previous) this.verifyRecord(session, previous, 'task-requirements', ledgerContract);
|
||||
if (input.expected_revision !== (previous?.revision ?? 0) || input.source_set_sha256 !== sourceSetHash(sources))
|
||||
throw planError('原文来源或要求修订已变化,请刷新后整理草案。', 'stale');
|
||||
const existing = task.requirementDrafts?.findLast(row => row.runId === run.id && row.expectedRevision === input.expected_revision && row.sourceSetSha256 === input.source_set_sha256);
|
||||
if (existing) { this.verifyRecord(session, existing, 'requirement-draft', draftContract); return existing; }
|
||||
if ((task.requirementDrafts?.length ?? 0) >= 12) throw planError('草案已到12份上限,请手动核对原文,不自动丢弃旧草案。');
|
||||
const pending = sources.filter(source => !previous?.sources.some(row => row.id === source.id && row.sha256 === source.sha256));
|
||||
const proposal = draftSegments(pending.length ? pending : sources);
|
||||
await verifyWorkspaceProject(this.store, this.store.project(session.projectId));
|
||||
if (session.taskId !== task.id || session.runId !== run.id || this.current(session)?.id !== previous?.id || input.source_set_sha256 !== sourceSetHash(requirementSources(task)))
|
||||
throw planError('整理期间原任务、来源或修订已变化。', 'stale');
|
||||
const draft = this.write(session, run, { id: randomUUID(), projectId: session.projectId, sessionId: session.id, taskId: task.id, runId: run.id,
|
||||
expectedRevision: input.expected_revision, sourceSetSha256: input.source_set_sha256, sources, proposal, createdAt: now() }, 'requirement-draft', draftContract);
|
||||
(task.requirementDrafts ??= []).push(draft); this.store.save(session, { type: 'task.requirement_draft', detail: { id: draft.id } });
|
||||
return draft;
|
||||
}); }
|
||||
async evidence(session, item, id, inspection) {
|
||||
if (item.kind === 'results') {
|
||||
const result = new FileResults(this.store).verify(session, id, { current: false });
|
||||
@@ -84,13 +105,31 @@ export class RequirementReview {
|
||||
return outcome;
|
||||
}
|
||||
save(session, input) { return this.planner.mutate(session, 'user', async () => {
|
||||
checkKeys(input, ['expected_revision', 'requirements']);
|
||||
checkKeys(input, ['expected_revision', 'requirements', 'source_set_sha256', 'reviewed_source_ids', 'draft_id']);
|
||||
const { task, run } = this.planner.task(session), previous = this.current(session), revision = previous?.revision ?? 0;
|
||||
if (previous) this.verifyRecord(session, previous, 'task-requirements', ledgerContract);
|
||||
if (input.expected_revision !== revision) throw planError('要求修订已变化,请刷新后保存。', 'stale');
|
||||
if (revision >= 24 || !Array.isArray(input.requirements) || !input.requirements.length || input.requirements.length > 24)
|
||||
throw planError('每个Task最多24项要求与24次修订。', 'input', 400);
|
||||
const sources = requirementSources(task), items = input.requirements.map(value => itemInput(value, sources));
|
||||
const explicitReview = input.source_set_sha256 !== undefined || input.reviewed_source_ids !== undefined || input.draft_id !== undefined;
|
||||
if (explicitReview && (input.source_set_sha256 !== sourceSetHash(sources) || !Array.isArray(input.reviewed_source_ids)
|
||||
|| new Set(input.reviewed_source_ids).size !== input.reviewed_source_ids.length || input.reviewed_source_ids.some(id => !sources.some(row => row.id === id))))
|
||||
throw planError('原文来源已变化或审阅列表无效,请刷新原文后保存。', 'stale');
|
||||
let draft = null;
|
||||
if (input.draft_id) {
|
||||
draft = task.requirementDrafts?.find(row => row.id === input.draft_id);
|
||||
if (!draft) throw planError('草案不属于当前Task。');
|
||||
this.verifyRecord(session, draft, 'requirement-draft', draftContract);
|
||||
if (draft.runId !== run.id || draft.expectedRevision !== revision || draft.sourceSetSha256 !== sourceSetHash(sources))
|
||||
throw planError('草案对应旧来源、运行或要求修订,请重新整理。', 'stale');
|
||||
if (draft.proposal.truncated && input.reviewed_source_ids.some(id => !previous?.sources.some(row => row.id === id)
|
||||
&& !draft.proposal.covered_source_ids.includes(id))) throw planError('草案未覆盖完整原文,请手动审阅未收录来源。');
|
||||
// Each proposed original range must remain accounted for, even when the
|
||||
// user keeps it unknown. Nothing is silently dropped during adoption.
|
||||
if (draft.proposal.items.some(row => !items.some(item => item.source.id === row.source.id && item.source.start <= row.source.start && item.source.end >= row.source.end)))
|
||||
throw planError('草案仍有未归类原文,请保留待澄清项或手动核对全部来源。');
|
||||
}
|
||||
if (new Set(items.map(row => row.key)).size !== items.length || previous?.items.some(row => !items.some(item => item.key === row.key)))
|
||||
throw planError('要求ID需唯一;原要求不能删除,可修订并保留原记录。', 'input', 400);
|
||||
if (JSON.stringify(items).length > 24000) throw planError('要求范围过大,请缩小Task。', 'input', 400);
|
||||
@@ -104,14 +143,16 @@ export class RequirementReview {
|
||||
if (session.taskId !== task.id || session.runId !== run.id || this.current(session)?.id !== previous?.id || !same(sources, requirementSources(task)))
|
||||
throw planError('保存期间原任务、来源或要求已变化。', 'stale');
|
||||
const row = this.write(session, run, { id: randomUUID(), sessionId: session.id, projectId: session.projectId, taskId: task.id, runId: run.id,
|
||||
revision: revision + 1, parentId: previous?.id ?? null, items, sources, createdAt: now() }, 'task-requirements', ledgerContract);
|
||||
revision: revision + 1, parentId: previous?.id ?? null, items,
|
||||
sources: explicitReview ? sources.filter(row => input.reviewed_source_ids.includes(row.id)) : sources,
|
||||
...(draft ? { draftId: draft.id, draftSha256: draft.contractSha256 } : {}), createdAt: now() }, 'task-requirements', ledgerContract);
|
||||
(task.requirementRevisions ??= []).push(row);
|
||||
this.store.save(session, { type: 'task.requirements_saved', detail: { id: row.id, revision: row.revision } });
|
||||
return row;
|
||||
}); }
|
||||
async inspect(session, { candidates = false, inspection = null } = {}) {
|
||||
const { task, run } = this.planner.task(session), ledger = this.current(session), sources = requirementSources(task);
|
||||
const base = { configured: !!ledger, task_id: task.id, revision: ledger?.revision ?? 0, sources, items: [], all_resolved: false, binding_sha256: null,
|
||||
const base = { configured: !!ledger, task_id: task.id, revision: ledger?.revision ?? 0, sources, source_set_sha256: sourceSetHash(sources), items: [], all_resolved: false, binding_sha256: null,
|
||||
note: '证据核对只证明所选范围;模型完成答复不等于业务验收。' };
|
||||
if (!ledger) return { ...base, status: 'not_recorded', unreviewed_sources: sources.map(row => row.id) };
|
||||
try { this.verifyRecord(session, ledger, 'task-requirements', ledgerContract); }
|
||||
@@ -125,7 +166,9 @@ export class RequirementReview {
|
||||
let status = 'pending', error = null, outcome = null;
|
||||
try {
|
||||
if (!source || source.sha256 !== item.source.sourceSha256) throw planError('原用户来源已变化。', 'stale');
|
||||
if (item.method === 'not_requested') {
|
||||
if (item.method === 'scope') {
|
||||
status = item.role === 'unknown' ? 'scope_unknown' : item.role === 'reference' ? 'reference_recorded' : 'boundary_recorded';
|
||||
} else if (item.method === 'not_requested') {
|
||||
if (taskContract(task).checks !== 'skip') throw planError('当前检查约定已变化。', 'stale');
|
||||
status = 'not_requested';
|
||||
} else if (proof) {
|
||||
@@ -148,7 +191,7 @@ export class RequirementReview {
|
||||
...(candidates && item.method === 'evidence' ? { candidates: this.planner.candidates(session, item) } : {}) });
|
||||
}
|
||||
if (task.id !== session.taskId || run.id !== session.runId || ledger.id !== this.current(session)?.id) throw planError('核对期间Task/Run或要求已变化。', 'stale');
|
||||
const resolved = !unreviewed.length && items.every(row => ['evidence_verified', 'user_confirmed', 'not_requested'].includes(row.status));
|
||||
const resolved = !unreviewed.length && items.every(row => ['evidence_verified', 'user_confirmed', 'not_requested', 'reference_recorded', 'boundary_recorded'].includes(row.status));
|
||||
return { ...base, items, unreviewed_sources: unreviewed, status: resolved ? 'resolved' : 'incomplete', all_resolved: resolved,
|
||||
history: proofs.map(row => ({ id: row.id, key: row.key, revision: row.requirementRevision, status: row.status, error: row.error, at: row.createdAt, artifact_id: row.contractArtifactId })),
|
||||
contract_artifact_id: ledger.contractArtifactId, contract_sha256: ledger.contractSha256,
|
||||
@@ -160,7 +203,7 @@ export class RequirementReview {
|
||||
if (!ledger || ledger.revision !== input.expected_revision) throw planError('要求修订已变化,请刷新后复核。', 'stale');
|
||||
this.verifyRecord(session, ledger, 'task-requirements', ledgerContract);
|
||||
const item = ledger.items.find(row => row.key === input.key);
|
||||
if (!item || item.method === 'not_requested') throw planError('请选择需要复核的当前要求。');
|
||||
if (!item || ['not_requested', 'scope'].includes(item.method)) throw planError('请选择需要复核的当前要求。');
|
||||
if ((task.requirementProofs?.length ?? 0) >= 128) throw planError('复核记录已到上限,请缩小任务。');
|
||||
if (item.method === 'user' ? input.evidence_id !== undefined : input.note !== undefined) throw planError('用户确认和原证据核对不能混用。', 'input', 400);
|
||||
const note = item.method === 'user' ? requiredText(input.note, 1000) : null;
|
||||
|
||||
+4
-4
@@ -377,7 +377,7 @@ return async (request, response) => {
|
||||
}
|
||||
}
|
||||
if (method === 'POST' && workerForProject(store, session.projectId)
|
||||
&& /^(?:mcp|engines|research|workspaces|delivery|browser|browsing|preview|task-plans|task-proofs|requirements|requirement-proofs|file-results|task-checkpoints|collaborations|evaluations)(?:\/|-|$)/.test(action)) throw workerConflict('受限子任务只开放原目标的读取、范围内改动和已审批检查;此操作请返回父项目。');
|
||||
&& /^(?:mcp|engines|research|workspaces|delivery|browser|browsing|preview|task-plans|task-proofs|requirements|requirement-proofs|requirement-drafts|file-results|task-checkpoints|collaborations|evaluations)(?:\/|-|$)/.test(action)) throw workerConflict('受限子任务只开放原目标的读取、范围内改动和已审批检查;此操作请返回父项目。');
|
||||
if (method === 'GET' && action === 'evaluations') return json(response,runtime.evaluationManager().view(session));
|
||||
if (method === 'POST' && action === 'evaluations') {
|
||||
const batch=await runtime.evaluationManager().plan(session,await body(request));
|
||||
@@ -522,14 +522,14 @@ return async (request, response) => {
|
||||
if (url.searchParams.get('taskId') !== session.taskId) throw Object.assign(new Error('所选任务已变化,请刷新要求与证据。'), { status: 409 });
|
||||
return json(response, await runtime.requirementReview().inspect(session, { candidates: true }));
|
||||
}
|
||||
if (method === 'POST' && ['requirements', 'requirement-proofs'].includes(action)) {
|
||||
if (method === 'POST' && ['requirements', 'requirement-proofs', 'requirement-drafts'].includes(action)) {
|
||||
const { taskId, runId, ...input } = await body(request);
|
||||
if (!taskId || !runId || taskId !== session.taskId || runId !== session.runId) throw Object.assign(new Error('原任务或运行已变化,未修改其他任务要求。'), { status: 409 });
|
||||
const manager = runtime.requirementReview();
|
||||
const result = action === 'requirements' ? await manager.save(session, input) : await manager.verify(session, input);
|
||||
const result = action === 'requirements' ? await manager.save(session, input) : action === 'requirement-drafts' ? await manager.createDraft(session, input) : await manager.verify(session, input);
|
||||
const requirements = await manager.inspect(session, { candidates: true });
|
||||
if (taskId !== session.taskId || runId !== session.runId) throw Object.assign(new Error('保存结果属于原任务,请刷新当前任务。'), { status: 409 });
|
||||
return json(response, { session: store.publicSession(session), requirements, ...(action === 'requirement-proofs' ? { verification: result } : {}) });
|
||||
return json(response, { session: store.publicSession(session), requirements, ...(action === 'requirement-proofs' ? { verification: result } : action === 'requirement-drafts' ? { draft: result } : {}) });
|
||||
}
|
||||
if (method === 'GET' && action === 'file-results') return json(response, runtime.fileResults().inspect(session, { path: url.searchParams.get('path') }));
|
||||
if (method === 'POST' && ['file-results', 'file-results/complete'].includes(action)) {
|
||||
|
||||
@@ -1,5 +1,17 @@
|
||||
# Agent Workbench:核心代理能力研究与产品计划
|
||||
|
||||
## 当前:1.25 要求草案、范围约定与诊断闭环
|
||||
|
||||
从干净f702b706接续,正式保持1.24.9/原PID36552/Provider。沿用planning-with-files/product-ui-ux/frontend-design,复用现有Task与要求复核,不委派、不推送、不读取/复制/解密/重存Key,不重启正式;真实模型预算0,旧V/T/R/P/O与Purge未知保持。
|
||||
|
||||
1. [complete] 核对现有要求/Task约定/诊断与真实入口,范围及验收案例已记docs/TASK-AGREEMENT-C.md;草案只保留原文待审阅,参考文件不变成输出。
|
||||
2. [complete] 本地有界草案/来源修订/跨Task/篡改/HTTP重启及显式范围接到原账本,首21项20通过1失败(旧编译宿主)保留,重建后原21/21通过,阶段回顾后本地提交。
|
||||
3. [in_progress] 现有任务面板完成草案审阅、范围编辑/保存/刷新/迟到响应保护及桌面/390px和实际Electron验收,异常恢复与基础文件路径回归后回顾提交。
|
||||
4. [pending] 诊断绑定原失败/Task/Run,报告与任务显示同一当前缺口/下一步;不重放命令、不丢原目标或把诊断算交付,相关验证与回顾提交。
|
||||
5. [pending] 完整构建、冻结来源/独立发行/安装/保留状态正式升级、原证据封存/离线/索引复核、最终回顾与本地提交;按实际完成报告,不把localhost夹具当真实自主交付。
|
||||
|
||||
恢复首次宽读发生截断,随后限定已知文件短段;一次PowerShell rg目录通配失败改-g过滤。只读失败和截断不作验证通过。session-catchup无待同步输出,工作区干净。
|
||||
|
||||
## 当前:A/B首批能力1.24.9独立发行与保留状态升级
|
||||
|
||||
用户在下一步说明后授权“全量开发”,本轮完整推进A/B首批能力发行,不把尚缺自动草案提取/完整范围约定/诊断闭环的1.25标成完成。沿用planning-with-files/product-ui-ux,不委派、不推送、不读取/复制/解密/重存真实Key,不重启正式Provider;真实模型预算0。
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { randomUUID } from 'node:crypto';
|
||||
import { fixture, launchWorkbench } from './helpers.mjs';
|
||||
import { beginPlanTask, completeRead } from './fixtures/task-plan-fixture.mjs';
|
||||
import { RequirementReview } from '../src/core/tasks/requirement-review.mjs';
|
||||
import { draftSegments, requirementSources, sourceSetHash } from '../src/core/tasks/requirement-drafts.mjs';
|
||||
|
||||
const create = async f => {
|
||||
const manager = new RequirementReview(f.store), view = await manager.inspect(f.session);
|
||||
const draft = await manager.createDraft(f.session, { expected_revision: view.revision, source_set_sha256: view.source_set_sha256 });
|
||||
return { manager, view, draft };
|
||||
};
|
||||
const scope = row => ({ key: row.key, title: row.title, criterion: row.criterion, role: row.role, kind: 'analysis', method: 'scope',
|
||||
source: { kind: row.source.kind, id: row.source.id, start: row.source.start, end: row.source.end } });
|
||||
const input = (view, draft, rows = draft.proposal.items.map(scope)) => ({ expected_revision: view.revision, source_set_sha256: view.source_set_sha256,
|
||||
reviewed_source_ids: view.sources.map(row => row.id), draft_id: draft.id, requirements: rows });
|
||||
|
||||
test('local draft preserves exact original ranges and duplicate source instances without inferring outputs or accepting facts', async t => {
|
||||
const f = fixture(t); beginPlanTask(f, '参考 README.md;仅说明如何修改,不执行修改。无需测试。');
|
||||
const task = f.store.core.task.get(f.session.taskId);
|
||||
task.instructions.push({ id: randomUUID(), source: 'user', content: task.goal, createdAt: new Date().toISOString() });
|
||||
const history = structuredClone(f.session.providerMessages), { manager, view, draft } = await create(f);
|
||||
assert.equal((await manager.inspect(f.session)).configured, false); assert.equal(task.requirementProofs, undefined);
|
||||
assert.ok(draft.proposal.items.length >= 6); assert.equal(draft.proposal.truncated, false);
|
||||
for (const item of draft.proposal.items) {
|
||||
const source = view.sources.find(row => row.id === item.source.id);
|
||||
assert.equal(item.source.quote, source.text.slice(item.source.start, item.source.end));
|
||||
assert.equal(item.role, 'unknown'); assert.equal(item.paths, undefined); assert.equal(item.evidence, undefined);
|
||||
}
|
||||
assert.notEqual(draft.proposal.items[0].source.sourceSha256, draft.proposal.items.at(-3).source.sourceSha256);
|
||||
assert.equal((await manager.createDraft(f.session, { expected_revision: 0, source_set_sha256: view.source_set_sha256 })).id, draft.id);
|
||||
assert.equal(task.requirementDrafts.length, 1); assert.deepEqual(f.session.providerMessages, history);
|
||||
assert.equal(f.session.changes.length, 0); assert.equal(f.store.core.check_job.size, 0);
|
||||
});
|
||||
|
||||
test('review keeps unknown blocking, references distinct from output and boundaries distinct from compliance evidence', async t => {
|
||||
const f = fixture(t); beginPlanTask(f, '参考 README.md;禁止修改原文件;交付范围待澄清。');
|
||||
const { manager, view, draft } = await create(f);
|
||||
const rows = draft.proposal.items.map((row, i) => scope({ ...row, role: ['reference', 'prohibition', 'unknown'][i] }));
|
||||
await manager.save(f.session, input(view, draft, rows));
|
||||
const current = await manager.inspect(f.session);
|
||||
assert.deepEqual(current.items.map(row => row.status), ['reference_recorded', 'boundary_recorded', 'scope_unknown']);
|
||||
assert.equal(current.all_resolved, false); assert.equal(f.store.core.task.get(f.session.taskId).requirementProofs, undefined);
|
||||
await assert.rejects(manager.verify(f.session, { expected_revision: 1, key: rows[0].key, evidence_id: randomUUID() }), /需要复核/);
|
||||
await assert.rejects(manager.assertReady(f.session), /待复核/);
|
||||
});
|
||||
|
||||
test('draft adoption must account for every original range and does not fill paths from a reference', async t => {
|
||||
const f = fixture(t); beginPlanTask(f, '参考README.md;修改notes.md。'); const { manager, view, draft } = await create(f);
|
||||
await assert.rejects(manager.save(f.session, input(view, draft, [scope(draft.proposal.items[0])])), /未归类原文/);
|
||||
const rows = draft.proposal.items.map(scope);
|
||||
rows[1] = { ...rows[1], role: 'requirement', kind: 'results', method: 'evidence', paths: [] };
|
||||
await assert.rejects(manager.save(f.session, input(view, draft, rows)), /文件路径/);
|
||||
rows[1].paths = ['notes.md']; await manager.save(f.session, input(view, draft, rows));
|
||||
const current = await manager.inspect(f.session); assert.deepEqual(current.items[1].paths, ['notes.md']);
|
||||
assert.equal(current.items[1].status, 'pending'); assert.equal(current.items[0].status, 'scope_unknown');
|
||||
});
|
||||
|
||||
test('source and requirement changes, other Tasks and tampered draft bytes are rejected without losing originals', async t => {
|
||||
const f = fixture(t); beginPlanTask(f, '研究README.md。'); const { manager, view, draft } = await create(f);
|
||||
const task = f.store.core.task.get(f.session.taskId);
|
||||
task.instructions.push({ id: randomUUID(), source: 'user', content: '新增要求', createdAt: new Date().toISOString() });
|
||||
await assert.rejects(manager.save(f.session, input(view, draft)), /来源已变化/);
|
||||
const latest = await create(f), originalTitle = latest.draft.proposal.items[0].title;
|
||||
latest.draft.proposal.items[0].title = '伪造完成';
|
||||
await assert.rejects(manager.save(f.session, input(latest.view, latest.draft)), /原工件不一致/);
|
||||
latest.draft.proposal.items[0].title = originalTitle;
|
||||
const other = fixture(t); beginPlanTask(other, '另一个任务'); const independent = await create(other);
|
||||
await assert.rejects(independent.manager.save(other.session, { ...input(independent.view, independent.draft), draft_id: draft.id }), /不属于/);
|
||||
assert.equal(task.requirementDrafts.length, 2); assert.equal(task.requirementRevisions, undefined);
|
||||
});
|
||||
|
||||
test('partial explicit source review leaves the other source unreviewed while old file evidence remains valid', async t => {
|
||||
const f = fixture(t); beginPlanTask(f, '研究README.md'); const manager = new RequirementReview(f.store), read = completeRead(f);
|
||||
const first = { key: 'read', title: '原文依据', criterion: '当前读取', kind: 'analysis', tools: ['read_file'], method: 'evidence', source: { kind: 'goal', id: f.session.taskId, start: 0, end: 10 } };
|
||||
await manager.save(f.session, { expected_revision: 0, requirements: [first] }); await manager.verify(f.session, { expected_revision: 1, key: 'read', evidence_id: read.id });
|
||||
f.store.core.task.get(f.session.taskId).instructions.push({ id: randomUUID(), source: 'user', content: '新目标待确认' });
|
||||
const view = await manager.inspect(f.session);
|
||||
await manager.save(f.session, { expected_revision: 1, source_set_sha256: view.source_set_sha256, reviewed_source_ids: [f.session.taskId], requirements: [first] });
|
||||
const current = await manager.inspect(f.session); assert.equal(current.unreviewed_sources.length, 1); assert.equal(current.items[0].status, 'evidence_verified');
|
||||
assert.equal(current.all_resolved, false);
|
||||
});
|
||||
|
||||
test('bounded draft does not claim full source coverage and cannot acknowledge an omitted remainder', async t => {
|
||||
const f = fixture(t); beginPlanTask(f, Array.from({ length: 30 }, (_, i) => '第' + i + '项原文。').join(''));
|
||||
const { manager, view, draft } = await create(f); assert.equal(draft.proposal.items.length, 24); assert.equal(draft.proposal.truncated, true);
|
||||
assert.deepEqual(draft.proposal.covered_source_ids, []);
|
||||
await assert.rejects(manager.save(f.session, input(view, draft)), /未覆盖完整原文/);
|
||||
const sources = requirementSources(f.store.core.task.get(f.session.taskId)); assert.equal(sourceSetHash(sources), view.source_set_sha256);
|
||||
assert.equal(draftSegments(sources, { characters: 5 }).truncated, true);
|
||||
});
|
||||
|
||||
test('draft HTTP preserves its original artifact across restart and rejects stale scope and source versions', async t => {
|
||||
const f = fixture(t); beginPlanTask(f, '参考README.md,不修改。'); f.store.close();
|
||||
let host = await launchWorkbench(t, f.data); const base = '/sessions/' + f.session.id;
|
||||
const view = await host.api(base + '/requirements?taskId=' + f.session.taskId);
|
||||
const request = { taskId: f.session.taskId, runId: f.session.runId, expected_revision: 0, source_set_sha256: view.source_set_sha256 };
|
||||
await assert.rejects(host.api(base + '/requirement-drafts', { ...request, runId: randomUUID() }), /原任务或运行/);
|
||||
const generated = await host.api(base + '/requirement-drafts', request); assert.equal(generated.requirements.configured, false);
|
||||
const original = generated.draft; await host.close(); host = await launchWorkbench(t, f.data);
|
||||
const restored = await host.api(base + '/requirement-drafts', request); assert.deepEqual(restored.draft, original);
|
||||
const saved = await host.api(base + '/requirements', { taskId: f.session.taskId, runId: f.session.runId, ...input(view, original) });
|
||||
assert.equal(saved.requirements.items[0].status, 'scope_unknown');
|
||||
await assert.rejects(host.api(base + '/requirement-drafts', request), /修订/);
|
||||
await assert.rejects(host.api(base + '/requirements', { taskId: f.session.taskId, runId: f.session.runId, ...input(view, original) }), /修订/);
|
||||
});
|
||||
Reference in New Issue
Block a user