p-doom/crowd-code-dataset-0.2 huggingface dataset:
[content] src/extension.ts (typescript)
// -------------------- UI State & Helpers --------------------
const UI_CONTEXT_KEY = 'crowdPilot.uiVisible';
let uiPanel: vscode.WebviewPanel | undefined;

function showPreviewUI(): void {
	if (uiPanel) {
		try {
			uiPanel.reveal(undefined, true /* preserveFocus */);
		} catch {}
		return;
	}
	uiPanel = vscode.window.createWebviewPanel(
		'crowdPilotPreview',
		'Crowd Pilot Preview',
		{ viewColumn: vscode.ViewColumn.Beside, preserveFocus: true },
		{ enableScripts: true, retainContextWhenHidden: true }
	);
	uiPanel.webview.html = getPreviewHtml();
	vscode.commands.executeCommand('setContext', UI_CONTEXT_KEY, true);
	uiPanel.onDidDispose(() => {
		uiPanel = undefined;
		vscode.commands.executeCommand('setContext', UI_CONTEXT_KEY, false);
	});

	// Allow Escape within the webview to close it
	uiPanel.webview.onDidReceiveMessage((msg) => {
		if (msg?.type === 'escape') {
			hidePreviewUI();
		}
	});
}

function hidePreviewUI(): void {
	if (!uiPanel) {
		vscode.commands.executeCommand('setContext', UI_CONTEXT_KEY, false);
		return;
	}
	try { uiPanel.dispose(); } catch {}
	uiPanel = undefined;
	vscode.commands.executeCommand('setContext', UI_CONTEXT_KEY, false);
}

function getPreviewHtml(): string {
	const styles = `
		body { font-family: var(--vscode-font-family); color: var(--vscode-foreground); background: var(--vscode-editor-background); margin: 0; }
		.container { padding: 16px; }
		h1 { font-size: 16px; margin: 0 0 8px; }
		p { margin: 0 0 12px; }
		ul { margin: 0 0 12px 18px; }
		.code { font-family: var(--vscode-editor-font-family); background: var(--vscode-editor-inactiveSelectionBackground); padding: 2px 4px; border-radius: 3px; }
		.hint { opacity: 0.8; }
	`;
	const script = `
		const vscode = acquireVsCodeApi();
		window.addEventListener('keydown', (e) => {
			if (e.key === 'Escape') {
				vscode.postMessage({ type: 'escape' });
			}
		});
	`;
	return `<!DOCTYPE html>
	<html lang="en">
	<head>
		<meta charset="UTF-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<title>Crowd Pilot Preview</title>
		<style>${styles}</style>
	</head>
	<body>
		<div class="container">
			<h1>Upcoming actions</h1>
			<p>This step will perform the following changes:</p>
			<ul>
				<li>Focus the active text document</li>
				<li>Edit the document by inserting <span class="code">hello world</span> at the top</li>
				<li>Focus the terminal</li>
				<li>Run <span class="code">echo VSCode test</span> in the terminal</li>
			</ul>
			<p class="hint">Press <span class="code">Tab</span> again to run, or <span class="code">Esc</span> to hide.</p>
		</div>
		<script>${script}</script>
	</body>
	</html>`;
}
[content] src/extension.ts (typescript)
		const plan = buildTestRunPlan(editor, doc, term);

		// If preview UI is not open, show it first and return. Next Tab will execute actions.
		if (!uiPanel) {
			showPreviewUI(plan);
			return;
		}

		// Close preview UI before executing actions
		hidePreviewUI();

		await executePlan(plan);
[content] src/extension.ts (typescript)
		const git = vscode.extensions.getExtension('vscode.git')?.exports?.getAPI(1);
		const repo = git?.repositories?.[0];
	
		await vscode.window.showTextDocument(doc);
		editor!.selections = [new vscode.Selection(0, 0, 0, 0)];
		await editor!.edit(e => e.insert(new vscode.Position(0, 0), 'hello world
'));
		term.show();
		term.sendText('echo VSCode test');
		//await repo?.pull();
[tab] package.json (json)
{
  "name": "crowd-pilot",
  "displayName": "crowd-pilot-extension",
  "description": "Teaching language models to code like humans.",
  "version": "0.0.1",
  "engines": {
    "vscode": "^1.99.3"
  },
  "categories": [
    "Other"
  ],
  "activationEvents": [
    "onStartupFinished"
  ],
  "main": "./out/extension.js",
  "contributes": {
    "commands": [
      {
        "command": "crowd-pilot.testRun",
        "title": "Test Run"
      },
      {
        "command": "crowd-pilot.hideUi",
        "title": "Crowd Pilot: Hide Preview"
      }
    ],
    "keybindings": [
      {
        "command": "crowd-pilot.testRun",
        "key": "tab",
        "mac": "tab",
        "when": "editorTextFocus || terminalFocus"
      },
      {
        "command": "crowd-pilot.hideUi",
        "key": "escape",
        "mac": "escape",
        "when": "crowdPilot.uiVisible"
      }
    ]
  },
  "scripts": {
    "vscode:prepublish": "npm run compile",
    "compile": "tsc -p ./",
    "watch": "tsc -watch -p ./",
    "pretest": "npm run compile && npm run lint",
    "lint": "eslint src",
    "test": "vscode-test"
  },
  "devDependencies": {
    "@types/vscode": "^1.105.0",
    "@types/mocha": "^10.0.10",
    "@types/node": "22.x",
    "@typescript-eslint/eslint-plugin": "^8.45.0",
    "@typescript-eslint/parser": "^8.45.0",
    "eslint": "^9.36.0",
    "typescript": "^5.9.3",
    "@vscode/test-cli": "^0.0.11",
    "@vscode/test-electron": "^2.5.2"
  }
}
[content] src/extension.ts (typescript)
}).join('');
return `<!DOCTYPE html>
	<html>
	<head>
		<meta charset="UTF-8" />
		<style>
		body{font-family:var(--vscode-font-family);color:var(--vscode-foreground);background:var(--vscode-editor-background);margin:0}
		.container{padding:12px}
		h1{font-size:14px;margin:0 0 8px}
		p{margin:0 0 8px}
		ul{margin:0 0 8px 18px}
		code{font-family:var(--vscode-editor-font-family);background:var(--vscode-editor-inactiveSelectionBackground);padding:1px 3px;border-radius:3px}
		.hint{opacity:.8}
		</style>
	</head>
	<body>
		<div class="container">
			<h1>Upcoming actions</h1>
			<p>This step will perform the following changes:</p>
			<ul>${items}</ul>
			<p class="hint">Press <code>Tab</code> again to run, or <code>Esc</code> to hide.</p>
		</div>
	</body>
	</html>`;
[content] src/extension.ts (typescript)
function getPreviewHtml(plan: PlannedAction[]): string {
const items = plan.map(action => {
	switch (action.kind) {
		case 'showTextDocument':
			return '<li>Focus the active text document</li>';
		case 'setSelections':
			return '<li>Move cursor to requested selection(s)</li>';
		case 'editInsert':
			return `<li>Insert <code>${escapeHtml(action.text)}</code> at (${action.position[0]}, ${action.position[1]})</li>`;
		case 'terminalShow':
			return '<li>Focus the terminal</li>';
		case 'terminalSendText':
			return `<li>Run <code>${escapeHtml(action.text)}</code> in the terminal</li>`;
		default:
			return '';
[content] src/extension.ts (typescript)
	uiPanel = vscode.window.createWebviewPanel(
		'crowdPilotPreview',
		'Crowd Pilot Preview',
		{ viewColumn: vscode.ViewColumn.Beside, preserveFocus: true },
		{ enableScripts: false, retainContextWhenHidden: false }
	);
	uiPanel.webview.html = getPreviewHtml(plan);
[content] src/extension.ts (typescript)
	const items: vscode.QuickPickItem[] = plan.map(action => {
		switch (action.kind) {
			case 'showTextDocument':
				return { label: '$(file) Focus active text document' };
			case 'setSelections':
				return { label: '$(cursor) Move cursor to selection(s)' };
			case 'editInsert':
				return { label: `$(pencil) Insert "${action.text.replace(/
/g, '\
')}" at (${action.position[0]}, ${action.position[1]})` };
			case 'terminalShow':
				return { label: '$(terminal) Focus terminal' };
			case 'terminalSendText':
				return { label: `$(terminal) Run "${action.text}" in terminal` };
		}
	});
	if (!previewQuickPick) {
		previewQuickPick = vscode.window.createQuickPick();
		previewQuickPick.title = 'Crowd Pilot Preview';
		previewQuickPick.matchOnDetail = true;
		previewQuickPick.ignoreFocusOut = true;
		previewQuickPick.canSelectMany = false;
		previewQuickPick.onDidAccept(async () => {
			const qp = previewQuickPick!;
			qp.hide();
			await executePlan(plan);
			vscode.window.showInformationMessage('All actions emitted');
		});
		previewQuickPick.onDidHide(() => {
			previewVisible = false;
			vscode.commands.executeCommand('setContext', UI_CONTEXT_KEY, false);
			try { previewQuickPick?.dispose(); } catch {}
			previewQuickPick = undefined;
		});
	}
	previewQuickPick.items = items;
	previewQuickPick.placeholder = 'Press Enter to run, or Esc to hide';
	previewQuickPick.show();
	previewVisible = true;
	vscode.commands.executeCommand('setContext', UI_CONTEXT_KEY, true);
[content] src/extension.ts (typescript)
function getPreviewHtml(plan: PlannedAction[]): string {
const items = plan.map(action => {
	switch (action.kind) {
		case 'showTextDocument':
			return '<li>Focus the active text document</li>';
		case 'setSelections':
			return '<li>Move cursor to requested selection(s)</li>';
		case 'editInsert':
			return `<li>Insert <code>${escapeHtml(action.text)}</code> at (${action.position[0]}, ${action.position[1]})</li>`;
		case 'terminalShow':
			return '<li>Focus the terminal</li>';
		case 'terminalSendText':
			return `<li>Run <code>${escapeHtml(action.text)}</code> in the terminal</li>`;
		default:
			return '';
	}
}).join('');
return `<!DOCTYPE html>
	<html>
	<head>
		<meta charset="UTF-8" />
		<style>
		body{font-family:var(--vscode-font-family);color:var(--vscode-foreground);background:var(--vscode-editor-background);margin:0}
		.container{padding:12px}
		h1{font-size:14px;margin:0 0 8px}
		p{margin:0 0 8px}
		ul{margin:0 0 8px 18px}
		code{font-family:var(--vscode-editor-font-family);background:var(--vscode-editor-inactiveSelectionBackground);padding:1px 3px;border-radius:3px}
		.hint{opacity:.8}
		</style>
	</head>
	<body>
		<div class="container">
			<h1>Upcoming actions</h1>
			<p>This step will perform the following changes:</p>
			<ul>${items}</ul>
			<p class="hint">Press <code>Tab</code> again to run, or <code>Esc</code> to hide.</p>
		</div>
	</body>
	</html>`;
}

function escapeHtml(text: string): string {
	return text
		.replace(/&/g, '&amp;')
		.replace(/</g, '&lt;')
		.replace(/>/g, '&gt;')
		.replace(/\"/g, '&quot;')
		.replace(/'/g, '&#39;');
}
[content] src/extension.ts (typescript)
	if (uiPanel) {
		try {
			uiPanel.reveal(undefined, true /* preserveFocus */);
		} catch {}
		uiPanel.webview.html = getPreviewHtml(plan);
		return;
	}
	uiPanel = vscode.window.createWebviewPanel(
		'crowdPilotPreview',
		'Crowd Pilot Preview',
		{ viewColumn: vscode.ViewColumn.Beside, preserveFocus: true },
		{ enableScripts: false, retainContextWhenHidden: false }
	);
	uiPanel.webview.html = getPreviewHtml(plan);
	vscode.commands.executeCommand('setContext', UI_CONTEXT_KEY, true);
	uiPanel.onDidDispose(() => {
		uiPanel = undefined;
		vscode.commands.executeCommand('setContext', UI_CONTEXT_KEY, false);
	});
}
[content] src/extension.ts (typescript)
	const items: vscode.QuickPickItem[] = plan.map(action => {
		switch (action.kind) {
			case 'showTextDocument':
				return { label: '$(file) Focus active text document' };
			case 'setSelections':
				return { label: '$(cursor) Move cursor to selection(s)' };
			case 'editInsert':
				return { label: `$(pencil) Insert "${action.text.replace(/
/g, '\
')}" at (${action.position[0]}, ${action.position[1]})` };
			case 'terminalShow':
				return { label: '$(terminal) Focus terminal' };
			case 'terminalSendText':
				return { label: `$(terminal) Run "${action.text}" in terminal` };
		}
	});
	if (!previewQuickPick) {
		previewQuickPick = vscode.window.createQuickPick();
		previewQuickPick.title = 'Crowd Pilot Preview';
		previewQuickPick.matchOnDetail = true;
		previewQuickPick.ignoreFocusOut = true;
		previewQuickPick.canSelectMany = false;
		previewQuickPick.onDidAccept(async () => {
			const qp = previewQuickPick!;
			qp.hide();
			await executePlan(plan);
			vscode.window.showInformationMessage('All actions emitted');
		});
		previewQuickPick.onDidHide(() => {
			previewVisible = false;
			vscode.commands.executeCommand('setContext', UI_CONTEXT_KEY, false);
			try { previewQuickPick?.dispose(); } catch {}
			previewQuickPick = undefined;
		});
	}
	previewQuickPick.items = items;
	previewQuickPick.placeholder = 'Press Enter to run, or Esc to hide';
	previewQuickPick.show();
	previewVisible = true;
	vscode.commands.executeCommand('setContext', UI_CONTEXT_KEY, true);
	currentPlan = plan;
[content] src/extension.ts (typescript)
        previewQuickPick.onDidAccept(async () => {
            const qp = previewQuickPick!;
            const selected = qp.selectedItems?.[0];
            qp.hide();
            if (selected) {
                await executePlan([plan[selected.index]]);
                vscode.window.showInformationMessage('Action executed');
            }
        });
[content] src/extension.ts (typescript)
const items: (vscode.QuickPickItem & { index: number })[] = plan.map((action, index) => {
    switch (action.kind) {
        case 'showTextDocument':
            return { index, label: '$(file) Focus active text document' };
        case 'setSelections':
            return { index, label: '$(cursor) Move cursor to selection(s)' };
        case 'editInsert':
            return { index, label: `$(pencil) Insert "${action.text.replace(/
/g, '\
')}" at (${action.position[0]}, ${action.position[1]})` };
        case 'terminalShow':
            return { index, label: '$(terminal) Focus terminal' };
        case 'terminalSendText':
            return { index, label: `$(terminal) Run "${action.text}" in terminal` };
    }
});
    if (!previewQuickPick) {
        previewQuickPick = vscode.window.createQuickPick<(vscode.QuickPickItem & { index: number })>();
[content] src/extension.ts (typescript)
	const items: vscode.QuickPickItem[] = plan.map(action => {
		switch (action.kind) {
			case 'showTextDocument':
				return { label: '$(file) Focus active text document' };
			case 'setSelections':
				return { label: '$(cursor) Move cursor to selection(s)' };
			case 'editInsert':
				return { label: `$(pencil) Insert "${action.text.replace(/
/g, '\
')}" at (${action.position[0]}, ${action.position[1]})` };
			case 'terminalShow':
				return { label: '$(terminal) Focus terminal' };
			case 'terminalSendText':
				return { label: `$(terminal) Run "${action.text}" in terminal` };
		}
	});
	if (!previewQuickPick) {
		previewQuickPick = vscode.window.createQuickPick();
[tab] package.json (json)
{
  "name": "crowd-pilot",
  "displayName": "crowd-pilot-extension",
  "description": "Teaching language models to code like humans.",
  "version": "0.0.1",
  "engines": {
    "vscode": "^1.99.3"
  },
  "categories": [
    "Other"
  ],
  "activationEvents": [
    "onStartupFinished"
  ],
  "main": "./out/extension.js",
  "contributes": {
    "commands": [
      {
        "command": "crowd-pilot.testRun",
        "title": "Test Run"
      },
      {
        "command": "crowd-pilot.hideUi",
        "title": "Crowd Pilot: Hide Preview"
      }
    ],
    "keybindings": [
      {
        "command": "crowd-pilot.testRun",
        "key": "tab",
        "mac": "tab",
        "when": "editorTextFocus || terminalFocus"
      },
      {
        "command": "crowd-pilot.testRun",
        "key": "tab",
        "mac": "tab",
        "when": "inQuickOpen && crowdPilot.uiVisible"
      },
      {
        "command": "crowd-pilot.hideUi",
        "key": "escape",
        "mac": "escape",
        "when": "crowdPilot.uiVisible"
      }
    ]
  },
  "scripts": {
    "vscode:prepublish": "npm run compile",
    "compile": "tsc -p ./",
    "watch": "tsc -watch -p ./",
    "pretest": "npm run compile && npm run lint",
    "lint": "eslint src",
    "test": "vscode-test"
  },
  "devDependencies": {
    "@types/vscode": "^1.105.0",
    "@types/mocha": "^10.0.10",
    "@types/node": "22.x",
    "@typescript-eslint/eslint-plugin": "^8.45.0",
    "@typescript-eslint/parser": "^8.45.0",
    "eslint": "^9.36.0",
    "typescript": "^5.9.3",
    "@vscode/test-cli": "^0.0.11",
    "@vscode/test-electron": "^2.5.2"
  }
}
[tab] src/extension.ts (typescript)
import * as vscode from 'vscode';

export function activate(context: vscode.ExtensionContext) {

	console.log('[Crowd Pilot] Extension activated');

	// Configure terminal to allow tab keybinding to work
	(async () => {
		const config = vscode.workspace.getConfiguration('terminal.integrated');
		const commandsToSkipShell = config.get<string[]>('commandsToSkipShell', []);
		if (!commandsToSkipShell.includes('crowd-pilot.testRun')) {
			commandsToSkipShell.push('crowd-pilot.testRun');
			await config.update('commandsToSkipShell', commandsToSkipShell, vscode.ConfigurationTarget.Global);
		}
		// Prime terminal subsystem after intercept is enabled (NOTE: this is a workaround)
		await primeTerminalSubsystem();
	})().catch((err) => console.error('[Crowd Pilot] Startup initialization error:', err));

	const testRun = vscode.commands.registerCommand('crowd-pilot.testRun', async () => {
		const editor = vscode.window.activeTextEditor;
		const doc = editor!.document;
		const term = vscode.window.terminals[0] ?? vscode.window.createTerminal('Test');
		const git = vscode.extensions.getExtension('vscode.git')?.exports?.getAPI(1);
		const repo = git?.repositories?.[0];
	
		await vscode.window.showTextDocument(doc);
		editor!.selections = [new vscode.Selection(0, 0, 0, 0)];
		await editor!.edit(e => e.insert(new vscode.Position(0, 0), 'hello world
'));
		term.show();
		term.sendText('echo VSCode test');
		//await repo?.pull();
	
		vscode.window.showInformationMessage('All actions emitted');
	  });

	context.subscriptions.push(testRun);
}

export function deactivate() {}

async function primeTerminalSubsystem(): Promise<void> {
	try {
		if (vscode.window.terminals.length > 0) {
			return;
		}
		const opened = new Promise<void>((resolve) => {
			const d = vscode.window.onDidOpenTerminal(() => {
				try { d.dispose(); } catch {}
				resolve();
			});
		});
		const t = vscode.window.createTerminal('Crowd Pilot Prime');
		await Promise.race([
			opened,
			new Promise<void>(r => setTimeout(r, 150))
		]);
		try { t.dispose(); } catch {}
		await new Promise<void>(r => setTimeout(r, 50));
		console.log('[Crowd Pilot] Primed terminal subsystem');
	} catch (err) {
		console.error('[Crowd Pilot] Failed to prime terminal subsystem:', err);
	}
}
[content] src/extension.ts (typescript)
// -------------------- SGLang Client (simple test) --------------------
async function callSGLangChat(port: number): Promise<void> {
	const url = `http://localhost:${port}/v1/chat/completions`;
	const requestBody = {
		model: 'qwen/qwen2.5-0.5b-instruct',
		messages: [
			{ role: 'user', content: 'What is the capital of France?' }
		]
	};
	try {
		const response = await fetch(url, {
			method: 'POST',
			headers: { 'Content-Type': 'application/json' },
			body: JSON.stringify(requestBody)
		});
		const json = await response.json();
		console.log('[crowd-pilot][sglang] Response:', JSON.stringify(json, null, 2));
		vscode.window.showInformationMessage('SGLang response received (see console).');
	} catch (err) {
		console.error('[crowd-pilot][sglang] Request failed:', err);
		vscode.window.showErrorMessage('SGLang request failed. See console for details.');
	}
}
[content] src/extension.ts (typescript)
	const sglangTest = vscode.commands.registerCommand('crowd-pilot.sglangTest', async () => {
		try {
			const portInput = await vscode.window.showInputBox({
				prompt: 'Enter SGLang server port',
				value: '30000'
			});
			if (!portInput) {
				return;
			}
			const port = Number(portInput);
			if (!Number.isFinite(port) || port <= 0) {
				vscode.window.showErrorMessage('Invalid port');
				return;
			}
			await callSGLangChat(port);
		} catch (err) {
			console.error('[crowd-pilot] SGLang test command failed:', err);
			vscode.window.showErrorMessage('SGLang test failed. See console for details.');
		}
	});

	context.subscriptions.push(testRun, hideUi, sglangTest);
[content] src/extension.ts (typescript)
// -------------------- SGLang Client (simple test) --------------------
async function callSGLangChat(port: number): Promise<void> {
	const url = `http://localhost:${port}/v1/chat/completions`;
	const requestBody = {
		model: 'qwen/qwen2.5-0.5b-instruct',
		messages: [
			{ role: 'user', content: 'What is the capital of France?' }
		]
	};
	try {
		const response = await fetch(url, {
			method: 'POST',
			headers: { 'Content-Type': 'application/json' },
			body: JSON.stringify(requestBody)
		});
		const json = await response.json();
		vscode.window.showInformationMessage(`SGLang response: ${JSON.stringify(json, null, 2)}`);
	} catch (err) {
		const errorMessage = err instanceof Error ? err.message : String(err);
		vscode.window.showErrorMessage(`SGLang request failed: ${errorMessage}`);
	}
}
[content] src/extension.ts (typescript)
	const sglangTest = vscode.commands.registerCommand('crowd-pilot.sglangTest', async () => {
		try {
			const portInput = await vscode.window.showInputBox({
				prompt: 'Enter SGLang server port',
				value: '30000'
			});
			if (!portInput) {
				return;
			}
			const port = Number(portInput);
			if (!Number.isFinite(port) || port <= 0) {
				vscode.window.showErrorMessage('Invalid port');
				return;
			}
			await callSGLangChat(port);
		} catch (err) {
			const errorMessage = err instanceof Error ? err.message : String(err);
			vscode.window.showErrorMessage(`SGLang test failed: ${errorMessage}`);
		}
	});

	context.subscriptions.push(testRun, hideUi, sglangTest);
[content] src/extension.ts (typescript)
// -------------------- SGLang Client (simple test) --------------------
async function callSGLangChat(port: number): Promise<void> {
	const requestBody = {
		model: 'qwen/qwen2.5-0.5b-instruct',
		messages: [
			{ role: 'user', content: 'What is the capital of France?' }
		]
	};
	const postData = JSON.stringify(requestBody);

	const options = {
		hostname: 'localhost',
		port: port,
		path: '/v1/chat/completions',
		method: 'POST',
		headers: {
			'Content-Type': 'application/json',
			'Content-Length': Buffer.byteLength(postData)
		}
	};

	try {
		const json = await new Promise<any>((resolve, reject) => {
			const req = http.request(options, (res) => {
				let data = '';
				res.on('data', (chunk) => {
					data += chunk;
				});
				res.on('end', () => {
					try {
						resolve(JSON.parse(data));
					} catch (err) {
						reject(new Error(`Failed to parse response: ${err instanceof Error ? err.message : String(err)}`));
					}
				});
			});

			req.on('error', (err) => {
				reject(err);
			});

			req.write(postData);
			req.end();
		});

		vscode.window.showInformationMessage(`SGLang response: ${JSON.stringify(json, null, 2)}`);
	} catch (err) {
		const errorMessage = err instanceof Error ? err.message : String(err);
		vscode.window.showErrorMessage(`SGLang request failed: ${errorMessage}`);
	}
}
[content] src/extension.ts (typescript)
// -------------------- SGLang Client (simple test) --------------------
async function callSGLangChat(port: number): Promise<void> {
	const requestBody = {
		model: 'qwen/qwen2.5-0.5b-instruct',
		messages: [
			{ role: 'user', content: 'What is the capital of France?' }
		]
	};
	const postData = JSON.stringify(requestBody);

	const options = {
		hostname: 'localhost',
		port: port,
		path: '/v1/chat/completions',
		method: 'POST',
		headers: {
			'Content-Type': 'application/json',
			'Content-Length': Buffer.byteLength(postData)
		}
	};

	try {
		const json = await new Promise<any>((resolve, reject) => {
			const req = http.request(options, (res: http.IncomingMessage) => {
				let data = '';
				res.on('data', (chunk: Buffer) => {
					data += chunk.toString();
				});
				res.on('end', () => {
					try {
						resolve(JSON.parse(data));
					} catch (err) {
						reject(new Error(`Failed to parse response: ${err instanceof Error ? err.message : String(err)}`));
					}
				});
			});

			req.on('error', (err: Error) => {
				reject(err);
			});

			req.write(postData);
			req.end();
		});

		vscode.window.showInformationMessage(`SGLang response: ${JSON.stringify(json, null, 2)}`);
	} catch (err) {
		const errorMessage = err instanceof Error ? err.message : String(err);
		vscode.window.showErrorMessage(`SGLang request failed: ${errorMessage}`);
	}
}
[tab] tsconfig.json (jsonc)
{
	"compilerOptions": {
		"module": "Node16",
		"target": "ES2022",
		"outDir": "out",
		"lib": [
			"ES2022"
		],
		"types": [
			"node",
			"vscode"
		],
		"skipLibCheck": true,
		"sourceMap": true,
		"rootDir": "src",
		"strict": true,   /* enable all strict type-checking options */
		/* Additional Checks */
		// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
		// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
		// "noUnusedParameters": true,  /* Report errors on unused parameters. */
	}
}
[tab] package.json (json)
{
  "name": "crowd-pilot",
  "displayName": "crowd-pilot-extension",
  "description": "Teaching language models to code like humans.",
  "publisher": "p(doom)",
  "version": "0.0.1",
  "engines": {
    "vscode": "^1.99.3"
  },
  "categories": [
    "Other"
  ],
  "activationEvents": [
    "onStartupFinished"
  ],
  "main": "./out/extension.js",
  "contributes": {
    "commands": [
      {
        "command": "crowd-pilot.testRun",
        "title": "Test Run"
      },
      {
        "command": "crowd-pilot.hideUi",
        "title": "Crowd Pilot: Hide Preview"
      },
      {
        "command": "crowd-pilot.sglangTest",
        "title": "Crowd Pilot: Test SGLang"
      }
    ],
    "keybindings": [
      {
        "command": "crowd-pilot.testRun",
        "key": "tab",
        "mac": "tab",
        "when": "editorTextFocus || terminalFocus"
      },
      {
        "command": "crowd-pilot.testRun",
        "key": "tab",
        "mac": "tab",
        "when": "inQuickOpen && crowdPilot.uiVisible"
      },
      {
        "command": "crowd-pilot.hideUi",
        "key": "escape",
        "mac": "escape",
        "when": "crowdPilot.uiVisible"
      }
    ]
  },
  "scripts": {
    "vscode:prepublish": "npm run compile",
    "compile": "tsc -p ./",
    "watch": "tsc -watch -p ./",
    "pretest": "npm run compile && npm run lint",
    "lint": "eslint src",
    "test": "vscode-test"
  },
  "devDependencies": {
    "@types/vscode": "^1.105.0",
    "@types/mocha": "^10.0.10",
    "@types/node": "22.x",
    "@typescript-eslint/eslint-plugin": "^8.45.0",
    "@typescript-eslint/parser": "^8.45.0",
    "eslint": "^9.36.0",
    "typescript": "^5.9.3",
    "@vscode/test-cli": "^0.0.11",
    "@vscode/test-electron": "^2.5.2"
  }
}