fix: retain source continuation and explain request reservation pauses

This commit is contained in:
Agent Workbench Dev
2026-11-04 00:45:53 +08:00
parent fbedb7381b
commit 5dcd6d7c3f
30 changed files with 439 additions and 81 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
import { randomUUID, createHash } from 'node:crypto';
export const APP_VERSION = '1.24.6';
export const APP_VERSION = '1.24.7';
export function executionEnvironment() {
const windows = process.platform === 'win32';
+1
View File
@@ -95,6 +95,7 @@ export function readText(project, relative) {
export function readLines(project, args) {
const file = readText(project, args.path);
if (args.expected_sha256 !== undefined && args.expected_sha256.toLowerCase() !== file.sha256) throw new Error('文件SHA256已变化,原分页不能继续拼接;请从新版本重新读取并核对。');
const lines = file.content.split('\n');
const start = Math.max(1, Number(args.start_line) || 1);
const end = Math.min(lines.length, start + 299, Math.max(start, Number(args.end_line) || start + 199));
+3 -3
View File
@@ -45,9 +45,9 @@ export const toolDefinitions = [
parameters: { type: 'object', properties: {}, required: [] } } },
{ type: 'function', function: { name: 'list_files', description: '查看当前项目的相对文件路径。依赖、版本目录、链接及常见凭据文件不会加入列表。',
parameters: { type: 'object', properties: { path: { type: 'string' }, depth: { type: 'integer', minimum: 0, maximum: 10 } }, required: ['path'] } } },
{ type: 'function', function: { name: 'read_file', description: '读取当前项目UTF-8文本与文件SHA256,行范围最多300行;实际页按当前请求预算缩小。分页用同一range_start_line/range_end_line和next_offset作为offset;此范围读完后用next_start_line继续。完整文件和原字节不变。',
{ type: 'function', function: { name: 'read_file', description: '读取项目UTF-8行与SHA256(最多300行),按预算分页。续读保持range_start_line/range_end_line,以next_offset为offset并传expected_sha256核对版本;范围读完用next_start_line。',
parameters: { type: 'object', properties: { path: { type: 'string' }, start_line: { type: 'integer' }, end_line: { type: 'integer' },
offset: { type: 'integer', minimum: 0 }, limit: { type: 'integer', minimum: 1, maximum: 16000 } }, required: ['path'] } } },
offset: { type: 'integer', minimum: 0 }, limit: { type: 'integer', minimum: 1, maximum: 16000 }, expected_sha256: { type: 'string', pattern: '^[a-fA-F0-9]{64}$' } }, required: ['path'] } } },
{ type: 'function', function: { name: 'search_files', description: '在当前项目的文本文件中按字面内容检索。结果声明已搜索文件数与数量上限。',
parameters: { type: 'object', properties: { query: { type: 'string' }, case_sensitive: { type: 'boolean' } }, required: ['query'] } } },
{ type: 'function', function: { name: 'propose_file', description: '提出一个文本文件的完整新内容。只产生待审查提案,不写入项目;由用户查看差异后应用。',
@@ -78,7 +78,7 @@ export function projectContext(project) {
'浏览器实际观察的controls.selector已在该DOM核对仅匹配一个元素,优先使用此定位并核对当前页面变化。按钮的nth-of-type可能在多个父元素各匹配一次,不能假定唯一。浏览器失败返回原错误;根据实际字段修正新计划,不重复读完的同一页。',
'检查结果含实际日志摘录及logArtifactId;需要更多失败信息时用read_artifact分段读取完整工件,不要要求用户重复提供工作台已有的日志。',
'若能力表提供浏览器工具,页面任务在构建后先用plan_browser/run_browser取得真实DOM与错误,按实际CSS定位交互和断言;观察或截图不代表通过。修复后重新构建并准备新计划验证,已有浏览器验收未通过时先处理再准备Git交付。',
'工作台会保留当前Task的代码与执行依据视图,绑定原工具结果和读取版本;可直接据此推进,不必反复恢复历史索引。内容有截取标记时按原结果工件取得缺少部分。',
'可直接使用当前Task的代码与执行依据视图。result_artifact_id只恢复已返回页;未读文件用read_file按原行范围和next_offset续读,expected_sha256核对版本,不拼接不同SHA。',
'最新完整工具组过大时,工作台发送可核验的最近工具反馈。先使用已返回状态继续;同一工程状态连续核对三次而未推进任务会暂停,不能把查询次数当成完成工作。',
'读取工件继续使用原artifact_id与next_offset;read_artifact这次返回的包装工具结果不是下一页入口。不要逐层读取包装或为了恢复已有代码而反复扫描历史索引。',
'文件已审核应用且实际检查通过后,可用plan_delivery准备Git提交预览。成功后工作台停止模型请求,等待用户在任务记录中审查并确认;不要继续查询提交状态,不把预览说成已提交。用delivery_report保存阶段证据;正式提交后的报告由工作台自动生成。',
+14 -3
View File
@@ -27,7 +27,7 @@ import { RequestPlanner, verifyPlanEvidence } from '../core/context/request-plan
import { ENGINE_SEED_RESERVATION } from '../shared/contracts/engine-context.mjs';
import { InputAttachments } from '../core/context/input-attachments.mjs';
import { BudgetResume } from '../core/context/budget-resume.mjs';
import { artifactPage, filePage, readMessageBudget, recordArtifactRead, recordBrowserRead, recordFileRead, recordUnchangedCheck, clearReadStreak, recordSessionInspection, recordUnchangedAction, readCoverageContext, readMetadataReserve, BROWSER_READ_HINT } from '../core/context/read-budget.mjs';
import { artifactPage, filePage, readMessageBudget, readBatchBudget, spendReadBudget, recordArtifactRead, recordBrowserRead, recordFileRead, recordUnchangedCheck, clearReadStreak, recordSessionInspection, recordUnchangedAction, readCoverageContext, readMetadataReserve, BROWSER_READ_HINT } from '../core/context/read-budget.mjs';
import { taskDeliveryProgress } from '../core/context/delivery-progress.mjs';
import { ChangeSetManager } from '../core/workspaces/change-sets.mjs';
import { assertChangeSetsResolved } from '../shared/contracts/change-sets.mjs';
@@ -119,6 +119,7 @@ export function validateToolArgs(tool, args) {
for (const field of required) if (typeof args[field] !== 'string') throw new Error('工具参数 ' + field + ' 必须是文本。');
for (const field of ['depth', 'start_line', 'end_line', 'offset', 'limit']) if (args[field] !== undefined && (!Number.isInteger(args[field]) || args[field] < 0)) throw new Error('工具参数 ' + field + ' 必须是非负整数。');
if (tool === 'read_file' && args.limit !== undefined && (args.limit < 1 || args.limit > 16000)) throw new Error('文件分页limit需要1到16000个字符。');
if (tool === 'read_file' && args.expected_sha256 !== undefined && (typeof args.expected_sha256 !== 'string' || !/^[a-f0-9]{64}$/i.test(args.expected_sha256))) throw new Error('文件续读expected_sha256需要64位SHA256。');
if (args.case_sensitive !== undefined && typeof args.case_sensitive !== 'boolean') throw new Error('case_sensitive 必须是布尔值。');
if (tool === 'plan_checks' && args.names !== undefined && (!Array.isArray(args.names) || args.names.some(name => typeof name !== 'string'))) throw new Error('检查脚本名称需要文本数组。');
if (tool === 'plan_delivery' && args.message !== undefined && typeof args.message !== 'string') throw new Error('提交说明需要文本。');
@@ -464,6 +465,9 @@ export class Runtime {
const calls = message.tool_calls ?? [];
if (run.worker && (calls.length > 16 || workerUsage(this.store, run.worker).toolCalls + calls.length > run.worker.budget.maxToolCalls)) throw new BudgetExceeded('worker_tool_limit', '子任务工具次数超出固定累计预算或单次16项上限;这批工具未执行,原响应和用量已保存。');
run.readMessageBytes = readMessageBudget(planned.record, message);
run.readBatchBudget = readBatchBudget(planned.record, message);
run.readPageCharacters = planned.record.budget.inputBudget - planned.record.nextReadFixedInputTokens
- (planned.record.workingRetentionTokens ?? 0) < 4096 ? 2000 : Infinity;
const previousIds = new Set(session.providerMessages.flatMap(item => (item.tool_calls ?? []).map(call => call.id)));
if (new Set(calls.map(call => call.id)).size !== calls.length || calls.some(call => previousIds.has(call.id))) throw new Error('模型返回了重复的工具调用 ID,请重新发送任务。');
session.providerMessages.push(message);
@@ -526,6 +530,7 @@ export class Runtime {
}
else if (signal.aborted) result = { status: 'interrupted', message: '用户停止了任务,这次调用没有执行。' };
else result = await this.executeTool(session, call, run);
spendReadBudget(run.readBatchBudget, call, result);
session.providerMessages.push({ role: 'tool', tool_call_id: call.id, content: JSON.stringify(result) });
if (call.function.name === 'prepare_change_set' && result.status === 'awaiting_review') preparedSets.add(result.change_set_id);
if (call.function.name === 'call_registered_mcp' && result.requires_verification) mcpReview = result.mcp_job_id;
@@ -625,7 +630,9 @@ export class Runtime {
const proofHint = !!this.store.core.task.get(run.taskId)?.currentTaskPlanId && PLAN_READ_TOOLS.includes(tool);
const readMetadata = { ...(proofHint ? { tool_invocation_id: event.invocationId } : {}),
...(tool === 'read_browser_result' ? { repeated_read_count: Number.MAX_SAFE_INTEGER, reading_hint: BROWSER_READ_HINT } : {}) };
const maximumMessageBytes = Math.max(1, (run.readMessageBytes ?? 16000) - readMetadataReserve(readMetadata));
const batch = run.readBatchBudget;
const pageBytes = batch?.remainingCalls ? Math.floor(batch.remainingBytes / batch.remainingCalls) : run.readMessageBytes ?? 16000;
const maximumMessageBytes = Math.max(1, pageBytes - readMetadataReserve(readMetadata));
if (!['act_browser_tab','prepare_environment','run_command', 'run_checks', 'run_browser'].includes(tool)) this.store.invocationState(session, event, 'running');
else this.store.save(session);
if (tool === 'inspect_session') result = { ...sessionSnapshot(session, run.project, run.config, value => this.provider.redact(value)), execution: this.store.executionSnapshot(session) };
@@ -765,7 +772,11 @@ export class Runtime {
}
else if (tool === 'list_files') result = listFiles(run.project, args.path, args.depth ?? 3, 500);
else if (tool === 'read_file') {
result = filePage(readLines(run.project, args), args, { callId: call.id, maximumMessageBytes });
result = filePage(readLines(run.project, args), args, { callId: call.id, maximumMessageBytes,
// Match the planner's complete-small-source retention boundary;
// returning a larger page that is immediately trimmed adds no useful
// throughput. The escaped JSON budget can still make this smaller.
...(run.readBatchBudget ? { maximumPageCharacters: run.readPageCharacters } : {}) });
recordFileRead(this.store.core.task.get(run.taskId), result, event.invocationId, run.id);
}
else if (tool === 'search_files') result = searchFiles(run.project, args);