ac4af582301a4e8a29245dbba767eba31334ddf9
8
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
d892dd6a22 |
gateway: a Claude conversation keeps the folder it named first when its caller moves
EricWvi on X (Claude Code -> local magpie -> a magpie on a server -> a
Claude subscription): the cache read flipped between under 10% and over
90%, each drop on a turn whose folder had changed (.../frontend, then
.../frontend/src). Claude Code 2.1.316 says a cd as a later
"# Environment update" message, "Primary working directory: /y (was /x)".
clientNamedWorkPlace took the last folder named, so a run started again
for the conversation (saved session resumed, branch, replay) got a
different prefix than its first run:
- a caller elsewhere: envTurnsNote names the folder, so append.md changed;
- a caller on this computer: the run worked in the new folder, whose
session project doesn't hold the saved session, so --resume was lost
and the whole conversation was told again.
Either way the whole conversation was written to the cache again.
Now the first text that names a folder decides it (within that text, its
last line, so "said twice" in one system prompt keeps its meaning). The
move still reaches the model in the conversation as the caller said it.
No text is added to the prompt; the note's wording is unchanged.
The reporter's per-turn flips on a v0.1.2879 server are the earlier
safeguards restart (git_state.cwd in safeguardsKept), fixed by
|
||
|
|
b9a45f59e0 |
claude: the run works in the caller's own folder, not one a turn quotes, and a --bare CWD: line is read (#4449)
clientNamedWorkPlace took the last working-directory line anywhere in
the request, so a user turn that merely quoted one ("Primary working
directory: /x", alone or inside a longer line) overrode the caller's
own, or broke the capture and fell back to magpie's shared folder; and
claude --bare states its folder as "CWD: /x", which was never matched,
so a --bare caller always worked in the shared folder while being told
it was theirs (WardLu).
From ggbdpq's patch (via gua2100): the caller's own word wins. Its
instructions and system messages are read first (every form, "CWD:"
included, on a line of its own); a turn is read only when the caller
named nothing, and only in the forms a caller states its folder in
(Codex's <environment_context>, OpenCode's <env>). "Primary working
directory: /y (was /x)" is read as /y, as the routing rules read it.
Not taken from the patch: it unmasked a folder whose word the redact
rules had masked and ran Claude Code there. Claude Code tells Anthropic
the folder it runs in (" - Primary working directory:" in its own
environment; the bridge goes straight to Anthropic), so the masked word
would have left the machine as written. A folder not on disk, masked or
not, falls back to magpie's folder as before, envElsewhere tells the
model its tools run in the caller's environment, and its paths are put
back on their way to the caller. TestClaudeNeverRunsInAMaskedFolder
Unmasked holds that.
Run on mote at this tree: gofmt -l internal/gateway clean; GOOS=linux
and GOOS=windows go vet ./internal/gateway ok; go test ./internal/gateway
-run 'TestClaude|TestWorkDir' -count=1 ok.
Broken by hand: the unmask put back: the masked test red (ran in
.../someuser-libs/proj); claude_subscription.go back to main: 6 of 9
subtests of TestClaudeRunsWhereTheCallerRunsNotWhereATurnQuotes red; the
layer split alone dropped: 3 red.
Not tried: a real claude --bare caller; a real redact plugin's masker
(the test masks through maskTextHits with RedactWords). Sibling:
workDirIn (workdir.go) still takes a quoted line in a user turn for
routing rules and the plugin folder header: #4940.
Co-authored-by: ggbdpq <ggbdpq@gmail.com>
|
||
|
|
1f03d75462 |
claude bridge: a caller on another computer naming no folder is told the tools run elsewhere
packinggoods on Discord: magpie on a Windows machine, the agent on a Mac.
Every shell command came wrapped in PowerShell. The model's prompt held
Claude Code's own environment section from the bridge's run: "Primary
working directory: C:\Users\...\Temp\magpie-claude-work, Platform: win32,
Shell: PowerShell". That describes the gateway, and no tool of the run
runs there: every tool is the caller's.
Claude Code has no option to leave that section out. With the real
claude 2.1.312 against a capture server (sandbox HOME, fake key), it is a
<system-reminder> in the run's first message, before magpie's text, with
the default prompt and with --system-prompt-file alike; the SDK's
excludeDynamicSections only moves it there. claude.exe on xiaomi-gpu gives
the same section with the Windows platform, temp folder and OS version.
|
||
|
|
13f9c7fca1 |
claude bridge: a caller elsewhere is told its environment is where the tools run
vv_nil on X: a Mac Claude Code through a Linux gateway's Claude subscription gets Claude Code's own prompt from the gateway's run, which names Linux and a temp folder, beside the caller's, which names the Mac and its project. The model spent extra tool calls finding out whether its environment had changed. A run that can't work in the caller's folder (the folder isn't on this computer, or Claude Code is in WSL) now has envElsewhereNote after the caller's instructions: the environment they describe is where every tool runs, and goes before one given earlier. Every tool of a run is the caller's, so that is true. The note names no app or vendor. A run in the caller's own folder, a lean run and a caller naming no folder are told nothing more. clientWorkDir is split so clientNamedWorkDir gives the folder named, wherever it is. Run: go test ./internal/gateway -run 'Claude|Bridge|Subscription|Lean|Vendor|Prompt' (ok, 49s), go vet for linux and windows, gofmt -l. TestClaudeCallersWorkDirElsewhereIsNotUsed now checks the note in both runs for a folder not here, a relative one and a Windows path, and not for no folder; TestClaudeRunsInTheCallersWorkDir checks a run in the caller's folder isn't told it. With envElsewhere forced false by hand the first is red (0 of 2 runs). Not tried: a real Claude Code run from a Mac client through a Linux gateway, so how many tool calls it saves is not measured. |
||
|
|
680b505687 |
claude: a run works in the caller's own folder, not magpie's temp folder
The bridged Claude Code told its model "Primary working directory:
<tmp>/magpie-claude-work-501", against the folder the client's own prompt
names. Under a real Claude Code client the model wrote pelican.html into
magpie's temp folder, through the client's tools, which run in the
client's folder.
startRun now runs Claude Code in the folder the caller names
(clientWorkDir): the last one in the system prompt or a non-assistant
message, as Claude Code ("Primary working directory:"), Codex (<cwd>),
OpenCode ("Working directory:") and pi ("Current working directory:")
write it, when it is an absolute path to a folder here. Otherwise (a caller
elsewhere, a WSL Claude Code, no folder named) the shared folder as before.
The caller's project's sessions are never swept; a run's session is still
removed by its id. CLAUDE_CODE_DISABLE_GIT_INSTRUCTIONS=1 keeps the
repository's status out of the prompt (setting sources and auto memory
were off already). The text sent upstream is unchanged apart from the
folder Claude Code reports itself.
Run:
- TestClaudeRunsInTheCallersWorkDir (Claude Code, Codex, OpenCode, pi,
named twice) and TestClaudeCallersWorkDirElsewhereIsNotUsed (missing,
relative, Windows path, none): red on the old code (the runs used the
shared folder). Broken by hand: sweeping the caller's folder goes red
("were swept"); dropping the env var goes red ("repository's status").
- Real run: sandbox HOME, dev build of this tree serving 127.0.0.1:3741 on
the owner's Claude Max sign-in (keychain linked in, login copies deleted
after), a client Claude Code 2.1.310 with its own CLAUDE_CONFIG_DIR,
ANTHROPIC_BASE_URL at the sandbox, run in $SB/wm and asked to write
pelican.html: it landed in $SB/wm; nothing new in magpie-claude-work-501
(its only pelican.html is the capture's, from before).
- go test ./internal/gateway at the staged tree (checkout-index), gofmt,
go vet; the full suite run is recorded in the next commit, at the pushed
head.
Not tried: a Windows client (a Windows path falls back, by the test), a
Claude Code in WSL (falls back by code).
|
||
|
|
06420a7121 |
tests: a fake program is a file macOS has already let run (testenv.Program), so a fake's first start no longer eats a test's wait under load
macOS checks a newly written executable before its first exec: 0.27s alone, 2-5s while other new programs start (a go test ./... starting its test binaries). The same file again takes 0.009s, and the pass is kept across a rename and an in-place rewrite. |
||
|
|
21702d01ff |
Add German translation; harden paths against unset env vars (#770)
* Add German translation and harden paths against unset env vars Add a German locale to the GUI, tray menu, usage alerts and website home page, and refuse to start when the home folder is unset or relative so nothing is written under the working folder; the pi plugin no longer adopts the user's PI_CODING_AGENT_DIR, and an inherited APPIMAGE no longer selects portable mode. Scripts refuse to run from the wrong folder or empty a shared out folder, and a new internal/testenv sandboxes every test package from the user's real files, which also fixes the Claude picker and Termux installer tests on Windows. * Makefile: know magpie's folder by its go.mod, so paths with spaces work The check compared $(CURDIR) with $(dir $(abspath …)), which make splits on spaces, so a checkout under 'My Projects' or 'John Doe' refused every target. It now reads go.mod relative to the working folder and wants magpie's module there: make -C and a symlinked Makefile work, make -f from another folder still stops before any recipe runs. * i18n: German for the strings main added since, with a parity test 75 strings main added (group order, patterns, slow-start wait, usage caps, RTK savings …) get their German, and two that main dropped go. gui-de.test.cjs checks, as gui-ja does, that de has every zh string with its placeholders and tags, and that the window reads in German when picked or on a German system. * appdir: ignore relative folder variables when reading, keep them for children CheckEnv no longer unsets anything. magpie reads the XDG folders, APPDATA/LOCALAPPDATA and every agent's folder variable through appdir.Getenv/LookupEnv, which pass over a relative value; the environment stays as it is, so the agents magpie starts get the variable as the user set it. That covers what proc.UserPath lends from the login shell too, which is set after main's check and reached the desktop app unchecked. On Windows a path rooted on the current drive (\Users\x, Git Bash's /c/x) counts as usable, and magpie version and help answer without a home, before run makes any folder. * Sandbox the tests main added since internal/wslrun gets testenv's TestMain, and four tests main added that set HOME alone set their home with testenv.SetHome, so on Windows they don't read the runner's profile through USERPROFILE. * agentenv: PI_CONFIG_DIR and OPENCODE_DB take relative names on purpose omp puts $PI_CONFIG_DIR under the home and OpenCode a relative $OPENCODE_DB in its data folder, so neither depends on the working folder: appdir no longer passes them over. * i18n: German for the Library's multi-select and System One's decision API The 19 strings main added since (#791's skill multi-select, the decision API snippets) get their German; the one main replaced (four APIs → five APIs) goes. * appdir: tidy the import into magpie's group; say what Go makes of /c/x The appdir import joins the group of magpie's own imports where a file has one. rooted's comment now says that Go takes a Git Bash path like /c/x as \c\x on the current drive, not C:\x. |
||
|
|
17363b7e30 |
claude: Claude Code runs share a folder only the user owns, the caller's system prompt is cached apart, and auto memory is off (#626, yg3415) — main already ran every Claude Code run in one $TMPDIR/magpie-claude so Anthropic's prompt cache is read again; this takes yg3415's version of that: the folder is magpie-claude-work-<uid> (the uid where the temp folder is shared, as /tmp is on Linux), made 0700 and used only when it is a real folder the user owns that no one else can write to (else the run works in a folder of its own, as before), so nobody else can put a CLAUDE.md in front of every run; the caller's system prompt goes to Claude Code as a block of its own with a 1h cache_control breakpoint (CLAUDE_CODE_PROMPT_CACHE_TTL=1h, since Anthropic refuses a 1h breakpoint after a 5m one), so requests with one system prompt and different conversations share its cache entry; and CLAUDE_CODE_DISABLE_AUTO_MEMORY=1, so a memory Claude Code writes in one caller's conversation doesn't show up in every other one in the shared folder. Merged onto main by hand: the run still starts through binary.command/binary.env, so a Claude Code in WSL works in the shared folder too; on Windows the folder is in the user's own %TEMP% and Go reports every folder there as 0777, so the mode check is skipped there (it refused every run before). Tests from the PR (TestClaudeRunsShareAWorkDir with a home kept in git, TestClaudeWorkDirOthersCanWriteIsAvoided, TestClaudeInstructionsCachedApart) pass; go vet (darwin, GOOS=windows), builds (darwin, GOOS=linux, GOOS=windows) and go test -tags nogui -count=1 ./... under a temp HOME pass.
Co-authored-by: yg3415 <115795347+yg3415@users.noreply.github.com> |