@privateclaw/privateclaw 0.1.11 → 0.1.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/cli.ts CHANGED
@@ -1,13 +1,43 @@
1
1
  #!/usr/bin/env node
2
2
 
3
+ import { parseArgs } from "node:util";
4
+ import { mkdir, readFile, writeFile } from "node:fs/promises";
5
+ import path from "node:path";
3
6
  import { EchoBridge } from "./bridges/echo-bridge.js";
4
7
  import { OpenClawAgentBridge } from "./bridges/openclaw-agent-bridge.js";
5
8
  import { OpenAICompatibleBridge } from "./bridges/openai-compatible-bridge.js";
6
9
  import { WebhookBridge } from "./bridges/webhook-bridge.js";
7
- import { runPairSession } from "./pair-session.js";
10
+ import { loadAvailableOpenClawCommands } from "./openclaw-command-discovery.js";
11
+ import {
12
+ parsePositiveIntegerFlag,
13
+ printPairInviteBundle,
14
+ runPairSession,
15
+ } from "./pair-session.js";
16
+ import {
17
+ handoffForegroundPairToBackground,
18
+ spawnBackgroundPairDaemon,
19
+ } from "./pair-daemon.js";
8
20
  import { DEFAULT_SESSION_TTL_MS, PrivateClawProvider } from "./provider.js";
9
21
  import { DEFAULT_RELAY_BASE_URL } from "./relay-defaults.js";
10
22
  import { resolveRelayEndpoints } from "./relay-endpoints.js";
23
+ import {
24
+ buildManagedSessionsReportLines,
25
+ kickManagedParticipantFromStateDir,
26
+ listManagedSessionsFromStateDir,
27
+ PrivateClawSessionControlServer,
28
+ resolvePrivateClawStateDir,
29
+ } from "./session-control.js";
30
+ import {
31
+ formatBilingualInline,
32
+ PRIVATECLAW_CLI_RELAY_OPTION_DESCRIPTION,
33
+ } from "./text.js";
34
+ import type { PrivateClawProviderHandoffState } from "./types.js";
35
+
36
+ type BridgeMode =
37
+ | "echo"
38
+ | "webhook"
39
+ | "openclaw-agent"
40
+ | "openai-compatible";
11
41
 
12
42
  function parsePositiveInteger(value: string | undefined, fallback: number): number {
13
43
  if (!value || value.trim() === "") {
@@ -34,79 +64,447 @@ function resolveChatCompletionsUrl(baseUrl: string): string {
34
64
  return url.toString();
35
65
  }
36
66
 
37
- const relayBaseUrl = process.env.PRIVATECLAW_RELAY_BASE_URL?.trim() || DEFAULT_RELAY_BASE_URL;
38
- const { providerWsUrl, appWsUrl } = resolveRelayEndpoints(relayBaseUrl);
39
- const webhookUrl = process.env.PRIVATECLAW_WEBHOOK_URL?.trim();
40
- const webhookToken = process.env.PRIVATECLAW_WEBHOOK_TOKEN?.trim();
41
- const gatewayBaseUrl = process.env.PRIVATECLAW_GATEWAY_BASE_URL?.trim();
42
- const gatewayChatCompletionsUrl = process.env.PRIVATECLAW_GATEWAY_CHAT_COMPLETIONS_URL?.trim();
43
- const gatewayModel = process.env.PRIVATECLAW_GATEWAY_MODEL?.trim() || "openclaw";
44
- const gatewayApiKey = process.env.PRIVATECLAW_GATEWAY_API_KEY?.trim();
45
- const gatewaySystemPrompt = process.env.PRIVATECLAW_GATEWAY_SYSTEM_PROMPT?.trim();
46
- const openClawAgentBridge = parseBooleanFlag(process.env.PRIVATECLAW_OPENCLAW_AGENT_BRIDGE);
47
- const openClawAgentExecutable = process.env.PRIVATECLAW_OPENCLAW_AGENT_BIN?.trim();
48
- const openClawAgentId = process.env.PRIVATECLAW_OPENCLAW_AGENT_ID?.trim();
49
- const openClawAgentChannel = process.env.PRIVATECLAW_OPENCLAW_AGENT_CHANNEL?.trim();
50
- const openClawAgentThinking = process.env.PRIVATECLAW_OPENCLAW_AGENT_THINKING?.trim() as
51
- | "off"
52
- | "minimal"
53
- | "low"
54
- | "medium"
55
- | "high"
56
- | undefined;
57
- const openClawAgentLocal = parseBooleanFlag(process.env.PRIVATECLAW_OPENCLAW_AGENT_LOCAL);
58
- const openClawAgentTimeoutSeconds = process.env.PRIVATECLAW_OPENCLAW_AGENT_TIMEOUT_SECONDS
59
- ? parsePositiveInteger(process.env.PRIVATECLAW_OPENCLAW_AGENT_TIMEOUT_SECONDS, 600)
60
- : undefined;
61
- const ttlMs = parsePositiveInteger(
62
- process.env.PRIVATECLAW_SESSION_TTL_MS,
63
- DEFAULT_SESSION_TTL_MS,
64
- );
65
- const openQr = parseBooleanFlag(process.env.PRIVATECLAW_OPEN_QR);
66
- const providerLabel = process.env.PRIVATECLAW_PROVIDER_LABEL?.trim() || "PrivateClaw";
67
- const welcomeMessage = process.env.PRIVATECLAW_WELCOME_MESSAGE?.trim();
68
-
69
- const bridge =
70
- openClawAgentBridge
71
- ? new OpenClawAgentBridge({
72
- ...(openClawAgentExecutable ? { executable: openClawAgentExecutable } : {}),
73
- ...(openClawAgentId ? { agentId: openClawAgentId } : {}),
74
- ...(openClawAgentChannel ? { channel: openClawAgentChannel } : {}),
75
- ...(openClawAgentThinking ? { thinking: openClawAgentThinking } : {}),
76
- ...(openClawAgentTimeoutSeconds ? { timeoutSeconds: openClawAgentTimeoutSeconds } : {}),
77
- ...(openClawAgentLocal ? { local: true } : {}),
67
+ function detectBridgeMode(): BridgeMode {
68
+ const explicit = process.env.PRIVATECLAW_BRIDGE_MODE?.trim().toLowerCase();
69
+ if (
70
+ explicit === "echo" ||
71
+ explicit === "webhook" ||
72
+ explicit === "openclaw-agent" ||
73
+ explicit === "openai-compatible"
74
+ ) {
75
+ return explicit;
76
+ }
77
+
78
+ const hasOpenClawAgentConfig =
79
+ parseBooleanFlag(process.env.PRIVATECLAW_OPENCLAW_AGENT_BRIDGE) ||
80
+ Boolean(process.env.PRIVATECLAW_OPENCLAW_AGENT_BIN?.trim()) ||
81
+ Boolean(process.env.PRIVATECLAW_OPENCLAW_AGENT_ID?.trim()) ||
82
+ Boolean(process.env.PRIVATECLAW_OPENCLAW_AGENT_CHANNEL?.trim());
83
+ if (hasOpenClawAgentConfig) {
84
+ return "openclaw-agent";
85
+ }
86
+ if (
87
+ process.env.PRIVATECLAW_GATEWAY_CHAT_COMPLETIONS_URL?.trim() ||
88
+ process.env.PRIVATECLAW_GATEWAY_BASE_URL?.trim()
89
+ ) {
90
+ return "openai-compatible";
91
+ }
92
+ if (process.env.PRIVATECLAW_WEBHOOK_URL?.trim()) {
93
+ return "webhook";
94
+ }
95
+ return "echo";
96
+ }
97
+
98
+ function createProvider(params?: {
99
+ providerId?: string;
100
+ relayBaseUrl?: string;
101
+ }): {
102
+ provider: PrivateClawProvider;
103
+ stateDir: string;
104
+ } {
105
+ const providerWsUrl = process.env.PRIVATECLAW_PROVIDER_WS_URL?.trim();
106
+ const appWsUrl = process.env.PRIVATECLAW_APP_WS_URL?.trim();
107
+ const relayBaseUrl =
108
+ params?.relayBaseUrl?.trim() ||
109
+ process.env.PRIVATECLAW_RELAY_BASE_URL?.trim() ||
110
+ DEFAULT_RELAY_BASE_URL;
111
+ const relayEndpoints =
112
+ !params?.relayBaseUrl && providerWsUrl && appWsUrl
113
+ ? { providerWsUrl, appWsUrl }
114
+ : resolveRelayEndpoints(relayBaseUrl);
115
+ const bridgeMode = detectBridgeMode();
116
+
117
+ const webhookUrl = process.env.PRIVATECLAW_WEBHOOK_URL?.trim();
118
+ const webhookToken = process.env.PRIVATECLAW_WEBHOOK_TOKEN?.trim();
119
+ const gatewayBaseUrl = process.env.PRIVATECLAW_GATEWAY_BASE_URL?.trim();
120
+ const gatewayChatCompletionsUrl =
121
+ process.env.PRIVATECLAW_GATEWAY_CHAT_COMPLETIONS_URL?.trim();
122
+ const gatewayModel =
123
+ process.env.PRIVATECLAW_GATEWAY_MODEL?.trim() || "openclaw";
124
+ const gatewayApiKey = process.env.PRIVATECLAW_GATEWAY_API_KEY?.trim();
125
+ const gatewaySystemPrompt =
126
+ process.env.PRIVATECLAW_GATEWAY_SYSTEM_PROMPT?.trim();
127
+ const openClawAgentExecutable =
128
+ process.env.PRIVATECLAW_OPENCLAW_AGENT_BIN?.trim();
129
+ const openClawAgentId = process.env.PRIVATECLAW_OPENCLAW_AGENT_ID?.trim();
130
+ const openClawAgentChannel =
131
+ process.env.PRIVATECLAW_OPENCLAW_AGENT_CHANNEL?.trim();
132
+ const openClawAgentThinking = process.env.PRIVATECLAW_OPENCLAW_AGENT_THINKING
133
+ ?.trim() as
134
+ | "off"
135
+ | "minimal"
136
+ | "low"
137
+ | "medium"
138
+ | "high"
139
+ | undefined;
140
+ const openClawAgentLocal = parseBooleanFlag(
141
+ process.env.PRIVATECLAW_OPENCLAW_AGENT_LOCAL,
142
+ );
143
+ const openClawAgentTimeoutSeconds =
144
+ process.env.PRIVATECLAW_OPENCLAW_AGENT_TIMEOUT_SECONDS
145
+ ? parsePositiveInteger(
146
+ process.env.PRIVATECLAW_OPENCLAW_AGENT_TIMEOUT_SECONDS,
147
+ 600,
148
+ )
149
+ : undefined;
150
+
151
+ const bridge =
152
+ bridgeMode === "openclaw-agent"
153
+ ? new OpenClawAgentBridge({
154
+ ...(openClawAgentExecutable
155
+ ? { executable: openClawAgentExecutable }
156
+ : {}),
157
+ ...(openClawAgentId ? { agentId: openClawAgentId } : {}),
158
+ ...(openClawAgentChannel ? { channel: openClawAgentChannel } : {}),
159
+ ...(openClawAgentThinking ? { thinking: openClawAgentThinking } : {}),
160
+ ...(openClawAgentTimeoutSeconds
161
+ ? { timeoutSeconds: openClawAgentTimeoutSeconds }
162
+ : {}),
163
+ ...(openClawAgentLocal ? { local: true } : {}),
164
+ onLog: (message) => {
165
+ console.log(`[privateclaw-provider] ${message}`);
166
+ },
167
+ })
168
+ : bridgeMode === "openai-compatible"
169
+ ? new OpenAICompatibleBridge({
170
+ endpoint:
171
+ gatewayChatCompletionsUrl ||
172
+ resolveChatCompletionsUrl(gatewayBaseUrl!),
173
+ model: gatewayModel,
174
+ ...(gatewayApiKey ? { apiKey: gatewayApiKey } : {}),
175
+ ...(gatewaySystemPrompt
176
+ ? { systemPrompt: gatewaySystemPrompt }
177
+ : {}),
178
+ })
179
+ : bridgeMode === "webhook"
180
+ ? new WebhookBridge({
181
+ endpoint: webhookUrl!,
182
+ ...(webhookToken ? { token: webhookToken } : {}),
183
+ })
184
+ : new EchoBridge(
185
+ process.env.PRIVATECLAW_ECHO_PREFIX?.trim() || "PrivateClaw demo",
186
+ );
187
+
188
+ const ttlMs = parsePositiveInteger(
189
+ process.env.PRIVATECLAW_SESSION_TTL_MS,
190
+ DEFAULT_SESSION_TTL_MS,
191
+ );
192
+ const providerLabel =
193
+ process.env.PRIVATECLAW_PROVIDER_LABEL?.trim() || "PrivateClaw";
194
+ const welcomeMessage = process.env.PRIVATECLAW_WELCOME_MESSAGE?.trim();
195
+
196
+ return {
197
+ provider: new PrivateClawProvider({
198
+ providerWsUrl: relayEndpoints.providerWsUrl,
199
+ appWsUrl: relayEndpoints.appWsUrl,
200
+ bridge,
201
+ ...(params?.providerId ? { providerId: params.providerId } : {}),
202
+ defaultTtlMs: ttlMs,
203
+ providerLabel,
204
+ commandsProvider: async () => {
205
+ try {
206
+ return await loadAvailableOpenClawCommands();
207
+ } catch {
208
+ return [];
209
+ }
210
+ },
211
+ ...(welcomeMessage ? { welcomeMessage } : {}),
212
+ onLog: (message) => {
213
+ console.log(`[privateclaw-provider] ${message}`);
214
+ },
215
+ }),
216
+ stateDir: resolvePrivateClawStateDir(),
217
+ };
218
+ }
219
+
220
+ async function waitForSessionsToDrain(
221
+ provider: PrivateClawProvider,
222
+ ): Promise<void> {
223
+ while (provider.listActiveSessions().length > 0) {
224
+ await new Promise((resolve) => setTimeout(resolve, 250));
225
+ }
226
+ }
227
+
228
+ async function writeDaemonResult(
229
+ resultFile: string,
230
+ payload: unknown,
231
+ ): Promise<void> {
232
+ await mkdir(path.dirname(resultFile), { recursive: true });
233
+ await writeFile(resultFile, JSON.stringify(payload), "utf8");
234
+ }
235
+
236
+ async function readHandoffState(
237
+ snapshotFile: string,
238
+ ): Promise<PrivateClawProviderHandoffState> {
239
+ return JSON.parse(await readFile(snapshotFile, "utf8")) as PrivateClawProviderHandoffState;
240
+ }
241
+
242
+ function printHelp(): void {
243
+ console.log(`privateclaw-provider <pair|sessions|kick>
244
+
245
+ pair [--ttl-ms <ms>] [--label <label>] [--relay <url>] [--group] [--print-only] [--open] [--foreground]
246
+ sessions
247
+ kick <sessionId> <appId>`);
248
+ console.log(`\n--relay <url>: ${PRIVATECLAW_CLI_RELAY_OPTION_DESCRIPTION}`);
249
+ }
250
+
251
+ async function runPairCommand(args: string[]): Promise<void> {
252
+ const parsed = parseArgs({
253
+ args,
254
+ allowPositionals: true,
255
+ options: {
256
+ "ttl-ms": { type: "string" },
257
+ label: { type: "string" },
258
+ relay: { type: "string", short: "r" },
259
+ group: { type: "boolean", default: false },
260
+ "print-only": { type: "boolean", default: false },
261
+ open: { type: "boolean", default: parseBooleanFlag(process.env.PRIVATECLAW_OPEN_QR) },
262
+ foreground: { type: "boolean", default: false },
263
+ "daemon-child": { type: "boolean", default: false },
264
+ "result-file": { type: "string" },
265
+ "resume-snapshot-file": { type: "string" },
266
+ help: { type: "boolean", short: "h" },
267
+ },
268
+ });
269
+
270
+ if (parsed.values.help) {
271
+ printHelp();
272
+ return;
273
+ }
274
+
275
+ const ttlMs = parsePositiveIntegerFlag(parsed.values["ttl-ms"], "--ttl-ms");
276
+ const label = parsed.values.label?.trim();
277
+ const relayBaseUrl = parsed.values.relay?.trim();
278
+ const groupMode = parsed.values.group === true;
279
+ const printOnly = parsed.values["print-only"] === true;
280
+ const openInBrowser = parsed.values.open === true;
281
+ const foreground = parsed.values.foreground === true;
282
+ const daemonChild = parsed.values["daemon-child"] === true;
283
+ const resultFile = parsed.values["result-file"];
284
+ const resumeSnapshotFile = parsed.values["resume-snapshot-file"];
285
+
286
+ if (daemonChild) {
287
+ if (!resultFile) {
288
+ throw new Error("--daemon-child requires --result-file.");
289
+ }
290
+ let provider: PrivateClawProvider | undefined;
291
+ let controlServer: PrivateClawSessionControlServer | undefined;
292
+ try {
293
+ const handoffState = resumeSnapshotFile
294
+ ? await readHandoffState(resumeSnapshotFile)
295
+ : undefined;
296
+ const resolved = createProvider(
297
+ handoffState
298
+ ? {
299
+ providerId: handoffState.providerId,
300
+ ...(relayBaseUrl ? { relayBaseUrl } : {}),
301
+ }
302
+ : relayBaseUrl
303
+ ? { relayBaseUrl }
304
+ : undefined,
305
+ );
306
+ provider = resolved.provider;
307
+ if (handoffState) {
308
+ provider.importHandoffState(handoffState);
309
+ await provider.connect();
310
+ }
311
+ controlServer = new PrivateClawSessionControlServer({
312
+ provider,
313
+ stateDir: resolved.stateDir,
314
+ kind: "pair-daemon",
78
315
  onLog: (message) => {
79
316
  console.log(`[privateclaw-provider] ${message}`);
80
317
  },
81
- })
82
- : gatewayChatCompletionsUrl || gatewayBaseUrl
83
- ? new OpenAICompatibleBridge({
84
- endpoint: gatewayChatCompletionsUrl || resolveChatCompletionsUrl(gatewayBaseUrl!),
85
- model: gatewayModel,
86
- ...(gatewayApiKey ? { apiKey: gatewayApiKey } : {}),
87
- ...(gatewaySystemPrompt ? { systemPrompt: gatewaySystemPrompt } : {}),
88
- })
89
- : webhookUrl
90
- ? new WebhookBridge({ endpoint: webhookUrl, ...(webhookToken ? { token: webhookToken } : {}) })
91
- : new EchoBridge(process.env.PRIVATECLAW_ECHO_PREFIX?.trim() || "PrivateClaw demo");
92
-
93
- const provider = new PrivateClawProvider({
94
- providerWsUrl,
95
- appWsUrl,
96
- bridge,
97
- defaultTtlMs: ttlMs,
98
- providerLabel,
99
- ...(welcomeMessage ? { welcomeMessage } : {}),
100
- onLog: (message) => {
101
- console.log(`[privateclaw-provider] ${message}`);
102
- },
103
- });
104
-
105
- await runPairSession({
106
- provider,
107
- ttlMs,
108
- ...(openQr ? { openInBrowser: true } : {}),
109
- writeLine: (line) => {
318
+ });
319
+ await controlServer.start();
320
+ if (handoffState) {
321
+ await writeDaemonResult(resultFile, {
322
+ ok: true,
323
+ resumedSessionCount: handoffState.sessions.length,
324
+ });
325
+ } else {
326
+ const bundle = await runPairSession({
327
+ provider,
328
+ ...(typeof ttlMs === "number" ? { ttlMs } : {}),
329
+ ...(label ? { label } : {}),
330
+ ...(groupMode ? { groupMode: true } : {}),
331
+ ...(openInBrowser ? { openInBrowser: true } : {}),
332
+ foreground: false,
333
+ writeLine: () => undefined,
334
+ });
335
+ await writeDaemonResult(resultFile, { ok: true, bundle });
336
+ }
337
+ await waitForSessionsToDrain(provider);
338
+ } catch (error) {
339
+ await writeDaemonResult(resultFile, {
340
+ ok: false,
341
+ error: error instanceof Error ? error.message : String(error),
342
+ });
343
+ throw error;
344
+ } finally {
345
+ await controlServer?.stop();
346
+ await provider?.dispose();
347
+ }
348
+ return;
349
+ }
350
+
351
+ if (printOnly || foreground) {
352
+ const { provider, stateDir } = createProvider(
353
+ relayBaseUrl ? { relayBaseUrl } : undefined,
354
+ );
355
+ const controlServer =
356
+ printOnly
357
+ ? undefined
358
+ : new PrivateClawSessionControlServer({
359
+ provider,
360
+ stateDir,
361
+ kind: "pair-foreground",
362
+ onLog: (message) => {
363
+ console.log(`[privateclaw-provider] ${message}`);
364
+ },
365
+ });
366
+ try {
367
+ await controlServer?.start();
368
+ await runPairSession({
369
+ provider,
370
+ ...(typeof ttlMs === "number" ? { ttlMs } : {}),
371
+ ...(label ? { label } : {}),
372
+ ...(groupMode ? { groupMode: true } : {}),
373
+ ...(printOnly ? { printOnly: true } : {}),
374
+ ...(openInBrowser ? { openInBrowser: true } : {}),
375
+ foreground: true,
376
+ ...(printOnly
377
+ ? {}
378
+ : {
379
+ handoffToBackground: async () => {
380
+ provider.suppressReconnectsForHandoff();
381
+ try {
382
+ await handoffForegroundPairToBackground({
383
+ cliModuleUrl: import.meta.url,
384
+ stateDir,
385
+ env: relayBaseUrl
386
+ ? {
387
+ ...process.env,
388
+ PRIVATECLAW_RELAY_BASE_URL: relayBaseUrl,
389
+ }
390
+ : process.env,
391
+ handoffState: provider.exportHandoffState(),
392
+ });
393
+ return formatBilingualInline(
394
+ "当前 PrivateClaw 会话已转入后台。可使用 `privateclaw-provider sessions` 查看。",
395
+ "The current PrivateClaw session is now running in the background. Use `privateclaw-provider sessions` to inspect it.",
396
+ );
397
+ } catch (error) {
398
+ provider.resumeReconnectsAfterHandoffFailure();
399
+ throw error;
400
+ }
401
+ },
402
+ }),
403
+ });
404
+ } finally {
405
+ await controlServer?.stop();
406
+ }
407
+ return;
408
+ }
409
+
410
+ const bundle = await spawnBackgroundPairDaemon({
411
+ cliModuleUrl: import.meta.url,
412
+ stateDir: resolvePrivateClawStateDir(),
413
+ env: relayBaseUrl
414
+ ? {
415
+ ...process.env,
416
+ PRIVATECLAW_RELAY_BASE_URL: relayBaseUrl,
417
+ }
418
+ : process.env,
419
+ ...(typeof ttlMs === "number" ? { ttlMs } : {}),
420
+ ...(label ? { label } : {}),
421
+ ...(groupMode ? { groupMode: true } : {}),
422
+ ...(openInBrowser ? { openInBrowser: true } : {}),
423
+ });
424
+ printPairInviteBundle(bundle, (line) => {
425
+ console.log(line);
426
+ });
427
+ }
428
+
429
+ async function runSessionsCommand(args: string[]): Promise<void> {
430
+ const parsed = parseArgs({
431
+ args,
432
+ allowPositionals: true,
433
+ options: {
434
+ help: { type: "boolean", short: "h" },
435
+ },
436
+ });
437
+ if (parsed.values.help) {
438
+ printHelp();
439
+ return;
440
+ }
441
+
442
+ const listings = await listManagedSessionsFromStateDir(resolvePrivateClawStateDir());
443
+ for (const line of buildManagedSessionsReportLines(listings)) {
110
444
  console.log(line);
111
- },
112
- });
445
+ }
446
+ }
447
+
448
+ async function runKickCommand(args: string[]): Promise<void> {
449
+ const parsed = parseArgs({
450
+ args,
451
+ allowPositionals: true,
452
+ options: {
453
+ help: { type: "boolean", short: "h" },
454
+ },
455
+ });
456
+ if (parsed.values.help) {
457
+ printHelp();
458
+ return;
459
+ }
460
+ if (parsed.positionals.length < 2) {
461
+ throw new Error(
462
+ formatBilingualInline(
463
+ "kick 需要提供 sessionId 和 appId。",
464
+ "kick requires both a sessionId and appId.",
465
+ ),
466
+ );
467
+ }
468
+
469
+ const [sessionIdRaw, appIdRaw] = parsed.positionals;
470
+ if (!sessionIdRaw || !appIdRaw) {
471
+ throw new Error(
472
+ formatBilingualInline(
473
+ "kick 需要提供 sessionId 和 appId。",
474
+ "kick requires both a sessionId and appId.",
475
+ ),
476
+ );
477
+ }
478
+ const sessionId = sessionIdRaw;
479
+ const appId = appIdRaw;
480
+ const result = await kickManagedParticipantFromStateDir({
481
+ stateDir: resolvePrivateClawStateDir(),
482
+ sessionId,
483
+ appId,
484
+ reason: "participant_removed",
485
+ });
486
+ console.log(
487
+ formatBilingualInline(
488
+ `已从会话 ${result.session.sessionId} 中移除 ${result.participant.displayName} (${result.participant.appId})。`,
489
+ `Removed ${result.participant.displayName} (${result.participant.appId}) from session ${result.session.sessionId}.`,
490
+ ),
491
+ );
492
+ }
493
+
494
+ const argv = process.argv.slice(2);
495
+ const [command, ...rest] =
496
+ argv.length === 0 || argv[0]!.startsWith("-")
497
+ ? ["pair", ...argv]
498
+ : argv;
499
+
500
+ if (command === "pair") {
501
+ await runPairCommand(rest);
502
+ } else if (command === "sessions") {
503
+ await runSessionsCommand(rest);
504
+ } else if (command === "kick") {
505
+ await runKickCommand(rest);
506
+ } else if (command === "help" || command === "--help" || command === "-h") {
507
+ printHelp();
508
+ } else {
509
+ throw new Error(`Unsupported privateclaw-provider command: ${command}`);
510
+ }
@@ -127,6 +127,7 @@ export interface OpenClawPluginServiceCompat {
127
127
  export interface OpenClawCliCommandCompat {
128
128
  command(name: string): OpenClawCliCommandCompat;
129
129
  description(text: string): OpenClawCliCommandCompat;
130
+ argument(spec: string): OpenClawCliCommandCompat;
130
131
  option(
131
132
  flags: string,
132
133
  description?: string,