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.
- package/.env.example +11 -0
- package/CLAUDE.md +70 -0
- package/LICENSE +21 -0
- package/README.md +117 -0
- package/dist/agent/agent.d.ts +84 -0
- package/dist/agent/agent.d.ts.map +1 -0
- package/dist/agent/agent.js +233 -0
- package/dist/agent/agent.js.map +1 -0
- package/dist/agent/index.d.ts +6 -0
- package/dist/agent/index.d.ts.map +1 -0
- package/dist/agent/index.js +6 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/agent/types.d.ts +47 -0
- package/dist/agent/types.d.ts.map +1 -0
- package/dist/agent/types.js +5 -0
- package/dist/agent/types.js.map +1 -0
- package/dist/cli/components/App.d.ts +14 -0
- package/dist/cli/components/App.d.ts.map +1 -0
- package/dist/cli/components/App.js +395 -0
- package/dist/cli/components/App.js.map +1 -0
- package/dist/cli/components/CommandSuggestions.d.ts +13 -0
- package/dist/cli/components/CommandSuggestions.d.ts.map +1 -0
- package/dist/cli/components/CommandSuggestions.js +32 -0
- package/dist/cli/components/CommandSuggestions.js.map +1 -0
- package/dist/cli/components/Header.d.ts +9 -0
- package/dist/cli/components/Header.d.ts.map +1 -0
- package/dist/cli/components/Header.js +13 -0
- package/dist/cli/components/Header.js.map +1 -0
- package/dist/cli/components/Input.d.ts +13 -0
- package/dist/cli/components/Input.d.ts.map +1 -0
- package/dist/cli/components/Input.js +27 -0
- package/dist/cli/components/Input.js.map +1 -0
- package/dist/cli/components/Logo.d.ts +2 -0
- package/dist/cli/components/Logo.d.ts.map +1 -0
- package/dist/cli/components/Logo.js +8 -0
- package/dist/cli/components/Logo.js.map +1 -0
- package/dist/cli/components/Messages.d.ts +37 -0
- package/dist/cli/components/Messages.d.ts.map +1 -0
- package/dist/cli/components/Messages.js +106 -0
- package/dist/cli/components/Messages.js.map +1 -0
- package/dist/cli/components/ModelSelector.d.ts +13 -0
- package/dist/cli/components/ModelSelector.d.ts.map +1 -0
- package/dist/cli/components/ModelSelector.js +72 -0
- package/dist/cli/components/ModelSelector.js.map +1 -0
- package/dist/cli/components/Spinner.d.ts +12 -0
- package/dist/cli/components/Spinner.d.ts.map +1 -0
- package/dist/cli/components/Spinner.js +45 -0
- package/dist/cli/components/Spinner.js.map +1 -0
- package/dist/cli/components/index.d.ts +12 -0
- package/dist/cli/components/index.d.ts.map +1 -0
- package/dist/cli/components/index.js +12 -0
- package/dist/cli/components/index.js.map +1 -0
- package/dist/cli/components/theme.d.ts +31 -0
- package/dist/cli/components/theme.d.ts.map +1 -0
- package/dist/cli/components/theme.js +36 -0
- package/dist/cli/components/theme.js.map +1 -0
- package/dist/cli/index-legacy.d.ts +7 -0
- package/dist/cli/index-legacy.d.ts.map +1 -0
- package/dist/cli/index-legacy.js +431 -0
- package/dist/cli/index-legacy.js.map +1 -0
- package/dist/cli/index.d.ts +7 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +116 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/ink-cli.d.ts +7 -0
- package/dist/cli/ink-cli.d.ts.map +1 -0
- package/dist/cli/ink-cli.js +105 -0
- package/dist/cli/ink-cli.js.map +1 -0
- package/dist/cli/session-picker.d.ts +16 -0
- package/dist/cli/session-picker.d.ts.map +1 -0
- package/dist/cli/session-picker.js +280 -0
- package/dist/cli/session-picker.js.map +1 -0
- package/dist/cli/ui.d.ts +61 -0
- package/dist/cli/ui.d.ts.map +1 -0
- package/dist/cli/ui.js +364 -0
- package/dist/cli/ui.js.map +1 -0
- package/dist/config/index.d.ts +7 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +6 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/manager.d.ts +31 -0
- package/dist/config/manager.d.ts.map +1 -0
- package/dist/config/manager.js +65 -0
- package/dist/config/manager.js.map +1 -0
- package/dist/config/types.d.ts +22 -0
- package/dist/config/types.d.ts.map +1 -0
- package/dist/config/types.js +6 -0
- package/dist/config/types.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/memory/index.d.ts +10 -0
- package/dist/memory/index.d.ts.map +1 -0
- package/dist/memory/index.js +9 -0
- package/dist/memory/index.js.map +1 -0
- package/dist/memory/init.d.ts +20 -0
- package/dist/memory/init.d.ts.map +1 -0
- package/dist/memory/init.js +332 -0
- package/dist/memory/init.js.map +1 -0
- package/dist/memory/manager.d.ts +85 -0
- package/dist/memory/manager.d.ts.map +1 -0
- package/dist/memory/manager.js +234 -0
- package/dist/memory/manager.js.map +1 -0
- package/dist/memory/types.d.ts +74 -0
- package/dist/memory/types.d.ts.map +1 -0
- package/dist/memory/types.js +6 -0
- package/dist/memory/types.js.map +1 -0
- package/dist/permissions/index.d.ts +7 -0
- package/dist/permissions/index.d.ts.map +1 -0
- package/dist/permissions/index.js +6 -0
- package/dist/permissions/index.js.map +1 -0
- package/dist/permissions/manager.d.ts +32 -0
- package/dist/permissions/manager.d.ts.map +1 -0
- package/dist/permissions/manager.js +79 -0
- package/dist/permissions/manager.js.map +1 -0
- package/dist/permissions/types.d.ts +14 -0
- package/dist/permissions/types.d.ts.map +1 -0
- package/dist/permissions/types.js +17 -0
- package/dist/permissions/types.js.map +1 -0
- package/dist/providers/anthropic.d.ts +20 -0
- package/dist/providers/anthropic.d.ts.map +1 -0
- package/dist/providers/anthropic.js +185 -0
- package/dist/providers/anthropic.js.map +1 -0
- package/dist/providers/gemini.d.ts +21 -0
- package/dist/providers/gemini.d.ts.map +1 -0
- package/dist/providers/gemini.js +241 -0
- package/dist/providers/gemini.js.map +1 -0
- package/dist/providers/index.d.ts +34 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/index.js +72 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/providers/openai.d.ts +19 -0
- package/dist/providers/openai.d.ts.map +1 -0
- package/dist/providers/openai.js +221 -0
- package/dist/providers/openai.js.map +1 -0
- package/dist/providers/types.d.ts +125 -0
- package/dist/providers/types.d.ts.map +1 -0
- package/dist/providers/types.js +6 -0
- package/dist/providers/types.js.map +1 -0
- package/dist/session/index.d.ts +6 -0
- package/dist/session/index.d.ts.map +1 -0
- package/dist/session/index.js +6 -0
- package/dist/session/index.js.map +1 -0
- package/dist/session/manager.d.ts +101 -0
- package/dist/session/manager.d.ts.map +1 -0
- package/dist/session/manager.js +295 -0
- package/dist/session/manager.js.map +1 -0
- package/dist/session/types.d.ts +39 -0
- package/dist/session/types.d.ts.map +1 -0
- package/dist/session/types.js +10 -0
- package/dist/session/types.js.map +1 -0
- package/dist/tools/builtin/bash.d.ts +7 -0
- package/dist/tools/builtin/bash.d.ts.map +1 -0
- package/dist/tools/builtin/bash.js +80 -0
- package/dist/tools/builtin/bash.js.map +1 -0
- package/dist/tools/builtin/edit.d.ts +7 -0
- package/dist/tools/builtin/edit.d.ts.map +1 -0
- package/dist/tools/builtin/edit.js +32 -0
- package/dist/tools/builtin/edit.js.map +1 -0
- package/dist/tools/builtin/glob.d.ts +7 -0
- package/dist/tools/builtin/glob.d.ts.map +1 -0
- package/dist/tools/builtin/glob.js +36 -0
- package/dist/tools/builtin/glob.js.map +1 -0
- package/dist/tools/builtin/grep.d.ts +7 -0
- package/dist/tools/builtin/grep.d.ts.map +1 -0
- package/dist/tools/builtin/grep.js +59 -0
- package/dist/tools/builtin/grep.js.map +1 -0
- package/dist/tools/builtin/read.d.ts +7 -0
- package/dist/tools/builtin/read.d.ts.map +1 -0
- package/dist/tools/builtin/read.js +29 -0
- package/dist/tools/builtin/read.js.map +1 -0
- package/dist/tools/builtin/write.d.ts +7 -0
- package/dist/tools/builtin/write.d.ts.map +1 -0
- package/dist/tools/builtin/write.js +24 -0
- package/dist/tools/builtin/write.js.map +1 -0
- package/dist/tools/index.d.ts +38 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +32 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/registry.d.ts +22 -0
- package/dist/tools/registry.d.ts.map +1 -0
- package/dist/tools/registry.js +71 -0
- package/dist/tools/registry.js.map +1 -0
- package/dist/tools/types.d.ts +62 -0
- package/dist/tools/types.d.ts.map +1 -0
- package/dist/tools/types.js +126 -0
- package/dist/tools/types.js.map +1 -0
- package/docs/README.md +16 -0
- package/docs/proposals/0001-web-fetch-tool.md +293 -0
- package/docs/proposals/0002-web-search-tool.md +306 -0
- package/docs/proposals/0003-task-subagents.md +333 -0
- package/docs/proposals/0004-plan-mode.md +338 -0
- package/docs/proposals/0005-todo-system.md +299 -0
- package/docs/proposals/0006-memory-system.md +539 -0
- package/docs/proposals/0007-context-management.md +429 -0
- package/docs/proposals/0008-checkpointing.md +327 -0
- package/docs/proposals/0009-hooks-system.md +343 -0
- package/docs/proposals/0010-mcp-integration.md +382 -0
- package/docs/proposals/0011-custom-commands.md +374 -0
- package/docs/proposals/0012-ask-user-question.md +317 -0
- package/docs/proposals/0013-multi-edit-tool.md +345 -0
- package/docs/proposals/0014-lsp-tool.md +478 -0
- package/docs/proposals/0015-ls-tool.md +407 -0
- package/docs/proposals/0016-kill-shell-tool.md +455 -0
- package/docs/proposals/0017-background-tasks.md +489 -0
- package/docs/proposals/0018-parallel-tool-execution.md +415 -0
- package/docs/proposals/0019-session-enhancements.md +462 -0
- package/docs/proposals/0020-session-summarization.md +447 -0
- package/docs/proposals/0021-skills-system.md +409 -0
- package/docs/proposals/0022-plugin-system.md +467 -0
- package/docs/proposals/0023-permission-enhancements.md +470 -0
- package/docs/proposals/0024-keyboard-shortcuts.md +443 -0
- package/docs/proposals/0025-cost-tracking.md +447 -0
- package/docs/proposals/0026-git-integration.md +475 -0
- package/docs/proposals/0027-enhanced-read-tool.md +514 -0
- package/docs/proposals/0028-enhanced-bash-tool.md +511 -0
- package/docs/proposals/0029-notebook-edit-tool.md +413 -0
- package/docs/proposals/0030-plugin-marketplace.md +360 -0
- package/docs/proposals/0031-command-suggestions.md +295 -0
- package/docs/proposals/0032-ide-integrations.md +328 -0
- package/docs/proposals/0033-enterprise-deployment.md +221 -0
- package/docs/proposals/0034-sandboxing.md +273 -0
- package/docs/proposals/0035-auto-updater.md +311 -0
- package/docs/proposals/0036-enhanced-glob-tool.md +267 -0
- package/docs/proposals/0037-enhanced-grep-tool.md +360 -0
- package/docs/proposals/0038-interactive-cli-ui.md +373 -0
- package/docs/proposals/0039-streaming-enhancements.md +359 -0
- package/docs/proposals/0040-multi-provider-enhancements.md +369 -0
- package/docs/proposals/README.md +84 -0
- package/docs/proposals/TEMPLATE.md +57 -0
- package/docs/proposals/research/claude-code-research.md +307 -0
- package/examples/agent-demo.ts +115 -0
- package/examples/basic.ts +166 -0
- package/package.json +50 -0
- package/src/agent/agent.ts +276 -0
- package/src/agent/index.ts +6 -0
- package/src/agent/types.ts +62 -0
- package/src/cli/components/App.tsx +565 -0
- package/src/cli/components/CommandSuggestions.tsx +58 -0
- package/src/cli/components/Header.tsx +36 -0
- package/src/cli/components/Input.tsx +60 -0
- package/src/cli/components/Logo.tsx +16 -0
- package/src/cli/components/Messages.tsx +210 -0
- package/src/cli/components/ModelSelector.tsx +135 -0
- package/src/cli/components/Spinner.tsx +72 -0
- package/src/cli/components/index.ts +21 -0
- package/src/cli/components/theme.ts +36 -0
- package/src/cli/index.tsx +136 -0
- package/src/config/index.ts +7 -0
- package/src/config/manager.ts +77 -0
- package/src/config/types.ts +25 -0
- package/src/index.ts +86 -0
- package/src/permissions/index.ts +7 -0
- package/src/permissions/manager.ts +97 -0
- package/src/permissions/types.ts +29 -0
- package/src/providers/anthropic.ts +224 -0
- package/src/providers/gemini.ts +295 -0
- package/src/providers/index.ts +97 -0
- package/src/providers/openai.ts +261 -0
- package/src/providers/types.ts +181 -0
- package/src/session/index.ts +6 -0
- package/src/session/manager.ts +354 -0
- package/src/session/types.ts +49 -0
- package/src/tools/builtin/bash.ts +92 -0
- package/src/tools/builtin/edit.ts +37 -0
- package/src/tools/builtin/glob.ts +42 -0
- package/src/tools/builtin/grep.ts +67 -0
- package/src/tools/builtin/read.ts +34 -0
- package/src/tools/builtin/write.ts +27 -0
- package/src/tools/index.ts +36 -0
- package/src/tools/registry.ts +83 -0
- package/src/tools/types.ts +172 -0
- 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)
|