layerfs 0.7.2: tool descriptions and errors say "the app" and "the host", not magpie (#358)

Tool descriptions, and the errors a call answers, are part of the prompt
the agent sends its vendor. provision said "magpie's config directory",
exec "magpie serves these tools…", "MAGPIE_LAYERFS_EXEC=1" and "in
magpie's plugin options". They now say "the app's config directory",
"the host serves these tools…", "the exec switch in the host's
environment (see the package's README)" and "the host's plugin options".
The siblings that reach the model too are reworded the same way: the
source refusal ("the app's config directory"), the sim-only error (no
package or repo name, no variable names) and the bad-backend error.
Every environment variable is still read as before.

Not changed, filed as plugins#360: the workspace path provision answers
is under ~/.magpie-layerfs by default; moving it needs a plan for
existing workspaces.

Run:
- bun test (packages/layerfs): 50 pass, 0 fail
- bun scripts/check.mjs: ok
- no-magpie.test.mjs against HEAD's index.mjs and layerfs.mjs: 2 of 2 red
This commit is contained in:
yetone
2026-10-24 17:43:23 +08:00
parent c9a52b3baf
commit 79e383c404
4 changed files with 60 additions and 11 deletions
+4 -4
View File
@@ -46,7 +46,7 @@ export const LayerfsTools = async (ctx = {}, options = {}) => {
"Gives the agent a LayerFS workspace for a project branch and answers the filesystem path to work in. " +
"The first provision of a project imports the source directory the caller passes — source is required, there is no default — as its first checkpoint; " +
"later provisions of the same branch answer the same path without copying the tree again (source is then ignored). " +
"Pass the directory the user chose for this project: magpie's config directory, credential stores (.ssh, .aws, .gnupg), the home directory and the plugin's own store are refused as sources, " +
"Pass the directory the user chose for this project: the app's config directory, credential stores (.ssh, .aws, .gnupg), the home directory and the plugin's own store are refused as sources, " +
"and secret-shaped files in the tree (.env*, private keys, .git internals) never enter the store — the import skips them and reports how many. " +
"Work in the returned path, then save progress with the checkpoint tool. " +
"Only the returned path is persistent — work anywhere else, including the host's /tmp, is outside LayerFS management; " +
@@ -136,8 +136,8 @@ export const LayerfsTools = async (ctx = {}, options = {}) => {
exec: {
description:
"Runs a shell command inside a branch's provisioned workspace and checkpoints whatever it changed as one commit: run, test, fix, all captured in the branch's history. " +
"DISABLED by default: the command runs with the plugin host's privileges, and magpie serves these tools to remote callers holding a gateway key, so a shell is not something a model key should silently become. " +
"It runs only when the user has opted in — the plugin's \"exec\" option set to true, or MAGPIE_LAYERFS_EXEC=1 in the host's environment. " +
"DISABLED by default: the command runs with the plugin host's privileges, and the host serves these tools to remote callers holding a gateway key, so a shell is not something a model key should silently become. " +
"It runs only when the user has opted in — the plugin's \"exec\" option set to true, or the exec switch in the host's environment. " +
"A command that changes nothing commits nothing. A failing command's changes are still checkpointed (history can be rewound), and its exit code, stdout and stderr are returned. " +
"Only the workspace path is persistent: the command runs with TMPDIR and XDG_CACHE_HOME redirected into the workspace (.tmp/ and .cache/), " +
"workspace-local scratch that checkpoint and publish never capture, and files written to the host's real /tmp are likewise outside LayerFS management. " +
@@ -156,7 +156,7 @@ export const LayerfsTools = async (ctx = {}, options = {}) => {
async execute(args) {
if (!execEnabled()) throw new Error(
"layerfs_exec is disabled by default: it runs shell commands with the plugin host's privileges, and these tools are reachable by any caller holding a gateway key. " +
"To enable it, the user sets the plugin's \"exec\" option to true in magpie's plugin options, or sets MAGPIE_LAYERFS_EXEC=1 in the plugin host's environment, and restarts the host.")
"To enable it, the user sets the plugin's \"exec\" option to true in the host's plugin options, or turns on the exec switch in the plugin host's environment (see the package's README), and restarts the host.")
const project = checkProject(str(args.project, "project"))
const branch = checkBranch(opt(args.branch, "branch", "main"))
const command = str(args.command, "command")
+6 -6
View File
@@ -166,12 +166,12 @@ export function checkSourceDir(sourceDir, { configDir, storeRoot } = {}) {
const src = canonicalForCompare(given) // real path, case-folded: the guard's currency
const overlaps = (a, b) => a === b || a.startsWith(b + sep) || b.startsWith(a + sep)
const refuses = [
[join(homedir(), ".config", "magpie"), "magpie's config directory, which holds plugin credentials (plugin-auth.json)"],
[join(homedir(), ".config", "magpie"), "the app's config directory, which holds plugin credentials (plugin-auth.json)"],
[join(homedir(), ".ssh"), "the SSH directory"],
[join(homedir(), ".aws"), "the AWS directory"],
[join(homedir(), ".gnupg"), "the GnuPG directory"],
]
if (configDir) refuses.unshift([configDir, "magpie's config directory, which holds plugin credentials (plugin-auth.json)"])
if (configDir) refuses.unshift([configDir, "the app's config directory, which holds plugin credentials (plugin-auth.json)"])
for (const [dir, what] of refuses)
if (overlaps(src, canonicalForCompare(dir)))
throw new Error(`refusing to import ${given}: it is, contains, or sits inside ${what}`)
@@ -738,15 +738,15 @@ export class SimBackend {
// MAGPIE_LAYERFS_NATIVE=1, or by the old "native" plugin option — is
// an explicit, loud error, never a silent fall back to sim.
const SIM_ONLY_NATIVE_ERROR =
"this package is sim-only: the native LayerFS backend is not part of the magpie-community package " +
"this package is sim-only: the native LayerFS backend is not part of it " +
"(it returns in a follow-up PR once @layerfs/sdk is published to npm with a version to pin; " +
"it is developed in the standalone repo, Mola-maker/magpie-layerfs). " +
"Unset MAGPIE_LAYERFS_BACKEND / MAGPIE_LAYERFS_NATIVE and the \"native\" option to use the sim backend."
"it is developed in its standalone repo). " +
"Unset the native backend's environment switches and the \"native\" option to use the sim backend."
export async function createBackend(env = process.env, options = {}) {
const want = (env.MAGPIE_LAYERFS_BACKEND || "auto").toLowerCase()
if (want === "native" || env.MAGPIE_LAYERFS_NATIVE === "1" || options?.native === true)
throw new Error(SIM_ONLY_NATIVE_ERROR)
if (want === "sim" || want === "auto") return new SimBackend(env.MAGPIE_LAYERFS_HOME)
throw new Error(`MAGPIE_LAYERFS_BACKEND is auto or sim in this package; got ${JSON.stringify(want)}`)
throw new Error(`the LayerFS backend setting is auto or sim in this package; got ${JSON.stringify(want)}`)
}
+49
View File
@@ -0,0 +1,49 @@
// What these tools put in front of the model goes on to whatever vendor
// the agent uses (#358): the tool list (descriptions and argument schemas)
// and the errors a call answers name neither magpie nor its settings.
import { afterAll, expect, test } from "bun:test"
import { mkdtempSync, rmSync } from "node:fs"
import { tmpdir } from "node:os"
import { join } from "node:path"
import { LayerfsTools } from "./index.mjs"
import { createBackend } from "./layerfs.mjs"
const envSnapshot = { ...process.env }
const dirs = []
const mk = (p) => { const d = mkdtempSync(join(tmpdir(), p)); dirs.push(d); return d }
afterAll(() => {
for (const d of dirs) rmSync(d, { recursive: true, force: true })
for (const k of Object.keys(process.env)) if (!(k in envSnapshot)) delete process.env[k]
Object.assign(process.env, envSnapshot)
})
const named = (s) => /magpie/i.test(String(s))
const message = async (p) => { try { await p; return "" } catch (e) { return String(e?.message ?? e) } }
test("no tool description or argument names magpie", async () => {
const { tool } = await LayerfsTools({})
const sent = Object.entries(tool).map(([name, t]) => ({ name, description: t.description, args: t.args }))
expect(sent.length).toBe(8)
expect(named(JSON.stringify(sent))).toBe(false)
})
test("the errors a call answers name neither magpie nor its settings", async () => {
process.env.MAGPIE_LAYERFS_HOME = mk("lfs-home-")
process.env.MAGPIE_LAYERFS_BACKEND = "sim"
delete process.env.MAGPIE_LAYERFS_EXEC
delete process.env.MAGPIE_LAYERFS_NATIVE
const cfg = mk("app-config-")
const { tool } = await LayerfsTools({ directory: cfg }, { exec: false })
const call = (name, args) => tool[name].execute(args, { agent: "test", abort: AbortSignal.timeout(5000) })
const errors = [
await message(call("exec", { project: "website", command: "true" })),
await message(call("provision", { project: "website", source: cfg })),
await message(createBackend({ MAGPIE_LAYERFS_BACKEND: "native" })),
await message(createBackend({ MAGPIE_LAYERFS_BACKEND: "other" })),
]
for (const e of errors) {
expect(e).not.toBe("")
expect(named(e)).toBe(false)
}
})
+1 -1
View File
@@ -45,5 +45,5 @@
"directory": "packages/layerfs"
},
"type": "module",
"version": "0.7.1"
"version": "0.7.2"
}