magpie icon indicating copy to clipboard operation
magpie copied to clipboard

[Bug] Cindy 共享指令/内置运行时写入 ~/.pi 与 ~/.claude 后,未装独立 CLI 仍被扫出 Pi / Claude Code

Open TomXPRIME opened this issue 1 week ago • 2 comments

现象

未安装独立 Pi / Claude Code CLI 的机器上,使用 Cindy + Magpie 0.1.4862(#7854)后,Agents 列表里会多出两个并非独立安装的条目:

  1. Pi 未找到 CLI(magpie ls:Pi CLI not found ~\.pi\agent\settings.json)
    • 本机原本无 ~/.pi/,给 Cindy 开启共享指令后,Magpie 写入 ~/.pi/agent/AGENTS.md,随后探测到该目录就把独立 Pi 扫进了列表(library.json 也多出 applied.pi.instructions = true)。
  2. Claude Code(未接入)
    • 本机无独立 claude CLI;Cindy 内置的 AppData\Roaming\Cindy\claude-code\2.1.321\claude.exe 启动时直接生成了 ~/.claude.json 与 ~/.claude/,导致被当成独立 Claude Code 扫出。

建议

探测独立 Pi 时,若既无 pi CLI 又无 settings.json / models.json 等自身配置(目录里只有 Magpie 写入的 AGENTS.md),不将其识别为已安装独立 Pi;Claude Code 若同理仅存在配置目录而无 CLI,可考虑区分或标注未找到 CLI。

  • 环境:Magpie 0.1.4862 / Cindy 0.1.146 / Windows
  • 关联:#7854

TomXPRIME avatar Nov 26 '26 13:11 TomXPRIME

take

ggbdpq avatar Nov 26 '26 16:11 ggbdpq

@yetone — an update on this one (@TomXPRIME's report): it is already fixed on upstream/main by your own commit 411b5be9e ("agent: Pi and Claude Code aren't listed for the files Cindy's own copies read", which cites this issue), plus eab18052e for the Codex side. We had posted a take and prepared a Pi-only candidate fix (dirIgnore: treat the Pi instruction files as no-sign files and reject the folder once they are taken out), but your landed readHere/otherCopy design covers the same ground and more (Claude Code), so we are not proposing a competing patch. Below is our independent verification of your fix on the current tip, plus one residual edge case we hit while testing ours.

Root cause (as fixed in 411b5be9e): the Library writes ~/.pi/agent/AGENTS.md for Cindy with no standalone Pi here, and any ~/.pi/agent holding anything but skills counted as Pi; Cindy's bundled Claude Code makes ~/.claude and ~/.claude.json on its first run, which counted as Claude Code. Pi's instruction files are now readHere no-sign files, and Cindy's-copy-only folders are otherCopy.

Independent verification on upstream/main 639b3c96b (Windows 11, Go 1.27.0, temp HOME, pinned Go caches):

Check Result
TestPiFolderOfInstructionsAloneIsNotPi (yours, 411b5be9e) pass
TestClaudeFolderOfCindysCopyIsNotClaudeCode (yours, 411b5be9e) pass
TestCindyInstructionsListNoPi (yours) pass
TestCindyClaudeKeepsClaudeLibraryRow (yours) pass
TestCodexFolderOfCindysCopyIsNotCodex (yours, eab18052e) pass
Pi from ~/.pi/agent holding only AGENTS.md / AGENTS.MD / CLAUDE.md / CLAUDE.MD / AGENTS.override.md (our independent subtests) not detected (pass)
Pi from a custom PI_CODING_AGENT_DIR holding only AGENTS.md not detected (pass)
Pi still detected with settings.json / models.json / auth.json / sessions/ beside AGENTS.md pass
Pi still detected with the pi command on PATH pass
go vet + GOOS=linux go vet -tags nogui + GOOS=windows go vet (internal/agent, internal/library) clean
go build + GOOS=linux go build -tags nogui + GOOS=windows go build (./internal/...) clean
targeted -race not run (no C toolchain on Windows host)

Red without the fix: on 17c4becad (v0.1.4886, before 411b5be9e) our reproduction tests are red exactly as reported — an empty ~/.pi/agent, or one holding only AGENTS.md, counts standalone Pi as installed ("Pi CLI not found"), likewise via PI_CODING_AGENT_DIR (TestPiInstructionsOnlyDirNotDetected, TestCindyInstructionsDoesNotDetectPi, internal/agent + internal/library). The same run's full-package reds (go test -tags nogui ./internal/agent ./internal/library -count=1) were compared against a pristine 17c4becad checkout on the same host: zero FAILs appear with the candidate change that does not already fail on the pristine base — no regressions; the reds are the filed Windows environment ones, plus TestCindyInstructions, which removes bin/pi but not the sandbox's bin/pi.exe, as you already noted in 411b5be9e's message.

One residual edge (for your judgment, not a patch proposal): after switching Cindy's shared instructions off, the Library removes the AGENTS.md it wrote, which can leave ~/.pi/agent empty. On 639b3c96b an empty folder still counts as the agent's (agentDir, len(es) == 0 returns true, internal/agent/agent.go:556), so standalone Pi is listed again in that state. Verified there: our empty_dir subtest and the last phase of our end-to-end test are red on 639b3c96b while every populated-folder subtest passes. Pi's own runs leave settings.json/auth.json/models.json/sessions behind, so this only arises from the disable flow; we leave the design call to you.

Source: #7872 by @TomXPRIME; Cindy's three runtimes at internal/agent/cindy.go; fix commits 411b5be9e (Pi + Claude Code) and eab18052e (Codex), both on upstream/main.

Not verified: no real Cindy install was tried — the fixtures follow Cindy 0.1.146's source, as in 411b5be9e; everything above ran on a Windows 11 host with a sandboxed HOME and pinned caches, not the reporter's machine; the full go test ./... and the GUI suite were not run; -race not run (no C toolchain on Windows host).

Attribution: AI-written; I've read the whole diff of 411b5be9e and the tests pass. Please keep the author (ggbdpq) or add Co-authored-by: ggbdpq <[email protected]> on any follow-up.

Generated-by: GLM-5.3-Flash (ZCode)

ggbdpq avatar Nov 26 '26 23:11 ggbdpq