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 / git / probes / untracked-rows-of / untracked-rows-of.ts
54 lines · 1.7 KBRaw
1import Limits from '../../../limits'
2import type Types from '../../types'
3import { datingsOf } from '../datings-of'
4import type { UntrackedPlace } from '../untracked-place'
5
6/**
7 * Listed untracked paths as 0/0 rows: the session's own first, then,
8 * when the scope asks, the tagged pre-session ones, up to the slots.
9 *
10 * At most MAX_UNTRACKED_PROBES are dated; a file past that or past the
11 * listing budget reads as pre-session, an undatable one as the session's
12 * (the built-in panel's rule).
13 *
14 * @param context the fetch's stamp probe and session start
15 * @param paths the untracked paths, root-relative, as the lister printed them
16 * @param place the free row slots and the scope
17 * @returns the rows to merge after the tracked ones
18 */
19export async function untrackedRowsOf(
20 context: Types.DatingContext,
21 paths: readonly string[],
22 place: UntrackedPlace,
23): Promise<readonly Types.FileStat[]> {
24 const probedPaths = paths.slice(0, Limits.MAX_UNTRACKED_PROBES)
25 const datings = await datingsOf(context, probedPaths)
26
27 const probed = probedPaths.map(path => ({
28 path,
29 isPreSession: datings.get(path) !== 'session',
30 }))
31
32 const isWithPreSession = place.scope === 'with-pre-session'
33
34 const earlier = isWithPreSession
35 ? [
36 ...probed.filter(file => file.isPreSession),
37 ...paths
38 .slice(Limits.MAX_UNTRACKED_PROBES)
39 .map(path => ({ path, isPreSession: true })),
40 ]
41 : []
42
43 const ordered = [...probed.filter(file => !file.isPreSession), ...earlier]
44
45 return ordered.slice(0, place.slots).map(file => ({
46 path: file.path,
47 renamedFrom: null,
48 added: 0,
49 removed: 0,
50 isBinary: false,
51 isUntracked: true,
52 isPreSession: file.isPreSession,
53 }))
54}