MCPcopy Index your code
hub / github.com/coder/mux / readSingleFile

Function readSingleFile

src/node/utils/main/instructionFiles.ts:71–102  ·  view source on GitHub ↗

Read a single instruction file via the given reader, returning structured info.

(
  reader: FileReader,
  directory: string,
  filename: string,
  scope: InstructionScope,
  isLocal: boolean,
  projectName: string | undefined,
  muxOnly: boolean
)

Source from the content-addressed store, hash-verified

69
70/** Read a single instruction file via the given reader, returning structured info. */
71async function readSingleFile(
72 reader: FileReader,
73 directory: string,
74 filename: string,
75 scope: InstructionScope,
76 isLocal: boolean,
77 projectName: string | undefined,
78 muxOnly: boolean
79): Promise<ReadInstructionFileResult> {
80 let raw: string;
81 try {
82 raw = await reader.readFile(path.join(directory, filename));
83 } catch {
84 return { exists: false };
85 }
86 const sanitized = stripMarkdownComments(raw);
87 if (sanitized.length === 0) return { exists: true, file: null };
88 return {
89 exists: true,
90 file: {
91 path: path.join(directory, filename),
92 filename,
93 isLocal,
94 muxOnly,
95 scope,
96 projectName: projectName ?? null,
97 content: sanitized,
98 bytes: Buffer.byteLength(sanitized, "utf-8"),
99 tokens: null,
100 },
101 };
102}
103
104/** Try each base filename in priority order; return the first that exists. */
105async function readBaseInstructionFile(

Callers 2

readBaseInstructionFileFunction · 0.85
readInstructionSetWithFunction · 0.85

Calls 2

stripMarkdownCommentsFunction · 0.85
readFileMethod · 0.65

Tested by

no test coverage detected