File size: 43,211 Bytes
1978456 |
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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 |
// universal-developer-vscode/src/extension.ts
import * as vscode from 'vscode';
/**
* Symbolic command definition
*/
interface SymbolicCommand {
name: string;
description: string;
parameters?: {
name: string;
description: string;
required?: boolean;
default?: any;
}[];
examples: string[];
provider?: {
claude?: boolean;
openai?: boolean;
qwen?: boolean;
gemini?: boolean;
ollama?: boolean;
};
}
/**
* Universal developer extension activation function
*/
export function activate(context: vscode.ExtensionContext) {
console.log('Universal Developer extension is now active');
// Register command palette commands
const insertSymbolicCommand = vscode.commands.registerCommand(
'universal-developer.insertSymbolicCommand',
async () => {
const commandName = await showSymbolicCommandQuickPick();
if (!commandName) return;
const command = SYMBOLIC_COMMANDS.find(cmd => cmd.name === commandName);
if (!command) return;
// Check if command has parameters
let commandString = `/${command.name}`;
if (command.parameters && command.parameters.length > 0) {
const parameters = await collectCommandParameters(command);
if (parameters) {
Object.entries(parameters).forEach(([key, value]) => {
if (value !== undefined && value !== null && value !== '') {
commandString += ` --${key}=${value}`;
}
});
}
}
// Insert command at cursor position
const editor = vscode.window.activeTextEditor;
if (editor) {
editor.edit(editBuilder => {
editBuilder.insert(editor.selection.active, commandString + ' ');
});
}
}
);
// Register the symbolic command chain builder
const buildSymbolicChain = vscode.commands.registerCommand(
'universal-developer.buildSymbolicChain',
async () => {
await showCommandChainBuilder();
}
);
// Register symbolic command hover provider
const hoverProvider = vscode.languages.registerHoverProvider(
['javascript', 'typescript', 'python', 'markdown', 'plaintext'],
{
provideHover(document, position, token) {
const range = document.getWordRangeAtPosition(position, /\/[a-zA-Z0-9_]+/);
if (!range) return;
const commandText = document.getText(range);
const commandName = commandText.substring(1); // Remove the leading /
const command = SYMBOLIC_COMMANDS.find(cmd => cmd.name === commandName);
if (!command) return;
// Create hover markdown
const hoverContent = new vscode.MarkdownString();
hoverContent.appendMarkdown(`**/${command.name}**\n\n`);
hoverContent.appendMarkdown(`${command.description}\n\n`);
if (command.parameters && command.parameters.length > 0) {
hoverContent.appendMarkdown('**Parameters:**\n\n');
command.parameters.forEach(param => {
const required = param.required ? ' (required)' : '';
const defaultValue = param.default !== undefined ? ` (default: ${param.default})` : '';
hoverContent.appendMarkdown(`- \`--${param.name}\`${required}${defaultValue}: ${param.description}\n`);
});
hoverContent.appendMarkdown('\n');
}
if (command.examples && command.examples.length > 0) {
hoverContent.appendMarkdown('**Examples:**\n\n');
command.examples.forEach(example => {
hoverContent.appendCodeBlock(example, 'markdown');
});
}
// Show provider compatibility
if (command.provider) {
hoverContent.appendMarkdown('\n**Compatible with:**\n\n');
const supported = Object.entries(command.provider)
.filter(([_, isSupported]) => isSupported)
.map(([provider]) => provider);
hoverContent.appendMarkdown(supported.join(', '));
}
return new vscode.Hover(hoverContent, range);
}
}
);
// Register completion provider for symbolic commands
const completionProvider = vscode.languages.registerCompletionItemProvider(
['javascript', 'typescript', 'python', 'markdown', 'plaintext'],
{
provideCompletionItems(document, position) {
const linePrefix = document.lineAt(position).text.substring(0, position.character);
// Check if we're at the start of a potential symbolic command
if (!linePrefix.endsWith('/')) {
return undefined;
}
const completionItems = SYMBOLIC_COMMANDS.map(command => {
const item = new vscode.CompletionItem(
command.name,
vscode.CompletionItemKind.Keyword
);
item.insertText = command.name;
item.detail = command.description;
item.documentation = new vscode.MarkdownString(command.description);
return item;
});
return completionItems;
}
},
'/' // Only trigger after the / character
);
// Register parameter completion provider
const parameterCompletionProvider = vscode.languages.registerCompletionItemProvider(
['javascript', 'typescript', 'python', 'markdown', 'plaintext'],
{
provideCompletionItems(document, position) {
const linePrefix = document.lineAt(position).text.substring(0, position.character);
// Match a symbolic command with a potential parameter start
const commandMatch = linePrefix.match(/\/([a-zA-Z0-9_]+)(?:\s+(?:[^\s]+\s+)*)?--$/);
if (!commandMatch) {
return undefined;
}
const commandName = commandMatch[1];
const command = SYMBOLIC_COMMANDS.find(cmd => cmd.name === commandName);
if (!command || !command.parameters || command.parameters.length === 0) {
return undefined;
}
// Offer parameter completions
const completionItems = command.parameters.map(param => {
const item = new vscode.CompletionItem(
param.name,
vscode.CompletionItemKind.Property
);
item.insertText = `${param.name}=`;
item.detail = param.description;
if (param.default !== undefined) {
item.documentation = new vscode.MarkdownString(
`${param.description}\n\nDefault: \`${param.default}\``
);
} else {
item.documentation = new vscode.MarkdownString(param.description);
}
return item;
});
return completionItems;
}
},
'-' // Trigger after - (the second dash in --)
);
// Register code actions provider for symbolic command suggestions
const codeActionsProvider = vscode.languages.registerCodeActionsProvider(
['javascript', 'typescript', 'python'],
{
provideCodeActions(document, range, context, token) {
// Check if there's any LLM API call in the current line
const line = document.lineAt(range.start.line).text;
const llmApiPatterns = [
/\.generate\(\s*{/, // UniversalLLM.generate()
/\.createCompletion\(/, // OpenAI
/\.createChatCompletion\(/, // OpenAI
/\.chat\.completions\.create\(/, // OpenAI v2
/\.messages\.create\(/, // Anthropic/Claude
/\.generateContent\(/ // Google Gemini
];
if (!llmApiPatterns.some(pattern => pattern.test(line))) {
return;
}
// Create code actions for adding symbolic commands
const actions: vscode.CodeAction[] = [];
// Find the prompt parameter
const promptMatch = line.match(/(prompt|messages|content)\s*:/);
if (!promptMatch) return;
// Add actions for common symbolic commands
['think', 'fast', 'reflect', 'loop'].forEach(commandName => {
const command = SYMBOLIC_COMMANDS.find(cmd => cmd.name === commandName);
if (!command) return;
const action = new vscode.CodeAction(
`Add /${commandName} command`,
vscode.CodeActionKind.RefactorRewrite
);
action.command = {
title: `Insert /${commandName}`,
command: 'universal-developer.insertSymbolicCommandAtPrompt',
arguments: [range.start.line, command]
};
actions.push(action);
});
return actions;
}
}
);
// Register command to insert symbolic command at prompt
const insertSymbolicCommandAtPrompt = vscode.commands.registerCommand(
'universal-developer.insertSymbolicCommandAtPrompt',
async (line: number, command: SymbolicCommand) => {
const editor = vscode.window.activeTextEditor;
if (!editor) return;
const document = editor.document;
const lineText = document.lineAt(line).text;
// Find where the prompt string starts
const promptMatch = lineText.match(/(prompt|messages|content)\s*:\s*['"]/);
if (!promptMatch) return;
const promptStartIdx = promptMatch.index! + promptMatch[0].length;
const position = new vscode.Position(line, promptStartIdx);
editor.edit(editBuilder => {
editBuilder.insert(position, `/${command.name} `);
});
}
);
// Register status bar item for active symbolic context
const statusBarItem = vscode.window.createStatusBarItem(
vscode.StatusBarAlignment.Right,
100
);
statusBarItem.text = "$(symbol-keyword) Symbolic";
statusBarItem.tooltip = "Universal Developer: Click to insert symbolic command";
statusBarItem.command = 'universal-developer.insertSymbolicCommand';
statusBarItem.show();
// Register documentation webview
const showDocumentation = vscode.commands.registerCommand(
'universal-developer.showDocumentation',
() => {
const panel = vscode.window.createWebviewPanel(
'universalDeveloperDocs',
'Universal Developer Documentation',
vscode.ViewColumn.One,
{ enableScripts: true }
);
panel.webview.html = getDocumentationHtml();
}
);
// Register commands for the extension
context.subscriptions.push(
insertSymbolicCommand,
buildSymbolicChain,
hoverProvider,
completionProvider,
parameterCompletionProvider,
codeActionsProvider,
insertSymbolicCommandAtPrompt,
statusBarItem,
showDocumentation
);
// Telemetry for command usage (anonymized)
context.subscriptions.push(
vscode.commands.registerCommand(
'universal-developer.trackCommandUsage',
(commandName: string) => {
// Only track if user has opted in to telemetry
const config = vscode.workspace.getConfiguration('universal-developer');
if (config.get('enableTelemetry', true)) {
sendAnonymizedTelemetry('command_used', { command: commandName });
}
}
)
);
}
// Helper function to show a quick pick for symbolic commands
async function showSymbolicCommandQuickPick(): Promise<string | undefined> {
const items = SYMBOLIC_COMMANDS.map(command => ({
label: `/${command.name}`,
description: command.description,
detail: command.parameters && command.parameters.length > 0
? `Parameters: ${command.parameters.map(p => p.name).join(', ')}`
: undefined
}));
const selected = await vscode
// universal-developer-vscode/src/extension.ts (continued)
// Helper function to show a quick pick for symbolic commands
async function showSymbolicCommandQuickPick(): Promise<string | undefined> {
const items = SYMBOLIC_COMMANDS.map(command => ({
label: `/${command.name}`,
description: command.description,
detail: command.parameters && command.parameters.length > 0
? `Parameters: ${command.parameters.map(p => p.name).join(', ')}`
: undefined
}));
const selected = await vscode.window.showQuickPick(items, {
placeHolder: 'Select a symbolic runtime command',
});
return selected ? selected.label.substring(1) : undefined; // Remove the leading /
}
// Helper function to collect parameters for a command
async function collectCommandParameters(command: SymbolicCommand): Promise<Record<string, any> | undefined> {
if (!command.parameters || command.parameters.length === 0) {
return {};
}
const parameters: Record<string, any> = {};
// Set default values
command.parameters.forEach(param => {
if (param.default !== undefined) {
parameters[param.name] = param.default;
}
});
// Ask for each parameter
for (const param of command.parameters) {
const value = await vscode.window.showInputBox({
prompt: param.description,
placeHolder: param.default !== undefined ? `Default: ${param.default}` : undefined,
ignoreFocusOut: true,
validateInput: text => {
if (param.required && !text) {
return `${param.name} is required`;
}
return null;
}
});
// User canceled
if (value === undefined) {
return undefined;
}
// Only set if value is provided
if (value !== '') {
parameters[param.name] = value;
}
}
return parameters;
}
// Command Chain Builder Interface
async function showCommandChainBuilder() {
// Create webview panel for the command chain builder
const panel = vscode.window.createWebviewPanel(
'universalDeveloperChainBuilder',
'Symbolic Command Chain Builder',
vscode.ViewColumn.Two,
{
enableScripts: true,
retainContextWhenHidden: true
}
);
// Load chain builder HTML
panel.webview.html = getCommandChainBuilderHtml();
// Handle messages from webview
panel.webview.onDidReceiveMessage(
message => {
switch (message.command) {
case 'insertCommandChain':
const editor = vscode.window.activeTextEditor;
if (editor) {
editor.edit(editBuilder => {
editBuilder.insert(editor.selection.active, message.commandChain);
});
}
break;
case 'getCommandInfo':
panel.webview.postMessage({
command: 'commandInfo',
commands: SYMBOLIC_COMMANDS
});
break;
}
},
undefined,
[]
);
}
// Get HTML for the command chain builder webview
function getCommandChainBuilderHtml() {
return `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Symbolic Command Chain Builder</title>
<style>
body {
font-family: var(--vscode-font-family);
padding: 20px;
color: var(--vscode-foreground);
background-color: var(--vscode-editor-background);
}
h1 {
font-size: 1.5em;
margin-bottom: 20px;
}
.command-chain {
display: flex;
flex-direction: column;
gap: 10px;
margin-bottom: 20px;
padding: 10px;
background-color: var(--vscode-editor-inactiveSelectionBackground);
border-radius: 4px;
}
.command-step {
display: flex;
align-items: center;
gap: 10px;
}
.command-preview {
margin-top: 20px;
padding: 10px;
background-color: var(--vscode-input-background);
border-radius: 4px;
font-family: var(--vscode-editor-font-family);
}
button {
padding: 8px 12px;
background-color: var(--vscode-button-background);
color: var(--vscode-button-foreground);
border: none;
border-radius: 4px;
cursor: pointer;
}
button:hover {
background-color: var(--vscode-button-hoverBackground);
}
select, input {
padding: 6px;
background-color: var(--vscode-input-background);
color: var(--vscode-input-foreground);
border: 1px solid var(--vscode-input-border);
border-radius: 4px;
}
.command-step .remove {
color: var(--vscode-errorForeground);
}
.parameter-group {
margin-left: 20px;
margin-top: 5px;
display: flex;
flex-wrap: wrap;
gap: 5px;
}
.parameter-item {
display: flex;
align-items: center;
gap: 5px;
}
.parameter-label {
font-size: 0.9em;
color: var(--vscode-descriptionForeground);
}
.command-description {
font-size: 0.9em;
margin-left: 20px;
color: var(--vscode-descriptionForeground);
}
.buttons {
display: flex;
gap: 10px;
margin-top: 20px;
}
</style>
</head>
<body>
<h1>Symbolic Command Chain Builder</h1>
<div class="command-chain" id="commandChain">
<!-- Command steps will be added here -->
</div>
<button id="addCommand">Add Command</button>
<div class="command-preview">
<div><strong>Preview:</strong></div>
<div id="previewText"></div>
</div>
<div class="buttons">
<button id="insertChain">Insert Into Editor</button>
<button id="clearChain">Clear</button>
</div>
<script>
// Communication with VSCode extension
const vscode = acquireVsCodeApi();
// Request command info from extension
vscode.postMessage({ command: 'getCommandInfo' });
// Store commands when received from extension
let commands = [];
window.addEventListener('message', event => {
const message = event.data;
if (message.command === 'commandInfo') {
commands = message.commands;
// If we already have commands in the UI, update their descriptions
updateCommandDescriptions();
}
});
// Chain state
let commandChain = [];
// DOM elements
const commandChainEl = document.getElementById('commandChain');
const addCommandBtn = document.getElementById('addCommand');
const previewTextEl = document.getElementById('previewText');
const insertChainBtn = document.getElementById('insertChain');
const clearChainBtn = document.getElementById('clearChain');
// Add new command
addCommandBtn.addEventListener('click', () => {
addCommandStep();
});
// Insert chain into editor
insertChainBtn.addEventListener('click', () => {
const commandChainText = generateCommandChainText();
vscode.postMessage({
command: 'insertCommandChain',
commandChain: commandChainText
});
});
// Clear command chain
clearChainBtn.addEventListener('click', () => {
commandChain = [];
commandChainEl.innerHTML = '';
updatePreview();
});
// Add a command step to the chain
function addCommandStep() {
const stepIndex = commandChain.length;
commandChain.push({
name: '',
parameters: {}
});
const stepEl = document.createElement('div');
stepEl.className = 'command-step';
stepEl.dataset.index = stepIndex;
const selectEl = document.createElement('select');
selectEl.innerHTML = '<option value="">Select command</option>' +
commands.map(cmd => `<option value="${cmd.name}">/${cmd.name}</option>`).join('');
selectEl.addEventListener('change', function() {
const commandName = this.value;
commandChain[stepIndex].name = commandName;
// Update command description
updateCommandDescription(stepIndex);
// Clear existing parameters
const existingParamGroup = stepEl.querySelector('.parameter-group');
if (existingParamGroup) {
existingParamGroup.remove();
}
// Add parameter inputs if command has parameters
const command = commands.find(c => c.name === commandName);
if (command && command.parameters && command.parameters.length > 0) {
const paramGroup = document.createElement('div');
paramGroup.className = 'parameter-group';
command.parameters.forEach(param => {
const paramItem = document.createElement('div');
paramItem.className = 'parameter-item';
const paramLabel = document.createElement('div');
paramLabel.className = 'parameter-label';
paramLabel.textContent = param.name + ':';
const paramInput = document.createElement('input');
paramInput.type = 'text';
paramInput.placeholder = param.default !== undefined ? `Default: ${param.default}` : '';
paramInput.dataset.paramName = param.name;
paramInput.title = param.description;
// Set parameter value
paramInput.addEventListener('change', function() {
if (this.value) {
commandChain[stepIndex].parameters[param.name] = this.value;
} else {
delete commandChain[stepIndex].parameters[param.name];
}
updatePreview();
});
paramItem.appendChild(paramLabel);
paramItem.appendChild(paramInput);
paramGroup.appendChild(paramItem);
});
stepEl.appendChild(paramGroup);
}
updatePreview();
});
const removeBtn = document.createElement('button');
removeBtn.className = 'remove';
removeBtn.textContent = '✕';
removeBtn.title = 'Remove command';
removeBtn.addEventListener('click', () => {
commandChain.splice(stepIndex, 1);
// Update all step indices
const steps = commandChainEl.querySelectorAll('.command-step');
steps.forEach((step, i) => {
step.dataset.index = i;
});
stepEl.remove();
updatePreview();
});
stepEl.appendChild(selectEl);
stepEl.appendChild(removeBtn);
// Add description element (will be populated when command is selected)
const descEl = document.createElement('div');
descEl.className = 'command-description';
stepEl.appendChild(descEl);
commandChainEl.appendChild(stepEl);
}
// Update the description for a specific command
function updateCommandDescription(stepIndex) {
const stepEl = commandChainEl.querySelector(`.command-step[data-index="${stepIndex}"]`);
if (!stepEl) return;
const descEl = stepEl.querySelector('.command-description');
if (!descEl) return;
const commandName = commandChain[stepIndex].name;
const command = commands.find(c => c.name === commandName);
if (command) {
descEl.textContent = command.description;
} else {
descEl.textContent = '';
}
}
// Update all command descriptions
function updateCommandDescriptions() {
commandChain.forEach((_, index) => {
updateCommandDescription(index);
});
}
// Generate preview text
function updatePreview() {
const previewText = generateCommandChainText();
previewTextEl.textContent = previewText || 'No commands added yet';
}
// Generate the command chain text
function generateCommandChainText() {
return commandChain
.filter(cmd => cmd.name)
.map(cmd => {
let commandText = \`/${cmd.name}\`;
// Add parameters if any
const params = Object.entries(cmd.parameters || {});
if (params.length > 0) {
const paramText = params
.map(([key, value]) => \`--\${key}=\${value}\`)
.join(' ');
commandText += ' ' + paramText;
}
return commandText;
})
.join(' ');
}
// Add initial command step
addCommandStep();
</script>
</body>
</html>`;
}
// Get HTML for the documentation webview
function getDocumentationHtml() {
return `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Universal Developer Documentation</title>
<style>
body {
font-family: var(--vscode-font-family);
padding: 20px;
color: var(--vscode-foreground);
background-color: var(--vscode-editor-background);
line-height: 1.5;
}
h1, h2, h3 {
font-weight: 600;
margin-top: 1.5em;
margin-bottom: 0.5em;
}
h1 {
font-size: 2em;
border-bottom: 1px solid var(--vscode-panel-border);
padding-bottom: 0.3em;
}
h2 {
font-size: 1.5em;
}
h3 {
font-size: 1.25em;
}
code {
font-family: var(--vscode-editor-font-family);
background-color: var(--vscode-editor-inactiveSelectionBackground);
padding: 2px 5px;
border-radius: 3px;
}
pre {
background-color: var(--vscode-editor-inactiveSelectionBackground);
padding: 10px;
border-radius: 5px;
overflow: auto;
}
pre code {
background-color: transparent;
padding: 0;
}
table {
border-collapse: collapse;
width: 100%;
margin: 1em 0;
}
th, td {
border: 1px solid var(--vscode-panel-border);
padding: 8px 12px;
text-align: left;
}
th {
background-color: var(--vscode-editor-inactiveSelectionBackground);
}
.command-section {
margin-bottom: 30px;
padding: 15px;
background-color: var(--vscode-editor-selectionHighlightBackground);
border-radius: 5px;
}
.example {
margin: 10px 0;
padding: 10px;
background-color: var(--vscode-input-background);
border-radius: 5px;
}
.tag {
display: inline-block;
padding: 2px 8px;
border-radius: 3px;
font-size: 0.8em;
margin-right: 5px;
}
.tag.compatibility {
background-color: var(--vscode-debugIcon-startForeground);
color: white;
}
.tag.advanced {
background-color: var(--vscode-debugIcon-restartForeground);
color: white;
}
.tag.experimental {
background-color: var(--vscode-debugIcon-pauseForeground);
color: white;
}
</style>
</head>
<body>
<h1>Universal Developer Documentation</h1>
<p>
The Universal Developer extension enables you to control large language model behavior through intuitive symbolic commands.
These commands provide a standardized interface for controlling model reasoning depth, response format, and other behaviors
across all major LLM platforms.
</p>
<h2>Core Symbolic Commands</h2>
<div class="command-section">
<h3><code>/think</code> <span class="tag compatibility">All Providers</span></h3>
<p>Activates extended reasoning pathways, encouraging the model to approach the problem with deeper analysis and step-by-step reasoning.</p>
<div class="example">
<strong>Example:</strong>
<pre><code>/think What are the economic implications of increasing minimum wage?</code></pre>
</div>
<p><strong>When to use:</strong> Complex questions, strategic planning, multi-factor analysis, ethical dilemmas.</p>
</div>
<div class="command-section">
<h3><code>/fast</code> <span class="tag compatibility">All Providers</span></h3>
<p>Optimizes for low-latency, concise responses. Prioritizes brevity and directness over comprehensiveness.</p>
<div class="example">
<strong>Example:</strong>
<pre><code>/fast What's the capital of France?</code></pre>
</div>
<p><strong>When to use:</strong> Simple fact queries, quick summaries, situations where speed is prioritized over depth.</p>
</div>
<div class="command-section">
<h3><code>/loop</code> <span class="tag compatibility">All Providers</span></h3>
<p>Enables iterative refinement cycles, where the model improves its response through multiple revisions.</p>
<div class="example">
<strong>Example:</strong>
<pre><code>/loop --iterations=3 Improve this paragraph: Climate change is a big problem that affects many people and animals.</code></pre>
</div>
<p><strong>Parameters:</strong></p>
<ul>
<li><code>iterations</code>: Number of refinement iterations (default: 3)</li>
</ul>
<p><strong>When to use:</strong> Content refinement, code improvement, iterative problem-solving.</p>
</div>
<div class="command-section">
<h3><code>/reflect</code> <span class="tag compatibility">All Providers</span></h3>
<p>Triggers meta-analysis of outputs, causing the model to critically examine its own response for biases, limitations, and improvements.</p>
<div class="example">
<strong>Example:</strong>
<pre><code>/reflect How might AI impact the future of work?</code></pre>
</div>
<p><strong>When to use:</strong> Critical analysis, identifying biases, ensuring balanced perspectives, philosophical inquiries.</p>
</div>
<div class="command-section">
<h3><code>/fork</code> <span class="tag compatibility">All Providers</span></h3>
<p>Generates multiple alternative responses representing different approaches or perspectives.</p>
<div class="example">
<strong>Example:</strong>
<pre><code>/fork --count=3 What are some approaches to reducing carbon emissions?</code></pre>
</div>
<p><strong>Parameters:</strong></p>
<ul>
<li><code>count</code>: Number of alternatives to generate (default: 2)</li>
</ul>
<p><strong>When to use:</strong> Exploring multiple options, creative brainstorming, presenting diverse perspectives.</p>
</div>
<div class="command-section">
<h3><code>/collapse</code> <span class="tag compatibility">All Providers</span></h3>
<p>Returns to default behavior, disabling any special processing modes.</p>
<div class="example">
<strong>Example:</strong>
<pre><code>/collapse What time is it?</code></pre>
</div>
<p><strong>When to use:</strong> Basic queries, resetting to default behavior, standard responses.</p>
</div>
<h2>Command Chaining</h2>
<p>Commands can be chained together to create complex behaviors. The order of commands matters:</p>
<div class="example">
<strong>Example:</strong>
<pre><code>/think /loop --iterations=2 What strategy should a startup use to enter a competitive market?</code></pre>
<p><em>This will engage deep thinking mode and then apply two refinement iterations to the output.</em></p>
</div>
<div class="example">
<strong>Example:</strong>
<pre><code>/reflect /fork --count=2 What are the ethical implications of AI in healthcare?</code></pre>
<p><em>This will generate two alternative responses, each with critical reflection on limitations and biases.</em></p>
</div>
<h2>Provider Compatibility</h2>
<p>
The Universal Developer extension adapts these symbolic commands to work across different LLM providers,
ensuring consistent behavior regardless of the underlying model API.
</p>
<table>
<tr>
<th>Provider</th>
<th>Supported Models</th>
<th>Implementation Notes</th>
</tr>
<tr>
<td>Anthropic</td>
<td>Claude 3 Opus, Sonnet, Haiku</td>
<td>Native thinking mode support via <code>enable_thinking</code> parameter</td>
</tr>
<tr>
<td>OpenAI</td>
<td>GPT-4, GPT-3.5</td>
<td>System prompt engineering for command emulation</td>
</tr>
<tr>
<td>Qwen</td>
<td>Qwen 3 models</td>
<td>Native thinking mode support via <code>/think</code> and <code>/no_think</code> markers</td>
</tr>
<tr>
<td>Gemini</td>
<td>Gemini Pro, Ultra</td>
<td>System prompt engineering with temperature adjustments</td>
</tr>
<tr>
<td>Local Models</td>
<td>Ollama, LMStudio</td>
<td>Limited support via prompt engineering</td>
</tr>
</table>
<h2>Code Integration</h2>
<div class="example">
<strong>JavaScript/TypeScript:</strong>
<pre><code>import { UniversalLLM } from 'universal-developer';
const llm = new UniversalLLM({
provider: 'anthropic',
apiKey: process.env.ANTHROPIC_API_KEY
});
async function analyze() {
const response = await llm.generate({
prompt: "/think What are the implications of quantum computing for cybersecurity?"
});
console.log(response);
}</code></pre>
</div>
<div class="example">
<strong>Python:</strong>
<pre><code>from universal_developer import UniversalLLM
llm = UniversalLLM(
provider="openai",
api_key=os.environ["OPENAI_API_KEY"]
)
def improve_code():
code = "def factorial(n):\\n result = 0\\n for i in range(1, n+1):\\n result *= i\\n return result"
response = llm.generate(
prompt=f"/loop --iterations=2 Improve this code:\\n```python\\n{code}\\n```"
)
print(response)</code></pre>
</div>
<h2>Custom Commands</h2>
<p>You can register custom symbolic commands to extend functionality:</p>
<div class="example">
<pre><code>llm.registerCommand("debate", {
description: "Generate a balanced debate with arguments for both sides",
parameters: [
{
name: "format",
description: "Format for the debate output",
required: false,
default: "point-counterpoint"
}
],
transform: async (prompt, options) => {
// Custom implementation
}
});</code></pre>
</div>
<h2>Extension Settings</h2>
<p>The Universal Developer extension includes the following settings:</p>
<ul>
<li><code>universal-developer.enableTelemetry</code>: Enable anonymous usage data collection (default: true)</li>
<li><code>universal-developer.defaultProvider</code>: Default provider for command examples</li>
<li><code>universal-developer.showStatusBar</code>: Show status bar item (default: true)</li>
</ul>
<p><em>/reflect This interface creates a new layer of intentionality between developer and model—enabling deeper connection through structured symbolic prompting.</em></p>
</body>
</html>`;
}
// Telemetry function - only collects anonymous usage data if enabled
async function sendAnonymizedTelemetry(event: string, data: Record<string, any> = {}) {
try {
const config = vscode.workspace.getConfiguration('universal-developer');
const telemetryEndpoint = config.get('telemetryEndpoint', 'https://telemetry.universal-developer.org/v1/events');
// Generate anonymous ID if not already cached
const extensionContext = await getContext();
let anonymousId = extensionContext.globalState.get('anonymousId');
if (!anonymousId) {
anonymousId = generateAnonymousId();
extensionContext.globalState.update('anonymousId', anonymousId);
}
// Add metadata to telemetry payload
const payload = {
event,
properties: {
...data,
timestamp: new Date().toISOString(),
extension_version: vscode.extensions.getExtension('universal-developer.vscode')?.packageJSON.version,
vscode_version: vscode.version
},
anonymousId
};
// Send data in non-blocking way
fetch(telemetryEndpoint, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload)
}).catch(() => {
// Silently fail on telemetry errors
});
} catch (error) {
// Never let telemetry errors impact extension functionality
}
}
// Helper function to get extension context
async function getContext(): Promise<vscode.ExtensionContext> {
return new Promise((resolve) => {
vscode.commands.executeCommand('universal-developer.getContext')
.then((context: vscode.ExtensionContext) => resolve(context));
});
}
// Generate anonymous ID for telemetry
function generateAnonymousId(): string {
return Math.random().toString(36).substring(2, 15) +
Math.random().toString(36).substring(2, 15);
}
// Symbolic commands data
const SYMBOLIC_COMMANDS: SymbolicCommand[] = [
{
name: 'think',
description: 'Activate extended reasoning pathways',
examples: [
'/think What are the implications of quantum computing for cybersecurity?',
'/think Analyze the economic impact of increasing minimum wage.'
],
provider: {
claude: true,
openai: true,
qwen: true,
gemini: true,
ollama: true
}
},
{
name: 'fast',
description: 'Optimize for low-latency responses',
examples: [
'/fast What\'s the capital of France?',
'/fast Summarize the key points of this article.'
],
provider: {
claude: true,
openai: true,
qwen: true,
gemini: true,
ollama: true
}
},
{
name: 'loop',
description: 'Enable iterative refinement cycles',
parameters: [
{
name: 'iterations',
description: 'Number of refinement iterations',
required: false,
default: 3
}
],
examples: [
'/loop Improve this code snippet: function add(a, b) { return a + b }',
'/loop --iterations=5 Refine this paragraph until it\'s clear and concise.'
],
provider: {
claude: true,
openai: true,
qwen: true,
gemini: true,
ollama: true
}
},
{
name: 'reflect',
description: 'Trigger meta-analysis of outputs',
examples: [
'/reflect How might AI impact the future of work?',
'/reflect What are the ethical implications of genetic engineering?'
],
provider: {
claude: true,
openai: true,
qwen: true,
gemini: true,
ollama: true
}
},
{
name: 'collapse',
description: 'Return to default behavior',
examples: [
'/collapse What time is it?',
'/collapse Tell me about the history of Rome.'
],
provider: {
claude: true,
openai: true,
qwen: true,
gemini: true,
ollama: true
}
},
{
name: 'fork',
description: 'Generate multiple alternative responses',
parameters: [
{
name: 'count',
description: 'Number of alternatives to generate',
required: false,
default: 2
}
],
examples: [
'/fork --count=3 What are some approaches to reducing carbon emissions?',
'/fork Generate two different marketing slogans
{
"name": "universal-developer",
"displayName": "Universal Developer - Symbolic Runtime Controls",
"description": "Control LLM behavior through symbolic runtime commands across all major AI platforms",
"version": "0.1.0",
"engines": {
"vscode": "^1.60.0"
},
"publisher": "universal-developer",
"categories": [
"Programming Languages",
"Snippets",
"Other"
],
"keywords": [
"ai",
"llm",
"claude",
"gpt",
"qwen",
"gemini",
"prompt engineering",
"symbolic commands"
],
"icon": "images/icon.png",
"galleryBanner": {
"color": "#24292e",
"theme": "dark"
},
"activationEvents": [
"onLanguage:javascript",
"onLanguage:typescript",
"onLanguage:python",
"onLanguage:markdown",
"onLanguage:plaintext"
],
"main": "./out/extension.js",
"contributes": {
"commands": [
{
"command": "universal-developer.insertSymbolicCommand",
"title": "Universal Developer: Insert Symbolic Command"
},
{
"command": "universal-developer.buildSymbolicChain",
"title": "Universal Developer: Build Symbolic Command Chain"
},
{
"command": "universal-developer.showDocumentation",
"title": "Universal Developer: Open Documentation"
},
{
"command": "universal-developer.getContext",
"title": "Universal Developer: Get Extension Context"
}
],
"keybindings": [
{
"command": "universal-developer.insertSymbolicCommand",
"key": "ctrl+shift+/",
"mac": "cmd+shift+/",
"when": "editorTextFocus"
},
{
"command": "universal-developer.buildSymbolicChain",
"key": "ctrl+shift+.",
"mac": "cmd+shift+.",
"when": "editorTextFocus"
}
],
"menus": {
"editor/context": [
{
"command": "universal-developer.insertSymbolicCommand",
"group": "universal-developer",
"when": "editorTextFocus"
},
{
"command": "universal-developer.buildSymbolicChain",
"group": "universal-developer",
"when": "editorTextFocus"
}
]
},
"configuration": {
"title": "Universal Developer",
"properties": {
"universal-developer.enableTelemetry": {
"type": "boolean",
"default": true,
"description": "Enable anonymous usage data collection to improve the extension"
},
"universal-developer.defaultProvider": {
"type": "string",
"enum": [
"anthropic",
"openai",
"qwen",
"gemini",
"ollama"
],
"default": "anthropic",
"description": "Default LLM provider for command examples"
},
"universal-developer.showStatusBar": {
"type": "boolean",
"default": true,
"description": "Show Universal Developer status bar item"
},
"universal-developer.telemetryEndpoint": {
"type": "string",
"default": "https://telemetry.universal-developer.org/v1/events",
"description": "Endpoint for telemetry data collection"
}
}
},
"snippets": [
{
"language": "javascript",
"path": "./snippets/javascript.json"
},
{
"language": "typescript",
"path": "./snippets/typescript.json"
},
{
"language": "python",
"path": "./snippets/python.json"
}
]
},
"scripts": {
"vscode:prepublish": "npm run compile",
"compile": "tsc -p ./",
"watch": "tsc -watch -p ./",
"pretest": "npm run compile && npm run lint",
"lint": "eslint src --ext ts",
"test": "node ./out/test/runTest.js",
"package": "vsce package"
},
"devDependencies": {
"@types/glob": "^7.1.3",
"@types/mocha": "^8.2.2",
"@types/node": "^14.14.37",
"@types/vscode": "^1.60.0",
"@typescript-eslint/eslint-plugin": "^4.21.0",
"@typescript-eslint/parser": "^4.21.0",
"eslint": "^7.24.0",
"glob": "^7.1.7",
"mocha": "^8.3.2",
"typescript": "^4.2.4",
"vscode-test": "^1.5.2",
"vsce": "^2.7.0"
},
"dependencies": {
"node-fetch": "^2.6.7"
},
"repository": {
"type": "git",
"url": "https://github.com/universal-developer/vscode-extension.git"
},
"homepage": "https://github.com/universal-developer/vscode-extension",
"bugs": {
"url": "https://github.com/universal-developer/vscode-extension/issues"
},
"license": "MIT"
}
|