跳到正文
DEV Community· Hamza Syed·· 4 小時前AI 評分55

AI 編碼工具中的「上下文」實際上代表甚麼

What 'context' actually means in AI coding tools

AI 導讀

Hamza Syed 將 AI 編碼工具的上下文分為三層:相關程式碼、書面規則,以及已作出的設計決策。規則應精簡、具體並保持更新;需要反覆解釋的決策則記錄曾嘗試的方法、失敗原因和替代方案。提示前可確認工具能否看到相關程式碼和測試、是否掌握書面規則及既定決策;三項齊備時,簡短提示便可依靠上下文發揮作用。

正文

Hamza Syed

Every AI coding tool talks about context, and most explanations stop at "the files it can see". That is only the start.
https://www.notvibescoded.com/articles/what-context-means-ai-coding
Context has three layers. Layer one is the code: the file being edited, the files it imports, the tests that cover it. An assistant that can see the test will write a change that passes it. One that cannot will write a change that looks right and fails it.
Layer two is the rules you have written down. A short context file at the root of the project, naming the exact test command, the exact lint command, the files nobody edits by hand, and the definition of done, is worth more than a hundred extra files in the model's view. Keep it short and specific, and never let it go stale: stale context is worse than no context, because the assistant follows it confidently.
Layer three is the decisions you have already made. Why this library and not that one, why this endpoint returns that shape. An assistant that does not know those decisions will happily reopen them. Document the ones that keep getting reopened, in one paragraph: what was tried, why it failed, what is used instead.
Before you prompt, check three things. Can it see the code and tests the task touches? Does it have your rules in writing? Does it know the decisions that would stop it reopening a settled question? If all three are yes, a short prompt works, because the context is doing the heavy lifting.
The full piece is on NotVibesCoded.
https://www.notvibescoded.com/articles/what-context-means-ai-coding

來源:DEV Community · dev.to