Skip to content

Commit

Permalink
github review tab
Browse files Browse the repository at this point in the history
  • Loading branch information
rjmacarthy committed Sep 18, 2024
1 parent 11ce1c2 commit 0d8bdad
Show file tree
Hide file tree
Showing 14 changed files with 596 additions and 79 deletions.
37 changes: 29 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,42 +85,47 @@
{
"command": "twinny.openChat",
"group": "navigation@0",
"when": "view == twinny.sidebar && twinnyManageTemplates || view == twinny.sidebar && twinnyManageProviders || view == twinny.sidebar && twinnyConversationHistory || view == twinny.sidebar && twinnySymmetryTab"
"when": "view == twinny.sidebar && twinnyManageTemplates || view == twinny.sidebar && twinnyManageProviders || view == twinny.sidebar && twinnyConversationHistory || view == twinny.sidebar && twinnySymmetryTab || view == twinny.sidebar && twinnyReviewTab"
},
{
"command": "twinny.symmetry",
"command": "twinny.review",
"group": "navigation@1",
"when": "view == twinny.sidebar"
},
{
"command": "twinny.manageProviders",
"command": "twinny.symmetry",
"group": "navigation@2",
"when": "view == twinny.sidebar"
},
{
"command": "twinny.manageTemplates",
"command": "twinny.manageProviders",
"group": "navigation@3",
"when": "view == twinny.sidebar"
},
{
"command": "twinny.manageTemplates",
"group": "navigation@4",
"when": "view == twinny.sidebar"
},
{
"command": "twinny.templates",
"when": "view == twinny.sidebar",
"group": "navigation@4"
"group": "navigation@5"
},
{
"command": "twinny.conversationHistory",
"when": "view == twinny.sidebar",
"group": "navigation@5"
"group": "navigation@6"
},
{
"command": "twinny.newConversation",
"when": "view == twinny.sidebar",
"group": "navigation@6"
"group": "navigation@7"
},
{
"command": "twinny.settings",
"when": "view == twinny.sidebar",
"group": "navigation@7"
"group": "navigation@8"
}
]
},
Expand Down Expand Up @@ -163,6 +168,10 @@
"title": "Disable twinny",
"shortTitle": "Disable twinny"
},
{
"command": "twinny.getGitCommitMessage",
"title": "Twinny - Generate commit message"
},
{
"command": "twinny.sidebar.focus",
"shortTitle": "Enable twinny sidebar",
Expand All @@ -174,6 +183,12 @@
"title": "Open twinny settings",
"icon": "$(gear)"
},
{
"command": "twinny.review",
"shortTitle": "twinny code reviewer",
"title": "Code reviewer",
"icon": "$(git-pull-request)"
},
{
"command": "twinny.symmetry",
"shortTitle": "twinny symmetry network",
Expand Down Expand Up @@ -376,6 +391,12 @@
"type": "string",
"description": "The symmetry master server key.",
"default": "4b4a9cc325d134dee6679e9407420023531fd7e96c563f6c5d00fd5549b77435"
},
"twinny.githubToken": {
"order": 27,
"type": "string",
"default": "",
"description": "Your GitHub token. Used for fetching GitHub data."
}
}
}
Expand Down
15 changes: 13 additions & 2 deletions src/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ export const EVENT_NAME = {
twinnySetWorkspaceContext: 'twinny-set-workspace-context',
twinnyStopGeneration: 'twinny-stop-generation',
twinnyTextSelection: 'twinny-text-selection',
twinnyGetWorkspaceContext: 'twinny-workspace-context'
twinnyGetWorkspaceContext: 'twinny-workspace-context',
twinnyGithhubReview: 'twinny-githhub-review'
}

export const TWINNY_COMMAND_NAME = {
Expand All @@ -87,6 +88,7 @@ export const TWINNY_COMMAND_NAME = {
conversationHistory: 'twinny.conversationHistory',
disable: 'twinny.disable',
enable: 'twinny.enable',
review: 'twinny.review',
explain: 'twinny.explain',
focusSidebar: 'twinny.sidebar.focus',
generateDocs: 'twinny.generateDocs',
Expand Down Expand Up @@ -151,7 +153,9 @@ export const WORKSPACE_STORAGE_KEY = {
selectedTemplates: 'selectedTemplates',
selection: 'selection',
showEmbeddingOptions: 'showEmbeddingOptions',
showProviders: 'showProviders'
showProviders: 'showProviders',
reviewOwner: 'reviewOwner',
reviewRepo: 'reviewRepo',
}

export const EXTENSION_SETTING_KEY = {
Expand All @@ -166,6 +170,7 @@ export const EXTENSION_CONTEXT_NAME = {
twinnyGeneratingText: 'twinnyGeneratingText',
twinnyManageProviders: 'twinnyManageProviders',
twinnyManageTemplates: 'twinnyManageTemplates',
twinnyReviewTab: 'twinnyReviewTab',
twinnyRerankThreshold: 'twinnyRerankThreshold',
twinnyMaxChunkSize: 'twinnyMaxChunkSize',
twinnyMinChunkSize: 'twinnyMinChunkSize',
Expand All @@ -186,6 +191,7 @@ export const WEBUI_TABS = {
chat: 'chat',
history: 'history',
providers: 'providers',
review: 'review',
settings: 'templates',
symmetry: 'symmetry'
}
Expand Down Expand Up @@ -242,6 +248,11 @@ export const DEFAULT_PROVIDER_FORM_VALUES = {
type: 'chat'
}

export const GITHUB_EVENT_NAME = {
getPullRequests: 'github.getPullRequests',
getPullRequestReview: 'github.getPullRequestReview'
}

export const TITLE_GENERATION_PROMPT_MESAGE = `
Generate a title for this conversation in under 10 words.
It should not contain any special characters or quotes.
Expand Down
10 changes: 10 additions & 0 deletions src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ export interface ClientMessage<T = string | boolean | Message[], Y = unknown> {
key?: string
}

export type ClientMessageWithData = ClientMessage<string | boolean> &
ClientMessage<Message[]> &
ClientMessage<GithubPullRequestMessage>

export interface ServerMessage<T = LanguageType> {
type: string
value: {
Expand All @@ -81,6 +85,12 @@ export interface Message {
content: string | undefined
}

export interface GithubPullRequestMessage {
owner: string
repo: string
number: number
}

export interface Conversation {
id?: string
title?: string
Expand Down
48 changes: 24 additions & 24 deletions src/extension/conversation-history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,30 @@ import { SymmetryService } from './symmetry-service'
type Conversations = Record<string, Conversation> | undefined

export class ConversationHistory {
private _context: ExtensionContext
private _config = workspace.getConfiguration('twinny')
private _keepAlive = this._config.get('keepAlive') as string | number
public config = workspace.getConfiguration('twinny')
public context: ExtensionContext
public keepAlive = this.config.get('keepAlive') as string | number
public temperature = this.config.get('temperature') as number
public webView: Webview
private _sessionManager: SessionManager | undefined
private _symmetryService: SymmetryService
private _temperature = this._config.get('temperature') as number
private _title = ''
private _webView: Webview

constructor(
context: ExtensionContext,
webView: Webview,
sessionManager: SessionManager | undefined,
symmetryService: SymmetryService
) {
this._context = context
this._webView = webView
this.context = context
this.webView = webView
this._sessionManager = sessionManager
this._symmetryService = symmetryService
this.setUpEventListeners()
}

setUpEventListeners() {
this._webView?.onDidReceiveMessage(
this.webView?.onDidReceiveMessage(
(message: ClientMessage<Conversation>) => {
this.handleMessage(message)
}
Expand All @@ -62,7 +62,7 @@ export class ConversationHistory {
SYMMETRY_EMITTER_KEY.conversationTitle,
(completion: string) => {
const activeConversation = this.getActiveConversation()
this._webView?.postMessage({
this.webView?.postMessage({
type: CONVERSATION_EVENT_NAME.getActiveConversation,
value: {
data: {
Expand Down Expand Up @@ -130,13 +130,13 @@ export class ConversationHistory {
})
}

private getProvider = () => {
return this._context?.globalState.get<TwinnyProvider>(
public getProvider = () => {
return this.context?.globalState.get<TwinnyProvider>(
ACTIVE_CHAT_PROVIDER_STORAGE_KEY
)
}

private buildStreamRequest(messages?: Message[]) {
public buildStreamRequest(messages?: Message[]) {
const provider = this.getProvider()

if (!provider || !messages?.length) return
Expand All @@ -156,15 +156,15 @@ export class ConversationHistory {
const requestBody = createStreamRequestBody(provider.provider, {
model: provider.modelName,
numPredictChat: 100,
temperature: this._temperature,
temperature: this.temperature,
messages: [
...messages,
{
role: 'user',
content: TITLE_GENERATION_PROMPT_MESAGE
}
],
keepAlive: this._keepAlive
keepAlive: this.keepAlive
})

return { requestOptions, requestBody }
Expand All @@ -178,7 +178,7 @@ export class ConversationHistory {

getAllConversations() {
const conversations = this.getConversations() || {}
this._webView?.postMessage({
this.webView?.postMessage({
type: CONVERSATION_EVENT_NAME.getConversations,
value: {
data: conversations
Expand All @@ -187,33 +187,33 @@ export class ConversationHistory {
}

getConversations(): Conversations {
const conversations = this._context.globalState.get<
const conversations = this.context.globalState.get<
Record<string, Conversation>
>(CONVERSATION_STORAGE_KEY)
return conversations
}

resetConversation() {
this._context.globalState.update(ACTIVE_CONVERSATION_STORAGE_KEY, undefined)
this.context.globalState.update(ACTIVE_CONVERSATION_STORAGE_KEY, undefined)
this.setActiveConversation(undefined)
}

updateConversation(conversation: Conversation) {
const conversations = this.getConversations() || {}
if (!conversation.id) return
this._context.globalState.update(CONVERSATION_STORAGE_KEY, {
this.context.globalState.update(CONVERSATION_STORAGE_KEY, {
...conversations,
[conversation.id]: conversation
})
this.setActiveConversation(conversation)
}

setActiveConversation(conversation: Conversation | undefined) {
this._context.globalState.update(
this.context.globalState.update(
ACTIVE_CONVERSATION_STORAGE_KEY,
conversation
)
this._webView?.postMessage({
this.webView?.postMessage({
type: CONVERSATION_EVENT_NAME.getActiveConversation,
value: {
data: conversation
Expand All @@ -224,7 +224,7 @@ export class ConversationHistory {

getActiveConversation() {
const conversation: Conversation | undefined =
this._context.globalState.get(ACTIVE_CONVERSATION_STORAGE_KEY)
this.context.globalState.get(ACTIVE_CONVERSATION_STORAGE_KEY)
this.setActiveConversation(conversation)
return conversation
}
Expand All @@ -233,15 +233,15 @@ export class ConversationHistory {
const conversations = this.getConversations() || {}
if (!conversation?.id) return
delete conversations[conversation.id]
this._context.globalState.update(CONVERSATION_STORAGE_KEY, {
this.context.globalState.update(CONVERSATION_STORAGE_KEY, {
...conversations
})
this.setActiveConversation(undefined)
this.getAllConversations()
}

clearAllConversations() {
this._context.globalState.update(CONVERSATION_STORAGE_KEY, {})
this.context.globalState.update(CONVERSATION_STORAGE_KEY, {})
this.setActiveConversation(undefined)
}

Expand Down Expand Up @@ -287,7 +287,7 @@ export class ConversationHistory {
messages: conversation.messages
}
conversations[id] = newConversation
this._context.globalState.update(CONVERSATION_STORAGE_KEY, conversations)
this.context.globalState.update(CONVERSATION_STORAGE_KEY, conversations)
this.setActiveConversation(newConversation)
this._title = ''
}
Expand Down
22 changes: 17 additions & 5 deletions src/extension/providers/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,13 @@ import { Logger } from '../../common/logger'
import { DiffManager } from '../diff'
import { ProviderManager } from '../provider-manager'
import { FileTreeProvider } from '../tree'
import { GithubService as ReviewService } from '../review-service'

const logger = new Logger()

export class BaseProvider {
public context: vscode.ExtensionContext
public webView?: vscode.Webview
public conversationHistory: ConversationHistory | undefined = undefined
private _config = vscode.workspace.getConfiguration('twinny')
private _chatService: ChatService | undefined = undefined
private _config = vscode.workspace.getConfiguration('twinny')
private _diffManager = new DiffManager()
private _embeddingDatabase: EmbeddingDatabase | undefined
private _fileTreeProvider: FileTreeProvider
Expand All @@ -55,6 +53,10 @@ export class BaseProvider {
private _symmetryService?: SymmetryService | undefined
private _templateDir: string | undefined
private _templateProvider: TemplateProvider
public context: vscode.ExtensionContext
public conversationHistory: ConversationHistory | undefined = undefined
public reviewService: ReviewService | undefined = undefined
public webView?: vscode.Webview

constructor(
context: vscode.ExtensionContext,
Expand Down Expand Up @@ -99,6 +101,14 @@ export class BaseProvider {
this._symmetryService
)

this.reviewService = new ReviewService(
this.context,
this.webView,
this._sessionManager,
this._symmetryService,
this._templateDir
)

new ProviderManager(this.context, this.webView)

vscode.window.onDidChangeActiveColorTheme(() => {
Expand Down Expand Up @@ -201,7 +211,9 @@ export class BaseProvider {
}
if (!this._embeddingDatabase) return
for (const dir of dirs) {
(await this._embeddingDatabase.injestDocuments(dir.uri.fsPath)).populateDatabase()
(
await this._embeddingDatabase.injestDocuments(dir.uri.fsPath)
).populateDatabase()
}
}

Expand Down
Loading

0 comments on commit 0d8bdad

Please sign in to comment.