Skip to content

Commit 3037646

Browse files
committed
feat: add skill workshop runtime policy
1 parent 3ea82ad commit 3037646

12 files changed

Lines changed: 660 additions & 72 deletions

‎docs/tools/skills-config.md‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ Most skills loader/install configuration lives under `skills` in
2525
nodeManager: "npm", // npm | pnpm | yarn | bun (Gateway runtime still Node; bun not recommended)
2626
allowUploadedArchives: false,
2727
},
28+
workshop: {
29+
autonomous: {
30+
enabled: true,
31+
},
32+
approvalPolicy: "pending", // pending | auto
33+
maxPending: 50,
34+
maxSkillBytes: 40000,
35+
},
2836
entries: {
2937
"image-lab": {
3038
enabled: true,
@@ -110,6 +118,16 @@ Rules:
110118
clients to install private zip archives staged through `skills.upload.*`
111119
(default: false). This only enables the uploaded-archive path; normal ClawHub
112120
installs do not require it.
121+
- `workshop.autonomous.enabled`: allow agents to create pending Skill Workshop
122+
proposals from durable conversation signals after successful turns (default:
123+
true). User-prompted skill creation still goes through Skill Workshop.
124+
- `workshop.approvalPolicy`: proposal lifecycle policy. `pending` requires
125+
approval before agent-initiated apply/reject/quarantine actions; `auto`
126+
allows those actions without approval.
127+
- `workshop.maxPending`: maximum pending/quarantined proposals retained per
128+
workspace (default: 50).
129+
- `workshop.maxSkillBytes`: maximum generated proposal body size in bytes
130+
(default: 40000).
113131
- `entries.<skillKey>`: per-skill overrides.
114132
- `agents.defaults.skills`: optional default skill allowlist inherited by agents
115133
that omit `agents.list[].skills`.

‎src/agents/agent-tools.before-tool-call.embedded-mode.test.ts‎

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,73 @@ describe("runBeforeToolCallHook — embedded mode approvals", () => {
313313
expect(runBeforeToolCallMock).not.toHaveBeenCalled();
314314
});
315315

316+
it("requires approval before skill_research applies a proposal", async () => {
317+
(hookRunner.hasHooks as ReturnType<typeof vi.fn>).mockReturnValue(false);
318+
mockCallGatewayTool.mockResolvedValueOnce({
319+
id: "skill-research-approval",
320+
decision: PluginApprovalResolutions.ALLOW_ONCE,
321+
});
322+
323+
const result = await runBeforeToolCallHook({
324+
toolName: "skill_research",
325+
params: { action: "apply", proposal_id: "weather-20260530-a1b2c3d4e5" },
326+
toolCallId: "call-skill-apply",
327+
ctx: {
328+
agentId: "main",
329+
sessionKey: "main",
330+
config: {
331+
skills: {
332+
workshop: {
333+
approvalPolicy: "pending",
334+
},
335+
},
336+
},
337+
},
338+
});
339+
340+
expect(result).toEqual({
341+
blocked: false,
342+
params: { action: "apply", proposal_id: "weather-20260530-a1b2c3d4e5" },
343+
approvalResolution: PluginApprovalResolutions.ALLOW_ONCE,
344+
});
345+
const approvalCall = requireApprovalRequestCall("skill_research approval request");
346+
expect(approvalCall.request.pluginId).toBeUndefined();
347+
expect(approvalCall.request.title).toBe("Apply workspace skill proposal");
348+
expect(approvalCall.request.description).toBe(
349+
"Apply a pending workspace skill proposal into live workspace skills.",
350+
);
351+
expect(approvalCall.request.severity).toBe("warning");
352+
expect(approvalCall.request.allowedDecisions).toEqual(["allow-once", "deny"]);
353+
expect(approvalCall.request.toolName).toBe("skill_research");
354+
expect(approvalCall.request.toolCallId).toBe("call-skill-apply");
355+
expect(runBeforeToolCallMock).not.toHaveBeenCalled();
356+
});
357+
358+
it("does not require skill_research lifecycle approval in auto mode", async () => {
359+
(hookRunner.hasHooks as ReturnType<typeof vi.fn>).mockReturnValue(false);
360+
361+
const result = await runBeforeToolCallHook({
362+
toolName: "skill_research",
363+
params: { action: "reject", proposal_id: "weather-20260530-a1b2c3d4e5" },
364+
ctx: {
365+
config: {
366+
skills: {
367+
workshop: {
368+
approvalPolicy: "auto",
369+
},
370+
},
371+
},
372+
},
373+
});
374+
375+
expect(result).toEqual({
376+
blocked: false,
377+
params: { action: "reject", proposal_id: "weather-20260530-a1b2c3d4e5" },
378+
});
379+
expect(mockCallGatewayTool).not.toHaveBeenCalled();
380+
expect(runBeforeToolCallMock).not.toHaveBeenCalled();
381+
});
382+
316383
it("preserves trusted policy params when before_tool_call hooks leave params unchanged", async () => {
317384
const registry = createEmptyPluginRegistry();
318385
registry.trustedToolPolicies = [

‎src/agents/agent-tools.before-tool-call.ts‎

Lines changed: 84 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import {
4141
resolveSkillTelemetrySourceValue,
4242
} from "../skills/loading/source.js";
4343
import type { SkillSnapshot, SkillTelemetrySource } from "../skills/types.js";
44+
import { resolveSkillResearchToolApproval } from "../skills/workshop/policy.js";
4445
import { isPlainObject } from "../utils.js";
4546
import { adjustedParamsByToolCallId } from "./agent-tools.before-tool-call.state.js";
4647
import { copyChannelAgentToolMeta, getChannelAgentToolMeta } from "./channel-tools.js";
@@ -603,6 +604,54 @@ export function cancelDeferredPluginToolApproval(
603604
notifyPluginApprovalResolution(deferredApproval.approval, PluginApprovalResolutions.CANCELLED);
604605
}
605606

607+
async function resolveBeforeToolCallApprovalOutcome(params: {
608+
result: PluginHookBeforeToolCallResult | undefined;
609+
approvalMode?: "request" | "report" | "defer";
610+
toolName: string;
611+
toolCallId?: string;
612+
ctx?: HookContext;
613+
signal?: AbortSignal;
614+
baseParams: unknown;
615+
}): Promise<HookOutcome | undefined> {
616+
const approval = params.result?.requireApproval;
617+
if (!approval) {
618+
return undefined;
619+
}
620+
if (params.approvalMode === "defer") {
621+
return {
622+
blocked: false,
623+
params: params.baseParams,
624+
deferredApproval: {
625+
approval,
626+
toolName: params.toolName,
627+
...(params.toolCallId ? { toolCallId: params.toolCallId } : {}),
628+
...(params.ctx ? { ctx: params.ctx } : {}),
629+
baseParams: params.baseParams,
630+
overrideParams: params.result?.params,
631+
},
632+
};
633+
}
634+
if (params.approvalMode === "report") {
635+
notifyPluginApprovalResolution(approval, PluginApprovalResolutions.CANCELLED);
636+
return {
637+
blocked: true,
638+
kind: "failure",
639+
deniedReason: "plugin-approval",
640+
reason: approval.description || approval.title || "Plugin approval required",
641+
params: params.baseParams,
642+
};
643+
}
644+
return await requestPluginToolApproval({
645+
approval,
646+
toolName: params.toolName,
647+
...(params.toolCallId ? { toolCallId: params.toolCallId } : {}),
648+
...(params.ctx ? { ctx: params.ctx } : {}),
649+
signal: params.signal,
650+
baseParams: params.baseParams,
651+
overrideParams: params.result?.params,
652+
});
653+
}
654+
606655
export function buildBlockedToolResult(params: {
607656
reason: string;
608657
deniedReason?: HookBlockedReason;
@@ -789,10 +838,15 @@ export async function runBeforeToolCallHook(args: {
789838
try {
790839
const hasBeforeToolCallHooks = hookRunner?.hasHooks("before_tool_call") === true;
791840
const shouldRunTrustedPolicies = hasTrustedToolPolicies();
792-
if (!shouldRunTrustedPolicies && !hasBeforeToolCallHooks) {
841+
const normalizedParams = isPlainObject(params) ? params : {};
842+
const corePolicyResult = resolveSkillResearchToolApproval({
843+
toolName,
844+
toolParams: normalizedParams,
845+
...(args.ctx?.config ? { config: args.ctx.config } : {}),
846+
});
847+
if (!corePolicyResult && !shouldRunTrustedPolicies && !hasBeforeToolCallHooks) {
793848
return { blocked: false, params };
794849
}
795-
const normalizedParams = isPlainObject(params) ? params : {};
796850
const deriveOptions =
797851
args.ctx?.cwd || args.ctx?.sandbox
798852
? {
@@ -821,6 +875,18 @@ export async function runBeforeToolCallHook(args: {
821875
...(args.ctx?.channelId && { channelId: args.ctx.channelId }),
822876
});
823877
const toolContext = buildToolContext(toolIdentity);
878+
const coreApprovalOutcome = await resolveBeforeToolCallApprovalOutcome({
879+
result: corePolicyResult,
880+
approvalMode: args.approvalMode,
881+
toolName,
882+
...(args.toolCallId ? { toolCallId: args.toolCallId } : {}),
883+
...(args.ctx ? { ctx: args.ctx } : {}),
884+
signal: args.signal,
885+
baseParams: params,
886+
});
887+
if (coreApprovalOutcome) {
888+
return coreApprovalOutcome;
889+
}
824890
const trustedPolicyResult = shouldRunTrustedPolicies
825891
? await runTrustedToolPolicies(
826892
{
@@ -869,45 +935,18 @@ export async function runBeforeToolCallHook(args: {
869935
};
870936
}
871937
if (trustedPolicyResult?.requireApproval) {
872-
if (args.approvalMode === "defer") {
873-
return {
874-
blocked: false,
875-
params,
876-
deferredApproval: {
877-
approval: trustedPolicyResult.requireApproval,
878-
toolName,
879-
...(args.toolCallId ? { toolCallId: args.toolCallId } : {}),
880-
...(args.ctx ? { ctx: args.ctx } : {}),
881-
baseParams: params,
882-
overrideParams: trustedPolicyResult.params,
883-
},
884-
};
885-
}
886-
if (args.approvalMode === "report") {
887-
notifyPluginApprovalResolution(
888-
trustedPolicyResult.requireApproval,
889-
PluginApprovalResolutions.CANCELLED,
890-
);
891-
return {
892-
blocked: true,
893-
kind: "failure",
894-
deniedReason: "plugin-approval",
895-
reason:
896-
trustedPolicyResult.requireApproval.description ||
897-
trustedPolicyResult.requireApproval.title ||
898-
"Plugin approval required",
899-
params,
900-
};
901-
}
902-
return await requestPluginToolApproval({
903-
approval: trustedPolicyResult.requireApproval,
938+
const approvalOutcome = await resolveBeforeToolCallApprovalOutcome({
939+
result: trustedPolicyResult,
940+
approvalMode: args.approvalMode,
904941
toolName,
905-
toolCallId: args.toolCallId,
906-
ctx: args.ctx,
942+
...(args.toolCallId ? { toolCallId: args.toolCallId } : {}),
943+
...(args.ctx ? { ctx: args.ctx } : {}),
907944
signal: args.signal,
908945
baseParams: params,
909-
overrideParams: trustedPolicyResult.params,
910946
});
947+
if (approvalOutcome) {
948+
return approvalOutcome;
949+
}
911950
}
912951
const rawPolicyAdjustedParams = trustedPolicyResult?.params ?? params;
913952
const policyAdjustedParams = normalizeCodeModeExecBeforeHookParamsForToolKind({
@@ -953,45 +992,18 @@ export async function runBeforeToolCallHook(args: {
953992
}
954993

955994
if (hookResult?.requireApproval) {
956-
if (args.approvalMode === "defer") {
957-
return {
958-
blocked: false,
959-
params: policyAdjustedParams,
960-
deferredApproval: {
961-
approval: hookResult.requireApproval,
962-
toolName,
963-
...(args.toolCallId ? { toolCallId: args.toolCallId } : {}),
964-
...(args.ctx ? { ctx: args.ctx } : {}),
965-
baseParams: policyAdjustedParams,
966-
overrideParams: hookResult.params,
967-
},
968-
};
969-
}
970-
if (args.approvalMode === "report") {
971-
notifyPluginApprovalResolution(
972-
hookResult.requireApproval,
973-
PluginApprovalResolutions.CANCELLED,
974-
);
975-
return {
976-
blocked: true,
977-
kind: "failure",
978-
deniedReason: "plugin-approval",
979-
reason:
980-
hookResult.requireApproval.description ||
981-
hookResult.requireApproval.title ||
982-
"Plugin approval required",
983-
params: policyAdjustedParams,
984-
};
985-
}
986-
return await requestPluginToolApproval({
987-
approval: hookResult.requireApproval,
995+
const approvalOutcome = await resolveBeforeToolCallApprovalOutcome({
996+
result: hookResult,
997+
approvalMode: args.approvalMode,
988998
toolName,
989-
toolCallId: args.toolCallId,
990-
ctx: args.ctx,
999+
...(args.toolCallId ? { toolCallId: args.toolCallId } : {}),
1000+
...(args.ctx ? { ctx: args.ctx } : {}),
9911001
signal: args.signal,
9921002
baseParams: policyAdjustedParams,
993-
overrideParams: hookResult.params,
9941003
});
1004+
if (approvalOutcome) {
1005+
return approvalOutcome;
1006+
}
9951007
}
9961008

9971009
if (hookResult?.params) {

‎src/agents/tools/skill-research-tool.test.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,24 @@ describe("skill_research tool", () => {
3232
expect(tools.some((tool) => tool.name === "skill_research")).toBe(true);
3333
});
3434

35+
it("stays exposed when autonomous proposal capture is disabled", async () => {
36+
const workspaceDir = await tempDirs.make("openclaw-skill-research-tool-");
37+
const tools = createOpenClawTools({
38+
workspaceDir,
39+
config: {
40+
skills: {
41+
workshop: {
42+
autonomous: {
43+
enabled: false,
44+
},
45+
},
46+
},
47+
},
48+
disablePluginTools: true,
49+
});
50+
expect(tools.some((tool) => tool.name === "skill_research")).toBe(true);
51+
});
52+
3553
it("is not exposed from sandboxed OpenClaw tool sets", async () => {
3654
const workspaceDir = await tempDirs.make("openclaw-skill-research-tool-");
3755
const tools = createOpenClawTools({

‎src/config/types.skills.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,26 @@ export type SkillsLimitsConfig = {
4444
maxSkillFileBytes?: number;
4545
};
4646

47+
export type SkillsWorkshopConfig = {
48+
/** Autonomous Skill Workshop behavior controlled separately from user-prompted proposals. */
49+
autonomous?: {
50+
/** Allow agents to create pending proposals from durable conversation signals. */
51+
enabled?: boolean;
52+
};
53+
/** Whether proposal lifecycle actions need explicit approval. */
54+
approvalPolicy?: "pending" | "auto";
55+
/** Maximum pending/quarantined proposals retained per workspace. */
56+
maxPending?: number;
57+
/** Maximum generated skill proposal size in bytes. */
58+
maxSkillBytes?: number;
59+
};
60+
4761
export type SkillsConfig = {
4862
/** Optional bundled-skill allowlist (only affects bundled skills). */
4963
allowBundled?: string[];
5064
load?: SkillsLoadConfig;
5165
install?: SkillsInstallConfig;
5266
limits?: SkillsLimitsConfig;
67+
workshop?: SkillsWorkshopConfig;
5368
entries?: Record<string, SkillConfig>;
5469
};

‎src/config/zod-schema.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,6 +1191,20 @@ export const OpenClawSchema = z
11911191
})
11921192
.strict()
11931193
.optional(),
1194+
workshop: z
1195+
.object({
1196+
autonomous: z
1197+
.object({
1198+
enabled: z.boolean().optional(),
1199+
})
1200+
.strict()
1201+
.optional(),
1202+
approvalPolicy: z.union([z.literal("pending"), z.literal("auto")]).optional(),
1203+
maxPending: z.number().int().min(1).optional(),
1204+
maxSkillBytes: z.number().int().min(1).optional(),
1205+
})
1206+
.strict()
1207+
.optional(),
11941208
entries: z.record(z.string(), SkillEntrySchema).optional(),
11951209
})
11961210
.strict()

0 commit comments

Comments
 (0)