fix: keep artifact pages observable and pause repeated context reads
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { randomUUID, createHash } from 'node:crypto';
|
||||
|
||||
export const APP_VERSION = '1.5.0';
|
||||
export const APP_VERSION = '1.5.1';
|
||||
|
||||
export function executionEnvironment() {
|
||||
const windows = process.platform === 'win32';
|
||||
|
||||
@@ -11,7 +11,7 @@ export const toolDefinitions = [
|
||||
{ type: 'function', function: { name: 'propose_patch', description: '按读取时的原文件SHA256,用唯一old_text锚点提出精确替换。所有替换基于同一原文且不得重叠;自动保留UTF-8 BOM和统一换行格式。只保存待审查提案,不写盘;哈希变化或锚点不唯一拒绝。', parameters: { type: 'object', properties: { path: { type: 'string' }, base_sha256: { type: 'string', pattern: '^[a-fA-F0-9]{64}$' }, reason: { type: 'string' }, edits: { type: 'array', minItems: 1, maxItems: 32, items: { type: 'object', properties: { old_text: { type: 'string', minLength: 1 }, new_text: { type: 'string' } }, required: ['old_text', 'new_text'], additionalProperties: false } } }, required: ['path', 'base_sha256', 'reason', 'edits'] } } },
|
||||
{ type: 'function', function: { name: 'plan_delivery', description: '为当前Task已经审核应用且实际检查通过的文件准备只读Git提交预览,保留其他暂存与工作区修改。只返回计划、路径、diff工件和署名,不提交;用户须在任务记录界面核对并确认。', parameters: { type: 'object', properties: { message: { type: 'string', maxLength: 1600, description: '本次本地提交说明;可省略并采用任务目标。' } } } } },
|
||||
{ type: 'function', function: { name: 'delivery_report', description: '从当前Task的源码指纹、实际检查、提交和Run用量生成JSON/Markdown证据报告工件,不执行项目命令。报告注明未检查/待审核/结果未知和业务需求未验收;运行中的报告为阶段快照。', parameters: { type: 'object', properties: {} } } },
|
||||
{ type: 'function', function: { name: 'read_artifact', description: '读取当前会话保存的实际执行工件或检查日志,按artifact_id校验归属和SHA256。可按offset/limit分段读取;每次最多16000字符。依据失败日志修复时使用,不重新执行检查。', parameters: { type: 'object', properties: { artifact_id: { type: 'string' }, offset: { type: 'integer', minimum: 0 }, limit: { type: 'integer', minimum: 1, maximum: 16000 } }, required: ['artifact_id'] } } },
|
||||
{ type: 'function', function: { name: 'read_artifact', description: '读取当前会话保存的实际执行工件或检查日志,校验归属和SHA256。offset/limit分页,默认2000字符,实际页按当前完整请求预算缩小;用返回的next_offset读取下一页,已读区间不要重复。完整原工件保留。优先读取实际结果/日志,不反复扫描更新的历史索引;不重新执行检查。', parameters: { type: 'object', properties: { artifact_id: { type: 'string' }, offset: { type: 'integer', minimum: 0 }, limit: { type: 'integer', minimum: 1, maximum: 16000 } }, required: ['artifact_id'] } } },
|
||||
{ type: 'function', function: { name: 'inspect_project', description: '识别当前工程的语言、入口、项目规则、npm脚本和只读Git基线;返回有界源文件指纹,不执行项目代码。', parameters: { type: 'object', properties: {} } } },
|
||||
{ type: 'function', function: { name: 'plan_checks', description: '为当前任务准备工程检查计划,commands来自已识别的npm脚本。返回plan id、脚本内容和工程指纹;不执行命令。', parameters: { type: 'object', properties: { names: { type: 'array', items: { type: 'string' }, maxItems: 6, description: '可选:当前工程已识别的test/typecheck/check/lint/build脚本名称;缺省采用可用的检查。' } } } } },
|
||||
{ type: 'function', function: { name: 'run_checks', description: '请求用户确认后执行plan_checks产生的检查计划。保存独立job、实际退出码、测试数量和日志工件;过期计划不执行,未报告测试数量不能记通过。', parameters: { type: 'object', properties: { plan_id: { type: 'string' } }, required: ['plan_id'] } } },
|
||||
|
||||
@@ -12,6 +12,7 @@ import { inspectProject } from '../core/project-inspector.mjs';
|
||||
import { GitDelivery } from '../core/git-delivery.mjs';
|
||||
import { ProjectIndex } from '../core/context/project-index.mjs';
|
||||
import { RequestPlanner } from '../core/context/request-plan.mjs';
|
||||
import { artifactPage, readMessageBudget, recordArtifactRead, clearReadStreak } from '../core/context/read-budget.mjs';
|
||||
import { ChangeSetManager } from '../core/workspaces/change-sets.mjs';
|
||||
import { assertChangeSetsResolved } from '../shared/contracts/change-sets.mjs';
|
||||
|
||||
@@ -130,7 +131,8 @@ export class Runtime {
|
||||
+ '\n当前任务目标与全部追加要求(用户任务数据,完整保留):\n' + JSON.stringify({
|
||||
goal: task.goal, instructions: task.instructions, constraints: task.constraints ?? [], acceptance: task.acceptance ?? [],
|
||||
}) + '\n结果未知的调用,不得假定成功或重放:' + JSON.stringify(unknown)
|
||||
+ '\n' + sessionContext(session, run.project, config, value => this.provider.redact(value)));
|
||||
+ '\n' + sessionContext(session, run.project, config, value => this.provider.redact(value))
|
||||
+ (task.readProgress?.warning ? '\n当前读取进展:' + task.readProgress.warning : ''));
|
||||
const planned = this.requestPlanner().prepare(session, run.record, config, { system: context, tools: toolDefinitions, stepId: stepRecord.id });
|
||||
if (planned.record.archivedGroups && !projectionLogged) {
|
||||
projectionLogged = true; session.compactions++;
|
||||
@@ -165,6 +167,7 @@ export class Runtime {
|
||||
signal.throwIfAborted();
|
||||
const message = response.message;
|
||||
const calls = message.tool_calls ?? [];
|
||||
run.readMessageBytes = readMessageBudget(planned.record, message);
|
||||
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);
|
||||
@@ -191,6 +194,8 @@ export class Runtime {
|
||||
signal.throwIfAborted();
|
||||
}
|
||||
this.store.finishStep(session, stepRecord);
|
||||
if (this.store.core.task.get(run.taskId).readProgress?.pause) throw new BudgetExceeded('no_progress',
|
||||
'模型连续重复读取已覆盖工件区间或更新的历史索引,未推进当前任务。已读取内容和原任务已保存,请核对结果或调整任务要求后继续。');
|
||||
}
|
||||
session.status = 'paused';
|
||||
run.stopReason = 'step_limit';
|
||||
@@ -250,9 +255,8 @@ export class Runtime {
|
||||
}
|
||||
else if (tool === 'read_artifact') {
|
||||
const artifact = this.store.owned('artifact', args.artifact_id, session.id), text = this.store.artifactStore.read(artifact);
|
||||
const offset = args.offset ?? 0, limit = Math.min(16000, Math.max(1, args.limit ?? 8000));
|
||||
result = { artifact_id: artifact.id, kind: artifact.kind, sha256: artifact.sha256, content: text.slice(offset, offset + limit), offset,
|
||||
total_characters: text.length, truncated: offset + limit < text.length };
|
||||
result = artifactPage(artifact, text, args, { callId: call.id, maximumMessageBytes: run.readMessageBytes ?? 16000 });
|
||||
recordArtifactRead(this.store.core.task.get(run.taskId), artifact, result, event.invocationId);
|
||||
}
|
||||
else if (tool === 'prepare_change_set') {
|
||||
const set = await this.changeSetManager().prepare(session, args.change_ids, { source: 'agent' });
|
||||
@@ -294,6 +298,7 @@ export class Runtime {
|
||||
else if (tool === 'run_command') result = await this.requestCommand(session, event, args, run);
|
||||
else throw new Error('当前能力表没有工具:' + tool);
|
||||
event.phase = ['denied', 'interrupted', 'unknown', 'unverified', 'stale'].includes(result.status) ? result.status : result.status === 'failed' ? 'failed' : 'completed';
|
||||
if (tool !== 'read_artifact' && !['error', 'interrupted', 'unknown', 'denied'].includes(result.status)) clearReadStreak(this.store.core.task.get(run.taskId));
|
||||
if (typeof result.stdout === 'string') { result.stdout = this.provider.redact(result.stdout); result.stderr = this.provider.redact(result.stderr ?? ''); }
|
||||
event.output = this.provider.redact(typeof result.stdout === 'string' ? result.stdout + (result.stderr ? '\n' + result.stderr : '') : JSON.stringify(result).slice(0, 16000));
|
||||
if (result.exit_code !== undefined) event.exitCode = result.exit_code;
|
||||
|
||||
@@ -337,6 +337,9 @@ export class Store extends EventEmitter {
|
||||
const goal = content || session.messages.find(message => message.role === 'user')?.content || session.title;
|
||||
task = createTask(session, goal, config, previous); this.core.task.set(task.id, task);
|
||||
} else if (content && (!resume || instructionSource)) task.instructions.push({ id: randomUUID(), content, createdAt: now(), ...(instructionSource ? { source: instructionSource } : {}) });
|
||||
if (task.readProgress) {
|
||||
task.readProgress.repeated = 0; task.readProgress.changingIndexes = []; task.readProgress.warning = null; task.readProgress.pause = false;
|
||||
}
|
||||
const run = createRun(session, task, config, resume ? previousRunId : null);
|
||||
this.core.run.set(run.id, run); task.activeRunId = run.id;
|
||||
session.taskId = task.id; session.runId = run.id; session.status = 'running';
|
||||
|
||||
Reference in New Issue
Block a user