termify-agent 1.0.12 → 1.0.13

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.
@@ -5,38 +5,113 @@
5
5
  *
6
6
  * Runs automatically after `npm install` to:
7
7
  * 1. Rebuild node-pty native module for the current platform
8
- * 2. Download the stats-agent binary for system monitoring
8
+ * 2. Download the termify-daemon binary for process monitoring and system stats
9
+ * 3. Download the stats-agent binary for detailed system monitoring (fallback)
9
10
  */
10
11
 
11
12
  import { execSync } from 'child_process';
12
- import { createWriteStream, mkdirSync, chmodSync, existsSync } from 'fs';
13
+ import { createWriteStream, mkdirSync, chmodSync, existsSync, unlinkSync } from 'fs';
13
14
  import { join } from 'path';
14
15
  import { homedir, platform, arch } from 'os';
15
16
  import { get } from 'https';
16
17
 
17
- const DOWNLOAD_BASE_URL = 'https://termify.justdiego.com/api/downloads/stats-agent';
18
+ const DOWNLOAD_BASE_URL = 'https://termify.justdiego.com/api/downloads';
18
19
  const TERMIFY_DIR = join(homedir(), '.termify');
20
+ const DAEMON_PATH = join(TERMIFY_DIR, 'termify-daemon');
19
21
  const STATS_AGENT_PATH = join(TERMIFY_DIR, 'stats-agent');
20
22
 
21
23
  /**
22
- * Step 1: Rebuild node-pty
24
+ * Step 1: Rebuild node-pty with improved error handling
23
25
  */
24
26
  function rebuildNodePty() {
25
27
  console.log('[termify-agent] Rebuilding node-pty for your platform...');
28
+
26
29
  try {
30
+ // First try regular rebuild
27
31
  execSync('npm rebuild node-pty', {
28
32
  stdio: 'pipe',
29
- timeout: 120000,
33
+ timeout: 180000,
30
34
  });
31
35
  console.log('[termify-agent] node-pty rebuilt successfully.');
36
+ return true;
37
+ } catch (err) {
38
+ console.warn('[termify-agent] Warning: npm rebuild node-pty failed.');
39
+ console.warn('[termify-agent] Attempting to reinstall node-pty...');
40
+
41
+ try {
42
+ // Try removing and reinstalling
43
+ execSync('rm -rf node_modules/node-pty && npm install node-pty', {
44
+ stdio: 'pipe',
45
+ timeout: 180000,
46
+ });
47
+ console.log('[termify-agent] node-pty reinstalled successfully.');
48
+ return true;
49
+ } catch (err2) {
50
+ console.error('[termify-agent] CRITICAL: node-pty installation failed.');
51
+ console.error('[termify-agent] Terminal features will NOT work.');
52
+ console.error('[termify-agent] Manual fix required:');
53
+ console.error(`[termify-agent] cd ${process.cwd()}`);
54
+ console.error('[termify-agent] npm rebuild node-pty');
55
+ console.error('[termify-agent]');
56
+ console.error('[termify-agent] If that fails, try:');
57
+ console.error('[termify-agent] rm -rf node_modules/node-pty');
58
+ console.error('[termify-agent] npm install node-pty');
59
+ return false;
60
+ }
61
+ }
62
+ }
63
+
64
+ /**
65
+ * Step 2: Download termify-daemon binary (new efficient daemon)
66
+ */
67
+ async function downloadDaemon() {
68
+ const plat = platform();
69
+ const ar = arch();
70
+
71
+ // Map Node.js platform/arch to our binary names
72
+ const platformMap = {
73
+ 'darwin-arm64': 'darwin-arm64',
74
+ 'darwin-x64': 'darwin-x64',
75
+ 'linux-x64': 'linux-x64',
76
+ 'linux-arm64': 'linux-arm64',
77
+ };
78
+
79
+ const key = `${plat}-${ar}`;
80
+ const binaryName = platformMap[key];
81
+
82
+ if (!binaryName) {
83
+ console.warn(`[termify-agent] Warning: No termify-daemon binary available for ${key}.`);
84
+ console.warn('[termify-agent] Process monitoring will use fallback (pgrep).');
85
+ return false;
86
+ }
87
+
88
+ // Skip if already exists (user can delete to force re-download)
89
+ if (existsSync(DAEMON_PATH)) {
90
+ console.log('[termify-agent] termify-daemon binary already exists, skipping download.');
91
+ return true;
92
+ }
93
+
94
+ console.log(`[termify-agent] Downloading termify-daemon for ${binaryName}...`);
95
+
96
+ // Ensure ~/.termify directory exists
97
+ mkdirSync(TERMIFY_DIR, { recursive: true });
98
+
99
+ const url = `${DOWNLOAD_BASE_URL}/termify-daemon/${binaryName}`;
100
+
101
+ try {
102
+ await downloadFile(url, DAEMON_PATH);
103
+ chmodSync(DAEMON_PATH, 0o755);
104
+ console.log(`[termify-agent] termify-daemon installed to ${DAEMON_PATH}`);
105
+ return true;
32
106
  } catch (err) {
33
- console.warn('[termify-agent] Warning: Failed to rebuild node-pty.');
34
- console.warn('[termify-agent] Terminal features may not work. Try running: npm rebuild node-pty');
107
+ console.warn(`[termify-agent] Warning: Failed to download termify-daemon: ${err.message}`);
108
+ console.warn('[termify-agent] Process monitoring will use fallback (pgrep).');
109
+ return false;
35
110
  }
36
111
  }
37
112
 
38
113
  /**
39
- * Step 2: Download stats-agent binary
114
+ * Step 3: Download stats-agent binary (fallback for detailed stats)
40
115
  */
41
116
  async function downloadStatsAgent() {
42
117
  const plat = platform();
@@ -55,7 +130,7 @@ async function downloadStatsAgent() {
55
130
 
56
131
  if (!binaryName) {
57
132
  console.warn(`[termify-agent] Warning: No stats-agent binary available for ${key}.`);
58
- console.warn('[termify-agent] System stats collection will be disabled.');
133
+ console.warn('[termify-agent] Detailed system stats collection will be disabled.');
59
134
  return;
60
135
  }
61
136
 
@@ -70,7 +145,7 @@ async function downloadStatsAgent() {
70
145
  // Ensure ~/.termify directory exists
71
146
  mkdirSync(TERMIFY_DIR, { recursive: true });
72
147
 
73
- const url = `${DOWNLOAD_BASE_URL}/${binaryName}`;
148
+ const url = `${DOWNLOAD_BASE_URL}/stats-agent/${binaryName}`;
74
149
 
75
150
  try {
76
151
  await downloadFile(url, STATS_AGENT_PATH);
@@ -78,7 +153,7 @@ async function downloadStatsAgent() {
78
153
  console.log(`[termify-agent] stats-agent installed to ${STATS_AGENT_PATH}`);
79
154
  } catch (err) {
80
155
  console.warn(`[termify-agent] Warning: Failed to download stats-agent: ${err.message}`);
81
- console.warn('[termify-agent] System stats collection will be disabled.');
156
+ console.warn('[termify-agent] Detailed system stats collection will be disabled.');
82
157
  }
83
158
  }
84
159
 
@@ -111,6 +186,8 @@ function downloadFile(url, dest, redirects = 0) {
111
186
  });
112
187
  file.on('error', (err) => {
113
188
  file.close();
189
+ // Clean up partial download
190
+ try { unlinkSync(dest); } catch {}
114
191
  reject(err);
115
192
  });
116
193
  });
@@ -128,9 +205,22 @@ function downloadFile(url, dest, redirects = 0) {
128
205
  */
129
206
  async function main() {
130
207
  console.log('[termify-agent] Running postinstall...');
208
+ console.log(`[termify-agent] Platform: ${platform()}-${arch()}`);
209
+
210
+ // Step 1: Rebuild node-pty (critical for terminal functionality)
211
+ const nodePtyOk = rebuildNodePty();
212
+ if (!nodePtyOk) {
213
+ console.error('[termify-agent] WARNING: Terminal features may not work until node-pty is fixed.');
214
+ }
131
215
 
132
- rebuildNodePty();
216
+ // Step 2: Download termify-daemon (efficient process monitoring)
217
+ try {
218
+ await downloadDaemon();
219
+ } catch (err) {
220
+ console.warn(`[termify-agent] Warning: ${err.message}`);
221
+ }
133
222
 
223
+ // Step 3: Download stats-agent (fallback for detailed stats)
134
224
  try {
135
225
  await downloadStatsAgent();
136
226
  } catch (err) {