thatgfsj-code 0.2.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 (179) hide show
  1. package/.patches/0001-fix-repl-replace-readline-with-inquirer-input-for-ke.patch +279 -0
  2. package/.patches/0002-fix-repl-stream-AI-output-directly-to-stdout-so-term.patch +564 -0
  3. package/.patches/0003-fix-session-break-the-hallucination-loop-in-assistan.patch +194 -0
  4. package/.patches/0004-chore-release-bump-version-to-0.2.1.patch +24 -0
  5. package/LICENSE +21 -0
  6. package/README.md +100 -0
  7. package/ROADMAP.md +107 -0
  8. package/dist/agent/core.d.ts +56 -0
  9. package/dist/agent/core.d.ts.map +1 -0
  10. package/dist/agent/core.js +142 -0
  11. package/dist/agent/core.js.map +1 -0
  12. package/dist/agent/index.d.ts +8 -0
  13. package/dist/agent/index.d.ts.map +1 -0
  14. package/dist/agent/index.js +8 -0
  15. package/dist/agent/index.js.map +1 -0
  16. package/dist/agent/intent.d.ts +36 -0
  17. package/dist/agent/intent.d.ts.map +1 -0
  18. package/dist/agent/intent.js +146 -0
  19. package/dist/agent/intent.js.map +1 -0
  20. package/dist/agent/streaming.d.ts +50 -0
  21. package/dist/agent/streaming.d.ts.map +1 -0
  22. package/dist/agent/streaming.js +110 -0
  23. package/dist/agent/streaming.js.map +1 -0
  24. package/dist/core/ai-engine.d.ts +59 -0
  25. package/dist/core/ai-engine.d.ts.map +1 -0
  26. package/dist/core/ai-engine.js +378 -0
  27. package/dist/core/ai-engine.js.map +1 -0
  28. package/dist/core/cli.d.ts +21 -0
  29. package/dist/core/cli.d.ts.map +1 -0
  30. package/dist/core/cli.js +143 -0
  31. package/dist/core/cli.js.map +1 -0
  32. package/dist/core/config.d.ts +38 -0
  33. package/dist/core/config.d.ts.map +1 -0
  34. package/dist/core/config.js +129 -0
  35. package/dist/core/config.js.map +1 -0
  36. package/dist/core/context-compactor.d.ts +54 -0
  37. package/dist/core/context-compactor.d.ts.map +1 -0
  38. package/dist/core/context-compactor.js +197 -0
  39. package/dist/core/context-compactor.js.map +1 -0
  40. package/dist/core/hooks.d.ts +75 -0
  41. package/dist/core/hooks.d.ts.map +1 -0
  42. package/dist/core/hooks.js +146 -0
  43. package/dist/core/hooks.js.map +1 -0
  44. package/dist/core/permissions.d.ts +52 -0
  45. package/dist/core/permissions.d.ts.map +1 -0
  46. package/dist/core/permissions.js +237 -0
  47. package/dist/core/permissions.js.map +1 -0
  48. package/dist/core/session.d.ts +54 -0
  49. package/dist/core/session.d.ts.map +1 -0
  50. package/dist/core/session.js +147 -0
  51. package/dist/core/session.js.map +1 -0
  52. package/dist/core/skills.d.ts +60 -0
  53. package/dist/core/skills.d.ts.map +1 -0
  54. package/dist/core/skills.js +175 -0
  55. package/dist/core/skills.js.map +1 -0
  56. package/dist/core/state.d.ts +60 -0
  57. package/dist/core/state.d.ts.map +1 -0
  58. package/dist/core/state.js +106 -0
  59. package/dist/core/state.js.map +1 -0
  60. package/dist/core/subagent.d.ts +68 -0
  61. package/dist/core/subagent.d.ts.map +1 -0
  62. package/dist/core/subagent.js +142 -0
  63. package/dist/core/subagent.js.map +1 -0
  64. package/dist/core/system-prompt.d.ts +40 -0
  65. package/dist/core/system-prompt.d.ts.map +1 -0
  66. package/dist/core/system-prompt.js +138 -0
  67. package/dist/core/system-prompt.js.map +1 -0
  68. package/dist/core/tool-registry.d.ts +53 -0
  69. package/dist/core/tool-registry.d.ts.map +1 -0
  70. package/dist/core/tool-registry.js +138 -0
  71. package/dist/core/tool-registry.js.map +1 -0
  72. package/dist/core/types.d.ts +206 -0
  73. package/dist/core/types.d.ts.map +1 -0
  74. package/dist/core/types.js +127 -0
  75. package/dist/core/types.js.map +1 -0
  76. package/dist/index.d.ts +7 -0
  77. package/dist/index.d.ts.map +1 -0
  78. package/dist/index.js +481 -0
  79. package/dist/index.js.map +1 -0
  80. package/dist/mcp/client.d.ts +83 -0
  81. package/dist/mcp/client.d.ts.map +1 -0
  82. package/dist/mcp/client.js +267 -0
  83. package/dist/mcp/client.js.map +1 -0
  84. package/dist/repl/index.d.ts +8 -0
  85. package/dist/repl/index.d.ts.map +1 -0
  86. package/dist/repl/index.js +8 -0
  87. package/dist/repl/index.js.map +1 -0
  88. package/dist/repl/input.d.ts +61 -0
  89. package/dist/repl/input.d.ts.map +1 -0
  90. package/dist/repl/input.js +127 -0
  91. package/dist/repl/input.js.map +1 -0
  92. package/dist/repl/loop.d.ts +53 -0
  93. package/dist/repl/loop.d.ts.map +1 -0
  94. package/dist/repl/loop.js +241 -0
  95. package/dist/repl/loop.js.map +1 -0
  96. package/dist/repl/output.d.ts +105 -0
  97. package/dist/repl/output.d.ts.map +1 -0
  98. package/dist/repl/output.js +197 -0
  99. package/dist/repl/output.js.map +1 -0
  100. package/dist/repl/welcome.d.ts +68 -0
  101. package/dist/repl/welcome.d.ts.map +1 -0
  102. package/dist/repl/welcome.js +249 -0
  103. package/dist/repl/welcome.js.map +1 -0
  104. package/dist/tools/file.d.ts +46 -0
  105. package/dist/tools/file.d.ts.map +1 -0
  106. package/dist/tools/file.js +100 -0
  107. package/dist/tools/file.js.map +1 -0
  108. package/dist/tools/git.d.ts +52 -0
  109. package/dist/tools/git.d.ts.map +1 -0
  110. package/dist/tools/git.js +112 -0
  111. package/dist/tools/git.js.map +1 -0
  112. package/dist/tools/index.d.ts +22 -0
  113. package/dist/tools/index.d.ts.map +1 -0
  114. package/dist/tools/index.js +43 -0
  115. package/dist/tools/index.js.map +1 -0
  116. package/dist/tools/search.d.ts +36 -0
  117. package/dist/tools/search.d.ts.map +1 -0
  118. package/dist/tools/search.js +223 -0
  119. package/dist/tools/search.js.map +1 -0
  120. package/dist/tools/shell.d.ts +57 -0
  121. package/dist/tools/shell.d.ts.map +1 -0
  122. package/dist/tools/shell.js +153 -0
  123. package/dist/tools/shell.js.map +1 -0
  124. package/dist/utils/diff-preview.d.ts +42 -0
  125. package/dist/utils/diff-preview.d.ts.map +1 -0
  126. package/dist/utils/diff-preview.js +174 -0
  127. package/dist/utils/diff-preview.js.map +1 -0
  128. package/dist/utils/index.d.ts +8 -0
  129. package/dist/utils/index.d.ts.map +1 -0
  130. package/dist/utils/index.js +8 -0
  131. package/dist/utils/index.js.map +1 -0
  132. package/dist/utils/memory.d.ts +81 -0
  133. package/dist/utils/memory.d.ts.map +1 -0
  134. package/dist/utils/memory.js +186 -0
  135. package/dist/utils/memory.js.map +1 -0
  136. package/dist/utils/project-context.d.ts +62 -0
  137. package/dist/utils/project-context.d.ts.map +1 -0
  138. package/dist/utils/project-context.js +197 -0
  139. package/dist/utils/project-context.js.map +1 -0
  140. package/docs/API_KEY_GUIDE.md +236 -0
  141. package/docs/FAQ.md +182 -0
  142. package/install.bat +63 -0
  143. package/install.ps1 +238 -0
  144. package/install.sh +113 -0
  145. package/package.json +36 -0
  146. package/src/agent/core.ts +179 -0
  147. package/src/agent/index.ts +8 -0
  148. package/src/agent/intent.ts +181 -0
  149. package/src/agent/streaming.ts +132 -0
  150. package/src/core/ai-engine.ts +437 -0
  151. package/src/core/cli.ts +171 -0
  152. package/src/core/config.ts +147 -0
  153. package/src/core/context-compactor.ts +245 -0
  154. package/src/core/hooks.ts +196 -0
  155. package/src/core/permissions.ts +308 -0
  156. package/src/core/session.ts +165 -0
  157. package/src/core/skills.ts +208 -0
  158. package/src/core/state.ts +120 -0
  159. package/src/core/subagent.ts +195 -0
  160. package/src/core/system-prompt.ts +163 -0
  161. package/src/core/tool-registry.ts +157 -0
  162. package/src/core/types.ts +280 -0
  163. package/src/index.ts +544 -0
  164. package/src/mcp/client.ts +330 -0
  165. package/src/repl/index.ts +8 -0
  166. package/src/repl/input.ts +139 -0
  167. package/src/repl/loop.ts +280 -0
  168. package/src/repl/output.ts +222 -0
  169. package/src/repl/welcome.ts +296 -0
  170. package/src/tools/file.ts +117 -0
  171. package/src/tools/git.ts +132 -0
  172. package/src/tools/index.ts +48 -0
  173. package/src/tools/search.ts +263 -0
  174. package/src/tools/shell.ts +181 -0
  175. package/src/utils/diff-preview.ts +202 -0
  176. package/src/utils/index.ts +8 -0
  177. package/src/utils/memory.ts +223 -0
  178. package/src/utils/project-context.ts +207 -0
  179. package/tsconfig.json +19 -0
@@ -0,0 +1,181 @@
1
+ /**
2
+ * Intent Recognition
3
+ * Identifies user intent: chat, code, command, or query
4
+ */
5
+
6
+ export interface Intent {
7
+ type: 'chat' | 'code' | 'command' | 'query' | 'complex';
8
+ confidence: number;
9
+ reason?: string;
10
+ subTasks?: SubTask[];
11
+ }
12
+
13
+ export interface SubTask {
14
+ description: string;
15
+ action: string;
16
+ target?: string;
17
+ }
18
+
19
+ /**
20
+ * Intent Recognition Prompt
21
+ */
22
+ const INTENT_PROMPT = `Analyze the user message and identify their intent.
23
+
24
+ Intent types:
25
+ - "chat": General conversation, questions, small talk
26
+ - "code": Write, edit, refactor code
27
+ - "command": Execute shell commands, git operations
28
+ - "query": Search files, find information, read code
29
+ - "complex": Multiple actions needed - break into subtasks
30
+
31
+ Respond with JSON:
32
+ {
33
+ "type": "chat|code|command|query|complex",
34
+ "confidence": 0.0-1.0,
35
+ "reason": "brief explanation",
36
+ "subTasks": [{"description": "...", "action": "...", "target": "..."}] // only for complex
37
+ }
38
+
39
+ User message:`;
40
+
41
+ export class IntentRecognizer {
42
+ private ai: any;
43
+
44
+ constructor(aiEngine: any) {
45
+ this.ai = aiEngine;
46
+ }
47
+
48
+ /**
49
+ * Recognize intent from user message
50
+ */
51
+ async recognize(message: string): Promise<Intent> {
52
+ // Fast path: simple keyword matching for common patterns
53
+ const fastIntent = this.fastRecognize(message);
54
+ if (fastIntent.confidence > 0.8) {
55
+ return fastIntent;
56
+ }
57
+
58
+ // Use AI for complex cases
59
+ return await this.aiRecognize(message);
60
+ }
61
+
62
+ /**
63
+ * Fast keyword-based recognition
64
+ */
65
+ private fastRecognize(message: string): Intent {
66
+ const lower = message.toLowerCase().trim();
67
+ const words = lower.split(/\s+/);
68
+
69
+ // Command patterns
70
+ const commandPatterns = [
71
+ /^run\s+/, /^execute\s+/, /^exec\s+/,
72
+ /^npm\s+/, /^node\s+/, /^git\s+/,
73
+ /^pip\s+/, /^python\s+/, /^cargo\s+/,
74
+ /^make\s+/, /^docker\s+/, /^curl\s+/,
75
+ ];
76
+
77
+ for (const pattern of commandPatterns) {
78
+ if (pattern.test(lower)) {
79
+ return { type: 'command', confidence: 0.9, reason: 'Command pattern detected' };
80
+ }
81
+ }
82
+
83
+ // Code patterns
84
+ const codePatterns = [
85
+ /^write\s+/, /^create\s+.*file/i,
86
+ /^edit\s+/, /^modify\s+/, /^change\s+/,
87
+ /^refactor/i, /^implement/i,
88
+ /^add\s+.*function/i, /^add\s+.*class/i,
89
+ /\{[\s\S]*\}/, // Contains code block
90
+ /function\s+\w+\s*\(/,
91
+ /const\s+\w+\s*=/,
92
+ /let\s+\w+\s*=/,
93
+ /class\s+\w+/,
94
+ ];
95
+
96
+ for (const pattern of codePatterns) {
97
+ if (pattern.test(message)) {
98
+ return { type: 'code', confidence: 0.85, reason: 'Code pattern detected' };
99
+ }
100
+ }
101
+
102
+ // Query patterns
103
+ const queryPatterns = [
104
+ /^find\s+/, /^search\s+/, /^grep\s+/,
105
+ /^show\s+.*files/i, /^list\s+.*files/i,
106
+ /^what\s+is\s+/, /^how\s+does\s+/,
107
+ /^explain\s+/, /^what's\s+in\s+/,
108
+ /^read\s+/, /^look\s+at\s+/,
109
+ ];
110
+
111
+ for (const pattern of queryPatterns) {
112
+ if (pattern.test(lower)) {
113
+ return { type: 'query', confidence: 0.85, reason: 'Query pattern detected' };
114
+ }
115
+ }
116
+
117
+ // Complex task patterns (multiple actions)
118
+ const complexPatterns = [
119
+ /refactor.*and.*test/i,
120
+ /create.*and.*setup/i,
121
+ /build.*and.*deploy/i,
122
+ /fix.*and.*verify/i,
123
+ /migrate.*to/i,
124
+ /rewrite.*from/i,
125
+ ];
126
+
127
+ for (const pattern of complexPatterns) {
128
+ if (pattern.test(lower)) {
129
+ return { type: 'complex', confidence: 0.8, reason: 'Multiple actions detected' };
130
+ }
131
+ }
132
+
133
+ // Default to chat
134
+ return { type: 'chat', confidence: 0.6, reason: 'Default intent' };
135
+ }
136
+
137
+ /**
138
+ * AI-powered recognition for ambiguous cases
139
+ */
140
+ private async aiRecognize(message: string): Promise<Intent> {
141
+ // For now, use fast recognition as fallback
142
+ // TODO: Implement AI-based recognition for complex cases
143
+ return this.fastRecognize(message);
144
+ }
145
+
146
+ /**
147
+ * Break complex task into subtasks
148
+ */
149
+ async breakIntoSubtasks(message: string): Promise<SubTask[]> {
150
+ const lower = message.toLowerCase();
151
+
152
+ // Simple rule-based decomposition
153
+ const tasks: SubTask[] = [];
154
+
155
+ // "refactor X and add tests"
156
+ if (lower.includes('refactor') && lower.includes('test')) {
157
+ tasks.push({ description: 'Refactor code', action: 'code', target: 'refactor' });
158
+ tasks.push({ description: 'Add tests', action: 'code', target: 'test' });
159
+ }
160
+
161
+ // "create X and setup Y"
162
+ if (lower.includes('create') && lower.includes('setup')) {
163
+ tasks.push({ description: 'Create component', action: 'code', target: 'create' });
164
+ tasks.push({ description: 'Setup configuration', action: 'command', target: 'setup' });
165
+ }
166
+
167
+ // "fix X and verify"
168
+ if (lower.includes('fix') && (lower.includes('verify') || lower.includes('test'))) {
169
+ tasks.push({ description: 'Fix issue', action: 'code', target: 'fix' });
170
+ tasks.push({ description: 'Verify fix', action: 'command', target: 'test' });
171
+ }
172
+
173
+ // If no decomposition rules matched, treat as single task
174
+ if (tasks.length === 0) {
175
+ const intent = this.fastRecognize(message);
176
+ tasks.push({ description: message, action: intent.type, target: message });
177
+ }
178
+
179
+ return tasks;
180
+ }
181
+ }
@@ -0,0 +1,132 @@
1
+ /**
2
+ * Streaming Output
3
+ * Handles real-time streaming output with typewriter effect
4
+ */
5
+
6
+ import chalk from 'chalk';
7
+
8
+ export type StreamCallback = (chunk: string) => void;
9
+ export type DoneCallback = (full: string) => void;
10
+
11
+ export class StreamingOutput {
12
+ private fullContent: string = '';
13
+ private isStreaming: boolean = false;
14
+ private onChunk?: StreamCallback;
15
+ private onDone?: DoneCallback;
16
+ private buffer: string = '';
17
+ private minChunkDelay: number = 10; // ms between chunks
18
+
19
+ /**
20
+ * Start streaming mode
21
+ */
22
+ start(callbacks?: { onChunk?: StreamCallback; onDone?: DoneCallback }): void {
23
+ this.fullContent = '';
24
+ this.isStreaming = true;
25
+ this.onChunk = callbacks?.onChunk;
26
+ this.onDone = callbacks?.onDone;
27
+ }
28
+
29
+ /**
30
+ * Process a chunk of content
31
+ */
32
+ processChunk(chunk: string): void {
33
+ if (!this.isStreaming) return;
34
+
35
+ this.fullContent += chunk;
36
+ this.buffer += chunk;
37
+
38
+ // Flush buffer periodically
39
+ if (this.buffer.length > 0) {
40
+ const toPrint = this.buffer;
41
+ this.buffer = '';
42
+
43
+ if (this.onChunk) {
44
+ this.onChunk(toPrint);
45
+ } else {
46
+ process.stdout.write(toPrint);
47
+ }
48
+ }
49
+ }
50
+
51
+ /**
52
+ * End streaming mode
53
+ */
54
+ end(): string {
55
+ this.isStreaming = false;
56
+
57
+ // Flush remaining buffer
58
+ if (this.buffer.length > 0) {
59
+ if (this.onChunk) {
60
+ this.onChunk(this.buffer);
61
+ } else {
62
+ process.stdout.write(this.buffer);
63
+ }
64
+ this.buffer = '';
65
+ }
66
+
67
+ if (this.onDone) {
68
+ this.onDone(this.fullContent);
69
+ }
70
+
71
+ return this.fullContent;
72
+ }
73
+
74
+ /**
75
+ * Stop streaming (for interrupt)
76
+ */
77
+ stop(): string {
78
+ this.isStreaming = false;
79
+ return this.fullContent;
80
+ }
81
+
82
+ /**
83
+ * Get full content so far
84
+ */
85
+ getContent(): string {
86
+ return this.fullContent;
87
+ }
88
+
89
+ /**
90
+ * Check if streaming
91
+ */
92
+ isActive(): boolean {
93
+ return this.isStreaming;
94
+ }
95
+
96
+ /**
97
+ * Print with typewriter effect (for interactive mode)
98
+ */
99
+ static async typewriter(
100
+ text: string,
101
+ delay: number = 20,
102
+ onChunk?: (chunk: string) => void
103
+ ): Promise<void> {
104
+ for (let i = 0; i < text.length; i++) {
105
+ process.stdout.write(text[i]);
106
+ if (onChunk) onChunk(text[i]);
107
+ await new Promise(r => setTimeout(r, delay));
108
+ }
109
+ }
110
+
111
+ /**
112
+ * Print code block with syntax highlighting hint
113
+ */
114
+ static printCodeBlock(code: string, language: string = ''): void {
115
+ const lines = code.split('\n');
116
+ const maxLen = Math.max(...lines.map(l => l.length), 60);
117
+
118
+ console.log(chalk.bgBlack.gray('┌' + '─'.repeat(Math.min(maxLen, 80)) + '┐'));
119
+
120
+ if (language) {
121
+ console.log(chalk.bgBlack.gray('│ ') + chalk.cyan(language) + chalk.bgBlack.gray(' '.repeat(Math.max(0, maxLen - language.length - 1))) + chalk.bgBlack.gray('│'));
122
+ console.log(chalk.bgBlack.gray('├' + '─'.repeat(Math.min(maxLen, 80)) + '┤'));
123
+ }
124
+
125
+ for (const line of lines) {
126
+ const displayLine = line.length > maxLen ? line.substring(0, maxLen - 3) + '...' : line;
127
+ console.log(chalk.bgBlack('│ ') + displayLine + ' '.repeat(Math.max(0, maxLen - displayLine.length)) + chalk.bgBlack(' │'));
128
+ }
129
+
130
+ console.log(chalk.bgBlack.gray('└' + '─'.repeat(Math.min(maxLen, 80)) + '┘'));
131
+ }
132
+ }