spacehub

surshar / claude-code

Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.

Built by Anthropic · github.com/anthropics

claude-code / mods / diff / hooks / views / body / plan / dock-plan-of.ts
80 lines · 2.5 KBRaw
1import PaneState from '../../../pane-state'
2import DialogPane from '../../dialog-pane'
3import Entries from '../../entries'
4import Layout from '../../layout'
5import type { DockPlan } from '../types'
6
7/**
8 * The docked pane's decisions over a model (ReplDiffSidebarBody's): which
9 * rows list, what the header counts, what stands in for an empty list.
10 *
11 * Over a picked turn the rows are the turn's files and nothing is empty;
12 * else the fetch's session rows, its pre-session rows apart. Under the
13 * header: the base line outside settled session mode, or the unborn note.
14 *
15 * @param model the pane's state
16 * @returns the plan
17 */
18export function dockPlanOf(model: PaneState.PaneModel): DockPlan {
19 const { data, requestedMode } = model
20 const turn = PaneState.pickedTurnOf(model)
21 const noise = model.isNoiseShown ? 'shown' : 'hidden'
22 const partition = PaneState.partitionOf(data?.files ?? [], noise)
23 const face = model.isPreSessionShown ? 'hide' : 'show'
24
25 const totals = turn
26 ? PaneState.turnTotalsOf(turn)
27 : data
28 ? PaneState.headerTotalsOf(data, partition)
29 : PaneState.ZERO_TOTALS
30
31 const empty = turn ? null : PaneState.emptyStateOf(model, totals.filesCount)
32
33 const listed = turn
34 ? []
35 : DialogPane.listBodyOf({ data, partition, totals, empty })
36
37 const notes = listed.flatMap(line => (typeof line === 'string' ? [line] : []))
38 const hasRows = turn ? turn.files.length > 0 : notes.length < listed.length
39
40 const entryOf = (file: Parameters<typeof Entries.bodyEntryOf>[0]) =>
41 Entries.bodyEntryOf(file, model)
42
43 const rows = turn
44 ? turn.files.map(Entries.turnEntryOf)
45 : hasRows
46 ? partition.shown.map(entryOf)
47 : []
48
49 const earlier = turn ? [] : partition.preSession.map(entryOf)
50 const hasEarlier = earlier.length > 0
51
52 const isBaseShown =
53 data !== null &&
54 !data.isUnborn &&
55 (requestedMode !== 'session' || data.mode !== 'session')
56
57 const line = turn
58 ? `Turn ${turn.index} "${turn.preview}"`
59 : isBaseShown
60 ? PaneState.modeLabelOf(requestedMode, model)
61 : PaneState.unbornNoteOf(model, totals.filesCount)
62
63 return {
64 turn,
65 partition,
66 totals,
67 empty,
68 line: line === null ? null : Layout.sanitizeName(line),
69 rows,
70 earlier,
71 earlierLabel: hasEarlier
72 ? `+${Layout.plural(earlier.length, 'file')} edited before this ` +
73 `session (${face})`
74 : null,
75 notes,
76 message: empty ? [empty.headline, ...notes] : hasRows ? [] : notes,
77 isUntrackedNoted:
78 !turn && data?.isUntrackedWithheld === true && empty === null,
79 }
80}