Skip to content

feat(composer): accept file references dragged from File Manager - #2580

Merged
Tioit-Wang merged 94 commits into
vastsa:mainfrom
Linuxdazhao:codex/file-manager-composer-drop-2579
Nov 29, 2026
Merged

Tioit-Wang merged 94 commits into
vastsa:mainfrom
Linuxdazhao:codex/file-manager-composer-drop-2579

Conversation

@Linuxdazhao

@Linuxdazhao Linuxdazhao commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary / 概要

  • 当前本地项目的 File Manager 普通文件可以拖进 Composer,加入一张可移除的整文件卡片。已有草稿保留,松手不发送,也不复制文件内容。
  • 插件 preload 只在可信的原生拖拽开始时取得短时、一次性令牌。宿主仅接受主窗口顶层 Composer 的 drop,重新校验可见视图、插件注册版本、当前会话和项目路径,再复用现有文件引用。
  • 跨仓库插件实现先提交在 File Manager #15。本 PR 可与正常安装的该插件候选联测。内置插件来源可在插件 PR 合并后更新。

Requirement link / 需求关联

Earlier work: #745 and Blue-Berrys' #786.

Validation / 验证

  • macOS arm64,Electron 43.6.0。宿主候选 ca67e9ef6e74,基线 649c3456af65,插件候选 6a7f95723373。通过正常 Host API 安装候选包,使用真实 File Manager、Composer 和原生鼠标。确认一份文件只加入一张卡片、可移除、保留草稿、不发送、原文件内容不变。拖到外部或按 Escape 不加入卡片。
  • 同一运行还通过已有行引用场景,包括未保存状态、发送时按行读取、Desktop/Host 重启恢复。模型 provider 使用本机回环夹具。
  • 20 项定向测试、桌面类型检查和生产构建、Host 构建、lint、文档检查及最新基线检查通过。
  • Windows/Linux 原生跨视图拖拽尚未验证。

原生拖拽截图

拖入前

拖入前

拖入后

拖入后

文件卡片近照

文件卡片近照

Linuxdazhao and others added 5 commits November 25, 2026 10:45
The durable abort can recover a partial reply while the renderer still
believes the session is running. Publish the classified failure after
recovery and before releasing the turn, so the transcript and queue
observe a single outcome.

Fixes vastsa#2570
The host skips active-branch saves until a revision exists. Seed the
first revision through the normal RPC so the smoke case can verify
growing live references and restoring both branches.
A queued prompt writes to Host directly and can pass a crash card
that is still in the outbox. Wait for the Host append, spool failures
under the original turn, and recheck live ownership before publishing.
Native Pi turns run inside the sidecar and never enter the main
process activeTurns map, so the session list reported no running
native sessions. After a renderer reload while a native turn was still
in flight (a stalled provider or a long retry), the composer showed
"Native Pi session is read-only: busy." with no Stop button, leaving
the session stuck until the app restarted.

The session list now also reports native sessions whose summary says
the turn can be stopped, so the reloaded renderer restores the running
state and offers Stop.

fixes vastsa#2575
Allow a compatible File Manager view to hand its active local file to
the Composer as a removable reference. Admit a single-use drag token
only for the owning view and session, reusing disk-file metadata and
normal tool permissions.

Refs vastsa#2579; pairs with Tioit-Wang/pi-desktop-plugin-file-manager#15.
The renderer integration tests alias the shared package to its source
entry. Use that entry for the drag marker so esbuild can resolve it.
Keep the plugin preload on its independently bundled narrow import.
Check durable session metadata before registering a file reference so
a remote session or isolated checkout cannot receive a project-tree
file. Tighten frame and gesture lifetime checks, show the blocked drop
state, and cover files from secondary project folders.
@Linuxdazhao

Copy link
Copy Markdown
Contributor Author

审阅跟进已提交。renderer 从 shared 主入口导入拖拽常量,沙箱 preload 继续使用独立子路径。原先失败的 remote-mvp-renderer.test.mjs 已在本地从红转绿,连同 native drop、文件行、顶层 frame、远端/隔离会话和多文件夹项目等定向测试共 25 项通过。

松手时从 Host 的 session.get 校验实际项目、remoteWorkspace 和 worktree。隔离会话的文件执行根由 worktree.location 解析。这版保留文件树拖拽选择的实际路径,因此隔离会话拒绝该操作,避免引用主 checkout 的同名文件。常见文件消失/不可访问情况直接放弃,禁用态无可接收光标,并收紧顶层 frame 和拖拽事件清理。

macOS arm64 / Electron 43.6.0,以宿主 f2cc335435f3 和 File Manager #15 的 cf2d49e 重跑安装包联测通过。真实拖放、取消、落在输入框外和现有行引用旅程均通过。Windows/Linux 原生拖拽仍待验证。

The target can close or change while Main saves the reference. Remove
the newly written record when the final drop validation rejects it so
the discarded drop leaves no unused file metadata behind.

fixes vastsa#2579
Keep the proposal pending while the user edits their draft. Sending a revision rejects the displayed checkpoint before starting a new planning turn in the same session, preserving the explicit approval boundary.

Closes vastsa#2576
The reference store checks the source again before writing. Treat a
source or project that disappears at that point like one that was
unavailable during the initial check. Storage errors still surface.

fixes vastsa#2579
Match the composer and submission guards to the live Plan checkpoint. Keep Stop available for an empty running turn, retain draft references on plain-text paste, and give the revision action a compact accessible control at narrow widths.

Exercise localized toolbar geometry and pending-state regressions.

Refs vastsa#2576
Keep the toolbar button padding independent of the shared button rule and verify the rendered glyph has its full aspect ratio.

Refs vastsa#2576
Confirm that reopening the File Manager after a rejected drop does not
make the consumed drag token valid again.
Keep native caption hit regions active after Zoom so users can move the window within or across displays. Let AppKit apply the titlebar double-click preference and remove the renderer-only drag markers.
Linuxdazhao and others added 9 commits November 25, 2026 16:34
Users want to keep working with the desktop's existing projects and
sessions from a phone or another browser on the same Wi-Fi. This adds
an off-by-default LAN listener in Electron Main with one-time-code
pairing, per-device project/temporary scopes and chat/organize grants,
and a phone-first page for browsing, creating, chatting and organizing.

The edge only calls existing Desktop handlers and Agent Host turn
admission under a non-owner principal, so tool approvals stay on the
desktop. Organization edits reuse the sidebar backup as the single
durable record and stay pending until the renderer acknowledges them,
so a stale sidebar snapshot cannot undo them. Transport is plain HTTP
by product decision; Host/Origin checks and CSRF tokens guard requests.
… projects apart

replaceChildren() stringifies null, so every list and chat view rendered a
stray "null" line from optional slots. Filter empty slots before rendering,
and assert no placeholder text in the phone user-path test.

Legacy folder-named projects frequently share a label (several "apps"),
which made the phone list and the Desktop pairing checklist ambiguous.
Repeated labels now carry their parent folder name, never the full path.
Move pairing and grant choices into focused dialogs so connection
status and device access are easier to scan. Keep device identity
when grants change, but reauthorize requests and live streams under
the new scope.
Make device confirmation the only project access decision so pairing
works without a project checklist and new local projects stay visible.
Keep Temporary, Chat and Organize as separate grants and refuse
stale per-project approvals instead of widening them.
A renderer that crashes deterministically at startup (GPU driver or
cache corruption, issue vastsa#2595) turned the automatic recovery into an
infinite loop: did-finish-load never fires, so the hidden main window
is never shown, and recoverRendererAfterGone reloads every 2s until
the user force-quits. A plain reinstall does not help because the
corrupt state lives in userData.

Recovery now counts consecutive crashes with no successful load in
between and stops reloading after five: the first trip relaunches the
app once with --disable-gpu (the classic mitigation for corrupt GPU
state), guarded by a userData marker so a loop that survives the
fallback surfaces a localized dialog instead of relaunching forever.
Boot reads the same marker to disable hardware acceleration for
manual launches too, and a run that stays loaded for ten minutes
clears it again. Successful loads reset the streak, so scattered
crashes over a long session never trip the breaker.

The dialog offers opening the log folder (where the rendererProcessGone
diagnostics already land) or quitting; strings are added to all nine
locales.
Treat the locally generated one-time code as the WebUI access decision.
Remove pending approvals and per-device grants while keeping device
revocation and the existing local workspace and Agent boundaries.
Normalize pasted codes and reject duplicate submits without consuming
extra pairing attempts. Distinguish an older service or a blocked
session cookie from a bad code. Provide a local QR and copy action
without sending pairing data to an external service.
@Tioit-Wang

Tioit-Wang commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

维护者接受 #2579 的功能方向:支持从 File Manager 拖入整文件引用。下面是对当前实现的修改意见,不是对这项功能的否定。

感谢两端的实现和 macOS 联测。审查 991fa9686 时,在这个 PR 自带的 file-manager-composer-drag.test.mjs 夹具上复现了一处与 #2579 不符的行为:切走会话再切回,之前的拖拽没有作废。

在 A 发起拖拽,drop() 等待 session.get 时把同一项目的选择从 A 切到 B,再切回 A。预期返回 null,实际返回了 project image.png 的文件引用。两个对照用例(普通投放、只切到 B)都通过。isCurrent() 只比对当前会话和项目,无法识别中途发生过的切换。应把一次拖拽绑定到开始时的会话选择版本;版本变更即作废,即使随后返回 A 也不能登记引用。

请补上 A → B → A 的回归用例;此前的 6 项绿色 CI 不覆盖这个场景。请同时同步最新 main,并在更新后的宿主和插件候选上重跑跨视图拖拽验证,附上两个提交 SHA,方便复审。

@Tioit-Wang Tioit-Wang closed this Nov 26, 2026
vastsa and others added 21 commits November 28, 2026 11:07
When the user pressed Stop and the sidecar then died before agent_end,
finishTurn still attached the classified crash error: the transcript got
an AGENT_SIDECAR_* card, the turn result looked failed, and Agent Host
recorded the crash code on what was a deliberate stop. The abort lock
taken before the cancel request already records that intent, so a
locked turn now settles as a plain abort.

The crash card also carries its turnId in the live projection, matching
the persisted row, so transcript grouping is the same before and after
reload.

Refs vastsa#2570
Place dir on ul/ol from the list's majority script so
padding-inline-start sits on the same side as RTL items.
The bidi probe now asserts list padding geometry and that an
Arabic paragraph stays visually right-aligned when an ancestor
uses physical text-align:left.

Fixes vastsa#2635
Describe the MessageBubble assistant contract as physical row placement
plus text-align:start under a majority-script dir. Add E2E-060d for
that alignment and list-gutter behavior. This PR is the verified
inherited-alignment fix; leave vastsa#2635 open until the reported Windows
chat path is confirmed.

Refs vastsa#2635
…nment

fix(chat): right-align Arabic assistant replies with logical text-align
…load

fix(session): keep running native Pi turns stoppable after reload
Calls in vastsa#2552 stored conversational junk in `path` ("Wizard.tsx here?",
"Wizard.tsx:{") next to a clean `file_path`. D273 let the canonical name
win when both arrived, so every retry ran the junk path and host-core
never saw the clean value. Picking either spelling is a guess, so a call
whose spellings disagree now fails with INVALID_ARGUMENT before the write
lock and host call, quoting each value so the next call can send one.
Identical values still fold to one argument.

The alias map and its validation move from runtime.ts into
tool-param-aliases.ts, shrinking the hotspot. Spec 03 and D690 record
the amendment to D273.

fixes vastsa#2552
fix(plan): allow revision requests from the pending composer
…tlebar-drag

fix(desktop): restore titlebar dragging for zoomed macOS windows
…sh-2570

fix(desktop): settle live turns after sidecar crashes
…keover

fix(desktop): break renderer crash loops with a guarded GPU-fallback relaunch
fix(agent-runtime): reject differing spellings of one tool argument
Remove obsolete UI and helper implementations with no production callers
so they cannot drift from the active paths. Preserve public package
exports, persisted compatibility fields, and runtime entry points.
)

Remove obsolete internal implementations and unused imports so they cannot drift from the active application paths.

Preserve public package exports, persisted compatibility fields, and runtime entry points.
@Tioit-Wang

Copy link
Copy Markdown
Collaborator

宿主端复查(554cfc8)

已通读 554cfc8 全部 24 个文件的 diff,并与插件候选 5ccfa2b 的契约逐项对照。

A → B → A 竞态已修好:createFileManagerComposerDrag 在 begin() 时记下 getSelectionRevision(),drop() 的 isCurrent() 先比版本再比 sessionId/projectPath,setActiveSession 只在会话或项目真的变化时自增,重复上报同一选择不会误作废。file-manager-composer-drag.test.mjs 的 A→B→A 回归稳定覆盖了这条。丢弃路径也很干净:referenceComposerFiles 与最终 isCurrent() 之间失败时 discardComposerFileReference 会删掉已写记录,测试断言了 readdir 里不留残骸。

以下 1 条建议合并前复跑确认,其余为后续可接受项。


1. preload 的 dragstart 捕获存在时序不确定性,建议重复复跑原生用例

apps/desktop/electron/preload/plugin-panel.ts:

if (composerFileLines) {
  window.addEventListener("dragstart", (event) => {
    composerDragStart = event.isTrusted ? event : undefined;
    // Clear after synchronous handlers even when the page never uses the bridge.
    queueMicrotask(() => {
      if (composerDragStart === event && event.eventPhase === Event.NONE) composerDragStart = undefined;
    });
  }, true);
  window.addEventListener("dragend", () => { composerDragStart = undefined; }, true);
}

微任务在 dispatchEvent 返回后运行,此时 eventPhase 已经是 Event.NONE。只要 view 的 startComposerFileDrag 调用链有一跳异步(React 合成事件、await、后续微任务),引用就会被提前清掉,函数返回 false,拖拽变成“无引用”。你在 comment 里也写了“首轮未收到原生拖拽结束事件,随后两次通过(最后一次未加诊断日志)”,和这个时序吻合。

请求:用同一个 .piplug + 同一个宿主包,连续跑 PI_FILE_MANAGER_TEST_NATIVE_DRAG=1 scripts/e2e-file-manager-lines.mjs 至少 5 次并贴结果。如果出现任意一次 dragstart 计数不对,建议改成不依赖 eventPhase 的清理方式(例如只靠 dragend/drop 清理,或在 begin 被调用后立即置空 composerDragStart)。

2. discardComposerFileReference 缺少 realpath 再删的保护

const root = await referenceRoot(dataDir);
await rm(join(root, `${localReference}.json`), { force: true });

referenceRoot 已经做了“目录被重定向”检查,但删除时没有再确认。referenceComposerFiles 里写入是 flag: "wx" + mode: 0o600,风险不高,但和同文件里 resolveComposerFileReference 的 realpath(recordPath) !== recordPath 保护不一致。建议补齐,保持同一文件的防御风格统一。

3. 同步 IPC 的入参校验

PLUGIN_PANEL_COMPOSER_FILE_DRAG_CHANNEL 的处理器在 Main 里先做 path.length > 4096 之类的校验后才进 fileManagerComposerTarget,这个顺序没问题。但 payload.path 到 normalizeProjectPath 之间没有先剥掉 . / ..,插件端若传相对路径片段会白跑一次 realpath。不是安全问题(最终有 fileLinePathInProject 双重包含检查),属于热路径上的小浪费。

4. 覆盖建议

  • 多文件夹项目 + 原生拖拽:secondary root 现在只有单测(rememberProjectGroups 模拟)。docs/spec/06-delivery/e2e/conversation.md 里已经写了“Repeat on a local secondary project folder”,但 e2e 脚本里没有对应步骤,请补上或在文档里标注为单测覆盖。
  • stat 与 writeFile 之间源被换成目录:setHostSession 夹具覆盖了 remote/worktree/relocated,但没有“解析后被替换成目录”这一条。resolveDragFile 的 isFile() 检查在写入前,二者之间仍有窗口。

我做了什么 / 没做什么

  • 我通读了两端全部 diff,交叉核对了 composer-file-references.ts 的 referenceComposerFiles/discardComposerFileReference、file-line-reference.ts 的 fileManagerComposerTarget、以及插件侧 Tree.tsx 的 effectAllowed 三分支实现。
  • 我没有运行 20/25 项定向测试、类型检查、Host 构建或原生拖拽 e2e——本地没有这两个候选的工作区,也不具备 macOS arm64 环境。第 1 条正是请你在 macOS 上做的重复复跑。
  • 与插件 5ccfa2b 是目前唯一互相验证过的一对候选,任何一端再改都要成对重跑并更新两个 SHA。

结论:安全边界(可见 sender、registry 版本、session.get 的 remote/worktree、词法+realpath 双重包含、一次性 token + TTL、主框架限定)我逐项核过,没找到绕过路径;合入前的唯一实质待办是第 1 条的原生拖拽稳定性复跑。

vastsa and others added 2 commits November 28, 2026 22:34
A paired phone's turn computed the remote `ask` ceiling but never applied
it: host-core authorized tools from the stored session mode, and an
`inherit` session with an `auto` default did not even forward the value.
Phone turns could therefore run tools without Desktop approval. The
ceiling is now recorded on the durable turn and queue entry (schema v35)
and host-core applies the stricter of it and the current session mode to
every tool decision of that turn, including delegates, child sessions,
session messages and background continuations. A Host that cannot record
it starts no turn.

The phone also offered Send and Queue in sessions of an archived project,
because send admission checked only the session's own flag. Those
conversations are now read-only with a project restore action, admission
rechecks the current archive state, and a web archive refuses while a
send is still being admitted.

Records ADR turn-permission-ceiling and updates the LAN WebUI, storage,
security and E2E specs.
fix(lan-webui): enforce the ask ceiling and archived-project read-only
@Tioit-Wang

Copy link
Copy Markdown
Collaborator

更正:我上一条评论有几处结论是错的

上一条评论发出后,我对它做了交叉验证(两个独立会话 + 我自己复跑探针)。结论:第 1 条与第 5 条成立,第 2、3、4、6 条不成立或表述错误,另外漏了一个真实缺陷。下面逐条更正,每条附证据。

我说错了、现在撤回的

第 2 条(onComposerFileDrag 两处判定冲突)——撤回。
App.tsx 决定是否提供回调(能力门控),Tree.tsx 决定哪些条目能调(条目门控)。这是两层门控的组合,不是两套冲突的真值表。我的表述是错的。

第 3 条(readdir().sort() 在 Windows 不可靠)——只对宿主成立,我对插件侧的断言是错的。
我原话说“插件侧新增用例也用了”这个模式。实际在 5ccfa2b 的 tests/electron/verify-explorer.cjs 里 grep,只有 3 处 assert.deepEqual,没有任何 readdir/sort。该断言只存在于 apps/desktop/test/file-manager-composer-drag.test.mjs,且那里的目录名全是小写,JS .sort() 的码元序是确定的。这条撤回,不构成任何一端的待办。

第 4 条(微任务早于桥接调用清空 token,startComposerFileDrag 返回 false)——过度断言,撤回。
我自己在 Node 与 Edge 上用脚本 dispatchEvent 复现出“微任务执行时 eventPhase === 0”,一度以为能证实。但那测的是脚本派发;真实受信任拖动的记录是 capture phase=1 → microtask phase=1 → target sync phase=2,微任务执行时事件仍在捕获阶段,Event.NONE 不成立,不会误清。而插件侧 Tree.tsx:280 的 onComposerFileDrag?.(entry) 就在 onDragStart 里同步调用。
结论:正常路径上不会返回 false。 我把“规范上存在时序不确定性”外推成了“会导致拖拽失效”,是没有原生环境就下结论。你自述的首轮 flaky 可能另有原因,但不该被我按这条口径写进待办。

第 6 条(宿主对老插件隐藏桥接方法)——部分撤回。
注入条件是“特定 view key + 权限”,不是插件版本检查。老插件只是不会调用这个方法,而不是被隐藏。功能降级本身成立,机制描述错了。

仍然成立的

第 1 条(生成包无法证明由合并后源码重建)——成立,且我补了根因。
scripts/prepare-package.mjs:8 的 entries 只是把 views 等目录原样复制进运行包,没有任何构建步骤。所以跑它无法证明 bundle 来自新源码,必须靠 pnpm build + git status 为空。

第 5 条(discardComposerFileReference 缺 realpath 保护)——成立。
composer-file-references.ts:45-49 只校验 UUID 后 rm;同文件 :101 的 resolve 路径有 realpath(recordPath) !== recordPath 保护,删除路径没有。

我漏掉的(这条才是真缺陷)

pending 是单槽位,连续拖两个文件会让第一个的 drop 失效。
file-manager-composer-drag.ts:58 每次 begin() 都直接覆盖 pending;:68-70 里旧 token 因 input.token !== drag.token 返回 null,且不会清掉新的 pending。
独立探针实测:firstDrop = null; secondDrop = accepted。这不是越权,是真实用户可见的功能缺陷:用户快速从树里连拖两个文件,第一个松手不会加卡片,且没有任何提示。建议改为按 token 存的 Map 或队列,而不是单槽位。

顺带核实、不构成缺陷的两条

  • fileLinePathInProject 的第三参数 canonicalPath 信任调用方:helper 层面确实可被伪造值误收,但生产链路 file-manager-composer-drag.ts:92 传的是 resolveDragFile() 真实 realpath 的结果,调用方无法伪造。我用 junction 指向项目外验证:真实 realpath 传入时返回 false(挡住),伪造值才返回 true。是契约脆弱,不是可利用绕过,建议加注释说明“第三参必须是调用方自解析的可信值”。
  • session.get 与 workspace/path 一致性:主项目已登记的所有 roots 都参与包含校验,次根可通过、组外不通过,被挡住。

我修正后的合并判词

方法与边界

  • 第 3、4 条由我亲自复核(grep 真实提交、Node + Edge 探针);第 1、5 条我读了候选代码确认行号;pending 单槽位由我读 :58-70 确认行为,探针结果由交叉验证会话给出。
  • 交叉验证会话的克隆目录在我这边不可读,所以凡是我标注“成立”的条目,都以我自己读到的 file:line 或跑出的输出为准,没有直接采信它的结论。
  • 我仍未在 macOS 上跑原生跨视图拖拽 e2e(无该环境),Windows/Linux 原生拖拽同样未验证——这一点上一条评论说得对,这里保持。

对上一版评论里那几条错判,我道歉;这条更正以证据为准,请以本评论替换相应条目。

@Linuxdazhao

Copy link
Copy Markdown
Contributor Author

按你更正后的两点更新了宿主。两次拖动各自保留自己的令牌,后一次不会覆盖前一次;清理还没交给输入框的文件引用前,也会像读取时一样核对记录的实际路径。

086ebb5e0 的 CI 6 项全过,本地相关测试也是 23/23。用 File Manager #15 重建的安装包 在 macOS 联测:拖入输入框会加卡片,按 Esc 或拖到外面不会加,之后还能正常再拖。首轮等待第一张卡片时超时,原因未确认;同一提交随后连续两轮通过。Windows 和 Linux 的原生跨视图拖拽没测。

@Tioit-Wang
Tioit-Wang merged commit 16b863e into vastsa:main Nov 29, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants