scai 0.1.79 → 0.1.81

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.
@@ -363,9 +363,9 @@ export async function promptChunkReviewMenu() {
363
363
  // Main command to review PR
364
364
  export async function reviewPullRequestCmd(branch = 'main', showAll = false) {
365
365
  try {
366
+ const { owner, repo } = await getRepoDetails();
366
367
  const token = await ensureGitHubAuth();
367
368
  const username = await getGitHubUsername(token);
368
- const { owner, repo } = await getRepoDetails();
369
369
  const prsWithReviewRequested = await getPullRequestsForReview(token, owner, repo, username, branch, !showAll);
370
370
  if (prsWithReviewRequested.length === 0)
371
371
  return;
@@ -18,11 +18,20 @@ export async function summarizeFile(filepath) {
18
18
  if (matches.length > 0) {
19
19
  const topMatch = matches[0];
20
20
  filePathResolved = path.resolve(process.cwd(), topMatch.path);
21
- console.log(`🔗 Matched file: ${path.relative(process.cwd(), filePathResolved)}`);
21
+ console.log(`🔗 Matched file from index: ${path.relative(process.cwd(), filePathResolved)}`);
22
22
  }
23
23
  else {
24
- console.error(`❌ Could not resolve file from query: "${filepath}"`);
25
- return;
24
+ // Fallback: check if it's a real file in CWD
25
+ const localPath = path.resolve(process.cwd(), filepath);
26
+ try {
27
+ await fs.access(localPath);
28
+ filePathResolved = localPath;
29
+ console.log(`📁 Using local file: ${path.relative(process.cwd(), localPath)}`);
30
+ }
31
+ catch {
32
+ console.error(`❌ Could not find or resolve file: "${filepath}"`);
33
+ return;
34
+ }
26
35
  }
27
36
  }
28
37
  // 📄 Load file content from resolved path
package/dist/config.js CHANGED
@@ -103,7 +103,6 @@ export const Config = {
103
103
  console.log(`📦 Database not found. ${chalk.green('Initializing DB')} at ${normalizePath(dbPath)}`);
104
104
  getDbForRepo(); // Now DB creation works after config update
105
105
  }
106
- console.log(`✅ Index directory set to: ${normalizePath(absPath)}`);
107
106
  },
108
107
  /**
109
108
  * Set both the scaiRepoRoot for the config and the indexDir (the actual repo root path)
@@ -1,15 +1,23 @@
1
+ import chalk from 'chalk';
1
2
  import { Config } from '../config.js';
2
3
  import { promptForToken } from './token.js';
3
4
  export async function ensureGitHubAuth() {
4
5
  // First check if the token exists in the config
5
6
  let token = Config.getGitHubToken();
6
7
  if (token) {
8
+ console.log("🔐 GitHub token found in config.");
7
9
  return token; // Token already exists in config, return it
8
10
  }
9
11
  // Token doesn't exist in config, prompt the user for it
10
- console.log("🔐 GitHub token not found.");
12
+ console.log(chalk.red("🔐 GitHub token not found."));
11
13
  token = await promptForToken();
14
+ // Ensure the token is not empty and has the required format (you can extend this check as needed)
15
+ while (!token || token.trim().length === 0) {
16
+ console.log("❌ Invalid token entered. Please enter a valid GitHub token.");
17
+ token = await promptForToken();
18
+ }
12
19
  // Save the token in the config
13
20
  Config.setGitHubToken(token.trim());
14
- return token.trim();
21
+ console.log(chalk.green("✅ GitHub token successfully saved."));
22
+ return token.trim(); // Return the trimmed token
15
23
  }
@@ -2,6 +2,7 @@ import path from 'path';
2
2
  import { execSync } from 'child_process';
3
3
  import { Config } from '../config.js';
4
4
  import { ensureGitHubAuth } from './auth.js';
5
+ import chalk from 'chalk';
5
6
  /**
6
7
  * Executes a Git command inside the specified working directory.
7
8
  */
@@ -43,14 +44,18 @@ function getRepoOwnerAndNameFromIndexDir(indexDir) {
43
44
  * Prefers Git config, falls back to parsing the path.
44
45
  */
45
46
  export async function getRepoDetails() {
46
- let indexDir = Config.getIndexDir(); // Fetch the current indexDir
47
- const currentDir = process.cwd(); // Get the current working directory
47
+ let indexDir = path.normalize(Config.getIndexDir()); // Fetch the current indexDir
48
+ const currentDir = path.normalize(process.cwd()); // Get the current working directory
48
49
  if (!indexDir) {
49
- throw new Error("❌ indexDir is not configured.");
50
+ console.log("❌ indexDir is not configured. Setting up a new index for the current directory...");
51
+ // Automatically set the index directory for the current directory
52
+ await setIndexDirForCurrentDir(currentDir);
53
+ // Now that the indexDir is set, fetch it again
54
+ indexDir = Config.getIndexDir();
50
55
  }
51
- console.log(`📦 Resolving GitHub repo info from indexDir: ${indexDir}`);
56
+ console.log(chalk.yellow(`📦 Resolving GitHub repo info from indexDir: ${indexDir}`));
52
57
  // Check if the current directory is the same as the index directory
53
- if (currentDir !== indexDir) {
58
+ if (path.resolve(currentDir) !== path.resolve(indexDir)) {
54
59
  console.log(`🚧 Current directory is not the index directory. Setting up new index...`);
55
60
  // Use the existing functionality to set up a new index directory
56
61
  await setIndexDirForCurrentDir(currentDir);
@@ -58,7 +63,7 @@ export async function getRepoDetails() {
58
63
  indexDir = Config.getIndexDir(); // Re-fetch the updated indexDir
59
64
  }
60
65
  // Ensure the repository authentication is available
61
- ensureAuthCredentials();
66
+ await ensureAuthCredentials();
62
67
  // Proceed with the normal flow to fetch the repo details
63
68
  try {
64
69
  return getRepoOwnerAndNameFromGit(indexDir); // Try fetching from Git config
@@ -1,4 +1,5 @@
1
1
  // Utility function to prompt for GitHub token
2
+ import chalk from 'chalk';
2
3
  import readline from 'readline';
3
4
  export function promptForToken() {
4
5
  return new Promise((resolve) => {
@@ -6,7 +7,7 @@ export function promptForToken() {
6
7
  input: process.stdin,
7
8
  output: process.stdout,
8
9
  });
9
- rl.question('Paste your GitHub Personal Access Token (scopes: `repo`): ', (token) => {
10
+ rl.question(`\nPaste your GitHub Personal Access Token:\n${chalk.yellow('(press Control + C to exit)')}\n`, (token) => {
10
11
  rl.close();
11
12
  resolve(token);
12
13
  });
package/dist/index.js CHANGED
@@ -153,9 +153,9 @@ index
153
153
  .description('Index supported files in the configured index directory')
154
154
  .action(runIndexCommand);
155
155
  index
156
- .command('set <dir>')
156
+ .command('set [dir]')
157
157
  .description('Set and activate index directory')
158
- .action((dir) => {
158
+ .action((dir = process.cwd()) => {
159
159
  Config.setIndexDir(dir);
160
160
  Config.show();
161
161
  });
@@ -1,13 +1,14 @@
1
1
  import columnify from "columnify";
2
2
  export function styleOutput(summaryText) {
3
3
  const terminalWidth = process.stdout.columns || 80;
4
- // You can control wrapping here
5
- const formatted = columnify([{ Summary: summaryText }], {
4
+ // Split by line to simulate multiple rows instead of one long wrapped field
5
+ const lines = summaryText.trim().split('\n').map(line => ({ Summary: line }));
6
+ const formatted = columnify(lines, {
6
7
  columnSplitter: ' ',
7
8
  maxLineWidth: terminalWidth,
8
9
  config: {
9
10
  Summary: {
10
- maxWidth: Math.floor((terminalWidth * 2) / 3), // Use 2/3 width like before
11
+ maxWidth: Math.floor((terminalWidth * 2) / 3),
11
12
  align: "left",
12
13
  },
13
14
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "scai",
3
- "version": "0.1.79",
3
+ "version": "0.1.81",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "scai": "./dist/index.js"