@privateclaw/privateclaw 0.1.34 → 0.1.36
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 +4 -3
- package/dist/openclaw-command-discovery.js +91 -25
- package/dist/openclaw-command-discovery.js.map +1 -1
- package/dist/openclaw-plugin.js +29 -7
- package/dist/openclaw-plugin.js.map +1 -1
- package/dist/session-control.js +22 -2
- package/dist/session-control.js.map +1 -1
- package/dist/setup.d.ts +2 -0
- package/dist/setup.js +79 -6
- package/dist/setup.js.map +1 -1
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
- package/src/openclaw-command-discovery.test.ts +117 -3
- package/src/openclaw-command-discovery.ts +115 -33
- package/src/openclaw-plugin.test.ts +281 -0
- package/src/openclaw-plugin.ts +33 -7
- package/src/session-control.test.ts +82 -1
- package/src/session-control.ts +28 -2
- package/src/setup.test.ts +7 -3
- package/src/setup.ts +114 -8
package/src/session-control.ts
CHANGED
|
@@ -182,6 +182,32 @@ function readNonEmptyString(value: unknown): string | undefined {
|
|
|
182
182
|
return trimmed === "" ? undefined : trimmed;
|
|
183
183
|
}
|
|
184
184
|
|
|
185
|
+
function isDescriptorProcessAlive(
|
|
186
|
+
descriptor: Pick<PrivateClawSessionControlDescriptor, "pid">,
|
|
187
|
+
): boolean {
|
|
188
|
+
if (!Number.isInteger(descriptor.pid) || descriptor.pid <= 0) {
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
try {
|
|
192
|
+
process.kill(descriptor.pid, 0);
|
|
193
|
+
return true;
|
|
194
|
+
} catch (error) {
|
|
195
|
+
const code = (error as NodeJS.ErrnoException | undefined)?.code;
|
|
196
|
+
return code !== "ESRCH";
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
async function pruneDescriptorIfProcessExited(params: {
|
|
201
|
+
descriptor: PrivateClawSessionControlDescriptor;
|
|
202
|
+
descriptorPath: string;
|
|
203
|
+
}): Promise<boolean> {
|
|
204
|
+
if (isDescriptorProcessAlive(params.descriptor)) {
|
|
205
|
+
return false;
|
|
206
|
+
}
|
|
207
|
+
await rm(params.descriptorPath, { force: true });
|
|
208
|
+
return true;
|
|
209
|
+
}
|
|
210
|
+
|
|
185
211
|
function normalizeManagedSessionLookupId(sessionId: string): string {
|
|
186
212
|
const trimmed = sessionId.trim();
|
|
187
213
|
const separatorIndex = trimmed.indexOf(":");
|
|
@@ -713,7 +739,7 @@ export async function listManagedSessionsFromStateDir(
|
|
|
713
739
|
sessions: response.sessions ?? [],
|
|
714
740
|
});
|
|
715
741
|
} catch {
|
|
716
|
-
await
|
|
742
|
+
await pruneDescriptorIfProcessExited({ descriptor, descriptorPath });
|
|
717
743
|
}
|
|
718
744
|
}
|
|
719
745
|
|
|
@@ -780,7 +806,7 @@ async function resolvePluginServiceDescriptor(params: {
|
|
|
780
806
|
await requestDescriptorJson<{ ok: true }>(candidate.descriptor, "/healthz");
|
|
781
807
|
return candidate;
|
|
782
808
|
} catch {
|
|
783
|
-
await
|
|
809
|
+
await pruneDescriptorIfProcessExited(candidate);
|
|
784
810
|
}
|
|
785
811
|
}
|
|
786
812
|
throw new Error(
|
package/src/setup.test.ts
CHANGED
|
@@ -151,10 +151,14 @@ test("buildPrivateClawSetupPlan prints manual OpenClaw commands when openclaw is
|
|
|
151
151
|
});
|
|
152
152
|
|
|
153
153
|
assert.equal(plan.localOpenClaw, false);
|
|
154
|
-
assert.equal(plan.manualSteps.length,
|
|
154
|
+
assert.equal(plan.manualSteps.length, 5);
|
|
155
155
|
assert.match(
|
|
156
156
|
renderPrivateClawSetupGuidance(plan),
|
|
157
|
-
/
|
|
157
|
+
/npm pack @privateclaw\/privateclaw@0\.1\.26/,
|
|
158
|
+
);
|
|
159
|
+
assert.match(
|
|
160
|
+
renderPrivateClawSetupGuidance(plan),
|
|
161
|
+
/openclaw plugins install \.\/privateclaw-privateclaw-0\.1\.26\.tgz/,
|
|
158
162
|
);
|
|
159
163
|
assert.equal(
|
|
160
164
|
plan.pairingCommand.display,
|
|
@@ -212,7 +216,7 @@ test("runPrivateClawSetup installs, enables, restarts, then starts pairing", asy
|
|
|
212
216
|
});
|
|
213
217
|
|
|
214
218
|
assert.deepEqual(executed, [
|
|
215
|
-
"openclaw plugins install
|
|
219
|
+
"npm pack @privateclaw/privateclaw@0.1.26 && openclaw plugins install ./privateclaw-privateclaw-0.1.26.tgz",
|
|
216
220
|
"openclaw plugins enable privateclaw",
|
|
217
221
|
"openclaw gateway restart",
|
|
218
222
|
]);
|
package/src/setup.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { spawn } from "node:child_process";
|
|
2
2
|
import { once } from "node:events";
|
|
3
|
-
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { mkdtemp, readFile, rm } from "node:fs/promises";
|
|
4
|
+
import os from "node:os";
|
|
5
|
+
import path from "node:path";
|
|
4
6
|
import { createInterface } from "node:readline/promises";
|
|
5
7
|
import { stdin, stdout } from "node:process";
|
|
6
8
|
import { formatBilingualInline } from "./text.js";
|
|
@@ -16,6 +18,8 @@ export interface PrivateClawSetupStep {
|
|
|
16
18
|
command: string;
|
|
17
19
|
args: string[];
|
|
18
20
|
display: string;
|
|
21
|
+
kind?: "command" | "npm-pack-install";
|
|
22
|
+
packageSpec?: string;
|
|
19
23
|
}
|
|
20
24
|
|
|
21
25
|
export interface PrivateClawSetupChoice {
|
|
@@ -172,12 +176,14 @@ function createStep(
|
|
|
172
176
|
command: string,
|
|
173
177
|
args: string[],
|
|
174
178
|
display: string,
|
|
179
|
+
extra?: Pick<PrivateClawSetupStep, "kind" | "packageSpec">,
|
|
175
180
|
): PrivateClawSetupStep {
|
|
176
181
|
return {
|
|
177
182
|
title,
|
|
178
183
|
command,
|
|
179
184
|
args,
|
|
180
185
|
display,
|
|
186
|
+
...(extra ?? {}),
|
|
181
187
|
};
|
|
182
188
|
}
|
|
183
189
|
|
|
@@ -204,8 +210,12 @@ function delay(ms: number): Promise<void> {
|
|
|
204
210
|
async function runOneShotCommand(
|
|
205
211
|
command: string,
|
|
206
212
|
args: string[],
|
|
213
|
+
options?: {
|
|
214
|
+
cwd?: string;
|
|
215
|
+
},
|
|
207
216
|
): Promise<RunOneShotCommandResult> {
|
|
208
217
|
const child = spawn(command, args, {
|
|
218
|
+
...(options?.cwd ? { cwd: options.cwd } : {}),
|
|
209
219
|
stdio: ["ignore", "pipe", "pipe"],
|
|
210
220
|
});
|
|
211
221
|
let stdoutText = "";
|
|
@@ -245,8 +255,12 @@ async function runOneShotCommand(
|
|
|
245
255
|
async function runStreamingCommand(
|
|
246
256
|
command: string,
|
|
247
257
|
args: string[],
|
|
258
|
+
options?: {
|
|
259
|
+
cwd?: string;
|
|
260
|
+
},
|
|
248
261
|
): Promise<RunOneShotCommandResult> {
|
|
249
262
|
const child = spawn(command, args, {
|
|
263
|
+
...(options?.cwd ? { cwd: options.cwd } : {}),
|
|
250
264
|
stdio: ["ignore", "pipe", "pipe"],
|
|
251
265
|
});
|
|
252
266
|
let stdoutText = "";
|
|
@@ -377,6 +391,98 @@ export async function resolveCurrentPrivateClawPackageSpec(): Promise<string> {
|
|
|
377
391
|
}
|
|
378
392
|
}
|
|
379
393
|
|
|
394
|
+
function resolveNpmCommand(): string {
|
|
395
|
+
return process.platform === "win32" ? "npm.cmd" : "npm";
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
function isExactSemverVersion(value: string): boolean {
|
|
399
|
+
return /^v?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/u.test(
|
|
400
|
+
value.trim(),
|
|
401
|
+
);
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
function buildPackedArchiveHint(packageSpec: string): string {
|
|
405
|
+
const normalizedSpec = packageSpec.trim();
|
|
406
|
+
const lastAt = normalizedSpec.lastIndexOf("@");
|
|
407
|
+
const hasSelector = lastAt > 0;
|
|
408
|
+
const packageName = hasSelector ? normalizedSpec.slice(0, lastAt) : normalizedSpec;
|
|
409
|
+
const selector = hasSelector ? normalizedSpec.slice(lastAt + 1) : "";
|
|
410
|
+
const sanitizedName = packageName.replace(/^@/u, "").replace(/\//gu, "-");
|
|
411
|
+
if (selector && isExactSemverVersion(selector)) {
|
|
412
|
+
return `${sanitizedName}-${selector.replace(/^v/iu, "")}.tgz`;
|
|
413
|
+
}
|
|
414
|
+
return `${sanitizedName}-*.tgz`;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
function createNpmPackInstallStep(packageSpec: string): PrivateClawSetupStep {
|
|
418
|
+
return createStep(
|
|
419
|
+
"Pack the PrivateClaw npm package locally, then install the generated archive into OpenClaw",
|
|
420
|
+
resolveNpmCommand(),
|
|
421
|
+
["pack", packageSpec],
|
|
422
|
+
`npm pack ${packageSpec} && openclaw plugins install ./${buildPackedArchiveHint(packageSpec)}`,
|
|
423
|
+
{
|
|
424
|
+
kind: "npm-pack-install",
|
|
425
|
+
packageSpec,
|
|
426
|
+
},
|
|
427
|
+
);
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
function createManualNpmArchiveInstallSteps(
|
|
431
|
+
packageSpec: string,
|
|
432
|
+
): [PrivateClawSetupStep, PrivateClawSetupStep] {
|
|
433
|
+
const archiveHint = buildPackedArchiveHint(packageSpec);
|
|
434
|
+
return [
|
|
435
|
+
createStep(
|
|
436
|
+
"Pack the PrivateClaw plugin from npm into a local archive",
|
|
437
|
+
resolveNpmCommand(),
|
|
438
|
+
["pack", packageSpec],
|
|
439
|
+
`npm pack ${packageSpec}`,
|
|
440
|
+
),
|
|
441
|
+
createStep(
|
|
442
|
+
"Install the generated PrivateClaw plugin archive into OpenClaw",
|
|
443
|
+
"openclaw",
|
|
444
|
+
["plugins", "install", `./${archiveHint}`],
|
|
445
|
+
`openclaw plugins install ./${archiveHint}`,
|
|
446
|
+
),
|
|
447
|
+
];
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
async function runNpmPackInstallStep(step: PrivateClawSetupStep): Promise<void> {
|
|
451
|
+
if (!step.packageSpec) {
|
|
452
|
+
throw new Error("Missing packageSpec for npm-pack-install step.");
|
|
453
|
+
}
|
|
454
|
+
const tempDir = await mkdtemp(path.join(os.tmpdir(), "privateclaw-plugin-install-"));
|
|
455
|
+
try {
|
|
456
|
+
const packResult = await runOneShotCommand(
|
|
457
|
+
resolveNpmCommand(),
|
|
458
|
+
[
|
|
459
|
+
"pack",
|
|
460
|
+
step.packageSpec,
|
|
461
|
+
"--json",
|
|
462
|
+
"--ignore-scripts",
|
|
463
|
+
"--pack-destination",
|
|
464
|
+
tempDir,
|
|
465
|
+
],
|
|
466
|
+
);
|
|
467
|
+
const packOutput = packResult.stdout.trim() || packResult.combined.trim();
|
|
468
|
+
const parsed = JSON.parse(packOutput) as Array<{ filename?: unknown }>;
|
|
469
|
+
const archiveFileName =
|
|
470
|
+
typeof parsed[0]?.filename === "string" && parsed[0].filename.trim() !== ""
|
|
471
|
+
? parsed[0].filename.trim()
|
|
472
|
+
: undefined;
|
|
473
|
+
if (!archiveFileName) {
|
|
474
|
+
throw new Error(`Could not determine the generated archive for ${step.packageSpec}.`);
|
|
475
|
+
}
|
|
476
|
+
await runStreamingCommand("openclaw", [
|
|
477
|
+
"plugins",
|
|
478
|
+
"install",
|
|
479
|
+
path.join(tempDir, archiveFileName),
|
|
480
|
+
]);
|
|
481
|
+
} finally {
|
|
482
|
+
await rm(tempDir, { recursive: true, force: true });
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
|
|
380
486
|
export function parsePrivateClawSessionDurationPreset(
|
|
381
487
|
value: string,
|
|
382
488
|
label = "--duration",
|
|
@@ -511,12 +617,8 @@ export function buildPrivateClawSetupPlan(params: {
|
|
|
511
617
|
openInBrowser?: boolean;
|
|
512
618
|
verbose?: boolean;
|
|
513
619
|
}): PrivateClawSetupPlan {
|
|
514
|
-
const installStep =
|
|
515
|
-
|
|
516
|
-
"openclaw",
|
|
517
|
-
["plugins", "install", params.packageSpec],
|
|
518
|
-
`openclaw plugins install ${params.packageSpec}`,
|
|
519
|
-
);
|
|
620
|
+
const installStep = createNpmPackInstallStep(params.packageSpec);
|
|
621
|
+
const manualInstallSteps = createManualNpmArchiveInstallSteps(params.packageSpec);
|
|
520
622
|
const updateStep = createStep(
|
|
521
623
|
"Update the existing PrivateClaw OpenClaw plugin",
|
|
522
624
|
"openclaw",
|
|
@@ -572,7 +674,7 @@ export function buildPrivateClawSetupPlan(params: {
|
|
|
572
674
|
"Could not detect `openclaw` on this machine. Run these commands on the machine where OpenClaw is installed:",
|
|
573
675
|
)}`,
|
|
574
676
|
automaticSteps: [],
|
|
575
|
-
manualSteps: [
|
|
677
|
+
manualSteps: [...manualInstallSteps, enableStep, restartStep, pairingCommand],
|
|
576
678
|
selectionNotes,
|
|
577
679
|
verificationNotes,
|
|
578
680
|
pairingCommand,
|
|
@@ -700,6 +802,10 @@ async function promptForPrivateClawChoice(
|
|
|
700
802
|
async function runPrivateClawSetupStep(
|
|
701
803
|
step: PrivateClawSetupStep,
|
|
702
804
|
): Promise<void> {
|
|
805
|
+
if (step.kind === "npm-pack-install") {
|
|
806
|
+
await runNpmPackInstallStep(step);
|
|
807
|
+
return;
|
|
808
|
+
}
|
|
703
809
|
await runStreamingCommand(step.command, step.args);
|
|
704
810
|
}
|
|
705
811
|
|