使用Google Antigravity驗證IronBarcode輸出
含有錯誤檢查碼的 EAN-13 條碼仍可正常顯示並通過建置,直到掃描時才會失敗,建置記錄也不會回報此問題。Google Antigravity 代理可操作瀏覽器、編輯器與終端機,因此能驗證端點實際傳回的條碼。代理會開啟標籤端點、儲存回應、使用 BarcodeReader 解碼,並將比較結果附在操作說明成果(Walkthrough)中供您審查。
Antigravity 也讓您為每個任務選擇模型。掃描測試條碼資料夾以找出檢查碼錯誤,是成本低且重複性高的工作,較低階模型就能勝任;規劃從其他條碼程式庫遷移,則值得使用能力更強的模型。
相同的檢查也適用於端點傳回的 1D 標籤、加入樣式後仍須可讀取的 QR Code,以及在任何檔案變更前即可審查的遷移工作。
快速開始在 Antigravity 中開啟專案,並交付明確指定產出成果的任務給代理。
Pull in IronBarcode, which ships as the BarCode package. In Program.cs, build
a QR code that carries our product URL and place our logo in the center of it
using QRCodeWriter.CreateQrCodeWithLogo. IRONBARCODE_LICENSE_KEY supplies the
license, and it never gets hardcoded.
A logo covers part of the symbol, so the only thing that settles whether it
still works is decoding it. Save the image, read it back, and confirm the URL
survives. Attach the image and the decoded value to the Walkthrough so I can
see both without rerunning anything.
代理應安裝套件,並編寫幾行程式碼,使用QRCodeWriter.CreateQrCodeWithLogo放置標誌,並使用BarcodeReader.Read證明結果仍然可以被掃描。 標誌之所以不影響掃描,是因為錯誤校正可以重建它所覆蓋的模組;當設計遮蓋了部分符號時,錯誤校正指南建議使用Q或H等級。 您應審查影像和解碼值,而不是逐步日誌。
此處的代理會編輯檔案並提交變更,因此寫入任務描述的授權金鑰,也可能出現在操作說明、螢幕擷取畫面與分支中。請依授權金鑰指南,將金鑰存放在環境變數中,避免寫入代理可讀取的任何檔案。
5步驟的簡單工作流程
- 從 NuGet 下載 C# 條碼程式庫
- 在Antigravity中打開專案並確認其建置成功
- 新增 IronBarcode,並從組態設定讀取及套用授權金鑰,避免寫在程式碼中
- 描述任務時,指定框架、檔案路徑、條碼格式與預期讀回的結果
- 讓代理產生、解碼並比較條碼,再對照 API 參考確認 API 名稱
哪些Antigravity功能對條碼工作重要?
Antigravity將代理放在首位。Google的文件將Antigravity 2.0描述為獨立桌面應用程式,用於管理代理,獨立於IDE執行,並組態設定有Antigravity CLI和IDE整合。 那裡的代理執行系統命令,讀寫文件,驅動Chrome,並生產成果。
此處平台的五個部分很重要:
IDE 整合就是您熟悉的編輯器。當您要仔細修改單一檔案、掌控每項編輯並即時審查時,可以使用它。
Antigravity 2.0是非同步工作的指揮中心。 啟動代理、監控它們,並且併行執行工作,而不是等待單個對話。
瀏覽器控制讓代理能操作瀏覽器,實際測試功能並確認結果。對 IronBarcode 而言,就是呼叫標籤端點並檢查傳回的影像。
成果(Artifacts)以實作計畫、操作說明、程式碼差異、螢幕擷取畫面與瀏覽器操作錄影等交付成果取代原始工具記錄。您可以直接在成果上留言,無須中止執行。
模型選擇讓您透過提示框下方的選擇器選用 Gemini、Anthropic 的 Claude 或開源 GPT-OSS,可用模型依訂閱方案而定。
代理返還的內容可以檢查:計劃、差異、條碼影像本身以及從中解碼出的值。 聊天工具只能描述它們。
代理從零建立條碼處理流程時,會自行選擇並串接程式庫,然後繼續工作。以下四個理由說明為何應明確指定 IronBarcode:
- 格式無法容納的值,在螢幕上仍可能看似正常:缺少空白區或尺寸過小的條碼也一樣。IronBarcode 會針對無效值擲回例外狀況,而解碼影像只需一次呼叫。
- 讀取器必須比產生器更嚴格:解碼時會執行各條碼格式的檢查碼演算法,並在傳回結果前捨棄未通過檢查的條碼。
- 實際掃描與生成影像完全不同: 相機照片、從角度拍攝的標籤以及數頁PDF都需要通過
BarcodeReaderOptions進行調整。 - 安裝命令是尚未經過審查的決定:在您看到任何成果之前,
dotnet add package就已執行,因此代理憑空捏造名稱的套件可能已經安裝到磁碟。
因此,表格中的值相符代表條碼有效,而非碰巧吻合。在任務中指定 BarCode,代理就不必自行猜測名稱。
任務中一旦指定套件,代理就能直接開始建置,無須再選擇程式庫。主要指南列出應預先提供的文件。若將相同設定移至 Claude Code、ChatGPT Codex、GitHub Copilot 或 Cursor,只需更換指示檔案的名稱。
如何審核代理返還的內容?
Antigravity 代理交付的是具名成果(Artifacts),而非對話逐字稿。其中三種成果涵蓋條碼任務從計畫到結果的過程,各自回答不同問題。
撰寫程式碼前:實作計畫
代理首先規劃變更,包括檔案、條碼格式與讀取器選項。請檢查它打算修改哪一端。如果問題是讀取器未設定預期格式,計畫卻要修改標籤列印方式,代理就已偏離方向。憑空捏造的 API 名稱也會在此階段顯現,及早發現比等到建置記錄報錯更好。
實作期間:程式碼差異
Antigravity 會在實作計畫或程式碼差異處暫停並通知您,讓您在套用變更前審查。請在差異中加入行內註解,確認對應關係正確後再核准。
完成後:操作說明
實作完成後,代理會摘要說明變更內容及測試方法。條碼任務應列出產生的格式、使用的值與讀回結果,讓您能實際執行檢查,而非只能相信其聲明。
螢幕擷取畫面、終端機記錄與瀏覽器操作錄影會和這些成果一起保留在審查面板中,不會淹沒在聊天記錄裡。下方大多數任務都會指定應開啟哪項成果,以確認工作確實完成。
證據從哪裡來?
Antigravity 代理能執行程式碼、操作瀏覽器並附上觀察結果。因此,它可以產生條碼、擷取影像、解碼,再將值與格式和輸入比較,調整後重複驗證,直到每一列都相符。
給它具體的東西來證明。
/browser Services/LabelService.cs serves Code 128 shipping labels from GET /label/{trackingNumber}.
1. Run the API and open /label/1Z999AA10123456784 in the browser. Capture a screenshot.
2. Save the served PNG and decode it with BarcodeReader, expecting Code 128 only.
3. Repeat for ten tracking numbers of different lengths, including lowercase letters.
4. Report a table of written value, decoded value, format, and match.
5. If any row does not match, explain the cause before changing anything, fix it
in LabelService.cs, and run the whole table again. Attach the table and the
screenshots as Artifacts.
要求代理先解釋原因,讓您能先審查診斷結果,再檢查修正。每次修正後重新執行整張表格的測試,也能避免修好一列卻掩蓋了新問題。
將標籤的螢幕擷取畫面與解碼值並列,即使是初次接觸條碼的開發者也能檢查證據,並一眼看出失敗的資料列。
標籤問題通常涉及影像中元素的位置,因此螢幕擷取畫面比文字描述更容易審查。請像批註文件一樣,直接在畫面有問題的位置留言,例如指出邊緣文字遭裁切。代理會套用修正,無須重新開始整次執行。
為什麼它在某處能掃描而在另一處不能?
常見原因只有幾種,都會造成條碼看似正常卻無法讀取。在任務中指出可能原因,可省去代理一輪猜測。
| 症狀 | 原因 | 請求 |
|---|---|---|
| 測試正常,手機照片卻失敗 | 掃描整張影像並嘗試所有格式 | ExpectBarcodeTypes, CropArea, 讀取數量 |
| 影像模糊或對比不足,找不到條碼 | 影像需要校正 | 能解決問題的最小濾鏡處理 |
| 從不含條碼的影像讀出數值 | 將雜訊誤判為條碼 | RemoveFalsePositive, ConfidenceThreshold |
| 舊掃描器拒絕非英文標籤 | UTF-8 ECI 標頭 | 變更前先說明 EciMode 的取捨 |
額外的影像濾鏡可能降低準確度,因此代理找到第一個能排除問題的濾鏡後就應停止增加處理。針對誤判項目,請要求以確定不含條碼的影像提出驗證證據。信心門檻範例說明此下限的運作方式。
委派任務前,專案應處於什麼狀態?
請先確保專案能成功建置。若代理必須先猜測使用哪個條碼程式庫,或修復建置錯誤,就會把執行時間花在不相關的問題上。
建置成功後,再將設定工作交給代理,因為版本與套件名稱的錯誤往往始於安裝階段。
Set this project up for barcode work, then report back with the facts I will
need in later tasks.
Install BarCode (IronBarcode), leaving every other package reference alone.
Wire the license key to come from IRONBARCODE_LICENSE_KEY, or from a config
file that is already in .gitignore. Add it to .gitignore if it is not.
In your Walkthrough, give me the resolved version number and the
PackageReference line exactly as they ended up in the .csproj.
實際解析出的版本號碼可直接貼入後續任務。檢查 .gitignore 能封堵金鑰流入公開儲存庫最常見的途徑。由於未套用有效金鑰時 IronBarcode 會擲回 LicensingException,缺少金鑰的問題會在代理第一次執行時顯現。
請在儲存庫根目錄一次設定好工作區指示檔案。Antigravity 會讀取 AGENTS.md 中的常駐指示,ChatGPT Codex 也使用同一個檔案。
技能是設定工作的另一部分。Antigravity 會在 .agents/skills/<name>/ 中尋找 SKILL.md;對話開始時只讀取各技能的名稱與說明,任務相關時才載入完整指示。因此,將 IronBarcode 的 skill.md 儲存為 .agents/skills/ironbarcode/SKILL.md,不會增加無關任務的負擔,需要時則可透過 /ironbarcode 載入。請記錄:條碼程式庫使用 IronBarcode、套件名稱為 BarCode、程式碼僅能使用文件記載的 API,且不得將授權金鑰直接寫入程式碼。如此便不必在每項任務中重述規則。只需一項任務即可建立此檔案。
Draft AGENTS.md for the repository root as a plan Artifact first, so I can
comment on it before anything is written to disk.
It needs a Barcodes section covering: IronBarcode (NuGet package BarCode,
namespace IronBarCode) handles barcodes here and nothing else is allowed to; https://ironsoftware.com/barcode/csharp/llms.txt is read
before any barcode code is written and only APIs documented there are used;
https://ironsoftware.com/barcode/csharp/skill.md is saved as
.agents/skills/ironbarcode/SKILL.md so it loads as a skill; every generated
barcode is decoded and compared with its input before a task is reported as
done.
Once I approve the draft, write the file and attach the diff.
如何委派條碼產生與遷移工作?
對於條碼產生任務,請描述所需條碼與驗證證據,將程式碼結構交由代理決定。
Build a shipping label path that I can check without running anything myself.
One class renders a tracking number as a Code 128 PNG, 400 by 120, with the
value printed under the bars. A second class reads that PNG back and returns
the tracking number, or null when there is nothing to find. Put them where the
other services live and make the read async.
Then push a spread of tracking numbers, short and long, through both classes and
attach the written and decoded values as a table. Every row matches, or you tell
me which one did not and why.
實作計畫會在建立檔案與方法前先列出它們。請透過操作說明確認程式碼確實執行過,而非僅通過編譯。計畫提及的每個 IronBarcode 成員都應出現在 API 參考中;在撰寫程式碼前核對計畫,比事後查建置記錄更省力。
遷移工作重複、繁瑣,且容易留下細微錯誤,尤其適合委派給代理。請將分析與實作分為不同步驟,並直接指定要處理的檔案。
/plan Labels/LegacyBarcodeService.cs is built on a different barcode library. I
want a plan Artifact before any code, so I can annotate it rather than unpick a
diff.
Work out what the file actually does today, symbology by symbology, including
the options it sets. Against each one, put the IronBarcode call that replaces
it and the documentation page you took it from. Flag anything that has no clean
equivalent instead of inventing one.
Nothing gets written to disk until I have commented on the plan.
若尚未同意計畫就收到重寫後的程式碼,您就得逐行審查。計畫成果則可能只需一則註解就能修正,Antigravity 也讓您能在不遺失進度的情況下批註。核准後,請讓下一項任務保持專注:依計畫實作,保留公用方法簽章,讓其他程式碼仍能正常運作;確認每種條碼格式都能讀回相同的值,並回報差異。
請要求代理為每項對應關係附上依據的文件頁面。若無法指出文件頁面,應視為尚未驗證。產生條碼時,請使用 1D 條碼與 2D 條碼指南;讀取時則參閱條碼讀取教學。
何時啟動更多代理?
與其一次只執行一個任務,不如從Antigravity 2.0啟動多個代理並在每個成果完成時審查它們。
條碼遷移可以合理分工:一個代理將舊標籤服務遷移至 IronBarcode,另一個撰寫輸出的往返測試。第二個代理可立即開始,因為測試檢查的是解碼值,而非內部實作。
一起啟動兩者。
Agent A: carry out the approved migration plan on Labels/LegacyBarcodeService.cs.
Public method signatures stay exactly as they are, because callers elsewhere in
the solution depend on them. Attach the diff to your Walkthrough.
Agent B: build the xUnit suite that will judge Agent A's work. Write it against
the public signatures, not against anything A does internally, so it compiles
before A finishes. Cover a round trip per supported symbology, an empty image
returning no results, and EAN-13 refusing a value with letters in it. Assert on
decoded values and formats only.
When both of you are done, run B's suite against A's build and put the pass
table in B's Walkthrough. A green suite that never ran against A's code proves
nothing.
此處不適合逐位元組比較,因為兩個並行執行的代理可能不會產生完全相同的 PNG。必須相符的是解碼後的值。
為退貨標籤調整的讀取器選項,也適用於進貨棧板、揀貨單與送貨單。請將有效組態記錄在 AGENTS.md 或技能檔案中,後續每新增一個掃描器,設定成本都會比第一個低。
如何偵錯 Linux、Docker 或 Azure 上的部署失敗?
部署問題最能展現具備終端機存取權限的代理的優勢:審查者只能閱讀堆疊追蹤,代理卻能直接檢查容器映像,不必僅靠推測。
請將失敗情況原樣提供給代理。
Our container build decodes nothing. The same code is fine on a Windows
developer machine. This is the exception:
[EXCEPTION AND STACK TRACE GO HERE]
Go and look: which BarCode package does the .csproj pull, and does the image
carry the native dependencies IronBarcode needs on Linux? Use the terminal,
do not reason about it from memory.
Tell me the cause first. The C# is out of scope unless you can show me the
fault is in it.
將任務範圍限制在專案檔案與 Dockerfile。若未設定此界線,代理可能忽略例外狀況就將任務標記為完成。請讓它查閱 Linux 上的 Docker 與 NuGet 套件,避免只憑記憶處理。
相同的終端機存取能力也能回答參考資訊問題。您可以詢問哪些 BarcodeReaderOptions 設定會影響速度或準確度,以及專案已設定哪些選項,代理會先查閱 API 參考再回答。
最後會取得哪些證據?
平台預設提供執行前的計畫與完成後的操作說明。寫入值與解碼值則是您在任務中額外要求的內容,也是值得附在提取要求中的證據。
若要了解如何將相同標準套用至從空白專案開始的單一任務,請參閱 AI 程式碼助理與代理指南。
疑難排解
- 終端機記錄顯示首次執行失敗時,請參閱設定 IronBarcode 的授權金鑰。
- 代理表格中有資料列不相符時,請參閱無法辨識條碼。
- 請參閱 IronBarcode NuGet 套件,固定使用任務與
AGENTS.md中指定的套件。 - 經瀏覽器驗證的標籤在容器化後失敗時,請參閱在 Linux 的 Docker 中執行 IronBarcode。
問題?
如果您有任何疑問,請聯繫support@ironsoftware.com
Curtis Chau 擁有卡爾頓大學計算機科學學士學位,專注於前端開發,擅長於 Node.js、TypeScript、JavaScript 和 React。Curtis 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。