MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / blockToWrite

Function blockToWrite

src/installer/targets/shared.ts:473–485  ·  view source on GitHub ↗

* `block`, unless it is the plain block and `file` already holds OpenCode's * (#1267). Agents share instructions files — the project's AGENTS.md is read by * Codex, Droid, Kimi, Pi and OpenCode, and dotfiles often link several agents' * files to one — and OpenCode's block names the tool both ways

(file: string, block: string)

Source from the content-addressed store, hash-verified

471 * the other agent's block.
472 */
473function blockToWrite(file: string, block: string): string {
474 if (block !== CODEGRAPH_INSTRUCTIONS_BLOCK) return block;
475 let content: string;
476 try {
477 content = fs.readFileSync(file, 'utf-8');
478 } catch {
479 return block;
480 }
481 const first = findMarkedSections(content, CODEGRAPH_SECTION_START, CODEGRAPH_SECTION_END)[0];
482 if (!first) return block;
483 const existing = withLineBreaks(content.slice(first.start, first.end), '\n');
484 return existing === OPENCODE_INSTRUCTIONS_BLOCK ? OPENCODE_INSTRUCTIONS_BLOCK : block;
485}
486
487/** Inverse of `upsertInstructionsEntry`: strip the CodeGraph block from `file`, if it has one. */
488export function removeInstructionsEntry(file: string): { path: string; action: 'removed' | 'not-found' | 'kept' } {

Callers 1

upsertInstructionsEntryFunction · 0.85

Calls 2

findMarkedSectionsFunction · 0.85
withLineBreaksFunction · 0.85

Tested by

no test coverage detected