nex-framework-cli 1.0.1

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.
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Registry - Registro de agentes instalados
3
+ */
4
+ import fs from 'fs-extra'
5
+ import path from 'path'
6
+
7
+ export default class Registry {
8
+ constructor() {
9
+ this.registryFile = path.join(process.cwd(), '.nex-core', 'agents', 'installed.json')
10
+ }
11
+
12
+ /**
13
+ * Registra agente instalado
14
+ */
15
+ async register(agentInfo) {
16
+ const registry = await this.loadRegistry()
17
+
18
+ registry[agentInfo.id] = {
19
+ ...agentInfo,
20
+ updatedAt: new Date().toISOString()
21
+ }
22
+
23
+ await this.saveRegistry(registry)
24
+ }
25
+
26
+ /**
27
+ * Remove registro de agente
28
+ */
29
+ async unregister(agentId) {
30
+ const registry = await this.loadRegistry()
31
+ delete registry[agentId]
32
+ await this.saveRegistry(registry)
33
+ }
34
+
35
+ /**
36
+ * Verifica se agente está instalado
37
+ */
38
+ async isInstalled(agentId) {
39
+ const registry = await this.loadRegistry()
40
+ return registry[agentId] || null
41
+ }
42
+
43
+ /**
44
+ * Lista todos os agentes instalados
45
+ */
46
+ async list() {
47
+ const registry = await this.loadRegistry()
48
+ return Object.values(registry)
49
+ }
50
+
51
+ /**
52
+ * Carrega registro
53
+ */
54
+ async loadRegistry() {
55
+ if (!await fs.pathExists(this.registryFile)) {
56
+ return {}
57
+ }
58
+
59
+ try {
60
+ return await fs.readJSON(this.registryFile)
61
+ } catch (error) {
62
+ console.warn('[Registry] Erro ao carregar registro, criando novo:', error)
63
+ return {}
64
+ }
65
+ }
66
+
67
+ /**
68
+ * Salva registro
69
+ */
70
+ async saveRegistry(registry) {
71
+ await fs.ensureDir(path.dirname(this.registryFile))
72
+ await fs.writeJSON(this.registryFile, registry, { spaces: 2 })
73
+ }
74
+ }
75
+