makecindy / makecindy/cindy

侧栏项目/会话列表无法感知外部数据库写入,且打包版没有任何手动刷新入口(只能重启)

Open
#990 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
TypeScript
Stars
2.7k
Forks
395
Avg merge
21h 48m
Merged PRs (30d)
776

Description

**提交人**: Albert Yang
**客户端版本**: 0.1.21

---

## 现象

在一台机器上通过 SSH 直接往本地库写入 `recent_workdirs` + `project_aliases`(用于给常驻机批量登记项目目录),正在运行的 Cindy 左侧项目栏不会出现新项目,必须重启 App 才能看到。重启会打断正在跑的 agent 会话,代价很高。

## 排查(基于 0.1.21 macOS 打包产物)

渲染层其实已经有完整的热刷新机制,三处订阅都在:

```js
// 会话 store
sessionsPush.onCreated(() => oo.forceRefreshAll())
// 最近工作目录 store
sessionsPush.onCreated(() => Id.forceRefresh())
recentWorkdirs.onChanged(() => Id.forceRefresh())
// 别名
projectAliases.onChanged(() => reload())
```

问题出在主进程侧:

1. `local-db:recent-workdirs:changed` 在整个主进程 bundle 里**只有一个发送点**,位于 `ipcMain.handle("local-db:recent-workdirs:remove")` 里。也就是说只有「用户删除最近工作目录」会广播,**新增从不广播**。
2. 侧栏项目列表是从 sessions 派生的,所以 0 会话的项目本来就不渲染——即使 `recent_workdirs` 已经有行。
3. 打包版把手动刷新入口去掉了:

```js
const o = app.isPackaged
? { label: viewMenu, submenu: [toggleSidebar, sep, resetZoom, zoomIn, zoomOut, sep, togglefullscreen] }
: { label: viewMenu, submenu: [toggleSidebar, sep, reload, forceReload, toggleDevTools, ...] }
```

正式版没有 View → Reload / Cmd+R,所以连「渲染层重载」这个逃生口都没有。

综合结果:**任何绕过 App 的库写入在重启前都不可见,且用户没有任何手段强制刷新。**

## 期望

外部/带外写入本地库后,运行中的 App 能在合理时间内自行感知并刷新,或者至少给用户一个不重启主进程的手动刷新方式。

## 建议修法(二选一或都做)

**A. 主进程监听库文件,广播已有事件(约 20 行)**

对 `~/Library/Application Support/Cindy/cindy-*.db`(含 `-wal`)做 `fs.watch` + 防抖,变化时向所有窗口广播现成的三个事件:

```js
win.webContents.send('local-db:recent-workdirs:changed', {})
win.webContents.send('local-db:project-aliases:changed', {})
win.webContents.send('local-db:sessions:created', { sessionId })
```

渲染层订阅已经就位,不需要动 UI 代码。

**B. 打包版保留 View → Reload**

把上面那个 `app.isPackaged` 三元去掉,至少留 `reload`。渲染层重载不影响主进程管理的 agent 子进程,是很轻的逃生口。

## 备注

目前的替代方案是用 `cindy_helper.send_to_session` 的 create 模式 + `working_dir` 建会话——走 App 自己的路径就会触发 `local-db:sessions:created`,列表能立刻刷新。但这要求发起方本身是该机器上的一个 Cindy 会话,跨机远程登记项目时用不上。
---
**版本区域**: CN
**OS**: darwin arm64 (25.5.0)
**界面语言**: zh-CN

Contributor guide

Open the contributing guide

Research direction

Locate the main-process local database IPC handlers, the database-change broadcasts, and the packaged View menu construction; then compare them with the renderer subscriptions listed in the issue. Verify the chosen approach with an external write to recent_workdirs or project_aliases on macOS. Done means the running packaged app shows the change without restarting the main process, either automatically or through a reload entry.

Written by the indexing model from the issue text.

Assessment

Tech stack
electron, typescript
Domain
databases, desktop
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.