thinknagent 0.1.13 → 0.1.15

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/lib/agent.js CHANGED
@@ -7,6 +7,8 @@ const LogWatcher = require('./logwatcher');
7
7
  const AlertEngine = require('./alerts');
8
8
  const ShellBridge = require('./shell');
9
9
  const store = require('./store');
10
+ const chokidar = require('chokidar');
11
+ const fs = require('fs');
10
12
 
11
13
  // allowed base dirs for log streaming
12
14
  // room owner agent:logs_updated se bahar ke paths reject ho jayenge
@@ -121,10 +123,52 @@ class Agent {
121
123
  if (this._active) this.logs.start();
122
124
  });
123
125
 
126
+ // Start watching the application path for git pulls or package.json updates
127
+ this._startAppWatcher(cfg);
128
+
124
129
  process.on('SIGTERM', () => this._shutdown('SIGTERM'));
125
130
  process.on('SIGINT', () => this._shutdown('SIGINT'));
126
131
  }
127
132
 
133
+ _startAppWatcher(cfg) {
134
+ if (!cfg.appPath) return;
135
+
136
+ try {
137
+ const resolvedPath = path.resolve(cfg.appPath);
138
+ const gitHeadPath = path.join(resolvedPath, '.git', 'HEAD');
139
+ const gitIndex = path.join(resolvedPath, '.git', 'index');
140
+ const pkgJsonPath = path.join(resolvedPath, 'package.json');
141
+
142
+ const filesToWatch = [];
143
+ if (fs.existsSync(gitHeadPath)) filesToWatch.push(gitHeadPath);
144
+ if (fs.existsSync(gitIndex)) filesToWatch.push(gitIndex);
145
+ if (fs.existsSync(pkgJsonPath)) filesToWatch.push(pkgJsonPath);
146
+
147
+ if (filesToWatch.length === 0) return;
148
+
149
+ console.log(`[agent] Watching application path for version changes: ${resolvedPath}`);
150
+ const watcher = chokidar.watch(filesToWatch, {
151
+ persistent: true,
152
+ ignoreInitial: true,
153
+ });
154
+
155
+ let debounceTimeout = null;
156
+ watcher.on('change', (filePath) => {
157
+ console.log(`[agent] Detected app file change: ${filePath}. Recalculating version...`);
158
+ if (debounceTimeout) clearTimeout(debounceTimeout);
159
+ debounceTimeout = setTimeout(() => {
160
+ const newVersion = Connection.getDeployedAppVersion(cfg.appPath);
161
+ console.log(`[agent] Reporting updated app version: ${newVersion}`);
162
+ this.conn.emit('agent:meta_update', { appVersion: newVersion });
163
+ }, 2000);
164
+ });
165
+
166
+ this._appWatcher = watcher;
167
+ } catch (err) {
168
+ console.warn(`[agent] Failed to initialize application path watcher: ${err.message}`);
169
+ }
170
+ }
171
+
128
172
  _onReady(role, roomId) {
129
173
  if (this._active) {
130
174
  console.log(`[agent] Reconnected. Role: ${role}`);
@@ -152,6 +196,11 @@ class Agent {
152
196
  this.metrics.stop();
153
197
  this.logs.stop();
154
198
  this.shell.killAll();
199
+ if (this._appWatcher) {
200
+ try {
201
+ this._appWatcher.close();
202
+ } catch (e) {}
203
+ }
155
204
  this.conn.socket?.disconnect();
156
205
  process.exit(0);
157
206
  }
package/lib/connect.js CHANGED
@@ -173,4 +173,5 @@ s.on('agent:approved', ({ agentToken, role, roomId }) => {
173
173
  }
174
174
  }
175
175
 
176
+ Connection.getDeployedAppVersion = getDeployedAppVersion;
176
177
  module.exports = Connection;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "thinknagent",
3
- "version": "0.1.13",
3
+ "version": "0.1.15",
4
4
  "description": "ThinkNCollab server agent — metrics, logs, alerts, shell bridge",
5
5
  "main": "lib/agent.js",
6
6
  "author": "ThinkNCollab Team <raman@thinkncollab.com>",