Skip to content

Commit c2521d7

Browse files
authored
fix(ui): catalog sessions select in place and continue from desktop-app sources (#106074)
* fix(ui): make catalog sessions selectable in place and continuable from desktop-app sources - sidebar: no phantom chat row for catalog keys, active highlight on catalog rows, adopted sessions render as their live row inside the catalog group (deduped from the regular list), host subtitle only for paired-node rows - chat: view-only banner only after catalog metadata proves canContinue=false - chat->sidebar continued event binds the adopted row before the next catalog poll - anthropic: local claude-desktop sessions share the ~/.claude/projects store, so list them as continuable and allow catalog continue to fork-resume them * refactor(ui): extract catalog row rendering and lookup into shared modules Keeps app-sidebar/chat-pane/anthropic session-catalog under the LOC ratchet by moving cohesive blocks: sidebar catalog groups + adopted-row binding into app-sidebar-session-catalogs.ts, the catalog metadata lookup into catalog-key.ts, and the Claude node-host commands into session-catalog-node-commands.ts; ratchet baselines down for all three. * fix(ui): explain the disabled composer when catalog metadata cannot resolve a session * style(ui): keep chat-pane within the LOC ratchet * fix(anthropic): keep catalog node-command helpers module-local and repin SDK surface The node-command module now owns its capability constant, projects-store probe, and params parsing, so the catalog engine exports nothing new. Repin the SDK surface budgets (+1 export/+1 callable landed on main without a pin bump); unexport the UI helper types knip flagged.
1 parent 02cbe66 commit c2521d7

11 files changed

Lines changed: 714 additions & 213 deletions

‎extensions/anthropic/register.runtime.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ import { anthropicMediaUnderstandingProvider } from "./media-understanding-provi
5757
import {
5858
createClaudeSessionNodeHostCommands,
5959
createClaudeSessionNodeInvokePolicies,
60-
registerClaudeSessionCatalog,
61-
} from "./session-catalog.js";
60+
} from "./session-catalog-node-commands.js";
61+
import { registerClaudeSessionCatalog } from "./session-catalog.js";
6262
import { wrapAnthropicProviderStream } from "./stream-wrappers.js";
6363
import { fetchAnthropicUsage, resolveAnthropicUsageAuth } from "./usage.js";
6464

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { statSync } from "node:fs";
2+
import os from "node:os";
3+
import path from "node:path";
4+
import type {
5+
OpenClawPluginNodeHostCommand,
6+
OpenClawPluginNodeInvokePolicy,
7+
} from "openclaw/plugin-sdk/plugin-entry";
8+
import {
9+
CLAUDE_SESSION_READ_COMMAND,
10+
CLAUDE_SESSIONS_LIST_COMMAND,
11+
listLocalClaudeSessionPage,
12+
readLocalClaudeTranscriptPage,
13+
} from "./session-catalog.js";
14+
15+
const CLAUDE_SESSIONS_CAPABILITY = "claude-sessions";
16+
17+
// Nodes advertise the catalog commands only when this machine has a Claude
18+
// Code session store; without it the gateway skips the node entirely.
19+
function claudeProjectsAvailable(env: NodeJS.ProcessEnv): boolean {
20+
const homeDir = env.HOME?.trim() || env.USERPROFILE?.trim() || os.homedir();
21+
try {
22+
return statSync(path.join(homeDir, ".claude", "projects")).isDirectory();
23+
} catch {
24+
return false;
25+
}
26+
}
27+
28+
function parseNodeParams(paramsJSON?: string | null): unknown {
29+
if (!paramsJSON) {
30+
return undefined;
31+
}
32+
try {
33+
return JSON.parse(paramsJSON) as unknown;
34+
} catch (error) {
35+
throw new Error("Claude session parameters must be valid JSON", { cause: error });
36+
}
37+
}
38+
39+
export function createClaudeSessionNodeHostCommands(): OpenClawPluginNodeHostCommand[] {
40+
return [
41+
{
42+
command: CLAUDE_SESSIONS_LIST_COMMAND,
43+
cap: CLAUDE_SESSIONS_CAPABILITY,
44+
dangerous: false,
45+
isAvailable: ({ env }) => claudeProjectsAvailable(env),
46+
handle: async (paramsJSON) =>
47+
JSON.stringify(await listLocalClaudeSessionPage(parseNodeParams(paramsJSON))),
48+
},
49+
{
50+
command: CLAUDE_SESSION_READ_COMMAND,
51+
cap: CLAUDE_SESSIONS_CAPABILITY,
52+
dangerous: false,
53+
isAvailable: ({ env }) => claudeProjectsAvailable(env),
54+
handle: async (paramsJSON) =>
55+
JSON.stringify(await readLocalClaudeTranscriptPage(parseNodeParams(paramsJSON))),
56+
},
57+
];
58+
}
59+
60+
export function createClaudeSessionNodeInvokePolicies(): OpenClawPluginNodeInvokePolicy[] {
61+
return [
62+
{
63+
commands: [CLAUDE_SESSIONS_LIST_COMMAND, CLAUDE_SESSION_READ_COMMAND],
64+
defaultPlatforms: ["macos", "linux", "windows"],
65+
handle: (context) => context.invokeNode(),
66+
},
67+
];
68+
}

‎extensions/anthropic/session-catalog.test.ts‎

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import type { OpenClawPluginApi } from "openclaw/plugin-sdk/plugin-entry";
55
import type { PluginRuntime } from "openclaw/plugin-sdk/plugin-runtime";
66
import type { SessionCatalogProvider } from "openclaw/plugin-sdk/session-catalog";
77
import { afterEach, describe, expect, it, vi } from "vitest";
8+
import { createClaudeSessionNodeHostCommands } from "./session-catalog-node-commands.js";
89
import {
910
CLAUDE_SESSIONS_LIST_COMMAND,
1011
CLAUDE_SESSION_READ_COMMAND,
11-
createClaudeSessionNodeHostCommands,
1212
listClaudeSessionCatalog,
1313
listLocalClaudeSessionPage,
1414
readLocalClaudeTranscriptPage,
@@ -154,6 +154,77 @@ describe("Claude session catalog", () => {
154154
);
155155
});
156156

157+
it("continues a local Desktop-app row and lists it as continuable", async () => {
158+
const home = await createHome();
159+
process.env.HOME = home;
160+
const sessionId = "desktop-source-session";
161+
await writeProject({
162+
home,
163+
entries: [
164+
{
165+
sessionId,
166+
fullPath: path.join(home, ".claude", "projects", "-workspace", `${sessionId}.jsonl`),
167+
summary: "Index title",
168+
projectPath: "/work/desktop",
169+
},
170+
],
171+
transcripts: { [sessionId]: [message(sessionId, "user", "desktop prompt", 1)] },
172+
});
173+
await writeDesktopMetadata(home, "active", {
174+
cliSessionId: sessionId,
175+
title: "Desktop title",
176+
cwd: "/desktop/cwd",
177+
isArchived: false,
178+
});
179+
const createSessionEntry = vi.fn(async (params: Record<string, unknown>) => ({
180+
key: `agent:main:${String(params.key)}`,
181+
agentId: "main",
182+
sessionId: "openclaw-adopted",
183+
entry: { sessionId: "openclaw-adopted", updatedAt: Date.now() },
184+
}));
185+
let provider: SessionCatalogProvider | undefined;
186+
const api = {
187+
id: "anthropic",
188+
config: {},
189+
runtime: {
190+
config: { current: () => ({}) },
191+
nodes: { list: async () => ({ nodes: [] }) },
192+
agent: {
193+
session: {
194+
listSessionEntries: () => [],
195+
createSessionEntry,
196+
},
197+
},
198+
},
199+
registerSessionCatalog: (candidate: SessionCatalogProvider) => {
200+
provider = candidate;
201+
},
202+
} as unknown as OpenClawPluginApi;
203+
registerClaudeSessionCatalog(api);
204+
205+
const hosts = await provider?.list({});
206+
expect(hosts?.[0]?.sessions).toEqual([
207+
expect.objectContaining({
208+
threadId: sessionId,
209+
source: "claude-desktop",
210+
canContinue: true,
211+
canArchive: false,
212+
}),
213+
]);
214+
await expect(
215+
provider?.continueSession?.({ hostId: "gateway:local", threadId: sessionId }),
216+
).resolves.toEqual({
217+
sessionKey: expect.stringContaining("plugin:anthropic:catalog-adopt:claude:"),
218+
});
219+
expect(createSessionEntry).toHaveBeenCalledWith(
220+
expect.objectContaining({
221+
initialEntry: expect.objectContaining({
222+
cliSessionBinding: { sessionId, forceReuse: true, forkNextResume: true },
223+
}),
224+
}),
225+
);
226+
});
227+
157228
it("merges CLI indexes with active Desktop metadata and hides archived Desktop sessions", async () => {
158229
const home = await createHome();
159230
await writeProject({

‎extensions/anthropic/session-catalog.ts‎

Lines changed: 14 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
import { createHash } from "node:crypto";
2-
import { statSync } from "node:fs";
32
import fs from "node:fs/promises";
43
import os from "node:os";
54
import path from "node:path";
65
import type { AgentMessage } from "openclaw/plugin-sdk/agent-harness-runtime";
76
import { listAgentIds, resolveDefaultAgentId } from "openclaw/plugin-sdk/agent-runtime";
87
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts";
9-
import type {
10-
OpenClawPluginApi,
11-
OpenClawPluginNodeHostCommand,
12-
OpenClawPluginNodeInvokePolicy,
13-
} from "openclaw/plugin-sdk/plugin-entry";
8+
import type { OpenClawPluginApi } from "openclaw/plugin-sdk/plugin-entry";
149
import type { PluginRuntime } from "openclaw/plugin-sdk/plugin-runtime";
1510
import type {
1611
SessionCatalogHost,
@@ -25,7 +20,6 @@ export const CLAUDE_SESSIONS_LIST_COMMAND = "anthropic.claude.sessions.list.v1";
2520
export const CLAUDE_SESSION_READ_COMMAND = "anthropic.claude.sessions.read.v1";
2621
import { CLAUDE_CLI_BACKEND_ID, CLAUDE_CLI_DEFAULT_MODEL_REF } from "./cli-constants.js";
2722

28-
const CLAUDE_SESSIONS_CAPABILITY = "claude-sessions";
2923
const CLAUDE_LOCAL_SESSION_HOST_ID = "gateway:local";
3024
const DEFAULT_PAGE_LIMIT = 50;
3125
const MAX_PAGE_LIMIT = 100;
@@ -51,6 +45,13 @@ const CLAUDE_HISTORY_IMPORT_MAX_BYTES = 512 * 1024;
5145

5246
type ClaudeSessionSource = "claude-cli" | "claude-desktop";
5347

48+
// Desktop-app sessions live in the same ~/.claude/projects store as CLI
49+
// sessions (records without a projects JSONL are dropped during discovery),
50+
// so `claude --resume --fork-session` continues both alike.
51+
function isResumableClaudeSource(source: string | undefined): boolean {
52+
return source === "claude-cli" || source === "claude-desktop";
53+
}
54+
5455
export type ClaudeSessionCatalogSession = {
5556
threadId: string;
5657
name?: string | null;
@@ -209,15 +210,6 @@ function currentHomeDir(env: NodeJS.ProcessEnv = process.env): string {
209210
return env.HOME?.trim() || env.USERPROFILE?.trim() || os.homedir();
210211
}
211212

212-
function claudeProjectsAvailable(env: NodeJS.ProcessEnv): boolean {
213-
const homeDir = currentHomeDir(env);
214-
try {
215-
return statSync(projectsDir(homeDir)).isDirectory();
216-
} catch {
217-
return false;
218-
}
219-
}
220-
221213
async function readDesktopMetadata(homeDir: string): Promise<{
222214
active: Map<string, DesktopSessionMetadata>;
223215
archived: Set<string>;
@@ -613,19 +605,6 @@ export async function listLocalClaudeSessionPage(
613605
};
614606
}
615607

616-
function parseNodeParams(paramsJSON?: string | null): unknown {
617-
if (!paramsJSON) {
618-
return undefined;
619-
}
620-
try {
621-
return JSON.parse(paramsJSON) as unknown;
622-
} catch (error) {
623-
throw new ClaudeCatalogParamsError("Claude session parameters must be valid JSON", {
624-
cause: error,
625-
});
626-
}
627-
}
628-
629608
function transcriptItemType(role: string, content: unknown): string {
630609
if (!Array.isArray(content)) {
631610
return role === "user" ? "userMessage" : "agentMessage";
@@ -1167,37 +1146,6 @@ async function readClaudeSessionTranscript(params: {
11671146
};
11681147
}
11691148

1170-
export function createClaudeSessionNodeHostCommands(): OpenClawPluginNodeHostCommand[] {
1171-
return [
1172-
{
1173-
command: CLAUDE_SESSIONS_LIST_COMMAND,
1174-
cap: CLAUDE_SESSIONS_CAPABILITY,
1175-
dangerous: false,
1176-
isAvailable: ({ env }) => claudeProjectsAvailable(env),
1177-
handle: async (paramsJSON) =>
1178-
JSON.stringify(await listLocalClaudeSessionPage(parseNodeParams(paramsJSON))),
1179-
},
1180-
{
1181-
command: CLAUDE_SESSION_READ_COMMAND,
1182-
cap: CLAUDE_SESSIONS_CAPABILITY,
1183-
dangerous: false,
1184-
isAvailable: ({ env }) => claudeProjectsAvailable(env),
1185-
handle: async (paramsJSON) =>
1186-
JSON.stringify(await readLocalClaudeTranscriptPage(parseNodeParams(paramsJSON))),
1187-
},
1188-
];
1189-
}
1190-
1191-
export function createClaudeSessionNodeInvokePolicies(): OpenClawPluginNodeInvokePolicy[] {
1192-
return [
1193-
{
1194-
commands: [CLAUDE_SESSIONS_LIST_COMMAND, CLAUDE_SESSION_READ_COMMAND],
1195-
defaultPlatforms: ["macos", "linux", "windows"],
1196-
handle: (context) => context.invokeNode(),
1197-
},
1198-
];
1199-
}
1200-
12011149
function adoptedSessionKey(threadId: string): string {
12021150
return `${CLAUDE_ADOPTED_SESSION_KEY_PREFIX}${createHash("sha256").update(threadId).digest("hex")}`;
12031151
}
@@ -1342,8 +1290,8 @@ async function continueClaudeSession(
13421290
const record = (await listClaudeSessions()).find(
13431291
(candidate) => candidate.threadId === threadId,
13441292
);
1345-
if (!record || record.source !== "claude-cli") {
1346-
throw new ClaudeCatalogParamsError("only local Claude CLI sessions can be continued");
1293+
if (!record || !isResumableClaudeSource(record.source)) {
1294+
throw new ClaudeCatalogParamsError("only local Claude Code sessions can be continued");
13471295
}
13481296
const source = await fs.stat(record.filePath).catch(() => undefined);
13491297
if (!source?.isFile()) {
@@ -1439,9 +1387,9 @@ function toGenericClaudeHost(
14391387
connected: host.connected,
14401388
...(host.nodeId ? { nodeId: host.nodeId } : {}),
14411389
sessions: host.sessions.map((session) => {
1442-
const localCli =
1443-
host.hostId === CLAUDE_LOCAL_SESSION_HOST_ID && session.source === "claude-cli";
1444-
const openClawSessionKey = localCli ? adopted.get(session.threadId) : undefined;
1390+
const localResumable =
1391+
host.hostId === CLAUDE_LOCAL_SESSION_HOST_ID && isResumableClaudeSource(session.source);
1392+
const openClawSessionKey = localResumable ? adopted.get(session.threadId) : undefined;
14451393
return {
14461394
threadId: session.threadId,
14471395
...(session.name ? { name: session.name } : {}),
@@ -1456,7 +1404,7 @@ function toGenericClaudeHost(
14561404
...(session.gitBranch ? { gitBranch: session.gitBranch } : {}),
14571405
archived: session.archived,
14581406
...(openClawSessionKey ? { openClawSessionKey } : {}),
1459-
canContinue: localCli,
1407+
canContinue: localResumable,
14601408
canArchive: false,
14611409
};
14621410
}),

0 commit comments

Comments
 (0)