From d887df0f647df4e69f359666f2024d5eac8ddbe6 Mon Sep 17 00:00:00 2001 From: Haitao Pan Date: Sat, 6 Jun 2026 08:06:50 +0800 Subject: [PATCH] Refactor: Fix path breakage by copying global media to task scope, flatten workspace resolution cascade --- dist/src/exportArtifacts.js | 47 ++++++++++++++++++------------------ src/exportArtifacts.ts | 48 ++++++++++++++++++------------------- 2 files changed, 48 insertions(+), 47 deletions(-) diff --git a/dist/src/exportArtifacts.js b/dist/src/exportArtifacts.js index 7dcbaa7..e08bdd5 100644 --- a/dist/src/exportArtifacts.js +++ b/dist/src/exportArtifacts.js @@ -161,6 +161,29 @@ export async function exportXWorkmateArtifacts(input) { warnings.push(`Unable to read artifact scope timestamp: ${String(error)}`); } } + // Copy global media to task scope to fix path breakage + if (scopePrepared || sinceUnixMs > 0) { + for (const source of openClawSnapshotSources(params, pluginConfig)) { + const globalCandidates = await collectSnapshotSourceCandidates({ + source, + sinceUnixMs: effectiveSince, + warnings, + }); + for (const gc of globalCandidates) { + const destRelPath = safeSnapshotDestinationRelativePath(source.label, gc.relativePath); + const dest = path.join(scopeRoot, "artifacts", destRelPath.split("/").join(path.sep)); + if (isWithinRoot(scopeRoot, dest)) { + try { + await fs.mkdir(path.dirname(dest), { recursive: true }); + await fs.copyFile(gc.absolutePath, dest); + } + catch (error) { + warnings.push(`Failed to copy media file ${gc.relativePath}: ${String(error)}`); + } + } + } + } + } const scopedCandidates = (await directoryExists(scopeRoot)) ? await collectCandidates({ scanRoot: scopeRoot, @@ -752,29 +775,7 @@ function resolveWorkspaceDir(input) { if (explicit) { return expandUserPath(explicit); } - const config = objectRecord(input.config); - const agents = objectRecord(config.agents); - const agentList = Array.isArray(agents.list) - ? agents.list.map(objectRecord).filter((entry) => Object.keys(entry).length > 0) - : []; - const agentId = agentIdFromSessionKey(input.sessionKey); - const selected = (agentId ? agentList.find((entry) => optionalString(entry.id) === agentId) : undefined) ?? - agentList.find((entry) => entry.default === true) ?? - agentList[0]; - const selectedWorkspace = selected ? optionalString(selected.workspace) : ""; - if (selectedWorkspace) { - return expandUserPath(selectedWorkspace); - } - const defaults = objectRecord(agents.defaults); - const defaultWorkspace = optionalString(defaults.workspace); - if (defaultWorkspace) { - return expandUserPath(defaultWorkspace); - } - const profile = process.env.OPENCLAW_PROFILE?.trim(); - if (profile && profile.toLowerCase() !== "default") { - return path.join(os.homedir(), ".openclaw", `workspace-${profile}`); - } - return path.join(os.homedir(), ".openclaw", "workspace"); + throw new Error("UnsupportedError: workspaceDir must be explicitly provided in params or pluginConfig"); } function agentIdFromSessionKey(sessionKey) { const parts = sessionKey.split(":"); diff --git a/src/exportArtifacts.ts b/src/exportArtifacts.ts index 0ab0c4b..6242d32 100644 --- a/src/exportArtifacts.ts +++ b/src/exportArtifacts.ts @@ -265,6 +265,29 @@ export async function exportXWorkmateArtifacts(input: ExportInput): Promise 0) { + for (const source of openClawSnapshotSources(params, pluginConfig)) { + const globalCandidates = await collectSnapshotSourceCandidates({ + source, + sinceUnixMs: effectiveSince, + warnings, + }); + for (const gc of globalCandidates) { + const destRelPath = safeSnapshotDestinationRelativePath(source.label, gc.relativePath); + const dest = path.join(scopeRoot, "artifacts", destRelPath.split("/").join(path.sep)); + if (isWithinRoot(scopeRoot, dest)) { + try { + await fs.mkdir(path.dirname(dest), { recursive: true }); + await fs.copyFile(gc.absolutePath, dest); + } catch (error) { + warnings.push(`Failed to copy media file ${gc.relativePath}: ${String(error)}`); + } + } + } + } + } const scopedCandidates = (await directoryExists(scopeRoot)) ? await collectCandidates({ scanRoot: scopeRoot, @@ -934,30 +957,7 @@ function resolveWorkspaceDir(input: { if (explicit) { return expandUserPath(explicit); } - const config = objectRecord(input.config); - const agents = objectRecord(config.agents); - const agentList = Array.isArray(agents.list) - ? agents.list.map(objectRecord).filter((entry) => Object.keys(entry).length > 0) - : []; - const agentId = agentIdFromSessionKey(input.sessionKey); - const selected = - (agentId ? agentList.find((entry) => optionalString(entry.id) === agentId) : undefined) ?? - agentList.find((entry) => entry.default === true) ?? - agentList[0]; - const selectedWorkspace = selected ? optionalString(selected.workspace) : ""; - if (selectedWorkspace) { - return expandUserPath(selectedWorkspace); - } - const defaults = objectRecord(agents.defaults); - const defaultWorkspace = optionalString(defaults.workspace); - if (defaultWorkspace) { - return expandUserPath(defaultWorkspace); - } - const profile = process.env.OPENCLAW_PROFILE?.trim(); - if (profile && profile.toLowerCase() !== "default") { - return path.join(os.homedir(), ".openclaw", `workspace-${profile}`); - } - return path.join(os.homedir(), ".openclaw", "workspace"); + throw new Error("UnsupportedError: workspaceDir must be explicitly provided in params or pluginConfig"); } function agentIdFromSessionKey(sessionKey: string): string {