@korl3one/ccode 2.2.0 → 3.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/README.md +143 -103
- package/dist/ai/claude.d.ts +2 -1
- package/dist/ai/claude.js +15 -12
- package/dist/ai/gemini.d.ts +13 -1
- package/dist/ai/gemini.js +62 -15
- package/dist/ai/manager.d.ts +25 -6
- package/dist/ai/manager.js +83 -21
- package/dist/cli/brand.js +1 -1
- package/dist/cli/index.js +258 -97
- package/dist/core/exports.d.ts +74 -0
- package/dist/core/exports.js +303 -0
- package/package.json +11 -5
- package/dist/ai/deepseek.d.ts +0 -11
- package/dist/ai/deepseek.js +0 -35
- package/dist/ai/groq.d.ts +0 -11
- package/dist/ai/groq.js +0 -35
- package/dist/ai/ollama.d.ts +0 -10
- package/dist/ai/ollama.js +0 -27
- package/dist/ai/openai.d.ts +0 -10
- package/dist/ai/openai.js +0 -34
package/README.md
CHANGED
|
@@ -1,93 +1,89 @@
|
|
|
1
|
-
|
|
2
|
-
██████╗ ██████╗ ██████╗ ██████╗ ███████╗
|
|
3
|
-
██╔════╝██╔════╝ ██╔═══██╗██╔══██╗██╔════╝
|
|
4
|
-
██║ ██║ ██║ ██║██║ ██║█████╗
|
|
5
|
-
██║ ██║ ██║ ██║██║ ██║██╔══╝
|
|
6
|
-
╚██████╗╚██████╗ ╚██████╔╝██████╔╝███████╗
|
|
7
|
-
╚═════╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚══════╝
|
|
8
|
-
```
|
|
1
|
+
<div align="center">
|
|
9
2
|
|
|
10
|
-
|
|
3
|
+
<img src="assets/logo.png" alt="CCODE" width="600"/>
|
|
4
|
+
|
|
5
|
+
<br/>
|
|
6
|
+
<br/>
|
|
11
7
|
|
|
12
8
|
**Persistent context CLI for AI-assisted development.**
|
|
13
9
|
|
|
14
10
|
Stop re-explaining your project to AI every time the session resets.
|
|
15
11
|
|
|
12
|
+
<br/>
|
|
13
|
+
|
|
16
14
|
```bash
|
|
17
15
|
npm install -g @korl3one/ccode
|
|
18
|
-
ccode init
|
|
19
16
|
```
|
|
20
17
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
[](https://www.npmjs.com/package/@korl3one/ccode)
|
|
21
|
+
[](LICENSE)
|
|
22
|
+
[](https://nodejs.org)
|
|
23
|
+
[](https://github.com/iDevelop25/ccode)
|
|
24
|
+
|
|
25
|
+
</div>
|
|
24
26
|
|
|
25
27
|
---
|
|
26
28
|
|
|
27
29
|
## The problem
|
|
28
30
|
|
|
29
|
-
Every time you switch sessions, models, or tools when working with AI, you lose your project context
|
|
31
|
+
Every time you switch sessions, models, or tools when working with AI, **you lose your project context**. You end up re-explaining the architecture, previous decisions, and current state over and over again.
|
|
30
32
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
CCODE stores your project context **inside the repository**. One command generates professional documentation, architecture, rules, and a verifiable task checklist — all adapted to your project's actual complexity.
|
|
33
|
+
And if you use multiple AI tools — Claude Code, Cursor, Gemini CLI, Copilot — you have to configure context files for each one manually.
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
## The solution
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
CCODE generates and maintains your project context **inside the repository**. One command produces professional documentation, architecture, rules, and a verifiable task checklist — all adapted to your project's actual complexity.
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
Then it **syncs that context to every major AI tool** automatically.
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
$ ccode init
|
|
41
|
+
Any developer or AI can read your project and understand it instantly.
|
|
43
42
|
|
|
44
|
-
|
|
45
|
-
██╔════╝██╔════╝ ██╔═══██╗██╔══██╗██╔════╝
|
|
46
|
-
██║ ██║ ██║ ██║██║ ██║█████╗
|
|
47
|
-
╚██████╗╚██████╗ ╚██████╔╝██████╔╝███████╗
|
|
48
|
-
╚═════╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚══════╝
|
|
43
|
+
---
|
|
49
44
|
|
|
50
|
-
|
|
45
|
+
## Universal Context Sync
|
|
51
46
|
|
|
52
|
-
|
|
47
|
+
This is what makes CCODE different. One command generates context files for **every major AI tool**:
|
|
53
48
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
├── rules.md Estandares de desarrollo
|
|
58
|
-
├── tasks.json Checklist de tareas (8 tareas)
|
|
59
|
-
├── context.json Configuracion
|
|
60
|
-
├── state.json Estado del workflow
|
|
61
|
-
└── memory.md Historial de decisiones
|
|
49
|
+
```bash
|
|
50
|
+
ccode sync
|
|
51
|
+
```
|
|
62
52
|
|
|
63
|
-
|
|
53
|
+
```
|
|
54
|
+
project/
|
|
55
|
+
├── AGENTS.md ← Open Standard (60K+ repos)
|
|
56
|
+
├── CLAUDE.md ← Claude Code
|
|
57
|
+
├── GEMINI.md ← Gemini CLI
|
|
58
|
+
├── .cursorrules ← Cursor
|
|
59
|
+
├── .github/copilot-instructions.md ← GitHub Copilot
|
|
60
|
+
└── .ccode/context-export.md ← Universal (copy/paste to any AI chat)
|
|
61
|
+
```
|
|
64
62
|
|
|
65
|
-
|
|
66
|
-
> Tarea activa: TASK-002 — Crear formulario de login
|
|
63
|
+
Each file is adapted to the tool's expected format. Your project context — architecture, rules, tasks, decisions — synced everywhere, from a single source of truth.
|
|
67
64
|
|
|
68
|
-
|
|
69
|
-
> Verificar progreso (se detectaron cambios)
|
|
70
|
-
Marcar tarea como completada
|
|
71
|
-
Iniciar siguiente tarea
|
|
72
|
-
Ver estado completo
|
|
73
|
-
Salir
|
|
74
|
-
```
|
|
65
|
+
No manual setup per tool. No copy-pasting between files. Context stays in sync automatically with `ccode init`, `ccode update`, and `ccode sync`.
|
|
75
66
|
|
|
76
67
|
---
|
|
77
68
|
|
|
78
69
|
## Why CCODE?
|
|
79
70
|
|
|
71
|
+
<div align="center">
|
|
72
|
+
|
|
80
73
|
| | CCODE | Manual prompts |
|
|
81
74
|
|---|:---:|:---:|
|
|
82
75
|
| Persistent project context | ✅ | ❌ |
|
|
76
|
+
| Universal context sync (5+ AI tools) | ✅ | ❌ |
|
|
83
77
|
| Architecture adapted to complexity | ✅ | ❌ |
|
|
84
78
|
| AI-ready documentation | ✅ | ❌ |
|
|
85
79
|
| Verifiable task checklist | ✅ | ❌ |
|
|
86
80
|
| Auto-detect file changes | ✅ | ❌ |
|
|
87
81
|
| AI-powered task verification | ✅ | ❌ |
|
|
88
|
-
|
|
|
82
|
+
| Zero-config AI provider detection | ✅ | ❌ |
|
|
89
83
|
| Context lives in the repo (Git) | ✅ | ❌ |
|
|
90
84
|
|
|
85
|
+
</div>
|
|
86
|
+
|
|
91
87
|
---
|
|
92
88
|
|
|
93
89
|
## How it works
|
|
@@ -99,15 +95,21 @@ cd my-project
|
|
|
99
95
|
ccode init
|
|
100
96
|
```
|
|
101
97
|
|
|
102
|
-
A step-by-step wizard asks about your project and an AI generates the full context. CCODE adapts automatically
|
|
98
|
+
A step-by-step wizard asks about your project and an AI generates the full context. CCODE **adapts automatically**:
|
|
99
|
+
|
|
100
|
+
| Project type | Context depth | Tasks |
|
|
101
|
+
|---|---|---|
|
|
102
|
+
| Simple (prototype, few features) | Lightweight docs | 3-5 |
|
|
103
|
+
| Medium (standard app) | Moderate architecture | 5-8 |
|
|
104
|
+
| Complex (multiple modules) | Detailed patterns + diagrams | 8-12 |
|
|
105
|
+
|
|
106
|
+
A simple login doesn't need microservice diagrams. CCODE is smart about it.
|
|
103
107
|
|
|
104
|
-
|
|
105
|
-
- **Medium project** (standard app) → moderate context, 5-8 tasks
|
|
106
|
-
- **Complex project** (multiple modules, integrations) → detailed architecture, 8-12 tasks
|
|
108
|
+
After generation, context is automatically synced to all AI tools.
|
|
107
109
|
|
|
108
110
|
### 2. Persistent session
|
|
109
111
|
|
|
110
|
-
After init, CCODE stays active — watching your project in real time:
|
|
112
|
+
After init, CCODE **stays active** — watching your project in real time:
|
|
111
113
|
|
|
112
114
|
- Detects file changes automatically
|
|
113
115
|
- Suggests verifying tasks when it sees progress
|
|
@@ -130,40 +132,50 @@ CCODE compares **acceptance criteria** against **actual project files**:
|
|
|
130
132
|
○ TASK-003: Implement JWT auth — PENDING
|
|
131
133
|
```
|
|
132
134
|
|
|
133
|
-
|
|
135
|
+
It doesn't guess — it verifies.
|
|
136
|
+
|
|
137
|
+
### 4. Context sync
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
ccode sync
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Regenerates context files for every AI tool. Run it after making significant changes, or let `ccode update` handle it when you re-analyze the project.
|
|
144
|
+
|
|
145
|
+
### 5. Context export
|
|
134
146
|
|
|
135
147
|
```bash
|
|
136
148
|
ccode export
|
|
137
149
|
```
|
|
138
150
|
|
|
139
|
-
|
|
151
|
+
Three options: sync to all tools, export a universal `.md` for copy/paste into any AI chat, or pick specific tools.
|
|
140
152
|
|
|
141
|
-
###
|
|
153
|
+
### 6. Project health check
|
|
142
154
|
|
|
143
155
|
```bash
|
|
144
156
|
ccode doctor
|
|
145
157
|
```
|
|
146
158
|
|
|
147
|
-
|
|
148
|
-
✓ Contexto generado
|
|
149
|
-
✓ Proveedor de IA configurado
|
|
150
|
-
⚠ 2 tareas sin completar
|
|
151
|
-
⚠ architecture.md no refleja 3 archivos nuevos
|
|
152
|
-
✓ Conexion con IA activa
|
|
153
|
-
```
|
|
159
|
+
Like a linter, but for your project context. Checks context files, AI connection, task status, export state, and tells you what needs attention.
|
|
154
160
|
|
|
155
161
|
---
|
|
156
162
|
|
|
157
163
|
## Supported AI Providers
|
|
158
164
|
|
|
165
|
+
<div align="center">
|
|
166
|
+
|
|
159
167
|
| Provider | Models | Note |
|
|
160
168
|
|----------|--------|------|
|
|
161
|
-
| **
|
|
162
|
-
| **
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
169
|
+
| **Google Gemini** | 2.5 Flash, 2.5 Pro, 2.0 Flash | Free — just a Google account |
|
|
170
|
+
| **Claude** (Anthropic) | Sonnet 4, Haiku 3.5, Opus 4 | Best quality |
|
|
171
|
+
|
|
172
|
+
</div>
|
|
173
|
+
|
|
174
|
+
CCODE auto-detects your provider:
|
|
175
|
+
|
|
176
|
+
1. **Gemini CLI OAuth** — If you have `gemini` CLI installed and authenticated, it works instantly. Zero config.
|
|
177
|
+
2. **Environment variables** — `GOOGLE_API_KEY` or `ANTHROPIC_API_KEY` detected automatically.
|
|
178
|
+
3. **Manual setup** — Guided wizard with browser-based key generation as fallback.
|
|
167
179
|
|
|
168
180
|
---
|
|
169
181
|
|
|
@@ -171,29 +183,49 @@ ccode doctor
|
|
|
171
183
|
|
|
172
184
|
| Command | What it does |
|
|
173
185
|
|---------|-------------|
|
|
174
|
-
| `ccode init` | Interactive wizard — generates full project context |
|
|
175
|
-
| `ccode
|
|
176
|
-
| `ccode
|
|
177
|
-
| `ccode
|
|
178
|
-
| `ccode
|
|
179
|
-
| `ccode connect` | Configure AI provider |
|
|
186
|
+
| `ccode init` | Interactive wizard — generates full project context + syncs to all AI tools |
|
|
187
|
+
| `ccode sync` | Sync context to all AI tools (AGENTS.md, CLAUDE.md, .cursorrules, ...) |
|
|
188
|
+
| `ccode update` | Re-analyze project with AI and refresh context |
|
|
189
|
+
| `ccode export` | Export context — all tools, universal .md, or pick specific |
|
|
190
|
+
| `ccode verify` | AI-powered task verification against actual project files |
|
|
180
191
|
| `ccode status` | Dashboard with progress bar and stats |
|
|
192
|
+
| `ccode doctor` | Health check — context files, AI connection, exports, tasks |
|
|
193
|
+
| `ccode connect` | Configure or reconfigure AI provider |
|
|
194
|
+
| `ccode explain` | Quick project summary for onboarding |
|
|
195
|
+
| `ccode plan` | Generate or regenerate task checklist |
|
|
196
|
+
| `ccode next` | Show and start the next pending task |
|
|
197
|
+
| `ccode complete` | Mark active task as completed |
|
|
181
198
|
|
|
182
199
|
---
|
|
183
200
|
|
|
184
201
|
## What gets generated
|
|
185
202
|
|
|
186
|
-
|
|
203
|
+
### Source of truth (`.ccode/`)
|
|
204
|
+
|
|
205
|
+
```
|
|
206
|
+
.ccode/
|
|
207
|
+
├── project.md Vision, objectives, scope
|
|
208
|
+
├── architecture.md System structure (adapted to complexity)
|
|
209
|
+
├── rules.md Development standards for your stack
|
|
210
|
+
├── tasks.json Task checklist with acceptance criteria
|
|
211
|
+
├── state.json Active task, workflow stage
|
|
212
|
+
├── context.json Project configuration
|
|
213
|
+
├── memory.md Decision history
|
|
214
|
+
├── config.json AI provider config
|
|
215
|
+
└── context-export.md Universal export
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
### Synced context files (project root)
|
|
219
|
+
|
|
220
|
+
```
|
|
221
|
+
AGENTS.md Open Standard
|
|
222
|
+
CLAUDE.md Claude Code
|
|
223
|
+
GEMINI.md Gemini CLI
|
|
224
|
+
.cursorrules Cursor
|
|
225
|
+
.github/copilot-instructions.md GitHub Copilot
|
|
226
|
+
```
|
|
187
227
|
|
|
188
|
-
|
|
189
|
-
|------|---------|
|
|
190
|
-
| `project.md` | Vision, objectives, scope |
|
|
191
|
-
| `architecture.md` | System structure adapted to complexity |
|
|
192
|
-
| `rules.md` | Development standards for your stack |
|
|
193
|
-
| `tasks.json` | Task checklist with acceptance criteria |
|
|
194
|
-
| `state.json` | Active task, workflow stage |
|
|
195
|
-
| `memory.md` | Decision history |
|
|
196
|
-
| `config.json` | AI provider config |
|
|
228
|
+
All derived from `.ccode/`. One source, multiple outputs.
|
|
197
229
|
|
|
198
230
|
---
|
|
199
231
|
|
|
@@ -201,46 +233,54 @@ Everything lives in `.ccode/` inside your repository:
|
|
|
201
233
|
|
|
202
234
|
```
|
|
203
235
|
src/
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
236
|
+
├── cli/ Session, branding, file watcher
|
|
237
|
+
├── core/ Context engine, tasks, prompt builder, exports
|
|
238
|
+
├── ai/ Provider adapters (Adapter pattern)
|
|
239
|
+
└── utils/ File system abstraction
|
|
208
240
|
```
|
|
209
241
|
|
|
210
|
-
|
|
242
|
+
**Patterns:** Adapter (AI providers) · Observer (file watcher) · State Machine (workflow) · Builder (prompts)
|
|
211
243
|
|
|
212
244
|
---
|
|
213
245
|
|
|
214
246
|
## Contributing
|
|
215
247
|
|
|
216
|
-
See [CONTRIBUTING.md](CONTRIBUTING.md) for setup instructions
|
|
248
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for setup instructions.
|
|
217
249
|
|
|
218
|
-
Adding a new AI provider?
|
|
250
|
+
Adding a new AI provider? Implement `IAIProvider`, add it to the manager, done.
|
|
251
|
+
|
|
252
|
+
Adding a new export format? Add a method to `ContextExporter`, register the format, done.
|
|
253
|
+
|
|
254
|
+
Zero changes to the rest of the system in both cases.
|
|
219
255
|
|
|
220
256
|
---
|
|
221
257
|
|
|
222
258
|
## Learn more
|
|
223
259
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
260
|
+
| Resource | Link |
|
|
261
|
+
|----------|------|
|
|
262
|
+
| Engineering roles | [AGENTS.md](AGENTS.md) |
|
|
263
|
+
| Technical competencies | [SKILLS.md](SKILLS.md) |
|
|
264
|
+
| YouTube | [@CreativeCode25](https://www.youtube.com/@CreativeCode25) |
|
|
228
265
|
|
|
229
266
|
---
|
|
230
267
|
|
|
231
|
-
|
|
268
|
+
<div align="center">
|
|
269
|
+
|
|
270
|
+
### If CCODE helps you, consider giving it a star
|
|
232
271
|
|
|
233
|
-
If CCODE helps you, consider giving it a **star on GitHub** ⭐
|
|
234
272
|
It helps the project grow and reach more developers.
|
|
235
273
|
|
|
236
|
-
|
|
274
|
+
<br/>
|
|
237
275
|
|
|
238
|
-
|
|
276
|
+
[](https://github.com/iDevelop25/ccode)
|
|
239
277
|
|
|
240
|
-
|
|
278
|
+
<br/>
|
|
241
279
|
|
|
242
|
-
|
|
280
|
+
**[npm](https://www.npmjs.com/package/@korl3one/ccode)** · **[GitHub](https://github.com/iDevelop25/ccode)** · **[YouTube](https://www.youtube.com/@CreativeCode25)**
|
|
243
281
|
|
|
244
|
-
|
|
282
|
+
<br/>
|
|
245
283
|
|
|
246
284
|
*CCODE doesn't tell you how to code — it tells you what to build and makes sure you don't lose track.*
|
|
285
|
+
|
|
286
|
+
</div>
|
package/dist/ai/claude.d.ts
CHANGED
|
@@ -3,7 +3,8 @@ import { IAIProvider, IAIConfig } from './provider.js';
|
|
|
3
3
|
* Adaptador para Claude (Anthropic).
|
|
4
4
|
*/
|
|
5
5
|
export declare class ClaudeAdapter implements IAIProvider {
|
|
6
|
-
private
|
|
6
|
+
private apiKey;
|
|
7
|
+
private model;
|
|
7
8
|
constructor(config: IAIConfig);
|
|
8
9
|
getName(): string;
|
|
9
10
|
generate(prompt: string): Promise<string>;
|
package/dist/ai/claude.js
CHANGED
|
@@ -3,32 +3,35 @@ import axios from 'axios';
|
|
|
3
3
|
* Adaptador para Claude (Anthropic).
|
|
4
4
|
*/
|
|
5
5
|
export class ClaudeAdapter {
|
|
6
|
-
|
|
6
|
+
apiKey;
|
|
7
|
+
model;
|
|
7
8
|
constructor(config) {
|
|
8
|
-
this.
|
|
9
|
-
|
|
10
|
-
model: config.model || 'claude-sonnet-4-20250514',
|
|
11
|
-
baseUrl: config.baseUrl || 'https://api.anthropic.com/v1/messages',
|
|
12
|
-
};
|
|
9
|
+
this.apiKey = config.apiKey || '';
|
|
10
|
+
this.model = config.model || 'claude-sonnet-4-20250514';
|
|
13
11
|
}
|
|
14
12
|
getName() {
|
|
15
|
-
return `Claude (${this.
|
|
13
|
+
return `Claude (${this.model})`;
|
|
16
14
|
}
|
|
17
15
|
async generate(prompt) {
|
|
18
|
-
if (!this.
|
|
16
|
+
if (!this.apiKey) {
|
|
19
17
|
throw new Error('API Key de Anthropic no configurada.');
|
|
20
18
|
}
|
|
21
|
-
const response = await axios.post(
|
|
22
|
-
model: this.
|
|
19
|
+
const response = await axios.post('https://api.anthropic.com/v1/messages', {
|
|
20
|
+
model: this.model,
|
|
23
21
|
max_tokens: 8096,
|
|
24
22
|
messages: [{ role: 'user', content: prompt }],
|
|
25
23
|
}, {
|
|
26
24
|
headers: {
|
|
27
|
-
'x-api-key': this.
|
|
25
|
+
'x-api-key': this.apiKey,
|
|
28
26
|
'anthropic-version': '2023-06-01',
|
|
29
27
|
'content-type': 'application/json',
|
|
30
28
|
},
|
|
29
|
+
timeout: 120000,
|
|
31
30
|
});
|
|
32
|
-
|
|
31
|
+
const text = response.data?.content?.[0]?.text;
|
|
32
|
+
if (!text) {
|
|
33
|
+
throw new Error('Claude respondio pero sin contenido. Intenta de nuevo.');
|
|
34
|
+
}
|
|
35
|
+
return text;
|
|
33
36
|
}
|
|
34
37
|
}
|
package/dist/ai/gemini.d.ts
CHANGED
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
import { IAIProvider, IAIConfig } from './provider.js';
|
|
2
2
|
/**
|
|
3
3
|
* Adaptador para Google Gemini.
|
|
4
|
+
* Soporta API Key y OAuth token (de Gemini CLI).
|
|
4
5
|
*/
|
|
5
6
|
export declare class GeminiAdapter implements IAIProvider {
|
|
6
|
-
private
|
|
7
|
+
private apiKey;
|
|
8
|
+
private oauthToken;
|
|
9
|
+
private model;
|
|
7
10
|
constructor(config: IAIConfig);
|
|
8
11
|
getName(): string;
|
|
12
|
+
/**
|
|
13
|
+
* Try to read OAuth token from Gemini CLI installation.
|
|
14
|
+
*/
|
|
15
|
+
static readOAuthToken(): string | null;
|
|
16
|
+
/**
|
|
17
|
+
* Check if Gemini CLI is installed and authenticated.
|
|
18
|
+
*/
|
|
19
|
+
static isAvailable(): boolean;
|
|
20
|
+
setOAuthToken(token: string): void;
|
|
9
21
|
generate(prompt: string): Promise<string>;
|
|
10
22
|
}
|
package/dist/ai/gemini.js
CHANGED
|
@@ -1,31 +1,78 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
import * as path from 'path';
|
|
4
|
+
import * as os from 'os';
|
|
2
5
|
/**
|
|
3
6
|
* Adaptador para Google Gemini.
|
|
7
|
+
* Soporta API Key y OAuth token (de Gemini CLI).
|
|
4
8
|
*/
|
|
5
9
|
export class GeminiAdapter {
|
|
6
|
-
|
|
10
|
+
apiKey;
|
|
11
|
+
oauthToken;
|
|
12
|
+
model;
|
|
7
13
|
constructor(config) {
|
|
8
|
-
this.
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
baseUrl: config.baseUrl || 'https://generativelanguage.googleapis.com/v1beta/models',
|
|
12
|
-
};
|
|
14
|
+
this.apiKey = config.apiKey || '';
|
|
15
|
+
this.oauthToken = '';
|
|
16
|
+
this.model = config.model || 'gemini-2.5-flash';
|
|
13
17
|
}
|
|
14
18
|
getName() {
|
|
15
|
-
return `Gemini (${this.
|
|
19
|
+
return `Gemini (${this.model})`;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Try to read OAuth token from Gemini CLI installation.
|
|
23
|
+
*/
|
|
24
|
+
static readOAuthToken() {
|
|
25
|
+
try {
|
|
26
|
+
const credsPath = path.join(os.homedir(), '.gemini', 'oauth_creds.json');
|
|
27
|
+
if (!fs.existsSync(credsPath))
|
|
28
|
+
return null;
|
|
29
|
+
const creds = JSON.parse(fs.readFileSync(credsPath, 'utf-8'));
|
|
30
|
+
if (creds.access_token && typeof creds.access_token === 'string') {
|
|
31
|
+
return creds.access_token;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
// ignore
|
|
36
|
+
}
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Check if Gemini CLI is installed and authenticated.
|
|
41
|
+
*/
|
|
42
|
+
static isAvailable() {
|
|
43
|
+
return GeminiAdapter.readOAuthToken() !== null;
|
|
44
|
+
}
|
|
45
|
+
setOAuthToken(token) {
|
|
46
|
+
this.oauthToken = token;
|
|
16
47
|
}
|
|
17
48
|
async generate(prompt) {
|
|
18
|
-
|
|
19
|
-
|
|
49
|
+
const baseUrl = `https://generativelanguage.googleapis.com/v1beta/models/${this.model}:generateContent`;
|
|
50
|
+
let url;
|
|
51
|
+
let headers;
|
|
52
|
+
if (this.oauthToken) {
|
|
53
|
+
// Use OAuth token from Gemini CLI
|
|
54
|
+
url = baseUrl;
|
|
55
|
+
headers = {
|
|
56
|
+
'Content-Type': 'application/json',
|
|
57
|
+
'Authorization': `Bearer ${this.oauthToken}`,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
else if (this.apiKey) {
|
|
61
|
+
// Use API key
|
|
62
|
+
url = `${baseUrl}?key=${this.apiKey}`;
|
|
63
|
+
headers = { 'Content-Type': 'application/json' };
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
throw new Error('No hay credenciales de Gemini configuradas.');
|
|
20
67
|
}
|
|
21
|
-
const url = `${this.config.baseUrl}/${this.config.model}:generateContent?key=${this.config.apiKey}`;
|
|
22
68
|
const response = await axios.post(url, {
|
|
23
69
|
contents: [{ parts: [{ text: prompt }] }],
|
|
24
70
|
generationConfig: { maxOutputTokens: 8096 },
|
|
25
|
-
}, {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
71
|
+
}, { headers, timeout: 120000 });
|
|
72
|
+
const text = response.data?.candidates?.[0]?.content?.parts?.[0]?.text;
|
|
73
|
+
if (!text) {
|
|
74
|
+
throw new Error('Gemini respondio pero sin contenido. Intenta de nuevo.');
|
|
75
|
+
}
|
|
76
|
+
return text;
|
|
30
77
|
}
|
|
31
78
|
}
|
package/dist/ai/manager.d.ts
CHANGED
|
@@ -1,18 +1,37 @@
|
|
|
1
1
|
import { IAIProvider } from './provider.js';
|
|
2
|
-
export type ProviderName = 'claude' | '
|
|
2
|
+
export type ProviderName = 'claude' | 'gemini';
|
|
3
3
|
export interface ICCODEConfig {
|
|
4
4
|
provider: ProviderName;
|
|
5
5
|
apiKey?: string;
|
|
6
6
|
model?: string;
|
|
7
|
-
|
|
7
|
+
authType?: 'api-key' | 'oauth';
|
|
8
8
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
export declare const PROVIDER_INFO: Record<ProviderName, {
|
|
10
|
+
name: string;
|
|
11
|
+
keyUrl: string;
|
|
12
|
+
envVars: string[];
|
|
13
|
+
models: Array<{
|
|
14
|
+
name: string;
|
|
15
|
+
value: string;
|
|
16
|
+
}>;
|
|
17
|
+
}>;
|
|
12
18
|
export declare class AIManager {
|
|
13
19
|
private static readonly CONFIG_FILE;
|
|
14
20
|
static loadConfig(): Promise<ICCODEConfig | null>;
|
|
15
21
|
static saveConfig(config: ICCODEConfig): Promise<void>;
|
|
16
22
|
static getProvider(config: ICCODEConfig): IAIProvider;
|
|
17
|
-
static testConnection(config: ICCODEConfig): Promise<
|
|
23
|
+
static testConnection(config: ICCODEConfig): Promise<{
|
|
24
|
+
ok: boolean;
|
|
25
|
+
error?: string;
|
|
26
|
+
}>;
|
|
27
|
+
/**
|
|
28
|
+
* Auto-detect the best available provider.
|
|
29
|
+
* Priority: 1) Gemini CLI OAuth, 2) env vars, 3) null
|
|
30
|
+
*/
|
|
31
|
+
static autoDetect(): {
|
|
32
|
+
provider: ProviderName;
|
|
33
|
+
authType: 'oauth' | 'api-key';
|
|
34
|
+
apiKey?: string;
|
|
35
|
+
source: string;
|
|
36
|
+
} | null;
|
|
18
37
|
}
|