← Financial Cloud Cloud Cloud Club · 建構文章

極點宏觀|Financial Cloud Cloud · 建構文章

Kiro:提示詞庫與深度程式碼說明附錄

系列: Kiro 工作坊

文章: 23

文章
Kiro 工作坊
01 使用 Kiro 建置:他加祿語學習 App 的提示優先產品設計工作坊
Kiro 工作坊
02 使用 Kiro 建置:他加祿語 學習 App 的教育優先開發技巧工作坊
Kiro 工作坊
03 使用 Kiro 建置:他加祿語 學習 App 的深入開發流程工作坊
Kiro 工作坊
04 使用 Kiro 建置:將 他加祿語 學習 App 在地化為中文變體工作坊
Kiro 工作坊
05 使用 Kiro 建置:他加祿語 卡片的文法與發音補強管線工作坊
Kiro 工作坊
06 使用 Kiro 建置:他加祿語 學習 App 中可審查的獨特額外例句工作坊
Kiro 工作坊
07 與 Kiro 同行:晶圓廠工程健康度 Hook 工作坊
Kiro 工作坊
08 與 Kiro 同行:蝕刻製程視窗風險測試自動化工作坊
Kiro 工作坊
09 與 Kiro 同行:黃光微影漂移風險開發工作坊
Kiro 工作坊
10 工程團隊入門 — 日常工廠值班使用 fab spc drift sync portal
Kiro 工作坊
11 工程團隊附錄 — fab spc drift sync portal 的日常工廠值班使用
Kiro 工作坊
12 Kiro:規格驅動工廠軟體的現場工程工作坊
Kiro 工作坊
13 Kiro:實作 Lab — 從零建置具型別的 Factory Risk Portal
Kiro 工作坊
14 Kiro:工程開發人員的提示、程式碼和型別標準手冊
Kiro 工作坊
15 Kiro:為什麼強 React 提示可以防止型別宣告錯誤啟動
Kiro 工作坊
17 與 Kiro 一起建構:建立工廠自動化入口網站 React UI
Kiro 工作坊
18 與 Kiro 一同建構:打造工廠自動化入口網站背後的自動化分析引擎
Kiro 工作坊
19 與 Kiro 一起實作:將 AI 工廠自動化輔助程式新增至工廠自動化入口網站
Kiro 工作坊
21 Kiro:2 小時專業開發人員工作坊指南
Kiro 工作坊
22 Kiro:從零建置 Fab SPC Drift Synchronization Portal
Kiro 工作坊
23 Kiro:提示詞庫與深度程式碼說明附錄
Kiro 工作坊
30 與 Kiro 一同建構:建立工廠自動化入口網站 UI
Kiro 工作坊
31 與 Kiro 一同建構:打造工廠自動化入口網站背後的自動化分析引擎
Kiro 工作坊
32 與 Kiro 一起實作:為工廠自動化入口網站增添 AI 工廠自動化助理
Kiro 工作坊
33 與 Kiro 一起開發:重建 CME Direct 風格的量化損益排行榜 UI
Kiro 工作坊
34 與 Kiro 一起開發:重建損益排行榜背後的量化分析引擎
Kiro 工作坊
35 與 Kiro 一起建構:適用於量化排行榜的 AWS AI 驅動交易台助理
Kiro 工作坊
36 單頁交易平台 SOP
Kiro 工作坊
AgentCore
A1 使用 AgentCore 與 Strands 建構:Gateway MCP 工具織網開發者工作坊
AgentCore
A2 使用 AgentCore 與 Strands 建構:受治理的多 Agent 風險系統開發者工作坊
AgentCore
A3 使用 AgentCore 與 Strands 建構:執行期主權風險代理人開發者工作坊
AgentCore
模擬考場
E1 用 Vibe Coding 打造多語言 AWS 證照模擬試題上線系統
模擬考場
E2 利用 Vibe Coding 開發技巧打造 AWS 證照模擬練習室
模擬考場
E3 打造靜態 AWS 模擬考場背後的練習引擎
模擬考場
Amazon Q
Q1 Amazon Q:ACM 憑證自動更新的CloudShell優先開發人員工作坊
Amazon Q
Tagalog 練習室
T1 為 AWS Manila Community Day 打造 Tagalog 學習 App:提示詞優先的產品設計
Tagalog 練習室
T2 為 AWS Manila Community Day 打造 Tagalog 學習 App,採用教育優先的開發提示
Tagalog 練習室
T3 為 AWS Manila Community Day 打造 Tagalog 學習 App 的開發流程深度解析
Tagalog 練習室
T4 將 Tagalog 學習 App 在 AWS Manila Community Day 情境中在地化為中文版本
Tagalog 練習室
T5 為 AWS Manila Community Day 打造 Tagalog 卡片打造文法與發音補強流程
Tagalog 練習室
T6 為 AWS Manila Community Day 打造 Tagalog 學習 App 的 Extra Examples 更獨特且可審閱
Tagalog 練習室
路線圖
R1 企業級 Data Analytics Roadmap 一百個深度情境題
路線圖
R2 前端開發路線圖:真實企業場景
路線圖
香港 Community Day
C1 伴隨 AWS Community Day 的香港週末:從雲端技術論壇到維港璀璨夜景
香港 Community Day
C2 講者的奢華週末:分享您的 AWS 故事,讓香港成為您的專屬舞台
香港 Community Day
C3 香港七十二小時:AWS Community Day 講者的極致之旅
香港 Community Day
馬尼拉 Community Day
C4 AWS Community Day Manila:一場連結雲端技術、城市文化與真摯友誼的快樂週末
馬尼拉 Community Day
C5 AWS Community Day Manila:雲端建立者在菲律賓感受最幸福的精神
馬尼拉 Community Day
C6 AWS Community Day Manila:在快樂之城建構、打破、重來,並找到歸屬
馬尼拉 Community Day
C7 菲律賓馬尼拉初次造訪建議
馬尼拉 Community Day
菲律賓 × 香港
C8 菲律賓香港資本市場升級
菲律賓 × 香港
回測
B1 使用 Bedrock AgentCore 與 Strands Agents 建立機構級 Amazon 純做多 (Long-Only) 回測代理
純做多 AMZN 代理:AgentCore、Strands 與可稽核的 Backtrader 帳本。
B2 使用 Backtrader、AgentCore 與 Strands Agents 建立具市況感知能力的 Amazon 部位管理
把市況當成部位控制,而不是圖表註解。
B3 使用 Nasdaq、S&P 500、Dow、AgentCore 與 Strands 建立相對於基準的 Amazon 進出場時機系統
相對 Nasdaq、S&P 500 與道瓊來判斷 AMZN 時機。
B4 使用 Bedrock AgentCore、Strands Agents 與 Backtrader 建立受治理的 Amazon 交易歷史工廠(Trade-History Factory)
把回測做成可稽核的交易歷史工廠。
B5 使用 Bedrock AgentCore 與 Strands Agents 建立智慧代理型 (Agentic) Amazon 回測營運模型 [Part 1]
先建立營運模型,再爭論結果。
B6 為 Amazon 擇時與部位管理建立客製化 Cerebro 程式碼說明 [第 2 部分]
先講 Cerebro 引擎,再講圖表。
B7 為 Amazon 策略結果與經驗教訓建立交易員審閱紀錄 [Part 3]
把策略排名寫成交易員審閱紀錄。
B8 使用 AgentCore 與 Strands 建立受治理的 FSI Amazon 部位管理 Playbook [Part 4]
受治理的 FSI Amazon 部位管理手冊。
B9 使用 Amazon Bedrock AgentCore 建立主權風險交易代理,分析殖利率差、FX 避險與債務重新定價
主權風險代理:殖利率差、外匯避險與債務重定價。
B11 建置現代波動率交易與合法泰國復原規劃代理程式:記憶體驅動的 Strands 多代理程式風險防護系統
記憶驅動的 Strands 代理:波動率與泰國復原規劃。
B12 使用 Amazon Bedrock AgentCore Memory 建構空頭跨式部位交易風險治理
空頭跨式部位的交易風險治理。
B13 在 Amazon EKS 上建構生產環境就緒的信用與收益質押 AI 智能體
在 EKS 上跑生產級信用與收益質押代理。
挑戰
01 週末生產力挑戰:Fab SPC 漂移同步入口網站
Fab SPC 漂移審查與建議入口網站。
02 週末生產力挑戰:Quant P&L Commander — AWS 上由 AI 驅動的交易生產力入口網站
AWS 上由 AI 驅動的交易生產力入口網站。
03 週末煩人的任務挑戰:交易台在雲端、鏈上、空中執行摘要
DeskPulse 日常交易執行摘要。
04 週末 Agent 挑戰:上午 6 點交易風險審查
無人值守、以證據為基礎的晨間交易風險簡報。
05 Weekend Creative Challenge: Leadership Card Game
瀏覽器版創意引導卡牌。
06 Full Stack Challenge: Community Day Board App
瀏覽器版活動溝通空間。
領導力卡牌
01 Leadership Card Game: 雲端還沒自動化的最後一項本事:像領導者一樣說話
寫給 建構者的現場隨筆——談語言、勇氣,以及 Leadership Card Game
02 領導力回合的解剖:Leadership Card Game 實際怎麼玩
給 建構者的引導員實地指南——讓演練嵌進真實會議
03 Leadership Card Game: 當機會不再屬於主辦者
寫給 建構者的現場隨筆:權力轉移、多語領導力練習夜,以及走完入口、資源、敘事的職涯弧線
04 週末創意挑戰:Leadership Card Game
一篇建構者手記:願景、架構,以及週末創意挑戰教會我的事
05 從週末挑戰專案到 $1,386 群眾募資:改變你在職場現身方式的領導力練習
一個週末做出的作品,變成 600 張卡的線上領導力練習室,並募到 $1,386。
06 從週末挑戰專案到 $1,386 群眾募資:進入科技產業的第一天路徑
一個週末挑戰如何變成具備 600 張卡、由 AWS 驅動的多語產品,並募到 $1,386?
07 從週末挑戰專案到 $1,386 群眾募資:用轉移機會建立專業品牌
一個週末挑戰把領導想法做成能跑的多語產品,並募到 $1,386。
08 Leadership Card Game — 群眾募資活動
募資目標: HKD 5,000 已募金額: HKD 1,386 距目標還差: HKD 3,614 進度: 28% 創作者: D.C. Dan · L.L. Diana · L.K. Lva 所在地: 日本、香港、新加坡 投資人權益: 即期價值、私密會員卡牌編輯器雲(Private Membership Card…
09 PR/FAQ 01 — Leadership Card Game 面向社群建構者正式推出
「逆向工作法」文件 · 對外新聞稿 + FAQ 產品: Leadership Card Game 受眾: 社群經理、志願組織者、職涯早期建構者
10 PR/FAQ 02 — 企業引導員採用 Leadership Card Game 進行現場領導力演練
「逆向工作法」文件 · 對外新聞稿 + FAQ 產品: Leadership Card Game 受眾: 學習與發展負責人、人員管理者、敏捷教練、企業引導員
10 PR/FAQ 03 — 多語 Leadership Card Game 為建構者擁有權開放全球練習室
「逆向工作法」文件 · 對外新聞稿 + FAQ 產品: Leadership Card Game 受眾: 全球 建構者、雙語社群、跨境產品團隊、開源導師
AWS Builder Center
01 AWS Builder Center、社群精神與 AWS Builder Jacket
霓虹訊號、共享創意,以及為建構者打造的外套。
02 走進 AWS Builder Center:一座能學習、貢獻,也讓人有歸屬感的全球技術平台
一段精彩旅程,不一定從機場開始。
03 AWS Community Builder 的巨大成功
當建構者公開分享,整個社群就會一起前進。
04 AWS Builder Center 的巨大成功
一座為好奇心打造、充滿活力的全球街區。
05 週末走進 AWS Builder Center:從社群靈感到令人難忘的 AWS Builder Jacket
星期五晚上,開始於建構者熟悉的感覺:有一個點子,正卡在問題與可能性之間。

僅供教育工程用途。本內容是軟體架構演練,不屬於製程放行建議。

如何使用本附錄

在工作坊期間,請在 Kiro 中使用這些提示。這些提示刻意寫得具體,因為專業團隊應該提供情境、限制與驗收條件,而不是模糊地提出需求。


提示組 1 — 專案啟動

提示 1.1 — 建立專案骨架

You are helping me build a professional TypeScript workshop project from scratch. Create the minimal Vite project files for a static browser application. Use no frontend framework. Include scripts for dev, build, test, test:watch, and lint. Do not add business logic yet.

這個提示為何有效

  • 它定義角色、技術與範圍。
  • 它阻止過早實作領域邏輯。
  • 它建立日後 hooks 可以呼叫的標準 scripts。

系統設計決策

  • 提示縮小了第一個 Kiro 任務。 新專案很容易擴張出不必要的檔案。只要求骨架的請求提供受控基準,也避免將設定與產品行為混在一起。
  • 不使用框架是一項架構限制。 工作坊重點是 Kiro 的 AI 工程工作流程,而不是元件函式庫的使用。純 TypeScript 讓產生的決策更可見。
  • 標準 scripts 建立穩定合約。 未來的提示、hooks 與文件可以一致參照 npm test、npm run lint 與 npm run build。

提示組 2 — Steering

提示 2.1 — 產生基礎 Steering

Generate workspace steering files for this project. Create product.md, tech.md, structure.md, domain.md, and testing.md. The project is a local advisory-only Fab SPC portal. It must model CD-SEM risk but must never command equipment. Use deterministic TypeScript functions and Vitest tests.

提示 2.2 — 改善 Domain Steering

Review .kiro/steering/domain.md. Add missing terms for SPC blind window, TMG, Mandel Slope, Fleet deviation, Residual 3σ, FDC health-link, APC guard, and yield-loss triage. Keep the language concise and enforce advisory-only behavior.

系統設計決策

  • Steering 提示應明確說明禁止的行為。 對敏感領域的工程工具而言,只描述要建置什麼並不夠。開發人員也必須定義不得產生什麼。
  • 領域詞彙屬於 workspace 記憶。 Kiro 理解這些術語後,後續的 spec、程式碼與測試產生會更一致。這能減少重複解釋,並避免術語漂移。
  • 測試期望應放在 steering 中。 如果及早說明需要決定性函式與 Vitest 覆蓋率,Kiro 更可能產生可測試的結構,而不是高度耦合的 UI 程式碼。

提示組 3 — 建立 Spec

提示 3.1 — 建立 Spec

Create a Kiro spec named fab-spc-portal. The feature is a local browser portal for detecting when routine SPC monitoring frequency is out of sync with actual mass production. Include requirements, system design, data model, risk scoring, UI behavior, accessibility, tests, and implementation tasks.

提示 3.2 — 強化驗收條件

Refine the requirements. Add acceptance criteria for: TMG above UCL, Mandel Slope outside 0.98–1.02, Fleet deviation above 2σ and 3σ, Residual 3σ above 0.18 nm, blind window above six hours, empty search results, and advisory-only safety language.

系統設計決策

  • 第一個提示建立端到端計畫。 Kiro 應將功能理解成一個系統,而不是一堆隨機檔案。需求、設計與任務形成可追溯的交付路徑。
  • 第二個提示強化邊界案例。 初始 AI spec 可能遺漏邊界條件。要求特定閾值與空狀態,讓最終程式碼更容易驗證。
  • Spec 成為可審查的證據。 開發人員可以將產生的實作與 spec 比較,並拒絕偏離的程式碼。對採用 AI 輔助交付的專業團隊而言,這尤其重要。

提示組 4 — 領域邏輯

提示 4.1 — 實作純風險函式

Implement the risk engine as pure TypeScript functions. Inputs are CdSemTool objects. Outputs are RiskAssessment objects with score, level, action, and reasons. Do not read the DOM, localStorage, network, clock, or random values. Keep thresholds centralized.

提示 4.2 — 要求審查風險優先順序

Review the risk engine priority order. Fleet deviation >3σ and Mandel Slope outside 0.98–1.02 should result in HoldReview. TMG above UCL should result in ApcGuard unless a higher-priority hold condition exists. Residual 3σ above limit should result in RunGoldenWafer unless a higher-priority condition exists.

系統設計決策

  • 純函式降低非決定性。 當計算不依賴外部狀態時,Kiro 產生的程式碼更容易信任。開發人員可以有信心地測試、審查與重構領域層。
  • 集中閾值改善可維護性。 散落在 UI 與測試中的閾值會造成未來漂移。單一常數區段讓審查與依圖層擴充更直接。
  • 優先順序審查防止誤導性建議。 一般分數可能掩蓋嚴重條件。明確的優先規則確保安全相關發現優先於較低層級的觀察狀態。

提示組 5 — UI 實作

提示 5.1 — Render 儀表板

Implement the UI rendering layer. Show summary metrics, tool rows, risk score, blind-window age, TMG, slope, Fleet σ, residual 3σ, action button, and reason details. Add search and sort. Keep rendering separate from risk calculations.

提示 5.2 — 無障礙審查

Review the UI for accessibility. Add semantic headings, button labels, sufficient contrast, keyboard-accessible interactions, useful empty states, and readable status text. Do not change domain logic.

系統設計決策

  • UI 使用評估結果,而不是自行計算。 這讓視覺程式碼專注在 render、互動與無障礙功能。業務規則留在領域層。
  • 搜尋與排序會揭示模型品質。 良好的產生 UI 不應只顯示卡片,也應支援操作工作流程。依風險、TMG、斜率與 Fleet 偏差排序,能讓入口網站真正有用。
  • 將無障礙視為實作品質。 開發人員應要求 Kiro 審查語意與互動狀態,再手動檢查結果。無障礙不能成為事後補救。

提示組 6 — 測試

提示 6.1 — 產生測試

Generate Vitest tests for the risk engine. Cover healthy release, TMG ApcGuard, Mandel Slope HoldReview, Fleet deviation HoldReview, residual RunGoldenWafer, blind-window Watch, reason strings, and priority ordering when multiple thresholds are breached.

提示 6.2 — 詢問遺漏案例

Analyze the current risk tests and list missing edge cases. Focus on threshold equality, just-over thresholds, negative inputs, NaN handling, empty series, and action priority conflicts. Do not modify files yet.

系統設計決策

  • 閾值邊界測試是必要的。 Production bug 常在剛好等於限制值時出現。Kiro 應測試相等與剛超過的案例,讓規則解讀明確。
  • 無效資料處理必須刻意決定。 Demo 可以很簡單,但專業開發人員應決定如何處理負值、NaN 或遺漏陣列,而不是讓產生的程式碼意外決定行為。
  • 先分析再修改能改善控制。 先要求 Kiro 列出遺漏測試,為開發人員提供一個在接受產生變更前的審查檢查點。

提示組 7 — Hooks

提示 7.1 — 建立 Command Hook

Create a Kiro workspace hook that runs npm test after saving files under src/domain or tests. Use PostFileSave, a narrow matcher, command action, 60-second timeout, and enabled true.

提示 7.2 — 建立文件 Hook

Create a Kiro agent hook that updates docs/decision-log.md after a spec task is completed. The hook should summarize changed files, decisions made, and follow-up risks. Keep it workspace-local and do not modify source code.

系統設計決策

  • Command hooks 用於決定性檢查。 測試與 linting 有明確的成功或失敗行為,因此自動化安全且可量測。
  • Agent hooks 用於敘事工作。 Decision log 需要摘要與情境。Kiro 的語言能力在這裡很有用,但 hook 應限制在文件範圍。
  • Matcher 保護開發人員生產力。 Hooks 只應在相關檔案變更時觸發。範圍過大的自動化會產生雜訊、拖慢開發並降低信任。

完整程式碼參考 — 領域層

src/domain/types.ts

export type AdvisoryAction =
  | "Release"
  | "Watch"
  | "RunGoldenWafer"
  | "RouteLimit"
  | "ApcGuard"
  | "HoldReview";

export type RiskLevel = "low" | "medium" | "high" | "critical";

export interface CdSemTool {
  id: string;
  layer: string;
  symptom: string;
  blindWindowHours: number;
  tmgNm: number;
  mandelSlope: number;
  fleetDeviationSigma: number;
  residualThreeSigmaNm: number;
  deltaMeanSeries: number[];
}

export interface RiskAssessment {
  toolId: string;
  score: number;
  level: RiskLevel;
  action: AdvisoryAction;
  reasons: string[];
}

說明

商業邏輯: 型別定義入口網站各處使用的領域合約,讓風險輸入與輸出清楚。

程式碼邏輯: AdvisoryAction 與 RiskLevel 是 union type,因此 TypeScript 會拒絕無效字串。介面定義必要欄位。

預期結果: Kiro 產生的模組共享相同資料合約,若欄位漂移,會在型別檢查期間快速失敗。


完整程式碼參考 — 風險引擎

src/domain/risk.ts

import type { AdvisoryAction, CdSemTool, RiskAssessment, RiskLevel } from "./types";

const LIMITS = {
  tmgUclNm: 0.2,
  slopeLow: 0.98,
  slopeHigh: 1.02,
  fleetWatchSigma: 2,
  fleetHoldSigma: 3,
  residualUclNm: 0.18,
  blindWindowWatchHours: 6
};

export function assessTool(tool: CdSemTool): RiskAssessment {
  let score = 0;
  const reasons: string[] = [];

  if (tool.tmgNm > LIMITS.tmgUclNm) {
    score += 30;
    reasons.push("TMG exceeds demo UCL");
  }

  if (tool.mandelSlope < LIMITS.slopeLow || tool.mandelSlope > LIMITS.slopeHigh) {
    score += 25;
    reasons.push("Mandel Slope outside safe range");
  }

  if (tool.fleetDeviationSigma > LIMITS.fleetHoldSigma) {
    score += 35;
    reasons.push("Fleet deviation exceeds hold threshold");
  } else if (tool.fleetDeviationSigma > LIMITS.fleetWatchSigma) {
    score += 20;
    reasons.push("Fleet deviation exceeds watch threshold");
  }

  if (tool.residualThreeSigmaNm > LIMITS.residualUclNm) {
    score += 20;
    reasons.push("Residual 3σ exceeds noise threshold");
  }

  if (tool.blindWindowHours > LIMITS.blindWindowWatchHours) {
    score += 15;
    reasons.push("SPC blind window is stale");
  }

  const normalizedScore = Math.min(score, 100);

  return {
    toolId: tool.id,
    score: normalizedScore,
    level: classifyRisk(normalizedScore),
    action: chooseAction(tool, normalizedScore),
    reasons: reasons.length > 0 ? reasons : ["No threshold breach detected"]
  };
}

export function classifyRisk(score: number): RiskLevel {
  if (score >= 85) return "critical";
  if (score >= 65) return "high";
  if (score >= 35) return "medium";
  return "low";
}

export function chooseAction(tool: CdSemTool, score: number): AdvisoryAction {
  if (tool.fleetDeviationSigma > LIMITS.fleetHoldSigma) return "HoldReview";
  if (tool.mandelSlope < LIMITS.slopeLow || tool.mandelSlope > LIMITS.slopeHigh) return "HoldReview";
  if (tool.tmgNm > LIMITS.tmgUclNm) return "ApcGuard";
  if (tool.residualThreeSigmaNm > LIMITS.residualUclNm) return "RunGoldenWafer";
  if (score >= 65) return "RouteLimit";
  if (score >= 35) return "Watch";
  return "Release";
}

說明

商業邏輯: 此函式將 fab 量測指標轉換為風險嚴重程度與建議動作,並凸顯哪些指標造成判定。

程式碼邏輯: 每個閾值都會增加分數與原因。分數上限為 100。動作選擇使用優先規則,避免嚴重條件被降級。

預期結果: 開發人員可以信任入口網站一致分類已知條件,並解釋機台為何具有風險。


完整程式碼參考 — Hook

.kiro/hooks/test-domain-on-save.json

{
  "version": "v1",
  "hooks": [
    {
      "name": "test-domain-on-save",
      "description": "Run risk tests when domain logic or tests are saved.",
      "trigger": "PostFileSave",
      "matcher": "^(src/domain/.*\\.ts|tests/.*\\.ts)$",
      "action": {
        "type": "command",
        "command": "npm test"
      },
      "timeout": 60,
      "enabled": true
    }
  ]
}

說明

商業邏輯: 領域行為必須保持穩定,因為它會驅動建議動作。

程式碼邏輯: Hook 監看狹窄的路徑樣式,並在儲存後執行決定性的指令。

預期結果: 當變更破壞風險計算時,開發人員會立即得到回饋。


最終 Capstone 提示

Act as a senior technical reviewer. Compare the implementation with the Kiro spec and steering files. Identify gaps in requirements coverage, domain correctness, tests, accessibility, maintainability, and hook safety. Return a prioritized list with recommended fixes. Do not change files.

最終開發人員練習

要求 Kiro 實作其中一項審查建議,但必須先:

  1. 找出它對應的 spec 需求。
  2. 預測哪些檔案應該變更。
  3. 預測應新增或更新哪些測試。
  4. 手動審查產生的 diff。
  5. 執行 hook 觸發的測試指令或手動測試指令。

# 擴充提示詞與程式碼附錄:使用 Kiro 遷移 HTML Demo

本附錄加入以 Fab SPC Drift Synchronization HTML Demo 為基礎的更深入提示模式與程式碼範例。當教導開發人員如何從可運作的瀏覽器 prototype 移轉至模組化、可測試且由 Kiro 建立的專案時,請使用這些提示。

提示組 8 — Demo 匯入與結構化分析

提示 8.1 — 先解釋再變更

Read the HTML demo and explain its architecture before making changes. Group findings into: layout, styling system, data model, risk board behavior, chart rendering, tab state, FDC matrix, runbook rendering, live simulation, and safety boundaries. Then propose target TypeScript modules.

提示 8.2 — 建立遷移任務

Create implementation tasks to migrate the HTML demo into a TypeScript/Vite app. Each task must have input files, output files, acceptance criteria, and test strategy. Preserve visual behavior as much as possible but improve architecture, accessibility, and testability.

系統設計決策

  • 先解釋的提示能降低盲目產生。 Kiro 應在撰寫替代模組之前展示它理解來源 prototype。這能避免意外遺失行為。
  • 遷移任務必須包含測試。 沒有測試就重構可運作的 Demo 是有風險的。每個任務都應指出開發人員如何在擷取行為後驗證它。
  • 提示區分 parity 與改善。 目標不是複製每個實作細節,而是在改善結構、無障礙與安全性的同時保留使用者可見行為。

提示組 9 — 擷取 CSS 設計系統

提示 9.1 — 擷取 CSS Token

Extract the visual design system from the HTML demo into src/styles.css. Preserve the dark factory-portal style, CSS variables, cards, grids, tabs, board rows, metric boxes, responsive breakpoints, and chart styling. Remove unused selectors and group CSS by responsibility.

程式碼範例 — CSS Token 擷取

:root {
  --bg: #061018;
  --panel: #081522;
  --panel2: #0c1f31;
  --line: #28465f;
  --text: #edf6ff;
  --muted: #9fb3c8;
  --cyan: #38bdf8;
  --cyan2: #77c7ff;
  --green: #31c48d;
  --red: #f05252;
  --yellow: #f6c85f;
  --orange: #fb923c;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", Arial, sans-serif;
}

body {
  margin: 0;
  color: var(--text);
  font-family: var(--sans);
  min-height: 100vh;
  background:
    linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    radial-gradient(circle at 8% 0, rgba(56, 189, 248, 0.19), transparent 30%),
    #061018;
  background-size: 32px 32px, 32px 32px, auto, auto;
}

.card,
.panel,
.chart-card,
.metrics {
  border: 1px solid var(--line);
  background: #06111c;
  padding: 14px;
}

說明

商業邏輯: 入口網站的視覺識別傳達工程營運主控台:深色背景、青色/黃色重點、指標卡片與風險色彩。

程式碼邏輯: CSS 變數集中管理色彩與字型決策。共用卡片選取器避免重複撰寫 border、background 與 padding 規則。

預期結果: TypeScript 專案保留 HTML Demo 的深色工廠入口網站風格,同時以可維護的方式組織 CSS。

系統設計決策

  • Design token 保留視覺一致性。 先擷取變數,可以避免 Kiro 產生新元件時發生樣式漂移。
  • 共用選取器減少重複。 原始 Demo 使用重複的 panel/card 模式。將它們分組後,未來更容易加入 UI 區段。
  • Responsive 規則保留在 CSS。 版面配置適應屬於 CSS,而不是 TypeScript。這讓 render 程式碼專注於內容與行為。

提示組 10 — Render 分解

提示 10.1 — 產生 Render 模組

Create src/ui/render.ts that composes the portal sections from smaller render functions. Include renderHeader, renderHero, renderStats, renderTabs, renderRiskBoard, renderFdcMatrix, renderMatchingSection, renderTriageSection, and renderRunbook. Do not put risk calculations inside this file.

程式碼範例 — Render 組合

import type { CdSemTool, FdcHealthLink, RiskAssessment, RunbookStep } from "../domain/types";
import { renderRiskBoard } from "./board";

export interface AppViewModel {
  tools: CdSemTool[];
  assessments: RiskAssessment[];
  fdcHealthLinks: FdcHealthLink[];
  runbookSteps: RunbookStep[];
}

export function renderApp(root: HTMLElement, model: AppViewModel): void {
  root.innerHTML = `
    <main class="page" id="top">
      <section class="shell">
        ${renderHeader()}
        ${renderHero()}
        ${renderStats(model)}
        <section class="content">
          ${renderTabs()}
          ${renderOverview()}
          ${renderRiskBoard(model.tools, model.assessments)}
          ${renderFdcMatrix(model.fdcHealthLinks)}
          ${renderRunbook(model.runbookSteps)}
        </section>
        ${renderFooter()}
      </section>
    </main>
  `;
}

說明

商業邏輯: Render 器組合與 Demo 入口網站相同的高階區段:header、hero、統計資料、分頁、風險看板、FDC、runbook 與頁尾。

程式碼邏輯: renderApp 接收 view model,並將每個區段委派給較小的函式。它不計算風險,也不修改資料。

預期結果: 開發人員可以個別審查、測試與修改各區段,而不必編輯一個大型 HTML 字串。

系統設計決策

  • View model 邊界讓 render 可預測。 Render 器收到所需的全部資料,因此更容易測試,也能避免隱藏的全域相依。
  • 小型 render 函式協助 Kiro 產生可審查的 diff。 如果 FDC matrix 變更,Kiro 應編輯該 render 器,而不是一個巨大頁面函式。
  • 刻意排除領域邏輯。 Render 應顯示決策,而不是做出決策。這讓風險規則可以不設定 DOM 就進行測試。

提示組 11 — 看板資料列與狀態色彩提示

提示 11.1 — Render 看板資料列

Implement renderRiskRow(tool, assessment). It should display rank, tool id, layer, symptom, risk score, blind window, TMG, Mandel Slope, Fleet σ, and action label. Match the HTML demo's color logic: high risk is red, watch is yellow, safe is green/cyan.

程式碼範例 — 狀態色調工具

export type Tone = "pos" | "neg" | "yellow" | "cyan";

export function riskTone(score: number): Tone {
  if (score >= 80) return "neg";
  if (score >= 55) return "yellow";
  return "pos";
}

export function thresholdTone(value: number, limit: number, direction: "above-is-bad" | "below-is-bad"): Tone {
  if (direction === "above-is-bad") {
    return value > limit ? "neg" : "pos";
  }

  return value < limit ? "neg" : "pos";
}

export function slopeTone(slope: number): Tone {
  return slope < 0.98 || slope > 1.02 ? "neg" : "pos";
}

說明

商業邏輯: 工程師需要風險分數、TMG 違反、斜率不匹配、Fleet 偏差與殘差雜訊的視覺嚴重程度提示。

程式碼邏輯: 輔助函式集中管理色彩 class 決策,避免在不同 render 器中重複條件運算式。

預期結果: UI 色彩行為與 HTML Demo 一致,也更容易測試。

系統設計決策

  • Tone 邏輯是 UI 邏輯,而不是領域動作邏輯。 領域決定建議,UI 決定色彩 class。將兩者分離,可避免視覺變更影響業務決策。
  • 命名的輔助程式改善可審查性。 slopeTone() 比重複的 inline 比較更容易理解。Kiro 應產生有表達力的輔助程式名稱。
  • 色彩 class 保留 prototype 風格。 使用 pos、neg、yellow 與 cyan,在模組化程式碼的同時維持與 Demo CSS 的相容性。

提示組 12 — 安全性與 Escaping 提示

提示 12.1 — 新增 HTML Escaping

Review all render functions that interpolate tool id, layer, symptom, FDC descriptions, and runbook text. Add an escapeHtml utility and use it consistently. Keep trusted static SVG structure unchanged.

程式碼範例 — src/ui/escapeHtml.ts

export function escapeHtml(value: string): string {
  return value
    .replaceAll("&", "&amp;")
    .replaceAll("<", "&lt;")
    .replaceAll(">", "&gt;")
    .replaceAll('"', "&quot;")
    .replaceAll("'", "&#039;");
}

說明

商業邏輯: 今天的工作坊資料是靜態的,但未來資料可能來自檔案、API、匯出結果或使用者輸入。顯示的工程文字不應變成可執行標記。

程式碼邏輯: 輔助程式會在字串插入範本前,將 HTML 特殊字元替換為安全的 entity。

預期結果: 即使 tool symptom 與 FDC 文字包含 <、> 或 & 等字元,也會以文字呈現。

系統設計決策

  • 安全改善是讓 Demo 專業化的一部分。 Prototype 可以假設字串可信。開發人員工作坊應示範更安全的預設做法。
  • Escaping 應靠近 render。 領域模組不應知道 HTML。Render 工具應處理 presentation layer 的編碼。
  • 應要求 Kiro 審查 injection 路徑。 AI 產生的範本字串可能意外插入未 escaping 的內容。專門的提示可以捕捉這項風險。

提示組 13 — Kiro 產生的 Commit 計畫

提示 13.1 — 建立以 Commit 為單位的實作計畫

Split the remaining work into commit-sized changes. Each commit should include purpose, files changed, tests to run, and review risks. Keep each commit small enough for a senior developer to review in under ten minutes.

輸出範例

## Commit 1 — Domain contracts and fixtures
Files:
- src/domain/types.ts
- src/data/tools.ts
- src/data/fdc.ts
- src/data/runbook.ts

Tests:
- npm run lint

Review risks:
- Action labels must remain advisory-only.
- Fixture values must match demo intent.

## Commit 2 — Risk engine
Files:
- src/domain/thresholds.ts
- src/domain/risk.ts
- tests/risk.test.ts

Tests:
- npm test
- npm run lint

Review risks:
- Priority order for HoldReview vs ApcGuard.
- Boundary behavior at exact thresholds.

系統設計決策

  • Commit 規劃讓 AI 工作可審查。 大型 AI diff 很難信任。以 Commit 為單位的計畫保留工程紀律。
  • 每個 Commit 都包含測試。 開發人員應確切知道在接受變更前要如何驗證。
  • 明確列出審查風險。 Kiro 可以協助找出需要人類注意的地方,但開發人員仍須對最終決策負責。

額外程式碼範例 — Demo 的閾值常數

export const demoThresholds = {
  tmgUclNm: 0.2,
  slopeLow: 0.98,
  slopeHigh: 1.02,
  fleetWatchSigma: 2,
  fleetHoldSigma: 3,
  residualThreeSigmaUclNm: 0.18,
  siteToSiteDeltaUclNm: 0.3,
  blindWindowWatchHours: 6
} as const;

說明

商業邏輯: 閾值反映 Demo 的決策邊界:TMG UCL、Mandel 斜率安全範圍、Fleet 警告與暫停限制、殘差雜訊限制、Site-to-site 限制與過時盲窗限制。

程式碼邏輯: as const 讓物件唯讀並保留 literal 值,協助 TypeScript 捕捉意外修改。

預期結果: 所有風險邏輯都匯入相同閾值,而不是重複定義數字。


額外程式碼範例 — 以程式碼表示動作優先順序表

import type { AdvisoryAction, CdSemTool } from "./types";
import { demoThresholds } from "./thresholds";

export function choosePriorityAction(tool: CdSemTool, score: number): AdvisoryAction {
  const t = demoThresholds;

  if (tool.fleetDeviationSigma > t.fleetHoldSigma) {
    return "HoldReview";
  }

  if (tool.mandelSlope < t.slopeLow || tool.mandelSlope > t.slopeHigh) {
    return "HoldReview";
  }

  if (tool.tmgNm > t.tmgUclNm) {
    return "ApcGuard";
  }

  if (tool.residualThreeSigmaNm > t.residualThreeSigmaUclNm) {
    return "RunGoldenWafer";
  }

  if (tool.blindWindowHours > t.blindWindowWatchHours) {
    return "RunSpc";
  }

  if (score >= 65) {
    return "RouteLimit";
  }

  if (score >= 35) {
    return "Watch";
  }

  return "Release";
}

說明

商業邏輯: 當多個風險因素同時存在時,入口網站應建議最強的建議動作。Fleet hold 與斜率不匹配代表系統性的量測可信度問題,因此優先級較高。

程式碼邏輯: 函式先評估高優先級閾值違反,再退回以分數為基礎的動作。

預期結果: 同時具有過時 SPC 與斜率不匹配的機台會收到 HoldReview,而不只是 RunSpc 或 Watch。


額外程式碼範例 — 風險原因代碼

export type RiskReasonCode =
  | "TMG_ABOVE_UCL"
  | "SLOPE_OUT_OF_RANGE"
  | "FLEET_SIGMA_WATCH"
  | "FLEET_SIGMA_HOLD"
  | "RESIDUAL_NOISE_HIGH"
  | "BLIND_WINDOW_STALE"
  | "NO_THRESHOLD_BREACH";

export interface RiskReason {
  code: RiskReasonCode;
  message: string;
  evidence: string;
}

說明

商業邏輯: 原因代碼讓建議更容易稽核、測試、翻譯與摘要。

程式碼邏輯: 結構化原因包含穩定的代碼、人類可讀的訊息,以及像 fleetDeviationSigma=3.2 這樣的證據。

預期結果: UI 可以顯示清楚的解釋,而測試則能斷言穩定的原因代碼。


額外提示 — 要求 Kiro 升級原因

Refactor risk reasons from plain strings into structured reason objects with code, message, and evidence. Update tests to assert reason codes. Update UI to display message and evidence. Preserve existing action behavior.

系統設計決策

  • 結構化原因優於純字串。 測試不應依賴精確的句子措辭。代碼提供穩定斷言,而訊息仍可保持對使用者友善。
  • 證據欄位改善可稽核性。 建議應顯示是哪個指標造成它,以及觀察到的值為何。
  • 重構原因是安全的 Kiro 任務。 既有動作行為已經過測試,開發人員可以要求 Kiro 改善可解釋性,而不改變決策。

最終擴充 Capstone 提示

Perform a final migration review. Compare the TypeScript/Vite app to the original HTML demo. Confirm parity for: header, hero, stats, tabs, risk board, sorting, search, detail panels, FDC matrix, matching section, triage section, runbook, SVG charts, responsive layout, and advisory-only safety text. Then identify production-hardening gaps such as data validation, authentication, audit logging, telemetry, model governance, and integration boundaries. Do not modify files.

最終擴充開發人員練習

  1. 要求 Kiro 找出一項遺漏的 parity 項目。
  2. 要求 Kiro 提出修正它的最小程式碼變更。
  3. 預測會變更哪些檔案。
  4. 要求 Kiro 只實作該項變更。
  5. 手動審查 diff。
  6. 執行測試。
  7. 更新 decision log。