@dependabit/detector 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/LICENSE +21 -0
- package/README.md +32 -0
- package/dist/detector.d.ts +64 -0
- package/dist/detector.d.ts.map +1 -0
- package/dist/detector.js +578 -0
- package/dist/detector.js.map +1 -0
- package/dist/diff-parser.d.ts +53 -0
- package/dist/diff-parser.d.ts.map +1 -0
- package/dist/diff-parser.js +203 -0
- package/dist/diff-parser.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/llm/client.d.ts +65 -0
- package/dist/llm/client.d.ts.map +1 -0
- package/dist/llm/client.js +12 -0
- package/dist/llm/client.js.map +1 -0
- package/dist/llm/copilot.d.ts +15 -0
- package/dist/llm/copilot.d.ts.map +1 -0
- package/dist/llm/copilot.js +119 -0
- package/dist/llm/copilot.js.map +1 -0
- package/dist/llm/prompts.d.ts +10 -0
- package/dist/llm/prompts.d.ts.map +1 -0
- package/dist/llm/prompts.js +94 -0
- package/dist/llm/prompts.js.map +1 -0
- package/dist/parsers/code-comments.d.ts +23 -0
- package/dist/parsers/code-comments.d.ts.map +1 -0
- package/dist/parsers/code-comments.js +139 -0
- package/dist/parsers/code-comments.js.map +1 -0
- package/dist/parsers/package-files.d.ts +31 -0
- package/dist/parsers/package-files.d.ts.map +1 -0
- package/dist/parsers/package-files.js +130 -0
- package/dist/parsers/package-files.js.map +1 -0
- package/dist/parsers/readme.d.ts +23 -0
- package/dist/parsers/readme.d.ts.map +1 -0
- package/dist/parsers/readme.js +151 -0
- package/dist/parsers/readme.js.map +1 -0
- package/package.json +41 -0
- package/src/detector.ts +746 -0
- package/src/diff-parser.ts +257 -0
- package/src/index.ts +43 -0
- package/src/llm/client.ts +85 -0
- package/src/llm/copilot.ts +147 -0
- package/src/llm/prompts.ts +102 -0
- package/src/parsers/code-comments.ts +178 -0
- package/src/parsers/package-files.ts +156 -0
- package/src/parsers/readme.ts +185 -0
- package/test/detector.test.ts +102 -0
- package/test/diff-parser.test.ts +187 -0
- package/test/llm/client.test.ts +31 -0
- package/test/llm/copilot.test.ts +55 -0
- package/test/parsers/code-comments.test.ts +98 -0
- package/test/parsers/package-files.test.ts +52 -0
- package/test/parsers/readme.test.ts +52 -0
- package/tsconfig.json +10 -0
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Diff Parser
|
|
3
|
+
* Parse git diffs to extract meaningful changes for dependency analysis
|
|
4
|
+
*/
|
|
5
|
+
// URL pattern to match HTTP(S) URLs
|
|
6
|
+
const URL_PATTERN = /https?:\/\/[^\s<>"{}|\\^`[\]]+/gi;
|
|
7
|
+
// Package dependency patterns
|
|
8
|
+
const PACKAGE_DEP_PATTERNS = {
|
|
9
|
+
packageJson: /"([^"]+)":\s*"[\^~]?[\d.]+"/g,
|
|
10
|
+
requirementsTxt: /^([a-zA-Z0-9_-]+)[>=<~!]=.*/gm,
|
|
11
|
+
cargoToml: /^(?!\s*(?:name|version|authors|edition|description|license|workspace|build|default-run|repository|homepage|documentation|readme|keywords|categories|exclude|include|publish|resolver)\s*=)\s*([a-zA-Z0-9_-]+)\s*=.*/gm
|
|
12
|
+
};
|
|
13
|
+
// File extensions relevant for dependency analysis
|
|
14
|
+
const RELEVANT_EXTENSIONS = [
|
|
15
|
+
'.md',
|
|
16
|
+
'.txt',
|
|
17
|
+
'.rst',
|
|
18
|
+
'.adoc', // Documentation
|
|
19
|
+
'.ts',
|
|
20
|
+
'.js',
|
|
21
|
+
'.py',
|
|
22
|
+
'.rs',
|
|
23
|
+
'.go',
|
|
24
|
+
'.java',
|
|
25
|
+
'.cpp',
|
|
26
|
+
'.c',
|
|
27
|
+
'.h', // Code
|
|
28
|
+
'.json',
|
|
29
|
+
'.toml',
|
|
30
|
+
'.yaml',
|
|
31
|
+
'.yml', // Config
|
|
32
|
+
'.html',
|
|
33
|
+
'.xml' // Markup
|
|
34
|
+
];
|
|
35
|
+
// Package manifest files
|
|
36
|
+
const PACKAGE_MANIFEST_FILES = [
|
|
37
|
+
'package.json',
|
|
38
|
+
'requirements.txt',
|
|
39
|
+
'Cargo.toml',
|
|
40
|
+
'go.mod',
|
|
41
|
+
'pom.xml',
|
|
42
|
+
'build.gradle',
|
|
43
|
+
'Gemfile',
|
|
44
|
+
'composer.json'
|
|
45
|
+
];
|
|
46
|
+
/**
|
|
47
|
+
* Parse a unified diff and extract additions and deletions
|
|
48
|
+
*/
|
|
49
|
+
export function parseDiff(patch) {
|
|
50
|
+
const additions = [];
|
|
51
|
+
const deletions = [];
|
|
52
|
+
if (!patch) {
|
|
53
|
+
return { additions, deletions };
|
|
54
|
+
}
|
|
55
|
+
const lines = patch.split('\n');
|
|
56
|
+
for (const line of lines) {
|
|
57
|
+
if (line.startsWith('+') && !line.startsWith('+++')) {
|
|
58
|
+
// Addition (remove the + prefix)
|
|
59
|
+
additions.push(line.substring(1));
|
|
60
|
+
}
|
|
61
|
+
else if (line.startsWith('-') && !line.startsWith('---')) {
|
|
62
|
+
// Deletion (remove the - prefix)
|
|
63
|
+
deletions.push(line.substring(1));
|
|
64
|
+
}
|
|
65
|
+
// Ignore context lines (no prefix or space prefix)
|
|
66
|
+
}
|
|
67
|
+
return { additions, deletions };
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Extract meaningful content from added lines
|
|
71
|
+
*/
|
|
72
|
+
export function extractAddedContent(additions, filename) {
|
|
73
|
+
const urls = [];
|
|
74
|
+
const packageDeps = [];
|
|
75
|
+
const content = additions.join('\n');
|
|
76
|
+
// Extract URLs
|
|
77
|
+
const urlMatches = content.matchAll(URL_PATTERN);
|
|
78
|
+
for (const match of urlMatches) {
|
|
79
|
+
urls.push(match[0]);
|
|
80
|
+
}
|
|
81
|
+
// Extract package dependencies based on file type
|
|
82
|
+
if (filename) {
|
|
83
|
+
const lowerFilename = filename.toLowerCase();
|
|
84
|
+
if (lowerFilename === 'package.json') {
|
|
85
|
+
const depMatches = content.matchAll(PACKAGE_DEP_PATTERNS.packageJson);
|
|
86
|
+
for (const match of depMatches) {
|
|
87
|
+
if (match[1])
|
|
88
|
+
packageDeps.push(match[1]);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
else if (lowerFilename === 'requirements.txt') {
|
|
92
|
+
const depMatches = content.matchAll(PACKAGE_DEP_PATTERNS.requirementsTxt);
|
|
93
|
+
for (const match of depMatches) {
|
|
94
|
+
if (match[1])
|
|
95
|
+
packageDeps.push(match[1]);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
else if (lowerFilename === 'cargo.toml') {
|
|
99
|
+
const depMatches = content.matchAll(PACKAGE_DEP_PATTERNS.cargoToml);
|
|
100
|
+
for (const match of depMatches) {
|
|
101
|
+
if (match[1])
|
|
102
|
+
packageDeps.push(match[1]);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
urls: Array.from(new Set(urls)),
|
|
108
|
+
packageDeps: Array.from(new Set(packageDeps))
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Extract meaningful content from removed lines
|
|
113
|
+
*/
|
|
114
|
+
export function extractRemovedContent(deletions, filename) {
|
|
115
|
+
// Use the same logic as extractAddedContent
|
|
116
|
+
return extractAddedContent(deletions, filename);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Identify files relevant for dependency analysis
|
|
120
|
+
*
|
|
121
|
+
* Note: Filenames in relevantFiles preserve their original case from the commit.
|
|
122
|
+
* Case-insensitive matching is used for identification, but original casing is maintained
|
|
123
|
+
* for consistency with file system operations.
|
|
124
|
+
*/
|
|
125
|
+
export function getChangedFiles(files) {
|
|
126
|
+
const relevantFiles = [];
|
|
127
|
+
const packageFiles = [];
|
|
128
|
+
const documentationFiles = [];
|
|
129
|
+
for (const file of files) {
|
|
130
|
+
const filename = file.filename.toLowerCase();
|
|
131
|
+
const basename = filename.split('/').pop() || '';
|
|
132
|
+
// Check if it's a package manifest file (case-insensitive comparison)
|
|
133
|
+
const isPackageFile = PACKAGE_MANIFEST_FILES.some((manifestFile) => manifestFile.toLowerCase() === basename);
|
|
134
|
+
if (isPackageFile) {
|
|
135
|
+
packageFiles.push(file.filename);
|
|
136
|
+
relevantFiles.push(file.filename);
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
// Check if it's a documentation file
|
|
140
|
+
if (basename.startsWith('readme') ||
|
|
141
|
+
filename.includes('/docs/') ||
|
|
142
|
+
filename.includes('/documentation/')) {
|
|
143
|
+
documentationFiles.push(file.filename);
|
|
144
|
+
relevantFiles.push(file.filename);
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
// Check if it has a relevant extension
|
|
148
|
+
const hasRelevantExtension = RELEVANT_EXTENSIONS.some((ext) => filename.endsWith(ext));
|
|
149
|
+
if (hasRelevantExtension) {
|
|
150
|
+
relevantFiles.push(file.filename);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return {
|
|
154
|
+
relevantFiles: Array.from(new Set(relevantFiles)),
|
|
155
|
+
packageFiles: Array.from(new Set(packageFiles)),
|
|
156
|
+
documentationFiles: Array.from(new Set(documentationFiles))
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Parse all diffs from commit files
|
|
161
|
+
*/
|
|
162
|
+
export function parseCommitDiffs(files) {
|
|
163
|
+
const diffMap = new Map();
|
|
164
|
+
for (const file of files) {
|
|
165
|
+
if (file.patch) {
|
|
166
|
+
diffMap.set(file.filename, parseDiff(file.patch));
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return diffMap;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Extract all dependency-related content from commit diffs
|
|
173
|
+
*/
|
|
174
|
+
export function extractDependencyChanges(files) {
|
|
175
|
+
const changedFiles = getChangedFiles(files);
|
|
176
|
+
const allAddedUrls = [];
|
|
177
|
+
const allRemovedUrls = [];
|
|
178
|
+
const allAddedPackages = [];
|
|
179
|
+
const allRemovedPackages = [];
|
|
180
|
+
for (const file of files) {
|
|
181
|
+
if (!file.patch || !changedFiles.relevantFiles.includes(file.filename)) {
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
const diff = parseDiff(file.patch);
|
|
185
|
+
const basename = file.filename.split('/').pop();
|
|
186
|
+
// Extract added content
|
|
187
|
+
const addedContent = extractAddedContent(diff.additions, basename);
|
|
188
|
+
allAddedUrls.push(...addedContent.urls);
|
|
189
|
+
allAddedPackages.push(...addedContent.packageDeps);
|
|
190
|
+
// Extract removed content
|
|
191
|
+
const removedContent = extractRemovedContent(diff.deletions, basename);
|
|
192
|
+
allRemovedUrls.push(...removedContent.urls);
|
|
193
|
+
allRemovedPackages.push(...removedContent.packageDeps);
|
|
194
|
+
}
|
|
195
|
+
return {
|
|
196
|
+
addedUrls: Array.from(new Set(allAddedUrls)),
|
|
197
|
+
removedUrls: Array.from(new Set(allRemovedUrls)),
|
|
198
|
+
addedPackages: Array.from(new Set(allAddedPackages)),
|
|
199
|
+
removedPackages: Array.from(new Set(allRemovedPackages)),
|
|
200
|
+
changedFiles
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
//# sourceMappingURL=diff-parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diff-parser.js","sourceRoot":"","sources":["../src/diff-parser.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAoBH,oCAAoC;AACpC,MAAM,WAAW,GAAG,kCAAkC,CAAC;AAEvD,8BAA8B;AAC9B,MAAM,oBAAoB,GAAG;IAC3B,WAAW,EAAE,8BAA8B;IAC3C,eAAe,EAAE,+BAA+B;IAChD,SAAS,EACP,uNAAuN;CAC1N,CAAC;AAEF,mDAAmD;AACnD,MAAM,mBAAmB,GA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AY,CAAC,CAAC;QAC5C,WAAW,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,cAAc,CAAC,CAAC;QAChD,aAAa,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,gBAAgB,CAAC,CAAC;QACpD,eAAe,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,kBAAkB,CAAC,CAAC;QACxD,YAAY;KACb,CAAC;AAAA,CACH"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type { LLMProvider, LLMProviderConfig, LLMResponse, RateLimitInfo, DetectedDependency, LLMUsageMetadata } from './llm/client.js';
|
|
2
|
+
export { GitHubCopilotProvider } from './llm/copilot.js';
|
|
3
|
+
export { SYSTEM_PROMPT, createDetectionPrompt, createClassificationPrompt } from './llm/prompts.js';
|
|
4
|
+
export type { ExtractedReference } from './parsers/readme.js';
|
|
5
|
+
export { parseReadme, extractGitHubReferences } from './parsers/readme.js';
|
|
6
|
+
export type { CommentReference } from './parsers/code-comments.js';
|
|
7
|
+
export { parseCodeComments, extractSpecReferences } from './parsers/code-comments.js';
|
|
8
|
+
export type { PackageMetadata } from './parsers/package-files.js';
|
|
9
|
+
export { parsePackageJson, parseRequirementsTxt, parseCargoToml, parseGoMod } from './parsers/package-files.js';
|
|
10
|
+
export type { DiffParseResult, ExtractedContent, ChangedFilesResult } from './diff-parser.js';
|
|
11
|
+
export { parseDiff, extractAddedContent, extractRemovedContent, getChangedFiles, parseCommitDiffs, extractDependencyChanges } from './diff-parser.js';
|
|
12
|
+
export type { DetectorOptions, DetectionResult } from './detector.js';
|
|
13
|
+
export { Detector } from './detector.js';
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,YAAY,EACV,WAAW,EACX,iBAAiB,EACjB,WAAW,EACX,aAAa,EACb,kBAAkB,EAClB,gBAAgB,EACjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,0BAA0B,EAAE,MAAM,kBAAkB,CAAC;AAGpG,YAAY,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAE3E,YAAY,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAEtF,YAAY,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,EACL,gBAAgB,EAChB,oBAAoB,EACpB,cAAc,EACd,UAAU,EACX,MAAM,4BAA4B,CAAC;AAGpC,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAC9F,OAAO,EACL,SAAS,EACT,mBAAmB,EACnB,qBAAqB,EACrB,eAAe,EACf,gBAAgB,EAChB,wBAAwB,EACzB,MAAM,kBAAkB,CAAC;AAG1B,YAAY,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACtE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Entry point for @dependabit/detector
|
|
2
|
+
export { GitHubCopilotProvider } from './llm/copilot.js';
|
|
3
|
+
export { SYSTEM_PROMPT, createDetectionPrompt, createClassificationPrompt } from './llm/prompts.js';
|
|
4
|
+
export { parseReadme, extractGitHubReferences } from './parsers/readme.js';
|
|
5
|
+
export { parseCodeComments, extractSpecReferences } from './parsers/code-comments.js';
|
|
6
|
+
export { parsePackageJson, parseRequirementsTxt, parseCargoToml, parseGoMod } from './parsers/package-files.js';
|
|
7
|
+
export { parseDiff, extractAddedContent, extractRemovedContent, getChangedFiles, parseCommitDiffs, extractDependencyChanges } from './diff-parser.js';
|
|
8
|
+
export { Detector } from './detector.js';
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AAWvC,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,0BAA0B,EAAE,MAAM,kBAAkB,CAAC;AAIpG,OAAO,EAAE,WAAW,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAG3E,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAGtF,OAAO,EACL,gBAAgB,EAChB,oBAAoB,EACpB,cAAc,EACd,UAAU,EACX,MAAM,4BAA4B,CAAC;AAIpC,OAAO,EACL,SAAS,EACT,mBAAmB,EACnB,qBAAqB,EACrB,eAAe,EACf,gBAAgB,EAChB,wBAAwB,EACzB,MAAM,kBAAkB,CAAC;AAI1B,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LLM Provider Interface
|
|
3
|
+
* Abstraction layer for different LLM providers (GitHub Copilot, Claude, OpenAI, etc.)
|
|
4
|
+
*/
|
|
5
|
+
export interface RateLimitInfo {
|
|
6
|
+
remaining: number;
|
|
7
|
+
limit: number;
|
|
8
|
+
resetAt: Date;
|
|
9
|
+
}
|
|
10
|
+
export interface LLMUsageMetadata {
|
|
11
|
+
promptTokens: number;
|
|
12
|
+
completionTokens: number;
|
|
13
|
+
totalTokens: number;
|
|
14
|
+
model: string;
|
|
15
|
+
latencyMs: number;
|
|
16
|
+
}
|
|
17
|
+
export interface DetectedDependency {
|
|
18
|
+
url: string;
|
|
19
|
+
name: string;
|
|
20
|
+
description?: string;
|
|
21
|
+
type: 'reference-implementation' | 'schema' | 'documentation' | 'research-paper' | 'api-example' | 'other';
|
|
22
|
+
confidence: number;
|
|
23
|
+
reasoning?: string;
|
|
24
|
+
}
|
|
25
|
+
export interface LLMResponse {
|
|
26
|
+
dependencies: DetectedDependency[];
|
|
27
|
+
usage: LLMUsageMetadata;
|
|
28
|
+
rawResponse?: string;
|
|
29
|
+
}
|
|
30
|
+
export interface LLMProviderConfig {
|
|
31
|
+
apiKey?: string;
|
|
32
|
+
endpoint?: string;
|
|
33
|
+
model?: string;
|
|
34
|
+
maxTokens?: number;
|
|
35
|
+
temperature?: number;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Base interface that all LLM providers must implement
|
|
39
|
+
*/
|
|
40
|
+
export interface LLMProvider {
|
|
41
|
+
/**
|
|
42
|
+
* Analyze content and detect external dependencies
|
|
43
|
+
* @param content - Text content to analyze (README, code, etc.)
|
|
44
|
+
* @param prompt - Detection prompt template
|
|
45
|
+
* @returns LLM response with detected dependencies
|
|
46
|
+
*/
|
|
47
|
+
analyze(content: string, prompt: string): Promise<LLMResponse>;
|
|
48
|
+
/**
|
|
49
|
+
* Get list of supported models for this provider
|
|
50
|
+
*/
|
|
51
|
+
getSupportedModels(): string[];
|
|
52
|
+
/**
|
|
53
|
+
* Get current rate limit status
|
|
54
|
+
*/
|
|
55
|
+
getRateLimit(): Promise<RateLimitInfo>;
|
|
56
|
+
/**
|
|
57
|
+
* Validate provider configuration
|
|
58
|
+
*/
|
|
59
|
+
validateConfig(): boolean;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Create an LLM provider instance
|
|
63
|
+
*/
|
|
64
|
+
export declare function createLLMProvider(providerName: string, config: LLMProviderConfig): LLMProvider;
|
|
65
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.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AAO,CAAC,aAAa,CAAC,CAAC;IAEvC;;OAEG;IACH,cAAc,IAAI,OAAO,CAAC;CAC3B;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,iBAAiB,GAAG,WAAW,CAG9F"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LLM Provider Interface
|
|
3
|
+
* Abstraction layer for different LLM providers (GitHub Copilot, Claude, OpenAI, etc.)
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Create an LLM provider instance
|
|
7
|
+
*/
|
|
8
|
+
export function createLLMProvider(providerName, config) {
|
|
9
|
+
// Implementation will be in specific provider files
|
|
10
|
+
throw new Error(`Provider ${providerName} not yet implemented`);
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/llm/client.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA2EH;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,YAAoB,EAAE,MAAyB,EAAe;IAC9F,oDAAoD;IACpD,MAAM,IAAI,KAAK,CAAC,YAAY,YAAY,sBAAsB,CAAC,CAAC;AAAA,CACjE"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GitHub Copilot CLI Provider Implementation
|
|
3
|
+
* Integrates with GitHub Copilot via CLI commands
|
|
4
|
+
*/
|
|
5
|
+
import type { LLMProvider, LLMProviderConfig, LLMResponse, RateLimitInfo } from './client.js';
|
|
6
|
+
export declare class GitHubCopilotProvider implements LLMProvider {
|
|
7
|
+
private config;
|
|
8
|
+
private model;
|
|
9
|
+
constructor(config?: LLMProviderConfig);
|
|
10
|
+
analyze(content: string, prompt: string): Promise<LLMResponse>;
|
|
11
|
+
getSupportedModels(): string[];
|
|
12
|
+
getRateLimit(): Promise<RateLimitInfo>;
|
|
13
|
+
validateConfig(): boolean;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=copilot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"copilot.d.ts","sourceRoot":"","sources":["../../src/llm/copilot.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,KAAK,EACV,WAAW,EACX,iBAAiB,EACjB,WAAW,EACX,aAAa,EAGd,MAAM,aAAa,CAAC;AAKrB,qBAAa,qBAAsB,YAAW,WAAW;IACvD,OAAO,CAAC,MAAM,CAA8B;IAC5C,OAAO,CAAC,KAAK,CAAS;IAEtB,YAAY,MAAM,GAAE,iBAAsB,EAczC;IAEK,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAqFnE;IAED,kBAAkB,IAAI,MAAM,EAAE,CAG7B;IAEK,YAAY,IAAI,OAAO,CAAC,aAAa,CAAC,CAQ3C;IAED,cAAc,IAAI,OAAO,CAIxB;CACF"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GitHub Copilot CLI Provider Implementation
|
|
3
|
+
* Integrates with GitHub Copilot via CLI commands
|
|
4
|
+
*/
|
|
5
|
+
import { exec } from 'node:child_process';
|
|
6
|
+
import { promisify } from 'node:util';
|
|
7
|
+
import { SYSTEM_PROMPT } from './prompts.js';
|
|
8
|
+
const execAsync = promisify(exec);
|
|
9
|
+
export class GitHubCopilotProvider {
|
|
10
|
+
config;
|
|
11
|
+
model;
|
|
12
|
+
constructor(config = {}) {
|
|
13
|
+
// Default configuration for CLI-based approach
|
|
14
|
+
this.config = {
|
|
15
|
+
apiKey: config.apiKey || process.env['GITHUB_TOKEN'] || '',
|
|
16
|
+
endpoint: config.endpoint || '',
|
|
17
|
+
model: config.model || 'gpt-4',
|
|
18
|
+
maxTokens: config.maxTokens || 4000,
|
|
19
|
+
temperature: config.temperature || 0.3
|
|
20
|
+
};
|
|
21
|
+
this.model = this.config.model;
|
|
22
|
+
// GitHub Copilot CLI uses GitHub authentication, not a separate API key
|
|
23
|
+
// The GITHUB_TOKEN is used for authentication with GitHub, not OpenAI
|
|
24
|
+
}
|
|
25
|
+
async analyze(content, prompt) {
|
|
26
|
+
const startTime = Date.now();
|
|
27
|
+
try {
|
|
28
|
+
// Combine system prompt and user prompt for CLI
|
|
29
|
+
const fullPrompt = `${SYSTEM_PROMPT}\n\n${prompt}`;
|
|
30
|
+
// Escape the prompt for shell safety (basic escaping)
|
|
31
|
+
const escapedPrompt = fullPrompt.replace(/"/g, '\\"').replace(/\$/g, '\\$');
|
|
32
|
+
// Use gh copilot suggest command to get AI response
|
|
33
|
+
// The --yes flag auto-accepts the suggestion, --shell-out returns raw output
|
|
34
|
+
const command = `echo "${escapedPrompt}" | gh copilot suggest --yes 2>&1`;
|
|
35
|
+
const { stdout, stderr } = await execAsync(command, {
|
|
36
|
+
maxBuffer: 10 * 1024 * 1024, // 10MB buffer for large responses
|
|
37
|
+
timeout: 60000 // 60 second timeout
|
|
38
|
+
});
|
|
39
|
+
const latencyMs = Date.now() - startTime;
|
|
40
|
+
if (stderr && !stdout) {
|
|
41
|
+
throw new Error(`Copilot CLI error: ${stderr}`);
|
|
42
|
+
}
|
|
43
|
+
// Try to parse the output as JSON
|
|
44
|
+
// Copilot CLI may return the JSON directly or wrapped in markdown
|
|
45
|
+
let content_text = stdout.trim();
|
|
46
|
+
// Remove markdown code blocks if present
|
|
47
|
+
if (content_text.includes('```json')) {
|
|
48
|
+
const jsonMatch = content_text.match(/```json\s*([\s\S]*?)```/);
|
|
49
|
+
if (jsonMatch && jsonMatch[1]) {
|
|
50
|
+
content_text = jsonMatch[1].trim();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
else if (content_text.includes('```')) {
|
|
54
|
+
const codeMatch = content_text.match(/```\s*([\s\S]*?)```/);
|
|
55
|
+
if (codeMatch && codeMatch[1]) {
|
|
56
|
+
content_text = codeMatch[1].trim();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
let parsed;
|
|
60
|
+
try {
|
|
61
|
+
parsed = JSON.parse(content_text);
|
|
62
|
+
}
|
|
63
|
+
catch (parseError) {
|
|
64
|
+
console.error('Failed to parse Copilot CLI response:', content_text, parseError);
|
|
65
|
+
// Return empty dependencies if parsing fails
|
|
66
|
+
parsed = { dependencies: [] };
|
|
67
|
+
}
|
|
68
|
+
// Estimate token usage (rough approximation since CLI doesn't provide this)
|
|
69
|
+
const estimatedTokens = Math.ceil(fullPrompt.length / 4) + Math.ceil(content_text.length / 4);
|
|
70
|
+
const usage = {
|
|
71
|
+
promptTokens: Math.ceil(fullPrompt.length / 4),
|
|
72
|
+
completionTokens: Math.ceil(content_text.length / 4),
|
|
73
|
+
totalTokens: estimatedTokens,
|
|
74
|
+
model: this.model,
|
|
75
|
+
latencyMs
|
|
76
|
+
};
|
|
77
|
+
return {
|
|
78
|
+
dependencies: parsed.dependencies || [],
|
|
79
|
+
usage,
|
|
80
|
+
rawResponse: content_text
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
const latencyMs = Date.now() - startTime;
|
|
85
|
+
console.error('Copilot CLI analysis failed:', error);
|
|
86
|
+
// Return empty result on error
|
|
87
|
+
return {
|
|
88
|
+
dependencies: [],
|
|
89
|
+
usage: {
|
|
90
|
+
promptTokens: 0,
|
|
91
|
+
completionTokens: 0,
|
|
92
|
+
totalTokens: 0,
|
|
93
|
+
model: this.model,
|
|
94
|
+
latencyMs
|
|
95
|
+
},
|
|
96
|
+
rawResponse: error instanceof Error ? error.message : 'Unknown error'
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
getSupportedModels() {
|
|
101
|
+
// Copilot CLI uses GitHub's models, not directly specified
|
|
102
|
+
return ['github-copilot', 'gpt-4', 'gpt-4-turbo'];
|
|
103
|
+
}
|
|
104
|
+
async getRateLimit() {
|
|
105
|
+
// Copilot CLI doesn't expose rate limits directly
|
|
106
|
+
// Rate limiting is handled by GitHub's infrastructure
|
|
107
|
+
return {
|
|
108
|
+
remaining: -1, // Unknown
|
|
109
|
+
limit: -1, // Unknown
|
|
110
|
+
resetAt: new Date(0) // Unknown
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
validateConfig() {
|
|
114
|
+
// For CLI approach, we just need gh CLI to be available
|
|
115
|
+
// Authentication is handled by GitHub CLI itself
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=copilot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"copilot.js","sourceRoot":"","sources":["../../src/llm/copilot.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAStC,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,MAAM,SAAS,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;AAElC,MAAM,OAAO,qBAAqB;IACxB,MAAM,CAA8B;IACpC,KAAK,CAAS;IAEtB,YAAY,MAAM,GAAsB,EAAE,EAAE;QAC1C,+CAA+C;QAC/C,IAAI,CAAC,MAAM,GAAG;YACZ,MAAM,EAAE,MAAM,CAAC,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,EAAE;YAC1D,QAAQ,EAAE,MAAM,CAAC,QAAQ,IAAI,EAAE;YAC/B,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,OAAO;YAC9B,SAAS,EAAE,MAAM,CAAC,SAAS,IAAI,IAAI;YACnC,WAAW,EAAE,MAAM,CAAC,WAAW,IAAI,GAAG;SACvC,CAAC;QAEF,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;QAE/B,wEAAwE;QACxE,sEAA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S,CAAC;YACzC,OAAO,CAAC,KAAK,CAAC,8BAA8B,EAAE,KAAK,CAAC,CAAC;YAErD,+BAA+B;YAC/B,OAAO;gBACL,YAAY,EAAE,EAAE;gBAChB,KAAK,EAAE;oBACL,YAAY,EAAE,CAAC;oBACf,gBAAgB,EAAE,CAAC;oBACnB,WAAW,EAAE,CAAC;oBACd,KAAK,EAAE,IAAI,CAAC,KAAK;oBACjB,SAAS;iBACV;gBACD,WAAW,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe;aACtE,CAAC;QACJ,CAAC;IAAA,CACF;IAED,kBAAkB,GAAa;QAC7B,2DAA2D;QAC3D,OAAO,CAAC,gBAAgB,EAAE,OAAO,EAAE,aAAa,CAAC,CAAC;IAAA,CACnD;IAED,KAAK,CAAC,YAAY,GAA2B;QAC3C,kDAAkD;QAClD,sDAAsD;QACtD,OAAO;YACL,SAAS,EAAE,CAAC,CAAC,EAAE,UAAU;YACzB,KAAK,EAAE,CAAC,CAAC,EAAE,UAAU;YACrB,OAAO,EAAE,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,UAAU;SAChC,CAAC;IAAA,CACH;IAED,cAAc,GAAY;QACxB,wDAAwD;QACxD,iDAAiD;QACjD,OAAO,IAAI,CAAC;IAAA,CACb;CACF"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Detection prompts for LLM-based dependency analysis
|
|
3
|
+
* Optimized for identifying external informational dependencies
|
|
4
|
+
*/
|
|
5
|
+
export declare const SYSTEM_PROMPT = "You are an expert at analyzing code repositories to identify external informational dependencies.\n\nYour task is to identify external resources that developers reference but are NOT tracked by package managers (npm, PyPI, Cargo, etc.).\n\nINCLUDE these types of dependencies:\n- GitHub repositories referenced but not declared in package files\n- Documentation sites and API references\n- OpenAPI/GraphQL schemas\n- Research papers and arXiv preprints\n- Reference implementations and code examples\n- Technical specifications and RFCs\n\nEXCLUDE these (handled by dependabot):\n- NPM packages in package.json\n- Python packages in requirements.txt \n- Rust crates in Cargo.toml\n- Docker images in Dockerfile\n- Any declared package manager dependencies\n\nFor each dependency found, provide:\n1. url: The complete URL\n2. name: A descriptive name\n3. description: What this dependency is used for\n4. type: One of [reference-implementation, schema, documentation, research-paper, api-example, other]\n5. confidence: A score from 0.0 to 1.0 indicating detection confidence\n6. reasoning: Brief explanation of why this is a dependency\n\nReturn ONLY valid JSON in this format:\n{\n \"dependencies\": [\n {\n \"url\": \"https://example.com/resource\",\n \"name\": \"Resource Name\",\n \"description\": \"Purpose in the project\",\n \"type\": \"documentation\",\n \"confidence\": 0.95,\n \"reasoning\": \"Referenced in README as API documentation\"\n }\n ]\n}";
|
|
6
|
+
export declare const DETECTION_PROMPT_TEMPLATE = "Analyze the following content from a code repository and identify external informational dependencies:\n\n## Content Type: {contentType}\n## File Path: {filePath}\n\n## Content:\n{content}\n\nRemember:\n- Focus on external resources NOT in package managers\n- Provide confidence scores based on clarity of references\n- Include context about how each dependency is used\n- Return valid JSON only\n\nAnalyze and respond:";
|
|
7
|
+
export declare function createDetectionPrompt(contentType: string, filePath: string, content: string): string;
|
|
8
|
+
export declare const CLASSIFICATION_PROMPT_TEMPLATE = "Given this URL, classify its dependency type and suggest the best access method:\n\nURL: {url}\nContext: {context}\n\nClassify as one of:\n- reference-implementation: Example code demonstrating usage\n- schema: OpenAPI, JSON Schema, GraphQL, Protocol Buffers \n- documentation: API docs, tutorials, guides\n- research-paper: Academic papers, arXiv preprints\n- api-example: Code snippets from documentation\n- other: If none of the above fit\n\nAlso determine the best access method:\n- github-api: For GitHub repositories\n- arxiv: For arXiv papers\n- openapi: For OpenAPI specifications\n- http: For generic web content\n\nReturn JSON:\n{\n \"type\": \"documentation\",\n \"accessMethod\": \"http\",\n \"confidence\": 0.9,\n \"reasoning\": \"URL structure suggests API documentation\"\n}";
|
|
9
|
+
export declare function createClassificationPrompt(url: string, context: string): string;
|
|
10
|
+
//# sourceMappingURL=prompts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../../src/llm/prompts.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,eAAO,MAAM,aAAa,89CAuCxB,CAAC;AAEH,eAAO,MAAM,yBAAyB,waAcjB,CAAC;AAEtB,wBAAgB,qBAAqB,CACnC,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,GACd,MAAM,CAIR;AAED,eAAO,MAAM,8BAA8B,+xBAyBzC,CAAC;AAEH,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAE/E"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Detection prompts for LLM-based dependency analysis
|
|
3
|
+
* Optimized for identifying external informational dependencies
|
|
4
|
+
*/
|
|
5
|
+
export const SYSTEM_PROMPT = `You are an expert at analyzing code repositories to identify external informational dependencies.
|
|
6
|
+
|
|
7
|
+
Your task is to identify external resources that developers reference but are NOT tracked by package managers (npm, PyPI, Cargo, etc.).
|
|
8
|
+
|
|
9
|
+
INCLUDE these types of dependencies:
|
|
10
|
+
- GitHub repositories referenced but not declared in package files
|
|
11
|
+
- Documentation sites and API references
|
|
12
|
+
- OpenAPI/GraphQL schemas
|
|
13
|
+
- Research papers and arXiv preprints
|
|
14
|
+
- Reference implementations and code examples
|
|
15
|
+
- Technical specifications and RFCs
|
|
16
|
+
|
|
17
|
+
EXCLUDE these (handled by dependabot):
|
|
18
|
+
- NPM packages in package.json
|
|
19
|
+
- Python packages in requirements.txt
|
|
20
|
+
- Rust crates in Cargo.toml
|
|
21
|
+
- Docker images in Dockerfile
|
|
22
|
+
- Any declared package manager dependencies
|
|
23
|
+
|
|
24
|
+
For each dependency found, provide:
|
|
25
|
+
1. url: The complete URL
|
|
26
|
+
2. name: A descriptive name
|
|
27
|
+
3. description: What this dependency is used for
|
|
28
|
+
4. type: One of [reference-implementation, schema, documentation, research-paper, api-example, other]
|
|
29
|
+
5. confidence: A score from 0.0 to 1.0 indicating detection confidence
|
|
30
|
+
6. reasoning: Brief explanation of why this is a dependency
|
|
31
|
+
|
|
32
|
+
Return ONLY valid JSON in this format:
|
|
33
|
+
{
|
|
34
|
+
"dependencies": [
|
|
35
|
+
{
|
|
36
|
+
"url": "https://example.com/resource",
|
|
37
|
+
"name": "Resource Name",
|
|
38
|
+
"description": "Purpose in the project",
|
|
39
|
+
"type": "documentation",
|
|
40
|
+
"confidence": 0.95,
|
|
41
|
+
"reasoning": "Referenced in README as API documentation"
|
|
42
|
+
}
|
|
43
|
+
]
|
|
44
|
+
}`;
|
|
45
|
+
export const DETECTION_PROMPT_TEMPLATE = `Analyze the following content from a code repository and identify external informational dependencies:
|
|
46
|
+
|
|
47
|
+
## Content Type: {contentType}
|
|
48
|
+
## File Path: {filePath}
|
|
49
|
+
|
|
50
|
+
## Content:
|
|
51
|
+
{content}
|
|
52
|
+
|
|
53
|
+
Remember:
|
|
54
|
+
- Focus on external resources NOT in package managers
|
|
55
|
+
- Provide confidence scores based on clarity of references
|
|
56
|
+
- Include context about how each dependency is used
|
|
57
|
+
- Return valid JSON only
|
|
58
|
+
|
|
59
|
+
Analyze and respond:`;
|
|
60
|
+
export function createDetectionPrompt(contentType, filePath, content) {
|
|
61
|
+
return DETECTION_PROMPT_TEMPLATE.replace('{contentType}', contentType)
|
|
62
|
+
.replace('{filePath}', filePath)
|
|
63
|
+
.replace('{content}', content);
|
|
64
|
+
}
|
|
65
|
+
export const CLASSIFICATION_PROMPT_TEMPLATE = `Given this URL, classify its dependency type and suggest the best access method:
|
|
66
|
+
|
|
67
|
+
URL: {url}
|
|
68
|
+
Context: {context}
|
|
69
|
+
|
|
70
|
+
Classify as one of:
|
|
71
|
+
- reference-implementation: Example code demonstrating usage
|
|
72
|
+
- schema: OpenAPI, JSON Schema, GraphQL, Protocol Buffers
|
|
73
|
+
- documentation: API docs, tutorials, guides
|
|
74
|
+
- research-paper: Academic papers, arXiv preprints
|
|
75
|
+
- api-example: Code snippets from documentation
|
|
76
|
+
- other: If none of the above fit
|
|
77
|
+
|
|
78
|
+
Also determine the best access method:
|
|
79
|
+
- github-api: For GitHub repositories
|
|
80
|
+
- arxiv: For arXiv papers
|
|
81
|
+
- openapi: For OpenAPI specifications
|
|
82
|
+
- http: For generic web content
|
|
83
|
+
|
|
84
|
+
Return JSON:
|
|
85
|
+
{
|
|
86
|
+
"type": "documentation",
|
|
87
|
+
"accessMethod": "http",
|
|
88
|
+
"confidence": 0.9,
|
|
89
|
+
"reasoning": "URL structure suggests API documentation"
|
|
90
|
+
}`;
|
|
91
|
+
export function createClassificationPrompt(url, context) {
|
|
92
|
+
return CLASSIFICATION_PROMPT_TEMPLATE.replace('{url}', url).replace('{context}', context);
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=prompts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompts.js","sourceRoot":"","sources":["../../src/llm/prompts.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,CAAC,MAAM,aAAa,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAuC3B,CAAC;AAEH,MAAM,CAAC,MAAM,yBAAyB,GAAG;;;;;;;;;;;;;;qBAcpB,CAAC;AAEtB,MAAM,UAAU,qBAAqB,CACnC,WAAmB,EACnB,QAAgB,EAChB,OAAe,EACP;IACR,OAAO,yBAAyB,CAAC,OAAO,CAAC,eAAe,EAAE,WAAW,CAAC;SACnE,OAAO,CAAC,YAAY,EAAE,QAAQ,CAAC;SAC/B,OAAO,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;AAAA,CAClC;AAED,MAAM,CAAC,MAAM,8BAA8B,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;EAyB5C,CAAC;AAEH,MAAM,UAAU,0BAA0B,CAAC,GAAW,EAAE,OAAe,EAAU;IAC/E,OAAO,8BAA8B,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;AAAA,CAC3F"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Code Comment Parser
|
|
3
|
+
* Extracts URLs and references from code comments
|
|
4
|
+
*/
|
|
5
|
+
export interface CommentReference {
|
|
6
|
+
url: string;
|
|
7
|
+
context: string;
|
|
8
|
+
file: string;
|
|
9
|
+
line: number;
|
|
10
|
+
commentType: 'single-line' | 'multi-line' | 'jsdoc';
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Parse code files and extract references from comments
|
|
14
|
+
*/
|
|
15
|
+
export declare function parseCodeComments(content: string, filePath: string): CommentReference[];
|
|
16
|
+
/**
|
|
17
|
+
* Extract specification and RFC references from comments
|
|
18
|
+
*/
|
|
19
|
+
export declare function extractSpecReferences(content: string): Array<{
|
|
20
|
+
spec: string;
|
|
21
|
+
context: string;
|
|
22
|
+
}>;
|
|
23
|
+
//# sourceMappingURL=code-comments.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-comments.d.ts","sourceRoot":"","sources":["../../src/parsers/code-comments.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,gBAAgB;IAC/B,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,aAAa,GAAG,YAAY,GAAG,OAAO,CAAC;CACrD;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,gBAAgB,EAAE,CA6DvF;AAwED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC,CAyB/F"}
|