惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

GbyAI
GbyAI
Martin Fowler
Martin Fowler
I
InfoQ
腾讯CDC
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
爱范儿
爱范儿
Microsoft Security Blog
Microsoft Security Blog
Google DeepMind News
Google DeepMind News
D
DataBreaches.Net
云风的 BLOG
云风的 BLOG
F
Fortinet All Blogs
N
Netflix TechBlog - Medium
博客园 - 聂微东
Microsoft Azure Blog
Microsoft Azure Blog
D
Docker
博客园 - 三生石上(FineUI控件)
Y
Y Combinator Blog
博客园 - Franky
Engineering at Meta
Engineering at Meta
B
Blog
罗磊的独立博客
Apple Machine Learning Research
Apple Machine Learning Research
Jina AI
Jina AI
V
Visual Studio Blog

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
refactor(sessions): route cleanup through controlled writ...
steipete · 2026-05-02 · via Recent Commits to openclaw:main

@@ -1,78 +1,56 @@

1-

import fs from "node:fs";

2-

import path from "node:path";

1+

import { findOverlappingWorkspaceAgentIds } from "../agents/agent-delete-safety.js";

32

import { resolveAgentDir, resolveAgentWorkspaceDir } from "../agents/agent-scope.js";

43

import { replaceConfigFile } from "../config/config.js";

54

import { logConfigUpdated } from "../config/logging.js";

6-

import { resolveSessionTranscriptsDirForAgent } from "../config/sessions.js";

7-

import type { OpenClawConfig } from "../config/types.openclaw.js";

5+

import {

6+

purgeAgentSessionStoreEntries,

7+

resolveSessionTranscriptsDirForAgent,

8+

} from "../config/sessions.js";

9+

import { callGateway, isGatewayTransportError } from "../gateway/call.js";

810

import { DEFAULT_AGENT_ID, normalizeAgentId } from "../routing/session-key.js";

911

import { type RuntimeEnv, writeRuntimeJson } from "../runtime.js";

1012

import { defaultRuntime } from "../runtime.js";

11-

import { lowercasePreservingWhitespace } from "../shared/string-coerce.js";

13+

import { GATEWAY_CLIENT_MODES, GATEWAY_CLIENT_NAMES } from "../utils/message-channel.js";

1214

import { createClackPrompter } from "../wizard/clack-prompter.js";

13-

import {

14-

createQuietRuntime,

15-

purgeAgentSessionStoreEntries,

16-

requireValidConfigFileSnapshot,

17-

} from "./agents.command-shared.js";

15+

import { createQuietRuntime, requireValidConfigFileSnapshot } from "./agents.command-shared.js";

1816

import { findAgentEntryIndex, listAgentEntries, pruneAgentConfig } from "./agents.config.js";

1917

import { moveToTrash } from "./onboard-helpers.js";

201821-

function normalizeWorkspacePathForComparison(input: string): string {

22-

const resolved = path.resolve(input.replaceAll("\0", ""));

23-

let normalized = resolved;

24-

try {

25-

normalized = fs.realpathSync.native(resolved);

26-

} catch {

27-

// Keep lexical path for non-existent directories.

28-

}

29-

if (process.platform === "win32") {

30-

return lowercasePreservingWhitespace(normalized);

31-

}

32-

return normalized;

33-

}

34-35-

function isPathWithinRoot(candidatePath: string, rootPath: string): boolean {

36-

const relative = path.relative(rootPath, candidatePath);

37-

return relative === "" || (!relative.startsWith("..") && !path.isAbsolute(relative));

38-

}

39-40-

function workspacePathsOverlap(left: string, right: string): boolean {

41-

const normalizedLeft = normalizeWorkspacePathForComparison(left);

42-

const normalizedRight = normalizeWorkspacePathForComparison(right);

43-

return (

44-

isPathWithinRoot(normalizedLeft, normalizedRight) ||

45-

isPathWithinRoot(normalizedRight, normalizedLeft)

46-

);

47-

}

48-49-

function findOverlappingWorkspaceAgentIds(

50-

cfg: OpenClawConfig,

51-

agentId: string,

52-

workspaceDir: string,

53-

): string[] {

54-

const entries = listAgentEntries(cfg);

55-

const normalizedAgentId = normalizeAgentId(agentId);

56-

const overlappingAgentIds: string[] = [];

57-

for (const entry of entries) {

58-

const otherAgentId = normalizeAgentId(entry.id);

59-

if (otherAgentId === normalizedAgentId) {

60-

continue;

61-

}

62-

const otherWorkspace = resolveAgentWorkspaceDir(cfg, otherAgentId);

63-

if (workspacePathsOverlap(workspaceDir, otherWorkspace)) {

64-

overlappingAgentIds.push(otherAgentId);

65-

}

66-

}

67-

return overlappingAgentIds;

68-

}

69-7019

type AgentsDeleteOptions = {

7120

id: string;

7221

force?: boolean;

7322

json?: boolean;

7423

};

752425+

type AgentsDeleteGatewayResult = {

26+

ok: true;

27+

agentId: string;

28+

removedBindings: number;

29+

};

30+31+

async function maybeDeleteAgentThroughGateway(params: {

32+

agentId: string;

33+

deleteFiles: boolean;

34+

}): Promise<AgentsDeleteGatewayResult | null> {

35+

try {

36+

return await callGateway<AgentsDeleteGatewayResult>({

37+

method: "agents.delete",

38+

params: {

39+

agentId: params.agentId,

40+

deleteFiles: params.deleteFiles,

41+

},

42+

mode: GATEWAY_CLIENT_MODES.CLI,

43+

clientName: GATEWAY_CLIENT_NAMES.CLI,

44+

requiredMethods: ["agents.delete"],

45+

});

46+

} catch (error) {

47+

if (isGatewayTransportError(error)) {

48+

return null;

49+

}

50+

throw error;

51+

}

52+

}

53+7654

export async function agentsDeleteCommand(

7755

opts: AgentsDeleteOptions,

7856

runtime: RuntimeEnv = defaultRuntime,

@@ -127,8 +105,34 @@ export async function agentsDeleteCommand(

127105

const workspaceDir = resolveAgentWorkspaceDir(cfg, agentId);

128106

const agentDir = resolveAgentDir(cfg, agentId);

129107

const sessionsDir = resolveSessionTranscriptsDirForAgent(agentId);

130-131108

const result = pruneAgentConfig(cfg, agentId);

109+110+

const gatewayResult = await maybeDeleteAgentThroughGateway({

111+

agentId,

112+

deleteFiles: true,

113+

});

114+

if (gatewayResult) {

115+

const workspaceSharedWith = findOverlappingWorkspaceAgentIds(cfg, agentId, workspaceDir);

116+

const workspaceRetained = workspaceSharedWith.length > 0;

117+

if (opts.json) {

118+

writeRuntimeJson(runtime, {

119+

agentId,

120+

workspace: workspaceDir,

121+

workspaceRetained: workspaceRetained || undefined,

122+

workspaceRetainedReason: workspaceRetained ? "shared" : undefined,

123+

workspaceSharedWith: workspaceRetained ? workspaceSharedWith : undefined,

124+

agentDir,

125+

sessionsDir,

126+

removedBindings: gatewayResult.removedBindings,

127+

removedAllow: result.removedAllow,

128+

transport: "gateway",

129+

});

130+

} else {

131+

runtime.log(`Deleted agent: ${agentId}`);

132+

}

133+

return;

134+

}

135+132136

await replaceConfigFile({

133137

nextConfig: result.config,

134138

...(baseHash !== undefined ? { baseHash } : {}),