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.
- package/.gencode/settings.local.json +7 -0
- package/README.md +11 -11
- package/dist/agent/agent.d.ts +42 -1
- package/dist/agent/agent.d.ts.map +1 -1
- package/dist/agent/agent.js +82 -15
- package/dist/agent/agent.js.map +1 -1
- package/dist/cli/components/App.d.ts +8 -1
- package/dist/cli/components/App.d.ts.map +1 -1
- package/dist/cli/components/App.js +231 -29
- package/dist/cli/components/App.js.map +1 -1
- package/dist/cli/components/CommandSuggestions.d.ts.map +1 -1
- package/dist/cli/components/CommandSuggestions.js +2 -0
- package/dist/cli/components/CommandSuggestions.js.map +1 -1
- package/dist/cli/components/Header.d.ts +1 -1
- package/dist/cli/components/Header.d.ts.map +1 -1
- package/dist/cli/components/Header.js +4 -6
- package/dist/cli/components/Header.js.map +1 -1
- package/dist/cli/components/Logo.d.ts +1 -0
- package/dist/cli/components/Logo.d.ts.map +1 -1
- package/dist/cli/components/Logo.js +16 -3
- package/dist/cli/components/Logo.js.map +1 -1
- package/dist/cli/components/Messages.d.ts +4 -4
- package/dist/cli/components/Messages.d.ts.map +1 -1
- package/dist/cli/components/Messages.js +51 -25
- package/dist/cli/components/Messages.js.map +1 -1
- package/dist/cli/components/PermissionPrompt.d.ts +60 -0
- package/dist/cli/components/PermissionPrompt.d.ts.map +1 -0
- package/dist/cli/components/PermissionPrompt.js +192 -0
- package/dist/cli/components/PermissionPrompt.js.map +1 -0
- package/dist/cli/components/ProviderManager.js +3 -3
- package/dist/cli/components/ProviderManager.js.map +1 -1
- package/dist/cli/components/Spinner.d.ts +7 -2
- package/dist/cli/components/Spinner.d.ts.map +1 -1
- package/dist/cli/components/Spinner.js +116 -25
- package/dist/cli/components/Spinner.js.map +1 -1
- package/dist/cli/components/TodoList.d.ts +7 -0
- package/dist/cli/components/TodoList.d.ts.map +1 -0
- package/dist/cli/components/TodoList.js +34 -0
- package/dist/cli/components/TodoList.js.map +1 -0
- package/dist/cli/components/index.d.ts +1 -0
- package/dist/cli/components/index.d.ts.map +1 -1
- package/dist/cli/components/index.js +1 -0
- package/dist/cli/components/index.js.map +1 -1
- package/dist/cli/index.js +47 -7
- package/dist/cli/index.js.map +1 -1
- package/dist/config/index.d.ts +13 -4
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +18 -3
- package/dist/config/index.js.map +1 -1
- package/dist/config/levels.d.ts +49 -0
- package/dist/config/levels.d.ts.map +1 -0
- package/dist/config/levels.js +222 -0
- package/dist/config/levels.js.map +1 -0
- package/dist/config/loader.d.ts +46 -0
- package/dist/config/loader.d.ts.map +1 -0
- package/dist/config/loader.js +153 -0
- package/dist/config/loader.js.map +1 -0
- package/dist/config/manager.d.ts +115 -15
- package/dist/config/manager.d.ts.map +1 -1
- package/dist/config/manager.js +260 -34
- package/dist/config/manager.js.map +1 -1
- package/dist/config/manager.test.d.ts +5 -0
- package/dist/config/manager.test.d.ts.map +1 -0
- package/dist/config/manager.test.js +192 -0
- package/dist/config/manager.test.js.map +1 -0
- package/dist/config/merger.d.ts +56 -0
- package/dist/config/merger.d.ts.map +1 -0
- package/dist/config/merger.js +177 -0
- package/dist/config/merger.js.map +1 -0
- package/dist/config/test-utils.d.ts +24 -0
- package/dist/config/test-utils.d.ts.map +1 -0
- package/dist/config/test-utils.js +55 -0
- package/dist/config/test-utils.js.map +1 -0
- package/dist/config/types.d.ts +78 -9
- package/dist/config/types.d.ts.map +1 -1
- package/dist/config/types.js +52 -2
- package/dist/config/types.js.map +1 -1
- package/dist/memory/import-resolver.d.ts +46 -0
- package/dist/memory/import-resolver.d.ts.map +1 -0
- package/dist/memory/import-resolver.js +117 -0
- package/dist/memory/import-resolver.js.map +1 -0
- package/dist/memory/index.d.ts +7 -6
- package/dist/memory/index.d.ts.map +1 -1
- package/dist/memory/index.js +7 -5
- package/dist/memory/index.js.map +1 -1
- package/dist/memory/init-prompt.d.ts +22 -0
- package/dist/memory/init-prompt.d.ts.map +1 -0
- package/dist/memory/init-prompt.js +103 -0
- package/dist/memory/init-prompt.js.map +1 -0
- package/dist/memory/memory-manager.d.ts +119 -0
- package/dist/memory/memory-manager.d.ts.map +1 -0
- package/dist/memory/memory-manager.js +587 -0
- package/dist/memory/memory-manager.js.map +1 -0
- package/dist/memory/rules-parser.d.ts +38 -0
- package/dist/memory/rules-parser.d.ts.map +1 -0
- package/dist/memory/rules-parser.js +69 -0
- package/dist/memory/rules-parser.js.map +1 -0
- package/dist/memory/test-utils.d.ts +20 -0
- package/dist/memory/test-utils.d.ts.map +1 -0
- package/dist/memory/test-utils.js +44 -0
- package/dist/memory/test-utils.js.map +1 -0
- package/dist/memory/types.d.ts +70 -63
- package/dist/memory/types.d.ts.map +1 -1
- package/dist/memory/types.js +42 -2
- package/dist/memory/types.js.map +1 -1
- package/dist/permissions/audit.d.ts +82 -0
- package/dist/permissions/audit.d.ts.map +1 -0
- package/dist/permissions/audit.js +229 -0
- package/dist/permissions/audit.js.map +1 -0
- package/dist/permissions/index.d.ts +11 -1
- package/dist/permissions/index.d.ts.map +1 -1
- package/dist/permissions/index.js +15 -0
- package/dist/permissions/index.js.map +1 -1
- package/dist/permissions/manager.d.ts +149 -13
- package/dist/permissions/manager.d.ts.map +1 -1
- package/dist/permissions/manager.js +480 -35
- package/dist/permissions/manager.js.map +1 -1
- package/dist/permissions/manager.test.d.ts +5 -0
- package/dist/permissions/manager.test.d.ts.map +1 -0
- package/dist/permissions/manager.test.js +213 -0
- package/dist/permissions/manager.test.js.map +1 -0
- package/dist/permissions/persistence.d.ts +74 -0
- package/dist/permissions/persistence.d.ts.map +1 -0
- package/dist/permissions/persistence.js +248 -0
- package/dist/permissions/persistence.js.map +1 -0
- package/dist/permissions/persistence.test.d.ts +5 -0
- package/dist/permissions/persistence.test.d.ts.map +1 -0
- package/dist/permissions/persistence.test.js +171 -0
- package/dist/permissions/persistence.test.js.map +1 -0
- package/dist/permissions/prompt-matcher.d.ts +64 -0
- package/dist/permissions/prompt-matcher.d.ts.map +1 -0
- package/dist/permissions/prompt-matcher.js +415 -0
- package/dist/permissions/prompt-matcher.js.map +1 -0
- package/dist/permissions/prompt-matcher.test.d.ts +5 -0
- package/dist/permissions/prompt-matcher.test.d.ts.map +1 -0
- package/dist/permissions/prompt-matcher.test.js +107 -0
- package/dist/permissions/prompt-matcher.test.js.map +1 -0
- package/dist/permissions/types.d.ts +157 -0
- package/dist/permissions/types.d.ts.map +1 -1
- package/dist/permissions/types.js +43 -8
- package/dist/permissions/types.js.map +1 -1
- package/dist/prompts/index.d.ts +92 -0
- package/dist/prompts/index.d.ts.map +1 -0
- package/dist/prompts/index.js +241 -0
- package/dist/prompts/index.js.map +1 -0
- package/dist/tools/builtin/bash.d.ts.map +1 -1
- package/dist/tools/builtin/bash.js +2 -1
- package/dist/tools/builtin/bash.js.map +1 -1
- package/dist/tools/builtin/edit.d.ts.map +1 -1
- package/dist/tools/builtin/edit.js +2 -1
- package/dist/tools/builtin/edit.js.map +1 -1
- package/dist/tools/builtin/glob.d.ts.map +1 -1
- package/dist/tools/builtin/glob.js +2 -1
- package/dist/tools/builtin/glob.js.map +1 -1
- package/dist/tools/builtin/grep.d.ts.map +1 -1
- package/dist/tools/builtin/grep.js +2 -1
- package/dist/tools/builtin/grep.js.map +1 -1
- package/dist/tools/builtin/read.d.ts.map +1 -1
- package/dist/tools/builtin/read.js +2 -1
- package/dist/tools/builtin/read.js.map +1 -1
- package/dist/tools/builtin/todowrite.d.ts +15 -0
- package/dist/tools/builtin/todowrite.d.ts.map +1 -0
- package/dist/tools/builtin/todowrite.js +88 -0
- package/dist/tools/builtin/todowrite.js.map +1 -0
- package/dist/tools/builtin/webfetch.d.ts.map +1 -1
- package/dist/tools/builtin/webfetch.js +2 -5
- package/dist/tools/builtin/webfetch.js.map +1 -1
- package/dist/tools/builtin/websearch.d.ts.map +1 -1
- package/dist/tools/builtin/websearch.js +2 -16
- package/dist/tools/builtin/websearch.js.map +1 -1
- package/dist/tools/builtin/write.d.ts.map +1 -1
- package/dist/tools/builtin/write.js +2 -1
- package/dist/tools/builtin/write.js.map +1 -1
- package/dist/tools/index.d.ts +7 -0
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +4 -0
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/types.d.ts +22 -0
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/tools/types.js +8 -0
- package/dist/tools/types.js.map +1 -1
- package/docs/config-system-comparison.md +707 -0
- package/docs/memory-system.md +238 -0
- package/docs/permissions.md +368 -0
- package/docs/proposals/0005-todo-system.md +350 -85
- package/docs/proposals/0006-memory-system.md +11 -10
- package/docs/proposals/0012-ask-user-question.md +941 -206
- package/docs/proposals/0023-permission-enhancements.md +61 -2
- package/docs/proposals/0041-configuration-system.md +33 -2
- package/docs/proposals/0042-prompt-optimization.md +866 -0
- package/docs/proposals/README.md +6 -5
- package/jest.config.js +26 -0
- package/package.json +8 -2
- package/src/agent/agent.ts +111 -16
- package/src/cli/components/App.tsx +309 -36
- package/src/cli/components/CommandSuggestions.tsx +2 -0
- package/src/cli/components/Header.tsx +11 -17
- package/src/cli/components/Logo.tsx +76 -9
- package/src/cli/components/Messages.tsx +73 -53
- package/src/cli/components/PermissionPrompt.tsx +388 -0
- package/src/cli/components/ProviderManager.tsx +5 -5
- package/src/cli/components/Spinner.tsx +138 -25
- package/src/cli/components/TodoList.tsx +54 -0
- package/src/cli/components/index.ts +6 -0
- package/src/cli/index.tsx +54 -6
- package/src/config/index.ts +78 -4
- package/src/config/levels.test.ts +163 -0
- package/src/config/levels.ts +285 -0
- package/src/config/loader.test.ts +120 -0
- package/src/config/loader.ts +178 -0
- package/src/config/manager.test.ts +215 -0
- package/src/config/manager.ts +328 -40
- package/src/config/merger.test.ts +360 -0
- package/src/config/merger.ts +221 -0
- package/src/config/test-utils.ts +79 -0
- package/src/config/types.ts +152 -9
- package/src/memory/import-resolver.test.ts +117 -0
- package/src/memory/import-resolver.ts +149 -0
- package/src/memory/index.ts +11 -0
- package/src/memory/init-prompt.ts +113 -0
- package/src/memory/memory-manager.test.ts +198 -0
- package/src/memory/memory-manager.ts +716 -0
- package/src/memory/rules-parser.test.ts +182 -0
- package/src/memory/rules-parser.ts +82 -0
- package/src/memory/test-utils.ts +60 -0
- package/src/memory/types.ts +119 -0
- package/src/permissions/audit.ts +284 -0
- package/src/permissions/index.ts +20 -1
- package/src/permissions/manager.test.ts +260 -0
- package/src/permissions/manager.ts +592 -40
- package/src/permissions/persistence.test.ts +220 -0
- package/src/permissions/persistence.ts +301 -0
- package/src/permissions/prompt-matcher.test.ts +213 -0
- package/src/permissions/prompt-matcher.ts +472 -0
- package/src/permissions/types.ts +236 -8
- package/src/prompts/index.test.ts +279 -0
- package/src/prompts/index.ts +306 -0
- package/src/prompts/system/anthropic.txt +29 -0
- package/src/prompts/system/base.txt +124 -0
- package/src/prompts/system/gemini.txt +35 -0
- package/src/prompts/system/generic.txt +128 -0
- package/src/prompts/system/openai.txt +29 -0
- package/src/prompts/tools/bash.txt +60 -0
- package/src/prompts/tools/edit.txt +29 -0
- package/src/prompts/tools/glob.txt +35 -0
- package/src/prompts/tools/grep.txt +43 -0
- package/src/prompts/tools/read.txt +22 -0
- package/src/prompts/tools/todowrite.txt +71 -0
- package/src/prompts/tools/webfetch.txt +34 -0
- package/src/prompts/tools/websearch.txt +41 -0
- package/src/prompts/tools/write.txt +23 -0
- package/src/tools/builtin/bash.ts +2 -1
- package/src/tools/builtin/edit.ts +2 -1
- package/src/tools/builtin/glob.ts +2 -1
- package/src/tools/builtin/grep.ts +2 -1
- package/src/tools/builtin/read.ts +2 -1
- package/src/tools/builtin/todowrite.ts +102 -0
- package/src/tools/builtin/webfetch.ts +2 -5
- package/src/tools/builtin/websearch.ts +2 -16
- package/src/tools/builtin/write.ts +2 -1
- package/src/tools/index.ts +4 -0
- package/src/tools/types.ts +12 -0
- package/tsconfig.json +1 -1
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
# Memory System
|
|
2
|
+
|
|
3
|
+
GenCode implements a hierarchical memory system compatible with Claude Code's CLAUDE.md mechanism. Memory files provide persistent context that survives across sessions.
|
|
4
|
+
|
|
5
|
+
## Memory File Hierarchy
|
|
6
|
+
|
|
7
|
+
| Level | Primary (GenCode) | Fallback (Claude Code) |
|
|
8
|
+
|-------|-------------------|------------------------|
|
|
9
|
+
| User | `~/.gencode/AGENT.md` | `~/.claude/CLAUDE.md` |
|
|
10
|
+
| User Rules | `~/.gencode/rules/*.md` | `~/.claude/rules/*.md` |
|
|
11
|
+
| Project | `./AGENT.md` or `./.gencode/AGENT.md` | `./CLAUDE.md` or `./.claude/CLAUDE.md` |
|
|
12
|
+
| Project Rules | `./.gencode/rules/*.md` | `./.claude/rules/*.md` |
|
|
13
|
+
| Local | `./.gencode/AGENT.local.md` | `./.claude/CLAUDE.local.md` |
|
|
14
|
+
|
|
15
|
+
**Loading Logic**: Primary path is checked first; if not found, fallback path is used.
|
|
16
|
+
|
|
17
|
+
## Memory Loading Flow
|
|
18
|
+
|
|
19
|
+
### Claude Code Memory Flow
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
┌─────────────────────────────────────────────────────────────────────┐
|
|
23
|
+
│ Claude Code Memory Loading │
|
|
24
|
+
└─────────────────────────────────────────────────────────────────────┘
|
|
25
|
+
│
|
|
26
|
+
▼
|
|
27
|
+
┌─────────────────────────────────────────────────────────────────────┐
|
|
28
|
+
│ 1. User Level: ~/.claude/CLAUDE.md │
|
|
29
|
+
│ └── ~/.claude/rules/*.md (User rules, lower priority) │
|
|
30
|
+
└─────────────────────────────────────────────────────────────────────┘
|
|
31
|
+
│
|
|
32
|
+
▼
|
|
33
|
+
┌─────────────────────────────────────────────────────────────────────┐
|
|
34
|
+
│ 2. Project Level: ./CLAUDE.md or ./.claude/CLAUDE.md │
|
|
35
|
+
│ └── ./.claude/rules/*.md (Project rules, with paths: scoping) │
|
|
36
|
+
└─────────────────────────────────────────────────────────────────────┘
|
|
37
|
+
│
|
|
38
|
+
▼
|
|
39
|
+
┌─────────────────────────────────────────────────────────────────────┐
|
|
40
|
+
│ 3. Local Level: ./.claude/CLAUDE.local.md (gitignored) │
|
|
41
|
+
└─────────────────────────────────────────────────────────────────────┘
|
|
42
|
+
│
|
|
43
|
+
▼
|
|
44
|
+
┌─────────────────────────────────────────────────────────────────────┐
|
|
45
|
+
│ 4. Directory-specific: src/CLAUDE.md (on-demand when accessing src) │
|
|
46
|
+
└─────────────────────────────────────────────────────────────────────┘
|
|
47
|
+
│
|
|
48
|
+
▼
|
|
49
|
+
┌─────────────────────────────────────────────────────────────────────┐
|
|
50
|
+
│ Inject into <claudeMd> tag │
|
|
51
|
+
└─────────────────────────────────────────────────────────────────────┘
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### GenCode Memory Flow
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
┌─────────────────────────────────────────────────────────────────────┐
|
|
58
|
+
│ GenCode Memory Loading │
|
|
59
|
+
└─────────────────────────────────────────────────────────────────────┘
|
|
60
|
+
│
|
|
61
|
+
▼
|
|
62
|
+
┌─────────────────────────────────────────────────────────────────────┐
|
|
63
|
+
│ 1. User Level │
|
|
64
|
+
│ Primary: ~/.gencode/AGENT.md │
|
|
65
|
+
│ Fallback: ~/.claude/CLAUDE.md │
|
|
66
|
+
│ Rules: ~/.gencode/rules/*.md → ~/.claude/rules/*.md │
|
|
67
|
+
└─────────────────────────────────────────────────────────────────────┘
|
|
68
|
+
│
|
|
69
|
+
▼
|
|
70
|
+
┌─────────────────────────────────────────────────────────────────────┐
|
|
71
|
+
│ 2. Project Level │
|
|
72
|
+
│ Primary: ./AGENT.md or ./.gencode/AGENT.md │
|
|
73
|
+
│ Fallback: ./CLAUDE.md or ./.claude/CLAUDE.md │
|
|
74
|
+
│ Rules: ./.gencode/rules/*.md → ./.claude/rules/*.md │
|
|
75
|
+
│ (with paths: frontmatter for scoping) │
|
|
76
|
+
└─────────────────────────────────────────────────────────────────────┘
|
|
77
|
+
│
|
|
78
|
+
▼
|
|
79
|
+
┌─────────────────────────────────────────────────────────────────────┐
|
|
80
|
+
│ 3. Local Level (gitignored) │
|
|
81
|
+
│ Primary: ./.gencode/AGENT.local.md │
|
|
82
|
+
│ Fallback: ./.claude/CLAUDE.local.md │
|
|
83
|
+
└─────────────────────────────────────────────────────────────────────┘
|
|
84
|
+
│
|
|
85
|
+
▼
|
|
86
|
+
┌─────────────────────────────────────────────────────────────────────┐
|
|
87
|
+
│ 4. Resolve @imports (max 5 levels, circular detection) │
|
|
88
|
+
└─────────────────────────────────────────────────────────────────────┘
|
|
89
|
+
│
|
|
90
|
+
▼
|
|
91
|
+
┌─────────────────────────────────────────────────────────────────────┐
|
|
92
|
+
│ 5. Activate path-scoped rules based on current file │
|
|
93
|
+
└─────────────────────────────────────────────────────────────────────┘
|
|
94
|
+
│
|
|
95
|
+
▼
|
|
96
|
+
┌─────────────────────────────────────────────────────────────────────┐
|
|
97
|
+
│ Inject into <claudeMd> tag │
|
|
98
|
+
└─────────────────────────────────────────────────────────────────────┘
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Comparison Table
|
|
102
|
+
|
|
103
|
+
| Feature | Claude Code | GenCode |
|
|
104
|
+
|---------|-------------|---------|
|
|
105
|
+
| Primary filename | CLAUDE.md | AGENT.md |
|
|
106
|
+
| Fallback support | No | Yes (→ CLAUDE.md) |
|
|
107
|
+
| User directory | ~/.claude/ | ~/.gencode/ → ~/.claude/ |
|
|
108
|
+
| Project directory | .claude/ | .gencode/ → .claude/ |
|
|
109
|
+
| Rules directory | .claude/rules/ | .gencode/rules/ → .claude/rules/ |
|
|
110
|
+
| Path scoping | Yes (paths: frontmatter) | Yes (paths: frontmatter) |
|
|
111
|
+
| @import syntax | Yes | Yes (max 5 levels) |
|
|
112
|
+
| Local files | CLAUDE.local.md | AGENT.local.md |
|
|
113
|
+
| Directory-specific | Yes (on-demand) | Not in v1 |
|
|
114
|
+
|
|
115
|
+
## Commands
|
|
116
|
+
|
|
117
|
+
### /init
|
|
118
|
+
|
|
119
|
+
Analyzes your codebase and generates an AGENT.md file:
|
|
120
|
+
|
|
121
|
+
```
|
|
122
|
+
> /init
|
|
123
|
+
|
|
124
|
+
Analyzing codebase...
|
|
125
|
+
Found 3 context file(s): package.json, README.md, tsconfig.json
|
|
126
|
+
Generating AGENT.md...
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
The command:
|
|
130
|
+
1. Scans for package.json, README.md, Makefile, etc.
|
|
131
|
+
2. Builds a prompt asking the AI to generate project instructions
|
|
132
|
+
3. Creates or updates AGENT.md via the Write tool
|
|
133
|
+
|
|
134
|
+
### /memory
|
|
135
|
+
|
|
136
|
+
Shows all loaded memory files:
|
|
137
|
+
|
|
138
|
+
```
|
|
139
|
+
> /memory
|
|
140
|
+
|
|
141
|
+
Loaded Memory Files:
|
|
142
|
+
[1] ~/.gencode/AGENT.md (user, 1.2KB)
|
|
143
|
+
[2] ./AGENT.md (project, 856B)
|
|
144
|
+
|
|
145
|
+
Loaded Rules:
|
|
146
|
+
[1] .gencode/rules/api.md (project-rules, 234B)
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### # Quick Add
|
|
150
|
+
|
|
151
|
+
Add notes to memory directly:
|
|
152
|
+
|
|
153
|
+
```
|
|
154
|
+
# Always use 2-space indentation
|
|
155
|
+
Added to project memory: ./AGENT.md
|
|
156
|
+
|
|
157
|
+
## Prefer async/await over callbacks
|
|
158
|
+
Added to user memory: ~/.gencode/AGENT.md
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
- `# note` → adds to project memory
|
|
162
|
+
- `## note` → adds to user memory
|
|
163
|
+
|
|
164
|
+
## Rules Directory
|
|
165
|
+
|
|
166
|
+
Create path-scoped rules in `.gencode/rules/`:
|
|
167
|
+
|
|
168
|
+
```
|
|
169
|
+
your-project/
|
|
170
|
+
├── .gencode/
|
|
171
|
+
│ ├── AGENT.md # Main project instructions
|
|
172
|
+
│ └── rules/
|
|
173
|
+
│ ├── code-style.md # Always loaded
|
|
174
|
+
│ ├── testing.md # Always loaded
|
|
175
|
+
│ └── api.md # Only when working with API files
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### Path-Scoped Rules (Frontmatter)
|
|
179
|
+
|
|
180
|
+
```yaml
|
|
181
|
+
---
|
|
182
|
+
paths:
|
|
183
|
+
- "src/api/**/*.ts"
|
|
184
|
+
- "src/routes/**/*.ts"
|
|
185
|
+
---
|
|
186
|
+
|
|
187
|
+
# API Development Rules
|
|
188
|
+
|
|
189
|
+
- Use async/await consistently
|
|
190
|
+
- Always validate request inputs with Zod
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
Rules with `paths:` frontmatter only load when working with matching files.
|
|
194
|
+
|
|
195
|
+
## @import Syntax
|
|
196
|
+
|
|
197
|
+
Include other files in your memory files:
|
|
198
|
+
|
|
199
|
+
```markdown
|
|
200
|
+
# AGENT.md
|
|
201
|
+
|
|
202
|
+
@./docs/architecture.md
|
|
203
|
+
@./docs/conventions.md
|
|
204
|
+
|
|
205
|
+
## Project Overview
|
|
206
|
+
...
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
Features:
|
|
210
|
+
- Max 5 levels of nesting
|
|
211
|
+
- Circular import detection
|
|
212
|
+
- Path traversal protection
|
|
213
|
+
|
|
214
|
+
## System Prompt Integration
|
|
215
|
+
|
|
216
|
+
Memory content is injected into the system prompt:
|
|
217
|
+
|
|
218
|
+
```xml
|
|
219
|
+
<claudeMd>
|
|
220
|
+
Codebase and user instructions are shown below...
|
|
221
|
+
|
|
222
|
+
Contents of ~/.gencode/AGENT.md (user's private global instructions):
|
|
223
|
+
[user memory content]
|
|
224
|
+
|
|
225
|
+
Contents of ./AGENT.md (project instructions):
|
|
226
|
+
[project memory content]
|
|
227
|
+
|
|
228
|
+
Rule from .gencode/rules/api.md (applies to: src/api/**):
|
|
229
|
+
[rule content]
|
|
230
|
+
</claudeMd>
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
## Best Practices
|
|
234
|
+
|
|
235
|
+
1. **Keep memory concise** - Memory files are loaded every session
|
|
236
|
+
2. **Use rules for path-specific guidance** - Avoid cluttering main AGENT.md
|
|
237
|
+
3. **Use local files for personal notes** - .gitignore automatically includes them
|
|
238
|
+
4. **Leverage fallback for Claude Code users** - Existing CLAUDE.md files work automatically
|
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
# Permission System
|
|
2
|
+
|
|
3
|
+
GenCode includes a comprehensive permission system compatible with Claude Code's permission model. It provides fine-grained control over tool execution with pattern matching, prompt-based approvals, and persistent allowlists.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
The permission system controls which tool operations require user approval:
|
|
8
|
+
|
|
9
|
+
- **Auto-approved**: Read-only operations (Read, Glob, Grep, LSP)
|
|
10
|
+
- **Require confirmation**: Write operations (Write, Edit, Bash, WebFetch, WebSearch)
|
|
11
|
+
- **Denied**: Explicitly blocked operations
|
|
12
|
+
|
|
13
|
+
Users can configure additional rules via settings files to auto-approve or block specific operations.
|
|
14
|
+
|
|
15
|
+
## Permission Check Flow
|
|
16
|
+
|
|
17
|
+
### Claude Code Official Flow
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
┌─────────────────────────────────────────────────────────────────┐
|
|
21
|
+
│ Tool Execution Request │
|
|
22
|
+
└─────────────────────────────────────────────────────────────────┘
|
|
23
|
+
│
|
|
24
|
+
▼
|
|
25
|
+
┌────────────────────────┐
|
|
26
|
+
│ Check DENY Rules │
|
|
27
|
+
│ (settings.deny[]) │
|
|
28
|
+
└────────────────────────┘
|
|
29
|
+
│
|
|
30
|
+
┌────────────┴────────────┐
|
|
31
|
+
│ │
|
|
32
|
+
Match Found No Match
|
|
33
|
+
│ │
|
|
34
|
+
▼ ▼
|
|
35
|
+
┌──────────┐ ┌────────────────────────┐
|
|
36
|
+
│ DENIED │ │ Check ALLOW Rules │
|
|
37
|
+
│ (block) │ │ (settings.allow[]) │
|
|
38
|
+
└──────────┘ └────────────────────────┘
|
|
39
|
+
│
|
|
40
|
+
┌────────────┴────────────┐
|
|
41
|
+
│ │
|
|
42
|
+
Match Found No Match
|
|
43
|
+
│ │
|
|
44
|
+
▼ ▼
|
|
45
|
+
┌──────────┐ ┌────────────────────────┐
|
|
46
|
+
│ ALLOWED │ │ Check ASK Rules │
|
|
47
|
+
│ (auto) │ │ (settings.ask[]) │
|
|
48
|
+
└──────────┘ └────────────────────────┘
|
|
49
|
+
│
|
|
50
|
+
┌────────────┴────────────┐
|
|
51
|
+
│ │
|
|
52
|
+
Match Found No Match
|
|
53
|
+
│ │
|
|
54
|
+
▼ ▼
|
|
55
|
+
┌──────────┐ ┌──────────────┐
|
|
56
|
+
│ PROMPT │ │ Default │
|
|
57
|
+
│ User │ │ Behavior │
|
|
58
|
+
└──────────┘ └──────────────┘
|
|
59
|
+
│
|
|
60
|
+
┌────────────────┴────────────────┐
|
|
61
|
+
│ │
|
|
62
|
+
Read-only Tool Write Tool
|
|
63
|
+
│ │
|
|
64
|
+
▼ ▼
|
|
65
|
+
┌──────────┐ ┌──────────┐
|
|
66
|
+
│ ALLOWED │ │ PROMPT │
|
|
67
|
+
│ (auto) │ │ User │
|
|
68
|
+
└──────────┘ └──────────┘
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
**Key Points (Claude Code)**:
|
|
72
|
+
1. **deny** rules are checked first - they block regardless of other rules
|
|
73
|
+
2. **allow** rules are checked second - they auto-approve if matched
|
|
74
|
+
3. **ask** rules always prompt for confirmation
|
|
75
|
+
4. Default behavior depends on tool type (read-only vs write)
|
|
76
|
+
|
|
77
|
+
### GenCode Implementation Flow
|
|
78
|
+
|
|
79
|
+
GenCode follows the same 4-step flow as Claude Code:
|
|
80
|
+
|
|
81
|
+
```
|
|
82
|
+
┌─────────────────────────────────────────────────────────────────┐
|
|
83
|
+
│ Tool Execution Request │
|
|
84
|
+
└─────────────────────────────────────────────────────────────────┘
|
|
85
|
+
│
|
|
86
|
+
▼
|
|
87
|
+
┌────────────────────────┐
|
|
88
|
+
│ 1. Check DENY Rules │
|
|
89
|
+
│ (settings.deny[]) │
|
|
90
|
+
└────────────────────────┘
|
|
91
|
+
│
|
|
92
|
+
┌────────────┴────────────┐
|
|
93
|
+
│ │
|
|
94
|
+
Match Found No Match
|
|
95
|
+
│ │
|
|
96
|
+
▼ ▼
|
|
97
|
+
┌──────────┐ ┌────────────────────────┐
|
|
98
|
+
│ DENIED │ │ 2. Check ALLOW Rules │
|
|
99
|
+
│ (block) │ │ (settings.allow[]) │
|
|
100
|
+
└──────────┘ └────────────────────────┘
|
|
101
|
+
│
|
|
102
|
+
┌────────────┴────────────┐
|
|
103
|
+
│ │
|
|
104
|
+
Match Found No Match
|
|
105
|
+
│ │
|
|
106
|
+
▼ ▼
|
|
107
|
+
┌──────────┐ ┌────────────────────────┐
|
|
108
|
+
│ ALLOWED │ │ 3. Check ASK Rules │
|
|
109
|
+
│ (auto) │ │ (settings.ask[]) │
|
|
110
|
+
└──────────┘ └────────────────────────┘
|
|
111
|
+
│
|
|
112
|
+
┌────────────┴────────────┐
|
|
113
|
+
│ │
|
|
114
|
+
Match Found No Match
|
|
115
|
+
│ │
|
|
116
|
+
▼ ▼
|
|
117
|
+
┌──────────┐ ┌──────────────┐
|
|
118
|
+
│ PROMPT │ │ 4. Default │
|
|
119
|
+
│ User │ │ Behavior │
|
|
120
|
+
└──────────┘ └──────────────┘
|
|
121
|
+
│
|
|
122
|
+
┌────────────────┴────────────────┐
|
|
123
|
+
│ │
|
|
124
|
+
Read-only Tool Write Tool
|
|
125
|
+
│ │
|
|
126
|
+
▼ ▼
|
|
127
|
+
┌──────────┐ ┌──────────┐
|
|
128
|
+
│ ALLOWED │ │ PROMPT │
|
|
129
|
+
│ (auto) │ │ User │
|
|
130
|
+
└──────────┘ └──────────┘
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
**GenCode Implementation Details**:
|
|
134
|
+
|
|
135
|
+
| Step | Check | Source | Action on Match |
|
|
136
|
+
|------|-------|--------|-----------------|
|
|
137
|
+
| 1 | DENY Rules | `settings.deny[]` | Block immediately |
|
|
138
|
+
| 2 | ALLOW Rules | `settings.allow[]` + defaults + Plan mode + session cache | Allow immediately |
|
|
139
|
+
| 3 | ASK Rules | `settings.ask[]` | Force prompt (always) |
|
|
140
|
+
| 4 | Default | Tool type | Read-only → auto, Write → prompt |
|
|
141
|
+
|
|
142
|
+
**Step 2 (ALLOW) includes**:
|
|
143
|
+
- `settings.allow[]` rules
|
|
144
|
+
- Prompt-based permissions (Plan mode `allowedPrompts`)
|
|
145
|
+
- Session approval cache
|
|
146
|
+
|
|
147
|
+
**Default Auto-Approved Tools (read-only)**:
|
|
148
|
+
- Read, Glob, Grep, LSP
|
|
149
|
+
|
|
150
|
+
## Quick Reference
|
|
151
|
+
|
|
152
|
+
| Command | Description |
|
|
153
|
+
|---------|-------------|
|
|
154
|
+
| `/permissions` | View current permission rules |
|
|
155
|
+
| `/permissions audit` | View recent permission decisions |
|
|
156
|
+
| `/permissions stats` | View permission statistics |
|
|
157
|
+
|
|
158
|
+
## Configuration Hierarchy
|
|
159
|
+
|
|
160
|
+
GenCode uses a multi-level configuration system (Claude Code compatible):
|
|
161
|
+
|
|
162
|
+
| Level | Path | Description |
|
|
163
|
+
|-------|------|-------------|
|
|
164
|
+
| User (global) | `~/.claude/settings.json` | User-wide settings |
|
|
165
|
+
| Project | `.claude/settings.json` | Project settings (tracked in git) |
|
|
166
|
+
| Project local | `.claude/settings.local.json` | Project settings (gitignored) |
|
|
167
|
+
|
|
168
|
+
**Fallback**: If `.claude/` doesn't exist, GenCode falls back to `.gencode/` directories.
|
|
169
|
+
|
|
170
|
+
**Loading order**: User → Project → Project local (later overrides earlier for scalar values, arrays are concatenated)
|
|
171
|
+
|
|
172
|
+
### Configuration Merging
|
|
173
|
+
|
|
174
|
+
- **Scalar values** (e.g., `model`): Later values override earlier ones
|
|
175
|
+
- **Array values** (e.g., `permissions.allow`): Arrays are concatenated
|
|
176
|
+
|
|
177
|
+
```json
|
|
178
|
+
// ~/.claude/settings.json (user)
|
|
179
|
+
{ "permissions": { "allow": ["Bash(git:*)"] } }
|
|
180
|
+
|
|
181
|
+
// .claude/settings.local.json (project local)
|
|
182
|
+
{ "permissions": { "allow": ["WebSearch"] } }
|
|
183
|
+
|
|
184
|
+
// Result: allow = ["Bash(git:*)", "WebSearch"]
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
## Permission Rules
|
|
188
|
+
|
|
189
|
+
### Rule Format
|
|
190
|
+
|
|
191
|
+
Rules are configured in settings files using Claude Code format:
|
|
192
|
+
|
|
193
|
+
```json
|
|
194
|
+
{
|
|
195
|
+
"permissions": {
|
|
196
|
+
"allow": ["Bash(git add:*)", "WebSearch"],
|
|
197
|
+
"ask": ["Bash(npm run:*)"],
|
|
198
|
+
"deny": ["Bash(rm -rf:*)"]
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
| Array | Mode | Description |
|
|
204
|
+
|-------|------|-------------|
|
|
205
|
+
| `allow` | auto | Auto-approve matching operations |
|
|
206
|
+
| `ask` | confirm | Always require confirmation |
|
|
207
|
+
| `deny` | deny | Block matching operations |
|
|
208
|
+
|
|
209
|
+
### Pattern Syntax
|
|
210
|
+
|
|
211
|
+
- `Tool` - Match all operations for a tool
|
|
212
|
+
- `Tool(pattern)` - Match operations where input matches pattern
|
|
213
|
+
- `*` - Wildcard matching any characters
|
|
214
|
+
- `:` - Treated as whitespace separator
|
|
215
|
+
|
|
216
|
+
### Examples
|
|
217
|
+
|
|
218
|
+
| Pattern | Matches |
|
|
219
|
+
|---------|---------|
|
|
220
|
+
| `Bash(git:*)` | Any git command |
|
|
221
|
+
| `Bash(npm install:*)` | npm install commands |
|
|
222
|
+
| `Bash(npm run test:*)` | npm test commands |
|
|
223
|
+
| `WebSearch` | All web searches |
|
|
224
|
+
| `WebFetch(domain:github.com)` | Fetches from github.com |
|
|
225
|
+
|
|
226
|
+
## Approval Options
|
|
227
|
+
|
|
228
|
+
When a tool requires confirmation, you can choose:
|
|
229
|
+
|
|
230
|
+
1. **Yes** - Allow this specific operation once
|
|
231
|
+
2. **Yes, and don't ask again** - Add a persistent rule to project settings
|
|
232
|
+
3. **No** - Block this operation
|
|
233
|
+
|
|
234
|
+
When you select "don't ask again", the rule is saved to `.claude/settings.local.json` (or `.gencode/settings.local.json` if using GenCode directories).
|
|
235
|
+
|
|
236
|
+
## Prompt-Based Permissions
|
|
237
|
+
|
|
238
|
+
Semantic prompts allow natural language permission grants (used by plan mode):
|
|
239
|
+
|
|
240
|
+
```typescript
|
|
241
|
+
// From plan mode (ExitPlanMode style)
|
|
242
|
+
agent.addAllowedPrompts([
|
|
243
|
+
{ tool: "Bash", prompt: "run tests" },
|
|
244
|
+
{ tool: "Bash", prompt: "install dependencies" },
|
|
245
|
+
{ tool: "Bash", prompt: "build the project" }
|
|
246
|
+
]);
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
### Built-in Prompts
|
|
250
|
+
|
|
251
|
+
The system recognizes these semantic prompts:
|
|
252
|
+
|
|
253
|
+
| Prompt | Matches |
|
|
254
|
+
|--------|---------|
|
|
255
|
+
| "run tests" | npm test, pytest, go test, jest, vitest |
|
|
256
|
+
| "install dependencies" | npm install, pip install, cargo build |
|
|
257
|
+
| "build the project" | npm run build, make, cargo build |
|
|
258
|
+
| "git operations" | Any git command |
|
|
259
|
+
| "lint code" | eslint, pylint, cargo clippy |
|
|
260
|
+
| "format code" | prettier, black, gofmt |
|
|
261
|
+
| "start dev server" | npm run dev, go run, cargo run |
|
|
262
|
+
|
|
263
|
+
## Permission Scopes
|
|
264
|
+
|
|
265
|
+
### Session Scope
|
|
266
|
+
- In-memory only
|
|
267
|
+
- Cleared when session ends
|
|
268
|
+
- Created by selecting "Allow once"
|
|
269
|
+
|
|
270
|
+
### Project Scope
|
|
271
|
+
- Stored in `.claude/settings.local.json`
|
|
272
|
+
- Applies to current project
|
|
273
|
+
- Created by selecting "Don't ask again"
|
|
274
|
+
|
|
275
|
+
### Global Scope
|
|
276
|
+
- Stored in `~/.claude/settings.json`
|
|
277
|
+
- Applies to all projects
|
|
278
|
+
- Configured manually in settings file
|
|
279
|
+
|
|
280
|
+
## Audit Logging
|
|
281
|
+
|
|
282
|
+
Permission decisions are logged for transparency:
|
|
283
|
+
|
|
284
|
+
```
|
|
285
|
+
/permissions audit
|
|
286
|
+
|
|
287
|
+
Recent Permission Decisions:
|
|
288
|
+
Time Decision Tool Input
|
|
289
|
+
──────────────────────────────────────────────────────
|
|
290
|
+
10:42 allowed Bash git status
|
|
291
|
+
10:41 allowed Read src/index.ts
|
|
292
|
+
10:40 confirmed Write src/new.ts
|
|
293
|
+
10:38 denied Bash rm -rf /tmp/test
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
## Security Best Practices
|
|
297
|
+
|
|
298
|
+
1. **Start restrictive**: Default is to require confirmation for write operations
|
|
299
|
+
2. **Narrow patterns**: Use `git add:*` instead of `git:*`
|
|
300
|
+
3. **Review audit logs**: Check `/permissions audit` regularly
|
|
301
|
+
4. **Use project scope**: Limit auto-approvals to specific projects
|
|
302
|
+
5. **Avoid global allows for dangerous commands**: Configure per-project instead
|
|
303
|
+
|
|
304
|
+
## Default Behavior
|
|
305
|
+
|
|
306
|
+
| Tool | Default Mode | Description |
|
|
307
|
+
|------|--------------|-------------|
|
|
308
|
+
| Read | auto | File reading |
|
|
309
|
+
| Glob | auto | Pattern matching |
|
|
310
|
+
| Grep | auto | Content search |
|
|
311
|
+
| LSP | auto | Language server |
|
|
312
|
+
| Write | confirm | File creation |
|
|
313
|
+
| Edit | confirm | File modification |
|
|
314
|
+
| Bash | confirm | Shell execution |
|
|
315
|
+
| WebFetch | confirm | HTTP requests |
|
|
316
|
+
| WebSearch | confirm | Web search |
|
|
317
|
+
|
|
318
|
+
## API Reference
|
|
319
|
+
|
|
320
|
+
### PermissionManager
|
|
321
|
+
|
|
322
|
+
```typescript
|
|
323
|
+
import { PermissionManager } from 'gencode';
|
|
324
|
+
|
|
325
|
+
const manager = new PermissionManager({
|
|
326
|
+
projectPath: '/path/to/project',
|
|
327
|
+
enableAudit: true
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
// Initialize with settings
|
|
331
|
+
await manager.initialize({
|
|
332
|
+
allow: ['Bash(git:*)'],
|
|
333
|
+
ask: ['Bash(npm run:*)'],
|
|
334
|
+
deny: ['Bash(rm -rf:*)']
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
// Check permission
|
|
338
|
+
const decision = await manager.checkPermission({
|
|
339
|
+
tool: 'Bash',
|
|
340
|
+
input: { command: 'git status' }
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
// Add prompt-based permission
|
|
344
|
+
manager.addAllowedPrompts([
|
|
345
|
+
{ tool: 'Bash', prompt: 'run tests' }
|
|
346
|
+
]);
|
|
347
|
+
|
|
348
|
+
// Set callback for saving rules to settings
|
|
349
|
+
manager.setSaveRuleCallback(async (tool, pattern) => {
|
|
350
|
+
// Save to settings.local.json
|
|
351
|
+
});
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
### PromptMatcher
|
|
355
|
+
|
|
356
|
+
```typescript
|
|
357
|
+
import { PromptMatcher, parsePatternString } from 'gencode';
|
|
358
|
+
|
|
359
|
+
const matcher = new PromptMatcher();
|
|
360
|
+
|
|
361
|
+
// Check if input matches prompt
|
|
362
|
+
const matches = matcher.matches('run tests', { command: 'npm test' });
|
|
363
|
+
// true
|
|
364
|
+
|
|
365
|
+
// Parse pattern string
|
|
366
|
+
const parsed = parsePatternString('Bash(git add:*)');
|
|
367
|
+
// { tool: 'Bash', pattern: 'git add:*' }
|
|
368
|
+
```
|