From d6d32718084da6f9f24c5d3681fbd8dc84ec102b Mon Sep 17 00:00:00 2001 From: Jason Woltje Date: Fri, 20 Nov 2026 03:54:59 -0600 Subject: [PATCH 1/3] fix(adapters,harness): pi-skills: with MOSAIC_SKILLS the pi adapter keeps --no-skills and puts each --skill after it, since pi 0.85.1 adds a --skill directory to discovery (with --skill alone a scratch-HOME probe also loaded the user, settings, package and ~/.agents skills); the fit check's sealed -p run, the worker shape, now passes --no-skills with one --skill directory and must list that skill and no planted one, so a pi that lets --skill bring discovery back, or drops the --skill directory beside --no-skills, is refused harness-feature-missing, at no extra run; the stand-in pi loads --skill directories (skillLeak, ignoreSkill knobs); tests red on BASE for the argv order, real pi 0.85.1 through the adapter and both stand-in refusals; READMEs and the Not run note updated (#1873, lane pi-skills) --- adapters/README.md | 13 +++ adapters/pi/adapter.sh | 12 ++- packages/harness/README.md | 14 ++- packages/harness/src/pi-fit.mjs | 35 +++++--- packages/harness/tests/pi-fit.test.mjs | 118 +++++++++++++++++++++++++ packages/harness/tests/pi-stand-in.mjs | 7 +- 6 files changed, 181 insertions(+), 18 deletions(-) diff --git a/adapters/README.md b/adapters/README.md index 3852471ce..2a2d178c6 100644 --- a/adapters/README.md +++ b/adapters/README.md @@ -106,6 +106,19 @@ keeps its existing channel; the CLI does not inherit the completion pipe. No ext writable mount or completion file is needed. Pi retains print mode and signals activity through its existing extension. Mock remains a test-only echo. +### A worker's skills (M17, #1873) + +Worker runs and `scripts/agent.sh` may set `MOSAIC_SKILLS`, a comma list of +skill directories. The pi adapter passes `--no-skills` and then +`--skill ` for each one. On pi 0.85.1 `--skill` adds to discovery and +does not replace it. With `--skill` alone, a probe with a scratch HOME also +loaded the user's skills, the skills a `settings.json` or a listed package +names, and `~/.agents/skills` (and the project's, without `--no-approve`). +With `--no-skills` first, only the given directories load. A directory that +doesn't exist stops the adapter with exit 2. The fit check runs this shape +in its sealed `-p` run (`packages/harness/README.md`). The fit check runs +before bus sessions only; worker containers run the pi pinned in the image. + ### A role's skills (row 64) A managed session's skills reach both adapters as text in the bundle's diff --git a/adapters/pi/adapter.sh b/adapters/pi/adapter.sh index 4ea49eaf7..c78b1e5ef 100644 --- a/adapters/pi/adapter.sh +++ b/adapters/pi/adapter.sh @@ -57,14 +57,17 @@ fi TOOLS_FLAG="--no-tools" [ -n "${MOSAIC_TOOLS:-}" ] && TOOLS_FLAG="--tools $MOSAIC_TOOLS" -# Skills (M17): explicitly provided skill dirs replace discovery. When none -# are provided the agent runs with --no-skills (nothing ambient to find). +# Skills (M17, #1873 pi-skills): --no-skills always, then one --skill per +# given dir. On pi 0.85.1 --skill adds to discovery and does not replace it: +# with --skill alone pi also loads the user's skills, settings and package +# skills and ~/.agents/skills (a planted-skill probe showed it, offline, with a +# scratch HOME). With --no-skills first only the given dirs load. The fit check +# (packages/harness/src/pi-fit.mjs) runs this shape in its sealed -p run. # Role sessions never get MOSAIC_SKILLS (ENV_ALLOW in packages/seat/src/ -# session.mjs leaves it out), so they run with --no-skills; their skills +# session.mjs leaves it out), so they run with --no-skills alone; their skills # are text in the system prompt (row 64). SKILLS_FLAG="--no-skills" if [ -n "${MOSAIC_SKILLS:-}" ]; then - SKILLS_FLAG="" OLDIFS=$IFS; IFS=',' for s in $MOSAIC_SKILLS; do [ -d "$s" ] || { echo "pi adapter: skill dir missing: $s" >&2; exit 2; } @@ -112,6 +115,7 @@ fi # --system-prompt replace the default prompt with the generated one, given # as the file's absolute path (checked above), never its text # --no-* no ambient context/skills/extensions/templates/themes +# SKILLS_FLAG --no-skills, then --skill for each MOSAIC_SKILLS dir # NO_MCP_FLAG --no-mcp when the binary lists it, else nothing # EXT_FLAGS the explicitly provided extensions only (-e) # SESSION_FLAGS ephemeral | persistent | forked (per env) diff --git a/packages/harness/README.md b/packages/harness/README.md index 276454420..a32ddaf71 100644 --- a/packages/harness/README.md +++ b/packages/harness/README.md @@ -93,9 +93,17 @@ that no session sets. So a branch on `TZ` or `LC_ALL` being unset, or on it, so `${TERM:-}` in the adapter is never empty, in a session or here.) It can't see a branch keyed on a value it doesn't try (a model, a path, another tool or provider). A last sealed `-p` run uses `--no-session`, as -worker runs do. Each run gets a fresh scratch directory, so no run sees -what another left. Not run: `--fork`, `--skill` and the interactive TUI -(worker containers and `scripts/agent.sh` only), the branches three or +worker runs do, and one `--skill` directory right after `--no-skills`, as +the adapter passes a worker's `MOSAIC_SKILLS`. Its `-e` extension must +list that skill and no planted one. pi 0.85.1 adds a `--skill` directory +to discovery, so a pi that let `--skill` bring the planted skills back is +refused there, and so is one that drops the `--skill` directory once +`--no-skills` is on. The shape rides on that existing run, so it adds no +run. Each run gets a fresh scratch directory, so no run sees +what another left. Not run: `--fork` and the interactive TUI +(worker containers and `scripts/agent.sh` only), `--skill` in rpc or +beside a session's flags (no session passes it), more than one `--skill` +directory, the branches three or four at a time beyond the five runs, `-c` over a session directory that holds nothing for the project (one more run costs about 340 ms cold), and a session's own values (tools beyond `read` and `bash`, thinking diff --git a/packages/harness/src/pi-fit.mjs b/packages/harness/src/pi-fit.mjs index 5207e7acd..9076de45f 100644 --- a/packages/harness/src/pi-fit.mjs +++ b/packages/harness/src/pi-fit.mjs @@ -39,8 +39,14 @@ // planted source. A test drives the adapter through every branch set, tool list // length and thinking level, and fails on an argv sessionShape doesn't build or a // pair no run passes. -// sealed -p the seal flags in -p with --no-session, as a worker run passes them. Its -e -// extension must reach session_start, and no planted source may show. +// sealed -p the seal flags in -p with --no-session, as a worker run passes them, with one +// --skill directory right after --no-skills, as adapters/pi/adapter.sh passes a +// worker's MOSAIC_SKILLS. Its -e extension must reach session_start and list the +// given skill, and no planted source may show. pi 0.85.1 adds a --skill directory to +// discovery, so a pi that let --skill turn discovery back on, or dropped --no-skills +// beside it, would show the planted skills here; one that ignores --skill once +// --no-skills is on would not list the given skill. This run costs nothing extra: it +// is the -p run the check already made. // missing -e a missing -e file, in rpc and in -p, stops the start: exit non-zero, no answer, // and no session_start for the -e extension given after it // @@ -76,9 +82,10 @@ // repository's pi), never a host path. // // Known limit: pi 0.85.1 appends the agent directory's APPEND_SYSTEM.md whatever the flags. The -// check doesn't plant one; a session's agent directory is the run's own. Not run: --fork, -// --skill with --no-skills dropped, and the interactive TUI, which only worker containers and -// scripts/agent.sh pass; the session branches three or four at a time beyond the session-shaped +// check doesn't plant one; a session's agent directory is the run's own. Not run: --fork and +// the interactive TUI, which only worker containers and scripts/agent.sh pass; --skill in rpc or +// beside a session's flags (no session passes it), and more than one --skill directory; the +// session branches three or four at a time beyond the session-shaped // runs; -c over a session directory that holds nothing for the project (the adapter passes -c // whenever the directory isn't empty), since one more run costs about 340 ms cold; and a // session's own values: its tool names beyond read and bash, thinking levels beyond low, @@ -313,7 +320,7 @@ async function check(found, { levels, bwrap, unshare, node, who, digest, host }) const answer = answered(r.stdout); const start = started(scratch); const listed = start?.commands ?? []; - return { ...r, answer, explicit: marked(scratch, EXPLICIT), second: marked(scratch, SECOND), prompt: start?.prompt ?? null, session: start?.session ?? null, listed: named(listed), seen: seen(scratch, [...(answer.commands ?? []), ...listed], start) }; + return { ...r, answer, explicit: marked(scratch, EXPLICIT), second: marked(scratch, SECOND), prompt: start?.prompt ?? null, session: start?.session ?? null, listed: named(listed), skill: names(listed, GIVEN_SKILL), seen: seen(scratch, [...(answer.commands ?? []), ...listed], start) }; } finally { // #1873 re-check 10: a run this check killed (a timeout, or stop) may have had bwrap in its // setup, and without unshare's outer layer bwrap's child then waits for good. The run is @@ -379,8 +386,9 @@ async function judge(found, { levels, who, digest, run }) { if (shape.cont) plantSession(s); return sessionShape({ noMcp, extensions: [join(s, "explicit", "fit.ts"), join(s, "explicit", "second.ts")], prompt: join(s, "prompt.md"), sessionDir: join(s, "sessions"), message: "fit check", ...shape }); }, "", { noMcp, shape })]); - // -p takes a message; offline with no key, pi stops before any model call. - const pRun = run((s) => ["-p", ...seal, ...given(s), "fit check"], "", { noMcp }); + // -p takes a message; offline with no key, pi stops before any model call. A worker's shape: the + // seal flags with a --skill directory right after --no-skills, as the adapter puts MOSAIC_SKILLS. + const pRun = run((s) => ["-p", ...seal.flatMap((f) => f === "--no-skills" ? [f, "--skill", join(s, "given", GIVEN_SKILL)] : [f]), ...given(s), "fit check"], "", { noMcp }); // A missing -e file stops the start. pi 0.85.1 loads the -e files in order and still loads the // one after the missing one, then exits 1 before session_start, so only session_start tells. const missingRuns = [["rpc", ["--mode", "rpc"], ask], ["-p", ["-p"], ""]].map(([mode, args, input]) => @@ -438,7 +446,8 @@ async function judge(found, { levels, who, digest, run }) { const p = await pRun; if (p.stopped) return refuse(`can't be checked: a -p start with the seal flags ${p.stopped}`); if (p.prompt === null) return refuse("can't be checked: a -p start with the seal flags didn't run its -e extension"); - if (p.seen.length) return refuse(`loaded a planted ${p.seen.map((x) => x.source).join(", ")} with the seal flags on in -p`); + if (p.seen.length) return refuse(`loaded a planted ${p.seen.map((x) => x.source).join(", ")} with the seal flags and a --skill directory on in -p`); + if (!p.skill) return refuse("didn't load a --skill directory with --no-skills on in -p"); for (const [mode, pending] of missingRuns) { const r = await pending; @@ -657,6 +666,9 @@ const GIVEN = "FITGIVENPROMPT"; // pass after it. const EXPLICIT = "explicit extension"; const SECOND = "second explicit extension"; +// The skill the sealed -p run passes with --skill (scratch/given/), outside every place pi +// looks for skills, so it shows only through --skill. It is not planted ambient: not in NAMED. +const GIVEN_SKILL = "fit-given-skill"; // The id of the session a -c run must resume. const PLANTED_SESSION = "fit-planted-session"; const markerName = (source) => source.replace(/[^a-z]/g, "-"); @@ -669,8 +681,10 @@ function started(scratch) { if (!m || typeof m.prompt !== "string" || !Array.isArray(m.commands)) return null; return { prompt: m.prompt, commands: m.commands.filter((c) => typeof c === "string"), session: typeof m.session === "string" ? m.session : null }; } +// Whether command names hold name, bare or after a prefix such as "skill:". +const names = (commands, name) => commands.some((c) => c === name || c.endsWith(`:${name}`)); // The planted skills and prompt templates among command names, as { source, kind }. -const named = (names) => Object.entries(NAMED).filter(([name]) => names.some((c) => c === name || c.endsWith(`:${name}`))).map(([, [source, kind]]) => ({ source, kind })); +const named = (commands) => Object.entries(NAMED).filter(([name]) => names(commands, name)).map(([, [source, kind]]) => ({ source, kind })); function plant(scratch) { const marks = join(scratch, "marks"); @@ -715,6 +729,7 @@ function plant(scratch) { put(join(project, ".agents", "skills", "fit-agents-skill", "SKILL.md"), skill("fit-agents-skill")); put(join(project, ".pi", "prompts", "fit-project-prompt.md"), prompt); put(join(scratch, "home", ".agents", "skills", "fit-home-skill", "SKILL.md"), skill("fit-home-skill")); + put(join(scratch, "given", GIVEN_SKILL, "SKILL.md"), skill(GIVEN_SKILL)); for (const [file, text] of TEXTS) put(join(scratch, file), `${text}\n`); put(join(scratch, "explicit", "fit.ts"), `import { writeFileSync } from "node:fs";\nexport default function (pi: any): void {\n writeFileSync(${JSON.stringify(join(marks, markerName(EXPLICIT)))}, "");\n pi.on("session_start", (_event: any, ctx: any) => { writeFileSync(${JSON.stringify(join(marks, "start.json"))}, JSON.stringify({ prompt: ctx.getSystemPrompt(), commands: pi.getCommands().map((c: any) => c.name), session: ctx.sessionManager.getSessionId() })); });\n}\n`); put(join(scratch, "explicit", "second.ts"), ext(SECOND)); diff --git a/packages/harness/tests/pi-fit.test.mjs b/packages/harness/tests/pi-fit.test.mjs index bc01e6c62..e65cc039e 100644 --- a/packages/harness/tests/pi-fit.test.mjs +++ b/packages/harness/tests/pi-fit.test.mjs @@ -123,6 +123,22 @@ test("pi-unpin S3: a stand-in that touches the planted MCP marker under the seal for (const [kind, line] of Object.entries(lines)) assert.equal((await fit(standIn(t, { sealLeak: [kind] }).env)).message, `pi 2.0.0 (MOSAIC_PI_BIN) ${line}`, kind); }); +// pi-skills: the worker's shape. pi 0.85.1 adds a --skill directory to discovery, so the adapter +// keeps --no-skills in front of each --skill; the fit check's sealed -p run passes that shape. +test("pi-skills: a stand-in that loads the planted skills once a --skill directory is given is refused", SKIP, async t => { + const s = standIn(t, { skillLeak: true }); + const problem = await pi.preflight({ env: { ...CREDENTIAL, ...s.env } }); + assert.deepEqual(problem, { code: "harness-feature-missing", message: "pi 2.0.0 (MOSAIC_PI_BIN) loaded a planted user skill, user settings skill, user package skill, project skill, project settings skill, project package skill, project .agents skill, home .agents skill with the seal flags and a --skill directory on in -p" }); + noPath(problem.message, s.paths); +}); + +test("pi-skills: a stand-in that drops a --skill directory once --no-skills is on is refused", SKIP, async t => { + const s = standIn(t, { ignoreSkill: true }); + const problem = await pi.preflight({ env: { ...CREDENTIAL, ...s.env } }); + assert.deepEqual(problem, { code: "harness-feature-missing", message: "pi 2.0.0 (MOSAIC_PI_BIN) didn't load a --skill directory with --no-skills on in -p" }); + noPath(problem.message, s.paths); +}); + test("pi-unpin S3: a stand-in that ignores the planted sources even without the seal flags fails the positive control and is refused as can't tell", SKIP, async t => { const s = standIn(t, { ignoreAll: true }); const problem = await pi.preflight({ env: { ...CREDENTIAL, ...s.env } }); @@ -188,6 +204,11 @@ test("pi-unpin S3 re-check 3: every run has its own scratch directory, and the r const shaped = (args) => args.includes("--session-dir"); assert.deepEqual(runs.filter((x) => shaped(x.args)).map((x) => JSON.stringify(x.args)).sort(), shapes.map((shape) => JSON.stringify(fitModule.sessionShape({ noMcp: extraFlags.length > 0, extensions: ["/explicit/fit.ts", "/explicit/second.ts"], prompt: "/prompt.md", sessionDir: "/sessions", message: "fit check", ...shape }))).sort()); const flagLists = []; + // pi-skills: the sealed -p run is a worker's shape, with one --skill directory right after + // --no-skills, as the adapter passes MOSAIC_SKILLS. No other run passes --skill. + const skilled = runs.filter((x) => x.args.includes("--skill")); + assert.equal(skilled.length, 1); + assert.deepEqual(skilled[0].args, ["-p", ...seal.flatMap((f) => f === "--no-skills" ? [f, "--skill", "/given/fit-given-skill"] : [f]), "-e", "/explicit/fit.ts", "--system-prompt", "/prompt.md", "fit check"]); for (const { args } of runs.filter((x) => x.args.length > 1 && !shaped(x.args))) { const flags = args.filter((a) => seal.includes(a)); assert.deepEqual(flags, seal.filter((f) => flags.includes(f)), "the seal flags keep their order"); @@ -195,6 +216,7 @@ test("pi-unpin S3 re-check 3: every run has its own scratch directory, and the r for (let i = 0; i < args.length; i++) { if (args[i] === "--mode") { i++; continue; } if (args[i] === "-e" && args[i + 1] === "/missing/extension.ts") { i++; continue; } + if (args[i] === "--skill" && args[i + 1] === "/given/fit-given-skill") { i++; continue; } if (args[i] === "-p" || seal.includes(args[i]) || (args.includes("-p") && i === args.length - 1)) continue; rest.push(args[i]); } @@ -863,6 +885,25 @@ test("pi-unpin S3: real pi 0.85.1 from node_modules is accepted, and the event l assert.ok(max <= GAP_MAX, `the event loop waited ${max.toFixed(0)} ms during the cold check`); }); +// pi-skills: real pi passes the fit check's worker shape, the sealed -p run with --no-skills and a +// --skill directory: it lists the given skill and no planted one. A logging bwrap shows the run. +test("pi-skills: real pi 0.85.1 passes the fit check's sealed -p run with --no-skills and a --skill directory", SKIP, async t => { + const found = locate({ PATH: "/usr/bin:/bin" }); + const root = mkdtempSync(join(tmpdir(), "mosaic-pi-skills-fit-")); + t.after(() => rmSync(root, { recursive: true, force: true })); + const log = join(root, "bwrap.log"); + const bwrap = join(root, "bwrap"); + writeFileSync(bwrap, `#!/bin/sh\nf=$(/usr/bin/mktemp '${log}.XXXXXX')\nfor a in "$@"; do printf '%s\\037' "$a"; done > "$f"\nexec '${BWRAP}' "$@"\n`, { mode: 0o755 }); + const r = await piFit(found, { levels: LEVELS, bwrap }); + assert.equal(r.ok, true, r.message); + const skilled = readdirSync(root).filter((n) => n.startsWith("bwrap.log.")).map((n) => readFileSync(join(root, n), "utf8").split("\x1f")).filter((a) => a.includes("--skill")); + assert.equal(skilled.length, 1); + const a = skilled[0]; + assert.equal(a[a.indexOf("--no-skills") + 1], "--skill"); + assert.match(a[a.indexOf("--skill") + 1], /\/given\/fit-given-skill$/); + assert.ok(a.includes("-p") && a.includes("--no-session")); +}); + test("pi-unpin S3 re-check 7: the event loop stays live while a stand-in's cold check runs", SKIP, async t => { const { result, max } = await gapDuring(() => fit(standIn(t, {}).env)); assert.equal(result.ok, true, result.message); @@ -957,6 +998,83 @@ test("pi-unpin S3: the adapter passes --no-mcp only when the module asks for it" assert.equal((await run(standIn(t, {}))).includes("--no-mcp"), false); }); +// pi-skills: a worker's MOSAIC_SKILLS. pi 0.85.1 adds a --skill directory to discovery, so the +// adapter keeps --no-skills and puts each --skill after it. A stub records the argv. +const workerAdapter = (t, extra = {}) => { + const root = mkdtempSync(join(tmpdir(), "mosaic-pi-skills-t-")); + t.after(() => rmSync(root, { recursive: true, force: true })); + const stub = join(root, "pi"); + writeFileSync(stub, '#!/bin/sh\nprintf "%s\\0" "$@" > "$ARGV_OUT"\n', { mode: 0o755 }); + writeFileSync(join(root, "prompt.md"), "p\n"); + const env = { PATH: "/usr/bin:/bin", HOME: join(root, "home"), ARGV_OUT: join(root, "argv"), MOSAIC_PI_BIN: stub, MOSAIC_SYSTEM_PROMPT_FILE: join(root, "prompt.md"), PI_PROVIDER: "fixture", PI_MODEL: "m", MOSAIC_REQUEST: "x", ...extra(root) }; + const r = spawnSync("/bin/sh", [join(REPO, "adapters", "pi", "adapter.sh")], { encoding: "utf8", env }); + return { root, r, argv: () => readFileSync(join(root, "argv"), "utf8").split("\0").slice(0, -1) }; +}; + +test("pi-skills: with MOSAIC_SKILLS the adapter passes --no-skills, then --skill for each directory", t => { + const w = workerAdapter(t, (root) => { + for (const n of ["one", "two"]) mkdirSync(join(root, "skills", n), { recursive: true }); + return { MOSAIC_SKILLS: `${join(root, "skills", "one")},${join(root, "skills", "two")}` }; + }); + assert.equal(w.r.status, 0, w.r.stderr); + const argv = w.argv(); + const i = argv.indexOf("--no-skills"); + assert.ok(i >= 0, argv.join(" ")); + assert.equal(argv.filter((a) => a === "--no-skills").length, 1, argv.join(" ")); + assert.deepEqual(argv.slice(i, i + 5), ["--no-skills", "--skill", join(w.root, "skills", "one"), "--skill", join(w.root, "skills", "two")]); + assert.equal(argv.filter((a) => a === "--skill").length, 2, argv.join(" ")); + // Without MOSAIC_SKILLS: --no-skills alone, as before. + const bare = workerAdapter(t, () => ({})); + assert.equal(bare.r.status, 0, bare.r.stderr); + assert.ok(bare.argv().includes("--no-skills")); + assert.ok(!bare.argv().includes("--skill")); +}); + +test("pi-skills: a missing MOSAIC_SKILLS directory still exits 2 before pi runs", t => { + const w = workerAdapter(t, (root) => { + mkdirSync(join(root, "skills", "one"), { recursive: true }); + return { MOSAIC_SKILLS: `${join(root, "skills", "one")},${join(root, "skills", "gone")}` }; + }); + assert.equal(w.r.status, 2); + assert.match(w.r.stderr, /^pi adapter: skill dir missing: /); + assert.equal(existsSync(join(w.root, "argv")), false, "pi did not run"); +}); + +// pi-skills: the worker's shape end to end. The adapter runs real pi 0.85.1 with MOSAIC_SKILLS, an +// -e extension that writes the command names at session_start, a HOME and workspace holding planted +// skills in every place pi 0.85.1 looks, the network unshared and no key: pi stops before any model +// call. Only the given skills may load. On the adapter that dropped --no-skills, the user, settings +// and ~/.agents skills loaded too. +const UNSHARE_NET = spawnSync("unshare", ["-rn", "true"]).status === 0 ? {} : { skip: "no unshare -rn here" }; +test("pi-skills: real pi 0.85.1 through the adapter with MOSAIC_SKILLS loads the given skills and no planted one", UNSHARE_NET, async t => { + const found = locate({ PATH: "/usr/bin:/bin" }); + assert.equal(found.label, "the repository's pi"); + const root = mkdtempSync(join(tmpdir(), "mosaic-pi-skills-real-")); + t.after(() => rmSync(root, { recursive: true, force: true })); + const put = (p, text) => { mkdirSync(dirname(p), { recursive: true }); writeFileSync(p, text); }; + const skill = (name) => put(join(root, ...name.split("/"), "SKILL.md"), `---\nname: ${name.split("/").pop()}\ndescription: a planted skill\n---\nA planted skill.\n`); + const home = join(root, "home"); + const ws = join(root, "ws"); + for (const s of ["home/.pi/agent/skills/amb-user-skill", "home/.agents/skills/amb-home-skill", "listed/amb-set-skill", "listed/pkg/skills/amb-pkg-skill", "ws/.pi/skills/amb-project-skill", "ws/.agents/skills/amb-agents-skill", "given/one-skill", "given/two-skill"]) skill(s); + put(join(root, "listed", "pkg", "package.json"), JSON.stringify({ name: "amb-package", version: "1.0.0" })); + put(join(home, ".pi", "agent", "settings.json"), JSON.stringify({ skills: [join(root, "listed", "amb-set-skill")], packages: [join(root, "listed", "pkg")], defaultProjectTrust: "always" })); + put(join(ws, ".pi", "settings.json"), JSON.stringify({ skills: [join(root, "listed", "amb-set-skill")] })); + const marks = join(root, "start.json"); + put(join(root, "ext", "list.ts"), `import { writeFileSync } from "node:fs";\nexport default function (pi: any): void {\n pi.on("session_start", () => { writeFileSync(${JSON.stringify(marks)}, JSON.stringify(pi.getCommands().map((c: any) => c.name))); });\n}\n`); + put(join(root, "prompt.md"), "p\n"); + mkdirSync(join(root, "tmp")); + const env = { + PATH: `${dirname(process.execPath)}:/usr/bin:/bin`, HOME: home, TMPDIR: join(root, "tmp"), LANG: "C.UTF-8", + MOSAIC_PI_BIN: found.bin, MOSAIC_SYSTEM_PROMPT_FILE: join(root, "prompt.md"), PI_PROVIDER: fitModule.SESSION_SHAPE.provider, PI_MODEL: fitModule.SESSION_SHAPE.model, + MOSAIC_REQUEST: "fit check", MOSAIC_WORKSPACE: ws, MOSAIC_EXTENSIONS: join(root, "ext", "list.ts"), + MOSAIC_SKILLS: `${join(root, "given", "one-skill")},${join(root, "given", "two-skill")}`, + }; + spawnSync("unshare", ["-rn", "/bin/sh", join(REPO, "adapters", "pi", "adapter.sh")], { encoding: "utf8", env, timeout: 60000 }); + const commands = JSON.parse(readFileSync(marks, "utf8")); + const skills = commands.filter((c) => c.startsWith("skill:")).map((c) => c.slice(6)).sort(); + assert.deepEqual(skills, ["one-skill", "two-skill"]); +}); + // Re-check 5 item 1, narrowed by re-check 6 P3-1. The adapter runs with the environment a bus // session's pi gets (busEnv: sessionEnv over a host, sessionSetenv, adapterEnv, pi.env()), so // HOME and the rest are set as a session sets them, not by the shell. Re-check 7 P2-1: every run is diff --git a/packages/harness/tests/pi-stand-in.mjs b/packages/harness/tests/pi-stand-in.mjs index 2209d81f6..81f8d566e 100644 --- a/packages/harness/tests/pi-stand-in.mjs +++ b/packages/harness/tests/pi-stand-in.mjs @@ -54,6 +54,10 @@ // no commands. // `commands` "fail" answers get_commands with success false; "list" answers // with a bare list. +// --skill loads that skill (its directory's name) whatever --no-skills says, +// as pi 0.85.1 does. `skillLeak`: with a --skill given, the planted skills load too +// whatever --no-skills says (discovery comes back with --skill). `ignoreSkill`: a +// --skill directory loads only without --no-skills. // otherwise a session with no $ARGV_OUT: prints `sessionOut` and exits 0. // // Trust, as pi 0.85.1 has it: the project is trusted with --approve, or with a saved trust and @@ -173,12 +177,13 @@ if (rpc || print) { for (const s of Object.values(json(f)?.mcpServers || {})) cp.spawnSync(s.command, s.args || [], { stdio: "ignore" }); } } - if (on("skills", "--no-skills")) { + if (on("skills", "--no-skills") || (K.skillLeak && has("--skill") && !ignoreAll)) { const home = process.env.HOME || "/"; const dirs = [path.join(agent, "skills"), path.join(cwd, ".pi", "skills"), path.join(cwd, ".agents", "skills"), path.join(home, ".agents", "skills"), ...packages.map((p) => path.join(p, "skills"))]; for (const d of dirs) for (const p of list(d, () => true)) commands.push({ name: "skill:" + path.basename(p), source: "skill" }); for (const s of settings) for (const p of s.skills || []) commands.push({ name: "skill:" + path.basename(p), source: "skill" }); } + if (!(K.ignoreSkill && has("--no-skills"))) for (const p of argv.flatMap((a, i) => a === "--skill" ? [argv[i + 1]] : [])) commands.push({ name: "skill:" + path.basename(p), source: "skill" }); if (on("prompts", "--no-prompt-templates")) { const dirs = [path.join(agent, "prompts"), path.join(cwd, ".pi", "prompts"), ...packages.map((p) => path.join(p, "prompts"))]; for (const d of dirs) for (const p of list(d, (n) => n.endsWith(".md"))) commands.push({ name: path.basename(p, ".md"), source: "prompt" }); -- 2.54.0 From 59af86a5ee2eaf753048c2f1d08f2eb17115c6f5 Mon Sep 17 00:00:00 2001 From: Jason Woltje Date: Fri, 20 Nov 2026 04:11:25 -0600 Subject: [PATCH 2/3] fix(harness): pi-skills review: the fit check's last -p run is now the adapter's headless worker argv with MOSAIC_SKILLS, an -e file and no tools (new export workerShape: --no-skills then two --skill directories, --no-tools, --no-session, the fit route's --provider and --model, --system-prompt, -p), and must list both given skills and no planted one, so a pi that leaks only with --skill and --provider is refused harness-feature-missing (P3-1); a test runs the adapter and holds its argv to workerShape; the run replaces the plain sealed -p --no-session run, so it still adds no run, and both Not run notes now name that plain shape, --skill beside --tools, --session-dir, -c, --thinking or --mode json, and one or three or more --skill directories (P2-1); tests red on ffe241789 (#1873, lane pi-skills) --- adapters/README.md | 5 +- adapters/pi/adapter.sh | 2 +- packages/harness/README.md | 28 ++++++----- packages/harness/src/pi-fit.mjs | 65 +++++++++++++++++--------- packages/harness/tests/pi-fit.test.mjs | 47 ++++++++++++++----- 5 files changed, 98 insertions(+), 49 deletions(-) diff --git a/adapters/README.md b/adapters/README.md index 2a2d178c6..f06773b21 100644 --- a/adapters/README.md +++ b/adapters/README.md @@ -115,8 +115,9 @@ does not replace it. With `--skill` alone, a probe with a scratch HOME also loaded the user's skills, the skills a `settings.json` or a listed package names, and `~/.agents/skills` (and the project's, without `--no-approve`). With `--no-skills` first, only the given directories load. A directory that -doesn't exist stops the adapter with exit 2. The fit check runs this shape -in its sealed `-p` run (`packages/harness/README.md`). The fit check runs +doesn't exist stops the adapter with exit 2. The fit check runs this +argv, with two skill directories, one `-e` file and no tools, as its last +`-p` run (`workerShape`, `packages/harness/README.md`). The fit check runs before bus sessions only; worker containers run the pi pinned in the image. ### A role's skills (row 64) diff --git a/adapters/pi/adapter.sh b/adapters/pi/adapter.sh index c78b1e5ef..a28ff67a6 100644 --- a/adapters/pi/adapter.sh +++ b/adapters/pi/adapter.sh @@ -62,7 +62,7 @@ TOOLS_FLAG="--no-tools" # with --skill alone pi also loads the user's skills, settings and package # skills and ~/.agents/skills (a planted-skill probe showed it, offline, with a # scratch HOME). With --no-skills first only the given dirs load. The fit check -# (packages/harness/src/pi-fit.mjs) runs this shape in its sealed -p run. +# (packages/harness/src/pi-fit.mjs) runs this argv as its last -p run (workerShape). # Role sessions never get MOSAIC_SKILLS (ENV_ALLOW in packages/seat/src/ # session.mjs leaves it out), so they run with --no-skills alone; their skills # are text in the system prompt (row 64). diff --git a/packages/harness/README.md b/packages/harness/README.md index a32ddaf71..088fff306 100644 --- a/packages/harness/README.md +++ b/packages/harness/README.md @@ -92,18 +92,24 @@ that no session sets. So a branch on `TZ` or `LC_ALL` being unset, or on `/bin/sh` sets an unset `TERM` to `dumb` for the shell without exporting it, so `${TERM:-}` in the adapter is never empty, in a session or here.) It can't see a branch keyed on a -value it doesn't try (a model, a path, another tool or provider). A last sealed `-p` run uses `--no-session`, as -worker runs do, and one `--skill` directory right after `--no-skills`, as -the adapter passes a worker's `MOSAIC_SKILLS`. Its `-e` extension must -list that skill and no planted one. pi 0.85.1 adds a `--skill` directory -to discovery, so a pi that let `--skill` bring the planted skills back is -refused there, and so is one that drops the `--skill` directory once -`--no-skills` is on. The shape rides on that existing run, so it adds no -run. Each run gets a fresh scratch directory, so no run sees +value it doesn't try (a model, a path, another tool or provider). A last `-p` run is a +headless worker's: the argv the adapter builds with `MOSAIC_SKILLS`, one +`-e` file and no tools (`workerShape`), so `--no-skills` and then two +`--skill` directories, `--no-tools`, `--no-session`, `--provider` and +`--model`. A test runs the adapter and holds its argv to `workerShape`. +The run's `-e` extension must list both skills and no planted one. pi +0.85.1 adds a `--skill` directory to discovery, so a pi that let +`--skill` bring the planted skills back is refused there, and so is one +that drops a `--skill` directory once `--no-skills` is on. This run +replaces the plain sealed `-p` run with `--no-session` and no `--skill`, +so it adds no run. Each run gets a fresh scratch directory, so no run sees what another left. Not run: `--fork` and the interactive TUI -(worker containers and `scripts/agent.sh` only), `--skill` in rpc or -beside a session's flags (no session passes it), more than one `--skill` -directory, the branches three or +(worker containers and `scripts/agent.sh` only), `-p` with +`--no-session` and no `--skill` (a worker without `MOSAIC_SKILLS`; every +bus session passes `--session-dir`), `--skill` beside `--tools`, +`--session-dir`, `-c`, `--thinking` or `--mode json`, or in rpc (a worker +may pass the first two; no bus session passes `--skill`), one or three or +more `--skill` directories, the branches three or four at a time beyond the five runs, `-c` over a session directory that holds nothing for the project (one more run costs about 340 ms cold), and a session's own values (tools beyond `read` and `bash`, thinking diff --git a/packages/harness/src/pi-fit.mjs b/packages/harness/src/pi-fit.mjs index 9076de45f..cb98f6725 100644 --- a/packages/harness/src/pi-fit.mjs +++ b/packages/harness/src/pi-fit.mjs @@ -39,14 +39,16 @@ // planted source. A test drives the adapter through every branch set, tool list // length and thinking level, and fails on an argv sessionShape doesn't build or a // pair no run passes. -// sealed -p the seal flags in -p with --no-session, as a worker run passes them, with one -// --skill directory right after --no-skills, as adapters/pi/adapter.sh passes a -// worker's MOSAIC_SKILLS. Its -e extension must reach session_start and list the -// given skill, and no planted source may show. pi 0.85.1 adds a --skill directory to -// discovery, so a pi that let --skill turn discovery back on, or dropped --no-skills -// beside it, would show the planted skills here; one that ignores --skill once -// --no-skills is on would not list the given skill. This run costs nothing extra: it -// is the -p run the check already made. +// worker -p the arguments adapters/pi/adapter.sh passes for a headless worker run with +// MOSAIC_SKILLS and no tools, in its order (workerShape below): the -e, --no-skills +// then two --skill directories, --no-tools, --no-session, the fixed --provider and +// --model, --system-prompt, -p and a message. Its -e extension must reach +// session_start and list both given skills, and no planted source may show. pi +// 0.85.1 adds a --skill directory to discovery, so a pi that let --skill turn +// discovery back on would show the planted skills here, and one that drops a --skill +// directory once --no-skills is on would not list it. This run replaces the sealed +// -p run the check made before (the seal flags in -p with --no-session and no +// --skill), so it adds no run; that plain shape is not run on its own any more. // missing -e a missing -e file, in rpc and in -p, stops the start: exit non-zero, no answer, // and no session_start for the -e extension given after it // @@ -83,9 +85,11 @@ // // Known limit: pi 0.85.1 appends the agent directory's APPEND_SYSTEM.md whatever the flags. The // check doesn't plant one; a session's agent directory is the run's own. Not run: --fork and -// the interactive TUI, which only worker containers and scripts/agent.sh pass; --skill in rpc or -// beside a session's flags (no session passes it), and more than one --skill directory; the -// session branches three or four at a time beyond the session-shaped +// the interactive TUI, which only worker containers and scripts/agent.sh pass; -p with +// --no-session and no --skill (a worker with no MOSAIC_SKILLS; every bus session passes +// --session-dir); --skill beside --tools, --session-dir, -c, --thinking or --mode json, or in rpc +// (a worker may pass the first two; no bus session passes --skill), and one or three or more +// --skill directories; the session branches three or four at a time beyond the session-shaped // runs; -c over a session directory that holds nothing for the project (the adapter passes -c // whenever the directory isn't empty), since one more run costs about 340 ms cold; and a // session's own values: its tool names beyond read and bash, thinking levels beyond low, @@ -139,6 +143,19 @@ export function sessionShape({ noMcp, extensions, prompt, sessionDir, tools, con "--system-prompt", prompt, "-p", message, ...(json ? ["--mode", "json"] : []), ]; } +// pi-skills: the arguments adapters/pi/adapter.sh builds for a headless worker run (run-task.sh in +// a container) with MOSAIC_SKILLS and no tools: the given -e files, --no-skills and then a --skill +// per directory, --no-tools, --no-session, the --provider and --model, the --system-prompt file, +// -p and the request. Keep its order: pi-fit.test.mjs runs the adapter with MOSAIC_SKILLS and +// fails when the two differ. +export function workerShape({ noMcp, extensions, skills, prompt, message }) { + return [ + "--offline", "--no-approve", "--no-extensions", ...(noMcp ? ["--no-mcp"] : []), ...extensions.flatMap((e) => ["-e", e]), + "--no-skills", ...skills.flatMap((s) => ["--skill", s]), "--no-prompt-templates", "--no-themes", "--no-context-files", + "--no-tools", "--no-session", "--provider", SESSION_SHAPE.provider, "--model", SESSION_SHAPE.model, + "--system-prompt", prompt, "-p", message, + ]; +} // What a session-shaped run is named by in a refusal line. const shapeName = ({ tools, cont, thinking, json }) => `in a session's shape with ${[tools ? "--tools" : "--no-tools", ...(cont ? ["-c"] : []), ...(thinking ? ["--thinking"] : []), ...(json ? ["--mode json"] : [])].join(", ")}`; const RUN_TIMEOUT = 20000; @@ -320,7 +337,7 @@ async function check(found, { levels, bwrap, unshare, node, who, digest, host }) const answer = answered(r.stdout); const start = started(scratch); const listed = start?.commands ?? []; - return { ...r, answer, explicit: marked(scratch, EXPLICIT), second: marked(scratch, SECOND), prompt: start?.prompt ?? null, session: start?.session ?? null, listed: named(listed), skill: names(listed, GIVEN_SKILL), seen: seen(scratch, [...(answer.commands ?? []), ...listed], start) }; + return { ...r, answer, explicit: marked(scratch, EXPLICIT), second: marked(scratch, SECOND), prompt: start?.prompt ?? null, session: start?.session ?? null, listed: named(listed), skills: GIVEN_SKILLS.every((n) => names(listed, n)), seen: seen(scratch, [...(answer.commands ?? []), ...listed], start) }; } finally { // #1873 re-check 10: a run this check killed (a timeout, or stop) may have had bwrap in its // setup, and without unshare's outer layer bwrap's child then waits for good. The run is @@ -386,9 +403,10 @@ async function judge(found, { levels, who, digest, run }) { if (shape.cont) plantSession(s); return sessionShape({ noMcp, extensions: [join(s, "explicit", "fit.ts"), join(s, "explicit", "second.ts")], prompt: join(s, "prompt.md"), sessionDir: join(s, "sessions"), message: "fit check", ...shape }); }, "", { noMcp, shape })]); - // -p takes a message; offline with no key, pi stops before any model call. A worker's shape: the - // seal flags with a --skill directory right after --no-skills, as the adapter puts MOSAIC_SKILLS. - const pRun = run((s) => ["-p", ...seal.flatMap((f) => f === "--no-skills" ? [f, "--skill", join(s, "given", GIVEN_SKILL)] : [f]), ...given(s), "fit check"], "", { noMcp }); + // -p takes a message; offline with no key, pi stops before any model call. A headless worker's + // shape with MOSAIC_SKILLS: two --skill directories right after --no-skills, as the adapter puts + // them. + const pRun = run((s) => workerShape({ noMcp, extensions: [join(s, "explicit", "fit.ts")], skills: GIVEN_SKILLS.map((n) => join(s, "given", n)), prompt: join(s, "prompt.md"), message: "fit check" }), "", { noMcp }); // A missing -e file stops the start. pi 0.85.1 loads the -e files in order and still loads the // one after the missing one, then exits 1 before session_start, so only session_start tells. const missingRuns = [["rpc", ["--mode", "rpc"], ask], ["-p", ["-p"], ""]].map(([mode, args, input]) => @@ -444,10 +462,11 @@ async function judge(found, { levels, who, digest, run }) { } const p = await pRun; - if (p.stopped) return refuse(`can't be checked: a -p start with the seal flags ${p.stopped}`); - if (p.prompt === null) return refuse("can't be checked: a -p start with the seal flags didn't run its -e extension"); - if (p.seen.length) return refuse(`loaded a planted ${p.seen.map((x) => x.source).join(", ")} with the seal flags and a --skill directory on in -p`); - if (!p.skill) return refuse("didn't load a --skill directory with --no-skills on in -p"); + if (p.stopped) return refuse(`can't be checked: the start in a worker's shape ${p.stopped}`); + if (p.prompt === null) return refuse("can't be checked: its -e extension didn't see the system prompt in a worker's shape"); + if (!p.prompt.includes(GIVEN)) return refuse("didn't use the --system-prompt file in a worker's shape"); + if (p.seen.length) return refuse(`loaded a planted ${p.seen.map((x) => x.source).join(", ")} in a worker's shape with --skill`); + if (!p.skills) return refuse("didn't load every --skill directory with --no-skills on in a worker's shape"); for (const [mode, pending] of missingRuns) { const r = await pending; @@ -666,9 +685,9 @@ const GIVEN = "FITGIVENPROMPT"; // pass after it. const EXPLICIT = "explicit extension"; const SECOND = "second explicit extension"; -// The skill the sealed -p run passes with --skill (scratch/given/), outside every place pi -// looks for skills, so it shows only through --skill. It is not planted ambient: not in NAMED. -const GIVEN_SKILL = "fit-given-skill"; +// The skills the worker-shaped run passes with --skill (scratch/given/), outside every place +// pi looks for skills, so they show only through --skill. Not planted ambient: not in NAMED. +const GIVEN_SKILLS = ["fit-given-skill", "fit-second-given-skill"]; // The id of the session a -c run must resume. const PLANTED_SESSION = "fit-planted-session"; const markerName = (source) => source.replace(/[^a-z]/g, "-"); @@ -729,7 +748,7 @@ function plant(scratch) { put(join(project, ".agents", "skills", "fit-agents-skill", "SKILL.md"), skill("fit-agents-skill")); put(join(project, ".pi", "prompts", "fit-project-prompt.md"), prompt); put(join(scratch, "home", ".agents", "skills", "fit-home-skill", "SKILL.md"), skill("fit-home-skill")); - put(join(scratch, "given", GIVEN_SKILL, "SKILL.md"), skill(GIVEN_SKILL)); + for (const n of GIVEN_SKILLS) put(join(scratch, "given", n, "SKILL.md"), skill(n)); for (const [file, text] of TEXTS) put(join(scratch, file), `${text}\n`); put(join(scratch, "explicit", "fit.ts"), `import { writeFileSync } from "node:fs";\nexport default function (pi: any): void {\n writeFileSync(${JSON.stringify(join(marks, markerName(EXPLICIT)))}, "");\n pi.on("session_start", (_event: any, ctx: any) => { writeFileSync(${JSON.stringify(join(marks, "start.json"))}, JSON.stringify({ prompt: ctx.getSystemPrompt(), commands: pi.getCommands().map((c: any) => c.name), session: ctx.sessionManager.getSessionId() })); });\n}\n`); put(join(scratch, "explicit", "second.ts"), ext(SECOND)); diff --git a/packages/harness/tests/pi-fit.test.mjs b/packages/harness/tests/pi-fit.test.mjs index e65cc039e..1e7d26f21 100644 --- a/packages/harness/tests/pi-fit.test.mjs +++ b/packages/harness/tests/pi-fit.test.mjs @@ -124,18 +124,29 @@ test("pi-unpin S3: a stand-in that touches the planted MCP marker under the seal }); // pi-skills: the worker's shape. pi 0.85.1 adds a --skill directory to discovery, so the adapter -// keeps --no-skills in front of each --skill; the fit check's sealed -p run passes that shape. +// keeps --no-skills in front of each --skill; the fit check's -p run passes the adapter's worker +// argv (workerShape) with two --skill directories. test("pi-skills: a stand-in that loads the planted skills once a --skill directory is given is refused", SKIP, async t => { const s = standIn(t, { skillLeak: true }); const problem = await pi.preflight({ env: { ...CREDENTIAL, ...s.env } }); - assert.deepEqual(problem, { code: "harness-feature-missing", message: "pi 2.0.0 (MOSAIC_PI_BIN) loaded a planted user skill, user settings skill, user package skill, project skill, project settings skill, project package skill, project .agents skill, home .agents skill with the seal flags and a --skill directory on in -p" }); + assert.deepEqual(problem, { code: "harness-feature-missing", message: "pi 2.0.0 (MOSAIC_PI_BIN) loaded a planted user skill, user settings skill, user package skill, project skill, project settings skill, project package skill, project .agents skill, home .agents skill in a worker's shape with --skill" }); noPath(problem.message, s.paths); }); test("pi-skills: a stand-in that drops a --skill directory once --no-skills is on is refused", SKIP, async t => { const s = standIn(t, { ignoreSkill: true }); const problem = await pi.preflight({ env: { ...CREDENTIAL, ...s.env } }); - assert.deepEqual(problem, { code: "harness-feature-missing", message: "pi 2.0.0 (MOSAIC_PI_BIN) didn't load a --skill directory with --no-skills on in -p" }); + assert.deepEqual(problem, { code: "harness-feature-missing", message: "pi 2.0.0 (MOSAIC_PI_BIN) didn't load every --skill directory with --no-skills on in a worker's shape" }); + noPath(problem.message, s.paths); +}); + +// Review P3-1: the run is the adapter's worker argv, --provider and --model included, so a pi that +// leaks only once --skill and --provider are both given is seen. +test("pi-skills review: a stand-in that loads the planted sources only with --skill and --provider is refused", SKIP, async t => { + const s = standIn(t, { leakWith: ["--skill", "--provider"] }); + const problem = await pi.preflight({ env: { ...CREDENTIAL, ...s.env } }); + assert.equal(problem.code, "harness-feature-missing"); + assert.match(problem.message, /^pi 2\.0\.0 \(MOSAIC_PI_BIN\) loaded a planted .* in a worker's shape with --skill$/); noPath(problem.message, s.paths); }); @@ -204,19 +215,18 @@ test("pi-unpin S3 re-check 3: every run has its own scratch directory, and the r const shaped = (args) => args.includes("--session-dir"); assert.deepEqual(runs.filter((x) => shaped(x.args)).map((x) => JSON.stringify(x.args)).sort(), shapes.map((shape) => JSON.stringify(fitModule.sessionShape({ noMcp: extraFlags.length > 0, extensions: ["/explicit/fit.ts", "/explicit/second.ts"], prompt: "/prompt.md", sessionDir: "/sessions", message: "fit check", ...shape }))).sort()); const flagLists = []; - // pi-skills: the sealed -p run is a worker's shape, with one --skill directory right after - // --no-skills, as the adapter passes MOSAIC_SKILLS. No other run passes --skill. + // pi-skills: the -p run is the adapter's worker argv with two --skill directories, built by + // workerShape, which the adapter test below holds to the adapter. No other run passes --skill. const skilled = runs.filter((x) => x.args.includes("--skill")); assert.equal(skilled.length, 1); - assert.deepEqual(skilled[0].args, ["-p", ...seal.flatMap((f) => f === "--no-skills" ? [f, "--skill", "/given/fit-given-skill"] : [f]), "-e", "/explicit/fit.ts", "--system-prompt", "/prompt.md", "fit check"]); - for (const { args } of runs.filter((x) => x.args.length > 1 && !shaped(x.args))) { + assert.deepEqual(skilled[0].args, fitModule.workerShape({ noMcp: extraFlags.length > 0, extensions: ["/explicit/fit.ts"], skills: ["/given/fit-given-skill", "/given/fit-second-given-skill"], prompt: "/prompt.md", message: "fit check" })); + for (const { args } of runs.filter((x) => x.args.length > 1 && !shaped(x.args) && !x.args.includes("--skill"))) { const flags = args.filter((a) => seal.includes(a)); assert.deepEqual(flags, seal.filter((f) => flags.includes(f)), "the seal flags keep their order"); const rest = []; for (let i = 0; i < args.length; i++) { if (args[i] === "--mode") { i++; continue; } if (args[i] === "-e" && args[i + 1] === "/missing/extension.ts") { i++; continue; } - if (args[i] === "--skill" && args[i + 1] === "/given/fit-given-skill") { i++; continue; } if (args[i] === "-p" || seal.includes(args[i]) || (args.includes("-p") && i === args.length - 1)) continue; rest.push(args[i]); } @@ -885,9 +895,9 @@ test("pi-unpin S3: real pi 0.85.1 from node_modules is accepted, and the event l assert.ok(max <= GAP_MAX, `the event loop waited ${max.toFixed(0)} ms during the cold check`); }); -// pi-skills: real pi passes the fit check's worker shape, the sealed -p run with --no-skills and a -// --skill directory: it lists the given skill and no planted one. A logging bwrap shows the run. -test("pi-skills: real pi 0.85.1 passes the fit check's sealed -p run with --no-skills and a --skill directory", SKIP, async t => { +// pi-skills: real pi passes the fit check's worker-shaped -p run, --no-skills and two --skill +// directories: it lists both given skills and no planted one. A logging bwrap shows the run. +test("pi-skills: real pi 0.85.1 passes the fit check's worker-shaped run with --no-skills and two --skill directories", SKIP, async t => { const found = locate({ PATH: "/usr/bin:/bin" }); const root = mkdtempSync(join(tmpdir(), "mosaic-pi-skills-fit-")); t.after(() => rmSync(root, { recursive: true, force: true })); @@ -901,7 +911,8 @@ test("pi-skills: real pi 0.85.1 passes the fit check's sealed -p run with --no-s const a = skilled[0]; assert.equal(a[a.indexOf("--no-skills") + 1], "--skill"); assert.match(a[a.indexOf("--skill") + 1], /\/given\/fit-given-skill$/); - assert.ok(a.includes("-p") && a.includes("--no-session")); + assert.match(a[a.indexOf("--skill") + 3], /\/given\/fit-second-given-skill$/); + for (const f of ["-p", "--no-session", "--provider", "--model"]) assert.ok(a.includes(f), f); }); test("pi-unpin S3 re-check 7: the event loop stays live while a stand-in's cold check runs", SKIP, async t => { @@ -1030,6 +1041,18 @@ test("pi-skills: with MOSAIC_SKILLS the adapter passes --no-skills, then --skill assert.ok(!bare.argv().includes("--skill")); }); +// Review P3-1: the fit check's worker-shaped run is the argv the adapter builds for a headless +// worker with MOSAIC_SKILLS, an -e file and no tools, flag for flag and in order. +test("pi-skills review: the adapter's worker argv with MOSAIC_SKILLS is workerShape's", t => { + const w = workerAdapter(t, (root) => { + for (const n of ["one", "two"]) mkdirSync(join(root, "skills", n), { recursive: true }); + writeFileSync(join(root, "fit.ts"), ""); + return { MOSAIC_SKILLS: `${join(root, "skills", "one")},${join(root, "skills", "two")}`, MOSAIC_EXTENSIONS: join(root, "fit.ts"), PI_PROVIDER: fitModule.SESSION_SHAPE.provider, PI_MODEL: fitModule.SESSION_SHAPE.model }; + }); + assert.equal(w.r.status, 0, w.r.stderr); + assert.deepEqual(w.argv(), fitModule.workerShape({ noMcp: false, extensions: [join(w.root, "fit.ts")], skills: [join(w.root, "skills", "one"), join(w.root, "skills", "two")], prompt: join(w.root, "prompt.md"), message: "x" })); +}); + test("pi-skills: a missing MOSAIC_SKILLS directory still exits 2 before pi runs", t => { const w = workerAdapter(t, (root) => { mkdirSync(join(root, "skills", "one"), { recursive: true }); -- 2.54.0 From ca7388743b31c8dd4a32fbabe3bdc167e3a2f44f Mon Sep 17 00:00:00 2001 From: Jason Woltje Date: Fri, 20 Nov 2026 04:24:33 -0600 Subject: [PATCH 3/3] fix(adapters,harness): pi-skills re-check: the docs no longer call the fit check's last -p run a headless worker's argv, since task launches refuse skill directories and set MOSAIC_SKILLS empty (packages/processing-control containers.mjs) and only the interactive launch (scripts/agent.sh) sets it, in the TUI with --tools and --session-dir; the run is now named the nearest headless form of the adapter's --skill argv, and the Not run notes name the TUI launch's flags and --skill with no -e (R2-P2-1, R2-P3-1); the untested --system-prompt check added to that run is dropped, as at BASE (R2-P3-2) (#1873, lane pi-skills) --- adapters/README.md | 13 +++++--- adapters/pi/adapter.sh | 3 +- packages/harness/README.md | 21 +++++++----- packages/harness/src/pi-fit.mjs | 46 ++++++++++++++------------ packages/harness/tests/pi-fit.test.mjs | 16 ++++----- 5 files changed, 56 insertions(+), 43 deletions(-) diff --git a/adapters/README.md b/adapters/README.md index f06773b21..6faf72d30 100644 --- a/adapters/README.md +++ b/adapters/README.md @@ -108,16 +108,19 @@ activity through its existing extension. Mock remains a test-only echo. ### A worker's skills (M17, #1873) -Worker runs and `scripts/agent.sh` may set `MOSAIC_SKILLS`, a comma list of -skill directories. The pi adapter passes `--no-skills` and then +`MOSAIC_SKILLS` is a comma list of skill directories. Today only the +interactive container launch (`scripts/agent.sh`) sets it; task launches +refuse skill directories and set it empty +(`packages/processing-control/src/containers.mjs`). The pi adapter passes `--no-skills` and then `--skill ` for each one. On pi 0.85.1 `--skill` adds to discovery and does not replace it. With `--skill` alone, a probe with a scratch HOME also loaded the user's skills, the skills a `settings.json` or a listed package names, and `~/.agents/skills` (and the project's, without `--no-approve`). With `--no-skills` first, only the given directories load. A directory that -doesn't exist stops the adapter with exit 2. The fit check runs this -argv, with two skill directories, one `-e` file and no tools, as its last -`-p` run (`workerShape`, `packages/harness/README.md`). The fit check runs +doesn't exist stops the adapter with exit 2. The fit check runs the +headless form of this argv, with two skill directories, one `-e` file, no +tools and no session, as its last `-p` run (`workerShape`, +`packages/harness/README.md`); the TUI shape the launch uses is not run. The fit check runs before bus sessions only; worker containers run the pi pinned in the image. ### A role's skills (row 64) diff --git a/adapters/pi/adapter.sh b/adapters/pi/adapter.sh index a28ff67a6..f9f11d942 100644 --- a/adapters/pi/adapter.sh +++ b/adapters/pi/adapter.sh @@ -62,7 +62,8 @@ TOOLS_FLAG="--no-tools" # with --skill alone pi also loads the user's skills, settings and package # skills and ~/.agents/skills (a planted-skill probe showed it, offline, with a # scratch HOME). With --no-skills first only the given dirs load. The fit check -# (packages/harness/src/pi-fit.mjs) runs this argv as its last -p run (workerShape). +# (packages/harness/src/pi-fit.mjs) runs its -p form as its last run (workerShape). +# Only the interactive launch (scripts/agent.sh) sets MOSAIC_SKILLS today. # Role sessions never get MOSAIC_SKILLS (ENV_ALLOW in packages/seat/src/ # session.mjs leaves it out), so they run with --no-skills alone; their skills # are text in the system prompt (row 64). diff --git a/packages/harness/README.md b/packages/harness/README.md index 088fff306..6ca7e0291 100644 --- a/packages/harness/README.md +++ b/packages/harness/README.md @@ -92,11 +92,15 @@ that no session sets. So a branch on `TZ` or `LC_ALL` being unset, or on `/bin/sh` sets an unset `TERM` to `dumb` for the shell without exporting it, so `${TERM:-}` in the adapter is never empty, in a session or here.) It can't see a branch keyed on a -value it doesn't try (a model, a path, another tool or provider). A last `-p` run is a -headless worker's: the argv the adapter builds with `MOSAIC_SKILLS`, one -`-e` file and no tools (`workerShape`), so `--no-skills` and then two +value it doesn't try (a model, a path, another tool or provider). A last `-p` run is the +argv the adapter builds in `-p` with `MOSAIC_SKILLS`, one `-e` file, no +tools and no session (`workerShape`), so `--no-skills` and then two `--skill` directories, `--no-tools`, `--no-session`, `--provider` and `--model`. A test runs the adapter and holds its argv to `workerShape`. +No caller makes this exact run today: task launches refuse skill +directories, and only the interactive launch (`scripts/agent.sh`) sets +`MOSAIC_SKILLS`, in the TUI, which no fit run can drive. It is the +nearest headless form of the adapter's `--skill` argv. The run's `-e` extension must list both skills and no planted one. pi 0.85.1 adds a `--skill` directory to discovery, so a pi that let `--skill` bring the planted skills back is refused there, and so is one @@ -105,11 +109,12 @@ replaces the plain sealed `-p` run with `--no-session` and no `--skill`, so it adds no run. Each run gets a fresh scratch directory, so no run sees what another left. Not run: `--fork` and the interactive TUI (worker containers and `scripts/agent.sh` only), `-p` with -`--no-session` and no `--skill` (a worker without `MOSAIC_SKILLS`; every -bus session passes `--session-dir`), `--skill` beside `--tools`, -`--session-dir`, `-c`, `--thinking` or `--mode json`, or in rpc (a worker -may pass the first two; no bus session passes `--skill`), one or three or -more `--skill` directories, the branches three or +`--no-session` and no `--skill` (a task launch's shape; every bus session +passes `--session-dir`), `--skill` beside `--tools`, `--session-dir`, +`-c`, `--thinking` or `--mode json`, or in rpc (the TUI launch passes the +first three; no bus session passes `--skill`), `--skill` with no `-e` +(every fit run needs its `-e` extension to see what loaded), one or three +or more `--skill` directories, the branches three or four at a time beyond the five runs, `-c` over a session directory that holds nothing for the project (one more run costs about 340 ms cold), and a session's own values (tools beyond `read` and `bash`, thinking diff --git a/packages/harness/src/pi-fit.mjs b/packages/harness/src/pi-fit.mjs index cb98f6725..8a2e72b5b 100644 --- a/packages/harness/src/pi-fit.mjs +++ b/packages/harness/src/pi-fit.mjs @@ -39,16 +39,21 @@ // planted source. A test drives the adapter through every branch set, tool list // length and thinking level, and fails on an argv sessionShape doesn't build or a // pair no run passes. -// worker -p the arguments adapters/pi/adapter.sh passes for a headless worker run with -// MOSAIC_SKILLS and no tools, in its order (workerShape below): the -e, --no-skills -// then two --skill directories, --no-tools, --no-session, the fixed --provider and -// --model, --system-prompt, -p and a message. Its -e extension must reach -// session_start and list both given skills, and no planted source may show. pi -// 0.85.1 adds a --skill directory to discovery, so a pi that let --skill turn +// worker -p the arguments adapters/pi/adapter.sh builds in -p with MOSAIC_SKILLS, one -e +// file, no tools and no session, in its order (workerShape below): the -e, +// --no-skills then two --skill directories, --no-tools, --no-session, the fixed +// --provider and --model, --system-prompt, -p and a message. Its -e extension must +// reach session_start and list both given skills, and no planted source may show. +// pi 0.85.1 adds a --skill directory to discovery, so a pi that let --skill turn // discovery back on would show the planted skills here, and one that drops a --skill -// directory once --no-skills is on would not list it. This run replaces the sealed -// -p run the check made before (the seal flags in -p with --no-session and no -// --skill), so it adds no run; that plain shape is not run on its own any more. +// directory once --no-skills is on would not list it. No caller makes this exact +// run today: task launches refuse skill directories (packages/processing-control +// containers.mjs), and only the interactive container launch (scripts/agent.sh) +// sets MOSAIC_SKILLS, in the TUI with --tools and --session-dir, which no fit run +// can drive. This is the nearest headless form of the adapter's --skill argv. It +// replaces the sealed -p run the check made before (the seal flags in -p with +// --no-session and no --skill), so it adds no run; that plain shape is not run on +// its own any more. // missing -e a missing -e file, in rpc and in -p, stops the start: exit non-zero, no answer, // and no session_start for the -e extension given after it // @@ -86,10 +91,11 @@ // Known limit: pi 0.85.1 appends the agent directory's APPEND_SYSTEM.md whatever the flags. The // check doesn't plant one; a session's agent directory is the run's own. Not run: --fork and // the interactive TUI, which only worker containers and scripts/agent.sh pass; -p with -// --no-session and no --skill (a worker with no MOSAIC_SKILLS; every bus session passes -// --session-dir); --skill beside --tools, --session-dir, -c, --thinking or --mode json, or in rpc -// (a worker may pass the first two; no bus session passes --skill), and one or three or more -// --skill directories; the session branches three or four at a time beyond the session-shaped +// --no-session and no --skill (a task launch's shape; every bus session passes --session-dir); +// --skill beside --tools, --session-dir, -c, --thinking or --mode json, or in rpc (the TUI +// launch passes the first three; no bus session passes --skill); --skill with no -e (every fit +// run needs its -e extension to see what loaded); one or three or more --skill directories; the +// session branches three or four at a time beyond the session-shaped // runs; -c over a session directory that holds nothing for the project (the adapter passes -c // whenever the directory isn't empty), since one more run costs about 340 ms cold; and a // session's own values: its tool names beyond read and bash, thinking levels beyond low, @@ -143,10 +149,10 @@ export function sessionShape({ noMcp, extensions, prompt, sessionDir, tools, con "--system-prompt", prompt, "-p", message, ...(json ? ["--mode", "json"] : []), ]; } -// pi-skills: the arguments adapters/pi/adapter.sh builds for a headless worker run (run-task.sh in -// a container) with MOSAIC_SKILLS and no tools: the given -e files, --no-skills and then a --skill -// per directory, --no-tools, --no-session, the --provider and --model, the --system-prompt file, -// -p and the request. Keep its order: pi-fit.test.mjs runs the adapter with MOSAIC_SKILLS and +// pi-skills: the arguments adapters/pi/adapter.sh builds in -p with MOSAIC_SKILLS, no tools and no +// session: the given -e files, --no-skills and then a --skill per directory, --no-tools, +// --no-session, the --provider and --model, the --system-prompt file, -p and the request. Only +// the interactive launch sets MOSAIC_SKILLS today, in the TUI; this is the nearest headless form. Keep its order: pi-fit.test.mjs runs the adapter with MOSAIC_SKILLS and // fails when the two differ. export function workerShape({ noMcp, extensions, skills, prompt, message }) { return [ @@ -403,9 +409,8 @@ async function judge(found, { levels, who, digest, run }) { if (shape.cont) plantSession(s); return sessionShape({ noMcp, extensions: [join(s, "explicit", "fit.ts"), join(s, "explicit", "second.ts")], prompt: join(s, "prompt.md"), sessionDir: join(s, "sessions"), message: "fit check", ...shape }); }, "", { noMcp, shape })]); - // -p takes a message; offline with no key, pi stops before any model call. A headless worker's - // shape with MOSAIC_SKILLS: two --skill directories right after --no-skills, as the adapter puts - // them. + // -p takes a message; offline with no key, pi stops before any model call. The adapter's -p argv + // with MOSAIC_SKILLS: two --skill directories right after --no-skills, as the adapter puts them. const pRun = run((s) => workerShape({ noMcp, extensions: [join(s, "explicit", "fit.ts")], skills: GIVEN_SKILLS.map((n) => join(s, "given", n)), prompt: join(s, "prompt.md"), message: "fit check" }), "", { noMcp }); // A missing -e file stops the start. pi 0.85.1 loads the -e files in order and still loads the // one after the missing one, then exits 1 before session_start, so only session_start tells. @@ -464,7 +469,6 @@ async function judge(found, { levels, who, digest, run }) { const p = await pRun; if (p.stopped) return refuse(`can't be checked: the start in a worker's shape ${p.stopped}`); if (p.prompt === null) return refuse("can't be checked: its -e extension didn't see the system prompt in a worker's shape"); - if (!p.prompt.includes(GIVEN)) return refuse("didn't use the --system-prompt file in a worker's shape"); if (p.seen.length) return refuse(`loaded a planted ${p.seen.map((x) => x.source).join(", ")} in a worker's shape with --skill`); if (!p.skills) return refuse("didn't load every --skill directory with --no-skills on in a worker's shape"); diff --git a/packages/harness/tests/pi-fit.test.mjs b/packages/harness/tests/pi-fit.test.mjs index 1e7d26f21..f85f0106e 100644 --- a/packages/harness/tests/pi-fit.test.mjs +++ b/packages/harness/tests/pi-fit.test.mjs @@ -124,8 +124,8 @@ test("pi-unpin S3: a stand-in that touches the planted MCP marker under the seal }); // pi-skills: the worker's shape. pi 0.85.1 adds a --skill directory to discovery, so the adapter -// keeps --no-skills in front of each --skill; the fit check's -p run passes the adapter's worker -// argv (workerShape) with two --skill directories. +// keeps --no-skills in front of each --skill; the fit check's last -p run passes the adapter's -p +// argv with MOSAIC_SKILLS (workerShape) and two --skill directories. test("pi-skills: a stand-in that loads the planted skills once a --skill directory is given is refused", SKIP, async t => { const s = standIn(t, { skillLeak: true }); const problem = await pi.preflight({ env: { ...CREDENTIAL, ...s.env } }); @@ -140,7 +140,7 @@ test("pi-skills: a stand-in that drops a --skill directory once --no-skills is o noPath(problem.message, s.paths); }); -// Review P3-1: the run is the adapter's worker argv, --provider and --model included, so a pi that +// Review P3-1: the run is the adapter's -p argv, --provider and --model included, so a pi that // leaks only once --skill and --provider are both given is seen. test("pi-skills review: a stand-in that loads the planted sources only with --skill and --provider is refused", SKIP, async t => { const s = standIn(t, { leakWith: ["--skill", "--provider"] }); @@ -215,7 +215,7 @@ test("pi-unpin S3 re-check 3: every run has its own scratch directory, and the r const shaped = (args) => args.includes("--session-dir"); assert.deepEqual(runs.filter((x) => shaped(x.args)).map((x) => JSON.stringify(x.args)).sort(), shapes.map((shape) => JSON.stringify(fitModule.sessionShape({ noMcp: extraFlags.length > 0, extensions: ["/explicit/fit.ts", "/explicit/second.ts"], prompt: "/prompt.md", sessionDir: "/sessions", message: "fit check", ...shape }))).sort()); const flagLists = []; - // pi-skills: the -p run is the adapter's worker argv with two --skill directories, built by + // pi-skills: the last -p run is the adapter's -p argv with two --skill directories, built by // workerShape, which the adapter test below holds to the adapter. No other run passes --skill. const skilled = runs.filter((x) => x.args.includes("--skill")); assert.equal(skilled.length, 1); @@ -1041,9 +1041,9 @@ test("pi-skills: with MOSAIC_SKILLS the adapter passes --no-skills, then --skill assert.ok(!bare.argv().includes("--skill")); }); -// Review P3-1: the fit check's worker-shaped run is the argv the adapter builds for a headless -// worker with MOSAIC_SKILLS, an -e file and no tools, flag for flag and in order. -test("pi-skills review: the adapter's worker argv with MOSAIC_SKILLS is workerShape's", t => { +// Review P3-1: the fit check's worker-shaped run is the argv the adapter builds in -p with +// MOSAIC_SKILLS, an -e file, no tools and no session, flag for flag and in order. +test("pi-skills review: the adapter's -p argv with MOSAIC_SKILLS is workerShape's", t => { const w = workerAdapter(t, (root) => { for (const n of ["one", "two"]) mkdirSync(join(root, "skills", n), { recursive: true }); writeFileSync(join(root, "fit.ts"), ""); @@ -1063,7 +1063,7 @@ test("pi-skills: a missing MOSAIC_SKILLS directory still exits 2 before pi runs" assert.equal(existsSync(join(w.root, "argv")), false, "pi did not run"); }); -// pi-skills: the worker's shape end to end. The adapter runs real pi 0.85.1 with MOSAIC_SKILLS, an +// pi-skills: the adapter's -p shape end to end. It runs real pi 0.85.1 with MOSAIC_SKILLS, an // -e extension that writes the command names at session_start, a HOME and workspace holding planted // skills in every place pi 0.85.1 looks, the network unshared and no key: pi stops before any model // call. Only the given skills may load. On the adapter that dropped --no-skills, the user, settings -- 2.54.0