Bỏ qua đến nội dung chính

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.

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 + keys
3. Start daemon background
4. Lấy Device ID của máy này
5. 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 next

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 Syncthing
2. Generate config + start daemon
3. 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 Folder
5. 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 overwrite

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\&lt;user&gt;\.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 → 21028
6. Start daemon background với nohup
7. Add folder `wsl-projects` → /home/&lt;user&gt;/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.

Save vào ~/.claude/projects/<slug>/memory/reference_syncthing_setup.md:

---
name: Syncthing P2P sync setup giữa PC + Laptop
description: 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 paths
---
name: WSL filesystem performance gotchas
description: 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/&lt;user&gt;/projects/ (ext4 native)
❌ Trong Windows process: KHÔNG access WSL filesystem qua 9P bridge
- \\wsl.localhost\Ubuntu\home\&lt;user&gt;\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)
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 Syncthing
inside WSL native (xem https://syncthing.aiws.vn/setup/wsl/).
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\&lt;user&gt;\.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`