feat: wire optional progress reminders to actual requests and verified readback

This commit is contained in:
Agent Workbench Dev
2026-11-06 16:05:21 +08:00
parent 7725cb2ad8
commit 01377b24c0
21 changed files with 686 additions and 22 deletions
+23
View File
@@ -1,5 +1,28 @@
# D:提醒与实际回读验收
## Runtime、设置与原始回读
第二切片已接入实际主模型请求、持久开关和原单轮观察面板。默认关闭;工具箱可开启/关闭并保存偏好,运行中关闭阻止后续建议,已提交请求的事实保留。只有明确文件任务符合条件,研究、诊断、worker/外部引擎及压缩历史不注入。提示放在动态尾部,原固定规则、工具和历史保留;可选提示规划失败时仅在发送前去掉提示重规划,不重放请求或工具。
发送前核对不可变context-plan、提醒原文、所属身份、原工具surface和请求SHA。Provider在实际fetch提交后记录attemptId及真实wire body SHA;网络失败仍只表示已随请求发出,不证明上游收到。回读核对原B收据和工具原结果,只有新增真实读取范围或原参数错误工具随后成功才解决。“明白”、跨Task、取消后迟到结果不核销。JSON/Markdown交付报告单列这些观察,不参与业务验收判断。队列、工件、规划或观察器故障与原执行隔离。
验证分来源保存于`.qa/reminder-readback-d/`:
- `runtime-round-3.tap`:35/35(纯队列10、当时Runtime10、原B15)。
- `integration-round-1.tap`:13/13(独立HTTP1、Runtime12,含原生Responses/Messages)。后端为candidate-2。
- `related-round-1.tap`:95/95,覆盖Runtime、请求计划、前缀、协议、存储;源码Runtime已含最后的不可变计划与报告补强,旧HTTP回归明确使用较早candidate-2,不混称最新后端。
- `final-backend-round-1.tap`:23/23(HTTP1、Runtime12、队列10);最后补强后另冻candidate-3,534输入,server SHA `2023af853ee7415044428de5fb42558c24f3f6f5d3901082915753bb940dd3c6`。
- `build-round-2.log`和`build-round-3.log`:完整TypeScript/Vite/mobile/server/desktop构建通过。
- 网页`web-34a9eda3-37a6-4fba-8fab-65389bd19c08/result.json`与实际Electron`electron-97cecbd5-5543-4711-af63-2735cbfb869d/result.json`各7组通过:默认关闭/保存/刷新、失败恢复、实际请求与回读、原工件入口、390px和宿主重启持久化。各6次本机固定HTTP、0页面错误、0真实模型。两端后端SHA为`a33704dab2dd3cef405768f57b0bcb55f670a5ea1b9c89628d3515bb595e1848`,位于最后后端补强之前;最终发行两端另验,不倒改这批来源。
实际查看了1440设置与390回读截图,沿用Orven三配色和现有任务记录。正式仍1.25.9,本切片尚未正式部署;独立源码/程序、安装及正式入口验收后另记交付。
## 原失败与回顾
`runtime-round-1.tap`因测试引用不存在的verifyContextPlan导出未加载,按真实公共函数verifyPlanEvidence修正。第二轮20项15过5失败,发现真产品问题:队列对字符串先JSON编码计算SHA,manager按原字符串SHA,导致已发出未记账/无冷却。已统一原字符串SHA;取消夹具另按原契约显式forceNewTask。`api-round-1.tap`使用修复前共享bundle仍失败,未放宽断言。candidate-1缺hot-upgrade/host-launcher被宿主登记拒绝(api-round-2),candidate-2补齐后通过。首构建错指项目内不存在的npm,实际构建未开始,原build-round-1保留。所有原日志及原B观察不重写。
本阶段增加的是可选、可核对的建议链,没有增加模型请求、恢复额度或自动审批停顿。固定HTTP证明实现契约;没有证明真实模型会减少重复读取、供应商更稳定或节省缓存/费用。历史真实交付、网络错误、unknown用量、AF拒绝及AG三网络失败保留,Purge收益仍unknown。下一完成1.25.10独立发行及保留状态升级,再按各自前置推进E/F,不重跑旧实验或用户项目。
## 第一源码切片
纯队列和原收据核对已实现,尚未接入Runtime、用户开关或正式程序。正式仍为Orven1.25.9,本切片不能称为用户功能已部署。
+4
View File
@@ -1323,3 +1323,7 @@ AI复核发现一处初始化异常边界:若只读观察器依赖的GitDelive
AI最终:该异常边界已隔离,真实git --version仍执行且退出0,独立记录观察故障。最终4131aae4的26/26通过,server135a2d97,输入保持;前一cbc28083上41相关及退出7边界1/1通过,来源分开。Git/报告核心未再改,正式1.25.8/PID71628/开放配置保持,没有实际供应商请求、旧样本续跑或正式写入;后续发行单独冻结来源。
D起点:1.25.9首次GitAtlas推送已逐SHA核对。B的observeTurn只接外显事实,recordTurnProgress保存不可变turn-progress-shadow及工具原结果引用;D复用这些来源,不以模型文字判采纳。候选必须原收据可核对、同Task/Run、无等待/新事实,提醒故障与原执行隔离。
D回顾:字符串SHA必须与请求计划同用原字节;只保存“准备发送”会漏掉真实重试/线路身份,现actual fetch后保存attemptId及wire SHA,并再核不可变context-plan。后续真实工具进展只证明时间上的对应,因果保持unproven。默认关闭时不生成建议收据/附加文字;最终独立23/23、相关95/95及两端各7组只证明实现契约,不证明真实模型收益。
D源码UI实际回看:已查看默认关闭的1440px设置窗口和390px真实回读。复用Orven三色变量/工具箱/任务观察,没有新增独立控制台;窄屏按钮均可达,因果未证实、原观察/实际请求/回读依据显示清楚。网页7组通过;独立backend-candidate-2/a33704da上的HTTP1项与源码Runtime12项共13/13通过。candidate-1漏hot-upgrade/host-launcher,宿主登记拒绝,原api-round-2保持;新候选补齐原宿主必需输入,不改守卫。
+10
View File
@@ -1971,3 +1971,13 @@ AI已封存84份29147488字节,163最终输入保持,离线复核成功收
Orven接续:推送会话28037退出0,远端feat/task-agreement-1.25=b35a4985e0a7533d0aa64f0296d23fc4c7fb1b50,与本地HEAD一致;工作树干净。已读D计划/Tianshu/1.25和B源模块,接续纯队列/来源验证。恢复时过量历史/文件清单输出截断,改限定src与短段,不把截断当完整验证;未修改原发行索引。
D第一源码切片:queue-round-1共25/25通过,新队列10+原B15;原TAP保留。纯队列不接模型文字,默认关闭、两次同事实重复、稳定key、送达/解决分离、自然解决/失效/冷却均已测;原收据验证提取复用。尚无Runtime/开关/UI接入,不宣称部署。恢复搜索两次Windows通配路径及猜测配置/组件路径未找到,已改限定真实目录,未改产品/正式数据。
D Runtime首轮:队列10项通过,Runtime测试文件因引用了不存在的verifyContextPlan导出而加载失败,原runtime-round-1.tap保留;实际公共函数为verifyPlanEvidence,已按原契约修正测试,不改产品接口。另一次猜测工件路径不存在,已用rg定位storage/artifact-store。
D Runtime第二轮原20项15过5失败,发现真实原文哈希差异:队列对字符串先JSON编码、planHash对字符串原字节,故实际已发出但建议未被记账/冷却。统一原字符串SHA后复验;取消夹具另须显式forceNewTask才能创建新Task,已按原契约修正。首构建命令错指项目内npm路径、未启动构建,保留build-round-1;实际Node24目录npm.cmd的build-round-2完整通过。
D API首轮调用的共享bundle来自哈希修复前,故提醒原文已发送但无delivered收据,0/1保持api-round-1.tap。改为从当前输入另建独立backend-candidate-1、保存输入与bundle SHA,后续HTTP显式指定候选,不放宽原断言。
D独立候选首轮缺hot-upgrade/host-launcher导致宿主登记拒绝,api-round-2保持;candidate-2补齐原必需输入后HTTP1+Runtime12共13/13通过,源码35/35通过,网页7组通过。已实际查看1440设置与390回读截图。复核后再补不可变context-plan归属核对及JSON/Markdown报告的独立提醒事实,未将提醒解决判为业务交付。
D第二切片收口:实际Electron7组同样通过,0页面错误/真实模型;相关95/95及最后补强后的candidate-3独立23/23通过(534输入,server2023af85)。网页/Electron原后端a33704da不冒称最后补强,最终发行载荷另验。已复核默认关闭、实际fetch提交与wire SHA、不可变计划/原B/工具回读、开关/取消/故障隔离及报告单列;原失败不改。准备定向提交,安全边界后只读核对Mnemo新证据消费协议,再准备1.25.10独立发行。
+122
View File
@@ -0,0 +1,122 @@
import fs from 'node:fs';
import path from 'node:path';
import net from 'node:net';
import assert from 'node:assert/strict';
import { createHash, randomUUID } from 'node:crypto';
import { chromium, _electron } from 'playwright';
import { fixture, compatibleFixture, launchWorkbench, until, call, completion } from '../tests/helpers.mjs';
import { HostController } from '../src/core/desktop/host-controller.mjs';
import { desktopExecutableIdentity } from '../src/core/desktop/app-installation.mjs';
import { projectEnvironment } from '../src/core/process-environment.mjs';
const actualElectron = process.argv.includes('--desktop'), appRoot = path.resolve(process.env.AGENT_WORKBENCH_QA_APP_ROOT || '.');
const directory = path.resolve(process.env.REMINDER_QA_OUTPUT || '.qa/reminder-readback-d', (actualElectron ? 'electron-' : 'web-') + randomUUID());
fs.mkdirSync(directory, { recursive: true });
const disposers = [], t = { after: fn => disposers.push(fn) }, f = fixture(t, { modernDefaults: true });
const passed = [], errors = [], screenshots = [], marker = '工作台可选进展建议';
let n = 0, browser, application, controller, host, page, window, result;
const model = await compatibleFixture(t, () => {
const step = ++n;
return { body: step < 4 ? completion([call('repeat-' + step, 'read_file', { path: 'README.md', offset: 0, limit: 10 })])
: step === 4 ? completion([call('ack', 'read_file', { path: 'README.md', offset: 0, limit: 10 })], '明白。')
: step === 5 ? completion([call('new-page', 'read_file', { path: 'README.md', offset: 10, limit: 10 })])
: completion([], '已核对读取过程,未修改文件。') };
});
f.session.title = 'D 提醒与回读本机验收'; f.store.save(f.session);
f.store.saveConfig({ mode: 'compatible', model: 'owned-reminder-ui', baseUrl: model.baseUrl, approvalMode: 'full' }); f.store.close();
const mark = name => { passed.push(name); console.log('PASS ' + name); };
const save = (name, value) => fs.writeFileSync(path.join(directory, name), JSON.stringify(value, null, 2));
async function shot(name) { const file = path.join(directory, name + '.png'); await page.screenshot({ path: file, scale: 'css' }); screenshots.push(file); }
async function settings() {
await page.getByRole('button', { name: '打开工具箱', exact: true }).click();
await page.getByLabel('搜索工作台工具').fill('进展提醒'); await page.getByRole('button', { name: '进展提醒', exact: true }).click();
const modal = page.getByRole('dialog', { name: '进展提醒', exact: true });
await modal.getByRole('switch', { name: '开启进展提醒', exact: true }).waitFor(); return modal;
}
async function visiblePanel() {
if (!await page.getByLabel('选择运行记录', { exact: true }).isVisible()) await page.getByRole('button', { name: '查看任务记录', exact: true }).click();
const observation = page.getByLabel('单轮观察', { exact: true }); await observation.waitFor();
if (!await observation.evaluate(element => element.open)) await observation.locator('summary').click();
const panel = page.getByLabel('提醒与回读', { exact: true }); await panel.waitFor(); await panel.scrollIntoViewIfNeeded(); return panel;
}
async function resize(width, height) {
if (window) { await window.evaluate((win, size) => win.setContentSize(size.width, size.height), { width, height }); await until(() => page.evaluate(w => innerWidth === w, width)); }
else await page.setViewportSize({ width, height });
}
try {
if (actualElectron) {
const socket = net.createServer(); await new Promise(resolve => socket.listen(0, '127.0.0.1', resolve));
const port = socket.address().port; await new Promise(resolve => socket.close(resolve)); assert.notEqual(port, 4318);
controller = new HostController({ appRoot, dataRoot: f.data, port, nodePath: process.execPath, timeoutMs: 60000 }); await controller.start();
host = { url: controller.url, bootstrap: await controller.api('/bootstrap'), api: (route, input) => controller.api(route, input === undefined ? {} : { method: 'POST', input }) };
const executable = desktopExecutableIdentity(appRoot).path;
application = await _electron.launch({ executablePath: executable,
args: [...(executable.toLowerCase().endsWith('agentworkbench.exe') ? [] : [path.join(appRoot, 'dist-desktop/main.cjs')]), '--app-root', appRoot, '--data-root', f.data, '--node', process.execPath, '--port', String(port), '--hidden-window'],
cwd: appRoot, env: projectEnvironment(), timeout: 60000 });
page = await application.firstWindow(); window = await application.browserWindow(page);
await window.evaluate(win => { win.showInactive(); win.setContentSize(1440, 1080); }); await until(() => page.evaluate(() => innerWidth === 1440));
assert.equal(await page.evaluate(() => typeof globalThis.process), 'undefined');
} else {
host = await launchWorkbench(t, f.data, {}, { appRoot }); assert.notEqual(new URL(host.url).port, '4318');
browser = await chromium.launch({ channel: 'msedge', headless: true }); page = await browser.newPage({ viewport: { width: 1440, height: 1080 } }); await page.goto(host.url);
}
page.on('pageerror', error => errors.push(error.message)); await page.locator('.connection.connected').waitFor();
assert.equal(host.bootstrap.config.hasKey, false); assert.equal(host.bootstrap.config.progressRemindersEnabled, false);
await page.getByLabel('当前项目').selectOption(f.project.id); await page.locator('.session-list button').filter({ hasText: f.session.title }).click();
let modal = await settings(); const toggle = () => modal.getByRole('switch', { name: '开启进展提醒', exact: true });
assert.equal(await toggle().isChecked(), false); await shot('default-off'); await toggle().click();
await until(async () => (await host.api('/progress-reminders/settings')).enabled === true);
await until(async () => (await modal.textContent()).includes('已开启')); assert.equal(n, 0);
await modal.getByRole('button', { name: '关闭窗口', exact: true }).click(); await page.reload(); await page.locator('.connection.connected').waitFor();
modal = await settings(); assert.equal(await toggle().isChecked(), true); mark('toolbox search opens a default-off setting; real save and refresh restore the preference without model calls');
const failSave = route => route.request().method() === 'POST' ? route.fulfill({ status: 503, contentType: 'application/json', body: JSON.stringify({ error: 'Owned settings failure' }) }) : route.continue();
await page.route('**/api/progress-reminders/settings', failSave); await toggle().click();
await modal.getByRole('alert').waitFor(); assert.equal(await toggle().isChecked(), true); await shot('save-error');
await page.unroute('**/api/progress-reminders/settings', failSave); assert.equal((await host.api('/progress-reminders/settings')).enabled, true);
await modal.getByRole('button', { name: '关闭窗口', exact: true }).click(); mark('a failed save preserves the real setting and shows a recoverable error');
await host.api('/sessions/' + f.session.id + '/messages', { content: '修改README.md,先读取核对原内容;无需测试。本机固定HTTP验收。' });
await until(async () => (await host.api('/sessions/' + f.session.id)).status === 'completed', 30000);
const snapshot = await host.api('/sessions/' + f.session.id + '/export'); save('session.json', snapshot);
const run = snapshot.execution.run, inspected = await host.api('/sessions/' + f.session.id + '/progress-reminders?run=' + run.id); save('readback.json', inspected);
assert.equal(n, 6); assert.equal(inspected.evidenceVerified, true); assert.equal(inspected.items[0].status, 'resolved');
assert.deepEqual(model.requests.map(row => JSON.stringify(row.input).includes(marker)), [false, false, false, true, false, false]);
let panel = await visiblePanel(); await until(async () => (await panel.textContent()).includes('已观察到进展'));
assert.match(await panel.textContent(), /已随 1 次请求发出/); assert.match(await panel.textContent(), /因果关系未证实/); await shot('observed-readback');
mark('six original HTTP requests show one dispatch, ignore acknowledgement and resolve only on the later new range');
for (const name of ['原观察 1', '实际请求 1', '回读依据']) {
await panel.getByRole('button', { name, exact: true }).click();
const artifact = page.getByRole('dialog', { name: '执行结果工件', exact: true }); await artifact.waitFor();
assert.ok((await artifact.textContent()).length > 100); await artifact.getByRole('button', { name: '关闭窗口', exact: true }).click();
}
mark('observation, actual request and readback evidence open their real artifact viewers');
await resize(390, 844); panel = await visiblePanel();
assert.equal(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth + 1), true);
assert.ok((await panel.getByRole('button', { name: '实际请求 1', exact: true }).boundingBox()).height >= 44); await shot('narrow-readback');
mark('390px keeps readback facts and source actions reachable without page overflow');
await resize(1440, 1080);
let failReadback = true;
const readbackFailure = route => failReadback ? route.fulfill({ status: 503, contentType: 'application/json', body: JSON.stringify({ error: 'Owned readback failure' }) }) : route.continue();
await page.route('**/api/sessions/*/progress-reminders?*', readbackFailure); await page.reload(); await page.locator('.connection.connected').waitFor(); panel = await visiblePanel();
await panel.getByRole('alert').waitFor(); assert.match(await panel.textContent(), /暂时无法核对/); await shot('readback-error');
failReadback = false; await panel.getByRole('button', { name: '重新核对', exact: true }).click();
await until(async () => (await panel.textContent()).includes('已观察到进展')); await page.unroute('**/api/sessions/*/progress-reminders?*', readbackFailure);
mark('readback failure and retry recover from real API responses without changing the run or calling the model');
modal = await settings(); await toggle().click(); await until(async () => (await host.api('/progress-reminders/settings')).enabled === false);
await modal.getByRole('button', { name: '关闭窗口', exact: true }).click();
if (application) { await application.close(); application = null; if (controller && await controller.health()) await controller.stop(); controller = null; }
else { await browser.close(); browser = null; await host.close(); }
const restarted = await launchWorkbench(t, f.data, {}, { appRoot });
assert.equal((await restarted.api('/progress-reminders/settings')).enabled, false);
assert.equal((await restarted.api('/sessions/' + f.session.id + '/progress-reminders?run=' + run.id)).evidenceVerified, true); await restarted.close();
assert.equal(n, 6); assert.deepEqual(errors, []); mark('closing and restarting the actual host preserves off preference and original verified readback');
result = { success: true, appRoot, actualElectron, passed, screenshots, errors, realModelRequests: 0, localFixtureRequests: n, officialServiceTouched: false,
serverSha256: createHash('sha256').update(fs.readFileSync(path.join(appRoot, 'dist-server/server.mjs'))).digest('hex') };
} catch (error) {
if (page) try { await shot('failure'); fs.writeFileSync(path.join(directory, 'failure-dom.txt'), await page.locator('body').innerText()); } catch {}
result = { success: false, appRoot, actualElectron, passed, screenshots, errors, error: error.stack, realModelRequests: 0, localFixtureRequests: n, officialServiceTouched: false };
} finally {
save('fixture-requests.json', model.requests.map(({ url, input }) => ({ url, input })));
if (application) await application.close(); if (browser) await browser.close(); if (controller && await controller.health()) await controller.stop();
for (const dispose of disposers.reverse()) await dispose(); save('result.json', result);
}
console.log(JSON.stringify({ directory, ...result }, null, 2)); if (!result.success) process.exitCode = 1;
+4
View File
@@ -30,6 +30,7 @@ import { BRAND, OrvenMark } from './brand';
import { WorkbenchTools } from './WorkbenchTools';
import type { WorkbenchAction } from './WorkbenchTools';
import { AppearancePanel } from './AppearancePanel';
import { ProgressReminderSettings } from './ProgressReminders';
import { Palette as PaletteIcon } from 'lucide-react';
const activeStates = ['running', 'awaiting_approval', 'stopping'];
@@ -81,6 +82,7 @@ export default function App() {
const [inspectorOpen, setInspectorOpen] = useState(false);
const [toolsOpen, setToolsOpen] = useState(false);
const [appearanceOpen, setAppearanceOpen] = useState(false);
const [reminderSettingsOpen, setReminderSettingsOpen] = useState(false);
const [narrow, setNarrow] = useState(() => window.innerWidth <= 940);
const [viewportWidth,setViewportWidth]=useState(()=>window.innerWidth);
const [mobile, setMobile] = useState(() => window.innerWidth <= 620);
@@ -574,6 +576,7 @@ export default function App() {
{ id: 'research', label: '机制研究与设计', description: '阅读已有研究报告与机制说明', group: '能力与研究', icon: BookOpenText, run: () => void openResearch() },
{ id: 'models', label: '模型中心', description: '选择模型、管理连接和模型池', group: '设置与连接', icon: ModelServer, run: () => setModelCenterOpen(true) },
{ id: 'appearance', label: '外观', description: '选择深青绿、雾蓝或鸢尾紫,自动记住你的偏好', group: '设置与连接', icon: PaletteIcon, run: () => setAppearanceOpen(true) },
{ id: 'progress-reminders', label: '进展提醒', description: '可选的重复读取与参数错误建议,查看实际送达和回读', group: '设置与连接', icon: Activity, run: () => setReminderSettingsOpen(true) },
{ id: 'diagnostics', label: '运行诊断', description: '检查连接、终端与最近错误', group: '设置与连接', icon: Activity, run: () => void openDiagnostics() },
{ id: 'companion', label: '手机连接', description: '在手机上查看和接续电脑任务', group: '设置与连接', icon: Link2, run: () => setCompanionOpen(true) },
...(desktop ? [{ id: 'desktop', label: '桌面宿主', description: '查看窗口、后台任务与本地宿主', group: '设置与连接', icon: SquareTerminal, run: () => setDesktopOpen(true) }] : []),
@@ -661,6 +664,7 @@ export default function App() {
</aside>
{toolsOpen && <Modal title="工具箱" description="项目的上下文、能力和连接,都在这里。" onClose={() => setToolsOpen(false)}><WorkbenchTools actions={actions} onClose={() => setToolsOpen(false)} /></Modal>}
{appearanceOpen && <Modal title="外观" description="选择适合你的工作台配色,切换后立即生效。" onClose={() => setAppearanceOpen(false)}><AppearancePanel /></Modal>}
{reminderSettingsOpen && <Modal title="进展提醒" description="根据原工具结果提供可选建议,并核对后续进展。" onClose={() => setReminderSettingsOpen(false)}><ProgressReminderSettings /></Modal>}
{installationOpen && <Modal title="版本与更新" description="核对本机版本、真实更新阶段与原始结果。" onClose={() => setInstallationOpen(false)}><InstallationStatus /></Modal>}
{projectOpen && <Modal title="打开项目" description="选择这台电脑上的项目文件夹,或输入完整路径。" onClose={() => { if (!projectBusy) { setProjectOpen(false); setDirectoryPickerOpen(false); setProjectError(''); } }}><form onSubmit={event => { event.preventDefault(); if (!directoryPickerOpen) void openProject(); }}><label className="form-field">项目文件夹<input autoFocus value={projectInput} disabled={projectBusy} onChange={event => { setProjectInput(event.target.value); setProjectError(''); }} placeholder="C:\Projects\my-app" aria-label="项目文件夹路径" /></label>{projectError && <p className="local-files-error" role="alert">{projectError}</p>}{directoryPickerOpen && <ProjectDirectoryPicker initialPath={projectInput.trim()} onChoose={value => { setProjectInput(value); setProjectError(''); setDirectoryPickerOpen(false); }} onCancel={() => setDirectoryPickerOpen(false)} />}<div className="modal-actions"><button type="button" className="button secondary" disabled={pickingProject || projectBusy} onClick={() => desktop ? void pickDesktopProject() : setDirectoryPickerOpen(value => !value)}><FolderOpen size={15} />选择文件夹</button>{exampleId && <button type="button" className="button secondary" disabled={projectBusy} onClick={() => { chooseProject(exampleId); setProjectOpen(false); setDirectoryPickerOpen(false); }}>打开示例项目</button>}<button type="submit" className="button primary" disabled={!projectInput.trim() || projectBusy || directoryPickerOpen}>{projectBusy ? <LoaderCircle className="spin" size={15} /> : <FolderOpen size={15} />}{projectBusy ? '正在打开…' : '打开项目'}</button></div></form></Modal>}
{companionOpen && <Modal title="手机连接" description="指定项目和权限,连接到同一个Windows执行宿主。" onClose={() => setCompanionOpen(false)} wide><CompanionPanel projects={projects} selectedProjectId={selectedProject?.id ?? ''} /></Modal>}
+11
View File
@@ -0,0 +1,11 @@
.reminder-settings { padding: 4px 2px 12px; font-size: 14px; line-height: 1.7; }
.reminder-settings p { margin: 14px 0; }
.reminder-toggle { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 12px 0 18px; border-bottom: 1px solid var(--orven-line); cursor: pointer; }
.reminder-toggle span { display: grid; gap: 4px; }
.reminder-toggle strong { font-size: 15px; }
.reminder-toggle small { font-size: 12px; color: var(--orven-muted); }
.reminder-toggle input { width: 21px; height: 21px; flex: 0 0 auto; accent-color: var(--orven-accent); cursor: pointer; }
.reminder-readback { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--orven-line); }
.reminder-readback h4 { margin: 0 0 8px; font-size: 13px; }
.reminder-evidence { display: flex; flex-wrap: wrap; gap: 4px 12px; }
@media (max-width: 620px) { .reminder-readback button, .reminder-settings button { min-height: 44px; } .reminder-toggle { min-height: 60px; } }
+73
View File
@@ -0,0 +1,73 @@
import { useEffect, useState } from 'react';
import { LoaderCircle } from 'lucide-react';
import { api } from './api';
import type { ReminderInspection, Run } from './types';
import './ProgressReminders.css';
export function ProgressReminderSettings() {
const [enabled, setEnabled] = useState<boolean | null>(null), [saving, setSaving] = useState(false);
const [error, setError] = useState(''), [notice, setNotice] = useState(''), [reload, setReload] = useState(0);
useEffect(() => {
let alive = true; setError(''); setEnabled(null);
api<{ enabled: boolean }>('/progress-reminders/settings').then(value => { if (alive) setEnabled(value.enabled); })
.catch(() => { if (alive) setError('暂时无法读取提醒设置,请重试。'); });
return () => { alive = false; };
}, [reload]);
async function toggle(next: boolean) {
setSaving(true); setError(''); setNotice('');
try {
const saved = await api<{ enabled: boolean }>('/progress-reminders/settings', { enabled: next });
setEnabled(saved.enabled); setNotice(saved.enabled ? '已开启,并保存为后续运行的偏好。' : '已关闭,后续请求不再附加建议。');
} catch { setError('设置未保存,请重试。原选择仍然保留。'); }
finally { setSaving(false); }
}
return <div className="reminder-settings">
<label className="reminder-toggle"><span><strong>开启进展提醒</strong><small>默认关闭。你的选择会自动保存。</small></span>
{enabled === null ? <LoaderCircle size={18} className="spin" aria-label="正在读取设置" />
: <input type="checkbox" role="switch" aria-label="开启进展提醒" checked={enabled} disabled={saving} onChange={event => void toggle(event.target.checked)} />}</label>
<p>仅在文件任务连续重复读取相同内容,或连续出现相同参数错误时,附加可选建议。正常分页、研究和等待检查继续按原任务进行。</p>
<p>在任务记录中查看建议随哪次请求发出、后续是否出现对应工具结果。回复“明白”不会被记为解决。</p>
<p className="record-footnote">本设置不改变操作权限、模型额度或历史传递。当前执行中的请求保留原记录;外部引擎与压缩历史不附加建议。</p>
{notice && <p role="status">{notice}</p>}
{saving && <p role="status">正在保存…</p>}
{error && <div role="alert"><p>{error}</p>{enabled === null && <button type="button" className="text-button" onClick={() => setReload(value => value + 1)}>重新读取</button>}</div>}
</div>;
}
const labels: Record<string, string> = { pending: '待发送', delivered: '已随请求发出', resolved: '已观察到进展', expired: '已过期' };
const reasons: Record<string, string> = { disabled: '已关闭提醒', cancelled: '运行已取消', run_finished: '运行已结束', ttl: '建议已过期',
research: '保留只读研究', waiting: '等待所属操作', user_boundary: '用户要求已变化', new_failure: '出现新的失败证据',
ineffective: '重复建议未见效果,已停止附加', tool_unavailable_or_advice_too_large: '本轮不再适用' };
export function ReminderReadback({ sessionId, run, openArtifact }: { sessionId: string; run: Run; openArtifact: (id: string) => void }) {
const [view, setView] = useState<ReminderInspection | null>(null), [error, setError] = useState(''), [reload, setReload] = useState(0);
const recorded = !!run.progressReminders || !!run.progressReminderError;
useEffect(() => {
let alive = true; setView(null); setError('');
if (recorded) api<ReminderInspection>('/sessions/' + sessionId + '/progress-reminders?run=' + run.id)
.then(value => { if (alive) setView(value); }).catch(() => { if (alive) setError('暂时无法核对提醒记录。'); });
return () => { alive = false; };
}, [sessionId, run.id, run.progressReminderReceiptId, run.progressReminderError?.phase, recorded, reload]);
if (!recorded) return null;
return <section className="reminder-readback" aria-label="提醒与回读">
<h4>提醒与回读</h4>
{!view && !error && <p role="status">正在核对原始记录…</p>}
{error && <p role="alert">{error}<button type="button" className="text-button" onClick={() => setReload(value => value + 1)}>重新核对</button></p>}
{view && !view.evidenceVerified && <p role="alert">提醒依据暂时无法核对。原任务和执行结果保留。</p>}
{view?.evidenceVerified && <>
{view.error && <p className="record-footnote">部分提醒未能记录,原任务继续执行。</p>}
{!view.items.length && <p className="record-footnote">本次运行没有生成建议。</p>}
<ol>{view.items.map(item => <li key={item.key}>
<strong>{item.category === 'repeated_read' ? '重复读取建议' : '参数错误建议'} · {labels[item.status] ?? item.status}</strong>
<p>{item.deliveries.length ? `已随 ${item.deliveries.length} 次请求发出` : '尚未随请求发出'}{item.exitReason ? ` · ${reasons[item.exitReason] ?? item.exitReason}` : ''}</p>
{item.resolution && <p>{item.resolution.relation === 'naturally_resolved' ? '发送前已自然出现对应工具结果。' : '发送后已出现对应工具结果,因果关系未证实。'}{item.resolution.kind === 'new_read_range' ? '已取得新的读取区间。' : '原参数错误工具已返回成功结果。'}</p>}
<div className="reminder-evidence">{item.source.map((ref, index) => <button type="button" className="text-button" key={ref.artifactId} onClick={() => openArtifact(ref.artifactId)}>原观察 {index + 1}</button>)}
{item.deliveries.map((delivery, index) => <button type="button" className="text-button" key={delivery.requestId} onClick={() => openArtifact(delivery.requestArtifactId)}>实际请求 {index + 1}</button>)}
{item.resolution && <button type="button" className="text-button" onClick={() => openArtifact(item.resolution!.source.artifactId)}>回读依据</button>}
</div>
</li>)}</ol>
{view.receiptArtifactId && <button type="button" className="text-button" onClick={() => openArtifact(view.receiptArtifactId!)}>查看提醒原收据</button>}
<p className="record-footnote">工具进展与业务完成分别核对;送达记录不代表模型收到、采纳或节省了 tokens。</p>
</>}
</section>;
}
+1 -1
View File
@@ -120,7 +120,7 @@ export function TaskPanel({ project, session, onSession, onError, busy, onWorksp
<dt>本次预算</dt><dd>{run.budget?.maxTokens === 0 ? 'tokens 不限' : number(run.budget?.maxTokens) + ' tokens'} · {run.budget?.maxDurationMs === 0 ? '时长不限' : Math.round((run.budget?.maxDurationMs ?? 0) / 60000) + ' 分钟'} · {run.budget?.maxSteps === 0 ? '轮次不限' : run.budget?.maxSteps + ' 轮'}</dd><dt>任务累计</dt><dd>{number(execution?.accountedTaskTokens)} / {task.budget.maxTokens === 0 ? '不限' : number(task.budget.maxTokens)} tokens</dd>
</dl>{run.stopReason && <p className="run-stop">{stopReasons[run.stopReason] || run.stopReason}</p>}
<p className="record-footnote">用量按请求尝试累计,包含失败响应已报告的 tokens;未报告的请求单独估算。历史缺失不补造,tokens 不等于费用。</p>
<TurnProgress run={run} openArtifact={openArtifact} />
<TurnProgress sessionId={session.id} run={run} openArtifact={openArtifact} />
</> : <p className="record-empty"><LoaderCircle size={14} className="spin" />正在读取运行记录</p>}
</section>}
{run && <RequestContextPanel session={session} runId={run.id} onError={onError} openArtifact={openArtifact} />}
+4 -2
View File
@@ -1,10 +1,11 @@
import type { Run } from './types';
import { ReminderReadback } from './ProgressReminders';
const labels: Record<string, string> = { baseline: '本次运行基线', waiting: '等待所属操作', evidence_growth: '新增外显证据', new_failure_evidence: '新增失败证据',
user_boundary: '用户边界变化', repeated_failure_candidate: '重复失败候选', repeated_read_candidate: '重复读取候选', no_observed_change: '未见新外显事实', unknown_bounded: '观察容量已满,保留未知' };
const failureLabels: Record<string, string> = { invalid_input: '参数无效', permission: '权限或审批拒绝', requires_verification: '结果待核对', network: '网络连接', service: '上游服务',
authentication: '身份验证', rate_limit: '请求限流', quota: '服务额度', tool_or_environment: '工具或环境', unknown: '尚未分类' };
export function TurnProgress({ run, openArtifact }: { run: Run; openArtifact: (id: string) => void }) {
if (!run.progressShadow && !run.progressShadowError) return null;
export function TurnProgress({ sessionId, run, openArtifact }: { sessionId: string; run: Run; openArtifact: (id: string) => void }) {
if (!run.progressShadow && !run.progressShadowError && !run.progressReminders && !run.progressReminderError) return null;
const shadow = run.progressShadow;
return <details className="turn-progress" aria-label="单轮观察">
<summary>单轮观察 · 仅记录{shadow ? ` · 已保留 ${shadow.turns.filter(row => row.phase === 'settled').length} 轮` : ''}</summary>
@@ -21,5 +22,6 @@ export function TurnProgress({ run, openArtifact }: { run: Run; openArtifact: (i
{!!turn.waiting.length && <p>等待 {turn.waiting.map(row => ({ approval: '审批', check_job: '检查作业', review: '审查' }[row.kind] ?? row.kind)).join('、')}</p>}
{run.progressShadowArtifactIds?.[index] && <button className="text-button" onClick={() => openArtifact(run.progressShadowArtifactIds![index])}>查看原观察收据</button>}
</li>)}</ol>
<ReminderReadback key={sessionId + '/' + run.id} sessionId={sessionId} run={run} openArtifact={openArtifact} />
</details>;
}
+9
View File
@@ -5,6 +5,7 @@ export interface Config {
executionMode?: 'unrestricted' | 'restricted';
capacityMode?: 'passthrough' | 'model' | 'manual';
historyPolicy?: 'preserve' | 'compact';
progressRemindersEnabled?: boolean;
maxRunDurationMs: number; maxRunTokens: number; maxTaskTokens: number;
modelResponseTimeoutMs?: number; modelStreamIdleTimeoutMs?: number;
}
@@ -152,6 +153,14 @@ export interface TurnObservation {
waiting: { kind: string; id: string }[];
}
export interface Run { progressShadow?: { mode: 'shadow'; observations: number; truncated: boolean; turns: TurnObservation[] }; progressShadowArtifactIds?: string[]; progressShadowError?: { kind: string; phase: string } }
export interface ReminderSource { artifactId: string; sha256: string; ordinal: number }
export interface ProgressReminder { key: string; category: string; status: string; createdAt: number; expiresAt: number; source: ReminderSource[];
toolNames: string[]; expected: { kind: string }; exitReason?: string;
deliveries: { requestId: string; requestArtifactId: string; requestSha256: string; dispatchedAt: number }[];
resolution?: { source: ReminderSource; kind: string; relation: string; causality: string } }
export interface ReminderInspection { enabled: boolean; recorded: boolean; evidenceVerified: boolean; receiptArtifactId: string | null;
items: ProgressReminder[]; error: { kind: string; phase: string } | null }
export interface Run { progressReminders?: { enabled: boolean; items: ProgressReminder[] }; progressReminderReceiptId?: string; progressReminderError?: { kind: string; phase: string } }
export interface RunBrief { purpose?: 'execution' | 'diagnostic'; source?: string; taskStatusBefore?: string; consumption?: ModelConsumption[] }
export interface Run { question?: string; diagnosticContext?: { artifactId: string; sha256: string; originalRunId: string | null } }
export interface DiagnosticContext {
+145
View File
@@ -0,0 +1,145 @@
import { planHash } from '../../shared/contracts/task-plans.mjs';
import { requestHistory, requestVariants } from '../../shared/contracts/model-request.mjs';
import { verifyTurnProgressReceipt } from './turn-progress-recorder.mjs';
import { observeReminders, selectReminder, recordReminderDispatch } from './reminder-queue.mjs';
const scopeOf = run => ({ projectId: run.projectId, sessionId: run.sessionId, taskId: run.taskId, runId: run.id });
const owned = (row, scope) => row && row.projectId === scope.projectId && row.sessionId === scope.sessionId && row.taskId === scope.taskId && row.runId === scope.runId;
const current = (session, run) => session.id === run.sessionId && session.projectId === run.projectId && session.taskId === run.taskId && session.runId === run.id;
export function verifyReminderMessage(store, session, plan, body) {
const ref = plan.progressReminder;
if (!ref) return null;
const scope = { projectId: plan.projectId, sessionId: plan.sessionId, taskId: plan.taskId, runId: plan.runId };
const artifact = store.owned('artifact', ref.artifactId, session.id);
if (!owned(artifact, scope) || artifact.kind !== 'progress-reminder-message' || artifact.sha256 !== ref.sha256) throw new Error('提醒原文来源不一致。');
const message = JSON.parse(store.artifactStore.read(artifact));
if (planHash(message.scope) !== planHash(scope) || message.key !== ref.key || planHash(message.content) !== message.sha256) throw new Error('提醒原文归属不一致。');
for (const variant of requestVariants(body)) {
const matches = requestHistory(variant).filter(row => ['user', 'system'].includes(row.role) && typeof row.content === 'string' && row.content.includes(message.content));
const tools = (variant.tools ?? []).map(tool => tool.function?.name ?? tool.name);
if (matches.length !== 1 || message.tools.some(name => !tools.includes(name))) throw new Error('提醒与实际请求正文或工具不一致。');
}
return message;
}
// No permissions, retries or stops are delegated to this observer. All entry
// points isolate their own failures and leave the original execution intact.
export class ReminderManager {
constructor(store) { this.store = store; }
error(session, run, phase) {
if (!current(session, run)) return;
run.progressReminderError = { kind: 'reminder_unavailable', phase };
try { this.store.save(session, { type: 'run.reminder_unavailable', detail: { runId: run.id, phase } }); } catch { /* Original execution owns persistence failures. */ }
}
verifiedState(session, run) {
if (!run.progressReminders) return null;
const artifact = this.store.owned('artifact', run.progressReminderReceiptId, session.id);
if (!owned(artifact, scopeOf(run)) || artifact.kind !== 'progress-reminder-queue') throw new Error('提醒队列收据归属不一致。');
const receipt = JSON.parse(this.store.artifactStore.read(artifact));
if (planHash(receipt.state) !== planHash(run.progressReminders) || planHash(receipt.state.scope) !== planHash(scopeOf(run))) throw new Error('提醒队列与原收据不一致。');
return run.progressReminders;
}
save(session, run, state, phase) {
if (planHash(state) === planHash(run.progressReminders ?? null)) return;
const artifact = this.store.artifactStore.write(session, run, { schemaVersion: 1, phase, state }, { kind: 'progress-reminder-queue' });
this.store.core.artifact.set(artifact.id, artifact);
run.progressReminders = state; run.progressReminderReceiptId = artifact.id;
this.store.save(session, { type: 'run.progress_reminder', detail: { runId: run.id, phase, artifactId: artifact.id } });
}
observe(session, run, { endReason = null } = {}) {
if (!current(session, run) || (!this.store.config.progressRemindersEnabled && !run.progressReminders)) return;
try {
const state = this.verifiedState(session, run), id = run.progressShadowArtifactIds?.at(-1);
let receipt = null;
if (id && !endReason && state?.lastArtifactId !== id) {
const verified = verifyTurnProgressReceipt(this.store, session, run, id);
if (planHash(verified.observation) !== planHash(run.progressShadow?.turns.at(-1))) throw new Error('提醒观察与原收据不一致。');
receipt = { ...verified, ref: { artifactId: id, sha256: verified.artifact.sha256, ordinal: run.progressShadow.observations } };
}
const task = this.store.core.task.get(run.taskId);
// Only explicit file work is eligible for read nudges. General analysis,
// research and diagnostics remain valid read-only work without prompting.
const research = run.purpose === 'diagnostic' || !!run.workerId || task?.contract?.kind !== 'file';
const next = observeReminders(state, { scope: scopeOf(run), enabled: this.store.config.progressRemindersEnabled,
at: Date.now(), receipt, research, endReason });
this.save(session, run, next, endReason ?? 'observation');
} catch { this.error(session, run, 'observation'); }
}
prepare(session, run, toolSurface) {
if (!current(session, run) || run.purpose === 'diagnostic' || run.workerId || (!this.store.config.progressRemindersEnabled && !run.progressReminders)) return null;
try {
const state = this.verifiedState(session, run);
// Check source integrity again at use, including receipts retained before
// B's display window. Never trust the mutable in-memory projection alone.
for (const item of state?.items.filter(row => ['pending', 'delivered'].includes(row.status)) ?? [])
for (const ref of item.source) this.verifySource(session, run, ref);
const selected = selectReminder(state, { scope: scopeOf(run), enabled: this.store.config.progressRemindersEnabled,
at: Date.now(), visibleTools: toolSurface.entries.filter(row => row.visible).map(row => row.name) });
this.save(session, run, selected.state, 'selection');
if (!selected.message) return null;
const artifact = this.store.artifactStore.write(session, run, selected.message, { kind: 'progress-reminder-message' });
this.store.core.artifact.set(artifact.id, artifact);
return { message: selected.message, ref: { key: selected.message.key, artifactId: artifact.id, sha256: artifact.sha256 } };
} catch { this.error(session, run, 'selection'); return null; }
}
verifySource(session, run, ref) {
const verified = verifyTurnProgressReceipt(this.store, session, run, ref.artifactId);
if (verified.artifact.sha256 !== ref.sha256) throw new Error('提醒依据SHA变化。');
return verified;
}
requestEvidence(session, run, plan) {
const scope = scopeOf(run), frozenArtifact = this.store.owned('artifact', plan.artifactId, session.id);
if (!owned(plan, scope) || !owned(frozenArtifact, scope) || frozenArtifact.kind !== 'context-plan') throw new Error('提醒请求计划归属不一致。');
const frozen = JSON.parse(this.store.artifactStore.read(frozenArtifact));
for (const key of ['id', 'projectId', 'sessionId', 'taskId', 'runId', 'requestArtifactId', 'requestSha256', 'progressReminder'])
if (planHash(frozen[key] ?? null) !== planHash(plan[key] ?? null)) throw new Error('提醒请求与发送前封存不一致。');
const artifact = this.store.owned('artifact', plan.requestArtifactId, session.id);
if (!owned(artifact, scope) || artifact.kind !== 'model-request' || artifact.sha256 !== plan.requestSha256) throw new Error('提醒请求原文变化。');
return JSON.parse(this.store.artifactStore.read(artifact));
}
dispatch(session, run, plan, submission) {
if (!plan.progressReminder || !current(session, run) || session.status === 'stopping') return;
try {
const state = this.verifiedState(session, run);
const body = this.requestEvidence(session, run, plan);
const message = verifyReminderMessage(this.store, session, plan, body);
if (!requestVariants(body).some(variant => planHash(variant) === submission.wireRequestSha256)) throw new Error('提醒实际线路请求与原计划不一致。');
const next = recordReminderDispatch(state, { scope: scopeOf(run), at: Date.now(), message, requestId: plan.id, requestSha256: plan.requestSha256,
attemptId: submission.attemptId, wireRequestSha256: submission.wireRequestSha256 });
// Provider calls this only after submitting fetch, before awaiting the
// response. A later disable/cancel cannot erase that dispatch fact.
if (next.items.find(row => row.key === message.key)?.deliveries.some(row => row.requestId === plan.id)) {
plan.progressReminderDispatches ??= [];
if (!plan.progressReminderDispatches.some(row => row.attemptId === submission.attemptId))
plan.progressReminderDispatches.push({ ...submission, recordedAt: new Date().toISOString() });
}
this.save(session, run, next, 'dispatch');
} catch { this.error(session, run, 'dispatch'); }
}
inspect(session, run) {
const view = { schemaVersion: 1, enabled: this.store.config.progressRemindersEnabled === true, recorded: !!run.progressReminders,
evidenceVerified: false, receiptArtifactId: run.progressReminderReceiptId ?? null, items: [], error: run.progressReminderError ?? null };
if (!view.recorded) { view.evidenceVerified = true; return view; }
try {
const state = this.verifiedState(session, run);
for (const item of state.items) {
for (const ref of [...item.source, ...(item.resolution ? [item.resolution.source] : [])]) this.verifySource(session, run, ref);
for (const delivered of item.deliveries) {
const plan = this.store.owned('context_plan', delivered.requestId, session.id);
if (!owned(plan, scopeOf(run)) || plan.requestSha256 !== delivered.requestSha256 || !plan.progressReminderDispatches?.length) throw new Error('提醒送达请求未核对。');
const body = this.requestEvidence(session, run, plan);
const message = verifyReminderMessage(this.store, session, plan, body);
if (message.key !== item.key || message.sha256 !== delivered.messageSha256) throw new Error('提醒送达原文变化。');
const variants = requestVariants(body).map(planHash);
if (!delivered.attempts?.length || delivered.attempts.some(attempt => !variants.includes(attempt.wireRequestSha256)
|| !plan.progressReminderDispatches.some(row => row.attemptId === attempt.attemptId && row.wireRequestSha256 === attempt.wireRequestSha256))) throw new Error('提醒实际线路送达未核对。');
}
}
view.items = structuredClone(state.items).map(item => ({ ...item, deliveries: item.deliveries.map(row => ({ ...row,
requestArtifactId: this.store.core.context_plan.get(row.requestId).requestArtifactId })) }));
view.evidenceVerified = true;
} catch { view.error = { kind: 'reminder_evidence_unverified', phase: 'readback' }; }
return view;
}
}
+11 -4
View File
@@ -1,6 +1,6 @@
import { createHash } from 'node:crypto';
const hash = value => createHash('sha256').update(JSON.stringify(value)).digest('hex');
const hash = value => createHash('sha256').update(typeof value === 'string' ? value : JSON.stringify(value)).digest('hex');
const sha = value => /^[a-f0-9]{64}$/.test(value ?? '');
const active = item => ['pending', 'delivered'].includes(item.status);
const same = (a, b) => hash(a) === hash(b);
@@ -114,14 +114,21 @@ export function selectReminder(previous, { scope, enabled = false, at, visibleTo
// Dispatch means included in a real submitted request. It does not assert that
// an upstream received it, the model adopted it, or the advice caused progress.
export function recordReminderDispatch(previous, { scope, at, message, requestId, requestSha256 }) {
export function recordReminderDispatch(previous, { scope, at, message, requestId, requestSha256, attemptId = null, wireRequestSha256 = null }) {
const state = queue(previous, scope, previous?.enabled, at), item = state.items.find(row => row.key === message?.key);
if (!same(message?.scope, state.scope) || !sha(requestSha256) || typeof requestId !== 'string' || !requestId) throw new Error('Reminder request ownership is invalid.');
if (!state.enabled || !item || !active(item)) return state;
const expected = messageFor(state, item, message.tools ?? []);
if (!expected || !same(expected, message)) throw new Error('Reminder dispatch differs from selected advice.');
if (item.deliveries.some(row => row.requestId === requestId)) return state;
item.deliveries.push({ requestId, requestSha256, messageSha256: message.sha256, ordinal: state.lastOrdinal, dispatchedAt: at });
if (attemptId !== null && (typeof attemptId !== 'string' || !attemptId || !sha(wireRequestSha256))) throw new Error('Reminder wire attempt is invalid.');
let delivery = item.deliveries.find(row => row.requestId === requestId);
if (!delivery) {
delivery = { requestId, requestSha256, messageSha256: message.sha256, ordinal: state.lastOrdinal, dispatchedAt: at };
item.deliveries.push(delivery);
}
if (attemptId && !delivery.attempts?.some(row => row.attemptId === attemptId)) {
delivery.attempts ??= []; delivery.attempts.push({ attemptId, wireRequestSha256, dispatchedAt: at });
}
item.status = 'delivered';
return state;
}
+5 -2
View File
@@ -12,6 +12,7 @@ import { prefixAudit } from './prefix-audit.mjs';
import { observeRequest, providerHistory, requestPath } from './request-observation.mjs';
import { verifyToolSurface } from './tool-surface.mjs';
import { isPassthrough } from '../../shared/contracts/model-capacity.mjs';
import { verifyReminderMessage } from './reminder-manager.mjs';
const hash = value => createHash('sha256').update(typeof value === 'string' ? value : JSON.stringify(value), 'utf8').digest('hex');
const PLACEHOLDER_ID = '00000000-0000-0000-0000-000000000000';
@@ -189,7 +190,7 @@ export class RequestPlanner {
return { artifact_id: artifact.id, sha256: artifact.sha256, group_sha256: group.sha256, bytes: Buffer.byteLength(text, 'utf8'), chunks: chunks.length };
}
prepare(session, run, config, { system, contextTail = null, tools, toolSurface = null, stepId, projectMemory = null, skillCatalog = null, mcpCatalog = null, transportReservationTokens = 0,engineStepOnly=false }) {
prepare(session, run, config, { system, contextTail = null, tools, toolSurface = null, stepId, projectMemory = null, skillCatalog = null, mcpCatalog = null, progressReminder = null, transportReservationTokens = 0,engineStepOnly=false }) {
const task = this.store.owned('task', run.taskId, session.id);
this.store.owned('run', run.id, session.id);
const history = providerHistory(session, run);
@@ -406,6 +407,7 @@ export class RequestPlanner {
requestArtifactId: requestArtifact.id,
prefixAudit: prefix,
requestObservation: observation,
...(progressReminder ? { progressReminder } : {}),
...(preserve ? { contextLayout: 'stable-prefix-1', historyPolicy: 'preserve', contextTailArtifactId: tailArtifact?.id ?? null, contextTailSha256: tailArtifact?.sha256 ?? null } : {}),
...(tokenReservation?{tokenReservation,maxBudgetAttempts:Math.min(8,Math.floor(credit/tokenReservation.reservedTokens))}:{engineStepOnly:true}),
estimateMethod: metrics.estimateMethod, beforeInputTokens: before.estimatedInputTokens, beforeBytes: before.bytes, budget,
@@ -474,9 +476,10 @@ export function verifyPlanEvidence(store, session, plan, cache = new Map()) {
historyGroups(requestHistory(body));
for (const variant of requestVariants(body)) historyGroups(requestHistory(variant));
const frozen = JSON.parse(store.artifactStore.read(get(plan.artifactId, 'context-plan')));
for (const key of ['contextLayout', 'historyPolicy', 'contextTailArtifactId', 'contextTailSha256', 'prefixAudit', 'requestObservation']) {
for (const key of ['contextLayout', 'historyPolicy', 'contextTailArtifactId', 'contextTailSha256', 'prefixAudit', 'requestObservation', 'progressReminder']) {
if (JSON.stringify(frozen[key] ?? null) !== JSON.stringify(plan[key] ?? null)) throw new Error('前缀或历史策略与发送前封存不匹配。');
}
verifyReminderMessage(store, session, plan, body);
if (plan.requestObservation) {
const run = store.owned('run', plan.runId, session.id);
const expected = observeRequest(store, session, run, providerHistory(session, run).slice(0, plan.originalMessages), plan.requestObservation.toolSurface);
+14
View File
@@ -11,6 +11,7 @@ import { currentBrowserVerification, verifyBrowserJob } from './browser/browser-
import { TaskPlanManager } from './tasks/task-plan-manager.mjs';
import { RequirementReview } from './tasks/requirement-review.mjs';
import { inspectTurnProgress } from './context/turn-progress-recorder.mjs';
import { ReminderManager } from './context/reminder-manager.mjs';
import { FileResults } from './tasks/file-results.mjs';
import { taskContract } from '../shared/contracts/task-control.mjs';
import { modelIdentityLabel } from '../shared/contracts/model-identity.mjs';
@@ -150,6 +151,8 @@ export class DeliveryReporter {
: researchScope && !check ? contract.checks === 'skip' ? 'scope_verified' : 'research_verified'
: hasFileScope && !fileDelivery.newChanges ? 'existing_verified' : hasFileScope && contract.checks === 'skip' ? 'files_delivered'
: hasCommit ? 'verified_committed' : 'verified_uncommitted';
const reminders = [...this.store.core.run.values()].filter(value => value.sessionId === session.id && value.taskId === taskId && (value.progressReminders || value.progressReminderError))
.map(value => ({ runId: value.id, ...new ReminderManager(this.store).inspect(session, value) }));
const report = {
schemaVersion: 1, kind: 'engineering-delivery', generatedAt: new Date().toISOString(), status, statusLabel: labels[status],
lifecycle: { phase: run.finishedAt ? 'final' : 'snapshot', runStatus: run.status, finishedAt: run.finishedAt ?? null },
@@ -164,6 +167,7 @@ export class DeliveryReporter {
context: inspectDiagnosticContext(this.store, session, value) })),
turnObservations: [...this.store.core.run.values()].filter(value => value.sessionId === session.id && value.taskId === taskId)
.map(value => ({ runId: value.id, ...inspectTurnProgress(this.store, session, value) })),
...(reminders.length ? { reminderObservations: reminders } : {}),
fileResults, fileDelivery,
checkPolicy: contract.checks === 'skip' ? 'not_requested' : contract.checks,
gitOutcome: { status: hasCommit ? 'committed' : terminalGit.length ? 'observed_unverified' : !fileDelivery.newChanges && hasFileScope ? 'no_new_changes' : 'uncommitted',
@@ -269,6 +273,16 @@ export function renderDeliveryMarkdown(report) {
turn.classification, turn.delta.read_characters, turn.delta.repeated_reads, turn.delta.new_failures + ' / ' + turn.delta.repeated_failures,
run.evidence_verified ? '原字节已核对' : run.error].map(escapeCell).join(' | ') + ' |');
}
if (report.reminderObservations?.length) {
lines.push('', '## 提醒与实际回读', '', '随请求发出与后续工具进展分别记录;模型收到、采纳和收益因果未证实,不作为业务交付通过依据。', '',
'| Run / 建议 | 状态 | 实际发送请求 | 回读依据 | 原收据核对 |', '| --- | --- | --- | --- | --- |');
for (const run of report.reminderObservations) {
if (run.error) lines.push('', '提醒观察部分不可用;原任务结果保留。');
for (const item of run.items) lines.push('| ' + [run.runId + ' / ' + item.category, item.status,
item.deliveries.map(row => row.requestId).join(', ') || '未发送', item.resolution?.source.artifactId ?? '尚未观察到对应结果',
run.evidenceVerified ? '原字节已核对' : '待核对'].map(escapeCell).join(' | ') + ' |');
}
}
if (report.taskPlan?.configured) {
lines.push('', '## 执行计划与实际核验', '', '计划:' + (report.taskPlan.plan_id ?? '无法核对'),
'核验:' + (report.taskPlan.verified_steps ?? 0) + '/' + (report.taskPlan.total_steps ?? 0), '',
+2
View File
@@ -8,11 +8,13 @@ export const DEFAULT_CONFIG = {
mode: 'demo', baseUrl: 'http://127.0.0.1:11434/v1', model: '', ...DEFAULT_MODEL_CAPACITY, approvalMode: 'ask', capacityMode: 'passthrough', historyPolicy: 'preserve', executionMode: 'unrestricted', maxSteps: 0,
maxRunDurationMs: 0, maxRunTokens: 0, maxTaskTokens: 0, configRevision: 1,
modelResponseTimeoutMs: 0, modelStreamIdleTimeoutMs: 0,
progressRemindersEnabled: false,
};
export function cleanConfig(value = {}) {
const result = { ...DEFAULT_CONFIG };
for (const key of Object.keys(result)) if (Object.hasOwn(value, key)) result[key] = value[key];
result.progressRemindersEnabled = result.progressRemindersEnabled === true;
if (!Object.hasOwn(value, 'executionMode') && ['contextLimit', 'maxOutputTokens', 'maxSteps', 'maxRunTokens'].some(key => Object.hasOwn(value, key))) result.executionMode = 'restricted';
// Old settings stay manual. Every saved Run keeps its original snapshot.
if (!Object.hasOwn(value, 'capacityMode') && (Object.hasOwn(value, 'contextLimit') || Object.hasOwn(value, 'maxOutputTokens'))) result.capacityMode = 'manual';
+15
View File
@@ -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
View File
@@ -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
View File
@@ -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 => {
+3 -2
View File
@@ -1041,5 +1041,6 @@ F收尾:57d075e修正独立编译QA路径,6d09ac8封存差异;202610302320
## D阶段
1. [complete] 纯队列/稳定key/来源回读/冷却与退出,Node24新10项+原B15项=25/25;见docs/QA-REMINDER-READBACK-D.md。
2. [in_progress] Runtime实际请求/原字节收据、默认关闭与持久偏好、同Run回读、取消/迟到及观察器故障隔离。
3. [pending] 原观察面板与工具设置、真实本机HTTP/网页/Electron、独立发行/回顾/提交。真实供应商与Purge收益不在此切片代签。
2. [complete] Runtime实际提交/wire SHA/不可变请求核对、默认关闭与持久偏好、同Run回读、取消/迟到及故障隔离;最终独立后端23/23、相关95/95,来源区别见QA。
3. [complete] 原观察面板与工具箱设置,网页/实际Electron各7组通过;原失败、截图及最后后端补强来源分别保留,阶段回顾并提交。
4. [in_progress] 1.25.10独立源码/程序、安装与正式入口验收。真实供应商、重复读取普遍改善与Purge收益不在此切片代签。
+31
View File
@@ -0,0 +1,31 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { fixture, launchWorkbench, compatibleFixture, until, completion, call } from './helpers.mjs';
test('HTTP settings persist independently of model credentials and inspected advice remains bound to the original session', async t => {
const f = fixture(t, { modernDefaults: true }); let n = 0;
const model = await compatibleFixture(t, () => ({ body: ++n < 5 ? completion([call('read-' + n, 'read_file', { path: 'README.md', offset: n === 4 ? 10 : 0, limit: 10 })]) : completion([], '本机固定流程完成。') }));
const foreign = f.store.createSession(f.project.id);
f.store.saveConfig({ mode: 'compatible', model: 'local-api-d', baseUrl: model.baseUrl, approvalMode: 'full' }); f.store.close();
let host = await launchWorkbench(t, f.data); assert.equal(host.bootstrap.config.progressRemindersEnabled, false);
const before = await host.api('/model-center/selection');
assert.deepEqual(await host.api('/progress-reminders/settings'), { enabled: false });
await assert.rejects(host.api('/progress-reminders/settings', { enabled: 'yes' }), error => error.status === 400);
await assert.rejects(host.api('/progress-reminders/settings', { enabled: true, approvalMode: 'ask' }), error => error.status === 400);
assert.deepEqual(await host.api('/progress-reminders/settings', { enabled: true }), { enabled: true });
const after = await host.api('/model-center/selection');
const { configRevision: beforeRevision, progressRemindersEnabled: beforeEnabled, ...original } = before.config;
const { configRevision: afterRevision, progressRemindersEnabled: afterEnabled, ...actual } = after.config;
assert.deepEqual(actual, original); assert.equal(afterEnabled, true); assert.equal(afterRevision, beforeRevision + 1);
await host.api('/sessions/' + f.session.id + '/messages', { content: '修改README.md,先读取核对内容;无需测试。' });
await until(async () => !['running', 'stopping', 'awaiting_approval'].includes((await host.api('/sessions/' + f.session.id)).status), 20000);
const state = await host.api('/sessions/' + f.session.id), run = state.execution.run;
const view = await host.api('/sessions/' + f.session.id + '/progress-reminders?run=' + run.id);
assert.equal(n, 5); assert.equal(view.evidenceVerified, true); assert.equal(view.items[0].status, 'resolved');
assert.ok(view.items[0].deliveries[0].requestArtifactId);
await assert.rejects(host.api('/sessions/' + foreign.id + '/progress-reminders?run=' + run.id), error => [403, 404, 409, 400].includes(error.status));
await host.close(); host = await launchWorkbench(t, f.data); assert.deepEqual(await host.api('/progress-reminders/settings'), { enabled: true });
assert.equal((await host.api('/sessions/' + f.session.id + '/progress-reminders?run=' + run.id)).evidenceVerified, true);
assert.deepEqual(await host.api('/progress-reminders/settings', { enabled: false }), { enabled: false });
assert.equal(n, 5, 'settings/readback never call the model');
});
+154
View File
@@ -0,0 +1,154 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import fs from 'node:fs';
import path from 'node:path';
import { fixture, compatibleFixture, call, completion, assertToolPairs, until } from './helpers.mjs';
import { Runtime } from '../src/server/runtime.mjs';
import { Provider } from '../src/server/provider.mjs';
import { Store } from '../src/server/store.mjs';
import { verifyPlanEvidence } from '../src/core/context/request-plan.mjs';
import { DeliveryReporter } from '../src/core/delivery-report.mjs';
const marker = '工作台可选进展建议';
const hasAdvice = body => JSON.stringify(body).includes(marker);
const goal = '修改README.md,先读取核对原内容;无需测试。';
const script = n => n < 4 ? completion([call('read-' + n, 'read_file', { path: 'README.md', offset: 0, limit: 10 })])
: n === 4 ? completion([call('acknowledge-and-read', 'read_file', { path: 'README.md', offset: 0, limit: 10 })], '明白,已知悉。')
: n === 5 ? completion([call('new-range', 'read_file', { path: 'README.md', offset: 10, limit: 10 })]) : completion([], '读取过程结束,未修改源码。');
async function setup(t, enabled = true, respond = n => ({ body: script(n) })) {
const f = fixture(t, { modernDefaults: true }); let requests = 0;
const model = await compatibleFixture(t, (url, body) => respond(++requests, body));
f.store.saveConfig({ mode: 'compatible', model: 'reminder-local-fixture', baseUrl: model.baseUrl, progressRemindersEnabled: enabled });
const runtime = new Runtime(f.store, new Provider()); f.onCleanup(() => runtime.stopAll());
return { ...f, runtime, model, start(content = goal) { runtime.start(f.session.id, content); return runtime.active.get(f.session.id).promise; } };
}
test('default-off runtime preserves original history, tools and unlimited requests without advice receipts', async t => {
const f = await setup(t, false); await f.start();
const run = f.store.core.run.get(f.session.runId);
assert.equal(f.model.requests.length, 6); assert.ok(f.model.requests.every(row => !hasAdvice(row.input)));
assert.equal(run.progressReminders, undefined); assert.equal(run.budget.maxTokens, 0); assert.equal(run.stopReason, null);
for (const row of f.model.requests) assert.equal(row.input.max_tokens, undefined);
assertToolPairs(f.session.providerMessages); assert.equal(f.session.status, 'completed');
});
test('actual HTTP submission, separate acknowledgement and original readback survive reopening and verify every request', async t => {
const f = await setup(t); const original = fs.readFileSync(path.join(f.projectRoot, 'README.md')); await f.start();
const run = f.store.core.run.get(f.session.runId), item = run.progressReminders.items[0];
assert.deepEqual(f.model.requests.map(row => hasAdvice(row.input)), [false, false, false, true, false, false]);
assert.equal(item.deliveries.length, 1); assert.equal(item.deliveries[0].attempts.length, 1); assert.equal(item.status, 'resolved');
assert.equal(item.resolution.relation, 'observed_after_dispatch'); assert.equal(item.resolution.causality, 'unproven');
assert.ok(item.resolution.source.ordinal > item.deliveries[0].ordinal + 1, 'acknowledgement plus repeated read did not resolve advice');
assert.deepEqual(fs.readFileSync(path.join(f.projectRoot, 'README.md')), original); assertToolPairs(f.session.providerMessages);
for (const plan of f.store.core.context_plan.values()) assert.doesNotThrow(() => verifyPlanEvidence(f.store, f.session, plan));
assert.equal(f.runtime.reminderManager().inspect(f.session, run).evidenceVerified, true);
const report = await new DeliveryReporter(f.store).create(f.session);
assert.equal(report.report.reminderObservations[0].evidenceVerified, true);
assert.equal(report.report.reminderObservations[0].items[0].status, 'resolved');
assert.match(f.store.artifactStore.read(f.store.core.artifact.get(report.markdownArtifactId)), /提醒与实际回读/);
assert.notEqual(report.report.status, 'verified_committed', 'reminder readback cannot prove file delivery');
const snapshot = structuredClone(run.progressReminders); f.store.close();
const reopened = new Store(f.data); f.onCleanup(() => reopened.close()); const nextRuntime = new Runtime(reopened, new Provider());
assert.deepEqual(reopened.core.run.get(run.id).progressReminders, snapshot);
assert.equal(reopened.config.progressRemindersEnabled, true);
assert.equal(nextRuntime.reminderManager().inspect(reopened.session(f.session.id), reopened.core.run.get(run.id)).evidenceVerified, true);
});
test('research and diagnosis remain legal read-only work without nudges', async t => {
const f = await setup(t); await f.start('只研究README.md的原内容,不修改文件。');
assert.ok(f.model.requests.every(row => !hasAdvice(row.input))); assert.equal(f.store.core.run.get(f.session.runId).progressReminders.items.length, 0);
assert.equal(f.session.status, 'completed');
});
test('turning off while a sent request waits preserves its dispatch but prevents later advice and readback resolution', async t => {
let release; const gate = new Promise(resolve => { release = resolve; });
const f = await setup(t, true, async n => { if (n === 4) await gate; return { body: script(n) }; });
const running = f.start(); await until(() => f.model.requests.length === 4, 15000);
const run = f.store.core.run.get(f.session.runId); assert.equal(run.progressReminders.items[0].status, 'delivered');
f.store.saveConfig({ progressRemindersEnabled: false }); f.runtime.progressRemindersChanged(); release(); await running;
const item = run.progressReminders.items[0]; assert.equal(item.status, 'expired'); assert.equal(item.exitReason, 'disabled'); assert.equal(item.resolution, undefined);
assert.equal(item.deliveries.length, 1); assert.deepEqual(f.model.requests.map(row => hasAdvice(row.input)), [false, false, false, true, false, false]);
assert.equal(f.runtime.reminderManager().inspect(f.session, run).evidenceVerified, true);
});
test('cancelled requests and a new Task cannot receive late reminder readback', async t => {
let release; const gate = new Promise(resolve => { release = resolve; });
const f = await setup(t, true, async n => { if (n === 4) await gate; return { body: script(n) }; });
const running = f.start(); await until(() => f.model.requests.length === 4, 15000); f.runtime.stop(f.session.id); await running; release();
const run = f.store.core.run.get(f.session.runId); assert.equal(run.stopReason, 'cancelled'); assert.equal(run.progressReminders.items[0].exitReason, 'cancelled');
const original = structuredClone(run.progressReminders); const other = f.store.beginRun(f.session, '新任务,仅查看历史', false, f.store.config, { forceNewTask: true });
assert.notEqual(other.taskId, run.taskId); f.runtime.reminderManager().observe(f.session, run);
assert.deepEqual(run.progressReminders, original); assert.equal(f.model.requests.length, 4);
});
test('reminder artifact failure does not fail or repeat original model requests or tools', async t => {
const f = await setup(t), write = f.store.artifactStore.write.bind(f.store.artifactStore);
f.store.artifactStore.write = (session, run, value, options) => {
if (options?.kind?.startsWith('progress-reminder')) throw new Error('injected reminder storage unavailable');
return write(session, run, value, options);
};
await f.start(); assert.equal(f.model.requests.length, 6); assert.equal(f.session.status, 'completed'); assert.equal(f.session.changes.length, 0);
assert.ok(f.model.requests.every(row => !hasAdvice(row.input))); assertToolPairs(f.session.providerMessages);
assert.equal(f.store.core.run.get(f.session.runId).progressReminderError.kind, 'reminder_unavailable');
});
test('optional request planning failure falls back to original complete request before dispatch', async t => {
const f = await setup(t), planner = f.runtime.requestPlanner(), prepare = planner.prepare.bind(planner); let failures = 0;
planner.prepare = (session, run, config, options) => { if (options.progressReminder) { failures++; throw new Error('injected optional planning failure'); } return prepare(session, run, config, options); };
await f.start(); assert.equal(f.model.requests.length, 6); assert.ok(failures > 0); assert.ok(f.model.requests.every(row => !hasAdvice(row.input)));
const run = f.store.core.run.get(f.session.runId); assert.equal(run.progressReminderError.phase, 'request_plan'); assert.equal(run.progressReminders.items[0].resolution.relation, 'naturally_resolved');
assert.equal(f.session.status, 'completed'); assertToolPairs(f.session.providerMessages);
});
test('actual invalid arguments resolve only after a successful original tool result', async t => {
const f = await setup(t, true, n => ({ body: n < 4 ? completion([call('invalid-' + n, 'read_file', { path: 17 })])
: n === 4 ? completion([call('corrected', 'read_file', { path: 'README.md', offset: 0, limit: 10 })]) : completion([], '读取已核对。') }));
await f.start(); const run = f.store.core.run.get(f.session.runId), item = run.progressReminders.items[0];
assert.equal(f.model.requests.length, 5); assert.equal(item.category, 'repeated_invalid_input'); assert.equal(item.status, 'resolved');
assert.equal(item.resolution.kind, 'corrected_tool_result'); assert.equal(f.runtime.reminderManager().inspect(f.session, run).evidenceVerified, true);
});
test('upstream error after submitting advice stays an upstream failure with unknown usage', async t => {
const f = await setup(t, true, n => n === 4 ? { status: 503, body: { error: { message: 'original supplier unavailable', code: 'D_FIXTURE_503' } } } : { body: script(n) });
await f.start(); const run = f.store.core.run.get(f.session.runId), item = run.progressReminders.items[0];
assert.equal(f.session.status, 'failed'); assert.equal(f.session.lastFailure.httpStatus, 503); assert.equal(f.model.requests.length, 4);
assert.equal(item.status, 'expired'); assert.equal(item.resolution, undefined); assert.equal(item.deliveries.length, 1);
assert.equal(run.usage.unknownRequests, 1); assert.equal(f.runtime.reminderManager().inspect(f.session, run).evidenceVerified, true);
});
test('tampered observation, queue, message or wire request remains unverified without granting completion', async t => {
const f = await setup(t); await f.start(); const run = f.store.core.run.get(f.session.runId), manager = f.runtime.reminderManager();
const item = run.progressReminders.items[0], request = f.store.core.context_plan.get(item.deliveries[0].requestId);
const original = request.progressReminderDispatches[0].wireRequestSha256; request.progressReminderDispatches[0].wireRequestSha256 = '0'.repeat(64);
assert.equal(manager.inspect(f.session, run).evidenceVerified, false); request.progressReminderDispatches[0].wireRequestSha256 = original;
const message = f.store.core.artifact.get(request.progressReminder.artifactId), old = message.sha256; message.sha256 = '0'.repeat(64);
assert.equal(manager.inspect(f.session, run).evidenceVerified, false); message.sha256 = old;
item.status = 'pending'; assert.equal(manager.inspect(f.session, run).evidenceVerified, false); item.status = 'resolved';
const planArtifactId = request.artifactId; request.artifactId = run.progressReminderReceiptId;
assert.equal(manager.inspect(f.session, run).evidenceVerified, false); request.artifactId = planArtifactId;
const receipt = f.store.core.artifact.get(item.source[0].artifactId), file = path.join(f.store.artifactStore.root, receipt.relative), bytes = fs.readFileSync(file);
fs.writeFileSync(file, 'source bytes corrupted'); assert.equal(manager.inspect(f.session, run).evidenceVerified, false); fs.writeFileSync(file, bytes);
assert.equal(manager.inspect(f.session, run).evidenceVerified, true);
});
for (const protocol of ['responses', 'anthropic-messages']) test(protocol + ' routes exact submitted advice through the selected native connection', async t => {
const f = fixture(t, { modernDefaults: true }); let n = 0;
const model = await compatibleFixture(t, () => {
const original = script(++n).choices[0].message, calls = original.tool_calls ?? [];
if (protocol === 'responses') return { body: { id: 'response-' + n, status: 'completed', model: 'owned-model',
output: [...(original.content ? [{ type: 'message', id: 'msg-' + n, status: 'completed', role: 'assistant', content: [{ type: 'output_text', text: original.content }] }] : []),
...calls.map(call => ({ type: 'function_call', id: 'fn-' + call.id, call_id: call.id, status: 'completed', name: call.function.name, arguments: call.function.arguments }))],
usage: { input_tokens: 100, output_tokens: 20, total_tokens: 120 } } };
return { body: { type: 'message', id: 'msg-' + n, role: 'assistant', model: 'owned-model',
content: [...(original.content ? [{ type: 'text', text: original.content }] : []), ...calls.map(call => ({ type: 'tool_use', id: call.id, name: call.function.name, input: JSON.parse(call.function.arguments) }))],
stop_reason: calls.length ? 'tool_use' : 'end_turn', stop_sequence: null, usage: { input_tokens: 100, output_tokens: 20 } } };
});
const provider = new Provider(), hub = provider.modelHub(f.store), connection = hub.upsert({ name: 'Local D ' + protocol, model: 'owned-model', protocol, baseUrl: model.baseUrl, requiresKey: false });
hub.select({ type: 'connection', id: connection.id }); f.store.saveConfig({ mode: 'compatible', progressRemindersEnabled: true });
const runtime = new Runtime(f.store, provider); f.onCleanup(() => runtime.stopAll()); runtime.start(f.session.id, goal); await runtime.active.get(f.session.id).promise;
const run = f.store.core.run.get(f.session.runId); assert.equal(f.session.status, 'completed'); assert.equal(model.requests.length, 6);
assert.deepEqual(model.requests.map(row => hasAdvice(row.input)), [false, false, false, true, false, false]);
assert.equal(run.progressReminders.items[0].deliveries[0].attempts.length, 1); assert.equal(runtime.reminderManager().inspect(f.session, run).evidenceVerified, true);
for (const plan of f.store.core.context_plan.values()) assert.doesNotThrow(() => verifyPlanEvidence(f.store, f.session, plan));
assertToolPairs(f.session.providerMessages);
});