@massa-ai/opencode-plugin 1.7.1 → 1.9.0

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.
@@ -542,6 +542,9 @@ var init_massa_ai_config = __esm(() => {
542
542
  },
543
543
  handoffs: {
544
544
  enabled: true
545
+ },
546
+ security: {
547
+ corsOrigins: []
545
548
  }
546
549
  };
547
550
  });
@@ -563,6 +566,7 @@ __export(exports_config_loader, {
563
566
  import fs from "fs";
564
567
  import path3 from "path";
565
568
  import os2 from "os";
569
+ import crypto from "crypto";
566
570
  function getConfigDir() {
567
571
  return CONFIG_DIR;
568
572
  }
@@ -591,7 +595,8 @@ function loadConfig() {
591
595
  llm: { ...defaultMassaAiConfig.llm, ...userConfig.llm },
592
596
  memory: { ...defaultMassaAiConfig.memory, ...userConfig.memory },
593
597
  hooks: { ...defaultMassaAiConfig.hooks, ...userConfig.hooks },
594
- handoffs: { ...defaultMassaAiConfig.handoffs, ...userConfig.handoffs }
598
+ handoffs: { ...defaultMassaAiConfig.handoffs, ...userConfig.handoffs },
599
+ security: { ...defaultMassaAiConfig.security, ...userConfig.security }
595
600
  };
596
601
  } catch (error) {
597
602
  console.error(`Error loading config from ${CONFIG_FILE}:`, error);
@@ -635,7 +640,17 @@ function saveConfig(config) {
635
640
  if (!fs.existsSync(CONFIG_DIR)) {
636
641
  fs.mkdirSync(CONFIG_DIR, { recursive: true });
637
642
  }
638
- fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2));
643
+ const unique = `${process.pid}.${++tempFileCounter}.${crypto.randomBytes(6).toString("hex")}`;
644
+ const tempFile = path3.join(CONFIG_DIR, `.config.json.${unique}.tmp`);
645
+ try {
646
+ fs.writeFileSync(tempFile, JSON.stringify(config, null, 2));
647
+ fs.renameSync(tempFile, CONFIG_FILE);
648
+ } catch (error) {
649
+ try {
650
+ fs.unlinkSync(tempFile);
651
+ } catch {}
652
+ throw error;
653
+ }
639
654
  }
640
655
  function initConfig() {
641
656
  if (!fs.existsSync(CONFIG_FILE)) {
@@ -663,7 +678,7 @@ function getConfigForEnv() {
663
678
  env.ENABLE_METRICS = String(config.logging.enableMetrics);
664
679
  return env;
665
680
  }
666
- var CONFIG_DIR, CONFIG_FILE, migrationAttempted = false;
681
+ var CONFIG_DIR, CONFIG_FILE, migrationAttempted = false, tempFileCounter = 0;
667
682
  var init_config_loader = __esm(() => {
668
683
  init_massa_ai_config();
669
684
  init_xdg();
@@ -698,12 +713,16 @@ try {
698
713
  if (cfg.database?.url && !process.env.DATABASE_URL) {
699
714
  process.env.DATABASE_URL = cfg.database.url;
700
715
  }
701
- if (cfg.llm?.apiKey && !process.env.RLM_LLM_API_KEY) {
702
- process.env.RLM_LLM_API_KEY = cfg.llm.apiKey;
716
+ if (cfg.llm?.apiKey && !process.env.MASSA_AI_LLM_API_KEY) {
717
+ process.env.MASSA_AI_LLM_API_KEY = cfg.llm.apiKey;
703
718
  }
704
719
  if (cfg.embedding?.apiKey && !process.env.OLLAMA_API_KEY) {
705
720
  process.env.OLLAMA_API_KEY = cfg.embedding.apiKey;
706
721
  }
722
+ const securityApiKey = cfg.security?.apiKey?.trim();
723
+ if (securityApiKey && !process.env.MASSA_AI_API_KEY?.trim()) {
724
+ process.env.MASSA_AI_API_KEY = securityApiKey;
725
+ }
707
726
  } catch {}
708
727
 
709
728
  // ../../packages/shared/dist/config/index.js
@@ -711,6 +730,11 @@ init_config_loader();
711
730
  init_massa_ai_config();
712
731
  init_config_loader();
713
732
  import path4 from "path";
733
+
734
+ // ../../packages/shared/dist/config/api-key.js
735
+ init_config_loader();
736
+
737
+ // ../../packages/shared/dist/config/index.js
714
738
  var DEFAULT_LLM_MODEL = "qwen2.5:7b-instruct";
715
739
  var DEFAULT_LLM_CODE_MODEL = "qwen2.5-coder:7b";
716
740
  function envNum(key, fallback) {
@@ -735,6 +759,13 @@ function envString(key, fallback) {
735
759
  const s = process.env[key];
736
760
  return s === undefined || s === "" ? fallback : s;
737
761
  }
762
+ function envList(key, fallback) {
763
+ const s = process.env[key];
764
+ if (s === undefined)
765
+ return fallback;
766
+ const parsed = s.split(",").map((v) => v.trim()).filter((v) => v.length > 0);
767
+ return parsed.length > 0 ? parsed : fallback;
768
+ }
738
769
  var MAX_IGNORE_PATTERNS = 1024;
739
770
  function validateCapturePolicyConfig(raw) {
740
771
  if (!raw || typeof raw !== "object")
@@ -855,15 +886,15 @@ var defaultConfig = {
855
886
  }
856
887
  },
857
888
  llm: {
858
- enabled: envBool("RLM_LLM_ENABLED", fileConfig.llm?.enabled ?? false),
859
- baseUrl: envString("RLM_LLM_BASE_URL", fileConfig.llm?.baseUrl ?? "http://localhost:11434/v1"),
860
- apiKey: envString("RLM_LLM_API_KEY", fileConfig.llm?.apiKey ?? "ollama"),
861
- model: envString("RLM_LLM_MODEL", fileConfig.llm?.model ?? DEFAULT_LLM_MODEL),
862
- codeModel: envString("RLM_LLM_CODE_MODEL", fileConfig.llm?.codeModel ?? DEFAULT_LLM_CODE_MODEL),
863
- temperature: envNum("RLM_LLM_TEMPERATURE", fileConfig.llm?.temperature ?? 0.2),
864
- maxOutputTokens: envNum("RLM_LLM_MAX_OUTPUT_TOKENS", fileConfig.llm?.maxOutputTokens ?? 8000),
865
- timeoutMs: envNum("RLM_LLM_TIMEOUT_MS", fileConfig.llm?.timeoutMs ?? 90000),
866
- disableThink: envBool("RLM_LLM_DISABLE_THINK", fileConfig.llm?.disableThink ?? true)
889
+ enabled: envBool("MASSA_AI_LLM_ENABLED", fileConfig.llm?.enabled ?? false),
890
+ baseUrl: envString("MASSA_AI_LLM_BASE_URL", fileConfig.llm?.baseUrl ?? "http://localhost:11434/v1"),
891
+ apiKey: envString("MASSA_AI_LLM_API_KEY", fileConfig.llm?.apiKey ?? "ollama"),
892
+ model: envString("MASSA_AI_LLM_MODEL", fileConfig.llm?.model ?? DEFAULT_LLM_MODEL),
893
+ codeModel: envString("MASSA_AI_LLM_CODE_MODEL", fileConfig.llm?.codeModel ?? DEFAULT_LLM_CODE_MODEL),
894
+ temperature: envNum("MASSA_AI_LLM_TEMPERATURE", fileConfig.llm?.temperature ?? 0.2),
895
+ maxOutputTokens: envNum("MASSA_AI_LLM_MAX_OUTPUT_TOKENS", fileConfig.llm?.maxOutputTokens ?? 8000),
896
+ timeoutMs: envNum("MASSA_AI_LLM_TIMEOUT_MS", fileConfig.llm?.timeoutMs ?? 90000),
897
+ disableThink: envBool("MASSA_AI_LLM_DISABLE_THINK", fileConfig.llm?.disableThink ?? true)
867
898
  },
868
899
  memory: {
869
900
  decay: {
@@ -913,7 +944,7 @@ var defaultConfig = {
913
944
  defaultStrategy: fileConfig.compression?.defaultStrategy ?? "code_structure",
914
945
  minTokensForCompression: envNum("MIN_TOKENS_FOR_COMPRESSION", fileConfig.compression?.minTokensForCompression ?? 100),
915
946
  targetCompressionRatio: envNum("TARGET_COMPRESSION_RATIO", fileConfig.compression?.targetCompressionRatio ?? 0.7),
916
- prompt: process.env.RLM_LLM_PROMPT || fileConfig.compression?.prompt || undefined
947
+ prompt: process.env.MASSA_AI_LLM_PROMPT || fileConfig.compression?.prompt || undefined
917
948
  },
918
949
  impact: {
919
950
  bfsCteEnabled: envBool("MASSA_AI_IMPACT_BFS_CTE", fileConfig.impact?.bfsCteEnabled ?? false)
@@ -945,7 +976,8 @@ var defaultConfig = {
945
976
  "**/generated/**",
946
977
  "*.min.js",
947
978
  "*.min.css"
948
- ]
979
+ ],
980
+ corsOrigins: envList("MASSA_AI_API_CORS_ORIGINS", fileConfig.security?.corsOrigins ?? [])
949
981
  },
950
982
  logging: {
951
983
  level: process.env.LOG_LEVEL || fileConfig.logging?.level || "info",
package/dist/index.js CHANGED
@@ -541,6 +541,9 @@ var init_massa_ai_config = __esm(() => {
541
541
  },
542
542
  handoffs: {
543
543
  enabled: true
544
+ },
545
+ security: {
546
+ corsOrigins: []
544
547
  }
545
548
  };
546
549
  });
@@ -562,6 +565,7 @@ __export(exports_config_loader, {
562
565
  import fs from "fs";
563
566
  import path3 from "path";
564
567
  import os2 from "os";
568
+ import crypto from "crypto";
565
569
  function getConfigDir() {
566
570
  return CONFIG_DIR;
567
571
  }
@@ -590,7 +594,8 @@ function loadConfig() {
590
594
  llm: { ...defaultMassaAiConfig.llm, ...userConfig.llm },
591
595
  memory: { ...defaultMassaAiConfig.memory, ...userConfig.memory },
592
596
  hooks: { ...defaultMassaAiConfig.hooks, ...userConfig.hooks },
593
- handoffs: { ...defaultMassaAiConfig.handoffs, ...userConfig.handoffs }
597
+ handoffs: { ...defaultMassaAiConfig.handoffs, ...userConfig.handoffs },
598
+ security: { ...defaultMassaAiConfig.security, ...userConfig.security }
594
599
  };
595
600
  } catch (error45) {
596
601
  console.error(`Error loading config from ${CONFIG_FILE}:`, error45);
@@ -634,7 +639,17 @@ function saveConfig(config2) {
634
639
  if (!fs.existsSync(CONFIG_DIR)) {
635
640
  fs.mkdirSync(CONFIG_DIR, { recursive: true });
636
641
  }
637
- fs.writeFileSync(CONFIG_FILE, JSON.stringify(config2, null, 2));
642
+ const unique = `${process.pid}.${++tempFileCounter}.${crypto.randomBytes(6).toString("hex")}`;
643
+ const tempFile = path3.join(CONFIG_DIR, `.config.json.${unique}.tmp`);
644
+ try {
645
+ fs.writeFileSync(tempFile, JSON.stringify(config2, null, 2));
646
+ fs.renameSync(tempFile, CONFIG_FILE);
647
+ } catch (error45) {
648
+ try {
649
+ fs.unlinkSync(tempFile);
650
+ } catch {}
651
+ throw error45;
652
+ }
638
653
  }
639
654
  function initConfig() {
640
655
  if (!fs.existsSync(CONFIG_FILE)) {
@@ -662,7 +677,7 @@ function getConfigForEnv() {
662
677
  env.ENABLE_METRICS = String(config2.logging.enableMetrics);
663
678
  return env;
664
679
  }
665
- var CONFIG_DIR, CONFIG_FILE, migrationAttempted = false;
680
+ var CONFIG_DIR, CONFIG_FILE, migrationAttempted = false, tempFileCounter = 0;
666
681
  var init_config_loader = __esm(() => {
667
682
  init_massa_ai_config();
668
683
  init_xdg();
@@ -13017,12 +13032,16 @@ try {
13017
13032
  if (cfg.database?.url && !process.env.DATABASE_URL) {
13018
13033
  process.env.DATABASE_URL = cfg.database.url;
13019
13034
  }
13020
- if (cfg.llm?.apiKey && !process.env.RLM_LLM_API_KEY) {
13021
- process.env.RLM_LLM_API_KEY = cfg.llm.apiKey;
13035
+ if (cfg.llm?.apiKey && !process.env.MASSA_AI_LLM_API_KEY) {
13036
+ process.env.MASSA_AI_LLM_API_KEY = cfg.llm.apiKey;
13022
13037
  }
13023
13038
  if (cfg.embedding?.apiKey && !process.env.OLLAMA_API_KEY) {
13024
13039
  process.env.OLLAMA_API_KEY = cfg.embedding.apiKey;
13025
13040
  }
13041
+ const securityApiKey = cfg.security?.apiKey?.trim();
13042
+ if (securityApiKey && !process.env.MASSA_AI_API_KEY?.trim()) {
13043
+ process.env.MASSA_AI_API_KEY = securityApiKey;
13044
+ }
13026
13045
  } catch {}
13027
13046
 
13028
13047
  // ../../packages/shared/dist/config/index.js
@@ -13030,6 +13049,11 @@ init_config_loader();
13030
13049
  init_massa_ai_config();
13031
13050
  init_config_loader();
13032
13051
  import path4 from "path";
13052
+
13053
+ // ../../packages/shared/dist/config/api-key.js
13054
+ init_config_loader();
13055
+
13056
+ // ../../packages/shared/dist/config/index.js
13033
13057
  var DEFAULT_LLM_MODEL = "qwen2.5:7b-instruct";
13034
13058
  var DEFAULT_LLM_CODE_MODEL = "qwen2.5-coder:7b";
13035
13059
  function envNum(key, fallback) {
@@ -13054,6 +13078,13 @@ function envString(key, fallback) {
13054
13078
  const s = process.env[key];
13055
13079
  return s === undefined || s === "" ? fallback : s;
13056
13080
  }
13081
+ function envList(key, fallback) {
13082
+ const s = process.env[key];
13083
+ if (s === undefined)
13084
+ return fallback;
13085
+ const parsed = s.split(",").map((v) => v.trim()).filter((v) => v.length > 0);
13086
+ return parsed.length > 0 ? parsed : fallback;
13087
+ }
13057
13088
  var MAX_IGNORE_PATTERNS = 1024;
13058
13089
  function validateCapturePolicyConfig(raw) {
13059
13090
  if (!raw || typeof raw !== "object")
@@ -13174,15 +13205,15 @@ var defaultConfig = {
13174
13205
  }
13175
13206
  },
13176
13207
  llm: {
13177
- enabled: envBool("RLM_LLM_ENABLED", fileConfig.llm?.enabled ?? false),
13178
- baseUrl: envString("RLM_LLM_BASE_URL", fileConfig.llm?.baseUrl ?? "http://localhost:11434/v1"),
13179
- apiKey: envString("RLM_LLM_API_KEY", fileConfig.llm?.apiKey ?? "ollama"),
13180
- model: envString("RLM_LLM_MODEL", fileConfig.llm?.model ?? DEFAULT_LLM_MODEL),
13181
- codeModel: envString("RLM_LLM_CODE_MODEL", fileConfig.llm?.codeModel ?? DEFAULT_LLM_CODE_MODEL),
13182
- temperature: envNum("RLM_LLM_TEMPERATURE", fileConfig.llm?.temperature ?? 0.2),
13183
- maxOutputTokens: envNum("RLM_LLM_MAX_OUTPUT_TOKENS", fileConfig.llm?.maxOutputTokens ?? 8000),
13184
- timeoutMs: envNum("RLM_LLM_TIMEOUT_MS", fileConfig.llm?.timeoutMs ?? 90000),
13185
- disableThink: envBool("RLM_LLM_DISABLE_THINK", fileConfig.llm?.disableThink ?? true)
13208
+ enabled: envBool("MASSA_AI_LLM_ENABLED", fileConfig.llm?.enabled ?? false),
13209
+ baseUrl: envString("MASSA_AI_LLM_BASE_URL", fileConfig.llm?.baseUrl ?? "http://localhost:11434/v1"),
13210
+ apiKey: envString("MASSA_AI_LLM_API_KEY", fileConfig.llm?.apiKey ?? "ollama"),
13211
+ model: envString("MASSA_AI_LLM_MODEL", fileConfig.llm?.model ?? DEFAULT_LLM_MODEL),
13212
+ codeModel: envString("MASSA_AI_LLM_CODE_MODEL", fileConfig.llm?.codeModel ?? DEFAULT_LLM_CODE_MODEL),
13213
+ temperature: envNum("MASSA_AI_LLM_TEMPERATURE", fileConfig.llm?.temperature ?? 0.2),
13214
+ maxOutputTokens: envNum("MASSA_AI_LLM_MAX_OUTPUT_TOKENS", fileConfig.llm?.maxOutputTokens ?? 8000),
13215
+ timeoutMs: envNum("MASSA_AI_LLM_TIMEOUT_MS", fileConfig.llm?.timeoutMs ?? 90000),
13216
+ disableThink: envBool("MASSA_AI_LLM_DISABLE_THINK", fileConfig.llm?.disableThink ?? true)
13186
13217
  },
13187
13218
  memory: {
13188
13219
  decay: {
@@ -13232,7 +13263,7 @@ var defaultConfig = {
13232
13263
  defaultStrategy: fileConfig.compression?.defaultStrategy ?? "code_structure",
13233
13264
  minTokensForCompression: envNum("MIN_TOKENS_FOR_COMPRESSION", fileConfig.compression?.minTokensForCompression ?? 100),
13234
13265
  targetCompressionRatio: envNum("TARGET_COMPRESSION_RATIO", fileConfig.compression?.targetCompressionRatio ?? 0.7),
13235
- prompt: process.env.RLM_LLM_PROMPT || fileConfig.compression?.prompt || undefined
13266
+ prompt: process.env.MASSA_AI_LLM_PROMPT || fileConfig.compression?.prompt || undefined
13236
13267
  },
13237
13268
  impact: {
13238
13269
  bfsCteEnabled: envBool("MASSA_AI_IMPACT_BFS_CTE", fileConfig.impact?.bfsCteEnabled ?? false)
@@ -13264,7 +13295,8 @@ var defaultConfig = {
13264
13295
  "**/generated/**",
13265
13296
  "*.min.js",
13266
13297
  "*.min.css"
13267
- ]
13298
+ ],
13299
+ corsOrigins: envList("MASSA_AI_API_CORS_ORIGINS", fileConfig.security?.corsOrigins ?? [])
13268
13300
  },
13269
13301
  logging: {
13270
13302
  level: process.env.LOG_LEVEL || fileConfig.logging?.level || "info",
@@ -13738,7 +13770,7 @@ async function massaAiGetWithQuery(endpoint, params, timeoutMs = FETCH_TIMEOUT_M
13738
13770
  }
13739
13771
  var MassaAiPlugin = async ({ project, directory, worktree, client }) => {
13740
13772
  ensureConfig();
13741
- const config3 = loadConfig();
13773
+ loadConfig();
13742
13774
  const projectPath = worktree || directory;
13743
13775
  const projectPins = new SessionProjectPin({
13744
13776
  computeProjectId: () => computePluginProjectId({
@@ -13953,7 +13985,7 @@ var MassaAiPlugin = async ({ project, directory, worktree, client }) => {
13953
13985
  includeSymbols: tool.schema.boolean().optional().default(true).describe("Include symbol metadata from graph"),
13954
13986
  includeImports: tool.schema.boolean().optional().default(true).describe("Extract and show import statements")
13955
13987
  },
13956
- async execute(args, ctx) {
13988
+ async execute(args, _ctx) {
13957
13989
  const result = await massaAiFetch("/api/v1/file/read", {
13958
13990
  filePath: args.filePath,
13959
13991
  projectId: args.projectId || projectId,
@@ -14016,7 +14048,7 @@ var MassaAiPlugin = async ({ project, directory, worktree, client }) => {
14016
14048
  exportedOnly: tool.schema.boolean().optional().default(false).describe("Return only exported symbols"),
14017
14049
  maxResults: tool.schema.number().optional().default(20).describe("Maximum number of results to return (default: 20)")
14018
14050
  },
14019
- async execute(args, ctx) {
14051
+ async execute(args, _ctx) {
14020
14052
  const result = await massaAiGetWithQuery("/api/v1/symbol/definitions", {
14021
14053
  projectId,
14022
14054
  search: args.query,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@massa-ai/opencode-plugin",
3
- "version": "1.7.1",
3
+ "version": "1.9.0",
4
4
  "description": "massa-ai plugin for OpenCode - Semantic code search, memory, and context compression",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -21,8 +21,8 @@
21
21
  "dependencies": {
22
22
  "@opencode-ai/plugin": "^1.2.15",
23
23
  "@opencode-ai/sdk": "^1.2.15",
24
- "@massa-ai/core": "^1.7.1",
25
- "@massa-ai/shared": "^1.7.1"
24
+ "@massa-ai/core": "^1.9.0",
25
+ "@massa-ai/shared": "^1.9.0"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@types/node": "^22.10.5",