@johpaz/hive 1.1.4 → 1.1.5
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/package.json +5 -5
- package/packages/cli/dist/commands/agent-run.d.ts +1 -0
- package/packages/cli/dist/commands/agent-run.js +178 -0
- package/packages/cli/dist/commands/agents.d.ts +1 -0
- package/packages/cli/dist/commands/agents.js +372 -0
- package/packages/cli/dist/commands/chat.d.ts +1 -0
- package/packages/cli/dist/commands/chat.js +152 -0
- package/packages/cli/dist/commands/config.d.ts +1 -0
- package/packages/cli/dist/commands/config.js +49 -0
- package/packages/cli/dist/commands/cron.d.ts +1 -0
- package/packages/cli/dist/commands/cron.js +166 -0
- package/packages/cli/dist/commands/dev.d.ts +1 -0
- package/packages/cli/dist/commands/dev.js +120 -0
- package/packages/cli/dist/commands/doctor.d.ts +1 -0
- package/packages/cli/dist/commands/doctor.js +161 -0
- package/packages/cli/dist/commands/gateway.d.ts +4 -0
- package/packages/cli/dist/commands/gateway.js +444 -0
- package/packages/cli/dist/commands/logs.d.ts +1 -0
- package/packages/cli/dist/commands/logs.js +87 -0
- package/packages/cli/dist/commands/mcp.d.ts +1 -0
- package/packages/cli/dist/commands/mcp.js +175 -0
- package/packages/cli/dist/commands/message.d.ts +1 -0
- package/packages/cli/dist/commands/message.js +65 -0
- package/packages/cli/dist/commands/onboard.d.ts +1 -0
- package/packages/cli/dist/commands/onboard.js +1715 -0
- package/packages/cli/dist/commands/security.d.ts +1 -0
- package/packages/cli/dist/commands/security.js +155 -0
- package/packages/cli/dist/commands/service.d.ts +1 -0
- package/packages/cli/dist/commands/service.js +77 -0
- package/packages/cli/dist/commands/sessions.d.ts +1 -0
- package/packages/cli/dist/commands/sessions.js +132 -0
- package/packages/cli/dist/commands/skills.d.ts +1 -0
- package/packages/cli/dist/commands/skills.js +190 -0
- package/packages/cli/dist/commands/update.d.ts +1 -0
- package/packages/cli/dist/commands/update.js +27 -0
- package/packages/cli/dist/hive-binary +0 -0
- package/packages/cli/dist/index.d.ts +2 -0
- package/packages/cli/dist/index.js +184 -0
- package/packages/cli/dist/utils/token.d.ts +1 -0
- package/packages/cli/dist/utils/token.js +8 -0
- package/packages/cli/package.json +3 -1
- package/packages/core/package.json +9 -1
- package/packages/core/src/config/loader.d.ts +298 -0
- package/packages/core/src/config/loader.js +513 -0
- package/packages/core/src/storage/schema.d.ts +3 -0
- package/packages/core/src/storage/schema.js +541 -0
- package/packages/core/src/storage/sqlite.d.ts +51 -0
- package/packages/core/src/storage/sqlite.js +350 -0
- package/packages/core/src/utils/logger.d.ts +84 -0
- package/packages/core/src/utils/logger.js +352 -0
- package/packages/cli/src/commands/agent-run.ts +0 -168
- package/packages/cli/src/commands/agents.ts +0 -398
- package/packages/cli/src/commands/chat.ts +0 -142
- package/packages/cli/src/commands/config.ts +0 -50
- package/packages/cli/src/commands/cron.ts +0 -161
- package/packages/cli/src/commands/dev.ts +0 -95
- package/packages/cli/src/commands/doctor.ts +0 -133
- package/packages/cli/src/commands/gateway.ts +0 -443
- package/packages/cli/src/commands/logs.ts +0 -57
- package/packages/cli/src/commands/mcp.ts +0 -175
- package/packages/cli/src/commands/message.ts +0 -77
- package/packages/cli/src/commands/onboard.ts +0 -1868
- package/packages/cli/src/commands/security.ts +0 -144
- package/packages/cli/src/commands/service.ts +0 -50
- package/packages/cli/src/commands/sessions.ts +0 -116
- package/packages/cli/src/commands/skills.ts +0 -187
- package/packages/cli/src/commands/update.ts +0 -25
- package/packages/cli/src/index.ts +0 -185
- package/packages/cli/src/utils/token.ts +0 -6
|
@@ -0,0 +1,444 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.start = start;
|
|
37
|
+
exports.stop = stop;
|
|
38
|
+
exports.status = status;
|
|
39
|
+
exports.reload = reload;
|
|
40
|
+
const hive_core_1 = require("@johpaz/hive-core");
|
|
41
|
+
const node_fs_1 = require("node:fs");
|
|
42
|
+
const path = __importStar(require("node:path"));
|
|
43
|
+
const child_process_1 = require("child_process");
|
|
44
|
+
const children = [];
|
|
45
|
+
function cleanup() {
|
|
46
|
+
if (children.length === 0)
|
|
47
|
+
return;
|
|
48
|
+
console.log("\n🧹 Limpiando procesos hijos...");
|
|
49
|
+
for (const child of children) {
|
|
50
|
+
if (child.pid) {
|
|
51
|
+
try {
|
|
52
|
+
// En Linux, matar el grupo de procesos si fue iniciado como detached
|
|
53
|
+
process.kill(-child.pid, "SIGTERM");
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
child.kill("SIGTERM");
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
// Listen for termination signals
|
|
62
|
+
process.on("SIGINT", () => {
|
|
63
|
+
cleanup();
|
|
64
|
+
process.exit(0);
|
|
65
|
+
});
|
|
66
|
+
process.on("SIGTERM", () => {
|
|
67
|
+
cleanup();
|
|
68
|
+
process.exit(0);
|
|
69
|
+
});
|
|
70
|
+
// Ensure cleanup on normal exit
|
|
71
|
+
process.on("exit", () => {
|
|
72
|
+
cleanup();
|
|
73
|
+
});
|
|
74
|
+
function getDefaultPidFile() {
|
|
75
|
+
return path.join((0, hive_core_1.getHiveDir)(), "gateway.pid");
|
|
76
|
+
}
|
|
77
|
+
function getLogFile() {
|
|
78
|
+
return path.join((0, hive_core_1.getHiveDir)(), "logs", "gateway.log");
|
|
79
|
+
}
|
|
80
|
+
async function getPidFile() {
|
|
81
|
+
try {
|
|
82
|
+
const config = await (0, hive_core_1.loadConfig)();
|
|
83
|
+
return (0, hive_core_1.expandConfigPath)(config.gateway?.pidFile) ?? getDefaultPidFile();
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
return getDefaultPidFile();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function ensureLogDir() {
|
|
90
|
+
const logDir = path.dirname(getLogFile());
|
|
91
|
+
if (!(0, node_fs_1.existsSync)(logDir)) {
|
|
92
|
+
(0, node_fs_1.mkdirSync)(logDir, { recursive: true });
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function openBrowser(url) {
|
|
96
|
+
const platform = process.platform;
|
|
97
|
+
// Build the shell command for the platform
|
|
98
|
+
let shellCmd;
|
|
99
|
+
if (platform === "win32") {
|
|
100
|
+
shellCmd = `start "" "${url}"`;
|
|
101
|
+
}
|
|
102
|
+
else if (platform === "darwin") {
|
|
103
|
+
shellCmd = `open "${url}"`;
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
// Linux: try gio open first (GNOME/Wayland native, no DISPLAY needed),
|
|
107
|
+
// then xdg-open, then common browser names. '|| true' ensures exit 0.
|
|
108
|
+
shellCmd = `gio open "${url}" 2>/dev/null || xdg-open "${url}" 2>/dev/null || sensible-browser "${url}" 2>/dev/null || x-www-browser "${url}" 2>/dev/null || true`;
|
|
109
|
+
}
|
|
110
|
+
console.log(`🌐 Abriendo navegador en ${url}`);
|
|
111
|
+
try {
|
|
112
|
+
const shell = platform === "win32" ? "cmd" : "/bin/sh";
|
|
113
|
+
const shellArg = platform === "win32" ? "/c" : "-c";
|
|
114
|
+
// Bun.spawn is the native Bun API — more reliable than child_process.spawn in Bun
|
|
115
|
+
const proc = Bun.spawn([shell, shellArg, shellCmd], {
|
|
116
|
+
stdout: "ignore",
|
|
117
|
+
stderr: "ignore",
|
|
118
|
+
stdin: "ignore",
|
|
119
|
+
});
|
|
120
|
+
proc.unref(); // Don't keep event loop alive waiting for the browser process
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
console.log(`\n🌐 Abre Hive aquí: ${url}\n`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
async function isSetupMode() {
|
|
127
|
+
const hiveDir = (0, hive_core_1.getHiveDir)();
|
|
128
|
+
const dbPath = path.join(hiveDir, "data", "hive.db");
|
|
129
|
+
return !(0, node_fs_1.existsSync)(dbPath);
|
|
130
|
+
}
|
|
131
|
+
async function isRunning() {
|
|
132
|
+
const pidFile = await getPidFile();
|
|
133
|
+
if (!(0, node_fs_1.existsSync)(pidFile))
|
|
134
|
+
return false;
|
|
135
|
+
const pid = parseInt((0, node_fs_1.readFileSync)(pidFile, "utf-8").trim(), 10);
|
|
136
|
+
if (isNaN(pid))
|
|
137
|
+
return false;
|
|
138
|
+
try {
|
|
139
|
+
process.kill(pid, 0);
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
catch {
|
|
143
|
+
try {
|
|
144
|
+
(0, node_fs_1.unlinkSync)(pidFile);
|
|
145
|
+
}
|
|
146
|
+
catch { }
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
async function waitForPort(port, timeout = 30000) {
|
|
151
|
+
const start = Date.now();
|
|
152
|
+
while (Date.now() - start < timeout) {
|
|
153
|
+
try {
|
|
154
|
+
const response = await fetch(`http://127.0.0.1:${port}/health`, {
|
|
155
|
+
method: "HEAD",
|
|
156
|
+
signal: AbortSignal.timeout(1000)
|
|
157
|
+
});
|
|
158
|
+
if (response.ok || response.status === 204) {
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
catch {
|
|
163
|
+
// Port not ready yet
|
|
164
|
+
}
|
|
165
|
+
await Bun.sleep(500);
|
|
166
|
+
}
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
async function waitForVite(port, timeout = 30000) {
|
|
170
|
+
const start = Date.now();
|
|
171
|
+
while (Date.now() - start < timeout) {
|
|
172
|
+
try {
|
|
173
|
+
// Usar 127.0.0.1 en lugar de localhost para evitar demoras de resolución DNS (IPv6 vs IPv4)
|
|
174
|
+
const response = await fetch(`http://127.0.0.1:${port}`, {
|
|
175
|
+
method: "HEAD",
|
|
176
|
+
signal: AbortSignal.timeout(200) // Timeout más agresivo para una conexión local
|
|
177
|
+
});
|
|
178
|
+
if (response.ok || response.status === 200) {
|
|
179
|
+
return true;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
catch {
|
|
183
|
+
// Puerto aún no disponible
|
|
184
|
+
}
|
|
185
|
+
await Bun.sleep(200); // Poll más frecuente
|
|
186
|
+
}
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
async function start(flags) {
|
|
190
|
+
const daemon = flags.includes("--daemon");
|
|
191
|
+
const skipCheck = flags.includes("--skip-check");
|
|
192
|
+
const devInternal = flags.includes("--dev-internal");
|
|
193
|
+
// Check if we're in dev mode and config doesn't exist
|
|
194
|
+
const isDev = process.env.HIVE_DEV === "true" || process.env.NODE_ENV === "development";
|
|
195
|
+
const hiveDir = (0, hive_core_1.getHiveDir)();
|
|
196
|
+
const dbPath = path.join(hiveDir, "data", "hive.db");
|
|
197
|
+
// Skip onboarding check if running as child process in dev mode
|
|
198
|
+
const isGatewayChild = process.env.HIVE_GATEWAY_CHILD === "1";
|
|
199
|
+
// Database-centric onboarding check
|
|
200
|
+
if (isDev && !isGatewayChild) {
|
|
201
|
+
let hasCompletedOnboarding = false;
|
|
202
|
+
if ((0, node_fs_1.existsSync)(dbPath)) {
|
|
203
|
+
try {
|
|
204
|
+
const { initializeDatabase, getDb } = await Promise.resolve().then(() => __importStar(require("../../../core/src/storage/sqlite")));
|
|
205
|
+
initializeDatabase();
|
|
206
|
+
const db = getDb();
|
|
207
|
+
const existingAgent = db.query("SELECT id FROM agents WHERE is_coordinator = 1 AND status = 'idle' LIMIT 1").get();
|
|
208
|
+
hasCompletedOnboarding = !!existingAgent;
|
|
209
|
+
}
|
|
210
|
+
catch (e) {
|
|
211
|
+
hasCompletedOnboarding = false;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
if (!hasCompletedOnboarding) {
|
|
215
|
+
console.log("\n🚀 Sistema no inicializado. Ejecutando onboard...\n");
|
|
216
|
+
const { onboard } = await Promise.resolve().then(() => __importStar(require("./onboard")));
|
|
217
|
+
await onboard();
|
|
218
|
+
// Verify onboarding success via DB
|
|
219
|
+
try {
|
|
220
|
+
const { getDb } = await Promise.resolve().then(() => __importStar(require("../../../core/src/storage/sqlite")));
|
|
221
|
+
const db = getDb();
|
|
222
|
+
const existingAgent = db.query("SELECT id FROM agents WHERE is_coordinator = 1 AND status = 'idle' LIMIT 1").get();
|
|
223
|
+
if (!existingAgent) {
|
|
224
|
+
console.error("❌ Onboard no completó la inicialización correctamente");
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
catch (e) {
|
|
229
|
+
console.error("❌ Error verificando inicialización:", e.message);
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
if (!skipCheck && await isRunning()) {
|
|
235
|
+
console.log("⚠️ Hive Gateway ya está corriendo");
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
const config = await (0, hive_core_1.loadConfig)();
|
|
239
|
+
if (config.logging?.level) {
|
|
240
|
+
hive_core_1.logger.setLevel(config.logging.level);
|
|
241
|
+
}
|
|
242
|
+
// Only show banner if not running as child process (parent already shows status)
|
|
243
|
+
if (!isGatewayChild) {
|
|
244
|
+
console.log(`
|
|
245
|
+
╔═══════════════════════════════════════════╗
|
|
246
|
+
║ ║
|
|
247
|
+
║ ██╗ ██╗██╗██╗ ██╗███████╗ ║
|
|
248
|
+
║ ██║ ██║██║██║ ██║██╔════╝ ║
|
|
249
|
+
║ ███████║██║██║ ██║█████╗ ║
|
|
250
|
+
║ ██╔══██║██║╚██╗ ██╔╝██╔══╝ ║
|
|
251
|
+
║ ██║ ██║██║ ╚████╔╝ ███████╗ ║
|
|
252
|
+
║ ╚═╝ ╚═╝╚═╝ ╚═══╝ ╚══════╝ ║
|
|
253
|
+
║ ║
|
|
254
|
+
║ Personal Swarm AI Gateway — v1.0.10 ║
|
|
255
|
+
╚════════════════════════════════════════════╝
|
|
256
|
+
`);
|
|
257
|
+
}
|
|
258
|
+
if (daemon) {
|
|
259
|
+
ensureLogDir();
|
|
260
|
+
const logFile = getLogFile();
|
|
261
|
+
const child = (0, child_process_1.spawn)(process.execPath, [process.argv[1] || "", "start", "--skip-check"], {
|
|
262
|
+
detached: true,
|
|
263
|
+
stdio: ["ignore", (0, node_fs_1.openSync)(logFile, "a"), (0, node_fs_1.openSync)(logFile, "a")],
|
|
264
|
+
});
|
|
265
|
+
child.unref();
|
|
266
|
+
(0, node_fs_1.writeFileSync)(await getPidFile(), child.pid?.toString() || "");
|
|
267
|
+
console.log(`✅ Hive Gateway iniciado en modo daemon (PID: ${child.pid})`);
|
|
268
|
+
console.log(` Logs: ${logFile}`);
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
// In dev mode, start Vite and Gateway concurrently for faster startup
|
|
272
|
+
if (isDev) {
|
|
273
|
+
// ── CHILD PROCESS: Only run Gateway server ───────────────────────────────
|
|
274
|
+
if (isGatewayChild) {
|
|
275
|
+
// Child process: skip Vite and Code Bridge, just start Gateway
|
|
276
|
+
hive_core_1.logger.info("Starting Gateway server (child process)...");
|
|
277
|
+
await (0, hive_core_1.startGateway)(config);
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
// ── PARENT PROCESS: Start Vite, Code Bridge, and spawn child Gateway ─────
|
|
281
|
+
const hiveUiPath = path.join(process.cwd(), "packages/hive-ui");
|
|
282
|
+
const hasVite = (0, node_fs_1.existsSync)(path.join(hiveUiPath, "package.json"));
|
|
283
|
+
// Start Vite in background (don't wait)
|
|
284
|
+
if (hasVite) {
|
|
285
|
+
console.log("🎨 Iniciando Vite (UI)...\n");
|
|
286
|
+
const viteProcess = (0, child_process_1.spawn)("bun", ["run", "dev"], {
|
|
287
|
+
cwd: hiveUiPath,
|
|
288
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
289
|
+
detached: true,
|
|
290
|
+
});
|
|
291
|
+
// Pipe logs to stdout/stderr with a prefix
|
|
292
|
+
viteProcess.stdout?.on("data", (data) => {
|
|
293
|
+
const lines = data.toString().split("\n");
|
|
294
|
+
for (const line of lines) {
|
|
295
|
+
if (line.trim())
|
|
296
|
+
console.log(`[Vite] ${line}`);
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
viteProcess.stderr?.on("data", (data) => {
|
|
300
|
+
const lines = data.toString().split("\n");
|
|
301
|
+
for (const line of lines) {
|
|
302
|
+
if (line.trim())
|
|
303
|
+
console.error(`[Vite] ${line}`);
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
viteProcess.on("error", (error) => {
|
|
307
|
+
console.error(`❌ Error iniciando Vite: ${error.message}`);
|
|
308
|
+
});
|
|
309
|
+
if (!daemon) {
|
|
310
|
+
children.push(viteProcess);
|
|
311
|
+
}
|
|
312
|
+
else {
|
|
313
|
+
viteProcess.unref();
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
// Start Code Bridge sidecar (parent process only)
|
|
317
|
+
try {
|
|
318
|
+
await Promise.resolve().then(() => __importStar(require("@johpaz/hive-code-bridge")));
|
|
319
|
+
}
|
|
320
|
+
catch (error) {
|
|
321
|
+
console.warn(`⚠️ No se pudo iniciar el Code Bridge: ${error.message}`);
|
|
322
|
+
}
|
|
323
|
+
// Start Gateway in a separate process (non-blocking)
|
|
324
|
+
const gatewayProcess = (0, child_process_1.spawn)(process.execPath, [process.argv[1] || "", "start", "--skip-check", "--dev-internal"], {
|
|
325
|
+
detached: true,
|
|
326
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
327
|
+
env: { ...process.env, HIVE_DEV: "true", HIVE_GATEWAY_CHILD: "1" },
|
|
328
|
+
});
|
|
329
|
+
gatewayProcess.stdout?.on("data", (data) => {
|
|
330
|
+
const lines = data.toString().split("\n");
|
|
331
|
+
for (const line of lines) {
|
|
332
|
+
if (line.trim())
|
|
333
|
+
console.log(`[Gateway] ${line}`);
|
|
334
|
+
}
|
|
335
|
+
});
|
|
336
|
+
gatewayProcess.stderr?.on("data", (data) => {
|
|
337
|
+
const lines = data.toString().split("\n");
|
|
338
|
+
for (const line of lines) {
|
|
339
|
+
if (line.trim())
|
|
340
|
+
console.error(`[Gateway] ${line}`);
|
|
341
|
+
}
|
|
342
|
+
});
|
|
343
|
+
gatewayProcess.on("error", (error) => {
|
|
344
|
+
console.error(`❌ Error iniciando Gateway: ${error.message}`);
|
|
345
|
+
});
|
|
346
|
+
if (!daemon) {
|
|
347
|
+
children.push(gatewayProcess);
|
|
348
|
+
}
|
|
349
|
+
else {
|
|
350
|
+
gatewayProcess.unref();
|
|
351
|
+
}
|
|
352
|
+
// Wait for both Vite and Gateway to be ready
|
|
353
|
+
console.log("⏳ Esperando servicios...");
|
|
354
|
+
const [viteReady, gatewayReady] = await Promise.all([
|
|
355
|
+
hasVite ? waitForVite(5173, 30000) : Promise.resolve(true),
|
|
356
|
+
waitForPort(18790, 30000),
|
|
357
|
+
]);
|
|
358
|
+
if (!viteReady && hasVite) {
|
|
359
|
+
console.error("⚠️ Vite no respondió a tiempo");
|
|
360
|
+
}
|
|
361
|
+
if (!gatewayReady) {
|
|
362
|
+
console.error("⚠️ Gateway no respondió a tiempo");
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
console.log("✅ Servicios listos\n");
|
|
366
|
+
// Determine if we should open /setup or /ui
|
|
367
|
+
const setupMode = await isSetupMode();
|
|
368
|
+
const url = setupMode
|
|
369
|
+
? "http://localhost:5173/setup"
|
|
370
|
+
: "http://localhost:5173";
|
|
371
|
+
console.log(`
|
|
372
|
+
╔════════════════════════════════════════╗
|
|
373
|
+
║ 🐝 Hive — Modo Desarrollo ║
|
|
374
|
+
╠════════════════════════════════════════╣
|
|
375
|
+
║ UI: ${url.padEnd(24)}║
|
|
376
|
+
║ API: http://127.0.0.1:18790 ║
|
|
377
|
+
║ WebSocket: ws://127.0.0.1:18790/ws ║
|
|
378
|
+
║ Canvas: ws://127.0.0.1:18790/canvas║
|
|
379
|
+
╠════════════════════════════════════════╣
|
|
380
|
+
║ ${setupMode ? "🎉 Primer arranque — abriendo setup..." : "Administra tu Hive aquí "}║
|
|
381
|
+
╚════════════════════════════════════════╝
|
|
382
|
+
`);
|
|
383
|
+
openBrowser(url);
|
|
384
|
+
// Keep the process alive
|
|
385
|
+
if (!daemon) {
|
|
386
|
+
await new Promise(() => { }); // Infinite wait
|
|
387
|
+
}
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
// Production mode (not dev) - start Gateway blocking
|
|
391
|
+
await (0, hive_core_1.startGateway)(config);
|
|
392
|
+
}
|
|
393
|
+
async function stop() {
|
|
394
|
+
if (!(await isRunning())) {
|
|
395
|
+
console.log("⚠️ Hive Gateway no está corriendo");
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
const pidFile = await getPidFile();
|
|
399
|
+
const pid = parseInt((0, node_fs_1.readFileSync)(pidFile, "utf-8").trim(), 10);
|
|
400
|
+
try {
|
|
401
|
+
process.kill(pid, "SIGTERM");
|
|
402
|
+
(0, node_fs_1.unlinkSync)(pidFile);
|
|
403
|
+
console.log("✅ Hive Gateway detenido");
|
|
404
|
+
}
|
|
405
|
+
catch (e) {
|
|
406
|
+
console.error("❌ Error deteniendo el Gateway:", e);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
async function status(flags) {
|
|
410
|
+
const running = await isRunning();
|
|
411
|
+
const hiveDir = (0, hive_core_1.getHiveDir)();
|
|
412
|
+
console.log("🐝 Hive Gateway Status\n");
|
|
413
|
+
const config = await (0, hive_core_1.loadConfig)();
|
|
414
|
+
const pidFile = await getPidFile();
|
|
415
|
+
console.log(`Estado: ${running ? "✅ Corriendo" : "⏹️ Detenido"}`);
|
|
416
|
+
if (running) {
|
|
417
|
+
const pid = (0, node_fs_1.readFileSync)(pidFile, "utf-8").trim();
|
|
418
|
+
console.log(`PID: ${pid}`);
|
|
419
|
+
}
|
|
420
|
+
console.log(`Puerto: ${config.gateway?.port || 18790}`);
|
|
421
|
+
console.log(`Host: ${config.gateway?.host || "127.0.0.1"}`);
|
|
422
|
+
const provider = config.models?.defaultProvider || "no configurado";
|
|
423
|
+
const model = config.models?.defaults?.[provider] || config.models?.defaults?.default || "no configurado";
|
|
424
|
+
console.log(`Modelo: ${provider} / ${model}`);
|
|
425
|
+
console.log(`Home: ${hiveDir}`);
|
|
426
|
+
console.log(`Logs: ${getLogFile()}`);
|
|
427
|
+
if (flags.includes("--json")) {
|
|
428
|
+
console.log("\n" + JSON.stringify({ running, pid: running ? (0, node_fs_1.readFileSync)(pidFile, "utf-8").trim() : null, config }, null, 2));
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
async function reload() {
|
|
432
|
+
if (!(await isRunning())) {
|
|
433
|
+
console.log("⚠️ Hive Gateway no está corriendo");
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
436
|
+
const pid = parseInt((0, node_fs_1.readFileSync)(await getPidFile(), "utf-8").trim(), 10);
|
|
437
|
+
try {
|
|
438
|
+
process.kill(pid, "SIGHUP");
|
|
439
|
+
console.log("✅ Configuración recargada");
|
|
440
|
+
}
|
|
441
|
+
catch (e) {
|
|
442
|
+
console.error("❌ Error recargando configuración:", e);
|
|
443
|
+
}
|
|
444
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function logs(flags: string[]): Promise<void>;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.logs = logs;
|
|
37
|
+
const fs = __importStar(require("fs"));
|
|
38
|
+
const path = __importStar(require("path"));
|
|
39
|
+
const child_process_1 = require("child_process");
|
|
40
|
+
const LOG_DIR = path.join(process.env.HOME || "", ".hive", "logs");
|
|
41
|
+
const LOG_FILE = path.join(LOG_DIR, "gateway.log");
|
|
42
|
+
async function logs(flags) {
|
|
43
|
+
if (flags.includes("--clear")) {
|
|
44
|
+
await clearLogs();
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (!fs.existsSync(LOG_FILE)) {
|
|
48
|
+
console.log("No hay logs disponibles");
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const follow = flags.includes("--follow") || flags.includes("-f");
|
|
52
|
+
const levelFlag = flags.find((f) => f.startsWith("--level"));
|
|
53
|
+
const level = levelFlag ? levelFlag.split("=")[1] || flags[flags.indexOf(levelFlag) + 1] : null;
|
|
54
|
+
const agentFlag = flags.find((f) => f.startsWith("--agent"));
|
|
55
|
+
const agent = agentFlag ? agentFlag.split("=")[1] || flags[flags.indexOf(agentFlag) + 1] : null;
|
|
56
|
+
const lines = 100;
|
|
57
|
+
if (follow) {
|
|
58
|
+
const tail = (0, child_process_1.spawn)("tail", ["-f", LOG_FILE], { stdio: "inherit" });
|
|
59
|
+
process.on("SIGINT", () => {
|
|
60
|
+
tail.kill();
|
|
61
|
+
process.exit(0);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
let content = fs.readFileSync(LOG_FILE, "utf-8");
|
|
66
|
+
const allLines = content.split("\n");
|
|
67
|
+
let filtered = allLines;
|
|
68
|
+
if (level) {
|
|
69
|
+
const levelLower = level.toLowerCase();
|
|
70
|
+
filtered = filtered.filter((l) => l.toLowerCase().includes(levelLower));
|
|
71
|
+
}
|
|
72
|
+
if (agent) {
|
|
73
|
+
filtered = filtered.filter((l) => l.includes(agent));
|
|
74
|
+
}
|
|
75
|
+
const lastLines = filtered.slice(-lines);
|
|
76
|
+
console.log(lastLines.join("\n"));
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
async function clearLogs() {
|
|
80
|
+
if (fs.existsSync(LOG_FILE)) {
|
|
81
|
+
fs.writeFileSync(LOG_FILE, "");
|
|
82
|
+
console.log("✅ Logs limpiados");
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
console.log("No hay logs para limpiar");
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function mcp(subcommand: string | undefined, args: string[]): Promise<void>;
|