draftify-cli 1.0.4 → 1.0.8

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/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
3
6
  Object.defineProperty(exports, "__esModule", { value: true });
4
7
  const commander_1 = require("commander");
8
+ const https_1 = __importDefault(require("https"));
5
9
  const login_1 = require("./commands/login");
6
10
  const refactor_1 = require("./commands/refactor");
7
11
  const repl_1 = require("./repl");
@@ -30,22 +34,57 @@ program.on('command:*', function () {
30
34
  ui_1.ui.error(`Invalid command: ${program.args.join(' ')}\nSee --help for a list of available commands.`);
31
35
  process.exit(1);
32
36
  });
33
- // Custom logic for when `draftify` is run without any arguments
34
- if (process.argv.slice(2).length === 0) {
35
- const token = (0, config_1.getToken)();
36
- if (!token) {
37
- // No token, run interactive login flow
38
- (0, login_1.loginCommand)().then((username) => (0, repl_1.startRepl)(username)).catch(() => process.exit(1));
37
+ async function checkVersion() {
38
+ return new Promise((resolve) => {
39
+ // Set a short timeout so the CLI doesn't hang if the registry is slow or offline
40
+ const req = https_1.default.get("https://registry.npmjs.org/draftify-cli/latest", { timeout: 2000 }, (res) => {
41
+ let data = "";
42
+ res.on("data", (chunk) => { data += chunk; });
43
+ res.on("end", () => {
44
+ try {
45
+ const latestVersion = JSON.parse(data).version;
46
+ const currentVersion = require("../package.json").version;
47
+ // Semver comparison: strict inequality since we just want to block older versions
48
+ if (latestVersion && currentVersion && latestVersion !== currentVersion) {
49
+ console.error(`\n\x1b[31m[!] Elavult verziót használsz: ${currentVersion}\x1b[0m`);
50
+ console.error(`\x1b[33mKérlek frissítsd a legújabbra (${latestVersion}) a folytatáshoz:\x1b[0m`);
51
+ console.error(`\n \x1b[36mnpm install -g draftify-cli@latest\x1b[0m\n`);
52
+ process.exit(1);
53
+ }
54
+ resolve();
55
+ }
56
+ catch (e) {
57
+ resolve();
58
+ }
59
+ });
60
+ });
61
+ req.on("error", () => resolve());
62
+ req.on("timeout", () => {
63
+ req.destroy();
64
+ resolve();
65
+ });
66
+ });
67
+ }
68
+ (async () => {
69
+ // Wait for version check before starting anything
70
+ await checkVersion();
71
+ // Custom logic for when `draftify` is run without any arguments
72
+ if (process.argv.slice(2).length === 0) {
73
+ const token = (0, config_1.getToken)();
74
+ if (!token) {
75
+ // No token, run interactive login flow
76
+ (0, login_1.loginCommand)().then((username) => (0, repl_1.startRepl)(username)).catch(() => process.exit(1));
77
+ }
78
+ else {
79
+ // Token exists, start REPL
80
+ (0, repl_1.startRepl)().catch((err) => {
81
+ ui_1.ui.error(`REPL crashed: ${err.message}`);
82
+ process.exit(1);
83
+ });
84
+ }
39
85
  }
40
86
  else {
41
- // Token exists, start REPL
42
- (0, repl_1.startRepl)().catch((err) => {
43
- ui_1.ui.error(`REPL crashed: ${err.message}`);
44
- process.exit(1);
45
- });
87
+ // Otherwise, let commander handle the parsed args
88
+ program.parse(process.argv);
46
89
  }
47
- }
48
- else {
49
- // Otherwise, let commander handle the parsed args
50
- program.parse(process.argv);
51
- }
90
+ })();
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
@@ -46,11 +46,46 @@ async function refactorCodeApi(fileName, code, instruction, history, modelName,
46
46
  role: 'user',
47
47
  parts: [{ text: currentPrompt }]
48
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.`;
49
84
  const responseStream = await ai.models.generateContentStream({
50
85
  model: geminiModel,
51
86
  contents: contents,
52
87
  config: {
53
- systemInstruction: "You are an expert AI software engineering CLI assistant. You provide solutions, refactorings, and terminal commands."
88
+ systemInstruction: systemInstruction
54
89
  }
55
90
  });
56
91
  let fullResult = "";
@@ -63,6 +98,9 @@ async function refactorCodeApi(fileName, code, instruction, history, modelName,
63
98
  onChunk(chunk.text);
64
99
  }
65
100
  }
101
+ // Rough estimation of tokens
102
+ const estimatedTokens = Math.ceil((JSON.stringify(contents).length + fullResult.length) / 4);
103
+ (0, config_1.addTokensUsed)(estimatedTokens);
66
104
  return fullResult;
67
105
  }
68
106
  // 2. TÁVOLI VÉGREHAJTÁS (Eredeti Vercel backend kód, ha nincs helyi API kulcs)
@@ -143,6 +181,9 @@ async function refactorCodeApi(fileName, code, instruction, history, modelName,
143
181
  }
144
182
  }
145
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);
146
187
  return fullResult;
147
188
  }
148
189
  async function getUserProfile() {
@@ -14,6 +14,8 @@ exports.setSkills = setSkills;
14
14
  exports.getThinkingLevel = getThinkingLevel;
15
15
  exports.setThinkingLevel = setThinkingLevel;
16
16
  exports.getGeminiApiKey = getGeminiApiKey;
17
+ exports.getTokensUsed = getTokensUsed;
18
+ exports.addTokensUsed = addTokensUsed;
17
19
  const os_1 = __importDefault(require("os"));
18
20
  const fs_1 = __importDefault(require("fs"));
19
21
  const path_1 = __importDefault(require("path"));
@@ -76,3 +78,11 @@ function getGeminiApiKey() {
76
78
  const config = getConfig();
77
79
  return config.geminiApiKey || null;
78
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.4",
3
+ "version": "1.0.8",
4
4
  "description": "Draftify AI CLI tool",
5
5
  "main": "dist/index.js",
6
6
  "bin": {