-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathprompt-loader.ts
More file actions
83 lines (76 loc) · 3.67 KB
/
prompt-loader.ts
File metadata and controls
83 lines (76 loc) · 3.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/**
* Utility functions for loading prompt template files.
*
* Prompt templates are imported as static string literals at build time via
* esbuild's `loader: { '.md': 'text' }` configuration. This ensures they
* are embedded in the bundled JS and available at runtime regardless of the
* execution layout (monorepo source, npm install, or VSIX bundle).
*/
// Static imports — esbuild inlines the file contents as string literals.
import checkForDuplicatedCode from './check-for-duplicated-code.prompt.md';
import compareOverlappingAlerts from './compare-overlapping-alerts.prompt.md';
import dataExtensionDevelopment from './data-extension-development.prompt.md';
import documentCodeqlQuery from './document-codeql-query.prompt.md';
import explainCodeqlQuery from './explain-codeql-query.prompt.md';
import findOverlappingQueries from './find-overlapping-queries.prompt.md';
import qlLspIterativeDevelopment from './ql-lsp-iterative-development.prompt.md';
import qlTddAdvanced from './ql-tdd-advanced.prompt.md';
import qlTddBasic from './ql-tdd-basic.prompt.md';
import runQueryAndSummarizeFalsePositives from './run-query-and-summarize-false-positives.prompt.md';
import sarifRankFalsePositives from './sarif-rank-false-positives.prompt.md';
import sarifRankTruePositives from './sarif-rank-true-positives.prompt.md';
import toolsQueryWorkflow from './tools-query-workflow.prompt.md';
import workshopCreationWorkflow from './workshop-creation-workflow.prompt.md';
/**
* Embedded prompt template map (filename → content).
*
* Every .prompt.md file in this directory must be listed here so it is
* bundled into the output. The keys must match the filenames passed to
* `loadPromptTemplate()` throughout the codebase.
*/
const PROMPT_TEMPLATES: Record<string, string> = {
'check-for-duplicated-code.prompt.md': checkForDuplicatedCode,
'compare-overlapping-alerts.prompt.md': compareOverlappingAlerts,
'data-extension-development.prompt.md': dataExtensionDevelopment,
'document-codeql-query.prompt.md': documentCodeqlQuery,
'explain-codeql-query.prompt.md': explainCodeqlQuery,
'find-overlapping-queries.prompt.md': findOverlappingQueries,
'ql-lsp-iterative-development.prompt.md': qlLspIterativeDevelopment,
'ql-tdd-advanced.prompt.md': qlTddAdvanced,
'ql-tdd-basic.prompt.md': qlTddBasic,
'run-query-and-summarize-false-positives.prompt.md': runQueryAndSummarizeFalsePositives,
'sarif-rank-false-positives.prompt.md': sarifRankFalsePositives,
'sarif-rank-true-positives.prompt.md': sarifRankTruePositives,
'tools-query-workflow.prompt.md': toolsQueryWorkflow,
'workshop-creation-workflow.prompt.md': workshopCreationWorkflow,
};
/**
* Load a prompt template by filename.
*
* Returns the embedded template content, or a descriptive fallback message
* if the template is not registered in the bundle.
*/
export function loadPromptTemplate(promptFileName: string): string {
const content = PROMPT_TEMPLATES[promptFileName];
if (content !== undefined) {
return content;
}
return `Prompt template '${promptFileName}' not available: not found in embedded prompt templates. Add it to PROMPT_TEMPLATES in prompt-loader.ts.`;
}
/**
* Process prompt template by replacing placeholders with actual values
*/
export function processPromptTemplate(template: string, variables: Record<string, string>): string {
let processed = template;
// Replace variables in the format {{variable}} or {variable}
for (const [key, value] of Object.entries(variables)) {
const patterns = [
new RegExp(`\\{\\{${key}\\}\\}`, 'g'),
new RegExp(`\\{${key}\\}`, 'g')
];
for (const pattern of patterns) {
processed = processed.replace(pattern, value);
}
}
return processed;
}