minimal-agent 0.3.1 → 0.3.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "minimal-agent",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "最小化 Agent 系统 —— 10 工具 + 插件系统 + workflow DSL + 自动压缩 + OpenAI 兼容 + Ink TUI;NodeNext + tsc 原地编译,dev 用 Bun .ts、install 用 Node .js(学习/教学用)",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "author": "Bill Wang <leiwang0359@gmail.com>",
@@ -13,6 +13,9 @@
13
13
  *
14
14
  * 契约:
15
15
  * - 两个文件都不存在 → 缓存 null(纯 markdown 声明式插件)
16
+ * - 两个文件都存在 + plugin.ts mtime > plugin.js mtime → console.warn
17
+ * 提示 stale(dev 模式跑过 build 后又改 .ts 源码的常见坑),加载行为
18
+ * 不变仍优先 plugin.js
16
19
  * - import 失败(语法错 / 运行时抛错)→ console.warn + 缓存 null
17
20
  * - import 成功但 default 不是对象 → 缓存 null
18
21
  * - 缓存 key = pluginRoot 绝对路径
@@ -20,7 +23,7 @@
20
23
  * 框架 hot-reload 由测试调用 _resetPluginLoader() 实现。
21
24
  * ============================================================
22
25
  */
23
- import { existsSync } from 'node:fs';
26
+ import { existsSync, statSync } from 'node:fs';
24
27
  import { join } from 'node:path';
25
28
  import { pathToFileURL } from 'node:url';
26
29
  const loaderCache = new Map();
@@ -41,9 +44,25 @@ export async function loadPluginApi(pluginRoot) {
41
44
  return loaderCache.get(pluginRoot) ?? null;
42
45
  }
43
46
  // prefer plugin.js(install / Node 兼容),fallback plugin.ts(dev / 用户 Bun 插件)
44
- const pluginEntry = ['plugin.js', 'plugin.ts']
45
- .map((f) => join(pluginRoot, f))
46
- .find((p) => existsSync(p));
47
+ const jsPath = join(pluginRoot, 'plugin.js');
48
+ const tsPath = join(pluginRoot, 'plugin.ts');
49
+ const jsExists = existsSync(jsPath);
50
+ const tsExists = existsSync(tsPath);
51
+ // dev 模式 stale 检测:两文件都存在 + .ts 比 .js 新 → 用户改了源码但没清编译产物
52
+ if (jsExists && tsExists) {
53
+ try {
54
+ const jsMtime = statSync(jsPath).mtimeMs;
55
+ const tsMtime = statSync(tsPath).mtimeMs;
56
+ if (tsMtime > jsMtime) {
57
+ console.warn(`[minimal-agent] 检测到 stale plugin.js(${pluginRoot}):plugin.ts 比 plugin.js 新,` +
58
+ `加载器仍优先吃 plugin.js。如果你刚改过源码却没生效,请跑 \`bun run clean\` 删掉原地编译产物。`);
59
+ }
60
+ }
61
+ catch {
62
+ // stat 失败静默,不影响加载
63
+ }
64
+ }
65
+ const pluginEntry = jsExists ? jsPath : tsExists ? tsPath : undefined;
47
66
  if (!pluginEntry) {
48
67
  loaderCache.set(pluginRoot, null);
49
68
  return null;