Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/hungry-sheep-bathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"overide": minor
---

Rollback: Embeddings and Dependency graph support.
101 changes: 3 additions & 98 deletions src/commands/command.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import fs from 'fs';
import path from 'path';

import { ConfigOption } from '../models/model.options';
import {
GlobalConfig,
Expand All @@ -12,7 +9,6 @@ import CommandHelper from '../utilis/util.command.config';
import OiCommand from './abstract.command';
import { Command } from 'commander';
import inquirer, { Question } from 'inquirer';
import serviceParser from '../services/service.parser';
import utilParser from '../utilis/util.parser';

/**
Expand Down Expand Up @@ -50,22 +46,17 @@ class Config extends OiCommand {
.command('local')
.description('Local configuration options')
.option('-i, --ignore <files...>', 'Ignore specific files or directories')
.option('-p, --parse', 'Creates dependency graph for the project')
.option('-n, --name <name>', 'Set project name');

const globalConfig = configCommand
.command('global') // Sub-command for global configuration
.description('Global configuration options')
.option('-p, --platform', 'Set global variable like API keys and org IDs')
.option('-a, --set-active', 'Select active platform');
.option('-p, --platform', 'Set global variable like API keys and org IDs');

configCommand.action(async options => {
if (Object.keys(options).length === 0) {
configCommand.outputHelp();
}
if (options.embedding) {
this.handleEmbeddingEnable();
}
});

localConfig.action(async options => {
Expand All @@ -75,13 +66,7 @@ class Config extends OiCommand {
if (Object.keys(options).length === 0) {
localConfig.outputHelp();
} else {
if (options.parse) {
await this.generateDependencyGraph(options.verbose);
} else if (options.graph) {
this.handleDepGraphEnable();
} else {
await this.handleLocalConfig(options);
}
await this.handleLocalConfig(options);
}
});

Expand All @@ -95,77 +80,9 @@ class Config extends OiCommand {
if (options.platform) {
await this.handleAddActivePlatform();
}
if (options.setActive) {
await this.handleChangeActivePlatform();
}
});
}

async handleDepGraphEnable(): Promise<void> {
// Set the embeddings flag to true.
this.handleLocalConfig({}, true);
return;
}

async handleEmbeddingEnable(): Promise<void> {
// Check if OpenAI platform details are available.
const activePlatform = CommandHelper.getActiveServiceDetails(true);
if (!activePlatform) {
console.warn(
'Overide supports embeddings over OpenAI\nEnabling this will incur additional cost'
);
// Ask for OpenAI platform details.
const answers = await this.promptPlatformConfig('openai');

// Check if a global config file already exists, if not initialize an empty config
const existingConfig = CommandHelper.configExists(true)
? CommandHelper.readConfigFileData(true)
: {};

// Merge the new platform configuration with the existing config
const updatedConfig = {
...existingConfig,
['openai']: {
...answers,
isActive: true // OpenAI is always active for embeddings
}
};

// Save the updated global configuration
CommandHelper.writeConfigFileData(true, updatedConfig);
}

// Set the embeddings flag to true.
this.handleLocalConfig({}, true);
return;
}

async generateDependencyGraph(verbose: boolean = false): Promise<void> {
try {
// Get the current directory
const currentDir = process.cwd();

// Get the ignore list from the oi-config.json file
const config: LocalConfig = CommandHelper.readConfigFileData() as LocalConfig;
const ignoreList = config.ignore || [];

// Generate dependency graphs for all files in the current directory
const dependencyGraphs = await serviceParser.makeProjectDepGraph(
currentDir,
ignoreList,
verbose
);

// Write the dependency graphs to a file
fs.writeFileSync(
path.join(currentDir, 'oi-dependency.json'),
JSON.stringify(dependencyGraphs, null, 2)
);
} catch (error) {
console.error('Failed to generate dependency graph:', error);
}
}

// Method to handle switching the active platform
async handleChangeActivePlatform(): Promise<void> {
// Get the global config file path
Expand Down Expand Up @@ -264,7 +181,7 @@ class Config extends OiCommand {
}

// Handle the local configuration for the project
async handleLocalConfig(options: ConfigOption, embedding: boolean = false): Promise<void> {
async handleLocalConfig(options: ConfigOption): Promise<void> {
// Get the path to the local configuration file
// const configFilePath = CommandHelper.getConfigFilePath();

Expand All @@ -276,13 +193,6 @@ class Config extends OiCommand {
process.exit(1); // Exit if the local config is not found
}

if (!CommandHelper.dependencyFileExists()) {
console.error(
'Dependency file (oi-dependency.json) not found. Run `overide init` to initialize the project.'
);
process.exit(1); // Exit if the dependency file is not found
}

// Read the local configuration
const config: LocalConfig = CommandHelper.readConfigFileData() as LocalConfig;

Expand All @@ -308,11 +218,6 @@ class Config extends OiCommand {
config.projectName = options.name;
}

if (embedding) {
console.log('Embedding support for project enabled.');
config.embedding = true;
}

// Save the updated local configuration
CommandHelper.writeConfigFileData(false, config);
console.log('Local config updated successfully.');
Expand Down
10 changes: 1 addition & 9 deletions src/commands/command.init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,9 @@ class Initialize extends OiCommand {
console.log('Overide Project initialized!');
console.log('\nNext steps:');
console.log(
"1. Use 'overide config global -p | --platform' to define the API KEYs, BASE URLs and Platforms"
"1. Use 'overide config global -p | --platform' to define the API KEYs, & BASE URLs"
);
console.log("2. Run 'overide start' to start getting code suggestions.");
console.log("3. Run 'overide config -e' to enable embeddings based context.");
}

/**
Expand All @@ -72,7 +71,6 @@ class Initialize extends OiCommand {
outputPath = path.join(process.cwd(), 'oi-config.json');
}

const dependencyFilePath = path.join(options.path ?? process.cwd(), 'oi-dependency.json');
const ignoreFiles = options.ignore || [];
const verbose = options.verbose || false;
const projectName = options.projectName || 'default-project';
Expand All @@ -89,7 +87,6 @@ class Initialize extends OiCommand {
// Default ignore files, including config and dependency files, and common directories
const defaultIgnoreFiles = [
'oi-config.json',
'oi-dependency.json',
'/(^|[/\\])../',
'node_modules',
'*.swp',
Expand Down Expand Up @@ -124,11 +121,6 @@ class Initialize extends OiCommand {
console.log(`Project initialized with config at ${outputPath}`);
}

if (!fs.existsSync(dependencyFilePath)) {
fs.writeFileSync(dependencyFilePath, JSON.stringify([], null, 2));
console.log(`Project initialized with dependency file at ${dependencyFilePath}`);
}

// Display ASCII art and instructions after initialization
this.displayAsciiArt();
} catch (error) {
Expand Down
22 changes: 1 addition & 21 deletions src/commands/command.start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ import startCommandHandlerImpl from '../handlers/handler.start';

import { StartOption } from '../models/model.options';
import { LocalConfig } from '../models/model.config';
import { DependencyGraph } from '../models/model.depgraph';
import serviceParser from '../services/service.parser';
import utilParser from '../utilis/util.parser';

/**
* The `Start` class extends `OiCommand` and is responsible for initiating
Expand All @@ -22,7 +19,6 @@ import utilParser from '../utilis/util.parser';
*/
class Start extends OiCommand {
// Stores the contents of all files in the project
private dependencyGraph: DependencyGraph[] | null = [];
private watcher: FSWatcher | null = null;

/**
Expand All @@ -36,13 +32,7 @@ class Start extends OiCommand {
.description('Start watching files for prompt changes');
this.addCommonOptions(startCommand); // Add common options such as --verbose

startCommand.action((options: StartOption) => {
// Load the dependency graph from the oi-dependency.json file
this.dependencyGraph = configCommandUtil.loadDependencyGraph(options.path) as
| DependencyGraph[]
| null;
this.startWatch(options);
});
startCommand.action((options: StartOption) => this.startWatch(options));
}

/**
Expand Down Expand Up @@ -106,16 +96,6 @@ class Start extends OiCommand {
console.log(`File ${filePath} has been changed`);
}

// Set the dep graph to false if project language is not supported.
const language = utilParser.identifyLanguageByExtension(filePath);
if (language) {
utilParser.loadParserForLanguage(language); // Check if the dependency graph is empty
await serviceParser.makeProjectDepGraphInc(filePath, ignoreFiles, verbose);
if (verbose) {
console.log('Dependency graph updated...');
}
}

await startCommandHandlerImpl.findPromptInFile(filePath, verbose);
}

Expand Down
36 changes: 0 additions & 36 deletions src/models/model.depgraph.ts

This file was deleted.

12 changes: 0 additions & 12 deletions src/models/model.language.map.ts

This file was deleted.

25 changes: 0 additions & 25 deletions src/services/service.dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,6 @@ abstract class DevService {
}

class DevServiceImpl extends DevService {
/**
* Extracts a code block from the content based on a specific format.
*
* @param content - The content to extract the code block from.
* @param verbose - If true, logs the extracted block.
* @returns The extracted code block.
* @throws Error if no code block is found.
*/
extractCodeBlock(content: string, verbose: boolean = false): ReplacementBlock[] {
console.log(content);
const codeMatch = content.match(/```[\s\S]*?\n([\s\S]*?)\n```/);
if (codeMatch && codeMatch[1]) {
if (verbose) {
console.log(`Extracted Code Block: ${codeMatch[1]}`);
}
try {
return JSON.parse(codeMatch[1]) as ReplacementBlock[];
} catch (err) {
throw new Error(`No valid JSON found in response ${(err as Error).message}`);
}
} else {
throw new Error('No code block found in the response');
}
}

/**
* Finds the index of the old block in the file content using a flexible matching approach.
*
Expand Down
Loading