gencode-ai 0.1.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 (274) hide show
  1. package/.env.example +11 -0
  2. package/CLAUDE.md +70 -0
  3. package/LICENSE +21 -0
  4. package/README.md +117 -0
  5. package/dist/agent/agent.d.ts +84 -0
  6. package/dist/agent/agent.d.ts.map +1 -0
  7. package/dist/agent/agent.js +233 -0
  8. package/dist/agent/agent.js.map +1 -0
  9. package/dist/agent/index.d.ts +6 -0
  10. package/dist/agent/index.d.ts.map +1 -0
  11. package/dist/agent/index.js +6 -0
  12. package/dist/agent/index.js.map +1 -0
  13. package/dist/agent/types.d.ts +47 -0
  14. package/dist/agent/types.d.ts.map +1 -0
  15. package/dist/agent/types.js +5 -0
  16. package/dist/agent/types.js.map +1 -0
  17. package/dist/cli/components/App.d.ts +14 -0
  18. package/dist/cli/components/App.d.ts.map +1 -0
  19. package/dist/cli/components/App.js +395 -0
  20. package/dist/cli/components/App.js.map +1 -0
  21. package/dist/cli/components/CommandSuggestions.d.ts +13 -0
  22. package/dist/cli/components/CommandSuggestions.d.ts.map +1 -0
  23. package/dist/cli/components/CommandSuggestions.js +32 -0
  24. package/dist/cli/components/CommandSuggestions.js.map +1 -0
  25. package/dist/cli/components/Header.d.ts +9 -0
  26. package/dist/cli/components/Header.d.ts.map +1 -0
  27. package/dist/cli/components/Header.js +13 -0
  28. package/dist/cli/components/Header.js.map +1 -0
  29. package/dist/cli/components/Input.d.ts +13 -0
  30. package/dist/cli/components/Input.d.ts.map +1 -0
  31. package/dist/cli/components/Input.js +27 -0
  32. package/dist/cli/components/Input.js.map +1 -0
  33. package/dist/cli/components/Logo.d.ts +2 -0
  34. package/dist/cli/components/Logo.d.ts.map +1 -0
  35. package/dist/cli/components/Logo.js +8 -0
  36. package/dist/cli/components/Logo.js.map +1 -0
  37. package/dist/cli/components/Messages.d.ts +37 -0
  38. package/dist/cli/components/Messages.d.ts.map +1 -0
  39. package/dist/cli/components/Messages.js +106 -0
  40. package/dist/cli/components/Messages.js.map +1 -0
  41. package/dist/cli/components/ModelSelector.d.ts +13 -0
  42. package/dist/cli/components/ModelSelector.d.ts.map +1 -0
  43. package/dist/cli/components/ModelSelector.js +72 -0
  44. package/dist/cli/components/ModelSelector.js.map +1 -0
  45. package/dist/cli/components/Spinner.d.ts +12 -0
  46. package/dist/cli/components/Spinner.d.ts.map +1 -0
  47. package/dist/cli/components/Spinner.js +45 -0
  48. package/dist/cli/components/Spinner.js.map +1 -0
  49. package/dist/cli/components/index.d.ts +12 -0
  50. package/dist/cli/components/index.d.ts.map +1 -0
  51. package/dist/cli/components/index.js +12 -0
  52. package/dist/cli/components/index.js.map +1 -0
  53. package/dist/cli/components/theme.d.ts +31 -0
  54. package/dist/cli/components/theme.d.ts.map +1 -0
  55. package/dist/cli/components/theme.js +36 -0
  56. package/dist/cli/components/theme.js.map +1 -0
  57. package/dist/cli/index-legacy.d.ts +7 -0
  58. package/dist/cli/index-legacy.d.ts.map +1 -0
  59. package/dist/cli/index-legacy.js +431 -0
  60. package/dist/cli/index-legacy.js.map +1 -0
  61. package/dist/cli/index.d.ts +7 -0
  62. package/dist/cli/index.d.ts.map +1 -0
  63. package/dist/cli/index.js +116 -0
  64. package/dist/cli/index.js.map +1 -0
  65. package/dist/cli/ink-cli.d.ts +7 -0
  66. package/dist/cli/ink-cli.d.ts.map +1 -0
  67. package/dist/cli/ink-cli.js +105 -0
  68. package/dist/cli/ink-cli.js.map +1 -0
  69. package/dist/cli/session-picker.d.ts +16 -0
  70. package/dist/cli/session-picker.d.ts.map +1 -0
  71. package/dist/cli/session-picker.js +280 -0
  72. package/dist/cli/session-picker.js.map +1 -0
  73. package/dist/cli/ui.d.ts +61 -0
  74. package/dist/cli/ui.d.ts.map +1 -0
  75. package/dist/cli/ui.js +364 -0
  76. package/dist/cli/ui.js.map +1 -0
  77. package/dist/config/index.d.ts +7 -0
  78. package/dist/config/index.d.ts.map +1 -0
  79. package/dist/config/index.js +6 -0
  80. package/dist/config/index.js.map +1 -0
  81. package/dist/config/manager.d.ts +31 -0
  82. package/dist/config/manager.d.ts.map +1 -0
  83. package/dist/config/manager.js +65 -0
  84. package/dist/config/manager.js.map +1 -0
  85. package/dist/config/types.d.ts +22 -0
  86. package/dist/config/types.d.ts.map +1 -0
  87. package/dist/config/types.js +6 -0
  88. package/dist/config/types.js.map +1 -0
  89. package/dist/index.d.ts +12 -0
  90. package/dist/index.d.ts.map +1 -0
  91. package/dist/index.js +21 -0
  92. package/dist/index.js.map +1 -0
  93. package/dist/memory/index.d.ts +10 -0
  94. package/dist/memory/index.d.ts.map +1 -0
  95. package/dist/memory/index.js +9 -0
  96. package/dist/memory/index.js.map +1 -0
  97. package/dist/memory/init.d.ts +20 -0
  98. package/dist/memory/init.d.ts.map +1 -0
  99. package/dist/memory/init.js +332 -0
  100. package/dist/memory/init.js.map +1 -0
  101. package/dist/memory/manager.d.ts +85 -0
  102. package/dist/memory/manager.d.ts.map +1 -0
  103. package/dist/memory/manager.js +234 -0
  104. package/dist/memory/manager.js.map +1 -0
  105. package/dist/memory/types.d.ts +74 -0
  106. package/dist/memory/types.d.ts.map +1 -0
  107. package/dist/memory/types.js +6 -0
  108. package/dist/memory/types.js.map +1 -0
  109. package/dist/permissions/index.d.ts +7 -0
  110. package/dist/permissions/index.d.ts.map +1 -0
  111. package/dist/permissions/index.js +6 -0
  112. package/dist/permissions/index.js.map +1 -0
  113. package/dist/permissions/manager.d.ts +32 -0
  114. package/dist/permissions/manager.d.ts.map +1 -0
  115. package/dist/permissions/manager.js +79 -0
  116. package/dist/permissions/manager.js.map +1 -0
  117. package/dist/permissions/types.d.ts +14 -0
  118. package/dist/permissions/types.d.ts.map +1 -0
  119. package/dist/permissions/types.js +17 -0
  120. package/dist/permissions/types.js.map +1 -0
  121. package/dist/providers/anthropic.d.ts +20 -0
  122. package/dist/providers/anthropic.d.ts.map +1 -0
  123. package/dist/providers/anthropic.js +185 -0
  124. package/dist/providers/anthropic.js.map +1 -0
  125. package/dist/providers/gemini.d.ts +21 -0
  126. package/dist/providers/gemini.d.ts.map +1 -0
  127. package/dist/providers/gemini.js +241 -0
  128. package/dist/providers/gemini.js.map +1 -0
  129. package/dist/providers/index.d.ts +34 -0
  130. package/dist/providers/index.d.ts.map +1 -0
  131. package/dist/providers/index.js +72 -0
  132. package/dist/providers/index.js.map +1 -0
  133. package/dist/providers/openai.d.ts +19 -0
  134. package/dist/providers/openai.d.ts.map +1 -0
  135. package/dist/providers/openai.js +221 -0
  136. package/dist/providers/openai.js.map +1 -0
  137. package/dist/providers/types.d.ts +125 -0
  138. package/dist/providers/types.d.ts.map +1 -0
  139. package/dist/providers/types.js +6 -0
  140. package/dist/providers/types.js.map +1 -0
  141. package/dist/session/index.d.ts +6 -0
  142. package/dist/session/index.d.ts.map +1 -0
  143. package/dist/session/index.js +6 -0
  144. package/dist/session/index.js.map +1 -0
  145. package/dist/session/manager.d.ts +101 -0
  146. package/dist/session/manager.d.ts.map +1 -0
  147. package/dist/session/manager.js +295 -0
  148. package/dist/session/manager.js.map +1 -0
  149. package/dist/session/types.d.ts +39 -0
  150. package/dist/session/types.d.ts.map +1 -0
  151. package/dist/session/types.js +10 -0
  152. package/dist/session/types.js.map +1 -0
  153. package/dist/tools/builtin/bash.d.ts +7 -0
  154. package/dist/tools/builtin/bash.d.ts.map +1 -0
  155. package/dist/tools/builtin/bash.js +80 -0
  156. package/dist/tools/builtin/bash.js.map +1 -0
  157. package/dist/tools/builtin/edit.d.ts +7 -0
  158. package/dist/tools/builtin/edit.d.ts.map +1 -0
  159. package/dist/tools/builtin/edit.js +32 -0
  160. package/dist/tools/builtin/edit.js.map +1 -0
  161. package/dist/tools/builtin/glob.d.ts +7 -0
  162. package/dist/tools/builtin/glob.d.ts.map +1 -0
  163. package/dist/tools/builtin/glob.js +36 -0
  164. package/dist/tools/builtin/glob.js.map +1 -0
  165. package/dist/tools/builtin/grep.d.ts +7 -0
  166. package/dist/tools/builtin/grep.d.ts.map +1 -0
  167. package/dist/tools/builtin/grep.js +59 -0
  168. package/dist/tools/builtin/grep.js.map +1 -0
  169. package/dist/tools/builtin/read.d.ts +7 -0
  170. package/dist/tools/builtin/read.d.ts.map +1 -0
  171. package/dist/tools/builtin/read.js +29 -0
  172. package/dist/tools/builtin/read.js.map +1 -0
  173. package/dist/tools/builtin/write.d.ts +7 -0
  174. package/dist/tools/builtin/write.d.ts.map +1 -0
  175. package/dist/tools/builtin/write.js +24 -0
  176. package/dist/tools/builtin/write.js.map +1 -0
  177. package/dist/tools/index.d.ts +38 -0
  178. package/dist/tools/index.d.ts.map +1 -0
  179. package/dist/tools/index.js +32 -0
  180. package/dist/tools/index.js.map +1 -0
  181. package/dist/tools/registry.d.ts +22 -0
  182. package/dist/tools/registry.d.ts.map +1 -0
  183. package/dist/tools/registry.js +71 -0
  184. package/dist/tools/registry.js.map +1 -0
  185. package/dist/tools/types.d.ts +62 -0
  186. package/dist/tools/types.d.ts.map +1 -0
  187. package/dist/tools/types.js +126 -0
  188. package/dist/tools/types.js.map +1 -0
  189. package/docs/README.md +16 -0
  190. package/docs/proposals/0001-web-fetch-tool.md +293 -0
  191. package/docs/proposals/0002-web-search-tool.md +306 -0
  192. package/docs/proposals/0003-task-subagents.md +333 -0
  193. package/docs/proposals/0004-plan-mode.md +338 -0
  194. package/docs/proposals/0005-todo-system.md +299 -0
  195. package/docs/proposals/0006-memory-system.md +539 -0
  196. package/docs/proposals/0007-context-management.md +429 -0
  197. package/docs/proposals/0008-checkpointing.md +327 -0
  198. package/docs/proposals/0009-hooks-system.md +343 -0
  199. package/docs/proposals/0010-mcp-integration.md +382 -0
  200. package/docs/proposals/0011-custom-commands.md +374 -0
  201. package/docs/proposals/0012-ask-user-question.md +317 -0
  202. package/docs/proposals/0013-multi-edit-tool.md +345 -0
  203. package/docs/proposals/0014-lsp-tool.md +478 -0
  204. package/docs/proposals/0015-ls-tool.md +407 -0
  205. package/docs/proposals/0016-kill-shell-tool.md +455 -0
  206. package/docs/proposals/0017-background-tasks.md +489 -0
  207. package/docs/proposals/0018-parallel-tool-execution.md +415 -0
  208. package/docs/proposals/0019-session-enhancements.md +462 -0
  209. package/docs/proposals/0020-session-summarization.md +447 -0
  210. package/docs/proposals/0021-skills-system.md +409 -0
  211. package/docs/proposals/0022-plugin-system.md +467 -0
  212. package/docs/proposals/0023-permission-enhancements.md +470 -0
  213. package/docs/proposals/0024-keyboard-shortcuts.md +443 -0
  214. package/docs/proposals/0025-cost-tracking.md +447 -0
  215. package/docs/proposals/0026-git-integration.md +475 -0
  216. package/docs/proposals/0027-enhanced-read-tool.md +514 -0
  217. package/docs/proposals/0028-enhanced-bash-tool.md +511 -0
  218. package/docs/proposals/0029-notebook-edit-tool.md +413 -0
  219. package/docs/proposals/0030-plugin-marketplace.md +360 -0
  220. package/docs/proposals/0031-command-suggestions.md +295 -0
  221. package/docs/proposals/0032-ide-integrations.md +328 -0
  222. package/docs/proposals/0033-enterprise-deployment.md +221 -0
  223. package/docs/proposals/0034-sandboxing.md +273 -0
  224. package/docs/proposals/0035-auto-updater.md +311 -0
  225. package/docs/proposals/0036-enhanced-glob-tool.md +267 -0
  226. package/docs/proposals/0037-enhanced-grep-tool.md +360 -0
  227. package/docs/proposals/0038-interactive-cli-ui.md +373 -0
  228. package/docs/proposals/0039-streaming-enhancements.md +359 -0
  229. package/docs/proposals/0040-multi-provider-enhancements.md +369 -0
  230. package/docs/proposals/README.md +84 -0
  231. package/docs/proposals/TEMPLATE.md +57 -0
  232. package/docs/proposals/research/claude-code-research.md +307 -0
  233. package/examples/agent-demo.ts +115 -0
  234. package/examples/basic.ts +166 -0
  235. package/package.json +50 -0
  236. package/src/agent/agent.ts +276 -0
  237. package/src/agent/index.ts +6 -0
  238. package/src/agent/types.ts +62 -0
  239. package/src/cli/components/App.tsx +565 -0
  240. package/src/cli/components/CommandSuggestions.tsx +58 -0
  241. package/src/cli/components/Header.tsx +36 -0
  242. package/src/cli/components/Input.tsx +60 -0
  243. package/src/cli/components/Logo.tsx +16 -0
  244. package/src/cli/components/Messages.tsx +210 -0
  245. package/src/cli/components/ModelSelector.tsx +135 -0
  246. package/src/cli/components/Spinner.tsx +72 -0
  247. package/src/cli/components/index.ts +21 -0
  248. package/src/cli/components/theme.ts +36 -0
  249. package/src/cli/index.tsx +136 -0
  250. package/src/config/index.ts +7 -0
  251. package/src/config/manager.ts +77 -0
  252. package/src/config/types.ts +25 -0
  253. package/src/index.ts +86 -0
  254. package/src/permissions/index.ts +7 -0
  255. package/src/permissions/manager.ts +97 -0
  256. package/src/permissions/types.ts +29 -0
  257. package/src/providers/anthropic.ts +224 -0
  258. package/src/providers/gemini.ts +295 -0
  259. package/src/providers/index.ts +97 -0
  260. package/src/providers/openai.ts +261 -0
  261. package/src/providers/types.ts +181 -0
  262. package/src/session/index.ts +6 -0
  263. package/src/session/manager.ts +354 -0
  264. package/src/session/types.ts +49 -0
  265. package/src/tools/builtin/bash.ts +92 -0
  266. package/src/tools/builtin/edit.ts +37 -0
  267. package/src/tools/builtin/glob.ts +42 -0
  268. package/src/tools/builtin/grep.ts +67 -0
  269. package/src/tools/builtin/read.ts +34 -0
  270. package/src/tools/builtin/write.ts +27 -0
  271. package/src/tools/index.ts +36 -0
  272. package/src/tools/registry.ts +83 -0
  273. package/src/tools/types.ts +172 -0
  274. package/tsconfig.json +21 -0
@@ -0,0 +1,539 @@
1
+ # Proposal: Memory System (MYCODE.md) with /init Command
2
+
3
+ - **Proposal ID**: 0006
4
+ - **Author**: mycode team
5
+ - **Status**: Draft
6
+ - **Created**: 2025-01-15
7
+ - **Updated**: 2025-01-15
8
+
9
+ ## Summary
10
+
11
+ Implement a comprehensive memory system inspired by Claude Code, including:
12
+ 1. **MYCODE.md files** - Project-specific context that persists across sessions
13
+ 2. **Hierarchical memory loading** - User → Project → Directory-specific rules
14
+ 3. **/init command** - Automatic project analysis and MYCODE.md generation
15
+ 4. **# prefix** - Quick memory adds during sessions
16
+ 5. **/memory command** - Edit memory files
17
+ 6. **@import syntax** - Include other files into memory
18
+ 7. **.mycode/rules/ directory** - Modular, path-scoped rules
19
+
20
+ ## Motivation
21
+
22
+ Currently, mycode has no way to remember project-specific context. This leads to:
23
+
24
+ 1. **Repetitive explanations**: Users re-explain project conventions every session
25
+ 2. **Inconsistent behavior**: Agent doesn't follow project standards
26
+ 3. **Poor onboarding**: New sessions start from scratch
27
+ 4. **No learning**: Corrections aren't remembered
28
+ 5. **No sharing**: Team conventions can't be documented for the agent
29
+
30
+ A memory system solves these by providing persistent, hierarchical project context.
31
+
32
+ ## Claude Code Reference (Deep Research)
33
+
34
+ Based on comprehensive research of Claude Code's implementation:
35
+
36
+ ### Memory File Hierarchy (Priority Order)
37
+
38
+ ```
39
+ 1. Enterprise Policy (highest priority)
40
+ └── Organization-managed CLAUDE.md
41
+
42
+ 2. User Memory
43
+ └── ~/.claude/CLAUDE.md (personal preferences across all projects)
44
+
45
+ 3. Project Memory
46
+ └── ./CLAUDE.md or ./.claude/CLAUDE.md
47
+ └── ./.claude/rules/*.md (path-scoped rules)
48
+ └── ./.claude/CLAUDE.local.md (gitignored personal project notes)
49
+
50
+ 4. Directory-Specific Memory (recursive up to root)
51
+ └── ./src/CLAUDE.md
52
+ └── ./src/components/CLAUDE.md
53
+ ```
54
+
55
+ ### /init Command
56
+
57
+ The /init command uses this exact prompt (extracted from Claude Code v2.1.8):
58
+
59
+ ```
60
+ Please analyze this codebase and create a CLAUDE.md file, which will be given
61
+ to future instances of Claude Code to operate in this repository.
62
+
63
+ What to add:
64
+ 1. Commands that will be commonly used, such as how to build, lint, and run tests.
65
+ Include the necessary commands to develop in this codebase, such as how to run
66
+ a single test.
67
+ 2. High-level code architecture and structure so that future instances can be
68
+ productive more quickly. Focus on the "big picture" architecture that requires
69
+ reading multiple files to understand.
70
+
71
+ Usage notes:
72
+ - If there's already a CLAUDE.md, suggest improvements to it.
73
+ - When you make the initial CLAUDE.md, do not repeat yourself and do not include
74
+ obvious instructions like "Provide helpful error messages to users", "Write
75
+ unit tests for all new utilities", "Never include sensitive information (API
76
+ keys, tokens) in code or commits".
77
+ - Avoid listing every component or file structure that can be easily discovered.
78
+ - Don't include generic development practices.
79
+ - If there are Cursor rules (in .cursor/rules/ or .cursorrules) or Copilot rules
80
+ (in .github/copilot-instructions.md), make sure to include the important parts.
81
+ - If there is a README.md, make sure to include the important parts.
82
+ - Do not make up information such as "Common Development Tasks", "Tips for
83
+ Development", "Support and Documentation" unless this is expressly included
84
+ in other files that you read.
85
+ - Be sure to prefix the file with the following text:
86
+
87
+ # CLAUDE.md
88
+
89
+ This file provides guidance to Claude Code (claude.ai/code) when working with
90
+ code in this repository.
91
+ ```
92
+
93
+ **Context Gathering**: Before running the prompt, Claude Code uses BatchTool with GlobTool to find:
94
+ - `package*.json`, `*.md`
95
+ - `.cursor/rules/**`, `.cursorrules/**`
96
+ - `.github/copilot-instructions.md`
97
+
98
+ ### Memory Loading Mechanism
99
+
100
+ 1. **Session-based loading**: All MYCODE.md files loaded at session start
101
+ 2. **Appears as "claudeMd" context**: Injected into system prompt as labeled context
102
+ 3. **Directory-aware**: Moving directories triggers loading of directory-specific rules
103
+ 4. **Additive loading**: Context accumulates, doesn't replace
104
+ 5. **@ imports resolved dynamically**: When reading files, not just at start
105
+
106
+ ### .claude/rules/ Directory
107
+
108
+ ```yaml
109
+ # .claude/rules/api-rules.md
110
+ ---
111
+ paths:
112
+ - "src/api/**/*.ts"
113
+ - "src/routes/**/*.ts"
114
+ ---
115
+
116
+ # API Development Rules
117
+
118
+ - Use async/await consistently
119
+ - Always validate request inputs with Zod
120
+ - Return consistent error response format
121
+ ```
122
+
123
+ **Key behaviors**:
124
+ - All `.md` files automatically loaded as project memory
125
+ - Same priority as `.claude/CLAUDE.md`
126
+ - `paths` frontmatter scopes rules to specific files
127
+ - Only loads when working on matching files
128
+
129
+ ### # Prefix Quick Adds
130
+
131
+ ```
132
+ # Always use 2-space indentation for TypeScript
133
+ ```
134
+
135
+ Instantly saved to appropriate MYCODE.md (user or project, with prompt to choose).
136
+
137
+ ### /memory Command
138
+
139
+ Opens memory files in system editor for manual editing:
140
+ - Shows which memory files are currently loaded
141
+ - Allows selecting which file to edit
142
+
143
+ ### @import Syntax
144
+
145
+ ```markdown
146
+ # MYCODE.md
147
+
148
+ @docs/architecture.md
149
+ @docs/api-conventions.md
150
+
151
+ ## Project Overview
152
+ ...
153
+ ```
154
+
155
+ **Behaviors**:
156
+ - Up to 5 levels of recursion
157
+ - Resolved dynamically when file is read
158
+ - Imported content injected via system reminders
159
+
160
+ ## Detailed Design
161
+
162
+ ### API Design
163
+
164
+ ```typescript
165
+ // src/memory/types.ts
166
+ type MemoryLevel = 'enterprise' | 'user' | 'project' | 'local' | 'directory';
167
+
168
+ interface MemoryFile {
169
+ path: string;
170
+ content: string;
171
+ level: MemoryLevel;
172
+ loadedAt: Date;
173
+ resolvedImports: string[]; // Paths of @imported files
174
+ }
175
+
176
+ interface MemoryRule {
177
+ path: string;
178
+ content: string;
179
+ paths?: string[]; // Glob patterns for scoping
180
+ isActive: boolean; // Whether current context matches paths
181
+ }
182
+
183
+ interface MemoryConfig {
184
+ filename: string; // Default: 'MYCODE.md'
185
+ localFilename: string; // Default: 'MYCODE.local.md'
186
+ userPath: string; // Default: '~/.mycode/MYCODE.md'
187
+ rulesDir: string; // Default: '.mycode/rules/'
188
+ maxFileSize: number; // Default: 100KB
189
+ maxTotalSize: number; // Default: 500KB
190
+ maxImportDepth: number; // Default: 5
191
+ }
192
+
193
+ interface LoadedMemory {
194
+ files: MemoryFile[];
195
+ rules: MemoryRule[];
196
+ totalTokens: number;
197
+ context: string; // Combined context for system prompt
198
+ }
199
+ ```
200
+
201
+ ```typescript
202
+ // src/memory/memory-manager.ts
203
+ class MemoryManager {
204
+ private config: MemoryConfig;
205
+ private loadedMemory: LoadedMemory;
206
+ private cwd: string;
207
+
208
+ constructor(config?: Partial<MemoryConfig>);
209
+
210
+ // Load all memory for current working directory
211
+ async load(cwd: string): Promise<LoadedMemory>;
212
+
213
+ // Get combined context string for system prompt
214
+ getContext(): string;
215
+
216
+ // Get context for specific file (includes path-scoped rules)
217
+ getContextForFile(filePath: string): string;
218
+
219
+ // Add content to memory via # prefix
220
+ async quickAdd(content: string, level: 'user' | 'project'): Promise<void>;
221
+
222
+ // Open memory file in editor
223
+ async editMemory(level?: MemoryLevel): Promise<void>;
224
+
225
+ // List loaded memory files
226
+ getLoadedFiles(): MemoryFile[];
227
+
228
+ // Resolve @imports in content
229
+ private resolveImports(content: string, basePath: string, depth: number): string;
230
+
231
+ // Parse frontmatter from rules files
232
+ private parseRuleFrontmatter(content: string): { paths?: string[]; body: string };
233
+
234
+ // Check if path matches glob patterns
235
+ private matchesGlob(filePath: string, patterns: string[]): boolean;
236
+ }
237
+ ```
238
+
239
+ ### /init Command Implementation
240
+
241
+ ```typescript
242
+ // src/commands/init-command.ts
243
+ interface InitCommandOptions {
244
+ improve?: boolean; // Improve existing MYCODE.md
245
+ force?: boolean; // Overwrite without confirmation
246
+ }
247
+
248
+ async function initCommand(context: CommandContext): Promise<void> {
249
+ const { agent, ui, cwd } = context;
250
+
251
+ ui.showMessage('Analyzing codebase...');
252
+
253
+ // Step 1: Gather context files
254
+ const contextFiles = await gatherContextFiles(cwd);
255
+
256
+ // Step 2: Check for existing MYCODE.md
257
+ const existingMycode = await findExistingMycode(cwd);
258
+
259
+ // Step 3: Build the init prompt
260
+ const prompt = buildInitPrompt(contextFiles, existingMycode);
261
+
262
+ // Step 4: Run agent with the prompt
263
+ ui.showMessage('Generating MYCODE.md...');
264
+ const result = await agent.run(prompt);
265
+
266
+ // Step 5: Write or confirm changes
267
+ const mycodeContent = extractMycodeContent(result);
268
+ await confirmAndWrite(cwd, mycodeContent, existingMycode, ui);
269
+ }
270
+
271
+ async function gatherContextFiles(cwd: string): Promise<Record<string, string>> {
272
+ const patterns = [
273
+ 'package*.json',
274
+ 'README.md',
275
+ 'CONTRIBUTING.md',
276
+ '.cursor/rules/**/*.md',
277
+ '.cursorrules',
278
+ '.github/copilot-instructions.md',
279
+ 'Cargo.toml',
280
+ 'go.mod',
281
+ 'pyproject.toml',
282
+ 'requirements.txt',
283
+ ];
284
+
285
+ const files: Record<string, string> = {};
286
+ for (const pattern of patterns) {
287
+ const matches = await glob(pattern, { cwd });
288
+ for (const match of matches.slice(0, 5)) { // Limit per pattern
289
+ const content = await readFile(path.join(cwd, match), 'utf-8');
290
+ if (content.length < 50000) { // Size limit
291
+ files[match] = content;
292
+ }
293
+ }
294
+ }
295
+ return files;
296
+ }
297
+
298
+ function buildInitPrompt(
299
+ contextFiles: Record<string, string>,
300
+ existingMycode?: string
301
+ ): string {
302
+ const contextParts = Object.entries(contextFiles)
303
+ .map(([path, content]) => `### ${path}\n\`\`\`\n${content}\n\`\`\``)
304
+ .join('\n\n');
305
+
306
+ return `
307
+ Please analyze this codebase and create a MYCODE.md file, which will be given
308
+ to future instances of mycode to operate in this repository.
309
+
310
+ ## Context Files
311
+
312
+ ${contextParts}
313
+
314
+ ${existingMycode ? `## Existing MYCODE.md\n\`\`\`\n${existingMycode}\n\`\`\`\n` : ''}
315
+
316
+ ## Instructions
317
+
318
+ What to add:
319
+ 1. Commands that will be commonly used, such as how to build, lint, and run tests.
320
+ Include the necessary commands to develop in this codebase, such as how to run
321
+ a single test.
322
+ 2. High-level code architecture and structure so that future instances can be
323
+ productive more quickly. Focus on the "big picture" architecture that requires
324
+ reading multiple files to understand.
325
+
326
+ Usage notes:
327
+ - ${existingMycode ? 'Suggest improvements to the existing MYCODE.md.' : 'Create a new MYCODE.md.'}
328
+ - Do not repeat yourself and do not include obvious instructions like "Provide
329
+ helpful error messages" or "Write tests for new code".
330
+ - Avoid listing every component or file structure that can be easily discovered.
331
+ - Don't include generic development practices.
332
+ - Do not make up information unless it's expressly included in the files above.
333
+ - Keep it concise - aim for ~20-30 lines.
334
+ - Prefix the file with:
335
+
336
+ # MYCODE.md
337
+
338
+ This file provides guidance to mycode when working with code in this repository.
339
+ `;
340
+ }
341
+ ```
342
+
343
+ ### Memory Loading Integration
344
+
345
+ ```typescript
346
+ // src/agent/agent.ts (modified)
347
+ class Agent {
348
+ private memoryManager: MemoryManager;
349
+
350
+ async run(prompt: string): Promise<AgentEvent[]> {
351
+ // Load memory at start of each run
352
+ const memory = await this.memoryManager.load(this.cwd);
353
+
354
+ // Build system prompt with memory context
355
+ const systemPrompt = this.buildSystemPrompt(memory);
356
+
357
+ // Continue with normal agent loop...
358
+ }
359
+
360
+ private buildSystemPrompt(memory: LoadedMemory): string {
361
+ const basePrompt = this.getBaseSystemPrompt();
362
+
363
+ if (memory.context) {
364
+ return `${basePrompt}
365
+
366
+ <claudeMd>
367
+ ${memory.context}
368
+ </claudeMd>
369
+
370
+ IMPORTANT: Follow the instructions above from MYCODE.md files. These are project-specific guidelines that take precedence over general behavior.
371
+ `;
372
+ }
373
+
374
+ return basePrompt;
375
+ }
376
+ }
377
+ ```
378
+
379
+ ### File Changes
380
+
381
+ | File | Action | Description |
382
+ |------|--------|-------------|
383
+ | `src/memory/types.ts` | Create | Memory system types |
384
+ | `src/memory/memory-manager.ts` | Create | Core memory management |
385
+ | `src/memory/import-resolver.ts` | Create | @import syntax handling |
386
+ | `src/memory/rules-parser.ts` | Create | .mycode/rules/ parsing |
387
+ | `src/memory/index.ts` | Create | Module exports |
388
+ | `src/commands/init-command.ts` | Create | /init command |
389
+ | `src/commands/memory-command.ts` | Create | /memory command |
390
+ | `src/agent/agent.ts` | Modify | Integrate memory loading |
391
+ | `src/cli/input-handler.ts` | Modify | Handle # prefix |
392
+
393
+ ## User Experience
394
+
395
+ ### Running /init
396
+
397
+ ```
398
+ $ mycode
399
+ > /init
400
+
401
+ Analyzing codebase...
402
+ Reading package.json
403
+ Reading README.md
404
+ Reading tsconfig.json
405
+ Found .cursorrules
406
+
407
+ Generating MYCODE.md...
408
+
409
+ ┌─ Generated MYCODE.md ─────────────────────────┐
410
+ │ │
411
+ │ # MYCODE.md │
412
+ │ │
413
+ │ This file provides guidance to mycode when │
414
+ │ working with code in this repository. │
415
+ │ │
416
+ │ ## Build Commands │
417
+ │ - `npm run build` - Compile TypeScript │
418
+ │ - `npm test` - Run all tests │
419
+ │ - `npm test -- path/to/test` - Single test │
420
+ │ │
421
+ │ ## Architecture │
422
+ │ - Provider abstraction in src/providers/ │
423
+ │ - Tool system in src/tools/ │
424
+ │ - Agent loop in src/agent/ │
425
+ │ │
426
+ └───────────────────────────────────────────────┘
427
+
428
+ Create MYCODE.md? [Yes] [Edit First] [Cancel]
429
+ ```
430
+
431
+ ### Quick Memory Add with #
432
+
433
+ ```
434
+ > # Always run npm run lint before committing
435
+
436
+ ✓ Added to project memory (MYCODE.md)
437
+ ```
438
+
439
+ ### /memory Command
440
+
441
+ ```
442
+ > /memory
443
+
444
+ Loaded Memory Files:
445
+ [1] ~/.mycode/MYCODE.md (user)
446
+ [2] ./MYCODE.md (project)
447
+ [3] ./.mycode/rules/api.md (rule, paths: src/api/**)
448
+
449
+ Select file to edit (1-3) or 'new' to create:
450
+ ```
451
+
452
+ ### Automatic Context Display
453
+
454
+ At session start:
455
+ ```
456
+ $ mycode
457
+ Loading context from:
458
+ ~/.mycode/MYCODE.md (user preferences)
459
+ ./MYCODE.md (project)
460
+ ./.mycode/rules/typescript.md (active)
461
+
462
+ mycode v0.2.0 | gpt-4o
463
+ >
464
+ ```
465
+
466
+ ## Alternatives Considered
467
+
468
+ ### Alternative 1: Database Storage
469
+ Store memory in SQLite.
470
+
471
+ **Pros**: Efficient queries, structured data
472
+ **Cons**: Not version-controllable, harder to share
473
+ **Decision**: Rejected - File-based is git-friendly
474
+
475
+ ### Alternative 2: Single Global File
476
+ Only support ~/.mycode/MYCODE.md.
477
+
478
+ **Pros**: Simple
479
+ **Cons**: No project-specific context
480
+ **Decision**: Rejected - Hierarchy is essential
481
+
482
+ ### Alternative 3: JSON Configuration
483
+ Use JSON instead of Markdown.
484
+
485
+ **Pros**: Structured, parseable
486
+ **Cons**: Less readable, harder for humans to write
487
+ **Decision**: Rejected - Markdown is more natural
488
+
489
+ ### Alternative 4: Skip /init
490
+ Let users create MYCODE.md manually.
491
+
492
+ **Pros**: Simpler
493
+ **Cons**: Poor onboarding, users don't know what to include
494
+ **Decision**: Rejected - /init provides great starting point
495
+
496
+ ## Security Considerations
497
+
498
+ 1. **Path Traversal**: Validate @import paths within project
499
+ 2. **File Size Limits**: Prevent memory exhaustion
500
+ 3. **Sensitive Data Warning**: Remind users not to include secrets
501
+ 4. **Import Depth Limit**: Prevent infinite recursion
502
+ 5. **Local Files**: MYCODE.local.md auto-added to .gitignore
503
+
504
+ ## Testing Strategy
505
+
506
+ 1. **Unit Tests**:
507
+ - Memory loading hierarchy
508
+ - @import resolution with depth limits
509
+ - Path glob matching for rules
510
+ - Frontmatter parsing
511
+
512
+ 2. **Integration Tests**:
513
+ - /init command end-to-end
514
+ - Memory injection into agent
515
+ - Directory-aware loading
516
+
517
+ 3. **Manual Testing**:
518
+ - Real projects with various structures
519
+ - Cursor/Copilot rule migration
520
+ - Team workflows
521
+
522
+ ## Migration Path
523
+
524
+ 1. **Phase 1**: Basic MYCODE.md loading (user + project)
525
+ 2. **Phase 2**: /init command implementation
526
+ 3. **Phase 3**: # prefix and /memory command
527
+ 4. **Phase 4**: @import syntax
528
+ 5. **Phase 5**: .mycode/rules/ with path scoping
529
+ 6. **Phase 6**: Directory-aware dynamic loading
530
+
531
+ ## References
532
+
533
+ - [Claude Code Memory Documentation](https://code.claude.com/docs/en/memory)
534
+ - [Piebald-AI/claude-code-system-prompts](https://github.com/Piebald-AI/claude-code-system-prompts) - Extracted prompts
535
+ - [How CLAUDE.md Works in Claude Code](https://gist.github.com/radleta/301666cfd7551b78d1378e18c82ba661)
536
+ - [Build your own /init command](https://kau.sh/blog/build-ai-init-command/)
537
+ - [Claude Code Best Practices: Memory Management](https://cuong.io/blog/2025/06/15-claude-code-best-practices-memory-management)
538
+ - [Modular Rules in Claude Code](https://claude-blog.setec.rs/blog/claude-code-rules-directory)
539
+ - [The Complete Guide to CLAUDE.md](https://www.builder.io/blog/claude-md-guide)