-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathcells.ts
More file actions
81 lines (74 loc) · 2.19 KB
/
Copy pathcells.ts
File metadata and controls
81 lines (74 loc) · 2.19 KB
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
74
75
76
77
78
79
80
81
import type { AgentSession, WorkspaceMode } from "@posthog/shared";
import type { Task } from "@posthog/shared/domain-types";
import {
getTerminalCellCwd,
getTerminalCellId,
isBrainrotCell,
isTerminalCell,
} from "./grid";
import { type CellStatus, deriveStatus, getRepoName } from "./status";
export interface CommandCenterCellData {
cellIndex: number;
taskId: string | null;
task: Task | undefined;
session: AgentSession | undefined;
status: CellStatus;
repoName: string | null;
workspaceMode: WorkspaceMode | null;
// Brainrot: a looping video slot rather than a task.
isBrainrot: boolean;
// Standalone terminal slot, independent of any agent run.
terminalId: string | null;
terminalCwd: string | null;
}
export interface BuildCellsInput {
taskById: Map<string, Task>;
sessionByTaskId: Map<string, AgentSession>;
workspaces: Record<string, { mode: WorkspaceMode } | undefined> | undefined;
}
const EMPTY_CELL_DATA = {
taskId: null,
task: undefined,
session: undefined,
status: "idle" as const,
repoName: null,
workspaceMode: null,
isBrainrot: false,
terminalId: null,
terminalCwd: null,
};
export function buildCommandCenterCells(
storeCells: (string | null)[],
input: BuildCellsInput,
): CommandCenterCellData[] {
const { taskById, sessionByTaskId, workspaces } = input;
return storeCells.map((cellValue, cellIndex) => {
if (isBrainrotCell(cellValue)) {
return { ...EMPTY_CELL_DATA, cellIndex, isBrainrot: true };
}
if (isTerminalCell(cellValue)) {
return {
...EMPTY_CELL_DATA,
cellIndex,
terminalId: getTerminalCellId(cellValue),
terminalCwd: getTerminalCellCwd(cellValue),
};
}
const taskId = cellValue;
const task = taskId ? taskById.get(taskId) : undefined;
const session = taskId ? sessionByTaskId.get(taskId) : undefined;
const status = taskId ? deriveStatus(session) : "idle";
const repoName = task ? getRepoName(task) : null;
const workspaceMode = (taskId ? workspaces?.[taskId]?.mode : null) ?? null;
return {
...EMPTY_CELL_DATA,
cellIndex,
taskId,
task,
session,
status,
repoName,
workspaceMode,
};
});
}