Skip to content

Commit

Permalink
summarize file now checks by default if the file should be summarized
Browse files Browse the repository at this point in the history
  • Loading branch information
brandon-schabel committed Jan 14, 2025
1 parent 9cd2daf commit 36ef863
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 32 deletions.
49 changes: 23 additions & 26 deletions packages/server/src/services/file-change-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,34 +51,31 @@ export class FileChangePlugin {
const globalState = await getState();


const summarizeFiles = globalState.settings.disableSummarizationProjectIds.includes(project.id);

if (summarizeFiles) {

// 5) Re-run summarization for this single file
await this.summaryService.summarizeFiles(
project.id,
[updatedFile],
{
settings: {
language: 'en',
theme: 'light',
codeThemeLight: 'atomOneLight',
codeThemeDark: 'atomOneDark',
ollamaGlobalUrl: 'http://localhost:11434',
lmStudioGlobalUrl: 'http://localhost:8000',
summarizationIgnorePatterns: [],
summarizationAllowPatterns: [],
disableSummarizationProjectIds: [],
},
counter: 0,
projectTabs: {},
projectActiveTabId: null,
chatTabs: {},
chatActiveTabId: null,
}
);
}
// 5) Re-run summarization for this single file
await this.summaryService.summarizeFiles(
project.id,
[updatedFile],
{
settings: {
language: 'en',
theme: 'light',
codeThemeLight: 'atomOneLight',
codeThemeDark: 'atomOneDark',
ollamaGlobalUrl: 'http://localhost:11434',
lmStudioGlobalUrl: 'http://localhost:8000',
summarizationIgnorePatterns: [],
summarizationAllowPatterns: [],
disableSummarizationProjectIds: [],
},
counter: 0,
projectTabs: {},
projectActiveTabId: null,
chatTabs: {},
chatActiveTabId: null,
}
);
} catch (err) {
console.error('[FileChangePlugin] Error handling file change:', err);
}
Expand Down
16 changes: 10 additions & 6 deletions packages/server/src/services/file-summary-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ProjectFile as ProjectFileType, GlobalState } from 'shared'
import { matchesAnyPattern } from 'shared/src/utils/pattern-matcher'
import { promptsMap } from '@/prompts/prompts-map'
import { UnifiedProviderService } from './model-providers/providers/unified-provider-service'
import { getState } from '@/websocket/websocket-config'

function chunkArray<T>(arr: T[], size: number): T[][] {
const chunks: T[][] = []
Expand All @@ -15,22 +16,24 @@ function chunkArray<T>(arr: T[], size: number): T[][] {
}

const shouldSummarizeFile = async (projectId: string, filePath: string): Promise<boolean> => {
const settings = await getSettings()

const state = await getState()
const settings = state.settings


if (settings.disableSummarizationProjectIds.includes(projectId)) {
return false
}

const matchesIgnorePattern = settings.summarizationIgnorePatterns.some(pattern =>
const matchesIgnorePattern = settings.summarizationIgnorePatterns.some(pattern =>
new RegExp(pattern).test(filePath)
)

if (matchesIgnorePattern) {
return false
}

const hasAllowPatterns = settings.summarizationAllowPatterns.length > 0
const matchesAllowPattern = settings.summarizationAllowPatterns.some(pattern =>
const matchesAllowPattern = settings.summarizationAllowPatterns.some(pattern =>
new RegExp(pattern).test(filePath)
)

Expand Down Expand Up @@ -168,9 +171,10 @@ export class FileSummaryService {
*/
private async summarizeFile(file: ProjectFileType) {
if (!await shouldSummarizeFile(file.projectId, file.path)) {
console.log(`[FileSummaryService] Skipping summarization for file: ${file.name}`)
return
}

try {
const fileContent = file.content || ''
if (!fileContent.trim()) {
Expand Down

0 comments on commit 36ef863

Please sign in to comment.