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
22 changes: 11 additions & 11 deletions packages/web/src/features/chat/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,19 +200,19 @@ When you have sufficient context, output your answer as a structured markdown re
**Required Response Format:**
- **CRITICAL**: You MUST always prefix your answer with a \`${ANSWER_TAG}\` tag at the very top of your response
- **CRITICAL**: You MUST provide your complete response in markdown format with embedded code references
- **CODE REFERENCE REQUIREMENT**: Whenever you mention, discuss, or refer to ANY specific part of the code (files, functions, variables, methods, classes, imports, etc.), you MUST immediately follow with a code reference using the format \`${fileReferenceToString({ fileName: 'filename'})}\` or \`${fileReferenceToString({ fileName: 'filename', range: { startLine: 1, endLine: 10 } })}\` (where the numbers are the start and end line numbers of the code snippet). This includes:
- Files (e.g., "The \`auth.ts\` file" → must include \`${fileReferenceToString({ fileName: 'auth.ts' })}\`)
- Function names (e.g., "The \`getRepos()\` function" → must include \`${fileReferenceToString({ fileName: 'auth.ts', range: { startLine: 15, endLine: 20 } })}\`)
- Variable names (e.g., "The \`suggestionQuery\` variable" → must include \`${fileReferenceToString({ fileName: 'search.ts', range: { startLine: 42, endLine: 42 } })}\`)
- Code patterns (e.g., "using \`file:\${suggestionQuery}\` pattern" → must include \`${fileReferenceToString({ fileName: 'search.ts', range: { startLine: 10, endLine: 15 } })}\`)
- **CODE REFERENCE REQUIREMENT**: Whenever you mention, discuss, or refer to ANY specific part of the code (files, functions, variables, methods, classes, imports, etc.), you MUST immediately follow with a code reference using the format \`${fileReferenceToString({ repo: 'repository', path: 'filename'})}\` or \`${fileReferenceToString({ repo: 'repository', path: 'filename', range: { startLine: 1, endLine: 10 } })}\` (where the numbers are the start and end line numbers of the code snippet). This includes:
- Files (e.g., "The \`auth.ts\` file" → must include \`${fileReferenceToString({ repo: 'repository', path: 'auth.ts' })}\`)
- Function names (e.g., "The \`getRepos()\` function" → must include \`${fileReferenceToString({ repo: 'repository', path: 'auth.ts', range: { startLine: 15, endLine: 20 } })}\`)
- Variable names (e.g., "The \`suggestionQuery\` variable" → must include \`${fileReferenceToString({ repo: 'repository', path: 'search.ts', range: { startLine: 42, endLine: 42 } })}\`)
- Any code snippet or line you're explaining
- Class names, method calls, imports, etc.
- Some examples of both correct and incorrect code references:
- Correct: @file:{path/to/file.ts}
- Correct: @file:{path/to/file.ts:10-15}
- Incorrect: @file{path/to/file.ts} (missing colon)
- Incorrect: @file:path/to/file.ts (missing curly braces)
- Incorrect: @file:{path/to/file.ts:10-25,30-35} (multiple ranges not supported)
- Correct: @file:{repository::path/to/file.ts}
- Correct: @file:{repository::path/to/file.ts:10-15}
- Incorrect: @file{repository::path/to/file.ts} (missing colon)
- Incorrect: @file:repository::path/to/file.ts (missing curly braces)
- Incorrect: @file:{repository::path/to/file.ts:10-25,30-35} (multiple ranges not supported)
- Incorrect: @file:{path/to/file.ts} (missing repository)
- Be clear and very concise. Use bullet points where appropriate
- Do NOT explain code without providing the exact location reference. Every code mention requires a corresponding \`${FILE_REFERENCE_PREFIX}\` reference
- If you cannot provide a code reference for something you're discussing, do not mention that specific code element
Expand All @@ -221,7 +221,7 @@ When you have sufficient context, output your answer as a structured markdown re
**Example answer structure:**
\`\`\`markdown
${ANSWER_TAG}
Authentication in Sourcebot is built on NextAuth.js with a session-based approach using JWT tokens and Prisma as the database adapter ${fileReferenceToString({ fileName: 'auth.ts', range: { startLine: 135, endLine: 140 } })}. The system supports multiple authentication providers and implements organization-based authorization with role-defined permissions.
Authentication in Sourcebot is built on NextAuth.js with a session-based approach using JWT tokens and Prisma as the database adapter ${fileReferenceToString({ repo: 'github.com/sourcebot-dev/sourcebot', path: 'auth.ts', range: { startLine: 135, endLine: 140 } })}. The system supports multiple authentication providers and implements organization-based authorization with role-defined permissions.
\`\`\`

</answer_instructions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ describe('calculateVisibleRanges', () => {
test('applies padding to a single range', () => {
const references: FileReference[] = [
{
fileName: 'test.ts',
path: 'test.ts',
id: '1',
type: 'file',
range: {
startLine: 10,
endLine: 15
}
},
repo: 'github.com/sourcebot-dev/sourcebot'
}
];

Expand All @@ -38,16 +39,18 @@ describe('calculateVisibleRanges', () => {
test('merges overlapping ranges', () => {
const references: FileReference[] = [
{
fileName: 'test.ts',
path: 'test.ts',
id: '1',
type: 'file',
range: { startLine: 10, endLine: 15 }
range: { startLine: 10, endLine: 15 },
repo: 'github.com/sourcebot-dev/sourcebot'
},
{
fileName: 'test.ts',
path: 'test.ts',
id: '2',
type: 'file',
range: { startLine: 12, endLine: 20 }
range: { startLine: 12, endLine: 20 },
repo: 'github.com/sourcebot-dev/sourcebot'
}
];

Expand All @@ -62,16 +65,18 @@ describe('calculateVisibleRanges', () => {
test('merges adjacent ranges (including padding)', () => {
const references: FileReference[] = [
{
fileName: 'test.ts',
path: 'test.ts',
id: '1',
type: 'file',
range: { startLine: 10, endLine: 15 }
range: { startLine: 10, endLine: 15 },
repo: 'github.com/sourcebot-dev/sourcebot'
},
{
fileName: 'test.ts',
path: 'test.ts',
id: '2',
type: 'file',
range: { startLine: 19, endLine: 25 }
range: { startLine: 19, endLine: 25 },
repo: 'github.com/sourcebot-dev/sourcebot'
}
];

Expand All @@ -88,16 +93,18 @@ describe('calculateVisibleRanges', () => {
test('keeps separate ranges when they dont overlap', () => {
const references: FileReference[] = [
{
fileName: 'test.ts',
path: 'test.ts',
id: '1',
type: 'file',
range: { startLine: 10, endLine: 15 }
range: { startLine: 10, endLine: 15 },
repo: 'github.com/sourcebot-dev/sourcebot'
},
{
fileName: 'test.ts',
path: 'test.ts',
id: '2',
type: 'file',
range: { startLine: 25, endLine: 30 }
range: { startLine: 25, endLine: 30 },
repo: 'github.com/sourcebot-dev/sourcebot'
}
];

Expand All @@ -112,10 +119,11 @@ describe('calculateVisibleRanges', () => {
test('respects file boundaries - start of file', () => {
const references: FileReference[] = [
{
fileName: 'test.ts',
path: 'test.ts',
id: '1',
type: 'file',
range: { startLine: 1, endLine: 5 }
range: { startLine: 1, endLine: 5 },
repo: 'github.com/sourcebot-dev/sourcebot'
}
];

Expand All @@ -130,10 +138,11 @@ describe('calculateVisibleRanges', () => {
test('respects file boundaries - end of file', () => {
const references: FileReference[] = [
{
fileName: 'test.ts',
path: 'test.ts',
id: '1',
type: 'file',
range: { startLine: 95, endLine: 100 }
range: { startLine: 95, endLine: 100 },
repo: 'github.com/sourcebot-dev/sourcebot'
}
];

Expand All @@ -148,28 +157,32 @@ describe('calculateVisibleRanges', () => {
test('handles multiple ranges with complex overlaps', () => {
const references: FileReference[] = [
{
fileName: 'test.ts',
path: 'test.ts',
id: '1',
type: 'file',
range: { startLine: 10, endLine: 15 }
range: { startLine: 10, endLine: 15 },
repo: 'github.com/sourcebot-dev/sourcebot'
},
{
fileName: 'test.ts',
path: 'test.ts',
id: '2',
type: 'file',
range: { startLine: 20, endLine: 25 }
range: { startLine: 20, endLine: 25 },
repo: 'github.com/sourcebot-dev/sourcebot'
},
{
fileName: 'test.ts',
path: 'test.ts',
id: '3',
type: 'file',
range: { startLine: 22, endLine: 30 }
range: { startLine: 22, endLine: 30 },
repo: 'github.com/sourcebot-dev/sourcebot'
},
{
fileName: 'test.ts',
path: 'test.ts',
id: '4',
type: 'file',
range: { startLine: 50, endLine: 55 }
range: { startLine: 50, endLine: 55 },
repo: 'github.com/sourcebot-dev/sourcebot'
}
];

Expand All @@ -195,16 +208,18 @@ describe('calculateVisibleRanges', () => {
test('ignores references without ranges', () => {
const references: FileReference[] = [
{
fileName: 'test.ts',
path: 'test.ts',
id: '1',
type: 'file',
// No range property
repo: 'github.com/sourcebot-dev/sourcebot'
},
{
fileName: 'test.ts',
path: 'test.ts',
id: '2',
type: 'file',
range: { startLine: 10, endLine: 15 }
range: { startLine: 10, endLine: 15 },
repo: 'github.com/sourcebot-dev/sourcebot'
}
];

Expand All @@ -219,10 +234,11 @@ describe('calculateVisibleRanges', () => {
test('works with zero padding', () => {
const references: FileReference[] = [
{
fileName: 'test.ts',
path: 'test.ts',
id: '1',
type: 'file',
range: { startLine: 10, endLine: 15 }
range: { startLine: 10, endLine: 15 },
repo: 'github.com/sourcebot-dev/sourcebot'
}
];

Expand All @@ -237,10 +253,11 @@ describe('calculateVisibleRanges', () => {
test('handles single line ranges', () => {
const references: FileReference[] = [
{
fileName: 'test.ts',
path: 'test.ts',
id: '1',
type: 'file',
range: { startLine: 10, endLine: 10 }
range: { startLine: 10, endLine: 10 },
repo: 'github.com/sourcebot-dev/sourcebot'
}
];

Expand All @@ -255,22 +272,25 @@ describe('calculateVisibleRanges', () => {
test('sorts ranges by start line', () => {
const references: FileReference[] = [
{
fileName: 'test.ts',
path: 'test.ts',
id: '1',
type: 'file',
range: { startLine: 50, endLine: 55 }
range: { startLine: 50, endLine: 55 },
repo: 'github.com/sourcebot-dev/sourcebot'
},
{
fileName: 'test.ts',
path: 'test.ts',
id: '2',
type: 'file',
range: { startLine: 10, endLine: 15 }
range: { startLine: 10, endLine: 15 },
repo: 'github.com/sourcebot-dev/sourcebot'
},
{
fileName: 'test.ts',
path: 'test.ts',
id: '3',
type: 'file',
range: { startLine: 30, endLine: 35 }
range: { startLine: 30, endLine: 35 },
repo: 'github.com/sourcebot-dev/sourcebot'
}
];

Expand Down Expand Up @@ -380,16 +400,18 @@ describe('StateField Integration', () => {
test('initial state calculation with references', () => {
const references: FileReference[] = [
{
fileName: 'test.ts',
path: 'test.ts',
id: '1',
type: 'file',
range: { startLine: 10, endLine: 15 }
range: { startLine: 10, endLine: 15 },
repo: 'github.com/sourcebot-dev/sourcebot'
},
{
fileName: 'test.ts',
path: 'test.ts',
id: '2',
type: 'file',
range: { startLine: 25, endLine: 30 }
range: { startLine: 25, endLine: 30 },
repo: 'github.com/sourcebot-dev/sourcebot'
}
];

Expand Down Expand Up @@ -457,7 +479,7 @@ describe('StateField Integration', () => {
// Update references
const newReferences: FileReference[] = [
{
fileName: 'test.ts',
path: 'test.ts',
id: '1',
type: 'file',
range: { startLine: 10, endLine: 15 }
Expand All @@ -482,10 +504,11 @@ describe('StateField Integration', () => {
test('expandRegionEffect expands hidden region up', () => {
const references: FileReference[] = [
{
fileName: 'test.ts',
path: 'test.ts',
id: '1',
type: 'file',
range: { startLine: 20, endLine: 25 }
range: { startLine: 20, endLine: 25 },
repo: 'github.com/sourcebot-dev/sourcebot'
}
];

Expand Down Expand Up @@ -528,10 +551,11 @@ describe('StateField Integration', () => {
test('expandRegionEffect expands hidden region down', () => {
const references: FileReference[] = [
{
fileName: 'test.ts',
path: 'test.ts',
id: '1',
type: 'file',
range: { startLine: 20, endLine: 25 }
range: { startLine: 20, endLine: 25 },
repo: 'github.com/sourcebot-dev/sourcebot'
}
];

Expand Down Expand Up @@ -564,10 +588,11 @@ describe('StateField Integration', () => {
test('document changes recalculate state', () => {
const references: FileReference[] = [
{
fileName: 'test.ts',
path: 'test.ts',
id: '1',
type: 'file',
range: { startLine: 10, endLine: 15 }
range: { startLine: 10, endLine: 15 },
repo: 'github.com/sourcebot-dev/sourcebot'
}
];

Expand Down Expand Up @@ -606,10 +631,11 @@ describe('StateField Integration', () => {
test('action creators work correctly', () => {
const references: FileReference[] = [
{
fileName: 'test.ts',
path: 'test.ts',
id: '1',
type: 'file',
range: { startLine: 10, endLine: 15 }
range: { startLine: 10, endLine: 15 },
repo: 'github.com/sourcebot-dev/sourcebot'
}
];

Expand Down Expand Up @@ -647,16 +673,18 @@ describe('StateField Integration', () => {
// Add references
const references: FileReference[] = [
{
fileName: 'test.ts',
path: 'test.ts',
id: '1',
type: 'file',
range: { startLine: 20, endLine: 25 }
range: { startLine: 20, endLine: 25 },
repo: 'github.com/sourcebot-dev/sourcebot'
},
{
fileName: 'test.ts',
path: 'test.ts',
id: '2',
type: 'file',
range: { startLine: 60, endLine: 65 }
range: { startLine: 60, endLine: 65 },
repo: 'github.com/sourcebot-dev/sourcebot'
}
];

Expand Down
Loading