Adds `@magpie-community/agent-zycode` 0.1.0: zycode (`zypi`, the VS Code extension, the ACP agent) on magpie's Agents page. magpie writes the model, gateway URL and key to `~/.pi-python/local.env`. A host part (`bridge.mjs`) copies them into the `[model]` table of `agent.toml` as text, and puts the file back byte for byte on disconnect, keeping any edits the user made meanwhile. Reviewed at 618771e7c9269c8248599f05cd86eb18e00c358f: - WSL Ubuntu 24.04, Bun 1.4.2: `bun test` in packages/zycode 20 pass; `bun scripts/check.mjs zycode` exit 0. - Broken by hand: disconnect leaving agent.toml as is (`const back = current`) turns 9 of 20 red. - No network and no child processes; local files only, temp-and-rename, symlinks refused. - Real run by the author (Ubuntu VM, zypi 0.9.1, magpie v0.1.4069): only the four [model] lines changed; one turn answered through magpie (Usage shows zycode, 4 calls); after disconnect, agent.toml and local.env have identical sha256. Not tried: Windows, macOS, the VS Code extension's frozen agent binary. Co-authored-by: zy1233 <zy1233@users.noreply.github.com>
21 lines
885 B
JavaScript
21 lines
885 B
JavaScript
import { pathsFor, startBridge, sync } from "./bridge.mjs"
|
|
|
|
const instance = Symbol.for("magpie.zycode.bridge.v1")
|
|
|
|
// The agent file runs in moejs, which edits json, yaml and env but not
|
|
// TOML. This part runs in magpie's plugin host and puts what magpie wrote
|
|
// to local.env into the [model] table of agent.toml, and takes it out again.
|
|
export default async function ZycodeBridgePlugin() {
|
|
if (!globalThis[instance]) {
|
|
const paths = pathsFor()
|
|
globalThis[instance] = { stop: startBridge(paths) }
|
|
// magpie takes its lines out of local.env before it closes the host on
|
|
// disable or removal: undo agent.toml on the way out, without waiting
|
|
// for the next poll.
|
|
process.once("exit", () => {
|
|
try { sync(paths) } catch (e) { console.error(`zycode bridge paused, agent.toml left as it is${e.refusal ? `: ${e.message}` : ""}`) }
|
|
})
|
|
}
|
|
return {}
|
|
}
|