dsh-plugin-pscad-expert-vyma 1.0.4 → 1.0.6

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/index.js CHANGED
@@ -179,7 +179,7 @@ export function apply(ctx, config) {
179
179
  description: def.description,
180
180
  parameters: def.parameters,
181
181
  output: {
182
- schema: { type: 'object' },
182
+ schema: { type: 'object', additionalProperties: true },
183
183
  render: renderJson,
184
184
  },
185
185
  execute: (args, exec) => runPy(def.name, args, config, exec.signal),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-plugin-pscad-expert-vyma",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "PSCAD 自动化建模与仿真控制专家插件(DSH Agent 工具库 + 基准模板 + 领域知识)",
5
5
  "type": "module",
6
6
  "main": "index.js",
package/plugin.yaml CHANGED
@@ -3,7 +3,7 @@
3
3
  # 由知识资产固化项目自动生成(2026-08-25)· 部署至 Git 仓库
4
4
  # ============================================================
5
5
  name: pscad-automation-expert
6
- version: 1.0.4
6
+ version: 1.0.6
7
7
  description: PSCAD 自动化建模与仿真控制专家插件
8
8
 
9
9
  # ---- 系统提示词(加载到 Agent 上下文最前置位置)----
package/tools/main.py CHANGED
@@ -109,44 +109,73 @@ _NAME_HINT: Dict[str, str] = {
109
109
  }
110
110
 
111
111
  # ---------------------------------------------------------------------------
112
- # 本地配置持久化(工作区 .pscad_config.json)
112
+ # 本地配置持久化(用户级优先:PSCAD 路径是机器属性,跨工作区共享)
113
+ # 查找顺序:PSCAD_CONFIG_DIR 环境变量 → 用户级(DSH_HOME/主目录) → 工作区级(兼容旧版)
113
114
  # ---------------------------------------------------------------------------
114
115
  _config_cache: Optional[Dict[str, Any]] = None
115
116
 
116
117
 
117
- def _config_path() -> str:
118
- """配置文件绝对路径(默认当前工作目录;可被环境变量 PSCAD_CONFIG 覆盖)。"""
119
- base = os.environ.get('PSCAD_CONFIG_DIR') or os.getcwd()
118
+ def _user_config_path() -> str:
119
+ """用户级配置路径:优先 DSH_HOME,其次用户主目录。"""
120
+ dsh_home = os.environ.get('DSH_HOME')
121
+ base = dsh_home if dsh_home else os.path.expanduser('~')
120
122
  return os.path.join(base, CONFIG_FILE_NAME)
121
123
 
122
124
 
125
+ def _config_path() -> str:
126
+ """配置写入路径(保存时使用):显式 PSCAD_CONFIG_DIR 优先,否则用户级。"""
127
+ env_dir = os.environ.get('PSCAD_CONFIG_DIR')
128
+ if env_dir:
129
+ return os.path.join(env_dir, CONFIG_FILE_NAME)
130
+ return _user_config_path()
131
+
132
+
123
133
  def load_config() -> Dict[str, Any]:
124
- """加载工作区本地配置 ``.pscad_config.json``。
134
+ """加载 PSCAD 路径配置(多级查找,**跨工作区共享**)。
135
+
136
+ 查找顺序:
137
+ 1. 环境变量 ``PSCAD_CONFIG_DIR`` 指定目录下的 ``.pscad_config.json``;
138
+ 2. 用户级:``$DSH_HOME/.pscad_config.json``(无 DSH_HOME 时用用户主目录)——
139
+ 一次配置,所有工作区/所有会话共享,**不依赖任何插件仓库目录**;
140
+ 3. 工作区级:当前目录 ``.pscad_config.json``(兼容旧版本遗留配置)。
125
141
 
126
142
  配置键:``pscad_exe_path``(PSCAD 可执行文件)、``mhi_pylib_path``
127
143
  (mhi.pscad 库目录)、``pscad_port``(自动化端口,可选)、``saved_at``。
128
144
 
129
145
  Returns:
130
- 配置字典;文件不存在或损坏时返回 ``{}``(**绝不抛异常**)。
146
+ 配置字典;均不存在或损坏时返回 ``{}``(**绝不抛异常**)。
131
147
  结果会缓存,供懒加载与连接逻辑读取。
132
148
  """
133
149
  global _config_cache
134
150
  if _config_cache is not None:
135
151
  return _config_cache
136
- try:
137
- path = _config_path()
138
- if os.path.isfile(path):
139
- with open(path, encoding='utf-8') as fh:
140
- _config_cache = json.load(fh)
141
- else:
142
- _config_cache = {}
143
- except Exception:
144
- _config_cache = {}
152
+ candidates: List[str] = []
153
+ env_dir = os.environ.get('PSCAD_CONFIG_DIR')
154
+ if env_dir:
155
+ candidates.append(os.path.join(env_dir, CONFIG_FILE_NAME))
156
+ candidates.append(_user_config_path())
157
+ candidates.append(os.path.join(os.getcwd(), CONFIG_FILE_NAME))
158
+ cfg: Dict[str, Any] = {}
159
+ for path in candidates:
160
+ try:
161
+ if os.path.isfile(path):
162
+ with open(path, encoding='utf-8') as fh:
163
+ data = json.load(fh)
164
+ if isinstance(data, dict) and data:
165
+ cfg = data
166
+ break
167
+ except Exception:
168
+ continue
169
+ _config_cache = cfg
145
170
  return _config_cache
146
171
 
147
172
 
148
173
  def save_config(exe_path: str, pylib_path: str) -> Dict[str, Any]:
149
- """将 PSCAD 路径配置持久化到工作区 ``.pscad_config.json``。
174
+ """将 PSCAD 路径配置持久化到**用户级** ``.pscad_config.json``(跨工作区共享)。
175
+
176
+ 写入位置:``PSCAD_CONFIG_DIR`` 环境变量(若设置)→ 否则 ``$DSH_HOME``(无则用户
177
+ 主目录)。**不写入当前工作区**——保证在其他任意工作区、其他电脑(无插件仓库)
178
+ 都能通过 load_config 读到同一份配置。
150
179
 
151
180
  Args:
152
181
  exe_path: PSCAD 可执行文件绝对路径(如 '<PSCAD_INSTALL_DIR>/bin/win64/Pscad.exe')。