Skip to content

Commit 343b128

Browse files
committed
fix(skills): simplify library dispatch and preserve resource identity
Share the Workshop schema and descriptor across local and worker paths, remove redundant adapters and UI/import/CLI duplication, and preserve lossless directory identities in remote skill transfer. The cleanup removes 114 production lines; a child-process regression proves adjacent large file indexes cannot share authority.
1 parent ad0aba2 commit 343b128

12 files changed

Lines changed: 196 additions & 263 deletions

File tree

‎packages/gateway-protocol/src/schema/worker-skill-workshop.ts‎

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ export const WorkerSkillWorkshopBindingSchema = Type.Object(
99
{ additionalProperties: false },
1010
);
1111
export type WorkerSkillWorkshopBinding = Static<typeof WorkerSkillWorkshopBindingSchema>;
12-
export const WorkerSkillWorkshopParamsSchema = Type.Object(
12+
export const SkillLibraryWorkshopSchema = Type.Object(
1313
{
14-
toolCallId: Type.String({ minLength: 1, maxLength: 256 }),
1514
action: Type.Enum(
1615
[
1716
"list",
@@ -27,14 +26,51 @@ export const WorkerSkillWorkshopParamsSchema = Type.Object(
2726
] as const,
2827
{ type: "string" },
2928
),
30-
skillId: Type.Optional(Type.String({ maxLength: 36 })),
31-
expectedRevision: Type.Optional(Type.String({ pattern: "^[a-f0-9]{64}$" })),
29+
target: Type.Optional(Type.Literal("personal")),
30+
skill_id: Type.Optional(Type.String({ maxLength: 36 })),
31+
expected_revision: Type.Optional(Type.String({ pattern: "^[a-f0-9]{64}$" })),
3232
revision: Type.Optional(Type.String({ pattern: "^[a-f0-9]{64}$" })),
33-
slug: Type.Optional(Type.String({ maxLength: 63 })),
34-
content: Type.Optional(Type.String({ maxLength: 32768 })),
35-
artifactPath: Type.Optional(Type.String({ maxLength: 512 })),
36-
files: Type.Optional(Type.Array(SkillLibraryFileSchema, { maxItems: 32 })),
37-
deleteFiles: Type.Optional(Type.Array(Type.String({ maxLength: 512 }), { maxItems: 32 })),
33+
name: Type.Optional(
34+
Type.String({
35+
maxLength: 63,
36+
description:
37+
"Human-facing slug, not the generated command name. Omit on update to preserve it.",
38+
}),
39+
),
40+
proposal_content: Type.Optional(Type.String({ maxLength: 32768 })),
41+
artifact_path: Type.Optional(
42+
Type.String({
43+
maxLength: 512,
44+
description:
45+
"Read one whole UTF-8 artifact; defaults to SKILL.md. Binary or oversized files require the UI or CLI.",
46+
}),
47+
),
48+
files: Type.Optional(
49+
Type.Array(
50+
Type.Object(
51+
{ ...SkillLibraryFileSchema.properties, content: Type.String({ maxLength: 32768 }) },
52+
{ additionalProperties: false },
53+
),
54+
{
55+
maxItems: 32,
56+
description:
57+
"Named support-file upserts. Other files and omitted executable flags are preserved.",
58+
},
59+
),
60+
),
61+
delete_files: Type.Optional(
62+
Type.Array(Type.String({ maxLength: 512 }), {
63+
maxItems: 32,
64+
description: "Exact supporting paths to remove intentionally; never SKILL.md.",
65+
}),
66+
),
67+
},
68+
{ additionalProperties: false },
69+
);
70+
export const WorkerSkillWorkshopParamsSchema = Type.Object(
71+
{
72+
toolCallId: Type.String({ minLength: 1, maxLength: 256 }),
73+
arguments: SkillLibraryWorkshopSchema,
3874
},
3975
{ additionalProperties: false },
4076
);

‎src/agents/tools/skill-workshop-tool-library.ts‎

Lines changed: 14 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,22 @@
1-
import { Type, type Static } from "typebox";
1+
import { Type } from "typebox";
22
import { Value } from "typebox/value";
3-
import { SkillLibraryFileSchema } from "../../../packages/gateway-protocol/src/schema/skill-library.js";
3+
import { SkillLibraryWorkshopSchema } from "../../../packages/gateway-protocol/src/schema/worker-skill-workshop.js";
44
import type { SkillLibraryAuthoringCapability } from "../../skills/library/authoring.js";
55
import { decodeSkillLibraryFile, validateSkillLibraryPath } from "../../skills/library/bundle.js";
6-
import { stringEnum } from "../schema/typebox.js";
76
import { ToolInputError, type AnyAgentTool } from "./common.js";
87
import { textResult } from "./tool-results.js";
98

10-
export const SkillLibraryWorkshopSchema = Type.Object(
11-
{
12-
action: stringEnum([
13-
"list",
14-
"read",
15-
"create",
16-
"update",
17-
"share",
18-
"unshare",
19-
"transfer",
20-
"activate",
21-
"remove",
22-
"rollback",
23-
] as const),
24-
target: Type.Optional(Type.Literal("personal")),
25-
skill_id: Type.Optional(Type.String({ maxLength: 36 })),
26-
expected_revision: Type.Optional(Type.String({ pattern: "^[a-f0-9]{64}$" })),
27-
revision: Type.Optional(Type.String({ pattern: "^[a-f0-9]{64}$" })),
28-
name: Type.Optional(
29-
Type.String({
30-
maxLength: 63,
31-
description:
32-
"Human-facing slug, not the generated command name. Omit on update to preserve it.",
33-
}),
34-
),
35-
proposal_content: Type.Optional(Type.String({ maxLength: 32768 })),
36-
artifact_path: Type.Optional(
37-
Type.String({
38-
maxLength: 512,
39-
description:
40-
"Read one whole UTF-8 artifact; defaults to SKILL.md. Binary or oversized files require the UI or CLI.",
41-
}),
42-
),
43-
files: Type.Optional(
44-
Type.Array(
45-
Type.Object(
46-
{ ...SkillLibraryFileSchema.properties, content: Type.String({ maxLength: 32768 }) },
47-
{ additionalProperties: false },
48-
),
49-
{
50-
maxItems: 32,
51-
description:
52-
"Named support-file upserts. Other files and omitted executable flags are preserved.",
53-
},
54-
),
55-
),
56-
delete_files: Type.Optional(
57-
Type.Array(Type.String({ maxLength: 512 }), {
58-
maxItems: 32,
59-
description: "Exact supporting paths to remove intentionally; never SKILL.md.",
60-
}),
61-
),
62-
},
63-
{ additionalProperties: false },
64-
);
65-
66-
export type SkillLibraryWorkshopParams = Static<typeof SkillLibraryWorkshopSchema>;
9+
export function createLibrarySkillWorkshopDescriptor(
10+
multipleProfiles: boolean,
11+
workspace?: AnyAgentTool,
12+
): Pick<AnyAgentTool, "name" | "label" | "displaySummary" | "description"> {
13+
return {
14+
name: "skill_workshop",
15+
label: "Skill Workshop",
16+
displaySummary: "Author reusable skills",
17+
description: `${workspace ? `${workspace.description} For personal library operations set target=personal. ` : "Author skills in the requesting person's personal library. "}Personal create/update publishes a revision only when the user requests the change; personal drafts are unsupported. Describe unsolicited improvements without publishing. Read before updating; name is the slug, not the command identity. Read artifact_path for a whole text support file. On update omit name/proposal_content to preserve them; files upserts named support files, delete_files removes explicit paths. Unmentioned files and omitted executable flags are preserved. Binary or oversized reads require My skills or the CLI. Ownership is bound by the Gateway. Publication affects new sessions; activate explicitly for the next turn in this session. Sharing or transfer requires explicit user intent and current permissions.${multipleProfiles ? " This shared Gateway has personal and team libraries; sharing preserves authorship and ownership, while transfer makes a skill team managed." : ""}`,
18+
};
19+
}
6720

6821
export function createLibrarySkillWorkshopTool(
6922
capability: SkillLibraryAuthoringCapability,
@@ -76,10 +29,7 @@ export function createLibrarySkillWorkshopTool(
7629
)
7730
: SkillLibraryWorkshopSchema;
7831
return {
79-
name: "skill_workshop",
80-
label: "Skill Workshop",
81-
displaySummary: "Author reusable skills",
82-
description: `${workspace ? `${workspace.description} For personal library operations set target=personal. ` : "Author skills in the requesting person's personal library. "}Personal create/update publishes a revision only when the user requests the change; personal drafts are unsupported. Describe unsolicited improvements without publishing. Read before updating; name is the slug, not the command identity. Read artifact_path for a whole text support file. On update omit name/proposal_content to preserve them; files upserts named support files, delete_files removes explicit paths. Unmentioned files and omitted executable flags are preserved. Binary or oversized reads require My skills or the CLI. Ownership is bound by the Gateway. Publication affects new sessions; activate explicitly for the next turn in this session. Sharing or transfer requires explicit user intent and current permissions.${capability.multipleProfiles ? " This shared Gateway has personal and team libraries; sharing preserves authorship and ownership, while transfer makes a skill team managed." : ""}`,
32+
...createLibrarySkillWorkshopDescriptor(capability.multipleProfiles, workspace),
8333
parameters: workspace ? Type.Union([workspace.parameters, schema]) : schema,
8434
execute: async (id, raw) => {
8535
if (workspace && (!raw || typeof raw !== "object" || !("target" in raw))) {

‎src/cli/skills-library-cli.ts‎

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { Option, type Command } from "commander";
22
import type {
33
SkillsLibraryActivateResult,
44
SkillsLibraryListResult,
5-
SkillsLibraryMutateParams,
65
SkillsLibraryReadResult,
76
SkillsLibraryReceipt,
87
} from "../../packages/gateway-protocol/src/index.js";
@@ -79,18 +78,6 @@ export function registerSkillsLibraryCli(skills: Command): void {
7978
defaultRuntime.writeStdout(format(result));
8079
}
8180
});
82-
const mutate = (command: Command, params: SkillsLibraryMutateParams) =>
83-
execute(
84-
command,
85-
(opts) =>
86-
callGatewayFromCliWithTransport<SkillsLibraryReceipt>(
87-
"skills.library.mutate",
88-
opts,
89-
params,
90-
),
91-
receiptText,
92-
);
93-
9481
leaf("list", "List your own and visible shared skills")
9582
.addOption(
9683
new Option("--scope <scope>", "Library scope")
@@ -301,24 +288,28 @@ export function registerSkillsLibraryCli(skills: Command): void {
301288
}
302289
command.action(
303290
(skillId: string, opts: LibraryOptions & { expectedRevision: string }, cmd: Command) =>
304-
mutate(cmd, {
305-
skillId,
306-
action,
307-
expectedRevision: opts.expectedRevision,
308-
...(opts.revision ? { revision: opts.revision } : {}),
309-
}),
291+
execute(
292+
cmd,
293+
(rpc) =>
294+
callGatewayFromCliWithTransport<SkillsLibraryReceipt>("skills.library.mutate", rpc, {
295+
skillId,
296+
action,
297+
expectedRevision: opts.expectedRevision,
298+
...(opts.revision ? { revision: opts.revision } : {}),
299+
}),
300+
receiptText,
301+
),
310302
);
311303
}
312304
for (const action of ["attach", "detach", "refresh"] as const) {
313305
const command = leaf(
314306
action,
315307
`${action.charAt(0).toUpperCase()}${action.slice(1)} managed selections explicitly for the next session turn`,
316308
).requiredOption("--session <key>", "Exact target session key");
317-
if (action !== "refresh") {
318-
command.requiredOption("--skill-id <id>", "Stable library skill ID");
319-
}
320309
if (action === "refresh") {
321310
command.option("--skill-id <id>", "Refresh only this selected skill; omit to refresh all");
311+
} else {
312+
command.requiredOption("--skill-id <id>", "Stable library skill ID");
322313
}
323314
if (action === "attach") {
324315
command.option("--revision <hash>", "Retained revision to select");

‎src/gateway/worker-environments/skill-resource-transfer.test.ts‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,54 @@ async function createSource() {
5959
}
6060

6161
describe("remote-exec skill resources", () => {
62+
it("rejects remote directory identities that collide when rounded to numbers", async () => {
63+
const { snapshot } = await createSource();
64+
let initializedRoot: string | undefined;
65+
try {
66+
await expect(
67+
transferSkillResources({
68+
snapshot,
69+
assertCurrent: () => {},
70+
tunnel: {
71+
runWorkspaceCommand: async (command) => {
72+
// Model adjacent Windows file indexes while retaining the real filesystem flow.
73+
const identityShim = `{
74+
const fs = require('node:fs');
75+
for (const method of ['lstatSync', 'statSync']) {
76+
const original = fs[method];
77+
fs[method] = (...args) => {
78+
const stat = original(...args);
79+
const ino = 9007199254740992n + (process.argv[1] === 'init' ? 0n : 1n);
80+
stat.ino = typeof stat.ino === 'bigint' ? ino : Number(ino);
81+
return stat;
82+
};
83+
}
84+
}`;
85+
const result = await tunnel.runWorkspaceCommand({
86+
...command,
87+
argv: [
88+
...command.argv.slice(0, 2),
89+
identityShim + command.argv[2],
90+
...command.argv.slice(3),
91+
],
92+
});
93+
if (command.argv[3] === "init") {
94+
initializedRoot = JSON.parse(result.stdout).root;
95+
}
96+
return result;
97+
},
98+
},
99+
}),
100+
).rejects.toThrow("Skill resource transfer failed");
101+
expect(initializedRoot).toBeDefined();
102+
await expect(fs.readdir(initializedRoot!)).resolves.toEqual([]);
103+
} finally {
104+
if (initializedRoot) {
105+
await fs.rm(initializedRoot, { recursive: true, force: true });
106+
}
107+
}
108+
});
109+
62110
it.each(["complete", "cancelled", "retired"] as const)(
63111
"preserves complete resources outside the project and cleans up only its current owner (%s)",
64112
async (outcome) => {

‎src/gateway/worker-environments/skill-resource-transfer.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ import { NODE_WORKER_WORKSPACE_STDIN_MAX_BYTES } from "../../worker/node-workspa
77
import type { WorkerWorkspaceTunnelHandle } from "./tunnel-contract.js";
88

99
const CHUNK_BYTES = Math.floor(NODE_WORKER_WORKSPACE_STDIN_MAX_BYTES / 4) * 3;
10-
// The receiving process chooses its own temporary root. Exact inode checks fence every later write.
10+
// The receiving process owns its temporary root; lossless IDs also fence large Windows file indexes.
1111
const RESOURCE_SCRIPT = String.raw`
1212
const fs=require('node:fs'), path=require('node:path'), os=require('node:os'), crypto=require('node:crypto');
1313
const [op,root,rootId,name,offsetText,sizeText,hash,executable]=process.argv.slice(1);
1414
const identity=s=>String(s.dev)+':'+String(s.ino);
15-
function enter(p,id){const s=fs.lstatSync(p);if(!s.isDirectory()||s.isSymbolicLink()||(id&&identity(s)!==id))throw Error('resource directory changed');process.chdir(p);if(identity(fs.statSync('.'))!==identity(s))throw Error('resource directory changed');}
15+
function enter(p,id){const s=fs.lstatSync(p,{bigint:true});if(!s.isDirectory()||s.isSymbolicLink()||(id&&identity(s)!==id))throw Error('resource directory changed');process.chdir(p);if(identity(fs.statSync('.',{bigint:true}))!==identity(s))throw Error('resource directory changed');}
1616
try {
17-
if(op==='init'){const dir=fs.mkdtempSync(path.join(os.tmpdir(),'openclaw-skill-resources-'));fs.chmodSync(dir,0o700);process.stdout.write(JSON.stringify({root:dir,identity:identity(fs.lstatSync(dir))}));}
17+
if(op==='init'){const dir=fs.mkdtempSync(path.join(os.tmpdir(),'openclaw-skill-resources-'));fs.chmodSync(dir,0o700);process.stdout.write(JSON.stringify({root:dir,identity:identity(fs.lstatSync(dir,{bigint:true}))}));}
1818
else {
1919
enter(root,rootId);
2020
if(op==='cleanup'){fs.rmSync(root,{recursive:true});}

‎src/gateway/worker-environments/worker-skill-authoring.ts‎

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,7 @@ export async function invokeWorkerSkillAuthoring(
4646
throw new Error("This turn reached its Workshop operation limit. Continue in a fresh turn.");
4747
}
4848
const result =
49-
previous?.result ??
50-
registration.tool.execute(request.toolCallId, {
51-
action: request.action,
52-
skill_id: request.skillId,
53-
expected_revision: request.expectedRevision,
54-
revision: request.revision,
55-
name: request.slug,
56-
proposal_content: request.content,
57-
artifact_path: request.artifactPath,
58-
files: request.files,
59-
delete_files: request.deleteFiles,
60-
});
49+
previous?.result ?? registration.tool.execute(request.toolCallId, request.arguments);
6150
registration.calls.set(request.toolCallId, { digest, result });
6251
const value = await result;
6352
registration.assertCurrent();

‎src/gateway/worker-environments/worker-turn-rpc.portal.test.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ describe("worker portal RPC authority", () => {
1919
await expect(
2020
workerService.executeSessionTool(identity, "portal", {
2121
toolCallId: "wrong-family",
22-
action: "read",
23-
artifactPath: "scripts/helper.sh",
22+
arguments: { action: "read", artifact_path: "scripts/helper.sh" },
2423
}),
2524
).resolves.toEqual({ ok: false, closeReason: "invalid-frame" });
2625
expect(executeSessionTool).not.toHaveBeenCalled();

‎src/skills/library/bundle.ts‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { createHash } from "node:crypto";
22
import fs from "node:fs/promises";
33
import path from "node:path";
4-
import { Type } from "typebox";
4+
import { Type, type Static } from "typebox";
55
import { Value } from "typebox/value";
66
import {
77
SKILL_LIBRARY_MAX_BUNDLE_BYTES,
@@ -18,15 +18,9 @@ import { SkillLibraryError } from "./errors.js";
1818
export const SKILL_LIBRARY_MAX_PATH_COMPONENTS = 16;
1919
export const SKILL_LIBRARY_MAX_TREE_ENTRIES = SKILL_LIBRARY_MAX_FILES * 2;
2020

21-
type SkillLibraryManifestFile = {
22-
path: string;
23-
sha256: string;
24-
sizeBytes: number;
25-
executable: boolean;
26-
};
2721
type PreparedSkillBundle = {
2822
revision: string;
29-
files: Array<SkillLibraryManifestFile & { bytes: Buffer }>;
23+
files: Array<Static<typeof manifestSchema>[number] & { bytes: Buffer }>;
3024
};
3125
export type PreparedSkillLibraryBundle = PreparedSkillBundle & { description: string };
3226
const portableCompare = (a: string, b: string) => (a < b ? -1 : a > b ? 1 : 0);

0 commit comments

Comments
 (0)