Compare commits

...
Author SHA1 Message Date
jason.woltje ca7388743b 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) 2026-11-20 04:30:23 -06:00
jason.woltje 59af86a5ee 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) 2026-11-20 04:30:23 -06:00
jason.woltje d6d3271808 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) 2026-11-20 04:30:23 -06:00
6 changed files with 247 additions and 22 deletions

No files matched your search

+17
View File
@@ -106,6 +106,23 @@ 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)
`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 <dir>` 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 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)
A managed session's skills reach both adapters as text in the bundle's
+9 -4
View File
@@ -57,14 +57,18 @@ 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 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; 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 +116,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 <dir> 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)
+23 -4
View File
@@ -92,10 +92,29 @@ 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. 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
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
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), `-p` with
`--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
+50 -12
View File
@@ -39,8 +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.
// 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.
// 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. 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
//
@@ -76,9 +89,13 @@
// 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; -p with
// --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,
@@ -132,6 +149,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 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 [
"--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;
@@ -313,7 +343,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), 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
@@ -379,8 +409,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. 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.
const missingRuns = [["rpc", ["--mode", "rpc"], ask], ["-p", ["-p"], ""]].map(([mode, args, input]) =>
@@ -436,9 +467,10 @@ 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.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.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;
@@ -657,6 +689,9 @@ const GIVEN = "FITGIVENPROMPT";
// pass after it.
const EXPLICIT = "explicit extension";
const SECOND = "second explicit extension";
// The skills the worker-shaped run passes with --skill (scratch/given/<name>), 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, "-");
@@ -669,8 +704,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 +752,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"));
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));
+142 -1
View File
@@ -123,6 +123,33 @@ 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 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 } });
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 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 -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"] });
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);
});
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,7 +215,12 @@ 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: ["<s>/explicit/fit.ts", "<s>/explicit/second.ts"], prompt: "<s>/prompt.md", sessionDir: "<s>/sessions", message: "fit check", ...shape }))).sort());
const flagLists = [];
for (const { args } of runs.filter((x) => x.args.length > 1 && !shaped(x.args))) {
// 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);
assert.deepEqual(skilled[0].args, fitModule.workerShape({ noMcp: extraFlags.length > 0, extensions: ["<s>/explicit/fit.ts"], skills: ["<s>/given/fit-given-skill", "<s>/given/fit-second-given-skill"], prompt: "<s>/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 = [];
@@ -863,6 +895,26 @@ 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-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 }));
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.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 => {
const { result, max } = await gapDuring(() => fit(standIn(t, {}).env));
assert.equal(result.ok, true, result.message);
@@ -957,6 +1009,95 @@ 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"));
});
// 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"), "");
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 });
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 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
// 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
+6 -1
View File
@@ -54,6 +54,10 @@
// no commands.
// `commands` "fail" answers get_commands with success false; "list" answers
// with a bare list.
// --skill <dir> 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" });