mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 14:10:51 +00:00
[codex] Extract filesystem safety primitives (#77918)
* refactor: extract filesystem safety primitives * refactor: use fs-safe for file access helpers * refactor: reuse fs-safe for media reads * refactor: use fs-safe for image reads * refactor: reuse fs-safe in qqbot media opener * refactor: reuse fs-safe for local media checks * refactor: consume cleaner fs-safe api * refactor: align fs-safe json option names * fix: preserve fs-safe migration contracts * refactor: use fs-safe primitive subpaths * refactor: use grouped fs-safe subpaths * refactor: align fs-safe api usage * refactor: adapt private state store api * chore: refresh proof gate * refactor: follow fs-safe json api split * refactor: follow reduced fs-safe surface * build: default fs-safe python helper off * fix: preserve fs-safe plugin sdk aliases * refactor: consolidate fs-safe usage * refactor: unify fs-safe store usage * refactor: trim fs-safe temp workspace usage * refactor: hide low-level fs-safe primitives * build: use published fs-safe package * fix: preserve outbound recovery durability after rebase * chore: refresh pr checks
This commit is contained in:
committed by
GitHub
parent
61481eb34f
commit
538605ff44
@@ -18,11 +18,12 @@ import {
|
||||
} from "openclaw/plugin-sdk/plugin-config-runtime";
|
||||
import { definePluginEntry, type OpenClawPluginApi } from "openclaw/plugin-sdk/plugin-entry";
|
||||
import { parseAgentSessionKey, parseThreadSessionSuffix } from "openclaw/plugin-sdk/routing";
|
||||
import { isPathInside, replaceFileAtomic } from "openclaw/plugin-sdk/security-runtime";
|
||||
import {
|
||||
resolveSessionStoreEntry,
|
||||
updateSessionStore,
|
||||
} from "openclaw/plugin-sdk/session-store-runtime";
|
||||
import { resolvePreferredOpenClawTmpDir } from "openclaw/plugin-sdk/temp-path";
|
||||
import { tempWorkspace, resolvePreferredOpenClawTmpDir } from "openclaw/plugin-sdk/temp-path";
|
||||
|
||||
const DEFAULT_TIMEOUT_MS = 15_000;
|
||||
const DEFAULT_AGENT_ID = "main";
|
||||
@@ -422,7 +423,7 @@ function resolveSafeTranscriptDir(baseSessionsDir: string, transcriptDir: string
|
||||
}
|
||||
const resolvedBase = path.resolve(baseSessionsDir);
|
||||
const candidate = path.resolve(resolvedBase, normalized);
|
||||
if (candidate !== resolvedBase && !candidate.startsWith(resolvedBase + path.sep)) {
|
||||
if (!isPathInside(resolvedBase, candidate)) {
|
||||
return path.resolve(resolvedBase, DEFAULT_TRANSCRIPT_DIR);
|
||||
}
|
||||
return candidate;
|
||||
@@ -664,14 +665,11 @@ async function readToggleStore(statePath: string): Promise<ActiveMemoryToggleSto
|
||||
}
|
||||
|
||||
async function writeToggleStore(statePath: string, store: ActiveMemoryToggleStore): Promise<void> {
|
||||
await fs.mkdir(path.dirname(statePath), { recursive: true });
|
||||
const tempPath = `${statePath}.${process.pid}.${Date.now()}.${crypto.randomUUID()}.tmp`;
|
||||
try {
|
||||
await fs.writeFile(tempPath, `${JSON.stringify(store, null, 2)}\n`, "utf8");
|
||||
await fs.rename(tempPath, statePath);
|
||||
} finally {
|
||||
await fs.rm(tempPath, { force: true }).catch(() => undefined);
|
||||
}
|
||||
await replaceFileAtomic({
|
||||
filePath: statePath,
|
||||
content: `${JSON.stringify(store, null, 2)}\n`,
|
||||
tempPrefix: ".active-memory",
|
||||
});
|
||||
}
|
||||
|
||||
async function isSessionActiveMemoryDisabled(params: {
|
||||
@@ -2378,9 +2376,13 @@ async function runRecallSubagent(params: {
|
||||
const subagentSessionKey = parentSessionKey
|
||||
? `${parentSessionKey}:${subagentSuffix}`
|
||||
: `agent:${params.agentId}:${subagentSuffix}`;
|
||||
const tempDir = params.config.persistTranscripts
|
||||
const transientWorkspace = params.config.persistTranscripts
|
||||
? undefined
|
||||
: await fs.mkdtemp(path.join(resolvePreferredOpenClawTmpDir(), "openclaw-active-memory-"));
|
||||
: await tempWorkspace({
|
||||
rootDir: resolvePreferredOpenClawTmpDir(),
|
||||
prefix: "openclaw-active-memory-",
|
||||
});
|
||||
const tempDir = transientWorkspace?.dir;
|
||||
const persistedDir = params.config.persistTranscripts
|
||||
? resolveSafeTranscriptDir(
|
||||
resolvePersistentTranscriptBaseDir(params.api, params.agentId),
|
||||
@@ -2479,9 +2481,7 @@ async function runRecallSubagent(params: {
|
||||
}
|
||||
throw error;
|
||||
} finally {
|
||||
if (tempDir) {
|
||||
await fs.rm(tempDir, { recursive: true, force: true }).catch(() => {});
|
||||
}
|
||||
await transientWorkspace?.cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user