indieclaw-agent 2.2.0 → 2.3.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 (3) hide show
  1. package/index.js +34 -45
  2. package/install.sh +14 -4
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -144,63 +144,52 @@ try {
144
144
  }
145
145
 
146
146
  // --- OpenClaw Detection ---
147
- const OPENCLAW_PORTS = [18789, 8080, 11434, 1234, 8000];
148
-
149
- function tryOpenClawPort(port) {
147
+ function detectOpenClaw() {
150
148
  return new Promise((resolve) => {
151
- const req = http.request(
152
- {
153
- hostname: '127.0.0.1',
154
- port,
155
- path: '/v1/models',
156
- method: 'GET',
157
- timeout: 2000,
158
- },
159
- (res) => {
160
- let body = '';
161
- res.on('data', (chunk) => (body += chunk));
162
- res.on('end', () => {
163
- try {
164
- const json = JSON.parse(body);
165
- const models = (json.data || []).map((m) => m.id);
166
- if (models.length > 0) {
167
- resolve({ available: true, models, port });
168
- } else {
169
- resolve({ available: false, models: [], port });
149
+ // Method 1: Use `openclaw gateway status` CLI (most reliable)
150
+ exec('openclaw gateway status 2>&1', { timeout: 5000 }, (err, stdout) => {
151
+ const output = (stdout || '').toLowerCase();
152
+ // "running" in output means gateway is active
153
+ if (!err && (output.includes('running') || output.includes('active'))) {
154
+ // Try to get the gateway port from config
155
+ const portMatch = (stdout || '').match(/:(\d+)/);
156
+ const port = portMatch ? parseInt(portMatch[1], 10) : 18789;
157
+ return resolve({ available: true, models: ['openclaw'], port });
158
+ }
159
+
160
+ // Method 2: Check if openclaw binary exists at all
161
+ exec('command -v openclaw 2>/dev/null', { timeout: 2000 }, (err2, binPath) => {
162
+ if (err2 || !binPath?.trim()) {
163
+ // Method 3: Check if openclaw-gateway process is running
164
+ exec('pgrep -f "openclaw.gateway\\|openclaw-gateway" 2>/dev/null', { timeout: 2000 }, (err3, pid) => {
165
+ if (!err3 && pid?.trim()) {
166
+ return resolve({ available: true, models: ['openclaw'], port: 18789 });
170
167
  }
171
- } catch {
172
- resolve({ available: false, models: [], port });
168
+ return resolve({ available: false, models: [], port: null });
169
+ });
170
+ return;
171
+ }
172
+
173
+ // Binary exists but gateway might not be running — try health check
174
+ exec('openclaw gateway health --url ws://127.0.0.1:18789 2>&1', { timeout: 5000 }, (err4, healthOut) => {
175
+ const hOutput = (healthOut || '').toLowerCase();
176
+ if (!err4 && (hOutput.includes('ok') || hOutput.includes('healthy') || hOutput.includes('reachable'))) {
177
+ return resolve({ available: true, models: ['openclaw'], port: 18789 });
173
178
  }
179
+ // Binary installed but gateway not running
180
+ return resolve({ available: false, models: [], port: null });
174
181
  });
175
- }
176
- );
177
- req.on('timeout', () => {
178
- req.destroy();
179
- resolve({ available: false, models: [], port });
180
- });
181
- req.on('error', () => {
182
- resolve({ available: false, models: [], port });
182
+ });
183
183
  });
184
- req.end();
185
184
  });
186
185
  }
187
186
 
188
- async function detectOpenClaw() {
189
- // Try all common ports in parallel
190
- const results = await Promise.all(OPENCLAW_PORTS.map(tryOpenClawPort));
191
- const found = results.find((r) => r.available);
192
- if (found) {
193
- return { available: true, models: found.models, port: found.port };
194
- }
195
- return { available: false, models: [], port: null };
196
- }
197
-
198
187
  // Run detection on startup
199
188
  detectOpenClaw().then((oc) => {
200
189
  if (oc.available) {
201
- console.log(` [OpenClaw] Detected on port ${oc.port}! Models: ${oc.models.join(', ')}`);
190
+ console.log(` [OpenClaw] Detected (gateway running on port ${oc.port})`);
202
191
  } else {
203
- console.log(` [OpenClaw] Not detected on ports ${OPENCLAW_PORTS.join(', ')}`);
192
+ console.log(' [OpenClaw] Not detected');
204
193
  }
205
194
  });
206
195
 
package/install.sh CHANGED
@@ -110,11 +110,21 @@ echo -e " ${GREEN}✓${NC} IP: ${MACHINE_IP}"
110
110
  # Step 5: Check OpenClaw
111
111
  echo -e "${YELLOW}[5/5]${NC} Checking OpenClaw..."
112
112
  OPENCLAW_STATUS="not detected"
113
- if curl -s --max-time 2 http://127.0.0.1:18789/v1/models > /dev/null 2>&1; then
114
- OPENCLAW_STATUS="detected on port 18789"
115
- echo -e " ${GREEN}✓${NC} OpenClaw detected on port 18789"
113
+ # Check via CLI (gateway status), then via process, then via binary existence
114
+ if command -v openclaw &> /dev/null; then
115
+ OC_STATUS=$(openclaw gateway status 2>&1 || true)
116
+ if echo "$OC_STATUS" | grep -qi "running\|active"; then
117
+ OPENCLAW_STATUS="running"
118
+ echo -e " ${GREEN}✓${NC} OpenClaw gateway is running"
119
+ elif pgrep -f "openclaw.gateway\|openclaw-gateway" > /dev/null 2>&1; then
120
+ OPENCLAW_STATUS="running"
121
+ echo -e " ${GREEN}✓${NC} OpenClaw gateway process detected"
122
+ else
123
+ OPENCLAW_STATUS="installed (gateway not running)"
124
+ echo -e " ${YELLOW}—${NC} OpenClaw installed but gateway not running. Start with: openclaw gateway run"
125
+ fi
116
126
  else
117
- echo -e " ${YELLOW}—${NC} OpenClaw not detected on port 18789 (optional, for AI features)"
127
+ echo -e " ${YELLOW}—${NC} OpenClaw not installed (optional, for AI features)"
118
128
  fi
119
129
 
120
130
  # Build deep link
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "indieclaw-agent",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "description": "Manage your server from your phone. Agent for the IndieClaw mobile app.",
5
5
  "main": "index.js",
6
6
  "bin": {