nextclaw 0.6.34 → 0.6.35
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/dist/cli/index.js +124 -73
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -20,7 +20,11 @@ import {
|
|
|
20
20
|
DEFAULT_WORKSPACE_DIR,
|
|
21
21
|
DEFAULT_WORKSPACE_PATH
|
|
22
22
|
} from "@nextclaw/core";
|
|
23
|
-
import {
|
|
23
|
+
import {
|
|
24
|
+
getPluginChannelBindings as getPluginChannelBindings3,
|
|
25
|
+
resolvePluginChannelMessageToolHints as resolvePluginChannelMessageToolHints2,
|
|
26
|
+
setPluginRuntimeBridge as setPluginRuntimeBridge2
|
|
27
|
+
} from "@nextclaw/openclaw-compat";
|
|
24
28
|
import { existsSync as existsSync8, mkdirSync as mkdirSync5, readFileSync as readFileSync6, writeFileSync as writeFileSync4 } from "fs";
|
|
25
29
|
import { join as join6, resolve as resolve9 } from "path";
|
|
26
30
|
import { createInterface as createInterface2 } from "readline";
|
|
@@ -3295,7 +3299,9 @@ var CliRuntime = class {
|
|
|
3295
3299
|
}
|
|
3296
3300
|
const uiHost = FORCED_PUBLIC_UI_HOST;
|
|
3297
3301
|
const uiPort = typeof state.uiPort === "number" && Number.isFinite(state.uiPort) ? state.uiPort : 18791;
|
|
3298
|
-
console.log(
|
|
3302
|
+
console.log(
|
|
3303
|
+
`Applying changes (${reason}): restarting ${APP_NAME4} background service...`
|
|
3304
|
+
);
|
|
3299
3305
|
await this.serviceCommands.stopService();
|
|
3300
3306
|
await this.serviceCommands.startService({
|
|
3301
3307
|
uiOverrides: {
|
|
@@ -3442,11 +3448,15 @@ var CliRuntime = class {
|
|
|
3442
3448
|
}
|
|
3443
3449
|
});
|
|
3444
3450
|
} catch (error) {
|
|
3445
|
-
console.warn(
|
|
3451
|
+
console.warn(
|
|
3452
|
+
`Warning: failed to write restart sentinel from exec context: ${String(error)}`
|
|
3453
|
+
);
|
|
3446
3454
|
}
|
|
3447
3455
|
}
|
|
3448
3456
|
async onboard() {
|
|
3449
|
-
console.warn(
|
|
3457
|
+
console.warn(
|
|
3458
|
+
`Warning: ${APP_NAME4} onboard is deprecated. Use "${APP_NAME4} init" instead.`
|
|
3459
|
+
);
|
|
3450
3460
|
await this.init({ source: "onboard" });
|
|
3451
3461
|
}
|
|
3452
3462
|
async init(options = {}) {
|
|
@@ -3465,7 +3475,10 @@ var CliRuntime = class {
|
|
|
3465
3475
|
const workspacePath = !workspaceSetting || workspaceSetting === DEFAULT_WORKSPACE_PATH ? join6(getDataDir7(), DEFAULT_WORKSPACE_DIR) : expandHome2(workspaceSetting);
|
|
3466
3476
|
const workspaceExisted = existsSync8(workspacePath);
|
|
3467
3477
|
mkdirSync5(workspacePath, { recursive: true });
|
|
3468
|
-
const templateResult = this.workspaceManager.createWorkspaceTemplates(
|
|
3478
|
+
const templateResult = this.workspaceManager.createWorkspaceTemplates(
|
|
3479
|
+
workspacePath,
|
|
3480
|
+
{ force }
|
|
3481
|
+
);
|
|
3469
3482
|
if (createdConfig) {
|
|
3470
3483
|
console.log(`\u2713 ${prefix}: created config at ${configPath}`);
|
|
3471
3484
|
}
|
|
@@ -3485,7 +3498,9 @@ ${this.logo} ${APP_NAME4} is ready! (${source})`);
|
|
|
3485
3498
|
console.log(` 1. Add your API key to ${configPath}`);
|
|
3486
3499
|
console.log(` 2. Chat: ${APP_NAME4} agent -m "Hello!"`);
|
|
3487
3500
|
} else {
|
|
3488
|
-
console.log(
|
|
3501
|
+
console.log(
|
|
3502
|
+
`Tip: Run "${APP_NAME4} init${force ? " --force" : ""}" to re-run initialization if needed.`
|
|
3503
|
+
);
|
|
3489
3504
|
}
|
|
3490
3505
|
}
|
|
3491
3506
|
async gateway(opts) {
|
|
@@ -3512,7 +3527,10 @@ ${this.logo} ${APP_NAME4} is ready! (${source})`);
|
|
|
3512
3527
|
if (opts.port) {
|
|
3513
3528
|
uiOverrides.port = Number(opts.port);
|
|
3514
3529
|
}
|
|
3515
|
-
await this.serviceCommands.startGateway({
|
|
3530
|
+
await this.serviceCommands.startGateway({
|
|
3531
|
+
uiOverrides,
|
|
3532
|
+
allowMissingProvider: true
|
|
3533
|
+
});
|
|
3516
3534
|
}
|
|
3517
3535
|
async start(opts) {
|
|
3518
3536
|
await this.init({ source: "start", auto: true });
|
|
@@ -3566,74 +3584,103 @@ ${this.logo} ${APP_NAME4} is ready! (${source})`);
|
|
|
3566
3584
|
const pluginRegistry = loadPluginRegistry(config2, workspace);
|
|
3567
3585
|
const extensionRegistry = toExtensionRegistry(pluginRegistry);
|
|
3568
3586
|
logPluginDiagnostics(pluginRegistry);
|
|
3569
|
-
const
|
|
3570
|
-
|
|
3571
|
-
|
|
3572
|
-
|
|
3573
|
-
|
|
3574
|
-
|
|
3575
|
-
|
|
3576
|
-
|
|
3577
|
-
|
|
3578
|
-
|
|
3579
|
-
|
|
3580
|
-
|
|
3581
|
-
|
|
3582
|
-
|
|
3583
|
-
|
|
3584
|
-
|
|
3585
|
-
|
|
3586
|
-
contextConfig: config2.agents.context,
|
|
3587
|
-
config: config2,
|
|
3588
|
-
extensionRegistry,
|
|
3589
|
-
resolveMessageToolHints: ({ channel, accountId }) => resolvePluginChannelMessageToolHints2({
|
|
3590
|
-
registry: pluginRegistry,
|
|
3591
|
-
channel,
|
|
3592
|
-
cfg: loadConfig6(),
|
|
3593
|
-
accountId
|
|
3594
|
-
})
|
|
3587
|
+
const pluginChannelBindings = getPluginChannelBindings3(pluginRegistry);
|
|
3588
|
+
setPluginRuntimeBridge2({
|
|
3589
|
+
loadConfig: () => toPluginConfigView(loadConfig6(), pluginChannelBindings),
|
|
3590
|
+
writeConfigFile: async (nextConfigView) => {
|
|
3591
|
+
if (!nextConfigView || typeof nextConfigView !== "object" || Array.isArray(nextConfigView)) {
|
|
3592
|
+
throw new Error(
|
|
3593
|
+
"plugin runtime writeConfigFile expects an object config"
|
|
3594
|
+
);
|
|
3595
|
+
}
|
|
3596
|
+
const current = loadConfig6();
|
|
3597
|
+
const next = mergePluginConfigView(
|
|
3598
|
+
current,
|
|
3599
|
+
nextConfigView,
|
|
3600
|
+
pluginChannelBindings
|
|
3601
|
+
);
|
|
3602
|
+
saveConfig5(next);
|
|
3603
|
+
}
|
|
3595
3604
|
});
|
|
3596
|
-
|
|
3597
|
-
const
|
|
3598
|
-
|
|
3599
|
-
|
|
3600
|
-
|
|
3601
|
-
|
|
3602
|
-
metadata: typeof opts.model === "string" && opts.model.trim() ? { model: opts.model.trim() } : {}
|
|
3605
|
+
try {
|
|
3606
|
+
const bus = new MessageBus2();
|
|
3607
|
+
const provider = this.serviceCommands.createProvider(config2) ?? this.serviceCommands.createMissingProvider(config2);
|
|
3608
|
+
const providerManager = new ProviderManager2({
|
|
3609
|
+
defaultProvider: provider,
|
|
3610
|
+
config: config2
|
|
3603
3611
|
});
|
|
3604
|
-
|
|
3605
|
-
|
|
3606
|
-
|
|
3607
|
-
|
|
3608
|
-
|
|
3609
|
-
|
|
3610
|
-
|
|
3611
|
-
|
|
3612
|
-
|
|
3613
|
-
|
|
3614
|
-
|
|
3615
|
-
|
|
3616
|
-
|
|
3617
|
-
|
|
3618
|
-
|
|
3619
|
-
|
|
3620
|
-
|
|
3621
|
-
|
|
3622
|
-
|
|
3623
|
-
|
|
3624
|
-
|
|
3625
|
-
|
|
3626
|
-
|
|
3627
|
-
|
|
3628
|
-
|
|
3629
|
-
|
|
3612
|
+
const agentLoop = new AgentLoop2({
|
|
3613
|
+
bus,
|
|
3614
|
+
providerManager,
|
|
3615
|
+
workspace,
|
|
3616
|
+
model: config2.agents.defaults.model,
|
|
3617
|
+
maxIterations: config2.agents.defaults.maxToolIterations,
|
|
3618
|
+
maxTokens: config2.agents.defaults.maxTokens,
|
|
3619
|
+
contextTokens: config2.agents.defaults.contextTokens,
|
|
3620
|
+
braveApiKey: config2.tools.web.search.apiKey || void 0,
|
|
3621
|
+
execConfig: config2.tools.exec,
|
|
3622
|
+
restrictToWorkspace: config2.tools.restrictToWorkspace,
|
|
3623
|
+
contextConfig: config2.agents.context,
|
|
3624
|
+
config: config2,
|
|
3625
|
+
extensionRegistry,
|
|
3626
|
+
resolveMessageToolHints: ({ channel, accountId }) => resolvePluginChannelMessageToolHints2({
|
|
3627
|
+
registry: pluginRegistry,
|
|
3628
|
+
channel,
|
|
3629
|
+
cfg: loadConfig6(),
|
|
3630
|
+
accountId
|
|
3631
|
+
})
|
|
3632
|
+
});
|
|
3633
|
+
if (opts.message) {
|
|
3634
|
+
const response = await agentLoop.processDirect({
|
|
3635
|
+
content: opts.message,
|
|
3636
|
+
sessionKey: opts.session ?? "cli:default",
|
|
3637
|
+
channel: "cli",
|
|
3638
|
+
chatId: "direct",
|
|
3639
|
+
metadata: typeof opts.model === "string" && opts.model.trim() ? { model: opts.model.trim() } : {}
|
|
3640
|
+
});
|
|
3641
|
+
printAgentResponse(response);
|
|
3642
|
+
return;
|
|
3630
3643
|
}
|
|
3631
|
-
|
|
3632
|
-
|
|
3633
|
-
|
|
3634
|
-
|
|
3644
|
+
console.log(
|
|
3645
|
+
`${this.logo} Interactive mode (type exit or Ctrl+C to quit)
|
|
3646
|
+
`
|
|
3647
|
+
);
|
|
3648
|
+
const historyFile = join6(getDataDir7(), "history", "cli_history");
|
|
3649
|
+
const historyDir = resolve9(historyFile, "..");
|
|
3650
|
+
mkdirSync5(historyDir, { recursive: true });
|
|
3651
|
+
const history = existsSync8(historyFile) ? readFileSync6(historyFile, "utf-8").split("\n").filter(Boolean) : [];
|
|
3652
|
+
const rl = createInterface2({
|
|
3653
|
+
input: process.stdin,
|
|
3654
|
+
output: process.stdout
|
|
3655
|
+
});
|
|
3656
|
+
rl.on("close", () => {
|
|
3657
|
+
const merged = history.concat(
|
|
3658
|
+
rl.history ?? []
|
|
3659
|
+
);
|
|
3660
|
+
writeFileSync4(historyFile, merged.join("\n"));
|
|
3661
|
+
process.exit(0);
|
|
3635
3662
|
});
|
|
3636
|
-
|
|
3663
|
+
let running = true;
|
|
3664
|
+
while (running) {
|
|
3665
|
+
const line = await prompt(rl, "You: ");
|
|
3666
|
+
const trimmed = line.trim();
|
|
3667
|
+
if (!trimmed) {
|
|
3668
|
+
continue;
|
|
3669
|
+
}
|
|
3670
|
+
if (EXIT_COMMANDS.has(trimmed.toLowerCase())) {
|
|
3671
|
+
rl.close();
|
|
3672
|
+
running = false;
|
|
3673
|
+
break;
|
|
3674
|
+
}
|
|
3675
|
+
const response = await agentLoop.processDirect({
|
|
3676
|
+
content: trimmed,
|
|
3677
|
+
sessionKey: opts.session ?? "cli:default",
|
|
3678
|
+
metadata: typeof opts.model === "string" && opts.model.trim() ? { model: opts.model.trim() } : {}
|
|
3679
|
+
});
|
|
3680
|
+
printAgentResponse(response);
|
|
3681
|
+
}
|
|
3682
|
+
} finally {
|
|
3683
|
+
setPluginRuntimeBridge2(null);
|
|
3637
3684
|
}
|
|
3638
3685
|
}
|
|
3639
3686
|
async update(opts) {
|
|
@@ -3641,7 +3688,9 @@ ${this.logo} ${APP_NAME4} is ready! (${source})`);
|
|
|
3641
3688
|
if (opts.timeout !== void 0) {
|
|
3642
3689
|
const parsed = Number(opts.timeout);
|
|
3643
3690
|
if (!Number.isFinite(parsed) || parsed <= 0) {
|
|
3644
|
-
console.error(
|
|
3691
|
+
console.error(
|
|
3692
|
+
"Invalid --timeout value. Provide milliseconds (e.g. 1200000)."
|
|
3693
|
+
);
|
|
3645
3694
|
process.exit(1);
|
|
3646
3695
|
}
|
|
3647
3696
|
timeoutMs = parsed;
|
|
@@ -3651,7 +3700,9 @@ ${this.logo} ${APP_NAME4} is ready! (${source})`);
|
|
|
3651
3700
|
const result = runSelfUpdate({ timeoutMs, cwd: process.cwd() });
|
|
3652
3701
|
const printSteps = () => {
|
|
3653
3702
|
for (const step of result.steps) {
|
|
3654
|
-
console.log(
|
|
3703
|
+
console.log(
|
|
3704
|
+
`- ${step.cmd} ${step.args.join(" ")} (code ${step.code ?? "?"})`
|
|
3705
|
+
);
|
|
3655
3706
|
if (step.stderr) {
|
|
3656
3707
|
console.log(` stderr: ${step.stderr}`);
|
|
3657
3708
|
}
|