thatgfsj-code 0.4.1 → 0.6.0

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 (94) hide show
  1. package/README.md +7 -12
  2. package/dist/app/index.d.ts +6 -14
  3. package/dist/app/index.d.ts.map +1 -1
  4. package/dist/app/index.js +29 -31
  5. package/dist/app/index.js.map +1 -1
  6. package/dist/cmd/index.d.ts +1 -2
  7. package/dist/cmd/index.d.ts.map +1 -1
  8. package/dist/cmd/index.js +58 -47
  9. package/dist/cmd/index.js.map +1 -1
  10. package/dist/config/index.d.ts.map +1 -1
  11. package/dist/config/index.js +1 -0
  12. package/dist/config/index.js.map +1 -1
  13. package/dist/config/types.d.ts +1 -0
  14. package/dist/config/types.d.ts.map +1 -1
  15. package/dist/llm/index.d.ts.map +1 -1
  16. package/dist/llm/index.js +0 -1
  17. package/dist/llm/index.js.map +1 -1
  18. package/dist/tui/app.d.ts +9 -0
  19. package/dist/tui/app.d.ts.map +1 -0
  20. package/dist/tui/app.js +40 -0
  21. package/dist/tui/app.js.map +1 -0
  22. package/dist/tui/components/ChatList.d.ts +14 -0
  23. package/dist/tui/components/ChatList.d.ts.map +1 -0
  24. package/dist/tui/components/ChatList.js +11 -0
  25. package/dist/tui/components/ChatList.js.map +1 -0
  26. package/dist/tui/components/ChatMessage.d.ts +14 -0
  27. package/dist/tui/components/ChatMessage.d.ts.map +1 -0
  28. package/dist/tui/components/ChatMessage.js +17 -0
  29. package/dist/tui/components/ChatMessage.js.map +1 -0
  30. package/dist/tui/components/Header.d.ts +9 -0
  31. package/dist/tui/components/Header.d.ts.map +1 -0
  32. package/dist/tui/components/Header.js +6 -0
  33. package/dist/tui/components/Header.js.map +1 -0
  34. package/dist/tui/components/Markdown.d.ts +8 -0
  35. package/dist/tui/components/Markdown.d.ts.map +1 -0
  36. package/dist/tui/components/Markdown.js +31 -0
  37. package/dist/tui/components/Markdown.js.map +1 -0
  38. package/dist/tui/components/Thinking.d.ts +8 -0
  39. package/dist/tui/components/Thinking.d.ts.map +1 -0
  40. package/dist/tui/components/Thinking.js +7 -0
  41. package/dist/tui/components/Thinking.js.map +1 -0
  42. package/dist/tui/components/ToolCall.d.ts +14 -0
  43. package/dist/tui/components/ToolCall.d.ts.map +1 -0
  44. package/dist/tui/components/ToolCall.js +37 -0
  45. package/dist/tui/components/ToolCall.js.map +1 -0
  46. package/dist/tui/components/UserInput.d.ts +9 -0
  47. package/dist/tui/components/UserInput.d.ts.map +1 -0
  48. package/dist/tui/components/UserInput.js +82 -0
  49. package/dist/tui/components/UserInput.js.map +1 -0
  50. package/dist/tui/hooks/useChat.d.ts +11 -0
  51. package/dist/tui/hooks/useChat.d.ts.map +1 -0
  52. package/dist/tui/hooks/useChat.js +138 -0
  53. package/dist/tui/hooks/useChat.js.map +1 -0
  54. package/dist/tui/hooks/useCommands.d.ts +10 -0
  55. package/dist/tui/hooks/useCommands.d.ts.map +1 -0
  56. package/dist/tui/hooks/useCommands.js +51 -0
  57. package/dist/tui/hooks/useCommands.js.map +1 -0
  58. package/dist/tui/index.d.ts +2 -4
  59. package/dist/tui/index.d.ts.map +1 -1
  60. package/dist/tui/index.js +2 -4
  61. package/dist/tui/index.js.map +1 -1
  62. package/dist/tui/output.d.ts +12 -3
  63. package/dist/tui/output.d.ts.map +1 -1
  64. package/dist/tui/output.js +43 -47
  65. package/dist/tui/output.js.map +1 -1
  66. package/dist/tui/repl.d.ts.map +1 -1
  67. package/dist/tui/repl.js +42 -28
  68. package/dist/tui/repl.js.map +1 -1
  69. package/dist/tui/welcome.d.ts.map +1 -1
  70. package/dist/tui/welcome.js +23 -5
  71. package/dist/tui/welcome.js.map +1 -1
  72. package/install.ps1 +171 -192
  73. package/package.json +9 -1
  74. package/src/app/index.ts +29 -34
  75. package/src/cmd/{index.ts → index.tsx} +52 -47
  76. package/src/config/index.ts +1 -0
  77. package/src/config/types.ts +1 -0
  78. package/src/llm/index.ts +0 -1
  79. package/src/tui/app.tsx +60 -0
  80. package/src/tui/components/ChatList.tsx +29 -0
  81. package/src/tui/components/ChatMessage.tsx +51 -0
  82. package/src/tui/components/Header.tsx +22 -0
  83. package/src/tui/components/Markdown.tsx +35 -0
  84. package/src/tui/components/Thinking.tsx +19 -0
  85. package/src/tui/components/ToolCall.tsx +72 -0
  86. package/src/tui/components/UserInput.tsx +101 -0
  87. package/src/tui/hooks/useChat.ts +154 -0
  88. package/src/tui/hooks/useCommands.ts +63 -0
  89. package/src/tui/index.ts +2 -4
  90. package/src/tui/output.ts +43 -44
  91. package/src/tui/repl.ts +40 -29
  92. package/src/tui/welcome.ts +25 -6
  93. package/tsconfig.json +5 -3
  94. package/src/app/agent.ts +0 -140
package/src/app/agent.ts DELETED
@@ -1,140 +0,0 @@
1
- /**
2
- * Agent Loop - Core agent logic with streaming and tool execution
3
- * Extracted from old src/core/ai-engine.ts
4
- *
5
- * The agent loop: while(true) { stream response → check tool calls → execute → repeat }
6
- */
7
-
8
- import chalk from 'chalk';
9
- import type { ChatMessage, ChatResponse } from '../types.js';
10
- import type { Tool } from '../tools/types.js';
11
- import type { HookManager } from '../hooks/index.js';
12
- import { LLMService } from '../llm/index.js';
13
- import { ToolRegistry } from '../tools/index.js';
14
-
15
- export interface AgentConfig {
16
- maxIterations?: number;
17
- hooks?: HookManager;
18
- }
19
-
20
- export class Agent {
21
- private llm: LLMService;
22
- private registry: ToolRegistry;
23
- private hooks?: HookManager;
24
- private maxIterations: number;
25
-
26
- constructor(llm: LLMService, registry: ToolRegistry, config: AgentConfig = {}) {
27
- this.llm = llm;
28
- this.registry = registry;
29
- this.hooks = config.hooks;
30
- this.maxIterations = config.maxIterations ?? 10;
31
-
32
- // Register tools with LLM service
33
- this.llm.registerTools(registry.list());
34
- }
35
-
36
- /**
37
- * Run agent loop with streaming output
38
- * Returns the final response
39
- */
40
- async *run(messages: ChatMessage[]): AsyncGenerator<string, ChatResponse> {
41
- let currentMessages = [...messages];
42
- let iterations = 0;
43
-
44
- while (iterations < this.maxIterations) {
45
- iterations++;
46
-
47
- // Hook: beforeAgentLoop
48
- if (this.hooks) {
49
- await this.hooks.emit('beforeAgentLoop', { messages: currentMessages, iteration: iterations });
50
- }
51
-
52
- // Stream the response
53
- let fullContent = '';
54
-
55
- for await (const chunk of this.llm.chatStream(currentMessages, { maxIterations: 1 })) {
56
- fullContent += chunk;
57
- yield chunk;
58
- }
59
-
60
- // Get the full response to check for tool calls
61
- const response: ChatResponse = {
62
- content: fullContent,
63
- role: 'assistant',
64
- };
65
-
66
- // Check if the response contains tool calls
67
- // For now, we rely on the LLM service to handle tool calls internally
68
- // If the LLM service returned tool_calls, we need to process them
69
- if (response.tool_calls && response.tool_calls.length > 0) {
70
- currentMessages.push({
71
- role: 'assistant',
72
- content: response.content,
73
- tool_calls: response.tool_calls,
74
- });
75
-
76
- for (const toolCall of response.tool_calls) {
77
- // Hook: beforeToolCall
78
- if (this.hooks) {
79
- await this.hooks.emit('beforeToolCall', {
80
- toolName: toolCall.function.name,
81
- toolParams: JSON.parse(toolCall.function.arguments || '{}'),
82
- toolCallId: toolCall.id,
83
- });
84
- }
85
-
86
- const result = await this.registry.execute(
87
- toolCall.function.name,
88
- JSON.parse(toolCall.function.arguments || '{}')
89
- );
90
-
91
- // Hook: afterToolCall
92
- if (this.hooks) {
93
- await this.hooks.emit('afterToolCall', {
94
- toolName: toolCall.function.name,
95
- toolParams: JSON.parse(toolCall.function.arguments || '{}'),
96
- toolResult: result,
97
- toolCallId: toolCall.id,
98
- });
99
- }
100
-
101
- currentMessages.push({
102
- role: 'tool',
103
- content: result.success ? (result.output || JSON.stringify(result.data)) : (result.error || 'Tool failed'),
104
- tool_call_id: toolCall.id,
105
- name: toolCall.function.name,
106
- });
107
-
108
- yield `\n${chalk.gray(`[tool: ${toolCall.function.name}]`)}`;
109
- }
110
-
111
- continue; // Next iteration
112
- }
113
-
114
- // No tool calls - done
115
- if (response.content) {
116
- currentMessages.push({ role: 'assistant', content: response.content });
117
- }
118
-
119
- // Hook: afterAgentLoop
120
- if (this.hooks) {
121
- await this.hooks.emit('afterAgentLoop', { messages: currentMessages, iteration: iterations });
122
- }
123
-
124
- return response;
125
- }
126
-
127
- return { content: '[Agent loop exceeded maximum iterations]', role: 'assistant' };
128
- }
129
-
130
- /**
131
- * Non-streaming chat (convenience method)
132
- */
133
- async chat(messages: ChatMessage[]): Promise<ChatResponse> {
134
- let fullContent = '';
135
- for await (const chunk of this.run(messages)) {
136
- fullContent += chunk;
137
- }
138
- return { content: fullContent, role: 'assistant' };
139
- }
140
- }