feat: wire optional progress reminders to actual requests and verified readback
This commit is contained in:
@@ -241,6 +241,21 @@ return async (request, response) => {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (route === '/api/progress-reminders/settings') {
|
||||
if (method === 'GET') return json(response, { enabled: store.config.progressRemindersEnabled === true });
|
||||
if (method === 'POST') {
|
||||
const input = await body(request);
|
||||
if (!input || Object.keys(input).length !== 1 || typeof input.enabled !== 'boolean') throw new Error('进展提醒设置只接受开启或关闭。');
|
||||
store.saveConfig({ progressRemindersEnabled: input.enabled }); runtime.progressRemindersChanged();
|
||||
return json(response, { enabled: store.config.progressRemindersEnabled === true });
|
||||
}
|
||||
}
|
||||
const reminderRoute = route.match(/^\/api\/sessions\/([a-f0-9-]{36})\/progress-reminders$/i);
|
||||
if (method === 'GET' && reminderRoute) {
|
||||
const session = store.session(reminderRoute[1]), id = url.searchParams.get('run') || session.runId;
|
||||
const run = store.owned('run', id, session.id);
|
||||
return json(response, runtime.reminderManager().inspect(session, run));
|
||||
}
|
||||
if (method === 'GET' && route === '/api/operations') {
|
||||
return json(response, inspectOperations({ store, provider, runtime, server, appDirectory, version: APP_VERSION, parameters: url.searchParams }));
|
||||
}
|
||||
|
||||
+10
-3
@@ -1,4 +1,4 @@
|
||||
import { randomUUID } from 'node:crypto';
|
||||
import { randomUUID, createHash } from 'node:crypto';
|
||||
import { unrestricted, approvalLabels } from '../shared/contracts/execution-policy.mjs';
|
||||
import { listFiles } from './files.mjs';
|
||||
import { setTimeout as delay } from 'node:timers/promises';
|
||||
@@ -234,8 +234,15 @@ export class Provider {
|
||||
dispatched = true;
|
||||
const transport=this.fetcher?null:(this.transport??=new ModelTransport());
|
||||
if(transport)onProgress?.({phase:'running',transport:transport.profile,attempt,maxAttempts:policy.attempts,wireAttemptId:receipt.attemptId});
|
||||
const response = await (this.fetcher??transport.fetch.bind(transport))(requestUrl, { method: body ? 'POST' : 'GET', headers,
|
||||
body: body ? JSON.stringify(body) : undefined, signal: requestSignal, redirect: 'manual' });
|
||||
const wireBody = body ? JSON.stringify(body) : undefined;
|
||||
const submitted = (this.fetcher??transport.fetch.bind(transport))(requestUrl, { method: body ? 'POST' : 'GET', headers,
|
||||
body: wireBody, signal: requestSignal, redirect: 'manual' });
|
||||
if (wireBody && options.onSubmitted) {
|
||||
// Optional local observers cannot interrupt an already submitted HTTP
|
||||
// request or leave its promise unobserved.
|
||||
try { options.onSubmitted({ attemptId: receipt.attemptId, wireRequestSha256: createHash('sha256').update(wireBody).digest('hex') }); } catch { /* Observer only. */ }
|
||||
}
|
||||
const response = await submitted;
|
||||
// Never forward either credential header to a redirect target. The
|
||||
// observed response URL is diagnostic data; queries/credentials are removed.
|
||||
let responseUrl = null;
|
||||
|
||||
+35
-8
@@ -51,6 +51,7 @@ import { browserPlanInput } from '../shared/contracts/browser.mjs';
|
||||
import { TaskPlanManager } from '../core/tasks/task-plan-manager.mjs';
|
||||
import { RequirementReview } from '../core/tasks/requirement-review.mjs';
|
||||
import { recordTurnProgress } from '../core/context/turn-progress-recorder.mjs';
|
||||
import { ReminderManager } from '../core/context/reminder-manager.mjs';
|
||||
import { FileResults } from '../core/tasks/file-results.mjs';
|
||||
import { fileResultInput, fileResultToolDefinitions } from '../shared/contracts/file-results.mjs';
|
||||
import { verifiedCheck } from '../core/delivery-report.mjs';
|
||||
@@ -220,6 +221,15 @@ export class Runtime {
|
||||
redact: value => this.provider.redact(value), projectBusy: projectId => this.projectHasActivity(projectId) });
|
||||
}
|
||||
requestPlanner() { return this.contextPlans ??= new RequestPlanner(this.store); }
|
||||
reminderManager() { return this.progressReminders ??= new ReminderManager(this.store); }
|
||||
observeProgress(session, run, step, phase = 'settled', failure = null) {
|
||||
const observation = recordTurnProgress(this.store, session, run, step, phase, failure);
|
||||
if (observation) this.reminderManager().observe(session, run);
|
||||
return observation;
|
||||
}
|
||||
progressRemindersChanged() {
|
||||
for (const [id, run] of this.active) this.reminderManager().observe(this.store.session(id), run.record);
|
||||
}
|
||||
inputAttachments() { return this.inputs ??= new InputAttachments(this.store,{busy:projectId=>this.projectHasActivity(projectId)}); }
|
||||
budgetResumes(){return this.resumes??=new BudgetResume(this.store,this.provider,this);}
|
||||
resumeBudget(id,input){const session=this.store.session(id),plan=this.budgetResumes().verify(session,input);return this.start(id,'',true,{resumePlan:plan});}
|
||||
@@ -325,6 +335,7 @@ export class Runtime {
|
||||
const status = session.status;
|
||||
if (record.purpose === 'diagnostic') session.status = record.taskStatusBefore;
|
||||
this.store.finishRun(session, record, run.stopReason ?? null, { status });
|
||||
this.reminderManager().observe(session, record, { endReason: run.stopReason === 'cancelled' ? 'cancelled' : 'run_finished' });
|
||||
await this.finalizeDeliveryReport(session, run);
|
||||
} finally { this.active.delete(id); }
|
||||
});
|
||||
@@ -390,7 +401,7 @@ export class Runtime {
|
||||
if (current.sourceFingerprint === originalTask.stagnation.sourceFingerprint) throw new BudgetExceeded('no_progress', '连续两次运行未增加源码改动、检查结果或新的读取依据。本次未请求模型;请根据原日志修改源码或发送具体调整,避免重复空续接。');
|
||||
originalTask.stagnation = null;
|
||||
}
|
||||
recordTurnProgress(this.store, session, run.record, null, 'baseline');
|
||||
this.observeProgress(session, run.record, null, 'baseline');
|
||||
for (let step = 0; config.maxSteps === 0 || step < config.maxSteps; step++) {
|
||||
signal.throwIfAborted();
|
||||
checkBudget(run.record, this.store.core.task.get(run.taskId));
|
||||
@@ -477,8 +488,22 @@ export class Runtime {
|
||||
: !taskToolAllowed(task, run.record, name) ? 'disabled_by_task_contract' : 'disabled_by_execution_mode' });
|
||||
const projectMemory = await this.memoryManager().context(session, { redact: value => this.provider.redact(value) });
|
||||
signal.throwIfAborted();
|
||||
const planned = this.requestPlanner().prepare(session, run.record, config, { system: stablePrefix ? this.provider.redact(fixedContext) : context, contextTail: stablePrefix ? context : null, tools, toolSurface, stepId: stepRecord.id, projectMemory, skillCatalog, mcpCatalog,
|
||||
transportReservationTokens:run.worker?.engine?ENGINE_SEED_RESERVATION:0,engineStepOnly:!!run.worker?.engine });
|
||||
let reminder = config.mode === 'compatible' && !run.worker && (config.capacityMode === 'passthrough' || config.historyPolicy === 'preserve')
|
||||
? this.reminderManager().prepare(session, run.record, toolSurface) : null;
|
||||
const prepare = selected => this.requestPlanner().prepare(session, run.record, config, {
|
||||
system: stablePrefix ? this.provider.redact(fixedContext) : context + (selected ? '\n' + selected.message.content : ''),
|
||||
contextTail: stablePrefix ? context + (selected ? '\n' + selected.message.content : '') : null,
|
||||
progressReminder: selected?.ref ?? null, tools, toolSurface, stepId: stepRecord.id, projectMemory, skillCatalog, mcpCatalog,
|
||||
transportReservationTokens: run.worker?.engine ? ENGINE_SEED_RESERVATION : 0, engineStepOnly: !!run.worker?.engine });
|
||||
let planned;
|
||||
try { planned = prepare(reminder); }
|
||||
catch (error) {
|
||||
if (!reminder) throw error;
|
||||
// Optional advice may never be the reason a request is refused or
|
||||
// original history is removed. Retry planning once without advice;
|
||||
// no model request or tool has been dispatched at this point.
|
||||
reminder = null; this.reminderManager().error(session, run.record, 'request_plan'); planned = prepare(null);
|
||||
}
|
||||
if (planned.record.archivedGroups && !projectionLogged) {
|
||||
projectionLogged = true; session.compactions++;
|
||||
this.store.event(session, { kind: 'context', label: '整理请求上下文', phase: 'completed', contextPlanId: planned.record.id,
|
||||
@@ -541,7 +566,9 @@ export class Runtime {
|
||||
response = externalEngine
|
||||
? await this.engineRunner().complete(session, run, planned.messages, progressHandler, planned.record, tools)
|
||||
: await this.provider.complete(requestConfig, planned.messages, run.project, signal, progressHandler, planned.record, tools,
|
||||
{ ...(config.mode === 'demo' ? { demoHistory: providerHistory(session, run.record) } : {}), maxBudgetAttempts:planned.record.maxBudgetAttempts,beforeDispatch:({previousFailure}={})=>checkModelDispatchBudget(this.store,session,run.record,requestConfig,planned.body,0,previousFailure)});
|
||||
{ ...(config.mode === 'demo' ? { demoHistory: providerHistory(session, run.record) } : {}),
|
||||
...(reminder ? { onSubmitted: submission => this.reminderManager().dispatch(session, run.record, planned.record, submission) } : {}),
|
||||
maxBudgetAttempts:planned.record.maxBudgetAttempts,beforeDispatch:({previousFailure}={})=>checkModelDispatchBudget(this.store,session,run.record,requestConfig,planned.body,0,previousFailure)});
|
||||
if (response.compatibility?.length && requestEvent) { requestEvent.compatibility = response.compatibility; this.store.save(session); }
|
||||
this.requestPlanner().finish(session, planned.record, { response, attempts: planned.record.requestAttempts });
|
||||
if (run.worker && !externalEngine && !responseAccounted) {
|
||||
@@ -720,7 +747,7 @@ export class Runtime {
|
||||
return;
|
||||
}
|
||||
stepRecord.progressSettled = true;
|
||||
recordTurnProgress(this.store, session, run.record, stepRecord);
|
||||
this.observeProgress(session, run.record, stepRecord);
|
||||
if (!unrestricted(config) && this.store.core.task.get(run.taskId).readProgress?.pause) throw new BudgetExceeded('no_progress',
|
||||
'模型连续重复读取工件或核对相同的工程状态,未推进当前任务。实际结果和原任务已保存,请核对后继续。');
|
||||
}
|
||||
@@ -762,7 +789,7 @@ export class Runtime {
|
||||
} finally {
|
||||
if (currentStep && !currentStep.progressSettled) {
|
||||
currentStep.progressSettled = true;
|
||||
recordTurnProgress(this.store, session, run.record, currentStep, 'settled', session.lastFailure?.runId === run.id ? session.lastFailure : null);
|
||||
this.observeProgress(session, run.record, currentStep, 'settled', session.lastFailure?.runId === run.id ? session.lastFailure : null);
|
||||
}
|
||||
if (run.worker?.engine) await this.engineRunner().finish(session, run);
|
||||
}
|
||||
@@ -946,7 +973,7 @@ export class Runtime {
|
||||
...(check.python ? { python: { runtime: check.python.runtime, mode: check.python.mode } } : {}) })),
|
||||
reason: '执行工程检查计划 ' + plan.id.slice(0, 8) + ';保存测试数量、退出码和日志。' }, run, async () => {
|
||||
const { promise } = await this.checkRunner().start(session, plan.id, { signal: run.controller.signal, source: 'agent' });
|
||||
recordTurnProgress(this.store, session, run.record, [...this.store.core.step.values()].findLast(row => row.runId === run.id), 'waiting');
|
||||
this.observeProgress(session, run.record, [...this.store.core.step.values()].findLast(row => row.runId === run.id), 'waiting');
|
||||
const job = await promise;
|
||||
return { status: job.status === 'cancelled' ? 'interrupted' : job.status === 'passed' ? 'completed' : job.status,
|
||||
check_status: job.status, job_id: job.id, plan_id: job.planId, results: job.results, summary: job.summary,
|
||||
@@ -1016,7 +1043,7 @@ export class Runtime {
|
||||
session.approvals.push(approval);
|
||||
event.phase = 'waiting'; session.status = 'awaiting_approval';
|
||||
this.store.invocationState(session, event, 'waiting');
|
||||
recordTurnProgress(this.store, session, run.record, [...this.store.core.step.values()].findLast(row => row.runId === run.id), 'waiting');
|
||||
this.observeProgress(session, run.record, [...this.store.core.step.values()].findLast(row => row.runId === run.id), 'waiting');
|
||||
const policy = automaticApproval(this.store.config, args);
|
||||
approval.approvalMode = policy.mode; approval.policyRevision = this.store.config.configRevision;
|
||||
const decision = policy.approve ? (approval.status = 'approved', approval.decisionSource = policy.source, approval.decidedAt = now(), this.store.save(session), true) : await new Promise(resolve => {
|
||||
|
||||
Reference in New Issue
Block a user