@mrtrinhvn/ag-kit 1.3.1 → 1.4.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.
- package/README.md +32 -46
- package/bin/cli.js +79 -201
- 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,69 @@
|
|
|
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
24
|
```
|
|
25
25
|
|
|
26
26
|
---
|
|
27
27
|
|
|
28
|
-
## 🛠 Lệnh CLI &
|
|
28
|
+
## 🛠 Lệnh CLI & Hệ sinh thái Bộ Não
|
|
29
29
|
|
|
30
|
-
| Lệnh | Ý nghĩa | Chi tiết |
|
|
30
|
+
| Lệnh | Ý nghĩa | Chi tiết tác vụ |
|
|
31
31
|
|---|---|---|
|
|
32
|
-
| `ag-kit` | **Dashboard** |
|
|
33
|
-
| `ag-kit init` | **Khởi tạo** |
|
|
34
|
-
| `ag-kit
|
|
35
|
-
| `ag-kit
|
|
36
|
-
| `ag-kit
|
|
32
|
+
| `ag-kit` | **Dashboard** | Mở menu tương tác trực quan. Khuyên dùng. |
|
|
33
|
+
| `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. |
|
|
34
|
+
| `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`. |
|
|
35
|
+
| `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`. |
|
|
36
|
+
| `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. |
|
|
37
|
+
| `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
38
|
|
|
38
|
-
|
|
39
|
+
---
|
|
39
40
|
|
|
40
|
-
|
|
41
|
+
## 🏗 Kiến trúc Trí nhớ 3 Tầng (3-Tier Memory)
|
|
41
42
|
|
|
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.
|
|
43
|
+
Sau khi chạy `init` và `brain`, dự án của bạn sẽ vận hành theo mô hình:
|
|
46
44
|
|
|
47
|
-
|
|
45
|
+
1. **Lớp L1 (Working Index):** `repomap.json` - Sơ đồ hàm, class của toàn bộ codebase.
|
|
46
|
+
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.
|
|
47
|
+
3. **Lớp L3 (Knowledge Base):** Báo cáo `summary.md` + file markdown gốc của dự án.
|
|
48
48
|
|
|
49
|
-
##
|
|
49
|
+
## 🤖 Dual-Model Coordination
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
Gói `ag-kit` khuyến khích nguyên lý kết hợp 2 AI:
|
|
52
|
+
- **Local AI (Ollama):** Đảm nhiệm việc đánh chỉ mục Vector (Embedding) lặng lẽ ở background.
|
|
53
|
+
- **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
54
|
|
|
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`).
|
|
55
|
+
> 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
56
|
|
|
59
57
|
---
|
|
60
58
|
|
|
61
59
|
## 🔄 Cập nhật & Bảo trì
|
|
62
60
|
|
|
63
|
-
Chúng tôi liên tục
|
|
61
|
+
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
62
|
|
|
65
63
|
```bash
|
|
66
|
-
# Luôn dùng @latest để lấy
|
|
64
|
+
# Luôn dùng @latest để lấy bộ kỹ năng mới nhất
|
|
67
65
|
npx @mrtrinhvn/ag-kit@latest update
|
|
68
66
|
```
|
|
69
67
|
|
|
70
68
|
---
|
|
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.*
|
|
69
|
+
*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,73 @@ 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
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
const match = content.match(/CDP_PORT=(\d+)/);
|
|
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
|
-
}
|
|
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');
|
|
203
104
|
}
|
|
105
|
+
});
|
|
204
106
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
} catch (e) {}
|
|
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;
|
|
213
114
|
}
|
|
214
|
-
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
|
|
217
115
|
try {
|
|
218
|
-
|
|
219
|
-
|
|
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
|
-
// Kiểm tra model mặc định
|
|
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');
|
|
233
|
-
}
|
|
116
|
+
const scriptPath = path.join(TARGET_AGENT_DIR, 'scripts', 'memory_tool.py');
|
|
117
|
+
execSync(`python3 ${scriptPath} list --limit 10`, { stdio: 'inherit' });
|
|
234
118
|
} catch (e) {
|
|
235
|
-
console.log('\x1b[
|
|
119
|
+
console.log('\n\x1b[31m❌ Không thể đọc memory. Đã build brain chưa?\x1b[0m');
|
|
236
120
|
}
|
|
237
|
-
|
|
238
|
-
// 4. Check Telegram Token (if in .env)
|
|
239
|
-
if (fs.existsSync(envPath)) {
|
|
240
|
-
const content = fs.readFileSync(envPath, 'utf-8');
|
|
241
|
-
if (content.includes('TELEGRAM_BOT_TOKEN') && !content.includes('YOUR_TOKEN_HERE')) {
|
|
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
|
-
}
|
|
246
|
-
}
|
|
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
121
|
});
|
|
250
122
|
|
|
251
123
|
program.command('status')
|
|
252
|
-
.description('
|
|
124
|
+
.description('Xem trạng thái cài đặt')
|
|
253
125
|
.action(() => {
|
|
254
|
-
console.log('\x1b[36m📊 Trạng thái AG-Kit
|
|
126
|
+
console.log('\x1b[36m📊 Trạng thái AG-Kit:\x1b[0m');
|
|
255
127
|
if (fs.existsSync(TARGET_AGENT_DIR)) {
|
|
256
128
|
console.log('\x1b[32m✅ Trạng thái : Đã Cài Đặt (Active)\x1b[0m');
|
|
257
|
-
console.log(`📁 Đường dẫn : ${TARGET_AGENT_DIR}`);
|
|
258
129
|
|
|
259
130
|
const vPath = path.join(TARGET_AGENT_DIR, '.version');
|
|
260
131
|
let installedVersion = '0.0.0';
|
|
261
132
|
if (fs.existsSync(vPath)) {
|
|
262
133
|
installedVersion = fs.readFileSync(vPath, 'utf-8').trim();
|
|
263
134
|
console.log(`🧠 Bản cài đặt : v${installedVersion}`);
|
|
264
|
-
} else {
|
|
265
|
-
console.log(`🧠 Bản cài đặt : Không rõ (Legacy)`);
|
|
266
135
|
}
|
|
267
|
-
|
|
268
|
-
console.log(`🏷 Bản Tool : v${pkg.version}`);
|
|
269
136
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
console.log(
|
|
137
|
+
const brainPath = path.join(TARGET_AGENT_DIR, 'brain', 'summary.md');
|
|
138
|
+
if (fs.existsSync(brainPath)) {
|
|
139
|
+
console.log(`📚 Nhận thức : Đã có não (summary.md)`);
|
|
140
|
+
} else {
|
|
141
|
+
console.log(`📚 Nhận thức : \x1b[33mChưa có não. Gõ "ag-kit brain" để tạo.\x1b[0m`);
|
|
273
142
|
}
|
|
274
143
|
|
|
275
144
|
} 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}`);
|
|
145
|
+
console.log('\x1b[31m❌ Trạng thái : Dự án Trắng.\x1b[0m');
|
|
279
146
|
}
|
|
280
147
|
});
|
|
281
148
|
|
|
@@ -283,38 +150,49 @@ program.command('status')
|
|
|
283
150
|
async function runInteractiveMenu() {
|
|
284
151
|
const inquirer = require('inquirer');
|
|
285
152
|
console.clear();
|
|
286
|
-
console.log('\x1b[35m\n🧠
|
|
153
|
+
console.log('\x1b[35m\n🧠 AG-KIT - BẢNG ĐIỀU KHIỂN HỆ SINH THÁI AI\x1b[0m');
|
|
287
154
|
console.log('\x1b[34m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\x1b[0m');
|
|
288
155
|
|
|
156
|
+
const hasAgent = fs.existsSync(TARGET_AGENT_DIR);
|
|
157
|
+
const vPath = path.join(TARGET_AGENT_DIR, '.version');
|
|
158
|
+
let updateTag = '';
|
|
159
|
+
if (hasAgent && fs.existsSync(vPath)) {
|
|
160
|
+
const installed = fs.readFileSync(vPath, 'utf-8').trim();
|
|
161
|
+
if (installed !== pkg.version) {
|
|
162
|
+
updateTag = `\x1b[31m(Có bản mới: v${pkg.version})\x1b[0m `;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const choices = hasAgent ? [
|
|
167
|
+
{ name: `🧠 Xây dựng / Cập nhật Bộ Não (build brain) - Thu thập Context`, value: 'brain' },
|
|
168
|
+
{ name: `🕸️ Khám phá Ký ức (memory) - Xem dữ liệu Vector`, value: 'memory' },
|
|
169
|
+
{ name: `🔄 Nâng cấp Kiến thức (update) ${updateTag}`, value: 'update' },
|
|
170
|
+
{ name: '📊 Trạng thái (status) - Xem version & độ nhận thức', value: 'status' },
|
|
171
|
+
new inquirer.Separator(),
|
|
172
|
+
{ name: '❌ Thoát', value: 'exit' }
|
|
173
|
+
] : [
|
|
174
|
+
{ name: '🚀 Khởi tạo (init) - Cấy ghép Tủy Não .agent vào thư mục này', value: 'init' },
|
|
175
|
+
new inquirer.Separator(),
|
|
176
|
+
{ name: '❌ Thoát', value: 'exit' }
|
|
177
|
+
];
|
|
178
|
+
|
|
289
179
|
const { action } = await inquirer.prompt([
|
|
290
180
|
{
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
{ name: '🚀 Khởi tạo (init) - Cài đặt .agent', value: 'init' },
|
|
296
|
-
{ name: '🔄 Cập nhật (update) - Nâng cấp bộ não', value: 'update' },
|
|
297
|
-
{ name: '🔍 Kiểm tra (check) - Test môi trường', value: 'check' },
|
|
298
|
-
{ name: '📊 Trạng thái (status) - Xem version', value: 'status' },
|
|
299
|
-
new inquirer.Separator(),
|
|
300
|
-
{ name: '❌ Thoát', value: 'exit' }
|
|
301
|
-
]
|
|
181
|
+
type: 'list',
|
|
182
|
+
name: 'action',
|
|
183
|
+
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:',
|
|
184
|
+
choices: choices
|
|
302
185
|
}
|
|
303
186
|
]);
|
|
304
187
|
|
|
305
188
|
if (action === 'exit') {
|
|
306
|
-
console.log('\x1b[36m👋 Tạm biệt
|
|
189
|
+
console.log('\x1b[36m👋 Tạm biệt!\x1b[0m\n');
|
|
307
190
|
process.exit(0);
|
|
308
191
|
}
|
|
309
192
|
|
|
310
|
-
|
|
311
|
-
console.log('\n\x1b[34m--- ĐANG THỰC THI ---\x1b[0m');
|
|
312
|
-
|
|
313
|
-
// Chúng ta parse lại command với action đã chọn
|
|
314
|
-
// Lưu ý: commander parse() trả về promise với parseAsync
|
|
193
|
+
console.log('\n\x1b[34m--- ĐANG THỰC THI ---\x1b[0m\n');
|
|
315
194
|
await program.parseAsync([process.argv[0], process.argv[1], action]);
|
|
316
|
-
|
|
317
|
-
console.log('\n\x1b[34m--- HOÀN TẤT TÁC VỤ ---\x1b[0m');
|
|
195
|
+
console.log('\n\x1b[34m--- HOÀN TẤT ---\x1b[0m\n');
|
|
318
196
|
|
|
319
197
|
const { resume } = await inquirer.prompt([
|
|
320
198
|
{
|
|
@@ -329,7 +207,7 @@ async function runInteractiveMenu() {
|
|
|
329
207
|
|
|
330
208
|
if (process.argv.length <= 2) {
|
|
331
209
|
runInteractiveMenu().catch(err => {
|
|
332
|
-
console.error('\x1b[31m❌ Lỗi
|
|
210
|
+
console.error('\x1b[31m❌ Lỗi:\x1b[0m', err);
|
|
333
211
|
process.exit(1);
|
|
334
212
|
});
|
|
335
213
|
} else {
|
package/package.json
CHANGED