@pptalker/agent 1.0.3 → 1.0.4
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/index.js +15 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { realpathSync } from 'node:fs';
|
|
2
3
|
import { createRequire } from 'node:module';
|
|
3
4
|
import { resolve } from 'node:path';
|
|
4
5
|
import { fileURLToPath } from 'node:url';
|
|
@@ -95,7 +96,20 @@ async function main() {
|
|
|
95
96
|
console.error(`[pptalker-agent] v${PKG.version} 就绪`);
|
|
96
97
|
}
|
|
97
98
|
|
|
98
|
-
|
|
99
|
+
// npx / node_modules/.bin 通过符号链接执行本文件,process.argv[1] 是链接路径,
|
|
100
|
+
// 而 import.meta.url 已被 Node 解析成真实路径。必须 realpath 归一后再比较,
|
|
101
|
+
// 否则直接运行为“静默退出”(exit 0、无任何输出),表现为 MCP 客户端 -32000。
|
|
102
|
+
function isDirectRun() {
|
|
103
|
+
const entry = process.argv[1];
|
|
104
|
+
if (!entry) return false;
|
|
105
|
+
try {
|
|
106
|
+
return realpathSync(resolve(entry)) === realpathSync(fileURLToPath(import.meta.url));
|
|
107
|
+
} catch {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (isDirectRun()) {
|
|
99
113
|
main().catch(() => {
|
|
100
114
|
console.error(`[pptalker-agent] 启动失败。${CONFIG_HELP}`);
|
|
101
115
|
process.exitCode = 1;
|