Skip to content

Commit 98a06c4

Browse files
committed
refactor(plugin-sdk): consolidate session catalog families
1 parent 4667d18 commit 98a06c4

16 files changed

Lines changed: 1544 additions & 1552 deletions

‎docs/plugins/sdk-entrypoints.md‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,24 @@ export default definePluginEntry({
154154
provider should call the optional
155155
`onHost(host)` callback as each host settles; the returned host array remains
156156
required as the final compatibility snapshot.
157+
158+
CLI-backed catalogs that expose the same local-plus-paired-node shape can use
159+
`createSessionCatalogFamily(...)`. The family composer owns canonical cursor
160+
validation, node payload validation, host projection, adopted-session
161+
projection, per-host publication, read routing, single-flight continuation,
162+
and terminal plan routing. The provider must supply its local store reads,
163+
identifiers and commands, error text, capability projection, continuation
164+
availability and persistence operations, upstream-activity check, and terminal
165+
executable/arguments. There are no default continuation, capability-mutation,
166+
or terminal authorities. Use `createSessionCatalogNodeHostBindings(...)` to
167+
build the matching list/read/terminal node commands and terminal-only invoke
168+
policy from those explicit provider inputs.
169+
170+
The same entrypoint exports `sessionCatalogPaging`, which groups the bounded
171+
list/read parameter parsers, canonical base64url cursor codec, and bounded
172+
UTF-8 transcript pager. Providers pass their own identifier pattern and
173+
validation messages into `parseReadParams(...)` and `parseListParams(...)`.
174+
157175
`resolveCreateSession({ agentId })` must return a config-derived model/runtime
158176
target before OpenClaw advertises creation or calls `startTerminalSession`.
159177
Use

‎docs/plugins/sdk-subpaths.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ Use `isLoopbackHost(host)` when a plugin must accept only the local machine. It
246246
| `plugin-sdk/reply-chunking` | Narrow text/markdown chunking helpers |
247247
| `plugin-sdk/agent-scope-runtime` | Focused agent ID, directory, default-agent, and session-agent scope resolution helpers for dependency-light control-plane and migration paths |
248248
| `plugin-sdk/session-store-runtime` | Session workflow helpers (`getSessionEntry`, `listSessionEntries`, `patchSessionEntry`, `upsertSessionEntry`), repair/lifecycle helpers (`deleteSessionEntry`, `cleanupSessionLifecycleArtifacts`, `resolveSessionStoreBackupPaths`), marker helpers for transitional `sessionFile` values, bounded recent user/assistant transcript text reads by session identity, session store path/session-key helpers, and updated-at reads, without broad config writes/maintenance imports |
249-
| `plugin-sdk/session-catalog` | External session catalog contracts, projections, adoption helpers, and history import |
249+
| `plugin-sdk/session-catalog` | External session catalog contracts, canonical cursor/parameter/transcript paging, explicit local-plus-node family composition, node-host bindings, adoption helpers, and history import |
250250
| `plugin-sdk/session-discussion` | External session discussion provider contracts, registration, and canonical Control UI session path building |
251251
| `plugin-sdk/session-transcript-runtime` | Private-local after July 2026; Transcript identity, bounded raw and visible cursors, scoped target/read/write helpers, visible message-entry projection, update publishing, write locks, and transcript memory hit keys |
252252
| `plugin-sdk/sqlite-runtime` | Private-local after July 2026; Focused SQLite agent-schema, path, and transaction helpers for first-party runtime, without database lifecycle controls |

‎extensions/acpx/lazy-import.test.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ describe("acpx Pi session catalog lazy imports", () => {
2525
checkUpstreamActivity: async () => [],
2626
openTerminal: async () => ({ kind: "local", argv: ["pi"] }),
2727
}),
28-
listPiSessions: async () => "[]",
29-
readPiSession: async () => "{}",
30-
resumePiSession: async () => "{}",
28+
listPiSessions: async () => ({ sessions: [] }),
29+
readPiSession: async () => ({ hostId: "gateway", threadId: "", items: [] }),
30+
requireLocalPiSession: async () => ({ threadId: "test", cwd: "/tmp" }),
3131
};
3232
});
3333

@@ -55,8 +55,8 @@ describe("acpx Pi session catalog lazy imports", () => {
5555

5656
await expect(catalogs[0]?.list({ agentId: "main" })).resolves.toEqual([]);
5757
await expect(catalogs[0]?.list({ agentId: "main" })).resolves.toEqual([]);
58-
await expect(nodeCommands[0]?.handle()).resolves.toBe("[]");
59-
await expect(nodeCommands[0]?.handle()).resolves.toBe("[]");
58+
await expect(nodeCommands[0]?.handle()).resolves.toBe('{"sessions":[]}');
59+
await expect(nodeCommands[0]?.handle()).resolves.toBe('{"sessions":[]}');
6060
expect(runtimeImports).toBe(1);
6161
});
6262
});

‎extensions/acpx/src/pi-session-catalog-plugin.ts‎

Lines changed: 46 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@ import {
33
createLazyRuntimeSurface,
44
} from "openclaw/plugin-sdk/lazy-runtime";
55
import { resolveNodeHostExecutable } from "openclaw/plugin-sdk/node-host";
6-
import type {
7-
OpenClawPluginApi,
8-
OpenClawPluginNodeHostCommand,
9-
OpenClawPluginNodeInvokePolicy,
10-
} from "openclaw/plugin-sdk/plugin-entry";
11-
import type { SessionCatalogProvider } from "openclaw/plugin-sdk/session-catalog";
6+
import type { OpenClawPluginApi } from "openclaw/plugin-sdk/plugin-entry";
7+
import {
8+
createSessionCatalogNodeHostBindings,
9+
type SessionCatalogProvider,
10+
} from "openclaw/plugin-sdk/session-catalog";
1211
import { isRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
1312
import {
13+
PI_SESSIONS_CAPABILITY,
1414
PI_SESSIONS_LIST_COMMAND,
15+
PI_SESSION_ID_PATTERN,
1516
PI_SESSION_READ_COMMAND,
1617
PI_TERMINAL_RESUME_COMMAND,
1718
} from "./pi-session-catalog-shared.js";
1819
import { piSessionStoreAvailable } from "./pi-session-paths.js";
1920

20-
const PI_SESSIONS_CAPABILITY = "pi-sessions";
2121
const loadPiSessionCatalogModule = createLazyRuntimeModule(
2222
() => import("./pi-session-catalog-runtime.js"),
2323
);
@@ -41,55 +41,45 @@ function isPiSessionCatalogEnabled(pluginConfig: unknown): boolean {
4141
);
4242
}
4343

44-
function createPiSessionNodeHostCommands(): OpenClawPluginNodeHostCommand[] {
44+
function createPiSessionNodeHostBindings() {
4545
const storeAvailable = ({ config, env }: { config: unknown; env: NodeJS.ProcessEnv }) =>
4646
fullConfigCatalogEnabled(config) && piSessionStoreAvailable(env);
47-
return [
48-
{
49-
command: PI_SESSIONS_LIST_COMMAND,
50-
cap: PI_SESSIONS_CAPABILITY,
51-
dangerous: false,
52-
isAvailable: storeAvailable,
53-
handle: async (paramsJSON) =>
54-
await (await loadPiSessionCatalogModule()).listPiSessions(paramsJSON),
55-
},
56-
{
57-
command: PI_SESSION_READ_COMMAND,
58-
cap: PI_SESSIONS_CAPABILITY,
59-
dangerous: false,
60-
isAvailable: storeAvailable,
61-
handle: async (paramsJSON) =>
62-
await (await loadPiSessionCatalogModule()).readPiSession(paramsJSON),
63-
},
64-
{
65-
command: PI_TERMINAL_RESUME_COMMAND,
66-
cap: PI_SESSIONS_CAPABILITY,
67-
dangerous: false,
68-
duplex: true,
69-
isAvailable: ({ config, env }) =>
70-
storeAvailable({ config, env }) &&
71-
Boolean(
72-
resolveNodeHostExecutable("pi", {
73-
env,
74-
pathEnv: env.PATH ?? env.Path ?? "",
75-
strategy: "direct",
76-
}),
77-
),
78-
handle: async (paramsJSON, io) =>
79-
await (await loadPiSessionCatalogModule()).resumePiSession(paramsJSON, io),
80-
},
81-
];
82-
}
83-
84-
function createPiSessionNodeInvokePolicies(): OpenClawPluginNodeInvokePolicy[] {
85-
return [
86-
{
87-
commands: [PI_SESSIONS_LIST_COMMAND, PI_SESSION_READ_COMMAND, PI_TERMINAL_RESUME_COMMAND],
88-
defaultPlatforms: ["macos", "linux", "windows"],
89-
handle: (context) =>
90-
context.command === PI_TERMINAL_RESUME_COMMAND ? { ok: true } : context.invokeNode(),
47+
return createSessionCatalogNodeHostBindings({
48+
capability: PI_SESSIONS_CAPABILITY,
49+
listCommand: PI_SESSIONS_LIST_COMMAND,
50+
readCommand: PI_SESSION_READ_COMMAND,
51+
terminalCommand: PI_TERMINAL_RESUME_COMMAND,
52+
sessionIdPattern: PI_SESSION_ID_PATTERN,
53+
executable: "pi",
54+
args: (threadId) => ["--session", threadId],
55+
listAvailable: storeAvailable,
56+
terminalAvailable: ({ config, env }) =>
57+
storeAvailable({ config, env }) &&
58+
Boolean(
59+
resolveNodeHostExecutable("pi", {
60+
env,
61+
pathEnv: env.PATH ?? env.Path ?? "",
62+
strategy: "direct",
63+
}),
64+
),
65+
parseParams: (paramsJSON) => {
66+
if (!paramsJSON) {
67+
return undefined;
68+
}
69+
try {
70+
return JSON.parse(paramsJSON) as unknown;
71+
} catch (error) {
72+
throw new Error("Pi session parameters must be valid JSON", { cause: error });
73+
}
9174
},
92-
];
75+
list: async (params) => await (await loadPiSessionCatalogModule()).listPiSessions(params),
76+
read: async (params) => await (await loadPiSessionCatalogModule()).readPiSession(params),
77+
requireSession: async (threadId) =>
78+
await (await loadPiSessionCatalogModule()).requireLocalPiSession(threadId),
79+
terminalIoRequiredMessage: "Pi terminal command requires duplex transport",
80+
terminalUnavailableMessage: "Pi CLI is unavailable",
81+
invalidThreadIdMessage: "INVALID_REQUEST: threadId is invalid",
82+
});
9383
}
9484

9585
export function registerPiSessionCatalog(api: OpenClawPluginApi): void {
@@ -111,10 +101,11 @@ export function registerPiSessionCatalog(api: OpenClawPluginApi): void {
111101
openTerminal: async (request) => await (await loadCatalogRuntime()).openTerminal(request),
112102
};
113103
api.registerSessionCatalog(provider);
114-
for (const command of createPiSessionNodeHostCommands()) {
104+
const nodeHost = createPiSessionNodeHostBindings();
105+
for (const command of nodeHost.commands) {
115106
api.registerNodeHostCommand(command);
116107
}
117-
for (const policy of createPiSessionNodeInvokePolicies()) {
108+
for (const policy of nodeHost.policies) {
118109
api.registerNodeInvokePolicy(policy);
119110
}
120111
}

0 commit comments

Comments
 (0)