Lệnh cho trợ lý AI
⭐ Unique value section — không-có-ở-đâu-khác.
Nếu bạn dùng AI coding assistant (Claude Code, Cursor, Aider, etc.), copy-paste prompts dưới để agent autonomous execute setup từ guide này.
Lệnh 1: Cài đặt ban đầu (phía PC)
Phần tiêu đề “Lệnh 1: Cài đặt ban đầu (phía PC)”Copy prompt này vào agent đầu tiên trên PC:
Anh muốn setup Syncthing P2P sync với 1 máy laptop khác trong cùng LAN.
Đọc tutorial: https://syncthing.aiws.vn/quick-start/
Em execute autonomous trên máy này:
1. Cài Syncthing qua winget (Windows) hoặc apt (WSL nếu sync WSL folders)2. Generate config + keys3. Start daemon background4. Lấy Device ID của máy này5. Add 2 folders sync với ignore patterns sau: - `~/.claude/` (folder ID: claude-state) — ignore session-env, shell-snapshots, file-history, backups - `D:/Public LAN Folder/` (folder ID: code-public-lan) — ignore node_modules, dist, build, .next
Khi xong, output cho anh:- Device ID- Web UI URL- Tóm tắt sync folders đã add
Skip step pair với laptop — anh sẽ làm sau từ laptop side.
Lưu ý:- KHÔNG run as Admin trừ khi cần symlink- Show recoverable info trước khi propose destructive actions (rm, kill processes)- Verify mỗi step pass trước khi nextLệnh 2: Pair laptop với PC
Phần tiêu đề “Lệnh 2: Pair laptop với PC”Copy prompt này vào agent trên laptop:
PC đã setup Syncthing với Device ID: <PC_DEVICE_ID_HERE>
Em execute trên laptop này:
1. Cài Syncthing2. Generate config + start daemon3. Add PC làm remote device (paste PC Device ID)4. Wait laptop notification → accept folders PC offer: - claude-state → C:\Users\<user>\.claude - code-public-lan → D:\Public LAN Folder5. Verify connection (Web UI → Remote Devices: PC = Connected)6. Output sync progress (% done, files left)
Lưu ý:- Laptop có thể có ~/.claude/ cũ → backup trước (cp -r ~/.claude ~/.claude.bak-<timestamp>)- Move existing folders: `~/.claude/projects` → `~/.claude/projects.local-bak` để sync overwriteLệnh 3: Đồng bộ WSL gốc (nâng cao)
Phần tiêu đề “Lệnh 3: Đồng bộ WSL gốc (nâng cao)”Nếu cần sync folders trong WSL Ubuntu:
Anh muốn setup Syncthing native trong WSL Ubuntu để sync ~/projects/ với laptop's WSL.
Đọc: https://syncthing.aiws.vn/setup/wsl/
Em execute:
1. Edit C:\Users\<user>\.wslconfig: ``` [wsl2] networkingMode=mirrored firewall=true dnsTunneling=true autoProxy=true
[experimental] hostAddressLoopback=true ```2. Hỏi anh confirm trước khi `wsl --shutdown` (sẽ stop containers)3. Cài Syncthing trong WSL: `sudo apt install -y syncthing`4. Generate config với home dir riêng: `~/.config/syncthing-wsl/`5. Change ports tránh conflict Windows Syncthing: - GUI: 8384 → 8385 - BEP: 22000 → 22001 - Discovery: 21027 → 210286. Start daemon background với nohup7. Add folder `wsl-projects` → /home/<user>/projects với ignore patterns: ``` **/node_modules **/dist **/build **/.next **/.venv **/__pycache__ **/data **/postgres-data **/*.log **/.cache ```8. Output WSL Device ID
Skip pair với laptop — anh setup laptop sau.
Memory: nếu user dùng n8n hoặc services trong WSL với restart=unless-stopped, tự restart sau wsl shutdown ~30-60s.Memory rule: hành vi xuyên session
Phần tiêu đề “Memory rule: hành vi xuyên session”Save vào ~/.claude/projects/<slug>/memory/reference_syncthing_setup.md:
---name: Syncthing P2P sync setup giữa PC + Laptopdescription: 2 máy sync code, conversations, configs qua Syncthing. PC = primary host, Laptop mobile.type: reference---
User dùng 2 máy:- PC desktop (always-on, LAN cáp)- Laptop (mobile, wifi)
Sync architecture:
| Component | PC | Laptop ||---|---|---|| Windows Syncthing :8384 | ✅ | ✅ || WSL Syncthing :8385 (nếu có WSL) | ✅ | ✅ || WSL networking | mirrored | mirrored |
Folders sync:- claude-state (~/.claude/)- code-public-lan (D:/Public LAN Folder/)- wsl-projects (~/projects/ inside WSL, native)
Rules cho agent:- KHÔNG cần re-config Syncthing khi user đã setup- Switch máy: đóng app trước, đợi 30s, mở máy kia- Conflict: review *.sync-conflict-* files manually- WSL workflows native fast, KHÔNG access via \\wsl.localhost\- File watcher reliable trên native pathsMemory rule: gotchas riêng của WSL
Phần tiêu đề “Memory rule: gotchas riêng của WSL”---name: WSL filesystem performance gotchasdescription: Native WSL ext4 vs Windows 9P bridge. Always use native paths in WSL.type: feedback---
Khi work với files trong WSL:
✅ Trong WSL: dùng native paths - /home/<user>/projects/ (ext4 native)
❌ Trong Windows process: KHÔNG access WSL filesystem qua 9P bridge - \\wsl.localhost\Ubuntu\home\<user>\projects/ ← chậm 100x! - Examples to avoid: Windows Syncthing read \\wsl.localhost\, Windows VSCode edit files via cross-OS path
Why:- 9P protocol = round-trip Windows → WSL VM → ext4 → response cho mỗi file syscall- Many small files (vd .git/objects/) = many round-trips = unbearable- Real measurement: 33 MB/min cross-OS vs 3952 MB/min native = 120x slower
Solutions:- Run process IN WSL (use native paths)- Mirrored networking → process can communicate cross network OK- Or: move files to Windows NTFS if must access from Windows (but DrvFs from WSL slow too)Lệnh khi gặp lỗi
Phần tiêu đề “Lệnh khi gặp lỗi”Sync đang chậm bất thường. Diagnose dùm em.
Steps em check:1. Folder path có phải native filesystem? (Windows path trên Windows Syncthing, /home/x trên WSL Syncthing — KHÔNG cross-OS)2. Ignore patterns có cover node_modules, .cache, .git/objects/pack?3. CPU usage của Syncthing process — bị bottleneck hash?4. Network: ss -tlnp | grep 22000 — listen OK?5. Connection state: Web UI → Remote Devices → Connected?6. Out of Sync items count — file watcher detect đầy đủ?
Show em output từng step. Nếu issue ở 9P bridge → recommend cài Syncthinginside WSL native (xem https://syncthing.aiws.vn/setup/wsl/).Lệnh: xử lý lỗi WSL networking
Phần tiêu đề “Lệnh: xử lý lỗi WSL networking”WSL Syncthing 2 máy không pair được. WSL VM IP của em là 172.x (NAT) hay 192.168.x (mirrored)?
Run: `ip addr show eth0 | grep "inet "`
Nếu 172.x → mirrored mode chưa active. Em check:1. C:\Users\<user>\.wslconfig có "networkingMode=mirrored" không?2. Đã `wsl --shutdown` sau edit config?3. Restart shell + verify lại `hostname -I`
Mirrored mode cần Windows 11 22H2+ để hoạt động. Check Windows version:`cmd.exe /c ver`Mẹo chung cho AI agent
Phần tiêu đề “Mẹo chung cho AI agent”Bước tiếp theo
Phần tiêu đề “Bước tiếp theo”- Common issues — fix khi pair fail / sync stop
- Performance — optimize slow sync
- Architecture — deep dive design choices