[tab] src/types.ts (typescript)
/**
 * crowd-code 2.0 Type Definitions
 * Observation-Action schema for state-based capture
 */

// ============================================================================
// Consent Types (kept from v1 for compatibility)
// ============================================================================

export type ConsentStatus = 'pending' | 'accepted' | 'declined'

// ============================================================================
// Action Sources
// ============================================================================

export type ActionSource = 'user' | 'external'

// ============================================================================
// Viewport Types
// ============================================================================

export interface CursorPosition {
	line: number
	character: number
}

export interface ViewportState {
	file: string
	startLine: number
	endLine: number
	content: string
	cursorPosition: CursorPosition | null
}

// ============================================================================
// Terminal Types
// ============================================================================

export interface TerminalEntry {
	type: 'command' | 'output'
	content: string
	timestamp: number
}

export interface TerminalState {
	id: string
	name: string
	recentHistory: TerminalEntry[]
}

// ============================================================================
// Observation Types
// ============================================================================

export interface Observation {
	viewport: ViewportState | null
	activeTerminals: TerminalState[]
}

// ============================================================================
// Action Types
// ============================================================================

export interface EditDiff {
	rangeOffset: number
	rangeLength: number
	text: string
}

export interface EditAction {
	kind: 'edit'
	source: ActionSource
	file: string
	diff: EditDiff
}

export interface SelectionAction {
	kind: 'selection'
	source: ActionSource
	file: string
	selectionStart: CursorPosition
	selectionEnd: CursorPosition
	selectedText: string
}

export interface TabSwitchAction {
	kind: 'tab_switch'
	source: ActionSource
	file: string
	previousFile: string | null
}

export interface TerminalFocusAction {
	kind: 'terminal_focus'
	source: ActionSource
	terminalId: string
	terminalName: string
}

export interface TerminalCommandAction {
	kind: 'terminal_command'
	source: ActionSource
	terminalId: string
	terminalName: string
	command: string
}

export interface TerminalOutputAction {
	kind: 'terminal_output'
	source: ActionSource
	terminalId: string
	terminalName: string
	output: string
}

export interface FileChangeAction {
	kind: 'file_change'
	source: ActionSource
	file: string
	changeType: 'create' | 'change' | 'delete'
	diff: string | null
}

export interface GitAction {
	kind: 'git'
	source: ActionSource
	operation: 'checkout' | 'stash' | 'pull' | 'merge' | 'other'
	details: string
}

export interface ScrollAction {
	kind: 'scroll'
	source: ActionSource
	file: string
}

export type Action =
	| EditAction
	| SelectionAction
	| TabSwitchAction
	| TerminalFocusAction
	| TerminalCommandAction
	| TerminalOutputAction
	| FileChangeAction
	| GitAction
	| ScrollAction

// ============================================================================
// Event Types
// ============================================================================

export interface ObservationEvent {
	sequence: number
	timestamp: number
	type: 'observation'
	observation: Observation
}

export interface ActionEvent {
	sequence: number
	timestamp: number
	type: 'action'
	action: Action
}

export type RecordingEvent = ObservationEvent | ActionEvent

// ============================================================================
// Recording Session Types
// ============================================================================

export interface RecordingSession {
	version: '2.0'
	sessionId: string
	startTime: number
	events: RecordingEvent[]
}

// ============================================================================
// Recording State
// ============================================================================

export interface RecordingState {
	isRecording: boolean
	startDateTime: Date | null
	endDateTime: Date | null
	sequence: number
	sessionId: string
	events: RecordingEvent[]
}

// ============================================================================
// Deduplication Types
// ============================================================================

export interface RecentAction {
	timestamp: number
	contentHash: string
}

// ============================================================================
// File Cache Types
// ============================================================================

export interface CachedFileContent {
	content: string
	timestamp: number
}