ai-tool-compliance by supercent-io/skills-template
npx skills add https://github.com/supercent-io/skills-template --skill ai-tool-compliancenpx skills add https://github.com/supercent-io/skills-template --skill ai-tool-compliance
| 操作 | 命令 | 描述 |
|---|---|---|
| 项目初始化 | /compliance-init |
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
| 生成 RBAC 矩阵、网关样板代码、日志模式、成本跟踪接口 |
| 快速扫描 | /compliance-scan, /compliance-quick, /quick | 快速检查 P0 关键项(基于代码模式) |
| 全面验证 | /compliance-verify, /compliance-full, /full | 全面验证 11 条 P0 规则 + 计算合规分数 |
| 分数检查 | /compliance-score | 显示当前合规分数(安全/认证/成本/日志记录) |
| 部署门控 | /compliance-gate | 绿色/黄色/红色裁决 + 部署批准/阻止决定 |
| 改进指南 | /compliance-improve, /improve | 针对每个违规项的特定修复建议 + 重新验证循环 |
模式斜杠命令映射如下。
/quick, /compliance-quick -> 快速扫描 (/compliance-scan)/full, /compliance-full -> 全面验证 (/compliance-verify)/improve -> 改进 (/compliance-improve)quick-scan)静态分析代码库,快速识别潜在的 P0 违规。
如何运行:/compliance-scan, /compliance-quick, /quick 或触发关键词 compliance scan, quick scan
功能:
输出:疑似违规列表(文件路径 + 行号 + 规则 ID)
持续时间:1–3 分钟
full-verify)全面验证所有 11 条 P0 规则并计算定量合规分数。
如何运行:/compliance-verify, /compliance-full, /full 或触发关键词 P0 verification, full verify, deploy verification
功能:
输出:合规报告 (compliance-report.md)
## Compliance Report
- Date: 2026-03-03
- Project: my-ai-tool
- Score: 92/100 (Green)
### Rule Results
| Rule ID | Rule Name | Result | Evidence |
|---------|-----------|--------|----------|
| AUTH-P0-001 | Force Guest for New Signups | PASS | signup.ts:45 role='guest' |
| AUTH-P0-002 | Block Guest Menu/API Access | PASS | middleware.ts:12 guestBlock |
| ... | ... | ... | ... |
### Score Breakdown
- Security: 33/40
- Auth: 25/25
- Cost: 17/20
- Logging: 12/15
- Total: 92/100
### Gate Decision: GREEN - Deploy Approved
持续时间:5–15 分钟(因项目大小而异)
improve)为违规项提供具体的修复指南并运行重新验证循环。
如何运行:/compliance-improve, /improve 或触发关键词 compliance improvement, fix violations
功能:
输出:修复建议 + 重新验证结果
/compliance-improve runs
|
1. Load latest verification-run.json
|
2. Extract FAIL items (rule_id + evidence)
|
3. For each FAIL:
|
a. Read violation code from evidence file:line
b. Derive fix direction from rule.remediation + rule.check_pattern.must_contain
c. Generate before/after code diff
d. Apply fix via Write (after user confirmation)
e. Re-verify only that rule (re-run Grep pattern)
f. Confirm transition to PASS
|
4. Full re-verification (/compliance-verify)
|
5. Output Before/After score comparison
|
6. If no remaining FAILs → present guide for introducing P1 recommended requirements
修复应用优先级:
must_not_contain 违规(需要立即移除)→ 删除代码或替换为服务器 API 调用must_contain 未满足(需要添加模式)→ 根据修复指南插入代码基于内部 AI 工具强制性实施指南 v1.1 的 11 条 P0 规则:
| 规则 ID | 类别 | 规则名称 | 描述 | 分数 |
|---|---|---|---|---|
| AUTH-P0-001 | 认证 | 强制新注册用户为访客 | 注册时自动分配角色=访客;仅通过邀请授予更高角色 | 认证 8 |
| AUTH-P0-002 | 认证 | 阻止访客访问菜单/API | 不向访客暴露工具名称、模型名称、内部基础设施、成本或结构。仅允许访问允许的菜单/API | 认证 7 |
| AUTH-P0-003 | 认证 | 服务器端最终认证检查 | 所有 API 请求都需要服务器端认证验证中间件。仅客户端检查是不够的 | 认证 10 |
| SEC-P0-004 | 安全 | 禁止直接访问 Firestore | 禁止从客户端直接读写 Firestore。仅允许通过云函数 | 安全 12 |
| SEC-P0-005 | 安全 | 强制执行外部 API 网关 | 禁止直接调用外部 AI API(Gemini、OpenAI 等)。必须通过内部网关(云函数)路由 | 安全 18 |
| SEC-P0-009 | 安全 | 服务器端敏感文本处理 | 敏感原始内容(提示、完整响应)仅在服务器端处理。仅引用值(ID)发送到客户端 | 安全 10 |
| COST-P0-006 | 成本 | 模型调用成本日志 | 必须为每次 AI 模型调用记录模型、输入令牌、输出令牌、预估成本 | 成本 10 |
| COST-P0-007 | 成本 | BQ 扫描成本日志 | 执行 BigQuery 查询时必须记录已处理字节数、预估成本 | 成本 5 |
| COST-P0-011 | 成本 | 缓存优先查找 | 高成本 API 调用前需要缓存查找。仅在缓存未命中时进行实际调用 | 成本 5 |
| LOG-P0-008 | 日志记录 | 强制记录失败请求 | 必须记录所有失败请求(4xx、5xx、超时)。不允许遗漏 | 日志记录 10 |
| LOG-P0-010 | 日志记录 | 认证变更审计日志 | 记录所有与认证相关的事件:角色变更、权限授予/撤销、邀请发送 | 日志记录 5 |
| 领域 | 最高分 | 包含的规则 |
|---|---|---|
| 安全 | 40 | SEC-P0-004, SEC-P0-005, SEC-P0-009 |
| 认证 | 25 | AUTH-P0-001, AUTH-P0-002, AUTH-P0-003 |
| 成本 | 20 | COST-P0-006, COST-P0-007, COST-P0-011 |
| 日志记录 | 15 | LOG-P0-008, LOG-P0-010 |
| 总计 | 100 | 11 条 P0 规则 |
每条规则的验证基于 rules/p0-catalog.yaml 中定义的 check_pattern 执行。核心机制是 Grep/Glob 静态分析。
裁决算法(每条规则):
1. Glob(check_targets) → 收集目标文件
2. grep_patterns 匹配 → 识别使用该功能的文件
- 0 匹配 → N/A(未使用该功能,无惩罚)
3. must_not_contain 检查(排除 exclude_paths)
- 找到匹配 → 立即失败 + 记录证据
4. must_contain 检查
- 全部满足 → 通过
- 部分满足 → 警告
- 未满足 → 失败
每条规则的关键 Grep 模式:
| 规则 ID | 功能检测 (grep_patterns) | 合规检查 (must_contain) | 违规检测 (must_not_contain) |
|---|---|---|---|
| AUTH-P0-001 | `signup | register | createUser` |
| AUTH-P0-002 | `guard | middleware | authorize` |
| AUTH-P0-003 | `router.(get | post | put |
| SEC-P0-004 | -- (所有目标) | -- | `firebase/firestore |
| SEC-P0-005 | -- (所有目标) | -- | fetch\(['"]https?://(?!localhost) (客户端路径) |
| SEC-P0-009 | -- (所有目标) | -- | `res.json(.*password |
| COST-P0-006 | `openai | vertexai | gemini |
| COST-P0-007 | `bigquery | BigQuery | createQueryJob` |
| COST-P0-011 | `openai | vertexai | gemini |
| LOG-P0-008 | `catch | errorHandler | onError` |
| LOG-P0-010 | `updateRole | changeRole | setRole` |
详细模式:参见 rules/p0-catalog.yaml 和 REFERENCE.md 中的“裁决算法”部分
在全面验证模式 (/compliance-verify) 中运行的 5 个关键验证场景。每个场景将相关的 P0 规则分组以进行端到端验证。
| ID | 场景 | 相关规则 | 验证方法 | 通过标准 |
|---|---|---|---|---|
| SC-001 | 新注册 -> 访客隔离 | AUTH-P0-001, AUTH-P0-002 | 验证注册代码中角色=访客的分配 + 确认访客调用受保护 API 时的 403 返回模式 | 当角色为访客且受保护 API 存在访问拒绝模式时通过 |
| SC-002 | AI 调用 -> 通过网关 + 记录成本 | SEC-P0-005, COST-P0-006, COST-P0-011 | (1) 确认没有直接的外部 API 调用 (2) 确认通过网关函数路由 (3) 确认记录了成本日志字段(模型、令牌、成本) (4) 确认存在缓存查找逻辑 | 当网关路由 + 记录了 4 个成本日志字段 + 存在缓存层时通过 |
| SC-003 | Firestore 访问 -> 仅限函数 | SEC-P0-004, AUTH-P0-003 | (1) 检测客户端代码中直接的 Firestore SDK 导入 (2) 确认存在服务器端认证验证中间件 | 当 0 个直接客户端访问实例 + 存在服务器中间件时通过 |
| SC-004 | 失败请求 -> 无日志缺口 | LOG-P0-008, LOG-P0-010 | (1) 确认错误处理程序中有日志调用 (2) 确认 catch 块中没有日志缺口 (3) 确认认证变更事件存在审计日志 | 当所有错误处理程序都调用日志 + 存在认证变更审计日志时通过 |
| SC-005 | 敏感数据 -> 不暴露给客户端 | SEC-P0-009, AUTH-P0-002 | (1) 确认 API 响应不包含原始提示/响应,仅包含引用 ID (2) 确认访客响应不包含模型名称/成本/基础设施信息 | 当响应中不包含原始内容 + 确认访客暴露控制时通过 |
SC-001: grep signup/register -> assert role='guest' -> grep guestBlock/guestDeny -> assert exists
SC-002: grep fetch(https://) in client -> assert 0 hits -> grep gateway log -> assert cost fields -> assert cache check
SC-003: grep firebase/firestore in client/ -> assert 0 hits -> grep authMiddleware in functions/ -> assert exists
SC-004: grep catch blocks -> assert logAction in each -> grep roleChange -> assert auditLog
SC-005: grep res.json for raw text -> assert 0 hits -> grep guest response -> assert no model/cost info
部署门控裁决后,必须根据等级清除角色的通过/不通过检查点。4 个角色 × 5 个项目 = 总共 20 个检查点。
---|---|---|---
1 | SLA 影响分析 | 确认对现有服务可用性/响应时间 SLA 无影响 | SLA 影响未分析或预期降级
2 | 回滚程序 | 回滚程序已记录 + 测试 | 回滚程序未建立
3 | 性能测试 | 负载/压力测试已完成 + 在阈值内 | 性能测试未运行
4 | 事件警报 | 事件检测警报通道(Slack/PagerDuty 等)已配置 | 警报通道未配置
5 | 监控仪表板 | 关键指标(错误率、响应时间、AI 成本)的仪表板存在 | 监控缺失
---|---|---|---
1 | 失败规则根本原因分析 | 所有失败规则的根本原因已识别 + 记录 | 存在未识别项
2 | 修复代码验证 | 修复代码准确反映了规则的意图 | 修复与规则意图不匹配
3 | 重新验证通过 | 修复后规则在重新验证中转为通过 | 未运行重新验证或仍为失败
4 | 无回归影响 | 确认修复对其他 P0 规则无负面影响 | 另一条规则新出现失败
5 | 代码审查完成 | 修复代码的代码审查批准已完成 | 代码审查未完成
---|---|---|---
1 | 用户影响评估 | 不合规项对用户的影响是可接受的 | 用户影响未评估
2 | 进度风险 | 修复时间线在发布进度内 | 预期进度超期
3 | 范围协议 | 范围变更的利益相关者协议已完成 | 协议未达成
4 | 成本影响 | AI 使用成本在批准的预算内 | 预期预算超支
5 | 沟通 | 变更已与相关团队分享 | 未分享
---|---|---|---
1 | 成本上限 | 月度 AI 成本在预先批准的预算内 | 预算上限超出
2 | 安全风险 | 所有安全 P0 通过或例外理由是合理的 | P0 安全失败 + 例外理由不充分
3 | 法律/监管风险 | 数据处理符合适用法律(隐私法等) | 法律风险未审查
4 | 业务连续性 | 如果部署失败,业务影响有限 | 存在业务中断风险
5 | 最终批准 | 当以上 4 项都通过时最终批准 | 即使有 1 项不通过也推迟
当运行 /compliance-verify 时生成的 compliance-report.md 包含 6 个部分。
# Compliance Report
## 1. Summary
- Project name, verification date/time, verification mode (quick-scan / full-verify)
- Total compliance score / 100
- Deploy gate grade (Green / Yellow / Red)
- P0 FAIL count
- Verification duration
## 2. Rule Results
| Rule ID | Category | Rule Name | Result | Score | Evidence |
|---------|----------|-----------|--------|-------|----------|
| AUTH-P0-001 | Auth | Force Guest for New Signups | PASS | 10/10 | signup.ts:45 |
| SEC-P0-005 | Security | Enforce External API Gateway | FAIL | 0/15 | client/api.ts:23 direct fetch |
| ...
## 3. Score Breakdown
| Domain | Score | Max | % |
|--------|-------|-----|---|
| Security | 20 | 40 | 50% |
| Auth | 25 | 25 | 100% |
| Cost | 17 | 20 | 85% |
| Logging | 12 | 15 | 80% |
| **Total** | **79** | **100** | **79%** |
## 4. Failures Detail
For each FAIL item:
- Violation code location (file:line)
- Description of the violation
- Recommended fix (remediation)
- Related verification scenario ID (SC-001–SC-005)
## 5. Gate Decision
- Verdict grade + basis for verdict
- List of required approval roles
- Role-based Go/No-Go checkpoint status (unmet items out of 20 shown)
## 6. Recommendations
- Immediate action: Fix P0 FAILs (file path + fix guide)
- Short-term improvement: Path from Yellow to Green
- Mid-term adoption: Order for introducing P1 recommended requirements
| 等级 | 分数 | 条件 | 决定 |
|---|---|---|---|
| 绿色 | 90–100 | 所有 P0 通过 + 总分 ≥ 90 | 自动部署批准 |
| 黄色 | 75–89 | 所有 P0 通过 + 总分 75–89 | 有条件批准(需要产品经理审查) |
| 红色 | 0–74 | 总分 ≤ 74 或 任何 P0 失败 | 部署阻止 |
/compliance-verify runs
|
Full verification of 11 P0 rules
|
Score computed (Security+Auth+Cost+Logging)
|
+----+----+----+
| | |
Green Yellow Red
| | |
Auto-Approve PM-Approve Deploy-Block
| Pending |
v | After Fix
Deploy v Re-verify
PM Review |
| | v
Approve Reject /compliance-improve
| |
v v
Deploy After Fix
Re-verify
基于内部 AI 工具强制性实施指南第 14 节。所需的审批角色因部署等级而异。
职责:验证事件影响、性能降级和回滚可行性
清单:
审批触发:黄色/红色等级需要
职责:失败规则的根本原因分析 + 代码级修复 + 重新验证
清单:
审批触发:红色等级需要(负责修复后的重新验证)
职责:用户影响、进度风险、范围变更批准
清单:
审批触发:黄色等级需要
职责:成本上限、业务风险、最终批准
清单:
审批触发:当成本上限超出或批准安全 P0 例外时
/compliance-init)project/
├── compliance/
│ ├── rbac-matrix.yaml # 5-角色 × 游戏/菜单/功能权限矩阵
│ ├── rules/
│ │ └── p0-rules.yaml # 11 条 P0 规则定义
│ ├── log-schema.yaml # 行为日志模式(Firestore/BigQuery)
│ └── cost-tracking.yaml # 成本跟踪字段定义
├── compliance-config.yaml # 项目元数据 + 验证设置
└── compliance-report.md # 验证结果报告(验证运行时生成)
compliance-config.yaml(项目根目录):
project:
name: "my-ai-tool"
type: "web-app" # web-app | api | mobile-app | library
tech_stack: ["typescript", "firebase", "next.js"]
verification:
catalog_path: "compliance/rules/p0-rules.yaml" # default
exclude_paths: # paths to exclude from verification
- "node_modules/**"
- "dist/**"
- "**/*.test.ts"
- "**/*.spec.ts"
scoring:
domain_weights: # total = 100
security: 40
auth: 25
cost: 20
logging: 15
gate:
green_threshold: 90 # >= 90 = auto approve
yellow_threshold: 75 # 75-89 = PM review required
p0_fail_override: true # Red verdict on P0 FAIL regardless of score
compliance/log-schema.yaml(行为日志模式):
log_schema:
version: "1.0.0"
storage:
primary: "firestore" # for real-time access
archive: "bigquery" # for analytics/audit
retention:
hot: 90 # days (Firestore)
cold: 365 # days (BigQuery)
fields:
- name: userId
type: string
required: true
- name: action
type: string
required: true
description: "action performed (ai_call, role_change, login, etc.)"
- name: timestamp
type: timestamp
required: true
- name: model
type: string
required: false
description: "AI model name (gemini-1.5-flash, etc.)"
- name: inputTokens
type: number
required: false
- name: outputTokens
type: number
required: false
- name: estimatedCost
type: number
required: false
description: "estimated cost in USD"
- name: status
type: string
required: true
enum: [success, fail, timeout, error]
- name: errorMessage
type: string
required: false
- name: metadata
type: map
required: false
description: "additional context (bytesProcessed, cacheHit, etc.)"
compliance/cost-tracking.yaml(成本跟踪字段):
cost_tracking:
version: "1.0.0"
ai_models:
required_fields:
- model # model identifier
- inputTokens # input token count
- outputTokens # output token count
- estimatedCost # estimated cost in USD
optional_fields:
- cacheHit # whether cache was hit
- latencyMs # response latency (ms)
bigquery:
required_fields:
- queryId # query identifier
- bytesProcessed # bytes scanned
- estimatedCost # estimated cost in USD
optional_fields:
- slotMs # slot usage time
- cacheHit # BQ cache hit indicator
cost_formula:
gemini_flash: "$0.075 / 1M input tokens, $0.30 / 1M output tokens"
gemini_pro: "$1.25 / 1M input tokens, $5.00 / 1M output tokens"
bigquery: "$5.00 / TB scanned"
# compliance/rbac-matrix.yaml
roles:
- id: super_admin
name: Super Admin
description: Full system administration + role assignment rights
- id: admin
name: Admin
description: Service configuration + user management
- id: manager
name: Manager
description: Team/game-level management
- id: viewer
name: Viewer
description: Read-only access
- id: guest
name: Guest
description: Minimum access (tool name/model name/cost/structure not exposed)
permissions:
- resource: "dashboard"
actions:
super_admin: [read, write, delete, admin]
admin: [read, write, delete]
manager: [read, write]
viewer: [read]
guest: [] # no access
# ... expand per game/menu/feature
// functions/src/gateway/ai-gateway.ts
// Direct external API calls forbidden - must route through this Gateway
import { onCall, HttpsError } from "firebase-functions/v2/https";
import { verifyRole } from "../auth/rbac";
import { logAction } from "../logging/audit";
import { checkCache } from "../cache/cost-cache";
export const callAIModel = onCall(async (request) => {
// 1. Server-side auth verification (AUTH-P0-003)
const user = await verifyRole(request.auth, ["admin", "manager"]);
// 2. Block Guest access (AUTH-P0-002)
if (user.role === "guest") {
throw new HttpsError("permission-denied", "Access denied");
}
// 3. Cache-first lookup (COST-P0-011)
const cached = await checkCache(request.data.prompt);
if (cached) {
await logAction({
userId: user.uid,
action: "ai_call",
source: "cache",
cost: 0,
});
return { result: cached, fromCache: true };
}
// 4. AI call via Gateway (SEC-P0-005)
const result = await callGeminiViaGateway(request.data.prompt);
// 5. Record cost log (COST-P0-006)
await logAction({
userId: user.uid,
action: "ai_call",
model: result.model,
inputTokens: result.usage.inputTokens,
outputTokens: result.usage.outputTokens,
estimatedCost: result.usage.estimatedCost,
});
// 6. Sensitive raw content processed server-side only; return reference ID to client (SEC-P0-009)
const responseRef = await storeResponse(result.text);
return { responseId: responseRef.id, summary: result.summary };
});
bmad-orchestrator 管理完整的项目开发阶段(分析 -> 规划 -> 解决方案 -> 实施),而 ai-tool-compliance 作为一个配套工具,验证每个阶段的输出是否符合合规要求。
推荐使用顺序:
/workflow-init (bmad) -- 建立项目结构/compliance-init (compliance) -- 生成合规基础/compliance-scan -- 架构级合规检查/compliance-verify -- 全面验证 + 部署门控裁决security-best-practices 提供通用的 Web 安全模式(OWASP、HTTPS、XSS、CSRF)。ai-tool-compliance 将这些作为前提条件,专注于组织特定的要求(5 角色 RBAC、网关强制执行、成本透明化、全面的行为日志记录)。
| 项目 | security-best-practices | ai-tool-compliance |
|---|---|---|
| RBAC | 一般提及 | 5 角色 + 游戏/菜单/功能矩阵 |
| API 安全 | 速率限制、CORS | 网关强制执行 + 成本日志 |
| 数据保护 | XSS、CSRF、SQL 注入 | 敏感内容服务器端 + Firestore 策略 |
| 日志记录 | 安全事件日志记录 | 全面的行为日志 + 模式/保留策略 |
| 部署门控 | 无 | 基于合规分数的自动阻止 |
code-review 主观地审查代码质量/可读性/安全性,而 ai-tool-compliance 提供关于“是否通过内部 AI 工具指南?”的定量裁决(通过/失败,满分 100)。/compliance-scan 结果可用作代码审查期间的参考材料。
workflow-automation 提供通用的 CI/CD 模式(npm 脚本、Makefile、GitHub Actions),而 ai-tool-compliance 提供插入该流水线中的领域特定验证步骤。
bash scripts/install.sh [options]
--dry-run preview without making changes
--skip-checks skip dependency checks
功能:
bash scripts/verify.sh [--rule RULE_ID] [--output JSON_PATH]
功能:
rules/p0-catalog.yaml(基于 yq 或 grep)check_targets Glob 收集目标文件grep_patterns 检测功能使用情况(如果未使用则为 N/A)must_not_contain 违规(排除 exclude_paths)must_contain 合规性templates/verification-run.json 格式输出结果bash scripts/score.sh [--input VERIFY_JSON] [--verbose]
功能:
templates/risk-score-report.mdtemplates/remediation-task.json(针对每个失败项)bash scripts/gate.sh
# exit 0 = Green (deploy approved)
# exit 1 = Red (deploy blocked)
# exit 2 = Yellow (conditional -- PM review required)
功能:
CI/CD 集成示例 (GitHub Actions):
# .github/workflows/compliance-gate.yml
name: Compliance Gate
on: [pull_request]
jobs:
compliance:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v
npx skills add https://github.com/supercent-io/skills-template --skill ai-tool-compliance
| Action | Command | Description |
|---|---|---|
| Project initialization | /compliance-init | Generate RBAC matrix, Gateway boilerplate, log schema, cost tracking interface |
| Quick scan | /compliance-scan, /compliance-quick, /quick | Quick inspection of P0 key items (code pattern-based) |
| Full verification | /compliance-verify, /compliance-full, /full | Full verification of 11 P0 rules + compliance score computation |
| Score check | /compliance-score |
Mode slash commands are mapped as follows.
/quick, /compliance-quick -> Quick Scan (/compliance-scan)/full, /compliance-full -> Full Verify (/compliance-verify)/improve -> Improve (/compliance-improve)quick-scan)Statically analyzes the codebase to quickly identify potential P0 violations.
How to run : /compliance-scan, /compliance-quick, /quick or trigger keywords compliance scan, quick scan
What it does :
Output : List of suspected violations (file path + line number + rule ID)
Duration : 1–3 minutes
full-verify)Fully verifies all 11 P0 rules and computes a quantitative compliance score.
How to run : /compliance-verify, /compliance-full, /full or trigger keywords P0 verification, full verify, deploy verification
What it does :
Output : Compliance report (compliance-report.md)
## Compliance Report
- Date: 2026-03-03
- Project: my-ai-tool
- Score: 92/100 (Green)
### Rule Results
| Rule ID | Rule Name | Result | Evidence |
|---------|-----------|--------|----------|
| AUTH-P0-001 | Force Guest for New Signups | PASS | signup.ts:45 role='guest' |
| AUTH-P0-002 | Block Guest Menu/API Access | PASS | middleware.ts:12 guestBlock |
| ... | ... | ... | ... |
### Score Breakdown
- Security: 33/40
- Auth: 25/25
- Cost: 17/20
- Logging: 12/15
- Total: 92/100
### Gate Decision: GREEN - Deploy Approved
Duration : 5–15 minutes (varies by project size)
improve)Provides specific fix guides for violations and runs a re-verification loop.
How to run : /compliance-improve, /improve or trigger keywords compliance improvement, fix violations
What it does :
Output : Fix proposal + re-verification results
/compliance-improve runs
|
1. Load latest verification-run.json
|
2. Extract FAIL items (rule_id + evidence)
|
3. For each FAIL:
|
a. Read violation code from evidence file:line
b. Derive fix direction from rule.remediation + rule.check_pattern.must_contain
c. Generate before/after code diff
d. Apply fix via Write (after user confirmation)
e. Re-verify only that rule (re-run Grep pattern)
f. Confirm transition to PASS
|
4. Full re-verification (/compliance-verify)
|
5. Output Before/After score comparison
|
6. If no remaining FAILs → present guide for introducing P1 recommended requirements
Fix application priority :
must_not_contain violations (requires immediate removal) → delete the code or replace with server API callmust_contain unmet (pattern needs to be added) → insert code per the remediation guide11 P0 rules based on the internal AI tool mandatory implementation guide v1.1:
| Rule ID | Category | Rule Name | Description | Score |
|---|---|---|---|---|
| AUTH-P0-001 | Auth | Force Guest for New Signups | Automatically assign role=Guest on signup; elevated roles granted only via invitation | Auth 8 |
| AUTH-P0-002 | Auth | Block Guest Menu/API Access | Do not expose tool name, model name, internal infrastructure, cost, or structure to Guest. Only allow access to permitted menus/APIs | Auth 7 |
| AUTH-P0-003 | Auth | Server-side Final Auth Check | Server-side auth verification middleware required for all API requests. Client-side checks alone are insufficient | Auth 10 |
| SEC-P0-004 | Security | Prohibit Direct Firestore Access | Direct read/write to Firestore from client is forbidden. Only via Cloud Functions is allowed | Security 12 |
| SEC-P0-005 | Security | Enforce External API Gateway |
| Domain | Max Score | Included Rules |
|---|---|---|
| Security | 40 | SEC-P0-004, SEC-P0-005, SEC-P0-009 |
| Auth | 25 | AUTH-P0-001, AUTH-P0-002, AUTH-P0-003 |
| Cost | 20 | COST-P0-006, COST-P0-007, COST-P0-011 |
| Logging | 15 | LOG-P0-008, LOG-P0-010 |
| Total | 100 | 11 P0 rules |
Verification for each rule is performed based on the check_pattern defined in rules/p0-catalog.yaml. The core mechanism is Grep/Glob static analysis.
Verdict Algorithm (per rule) :
1. Glob(check_targets) → collect target files
2. grep_patterns matching → identify files using that feature
- 0 matches → N/A (feature not used, no penalty)
3. must_not_contain check (excluding exclude_paths)
- Match found → immediate FAIL + record evidence
4. must_contain check
- All satisfied → PASS
- Partially satisfied → WARNING
- Not satisfied → FAIL
Key Grep Patterns per Rule :
| Rule ID | Feature Detection (grep_patterns) | Compliance Check (must_contain) | Violation Detection (must_not_contain) |
|---|---|---|---|
| AUTH-P0-001 | `signup | register | createUser` |
| AUTH-P0-002 | `guard | middleware | authorize` |
| AUTH-P0-003 | `router.(get | post | put |
| SEC-P0-004 | -- (all targets) | -- | `firebase/firestore |
| SEC-P0-005 | -- (all targets) | -- | fetch\(['"]https?://(?!localhost) (client paths) |
| SEC-P0-009 | -- (all targets) | -- | `res.json(.*password |
Detailed schema : see rules/p0-catalog.yaml and the "Judgment Algorithm" section in REFERENCE.md
5 key verification scenarios run in Full Verify mode (/compliance-verify). Each scenario groups related P0 rules for end-to-end verification.
| ID | Scenario | Related Rules | Verification Method | Pass Criteria |
|---|---|---|---|---|
| SC-001 | New Signup - > Guest Isolation | AUTH-P0-001, AUTH-P0-002 | Verify role=guest assignment in signup code + confirm 403 return pattern when Guest calls protected API | PASS when role is guest and access-denied pattern exists for protected API |
| SC-002 | AI Call - > Via Gateway + Cost Logged | SEC-P0-005, COST-P0-006, COST-P0-011 | (1) Confirm absence of direct external API calls (2) Confirm routing via Gateway function (3) Confirm cost log fields (model, tokens, cost) recorded (4) Confirm cache lookup logic exists | PASS when Gateway routing + 4 cost log fields recorded + cache layer exists |
| SC-003 | Firestore Access - > Functions-Only | SEC-P0-004, AUTH-P0-003 | (1) Detect direct Firestore SDK import in client code (2) Confirm server-side auth verification middleware exists | PASS when 0 direct client access instances + server middleware exists |
| SC-004 | Failed Requests - > No Log Gaps |
SC-001: grep signup/register -> assert role='guest' -> grep guestBlock/guestDeny -> assert exists
SC-002: grep fetch(https://) in client -> assert 0 hits -> grep gateway log -> assert cost fields -> assert cache check
SC-003: grep firebase/firestore in client/ -> assert 0 hits -> grep authMiddleware in functions/ -> assert exists
SC-004: grep catch blocks -> assert logAction in each -> grep roleChange -> assert auditLog
SC-005: grep res.json for raw text -> assert 0 hits -> grep guest response -> assert no model/cost info
After the deploy gate verdict, the role's Go/No-Go checkpoints must be cleared based on the grade. 4 roles × 5 items = 20 checkpoints total.
---|---|---|---
1 | SLA Impact Analysis | Confirmed no impact on existing service availability/response-time SLA | SLA impact unanalyzed or degradation expected
2 | Rollback Procedure | Rollback procedure documented + tested | Rollback procedure not established
3 | Performance Test | Load/stress test completed + within threshold | Performance test not run
4 | Incident Alerts | Incident detection alert channels (Slack/PagerDuty, etc.) configured | Alert channels not configured
5 | Monitoring Dashboard | Dashboard for key metrics (error rate, response time, AI cost) exists | Monitoring absent
---|---|---|---
1 | FAIL Rule Root Cause Analysis | Root cause identified + documented for all FAIL rules | Unidentified items exist
2 | Fix Code Verification | Fixed code accurately reflects the intent of the rule | Fix does not match rule intent
3 | Re-verification Pass | Rule transitions to PASS in re-verification after fix | Re-verification not run or still FAIL
4 | No Regression Impact | Fix confirmed to have no negative impact on other P0 rules | Another rule newly FAILs
5 | Code Review Done | Code review approval completed for fixed code | Code review not completed
---|---|---|---
1 | User Impact Assessment | User impact of non-compliant items is acceptable | User impact not assessed
2 | Schedule Risk | Fix timeline is within release schedule | Schedule overrun expected
3 | Scope Agreement | Stakeholder agreement completed for scope changes | Agreement not reached
4 | Cost Impact | AI usage cost within approved budget | Budget overrun expected
5 | Communication | Changes shared with relevant teams | Not shared
---|---|---|---
1 | Cost Cap | Monthly AI cost within pre-approved budget | Budget cap exceeded
2 | Security Risk | All security P0 passed or exception reason is reasonable | P0 security FAIL + insufficient exception justification
3 | Legal/Regulatory Risk | Data processing complies with applicable laws (privacy laws, etc.) | Legal risks not reviewed
4 | Business Continuity | Business impact is limited if deployment fails | Business disruption risk exists
5 | Final Approval | Final approval when all 4 above are Go | Deferred if even 1 is No-Go
compliance-report.md, generated when /compliance-verify runs, consists of 6 sections.
# Compliance Report
## 1. Summary
- Project name, verification date/time, verification mode (quick-scan / full-verify)
- Total compliance score / 100
- Deploy gate grade (Green / Yellow / Red)
- P0 FAIL count
- Verification duration
## 2. Rule Results
| Rule ID | Category | Rule Name | Result | Score | Evidence |
|---------|----------|-----------|--------|-------|----------|
| AUTH-P0-001 | Auth | Force Guest for New Signups | PASS | 10/10 | signup.ts:45 |
| SEC-P0-005 | Security | Enforce External API Gateway | FAIL | 0/15 | client/api.ts:23 direct fetch |
| ...
## 3. Score Breakdown
| Domain | Score | Max | % |
|--------|-------|-----|---|
| Security | 20 | 40 | 50% |
| Auth | 25 | 25 | 100% |
| Cost | 17 | 20 | 85% |
| Logging | 12 | 15 | 80% |
| **Total** | **79** | **100** | **79%** |
## 4. Failures Detail
For each FAIL item:
- Violation code location (file:line)
- Description of the violation
- Recommended fix (remediation)
- Related verification scenario ID (SC-001–SC-005)
## 5. Gate Decision
- Verdict grade + basis for verdict
- List of required approval roles
- Role-based Go/No-Go checkpoint status (unmet items out of 20 shown)
## 6. Recommendations
- Immediate action: Fix P0 FAILs (file path + fix guide)
- Short-term improvement: Path from Yellow to Green
- Mid-term adoption: Order for introducing P1 recommended requirements
| Grade | Score | Condition | Decision |
|---|---|---|---|
| Green | 90–100 | All P0 PASS + total score ≥ 90 | Auto deploy approved |
| Yellow | 75–89 | All P0 PASS + total score 75–89 | Conditional approval (PM review required) |
| Red | 0–74 | Total score ≤ 74 or any P0 FAIL | Deploy blocked |
/compliance-verify runs
|
Full verification of 11 P0 rules
|
Score computed (Security+Auth+Cost+Logging)
|
+----+----+----+
| | |
Green Yellow Red
| | |
Auto-Approve PM-Approve Deploy-Block
| Pending |
v | After Fix
Deploy v Re-verify
PM Review |
| | v
Approve Reject /compliance-improve
| |
v v
Deploy After Fix
Re-verify
Based on Section 14 of the internal AI tool mandatory implementation guide. The required approval roles vary by deploy grade.
Responsibility : Verify incident impact, performance degradation, and rollback feasibility
Checklist:
Approval trigger : Required for Yellow/Red grade
Responsibility : Root cause analysis of failed rules + code-level fix + re-verification
Checklist:
Approval trigger : Required for Red grade (responsible for re-verification after fix)
Responsibility : User impact, schedule risk, scope change approval
Checklist:
Approval trigger : Required for Yellow grade
Responsibility : Cost cap, business risk, final approval
Checklist:
Approval trigger : When cost cap is exceeded or when approving a security P0 exception
/compliance-init)project/
├── compliance/
│ ├── rbac-matrix.yaml # 5-role × game/menu/feature permission matrix
│ ├── rules/
│ │ └── p0-rules.yaml # 11 P0 rule definitions
│ ├── log-schema.yaml # Behavior log schema (Firestore/BigQuery)
│ └── cost-tracking.yaml # Cost tracking field definitions
├── compliance-config.yaml # Project metadata + verification settings
└── compliance-report.md # Verification result report (generated on verify run)
compliance-config.yaml (project root):
project:
name: "my-ai-tool"
type: "web-app" # web-app | api | mobile-app | library
tech_stack: ["typescript", "firebase", "next.js"]
verification:
catalog_path: "compliance/rules/p0-rules.yaml" # default
exclude_paths: # paths to exclude from verification
- "node_modules/**"
- "dist/**"
- "**/*.test.ts"
- "**/*.spec.ts"
scoring:
domain_weights: # total = 100
security: 40
auth: 25
cost: 20
logging: 15
gate:
green_threshold: 90 # >= 90 = auto approve
yellow_threshold: 75 # 75-89 = PM review required
p0_fail_override: true # Red verdict on P0 FAIL regardless of score
compliance/log-schema.yaml (behavior log schema):
log_schema:
version: "1.0.0"
storage:
primary: "firestore" # for real-time access
archive: "bigquery" # for analytics/audit
retention:
hot: 90 # days (Firestore)
cold: 365 # days (BigQuery)
fields:
- name: userId
type: string
required: true
- name: action
type: string
required: true
description: "action performed (ai_call, role_change, login, etc.)"
- name: timestamp
type: timestamp
required: true
- name: model
type: string
required: false
description: "AI model name (gemini-1.5-flash, etc.)"
- name: inputTokens
type: number
required: false
- name: outputTokens
type: number
required: false
- name: estimatedCost
type: number
required: false
description: "estimated cost in USD"
- name: status
type: string
required: true
enum: [success, fail, timeout, error]
- name: errorMessage
type: string
required: false
- name: metadata
type: map
required: false
description: "additional context (bytesProcessed, cacheHit, etc.)"
compliance/cost-tracking.yaml (cost tracking fields):
cost_tracking:
version: "1.0.0"
ai_models:
required_fields:
- model # model identifier
- inputTokens # input token count
- outputTokens # output token count
- estimatedCost # estimated cost in USD
optional_fields:
- cacheHit # whether cache was hit
- latencyMs # response latency (ms)
bigquery:
required_fields:
- queryId # query identifier
- bytesProcessed # bytes scanned
- estimatedCost # estimated cost in USD
optional_fields:
- slotMs # slot usage time
- cacheHit # BQ cache hit indicator
cost_formula:
gemini_flash: "$0.075 / 1M input tokens, $0.30 / 1M output tokens"
gemini_pro: "$1.25 / 1M input tokens, $5.00 / 1M output tokens"
bigquery: "$5.00 / TB scanned"
# compliance/rbac-matrix.yaml
roles:
- id: super_admin
name: Super Admin
description: Full system administration + role assignment rights
- id: admin
name: Admin
description: Service configuration + user management
- id: manager
name: Manager
description: Team/game-level management
- id: viewer
name: Viewer
description: Read-only access
- id: guest
name: Guest
description: Minimum access (tool name/model name/cost/structure not exposed)
permissions:
- resource: "dashboard"
actions:
super_admin: [read, write, delete, admin]
admin: [read, write, delete]
manager: [read, write]
viewer: [read]
guest: [] # no access
# ... expand per game/menu/feature
// functions/src/gateway/ai-gateway.ts
// Direct external API calls forbidden - must route through this Gateway
import { onCall, HttpsError } from "firebase-functions/v2/https";
import { verifyRole } from "../auth/rbac";
import { logAction } from "../logging/audit";
import { checkCache } from "../cache/cost-cache";
export const callAIModel = onCall(async (request) => {
// 1. Server-side auth verification (AUTH-P0-003)
const user = await verifyRole(request.auth, ["admin", "manager"]);
// 2. Block Guest access (AUTH-P0-002)
if (user.role === "guest") {
throw new HttpsError("permission-denied", "Access denied");
}
// 3. Cache-first lookup (COST-P0-011)
const cached = await checkCache(request.data.prompt);
if (cached) {
await logAction({
userId: user.uid,
action: "ai_call",
source: "cache",
cost: 0,
});
return { result: cached, fromCache: true };
}
// 4. AI call via Gateway (SEC-P0-005)
const result = await callGeminiViaGateway(request.data.prompt);
// 5. Record cost log (COST-P0-006)
await logAction({
userId: user.uid,
action: "ai_call",
model: result.model,
inputTokens: result.usage.inputTokens,
outputTokens: result.usage.outputTokens,
estimatedCost: result.usage.estimatedCost,
});
// 6. Sensitive raw content processed server-side only; return reference ID to client (SEC-P0-009)
const responseRef = await storeResponse(result.text);
return { responseId: responseRef.id, summary: result.summary };
});
Where bmad-orchestrator manages the full project development phases (Analysis -> Planning -> Solutioning -> Implementation), ai-tool-compliance acts as a companion tool that verifies whether each phase's outputs meet compliance requirements.
Recommended usage order :
/workflow-init (bmad) -- establish project structure/compliance-init (compliance) -- generate compliance foundation/compliance-scan -- architecture-level compliance check/compliance-verify -- full verification + deploy gate verdictsecurity-best-practices provides general web security patterns (OWASP, HTTPS, XSS, CSRF). ai-tool-compliance assumes these as prerequisites and focuses on organization-specific requirements (5-role RBAC, Gateway enforcement, cost transparency, comprehensive behavior logging).
| Item | security-best-practices | ai-tool-compliance |
|---|---|---|
| RBAC | General mention | 5-role + game/menu/feature matrix |
| API Security | Rate Limiting, CORS | Gateway enforcement + cost log |
| Data Protection | XSS, CSRF, SQL Injection | Sensitive content server-side + Firestore policy |
| Logging | Security event logging | Comprehensive behavior log + schema/retention policy |
| Deploy Gate | None | Auto-block based on compliance score |
Where code-review subjectively reviews code quality/readability/security, ai-tool-compliance provides a quantitative verdict (pass/fail, out of 100) on "Does it pass the internal AI tool guide?" The /compliance-scan result can be used as reference material during code review.
Where workflow-automation provides general CI/CD patterns (npm scripts, Makefile, GitHub Actions), ai-tool-compliance provides the domain-specific verification step inserted into that pipeline.
bash scripts/install.sh [options]
--dry-run preview without making changes
--skip-checks skip dependency checks
What it does:
bash scripts/verify.sh [--rule RULE_ID] [--output JSON_PATH]
What it does:
rules/p0-catalog.yaml (yq or grep-based)check_targets Globgrep_patterns (N/A if not used)must_not_contain violations (excluding exclude_paths)must_contain compliancetemplates/verification-run.json formatbash scripts/score.sh [--input VERIFY_JSON] [--verbose]
What it does:
templates/risk-score-report.mdtemplates/remediation-task.json (per FAIL item)bash scripts/gate.sh
# exit 0 = Green (deploy approved)
# exit 1 = Red (deploy blocked)
# exit 2 = Yellow (conditional -- PM review required)
What it does:
CI/CD integration example (GitHub Actions) :
# .github/workflows/compliance-gate.yml
name: Compliance Gate
on: [pull_request]
jobs:
compliance:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run compliance gate
run: bash .agent-skills/ai-tool-compliance/scripts/gate.sh
Items recommended for gradual adoption after passing all P0 rules:
| Domain | Requirement | Description |
|---|---|---|
| Domain Management | Allowed domain whitelist | Restrict external domains callable by AI Gateway |
| Usage Statistics | Per-user/team usage aggregation | Daily/weekly/monthly usage dashboard |
| Cost Control | Budget cap alerts | Alert when cost threshold exceeded per team/project |
| Log Retention | Log retention policy | 90-day Hot / 365-day Cold / delete thereafter |
| Rule ID | Domain | Check Type | Key Criteria | Score |
|---|---|---|---|---|
| P1-DOM-001 | Domain Management | static_analysis | Domain CRUD history + createdAt/updatedAt/status/owner metadata | 7 |
| P1-STAT-002 | Statistics | api_test | User/model/period/game filter statistics + cost aggregation freshness (<1h) | 6 |
| P1-COST-003 | Cost Control | config_check | 80% budget warning + 100% block (429/403) + reset cycle | 6 |
| P1-LOG-004 | Logging | config_check | Log schema validation + 6+ month retention + search/Export | 6 |
| Column | Description | Source |
|---|---|---|
| Rule ID | Rule identifier | rules/p1-catalog.yaml |
| Category/Domain | Compliance domain | rules/p1-catalog.yaml |
| Check Type | Verification method (static/api/config/log) | rules/*-catalog.yaml |
| Pass/Fail Condition | Verdict criteria | rules/*-catalog.yaml |
| Score Impact | Weight | rules/*-catalog.yaml |
| Evidence | File:line or config reference | verify result JSON |
| Owner Role | Role responsible for action | compliance-report / role checklist |
| Action Queue | Improvement items within 1 week | remediation-task / report |
| Component | Responsibility | Output |
|---|---|---|
| Rule Registry | P0/P1 catalog version management and load policy | rules/catalog.json, rules/catalog-p1.json, rules/catalog-all.json |
| Evidence Collector | Code/config/API evidence collection and normalization | evidence/violations from verify.sh output |
| Verifier Engine | Per-rule PASS/FAIL/WARNING/NA verdict | /tmp/compliance-verify.json |
| Risk Scorer | Compute P0 Gate Score + P1 Maturity Score |
| Mode | Command | Behavior |
|---|---|---|
| P0 Default | bash scripts/verify.sh . | Verify P0 rules only (default, backward-compatible) |
| P0+P1 Extended | bash scripts/verify.sh . --include-p1 | P0 verification + P1 recommended rules simultaneously |
| Gate Verdict | bash scripts/gate.sh --score-file ... | Deploy verdict based on P0; P1 tracks maturity/improvement |
/compliance-init before implementing business logic/compliance-verify to confirm score changes#compliance #RBAC #security #cost-tracking #audit-log #gateway #firestore #deploy-gate #P0 #AI-tool
Weekly Installs
6.7K
Repository
GitHub Stars
88
First Seen
Mar 3, 2026
Security Audits
Gen Agent Trust HubFailSocketPassSnykPass
Installed on
codex6.6K
gemini-cli6.6K
opencode6.6K
github-copilot6.6K
cursor6.6K
cline6.6K
83,400 周安装
| Display current compliance score (security/auth/cost/logging) |
| Deploy gate | /compliance-gate | Green/Yellow/Red verdict + deploy approve/block decision |
| Improvement guide | /compliance-improve, /improve | Specific fix suggestions per violation + re-verification loop |
| Direct calls to external AI APIs (Gemini, OpenAI, etc.) are forbidden. Must route through internal Gateway (Cloud Functions) |
| Security 18 |
| SEC-P0-009 | Security | Server-side Sensitive Text Processing | Sensitive raw content (prompts, full responses) is processed server-side only. Only reference values (IDs) are sent to clients | Security 10 |
| COST-P0-006 | Cost | Model Call Cost Log | Must record model, inputTokens, outputTokens, estimatedCost for every AI model call | Cost 10 |
| COST-P0-007 | Cost | BQ Scan Cost Log | Must record bytesProcessed, estimatedCost when executing BigQuery queries | Cost 5 |
| COST-P0-011 | Cost | Cache-first Lookup | Cache lookup required before high-cost API calls. Actual call only on cache miss | Cost 5 |
| LOG-P0-008 | Logging | Mandatory Failed Request Logging | Must log all failed requests (4xx, 5xx, timeout). No omissions allowed | Logging 10 |
| LOG-P0-010 | Logging | Auth Change Audit Log | Record all auth-related events: role changes, permission grants/revocations, invitation sends | Logging 5 |
| COST-P0-006 | `openai | vertexai | gemini |
| COST-P0-007 | `bigquery | BigQuery | createQueryJob` |
| COST-P0-011 | `openai | vertexai | gemini |
| LOG-P0-008 | `catch | errorHandler | onError` |
| LOG-P0-010 | `updateRole | changeRole | setRole` |
| LOG-P0-008, LOG-P0-010 |
| (1) Confirm log call in error handler (2) Confirm no log gaps in catch blocks (3) Confirm audit log exists for auth change events |
| PASS when all error handlers call log + auth change audit log exists |
| SC-005 | Sensitive Data - > Not Exposed to Client | SEC-P0-009, AUTH-P0-002 | (1) Confirm API responses do not include raw prompts/responses, only reference IDs (2) Confirm Guest responses do not include model name/cost/infrastructure info | PASS when raw content not in response + Guest exposure control confirmed |
/tmp/compliance-score.json| Gatekeeper | Separate deploy block (P0) and recommendation (P1) decisions | gate.sh exit code + gate summary |