@wu529778790/open-im 0.1.3 → 0.2.0

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.
Files changed (2) hide show
  1. package/dist/cli.js +29 -3
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -4,15 +4,15 @@ import { spawn, execFileSync } from 'node:child_process';
4
4
  import { fileURLToPath } from 'node:url';
5
5
  import { dirname, join } from 'node:path';
6
6
  import { mkdir, writeFile, rm, readFile } from 'node:fs/promises';
7
- import { existsSync } from 'node:fs';
8
- import { platform } from 'node:os';
9
- import { homedir } from 'node:os';
7
+ import { existsSync, readFileSync } from 'node:fs';
8
+ import { platform, homedir } from 'node:os';
10
9
  const __filename = fileURLToPath(import.meta.url);
11
10
  const __dirname = dirname(__filename);
12
11
  // PID 文件路径
13
12
  const PID_DIR = join(homedir(), '.open-im');
14
13
  const PID_FILE = join(PID_DIR, 'daemon.pid');
15
14
  const STOP_FILE = join(PID_DIR, 'stop.flag');
15
+ const CONFIG_FILE = join(PID_DIR, 'config.json');
16
16
  // 保存 PID 到文件
17
17
  async function savePid(pid) {
18
18
  try {
@@ -47,6 +47,27 @@ async function removePidFile() {
47
47
  // 忽略删除错误
48
48
  }
49
49
  }
50
+ // 更新工作目录到配置文件
51
+ async function updateWorkDir(workDir) {
52
+ try {
53
+ await mkdir(PID_DIR, { recursive: true });
54
+ let config = {};
55
+ if (existsSync(CONFIG_FILE)) {
56
+ try {
57
+ config = JSON.parse(readFileSync(CONFIG_FILE, 'utf-8'));
58
+ }
59
+ catch {
60
+ // 忽略解析错误
61
+ }
62
+ }
63
+ // 更新工作目录
64
+ config.claudeWorkDir = workDir;
65
+ await writeFile(CONFIG_FILE, JSON.stringify(config, null, 2), 'utf-8');
66
+ }
67
+ catch (err) {
68
+ console.error('无法保存工作目录配置:', err);
69
+ }
70
+ }
50
71
  // 检查进程是否在运行
51
72
  async function isProcessRunning(pid) {
52
73
  try {
@@ -115,6 +136,11 @@ if (args[0] === 'stop') {
115
136
  });
116
137
  }
117
138
  else if (args[0] === 'start') {
139
+ // 获取当前工作目录
140
+ const currentDir = process.cwd();
141
+ // 更新配置中的工作目录
142
+ await updateWorkDir(currentDir);
143
+ console.log(`工作目录已设置为: ${currentDir}`);
118
144
  // 后台启动 - 跨平台方案
119
145
  const distPath = join(__dirname, '..', 'dist', 'index.js');
120
146
  // 使用 detached 模式创建独立进程
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wu529778790/open-im",
3
- "version": "0.1.3",
3
+ "version": "0.2.0",
4
4
  "description": "Multi-platform IM bridge for AI CLI tools (Claude, Codex, Cursor)",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",