Skip to content

fix(report): clean prompt rendering#78

Merged
wasabeef merged 5 commits into
mainfrom
fix/pr-report-interaction-labels
May 15, 2026
Merged

fix(report): clean prompt rendering#78
wasabeef merged 5 commits into
mainfrom
fix/pr-report-interaction-labels

Conversation

@wasabeef
Copy link
Copy Markdown
Owner

@wasabeef wasabeef commented May 15, 2026

Summary

  • Render PR Report interaction labels outside blockquotes so Prompt / Response stay structural while bodies remain quoted.
  • Strip leading runtime metadata such as <environment_context> before prompt text becomes durable Agent Note data.
  • Apply the same prompt sanitizer to Claude, Codex, Cursor, and Gemini hook events and transcript recovery.
  • Update maintainer docs and rebuild generated CLI bundles.

Release Note Plan

Release note: Clean PR Report prompt rendering and hide injected runtime metadata from newly recorded prompts.

Type of Change

  • Fix
  • Feature
  • Documentation
  • Refactor
  • Test
  • CI / release

Checklist

  • I kept structural changes separate from behavior changes where practical.
  • I added or updated tests for behavior changes.
  • I updated README / docs / website content when user-facing behavior changed.
  • I rebuilt generated bundles when bundled source changed.
  • I ran the relevant checks locally.

Notes for Reviewers

  • Existing git notes are immutable; prompts recorded before this sanitizer may still show injected metadata, but newly recorded notes are cleaned at adapter/transcript ingestion time.
  • Verified with npm run test --workspace packages/pr-report, npm run build --workspace packages/pr-report, npm run build --workspace packages/cli, npm run typecheck --workspace packages/cli, npm run lint --workspace packages/cli, node --import tsx/esm --test src/commands/pr.test.ts, and full npm test --workspace packages/cli.

🧑💬🤖 Agent Note

Total AI Ratio: ████████ 100%
Model: gpt-5.4

Commit AI Ratio Prompts Files
b3755d2 fix(report): render prompt labels outside blockquotes █████ 100% 3 prompt-context.md 🤖, cli.js 👤, index.js 👤, report.test.ts 🤖, report.ts 🤖
6d92cd5 fix(cli): strip runtime metadata from prompts █████ 100% 3 AGENTS.md 🤖, CLAUDE.md 🤖, architecture.md 🤖, cli.js 👤, claude.test.ts 🤖, claude.ts 🤖, codex.test.ts 🤖, codex.ts 🤖, cursor.test.ts 🤖, cursor.ts 🤖, gemini.test.ts 🤖, gemini.ts 🤖, prompt-text.test.ts 🤖, prompt-text.ts 🤖
fbe54f2 fix(cli): harden system prompt filtering █████ 100% 1 cli.js 👤, prompt-text.test.ts 🤖, prompt-text.ts 🤖
80f98f9 fix(cli): preserve prompts after system tags █████ 100% 2 cli.js 👤, prompt-text.test.ts 🤖, prompt-text.ts 🤖
d8ab1b7 test(cli): cover self-closing environment metadata █████ 100% 2 prompt-text.test.ts 🤖
💬 Prompts & Responses (8 shown / 11 total)

b3755d2 fix(report): render prompt labels outside blockquotes

🧑 Prompt

<environment_context>
<current_date>2026-05-15</current_date>
Asia/Tokyo
</environment_context>

今 PR REPORT の出力がこういうフォーマット担ってると思うけど

🧑 Prompt
Claude Agent View の機能について詳細調査してほしい。Agent Note のセッション判断処理に大きな問題がでないかどうか

🤖 Response
Claude Agent View は外部仕様の変化が絡むので、まず公式情報を確認しつつ、こちらの Claude adapter / session 判定 / hook config との接点を洗います。ローカル実装と照らして「壊れる可能性がある箇所」と「今すぐ対策すべきか」を分けて見ます。
公式 docs では Agent View は claude agents / claude --bg / /bg で background sess…

🤖 Response

賛成です。今の形式だと Prompt / Response のラベル自体も引用文の一部に見えるので、少し読みづらいです。

提案の形のほうが自然です。

**🧑 Prompt**
> ...

**🤖 Response**
> ...

理由はシンプルで、Prompt / Response は構造ラベル、本文は引用対象、という役割が分かれるからです。PR Report 上でもラベルが目に入りやすく、長い response も blockquote のままなので本文のまとまりは保てます。

実装するなら PR Report の interaction renderer だけ変更し、Dashboard や git note schema は触らないのがよさそうです。テストは Markdown snapshot / expected output の更新で十分だと思います。

🧑 Prompt

ブランチきって修正

🤖 Response

PR Report の表示だけを変える小さな修正として進めます。まずブランチを切って、renderer と該当テストの場所を確認してから最小差分で直します。
表示生成は packages/pr-report/src/report.tspushBlockquoteSection だけで制御できそうです。ラベル行を引用から外し、本文だけ blockquote にする形へ変更します。
実装に入ります。ラベルを blockquote 外へ出すだけなので schema や prompt selection には触れず、Markdown renderer とその期待値テスト、関連する設計メモの例だけを合わせます。
ラベルを引用外へ出し、テストで「ラベルが > 付きにならない」ことを固定しました。次に PR Report / CLI の build とテストを通します。
pr-reportcli の dist も再生成しました。CLI 側は PR preview が agent-note-pr-report を bundle しているので、今回の表示変更を含めるた…

6d92cd5 fix(cli): strip runtime metadata from prompts

🧑 Prompt

PR まで作成して

🤖 Response

common:pr-create を使って、この branch の差分から PR を作成します。docs/blog/ は未追跡のまま PR に含めず、既に push 済みの fix/pr-report-interaction-labels から main 向けに作ります。
差分は既に commit / push 済みなので、PR 本文だけ整えます。テンプレートがあればそれに合わせ、なければ Summary / Verification の最小構成で作成します。
PR は bug label 付きの Draft で作成します。本文には release note と検証コマンドを入れて、表示変更の範囲が renderer のみだと分かるようにします。
PR #78 を作成しました。最後に PR metadata と working tree を確認して、docs/blog/ 以外の残りがないことを見ます。
PR 作成しました。

#78

状態は Draft、label は `bug…

🧑 Prompt

🧑 Prompt

<environment_context>
<current_date>2026-05-15</current_date>
Asia/Tokyo
</environment_context>

今 PR REPORT の出力がこういうフォーマット担ってると思うけど

🧑 Prompt
Claude Agent View の機能について詳細調査してほしい。Agent Note のセッション判断処理に大きな問題がでないかどうか

🤖 Response
Claude Agent View は外部仕様の変化が絡むので、まず公式情報を確認しつつ、こちらの Claude adapter / session 判定 / hook config との接点を洗います。ローカル実装と照らして「壊れる可能性がある箇所」と「今すぐ対策すべきか」を分けて見ます。
公式 docs では Agent View は claude agents /…

🤖 Response

これはユーザー入力ではなく、この実行環境が会話に付与している システム側の環境メタデータ です。

今回だと、

<environment_context>
  <current_date>2026-05-15</current_date>
  <timezone>Asia/Tokyo</timezone>
</environment_context>

は「現在日付と timezone」を Codex に渡すための補助情報で、あなたが typed prompt として入力したものではありません。Agent Note がそれを prompt 本文として拾ってしまっているなら、かなり微妙です。PR Report に出すべき “user prompt” ではないので、filter 対象にしたほうがよさそうです。

つまり分類としては:

  • ユーザーの意図: 今 PR REPORT の出力が...
  • システム注入メタデータ: <environment_context>...
  • 期待挙動: PR Report / Dashboard の Prompt…

🧑 Prompt

直してほしい

🤖 Response

これは良い発見です。environment_context はユーザー intent ではないので、Agent Note の prompt 正規化/選択前に落とす方向で直します。まずどの adapter 経由で混入しているかと、既存の system-injected prompt filter の場所を確認します。
<environment_context> は実ユーザー入力ではなく、実行環境が先頭に注入したメタ情報なので、記録時点で削るのが正解です。PR 表示だけで隠すのではなく、各 Agent から入ってくる prompt / transcript を共通の sanitizer に通す形で直します。
原因はひとつに絞れました。Agent ごとの adapter が prompt をそのまま保存していて、<system-reminder> 系だけ Claude 固有に落としていました。今回は全 Agent 共通で「先頭に混ざった環境メタ情報だけを剥がし、本来の prompt は残す」方向に寄せます。
修正は adapter の出口ではなく、prompt が durable…

fbe54f2 fix(cli): harden system prompt filtering

🧑 Prompt

⏺ ---
PR #78 レビュー

HEAD: b3755d2
CI: ✅ Test / Lint / PR Report / Dashboard / Website / deploy 全 pass
CodeRabbit: ✅ pass


全体像

2 コミットの focused fix。プロンプト表示まわりの 2 つの独立した問題を修正。

┌─────────┬─────────────┬──────────────────────────────────────────────────────────────────────────┐
│ Commit │ 種別 │ 内容 │
├─────────┼─────────────┼──────────────────────────────────────────────────────────────────────────┤
│…

🤖 Response

レビュー内容はおおむね妥当です。ブロッカーではないですが、<system-reminder/> と tag case の非対称は小さく安全に潰せるので、この PR 上で追加修正しておきます。
軽微指摘 2 件も潰しました。system-reminder 系は self-closing と mixed-case も落とすようにして、既存の「似た名前や文中 mention は残す」境界は維持しています。

80f98f9 fix(cli): preserve prompts after system tags

🧑 Prompt

$coderabbit-review

coderabbit-review /Users/a12622/git/context-history/.codex/skills/coderabbit-review/SKILL.md --- name: coderabbit-review description: Fetch CodeRabbit review feedback for the current PR, classify actionable items, implement fixes, verify them, and resolve only addressed review threads. ---

CodeRabbit Review Workflow

Use this skill when the task asks to address CodeRabbit comments, review CodeRabbit feedback, or resolve CodeRabbit threads.…

🤖 Response

coderabbit-review skill で PR #78 の未解決 CodeRabbit thread を確認します。指摘があれば、実コードを見て「直す / 既に解消 / false positive / 判断保留」に分けて進めます。
CodeRabbit の指摘は valid です。今の regex だと <system-reminder>...</system-reminder>\n実 prompt のような「tag で始まるが全体は standalone ではない」入力まで落とす可能性があるので、standalone system message のみ null にする形へ絞ります。
指摘対応は最小差分で入りました。standalone system tag だけを落とすよう正規表現を end anchor 付きにし、tag + real prompt を保持する regression test も足しています。

d8ab1b7 test(cli): cover self-closing environment metadata

🧑 Prompt

$coderabbit-review

coderabbit-review /Users/a12622/git/context-history/.codex/skills/coderabbit-review/SKILL.md --- name: coderabbit-review description: Fetch CodeRabbit review feedback for the current PR, classify actionable items, implement fixes, verify them, and resolve only addressed review threads. ---

CodeRabbit Review Workflow

Use this skill when the task asks to address CodeRabbit comments, review CodeRabbit feedback, or resolve CodeRabbit threads.…

🤖 Response

coderabbit-review skill で、PR #78 の未解決 CodeRabbit thread を再取得します。前回の追加 push 後に新しい指摘が出ていないかを確認し、未解決なら実コードを見て対応します。
新しい未解決 thread が 1 件あります。内容は test 追加のみの nit で、self-closing <environment_context /> の path が実装済みなのに直接 test されていない、という指摘です。これは妥当なので小さく追加します。

Summary by CodeRabbit

  • New Features

    • Added prompt normalization to strip leading runtime metadata and ignore standalone system-injected prompts across agents and transcript extraction.
  • Style

    • Section labels (Context / Prompt / Response) now render as standalone bold lines with quoted bodies for clearer display.
  • Documentation

    • Updated examples and architecture/hook docs to describe consistent prompt sanitization behavior.
  • Tests

    • Added and expanded tests verifying prompt normalization and non-quoted section label rendering.

Review Change Stack

Move PR Report interaction labels out of the blockquote body so the label remains structural while prompt and response text stay quoted.

Verification: npm run test --workspace packages/pr-report; npm run build --workspace packages/pr-report; npm run build --workspace packages/cli; npm run typecheck --workspace packages/cli; npm run lint --workspace packages/cli; node --import tsx/esm --test src/commands/pr.test.ts (from packages/cli).

Release note: Render PR Report prompt and response labels outside quote blocks for clearer reading.
@wasabeef wasabeef added the bug Something isn't working label May 15, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 15, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: d7c3d8ad-4f7c-43b1-b58c-22411492579d

📥 Commits

Reviewing files that changed from the base of the PR and between 80f98f9 and d8ab1b7.

📒 Files selected for processing (1)
  • packages/cli/src/agents/prompt-text.test.ts

📝 Walkthrough

Walkthrough

Adds a shared prompt normalizer (strip leading <environment_context> blocks, drop system-injected standalone tags), applies it across adapters (Claude, Codex, Gemini, Cursor) for hook events and transcript extraction, updates tests to validate normalization, and documents the sanitizer in AGENTS/CLAUDE/architecture docs.

Changes

Prompt sanitizer & adapter normalization

Layer / File(s) Summary
Normalizer tests
packages/cli/src/agents/prompt-text.test.ts
Adds a Node node:test suite for normalizeUserPromptText that verifies stripping leading <environment_context> blocks (paired and self-closing), returning null for metadata-only or system-injected prompts (including mixed-case/self-closing variants), and preserving tags when they appear inside user text.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 62.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(report): clean prompt rendering' accurately describes the main change: improving how PR Report renders interaction labels and prompt content by removing blockquote formatting from labels while keeping bodies quoted.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/pr-report-interaction-labels

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


Comment @coderabbitai help to get the list of available commands and usage tips.

@wasabeef wasabeef marked this pull request as ready for review May 15, 2026 01:21
Why
Agent runtimes can prepend environment metadata such as <environment_context> to the text reported as a user prompt. That metadata is useful to the model but should not become durable Agent Note data or appear in PR Reports.

User impact
PR Report, Dashboard, show, and why now display the user's actual request without leading runtime metadata while still dropping standalone system-injected messages.

Verification
npm run typecheck --workspace packages/cli
npm run lint --workspace packages/cli
npm run build --workspace packages/cli
npm test --workspace packages/cli

Release note: Hide injected runtime metadata from recorded prompts while preserving the real user request.
@wasabeef wasabeef changed the title fix(report): render prompt labels outside blockquotes fix(report): clean prompt rendering May 15, 2026
Why
Runtime system messages can appear as self-closing or differently cased tags. The prompt sanitizer should treat those as metadata while preserving real prompts that merely mention similar tag names.

User impact
Agent Note avoids recording standalone runtime/system prompts in a few additional edge cases without hiding user-authored prompt text.

Verification
npm run typecheck --workspace packages/cli
npm run lint --workspace packages/cli
npm run build --workspace packages/cli
node --import tsx/esm --test src/agents/prompt-text.test.ts src/agents/claude.test.ts

Release note: skip
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/cli/src/agents/prompt-text.ts`:
- Around line 1-2: The current SYSTEM_PROMPT_TAG_RE matches prompts that start
with a system tag and thus can incorrectly drop legitimate trailing text; update
the pattern so it only matches when the entire normalized prompt is exactly a
standalone injected tag (either a self-closing tag like <task-notification .../>
or a paired tag like <task-notification ...>...</task-notification>) by
anchoring the regex to the start and end and allowing optional whitespace and an
optional matching closing tag; modify the constant SYSTEM_PROMPT_TAG_RE
accordingly and ensure it still ignores case and permits attributes.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 7b65e14c-30bf-496b-9e64-80afbdd277e1

📥 Commits

Reviewing files that changed from the base of the PR and between 6d92cd5 and fbe54f2.

⛔ Files ignored due to path filters (1)
  • packages/cli/dist/cli.js is excluded by !**/dist/**, !**/dist/**
📒 Files selected for processing (2)
  • packages/cli/src/agents/prompt-text.test.ts
  • packages/cli/src/agents/prompt-text.ts

Comment thread packages/cli/src/agents/prompt-text.ts Outdated
Why
CodeRabbit caught that the system prompt filter matched any prompt starting with a system tag. The intended contract is narrower: only standalone injected tag payloads should be skipped.

User impact
Agent Note no longer drops legitimate user text that follows a system-looking tag, while standalone injected messages are still filtered.

Verification
npm run typecheck --workspace packages/cli
npm run lint --workspace packages/cli
npm run build --workspace packages/cli
node --import tsx/esm --test src/agents/prompt-text.test.ts src/agents/claude.test.ts

Release note: skip
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/cli/src/agents/prompt-text.test.ts`:
- Around line 21-27: Add a new unit test to prompt-text.test.ts that asserts
normalizeUserPromptText returns null when given a leading self-closing
environment context string like "<environment_context />" (or with
whitespace/newline variants) to ensure the sanitizer's self-closing-strip path
is covered; reference the existing test that uses normalizeUserPromptText (the
paired-tag variant) and create a similar it(...) case that passes a self-closing
"<environment_context />" input and expects null, covering the
rescue/false-positive path per docs/engineering.md.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 6415bd11-53f1-45d2-90bb-b372d041c008

📥 Commits

Reviewing files that changed from the base of the PR and between fbe54f2 and 80f98f9.

⛔ Files ignored due to path filters (1)
  • packages/cli/dist/cli.js is excluded by !**/dist/**, !**/dist/**
📒 Files selected for processing (2)
  • packages/cli/src/agents/prompt-text.test.ts
  • packages/cli/src/agents/prompt-text.ts

Comment thread packages/cli/src/agents/prompt-text.test.ts
Why
CodeRabbit noted that the prompt sanitizer had a dedicated self-closing environment_context path without direct test coverage.

User impact
Keeps the prompt sanitizer regression suite explicit for self-closing runtime metadata while leaving behavior unchanged.

Verification
npm run lint --workspace packages/cli
node --import tsx/esm --test src/agents/prompt-text.test.ts

Release note: skip
@wasabeef wasabeef merged commit 0ddf9f5 into main May 15, 2026
11 checks passed
@wasabeef wasabeef deleted the fix/pr-report-interaction-labels branch May 15, 2026 05:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant