@mrtrinhvn/ag-kit 1.0.2 → 1.0.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/bin/cli.js CHANGED
@@ -24,10 +24,11 @@ function copyRecursiveSync(src, dest) {
24
24
  }
25
25
  }
26
26
 
27
+ const pkg = require('../package.json');
27
28
  program
28
29
  .name('ag-kit')
29
30
  .description('Trí khôn Lập trình Phổ quát - AI Agent Initialization Framework')
30
- .version('1.0.0');
31
+ .version(pkg.version);
31
32
 
32
33
  program.command('init')
33
34
  .description('Install .agent folder into your project')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mrtrinhvn/ag-kit",
3
- "version": "1.0.2",
3
+ "version": "1.0.5",
4
4
  "description": "Antigravity Kit Base Framework - Generic Agentic AI Programming Core",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -0,0 +1,48 @@
1
+ ---
2
+ name: cli-generator
3
+ description: Meta-skill enabling the Agent to automatically convert local software, repositories, or APIs into structured CLI tools using HKUDS/CLI-Anything.
4
+ ---
5
+
6
+ # CLI-Generator (Meta-Skill)
7
+
8
+ > 🔴 **CRITICAL**: This is a Meta-Skill. It gives you (the AI Agent) the ability to forge your own tools to solve complex constraints.
9
+
10
+ ## When to Use
11
+
12
+ Use this skill when:
13
+ - The user asks you to interact with a complex local GUI software (e.g., GIMP, OBS).
14
+ - You are working with a messy, undocumented local API or scripting repository that is too brittle to run manually via ad-hoc scripts.
15
+ - You need a dedicated CLI tool to perform repetitive tasks reliably, but none exists.
16
+
17
+ ## The Forging Process
18
+
19
+ When you decide you need a new CLI tool for a given `TARGET_DIR` (the source code of the application), follow exactly these steps:
20
+
21
+ ### 1. Install CLI-Anything (If not already installed)
22
+ Check if `cli-anything` is available in your PATH. If not, install it globally:
23
+ ```bash
24
+ pip install cli-anything
25
+ ```
26
+ *(If the package is not on PyPI, clone `https://github.com/HKUDS/CLI-Anything` and run `pip install -e .`)*
27
+
28
+ ### 2. Run the Generator Pipeline
29
+ Navigate to a neutral workspace or the target, and run the automated generation pipeline:
30
+ ```bash
31
+ cli-anything --source /absolute/path/to/TARGET_DIR
32
+ ```
33
+ *Note: This process analyzes the source code and generates the harness. It may take several minutes and uses the underlying LLM's API tokens.*
34
+
35
+ ### 3. Integrate the Forged Skill into `ag-kit`
36
+ The pipeline will generate a new Python package (e.g., `cli-anything-targetname`) and automatically produce a `SKILL.md` file within its package directory (usually `cli_anything/<software>/skills/SKILL.md`).
37
+ You MUST locate this generated `SKILL.md` and copy it into the user's `ag-kit` workspace:
38
+ ```bash
39
+ mkdir -p .agent/skills/<targetname-cli>
40
+ cp /path/to/generated/SKILL.md .agent/skills/<targetname-cli>/SKILL.md
41
+ ```
42
+
43
+ ### 4. Self-Update
44
+ Once the new `SKILL.md` is in place, you (or any other agent using this repository like GravityClaw / Openclaw) will instantly possess the knowledge to use the newly forged CLI tool. Proceed to solve the user's original objective using the new tool natively.
45
+
46
+ ## Anti-Patterns
47
+ - ❌ **Manual wrappers**: Do NOT try to manually write a CLI harness or wrappers if `cli-anything` can automate it perfectly.
48
+ - ❌ **Token waste**: Do NOT run the generator repeatedly on the same source code. Generate the CLI once, store the `SKILL.md`, and reuse the tool.
@@ -16,7 +16,7 @@ allowed-tools: Read, Write, Glob, Grep
16
16
 
17
17
  ### Mandatory Read Before Action
18
18
  Before interacting with any third-party API, database schema, or core system component, you **MUST** search the `.agent/knowledge/` directory for existing documentation.
19
- *Example: Before coding a DNSE WebSocket feature, read `.agent/knowledge/integrations/dnse_api.md` to get the exact channels and payload structures.*
19
+ *Example: Before coding a payment integration feature, read `.agent/knowledge/integrations/stripe_api.md` to get the exact webhooks and payload structures.*
20
20
 
21
21
  ### Mandatory Proactive Updates (Zero Prompting Rule)
22
22
  When you successfully:
@@ -60,7 +60,7 @@ When modifying a feature or fixing a bug, ask yourself:
60
60
  **PRINCIPLE:** Context should be scoped locally to reduce token bloat and prevent the AI from hallucinating across unrelated domains. Do not stuff all documentation into a monolithic global file.
61
61
 
62
62
  ### Sub-Directory Contexts
63
- When working within a specific module (e.g., `backend/app/services/` or `frontend/src/components/`), you should:
63
+ When working within a specific module (e.g., `packages/core/services/` or `apps/web/components/`), you should:
64
64
  1. **Check for Local Context:** Look for a `CONTEXT.md` or `README.md` file *within that specific directory* before starting work.
65
- 2. **Context Routing:** Leave pointers in central documentation (like `.agent/knowledge/architecture.md`) that route the AI to these deep local files. (e.g., `-> For trading engine logic, see backend/app/services/CONTEXT.md`).
65
+ 2. **Context Routing:** Leave pointers in central documentation (like `.agent/knowledge/architecture.md`) that route the AI to these deep local files. (e.g., `-> For payment processing logic, see packages/core/billing/CONTEXT.md`).
66
66
  3. **Local Updates:** When making fundamental changes to a localized component, create or update its local `CONTEXT.md` instead of polluting the global knowledge base. Keep local context files under 100 lines.
@@ -0,0 +1,107 @@
1
+ ---
2
+ name: memory-architecture
3
+ description: >
4
+ Hệ thống Bộ nhớ Đồ thị Đa Tầng (Multi-layered Graph Memory) cho Agent.
5
+ Hợp nhất giữa Progressive Disclosure (L1, L2, L3) và Temporal Knowledge Graph (Node-Edge).
6
+ ---
7
+
8
+ # Multi-layered Graph Memory Architecture
9
+
10
+ > 🔴 **CRITICAL RULE**: Trí nhớ của Agent không còn là Text phẳng. Nó là một **Đồ thị Tri thức Đa tầng (Graph)** cho phép "Zoom-out" nhìn toàn cảnh và "Zoom-in" đọc chi tiết lõi.
11
+
12
+ ---
13
+
14
+ ## 1. Nguyên tắc cốt lõi: 3 Tầng Ký ức (L1/L2/L3)
15
+
16
+ ```text
17
+ L1 (Zoom Out) → session_summary & Core_Nodes — "Toàn cảnh dự án, các khái niệm lõi"
18
+ L2 (Mid) → category-indexed & Edges — "Mạng lưới quan hệ, mạch sự kiện"
19
+ L3 (Zoom In) → detail_record & Solutions — "Chi tiết lỗi, code snippet gốc"
20
+ ```
21
+
22
+ ---
23
+
24
+ ## 2. Hình thái Dữ liệu cấp thấp (Node-Edge Graph)
25
+
26
+ Mọi dữ liệu trong tầng L1/L2/L3 đều được lưu dưới dạng Đồ thị (Graph):
27
+
28
+ ### A. NODES (Hạt nhân Kiến thức)
29
+ Các khái niệm định danh tĩnh. Vd: `[Node:DB_PORT] => 5432 (Energy: 100)`
30
+
31
+ ### B. EDGES / EPISODES (Mạch Câu chuyện)
32
+ Luồng sự kiện liên kết. Vd: `[Node:USER] --(muốn mở port)--> [Node:DB_PORT]`
33
+
34
+ ### Progressive Disclosure (Tiết kiệm Token):
35
+ Thay vì load toàn bộ Memory, hệ thống truy vấn tự động theo dạng Phóng to/Thu nhỏ:
36
+ 1. **Search (Zoom Out):** Chỉ lấy mỏ neo 1-2 Node lõi + Quan hệ (L1/L2) (Tốn rất ít token).
37
+ 2. **Details (Zoom In):** Nếu AI cần phân tích sâu 1 đoạn code phức tạp, gọi L3 (Token cao hơn nhưng cực kỳ chính xác).
38
+
39
+ ---
40
+
41
+ ## 3. Vòng đời Trí nhớ (Biocybernetic Lifecycle)
42
+
43
+ 1. **Temporal Decay (Phai mờ):** Mỗi Node và Edge có `Energy`. Bị hao hụt tự động mỗi 24h. L1 siêu bền, L3 hao nhanh.
44
+ 2. **Reinforcement (Củng cố):** Mỗi lần "bò" (traversal) qua Node, Energy phục hồi.
45
+ 3. **Consolidation (Ngủ):** Cứ đêm đến, AI gộp các mạch nhớ L3/L2 rườm rà thành 1 Node L1 khái quát siêu bền.
46
+ 4. **Forgetting (Quên lãng):** Node có `Energy < 0` HOẶC mồ côi (không ai gọi tới) sẽ BỊ XOÁ (Quét rác sinh học).
47
+
48
+ ---
49
+
50
+ ## 4. Bảng Phân loại Khối Lượng Ký ức
51
+
52
+ | Target / Kiểu Node | Tầng | Giải thích | Energy Khởi tạo | Mức độ Tự Phân Hủy (Decay) |
53
+ |---|---|---|---|---|
54
+ | `session_summary` | L1 | Toàn cảnh phiên làm việc | 100 | Lâu dài (Gần như không) |
55
+ | `Core_Fact` | L1 | Cấu hình, IP, Convention cốt lõi | 100 | Gần như không |
56
+ | `User_Pref` | L2 | Thói quen user | 80 | Cực chậm |
57
+ | `project_context` | L2 | Ngữ cảnh dự án hiện tại | 80 | Trung hạn (Cập nhật đổi version) |
58
+ | `Episode_Edge` | L2 | "Hôm qua đã làm gì" | 30 | Nhanh (Rất mau phai mờ) |
59
+ | `error_solution` | L3 | Bug log + Code fix cụ thể | 50 | Trung bình (Công nghệ đổi -> Xóa) |
60
+
61
+ ---
62
+
63
+ ## 5. Workflow Tương tác Trí Nhớ (Mô phỏng GraphRAG)
64
+
65
+ ### KHI BẮT ĐẦU task mới (Retrieve):
66
+ ```text
67
+ 1. Bắn 1 tia Vector Search thả mỏ neo vào Đồ thị (Tìm L1/L2).
68
+ 2. Khôi phục lại Mạch Câu Chuyện bằng cách "Bò" dọc theo Edges lân cận (BFS).
69
+ 3. Nếu cần code chính xác của 1 Bug, gọi lệnh lấy Detail (L3).
70
+ ```
71
+
72
+ ### KHI KẾT THÚC task (Commit):
73
+ ❌ **Sai:** Lưu text rác `memory_save("Fix xong bug X")` vào trong hư không.
74
+ ✅ **Đúng:**
75
+ ```text
76
+ 1. Khởi tạo Node mới: Node[Fix_CORS] = "Thiếu accept headers"
77
+ 2. Nối Mạch: Node[Env_Prod] --(gặp lỗi)=> Node[Fix_CORS]
78
+ 3. (Tùy chọn) Gắn thêm Detail record vào L3 nếu fix cực phức tạp cần giữ code snippet.
79
+ ```
80
+
81
+ ---
82
+
83
+ ## 6. Anti-Patterns Kịch Độc
84
+
85
+ ```text
86
+ ❌ Gọi L3 load toàn bộ chi tiết khi không cần thiết (Tràn token).
87
+ ❌ Cố gắng chèn 200 dòng code vào Tên của Node (Node chỉ giữ Context lõi, Code đẩy xuống L3).
88
+ ❌ Tạo Node rác không gán Edge quan hệ. (Garbage Collector sẽ chém thẳng tay).
89
+ ```
90
+
91
+ ---
92
+
93
+ ## 7. Giao thức Tự động Dịch chuyển Ký ức (Self-Migration Protocol)
94
+
95
+ > **Dành cho các AI Agent hoạt động trong dự án cũ (Legacy Projects) vừa được cập nhật `ag-kit` thông qua `npx`.**
96
+
97
+ Khi bạn (AI) nhận thức được mình đang ở trong một dự án đã có sẵn dữ liệu ký ức cũ (chứa trong các file `.jsonl` hoặc `memory.db` phẳng), bạn **CÓ TRÁCH NHIỆM TỰ ĐỘNG** thực hiện quá trình "Memory Migration" (Dịch chuyển Ký ức) mà không cần User yêu cầu, theo các bước sau:
98
+
99
+ 1. **Phát hiện:** Dùng lệnh đọc file hoặc MCP để quét nội dung các ký ức cũ trong thư mục `data/memories/` (nếu có).
100
+ 2. **Băm nhỏ (Chunking & Entity Extraction):** Phân tích các đoạn log cũ xem chúng nói về chủ đề gì (vd: Lịch sử fix bug, Convention code cũ, Sở thích User).
101
+ 3. **Tái cấu trúc (Graph Construction):**
102
+ - Từ các đoạn text đó, rút trích ra các `Nodes` cốt lõi mang tính sự thật (Core Facts).
103
+ - Thiết lập các `Edges` (Mạch kết nối) mô tả luồng logic giữa các Nodes đó.
104
+ 4. **Lưu trữ (Commit):** Lưu bộ Graph vừa tạo vào cơ sở dữ liệu mới (thông qua `GraphMemoryTool` nếu dự án đã hỗ trợ, hoặc lưu ngược lại bằng `memory_save` dưới cấu trúc **Pseudo-Graph** cực đoan: `[Node:A] --[rel]--> [Node:B]` nếu nền tảng chưa được nâng cấp DB SQLite).
105
+
106
+ Bằng giao thức này, kiến thức của dự án sẽ KHÔNG BAO GIỜ bị đứt gãy sau khi cập nhật kiến trúc. Mọi ký ức quá khứ sẽ tự động "tiến hóa" thành dạng Đồ thị tương lai!
107
+
@@ -114,7 +114,7 @@ When executing long chains of tool calls (especially when searching, indexing, o
114
114
 
115
115
  ❌ **Random changes** - "Maybe if I change this..."
116
116
  ❌ **Ignoring evidence** - "That can't be the cause"
117
- ❌ **Assuming Data/API is dead** - Concluding an API endpoint is removed or data is unavailable just because a simple test failed (e.g., testing outside trading hours). ALWAYS check official documentation or sample SDK code before declaring an API dead.
117
+ ❌ **Assuming Data/API is dead** - Concluding an API endpoint is removed or data is unavailable just because a simple test failed (e.g., testing outside of service hours or without proper auth). ALWAYS check official documentation or sample SDK code before declaring an API dead.
118
118
  ❌ **Assuming** - "It must be X" without proof
119
119
  ❌ **Not reproducing first** - Fixing blindly
120
120
  ❌ **Stopping at symptoms** - Not finding root cause