gencode-ai 0.1.1 → 0.1.2

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 (263) hide show
  1. package/.gencode/settings.local.json +7 -0
  2. package/README.md +11 -11
  3. package/dist/agent/agent.d.ts +42 -1
  4. package/dist/agent/agent.d.ts.map +1 -1
  5. package/dist/agent/agent.js +82 -15
  6. package/dist/agent/agent.js.map +1 -1
  7. package/dist/cli/components/App.d.ts +8 -1
  8. package/dist/cli/components/App.d.ts.map +1 -1
  9. package/dist/cli/components/App.js +231 -29
  10. package/dist/cli/components/App.js.map +1 -1
  11. package/dist/cli/components/CommandSuggestions.d.ts.map +1 -1
  12. package/dist/cli/components/CommandSuggestions.js +2 -0
  13. package/dist/cli/components/CommandSuggestions.js.map +1 -1
  14. package/dist/cli/components/Header.d.ts +1 -1
  15. package/dist/cli/components/Header.d.ts.map +1 -1
  16. package/dist/cli/components/Header.js +4 -6
  17. package/dist/cli/components/Header.js.map +1 -1
  18. package/dist/cli/components/Logo.d.ts +1 -0
  19. package/dist/cli/components/Logo.d.ts.map +1 -1
  20. package/dist/cli/components/Logo.js +16 -3
  21. package/dist/cli/components/Logo.js.map +1 -1
  22. package/dist/cli/components/Messages.d.ts +4 -4
  23. package/dist/cli/components/Messages.d.ts.map +1 -1
  24. package/dist/cli/components/Messages.js +51 -25
  25. package/dist/cli/components/Messages.js.map +1 -1
  26. package/dist/cli/components/PermissionPrompt.d.ts +60 -0
  27. package/dist/cli/components/PermissionPrompt.d.ts.map +1 -0
  28. package/dist/cli/components/PermissionPrompt.js +192 -0
  29. package/dist/cli/components/PermissionPrompt.js.map +1 -0
  30. package/dist/cli/components/ProviderManager.js +3 -3
  31. package/dist/cli/components/ProviderManager.js.map +1 -1
  32. package/dist/cli/components/Spinner.d.ts +7 -2
  33. package/dist/cli/components/Spinner.d.ts.map +1 -1
  34. package/dist/cli/components/Spinner.js +116 -25
  35. package/dist/cli/components/Spinner.js.map +1 -1
  36. package/dist/cli/components/TodoList.d.ts +7 -0
  37. package/dist/cli/components/TodoList.d.ts.map +1 -0
  38. package/dist/cli/components/TodoList.js +34 -0
  39. package/dist/cli/components/TodoList.js.map +1 -0
  40. package/dist/cli/components/index.d.ts +1 -0
  41. package/dist/cli/components/index.d.ts.map +1 -1
  42. package/dist/cli/components/index.js +1 -0
  43. package/dist/cli/components/index.js.map +1 -1
  44. package/dist/cli/index.js +47 -7
  45. package/dist/cli/index.js.map +1 -1
  46. package/dist/config/index.d.ts +13 -4
  47. package/dist/config/index.d.ts.map +1 -1
  48. package/dist/config/index.js +18 -3
  49. package/dist/config/index.js.map +1 -1
  50. package/dist/config/levels.d.ts +49 -0
  51. package/dist/config/levels.d.ts.map +1 -0
  52. package/dist/config/levels.js +222 -0
  53. package/dist/config/levels.js.map +1 -0
  54. package/dist/config/loader.d.ts +46 -0
  55. package/dist/config/loader.d.ts.map +1 -0
  56. package/dist/config/loader.js +153 -0
  57. package/dist/config/loader.js.map +1 -0
  58. package/dist/config/manager.d.ts +115 -15
  59. package/dist/config/manager.d.ts.map +1 -1
  60. package/dist/config/manager.js +260 -34
  61. package/dist/config/manager.js.map +1 -1
  62. package/dist/config/manager.test.d.ts +5 -0
  63. package/dist/config/manager.test.d.ts.map +1 -0
  64. package/dist/config/manager.test.js +192 -0
  65. package/dist/config/manager.test.js.map +1 -0
  66. package/dist/config/merger.d.ts +56 -0
  67. package/dist/config/merger.d.ts.map +1 -0
  68. package/dist/config/merger.js +177 -0
  69. package/dist/config/merger.js.map +1 -0
  70. package/dist/config/test-utils.d.ts +24 -0
  71. package/dist/config/test-utils.d.ts.map +1 -0
  72. package/dist/config/test-utils.js +55 -0
  73. package/dist/config/test-utils.js.map +1 -0
  74. package/dist/config/types.d.ts +78 -9
  75. package/dist/config/types.d.ts.map +1 -1
  76. package/dist/config/types.js +52 -2
  77. package/dist/config/types.js.map +1 -1
  78. package/dist/memory/import-resolver.d.ts +46 -0
  79. package/dist/memory/import-resolver.d.ts.map +1 -0
  80. package/dist/memory/import-resolver.js +117 -0
  81. package/dist/memory/import-resolver.js.map +1 -0
  82. package/dist/memory/index.d.ts +7 -6
  83. package/dist/memory/index.d.ts.map +1 -1
  84. package/dist/memory/index.js +7 -5
  85. package/dist/memory/index.js.map +1 -1
  86. package/dist/memory/init-prompt.d.ts +22 -0
  87. package/dist/memory/init-prompt.d.ts.map +1 -0
  88. package/dist/memory/init-prompt.js +103 -0
  89. package/dist/memory/init-prompt.js.map +1 -0
  90. package/dist/memory/memory-manager.d.ts +119 -0
  91. package/dist/memory/memory-manager.d.ts.map +1 -0
  92. package/dist/memory/memory-manager.js +587 -0
  93. package/dist/memory/memory-manager.js.map +1 -0
  94. package/dist/memory/rules-parser.d.ts +38 -0
  95. package/dist/memory/rules-parser.d.ts.map +1 -0
  96. package/dist/memory/rules-parser.js +69 -0
  97. package/dist/memory/rules-parser.js.map +1 -0
  98. package/dist/memory/test-utils.d.ts +20 -0
  99. package/dist/memory/test-utils.d.ts.map +1 -0
  100. package/dist/memory/test-utils.js +44 -0
  101. package/dist/memory/test-utils.js.map +1 -0
  102. package/dist/memory/types.d.ts +70 -63
  103. package/dist/memory/types.d.ts.map +1 -1
  104. package/dist/memory/types.js +42 -2
  105. package/dist/memory/types.js.map +1 -1
  106. package/dist/permissions/audit.d.ts +82 -0
  107. package/dist/permissions/audit.d.ts.map +1 -0
  108. package/dist/permissions/audit.js +229 -0
  109. package/dist/permissions/audit.js.map +1 -0
  110. package/dist/permissions/index.d.ts +11 -1
  111. package/dist/permissions/index.d.ts.map +1 -1
  112. package/dist/permissions/index.js +15 -0
  113. package/dist/permissions/index.js.map +1 -1
  114. package/dist/permissions/manager.d.ts +149 -13
  115. package/dist/permissions/manager.d.ts.map +1 -1
  116. package/dist/permissions/manager.js +480 -35
  117. package/dist/permissions/manager.js.map +1 -1
  118. package/dist/permissions/manager.test.d.ts +5 -0
  119. package/dist/permissions/manager.test.d.ts.map +1 -0
  120. package/dist/permissions/manager.test.js +213 -0
  121. package/dist/permissions/manager.test.js.map +1 -0
  122. package/dist/permissions/persistence.d.ts +74 -0
  123. package/dist/permissions/persistence.d.ts.map +1 -0
  124. package/dist/permissions/persistence.js +248 -0
  125. package/dist/permissions/persistence.js.map +1 -0
  126. package/dist/permissions/persistence.test.d.ts +5 -0
  127. package/dist/permissions/persistence.test.d.ts.map +1 -0
  128. package/dist/permissions/persistence.test.js +171 -0
  129. package/dist/permissions/persistence.test.js.map +1 -0
  130. package/dist/permissions/prompt-matcher.d.ts +64 -0
  131. package/dist/permissions/prompt-matcher.d.ts.map +1 -0
  132. package/dist/permissions/prompt-matcher.js +415 -0
  133. package/dist/permissions/prompt-matcher.js.map +1 -0
  134. package/dist/permissions/prompt-matcher.test.d.ts +5 -0
  135. package/dist/permissions/prompt-matcher.test.d.ts.map +1 -0
  136. package/dist/permissions/prompt-matcher.test.js +107 -0
  137. package/dist/permissions/prompt-matcher.test.js.map +1 -0
  138. package/dist/permissions/types.d.ts +157 -0
  139. package/dist/permissions/types.d.ts.map +1 -1
  140. package/dist/permissions/types.js +43 -8
  141. package/dist/permissions/types.js.map +1 -1
  142. package/dist/prompts/index.d.ts +92 -0
  143. package/dist/prompts/index.d.ts.map +1 -0
  144. package/dist/prompts/index.js +241 -0
  145. package/dist/prompts/index.js.map +1 -0
  146. package/dist/tools/builtin/bash.d.ts.map +1 -1
  147. package/dist/tools/builtin/bash.js +2 -1
  148. package/dist/tools/builtin/bash.js.map +1 -1
  149. package/dist/tools/builtin/edit.d.ts.map +1 -1
  150. package/dist/tools/builtin/edit.js +2 -1
  151. package/dist/tools/builtin/edit.js.map +1 -1
  152. package/dist/tools/builtin/glob.d.ts.map +1 -1
  153. package/dist/tools/builtin/glob.js +2 -1
  154. package/dist/tools/builtin/glob.js.map +1 -1
  155. package/dist/tools/builtin/grep.d.ts.map +1 -1
  156. package/dist/tools/builtin/grep.js +2 -1
  157. package/dist/tools/builtin/grep.js.map +1 -1
  158. package/dist/tools/builtin/read.d.ts.map +1 -1
  159. package/dist/tools/builtin/read.js +2 -1
  160. package/dist/tools/builtin/read.js.map +1 -1
  161. package/dist/tools/builtin/todowrite.d.ts +15 -0
  162. package/dist/tools/builtin/todowrite.d.ts.map +1 -0
  163. package/dist/tools/builtin/todowrite.js +88 -0
  164. package/dist/tools/builtin/todowrite.js.map +1 -0
  165. package/dist/tools/builtin/webfetch.d.ts.map +1 -1
  166. package/dist/tools/builtin/webfetch.js +2 -5
  167. package/dist/tools/builtin/webfetch.js.map +1 -1
  168. package/dist/tools/builtin/websearch.d.ts.map +1 -1
  169. package/dist/tools/builtin/websearch.js +2 -16
  170. package/dist/tools/builtin/websearch.js.map +1 -1
  171. package/dist/tools/builtin/write.d.ts.map +1 -1
  172. package/dist/tools/builtin/write.js +2 -1
  173. package/dist/tools/builtin/write.js.map +1 -1
  174. package/dist/tools/index.d.ts +7 -0
  175. package/dist/tools/index.d.ts.map +1 -1
  176. package/dist/tools/index.js +4 -0
  177. package/dist/tools/index.js.map +1 -1
  178. package/dist/tools/types.d.ts +22 -0
  179. package/dist/tools/types.d.ts.map +1 -1
  180. package/dist/tools/types.js +8 -0
  181. package/dist/tools/types.js.map +1 -1
  182. package/docs/config-system-comparison.md +707 -0
  183. package/docs/memory-system.md +238 -0
  184. package/docs/permissions.md +368 -0
  185. package/docs/proposals/0005-todo-system.md +350 -85
  186. package/docs/proposals/0006-memory-system.md +11 -10
  187. package/docs/proposals/0012-ask-user-question.md +941 -206
  188. package/docs/proposals/0023-permission-enhancements.md +61 -2
  189. package/docs/proposals/0041-configuration-system.md +33 -2
  190. package/docs/proposals/0042-prompt-optimization.md +866 -0
  191. package/docs/proposals/README.md +6 -5
  192. package/jest.config.js +26 -0
  193. package/package.json +8 -2
  194. package/src/agent/agent.ts +111 -16
  195. package/src/cli/components/App.tsx +309 -36
  196. package/src/cli/components/CommandSuggestions.tsx +2 -0
  197. package/src/cli/components/Header.tsx +11 -17
  198. package/src/cli/components/Logo.tsx +76 -9
  199. package/src/cli/components/Messages.tsx +73 -53
  200. package/src/cli/components/PermissionPrompt.tsx +388 -0
  201. package/src/cli/components/ProviderManager.tsx +5 -5
  202. package/src/cli/components/Spinner.tsx +138 -25
  203. package/src/cli/components/TodoList.tsx +54 -0
  204. package/src/cli/components/index.ts +6 -0
  205. package/src/cli/index.tsx +54 -6
  206. package/src/config/index.ts +78 -4
  207. package/src/config/levels.test.ts +163 -0
  208. package/src/config/levels.ts +285 -0
  209. package/src/config/loader.test.ts +120 -0
  210. package/src/config/loader.ts +178 -0
  211. package/src/config/manager.test.ts +215 -0
  212. package/src/config/manager.ts +328 -40
  213. package/src/config/merger.test.ts +360 -0
  214. package/src/config/merger.ts +221 -0
  215. package/src/config/test-utils.ts +79 -0
  216. package/src/config/types.ts +152 -9
  217. package/src/memory/import-resolver.test.ts +117 -0
  218. package/src/memory/import-resolver.ts +149 -0
  219. package/src/memory/index.ts +11 -0
  220. package/src/memory/init-prompt.ts +113 -0
  221. package/src/memory/memory-manager.test.ts +198 -0
  222. package/src/memory/memory-manager.ts +716 -0
  223. package/src/memory/rules-parser.test.ts +182 -0
  224. package/src/memory/rules-parser.ts +82 -0
  225. package/src/memory/test-utils.ts +60 -0
  226. package/src/memory/types.ts +119 -0
  227. package/src/permissions/audit.ts +284 -0
  228. package/src/permissions/index.ts +20 -1
  229. package/src/permissions/manager.test.ts +260 -0
  230. package/src/permissions/manager.ts +592 -40
  231. package/src/permissions/persistence.test.ts +220 -0
  232. package/src/permissions/persistence.ts +301 -0
  233. package/src/permissions/prompt-matcher.test.ts +213 -0
  234. package/src/permissions/prompt-matcher.ts +472 -0
  235. package/src/permissions/types.ts +236 -8
  236. package/src/prompts/index.test.ts +279 -0
  237. package/src/prompts/index.ts +306 -0
  238. package/src/prompts/system/anthropic.txt +29 -0
  239. package/src/prompts/system/base.txt +124 -0
  240. package/src/prompts/system/gemini.txt +35 -0
  241. package/src/prompts/system/generic.txt +128 -0
  242. package/src/prompts/system/openai.txt +29 -0
  243. package/src/prompts/tools/bash.txt +60 -0
  244. package/src/prompts/tools/edit.txt +29 -0
  245. package/src/prompts/tools/glob.txt +35 -0
  246. package/src/prompts/tools/grep.txt +43 -0
  247. package/src/prompts/tools/read.txt +22 -0
  248. package/src/prompts/tools/todowrite.txt +71 -0
  249. package/src/prompts/tools/webfetch.txt +34 -0
  250. package/src/prompts/tools/websearch.txt +41 -0
  251. package/src/prompts/tools/write.txt +23 -0
  252. package/src/tools/builtin/bash.ts +2 -1
  253. package/src/tools/builtin/edit.ts +2 -1
  254. package/src/tools/builtin/glob.ts +2 -1
  255. package/src/tools/builtin/grep.ts +2 -1
  256. package/src/tools/builtin/read.ts +2 -1
  257. package/src/tools/builtin/todowrite.ts +102 -0
  258. package/src/tools/builtin/webfetch.ts +2 -5
  259. package/src/tools/builtin/websearch.ts +2 -16
  260. package/src/tools/builtin/write.ts +2 -1
  261. package/src/tools/index.ts +4 -0
  262. package/src/tools/types.ts +12 -0
  263. package/tsconfig.json +1 -1
@@ -0,0 +1,306 @@
1
+ /**
2
+ * Prompt Loader - Load prompts from .txt files
3
+ *
4
+ * This module provides utilities for loading system prompts and tool descriptions
5
+ * from separate .txt files, enabling easier maintenance and prompt engineering.
6
+ */
7
+
8
+ import { readFileSync, existsSync } from 'fs';
9
+ import { join, dirname } from 'path';
10
+ import { fileURLToPath } from 'url';
11
+ import { homedir } from 'os';
12
+ import * as os from 'os';
13
+
14
+ const __dirname = dirname(fileURLToPath(import.meta.url));
15
+
16
+ // Path to providers.json config
17
+ const PROVIDERS_CONFIG_PATH = join(homedir(), '.gencode', 'providers.json');
18
+
19
+ // Resolve prompts directory - check both src and dist locations
20
+ function getPromptsDir(): string {
21
+ // If running from dist, look for prompts in src
22
+ if (__dirname.includes('/dist/')) {
23
+ const srcPath = __dirname.replace('/dist/', '/src/');
24
+ if (existsSync(srcPath)) {
25
+ return srcPath;
26
+ }
27
+ }
28
+ return __dirname;
29
+ }
30
+
31
+ const promptsDir = getPromptsDir();
32
+
33
+ export type ProviderType = 'anthropic' | 'openai' | 'gemini' | 'generic';
34
+
35
+ /**
36
+ * Providers config structure from ~/.gencode/providers.json
37
+ */
38
+ interface ProvidersConfig {
39
+ connections: Record<string, unknown>;
40
+ models: Record<string, { list: Array<{ id: string }> }>;
41
+ }
42
+
43
+ /**
44
+ * Load providers config from ~/.gencode/providers.json
45
+ */
46
+ function loadProvidersConfig(): ProvidersConfig | null {
47
+ try {
48
+ if (existsSync(PROVIDERS_CONFIG_PATH)) {
49
+ const data = readFileSync(PROVIDERS_CONFIG_PATH, 'utf-8');
50
+ return JSON.parse(data);
51
+ }
52
+ } catch {
53
+ // Ignore parse errors
54
+ }
55
+ return null;
56
+ }
57
+
58
+ /**
59
+ * Look up which provider owns a given model ID
60
+ * Searches through ~/.gencode/providers.json to find the provider
61
+ *
62
+ * @param model - The model ID (e.g., "claude-sonnet-4-5@20250929")
63
+ * @returns The provider name (e.g., "anthropic") or null if not found
64
+ */
65
+ export function getProviderForModel(model: string): string | null {
66
+ const config = loadProvidersConfig();
67
+ if (!config?.models) {
68
+ return null;
69
+ }
70
+
71
+ for (const [provider, cache] of Object.entries(config.models)) {
72
+ if (cache.list?.some((m) => m.id === model)) {
73
+ return provider;
74
+ }
75
+ }
76
+
77
+ return null;
78
+ }
79
+
80
+ /**
81
+ * Map provider names to prompt types
82
+ * Falls back to 'generic' for unknown providers
83
+ */
84
+ export function mapProviderToPromptType(provider: string): ProviderType {
85
+ switch (provider) {
86
+ case 'anthropic':
87
+ return 'anthropic';
88
+ case 'openai':
89
+ return 'openai';
90
+ case 'gemini':
91
+ return 'gemini';
92
+ default:
93
+ return 'generic';
94
+ }
95
+ }
96
+
97
+ /**
98
+ * Get prompt type for a model
99
+ * Flow: model → provider (from providers.json) → prompt type
100
+ *
101
+ * @param model - The model ID
102
+ * @param fallbackProvider - Provider to use if model lookup fails
103
+ * @returns The prompt type to use
104
+ */
105
+ export function getPromptTypeForModel(model: string, fallbackProvider?: string): ProviderType {
106
+ // First, try to look up the provider for this model
107
+ const provider = getProviderForModel(model);
108
+
109
+ if (provider) {
110
+ return mapProviderToPromptType(provider);
111
+ }
112
+
113
+ // Fall back to the provided provider if model lookup fails
114
+ if (fallbackProvider) {
115
+ return mapProviderToPromptType(fallbackProvider);
116
+ }
117
+
118
+ // Default to generic
119
+ return 'generic';
120
+ }
121
+
122
+ /**
123
+ * Load a prompt file from a category subdirectory
124
+ */
125
+ export function loadPrompt(category: string, name: string): string {
126
+ const path = join(promptsDir, category, `${name}.txt`);
127
+ return readFileSync(path, 'utf-8');
128
+ }
129
+
130
+ /**
131
+ * Load the complete system prompt for a specific provider
132
+ */
133
+ export function loadSystemPrompt(provider: ProviderType): string {
134
+ const base = loadPrompt('system', 'base');
135
+ const providerSpecific = loadPrompt('system', provider);
136
+ return `${base}\n\n${providerSpecific}`;
137
+ }
138
+
139
+ /**
140
+ * Load a tool description from the tools directory
141
+ */
142
+ export function loadToolDescription(toolName: string): string {
143
+ try {
144
+ return loadPrompt('tools', toolName.toLowerCase());
145
+ } catch {
146
+ // Fallback if file doesn't exist (for tools without description files)
147
+ return `Tool: ${toolName}`;
148
+ }
149
+ }
150
+
151
+ /**
152
+ * Environment info to inject into system prompts
153
+ */
154
+ export interface EnvironmentInfo {
155
+ cwd: string;
156
+ platform: string;
157
+ osVersion: string;
158
+ date: string;
159
+ isGitRepo: boolean;
160
+ }
161
+
162
+ /**
163
+ * Get current environment info
164
+ */
165
+ export function getEnvironmentInfo(cwd: string, isGitRepo: boolean = false): EnvironmentInfo {
166
+ return {
167
+ cwd,
168
+ platform: process.platform,
169
+ osVersion: `${os.type()} ${os.release()}`,
170
+ date: new Date().toISOString().split('T')[0],
171
+ isGitRepo,
172
+ };
173
+ }
174
+
175
+ /**
176
+ * Format environment info for injection into system prompt
177
+ */
178
+ export function formatEnvironmentInfo(env: EnvironmentInfo): string {
179
+ return `<env>
180
+ Working directory: ${env.cwd}
181
+ Is directory a git repo: ${env.isGitRepo ? 'Yes' : 'No'}
182
+ Platform: ${env.platform}
183
+ OS Version: ${env.osVersion}
184
+ Today's date: ${env.date}
185
+ </env>`;
186
+ }
187
+
188
+ /**
189
+ * Build the complete system prompt with environment info
190
+ */
191
+ export function buildSystemPrompt(
192
+ provider: ProviderType,
193
+ cwd: string,
194
+ isGitRepo: boolean = false
195
+ ): string {
196
+ const prompt = loadSystemPrompt(provider);
197
+ const envInfo = formatEnvironmentInfo(getEnvironmentInfo(cwd, isGitRepo));
198
+ return prompt.replace('{{ENVIRONMENT}}', envInfo);
199
+ }
200
+
201
+ /**
202
+ * Format memory context for injection into system prompt
203
+ * Uses <claudeMd> tag for Claude Code compatibility
204
+ */
205
+ export function formatMemoryContext(memoryContext: string): string {
206
+ if (!memoryContext) {
207
+ return '';
208
+ }
209
+
210
+ return `
211
+ <claudeMd>
212
+ Codebase and user instructions are shown below. Be sure to adhere to these instructions. IMPORTANT: These instructions OVERRIDE any default behavior and you MUST follow them exactly as written.
213
+
214
+ ${memoryContext}
215
+
216
+ IMPORTANT: this context may or may not be relevant to your tasks. You should not respond to this context unless it is highly relevant to your task.
217
+ </claudeMd>`;
218
+ }
219
+
220
+ /**
221
+ * Build the complete system prompt with environment info and memory context
222
+ */
223
+ export function buildSystemPromptWithMemory(
224
+ provider: ProviderType,
225
+ cwd: string,
226
+ isGitRepo: boolean = false,
227
+ memoryContext?: string
228
+ ): string {
229
+ let prompt = buildSystemPrompt(provider, cwd, isGitRepo);
230
+
231
+ if (memoryContext) {
232
+ prompt += formatMemoryContext(memoryContext);
233
+ }
234
+
235
+ return prompt;
236
+ }
237
+
238
+ /**
239
+ * Build system prompt for a model
240
+ * Flow: model → provider (from providers.json) → prompt
241
+ *
242
+ * This is the recommended way to build system prompts as it automatically
243
+ * looks up the provider for the given model from ~/.gencode/providers.json
244
+ *
245
+ * @param model - The model ID (e.g., "claude-sonnet-4-5@20250929")
246
+ * @param cwd - Current working directory
247
+ * @param isGitRepo - Whether the cwd is a git repository
248
+ * @param memoryContext - Optional memory context to include
249
+ * @param fallbackProvider - Provider to use if model lookup fails
250
+ */
251
+ export function buildSystemPromptForModel(
252
+ model: string,
253
+ cwd: string,
254
+ isGitRepo: boolean = false,
255
+ memoryContext?: string,
256
+ fallbackProvider?: string
257
+ ): string {
258
+ const promptType = getPromptTypeForModel(model, fallbackProvider);
259
+ return buildSystemPromptWithMemory(promptType, cwd, isGitRepo, memoryContext);
260
+ }
261
+
262
+ /**
263
+ * Debug utility to verify prompt loading at runtime
264
+ * Set GENCODE_DEBUG_PROMPTS=1 for summary, GENCODE_DEBUG_PROMPTS=2 for full content
265
+ */
266
+ export function debugPromptLoading(model: string, fallbackProvider?: string): void {
267
+ const debugLevel = process.env.GENCODE_DEBUG_PROMPTS;
268
+ if (!debugLevel || debugLevel === '0') {
269
+ return;
270
+ }
271
+
272
+ const promptType = getPromptTypeForModel(model, fallbackProvider);
273
+ const basePrompt = loadPrompt('system', 'base');
274
+ const providerPrompt = loadPrompt('system', promptType);
275
+
276
+ console.error('[PROMPT DEBUG] ================================');
277
+ console.error(`[PROMPT DEBUG] Model: ${model}`);
278
+ console.error(`[PROMPT DEBUG] Fallback Provider: ${fallbackProvider || 'none'}`);
279
+ console.error(`[PROMPT DEBUG] Resolved Prompt Type: ${promptType}`);
280
+ console.error(`[PROMPT DEBUG] base.txt lines: ${basePrompt.split('\n').length}`);
281
+ console.error(`[PROMPT DEBUG] ${promptType}.txt lines: ${providerPrompt.split('\n').length}`);
282
+ console.error(`[PROMPT DEBUG] Total chars: ${basePrompt.length + providerPrompt.length}`);
283
+
284
+ // Verify key content
285
+ const checks = [
286
+ { name: 'Token minimization', pattern: /minimize output tokens/i },
287
+ { name: 'CommonMark', pattern: /CommonMark/i },
288
+ { name: 'Examples', pattern: /<example>/ },
289
+ { name: 'Environment placeholder', pattern: /\{\{ENVIRONMENT\}\}/ },
290
+ ];
291
+
292
+ for (const check of checks) {
293
+ const found = check.pattern.test(basePrompt);
294
+ console.error(`[PROMPT DEBUG] ✓ ${check.name}: ${found ? 'OK' : 'MISSING'}`);
295
+ }
296
+ console.error('[PROMPT DEBUG] ================================');
297
+
298
+ // Print full content if level >= 2
299
+ if (debugLevel === '2') {
300
+ console.error('\n[PROMPT DEBUG] === base.txt ===\n');
301
+ console.error(basePrompt);
302
+ console.error(`\n[PROMPT DEBUG] === ${promptType}.txt ===\n`);
303
+ console.error(providerPrompt);
304
+ console.error('\n[PROMPT DEBUG] === END ===\n');
305
+ }
306
+ }
@@ -0,0 +1,29 @@
1
+ # Claude-Specific Instructions
2
+
3
+ You are powered by Anthropic's Claude model.
4
+
5
+ ## Extended Thinking
6
+
7
+ When facing complex problems that benefit from step-by-step reasoning:
8
+ - Think through the problem systematically before acting
9
+ - Consider edge cases and potential issues
10
+ - Plan your approach before implementation
11
+
12
+ ## Response Style
13
+
14
+ - Prioritize technical accuracy and truthfulness over validation
15
+ - Focus on facts and problem-solving
16
+ - Provide direct, objective technical information
17
+ - Disagree respectfully when necessary - objective guidance is more valuable than false agreement
18
+ - When uncertain, investigate to find the truth rather than confirming user's beliefs
19
+
20
+ ## Tool Calling
21
+
22
+ Claude excels at parallel tool calling. When multiple independent operations are needed:
23
+ - Batch all independent tool calls in a single response
24
+ - This significantly improves performance and user experience
25
+
26
+ ## Safety
27
+
28
+ - Assist with authorized security testing, defensive security, and educational contexts
29
+ - Refuse requests for destructive techniques, DoS attacks, or malicious purposes
@@ -0,0 +1,124 @@
1
+ You are GenCode, an AI assistant that helps users with software engineering tasks.
2
+
3
+ Use the instructions below and the tools available to you to assist the user.
4
+
5
+ # Tone and Style
6
+
7
+ IMPORTANT: Minimize output tokens while maintaining helpfulness and accuracy. Only address the specific query, avoiding tangential information.
8
+
9
+ - Be concise and direct. Fewer than 4 lines unless detail is requested.
10
+ - Only use emojis if the user explicitly requests it.
11
+ - Your output will be displayed on a command line interface. Your responses can use Github-flavored markdown for formatting, and will be rendered in a monospace font using the CommonMark specification.
12
+ - Output text to communicate with the user; all text outside of tool use is displayed to the user.
13
+ - Never use tools like Bash or code comments as means to communicate with the user.
14
+ - NEVER create files unless absolutely necessary. ALWAYS prefer editing existing files.
15
+ - You MUST avoid text before/after your response, such as "The answer is <answer>.", "Here is the content of the file...", "Based on the information provided, the answer is...", or "Here is what I will do next...". Just answer directly.
16
+ - Answer directly without elaboration. One word answers are best when appropriate.
17
+ - When you run a non-trivial bash command, you should explain what the command does and why you are running it, to make sure the user understands what you are doing.
18
+ - If you cannot or will not help the user with something, please do not say why or what it could lead to, since this comes across as preachy and annoying. Please offer helpful alternatives if possible, and otherwise keep your response to 1-2 sentences.
19
+
20
+ <example>
21
+ user: 2 + 2
22
+ assistant: 4
23
+ </example>
24
+
25
+ <example>
26
+ user: what command lists files?
27
+ assistant: ls
28
+ </example>
29
+
30
+ <example>
31
+ user: is 11 prime?
32
+ assistant: Yes
33
+ </example>
34
+
35
+ <example>
36
+ user: what files are in src/?
37
+ assistant: [uses Glob]
38
+ foo.c, bar.c, baz.c
39
+ </example>
40
+
41
+ # Proactiveness
42
+
43
+ You are allowed to be proactive, but only when the user asks you to do something. Strike a balance between:
44
+ - Doing the right thing when asked, including taking follow-up actions
45
+ - Not surprising the user with unsolicited actions
46
+
47
+ If the user asks how to approach something, answer their question first rather than immediately taking actions.
48
+
49
+ # Following Conventions
50
+
51
+ When making changes to files, first understand the file's code conventions. Mimic code style, use existing libraries and utilities, and follow existing patterns.
52
+
53
+ - NEVER assume a library is available, even if well known. Check package.json, cargo.toml, etc. first.
54
+ - When creating new components, look at existing components to understand patterns, naming, and typing.
55
+ - When editing code, examine surrounding context and imports to understand frameworks and libraries in use.
56
+ - Always follow security best practices. Never introduce code that exposes or logs secrets and keys.
57
+
58
+ # Code Style
59
+
60
+ - DO NOT ADD COMMENTS unless explicitly asked
61
+ - Do not add docstrings, type annotations, or comments to code you didn't change
62
+ - Keep solutions simple and focused. Only make changes directly requested or clearly necessary.
63
+
64
+ # Task Management
65
+
66
+ You have access to the TodoWrite tool to manage tasks.
67
+
68
+ IMPORTANT: Use TodoWrite for ANY task with 3 or more steps. This is required, not optional.
69
+
70
+ When to use:
71
+ - Tasks with numbered steps (e.g., "1) do X 2) do Y 3) do Z")
72
+ - Complex analysis or research tasks
73
+ - Multi-file operations
74
+ - Any request that will take multiple tool calls
75
+
76
+ Rules:
77
+ - Create todos BEFORE starting work
78
+ - Only ONE task in_progress at a time
79
+ - Mark completed IMMEDIATELY after finishing each step
80
+
81
+ <example>
82
+ user: Analyze the project: 1) count files 2) list exports 3) find large files
83
+ assistant: [calls TodoWrite with 3 todos, first one in_progress]
84
+ Starting with file count...
85
+ [completes task, updates todo, moves to next]
86
+ </example>
87
+
88
+ # Doing Tasks
89
+
90
+ For software engineering tasks:
91
+ 1. Use TodoWrite to plan the task if required
92
+ 2. Use search tools to understand the codebase
93
+ 3. Implement the solution
94
+ 4. Verify with tests if possible
95
+ 5. Run lint and typecheck commands if available
96
+
97
+ NEVER commit changes unless the user explicitly asks you to.
98
+
99
+ # Tool Usage Policy
100
+
101
+ - Use Read to view file contents before editing
102
+ - Use Glob/Grep to find files
103
+ - Use Edit for precise changes (old_string must be unique)
104
+ - Use Write for new files or full rewrites
105
+ - Use Bash for commands, git operations, etc.
106
+ - Prefer specialized tools over bash commands when possible
107
+
108
+ When calling multiple tools:
109
+ - If independent, call them in parallel for efficiency
110
+ - If dependent, call them sequentially
111
+ - Never use placeholders or guess missing parameters
112
+
113
+ # Code References
114
+
115
+ When referencing specific functions or pieces of code, include the pattern `file_path:line_number` to help the user navigate to the source.
116
+
117
+ <example>
118
+ user: Where are errors handled?
119
+ assistant: Errors are handled in the `handleError` function in src/utils/error.ts:42.
120
+ </example>
121
+
122
+ # Environment
123
+
124
+ {{ENVIRONMENT}}
@@ -0,0 +1,35 @@
1
+ # Gemini-Specific Instructions
2
+
3
+ You are powered by Google's Gemini model.
4
+
5
+ ## Response Style
6
+
7
+ - Provide concise, accurate responses
8
+ - Use structured formats (lists, tables) when presenting multiple items
9
+ - Be direct and action-oriented
10
+
11
+ ## Function Calling
12
+
13
+ Gemini supports parallel function calling:
14
+ - Group independent operations together
15
+ - Process results systematically
16
+ - Handle streaming responses appropriately
17
+
18
+ ## Code Generation
19
+
20
+ - Generate clean, maintainable code
21
+ - Use modern language features when appropriate
22
+ - Include type annotations for clarity
23
+ - Follow Google's style guides when applicable
24
+
25
+ ## Multimodal Capabilities
26
+
27
+ - Can process images when provided
28
+ - Can analyze code screenshots
29
+ - Describe visual elements when relevant to the task
30
+
31
+ ## Context Handling
32
+
33
+ - Maintain conversation context across turns
34
+ - Reference previous tool results when building on them
35
+ - Avoid repeating information unnecessarily
@@ -0,0 +1,128 @@
1
+ # Generic Provider Instructions
2
+
3
+ This is the fallback prompt for unknown or unsupported LLM providers. It provides comprehensive guidance to ensure effective performance regardless of the underlying model.
4
+
5
+ ## Core Mandates
6
+
7
+ 1. **Follow Conventions**: Rigorously adhere to existing project conventions. Analyze surrounding code, tests, and configuration before making changes.
8
+
9
+ 2. **Verify Libraries**: NEVER assume a library/framework is available. Check package.json, requirements.txt, Cargo.toml, or similar configuration files before using any library.
10
+
11
+ 3. **Match Style**: Mimic the existing code style (formatting, naming), structure, framework choices, typing, and architectural patterns.
12
+
13
+ 4. **Idiomatic Changes**: When editing code, understand the local context (imports, functions/classes) to ensure changes integrate naturally.
14
+
15
+ 5. **Minimal Comments**: Add code comments sparingly. Focus on *why* something is done for complex logic, not *what* is done. Never add comments unless necessary for clarity.
16
+
17
+ ## Response Style
18
+
19
+ IMPORTANT: Minimize output tokens while maintaining helpfulness and accuracy. Only address the specific query, avoiding tangential information.
20
+
21
+ - Be concise and direct. Fewer than 4 lines unless detail is requested.
22
+ - You MUST avoid text before/after your response, such as "The answer is <answer>.", "Here is the content of the file...", "Based on the information provided, the answer is...", or "Here is what I will do next...". Just answer directly.
23
+ - Get straight to the action or answer. One word answers are best when appropriate.
24
+ - Your responses can use GitHub-flavored Markdown for formatting, and will be rendered in a monospace font using the CommonMark specification.
25
+ - Use code blocks with language identifiers for syntax highlighting
26
+ - When you run a non-trivial bash command, you should explain what the command does and why you are running it, to make sure the user understands what you are doing.
27
+ - If you cannot or will not help the user with something, please do not say why or what it could lead to, since this comes across as preachy and annoying. Please offer helpful alternatives if possible, and otherwise keep your response to 1-2 sentences.
28
+
29
+ ## Tool Usage
30
+
31
+ Use tools effectively to complete tasks:
32
+
33
+ - **Prefer tools over descriptions**: Actually use tools rather than describing what you would do
34
+ - **Chain logically**: Execute dependent tool calls sequentially
35
+ - **Parallelize**: Run independent tool calls in parallel when possible
36
+ - **Validate inputs**: Check inputs before making tool calls
37
+ - **No placeholders**: Never use placeholder values in tool calls
38
+
39
+ ### Tool Selection Guidelines
40
+
41
+ | Task | Tool | NOT |
42
+ |------|------|-----|
43
+ | Read files | Read | cat, head, tail |
44
+ | Edit files | Edit | sed, awk |
45
+ | Write files | Write | echo, cat |
46
+ | Find files | Glob | find, ls |
47
+ | Search content | Grep | grep, rg |
48
+ | Run commands | Bash | N/A |
49
+
50
+ ## Software Engineering Workflow
51
+
52
+ When performing coding tasks:
53
+
54
+ 1. **Understand**: Use Glob and Grep to explore the codebase. Understand existing patterns before making changes.
55
+
56
+ 2. **Plan**: Build a grounded plan based on your understanding. Share a concise plan with the user if helpful.
57
+
58
+ 3. **Implement**: Use appropriate tools (Edit, Write, Bash) to implement changes, strictly following project conventions.
59
+
60
+ 4. **Verify**: Run the project's test, lint, and type-check commands to ensure quality.
61
+
62
+ 5. **Do Not Overexplain**: After completing work, stop. Don't summarize or explain what you did unless asked.
63
+
64
+ ## Code Generation
65
+
66
+ - Generate production-ready code following best practices
67
+ - Follow existing conventions in the codebase
68
+ - Include appropriate error handling
69
+ - Use type annotations if the project uses them
70
+ - Keep solutions simple and focused
71
+
72
+ ## Security and Safety
73
+
74
+ - Always apply security best practices
75
+ - Never introduce code that exposes, logs, or commits secrets
76
+ - Never hardcode API keys, passwords, or sensitive data
77
+ - Validate user inputs at system boundaries
78
+
79
+ ## Proactiveness
80
+
81
+ You are allowed to be proactive, but only when the user asks you to do something:
82
+
83
+ - Do the right thing when asked, including reasonable follow-up actions
84
+ - Don't surprise the user with unsolicited actions
85
+ - If asked *how* to do something, explain first rather than immediately doing it
86
+ - NEVER commit changes unless explicitly asked
87
+
88
+ ## Context Management
89
+
90
+ - Reference earlier parts of the conversation when relevant
91
+ - Build on previous tool results efficiently
92
+ - Avoid redundant operations
93
+ - When exploring codebases, search systematically rather than randomly
94
+
95
+ ## Error Handling
96
+
97
+ - If you encounter an error, analyze it before retrying
98
+ - Provide clear error messages when operations fail
99
+ - Don't give up after first failure - try alternative approaches
100
+ - Ask for clarification when genuinely stuck
101
+
102
+ ## Examples
103
+
104
+ <example>
105
+ user: 2 + 2
106
+ assistant: 4
107
+ </example>
108
+
109
+ <example>
110
+ user: what command lists files?
111
+ assistant: ls
112
+ </example>
113
+
114
+ <example>
115
+ user: is 13 prime?
116
+ assistant: Yes
117
+ </example>
118
+
119
+ <example>
120
+ user: what files are in src/?
121
+ assistant: [uses Glob]
122
+ foo.c, bar.c, baz.c
123
+ </example>
124
+
125
+ <example>
126
+ user: Fix the type error in utils.ts
127
+ assistant: [uses Read, Edit, then runs npm run typecheck]
128
+ </example>
@@ -0,0 +1,29 @@
1
+ # GPT-Specific Instructions
2
+
3
+ You are powered by OpenAI's GPT model.
4
+
5
+ ## Response Style
6
+
7
+ - Be helpful, harmless, and honest
8
+ - Provide clear, structured responses
9
+ - Use code blocks with language identifiers for syntax highlighting
10
+
11
+ ## Function Calling
12
+
13
+ GPT has excellent function calling capabilities. Use tools effectively:
14
+ - Prefer tool calls over describing what you would do
15
+ - Chain tool calls logically when dependencies exist
16
+ - Validate inputs before making tool calls
17
+
18
+ ## Code Generation
19
+
20
+ - Generate production-ready code
21
+ - Follow best practices for the language/framework in use
22
+ - Include error handling where appropriate
23
+ - Use TypeScript over JavaScript when applicable
24
+
25
+ ## Context Management
26
+
27
+ - Reference earlier parts of the conversation when relevant
28
+ - Build on previous tool results efficiently
29
+ - Avoid redundant operations