JuliusBrussee/caveman · error

caveman-code: not a file

Error message

caveman-code: not a file: ${input.path}

What it means

The read tool in packages/agent/src/code.ts resolves the requested path inside the workspace (contained()), stats it, and requires it to be a regular file. If stat succeeds but the target is a directory, symlink-to-directory, socket, or other non-file, it throws 'caveman-code: not a file: <path>'.

Solutions

  1. Pass the full path to a regular file (e.g. src/index.ts), not a directory.
  2. Use the list/glob tool to enumerate directory contents first, then read individual files.
  3. Resolve symlinks: point the read at the actual file the symlink targets.
  4. Strip trailing slashes or glob patterns from the path before calling read.
  5. If you need directory contents, use the codebase search/list tools instead of read.

Example fix

// before
tool.read({ path: "src" })
// after
tool.read({ path: "src/index.ts" })
Defensive patterns

Strategy: validation

Validate before calling

const st = await fs.promises.stat(path);
if (!st.isFile()) throw new Error(`${path} is not a regular file`);

Type guard

const isRegularFile = (p: string) =>
  fs.existsSync(p) && fs.statSync(p).isFile();

Try / catch

try {
  await read({ path });
} catch (e) {
  if (e.message.startsWith("caveman-code: not a file:")) {
    const st = await fs.promises.stat(path);
    if (st.isDirectory()) console.error(`${path} is a directory — list it first, then read files individually`);
  } else throw e;
}

Prevention

When it happens

Trigger: Invoking the read tool with input.path pointing at a directory (e.g. 'src' or '.'), a device/pipe file, or a symlink resolving to a directory; passing a path without the filename when intending to read every file in a folder.

Common situations: The LLM/agent passes a directory path hoping for a directory listing; a config variable holding a directory root is reused as a read target; a symlink points at a directory after a refactor; trailing-slash or glob-style paths like 'src/*.ts' are supplied.

Related errors


AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20). Data as JSON: /api/errors/9b096beba3a286ad. Report an issue: GitHub.

Appendix: source

Thrown at packages/agent/src/code.ts:242

    containedPath(await workspaceRoot(), candidate);

  const readFileTool = tool({
    name: "read_file",
    description:
      "Read a UTF-8 file from the workspace. Optional offset/limit read a line range. " +
      `Output is capped at ${caps.read_file} bytes.`,
    input: schema.object({
      path: schema.string(),
      offset: schema.optional(schema.integer()),
      limit: schema.optional(schema.integer()),
    }),
    effect: "read",
    result: "inline",
    timeoutMs: READ_TIMEOUT_MS,
    async execute(input) {
      const target = await contained(input.path);
      const info = await stat(target);
      if (!info.isFile()) throw new Error(`caveman-code: not a file: ${input.path}`);
      const content = await readFile(target, "utf8");
      const lines = content.split("\n");
      const offset = Math.max(1, input.offset ?? 1);
      const limit = input.limit === undefined ? lines.length : Math.max(1, input.limit);
      const selected = lines.slice(offset - 1, offset - 1 + limit);
      const numbered = selected
        .map((line, index) => `${offset + index}\t${line}`)
        .join("\n");
      const text = capOutput(numbered, caps.read_file);
      record(`read_file:${input.path}`, text);
      return text;
    },
  });

  const grepTool = tool({
    name: "grep",
    description:
      "Search the workspace for a regular expression with ripgrep (grep fallback). " +

View on GitHub (pinned to 3ee70a1026)