@ai-setting/roy-agent-cli 1.5.38 → 1.5.40
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/bin/roy-agent.js +142 -253
- package/dist/index.js +142 -253
- package/dist/roy-agent-linux-x64/bin/roy-agent +0 -0
- package/package.json +3 -3
package/dist/bin/roy-agent.js
CHANGED
|
@@ -7220,7 +7220,7 @@ var require_dist = __commonJS((exports) => {
|
|
|
7220
7220
|
var require_package = __commonJS((exports, module) => {
|
|
7221
7221
|
module.exports = {
|
|
7222
7222
|
name: "@ai-setting/roy-agent-cli",
|
|
7223
|
-
version: "1.5.
|
|
7223
|
+
version: "1.5.40",
|
|
7224
7224
|
type: "module",
|
|
7225
7225
|
description: "CLI for roy-agent - Non-interactive command execution",
|
|
7226
7226
|
main: "./dist/index.js",
|
|
@@ -7246,8 +7246,8 @@ var require_package = __commonJS((exports, module) => {
|
|
|
7246
7246
|
typecheck: "npx tsc --noEmit --skipLibCheck"
|
|
7247
7247
|
},
|
|
7248
7248
|
dependencies: {
|
|
7249
|
-
"@ai-setting/roy-agent-coder-harness": "^1.5.
|
|
7250
|
-
"@ai-setting/roy-agent-core": "^1.5.
|
|
7249
|
+
"@ai-setting/roy-agent-coder-harness": "^1.5.40",
|
|
7250
|
+
"@ai-setting/roy-agent-core": "^1.5.40",
|
|
7251
7251
|
chalk: "^5.6.2",
|
|
7252
7252
|
commander: "^14.0.3",
|
|
7253
7253
|
effect: "^3.21.2",
|
|
@@ -7337,7 +7337,8 @@ import {
|
|
|
7337
7337
|
McpComponent,
|
|
7338
7338
|
CommandsComponent,
|
|
7339
7339
|
MemoryComponent,
|
|
7340
|
-
EventSourceComponent
|
|
7340
|
+
EventSourceComponent,
|
|
7341
|
+
PluginComponent
|
|
7341
7342
|
} from "@ai-setting/roy-agent-core";
|
|
7342
7343
|
import { WorkflowComponent } from "@ai-setting/roy-agent-core";
|
|
7343
7344
|
import { MemoryPlugin } from "@ai-setting/roy-agent-core";
|
|
@@ -7404,124 +7405,6 @@ class OutputService {
|
|
|
7404
7405
|
}
|
|
7405
7406
|
}
|
|
7406
7407
|
|
|
7407
|
-
// src/plugin/registry.ts
|
|
7408
|
-
var taskTagPlugin = {
|
|
7409
|
-
info: {
|
|
7410
|
-
name: "task-tag",
|
|
7411
|
-
version: "1.0.0",
|
|
7412
|
-
description: "Intelligent tag suggestion and similar task experience injection"
|
|
7413
|
-
},
|
|
7414
|
-
getComponentPlugins() {
|
|
7415
|
-
return [{
|
|
7416
|
-
name: "task-tag",
|
|
7417
|
-
targetComponent: "task",
|
|
7418
|
-
factory: async () => {
|
|
7419
|
-
const { TaskTagPlugin } = await import("@ai-setting/roy-agent-core");
|
|
7420
|
-
return new TaskTagPlugin;
|
|
7421
|
-
}
|
|
7422
|
-
}];
|
|
7423
|
-
}
|
|
7424
|
-
};
|
|
7425
|
-
var BUILTIN_PLUGINS = [
|
|
7426
|
-
taskTagPlugin
|
|
7427
|
-
];
|
|
7428
|
-
|
|
7429
|
-
class PluginRegistry {
|
|
7430
|
-
plugins = new Map;
|
|
7431
|
-
constructor() {
|
|
7432
|
-
for (const plugin of BUILTIN_PLUGINS) {
|
|
7433
|
-
this.registerBuiltin(plugin);
|
|
7434
|
-
}
|
|
7435
|
-
}
|
|
7436
|
-
register(plugin) {
|
|
7437
|
-
if (this.plugins.has(plugin.info.name)) {
|
|
7438
|
-
throw new Error(`Plugin "${plugin.info.name}" is already registered`);
|
|
7439
|
-
}
|
|
7440
|
-
this.plugins.set(plugin.info.name, plugin);
|
|
7441
|
-
}
|
|
7442
|
-
registerBuiltin(plugin) {
|
|
7443
|
-
if (!this.plugins.has(plugin.info.name)) {
|
|
7444
|
-
this.plugins.set(plugin.info.name, plugin);
|
|
7445
|
-
}
|
|
7446
|
-
}
|
|
7447
|
-
unregister(name) {
|
|
7448
|
-
this.plugins.delete(name);
|
|
7449
|
-
}
|
|
7450
|
-
get(name) {
|
|
7451
|
-
return this.plugins.get(name);
|
|
7452
|
-
}
|
|
7453
|
-
has(name) {
|
|
7454
|
-
return this.plugins.has(name);
|
|
7455
|
-
}
|
|
7456
|
-
getAll() {
|
|
7457
|
-
return Array.from(this.plugins.values()).sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));
|
|
7458
|
-
}
|
|
7459
|
-
get size() {
|
|
7460
|
-
return this.plugins.size;
|
|
7461
|
-
}
|
|
7462
|
-
getAllCommands() {
|
|
7463
|
-
const commands = [];
|
|
7464
|
-
for (const plugin of this.getAll()) {
|
|
7465
|
-
commands.push(...plugin.getCommands?.() ?? []);
|
|
7466
|
-
}
|
|
7467
|
-
return commands;
|
|
7468
|
-
}
|
|
7469
|
-
getAllComponents() {
|
|
7470
|
-
const components = [];
|
|
7471
|
-
for (const plugin of this.getAll()) {
|
|
7472
|
-
components.push(...plugin.getComponents?.() ?? []);
|
|
7473
|
-
}
|
|
7474
|
-
return components;
|
|
7475
|
-
}
|
|
7476
|
-
getAllComponentPlugins() {
|
|
7477
|
-
const componentPlugins = [];
|
|
7478
|
-
for (const plugin of this.getAll()) {
|
|
7479
|
-
componentPlugins.push(...plugin.getComponentPlugins?.() ?? []);
|
|
7480
|
-
}
|
|
7481
|
-
return componentPlugins;
|
|
7482
|
-
}
|
|
7483
|
-
getComponentPlugin(name) {
|
|
7484
|
-
for (const plugin of this.getAll()) {
|
|
7485
|
-
const componentPlugins = plugin.getComponentPlugins?.() ?? [];
|
|
7486
|
-
for (const cp of componentPlugins) {
|
|
7487
|
-
if (cp.name === name) {
|
|
7488
|
-
return cp;
|
|
7489
|
-
}
|
|
7490
|
-
}
|
|
7491
|
-
}
|
|
7492
|
-
return;
|
|
7493
|
-
}
|
|
7494
|
-
*getPluginComponents() {
|
|
7495
|
-
for (const plugin of this.getAll()) {
|
|
7496
|
-
for (const definition of plugin.getComponents?.() ?? []) {
|
|
7497
|
-
yield { plugin, definition };
|
|
7498
|
-
}
|
|
7499
|
-
}
|
|
7500
|
-
}
|
|
7501
|
-
clear() {
|
|
7502
|
-
for (const name of this.plugins.keys()) {
|
|
7503
|
-
const plugin = this.plugins.get(name);
|
|
7504
|
-
if (!BUILTIN_PLUGINS.some((p) => p.info.name === name)) {
|
|
7505
|
-
this.plugins.delete(name);
|
|
7506
|
-
}
|
|
7507
|
-
}
|
|
7508
|
-
}
|
|
7509
|
-
async executeLifecycleHooks(phase, env) {
|
|
7510
|
-
const hookName = phase === "beforeInit" ? "onBeforeInit" : "onAfterInit";
|
|
7511
|
-
for (const plugin of this.getAll()) {
|
|
7512
|
-
const hook = plugin[hookName];
|
|
7513
|
-
if (hook) {
|
|
7514
|
-
try {
|
|
7515
|
-
await hook({ env });
|
|
7516
|
-
} catch (err) {
|
|
7517
|
-
console.warn(`[roy] Plugin "${plugin.info.name}" ${hookName} failed:`, err);
|
|
7518
|
-
}
|
|
7519
|
-
}
|
|
7520
|
-
}
|
|
7521
|
-
}
|
|
7522
|
-
}
|
|
7523
|
-
var globalPluginRegistry = new PluginRegistry;
|
|
7524
|
-
|
|
7525
7408
|
// src/services/environment.service.ts
|
|
7526
7409
|
var logger = createLogger("environment-service");
|
|
7527
7410
|
var CLI_CONFIG_DIR_NAME = "roy-agent";
|
|
@@ -7553,6 +7436,7 @@ class EnvironmentService {
|
|
|
7553
7436
|
memoryPlugin;
|
|
7554
7437
|
eventSourceComponent;
|
|
7555
7438
|
workflowComponent;
|
|
7439
|
+
pluginComponent;
|
|
7556
7440
|
constructor(output) {
|
|
7557
7441
|
this.output = output ?? new OutputService;
|
|
7558
7442
|
}
|
|
@@ -7585,6 +7469,7 @@ class EnvironmentService {
|
|
|
7585
7469
|
}
|
|
7586
7470
|
async dispose() {
|
|
7587
7471
|
for (const component of [
|
|
7472
|
+
this.pluginComponent,
|
|
7588
7473
|
this.eventSourceComponent,
|
|
7589
7474
|
this.memoryComponent,
|
|
7590
7475
|
this.commandsComponent,
|
|
@@ -7814,20 +7699,22 @@ class EnvironmentService {
|
|
|
7814
7699
|
env.registerComponent(memoryComponent);
|
|
7815
7700
|
env.registerComponent(eventSourceComponent);
|
|
7816
7701
|
env.registerComponent(workflowComponent);
|
|
7702
|
+
this.pluginComponent = new PluginComponent;
|
|
7703
|
+
const pluginComponent = this.pluginComponent;
|
|
7704
|
+
await pluginComponent.init({
|
|
7705
|
+
env,
|
|
7706
|
+
options: {
|
|
7707
|
+
configComponent
|
|
7708
|
+
}
|
|
7709
|
+
});
|
|
7710
|
+
env.registerComponent(pluginComponent);
|
|
7817
7711
|
this.registerCommandsPromptHook(promptComponent, commandsComponent);
|
|
7818
7712
|
await env.init();
|
|
7819
7713
|
await env.start();
|
|
7820
7714
|
agentComponent.refreshDependencies();
|
|
7821
7715
|
logger.debug("[EnvironmentService] AgentComponent dependencies refreshed after env.start()");
|
|
7822
7716
|
if (options?.plugins && options.plugins.length > 0) {
|
|
7823
|
-
await this.
|
|
7824
|
-
task: taskComponent,
|
|
7825
|
-
memory: memoryComponent,
|
|
7826
|
-
llm: llmComponent
|
|
7827
|
-
});
|
|
7828
|
-
}
|
|
7829
|
-
if (options?.plugins && options.plugins.length > 0) {
|
|
7830
|
-
await this.loadCoderPlugins(options.plugins);
|
|
7717
|
+
await this.loadPlugins(options.plugins);
|
|
7831
7718
|
}
|
|
7832
7719
|
this.environment = env;
|
|
7833
7720
|
return env;
|
|
@@ -7854,27 +7741,54 @@ class EnvironmentService {
|
|
|
7854
7741
|
});
|
|
7855
7742
|
this.output.info("Registered commands-prompt Hook");
|
|
7856
7743
|
}
|
|
7857
|
-
async
|
|
7744
|
+
async loadPlugins(pluginNames) {
|
|
7858
7745
|
for (const name of pluginNames) {
|
|
7859
7746
|
try {
|
|
7860
|
-
|
|
7861
|
-
|
|
7862
|
-
|
|
7863
|
-
|
|
7864
|
-
|
|
7865
|
-
|
|
7866
|
-
|
|
7867
|
-
|
|
7868
|
-
|
|
7869
|
-
|
|
7870
|
-
|
|
7871
|
-
|
|
7872
|
-
|
|
7873
|
-
|
|
7874
|
-
|
|
7747
|
+
let plugin;
|
|
7748
|
+
switch (name) {
|
|
7749
|
+
case "task-tag": {
|
|
7750
|
+
const { TaskTagPlugin } = await import("@ai-setting/roy-agent-core");
|
|
7751
|
+
plugin = new TaskTagPlugin;
|
|
7752
|
+
break;
|
|
7753
|
+
}
|
|
7754
|
+
case "lsp": {
|
|
7755
|
+
const { LSPPlugin } = await import("@ai-setting/roy-agent-coder-harness");
|
|
7756
|
+
plugin = new LSPPlugin({ preloadMode: "startup" });
|
|
7757
|
+
break;
|
|
7758
|
+
}
|
|
7759
|
+
case "code-check": {
|
|
7760
|
+
const { CodeCheckPlugin } = await import("@ai-setting/roy-agent-coder-harness");
|
|
7761
|
+
plugin = new CodeCheckPlugin;
|
|
7762
|
+
break;
|
|
7763
|
+
}
|
|
7764
|
+
case "reminder": {
|
|
7765
|
+
const { ReminderPlugin } = await import("@ai-setting/roy-agent-coder-harness");
|
|
7766
|
+
plugin = new ReminderPlugin;
|
|
7767
|
+
break;
|
|
7768
|
+
}
|
|
7769
|
+
case "tslsp": {
|
|
7770
|
+
const { TSLSPPlugin } = await import("@ai-setting/roy-agent-coder-harness");
|
|
7771
|
+
plugin = new TSLSPPlugin({ preloadMode: "startup" });
|
|
7772
|
+
break;
|
|
7773
|
+
}
|
|
7774
|
+
case "pylsp": {
|
|
7775
|
+
const { PyLSPPlugin } = await import("@ai-setting/roy-agent-coder-harness");
|
|
7776
|
+
plugin = new PyLSPPlugin({ preloadMode: "startup" });
|
|
7777
|
+
break;
|
|
7778
|
+
}
|
|
7779
|
+
case "mdlsp": {
|
|
7780
|
+
const { MDLSPPlugin } = await import("@ai-setting/roy-agent-coder-harness");
|
|
7781
|
+
plugin = new MDLSPPlugin;
|
|
7782
|
+
break;
|
|
7783
|
+
}
|
|
7784
|
+
default:
|
|
7785
|
+
this.output.warn(`[EnvironmentService] Unknown plugin: ${name}`);
|
|
7786
|
+
continue;
|
|
7875
7787
|
}
|
|
7788
|
+
this.pluginComponent?.register(plugin);
|
|
7789
|
+
this.output.log(`[EnvironmentService] Registered plugin: ${name}`);
|
|
7876
7790
|
} catch (error) {
|
|
7877
|
-
this.output.error(`[EnvironmentService] Error loading
|
|
7791
|
+
this.output.error(`[EnvironmentService] Error loading plugin "${name}": ${error}`);
|
|
7878
7792
|
}
|
|
7879
7793
|
}
|
|
7880
7794
|
}
|
|
@@ -7892,22 +7806,6 @@ ${rows}
|
|
|
7892
7806
|
|
|
7893
7807
|
Progressive Discovery: Run \`<command> --help\` to explore full capabilities.`;
|
|
7894
7808
|
}
|
|
7895
|
-
async loadCoderPlugins(pluginNames) {
|
|
7896
|
-
const { createPluginHookAdapter } = await import("@ai-setting/roy-agent-coder-harness");
|
|
7897
|
-
const { globalHookManager: globalHookManager2 } = await import("@ai-setting/roy-agent-core");
|
|
7898
|
-
const pluginConfigs = {
|
|
7899
|
-
enableLSP: pluginNames.includes("lsp"),
|
|
7900
|
-
enableCodeCheck: pluginNames.includes("code-check"),
|
|
7901
|
-
enableReminder: pluginNames.includes("reminder")
|
|
7902
|
-
};
|
|
7903
|
-
if (!pluginConfigs.enableLSP && !pluginConfigs.enableCodeCheck && !pluginConfigs.enableReminder) {
|
|
7904
|
-
return;
|
|
7905
|
-
}
|
|
7906
|
-
const hookManager = globalHookManager2;
|
|
7907
|
-
const adapter = createPluginHookAdapter(hookManager, pluginConfigs);
|
|
7908
|
-
await adapter.initialize();
|
|
7909
|
-
this.output.log(`[EnvironmentService] Loaded coder plugins: ${pluginNames.join(", ")}`);
|
|
7910
|
-
}
|
|
7911
7809
|
}
|
|
7912
7810
|
|
|
7913
7811
|
// src/commands/act.ts
|
|
@@ -8406,64 +8304,47 @@ function createActCommand(externalEnvService) {
|
|
|
8406
8304
|
if (llmComponent && promptComponent) {
|
|
8407
8305
|
sessionComponent.setSummaryComponents(promptComponent, llmComponent);
|
|
8408
8306
|
}
|
|
8409
|
-
if (coderPluginNames.
|
|
8307
|
+
if (coderPluginNames.includes("lsp")) {
|
|
8410
8308
|
try {
|
|
8411
|
-
const { globalHookManager: globalHookManager2 } = await import("@ai-setting/roy-agent-core");
|
|
8412
|
-
const { createPluginHookAdapter, createGlobalLSPManager } = await import("@ai-setting/roy-agent-coder-harness");
|
|
8413
|
-
const adapter = createPluginHookAdapter(globalHookManager2, {
|
|
8414
|
-
enableLSP: coderPluginNames.includes("lsp"),
|
|
8415
|
-
enableCodeCheck: coderPluginNames.includes("code-check"),
|
|
8416
|
-
enableReminder: coderPluginNames.includes("reminder"),
|
|
8417
|
-
enableTSLSP: coderPluginNames.includes("tslsp"),
|
|
8418
|
-
enablePylsp: coderPluginNames.includes("pylsp"),
|
|
8419
|
-
enableMdlsp: coderPluginNames.includes("mdlsp")
|
|
8420
|
-
});
|
|
8421
|
-
await adapter.initialize();
|
|
8422
|
-
pluginAdapterDispose = () => adapter.dispose();
|
|
8423
8309
|
const enabledPlugins = coderPluginNames.filter((p) => CODER_HARNESS_PLUGINS.has(p.split(":")[0]));
|
|
8424
8310
|
if (enabledPlugins.length > 0) {
|
|
8425
8311
|
console.log(`已启用插件: ${enabledPlugins.join(", ")}`);
|
|
8426
8312
|
output.success(`✅ 已启用插件: ${enabledPlugins.join(", ")}`);
|
|
8427
|
-
if (
|
|
8313
|
+
if (!quiet) {
|
|
8428
8314
|
output.info(`\uD83D\uDD27 LSP 服务预加载中,首次诊断可能需要等待...`);
|
|
8429
8315
|
}
|
|
8430
8316
|
}
|
|
8431
|
-
|
|
8432
|
-
|
|
8433
|
-
|
|
8434
|
-
|
|
8435
|
-
|
|
8317
|
+
const { createLSPConfigLoader } = await import("@ai-setting/roy-agent-coder-harness");
|
|
8318
|
+
const configLoader = createLSPConfigLoader();
|
|
8319
|
+
const lspConfig = configLoader.load();
|
|
8320
|
+
if (!quiet) {
|
|
8321
|
+
output.info("正在预热 LSP 服务器...");
|
|
8322
|
+
if (lspConfig.preload) {
|
|
8323
|
+
output.info("\uD83D\uDCCB 使用配置文件中的预加载设置");
|
|
8324
|
+
}
|
|
8325
|
+
}
|
|
8326
|
+
const { createGlobalLSPManager: createGlobalLSPManager2 } = await import("@ai-setting/roy-agent-coder-harness");
|
|
8327
|
+
const lspManager = createGlobalLSPManager2({
|
|
8328
|
+
idleTimeout: lspConfig.idleTimeout ?? 300000,
|
|
8329
|
+
maxConnections: lspConfig.maxConnections ?? 10,
|
|
8330
|
+
autoDownload: lspConfig.autoInstall ?? false,
|
|
8331
|
+
preloadLanguages: lspConfig.preloadLanguages
|
|
8332
|
+
});
|
|
8333
|
+
lspManager.registerShutdownHandler();
|
|
8334
|
+
lspManagerDispose = () => lspManager.dispose();
|
|
8335
|
+
if (lspConfig.preload || coderPluginNames.includes("lsp")) {
|
|
8336
|
+
lspManager.prewarm().then(() => {
|
|
8436
8337
|
if (!quiet) {
|
|
8437
|
-
output.
|
|
8438
|
-
if (lspConfig.preload) {
|
|
8439
|
-
output.info("\uD83D\uDCCB 使用配置文件中的预加载设置");
|
|
8440
|
-
}
|
|
8338
|
+
output.success("✅ LSP 服务器预热完成");
|
|
8441
8339
|
}
|
|
8442
|
-
|
|
8443
|
-
|
|
8444
|
-
|
|
8445
|
-
autoDownload: lspConfig.autoInstall ?? false,
|
|
8446
|
-
preloadLanguages: lspConfig.preloadLanguages
|
|
8447
|
-
});
|
|
8448
|
-
lspManager.registerShutdownHandler();
|
|
8449
|
-
lspManagerDispose = () => lspManager.dispose();
|
|
8450
|
-
if (lspConfig.preload || coderPluginNames.includes("lsp")) {
|
|
8451
|
-
lspManager.prewarm().then(() => {
|
|
8452
|
-
if (!quiet) {
|
|
8453
|
-
output.success("✅ LSP 服务器预热完成");
|
|
8454
|
-
}
|
|
8455
|
-
}).catch((err) => {
|
|
8456
|
-
if (!quiet) {
|
|
8457
|
-
output.warn(`⚠ LSP 预热部分失败: ${err.message}`);
|
|
8458
|
-
}
|
|
8459
|
-
});
|
|
8340
|
+
}).catch((err) => {
|
|
8341
|
+
if (!quiet) {
|
|
8342
|
+
output.warn(`⚠ LSP 预热部分失败: ${err.message}`);
|
|
8460
8343
|
}
|
|
8461
|
-
}
|
|
8462
|
-
output.warn(`⚠ LSP 预热失败: ${error}`);
|
|
8463
|
-
}
|
|
8344
|
+
});
|
|
8464
8345
|
}
|
|
8465
8346
|
} catch (error) {
|
|
8466
|
-
output.
|
|
8347
|
+
output.warn(`⚠ LSP 预热失败: ${error}`);
|
|
8467
8348
|
}
|
|
8468
8349
|
}
|
|
8469
8350
|
const streamService = new StreamOutputService({
|
|
@@ -8654,8 +8535,7 @@ class SessionManager {
|
|
|
8654
8535
|
|
|
8655
8536
|
// src/commands/shared/query-executor.ts
|
|
8656
8537
|
init_stream_output_service();
|
|
8657
|
-
import { ContextError as ContextError3, ErrorCodes as ErrorCodes3,
|
|
8658
|
-
|
|
8538
|
+
import { ContextError as ContextError3, ErrorCodes as ErrorCodes3, TracedAs as TracedAs2 } from "@ai-setting/roy-agent-core";
|
|
8659
8539
|
class QueryExecutor {
|
|
8660
8540
|
env;
|
|
8661
8541
|
sessionComponent;
|
|
@@ -8757,33 +8637,16 @@ class QueryExecutor {
|
|
|
8757
8637
|
},
|
|
8758
8638
|
...agentContext
|
|
8759
8639
|
};
|
|
8760
|
-
let span;
|
|
8761
|
-
const tracer = getTracerProvider3().getTracer("roy-tracer");
|
|
8762
|
-
const currentContext = tracer.getCurrentContext();
|
|
8763
|
-
span = tracer.startSpan("query-executor.execute", {
|
|
8764
|
-
parent: currentContext,
|
|
8765
|
-
attributes: {
|
|
8766
|
-
query: message.substring(0, 200),
|
|
8767
|
-
sessionId
|
|
8768
|
-
}
|
|
8769
|
-
});
|
|
8770
8640
|
let result;
|
|
8771
8641
|
try {
|
|
8772
8642
|
result = await contextHandler.handleQueryWithContext(message, context);
|
|
8773
|
-
if (span) {
|
|
8774
|
-
span.end(result);
|
|
8775
|
-
}
|
|
8776
8643
|
} catch (error) {
|
|
8777
|
-
if (span) {
|
|
8778
|
-
span.setAttribute("error", String(error));
|
|
8779
|
-
span.end(undefined, error instanceof Error ? error : new Error(String(error)));
|
|
8780
|
-
}
|
|
8781
8644
|
if (error instanceof ContextError3 && error.code === ErrorCodes3.CONTEXT_THRESHOLD_EXCEEDED) {
|
|
8782
8645
|
this.output.error(`上下文阈值超出限制: ${error.usage?.totalTokens}/${error.contextWindow}`);
|
|
8783
8646
|
this.output.info("请手动压缩会话: roy-agent sessions compact " + sessionId);
|
|
8784
8647
|
}
|
|
8785
8648
|
throw error;
|
|
8786
|
-
}
|
|
8649
|
+
}
|
|
8787
8650
|
if (!this.quiet) {
|
|
8788
8651
|
this.output.success("执行完成");
|
|
8789
8652
|
}
|
|
@@ -8836,6 +8699,18 @@ class QueryExecutor {
|
|
|
8836
8699
|
}
|
|
8837
8700
|
}
|
|
8838
8701
|
}
|
|
8702
|
+
__legacyDecorateClassTS([
|
|
8703
|
+
TracedAs2("cli.query-executor.execute", { recordParams: true, log: true }),
|
|
8704
|
+
__legacyMetadataTS("design:type", Function),
|
|
8705
|
+
__legacyMetadataTS("design:paramtypes", [
|
|
8706
|
+
String,
|
|
8707
|
+
String,
|
|
8708
|
+
typeof Partial === "undefined" ? Object : Partial,
|
|
8709
|
+
String,
|
|
8710
|
+
Object
|
|
8711
|
+
]),
|
|
8712
|
+
__legacyMetadataTS("design:returntype", typeof Promise === "undefined" ? Object : Promise)
|
|
8713
|
+
], QueryExecutor.prototype, "execute", null);
|
|
8839
8714
|
|
|
8840
8715
|
// src/commands/shared/event-message-formatter.ts
|
|
8841
8716
|
var TaskEventTypes = {
|
|
@@ -8970,6 +8845,7 @@ class EventMessageFormatter {
|
|
|
8970
8845
|
}
|
|
8971
8846
|
|
|
8972
8847
|
// src/commands/shared/event-handler.ts
|
|
8848
|
+
import { TracedAs as TracedAs3 } from "@ai-setting/roy-agent-core";
|
|
8973
8849
|
class EventHandler {
|
|
8974
8850
|
env;
|
|
8975
8851
|
eventTypes;
|
|
@@ -9080,10 +8956,18 @@ class EventHandler {
|
|
|
9080
8956
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
9081
8957
|
}
|
|
9082
8958
|
}
|
|
8959
|
+
__legacyDecorateClassTS([
|
|
8960
|
+
TracedAs3("cli.event-handler.handleEvent", { recordParams: true }),
|
|
8961
|
+
__legacyMetadataTS("design:type", Function),
|
|
8962
|
+
__legacyMetadataTS("design:paramtypes", [
|
|
8963
|
+
typeof EnvEvent === "undefined" ? Object : EnvEvent
|
|
8964
|
+
]),
|
|
8965
|
+
__legacyMetadataTS("design:returntype", undefined)
|
|
8966
|
+
], EventHandler.prototype, "handleEvent", null);
|
|
9083
8967
|
|
|
9084
8968
|
// src/commands/interactive.ts
|
|
9085
8969
|
init_stream_output_service();
|
|
9086
|
-
import { createLogger as createLogger4, getTracerProvider as
|
|
8970
|
+
import { createLogger as createLogger4, getTracerProvider as getTracerProvider3 } from "@ai-setting/roy-agent-core";
|
|
9087
8971
|
|
|
9088
8972
|
// src/commands/input-handler.ts
|
|
9089
8973
|
class InputHandler {
|
|
@@ -9343,11 +9227,14 @@ ${COLORS.system("[通知2] ❯ " + message.replace(/\n/g, `
|
|
|
9343
9227
|
` + COLORS.system("[通知2] ❯ ")))}
|
|
9344
9228
|
`);
|
|
9345
9229
|
const sourceId = envEvent.metadata?.sourceId;
|
|
9346
|
-
|
|
9347
|
-
|
|
9348
|
-
|
|
9349
|
-
|
|
9350
|
-
|
|
9230
|
+
let pluginEnabled = envEvent.metadata?.pluginEnabled;
|
|
9231
|
+
let plugins = envEvent.metadata?.plugins;
|
|
9232
|
+
if (!pluginEnabled || Object.keys(pluginEnabled).length === 0) {
|
|
9233
|
+
pluginEnabled = {};
|
|
9234
|
+
for (const pluginName of plugins || []) {
|
|
9235
|
+
const key = `${sourceId}:${pluginName}`;
|
|
9236
|
+
pluginEnabled[key] = true;
|
|
9237
|
+
}
|
|
9351
9238
|
}
|
|
9352
9239
|
this.currentAgentContext = {
|
|
9353
9240
|
pluginEnabled,
|
|
@@ -9365,11 +9252,21 @@ ${COLORS.system("[通知2] ❯ " + message.replace(/\n/g, `
|
|
|
9365
9252
|
const agentContext = this.currentAgentContext;
|
|
9366
9253
|
this.currentAgentContext = undefined;
|
|
9367
9254
|
resetStreamAbort();
|
|
9368
|
-
const provider =
|
|
9255
|
+
const provider = getTracerProvider3();
|
|
9369
9256
|
const tracer = provider.getTracer("roy-tracer");
|
|
9370
|
-
const
|
|
9371
|
-
|
|
9372
|
-
|
|
9257
|
+
const existingContext = provider.getGlobalContext();
|
|
9258
|
+
let rootSpan;
|
|
9259
|
+
let traceId;
|
|
9260
|
+
if (existingContext) {
|
|
9261
|
+
rootSpan = tracer.startSpan("interactive.execute", {
|
|
9262
|
+
parent: existingContext
|
|
9263
|
+
});
|
|
9264
|
+
traceId = existingContext.traceId;
|
|
9265
|
+
} else {
|
|
9266
|
+
rootSpan = tracer.startSpan("interactive.execute");
|
|
9267
|
+
traceId = rootSpan.spanContext.traceId;
|
|
9268
|
+
provider.setGlobalContext(rootSpan.spanContext);
|
|
9269
|
+
}
|
|
9373
9270
|
console.log(`${COLORS.system("[Trace] " + traceId)}`);
|
|
9374
9271
|
console.log(`${COLORS.progress("[thinking...]")}`);
|
|
9375
9272
|
try {
|
|
@@ -9385,8 +9282,12 @@ ${COLORS.error("❌ 执行失败: " + error)}
|
|
|
9385
9282
|
rootSpan.setAttribute("error", String(error));
|
|
9386
9283
|
}
|
|
9387
9284
|
} finally {
|
|
9388
|
-
provider.setGlobalContext(undefined);
|
|
9389
9285
|
rootSpan.end();
|
|
9286
|
+
if (existingContext) {
|
|
9287
|
+
provider.setGlobalContext(existingContext);
|
|
9288
|
+
} else {
|
|
9289
|
+
provider.setGlobalContext(undefined);
|
|
9290
|
+
}
|
|
9390
9291
|
this.isExecuting = false;
|
|
9391
9292
|
if (options.showPrompt) {
|
|
9392
9293
|
this.rl.prompt(true);
|
|
@@ -9678,18 +9579,6 @@ function createInteractiveCommand(externalEnvService) {
|
|
|
9678
9579
|
let memoryPluginInstance = null;
|
|
9679
9580
|
if (coderPluginNames.length > 0) {
|
|
9680
9581
|
try {
|
|
9681
|
-
const { globalHookManager: globalHookManager2 } = await import("@ai-setting/roy-agent-core");
|
|
9682
|
-
const { createPluginHookAdapter, createGlobalLSPManager } = await import("@ai-setting/roy-agent-coder-harness");
|
|
9683
|
-
const adapter = createPluginHookAdapter(globalHookManager2, {
|
|
9684
|
-
enableLSP: coderPluginNames.includes("lsp"),
|
|
9685
|
-
enableCodeCheck: coderPluginNames.includes("code-check"),
|
|
9686
|
-
enableReminder: coderPluginNames.includes("reminder"),
|
|
9687
|
-
enableTSLSP: coderPluginNames.includes("tslsp"),
|
|
9688
|
-
enablePylsp: coderPluginNames.includes("pylsp"),
|
|
9689
|
-
enableMdlsp: coderPluginNames.includes("mdlsp")
|
|
9690
|
-
});
|
|
9691
|
-
await adapter.initialize();
|
|
9692
|
-
pluginAdapterDispose = () => adapter.dispose();
|
|
9693
9582
|
const enabledPlugins = coderPluginNames.filter((p) => CODER_HARNESS_PLUGINS.has(p.split(":")[0]));
|
|
9694
9583
|
if (enabledPlugins.length > 0) {
|
|
9695
9584
|
console.log(`已启用插件: ${enabledPlugins.join(", ")}`);
|
|
@@ -16528,7 +16417,7 @@ var import_yaml = __toESM(require_dist(), 1);
|
|
|
16528
16417
|
import chalk55 from "chalk";
|
|
16529
16418
|
import fs5 from "fs";
|
|
16530
16419
|
import path8 from "path";
|
|
16531
|
-
import { getTracerProvider as
|
|
16420
|
+
import { getTracerProvider as getTracerProvider4, propagation, wrapFunction } from "@ai-setting/roy-agent-core";
|
|
16532
16421
|
var runWorkflow = wrapFunction(async function runWorkflowImpl(args) {
|
|
16533
16422
|
const output = new OutputService;
|
|
16534
16423
|
const envService = new EnvironmentService(output);
|
|
@@ -16549,7 +16438,7 @@ var runWorkflow = wrapFunction(async function runWorkflowImpl(args) {
|
|
|
16549
16438
|
output.info(`[OTel Trace] TRACEPARENT=${traceparent || "none"}, traceId=${traceId}, parentSpanId=${parentSpanId}`);
|
|
16550
16439
|
let workflowSpan = undefined;
|
|
16551
16440
|
try {
|
|
16552
|
-
const provider =
|
|
16441
|
+
const provider = getTracerProvider4();
|
|
16553
16442
|
await provider.initialize();
|
|
16554
16443
|
const tracer = provider.getTracer("roy-tracer");
|
|
16555
16444
|
const restoredContext = tracer.getCurrentContext();
|
package/dist/index.js
CHANGED
|
@@ -7219,7 +7219,7 @@ var require_dist = __commonJS((exports) => {
|
|
|
7219
7219
|
var require_package = __commonJS((exports, module) => {
|
|
7220
7220
|
module.exports = {
|
|
7221
7221
|
name: "@ai-setting/roy-agent-cli",
|
|
7222
|
-
version: "1.5.
|
|
7222
|
+
version: "1.5.40",
|
|
7223
7223
|
type: "module",
|
|
7224
7224
|
description: "CLI for roy-agent - Non-interactive command execution",
|
|
7225
7225
|
main: "./dist/index.js",
|
|
@@ -7245,8 +7245,8 @@ var require_package = __commonJS((exports, module) => {
|
|
|
7245
7245
|
typecheck: "npx tsc --noEmit --skipLibCheck"
|
|
7246
7246
|
},
|
|
7247
7247
|
dependencies: {
|
|
7248
|
-
"@ai-setting/roy-agent-coder-harness": "^1.5.
|
|
7249
|
-
"@ai-setting/roy-agent-core": "^1.5.
|
|
7248
|
+
"@ai-setting/roy-agent-coder-harness": "^1.5.40",
|
|
7249
|
+
"@ai-setting/roy-agent-core": "^1.5.40",
|
|
7250
7250
|
chalk: "^5.6.2",
|
|
7251
7251
|
commander: "^14.0.3",
|
|
7252
7252
|
effect: "^3.21.2",
|
|
@@ -7336,7 +7336,8 @@ import {
|
|
|
7336
7336
|
McpComponent,
|
|
7337
7337
|
CommandsComponent,
|
|
7338
7338
|
MemoryComponent,
|
|
7339
|
-
EventSourceComponent
|
|
7339
|
+
EventSourceComponent,
|
|
7340
|
+
PluginComponent
|
|
7340
7341
|
} from "@ai-setting/roy-agent-core";
|
|
7341
7342
|
import { WorkflowComponent } from "@ai-setting/roy-agent-core";
|
|
7342
7343
|
import { MemoryPlugin } from "@ai-setting/roy-agent-core";
|
|
@@ -7403,124 +7404,6 @@ class OutputService {
|
|
|
7403
7404
|
}
|
|
7404
7405
|
}
|
|
7405
7406
|
|
|
7406
|
-
// src/plugin/registry.ts
|
|
7407
|
-
var taskTagPlugin = {
|
|
7408
|
-
info: {
|
|
7409
|
-
name: "task-tag",
|
|
7410
|
-
version: "1.0.0",
|
|
7411
|
-
description: "Intelligent tag suggestion and similar task experience injection"
|
|
7412
|
-
},
|
|
7413
|
-
getComponentPlugins() {
|
|
7414
|
-
return [{
|
|
7415
|
-
name: "task-tag",
|
|
7416
|
-
targetComponent: "task",
|
|
7417
|
-
factory: async () => {
|
|
7418
|
-
const { TaskTagPlugin } = await import("@ai-setting/roy-agent-core");
|
|
7419
|
-
return new TaskTagPlugin;
|
|
7420
|
-
}
|
|
7421
|
-
}];
|
|
7422
|
-
}
|
|
7423
|
-
};
|
|
7424
|
-
var BUILTIN_PLUGINS = [
|
|
7425
|
-
taskTagPlugin
|
|
7426
|
-
];
|
|
7427
|
-
|
|
7428
|
-
class PluginRegistry {
|
|
7429
|
-
plugins = new Map;
|
|
7430
|
-
constructor() {
|
|
7431
|
-
for (const plugin of BUILTIN_PLUGINS) {
|
|
7432
|
-
this.registerBuiltin(plugin);
|
|
7433
|
-
}
|
|
7434
|
-
}
|
|
7435
|
-
register(plugin) {
|
|
7436
|
-
if (this.plugins.has(plugin.info.name)) {
|
|
7437
|
-
throw new Error(`Plugin "${plugin.info.name}" is already registered`);
|
|
7438
|
-
}
|
|
7439
|
-
this.plugins.set(plugin.info.name, plugin);
|
|
7440
|
-
}
|
|
7441
|
-
registerBuiltin(plugin) {
|
|
7442
|
-
if (!this.plugins.has(plugin.info.name)) {
|
|
7443
|
-
this.plugins.set(plugin.info.name, plugin);
|
|
7444
|
-
}
|
|
7445
|
-
}
|
|
7446
|
-
unregister(name) {
|
|
7447
|
-
this.plugins.delete(name);
|
|
7448
|
-
}
|
|
7449
|
-
get(name) {
|
|
7450
|
-
return this.plugins.get(name);
|
|
7451
|
-
}
|
|
7452
|
-
has(name) {
|
|
7453
|
-
return this.plugins.has(name);
|
|
7454
|
-
}
|
|
7455
|
-
getAll() {
|
|
7456
|
-
return Array.from(this.plugins.values()).sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));
|
|
7457
|
-
}
|
|
7458
|
-
get size() {
|
|
7459
|
-
return this.plugins.size;
|
|
7460
|
-
}
|
|
7461
|
-
getAllCommands() {
|
|
7462
|
-
const commands = [];
|
|
7463
|
-
for (const plugin of this.getAll()) {
|
|
7464
|
-
commands.push(...plugin.getCommands?.() ?? []);
|
|
7465
|
-
}
|
|
7466
|
-
return commands;
|
|
7467
|
-
}
|
|
7468
|
-
getAllComponents() {
|
|
7469
|
-
const components = [];
|
|
7470
|
-
for (const plugin of this.getAll()) {
|
|
7471
|
-
components.push(...plugin.getComponents?.() ?? []);
|
|
7472
|
-
}
|
|
7473
|
-
return components;
|
|
7474
|
-
}
|
|
7475
|
-
getAllComponentPlugins() {
|
|
7476
|
-
const componentPlugins = [];
|
|
7477
|
-
for (const plugin of this.getAll()) {
|
|
7478
|
-
componentPlugins.push(...plugin.getComponentPlugins?.() ?? []);
|
|
7479
|
-
}
|
|
7480
|
-
return componentPlugins;
|
|
7481
|
-
}
|
|
7482
|
-
getComponentPlugin(name) {
|
|
7483
|
-
for (const plugin of this.getAll()) {
|
|
7484
|
-
const componentPlugins = plugin.getComponentPlugins?.() ?? [];
|
|
7485
|
-
for (const cp of componentPlugins) {
|
|
7486
|
-
if (cp.name === name) {
|
|
7487
|
-
return cp;
|
|
7488
|
-
}
|
|
7489
|
-
}
|
|
7490
|
-
}
|
|
7491
|
-
return;
|
|
7492
|
-
}
|
|
7493
|
-
*getPluginComponents() {
|
|
7494
|
-
for (const plugin of this.getAll()) {
|
|
7495
|
-
for (const definition of plugin.getComponents?.() ?? []) {
|
|
7496
|
-
yield { plugin, definition };
|
|
7497
|
-
}
|
|
7498
|
-
}
|
|
7499
|
-
}
|
|
7500
|
-
clear() {
|
|
7501
|
-
for (const name of this.plugins.keys()) {
|
|
7502
|
-
const plugin = this.plugins.get(name);
|
|
7503
|
-
if (!BUILTIN_PLUGINS.some((p) => p.info.name === name)) {
|
|
7504
|
-
this.plugins.delete(name);
|
|
7505
|
-
}
|
|
7506
|
-
}
|
|
7507
|
-
}
|
|
7508
|
-
async executeLifecycleHooks(phase, env) {
|
|
7509
|
-
const hookName = phase === "beforeInit" ? "onBeforeInit" : "onAfterInit";
|
|
7510
|
-
for (const plugin of this.getAll()) {
|
|
7511
|
-
const hook = plugin[hookName];
|
|
7512
|
-
if (hook) {
|
|
7513
|
-
try {
|
|
7514
|
-
await hook({ env });
|
|
7515
|
-
} catch (err) {
|
|
7516
|
-
console.warn(`[roy] Plugin "${plugin.info.name}" ${hookName} failed:`, err);
|
|
7517
|
-
}
|
|
7518
|
-
}
|
|
7519
|
-
}
|
|
7520
|
-
}
|
|
7521
|
-
}
|
|
7522
|
-
var globalPluginRegistry = new PluginRegistry;
|
|
7523
|
-
|
|
7524
7407
|
// src/services/environment.service.ts
|
|
7525
7408
|
var logger = createLogger("environment-service");
|
|
7526
7409
|
var CLI_CONFIG_DIR_NAME = "roy-agent";
|
|
@@ -7552,6 +7435,7 @@ class EnvironmentService {
|
|
|
7552
7435
|
memoryPlugin;
|
|
7553
7436
|
eventSourceComponent;
|
|
7554
7437
|
workflowComponent;
|
|
7438
|
+
pluginComponent;
|
|
7555
7439
|
constructor(output) {
|
|
7556
7440
|
this.output = output ?? new OutputService;
|
|
7557
7441
|
}
|
|
@@ -7584,6 +7468,7 @@ class EnvironmentService {
|
|
|
7584
7468
|
}
|
|
7585
7469
|
async dispose() {
|
|
7586
7470
|
for (const component of [
|
|
7471
|
+
this.pluginComponent,
|
|
7587
7472
|
this.eventSourceComponent,
|
|
7588
7473
|
this.memoryComponent,
|
|
7589
7474
|
this.commandsComponent,
|
|
@@ -7813,20 +7698,22 @@ class EnvironmentService {
|
|
|
7813
7698
|
env.registerComponent(memoryComponent);
|
|
7814
7699
|
env.registerComponent(eventSourceComponent);
|
|
7815
7700
|
env.registerComponent(workflowComponent);
|
|
7701
|
+
this.pluginComponent = new PluginComponent;
|
|
7702
|
+
const pluginComponent = this.pluginComponent;
|
|
7703
|
+
await pluginComponent.init({
|
|
7704
|
+
env,
|
|
7705
|
+
options: {
|
|
7706
|
+
configComponent
|
|
7707
|
+
}
|
|
7708
|
+
});
|
|
7709
|
+
env.registerComponent(pluginComponent);
|
|
7816
7710
|
this.registerCommandsPromptHook(promptComponent, commandsComponent);
|
|
7817
7711
|
await env.init();
|
|
7818
7712
|
await env.start();
|
|
7819
7713
|
agentComponent.refreshDependencies();
|
|
7820
7714
|
logger.debug("[EnvironmentService] AgentComponent dependencies refreshed after env.start()");
|
|
7821
7715
|
if (options?.plugins && options.plugins.length > 0) {
|
|
7822
|
-
await this.
|
|
7823
|
-
task: taskComponent,
|
|
7824
|
-
memory: memoryComponent,
|
|
7825
|
-
llm: llmComponent
|
|
7826
|
-
});
|
|
7827
|
-
}
|
|
7828
|
-
if (options?.plugins && options.plugins.length > 0) {
|
|
7829
|
-
await this.loadCoderPlugins(options.plugins);
|
|
7716
|
+
await this.loadPlugins(options.plugins);
|
|
7830
7717
|
}
|
|
7831
7718
|
this.environment = env;
|
|
7832
7719
|
return env;
|
|
@@ -7853,27 +7740,54 @@ class EnvironmentService {
|
|
|
7853
7740
|
});
|
|
7854
7741
|
this.output.info("Registered commands-prompt Hook");
|
|
7855
7742
|
}
|
|
7856
|
-
async
|
|
7743
|
+
async loadPlugins(pluginNames) {
|
|
7857
7744
|
for (const name of pluginNames) {
|
|
7858
7745
|
try {
|
|
7859
|
-
|
|
7860
|
-
|
|
7861
|
-
|
|
7862
|
-
|
|
7863
|
-
|
|
7864
|
-
|
|
7865
|
-
|
|
7866
|
-
|
|
7867
|
-
|
|
7868
|
-
|
|
7869
|
-
|
|
7870
|
-
|
|
7871
|
-
|
|
7872
|
-
|
|
7873
|
-
|
|
7746
|
+
let plugin;
|
|
7747
|
+
switch (name) {
|
|
7748
|
+
case "task-tag": {
|
|
7749
|
+
const { TaskTagPlugin } = await import("@ai-setting/roy-agent-core");
|
|
7750
|
+
plugin = new TaskTagPlugin;
|
|
7751
|
+
break;
|
|
7752
|
+
}
|
|
7753
|
+
case "lsp": {
|
|
7754
|
+
const { LSPPlugin } = await import("@ai-setting/roy-agent-coder-harness");
|
|
7755
|
+
plugin = new LSPPlugin({ preloadMode: "startup" });
|
|
7756
|
+
break;
|
|
7757
|
+
}
|
|
7758
|
+
case "code-check": {
|
|
7759
|
+
const { CodeCheckPlugin } = await import("@ai-setting/roy-agent-coder-harness");
|
|
7760
|
+
plugin = new CodeCheckPlugin;
|
|
7761
|
+
break;
|
|
7762
|
+
}
|
|
7763
|
+
case "reminder": {
|
|
7764
|
+
const { ReminderPlugin } = await import("@ai-setting/roy-agent-coder-harness");
|
|
7765
|
+
plugin = new ReminderPlugin;
|
|
7766
|
+
break;
|
|
7767
|
+
}
|
|
7768
|
+
case "tslsp": {
|
|
7769
|
+
const { TSLSPPlugin } = await import("@ai-setting/roy-agent-coder-harness");
|
|
7770
|
+
plugin = new TSLSPPlugin({ preloadMode: "startup" });
|
|
7771
|
+
break;
|
|
7772
|
+
}
|
|
7773
|
+
case "pylsp": {
|
|
7774
|
+
const { PyLSPPlugin } = await import("@ai-setting/roy-agent-coder-harness");
|
|
7775
|
+
plugin = new PyLSPPlugin({ preloadMode: "startup" });
|
|
7776
|
+
break;
|
|
7777
|
+
}
|
|
7778
|
+
case "mdlsp": {
|
|
7779
|
+
const { MDLSPPlugin } = await import("@ai-setting/roy-agent-coder-harness");
|
|
7780
|
+
plugin = new MDLSPPlugin;
|
|
7781
|
+
break;
|
|
7782
|
+
}
|
|
7783
|
+
default:
|
|
7784
|
+
this.output.warn(`[EnvironmentService] Unknown plugin: ${name}`);
|
|
7785
|
+
continue;
|
|
7874
7786
|
}
|
|
7787
|
+
this.pluginComponent?.register(plugin);
|
|
7788
|
+
this.output.log(`[EnvironmentService] Registered plugin: ${name}`);
|
|
7875
7789
|
} catch (error) {
|
|
7876
|
-
this.output.error(`[EnvironmentService] Error loading
|
|
7790
|
+
this.output.error(`[EnvironmentService] Error loading plugin "${name}": ${error}`);
|
|
7877
7791
|
}
|
|
7878
7792
|
}
|
|
7879
7793
|
}
|
|
@@ -7891,22 +7805,6 @@ ${rows}
|
|
|
7891
7805
|
|
|
7892
7806
|
Progressive Discovery: Run \`<command> --help\` to explore full capabilities.`;
|
|
7893
7807
|
}
|
|
7894
|
-
async loadCoderPlugins(pluginNames) {
|
|
7895
|
-
const { createPluginHookAdapter } = await import("@ai-setting/roy-agent-coder-harness");
|
|
7896
|
-
const { globalHookManager: globalHookManager2 } = await import("@ai-setting/roy-agent-core");
|
|
7897
|
-
const pluginConfigs = {
|
|
7898
|
-
enableLSP: pluginNames.includes("lsp"),
|
|
7899
|
-
enableCodeCheck: pluginNames.includes("code-check"),
|
|
7900
|
-
enableReminder: pluginNames.includes("reminder")
|
|
7901
|
-
};
|
|
7902
|
-
if (!pluginConfigs.enableLSP && !pluginConfigs.enableCodeCheck && !pluginConfigs.enableReminder) {
|
|
7903
|
-
return;
|
|
7904
|
-
}
|
|
7905
|
-
const hookManager = globalHookManager2;
|
|
7906
|
-
const adapter = createPluginHookAdapter(hookManager, pluginConfigs);
|
|
7907
|
-
await adapter.initialize();
|
|
7908
|
-
this.output.log(`[EnvironmentService] Loaded coder plugins: ${pluginNames.join(", ")}`);
|
|
7909
|
-
}
|
|
7910
7808
|
}
|
|
7911
7809
|
|
|
7912
7810
|
// src/commands/act.ts
|
|
@@ -8405,64 +8303,47 @@ function createActCommand(externalEnvService) {
|
|
|
8405
8303
|
if (llmComponent && promptComponent) {
|
|
8406
8304
|
sessionComponent.setSummaryComponents(promptComponent, llmComponent);
|
|
8407
8305
|
}
|
|
8408
|
-
if (coderPluginNames.
|
|
8306
|
+
if (coderPluginNames.includes("lsp")) {
|
|
8409
8307
|
try {
|
|
8410
|
-
const { globalHookManager: globalHookManager2 } = await import("@ai-setting/roy-agent-core");
|
|
8411
|
-
const { createPluginHookAdapter, createGlobalLSPManager } = await import("@ai-setting/roy-agent-coder-harness");
|
|
8412
|
-
const adapter = createPluginHookAdapter(globalHookManager2, {
|
|
8413
|
-
enableLSP: coderPluginNames.includes("lsp"),
|
|
8414
|
-
enableCodeCheck: coderPluginNames.includes("code-check"),
|
|
8415
|
-
enableReminder: coderPluginNames.includes("reminder"),
|
|
8416
|
-
enableTSLSP: coderPluginNames.includes("tslsp"),
|
|
8417
|
-
enablePylsp: coderPluginNames.includes("pylsp"),
|
|
8418
|
-
enableMdlsp: coderPluginNames.includes("mdlsp")
|
|
8419
|
-
});
|
|
8420
|
-
await adapter.initialize();
|
|
8421
|
-
pluginAdapterDispose = () => adapter.dispose();
|
|
8422
8308
|
const enabledPlugins = coderPluginNames.filter((p) => CODER_HARNESS_PLUGINS.has(p.split(":")[0]));
|
|
8423
8309
|
if (enabledPlugins.length > 0) {
|
|
8424
8310
|
console.log(`已启用插件: ${enabledPlugins.join(", ")}`);
|
|
8425
8311
|
output.success(`✅ 已启用插件: ${enabledPlugins.join(", ")}`);
|
|
8426
|
-
if (
|
|
8312
|
+
if (!quiet) {
|
|
8427
8313
|
output.info(`\uD83D\uDD27 LSP 服务预加载中,首次诊断可能需要等待...`);
|
|
8428
8314
|
}
|
|
8429
8315
|
}
|
|
8430
|
-
|
|
8431
|
-
|
|
8432
|
-
|
|
8433
|
-
|
|
8434
|
-
|
|
8316
|
+
const { createLSPConfigLoader } = await import("@ai-setting/roy-agent-coder-harness");
|
|
8317
|
+
const configLoader = createLSPConfigLoader();
|
|
8318
|
+
const lspConfig = configLoader.load();
|
|
8319
|
+
if (!quiet) {
|
|
8320
|
+
output.info("正在预热 LSP 服务器...");
|
|
8321
|
+
if (lspConfig.preload) {
|
|
8322
|
+
output.info("\uD83D\uDCCB 使用配置文件中的预加载设置");
|
|
8323
|
+
}
|
|
8324
|
+
}
|
|
8325
|
+
const { createGlobalLSPManager: createGlobalLSPManager2 } = await import("@ai-setting/roy-agent-coder-harness");
|
|
8326
|
+
const lspManager = createGlobalLSPManager2({
|
|
8327
|
+
idleTimeout: lspConfig.idleTimeout ?? 300000,
|
|
8328
|
+
maxConnections: lspConfig.maxConnections ?? 10,
|
|
8329
|
+
autoDownload: lspConfig.autoInstall ?? false,
|
|
8330
|
+
preloadLanguages: lspConfig.preloadLanguages
|
|
8331
|
+
});
|
|
8332
|
+
lspManager.registerShutdownHandler();
|
|
8333
|
+
lspManagerDispose = () => lspManager.dispose();
|
|
8334
|
+
if (lspConfig.preload || coderPluginNames.includes("lsp")) {
|
|
8335
|
+
lspManager.prewarm().then(() => {
|
|
8435
8336
|
if (!quiet) {
|
|
8436
|
-
output.
|
|
8437
|
-
if (lspConfig.preload) {
|
|
8438
|
-
output.info("\uD83D\uDCCB 使用配置文件中的预加载设置");
|
|
8439
|
-
}
|
|
8337
|
+
output.success("✅ LSP 服务器预热完成");
|
|
8440
8338
|
}
|
|
8441
|
-
|
|
8442
|
-
|
|
8443
|
-
|
|
8444
|
-
autoDownload: lspConfig.autoInstall ?? false,
|
|
8445
|
-
preloadLanguages: lspConfig.preloadLanguages
|
|
8446
|
-
});
|
|
8447
|
-
lspManager.registerShutdownHandler();
|
|
8448
|
-
lspManagerDispose = () => lspManager.dispose();
|
|
8449
|
-
if (lspConfig.preload || coderPluginNames.includes("lsp")) {
|
|
8450
|
-
lspManager.prewarm().then(() => {
|
|
8451
|
-
if (!quiet) {
|
|
8452
|
-
output.success("✅ LSP 服务器预热完成");
|
|
8453
|
-
}
|
|
8454
|
-
}).catch((err) => {
|
|
8455
|
-
if (!quiet) {
|
|
8456
|
-
output.warn(`⚠ LSP 预热部分失败: ${err.message}`);
|
|
8457
|
-
}
|
|
8458
|
-
});
|
|
8339
|
+
}).catch((err) => {
|
|
8340
|
+
if (!quiet) {
|
|
8341
|
+
output.warn(`⚠ LSP 预热部分失败: ${err.message}`);
|
|
8459
8342
|
}
|
|
8460
|
-
}
|
|
8461
|
-
output.warn(`⚠ LSP 预热失败: ${error}`);
|
|
8462
|
-
}
|
|
8343
|
+
});
|
|
8463
8344
|
}
|
|
8464
8345
|
} catch (error) {
|
|
8465
|
-
output.
|
|
8346
|
+
output.warn(`⚠ LSP 预热失败: ${error}`);
|
|
8466
8347
|
}
|
|
8467
8348
|
}
|
|
8468
8349
|
const streamService = new StreamOutputService({
|
|
@@ -8653,8 +8534,7 @@ class SessionManager {
|
|
|
8653
8534
|
|
|
8654
8535
|
// src/commands/shared/query-executor.ts
|
|
8655
8536
|
init_stream_output_service();
|
|
8656
|
-
import { ContextError as ContextError3, ErrorCodes as ErrorCodes3,
|
|
8657
|
-
|
|
8537
|
+
import { ContextError as ContextError3, ErrorCodes as ErrorCodes3, TracedAs as TracedAs2 } from "@ai-setting/roy-agent-core";
|
|
8658
8538
|
class QueryExecutor {
|
|
8659
8539
|
env;
|
|
8660
8540
|
sessionComponent;
|
|
@@ -8756,33 +8636,16 @@ class QueryExecutor {
|
|
|
8756
8636
|
},
|
|
8757
8637
|
...agentContext
|
|
8758
8638
|
};
|
|
8759
|
-
let span;
|
|
8760
|
-
const tracer = getTracerProvider3().getTracer("roy-tracer");
|
|
8761
|
-
const currentContext = tracer.getCurrentContext();
|
|
8762
|
-
span = tracer.startSpan("query-executor.execute", {
|
|
8763
|
-
parent: currentContext,
|
|
8764
|
-
attributes: {
|
|
8765
|
-
query: message.substring(0, 200),
|
|
8766
|
-
sessionId
|
|
8767
|
-
}
|
|
8768
|
-
});
|
|
8769
8639
|
let result;
|
|
8770
8640
|
try {
|
|
8771
8641
|
result = await contextHandler.handleQueryWithContext(message, context);
|
|
8772
|
-
if (span) {
|
|
8773
|
-
span.end(result);
|
|
8774
|
-
}
|
|
8775
8642
|
} catch (error) {
|
|
8776
|
-
if (span) {
|
|
8777
|
-
span.setAttribute("error", String(error));
|
|
8778
|
-
span.end(undefined, error instanceof Error ? error : new Error(String(error)));
|
|
8779
|
-
}
|
|
8780
8643
|
if (error instanceof ContextError3 && error.code === ErrorCodes3.CONTEXT_THRESHOLD_EXCEEDED) {
|
|
8781
8644
|
this.output.error(`上下文阈值超出限制: ${error.usage?.totalTokens}/${error.contextWindow}`);
|
|
8782
8645
|
this.output.info("请手动压缩会话: roy-agent sessions compact " + sessionId);
|
|
8783
8646
|
}
|
|
8784
8647
|
throw error;
|
|
8785
|
-
}
|
|
8648
|
+
}
|
|
8786
8649
|
if (!this.quiet) {
|
|
8787
8650
|
this.output.success("执行完成");
|
|
8788
8651
|
}
|
|
@@ -8835,6 +8698,18 @@ class QueryExecutor {
|
|
|
8835
8698
|
}
|
|
8836
8699
|
}
|
|
8837
8700
|
}
|
|
8701
|
+
__legacyDecorateClassTS([
|
|
8702
|
+
TracedAs2("cli.query-executor.execute", { recordParams: true, log: true }),
|
|
8703
|
+
__legacyMetadataTS("design:type", Function),
|
|
8704
|
+
__legacyMetadataTS("design:paramtypes", [
|
|
8705
|
+
String,
|
|
8706
|
+
String,
|
|
8707
|
+
typeof Partial === "undefined" ? Object : Partial,
|
|
8708
|
+
String,
|
|
8709
|
+
Object
|
|
8710
|
+
]),
|
|
8711
|
+
__legacyMetadataTS("design:returntype", typeof Promise === "undefined" ? Object : Promise)
|
|
8712
|
+
], QueryExecutor.prototype, "execute", null);
|
|
8838
8713
|
|
|
8839
8714
|
// src/commands/shared/event-message-formatter.ts
|
|
8840
8715
|
var TaskEventTypes = {
|
|
@@ -8969,6 +8844,7 @@ class EventMessageFormatter {
|
|
|
8969
8844
|
}
|
|
8970
8845
|
|
|
8971
8846
|
// src/commands/shared/event-handler.ts
|
|
8847
|
+
import { TracedAs as TracedAs3 } from "@ai-setting/roy-agent-core";
|
|
8972
8848
|
class EventHandler {
|
|
8973
8849
|
env;
|
|
8974
8850
|
eventTypes;
|
|
@@ -9079,10 +8955,18 @@ class EventHandler {
|
|
|
9079
8955
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
9080
8956
|
}
|
|
9081
8957
|
}
|
|
8958
|
+
__legacyDecorateClassTS([
|
|
8959
|
+
TracedAs3("cli.event-handler.handleEvent", { recordParams: true }),
|
|
8960
|
+
__legacyMetadataTS("design:type", Function),
|
|
8961
|
+
__legacyMetadataTS("design:paramtypes", [
|
|
8962
|
+
typeof EnvEvent === "undefined" ? Object : EnvEvent
|
|
8963
|
+
]),
|
|
8964
|
+
__legacyMetadataTS("design:returntype", undefined)
|
|
8965
|
+
], EventHandler.prototype, "handleEvent", null);
|
|
9082
8966
|
|
|
9083
8967
|
// src/commands/interactive.ts
|
|
9084
8968
|
init_stream_output_service();
|
|
9085
|
-
import { createLogger as createLogger4, getTracerProvider as
|
|
8969
|
+
import { createLogger as createLogger4, getTracerProvider as getTracerProvider3 } from "@ai-setting/roy-agent-core";
|
|
9086
8970
|
|
|
9087
8971
|
// src/commands/input-handler.ts
|
|
9088
8972
|
class InputHandler {
|
|
@@ -9342,11 +9226,14 @@ ${COLORS.system("[通知2] ❯ " + message.replace(/\n/g, `
|
|
|
9342
9226
|
` + COLORS.system("[通知2] ❯ ")))}
|
|
9343
9227
|
`);
|
|
9344
9228
|
const sourceId = envEvent.metadata?.sourceId;
|
|
9345
|
-
|
|
9346
|
-
|
|
9347
|
-
|
|
9348
|
-
|
|
9349
|
-
|
|
9229
|
+
let pluginEnabled = envEvent.metadata?.pluginEnabled;
|
|
9230
|
+
let plugins = envEvent.metadata?.plugins;
|
|
9231
|
+
if (!pluginEnabled || Object.keys(pluginEnabled).length === 0) {
|
|
9232
|
+
pluginEnabled = {};
|
|
9233
|
+
for (const pluginName of plugins || []) {
|
|
9234
|
+
const key = `${sourceId}:${pluginName}`;
|
|
9235
|
+
pluginEnabled[key] = true;
|
|
9236
|
+
}
|
|
9350
9237
|
}
|
|
9351
9238
|
this.currentAgentContext = {
|
|
9352
9239
|
pluginEnabled,
|
|
@@ -9364,11 +9251,21 @@ ${COLORS.system("[通知2] ❯ " + message.replace(/\n/g, `
|
|
|
9364
9251
|
const agentContext = this.currentAgentContext;
|
|
9365
9252
|
this.currentAgentContext = undefined;
|
|
9366
9253
|
resetStreamAbort();
|
|
9367
|
-
const provider =
|
|
9254
|
+
const provider = getTracerProvider3();
|
|
9368
9255
|
const tracer = provider.getTracer("roy-tracer");
|
|
9369
|
-
const
|
|
9370
|
-
|
|
9371
|
-
|
|
9256
|
+
const existingContext = provider.getGlobalContext();
|
|
9257
|
+
let rootSpan;
|
|
9258
|
+
let traceId;
|
|
9259
|
+
if (existingContext) {
|
|
9260
|
+
rootSpan = tracer.startSpan("interactive.execute", {
|
|
9261
|
+
parent: existingContext
|
|
9262
|
+
});
|
|
9263
|
+
traceId = existingContext.traceId;
|
|
9264
|
+
} else {
|
|
9265
|
+
rootSpan = tracer.startSpan("interactive.execute");
|
|
9266
|
+
traceId = rootSpan.spanContext.traceId;
|
|
9267
|
+
provider.setGlobalContext(rootSpan.spanContext);
|
|
9268
|
+
}
|
|
9372
9269
|
console.log(`${COLORS.system("[Trace] " + traceId)}`);
|
|
9373
9270
|
console.log(`${COLORS.progress("[thinking...]")}`);
|
|
9374
9271
|
try {
|
|
@@ -9384,8 +9281,12 @@ ${COLORS.error("❌ 执行失败: " + error)}
|
|
|
9384
9281
|
rootSpan.setAttribute("error", String(error));
|
|
9385
9282
|
}
|
|
9386
9283
|
} finally {
|
|
9387
|
-
provider.setGlobalContext(undefined);
|
|
9388
9284
|
rootSpan.end();
|
|
9285
|
+
if (existingContext) {
|
|
9286
|
+
provider.setGlobalContext(existingContext);
|
|
9287
|
+
} else {
|
|
9288
|
+
provider.setGlobalContext(undefined);
|
|
9289
|
+
}
|
|
9389
9290
|
this.isExecuting = false;
|
|
9390
9291
|
if (options.showPrompt) {
|
|
9391
9292
|
this.rl.prompt(true);
|
|
@@ -9677,18 +9578,6 @@ function createInteractiveCommand(externalEnvService) {
|
|
|
9677
9578
|
let memoryPluginInstance = null;
|
|
9678
9579
|
if (coderPluginNames.length > 0) {
|
|
9679
9580
|
try {
|
|
9680
|
-
const { globalHookManager: globalHookManager2 } = await import("@ai-setting/roy-agent-core");
|
|
9681
|
-
const { createPluginHookAdapter, createGlobalLSPManager } = await import("@ai-setting/roy-agent-coder-harness");
|
|
9682
|
-
const adapter = createPluginHookAdapter(globalHookManager2, {
|
|
9683
|
-
enableLSP: coderPluginNames.includes("lsp"),
|
|
9684
|
-
enableCodeCheck: coderPluginNames.includes("code-check"),
|
|
9685
|
-
enableReminder: coderPluginNames.includes("reminder"),
|
|
9686
|
-
enableTSLSP: coderPluginNames.includes("tslsp"),
|
|
9687
|
-
enablePylsp: coderPluginNames.includes("pylsp"),
|
|
9688
|
-
enableMdlsp: coderPluginNames.includes("mdlsp")
|
|
9689
|
-
});
|
|
9690
|
-
await adapter.initialize();
|
|
9691
|
-
pluginAdapterDispose = () => adapter.dispose();
|
|
9692
9581
|
const enabledPlugins = coderPluginNames.filter((p) => CODER_HARNESS_PLUGINS.has(p.split(":")[0]));
|
|
9693
9582
|
if (enabledPlugins.length > 0) {
|
|
9694
9583
|
console.log(`已启用插件: ${enabledPlugins.join(", ")}`);
|
|
@@ -16527,7 +16416,7 @@ var import_yaml = __toESM(require_dist(), 1);
|
|
|
16527
16416
|
import chalk55 from "chalk";
|
|
16528
16417
|
import fs5 from "fs";
|
|
16529
16418
|
import path8 from "path";
|
|
16530
|
-
import { getTracerProvider as
|
|
16419
|
+
import { getTracerProvider as getTracerProvider4, propagation, wrapFunction } from "@ai-setting/roy-agent-core";
|
|
16531
16420
|
var runWorkflow = wrapFunction(async function runWorkflowImpl(args) {
|
|
16532
16421
|
const output = new OutputService;
|
|
16533
16422
|
const envService = new EnvironmentService(output);
|
|
@@ -16548,7 +16437,7 @@ var runWorkflow = wrapFunction(async function runWorkflowImpl(args) {
|
|
|
16548
16437
|
output.info(`[OTel Trace] TRACEPARENT=${traceparent || "none"}, traceId=${traceId}, parentSpanId=${parentSpanId}`);
|
|
16549
16438
|
let workflowSpan = undefined;
|
|
16550
16439
|
try {
|
|
16551
|
-
const provider =
|
|
16440
|
+
const provider = getTracerProvider4();
|
|
16552
16441
|
await provider.initialize();
|
|
16553
16442
|
const tracer = provider.getTracer("roy-tracer");
|
|
16554
16443
|
const restoredContext = tracer.getCurrentContext();
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-setting/roy-agent-cli",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.40",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "CLI for roy-agent - Non-interactive command execution",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
"typecheck": "npx tsc --noEmit --skipLibCheck"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@ai-setting/roy-agent-coder-harness": "^1.5.
|
|
30
|
-
"@ai-setting/roy-agent-core": "^1.5.
|
|
29
|
+
"@ai-setting/roy-agent-coder-harness": "^1.5.40",
|
|
30
|
+
"@ai-setting/roy-agent-core": "^1.5.40",
|
|
31
31
|
"chalk": "^5.6.2",
|
|
32
32
|
"commander": "^14.0.3",
|
|
33
33
|
"effect": "^3.21.2",
|