@coclaw/openclaw-coclaw 0.1.1 → 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
@@ -1,6 +1,6 @@
1
1
  # @coclaw/openclaw-coclaw
2
2
 
3
- CoClaw 的 OpenClaw 插件(npm: `@coclaw/openclaw-coclaw`,plugin id: `coclaw`),包含:
3
+ CoClaw 的 OpenClaw 插件(npm: `@coclaw/openclaw-coclaw`,plugin id: `openclaw-coclaw`),包含:
4
4
 
5
5
  - **transport bridge** — CoClaw server 与 OpenClaw gateway 之间的实时消息桥接
6
6
  - **session-manager** — 会话列表/读取能力(`nativeui.sessions.listAll` / `nativeui.sessions.get`)
package/index.js CHANGED
@@ -47,7 +47,7 @@ function respondError(respond, err) {
47
47
 
48
48
  /* c8 ignore start */
49
49
  const plugin = {
50
- id: 'coclaw',
50
+ id: 'openclaw-coclaw',
51
51
  name: 'CoClaw',
52
52
  description: 'OpenClaw CoClaw channel plugin for remote chat',
53
53
  register(api) {
@@ -1,5 +1,5 @@
1
1
  {
2
- "id": "coclaw",
2
+ "id": "openclaw-coclaw",
3
3
  "name": "CoClaw",
4
4
  "description": "OpenClaw CoClaw channel plugin for remote chat",
5
5
  "channels": ["coclaw"],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coclaw/openclaw-coclaw",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "description": "OpenClaw CoClaw channel plugin for remote chat",
@@ -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 {} // eslint-disable-line no-empty
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('\n');
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('\n').filter(Boolean)) {
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
  }