ai-engineering-loop 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +272 -0
  3. package/adapters/dot/README.md +55 -0
  4. package/adapters/dot/coreview.md +88 -0
  5. package/adapters/dot/gitlab.md +128 -0
  6. package/adapters/dot/mattermost.md +102 -0
  7. package/adapters/dot/multi-branch.md +89 -0
  8. package/agents/devil-advocate.md +111 -0
  9. package/agents/judge.md +69 -0
  10. package/agents/maker.md +66 -0
  11. package/bin/ai-engineering-loop.js +633 -0
  12. package/core/configuration-precedence.md +102 -0
  13. package/core/context-impact-assessment.md +127 -0
  14. package/core/context-refresh-policy.md +116 -0
  15. package/core/definition-of-done.md +79 -0
  16. package/core/escalation-policy.md +99 -0
  17. package/core/goal-contract.md +88 -0
  18. package/core/iteration-policy.md +108 -0
  19. package/core/judge-policy.md +123 -0
  20. package/core/project-initialization.md +97 -0
  21. package/core/repo-config-schema.md +72 -0
  22. package/core/verification-loop.md +97 -0
  23. package/docs/antigravity-feasibility.md +90 -0
  24. package/docs/migration-plan.md +70 -0
  25. package/examples/backend-api/payment-idempotency/README.md +33 -0
  26. package/examples/backend-api/payment-idempotency/goal-contract.md +33 -0
  27. package/examples/backend-api/payment-idempotency/judge-verdict.md +28 -0
  28. package/examples/backend-api/payment-idempotency/review-findings.md +50 -0
  29. package/examples/dot/attendance-confirmation/README.md +22 -0
  30. package/examples/dot/attendance-confirmation/delivery-report.md +51 -0
  31. package/examples/dot/attendance-confirmation/goal-contract.md +39 -0
  32. package/examples/dot/attendance-confirmation/judge-verdict.md +43 -0
  33. package/examples/dot/attendance-confirmation/review-findings.md +57 -0
  34. package/examples/initialization/README.md +19 -0
  35. package/examples/initialization/discovery-trace.md +63 -0
  36. package/examples/initialization/generated-context.md +110 -0
  37. package/examples/mobile-app/offline-sync-queue/README.md +33 -0
  38. package/examples/mobile-app/offline-sync-queue/goal-contract.md +32 -0
  39. package/examples/mobile-app/offline-sync-queue/judge-verdict.md +27 -0
  40. package/examples/mobile-app/offline-sync-queue/review-findings.md +30 -0
  41. package/package.json +31 -0
  42. package/policies/discovery-safety-policy.md +51 -0
  43. package/policies/evidence-policy.md +70 -0
  44. package/policies/finding-policy.md +102 -0
  45. package/policies/no-progress-policy.md +92 -0
  46. package/profiles/README.md +42 -0
  47. package/profiles/backend-api.md +64 -0
  48. package/profiles/library.md +51 -0
  49. package/profiles/mobile-app.md +59 -0
  50. package/profiles/monorepo.md +46 -0
  51. package/profiles/web-app.md +65 -0
  52. package/scripts/init.sh +85 -0
  53. package/templates/repo-config/adapter.md +11 -0
  54. package/templates/repo-config/architecture.md +15 -0
  55. package/templates/repo-config/config.md +11 -0
  56. package/templates/repo-config/conventions.md +16 -0
  57. package/templates/repo-config/verification.md +13 -0
@@ -0,0 +1,30 @@
1
+ # Adversarial Review Findings: Offline Sync Queue
2
+
3
+ ## 1. Review Summary
4
+ - **Reviewer**: Devil's Advocate Agent (Profile: `mobile-app`)
5
+ - **Active Review Domains**: Offline Sync, Lifecycle, Permissions, Battery/Network Hygiene
6
+ - **Total Findings**: 1
7
+ - **Blocking (SEV-1/2)**: 1
8
+
9
+ ---
10
+
11
+ ## 2. Findings Ledger
12
+
13
+ ### Finding ERR-001: Missing unhandled SQLite disk full exception handling
14
+ - **Severity**: `HIGH` (SEV-2)
15
+ - **Category**: `Error Handling & Persistence`
16
+ - **Location**: `lib/core/sync/sqlite_mutation_store.dart:45-56`
17
+ - **Evidence**:
18
+ ```dart
19
+ await _db.insert('mutation_queue', item.toMap());
20
+ ```
21
+ - **Problem**:
22
+ If the device filesystem runs out of storage space (common on low-end inspection tablets), `_db.insert()` throws an unhandled `DatabaseException` that bubbles up and crashes the UI layer, preventing the user from navigating or seeing an alert.
23
+ - **Impact**:
24
+ App crash on disk full errors with uninformative logs.
25
+ - **Recommendation**:
26
+ Wrap write operations in domain-specific `StorageException` handling and surface a user-friendly "Device Storage Low" snackbar notification.
27
+ - **Confidence**: `HIGH`
28
+ - **Status**: `TRIAGED_VALID`
29
+ - **Resolution**:
30
+ Maker Agent wrapped repository writes in `try/catch (DatabaseException)` with fallback error telemetry and added unit test `should throw StorageFullException gracefully when disk is full`.
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "ai-engineering-loop",
3
+ "version": "1.0.0",
4
+ "description": "A reusable, framework-agnostic AI Engineering Operating System for autonomous coding agents.",
5
+ "main": "bin/ai-engineering-loop.js",
6
+ "bin": {
7
+ "ai-engineering-loop": "bin/ai-engineering-loop.js"
8
+ },
9
+ "scripts": {
10
+ "init": "node bin/ai-engineering-loop.js"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/egagofur/ai-engineering-loop.git"
15
+ },
16
+ "keywords": [
17
+ "ai-agents",
18
+ "agentic-workflow",
19
+ "software-engineering",
20
+ "devils-advocate",
21
+ "verification",
22
+ "autonomous-agents",
23
+ "antigravity"
24
+ ],
25
+ "author": "Ega Gofur",
26
+ "license": "MIT",
27
+ "bugs": {
28
+ "url": "https://github.com/egagofur/ai-engineering-loop/issues"
29
+ },
30
+ "homepage": "https://github.com/egagofur/ai-engineering-loop#readme"
31
+ }
@@ -0,0 +1,51 @@
1
+ # Discovery Safety Policy Specification
2
+
3
+ ## 1. Principle & Core Rule
4
+
5
+ Project initialization and context discovery is a **read-mostly, non-destructive operation**.
6
+
7
+ Its sole objective is to inspect repository topology, manifests, and architecture to generate or update `.ai-engineering-loop/`. It must never alter production application code or compromise security.
8
+
9
+ ---
10
+
11
+ ## 2. Strictly Prohibited Actions During Discovery
12
+
13
+ An agent executing project initialization MUST NEVER:
14
+
15
+ ```mermaid
16
+ flowchart TD
17
+ Init[Discovery & Initialization Phase] --> Prohibited[STRICTLY PROHIBITED ACTIONS]
18
+
19
+ Prohibited --> P1[1. Secret Leakage: Never inspect .env, tokens, credentials, private keys]
20
+ Prohibited --> P2[2. Code Mutation: Never modify application code, config, or tests]
21
+ Prohibited --> P3[3. File Deletion: Never delete any files in the repository]
22
+ Prohibited --> P4[4. Git Mutations: Never commit, create branches, or push during init]
23
+ Prohibited --> P5[5. Disruptive Commands: Never run database migrations or destructive scripts]
24
+ ```
25
+
26
+ ### 1. Secret & Credential Inspection
27
+ - **Prohibited Files**: `.env`, `.env.local`, `.env.production`, `id_rsa`, `*.pem`, `*.key`, `credentials.json`, `secrets.yaml`, `.netrc`.
28
+ - **Permitted Files**: `.env.example`, `.env.sample`, `config.example.json` (template files containing no real secret values).
29
+ - **Rule**: If an agent inadvertently reads a file containing API keys or database passwords, it is **strictly forbidden** from copying or referencing those values in `.ai-engineering-loop/`.
30
+
31
+ ### 2. Application Code Mutation
32
+ - The agent must not edit `src/`, `apps/`, `packages/`, or any configuration files outside of `.ai-engineering-loop/` during the initialization stage.
33
+
34
+ ### 3. File Deletion
35
+ - The agent must not delete any files, directories, or caches during discovery.
36
+
37
+ ### 4. Git Mutations
38
+ - The agent must not execute `git commit`, `git checkout -b`, `git push`, or `git reset` during initialization. Git commands are strictly restricted to read-only inspection (`git status`, `git log -n 5`, `git remote -v`).
39
+
40
+ ### 5. Disruptive Commands
41
+ - The agent must not execute live database migrations (`prisma migrate dev`, `alembic upgrade head`) or destructive test cleanup scripts during discovery.
42
+
43
+ ---
44
+
45
+ ## 3. Permitted Actions During Discovery
46
+
47
+ The only actions authorized during project initialization are:
48
+
49
+ 1. **Read-Only Inspection**: Reading repository directories, file trees, package manifests, configuration files, and documentation.
50
+ 2. **Writing Context Files**: Creating or updating markdown files strictly within `<workspace-root>/.ai-engineering-loop/`.
51
+ 3. **Informational Git Queries**: Running `git status`, `git remote -v`, and `git log -n 5 --stat`.
@@ -0,0 +1,70 @@
1
+ # Evidence Policy Specification
2
+
3
+ ## 1. Principle & Core Law
4
+
5
+ The foundational premise of the AI Engineering Loop is:
6
+
7
+ > **Claims without verifiable evidence are invalid.**
8
+
9
+ An agent may not state that code is functional, bug-free, optimized, or ready for merge based on assumption or conversational confidence. Every positive and negative claim throughout the loop must be substantiated by demonstrable proof.
10
+
11
+ ---
12
+
13
+ ## 2. The Evidence Hierarchy
14
+
15
+ Evidence is ranked in order of reliability and truth value:
16
+
17
+ ```mermaid
18
+ flowchart TD
19
+ E1[Level 1: Deterministic Machine Execution<br>Unit tests, CLI exit codes, compiler output]
20
+ E2[Level 2: Concrete Codebase Artifacts<br>Actual file contents, git commit history, schema files]
21
+ E3[Level 3: Adversarial Code Diffs<br>Exact before/after reproduction snippets]
22
+ E4[Level 4: Theoretical / Analytical Deduction<br>Reasoning through architectural implications]
23
+ E5[Level 5: Unsupported Assertion<br>'Looks correct', 'Should work fine' - REJECTED]
24
+
25
+ E1 --> E2 --> E3 --> E4 -.-> E5
26
+ ```
27
+
28
+ ### Level 1: Deterministic Machine Execution (Highest Proof)
29
+ - Automated unit/integration test results with full test names, assertions, and exit codes.
30
+ - Compiler / typechecker outputs (`tsc --noEmit`, `cargo check`).
31
+ - Linter execution reports with zero errors.
32
+ - Real-time build artifacts and exit statuses.
33
+
34
+ ### Level 2: Concrete Codebase Artifacts
35
+ - Direct citations of existing repository files, functions, database schemas, and configuration keys with explicit file paths and line ranges.
36
+ - Git commit logs (`git log -n 5 -p`) and git blame history proving past behavior.
37
+
38
+ ### Level 3: Adversarial Code Diffs
39
+ - Concrete code diffs demonstrating an edge case or proposing a surgical fix.
40
+
41
+ ### Level 4: Analytical Deduction
42
+ - Structured logical deduction mapping user workflows to code paths. Acceptable for brainstorming and initial analysis, but must be validated by Level 1 or Level 2 before completion.
43
+
44
+ ### Level 5: Unsupported Assertions (Strictly Prohibited)
45
+ - Vague statements of confidence (*"I am confident this fixes the problem"*).
46
+ - Claiming a test passed without running the command.
47
+ - Assuming an API exists without checking `node_modules` or codebase imports.
48
+ - **Action**: The Judge Agent automatically invalidates any finding or completion claim backed only by Level 5 assertions.
49
+
50
+ ---
51
+
52
+ ## 3. Evidence Requirements for Common Agent Claims
53
+
54
+ | Claim Type | Mandatory Evidence Required | Prohibited Substitute |
55
+ |---|---|---|
56
+ | **"Bug is fixed"** | Reproducing test that previously failed now passes with exit code 0. | "The logic was corrected." |
57
+ | **"No regressions"** | Full test suite execution log showing 0 failures. | "I only touched a single function." |
58
+ | **"Type safe"** | `tsc --noEmit` / compiler run output with 0 errors. | "I added type annotations." |
59
+ | **"Review finding is invalid (Halu)"** | File path & line showing the suggested API does not exist or behavior is intentional. | "I disagree with the reviewer." |
60
+ | **"Acceptance criteria AC-X met"** | Test function name & assertion specifically targeting AC-X. | "Implemented according to spec." |
61
+
62
+ ---
63
+
64
+ ## 4. Evidentiary Audit Trail
65
+
66
+ Every artifact created during the engineering loop (Goal Contract, Maker Log, Review Findings, Judge Verdict) must maintain an unbroken chain of evidence:
67
+
68
+ 1. **Exact Commands Run**: Included in verbatim code blocks.
69
+ 2. **Standard Output / Error Logs**: Verbatim output snippets without truncation of error counts.
70
+ 3. **Traceable File Links**: Every cited file must use clickable format (`file:///path/to/file#L1-L10`).
@@ -0,0 +1,102 @@
1
+ # Finding Policy Specification
2
+
3
+ ## 1. Purpose
4
+
5
+ The **Finding Policy** defines the standardized schema, severity definitions, categories, and lifecycle states for all issues identified by review agents (such as the [Devil's Advocate](file:///Users/egagofur/Development/work/ai-engineering-loop/agents/devil-advocate.md) or external review bots).
6
+
7
+ A standardized finding schema ensures that:
8
+ 1. Every criticism is actionable, localized, and backed by evidence.
9
+ 2. Review findings can be parsed, hashed, and tracked across autonomous iterations.
10
+ 3. The [Judge Agent](file:///Users/egagofur/Development/work/ai-engineering-loop/agents/judge.md) can evaluate findings objectively without subjective ambiguity.
11
+
12
+ ---
13
+
14
+ ## 2. Standardized Finding Schema
15
+
16
+ Every finding MUST be structured according to the following specification:
17
+
18
+ ```yaml
19
+ id: "<CATEGORY_PREFIX>-<3_DIGIT_NUMBER>" # e.g. COR-001, SEC-002, PERF-001
20
+ title: "<Short, descriptive summary of the problem>"
21
+ severity: "<CRITICAL | HIGH | MEDIUM | LOW | INFO>"
22
+ category: "<Correctness | ErrorHandling | Security | Concurrency | Performance | Maintainability | TestingGaps>"
23
+ location:
24
+ file: "<Relative file path>"
25
+ startLine: <Integer>
26
+ endLine: <Integer>
27
+ evidence: "<Exact code snippet, command output, or trace exhibiting the flaw>"
28
+ problem: "<Detailed technical explanation of what is wrong>"
29
+ impact: "<Concrete operational, business, or runtime consequence>"
30
+ recommendation: "<Actionable suggestion and concrete code diff showing the fix>"
31
+ confidence: "<HIGH | MEDIUM | LOW>"
32
+ status: "<NEW | TRIAGED_VALID | TRIAGED_INVALID | TRIAGED_UNCERTAIN | RESOLVED | VERIFIED>"
33
+ triageReason: "<Required when status is TRIAGED_INVALID or TRIAGED_UNCERTAIN>"
34
+ ```
35
+
36
+ ---
37
+
38
+ ## 3. Severity Matrix & Definitions
39
+
40
+ | Severity Level | Definition | Impact on Build / Loop |
41
+ |---|---|---|
42
+ | **`CRITICAL` (SEV-1)** | Complete system crash, remote code execution, severe data corruption, authentication bypass, or massive data loss. | **BLOCKING**: Hard block. Must be resolved immediately; cannot pass DoD. |
43
+ | **`HIGH` (SEV-2)** | Core business logic defect, unhandled null exception on primary user path, IDOR/authorization gap, or significant performance regression. | **BLOCKING**: Must be resolved before `PASS` verdict. |
44
+ | **`MEDIUM` (SEV-3)** | Edge-case logic failure, missing error telemetry, suboptimal query with limited dataset, or unhandled rare boundary condition. | **NON-BLOCKING**: Can pass DoD if documented in backlog, unless directly violating an Acceptance Criterion. |
45
+ | **`LOW` (SEV-4)** | Minor maintainability issue, non-critical testing gap, minor code duplication, or naming ambiguity. | **ADVISORY**: Does not block completion. |
46
+ | **`INFO` (SEV-5)** | Informational observation, architectural note, or praise for a well-designed pattern. | **INFORMATIONAL**: No action required. |
47
+
48
+ ---
49
+
50
+ ## 4. Review Categories
51
+
52
+ Findings are categorized under one of the 7 standard domains:
53
+
54
+ 1. **`Correctness` (`COR`)**: Functional bugs, logic errors, type mismatches, inverted conditionals, timezone bugs, calculation errors.
55
+ 2. **`ErrorHandling` (`ERR`)**: Swallowed errors, unhandled rejections, missing fallbacks, crashing async boundaries.
56
+ 3. **`Security` (`SEC`)**: Injection, broken auth/access control, secret exposure, sensitive data logging, unsanitized inputs.
57
+ 4. **`Concurrency` (`CONC`)**: Race conditions, un-synchronized shared memory, non-atomic database operations, thread safety issues.
58
+ 5. **`Performance` (`PERF`)**: N+1 queries, memory leaks, unbounded array loops, unindexed filters, heavy synchronous blocking operations.
59
+ 6. **`Maintainability` (`MAINT`)**: High coupling, breaking existing architecture, anti-patterns, dead code, circular dependencies.
60
+ 7. **`TestingGaps` (`TEST`)**: Untested boundary conditions, weak/tautological assertions, missing negative test cases.
61
+
62
+ ---
63
+
64
+ ## 5. Finding Status & Validity Rules
65
+
66
+ Review findings are hypotheses, not absolute truths. Every finding exists in one of the following states:
67
+
68
+ - **`NEW`**: Initial discovery by reviewer.
69
+ - **`TRIAGED_VALID`**: Author and Judge confirm that the defect is real and violates technical or contract requirements. Must be fixed by Maker.
70
+ - **`TRIAGED_INVALID` (False Positive / "Halu")**: Author demonstrates with evidence that the reviewer's concern is factually incorrect, based on an API that does not exist, or flags intentional/designed behavior.
71
+ - **`TRIAGED_UNCERTAIN`**: Ambiguous requirement where the codebase documentation is silent or contradictory. Triggers escalation.
72
+ - **`RESOLVED`**: Maker has applied code fix and passing test suite.
73
+ - **`VERIFIED`**: Devil's Advocate and Judge re-evaluated and confirmed the issue is fully solved.
74
+
75
+ ---
76
+
77
+ ## 6. Concrete Example
78
+
79
+ ```yaml
80
+ id: "COR-001"
81
+ title: "Unsafe timezone conversion in attendance clock-in calculation"
82
+ severity: "HIGH"
83
+ category: "Correctness"
84
+ location:
85
+ file: "src/server/attendance/utils/calculate-duration.ts"
86
+ startLine: 28
87
+ endLine: 34
88
+ evidence: |
89
+ const checkInHour = new Date(record.clockIn).getHours();
90
+ problem: |
91
+ Using Date.prototype.getHours() extracts the local server timezone hour instead of converting to the employee's designated timezone (e.g. Asia/Jakarta).
92
+ impact: |
93
+ Employees clocking in between 00:00 and 07:00 UTC will be marked as late or absent depending on the server hosting region.
94
+ recommendation: |
95
+ Use timezone-aware date parsing with dayjs/date-fns-tz:
96
+ ```diff
97
+ - const checkInHour = new Date(record.clockIn).getHours();
98
+ + const checkInHour = dayjs(record.clockIn).tz(userTimezone).hour();
99
+ ```
100
+ confidence: "HIGH"
101
+ status: "TRIAGED_VALID"
102
+ ```
@@ -0,0 +1,92 @@
1
+ # No-Progress Policy Specification
2
+
3
+ ## 1. Overview & Objective
4
+
5
+ A major risk in autonomous AI agent loops is **thrashing (stagnation)**: the agent modifies code repeatedly across iterations without actually resolving the underlying defect, oscillating between two broken states, or generating the same unresolved findings repeatedly.
6
+
7
+ The **No-Progress Policy** defines an algorithmic mechanism to detect stagnation early and halt the loop with a [Human Escalation](file:///Users/egagofur/Development/work/ai-engineering-loop/core/escalation-policy.md) rather than wasting tokens and computational cycles.
8
+
9
+ ```mermaid
10
+ flowchart LR
11
+ Iter1[Iteration 1: Finding A] --> Iter2[Iteration 2: Finding A]
12
+ Iter2 --> Detect{No-Progress Detector}
13
+ Detect -->|Signatures Match & No Code Progress| Halt([ABORT LOOP ──▶ ESCALATE])
14
+ Detect -->|Demonstrated Progress / New Resolved State| Continue([CONTINUE LOOP])
15
+ ```
16
+
17
+ ---
18
+
19
+ ## 2. Finding Signature Hashing
20
+
21
+ To detect recurring findings objectively across iterations, each active finding is assigned a **Finding Signature**:
22
+
23
+ $$\text{Signature} = \text{Hash}\Big(\text{Category} + \text{File Location} + \text{Core Problem Concept}\Big)$$
24
+
25
+ ### Signature Formula Components:
26
+ 1. **Category**: One of `Correctness`, `Security`, `ErrorHandling`, etc.
27
+ 2. **Normalized Location**: File path and functional block (e.g. `src/server/attendance/service.ts:calculateDuration`).
28
+ 3. **Core Issue Key**: Normalized problem keywords (e.g. `timezone-conversion-utc`, `null-pointer-overtime-note`, `missing-auth-tenant-id`).
29
+
30
+ ---
31
+
32
+ ## 3. Stagnation Detection Criteria
33
+
34
+ Stagnation is detected if any of the following rules evaluate to `TRUE`:
35
+
36
+ ### Criterion 1: Identical Unresolved Finding Across 2 Consecutive Iterations
37
+ - If Iteration $K$ produces an unresolved blocking finding with the exact same Signature as Iteration $K-1$, AND the Maker Agent's diff did not change the underlying logic block.
38
+
39
+ ### Criterion 2: Oscillating Diffs (Ping-Pong State)
40
+ - If the diff generated in Iteration $K$ reverts the codebase back to the state of Iteration $K-2$.
41
+
42
+ ### Criterion 3: Persistent Deterministic Failure
43
+ - If the exact same unit test or compiler error fails in Iteration $K$ after the Maker Agent attempted a fix in Iteration $K-1$.
44
+
45
+ ### Criterion 4: Scope Divergence / Thrashing
46
+ - If the Maker Agent modifies more than $3\times$ the number of lines or files compared to Iteration 1 without resolving the original Acceptance Criteria (indicating uncontrolled thrashing).
47
+
48
+ ---
49
+
50
+ ## 4. Operational Algorithm
51
+
52
+ ```python
53
+ def check_stagnation(
54
+ current_iteration: int,
55
+ iteration_history: list[IterationRecord]
56
+ ) -> tuple[bool, str]:
57
+ if current_iteration < 2:
58
+ return False, "Initial iteration"
59
+
60
+ prev_record = iteration_history[current_iteration - 2]
61
+ curr_record = iteration_history[current_iteration - 1]
62
+
63
+ # Check 1: Recurring blocking finding signatures
64
+ prev_blocking = {f.signature for f in prev_record.unresolved_blocking_findings}
65
+ curr_blocking = {f.signature for f in curr_record.unresolved_blocking_findings}
66
+
67
+ recurring = prev_blocking.intersection(curr_blocking)
68
+ if recurring and curr_record.diff_hash == prev_record.diff_hash:
69
+ return True, f"Identical unresolved findings {recurring} with no effective diff progress"
70
+
71
+ # Check 2: Ping-Pong reversion
72
+ if current_iteration >= 3:
73
+ two_back_record = iteration_history[current_iteration - 3]
74
+ if curr_record.diff_hash == two_back_record.diff_hash:
75
+ return True, "Oscillating diff detected (reverted to state from 2 iterations ago)"
76
+
77
+ # Check 3: Identical deterministic failure
78
+ if (curr_record.deterministic_errors == prev_record.deterministic_errors and
79
+ len(curr_record.deterministic_errors) > 0):
80
+ return True, f"Deterministic check failed with identical errors across iterations: {curr_record.deterministic_errors}"
81
+
82
+ return False, "Progress verified"
83
+ ```
84
+
85
+ ---
86
+
87
+ ## 5. Escalation Action
88
+
89
+ When `check_stagnation` returns `True`:
90
+ 1. The Judge Agent immediately sets the verdict to **`ESCALATE`**.
91
+ 2. Autonomous iteration stops.
92
+ 3. The agent generates the standardized [Human Escalation Report](file:///Users/egagofur/Development/work/ai-engineering-loop/core/escalation-policy.md) highlighting the recurring signature and exact blocking contradiction.
@@ -0,0 +1,42 @@
1
+ # Project Profiles Specification
2
+
3
+ ## 1. Purpose & Core Concept
4
+
5
+ A **Project Profile** describes the engineering characteristics, verification expectations, common risk areas, and active review domains of a broad software archetype without modifying the generic core engineering loop.
6
+
7
+ ```mermaid
8
+ flowchart TD
9
+ Core[AI Engineering Loop Core] --> Selector{Resolve Project Profile}
10
+
11
+ Selector --> P1[profiles/web-app.md]
12
+ Selector --> P2[profiles/backend-api.md]
13
+ Selector --> P3[profiles/mobile-app.md]
14
+ Selector --> P4[profiles/library.md]
15
+ Selector --> P5[profiles/monorepo.md]
16
+
17
+ P1 & P2 & P3 & P4 & P5 --> CustomContext[Contextualized Maker, Reviewer & Verifier]
18
+ ```
19
+
20
+ ---
21
+
22
+ ## 2. Standard Profile Catalog
23
+
24
+ | Profile | Target Archetype | Primary Verification Focus | Active Review Domains |
25
+ |---|---|---|---|
26
+ | **[`web-app`](file:///Users/egagofur/Development/work/ai-engineering-loop/profiles/web-app.md)** | Single-Page Apps, SSR/SSG websites, Admin Portals | DOM rendering, browser responsiveness, bundle size, CSS/tokens | Responsive layout, accessibility (a11y), client state, Core Web Vitals |
27
+ | **[`backend-api`](file:///Users/egagofur/Development/work/ai-engineering-loop/profiles/backend-api.md)** | REST / GraphQL / gRPC Microservices, Background Workers | Unit tests, database migrations, schema contracts | Auth/Authz, SQL injection, concurrency, transactions, API contracts |
28
+ | **[`mobile-app`](file:///Users/egagofur/Development/work/ai-engineering-loop/profiles/mobile-app.md)** | iOS, Android, React Native, Flutter | Platform builds, simulator smoke tests, widget tests | Offline sync, device permissions, lifecycle transitions, network resilience |
29
+ | **[`library`](file:///Users/egagofur/Development/work/ai-engineering-loop/profiles/library.md)** | Reusable SDKs, packages, shared utilities | Broad runtime compatibility, zero external dependencies | Public API stability, semver breaking changes, bundle tree-shaking |
30
+ | **[`monorepo`](file:///Users/egagofur/Development/work/ai-engineering-loop/profiles/monorepo.md)** | Turborepo, Nx, Lerna, Yarn/pnpm Workspaces | Workspace scope tests, affected package compilation | Cross-package boundaries, circular dependencies, dependency isolation |
31
+
32
+ ---
33
+
34
+ ## 3. Profile Discovery & Binding
35
+
36
+ 1. **Explicit Binding**: Declared in `<repo>/.ai-engineering-loop/config.md` via `project_profile: <name>`.
37
+ 2. **Implicit Auto-Detection**: If `.ai-engineering-loop/` is absent, the engine inspects repository manifest files:
38
+ - `flutter.yaml` / `ios/` / `android/` $\rightarrow$ `mobile-app`
39
+ - `turbo.json` / `nx.json` / `pnpm-workspace.yaml` $\rightarrow$ `monorepo`
40
+ - `next.config.js` / `vite.config.ts` / `index.html` $\rightarrow$ `web-app`
41
+ - `Dockerfile` / `go.mod` / `requirements.txt` $\rightarrow$ `backend-api`
42
+ - `rollup.config.js` / `tsup.config.ts` / `"main": "dist/..."` $\rightarrow$ `library`
@@ -0,0 +1,64 @@
1
+ # Project Profile: `backend-api`
2
+
3
+ ## 1. Profile Definition
4
+
5
+ - **Archetype**: Backend Services, REST / tRPC / GraphQL / gRPC APIs, Microservices, Background Workers (Node.js/TypeScript, Go, Python, Java, Rust, Elixir).
6
+ - **Core Environment**: Server runtimes, databases (PostgreSQL, MySQL, MongoDB, Redis), message queues (Kafka, RabbitMQ), containerized infrastructure.
7
+
8
+ ---
9
+
10
+ ## 2. Engineering & Architecture Characteristics
11
+
12
+ - **Layered Clean Architecture**: Strict boundaries between Transport/Controllers $\rightarrow$ Domain Services $\rightarrow$ Data Repositories $\rightarrow$ Infrastructure.
13
+ - **Data Integrity & ACID**: Explicit transaction boundaries for multi-table mutations. Zero partial database writes on mid-operation failures.
14
+ - **Idempotency**: Critical endpoints (e.g. payment, billing, order placement) must implement idempotent processing via unique request tokens or database unique constraints.
15
+ - **API Contract Discipline**: Strict schema validation on input payloads and response shapes (`zod`, `pydantic`, `protobuf`).
16
+
17
+ ---
18
+
19
+ ## 3. Verification Expectations
20
+
21
+ When working in a `backend-api` repository, deterministic verification should prioritize:
22
+
23
+ 1. **Unit & Domain Tests**: Fast, isolated tests of domain services and calculation logic.
24
+ 2. **Integration / DB Tests**: Real or test-container database tests validating transaction rollbacks, unique constraints, and foreign key integrity.
25
+ 3. **Static Typing / Linting**: `tsc --noEmit`, `golangci-lint`, `ruff`, `mypy`.
26
+ 4. **Schema Contract Validation**: Verifying that OpenAPI / GraphQL / protobuf contracts have not broken backwards compatibility.
27
+ 5. **Database Migration Checks**: Dry-run migration execution and rollback tests.
28
+
29
+ ---
30
+
31
+ ## 4. Active Review Domains for Devil's Advocate
32
+
33
+ When reviewing diffs in a `backend-api` project, the [Devil's Advocate](file:///Users/egagofur/Development/work/ai-engineering-loop/agents/devil-advocate.md) activates these targeted checks:
34
+
35
+ ```mermaid
36
+ flowchart LR
37
+ DA[Devil's Advocate] --> R1[1. Authorization & Tenant Isolation]
38
+ DA --> R2[2. Database Transactions & Atomicity]
39
+ DA --> R3[3. Concurrency & Race Conditions]
40
+ DA --> R4[4. Query Performance & N+1 Loops]
41
+ DA --> R5[5. API Contract Backwards Compatibility]
42
+ DA --> R6[6. Input Validation & Injection]
43
+ ```
44
+
45
+ ### 1. Authorization & Tenant Isolation (IDOR)
46
+ - Does the endpoint verify that the requesting user has access to the requested entity (`tenant_id` / `org_id` / `user_id` check), or does it blindly trust IDs supplied in the request body/path?
47
+
48
+ ### 2. Database Transactions & Atomicity
49
+ - If multiple database writes occur in one business operation, are they wrapped inside an explicit database transaction with rollback on error?
50
+
51
+ ### 3. Concurrency & Race Conditions
52
+ - Can two concurrent requests for the same user cause double spending, duplicate voucher redemptions, or negative inventory balances?
53
+ - Are optimistic locks (e.g. `version` column) or database-level row locks (`SELECT FOR UPDATE`) used where necessary?
54
+
55
+ ### 4. Query Performance & N+1 Loops
56
+ - Are relational queries executing queries in a loop (`for item in items: db.query(...)`) instead of using joins or batch fetching (`IN (...)` / dataloaders)?
57
+ - Are new `WHERE` or `ORDER BY` filters supported by database indexes?
58
+
59
+ ### 5. API Contract Compatibility
60
+ - Does the change remove or rename an existing response field that could break existing mobile or web clients in production?
61
+
62
+ ### 6. Input Validation & Injection
63
+ - Are inputs validated using schema parsers before reaching domain logic?
64
+ - Are database queries constructed safely via parameterization?
@@ -0,0 +1,51 @@
1
+ # Project Profile: `library`
2
+
3
+ ## 1. Profile Definition
4
+
5
+ - **Archetype**: Reusable SDKs, Shared Packages, npm/PyPI/crates/Go modules, Open Source Libraries.
6
+ - **Core Environment**: Diverse downstream host runtimes, varied Node/browser versions, zero assumption about host application architecture.
7
+
8
+ ---
9
+
10
+ ## 2. Engineering & Architecture Characteristics
11
+
12
+ - **Semantic Versioning & Public API Stability**: Strict adherence to SemVer. Zero breaking changes on exported function signatures or interfaces in minor/patch releases.
13
+ - **Minimal Dependencies**: Extreme reluctance to introduce third-party transitive dependencies. Prefer native standard libraries.
14
+ - **Tree-Shaking & Bundle Efficiency**: Clean ES Module / CommonJS dual packaging, side-effect free declarations (`"sideEffects": false`).
15
+ - **Comprehensive TypeScript Declarations**: Exported `.d.ts` definitions with complete JSDoc annotations and strong generics.
16
+
17
+ ---
18
+
19
+ ## 3. Verification Expectations
20
+
21
+ 1. **Compatibility Matrix Testing**: Unit tests executed across multiple runtime versions (e.g. Node 18, 20, 22).
22
+ 2. **API Surface & Type Tests**: Type-level regression tests (e.g. `tsd`, `expect-type`) ensuring type inference remains intact for consumers.
23
+ 3. **Packaging & Export Tests**: Build tools (`tsup`, `rollup`, `pkgroll`) verifying that output bundles export all expected entrypoints.
24
+ 4. **Zero-Dependency Audit**: Dependency vulnerability and size audit.
25
+
26
+ ---
27
+
28
+ ## 4. Active Review Domains for Devil's Advocate
29
+
30
+ When reviewing diffs in a `library` project, the [Devil's Advocate](file:///Users/egagofur/Development/work/ai-engineering-loop/agents/devil-advocate.md) activates these targeted checks:
31
+
32
+ ```mermaid
33
+ flowchart LR
34
+ DA[Devil's Advocate] --> R1[1. Public API Breaking Changes]
35
+ DA --> R2[2. Unwanted Dependency Bloat]
36
+ DA --> R3[3. Cross-Runtime Compatibility]
37
+ DA --> R4[4. Tree-Shaking & Side-Effects]
38
+ DA --> R5[5. Type Inference Regressions]
39
+ ```
40
+
41
+ ### 1. Public API Breaking Changes
42
+ - Does modifying this parameter or return type break existing consumers who update within the same major version?
43
+
44
+ ### 2. Unwanted Dependency Bloat
45
+ - Is a new dependency being pulled in for something that could be written in 10 lines of standard library code?
46
+
47
+ ### 3. Cross-Runtime Compatibility
48
+ - Does the code rely on Node.js-specific globals (`process`, `Buffer`, `fs`) in a package intended to also run in browser or edge runtimes (Cloudflare Workers, Deno)?
49
+
50
+ ### 4. Tree-Shaking & Side-Effects
51
+ - Does importing a single utility from the package accidentally cause the entire library to be bundled by Webpack/Vite?
@@ -0,0 +1,59 @@
1
+ # Project Profile: `mobile-app`
2
+
3
+ ## 1. Profile Definition
4
+
5
+ - **Archetype**: Native & Cross-Platform Mobile Applications (iOS / Swift, Android / Kotlin, Flutter / Dart, React Native).
6
+ - **Core Environment**: Mobile operating systems (iOS, Android), intermittent network connectivity, constrained memory and battery, background lifecycle states.
7
+
8
+ ---
9
+
10
+ ## 2. Engineering & Architecture Characteristics
11
+
12
+ - **Offline-First & Resilience**: Expect network loss at any time. State must persist locally (SQLite, Room, CoreData, Hive, WatermelonDB) and synchronize reliably upon reconnection.
13
+ - **Platform Lifecycle Handling**: Gracefully handle backgrounding, app suspension, memory pressure warnings, and foreground resumption.
14
+ - **State Management**: Reactive state architecture (Bloc, Riverpod, Redux, Zustand, Combine, StateFlow) with single source of truth.
15
+ - **Secure Device Storage**: Sensitive credentials (auth tokens, encryption keys) stored in iOS Keychain or Android Keystore / EncryptedSharedPreferences.
16
+
17
+ ---
18
+
19
+ ## 3. Verification Expectations
20
+
21
+ When working in a `mobile-app` repository, deterministic verification should prioritize:
22
+
23
+ 1. **Unit & Logic Testing**: Pure Dart/Kotlin/Swift unit tests on stores, state notifiers, repository mappers, and sync algorithms.
24
+ 2. **Widget & Component Testing**: Testing component rendering, user taps, and navigation state.
25
+ 3. **Static Analysis & Typechecks**: `dart analyze`, `flutter test`, `swiftlint`, `ktlint`, `detekt`.
26
+ 4. **Native Build Validation**: `flutter build bundle`, `xcodebuild build-for-testing`, `./gradlew assembleDebug`.
27
+ 5. **Offline Scenario Simulation**: Unit tests verifying behavior when network repository throws `SocketException` or returns 503.
28
+
29
+ ---
30
+
31
+ ## 4. Active Review Domains for Devil's Advocate
32
+
33
+ When reviewing diffs in a `mobile-app` project, the [Devil's Advocate](file:///Users/egagofur/Development/work/ai-engineering-loop/agents/devil-advocate.md) activates these targeted checks:
34
+
35
+ ```mermaid
36
+ flowchart LR
37
+ DA[Devil's Advocate] --> R1[1. Offline Sync & Conflict Resolution]
38
+ DA --> R2[2. Platform Lifecycle & State Loss]
39
+ DA --> R3[3. Permission Rejection Handling]
40
+ DA --> R4[4. Battery & Network Hygiene]
41
+ DA --> R5[5. Secure Credential Storage]
42
+ ```
43
+
44
+ ### 1. Offline Sync & Conflict Resolution
45
+ - Does the code properly enqueue mutations when offline, or will unsaved user data be lost if the network drops before submit?
46
+ - If the server has a newer version of a record upon sync, does the app have an explicit conflict resolution strategy?
47
+
48
+ ### 2. Platform Lifecycle & State Loss
49
+ - If the operating system kills the app in the background due to memory pressure, does the user return to an empty screen or is essential draft state restored?
50
+
51
+ ### 3. Permission Rejection Handling
52
+ - If the user denies camera, location, or notification permissions, does the app degrade gracefully or enter a crash loop?
53
+
54
+ ### 4. Battery & Network Hygiene
55
+ - Are location listeners, GPS polling, or background timers stopped when the screen is dismissed?
56
+ - Are large images cached appropriately on disk rather than re-downloaded on every scroll?
57
+
58
+ ### 5. Secure Credential Storage
59
+ - Are JWT tokens or API secrets saved in secure hardware-backed storage rather than plain `SharedPreferences` / `UserDefaults`?
@@ -0,0 +1,46 @@
1
+ # Project Profile: `monorepo`
2
+
3
+ ## 1. Profile Definition
4
+
5
+ - **Archetype**: Multi-package workspaces, Turborepo, Nx, Lerna, Cargo workspaces, Go multi-module repositories.
6
+ - **Core Environment**: Shared codebases hosting multiple interdependent apps, services, and shared packages in a single git repository.
7
+
8
+ ---
9
+
10
+ ## 2. Engineering & Architecture Characteristics
11
+
12
+ - **Workspace Boundaries**: Strict dependency rules between packages (e.g. `packages/ui` must not import `apps/web`; shared packages must only depend on approved core libraries).
13
+ - **Internal Dependency Linking**: Use of `workspace:*` references rather than published npm packages for local development.
14
+ - **Incremental Builds & Task Caching**: Optimized task pipelines where unaffected packages are skipped during verification.
15
+
16
+ ---
17
+
18
+ ## 3. Verification Expectations
19
+
20
+ 1. **Scoped & Affected Testing**: Running tests on touched packages and their direct downstream dependents (e.g. `turbo run test --filter=...[origin/main]`).
21
+ 2. **Workspace Typecheck**: Full typecheck across the monorepo root ensuring zero cross-package type breakage.
22
+ 3. **Circular Dependency Checks**: Static analysis tools verifying zero circular package graph dependencies (`madge`, `eslint-plugin-import`).
23
+ 4. **Boundary Linting**: Linters enforcing architecture tags (e.g. Nx boundaries).
24
+
25
+ ---
26
+
27
+ ## 4. Active Review Domains for Devil's Advocate
28
+
29
+ When reviewing diffs in a `monorepo` project, the [Devil's Advocate](file:///Users/egagofur/Development/work/ai-engineering-loop/agents/devil-advocate.md) activates these targeted checks:
30
+
31
+ ```mermaid
32
+ flowchart LR
33
+ DA[Devil's Advocate] --> R1[1. Cross-Package Boundary Leaps]
34
+ DA --> R2[2. Circular Dependency Loops]
35
+ DA --> R3[3. Blast-Radius on Shared Packages]
36
+ DA --> R4[4. Monorepo Cache Invalidation]
37
+ ```
38
+
39
+ ### 1. Cross-Package Boundary Leaps
40
+ - Is a shared package importing code or types from an application-layer package?
41
+
42
+ ### 2. Blast-Radius on Shared Packages
43
+ - If modifying a core utility in `packages/common`, have all consuming applications (`apps/api`, `apps/web`, `apps/mobile`) been verified against breaking changes?
44
+
45
+ ### 3. Circular Dependency Loops
46
+ - Does adding this import introduce a cycle in the monorepo graph?