Skip to content

Commit 29b6f56

Browse files
authored
feat(system-agent): host skills and web-search setup in Ask OpenClaw (#115130)
* feat(system-agent): host skills and search setup * test(system-agent): align stop-message assertions with channel-specific labels * fix(system-agent): report failed search-provider install honestly * fix(system-agent): preserve nonfatal search setup skips * test(flows): satisfy plugin-install mock return type * test(system-agent): split setup-flow operation tests
1 parent 59f8245 commit 29b6f56

21 files changed

Lines changed: 1163 additions & 282 deletions

‎src/agents/tools/system-agent-tool.test.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,15 @@ describe("openclaw tool", () => {
317317
expect(toolText(connect)).toContain("directive:");
318318
expect(directiveRef.current).toEqual({ kind: "channel-setup", channel: "telegram" });
319319

320+
const skills = await tool.execute("t5-skills", { action: "configure_skills" });
321+
expect(toolText(skills)).toContain("directive:");
322+
expect(directiveRef.current).toEqual({ kind: "skills-setup" });
323+
324+
const search = await tool.execute("t5-search", { action: "configure_search" });
325+
expect(toolText(search)).toContain("directive:");
326+
expect(toolText(search)).toContain("never ask for or repeat a credential");
327+
expect(directiveRef.current).toEqual({ kind: "search-setup" });
328+
320329
const configureModel = await tool.execute("t6", {
321330
action: "configure_model_provider",
322331
workspace: "/tmp/work",
@@ -377,6 +386,18 @@ describe("openclaw tool", () => {
377386
resultText: "directive: the host chat now starts the guided telegram setup.",
378387
}),
379388
).toEqual({ kind: "channel-setup", channel: "telegram" });
389+
expect(
390+
resolveSystemAgentDirectiveTransition({
391+
args: { action: "configure_skills" },
392+
resultText: "directive: the host chat starts skills setup.",
393+
}),
394+
).toEqual({ kind: "skills-setup" });
395+
expect(
396+
resolveSystemAgentDirectiveTransition({
397+
args: { action: "configure_search" },
398+
resultText: "directive: the host chat starts web search setup.",
399+
}),
400+
).toEqual({ kind: "search-setup" });
380401
expect(
381402
resolveSystemAgentDirectiveTransition({
382403
args: { action: "open_agent" },
@@ -396,6 +417,12 @@ describe("openclaw tool", () => {
396417
resultText: "directive: classic setup cannot run inside OpenClaw; run openclaw onboard.",
397418
}),
398419
).toEqual({ kind: "open-setup", target: "classic" });
420+
expect(
421+
resolveSystemAgentDirectiveTransition({
422+
args: { action: "open_setup", target: "search" },
423+
resultText: "directive: the host opens masked search setup.",
424+
}),
425+
).toEqual({ kind: "open-setup", target: "search" });
399426
// Non-directive results and other actions never mirror.
400427
expect(
401428
resolveSystemAgentDirectiveTransition({ args: { action: "status" }, resultText: "ok" }),

‎src/agents/tools/system-agent-tool.ts‎

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ export type SystemAgentToolOptions = {
4545
/** Host directives the hosting chat engine handles after the turn. */
4646
export type SystemAgentToolDirective =
4747
| { kind: "channel-setup"; channel: string }
48+
| { kind: "skills-setup" }
49+
| { kind: "search-setup" }
4850
| { kind: "model-setup"; workspace?: string }
4951
| { kind: "open-tui"; agentId?: string; workspace?: string }
5052
| Extract<SystemAgentOperation, { kind: "open-setup" }>
@@ -98,6 +100,9 @@ function directiveForOperation(
98100
if (operation.kind === "channel-setup") {
99101
return { kind: "channel-setup", channel: operation.channel };
100102
}
103+
if (operation.kind === "skills-setup" || operation.kind === "search-setup") {
104+
return operation;
105+
}
101106
if (operation.kind === "model-setup") {
102107
return {
103108
kind: "model-setup",
@@ -168,6 +173,8 @@ const SYSTEM_AGENT_TOOL_ACTIONS = [
168173
"plugin_search",
169174
// Host directives handled by the hosting chat after this turn.
170175
"connect_channel",
176+
"configure_skills",
177+
"configure_search",
171178
"configure_model_provider",
172179
"open_agent",
173180
"open_setup",
@@ -200,9 +207,9 @@ const SystemAgentToolSchema = Type.Object({
200207
}),
201208
),
202209
target: Type.Optional(
203-
stringEnum(["guided", "classic", "channels"], {
210+
stringEnum(["guided", "classic", "channels", "search"], {
204211
description:
205-
"Setup target for open_setup. channels runs in this chat; guided/classic require exiting OpenClaw and running openclaw onboard.",
212+
"Setup target for open_setup. channels/search open masked terminal flows; guided/classic require exiting OpenClaw and running openclaw onboard.",
206213
}),
207214
),
208215
query: Type.Optional(Type.String({ description: "Search query for plugin_search" })),
@@ -236,9 +243,11 @@ function requireParam(params: Record<string, unknown>, name: string): string {
236243
return value.trim();
237244
}
238245

239-
function readSetupTarget(params: Record<string, unknown>): "guided" | "classic" | "channels" {
246+
function readSetupTarget(
247+
params: Record<string, unknown>,
248+
): "guided" | "classic" | "channels" | "search" {
240249
const target = readStringParam(params, "target")?.trim() ?? "guided";
241-
if (target === "guided" || target === "classic" || target === "channels") {
250+
if (target === "guided" || target === "classic" || target === "channels" || target === "search") {
242251
return target;
243252
}
244253
throw new ToolInputError(`openclaw: unknown setup target "${target}"`);
@@ -273,6 +282,10 @@ function operationForAction(params: Record<string, unknown>): SystemAgentOperati
273282
return { kind: "gateway-status" };
274283
case "connect_channel":
275284
return { kind: "channel-setup", channel: requireParam(params, "channel").toLowerCase() };
285+
case "configure_skills":
286+
return { kind: "skills-setup" };
287+
case "configure_search":
288+
return { kind: "search-setup" };
276289
case "configure_model_provider": {
277290
const workspace = readStringParam(params, "workspace")?.trim();
278291
return { kind: "model-setup", ...(workspace ? { workspace } : {}) };
@@ -368,7 +381,7 @@ export function createSystemAgentTool(options: SystemAgentToolOptions): AnyAgent
368381
description: [
369382
"System agent. Setup, config, channels, plugins, agents, repair.",
370383
"Read now: status, models, agents, channels, channel_info, config_get, config_schema, gateway_status, plugin_search, validate_config, doctor, audit.",
371-
"Handoff: connect_channel; open_setup target=channels; open_agent.",
384+
"Handoff: connect_channel, configure_skills, configure_search; open_setup target=channels|search; open_agent.",
372385
"Provider/auth/credentials: exit; run `openclaw onboard`. Never request credentials.",
373386
"Write: setup, set_default_model (agentId optional; live-tested), config_set, config_set_ref, create_agent, gateway_*, plugin_install, plugin_uninstall. Exact user approval required; then approved=true. Host applies after turn; rechecks inference owner.",
374387
"plugin_install: ClawHub/bundled/official only. Arbitrary source: exit, trusted shell.",
@@ -389,13 +402,19 @@ export function createSystemAgentTool(options: SystemAgentToolOptions): AnyAgent
389402
return textResult(
390403
directive.kind === "channel-setup"
391404
? `${SYSTEM_AGENT_DIRECTIVE_PREFIX} the host chat now starts the guided ${directive.channel} setup with the user. Tell the user the setup questions come next; do not describe steps yourself.`
392-
: directive.kind === "model-setup"
393-
? `${SYSTEM_AGENT_DIRECTIVE_PREFIX} the active inference route cannot be changed inside OpenClaw. Tell the user to exit OpenClaw and run \`openclaw onboard\`; do not ask for provider credentials here.`
394-
: directive.kind === "open-tui"
395-
? `${SYSTEM_AGENT_DIRECTIVE_PREFIX} the host now hands the user over to their normal agent. Say goodbye briefly.`
396-
: directive.target === "channels"
397-
? `${SYSTEM_AGENT_DIRECTIVE_PREFIX} the host now opens channel setup${directive.channel ? ` for ${directive.channel}` : ""}. Tell the user the channel setup questions come next.`
398-
: `${SYSTEM_AGENT_DIRECTIVE_PREFIX} ${directive.target} setup cannot run inside OpenClaw because it may change the active inference route. Tell the user to exit OpenClaw and run \`openclaw onboard\`.`,
405+
: directive.kind === "skills-setup"
406+
? `${SYSTEM_AGENT_DIRECTIVE_PREFIX} the host chat now starts skills dependency setup with the user. Tell the user the skills status and setup steps come next; do not describe steps yourself.`
407+
: directive.kind === "search-setup"
408+
? `${SYSTEM_AGENT_DIRECTIVE_PREFIX} the host chat now starts guided web search provider setup with the user. Tell the user the provider setup questions come next; never ask for or repeat a credential yourself.`
409+
: directive.kind === "model-setup"
410+
? `${SYSTEM_AGENT_DIRECTIVE_PREFIX} the active inference route cannot be changed inside OpenClaw. Tell the user to exit OpenClaw and run \`openclaw onboard\`; do not ask for provider credentials here.`
411+
: directive.kind === "open-tui"
412+
? `${SYSTEM_AGENT_DIRECTIVE_PREFIX} the host now hands the user over to their normal agent. Say goodbye briefly.`
413+
: directive.target === "channels"
414+
? `${SYSTEM_AGENT_DIRECTIVE_PREFIX} the host now opens channel setup${directive.channel ? ` for ${directive.channel}` : ""}. Tell the user the channel setup questions come next.`
415+
: directive.target === "search"
416+
? `${SYSTEM_AGENT_DIRECTIVE_PREFIX} the host now opens masked terminal web search setup. Tell the user the terminal wizard comes next.`
417+
: `${SYSTEM_AGENT_DIRECTIVE_PREFIX} ${directive.target} setup cannot run inside OpenClaw because it may change the active inference route. Tell the user to exit OpenClaw and run \`openclaw onboard\`.`,
399418
{},
400419
);
401420
}

‎src/commands/configure.wizard.test.ts‎

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,10 @@ describe("runConfigureWizard", () => {
341341
},
342342
]);
343343
mocks.setupSearch.mockReset();
344-
mocks.setupSearch.mockImplementation(async (cfg: OpenClawConfig) => cfg);
344+
mocks.setupSearch.mockImplementation(async (cfg: OpenClawConfig) => ({
345+
outcome: "completed",
346+
config: cfg,
347+
}));
345348
mocks.promptAuthConfig.mockReset();
346349
mocks.promptAuthConfig.mockImplementation(async (cfg: OpenClawConfig) => cfg);
347350
mocks.promptGatewayConfig.mockReset();
@@ -642,12 +645,15 @@ describe("runConfigureWizard", () => {
642645
config: { webSearch: { apiKey: "fc-entered-key" } },
643646
})(cfg);
644647
return {
645-
...configured,
646-
tools: {
647-
...configured.tools,
648-
web: {
649-
...configured.tools?.web,
650-
fetch: { provider: "firecrawl" },
648+
outcome: "completed",
649+
config: {
650+
...configured,
651+
tools: {
652+
...configured.tools,
653+
web: {
654+
...configured.tools?.web,
655+
fetch: { provider: "firecrawl" },
656+
},
651657
},
652658
},
653659
};
@@ -692,13 +698,16 @@ describe("runConfigureWizard", () => {
692698
it("keeps web_search disabled when provider setup has no credential", async () => {
693699
setupBaseWizardState();
694700
mocks.setupSearch.mockImplementation(async (cfg: OpenClawConfig) => ({
695-
...cfg,
696-
tools: {
697-
...cfg.tools,
698-
web: {
699-
...cfg.tools?.web,
700-
fetch: { provider: "firecrawl" },
701-
search: { enabled: false, provider: "firecrawl" },
701+
outcome: "completed",
702+
config: {
703+
...cfg,
704+
tools: {
705+
...cfg.tools,
706+
web: {
707+
...cfg.tools?.web,
708+
fetch: { provider: "firecrawl" },
709+
search: { enabled: false, provider: "firecrawl" },
710+
},
702711
},
703712
},
704713
}));
@@ -794,11 +803,12 @@ describe("runConfigureWizard", () => {
794803
credentialPath: "",
795804
}),
796805
]);
797-
mocks.setupSearch.mockImplementation(async (cfg: OpenClawConfig) =>
798-
createEnabledWebSearchConfig("duckduckgo", {
806+
mocks.setupSearch.mockImplementation(async (cfg: OpenClawConfig) => ({
807+
outcome: "completed",
808+
config: createEnabledWebSearchConfig("duckduckgo", {
799809
enabled: true,
800810
})(cfg),
801-
);
811+
}));
802812
queueWizardPrompts({
803813
select: [],
804814
confirm: [true, false],

‎src/commands/configure.wizard.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,9 +332,10 @@ async function promptWebToolsConfig(
332332
};
333333
}
334334
} else {
335-
workingConfig = await runSearchSetupFlow(workingConfig, runtime, prompter, {
335+
const searchSetup = await runSearchSetupFlow(workingConfig, runtime, prompter, {
336336
preserveDisabledSearchState: false,
337337
});
338+
workingConfig = searchSetup.config;
338339
const selectedSearch = workingConfig.tools?.web?.search;
339340
nextSearch = {
340341
...selectedSearch,

‎src/commands/onboard-skills.test.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,29 @@ describe("setupSkills", () => {
285285
expect(installNote?.message).not.toContain("repo-helper");
286286
});
287287

288+
it("rechecks persistent-effect authority immediately before each dependency install", async () => {
289+
mockMissingBrewStatus([
290+
createBundledSkill({
291+
name: "node-helper",
292+
description: "Node helper",
293+
bins: ["node-helper"],
294+
installLabel: "Install node-helper",
295+
installKind: "node",
296+
}),
297+
]);
298+
const beforePersistentEffect = vi.fn(async () => {});
299+
300+
const { prompter } = createPrompter({});
301+
await setupSkills({} as OpenClawConfig, "/tmp/ws", runtime, prompter, {
302+
beforePersistentEffect,
303+
});
304+
305+
expect(beforePersistentEffect).toHaveBeenCalledOnce();
306+
expect(beforePersistentEffect.mock.invocationCallOrder[0]).toBeLessThan(
307+
mocks.installSkill.mock.invocationCallOrder[0] ?? Number.POSITIVE_INFINITY,
308+
);
309+
});
310+
288311
it("uses the requested node manager for node-backed auto installs", async () => {
289312
mockMissingBrewStatus([
290313
createBundledSkill({

‎src/commands/onboard-skills.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,10 @@ export async function setupSkills(
146146
workspaceDir: string,
147147
runtime: RuntimeEnv,
148148
prompter: WizardPrompter,
149-
options: { nodeManager?: NodeManagerChoice } = {},
149+
options: {
150+
nodeManager?: NodeManagerChoice;
151+
beforePersistentEffect?: () => Promise<void>;
152+
} = {},
150153
): Promise<OpenClawConfig> {
151154
const report = buildWorkspaceSkillStatus(workspaceDir, { config: cfg });
152155
const eligible = report.skills.filter((s) => s.eligible);
@@ -296,6 +299,7 @@ export async function setupSkills(
296299
}
297300
// Onboarding installs the primary recipe only; alternative recipes remain
298301
// visible through `openclaw skills list --verbose`.
302+
await options.beforePersistentEffect?.();
299303
const spin = prompter.progress(t("wizard.skills.installing", { name: target.name }));
300304
const result = await installSkill({
301305
workspaceDir,

0 commit comments

Comments
 (0)