






















@@ -508,51 +508,56 @@ export function createOpenClawCodingTools(options?: {
508508const imageSanitization = resolveImageSanitizationLimits(options?.config);
509509options?.recordToolPrepStage?.("workspace-policy");
510510511-const base = includeBaseCodingTools
512- ? (createCodingTools(workspaceRoot) as unknown as AnyAgentTool[]).flatMap((tool) => {
513-if (tool.name === "read") {
514-if (sandboxRoot) {
515-const sandboxed = createSandboxedReadTool({
516-root: sandboxRoot,
517-bridge: sandboxFsBridge!,
518-modelContextWindowTokens: options?.modelContextWindowTokens,
519- imageSanitization,
520-});
521-return [
522-workspaceOnly
523- ? wrapToolWorkspaceRootGuardWithOptions(sandboxed, sandboxRoot, {
524-containerWorkdir: sandbox.containerWorkdir,
525-})
526- : sandboxed,
527-];
528-}
529-const freshReadTool = createReadTool(workspaceRoot);
530-const wrapped = createOpenClawReadTool(freshReadTool, {
511+const base: AnyAgentTool[] = [];
512+if (includeBaseCodingTools) {
513+for (const tool of createCodingTools(workspaceRoot) as unknown as AnyAgentTool[]) {
514+if (tool.name === "read") {
515+if (sandboxRoot) {
516+const sandboxed = createSandboxedReadTool({
517+root: sandboxRoot,
518+bridge: sandboxFsBridge!,
531519modelContextWindowTokens: options?.modelContextWindowTokens,
532520 imageSanitization,
533521});
534-return [workspaceOnly ? wrapToolWorkspaceRootGuard(wrapped, workspaceRoot) : wrapped];
535-}
536-if (tool.name === "bash" || tool.name === execToolName) {
537-return [];
522+base.push(
523+workspaceOnly
524+ ? wrapToolWorkspaceRootGuardWithOptions(sandboxed, sandboxRoot, {
525+containerWorkdir: sandbox.containerWorkdir,
526+})
527+ : sandboxed,
528+);
529+continue;
538530}
539-if (tool.name === "write") {
540-if (sandboxRoot) {
541-return [];
542-}
543-const wrapped = createHostWorkspaceWriteTool(workspaceRoot, { workspaceOnly });
544-return [workspaceOnly ? wrapToolWorkspaceRootGuard(wrapped, workspaceRoot) : wrapped];
531+const freshReadTool = createReadTool(workspaceRoot);
532+const wrapped = createOpenClawReadTool(freshReadTool, {
533+modelContextWindowTokens: options?.modelContextWindowTokens,
534+ imageSanitization,
535+});
536+base.push(workspaceOnly ? wrapToolWorkspaceRootGuard(wrapped, workspaceRoot) : wrapped);
537+continue;
538+}
539+if (tool.name === "bash" || tool.name === execToolName) {
540+continue;
541+}
542+if (tool.name === "write") {
543+if (sandboxRoot) {
544+continue;
545545}
546-if (tool.name === "edit") {
547-if (sandboxRoot) {
548-return [];
549-}
550-const wrapped = createHostWorkspaceEditTool(workspaceRoot, { workspaceOnly });
551-return [workspaceOnly ? wrapToolWorkspaceRootGuard(wrapped, workspaceRoot) : wrapped];
546+const wrapped = createHostWorkspaceWriteTool(workspaceRoot, { workspaceOnly });
547+base.push(workspaceOnly ? wrapToolWorkspaceRootGuard(wrapped, workspaceRoot) : wrapped);
548+continue;
549+}
550+if (tool.name === "edit") {
551+if (sandboxRoot) {
552+continue;
552553}
553-return [tool];
554-})
555- : [];
554+const wrapped = createHostWorkspaceEditTool(workspaceRoot, { workspaceOnly });
555+base.push(workspaceOnly ? wrapToolWorkspaceRootGuard(wrapped, workspaceRoot) : wrapped);
556+continue;
557+}
558+base.push(tool);
559+}
560+}
556561options?.recordToolPrepStage?.("base-coding-tools");
557562const { cleanupMs: cleanupMsOverride, ...execDefaults } = options?.exec ?? {};
558563const execTool = includeShellTools
@@ -754,28 +759,29 @@ export function createOpenClawCodingTools(options?: {
754759 : pluginToolsOnly),
755760];
756761options?.recordToolPrepStage?.("openclaw-tools");
757-const toolsForMemoryFlush =
758-isMemoryFlushRun && memoryFlushWritePath
759- ? tools.flatMap((tool) => {
760-if (!MEMORY_FLUSH_ALLOWED_TOOL_NAMES.has(tool.name)) {
761-return [];
762-}
763-if (tool.name === "write") {
764-return [
765-wrapToolMemoryFlushAppendOnlyWrite(tool, {
766-root: sandboxRoot ?? workspaceRoot,
767-relativePath: memoryFlushWritePath,
768-containerWorkdir: sandbox?.containerWorkdir,
769-sandbox:
770-sandboxRoot && sandboxFsBridge
771- ? { root: sandboxRoot, bridge: sandboxFsBridge }
772- : undefined,
773-}),
774-];
775-}
776-return [tool];
777-})
778- : tools;
762+const toolsForMemoryFlush: AnyAgentTool[] = isMemoryFlushRun && memoryFlushWritePath ? [] : tools;
763+if (isMemoryFlushRun && memoryFlushWritePath) {
764+for (const tool of tools) {
765+if (!MEMORY_FLUSH_ALLOWED_TOOL_NAMES.has(tool.name)) {
766+continue;
767+}
768+if (tool.name === "write") {
769+toolsForMemoryFlush.push(
770+wrapToolMemoryFlushAppendOnlyWrite(tool, {
771+root: sandboxRoot ?? workspaceRoot,
772+relativePath: memoryFlushWritePath,
773+containerWorkdir: sandbox?.containerWorkdir,
774+sandbox:
775+sandboxRoot && sandboxFsBridge
776+ ? { root: sandboxRoot, bridge: sandboxFsBridge }
777+ : undefined,
778+}),
779+);
780+continue;
781+}
782+toolsForMemoryFlush.push(tool);
783+}
784+}
779785const toolsForMessageProvider = filterToolsByMessageProvider(
780786toolsForMemoryFlush,
781787options?.messageProvider,
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。