Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(browser): focus interactive recipes and defer forced exports
Dash1cc131fb5f84
diff --git a/packages/lizi-mcps/src/browser/opencli-page.ts b/packages/lizi-mcps/src/browser/opencli-page.tsindex 173f0fc8b0..819fe73bd8 100644--- a/packages/lizi-mcps/src/browser/opencli-page.ts+++ b/packages/lizi-mcps/src/browser/opencli-page.ts@@ -33,6 +33,7 @@ export class OpenCliPage extends CDPBasePage {constructor(private readonly deps: PageDeps,private readonly home?: string,+ private readonly windowMode?: 'foreground' | 'background',) {super();this.targetId = deps.targetId;@@ -44,6 +45,7 @@ export class OpenCliPage extends CDPBasePage {): Promise<Record<string, unknown>> {const result = await this.deps.call({...request,+ ...(request.action === 'open' && this.windowMode === 'foreground' ? { background: false } : {}),...((request.targetId ?? this.targetId) ? { targetId: request.targetId ?? this.targetId } : {}),});if (!result.ok)@@ -55,6 +57,12 @@ export class OpenCliPage extends CDPBasePage {);const target = data.targetId ?? data.tabId;if (adoptTarget && typeof target === "string") this.targetId = target;+ // Embedded opens are always background; focus explicitly on both backends.+ // One navigation boundary covers goto, lazy target creation and newTab.+ if (this.windowMode === 'foreground' && (request.action === 'open' || request.action === 'navigate')) {+ if (!this.targetId) throw new Error('Browser did not return a targetId');+ await this.request({ action: 'focus' }, false);+ }return data;}@@ -287,6 +295,7 @@ export async function runOpenCliAdapter(const page = new OpenCliPage(deps,command.domain ? `https://${command.domain}` : undefined,+ command.defaultWindowMode,);try {const files = await deps.recipeFiles?.();diff --git a/packages/lizi-mcps/src/browser/opencli-recipes.test.ts b/packages/lizi-mcps/src/browser/opencli-recipes.test.tsindex 8240c973cf..f5ae0a5cda 100644--- a/packages/lizi-mcps/src/browser/opencli-recipes.test.ts+++ b/packages/lizi-mcps/src/browser/opencli-recipes.test.ts@@ -9,7 +9,7 @@ import * as downloads from '@jackwener/opencli/download';import { downloadArticle } from '@jackwener/opencli/download/article-download';import { resolveExistingUploadPaths } from '../../../browser-control-runtime/src/_generated/extension/src/browser/paths.js';import { createBrowserMcpServer } from "./server.js";-import { OpenCliPage } from "./opencli-page.js";+import { OpenCliPage, runOpenCliAdapter } from "./opencli-page.js";import { loadRecipes, RecipeSchema, type Recipe } from "./recipe-loader.js";import { runRecipe } from "./recipe-runner.js";import { executeAdapter, type IPage } from '@jackwener/opencli/cindy';@@ -58,6 +58,50 @@ afterEach(() => {});describe("bundled OpenCLI recipes", () => {+ // #6826 foreground regression, unit tier. Use the real login adapter/page+ // with an in-memory transport: previous navigation tests omitted metadata.+ it.each([undefined, 'existing-target'])('focuses interactive login before probing from %s', async targetId => {+ const calls: BrowserControlRequest[] = [];+ const result = await runOpenCliAdapter('midjourney/login', {}, { targetId, call: async request => {+ calls.push(request);+ const fn = request.request?.fn ?? '';+ return { ok: true, action: request.action, data: request.action === 'open'+ ? { targetId: 'login-target' }+ : { result: fn.includes('location.hostname') ? 'www.midjourney.com'+ : fn.includes('/api/subscriptions-check') ? { ok: true, status: 200,+ text: JSON.stringify({ user_id: 'fixture', status: 'active', plan: { type: 'fixture' } }) }+ : true } };+ } });+ expect(result).toMatchObject({ status: 'already_logged_in', logged_in: true });+ expect(calls.slice(0, 2).map(request => request.action)).toEqual([targetId ? 'navigate' : 'open', 'focus']);+ expect(calls[1].targetId).toBe(targetId ?? 'login-target');+ if (!targetId) expect(calls[0].background).toBe(false);+ });++ it('surfaces a foreground focus failure before login polling starts', async () => {+ const calls: BrowserControlRequest[] = [];+ await expect(runOpenCliAdapter('midjourney/login', {}, { targetId: 'login-target', call: async request => {+ calls.push(request);+ if (request.action === 'act') throw new Error('probe started before focus');+ return request.action === 'focus'+ ? { ok: false, action: request.action, message: 'fixture focus unavailable' }+ : { ok: true, action: request.action, data: { result: true } };+ } })).rejects.toThrow('fixture focus unavailable');+ expect(calls.map(request => request.action)).toEqual(['navigate', 'focus']);+ });++ // Forced screenshots have no opt-out. Exclusion must happen at discovery+ // and direct execution, before drawing mutates a user's canvas (unit tier).+ it.each(['geogebra/triangle', 'geogebra/hexagon'])('defers mandatory file export %s before page effects', async id => {+ const effect = vi.fn(async () => { throw new Error('unexpected canvas mutation'); });+ const start = vi.fn();+ await expect(executeAdapter(id, {}, new Proxy({}, { get: () => effect }) as IPage, undefined, start))+ .rejects.toThrow('Unknown bundled adapter');+ expect(loadRecipes().has(`opencli:${id}`)).toBe(false);+ expect(start).not.toHaveBeenCalled();+ expect(effect).not.toHaveBeenCalled();+ });+// #6826 export-mode recurrence, unit tier. Earlier tests only exercised// link flags and web/stdout, missing optional archive/browser-download modes.// Every retired argument must disappear and fail before execution begins.diff --git a/packages/opencli-vendor/README.md b/packages/opencli-vendor/README.mdindex e0b3c87223..2d97fffbfd 100644--- a/packages/opencli-vendor/README.md+++ b/packages/opencli-vendor/README.md@@ -12,14 +12,14 @@- 1,112 个命令模块,所有生产共享代码、JSON 和其他资源一并引入;不引入上游测试。- 上游快照完整保留,但默认目录独立选择:排除 Z-Library、Slock、Claude.ai、Spotify、ONES、小宇宙适配器、PaperReview、Quark、Kimi、微信读书官方 API、MiniMax、Jira 和 Confluence 共 139 条,- 另暂缓 17 条直接落盘命令,剩余 1,067 条命令、25 个上游别名。原因记录在 [selection.json](cindy/selection.json),+ 另暂缓 19 条直接落盘命令(含两个强制截图的 GeoGebra 绘图命令),剩余 1,065 条命令、25 个上游别名。原因记录在 [selection.json](cindy/selection.json),同步会沿用此选择,排除条目不进入模块导入表和可执行目录。- Cindy 原有 56 个 ID:47 个转到新版适配器,7 个保留原流程,两个爬虫练习站移至`packages/lizi-mcps/src/browser/recipe-examples`,不再出现在默认列表。逐项记录见 [legacy-coverage.json](cindy/legacy-coverage.json)。- Cindy 独立增加 App Store 搜索、Google Play 搜索、TapTap 中国站游戏详情、Steam 玩家评价、Open Library 书目查询和 Crossref 文献/DOI 查询,共 6 个配方,位于- `packages/lizi-mcps/src/browser/cindy-recipes`。共 1,152 个可发现 ID、166 份指南;这个数包含别名和兼容入口。+ `packages/lizi-mcps/src/browser/cindy-recipes`。共 1,150 个可发现 ID、166 份指南;这个数包含别名和兼容入口。- 兼容入口保持输入名,输出改为新版结构化结果;用户本地覆盖层仍优先于内置层。通过 `browser(action="siteguide")` 查询精简完整目录;传 `site`(域名或上游站点名)@@ -61,14 +61,19 @@成功和失败均沿用调用 finally 清理,源文件保留;外部 Chrome 与内嵌浏览器使用相同的暂存入口。- Desktop 不授予适配器直接写任务路径的能力,也不返回任务路径用于目录枚举;路径校验不能保证之后的 mkdir、write、rename 等操作不跟随被替换的链接,因此不为- 这些入口新增跨平台写入机制。17 条直接落盘命令暂缓,生成配方沿用已有链接分支,+ 这些入口新增跨平台写入机制。19 条直接落盘命令暂缓,生成配方沿用已有链接分支,通用网页读取默认返回正文;发现与执行共用这些默认值,显式关闭上述模式在页面动作前拒绝。需要保存结果时使用已有宿主文件工具。调用内诊断、上传副本和转换结果继续可用,结束后清理。+ 临时根由宿主提供,每次调用用 `mkdtemp` 创建不可预测的私有目录(POSIX 为 0700);+ 这遵循现有宿主临时存储边界,不提供对同一操作系统账号下恶意并发进程的沙箱隔离。+ 任意本机命令执行者已经拥有该账号的文件权限,本次目录刷新不引入新的进程隔离机制。- 同一 selection 还收回 16 条命令的 19 个导出参数:X 收藏/喜欢的断点与归档文件、Band图片目录、豆包转录下载,以及生成/通用读取的输出目录和图片下载选项。发现入口不再展示,旧调用即使显式传入也在参数预检时拒绝,早于执行开始和页面/网络动作;命令本身的正文、列表、媒体链接仍可用,幕布的 `output` 格式参数不受影响。不增加下载捕获或文件归档机制。- 脉脉人才搜索使用已有 `sleep(5)` 秒接口;全部来源仅这一处使用不支持的 `waitForTimeout`。+- 配方声明的前台模式传入宿主页对象,首次打开、已有页导航、延迟建页和新页签统一显式聚焦,+ 然后才进行页面读取或登录轮询;聚焦失败直接报告,后台模式保持原有行为。- Instagram 图片转换、视频元数据、封面及 story 裁剪只读取批准字节的调用内副本,不重新打开原始源路径;临时输入及转换结果沿用同一调用目录,在成功或失败后清理。- 抖音分片上传先批准并打开源文件,再创建远端上传;上传 ID 和进度只存于本次调用,diff --git a/packages/opencli-vendor/cindy/host.ts b/packages/opencli-vendor/cindy/host.tsindex 29e99cd0b0..aa1c8e72e1 100644--- a/packages/opencli-vendor/cindy/host.ts+++ b/packages/opencli-vendor/cindy/host.ts@@ -3,7 +3,11 @@ import { readFileSync, writeFileSync, mkdirSync, mkdtempSync, rmSync, openSync,import { tmpdir } from 'node:os';import { join, resolve, relative, isAbsolute, basename } from 'node:path';-/** Lazy allocation: importing the catalog never touches the filesystem. */+/** Lazy allocation: importing the catalog never touches the filesystem.+ * The host chooses the parent; mkdtemp creates an unpredictable private directory+ * (0700 on POSIX). This is ordinary trusted-host temporary storage, not process+ * isolation from another program already running with the same OS user rights.+ */export function recipeTemporaryDirectory(): string {const host = activeHost();if (host.temporaryDirectory) return host.temporaryDirectory;diff --git a/packages/opencli-vendor/cindy/modules.js b/packages/opencli-vendor/cindy/modules.jsindex 52b04f784e..42de35245b 100644--- a/packages/opencli-vendor/cindy/modules.js+++ b/packages/opencli-vendor/cindy/modules.js@@ -310,10 +310,8 @@ import "../clis/geogebra/add-line.js";import "../clis/geogebra/add-point.js";import "../clis/geogebra/add-polygon.js";import "../clis/geogebra/eval.js";-import "../clis/geogebra/hexagon.js";import "../clis/geogebra/info.js";import "../clis/geogebra/list.js";-import "../clis/geogebra/triangle.js";import "../clis/gitee/auth.js";import "../clis/gitee/search.js";import "../clis/gitee/trending.js";@@ -1303,10 +1301,8 @@ export const modules = {"geogebra/add-point.js": true,"geogebra/add-polygon.js": true,"geogebra/eval.js": true,- "geogebra/hexagon.js": true,"geogebra/info.js": true,"geogebra/list.js": true,- "geogebra/triangle.js": true,"gitee/auth.js": true,"gitee/search.js": true,"gitee/trending.js": true,diff --git a/packages/opencli-vendor/cindy/selection.json b/packages/opencli-vendor/cindy/selection.jsonindex e5485e2cc9..c8ac40c8d2 100644--- a/packages/opencli-vendor/cindy/selection.json+++ b/packages/opencli-vendor/cindy/selection.json@@ -1,6 +1,7 @@{"excludedCommands": ["1688/download", "bilibili/download", "douban/download", "grok/image",+ "geogebra/triangle", "geogebra/hexagon","instagram/download", "midjourney/download", "pinterest/download","pixiv/bookmark-download", "pixiv/download", "pixiv/novel-download","rednote/download", "suno/download", "twitter/download", "uiverse/preview",