Skip to content

Commit

Permalink
Setting up expertise and questionnaire
Browse files Browse the repository at this point in the history
  • Loading branch information
PrashamTrivedi committed Aug 12, 2024
1 parent c434e51 commit 205cdb1
Show file tree
Hide file tree
Showing 8 changed files with 563 additions and 27 deletions.
22 changes: 17 additions & 5 deletions commands/analyse.mts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import {FileNode, getDirStructure} from "../directoryProcessor.mjs"
import OpenAIInferrence, {LlmInterface} from "../openai.mjs"
import fs from 'fs'
Expand All @@ -6,8 +7,11 @@ import ora from 'ora'
import {Arguments} from 'yargs'
import {ChatCompletionChunk} from "openai/resources/index.mjs"
import {Stream} from "openai/streaming.mjs"

import chalk from "chalk"
import {confirm} from '@inquirer/prompts'
import {handler as setExpertiseHandler} from './setExpertise.mjs'



// Export these functions for testing
export {
Expand Down Expand Up @@ -73,7 +77,6 @@ export async function handler(argv: Arguments) {
console.log(`Analyse the given directory structure to understand the project structure and dependencies: ${argv.path}`)
}
const config = readConfig()

const rootDir = config.ANALYSIS_DIR

const projectName = argv.path as string
Expand All @@ -96,6 +99,7 @@ export async function handler(argv: Arguments) {
const sourceCodePath = argv.path as string
const dirToWriteAnalysis = isProjectRoot ? `${sourceCodePath}/.SourceSailor` : `${rootDir}/.SourceSailor/${projectName}`


const {directoryInferrence, directoryStructureWithContent} = await analyseDirectoryStructure(path, isVerbose, isRoot,
dirToWriteAnalysis, useOpenAi, isProjectRoot, ignore, llmInterface)

Expand Down Expand Up @@ -146,13 +150,19 @@ export async function handler(argv: Arguments) {
}
}


}
if (!config.userExpertise) {
console.log(chalk.yellow("User expertise is not set. Setting your expertise level will help us provide more tailored analysis."))
const setExpertise = await confirm({message: "Would you like to set your expertise now?", default: true})
if (setExpertise) {
await setExpertiseHandler()
}
}
}


async function analyseDirectoryStructure(path: string, isVerbose: boolean | undefined,
isRoot: boolean, projectName: string, useOpenAi: any, isProjectRoot: boolean | undefined,
isRoot: boolean, projectName: string, useOpenAi: boolean, isProjectRoot: boolean | undefined,
ignore: string[], llm: LlmInterface) {
const spinner = ora('Analyzing the directory structure...').start()
const directoryStructureWithContent = await getDirStructure(path, ignore, isVerbose)
Expand Down Expand Up @@ -314,7 +324,9 @@ async function getDirectoryWithoutLockfile(directoryInferrence: any, directorySt
const lockfile = directoryInferrence.lockFile
const directoryStructureWithoutLockFile = JSON.parse(JSON.stringify(directoryStructureWithContent))
removeLockFile(directoryStructureWithoutLockFile, lockfile)

if (isVerbose) {
console.log({directoryStructureWithoutLockFile})
}

return directoryStructureWithoutLockFile
}
Expand Down
40 changes: 29 additions & 11 deletions commands/getDirStructure.mts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import chalk from "chalk"
import {readConfig} from "../utils.mjs"
import {getDirStructure, FileNode} from "../directoryProcessor.mjs"

import {Argv} from 'yargs'
import {Arguments} from 'yargs'
import {readConfig} from "../utils.mjs"
import {confirm} from '@inquirer/prompts'
import {handler as setExpertiseHandler} from './setExpertise.mjs'

export const command = 'dirStructure <path|p> [verbose|v] [withContent|c] [ignore|i]'

export const describe = 'Get Directory Structure'

import {Argv} from 'yargs'


export function builder(yargs: Argv) {
yargs.positional('path', {
Expand Down Expand Up @@ -41,7 +44,6 @@ export function builder(yargs: Argv) {
return yargs
}

import {Arguments} from 'yargs'

export async function handler(argv: Arguments) {
const isVerbose = argv.verbose as boolean || argv.v as boolean || false
Expand All @@ -52,6 +54,8 @@ export async function handler(argv: Arguments) {
}
const projectName = argv.path as string

const config = readConfig()

if (isVerbose) {
console.log(`Project Name: ${projectName}`)
}
Expand All @@ -73,15 +77,12 @@ export async function handler(argv: Arguments) {
} else {
const directoryStructure = JSON.parse(JSON.stringify(directoryStructureWithContent))

function deleteContent(file: FileNode) {
delete file.content
if (file.children) {
for (const child of file.children) {
deleteContent(child)
}
}
for (const file of directoryStructure.children) {
deleteContent(file)
}



for (const file of directoryStructure.children) {
deleteContent(file)
}
Expand All @@ -90,6 +91,23 @@ export async function handler(argv: Arguments) {
} catch (error) {
console.error('Error analyzing directory structure:', error)
}

if (!config.userExpertise) {
console.log(chalk.yellow("User expertise is not set. Setting your expertise level will help us provide more tailored analysis."))
const setExpertise = await confirm({message: "Would you like to set your expertise now?", default: true})
if (setExpertise) {
await setExpertiseHandler()
}
}
}

function deleteContent(file: FileNode) {
delete file.content
if (file.children) {
for (const child of file.children) {
deleteContent(child)
}
}
}

export const usage = '$0 <cmd> [args]'
Expand Down
12 changes: 11 additions & 1 deletion commands/prepareReport.mts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import OpenAIInferrence, {LlmInterface} from "../openai.mjs"
import ora from "ora"
import {ChatCompletionChunk} from "openai/resources/index.mjs"
import {Stream} from "openai/streaming.mjs"
import chalk from "chalk"
import {confirm} from '@inquirer/prompts'
import {handler as setExpertiseHandler} from './setExpertise.mjs'

export const command = 'prepareReport <path|p> [verbose|v] [streaming|s]'

Expand Down Expand Up @@ -41,7 +44,6 @@ export async function handler(argv: Arguments) {
const allowStreaming = argv.streaming as boolean || argv.s as boolean || false
const projectDir = argv.path as string || argv.p as string
const config = readConfig()

const openai = new OpenAIInferrence()
const llmInterface: LlmInterface = openai
const rootDir = config.ANALYSIS_DIR
Expand Down Expand Up @@ -90,6 +92,14 @@ export async function handler(argv: Arguments) {
readmeResponse = reportAsText
}
}

if (!config.userExpertise) {
console.log(chalk.yellow("User expertise is not set. Setting your expertise level will help us provide more tailored reports."))
const setExpertise = await confirm({message: "Would you like to set your expertise now?", default: true})
if (setExpertise) {
await setExpertiseHandler()
}
}
}
export const usage = '$0 <cmd> [args]'

Expand Down
90 changes: 90 additions & 0 deletions commands/setExpertise.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import {readConfig, writeConfig} from '../utils.mjs'
import chalk from 'chalk'
import {confirm, select} from '@inquirer/prompts'
export const command = 'set-expertise'

export const describe = 'Set the user expertise level for various programming languages and frameworks'

export function builder(yargs: any) {
return yargs
}
interface Language {
name: string, frameworks: string[]
}

interface Choice {
name: string, value: string, description: string
}

const languages: Language[] = [
{name: 'JavaScript', frameworks: ['React', 'Angular', 'Vue.js', 'Express', 'Node.js']},
{name: 'Python', frameworks: ['Django', 'Flask', 'FastAPI', 'Pyramid']},
{name: 'Java', frameworks: ['Spring', 'Hibernate', 'Struts', 'JavaServer Faces']},
{name: 'C#', frameworks: ['.NET Core', 'ASP.NET', 'Entity Framework', 'Xamarin']},
{name: 'Ruby', frameworks: ['Ruby on Rails', 'Sinatra', 'Hanami']},
{name: 'PHP', frameworks: ['Laravel', 'Symfony', 'CodeIgniter', 'Yii']},
{name: 'Go', frameworks: ['Gin', 'Echo', 'Beego', 'Revel']},
{name: 'Rust', frameworks: ['Rocket', 'Actix', 'Warp', 'Tide']},
{name: 'TypeScript', frameworks: ['NestJS', 'Deno', 'Angular', 'Next.js']},
{name: 'Swift', frameworks: ['SwiftUI', 'Vapor', 'Perfect', 'Kitura']}
]

const expertiseLevels: Choice[] = [
{name: 'Beginner', value: 'beginner', description: 'Beginner'},
{name: 'Intermediate', value: 'intermediate', description: 'Intermediate'},
{name: 'Expert', value: 'expert', description: 'Expert'}
]

export async function handler() {
try {
const config = await readConfig()
config.userExpertise = {}

console.log(chalk.blue('Welcome to the expertise assessment questionnaire!'))
console.log(chalk.yellow('Please answer the following questions about your programming expertise.'))

for (const lang of languages) {
const knowsLanguage = await confirm({
message: `Do you have experience with ${lang.name}?`,
default: false
})

if (knowsLanguage) {
const languageLevel = await select({
message: `What is your expertise level in ${lang.name}?`,
choices: expertiseLevels,
default: 'beginner'
})

config.userExpertise[lang.name] = languageLevel

for (const framework of lang.frameworks) {
const knowsFramework = await confirm({
message: `Do you have experience with ${framework}?`,
default: false
})

if (knowsFramework) {
const frameworkLevel = await select({
message: `What is your expertise level in ${framework}?`,
choices: expertiseLevels,
default: 'beginner'
})

config.userExpertise[framework] = frameworkLevel
}
}
}
}

await writeConfig(config)
console.log(chalk.green('Expertise levels have been successfully set and saved!'))
} catch (error) {
console.error(chalk.red('Error setting user expertise levels:'), error)
}
}

export const usage = '$0 <cmd>'

export const aliases = ['expertise', 'skill-level', 'h', 'help']
3 changes: 3 additions & 0 deletions index.mts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import * as ListConfigProcessor from "./commands/listConfig.mjs"
import * as UpdateConfigProcessor from "./commands/updateConfig.mjs"
import * as PrepareReportProcessor from "./commands/prepareReport.mjs"
import * as GetDirStructure from "./commands/getDirStructure.mjs"
import * as SetExpertiseCommand from "./commands/setExpertise.mjs"

const yargsSetup = yargs(hideBin(process.argv))
// console.log("Hello there")
Expand All @@ -27,6 +28,8 @@ yargsSetup.
.command(UpdateConfigProcessor)
.command(PrepareReportProcessor)
.command(GetDirStructure)
.command(SetExpertiseCommand)

.help()
.alias('h', 'help')
.demandCommand(1)
Expand Down
Loading

0 comments on commit 205cdb1

Please sign in to comment.