@better_openclaw/betterclaw 3.0.1 → 3.0.2
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/package.json +1 -1
- package/src/cli.ts +7 -0
- package/src/index.ts +32 -15
package/package.json
CHANGED
package/src/cli.ts
CHANGED
|
@@ -24,7 +24,14 @@ export const BETTERCLAW_COMMANDS = [
|
|
|
24
24
|
"system.notify",
|
|
25
25
|
].sort();
|
|
26
26
|
|
|
27
|
+
export const BETTERCLAW_TOOLS = ["check_tier", "get_context"];
|
|
28
|
+
|
|
27
29
|
export function mergeAllowCommands(existing: string[], toAdd: string[]): string[] {
|
|
28
30
|
const set = new Set([...existing, ...toAdd]);
|
|
29
31
|
return [...set].sort();
|
|
30
32
|
}
|
|
33
|
+
|
|
34
|
+
export function mergeAlsoAllow(existing: string[], toAdd: string[]): string[] {
|
|
35
|
+
const set = new Set([...existing, ...toAdd]);
|
|
36
|
+
return [...set];
|
|
37
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { RulesEngine } from "./filter.js";
|
|
|
7
7
|
import { PatternEngine } from "./patterns.js";
|
|
8
8
|
import { processEvent } from "./pipeline.js";
|
|
9
9
|
import type { PipelineDeps } from "./pipeline.js";
|
|
10
|
-
import { BETTERCLAW_COMMANDS, mergeAllowCommands } from "./cli.js";
|
|
10
|
+
import { BETTERCLAW_COMMANDS, BETTERCLAW_TOOLS, mergeAllowCommands, mergeAlsoAllow } from "./cli.js";
|
|
11
11
|
import { storeJwt } from "./jwt.js";
|
|
12
12
|
import { loadTriageProfile, runLearner } from "./learner.js";
|
|
13
13
|
import { ReactionTracker } from "./reactions.js";
|
|
@@ -490,37 +490,54 @@ export default {
|
|
|
490
490
|
|
|
491
491
|
cmd
|
|
492
492
|
.command("setup")
|
|
493
|
-
.description("Configure gateway allowedCommands for BetterClaw")
|
|
493
|
+
.description("Configure gateway allowedCommands and agent tools for BetterClaw")
|
|
494
494
|
.option("--dry-run", "Preview changes without writing")
|
|
495
495
|
.action(async (opts: { dryRun?: boolean }) => {
|
|
496
496
|
try {
|
|
497
497
|
const currentConfig = await api.runtime.config.loadConfig();
|
|
498
|
-
const
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
const
|
|
498
|
+
const configObj = { ...currentConfig } as any;
|
|
499
|
+
|
|
500
|
+
// 1. Merge node allowedCommands
|
|
501
|
+
const existingCmds: string[] = configObj?.gateway?.nodes?.allowCommands ?? [];
|
|
502
|
+
const mergedCmds = mergeAllowCommands(existingCmds, BETTERCLAW_COMMANDS);
|
|
503
|
+
const addedCmds = mergedCmds.length - existingCmds.length;
|
|
504
|
+
|
|
505
|
+
// 2. Merge tools.alsoAllow for plugin tools
|
|
506
|
+
configObj.tools = configObj.tools ?? {};
|
|
507
|
+
const existingAllow: string[] = configObj.tools.alsoAllow ?? [];
|
|
508
|
+
const mergedAllow = mergeAlsoAllow(existingAllow, BETTERCLAW_TOOLS);
|
|
509
|
+
const addedTools = mergedAllow.length - existingAllow.length;
|
|
502
510
|
|
|
503
511
|
if (opts.dryRun) {
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
512
|
+
if (addedCmds > 0) {
|
|
513
|
+
const newCmds = mergedCmds.filter((c) => !existingCmds.includes(c));
|
|
514
|
+
console.log(`[dry-run] Would add ${addedCmds} node commands: ${newCmds.join(", ")}`);
|
|
515
|
+
}
|
|
516
|
+
if (addedTools > 0) {
|
|
517
|
+
const newTools = mergedAllow.filter((t) => !existingAllow.includes(t));
|
|
518
|
+
console.log(`[dry-run] Would add ${addedTools} agent tools to alsoAllow: ${newTools.join(", ")}`);
|
|
519
|
+
}
|
|
520
|
+
if (addedCmds === 0 && addedTools === 0) {
|
|
521
|
+
console.log("[dry-run] Everything already configured.");
|
|
508
522
|
}
|
|
509
523
|
return;
|
|
510
524
|
}
|
|
511
525
|
|
|
512
|
-
if (
|
|
513
|
-
console.log(
|
|
526
|
+
if (addedCmds === 0 && addedTools === 0) {
|
|
527
|
+
console.log("All BetterClaw commands and tools already configured.");
|
|
514
528
|
return;
|
|
515
529
|
}
|
|
516
530
|
|
|
517
|
-
const configObj = { ...currentConfig } as any;
|
|
518
531
|
configObj.gateway = configObj.gateway ?? {};
|
|
519
532
|
configObj.gateway.nodes = configObj.gateway.nodes ?? {};
|
|
520
|
-
configObj.gateway.nodes.allowCommands =
|
|
533
|
+
configObj.gateway.nodes.allowCommands = mergedCmds;
|
|
534
|
+
configObj.tools.alsoAllow = mergedAllow;
|
|
521
535
|
await api.runtime.config.writeConfigFile(configObj);
|
|
522
536
|
|
|
523
|
-
|
|
537
|
+
const parts: string[] = [];
|
|
538
|
+
if (addedCmds > 0) parts.push(`${addedCmds} node commands`);
|
|
539
|
+
if (addedTools > 0) parts.push(`${addedTools} agent tools (${BETTERCLAW_TOOLS.join(", ")})`);
|
|
540
|
+
console.log(`Added ${parts.join(" + ")}. Restart gateway to apply.`);
|
|
524
541
|
} catch (err) {
|
|
525
542
|
console.error(`Failed to update config: ${err}`);
|
|
526
543
|
process.exit(1);
|