* `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)
| 471 | * the other agent's block. |
| 472 | */ |
| 473 | function 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. */ |
| 488 | export function removeInstructionsEntry(file: string): { path: string; action: 'removed' | 'not-found' | 'kept' } { |
no test coverage detected