p-doom/crowd-code-dataset-0.2 huggingface dataset:
[content] crowd-pilot-extension/src/extension.ts (typescript)
	// Check model certainty from logprobs before proceeding
	const certainty = calculateModelCertainty(json);
	if (MIN_MODEL_CERTAINTY > 0 && certainty < MIN_MODEL_CERTAINTY) {
		throw new Error(`Model certainty (${(certainty * 100).toFixed(1)}%) below threshold (${(MIN_MODEL_CERTAINTY * 100).toFixed(1)}%)`);
	}
[content] crowd-pilot-extension/src/extension.ts (typescript)
/**
 * Calculate average model certainty from logprobs in the API response.
 * Returns a value between 0.0 and 1.0, where 1.0 is highest certainty.
 * Returns 1.0 if logprobs are not available (to avoid blocking suggestions).
 */
function calculateModelCertainty(json: any): number {
	try {
		if (!json || !Array.isArray(json.choices) || !json.choices[0]) {
			return 1.0; // No logprobs available, allow suggestion
		}
		const choice = json.choices[0];
		const logprobs = choice.logprobs;
		
		if (!logprobs || !Array.isArray(logprobs.content) || logprobs.content.length === 0) {
			return 1.0; // No logprobs available, allow suggestion
		}

		// Calculate average probability from log probabilities
		// logprob = ln(probability), so probability = exp(logprob)
		let totalLogProb = 0;
		let tokenCount = 0;

		for (const tokenInfo of logprobs.content) {
			if (typeof tokenInfo.logprob === 'number' && isFinite(tokenInfo.logprob)) {
				totalLogProb += tokenInfo.logprob;
				tokenCount++;
			}
		}

		if (tokenCount === 0) {
			return 1.0; // No valid logprobs, allow suggestion
		}

		// Calculate geometric mean of probabilities (equivalent to exp(mean of logprobs))
		const avgLogProb = totalLogProb / tokenCount;
		const certainty = Math.exp(avgLogProb);
		
		return Math.max(0, Math.min(1, certainty)); // Clamp to [0, 1]
	} catch {
		return 1.0; // On error, allow suggestion
	}
}
[content] crowd-pilot-extension/src/extension.ts (typescript)
// Minimum cumulative logprob threshold for displaying suggestions
// This is the sum of log probabilities for the entire sequence (negative values, closer to 0 = more confident)
// Set to -Infinity to disable certainty filtering
const MIN_CUMULATIVE_LOGPROB = -50;
[content] crowd-pilot-extension/src/extension.ts (typescript)
	// Check model certainty from cumulative logprobs before proceeding
	const cumulativeLogprob = calculateCumulativeLogprob(json);
	if (cumulativeLogprob !== null && cumulativeLogprob < MIN_CUMULATIVE_LOGPROB) {
		return undefined as any; // Low certainty, silently skip suggestion
	}
[content] crowd-pilot-extension/src/extension.ts (typescript)
// Minimum sequence probability threshold for displaying suggestions
// This is the product of token probabilities (0.0 to 1.0, higher = more confident)
// Set to 0.0 to disable certainty filtering
const MIN_SEQUENCE_PROBABILITY = 0.001;
[content] crowd-pilot-extension/src/extension.ts (typescript)
	// Check model certainty from sequence probability before proceeding
	const sequenceProbability = calculateSequenceProbability(json);
	if (sequenceProbability !== null && sequenceProbability < MIN_SEQUENCE_PROBABILITY) {
		return undefined as any; // Low certainty, silently skip suggestion
	}
[content] crowd-pilot-extension/src/extension.ts (typescript)
/**
 * Calculate cumulative logprob (sum of token log probabilities) from the API response.
 * Returns the sum of logprobs for the entire sequence (negative value, closer to 0 = more confident).
 * Returns null if logprobs are not available.
 */
function calculateCumulativeLogprob(json: any): number | null {
	try {
		if (!json || !Array.isArray(json.choices) || !json.choices[0]) {
			return null; // No logprobs available
		}
		const choice = json.choices[0];
		const logprobs = choice.logprobs;
		
		if (!logprobs || !Array.isArray(logprobs.content) || logprobs.content.length === 0) {
			return null; // No logprobs available
		}

		// Sum all token log probabilities (cumulative logprob of the sequence)
		let cumulativeLogprob = 0;

		for (const tokenInfo of logprobs.content) {
			if (typeof tokenInfo.logprob === 'number' && isFinite(tokenInfo.logprob)) {
				cumulativeLogprob += tokenInfo.logprob;
			}
		}

		return cumulativeLogprob;
	} catch {
		return null; // On error, allow suggestion
	}
}
[content] crowd-pilot-extension/src/extension.ts (typescript)
/**
 * Calculate cumulative logprob (sum of token log probabilities) from the API response.
 * Returns the sum of logprobs for the entire sequence (negative value, closer to 0 = more confident).
 * Returns null if logprobs are not available.
 */
function calculateCumulativeLogprob(json: any): number | null {
	const content = json?.choices?.[0]?.logprobs?.content;
	if (!Array.isArray(content)) { return null; }
	return content.reduce((sum: number, tokenInfo: any) => sum + (tokenInfo.logprob || 0), 0);
}
[content] crowd-pilot-extension/src/extension.ts (typescript)
	// Check model certainty from cumulative logprobs before proceeding
	const cumulativeLogprob = calculateCumulativeLogprob(json);
	if (cumulativeLogprob < MIN_CUMULATIVE_LOGPROB) {
		return undefined as any; // Low certainty, silently skip suggestion
	}
[content] crowd-pilot-extension/src/extension.ts (typescript)
/**
 * Calculate cumulative logprob (sum of token log probabilities) from the API response.
 * Returns the sum of logprobs for the entire sequence (negative value, closer to 0 = more confident).
 * Returns null if logprobs are not available.
 */
function calculateCumulativeLogprob(json: any): number | null {
	const logprobs = json.choices[0].logprobs;
	return logprobs.content.reduce((sum: number, tokenInfo: any) => sum + (tokenInfo.logprob || 0), 0);
}
[content] crowd-pilot-extension/src/extension.ts (typescript)
	const content = json?.choices?.[0]?.logprobs?.content;
	if (!Array.isArray(content) || content.length === 0) {
		return null;
	}
	return content.reduce((sum: number, tokenInfo: any) => sum + (tokenInfo.logprob || 0), 0);
[tab] crowd-pilot-extension/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.hideUi",
        "title": "crowd-pilot: Hide Preview"
      },
      {
        "command": "crowd-pilot.sglangTest",
        "title": "crowd-pilot: Test SGLang"
      },
      {
        "command": "crowd-pilot.modelRun",
        "title": "crowd-pilot: Model Plan & Run"
      }
    ],
    "keybindings": [
      {
        "command": "crowd-pilot.modelRun",
        "key": "tab",
        "mac": "tab",
        "when": "editorTextFocus && crowdPilot.uiVisible"
      },
      {
        "command": "crowd-pilot.modelRun",
        "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"
  }
}
[content] crowd-pilot-extension/src/extension.ts (typescript)
// Tab suggestions enabled state
let suggestionsEnabled = true;
let statusBarItem: vscode.StatusBarItem | undefined;

function updateStatusBarItem(): void {
	if (!statusBarItem) { return; }
	if (suggestionsEnabled) {
		statusBarItem.text = '$(lightbulb) Crowd Pilot';
		statusBarItem.tooltip = 'Crowd Pilot: Tab suggestions enabled (click to disable)';
		statusBarItem.backgroundColor = undefined;
	} else {
		statusBarItem.text = '$(lightbulb-autofix) Crowd Pilot';
		statusBarItem.tooltip = 'Crowd Pilot: Tab suggestions disabled (click to enable)';
		statusBarItem.backgroundColor = new vscode.ThemeColor('statusBarItem.warningBackground');
	}
}
[content] crowd-pilot-extension/src/extension.ts (typescript)
	// Create status bar item
	statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, 100);
	statusBarItem.command = 'crowd-pilot.toggleSuggestions';
	updateStatusBarItem();
	statusBarItem.show();
	context.subscriptions.push(statusBarItem);

	const toggleSuggestions = vscode.commands.registerCommand('crowd-pilot.toggleSuggestions', () => {
		suggestionsEnabled = !suggestionsEnabled;
		updateStatusBarItem();
		if (!suggestionsEnabled) {
			hidePreviewUI(true);
		}
		vscode.window.showInformationMessage(
			suggestionsEnabled 
				? 'Crowd Pilot: Tab suggestions enabled' 
				: 'Crowd Pilot: Tab suggestions disabled'
		);
	});
[content] crowd-pilot-extension/src/extension.ts (typescript)
// Configuration helper
function getConfig() {
	const config = vscode.workspace.getConfiguration('crowd-pilot');
	return {
		hostname: config.get<string>('hostname', 'hai002'),
		port: config.get<number>('port', 30000),
		basePath: config.get<string>('basePath', '/v1/chat/completions'),
		modelName: config.get<string>('modelName', 'qwen/qwen3-8b'),
	};
}
[content] crowd-pilot-extension/src/extension.ts (typescript)
function calculateAverageLogprob(json: any): number {
	const logprobs = json.choices[0]?.logprobs;
	const content = logprobs?.content;
	if (!content || content.length === 0) { return -Infinity; }
	const sum = content.reduce((s: number, t: any) => s + t.logprob, 0);
	return sum / content.length;
[content] crowd-pilot-extension/src/extension.ts (typescript)
 * Calculate average logprob per token from the API response.
 * Returns the mean of logprobs across all tokens (negative value, closer to 0 = more confident).
 * Returns -Infinity if logprobs are not available.
[content] crowd-pilot-extension/src/extension.ts (typescript)
 * Calculate cumulative logprob (sum of token log probabilities) from the API response.
 * Returns the sum of logprobs for the entire sequence (negative value, closer to 0 = more confident).
 * Returns null if logprobs are not available.
[content] crowd-pilot-extension/src/extension.ts (typescript)
		'You are a helpful assistant that interacts with a computer shell to solve programming tasks.',
		'Your goal is to predict the next bash command a developer would most likely execute, given their editing and navigation history.',
		'',
		'=== CONVERSATION FORMAT ===',
		'The conversation history alternates between:',
		'- Assistant messages: bash commands in fenced code blocks',
		'- User messages: command output wrapped in <stdout>...</stdout> tags',
		'',
		'File contents are displayed with 6-character right-aligned line numbers followed by a tab, e.g.:',
		'     1	first line',
		'     2	second line',
		'',
		'File content is typically shown in viewports of ~20 lines around the area of interest.',
		'',
		'=== RESPONSE FORMAT ===',
[content] crowd-pilot-extension/LICENSE (plaintext)
Copyright [yyyy] [name of copyright owner]

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
[content] crowd-pilot-extension/src/extension.ts (typescript)
function getOrCreateCrowdPilotTerminal(): vscode.Terminal {
	// Check if our dedicated terminal still exists
	if (crowdPilotTerminal && vscode.window.terminals.includes(crowdPilotTerminal)) {
		return crowdPilotTerminal;
	}
	// Create a new dedicated terminal
	crowdPilotTerminal = vscode.window.createTerminal('crowd-pilot');
	return crowdPilotTerminal;
}
[content] crowd-pilot-extension/src/extension.ts (typescript)
// Find or create a dedicated terminal for crowd-pilot commands
function getOrCreateCrowdPilotTerminal(): vscode.Terminal {
	const terminalName = 'crowd-pilot';
	// Look for an existing crowd-pilot terminal
	const existing = vscode.window.terminals.find(t => t.name === terminalName);
	if (existing) {
		return existing;
	}
	// Create a new dedicated terminal
	return vscode.window.createTerminal(terminalName);
}
[content] crowd-pilot-extension/src/extension.ts (typescript)
// Get the most recently used terminal, or create one if none exists
function getActiveOrCreateTerminal(): vscode.Terminal {
	// activeTerminal is the terminal the user most recently interacted with
	if (vscode.window.activeTerminal) {
		return vscode.window.activeTerminal;
	}
	// Fallback: create a new terminal if none is active
	return vscode.window.createTerminal('crowd-pilot');
}