draftify-cli 1.0.3 → 1.0.6

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/dist/repl.js CHANGED
@@ -432,6 +432,7 @@ async function startRepl(initialUsername) {
432
432
  console.log(` ${(0, kleur_1.cyan)("/thinking-level")} - Adjust the AI's thinking process depth`);
433
433
  console.log(` ${(0, kleur_1.cyan)("/login")} - Log in to your Draftify account`);
434
434
  console.log(` ${(0, kleur_1.cyan)("/logout")} - Log out of your account`);
435
+ console.log(` ${(0, kleur_1.cyan)("/usage")} - Show your token usage and quota`);
435
436
  console.log(` ${(0, kleur_1.cyan)("/help")} - List commands`);
436
437
  console.log(` ${(0, kleur_1.cyan)("/clear")} - Clear the terminal screen`);
437
438
  console.log(` ${(0, kleur_1.cyan)("/exit")} - Exit the CLI`);
@@ -440,6 +441,11 @@ async function startRepl(initialUsername) {
440
441
  else if (cmd === "clear") {
441
442
  renderWelcome();
442
443
  }
444
+ else if (cmd === "usage") {
445
+ ui_1.ui.header("Usage & Quota");
446
+ console.log(` Quota: ${(0, kleur_1.cyan)("Infinite")}`);
447
+ console.log(` Tokens used: ${(0, kleur_1.cyan)((0, config_1.getTokensUsed)().toLocaleString())}\n`);
448
+ }
443
449
  else if (cmd === "chats") {
444
450
  const chats = (0, chats_1.loadChats)();
445
451
  if (chats.length === 0) {
package/dist/utils/api.js CHANGED
@@ -10,10 +10,11 @@ const genai_1 = require("@google/genai");
10
10
  const dotenv_1 = __importDefault(require("dotenv"));
11
11
  dotenv_1.default.config();
12
12
  async function refactorCodeApi(fileName, code, instruction, history, modelName, skillsData, thinkingLevel, onChunk, abortSignal) {
13
+ const apiKey = process.env.GEMINI_API_KEY || (0, config_1.getGeminiApiKey)();
13
14
  // 1. HELYI VÉGREHAJTÁS (Ha van GEMINI_API_KEY a .env-ben, közvetlenül a Geminit hívjuk)
14
15
  // Ez tökéletes a helyi teszteléshez, mielőtt a backendre (Vercel) kerül a kód.
15
- if (process.env.GEMINI_API_KEY) {
16
- const ai = new genai_1.GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
16
+ if (apiKey) {
17
+ const ai = new genai_1.GoogleGenAI({ apiKey: apiKey });
17
18
  // Modell kiválasztása a kívánt logika alapján
18
19
  let geminiModel = 'gemini-3.5-flash'; // Alapértelmezett (Medium, Low, Adaptive)
19
20
  if (thinkingLevel === 'High') {
@@ -45,11 +46,46 @@ async function refactorCodeApi(fileName, code, instruction, history, modelName,
45
46
  role: 'user',
46
47
  parts: [{ text: currentPrompt }]
47
48
  });
49
+ const systemInstruction = `You are Draftify AI, an expert software engineering CLI assistant.
50
+ You have the ability to automatically create files, modify files, delete files, and run terminal commands on the user's machine.
51
+ To do this, you MUST format your response using the following XML tags:
52
+
53
+ 1. To create a file:
54
+ <FILE_CREATE path="relative/path/to/file.ext">
55
+ file content here
56
+ </FILE_CREATE>
57
+
58
+ 2. To modify an existing file:
59
+ <FILE_MODIFY path="relative/path/to/file.ext">
60
+ <<<<<<< SEARCH
61
+ exact lines to replace
62
+ =======
63
+ new lines
64
+ >>>>>>>
65
+ </FILE_MODIFY>
66
+
67
+ 3. To delete a file:
68
+ <FILE_DELETE path="relative/path/to/file.ext" />
69
+
70
+ 4. To run a terminal command:
71
+ <RUN_COMMAND>npm install express</RUN_COMMAND>
72
+
73
+ 5. To ask clarifying questions when the user's intent is ambiguous:
74
+ <ASK_QUESTIONS>
75
+ [
76
+ {
77
+ "question": "What tech stack do you prefer?",
78
+ "options": ["React + Vite", "Next.js", "Vanilla HTML/JS"]
79
+ }
80
+ ]
81
+ </ASK_QUESTIONS>
82
+
83
+ Always use these tags when you write code or ask questions so the CLI can apply it automatically! Keep explanations short and outside the tags.`;
48
84
  const responseStream = await ai.models.generateContentStream({
49
85
  model: geminiModel,
50
86
  contents: contents,
51
87
  config: {
52
- systemInstruction: "You are an expert AI software engineering CLI assistant. You provide solutions, refactorings, and terminal commands."
88
+ systemInstruction: systemInstruction
53
89
  }
54
90
  });
55
91
  let fullResult = "";
@@ -62,6 +98,9 @@ async function refactorCodeApi(fileName, code, instruction, history, modelName,
62
98
  onChunk(chunk.text);
63
99
  }
64
100
  }
101
+ // Rough estimation of tokens
102
+ const estimatedTokens = Math.ceil((JSON.stringify(contents).length + fullResult.length) / 4);
103
+ (0, config_1.addTokensUsed)(estimatedTokens);
65
104
  return fullResult;
66
105
  }
67
106
  // 2. TÁVOLI VÉGREHAJTÁS (Eredeti Vercel backend kód, ha nincs helyi API kulcs)
@@ -142,6 +181,9 @@ async function refactorCodeApi(fileName, code, instruction, history, modelName,
142
181
  }
143
182
  }
144
183
  }
184
+ // Rough estimation of tokens
185
+ const estimatedTokens = Math.ceil((JSON.stringify({ fileName, code, instruction, history, modelName, skillsData }).length + fullResult.length) / 4);
186
+ (0, config_1.addTokensUsed)(estimatedTokens);
145
187
  return fullResult;
146
188
  }
147
189
  async function getUserProfile() {
@@ -13,6 +13,9 @@ exports.getSkills = getSkills;
13
13
  exports.setSkills = setSkills;
14
14
  exports.getThinkingLevel = getThinkingLevel;
15
15
  exports.setThinkingLevel = setThinkingLevel;
16
+ exports.getGeminiApiKey = getGeminiApiKey;
17
+ exports.getTokensUsed = getTokensUsed;
18
+ exports.addTokensUsed = addTokensUsed;
16
19
  const os_1 = __importDefault(require("os"));
17
20
  const fs_1 = __importDefault(require("fs"));
18
21
  const path_1 = __importDefault(require("path"));
@@ -71,3 +74,15 @@ function getThinkingLevel() {
71
74
  function setThinkingLevel(level) {
72
75
  saveConfig({ thinkingLevel: level });
73
76
  }
77
+ function getGeminiApiKey() {
78
+ const config = getConfig();
79
+ return config.geminiApiKey || null;
80
+ }
81
+ function getTokensUsed() {
82
+ const config = getConfig();
83
+ return config.tokensUsed || 0;
84
+ }
85
+ function addTokensUsed(amount) {
86
+ const current = getTokensUsed();
87
+ saveConfig({ tokensUsed: current + amount });
88
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "draftify-cli",
3
- "version": "1.0.3",
3
+ "version": "1.0.6",
4
4
  "description": "Draftify AI CLI tool",
5
5
  "main": "dist/index.js",
6
6
  "bin": {