diff --git a/apps/desktop/README.i18n.yaml b/apps/desktop/README.i18n.yaml index 17a48145b7..4eebef3d9d 100644 --- a/apps/desktop/README.i18n.yaml +++ b/apps/desktop/README.i18n.yaml @@ -2,5 +2,5 @@ # side as of the last confirmed-consistent state. Both languages carry equal authority; # after editing either side, bring the other along and re-record with: # pnpm run verify-translation-pairing --write apps/desktop/README.md -README.md: 9f5ad70146b04ac6bd114dd8f8833434b840f9ad -README.zh.md: 872f673c9a0a3a7be525f89b901a21d0f7145282 +README.md: c419013f5248d6103635a5dc01222e83627cdc4e +README.zh.md: f329872715793c28a6bb82d3e5aff62a3c69c335 diff --git a/apps/desktop/README.md b/apps/desktop/README.md index 9f5ad70146..c419013f52 100644 --- a/apps/desktop/README.md +++ b/apps/desktop/README.md @@ -40,7 +40,7 @@ Electron owns the reserved profile at `$AVN_HOME/profiles/desktop`. Its manifest The main avn renderer receives only the desktop protocol marker. The separate plugin window receives structured list, install, remove, update, and update-check operations; neither renderer receives filesystem access, raw Electron IPC, a shell, or arbitrary pnpm arguments. -Link clicks and right-click menus are split the same way. The window opens no browser of its own: an address its content asks to open is reported to the page (`external-links.ts`), which opens it in the sidebar's browser, in the Host's Chromium that the agent drives, or in the system browser, and a page that never subscribes keeps the operating-system handoff. A right-click menu is drawn in this process but described by the page (`app-menu.ts`, `context-menu.ts`), because the page knows what its own links and file names mean: the shell validates the rows, pops the native menu, and reports the chosen row back. The sidebar address bar and agent navigation accept HTTP(S) and `file:` URLs; local pages retain the guest's sandbox, context isolation, and disabled Node integration. +Link clicks and right-click menus are split the same way. The window opens no browser of its own: an address its content asks to open is reported to the page (`external-links.ts`), which opens it in the sidebar's browser, in the Host's Chromium that the agent drives, or in the system browser, and a page that never subscribes keeps the operating-system handoff. A right-click menu is drawn in this process but described by the page (`app-menu.ts`, `context-menu.ts`), because the page knows what its own links and file names mean: the shell validates the rows, pops the native menu, and reports the chosen row back. The sidebar address bar and agent navigation accept HTTP(S) and `file:` URLs; local pages retain the guest's sandbox, context isolation, and disabled Node integration. While the agent drives a guest, and for a minute after its last action, the guest keeps background throttling off (`browser-guests.ts`): a throttled guest in a hidden or covered window draws no frames, so a menu or dialog the agent closed never finishes closing and its backdrop takes the next click. Electron chooses typed English or Chinese shell copy from its application locale and falls back to English. Menus, native dialogs, and the plugin-management renderer use the same locale payload; the repository Client UI i18n gate checks these desktop sources. diff --git a/apps/desktop/README.zh.md b/apps/desktop/README.zh.md index 872f673c9a..f329872715 100644 --- a/apps/desktop/README.zh.md +++ b/apps/desktop/README.zh.md @@ -40,7 +40,7 @@ Electron 拥有保留 profile `$AVN_HOME/profiles/desktop`。其 manifest(元 avn 主渲染进程只获得桌面协议标记。独立插件窗口获得结构化的列出、安装、移除、更新和更新检查操作;两个渲染进程都拿不到文件系统、原始 Electron IPC、shell 或任意 pnpm 参数。 -链接点击与右键菜单同样分工。窗口自己不打开任何浏览器:内容请求打开的地址会被上报给页面(`external-links.ts`),由页面在侧边栏浏览器、agent 所驱动的 Host Chromium,或系统浏览器中打开;从未订阅的页面仍走操作系统交接。右键菜单在本进程中绘制,但由页面描述(`app-menu.ts`、`context-menu.ts`),因为页面才知道自己的链接与文件名意味着什么:shell 校验这些行,弹出原生菜单,并把读者所选的行回传给页面。侧边栏地址栏与 agent 导航接受 HTTP(S) 和 `file:` URL;本地页面仍使用 guest 的沙箱、上下文隔离,并禁用 Node integration。 +链接点击与右键菜单同样分工。窗口自己不打开任何浏览器:内容请求打开的地址会被上报给页面(`external-links.ts`),由页面在侧边栏浏览器、agent 所驱动的 Host Chromium,或系统浏览器中打开;从未订阅的页面仍走操作系统交接。右键菜单在本进程中绘制,但由页面描述(`app-menu.ts`、`context-menu.ts`),因为页面才知道自己的链接与文件名意味着什么:shell 校验这些行,弹出原生菜单,并把读者所选的行回传给页面。侧边栏地址栏与 agent 导航接受 HTTP(S) 和 `file:` URL;本地页面仍使用 guest 的沙箱、上下文隔离,并禁用 Node integration。agent 驱动 guest 期间及其最后一次操作后的一分钟内,该 guest 关闭后台节流(`browser-guests.ts`):被节流的 guest 在隐藏或被遮挡的窗口中不绘制帧,agent 关闭的菜单或对话框便永远关不完,其遮罩会截走下一次点击。 Electron 根据应用 locale 选择类型化的英文或中文桌面壳文案,并以英文作为 fallback。菜单、原生对话框与插件管理渲染进程使用同一 locale 数据;仓库的 Client UI i18n gate 会检查这些桌面源文件。 diff --git a/apps/desktop/src/browser-guests.ts b/apps/desktop/src/browser-guests.ts index 9d0f233cf8..07f55cb09a 100644 --- a/apps/desktop/src/browser-guests.ts +++ b/apps/desktop/src/browser-guests.ts @@ -122,6 +122,44 @@ function attachDebugger(guest: WebContents): void { if (!guest.debugger.isAttached()) guest.debugger.attach(CDP_VERSION) } +/** + * How long a guest keeps drawing frames in a background window after its last + * engine operation. A transition an action starts, such as a menu closing or a + * dialog fading out, runs after the operation returns, and the agent's next + * action follows the model's turn; a throttled guest in a hidden or covered + * window draws no frames, so the transition never ends and its backdrop takes + * the next click. + */ +const RENDER_AFTER_OPERATION_MS = 60_000 + +/** Engine operations in flight per guest, and the pending return to background throttling. */ +const renderingGuests = new WeakMap() + +/** + * Keep a guest rendering while the application window is in the background, for + * one engine operation and {@link RENDER_AFTER_OPERATION_MS} after the last one + * ends. Outside that window the guest is throttled again, so a page the agent + * left does not spend frames or timers while nobody watches it. + * @param guest - the guest an operation is about to drive. + * @returns the call that marks the operation ended. + */ +function renderWhileDriven(guest: WebContents): () => void { + const state = renderingGuests.get(guest) ?? { operations: 0, timer: undefined } + renderingGuests.set(guest, state) + clearTimeout(state.timer) + state.timer = undefined + state.operations += 1 + guest.setBackgroundThrottling(false) + return () => { + state.operations -= 1 + if (state.operations > 0) return + state.timer = setTimeout(() => { + state.timer = undefined + if (!guest.isDestroyed()) guest.setBackgroundThrottling(true) + }, RENDER_AFTER_OPERATION_MS) + } +} + /** * Binding a guest's page calls to report that its content moved. * @@ -329,6 +367,7 @@ export function registerBrowserIpc(isAppSender: (event: IpcMainEvent | IpcMainIn const closed = new AbortController() const destroyed = (): void => { closed.abort() } guest.once('destroyed', destroyed) + const driven = renderWhileDriven(guest) try { const target = guestTarget(guest) return await run(event, guest.id, operation, input, requestId, timeoutMs, @@ -342,6 +381,7 @@ export function registerBrowserIpc(isAppSender: (event: IpcMainEvent | IpcMainIn } }, closed.signal) } finally { + driven() guest.off('destroyed', destroyed) } }) diff --git a/packages/preset/agent-presets/presets/aeven/procedures/x-post.md b/packages/preset/agent-presets/presets/aeven/procedures/x-post.md new file mode 100644 index 0000000000..93eae17594 --- /dev/null +++ b/packages/preset/agent-presets/presets/aeven/procedures/x-post.md @@ -0,0 +1,76 @@ +--- +name: x-post +description: Draft, publish, or schedule a post or thread on X (Twitter) in the in-app browser, with links, images, video, GIFs, polls, or reply settings. +summary: >- + Open the composer from x.com/home with the left Post link (a[href="/compose/post"]); the editor is the dialog's textarea "What's happening?" (older UI: [data-testid=tweetTextarea_0]). Never click Post, Post all, or the scheduler's Schedule, and never press Cmd/Ctrl+Enter, unless the user asked to publish this exact post. 280 weighted characters per post for regular accounts (a URL counts 23): split longer text into a thread with "Add another post", one part at a time; one part over 280 or one empty part disables Post all. A pasted URL gets a card at once; media replaces it, and removing the media brings it back even after "Remove card preview", so remove the card last. Up to 20 photos/videos/GIFs mixed. Escape closes the whole composer into "Save post?" (Discard/Save). Read memory_get for threads, polls, scheduling, and every trap. +--- + +# X post + +Drive x.com in the in-app browser with the `preview_*` tools (load the `in-app-browser` skill first). The user must already be signed in; a sign-in page is a `preview_handoff`. + +## Ground rules + +- Click `Post`, `Post all`, or `Schedule` in the scheduler, or press Cmd/Ctrl+Enter, only when the user asked to publish this exact post or thread. Drafting ends with the draft open in the composer and a summary to the user. +- Enter in the editor adds a line; Cmd/Ctrl+Enter publishes. +- X serves two composers. The new one is a `Create post` dialog with a plain `textarea[aria-label="What's happening?"]` and no `data-testid` attributes; the older one uses Draft.js with `[data-testid=tweetTextarea_0]`, `[data-testid=tweetButton]`, and other test ids. Match controls by `aria-label` and role so both work. +- The same `aria-label` can sit on several buttons, hidden copies included (`More` appears seven times). Act on the visible one; a click on a zero-size match lands on the modal backdrop and closes the composer. +- Read the composer back after every step; a click that reported `ok` has not necessarily changed it. + +## Open the composer + +1. On `https://x.com/home`, click the visible `a[href="/compose/post"]` (the left navigation's `Post`, which opens a composer and publishes nothing). Loading `/compose/post` directly does not always open the dialog. +2. In a narrow pane the older UI opens a full page instead, with `Back`, `Drafts`, and `Post` in the header. +3. Click the editor, then `preview_type` the text of one post. + +## Length and threads + +- Regular accounts get 280 weighted characters per post. A URL counts 23 whatever its length; emoji and CJK characters count 2. +- Near the limit a counter shows the characters left. Past it the overflow turns red, the counter shows `-N` with "You have exceeded the character limit by N", `Post` is disabled, and "Upgrade to Plus to write longer posts" appears. X never splits text itself. +- For longer text, split it at sentence or paragraph ends into parts of at most 280, then build a thread: + 1. Type part 1. + 2. Click `Add another post`; a new empty part appears after the active one and takes focus. Type the next part. Repeat. + 3. With two or more parts the publish button reads `Post all` and publishes the whole thread at once. +- Only the active part shows its controls (`Remove post`, `Add media`, `Add GIF`, `Add poll`, `Add another post`). A part becomes active only through a real click on its editor; focusing it from a script does not move the controls. Media and polls go into the active part, so click the part first. +- `Add another post` inserts after the active part, not at the end; click the last part before adding one there. +- `Who can reply` exists only on the first part. The first part has no `Remove post`. +- One part over 280 or one empty part disables `Post all` for the whole thread. +- `Remove post` deletes that part at once, without confirmation. Number parts ("1/3") only once the thread is final; X does not renumber them. + +## Links and the preview card + +- A pasted URL shows a card at once (`From `); typed text shows it after the URL is complete. The URL stays in the text either way. +- `Remove card preview` removes the card and keeps the URL; the post then goes out without a card. +- Adding any media replaces the card automatically, so own images need no card removal first. +- Removing the media brings the card back, even one removed earlier. When the post should have neither card nor media, remove the card after the last media change and check again. +- A poll also hides the card. + +## Images, video, and GIFs + +1. `Add media` (older UI: `Add photos or video`) opens a file chooser; use `preview_upload` with the absolute paths and that button as the selector. The input accepts JPEG, PNG, WebP, GIF, MP4, and MOV, several at once. +2. Up to 20 items per post since November 2026, photos, videos, and GIFs mixed. Four show as a 2×2 grid, five or more as a carousel. +3. Each item has `Edit`, `Remove `, and, below the media, `Tag people` and `Add description`; videos add `Upload caption file (.srt)`. +4. `Edit` opens the media editor with `Crop`, `ALT` (description, 1,000 characters), and `Content warning`, plus `Previous`/`Next` between items; `Save` returns to the composer. The first `Add description` shows an explainer with `Sure` / `No, thanks`. After saving, the strip reads "1 image description". +5. A video shows ": Ready" before X accepts it, and `Post` stays disabled while it processes. Wait until `Post` is enabled again. +6. `Add GIF` opens a GIF search (`/i/foundmedia/search`) with trending categories; picking one adds it as a media item. + +## Poll + +- `Add poll`: choices `Choice1`–`Choice4` (25 characters each, two shown, `Add a choice` up to four), each with its own `Add media`, and a duration of days (0–7), hours (0–23), and minutes (0–59), default 1 day. `Remove poll` takes it away. +- While a poll is open, `Add media`, `Add GIF`, and `Schedule post` are disabled, and `Post` stays disabled until the choices are filled. A poll needs a post without media. + +## Reply settings, disclosures, location + +- `Who can reply: Everyone` opens a menu: Everyone, Accounts you follow, Accounts you follow & who they follow, Only accounts you mention, Verified accounts. +- `More` holds `Content Disclosures` (checkboxes `Paid Partnership`, `Made with AI`) and `Add location`. The older UI shows `Content disclosure` and `Tag location` directly. +- `Add emoji` and `Generate image` (Grok) sit in the toolbar too. + +## Schedule + +`Schedule post` opens a calendar: past days and past times are disabled, times come in 15-minute slots in the user's timezone, and `View Scheduled Posts` lists queued posts. Its `Schedule` button queues the post to publish later and needs the same explicit request as `Post`. Scheduling is disabled while a poll is open. + +## Close, drafts + +- `Close` (older UI: `Back`), Escape, or a click outside the dialog asks "Save post?" with `Discard` and `Save`. Save only when the user asked to keep the draft. In the older UI `Save` is `confirmationSheetConfirm` and `Discard` is `confirmationSheetCancel`. +- Close menus by clicking the editor, not with Escape: Escape closes the whole composer. +- `Drafts` with text in the editor asks "Save post?" first; it then lists `Unsent posts` and `Scheduled`.