本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
內容管理和設定檔
了解設定檔和內容
設定檔可讓您在一組內容之間切換,為 Amazon Q Developer CLI 提供與您和您的系統互動的獨特方式。內容檔案包含 Amazon Q 用來提供更相關且量身打造之回應的開發規則、專案詳細資訊或編碼標準等資訊。
一律會有預設設定檔,其中包含全域內容和工作區內容:
-
全域內容:套用至所有設定檔的檔案
-
工作區內容:目前設定檔的特定檔案
當您新增設定檔時,它們會有自己的唯一工作區內容,可讓您指定讓該設定檔以工作流程和程序獨有的方式運作和互動的檔案格式。
例如,您可以建立:
-
具有infrastructure-as-code「terraform」描述檔
-
具有 Python 編碼標準的「python」設定檔
-
Java 最佳實務的「java」設定檔
透過切換設定檔,您可以快速變更 Amazon Q 用來提供回應的內容,而不必在每次對話中手動指定這些檔案。
管理設定檔
您可以使用 /profile
命令或 /context profile
命令來管理設定檔。
使用 /profile 命令
/profile
命令可讓您在 Amazon Q Developer CLI 中檢視和切換不同的內容描述檔。
當您在沒有引數的情況下執行/profile
命令時,它會顯示可用的設定檔清單:
q chat > /profile Available profiles: * default dev prod staging
星號 (*) 表示目前作用中的設定檔。
若要切換到不同的設定檔,請指定設定檔名稱:
q chat > /profile set dev Switched to profile: dev
管理內容
內容檔案是 Markdown 檔案,其中包含您希望 Amazon Q 在對話期間考慮的資訊。這些可能包括專案需求、編碼標準、開發規則,或任何其他有助於 Amazon Q 提供更相關回應的資訊。
新增內容
您可以使用 /context add
命令將檔案或目錄新增至內容:
q chat > /context add README.md Added 1 path(s) to profile context.
若要將檔案新增至全域內容 (適用於所有設定檔),請使用 --global
旗標:
q chat > /context add --global coding-standards.md Added 1 path(s) to global context.
您也可以使用 glob 模式一次新增多個檔案:
q chat > /context add docs/*.md Added 3 path(s) to profile context.
檢視內容
若要檢視您目前的內容,請使用 /context show
命令:
q chat > /context show Global context: /home/user/coding-standards.md Profile context (terraform): /home/user/terraform-project/README.md /home/user/terraform-project/docs/architecture.md /home/user/terraform-project/docs/best-practices.md
移除內容
若要從內容中移除檔案,請使用 /context rm
命令:
q chat > /context rm docs/architecture.md Removed 1 path(s) from profile context.
若要從全域內容中移除檔案,請使用 --global
旗標:
q chat > /context rm --global coding-standards.md Removed 1 path(s) from global context.
若要清除內容中的所有檔案,請使用 /context clear
命令:
q chat > /context clear Cleared all paths from profile context.
若要清除全域內容,請使用 --global
旗標:
q chat > /context clear --global Cleared all paths from global context.
常用案例
以下是內容描述檔的一些常見使用案例:
使用專案規則
Amazon Q 支援可定義安全準則和限制的專案層級規則。這些規則會在專案.amazonq/rules
目錄中的 Markdown 檔案中定義。
例如,您可以建立規則來指定:
-
Amazon Q 應該避免存取哪些目錄
-
產生程式碼的安全需求
-
編碼標準和最佳實務
您可以使用 /context add
命令將專案規則新增至您的內容:
q chat > /context add .amazonq/rules/*.md Added 3 path(s) to profile context.
您也可以將專案規則新增至全域內容,以將其套用至所有設定檔:
q chat > /context add --global .amazonq/rules/security-standards.md Added 1 path(s) to global context.
如需建立和使用專案規則的詳細資訊,請參閱 IDE 文件中的建立與 Amazon Q Developer 聊天搭配使用的專案規則。
使用多個專案
如果您使用不同需求的多個專案,您可以為每個專案建立設定檔:
q chat > /profile create project-a Created profile: project-a > /context add ./project-a/README.md ./project-a/docs/*.md Added 4 path(s) to profile context. > /profile create project-b Created profile: project-b > /context add ./project-b/README.md ./project-b/docs/*.md Added 3 path(s) to profile context.
然後,您可以在專案之間移動時切換設定檔:
q chat > /profile project-a Switched to profile: project-a
不同的開發角色
您可以為執行的不同角色建立設定檔:
q chat > /profile create backend-dev Created profile: backend-dev > /context add backend-standards.md api-docs/*.md Added 4 path(s) to profile context. > /profile create devops Created profile: devops > /context add infrastructure/*.md deployment-guides/*.md Added 5 path(s) to profile context.