magpie-image was the one MCP server the hub left out, because it saves what it makes on disk and needs to know whose project that is. The hub now serves its tools like any other server's and tells it where the caller works: 1. the hub answers a tools/call as SSE and asks the agent roots/list on that stream (3s), as Claude Code answers; 2. else Codex's _meta x-codex-turn-metadata.workspaces (git repos only); 3. else the Codex thread's cwd from its session file (sessions.CodexThreadCwd), only with session consent; 4. else none, and the image goes to ~/Pictures/Magpie as before. The hub passes `magpie/roots` and `magpie/client` in the call's _meta; imagemcp saves into the first root and names the agent on its usage row. Its result carries `magpie/model`, which the hub's own usage row takes, so the row says which image model drew it. A WSL agent keeps magpie-image as its own entry (the hub can't reach a path inside the distro). docs/subsystems/mcp-hub.md (mcp-router.md after the next commit), gateway-routing.md and gateway-sessions.md say so. It is rebased on #4382 (b889ffe81), which lets the user keep a server out of the hub (Server.Hub = direct). inHub now asks both: a server kept direct is out, and magpie-image is in unless the agent is in WSL, so the user can keep magpie-image direct too; the editor's switch shows for it like any server, and the hub's line counts it with the others (mcp-hub-direct.test.cjs follows). Run at e2583df31 (this stack on86fef947e), on mote: gofmt -l clean; go vet for darwin, linux (-tags nogui) and windows; go build ./...; go test -tags nogui ./... -timeout 45m, 81 packages ok, 0 FAIL; library, gateway, imagemcp, sessions, cli and gui again alone, ok; site's node --test, 49 of 49. GUI on xiaomi-gpu (Windows; mote's browsers crashed under other sessions' suites): library-*, image*, mcp-hub-direct, i18n-keys, list-sort and plugin-tools, both engines and every language, 1055 of 1056: i18n-keys found "{name} is given to each agent directly" dropped from the library's strings in the rebase. Put back in the first commit; at the pushed head i18n-keys, mcp-hub-direct and library-mcp-hub are 48 of 48. That is the only difference from e2583df31. Broken by hand at e2583df31: imagemcp ignoring magpie/roots fails TestHubCallSavesInTheCallersProject; the router asking anything but roots/list fails TestHubAsksTheAgentItsRoots and TestHubRootsUnasked; inHub leaving magpie-image out fails TestHubGivesMagpieImage. Real use, sandbox HOME and gateway, at 62421e570 (before the rebase): Claude Code saved into its project via roots/list; Codex in a git repo via its workspaces _meta; Codex outside a repo with session consent via the thread's cwd. At 62421e570 the whole GUI suite ran on WSL magpie-desktop at load 116 to 135 from other runs: 504 of 15757 red in 118 files, WebKit timeouts, none in a file this change touches; filed as #4471 with the list. Rebased once more onto2570efb5f, which changed library-mcp-hub, list-sort, mcp-hub-direct and gateway-routing.md. Run at the pushed head: go build; gateway, library, cli and imagemcp tests ok; the GUI budget tests ok; on xiaomi-gpu i18n-keys, mcp-hub-direct, library-mcp-hub and list-sort, 51 of 54. The three reds were WebKit 420px library-mcp-hub cases with no Connect sheet after a reload. origin/maind77da5bffgoes red the same way (de 420px, 9 of 11). In a second run of library-mcp-hub on WebKit at this head, 11 of 11 passed. Filed as #4483. Not tried: Codex outside a git repo without consent (it saves to ~/Pictures/Magpie, #4435); agents on Windows and in WSL with real use.
36 lines
882 B
Go
36 lines
882 B
Go
package sessions
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
// CodexThreadCwd is the folder Codex thread id runs in, as its newest
|
|
// rollout's session_meta says; "" when no rollout of it is read. magpie's
|
|
// MCP hub asks it for Codex, which says no roots (roots/list answers
|
|
// none) but names its thread in each tool call's _meta, so magpie-image
|
|
// behind the hub still saves into the thread's project.
|
|
func CodexThreadCwd(id string) string {
|
|
id = strings.TrimSpace(id)
|
|
if id == "" {
|
|
return ""
|
|
}
|
|
var path string
|
|
var mod time.Time
|
|
for _, f := range codexFiles() {
|
|
if f.cold || !strings.EqualFold(f.key, "codex:"+id) || (path != "" && !f.mod.After(mod)) {
|
|
continue
|
|
}
|
|
path, mod = f.path, f.mod
|
|
}
|
|
if path == "" {
|
|
return ""
|
|
}
|
|
var l cxLine
|
|
if json.Unmarshal(firstLine(path), &l) != nil || l.Type != "session_meta" {
|
|
return ""
|
|
}
|
|
return l.Payload.Cwd
|
|
}
|