From 2370ea5d1b8119408f1ca8e0df60ce458caa2e4e Mon Sep 17 00:00:00 2001 From: Gustavo Madeira Santana Date: Tue, 3 Mar 2026 02:44:04 -0500 Subject: [PATCH] agents: propagate config for embedded skill loading --- CHANGELOG.md | 1 + src/agents/pi-embedded-runner/compact.ts | 11 +-- src/agents/pi-embedded-runner/run/attempt.ts | 11 +-- .../skills-runtime.integration.test.ts | 90 +++++++++++++++++++ .../pi-embedded-runner/skills-runtime.test.ts | 67 ++++++++++++++ .../pi-embedded-runner/skills-runtime.ts | 19 ++++ 6 files changed, 189 insertions(+), 10 deletions(-) create mode 100644 src/agents/pi-embedded-runner/skills-runtime.integration.test.ts create mode 100644 src/agents/pi-embedded-runner/skills-runtime.test.ts create mode 100644 src/agents/pi-embedded-runner/skills-runtime.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ed9b1c353a..69b29bd0799 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ Docs: https://docs.openclaw.ai ### Fixes +- Agents/Skills runtime loading: propagate run config into embedded attempt and compaction skill-entry loading so explicitly enabled bundled companion skills are discovered consistently when skill snapshots do not already provide resolved entries. Thanks @gumadeiras. - Agents/Compaction continuity: expand staged-summary merge instructions to preserve active task status, batch progress, latest user request, and follow-up commitments so compaction handoffs retain in-flight work context. (#8903) thanks @joetomasone. - Gateway/status self version reporting: make Gateway self version in `openclaw status` prefer runtime `VERSION` (while preserving explicit `OPENCLAW_VERSION` override), preventing stale post-upgrade app version output. (#32655) thanks @liuxiaopai-ai. - Memory/QMD index isolation: set `QMD_CONFIG_DIR` alongside `XDG_CONFIG_HOME` so QMD config state stays per-agent despite upstream XDG handling bugs, preventing cross-agent collection indexing and excess disk/CPU usage. (#27028) thanks @HenryLoenwind. diff --git a/src/agents/pi-embedded-runner/compact.ts b/src/agents/pi-embedded-runner/compact.ts index f65df4d4290..2fc622c842b 100644 --- a/src/agents/pi-embedded-runner/compact.ts +++ b/src/agents/pi-embedded-runner/compact.ts @@ -53,7 +53,6 @@ import { detectRuntimeShell } from "../shell-utils.js"; import { applySkillEnvOverrides, applySkillEnvOverridesFromSnapshot, - loadWorkspaceSkillEntries, resolveSkillsPromptForRun, type SkillSnapshot, } from "../skills.js"; @@ -74,6 +73,7 @@ import { log } from "./logger.js"; import { buildModelAliasLines, resolveModel } from "./model.js"; import { buildEmbeddedSandboxInfo } from "./sandbox-info.js"; import { prewarmSessionFile, trackSessionManagerAccess } from "./session-manager-cache.js"; +import { resolveEmbeddedRunSkillEntries } from "./skills-runtime.js"; import { applySystemPromptOverrideToSession, buildEmbeddedSystemPrompt, @@ -333,10 +333,11 @@ export async function compactEmbeddedPiSessionDirect( let restoreSkillEnv: (() => void) | undefined; process.chdir(effectiveWorkspace); try { - const shouldLoadSkillEntries = !params.skillsSnapshot || !params.skillsSnapshot.resolvedSkills; - const skillEntries = shouldLoadSkillEntries - ? loadWorkspaceSkillEntries(effectiveWorkspace) - : []; + const { shouldLoadSkillEntries, skillEntries } = resolveEmbeddedRunSkillEntries({ + workspaceDir: effectiveWorkspace, + config: params.config, + skillsSnapshot: params.skillsSnapshot, + }); restoreSkillEnv = params.skillsSnapshot ? applySkillEnvOverridesFromSnapshot({ snapshot: params.skillsSnapshot, diff --git a/src/agents/pi-embedded-runner/run/attempt.ts b/src/agents/pi-embedded-runner/run/attempt.ts index d1b158eee9f..63898d4dfe0 100644 --- a/src/agents/pi-embedded-runner/run/attempt.ts +++ b/src/agents/pi-embedded-runner/run/attempt.ts @@ -69,7 +69,6 @@ import { detectRuntimeShell } from "../../shell-utils.js"; import { applySkillEnvOverrides, applySkillEnvOverridesFromSnapshot, - loadWorkspaceSkillEntries, resolveSkillsPromptForRun, } from "../../skills.js"; import { buildSystemPromptParams } from "../../system-prompt-params.js"; @@ -99,6 +98,7 @@ import { import { buildEmbeddedSandboxInfo } from "../sandbox-info.js"; import { prewarmSessionFile, trackSessionManagerAccess } from "../session-manager-cache.js"; import { prepareSessionManagerForRun } from "../session-manager-init.js"; +import { resolveEmbeddedRunSkillEntries } from "../skills-runtime.js"; import { applySystemPromptOverrideToSession, buildEmbeddedSystemPrompt, @@ -570,10 +570,11 @@ export async function runEmbeddedAttempt( let restoreSkillEnv: (() => void) | undefined; process.chdir(effectiveWorkspace); try { - const shouldLoadSkillEntries = !params.skillsSnapshot || !params.skillsSnapshot.resolvedSkills; - const skillEntries = shouldLoadSkillEntries - ? loadWorkspaceSkillEntries(effectiveWorkspace) - : []; + const { shouldLoadSkillEntries, skillEntries } = resolveEmbeddedRunSkillEntries({ + workspaceDir: effectiveWorkspace, + config: params.config, + skillsSnapshot: params.skillsSnapshot, + }); restoreSkillEnv = params.skillsSnapshot ? applySkillEnvOverridesFromSnapshot({ snapshot: params.skillsSnapshot, diff --git a/src/agents/pi-embedded-runner/skills-runtime.integration.test.ts b/src/agents/pi-embedded-runner/skills-runtime.integration.test.ts new file mode 100644 index 00000000000..03191e51c8e --- /dev/null +++ b/src/agents/pi-embedded-runner/skills-runtime.integration.test.ts @@ -0,0 +1,90 @@ +import fs from "node:fs/promises"; +import os from "node:os"; +import path from "node:path"; +import { afterEach, describe, expect, it } from "vitest"; +import type { OpenClawConfig } from "../../config/config.js"; +import { clearPluginManifestRegistryCache } from "../../plugins/manifest-registry.js"; +import { resolveEmbeddedRunSkillEntries } from "./skills-runtime.js"; + +const tempDirs: string[] = []; +const originalBundledDir = process.env.OPENCLAW_BUNDLED_PLUGINS_DIR; + +async function createTempDir(prefix: string) { + const dir = await fs.mkdtemp(path.join(os.tmpdir(), prefix)); + tempDirs.push(dir); + return dir; +} + +async function setupBundledDiffsPlugin() { + const bundledPluginsDir = await createTempDir("openclaw-bundled-"); + const workspaceDir = await createTempDir("openclaw-workspace-"); + const pluginRoot = path.join(bundledPluginsDir, "diffs"); + + await fs.mkdir(path.join(pluginRoot, "skills", "diffs"), { recursive: true }); + await fs.writeFile( + path.join(pluginRoot, "openclaw.plugin.json"), + JSON.stringify( + { + id: "diffs", + skills: ["./skills"], + configSchema: { type: "object", additionalProperties: false, properties: {} }, + }, + null, + 2, + ), + "utf-8", + ); + await fs.writeFile(path.join(pluginRoot, "index.ts"), "export {};\n", "utf-8"); + await fs.writeFile( + path.join(pluginRoot, "skills", "diffs", "SKILL.md"), + `---\nname: diffs\ndescription: runtime integration test\n---\n`, + "utf-8", + ); + + return { bundledPluginsDir, workspaceDir }; +} + +afterEach(async () => { + process.env.OPENCLAW_BUNDLED_PLUGINS_DIR = originalBundledDir; + clearPluginManifestRegistryCache(); + await Promise.all( + tempDirs.splice(0, tempDirs.length).map((dir) => fs.rm(dir, { recursive: true, force: true })), + ); +}); + +describe("resolveEmbeddedRunSkillEntries (integration)", () => { + it("loads bundled diffs skill when explicitly enabled in config", async () => { + const { bundledPluginsDir, workspaceDir } = await setupBundledDiffsPlugin(); + process.env.OPENCLAW_BUNDLED_PLUGINS_DIR = bundledPluginsDir; + clearPluginManifestRegistryCache(); + + const config: OpenClawConfig = { + plugins: { + entries: { + diffs: { enabled: true }, + }, + }, + }; + + const result = resolveEmbeddedRunSkillEntries({ + workspaceDir, + config, + }); + + expect(result.shouldLoadSkillEntries).toBe(true); + expect(result.skillEntries.map((entry) => entry.skill.name)).toContain("diffs"); + }); + + it("skips bundled diffs skill when config is missing", async () => { + const { bundledPluginsDir, workspaceDir } = await setupBundledDiffsPlugin(); + process.env.OPENCLAW_BUNDLED_PLUGINS_DIR = bundledPluginsDir; + clearPluginManifestRegistryCache(); + + const result = resolveEmbeddedRunSkillEntries({ + workspaceDir, + }); + + expect(result.shouldLoadSkillEntries).toBe(true); + expect(result.skillEntries.map((entry) => entry.skill.name)).not.toContain("diffs"); + }); +}); diff --git a/src/agents/pi-embedded-runner/skills-runtime.test.ts b/src/agents/pi-embedded-runner/skills-runtime.test.ts new file mode 100644 index 00000000000..9ddead32d73 --- /dev/null +++ b/src/agents/pi-embedded-runner/skills-runtime.test.ts @@ -0,0 +1,67 @@ +import { beforeEach, describe, expect, it, vi } from "vitest"; +import type { OpenClawConfig } from "../../config/config.js"; +import type { SkillSnapshot } from "../skills.js"; + +const hoisted = vi.hoisted(() => ({ + loadWorkspaceSkillEntries: vi.fn(() => []), +})); + +vi.mock("../skills.js", async (importOriginal) => { + const actual = await importOriginal(); + return { + ...actual, + loadWorkspaceSkillEntries: (...args: unknown[]) => hoisted.loadWorkspaceSkillEntries(...args), + }; +}); + +const { resolveEmbeddedRunSkillEntries } = await import("./skills-runtime.js"); + +describe("resolveEmbeddedRunSkillEntries", () => { + beforeEach(() => { + hoisted.loadWorkspaceSkillEntries.mockReset(); + hoisted.loadWorkspaceSkillEntries.mockReturnValue([]); + }); + + it("loads skill entries with config when no resolved snapshot skills exist", () => { + const config: OpenClawConfig = { + plugins: { + entries: { + diffs: { enabled: true }, + }, + }, + }; + + const result = resolveEmbeddedRunSkillEntries({ + workspaceDir: "/tmp/workspace", + config, + skillsSnapshot: { + prompt: "skills prompt", + skills: [], + }, + }); + + expect(result.shouldLoadSkillEntries).toBe(true); + expect(hoisted.loadWorkspaceSkillEntries).toHaveBeenCalledTimes(1); + expect(hoisted.loadWorkspaceSkillEntries).toHaveBeenCalledWith("/tmp/workspace", { config }); + }); + + it("skips skill entry loading when resolved snapshot skills are present", () => { + const snapshot: SkillSnapshot = { + prompt: "skills prompt", + skills: [{ name: "diffs" }], + resolvedSkills: [], + }; + + const result = resolveEmbeddedRunSkillEntries({ + workspaceDir: "/tmp/workspace", + config: {}, + skillsSnapshot: snapshot, + }); + + expect(result).toEqual({ + shouldLoadSkillEntries: false, + skillEntries: [], + }); + expect(hoisted.loadWorkspaceSkillEntries).not.toHaveBeenCalled(); + }); +}); diff --git a/src/agents/pi-embedded-runner/skills-runtime.ts b/src/agents/pi-embedded-runner/skills-runtime.ts new file mode 100644 index 00000000000..3f3d138e6ae --- /dev/null +++ b/src/agents/pi-embedded-runner/skills-runtime.ts @@ -0,0 +1,19 @@ +import type { OpenClawConfig } from "../../config/config.js"; +import { loadWorkspaceSkillEntries, type SkillEntry, type SkillSnapshot } from "../skills.js"; + +export function resolveEmbeddedRunSkillEntries(params: { + workspaceDir: string; + config?: OpenClawConfig; + skillsSnapshot?: SkillSnapshot; +}): { + shouldLoadSkillEntries: boolean; + skillEntries: SkillEntry[]; +} { + const shouldLoadSkillEntries = !params.skillsSnapshot || !params.skillsSnapshot.resolvedSkills; + return { + shouldLoadSkillEntries, + skillEntries: shouldLoadSkillEntries + ? loadWorkspaceSkillEntries(params.workspaceDir, { config: params.config }) + : [], + }; +}