Skip to content

armgit / qm

Public Imported from GitHub
0

Multiplayer agent harness for work.

Materialize skill contents only on explicit access (#1325)

Regan Bell743b5c0dd248
diff --git a/scripts/skills-materialize-smoke.ts b/scripts/skills-materialize-smoke.ts
index 520df4b0e..18aefe677 100644
--- a/scripts/skills-materialize-smoke.ts
+++ b/scripts/skills-materialize-smoke.ts
@@ -5,7 +5,7 @@ import { createSpritesSandbox } from "../src/sandbox/sprites-sandbox.ts";
import { createLocalWorkspaceStore } from "../src/workspace/workspace-store.ts";
import { scopeId } from "../src/types.ts";
import { loadConfig } from "../src/config.ts";
-import { materializeSkillIndex, materializeSkillTree } from "../src/skills/materialize.ts";
+import { reconcileSkillIndex, materializeSkillTree } from "../src/skills/materialize.ts";
import { computeBundleHash, type SkillBundle } from "../src/skills/skill-bundle-store.ts";
import type { SkillFile, SkillResolution } from "../src/skills/skill-store.ts";
@@ -40,15 +40,15 @@ try {
]);
const light = res("plain-skill", "# Plain\njust instructions");
- console.log("materializeSkillIndex (eager, bodies only) …");
- await materializeSkillIndex(sb, h, [heavy, light]);
- assert((await sb.readFile(h, "skills/popular-web-designs/SKILL.md"))?.includes("entry point"), "heavy SKILL.md laid");
- assert((await sb.readFile(h, "skills/plain-skill/SKILL.md"))?.includes("just instructions"), "light SKILL.md laid");
+ console.log("reconcileSkillIndex (ownership only) …");
+ await reconcileSkillIndex(sb, h, [heavy, light]);
+ assert((await sb.readFile(h, "skills/popular-web-designs/SKILL.md")) === null, "heavy body stays in core");
+ assert((await sb.readFile(h, "skills/plain-skill/SKILL.md")) === null, "unused body stays in core");
assert(
(await sb.readFile(h, "skills/popular-web-designs/scripts/render.py")) === null,
"asset NOT laid by index (lazy)",
);
- console.log(" ok: bodies present, assets absent");
+ console.log(" ok: no skill content copied");
console.log("materializeSkillTree (lazy, assets + bundle, one tar) …");
const b = bundle("pack1", [{ path: "lib/cite.mjs", content: "export const cite = 1\n" }]);
@@ -61,7 +61,10 @@ try {
(await sb.readFile(h, "skills/popular-web-designs/references/catalog.md"))?.includes("catalog"),
"ref laid lazily",
);
- assert((await sb.readFile(h, "lib/cite.mjs"))?.includes("cite"), "pack bundle overlaid at repo-relative path");
+ assert(
+ (await sb.readFile(h, "skills/.packs/pack1/lib/cite.mjs"))?.includes("cite"),
+ "pack bundle overlaid at repo-relative path",
+ );
assert((await sb.readFile(h, "skills/popular-web-designs/.tree")) !== null, "tree marker written");
console.log(" ok: assets + bundle landed via tar");
diff --git a/src/core/orchestrator/sandboxes.ts b/src/core/orchestrator/sandboxes.ts
index 644a577bb..27f3f18ae 100644
--- a/src/core/orchestrator/sandboxes.ts
+++ b/src/core/orchestrator/sandboxes.ts
@@ -302,15 +302,7 @@ export function createTurnSandboxes(ctx: TurnSandboxContext) {
emit("proc_reconcile", procReconcileStart, Date.now());
}
}
- if (deps.skills) {
- const materializeStart = Date.now();
- try {
- await skillMaterializer.materializeIndex(deps.sandbox, handle, visibleSkills, visibleSkillsForTurn);
- } finally {
- emit("skills_materialize", materializeStart, Date.now());
- box.materializeMs = Date.now() - materializeStart;
- }
- }
+ if (deps.skills) await skillMaterializer.reconcileIndex(deps.sandbox, handle, visibleSkills, visibleSkillsForTurn);
box.handle = handle;
return handle;
};
@@ -370,9 +362,12 @@ export function createTurnSandboxes(ctx: TurnSandboxContext) {
const ensureSkillTree = async (skillDir: string, sandboxId?: string): Promise<void> => {
const current = await visibleSkillsForTurn();
const requested = current.filter(
- (r) => r.skill && (skillDir === ".packs" ? r.skill.pack : r.skill.manifest.name === skillDir),
+ (r) =>
+ r.skill &&
+ (skillDir.startsWith(".packs/")
+ ? r.skill.pack?.packId === skillDir.slice(".packs/".length)
+ : r.skill.manifest.name === skillDir),
);
- if (!requested.length) return;
const handle = sandboxId ? await provisionResource(sandboxId) : await provision();
for (const r of requested) {
await materializeSkillTree(handle, r, sandboxId);
@@ -398,7 +393,7 @@ export function createTurnSandboxes(ctx: TurnSandboxContext) {
await prepareCredentials(handle, emitGapWork);
await prepareTurnFiles(handle);
if (deps.skills)
- await skillMaterializer.materializeIndex(deps.sandbox, handle, visibleSkills, visibleSkillsForTurn);
+ await skillMaterializer.reconcileIndex(deps.sandbox, handle, visibleSkills, visibleSkillsForTurn);
resourceHandles.set(id, handle);
resourcePendingHandles.delete(id);
return handle;
diff --git a/src/skills/materialize.ts b/src/skills/materialize.ts
index 90b848775..d4cba9709 100644
--- a/src/skills/materialize.ts
+++ b/src/skills/materialize.ts
@@ -18,7 +18,7 @@ const SKILL_PACKS_DIR = `${SKILLS_DIR}/.packs`;
export { SKILLS_DIR } from "./materialization-paths.ts";
export interface SkillMaterializer {
- materializeIndex(
+ reconcileIndex(
sandbox: Sandbox,
handle: SandboxHandle,
resolved: SkillResolution[],
@@ -46,7 +46,7 @@ function indexHash(resolved: SkillResolution[]): string {
const h = createHash("sha256");
const entries = resolved
.filter((r) => r.skill)
- .map((r) => `${r.skill!.manifest.name}\0${r.skill!.scopeId}\0${r.skill!.id}\0${renderSkillBody(r)}`)
+ .map((r) => `${r.skill!.manifest.name}\0${r.skill!.scopeId}\0${r.skill!.id}`)
.sort();
for (const e of entries) {
h.update(e);
@@ -213,7 +213,7 @@ async function layFiles(sandbox: Sandbox, handle: SandboxHandle, entries: LayEnt
for (const e of entries) await sandbox.writeFile(handle, e.path, e.content);
}
-async function materializeSkillIndexUnlocked(
+async function reconcileSkillIndexUnlocked(
sandbox: Sandbox,
handle: SandboxHandle,
resolved: SkillResolution[],
@@ -261,13 +261,6 @@ async function materializeSkillIndexUnlocked(
}
const entries: LayEntry[] = [];
- for (const r of resolved) {
- if (!r.skill) continue;
- entries.push({
- path: `${SKILLS_DIR}/${safeSkillDirName(r.skill.manifest.name)}/SKILL.md`,
- content: renderSkillBody(r),
- });
- }
entries.push({
path: INDEX_MARKER,
content: JSON.stringify({
@@ -377,10 +370,10 @@ export function createSkillMaterializer(advisoryLock?: AdvisoryLock): SkillMater
return queue(key, () => advisoryLock?.withLock(key, fn) ?? fn());
};
return {
- materializeIndex(sandbox, handle, resolved, current) {
+ reconcileIndex(sandbox, handle, resolved, current) {
return locked(handle, async () => {
const latest = current ? await current() : resolved;
- await materializeSkillIndexUnlocked(sandbox, handle, latest);
+ await reconcileSkillIndexUnlocked(sandbox, handle, latest);
});
},
materializeTree(sandbox, handle, resolution, bundles = [], current) {
@@ -394,12 +387,12 @@ export function createSkillMaterializer(advisoryLock?: AdvisoryLock): SkillMater
const localMaterializer = createSkillMaterializer();
-export function materializeSkillIndex(
+export function reconcileSkillIndex(
sandbox: Sandbox,
handle: SandboxHandle,
resolved: SkillResolution[],
): Promise<void> {
- return localMaterializer.materializeIndex(sandbox, handle, resolved);
+ return localMaterializer.reconcileIndex(sandbox, handle, resolved);
}
export function materializeSkillTree(
diff --git a/src/tools/primitives.ts b/src/tools/primitives.ts
index 8d7a8bf80..0689bec3b 100644
--- a/src/tools/primitives.ts
+++ b/src/tools/primitives.ts
@@ -77,13 +77,14 @@ import type { CapabilityClaims } from "../auth/capability-token.ts";
import type { VisibleCron } from "../api/app.ts";
import { createPlaygroundArtifact, type PlaygroundArtifact } from "../playgrounds/playground.ts";
-const SKILL_FILE_RE = /^(?:\.\/)?skills\/([^/]+)\/.+$/;
+const SKILL_FILE_RE = /^(?:\.\/)?skills\/(\.packs\/[^/]+|[^/]+)\/.+$/;
function skillTreeDirFor(path: string): string | null {
const m = SKILL_FILE_RE.exec(path);
return m ? m[1]! : null;
}
-const SKILL_DIR_IN_COMMAND_RE = /(?:^|[\s'"=(&|;])(?:\.\/)?skills\/([^/\s'"&|;)]+)(?=[/\s'"&|;)]|$)/g;
+const SKILL_DIR_IN_COMMAND_RE =
+ /(?:^|[\s'"=(&|;])(?:\.\/)?skills\/(\.packs\/[^/\s'"&|;)]+|[^/\s'"&|;)]+)(?=[/\s'"&|;)]|$)/g;
function skillTreeDirsInCommand(command: string): string[] {
const dirs = new Set<string>();
for (const m of command.matchAll(SKILL_DIR_IN_COMMAND_RE)) dirs.add(m[1]!);
diff --git a/test/skills-callable.test.ts b/test/skills-callable.test.ts
index ce362c70f..5b14bee5e 100644
--- a/test/skills-callable.test.ts
+++ b/test/skills-callable.test.ts
@@ -69,29 +69,45 @@ test("a channel session does NOT see a personal skill (scope boundary)", async (
assert.doesNotMatch(sys.reply ?? "", /make-digest/);
});
-test("the next provision reconciles the index after the last visible skill is archived", async () => {
+test("ordinary sandbox work reconciles ownership without copying skill contents", async () => {
const { app, skills, sandbox } = freshApp();
- const skill = await publishPersonalSkill(skills);
- await app.turn({
- surface: "test",
- actor,
- conversation: { kind: "dm", threadRef: "dm:U1:cleanup-1" },
- text: "!read skills/make-digest/SKILL.md",
- } as TurnRequest);
-
- const removed: string[] = [];
- const originalRemove = sandbox.removeDir.bind(sandbox);
+ await publishPersonalSkill(skills);
+ const touched: string[] = [];
+ const read = sandbox.readFile.bind(sandbox);
+ sandbox.readFile = async (handle, path) => {
+ if (path.startsWith("skills/")) touched.push(path);
+ return read(handle, path);
+ };
+ const write = sandbox.writeFile.bind(sandbox);
+ sandbox.writeFile = async (handle, path, content) => {
+ if (path.startsWith("skills/")) touched.push(path);
+ return write(handle, path, content);
+ };
+ const remove = sandbox.removeDir.bind(sandbox);
sandbox.removeDir = async (handle, path) => {
- removed.push(path);
- await originalRemove(handle, path);
+ if (path.startsWith("skills/")) touched.push(path);
+ return remove(handle, path);
};
- await skills.archive(skill.id);
await app.turn({
surface: "test",
actor,
- conversation: { kind: "dm", threadRef: "dm:U1:cleanup-2" },
+ conversation: { kind: "dm", threadRef: "dm:U1:no-sync" },
text: "!read missing.txt",
} as TurnRequest);
+ assert.deepEqual(touched, ["skills/.index", "skills/.index"]);
+});
- assert.ok(removed.some((path) => path === "skills/make-digest" || path.startsWith("skills/make-digest/")));
+test("ordinary sandbox reads remove archived skill files before access", async () => {
+ const { app, skills } = freshApp();
+ const skill = await publishPersonalSkill(skills);
+ const request = {
+ surface: "test",
+ actor,
+ conversation: { kind: "dm", threadRef: "dm:U1:archive" },
+ };
+ const before = await app.turn({ ...request, text: "!read skills/make-digest/SKILL.md" } as TurnRequest);
+ assert.match(before.reply ?? "", /Step 1: gather/);
+ await skills.archive(skill.id);
+ const after = await app.turn({ ...request, text: "!read ././skills/make-digest/SKILL.md" } as TurnRequest);
+ assert.doesNotMatch(after.reply ?? "", /Step 1: gather/);
});
diff --git a/test/skills-lazy-read-seam.test.ts b/test/skills-lazy-read-seam.test.ts
index db3a97279..b2eef6f69 100644
--- a/test/skills-lazy-read-seam.test.ts
+++ b/test/skills-lazy-read-seam.test.ts
@@ -102,3 +102,12 @@ test("a background job that runs a skill's script materializes its tree first to
assert.equal(r.status.state, "exited");
assert.equal(r.output, "ran", "the job ran cleanly because the assets were laid before it started");
});
+
+test("pack file access selects only the named pack", async () => {
+ const seen: string[] = [];
+ const tc = ctx((dir) => seen.push(dir));
+ await tc.read("skills/.packs/selected/reference.txt");
+ await tc.execute("python skills/.packs/selected/script.py");
+ await tc.backgroundStart("sh skills/.packs/selected/job.sh");
+ assert.deepEqual(seen, [".packs/selected", ".packs/selected", ".packs/selected"]);
+});
diff --git a/test/skills-materialize.test.ts b/test/skills-materialize.test.ts
index 35fe3acbf..e28a15224 100644
--- a/test/skills-materialize.test.ts
+++ b/test/skills-materialize.test.ts
@@ -4,7 +4,7 @@ import { CapabilityUnsupportedError, type Sandbox, type SandboxHandle } from "..
import type { SkillFile, SkillResolution } from "../src/skills/skill-store.ts";
import {
createSkillMaterializer,
- materializeSkillIndex,
+ reconcileSkillIndex,
materializeSkillTree,
safeSkillDirName,
} from "../src/skills/materialize.ts";
@@ -53,81 +53,81 @@ test("materialized skill directory names are validated and never lossy", () => {
assert.throws(() => safeSkillDirName(".."), /skill name must/);
});
-test("materializeSkillIndex lays only each SKILL.md body + an index marker", async () => {
+test("reconcileSkillIndex records ownership without copying any skill content", async () => {
const { sandbox, files, calls } = fakeSandbox();
- await materializeSkillIndex(sandbox, handle, [res("alpha", "A"), res("beta", "B")]);
+ await reconcileSkillIndex(sandbox, handle, [res("alpha", "A"), res("beta", "B")]);
- assert.equal(files.get("skills/alpha/SKILL.md"), "A");
- assert.equal(files.get("skills/beta/SKILL.md"), "B");
+ assert.equal(files.has("skills/alpha/SKILL.md"), false);
+ assert.equal(files.has("skills/beta/SKILL.md"), false);
assert.ok(files.has("skills/.index"), "an index marker is written");
- assert.equal(calls.writes, 3, "2 SKILL.md bodies + 1 marker — no asset writes");
+ assert.equal(calls.writes, 1);
});
-test("materializeSkillIndex does NOT lay a skill's asset tree (that's lazy)", async () => {
+test("reconcileSkillIndex does NOT lay a skill's asset tree (that's lazy)", async () => {
const { sandbox, files } = fakeSandbox();
- await materializeSkillIndex(sandbox, handle, [
+ await reconcileSkillIndex(sandbox, handle, [
res("gamma", "G", [{ path: "scripts/hello.py", content: "print('hi')" }]),
]);
- assert.equal(files.get("skills/gamma/SKILL.md"), "G", "the body is eager");
+ assert.equal(files.has("skills/gamma/SKILL.md"), false);
assert.equal(files.has("skills/gamma/scripts/hello.py"), false, "the asset is NOT laid until first read");
});
-test("materializeSkillIndex SKIPS when the body set is unchanged (order-independent)", async () => {
+test("reconcileSkillIndex SKIPS when the body set is unchanged (order-independent)", async () => {
const { sandbox, calls } = fakeSandbox();
- await materializeSkillIndex(sandbox, handle, [res("alpha", "A"), res("beta", "B")]);
+ await reconcileSkillIndex(sandbox, handle, [res("alpha", "A"), res("beta", "B")]);
const writes = calls.writes;
- await materializeSkillIndex(sandbox, handle, [res("beta", "B"), res("alpha", "A")]);
+ await reconcileSkillIndex(sandbox, handle, [res("beta", "B"), res("alpha", "A")]);
assert.equal(calls.writes, writes, "no rewrite on a matching body set");
});
-test("materializeSkillIndex re-lays when a body changes", async () => {
+test("reconcileSkillIndex ignores body changes until that skill is invoked", async () => {
const { sandbox, files, calls } = fakeSandbox();
- await materializeSkillIndex(sandbox, handle, [res("alpha", "A")]);
+ await reconcileSkillIndex(sandbox, handle, [res("alpha", "A")]);
const writes = calls.writes;
- await materializeSkillIndex(sandbox, handle, [res("alpha", "A2")]);
- assert.ok(calls.writes > writes, "a changed body busts the index marker");
- assert.equal(files.get("skills/alpha/SKILL.md"), "A2");
+ await reconcileSkillIndex(sandbox, handle, [res("alpha", "A2")]);
+ assert.equal(calls.writes, writes);
+ assert.equal(files.has("skills/alpha/SKILL.md"), false);
});
-test("materializeSkillIndex does NOT re-lay when only an asset changes (asset is not in the index hash)", async () => {
+test("reconcileSkillIndex does NOT re-lay when only an asset changes (asset is not in the index hash)", async () => {
const { sandbox, calls } = fakeSandbox();
- await materializeSkillIndex(sandbox, handle, [res("gamma", "G", [{ path: "s.py", content: "v1" }])]);
+ await reconcileSkillIndex(sandbox, handle, [res("gamma", "G", [{ path: "s.py", content: "v1" }])]);
const writes = calls.writes;
- await materializeSkillIndex(sandbox, handle, [res("gamma", "G", [{ path: "s.py", content: "v2" }])]);
+ await reconcileSkillIndex(sandbox, handle, [res("gamma", "G", [{ path: "s.py", content: "v2" }])]);
assert.equal(calls.writes, writes, "asset-only change doesn't touch the eager index");
});
-test("materializeSkillIndex removes an archived skill's materialized tree", async () => {
+test("reconcileSkillIndex removes an archived skill's materialized tree", async () => {
const { sandbox, files, calls } = fakeSandbox();
const alpha = res("alpha", "A", [{ path: "asset.txt", content: "asset" }]);
- await materializeSkillIndex(sandbox, handle, [alpha]);
+ await reconcileSkillIndex(sandbox, handle, [alpha]);
await materializeSkillTree(sandbox, handle, alpha, [bundle("p", [{ path: "lib/alpha.mjs", content: "shared" }])]);
- await materializeSkillIndex(sandbox, handle, []);
+ await reconcileSkillIndex(sandbox, handle, []);
assert.equal(files.has("skills/alpha/SKILL.md"), false);
assert.equal(files.has("skills/alpha/asset.txt"), false);
assert.equal(files.has("lib/alpha.mjs"), false);
const removes = calls.removes;
- await materializeSkillIndex(sandbox, handle, []);
+ await reconcileSkillIndex(sandbox, handle, []);
assert.equal(calls.removes, removes, "the reconciled marker makes the next pass idempotent");
});
-test("materializeSkillIndex migrates a legacy hash marker without retaining old skill paths", async () => {
+test("reconcileSkillIndex migrates a legacy hash marker without retaining old skill paths", async () => {
const { sandbox, files } = fakeSandbox();
const alpha = res("alpha", "A");
- await materializeSkillIndex(sandbox, handle, [alpha]);
+ await reconcileSkillIndex(sandbox, handle, [alpha]);
const state = JSON.parse(files.get("skills/.index")!) as { hash: string };
files.set("skills/.index", state.hash);
files.set("skills/removed/SKILL.md", "removed");
files.set("skills/removed/asset.txt", "stale");
- await materializeSkillIndex(sandbox, handle, [alpha]);
+ await reconcileSkillIndex(sandbox, handle, [alpha]);
assert.equal(files.has("skills/removed/SKILL.md"), false);
assert.equal(files.has("skills/removed/asset.txt"), false);
- assert.equal(files.get("skills/alpha/SKILL.md"), "A");
+ assert.equal(files.has("skills/alpha/SKILL.md"), false);
const migrated = JSON.parse(files.get("skills/.index")!);
assert.equal(migrated.version, 2);
assert.equal(migrated.legacyExternalPathsPreserved, true);
@@ -137,7 +137,7 @@ test("legacy migration cleans the managed skills namespace but preserves unknown
const { sandbox, files } = fakeSandbox();
const alpha = res("alpha", "A");
const currentBundle = bundle("p", [{ path: "lib/current.mjs", content: "current" }]);
- await materializeSkillIndex(sandbox, handle, [alpha]);
+ await reconcileSkillIndex(sandbox, handle, [alpha]);
await materializeSkillTree(sandbox, handle, alpha, [currentBundle]);
const index = JSON.parse(files.get("skills/.index")!) as { hash: string };
files.set("skills/.index", index.hash);
@@ -145,7 +145,7 @@ test("legacy migration cleans the managed skills namespace but preserves unknown
files.set("skills/.packs/p/lib/current.mjs", "stale known content");
files.set("lib/unknown-pre-v1.mjs", "ownership unknowable");
- await materializeSkillIndex(sandbox, handle, [alpha]);
+ await reconcileSkillIndex(sandbox, handle, [alpha]);
await materializeSkillTree(sandbox, handle, alpha, [currentBundle]);
assert.equal(files.has("skills/removed/stale.txt"), false);
assert.equal(
@@ -156,7 +156,7 @@ test("legacy migration cleans the managed skills namespace but preserves unknown
assert.equal(files.get("lib/unknown-pre-v1.mjs"), "ownership unknowable");
assert.equal(JSON.parse(files.get("skills/.index")!).legacyExternalPathsPreserved, true);
- await materializeSkillIndex(sandbox, handle, [res("alpha", "A2")]);
+ await reconcileSkillIndex(sandbox, handle, [res("alpha", "A2")]);
assert.equal(
JSON.parse(files.get("skills/.index")!).legacyExternalPathsPreserved,
true,
@@ -346,11 +346,11 @@ test("fresh reconciliation prevents an older turn from regressing a newer projec
const olderTurn = createSkillMaterializer(fleetLock);
const current = res("gamma", "G3", [{ path: "s.py", content: "v3" }]);
- await newerTurn.materializeIndex(sandbox, handle, [current], async () => [current]);
+ await newerTurn.reconcileIndex(sandbox, handle, [current], async () => [current]);
await newerTurn.materializeTree(sandbox, handle, current, [], async () => ({ resolution: current, bundles: [] }));
const removes = calls.removes;
- await olderTurn.materializeIndex(sandbox, handle, [], async () => [current]);
+ await olderTurn.reconcileIndex(sandbox, handle, [], async () => [current]);
await olderTurn.materializeTree(
sandbox,
handle,
@@ -382,7 +382,7 @@ test("materializeSkillTree never lays bundle content over core marker paths", as
const { sandbox, files } = fakeSandbox();
const alpha = res("alpha", "A");
const beta = res("beta", "B");
- await materializeSkillIndex(sandbox, handle, [alpha, beta]);
+ await reconcileSkillIndex(sandbox, handle, [alpha, beta]);
files.set("keep.txt", "valuable");
const forged = JSON.stringify({
version: 1,
@@ -407,7 +407,7 @@ test("materializeSkillTree never lays bundle content over core marker paths", as
test("materializeSkillTree never trusts a pre-hardening JSON delete manifest", async () => {
const { sandbox, files } = fakeSandbox();
const alpha = res("alpha", "A");
- await materializeSkillIndex(sandbox, handle, [alpha]);
+ await reconcileSkillIndex(sandbox, handle, [alpha]);
files.set("keep.txt", "valuable");
files.set(
"skills/alpha/.tree",
@@ -442,7 +442,7 @@ test("materializeSkillTree removes stale bundle paths but preserves another curr
const { sandbox, files } = fakeSandbox();
const alpha = res("alpha", "A");
const beta = res("beta", "B");
- await materializeSkillIndex(sandbox, handle, [alpha, beta]);
+ await reconcileSkillIndex(sandbox, handle, [alpha, beta]);
await materializeSkillTree(sandbox, handle, beta, [
bundle("shared-pack", [{ path: "lib/shared.mjs", content: "shared" }]),
]);
@@ -501,7 +501,7 @@ test("materializeSkillTree uses importFiles (one batch) when the backend offers
assert.equal(files.get("skills/gamma/b.py"), "B");
});
-test("switching a same-named skill source removes prior private assets before any command", async () => {
+test("reconciling a same-named skill source removes prior private assets before invocation", async () => {
const { sandbox, files, calls } = fakeSandbox();
const privateSkill = res(
"deploy",
@@ -512,19 +512,19 @@ test("switching a same-named skill source removes prior private assets before an
Object.assign(privateSkill.skill!, { id: "private", scopeId: "personal:U1" });
const orgSkill = res("deploy", "Same instructions");
Object.assign(orgSkill.skill!, { id: "public", scopeId: "org:acme" });
- await materializeSkillIndex(sandbox, handle, [privateSkill]);
+ await reconcileSkillIndex(sandbox, handle, [privateSkill]);
await materializeSkillTree(sandbox, handle, privateSkill, [
bundle("private-pack", [{ path: "private-lib.txt", content: "PRIVATE_PACK" }]),
]);
assert.ok([...files.values()].some((body) => body.includes("PRIVATE_ASSET")));
assert.ok([...files.values()].some((body) => body.includes("PRIVATE_PACK")));
- await materializeSkillIndex(sandbox, handle, [orgSkill]);
- assert.equal(files.get("skills/deploy/SKILL.md"), "Same instructions");
+ await reconcileSkillIndex(sandbox, handle, [orgSkill]);
+ assert.equal(files.has("skills/deploy/SKILL.md"), false);
assert.equal(
[...files.values()].some((body) => body.includes("PRIVATE_ASSET") || body.includes("PRIVATE_PACK")),
false,
);
const writes = calls.writes;
- await materializeSkillIndex(sandbox, handle, [orgSkill]);
+ await reconcileSkillIndex(sandbox, handle, [orgSkill]);
assert.equal(calls.writes, writes);
});
diff --git a/test/skills-source-read.test.ts b/test/skills-source-read.test.ts
index 7f38cca18..9cd33f5e2 100644
--- a/test/skills-source-read.test.ts
+++ b/test/skills-source-read.test.ts
@@ -112,6 +112,10 @@ test("a source-only read avoids sandbox work and a subsequent asset request mate
},
shadowed: [],
} as unknown as SkillResolution;
+ const unrelated = structuredClone(resolution);
+ unrelated.skill!.id = "other";
+ unrelated.skill!.manifest.name = "unrelated";
+ unrelated.skill!.pack = { packId: "other-pack", commit: "c", upstreamName: "unrelated" };
const handle = { id: "box", rootDir: "/workspace" };
const turn = createTurnSandboxes({
deps: {
@@ -142,8 +146,8 @@ test("a source-only read avoids sandbox work and a subsequent asset request mate
connectorEnv: {},
ownerEnvCredentialIds: [],
credentialCutoverServices: [],
- visibleSkills: [resolution],
- visibleSkillsForTurn: async () => [resolution],
+ visibleSkills: [resolution, unrelated],
+ visibleSkillsForTurn: async () => [resolution, unrelated],
skillMaterializer: createSkillMaterializer(),
emitGapWork: () => {},
perf: { credsMs: 0 },
@@ -154,6 +158,8 @@ test("a source-only read avoids sandbox work and a subsequent asset request mate
resolution = structuredClone(resolution);
resolution.skill!.manifest.files![0]!.content = "v2";
assert.equal((await turn.readSkill("skill://source-helper/references/example.txt")).content, "v2");
+ await turn.provision();
+ assert.deepEqual([...files.keys()], ["skills/.index"]);
await turn.ensureSkillTree("source-helper");
assert.equal(provisions, 1);
assert.equal(files.get("skills/source-helper/references/example.txt"), "v2");
@@ -164,9 +170,16 @@ test("a source-only read avoids sandbox work and a subsequent asset request mate
resolution.screenedBundles = [
{ packId: "pack", commit: "c", hash: "pack-hash", files: [{ path: "lib.txt", content: "PACK_RESOURCE" }] },
];
- await turn.ensureSkillTree(".packs", "resource-1");
+ const beforeResource = new Map(files);
+ await turn.provisionResource("resource-1");
+ assert.deepEqual(files, beforeResource);
+ await turn.ensureSkillTree(".packs/pack", "resource-1");
assert.deepEqual(sandboxIds, [undefined, "resource-1"]);
assert.equal(files.get("skills/.packs/pack/lib.txt"), "PACK_RESOURCE");
+ assert.equal(
+ [...files.keys()].some((path) => path.startsWith("skills/unrelated/")),
+ false,
+ );
});
test("pack assets remain readable and executable on later turns after source-only reads", async (t) => {
diff --git a/test/system-prompt-order.test.ts b/test/system-prompt-order.test.ts
index fb09f51d3..5b7d6b9f8 100644
--- a/test/system-prompt-order.test.ts
+++ b/test/system-prompt-order.test.ts
@@ -794,7 +794,24 @@ for (const location of [
assert.equal(read.status, "ok", read.reason);
assert.doesNotMatch(read.reply ?? "", /!security-risk|!security-screen-unavailable/);
assert.equal(disk.has("skills/carried-method/SKILL.md"), false);
+ assert.equal(disk.has("skills/local-method/SKILL.md"), false);
+ const localRead = await orchestrator.handleTurn({
+ surface: "test",
+ actor,
+ origin: { kind: "human" },
+ conversation: {
+ kind: "channel",
+ channelRef: "C1",
+ threadRef: `C1:read-local-${location}`,
+ audience: [actor],
+ publishMembers: [actor],
+ },
+ text: "!read skills/local-method/SKILL.md",
+ });
+ assert.equal(localRead.status, "ok", localRead.reason);
+ assert.match(localRead.reply ?? "", /Do useful work/);
assert.ok(disk.has("skills/local-method/SKILL.md"));
+ assert.equal(disk.has("skills/carried-method/SKILL.md"), false);
});
}