<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Robbin Lee on Medium]]></title>
        <description><![CDATA[Stories by Robbin Lee on Medium]]></description>
        <link>https://medium.com/@robbin0919?source=rss-9abd3bed64d2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*e802So43Ecb_8rR4.</url>
            <title>Stories by Robbin Lee on Medium</title>
            <link>https://medium.com/@robbin0919?source=rss-9abd3bed64d2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 23:06:46 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@robbin0919/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Gemini CLI 遙測功能設定指南 (新版)]]></title>
            <link>https://robbin0919.medium.com/gemini-cli-%E9%81%99%E6%B8%AC%E5%8A%9F%E8%83%BD%E8%A8%AD%E5%AE%9A%E6%8C%87%E5%8D%97-%E6%96%B0%E7%89%88-ce1ecd944bca?source=rss-9abd3bed64d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/ce1ecd944bca</guid>
            <category><![CDATA[gemini]]></category>
            <category><![CDATA[telemetry]]></category>
            <dc:creator><![CDATA[Robbin Lee]]></dc:creator>
            <pubDate>Sat, 20 Sep 2025 04:08:45 GMT</pubDate>
            <atom:updated>2025-09-20T04:08:45.444Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LKyPduCHF4yLNH1gdAiJXQ.png" /></figure><p>這份文件將說明如何啟用 <strong>Gemini CLI 遙測（telemetry）</strong> 功能，藉此收集並分析 Gemini CLI 的使用情況。</p><p>這項功能屬於 Gemini CLI 的進階應用，能幫助我們更好地了解工具的使用模式。</p><p>件根據 Gemini CLI 最新的官方說明文件進行更新，旨在提供設定遙測 (Telemetry) 功能的現代化指南。舊有的許多環境變數和旗標已被棄用，設定已統一集中到 .gemini/settings.json 檔案中。</p><h3>設定的優先順序</h3><p>Gemini CLI 的設定會依照以下優先順序進行讀取，後者會覆蓋前者：</p><ol><li><strong>預設值 (Defaults)</strong></li><li><strong>使用者設定檔</strong> (~/.gemini/settings.json)</li><li><strong>工作區設定檔</strong> (&lt;workspace&gt;/.gemini/settings.json)</li><li><strong>環境變數 (Environment Variables)</strong></li><li><strong>指令行旗標 (CLI Flags)</strong> — <strong>優先級最高</strong></li></ol><h3>如何設定與啟用</h3><p>主要建議使用 settings.json 檔案進行永久設定，使用指令行旗標進行臨時性的覆蓋。</p><h3>方法一：使用 settings.json 檔案 (建議)</h3><p>這是最推薦的永久設定方式。您可以在您的使用者主目錄或特定的工作區目錄下找到或建立 .gemini/settings.json 檔案。</p><h4>範例 1：啟用遙測並輸出到檔案</h4><p>這是最簡單的本機檢查方式。遙測數據會以 JSON Lines 格式寫入指定檔案。</p><pre>{<br>  &quot;gemini.telemetry.enabled&quot;: true,<br>  &quot;gemini.telemetry.outfile&quot;: &quot;/path/to/your/telemetry.log&quot;<br>}</pre><ul><li>gemini.telemetry.enabled: 設為 true 來啟用遙測。</li><li>gemini.telemetry.outfile: 指定一個絕對路徑來存放遙測日誌。</li></ul><h4>範例 2：啟用遙測並傳送到 OTEL/GCP</h4><p>如果您需要將數據傳送到 OpenTelemetry (OTEL) Collector (例如 Jaeger 或 Google Cloud)，可以進行以下設定。</p><pre>{<br>  &quot;gemini.telemetry.enabled&quot;: true,<br>  &quot;otel.exporter.otlp.endpoint&quot;: &quot;http://localhost:4317&quot;,<br>  &quot;otel.exporter.otlp.protocol&quot;: &quot;grpc&quot;<br>}</pre><ul><li>otel.exporter.otlp.endpoint: 指向您的 OTEL Collector 接收端點。</li><li>otel.exporter.otlp.protocol: 指定傳輸協定，可以是 grpc 或 http/protobuf。</li></ul><h3>方法二：使用指令行旗標 (臨時覆蓋)</h3><p>如果您只想為單次指令啟用或修改遙測設定，可以使用旗標，它的優先級最高。</p><pre># 即使 settings.json 中禁用了遙測，這次執行依然會將遙測數據寫入指定檔案</pre><pre>gemini [YOUR_PROMPT] --telemetry --telemetry-outfile &quot;/tmp/temp_telemetry.log&quot;</pre><h3>執行本地遙測環境 (開發者用)</h3><p>新版 CLI 文件提供了方便的 npm 腳本來快速啟動一個本地的遙測基礎設施，用於開發和測試，這證實了先前文件中的推測。</p><p><strong>注意：</strong> 這些指令是給<strong>開發者</strong>在專案原始碼目錄下使用的，一般使用者<strong>不需要</strong>執行它們。</p><ol><li><strong>啟動本地遙-測管道 (含 Jaeger UI)</strong></li><li>這個指令會使用 Docker 啟動一個 OTEL Collector 和一個 Jaeger 容器，讓您可以在本地的 Web UI (http://localhost:16686) 上視覺化追蹤數據。</li></ol><ul><li>npm run telemetry -- --target=local</li></ul><ol><li><strong>啟動轉發到 Google Cloud 的本地收集器</strong></li><li>這個指令會啟動一個本地的 OTEL Collector，它會接收數據，然後將其轉發到您設定好的 Google Cloud 專案。</li></ol><ul><li>npm run telemetry -- --target=gcp</li></ul><h3>總結</h3><p>新版的 Gemini CLI 大幅簡化了遙測設定流程。對於大多數使用者來說，只需要在 .gemini/settings.json 檔案中加入幾行設定即可完成。開發者也獲得了更便利的本地測試工具。</p><h3>附錄：非開發者如何設定遙測後端 (OTEL/GCP)</h3><p>本章節旨在釐清一個重要觀念：雖然 Gemini CLI 遵循 Issue #6706 的精神簡化了<strong>客戶端（CLI）的設定</strong>，但對於非開發者而言，要架設一個能接收遙測數據的<strong>後端服務（OTEL Collector）</strong>，仍需要一些手動步驟。</p><h3>核心概念：CLI 設定 vs. 後端架設</h3><p>您可以將整個流程拆成兩個獨立的部分來看：</p><h3>1. 設定 Gemini CLI (已簡化)</h3><p>這部分完全符合 Issue #6706 的簡化精神。身為使用者，您唯一需要做的事情就是在 .gemini/settings.json 檔案中告訴 CLI 數據要往哪裡送。這對所有使用者來說都是簡單、一致的。</p><p><strong>範例 </strong><strong>~/.gemini/settings.json：</strong></p><pre>{<br>  &quot;gemini.telemetry.enabled&quot;: true,<br>  &quot;otel.exporter.otlp.endpoint&quot;: &quot;http://localhost:4317&quot;<br>}</pre><h3>2. 架設後端服務 (對非開發者較複雜)</h3><p>Gemini CLI 需要一個正在運行的服務來接收它在 http://localhost:4317 送出的數據。這個服務就是 OTEL Collector。</p><ul><li><strong>開發者</strong>：可以透過專案內建的 npm run telemetry 腳本捷徑來快速啟動此服務。</li><li><strong>非開發者</strong>：由於沒有專案原始碼，無法使用該捷徑。因此，需要採用業界最標準的方式來啟動這個服務，也就是使用 <strong>Docker</strong>。</li></ul><p>接下來的步驟，就是在說明如何手動完成「架設後端服務」這個任務。</p><h3>非開發者手動架設 OTEL Collector 指南</h3><h3>流程概觀</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ozJ-HUy1mVGY9a0NTPwjdA.png" /></figure><p>Google Cloud PlatformOTEL Collector (在 Docker 中執行)Gemini CLI (您在本機執行)Google Cloud PlatformOTEL Collector (在 Docker 中執行)Gemini CLI (您在本機執行)監聽來自 CLI 的數據1. 您設定 settings.json2. 傳送遙測數據 (OTLP)3. 驗證並轉發數據</p><h3>步驟一：準備 GCP 環境與憑證</h3><p>這是讓 Collector 能夠將數據寫入您的 GCP 專案的必要授權步驟。</p><ol><li><strong>啟用 API</strong>：<br>確保您的 GCP 專案已啟用 Cloud Monitoring API 和 Cloud Logging API。</li><li><strong>建立服務帳號</strong>：<br>在 GCP Console 的「IAM &amp; Admin」&gt;「Service Accounts」中建立一個服務帳號。</li><li><strong>授予權限</strong>：<br>授予該服務帳號 Monitoring Metric Writer 和 Logs Writer 這兩個角色。</li><li><strong>下載金鑰</strong>：<br>為該服務帳號建立一個 JSON 金鑰，下載它，並將其放置在您電腦上的一個工作目錄中（例如，重新命名為 gcp-key.json）。</li></ol><h3>步驟二：建立 Collector 設定檔</h3><p>在您存放 gcp-key.json 的同一個工作目錄中，建立一個名為 config.yaml 的檔案。這個檔案是 Collector 的操作說明書。</p><p><strong>config.yaml</strong></p><pre>receivers:<br>  otlp:<br>    protocols:<br>      grpc:<br>        endpoint: 0.0.0.0:4317 # 監聽所有來源的 4317 埠</pre><pre>exporters:<br>  googlecloud:<br>    project: &quot;your-gcp-project-id&quot; # &lt;-- 請替換成您的 GCP 專案 ID<br>    metric:<br>      prefix: &quot;gemini.cli/&quot;</pre><pre>processors:<br>  batch:</pre><pre>service:<br>  pipelines:<br>    metrics:<br>      receivers: [otlp]<br>      processors: [batch]<br>      exporters: [googlecloud]<br>    logs:<br>      receivers: [otlp]<br>      processors: [batch]<br>      exporters: [googlecloud]</pre><p><strong>請務必將 </strong><strong>your-gcp-project-id 替換成您自己的 GCP 專案 ID。</strong></p><h3>步驟三：使用 Docker 執行 OTEL Collector</h3><p>開啟您的終端機，cd 到存放 config.yaml 和 gcp-key.json 的目錄，然後執行以下 Docker 指令來啟動 Collector 容器：</p><pre>docker run -d \<br>  --name otel-collector-gcp \<br>  -v &quot;$(pwd)/config.yaml:/etc/otelcol-contrib/config.yaml&quot; \<br>  -v &quot;$(pwd)/gcp-key.json:/etc/gcp-key.json&quot; \<br>  -e &quot;GOOGLE_APPLICATION_CREDENTIALS=/etc/gcp-key.json&quot; \<br>  -p 4317:4317 \<br>  otel/opentelemetry-collector-contrib</pre><p>此指令會在背景啟動一個名為 otel-collector-gcp 的容器，並將您的設定檔和金鑰掛載進去，同時開放 4317 埠接收數據。</p><h3>步驟四：設定 Gemini CLI</h3><p>這是回到「簡化設定」的最後一步。編輯您的 ~/.gemini/settings.json 檔案，確保它指向您剛啟動的 Collector。</p><p><strong>.gemini/settings.json</strong></p><pre>{<br>  &quot;gemini.telemetry.enabled&quot;: true,<br>  &quot;otel.exporter.otlp.endpoint&quot;: &quot;http://localhost:4317&quot;,<br>  &quot;otel.exporter.otlp.protocol&quot;: &quot;grpc&quot;<br>}</pre><p>完成以上步驟後，您的遙測數據流就會正常運作：從 Gemini CLI 出發，經由您手動架設的 Docker Collector，最終成功進入您的 GCP 專案。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ce1ecd944bca" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[copilot-instructions for Function explanation instructions]]></title>
            <link>https://robbin0919.medium.com/copilot-instructions-for-function-explanation-instructions-1aae60b552c2?source=rss-9abd3bed64d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/1aae60b552c2</guid>
            <dc:creator><![CDATA[Robbin Lee]]></dc:creator>
            <pubDate>Mon, 26 May 2025 17:28:00 GMT</pubDate>
            <atom:updated>2025-05-26T17:30:23.436Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K1iibGy49FUKxXQMFEvmbQ.png" /></figure><p>為更有效地協助程式碼審閱 (Code Review) 並從程式碼中整理相關文件，特別整理了 GitHub Copilot 常用的功能解釋指令集。</p><p><a href="https://github.com/robbin0919/Github_copilot/blob/main/Function_explanation_instructions.md">Github_copilot/Function_explanation_instructions.md at main · robbin0919/Github_copilot</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1aae60b552c2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ubuntu 25.04行列與新酷音中文輸入法安裝]]></title>
            <link>https://robbin0919.medium.com/ubuntu-25-04%E8%A1%8C%E5%88%97%E8%88%87%E6%96%B0%E9%85%B7%E9%9F%B3%E4%B8%AD%E6%96%87%E8%BC%B8%E5%85%A5%E6%B3%95%E5%AE%89%E8%A3%9D-0d62bc593bda?source=rss-9abd3bed64d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/0d62bc593bda</guid>
            <category><![CDATA[ubuntu]]></category>
            <category><![CDATA[ibu]]></category>
            <category><![CDATA[arrays]]></category>
            <category><![CDATA[chewing]]></category>
            <dc:creator><![CDATA[Robbin Lee]]></dc:creator>
            <pubDate>Fri, 23 May 2025 16:48:57 GMT</pubDate>
            <atom:updated>2025-05-24T11:43:44.069Z</atom:updated>
            <content:encoded><![CDATA[<h3>安裝系統</h3><ol><li>最小安裝, 安裝更新, 不安裝第三方套件</li><li>英文</li><li>時區台北</li></ol><p>時區選台北之後，內建語言是很奇怪</p><h3>生成&amp;設定語言成zh_TW</h3><pre>sudo locale-gen zh_TW.UTF-8<br>sudo localectl set-locale LANG=zh_TW.UTF-8</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/787/1*XNqiVsy5nqYo7B3j6464ng.png" /></figure><p>ibus 為預設的輸入法</p><p>內健的行列輸入法，和慣用不同，改加入以下套件。</p><p>點Region &amp; Language，→ Manage installed languages → 彈出Language Support視窗</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*de_6PZ7u0LJqoYMHkKQ9jg.png" /></figure><p>點Region &amp; Language，→ Manage installed languages → 彈出Language Support視窗</p><h3>Language Support內安裝繁體中文語言包</h3><p>若出現這個視窗，點擊Remind Me Later就好。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/703/1*anykvLxA0GNmTTuP_GtBGA.png" /></figure><p><em>點擊</em><em>Details會發現都是英文語系套件，不是我們要的中文套件</em></p><p>點擊下方Install / Remove Languages按鈕 → 彈出Installed Languages視窗</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/504/1*iHjGx_GML7SWafb8i_P1ZA.png" /></figure><p>找到Chinese (traditional)並勾選，按右下角Apply</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/559/1*01EeC_dS5VjdaDk2kI3Y7g.png" /></figure><h3>安裝ibus-行列 輸入法</h3><pre>sudo apt-get install ibus-array<br>#ibus-anthy: 日文輸入法。<br>#ibus-array: 行列輸入法<br>#ibus-chewing: 新酷音輸入法，智慧型形注音輸入法。<br>#ibus-hangul: 韓文輸入法。<br>#ibus-kkc：日文假名漢字轉換輸入法。<br># man ibus<br># man ibus-daemon<br># man ibus-setup</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dJwk3i57MYG9-ZI49sQc_Q.png" /></figure><h3>重啟系統</h3><p>到這裡就可以重新啟動系統</p><h3>請不要改成中文目錄</h3><p>重啟之後Ubuntu會問你是否要改成中文目錄名稱，請務必選不要，避免一些應用程式無法存取</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/663/1*W3GRdV4IXhp9uFJsytSe-w.png" /></figure><h3>新增鍵盤的輸入來源</h3><p>左半選單中點鍵盤→點擊輸入來源下方的+號按鈕→彈跳出加入輸入來源對話方塊</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/978/1*n0s4psIb1QfMCN0jAuvtFQ.png" /></figure><h3>Ubuntu 25.04內建輸入法切換是使用Window + Space做</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*chb5mR3is0UeDh23vZ0gVg.png" /></figure><h3>改輸入法切換快捷鍵</h3><p>點擊下方鍵盤快捷鍵的檢視與自訂快捷鍵按鈕→彈跳鍵盤快捷鍵視窗→點擊輸入</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DYx0aG8TtrqffeqquUneOA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/642/1*3U0b5jDRCi3qIuLcq_JQHA.png" /></figure><p>這裡就可以點擊想要修改的切換輸入法的快捷鍵功能</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/648/1*peqSEsuC-tf3wiC6nDR0UA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0d62bc593bda" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[手動建立 Git 儲存庫過程 — git init的過程]]></title>
            <link>https://robbin0919.medium.com/%E6%89%8B%E5%8B%95%E5%BB%BA%E7%AB%8B-git-%E5%84%B2%E5%AD%98%E5%BA%AB%E9%81%8E%E7%A8%8B-git-init%E7%9A%84%E9%81%8E%E7%A8%8B-04001b5b387e?source=rss-9abd3bed64d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/04001b5b387e</guid>
            <category><![CDATA[manual-git-repo]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[git-init]]></category>
            <dc:creator><![CDATA[Robbin Lee]]></dc:creator>
            <pubDate>Tue, 20 May 2025 16:31:08 GMT</pubDate>
            <atom:updated>2025-05-20T16:31:08.765Z</atom:updated>
            <content:encoded><![CDATA[<h3>手動建立 Git 儲存庫過程 — git init的過程</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CIYOGiN9Osg7YVt_wBMrsA.png" /></figure><h3>#目錄結構說明</h3><pre>~/manual-git-repo/<br>└── .git/<br>    ├── HEAD              # 指向當前分支的參考<br>    ├── config            # 儲存庫特定的配置<br>    ├── description       # 用於 Git Web 的儲存庫描述<br>    ├── hooks/            # 存放各種 Git 腳本<br>    │   └── (各種樣腳本)<br>    ├── objects/          # Git 的物件資料庫<br>    │   ├── info/         # 用於管理物件庫的資訊<br>    │   └── pack/         # 用於存放打包的物件<br>    └── refs/             # 存放參考（分支、標籤等）<br>        ├── heads/        # 儲存本地分支參考<br>        └── tags/         # 儲存標籤參考</pre><h3># 建立專案資料夾</h3><pre>mkdir -p ~/manual_git_demo<br>cd ~/manual_git_demo</pre><h3># 建立 Git 儲存庫結構</h3><pre>mkdir -p .git/objects/info<br>mkdir -p .git/objects/pack<br>mkdir -p .git/refs/heads<br>mkdir -p .git/refs/tags<br>mkdir -p .git/hooks</pre><h3># 建立 HEAD 檔案指向 master 分支</h3><pre>echo &quot;ref: refs/heads/master&quot; &gt; .git/HEAD</pre><h3># 建立 description 檔案</h3><pre>echo &quot;Manual Git Repository&quot; &gt; .git/description</pre><h3># 建立 config 檔案</h3><pre>cat &gt; .git/config &lt;&lt; EOF<br>[core]<br>        repositoryformatversion = 0<br>        filemode = true<br>        bare = false<br>        logallrefupdates = true<br>[user]<br>        name = robbin0919<br>        email = robbin0919@example.com<br>EOF</pre><h3># 創建一個基本的 .gitignore 檔案</h3><pre>echo &quot;.DS_Store&quot; &gt; .gitignore</pre><h3># 建立 description 檔案</h3><pre>echo &quot;Unnamed repository; edit this file &#39;description&#39; to name the repository.&quot; &gt; .git/description</pre><h3>##驗證儲存庫結構</h3><h3>方法 1：使用 Git 本身進行驗證</h3><pre>cd ~/manual-git-repo<br>git status</pre><p>如果結構正確，應該看到類似下面的輸出</p><pre>On branch master<br><br>No commits yet<br><br>nothing to commit (create/copy files and use &quot;git add&quot; to track)</pre><h3>方法 2：使用內建指令，建立README.md提交</h3><p># 建立一個測試檔案</p><pre>echo &quot;# Test Repository&quot; &gt; README.md</pre><p># 將檔案新增到 Git</p><pre>git add README.md</pre><p># 建立提交</p><pre>git commit -m &quot;Initial commit&quot;</pre><p># 檢查是否成功建立提交</p><pre>git log</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=04001b5b387e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[手動建立 Git 儲存庫過程--檔案大小計算]]></title>
            <link>https://robbin0919.medium.com/%E6%89%8B%E5%8B%95%E5%BB%BA%E7%AB%8B-git-%E5%84%B2%E5%AD%98%E5%BA%AB%E9%81%8E%E7%A8%8B-%E6%AA%94%E6%A1%88%E5%A4%A7%E5%B0%8F%E8%A8%88%E7%AE%97-148b35843ae3?source=rss-9abd3bed64d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/148b35843ae3</guid>
            <category><![CDATA[git]]></category>
            <category><![CDATA[git-objects]]></category>
            <dc:creator><![CDATA[Robbin Lee]]></dc:creator>
            <pubDate>Sun, 18 May 2025 08:43:43 GMT</pubDate>
            <atom:updated>2025-05-18T08:43:43.308Z</atom:updated>
            <content:encoded><![CDATA[<p>批次檔方式：</p><pre>@echo off<br>setlocal enabledelayedexpansion<br><br>REM === 獲取當前日期時間 ===<br>for /f &quot;tokens=2 delims==&quot; %%a in (&#39;wmic OS Get LocalDateTime /value&#39;) do set dt=%%a<br>set YEAR=%dt:~0,4%<br>set MONTH=%dt:~4,2%<br>set DAY=%dt:~6,2%<br>set HOUR=%dt:~8,2%<br>set MINUTE=%dt:~10,2%<br>set SECOND=%dt:~12,2%<br>set CURRENT_DATETIME=%YEAR%-%MONTH%-%DAY% %HOUR%:%MINUTE%:%SECOND%<br><br>REM === 檢查參數 ===<br>if &quot;%~1&quot;==&quot;&quot; (<br>    echo 錯誤: 缺少檔案路徑參數！<br>    echo 用法: CalcFileSize.bat [檔案路徑]<br>    echo 範例: CalcFileSize.bat C:\path\to\image.png<br>    exit /b 1<br>)<br><br>REM === 檢查檔案是否存在 ===<br>if not exist &quot;%~1&quot; (<br>    echo 錯誤: 檔案 &quot;%~1&quot; 不存在！<br>    exit /b 2<br>)<br><br>REM === 計算檔案資訊 ===<br>for %%A in (&quot;%~1&quot;) do (<br>    set FILE_PATH=%%~fA<br>    set FILE_NAME=%%~nxA<br>    set FILE_SIZE=%%~zA<br>    set FILE_DATE=%%~tA<br>)<br><br>REM === 建立臨時目錄 ===<br>set TEMP_DIR=%TEMP%\file_size_calc_%RANDOM%<br>mkdir &quot;%TEMP_DIR%&quot; 2&gt;nul<br><br>REM === 使用 set /p 建立 blob header ===<br>set /p=&quot;blob %FILE_SIZE%&quot;&lt;nul&gt; &quot;%TEMP_DIR%\blob_header.bin&quot;<br>echo.&gt;&gt; &quot;%TEMP_DIR%\blob_header.bin&quot;<br><br>REM === 計算 header 檔案大小 ===<br>for %%A in (&quot;%TEMP_DIR%\blob_header.bin&quot;) do set HEADER_SIZE=%%~zA<br><br>REM === 合併 header 與檔案 ===<br>copy /b &quot;%TEMP_DIR%\blob_header.bin&quot;+&quot;%FILE_PATH%&quot; &quot;%TEMP_DIR%\full_blob.bin&quot; &gt; nul<br><br>REM === 計算合併檔案大小 ===<br>for %%A in (&quot;%TEMP_DIR%\full_blob.bin&quot;) do set TOTAL_SIZE=%%~zA<br><br>REM === 顯示檔案信息 ===<br>echo.<br>echo === 檔案資訊 (計算時間: %CURRENT_DATETIME%) ===<br>echo.<br>echo 檔案名稱: %FILE_NAME%<br>echo 檔案路徑: %FILE_PATH%<br>echo 檔案大小: %FILE_SIZE% 字節<br>echo 修改時間: %FILE_DATE%<br>echo.<br><br>REM === 顯示 Git Blob 資訊 ===<br>echo === Git Blob 大小計算結果 ===<br>echo.<br>echo Blob Header: &#39;blob %FILE_SIZE%\0&#39;<br>echo Header 大小: %HEADER_SIZE% 字節<br>echo 完整 Blob 大小: %TOTAL_SIZE% 字節<br>echo 建立者: %USERNAME%<br>echo.<br><br>REM === 確認大小計算正確性 ===<br>set /a EXPECTED_SIZE=%FILE_SIZE% + %HEADER_SIZE%<br>if %TOTAL_SIZE% EQU %EXPECTED_SIZE% (<br>    echo 驗證結果: 成功 - 檔案大小計算正確<br>) else (<br>    echo 驗證結果: 失敗 - 大小不一致！<br>    echo   預期總大小: %EXPECTED_SIZE% 字節<br>    echo   實際總大小: %TOTAL_SIZE% 字節<br>)<br><br>REM === 清理臨時檔案 ===<br>rd /s /q &quot;%TEMP_DIR%&quot; 2&gt;nul<br><br>exit /b 0</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/858/1*Oc7EbwPeVnPZ0EUF20QZiA.png" /></figure><pre>&lt;#<br>.SYNOPSIS<br>    計算檔案大小並模擬 Git Blob 格式的 header 大小計算<br>.DESCRIPTION<br>    此腳本接受一個檔案路徑，然後計算該檔案大小及對應的 Git Blob 格式 header 大小<br>.PARAMETER FilePath<br>    要計算大小的檔案路徑<br>.EXAMPLE<br>    .\Calc-GitBlobSize.ps1 -FilePath C:\path\to\image.png<br>#&gt;<br><br>param (<br>    [Parameter(Mandatory = $true, Position = 0)]<br>    [ValidateScript({Test-Path $_ -PathType Leaf})]<br>    [string]$FilePath<br>)<br><br># 設定當前日期時間（使用 UTC 時間）<br>$currentDateTime = Get-Date -Format &quot;yyyy-MM-dd HH:mm:ss&quot;<br>$currentUTC = (Get-Date).ToUniversalTime().ToString(&quot;yyyy-MM-dd HH:mm:ss&quot;)<br><br># 獲取當前用戶<br>$currentUser = $env:USERNAME<br><br># 獲取檔案資訊<br>$fileInfo = Get-Item -Path $FilePath<br>$fileName = $fileInfo.Name<br>$filePath = $fileInfo.FullName<br>$fileSize = $fileInfo.Length<br>$fileModified = $fileInfo.LastWriteTime<br><br># 建立臨時目錄<br>$tempDir = Join-Path $env:TEMP &quot;git_blob_calc_$([Guid]::NewGuid().ToString(&#39;N&#39;))&quot;<br>New-Item -ItemType Directory -Path $tempDir -Force | Out-Null<br><br># 建立 Git Blob Header<br>$blobHeader = &quot;blob $fileSize&quot; + [char]0<br>$headerPath = Join-Path $tempDir &quot;blob_header.bin&quot;<br>[System.IO.File]::WriteAllBytes($headerPath, [System.Text.Encoding]::UTF8.GetBytes($blobHeader))<br><br># 計算 Header 大小<br>$headerSize = (Get-Item -Path $headerPath).Length<br><br># 合併 Header 與檔案（在 PowerShell 中只算大小，不實際合併）<br>$totalSize = $headerSize + $fileSize<br><br># 顯示檔案資訊<br>Write-Host &quot;`n=== 檔案資訊 (計算時間: $currentDateTime) ===&quot; -ForegroundColor Cyan<br>Write-Host<br>Write-Host &quot;檔案名稱: $fileName&quot;<br>Write-Host &quot;檔案路徑: $filePath&quot;<br>Write-Host &quot;檔案大小: $fileSize 字節&quot;<br>Write-Host &quot;修改時間: $fileModified&quot;<br>Write-Host &quot;本地時間: $currentDateTime&quot;<br>Write-Host &quot;UTC 時間: $currentUTC&quot;<br>Write-Host<br><br># 顯示 Git Blob 資訊<br>Write-Host &quot;=== Git Blob 大小計算結果 ===&quot; -ForegroundColor Cyan<br>Write-Host<br>Write-Host &quot;Blob Header: &#39;blob $fileSize\0&#39;&quot;<br>Write-Host &quot;Header 大小: $headerSize 字節&quot;<br>Write-Host &quot;完整 Blob 大小: $totalSize 字節&quot;<br>Write-Host &quot;建立者: $currentUser&quot;<br>Write-Host<br><br># 實際讀取 Header 檔案以顯示確切內容<br>$headerContent = [System.IO.File]::ReadAllBytes($headerPath)<br>$headerString = [System.Text.Encoding]::UTF8.GetString($headerContent)<br>$headerHex = [BitConverter]::ToString($headerContent).Replace(&quot;-&quot;, &quot; &quot;)<br><br>Write-Host &quot;=== Header 詳細資訊 ===&quot; -ForegroundColor Green<br>Write-Host<br>Write-Host &quot;文字內容: &quot; -NoNewline<br>$headerContent | ForEach-Object {<br>    if ($_ -eq 0) { <br>        Write-Host &quot;\0&quot; -NoNewline -ForegroundColor Yellow<br>    } else {<br>        Write-Host ([char]$_) -NoNewline <br>    }<br>}<br>Write-Host<br>Write-Host &quot;十六進位: $headerHex&quot;<br>Write-Host<br><br># 清理臨時檔案<br>Remove-Item -Path $tempDir -Recurse -Force<br><br># 如果要實際建立完整的 Blob 物件 (可選部分，已注釋)<br>&lt;#<br># 建立完整的 Blob 物件（Header + 檔案內容）<br>$fullBlobPath = Join-Path $tempDir &quot;full_blob.bin&quot;<br>$headerBytes = [System.IO.File]::ReadAllBytes($headerPath)<br>$fileBytes = [System.IO.File]::ReadAllBytes($FilePath)<br>$fullBlob = New-Object byte[] ($headerBytes.Length + $fileBytes.Length)<br>[Array]::Copy($headerBytes, 0, $fullBlob, 0, $headerBytes.Length)<br>[Array]::Copy($fileBytes, 0, $fullBlob, $headerBytes.Length, $fileBytes.Length)<br>[System.IO.File]::WriteAllBytes($fullBlobPath, $fullBlob)<br><br># 計算實際大小並驗證<br>$actualSize = (Get-Item -Path $fullBlobPath).Length<br>if ($actualSize -eq $totalSize) {<br>    Write-Host &quot;驗證結果: 成功 - 檔案大小計算正確&quot; -ForegroundColor Green<br>} else {<br>    Write-Host &quot;驗證結果: 失敗 - 大小不一致！&quot; -ForegroundColor Red<br>    Write-Host &quot;  預期: $totalSize 字節&quot;<br>    Write-Host &quot;  實際: $actualSize 字節&quot;<br>}<br>#&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kIqb9WbSRyvUf5DGS6VTHQ.png" /></figure><p>PowerShell 版本算出來是完整 Blob 大小: 179 bytes<br>批次檔算出來是完整 Blob 大小: 180 bytes</p><h3>差異原因</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/835/1*99R70w2CVSP0bBMh5tfsfQ.png" /></figure><p>這個 1 位元組差異來自於批次檔和 PowerShell 處理 Git Blob Header 的方式不同：</p><h3>PowerShell 詳細資訊可以看到：</h3><ul><li>文字內容：blob 170\0</li><li>十六進位：62 6C 6F 62 20 31 37 30 00</li><li>這正好是 9 個字節</li><li>最後的 00 是真正的空字元 (null terminator)</li><li>這符合 Git 的標準格式：&quot;blob &quot; + filesize + null byte</li></ul><h3>批次檔的近似實現</h3><p>批次檔中，我們看到 Header 大小為 10 字節，這是因為：</p><pre>set /p=&quot;blob 170&quot;&lt;nul&gt; blob_header.bin<br>echo.&gt;&gt; blob_header.bin</pre><ul><li>批次檔無法直接產生 null byte，而是用 echo.&gt;&gt; 來模擬</li><li>在 Windows 中，這會加入 CR+LF (回車+換行，\r\n)，佔用 2 個字節</li><li>但實際上 Git 的標準只需要 1 個 null byte</li></ul><h3>PowerShell 版本的計算更準確：</h3><ul><li>它使用了真正的空字元 (\0)，完全符合 Git 內部格式</li><li>從您的 PowerShell 輸出可以看到十六進位表示法，確認了正確性</li></ul><h3>修正的批次檔版本</h3><pre>@echo off<br>setlocal enabledelayedexpansion<br><br>REM === 獲取當前日期時間 ===<br>for /f &quot;tokens=2 delims==&quot; %%a in (&#39;wmic OS Get LocalDateTime /value&#39;) do set dt=%%a<br>set YEAR=%dt:~0,4%<br>set MONTH=%dt:~4,2%<br>set DAY=%dt:~6,2%<br>set HOUR=%dt:~8,2%<br>set MINUTE=%dt:~10,2%<br>set SECOND=%dt:~12,2%<br>set CURRENT_DATETIME=%YEAR%-%MONTH%-%DAY% %HOUR%:%MINUTE%:%SECOND%<br><br>REM === 檢查參數 ===<br>if &quot;%~1&quot;==&quot;&quot; (<br>    echo 錯誤: 缺少檔案路徑參數！<br>    echo 用法: CalcFileSize.bat [檔案路徑]<br>    echo 範例: CalcFileSize.bat C:\path\to\image.png<br>    exit /b 1<br>)<br><br>REM === 檢查檔案是否存在 ===<br>if not exist &quot;%~1&quot; (<br>    echo 錯誤: 檔案 &quot;%~1&quot; 不存在！<br>    exit /b 2<br>)<br><br>REM === 計算檔案資訊 ===<br>for %%A in (&quot;%~1&quot;) do (<br>    set FILE_PATH=%%~fA<br>    set FILE_NAME=%%~nxA<br>    set FILE_SIZE=%%~zA<br>    set FILE_DATE=%%~tA<br>)<br><br>REM === 建立臨時目錄 ===<br>set TEMP_DIR=%TEMP%\file_size_calc_%RANDOM%<br>mkdir &quot;%TEMP_DIR%&quot; 2&gt;nul<br><br>REM === 使用 PowerShell 生成正確的 blob header 包含真實空字元 ===<br>echo $header = &quot;blob %FILE_SIZE%&quot; + [char]0; &gt; &quot;%TEMP_DIR%\create_header.ps1&quot;<br>echo [System.IO.File]::WriteAllBytes(&quot;%TEMP_DIR%\blob_header.bin&quot;, [System.Text.Encoding]::UTF8.GetBytes($header)); &gt;&gt; &quot;%TEMP_DIR%\create_header.ps1&quot;<br>powershell -ExecutionPolicy Bypass -File &quot;%TEMP_DIR%\create_header.ps1&quot; &gt; nul<br><br>REM === 計算 header 檔案大小 ===<br>for %%A in (&quot;%TEMP_DIR%\blob_header.bin&quot;) do set HEADER_SIZE=%%~zA<br><br>REM === 合併 header 與檔案 ===<br>copy /b &quot;%TEMP_DIR%\blob_header.bin&quot;+&quot;%FILE_PATH%&quot; &quot;%TEMP_DIR%\full_blob.bin&quot; &gt; nul<br><br>REM === 計算合併檔案大小 ===<br>for %%A in (&quot;%TEMP_DIR%\full_blob.bin&quot;) do set TOTAL_SIZE=%%~zA<br><br>REM === 顯示檔案信息 ===<br>echo.<br>echo === 檔案資訊 (計算時間: %CURRENT_DATETIME%) ===<br>echo.<br>echo 檔案名稱: %FILE_NAME%<br>echo 檔案路徑: %FILE_PATH%<br>echo 檔案大小: %FILE_SIZE% 字節<br>echo 修改時間: %FILE_DATE%<br>echo.<br><br>REM === 顯示 Git Blob 資訊 ===<br>echo === Git Blob 大小計算結果 ===<br>echo.<br>echo Blob Header: &#39;blob %FILE_SIZE%\0&#39;<br>echo Header 大小: %HEADER_SIZE% 字節<br>echo 完整 Blob 大小: %TOTAL_SIZE% 字節<br>echo 建立者: %USERNAME%<br>echo.<br><br>REM === 確認大小計算正確性 ===<br>set /a EXPECTED_SIZE=%FILE_SIZE% + %HEADER_SIZE%<br>if %TOTAL_SIZE% EQU %EXPECTED_SIZE% (<br>    echo 驗證結果: 成功 - 檔案大小計算正確<br>) else (<br>    echo 驗證結果: 失敗 - 大小不一致！<br>    echo   預期總大小: %EXPECTED_SIZE% 字節<br>    echo   實際總大小: %TOTAL_SIZE% 字節<br>)<br><br>REM === 顯示 Header 詳細資訊 (從 PowerShell 獲取) ===<br>echo.<br>echo === Header 詳細資訊 ===<br>echo.<br>echo $headerBytes = [System.IO.File]::ReadAllBytes(&quot;%TEMP_DIR%\blob_header.bin&quot;); &gt; &quot;%TEMP_DIR%\read_header.ps1&quot;<br>echo $headerContent = &quot;&quot;; &gt;&gt; &quot;%TEMP_DIR%\read_header.ps1&quot;<br>echo foreach($b in $headerBytes) { if($b -eq 0) { $headerContent += &quot;\0&quot; } else { $headerContent += [char]$b } } &gt;&gt; &quot;%TEMP_DIR%\read_header.ps1&quot;<br>echo $hexContent = [BitConverter]::ToString($headerBytes).Replace(&quot;-&quot;, &quot; &quot;); &gt;&gt; &quot;%TEMP_DIR%\read_header.ps1&quot;<br>echo &quot;文字內容: &quot; + $headerContent; &gt;&gt; &quot;%TEMP_DIR%\read_header.ps1&quot;<br>echo &quot;十六進位: &quot; + $hexContent; &gt;&gt; &quot;%TEMP_DIR%\read_header.ps1&quot;<br>powershell -ExecutionPolicy Bypass -File &quot;%TEMP_DIR%\read_header.ps1&quot;<br><br>REM === 清理臨時檔案 ===<br>rd /s /q &quot;%TEMP_DIR%&quot; 2&gt;nul<br><br>exit /b 0</pre><p>使用 PowerShell 生成正確的 blob header<br>不再使用 set /p 和 echo.&gt;&gt; 組合<br>利用 PowerShell 的能力來生成包含真正 null 字元的二進制檔案</p><h3>Bash script版本</h3><pre>#!/bin/bash<br># Git Blob 大小計算工具 (Windows Git Bash 兼容版)<br># 日期: 2025-05-18<br><br># 檢查命令行參數<br>if [ $# -ne 1 ]; then<br>    echo &quot;用法: $0 &lt;檔案路徑&gt;&quot;<br>    exit 1<br>fi<br><br>FILE_PATH=&quot;$1&quot;<br><br># 檢查檔案是否存在<br>if [ ! -f &quot;$FILE_PATH&quot; ]; then<br>    echo &quot;錯誤: 檔案 &#39;$FILE_PATH&#39; 不存在&quot;<br>    exit 2<br>fi<br><br># 獲取檔案資訊<br>FILE_NAME=$(basename &quot;$FILE_PATH&quot;)<br># 使用wc代替stat，更好的MinGW兼容性<br>FILE_SIZE=$(wc -c &lt; &quot;$FILE_PATH&quot; | tr -d &#39; &#39;)<br>CURRENT_DATETIME=$(date &quot;+%Y-%m-%d %H:%M:%S&quot;)<br>CURRENT_USER=$(whoami)<br><br># 建立臨時目錄<br>TEMP_DIR=$(mktemp -d -p &quot;${TMPDIR:-/tmp}&quot; &quot;git-blob-XXXXXX&quot;)<br><br># 建立 Git Blob header (含 null 字元)<br>printf &quot;blob ${FILE_SIZE}\0&quot; &gt; &quot;$TEMP_DIR/header.bin&quot;<br><br># 計算 header 大小<br>HEADER_SIZE=$(wc -c &lt; &quot;$TEMP_DIR/header.bin&quot; | tr -d &#39; &#39;)<br><br># 合併 header 與檔案內容<br>cat &quot;$TEMP_DIR/header.bin&quot; &quot;$FILE_PATH&quot; &gt; &quot;$TEMP_DIR/full_blob.bin&quot;<br><br># 計算合併後的大小<br>TOTAL_SIZE=$(wc -c &lt; &quot;$TEMP_DIR/full_blob.bin&quot; | tr -d &#39; &#39;)<br><br># 顯示計算結果<br>echo<br>echo &quot;=== Git Blob 大小計算結果 (計算時間: $CURRENT_DATETIME) ===&quot;<br>echo<br>echo &quot;檔案名稱: $FILE_NAME&quot;<br>echo &quot;檔案大小: $FILE_SIZE bytes&quot;<br>echo &quot;Blob Header: &#39;blob ${FILE_SIZE}\0&#39;&quot;<br>echo &quot;Header 大小: $HEADER_SIZE bytes&quot;<br>echo &quot;完整 Blob 大小: $TOTAL_SIZE bytes&quot;<br>echo &quot;建立者: $CURRENT_USER&quot;<br>echo<br><br># 顯示 Header 詳細資訊 (不使用hexdump)<br>echo &quot;=== Header 詳細資訊 ===&quot;<br>echo<br>echo -n &quot;文字內容: &quot;<br># 使用od和tr替代hexdump顯示文字內容<br>od -An -tx1c &quot;$TEMP_DIR/header.bin&quot; | tr -d &#39;\n&#39; | sed &#39;s/  \+/ /g&#39; | sed &#39;s/ $//&#39; | sed &#39;s/\\0/\\0/g&#39; | sed &#39;s/^[ \t]*//&#39;<br>echo<br>echo -n &quot;十六進位: &quot;<br># 使用xxd或od替代hexdump顯示十六進位<br>if command -v xxd &amp;&gt; /dev/null; then<br>    xxd -p &quot;$TEMP_DIR/header.bin&quot; | tr -d &#39;\n&#39; | sed &#39;s/\(..\)/\1 /g&#39; | sed &#39;s/ $//&#39;<br>else<br>    # 如果沒有xxd，使用od<br>    od -An -tx1 &quot;$TEMP_DIR/header.bin&quot; | tr -d &#39;\n&#39; | sed &#39;s/  \+/ /g&#39; | sed &#39;s/ $//&#39; | sed &#39;s/^[ \t]*//&#39;<br>fi<br>echo<br>echo<br># 可選：計算 SHA-1 哈希<br>if command -v sha1sum &amp;&gt; /dev/null; then<br>    echo<br>    echo &quot;=== SHA-1 哈希值 ===&quot;<br>    echo<br>    SHA1=$(sha1sum &quot;$TEMP_DIR/full_blob.bin&quot; | cut -d &#39; &#39; -f 1)<br>    echo &quot;Git Blob SHA-1: $SHA1&quot;<br>fi<br><br># 清理臨時檔案<br>rm -rf &quot;$TEMP_DIR&quot;<br><br>exit 0</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hj96TDQ-F8n4Dqdvg75c5Q.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=148b35843ae3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[Github Copilot]promptFiles 和 instructionsFiles 的區別]]></title>
            <link>https://robbin0919.medium.com/github-copilot-promptfiles-%E5%92%8C-instructionsfiles-%E7%9A%84%E5%8D%80%E5%88%A5-da52deba6d93?source=rss-9abd3bed64d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/da52deba6d93</guid>
            <category><![CDATA[instruction]]></category>
            <category><![CDATA[prompt]]></category>
            <category><![CDATA[github-copilot]]></category>
            <dc:creator><![CDATA[Robbin Lee]]></dc:creator>
            <pubDate>Sun, 11 May 2025 18:18:52 GMT</pubDate>
            <atom:updated>2025-05-12T05:30:16.942Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/994/1*WzZG7gAiw9dw5WsEEmilKw.png" /></figure><h3>提示 (prompts) 與指示 (instructions)</h3><h3>簡單區別</h3><p>■存取目標不同:</p><ul><li>promptFiles 是用來影響 Chat Copilot 的對話風格與回應內容。</li><li>instructionsFiles 是用來指導 Chat Copilot 如何執行具體任務。</li></ul><p>■檔案使用情境不同:</p><ul><li>promptFiles 更偏向於對話生成。</li><li>instructionsFiles 更偏向於操作執行。</li></ul><h3>promptFiles</h3><ul><li>用途: 儲存用於生成回應的提示內容。</li><li>內容: 這些檔案包含針對 Chat Copilot 的具體提示，定義 Chat Copilot 在與使用者互動時的行為或語調。</li><li>目標: 幫助 Chat Copilot 理解如何根據特定情境或需求生成回應。用途: 儲存用於執行特定操作或任務的指示內容。</li></ul><h3>instructionsFiles</h3><ul><li>內容: 這些檔案通常包含指令、操作指南或具體的行為規範，指導 Chat Copilot 如何處理特定類型的請求或任務。</li><li>目標: 幫助 Chat Copilot 在執行任務或操作時更精準地完成用戶需求。</li></ul><p>promptFiles的主要目的是影響 Chat Copilot 在特定場景中的回應風格或行為方向，它們可以用來設計如何與開發者互動，並根據不同的需求調整回答的語氣、內容深度或格式。</p><h3>如何運用 instructionsFiles 與 promptFiles 來指導 Chat Copilot 生成程式碼</h3><p>在生成程式碼的情境中，instructionsFiles 和 promptFiles 可以結合使用，分別發揮以下作用：</p><ul><li>instructionsFiles：定義 Chat Copilot 如何執行任務，提供具體的操作指導，如如何讀取資料庫連線資訊或開啟資料庫連線。</li><li>promptFiles：控制 Chat Copilot 回答的語氣與風格，確保生成的程式碼符合使用者的需求，例如簡潔、專業或詳細解說。</li></ul><p>以下是具體範例，展示如何在 C# 開發環境中使用這兩種類型的文件。</p><h3>instructionsFiles 範例：如何讀取資料庫連線資訊並開啟連線</h3><pre># 指示：C# 資料庫連線指導<br>## 適用情境<br>當使用者要求生成與資料庫連線相關的程式碼時，請依照以下指導。<br><br>## 指導內容<br>1. **讀取資料庫連線資訊**：<br>   - 使用 `appsettings.json` 或環境變數來儲存連線字串。<br>   - 使用 `IConfiguration` 來讀取設定值。<br>2. **開啟資料庫連線**：<br>   - 使用 `SqlConnection` 類別開啟連線。<br>   - 確保使用 `try-catch-finally` 或 `using` 語句來管理連線生命週期。<br>3. **錯誤處理**：<br>   - 捕捉連線失敗的異常，並記錄日誌。<br><br>## 範例<br>以下是一個完整的範例程式碼：<br>```csharp<br>using System;<br>using System.Data.SqlClient;<br>using Microsoft.Extensions.Configuration;<br><br>class Program<br>{<br>    static void Main(string[] args)<br>    {<br>        // 讀取 appsettings.json 中的連線字串<br>        var configuration = new ConfigurationBuilder()<br>            .AddJsonFile(&quot;appsettings.json&quot;)<br>            .Build();<br><br>        string connectionString = configuration.GetConnectionString(&quot;DefaultConnection&quot;);<br><br>        // 開啟資料庫連線<br>        using (SqlConnection connection = new SqlConnection(connectionString))<br>        {<br>            try<br>            {<br>                connection.Open();<br>                Console.WriteLine(&quot;資料庫連線成功！&quot;);<br>            }<br>            catch (SqlException ex)<br>            {<br>                Console.WriteLine($&quot;資料庫連線失敗：{ex.Message}&quot;);<br>            }<br>        }<br>    }<br>}<br>```<br><br>---<br>## **2. `instructionsFiles` 範例：`using` 語句的標準使用**<br><br>````markdown name=.github/instructions/using-statement.md<br># 指示：C# `using` 語句的標準使用<br>## 適用情境<br>當使用者要求處理資源（如資料庫連線、文件流）時，請指導使用 `using` 語句來管理資源的生命週期。<br><br>## 指導內容<br>1. **使用範圍**：<br>   - 適用於任何實現了 `IDisposable` 介面的物件。<br>   - 確保在程式碼執行完畢後自動釋放資源。<br>2. **典型應用場景**：<br>   - 資料庫連線（例如 `SqlConnection`）。<br>   - 檔案流（例如 `FileStream`）。<br>3. **範例**：<br>   - 以下是一個使用 `using` 語句管理資料庫連線的範例：<br>```csharp<br>using (SqlConnection connection = new SqlConnection(connectionString))<br>{<br>    connection.Open();<br>    // 執行資料庫操作<br>}<br>```<br>   - 當 `using` 區塊結束時，`connection` 將自動釋放。</pre><h3>promptFiles 範例：生成簡潔專業的程式碼</h3><pre># 提示：專業程式碼生成<br>## 使用情境<br>當使用者要求生成程式碼時，請以簡潔且專業的方式生成程式碼，並附上必要的註解。<br><br>## 指導內容<br>1. 程式碼應符合 C# 的最佳實踐。<br>2. 添加必要的 XML Documentation 註解。<br>3. 避免提供過多的細節，只需包含核心功能。<br>4. 如果需要，提供簡短的代碼說明。<br><br>## 範例回應格式<br>以下是一個回應範例：<br>```csharp<br>/// &lt;summary&gt;<br>/// 開啟資料庫連線並執行查詢的範例。<br>/// &lt;/summary&gt;<br>/// &lt;param name=&quot;connectionString&quot;&gt;資料庫連線字串。&lt;/param&gt;<br>public void QueryDatabase(string connectionString)<br>{<br>    using (SqlConnection connection = new SqlConnection(connectionString))<br>    {<br>        connection.Open();<br>        // 在這裡執行查詢<br>    }<br>}<br>```</pre><h3>promptFiles 範例：生成包含詳細說明的程式碼</h3><pre># 提示：生成包含詳細說明的程式碼<br>## 使用情境<br>當使用者是初學者，並希望學習程式碼細節時，使用此提示。<br><br>## 指導內容<br>1. 提供詳細的註解，幫助使用者理解每一部分的功能。<br>2. 適當時給出背景知識的簡短解釋。<br>3. 包含錯誤處理和資源管理的完整流程。<br><br>## 範例回應格式<br>以下是一個回應範例：<br>```csharp<br>using System;<br>using System.Data.SqlClient;<br><br>/// &lt;summary&gt;<br>/// 這是一個簡單的資料庫連線範例，展示如何使用 SqlConnection 類別連接到資料庫。<br>/// &lt;/summary&gt;<br>class Program<br>{<br>    static void Main(string[] args)<br>    {<br>        // 資料庫連線字串，通常存放在設定檔或環境變數中<br>        string connectionString = &quot;your_connection_string_here&quot;;<br><br>        // 使用 SqlConnection 類別進行資料庫連線<br>        using (SqlConnection connection = new SqlConnection(connectionString))<br>        {<br>            try<br>            {<br>                // 嘗試開啟連線<br>                connection.Open();<br>                Console.WriteLine(&quot;資料庫連線成功！&quot;);<br>            }<br>            catch (SqlException ex)<br>            {<br>                // 捕捉並處理資料庫連線異常<br>                Console.WriteLine($&quot;資料庫連線失敗：{ex.Message}&quot;);<br>            }<br>        }<br>    }<br>}<br>```</pre><h3>如何運作</h3><p>instructionsFiles 提供具體的技術指導。</p><ul><li>使用者如果詢問如何與資料庫交互，instructionsFiles 會指導 Copilot 提供標準化的程式碼模式（如使用 using 語句、讀取 appsettings.json 的方式）。</li></ul><p>promptFiles 控制語氣和內容風格。</p><ul><li>如果使用者是初學者，promptFiles 會生成詳細解說的程式碼。</li><li>如果使用者需要專業的程式碼，promptFiles 會生成簡潔的高質量程式碼。</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=da52deba6d93" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[撰寫copilot-instructions筆記(1)]]></title>
            <link>https://robbin0919.medium.com/%E6%92%B0%E5%AF%ABcopilot-instructions%E7%AD%86%E8%A8%98-1-3f36fa47015f?source=rss-9abd3bed64d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/3f36fa47015f</guid>
            <category><![CDATA[instruction]]></category>
            <category><![CDATA[github-copilot]]></category>
            <dc:creator><![CDATA[Robbin Lee]]></dc:creator>
            <pubDate>Sat, 10 May 2025 18:00:05 GMT</pubDate>
            <atom:updated>2025-05-10T18:00:05.823Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lT1gaslaz6aowbQZ" /></figure><p>問題：即使在 copilot-instructions-batchscript.md 中明確提到需要設定命令提示字元為 UTF-8 編碼，但產生的程式碼中常常會缺少這個重要步驟。</p><pre>## 實踐建議<br>當使用 GitHub Copilot 或其他工具產生批次檔時：<br>1. **主動提供上下文**：明確告知需要處理中文內容<br>2. **首先要求編碼設定**：先讓工具生成基本框架，包含編碼設定<br>3. **模板化使用**：建立包含正確編碼設定的批次檔模板<br>若注意到產生的代碼缺少編碼設定，請始終手動添加這一關鍵步驟，並且在團隊中宣導其重要性。</pre><p>最近在整理copilot-instructions For batchscript，遇到以上問題，直接匯整：</p><ul><li>不要將instructions當作自動化來使用</li><li>人類自已都不知道怎麼作，AI更不知道</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3f36fa47015f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[copilot-instructions for batchscript]]></title>
            <link>https://robbin0919.medium.com/copilot-instructions-for-batchscript-da5be490cbcb?source=rss-9abd3bed64d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/da5be490cbcb</guid>
            <category><![CDATA[instruction]]></category>
            <category><![CDATA[batch-script]]></category>
            <dc:creator><![CDATA[Robbin Lee]]></dc:creator>
            <pubDate>Fri, 09 May 2025 15:57:36 GMT</pubDate>
            <atom:updated>2025-05-10T04:53:00.387Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r_85nptkTZLLoWHjnga-fA.png" /></figure><p>這陣子使用AI工具撰寫批次檔，經常反覆遇到一些問題，所以整理成instructions，歡迎取用，若有更好的instructions，請幫忙加強。</p><p><a href="https://github.com/robbin0919/Github_copilot/blob/main/copilot-instructions-batchscript.md">Github_copilot/copilot-instructions-batchscript.md at main · robbin0919/Github_copilot</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=da5be490cbcb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Windows 作業系統 中，幾種方法來計算檔案或字串的 SHA-1 哈希值]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://robbin0919.medium.com/windows-%E4%BD%9C%E6%A5%AD%E7%B3%BB%E7%B5%B1-%E4%B8%AD-%E5%B9%BE%E7%A8%AE%E6%96%B9%E6%B3%95%E4%BE%86%E8%A8%88%E7%AE%97%E6%AA%94%E6%A1%88%E6%88%96%E5%AD%97%E4%B8%B2%E7%9A%84-sha-1-%E5%93%88%E5%B8%8C%E5%80%BC-680ce01e9308?source=rss-9abd3bed64d2------2"><img src="https://cdn-images-1.medium.com/max/1146/1*8oWesjkenfyi6TLTIRpzIw.png" width="1146"></a></p><p class="medium-feed-snippet">&#x4F7F;&#x7528; PowerShell</p><p class="medium-feed-link"><a href="https://robbin0919.medium.com/windows-%E4%BD%9C%E6%A5%AD%E7%B3%BB%E7%B5%B1-%E4%B8%AD-%E5%B9%BE%E7%A8%AE%E6%96%B9%E6%B3%95%E4%BE%86%E8%A8%88%E7%AE%97%E6%AA%94%E6%A1%88%E6%88%96%E5%AD%97%E4%B8%B2%E7%9A%84-sha-1-%E5%93%88%E5%B8%8C%E5%80%BC-680ce01e9308?source=rss-9abd3bed64d2------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://robbin0919.medium.com/windows-%E4%BD%9C%E6%A5%AD%E7%B3%BB%E7%B5%B1-%E4%B8%AD-%E5%B9%BE%E7%A8%AE%E6%96%B9%E6%B3%95%E4%BE%86%E8%A8%88%E7%AE%97%E6%AA%94%E6%A1%88%E6%88%96%E5%AD%97%E4%B8%B2%E7%9A%84-sha-1-%E5%93%88%E5%B8%8C%E5%80%BC-680ce01e9308?source=rss-9abd3bed64d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/680ce01e9308</guid>
            <category><![CDATA[hash]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[sha-1]]></category>
            <dc:creator><![CDATA[Robbin Lee]]></dc:creator>
            <pubDate>Thu, 08 May 2025 18:04:46 GMT</pubDate>
            <atom:updated>2025-05-08T18:04:46.245Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[.git 資料夾的基礎結構]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://robbin0919.medium.com/git-%E8%B3%87%E6%96%99%E5%A4%BE%E7%9A%84%E5%9F%BA%E7%A4%8E%E7%B5%90%E6%A7%8B-e07a4eccb166?source=rss-9abd3bed64d2------2"><img src="https://cdn-images-1.medium.com/max/1885/1*HKLUzjQTpm5XJckPRDnUBg.png" width="1885"></a></p><p class="medium-feed-snippet">&#x53C3;&#x8003;&#x6587;&#x4EF6;: https://git-scm.com/book/en/v2</p><p class="medium-feed-link"><a href="https://robbin0919.medium.com/git-%E8%B3%87%E6%96%99%E5%A4%BE%E7%9A%84%E5%9F%BA%E7%A4%8E%E7%B5%90%E6%A7%8B-e07a4eccb166?source=rss-9abd3bed64d2------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://robbin0919.medium.com/git-%E8%B3%87%E6%96%99%E5%A4%BE%E7%9A%84%E5%9F%BA%E7%A4%8E%E7%B5%90%E6%A7%8B-e07a4eccb166?source=rss-9abd3bed64d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/e07a4eccb166</guid>
            <category><![CDATA[git]]></category>
            <category><![CDATA[git-objects]]></category>
            <dc:creator><![CDATA[Robbin Lee]]></dc:creator>
            <pubDate>Sat, 03 May 2025 05:04:59 GMT</pubDate>
            <atom:updated>2025-05-03T05:35:31.522Z</atom:updated>
        </item>
    </channel>
</rss>