This document is the canonical reference guide for AI coding agents operating in this repository. It defines the core philosophy, the 4-phase Secure TDD inner-loop workflow, data contracts, and tool conventions.
Test-Driven Development (TDD) involves writing tests before implementation clarifies requirements, verifies functional correctness, documents system behavior, and catches regressions early.
Traditionally, software teams treat functional development and security testing as disconnected workflows—features are written first, and security is bolted on later via delayed post-merge scans or third-party audits (leading to 20–70 day remediation cycles and high rework costs).
This framework unites functional engineering and security into a single test-first workflow:
- TDD for Features & Quality: Features, enhancements, and bug fixes are developed using incremental, test-first cycles (RED -> GREEN -> REFACTOR).
- Security as Part of Quality: Security is an inseparable aspect of software quality. When security patches are developed in isolation without functional tests, they risk breaking production behavior and introducing regressions. Co-verifying security and functionality supports operational stability.
- Security Added at Every Phase: Architectural trust zones and threat models are considered during planning; security invariants (authentication, input allow-lists, safe sinks, least privilege) are codified into tests alongside functional acceptance criteria.
- Fast, Local Feedback: Developers and AI agents catch functional bugs and security flaws locally before code is committed or pushed.
+-----------------------------------------+
| 1. PLAN |
| - Ingest CONTEXT.md |
| - Functional Specs & Scoping |
| - STRIDE Threat Model (threat_model.md)|
+--------------------+--------------------+
|
v
+-----------------------------------------+
| 2. RED |
| - Functional QA Tests (Happy Paths) |
| - Edge Cases & Boundary Handling |
| - Security Boundary Tests (Assert RED) |
+--------------------+--------------------+
|
v
+-----------------------------------------+
| 3. GREEN |
| - Clean, Functional & Defensive Code |
| - Satisfy Functional & Security Tests |
+--------------------+--------------------+
|
v
+-----------------------------------------+
| 4. REFACTOR & EVOLVE |
| - Code Quality & Regression Tests |
| - Local Scans & Guided Review |
| - Update CONTEXT.md & Evolve Skills |
+--------------------+--------------------+
|
+--- Continuous Evolution ---+
- Skill:
threat_model_assessor - Ingest
CONTEXT.mdto identify existing architecture, trust boundaries, and approved helpers. - Decompose the task into functional deliverables, user stories, and acceptance criteria.
- Perform STRIDE assessment on the proposed change to identify trust boundaries and security constraints.
- Generate or update
threat_model.mdat the workspace root, establishing both Functional and Security Acceptance Criteria.
- Skill:
security_test_writer - Author unit and integration tests asserting:
- Functional Correctness: Happy-path user journeys, business logic execution, expected outputs (e.g. HTTP 200/302).
- Edge Cases & Error Handling: Missing parameters, malformed payloads, out-of-boundary values.
- Security Boundaries: Access control rejections (HTTP 401/403), input validation failures (HTTP 400), injection resistance.
- Adhere to the Three Verification Pillars:
- Behavior-driven HTTP/API outcomes (assert on contract responses and status codes).
- Strict test isolation (transaction rollbacks, fresh contexts).
- Integration over fragile mocking (real test contexts over superficial mocks).
- Run the test suite and verify tests fail for the expected assertion reason (RED).
- Skill:
defensive_developer - Author clean, modular, and maintainable production code to satisfy all failing tests and deliver the feature.
- Adhere to the Three Defensive Pillars:
- Strict input validation (allow-lists, typed schemas with
pydantic). - Explicit authorization & caller identity verification.
- Least privilege data payloads & parameterized sinks.
- Strict input validation (allow-lists, typed schemas with
- Run the test suite and confirm all tests pass cleanly (GREEN).
- Skill:
local_refactor_scanner - Clean up code, eliminate duplication, improve maintainability, and verify 100% passing regression tests.
- Execute fast deterministic scans locally (secrets, dependencies, Semgrep / CodeMender).
- Conduct a guided AI review to verify business logic, edge cases, and eliminate design flaws.
- Keep diffs small, surgical, and focused on preserving baseline stability.
- Skill:
skill_evolution_updater - On resolving a tricky bug, establishing a new pattern, or introducing a helper, extract the systemic rule.
- Append the rule to
CONTEXT.mdunder## 4. Continuous Evolution: Auto-Evolved Conventionsor updateSKILL.mdinstructions. - All future agent sessions inherit these rules upfront.
- When resolving multiple findings from a scan or gate rejection, process them sequentially one finding at a time:
- Author one discrete boundary test for the finding (RED).
- Implement the minimal defensive fix (GREEN).
- Verify the local test passes before moving to the next finding.
- Avoid batching multiple unrelated edits into a single unverified change. Full regression suites run after each individual finding is verified.
- No Database Required: All state is managed via plain Markdown (
CONTEXT.md,threat_model.md) and append-only logs (.security-gate/findings-log.ndjson). - Deterministic Pre-Push Gate: On
git push, the local hook intercepts the push to scan modified files so clean, tested code reaches remote repositories.