gthinking 1.3.0 → 2.1.1

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.
Files changed (271) hide show
  1. package/.eslintrc.js +34 -0
  2. package/ANALYSIS_SUMMARY.md +363 -0
  3. package/README.md +230 -250
  4. package/dist/analysis/analysis-engine.d.ts +63 -0
  5. package/dist/analysis/analysis-engine.d.ts.map +1 -0
  6. package/dist/analysis/analysis-engine.js +322 -0
  7. package/dist/analysis/analysis-engine.js.map +1 -0
  8. package/dist/core/config.d.ts +1419 -0
  9. package/dist/core/config.d.ts.map +1 -0
  10. package/dist/core/config.js +361 -0
  11. package/dist/core/config.js.map +1 -0
  12. package/dist/core/engine.d.ts +176 -0
  13. package/dist/core/engine.d.ts.map +1 -0
  14. package/dist/core/engine.js +604 -0
  15. package/dist/core/engine.js.map +1 -0
  16. package/dist/core/errors.d.ts +153 -0
  17. package/dist/core/errors.d.ts.map +1 -0
  18. package/dist/core/errors.js +287 -0
  19. package/dist/core/errors.js.map +1 -0
  20. package/dist/core/index.d.ts +7 -0
  21. package/dist/core/index.d.ts.map +1 -0
  22. package/dist/{types.js → core/index.js} +8 -4
  23. package/dist/core/index.js.map +1 -0
  24. package/dist/core/pipeline.d.ts +121 -0
  25. package/dist/core/pipeline.d.ts.map +1 -0
  26. package/dist/core/pipeline.js +289 -0
  27. package/dist/core/pipeline.js.map +1 -0
  28. package/dist/core/rate-limiter.d.ts +58 -0
  29. package/dist/core/rate-limiter.d.ts.map +1 -0
  30. package/dist/core/rate-limiter.js +133 -0
  31. package/dist/core/rate-limiter.js.map +1 -0
  32. package/dist/core/session-manager.d.ts +96 -0
  33. package/dist/core/session-manager.d.ts.map +1 -0
  34. package/dist/core/session-manager.js +223 -0
  35. package/dist/core/session-manager.js.map +1 -0
  36. package/dist/creativity/creativity-engine.d.ts +6 -0
  37. package/dist/creativity/creativity-engine.d.ts.map +1 -0
  38. package/dist/creativity/creativity-engine.js +17 -0
  39. package/dist/creativity/creativity-engine.js.map +1 -0
  40. package/dist/index.d.ts +24 -32
  41. package/dist/index.d.ts.map +1 -1
  42. package/dist/index.js +130 -104
  43. package/dist/index.js.map +1 -1
  44. package/dist/learning/learning-engine.d.ts +6 -0
  45. package/dist/learning/learning-engine.d.ts.map +1 -0
  46. package/dist/learning/learning-engine.js +17 -0
  47. package/dist/learning/learning-engine.js.map +1 -0
  48. package/dist/llm/index.d.ts +10 -0
  49. package/dist/llm/index.d.ts.map +1 -0
  50. package/dist/llm/index.js +26 -0
  51. package/dist/llm/index.js.map +1 -0
  52. package/dist/llm/llm-service.d.ts +109 -0
  53. package/dist/llm/llm-service.d.ts.map +1 -0
  54. package/dist/llm/llm-service.js +224 -0
  55. package/dist/llm/llm-service.js.map +1 -0
  56. package/dist/llm/providers/base.d.ts +85 -0
  57. package/dist/llm/providers/base.d.ts.map +1 -0
  58. package/dist/llm/providers/base.js +57 -0
  59. package/dist/llm/providers/base.js.map +1 -0
  60. package/dist/llm/providers/cli.d.ts +23 -0
  61. package/dist/llm/providers/cli.d.ts.map +1 -0
  62. package/dist/llm/providers/cli.js +158 -0
  63. package/dist/llm/providers/cli.js.map +1 -0
  64. package/dist/llm/providers/gemini.d.ts +30 -0
  65. package/dist/llm/providers/gemini.d.ts.map +1 -0
  66. package/dist/llm/providers/gemini.js +168 -0
  67. package/dist/llm/providers/gemini.js.map +1 -0
  68. package/dist/llm/sanitization.d.ts +50 -0
  69. package/dist/llm/sanitization.d.ts.map +1 -0
  70. package/dist/llm/sanitization.js +149 -0
  71. package/dist/llm/sanitization.js.map +1 -0
  72. package/dist/{server.d.ts.map → mcp/server.d.ts.map} +1 -1
  73. package/dist/mcp/server.js +108 -0
  74. package/dist/mcp/server.js.map +1 -0
  75. package/dist/planning/planning-engine.d.ts +6 -0
  76. package/dist/planning/planning-engine.d.ts.map +1 -0
  77. package/dist/planning/planning-engine.js +17 -0
  78. package/dist/planning/planning-engine.js.map +1 -0
  79. package/dist/reasoning/reasoning-engine.d.ts +6 -0
  80. package/dist/reasoning/reasoning-engine.d.ts.map +1 -0
  81. package/dist/reasoning/reasoning-engine.js +17 -0
  82. package/dist/reasoning/reasoning-engine.js.map +1 -0
  83. package/dist/search/search-engine.d.ts +99 -0
  84. package/dist/search/search-engine.d.ts.map +1 -0
  85. package/dist/search/search-engine.js +271 -0
  86. package/dist/search/search-engine.js.map +1 -0
  87. package/dist/synthesis/synthesis-engine.d.ts +6 -0
  88. package/dist/synthesis/synthesis-engine.d.ts.map +1 -0
  89. package/dist/synthesis/synthesis-engine.js +17 -0
  90. package/dist/synthesis/synthesis-engine.js.map +1 -0
  91. package/dist/types/analysis.d.ts +1534 -49
  92. package/dist/types/analysis.d.ts.map +1 -1
  93. package/dist/types/analysis.js +250 -0
  94. package/dist/types/analysis.js.map +1 -1
  95. package/dist/types/core.d.ts +257 -30
  96. package/dist/types/core.d.ts.map +1 -1
  97. package/dist/types/core.js +148 -18
  98. package/dist/types/core.js.map +1 -1
  99. package/dist/types/creativity.d.ts +2871 -56
  100. package/dist/types/creativity.d.ts.map +1 -1
  101. package/dist/types/creativity.js +195 -0
  102. package/dist/types/creativity.js.map +1 -1
  103. package/dist/types/index.d.ts +6 -2
  104. package/dist/types/index.d.ts.map +1 -1
  105. package/dist/types/index.js +17 -2
  106. package/dist/types/index.js.map +1 -1
  107. package/dist/types/learning.d.ts +851 -61
  108. package/dist/types/learning.d.ts.map +1 -1
  109. package/dist/types/learning.js +155 -0
  110. package/dist/types/learning.js.map +1 -1
  111. package/dist/types/planning.d.ts +2223 -71
  112. package/dist/types/planning.d.ts.map +1 -1
  113. package/dist/types/planning.js +190 -0
  114. package/dist/types/planning.js.map +1 -1
  115. package/dist/types/reasoning.d.ts +2209 -72
  116. package/dist/types/reasoning.d.ts.map +1 -1
  117. package/dist/types/reasoning.js +200 -1
  118. package/dist/types/reasoning.js.map +1 -1
  119. package/dist/types/search.d.ts +981 -53
  120. package/dist/types/search.d.ts.map +1 -1
  121. package/dist/types/search.js +137 -0
  122. package/dist/types/search.js.map +1 -1
  123. package/dist/types/synthesis.d.ts +583 -38
  124. package/dist/types/synthesis.d.ts.map +1 -1
  125. package/dist/types/synthesis.js +138 -0
  126. package/dist/types/synthesis.js.map +1 -1
  127. package/dist/utils/cache.d.ts +144 -0
  128. package/dist/utils/cache.d.ts.map +1 -0
  129. package/dist/utils/cache.js +288 -0
  130. package/dist/utils/cache.js.map +1 -0
  131. package/dist/utils/id-generator.d.ts +89 -0
  132. package/dist/utils/id-generator.d.ts.map +1 -0
  133. package/dist/utils/id-generator.js +132 -0
  134. package/dist/utils/id-generator.js.map +1 -0
  135. package/dist/utils/index.d.ts +11 -0
  136. package/dist/utils/index.d.ts.map +1 -0
  137. package/dist/utils/index.js +33 -0
  138. package/dist/utils/index.js.map +1 -0
  139. package/dist/utils/logger.d.ts +142 -0
  140. package/dist/utils/logger.d.ts.map +1 -0
  141. package/dist/utils/logger.js +248 -0
  142. package/dist/utils/logger.js.map +1 -0
  143. package/dist/utils/metrics.d.ts +149 -0
  144. package/dist/utils/metrics.d.ts.map +1 -0
  145. package/dist/utils/metrics.js +296 -0
  146. package/dist/utils/metrics.js.map +1 -0
  147. package/dist/utils/timer.d.ts +7 -0
  148. package/dist/utils/timer.d.ts.map +1 -0
  149. package/dist/utils/timer.js +17 -0
  150. package/dist/utils/timer.js.map +1 -0
  151. package/dist/utils/validation.d.ts +147 -0
  152. package/dist/utils/validation.d.ts.map +1 -0
  153. package/dist/utils/validation.js +275 -0
  154. package/dist/utils/validation.js.map +1 -0
  155. package/docs/API.md +411 -0
  156. package/docs/ARCHITECTURE.md +271 -0
  157. package/docs/CHANGELOG.md +283 -0
  158. package/jest.config.js +28 -0
  159. package/package.json +43 -30
  160. package/src/analysis/analysis-engine.ts +383 -0
  161. package/src/core/config.ts +406 -0
  162. package/src/core/engine.ts +785 -0
  163. package/src/core/errors.ts +349 -0
  164. package/src/core/index.ts +12 -0
  165. package/src/core/pipeline.ts +424 -0
  166. package/src/core/rate-limiter.ts +155 -0
  167. package/src/core/session-manager.ts +269 -0
  168. package/src/creativity/creativity-engine.ts +14 -0
  169. package/src/index.ts +178 -0
  170. package/src/learning/learning-engine.ts +14 -0
  171. package/src/llm/index.ts +10 -0
  172. package/src/llm/llm-service.ts +285 -0
  173. package/src/llm/providers/base.ts +146 -0
  174. package/src/llm/providers/cli.ts +186 -0
  175. package/src/llm/providers/gemini.ts +201 -0
  176. package/src/llm/sanitization.ts +178 -0
  177. package/src/mcp/server.ts +117 -0
  178. package/src/planning/planning-engine.ts +14 -0
  179. package/src/reasoning/reasoning-engine.ts +14 -0
  180. package/src/search/search-engine.ts +333 -0
  181. package/src/synthesis/synthesis-engine.ts +14 -0
  182. package/src/types/analysis.ts +337 -0
  183. package/src/types/core.ts +342 -0
  184. package/src/types/creativity.ts +268 -0
  185. package/src/types/index.ts +31 -0
  186. package/src/types/learning.ts +215 -0
  187. package/src/types/planning.ts +251 -0
  188. package/src/types/reasoning.ts +288 -0
  189. package/src/types/search.ts +192 -0
  190. package/src/types/synthesis.ts +187 -0
  191. package/src/utils/cache.ts +363 -0
  192. package/src/utils/id-generator.ts +135 -0
  193. package/src/utils/index.ts +22 -0
  194. package/src/utils/logger.ts +290 -0
  195. package/src/utils/metrics.ts +380 -0
  196. package/src/utils/timer.ts +15 -0
  197. package/src/utils/validation.ts +297 -0
  198. package/tests/setup.ts +22 -0
  199. package/tests/unit/cache.test.ts +189 -0
  200. package/tests/unit/engine.test.ts +179 -0
  201. package/tests/unit/validation.test.ts +218 -0
  202. package/tsconfig.json +17 -12
  203. package/GEMINI.md +0 -68
  204. package/analysis.ts +0 -1063
  205. package/creativity.ts +0 -1055
  206. package/dist/analysis.d.ts +0 -54
  207. package/dist/analysis.d.ts.map +0 -1
  208. package/dist/analysis.js +0 -866
  209. package/dist/analysis.js.map +0 -1
  210. package/dist/creativity.d.ts +0 -81
  211. package/dist/creativity.d.ts.map +0 -1
  212. package/dist/creativity.js +0 -828
  213. package/dist/creativity.js.map +0 -1
  214. package/dist/engine.d.ts +0 -90
  215. package/dist/engine.d.ts.map +0 -1
  216. package/dist/engine.js +0 -720
  217. package/dist/engine.js.map +0 -1
  218. package/dist/examples.d.ts +0 -7
  219. package/dist/examples.d.ts.map +0 -1
  220. package/dist/examples.js +0 -506
  221. package/dist/examples.js.map +0 -1
  222. package/dist/learning.d.ts +0 -72
  223. package/dist/learning.d.ts.map +0 -1
  224. package/dist/learning.js +0 -615
  225. package/dist/learning.js.map +0 -1
  226. package/dist/llm-service.d.ts +0 -21
  227. package/dist/llm-service.d.ts.map +0 -1
  228. package/dist/llm-service.js +0 -100
  229. package/dist/llm-service.js.map +0 -1
  230. package/dist/planning.d.ts +0 -62
  231. package/dist/planning.d.ts.map +0 -1
  232. package/dist/planning.js +0 -886
  233. package/dist/planning.js.map +0 -1
  234. package/dist/reasoning.d.ts +0 -73
  235. package/dist/reasoning.d.ts.map +0 -1
  236. package/dist/reasoning.js +0 -845
  237. package/dist/reasoning.js.map +0 -1
  238. package/dist/search-discovery.d.ts +0 -73
  239. package/dist/search-discovery.d.ts.map +0 -1
  240. package/dist/search-discovery.js +0 -548
  241. package/dist/search-discovery.js.map +0 -1
  242. package/dist/server.js +0 -113
  243. package/dist/server.js.map +0 -1
  244. package/dist/types/engine.d.ts +0 -55
  245. package/dist/types/engine.d.ts.map +0 -1
  246. package/dist/types/engine.js +0 -3
  247. package/dist/types/engine.js.map +0 -1
  248. package/dist/types.d.ts +0 -6
  249. package/dist/types.d.ts.map +0 -1
  250. package/dist/types.js.map +0 -1
  251. package/engine.ts +0 -1009
  252. package/examples.ts +0 -717
  253. package/index.ts +0 -106
  254. package/learning.ts +0 -779
  255. package/llm-service.ts +0 -120
  256. package/planning.ts +0 -1101
  257. package/reasoning.ts +0 -1079
  258. package/search-discovery.ts +0 -700
  259. package/server.ts +0 -115
  260. package/types/analysis.ts +0 -69
  261. package/types/core.ts +0 -90
  262. package/types/creativity.ts +0 -72
  263. package/types/engine.ts +0 -60
  264. package/types/index.ts +0 -9
  265. package/types/learning.ts +0 -69
  266. package/types/planning.ts +0 -85
  267. package/types/reasoning.ts +0 -92
  268. package/types/search.ts +0 -58
  269. package/types/synthesis.ts +0 -43
  270. package/types.ts +0 -6
  271. /package/dist/{server.d.ts → mcp/server.d.ts} +0 -0
package/README.md CHANGED
@@ -1,83 +1,104 @@
1
- # Sequential Thinking System
2
-
3
- ระบบ Sequential Thinking อัจฉริยะที่ครอบคลุมการคิดวิเคราะห์แบบหลายขั้นตอน สำหรับการแก้ปัญหาที่ซับซ้อน
4
-
5
- ## Recent Updates (v1.3.0)
6
- * **Dynamic Pipeline:** ระบบสามารถวิเคราะห์คำถามและเลือกขั้นตอนการคิด (Thinking Stages) ที่เหมาะสมโดยอัตโนมัติ ไม่จำเป็นต้องรันทุกขั้นตอนเสมอไป ทำให้ทำงานได้รวดเร็วและตรงจุดยิ่งขึ้น
7
- * **Devil's Advocate Mode:** เพิ่มฟีเจอร์ "ผู้คัดค้าน" ในขั้นตอน Synthesis ที่จะคอยวิจารณ์ข้อสรุป หาจุดอ่อน และเสนอแนะมุมมองตรงกันข้าม เพื่อให้คำตอบมีความรอบด้านและน่าเชื่อถือที่สุด
8
- * **Dynamic Planning:** `PlanningEngine` สามารถกำหนด Workflow ของการคิดได้เอง based on user query context.
9
-
10
- ## Recent Updates (v1.2.1)
11
- * **Security Fix:** ป้องกัน Command Injection Vulnerability ใน module `llm-service` โดยเปลี่ยนการทำงานจาก `exec` เป็น `spawn` เพื่อความปลอดภัยสูงสุด
12
- * **Refactoring:** ปรับโครงสร้าง Codebase แยกไฟล์ `types.ts` ขนาดใหญ่เป็นโมดูลย่อย (`types/*`) เพื่อการบำรุงรักษาที่ดีขึ้น
13
- * **Architecture:** เพิ่มการรองรับ **Dependency Injection** ใน `SequentialThinkingEngine` เพื่อความยืดหยุ่นและการทดสอบที่ง่ายขึ้น
14
-
15
- ## คุณสมบัติหลัก
16
-
17
- ### 1. Search & Discovery (ค้นหาและค้นพบ)
18
- - **Web Search แบบ Real-time**: ค้นหาข้อมูลจากหลายแหล่งพร้อมกัน
19
- - **Multi-source Aggregation**: รวมผลลัพธ์จากหลายแหล่งข้อมูล
20
- - **Intelligent Filtering**: กรองและจัดอันดับผลลัพธ์ตามความน่าเชื่อถือและความเกี่ยวข้อง
21
- - **Knowledge Base Integration**: เชื่อมต่อกับฐานความรู้ภายใน
22
-
23
- ### 2. Analysis (การวิเคราะห์)
24
- - **Sentiment Analysis**: วิเคราะห์ความรู้สึกในเนื้อหา
25
- - **Entity Extraction**: แยกแยะบุคคล องค์กร สถานที่
26
- - **Topic Extraction**: ระบุหัวข้อหลัก
27
- - **Keyword Extraction**: สกัดคำสำคัญ
28
- - **Summarization**: สรุปเนื้อหา
29
- - **Fact Checking**: ตรวจสอบความถูกต้อง
30
- - **Comparison**: เปรียบเทียบข้อมูล
31
-
32
- ### 3. Reasoning (การคิดเชิงตรรกะ)
33
- - **Chain of Thought**: โซ่แห่งการคิดแบบลึกซึ้ง
34
- - **Multiple Reasoning Types**:
35
- - Deductive (อนุมาน)
36
- - Inductive (ตรรกยานุมาน)
37
- - Abductive (อนุมานแบบพยากรณ์)
38
- - Analogical (เปรียบเทียบ)
39
- - Causal (เหตุและผล)
40
- - Counterfactual (สมมติฐาน)
41
- - **Hypothesis Testing**: การตั้งสมมติฐานและพิสูจน์
42
- - **Problem Decomposition**: แยกปัญหาย่อย
43
-
44
- ### 4. Learning (การเรียนรู้)
45
- - **Context Memory**: จดจำบริบทการสนทนา
46
- - **Pattern Recognition**: จดจำรูปแบบ
47
- - **Knowledge Graph**: กราฟความรู้ที่เชื่อมโยง
48
- - **User Preferences**: เรียนรู้ความชอบของผู้ใช้
49
- - **Feedback Integration**: ปรับปรุงจาก feedback
50
-
51
- ### 5. Planning (การวางแผน)
52
- - **Task Decomposition**: แบ่งงานเป็นขั้นตอนย่อย
53
- - **Prioritization**: จัดลำดับความสำคัญ
54
- - **Resource Allocation**: จัดสรรทรัพยากร
55
- - **Progress Tracking**: ติดตามความคืบหน้า
56
- - **Risk Analysis**: วิเคราะห์ความเสี่ยง
57
-
58
- ### 6. Creativity (การสร้างสรรค์)
59
- - **Brainstorming**: ระดมความคิด
60
- - **SCAMPER Technique**: เทคนิค SCAMPER
61
- - **Six Thinking Hats**: หมวก 6 ใบ
62
- - **Mind Mapping**: แผนที่ความคิด
63
- - **Out-of-Box Thinking**: คิดนอกกรอบ
64
- - **Concept Connection**: เชื่อมโยงแนวคิด
65
-
66
- ## การติดตั้ง
1
+ # gthinking v2.1.1
2
+
3
+ Sequential Thinking System - Advanced multi-stage thinking engine with AI-powered analysis, reasoning, and planning
4
+
5
+ ## Overview
6
+
7
+ `gthinking` is a comprehensive TypeScript library that implements a sequential thinking system designed to solve complex problems through multiple stages of analysis, reasoning, and synthesis. Version 2.1.1 brings critical security updates and a fully implemented Analysis Engine.
8
+
9
+ ## Features
10
+
11
+ ### Core Features
12
+ - **Sequential Thinking Pipeline**: 8-stage thinking process (Search → Analysis → Reasoning → Learning → Planning → Creativity → Synthesis → Evaluation)
13
+ - **Dynamic Pipeline**: Automatically selects appropriate stages based on query context
14
+ - **Parallel Execution**: Supports parallel execution of independent stages
15
+ - **Streaming Support**: Real-time results as each stage completes
16
+ - **Caching Layer**: Intelligent caching to reduce redundant processing
17
+
18
+ ### Search & Discovery
19
+ - Multi-provider web search (Google, Bing, Brave, DuckDuckGo)
20
+ - Knowledge base integration
21
+ - Intelligent result ranking and aggregation
22
+ - Conflict detection and consensus scoring
23
+
24
+ ### Analysis
25
+ - Sentiment analysis with emotion detection
26
+ - Entity extraction (people, organizations, locations, etc.)
27
+ - Topic extraction and keyword analysis
28
+ - Text summarization
29
+ - Fact checking
30
+ - Language detection
31
+ - Readability analysis
32
+
33
+ ### Reasoning
34
+ - 6 types of reasoning: Deductive, Inductive, Abductive, Analogical, Causal, Counterfactual
35
+ - Chain of Thought generation
36
+ - Hypothesis management and testing
37
+ - Problem decomposition
38
+
39
+ ### Planning
40
+ - Task decomposition and prioritization
41
+ - Resource allocation
42
+ - Timeline generation with critical path analysis
43
+ - Risk assessment and mitigation
44
+
45
+ ### Creativity
46
+ - Brainstorming with multiple techniques
47
+ - SCAMPER analysis
48
+ - Six Thinking Hats
49
+ - Mind mapping
50
+ - Out-of-box thinking perspectives
51
+
52
+ ### Learning
53
+ - Pattern recognition
54
+ - Knowledge graph management
55
+ - Context memory
56
+ - User preference learning
57
+
58
+ ## Installation
67
59
 
68
60
  ```bash
69
- npm install sequential-thinking-system
61
+ npm install gthinking
70
62
  ```
71
63
 
72
- ## การใช้งานผ่าน npx (Recommended for MCP)
64
+ ## Quick Start
73
65
 
74
- วิธีที่ง่ายที่สุดในการใช้งานคือผ่าน **npx** โดยไม่ต้องติดตั้งลงเครื่อง เหมาะสำหรับนำไปเชื่อมต่อกับ **Gemini CLI** หรือ **Claude Desktop**
66
+ ### Basic Usage
75
67
 
76
- ### การตั้งค่า MCP (Model Context Protocol)
68
+ ```typescript
69
+ import { SequentialThinkingEngine } from 'gthinking';
70
+
71
+ const engine = new SequentialThinkingEngine();
77
72
 
78
- เพิ่ม configuration นี้ลงในไฟล์ settings ของ MCP Client ของคุณ:
73
+ const result = await engine.think({
74
+ query: 'How can we improve remote work productivity?',
75
+ preferredStages: ['search', 'analysis', 'reasoning', 'synthesis'],
76
+ });
77
+
78
+ console.log(result.summary);
79
+ console.log(result.recommendations);
80
+ ```
79
81
 
80
- **สำหรับ Gemini CLI (`~/.gemini/config.json`) หรือ Claude Desktop:**
82
+ ### Using Individual Engines
83
+
84
+ ```typescript
85
+ import { AnalysisEngine, ReasoningEngine } from 'gthinking';
86
+
87
+ // Analysis
88
+ const analysis = await AnalysisEngine.analyze({
89
+ content: 'Your text here...',
90
+ types: ['sentiment', 'entity', 'keyword'],
91
+ });
92
+
93
+ // Reasoning
94
+ const reasoning = await ReasoningEngine.reason({
95
+ problem: 'Should we expand to Asian markets?',
96
+ type: 'deductive',
97
+ context: ['Current market saturation in US', 'Growing Asian economy'],
98
+ });
99
+ ```
100
+
101
+ ### MCP Server Usage
81
102
 
82
103
  ```json
83
104
  {
@@ -86,241 +107,200 @@ npm install sequential-thinking-system
86
107
  "command": "npx",
87
108
  "args": ["-y", "gthinking"],
88
109
  "env": {
89
- "LLM_PROVIDER": "gemini"
110
+ "LLM_PROVIDER": "gemini",
111
+ "LLM_API_KEY": "your-api-key"
90
112
  }
91
113
  }
92
114
  }
93
115
  }
94
116
  ```
95
117
 
96
- **Configuration Options:**
97
- * `LLM_PROVIDER`: เลือก LLM ที่ติดตั้งในเครื่องเพื่อใช้ประมวลผล (รองรับ: `gemini`, `claude`, `kimi`, `opencode`) - ค่าเริ่มต้นคือ `gemini`
98
-
99
- ### Gemini Instruction (Prompt)
118
+ ## CLI Mode (No API Key Required)
100
119
 
101
- เพื่อให้ Gemini เรียกใช้งานเครื่องมือได้อย่างมีประสิทธิภาพ แนะนำให้เพิ่ม Prompt นี้ใน System Instruction หรือตอนเริ่มสนทนา:
120
+ `gthinking` v2.1.0 introduces **CLI Mode**, allowing you to use local CLI tools (like Gemini CLI, Claude CLI, or custom wrappers) directly without requiring an API key in the configuration. This is ideal for users who are already authenticated via OAuth in their terminal.
102
121
 
103
- > "You have access to a specialized thinking engine called 'gthinking'. Use the `think` tool for complex analysis, reasoning, and planning tasks. Use `creative_solve` for brainstorming and ideation. Use `quick_search` for fast information retrieval. When using `think`, consider the appropriate 'depth' and 'complexity' based on the user's request."
122
+ ### Configuration
104
123
 
105
- ## การใช้งานเบื้องต้น (Code Library)
124
+ Set the `GTHINKING_LLM_PROVIDER` to `cli` and specify your command.
106
125
 
107
- ### 1. การคิดแบบพื้นฐาน
126
+ #### 1. Gemini CLI (Smart Defaults)
127
+ If you use the standard Gemini CLI, `gthinking` automatically configures the arguments for you.
108
128
 
109
- ```typescript
110
- import { thinkingEngine } from 'sequential-thinking-system';
111
-
112
- const response = await thinkingEngine.think({
113
- id: 'request_1',
114
- query: 'What are the implications of AI in healthcare?'
115
- });
116
-
117
- console.log(response.finalAnswer);
118
- console.log(`Confidence: ${response.confidence}`);
129
+ ```bash
130
+ export GTHINKING_LLM_PROVIDER=cli
131
+ export GTHINKING_LLM_CLI_COMMAND=gemini
132
+ # System will execute: gemini -p "your prompt"
119
133
  ```
120
134
 
121
- ### 2. การค้นหาอย่างรวดเร็ว
122
-
123
- ```typescript
124
- import { think } from 'sequential-thinking-system';
135
+ #### 2. Other Tools (Generic)
136
+ For tools that read from `stdin` (standard input):
125
137
 
126
- const answer = await think('Latest technology trends 2024');
127
- console.log(answer);
138
+ ```bash
139
+ export GTHINKING_LLM_PROVIDER=cli
140
+ export GTHINKING_LLM_CLI_COMMAND=opencode
141
+ # System will execute: opencode << "your prompt"
128
142
  ```
129
143
 
130
- ### 3. การวิเคราะห์เชิงลึก
144
+ #### 3. Custom Arguments
145
+ For tools requiring specific flags or arguments:
131
146
 
132
- ```typescript
133
- import { analyze } from 'sequential-thinking-system';
134
-
135
- const analysis = await analyze(
136
- 'Climate change impact on agriculture',
137
- 'Focus on developing countries'
138
- );
139
- console.log(analysis);
147
+ ```bash
148
+ export GTHINKING_LLM_PROVIDER=cli
149
+ export GTHINKING_LLM_CLI_COMMAND=mytool
150
+ export GTHINKING_LLM_CLI_ARGS="--fast,--json"
151
+ export GTHINKING_LLM_CLI_PROMPT_METHOD=arg
152
+ export GTHINKING_LLM_CLI_PROMPT_FLAG=--query
153
+ # System will execute: mytool --fast --json --query "your prompt"
140
154
  ```
141
155
 
142
- ### 4. การแก้ปัญหาเชิงสร้างสรรค์
143
-
144
- ```typescript
145
- import { solveCreatively } from 'sequential-thinking-system';
156
+ ## Configuration
146
157
 
147
- const solution = await solveCreatively(
148
- 'How to reduce urban traffic congestion?'
149
- );
150
- console.log(solution);
151
- ```
158
+ ### Environment Variables
152
159
 
153
- ### 5. การสร้างแผน
160
+ ```bash
161
+ # LLM Configuration
162
+ GTHINKING_LLM_PROVIDER=gemini
163
+ GTHINKING_LLM_API_KEY=your-api-key
164
+ GTHINKING_LLM_MODEL=gemini-pro
154
165
 
155
- ```typescript
156
- import { createPlan } from 'sequential-thinking-system';
166
+ # Search Configuration
167
+ GTHINKING_SEARCH_API_KEY=your-search-api-key
157
168
 
158
- const plan = await createPlan('Launch a mobile app');
159
- console.log(`Tasks: ${plan.tasks.length}`);
160
- console.log(`Estimated duration: ${plan.timeline.endDate}`);
169
+ # Logging
170
+ GTHINKING_LOG_LEVEL=info
161
171
  ```
162
172
 
163
- ## การใช้งานขั้นสูง
164
-
165
- ### กำหนดค่าการทำงาน
173
+ ### Programmatic Configuration
166
174
 
167
175
  ```typescript
168
- import { SequentialThinkingEngine } from 'sequential-thinking-system';
169
-
170
- const engine = new SequentialThinkingEngine({
171
- maxSearchResults: 20,
172
- analysisDepth: 'deep',
173
- reasoningComplexity: 'complex',
174
- learningEnabled: true,
175
- creativityLevel: 'adventurous',
176
- planningDetail: 'granular',
177
- timeout: 120000
176
+ import { SequentialThinkingEngine, ConfigManager } from 'gthinking';
177
+
178
+ const config = new ConfigManager({
179
+ llm: {
180
+ provider: 'openai',
181
+ apiKey: 'your-api-key',
182
+ model: 'gpt-4',
183
+ },
184
+ search: {
185
+ providers: ['google', 'bing'],
186
+ maxResults: 20,
187
+ },
188
+ cache: {
189
+ enabled: true,
190
+ maxSize: 2000,
191
+ },
178
192
  });
179
193
 
180
- const response = await engine.think({
181
- id: 'advanced_request',
182
- query: 'Complex problem to solve',
183
- preferredStages: [
184
- 'search',
185
- 'analysis',
186
- 'reasoning',
187
- 'creativity',
188
- 'synthesis'
189
- ]
190
- });
194
+ const engine = new SequentialThinkingEngine(config.getConfig());
191
195
  ```
192
196
 
193
- ### การใช้งานแต่ละโมดูลแยกต่างหาก
194
-
195
- ```typescript
196
- import {
197
- searchEngine,
198
- analysisEngine,
199
- reasoningEngine,
200
- learningEngine,
201
- planningEngine,
202
- creativityEngine
203
- } from 'sequential-thinking-system';
204
-
205
- // Search
206
- const searchResults = await searchEngine.search('AI ethics', {
207
- maxResults: 10,
208
- sources: ['web', 'knowledge_base']
209
- });
197
+ ## API Reference
210
198
 
211
- // Analysis
212
- const analysis = await analysisEngine.analyze(content, {
213
- types: ['sentiment', 'entity', 'topic'],
214
- depth: 'deep'
215
- });
199
+ ### SequentialThinkingEngine
216
200
 
217
- // Reasoning
218
- const reasoning = await reasoningEngine.reason(problem, {
219
- type: 'deductive',
220
- maxSteps: 5
221
- });
201
+ The main orchestrator class that coordinates all thinking stages.
222
202
 
223
- // Learning
224
- const context = learningEngine.getOrCreateContext('session_1');
225
- learningEngine.recordInteraction('session_1', query, response);
203
+ #### Methods
226
204
 
227
- // Planning
228
- const plan = planningEngine.createPlan('Build a website', {
229
- resources: [...],
230
- deadline: new Date('2024-12-31')
231
- });
205
+ - `think(request: ThinkingRequest): Promise<SynthesisResult>` - Execute full thinking pipeline
206
+ - `quickSearch(query: string): Promise<SynthesisResult>` - Fast search with minimal stages
207
+ - `deepAnalysis(query: string): Promise<SynthesisResult>` - Comprehensive analysis with all stages
208
+ - `creativeSolve(challenge: string): Promise<CreativeResult>` - Creative problem solving
209
+ - `createPlan(goal: string, options?: PlanningOptions): Promise<Plan>` - Generate execution plan
232
210
 
233
- // Creativity
234
- const session = creativityEngine.startSession('Improve user experience', {
235
- techniques: ['brainstorming', 'scamper'],
236
- ideaCount: 20
237
- });
238
- ```
211
+ ### Individual Engines
239
212
 
240
- ### การติดตามเหตุการณ์
213
+ Each engine can be used independently:
241
214
 
242
- ```typescript
243
- thinkingEngine.on('thinking_complete', (event) => {
244
- console.log(`Completed in ${event.data.processingTime}ms`);
245
- });
215
+ - `SearchDiscoveryEngine` - Web search and knowledge retrieval
216
+ - `AnalysisEngine` - Content analysis
217
+ - `ReasoningEngine` - Logical reasoning
218
+ - `PlanningEngine` - Task planning
219
+ - `CreativityEngine` - Creative thinking
220
+ - `LearningEngine` - Pattern learning
221
+ - `SynthesisEngine` - Result synthesis
246
222
 
247
- thinkingEngine.on('search_complete', (event) => {
248
- console.log(`Found ${event.data.results.length} results`);
249
- });
223
+ ## Security
250
224
 
251
- thinkingEngine.on('analysis_complete', (event) => {
252
- console.log(`Analysis confidence: ${event.data.confidence}`);
253
- });
254
- ```
225
+ Version 2.0.0 includes significant security improvements:
255
226
 
256
- ## โครงสร้างโปรเจค
227
+ - **Input Sanitization**: All user inputs are sanitized to prevent injection attacks
228
+ - **Rate Limiting**: Built-in rate limiting to prevent abuse
229
+ - **Safe LLM Calls**: HTTP API calls instead of shell commands
230
+ - **Validation**: Comprehensive input validation using Zod schemas
257
231
 
258
- ```
259
- sequential-thinking-system/
260
- ├── types.ts # Type definitions
261
- ├── search-discovery.ts # Search module
262
- ├── analysis.ts # Analysis module
263
- ├── reasoning.ts # Reasoning module
264
- ├── learning.ts # Learning module
265
- ├── planning.ts # Planning module
266
- ├── creativity.ts # Creativity module
267
- ├── engine.ts # Main engine
268
- ├── index.ts # Exports
269
- └── README.md # Documentation
270
- ```
232
+ ## Performance
271
233
 
272
- ## ตัวอย่าง Use Cases
234
+ - **Caching**: Multi-level caching with TTL support
235
+ - **Parallel Execution**: Independent stages run in parallel
236
+ - **Streaming**: Real-time results without waiting for all stages
237
+ - **Metrics**: Built-in performance metrics collection
273
238
 
274
- ### 1. การวิจัยและรายงาน
239
+ ## Error Handling
275
240
 
276
241
  ```typescript
277
- const response = await thinkingEngine.deepAnalysis(
278
- 'Impact of remote work on productivity'
279
- );
280
- // ได้รับ: สรุปผลการวิจัย การวิเคราะห์ ข้อเสนอแนะ
242
+ import { ThinkingError, TimeoutError, ValidationError } from 'gthinking';
243
+
244
+ try {
245
+ const result = await engine.think({ query: '...' });
246
+ } catch (error) {
247
+ if (error instanceof TimeoutError) {
248
+ console.log('Operation timed out:', error.stage);
249
+ } else if (error instanceof ValidationError) {
250
+ console.log('Validation failed:', error.details);
251
+ }
252
+ }
281
253
  ```
282
254
 
283
- ### 2. การวางแผนโครงการ
255
+ ## Testing
284
256
 
285
- ```typescript
286
- const plan = await thinkingEngine.createPlan(
287
- 'Develop AI-powered chatbot',
288
- {
289
- resources: [developer, designer],
290
- deadline: new Date('2024-06-01')
291
- }
292
- );
293
- // ได้รับ: รายการงานย่อย ลำดับความสำคัญ ไทม์ไลน์
294
- ```
257
+ ```bash
258
+ # Run all tests
259
+ npm test
295
260
 
296
- ### 3. การแก้ปัญหาสร้างสรรค์
261
+ # Run with coverage
262
+ npm run test:coverage
297
263
 
298
- ```typescript
299
- const solution = await thinkingEngine.creativeSolve(
300
- 'Increase customer engagement'
301
- );
302
- // ได้รับ: ไอเดียใหม่ๆ มุมมองที่แตกต่าง แนวทางปฏิบัติ
264
+ # Run in watch mode
265
+ npm run test:watch
303
266
  ```
304
267
 
305
- ### 4. การตัดสินใจ
268
+ ## Contributing
306
269
 
307
- ```typescript
308
- const response = await thinkingEngine.think({
309
- query: 'Should we expand to Asian markets?',
310
- preferredStages: ['search', 'analysis', 'reasoning'],
311
- config: { reasoningComplexity: 'complex' }
312
- });
313
- // ได้รับ: การวิเคราะห์ การให้เหตุผล ข้อเสนอแนะ
314
- ```
270
+ 1. Fork the repository
271
+ 2. Create a feature branch
272
+ 3. Make your changes
273
+ 4. Add tests
274
+ 5. Submit a pull request
275
+
276
+ ## License
277
+
278
+ MIT License - see LICENSE file for details
315
279
 
316
- ## สิทธิ์การใช้งาน
280
+ ## Changelog
317
281
 
318
- MIT License
282
+ ### v2.1.1
283
+ - **Security Update**: Hardened input sanitization (`sanitizeForShell`) to strictly allow only alphanumeric and safe characters, preventing potential command injection.
284
+ - **New Feature**: Fully implemented `AnalysisEngine` with support for Sentiment Analysis, Entity Extraction, Topic Extraction, Keyword Extraction, Summarization, and Readability metrics.
285
+ - **Integration**: `SequentialThinkingEngine` now automatically initializes and uses `AnalysisEngine` for analysis tasks.
319
286
 
320
- ## การมีส่วนร่วม
287
+ ### v2.1.0
288
+ - **New Feature**: CLI Provider support! Connect `gthinking` to any local LLM CLI tool (Gemini, Claude, etc.).
289
+ - Added `CLIProvider` for secure local process execution.
290
+ - Added support for custom CLI arguments and prompt passing methods (Stdin/Arg).
291
+ - Smart defaults for Gemini CLI integration.
321
292
 
322
- ยินดีรับ Pull Requests และ Issues
293
+ ### v2.0.0
294
+ - Complete rewrite with improved architecture
295
+ - Added security features (input sanitization, rate limiting)
296
+ - Implemented caching layer
297
+ - Added streaming support
298
+ - Improved error handling
299
+ - Added comprehensive test suite
300
+ - Enhanced type safety
301
+ - Added metrics collection
302
+ - Improved LLM integration with HTTP APIs
323
303
 
324
- ## ติดต่อ
304
+ ## Support
325
305
 
326
- For questions and support, please open an issue on GitHub.
306
+ For issues and feature requests, please use the [GitHub issue tracker](https://github.com/gotza02/gthinking/issues).
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Analysis Engine for gthinking v2.0.0
3
+ * AI-powered content analysis including sentiment, entities, topics, and more.
4
+ */
5
+ import { EventEmitter } from 'events';
6
+ import { LLMService } from '../llm/llm-service';
7
+ import { CompleteAnalysisResult } from '../types';
8
+ /**
9
+ * Analysis Engine
10
+ */
11
+ export declare class AnalysisEngine extends EventEmitter {
12
+ private llmService;
13
+ constructor(llmService?: LLMService);
14
+ /**
15
+ * Set the LLM service
16
+ * @param llmService - The LLM service instance
17
+ */
18
+ setLLMService(llmService: LLMService): void;
19
+ /**
20
+ * Analyze content based on request
21
+ * @param request - The analysis request
22
+ * @returns Complete analysis result
23
+ */
24
+ analyze(request: unknown): Promise<CompleteAnalysisResult>;
25
+ /**
26
+ * Analyze sentiment
27
+ */
28
+ private analyzeSentiment;
29
+ /**
30
+ * Extract entities
31
+ */
32
+ private extractEntities;
33
+ /**
34
+ * Extract topics
35
+ */
36
+ private extractTopics;
37
+ /**
38
+ * Extract keywords
39
+ */
40
+ private extractKeywords;
41
+ /**
42
+ * Generate summary
43
+ */
44
+ private generateSummary;
45
+ /**
46
+ * Calculate readability metrics (Locally)
47
+ */
48
+ private analyzeReadability;
49
+ private countSyllables;
50
+ private countComplexWords;
51
+ private getGradeLevel;
52
+ /**
53
+ * Execute LLM analysis with retries and parsing
54
+ */
55
+ private executeLLMAnalysis;
56
+ private ensureLLM;
57
+ private calculateOverallConfidence;
58
+ }
59
+ /**
60
+ * Factory function
61
+ */
62
+ export declare function createAnalysisEngine(llmService?: LLMService): AnalysisEngine;
63
+ //# sourceMappingURL=analysis-engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"analysis-engine.d.ts","sourceRoot":"","sources":["../../src/analysis/analysis-engine.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEtC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAIL,sBAAsB,EASvB,MAAM,UAAU,CAAC;AAMlB;;GAEG;AACH,qBAAa,cAAe,SAAQ,YAAY;IAC9C,OAAO,CAAC,UAAU,CAA2B;gBAEjC,UAAU,CAAC,EAAE,UAAU;IAKnC;;;OAGG;IACI,aAAa,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI;IAIlD;;;;OAIG;IACU,OAAO,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,sBAAsB,CAAC;IA4EvE;;OAEG;YACW,gBAAgB;IAiB9B;;OAEG;YACW,eAAe;IAmC7B;;OAEG;YACW,aAAa;IA+B3B;;OAEG;YACW,eAAe;IAgC7B;;OAEG;YACW,eAAe;IA0B7B;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAmC1B,OAAO,CAAC,cAAc;IAKtB,OAAO,CAAC,iBAAiB;IAKzB,OAAO,CAAC,aAAa;IAQrB;;OAEG;YACW,kBAAkB;IAiBhC,OAAO,CAAC,SAAS;IAMjB,OAAO,CAAC,0BAA0B;CAUnC;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,UAAU,CAAC,EAAE,UAAU,GAAG,cAAc,CAE5E"}