@mrtrinhvn/ag-kit 1.3.2 → 1.4.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.
- package/README.md +36 -46
- package/bin/cli.js +107 -189
- package/package.json +1 -1
- package/template/.agent/knowledge/USER.md +4 -0
- package/template/.agent/knowledge/ag-kit-ecosystem.md +168 -0
- package/template/.agent/knowledge/ag-kit-elite.md +6 -3
- package/template/.agent/knowledge/context_isolation.md +16 -0
- package/template/.agent/scripts/_post-commit-hook +8 -0
- package/template/.agent/scripts/brain_builder.py +287 -0
- package/template/.agent/scripts/memory_mcp_server.py +423 -0
- package/template/.agent/scripts/memory_tool.py +367 -0
- package/template/.agent/scripts/receptionist_down.sh +5 -5
- package/template/.agent/scripts/receptionist_up.sh +13 -10
- package/template/.agent/scripts/refresh_brain.sh +21 -0
- package/template/.agent/scripts/repomap.py +32 -3
- package/template/.agent/skills/ag-kit-core/SKILL.md +88 -2
- package/template/.agent/skills/intelligent-routing/SKILL.md +20 -10
- package/template/.agent/skills/telegram-agentic-gateway/SKILL.md +3 -0
- package/template/.agent/skills/telegram-agentic-gateway/templates/start.sh.template +2 -2
package/README.md
CHANGED
|
@@ -1,83 +1,73 @@
|
|
|
1
|
-
# Antigravity Kit
|
|
1
|
+
# Antigravity Kit (`@mrtrinhvn/ag-kit`) 🧠
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Universal Memory System** - Trái tim nhận thức và ghi nhớ cho mọi dự án AI Agentic.
|
|
4
|
+
Cấy ghép Lõi Bộ Nhớ 3 Tầng (.agent) vào bất kỳ dự án nào để cung cấp khả năng lưu trữ Context, cấu trúc Codebase, và Vector Semantic Search (nhờ `Ollama` + `nomic-embed-text`) cho các tác tử AI.
|
|
4
5
|
|
|
5
6
|
## 📦 Quick Start
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
Cách tốt nhất để cấy ghép AG-Kit vào dự án là dùng `npx`. Chạy lệnh sau để mở **Bảng điều khiển Tương tác**:
|
|
8
9
|
|
|
9
10
|
```bash
|
|
10
|
-
# DASHBOARD - Menu chọn tất cả tác vụ (Khuyên dùng)
|
|
11
11
|
npx @mrtrinhvn/ag-kit@latest
|
|
12
12
|
```
|
|
13
13
|
|
|
14
|
-
Hoặc chạy các lệnh đơn
|
|
14
|
+
Hoặc chạy các lệnh đơn lẻ nếu bạn đã nhớ cú pháp:
|
|
15
15
|
```bash
|
|
16
|
-
# 1. Khởi tạo
|
|
16
|
+
# 1. Khởi tạo / Cấy ghép Lõi (.agent folder)
|
|
17
17
|
npx @mrtrinhvn/ag-kit@latest init
|
|
18
18
|
|
|
19
|
-
# 2.
|
|
20
|
-
npx @mrtrinhvn/ag-kit@latest
|
|
19
|
+
# 2. Xây dựng Bộ não (Quét Codebase & Vector hóa ký ức)
|
|
20
|
+
npx @mrtrinhvn/ag-kit@latest brain
|
|
21
21
|
|
|
22
|
-
# 3.
|
|
23
|
-
npx @mrtrinhvn/ag-kit@latest
|
|
22
|
+
# 3. Tra cứu Vector Memory (Xem các node đã lưu)
|
|
23
|
+
npx @mrtrinhvn/ag-kit@latest memory
|
|
24
|
+
|
|
25
|
+
# 4. Kiểm tra cửa ngõ IDE, Telegram Bot (Dành cho project dùng bot)
|
|
26
|
+
npx @mrtrinhvn/ag-kit@latest gateway
|
|
24
27
|
```
|
|
25
28
|
|
|
26
29
|
---
|
|
27
30
|
|
|
28
|
-
## 🛠 Lệnh CLI &
|
|
31
|
+
## 🛠 Lệnh CLI & Hệ sinh thái Bộ Não
|
|
29
32
|
|
|
30
|
-
| Lệnh | Ý nghĩa | Chi tiết |
|
|
33
|
+
| Lệnh | Ý nghĩa | Chi tiết tác vụ |
|
|
31
34
|
|---|---|---|
|
|
32
|
-
| `ag-kit` | **Dashboard** |
|
|
33
|
-
| `ag-kit init` | **Khởi tạo** |
|
|
34
|
-
| `ag-kit
|
|
35
|
-
| `ag-kit
|
|
36
|
-
| `ag-kit
|
|
35
|
+
| `ag-kit` | **Dashboard** | Mở menu tương tác trực quan. Khuyên dùng. |
|
|
36
|
+
| `ag-kit init` | **Khởi tạo** | Cấy ghép toàn bộ tủy não `.agent` vào dự án trắng. |
|
|
37
|
+
| `ag-kit brain` | **Bộ Não** | Tự động gọi `brain_builder.py` để quét Codebase, trích xuất Vector Memory và viết Báo cáo Nhận thức `summary.md`. |
|
|
38
|
+
| `ag-kit memory` | **Ký ức** | Hiển thị các Mảnh ký ức (Hot/Cold Nodes) đang được lưu trong Không gian Vector `graph.db`. |
|
|
39
|
+
| `ag-kit gateway` | **Bot Test** | (Tùy chọn) Quét cổng CDP (IDE), Ollama và Telegram Bot Token cho các dự án dùng Agentic bot. |
|
|
40
|
+
| `ag-kit update` | **Cập nhật** | Nâng cấp Agents/Skills/Workflows mới nhất từ NPM mà không làm mất dữ liệu Ký ức hoặc Knowledge của dự án. |
|
|
41
|
+
| `ag-kit status` | **Trạng thái** | Hiển thị phiên bản Tool và kiểm tra xem Bộ Não (`summary.md`) đã được hình thành chưa. |
|
|
37
42
|
|
|
38
|
-
|
|
43
|
+
---
|
|
39
44
|
|
|
40
|
-
|
|
45
|
+
## 🏗 Kiến trúc Trí nhớ 3 Tầng (3-Tier Memory)
|
|
41
46
|
|
|
42
|
-
|
|
43
|
-
CDP_PORT=12345
|
|
44
|
-
```
|
|
45
|
-
Lệnh `ag-kit check` sẽ tự động ưu tiên cổng này để kết nối với IDE.
|
|
47
|
+
Sau khi chạy `init` và `brain`, dự án của bạn sẽ vận hành theo mô hình:
|
|
46
48
|
|
|
47
|
-
|
|
49
|
+
1. **Lớp L1 (Working Index):** `repomap.json` - Sơ đồ hàm, class của toàn bộ codebase.
|
|
50
|
+
2. **Lớp L2 (Graph Vector Memory):** `graph.db` - Cơ sở dữ liệu đồ thị + Vector Embeddings. Hệ thống ngầm gọi **Ollama (nomic-embed-text)** để mã hóa mọi lệnh `memory_save` thành toán học, cho phép RAG tìm kiếm theo ý nghĩa (Semantic Search) với độ trễ 0ms và chi phí API $0.
|
|
51
|
+
3. **Lớp L3 (Knowledge Base):** Báo cáo `summary.md` + file markdown gốc của dự án.
|
|
48
52
|
|
|
49
|
-
##
|
|
53
|
+
## 🤖 Dual-Model Coordination
|
|
50
54
|
|
|
51
|
-
|
|
55
|
+
Gói `ag-kit` khuyến khích nguyên lý kết hợp 2 AI:
|
|
56
|
+
- **Local AI (Ollama):** Đảm nhiệm việc đánh chỉ mục Vector (Embedding) lặng lẽ ở background.
|
|
57
|
+
- **Cloud AI (Gemini/Claude):** Dùng để suy luận logic và viết code dựa trên Context mớm từ Local AI.
|
|
52
58
|
|
|
53
|
-
|
|
54
|
-
- **`agents/`**: Các đặc vụ chuyên trách (Orchestrator, Frontend, Backend, Debugger).
|
|
55
|
-
- **`skills/`**: Các thuật toán tác chiến (Clean code, TDD, React Expert, Rust Pro...).
|
|
56
|
-
- **`workflows/`**: Các lệnh gõ tắt (slash commands) như `/create`, `/plan`, `/debug`.
|
|
57
|
-
- **`knowledge/`**: Nơi lưu giữ giao thức v3 và các kiến thức tự chữa lành (`self-healing`).
|
|
59
|
+
> Vui lòng tải model: `ollama pull nomic-embed-text` để kích hoạt tính năng Semantic Search của `ag-kit`.
|
|
58
60
|
|
|
59
61
|
---
|
|
60
62
|
|
|
61
63
|
## 🔄 Cập nhật & Bảo trì
|
|
62
64
|
|
|
63
|
-
Chúng tôi liên tục
|
|
65
|
+
Chúng tôi liên tục nâng cấp kỹ năng cho Agent (Skills, Workflows). Để bộ não dự án của bạn luôn thông minh nhất:
|
|
64
66
|
|
|
65
67
|
```bash
|
|
66
|
-
# Luôn dùng @latest để lấy
|
|
68
|
+
# Luôn dùng @latest để lấy bộ kỹ năng mới nhất
|
|
67
69
|
npx @mrtrinhvn/ag-kit@latest update
|
|
68
70
|
```
|
|
69
71
|
|
|
70
72
|
---
|
|
71
|
-
|
|
72
|
-
## ❌ Xử lý lỗi thường gặp (Troubleshooting)
|
|
73
|
-
|
|
74
|
-
**1. Lỗi phiên bản không khớp (Version ghosting):**
|
|
75
|
-
Nếu `status` báo phiên bản cũ hơn bản trên NPM, đó là do cache của `npx` hoặc bạn đã cài global.
|
|
76
|
-
- Cách giải quyết: Luôn thêm `@latest` sau tên gói (`npx @mrtrinhvn/ag-kit@latest`) hoặc cập nhật bộ não bằng lệnh `ag-kit update`.
|
|
77
|
-
- Giờ đây, các lệnh `init` và `status` sẽ tự động phát hiện và nhắc bạn chạy `update` nếu phát hiện lệch phiên bản.
|
|
78
|
-
|
|
79
|
-
**2. Lỗi EACCES (Quyền truy cập):**
|
|
80
|
-
Nếu cài global bị báo lỗi quyền, hãy dùng `npx` (Khuyên dùng) hoặc dùng `sudo`.
|
|
81
|
-
|
|
82
|
-
---
|
|
83
|
-
*Built with ❤️ to enforce Institutional-Grade Software Standards.*
|
|
73
|
+
*Built with ❤️ to enforce Institutional-Grade AI Memory Standards.*
|
package/bin/cli.js
CHANGED
|
@@ -2,31 +2,11 @@
|
|
|
2
2
|
const { program } = require('commander');
|
|
3
3
|
const fs = require('fs');
|
|
4
4
|
const path = require('path');
|
|
5
|
-
const
|
|
5
|
+
const { execSync } = require('child_process');
|
|
6
6
|
|
|
7
7
|
const TEMPLATE_DIR = path.join(__dirname, '..', 'template');
|
|
8
8
|
const TARGET_AGENT_DIR = path.join(process.cwd(), '.agent');
|
|
9
9
|
|
|
10
|
-
function isPortAvailable(port) {
|
|
11
|
-
return new Promise((resolve) => {
|
|
12
|
-
const server = net.createServer();
|
|
13
|
-
server.once('error', () => resolve(false));
|
|
14
|
-
server.once('listening', () => {
|
|
15
|
-
server.close();
|
|
16
|
-
resolve(true);
|
|
17
|
-
});
|
|
18
|
-
server.listen(port, '127.0.0.1');
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
async function findNextAvailablePort(startPort) {
|
|
23
|
-
let port = startPort;
|
|
24
|
-
while (!(await isPortAvailable(port))) {
|
|
25
|
-
port++;
|
|
26
|
-
}
|
|
27
|
-
return port;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
10
|
// Helper copy đệ quy
|
|
31
11
|
function copyRecursiveSync(src, dest) {
|
|
32
12
|
const exists = fs.existsSync(src);
|
|
@@ -44,108 +24,42 @@ function copyRecursiveSync(src, dest) {
|
|
|
44
24
|
}
|
|
45
25
|
}
|
|
46
26
|
|
|
47
|
-
|
|
48
|
-
function migrateLegacyMemories() {
|
|
49
|
-
const legacyDir = path.join(process.cwd(), 'data', 'memories');
|
|
50
|
-
if (!fs.existsSync(legacyDir)) return;
|
|
51
|
-
|
|
52
|
-
let migratedCount = 0;
|
|
53
|
-
try {
|
|
54
|
-
const files = fs.readdirSync(legacyDir).filter(f => f.endsWith('.jsonl'));
|
|
55
|
-
for (const file of files) {
|
|
56
|
-
const filePath = path.join(legacyDir, file);
|
|
57
|
-
const lines = fs.readFileSync(filePath, 'utf-8').split('\n');
|
|
58
|
-
let changed = false;
|
|
59
|
-
const newLines = lines.map(line => {
|
|
60
|
-
if (!line.trim()) return line;
|
|
61
|
-
try {
|
|
62
|
-
const item = JSON.parse(line);
|
|
63
|
-
if (item.content && !item.content.includes('[Node:')) {
|
|
64
|
-
item.content = `[Node:Legacy_Knowledge] => ${item.content}`;
|
|
65
|
-
changed = true;
|
|
66
|
-
return JSON.stringify(item);
|
|
67
|
-
}
|
|
68
|
-
} catch(e) {}
|
|
69
|
-
return line;
|
|
70
|
-
});
|
|
71
|
-
if (changed) {
|
|
72
|
-
fs.writeFileSync(filePath, newLines.join('\n'));
|
|
73
|
-
migratedCount++;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
if (migratedCount > 0) {
|
|
77
|
-
console.log(`\x1b[35m🧠 TỰ ĐỘNG: Đã băm ${migratedCount} tệp Ký ức cũ thành Tiền-Đồ-Thị (Pseudo-Graph) để tương thích chuẩn mới!\x1b[0m`);
|
|
78
|
-
}
|
|
79
|
-
} catch(e) { /* ignore errors during migration */ }
|
|
80
|
-
}
|
|
81
|
-
|
|
82
27
|
const pkg = require('../package.json');
|
|
83
28
|
program
|
|
84
29
|
.name('ag-kit')
|
|
85
|
-
.description('
|
|
30
|
+
.description('Antigravity Kit - Hệ thống Trí nhớ và Nhận thức AI Phổ quát')
|
|
86
31
|
.version(pkg.version);
|
|
87
32
|
|
|
88
33
|
program.command('init')
|
|
89
|
-
.description('
|
|
34
|
+
.description('Cấy ghép Lõi Trí Nhớ (.agent) vào dự án này')
|
|
90
35
|
.action(() => {
|
|
91
36
|
console.log('\x1b[36m🚀 Đang khởi tạo bộ Tủy Não Lập Trình AI (AG-Kit)...\x1b[0m');
|
|
92
37
|
|
|
93
38
|
const srcAgent = path.join(TEMPLATE_DIR, '.agent');
|
|
94
39
|
if (!fs.existsSync(TARGET_AGENT_DIR)) {
|
|
95
40
|
copyRecursiveSync(srcAgent, TARGET_AGENT_DIR);
|
|
96
|
-
// Ghi lại version vào .agent/.version
|
|
97
41
|
fs.writeFileSync(path.join(TARGET_AGENT_DIR, '.version'), pkg.version);
|
|
98
|
-
console.log(`\x1b[32m✅ Đã
|
|
42
|
+
console.log(`\x1b[32m✅ Đã cấy ghép thành công thư mục .agent (v${pkg.version}) vào Project!\x1b[0m`);
|
|
99
43
|
|
|
100
|
-
|
|
101
|
-
const envPath = path.join(process.cwd(), '.env');
|
|
102
|
-
(async () => {
|
|
103
|
-
const idePort = await findNextAvailablePort(9555);
|
|
104
|
-
const bridgePort = await findNextAvailablePort(idePort + 1);
|
|
105
|
-
|
|
106
|
-
if (!fs.existsSync(envPath)) {
|
|
107
|
-
const envTemplate = `# --- Remote Orchestration (Golden Combo) ---\nIDE_PORT=${idePort}\nBRIDGE_PORT=${bridgePort}\n\nPROJECT_NAME=ag-project\n`;
|
|
108
|
-
fs.writeFileSync(envPath, envTemplate);
|
|
109
|
-
console.log(`\x1b[34mℹ️ Đã tạo .env với IDE_PORT=${idePort} và BRIDGE_PORT=${bridgePort}\x1b[0m`);
|
|
110
|
-
} else {
|
|
111
|
-
let envContent = fs.readFileSync(envPath, 'utf-8');
|
|
112
|
-
let changed = false;
|
|
113
|
-
if (!envContent.includes('IDE_PORT=')) {
|
|
114
|
-
envContent += `\nIDE_PORT=${idePort}\n`;
|
|
115
|
-
changed = true;
|
|
116
|
-
}
|
|
117
|
-
if (!envContent.includes('BRIDGE_PORT=')) {
|
|
118
|
-
envContent += `BRIDGE_PORT=${bridgePort}\n`;
|
|
119
|
-
changed = true;
|
|
120
|
-
}
|
|
121
|
-
if (changed) {
|
|
122
|
-
fs.writeFileSync(envPath, envContent);
|
|
123
|
-
console.log(`\x1b[34mℹ️ Đã bổ sung cổng tự động: IDE_PORT=${idePort}, BRIDGE_PORT=${bridgePort}\x1b[0m`);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
})();
|
|
44
|
+
console.log('\x1b[35m👉 Bước tiếp theo: Hãy chọn menu "Build Bộ Não" để quét dự án.\x1b[0m');
|
|
127
45
|
} else {
|
|
128
46
|
console.log('\x1b[33m⚠️ Thư mục .agent đã tồn tại.\x1b[0m');
|
|
129
47
|
const vPath = path.join(TARGET_AGENT_DIR, '.version');
|
|
130
48
|
if (fs.existsSync(vPath)) {
|
|
131
49
|
const installedVersion = fs.readFileSync(vPath, 'utf-8').trim();
|
|
132
50
|
if (installedVersion !== pkg.version) {
|
|
133
|
-
console.log(`\x1b[35m👉 Phát hiện phiên bản cũ (v${installedVersion}). Hãy dùng lệnh "ag-kit update"
|
|
51
|
+
console.log(`\x1b[35m👉 Phát hiện phiên bản cũ (v${installedVersion}). Hãy dùng lệnh "ag-kit update".\x1b[0m`);
|
|
134
52
|
} else {
|
|
135
53
|
console.log(`\x1b[34mℹ️ Bạn đang sử dụng phiên bản khớp với bộ công cụ (v${pkg.version}).\x1b[0m`);
|
|
136
54
|
}
|
|
137
|
-
} else {
|
|
138
|
-
console.log('\x1b[35m👉 Hãy dùng lệnh "ag-kit update" để đồng bộ cấu trúc mới.\x1b[0m');
|
|
139
55
|
}
|
|
140
56
|
}
|
|
141
|
-
|
|
142
|
-
console.log('\x1b[35m\n🎉 Hoàn tất! Vui lòng copy luật GEMINI vào file GEMINI.md của dự án nếu chưa có.\x1b[0m');
|
|
143
57
|
});
|
|
144
58
|
|
|
145
59
|
program.command('update')
|
|
146
|
-
.description('
|
|
60
|
+
.description('Nâng cấp các kỹ năng AI lên phiên bản mới nhất')
|
|
147
61
|
.action(() => {
|
|
148
|
-
console.log('\x1b[36m🔄 Đang
|
|
62
|
+
console.log('\x1b[36m🔄 Đang nâng cấp Kỹ năng AI (AG-Kit)...\x1b[0m');
|
|
149
63
|
const srcAgent = path.join(TEMPLATE_DIR, '.agent');
|
|
150
64
|
const vPath = path.join(TARGET_AGENT_DIR, '.version');
|
|
151
65
|
let oldVersion = '0.0.0';
|
|
@@ -153,9 +67,8 @@ program.command('update')
|
|
|
153
67
|
oldVersion = fs.readFileSync(vPath, 'utf-8').trim();
|
|
154
68
|
}
|
|
155
69
|
|
|
156
|
-
// Chỉ cập nhật
|
|
157
|
-
|
|
158
|
-
['agents', 'skills', 'workflows', 'scripts', 'rules'].forEach(folder => {
|
|
70
|
+
// Chỉ cập nhật các thư mục chuẩn, KHÔNG chạm vào .agent/brain, .agent/cache, .agent/memory
|
|
71
|
+
['agents', 'skills', 'workflows', 'scripts', 'rules', 'knowledge'].forEach(folder => {
|
|
159
72
|
const src = path.join(srcAgent, folder);
|
|
160
73
|
const dest = path.join(TARGET_AGENT_DIR, folder);
|
|
161
74
|
if (fs.existsSync(src)) {
|
|
@@ -163,119 +76,119 @@ program.command('update')
|
|
|
163
76
|
}
|
|
164
77
|
});
|
|
165
78
|
|
|
166
|
-
migrateLegacyMemories();
|
|
167
|
-
// Cập nhật version vào .agent/.version
|
|
168
79
|
fs.writeFileSync(vPath, pkg.version);
|
|
169
|
-
console.log(`\x1b[32m✅
|
|
170
|
-
console.log('\x1b[34m⚡️ Toàn bộ cấu trúc kỹ năng đã được đồng bộ.\x1b[0m');
|
|
80
|
+
console.log(`\x1b[32m✅ Nâng cấp thành công! Phiên bản hiện tại: v${oldVersion} -> v${pkg.version}\x1b[0m`);
|
|
171
81
|
});
|
|
172
82
|
|
|
173
|
-
program.command('
|
|
174
|
-
.description('
|
|
175
|
-
.action(
|
|
176
|
-
|
|
177
|
-
console.log('\x1b[36m🔍 Đang kiểm tra hệ sinh thái Antigravity...\x1b[0m');
|
|
178
|
-
|
|
83
|
+
program.command('brain')
|
|
84
|
+
.description('Quét Repo và Xây dựng/Cập nhật Bộ não (3-Tier Memory)')
|
|
85
|
+
.action(() => {
|
|
86
|
+
console.log('\x1b[36m🧠 Đang khởi động tiến trình Tổng hợp Bộ Não...\x1b[0m');
|
|
179
87
|
if (!fs.existsSync(TARGET_AGENT_DIR)) {
|
|
180
|
-
console.log('\x1b[31m❌
|
|
181
|
-
console.log('\x1b[35m👉 Hãy chạy "ag-kit init" trước khi thực hiện kiểm tra này.\x1b[0m');
|
|
88
|
+
console.log('\x1b[31m❌ Chưa cấy ghép .agent. Hãy chạy "ag-kit init" trước.\x1b[0m');
|
|
182
89
|
return;
|
|
183
90
|
}
|
|
184
91
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
console.log('\x1b[
|
|
189
|
-
|
|
190
|
-
|
|
92
|
+
try {
|
|
93
|
+
// Gọi Python script brain_builder với cờ --update
|
|
94
|
+
console.log('\x1b[35m[1/3] Quét cấu trúc Codebase...\x1b[0m');
|
|
95
|
+
console.log('\x1b[35m[2/3] Trích xuất Vector Memory...\x1b[0m');
|
|
96
|
+
console.log('\x1b[35m[3/3] Viết báo cáo Nhận thức...\x1b[0m\n');
|
|
97
|
+
|
|
98
|
+
const scriptPath = path.join(TARGET_AGENT_DIR, 'scripts', 'brain_builder.py');
|
|
99
|
+
execSync(`python3 ${scriptPath} --update`, { stdio: 'inherit' });
|
|
100
|
+
|
|
101
|
+
console.log('\n\x1b[32m✅ Bộ Não đã được tổng hợp thành công tại .agent/brain/summary.md!\x1b[0m');
|
|
102
|
+
} catch (e) {
|
|
103
|
+
console.log('\n\x1b[31m❌ Lỗi khi xây dựng Bộ Não. Hãy chắc chắn máy bạn có Python 3.\x1b[0m');
|
|
191
104
|
}
|
|
105
|
+
});
|
|
192
106
|
|
|
193
|
-
|
|
107
|
+
program.command('memory')
|
|
108
|
+
.description('Tra cứu Bộ nhớ Thực (Vector Memory)')
|
|
109
|
+
.action(() => {
|
|
110
|
+
console.log('\x1b[36m🕸️ Tra cứu Trí nhớ Semantic (graph.db)...\x1b[0m');
|
|
111
|
+
if (!fs.existsSync(TARGET_AGENT_DIR)) {
|
|
112
|
+
console.log('\x1b[31m❌ Chưa cấy ghép .agent. Hãy chạy "ag-kit init" trước.\x1b[0m');
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
try {
|
|
116
|
+
const scriptPath = path.join(TARGET_AGENT_DIR, 'scripts', 'memory_tool.py');
|
|
117
|
+
execSync(`python3 ${scriptPath} list --limit 10`, { stdio: 'inherit' });
|
|
118
|
+
} catch (e) {
|
|
119
|
+
console.log('\n\x1b[31m❌ Không thể đọc memory. Đã build brain chưa?\x1b[0m');
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
program.command('gateway')
|
|
124
|
+
.description('Kiểm tra trạng thái Agentic Gateway (IDE, Ollama, Telegram)')
|
|
125
|
+
.action(() => {
|
|
126
|
+
console.log('\x1b[36m🤖 Đang kiểm tra hệ sinh thái Agentic Gateway...\x1b[0m');
|
|
127
|
+
if (!fs.existsSync(TARGET_AGENT_DIR)) {
|
|
128
|
+
console.log('\x1b[31m❌ Chưa cấy ghép .agent.\x1b[0m');
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
const envPath = path.join(process.cwd(), '.env');
|
|
194
132
|
let ports = [9555, 9222];
|
|
195
133
|
if (fs.existsSync(envPath)) {
|
|
196
|
-
const
|
|
197
|
-
|
|
198
|
-
if (match) {
|
|
199
|
-
const customPort = parseInt(match[1]);
|
|
200
|
-
ports = [customPort, ...ports.filter(p => p !== customPort)];
|
|
201
|
-
console.log(`\x1b[34mℹ️ Sử dụng cổng CDP tùy chỉnh từ .env: ${customPort}\x1b[0m`);
|
|
202
|
-
}
|
|
134
|
+
const match = fs.readFileSync(envPath, 'utf-8').match(/CDP_PORT=(\d+)/);
|
|
135
|
+
if (match) ports.unshift(parseInt(match[1]));
|
|
203
136
|
}
|
|
204
|
-
|
|
137
|
+
|
|
205
138
|
let cdpOk = false;
|
|
206
139
|
for (const port of ports) {
|
|
207
|
-
try {
|
|
208
|
-
execSync(`curl -s --max-time 2 http://127.0.0.1:${port}/json/version`, { stdio: 'ignore' });
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
break;
|
|
140
|
+
try {
|
|
141
|
+
execSync(`curl -s --max-time 2 http://127.0.0.1:${port}/json/version`, { stdio: 'ignore' });
|
|
142
|
+
cdpOk = true;
|
|
143
|
+
console.log(`\x1b[32m✅ IDE CDP: Phát hiện tại cổng ${port}\x1b[0m`);
|
|
144
|
+
break;
|
|
212
145
|
} catch (e) {}
|
|
213
146
|
}
|
|
214
147
|
if (!cdpOk) console.log(`\x1b[31m❌ IDE CDP: Không tìm thấy IDE đang chạy ở các cổng: ${ports.join(', ')}\x1b[0m`);
|
|
215
|
-
|
|
216
|
-
// 3. Check Ollama
|
|
148
|
+
|
|
217
149
|
try {
|
|
218
|
-
execSync('ollama --version', { stdio: 'ignore' });
|
|
150
|
+
execSync('ollama --version', { stdio: 'ignore' });
|
|
219
151
|
console.log('\x1b[32m✅ Ollama: Đã cài đặt\x1b[0m');
|
|
220
|
-
try {
|
|
221
|
-
execSync('curl -s --max-time 2 http://127.0.0.1:11434/api/tags', { stdio: 'ignore' });
|
|
222
|
-
console.log('\x1b[32m✅ Ollama Service: Online\x1b[0m');
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
const models = execSync('curl -s http://127.0.0.1:11434/api/tags').toString();
|
|
226
|
-
if (models.includes('nvidia_Orchestrator')) {
|
|
227
|
-
console.log('\x1b[32m✅ Default Model: nvidia_Orchestrator (Sẵn sàng)\x1b[0m');
|
|
228
|
-
} else {
|
|
229
|
-
console.log('\x1b[33m⚠️ Default Model: nvidia_Orchestrator (Chưa tải - Khuyên dùng "ollama run hf.co/bartowski/nvidia_Orchestrator-8B-GGUF:Q4_K_M")\x1b[0m');
|
|
230
|
-
}
|
|
231
|
-
} catch (e) {
|
|
232
|
-
console.log('\x1b[31m❌ Ollama Service: Offline (Gõ "ollama serve")\x1b[0m');
|
|
152
|
+
try {
|
|
153
|
+
execSync('curl -s --max-time 2 http://127.0.0.1:11434/api/tags', { stdio: 'ignore' });
|
|
154
|
+
console.log('\x1b[32m✅ Ollama Service: Online\x1b[0m');
|
|
155
|
+
} catch (e) {
|
|
156
|
+
console.log('\x1b[31m❌ Ollama Service: Offline\x1b[0m');
|
|
233
157
|
}
|
|
234
|
-
} catch
|
|
235
|
-
console.log('\x1b[33m⚠️ Ollama: Chưa cài đặt
|
|
158
|
+
} catch(e) {
|
|
159
|
+
console.log('\x1b[33m⚠️ Ollama: Chưa cài đặt.\x1b[0m');
|
|
236
160
|
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
console.log('\x1b[32m✅ Telegram Token: Đã cấu hình\x1b[0m');
|
|
243
|
-
} else {
|
|
244
|
-
console.log('\x1b[33m⚠️ Telegram Token: Chưa cấu hình hoặc dùng giá trị mặc định.\x1b[0m');
|
|
245
|
-
}
|
|
161
|
+
|
|
162
|
+
if (fs.existsSync(envPath) && fs.readFileSync(envPath, 'utf-8').includes('TELEGRAM_BOT_TOKEN=')) {
|
|
163
|
+
console.log('\x1b[32m✅ Telegram Token: Có trong .env\x1b[0m');
|
|
164
|
+
} else {
|
|
165
|
+
console.log('\x1b[33m⚠️ Telegram Token: Chưa cấu hình\x1b[0m');
|
|
246
166
|
}
|
|
247
|
-
|
|
248
|
-
console.log('\n\x1b[35m✨ Kiểm tra hoàn tất. Hãy đảm bảo IDE và Bot cùng tần số!\x1b[0m');
|
|
249
167
|
});
|
|
250
168
|
|
|
251
169
|
program.command('status')
|
|
252
|
-
.description('
|
|
170
|
+
.description('Xem trạng thái cài đặt')
|
|
253
171
|
.action(() => {
|
|
254
|
-
console.log('\x1b[36m📊 Trạng thái AG-Kit
|
|
172
|
+
console.log('\x1b[36m📊 Trạng thái AG-Kit:\x1b[0m');
|
|
255
173
|
if (fs.existsSync(TARGET_AGENT_DIR)) {
|
|
256
174
|
console.log('\x1b[32m✅ Trạng thái : Đã Cài Đặt (Active)\x1b[0m');
|
|
257
|
-
console.log(`📁 Đường dẫn : ${TARGET_AGENT_DIR}`);
|
|
258
175
|
|
|
259
176
|
const vPath = path.join(TARGET_AGENT_DIR, '.version');
|
|
260
177
|
let installedVersion = '0.0.0';
|
|
261
178
|
if (fs.existsSync(vPath)) {
|
|
262
179
|
installedVersion = fs.readFileSync(vPath, 'utf-8').trim();
|
|
263
180
|
console.log(`🧠 Bản cài đặt : v${installedVersion}`);
|
|
264
|
-
} else {
|
|
265
|
-
console.log(`🧠 Bản cài đặt : Không rõ (Legacy)`);
|
|
266
181
|
}
|
|
267
|
-
|
|
268
|
-
console.log(`🏷 Bản Tool : v${pkg.version}`);
|
|
269
182
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
console.log(
|
|
183
|
+
const brainPath = path.join(TARGET_AGENT_DIR, 'brain', 'summary.md');
|
|
184
|
+
if (fs.existsSync(brainPath)) {
|
|
185
|
+
console.log(`📚 Nhận thức : Đã có não (summary.md)`);
|
|
186
|
+
} else {
|
|
187
|
+
console.log(`📚 Nhận thức : \x1b[33mChưa có não. Gõ "ag-kit brain" để tạo.\x1b[0m`);
|
|
273
188
|
}
|
|
274
189
|
|
|
275
190
|
} else {
|
|
276
|
-
console.log('\x1b[31m❌ Trạng thái :
|
|
277
|
-
console.log('\x1b[35m👉 Gõ "ag-kit init" để biến thư mục này thành một Agentic Workspace!\x1b[0m');
|
|
278
|
-
console.log(`🏷 Bản Tool : v${pkg.version}`);
|
|
191
|
+
console.log('\x1b[31m❌ Trạng thái : Dự án Trắng.\x1b[0m');
|
|
279
192
|
}
|
|
280
193
|
});
|
|
281
194
|
|
|
@@ -283,45 +196,50 @@ program.command('status')
|
|
|
283
196
|
async function runInteractiveMenu() {
|
|
284
197
|
const inquirer = require('inquirer');
|
|
285
198
|
console.clear();
|
|
286
|
-
console.log('\x1b[35m\n🧠
|
|
199
|
+
console.log('\x1b[35m\n🧠 AG-KIT - BẢNG ĐIỀU KHIỂN HỆ SINH THÁI AI\x1b[0m');
|
|
287
200
|
console.log('\x1b[34m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\x1b[0m');
|
|
288
201
|
|
|
289
202
|
const hasAgent = fs.existsSync(TARGET_AGENT_DIR);
|
|
203
|
+
const vPath = path.join(TARGET_AGENT_DIR, '.version');
|
|
204
|
+
let updateTag = '';
|
|
205
|
+
if (hasAgent && fs.existsSync(vPath)) {
|
|
206
|
+
const installed = fs.readFileSync(vPath, 'utf-8').trim();
|
|
207
|
+
if (installed !== pkg.version) {
|
|
208
|
+
updateTag = `\x1b[31m(Có bản mới: v${pkg.version})\x1b[0m `;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
290
211
|
|
|
291
212
|
const choices = hasAgent ? [
|
|
292
|
-
{ name:
|
|
293
|
-
{ name:
|
|
294
|
-
{ name:
|
|
213
|
+
{ name: `🧠 Xây dựng / Cập nhật Bộ Não (build brain) - Thu thập Context`, value: 'brain' },
|
|
214
|
+
{ name: `🕸️ Khám phá Ký ức (memory) - Xem dữ liệu Vector`, value: 'memory' },
|
|
215
|
+
{ name: `🤖 Kiểm tra Agentic Gateway (gateway) - Test IDE/Bot`, value: 'gateway' },
|
|
216
|
+
{ name: `🔄 Nâng cấp Kiến thức (update) ${updateTag}`, value: 'update' },
|
|
217
|
+
{ name: '📊 Trạng thái (status) - Xem version & độ nhận thức', value: 'status' },
|
|
295
218
|
new inquirer.Separator(),
|
|
296
219
|
{ name: '❌ Thoát', value: 'exit' }
|
|
297
220
|
] : [
|
|
298
|
-
{ name: '🚀 Khởi tạo (init) - Cấy ghép Tủy Não .agent vào
|
|
221
|
+
{ name: '🚀 Khởi tạo (init) - Cấy ghép Tủy Não .agent vào thư mục này', value: 'init' },
|
|
299
222
|
new inquirer.Separator(),
|
|
300
223
|
{ name: '❌ Thoát', value: 'exit' }
|
|
301
224
|
];
|
|
302
225
|
|
|
303
226
|
const { action } = await inquirer.prompt([
|
|
304
227
|
{
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
228
|
+
type: 'list',
|
|
229
|
+
name: 'action',
|
|
230
|
+
message: hasAgent ? 'Lõi .agent đã sẵn sàng. Bạn muốn làm gì?' : 'Thư mục trống. Hãy chọn thao tác:',
|
|
231
|
+
choices: choices
|
|
309
232
|
}
|
|
310
233
|
]);
|
|
311
234
|
|
|
312
235
|
if (action === 'exit') {
|
|
313
|
-
console.log('\x1b[36m👋 Tạm biệt
|
|
236
|
+
console.log('\x1b[36m👋 Tạm biệt!\x1b[0m\n');
|
|
314
237
|
process.exit(0);
|
|
315
238
|
}
|
|
316
239
|
|
|
317
|
-
|
|
318
|
-
console.log('\n\x1b[34m--- ĐANG THỰC THI ---\x1b[0m');
|
|
319
|
-
|
|
320
|
-
// Chúng ta parse lại command với action đã chọn
|
|
321
|
-
// Lưu ý: commander parse() trả về promise với parseAsync
|
|
240
|
+
console.log('\n\x1b[34m--- ĐANG THỰC THI ---\x1b[0m\n');
|
|
322
241
|
await program.parseAsync([process.argv[0], process.argv[1], action]);
|
|
323
|
-
|
|
324
|
-
console.log('\n\x1b[34m--- HOÀN TẤT TÁC VỤ ---\x1b[0m');
|
|
242
|
+
console.log('\n\x1b[34m--- HOÀN TẤT ---\x1b[0m\n');
|
|
325
243
|
|
|
326
244
|
const { resume } = await inquirer.prompt([
|
|
327
245
|
{
|
|
@@ -336,7 +254,7 @@ async function runInteractiveMenu() {
|
|
|
336
254
|
|
|
337
255
|
if (process.argv.length <= 2) {
|
|
338
256
|
runInteractiveMenu().catch(err => {
|
|
339
|
-
console.error('\x1b[31m❌ Lỗi
|
|
257
|
+
console.error('\x1b[31m❌ Lỗi:\x1b[0m', err);
|
|
340
258
|
process.exit(1);
|
|
341
259
|
});
|
|
342
260
|
} else {
|
package/package.json
CHANGED