draftify-cli 1.0.76 → 1.0.79

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
@@ -46,51 +46,13 @@ function getContextForPrompt(dir, prompt) {
46
46
  }
47
47
  }
48
48
  walk(dir, 0);
49
- const lowercasePrompt = prompt.toLowerCase();
50
- // Check if any specific workspace files are mentioned in the prompt
51
- const matchedFiles = allPaths.filter(filePath => {
52
- const baseName = path_1.default.basename(filePath).toLowerCase();
53
- const nameWithoutExt = path_1.default.parse(baseName).name.toLowerCase();
54
- const ext = path_1.default.extname(filePath).toLowerCase();
55
- const validExts = [
56
- '.ts', '.tsx', '.js', '.jsx', '.css', '.json', '.html',
57
- '.py', '.md', '.txt', '.c', '.cpp', '.h', '.java', '.go', '.rs', '.php', '.rb', '.sh'
58
- ];
59
- if (!validExts.includes(ext))
60
- return false;
61
- // Check if the prompt contains the full filename (e.g. 'snake.py') or name without ext (e.g. 'snake')
62
- return lowercasePrompt.includes(baseName) || (nameWithoutExt.length > 2 && lowercasePrompt.includes(nameWithoutExt));
63
- });
64
- let filesToRead = [];
65
- if (matchedFiles.length > 0) {
66
- // If specific files are mentioned, only load those files
67
- filesToRead = matchedFiles.slice(0, 5);
68
- }
69
- // Load the contents of selected files
70
- for (const filePath of filesToRead) {
71
- const fullPath = path_1.default.resolve(dir, filePath);
72
- try {
73
- ui_1.ui.fileRead(filePath);
74
- const content = fs_1.default.readFileSync(fullPath, 'utf-8');
75
- if (content.length < 50000) { // Limit to 50KB per file
76
- codeFiles.push({ path: filePath, content });
77
- }
78
- }
79
- catch {
80
- // Ignore unreadable files
81
- }
82
- }
83
49
  let structureStr = allPaths.join('\n');
84
50
  if (allPaths.length >= maxPaths) {
85
51
  structureStr += '\n... (and more files omitted)';
86
52
  }
87
53
  let combinedCode = `--- PROJECT DIRECTORY STRUCTURE ---\n${structureStr}\n\n`;
88
- if (codeFiles.length > 0) {
89
- combinedCode += `--- ATTACHED FILE CONTENTS ---\n`;
90
- combinedCode += codeFiles.map(f => `--- File: ${f.path} ---\n${f.content}\n`).join('\n');
91
- }
92
54
  return {
93
- fileName: codeFiles.length > 0 ? codeFiles[0].path : "workspace_context",
55
+ fileName: "workspace_context",
94
56
  code: combinedCode
95
57
  };
96
58
  }
@@ -429,8 +391,30 @@ async function startRepl(initialUsername) {
429
391
  }
430
392
  else if (cmd === "usage") {
431
393
  ui_1.ui.header("Usage & Quota");
432
- console.log(` Quota: ${(0, kleur_1.cyan)("Infinite")}`);
433
- console.log(` Tokens used: ${(0, kleur_1.cyan)((0, config_1.getTokensUsed)().toLocaleString())}\n`);
394
+ const spinner = (0, ui_1.createSpinner)("Fetching usage...");
395
+ spinner.start();
396
+ try {
397
+ const usage = await (0, api_1.getUserUsage)();
398
+ spinner.stop();
399
+ if (usage) {
400
+ const quotaStr = usage.r1Limit === -1 ? "Infinite" : usage.r1Limit.toLocaleString();
401
+ console.log(` Plan: ${(0, kleur_1.cyan)(usage.plan)}`);
402
+ console.log(` Opus 4.8-level Quota: ${(0, kleur_1.cyan)(quotaStr)} tokens`);
403
+ console.log(` Opus 4.8-level Used: ${(0, kleur_1.cyan)(usage.r1TokensUsed.toLocaleString())} tokens\n`);
404
+ }
405
+ else {
406
+ ui_1.ui.error("Could not fetch usage. Are you logged in?");
407
+ }
408
+ }
409
+ catch (e) {
410
+ spinner.stop();
411
+ if (e.message === "UNAUTHORIZED") {
412
+ ui_1.ui.error("You are not logged in. Please run '/login' first.");
413
+ }
414
+ else {
415
+ ui_1.ui.error("Failed to fetch usage: " + e.message);
416
+ }
417
+ }
434
418
  }
435
419
  else if (cmd === "chats") {
436
420
  const chats = (0, chats_1.loadChats)();
@@ -655,7 +639,7 @@ async function startRepl(initialUsername) {
655
639
  }
656
640
  if (fs_1.default.existsSync(fullPath)) {
657
641
  let fileContent = fs_1.default.readFileSync(fullPath, 'utf-8');
658
- const searchBlockRegex = /<<<<<<< SEARCH\n([\s\S]*?)\n=======\n([\s\S]*?)\n>>>>>>>/g;
642
+ const searchBlockRegex = /<<<<<<< SEARCH>?\r?\n([\s\S]*?)\r?\n=======\r?\n([\s\S]*?)\r?\n>>>>>>>/g;
659
643
  let diffMatch;
660
644
  let diffApplied = false;
661
645
  let hasDiffBlocks = false;
@@ -1041,7 +1025,8 @@ async function startRepl(initialUsername) {
1041
1025
  promptAdditions.push(`I executed your file system requests. Here are the results:\n${autoExplorationOutputs.join('\n\n')}`);
1042
1026
  autoPrompt = promptAdditions.join("\n\n");
1043
1027
  }
1044
- if (finalDisplayResult) {
1028
+ const isIntermediateExploration = (filesToReadAuto.length > 0 || dirsToListAuto.length > 0) && commandsToRun.length === 0 && questions.length === 0;
1029
+ if (finalDisplayResult && !isIntermediateExploration) {
1045
1030
  ui_1.ui.box("Draftify AI", finalDisplayResult.split("\n"));
1046
1031
  }
1047
1032
  // --- INTERACTIVE MENU FOR QUESTIONS ---
package/dist/utils/api.js CHANGED
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.refactorCodeApi = refactorCodeApi;
7
7
  exports.getUserProfile = getUserProfile;
8
+ exports.getUserUsage = getUserUsage;
8
9
  const config_1 = require("./config");
9
10
  const dotenv_1 = __importDefault(require("dotenv"));
10
11
  dotenv_1.default.config();
@@ -106,3 +107,24 @@ async function getUserProfile() {
106
107
  }
107
108
  return null;
108
109
  }
110
+ async function getUserUsage() {
111
+ const token = (0, config_1.getToken)();
112
+ if (!token)
113
+ throw new Error("UNAUTHORIZED");
114
+ // Replace the trailing /api/cli or /api/user/profile with /api/user/usage
115
+ let apiUrl = (0, config_1.getApiUrl)();
116
+ apiUrl = apiUrl.replace(/\/api\/.*$/, "/api/user/usage");
117
+ try {
118
+ const response = await fetch(apiUrl, {
119
+ method: "GET",
120
+ headers: { Authorization: `Bearer ${token}` }
121
+ });
122
+ if (response.ok) {
123
+ return await response.json();
124
+ }
125
+ }
126
+ catch (e) {
127
+ // Ignore errors
128
+ }
129
+ return null;
130
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "draftify-cli",
3
- "version": "1.0.76",
3
+ "version": "1.0.79",
4
4
  "description": "Draftify AI CLI tool",
5
5
  "main": "dist/index.js",
6
6
  "bin": {