Skip to content

feat: resolve message role from the promptSource field (ADR-009) - #13

Merged
Mapleeeeeeeeeee merged 1 commit into
mainfrom
feat/adr-009-prompt-source
Sep 2, 2026
Merged

feat: resolve message role from the promptSource field (ADR-009)#13
Mapleeeeeeeeeee merged 1 commit into
mainfrom
feat/adr-009-prompt-source

Conversation

@Mapleeeeeeeeeee

Copy link
Copy Markdown
Owner

為什麼

ADR-008 之後 reader 判斷 user 訊息是人打的還是 harness 塞的,全靠比對文字開頭;harness 改一次措辭就漏一批,兩天內補了八種。CLI 從 2.1.165 起在 user entry 寫 promptSource 欄位,直接標明來源。量測 60 天兩層 transcript 11,064 則:五種值全部九成以上啟動一輪;人的來源被字串比對誤判成 harness 是 0 例;有 15 則排程觸發的自然語言 prompt 只有這個欄位抓得到。決策記錄在 docs/adr-009-prompt-source-field.md

改了什麼

  • rawEntrypromptSource,帶到 UserMessage.PromptSource
  • 有帶時決定角色:systemharness:sdkuser (sdk):(context 格式 S:);其餘 → user:
  • 有帶時 CountsAsTurn() 一律 true
  • 字串分類照跑,決定 compact 形式;system 但形狀認不出來的渲染全文標 harness:;人的來源對上 harness 形狀時以欄位為準,整則重置為純文字
  • 沒帶欄位的訊息行為不變;不把「沒帶」當 harness 訊號
  • SKILL.md 輸出行為補 user (sdk): 說明

驗證

  • gofmt / go vet / go test ./... 全綠;新增 parser、turn 政策、角色標籤三層測試,含「人的來源勝過 harness 形狀」與「沒帶欄位行為同前」
  • 真實 session 7f4f1af5(SDK 驅動):[08:49:25] user (sdk):ca1581db 的排程 prompt Check if background task… 渲染為 harness: 全文
  • 回歸:read b11858cf 輸出 md5 改動前後一致(其 8 則 system 全是已認得的 task-notification)

🤖 Generated with Claude Code

https://claude.ai/code/session_01TcvWErnKnuADJsomnZfwFr

Claude Code >= 2.1.165 writes promptSource on user entries. When it
is present it decides the role label: system renders as harness:,
sdk as user (sdk):, typed/queued/suggestion_accepted as user:, and
any value counts as a turn. String classification still runs to pick
the compact form for recognized shapes and remains the only path for
entries without the field. A human source beats a harness-shaped
body; a system source with an unrecognized shape renders in full
under harness:. Absence of the field is not treated as a signal.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TcvWErnKnuADJsomnZfwFr
@Mapleeeeeeeeeee
Mapleeeeeeeeeee merged commit b2468c3 into main Sep 2, 2026
3 checks passed
@Mapleeeeeeeeeee
Mapleeeeeeeeeee deleted the feat/adr-009-prompt-source branch September 2, 2026 10:07
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.

1 participant