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 / datings-of / datings-of.ts
38 lines · 1.3 KBRaw
1import type Types from '../../types'
2import { stampIfFile } from '../stamp-if-file'
3
4/**
5 * When each path was last modified against the session's start, dating a
6 * path only when it is a real file under real directories at every level.
7 *
8 * Listings report an entry's own kind, so a symbolic link anywhere on the
9 * path is never listed, descended or stat'ed: session work (the engine
10 * lstats); a path the listing budget never reached is the caller's to place.
11 *
12 * @param context the fetch's stamp probe over the working tree's top, and
13 * when the session began
14 * @param paths repository-relative paths, `/`-separated as git prints them
15 * @returns each path's Dating
16 */
17export async function datingsOf(
18 context: Types.DatingContext,
19 paths: readonly string[],
20): Promise<ReadonlyMap<string, Types.Dating>> {
21 const { sessionStartMs } = context.deps
22
23 const stamps: readonly Types.Stamp[] = await Promise.all(
24 paths.map(path => stampIfFile(context.stamps, path)),
25 )
26
27 function datingOf(stamp: Types.Stamp): Types.Dating {
28 if (stamp === 'over-budget') {
29 return 'unlisted'
30 }
31
32 const isEarlier = (stamp ?? Number.POSITIVE_INFINITY) < sessionStartMs
33
34 return isEarlier ? 'pre-session' : 'session'
35 }
36
37 return new Map(paths.map((path, at) => [path, datingOf(stamps[at] ?? null)]))
38}