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 / agents-md / hooks / files / files-of.ts
20 lines · 681 BRaw
1import type { FsAncestor, InstructionFile } from 'claude-code'
2
3/**
4 * The found AGENTS.md files as project instruction files, one per file and
5 * per file it `@`-imported, in walk and load order.
6 *
7 * An import names the file that brought it as its parent.
8 *
9 * @param found what `$.fs.ancestors` found, root first
10 * @returns the instruction files, kind `project`
11 */
12export const filesOf = (found: readonly FsAncestor[]): InstructionFile[] =>
13 found.flatMap(entry =>
14 entry.parts.map((part, index) => ({
15 path: part.path,
16 kind: 'project' as const,
17 content: part.content,
18 ...(index > 0 && { parent: entry.parts[0]?.path ?? part.path }),
19 })),
20 )