p-doom/crowd-code-dataset-0.2 huggingface dataset:
[tab] src/preview/types.ts (typescript)
import * as vscode from 'vscode';

/**
 * Action types that can be previewed and executed.
 */
export type Action =
    | { kind: 'showTextDocument' }
    | { kind: 'setSelections'; selections: Array<{ start: [number, number]; end: [number, number] }> }
    | { kind: 'editInsert'; position: [number, number]; text: string }
    | { kind: 'editDelete'; range: { start: [number, number]; end: [number, number] } }
    | { kind: 'editReplace'; range: { start: [number, number]; end: [number, number] }; text: string }
    | { kind: 'terminalShow' }
    | { kind: 'terminalSendText'; text: string }
    | { kind: 'openFile'; filePath: string; selections?: Array<{ start: [number, number]; end: [number, number] }> };

/**
 * Convert action range to VS Code Range.
 */
export function toVscodeRange(range: { start: [number, number]; end: [number, number] }): vscode.Range {
    return new vscode.Range(
        new vscode.Position(range.start[0], range.start[1]),
        new vscode.Position(range.end[0], range.end[1])
    );
}

/**
 * Convert action position to VS Code Position.
 */
export function toVscodePosition(position: [number, number]): vscode.Position {
    return new vscode.Position(position[0], position[1]);
}

/**
 * Truncate text to a maximum length with ellipsis.
 */
export function truncate(text: string, maxLength: number): string {
    const oneLine = text.replace(/
?
/g, '↵');
    if (oneLine.length <= maxLength) {
        return oneLine;
    }
    return oneLine.slice(0, maxLength - 1) + '…';
}
[tab] /home/franz.srambical/slurm/jobs/franz/berlin/crowd-pilot/start_sglang_server_glm4_5_air.sh (shellscript)
#!/usr/bin/env bash

#SBATCH --nodes=1
#SBATCH --ntasks-per-node=1
#SBATCH --time=24:00:00
#SBATCH --cpus-per-task=8
#SBATCH --gres=gpu:1
#SBATCH --output=/fast/project/HFMI_SynergyUnit/tab_model/logs/franz/%x_%j.log
#SBATCH --error=/fast/project/HFMI_SynergyUnit/tab_model/logs/franz/%x_%j.log
#SBATCH --job-name=crowd_pilot_sglang
#SBATCH --mem=400GB
#SBATCH --qos=normal

export HF_HOME=/fast/project/HFMI_SynergyUnit/tab_model/franz/hf_home/

source /home/franz.srambical/crowd-pilot-serializer-legacy/.venv/bin/activate
module load CUDA/12.8

model_path="zai-org/GLM-4.5-Air"
python3 -m sglang.launch_server --model-path $model_path --host 0.0.0.0 --log-requests \
  --tp-size 8 \
  --tool-call-parser glm45  \
  --reasoning-parser glm45 \
  --speculative-algorithm EAGLE \
  --speculative-num-steps 3 \
  --speculative-eagle-topk 1 \
  --speculative-num-draft-tokens 4 \
  --mem-fraction-static 0.9
[tab] src/preview/quickPick.ts (typescript)
import * as vscode from 'vscode';
import { Action, truncate } from './types';

/**
 * Result of the quick pick interaction.
 */
export type QuickPickResult = 'accept' | 'dismiss' | null;

/**
 * Show a quick pick modal for the pending action.
 * Used when terminal is focused and decorations can't be shown.
 */
export async function showPendingActionQuickPick(action: Action): Promise<QuickPickResult> {
    const detail = formatActionDetail(action);
    
    const items: vscode.QuickPickItem[] = [
        { 
            label: '$(check) Accept', 
            description: 'Execute this action',
            detail: detail
        },
        { 
            label: '$(x) Dismiss', 
            description: 'Cancel this suggestion'
        },
    ];

    const result = await vscode.window.showQuickPick(items, {
        title: 'Pending Suggestion',
        placeHolder: getActionSummary(action),
        ignoreFocusOut: false,
    });

    if (result?.label.includes('Accept')) {
        return 'accept';
    }
    if (result?.label.includes('Dismiss')) {
        return 'dismiss';
    }
    return null;
}

/**
 * Get a short summary of the action for the quick pick placeholder.
 */
function getActionSummary(action: Action): string {
    switch (action.kind) {
        case 'terminalSendText':
            return `Run terminal command`;
        case 'openFile':
            const fileName = action.filePath.split(/[/\\]/).pop() || action.filePath;
            return `Open file: ${fileName}`;
        case 'setSelections':
            return `Move cursor to line ${action.selections[0].start[0] + 1}`;
        case 'editInsert':
            return 'Insert text';
        case 'editReplace':
            return 'Replace text';
        case 'editDelete':
            return `Delete lines ${action.range.start[0] + 1}–${action.range.end[0] + 1}`;
        case 'terminalShow':
            return 'Show terminal';
        case 'showTextDocument':
            return 'Show document';
        default:
            return 'Execute action';
    }
}

/**
 * Format the full action detail for display in quick pick.
 */
function formatActionDetail(action: Action): string {
    switch (action.kind) {
        case 'terminalSendText':
            return action.text;
        case 'openFile':
            if (action.selections?.[0]) {
                const line = action.selections[0].start[0] + 1;
                return `${action.filePath}:${line}`;
            }
            return action.filePath;
        case 'setSelections':
            const sel = action.selections[0];
            return `Line ${sel.start[0] + 1}, Column ${sel.start[1] + 1}`;
        case 'editInsert':
            return truncate(action.text, 200);
        case 'editReplace':
            return truncate(action.text, 200);
        case 'editDelete':
            return `Lines ${action.range.start[0] + 1} to ${action.range.end[0] + 1}`;
        default:
            return '';
    }
}
[content] src/preview/inlineProvider.ts (typescript)
import * as vscode from 'vscode';
import { Action, toVscodeRange, toVscodePosition } from './types';

/**
 * Provides inline completion items (ghost text) for code edit actions.
 * This takes priority over Cursor's hints and works on empty lines.
 */
export class CrowdPilotInlineProvider implements vscode.InlineCompletionItemProvider {
    private action: Action | null = null;
    private enabled: boolean = true;

    /**
     * Set the current action to display as inline completion.
     */
    setAction(action: Action): void {
        this.action = action;
        // Trigger VS Code to re-query inline completions
        vscode.commands.executeCommand('editor.action.inlineSuggest.trigger');
    }

    /**
     * Clear the current action.
     */
    clearAction(): void {
        this.action = null;
    }

    /**
     * Get the current action.
     */
    getAction(): Action | null {
        return this.action;
    }

    /**
     * Enable or disable the provider.
     */
    setEnabled(enabled: boolean): void {
        this.enabled = enabled;
    }

    /**
     * Provide inline completion items.
     */
    provideInlineCompletionItems(
        document: vscode.TextDocument,
        position: vscode.Position,
        context: vscode.InlineCompletionContext,
        token: vscode.CancellationToken
    ): vscode.ProviderResult<vscode.InlineCompletionList | vscode.InlineCompletionItem[]> {
        if (!this.enabled || !this.action) {
            return [];
        }

        // Only handle pure insertions (not replacements)
        // Replacements are handled by decorations to properly show what's being deleted
        if (this.action.kind !== 'editInsert') {
            return [];
        }

        const insertPos = toVscodePosition(this.action.position);
        
        // Only provide completion if insert position is at or after the cursor
        // VS Code's inline completion API shows ghost text at/after cursor position
        if (insertPos.isBefore(position)) {
            return [];
        }
        
        const item = new vscode.InlineCompletionItem(
            this.action.text,
            new vscode.Range(insertPos, insertPos)
        );
        
        return [item];
    }

    /**
     * Check if the current action's position is near the given cursor position.
     * Used to determine if we need a fallback indicator.
     */
    isActionNearCursor(cursorLine: number): boolean {
        if (!this.action) return false;
        
        if (this.action.kind === 'editInsert') {
            return Math.abs(this.action.position[0] - cursorLine) <= 1;
        }
        
        if (this.action.kind === 'editReplace') {
            return cursorLine >= this.action.range.start[0] - 1 && 
                   cursorLine <= this.action.range.end[0] + 1;
        }
        
        return false;
    }
}
[content] src/preview/inlineProvider.ts (typescript)
import * as vscode from 'vscode';
import { Action, toVscodeRange, toVscodePosition } from './types';

/**
 * Provides inline completion items (ghost text) for code edit actions.
 * This takes priority over Cursor's hints and works on empty lines.
 */
export class CrowdPilotInlineProvider implements vscode.InlineCompletionItemProvider {
    private action: Action | null = null;
    private enabled: boolean = true;

    /**
     * Set the current action to display as inline completion.
     */
    setAction(action: Action): void {
        this.action = action;
        // Trigger VS Code to re-query inline completions
        vscode.commands.executeCommand('editor.action.inlineSuggest.trigger');
    }

    /**
     * Clear the current action.
     */
    clearAction(): void {
        this.action = null;
    }

    /**
     * Get the current action.
     */
    getAction(): Action | null {
        return this.action;
    }

    /**
     * Enable or disable the provider.
     */
    setEnabled(enabled: boolean): void {
        this.enabled = enabled;
    }

    /**
     * Provide inline completion items.
     */
    provideInlineCompletionItems(
        document: vscode.TextDocument,
        position: vscode.Position,
        context: vscode.InlineCompletionContext,
        token: vscode.CancellationToken
    ): vscode.ProviderResult<vscode.InlineCompletionList | vscode.InlineCompletionItem[]> {
        if (!this.enabled || !this.action) {
            return [];
        }

        // Only handle pure insertions (not replacements)
        // Replacements are handled by decorations to properly show what's being deleted
        if (this.action.kind !== 'editInsert') {
            return [];
        }

        const insertPos = toVscodePosition(this.action.position);
        
        // Only provide completion if insert position is at or after the cursor
        // VS Code's inline completion API shows ghost text at/after cursor position
        if (insertPos.isBefore(position)) {
            return [];
        }
        
        const item = new vscode.InlineCompletionItem(
            this.action.text,
            new vscode.Range(insertPos, insertPos)
        );
        
        return [item];
    }

    /**
     * Check if the current action's position is near the given cursor position.
     * Used to determine if we need a fallback indicator.
     */
    isActionNearCursor(cursorLine: number): boolean {
        if (!this.action) {
            return false;
        }
        
        if (this.action.kind === 'editInsert') {
            return Math.abs(this.action.position[0] - cursorLine) <= 1;
        }
        
        if (this.action.kind === 'editReplace') {
            return cursorLine >= this.action.range.start[0] - 1 && 
                   cursorLine <= this.action.range.end[0] + 1;
        }
        
        return false;
    }
}
[content] src/preview/inlineProvider.ts (typescript)
import * as vscode from 'vscode';
import { Action, toVscodePosition } from './types';

/**
 * Provides inline completion items (ghost text) for code edit actions.
 * This takes priority over Cursor's hints and works on empty lines.
 */
export class CrowdPilotInlineProvider implements vscode.InlineCompletionItemProvider {
    private action: Action | null = null;
    private enabled: boolean = true;

    /**
     * Set the current action to display as inline completion.
     */
    setAction(action: Action): void {
        this.action = action;
        // Trigger VS Code to re-query inline completions
        vscode.commands.executeCommand('editor.action.inlineSuggest.trigger');
    }

    /**
     * Clear the current action.
     */
    clearAction(): void {
        this.action = null;
    }

    /**
     * Get the current action.
     */
    getAction(): Action | null {
        return this.action;
    }

    /**
     * Enable or disable the provider.
     */
    setEnabled(enabled: boolean): void {
        this.enabled = enabled;
    }

    /**
     * Provide inline completion items.
     */
    provideInlineCompletionItems(
        document: vscode.TextDocument,
        position: vscode.Position,
        context: vscode.InlineCompletionContext,
        token: vscode.CancellationToken
    ): vscode.ProviderResult<vscode.InlineCompletionList | vscode.InlineCompletionItem[]> {
        if (!this.enabled || !this.action) {
            return [];
        }

        // Only handle pure insertions (not replacements)
        // Replacements are handled by decorations to properly show what's being deleted
        if (this.action.kind !== 'editInsert') {
            return [];
        }

        const insertPos = toVscodePosition(this.action.position);
        
        // Only provide completion if insert position is at or after the cursor
        // VS Code's inline completion API shows ghost text at/after cursor position
        if (insertPos.isBefore(position)) {
            return [];
        }
        
        const item = new vscode.InlineCompletionItem(
            this.action.text,
            new vscode.Range(insertPos, insertPos)
        );
        
        return [item];
    }

    /**
     * Check if the current action's position is near the given cursor position.
     * Used to determine if we need a fallback indicator.
     */
    isActionNearCursor(cursorLine: number): boolean {
        if (!this.action) {
            return false;
        }
        
        if (this.action.kind === 'editInsert') {
            return Math.abs(this.action.position[0] - cursorLine) <= 1;
        }
        
        if (this.action.kind === 'editReplace') {
            return cursorLine >= this.action.range.start[0] - 1 && 
                   cursorLine <= this.action.range.end[0] + 1;
        }
        
        return false;
    }
}