Commit Graph
6 Commits
Author SHA1 Message Date
yetone 73a12e8bf6 wsl: a distro's agent folder that is a link is opened where it leads (#4502)
On Windows, adding a skill or switching RTK on for an agent in WSL failed
with `mkdir \\wsl.localhost\<distro>\root\.codex: Cannot create a file
when that file already exists` (linusxiong). In the distro ~/.codex is a
link to /mnt/c/Users/<user>/.codex. Through \\wsl.localhost Windows can't
follow a link the distro has: a mkdir of it says it exists, and nothing
below it can be made, written, read or listed. ggbdpq found and explained
the link (thanks); their patch, which takes that EEXIST as "there", wasn't
used: the writes below the link fail next (its test passed because a
symlink here is followed).

The fix, for every agent folder and every writer through \\wsl.localhost:
- The WSL probe asks `readlink -f` in the distro where each agent folder,
  its skills folder and the folders beside them lead (wslLinkPaths ->
  distro.Links; a $HOME that is itself through a link is left alone), and
  which drive each Windows mount is (win:/mnt/c C: -> distro.Drives).
- distro.open opens a path at or below a link where it leads: on a Windows
  drive, the drive's own path (C:\Users\<user>\.codex); elsewhere in the
  distro, through \\wsl.localhost again. native spells it back through
  the link, so the agent is told its own path.
- A link readlink couldn't resolve is never guessed at: distro.open
  errors, and the agent is unreached (Agent.Unreached: its notice says
  why; every field Set and Sync returns it).
- Writers: the agents' own files (place.join/place.open, every
  filepath.Join(at.home, ...) in internal/agent), the library's WSL
  targets (wslOpen/wslOpened; one "wsl" problem per agent and nothing
  written), RTK (rtkAt, rtkInstall checks agent.WSLOpen before its mkdir),
  the Sessions page's WSL reads (sessions.WSLHome.Open) and the Copilot
  CLI sign-in read (provider.CopilotWSLHomes -> CopilotWSLDirs).
- Not changed: magpie's image MCP server opens arbitrary paths an agent
  in WSL gives it the same way; filed as #4578. Links deeper than the
  probed paths (other than <agent dir>/skills) aren't resolved. A distro
  probed by an older magpie has no Links until probed again (each run).

Run:
- Real Windows box (xiaomi-gpu, distro magpie-desktop, sandbox
  /tmp/x4502/home with .codex -> /mnt/c/Users/yeton/runs/x4502-target/.codex,
  .claude -> /tmp/x4502/data/claude, .pi -> a missing folder), a throwaway
  Windows test running the real probe with that HOME: probe said
  link:.codex /mnt/c/..., link:.claude /tmp/x4502/data/claude, link:.pi,
  win:/mnt/c C:, win:/mnt/d D:. The old way, MkdirAll(\\wsl.localhost\
  magpie-desktop\tmp\x4502\home\.codex\skills\pdf) = "Cannot create a file
  when that file already exists" (the report's error). distro.open wrote
  SKILL.md to C:\Users\yeton\runs\x4502-target\.codex\skills\pdf and to
  \\wsl.localhost\magpie-desktop\tmp\x4502\data\claude\skills\pdf, both
  read back with cat in the distro through the links; .pi said "~/.pi in
  WSL magpie-desktop is a link magpie couldn't follow". Sandbox and target
  removed after.
- New tests with a fake distro whose ~/.codex and ~/.claude are links to
  /mnt/c/... that don't exist here, so, as through \\wsl.localhost,
  nothing below them can be made: TestWSLFolderIsALinkToC,
  TestWSLFolderLinkUnresolved, TestRTKWSLFolderIsALink,
  TestRTKWSLFolderLinkUnresolved (library); TestWSLProbeLinks (runs the
  probe script), TestWSLOpenThroughLinks, TestWSLAgentFolderIsALink
  (config and a Claude session read on C:), TestWSLAgentFolderLinkUnresolved
  (agent).
- Broken by hand: the library tests on the base (with a no-op
  FakeWSLDrives) fail with "mkdir .../home/me/.codex: file exists", the
  report's error; with ggbdpq's patch applied they still fail (the skill
  mkdir, and RTK's hook not written).
- mote: go build ./...; go vet of agent, library, sessions, provider for
  darwin, GOOS=windows (and linux for agent, library); gofmt -l clean;
  go test -timeout 45m ./internal/agent ./internal/library
  ./internal/sessions ./internal/provider: all ok.
- Windows (win-run): the same four packages. The new tests pass (the
  RTK ones skip: the fake distro runs sh). 32 tests are red, all already
  red at the base c63c2136b run on the same box, and filed (#4115, #2808:
  Hermes profiles, Codex keychain, Agy, desktop entries, ...); the Hermes
  ones fail alike on base and branch with -count=3.

- Rebased on origin/main 3ecc02b78 (it changed internal/agent): at this
  head on mote, go build ./..., go vet of the four packages for darwin,
  windows and linux, gofmt -l, go test ./internal/agent ./internal/library:
  ok.

Not tried: the full ./... suite; the GUI (no GUI change; the unreached
notice uses the existing Notice); a real Codex/Claude Code run against
the moved files in the distro.
2026-10-31 21:29:22 +08:00
yetone fbfb76149c provider: TestCopilotSecretToolUsername's fake secret-tool answers a loaded Mac's suite, not "token """ after two 5s waits (#1627)
The cause: the test wrote its fake secret-tool with os.WriteFile, so its
first exec paid macOS's check of a newly written program (0.27s here at
load ~10, several seconds while a go test ./... starts its binaries, as
testenv.Program's own doc records). That ran into copilotSecretWait (5s),
which the happy path was held to: both lookups (account, then username)
were killed and the token read as "".

Not a product bug from this cause: copilotSecretTool runs only on Linux,
against the user's installed secret-tool, which has no such check. The 5s
bound is for a keyring prompt nobody answers (#723) and stays.

The fix, in the test only:
- both fakes are testenv.Programs (a file that has already run once);
- the lookups that answer get copilotSecretWait = 10 minutes, since which
  attribute is asked is no question of time; only the keyring that never
  answers keeps 200ms;
- that case's bound moves from 10s to 30s: bounded it takes 2.4s at most
  unloaded, unbounded 60s, so a loaded runner has room on both sides.

Run at the reviewed head (macOS, load ~9-15):
- Injected delay (sleep 6 at the top of the fake): the old test fails with
  copilot_cli_test.go:94 token "", want the one under username (12.01s);
  the new one passes (27s). Removing only the 10-minute wait by hand, with
  the delay, goes red again.
- Broken by hand in copilot_cli.go: asking "account" only fails the test
  (token ""), and dropping the timeout fails it on the hang case (63s).
- go test -count=20 -cpu 1,4 -run 'TestCopilotSecretToolUsername$|TestCopilotCLI'
  ./internal/provider: ok.
- gofmt -l: clean. go vet -tags nogui for darwin, windows, linux: clean.
- go test -p 4 -timeout 40m ./... under a sandbox HOME: 53 packages ok,
  no FAIL.
2026-10-15 05:54:03 +08:00
yetone 4464ef28d4 provider: magpie on Linux finds the Copilot CLI 1.0's token in the keyring (#723, jia2)
magpie looked the CLI's token up with `secret-tool lookup service
copilot-cli account <host>:<login>`, the attributes keytar wrote before
the CLI 1.0. The CLI 1.0's Rust runtime keeps it through keyring-core's
zbus-secret-service-keyring-store, whose items carry service and
username (cred.rs search_attributes), so a CLI 1.0 signed in with a
keyring (magpie inside WSL or on a Linux desktop) wasn't found.

copilotSecretTool asks for both attributes, account first, and bounds
each lookup at 5s (copilotSecretWait): a keyring waiting on an unlock
prompt nobody answers held the caller for good, including a sign-in's
last step (addCopilotLogin -> copilotOwnUser -> copilotCLILogin).

The service name is still taken to be copilot-cli: the string is in the
1.0.95 runtime, but which call uses it couldn't be read from the binary.

Run: TestCopilotSecretToolUsername (a shell secret-tool answering only
under username, and one that never answers): red with only "account"
asked, green now.
2026-10-11 04:00:27 +08:00
yetone 31468ad0ed provider, agent: magpie on Windows finds the Copilot CLI signed in inside a running WSL distro (#723, jia2)
jia2 runs Copilot CLI 1.0.95 inside WSL, signed in, and magpie (on
Windows) never saw it: copilotCLILogin read only Windows'
%USERPROFILE%\.copilot\config.json.

In a distro with no Secret Service (WSL has none unless one is set up),
the CLI asks to keep its token in plaintext and writes it under
copilotTokens["https://github.com:<login>"] in ~/.copilot/config.json
(read from the @github/copilot 1.0.95 package: its Rust runtime's
storeTokenPlaintext / needs-plaintext-DBus path).

- provider: copilotCLILogin falls back to each running distro's
  ~/.copilot/config.json (plaintext tokens only; a distro's keyring is
  out of reach), through a new CopilotWSLHomes hook, cached 20s since
  it is read over WSL's file share. The read itself moved into
  copilotCLILoginIn(dir, secret).
- agent: the probe looks for $HOME/.copilot, and a distro that has only
  it is kept (wslKept) so its home is known; it makes no agent row.
  CopilotWSLHomes lists only running distros: reading a stopped one
  would start it.

Run: TestCopilotCLIInWSL (provider) and TestWSLCopilotHome (agent),
both red with the fallback / wslKept broken by hand, green with it;
go test ./internal/agent ./internal/sessions green; both tests also
pass on Windows 11. On the Windows box with a real running distro, a
program built from this commit listed \\wsl.localhost\<distro>\home\<user>
and found the copilot account once a CLI-shaped plaintext config.json
was put in the distro's ~/.copilot (removed after), and none before. No
real Copilot CLI sign-in was used.
2026-10-11 04:00:27 +08:00
yetone ffa55fc277 copilot: Auto — Copilot's own pick, the only choice a Student plan has — is listed for every Copilot account and works through magpie, as Copilot's clients do it (#256; Discord, CakeJskSUMM: Copilot Student can only use Auto) — Copilot's /models doesn't list Auto; its clients add it themselves (Copilot CLI 1.0.79: {id:"auto",name:"Auto"}, AUTO_MODEL_ID) and ask POST {api}/models/session with {"auto_mode":{"model_hints":["auto"]}} for a session_token, the selected_model and expires_at, each request then naming that model with the token in Copilot-Session-Token. magpie listed no Auto, failed an account whose list left nothing to pick by hand ("Copilot lists no chat model for this account"), and sent "auto" as a model. Now copilot_auto.go keeps the session per GitHub account, asked again two minutes before it expires; the gateway resolves Auto before choosing the API, so a picked model served only on /responses goes there; a body still naming "auto" (the model test) is rewritten; the endpoints of every model Copilot lists, hidden ones too, are kept for the picked one. A reply to "auto" from another model isn't counted as swapped (Cursor's auto too); the Copilot CLI's picker, which offers auto itself, leaves out the listed one. Tested with fakes in a sandbox HOME: provider/copilot_auto_test.go (a Student-like account whose models are all disabled lists [auto], the session body sent as above, requests carry the picked gpt-5-mini and the token, one session reused, renewed near expiry, an object-shaped selected_model, a refusal reported) and gateway/copilot_auto_test.go (a chat request for copilot/auto goes to /responses as gpt-5-mini with the token, two turns one session; fails without the gateway change); served_test gains the auto cases. go vet ./internal/..., go build -tags nogui (and GOOS=linux, GOOS=windows) and go test -tags nogui ./... pass. Not tried with a real Student account: what its /models returns, whether the plain session request suffices (Auto v2's /models/session/intent is not done), and the body is from VS Code's Copilot Chat, not captured traffic. 2026-09-30 10:17:15 +08:00
yetone e1d211cc4b provider: a Copilot CLI sign-in is found — who from ~/.copilot/config.json (JSONC, COPILOT_HOME honoured), the token from the keychain's copilot-cli item or the file's plaintext copilotTokens; the CLI's token is not traded for a session token (that answers 403) but sent as is under the CLI's own integration, at the API its account is served from 2026-09-24 18:24:03 +08:00