Skip to content

EROFS crash when OpenCode launched outside a git repo (//AGENTS.md path) #25

@RobinVivant

Description

@RobinVivant

Bug

When OpenCode is launched from a directory that is not a git repository (e.g. the user's home directory), the lore plugin crashes with an EROFS: read-only file system error trying to write to //AGENTS.md.

Root Cause

In src/index.ts:64:

const projectPath = ctx.worktree || ctx.directory;

When there is no git worktree and ctx.directory resolves to / (or an empty-ish path), the file path construction at lines 84 and 386:

const filePath = `${projectPath}/${agentsCfg.path}`;

produces //AGENTS.md. Then exportToFile calls mkdirSync(dirname("//AGENTS.md")) which attempts to write to the system root — a read-only filesystem on macOS.

Stack Trace

EROFS: read-only file system, open '//AGENTS.md'
    path: "//AGENTS.md",
    syscall: "open",
    errno: -30,
    code: "EROFS"

    at exportToFile (/Users/.../.cache/opencode/node_modules/opencode-lore/src/agents-file.ts:285:3)
    at <anonymous> (/Users/.../.cache/opencode/node_modules/opencode-lore/src/index.ts:387:13)

Suggested Fix

Guard against invalid project paths before attempting the agents-file export. For example:

import { join, isAbsolute } from "path";

// Option A: Skip export when projectPath is root or empty
if (projectPath === "/" || projectPath === "" || !projectPath) {
  console.error("[lore] skipping agents-file export: no valid project path");
  return;
}

// Option B: Use path.join instead of string concatenation
const filePath = join(projectPath, agentsCfg.path);

Both the import (line 84) and export (line 386) path constructions have this issue.

Environment

  • macOS (APFS, root is read-only)
  • opencode-lore v0.5.0
  • OpenCode launched from home directory (not a git repo)

Workaround

Run git init in the home directory so ctx.worktree resolves to a valid path.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions