|
1 | 1 | export class ToolTracker { |
2 | | - private searchCalls: number = 0; |
3 | | - private searchResults: Set<string> = new Set(); |
4 | | - private viewedPaths: Set<string> = new Set(); |
| 2 | + private docSearchCalls: number = 0; |
| 3 | + private docSearchResults: Set<string> = new Set(); |
| 4 | + private viewedDocPaths: Set<string> = new Set(); |
| 5 | + private codeSearchCalls: number = 0; |
| 6 | + private codeSearchResults: number = 0; |
| 7 | + private viewedCodePaths: Set<string> = new Set(); |
| 8 | + private listedDirs: number = 0; |
5 | 9 |
|
6 | 10 | recordSearchCall(results: string[]): void { |
7 | | - this.searchCalls++; |
8 | | - results.forEach((result) => this.searchResults.add(result)); |
| 11 | + this.docSearchCalls++; |
| 12 | + results.forEach((result) => this.docSearchResults.add(result)); |
9 | 13 | } |
10 | 14 |
|
11 | 15 | recordViewCall(filePaths: string | string[]): void { |
12 | 16 | const paths = Array.isArray(filePaths) ? filePaths : [filePaths]; |
13 | | - paths.forEach((path) => this.viewedPaths.add(path)); |
| 17 | + paths.forEach((path) => this.viewedDocPaths.add(path)); |
| 18 | + } |
| 19 | + |
| 20 | + recordCodeSearchCall(resultCount: number): void { |
| 21 | + this.codeSearchCalls++; |
| 22 | + this.codeSearchResults += resultCount; |
| 23 | + } |
| 24 | + |
| 25 | + recordCodeViewCall(filePaths: string | string[]): void { |
| 26 | + const paths = Array.isArray(filePaths) ? filePaths : [filePaths]; |
| 27 | + paths.forEach((path) => this.viewedCodePaths.add(path)); |
| 28 | + } |
| 29 | + |
| 30 | + recordListDir(): void { |
| 31 | + this.listedDirs++; |
14 | 32 | } |
15 | 33 |
|
16 | 34 | getSummary(): string { |
17 | 35 | const parts: string[] = []; |
18 | 36 |
|
19 | | - if (this.searchCalls > 0) { |
20 | | - const resultCount = this.searchResults.size; |
21 | | - const timesText = this.searchCalls === 1 ? "time" : "times"; |
| 37 | + if (this.docSearchCalls > 0) { |
| 38 | + const resultCount = this.docSearchResults.size; |
| 39 | + const timesText = this.docSearchCalls === 1 ? "time" : "times"; |
22 | 40 | const resultsText = resultCount === 1 ? "result" : "results"; |
23 | 41 | parts.push( |
24 | | - `searched ${this.searchCalls} ${timesText} with ${resultCount} ${resultsText}`, |
| 42 | + `searched docs ${this.docSearchCalls} ${timesText} with ${resultCount} ${resultsText}`, |
25 | 43 | ); |
26 | 44 | } |
27 | 45 |
|
28 | | - if (this.viewedPaths.size > 0) { |
29 | | - const pageCount = this.viewedPaths.size; |
| 46 | + if (this.viewedDocPaths.size > 0) { |
| 47 | + const pageCount = this.viewedDocPaths.size; |
30 | 48 | const pagesText = pageCount === 1 ? "page" : "pages"; |
31 | | - parts.push(`viewed ${pageCount} ${pagesText}`); |
| 49 | + parts.push(`viewed ${pageCount} doc ${pagesText}`); |
| 50 | + } |
| 51 | + |
| 52 | + if (this.codeSearchCalls > 0) { |
| 53 | + const timesText = this.codeSearchCalls === 1 ? "time" : "times"; |
| 54 | + const matchText = this.codeSearchResults === 1 ? "match" : "matches"; |
| 55 | + parts.push( |
| 56 | + `searched code ${this.codeSearchCalls} ${timesText} with ${this.codeSearchResults} ${matchText}`, |
| 57 | + ); |
| 58 | + } |
| 59 | + |
| 60 | + if (this.viewedCodePaths.size > 0) { |
| 61 | + const fileCount = this.viewedCodePaths.size; |
| 62 | + const filesText = fileCount === 1 ? "file" : "files"; |
| 63 | + parts.push(`viewed ${fileCount} source ${filesText}`); |
32 | 64 | } |
33 | 65 |
|
34 | 66 | if (parts.length === 0) return ""; |
35 | 67 |
|
36 | 68 | const firstPart = parts[0].charAt(0).toUpperCase() + parts[0].slice(1); |
37 | | - return parts.length === 1 ? firstPart : firstPart + ", " + parts[1]; |
| 69 | + if (parts.length === 1) return firstPart; |
| 70 | + return firstPart + ", " + parts.slice(1).join(", "); |
38 | 71 | } |
39 | 72 | } |
0 commit comments