gthinking 1.2.1 → 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 -245
  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 -37
  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 -677
  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 -58
  231. package/dist/planning.d.ts.map +0 -1
  232. package/dist/planning.js +0 -824
  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 -947
  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 -1028
  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 -42
  270. package/types.ts +0 -6
  271. /package/dist/{server.d.ts → mcp/server.d.ts} +0 -0
package/README.md CHANGED
@@ -1,78 +1,104 @@
1
- # Sequential Thinking System
2
-
3
- ระบบ Sequential Thinking อัจฉริยะที่ครอบคลุมการคิดวิเคราะห์แบบหลายขั้นตอน สำหรับการแก้ปัญหาที่ซับซ้อน
4
-
5
- ## Recent Updates (v1.2.1)
6
- * **Security Fix:** ป้องกัน Command Injection Vulnerability ใน module `llm-service` โดยเปลี่ยนการทำงานจาก `exec` เป็น `spawn` เพื่อความปลอดภัยสูงสุด
7
- * **Refactoring:** ปรับโครงสร้าง Codebase แยกไฟล์ `types.ts` ขนาดใหญ่เป็นโมดูลย่อย (`types/*`) เพื่อการบำรุงรักษาที่ดีขึ้น
8
- * **Architecture:** เพิ่มการรองรับ **Dependency Injection** ใน `SequentialThinkingEngine` เพื่อความยืดหยุ่นและการทดสอบที่ง่ายขึ้น
9
-
10
- ## คุณสมบัติหลัก
11
-
12
- ### 1. Search & Discovery (ค้นหาและค้นพบ)
13
- - **Web Search แบบ Real-time**: ค้นหาข้อมูลจากหลายแหล่งพร้อมกัน
14
- - **Multi-source Aggregation**: รวมผลลัพธ์จากหลายแหล่งข้อมูล
15
- - **Intelligent Filtering**: กรองและจัดอันดับผลลัพธ์ตามความน่าเชื่อถือและความเกี่ยวข้อง
16
- - **Knowledge Base Integration**: เชื่อมต่อกับฐานความรู้ภายใน
17
-
18
- ### 2. Analysis (การวิเคราะห์)
19
- - **Sentiment Analysis**: วิเคราะห์ความรู้สึกในเนื้อหา
20
- - **Entity Extraction**: แยกแยะบุคคล องค์กร สถานที่
21
- - **Topic Extraction**: ระบุหัวข้อหลัก
22
- - **Keyword Extraction**: สกัดคำสำคัญ
23
- - **Summarization**: สรุปเนื้อหา
24
- - **Fact Checking**: ตรวจสอบความถูกต้อง
25
- - **Comparison**: เปรียบเทียบข้อมูล
26
-
27
- ### 3. Reasoning (การคิดเชิงตรรกะ)
28
- - **Chain of Thought**: โซ่แห่งการคิดแบบลึกซึ้ง
29
- - **Multiple Reasoning Types**:
30
- - Deductive (อนุมาน)
31
- - Inductive (ตรรกยานุมาน)
32
- - Abductive (อนุมานแบบพยากรณ์)
33
- - Analogical (เปรียบเทียบ)
34
- - Causal (เหตุและผล)
35
- - Counterfactual (สมมติฐาน)
36
- - **Hypothesis Testing**: การตั้งสมมติฐานและพิสูจน์
37
- - **Problem Decomposition**: แยกปัญหาย่อย
38
-
39
- ### 4. Learning (การเรียนรู้)
40
- - **Context Memory**: จดจำบริบทการสนทนา
41
- - **Pattern Recognition**: จดจำรูปแบบ
42
- - **Knowledge Graph**: กราฟความรู้ที่เชื่อมโยง
43
- - **User Preferences**: เรียนรู้ความชอบของผู้ใช้
44
- - **Feedback Integration**: ปรับปรุงจาก feedback
45
-
46
- ### 5. Planning (การวางแผน)
47
- - **Task Decomposition**: แบ่งงานเป็นขั้นตอนย่อย
48
- - **Prioritization**: จัดลำดับความสำคัญ
49
- - **Resource Allocation**: จัดสรรทรัพยากร
50
- - **Progress Tracking**: ติดตามความคืบหน้า
51
- - **Risk Analysis**: วิเคราะห์ความเสี่ยง
52
-
53
- ### 6. Creativity (การสร้างสรรค์)
54
- - **Brainstorming**: ระดมความคิด
55
- - **SCAMPER Technique**: เทคนิค SCAMPER
56
- - **Six Thinking Hats**: หมวก 6 ใบ
57
- - **Mind Mapping**: แผนที่ความคิด
58
- - **Out-of-Box Thinking**: คิดนอกกรอบ
59
- - **Concept Connection**: เชื่อมโยงแนวคิด
60
-
61
- ## การติดตั้ง
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
62
59
 
63
60
  ```bash
64
- npm install sequential-thinking-system
61
+ npm install gthinking
65
62
  ```
66
63
 
67
- ## การใช้งานผ่าน npx (Recommended for MCP)
64
+ ## Quick Start
68
65
 
69
- วิธีที่ง่ายที่สุดในการใช้งานคือผ่าน **npx** โดยไม่ต้องติดตั้งลงเครื่อง เหมาะสำหรับนำไปเชื่อมต่อกับ **Gemini CLI** หรือ **Claude Desktop**
66
+ ### Basic Usage
70
67
 
71
- ### การตั้งค่า MCP (Model Context Protocol)
68
+ ```typescript
69
+ import { SequentialThinkingEngine } from 'gthinking';
70
+
71
+ const engine = new SequentialThinkingEngine();
72
72
 
73
- เพิ่ม 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
+ ```
74
81
 
75
- **สำหรับ 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
76
102
 
77
103
  ```json
78
104
  {
@@ -81,241 +107,200 @@ npm install sequential-thinking-system
81
107
  "command": "npx",
82
108
  "args": ["-y", "gthinking"],
83
109
  "env": {
84
- "LLM_PROVIDER": "gemini"
110
+ "LLM_PROVIDER": "gemini",
111
+ "LLM_API_KEY": "your-api-key"
85
112
  }
86
113
  }
87
114
  }
88
115
  }
89
116
  ```
90
117
 
91
- **Configuration Options:**
92
- * `LLM_PROVIDER`: เลือก LLM ที่ติดตั้งในเครื่องเพื่อใช้ประมวลผล (รองรับ: `gemini`, `claude`, `kimi`, `opencode`) - ค่าเริ่มต้นคือ `gemini`
93
-
94
- ### Gemini Instruction (Prompt)
118
+ ## CLI Mode (No API Key Required)
95
119
 
96
- เพื่อให้ 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.
97
121
 
98
- > "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
99
123
 
100
- ## การใช้งานเบื้องต้น (Code Library)
124
+ Set the `GTHINKING_LLM_PROVIDER` to `cli` and specify your command.
101
125
 
102
- ### 1. การคิดแบบพื้นฐาน
126
+ #### 1. Gemini CLI (Smart Defaults)
127
+ If you use the standard Gemini CLI, `gthinking` automatically configures the arguments for you.
103
128
 
104
- ```typescript
105
- import { thinkingEngine } from 'sequential-thinking-system';
106
-
107
- const response = await thinkingEngine.think({
108
- id: 'request_1',
109
- query: 'What are the implications of AI in healthcare?'
110
- });
111
-
112
- console.log(response.finalAnswer);
113
- 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"
114
133
  ```
115
134
 
116
- ### 2. การค้นหาอย่างรวดเร็ว
117
-
118
- ```typescript
119
- import { think } from 'sequential-thinking-system';
135
+ #### 2. Other Tools (Generic)
136
+ For tools that read from `stdin` (standard input):
120
137
 
121
- const answer = await think('Latest technology trends 2024');
122
- 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"
123
142
  ```
124
143
 
125
- ### 3. การวิเคราะห์เชิงลึก
144
+ #### 3. Custom Arguments
145
+ For tools requiring specific flags or arguments:
126
146
 
127
- ```typescript
128
- import { analyze } from 'sequential-thinking-system';
129
-
130
- const analysis = await analyze(
131
- 'Climate change impact on agriculture',
132
- 'Focus on developing countries'
133
- );
134
- 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"
135
154
  ```
136
155
 
137
- ### 4. การแก้ปัญหาเชิงสร้างสรรค์
138
-
139
- ```typescript
140
- import { solveCreatively } from 'sequential-thinking-system';
156
+ ## Configuration
141
157
 
142
- const solution = await solveCreatively(
143
- 'How to reduce urban traffic congestion?'
144
- );
145
- console.log(solution);
146
- ```
158
+ ### Environment Variables
147
159
 
148
- ### 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
149
165
 
150
- ```typescript
151
- import { createPlan } from 'sequential-thinking-system';
166
+ # Search Configuration
167
+ GTHINKING_SEARCH_API_KEY=your-search-api-key
152
168
 
153
- const plan = await createPlan('Launch a mobile app');
154
- console.log(`Tasks: ${plan.tasks.length}`);
155
- console.log(`Estimated duration: ${plan.timeline.endDate}`);
169
+ # Logging
170
+ GTHINKING_LOG_LEVEL=info
156
171
  ```
157
172
 
158
- ## การใช้งานขั้นสูง
159
-
160
- ### กำหนดค่าการทำงาน
173
+ ### Programmatic Configuration
161
174
 
162
175
  ```typescript
163
- import { SequentialThinkingEngine } from 'sequential-thinking-system';
164
-
165
- const engine = new SequentialThinkingEngine({
166
- maxSearchResults: 20,
167
- analysisDepth: 'deep',
168
- reasoningComplexity: 'complex',
169
- learningEnabled: true,
170
- creativityLevel: 'adventurous',
171
- planningDetail: 'granular',
172
- 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
+ },
173
192
  });
174
193
 
175
- const response = await engine.think({
176
- id: 'advanced_request',
177
- query: 'Complex problem to solve',
178
- preferredStages: [
179
- 'search',
180
- 'analysis',
181
- 'reasoning',
182
- 'creativity',
183
- 'synthesis'
184
- ]
185
- });
194
+ const engine = new SequentialThinkingEngine(config.getConfig());
186
195
  ```
187
196
 
188
- ### การใช้งานแต่ละโมดูลแยกต่างหาก
189
-
190
- ```typescript
191
- import {
192
- searchEngine,
193
- analysisEngine,
194
- reasoningEngine,
195
- learningEngine,
196
- planningEngine,
197
- creativityEngine
198
- } from 'sequential-thinking-system';
199
-
200
- // Search
201
- const searchResults = await searchEngine.search('AI ethics', {
202
- maxResults: 10,
203
- sources: ['web', 'knowledge_base']
204
- });
197
+ ## API Reference
205
198
 
206
- // Analysis
207
- const analysis = await analysisEngine.analyze(content, {
208
- types: ['sentiment', 'entity', 'topic'],
209
- depth: 'deep'
210
- });
199
+ ### SequentialThinkingEngine
211
200
 
212
- // Reasoning
213
- const reasoning = await reasoningEngine.reason(problem, {
214
- type: 'deductive',
215
- maxSteps: 5
216
- });
201
+ The main orchestrator class that coordinates all thinking stages.
217
202
 
218
- // Learning
219
- const context = learningEngine.getOrCreateContext('session_1');
220
- learningEngine.recordInteraction('session_1', query, response);
203
+ #### Methods
221
204
 
222
- // Planning
223
- const plan = planningEngine.createPlan('Build a website', {
224
- resources: [...],
225
- deadline: new Date('2024-12-31')
226
- });
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
227
210
 
228
- // Creativity
229
- const session = creativityEngine.startSession('Improve user experience', {
230
- techniques: ['brainstorming', 'scamper'],
231
- ideaCount: 20
232
- });
233
- ```
211
+ ### Individual Engines
234
212
 
235
- ### การติดตามเหตุการณ์
213
+ Each engine can be used independently:
236
214
 
237
- ```typescript
238
- thinkingEngine.on('thinking_complete', (event) => {
239
- console.log(`Completed in ${event.data.processingTime}ms`);
240
- });
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
241
222
 
242
- thinkingEngine.on('search_complete', (event) => {
243
- console.log(`Found ${event.data.results.length} results`);
244
- });
223
+ ## Security
245
224
 
246
- thinkingEngine.on('analysis_complete', (event) => {
247
- console.log(`Analysis confidence: ${event.data.confidence}`);
248
- });
249
- ```
225
+ Version 2.0.0 includes significant security improvements:
250
226
 
251
- ## โครงสร้างโปรเจค
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
252
231
 
253
- ```
254
- sequential-thinking-system/
255
- ├── types.ts # Type definitions
256
- ├── search-discovery.ts # Search module
257
- ├── analysis.ts # Analysis module
258
- ├── reasoning.ts # Reasoning module
259
- ├── learning.ts # Learning module
260
- ├── planning.ts # Planning module
261
- ├── creativity.ts # Creativity module
262
- ├── engine.ts # Main engine
263
- ├── index.ts # Exports
264
- └── README.md # Documentation
265
- ```
232
+ ## Performance
266
233
 
267
- ## ตัวอย่าง 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
268
238
 
269
- ### 1. การวิจัยและรายงาน
239
+ ## Error Handling
270
240
 
271
241
  ```typescript
272
- const response = await thinkingEngine.deepAnalysis(
273
- 'Impact of remote work on productivity'
274
- );
275
- // ได้รับ: สรุปผลการวิจัย การวิเคราะห์ ข้อเสนอแนะ
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
+ }
276
253
  ```
277
254
 
278
- ### 2. การวางแผนโครงการ
255
+ ## Testing
279
256
 
280
- ```typescript
281
- const plan = await thinkingEngine.createPlan(
282
- 'Develop AI-powered chatbot',
283
- {
284
- resources: [developer, designer],
285
- deadline: new Date('2024-06-01')
286
- }
287
- );
288
- // ได้รับ: รายการงานย่อย ลำดับความสำคัญ ไทม์ไลน์
289
- ```
257
+ ```bash
258
+ # Run all tests
259
+ npm test
290
260
 
291
- ### 3. การแก้ปัญหาสร้างสรรค์
261
+ # Run with coverage
262
+ npm run test:coverage
292
263
 
293
- ```typescript
294
- const solution = await thinkingEngine.creativeSolve(
295
- 'Increase customer engagement'
296
- );
297
- // ได้รับ: ไอเดียใหม่ๆ มุมมองที่แตกต่าง แนวทางปฏิบัติ
264
+ # Run in watch mode
265
+ npm run test:watch
298
266
  ```
299
267
 
300
- ### 4. การตัดสินใจ
268
+ ## Contributing
301
269
 
302
- ```typescript
303
- const response = await thinkingEngine.think({
304
- query: 'Should we expand to Asian markets?',
305
- preferredStages: ['search', 'analysis', 'reasoning'],
306
- config: { reasoningComplexity: 'complex' }
307
- });
308
- // ได้รับ: การวิเคราะห์ การให้เหตุผล ข้อเสนอแนะ
309
- ```
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
310
279
 
311
- ## สิทธิ์การใช้งาน
280
+ ## Changelog
312
281
 
313
- 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.
314
286
 
315
- ## การมีส่วนร่วม
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.
316
292
 
317
- ยินดีรับ 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
318
303
 
319
- ## ติดต่อ
304
+ ## Support
320
305
 
321
- 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"}