{ "code": 200, "data": { "description": "AICL — AI-Centric Language: A specification-first programming language where risks, recoveries, and validations are mandatory syntactic elements - AICL/src/aicl/autonomous.py at main · AFKmoney/AICL", "external": { "alternate": { "https://github.githubassets.com/favicons/favicon.png": { "class": "js-site-favicon", "type": "image/png" } }, "assets": { "https://github.githubassets.com/": {} }, "dns-prefetch": { "https://avatars.githubusercontent.com/": {}, "https://github-cloud.s3.amazonaws.com/": {}, "https://github.githubassets.com/": {}, "https://user-images.githubusercontent.com/": {} }, "fluid-icon": { "https://github.com/fluidicon.png": { "title": "GitHub" } }, "icon": { "https://github.githubassets.com/favicons/favicon.png": { "class": "js-site-favicon", "type": "image/png" }, "https://github.githubassets.com/favicons/favicon.svg": { "class": "js-site-favicon", "data-base-href": "https://github.githubassets.com/favicons/favicon", "type": "image/svg+xml" } }, "manifest": { "https://github.com/manifest.json": { "crossorigin": "use-credentials" } }, "mask-icon": { "https://github.githubassets.com/assets/pinned-octocat-093da3e6fa40.svg": { "color": "#000000" } }, "preconnect": { "https://avatars.githubusercontent.com/": {}, "https://github.githubassets.com/": { "crossorigin": "" } }, "search": { "https://github.com/opensearch.xml": { "title": "GitHub", "type": "application/opensearchdescription+xml" } } }, "html": "\n \n \n \n \n \n \n \n\n \n\n\n \n\n \n\n \n \n \n \n \n\n\n \n\n \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n \n \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n \n\n\n\n\n\n\n AICL/src/aicl/autonomous.py at main · AFKmoney/AICL · GitHub\n\n\n\n \n \n \n \n\n \n \n\n\n \n\n\n \n\n\n \n \n\n \n \n\n \n\n\n\n\n\n\n\n \n\n \n\n\n\n\n \n\n \n\n \n\n \n\n \n\n \n\n \n \n \n\n \n \n \n\n\n\n\n \n\n\n\n \n\n\n \n \n \n \n\n \n\n \n\n \n\n \n\n \n \n\n\n\n \n\n \n \n\n\n \n\n \n\n \n \n\n \n \n \n\n\n\n\n\n \n\n \n\n \n
\n
\n \n\n
\n Skip to content\n\n \n \n \n \n \n\n\n\n \n \n
\n
\n\n\n\n\n\n \n\n \n\n \n\n\n\n\n\n\n
\n

Navigation Menu

\n\n \n\n
\n
\n
\n \n
\n\n \n \n \n\n \n\n
\n \n Sign in\n \n
\n \n Appearance settings\n\n \n \n \n\n\n\n \n \n
\n
\n\n\n
\n
\n\n
\n
\n\n\n
\n
\n \n\n\n\n \n \n
\n
\n\n\n\n
\n \n\n\n\n
\n \n\n \n\n \n
\n \n

Search code, repositories, users, issues, pull requests...

\n
\n \n
\n
\n\n
\n
\n
\n \n
\n \n\n \n
\n
\n
\n

\n Provide feedback\n

\n \n
\n
\n \n
\n
\n \n
\n \n
\n

We read every piece of feedback, and take your input very seriously.

\n \n \n \n
\n
\n \n
\n\n \n \n\n \n
\n
\n
\n

\n Saved searches\n

\n

Use saved searches to filter your results more quickly

\n
\n
\n \n
\n
\n \n
\n \n
\n\n \n\n
\n
\n
\n\n
\n
\n \n
\n
\n
\n
\n\n\n \n\n \n Sign up\n \n\n
\n \n Appearance settings\n\n \n \n \n\n\n\n \n \n
\n
\n\n\n
\n
\n\n \n
\n
\n
\n
\n
\n\n \n
\n\n
\n\n\n\n\n\n\n\n\n
\n\n\n\n\n \n
\n\n\n \n\n\n\n\n\n\n
\n
\n
\n \n \n\n\n\n\n\n\n\n \n\n
\n\n
\n\n
\n \n
\n \n \n\n \n \n \n AFKmoney\n \n /\n \n AICL\n \n\n Public\n
\n\n\n
\n\n
\n \n\n
\n
\n\n
\n
\n\n\n \n\n
\n \n\n\n\n\n
\n \n\n\n\n \n \n \n\n\n\n\n\n\n\n\n\n \n \n

Collapse file tree

Files

Search this repository(forward slash) forward slash/
/

autonomous.py

Copy path
More file actions
More file actions

Latest commit

c65d989 · Jun 13, 2026

History

History
Open commit details
History
1134 lines (970 loc) · 45 KB
/

autonomous.py

Copy path

File metadata and controls

1134 lines (970 loc) · 45 KB
Copy raw file
Download raw file
You must be signed in to make or propose changes
More edit options
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
\"\"\"
AICL Autonomous Compilation System — Self-Writing, Self-Validating Code
\n
The central thesis: a compiler that cannot explain why it generated a line
should not generate it. This module extends that thesis to its logical
conclusion: a compiler that can diagnose its own failures, fix its own
specifications, learn new patterns, and validate its own output — all
while preserving the No-Orphan Property.
\n
The Autonomous Compilation Loop:
SPEC → COMPILE → VERIFY → TEST → DIAGNOSE → FIX → RECOMPILE
↑ │
└──────────────────────────────────────┘
\n
Every iteration of the loop preserves the provenance chain. Every fix
is recorded. Every learned pattern is tracked. The loop converges when:
1. Spec verification passes (completeness, coherence, satisfaction)
2. Audit coverage = 1.0 (no orphans)
3. All generated tests pass
4. No fallback compilations remain
5. Improvement score converges (delta < threshold)
\n
New ProvenanceTypes added by this module:
- AI_GENERATION: Code generated by AI-assisted fallback
- SELF_HEALING: Code fixed by autonomous diagnosis
- PATTERN_LEARNED: New pattern learned from unmatched actions
- SPEC_EVOLVED: Specification modified by autonomous evolution
\n
Usage:
aicl evolve <source.aicl> [--max-iterations 10] [--no-ai]
aicl evolve <source.aicl> --watch # continuous mode
\"\"\"
\n
import os
import re
import sys
import json
import time
import hashlib
import subprocess
import tempfile
import shutil
import traceback
from dataclasses import dataclass, field
from typing import List, Dict, Optional, Tuple, Set, Any
from enum import Enum
\n
from .provenance import ProvenanceType
\n
\n
class LoopState(Enum):
\"\"\"State of the autonomous compilation loop.\"\"\"
INITIALIZING = \"initializing\"
COMPILING = \"compiling\"
VERIFYING = \"verifying\"
TESTING = \"testing\"
DIAGNOSING = \"diagnosing\"
FIXING = \"fixing\"
LEARNING = \"learning\"
CONVERGED = \"converged\"
FAILED = \"failed\"
TIMED_OUT = \"timed_out\"
\n
\n
@dataclass
class LoopIteration:
\"\"\"Record of a single loop iteration.\"\"\"
iteration: int
state_entered: LoopState
timestamp_start: float
state_exited: LoopState = LoopState.INITIALIZING
timestamp_end: float = 0.0
spec_changes: List[str] = field(default_factory=list)
patterns_learned: List[str] = field(default_factory=list)
tests_passed: int = 0
tests_failed: int = 0
tests_total: int = 0
audit_coverage: float = 0.0
fallback_count: int = 0
provenance_records_added: int = 0
errors: List[str] = field(default_factory=list)
fixes_applied: List[str] = field(default_factory=list)
\n
@property
def duration(self) -> float:
return self.timestamp_end - self.timestamp_start
\n
@property
def success(self) -> bool:
return (
self.tests_failed == 0
and self.tests_total > 0
and self.audit_coverage >= 1.0
and self.fallback_count == 0
)
\n
\n
@dataclass
class AutonomousResult:
\"\"\"Final result of an autonomous compilation session.\"\"\"
converged: bool
iterations: List[LoopIteration]
total_duration: float
final_audit_coverage: float
final_test_pass_rate: float
patterns_learned: List[str]
spec_evolution: List[str]
convergence_iteration: Optional[int] = None
proof_valid: bool = False
\n
@property
def summary(self) -> str:
lines = [
f\"Converged: {self.converged}\",
f\"Iterations: {len(self.iterations)}\",
f\"Duration: {self.total_duration:.2f}s\",
f\"Audit Coverage: {self.final_audit_coverage:.1%}\",
f\"Test Pass Rate: {self.final_test_pass_rate:.1%}\",
f\"Patterns Learned: {len(self.patterns_learned)}\",
f\"Spec Changes: {len(self.spec_evolution)}\",
f\"Proof Valid: {self.proof_valid}\",
]
if self.convergence_iteration is not None:
lines.append(f\"Converged at iteration: {self.convergence_iteration}\")
return \"\\n\".join(lines)
\n
\n
class TestRunner:
\"\"\"Execute generated tests and analyze failures.\"\"\"
\n
def __init__(self, timeout: int = 30):
self.timeout = timeout
self.last_results: Dict[str, Any] = {}
\n
def run_tests(self, output_dir: str) -> Tuple[int, int, int, List[Dict]]:
\"\"\"
Run pytest on the generated test file.
Returns (passed, failed, total, failure_details).
\"\"\"
test_file = os.path.join(output_dir, \"test_main.py\")
if not os.path.exists(test_file):
return 0, 0, 0, [{\"error\": \"No test file found\"}]
\n
# Try to find pytest - check venv first, then system
pytest_path = shutil.which(\"pytest\")
python_path = sys.executable
\n
try:
cmd = [python_path, \"-m\", \"pytest\", test_file, \"-v\", \"--tb=short\", \"--no-header\"]
result = subprocess.run(
cmd,
capture_output=True,
text=True,
timeout=self.timeout,
cwd=output_dir,
)
except subprocess.TimeoutExpired:
return 0, 0, 0, [{\"error\": f\"Test execution timed out after {self.timeout}s\"}]
except Exception as e:
return 0, 0, 0, [{\"error\": f\"Test execution failed: {str(e)}\"}]
\n
# Parse pytest output
passed, failed, total = 0, 0, 0
failure_details = []
converged=self.loop_controller.is_converged,
iterations=self.loop_controller.iterations,
total_duration=total_duration,
final_audit_coverage=final_coverage,
final_test_pass_rate=final_pass_rate,
patterns_learned=[
p[\"name\"] for p in self.pattern_learner.learned_patterns.values()
],
spec_evolution=[
entry[\"change\"] for entry in self.spec_evolver.evolution_log
],
convergence_iteration=self.loop_controller.convergence_iteration,
proof_valid=proof_valid,
)
\n
\n
def format_evolve_report(result: AutonomousResult) -> str:
\"\"\"Format an AutonomousResult into a readable report.\"\"\"
lines = [
\"=\" * 70,
\"AICL AUTONOMOUS COMPILATION REPORT\",
\"=\" * 70,
\"\",
f\" Converged: {result.converged}\",
f\" Total Duration: {result.total_duration:.2f}s\",
f\" Iterations: {len(result.iterations)}\",
f\" Audit Coverage: {result.final_audit_coverage:.1%}\",
f\" Test Pass Rate: {result.final_test_pass_rate:.1%}\",
f\" Proof Valid: {result.proof_valid}\",
\"\",
]
\n
if result.convergence_iteration is not None:
lines.append(f\" Converged at: Iteration {result.convergence_iteration}\")
else:
lines.append(f\" Converged at: N/A (did not converge)\")
\n
lines.append(\"\")
\n
# Patterns learned
if result.patterns_learned:
lines.append(\"PATTERNS LEARNED:\")
for p in result.patterns_learned:
lines.append(f\" - {p}\")
lines.append(\"\")
\n
# Spec evolution
if result.spec_evolution:
lines.append(\"SPECIFICATION EVOLUTION:\")
for change in result.spec_evolution:
lines.append(f\" - {change}\")
lines.append(\"\")
\n
# Iteration details
lines.append(\"ITERATION DETAILS:\")
lines.append(\"-\" * 70)
for it in result.iterations:
status = \"✓ CONVERGED\" if it.success else \"→ ITERATING\"
lines.append(
f\" [{it.iteration}] {status} \"
f\"coverage={it.audit_coverage:.1%} \"
f\"tests={it.tests_passed}/{it.tests_total} \"
f\"fallbacks={it.fallback_count} \"
f\"fixes={len(it.fixes_applied)} \"
f\"patterns={len(it.patterns_learned)} \"
f\"({it.duration:.2f}s)\"
)
if it.errors:
for err in it.errors[:3]:
lines.append(f\" ⚠ {err[:80]}\")
lines.append(\"-\" * 70)
lines.append(\"\")
\n
return \"\\n\".join(lines)
\n
\n\n\n\n\n
\n\n
\n\n
\n
\n\n
\n\n \n\n\n\n \n\n\n\n\n \n\n \n\n
\n
\n
\n\n \n\n\n\n\n\n
\n
\n
\n \n\n\n
", "metadata": { "analytics-location": "///blob/show", "apple-itunes-app": "app-id=1477376905, app-argument=https://github.com/AFKmoney/AICL/blob/main/src/aicl/autonomous.py", "browser-errors-url": "https://api.github.com/_private/browser/errors", "browser-stats-url": "https://api.github.com/_private/browser/stats", "color-scheme": "light dark", "current-catalog-service-hash": "f3abb0cc802f3d7b95fc8762b94bdcb13bf39634c40c357301c4aa1d67a256fb", "description": "AICL — AI-Centric Language: A specification-first programming language where risks, recoveries, and validations are mandatory syntactic elements - AICL/src/aicl/autonomous.py at main · AFKmoney/AICL", "disable-turbo": "false", "expected-hostname": "github.com", "fb:app_id": "1401488693436528", "fetch-nonce": "v2:61d81cbd-6324-7960-3633-26bd1e313380", "github-keyboard-shortcuts": "repository,source-code,file-tree,copilot", "go-import": "github.com/AFKmoney/AICL git https://github.com/AFKmoney/AICL.git", "google-site-verification": "Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I", "hostname": "github.com", "hovercard-subject-tag": "repository:1267732957", "html-safe-nonce": "e3136b009cbcb5d7af47fdd9040f2ada2c2df32a18c34ac6c83e96478201389a", "lang": "en", "octolytics-dimension-repository_id": "1267732957", "octolytics-dimension-repository_is_fork": "false", "octolytics-dimension-repository_network_root_id": "1267732957", "octolytics-dimension-repository_network_root_nwo": "AFKmoney/AICL", "octolytics-dimension-repository_nwo": "AFKmoney/AICL", "octolytics-dimension-repository_public": "true", "octolytics-dimension-user_id": "221682733", "octolytics-dimension-user_login": "AFKmoney", "octolytics-url": "https://collector.github.com/github/collect", "og:description": "AICL — AI-Centric Language: A specification-first programming language where risks, recoveries, and validations are mandatory syntactic elements - AFKmoney/AICL", "og:image": "https://opengraph.githubassets.com/d555ba09ba6153ec5fff09566101cdfc63d41310be43da91a981b8a2b3673861/AFKmoney/AICL", "og:image:alt": "AICL — AI-Centric Language: A specification-first programming language where risks, recoveries, and validations are mandatory syntactic elements - AFKmoney/AICL", "og:image:height": "600", "og:image:width": "1200", "og:site_name": "GitHub", "og:title": "AICL/src/aicl/autonomous.py at main · AFKmoney/AICL", "og:type": "object", "og:url": "https://github.com/AFKmoney/AICL/blob/main/src/aicl/autonomous.py", "release": "3f244c05cbe64c2455314b1780ba7b42e978858d", "request-id": "9043:1D0FBE:C357DE8:C5E0D47:6A2DA1D6", "route-action": "show", "route-controller": "blob", "route-pattern": "/:user_id/:repository/blob/*name(/*path)", "theme-color": "#1e2327", "turbo-body-classes": "logged-out env-production page-responsive", "turbo-cache-control": [ "no-preview", "no-cache" ], "twitter:card": "summary_large_image", "twitter:description": "AICL — AI-Centric Language: A specification-first programming language where risks, recoveries, and validations are mandatory syntactic elements - AFKmoney/AICL", "twitter:image": "https://opengraph.githubassets.com/d555ba09ba6153ec5fff09566101cdfc63d41310be43da91a981b8a2b3673861/AFKmoney/AICL", "twitter:site": "@github", "twitter:title": "AICL/src/aicl/autonomous.py at main · AFKmoney/AICL", "ui-target": "full", "user-login": "", "viewport": "width=device-width", "visitor-hmac": "886a42ecc216f3137a60ddff0d43e377f33c8b42e6d4df92709a92850a1068fa", "visitor-payload": "eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MDQzOjFEMEZCRTpDMzU3REU4OkM1RTBENDc6NkEyREExRDYiLCJ2aXNpdG9yX2lkIjoiNzE4MTg5MTY5Njc4NDY3OTM4MiIsInJlZ2lvbl9lZGdlIjoic2VhIiwicmVnaW9uX3JlbmRlciI6InNlYSJ9" }, "title": "AICL/src/aicl/autonomous.py at main · AFKmoney/AICL", "url": "https://github.com/AFKmoney/AICL/blob/main/src/aicl/autonomous.py", "usage": { "tokens": 221439 } }, "meta": { "usage": { "tokens": 221439 } }, "status": 20000 }