防护思路
点击放大

> A TDD and QA framework with integrated security for AI coding agents and de. Combines functional test-first engineering, living STRIDE threat modeling, local code quality checks, and continuous skill self-e to mitigate recurring issues.
> [!CAUTION]
> Use at Your Own Risk: This repository is a demonstration of an approach, not an officially supported framework. AI coding agents generate and execute code that may be unstable or perform unexpected actions. While this approach works to mitigate these very problems through test-first boundaries and local scanning, no testing framework offers a complete solution to model error. Run agentic workflows only in isolated de en and never on systems with access to production credentials, sensiti data, or internal networks.
---
Test-Dri (TDD) writes tests first to encode the requirements early on and target de against discrete goals. It documents expected behavior, catches regressions early, and keeps the agent zeroed in on implementing logic instead of guessing. This reduces some of the common issues with AI generated code, for example hallucinated features, hallucinations on test co, and going off on sidequests to recreate entire helper libraries, which is a nightmare to even run agentic reviews against.
Historically, software engineering has often treated functional QA and security testing as completely separate disciplines:
The Inner-Loop Ad: Moving threat modeling and security test assertions into the de's local test-first loop (TDD) eliminates issues in seconds while code is actively being written.
Secure TDD brings security into e QA and TDD workflows:
1. Holistic Planning & Threat Modeling: Features are planned with both functional user stories and STRIDE boundary constraints *before* code is authored.
2. Comprehensi (RED): Unit and integration tests assert both functional outcomes (HTTP 200/302, correct payloads) and defensi (HTTP 400/401/403, input rejections).
3. Clean, Defensi (GREEN): Minimal, maintainable production code satisfies functional specifications while using safe design patterns (allow-lists, parameterized queries, least pri).
4. Local Refactoring & Deterministic Scanning (REFACTOR): Fast local checks (linting, test suite regression passes, secret detection, Semgrep SAST) code quality before commits.
5. Continuous Quality & Security E: When edge cases, bugs, or security patterns are resolved, the framework captures the lesson into CONTEXT.md and SKILL.md so the entire team and agent fleet learn permanently.
6. No Hea Required: All state is managed transparently Markdown (CONTEXT.md, threat_model.md) and append-only logs (.security-gate/).
> [!TIP]
> Living Exemplar (Dogfooded in this Repository): We use this exact Secure TDD workflow to update and maintain this framework itself! Readers can inspect the live threat_model.md generated during Phase A (which models the framework's own pre-push hook gates and trust boundaries) and the comprehensive test co across tests/ and .agents/tests/ written test-first during Phase B as real, working examples.
---
This framework brings together two inspirations:
1. TDD & Continuous : Drawing on the engineering discipline of TDD and Paul Hammond's pioneering work where rapid feedback loops, high confidence, and test-first design enable de to ship reliably and move fast.
2. Modular Agent Skill Architectures: Inspired by research into agentic reasoning and specialized skill structures, including Google's Mantis project.
CONTEXT.md, threat_model.md), and local deterministic pre-push hooks run offline.SKILL.md files directly when new con or edge cases are resolved.git, pytest, unittest, local linters) without requiring hea infrastructure or out-of-band audit cycles.SKILL.md packages. De can freely adopt, customize, or extend whiche suit their project (e.g. adding custom domain linters, specialized QA runbooks, or tailored threat models).CONTEXT.md, threat_model.md) and append-only logs (.security-gate/).---
#### Phase A: Planning, Functional Scoping & Threat Modeling (Plan Phase)
threat_model_assessorCONTEXT.md to identify existing trust boundaries, data flows, and appro.threat_model.md at the workspace root, establishing both Functional and Security Acceptance Criteria.#### Phase B: Functional & Security Test-First Case Creation (Red Phase)
security_test_writer#### Phase C: Clean Defensi (Green Phase)
defensipydantic), and allow-lists o regex.#### Phase D: Refactoring, Quality, Context & Continuous E (Refactor Phase)
local_refactor_scanner, skill_eCONTEXT.md)*: Extract systemic lessons, appro, and newly established con, appending them directly to CONTEXT.md under ## 4. Continuous E: Auto-E Con.SKILL.md)*: If a recurring anti-pattern, tricky edge case, or specialized QA/security workflow was identified, suggest or apply updates to SKILL.md instructions so future AI agent sessions inherit the rule upfront and avoid repeating the mistake.##### Security Gate Hook Flow (Sequential Pipeline & Loop)
> TDD Principles & Continuous E in Hook Remediation:
> Every automated fix follows the TDD cycle rather than applying isolated code patches:
> 1. Add Boundary Test First (RED): A test case reproducing the finding or boundary constraint is added to the test suite and confirmed failing.
> 2. Apply Minimal Fix (GREEN): The defensive code change is applied to satisfy the failing test.
> 3. Full Suite Regression : The complete test suite is executed across all existing unit and integration tests to confirm that existing functionality is preserved and regressions are caught early.
> 4. Cross-Stage Context Import: Fixes applied during the Stage 1 deterministic scan are imported into Stage 2 so the contextual AI engine them against semantic constraints. If a Stage 1 fix cannot pass tests within 3 attempts, the unresol is imported directly into Stage 2 for multi-file contextual remediation.
> 5. Detailed Commit Documentation: Auto-commits include structured commit bodies detailing why the security test was added, the threat model boundary addressed, the fix implemented, and test passing confirmation.
> 6. Local Context & Skill E: When enabled, the hook appends newly con directly to the directory-level CONTEXT.md and outputs actionable suggestions for updating relevant SKILL.md files so future agent sessions avoid repeating the issue.
The security gate hook supports modular scanning engines. Both scanners are optional:
PATH.semgrep is not installed, the pipeline skips Stage 1 and proceeds directly to Stage 2 (cm). If neither scanner is installed, the hook logs an informational notice and allows the push to proceed normally..agents/lib/ is structured so teams can integrate alternati down the road (such as Wiz Code or Semgrep Pro for Stage 1, or custom engines for Stage 2).#### 1. Semgrep (Stage 1: Open-Source Deterministic AST Scanner)
Semgrep runs fast local pattern checks against open-source rules without sending code off your machine.
Installation:
#### 2. CodeMender CLI (cm - Stage 2: Semantic Analysis & Remediation)
CodeMender provides semantic code analysis and multi-file contextual auto-remediation.
Installation & Setup:
1. Authenticate with Google Cloud:
2. Download the cm binary for your platform:
3. Extract and place on PATH:
4. Initialize your project:
---
This repository (secure-tdd-agent-framework) serves as the canonical upstream single source of truth for all skills, rules, threat models, and hook scripts.
Instead of maintaining redundant duplicate folders, the framework automatically builds and synchronizes dedicated downstream distributions:
secure-tdd-antigravity: Dedicated Antigravity workspace package containing .agents/, AGENTS.md, and CONTEXT.md.secure-tdd-claude-code: Dedicated Claude Code CLI package containing .claude/ (with kebab-case skills and bash hooks), CLAUDE.md, and CONTEXT.md.sync_downstream.py distributes them cleanly to their nati:| Platform | Rule / Workflow Location | Purpose & Discovery Mechanism |
| :--- | :--- | :--- |
| Antigravity | .agents/rules/secure_tdd_workflow.md | Auto-discovered from .agents/rules/ with trigger: always_on. |
| Claude Code | CLAUDE.md (Project Root) | Auto-loaded by Claude Code on session start as the project system prompt. |
| Uni Agents | AGENTS.md (Project Root) | Uni reference document for any AI coding assistant or de. |
| Shared Context | CONTEXT.md & threat_model.md | Living architectural boundaries, helpers, and STRIDE acceptance criteria. |
---
SKILL.md instructions, add custom domain helpers to CONTEXT.md, and configure your own test commands without needing approval from a centralized committee.security_test_writer: Translates a finding into an explicit, reproducing test asserting the boundary constraint before touching code.defensi: Applies minimal code modifications using established helpers and parameterization to satisfy the test.local_refactor_scanner: Executes the full local regression test suite to confirm existing functional behavior is preserved.CONTEXT.md as its primary reference:CONTEXT.md.Recommended Remediation Sequence for Legacy Applications:
1. Initial Hotspot Triage: Run dedicated scanning and review tools like Mantis or CodeMender to identify high-risk components and compile an in of findings.
2. Establish Baseline Functional Test Co: Before modifying application logic, generate functional characterization tests for the target component until all existing paths pass green.
- *Example Prompt for Coding Agent*:
> "Analyze [target_module.py] and its callers. Write characterization unit and integration tests co the existing happy paths, parameter handling, and return contracts. Confirm all tests pass green against current behavior before applying any security modifications."
3. Incremental Secure TDD Fixes: Once baseline functional tests are passing green, address security findings one by one: write a reproducing boundary test (RED), apply the defensive fix using appro (GREEN), and confirm all existing legacy tests continue to pass.
---
---
Whene are made to skills, rules, or hook scripts in this repository, the downstream repositories are updated automatically:
post-commit Hook.git/hooks/post-commit to automatically run sync_downstream.py --commit on every commit in this repository.main.---
*Output: 10 tests passed ( both functional happy paths and security boundary rejection).*
*Output: 76/76 mock tests passing (38 per test harness) across PASS, AD, ERROR, BLOCKED, FIXED, and PIPELINE outcomes.*
---
Licensed under the Apache License, 2.0.
开发语言:Shell
Star 数:2
该项目属于防护思路方向的开源资源,代码结构清晰,适合安全研究人员学习参考。项目围绕Test-Driven Development agent framework with integrated threat modeling, defensive coding, security review hooks, and self-evolving skills for AI coding agents.展开,提供了可运行的实现,对理解相关安全机制、工具原理与攻防技术具有较高的研究价值。
从技术实现角度看,此类项目的核心在于对底层原理的深入理解与工程化落地。开发者在研究过程中可以结合官方文档与社区讨论,梳理项目的初始化流程、核心模块职责与数据流转,逐步掌握其中的技术细节与设计思路。
1. 下载源码压缩包,解压到本地环境。
2. 根据项目类型准备对应的运行环境与依赖。
3. 按照 README 中的步骤完成配置与部署。
4. 在隔离的测试环境中运行验证,避免影响生产系统。
本资源来源于开源社区,仅供安全研究、技术学习与合法授权范围内的攻防演练使用,请勿用于任何非法或侵害他人权益的用途。使用本项目产生的一切后果由使用者自行承担。
| 资源标题 | secure-tdd-agent-framework - Test-Driven Development agent framework with integ |
| 所属分类 | 防护思路 |
| 发布作者 | admin |
| 发布时间 | 2026-10-06 00:20:31 |
| 下载权限 | 免费下载 |
| 附件数量 | 2 个下载链接 |
| 浏览次数 | 122 |
| 讨论数量 | 0 |
| 主题状态 | 正常讨论中 |