feat: resolve message role from the promptSource field (ADR-009) - #13
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
為什麼
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。改了什麼
rawEntry讀promptSource,帶到UserMessage.PromptSourcesystem→harness:;sdk→user (sdk):(context 格式S:);其餘 →user:CountsAsTurn()一律 truesystem但形狀認不出來的渲染全文標harness:;人的來源對上 harness 形狀時以欄位為準,整則重置為純文字user (sdk):說明驗證
gofmt/go vet/go test ./...全綠;新增 parser、turn 政策、角色標籤三層測試,含「人的來源勝過 harness 形狀」與「沒帶欄位行為同前」7f4f1af5(SDK 驅動):[08:49:25] user (sdk):;ca1581db的排程 promptCheck if background task…渲染為harness:全文read b11858cf輸出 md5 改動前後一致(其 8 則system全是已認得的 task-notification)🤖 Generated with Claude Code
https://claude.ai/code/session_01TcvWErnKnuADJsomnZfwFr