fix(runtime): provide current delivery evidence after reviewed application
This commit is contained in:
@@ -2,6 +2,10 @@
|
||||
|
||||
## I 修复启动
|
||||
|
||||
I-B首2项真实文件/检查专项通过,证明旧检查失效、应用SHA、当前计划/检查到Git预览建议和用户再次修改阻断,快照本身没有执行检查或提交。构建与编译宿主10组原交接UI通过(整批应用、显式续接、真实Node检查及两视口预算诊断)。下一补最终编译API完整检查/Git及实际Harness,尚不把建议快照当真实模型交付。
|
||||
|
||||
I-A小步提交3659f5e8。更广模型/引擎/交付开发轮90/90通过,保持其开发轮含义;I-B开始新增当前应用SHA/检查计划/下一可验证动作快照,宿主原权限不改变。两次猜测共享checks模块不存在、补丁最后锚点不匹配均在生效前纠正;后续按现有CheckRunner.planFor复用封存校验,不重复造检查契约。
|
||||
|
||||
I-A独立切片准备本地提交:76相关、16补充、构建与3组UI均已通过,更广引擎/交付回归作为开发回归保留不冒充最终冻结轮。一次计划更新补丁因findings标题锚点错误被原子拒绝,改为准确计划锚点;无部分应用。
|
||||
|
||||
I-A补充16/16与tsc/网页/手机/服务构建通过。编译宿主的身份界面3组通过:严格策略和双别名保存刷新、首不一致在工具前暂停并保存20报告tokens、刷新及两视口原响应下载SHA核对、账本同源显示;桌面及390px截图实际目视通过。广泛引擎/交付回归仍运行,正式未部署。原模型中心UI验收器两处旧标签随产品“请求模型名称”改名,避免把请求标签继续写作实际底层型号。
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
import {readText} from '../../server/files.mjs';
|
||||
import {inspectProject} from '../project-inspector.mjs';
|
||||
import {taskContract} from '../../shared/contracts/task-control.mjs';
|
||||
import {pendingDeliveryReview} from '../../shared/contracts/delivery-review.mjs';
|
||||
|
||||
// A fresh, bounded observation for the next request. It grants no permission:
|
||||
// checks, proofs and Git still validate their original contracts at execution.
|
||||
export async function taskDeliveryProgress(store,session,run,{checks,worker=false,taskPlan=null}={}){
|
||||
if(run.purpose==='diagnostic')return null;
|
||||
const task=store.owned('task',run.taskId,session.id),project=store.project(session.projectId);
|
||||
const changes=session.changes.filter(change=>change.taskId===task.id&&change.status==='applied');
|
||||
if(!changes.length)return null;
|
||||
const latest=[...new Map(changes.map(change=>[change.path,change])).values()];
|
||||
const files=latest.slice(-24).map(change=>{
|
||||
let currentSha256=null,error=null;try{currentSha256=readText(project,change.path).sha256;}catch(cause){error=cause.message;}
|
||||
return {path:change.path,change_id:change.id,change_set_id:change.changeSetId??null,applied_sha256:change.sha256,
|
||||
current_sha256:currentSha256,current:currentSha256===change.sha256,...(error?{error}:{})};
|
||||
});
|
||||
const inspection=await inspectProject(project),owned=value=>value.taskId===task.id&&value.sessionId===session.id&&value.projectId===session.projectId;
|
||||
const plans=[...store.core.check_plan.values()].filter(owned),jobs=[...store.core.check_job.values()].filter(owned);
|
||||
const latestPlan=plans.at(-1),latestJob=jobs.at(-1);
|
||||
let planCurrent=false,planError=null;
|
||||
if(latestPlan)try{checks.planFor(session,latestPlan.id);planCurrent=latestPlan.fingerprint===inspection.fingerprint;}
|
||||
catch(cause){planError=cause.message;}
|
||||
const sourceCurrent=!!latestJob&&!latestJob.stale&&!latestJob.requiresVerification
|
||||
&&(latestJob.sourceFingerprint?latestJob.sourceFingerprint===inspection.sourceFingerprint:latestJob.fingerprint===inspection.fingerprint);
|
||||
const unknown=[...store.core.tool.values()].filter(value=>owned(value)&&value.requiresVerification).map(value=>value.id);
|
||||
const pending=session.changes.filter(change=>['pending','conflict'].includes(change.status)).map(change=>({id:change.id,path:change.path,status:change.status}));
|
||||
const review=pendingDeliveryReview(store,session),contract=taskContract(task);
|
||||
const snapshot={schemaVersion:1,kind:'task-delivery-progress',task_id:task.id,run_id:run.id,source_fingerprint:inspection.sourceFingerprint,
|
||||
semantics:'current_observations_not_authorization_or_delivery_proof',files,total_files:latest.length,files_truncated:latest.length>files.length,
|
||||
checks_policy:contract.checks,check_plan:latestPlan?{id:latestPlan.id,current:planCurrent,checks:latestPlan.checks.map(value=>value.name),error:planError}:null,
|
||||
latest_check:latestJob?{id:latestJob.id,plan_id:latestJob.planId,status:latestJob.status,current_source:sourceCurrent,
|
||||
stale:!!latestJob.stale||!sourceCurrent,results:latestJob.results.map(value=>({name:value.name,status:value.status,tests:value.tests,
|
||||
log_artifact_id:value.logArtifactId,log_sha256:store.core.artifact.get(value.logArtifactId)?.sha256??null}))}:null,
|
||||
remaining_plan_steps:taskPlan?.remaining_steps??[],plan_steps:taskPlan?.steps.map(step=>({key:step.key,kind:step.kind,status:step.status,blockers:step.blockers,proof_id:step.proof_id}))??[],
|
||||
pending_changes:pending,unknown_tool_ids:unknown,
|
||||
stage:null,next_action:null,execution_note:'建议只依据当前事实;实际操作仍核对原计划和权限,执行检查等待审批,Git只准备预览并交还审查。'};
|
||||
const next=(stage,tool,args={})=>{snapshot.stage=stage;snapshot.next_action=tool?{tool,arguments:args}:null;return snapshot;};
|
||||
if(pending.length||unknown.length||review)return next('awaiting_review_or_verification');
|
||||
if(snapshot.files_truncated||files.some(file=>!file.current))return next('applied_files_need_review');
|
||||
if(contract.checks==='skip')return next('checks_not_requested',worker?null:'delivery_report');
|
||||
if(!sourceCurrent||!latestJob){
|
||||
if(planCurrent)return next('ready_for_checks','run_checks',{plan_id:latestPlan.id});
|
||||
return next('needs_current_check_plan','plan_checks',latestPlan?.checks.length?{names:latestPlan.checks.map(value=>value.name)}:{});
|
||||
}
|
||||
if(latestJob.status!=='passed')return next('checks_need_repair');
|
||||
if(taskPlan?.configured&&!taskPlan.all_verified){
|
||||
for(const step of taskPlan.steps.filter(value=>value.status!=='verified'&&!value.blockers.length)){
|
||||
const evidence=step.kind==='checks'?latestJob:step.kind==='changes'?[...store.core.change_set.values()].findLast(value=>owned(value)
|
||||
&&value.direction==='apply'&&value.status==='completed'&&step.paths.every(path=>value.files.some(file=>file.path===path&&file.state==='after'))):null;
|
||||
if(evidence)return next('needs_plan_evidence','verify_task_step',{plan_id:taskPlan.plan_id,expected_revision:taskPlan.revision,step_key:step.key,evidence_id:evidence.id});
|
||||
}
|
||||
return next('needs_plan_evidence');
|
||||
}
|
||||
if(worker)return next('ready_for_parent_review');
|
||||
return next('ready_for_git_preview','plan_delivery');
|
||||
}
|
||||
@@ -28,6 +28,7 @@ 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, 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';
|
||||
import { pendingDeliveryReview } from '../shared/contracts/delivery-review.mjs';
|
||||
@@ -327,6 +328,7 @@ export class Runtime {
|
||||
config.inputImages=this.inputAttachments().images(session,task);
|
||||
if(config.inputImages.length&&config.mode==='demo')throw new Error('固定演示执行器不会读取图片;请连接并声明支持视觉的模型。');
|
||||
const taskPlan = task.currentTaskPlanId ? await this.taskPlanner().inspect(session, { candidates: false }) : null;
|
||||
const deliveryProgress = await taskDeliveryProgress(this.store, session, run.record, { checks: this.checkRunner(), worker: !!run.worker, taskPlan });
|
||||
const state = session.changes.filter(change => change.taskId === task.id || ['pending', 'conflict'].includes(change.status))
|
||||
.map(change => ({ path: change.path, status: change.status, id: change.id, changeSetId: change.changeSetId ?? null }));
|
||||
const unknown = [...this.store.core.tool.values()].filter(tool => tool.taskId === task.id && tool.requiresVerification)
|
||||
@@ -341,6 +343,7 @@ export class Runtime {
|
||||
goal: taskContract(task).goal, instructions: task.instructions.filter(instruction => instruction.source !== 'review-action'), constraints: task.constraints ?? [], acceptance: task.acceptance ?? [], contract: taskContract(task),
|
||||
}) + (run.record.purpose === 'diagnostic' ? '\n本次仅回答运行诊断问题,允许读取所属结果;不得修改文件、执行命令或将解释视为原任务交付。诊断问题:' + run.record.question : '')
|
||||
+ '\n结果未知的调用,不得假定成功或重放:' + JSON.stringify(unknown)
|
||||
+ (deliveryProgress ? '\n已应用修改后的当前交付依据(每次请求重新核对,非操作授权):\n' + JSON.stringify(deliveryProgress) : '')
|
||||
+ (fileResults.results.length || fileResults.sources.length ? '\n当前成果与可显式采用的旧来源(任务数据,原文件不等于新写入):' + JSON.stringify({
|
||||
current: fileResults.results.slice(0, 8).map(row => ({ id: row.id, taskId: row.taskId, runId: row.runId, verification: row.verification, error: row.error, reason: row.reason, files: row.files.map(({ path, sha256, origin }) => ({ path, sha256, origin })) })),
|
||||
sources: fileResults.sources.slice(0, 4),
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import {fixture} from './helpers.mjs';
|
||||
import {createDeliveryProject,applyDeliveryFix,deliveryGit} from './fixtures/delivery-project.mjs';
|
||||
import {CheckRunner} from '../src/core/check-runner.mjs';
|
||||
import {taskDeliveryProgress} from '../src/core/context/delivery-progress.mjs';
|
||||
|
||||
test('reviewed application invalidates old checks, names current SHA and advances through a new approved check to Git preview',async t=>{
|
||||
const f=fixture(t),run=createDeliveryProject(f),checks=new CheckRunner(f.store);f.onCleanup(()=>checks.stopAll());
|
||||
const snapshot=()=>taskDeliveryProgress(f.store,f.session,run,{checks});
|
||||
assert.equal(await snapshot(),null);const before=deliveryGit(f,['rev-parse','HEAD']);
|
||||
const original=await checks.plan(f.session);await(await checks.start(f.session,original.id)).promise;
|
||||
applyDeliveryFix(f);let progress=await snapshot();assert.equal(progress.stage,'needs_current_check_plan');
|
||||
assert.equal(progress.latest_check.stale,true);assert.ok(progress.files.every(file=>file.current&&file.current_sha256===file.applied_sha256));
|
||||
assert.deepEqual(progress.next_action,{tool:'plan_checks',arguments:{names:['test','build']}});
|
||||
const plan=await checks.plan(f.session);progress=await snapshot();assert.equal(progress.stage,'ready_for_checks');
|
||||
assert.deepEqual(progress.next_action,{tool:'run_checks',arguments:{plan_id:plan.id}});assert.equal(f.store.core.check_job.size,1,'snapshot never executes a check');
|
||||
const passed=await(await checks.start(f.session,plan.id)).promise;assert.equal(passed.status,'passed');
|
||||
progress=await snapshot();assert.equal(progress.stage,'ready_for_git_preview');assert.equal(progress.latest_check.current_source,true);
|
||||
assert.equal(progress.next_action.tool,'plan_delivery');assert.equal(deliveryGit(f,['rev-parse','HEAD']),before,'snapshot cannot publish a commit');
|
||||
fs.appendFileSync(path.join(f.projectRoot,'src/math.mjs'),'// owner changed\n');progress=await snapshot();
|
||||
assert.equal(progress.stage,'applied_files_need_review');assert.equal(progress.next_action,null);assert.equal(progress.files.find(file=>file.path==='src/math.mjs').current,false);
|
||||
});
|
||||
|
||||
test('skip-tests, foreign task, unknown operations, diagnostic and parent review retain their boundaries',async t=>{
|
||||
const f=fixture(t),run=createDeliveryProject(f),checks=new CheckRunner(f.store);f.onCleanup(()=>checks.stopAll());applyDeliveryFix(f);
|
||||
const task=f.store.core.task.get(f.session.taskId);task.contract={...task.contract,checks:'skip'};
|
||||
const snapshot=options=>taskDeliveryProgress(f.store,f.session,run,{checks,...options});
|
||||
assert.equal((await snapshot()).stage,'checks_not_requested');assert.equal((await snapshot()).next_action.tool,'delivery_report');
|
||||
assert.equal((await snapshot({worker:true})).next_action,null);assert.equal(f.store.core.check_plan.size,0);
|
||||
assert.equal(await taskDeliveryProgress(f.store,f.session,{...run,purpose:'diagnostic'},{checks}),null);
|
||||
f.session.changes[0].taskId='foreign-task';assert.equal((await snapshot()).files.length,1);
|
||||
const id='owned-unknown';f.store.core.tool.set(id,{id,sessionId:f.session.id,projectId:f.project.id,taskId:task.id,requiresVerification:true});
|
||||
assert.equal((await snapshot()).stage,'awaiting_review_or_verification');assert.equal((await snapshot()).next_action,null);
|
||||
});
|
||||
Reference in New Issue
Block a user