specialist-agent 3.2.0 → 3.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.
@@ -1,11 +1,12 @@
1
- // ../../apps/gerenciador/src/agente/workers/hw-worker.ts
1
+ // ../../apps/manager/src/agent/workers/hw-worker.ts
2
+ import { homedir } from "node:os";
2
3
  import { parentPort, workerData } from "node:worker_threads";
3
4
 
4
5
  // ../core/src/node/hardware.ts
5
6
  import { spawnSync } from "node:child_process";
6
- import { existsSync, readdirSync, readFileSync } from "node:fs";
7
+ import { existsSync, readdirSync, readFileSync, statfsSync } from "node:fs";
7
8
  import { totalmem } from "node:os";
8
- import { join } from "node:path";
9
+ import { dirname, join, resolve } from "node:path";
9
10
 
10
11
  // ../core/src/hardware.ts
11
12
  function currentOS(platform) {
@@ -15,9 +16,10 @@ function currentOS(platform) {
15
16
  }
16
17
  var NV = { "1050": 2, "1050 ti": 4, "1060": 6, "1070": 8, "1070 ti": 8, "1080": 8, "1080 ti": 11, "1630": 4, "1650": 4, "1650 super": 4, "1660": 6, "1660 super": 6, "1660 ti": 6, "2060": 6, "2060 super": 8, "2070": 8, "2070 super": 8, "2080": 8, "2080 super": 8, "2080 ti": 11, "3050": 8, "3060": 12, "3060 ti": 8, "3070": 8, "3070 ti": 8, "3080": 10, "3080 ti": 12, "3090": 24, "3090 ti": 24, "4060": 8, "4060 ti": 8, "4070": 12, "4070 super": 12, "4070 ti": 12, "4070 ti super": 16, "4080": 16, "4080 super": 16, "4090": 24, "5050": 8, "5060": 8, "5060 ti": 16, "5070": 12, "5070 ti": 16, "5080": 16, "5090": 32 };
17
18
  var NVL = { "1650": 4, "1660 ti": 6, "2050": 4, "2060": 6, "2070": 8, "2080": 8, "3050": 4, "3050 ti": 4, "3060": 6, "3070": 8, "3070 ti": 8, "3080": 8, "3080 ti": 16, "4050": 6, "4060": 8, "4070": 8, "4080": 12, "4090": 16, "5050": 8, "5060": 8, "5070": 8, "5070 ti": 12, "5080": 16, "5090": 24 };
18
- var NV_VAR = { "1060": "3 ou 6 GB", "2060": "6 ou 12 GB", "3050": "6 ou 8 GB", "3060": "8 ou 12 GB", "3080": "10 ou 12 GB", "4060 ti": "8 ou 16 GB", "5060 ti": "8 ou 16 GB" };
19
+ var NV_VAR = { "1060": [3, 6], "2060": [6, 12], "3050": [6, 8], "3060": [8, 12], "3080": [10, 12], "4060 ti": [8, 16], "5060 ti": [8, 16] };
19
20
  var AMD = { "570": 4, "580": 8, "590": 8, "5500 xt": 8, "5600 xt": 6, "5700": 8, "5700 xt": 8, "6400": 4, "6500 xt": 4, "6600": 8, "6600 xt": 8, "6650 xt": 8, "6700": 10, "6700 xt": 12, "6750 xt": 12, "6800": 16, "6800 xt": 16, "6900 xt": 16, "6950 xt": 16, "7600": 8, "7600 xt": 16, "7700 xt": 12, "7800 xt": 16, "7900 gre": 16, "7900 xt": 20, "7900 xtx": 24, "9060 xt": 16, "9070": 16, "9070 xt": 16 };
20
21
  var ARC = { a310: 4, a380: 6, a580: 8, a750: 8, a770: 16, b570: 10, b580: 12 };
22
+ var APPLE_CHIP = /\bM[1-9]\b/;
21
23
  function parseGPU(raw) {
22
24
  const s = String(raw || "").replace(/\((R|TM|C)\)/gi, " ");
23
25
  const out = { brand: "", vram: null, gpu: "", note: "" };
@@ -32,9 +34,10 @@ function parseGPU(raw) {
32
34
  out.gpu = m[1].toUpperCase() + " " + m[2] + (m[3] ? " Ti" : "") + (m[4] ? " Super" : "") + (laptop ? " (notebook)" : "");
33
35
  const v = (laptop ? NVL[key] : void 0) ?? NV[key];
34
36
  if (v != null) out.vram = v;
35
- if (!laptop && NV_VAR[key]) out.note = "Existe vers\xE3o de " + NV_VAR[key] + ". Confira.";
37
+ const sizes = laptop ? void 0 : NV_VAR[key];
38
+ if (sizes) out.note = `Existe vers\xE3o de ${sizes[0]} ou ${sizes[1]} GB. Confira.`;
36
39
  } else out.gpu = "NVIDIA";
37
- } else if ((/apple/i.test(s) || /\bM[1-9]\b/.test(s)) && !/intel|radeon/i.test(s)) {
40
+ } else if ((/apple/i.test(s) || APPLE_CHIP.test(s)) && !/intel|radeon/i.test(s)) {
38
41
  out.brand = "apple";
39
42
  out.gpu = "Chip Apple";
40
43
  out.note = "No Mac, a placa usa a mem\xF3ria do sistema.";
@@ -67,20 +70,30 @@ function parseGPU(raw) {
67
70
  function parseNvidiaSmi(text) {
68
71
  return String(text || "").split(/\r?\n/).map((l) => l.split(",")).filter((p) => p.length >= 2 && p[0].trim()).map((p) => ({ name: p[0].trim(), vram: Math.round(parseFloat(p[1]) / 1024) })).filter((g) => Number.isFinite(g.vram));
69
72
  }
70
- function parseWinVideo(json) {
73
+ var WIN_4GB_NOTE = "O Windows s\xF3 informa at\xE9 4 GB. Se a sua placa tiver mais, use --vram.";
74
+ var parseJsonList = (json) => {
71
75
  let data;
72
76
  try {
73
77
  data = JSON.parse(String(json || "").trim() || "null");
74
78
  } catch {
75
79
  return [];
76
80
  }
77
- const list = Array.isArray(data) ? data : data ? [data] : [];
81
+ return Array.isArray(data) ? data : data ? [data] : [];
82
+ };
83
+ function parseWinRegistryVram(json) {
84
+ return parseJsonList(json).filter((a) => a && typeof a.DriverDesc === "string" && a.DriverDesc.trim()).map((a) => ({ name: String(a.DriverDesc).trim(), vram: Math.round(Number(a["HardwareInformation.qwMemorySize"]) / 2 ** 30) })).filter((g) => Number.isFinite(g.vram) && g.vram > 0);
85
+ }
86
+ function parseWinVideo(json, registry = []) {
87
+ const list = parseJsonList(json);
78
88
  return list.filter((a) => a && a.Name).map((a) => {
89
+ const name = String(a.Name).trim();
79
90
  const p = parseGPU(a.Name);
80
91
  const gb = Number(a.AdapterRAM) > 0 ? Number(a.AdapterRAM) / 2 ** 30 : null;
92
+ const fromRegistry = registry.find((r) => r.name.toLowerCase() === name.toLowerCase())?.vram;
81
93
  let vram = p.vram;
94
+ if (vram == null && fromRegistry) return { name, brand: p.brand, vram: fromRegistry, approx: true, note: p.note || "" };
82
95
  if (vram == null && gb != null) vram = gb >= 3.9 ? 4 : Math.round(gb);
83
- return { name: String(a.Name).trim(), brand: p.brand, vram, approx: true, note: p.note || (gb != null && gb >= 3.9 && p.vram == null ? "O Windows s\xF3 informa at\xE9 4 GB. Se a sua placa tiver mais, use --vram." : "") };
96
+ return { name, brand: p.brand, vram, approx: true, note: p.note || (gb != null && gb >= 3.9 && p.vram == null ? WIN_4GB_NOTE : "") };
84
97
  });
85
98
  }
86
99
  function parseLspci(text) {
@@ -128,9 +141,10 @@ function capture(file, args, timeout = 15e3) {
128
141
  return { status: null, stdout: "" };
129
142
  }
130
143
  }
144
+ var WIN_REGISTRY_VRAM = "Get-ItemProperty 'HKLM:\\SYSTEM\\CurrentControlSet\\Control\\Class\\{4d36e968-e325-11ce-bfc1-08002be10318}\\0*' -ErrorAction SilentlyContinue | Select-Object DriverDesc,'HardwareInformation.qwMemorySize' | ConvertTo-Json";
131
145
  var VENDORS = { "0x10de": "nvidia", "0x1002": "amd", "0x8086": "intel" };
132
146
  var linuxSys = {
133
- // Sem lspci: lê o fabricante direto do /sys.
147
+ // Without lspci: reads the vendor straight from /sys.
134
148
  pciGPUs() {
135
149
  const root = "/sys/bus/pci/devices";
136
150
  const out = [];
@@ -168,6 +182,20 @@ function nvidiaSmi(run, os2) {
168
182
  const gpus = parseNvidiaSmi(r.stdout).sort((a, b) => b.vram - a.vram);
169
183
  return gpus[0] || null;
170
184
  }
185
+ function freeDiskGB(folder, readDisk = statfsSync) {
186
+ let p = resolve(folder);
187
+ while (!existsSync(p)) {
188
+ const above = dirname(p);
189
+ if (above === p) return null;
190
+ p = above;
191
+ }
192
+ try {
193
+ const st = readDisk(p);
194
+ return Math.floor(Number(st.bavail) * Number(st.bsize) / 2 ** 30);
195
+ } catch {
196
+ return null;
197
+ }
198
+ }
171
199
  function detectHardware({ os: os2 = currentOS(process.platform), run = capture, mem = totalmem(), arch = process.arch, sys = linuxSys } = {}) {
172
200
  const pc2 = { os: os2, brand: "", vram: null, ram: Math.round(mem / 2 ** 30), name: "", source: "", approx: false, note: "" };
173
201
  if (os2 === "win" || os2 === "linux") {
@@ -176,7 +204,12 @@ function detectHardware({ os: os2 = currentOS(process.platform), run = capture,
176
204
  }
177
205
  if (os2 === "win") {
178
206
  const r2 = run("powershell", ["-NoProfile", "-NonInteractive", "-Command", "Get-CimInstance Win32_VideoController | Select-Object Name,AdapterRAM | ConvertTo-Json"]);
179
- const best2 = r2.status === 0 ? pickBest(parseWinVideo(r2.stdout)) : null;
207
+ let cards = r2.status === 0 ? parseWinVideo(r2.stdout) : [];
208
+ if (cards.some((c) => c.note === WIN_4GB_NOTE)) {
209
+ const reg = run("powershell", ["-NoProfile", "-NonInteractive", "-Command", WIN_REGISTRY_VRAM]);
210
+ if (reg.status === 0) cards = parseWinVideo(r2.stdout, parseWinRegistryVram(reg.stdout));
211
+ }
212
+ const best2 = pickBest(cards);
180
213
  return best2 ? { ...pc2, ...best2, source: "Windows" } : pc2;
181
214
  }
182
215
  if (os2 === "mac") {
@@ -234,14 +267,14 @@ function hasPrereq(id, os2) {
234
267
  return commandExists(bin, os2);
235
268
  }
236
269
 
237
- // ../../apps/gerenciador/src/agente/workers/hw-worker.ts
238
- var { os, path, pathKey } = workerData || {};
270
+ // ../../apps/manager/src/agent/workers/hw-worker.ts
271
+ var { os, path, pathKey, base } = workerData || {};
239
272
  if (path && pathKey) process.env[pathKey] = path;
240
273
  var pc;
241
274
  try {
242
275
  pc = detectHardware({ os });
243
276
  } catch (e) {
244
- pc = { os, brand: "", vram: null, ram: null, name: "", source: "erro", note: String(e.message || e) };
277
+ pc = { os, brand: "", vram: null, ram: null, name: "", source: "error", note: String(e.message || e) };
245
278
  }
246
279
  var prereqs = {};
247
280
  for (const id of PRE_ORDER) {
@@ -251,4 +284,5 @@ for (const id of PRE_ORDER) {
251
284
  prereqs[id] = null;
252
285
  }
253
286
  }
254
- parentPort?.postMessage({ pc, prereqs });
287
+ var freeDisk = freeDiskGB(base || homedir());
288
+ parentPort?.postMessage({ pc, prereqs, freeDisk });