@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
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@johpaz/hive",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.5",
|
|
4
4
|
"description": "Tu colmena de agentes IA. Local-first. Multi-canal. Open source. Construido desde Colombia para el mundo.",
|
|
5
5
|
"bin": {
|
|
6
|
-
"hive": "packages/cli/
|
|
6
|
+
"hive": "packages/cli/dist/hive-binary"
|
|
7
7
|
},
|
|
8
8
|
"main": "packages/core/src/index.ts",
|
|
9
9
|
"repository": {
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"license": "MIT",
|
|
32
32
|
"files": [
|
|
33
33
|
"packages/core/",
|
|
34
|
-
"packages/cli/",
|
|
34
|
+
"packages/cli/dist/",
|
|
35
35
|
"packages/mcp/",
|
|
36
36
|
"packages/skills/",
|
|
37
37
|
"packages/tools/",
|
|
@@ -48,13 +48,13 @@
|
|
|
48
48
|
"dev": "HIVE_HOME=$HOME/.hive-dev HIVE_DEV=true bun run packages/cli/src/index.ts dev",
|
|
49
49
|
"dev:keep": "HIVE_HOME=$HOME/.hive-dev HIVE_DEV=true HIVE_DEV_CLEAN=false bun run packages/cli/src/index.ts dev",
|
|
50
50
|
"start": "bun run packages/cli/src/index.ts start",
|
|
51
|
+
"build": "cd packages/cli && bun build src/index.ts --compile --outfile dist/hive-binary",
|
|
51
52
|
"test": "bun test",
|
|
52
53
|
"test:ci": "bun test --coverage",
|
|
53
54
|
"lint": "bunx tsc --noEmit",
|
|
54
|
-
"build": "echo 'No build needed - TypeScript is interpreted by Bun'",
|
|
55
55
|
"build:binaries": "bun run scripts/build-binaries.ts",
|
|
56
56
|
"bench": "bun run scripts/bench.ts",
|
|
57
|
-
"prepublishOnly": "
|
|
57
|
+
"prepublishOnly": "npm run build"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
60
|
"@ag-ui/core": "^0.0.46",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function agent(subcommand: string | undefined, args: string[]): Promise<void>;
|
|
@@ -0,0 +1,178 @@
|
|
|
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.agent = agent;
|
|
37
|
+
const p = __importStar(require("@clack/prompts"));
|
|
38
|
+
const loader_1 = require("@johpaz/hive-core/config/loader");
|
|
39
|
+
function getGatewayUrl(config) {
|
|
40
|
+
const gateway = config?.gateway;
|
|
41
|
+
const host = gateway?.host ?? "localhost";
|
|
42
|
+
const port = gateway?.port ?? 3000;
|
|
43
|
+
return `http://${host}:${port}`;
|
|
44
|
+
}
|
|
45
|
+
async function agent(subcommand, args) {
|
|
46
|
+
switch (subcommand) {
|
|
47
|
+
case "run":
|
|
48
|
+
await agentRun(args);
|
|
49
|
+
break;
|
|
50
|
+
default:
|
|
51
|
+
console.log(`
|
|
52
|
+
Usage: hive agent <command>
|
|
53
|
+
|
|
54
|
+
Commands:
|
|
55
|
+
run --message <text> Ejecutar agente con mensaje
|
|
56
|
+
run --thinking <level> Nivel de razonamiento (low/medium/high)
|
|
57
|
+
run --wait Esperar respuesta completa
|
|
58
|
+
`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
async function agentRun(args) {
|
|
62
|
+
const messageIndex = args.indexOf("--message");
|
|
63
|
+
const thinkingIndex = args.indexOf("--thinking");
|
|
64
|
+
const toolsIndex = args.indexOf("--tools");
|
|
65
|
+
const agentIndex = args.indexOf("--agent");
|
|
66
|
+
const waitIndex = args.indexOf("--wait");
|
|
67
|
+
if (messageIndex === -1) {
|
|
68
|
+
const msg = await p.text({
|
|
69
|
+
message: "Mensaje para el agente:",
|
|
70
|
+
placeholder: "Analiza el archivo README.md",
|
|
71
|
+
validate: (v) => (!v ? "El mensaje es requerido" : undefined),
|
|
72
|
+
});
|
|
73
|
+
if (p.isCancel(msg)) {
|
|
74
|
+
p.cancel("Cancelado");
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
args.push("--message", msg);
|
|
78
|
+
return agentRun(args);
|
|
79
|
+
}
|
|
80
|
+
const message = args[messageIndex + 1];
|
|
81
|
+
const thinking = thinkingIndex !== -1 ? args[thinkingIndex + 1] : "medium";
|
|
82
|
+
const tools = toolsIndex !== -1 ? args[toolsIndex + 1] : "all";
|
|
83
|
+
const agentId = agentIndex !== -1 ? args[agentIndex + 1] : "main";
|
|
84
|
+
const wait = waitIndex !== -1;
|
|
85
|
+
if (!message) {
|
|
86
|
+
console.log("❌ Mensaje requerido");
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
const config = (0, loader_1.loadConfig)();
|
|
90
|
+
const gatewayUrl = getGatewayUrl(config);
|
|
91
|
+
const spinner = p.spinner();
|
|
92
|
+
spinner.start("Conectando con el agente...");
|
|
93
|
+
try {
|
|
94
|
+
if (wait) {
|
|
95
|
+
await executeWithStream(gatewayUrl, { message, thinking, tools, agentId }, spinner);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
await executeAsync(gatewayUrl, { message, thinking, tools, agentId }, spinner);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
spinner.stop("Error");
|
|
103
|
+
console.log(`❌ ${error.message}`);
|
|
104
|
+
console.log(" ¿Está corriendo el Gateway? Ejecuta: hive start");
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
async function executeWithStream(gatewayUrl, payload, spinner) {
|
|
108
|
+
const response = await fetch(`${gatewayUrl}/api/agent/execute`, {
|
|
109
|
+
method: "POST",
|
|
110
|
+
headers: { "Content-Type": "application/json" },
|
|
111
|
+
body: JSON.stringify({ ...payload, stream: true }),
|
|
112
|
+
});
|
|
113
|
+
if (!response.ok) {
|
|
114
|
+
throw new Error(`Error: ${response.statusText}`);
|
|
115
|
+
}
|
|
116
|
+
spinner.stop("Conectado");
|
|
117
|
+
const reader = response.body?.getReader();
|
|
118
|
+
if (!reader) {
|
|
119
|
+
throw new Error("No se pudo obtener el stream");
|
|
120
|
+
}
|
|
121
|
+
const decoder = new TextDecoder();
|
|
122
|
+
let buffer = "";
|
|
123
|
+
let thinking = true;
|
|
124
|
+
process.stdout.write("\n");
|
|
125
|
+
while (true) {
|
|
126
|
+
const { done, value } = await reader.read();
|
|
127
|
+
if (done)
|
|
128
|
+
break;
|
|
129
|
+
buffer += decoder.decode(value, { stream: true });
|
|
130
|
+
const lines = buffer.split("\n");
|
|
131
|
+
buffer = lines.pop() ?? "";
|
|
132
|
+
for (const line of lines) {
|
|
133
|
+
if (!line.trim() || !line.startsWith("data: "))
|
|
134
|
+
continue;
|
|
135
|
+
try {
|
|
136
|
+
const data = JSON.parse(line.slice(6));
|
|
137
|
+
if (data.type === "thinking" && thinking) {
|
|
138
|
+
process.stdout.write(".");
|
|
139
|
+
}
|
|
140
|
+
else if (data.type === "response") {
|
|
141
|
+
if (thinking) {
|
|
142
|
+
process.stdout.write("\n\n");
|
|
143
|
+
thinking = false;
|
|
144
|
+
}
|
|
145
|
+
process.stdout.write(data.content ?? "");
|
|
146
|
+
}
|
|
147
|
+
else if (data.type === "tool_call") {
|
|
148
|
+
process.stdout.write(`\n[Tool: ${data.toolName}]`);
|
|
149
|
+
}
|
|
150
|
+
else if (data.type === "complete") {
|
|
151
|
+
process.stdout.write("\n\n");
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
catch {
|
|
155
|
+
// Ignore parse errors
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
async function executeAsync(gatewayUrl, payload, spinner) {
|
|
161
|
+
const response = await fetch(`${gatewayUrl}/api/agent/execute`, {
|
|
162
|
+
method: "POST",
|
|
163
|
+
headers: { "Content-Type": "application/json" },
|
|
164
|
+
body: JSON.stringify({ ...payload, stream: false }),
|
|
165
|
+
});
|
|
166
|
+
if (!response.ok) {
|
|
167
|
+
throw new Error(`Error: ${response.statusText}`);
|
|
168
|
+
}
|
|
169
|
+
const result = await response.json();
|
|
170
|
+
spinner.stop("Enviado");
|
|
171
|
+
if (result.taskId) {
|
|
172
|
+
console.log(`✓ Tarea enviada: ${result.taskId}`);
|
|
173
|
+
console.log(" Usa `hive tasks list` para ver el estado");
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
console.log("✓ Tarea enviada");
|
|
177
|
+
}
|
|
178
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function agents(subcommand: string | undefined, args: string[]): Promise<void>;
|
|
@@ -0,0 +1,372 @@
|
|
|
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.agents = agents;
|
|
37
|
+
const p = __importStar(require("@clack/prompts"));
|
|
38
|
+
const fs = __importStar(require("fs"));
|
|
39
|
+
const path = __importStar(require("path"));
|
|
40
|
+
const loader_1 = require("@johpaz/hive-core/config/loader");
|
|
41
|
+
const getAgentsPath = () => path.join((0, loader_1.getHiveDir)(), "agents");
|
|
42
|
+
async function loadLifecycleAgents() {
|
|
43
|
+
const agents = [];
|
|
44
|
+
try {
|
|
45
|
+
if (!fs.existsSync(getAgentsPath()))
|
|
46
|
+
return [];
|
|
47
|
+
const entries = fs.readdirSync(getAgentsPath(), { withFileTypes: true });
|
|
48
|
+
for (const entry of entries) {
|
|
49
|
+
if (!entry.isDirectory())
|
|
50
|
+
continue;
|
|
51
|
+
const statePath = path.join(getAgentsPath(), entry.name, "state.json");
|
|
52
|
+
try {
|
|
53
|
+
const content = fs.readFileSync(statePath, "utf-8");
|
|
54
|
+
agents.push(JSON.parse(content));
|
|
55
|
+
}
|
|
56
|
+
catch { }
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
catch { }
|
|
60
|
+
return agents;
|
|
61
|
+
}
|
|
62
|
+
async function agents(subcommand, args) {
|
|
63
|
+
switch (subcommand) {
|
|
64
|
+
case "add":
|
|
65
|
+
await addAgent(args[0]);
|
|
66
|
+
break;
|
|
67
|
+
case "create":
|
|
68
|
+
await createAgent(args);
|
|
69
|
+
break;
|
|
70
|
+
case "list":
|
|
71
|
+
case "ls":
|
|
72
|
+
await listAgents(args.includes("--bindings"));
|
|
73
|
+
break;
|
|
74
|
+
case "logs":
|
|
75
|
+
await showLogs(args[0]);
|
|
76
|
+
break;
|
|
77
|
+
case "hibernate":
|
|
78
|
+
await hibernateAgent(args[0]);
|
|
79
|
+
break;
|
|
80
|
+
case "wake":
|
|
81
|
+
await wakeAgent(args[0]);
|
|
82
|
+
break;
|
|
83
|
+
case "terminate":
|
|
84
|
+
case "kill":
|
|
85
|
+
await terminateAgent(args[0], args.includes("--cascade"));
|
|
86
|
+
break;
|
|
87
|
+
case "tree":
|
|
88
|
+
await showTree();
|
|
89
|
+
break;
|
|
90
|
+
case "remove":
|
|
91
|
+
await removeAgent(args[0]);
|
|
92
|
+
break;
|
|
93
|
+
default:
|
|
94
|
+
console.log(`
|
|
95
|
+
Usage: hive agents <command> [arguments]
|
|
96
|
+
|
|
97
|
+
Commands:
|
|
98
|
+
list, ls List all agents
|
|
99
|
+
add <id> Create agent (legacy)
|
|
100
|
+
create Create agent with new lifecycle system
|
|
101
|
+
logs <agent-id> Show agent logs
|
|
102
|
+
hibernate <agent-id> Put agent to sleep
|
|
103
|
+
wake <agent-id> Wake a hibernated agent
|
|
104
|
+
terminate <agent-id> [--cascade] Terminate an agent
|
|
105
|
+
tree Show agent hierarchy tree
|
|
106
|
+
remove <id> Remove agent (legacy)
|
|
107
|
+
|
|
108
|
+
Examples:
|
|
109
|
+
hive agents list
|
|
110
|
+
hive agents create
|
|
111
|
+
hive agents tree
|
|
112
|
+
hive agents hibernate agent-abc123
|
|
113
|
+
hive agents wake agent-abc123
|
|
114
|
+
hive agents terminate agent-abc123 --cascade
|
|
115
|
+
`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
async function createAgent(args) {
|
|
119
|
+
const name = args[0] || await promptInput("Agent name:", `agent-${Date.now()}`);
|
|
120
|
+
const purpose = args[1] || await promptInput("Purpose:", "General AI assistant");
|
|
121
|
+
const agentId = `agent-${crypto.randomUUID().slice(0, 8)}`;
|
|
122
|
+
const workspacePath = path.join(getAgentsPath(), agentId);
|
|
123
|
+
fs.mkdirSync(path.join(workspacePath, "memory"), { recursive: true });
|
|
124
|
+
fs.mkdirSync(path.join(workspacePath, "skills"), { recursive: true });
|
|
125
|
+
fs.mkdirSync(path.join(workspacePath, "logs"), { recursive: true });
|
|
126
|
+
const soulMd = `# SOUL.md - ${name}
|
|
127
|
+
|
|
128
|
+
## Identity
|
|
129
|
+
|
|
130
|
+
I am ${name}, created to ${purpose.toLowerCase()}.
|
|
131
|
+
|
|
132
|
+
## Personality
|
|
133
|
+
|
|
134
|
+
- Helpful and responsive
|
|
135
|
+
- Clear communicator
|
|
136
|
+
- Adaptable to user needs
|
|
137
|
+
`;
|
|
138
|
+
const ethicsMd = `# ETHICS.md
|
|
139
|
+
|
|
140
|
+
## Core Principles
|
|
141
|
+
|
|
142
|
+
1. Honesty - Never deceive the user
|
|
143
|
+
2. Privacy - Protect user data
|
|
144
|
+
3. Safety - Prevent harm
|
|
145
|
+
4. Consent - Ask before significant actions
|
|
146
|
+
`;
|
|
147
|
+
fs.writeFileSync(path.join(workspacePath, "SOUL.md"), soulMd);
|
|
148
|
+
fs.writeFileSync(path.join(workspacePath, "ETHICS.md"), ethicsMd);
|
|
149
|
+
fs.writeFileSync(path.join(workspacePath, "USER.md"), "# USER.md\n\n## Preferences\n\n");
|
|
150
|
+
const state = {
|
|
151
|
+
id: agentId,
|
|
152
|
+
name,
|
|
153
|
+
type: "sibling",
|
|
154
|
+
state: "active",
|
|
155
|
+
purpose,
|
|
156
|
+
childrenIds: [],
|
|
157
|
+
workspacePath,
|
|
158
|
+
createdAt: new Date().toISOString(),
|
|
159
|
+
lastActivity: new Date().toISOString(),
|
|
160
|
+
capabilities: ["general"],
|
|
161
|
+
};
|
|
162
|
+
fs.writeFileSync(path.join(workspacePath, "state.json"), JSON.stringify(state, null, 2));
|
|
163
|
+
console.log(`\n✅ Agent created: ${name} (${agentId})`);
|
|
164
|
+
console.log(` Workspace: ${workspacePath}\n`);
|
|
165
|
+
}
|
|
166
|
+
async function promptInput(message, defaultVal) {
|
|
167
|
+
const result = await p.text({
|
|
168
|
+
message,
|
|
169
|
+
placeholder: defaultVal,
|
|
170
|
+
defaultValue: defaultVal,
|
|
171
|
+
});
|
|
172
|
+
if (p.isCancel(result)) {
|
|
173
|
+
p.cancel("Cancelled");
|
|
174
|
+
process.exit(0);
|
|
175
|
+
}
|
|
176
|
+
return result;
|
|
177
|
+
}
|
|
178
|
+
async function showLogs(agentId) {
|
|
179
|
+
if (!agentId) {
|
|
180
|
+
console.log("Usage: hive agents logs <agent-id>");
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
const logPath = path.join(getAgentsPath(), agentId, "logs");
|
|
184
|
+
try {
|
|
185
|
+
const files = fs.readdirSync(logPath).filter((f) => f.endsWith(".log")).sort().reverse();
|
|
186
|
+
if (files.length === 0) {
|
|
187
|
+
console.log("\n📋 No logs found.\n");
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
const content = fs.readFileSync(path.join(logPath, files[0]), "utf-8");
|
|
191
|
+
console.log(`\n📋 Logs for ${agentId}:\n`);
|
|
192
|
+
console.log(content.slice(-3000));
|
|
193
|
+
}
|
|
194
|
+
catch {
|
|
195
|
+
console.log(`\n❌ Agent not found: ${agentId}\n`);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
async function hibernateAgent(agentId) {
|
|
199
|
+
if (!agentId) {
|
|
200
|
+
console.log("Usage: hive agents hibernate <agent-id>");
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
const statePath = path.join(getAgentsPath(), agentId, "state.json");
|
|
204
|
+
try {
|
|
205
|
+
const state = JSON.parse(fs.readFileSync(statePath, "utf-8"));
|
|
206
|
+
state.state = "hibernated";
|
|
207
|
+
state.hibernatedAt = new Date().toISOString();
|
|
208
|
+
fs.writeFileSync(statePath, JSON.stringify(state, null, 2));
|
|
209
|
+
console.log(`\n💤 Agent ${state.name} hibernated.\n`);
|
|
210
|
+
}
|
|
211
|
+
catch {
|
|
212
|
+
console.log(`\n❌ Agent not found: ${agentId}\n`);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
async function wakeAgent(agentId) {
|
|
216
|
+
if (!agentId) {
|
|
217
|
+
console.log("Usage: hive agents wake <agent-id>");
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
const statePath = path.join(getAgentsPath(), agentId, "state.json");
|
|
221
|
+
try {
|
|
222
|
+
const state = JSON.parse(fs.readFileSync(statePath, "utf-8"));
|
|
223
|
+
state.state = "active";
|
|
224
|
+
state.lastActivity = new Date().toISOString();
|
|
225
|
+
fs.writeFileSync(statePath, JSON.stringify(state, null, 2));
|
|
226
|
+
console.log(`\n⚡ Agent ${state.name} activated.\n`);
|
|
227
|
+
}
|
|
228
|
+
catch {
|
|
229
|
+
console.log(`\n❌ Agent not found: ${agentId}\n`);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
async function terminateAgent(agentId, cascade) {
|
|
233
|
+
if (!agentId) {
|
|
234
|
+
console.log("Usage: hive agents terminate <agent-id> [--cascade]");
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
const statePath = path.join(getAgentsPath(), agentId, "state.json");
|
|
238
|
+
try {
|
|
239
|
+
const state = JSON.parse(fs.readFileSync(statePath, "utf-8"));
|
|
240
|
+
state.state = "terminated";
|
|
241
|
+
state.terminatedAt = new Date().toISOString();
|
|
242
|
+
state.terminationReason = "User requested";
|
|
243
|
+
fs.writeFileSync(statePath, JSON.stringify(state, null, 2));
|
|
244
|
+
console.log(`\n⚫ Agent ${state.name} terminated.\n`);
|
|
245
|
+
if (cascade && state.childrenIds?.length > 0) {
|
|
246
|
+
for (const childId of state.childrenIds) {
|
|
247
|
+
await terminateAgent(childId, true);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
catch {
|
|
252
|
+
console.log(`\n❌ Agent not found: ${agentId}\n`);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
async function showTree() {
|
|
256
|
+
const agents = await loadLifecycleAgents();
|
|
257
|
+
if (agents.length === 0) {
|
|
258
|
+
console.log("\n📋 No agents found. Run 'hive onboard' to create your first agent.\n");
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
const primaries = agents.filter((a) => a.type === "primary" && a.state !== "terminated");
|
|
262
|
+
const printTree = (agent, indent = "") => {
|
|
263
|
+
const icon = agent.state === "active" ? "🟢" : agent.state === "hibernated" ? "💤" : "⚫";
|
|
264
|
+
console.log(`${indent}${icon} ${agent.name} (${agent.id.slice(0, 12)}...)`);
|
|
265
|
+
const children = agents.filter((a) => a.parentId === agent.id);
|
|
266
|
+
for (const child of children) {
|
|
267
|
+
printTree(child, indent + " ");
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
console.log("\n🌳 Agent Hierarchy:\n");
|
|
271
|
+
for (const primary of primaries) {
|
|
272
|
+
printTree(primary);
|
|
273
|
+
}
|
|
274
|
+
console.log("");
|
|
275
|
+
}
|
|
276
|
+
async function addAgent(id) {
|
|
277
|
+
const config = (0, loader_1.loadConfig)();
|
|
278
|
+
if (!id) {
|
|
279
|
+
const result = await p.text({
|
|
280
|
+
message: "ID del nuevo agente:",
|
|
281
|
+
placeholder: "work",
|
|
282
|
+
validate: (v) => (!v ? "El ID es requerido" : undefined),
|
|
283
|
+
});
|
|
284
|
+
if (p.isCancel(result)) {
|
|
285
|
+
p.cancel("Cancelado");
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
id = result;
|
|
289
|
+
}
|
|
290
|
+
const agentsList = config.agents?.list || [];
|
|
291
|
+
if (agentsList.find((a) => a.id === id)) {
|
|
292
|
+
console.log(`❌ Ya existe un agente con ID "${id}"`);
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
const name = await p.text({
|
|
296
|
+
message: "Nombre del agente:",
|
|
297
|
+
placeholder: id,
|
|
298
|
+
defaultValue: id,
|
|
299
|
+
});
|
|
300
|
+
if (p.isCancel(name)) {
|
|
301
|
+
p.cancel("Cancelado");
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
const workspace = path.join((0, loader_1.getHiveDir)(), "agents", id, "workspace");
|
|
305
|
+
const agentDir = path.join((0, loader_1.getHiveDir)(), "agents", id, "agent");
|
|
306
|
+
const newAgent = {
|
|
307
|
+
id: id,
|
|
308
|
+
name: name,
|
|
309
|
+
workspace,
|
|
310
|
+
agentDir,
|
|
311
|
+
};
|
|
312
|
+
fs.mkdirSync(workspace, { recursive: true });
|
|
313
|
+
fs.mkdirSync(agentDir, { recursive: true });
|
|
314
|
+
const soulPath = path.join(agentDir, "SOUL.md");
|
|
315
|
+
if (!fs.existsSync(soulPath)) {
|
|
316
|
+
fs.writeFileSync(soulPath, `# ${name} — Soul\n\nEres ${name}, un agente especializado.\n`, "utf-8");
|
|
317
|
+
}
|
|
318
|
+
const userPath = path.join(agentDir, "USER.md");
|
|
319
|
+
if (!fs.existsSync(userPath)) {
|
|
320
|
+
fs.writeFileSync(userPath, `# User Profile\n\nNotas sobre el usuario.\n`, "utf-8");
|
|
321
|
+
}
|
|
322
|
+
agentsList.push(newAgent);
|
|
323
|
+
console.log(`✅ Agente "${id}" creado`);
|
|
324
|
+
console.log(` Workspace: ${workspace}`);
|
|
325
|
+
console.log(` AgentDir: ${agentDir}`);
|
|
326
|
+
}
|
|
327
|
+
async function listAgents(showBindings) {
|
|
328
|
+
const config = (0, loader_1.loadConfig)();
|
|
329
|
+
const agentsList = config.agents?.list || [];
|
|
330
|
+
if (agentsList.length === 0) {
|
|
331
|
+
console.log("No hay agentes configurados");
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
console.log("\n🐝 Agentes:\n");
|
|
335
|
+
for (const agent of agentsList) {
|
|
336
|
+
const defaultTag = agent.default ? " (default)" : "";
|
|
337
|
+
console.log(` ${agent.id}${defaultTag}`);
|
|
338
|
+
console.log(` Nombre: ${agent.name}`);
|
|
339
|
+
console.log(` Workspace: ${agent.workspace}`);
|
|
340
|
+
if (showBindings) {
|
|
341
|
+
const bindings = config.bindings?.filter((b) => (b.agentId || b.agent) === agent.id) || [];
|
|
342
|
+
console.log(` Bindings: ${bindings.length}`);
|
|
343
|
+
}
|
|
344
|
+
console.log();
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
async function removeAgent(id) {
|
|
348
|
+
if (!id) {
|
|
349
|
+
console.log("❌ Especifica el ID del agente: hive agents remove <id>");
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
const config = (0, loader_1.loadConfig)();
|
|
353
|
+
const agentsList = config.agents?.list || [];
|
|
354
|
+
const agent = agentsList.find((a) => a.id === id);
|
|
355
|
+
if (!agent) {
|
|
356
|
+
console.log(`❌ No existe el agente "${id}"`);
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
if (agent.default) {
|
|
360
|
+
console.log("❌ No puedes eliminar el agente por defecto");
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
const confirm = await p.confirm({
|
|
364
|
+
message: `¿Eliminar el agente "${id}"?`,
|
|
365
|
+
initialValue: false,
|
|
366
|
+
});
|
|
367
|
+
if (p.isCancel(confirm) || !confirm) {
|
|
368
|
+
console.log("Cancelado");
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
console.log(`✅ Agente "${id}" eliminado`);
|
|
372
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function chat(flags: string[]): Promise<void>;
|