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
| 1 | import type Types from '../../types' |
| 2 | |
| 3 | /** |
| 4 | * A KindWalk: each directory is listed once, only after its own entry |
| 5 | * read as `dir` in its parent, and only while listings remain. |
| 6 | * |
| 7 | * Read from the root down, one listing a component: the depth is the |
| 8 | * budget's, never the stack's. A symbolic link is never listed or descended |
| 9 | * and what lies under it reads as null; the unlisted reads `over-budget`. |
| 10 | * |
| 11 | * @param entryKindsOf the host's directory listing |
| 12 | * @param root the absolute directory the walk's paths are relative to |
| 13 | * @param budget how many directories this walk may list |
| 14 | * @returns the walk |
| 15 | */ |
| 16 | export function kindWalkOf( |
| 17 | entryKindsOf: Types.GitDeps['entryKindsOf'], |
| 18 | root: string, |
| 19 | budget: number, |
| 20 | ): Types.KindWalk { |
| 21 | const listings = new Map< |
| 22 | string, |
| 23 | Promise<ReadonlyMap<string, Types.EntryKind> | null> |
| 24 | >() |
| 25 | |
| 26 | function listingOf(directory: string) { |
| 27 | const held = listings.get(directory) |
| 28 | const isOverBudget = held === undefined && listings.size >= budget |
| 29 | |
| 30 | if (isOverBudget) { |
| 31 | return 'over-budget' |
| 32 | } |
| 33 | |
| 34 | const listed = |
| 35 | held ?? entryKindsOf(directory === '' ? root : `${root}/${directory}`) |
| 36 | |
| 37 | listings.set(directory, listed) |
| 38 | |
| 39 | return listed |
| 40 | } |
| 41 | |
| 42 | async function kindOf(path: string): Promise<Types.WalkKind> { |
| 43 | const names = path === '' ? [] : path.split('/') |
| 44 | |
| 45 | let directory = '' |
| 46 | |
| 47 | for (const [depth, name] of names.entries()) { |
| 48 | const listing = listingOf(directory) |
| 49 | |
| 50 | if (listing === 'over-budget') { |
| 51 | return 'over-budget' |
| 52 | } |
| 53 | |
| 54 | const kind = (await listing)?.get(name) ?? null |
| 55 | const isLeaf = depth === names.length - 1 |
| 56 | |
| 57 | if (isLeaf) { |
| 58 | return kind |
| 59 | } |
| 60 | |
| 61 | if (kind !== 'dir') { |
| 62 | return null |
| 63 | } |
| 64 | |
| 65 | directory = directory === '' ? name : `${directory}/${name}` |
| 66 | } |
| 67 | |
| 68 | return 'dir' |
| 69 | } |
| 70 | |
| 71 | return { kindOf } |
| 72 | } |