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.
- package/.patches/0001-fix-repl-replace-readline-with-inquirer-input-for-ke.patch +279 -0
- package/.patches/0002-fix-repl-stream-AI-output-directly-to-stdout-so-term.patch +564 -0
- package/.patches/0003-fix-session-break-the-hallucination-loop-in-assistan.patch +194 -0
- package/.patches/0004-chore-release-bump-version-to-0.2.1.patch +24 -0
- package/LICENSE +21 -0
- package/README.md +100 -0
- package/ROADMAP.md +107 -0
- package/dist/agent/core.d.ts +56 -0
- package/dist/agent/core.d.ts.map +1 -0
- package/dist/agent/core.js +142 -0
- package/dist/agent/core.js.map +1 -0
- package/dist/agent/index.d.ts +8 -0
- package/dist/agent/index.d.ts.map +1 -0
- package/dist/agent/index.js +8 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/agent/intent.d.ts +36 -0
- package/dist/agent/intent.d.ts.map +1 -0
- package/dist/agent/intent.js +146 -0
- package/dist/agent/intent.js.map +1 -0
- package/dist/agent/streaming.d.ts +50 -0
- package/dist/agent/streaming.d.ts.map +1 -0
- package/dist/agent/streaming.js +110 -0
- package/dist/agent/streaming.js.map +1 -0
- package/dist/core/ai-engine.d.ts +59 -0
- package/dist/core/ai-engine.d.ts.map +1 -0
- package/dist/core/ai-engine.js +378 -0
- package/dist/core/ai-engine.js.map +1 -0
- package/dist/core/cli.d.ts +21 -0
- package/dist/core/cli.d.ts.map +1 -0
- package/dist/core/cli.js +143 -0
- package/dist/core/cli.js.map +1 -0
- package/dist/core/config.d.ts +38 -0
- package/dist/core/config.d.ts.map +1 -0
- package/dist/core/config.js +129 -0
- package/dist/core/config.js.map +1 -0
- package/dist/core/context-compactor.d.ts +54 -0
- package/dist/core/context-compactor.d.ts.map +1 -0
- package/dist/core/context-compactor.js +197 -0
- package/dist/core/context-compactor.js.map +1 -0
- package/dist/core/hooks.d.ts +75 -0
- package/dist/core/hooks.d.ts.map +1 -0
- package/dist/core/hooks.js +146 -0
- package/dist/core/hooks.js.map +1 -0
- package/dist/core/permissions.d.ts +52 -0
- package/dist/core/permissions.d.ts.map +1 -0
- package/dist/core/permissions.js +237 -0
- package/dist/core/permissions.js.map +1 -0
- package/dist/core/session.d.ts +54 -0
- package/dist/core/session.d.ts.map +1 -0
- package/dist/core/session.js +147 -0
- package/dist/core/session.js.map +1 -0
- package/dist/core/skills.d.ts +60 -0
- package/dist/core/skills.d.ts.map +1 -0
- package/dist/core/skills.js +175 -0
- package/dist/core/skills.js.map +1 -0
- package/dist/core/state.d.ts +60 -0
- package/dist/core/state.d.ts.map +1 -0
- package/dist/core/state.js +106 -0
- package/dist/core/state.js.map +1 -0
- package/dist/core/subagent.d.ts +68 -0
- package/dist/core/subagent.d.ts.map +1 -0
- package/dist/core/subagent.js +142 -0
- package/dist/core/subagent.js.map +1 -0
- package/dist/core/system-prompt.d.ts +40 -0
- package/dist/core/system-prompt.d.ts.map +1 -0
- package/dist/core/system-prompt.js +138 -0
- package/dist/core/system-prompt.js.map +1 -0
- package/dist/core/tool-registry.d.ts +53 -0
- package/dist/core/tool-registry.d.ts.map +1 -0
- package/dist/core/tool-registry.js +138 -0
- package/dist/core/tool-registry.js.map +1 -0
- package/dist/core/types.d.ts +206 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +127 -0
- package/dist/core/types.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +481 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/client.d.ts +83 -0
- package/dist/mcp/client.d.ts.map +1 -0
- package/dist/mcp/client.js +267 -0
- package/dist/mcp/client.js.map +1 -0
- package/dist/repl/index.d.ts +8 -0
- package/dist/repl/index.d.ts.map +1 -0
- package/dist/repl/index.js +8 -0
- package/dist/repl/index.js.map +1 -0
- package/dist/repl/input.d.ts +61 -0
- package/dist/repl/input.d.ts.map +1 -0
- package/dist/repl/input.js +127 -0
- package/dist/repl/input.js.map +1 -0
- package/dist/repl/loop.d.ts +53 -0
- package/dist/repl/loop.d.ts.map +1 -0
- package/dist/repl/loop.js +241 -0
- package/dist/repl/loop.js.map +1 -0
- package/dist/repl/output.d.ts +105 -0
- package/dist/repl/output.d.ts.map +1 -0
- package/dist/repl/output.js +197 -0
- package/dist/repl/output.js.map +1 -0
- package/dist/repl/welcome.d.ts +68 -0
- package/dist/repl/welcome.d.ts.map +1 -0
- package/dist/repl/welcome.js +249 -0
- package/dist/repl/welcome.js.map +1 -0
- package/dist/tools/file.d.ts +46 -0
- package/dist/tools/file.d.ts.map +1 -0
- package/dist/tools/file.js +100 -0
- package/dist/tools/file.js.map +1 -0
- package/dist/tools/git.d.ts +52 -0
- package/dist/tools/git.d.ts.map +1 -0
- package/dist/tools/git.js +112 -0
- package/dist/tools/git.js.map +1 -0
- package/dist/tools/index.d.ts +22 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +43 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/search.d.ts +36 -0
- package/dist/tools/search.d.ts.map +1 -0
- package/dist/tools/search.js +223 -0
- package/dist/tools/search.js.map +1 -0
- package/dist/tools/shell.d.ts +57 -0
- package/dist/tools/shell.d.ts.map +1 -0
- package/dist/tools/shell.js +153 -0
- package/dist/tools/shell.js.map +1 -0
- package/dist/utils/diff-preview.d.ts +42 -0
- package/dist/utils/diff-preview.d.ts.map +1 -0
- package/dist/utils/diff-preview.js +174 -0
- package/dist/utils/diff-preview.js.map +1 -0
- package/dist/utils/index.d.ts +8 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +8 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/memory.d.ts +81 -0
- package/dist/utils/memory.d.ts.map +1 -0
- package/dist/utils/memory.js +186 -0
- package/dist/utils/memory.js.map +1 -0
- package/dist/utils/project-context.d.ts +62 -0
- package/dist/utils/project-context.d.ts.map +1 -0
- package/dist/utils/project-context.js +197 -0
- package/dist/utils/project-context.js.map +1 -0
- package/docs/API_KEY_GUIDE.md +236 -0
- package/docs/FAQ.md +182 -0
- package/install.bat +63 -0
- package/install.ps1 +238 -0
- package/install.sh +113 -0
- package/package.json +36 -0
- package/src/agent/core.ts +179 -0
- package/src/agent/index.ts +8 -0
- package/src/agent/intent.ts +181 -0
- package/src/agent/streaming.ts +132 -0
- package/src/core/ai-engine.ts +437 -0
- package/src/core/cli.ts +171 -0
- package/src/core/config.ts +147 -0
- package/src/core/context-compactor.ts +245 -0
- package/src/core/hooks.ts +196 -0
- package/src/core/permissions.ts +308 -0
- package/src/core/session.ts +165 -0
- package/src/core/skills.ts +208 -0
- package/src/core/state.ts +120 -0
- package/src/core/subagent.ts +195 -0
- package/src/core/system-prompt.ts +163 -0
- package/src/core/tool-registry.ts +157 -0
- package/src/core/types.ts +280 -0
- package/src/index.ts +544 -0
- package/src/mcp/client.ts +330 -0
- package/src/repl/index.ts +8 -0
- package/src/repl/input.ts +139 -0
- package/src/repl/loop.ts +280 -0
- package/src/repl/output.ts +222 -0
- package/src/repl/welcome.ts +296 -0
- package/src/tools/file.ts +117 -0
- package/src/tools/git.ts +132 -0
- package/src/tools/index.ts +48 -0
- package/src/tools/search.ts +263 -0
- package/src/tools/shell.ts +181 -0
- package/src/utils/diff-preview.ts +202 -0
- package/src/utils/index.ts +8 -0
- package/src/utils/memory.ts +223 -0
- package/src/utils/project-context.ts +207 -0
- package/tsconfig.json +19 -0
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for Thatgfsj Code
|
|
3
|
+
* S02: Enhanced Tool interface with Builder pattern, inputSchema, and metadata
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export type Role = 'system' | 'user' | 'assistant' | 'tool';
|
|
7
|
+
|
|
8
|
+
export interface ChatMessage {
|
|
9
|
+
role: Role;
|
|
10
|
+
content: string;
|
|
11
|
+
name?: string;
|
|
12
|
+
tool_calls?: ToolCall[];
|
|
13
|
+
tool_call_id?: string;
|
|
14
|
+
reasoning_content?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface ToolCall {
|
|
18
|
+
id: string;
|
|
19
|
+
type: 'function';
|
|
20
|
+
function: {
|
|
21
|
+
name: string;
|
|
22
|
+
arguments: string;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface AIResponse {
|
|
27
|
+
content: string;
|
|
28
|
+
role: 'assistant';
|
|
29
|
+
usage?: {
|
|
30
|
+
prompt_tokens: number;
|
|
31
|
+
completion_tokens: number;
|
|
32
|
+
total_tokens: number;
|
|
33
|
+
};
|
|
34
|
+
tool_calls?: ToolCall[];
|
|
35
|
+
reasoning_content?: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface AIConfig {
|
|
39
|
+
model: string;
|
|
40
|
+
apiKey?: string;
|
|
41
|
+
temperature?: number;
|
|
42
|
+
maxTokens?: number;
|
|
43
|
+
baseUrl?: string;
|
|
44
|
+
provider?: 'minimax' | 'openai' | 'siliconflow' | 'anthropic' | 'ollama' | 'custom' | 'gemini' | 'kimi' | 'deepseek' | 'ernie';
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// ==================== S02: Enhanced Tool Interface ====================
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Tool parameter with type support
|
|
51
|
+
*/
|
|
52
|
+
export interface ToolParameter {
|
|
53
|
+
name: string;
|
|
54
|
+
type: string;
|
|
55
|
+
description: string;
|
|
56
|
+
required: boolean;
|
|
57
|
+
default?: any;
|
|
58
|
+
enum?: string[];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* S02: Input Schema — JSON Schema style tool input definition
|
|
63
|
+
* Claude Code uses this for structured tool parameter validation
|
|
64
|
+
*/
|
|
65
|
+
export interface ToolInputSchema {
|
|
66
|
+
type: 'object';
|
|
67
|
+
properties: Record<string, {
|
|
68
|
+
type: string;
|
|
69
|
+
description: string;
|
|
70
|
+
default?: any;
|
|
71
|
+
enum?: string[];
|
|
72
|
+
}>;
|
|
73
|
+
required?: string[];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* S02: Tool metadata — extra info beyond name/description
|
|
78
|
+
*/
|
|
79
|
+
export interface ToolMetadata {
|
|
80
|
+
/** Permission category: read, write, execute, network */
|
|
81
|
+
permissions?: ('read' | 'write' | 'execute' | 'network')[];
|
|
82
|
+
/** Max execution time in ms */
|
|
83
|
+
maxDuration?: number;
|
|
84
|
+
/** Tags for categorization */
|
|
85
|
+
tags?: string[];
|
|
86
|
+
/** Version */
|
|
87
|
+
version?: string;
|
|
88
|
+
/** Deprecation notice */
|
|
89
|
+
deprecated?: string;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* S02: Tool interface with inputSchema + metadata
|
|
94
|
+
* Both 'parameters' (legacy) and 'inputSchema' (new) are supported
|
|
95
|
+
*/
|
|
96
|
+
export interface Tool {
|
|
97
|
+
name: string;
|
|
98
|
+
description: string;
|
|
99
|
+
/** Legacy parameter list (still used by existing tools) */
|
|
100
|
+
parameters: ToolParameter[];
|
|
101
|
+
/** S02: JSON Schema for tool input (computed from parameters) */
|
|
102
|
+
inputSchema?: ToolInputSchema;
|
|
103
|
+
/** S02: Metadata for permissions, tags, etc. */
|
|
104
|
+
metadata?: ToolMetadata;
|
|
105
|
+
execute(params: Record<string, any>, ctx?: ToolContext): Promise<ToolResult>;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* S02: Enriched execution context
|
|
110
|
+
*/
|
|
111
|
+
export interface ToolContext {
|
|
112
|
+
sessionId?: string;
|
|
113
|
+
workingDirectory?: string;
|
|
114
|
+
confirmAction?: (msg: string) => Promise<boolean>;
|
|
115
|
+
signal?: AbortSignal;
|
|
116
|
+
toolCallId?: string;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Legacy alias
|
|
120
|
+
export { ToolParameter as ToolParam };
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* S02: Tool Builder — fluent API to construct tools
|
|
124
|
+
*/
|
|
125
|
+
export class ToolBuilder {
|
|
126
|
+
private _name = '';
|
|
127
|
+
private _description = '';
|
|
128
|
+
private _parameters: ToolParameter[] = [];
|
|
129
|
+
private _inputSchema: ToolInputSchema = { type: 'object', properties: {} };
|
|
130
|
+
private _metadata: ToolMetadata = {};
|
|
131
|
+
private _fn?: (params: Record<string, any>, ctx: ToolContext) => Promise<ToolResult>;
|
|
132
|
+
|
|
133
|
+
name(n: string): this { this._name = n; return this; }
|
|
134
|
+
description(d: string): this { this._description = d; return this; }
|
|
135
|
+
|
|
136
|
+
param(p: ToolParameter): this {
|
|
137
|
+
this._parameters.push(p);
|
|
138
|
+
this._inputSchema.properties[p.name] = {
|
|
139
|
+
type: p.type,
|
|
140
|
+
description: p.description,
|
|
141
|
+
default: p.default,
|
|
142
|
+
enum: p.enum
|
|
143
|
+
};
|
|
144
|
+
return this;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
stringParam(name: string, description: string, required = true, defaultVal?: string): this {
|
|
148
|
+
return this.param({ name, type: 'string', description, required, default: defaultVal });
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
numberParam(name: string, description: string, required = true, defaultVal?: number): this {
|
|
152
|
+
return this.param({ name, type: 'number', description, required, default: defaultVal });
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
booleanParam(name: string, description: string, required: boolean = false, defaultVal?: boolean): this {
|
|
156
|
+
return this.param({ name, type: 'boolean', description, required, default: defaultVal });
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
required(...names: string[]): this {
|
|
160
|
+
this._inputSchema.required = names;
|
|
161
|
+
return this;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
meta(m: ToolMetadata): this {
|
|
165
|
+
this._metadata = { ...this._metadata, ...m };
|
|
166
|
+
return this;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
permissions(...perms: ('read' | 'write' | 'execute' | 'network')[]): this {
|
|
170
|
+
this._metadata.permissions = perms;
|
|
171
|
+
return this;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
tags(...t: string[]): this {
|
|
175
|
+
this._metadata.tags = t;
|
|
176
|
+
return this;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
handle(fn: (params: Record<string, any>, ctx: ToolContext) => Promise<ToolResult>): this {
|
|
180
|
+
this._fn = fn;
|
|
181
|
+
return this;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
build(): Tool {
|
|
185
|
+
if (!this._name || !this._fn) {
|
|
186
|
+
throw new Error('Tool name and handler are required');
|
|
187
|
+
}
|
|
188
|
+
return {
|
|
189
|
+
name: this._name,
|
|
190
|
+
description: this._description,
|
|
191
|
+
parameters: this._parameters,
|
|
192
|
+
inputSchema: this._inputSchema,
|
|
193
|
+
metadata: this._metadata,
|
|
194
|
+
execute: this._fn
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// ==================== Tool Registry Enhancement ====================
|
|
200
|
+
|
|
201
|
+
export interface ToolResult {
|
|
202
|
+
success: boolean;
|
|
203
|
+
output?: string;
|
|
204
|
+
error?: string;
|
|
205
|
+
data?: any;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export interface Session {
|
|
209
|
+
id: string;
|
|
210
|
+
messages: ChatMessage[];
|
|
211
|
+
createdAt: Date;
|
|
212
|
+
lastActiveAt: Date;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export interface Config {
|
|
216
|
+
model: string;
|
|
217
|
+
apiKey: string;
|
|
218
|
+
temperature: number;
|
|
219
|
+
maxTokens: number;
|
|
220
|
+
provider?: 'minimax' | 'openai' | 'siliconflow' | 'anthropic' | 'ollama' | 'custom' | 'gemini' | 'kimi' | 'deepseek' | 'ernie';
|
|
221
|
+
baseUrl?: string;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// Provider configurations
|
|
225
|
+
export const PROVIDERS = {
|
|
226
|
+
minimax: {
|
|
227
|
+
name: 'MiniMax',
|
|
228
|
+
baseUrl: 'https://api.minimax.io/anthropic/v1',
|
|
229
|
+
defaultModel: 'MiniMax-M2.5',
|
|
230
|
+
envKeys: ['MINIMAX_API_KEY', 'OPENAI_API_KEY']
|
|
231
|
+
},
|
|
232
|
+
siliconflow: {
|
|
233
|
+
name: 'SiliconFlow (硅基流动)',
|
|
234
|
+
baseUrl: 'https://api.siliconflow.cn/v1',
|
|
235
|
+
defaultModel: 'Qwen/Qwen2.5-7B-Instruct',
|
|
236
|
+
envKeys: ['SILICONFLOW_API_KEY', 'OPENAI_API_KEY']
|
|
237
|
+
},
|
|
238
|
+
openai: {
|
|
239
|
+
name: 'OpenAI',
|
|
240
|
+
baseUrl: 'https://api.openai.com/v1',
|
|
241
|
+
defaultModel: 'gpt-4o-mini',
|
|
242
|
+
envKeys: ['OPENAI_API_KEY']
|
|
243
|
+
},
|
|
244
|
+
anthropic: {
|
|
245
|
+
name: 'Anthropic',
|
|
246
|
+
baseUrl: 'https://api.anthropic.com/v1',
|
|
247
|
+
defaultModel: 'claude-3-haiku-20240307',
|
|
248
|
+
envKeys: ['ANTHROPIC_API_KEY']
|
|
249
|
+
},
|
|
250
|
+
ollama: {
|
|
251
|
+
name: 'Ollama (Local)',
|
|
252
|
+
baseUrl: process.env.OLLAMA_BASE_URL || 'http://localhost:11434',
|
|
253
|
+
defaultModel: 'llama2',
|
|
254
|
+
envKeys: []
|
|
255
|
+
},
|
|
256
|
+
gemini: {
|
|
257
|
+
name: 'Google Gemini',
|
|
258
|
+
baseUrl: 'https://generativelanguage.googleapis.com/v1beta',
|
|
259
|
+
defaultModel: 'gemini-1.5-flash',
|
|
260
|
+
envKeys: ['GEMINI_API_KEY']
|
|
261
|
+
},
|
|
262
|
+
kimi: {
|
|
263
|
+
name: 'Kimi (Moonshot AI)',
|
|
264
|
+
baseUrl: 'https://api.moonshot.cn/v1',
|
|
265
|
+
defaultModel: 'moonshot-v1-8k',
|
|
266
|
+
envKeys: ['KIMI_API_KEY', 'MOONSHOT_API_KEY']
|
|
267
|
+
},
|
|
268
|
+
deepseek: {
|
|
269
|
+
name: 'DeepSeek',
|
|
270
|
+
baseUrl: 'https://api.deepseek.com/v1',
|
|
271
|
+
defaultModel: 'deepseek-chat',
|
|
272
|
+
envKeys: ['DEEPSEEK_API_KEY']
|
|
273
|
+
},
|
|
274
|
+
ernie: {
|
|
275
|
+
name: 'Baidu ERNIE (文心一言)',
|
|
276
|
+
baseUrl: 'https://aip.baidubce.com/rpc/2.0/ai_custom/v1',
|
|
277
|
+
defaultModel: 'ernie-4.0-8k',
|
|
278
|
+
envKeys: ['ERNIE_API_KEY', 'BAIDU_API_KEY']
|
|
279
|
+
}
|
|
280
|
+
} as const;
|