Open-source, local-first AI agent team for your desktop: multi-agent group chats, computer use, browser, MCP, routines and approvals. macOS, Windows, Linux + Android. Built on pi.
TypeScript agentai-agentai-agentsai-assistantandroidautomationchatgptcoding-agentcomputer-usedesktop-appelectronllmlocal-firstmcpmulti-agentollamaopenaiprivacyself-hostedtypescript
fix(computer-use): Finder by bundle ID, precise schema errors, plain Space wording
leen.zhou2ec2627995ff
diff --git a/packages/brain/src/runtime/computer/computer-tools.ts b/packages/brain/src/runtime/computer/computer-tools.tsindex 5199d91..6eb0dbd 100644--- a/packages/brain/src/runtime/computer/computer-tools.ts+++ b/packages/brain/src/runtime/computer/computer-tools.ts@@ -58,19 +58,27 @@ export const computerSchemas = {.max(10).optional(),})- .refine(- (v) =>- v.action === "batch"- ? v.actions !== undefined &&- v.elementId === undefined &&- v.path === undefined &&- v.value === undefined- : v.actions === undefined &&- (v.action === "menu"- ? v.path !== undefined && v.elementId === undefined && v.value === undefined- : v.elementId !== undefined && v.path === undefined),- 'Provide elementId, or menu path, or action="batch" with 1–10 element actions in one window',- ),+ .superRefine((v, ctx) => {+ // One issue per offending field with a fixed code (tool-input-issues.ts words it): a bare+ // "custom" left models re-sending the same mixed shape.+ const flag = (field: string, message: string) =>+ ctx.addIssue({ code: "custom", path: [field], message });+ if (v.action === "batch") {+ if (v.actions === undefined) flag("actions", "ui_action_batch_actions_required");+ for (const field of ["elementId", "path", "value"] as const)+ if (v[field] !== undefined) flag(field, "ui_action_batch_forbids_field");+ return;+ }+ if (v.actions !== undefined) flag("actions", "ui_action_single_forbids_actions");+ if (v.action === "menu") {+ if (v.path === undefined) flag("path", "ui_action_menu_path_required");+ for (const field of ["elementId", "value"] as const)+ if (v[field] !== undefined) flag(field, "ui_action_menu_forbids_field");+ return;+ }+ if (v.elementId === undefined) flag("elementId", "ui_action_element_id_required");+ if (v.path !== undefined) flag("path", "ui_action_element_forbids_path");+ }),pointer: z.strictObject({app,window: window.optional(),@@ -90,7 +98,12 @@ export const computerSchemas = {text: z.string().min(1).max(10_000).optional(),combo: z.array(z.string().min(1).max(20)).min(1).max(5).optional(),})- .refine((v) => (v.text === undefined) !== (v.combo === undefined), "Provide text or combo"),+ .superRefine((v, ctx) => {+ if (v.text !== undefined && v.combo !== undefined)+ ctx.addIssue({ code: "custom", path: ["combo"], message: "keys_text_and_combo" });+ else if (v.text === undefined && v.combo === undefined)+ ctx.addIssue({ code: "custom", path: [], message: "keys_text_or_combo_required" });+ }),open_app: z.strictObject({ app: z.string().trim().min(1).max(200) }),open_file: z.strictObject({ path: z.string().min(1).max(32_768), app }),};diff --git a/packages/brain/src/runtime/tools/tool-input-issues.ts b/packages/brain/src/runtime/tools/tool-input-issues.tsindex 854dffd..b52acba 100644--- a/packages/brain/src/runtime/tools/tool-input-issues.ts+++ b/packages/brain/src/runtime/tools/tool-input-issues.ts@@ -140,6 +140,24 @@ function baseIssueText(issue: z.core.$ZodIssue): string {"tableColumns 必须提供 columns(1–20 个不重复列名) / tableColumns requires columns (1–20 unique names)","Choose ref or screenshotId/x/y":"只用一种方式:要么 ref(来自最新的 browser_snapshot),要么 screenshotId 加 x、y(来自最新的 browser_screenshot),不要同时给 / Use one target: either ref from the latest browser_snapshot, or screenshotId with x and y from the latest browser_screenshot, not both",+ keys_text_and_combo:+ "text 和 combo 只能给一个:text 输入文字,combo 按快捷键;先输入再按键就分两次调用 keys / Give text or combo, not both: text types characters, combo presses a shortcut; to type and then press keys, make two keys calls",+ keys_text_or_combo_required:+ '需要 text(要输入的文字)或 combo(快捷键,如 ["cmd","s"])其中一个 / Provide exactly one of text (characters to type) or combo (a shortcut, e.g. ["cmd","s"])',+ ui_action_batch_actions_required:+ 'action "batch" 需要 actions:[{elementId,action,value?}](1–10 个) / action "batch" requires actions:[{elementId,action,value?}] (1–10)',+ ui_action_batch_forbids_field:+ 'action "batch" 只接受 actions:[{elementId,action,value?}],删除顶层的这个字段 / action "batch" takes only actions:[{elementId,action,value?}]; remove this top-level field',+ ui_action_single_forbids_actions:+ 'actions 只用于 action "batch";单个操作给 elementId(菜单给 path),删除 actions / actions is only for action "batch"; a single action gives elementId (path for menu), so remove actions',+ ui_action_menu_path_required:+ 'action "menu" 需要 path(菜单标题),如 ["Edit","Delete"] / action "menu" requires path (menu titles), e.g. ["Edit","Delete"]',+ ui_action_menu_forbids_field:+ 'action "menu" 只用 path,删除这个字段(elementId / value) / action "menu" uses only path; remove this field (elementId / value)',+ ui_action_element_id_required:+ '元素操作需要 ui_tree 里的 elementId;菜单项改用 action "menu" 加 path / Element actions require elementId from ui_tree; for a menu item use action "menu" with path',+ ui_action_element_forbids_path:+ 'path 只用于 action "menu";元素操作只给 elementId,删除 path / path is only for action "menu"; element actions take elementId, so remove path',acceptance_columns_forbidden:"此检查不接受 columns,请删除;只有 tableColumns 使用 columns / Omit columns; only tableColumns accepts it",};diff --git a/packages/computer-use-contract/src/i18n/computer-handoff.ts b/packages/computer-use-contract/src/i18n/computer-handoff.tsindex cf6b199..d289f47 100644--- a/packages/computer-use-contract/src/i18n/computer-handoff.ts+++ b/packages/computer-use-contract/src/i18n/computer-handoff.ts@@ -33,7 +33,8 @@ export const computerHandoffZh = {"computerHandoff.say.window_minimized.darwin": "请把「{app}」的窗口从程序坞里恢复出来。","computerHandoff.say.window_minimized.win32": "请把「{app}」的窗口从任务栏里恢复出来。","computerHandoff.say.window_minimized.linux": "请恢复「{app}」的窗口。",- "computerHandoff.say.window_other_space.darwin": "请把「{app}」的窗口移到你现在用的这个桌面。",+ "computerHandoff.say.window_other_space.darwin":+ "「{app}」的窗口在另一个桌面,或被全屏应用挡住了。请切换到那个桌面,或先退出全屏。","computerHandoff.say.window_other_space.win32": "请把「{app}」的窗口移到你现在用的这个虚拟桌面。","computerHandoff.say.window_other_space.linux": "请恢复「{app}」的窗口。","computerHandoff.say.window_covered": "「{app}」的窗口被其他窗口挡住了,请把它露出来一部分。",@@ -95,7 +96,7 @@ export const computerHandoffEn: Record<keyof typeof computerHandoffZh, string> ="Please restore the “{app}” window from the taskbar.","computerHandoff.say.window_minimized.linux": "Please restore the “{app}” window.","computerHandoff.say.window_other_space.darwin":- "Please move the “{app}” window to the desktop you're using now.",+ "The “{app}” window is on another desktop or behind a full-screen app. Please switch to that desktop, or exit full screen.","computerHandoff.say.window_other_space.win32":"Please move the “{app}” window to the virtual desktop you're using now.","computerHandoff.say.window_other_space.linux": "Please restore the “{app}” window.",diff --git a/packages/computer-use/src/brain/service/run/computer-text.ts b/packages/computer-use/src/brain/service/run/computer-text.tsindex 90a7a10..65fc75a 100644--- a/packages/computer-use/src/brain/service/run/computer-text.ts+++ b/packages/computer-use/src/brain/service/run/computer-text.ts@@ -206,6 +206,12 @@ const details: [prefix: string, text: string][] = ["窗口几乎完全被别的窗口挡住,截图看不到内容。改用 ui_tree 读界面(后台可用),或请用户把这个窗口放到前面 / " +"The window is almost entirely covered by other windows, so a screenshot shows nothing. Read it with ui_tree (works in the background), or ask the user to bring the window to the front",],+ [+ // The vaguer window_not_found text left the model retrying instead of telling the user.+ "window_on_other_space",+ "这个窗口在另一个桌面(空间)上,或当前桌面是一个全屏应用,Pi Bot 看不到也操作不了它。不要重试同样的调用,也不要自己切换桌面:直接告诉用户切换到这个窗口所在的桌面,或先退出全屏,然后再继续 / " ++ "The window is on another desktop (Space), or the current desktop is a full-screen app, so Pi Bot can neither see nor operate it. Do not retry the same call or switch desktops yourself: tell the user plainly to switch to the desktop that window is on, or exit full screen, then continue",+ ],["window_not_capturable","窗口在屏幕上,但系统没有给出它的截图。改用 ui_tree 读界面,不要重试截图 / " +diff --git a/packages/computer/src/drivers/mac-worker-script.ts b/packages/computer/src/drivers/mac-worker-script.tsindex 4a02dd3..2f4d7cb 100644--- a/packages/computer/src/drivers/mac-worker-script.ts+++ b/packages/computer/src/drivers/mac-worker-script.ts@@ -52,11 +52,23 @@ function unwrapStr(v) {return undefined;}+// A display name resolves through LaunchServices by name; a reverse-DNS bundle ID resolves by ID+// (Finder lives outside the scanned folders). Either way the answer is the bundle LaunchServices+// actually holds, never the raw string, so an ID that names no installed app stays unresolved.function resolveAppName(m) {- var path = $.NSWorkspace.sharedWorkspace.fullPathForApplication(m.name);- if (!unwrapStr(path)) return null;+ var ws = $.NSWorkspace.sharedWorkspace;+ var path = unwrapStr(ws.fullPathForApplication(m.name));+ var byId = false;+ if (!path && /^[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)+$/.test(m.name)) {+ var url = ws.URLForApplicationWithBundleIdentifier(m.name);+ path = url && !url.isNil() ? unwrapStr(url.path) : undefined;+ byId = true;+ }+ if (!path) return null;var bundle = $.NSBundle.bundleWithPath(path);- return bundle ? (unwrapStr(bundle.bundleIdentifier) || null) : null;+ var id = bundle ? unwrapStr(bundle.bundleIdentifier) : undefined;+ if (!id) return null;+ return byId && id.toLowerCase() !== m.name.toLowerCase() ? null : id;}function appInfo(a) {@@ -120,7 +132,11 @@ function installed(m) {else if (depth > 0) scan(path, depth - 1);}}- for (var d = 0; d < m.dirs.length && !truncated; d++) scan(m.dirs[d], 1);+ // An entry naming a bundle itself (Finder.app) is added as is; folders are scanned.+ for (var d = 0; d < m.dirs.length && !truncated; d++) {+ if (/\.app$/.test(m.dirs[d])) add(m.dirs[d]);+ else scan(m.dirs[d], 1);+ }return { apps: out, truncated: truncated };}diff --git a/packages/computer/src/drivers/mac.ts b/packages/computer/src/drivers/mac.tsindex d6b5722..19f47f7 100644--- a/packages/computer/src/drivers/mac.ts+++ b/packages/computer/src/drivers/mac.ts@@ -205,6 +205,8 @@ export function createMacDriver(options: {"/System/Applications",join(homedir(), "Applications"),"/System/Library/CoreServices/Applications",+ // Finder sits directly in CoreServices, next to hundreds of agents that are not targets.+ "/System/Library/CoreServices/Finder.app",];return worker.call<{ apps: InstalledApp[]; truncated: boolean }>("installed",