diff --git a/docs/CAPABILITIES.md b/docs/CAPABILITIES.md index 0f476856..7f420298 100644 --- a/docs/CAPABILITIES.md +++ b/docs/CAPABILITIES.md @@ -6,6 +6,8 @@ 下一阶段[1.12执行方案](PLAN-1.12.md)按连接注册/专业界面、模型池、配置导入、运行巡检四个切片推进。轮询、跨品牌协议、多模态、自动导入和其他长期能力在各自实现与实际验证前均为计划。 +2026-10-30源码进度:fb58a41已实现多连接、兼容Chat协议池路由、已确认格式导入与只读巡检;仍未作为新不可变发行部署。新增项目记忆管理支持跨会话查看、来源/工程指纹、到期/归档与不完整扫描降级,7项专项和全量312/312通过,桌面/390px已核对。模型上下文接入、真实模型池任务和WorkBuddy未知schema继续单独验收。 + ## 1. 能力的完成定义 “研究到机制”“模块实现”“契约检查通过”“真实工程验收通过”分别登记。只有实现进入产品、相关检查通过、用户场景有实际结果,才标为可交付。外部客户端的能力和本地其他项目中的模块,也分别记录,不能计入工作台现有能力。 @@ -103,7 +105,7 @@ | C02 执行状态与恢复 | 会话JSON保存,active/waiters在内存;重启不重放命令 | 独立Task/Run/Step身份、持久事件、检查点与未知结果核对 | CC-2、CU-1、DS-1 / storage、tasks / M1 | 在审批、调用、结果与落盘等切点中断;恢复不重复已完成副作用 | | C03 工程识别与索引 | 提供有界文件清单/文本搜索,没有工程索引 | 识别语言、入口、规则、脚本、依赖和Git;增量索引;符号/引用与必要的语义检索 | CU-2、DS-3 / context / M2 | 对Node/React/Python样本定位实际修改入口;代码变动后索引更新 | | C04 上下文与项目归属 | 有提取式消息投影、运行诊断和当前项目资料 | 为Run组合需求、规则、代码、错误与验证结果;引用来源;严格绑定项目 | CC-2、CU-1 / context、contracts / M1–M2 | 切换两个项目/任务后,错误与工具结果仍归属正确;大输出用工件引用 | -| C05 长期项目记忆 | 保存聊天历史,没有可检验的长期事实 | 记住决策、约束、失败与有效做法;附commit/文件来源;失效重检;压缩保留目标和未完成项 | CC-2、WB-1 / context、storage / M4 | 长任务压缩/重启后完成标准不丢;过期代码事实被更新或标记 | +| C05 长期项目记忆 | 项目所属持久条目、来源/工程指纹、到期/归档与不完整扫描降级已实现;尚未进入模型上下文 | 记住决策、约束、失败与有效做法;来源重检、上下文预算与压缩保留目标和未完成项 | CC-2、WB-1 / context、storage / M4 | 长任务压缩/重启后完成标准不丢;过期代码事实被更新或标记 | | C06 工具、Skills与MCP | 固定6工具,没有动态注册或外部工具契约 | 工具注册、schema与能力声明;版本锁定Skills/MCP;安装/调用有来源和范围 | CC-1、CU-1、WB-2 / tools / M3 | 未知工具、错误参数、工具失联有原调用身份;新工具可按契约接入 | | C07 执行控制 | 文件范围/基线检查、逐次命令确认与进程停止 | 操作范围、授权记录、预算、进程所有权、并发准入和取消传播;沿用用户已授权的范围 | CC-1、CU-1、DS-1 / tools、tasks / M1–M4 | 过期授权不能用于新Run;停止只处理所属任务;修改后的输入重新校验 | | C08 精确编辑与多文件变更 | 完整替换单文件提案,有备份与冲突拒绝 | patch、创建/改名/删除、多文件ChangeSet、基线校验、隔离应用与可恢复合并 | CU-2 / workspaces / M2 | 跨4文件修改保留无关内容;外部改动引起冲突;部分失败有明确状态 | diff --git a/docs/PLAN-1.12.md b/docs/PLAN-1.12.md index ec4f550a..ee30d09f 100644 --- a/docs/PLAN-1.12.md +++ b/docs/PLAN-1.12.md @@ -16,6 +16,10 @@ A–D分别提交和验收。A先建立注册与归属,B依赖A,C使用A的连接契约,D贯穿每一切片;每次正式升级继续使用不可变发行目录和全量数据核对。新的真实模型验收在连接与用户安排就绪后执行。 +2026-10-30开发状态:A–D首个切片已本地提交fb58a41,支持兼容Chat协议连接注册、内存凭据、轮询/权重与故障切换、已验证CCSwitch/工作台JSON导入及只读运行巡检。WorkBuddy schema、更多协议、真实模型与正式发行仍待单独验收。 + +项目记忆管理切片已完成项目隔离、来源SHA256/工程指纹、显式到期/归档和扫描不完整时的unverified状态;专项7/7、桌面/390px和固定环境全量312/312通过。当前记忆不进入通用执行快照,也尚未进入模型请求;下一切片仅在来源重新核对且完整预算允许时纳入上下文。源码核对表示来源仍匹配,不能证明用户记忆内容的业务结论正确。 + ## 专业界面与操作结构 用户需要持续交付工程的工作空间。桌面采用坚实的工程控制台:蓝黑文字、钢灰底、清楚的实体面板和高辨识操作状态;减少小字号、低对比细线和大块无用途留白。数字只显示实际量测结果。 diff --git a/findings.md b/findings.md index edc8bd51..8f424468 100644 --- a/findings.md +++ b/findings.md @@ -338,3 +338,10 @@ Claude Code 报告已验证工具输入校验、权限决定、队列并发屏 - `ConfigImporter.apply` 保留既有来源自动同步偏好;同步只在来源指纹变化时导入,来源不变也更新`lastCheckedAt`。手动修改后的连接不被自动同步覆盖,并报告冲突;凭据始终只写入Provider内存。 - 独立UI验收的可访问标签在原页面使用自定义label结构,模型池/连接操作按实际DOM定位;桌面1440px和手机390px截图均核对无横向溢出。巡检报告明确`modelRequests=0`。 - 1.12代码仍未作为不可变发行部署;真实模型、WorkBuddy schema、加密凭据、多模态和移动远程配对属于后续切片,不能从本地夹具通过推断完成。 + +## 2026-10-30 项目记忆切片接续 + +- 项目记忆已保存在已有SQLite memory记录类型中,保留创建会话/Task/Run、来源和工程指纹;源码变化和到期持久化为memory.expired,显式归档需要来源会话。 +- 不完整工程扫描会将当前条目展示为unverified并禁止新增;明确引用的文件即使被清单排除,也单独比较SHA256。普通executionSnapshot不暴露记忆,因此inspect_session不能绕过复核。 +- 固定Node v24.22.1和隔离Python 3.10.11/pytest8.4.2后,全量312/312通过,0失败/取消/跳过,580409.4888ms。此前缺pytest失败仍保留;本次测试运行未写独立完整TAP,不冒称已有原TAP文件。 +- 项目记忆管理/界面通过不代表已进入模型上下文;下一切片需对current、来源完整性、字节/条目预算、数据标记和provider.redact建立真实本地HTTP请求证据。 diff --git a/package.json b/package.json index c693381e..5db3719e 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,8 @@ "verify:browser": "node scripts/verify-browser.mjs", "verify:browser-ui": "node scripts/verify-browser-ui.mjs", "verify:task-plans": "node scripts/verify-task-plans-ui.mjs", - "verify:model-center": "node scripts/verify-model-center-ui.mjs" + "verify:model-center": "node scripts/verify-model-center-ui.mjs", + "verify:project-memory": "node scripts/verify-project-memory-ui.mjs" }, "dependencies": { "@babel/parser": "7.29.11", diff --git a/progress.md b/progress.md index fd7452c0..d9dc3ee7 100644 --- a/progress.md +++ b/progress.md @@ -380,3 +380,9 @@ - 本地巡检只读检查Node、SQLite、最近工件和模型配置,不发送模型请求、不执行项目命令;前端专业模型中心覆盖桌面和390px窄屏。 - 固定Node `v24.22.1`并设置隔离Python `3.10.11/pytest 8.4.2`后完整回归 **305/305通过**;最终构建通过。模型中心专项7/7通过;独立桌面/390px验收5组通过,0页面错误、0请求失败、0巡检模型请求。证据目录:`.qa/model-center-ui-69ae2c90-cd8d-461f-86ca-d598f56ce15e`。 - 首轮304项的2项pytest失败是环境未注入解释器,已原样保留;本轮不覆盖该诊断。正式4318未重启、不读取Key、不发真实模型请求。 +# 2026-10-30 项目记忆接续 + +- 恢复fb58a41后的未提交记忆管理切片,读取AGENTS.md和既有计划;正式4318保持原服务和凭据,不执行真实模型调用。 +- 全量回归使用C:/Program Files/nodejs/node.exe v24.22.1及.qa/dev-task-plans/.qa/python-3.10/Scripts/python.exe:312通过,0失败/取消/跳过,耗时580409.4888ms,退出码0。本次原输出在执行工具记录中,未生成完整TAP文件。 +- 之前构建、7项记忆专项与1440px/390px界面验收已完成;界面证据为.qa/project-memory-ui-004a0733-3aa5-4a13-b8be-7c120a84d7a8/result.json。 +- 当前完成范围是持久记忆管理与来源失效;模型上下文接入仍待实现,先整理文档和本地提交,再独立验证下一切片。 diff --git a/scripts/verify-project-memory-ui.mjs b/scripts/verify-project-memory-ui.mjs new file mode 100644 index 00000000..a2842d9f --- /dev/null +++ b/scripts/verify-project-memory-ui.mjs @@ -0,0 +1,73 @@ +import fs from 'node:fs'; +import path from 'node:path'; +import assert from 'node:assert/strict'; +import { randomUUID } from 'node:crypto'; +import { chromium, expect } from 'playwright/test'; +import { fixture, launchWorkbench } from '../tests/helpers.mjs'; + +const evidenceDir = path.resolve('.qa', 'project-memory-ui-' + randomUUID()); +fs.mkdirSync(evidenceDir, { recursive: true }); +const disposers = [], t = { after: dispose => disposers.push(dispose) }; +const f = fixture(t); f.store.close(); +const host = await launchWorkbench(t, f.data); +assert.notEqual(new URL(host.url).port, '4318'); +const browser = await chromium.launch({ channel: 'msedge', headless: true }); +const page = await browser.newPage({ viewport: { width: 1440, height: 1000 } }); +const project = f.project, session = f.session; +const pageErrors = [], requestFailures = [], marks = []; +page.on('pageerror', error => pageErrors.push(error.message)); +page.on('requestfailed', request => requestFailures.push(request.url() + ': ' + request.failure()?.errorText)); +const mark = value => { marks.push(value); console.log('PASS ' + value); }; + +try { + await page.addInitScript(({ projectId, sessionId }) => { localStorage.setItem('awb-project', projectId); localStorage.setItem('awb-session', sessionId); }, + { projectId: project.id, sessionId: session.id }); + await page.goto(host.url); await page.waitForLoadState('networkidle'); + await page.getByRole('button', { name: '项目记忆', exact: true }).click(); + const dialog = page.getByRole('dialog', { name: '项目记忆', exact: true }); await expect(dialog).toBeVisible(); + await expect(dialog.locator('.memory-editor')).toBeVisible(); + const editor = dialog.locator('.memory-editor'); + await editor.getByLabel('标题', { exact: true }).fill('文件来源记忆'); + await editor.getByLabel('来源文件(可选)', { exact: true }).fill('README.md'); + await editor.getByLabel('内容', { exact: true }).fill('这条事实绑定README的实际字节和项目源码指纹。'); + await editor.getByRole('button', { name: '保存记忆', exact: true }).click(); + const firstCard = dialog.locator('.memory-card').filter({ hasText: '文件来源记忆' }); + await expect(firstCard).toContainText('当前'); await expect(firstCard).toContainText('来源 SHA'); + const initialExecution = await host.api('/sessions/' + session.id + '/execution'); + assert.equal(Object.hasOwn(initialExecution, 'memories'), false); + fs.appendFileSync(path.join(f.projectRoot, 'README.md'), '\nExternal fixture change.\n'); + await dialog.getByRole('button', { name: '重新核对', exact: true }).click(); + await expect(firstCard).toContainText('已过期'); await expect(firstCard).toContainText('来源文件已变化'); + assert.equal((await host.api('/projects/' + project.id + '/memories')).summary.expired, 1); + mark('source hashes remain visible and a changed file is explicitly expired with retained provenance'); + await page.screenshot({ path: path.join(evidenceDir, 'desktop-expired-memory.png') }); + + await editor.getByLabel('标题', { exact: true }).fill('扫描范围记忆'); + await editor.getByLabel('来源文件(可选)', { exact: true }).fill(''); + await editor.getByLabel('内容', { exact: true }).fill('不完整工程扫描时不能把记忆冒充当前事实。'); + await editor.getByRole('button', { name: '保存记忆', exact: true }).click(); + const currentCard = dialog.locator('.memory-card').filter({ hasText: '扫描范围记忆' }); + await expect(currentCard).toContainText('当前'); + fs.writeFileSync(path.join(f.projectRoot, 'oversized-source.mjs'), Buffer.alloc(1024 * 1024 + 1)); + await dialog.getByRole('button', { name: '重新核对', exact: true }).click(); + await expect(dialog.locator('.memory-scope-warning')).toContainText('源码扫描未覆盖完整工程'); + await expect(currentCard).toContainText('扫描不完整'); + await expect(editor.getByRole('button', { name: '保存记忆', exact: true })).toBeDisabled(); + const incomplete = await host.api('/projects/' + project.id + '/memories'); + assert.equal(incomplete.summary.current, 0); assert.equal(incomplete.summary.unverified, 1); + assert.equal(incomplete.memories.find(value => value.title === '扫描范围记忆').status, 'unverified'); + assert.equal((await host.api('/sessions/' + session.id + '/execution')).memories, undefined); + mark('incomplete inventory marks existing facts unverified and blocks new saves'); + + await page.setViewportSize({ width: 390, height: 844 }); + assert.ok(await page.locator('body').evaluate(node => node.scrollWidth <= 390), '390px viewport must not overflow horizontally'); + await page.screenshot({ path: path.join(evidenceDir, 'mobile-incomplete-memory.png'), fullPage: false }); + mark('390px memory review stays within the viewport with the incomplete-scan warning visible'); + assert.deepEqual(pageErrors, []); assert.deepEqual(requestFailures, []); + fs.writeFileSync(path.join(evidenceDir, 'result.json'), JSON.stringify({ url: host.url, viewportWidths: [1440, 390], + assertions: marks, pageErrors, requestFailures, screenshots: ['desktop-expired-memory.png', 'mobile-incomplete-memory.png'] }, null, 2)); + console.log('EVIDENCE ' + evidenceDir); +} finally { + await browser.close(); + for (const dispose of disposers.reverse()) await dispose(); +} diff --git a/src/client/App.tsx b/src/client/App.tsx index 4f72a105..061f2080 100644 --- a/src/client/App.tsx +++ b/src/client/App.tsx @@ -1,5 +1,5 @@ import { useEffect, useMemo, useRef, useState } from 'react'; -import { Activity, ClipboardCheck, RotateCw, ArrowDownToLine, ArrowRight, ArrowUp, BookOpenText, Check, ChevronDown, ChevronRight, Code2, Copy, File, FileCode2, Folder, FolderOpen, GitBranch, Link2, LoaderCircle, Maximize2, MessageSquare, Minimize2, PanelLeftClose, PanelLeftOpen, Pencil, Play, Plus, Search, Server as ModelServer, Settings2, ShieldCheck, Square, SquareTerminal, Trash2, X } from 'lucide-react'; +import { Activity, Brain, ClipboardCheck, RotateCw, ArrowDownToLine, ArrowRight, ArrowUp, BookOpenText, Check, ChevronDown, ChevronRight, Code2, Copy, File, FileCode2, Folder, FolderOpen, GitBranch, Link2, LoaderCircle, Maximize2, MessageSquare, Minimize2, PanelLeftClose, PanelLeftOpen, Pencil, Play, Plus, Search, Server as ModelServer, Settings2, ShieldCheck, Square, SquareTerminal, Trash2, X } from 'lucide-react'; import type { Bootstrap, Change, Config, FileEntry, OpenFile, Project, ResearchDoc, Session, SessionBrief, ToolEvent, RuntimeDiagnostics, RuntimeFailure } from './types'; import { api, downloadBlob, exportSession, setToken } from './api'; import { DiffView, EmptyInspector, IconButton, Modal, ResearchContent, Status, ToolRow, FailureCard } from './components'; @@ -10,6 +10,7 @@ import { ChangesInspector } from './ChangesInspector'; import { ResearchPanel } from './ResearchPanel'; import { EnginePanel } from './EnginePanel'; import { ModelCenter } from './ModelCenter'; +import { ProjectMemoryPanel } from './ProjectMemoryPanel'; const activeStates = ['running', 'awaiting_approval', 'stopping']; const defaultConfig: Config = { mode: 'demo', baseUrl: 'http://127.0.0.1:11434/v1', model: '', contextLimit: 16000, maxSteps: 12, maxOutputTokens: 2048, hasKey: false, maxRunDurationMs: 600000, maxRunTokens: 200000, maxTaskTokens: 1000000 }; @@ -66,6 +67,7 @@ export default function App() { const [reaOpen, setReaOpen] = useState(false); const [engineOpen, setEngineOpen] = useState(false); const [modelCenterOpen, setModelCenterOpen] = useState(false); + const [memoryOpen, setMemoryOpen] = useState(false); const [researchDocs, setResearchDocs] = useState([]); const [report, setReport] = useState<{ title: string; content: string } | null>(null); const chatEnd = useRef(null); @@ -500,7 +502,7 @@ export default function App() { if (file.kind === 'directory') setCollapsed(previous => { const next = new Set(previous); if (next.has(file.path)) next.delete(file.path); else next.add(file.path); return next; }); else loadFile(file.path); }}>{file.kind === 'directory' ? <>{collapsed.has(file.path) ? : } : <>}{filter ? file.path : file.name})}{filter && !visibleFiles.length &&

没有匹配的文件。

} -
{ready ? '本地服务已连接' : '正在连接本地服务'}v{version}
+
{ready ? '本地服务已连接' : '正在连接本地服务'}v{version}
{(!sidebarOpen || mobile) && setSidebarOpen(true)}>}
{selectedProject?.name || '工作空间'} 任务

{session?.title || '让任务走到完成'}

@@ -552,6 +554,7 @@ export default function App() { {engineOpen && session && selectedProject && setEngineOpen(false)}>} {researchOpen && setResearchOpen(false)}>
{report && }
} {modelCenterOpen && setModelCenterOpen(false)}> { setModelCenterOpen(false); openSettings(); }} />} + {memoryOpen && selectedProject && setMemoryOpen(false)}>} {toast &&
{toast} setToast('')}>
} ); diff --git a/src/client/ProjectMemory.css b/src/client/ProjectMemory.css new file mode 100644 index 00000000..8b3809c4 --- /dev/null +++ b/src/client/ProjectMemory.css @@ -0,0 +1,3 @@ +.project-memory{display:flex;flex-direction:column;min-height:0;background:#f8fafc;color:#15283f;padding:24px 28px;overflow:auto}.memory-overview{display:flex;align-items:flex-start;justify-content:space-between;gap:18px;padding-bottom:18px;border-bottom:1px solid #cbd5df}.memory-eyebrow{display:flex;align-items:center;gap:7px;color:#2560a3;letter-spacing:.13em;font-size:10px;font-weight:700}.memory-overview h3{font-size:22px;margin:8px 0 5px}.memory-overview p{color:#5b6d83;font-size:12px;line-height:1.8}.memory-summary{display:flex;gap:16px;flex-wrap:wrap;padding:13px 0;color:#5d7088;font-size:12px}.memory-summary strong{color:#15283f;font-size:16px;margin-right:4px}.memory-summary code{color:#33577f}.memory-list{display:grid;gap:11px}.memory-card{padding:17px 18px;background:#fff;border:1px solid #cbd6e2;border-left:3px solid #2f806e;border-radius:6px}.memory-card.memory-expired{border-left-color:#b4772b;background:#fffaf0}.memory-card.memory-archived{border-left-color:#8b9aaa;background:#f4f7fa;opacity:.82}.memory-card-heading{display:flex;align-items:center;gap:10px;flex-wrap:wrap}.memory-card-heading h4{font-size:14px;flex:1;min-width:130px}.memory-card-heading time{font-size:11px;color:#74859a}.memory-state{padding:3px 7px;border:1px solid #b9d9cb;border-radius:4px;color:#216d5f;background:#e6f3ee;font-size:10px;font-weight:650}.memory-expired .memory-state{color:#8b5c12;background:#fff4d9;border-color:#e6d09d}.memory-archived .memory-state{color:#67788d;background:#e9eef3;border-color:#d1dbe4}.memory-content{font-size:13px;line-height:1.8;white-space:pre-wrap;overflow-wrap:anywhere;margin-top:11px;color:#233b55}.memory-meta{display:flex;gap:8px;align-items:center;flex-wrap:wrap;margin-top:12px;color:#6a7d92;font-size:11px}.memory-meta code{font-size:10px;color:#7b8ca1}.memory-tag{padding:3px 6px;background:#edf3f8;color:#4e6884;border-radius:3px}.memory-warning{display:flex;align-items:flex-start;gap:6px;color:#8b5c12;font-size:11px;line-height:1.7;margin-top:11px}.memory-card>.text-button{padding:8px 0;margin-top:8px}.memory-notice,.memory-error{display:flex;gap:7px;align-items:flex-start;padding:11px 13px;margin:15px 0 0;border-radius:5px;font-size:12px;line-height:1.7}.memory-notice{color:#216d5f;background:#e6f3ee;border:1px solid #b9d9cb}.memory-error{color:#a7353e;background:#fff0f0;border:1px solid #e8bac0}.memory-empty{display:grid;place-items:center;padding:38px 20px;margin:7px 0 17px;background:#fff;border:1px dashed #b5c6d7;border-radius:7px;color:#61738a;text-align:center}.memory-empty svg{color:#6c87a5;margin-bottom:10px}.memory-empty strong{color:#314b68;font-size:14px}.memory-empty p{font-size:12px;line-height:1.8;margin-top:7px;max-width:480px}.memory-editor{padding:19px 20px;margin-top:18px;border:1px solid #b2c6da;border-top:3px solid #2560a3;border-radius:7px;background:#fff}.memory-editor-heading{display:flex;align-items:flex-start;justify-content:space-between;color:#2560a3}.memory-editor-heading h4{font-size:15px;color:#15283f}.memory-editor-heading p{font-size:11px;color:#687a90;margin-top:5px;line-height:1.7}.memory-form-grid{display:grid;grid-template-columns:1fr 1fr;gap:14px;margin-top:16px}.memory-form-grid label{display:flex;flex-direction:column;gap:7px;color:#4e637d;font-size:11px}.memory-form-grid input,.memory-form-grid textarea{border:1px solid #b9c8d6;border-radius:5px;padding:9px 10px;min-height:38px;font:inherit;color:#15283f;resize:vertical}.memory-form-grid input:focus,.memory-form-grid textarea:focus{outline:2px solid #2560a333;border-color:#2560a3}.memory-full{grid-column:1/-1}.memory-editor-footer{display:flex;align-items:center;justify-content:space-between;gap:15px;flex-wrap:wrap;margin-top:14px}.memory-editor-footer>span{display:flex;align-items:center;gap:6px;color:#67798e;font-size:11px}.memory-editor-footer svg{color:#2f806e}.project-memory button{min-height:36px} +@media(max-width:620px){.project-memory{padding:18px 15px}.memory-overview{flex-direction:column}.memory-form-grid{grid-template-columns:1fr}.memory-full{grid-column:auto}.memory-editor{padding:17px 14px}.memory-card{padding:15px 13px}.memory-card-heading time{width:100%}} +.memory-unverified .memory-state{color:#8a5b16;background:#fff7df;border-color:#ead39a}.memory-scope-warning{margin:14px 0;padding:12px 14px;line-height:1.7} diff --git a/src/client/ProjectMemoryPanel.tsx b/src/client/ProjectMemoryPanel.tsx new file mode 100644 index 00000000..4b9b6629 --- /dev/null +++ b/src/client/ProjectMemoryPanel.tsx @@ -0,0 +1,52 @@ +import { useEffect, useRef, useState } from 'react'; +import type { FormEvent } from 'react'; +import { Archive, Brain, CircleHelp, LoaderCircle, Plus, RefreshCw, ShieldCheck } from 'lucide-react'; +import type { Project, ProjectMemory, ProjectMemoryView, Session } from './types'; +import { api } from './api'; +import './ProjectMemory.css'; + +const statusLabel: Record = { current: '当前', unverified: '扫描不完整', expired: '已过期', archived: '已归档' }; + +export function ProjectMemoryPanel({ project, session }: { project: Project; session: Session | null }) { + const [view, setView] = useState(null); + const [loading, setLoading] = useState(false); + const [working, setWorking] = useState(false); + const [notice, setNotice] = useState(''); + const [error, setError] = useState(''); + const [draft, setDraft] = useState({ title: '', content: '', sourcePath: '', tags: '', expiresAt: '' }); + const alive = useRef(true); + const load = async () => { + setLoading(true); setError(''); + try { const result = await api('/projects/' + project.id + '/memories'); if (alive.current) setView(result); } + catch (cause) { if (alive.current) setError(cause instanceof Error ? cause.message : '项目记忆读取失败。'); } + finally { if (alive.current) setLoading(false); } + }; + useEffect(() => { alive.current = true; void load(); return () => { alive.current = false; }; }, [project.id]); + const create = async (event: FormEvent) => { + event.preventDefault(); if (!session || !draft.content.trim()) return; + setWorking(true); setError(''); setNotice(''); + try { + await api('/sessions/' + session.id + '/memories', { title: draft.title || '未命名记忆', content: draft.content, tags: draft.tags.split(',').map(value => value.trim()).filter(Boolean), ...(draft.sourcePath.trim() ? { source: { kind: 'file', path: draft.sourcePath.trim() } } : {}), ...(draft.expiresAt ? { expiresAt: new Date(draft.expiresAt).toISOString() } : {}) }); + if (alive.current) { setDraft({ title: '', content: '', sourcePath: '', tags: '', expiresAt: '' }); setNotice('记忆已保存,并绑定当前源码指纹。'); await load(); } + } catch (cause) { if (alive.current) setError(cause instanceof Error ? cause.message : '项目记忆保存失败。'); } + finally { if (alive.current) setWorking(false); } + }; + const archive = async (memory: ProjectMemory) => { + if (!session) return; + setWorking(true); setError(''); + try { await api('/sessions/' + session.id + '/memories/' + memory.id + '/archive', {}); if (alive.current) { setNotice('已归档这条记忆。'); await load(); } } + catch (cause) { if (alive.current) setError(cause instanceof Error ? cause.message : '项目记忆归档失败。'); } + finally { if (alive.current) setWorking(false); } + }; + const memories = view?.memories ?? []; + return
+
PROJECT MEMORY

项目记忆

只复用经过源码指纹核对的事实;工程变化后自动进入历史状态。

+ {notice &&

{notice}

} + {error &&

{error}

} + {view &&
{view.summary.current} 条当前记忆{(view.summary.unverified ?? 0) > 0 && {view.summary.unverified} 条未能验证}{view.summary.expired} 条需重新核对源码 {view.sourceFingerprint.slice(0, 12)}
} + {view && !view.scope.complete &&

本次源码扫描未覆盖完整工程(已扫描 {view.scope.scannedFiles} 个文件,{view.scope.bytes.toLocaleString()} 字节);现有记忆暂标为“扫描不完整”,不会作为当前事实。请缩小项目范围或排除超预算文件后重新核对。

} + {!memories.length && !loading &&
这个项目还没有记忆

保存架构决策、约束和经过核对的工程事实,后续任务可以直接查看来源。

} +
{memories.map(memory =>
{statusLabel[memory.status] || memory.status}

{memory.title}

{memory.content}

来源:{memory.source.kind === 'file' ? memory.source.path : memory.source.label || memory.source.kind}{memory.source.sha256 && 来源 SHA {memory.source.sha256.slice(0, 12)}}工程 {memory.sourceFingerprint.slice(0, 12)}{memory.tags.map(tag => {tag})}
{memory.expiredReason &&

{memory.expiredReason}

}{memory.status !== 'archived' && }
)}
+

保存一条项目记忆

来源默认绑定当前会话;填写文件路径后会额外保存文件 SHA256。