Skip to content

fix: Starlark rules generated with multiline string cause parse error #250

Description

@ningjiabing

Bug Description

When clicking "Always Allow" in CodeIsland for a Codex command that contains multiline content (e.g. python3 -c with inline Python code), the generated Starlark rule file contains raw newline characters inside a string literal, causing a parse error.

Error

Error loading rules:
/Users/ningjiabing/.codex/rules/codeisland.rules:111: starlark error: error: Parse error: unfinished string literal (problem is on or around line 111)

Reproduction

  1. Use Codex to run a multiline command like: python3 -c "import json\nd=json.load(...)"
  2. Click "Always Allow" in CodeIsland for this command
  3. CodeIsland writes the raw multiline string into ~/.codex/rules/codeisland.rules
  4. Starlark parser fails with unfinished string literal

Generated (Broken) Output

prefix_rule(
    pattern = ["python3", "-c", "
import json
d=json.load(open('/tmp/apps.json'))
for a in d.get('apps',[]):
    ...
"],
    decision = "allow",
)

Expected Output

Newlines should be escaped as \n:

prefix_rule(
    pattern = ["python3", "-c", "import json\nd=json.load(open('/tmp/apps.json'))\nfor a in d.get('apps',[]):\n    ...\n"],
    decision = "allow",
)

Fix Suggestion

In the rule generation code, when serializing command arguments to Starlark string literals, escape \n\\n and \r\\r before writing to the .rules file.

Environment

  • macOS arm64 (Apple Silicon, macOS 26)
  • CodeIsland: installed via Homebrew
  • Codex CLI

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