Skip to content

fix(cli): prefix environment_details block with a textual separator - #13131

Open
santhiprakash wants to merge 2 commits into
Kilo-Org:mainfrom
santhiprakash:fix/environment-details-separator
Open

fix(cli): prefix environment_details block with a textual separator#13131
santhiprakash wants to merge 2 commits into
Kilo-Org:mainfrom
santhiprakash:fix/environment-details-separator

Conversation

@santhiprakash

@santhiprakash santhiprakash commented Aug 15, 2026

Copy link
Copy Markdown

Issue

Fixes #13110

Context

The user prompt and the auto-generated <environment_details> block are sent as two separate text content parts in the same user message. When the second part immediately follows a write-tool argument, some OpenAI-compatible providers can interpret the <environment_details> block as a continuation of that argument, leaking it into tool arguments.

The issue already reproduced this leak 6/6 times; prefixing the block with \n\n reduced it to 0/6.

This is a core CLI/provider prompt-construction change, not a visible UI change.

Implementation

  • packages/opencode/src/kilocode/editor-context.ts: prefix the generated <environment_details> block with \n\n so it is clearly separated from the preceding text.
  • packages/opencode/src/provider/transform.ts: use trimStart().startsWith(...) when skipping the trailing block for prompt-cache breakpoint placement, so the detection still matches the new leading whitespace.
  • Added regression tests in packages/opencode/test/kilocode/system-prompt.test.ts and packages/opencode/test/provider/transform.test.ts.

Screenshots / Video

N/A — this is a non-visual CLI/provider change.

How to Test

  • cd packages/opencode && bun run typecheck
  • cd packages/opencode && bun test ./test/kilocode/system-prompt.test.ts
  • cd packages/opencode && bun test ./test/provider/transform.test.ts
  • bun run script/check-opencode-annotations.ts --worktree

All passed locally on this branch. Targeted oxlint on the four changed files reported 0 errors (only pre-existing warnings).

Checklist

  • Issue linked above, or exception explained
  • Tests/verification described
  • Screenshots/video included for visual changes, or marked N/A
  • Changeset considered for user-facing changes
  • I personally reviewed the diff and can explain the changes, including any AI-assisted work.

@@ -0,0 +1,5 @@
---
"kilo-code": patch

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: Changeset targets the wrong package

This PR only changes packages/opencode/ (published as @kilocode/cli), but the changeset bumps "kilo-code" (the VS Code extension package). Comparable CLI-only fixes in this repo (e.g. memory-sse-json.md, trim-inferred-variants.md) use "@kilocode/cli": patch. As written, the CLI package won't get a version bump or release note for this fix. Consider targeting @kilocode/cli (or both packages, if the extension release should also ship the note).

Suggested change
"kilo-code": patch
"@kilocode/cli": patch

Reply with @kilocode-bot fix it to have Kilo Code address this issue.

@kilo-code-bot

kilo-code-bot Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

The previous finding (changeset targeted "kilo-code" instead of "@kilocode/cli") was resolved in the latest commit, which corrects the changeset package to "@kilocode/cli": patch. The incremental diff contains only this changeset fix; no new issues were found.

Files Reviewed (5 files)
  • .changeset/environment-details-separator.md
  • packages/opencode/src/kilocode/editor-context.ts
  • packages/opencode/src/provider/transform.ts
  • packages/opencode/test/kilocode/system-prompt.test.ts
  • packages/opencode/test/provider/transform.test.ts
Previous Review Summary (commit dd2384b)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit dd2384b)

Status: 1 Issue Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0

The core fix is sound: the \n\n prefix in environmentDetails() is matched by the trimStart().startsWith(...) update in the prompt-cache breakpoint logic, and all other <environment_details> consumers (VS Code legacy migration, JetBrains legacy importer) already tolerate leading whitespace via ^\s* regexes. Regression tests cover both sides of the change. The only finding is that the changeset bumps the VS Code extension package (kilo-code) instead of the CLI package (@kilocode/cli) for a CLI-only change.

Issue Details (click to expand)

WARNING

File Line Issue
.changeset/environment-details-separator.md 2 Changeset targets "kilo-code" (VS Code extension) instead of "@kilocode/cli" for a CLI-only fix
Files Reviewed (5 files)
  • .changeset/environment-details-separator.md - 1 issue
  • packages/opencode/src/kilocode/editor-context.ts
  • packages/opencode/src/provider/transform.ts
  • packages/opencode/test/kilocode/system-prompt.test.ts
  • packages/opencode/test/provider/transform.test.ts

Fix these issues in Kilo Cloud


Reviewed by kimi-k3 · Input: 45K · Output: 2.7K · Cached: 201.2K

Review guidance: REVIEW.md from base branch main

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

<environment_details> can leak into tool arguments when sent as adjacent text content part

1 participant