clew-code 0.2.21 → 0.2.23
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 +45 -45
- package/dist/main.js +2906 -2722
- package/docs/architecture.html +91 -148
- package/docs/assets/clew-agent-loop.png +0 -0
- package/docs/assets/clew-general-architecture.png +0 -0
- package/docs/assets/clew-mcp-architecture.png +0 -0
- package/docs/assets/clew-p2p-swarm.png +0 -0
- package/docs/changelog.html +150 -0
- package/docs/cli-reference.html +90 -0
- package/docs/commands.html +133 -241
- package/docs/configuration.html +85 -147
- package/docs/contributing.html +91 -0
- package/docs/css/styles.css +272 -152
- package/docs/daemon.html +62 -129
- package/docs/features/bridge-mode.html +61 -66
- package/docs/features/evals.html +57 -149
- package/docs/features/searxng-search.html +58 -118
- package/docs/features/sentry-setup.html +61 -124
- package/docs/index.html +185 -148
- package/docs/installation.html +77 -105
- package/docs/internals/growthbook-ab-testing.html +69 -91
- package/docs/internals/hidden-features.html +81 -143
- package/docs/js/main.js +29 -0
- package/docs/loop.html +69 -181
- package/docs/mcp.html +99 -247
- package/docs/models.html +63 -92
- package/docs/permission-model.html +86 -102
- package/docs/plugins.html +84 -102
- package/docs/providers.html +87 -127
- package/docs/quick-start.html +81 -93
- package/docs/research-memory.html +71 -102
- package/docs/security.html +71 -0
- package/docs/skills.html +67 -117
- package/docs/swarm.html +78 -236
- package/docs/tools.html +183 -171
- package/docs/troubleshooting.html +86 -106
- package/docs/voice-mode.html +79 -0
- package/package.json +1 -1
- package/docs/architecture.th.html +0 -79
- package/docs/clew-code-architecture.html +0 -1126
- package/docs/commands.th.html +0 -269
- package/docs/configuration.th.html +0 -108
- package/docs/daemon.th.html +0 -73
- package/docs/features/bridge-mode.th.html +0 -62
- package/docs/features/evals.th.html +0 -62
- package/docs/features/searxng-search.th.html +0 -67
- package/docs/features/sentry-setup.th.html +0 -69
- package/docs/features/swarm.html +0 -156
- package/docs/generated/providers.html +0 -625
- package/docs/generated/tools.html +0 -558
- package/docs/index.th.html +0 -292
- package/docs/installation.th.html +0 -105
- package/docs/internals/growthbook-ab-testing.th.html +0 -60
- package/docs/internals/hidden-features.th.html +0 -107
- package/docs/loop.th.html +0 -227
- package/docs/mcp.th.html +0 -207
- package/docs/models.th.html +0 -61
- package/docs/permission-model.th.html +0 -67
- package/docs/plugins.th.html +0 -79
- package/docs/prompts-and-features.html +0 -806
- package/docs/providers.th.html +0 -81
- package/docs/quick-start.th.html +0 -89
- package/docs/research-memory.th.html +0 -72
- package/docs/skills.th.html +0 -90
- package/docs/swarm.th.html +0 -280
- package/docs/tools.th.html +0 -84
- package/docs/troubleshooting.th.html +0 -85
package/docs/swarm.th.html
DELETED
|
@@ -1,280 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="th">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="UTF-8">
|
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
-
<title>ระบบ Peer — Clew</title>
|
|
7
|
-
<meta name="description" content="ระบบ peer-to-peer บน LAN — ค้นหา, ส่งข้อความ, มอบหมายงาน, และรันคำสั่งระยะไกลระหว่าง Clew instances">
|
|
8
|
-
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
9
|
-
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
10
|
-
<link href="https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600;700&family=Noto+Sans+Thai:wght@400;500;600;700&display=swap" rel="stylesheet">
|
|
11
|
-
<link rel="stylesheet" href="css/styles.css">
|
|
12
|
-
<link rel="icon" type="image/svg+xml" href="./assets/clew.svg">
|
|
13
|
-
</head>
|
|
14
|
-
<body>
|
|
15
|
-
<header class="header"></header>
|
|
16
|
-
<div class="app">
|
|
17
|
-
<aside class="sidebar" id="sidebar"></aside>
|
|
18
|
-
<div class="sidebar-overlay" id="sidebarOverlay"></div>
|
|
19
|
-
<div class="content-wrap">
|
|
20
|
-
<main class="content">
|
|
21
|
-
<div class="breadcrumbs"><a href="index.th.html">หน้าแรก</a><span class="sep">/</span><span>ระบบ Peer</span></div>
|
|
22
|
-
<h1>ระบบ Peer</h1>
|
|
23
|
-
<p class="section-subtitle">Peer-to-peer บน LAN — ค้นหา Clew instances อื่น, ส่งข้อความ, มอบหมายงาน, และรันคำสั่งระยะไกล</p>
|
|
24
|
-
|
|
25
|
-
<p>ระบบ peer อยู่ใน <code>src/peer/</code> และประกอบด้วย 3 ชั้นหลัก: <strong>PeerServer</strong> (HTTP server), <strong>PeerDiscovery</strong> (สแกน LAN), และ <strong>PeerStore</strong> (registry ในหน่วยความจำ)</p>
|
|
26
|
-
|
|
27
|
-
<h2>สถาปัตยกรรม</h2>
|
|
28
|
-
<pre><code> ┌─────────────────────────────────────────────────────────────────────────────┐
|
|
29
|
-
│ SWARM SYSTEM FLOW │
|
|
30
|
-
└─────────────────────────────────────────────────────────────────────────────┘
|
|
31
|
-
|
|
32
|
-
┌──────────────────────────┐
|
|
33
|
-
│ /swarm share │
|
|
34
|
-
│ (Machine A — Worker) │
|
|
35
|
-
└────────────┬─────────────┘
|
|
36
|
-
│
|
|
37
|
-
┌─────────────────┼─────────────────┐
|
|
38
|
-
▼ ▼ ▼
|
|
39
|
-
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
|
|
40
|
-
│ PeerServer │ │PeerDiscovery │ │ PeerStore │
|
|
41
|
-
│ HTTP :random │ │ │ │ (in-memory) │
|
|
42
|
-
│ port │ │ │ │ │
|
|
43
|
-
└──────┬───────┘ └──────┬───────┘ └──────────────┘
|
|
44
|
-
│ │
|
|
45
|
-
│ ┌────────────┼────────────┐
|
|
46
|
-
│ │ │ │
|
|
47
|
-
│ ▼ ▼ ▼
|
|
48
|
-
│ ┌────────┐ ┌────────┐ ┌─────────────┐
|
|
49
|
-
│ │ File │ │ UDP │ │ PeerStore │
|
|
50
|
-
│ │ ~/.cl/ │ │multicast│ │ (singleton) │
|
|
51
|
-
│ │ peers/ │ │239... │ │ │
|
|
52
|
-
│ │{pid}. │ │:42069 │ │ │
|
|
53
|
-
│ │ json │ │ │ │ │
|
|
54
|
-
│ └────┬───┘ └────┬───┘ └─────────────┘
|
|
55
|
-
│ │ │
|
|
56
|
-
│ │ │ heartbeat ทุก 30s
|
|
57
|
-
│ │ │ stale timeout 90s
|
|
58
|
-
│ │ │
|
|
59
|
-
▼ ▼ ▼
|
|
60
|
-
┌─────────────────────────────────────────────────────┐
|
|
61
|
-
│ LAN NETWORK │
|
|
62
|
-
│ │
|
|
63
|
-
│ ┌─────────┐ ┌─────────┐ │
|
|
64
|
-
│ │ Machine B│◄───────►│ Machine C│ ... │
|
|
65
|
-
│ │ Clew Code│ query │ Clew Code│ │
|
|
66
|
-
│ └────┬─────┘ └────┬─────┘ │
|
|
67
|
-
│ │ │ │
|
|
68
|
-
└────────┼────────────────────┼─────────────────────────┘
|
|
69
|
-
│ │
|
|
70
|
-
│ /swarm discover │ /swarm discover
|
|
71
|
-
▼ ▼
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
═══ WORKER (Machine A) ENDPOINTS ═══
|
|
75
|
-
|
|
76
|
-
Peer อื่น POST /peer-info ──► { hostname, ip, cwd, shell, ... }
|
|
77
|
-
│ POST /peer-msg ──► รับข้อความ chat
|
|
78
|
-
├───────────────► POST /peer-todo ──► รับ task (ไปอยู่ใน inbox)
|
|
79
|
-
│ POST /peer-exec ──► รัน shell command + คืน stdout/stderr
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
═══ CLIENT (Machine B) SWARM TOOLS ═══
|
|
83
|
-
|
|
84
|
-
/swarm discover ──► scan files + UDP query (3s timeout)
|
|
85
|
-
│
|
|
86
|
-
▼
|
|
87
|
-
[peer list]
|
|
88
|
-
│
|
|
89
|
-
┌───────────────────┼───────────────────┐
|
|
90
|
-
▼ ▼ ▼
|
|
91
|
-
/swarm join /swarm send_task /swarm run
|
|
92
|
-
(POST /peer-info) (POST /peer-todo) (POST /peer-exec)
|
|
93
|
-
|
|
94
|
-
│
|
|
95
|
-
▼
|
|
96
|
-
/swarm send_message ──► POST /peer-msg ──► inbox ปลายทาง
|
|
97
|
-
/swarm broadcast ──► POST /peer-msg ──► ทุก peer ที่เชื่อมต่อ
|
|
98
|
-
/swarm ping ──► GET /peer-info ──► เช็ค alive
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
═══ DAEMON (agentLoop.ts) ═══
|
|
102
|
-
|
|
103
|
-
┌───────────────────────────────────┐
|
|
104
|
-
│ Autonomous Agent Loop │
|
|
105
|
-
│ - ฟัง /peer-todo ตลอด 24/7 │
|
|
106
|
-
│ - รับ task จาก remote swarm nodes │
|
|
107
|
-
│ - execute ใน background worker │
|
|
108
|
-
│ - สูงสุด 3 workers พร้อมกัน │
|
|
109
|
-
└───────────────────────────────────┘
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
═══ DATA LIFECYCLE ═══
|
|
113
|
-
|
|
114
|
-
advertise ──► heartbeat ทุก 30s
|
|
115
|
-
│
|
|
116
|
-
├── 90s ไม่มี heartbeat ──► stale → evict
|
|
117
|
-
│
|
|
118
|
-
stop share ──► send UDP "offline"
|
|
119
|
-
delete peer file
|
|
120
|
-
close HTTP server</code></pre>
|
|
121
|
-
|
|
122
|
-
<h2>เทคนิคและหลักการ</h2>
|
|
123
|
-
|
|
124
|
-
<h3>Discovery แบบสองชั้น (Two-Layer Discovery)</h3>
|
|
125
|
-
<p>ทำไมไม่ใช้แค่ UDP multicast หรือแค่ file-based อย่างเดียว?</p>
|
|
126
|
-
<ul>
|
|
127
|
-
<li><strong>File-based</strong> — ทำงานบนเครื่องเดียวกันได้ทันที โดยไม่ต้องใช้ network เลย แค่อ่าน/เขียนไฟล์ JSON ใน <code>~/.clew/peers/</code> ซึ่งเร็วกว่าและไม่ต้องกังวลเรื่อง firewall</li>
|
|
128
|
-
<li><strong>UDP Multicast</strong> — ข้ามเครื่องได้ผ่าน LAN ใช้ multicast group <code>239.255.37.37:42069</code> ไม่ต้องรู้ IP ปลายทางล่วงหน้า</li>
|
|
129
|
-
<li><strong>ทำไมต้องทั้งสอง?</strong> — แต่ละวิธีมีข้อจำกัด: file-based ข้ามเครื่องไม่ได้, UDP multicast อาจถูกบล็อคด้วย network policy การใช้ทั้งสองวิธีทำให้ discovery ทำงานได้ในทุกสภาพแวดล้อม โดยไม่ต้องให้ผู้ใช้ configure อะไรเลย</li>
|
|
130
|
-
</ul>
|
|
131
|
-
|
|
132
|
-
<h3>Lease-based Task Claiming</h3>
|
|
133
|
-
<p>เมื่อมีหลาย worker (หรือหลาย daemon process) วิ่งพร้อมกัน จะป้องกันไม่ให้ task ถูกทำซ้ำได้อย่างไร?</p>
|
|
134
|
-
<ul>
|
|
135
|
-
<li><strong>Atomic lease</strong> — ก่อนเริ่ม task, worker ต้องขอ lease ด้วย <code>leaseTask(id, agentId)</code> ซึ่งเช็คว่า task ยังไม่มีใครจอง และเขียน lease owner + expiry timestamp ลงไฟล์แบบ atomic (read-modify-write ภายใต้ lock)</li>
|
|
136
|
-
<li><strong>Lease expiry</strong> — ถ้า worker crash หรือ disconnect, lease จะหมดอายุเอง (default 30 นาที) ทำให้ worker อื่นมารับงานต่อได้ — <em>crash recovery โดยไม่ต้องมี distributed coordinator</em></li>
|
|
137
|
-
<li><strong>Stale lease cleanup</strong> — ตอน startLoop จะรอ 2 วินาที แล้วเรียก <code>expireLeases()</code> เพื่อ clear lease เก่าจาก session ก่อนหน้า</li>
|
|
138
|
-
<li><strong>ทำไมไม่ใช้ lock file?</strong> — lock file แบบ OS-level (flock) ใช้ข้าม process บนเครื่องเดียวกันได้ แต่ใช้ข้ามเครื่องไม่ได้ Lease บนไฟล์ JSON แก้ปัญหานี้ได้โดยไม่ต้องพึ่ง external service อย่าง Redis/ZooKeeper</li>
|
|
139
|
-
</ul>
|
|
140
|
-
|
|
141
|
-
<h3>Heartbeat + Stale Eviction</h3>
|
|
142
|
-
<p>Peer discovery ต้องรู้ว่าใครยัง alive อยู่ โดยไม่ต้อง polling:</p>
|
|
143
|
-
<ul>
|
|
144
|
-
<li><strong>Push-based heartbeat</strong> — แต่ละ peer ส่ง beacon ทุก 30 วินาที ผ่านทั้ง file (เขียน timestamp ใหม่) และ UDP multicast</li>
|
|
145
|
-
<li><strong>Pull-based eviction</strong> — consumer เช็คอายุของ peer entry ถ้าเกิน 90 วินาที (<code>PEER_STALE_TIMEOUT</code>) ถือว่า stale → evict</li>
|
|
146
|
-
<li><strong>3× heartbeat interval</strong> — timeout = 3 × heartbeat interval เป็นค่า default ในระบบ distributed systems (ให้โอกาส retry ก่อน宣布ตาย)</li>
|
|
147
|
-
<li><strong>Graceful shutdown</strong> — ตอน <code>/swarm stop</code> จะส่ง UDP "offline" message + ลบไฟล์ peer ทันที ไม่ต้องรอ timeout</li>
|
|
148
|
-
</ul>
|
|
149
|
-
|
|
150
|
-
<h3>Random Port Binding</h3>
|
|
151
|
-
<p>PeerServer bind ที่ port 0 (OS เลือก port ว่างให้):</p>
|
|
152
|
-
<ul>
|
|
153
|
-
<li><strong>No port conflicts</strong> — ถ้าใช้ fixed port แล้วมีหลาย instance จะชนกัน</li>
|
|
154
|
-
<li><strong>Security through obscurity</strong> — port สุ่มทำให้ attacker สแกนหายากกว่า fixed port (แต่ไม่ใช่ security หลัก — security จริงอยู่ที่ authentication layer)</li>
|
|
155
|
-
<li><strong>Discovery solves discovery</strong> — ไม่ต้องรู้ port ล่วงหน้า เพราะ discovery protocol จะบอก port ให้เอง</li>
|
|
156
|
-
</ul>
|
|
157
|
-
|
|
158
|
-
<h3>Message Broadcasting</h3>
|
|
159
|
-
<p><code>peer_broadcast</code> ส่ง task ไปทุก peer ที่เชื่อมต่อพร้อมกัน:</p>
|
|
160
|
-
<ul>
|
|
161
|
-
<li>ไม่ใช่ UDP broadcast — ใช้ HTTP POST sequential ไปทีละ peer (fire-and-forget)</li>
|
|
162
|
-
<li>รองรับ parallel สูงสุด 8 peers ต่อ 1 batch</li>
|
|
163
|
-
<li>เหมาะสำหรับ: deploy to all machines, run tests everywhere, health check ทุก node</li>
|
|
164
|
-
</ul>
|
|
165
|
-
|
|
166
|
-
<h2>องค์ประกอบหลัก</h2>
|
|
167
|
-
|
|
168
|
-
<h3>PeerServer <code>src/peer/PeerServer.ts</code></h3>
|
|
169
|
-
<p>HTTP server ขนาดเล็กที่เริ่มบน port สุ่ม (OS เลือกให้) เมื่อรัน <code>/swarm share</code> แต่ละ endpoint รองรับการโต้ตอบแบบต่างๆ:</p>
|
|
170
|
-
<table>
|
|
171
|
-
<tr><th>Endpoint</th><th>Method</th><th>หน้าที่</th></tr>
|
|
172
|
-
<tr><td><code>/peer-info</code></td><td>GET</td><td>ส่งข้อมูล peer (hostname, IP, cwd, shell, platform)</td></tr>
|
|
173
|
-
<tr><td><code>/peer-msg</code></td><td>POST</td><td>รับข้อความ chat จาก peer อื่น</td></tr>
|
|
174
|
-
<tr><td><code>/peer-todo</code></td><td>POST</td><td>รับ task ที่ถูกมอบหมายจาก peer อื่น</td></tr>
|
|
175
|
-
<tr><td><code>/peer-exec</code></td><td>POST</td><td>รันคำสั่ง shell และส่งคืน stdout/stderr</td></tr>
|
|
176
|
-
</table>
|
|
177
|
-
|
|
178
|
-
<h3>PeerDiscovery <code>src/peer/PeerDiscovery.ts</code></h3>
|
|
179
|
-
<p>กลไกค้นหา 2 วิธีทำงานร่วมกัน:</p>
|
|
180
|
-
<ul>
|
|
181
|
-
<li><strong>File-based</strong> — แต่ละ instance เขียนไฟล์ <code>~/.clew/peers/{pid}.json</code> เก็บข้อมูล hostname, IP, port, shell, cwd instances อื่นอ่านไฟล์เพื่อค้นหา peer ในเครื่องเดียวกัน</li>
|
|
182
|
-
<li><strong>UDP Multicast</strong> — ส่ง heartbeat beacon ไปที่ <code>239.255.37.37:42069</code> ทุก 30 วินาที ตอบกลับ <code>clew-peer-query</code> ด้วย <code>clew-peer-info</code> ใช้ข้ามเครื่อง</li>
|
|
183
|
-
<li><strong>Stale eviction</strong> — Peer ที่ไม่เห็น 90 วินาที (<code>PEER_STALE_TIMEOUT</code>) จะถูกลบอัตโนมัติ</li>
|
|
184
|
-
</ul>
|
|
185
|
-
|
|
186
|
-
<h3>PeerStore <code>src/peer/PeerStore.ts</code></h3>
|
|
187
|
-
<p>Singleton registry ในหน่วยความจำที่เก็บ peer ทั้งหมดที่รู้จัก (ทั้งที่ค้นพบและที่ join เอง), ข้อความ chat, todos, และ custom tags (ชื่อที่กำหนดเอง, บทบาท)</p>
|
|
188
|
-
<ul>
|
|
189
|
-
<li><strong>Discovered peers</strong> — ถูกลบอัตโนมัติเมื่อ stale</li>
|
|
190
|
-
<li><strong>Joined connections</strong> — คงอยู่ถาวร ไม่ถูกลบอัตโนมัติ</li>
|
|
191
|
-
<li><strong>Tags</strong> — ชื่อที่กำหนดเองและบทบาทต่อ peer</li>
|
|
192
|
-
</ul>
|
|
193
|
-
|
|
194
|
-
<h2>Discovery Protocol</h2>
|
|
195
|
-
<pre><code>DiscoveryMessage =
|
|
196
|
-
| { type: "clew-peer-query", version: 1 } // broadcast scan
|
|
197
|
-
| { type: "clew-peer-info", version: 1, // heartbeat / response
|
|
198
|
-
id: string, hostname: string, ip: string, port: number,
|
|
199
|
-
cwd: string, sessionId?: string, appVersion: string,
|
|
200
|
-
shell?: string, platform?: string, term?: string,
|
|
201
|
-
status: "online" | "offline" }
|
|
202
|
-
|
|
203
|
-
UDP port: 42069
|
|
204
|
-
Multicast IP: 239.255.37.37
|
|
205
|
-
Heartbeat: ทุก 30 วินาที
|
|
206
|
-
Stale after: 90 วินาที</code></pre>
|
|
207
|
-
|
|
208
|
-
<h2>คำสั่ง</h2>
|
|
209
|
-
<table>
|
|
210
|
-
<tr><th>คำสั่ง</th><th>คำอธิบาย</th></tr>
|
|
211
|
-
<tr><td><code>/swarm</code></td><td>เปิดเมนู interactive (share, join, discover, inbox)</td></tr>
|
|
212
|
-
<tr><td><code>/swarm share</code></td><td>เริ่มประกาศ instance นี้เป็น worker บน LAN</td></tr>
|
|
213
|
-
<tr><td><code>/swarm stop</code></td><td>หยุดประกาศและปิด swarm server</td></tr>
|
|
214
|
-
<tr><td><code>/swarm discover</code></td><td>สแกนหา peers (file + UDP, timeout 3s)</td></tr>
|
|
215
|
-
<tr><td><code>/swarm join <host> <port></code></td><td>เชื่อมต่อกับ remote swarm node ด้วย host และ port</td></tr>
|
|
216
|
-
<tr><td><code>/swarm name <ชื่อ></code></td><td>กำหนดชื่อที่แสดงสำหรับตัวเอง</td></tr>
|
|
217
|
-
<tr><td><code>/swarm role <บทบาท></code></td><td>กำหนดบทบาท (builder, tester, deployer, ฯลฯ)</td></tr>
|
|
218
|
-
<tr><td><code>/swarm inbox</code></td><td>ดูข้อความและ todos ที่รออยู่จาก peers</td></tr>
|
|
219
|
-
<tr><td><code>/swarm disconnect <peer></code></td><td>ตัดการเชื่อมต่อจาก peer ที่ระบุ</td></tr>
|
|
220
|
-
<tr><td><code>/swarm todos</code></td><td>แสดงรายการ task ทั้งหมดที่ได้รับ</td></tr>
|
|
221
|
-
<tr><td><code>/swarm todo done <id></code></td><td>ทำเครื่องหมาย task ว่าเสร็จแล้ว</td></tr>
|
|
222
|
-
</table>
|
|
223
|
-
|
|
224
|
-
<h2>AI Tools</h2>
|
|
225
|
-
<p>เครื่องมือที่ AI agent ใช้เพื่อโต้ตอบกับระบบ peer:</p>
|
|
226
|
-
<table>
|
|
227
|
-
<tr><th>Tool</th><th>คำอธิบาย</th></tr>
|
|
228
|
-
<tr><td><code>peer_discover</code></td><td>สแกน LAN หา Clew workers</td></tr>
|
|
229
|
-
<tr><td><code>peer_join</code></td><td>เชื่อมต่อกับ remote swarm node ผ่าน HTTP</td></tr>
|
|
230
|
-
<tr><td><code>peer_ping</code></td><td>ตรวจสอบว่า peer ออนไลน์อยู่หรือไม่ (GET /peer-info)</td></tr>
|
|
231
|
-
<tr><td><code>peer_info</code></td><td>ดึงข้อมูล peer อย่างละเอียด</td></tr>
|
|
232
|
-
<tr><td><code>peer_send_message</code></td><td>ส่งข้อความ chat ไปที่ peer</td></tr>
|
|
233
|
-
<tr><td><code>peer_send_task</code></td><td>มอบหมาย task ให้ remote worker</td></tr>
|
|
234
|
-
<tr><td><code>peer_broadcast</code></td><td>ส่ง task ไปทุก peer ที่เชื่อมต่อพร้อมกัน</td></tr>
|
|
235
|
-
<tr><td><code>peer_run</code></td><td>รันคำสั่ง shell บน remote worker</td></tr>
|
|
236
|
-
<tr><td><code>peer_disconnect</code></td><td>ลบ peer ออกจากรายการเชื่อมต่อ</td></tr>
|
|
237
|
-
<tr><td><code>peer_list_messages</code></td><td>แสดงข้อความ chat ทั้งหมดที่ได้รับ</td></tr>
|
|
238
|
-
<tr><td><code>peer_list_roles</code></td><td>แสดงรายการ peers พร้อมบทบาท</td></tr>
|
|
239
|
-
<tr><td><code>peer_list_tasks</code></td><td>แสดง task ทั้งหมดและสถานะ</td></tr>
|
|
240
|
-
<tr><td><code>peer_set_name</code></td><td>กำหนดชื่อที่แสดงให้ peer</td></tr>
|
|
241
|
-
<tr><td><code>peer_set_role</code></td><td>กำหนดบทบาทให้ peer</td></tr>
|
|
242
|
-
<tr><td><code>peer_share</code></td><td>เปิด/ปิด/เช็คสถานะการแชร์</td></tr>
|
|
243
|
-
</table>
|
|
244
|
-
|
|
245
|
-
<h2>การเชื่อมต่อกับ DAEMON</h2>
|
|
246
|
-
<p>Autonomous agent loop (<code>src/services/autonomous/agentLoop.ts</code>) เชื่อมต่อกับ PeerServer เพื่อรับ task จาก remote swarm nodes:</p>
|
|
247
|
-
<ul>
|
|
248
|
-
<li>ฟัง <code>/peer-todo</code> POST ตลอด 24/7</li>
|
|
249
|
-
<li>จัดคิว task ที่ได้รับและประมวลผลใน background workers</li>
|
|
250
|
-
<li>สูงสุด 3 workers พร้อมกัน; task timeout หลัง 30 นาที</li>
|
|
251
|
-
<li>ดูผลลัพธ์ผ่าน <code>/swarm todos</code> และ <code>/tasks</code></li>
|
|
252
|
-
</ul>
|
|
253
|
-
|
|
254
|
-
<h2>ไฟล์ในระบบ</h2>
|
|
255
|
-
<table>
|
|
256
|
-
<tr><th>ไฟล์</th><th>หน้าที่</th></tr>
|
|
257
|
-
<tr><td><code>src/peer/PeerServer.ts</code></td><td>HTTP server พร้อม endpoint /peer-info, /peer-msg, /peer-todo, /peer-exec</td></tr>
|
|
258
|
-
<tr><td><code>src/peer/PeerDiscovery.ts</code></td><td>ค้นหา peer ผ่านไฟล์ + UDP multicast บน LAN</td></tr>
|
|
259
|
-
<tr><td><code>src/peer/PeerStore.ts</code></td><td>Singleton registry ใน memory (peers, messages, todos, tags)</td></tr>
|
|
260
|
-
<tr><td><code>src/peer/types.ts</code></td><td>Shared types และค่าคงที่ของ protocol</td></tr>
|
|
261
|
-
<tr><td><code>src/commands/swarm/</code></td><td>Interactive peer menu และ CLI commands</td></tr>
|
|
262
|
-
<tr><td><code>src/tools/Peer*Tool/</code></td><td>16 AI agent tools สำหรับ swarm operations</td></tr>
|
|
263
|
-
<tr><td><code>src/services/autonomous/agentLoop.ts</code></td><td>Daemon integration: รับ remote tasks ผ่าน PeerServer</td></tr>
|
|
264
|
-
</table>
|
|
265
|
-
|
|
266
|
-
<footer class="footer">
|
|
267
|
-
<span>Clew Code 0.2.14 — Open Source</span>
|
|
268
|
-
<div class="footer-links">
|
|
269
|
-
<a href="https://github.com/ClewCode/ClewCode">GitHub</a>
|
|
270
|
-
<a href="https://github.com/ClewCode/ClewCode/issues">Issues</a>
|
|
271
|
-
</div>
|
|
272
|
-
</footer>
|
|
273
|
-
</main>
|
|
274
|
-
<nav class="toc-sidebar"></nav>
|
|
275
|
-
</div>
|
|
276
|
-
</div>
|
|
277
|
-
<script src="js/main.js"></script>
|
|
278
|
-
</body>
|
|
279
|
-
</html>
|
|
280
|
-
|
package/docs/tools.th.html
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="th">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="UTF-8">
|
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
-
<title>เครื่องมือ — Clew</title>
|
|
7
|
-
<meta name="description" content="ข้อมูลอ้างอิงเครื่องมือในตัวของ Clew — การดำเนินการไฟล์, เชลล์, ค้นหา, เอเจนต์, MCP, และระบบอัตโนมัติ">
|
|
8
|
-
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
9
|
-
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
10
|
-
<link href="https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600;700&family=Noto+Sans+Thai:wght@400;500;600;700&display=swap" rel="stylesheet">
|
|
11
|
-
<link rel="stylesheet" href="css/styles.css">
|
|
12
|
-
<link rel="icon" type="image/svg+xml" href="./assets/clew.svg">
|
|
13
|
-
</head>
|
|
14
|
-
<body>
|
|
15
|
-
<header class="header"></header>
|
|
16
|
-
<div class="app"><aside class="sidebar" id="sidebar"></aside><div class="sidebar-overlay" id="sidebarOverlay"></div>
|
|
17
|
-
<div class="content-wrap"><main class="content">
|
|
18
|
-
<div class="breadcrumbs"><a href="index.th.html">หน้าแรก</a><span class="sep">/</span><span>เครื่องมือ</span></div>
|
|
19
|
-
<h1>เครื่องมือ</h1>
|
|
20
|
-
<p class="section-subtitle">Clew มีเครื่องมือในตัว 50+ รายการ พร้อมเครื่องมือ MCP ที่โหลดแบบไดนามิก เครื่องมือถูกเรียกโดยโมเดล AI ผ่านบล็อก <code>tool_use</code></p>
|
|
21
|
-
|
|
22
|
-
<h2>วิธีการทำงานของเครื่องมือ</h2>
|
|
23
|
-
<p>เครื่องมือถูกกำหนดด้วย Zod schemas ใน <code>src/Tool.ts</code> ผ่านตัวช่วย <code>buildTool()</code> และลงทะเบียนใน <code>src/tools.ts</code></p>
|
|
24
|
-
|
|
25
|
-
<pre><code>โมเดลส่ง tool_use
|
|
26
|
-
ปรับมาตรฐานการเรียกใช้เครื่องมือ (toolCallParser.ts)
|
|
27
|
-
ตรวจสอบสิทธิ์ (permissions.ts)
|
|
28
|
-
ฮุค PreToolUse (ปลั๊กอิน)
|
|
29
|
-
ดำเนินการเครื่องมือ (StreamingToolExecutor)
|
|
30
|
-
ฮุค PostToolUse (ปลั๊กอิน)
|
|
31
|
-
ส่งคืนผลลัพธ์เป็น tool_result
|
|
32
|
-
วนซ้ำคำถามต่อไป</code></pre>
|
|
33
|
-
|
|
34
|
-
<h2>การดำเนินการไฟล์และโค้ด</h2>
|
|
35
|
-
<table>
|
|
36
|
-
<tr><th>เครื่องมือ</th><th>คำอธิบาย</th></tr>
|
|
37
|
-
<tr><td><code>Read</code></td><td>อ่านไฟล์พร้อมหมายเลขบรรทัด, รองรับรูปภาพ, PDF, Jupyter notebooks</td></tr>
|
|
38
|
-
<tr><td><code>Write</code></td><td>สร้างไฟล์ใหม่พร้อมเนื้อหาเต็ม</td></tr>
|
|
39
|
-
<tr><td><code>Edit</code></td><td>แก้ไขแบบแทนที่สตริงที่แน่นอน</td></tr>
|
|
40
|
-
<tr><td><code>Glob</code></td><td>ค้นหาไฟล์ด้วย pattern, เรียงตามเวลาแก้ไข</td></tr>
|
|
41
|
-
<tr><td><code>Grep</code></td><td>ค้นหาเนื้อหาด้วย regex พร้อมบรรทัดบริบท</td></tr>
|
|
42
|
-
<tr><td><code>NotebookEdit</code></td><td>แก้ไขเซลล์ Jupyter notebook</td></tr>
|
|
43
|
-
</table>
|
|
44
|
-
|
|
45
|
-
<h2>เชลล์และระบบ</h2>
|
|
46
|
-
<table>
|
|
47
|
-
<tr><th>เครื่องมือ</th><th>คำอธิบาย</th></tr>
|
|
48
|
-
<tr><td><code>Bash</code></td><td>รันคำสั่ง shell พร้อม timeout, background, sandbox</td></tr>
|
|
49
|
-
<tr><td><code>Monitor</code></td><td>สตรีม stdout/stderr จากงานพื้นหลังแบบเรียลไทม์</td></tr>
|
|
50
|
-
<tr><td><code>TaskOutput</code></td><td>รับผลลัพธ์จากงานที่กำลังรันหรือเสร็จแล้ว</td></tr>
|
|
51
|
-
</table>
|
|
52
|
-
|
|
53
|
-
<h2>ค้นหาและเว็บ</h2>
|
|
54
|
-
<table>
|
|
55
|
-
<tr><th>เครื่องมือ</th><th>คำอธิบาย</th></tr>
|
|
56
|
-
<tr><td><code>WebSearch</code></td><td>ค้นหาเว็บหลายผู้ให้บริการ (Tavily, Brave, Serper, SearXNG, DuckDuckGo)</td></tr>
|
|
57
|
-
<tr><td><code>WebFetch</code></td><td>ดึงและวิเคราะห์เนื้อหาจาก URL</td></tr>
|
|
58
|
-
<tr><td><code>SessionSearch</code></td><td>ค้นหาข้อความเต็มในประวัติเซสชันที่ผ่านมา</td></tr>
|
|
59
|
-
</table>
|
|
60
|
-
|
|
61
|
-
<h2>ความปลอดภัยและสิทธิ์ของเครื่องมือ</h2>
|
|
62
|
-
<p>แต่ละเครื่องมือประกาศ:</p>
|
|
63
|
-
<ul>
|
|
64
|
-
<li><strong>isEnabled()</strong> — พร้อมใช้งานใน build ปัจจุบันหรือไม่</li>
|
|
65
|
-
<li><strong>isConcurrencySafe()</strong> — รันพร้อมกับเครื่องมืออื่นได้หรือไม่</li>
|
|
66
|
-
<li><strong>isReadOnly()</strong> — ไม่แก้ไขระบบไฟล์</li>
|
|
67
|
-
<li><strong>isDestructive()</strong> — ดำเนินการที่ไม่สามารถย้อนกลับ</li>
|
|
68
|
-
</ul>
|
|
69
|
-
|
|
70
|
-
<footer class="footer">
|
|
71
|
-
<span>Clew Code 0.2.14 — โอเพนซอร์ส</span>
|
|
72
|
-
<div class="footer-links">
|
|
73
|
-
<a href="https://github.com/ClewCode/ClewCode">GitHub</a>
|
|
74
|
-
<a href="https://github.com/ClewCode/ClewCode/issues">ปัญหา</a>
|
|
75
|
-
</div>
|
|
76
|
-
</footer>
|
|
77
|
-
</main>
|
|
78
|
-
<nav class="toc-sidebar"></nav>
|
|
79
|
-
</div>
|
|
80
|
-
</div>
|
|
81
|
-
<script src="js/main.js"></script>
|
|
82
|
-
</body>
|
|
83
|
-
</html>
|
|
84
|
-
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="th">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="UTF-8">
|
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
-
<title>การแก้ปัญหา — Clew</title>
|
|
7
|
-
<meta name="description" content="ปัญหาทั่วไปและวิธีแก้ไขสำหรับ Clew — คีย์ผู้ให้บริการ, ข้อผิดพลาด build, MCP, ปลั๊กอิน, และปัญหารันไทม์">
|
|
8
|
-
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
9
|
-
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
10
|
-
<link href="https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600;700&family=Noto+Sans+Thai:wght@400;500;600;700&display=swap" rel="stylesheet">
|
|
11
|
-
<link rel="stylesheet" href="css/styles.css">
|
|
12
|
-
<link rel="icon" type="image/svg+xml" href="./assets/clew.svg">
|
|
13
|
-
</head>
|
|
14
|
-
<body>
|
|
15
|
-
<header class="header"></header>
|
|
16
|
-
<div class="app"><aside class="sidebar" id="sidebar"></aside><div class="sidebar-overlay" id="sidebarOverlay"></div>
|
|
17
|
-
<div class="content-wrap"><main class="content">
|
|
18
|
-
<div class="breadcrumbs"><a href="index.th.html">หน้าแรก</a><span class="sep">/</span><span>การแก้ปัญหา</span></div>
|
|
19
|
-
<h1>การแก้ปัญหา</h1>
|
|
20
|
-
<p class="section-subtitle">เริ่มต้นด้วย <code>/doctor</code> — มันตรวจสอบเวอร์ชันรันไทม์, ข้อมูลประจำตัวผู้ให้บริการ, ความสมบูรณ์ของการตั้งค่า, สถานะปลั๊กอิน/MCP, และ Sentry telemetry</p>
|
|
21
|
-
|
|
22
|
-
<h2>ปัญหาเริ่มต้น</h2>
|
|
23
|
-
<h3>"command not found: clew"</h3>
|
|
24
|
-
<p>พาธติดตั้ง global npm อาจไม่อยู่ใน <code>PATH</code> ใช้ <code>npx clew-code</code> หรือ <code>bun x clew-code</code> เป็นทางเลือก</p>
|
|
25
|
-
|
|
26
|
-
<h3>"Bun not found"</h3>
|
|
27
|
-
<p>Clew ต้องใช้ <a href="https://bun.sh">Bun 1.3+</a> เป็นรันไทม์สำหรับแพ็กเกจ npm</p>
|
|
28
|
-
|
|
29
|
-
<h2>ปัญหาผู้ให้บริการ</h2>
|
|
30
|
-
<h3>"No API key configured"</h3>
|
|
31
|
-
<p>ตั้งค่าคีย์ API อย่างน้อยหนึ่งรายการเป็นตัวแปรสภาพแวดล้อม ดู <a href="providers.th.html">ผู้ให้บริการ</a> สำหรับรายการทั้งหมด</p>
|
|
32
|
-
<pre><code>export ANTHROPIC_API_KEY=sk-ant-...
|
|
33
|
-
export DEEPSEEK_API_KEY=sk-...</code></pre>
|
|
34
|
-
<p>รัน <code>/doctor</code> เพื่อตรวจสอบผู้ให้บริการที่ตั้งค่า</p>
|
|
35
|
-
|
|
36
|
-
<h3>"Rate limited" หรือ "Quota exceeded"</h3>
|
|
37
|
-
<p>ตั้งค่าโมเดลสำรองผ่าน CLI: <code>--fallback-model <model></code> หรือใช้ <code>/model</code> เพื่อสลับไปยังผู้ให้บริการอื่น</p>
|
|
38
|
-
|
|
39
|
-
<h2>ปัญหา Build</h2>
|
|
40
|
-
<h3>ข้อผิดพลาด TypeScript ระหว่าง build</h3>
|
|
41
|
-
<pre><code>bun run build
|
|
42
|
-
# ข้อผิดพลาด TypeScript อาจอยู่ในโค้ดที่ยังไม่ได้ commit หรือโมดูลภายนอก
|
|
43
|
-
# รันการตรวจสอบเป้าหมาย:
|
|
44
|
-
bun x tsc --noEmit
|
|
45
|
-
bun test <targeted-path></code></pre>
|
|
46
|
-
|
|
47
|
-
<h3>ปัญหาเฉพาะ Windows</h3>
|
|
48
|
-
<ul>
|
|
49
|
-
<li>ripgrep แถมมาที่ <code>src/utils/vendor/ripgrep/x64-win32/rg.exe</code></li>
|
|
50
|
-
<li>TTY polyfill อาจจำเป็นสำหรับ Ink compatibility</li>
|
|
51
|
-
<li>PowerShell และ Bash อาจทำงานแตกต่างสำหรับการเรียกใช้เครื่องมือ</li>
|
|
52
|
-
</ul>
|
|
53
|
-
|
|
54
|
-
<h2>ปัญหา MCP</h2>
|
|
55
|
-
<h3>"MCP server connection failed"</h3>
|
|
56
|
-
<p>ตรวจสอบว่าคำสั่งเซิร์ฟเวอร์มีอยู่และพาธถูกต้อง ตรวจสอบไวยากรณ์ JSON config ด้วยคำสั่ง <code>/mcp</code></p>
|
|
57
|
-
|
|
58
|
-
<h2>ปัญหาปลั๊กอิน</h2>
|
|
59
|
-
<h3>ปลั๊กอินไม่โหลด</h3>
|
|
60
|
-
<p>ตรวจสอบรูปแบบและตำแหน่ง manifest ของปลั๊กอิน ใช้ <code>/plugin</code> และ <code>/reload-plugins</code> เพื่อรีเฟรช</p>
|
|
61
|
-
|
|
62
|
-
<h2>การขอความช่วยเหลือ</h2>
|
|
63
|
-
<ul>
|
|
64
|
-
<li><strong>การตรวจสอบในแอป:</strong> <code>/doctor</code> — ตรวจสอบสภาพแวดล้อมอย่างครอบคลุม</li>
|
|
65
|
-
<li><strong>ภาพรวมสถานะ:</strong> <code>/status</code> — เวอร์ชัน, โมเดล, การเชื่อมต่อ API</li>
|
|
66
|
-
<li><strong>GitHub Issues:</strong> รายงานบั๊กและขอฟีเจอร์</li>
|
|
67
|
-
<li><strong>โหมด Debug:</strong> รันด้วย <code>DEBUG=1</code> หรือ <code>DEBUG=provider:anthropic</code></li>
|
|
68
|
-
</ul>
|
|
69
|
-
|
|
70
|
-
<footer class="footer">
|
|
71
|
-
<span>Clew Code 0.2.14 — โอเพนซอร์ส</span>
|
|
72
|
-
<div class="footer-links">
|
|
73
|
-
<a href="https://github.com/ClewCode/ClewCode">GitHub</a>
|
|
74
|
-
<a href="https://github.com/ClewCode/ClewCode/issues">ปัญหา</a>
|
|
75
|
-
<a href="https://npmjs.com/package/clew-code">npm</a>
|
|
76
|
-
</div>
|
|
77
|
-
</footer>
|
|
78
|
-
</main>
|
|
79
|
-
<nav class="toc-sidebar"></nav>
|
|
80
|
-
</div>
|
|
81
|
-
</div>
|
|
82
|
-
<script src="js/main.js"></script>
|
|
83
|
-
</body>
|
|
84
|
-
</html>
|
|
85
|
-
|