diff --git a/CHANGELOG.md b/CHANGELOG.md index 71ab0284..10cb3fc1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Agent Workbench 更新记录 +## 1.22.1 · 项目选择与 HTML 文件预览 + +- 网页端打开项目可浏览本机文件夹、常用位置和盘符,保留完整路径输入;选择/取消、加载和错误均有明确反馈。 +- HTML 文件默认打开隔离预览,支持内联脚本及项目相对 CSS、模块、图片和 JSON;可切换源码、刷新或打开独立页面。 +- 桌面端仅放行宿主登记的文件预览,预览页面无法使用工作台原生桥;关闭、切换和宿主退出会释放预览。 + ## 1.22.0 · 内置浏览器与所属开发预览(已本地交付) - 所属Vite预览固定工作区、实际依赖和运行器,核对监听进程/HTTP就绪,支持停止、原日志和unknown核对。 diff --git a/docs/QA-1.22.1.md b/docs/QA-1.22.1.md new file mode 100644 index 00000000..0e76f1b5 --- /dev/null +++ b/docs/QA-1.22.1.md @@ -0,0 +1,21 @@ +# 1.22.1:项目选择与 HTML 文件预览 + +本补丁修复用户在正式网页现场指出的两条基础流程:添加项目只能手输路径;选中 HTML 后只能看源码。原 1.22 的任务浏览器和 Vite 预览仍按各自授权流程使用。 + +## 实现 + +网页增加已认证的本机一层目录选择器,支持常用位置、盘符、上一级、路径前往、筛选、明确选择和取消。选择阶段不添加项目,打开后才保存。桌面沿用 Windows 原生选择器。修复首次目录读取可能覆盖用户刚输入路径的竞态,读取时保持输入禁用,错误保留可恢复路径。 + +HTML 文件默认预览,代码索引定位仍进入源码。预览显示已保存文件,源码/预览可切换,刷新会重新读取文件,独立页面使用相同受限服务。每个预览使用独立 loopback 端口及随机地址、sandbox、静态类型白名单、项目路径校验和 30 分钟闲置回收。普通 HTML 无需 npm、Git 工作区或启动 Vite;项目脚本不能读取工作台 bootstrap/API 或调用桌面原生桥。 + +此处是隔离静态预览:后端服务、构建型应用、外部网站、登录和代理操作继续使用已有的工程预览/授权浏览流程。绝对站点根路径和外部 CDN 不由本补丁重写或自动授权。未将静态预览作为模型页面验收证据。 + +## 验证与回顾 + +- TypeScript、Vite、移动 shell、服务端/桌面构建通过。 +- 40 项定向回归通过:新目录/预览、API、文件、桌面桥和所属任务浏览能力;真实模型请求 0。历史完整回归不计入本补丁新执行结果。 +- 隔离 Edge/Electron 九组主流程通过,覆盖目录选择/取消/错误恢复/刷新保留,内联 JS、相对模块/CSS/图片/JSON、跨源控制接口隔离,源码/刷新、独立页面、切换项目、390px 和实际桌面子帧原生桥隔离。桌面选择取消使用明确的系统对话框夹具;不把它宣称为新人工实机选择。 +- 首轮路径夹具错误指回项目内部;随后改为真实项目外 HTML。Host 拒绝测试改用真实 HTTP 请求,因为 Node fetch 会忽略覆盖的 Host。原开发失败另存。 +- 首轮实际 Electron 在未显示的测试窗口内点击没有产生计数变化;验收器改为实际显示窗口后,原控件点击通过。未以脚本赋值替代点击。 + +本地部署身份、精确数据保持及现场回看将在完成后补入;下一 1.23 发行效率计划继续保留。本补丁不调用真实模型、不续跑用户任务,也不修改用户 HTML。 diff --git a/findings.md b/findings.md index f0769774..a35e2809 100644 --- a/findings.md +++ b/findings.md @@ -841,3 +841,6 @@ Responses已采用typed Items、call_id原配对和同线路加密reasoning续 B独立管线已运行,受门控的推广等待独立源码/便携/同载荷安装完整成功,正式状态不得提前改写。恢复时一次补丁使用未知标题导致原子拒绝,随后改用已读定位;没有修改产品输入。 冻结期间复核了历史UI与随包专项的收据归属:all-ui将原结果复制到版本化docs指针,并保留各自日志/独立UUID目录;随后随包环境、原生参数、等待、协议、视觉、缓存、伴随及评测验证器写各自原目录,不覆盖这些主回归docs收据。最终封存仍逐一核对原结果/日志中的显式目录和截图SHA;没有仅凭最新全局指针推断历史结果。此项为静态归属审查,不增加模型或重跑已通过的验证。 +# 当前现场:两条基本操作缺口 + +正式服务实际 1.22.0,URL 的旧 release 参数不代表实际版本。网页的选择文件夹按钮被 desktop 条件隐藏;选中 pelican-bicycle.html 后只有源码且无预览入口。文件包含内联 SVG/JS 动画;现有任务浏览能力要求 Vite/桌面,不适用于直接打开普通 HTML。本次用已认证的本机一层目录浏览补网页选择;HTML 以独立 loopback 源、受限静态资源和 sandbox 渲染,不把项目脚本放进工作台 API 同源。 diff --git a/package-lock.json b/package-lock.json index 6720587e..e5769ee3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "local-agent-workbench", - "version": "1.22.0", + "version": "1.22.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "local-agent-workbench", - "version": "1.22.0", + "version": "1.22.1", "dependencies": { "@babel/parser": "7.29.11", "@peculiar/x509": "3.1.0", diff --git a/package.json b/package.json index 35e8b6fa..a4cb7d8e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "local-agent-workbench", - "version": "1.22.0", + "version": "1.22.1", "private": true, "type": "module", "description": "A local coding workbench with explicit tool execution, reviewable changes and recoverable sessions.", diff --git a/progress.md b/progress.md index 1ae033e6..a43cd6b9 100644 --- a/progress.md +++ b/progress.md @@ -1241,3 +1241,10 @@ A–C首实现已写入:只读Node/npm/Python/pytest诊断、锁定npm ci、 独立管线`.qa/reproducible-env-independent.mjs`已启动(exec session26683),控制台`.qa/reproducible-env-independent-console.log`;冻结身份`.qa/reproducible-env-code-baseline.json`绑定输入/构建与a94807f。顺序:新不可变package→归档解压至D:/AWQA21短路径→独立源码全套(一般并发2、upgrade.test独占)→便携→8类随包UI→自有旧1.20.3升级→同载荷隔离安装7组。管线终结`.qa/reproducible-env-independent-result.json`成功前不运行正式升级。正式驱动`.qa/reproducible-env-formal.mjs`接受stage/upgrade/activate/verify,每阶段新收据且拒绝重放;已有旧脚本只复制为新名,不改旧证据。正式当前仍1.20.3/PID36552,Provider未动。 2026-11-01核对未提交实现和原始验收。环境专项原13/13、UI实际7组通过,迁移补登记后升级2/2通过;真实工程原轮仍失败,不能认定D完成。定位Vite空临时目录误判后修正身份逻辑,保留目录预算和外部链接拒绝,新增空目录与实际代码变化的行为验证。当前串行环境/评测专项运行中,后续重跑原React/Python并完成冻结发行。正式1.20.3/PID36552、Provider与用户项目未修改,真实模型请求0。 +# 项目选择 / HTML 预览修复接续 + +40/40 定向回归及 Edge/Electron 九组实际流程通过。实际复核 wide/390px 截图:目录常用位置、文件列表、选择动作可见且无横向溢出,HTML 有完整脚本与相对资源。源码定位仍保持原有行为。正式部署采用新不可变本地补丁候选,复用原 1.22.0 已有运行组件并重新核对全部清单,避免为两项修复重打无关大型历史证据压缩包;不改原安装目录或历史发行物,仍使用产品激活和指针回退机制。单独发行下载包不作为本次已完成能力。 + +初轮构建修正桌面桥可选对象的 TS 空值收窄后通过。定向 39 项首轮 38 通过;一项失败来自夹具把 junction 指回项目内部并错误期望它被当作越界。改为真实项目外 HTML 来验证边界,保留初轮失败记录,不改 safePath 既有语义。接续实际浏览器脚本/相对模块/样式/图片与桌面流程验收。补丁版本 1.22.1。 + +已核对 bfd2f21 干净工作树并创建 fix/project-picker-html-preview。现场两项缺陷已复现。使用 product-ui-ux 与 frontend-design,保留既有界面,只补核心操作流程。正式服务、用户 HTML、会话和 Provider 尚未修改。历史完整回归只作为历史证据,不计作本补丁新执行。 diff --git a/scripts/upgrade-running.mjs b/scripts/upgrade-running.mjs index b1effe5c..67178471 100644 --- a/scripts/upgrade-running.mjs +++ b/scripts/upgrade-running.mjs @@ -64,7 +64,7 @@ export async function upgradeRunning({ url, pid, currentRoot, newRoot, handlerRo if (!fs.existsSync(originalScript) || !fs.existsSync(upgradeScript) || !fs.existsSync(path.join(next, 'dist-client', 'index.html'))) throw new Error('Upgrade bundles are incomplete.'); if (!Number.isInteger(pid) || pid < 1 || pid === process.pid) throw new Error('Invalid target process.'); const before = await readUpgradeJson(origin + '/api/bootstrap', 5000, 'Read original Workbench'); - if (!before.token || !['0.1.0', '1.0.0', '1.1.0', '1.2.0', '1.3.0', '1.4.0', '1.5.0', '1.5.1', '1.6.0', '1.6.1', '1.6.2', '1.7.0', '1.8.0', '1.9.0', '1.10.0', '1.10.1', '1.11.0', '1.12.0', '1.12.1', '1.13.0', '1.14.0', '1.15.0', '1.16.0', '1.17.0', '1.18.0', '1.19.0', '1.20.0', '1.20.1', '1.20.2', '1.20.3', '1.21.0', '1.22.0'].includes(before.version)) throw new Error('This migration accepts a supported existing Workbench.'); + if (!before.token || !['0.1.0', '1.0.0', '1.1.0', '1.2.0', '1.3.0', '1.4.0', '1.5.0', '1.5.1', '1.6.0', '1.6.1', '1.6.2', '1.7.0', '1.8.0', '1.9.0', '1.10.0', '1.10.1', '1.11.0', '1.12.0', '1.12.1', '1.13.0', '1.14.0', '1.15.0', '1.16.0', '1.17.0', '1.18.0', '1.19.0', '1.20.0', '1.20.1', '1.20.2', '1.20.3', '1.21.0', '1.22.0', '1.22.1'].includes(before.version)) throw new Error('This migration accepts a supported existing Workbench.'); if (before.sessions.some(session => ['running', 'awaiting_approval', 'stopping'].includes(session.status))) throw new Error('Wait for existing tasks and approvals before upgrading.'); let protocol, socket, enabledHere = false, paused = false; const breakpoints = []; diff --git a/scripts/verify-desktop-window.mjs b/scripts/verify-desktop-window.mjs index 0f8e5440..e9d7bf32 100644 --- a/scripts/verify-desktop-window.mjs +++ b/scripts/verify-desktop-window.mjs @@ -64,7 +64,7 @@ try { } else { stage = 'sandboxed renderer and fixed preload'; const surface = await page.evaluate(() => ({ methods: Object.keys(window.desktopWorkbench).sort(), require: typeof window.require, process: typeof window.process, ipc: typeof window.ipcRenderer, frozen: Object.isFrozen(window.desktopWorkbench) })); - const browserMethods = original.version === '1.22.0' ? ['browsingLayout'] : []; + const browserMethods = ['1.22.0', '1.22.1'].includes(original.version) ? ['browsingLayout', ...(original.version === '1.22.1' ? ['openFilePreview'] : [])] : []; assert.deepEqual(surface.methods, [...browserMethods, 'pickProject', 'projectFolder', 'protocol', 'revealFile', 'reviewTask', 'status', 'stopHost'].sort()); assert.equal(surface.require, 'undefined'); assert.equal(surface.process, 'undefined'); assert.equal(surface.ipc, 'undefined'); assert.equal(surface.frozen, true); const preferences = await (await application.browserWindow(page)).evaluate(value => value.webContents.getLastWebPreferences()); diff --git a/scripts/verify-local-files.mjs b/scripts/verify-local-files.mjs new file mode 100644 index 00000000..51fa96cb --- /dev/null +++ b/scripts/verify-local-files.mjs @@ -0,0 +1,118 @@ +import fs from 'node:fs'; +import path from 'node:path'; +import net from 'node:net'; +import assert from 'node:assert/strict'; +import { randomUUID, createHash } from 'node:crypto'; +import { chromium, _electron, expect } from 'playwright/test'; +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'; + +if (process.argv.includes('--help')) { console.log('node scripts/verify-local-files.mjs — isolated real Edge/Electron project-picker and HTML preview acceptance; optional AGENT_WORKBENCH_QA_APP_ROOT for immutable candidate. No model requests.'); process.exit(0); } +if (process.argv.length > 2) throw Error('Use --help.'); +const appRoot = path.resolve(process.env.AGENT_WORKBENCH_QA_APP_ROOT || '.'), root = path.resolve('.qa', 'local-files-' + randomUUID()); +const dataRoot = path.join(root, 'data'), projectRoot = path.join(root, '中文 项目'), otherRoot = path.join(root, 'other-project'); +fs.mkdirSync(path.join(projectRoot, 'pages'), { recursive: true }); fs.mkdirSync(path.join(projectRoot, 'assets')); fs.mkdirSync(otherRoot); +fs.writeFileSync(path.join(otherRoot, 'README.md'), '# Other project'); +fs.writeFileSync(path.join(projectRoot, 'assets', 'theme.css'), 'body{font:16px system-ui;background:#f4f7fa;color:rgb(20,60,100);padding:24px}button{padding:12px}img{width:64px;height:64px}'); +fs.writeFileSync(path.join(projectRoot, 'assets', 'mark.svg'), ''); +fs.writeFileSync(path.join(projectRoot, 'assets', 'value.mjs'), 'export const label="相对模块已运行";'); +fs.writeFileSync(path.join(projectRoot, 'assets', 'data.json'), '{"message":"相对数据已加载"}'); +fs.writeFileSync(path.join(projectRoot, 'assets', 'app.mjs'), 'import {label} from "./value.mjs";document.querySelector("#module").textContent=label;fetch("./../assets/data.json").then(r=>r.json()).then(v=>document.querySelector("#data").textContent=v.message);'); +const reserve = net.createServer(); await new Promise(resolve => reserve.listen(0, '127.0.0.1', resolve)); const port = reserve.address().port; await new Promise(resolve => reserve.close(resolve)); +const controller = new HostController({ appRoot, dataRoot, port, nodePath: process.execPath, timeoutMs: 60000 }); +let browser, application, stage = 'start'; const checks = [], screenshots = [], errors = []; +const record = name => { checks.push(name); console.log(name + ': passed'); }; +const screenshot = async (page, name) => { const file = path.join(root, name + '.png'); await page.screenshot({ path: file }); screenshots.push({ file, sha256: createHash('sha256').update(fs.readFileSync(file)).digest('hex') }); }; +const overflow = async page => assert.equal(await page.evaluate(() => document.documentElement.scrollWidth > innerWidth), false); +async function fileFlow(page, label) { + const item = page.getByRole('button', { name: '页面.html', exact: true }); + await item.waitFor(); await item.click(); + const frame = page.frameLocator('iframe[title="HTML 预览:pages/页面.html"]'); + await expect(frame.getByRole('heading', { name: '文件预览验收' })).toBeVisible(); + await expect(frame.locator('#module')).toHaveText('相对模块已运行'); + await expect(frame.locator('#data')).toHaveText('相对数据已加载'); + await expect(frame.locator('#boundary')).toHaveText('工作台接口已隔离'); + await expect(frame.locator('body')).toHaveCSS('color', 'rgb(20, 60, 100)'); + await expect.poll(() => frame.locator('img').evaluate(image => image.complete && image.naturalWidth)).toBe(64); + await frame.getByRole('button', { name: '计数 0' }).click(); + await expect(frame.getByRole('button', { name: '计数 1' })).toBeVisible(); record(label + ': inline JS, relative modules/CSS/image/JSON, workbench isolation and interaction'); + await screenshot(page, label + '-preview-wide'); + await page.getByRole('button', { name: '源码', exact: true }).click(); + await expect(page.locator('.code-view')).toContainText(''); + await expect(page.locator('iframe')).toHaveCount(0); + await page.getByRole('button', { name: '预览', exact: true }).click(); await expect(frame.getByRole('button', { name: '计数 0' })).toBeVisible(); + await frame.getByRole('button', { name: '计数 0' }).click(); await page.getByRole('button', { name: '刷新预览' }).click(); + await expect(frame.getByRole('button', { name: '计数 0' })).toBeVisible(); record(label + ': source switch and fresh saved-file reload'); + return frame; +} +try { + const original = await controller.start(); + fs.writeFileSync(path.join(projectRoot, 'pages', '页面.html'), `文件预览验收

文件预览验收

相对图像

等待模块

等待数据

核对隔离

`); + const initial = (await controller.api('/bootstrap')).projects.length; + browser = await chromium.launch({ channel: 'msedge', headless: true }); + const page = await browser.newPage({ viewport: { width: 1440, height: 960 } }); page.on('pageerror', error => errors.push(error.message)); + await page.goto(controller.url); await page.locator('.connection.connected').waitFor(); + stage = 'web directory picker'; + await page.getByRole('button', { name: '打开项目', exact: true }).click(); + await page.getByRole('button', { name: '选择文件夹', exact: true }).click(); + await page.getByLabel('浏览文件夹路径').fill(root); await page.getByRole('button', { name: '前往', exact: true }).click(); + await page.getByRole('button', { name: '中文 项目', exact: true }).click(); + await screenshot(page, 'web-directory-wide'); + await page.getByRole('button', { name: '取消选择' }).click(); + assert.equal((await controller.api('/bootstrap')).projects.length, initial); + await page.getByLabel('项目文件夹路径').fill(path.join(root, 'missing')); + await page.getByRole('dialog').getByRole('button', { name: '打开项目', exact: true }).click(); + await expect(page.getByRole('dialog').getByRole('alert')).toBeVisible(); + await page.getByLabel('项目文件夹路径').fill(root); + await page.getByRole('button', { name: '选择文件夹', exact: true }).click(); + await page.getByRole('button', { name: '中文 项目', exact: true }).click(); + await page.getByRole('button', { name: '使用此文件夹' }).click(); + await expect(page.getByLabel('项目文件夹路径')).toHaveValue(projectRoot); + await page.getByRole('dialog').getByRole('button', { name: '打开项目', exact: true }).click(); + await expect(page.getByRole('dialog')).toHaveCount(0); + const project = (await controller.api('/bootstrap')).projects.find(item => item.root === projectRoot); assert.ok(project); + await page.reload(); await expect(page.getByRole('combobox', { name: '当前项目', exact: true })).toHaveValue(project.id); record('web: directory selection, cancel, invalid path recovery, project persistence'); + stage = 'web HTML preview'; await fileFlow(page, 'web'); + const link = page.getByRole('link', { name: '独立页面' }), popupEvent = page.waitForEvent('popup'); await link.click(); const popup = await popupEvent; + await expect(popup.getByRole('heading', { name: '文件预览验收' })).toBeVisible(); await popup.close(); record('web: independent page renders'); + await page.setViewportSize({ width: 390, height: 844 }); await overflow(page); await screenshot(page, 'web-preview-390'); + const other = await controller.api('/projects', { method: 'POST', input: { root: otherRoot } }); + await page.setViewportSize({ width: 1440, height: 960 }); await page.reload(); + await page.getByRole('combobox', { name: '当前项目', exact: true }).selectOption(other.id); await expect(page.locator('iframe')).toHaveCount(0); record('web: project switch clears old file preview'); + await page.getByRole('button', { name: '打开项目', exact: true }).click(); await page.getByRole('button', { name: '选择文件夹', exact: true }).click(); + await page.getByLabel('浏览文件夹路径').fill(root); await page.getByRole('button', { name: '前往', exact: true }).click(); + await page.setViewportSize({ width: 390, height: 844 }); await overflow(page); await screenshot(page, 'web-directory-390'); + await browser.close(); browser = null; + stage = 'actual Electron preview'; + const executable = desktopExecutableIdentity(appRoot).path, packaged = executable.toLowerCase().endsWith('agentworkbench.exe'); + application = await _electron.launch({ executablePath: executable, args: [...(packaged ? [] : [path.join(appRoot, 'dist-desktop/main.cjs')]), '--app-root', appRoot, '--data-root', dataRoot, '--node', process.execPath, '--port', String(port), '--hidden-window'], cwd: appRoot, env: projectEnvironment(), timeout: 60000 }); + const desktopPage = await application.firstWindow(); desktopPage.on('pageerror', error => errors.push(error.message)); + await (await application.browserWindow(desktopPage)).evaluate(window => { window.showInactive(); window.setContentSize(1440, 960); }); + await desktopPage.locator('.connection.connected').waitFor(); await desktopPage.getByRole('combobox', { name: '当前项目', exact: true }).selectOption(project.id); + await fileFlow(desktopPage, 'electron'); await overflow(desktopPage); + const rejected = await desktopPage.frameLocator('iframe').locator('body').evaluate(() => ({ bridge: typeof window.desktopWorkbench, require: typeof window.require })); + assert.deepEqual(rejected, { bridge: 'undefined', require: 'undefined' }); record('electron: preview subframe has no native bridge or Node'); + await desktopPage.getByRole('button', { name: '源码', exact: true }).click(); + // Exercise the actual Windows openDirectory dialog contract with an explicit + // cancelled fixture, without asking the user to select a test-only project. + await application.evaluate(({ dialog }) => { dialog.showOpenDialog = async () => ({ canceled: true, filePaths: [] }); }); + await desktopPage.getByRole('button', { name: '打开项目', exact: true }).click(); await desktopPage.getByRole('button', { name: '选择文件夹', exact: true }).click(); + await expect(desktopPage.getByRole('dialog')).toBeVisible(); record('electron: existing native picker cancel leaves project unchanged (explicit dialog fixture)'); + await application.close(); application = null; + assert.deepEqual(errors, []); + const final = await controller.api('/bootstrap'); assert.equal(final.config.mode, 'demo'); assert.equal(final.config.hasKey, false); assert.equal(final.version, '1.22.1'); + const result = { success: true, version: final.version, appRoot, root, checks, screenshots, realModelRequests: 0, errors, hostPid: original.identity.pid }; + fs.writeFileSync(path.join(root, 'result.json'), JSON.stringify(result, null, 2)); fs.writeFileSync('.qa/local-files-latest.json', JSON.stringify(result, null, 2)); console.log(JSON.stringify({ success: true, checks: checks.length, root })); +} catch (error) { + for (const [index, page] of (browser?.contexts().flatMap(context => context.pages()) || []).entries()) { + await screenshot(page, 'failure-' + index).catch(() => {}); + fs.writeFileSync(path.join(root, 'failure-' + index + '.html'), await page.content().catch(() => 'Page unavailable')); + } + if (application) { + const page = await application.firstWindow(); await screenshot(page, 'failure-electron').catch(() => {}); + fs.writeFileSync(path.join(root, 'failure-electron.html'), await page.content().catch(() => 'Page unavailable')); + } + const result = { success: false, stage, root, checks, screenshots, errors, error: error.stack }; + fs.writeFileSync(path.join(root, 'result.json'), JSON.stringify(result, null, 2)); fs.writeFileSync('.qa/local-files-latest.json', JSON.stringify(result, null, 2)); console.error(JSON.stringify(result, null, 2)); process.exitCode = 1; +} finally { await browser?.close(); await application?.close(); await controller.stop().catch(() => {}); } diff --git a/src/client/App.tsx b/src/client/App.tsx index 5c439e3d..addceb49 100644 --- a/src/client/App.tsx +++ b/src/client/App.tsx @@ -1,4 +1,6 @@ import { EmbeddedBrowserPanel } from './EmbeddedBrowserPanel'; +import { ProjectDirectoryPicker } from './ProjectDirectoryPicker'; +import { HtmlFilePreview } from './HtmlFilePreview'; import { useEffect, useMemo, useRef, useState } from '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, Puzzle, Search, Server as ModelServer, Settings2, ShieldCheck, Square, SquareTerminal, Trash2, X } from 'lucide-react'; import type { Bootstrap, Change, Config, ModelSelection, FileEntry, OpenFile, Project, ResearchDoc, Session, SessionBrief, ToolEvent, RuntimeDiagnostics, RuntimeFailure } from './types'; @@ -46,6 +48,7 @@ export default function App() { const [filter, setFilter] = useState(''); const [collapsed, setCollapsed] = useState>(new Set()); const [openFile, setOpenFile] = useState(null); + const [fileMode, setFileMode] = useState<'source' | 'preview'>('source'); const [fileLoading, setFileLoading] = useState(false); const [fileLine, setFileLine] = useState(null); const [fileNotice, setFileNotice] = useState(''); @@ -78,6 +81,9 @@ export default function App() { const [settingsBusy, setSettingsBusy] = useState(false); const [projectOpen, setProjectOpen] = useState(false); const [projectInput, setProjectInput] = useState(''); + const [directoryPickerOpen, setDirectoryPickerOpen] = useState(false); + const [projectBusy, setProjectBusy] = useState(false); + const [projectError, setProjectError] = useState(''); const [toast, setToast] = useState(''); const [researchOpen, setResearchOpen] = useState(false); const [reaOpen, setReaOpen] = useState(false); @@ -270,13 +276,15 @@ export default function App() { finally { setSending(false); } } async function openProject() { - if (!projectInput.trim()) return; + if (!projectInput.trim() || projectBusy) return; + setProjectBusy(true); setProjectError(''); try { const project = await api('/projects', { root: projectInput.trim() }); setProjects(previous => [project, ...previous.filter(item => item.id !== project.id)]); await chooseProject(project.id); setProjectOpen(false); setProjectInput(''); notify('已打开项目 ' + project.name); - } catch (error) { failure(error); } + } catch (error) { setProjectError(error instanceof Error ? error.message : '打开项目失败。'); } + finally { setProjectBusy(false); } } async function acceptDesktopProject(project: Project) { setProjects(previous => [project, ...previous.filter(item => item.id !== project.id)]); @@ -295,7 +303,7 @@ export default function App() { try { const file = await api('/projects/' + targetProject + '/file?path=' + encodeURIComponent(relative)); if (fileRequest.current === request && selectedProjectRef.current === targetProject) { - setOpenFile(file); setDraft(file.content); + setOpenFile(file); setDraft(file.content); setFileMode(!location && /\.html?$/i.test(file.path) ? 'preview' : 'source'); if (location && file.sha256 !== location.expectedSha256) setFileNotice('文件在索引后已变化,已打开当前内容。请回到索引刷新后重新定位。'); else if (location && location.line >= 1 && location.line <= file.content.split('\n').length) setFileLine(location.line); } @@ -608,7 +616,7 @@ export default function App() { onDoubleClick={()=>setInspectorWidth(null)} onKeyDown={event=>{const width=event.currentTarget.parentElement!.getBoundingClientRect().width;if(event.key==='ArrowLeft'||event.key==='ArrowRight'){event.preventDefault();resizeInspector(width+(event.key==='ArrowLeft'?32:-32));}else if(event.key==='Home'){event.preventDefault();resizeInspector(310);}else if(event.key==='End'){event.preventDefault();resizeInspector(maximumInspector);}}}/>}
setWide(previous => !previous)}>{narrow ? : wide ? : }
- {tab === 'file' && (fileLoading ?
正在读取文件
: openFile ?
{openFile.path} navigator.clipboard.writeText(openFile.content).then(() => notify('已复制文件内容。')).catch(failure)}> { setEditing(previous => !previous); setDraft(openFile.content); }}>
{lineCount} 行 · {openFile.bytes.toLocaleString()} B{fileLine ? ' · 定位第 ' + fileLine + ' 行' : ''}{openFile.sha256.slice(0, 10)}
{fileNotice &&
{fileNotice}
}{editing ? <>