Skip to content

armgit / qm

Public Imported from GitHub
0

Multiplayer agent harness for work.

Rank skill shortlists and add source-safe native discovery (#2210)

Regan Bell6374e44c3afd
diff --git a/src/core/orchestrator.ts b/src/core/orchestrator.ts
index a84036c65..4999bf67d 100644
--- a/src/core/orchestrator.ts
+++ b/src/core/orchestrator.ts
@@ -1169,7 +1169,7 @@ export function createOrchestrator(deps: OrchestratorDeps): Orchestrator {
if (input.privateSessionMessage)
systemPrompt +=
"\n\nThis is a private message from another session. You may read context and reply using session.write with the sender session ID. Replies remain private and read-only. Do not open children or interrupt work. Reply only when there is useful information to send; reply chains are bounded.";
- const sharingPrompt = renderSharingPosturePrompt(actor, sharingSources);
+ const sharingPrompt = renderSharingPosturePrompt(actor, [...sharingSources].sort());
if (sharingPrompt) systemPrompt += `\n\n${sharingPrompt}`;
const scopeProfile = supportsScopeProfile(deps.sandbox)
? await deps.sandbox
@@ -1213,12 +1213,13 @@ export function createOrchestrator(deps: OrchestratorDeps): Orchestrator {
)
: [];
const carriedSkillScreens = new Map<string, Promise<boolean>>();
- const visibleSkillsForTurn = async (): Promise<SkillResolution[]> => {
- const resolved = filterConnectorSkills(await context.listSkills(), configuredProviders);
+ const visibleSkillsForTurn = async (sources?: readonly string[]): Promise<SkillResolution[]> => {
+ const current = await context.listSkills(sources);
+ const resolved = filterConnectorSkills(current.skills, configuredProviders);
const allowed: SkillResolution[] = [];
for (const entry of resolved) {
const skill = entry.skill;
- if (!skill || !sharingSources.includes(skill.scopeId) || securityPolicy.screening === "off") {
+ if (!skill || !current.sharingSources.includes(skill.scopeId) || securityPolicy.screening === "off") {
allowed.push(entry);
continue;
}
@@ -1268,20 +1269,26 @@ export function createOrchestrator(deps: OrchestratorDeps): Orchestrator {
detail: JSON.stringify({ actor: actor.id, source: skill.scopeId, target: scopeId }),
});
}
+ for (const entry of allowed) {
+ if (!entry.skill || !current.sharingSources.includes(entry.skill.scopeId)) continue;
+ deps.auditLog.record({
+ at: Date.now(),
+ principalId: actor.id,
+ action: "sharing.cross_context_read",
+ resource: `skill:${entry.skill.id}`,
+ scopeLabel: scopeId,
+ detail: JSON.stringify({ actor: actor.id, source: entry.skill.scopeId, target: scopeId }),
+ });
+ }
return allowed;
};
- const visibleSkills = await visibleSkillsForTurn();
- for (const entry of visibleSkills) {
- if (!entry.skill || !sharingSources.includes(entry.skill.scopeId)) continue;
- deps.auditLog.record({
- at: Date.now(),
- principalId: actor.id,
- action: "sharing.cross_context_read",
- resource: `skill:${entry.skill.id}`,
- scopeLabel: scopeId,
- detail: JSON.stringify({ actor: actor.id, source: entry.skill.scopeId, target: scopeId }),
- });
- }
+ const skillSourceContext = await context.listSkills([scopeId, resolution.orgScopeId]);
+ const otherSkillSources = skillSourceContext.skillSources
+ .filter((source) => source !== scopeId && source !== resolution.orgScopeId)
+ .sort();
+ if (otherSkillSources.length)
+ systemPrompt += `\n\nAdditional skill sources: ${otherSkillSources.join(", ")}. Use skills list/search with source to discover their authorized skills; read with the same source.`;
+ const nativeSkills = filterConnectorSkills(skillSourceContext.skills, configuredProviders);
const transferId = turnFileId(input.runId, input.attempt);
const turnSessionDir = `${TURN_FILES_DIR}/${hashId([conversation.threadRef], 24)}`;
const turnFilesDir = `${turnSessionDir}/${transferId}`;
@@ -1295,7 +1302,8 @@ export function createOrchestrator(deps: OrchestratorDeps): Orchestrator {
if (!external && deps.deploymentLayer?.hints.length) {
systemPrompt += `\n\n## Deployment tool hints\n${deps.deploymentLayer.hints.map((hint) => `- ${hint}`).join("\n")}`;
}
- if (visibleSkills.length) turnContextBlocks["Skills"] = skillsIndex(visibleSkills, sharingSources);
+ systemPrompt +=
+ "\n\n## Skills\nThe per-turn shortlist is not exhaustive. Use skills action list to browse all or search with query to find omitted or new skills. Read a skill before relying on it.";
const gatewayBlock = renderGatewayContext(input.surface, input.gatewayContext);
if (gatewayBlock) turnContextBlocks["Where you are"] = gatewayBlock;
const homeChannel =
@@ -2066,6 +2074,7 @@ export function createOrchestrator(deps: OrchestratorDeps): Orchestrator {
return true;
});
const memoryWindow = await deps.sessions.getContextWindow(session.id);
+
memoryView = await context.memorySnapshot();
recalled = memoryView.recalled;
const latestMemoryContext = memoryWindow.entries.findLast((entry) => memoryContextPayload(entry));
@@ -2719,6 +2728,7 @@ export function createOrchestrator(deps: OrchestratorDeps): Orchestrator {
...(provisionOwnerAuth ? { provisionOwnerAuth } : {}),
...(ownerAuthCommand ? { ownerAuthCommand } : {}),
useSkill,
+ listSkills: (source) => visibleSkillsForTurn(source ? [source] : [scopeId, resolution.orgScopeId]),
...(reachAvailable
? {
reach: {
@@ -3170,6 +3180,22 @@ export function createOrchestrator(deps: OrchestratorDeps): Orchestrator {
inputUnscreened || (enforceScreen && inbound.unscreened.length) || documentsUnscreened
? unscreenedNotice("inbound content")
: "";
+ const usedSkills = history.flatMap((entry) => {
+ const p = entry.payload;
+ return entry.type === "tool_call" &&
+ isObj(p) &&
+ p.tool === "skills" &&
+ p.action === "read" &&
+ typeof p.name === "string"
+ ? [p.name]
+ : [];
+ });
+ turnContextBlocks["Skills"] = skillsIndex(
+ nativeSkills,
+ [scopeId, resolution.orgScopeId],
+ input.text,
+ usedSkills,
+ );
const turnEnvironmentContents = [
manifest,
principalDelivered,
diff --git a/src/core/orchestrator/sandboxes.ts b/src/core/orchestrator/sandboxes.ts
index bfc1185d3..bf20c5a03 100644
--- a/src/core/orchestrator/sandboxes.ts
+++ b/src/core/orchestrator/sandboxes.ts
@@ -1,3 +1,4 @@
+import { hashId } from "../../util/crypto.ts";
import type { Principal, Resolution, ScopeId, Session } from "../../types.ts";
import { personalScope } from "../../types.ts";
import { intersectEgressPolicies } from "../../resolution/egress-policy.ts";
@@ -44,7 +45,7 @@ export interface TurnSandboxContext {
openSpeakerKeychain?: boolean;
openResourceAccess?: boolean;
ownerAuthAvailable: boolean;
- visibleSkillsForTurn: () => Promise<SkillResolution[]>;
+ visibleSkillsForTurn: (sources?: readonly string[]) => Promise<SkillResolution[]>;
emitGapWork: (phase: GapPhase, start: number, end: number) => void;
}
@@ -260,15 +261,16 @@ export function createTurnSandboxes(ctx: TurnSandboxContext) {
box.handle = handle;
return handle;
};
- const skillsRoot = () => `${SKILLS_ROOT}/${turnSessionDir.split("/").at(-1)}`;
+ const skillsRoot = (r: SkillResolution) =>
+ `${SKILLS_ROOT}/${turnSessionDir.split("/").at(-1)}/${hashId([r.skill!.id, String(r.skill!.version)], 16)}`;
const laidTrees = new Set<string>();
const materializeSkillTree = async (handle: SandboxHandle, r: SkillResolution, sandboxId?: string): Promise<void> => {
- const treeKey = `${sandboxId ?? "default"}:${skillDir(skillsRoot(), r)}`;
+ const treeKey = `${sandboxId ?? "default"}:${skillDir(skillsRoot(r), r)}`;
if (laidTrees.has(treeKey)) return;
const start = Date.now();
try {
const bundles = r.screenedBundles ?? (deps.skillBundles ? await loadActiveBundles(deps.skillBundles, [r]) : []);
- await laySkillTree(deps.sandbox, handle, skillsRoot(), r, bundles);
+ await laySkillTree(deps.sandbox, handle, skillsRoot(r), r, bundles);
laidTrees.add(treeKey);
} catch (err) {
deps.errors?.record(
@@ -286,7 +288,7 @@ export function createTurnSandboxes(ctx: TurnSandboxContext) {
emitGapWork("skills_materialize", start, Date.now());
}
};
- const useSkill = async (name: string, file: string, sandboxId?: string): Promise<SkillResult> => {
+ const useSkill = async (name: string, file: string, sandboxId?: string, source?: string): Promise<SkillResult> => {
const missing = { content: null, sourceScopeId: null };
if (!isSafeSkillName(name)) return missing;
try {
@@ -294,7 +296,9 @@ export function createTurnSandboxes(ctx: TurnSandboxContext) {
} catch {
return missing;
}
- const resolution = (await visibleSkillsForTurn()).find((r) => r.skill?.manifest.name === name);
+ const resolution = (await visibleSkillsForTurn(source ? [source] : undefined)).find(
+ (r) => r.skill?.manifest.name === name,
+ );
if (!resolution?.skill) return missing;
const shipsFiles = (resolution.skill.manifest.files?.length ?? 0) > 0 || resolution.skill.pack !== undefined;
const asset = resolution.skill.manifest.files?.find((f) => {
@@ -310,13 +314,13 @@ export function createTurnSandboxes(ctx: TurnSandboxContext) {
const render = (root?: string) =>
file === "SKILL.md"
? renderSkillBody(resolution, root)
- : rehomeSkillPaths(resolution, asset!, root ?? skillsRoot());
+ : rehomeSkillPaths(resolution, asset!, root ?? skillsRoot(resolution));
if (!shipsFiles) return { content: render(), sourceScopeId: resolution.skill.scopeId };
const access = sandboxId ? await accessResource(sandboxId) : undefined;
- if (access?.crossScope) return { content: render(skillsRoot()), sourceScopeId: resolution.skill.scopeId };
+ if (access?.crossScope) return { content: render(skillsRoot(resolution)), sourceScopeId: resolution.skill.scopeId };
const handle = access ? await provisionResource(access) : await provision();
await materializeSkillTree(handle, resolution, sandboxId);
- const root = `${handle.rootDir}/${skillsRoot()}`;
+ const root = `${handle.rootDir}/${skillsRoot(resolution)}`;
const pack = packRoot(root, resolution);
return {
content: render(root),
@@ -530,17 +534,13 @@ export function createTurnSandboxes(ctx: TurnSandboxContext) {
}
};
const pruneSkills = async (handle: SandboxHandle): Promise<void> => {
- const visible = (await visibleSkillsForTurn()).flatMap((r) => (r.skill ? [r.skill] : []));
- const keep = new Set([
- ...visible.map((skill) => skill.manifest.name),
- ...visible.flatMap((skill) => (skill.pack ? [`.packs/${skill.pack.packId}`] : [])),
- ]);
+ const visible = (await visibleSkillsForTurn()).flatMap((r) => (r.skill ? [r.skill, ...r.shadowed] : []));
+ const keep = new Set(visible.map((skill) => hashId([skill.id, String(skill.version)], 16)));
const stale = new Set<string>();
for (const path of await deps.sandbox.listDir(handle, SKILLS_ROOT)) {
- const [root, conversation, name, sub] = path.split("/");
- const key = name === ".packs" ? `${name}/${sub}` : name;
- if (root === SKILLS_ROOT && conversation && key && !keep.has(key))
- stale.add(`${SKILLS_ROOT}/${conversation}/${key}`);
+ const [root, conversation, identity] = path.split("/");
+ if (root === SKILLS_ROOT && conversation && identity && !keep.has(identity))
+ stale.add(`${SKILLS_ROOT}/${conversation}/${identity}`);
}
await Promise.all(
[...stale].map((dir) =>
diff --git a/src/harness/agent-tools.ts b/src/harness/agent-tools.ts
index 8c99bb198..d5c3a9ca8 100644
--- a/src/harness/agent-tools.ts
+++ b/src/harness/agent-tools.ts
@@ -1029,13 +1029,52 @@ export function createAgentTools(ref: ToolContextRef, opts?: AgentToolsOptions):
},
});
+ const discoverSkills = (search: boolean) =>
+ defineTool({
+ name: search ? "search_skills" : "list_skills",
+ label: search ? "Search skills" : "List skills",
+ description: search
+ ? "Search current-scope and organization skills by name or description, including omitted skills. To search a carried source listed in the sharing context, set source. Read a skill before using it."
+ : "Browse current-scope and organization skills, including omitted or new skills. Set source to browse a carried source listed in the sharing context. Follow nextOffset within the same source; does not start a sandbox.",
+ parameters: Type.Object({
+ ...(search
+ ? { query: Type.String({ minLength: 1, description: "Words to find in skill names or descriptions." }) }
+ : {}),
+ source: Type.Optional(
+ Type.String({
+ description:
+ "Exact authorized source scope from the sharing context; omitted means current scope and organization.",
+ }),
+ ),
+ offset: Type.Optional(Type.Integer({ minimum: 0 })),
+ limit: Type.Optional(Type.Integer({ minimum: 1, maximum: 100 })),
+ }),
+ async execute(callId, params) {
+ if (!ref.current) return text("[error] no active tool context");
+ const p = params as { query?: string; offset?: number; limit?: number; source?: string };
+ const action = search ? "search" : "list";
+ await recordCall(callId, { tool: "skills", action, ...p });
+ const { sourceScopeId, ...result } = await ref.current.listSkills(p.query, p.offset, p.limit, p.source);
+ return recordResult(
+ callId,
+ { tool: "skills", action, count: result.skills.length },
+ text(JSON.stringify(result)),
+ false,
+ sourceScopeId,
+ );
+ },
+ });
+
const skill = defineTool({
name: "skill",
label: "skill",
description:
- "Load a skill from the Skills index before relying on it. Returns its SKILL.md instructions (or the relative file named by `path`) straight from the published source, without starting a sandbox. When the skill ships scripts or supporting files, this call also syncs them into a stable directory on the computer and reports it; run and read them there with execute and files action read. Reading the skill again refreshes that copy.",
+ "Load a skill by name before relying on it; use list or search to discover names outside the shortlist. Returns its SKILL.md instructions (or the relative file named by `path`) straight from the published source, without starting a sandbox. When the skill ships scripts or supporting files, this call also syncs them into a stable directory on the computer and reports it; run and read them there with execute and files action read. Reading the skill again refreshes that copy.",
parameters: Type.Object({
- name: Type.String({ description: "Skill name exactly as listed in the Skills index." }),
+ name: Type.String({ description: "Skill name from the shortlist, list, or search." }),
+ source: Type.Optional(
+ Type.String({ description: "Use the same source as the discovery call to read that exact skill." }),
+ ),
path: Type.Optional(
Type.String({ description: "Relative file within the skill to return instead of SKILL.md." }),
),
@@ -1050,12 +1089,19 @@ export function createAgentTools(ref: ToolContextRef, opts?: AgentToolsOptions):
async execute(callId, params) {
const tc = ref.current;
if (!tc) return text("[error] no active tool context");
- const p = params as { name: string; path?: string; sandbox_id?: string };
- await recordCall(callId, { tool: "skills", action: "read", name: p.name, ...(p.path ? { path: p.path } : {}) });
+ const p = params as { name: string; path?: string; sandbox_id?: string; source?: string };
+ await recordCall(callId, {
+ tool: "skills",
+ action: "read",
+ name: p.name,
+ ...(p.path ? { path: p.path } : {}),
+ ...(p.source ? { source: p.source } : {}),
+ });
const signal = ref.abortSignal;
signal?.throwIfAborted();
const { content, sourceScopeId, dir, packDir } = await tc.skill(p.name, {
...(p.path ? { path: p.path } : {}),
+ ...(p.source ? { source: p.source } : {}),
...(p.sandbox_id ? { sandboxId: p.sandbox_id } : {}),
...(signal ? { signal } : {}),
});
@@ -4244,6 +4290,8 @@ export function createAgentTools(ref: ToolContextRef, opts?: AgentToolsOptions):
const tools = [
...(!delegateWork ? [execute] : []),
resourceTool("skills", {
+ list: discoverSkills(false),
+ search: discoverSkills(true),
read: skill,
...(controlTools ? { share: sharingTool("skill"), move: sharingTool("skill", true) } : {}),
}),
diff --git a/src/resolution/turn-context.ts b/src/resolution/turn-context.ts
index 9f586c4dd..4adcd8702 100644
--- a/src/resolution/turn-context.ts
+++ b/src/resolution/turn-context.ts
@@ -47,16 +47,6 @@ export async function resolveTurnContext(input: ContextInput) {
(useMemory && memoryPolicy.capture !== "off") || read.length
? { ...(useMemory && memoryPolicy.capture !== "off" ? { write: memoryScopeId } : {}), read }
: undefined;
- const skillScopes = [
- ...new Set([
- memoryScopeId,
- ...resolution.layers
- .filter((layer) => layer.mode === "ro" && layer.scopeId !== resolution.orgScopeId)
- .map((layer) => layer.scopeId),
- ...sharingSources,
- ...(!input.external ? [resolution.orgScopeId] : []),
- ]),
- ];
const recordRead = (scope: ScopeId, resource: string) => {
if (!sharingSources.includes(scope)) return;
input.auditLog?.record({
@@ -83,19 +73,6 @@ export async function resolveTurnContext(input: ContextInput) {
...resolution.grantedHandles,
...(await carriedFileHandles(sharingSources, input.workspace, input.files)),
];
- const grantedSkills: GrantedSkillRef[] = input.external
- ? []
- : (
- await input.acl
- .sharedOfKindForAudience(
- "skill",
- input.audience,
- input.targetScope,
- resolution.orgScopeId,
- principalEntitledToScope,
- )
- .catch(swallowAs("context: skill grants for audience", []))
- ).map((grant) => ({ id: parseRef(grant.ref).id, ownerScopeId: grant.ownerScopeId }));
return {
sharingSources,
memoryScopeId,
@@ -138,7 +115,43 @@ export async function resolveTurnContext(input: ContextInput) {
return hits.flat().slice(0, limit);
},
listFiles: () => handles,
- listSkills: async () => (await input.skills?.visibleFor(skillScopes, grantedSkills)) ?? [],
+ listSkills: async (sources?: readonly string[]) => {
+ const sharingSources = input.external
+ ? []
+ : await sharingSourcesForTurn({ ...input, posture: resolution.sharingPosture });
+ const skillScopes = [
+ ...new Set([
+ memoryScopeId,
+ ...resolution.layers
+ .filter((layer) => layer.mode === "ro" && layer.scopeId !== resolution.orgScopeId)
+ .map((layer) => layer.scopeId),
+ ...sharingSources,
+ ...(!input.external ? [resolution.orgScopeId] : []),
+ ]),
+ ];
+ const grantedSkills: GrantedSkillRef[] = input.external
+ ? []
+ : (
+ await input.acl
+ .sharedOfKindForAudience(
+ "skill",
+ input.audience,
+ input.targetScope,
+ resolution.orgScopeId,
+ principalEntitledToScope,
+ )
+ .catch(swallowAs("context: skill grants for audience", []))
+ ).map((grant) => ({ id: parseRef(grant.ref).id, ownerScopeId: grant.ownerScopeId }));
+ return {
+ skills:
+ (await input.skills?.visibleFor(
+ sources ? skillScopes.filter((scope) => sources.includes(scope)) : skillScopes,
+ sources ? grantedSkills.filter((grant) => sources.includes(grant.ownerScopeId)) : grantedSkills,
+ )) ?? [],
+ sharingSources,
+ skillSources: [...new Set([...skillScopes, ...grantedSkills.map((grant) => grant.ownerScopeId)])],
+ };
+ },
readFile: (path: string) =>
readContextFile(path, handles, input.workspace, input.files, (grant) => {
if (grant.carried) recordRead(grant.ownerScopeId, grant.ownerPath);
diff --git a/src/skills/materialize.ts b/src/skills/materialize.ts
index b3ca22c53..188c9274d 100644
--- a/src/skills/materialize.ts
+++ b/src/skills/materialize.ts
@@ -92,26 +92,66 @@ export async function materializeSkillTree(
for (const e of entries) await sandbox.writeFile(handle, e.path, e.content);
}
-export function skillsIndex(resolved: SkillResolution[], provenanceScopes: readonly ScopeId[] = []): string {
+export function rankedSkills(
+ resolved: SkillResolution[],
+ query = "",
+ usedNames: readonly string[] = [],
+ onlyMatches = false,
+): SkillResolution[] {
+ const tokens = (text: string) =>
+ new Set(
+ [...new Intl.Segmenter("en", { granularity: "word" }).segment(text.toLowerCase())]
+ .filter((part) => part.isWordLike)
+ .map((part) => part.segment),
+ );
+ const ignored = new Set(
+ "a an and are as at be by can do for from have help i in is it me my of on or please that the this to today use want what with you your".split(
+ " ",
+ ),
+ );
+ const words = [...tokens(query)].filter((word) => !ignored.has(word));
+ const unique = new Map<string, SkillResolution>();
+ for (const entry of resolved) {
+ if (entry.skill && !unique.has(entry.skill.manifest.name)) unique.set(entry.skill.manifest.name, entry);
+ }
+ return [...unique.values()]
+ .map((entry) => {
+ const skill = entry.skill!;
+ const text = tokens(`${skill.manifest.name} ${skill.manifest.description}`);
+ return {
+ entry,
+ relevance: words.filter((word) => text.has(word)).length,
+ used: usedNames.includes(skill.manifest.name) ? 1 : 0,
+ };
+ })
+ .filter(({ relevance }) => !onlyMatches || relevance > 0)
+ .sort(
+ (a, b) =>
+ b.relevance - a.relevance ||
+ b.used - a.used ||
+ a.entry.skill!.manifest.name.localeCompare(b.entry.skill!.manifest.name),
+ )
+ .map(({ entry }) => entry);
+}
+
+export function skillsIndex(
+ resolved: SkillResolution[],
+ provenanceScopes: readonly ScopeId[] = [],
+ query = "",
+ usedNames: readonly string[] = [],
+): string {
const provenance = new Set(provenanceScopes);
- const items = resolved
- .filter((r) => r.skill)
- .sort((a, b) => {
- const [x, y] = [a.skill!.manifest.name, b.skill!.manifest.name];
- if (x < y) return -1;
- if (x > y) return 1;
- return 0;
- });
+ const ranked = rankedSkills(resolved, query, usedNames);
+ const items = ranked.slice(0, 12);
if (!items.length) return "";
const lines = items.map((r) => {
const m = r.skill!.manifest;
- const shadow = r.shadowed.length ? " (shadows a broader-scope skill of the same name)" : "";
const source = provenance.has(r.skill!.scopeId) ? ` [from ${r.skill!.scopeId}]` : "";
- return `- **${m.name}**${source} — ${m.description}${shadow}`;
+ return `- **${m.name}**${source} — ${m.description}`;
});
return [
"## Skills",
- 'Load a skill with the skills tool before relying on it: skills({ action: "read", name }) returns its instructions without starting a sandbox. When a skill ships scripts or supporting files, the same call syncs them into a stable directory on the computer and names it; run and read them there. Reading the skill again refreshes that copy.',
+ `Showing ${items.length} of ${ranked.length} available skills. Use skills action list or search for the rest.`,
...lines,
].join("\n");
}
diff --git a/src/tools/primitives.ts b/src/tools/primitives.ts
index d28d3e037..3c57aab6b 100644
--- a/src/tools/primitives.ts
+++ b/src/tools/primitives.ts
@@ -1,4 +1,6 @@
import type { AdminToolAccess } from "./admin.ts";
+import { rankedSkills } from "../skills/materialize.ts";
+import type { SkillResolution } from "../skills/skill-store.ts";
import {
prepareExecutionFiles,
processCredentialFiles,
@@ -223,7 +225,20 @@ export interface ToolContext extends SurfaceToolDeps {
computerStatus(sandboxId?: string): Promise<ComputerStatus>;
restartComputer(sandboxId?: string): Promise<void>;
read(path: string, signal?: AbortSignal): Promise<ReadResult>;
- skill(name: string, opts?: { path?: string; sandboxId?: string; signal?: AbortSignal }): Promise<SkillResult>;
+ listSkills(
+ query?: string,
+ offset?: number,
+ limit?: number,
+ source?: string,
+ ): Promise<{
+ sourceScopeId: ScopeId | null;
+ skills: Array<{ name: string; description: string; source?: string }>;
+ nextOffset?: number;
+ }>;
+ skill(
+ name: string,
+ opts?: { path?: string; sandboxId?: string; source?: string; signal?: AbortSignal },
+ ): Promise<SkillResult>;
write(path: string, data?: string, share?: ShareDirective[]): Promise<WriteResult>;
publish(input: PublishInput): Promise<PublishResult>;
setDeploymentPublic(id: string, isPublic: boolean): Promise<{ id: string; name?: string; public: boolean }>;
@@ -455,7 +470,8 @@ export interface ToolContextDeps {
accessSandboxResource?: (id: string) => Promise<SandboxAccessPlan>;
provisionOwnerAuth?: () => Promise<SandboxHandle>;
ownerAuthCommand?: (command: string, env?: Record<string, string>) => string;
- useSkill?: (name: string, path: string, sandboxId?: string) => Promise<SkillResult>;
+ listSkills?: (source?: string) => Promise<SkillResolution[]>;
+ useSkill?: (name: string, path: string, sandboxId?: string, source?: string) => Promise<SkillResult>;
reach?: {
resolveChannel(query: string): Promise<ReachResolution>;
provisionFor(scopeId: ScopeId): Promise<SandboxHandle>;
@@ -967,15 +983,36 @@ export function createToolContext(deps: ToolContextDeps): ToolContext {
);
},
+ async listSkills(query = "", offset = 0, limit = 50, source?: string) {
+ const available = (await deps.listSkills?.(source)) ?? [];
+ const matches = rankedSkills(available, query, [], Boolean(query));
+ const start = Math.max(0, Math.floor(offset));
+ const selected = matches.slice(start, start + Math.max(1, Math.min(100, Math.floor(limit))));
+ const sourceScopeId = selected.length && source ? selected[0]!.skill!.scopeId : null;
+ const end = start + selected.length;
+ return {
+ sourceScopeId,
+ skills: selected.map(({ skill }) => ({
+ name: skill!.manifest.name,
+ description: skill!.manifest.description,
+ source: skill!.scopeId,
+ })),
+ ...(end < matches.length ? { nextOffset: end } : {}),
+ };
+ },
+
async skill(
name: string,
- opts?: { path?: string; sandboxId?: string; signal?: AbortSignal },
+ opts?: { path?: string; sandboxId?: string; source?: string; signal?: AbortSignal },
): Promise<SkillResult> {
opts?.signal?.throwIfAborted();
if (!deps.useSkill) return { content: null, sourceScopeId: null };
if (opts?.sandboxId && (!deps.sandboxResources || !deps.provisionResource))
throw new Error("named sandboxes are not available here");
- return withAbort(() => deps.useSkill!(name, opts?.path ?? "SKILL.md", opts?.sandboxId), opts?.signal);
+ return withAbort(
+ () => deps.useSkill!(name, opts?.path ?? "SKILL.md", opts?.sandboxId, opts?.source),
+ opts?.signal,
+ );
},
async write(path: string, data?: string, share?: ShareDirective[]): Promise<WriteResult> {
diff --git a/test/agent-tools.test.ts b/test/agent-tools.test.ts
index 5d6e6bba5..c0d145460 100644
--- a/test/agent-tools.test.ts
+++ b/test/agent-tools.test.ts
@@ -28,6 +28,9 @@ function fakeToolContext(sink?: { lastExecOpts?: Parameters<ToolContext["execute
async computerStatus() {
return { machine: "healthy", guestResponsive: true };
},
+ async listSkills() {
+ return { sourceScopeId: null, skills: [] };
+ },
async skill() {
return { content: null, sourceScopeId: null };
},
@@ -4450,3 +4453,47 @@ test("split sandbox tools reject missing, mistyped, blank and unrelated fields w
);
assert.equal(dispatched, 0);
});
+
+test("native skills discovery exposes list and search with validated pagination", async () => {
+ const ctx = fakeToolContext();
+ const seen: unknown[] = [];
+ ctx.listSkills = async (...args) => {
+ seen.push(args);
+ return { sourceScopeId: null, skills: [{ name: "rare-helper", description: "Rare task" }] };
+ };
+ const tool = createAgentTools({ current: ctx }).find((t) => t.name === "skills")!;
+ assert.match(textOut(await call(tool, { action: "search", query: "rare", limit: 10 })), /rare-helper/);
+ await call(tool, { action: "list", offset: 4, limit: 2 });
+ assert.deepEqual(seen, [
+ ["rare", undefined, 10, undefined],
+ [undefined, 4, 2, undefined],
+ ]);
+ for (const input of [{ action: "search" }, { action: "list", limit: 101 }, { action: "list", offset: -1 }]) {
+ assert.match(textOut(await call(tool, input)), /Invalid arguments/);
+ }
+});
+
+test("skill discovery records the page's source scope for history and tape filtering", async () => {
+ const emitted: Emitted[] = [];
+ const ctx = fakeToolContext();
+ ctx.listSkills = async () => ({
+ sourceScopeId: "personal:U1",
+ skills: [{ name: "private-helper", description: "Private description" }],
+ nextOffset: 1,
+ });
+ const ref: ToolContextRef = {
+ current: ctx,
+ scopeLabel: "channel:C1",
+ orgScopeId: "org:default-org",
+ emit: (e) => {
+ emitted.push(e as Emitted);
+ },
+ };
+ const tool = createAgentTools(ref).find((t) => t.name === "skills")!;
+ await callWith(tool, "discovery", { action: "list" });
+ assert.equal(ref.tapeResultScopes?.get("discovery"), "personal:U1");
+ const history = emitted.map((e, seq) => ({ ...e, seq, createdAt: seq, sessionId: "s" })) as SessionEntry[];
+ const visible = filterHistoryForAudience(history, [{ id: "U2", type: "internal" }], "channel:C1", "org:default-org");
+ assert.doesNotMatch(JSON.stringify(visible), /Private description|private-helper/);
+ assert.match(JSON.stringify(history), /Private description/);
+});
diff --git a/test/sandbox-resources.test.ts b/test/sandbox-resources.test.ts
index 0ba157cf4..7e833397b 100644
--- a/test/sandbox-resources.test.ts
+++ b/test/sandbox-resources.test.ts
@@ -902,3 +902,46 @@ test("two concurrent turns on one parking computer: only the last turn to finish
assert.deepEqual(teardowns, [{ keepWarm: true }, {}]);
assert.deepEqual((await resources.get(record.id)).holders, []);
});
+
+test("same-name skills from distinct sources keep their materialized assets separate", async () => {
+ const { resources, router, layers } = fixture();
+ const record = await resources.create("alice", "personal:alice", "local");
+ await resources.setDefault("alice", "personal:alice", record.id);
+ const turn = createTurnSandboxes({
+ deps: { sandbox: router, sandboxResources: resources },
+ input: { origin: { kind: "user" } },
+ actor: { id: "alice", type: "internal" },
+ session: { id: "s" },
+ resolution: { layers },
+ scopeId: "personal:alice",
+ memoryScopeId: "personal:alice",
+ transferId: "t",
+ turnSessionDir: "turn/s",
+ turnFilesDir: "turn/s/t",
+ connectorEnv: {},
+ ownerAuthAvailable: false,
+ emitGapWork: () => {},
+ visibleSkillsForTurn: async (sources: readonly string[] = ["org:example", "personal:alice"]) =>
+ sources.map((source) => ({
+ skill: {
+ id: source,
+ scopeId: source,
+ version: 1,
+ manifest: {
+ name: "helper",
+ body: "Run skills/helper/value.py",
+ files: [{ path: "value.py", content: source }],
+ },
+ },
+ shadowed: [],
+ })),
+ } as unknown as TurnSandboxContext);
+ const a = await turn.useSkill("helper", "SKILL.md", undefined, "org:example");
+ const b = await turn.useSkill("helper", "SKILL.md", undefined, "personal:alice");
+ const again = await turn.useSkill("helper", "SKILL.md", undefined, "org:example");
+ assert.notEqual(a.dir, b.dir);
+ assert.equal(a.dir, again.dir);
+ const handle = await turn.provision();
+ assert.equal(await router.readFile(handle, `${a.dir!.replace("/workspace/", "")}/value.py`), "org:example");
+ assert.equal(await router.readFile(handle, `${b.dir!.replace("/workspace/", "")}/value.py`), "personal:alice");
+});
diff --git a/test/sharing-context-e2e.test.ts b/test/sharing-context-e2e.test.ts
index 3740e26a5..829c6e8eb 100644
--- a/test/sharing-context-e2e.test.ts
+++ b/test/sharing-context-e2e.test.ts
@@ -198,7 +198,7 @@ test("sharing e2e: room file and memory access is revoked on the next DM turn",
test("sharing e2e: skill lazy assets execute, update, and disappear from the same computer after opt-out", async (t) => {
const b = await fixture(t);
const s = await b.skill("personal:U1", "carried-helper", "VERSION_ONE");
- assert.match(await b.turn("!sysprompt", true), /carried-helper/);
+ assert.doesNotMatch(await b.turn("!sysprompt", true), /carried-helper/);
assert.equal(await b.turn("!skill-run carried-helper python3 {dir}/scripts/value.py", true), "VERSION_ONE");
await b.skills.update(s.id, {
...s.manifest,
diff --git a/test/skill-tool.test.ts b/test/skill-tool.test.ts
index 6f7f2327b..e9b99d366 100644
--- a/test/skill-tool.test.ts
+++ b/test/skill-tool.test.ts
@@ -1,6 +1,6 @@
import { test } from "node:test";
import assert from "node:assert/strict";
-import { createToolContext, type SkillResult } from "../src/tools/primitives.ts";
+import { createToolContext, type ToolContextDeps, type SkillResult } from "../src/tools/primitives.ts";
import type { Sandbox, SandboxHandle } from "../src/sandbox/sandbox.ts";
import { scopeId } from "../src/types.ts";
@@ -80,7 +80,7 @@ test("skill without a materializer reports no file", async () => {
assert.deepEqual(await tc.skill("send"), { content: null, sourceScopeId: null });
});
-function createToolContextWithout() {
+function createToolContextWithout(extra: Partial<ToolContextDeps> = {}) {
const tc = createToolContext({
sandbox: {} as unknown as Sandbox,
provision: async () => ({ id: "h", rootDir: "/workspace" }) as SandboxHandle,
@@ -92,6 +92,59 @@ function createToolContextWithout() {
deploy: {} as never,
acl: {} as never,
createdBy: "U1",
+ ...extra,
});
return { tc };
}
+
+test("skill discovery pages the current visible catalog without provisioning or exposing metadata", async () => {
+ const skills = Array.from({ length: 3 }, (_, i) => ({
+ skill: {
+ manifest: {
+ name: `skill-${i}`,
+ description: i === 2 ? "Telescope planning" : "General task",
+ body: "Instructions",
+ requiredCapabilities: [],
+ },
+ id: `id-${i}`,
+ signature: "",
+ status: "published" as const,
+ createdBy: "someone",
+ version: 1,
+ grantedCapabilities: [],
+ approvals: [],
+ lastUsedAt: 100,
+ scopeId: scopeId("personal", "someone"),
+ },
+ shadowed: [],
+ }));
+ const { tc } = createToolContextWithout({
+ provision: async () => {
+ throw new Error("must not provision");
+ },
+ listSkills: async (source) => skills.filter(({ skill }) => skill.scopeId === (source ?? "personal:U1")),
+ });
+ assert.deepEqual(await tc.listSkills(), { sourceScopeId: null, skills: [] });
+ assert.deepEqual(await tc.listSkills("", 0, 2, "personal:someone"), {
+ sourceScopeId: "personal:someone",
+ skills: [0, 1].map((i) => ({ name: `skill-${i}`, description: "General task", source: "personal:someone" })),
+ nextOffset: 2,
+ });
+ assert.deepEqual(await tc.listSkills("", 2, 2, "personal:someone"), {
+ sourceScopeId: "personal:someone",
+ skills: [{ name: "skill-2", description: "Telescope planning", source: "personal:someone" }],
+ });
+ assert.deepEqual(await tc.listSkills("telescope", 0, 50, "personal:someone"), {
+ sourceScopeId: "personal:someone",
+ skills: [{ name: "skill-2", description: "Telescope planning", source: "personal:someone" }],
+ });
+ skills[1]!.skill.scopeId = scopeId("personal", "U1");
+ const native = await tc.listSkills();
+ assert.deepEqual(native, {
+ sourceScopeId: null,
+ skills: [{ name: "skill-1", description: "General task", source: "personal:U1" }],
+ });
+ assert.deepEqual(await tc.listSkills("", 0, 100, "personal:missing"), { sourceScopeId: null, skills: [] });
+ skills.pop();
+ assert.deepEqual(await tc.listSkills("telescope", 0, 50, "personal:someone"), { sourceScopeId: null, skills: [] });
+});
diff --git a/test/skills-callable.test.ts b/test/skills-callable.test.ts
index 70e6f898a..01ab64f61 100644
--- a/test/skills-callable.test.ts
+++ b/test/skills-callable.test.ts
@@ -135,3 +135,96 @@ test("skill files stay on the computer across turns", async () => {
await skills.archive(first.id);
assert.match((await app.turn({ ...request, text: "!skill helper" } as TurnRequest)).reply ?? "", /no skill file/);
});
+
+test("shortlist uses visible history, resets with compaction, and leaves the system prefix stable", async () => {
+ const built = freshApp();
+ for (let i = 0; i < 20; i++) {
+ const skill = await built.skills.create({
+ scopeId: "personal:U1",
+ createdBy: "U1",
+ manifest: {
+ name: `helper-${String(i).padStart(2, "0")}`,
+ description: "General task",
+ body: "Instructions",
+ requiredCapabilities: [],
+ },
+ });
+ await built.skills.review(skill.id, "reviewer", []);
+ await built.skills.publish(skill.id);
+ }
+ const request = {
+ surface: "test" as const,
+ actor,
+ conversation: { kind: "dm" as const, threadRef: "shortlist-history" },
+ text: "!sysprompt",
+ };
+ const first = await built.app.turn(request);
+ assert.doesNotMatch(first.reply ?? "", /\*\*helper-19\*\*/);
+ const sessionId = first.sessionId!;
+ const { lease } = await built.sessions.acquireLease(sessionId, "turn");
+ assert.ok(lease);
+ await built.sessions.append(lease, {
+ type: "tool_call",
+ payload: { tool: "skills", action: "read", name: "helper-19" },
+ scopeLabel: "personal:U1",
+ });
+ await built.sessions.releaseLease(lease);
+ const second = await built.app.turn(request);
+ assert.match(second.reply ?? "", /\*\*helper-19\*\*/);
+ const unchanged = await built.app.turn(request);
+ assert.doesNotMatch(unchanged.reply ?? "", /Showing 12 of/);
+ const entries = await built.sessions.getEntries(sessionId);
+ const reset = await built.sessions.acquireLease(sessionId, "compaction");
+ assert.ok(reset.lease);
+ await built.sessions.append(reset.lease, {
+ type: "system",
+ payload: { kind: "context_summary", text: "Earlier work complete", throughSeq: entries.at(-1)!.seq },
+ scopeLabel: "personal:U1",
+ });
+ await built.sessions.releaseLease(reset.lease);
+ const third = await built.app.turn(request);
+ assert.doesNotMatch(third.reply ?? "", /\*\*helper-19\*\*/);
+ const recorded = (await built.sessions.listLlmRequests(sessionId)).filter((r) => r.model === "mock");
+ const systems = recorded.map((r) => (r.promptEnvelope as { system: string }).system);
+ assert.equal(systems.length, 4);
+ assert.equal(systems[0], systems[1]);
+ assert.equal(systems[1], systems[2]);
+ assert.equal(systems[2], systems[3]);
+});
+
+test("Open sharing keeps private skill metadata out of the persisted channel shortlist", async () => {
+ const built = buildApp(testConfig({ securityScreen: "off" }));
+ await built.config.setSharingPosture("org:default-org", "open");
+ await publishPersonalSkill(built.skills);
+ const result = await built.app.turn({
+ surface: "test",
+ origin: { kind: "human" },
+ actor,
+ conversation: {
+ kind: "channel",
+ channelRef: "C1",
+ threadRef: "shortlist-open",
+ audience: [actor],
+ publishMembers: [actor],
+ },
+ text: "!sysprompt",
+ });
+ assert.equal(result.status, "ok");
+ assert.doesNotMatch(result.reply ?? "", /assemble a morning digest|\*\*make-digest\*\*/);
+ const read = await built.app.turn({
+ surface: "test",
+ origin: { kind: "human" },
+ actor,
+ conversation: {
+ kind: "channel",
+ channelRef: "C1",
+ threadRef: "shortlist-open",
+ audience: [actor],
+ publishMembers: [actor],
+ },
+ text: "!skill make-digest",
+ });
+ assert.match(read.reply ?? "", /Step 1: gather/);
+ const entries = await built.sessions.getEntries(result.sessionId!);
+ assert.doesNotMatch(JSON.stringify(entries.filter((e) => e.type === "user")), /assemble a morning digest/);
+});
diff --git a/test/skills-materialize.test.ts b/test/skills-materialize.test.ts
index 99abbc1d6..e0ff49f4b 100644
--- a/test/skills-materialize.test.ts
+++ b/test/skills-materialize.test.ts
@@ -1,8 +1,16 @@
+import { readdirSync, readFileSync } from "node:fs";
+import { parseSeedSkill } from "../src/skills/seed.ts";
import { test } from "node:test";
import assert from "node:assert/strict";
import { CapabilityUnsupportedError, type Sandbox, type SandboxHandle } from "../src/sandbox/sandbox.ts";
import type { SkillFile, SkillResolution } from "../src/skills/skill-store.ts";
-import { materializeSkillTree, renderSkillBody, safeSkillDirName } from "../src/skills/materialize.ts";
+import {
+ materializeSkillTree,
+ rankedSkills,
+ renderSkillBody,
+ safeSkillDirName,
+ skillsIndex,
+} from "../src/skills/materialize.ts";
import { computeBundleHash, type SkillBundle } from "../src/skills/skill-bundle-store.ts";
const handle: SandboxHandle = { id: "h", rootDir: "/workspace" };
@@ -148,3 +156,44 @@ test("a pack bundle may ship a root SKILL.md of its own", async () => {
]);
assert.equal(files.get(`${root}/.packs/s1/SKILL.md`), "pack readme");
});
+
+test("skill shortlist favors relevant and visibly used skills without global usage signals", () => {
+ const skills = Array.from({ length: 20 }, (_, i) => res(`skill-${String(i).padStart(2, "0")}`, "body"));
+ for (const r of skills) r.skill!.manifest.description = "General task";
+ skills[19]!.skill!.manifest.description = "Prepare telescope observations";
+ skills[18]!.skill!.lastUsedAt = Number.MAX_SAFE_INTEGER;
+ const duplicate = structuredClone(skills[0]!);
+ duplicate.skill!.manifest.description = "shadowed description";
+ const visible = [...skills, duplicate, { skill: null, shadowed: [] }];
+ const index = skillsIndex(visible, [], "telescope", ["skill-17"]);
+ assert.match(index, /Showing 12 of 20/);
+ assert.ok(index.indexOf("**skill-19**") < index.indexOf("**skill-17**"));
+ assert.doesNotMatch(index, /skill-18|shadowed description|lastUsedAt/);
+ assert.match(index, /skills action list/);
+ assert.equal(rankedSkills(visible).length, 20);
+ assert.deepEqual(
+ rankedSkills(visible, "telescope", [], true).map((r) => r.skill!.manifest.name),
+ ["skill-19"],
+ );
+ assert.deepEqual(rankedSkills(visible, "unmatched", [], true), []);
+ assert.equal(skillsIndex([{ skill: null, shadowed: [] }]), "");
+});
+
+test("a natural-language Gmail request keeps its relevant bundled skill in the shortlist", () => {
+ const entries = readdirSync(new URL("../skills-seed/", import.meta.url), { withFileTypes: true })
+ .filter((entry) => entry.isDirectory())
+ .flatMap((entry) => {
+ const path = new URL(`../skills-seed/${entry.name}/SKILL.md`, import.meta.url);
+ try {
+ const manifest = parseSeedSkill(readFileSync(path, "utf8"));
+ const result = res(manifest.name, manifest.body);
+ result.skill!.manifest = manifest;
+ return [result];
+ } catch (error) {
+ if ((error as NodeJS.ErrnoException).code === "ENOENT") return [];
+ throw error;
+ }
+ });
+ const shortlist = skillsIndex(entries, [], "Please check my Gmail inbox and tell me what I need to do today");
+ assert.match(shortlist, /\*\*google-workspace\*\*/);
+});
diff --git a/test/skills-source-read.test.ts b/test/skills-source-read.test.ts
index 62b2830aa..1b76d7a0b 100644
--- a/test/skills-source-read.test.ts
+++ b/test/skills-source-read.test.ts
@@ -56,8 +56,11 @@ async function fixture(t: TestContext) {
test("published skill sources and assets read without a sandbox, respecting scope and archive", async (t) => {
const b = await fixture(t);
const skill = await b.publish("personal:U1", "PUBLISHED_BODY");
- assert.match(await b.turn("!sysprompt"), /\*\*source-helper\*\*/);
- assert.match(await b.turn("!skill source-helper"), /^\/.+\/\.agent-skills\/\w+\/source-helper\nPUBLISHED_BODY$/);
+ assert.match(await b.turn("!sysprompt source-helper"), /\*\*source-helper\*\*/);
+ assert.match(
+ await b.turn("!skill source-helper"),
+ /^\/.+\/\.agent-skills\/\w+\/[a-f0-9]{16}\/source-helper\nPUBLISHED_BODY$/,
+ );
assert.match(await b.turn("!skill source-helper references/example.txt"), /\nPUBLISHED_ASSET$/);
assert.equal(await b.turn("!skill-run source-helper cat {dir}/references/example.txt"), "PUBLISHED_ASSET");
assert.match(await b.turn("!skill source-helper", "U2"), /no skill file/);
@@ -119,6 +122,7 @@ test("a body read avoids sandbox work and a file request materializes that skill
let resolution = {
skill: {
id: "s",
+ version: 1,
scopeId: "personal:U1",
manifest: {
name: "source-helper",
@@ -180,12 +184,13 @@ test("a body read avoids sandbox work and a file request materializes that skill
visible[0] = resolution;
const loaded = await turn.useSkill("source-helper", "references/example.txt");
assert.equal(loaded.content, "v2");
- assert.equal(loaded.dir, "/workspace/.agent-skills/s/source-helper");
+ assert.match(loaded.dir!, /^\/workspace\/\.agent-skills\/s\/[a-f0-9]{16}\/source-helper$/);
+ const root = loaded.dir!.slice("/workspace/".length, -"/source-helper".length);
assert.equal(provisions, 1);
- assert.equal(files.get(".agent-skills/s/source-helper/references/example.txt"), "v2");
- files.set(".agent-skills/s/source-helper/references/example.txt", "local edit");
- await turn.useSkill("source-helper", "SKILL.md");
- assert.equal(files.get(".agent-skills/s/source-helper/references/example.txt"), "local edit");
+ assert.equal(files.get(`${root}/source-helper/references/example.txt`), "v2");
+ files.set(`${root}/source-helper/references/example.txt`, "local edit");
+ assert.equal((await turn.useSkill("source-helper", "SKILL.md")).dir, loaded.dir);
+ assert.equal(files.get(`${root}/source-helper/references/example.txt`), "local edit");
resolution.skill!.pack = { packId: "pack", commit: "c", upstreamName: "source-helper" };
resolution.screenedBundles = [
{ packId: "pack", commit: "c", hash: "pack-hash", files: [{ path: "lib.txt", content: "PACK_RESOURCE" }] },
@@ -194,9 +199,10 @@ test("a body read avoids sandbox work and a file request materializes that skill
await turn.provisionResource("resource-1");
assert.deepEqual(files, beforeResource);
const onResource = await turn.useSkill("source-helper", "SKILL.md", "resource-1");
- assert.equal(onResource.packDir, "/workspace/.agent-skills/s/.packs/pack");
+ assert.equal(onResource.dir, loaded.dir);
+ assert.equal(onResource.packDir, `/workspace/${root}/.packs/pack`);
assert.deepEqual(sandboxIds, [undefined, "resource-1"]);
- assert.equal(files.get(".agent-skills/s/.packs/pack/lib.txt"), "PACK_RESOURCE");
+ assert.equal(files.get(`${root}/.packs/pack/lib.txt`), "PACK_RESOURCE");
assert.equal(
[...files.keys()].some((path) => path.includes("/unrelated/")),
false,
@@ -209,7 +215,7 @@ test("pack assets run from the skills root and stay across turns", async (t) =>
const skill = await b.publish("personal:U1", "PACK_BODY", "source-pack");
const files = [{ path: "example.sh", content: "printf PACK_ASSET" }];
await b.skillBundles.put({ packId: "source-pack", commit: "c", files, hash: computeBundleHash(files) });
- assert.match(await b.turn("!skill source-helper"), /\.agent-skills\/\w+\/\.packs\/source-pack/);
+ assert.match(await b.turn("!skill source-helper"), /\.agent-skills\/\w+\/[a-f0-9]{16}\/\.packs\/source-pack/);
assert.equal(b.provisions(), 1);
assert.equal(await b.turn("!skill-run source-helper sh {dir}/../.packs/source-pack/example.sh"), "PACK_ASSET");
assert.equal(await b.turn("!run find . -name example.sh | wc -l | tr -d ' '"), "1");
diff --git a/test/system-prompt-order.test.ts b/test/system-prompt-order.test.ts
index 1a0fe274c..6b989c3e7 100644
--- a/test/system-prompt-order.test.ts
+++ b/test/system-prompt-order.test.ts
@@ -315,7 +315,7 @@ test("Open carries only the live actor's personal reads into a shared turn and a
});
});
-test("Open labels and audits a carried personal skill without granting it to the room", async () => {
+test("Open advertises the source and audits a carried skill read without granting it to the room", async () => {
const personal = scopeId("personal", actor.id);
const skills = createSkillStore();
const skill = await skills.create({
@@ -348,7 +348,23 @@ test("Open labels and audits a carried personal skill without granting it to the
text: "!sysprompt",
origin: { kind: "human" },
});
- assert.match(result.reply ?? "", /\*\*private-method\*\* \[from personal:U1\]/);
+ assert.match(result.reply ?? "", /Additional skill sources: personal:U1/);
+ assert.doesNotMatch(result.reply ?? "", /private-method|Use a private working method/);
+ const read = await orchestrator.handleTurn({
+ surface: "test",
+ actor,
+ conversation: {
+ kind: "channel",
+ threadRef: "C1:skill",
+ channelRef: "C1",
+ audience: [actor],
+ publishMembers: [actor],
+ },
+ text: "!skill private-method",
+ origin: { kind: "human" },
+ });
+ assert.equal(read.status, "ok", read.reason);
+ assert.equal(read.reply, "Keep the method private.");
const event = (await auditLog.events()).find(
(candidate) => candidate.action === "sharing.cross_context_read" && candidate.resource === `skill:${skill.id}`,
);
@@ -472,7 +488,7 @@ test("the system prompt is byte-identical across two turns a minute apart; the c
!environmentOf(second.reply ?? "").includes(`\n## ${title}\n`),
`unchanged "## ${title}" must not repeat`,
);
- assert.ok(!systemOf(first.reply ?? "").includes(`\n## ${title}\n`));
+ if (title !== "Skills") assert.ok(!systemOf(first.reply ?? "").includes(`\n## ${title}\n`));
}
for (const title of ["Sandbox environment profile", "The user's local time", "What you remember", "Your logins"]) {
assert.ok(
@@ -877,11 +893,11 @@ test("Open uses the exact skill snapshot that passed screening despite an in-fli
audience: [actor],
publishMembers: [actor],
},
- text: "!sysprompt",
+ text: "!skill snapshot-method",
});
assert.equal(result.status, "ok", result.reason);
assert.equal(updated, true);
- assert.match(result.reply ?? "", /SAFE_DESCRIPTION/);
+ assert.match(result.reply ?? "", /SAFE_BODY/);
assert.doesNotMatch(result.reply ?? "", /UNSCREENED_UPDATE|UNSCREENED_BODY/);
});
diff --git a/test/turn-context.test.ts b/test/turn-context.test.ts
index d9321082a..11abd772b 100644
--- a/test/turn-context.test.ts
+++ b/test/turn-context.test.ts
@@ -164,3 +164,60 @@ test("ambiguous file aliases fail closed in the shared reader", async () => {
assert.ok(result && "error" in result);
assert.match(result.error, /ambiguous shared handle/);
});
+
+test("skill discovery refreshes carried membership and explicit grants in the same turn", async () => {
+ const { input, acl, removeMember } = await fixture();
+ const seen: Array<{ scopes: readonly string[]; grants: unknown }> = [];
+ input.skills = {
+ visibleFor: async (scopes, grants) => {
+ seen.push({ scopes: [...scopes], grants });
+ return [];
+ },
+ } as Pick<NonNullable<typeof input.skills>, "visibleFor"> as NonNullable<typeof input.skills>;
+ const context = await resolveTurnContext(input);
+ assert.deepEqual((await context.listSkills()).sharingSources, ["channel:eng"]);
+ await acl.grant(
+ {
+ ownerScopeId: "personal:owner",
+ ref: "skill:new",
+ granteeScopeId: "personal:alice",
+ permission: "read",
+ grantedBy: "owner",
+ },
+ "owner",
+ );
+ await context.listSkills();
+ assert.deepEqual(seen[1]!.grants, [{ id: "new", ownerScopeId: "personal:owner" }]);
+ await acl.revoke("personal:owner", "skill:new", "personal:alice", "owner");
+ removeMember();
+ assert.deepEqual((await context.listSkills()).sharingSources, []);
+ assert.deepEqual(seen[2], { scopes: ["personal:alice", "org:test"], grants: [] });
+});
+
+test("source selection precedes name shadowing and preserves skill-level grants", async () => {
+ const { input, acl } = await fixture();
+ await acl.grant(
+ {
+ ownerScopeId: "personal:owner",
+ ref: "skill:one",
+ granteeScopeId: "personal:alice",
+ permission: "read",
+ grantedBy: "owner",
+ },
+ "owner",
+ );
+ const seen: Array<{ scopes: readonly string[]; grants: unknown }> = [];
+ input.skills = {
+ visibleFor: async (scopes, grants) => {
+ seen.push({ scopes: [...scopes], grants });
+ return [];
+ },
+ } as Pick<NonNullable<typeof input.skills>, "visibleFor"> as NonNullable<typeof input.skills>;
+ const context = await resolveTurnContext(input);
+ await context.listSkills(["org:test"]);
+ assert.deepEqual(seen[0], { scopes: ["org:test"], grants: [] });
+ await context.listSkills(["personal:owner"]);
+ assert.deepEqual(seen[1], { scopes: [], grants: [{ id: "one", ownerScopeId: "personal:owner" }] });
+ await context.listSkills(["personal:stranger"]);
+ assert.deepEqual(seen[2], { scopes: [], grants: [] });
+});