@coclaw/openclaw-coclaw 0.1.0 → 0.1.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/README.md
CHANGED
|
@@ -78,8 +78,8 @@ bind/unbind 成功后会通过 gateway RPC 通知插件刷新/停止 bridge 连
|
|
|
78
78
|
### 方式三:独立 CLI(兼容)
|
|
79
79
|
|
|
80
80
|
```bash
|
|
81
|
-
node ~/.openclaw/extensions/
|
|
82
|
-
node ~/.openclaw/extensions/
|
|
81
|
+
node ~/.openclaw/extensions/coclaw/src/cli.js bind <binding-code> --server <url>
|
|
82
|
+
node ~/.openclaw/extensions/coclaw/src/cli.js unbind --server <url>
|
|
83
83
|
```
|
|
84
84
|
|
|
85
85
|
## 配置存储
|
package/package.json
CHANGED
package/src/cli-registrar.js
CHANGED
|
@@ -29,6 +29,7 @@ export function callGatewayMethod(method, spawnFn, opts) {
|
|
|
29
29
|
try {
|
|
30
30
|
child = doSpawn('openclaw', ['gateway', 'call', method, '--json'], {
|
|
31
31
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
32
|
+
shell: true, // Windows 上 npm 全局安装生成 .cmd,需经 shell 解析
|
|
32
33
|
});
|
|
33
34
|
} catch {
|
|
34
35
|
resolve({ ok: false, error: 'spawn_failed' });
|
|
@@ -45,7 +46,7 @@ export function callGatewayMethod(method, spawnFn, opts) {
|
|
|
45
46
|
settled = true;
|
|
46
47
|
clearTimeout(timeoutTimer);
|
|
47
48
|
clearTimeout(graceTimer);
|
|
48
|
-
try { child.kill(); } catch {}
|
|
49
|
+
try { child.kill(); } catch {}
|
|
49
50
|
resolve(result);
|
|
50
51
|
};
|
|
51
52
|
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 跨平台 mock os.homedir()
|
|
3
|
+
*
|
|
4
|
+
* Node.js os.homedir() 在不同平台读取不同环境变量:
|
|
5
|
+
* - POSIX: HOME
|
|
6
|
+
* - Windows: USERPROFILE(优先)、HOMEDRIVE+HOMEPATH
|
|
7
|
+
*
|
|
8
|
+
* 测试中需同时设置两端变量,确保 os.homedir() 返回期望路径。
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const HOME_VARS = ['HOME', 'USERPROFILE'];
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 保存当前 home 相关环境变量
|
|
15
|
+
* @returns {Record<string, string | undefined>}
|
|
16
|
+
*/
|
|
17
|
+
export function saveHomedir() {
|
|
18
|
+
const saved = {};
|
|
19
|
+
for (const key of HOME_VARS) {
|
|
20
|
+
saved[key] = process.env[key];
|
|
21
|
+
}
|
|
22
|
+
return saved;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* 将 home 相关环境变量统一设置为指定路径
|
|
27
|
+
* @param {string} dir - 目标路径
|
|
28
|
+
*/
|
|
29
|
+
export function setHomedir(dir) {
|
|
30
|
+
for (const key of HOME_VARS) {
|
|
31
|
+
process.env[key] = dir;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* 恢复之前保存的 home 相关环境变量
|
|
37
|
+
* @param {Record<string, string | undefined>} saved
|
|
38
|
+
*/
|
|
39
|
+
export function restoreHomedir(saved) {
|
|
40
|
+
for (const key of HOME_VARS) {
|
|
41
|
+
if (saved[key] === undefined) {
|
|
42
|
+
delete process.env[key];
|
|
43
|
+
} else {
|
|
44
|
+
process.env[key] = saved[key];
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -100,7 +100,7 @@ function extractRawTextFromContent(content) {
|
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
function findFirstUserRawText(filePath, logger) {
|
|
103
|
-
const lines = fs.readFileSync(filePath, 'utf8').split(
|
|
103
|
+
const lines = fs.readFileSync(filePath, 'utf8').split(/\r?\n/);
|
|
104
104
|
for (const line of lines) {
|
|
105
105
|
if (!line) continue;
|
|
106
106
|
try {
|
|
@@ -249,7 +249,7 @@ export function createSessionManager(options = {}) {
|
|
|
249
249
|
if (!file) throw new Error(`session transcript not found: ${sessionId}`);
|
|
250
250
|
|
|
251
251
|
const all = [];
|
|
252
|
-
for (const line of fs.readFileSync(file, 'utf8').split(
|
|
252
|
+
for (const line of fs.readFileSync(file, 'utf8').split(/\r?\n/).filter(Boolean)) {
|
|
253
253
|
try {
|
|
254
254
|
all.push(JSON.parse(line));
|
|
255
255
|
}
|