File size: 2,373 Bytes
d242052
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { SelectionStore } from './SelectionStore';
import { ContextEngine } from './ContextEngine';
import { WorkspaceEvents } from './WorkspaceEvents';
import { WorkspaceHistory } from './WorkspaceHistory';
import { WorkspaceTimeline } from './WorkspaceTimeline';
import { WorkspaceSnapshots } from './WorkspaceSnapshots';
import { WorkspaceLayout } from './WorkspaceLayout';

import type { EngineeringIntent, WorkspaceMode, ContextState } from './types';

export class WorkspaceController {
  private static instance: WorkspaceController;

  public selection = new SelectionStore();
  public contextEngine = new ContextEngine();
  public events = new WorkspaceEvents();
  public history = new WorkspaceHistory();
  public timeline = new WorkspaceTimeline();
  public snapshots = new WorkspaceSnapshots();
  public layout = new WorkspaceLayout();

  private activeIntent: EngineeringIntent = 'Understand Repository';
  private activeMode: WorkspaceMode = 'explore';
  private contextState: ContextState = 'API Layer';
  private confidencePct: number = 94;

  public static getInstance(): WorkspaceController {
    if (!WorkspaceController.instance) {
      WorkspaceController.instance = new WorkspaceController();
    }
    return WorkspaceController.instance;
  }

  public getActiveIntent(): EngineeringIntent {
    return this.activeIntent;
  }

  public getActiveMode(): WorkspaceMode {
    return this.activeMode;
  }

  public getContextState(): ContextState {
    return this.contextState;
  }

  public getConfidencePct(): number {
    return this.confidencePct;
  }

  public setIntent(intent: EngineeringIntent): void {
    this.activeIntent = intent;
    const l = this.layout.getLayoutForIntent(intent);
    this.activeMode = l.mode;
    this.timeline.recordAction('Changed Intent', intent);
    this.events.emit('state_changed');
  }

  public selectFile(file_path: string): void {
    this.selection.setSelectedFile(file_path);
    this.history.push(file_path);
    this.timeline.recordAction('Opened File', file_path);

    const inferred = this.contextEngine.inferContext(file_path);
    this.contextState = inferred.contextState;
    this.confidencePct = inferred.confidencePct;

    this.events.emit('selection_changed', { file_path });
    this.events.emit('state_changed');
  }
}

export const workspaceController = WorkspaceController.getInstance();