@dtd-dev/agent-kb 0.1.1 → 0.1.2
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 -13
- package/bin/cli.js +27 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -88,20 +88,39 @@ tiêu đề đã điền tên feature — khỏi copy thư mục `feature-a/` (v
|
|
|
88
88
|
- `.ai/core/*` là Tier 1 (luôn load, giữ nhỏ). Mọi thứ khác load theo task qua router trong `AGENTS.md`.
|
|
89
89
|
- Không nhân bản rule sang nhiều file → tránh lệch và tốn token.
|
|
90
90
|
|
|
91
|
-
##
|
|
92
|
-
1. `name` trong `package.json` đã đặt là `@dtd-dev/agent-kb` (đổi scope nếu cần).
|
|
93
|
-
2. `npm login`
|
|
94
|
-
3. `npm publish --access public`
|
|
95
|
-
Sau đó cả team dùng: `npx @dtd-dev/agent-kb`.
|
|
91
|
+
## Bản đồ file: cái nào core, cái nào cá nhân hoá, cái nào nhờ AI điền
|
|
96
92
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
93
|
+
Sau khi `init`, mỗi file rơi vào **một** trong 3 nhóm. Cột "Ai điền" cho biết bạn phải tự làm hay nhờ AI/CLI:
|
|
94
|
+
|
|
95
|
+
| File / Thư mục | Nhóm | Ai điền | Ghi chú |
|
|
96
|
+
|---|---|---|---|
|
|
97
|
+
| `AGENTS.md` (router + quy tắc), `CLAUDE.md`/`GEMINI.md`/`copilot-instructions.md` | 🟦 **Core** | CLI | Khung dùng lại mọi dự án. Phần trong block `BEGIN/END agent-kb` do CLI quản — đừng sửa tay (chạy lại `init` sẽ ghi đè block). |
|
|
98
|
+
| `.ai/README.md` (index Tier 0) | 🟦 **Core** | — | Bản đồ "task → file". Giữ nguyên. |
|
|
99
|
+
| `.ai/workflows/*` (create-feature, fix-bug, code-review, release, learn, incident-response) | 🟦 **Core** | — | Phương pháp luận, dùng lại như nhau giữa các dự án. |
|
|
100
|
+
| `.ai/agents/*` (reviewer, tester, bug-fixer, feature-builder) | 🟦 **Core** | — | Nguồn chân lý của sub-agent; CLI tự emit sang `.claude/agents/`. |
|
|
101
|
+
| `.ai/core/tech-stack.md` | 🟩 **AI điền** | CLI + AI | CLI điền `{{...}}` từ nhận diện stack; AI bổ sung các chỗ `<!-- vd: ... -->` (cache, state, UI lib…) sau khi đọc code. |
|
|
102
|
+
| `.ai/core/coding-standards.md`, `.ai/core/glossary.md` | 🟩 **AI điền** | AI | Nhờ AI đọc codebase rồi viết. |
|
|
103
|
+
| `.ai/architecture.md` | 🟩 **AI điền** | AI | AI suy ra từ cấu trúc dự án. |
|
|
104
|
+
| `.ai/examples/*` | 🟩 **AI điền** | AI | Sinh từ code thật của bạn (thay ví dụ mẫu). |
|
|
105
|
+
| `.ai/skills/devops/*` (deployment, docker, github-actions), `.ai/skills/frontend/react.md`, `ui-guideline.md` | 🟩 **AI điền** | AI | Skill generic — AI viết theo stack thực tế. `deployment.md` có `{{DEPLOY_CMD}}` do CLI điền. |
|
|
106
|
+
| `.ai/memory/*` (common-bugs, lessons-learned, troubleshooting) | 🟩 **AI điền** | AI (dần dần) | Tích luỹ qua workflow `learn.md` mỗi khi rút kinh nghiệm. |
|
|
107
|
+
| `.ai/product/*` (vision, business-rules, domain-model) | 🟥 **Cá nhân hoá** | Người (+AI hỗ trợ) | **Nội dung shipped là MẪU CarePay** — bắt buộc thay bằng nghiệp vụ công ty bạn. Giữ cách đánh số (BR-001…). |
|
|
108
|
+
| `.ai/skills/backend/carepay-*`, `.ai/skills/frontend/carepay-firebase.md` | 🟥 **Cá nhân hoá** | Người | Skill nghiệp vụ mẫu — xoá hoặc thay bằng skill dự án bạn. |
|
|
109
|
+
| `.ai/decisions/ADR-00x-*` | 🟥 **Cá nhân hoá** | Người | Mẫu — thay bằng quyết định thật; tạo mới: `agent-kb adr <tiêu đề>`. |
|
|
110
|
+
| `.ai/specs/feature-a/*` | 🟥 **Cá nhân hoá** | Người | Spec mẫu — tạo spec thật: `agent-kb feature <tên>`. |
|
|
111
|
+
|
|
112
|
+
> 🟦 **Core** = giữ nguyên, dùng lại mọi dự án. 🟩 **AI điền** = nhờ AI đọc code rồi viết. 🟥 **Cá nhân hoá** = nội dung nghiệp vụ riêng, bạn (hoặc AI có ngữ cảnh công ty) phải thay.
|
|
113
|
+
|
|
114
|
+
### AI đọc file nào mỗi lần chạy?
|
|
115
|
+
- **Luôn (mọi session)**: `CLAUDE.md` → import `AGENTS.md` (router + Tier 1). Tier 1 = `.ai/core/tech-stack.md` + `coding-standards.md` + `glossary.md`. Giữ 3 file này thật ngắn (< ~500 token/file) vì đây là phần tốn token cố định.
|
|
116
|
+
- **Theo task (Tier 2, on-demand)**: AI tra bảng router trong `AGENTS.md` / `.ai/README.md` rồi chỉ mở file khớp task — vd fix bug → `workflows/fix-bug.md` + `memory/common-bugs.md`; hiểu nghiệp vụ → `product/business-rules.md` + `product/domain-model.md`. **Không** nuốt cả `.ai/`.
|
|
102
117
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
118
|
+
Gợi ý onboard dự án mới: điền 🟩 (nhờ AI) trước → thay 🟥 (nghiệp vụ) → chạy `agent-kb doctor` để chốt.
|
|
119
|
+
|
|
120
|
+
**Prompt 1-câu để Agent tự điền các file 🟩** (dán vào Claude Code/Cursor… ở thư mục gốc dự án):
|
|
121
|
+
|
|
122
|
+
```
|
|
123
|
+
Đọc codebase của dự án này rồi điền chính xác CHỈ các file nhóm 🟩 trong .ai/ (core/tech-stack.md ở các chỗ <!-- vd: ... -->, core/coding-standards.md, core/glossary.md, architecture.md, examples/*, skills/devops/* và skills/frontend/react.md + ui-guideline.md) bằng dữ kiện có thật trong code — giữ mỗi file core/* dưới ~500 token, KHÔNG đụng file 🟥 nghiệp vụ (product/*, skills/backend/carepay-*, carepay-firebase, decisions/, specs/), KHÔNG sửa trong block BEGIN/END agent-kb — xong chạy `agent-kb doctor` và sửa tới khi sạch cảnh báo.
|
|
124
|
+
```
|
|
106
125
|
|
|
107
126
|
MIT
|
package/bin/cli.js
CHANGED
|
@@ -271,6 +271,8 @@ function availableStacks() {
|
|
|
271
271
|
}
|
|
272
272
|
|
|
273
273
|
// Emit sub-agent: copy .ai/agents/*.md (nguồn chân lý) -> .claude/agents/ cho Claude Code đọc.
|
|
274
|
+
// .claude/agents/ là bản emit PHÁI SINH — luôn ghi đè theo nguồn (không tôn trọng --force/skip),
|
|
275
|
+
// nếu không sửa .ai/agents/ rồi chạy lại init sẽ không đồng bộ.
|
|
274
276
|
function emitAgents(stats) {
|
|
275
277
|
const src = path.join(CWD, ".ai", "agents");
|
|
276
278
|
if (!fs.existsSync(src)) return 0;
|
|
@@ -278,7 +280,17 @@ function emitAgents(stats) {
|
|
|
278
280
|
let n = 0;
|
|
279
281
|
for (const f of fs.readdirSync(src)) {
|
|
280
282
|
if (!f.endsWith(".md")) continue;
|
|
281
|
-
|
|
283
|
+
const to = path.join(dest, f);
|
|
284
|
+
const rel = path.relative(CWD, to);
|
|
285
|
+
const content = fs.readFileSync(path.join(src, f), "utf8");
|
|
286
|
+
const existed = fs.existsSync(to);
|
|
287
|
+
if (existed && fs.readFileSync(to, "utf8") === content) {
|
|
288
|
+
n++;
|
|
289
|
+
continue; // đã trùng nguồn → không ghi, không báo
|
|
290
|
+
}
|
|
291
|
+
fs.mkdirSync(dest, { recursive: true });
|
|
292
|
+
fs.writeFileSync(to, content);
|
|
293
|
+
(existed ? stats.synced : stats.written).push(rel);
|
|
282
294
|
n++;
|
|
283
295
|
}
|
|
284
296
|
return n;
|
|
@@ -335,7 +347,7 @@ async function init() {
|
|
|
335
347
|
rl.close();
|
|
336
348
|
}
|
|
337
349
|
|
|
338
|
-
const stats = { written: [], skipped: [], merged: [] };
|
|
350
|
+
const stats = { written: [], skipped: [], merged: [], synced: [] };
|
|
339
351
|
for (const [from, to] of MAP) {
|
|
340
352
|
copyRecursive(path.join(TEMPLATE_DIR, from), path.join(CWD, to), stats);
|
|
341
353
|
}
|
|
@@ -365,7 +377,10 @@ async function init() {
|
|
|
365
377
|
}
|
|
366
378
|
if (tools.length) console.log(`🔌 Tool đã bật: ${tools.join(", ")}`);
|
|
367
379
|
if (stacks.length) console.log(`📦 Gói stack: ${stacks.join(", ")} → .ai/skills/stacks/`);
|
|
368
|
-
if (agentsCount)
|
|
380
|
+
if (agentsCount) {
|
|
381
|
+
const note = stats.synced.length ? ` (${stats.synced.length} đồng bộ lại từ nguồn)` : "";
|
|
382
|
+
console.log(`🤖 Sub-agents: ${agentsCount} → .claude/agents/ (nguồn: .ai/agents/)${note}`);
|
|
383
|
+
}
|
|
369
384
|
if (stats.skipped.length) {
|
|
370
385
|
console.log(`↷ Bỏ qua ${stats.skipped.length} file đã tồn tại (dùng --force để ghi đè).`);
|
|
371
386
|
}
|
|
@@ -552,13 +567,19 @@ function doctor() {
|
|
|
552
567
|
if (fs.existsSync(path.join(CWD, dest))) oks.push(`${dest} (${t})`);
|
|
553
568
|
}
|
|
554
569
|
|
|
555
|
-
// Sub-agents: mỗi .ai/agents/*.md cần có bản emit ở .claude/agents/
|
|
570
|
+
// Sub-agents: mỗi .ai/agents/*.md cần có bản emit ở .claude/agents/ KHỚP nội dung nguồn.
|
|
556
571
|
const aiAgents = path.join(CWD, ".ai", "agents");
|
|
557
572
|
if (fs.existsSync(aiAgents)) {
|
|
558
573
|
for (const f of fs.readdirSync(aiAgents)) {
|
|
559
574
|
if (!f.endsWith(".md")) continue;
|
|
560
|
-
|
|
561
|
-
|
|
575
|
+
const emit = path.join(CWD, ".claude", "agents", f);
|
|
576
|
+
if (!fs.existsSync(emit)) {
|
|
577
|
+
warnings.push(`Agent .ai/agents/${f} chưa emit sang .claude/agents/ (chạy lại agent-kb init)`);
|
|
578
|
+
} else if (fs.readFileSync(path.join(aiAgents, f), "utf8") !== fs.readFileSync(emit, "utf8")) {
|
|
579
|
+
warnings.push(`.claude/agents/${f} lệch với nguồn .ai/agents/${f} (chạy lại agent-kb init để đồng bộ)`);
|
|
580
|
+
} else {
|
|
581
|
+
oks.push(`.claude/agents/${f}`);
|
|
582
|
+
}
|
|
562
583
|
}
|
|
563
584
|
}
|
|
564
585
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dtd-dev/agent-kb",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Bộ agent skill chuẩn hoá cho doanh nghiệp: scaffold knowledge base .ai/ tiết kiệm token, tăng độ chính xác khi viết code, và cá nhân hoá theo nghiệp vụ công ty để tái dùng cho nhiều dự án cùng nghiệp vụ (AGENTS.md, CLAUDE.md, GEMINI.md, Copilot).",
|
|
5
5
|
"bin": {
|
|
6
6
|
"agent-kb": "bin/cli.js"
|