agentgui 1.0.816 → 1.0.818

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/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 2026-04-11
2
+ - refactor: split jsonl-watcher.js parse/event logic into jsonl-parser.js; watcher retains file watching/polling only
3
+ - refactor: split tool-version.js into tool-version-check.js (sync) and tool-version-fetch.js (async/network)
4
+
1
5
  ## [Unreleased]
2
6
  ### Refactor
3
7
  - Strip all standalone comment lines (// and /* */ block lines) from 14 static JS files: event-filter.js, image-loader.js, syntax-highlighter.js, client.js, streaming-renderer.js, ui-components.js, conversations.js, websocket-manager.js, conv-machine.js, ws-machine.js, ws-client.js, state-barrier.js, script-runner.js, theme.js. Total 781 comment lines removed. All files syntax-verified.
@@ -0,0 +1,179 @@
1
+ import path from 'path';
2
+
3
+ export class JsonlParser {
4
+ constructor({ broadcastSync, queries, ownedSessionIds }) {
5
+ this._bc = broadcastSync;
6
+ this._q = queries;
7
+ this._owned = ownedSessionIds;
8
+ this._convMap = new Map();
9
+ this._emitted = new Map();
10
+ this._seqs = new Map();
11
+ this._streaming = new Set();
12
+ this._sessions = new Map();
13
+ }
14
+
15
+ clear() {
16
+ this._convMap.clear();
17
+ this._emitted.clear();
18
+ this._seqs.clear();
19
+ this._streaming.clear();
20
+ this._sessions.clear();
21
+ }
22
+
23
+ removeSid(sid) {
24
+ this._convMap.delete(sid);
25
+ this._seqs.delete(sid);
26
+ this._streaming.delete(sid);
27
+ this._sessions.delete(sid);
28
+ for (const key of [...this._emitted.keys()]) if (key.startsWith(`${sid}:`)) this._emitted.delete(key);
29
+ }
30
+
31
+ endAllStreaming() {
32
+ for (const sid of [...this._streaming]) this._endStreaming(this._convMap.get(sid), sid);
33
+ }
34
+
35
+ _line(fp, line) {
36
+ line = line.trim(); if (!line) return;
37
+ let e; try { e = JSON.parse(line); } catch (_) { return; }
38
+ if (!e || !e.sessionId) return;
39
+ if (this._owned?.has(e.sessionId)) return;
40
+ const cid = this._conv(e.sessionId, e, fp);
41
+ if (cid) this._route(cid, e.sessionId, e);
42
+ }
43
+
44
+ _conv(sid, e) {
45
+ if (this._convMap.has(sid)) return this._convMap.get(sid);
46
+ const found = this._q.getConversations().find(c => c.claudeSessionId === sid);
47
+ if (found) { this._convMap.set(sid, found.id); return found.id; }
48
+ if (e.type === 'queue-operation' || e.type === 'last-prompt') return null;
49
+ if (e.type === 'user' && e.isMeta) return null;
50
+ const cwd = e.cwd || process.cwd();
51
+ const branch = e.gitBranch || '';
52
+ const base = path.basename(cwd);
53
+ const title = branch ? `${branch} @ ${base}` : base;
54
+ const conv = this._q.createConversation('claude-code', title, cwd);
55
+ this._q.setClaudeSessionId(conv.id, sid);
56
+ this._convMap.set(sid, conv.id);
57
+ this._bc({ type: 'conversation_created', conversation: conv, timestamp: Date.now() });
58
+ return conv.id;
59
+ }
60
+
61
+ _seq(sid) { const n = (this._seqs.get(sid) || 0) + 1; this._seqs.set(sid, n); return n; }
62
+
63
+ _dbSession(cid, sid) {
64
+ if (this._sessions.has(sid)) return this._sessions.get(sid);
65
+ const sess = this._q.createSession(cid);
66
+ this._q.updateSession(sess.id, { status: 'active' });
67
+ this._sessions.set(sid, sess.id);
68
+ return sess.id;
69
+ }
70
+
71
+ _emit(cid, sid, block, role, extra) {
72
+ const dbSid = this._dbSession(cid, sid);
73
+ const seq = this._seq(sid);
74
+ try { this._q.createChunk(dbSid, cid, seq, block.type || 'unknown', block); } catch (_) {}
75
+ this._bc({ type: 'streaming_progress', sessionId: dbSid, conversationId: cid, block, blockRole: role, seq, timestamp: Date.now(), ...extra });
76
+ }
77
+
78
+ _emitBlocks(cid, sid, blocks, role) {
79
+ for (const b of blocks) {
80
+ if (!b || !b.type) continue;
81
+ this._emit(cid, sid, b, role);
82
+ }
83
+ }
84
+
85
+ _startStreaming(cid, sid) {
86
+ if (this._streaming.has(sid)) return;
87
+ this._streaming.add(sid);
88
+ const dbSid = this._dbSession(cid, sid);
89
+ this._q.setIsStreaming(cid, true);
90
+ this._bc({ type: 'streaming_start', sessionId: dbSid, conversationId: cid, agentId: 'cli-claude', timestamp: Date.now() });
91
+ }
92
+
93
+ _endStreaming(cid, sid) {
94
+ if (!this._streaming.has(sid)) return;
95
+ this._streaming.delete(sid);
96
+ const dbSid = this._sessions.get(sid);
97
+ if (dbSid) {
98
+ try { this._q.updateSession(dbSid, { status: 'completed', completed_at: Date.now() }); } catch (_) {}
99
+ }
100
+ this._q.setIsStreaming(cid, false);
101
+ this._bc({ type: 'streaming_complete', sessionId: dbSid || sid, conversationId: cid, agentId: 'cli-claude', eventCount: 0, seq: this._seq(sid), timestamp: Date.now() });
102
+ this._sessions.delete(sid);
103
+ }
104
+
105
+ _route(cid, sid, e) {
106
+ if (e.type === 'queue-operation' || e.type === 'last-prompt' || (e.type === 'user' && e.isMeta)) return;
107
+
108
+ if (e.isApiErrorMessage && e.error === 'rate_limit') {
109
+ this._bc({ type: 'streaming_error', sessionId: this._sessions.get(sid) || sid, conversationId: cid, error: 'Rate limit hit', recoverable: true, timestamp: Date.now() });
110
+ return;
111
+ }
112
+
113
+ if (e.type === 'system') {
114
+ if (e.subtype === 'init') { this._startStreaming(cid, sid); return; }
115
+ if (e.subtype === 'turn_duration' || e.subtype === 'stop_hook_summary') { this._endStreaming(cid, sid); return; }
116
+ this._startStreaming(cid, sid);
117
+ this._emit(cid, sid, { type: 'system', subtype: e.subtype, model: e.model, cwd: e.cwd, tools: e.tools, preTokens: e.compactMetadata?.preTokens }, 'system');
118
+ return;
119
+ }
120
+
121
+ if (e.type === 'assistant' && e.message?.content) {
122
+ this._startStreaming(cid, sid);
123
+ const key = `${sid}:${e.message.id}`;
124
+ const prev = this._emitted.get(key) || 0;
125
+ const content = e.message.content;
126
+ const newBlocks = content.slice(prev);
127
+ if (newBlocks.length > 0) {
128
+ this._emitted.set(key, content.length);
129
+ this._emitBlocks(cid, sid, newBlocks, 'assistant');
130
+ }
131
+ if (e.message.stop_reason) this._emitted.delete(key);
132
+ return;
133
+ }
134
+
135
+ if (e.type === 'user' && e.message?.content) {
136
+ if (e.isCompactSummary) { this._emit(cid, sid, { type: 'compact_summary', content: e.message.content }, 'system'); return; }
137
+ this._startStreaming(cid, sid);
138
+ const content = e.message.content;
139
+ const textParts = Array.isArray(content)
140
+ ? content.filter(b => b.type === 'text' && b.text && !b.text.startsWith('<task-notification>')).map(b => b.text).join('\n')
141
+ : (typeof content === 'string' && !content.startsWith('<task-notification>') ? content : '');
142
+ if (textParts) {
143
+ try { this._q.createMessage(cid, 'user', textParts); } catch (_) {}
144
+ }
145
+ const blocks = Array.isArray(content) ? content : [];
146
+ for (const b of blocks) if (b.type === 'tool_result') this._emit(cid, sid, b, 'tool_result');
147
+ return;
148
+ }
149
+
150
+ if (e.type === 'progress') {
151
+ this._startStreaming(cid, sid);
152
+ const d = e.data || {};
153
+ if (d.type === 'agent_progress') {
154
+ const inner = d.message?.message || d.message;
155
+ const content = inner?.content;
156
+ if (Array.isArray(content)) {
157
+ const role = inner.role === 'user' ? 'tool_result' : 'assistant';
158
+ this._emitBlocks(cid, sid, content, role);
159
+ }
160
+ return;
161
+ }
162
+ if (d.type === 'hook_progress') {
163
+ this._emit(cid, sid, { type: 'hook_progress', hookEvent: d.hookEvent, hookName: d.hookName }, 'system');
164
+ return;
165
+ }
166
+ if (d.type === 'mcp_progress') {
167
+ this._emit(cid, sid, { type: 'mcp_progress', status: d.status, serverName: d.serverName, toolName: d.toolName }, 'system');
168
+ return;
169
+ }
170
+ this._emit(cid, sid, { type: d.type || e.subtype || 'progress', content: e.content || d }, 'progress');
171
+ return;
172
+ }
173
+
174
+ if (e.type === 'result') {
175
+ this._emit(cid, sid, { type: 'result', result: e.result, subtype: e.subtype, duration_ms: e.duration_ms, total_cost_usd: e.total_cost_usd, is_error: e.is_error || false }, 'result', { isResult: true });
176
+ this._endStreaming(cid, sid);
177
+ }
178
+ }
179
+ }
@@ -1,22 +1,16 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
3
  import os from 'os';
4
+ import { JsonlParser } from './jsonl-parser.js';
4
5
 
5
6
  const PROJECTS_DIR = path.join(os.homedir(), '.claude', 'projects');
6
7
  const DEBOUNCE_MS = 16;
7
8
 
8
9
  export class JsonlWatcher {
9
10
  constructor({ broadcastSync, queries, ownedSessionIds }) {
10
- this._bc = broadcastSync;
11
- this._q = queries;
12
- this._owned = ownedSessionIds;
11
+ this._parser = new JsonlParser({ broadcastSync, queries, ownedSessionIds });
13
12
  this._tails = new Map();
14
- this._convMap = new Map();
15
- this._emitted = new Map();
16
13
  this._timers = new Map();
17
- this._seqs = new Map();
18
- this._streaming = new Set();
19
- this._sessions = new Map();
20
14
  this._watcher = null;
21
15
  }
22
16
 
@@ -24,7 +18,7 @@ export class JsonlWatcher {
24
18
  if (!fs.existsSync(PROJECTS_DIR)) return;
25
19
  this._scanDir(PROJECTS_DIR, 0);
26
20
  for (const [fp, t] of this._timers.entries()) { clearTimeout(t); this._timers.delete(fp); this._read(fp); }
27
- for (const sid of [...this._streaming]) this._endStreaming(this._convMap.get(sid), sid);
21
+ this._parser.endAllStreaming();
28
22
  try {
29
23
  this._watcher = fs.watch(PROJECTS_DIR, { recursive: true }, (_, f) => {
30
24
  if (f && f.endsWith('.jsonl')) this._debounce(path.join(PROJECTS_DIR, f));
@@ -40,13 +34,9 @@ export class JsonlWatcher {
40
34
  }
41
35
 
42
36
  removeConversation(conversationId) {
43
- const sids = [...this._convMap.entries()].filter(([, cid]) => cid === conversationId).map(([sid]) => sid);
37
+ const sids = [...this._parser._convMap.entries()].filter(([, cid]) => cid === conversationId).map(([sid]) => sid);
44
38
  for (const sid of sids) {
45
- this._convMap.delete(sid);
46
- this._seqs.delete(sid);
47
- this._streaming.delete(sid);
48
- this._sessions.delete(sid);
49
- for (const key of [...this._emitted.keys()]) if (key.startsWith(`${sid}:`)) this._emitted.delete(key);
39
+ this._parser.removeSid(sid);
50
40
  for (const [fp, s] of this._tails.entries()) {
51
41
  if (!fp.includes(sid)) continue;
52
42
  if (s.fd !== null) try { fs.closeSync(s.fd); } catch (_) {}
@@ -60,9 +50,9 @@ export class JsonlWatcher {
60
50
  removeAllConversations() {
61
51
  for (const s of this._tails.values()) if (s.fd !== null) try { fs.closeSync(s.fd); } catch (_) {}
62
52
  for (const t of this._timers.values()) clearTimeout(t);
63
- this._tails.clear(); this._convMap.clear(); this._emitted.clear();
64
- this._timers.clear(); this._seqs.clear(); this._streaming.clear();
65
- this._sessions.clear();
53
+ this._tails.clear();
54
+ this._timers.clear();
55
+ this._parser.clear();
66
56
  }
67
57
 
68
58
  _scanDir(dir, depth) {
@@ -99,155 +89,10 @@ export class JsonlWatcher {
99
89
  s.partial = text.slice(start);
100
90
  const ms = Number(process.hrtime.bigint() - t0) / 1e6;
101
91
  if (ms > 5) console.warn(`[JsonlWatcher] hot path ${ms.toFixed(1)}ms (${lines.length} lines)`);
102
- for (const l of lines) this._line(fp, l);
92
+ for (const l of lines) this._parser._line(fp, l);
103
93
  } catch (e) {
104
94
  if (e.code !== 'ENOENT') console.error('[JsonlWatcher] read error:', e.message);
105
95
  if (s.fd !== null) { try { fs.closeSync(s.fd); } catch (_) {} s.fd = null; }
106
96
  }
107
97
  }
108
-
109
- _line(fp, line) {
110
- line = line.trim(); if (!line) return;
111
- let e; try { e = JSON.parse(line); } catch (_) { return; }
112
- if (!e || !e.sessionId) return;
113
- if (this._owned?.has(e.sessionId)) return;
114
- const cid = this._conv(e.sessionId, e, fp);
115
- if (cid) this._route(cid, e.sessionId, e);
116
- }
117
-
118
- _conv(sid, e) {
119
- if (this._convMap.has(sid)) return this._convMap.get(sid);
120
- const found = this._q.getConversations().find(c => c.claudeSessionId === sid);
121
- if (found) { this._convMap.set(sid, found.id); return found.id; }
122
- if (e.type === 'queue-operation' || e.type === 'last-prompt') return null;
123
- if (e.type === 'user' && e.isMeta) return null;
124
- const cwd = e.cwd || process.cwd();
125
- const branch = e.gitBranch || '';
126
- const base = path.basename(cwd);
127
- const title = branch ? `${branch} @ ${base}` : base;
128
- const conv = this._q.createConversation('claude-code', title, cwd);
129
- this._q.setClaudeSessionId(conv.id, sid);
130
- this._convMap.set(sid, conv.id);
131
- this._bc({ type: 'conversation_created', conversation: conv, timestamp: Date.now() });
132
- return conv.id;
133
- }
134
-
135
- _seq(sid) { const n = (this._seqs.get(sid) || 0) + 1; this._seqs.set(sid, n); return n; }
136
-
137
- _dbSession(cid, sid) {
138
- if (this._sessions.has(sid)) return this._sessions.get(sid);
139
- const sess = this._q.createSession(cid);
140
- this._q.updateSession(sess.id, { status: 'active' });
141
- this._sessions.set(sid, sess.id);
142
- return sess.id;
143
- }
144
-
145
- _emit(cid, sid, block, role, extra) {
146
- const dbSid = this._dbSession(cid, sid);
147
- const seq = this._seq(sid);
148
- try { this._q.createChunk(dbSid, cid, seq, block.type || 'unknown', block); } catch (_) {}
149
- this._bc({ type: 'streaming_progress', sessionId: dbSid, conversationId: cid, block, blockRole: role, seq, timestamp: Date.now(), ...extra });
150
- }
151
-
152
- _emitBlocks(cid, sid, blocks, role) {
153
- for (const b of blocks) {
154
- if (!b || !b.type) continue;
155
- this._emit(cid, sid, b, role);
156
- }
157
- }
158
-
159
- _startStreaming(cid, sid) {
160
- if (this._streaming.has(sid)) return;
161
- this._streaming.add(sid);
162
- const dbSid = this._dbSession(cid, sid);
163
- this._q.setIsStreaming(cid, true);
164
- this._bc({ type: 'streaming_start', sessionId: dbSid, conversationId: cid, agentId: 'cli-claude', timestamp: Date.now() });
165
- }
166
-
167
- _endStreaming(cid, sid) {
168
- if (!this._streaming.has(sid)) return;
169
- this._streaming.delete(sid);
170
- const dbSid = this._sessions.get(sid);
171
- if (dbSid) {
172
- try { this._q.updateSession(dbSid, { status: 'completed', completed_at: Date.now() }); } catch (_) {}
173
- }
174
- this._q.setIsStreaming(cid, false);
175
- this._bc({ type: 'streaming_complete', sessionId: dbSid || sid, conversationId: cid, agentId: 'cli-claude', eventCount: 0, seq: this._seq(sid), timestamp: Date.now() });
176
- this._sessions.delete(sid);
177
- }
178
-
179
- _route(cid, sid, e) {
180
- if (e.type === 'queue-operation' || e.type === 'last-prompt' || (e.type === 'user' && e.isMeta)) return;
181
-
182
- if (e.isApiErrorMessage && e.error === 'rate_limit') {
183
- this._bc({ type: 'streaming_error', sessionId: this._sessions.get(sid) || sid, conversationId: cid, error: 'Rate limit hit', recoverable: true, timestamp: Date.now() });
184
- return;
185
- }
186
-
187
- if (e.type === 'system') {
188
- if (e.subtype === 'init') { this._startStreaming(cid, sid); return; }
189
- if (e.subtype === 'turn_duration' || e.subtype === 'stop_hook_summary') { this._endStreaming(cid, sid); return; }
190
- this._startStreaming(cid, sid);
191
- this._emit(cid, sid, { type: 'system', subtype: e.subtype, model: e.model, cwd: e.cwd, tools: e.tools, preTokens: e.compactMetadata?.preTokens }, 'system');
192
- return;
193
- }
194
-
195
- if (e.type === 'assistant' && e.message?.content) {
196
- this._startStreaming(cid, sid);
197
- const key = `${sid}:${e.message.id}`;
198
- const prev = this._emitted.get(key) || 0;
199
- const content = e.message.content;
200
- const newBlocks = content.slice(prev);
201
- if (newBlocks.length > 0) {
202
- this._emitted.set(key, content.length);
203
- this._emitBlocks(cid, sid, newBlocks, 'assistant');
204
- }
205
- if (e.message.stop_reason) this._emitted.delete(key);
206
- return;
207
- }
208
-
209
- if (e.type === 'user' && e.message?.content) {
210
- if (e.isCompactSummary) { this._emit(cid, sid, { type: 'compact_summary', content: e.message.content }, 'system'); return; }
211
- this._startStreaming(cid, sid);
212
- const content = e.message.content;
213
- const textParts = Array.isArray(content)
214
- ? content.filter(b => b.type === 'text' && b.text && !b.text.startsWith('<task-notification>')).map(b => b.text).join('\n')
215
- : (typeof content === 'string' && !content.startsWith('<task-notification>') ? content : '');
216
- if (textParts) {
217
- try { this._q.createMessage(cid, 'user', textParts); } catch (_) {}
218
- }
219
- const blocks = Array.isArray(content) ? content : [];
220
- for (const b of blocks) if (b.type === 'tool_result') this._emit(cid, sid, b, 'tool_result');
221
- return;
222
- }
223
-
224
- if (e.type === 'progress') {
225
- this._startStreaming(cid, sid);
226
- const d = e.data || {};
227
- if (d.type === 'agent_progress') {
228
- const inner = d.message?.message || d.message;
229
- const content = inner?.content;
230
- if (Array.isArray(content)) {
231
- const role = inner.role === 'user' ? 'tool_result' : 'assistant';
232
- this._emitBlocks(cid, sid, content, role);
233
- }
234
- return;
235
- }
236
- if (d.type === 'hook_progress') {
237
- this._emit(cid, sid, { type: 'hook_progress', hookEvent: d.hookEvent, hookName: d.hookName }, 'system');
238
- return;
239
- }
240
- if (d.type === 'mcp_progress') {
241
- this._emit(cid, sid, { type: 'mcp_progress', status: d.status, serverName: d.serverName, toolName: d.toolName }, 'system');
242
- return;
243
- }
244
- this._emit(cid, sid, { type: d.type || e.subtype || 'progress', content: e.content || d }, 'progress');
245
- return;
246
- }
247
-
248
- if (e.type === 'result') {
249
- this._emit(cid, sid, { type: 'result', result: e.result, subtype: e.subtype, duration_ms: e.duration_ms, total_cost_usd: e.total_cost_usd, is_error: e.is_error || false }, 'result', { isResult: true });
250
- this._endStreaming(cid, sid);
251
- }
252
- }
253
98
  }
@@ -1,4 +1,4 @@
1
- import { checkToolViaBunx, clearVersionCache } from './tool-version.js';
1
+ import { checkToolViaBunx, clearVersionCache } from './tool-version-fetch.js';
2
2
  import { createInstaller } from './tool-spawner.js';
3
3
  import { autoProvision as _autoProvision, startPeriodicUpdateCheck as _startPeriodicUpdateCheck, stopPeriodicUpdateCheck } from './tool-provisioner.js';
4
4
 
@@ -1,4 +1,4 @@
1
- import { checkToolViaBunx } from './tool-version.js';
1
+ import { checkToolViaBunx } from './tool-version-fetch.js';
2
2
  import * as toolInstallMachine from './tool-install-machine.js';
3
3
 
4
4
  let updateCheckInterval = null;
@@ -1,6 +1,7 @@
1
1
  import { spawn } from 'child_process';
2
2
  import os from 'os';
3
- import { getCliVersion, getInstalledVersion, clearVersionCache, checkToolViaBunx } from './tool-version.js';
3
+ import { getCliVersion, getInstalledVersion } from './tool-version-check.js';
4
+ import { clearVersionCache, checkToolViaBunx } from './tool-version-fetch.js';
4
5
  import * as toolInstallMachine from './tool-install-machine.js';
5
6
 
6
7
  const isWindows = os.platform() === 'win32';
@@ -1,13 +1,12 @@
1
1
  import os from 'os';
2
2
  import fs from 'fs';
3
3
  import path from 'path';
4
- import https from 'https';
5
4
  import { execSync } from 'child_process';
6
5
 
7
6
  const isWindows = os.platform() === 'win32';
8
7
  const homeDir = os.homedir();
9
8
 
10
- const BIN_MAP = {
9
+ export const BIN_MAP = {
11
10
  '@anthropic-ai/claude-code': 'claude',
12
11
  'opencode-ai': 'opencode',
13
12
  '@google/gemini-cli': 'gemini',
@@ -31,7 +30,7 @@ function getClaudeInstalledPluginPath(pluginId) {
31
30
  return null;
32
31
  }
33
32
 
34
- const FRAMEWORK_PATHS = {
33
+ export const FRAMEWORK_PATHS = {
35
34
  claude: {
36
35
  pluginDir: (pluginId) => getClaudeInstalledPluginPath(pluginId) || path.join(homeDir, '.claude', 'plugins', pluginId),
37
36
  versionFile: (pluginId) => {
@@ -96,15 +95,12 @@ export function getInstalledVersion(pkg, pluginId = null, frameWork = null, tool
96
95
  const tool = tools.find(t => t.pkg === pkg);
97
96
  const actualPluginId = pluginId || tool?.pluginId || pkg;
98
97
  const actualFrameWork = frameWork || tool?.frameWork;
99
-
100
98
  const frameworks = actualFrameWork ? [actualFrameWork] : Object.keys(FRAMEWORK_PATHS);
101
99
  for (const fw of frameworks) {
102
100
  const fwConfig = FRAMEWORK_PATHS[fw];
103
101
  if (!fwConfig) continue;
104
-
105
102
  const version = tryReadVersion(fwConfig, actualPluginId);
106
103
  if (version) return version;
107
-
108
104
  if (fwConfig.fallbackInstalled) {
109
105
  const hasMarker = fwConfig.markerFile && fs.existsSync(fwConfig.markerFile(actualPluginId));
110
106
  const hasDir = fs.existsSync(fwConfig.pluginDir(actualPluginId));
@@ -177,62 +173,3 @@ export function compareVersions(v1, v2) {
177
173
  }
178
174
  return false;
179
175
  }
180
-
181
- const versionCache = new Map();
182
-
183
- export function getPublishedVersion(pkg) {
184
- const cacheKey = `published-${pkg}`;
185
- const cached = versionCache.get(cacheKey);
186
- if (cached && Date.now() - cached.timestamp < 3600000) {
187
- return cached.version;
188
- }
189
- return null;
190
- }
191
-
192
- export async function fetchPublishedVersion(pkg) {
193
- const cacheKey = `published-${pkg}`;
194
- const cached = versionCache.get(cacheKey);
195
- if (cached && Date.now() - cached.timestamp < 3600000) {
196
- return cached.version;
197
- }
198
- try {
199
- const version = await new Promise((resolve, reject) => {
200
- const url = `https://registry.npmjs.org/${pkg}/latest`;
201
- https.get(url, { headers: { 'User-Agent': 'agentgui-version-check/1.0' } }, (res) => {
202
- let data = '';
203
- res.on('data', chunk => { data += chunk; });
204
- res.on('end', () => {
205
- try { resolve(JSON.parse(data).version || null); } catch (e) { reject(e); }
206
- });
207
- }).on('error', reject);
208
- });
209
- if (version) versionCache.set(cacheKey, { version, timestamp: Date.now() });
210
- return version;
211
- } catch (_) {}
212
- return null;
213
- }
214
-
215
- export function clearVersionCache() {
216
- versionCache.clear();
217
- }
218
-
219
- export async function checkToolViaBunx(pkg, pluginId = null, category = 'plugin', frameWork = null, skipPublishedVersion = false, tools = []) {
220
- try {
221
- const isCli = category === 'cli';
222
- const installed = isCli ? checkCliInstalled(pkg) : checkToolInstalled(pluginId || pkg, frameWork);
223
- const installedVersion = isCli ? getCliVersion(pkg) : getInstalledVersion(pkg, pluginId, frameWork, tools);
224
- let publishedVersion = null;
225
- if (!skipPublishedVersion) {
226
- publishedVersion = await fetchPublishedVersion(pkg);
227
- }
228
- const needsUpdate = installed && publishedVersion && compareVersions(installedVersion, publishedVersion);
229
- const isUpToDate = installed && !needsUpdate;
230
- return { installed, isUpToDate, upgradeNeeded: needsUpdate, output: 'version-check', installedVersion, publishedVersion };
231
- } catch (err) {
232
- console.log(`[tool-manager] Error checking ${pkg}:`, err.message);
233
- const isCli = category === 'cli';
234
- const installed = isCli ? checkCliInstalled(pkg) : checkToolInstalled(pluginId || pkg, frameWork);
235
- const installedVersion = isCli ? getCliVersion(pkg) : getInstalledVersion(pkg, pluginId, frameWork, tools);
236
- return { installed, isUpToDate: false, upgradeNeeded: false, output: '', installedVersion, publishedVersion: null };
237
- }
238
- }
@@ -0,0 +1,61 @@
1
+ import https from 'https';
2
+ import { checkCliInstalled, getCliVersion, checkToolInstalled, compareVersions, getInstalledVersion } from './tool-version-check.js';
3
+
4
+ const versionCache = new Map();
5
+
6
+ export function getPublishedVersion(pkg) {
7
+ const cacheKey = `published-${pkg}`;
8
+ const cached = versionCache.get(cacheKey);
9
+ if (cached && Date.now() - cached.timestamp < 3600000) {
10
+ return cached.version;
11
+ }
12
+ return null;
13
+ }
14
+
15
+ export async function fetchPublishedVersion(pkg) {
16
+ const cacheKey = `published-${pkg}`;
17
+ const cached = versionCache.get(cacheKey);
18
+ if (cached && Date.now() - cached.timestamp < 3600000) {
19
+ return cached.version;
20
+ }
21
+ try {
22
+ const version = await new Promise((resolve, reject) => {
23
+ const url = `https://registry.npmjs.org/${pkg}/latest`;
24
+ https.get(url, { headers: { 'User-Agent': 'agentgui-version-check/1.0' } }, (res) => {
25
+ let data = '';
26
+ res.on('data', chunk => { data += chunk; });
27
+ res.on('end', () => {
28
+ try { resolve(JSON.parse(data).version || null); } catch (e) { reject(e); }
29
+ });
30
+ }).on('error', reject);
31
+ });
32
+ if (version) versionCache.set(cacheKey, { version, timestamp: Date.now() });
33
+ return version;
34
+ } catch (_) {}
35
+ return null;
36
+ }
37
+
38
+ export function clearVersionCache() {
39
+ versionCache.clear();
40
+ }
41
+
42
+ export async function checkToolViaBunx(pkg, pluginId = null, category = 'plugin', frameWork = null, skipPublishedVersion = false, tools = []) {
43
+ try {
44
+ const isCli = category === 'cli';
45
+ const installed = isCli ? checkCliInstalled(pkg) : checkToolInstalled(pluginId || pkg, frameWork);
46
+ const installedVersion = isCli ? getCliVersion(pkg) : getInstalledVersion(pkg, pluginId, frameWork, tools);
47
+ let publishedVersion = null;
48
+ if (!skipPublishedVersion) {
49
+ publishedVersion = await fetchPublishedVersion(pkg);
50
+ }
51
+ const needsUpdate = installed && publishedVersion && compareVersions(installedVersion, publishedVersion);
52
+ const isUpToDate = installed && !needsUpdate;
53
+ return { installed, isUpToDate, upgradeNeeded: needsUpdate, output: 'version-check', installedVersion, publishedVersion };
54
+ } catch (err) {
55
+ console.log(`[tool-manager] Error checking ${pkg}:`, err.message);
56
+ const isCli = category === 'cli';
57
+ const installed = isCli ? checkCliInstalled(pkg) : checkToolInstalled(pluginId || pkg, frameWork);
58
+ const installedVersion = isCli ? getCliVersion(pkg) : getInstalledVersion(pkg, pluginId, frameWork, tools);
59
+ return { installed, isUpToDate: false, upgradeNeeded: false, output: '', installedVersion, publishedVersion: null };
60
+ }
61
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentgui",
3
- "version": "1.0.816",
3
+ "version": "1.0.818",
4
4
  "description": "Multi-agent ACP client with real-time communication",
5
5
  "type": "module",
6
6
  "main": "electron/main.js",