Skip to content

Commit c991802

Browse files
authored
extract title from prompt (#7875)
* extract title from prompt * tests
1 parent 248ba94 commit c991802

File tree

3 files changed

+26
-26
lines changed

3 files changed

+26
-26
lines changed

src/github/copilotRemoteAgent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ export class CopilotRemoteAgentManager extends Disposable {
712712
return { error: vscode.l10n.t('Failed to configure base branch \'{0}\' does not exist on the remote repository \'{1}/{2}\'. Please create the remote branch first.', base_ref, owner, repo), state: 'error' };
713713
}
714714

715-
const title = extractTitle(problemContext);
715+
const title = extractTitle(prompt, problemContext);
716716
const { problemStatement, isTruncated } = truncatePrompt(prompt, problemContext);
717717

718718
if (isTruncated) {

src/github/copilotRemoteAgentUtils.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,22 @@ export function truncatePrompt(prompt: string, context?: string): { problemState
4141
};
4242
}
4343

44-
export function extractTitle(context: string | undefined): string | undefined {
45-
if (!context) {
46-
return;
44+
export function extractTitle(prompt: string, context: string | undefined): string | undefined {
45+
const fromTitle = () => {
46+
if (!prompt) {
47+
return;
48+
}
49+
if (prompt.length <= 20) {
50+
return prompt;
51+
}
52+
return prompt.substring(0, 20) + '...';
4753
}
48-
const titleMatch = context.match(/TITLE: \s*(.*)/i);
54+
const titleMatch = context?.match(/TITLE: \s*(.*)/i);
4955
if (titleMatch && titleMatch[1]) {
5056
return titleMatch[1].trim();
5157
}
58+
return fromTitle();
59+
5260
}
5361

5462
export function formatBodyPlaceholder(title: string | undefined): string {

src/test/github/copilotRemoteAgentUtils.test.ts

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -61,46 +61,38 @@ describe('copilotRemoteAgentUtils', () => {
6161
describe('extractTitle', () => {
6262
it('should extract title from context with TITLE prefix', () => {
6363
const context = 'Some initial text\nTITLE: Fix authentication bug\nSome other content';
64-
65-
const result = extractTitle(context);
66-
64+
const result = extractTitle('', context);
6765
assert.strictEqual(result, 'Fix authentication bug');
6866
});
6967

7068
it('should extract title with case insensitive matching', () => {
7169
const context = 'Some text\ntitle: Add new feature\nMore text';
72-
73-
const result = extractTitle(context);
74-
70+
const result = extractTitle('', context);
7571
assert.strictEqual(result, 'Add new feature');
7672
});
7773

7874
it('should extract title with extra whitespace', () => {
7975
const context = 'TITLE: Refactor code structure \n';
80-
81-
const result = extractTitle(context);
82-
76+
const result = extractTitle('', context);
8377
assert.strictEqual(result, 'Refactor code structure');
8478
});
8579

86-
it('should return undefined when no title is found', () => {
80+
it('should use prompt when no title is found', () => {
8781
const context = 'Some text without any title marker\nJust regular content';
88-
89-
const result = extractTitle(context);
90-
91-
assert.strictEqual(result, undefined);
82+
const result = extractTitle('Default Title', context);
83+
assert.strictEqual(result, 'Default Title');
9284
});
9385

94-
it('should return undefined when context is undefined', () => {
95-
const result = extractTitle(undefined);
96-
97-
assert.strictEqual(result, undefined);
86+
it('should use prompt when context is undefined', () => {
87+
const result = extractTitle('Default Title', undefined);
88+
assert.strictEqual(result, 'Default Title');
9889
});
9990

100-
it('should return undefined when context is empty string', () => {
101-
const result = extractTitle('');
91+
it('should return truncated title when context is empty string', () => {
92+
const title = 'TEST TEST TEST TEST TEST TEST'; // will truncate to 20 characters
93+
const result = extractTitle(title, '');
10294

103-
assert.strictEqual(result, undefined);
95+
assert.strictEqual(result, 'TEST TEST TEST TEST ...');
10496
});
10597
});
10698
});

0 commit comments

Comments
 (0)