@privateclaw/privateclaw 0.1.16 → 0.1.17
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/README.md +44 -1
- package/dist/audio-transcriber.d.ts +46 -0
- package/dist/audio-transcriber.js +433 -0
- package/dist/audio-transcriber.js.map +1 -0
- package/dist/bridges/openclaw-agent-bridge.d.ts +4 -1
- package/dist/bridges/openclaw-agent-bridge.js +81 -8
- package/dist/bridges/openclaw-agent-bridge.js.map +1 -1
- package/dist/cli.js +57 -6
- package/dist/cli.js.map +1 -1
- package/dist/openclaw-plugin.js +150 -51
- package/dist/openclaw-plugin.js.map +1 -1
- package/dist/pair-daemon.d.ts +2 -0
- package/dist/pair-daemon.js +2 -0
- package/dist/pair-daemon.js.map +1 -1
- package/dist/provider.d.ts +2 -0
- package/dist/provider.js +103 -14
- package/dist/provider.js.map +1 -1
- package/dist/session-control.d.ts +7 -0
- package/dist/session-control.js +122 -0
- package/dist/session-control.js.map +1 -1
- package/dist/text.d.ts +2 -0
- package/dist/text.js +3 -1
- package/dist/text.js.map +1 -1
- package/dist/types.d.ts +8 -0
- package/package.json +1 -1
- package/src/audio-transcriber.test.ts +299 -0
- package/src/audio-transcriber.ts +615 -0
- package/src/bridges/openclaw-agent-bridge.test.ts +78 -13
- package/src/bridges/openclaw-agent-bridge.ts +109 -7
- package/src/cli.ts +73 -5
- package/src/openclaw-plugin.test.ts +12 -2
- package/src/openclaw-plugin.ts +191 -54
- package/src/pair-daemon.ts +4 -0
- package/src/provider.test.ts +304 -0
- package/src/provider.ts +146 -20
- package/src/session-control.test.ts +80 -0
- package/src/session-control.ts +151 -0
- package/src/text.ts +12 -2
- package/src/types.ts +12 -0
|
@@ -93,6 +93,27 @@ test("parseOpenClawAgentOutput prefers tagged structured PrivateClaw responses",
|
|
|
93
93
|
});
|
|
94
94
|
});
|
|
95
95
|
|
|
96
|
+
test("parseOpenClawAgentOutput tolerates trailing commas inside structured responses", () => {
|
|
97
|
+
const result = parseOpenClawAgentOutput(
|
|
98
|
+
JSON.stringify({
|
|
99
|
+
status: "ok",
|
|
100
|
+
result: {
|
|
101
|
+
payloads: [
|
|
102
|
+
{
|
|
103
|
+
text: [
|
|
104
|
+
"<privateclaw-response>",
|
|
105
|
+
'{"version":1,"messages":[{"text":"voice-reply"},],"data":{}}',
|
|
106
|
+
"</privateclaw-response>",
|
|
107
|
+
].join("\n"),
|
|
108
|
+
},
|
|
109
|
+
],
|
|
110
|
+
},
|
|
111
|
+
}),
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
assert.equal(result, "voice-reply");
|
|
115
|
+
});
|
|
116
|
+
|
|
96
117
|
test("OpenClawAgentBridge invokes openclaw agent with session-aware arguments", async () => {
|
|
97
118
|
let invokedFile = "";
|
|
98
119
|
let invokedArgs: string[] = [];
|
|
@@ -157,6 +178,54 @@ test("OpenClawAgentBridge invokes openclaw agent with session-aware arguments",
|
|
|
157
178
|
assert.equal(result, "bridge-ok");
|
|
158
179
|
});
|
|
159
180
|
|
|
181
|
+
test("OpenClawAgentBridge emits verbose execution logs when enabled", async () => {
|
|
182
|
+
const logs: string[] = [];
|
|
183
|
+
|
|
184
|
+
const bridge = new OpenClawAgentBridge({
|
|
185
|
+
verboseController: { enabled: true },
|
|
186
|
+
onLog: (message) => {
|
|
187
|
+
logs.push(message);
|
|
188
|
+
},
|
|
189
|
+
execFileImpl: (_file, _args, _options, callback) => {
|
|
190
|
+
callback(
|
|
191
|
+
null,
|
|
192
|
+
JSON.stringify({
|
|
193
|
+
status: "ok",
|
|
194
|
+
result: {
|
|
195
|
+
payloads: [{ text: "verbose-ok" }],
|
|
196
|
+
},
|
|
197
|
+
}),
|
|
198
|
+
"",
|
|
199
|
+
);
|
|
200
|
+
},
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
const result = await bridge.handleUserMessage({
|
|
204
|
+
sessionId: "verbose-session",
|
|
205
|
+
message: "hello",
|
|
206
|
+
history: [],
|
|
207
|
+
invite: {
|
|
208
|
+
version: 1,
|
|
209
|
+
sessionId: "verbose-session",
|
|
210
|
+
sessionKey: "test",
|
|
211
|
+
appWsUrl: "ws://127.0.0.1/app?sessionId=verbose-session",
|
|
212
|
+
expiresAt: new Date().toISOString(),
|
|
213
|
+
},
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
assert.equal(result, "verbose-ok");
|
|
217
|
+
assert.ok(
|
|
218
|
+
logs.some((message) => message.includes("[bridge][verbose] exec_start session=verbose-session")),
|
|
219
|
+
"verbose bridge logging should include exec_start details",
|
|
220
|
+
);
|
|
221
|
+
assert.ok(
|
|
222
|
+
logs.some((message) =>
|
|
223
|
+
message.includes("[bridge][verbose] prompt_body_ready session=verbose-session"),
|
|
224
|
+
),
|
|
225
|
+
"verbose bridge logging should include prompt preparation details",
|
|
226
|
+
);
|
|
227
|
+
});
|
|
228
|
+
|
|
160
229
|
test("resolveOpenClawLaunchCommand reuses the current OpenClaw CLI script on Windows", () => {
|
|
161
230
|
const command = resolveOpenClawLaunchCommand({
|
|
162
231
|
platform: "win32",
|
|
@@ -322,19 +391,15 @@ test("OpenClawAgentBridge recovers structured assistant text from the session lo
|
|
|
322
391
|
message: {
|
|
323
392
|
role: "assistant",
|
|
324
393
|
content: [
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
}),
|
|
335
|
-
"</privateclaw-response>",
|
|
336
|
-
].join("\n"),
|
|
337
|
-
},
|
|
394
|
+
{
|
|
395
|
+
type: "text",
|
|
396
|
+
text: [
|
|
397
|
+
"Interim text that should be ignored.",
|
|
398
|
+
"<privateclaw-response>",
|
|
399
|
+
'{"version":1,"messages":[{"text":"pixel.png"},],"data":{"filename":"pixel.png"}}',
|
|
400
|
+
"</privateclaw-response>",
|
|
401
|
+
].join("\n"),
|
|
402
|
+
},
|
|
338
403
|
],
|
|
339
404
|
isError: false,
|
|
340
405
|
},
|
|
@@ -10,6 +10,7 @@ import type {
|
|
|
10
10
|
BridgeResponse,
|
|
11
11
|
PrivateClawAgentBridge,
|
|
12
12
|
PrivateClawAudioTranscriptionRequest,
|
|
13
|
+
PrivateClawVerboseController,
|
|
13
14
|
} from "../types.js";
|
|
14
15
|
|
|
15
16
|
type OpenClawThinkingLevel = "off" | "minimal" | "low" | "medium" | "high";
|
|
@@ -117,6 +118,7 @@ export interface OpenClawAgentBridgeOptions {
|
|
|
117
118
|
timeoutSeconds?: number;
|
|
118
119
|
stateDir?: string;
|
|
119
120
|
workspaceDir?: string;
|
|
121
|
+
verboseController?: PrivateClawVerboseController;
|
|
120
122
|
onLog?: (message: string) => void;
|
|
121
123
|
execFileImpl?: OpenClawAgentExecFile;
|
|
122
124
|
}
|
|
@@ -268,6 +270,17 @@ export class OpenClawAgentBridge implements PrivateClawAgentBridge {
|
|
|
268
270
|
this.options.onLog?.(`[bridge] ${message}`);
|
|
269
271
|
}
|
|
270
272
|
|
|
273
|
+
private isVerboseLoggingEnabled(): boolean {
|
|
274
|
+
return this.options.verboseController?.enabled === true;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
private verboseLog(message: string): void {
|
|
278
|
+
if (!this.isVerboseLoggingEnabled()) {
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
this.options.onLog?.(`[bridge][verbose] ${message}`);
|
|
282
|
+
}
|
|
283
|
+
|
|
271
284
|
async handleUserMessage(params: {
|
|
272
285
|
sessionId: string;
|
|
273
286
|
message: string;
|
|
@@ -331,8 +344,12 @@ export class OpenClawAgentBridge implements PrivateClawAgentBridge {
|
|
|
331
344
|
},
|
|
332
345
|
): Promise<BridgeResponse> {
|
|
333
346
|
const args = this.buildArgs(sessionId, promptMessage);
|
|
347
|
+
this.verboseLog(
|
|
348
|
+
`exec_start session=${sessionId} promptChars=${promptMessage.length} argCount=${args.length} includeArtifacts=${options?.includeArtifacts !== false} agent=${JSON.stringify(this.options.agentId ?? "default")} channel=${JSON.stringify(this.options.channel ?? "default")} local=${this.options.local === true} thinking=${JSON.stringify(this.options.thinking ?? "default")} timeoutSeconds=${this.options.timeoutSeconds ?? "default"}`,
|
|
349
|
+
);
|
|
334
350
|
const sessionLogCursor = await this.captureSessionLogCursor(sessionId);
|
|
335
351
|
const stdout = await this.execOpenClaw(args);
|
|
352
|
+
this.verboseLog(`exec_complete session=${sessionId} stdoutChars=${stdout.length}`);
|
|
336
353
|
let parsed: OpenClawAgentJsonResult | undefined;
|
|
337
354
|
let parseError: unknown;
|
|
338
355
|
try {
|
|
@@ -356,6 +373,9 @@ export class OpenClawAgentBridge implements PrivateClawAgentBridge {
|
|
|
356
373
|
...collectedMessages.assistantMessages,
|
|
357
374
|
...(options?.includeArtifacts === false ? [] : collectedMessages.artifactMessages),
|
|
358
375
|
];
|
|
376
|
+
this.verboseLog(
|
|
377
|
+
`session_log_delta session=${sessionId} assistantRecovered=${collectedMessages.assistantMessages.length} artifactRecovered=${collectedMessages.artifactMessages.length} includeArtifacts=${options?.includeArtifacts !== false}`,
|
|
378
|
+
);
|
|
359
379
|
if (!parsed) {
|
|
360
380
|
if (recoveredMessages.length > 0) {
|
|
361
381
|
this.log(
|
|
@@ -367,6 +387,9 @@ export class OpenClawAgentBridge implements PrivateClawAgentBridge {
|
|
|
367
387
|
}
|
|
368
388
|
try {
|
|
369
389
|
const response = parseOpenClawAgentResult(parsed);
|
|
390
|
+
this.verboseLog(
|
|
391
|
+
`response_ready session=${sessionId} directMessages=${typeof response === "string" ? 1 : response.messages.length} artifactMessages=${options?.includeArtifacts === false ? 0 : collectedMessages.artifactMessages.length}`,
|
|
392
|
+
);
|
|
370
393
|
return options?.includeArtifacts === false
|
|
371
394
|
? response
|
|
372
395
|
: mergeBridgeResponses(response, collectedMessages.artifactMessages);
|
|
@@ -390,10 +413,14 @@ export class OpenClawAgentBridge implements PrivateClawAgentBridge {
|
|
|
390
413
|
private async captureSessionLogCursor(sessionId: string): Promise<OpenClawSessionLogCursor> {
|
|
391
414
|
const sessionLogPath = await this.resolveSessionLogPath(sessionId);
|
|
392
415
|
if (!sessionLogPath) {
|
|
416
|
+
this.verboseLog(`session_log_cursor_missing session=${sessionId}`);
|
|
393
417
|
return { sizeBytes: 0 };
|
|
394
418
|
}
|
|
395
419
|
|
|
396
420
|
const stat = await fs.stat(sessionLogPath);
|
|
421
|
+
this.verboseLog(
|
|
422
|
+
`session_log_cursor session=${sessionId} logPath=${JSON.stringify(sessionLogPath)} sizeBytes=${stat.size}`,
|
|
423
|
+
);
|
|
397
424
|
return {
|
|
398
425
|
path: sessionLogPath,
|
|
399
426
|
sizeBytes: stat.size,
|
|
@@ -490,6 +517,9 @@ export class OpenClawAgentBridge implements PrivateClawAgentBridge {
|
|
|
490
517
|
const candidate = path.join(agentsDir, entry.name, "sessions", `${sessionId}.jsonl`);
|
|
491
518
|
try {
|
|
492
519
|
await fs.access(candidate);
|
|
520
|
+
this.verboseLog(
|
|
521
|
+
`session_log_resolved session=${sessionId} logPath=${JSON.stringify(candidate)}`,
|
|
522
|
+
);
|
|
493
523
|
return candidate;
|
|
494
524
|
} catch (error) {
|
|
495
525
|
if (isNodeError(error) && error.code === "ENOENT") {
|
|
@@ -505,6 +535,7 @@ export class OpenClawAgentBridge implements PrivateClawAgentBridge {
|
|
|
505
535
|
throw error;
|
|
506
536
|
}
|
|
507
537
|
|
|
538
|
+
this.verboseLog(`session_log_not_found session=${sessionId}`);
|
|
508
539
|
return undefined;
|
|
509
540
|
}
|
|
510
541
|
|
|
@@ -549,6 +580,9 @@ export class OpenClawAgentBridge implements PrivateClawAgentBridge {
|
|
|
549
580
|
this.log(
|
|
550
581
|
`prompt_ready session=${sessionId} stagedAttachments=${stagedAttachments.length} textChars=${trimmed.length} contractVersion=${PRIVATECLAW_RESPONSE_CONTRACT_VERSION}`,
|
|
551
582
|
);
|
|
583
|
+
this.verboseLog(
|
|
584
|
+
`prompt_body_ready session=${sessionId} promptChars=${promptMessage.length} trimmedTextChars=${trimmed.length} stagedAttachments=${stagedAttachments.length}`,
|
|
585
|
+
);
|
|
552
586
|
return promptMessage;
|
|
553
587
|
}
|
|
554
588
|
|
|
@@ -975,15 +1009,15 @@ function parseStructuredResponseBlock(raw: string): PrivateClawStructuredRespons
|
|
|
975
1009
|
return undefined;
|
|
976
1010
|
}
|
|
977
1011
|
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
} catch {
|
|
1012
|
+
const parsed = parseStructuredResponseJson(payload);
|
|
1013
|
+
if (
|
|
1014
|
+
!parsed ||
|
|
1015
|
+
parsed.version !== PRIVATECLAW_RESPONSE_CONTRACT_VERSION ||
|
|
1016
|
+
!Array.isArray(parsed.messages)
|
|
1017
|
+
) {
|
|
985
1018
|
return undefined;
|
|
986
1019
|
}
|
|
1020
|
+
return parsed;
|
|
987
1021
|
}
|
|
988
1022
|
|
|
989
1023
|
function stripStructuredResponseBlock(raw: string): string {
|
|
@@ -997,6 +1031,74 @@ function buildStructuredResponseBlockPattern(flags: string): RegExp {
|
|
|
997
1031
|
);
|
|
998
1032
|
}
|
|
999
1033
|
|
|
1034
|
+
function parseStructuredResponseJson(
|
|
1035
|
+
payload: string,
|
|
1036
|
+
): PrivateClawStructuredResponse | undefined {
|
|
1037
|
+
try {
|
|
1038
|
+
return JSON.parse(payload) as PrivateClawStructuredResponse;
|
|
1039
|
+
} catch {
|
|
1040
|
+
const normalizedPayload = stripJsonTrailingCommas(payload);
|
|
1041
|
+
if (normalizedPayload === payload) {
|
|
1042
|
+
return undefined;
|
|
1043
|
+
}
|
|
1044
|
+
try {
|
|
1045
|
+
return JSON.parse(normalizedPayload) as PrivateClawStructuredResponse;
|
|
1046
|
+
} catch {
|
|
1047
|
+
return undefined;
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
|
|
1052
|
+
function stripJsonTrailingCommas(payload: string): string {
|
|
1053
|
+
let normalized = "";
|
|
1054
|
+
let inString = false;
|
|
1055
|
+
let escaped = false;
|
|
1056
|
+
|
|
1057
|
+
for (let index = 0; index < payload.length; index += 1) {
|
|
1058
|
+
const character = payload[index]!;
|
|
1059
|
+
|
|
1060
|
+
if (escaped) {
|
|
1061
|
+
normalized += character;
|
|
1062
|
+
escaped = false;
|
|
1063
|
+
continue;
|
|
1064
|
+
}
|
|
1065
|
+
|
|
1066
|
+
if (inString) {
|
|
1067
|
+
normalized += character;
|
|
1068
|
+
if (character === "\\") {
|
|
1069
|
+
escaped = true;
|
|
1070
|
+
} else if (character === '"') {
|
|
1071
|
+
inString = false;
|
|
1072
|
+
}
|
|
1073
|
+
continue;
|
|
1074
|
+
}
|
|
1075
|
+
|
|
1076
|
+
if (character === '"') {
|
|
1077
|
+
normalized += character;
|
|
1078
|
+
inString = true;
|
|
1079
|
+
continue;
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
if (character === ",") {
|
|
1083
|
+
let lookahead = index + 1;
|
|
1084
|
+
while (
|
|
1085
|
+
lookahead < payload.length &&
|
|
1086
|
+
/\s/u.test(payload[lookahead]!)
|
|
1087
|
+
) {
|
|
1088
|
+
lookahead += 1;
|
|
1089
|
+
}
|
|
1090
|
+
const nextCharacter = payload[lookahead];
|
|
1091
|
+
if (nextCharacter === "]" || nextCharacter === "}") {
|
|
1092
|
+
continue;
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
|
|
1096
|
+
normalized += character;
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1099
|
+
return normalized;
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1000
1102
|
function escapeRegExpLiteral(value: string): string {
|
|
1001
1103
|
return value.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
|
|
1002
1104
|
}
|
package/src/cli.ts
CHANGED
|
@@ -5,6 +5,9 @@ import { parseArgs } from "node:util";
|
|
|
5
5
|
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
6
6
|
import path from "node:path";
|
|
7
7
|
import { EchoBridge } from "./bridges/echo-bridge.js";
|
|
8
|
+
import {
|
|
9
|
+
buildPreferredAudioTranscriber,
|
|
10
|
+
} from "./audio-transcriber.js";
|
|
8
11
|
import { OpenClawAgentBridge } from "./bridges/openclaw-agent-bridge.js";
|
|
9
12
|
import { OpenAICompatibleBridge } from "./bridges/openai-compatible-bridge.js";
|
|
10
13
|
import { WebhookBridge } from "./bridges/webhook-bridge.js";
|
|
@@ -26,6 +29,7 @@ import { DEFAULT_RELAY_BASE_URL } from "./relay-defaults.js";
|
|
|
26
29
|
import { resolveRelayEndpoints } from "./relay-endpoints.js";
|
|
27
30
|
import {
|
|
28
31
|
buildManagedSessionQrLegacyLines,
|
|
32
|
+
followManagedSessionLogFromStateDir,
|
|
29
33
|
buildManagedSessionsReportLines,
|
|
30
34
|
closeManagedSessionsFromStateDir,
|
|
31
35
|
closeManagedSessionFromStateDir,
|
|
@@ -41,11 +45,16 @@ import {
|
|
|
41
45
|
formatBilingualInline,
|
|
42
46
|
PRIVATECLAW_CLI_NOTIFY_OPTION_DESCRIPTION,
|
|
43
47
|
PRIVATECLAW_CLI_RELAY_OPTION_DESCRIPTION,
|
|
48
|
+
PRIVATECLAW_CLI_SESSIONS_FOLLOW_DESCRIPTION,
|
|
44
49
|
PRIVATECLAW_CLI_SESSIONS_KILL_DESCRIPTION,
|
|
45
50
|
PRIVATECLAW_CLI_SESSIONS_KILLALL_DESCRIPTION,
|
|
46
51
|
PRIVATECLAW_CLI_SESSIONS_QR_DESCRIPTION,
|
|
52
|
+
PRIVATECLAW_CLI_VERBOSE_OPTION_DESCRIPTION,
|
|
47
53
|
} from "./text.js";
|
|
48
|
-
import type {
|
|
54
|
+
import type {
|
|
55
|
+
PrivateClawProviderHandoffState,
|
|
56
|
+
PrivateClawVerboseController,
|
|
57
|
+
} from "./types.js";
|
|
49
58
|
|
|
50
59
|
type BridgeMode =
|
|
51
60
|
| "echo"
|
|
@@ -112,6 +121,7 @@ function detectBridgeMode(): BridgeMode {
|
|
|
112
121
|
function createProvider(params?: {
|
|
113
122
|
providerId?: string;
|
|
114
123
|
relayBaseUrl?: string;
|
|
124
|
+
verboseController?: PrivateClawVerboseController;
|
|
115
125
|
}): {
|
|
116
126
|
provider: PrivateClawProvider;
|
|
117
127
|
stateDir: string;
|
|
@@ -161,6 +171,8 @@ function createProvider(params?: {
|
|
|
161
171
|
600,
|
|
162
172
|
)
|
|
163
173
|
: undefined;
|
|
174
|
+
const verboseController = params?.verboseController;
|
|
175
|
+
const audioTranscriber = buildCliAudioTranscriber();
|
|
164
176
|
|
|
165
177
|
const bridge =
|
|
166
178
|
bridgeMode === "openclaw-agent"
|
|
@@ -175,6 +187,7 @@ function createProvider(params?: {
|
|
|
175
187
|
? { timeoutSeconds: openClawAgentTimeoutSeconds }
|
|
176
188
|
: {}),
|
|
177
189
|
...(openClawAgentLocal ? { local: true } : {}),
|
|
190
|
+
...(verboseController ? { verboseController } : {}),
|
|
178
191
|
onLog: (message) => {
|
|
179
192
|
console.log(`[privateclaw-provider] ${message}`);
|
|
180
193
|
},
|
|
@@ -212,9 +225,11 @@ function createProvider(params?: {
|
|
|
212
225
|
providerWsUrl: relayEndpoints.providerWsUrl,
|
|
213
226
|
appWsUrl: relayEndpoints.appWsUrl,
|
|
214
227
|
bridge,
|
|
228
|
+
...(audioTranscriber ? { audioTranscriber } : {}),
|
|
215
229
|
...(params?.providerId ? { providerId: params.providerId } : {}),
|
|
216
230
|
defaultTtlMs: ttlMs,
|
|
217
231
|
providerLabel,
|
|
232
|
+
...(verboseController ? { verboseController } : {}),
|
|
218
233
|
commandsProvider: async () => {
|
|
219
234
|
try {
|
|
220
235
|
return await loadAvailableOpenClawCommands();
|
|
@@ -231,6 +246,15 @@ function createProvider(params?: {
|
|
|
231
246
|
};
|
|
232
247
|
}
|
|
233
248
|
|
|
249
|
+
function buildCliAudioTranscriber() {
|
|
250
|
+
return buildPreferredAudioTranscriber({
|
|
251
|
+
env: process.env,
|
|
252
|
+
onLog: (message) => {
|
|
253
|
+
console.log(`[privateclaw-provider] ${message}`);
|
|
254
|
+
},
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
|
|
234
258
|
async function waitForSessionsToDrain(
|
|
235
259
|
provider: PrivateClawProvider,
|
|
236
260
|
): Promise<void> {
|
|
@@ -256,15 +280,18 @@ async function readHandoffState(
|
|
|
256
280
|
function printHelp(): void {
|
|
257
281
|
console.log(`privateclaw-provider <pair|sessions|kick|killall>
|
|
258
282
|
|
|
259
|
-
pair [--ttl-ms <ms>] [--label <label>] [--relay <url>] [--group] [--print-only] [--open] [--foreground]
|
|
283
|
+
pair [--ttl-ms <ms>] [--label <label>] [--relay <url>] [--group] [--print-only] [--open] [--foreground] [--verbose]
|
|
260
284
|
sessions
|
|
285
|
+
sessions follow <sessionId>
|
|
261
286
|
sessions qr <sessionId> [--open] [--notify]
|
|
262
287
|
sessions kill <sessionId>
|
|
263
288
|
sessions killall
|
|
264
289
|
killall
|
|
265
290
|
kick <sessionId> <appId>`);
|
|
266
291
|
console.log(`\n--relay <url>: ${PRIVATECLAW_CLI_RELAY_OPTION_DESCRIPTION}`);
|
|
292
|
+
console.log(`--verbose: ${PRIVATECLAW_CLI_VERBOSE_OPTION_DESCRIPTION}`);
|
|
267
293
|
console.log(`--notify: ${PRIVATECLAW_CLI_NOTIFY_OPTION_DESCRIPTION}`);
|
|
294
|
+
console.log(`sessions follow: ${PRIVATECLAW_CLI_SESSIONS_FOLLOW_DESCRIPTION}`);
|
|
268
295
|
console.log(`sessions qr: ${PRIVATECLAW_CLI_SESSIONS_QR_DESCRIPTION}`);
|
|
269
296
|
console.log(`sessions kill: ${PRIVATECLAW_CLI_SESSIONS_KILL_DESCRIPTION}`);
|
|
270
297
|
console.log(`sessions killall: ${PRIVATECLAW_CLI_SESSIONS_KILLALL_DESCRIPTION}`);
|
|
@@ -283,6 +310,7 @@ async function runPairCommand(args: string[]): Promise<void> {
|
|
|
283
310
|
"print-only": { type: "boolean", default: false },
|
|
284
311
|
open: { type: "boolean", default: parseBooleanFlag(process.env.PRIVATECLAW_OPEN_QR) },
|
|
285
312
|
foreground: { type: "boolean", default: false },
|
|
313
|
+
verbose: { type: "boolean", default: parseBooleanFlag(process.env.PRIVATECLAW_VERBOSE) },
|
|
286
314
|
"daemon-child": { type: "boolean", default: false },
|
|
287
315
|
"result-file": { type: "string" },
|
|
288
316
|
"resume-snapshot-file": { type: "string" },
|
|
@@ -302,9 +330,11 @@ async function runPairCommand(args: string[]): Promise<void> {
|
|
|
302
330
|
const printOnly = parsed.values["print-only"] === true;
|
|
303
331
|
const openInBrowser = parsed.values.open === true;
|
|
304
332
|
const foreground = parsed.values.foreground === true;
|
|
333
|
+
const verbose = parsed.values.verbose === true;
|
|
305
334
|
const daemonChild = parsed.values["daemon-child"] === true;
|
|
306
335
|
const resultFile = parsed.values["result-file"];
|
|
307
336
|
const resumeSnapshotFile = parsed.values["resume-snapshot-file"];
|
|
337
|
+
const verboseController = { enabled: verbose } satisfies PrivateClawVerboseController;
|
|
308
338
|
|
|
309
339
|
if (daemonChild) {
|
|
310
340
|
if (!resultFile) {
|
|
@@ -321,10 +351,11 @@ async function runPairCommand(args: string[]): Promise<void> {
|
|
|
321
351
|
? {
|
|
322
352
|
providerId: handoffState.providerId,
|
|
323
353
|
...(relayBaseUrl ? { relayBaseUrl } : {}),
|
|
354
|
+
verboseController,
|
|
324
355
|
}
|
|
325
356
|
: relayBaseUrl
|
|
326
|
-
? { relayBaseUrl }
|
|
327
|
-
:
|
|
357
|
+
? { relayBaseUrl, verboseController }
|
|
358
|
+
: { verboseController },
|
|
328
359
|
);
|
|
329
360
|
provider = resolved.provider;
|
|
330
361
|
if (handoffState) {
|
|
@@ -373,7 +404,7 @@ async function runPairCommand(args: string[]): Promise<void> {
|
|
|
373
404
|
|
|
374
405
|
if (printOnly || foreground) {
|
|
375
406
|
const { provider, stateDir } = createProvider(
|
|
376
|
-
relayBaseUrl ? { relayBaseUrl } :
|
|
407
|
+
relayBaseUrl ? { relayBaseUrl, verboseController } : { verboseController },
|
|
377
408
|
);
|
|
378
409
|
const controlServer =
|
|
379
410
|
printOnly
|
|
@@ -405,6 +436,7 @@ async function runPairCommand(args: string[]): Promise<void> {
|
|
|
405
436
|
await handoffForegroundPairToBackground({
|
|
406
437
|
cliModuleUrl: import.meta.url,
|
|
407
438
|
stateDir,
|
|
439
|
+
...(verbose ? { verbose: true } : {}),
|
|
408
440
|
env: relayBaseUrl
|
|
409
441
|
? {
|
|
410
442
|
...process.env,
|
|
@@ -443,6 +475,7 @@ async function runPairCommand(args: string[]): Promise<void> {
|
|
|
443
475
|
...(label ? { label } : {}),
|
|
444
476
|
...(groupMode ? { groupMode: true } : {}),
|
|
445
477
|
...(openInBrowser ? { openInBrowser: true } : {}),
|
|
478
|
+
...(verbose ? { verbose: true } : {}),
|
|
446
479
|
});
|
|
447
480
|
printPairInviteBundle(bundle, (line) => {
|
|
448
481
|
console.log(line);
|
|
@@ -456,6 +489,10 @@ async function runPairCommand(args: string[]): Promise<void> {
|
|
|
456
489
|
}
|
|
457
490
|
|
|
458
491
|
async function runSessionsCommand(args: string[]): Promise<void> {
|
|
492
|
+
if (args[0] === "follow") {
|
|
493
|
+
await runSessionsFollowCommand(args.slice(1));
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
459
496
|
if (args[0] === "qr") {
|
|
460
497
|
await runSessionsQrCommand(args.slice(1));
|
|
461
498
|
return;
|
|
@@ -486,6 +523,37 @@ async function runSessionsCommand(args: string[]): Promise<void> {
|
|
|
486
523
|
}
|
|
487
524
|
}
|
|
488
525
|
|
|
526
|
+
async function runSessionsFollowCommand(args: string[]): Promise<void> {
|
|
527
|
+
const parsed = parseArgs({
|
|
528
|
+
args,
|
|
529
|
+
allowPositionals: true,
|
|
530
|
+
options: {
|
|
531
|
+
help: { type: "boolean", short: "h" },
|
|
532
|
+
},
|
|
533
|
+
});
|
|
534
|
+
if (parsed.values.help) {
|
|
535
|
+
printHelp();
|
|
536
|
+
return;
|
|
537
|
+
}
|
|
538
|
+
const sessionId = parsed.positionals[0];
|
|
539
|
+
if (!sessionId) {
|
|
540
|
+
throw new Error(
|
|
541
|
+
formatBilingualInline(
|
|
542
|
+
"`sessions follow` 需要提供 sessionId。",
|
|
543
|
+
"`sessions follow` requires a sessionId.",
|
|
544
|
+
),
|
|
545
|
+
);
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
await followManagedSessionLogFromStateDir({
|
|
549
|
+
stateDir: resolvePrivateClawStateDir(),
|
|
550
|
+
sessionId,
|
|
551
|
+
writeLine: (line: string) => {
|
|
552
|
+
console.log(line);
|
|
553
|
+
},
|
|
554
|
+
});
|
|
555
|
+
}
|
|
556
|
+
|
|
489
557
|
async function runSessionsKillCommand(args: string[]): Promise<void> {
|
|
490
558
|
const parsed = parseArgs({
|
|
491
559
|
args,
|
|
@@ -75,6 +75,7 @@ function createMockApi(): {
|
|
|
75
75
|
|
|
76
76
|
class FakeCliCommand {
|
|
77
77
|
readonly children = new Map<string, FakeCliCommand>();
|
|
78
|
+
readonly options: string[] = [];
|
|
78
79
|
actionHandler: ((...args: unknown[]) => void | Promise<void>) | undefined;
|
|
79
80
|
|
|
80
81
|
constructor(readonly name: string) {}
|
|
@@ -94,6 +95,7 @@ class FakeCliCommand {
|
|
|
94
95
|
}
|
|
95
96
|
|
|
96
97
|
option(_flags: string, _description?: string, _defaultValue?: string | boolean): FakeCliCommand {
|
|
98
|
+
this.options.push(_flags);
|
|
97
99
|
return this;
|
|
98
100
|
}
|
|
99
101
|
|
|
@@ -171,7 +173,7 @@ test("privateclaw command writes QR media into the OpenClaw state media director
|
|
|
171
173
|
const remainingMs = new Date(invite.expiresAt).getTime() - Date.now();
|
|
172
174
|
assert.ok(
|
|
173
175
|
remainingMs > DEFAULT_SESSION_TTL_MS - 60_000,
|
|
174
|
-
"new sessions should default to roughly
|
|
176
|
+
"new sessions should default to roughly 24 hours even when relay default TTL is shorter",
|
|
175
177
|
);
|
|
176
178
|
const expectedMediaDir = path.join(stateDir, "media", "privateclaw");
|
|
177
179
|
const mediaPath =
|
|
@@ -341,6 +343,10 @@ test("privateclaw command can override the relay per invocation", async (t) => {
|
|
|
341
343
|
sessions?.actionHandler,
|
|
342
344
|
"plugin should register the privateclaw sessions subcommand",
|
|
343
345
|
);
|
|
346
|
+
assert.ok(
|
|
347
|
+
sessions?.children.get("follow")?.actionHandler,
|
|
348
|
+
"plugin should register the privateclaw sessions follow subcommand",
|
|
349
|
+
);
|
|
344
350
|
assert.ok(
|
|
345
351
|
sessions?.children.get("qr")?.actionHandler,
|
|
346
352
|
"plugin should register the privateclaw sessions qr subcommand",
|
|
@@ -407,6 +413,10 @@ test("privateclaw plugin local pair CLI defaults to the long session TTL", async
|
|
|
407
413
|
|
|
408
414
|
const pair = privateclaw.children.get("pair");
|
|
409
415
|
assert.ok(pair?.actionHandler, "plugin should register the privateclaw pair subcommand");
|
|
416
|
+
assert.ok(
|
|
417
|
+
pair.options.includes("--verbose"),
|
|
418
|
+
"plugin should expose a --verbose flag on the privateclaw pair subcommand",
|
|
419
|
+
);
|
|
410
420
|
|
|
411
421
|
const stateDir = await mkdtemp(path.join(os.tmpdir(), "privateclaw-cli-state-"));
|
|
412
422
|
const previousStateDir = process.env.OPENCLAW_STATE_DIR;
|
|
@@ -461,7 +471,7 @@ test("privateclaw plugin local pair CLI defaults to the long session TTL", async
|
|
|
461
471
|
const remainingMs = new Date(invite.expiresAt).getTime() - Date.now();
|
|
462
472
|
assert.ok(
|
|
463
473
|
remainingMs > DEFAULT_SESSION_TTL_MS - 60_000,
|
|
464
|
-
"local pair sessions should default to roughly
|
|
474
|
+
"local pair sessions should default to roughly 24 hours even when relay default TTL is shorter",
|
|
465
475
|
);
|
|
466
476
|
const qrPath = qrPathLine.replace("二维码 PNG 路径 / QR PNG path: ", "");
|
|
467
477
|
const qrPng = await readFile(qrPath);
|