@ai-setting/roy-agent-cli 1.5.39 → 1.5.41

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.
@@ -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.39",
7223
+ version: "1.5.41",
7224
7224
  type: "module",
7225
7225
  description: "CLI for roy-agent - Non-interactive command execution",
7226
7226
  main: "./dist/index.js",
@@ -7246,8 +7246,9 @@ 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.36",
7250
- "@ai-setting/roy-agent-core": "^1.5.37",
7249
+ "@ai-setting/roy-agent-coder-harness": "^1.5.41",
7250
+ "@ai-setting/roy-agent-core": "^1.5.41",
7251
+ "@ai-setting/roy-agent-ontology-harness": "^1.5.41",
7251
7252
  chalk: "^5.6.2",
7252
7253
  commander: "^14.0.3",
7253
7254
  effect: "^3.21.2",
@@ -7337,7 +7338,8 @@ import {
7337
7338
  McpComponent,
7338
7339
  CommandsComponent,
7339
7340
  MemoryComponent,
7340
- EventSourceComponent
7341
+ EventSourceComponent,
7342
+ PluginComponent
7341
7343
  } from "@ai-setting/roy-agent-core";
7342
7344
  import { WorkflowComponent } from "@ai-setting/roy-agent-core";
7343
7345
  import { MemoryPlugin } from "@ai-setting/roy-agent-core";
@@ -7404,124 +7406,6 @@ class OutputService {
7404
7406
  }
7405
7407
  }
7406
7408
 
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
7409
  // src/services/environment.service.ts
7526
7410
  var logger = createLogger("environment-service");
7527
7411
  var CLI_CONFIG_DIR_NAME = "roy-agent";
@@ -7553,6 +7437,7 @@ class EnvironmentService {
7553
7437
  memoryPlugin;
7554
7438
  eventSourceComponent;
7555
7439
  workflowComponent;
7440
+ pluginComponent;
7556
7441
  constructor(output) {
7557
7442
  this.output = output ?? new OutputService;
7558
7443
  }
@@ -7585,6 +7470,7 @@ class EnvironmentService {
7585
7470
  }
7586
7471
  async dispose() {
7587
7472
  for (const component of [
7473
+ this.pluginComponent,
7588
7474
  this.eventSourceComponent,
7589
7475
  this.memoryComponent,
7590
7476
  this.commandsComponent,
@@ -7814,20 +7700,22 @@ class EnvironmentService {
7814
7700
  env.registerComponent(memoryComponent);
7815
7701
  env.registerComponent(eventSourceComponent);
7816
7702
  env.registerComponent(workflowComponent);
7703
+ this.pluginComponent = new PluginComponent;
7704
+ const pluginComponent = this.pluginComponent;
7705
+ await pluginComponent.init({
7706
+ env,
7707
+ options: {
7708
+ configComponent
7709
+ }
7710
+ });
7711
+ env.registerComponent(pluginComponent);
7817
7712
  this.registerCommandsPromptHook(promptComponent, commandsComponent);
7818
7713
  await env.init();
7819
7714
  await env.start();
7820
7715
  agentComponent.refreshDependencies();
7821
7716
  logger.debug("[EnvironmentService] AgentComponent dependencies refreshed after env.start()");
7822
7717
  if (options?.plugins && options.plugins.length > 0) {
7823
- await this.loadComponentPlugins(options.plugins, {
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);
7718
+ await this.loadPlugins(options.plugins);
7831
7719
  }
7832
7720
  this.environment = env;
7833
7721
  return env;
@@ -7854,27 +7742,62 @@ class EnvironmentService {
7854
7742
  });
7855
7743
  this.output.info("Registered commands-prompt Hook");
7856
7744
  }
7857
- async loadComponentPlugins(pluginNames, components) {
7745
+ async loadPlugins(pluginNames) {
7858
7746
  for (const name of pluginNames) {
7859
7747
  try {
7860
- const definition = globalPluginRegistry.getComponentPlugin(name);
7861
- if (!definition) {
7862
- this.output.warn(`[EnvironmentService] Component plugin not found: ${name}`);
7863
- continue;
7864
- }
7865
- const plugin = await definition.factory();
7866
- const targetComponent = components[definition.targetComponent];
7867
- if (targetComponent && typeof targetComponent.registerPlugin === "function") {
7868
- targetComponent.registerPlugin(plugin);
7869
- const registeredPlugins = targetComponent.listPlugins?.() || [];
7870
- const isRegistered = registeredPlugins.some((p) => p.name === plugin.name);
7871
- this.output.log(`[EnvironmentService] Loaded component plugin: ${name} -> ${definition.targetComponent}`);
7872
- this.output.log(`[EnvironmentService] Plugin verified: ${isRegistered ? "YES" : "NO"} (${plugin.name} in ${definition.targetComponent})`);
7873
- } else {
7874
- this.output.warn(`[EnvironmentService] Target component not found or not registerable: ${definition.targetComponent}`);
7748
+ let plugin;
7749
+ switch (name) {
7750
+ case "task-tag": {
7751
+ const { TaskTagPlugin } = await import("@ai-setting/roy-agent-core");
7752
+ plugin = new TaskTagPlugin;
7753
+ break;
7754
+ }
7755
+ case "lsp": {
7756
+ const { LSPPlugin } = await import("@ai-setting/roy-agent-coder-harness");
7757
+ plugin = new LSPPlugin({ preloadMode: "startup" });
7758
+ break;
7759
+ }
7760
+ case "code-check": {
7761
+ const { CodeCheckPlugin } = await import("@ai-setting/roy-agent-coder-harness");
7762
+ plugin = new CodeCheckPlugin;
7763
+ break;
7764
+ }
7765
+ case "reminder": {
7766
+ const { ReminderPlugin } = await import("@ai-setting/roy-agent-coder-harness");
7767
+ plugin = new ReminderPlugin;
7768
+ break;
7769
+ }
7770
+ case "tslsp": {
7771
+ const { TSLSPPlugin } = await import("@ai-setting/roy-agent-coder-harness");
7772
+ plugin = new TSLSPPlugin({ preloadMode: "startup" });
7773
+ break;
7774
+ }
7775
+ case "pylsp": {
7776
+ const { PyLSPPlugin } = await import("@ai-setting/roy-agent-coder-harness");
7777
+ plugin = new PyLSPPlugin({ preloadMode: "startup" });
7778
+ break;
7779
+ }
7780
+ case "mdlsp": {
7781
+ const { MDLSPPlugin } = await import("@ai-setting/roy-agent-coder-harness");
7782
+ plugin = new MDLSPPlugin;
7783
+ break;
7784
+ }
7785
+ case "ontologylsp": {
7786
+ const { OntologyLSPPlugin } = await import("@ai-setting/roy-agent-ontology-harness");
7787
+ plugin = new OntologyLSPPlugin({
7788
+ preloadMode: "startup",
7789
+ workspaceRoot: process.cwd()
7790
+ });
7791
+ break;
7792
+ }
7793
+ default:
7794
+ this.output.warn(`[EnvironmentService] Unknown plugin: ${name}`);
7795
+ continue;
7875
7796
  }
7797
+ this.pluginComponent?.register(plugin);
7798
+ this.output.log(`[EnvironmentService] Registered plugin: ${name}`);
7876
7799
  } catch (error) {
7877
- this.output.error(`[EnvironmentService] Error loading component plugin "${name}": ${error}`);
7800
+ this.output.error(`[EnvironmentService] Error loading plugin "${name}": ${error}`);
7878
7801
  }
7879
7802
  }
7880
7803
  }
@@ -7892,22 +7815,6 @@ ${rows}
7892
7815
 
7893
7816
  Progressive Discovery: Run \`<command> --help\` to explore full capabilities.`;
7894
7817
  }
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
7818
  }
7912
7819
 
7913
7820
  // src/commands/act.ts
@@ -8326,7 +8233,8 @@ function createActCommand(externalEnvService) {
8326
8233
  "reminder",
8327
8234
  "tslsp",
8328
8235
  "pylsp",
8329
- "mdlsp"
8236
+ "mdlsp",
8237
+ "ontologylsp"
8330
8238
  ]);
8331
8239
  const coderPluginNames = [];
8332
8240
  const otherPluginNames = [];
@@ -8406,64 +8314,47 @@ function createActCommand(externalEnvService) {
8406
8314
  if (llmComponent && promptComponent) {
8407
8315
  sessionComponent.setSummaryComponents(promptComponent, llmComponent);
8408
8316
  }
8409
- if (coderPluginNames.length > 0) {
8317
+ if (coderPluginNames.includes("lsp")) {
8410
8318
  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
8319
  const enabledPlugins = coderPluginNames.filter((p) => CODER_HARNESS_PLUGINS.has(p.split(":")[0]));
8424
8320
  if (enabledPlugins.length > 0) {
8425
8321
  console.log(`已启用插件: ${enabledPlugins.join(", ")}`);
8426
8322
  output.success(`✅ 已启用插件: ${enabledPlugins.join(", ")}`);
8427
- if (coderPluginNames.includes("lsp") && !quiet) {
8323
+ if (!quiet) {
8428
8324
  output.info(`\uD83D\uDD27 LSP 服务预加载中,首次诊断可能需要等待...`);
8429
8325
  }
8430
8326
  }
8431
- if (coderPluginNames.includes("lsp")) {
8432
- try {
8433
- const { createLSPConfigLoader } = await import("@ai-setting/roy-agent-coder-harness");
8434
- const configLoader = createLSPConfigLoader();
8435
- const lspConfig = configLoader.load();
8327
+ const { createLSPConfigLoader } = await import("@ai-setting/roy-agent-coder-harness");
8328
+ const configLoader = createLSPConfigLoader();
8329
+ const lspConfig = configLoader.load();
8330
+ if (!quiet) {
8331
+ output.info("正在预热 LSP 服务器...");
8332
+ if (lspConfig.preload) {
8333
+ output.info("\uD83D\uDCCB 使用配置文件中的预加载设置");
8334
+ }
8335
+ }
8336
+ const { createGlobalLSPManager: createGlobalLSPManager2 } = await import("@ai-setting/roy-agent-coder-harness");
8337
+ const lspManager = createGlobalLSPManager2({
8338
+ idleTimeout: lspConfig.idleTimeout ?? 300000,
8339
+ maxConnections: lspConfig.maxConnections ?? 10,
8340
+ autoDownload: lspConfig.autoInstall ?? false,
8341
+ preloadLanguages: lspConfig.preloadLanguages
8342
+ });
8343
+ lspManager.registerShutdownHandler();
8344
+ lspManagerDispose = () => lspManager.dispose();
8345
+ if (lspConfig.preload || coderPluginNames.includes("lsp")) {
8346
+ lspManager.prewarm().then(() => {
8436
8347
  if (!quiet) {
8437
- output.info("正在预热 LSP 服务器...");
8438
- if (lspConfig.preload) {
8439
- output.info("\uD83D\uDCCB 使用配置文件中的预加载设置");
8440
- }
8348
+ output.success(" LSP 服务器预热完成");
8441
8349
  }
8442
- const lspManager = createGlobalLSPManager({
8443
- idleTimeout: lspConfig.idleTimeout ?? 300000,
8444
- maxConnections: lspConfig.maxConnections ?? 10,
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
- });
8350
+ }).catch((err) => {
8351
+ if (!quiet) {
8352
+ output.warn(`⚠ LSP 预热部分失败: ${err.message}`);
8460
8353
  }
8461
- } catch (error) {
8462
- output.warn(`⚠ LSP 预热失败: ${error}`);
8463
- }
8354
+ });
8464
8355
  }
8465
8356
  } catch (error) {
8466
- output.error(`❌ 加载 coder-harness 插件失败: ${error}`);
8357
+ output.warn(`⚠ LSP 预热失败: ${error}`);
8467
8358
  }
8468
8359
  }
8469
8360
  const streamService = new StreamOutputService({
@@ -8654,8 +8545,7 @@ class SessionManager {
8654
8545
 
8655
8546
  // src/commands/shared/query-executor.ts
8656
8547
  init_stream_output_service();
8657
- import { ContextError as ContextError3, ErrorCodes as ErrorCodes3, getTracerProvider as getTracerProvider3 } from "@ai-setting/roy-agent-core";
8658
-
8548
+ import { ContextError as ContextError3, ErrorCodes as ErrorCodes3, TracedAs as TracedAs2 } from "@ai-setting/roy-agent-core";
8659
8549
  class QueryExecutor {
8660
8550
  env;
8661
8551
  sessionComponent;
@@ -8757,33 +8647,16 @@ class QueryExecutor {
8757
8647
  },
8758
8648
  ...agentContext
8759
8649
  };
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
8650
  let result;
8771
8651
  try {
8772
8652
  result = await contextHandler.handleQueryWithContext(message, context);
8773
- if (span) {
8774
- span.end(result);
8775
- }
8776
8653
  } 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
8654
  if (error instanceof ContextError3 && error.code === ErrorCodes3.CONTEXT_THRESHOLD_EXCEEDED) {
8782
8655
  this.output.error(`上下文阈值超出限制: ${error.usage?.totalTokens}/${error.contextWindow}`);
8783
8656
  this.output.info("请手动压缩会话: roy-agent sessions compact " + sessionId);
8784
8657
  }
8785
8658
  throw error;
8786
- } finally {}
8659
+ }
8787
8660
  if (!this.quiet) {
8788
8661
  this.output.success("执行完成");
8789
8662
  }
@@ -8836,6 +8709,18 @@ class QueryExecutor {
8836
8709
  }
8837
8710
  }
8838
8711
  }
8712
+ __legacyDecorateClassTS([
8713
+ TracedAs2("cli.query-executor.execute", { recordParams: true, log: true }),
8714
+ __legacyMetadataTS("design:type", Function),
8715
+ __legacyMetadataTS("design:paramtypes", [
8716
+ String,
8717
+ String,
8718
+ typeof Partial === "undefined" ? Object : Partial,
8719
+ String,
8720
+ Object
8721
+ ]),
8722
+ __legacyMetadataTS("design:returntype", typeof Promise === "undefined" ? Object : Promise)
8723
+ ], QueryExecutor.prototype, "execute", null);
8839
8724
 
8840
8725
  // src/commands/shared/event-message-formatter.ts
8841
8726
  var TaskEventTypes = {
@@ -8970,6 +8855,7 @@ class EventMessageFormatter {
8970
8855
  }
8971
8856
 
8972
8857
  // src/commands/shared/event-handler.ts
8858
+ import { TracedAs as TracedAs3 } from "@ai-setting/roy-agent-core";
8973
8859
  class EventHandler {
8974
8860
  env;
8975
8861
  eventTypes;
@@ -9080,10 +8966,18 @@ class EventHandler {
9080
8966
  return new Promise((resolve) => setTimeout(resolve, ms));
9081
8967
  }
9082
8968
  }
8969
+ __legacyDecorateClassTS([
8970
+ TracedAs3("cli.event-handler.handleEvent", { recordParams: true }),
8971
+ __legacyMetadataTS("design:type", Function),
8972
+ __legacyMetadataTS("design:paramtypes", [
8973
+ typeof EnvEvent === "undefined" ? Object : EnvEvent
8974
+ ]),
8975
+ __legacyMetadataTS("design:returntype", undefined)
8976
+ ], EventHandler.prototype, "handleEvent", null);
9083
8977
 
9084
8978
  // src/commands/interactive.ts
9085
8979
  init_stream_output_service();
9086
- import { createLogger as createLogger4, getTracerProvider as getTracerProvider4 } from "@ai-setting/roy-agent-core";
8980
+ import { createLogger as createLogger4, getTracerProvider as getTracerProvider3 } from "@ai-setting/roy-agent-core";
9087
8981
 
9088
8982
  // src/commands/input-handler.ts
9089
8983
  class InputHandler {
@@ -9343,11 +9237,14 @@ ${COLORS.system("[通知2] ❯ " + message.replace(/\n/g, `
9343
9237
  ` + COLORS.system("[通知2] ❯ ")))}
9344
9238
  `);
9345
9239
  const sourceId = envEvent.metadata?.sourceId;
9346
- const plugins = envEvent.metadata?.plugins || [];
9347
- const pluginEnabled = {};
9348
- for (const pluginName of plugins) {
9349
- const key = `${sourceId}:${pluginName}`;
9350
- pluginEnabled[key] = true;
9240
+ let pluginEnabled = envEvent.metadata?.pluginEnabled;
9241
+ let plugins = envEvent.metadata?.plugins;
9242
+ if (!pluginEnabled || Object.keys(pluginEnabled).length === 0) {
9243
+ pluginEnabled = {};
9244
+ for (const pluginName of plugins || []) {
9245
+ const key = `${sourceId}:${pluginName}`;
9246
+ pluginEnabled[key] = true;
9247
+ }
9351
9248
  }
9352
9249
  this.currentAgentContext = {
9353
9250
  pluginEnabled,
@@ -9365,11 +9262,21 @@ ${COLORS.system("[通知2] ❯ " + message.replace(/\n/g, `
9365
9262
  const agentContext = this.currentAgentContext;
9366
9263
  this.currentAgentContext = undefined;
9367
9264
  resetStreamAbort();
9368
- const provider = getTracerProvider4();
9265
+ const provider = getTracerProvider3();
9369
9266
  const tracer = provider.getTracer("roy-tracer");
9370
- const rootSpan = tracer.startSpan("interactive.execute");
9371
- const traceId = rootSpan.spanContext.traceId;
9372
- provider.setGlobalContext(rootSpan.spanContext);
9267
+ const existingContext = provider.getGlobalContext();
9268
+ let rootSpan;
9269
+ let traceId;
9270
+ if (existingContext) {
9271
+ rootSpan = tracer.startSpan("interactive.execute", {
9272
+ parent: existingContext
9273
+ });
9274
+ traceId = existingContext.traceId;
9275
+ } else {
9276
+ rootSpan = tracer.startSpan("interactive.execute");
9277
+ traceId = rootSpan.spanContext.traceId;
9278
+ provider.setGlobalContext(rootSpan.spanContext);
9279
+ }
9373
9280
  console.log(`${COLORS.system("[Trace] " + traceId)}`);
9374
9281
  console.log(`${COLORS.progress("[thinking...]")}`);
9375
9282
  try {
@@ -9385,8 +9292,12 @@ ${COLORS.error("❌ 执行失败: " + error)}
9385
9292
  rootSpan.setAttribute("error", String(error));
9386
9293
  }
9387
9294
  } finally {
9388
- provider.setGlobalContext(undefined);
9389
9295
  rootSpan.end();
9296
+ if (existingContext) {
9297
+ provider.setGlobalContext(existingContext);
9298
+ } else {
9299
+ provider.setGlobalContext(undefined);
9300
+ }
9390
9301
  this.isExecuting = false;
9391
9302
  if (options.showPrompt) {
9392
9303
  this.rl.prompt(true);
@@ -9621,7 +9532,8 @@ function createInteractiveCommand(externalEnvService) {
9621
9532
  "reminder",
9622
9533
  "tslsp",
9623
9534
  "pylsp",
9624
- "mdlsp"
9535
+ "mdlsp",
9536
+ "ontologylsp"
9625
9537
  ]);
9626
9538
  const rawPlugins = args.plugin;
9627
9539
  const pluginNames = Array.isArray(rawPlugins) ? rawPlugins : rawPlugins ? [rawPlugins] : [];
@@ -9639,7 +9551,7 @@ function createInteractiveCommand(externalEnvService) {
9639
9551
  if (!externalEnvService) {
9640
9552
  await envService.create({
9641
9553
  configPath: args.config,
9642
- plugins: componentPluginNames
9554
+ plugins: [...componentPluginNames, ...coderPluginNames]
9643
9555
  });
9644
9556
  }
9645
9557
  const env = envService.getEnvironment();
@@ -9678,18 +9590,6 @@ function createInteractiveCommand(externalEnvService) {
9678
9590
  let memoryPluginInstance = null;
9679
9591
  if (coderPluginNames.length > 0) {
9680
9592
  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
9593
  const enabledPlugins = coderPluginNames.filter((p) => CODER_HARNESS_PLUGINS.has(p.split(":")[0]));
9694
9594
  if (enabledPlugins.length > 0) {
9695
9595
  console.log(`已启用插件: ${enabledPlugins.join(", ")}`);
@@ -16528,7 +16428,7 @@ var import_yaml = __toESM(require_dist(), 1);
16528
16428
  import chalk55 from "chalk";
16529
16429
  import fs5 from "fs";
16530
16430
  import path8 from "path";
16531
- import { getTracerProvider as getTracerProvider5, propagation, wrapFunction } from "@ai-setting/roy-agent-core";
16431
+ import { getTracerProvider as getTracerProvider4, propagation, wrapFunction } from "@ai-setting/roy-agent-core";
16532
16432
  var runWorkflow = wrapFunction(async function runWorkflowImpl(args) {
16533
16433
  const output = new OutputService;
16534
16434
  const envService = new EnvironmentService(output);
@@ -16549,7 +16449,7 @@ var runWorkflow = wrapFunction(async function runWorkflowImpl(args) {
16549
16449
  output.info(`[OTel Trace] TRACEPARENT=${traceparent || "none"}, traceId=${traceId}, parentSpanId=${parentSpanId}`);
16550
16450
  let workflowSpan = undefined;
16551
16451
  try {
16552
- const provider = getTracerProvider5();
16452
+ const provider = getTracerProvider4();
16553
16453
  await provider.initialize();
16554
16454
  const tracer = provider.getTracer("roy-tracer");
16555
16455
  const restoredContext = tracer.getCurrentContext();
@@ -17689,6 +17589,9 @@ Plugins:
17689
17589
  pylsp Python LSP (diagnostics, completions)
17690
17590
  mdlsp Markdown LSP (diagnostics, wikilink checking)
17691
17591
 
17592
+ ontology-harness plugins:
17593
+ ontologylsp Typed Markdown Ontology (markdown LSP + TM001-TM006 constraints)
17594
+
17692
17595
  coder-harness plugins:
17693
17596
  code-check External command code checking (linter + type check)
17694
17597
  reminder Max iterations reminder for ReAct loop
@@ -17701,6 +17604,7 @@ Examples:
17701
17604
  --plugin pylsp Enable Python LSP
17702
17605
  --plugin mdlsp Enable Markdown LSP
17703
17606
  --plugin tslsp pylsp mdlsp Enable all LSP plugins
17607
+ --plugin ontologylsp Enable Typed Markdown Ontology checking
17704
17608
  --plugin lsp Enable all (legacy mode)
17705
17609
  --plugin code-check Enable external command checking
17706
17610
  --plugin reminder Enable iteration reminder
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.39",
7222
+ version: "1.5.41",
7223
7223
  type: "module",
7224
7224
  description: "CLI for roy-agent - Non-interactive command execution",
7225
7225
  main: "./dist/index.js",
@@ -7245,8 +7245,9 @@ 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.36",
7249
- "@ai-setting/roy-agent-core": "^1.5.37",
7248
+ "@ai-setting/roy-agent-coder-harness": "^1.5.41",
7249
+ "@ai-setting/roy-agent-core": "^1.5.41",
7250
+ "@ai-setting/roy-agent-ontology-harness": "^1.5.41",
7250
7251
  chalk: "^5.6.2",
7251
7252
  commander: "^14.0.3",
7252
7253
  effect: "^3.21.2",
@@ -7336,7 +7337,8 @@ import {
7336
7337
  McpComponent,
7337
7338
  CommandsComponent,
7338
7339
  MemoryComponent,
7339
- EventSourceComponent
7340
+ EventSourceComponent,
7341
+ PluginComponent
7340
7342
  } from "@ai-setting/roy-agent-core";
7341
7343
  import { WorkflowComponent } from "@ai-setting/roy-agent-core";
7342
7344
  import { MemoryPlugin } from "@ai-setting/roy-agent-core";
@@ -7403,124 +7405,6 @@ class OutputService {
7403
7405
  }
7404
7406
  }
7405
7407
 
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
7408
  // src/services/environment.service.ts
7525
7409
  var logger = createLogger("environment-service");
7526
7410
  var CLI_CONFIG_DIR_NAME = "roy-agent";
@@ -7552,6 +7436,7 @@ class EnvironmentService {
7552
7436
  memoryPlugin;
7553
7437
  eventSourceComponent;
7554
7438
  workflowComponent;
7439
+ pluginComponent;
7555
7440
  constructor(output) {
7556
7441
  this.output = output ?? new OutputService;
7557
7442
  }
@@ -7584,6 +7469,7 @@ class EnvironmentService {
7584
7469
  }
7585
7470
  async dispose() {
7586
7471
  for (const component of [
7472
+ this.pluginComponent,
7587
7473
  this.eventSourceComponent,
7588
7474
  this.memoryComponent,
7589
7475
  this.commandsComponent,
@@ -7813,20 +7699,22 @@ class EnvironmentService {
7813
7699
  env.registerComponent(memoryComponent);
7814
7700
  env.registerComponent(eventSourceComponent);
7815
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);
7816
7711
  this.registerCommandsPromptHook(promptComponent, commandsComponent);
7817
7712
  await env.init();
7818
7713
  await env.start();
7819
7714
  agentComponent.refreshDependencies();
7820
7715
  logger.debug("[EnvironmentService] AgentComponent dependencies refreshed after env.start()");
7821
7716
  if (options?.plugins && options.plugins.length > 0) {
7822
- await this.loadComponentPlugins(options.plugins, {
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);
7717
+ await this.loadPlugins(options.plugins);
7830
7718
  }
7831
7719
  this.environment = env;
7832
7720
  return env;
@@ -7853,27 +7741,62 @@ class EnvironmentService {
7853
7741
  });
7854
7742
  this.output.info("Registered commands-prompt Hook");
7855
7743
  }
7856
- async loadComponentPlugins(pluginNames, components) {
7744
+ async loadPlugins(pluginNames) {
7857
7745
  for (const name of pluginNames) {
7858
7746
  try {
7859
- const definition = globalPluginRegistry.getComponentPlugin(name);
7860
- if (!definition) {
7861
- this.output.warn(`[EnvironmentService] Component plugin not found: ${name}`);
7862
- continue;
7863
- }
7864
- const plugin = await definition.factory();
7865
- const targetComponent = components[definition.targetComponent];
7866
- if (targetComponent && typeof targetComponent.registerPlugin === "function") {
7867
- targetComponent.registerPlugin(plugin);
7868
- const registeredPlugins = targetComponent.listPlugins?.() || [];
7869
- const isRegistered = registeredPlugins.some((p) => p.name === plugin.name);
7870
- this.output.log(`[EnvironmentService] Loaded component plugin: ${name} -> ${definition.targetComponent}`);
7871
- this.output.log(`[EnvironmentService] Plugin verified: ${isRegistered ? "YES" : "NO"} (${plugin.name} in ${definition.targetComponent})`);
7872
- } else {
7873
- this.output.warn(`[EnvironmentService] Target component not found or not registerable: ${definition.targetComponent}`);
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
+ case "ontologylsp": {
7785
+ const { OntologyLSPPlugin } = await import("@ai-setting/roy-agent-ontology-harness");
7786
+ plugin = new OntologyLSPPlugin({
7787
+ preloadMode: "startup",
7788
+ workspaceRoot: process.cwd()
7789
+ });
7790
+ break;
7791
+ }
7792
+ default:
7793
+ this.output.warn(`[EnvironmentService] Unknown plugin: ${name}`);
7794
+ continue;
7874
7795
  }
7796
+ this.pluginComponent?.register(plugin);
7797
+ this.output.log(`[EnvironmentService] Registered plugin: ${name}`);
7875
7798
  } catch (error) {
7876
- this.output.error(`[EnvironmentService] Error loading component plugin "${name}": ${error}`);
7799
+ this.output.error(`[EnvironmentService] Error loading plugin "${name}": ${error}`);
7877
7800
  }
7878
7801
  }
7879
7802
  }
@@ -7891,22 +7814,6 @@ ${rows}
7891
7814
 
7892
7815
  Progressive Discovery: Run \`<command> --help\` to explore full capabilities.`;
7893
7816
  }
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
7817
  }
7911
7818
 
7912
7819
  // src/commands/act.ts
@@ -8325,7 +8232,8 @@ function createActCommand(externalEnvService) {
8325
8232
  "reminder",
8326
8233
  "tslsp",
8327
8234
  "pylsp",
8328
- "mdlsp"
8235
+ "mdlsp",
8236
+ "ontologylsp"
8329
8237
  ]);
8330
8238
  const coderPluginNames = [];
8331
8239
  const otherPluginNames = [];
@@ -8405,64 +8313,47 @@ function createActCommand(externalEnvService) {
8405
8313
  if (llmComponent && promptComponent) {
8406
8314
  sessionComponent.setSummaryComponents(promptComponent, llmComponent);
8407
8315
  }
8408
- if (coderPluginNames.length > 0) {
8316
+ if (coderPluginNames.includes("lsp")) {
8409
8317
  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
8318
  const enabledPlugins = coderPluginNames.filter((p) => CODER_HARNESS_PLUGINS.has(p.split(":")[0]));
8423
8319
  if (enabledPlugins.length > 0) {
8424
8320
  console.log(`已启用插件: ${enabledPlugins.join(", ")}`);
8425
8321
  output.success(`✅ 已启用插件: ${enabledPlugins.join(", ")}`);
8426
- if (coderPluginNames.includes("lsp") && !quiet) {
8322
+ if (!quiet) {
8427
8323
  output.info(`\uD83D\uDD27 LSP 服务预加载中,首次诊断可能需要等待...`);
8428
8324
  }
8429
8325
  }
8430
- if (coderPluginNames.includes("lsp")) {
8431
- try {
8432
- const { createLSPConfigLoader } = await import("@ai-setting/roy-agent-coder-harness");
8433
- const configLoader = createLSPConfigLoader();
8434
- const lspConfig = configLoader.load();
8326
+ const { createLSPConfigLoader } = await import("@ai-setting/roy-agent-coder-harness");
8327
+ const configLoader = createLSPConfigLoader();
8328
+ const lspConfig = configLoader.load();
8329
+ if (!quiet) {
8330
+ output.info("正在预热 LSP 服务器...");
8331
+ if (lspConfig.preload) {
8332
+ output.info("\uD83D\uDCCB 使用配置文件中的预加载设置");
8333
+ }
8334
+ }
8335
+ const { createGlobalLSPManager: createGlobalLSPManager2 } = await import("@ai-setting/roy-agent-coder-harness");
8336
+ const lspManager = createGlobalLSPManager2({
8337
+ idleTimeout: lspConfig.idleTimeout ?? 300000,
8338
+ maxConnections: lspConfig.maxConnections ?? 10,
8339
+ autoDownload: lspConfig.autoInstall ?? false,
8340
+ preloadLanguages: lspConfig.preloadLanguages
8341
+ });
8342
+ lspManager.registerShutdownHandler();
8343
+ lspManagerDispose = () => lspManager.dispose();
8344
+ if (lspConfig.preload || coderPluginNames.includes("lsp")) {
8345
+ lspManager.prewarm().then(() => {
8435
8346
  if (!quiet) {
8436
- output.info("正在预热 LSP 服务器...");
8437
- if (lspConfig.preload) {
8438
- output.info("\uD83D\uDCCB 使用配置文件中的预加载设置");
8439
- }
8347
+ output.success(" LSP 服务器预热完成");
8440
8348
  }
8441
- const lspManager = createGlobalLSPManager({
8442
- idleTimeout: lspConfig.idleTimeout ?? 300000,
8443
- maxConnections: lspConfig.maxConnections ?? 10,
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
- });
8349
+ }).catch((err) => {
8350
+ if (!quiet) {
8351
+ output.warn(`⚠ LSP 预热部分失败: ${err.message}`);
8459
8352
  }
8460
- } catch (error) {
8461
- output.warn(`⚠ LSP 预热失败: ${error}`);
8462
- }
8353
+ });
8463
8354
  }
8464
8355
  } catch (error) {
8465
- output.error(`❌ 加载 coder-harness 插件失败: ${error}`);
8356
+ output.warn(`⚠ LSP 预热失败: ${error}`);
8466
8357
  }
8467
8358
  }
8468
8359
  const streamService = new StreamOutputService({
@@ -8653,8 +8544,7 @@ class SessionManager {
8653
8544
 
8654
8545
  // src/commands/shared/query-executor.ts
8655
8546
  init_stream_output_service();
8656
- import { ContextError as ContextError3, ErrorCodes as ErrorCodes3, getTracerProvider as getTracerProvider3 } from "@ai-setting/roy-agent-core";
8657
-
8547
+ import { ContextError as ContextError3, ErrorCodes as ErrorCodes3, TracedAs as TracedAs2 } from "@ai-setting/roy-agent-core";
8658
8548
  class QueryExecutor {
8659
8549
  env;
8660
8550
  sessionComponent;
@@ -8756,33 +8646,16 @@ class QueryExecutor {
8756
8646
  },
8757
8647
  ...agentContext
8758
8648
  };
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
8649
  let result;
8770
8650
  try {
8771
8651
  result = await contextHandler.handleQueryWithContext(message, context);
8772
- if (span) {
8773
- span.end(result);
8774
- }
8775
8652
  } 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
8653
  if (error instanceof ContextError3 && error.code === ErrorCodes3.CONTEXT_THRESHOLD_EXCEEDED) {
8781
8654
  this.output.error(`上下文阈值超出限制: ${error.usage?.totalTokens}/${error.contextWindow}`);
8782
8655
  this.output.info("请手动压缩会话: roy-agent sessions compact " + sessionId);
8783
8656
  }
8784
8657
  throw error;
8785
- } finally {}
8658
+ }
8786
8659
  if (!this.quiet) {
8787
8660
  this.output.success("执行完成");
8788
8661
  }
@@ -8835,6 +8708,18 @@ class QueryExecutor {
8835
8708
  }
8836
8709
  }
8837
8710
  }
8711
+ __legacyDecorateClassTS([
8712
+ TracedAs2("cli.query-executor.execute", { recordParams: true, log: true }),
8713
+ __legacyMetadataTS("design:type", Function),
8714
+ __legacyMetadataTS("design:paramtypes", [
8715
+ String,
8716
+ String,
8717
+ typeof Partial === "undefined" ? Object : Partial,
8718
+ String,
8719
+ Object
8720
+ ]),
8721
+ __legacyMetadataTS("design:returntype", typeof Promise === "undefined" ? Object : Promise)
8722
+ ], QueryExecutor.prototype, "execute", null);
8838
8723
 
8839
8724
  // src/commands/shared/event-message-formatter.ts
8840
8725
  var TaskEventTypes = {
@@ -8969,6 +8854,7 @@ class EventMessageFormatter {
8969
8854
  }
8970
8855
 
8971
8856
  // src/commands/shared/event-handler.ts
8857
+ import { TracedAs as TracedAs3 } from "@ai-setting/roy-agent-core";
8972
8858
  class EventHandler {
8973
8859
  env;
8974
8860
  eventTypes;
@@ -9079,10 +8965,18 @@ class EventHandler {
9079
8965
  return new Promise((resolve) => setTimeout(resolve, ms));
9080
8966
  }
9081
8967
  }
8968
+ __legacyDecorateClassTS([
8969
+ TracedAs3("cli.event-handler.handleEvent", { recordParams: true }),
8970
+ __legacyMetadataTS("design:type", Function),
8971
+ __legacyMetadataTS("design:paramtypes", [
8972
+ typeof EnvEvent === "undefined" ? Object : EnvEvent
8973
+ ]),
8974
+ __legacyMetadataTS("design:returntype", undefined)
8975
+ ], EventHandler.prototype, "handleEvent", null);
9082
8976
 
9083
8977
  // src/commands/interactive.ts
9084
8978
  init_stream_output_service();
9085
- import { createLogger as createLogger4, getTracerProvider as getTracerProvider4 } from "@ai-setting/roy-agent-core";
8979
+ import { createLogger as createLogger4, getTracerProvider as getTracerProvider3 } from "@ai-setting/roy-agent-core";
9086
8980
 
9087
8981
  // src/commands/input-handler.ts
9088
8982
  class InputHandler {
@@ -9342,11 +9236,14 @@ ${COLORS.system("[通知2] ❯ " + message.replace(/\n/g, `
9342
9236
  ` + COLORS.system("[通知2] ❯ ")))}
9343
9237
  `);
9344
9238
  const sourceId = envEvent.metadata?.sourceId;
9345
- const plugins = envEvent.metadata?.plugins || [];
9346
- const pluginEnabled = {};
9347
- for (const pluginName of plugins) {
9348
- const key = `${sourceId}:${pluginName}`;
9349
- pluginEnabled[key] = true;
9239
+ let pluginEnabled = envEvent.metadata?.pluginEnabled;
9240
+ let plugins = envEvent.metadata?.plugins;
9241
+ if (!pluginEnabled || Object.keys(pluginEnabled).length === 0) {
9242
+ pluginEnabled = {};
9243
+ for (const pluginName of plugins || []) {
9244
+ const key = `${sourceId}:${pluginName}`;
9245
+ pluginEnabled[key] = true;
9246
+ }
9350
9247
  }
9351
9248
  this.currentAgentContext = {
9352
9249
  pluginEnabled,
@@ -9364,11 +9261,21 @@ ${COLORS.system("[通知2] ❯ " + message.replace(/\n/g, `
9364
9261
  const agentContext = this.currentAgentContext;
9365
9262
  this.currentAgentContext = undefined;
9366
9263
  resetStreamAbort();
9367
- const provider = getTracerProvider4();
9264
+ const provider = getTracerProvider3();
9368
9265
  const tracer = provider.getTracer("roy-tracer");
9369
- const rootSpan = tracer.startSpan("interactive.execute");
9370
- const traceId = rootSpan.spanContext.traceId;
9371
- provider.setGlobalContext(rootSpan.spanContext);
9266
+ const existingContext = provider.getGlobalContext();
9267
+ let rootSpan;
9268
+ let traceId;
9269
+ if (existingContext) {
9270
+ rootSpan = tracer.startSpan("interactive.execute", {
9271
+ parent: existingContext
9272
+ });
9273
+ traceId = existingContext.traceId;
9274
+ } else {
9275
+ rootSpan = tracer.startSpan("interactive.execute");
9276
+ traceId = rootSpan.spanContext.traceId;
9277
+ provider.setGlobalContext(rootSpan.spanContext);
9278
+ }
9372
9279
  console.log(`${COLORS.system("[Trace] " + traceId)}`);
9373
9280
  console.log(`${COLORS.progress("[thinking...]")}`);
9374
9281
  try {
@@ -9384,8 +9291,12 @@ ${COLORS.error("❌ 执行失败: " + error)}
9384
9291
  rootSpan.setAttribute("error", String(error));
9385
9292
  }
9386
9293
  } finally {
9387
- provider.setGlobalContext(undefined);
9388
9294
  rootSpan.end();
9295
+ if (existingContext) {
9296
+ provider.setGlobalContext(existingContext);
9297
+ } else {
9298
+ provider.setGlobalContext(undefined);
9299
+ }
9389
9300
  this.isExecuting = false;
9390
9301
  if (options.showPrompt) {
9391
9302
  this.rl.prompt(true);
@@ -9620,7 +9531,8 @@ function createInteractiveCommand(externalEnvService) {
9620
9531
  "reminder",
9621
9532
  "tslsp",
9622
9533
  "pylsp",
9623
- "mdlsp"
9534
+ "mdlsp",
9535
+ "ontologylsp"
9624
9536
  ]);
9625
9537
  const rawPlugins = args.plugin;
9626
9538
  const pluginNames = Array.isArray(rawPlugins) ? rawPlugins : rawPlugins ? [rawPlugins] : [];
@@ -9638,7 +9550,7 @@ function createInteractiveCommand(externalEnvService) {
9638
9550
  if (!externalEnvService) {
9639
9551
  await envService.create({
9640
9552
  configPath: args.config,
9641
- plugins: componentPluginNames
9553
+ plugins: [...componentPluginNames, ...coderPluginNames]
9642
9554
  });
9643
9555
  }
9644
9556
  const env = envService.getEnvironment();
@@ -9677,18 +9589,6 @@ function createInteractiveCommand(externalEnvService) {
9677
9589
  let memoryPluginInstance = null;
9678
9590
  if (coderPluginNames.length > 0) {
9679
9591
  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
9592
  const enabledPlugins = coderPluginNames.filter((p) => CODER_HARNESS_PLUGINS.has(p.split(":")[0]));
9693
9593
  if (enabledPlugins.length > 0) {
9694
9594
  console.log(`已启用插件: ${enabledPlugins.join(", ")}`);
@@ -16527,7 +16427,7 @@ var import_yaml = __toESM(require_dist(), 1);
16527
16427
  import chalk55 from "chalk";
16528
16428
  import fs5 from "fs";
16529
16429
  import path8 from "path";
16530
- import { getTracerProvider as getTracerProvider5, propagation, wrapFunction } from "@ai-setting/roy-agent-core";
16430
+ import { getTracerProvider as getTracerProvider4, propagation, wrapFunction } from "@ai-setting/roy-agent-core";
16531
16431
  var runWorkflow = wrapFunction(async function runWorkflowImpl(args) {
16532
16432
  const output = new OutputService;
16533
16433
  const envService = new EnvironmentService(output);
@@ -16548,7 +16448,7 @@ var runWorkflow = wrapFunction(async function runWorkflowImpl(args) {
16548
16448
  output.info(`[OTel Trace] TRACEPARENT=${traceparent || "none"}, traceId=${traceId}, parentSpanId=${parentSpanId}`);
16549
16449
  let workflowSpan = undefined;
16550
16450
  try {
16551
- const provider = getTracerProvider5();
16451
+ const provider = getTracerProvider4();
16552
16452
  await provider.initialize();
16553
16453
  const tracer = provider.getTracer("roy-tracer");
16554
16454
  const restoredContext = tracer.getCurrentContext();
@@ -17688,6 +17588,9 @@ Plugins:
17688
17588
  pylsp Python LSP (diagnostics, completions)
17689
17589
  mdlsp Markdown LSP (diagnostics, wikilink checking)
17690
17590
 
17591
+ ontology-harness plugins:
17592
+ ontologylsp Typed Markdown Ontology (markdown LSP + TM001-TM006 constraints)
17593
+
17691
17594
  coder-harness plugins:
17692
17595
  code-check External command code checking (linter + type check)
17693
17596
  reminder Max iterations reminder for ReAct loop
@@ -17700,6 +17603,7 @@ Examples:
17700
17603
  --plugin pylsp Enable Python LSP
17701
17604
  --plugin mdlsp Enable Markdown LSP
17702
17605
  --plugin tslsp pylsp mdlsp Enable all LSP plugins
17606
+ --plugin ontologylsp Enable Typed Markdown Ontology checking
17703
17607
  --plugin lsp Enable all (legacy mode)
17704
17608
  --plugin code-check Enable external command checking
17705
17609
  --plugin reminder Enable iteration reminder
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-setting/roy-agent-cli",
3
- "version": "1.5.39",
3
+ "version": "1.5.41",
4
4
  "type": "module",
5
5
  "description": "CLI for roy-agent - Non-interactive command execution",
6
6
  "main": "./dist/index.js",
@@ -26,8 +26,9 @@
26
26
  "typecheck": "npx tsc --noEmit --skipLibCheck"
27
27
  },
28
28
  "dependencies": {
29
- "@ai-setting/roy-agent-coder-harness": "^1.5.36",
30
- "@ai-setting/roy-agent-core": "^1.5.37",
29
+ "@ai-setting/roy-agent-coder-harness": "^1.5.41",
30
+ "@ai-setting/roy-agent-core": "^1.5.41",
31
+ "@ai-setting/roy-agent-ontology-harness": "^1.5.41",
31
32
  "chalk": "^5.6.2",
32
33
  "commander": "^14.0.3",
33
34
  "effect": "^3.21.2",