@siftd/connect-agent 0.2.18 → 0.2.19

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/dist/agent.js CHANGED
@@ -8,110 +8,33 @@ import { startHeartbeat, stopHeartbeat, getHeartbeatState } from './heartbeat.js
8
8
  function stripAnsi(str) {
9
9
  return str.replace(/\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])/g, '');
10
10
  }
11
- // Lock to prevent concurrent updates
12
- let updateInProgress = false;
13
11
  /**
14
- * Get the installed version of connect-agent
15
- */
16
- function getInstalledVersion() {
17
- try {
18
- const output = execSync('npm list -g @siftd/connect-agent --depth=0 2>/dev/null', {
19
- encoding: 'utf8',
20
- shell: '/bin/bash'
21
- });
22
- const match = output.match(/@siftd\/connect-agent@([\d.]+)/);
23
- return match ? match[1] : 'unknown';
24
- }
25
- catch {
26
- return 'unknown';
27
- }
28
- }
29
- /**
30
- * Get the latest published version from npm
31
- */
32
- function getLatestVersion() {
33
- try {
34
- const output = execSync('npm view @siftd/connect-agent version 2>/dev/null', {
35
- encoding: 'utf8',
36
- shell: '/bin/bash'
37
- });
38
- return output.trim();
39
- }
40
- catch {
41
- return 'unknown';
42
- }
43
- }
44
- /**
45
- * Actually perform a self-update - runs npm install and restarts
12
+ * Self-update: npm install latest and restart
13
+ * Called from webapp banner or update command
46
14
  */
47
15
  async function performSelfUpdate() {
48
- // Prevent concurrent updates
49
- if (updateInProgress) {
50
- return '⏳ Update already in progress. Please wait...';
51
- }
52
- updateInProgress = true;
53
- console.log('[AGENT] Starting self-update...');
16
+ console.log('[AGENT] === SELF-UPDATE STARTING ===');
54
17
  try {
55
- // Get current version
56
- const currentVersion = getInstalledVersion();
57
- console.log('[AGENT] Current version:', currentVersion);
58
- // Check latest version first
59
- const latestVersion = getLatestVersion();
60
- console.log('[AGENT] Latest available:', latestVersion);
61
- if (currentVersion === latestVersion && currentVersion !== 'unknown') {
62
- updateInProgress = false;
63
- return `✅ Already on latest version (${currentVersion})`;
64
- }
18
+ // Just do it - npm install latest
65
19
  console.log('[AGENT] Running: npm install -g @siftd/connect-agent@latest');
66
- // Actually run the npm install with more detailed error capture
67
- let installOutput;
68
- try {
69
- installOutput = execSync('npm install -g @siftd/connect-agent@latest 2>&1', {
70
- encoding: 'utf8',
71
- shell: '/bin/bash',
72
- timeout: 180000, // 3 minute timeout
73
- maxBuffer: 10 * 1024 * 1024 // 10MB buffer
74
- });
75
- }
76
- catch (installError) {
77
- const err = installError;
78
- const output = err.stdout || err.stderr || err.message || 'Unknown install error';
79
- console.error('[AGENT] npm install failed:', output);
80
- updateInProgress = false;
81
- // Parse common npm errors
82
- if (output.includes('EACCES') || output.includes('permission denied')) {
83
- return `❌ Permission denied. Try running:\nsudo npm install -g @siftd/connect-agent@latest`;
84
- }
85
- if (output.includes('ENOTFOUND') || output.includes('network')) {
86
- return `❌ Network error. Check your internet connection and try again.`;
87
- }
88
- if (output.includes('E404')) {
89
- return `❌ Package not found on npm. The package may have been unpublished.`;
90
- }
91
- return `❌ Update failed:\n${output.slice(0, 500)}\n\nRun manually:\nnpm install -g @siftd/connect-agent@latest`;
92
- }
93
- console.log('[AGENT] Install output:', installOutput.slice(0, 500));
94
- // Verify the update succeeded
95
- const newVersion = getInstalledVersion();
96
- console.log('[AGENT] New version:', newVersion);
97
- if (newVersion === currentVersion && currentVersion !== 'unknown') {
98
- updateInProgress = false;
99
- return `⚠️ Version unchanged (${currentVersion}). npm may have used cache.\n\nTry: npm cache clean --force && npm install -g @siftd/connect-agent@latest`;
100
- }
101
- // Schedule restart
102
- console.log('[AGENT] Scheduling restart in 3 seconds...');
20
+ execSync('npm install -g @siftd/connect-agent@latest', {
21
+ encoding: 'utf8',
22
+ shell: '/bin/bash',
23
+ stdio: 'inherit', // Show output in real-time
24
+ timeout: 180000
25
+ });
26
+ console.log('[AGENT] Update installed. Restarting in 2 seconds...');
27
+ // Restart the agent
103
28
  setTimeout(() => {
104
- console.log('[AGENT] Restarting...');
105
- updateInProgress = false;
106
- process.exit(0); // Exit - systemd/pm2/user will restart
107
- }, 3000);
108
- return `✅ Update complete!\n\n${currentVersion} → ${newVersion}\n\nRestarting agent in 3 seconds...`;
29
+ console.log('[AGENT] === RESTARTING ===');
30
+ process.exit(0);
31
+ }, 2000);
32
+ return '✅ Update installed. Restarting...';
109
33
  }
110
34
  catch (error) {
111
- updateInProgress = false;
112
- const errMsg = error instanceof Error ? error.message : String(error);
113
- console.error('[AGENT] Update failed:', errMsg);
114
- return `❌ Update failed: ${errMsg}\n\nYou may need to run manually:\nnpm install -g @siftd/connect-agent@latest`;
35
+ const msg = error instanceof Error ? error.message : String(error);
36
+ console.error('[AGENT] Update failed:', msg);
37
+ return `❌ Update failed: ${msg}`;
115
38
  }
116
39
  }
117
40
  // Conversation history for orchestrator mode
@@ -258,10 +181,9 @@ export async function processMessage(message) {
258
181
  );
259
182
  return response;
260
183
  }
261
- // Handle self-update requests - ACTUALLY run the update, don't just pretend
262
- if (content.includes('update') && content.includes('connect-agent') &&
263
- (content.includes('npm install') || content.includes('latest'))) {
264
- console.log('[AGENT] Self-update request detected - forcing actual execution');
184
+ // Handle self-update requests - trigger on "update" keyword
185
+ if (content.includes('update') && (content.includes('agent') || content.includes('yourself') || content.includes('latest'))) {
186
+ console.log('[AGENT] Update request detected');
265
187
  return await performSelfUpdate();
266
188
  }
267
189
  try {
package/dist/heartbeat.js CHANGED
@@ -10,7 +10,7 @@ import { hostname } from 'os';
10
10
  import { createHash } from 'crypto';
11
11
  import { getServerUrl, getAgentToken, getUserId, isCloudMode } from './config.js';
12
12
  const HEARTBEAT_INTERVAL = 10000; // 10 seconds
13
- const VERSION = '0.2.18'; // Should match package.json
13
+ const VERSION = '0.2.19'; // Should match package.json
14
14
  const state = {
15
15
  intervalId: null,
16
16
  runnerId: null,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@siftd/connect-agent",
3
- "version": "0.2.18",
3
+ "version": "0.2.19",
4
4
  "description": "Master orchestrator agent - control Claude Code remotely via web",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",