Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

feat(skills): let bots import a skill from GitHub or skills.sh

AdityaUmale558047fffa00
diff --git a/server/drivers/agents-call.test.ts b/server/drivers/agents-call.test.ts
index eef8f03003..d16c29e2da 100644
--- a/server/drivers/agents-call.test.ts
+++ b/server/drivers/agents-call.test.ts
@@ -222,12 +222,27 @@ describe("skill_manage", () => {
const sent: unknown[] = [];
const ctx = context({ client: { api: async (path) => { sent.push(path); return {}; }, apiResponse: async () => ({ ok: true, status: 200, body: {} }) } });
expect(await callTool("skill_manage", { action: "save" }, ctx)).toEqual({
- text: 'skill_manage action must be "create", "update", "enable", "disable" or "delete". It takes action, skill_name, skill_md, references, gist, base_revision, source.',
+ text: 'skill_manage action must be "create", "update", "import", "enable", "disable" or "delete". It takes action, skill_name, skill_md, references, gist, base_revision, source.',
isError: true,
});
expect((await callTool("skill_manage", { action: "create", source: "conversation" }, ctx)).text).toContain("---\\nname: file-expense\\ndescription:");
expect(sent).toEqual([]);
});
+
+ it("sends import with only its source, so the app fetches the skill and it gets the same card as create", async () => {
+ const sent: Array<{ path: string; body: any }> = [];
+ const ctx = context({ client: { api: async (path, init) => { sent.push({ path, body: JSON.parse(String(init?.body)) }); return { name: "pdf" }; }, apiResponse: async () => ({ ok: true, status: 200, body: {} }) } });
+ expect((await callTool("skill_manage", { action: "import" }, ctx)).text).toContain("skill_manage needs source");
+ const result = await callTool("skill_manage", { action: "import", source: "https://skills.sh/acme/skills/pdf" }, ctx);
+ expect(result.text).toContain("A confirmation card is now visible to the user for new skill “pdf”.");
+ expect(sent).toEqual([{ path: "/api/internal/skills/stage", body: expect.objectContaining({ action: "import", skill_md: "", source: "https://skills.sh/acme/skills/pdf" }) }]);
+ });
+
+ it("tells bots they can import a skill from GitHub or skills.sh", () => {
+ const tool = availableTools({ ...catalogProfileFromEnv({}), skillAuthoring: true }).find((entry) => entry.name === "skill_manage");
+ expect(tool?.description).toContain("import one from GitHub or skills.sh");
+ expect(tool?.inputSchema.properties).toMatchObject({ action: { enum: expect.arrayContaining(["import"]) } });
+ });
});
describe("app_settings", () => {
diff --git a/server/drivers/agents-call.ts b/server/drivers/agents-call.ts
index 4e2fc5c9d3..f45176e064 100644
--- a/server/drivers/agents-call.ts
+++ b/server/drivers/agents-call.ts
@@ -919,16 +919,16 @@ export async function callTool(called: string, input: Json, context: ToolCallCon
text: `A confirmation card is now visible to the user to ${verb} skill “${skillName}”. Nothing changes until they approve it. End this turn and wait for the decision.`,
};
}
- if (args.action !== "create" && args.action !== "update") {
- return { text: `skill_manage action must be "create", "update", "enable", "disable" or "delete". It takes ${argumentNames(fullInputSchema(name))}.`, isError: true };
+ if (args.action !== "create" && args.action !== "update" && args.action !== "import") {
+ return { text: `skill_manage action must be "create", "update", "import", "enable", "disable" or "delete". It takes ${argumentNames(fullInputSchema(name))}.`, isError: true };
}
const skillMd = typeof args.skill_md === "string" ? args.skill_md : "";
- if (!skillMd.trim()) {
+ if (!skillMd.trim() && args.action !== "import") {
return { text: 'skill_manage needs skill_md: the full SKILL.md including YAML frontmatter, e.g. "---\\nname: file-expense\\ndescription: Files an expense in the company portal.\\n---\\n\\n# File expense\\n".', isError: true };
}
const source = typeof args.source === "string" ? args.source.trim() : "";
if (!source) {
- return { text: 'skill_manage needs source: the URL, folder, or "conversation" used to author the skill.', isError: true };
+ return { text: 'skill_manage needs source: the URL, folder, or "conversation" used to author the skill (for import, the GitHub or skills.sh link).', isError: true };
}
const skillName = typeof args.skill_name === "string" ? args.skill_name.trim() : "";
if (args.action === "update" && !skillName) {
diff --git a/server/drivers/agents-catalog-goldens/full.tools-list.json b/server/drivers/agents-catalog-goldens/full.tools-list.json
index 07b568d3ff..984549988b 100644
--- a/server/drivers/agents-catalog-goldens/full.tools-list.json
+++ b/server/drivers/agents-catalog-goldens/full.tools-list.json
@@ -2075,7 +2075,7 @@
},
{
"name": "skill_manage",
- "description": "Create or update a reusable skill (SKILL.md), or turn one of your own skills on or off, or delete it. Never change a skill unless the person explicitly asked for that named skill. It applies at once, with an Undo where possible: read the result before saying it did. It never raises another bot's execution permissions.",
+ "description": "Create or update a reusable skill (SKILL.md), import one from GitHub or skills.sh (action import with source; same review as create, brings SKILL.md and references/*.md), or turn one of your own skills on or off, or delete it. Never change a skill unless the person explicitly asked for that named skill. It applies at once, with an Undo where possible: read the result before saying it did. It never raises another bot's execution permissions.",
"inputSchema": {
"type": "object",
"additionalProperties": false,
@@ -2085,6 +2085,7 @@
"enum": [
"create",
"update",
+ "import",
"enable",
"disable",
"delete"
@@ -2092,7 +2093,7 @@
},
"skill_name": {
"type": "string",
- "description": "Every action but create: the exact name from skills_list."
+ "description": "Every action but create and import: the exact name from skills_list."
},
"skill_md": {
"type": "string",
@@ -2130,7 +2131,7 @@
},
"source": {
"type": "string",
- "description": "create or update: the URL, folder or 'conversation' it came from."
+ "description": "create or update: the URL, folder or 'conversation' it came from. import: owner/repo, a GitHub link to the skill's folder or SKILL.md, or a skills.sh link."
}
},
"required": [
diff --git a/server/drivers/agents-catalog-goldens/profiles.json b/server/drivers/agents-catalog-goldens/profiles.json
index a758c9e537..028729415e 100644
--- a/server/drivers/agents-catalog-goldens/profiles.json
+++ b/server/drivers/agents-catalog-goldens/profiles.json
@@ -234,8 +234,8 @@
]
},
"skills": {
- "bytes": 60294,
- "sha256": "9f375e95e3c2d37ded718d9d416924cd4749007c665b404c037e79e2dbcde7c6",
+ "bytes": 60529,
+ "sha256": "6b06e9380eaed93ff978f08626a7371600ff01860309efca4168581bb184144d",
"tools": [
"tool_result_read",
"list_room_targets",
@@ -293,8 +293,8 @@
]
},
"skills+voice": {
- "bytes": 61075,
- "sha256": "122dd36954b22a3987a28fa0bbad80eea7270c9164ecaf04ccb76c20bf61b921",
+ "bytes": 61310,
+ "sha256": "90e0c7924a61ccc9fd458d75bd4c13d9e1f94ca3a0d2f6fc12280933971e8c88",
"tools": [
"tool_result_read",
"list_room_targets",
@@ -353,8 +353,8 @@
]
},
"skills+shared": {
- "bytes": 62559,
- "sha256": "f9ebb60b88ece0249462ae2d6a1c5cf4e7a7c80f1c5ca6dcf4029fbb11f2443e",
+ "bytes": 62794,
+ "sha256": "f99889854ec7ec4ec854cd2e94492c66ba382f0e5b29b3e04497d66077e97c5c",
"tools": [
"tool_result_read",
"list_shared_computers",
@@ -414,8 +414,8 @@
]
},
"skills+shared+voice": {
- "bytes": 63340,
- "sha256": "eb48a68a1a4802210e7d38685823922a3676e34b47c8f09c6b83d376989c846e",
+ "bytes": 63575,
+ "sha256": "549b46bda2bbc7ad6dc2ac057fbcb784d2298308178a6bd78102554b50dcfc5d",
"tools": [
"tool_result_read",
"list_shared_computers",
@@ -682,8 +682,8 @@
]
},
"skills+non-chief": {
- "bytes": 51877,
- "sha256": "ae477368a2fd375b9d3171b4ce06486efe575667cdb251a285a05f0cf715bdab",
+ "bytes": 52112,
+ "sha256": "6b28e7e612009b74b2c071cd6d9e615650b6972036d96ca23747e7e1cd9b218b",
"tools": [
"tool_result_read",
"list_room_targets",
@@ -734,8 +734,8 @@
]
},
"skills+voice+non-chief": {
- "bytes": 52658,
- "sha256": "6c656392c283c6b27538e5bb29e00ef0a2f014e19d909eb574fafb1f5da7d730",
+ "bytes": 52893,
+ "sha256": "93ad38c1f15d69cf603e4fda3e98366444399195c66b77a3adfecf7832fb643e",
"tools": [
"tool_result_read",
"list_room_targets",
@@ -787,8 +787,8 @@
]
},
"skills+shared+non-chief": {
- "bytes": 54142,
- "sha256": "ccdd9890eed20f02c8bcf0cdc2aa74489b3cbe45e5dc759cc1cc8f321dcce487",
+ "bytes": 54377,
+ "sha256": "5c607bcc8a5e2e0be62d808154ece470630b392cc01c76d1b3191ab724378189",
"tools": [
"tool_result_read",
"list_shared_computers",
@@ -841,8 +841,8 @@
]
},
"skills+shared+voice+non-chief": {
- "bytes": 54923,
- "sha256": "1f70489c75f0f8998333b8780730848d18170bc99cb02f679db25a8931645fd9",
+ "bytes": 55158,
+ "sha256": "2e877006de5e8ad5a692236dabe0862ff2f8b0fd3d04294d260f2bca6117b5d5",
"tools": [
"tool_result_read",
"list_shared_computers",
@@ -896,8 +896,8 @@
]
},
"skills+shared+voice+cloud-home": {
- "bytes": 63106,
- "sha256": "1966d8684d3168ca7be275f793c59211d246e5a9ddf622c16bf48730571b34c6",
+ "bytes": 63341,
+ "sha256": "5cb156d775aa20677b8ea5b63e3b3bf4a2bbaefe25d706dda17ff548a9e99fe2",
"tools": [
"tool_result_read",
"list_shared_computers",
@@ -958,8 +958,8 @@
]
},
"skills+shared+voice+non-chief+cloud-home": {
- "bytes": 54689,
- "sha256": "f3dce8fe1f34aa42a4f4e0bb55711267b0471956347c8f87c912b6ced09d7887",
+ "bytes": 54924,
+ "sha256": "3af6d73ec7fb10a3120f61cd31900973d2773229fab382252c3fa1ce9703e6b6",
"tools": [
"tool_result_read",
"list_shared_computers",
@@ -1013,8 +1013,8 @@
]
},
"skills+shared+voice+x": {
- "bytes": 67179,
- "sha256": "ba651aebfc222fdefa0dc4ac7dc9cc8e6752b6d1e2c5caaaca472162d4d0fe73",
+ "bytes": 67414,
+ "sha256": "a8d8fbc59c415b5145cda18e902772e5454a985d685e0ee12af4cc121e500130",
"tools": [
"tool_result_read",
"list_shared_computers",
@@ -1079,8 +1079,8 @@
]
},
"skills+shared+voice+x+team": {
- "bytes": 67179,
- "sha256": "ba651aebfc222fdefa0dc4ac7dc9cc8e6752b6d1e2c5caaaca472162d4d0fe73",
+ "bytes": 67414,
+ "sha256": "a8d8fbc59c415b5145cda18e902772e5454a985d685e0ee12af4cc121e500130",
"tools": [
"tool_result_read",
"list_shared_computers",
@@ -1145,8 +1145,8 @@
]
},
"skills+shared+voice+x+team+images": {
- "bytes": 67952,
- "sha256": "dc5c8cf6bb049b803ee7b64d225acc94593e0fa54ec0f9f4f5f1d319366d26a0",
+ "bytes": 68187,
+ "sha256": "1c96e81c2729bb12fdfef62713ef6499eb09bfcb3a8f5d00a8157464d8bf2d29",
"tools": [
"tool_result_read",
"list_shared_computers",
@@ -1328,8 +1328,8 @@
]
},
"skills+shared+voice+mausbot": {
- "bytes": 63991,
- "sha256": "24df79984b3017182c1a5fb62c41a1c6ed1758325da1863bced4ccf3c09c9b78",
+ "bytes": 64226,
+ "sha256": "ca7765649251275d2961fa65c0d5b49c67cf8f5d36dbe5067557be5e8aabd01c",
"tools": [
"tool_result_read",
"list_shared_computers",
@@ -1601,8 +1601,8 @@
]
},
"skills+shared+voice+x+team+images+hosting": {
- "bytes": 69815,
- "sha256": "924a7b17b4a013427a66af3c7990648b2b5783d1d918ca6f3f437322354046ff",
+ "bytes": 70050,
+ "sha256": "3af9612934e72eeeb7c81f6f69c20231f931acbc31342b84f94d2579741e6520",
"tools": [
"tool_result_read",
"list_shared_computers",
diff --git a/server/drivers/agents-catalog.ts b/server/drivers/agents-catalog.ts
index 9bfb205b9b..103d7edbad 100644
--- a/server/drivers/agents-catalog.ts
+++ b/server/drivers/agents-catalog.ts
@@ -719,13 +719,13 @@ const TOOL_DEFINITIONS = [
{
name: "skill_manage",
description:
- "Create or update a reusable skill (SKILL.md), or turn one of your own skills on or off, or delete it. Never change a skill unless the person explicitly asked for that named skill." + APPLIES_OUTCOME,
+ "Create or update a reusable skill (SKILL.md), import one from GitHub or skills.sh (action import with source; same review as create, brings SKILL.md and references/*.md), or turn one of your own skills on or off, or delete it. Never change a skill unless the person explicitly asked for that named skill." + APPLIES_OUTCOME,
inputSchema: {
type: "object",
additionalProperties: false,
properties: {
- action: { type: "string", enum: ["create", "update", "enable", "disable", "delete"] },
- skill_name: { type: "string", description: "Every action but create: the exact name from skills_list." },
+ action: { type: "string", enum: ["create", "update", "import", "enable", "disable", "delete"] },
+ skill_name: { type: "string", description: "Every action but create and import: the exact name from skills_list." },
skill_md: { type: "string", description: "create or update: the full SKILL.md with its YAML frontmatter." },
references: {
type: "array",
@@ -743,7 +743,7 @@ const TOOL_DEFINITIONS = [
},
gist: { type: "string", description: "Optional one-line summary of the change." },
base_revision: { type: "string", description: "To update a skill shared with your team: its revision from skills_list." },
- source: { type: "string", description: "create or update: the URL, folder or 'conversation' it came from." },
+ source: { type: "string", description: "create or update: the URL, folder or 'conversation' it came from. import: owner/repo, a GitHub link to the skill's folder or SKILL.md, or a skills.sh link." },
},
required: ["action"],
},
diff --git a/server/drivers/agents-proxy.test.ts b/server/drivers/agents-proxy.test.ts
index 05b9736d20..7dedd3a5a4 100644
--- a/server/drivers/agents-proxy.test.ts
+++ b/server/drivers/agents-proxy.test.ts
@@ -2107,7 +2107,7 @@ describe("agents-proxy MCP surface", () => {
const manage = list.result.tools.find((t: { name: string }) => t.name === "skill_manage");
expect(JSON.stringify(manage.inputSchema)).not.toMatch(/"(oneOf|anyOf|allOf|const|format)":/);
expect(manage.inputSchema.required).toEqual(["action"]);
- expect(manage.inputSchema.properties.action.enum).toEqual(["create", "update", "enable", "disable", "delete"]);
+ expect(manage.inputSchema.properties.action.enum).toEqual(["create", "update", "import", "enable", "disable", "delete"]);
const listed = await callTool("skills_list", {});
expect(listed.result.content[0].text).toContain("file-expense");
diff --git a/server/index.test.ts b/server/index.test.ts
index 483b5888ae..e175afd586 100644
--- a/server/index.test.ts
+++ b/server/index.test.ts
@@ -12144,6 +12144,26 @@ describe("harness HTTP API", () => {
}
});
+ it("refuses a skill_manage import it cannot fetch with the reason, and stages nothing", async () => {
+ const bot = (await api("POST", "/api/bots", {})).body.bot;
+ try {
+ const token = await mintTestCapability(BASE, bot.id, bot.threadId, { skillAuthoring: true });
+ const post = async (body: Record<string, unknown>) => {
+ const response = await fetch(`${BASE}/api/internal/skills/stage`, {
+ method: "POST",
+ headers: { authorization: `Bearer ${token}`, "content-type": "application/json" },
+ body: JSON.stringify({ fromBotId: bot.id, fromThreadId: bot.threadId, action: "import", ...body }),
+ });
+ return { status: response.status, error: ((await response.json()) as { error: string }).error };
+ };
+ expect(await post({})).toEqual({ status: 422, error: expect.stringContaining("skill_manage import needs source") });
+ expect(await post({ source: "not a link" })).toEqual({ status: 422, error: expect.stringMatching(/^Could not import a skill from not a link: /) });
+ expect((await api("GET", `/api/bots/${bot.id}/skills`)).body.skills).toEqual([]);
+ } finally {
+ await api("DELETE", `/api/bots/${bot.id}`);
+ }
+ });
+
it("turns a bot's own skill on, off or deletes it at once, with a receipt the person can undo", async () => {
const bot = (await api("POST", "/api/bots", {})).body.bot;
try {
diff --git a/server/index.ts b/server/index.ts
index d0fa5c8057..d62880b08c 100644
--- a/server/index.ts
+++ b/server/index.ts
@@ -386,7 +386,7 @@ import {
} from "./skills.ts";
import { fetchSkillFromSource } from "./skill-fetch.ts";
import { ensureTaskWorkspaceWithSkills, harnessSkillLinks } from "./skill-task-links.ts"; import { changedWords, createLendingLifts, handedInSince } from "./host/lending-lifts.ts"; import { deviceWord } from "./lent-computers.ts";
-import { parseSkillManageReferences, previousSkillVersion, skillCardCopy, skillRequestReferences } from "./skill-request-card.ts";
+import { importedSkillRequest, parseSkillManageReferences, previousSkillVersion, skillCardCopy, skillRequestReferences } from "./skill-request-card.ts";
import { skillReferencesSha256 } from "./skill-storage.ts";
import { createSkillsLibraryHost } from "./host/skills-library.ts";
import { skillExport } from "./skill-export.ts";
@@ -13525,18 +13525,18 @@ const handleRequest = async (req: IncomingMessage, res: ServerResponse) => {
if (method === "POST" && path === "/api/internal/skills/stage") {
if (!skillAuthoringEnabled(cfg)) return json(res, 403, { error: "skill authoring is not enabled in Settings" });
if (!internalCapability.skillAuthoring) return json(res, 403, { error: store.groupByThread(internalCapability.threadId) ? roomSkillsRefusal(Boolean(internalCapability.roomHandoffId)) : "skill authoring is not enabled for this turn" });
- const body = await readInternalBody();
- const from = internalSender;
- const fromThreadId = internalCapability.threadId;
+ const received = await readInternalBody();
+ const from = internalSender, fromThreadId = internalCapability.threadId;
if (!connectorThread(from.id, fromThreadId)) {
return json(res, 403, { error: "source conversation does not belong to sender" });
}
const direct = appliesDirectly(from.id, fromThreadId);
- if (isSkillSwitchAction(body.action)) { const staged = skillSwitch.stage(from, fromThreadId, body.action, body, direct); return json(res, staged.status, staged.body); }
+ if (isSkillSwitchAction(received.action)) { const staged = skillSwitch.stage(from, fromThreadId, received.action, received, direct); return json(res, staged.status, staged.body); }
const persistence = skillProposalPersistence(from.id, fromThreadId, !direct);
if (!persistence.ok) return json(res, persistence.status, { error: persistence.error });
+ const body = await importedSkillRequest(received); if ("importError" in body) return json(res, 422, { error: body.importError }); if (!internalCapabilityIsActive(internalCapability)) return json(res, 401, { error: TURN_ENDED_REFUSAL });
const action = body.action === "create" || body.action === "update" ? body.action : "";
- if (!action) return json(res, 400, { error: 'action must be "create" or "update"' });
+ if (!action) return json(res, 400, { error: 'action must be "create", "update" or "import"' });
const skillMd = typeof body.skill_md === "string" ? body.skill_md : "";
if (!skillMd.trim()) {
return json(res, 400, { error: 'skill_manage needs skill_md: the full SKILL.md including YAML frontmatter, for example ---\\nname: file-expense\\ndescription: Files an expense in the company portal.\\n---\\n\\n# File expense\\n' });
diff --git a/server/skill-request-card.test.ts b/server/skill-request-card.test.ts
new file mode 100644
index 0000000000..65b13050ad
--- /dev/null
+++ b/server/skill-request-card.test.ts
@@ -0,0 +1,43 @@
+import { describe, expect, it } from "vitest";
+
+import { importedSkillRequest } from "./skill-request-card.ts";
+import { fakeGitHub } from "./testing/fake-github.ts";
+
+const SKILL = (name: string) => `---\nname: ${name}\ndescription: Does ${name} things.\n---\n\n# ${name}\n`;
+const github = fakeGitHub({
+ "acme/skills": {
+ "skills/pdf/SKILL.md": SKILL("pdf"),
+ "skills/pdf/references/forms.md": "# Forms\n",
+ "skills/pdf/scripts/fill.py": { content: "print('fill')\n", executable: true },
+ "skills/docx/SKILL.md": SKILL("docx"),
+ },
+ "acme/notes": { "references/forms.md": "# Forms\n" },
+});
+const importing = (source?: string) => importedSkillRequest({ action: "import", skill_name: "ignored", ...(source ? { source } : {}) }, github.fetch);
+
+describe("importedSkillRequest", () => {
+ it("leaves every action but import as it came", async () => {
+ const body = { action: "create", skill_md: SKILL("pdf"), source: "conversation" };
+ expect(await importedSkillRequest(body, github.fetch)).toBe(body);
+ expect(github.requests).toEqual([]);
+ });
+
+ it("turns an import into a create with the fetched SKILL.md, its references and its source, and says what was left behind", async () => {
+ const body = await importing("https://github.com/acme/skills/tree/main/skills/pdf");
+ expect(body).toMatchObject({
+ action: "create",
+ skill_name: undefined,
+ skill_md: SKILL("pdf"),
+ references: [{ path: "references/forms.md", content: "# Forms\n" }],
+ source: "github.com/acme/skills@main/skills/pdf",
+ gist: expect.stringMatching(/Not brought in \(only SKILL\.md and references\/\*\.md are\): scripts\/fill\.py$/),
+ });
+ });
+
+ it("refuses with a clear error when the source is missing, wrong, has several skills or none", async () => {
+ expect(await importing()).toEqual({ importError: expect.stringContaining("needs source") });
+ expect(await importing("not a link")).toEqual({ importError: expect.stringMatching(/^Could not import a skill from not a link: /) });
+ expect(await importing("acme/skills")).toEqual({ importError: expect.stringContaining("acme/skills has 2 skills (") });
+ expect(await importing("acme/notes")).toEqual({ importError: expect.stringMatching(/^Could not import a skill from acme\/notes: /) });
+ });
+});
diff --git a/server/skill-request-card.ts b/server/skill-request-card.ts
index aafb00c856..98a5d11376 100644
--- a/server/skill-request-card.ts
+++ b/server/skill-request-card.ts
@@ -1,7 +1,9 @@
import { createHash } from "node:crypto";
import { redactSecretsInText } from "./redact.ts";
-import { listSkills, readSkillFile, readSkillReferences } from "./skills.ts";
+import { fetchSkillFromSource } from "./skill-fetch.ts";
+import { isSkillReferencePath, MAX_SKILL_REFERENCES, STAGED_SKILL_REFERENCE_MAX_BYTES } from "./skill-storage.ts";
+import { listSkills, readSkillFile, readSkillReferences, STAGED_GIST_MAX } from "./skills.ts";
import type { SkillRequestCardData } from "../shared/skill-request.ts";
type SkillFile = { path: string; content: string };
@@ -49,6 +51,42 @@ export function parseSkillManageReferences(value: unknown): SkillFile[] | { erro
return references.map((file) => ({ path: file.path.trim(), content: file.content }));
}
+/**
+ * skill_manage action "import": fetch the skill the way the Skills page Import box does (HTTPS from the app, no git on
+ * the person's computer) and turn it into a create request, so it gets the same card, scan and name checks as one the
+ * bot wrote. Only SKILL.md and its references/<topic>.md files come in; the card says what was left behind.
+ */
+export async function importedSkillRequest<T extends Record<string, unknown>>(body: T, fetcher: typeof fetch = fetch): Promise<T | { importError: string }> {
+ if (body.action !== "import") return body;
+ const source = typeof body.source === "string" ? body.source.trim() : "";
+ if (!source) return { importError: "skill_manage import needs source: owner/repo, a GitHub link to a skill folder or its SKILL.md, or a skills.sh link." };
+ const fetched = await fetchSkillFromSource(source, fetcher);
+ if ("error" in fetched) return { importError: `Could not import a skill from ${source}: ${fetched.error}` };
+ if (fetched.skills.length !== 1) {
+ const names = fetched.skills.map((skill) => skill.source.split("/").pop()).join(", ");
+ return { importError: `${source} has ${fetched.skills.length} skills (${names}). Import one at a time: pass the link to that skill's folder or its skills.sh page.` };
+ }
+ const skill = fetched.skills[0]!;
+ const skillMd = skill.files.find((file) => file.path === "SKILL.md");
+ if (!skillMd) return { importError: `${source} has no SKILL.md to import.` };
+ const references = skill.files
+ .filter((file) => isSkillReferencePath(file.path) && file.content.byteLength <= STAGED_SKILL_REFERENCE_MAX_BYTES)
+ .slice(0, MAX_SKILL_REFERENCES);
+ const left = [...skill.files.filter((file) => file !== skillMd && !references.includes(file)).map((file) => file.path), ...skill.skipped.map((file) => file.path)];
+ const gist = left.length
+ ? `Imported from ${skill.source}. Not brought in (only SKILL.md and references/*.md are): ${left.join(", ")}`.slice(0, STAGED_GIST_MAX)
+ : body.gist;
+ return {
+ ...body,
+ action: "create",
+ skill_name: undefined,
+ skill_md: skillMd.content.toString("utf8"),
+ references: references.map((file) => ({ path: file.path, content: file.content.toString("utf8") })),
+ source: skill.source,
+ gist,
+ };
+}
+
/** Any scrub change to the SKILL.md or a reference drops sha256, so the card is deny-only and never approves bytes it did not show. */
export function scrubbedSkillRequest(request: SkillRequestCardData): SkillRequestCardData {
const originalPreview = request.preview;