[tab] src/extension.ts (typescript)
// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
import * as vscode from 'vscode';

// This method is called when your extension is activated
// Your extension is activated the very first time the command is executed
export function activate(context: vscode.ExtensionContext) {

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

	// Read current configuration for diagnostics only (no automatic writes)
	const config = vscode.workspace.getConfiguration('terminal.integrated');
	const commandsToSkipShell = config.get<string[]>('commandsToSkipShell', []);
	console.log('[Crowd Pilot] Current commandsToSkipShell:', JSON.stringify(commandsToSkipShell));

	const testRun = vscode.commands.registerCommand('crowd-pilot.testRun', async () => {
		// Log context information
		const activeEditor = vscode.window.activeTextEditor;
		const activeTerminal = vscode.window.activeTerminal;
		const contextInfo = {
			hasActiveEditor: !!activeEditor,
			hasActiveTerminal: !!activeTerminal,
			activeTerminalName: activeTerminal?.name,
			terminalCount: vscode.window.terminals.length,
		};
		console.log('[Crowd Pilot] testRun command executed', JSON.stringify(contextInfo));
		
		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];
	
		// Emit a few actions:
		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');
	  });

	// Command: Enable terminal interception for Tab
	const enableIntercept = vscode.commands.registerCommand('crowd-pilot.enableTerminalIntercept', async () => {
		const cfg = vscode.workspace.getConfiguration('terminal.integrated');
		const list = cfg.get<string[]>('commandsToSkipShell', []) ?? [];
		if (!list.includes('crowd-pilot.testRun')) {
			await cfg.update('commandsToSkipShell', [...list, 'crowd-pilot.testRun'], vscode.ConfigurationTarget.Global, false);
			console.log('[Crowd Pilot] Enabled terminal intercept for crowd-pilot.testRun');
			vscode.window.showInformationMessage('Enabled terminal intercept for crowd-pilot.testRun');
		} else {
			vscode.window.showInformationMessage('Terminal intercept already enabled for crowd-pilot.testRun');
		}
	});

	// Command: Disable terminal interception for Tab
	const disableIntercept = vscode.commands.registerCommand('crowd-pilot.disableTerminalIntercept', async () => {
		const cfg = vscode.workspace.getConfiguration('terminal.integrated');
		const list = cfg.get<string[]>('commandsToSkipShell', []) ?? [];
		if (list.includes('crowd-pilot.testRun')) {
			const updated = list.filter(c => c !== 'crowd-pilot.testRun');
			await cfg.update('commandsToSkipShell', updated, vscode.ConfigurationTarget.Global, false);
			console.log('[Crowd Pilot] Disabled terminal intercept for crowd-pilot.testRun');
			vscode.window.showInformationMessage('Disabled terminal intercept for crowd-pilot.testRun');
		} else {
			vscode.window.showInformationMessage('Terminal intercept not enabled for crowd-pilot.testRun');
		}
	});

	// Diagnostic command to check keybinding configuration and context
	const checkConfig = vscode.commands.registerCommand('crowd-pilot.checkConfig', () => {
		const config = vscode.workspace.getConfiguration('terminal.integrated');
		const commandsToSkipShell = config.get<string[]>('commandsToSkipShell', []);
		const hasCommand = commandsToSkipShell.includes('crowd-pilot.testRun');
		
		const activeEditor = vscode.window.activeTextEditor;
		const activeTerminal = vscode.window.activeTerminal;
		
		const message = `commandsToSkipShell: ${JSON.stringify(commandsToSkipShell)}
` +
			`Contains 'crowd-pilot.testRun': ${hasCommand}
` +
			`Active Editor: ${activeEditor ? 'Yes' : 'No'}
` +
			`Active Terminal: ${activeTerminal ? activeTerminal.name : 'No'}
` +
			`Terminal Count: ${vscode.window.terminals.length}`;
		
		console.log('[Crowd Pilot] Config check:', message);
		vscode.window.showInformationMessage(message, { modal: true });
	});

	context.subscriptions.push(testRun);
	context.subscriptions.push(checkConfig);
	context.subscriptions.push(enableIntercept);
	context.subscriptions.push(disableIntercept);
}

// This method is called when your extension is deactivated
export function deactivate() {}