anomalyco / anomalyco/opencode

[Bug] apply_patch rejects heredoc wrappers with non-word delimiters

Open
#43,389 0 comments 0 reactions 1 assignee View on GitHub

@kitlangton is already working on this.

Since Aug 19, 2026.

Dominant language
TypeScript
Stars
209k
Forks
27.5k
PR merge metrics
PR metrics pending

Description

Description

apply_patch accepts shell heredoc wrappers only when the delimiter is \w+. A valid wrapper like cat <<'PATCH-1' is parsed as NotApplyPatch, so the patch never reaches apply_patch.

This is a real user-facing failure because shell heredoc delimiters commonly contain - or other non-word characters.

Expected Behavior

A patch wrapped in a valid heredoc delimiter should be extracted and parsed the same way as <<'EOF'.

Current Behavior

The parser only matches apply_patch\s*<<['\"](\w+)['\"], so PATCH-1 is rejected.

Minimal Repro
import { maybeParseApplyPatch } from "./src/patch/index.ts"

const script = String.raw`apply_patch <<'PATCH-1'
*** Begin Patch
*** Add File: x.txt
+ok
*** End Patch
PATCH-1`

console.log(maybeParseApplyPatch(["bash", "-lc", script]).type)
// NotApplyPatch
Root Cause

The heredoc regex in packages/opencode/src/patch/index.ts only allows \w+ delimiters. The core parser uses the same restriction in packages/core/src/patch.ts.

Suggested Fix

Relax the heredoc delimiter pattern to accept non-whitespace delimiter tokens, and add a regression test for a delimiter like PATCH-1.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.