TokenPLS:Clash CLI 写配置须先解决跨进程锁和权限边界
TokenPLS 支持脚本与 AI agent 通过 clash-cli 操作 Clash,但在合并写入功能前,App 与隧道扩展须共用跨进程锁,且 App 要感知外部改动,避免互相覆盖。团队倾向先允许 App Group socket 的本地写入;持有控制器 secret 的局域网客户端能永久修改规则或 DNS,须另行安全审查。该分支还需适配现有配置存储。
作者原文@TokenPLSThank you for this, and sorry for the slow reply. Letting scripts and AI agents drive Clash through
clash-cliis a direction we want to support, so we're treating this as more than a one-off change.Before it can go in, two things need solving:
- Writes from two processes.
profiles.jsonis written by the App, and with this change also by the tunnel extension, which runs in a separate process. The App's write lock only covers its own process, so a CLI write and an App write at the same moment can overwrite each other. The App also doesn't notice the file changed, so saving something in the UI afterwards can undo the CLI's edit. Both sides need to share one cross-process lock, and the App needs to pick up the change.- Who can write. The new write endpoints are also reachable from a LAN controller client. Anyone on the network with the secret could then permanently change a profile's rules, or point a domain's DNS at any server. We'd start with local-only writes (the App Group socket) and look at the LAN case separately, after a security review.
The App's config store has also changed quite a bit since this branch was cut, so it will need bringing up to date. We'd like to bring the change into our tree and work through these two points; we'll follow up here, and on ProjectClash/Clash#13, with what we change.