@aiyiran/myclaw 1.0.139 → 1.0.141

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/gateway.js ADDED
@@ -0,0 +1,170 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * gateway.js
5
+ *
6
+ * Gateway 生命周期管理(跨平台: Mac/Linux/Windows/容器)
7
+ *
8
+ * 提供:
9
+ * stop() — 先礼后兵,确保彻底关闭
10
+ * start() — 后台启动 + 健康检查
11
+ * restart() — stop + start
12
+ */
13
+
14
+ const { execSync } = require('child_process');
15
+
16
+ const PORT = 18789;
17
+ const isWin = process.platform === 'win32';
18
+
19
+ // ANSI 颜色
20
+ const colors = {
21
+ green: '\x1b[32m',
22
+ yellow: '\x1b[33m',
23
+ red: '\x1b[31m',
24
+ nc: '\x1b[0m',
25
+ };
26
+
27
+ /**
28
+ * 彻底停止 Gateway(先礼后兵)
29
+ */
30
+ function stop() {
31
+ // Step 1: 优雅关闭
32
+ console.log('[停止] Step 1 — 优雅关闭...');
33
+ try {
34
+ execSync('openclaw gateway stop', { stdio: 'pipe', timeout: 10000 });
35
+ console.log('[停止] ' + colors.green + 'Gateway 已发送停止信号' + colors.nc);
36
+ } catch {
37
+ console.log('[停止] Gateway 未在运行或已停止');
38
+ }
39
+
40
+ // 等 2 秒让优雅关闭执行
41
+ execSync(isWin ? 'timeout /t 2 /nobreak >nul' : 'sleep 2', { stdio: 'ignore' });
42
+
43
+ // Step 2: 检查残留进程并强杀
44
+ console.log('[停止] Step 2 — 清理残留进程...');
45
+
46
+ // 2a. 杀端口占用者
47
+ try {
48
+ if (isWin) {
49
+ const netstat = execSync('netstat -ano | findstr :' + PORT + ' | findstr LISTENING', {
50
+ encoding: 'utf8', stdio: 'pipe', timeout: 5000
51
+ }).trim();
52
+ const pids = [...new Set(netstat.split('\n').map(l => l.trim().split(/\s+/).pop()).filter(p => p && p !== '0'))];
53
+ for (const pid of pids) {
54
+ try {
55
+ execSync('taskkill /F /PID ' + pid, { stdio: 'pipe', timeout: 5000 });
56
+ console.log('[停止] 🔪 强杀端口占用进程 PID=' + pid);
57
+ } catch {}
58
+ }
59
+ } else {
60
+ const pids = execSync('lsof -i :' + PORT + ' -t 2>/dev/null', {
61
+ encoding: 'utf8', stdio: 'pipe', timeout: 5000
62
+ }).trim();
63
+ if (pids) {
64
+ for (const pid of pids.split('\n').filter(Boolean)) {
65
+ try {
66
+ execSync('kill -9 ' + pid, { stdio: 'pipe', timeout: 3000 });
67
+ console.log('[停止] 🔪 强杀端口占用进程 PID=' + pid);
68
+ } catch {}
69
+ }
70
+ }
71
+ }
72
+ } catch {
73
+ // 没有端口占用,正常
74
+ }
75
+
76
+ // 2b. 杀所有 openclaw 相关进程(防止僵尸进程)
77
+ try {
78
+ if (!isWin) {
79
+ const myPid = process.pid;
80
+ const procs = execSync('pgrep -f "openclaw" 2>/dev/null || true', {
81
+ encoding: 'utf8', stdio: 'pipe', timeout: 5000
82
+ }).trim();
83
+ if (procs) {
84
+ for (const pid of procs.split('\n').filter(Boolean)) {
85
+ if (pid === String(myPid)) continue;
86
+ try {
87
+ execSync('kill -9 ' + pid, { stdio: 'pipe', timeout: 3000 });
88
+ console.log('[停止] 🔪 清理残留 openclaw 进程 PID=' + pid);
89
+ } catch {}
90
+ }
91
+ }
92
+ }
93
+ } catch {}
94
+
95
+ console.log('[停止] ' + colors.green + '清理完成' + colors.nc);
96
+
97
+ // Step 3: 轮询等待端口释放
98
+ const MAX_WAIT = 10;
99
+ let portFree = false;
100
+
101
+ for (let i = 0; i < MAX_WAIT; i++) {
102
+ try {
103
+ if (isWin) {
104
+ execSync('netstat -ano | findstr :' + PORT + ' | findstr LISTENING', {
105
+ stdio: 'pipe', timeout: 2000
106
+ });
107
+ } else {
108
+ execSync('lsof -i :' + PORT + ' -t 2>/dev/null', { stdio: 'pipe', timeout: 2000 });
109
+ }
110
+ process.stdout.write('[等待] 端口 ' + PORT + ' 释放中... (' + (i + 1) + '/' + MAX_WAIT + 's)\r');
111
+ execSync(isWin ? 'timeout /t 1 /nobreak >nul' : 'sleep 1', { stdio: 'ignore' });
112
+ } catch {
113
+ portFree = true;
114
+ break;
115
+ }
116
+ }
117
+
118
+ if (portFree) {
119
+ console.log('[等待] ' + colors.green + '端口已释放' + colors.nc + ' ');
120
+ } else {
121
+ console.log('[等待] ' + colors.yellow + '端口释放超时' + colors.nc);
122
+ }
123
+
124
+ return portFree;
125
+ }
126
+
127
+ /**
128
+ * 启动 Gateway(后台 + 健康检查)
129
+ */
130
+ function start() {
131
+ console.log('[启动] 正在启动 Gateway...');
132
+
133
+ if (isWin) {
134
+ execSync('start /B openclaw gateway > %TEMP%\\openclaw-gateway.log 2>&1', {
135
+ stdio: 'ignore', shell: true,
136
+ });
137
+ } else {
138
+ execSync('nohup openclaw gateway > /tmp/openclaw-gateway.log 2>&1 &', {
139
+ stdio: 'ignore', shell: true,
140
+ });
141
+ }
142
+
143
+ // 等待启动完成
144
+ execSync(isWin ? 'timeout /t 3 /nobreak >nul' : 'sleep 3', { stdio: 'ignore' });
145
+
146
+ // 健康检查
147
+ try {
148
+ execSync('openclaw health', { stdio: 'pipe', timeout: 5000 });
149
+ console.log('[启动] ' + colors.green + 'Gateway 启动成功!' + colors.nc);
150
+ console.log('');
151
+ console.log('控制台: ' + colors.yellow + 'http://127.0.0.1:' + PORT + colors.nc);
152
+ return true;
153
+ } catch {
154
+ console.log('[启动] ' + colors.yellow + 'Gateway 正在启动中...' + colors.nc);
155
+ const logPath = isWin ? '%TEMP%\\openclaw-gateway.log' : '/tmp/openclaw-gateway.log';
156
+ console.log('日志: ' + colors.yellow + 'tail -f ' + logPath + colors.nc);
157
+ return false;
158
+ }
159
+ }
160
+
161
+ /**
162
+ * 重启 Gateway(stop + start)
163
+ */
164
+ function restart() {
165
+ stop();
166
+ console.log('');
167
+ return start();
168
+ }
169
+
170
+ module.exports = { stop, start, restart, PORT };
package/index.js CHANGED
@@ -776,6 +776,7 @@ function runUnpatch() {
776
776
  }
777
777
 
778
778
  function runRestart() {
779
+ const gateway = require('./gateway');
779
780
  const bar = '----------------------------------------';
780
781
 
781
782
  console.log('');
@@ -784,35 +785,7 @@ function runRestart() {
784
785
  console.log('');
785
786
 
786
787
  try {
787
- console.log('[停止] 正在停止 Gateway...');
788
- try {
789
- execSync('openclaw gateway stop', { stdio: 'pipe', timeout: 10000 });
790
- console.log('[停止] ' + colors.green + 'Gateway 已停止' + colors.nc);
791
- } catch {
792
- console.log('[停止] Gateway 未在运行或已停止');
793
- }
794
-
795
- console.log('');
796
- console.log('[启动] 正在启动 Gateway...');
797
- // 使用 nohup + 后台启动,避免阻塞当前进程
798
- execSync('nohup openclaw gateway > /tmp/openclaw-gateway.log 2>&1 &', {
799
- stdio: 'ignore',
800
- shell: true,
801
- });
802
-
803
- // 等待 2 秒让 Gateway 启动
804
- execSync('sleep 2', { stdio: 'ignore' });
805
-
806
- // 检查是否启动成功
807
- try {
808
- execSync('openclaw health', { stdio: 'pipe', timeout: 5000 });
809
- console.log('[启动] ' + colors.green + 'Gateway 启动成功!' + colors.nc);
810
- console.log('');
811
- console.log('控制台: ' + colors.yellow + 'http://127.0.0.1:18789' + colors.nc);
812
- } catch {
813
- console.log('[启动] ' + colors.yellow + 'Gateway 正在启动中...' + colors.nc);
814
- console.log('日志: ' + colors.yellow + 'tail -f /tmp/openclaw-gateway.log' + colors.nc);
815
- }
788
+ gateway.restart();
816
789
  } catch (err) {
817
790
  console.error('[' + colors.red + '错误' + colors.nc + '] 重启失败: ' + err.message);
818
791
  }
@@ -1060,6 +1033,10 @@ if (!command || command === 'help' || command === '--help' || command === '-h')
1060
1033
  runUpdate();
1061
1034
  } else if (command === 'up') {
1062
1035
  runUpdate();
1036
+ // 更新后自动 patch,恢复 UI 注入和自定义配置
1037
+ console.log('');
1038
+ console.log('🔧 自动执行 patch 以恢复自定义配置...');
1039
+ runPatch();
1063
1040
  if (detectPlatform() === 'windows') {
1064
1041
  runBat();
1065
1042
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiyiran/myclaw",
3
- "version": "1.0.139",
3
+ "version": "1.0.141",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -1,32 +1,35 @@
1
1
  {
2
- "_doc": "MyClaw 注入清单 (auto-generated)。strategy: auto | on | off | delete",
3
- "_generated": "2026-04-07T16:26:14.875Z",
4
- "agents": [
2
+ "_doc": "MyClaw 注入清单 (手动维护)。strategy: auto | on | off | delete",
3
+ "_doc_order": "执行顺序: 1.UI注入(patch.js) → 2.skills → 3.agents → 4.config → 5.run",
4
+ "_doc_skills": "Step 2: 将 myclaw/skills/ 下的技能包复制到 ~/.openclaw/workspace/skills/",
5
+ "skills": [
5
6
  {
6
- "id": "danci",
7
- "workspace": "workspace-danci",
7
+ "name": "minimax-inject",
8
8
  "strategy": "off",
9
- "description": "danci"
9
+ "description": "minimax-inject (agent 可调用的注入技能)"
10
10
  },
11
11
  {
12
- "id": "kakaxi",
13
- "workspace": "workspace-kakaxi",
12
+ "name": "tavily-search",
14
13
  "strategy": "off",
15
- "description": "kakaxi"
14
+ "description": "tavily-search (Tavily 搜索技能包)"
16
15
  }
17
16
  ],
18
- "skills": [
17
+ "_doc_agents": "Step 3: 将 agent-list/ 下的智能体分发到 ~/.openclaw/ 并注册到 openclaw.json",
18
+ "agents": [
19
19
  {
20
- "name": "minimax-inject",
20
+ "id": "danci",
21
+ "workspace": "workspace-danci",
21
22
  "strategy": "off",
22
- "description": "minimax-inject (agent 可调用的注入技能)"
23
+ "description": "danci"
23
24
  },
24
25
  {
25
- "name": "tavily-search",
26
+ "id": "kakaxi",
27
+ "workspace": "workspace-kakaxi",
26
28
  "strategy": "off",
27
- "description": "tavily-search (Tavily 搜索技能包)"
29
+ "description": "kakaxi"
28
30
  }
29
31
  ],
32
+ "_doc_config": "Step 4: 使用 dot-notation 补丁修改 openclaw.json 的系统配置,深度合并",
30
33
  "config": {
31
34
  "strategy": "on",
32
35
  "patches": {
@@ -35,10 +38,11 @@
35
38
  "tools.exec.ask": "off",
36
39
  "tools.exec.security": "full",
37
40
  "plugins.entries.tavily.enabled": true,
38
- "plugins.entries.tavily.config.webSearch.apiKey": "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,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",
41
+ "plugins.entries.tavily.config.webSearch.apiKey": "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",
39
42
  "update.checkOnStart": false
40
43
  }
41
44
  },
45
+ "_doc_run": "Step 5: 按顺序 require(module).run([]) 执行自定义脚本,不触发 Gateway 重启",
42
46
  "run": [
43
47
  {
44
48
  "module": "./inject-image",
@@ -46,4 +50,4 @@
46
50
  "description": "图片模型注入 (vveai)"
47
51
  }
48
52
  ]
49
- }
53
+ }
package/publish.sh CHANGED
@@ -3,9 +3,7 @@ set -e # 遇到错误即停止
3
3
 
4
4
  echo "📦 准备发布新版本..."
5
5
 
6
- # 0. 自动构建 patch-manifest.json(从 agent-list/ 目录扫描)
7
- echo "📋 构建注入清单..."
8
- node build-manifest.js
6
+ # patch-manifest.json 由手动维护,不再自动构建
9
7
 
10
8
  # 1. 添加所有变动
11
9
  git add .
package/build-manifest.js DELETED
@@ -1,141 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- /**
4
- * ============================================================================
5
- * build-manifest.js - 自动构建 patch-manifest.json
6
- * ============================================================================
7
- *
8
- * 扫描 agent-list/ 和 skills/ 目录,自动生成统一注入清单。
9
- * 已有的 strategy 设置会保留(不会被覆盖)。
10
- *
11
- * 在 publish.sh 中自动调用,无需手动维护 manifest。
12
- * ============================================================================
13
- */
14
-
15
- const fs = require('fs');
16
- const path = require('path');
17
-
18
- const MANIFEST_PATH = path.join(__dirname, 'patch-manifest.json');
19
- const AGENT_LIST_DIR = path.join(__dirname, 'agent-list');
20
- const SKILLS_DIR = path.join(__dirname, 'skills');
21
-
22
- // 默认 config patches(硬编码,不从目录扫描)
23
- const DEFAULT_CONFIG = {
24
- strategy: 'on',
25
- patches: {
26
- 'session.reset.mode': 'idle',
27
- 'session.reset.idleMinutes': 90720,
28
- 'tools.exec.ask': 'off',
29
- 'tools.exec.security': 'full',
30
- // 'gateway.auth.token': 'aiyiran',// 为了志新docker关闭掉
31
- 'plugins.entries.tavily.enabled': true,
32
- 'plugins.entries.tavily.config.webSearch.apiKey': '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,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',
33
- },
34
- };
35
-
36
- function buildManifest() {
37
- // 读取已有 manifest(保留手动设置的 strategy)
38
- let existing = { agents: [], skills: [], config: DEFAULT_CONFIG };
39
- if (fs.existsSync(MANIFEST_PATH)) {
40
- try {
41
- existing = JSON.parse(fs.readFileSync(MANIFEST_PATH, 'utf8'));
42
- } catch { }
43
- }
44
-
45
- // 建立已有策略映射(保留手动覆盖)
46
- const saved = {};
47
- for (const list of [existing.agents || [], existing.skills || []]) {
48
- for (const item of list) {
49
- const key = item.id || item.name;
50
- if (key && item.strategy) saved[key] = item.strategy;
51
- if (key && item.description) saved[key + '_desc'] = item.description;
52
- }
53
- }
54
-
55
- // === 1. 扫描 agent-list/ ===
56
- const agents = [];
57
- if (fs.existsSync(AGENT_LIST_DIR)) {
58
- const dirs = fs.readdirSync(AGENT_LIST_DIR, { withFileTypes: true })
59
- .filter(d => d.isDirectory() && d.name.startsWith('workspace-'))
60
- .sort((a, b) => a.name.localeCompare(b.name));
61
-
62
- for (const d of dirs) {
63
- const agentId = d.name.replace(/^workspace-/, '');
64
- agents.push({
65
- id: agentId,
66
- workspace: d.name,
67
- strategy: saved[agentId] || 'auto',
68
- description: saved[agentId + '_desc'] || agentId,
69
- });
70
- }
71
- }
72
-
73
- // === 2. 扫描 skills/ ===
74
- const skills = [];
75
- if (fs.existsSync(SKILLS_DIR)) {
76
- const dirs = fs.readdirSync(SKILLS_DIR, { withFileTypes: true })
77
- .filter(d => d.isDirectory())
78
- .sort((a, b) => a.name.localeCompare(b.name));
79
-
80
- for (const d of dirs) {
81
- // 必须有 SKILL.md 才是合法 skill
82
- const skillMd = path.join(SKILLS_DIR, d.name, 'SKILL.md');
83
- if (!fs.existsSync(skillMd)) continue;
84
-
85
- skills.push({
86
- name: d.name,
87
- strategy: saved[d.name] || 'auto',
88
- description: saved[d.name + '_desc'] || d.name,
89
- });
90
- }
91
- }
92
-
93
- // === 3. 合并 config(以 DEFAULT_CONFIG 为基础,保留旧 manifest 中手动添加的) ===
94
- const config = {
95
- ...DEFAULT_CONFIG,
96
- patches: {
97
- ...DEFAULT_CONFIG.patches,
98
- ...(existing.config?.patches || {}),
99
- },
100
- };
101
- // 确保 DEFAULT_CONFIG 中的新字段一定存在(防止旧 manifest 覆盖丢失)
102
- for (const [k, v] of Object.entries(DEFAULT_CONFIG.patches)) {
103
- config.patches[k] = v;
104
- }
105
-
106
- // === 4. 合并 run 命令列表(保留已有的,或使用默认的) ===
107
- const DEFAULT_RUN = [
108
- {
109
- "module": "./inject-image",
110
- "strategy": "auto",
111
- "description": "图片模型注入 (vveai)"
112
- }
113
- ];
114
- const runItems = (existing.run && Array.isArray(existing.run) && existing.run.length > 0)
115
- ? existing.run
116
- : DEFAULT_RUN;
117
-
118
- const manifest = {
119
- _doc: 'MyClaw 注入清单 (auto-generated)。strategy: auto | on | off | delete',
120
- _generated: new Date().toISOString(),
121
- agents,
122
- skills,
123
- config,
124
- run: runItems,
125
- };
126
-
127
- fs.writeFileSync(MANIFEST_PATH, JSON.stringify(manifest, null, 2) + '\n', 'utf8');
128
-
129
- console.log('📋 patch-manifest.json 已生成');
130
- console.log(' 智能体: ' + agents.length + ' 个');
131
- for (const a of agents) {
132
- console.log(' • ' + a.id + ' [' + a.strategy + ']');
133
- }
134
- console.log(' 技能: ' + skills.length + ' 个');
135
- for (const s of skills) {
136
- console.log(' • ' + s.name + ' [' + s.strategy + ']');
137
- }
138
- console.log(' 配置: ' + Object.keys(config.patches || {}).length + ' 项 [' + (config.strategy || 'on') + ']');
139
- }
140
-
141
- buildManifest();