Qalam commited on
Commit
c0216d4
·
verified ·
1 Parent(s): 471e3f0

Deploy canonical runtime 4af0011 from GitHub Actions

Browse files
__pycache__/app.cpython-311.pyc CHANGED
Binary files a/__pycache__/app.cpython-311.pyc and b/__pycache__/app.cpython-311.pyc differ
 
__pycache__/core_hf.cpython-311.pyc CHANGED
Binary files a/__pycache__/core_hf.cpython-311.pyc and b/__pycache__/core_hf.cpython-311.pyc differ
 
core/autonomy_control.py ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Bounded controls for autonomous research execution.
2
+
3
+ This module deliberately controls orchestration only. It cannot weaken safety
4
+ policies, evaluation thresholds, credential rules or ledger admission gates.
5
+ """
6
+ from __future__ import annotations
7
+
8
+ import json
9
+ import os
10
+ import time
11
+ from contextlib import contextmanager
12
+ from datetime import datetime, timezone
13
+ from pathlib import Path
14
+ from typing import Iterator
15
+
16
+
17
+ STOP_EXIT_CODE = 78
18
+
19
+
20
+ def _truthy(value: str | None, default: bool = False) -> bool:
21
+ if value is None or not value.strip():
22
+ return default
23
+ return value.strip().lower() in {"1", "true", "yes", "on"}
24
+
25
+
26
+ def autonomy_enabled() -> bool:
27
+ return _truthy(os.getenv("AUTONOMY_ENABLED"), default=True)
28
+
29
+
30
+ def emergency_stop_active() -> bool:
31
+ return _truthy(os.getenv("EMERGENCY_STOP"), default=False)
32
+
33
+
34
+ def _state_path(root: Path) -> Path:
35
+ return root / "knowledge_base" / "autonomy_control.json"
36
+
37
+
38
+ def record_event(root: Path, event: str, **details: object) -> None:
39
+ path = _state_path(root)
40
+ path.parent.mkdir(parents=True, exist_ok=True)
41
+ payload = {
42
+ "updated_at": datetime.now(timezone.utc).isoformat(),
43
+ "event": event,
44
+ "details": details,
45
+ }
46
+ path.write_text(json.dumps(payload, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
47
+
48
+
49
+ @contextmanager
50
+ def single_run_lock(root: Path) -> Iterator[None]:
51
+ """Acquire a process lock without leaving a stale lock after normal exit."""
52
+ path = root / "knowledge_base" / ".autonomy.lock"
53
+ path.parent.mkdir(parents=True, exist_ok=True)
54
+ try:
55
+ fd = os.open(path, os.O_CREAT | os.O_EXCL | os.O_WRONLY, 0o600)
56
+ except FileExistsError as exc:
57
+ raise RuntimeError("another autonomous run is already active") from exc
58
+ try:
59
+ os.write(fd, str(os.getpid()).encode("ascii"))
60
+ os.close(fd)
61
+ record_event(root, "started", pid=os.getpid())
62
+ yield
63
+ finally:
64
+ try:
65
+ path.unlink()
66
+ except FileNotFoundError:
67
+ pass
68
+ record_event(root, "finished", pid=os.getpid())
69
+
70
+
71
+ def guard(root: Path) -> int:
72
+ if not autonomy_enabled():
73
+ record_event(root, "disabled")
74
+ return STOP_EXIT_CODE
75
+ if emergency_stop_active():
76
+ record_event(root, "emergency_stop")
77
+ return STOP_EXIT_CODE
78
+ return 0
knowledge_base/knowledge_graph.json CHANGED
@@ -11,9 +11,9 @@
11
  "scientific_accuracy": 92.0,
12
  "novelty_score": 78.0,
13
  "usefulness_score": 85.0,
14
- "created": "2026-08-19T23:02:39.313866"
15
  },
16
- "created": "2026-08-19T23:02:39.313872"
17
  },
18
  "1d94037a7442ae1b": {
19
  "id": "1d94037a7442ae1b",
@@ -25,9 +25,9 @@
25
  "scientific_accuracy": 94.0,
26
  "novelty_score": 82.0,
27
  "usefulness_score": 88.0,
28
- "created": "2026-08-19T23:02:39.313878"
29
  },
30
- "created": "2026-08-19T23:02:39.313881"
31
  }
32
  },
33
  "relationships": [],
 
11
  "scientific_accuracy": 92.0,
12
  "novelty_score": 78.0,
13
  "usefulness_score": 85.0,
14
+ "created": "2026-08-19T23:18:44.887396"
15
  },
16
+ "created": "2026-08-19T23:18:44.887401"
17
  },
18
  "1d94037a7442ae1b": {
19
  "id": "1d94037a7442ae1b",
 
25
  "scientific_accuracy": 94.0,
26
  "novelty_score": 82.0,
27
  "usefulness_score": 88.0,
28
+ "created": "2026-08-19T23:18:44.887407"
29
  },
30
+ "created": "2026-08-19T23:18:44.887415"
31
  }
32
  },
33
  "relationships": [],
knowledge_base/virtual_ledger.json CHANGED
@@ -2,31 +2,31 @@
2
  "chain": [
3
  {
4
  "index": 0,
5
- "timestamp": "2026-08-19T23:02:41.256836",
6
  "transactions": [
7
  {
8
- "tx_id": "8d50babf9315426ae6f799ea",
9
  "sender": "genesis",
10
  "recipient": "system_treasury",
11
  "amount": 0.0,
12
- "timestamp": "2026-08-19T23:02:41.256797",
13
  "metadata": {
14
  "note": "Nuclear Intelligence Genesis Block v1.0.0",
15
  "version": "1.0.0",
16
- "timestamp": "2026-08-19T23:02:41.256791",
17
  "difficulty": 3,
18
  "system": "Nuclear Intelligence Virtual Blockchain"
19
  },
20
- "signature": "79d4a76d904a8d43865b72cc2cf419264a887d543c1897112e05675aa27b4e88b4a96f107856b63723d99b8d51c20357",
21
  "nonce": 0,
22
  "status": "confirmed"
23
  }
24
  ],
25
- "merkle_root": "896fe285d4dda7087c04990371b1888ee4b0a4f0a2af3b2053fb96f0012be498",
26
  "previous_hash": "0000000000000000000000000000000000000000000000000000000000000000",
27
- "nonce": 689,
28
- "hash": "000bd36bdd9118245115e28121171a3069447672b6bea2491415999c6d1e6aa9",
29
- "difficulty": 3,
30
  "miner": "genesis",
31
  "reward": 1.0,
32
  "tx_count": 1,
@@ -36,5 +36,5 @@
36
  "difficulty": 3,
37
  "nes_supply": 0.0,
38
  "total_transactions": 0,
39
- "saved_at": "2026-08-19T23:02:41.261056"
40
  }
 
2
  "chain": [
3
  {
4
  "index": 0,
5
+ "timestamp": "2026-08-19T23:18:46.449901",
6
  "transactions": [
7
  {
8
+ "tx_id": "d265bc60f03bf60cacb513b4",
9
  "sender": "genesis",
10
  "recipient": "system_treasury",
11
  "amount": 0.0,
12
+ "timestamp": "2026-08-19T23:18:46.449875",
13
  "metadata": {
14
  "note": "Nuclear Intelligence Genesis Block v1.0.0",
15
  "version": "1.0.0",
16
+ "timestamp": "2026-08-19T23:18:46.449870",
17
  "difficulty": 3,
18
  "system": "Nuclear Intelligence Virtual Blockchain"
19
  },
20
+ "signature": "b6a4d37283f4753590881c1464de45cfa3ca15f544f5fb4a659099b5c750475b6ac021583fa63fcae30cbd5680832150",
21
  "nonce": 0,
22
  "status": "confirmed"
23
  }
24
  ],
25
+ "merkle_root": "0ba9a8ed95b7f2b6cd529f3d09684bace87905261e1c4efab66800b2120e6b7a",
26
  "previous_hash": "0000000000000000000000000000000000000000000000000000000000000000",
27
+ "nonce": 1001,
28
+ "hash": "031781fb07a426a9cfaf9332c7dde1d1a4d74e5b57f7c245394415a23d0c1eb6",
29
+ "difficulty": 1,
30
  "miner": "genesis",
31
  "reward": 1.0,
32
  "tx_count": 1,
 
36
  "difficulty": 3,
37
  "nes_supply": 0.0,
38
  "total_transactions": 0,
39
+ "saved_at": "2026-08-19T23:18:46.455631"
40
  }
scripts/autonomous_developer.py ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Create a reviewable developer queue from canonical cycle proposals.
2
+
3
+ The agent is intentionally proposal-first: it may prepare documentation and
4
+ quality-work artifacts, but it never edits production code or merges a change.
5
+ """
6
+ from __future__ import annotations
7
+
8
+ import json
9
+ import os
10
+ from datetime import datetime, timezone
11
+ from pathlib import Path
12
+ from typing import Any
13
+
14
+
15
+ MAX_REPORTS = 100
16
+ MAX_PROPOSALS = 50
17
+
18
+
19
+ def _safe(value: Any, limit: int = 500) -> str:
20
+ text = " ".join(str(value or "").split())
21
+ return text[:limit]
22
+
23
+
24
+ def collect(root: Path) -> list[dict[str, str]]:
25
+ proposals: list[dict[str, str]] = []
26
+ reports = sorted((root / "reports").glob("*.json"), key=lambda p: p.stat().st_mtime, reverse=True)
27
+ for report_path in reports[:MAX_REPORTS]:
28
+ try:
29
+ report = json.loads(report_path.read_text(encoding="utf-8"))
30
+ except (OSError, ValueError):
31
+ continue
32
+ governance = report.get("governance") if isinstance(report, dict) else {}
33
+ candidates = governance.get("open_proposals", []) if isinstance(governance, dict) else []
34
+ if not isinstance(candidates, list):
35
+ continue
36
+ for item in candidates:
37
+ if not isinstance(item, dict):
38
+ continue
39
+ proposals.append({
40
+ "title": _safe(item.get("title", "Untitled proposal"), 180),
41
+ "rationale": _safe(item.get("rationale", item.get("reason", ""))),
42
+ "impact": _safe(item.get("impact_area", item.get("area", "quality")), 120),
43
+ "source": report_path.name,
44
+ })
45
+ if len(proposals) >= MAX_PROPOSALS:
46
+ return proposals
47
+ return proposals
48
+
49
+
50
+ def render(proposals: list[dict[str, str]]) -> str:
51
+ now = datetime.now(timezone.utc).isoformat()
52
+ lines = [
53
+ "# Autonomous Developer Queue",
54
+ "",
55
+ f"Generated at `{now}`.",
56
+ "",
57
+ "> This is a review queue, not an authorization to change production code. Every implementation must pass CI and receive human review through a pull request.",
58
+ "",
59
+ ]
60
+ if not proposals:
61
+ lines.append("No new reviewable proposals were found.")
62
+ return "\n".join(lines) + "\n"
63
+ lines.extend(["| Priority | Proposal | Impact | Source |", "|---:|---|---|---|"])
64
+ for index, proposal in enumerate(proposals, start=1):
65
+ title = proposal["title"].replace("|", "-")
66
+ impact = proposal["impact"].replace("|", "-")
67
+ source = proposal["source"].replace("|", "-")
68
+ lines.append(f"| {index} | {title} | {impact} | `{source}` |")
69
+ if proposal["rationale"]:
70
+ lines.append(f"| | Rationale: {proposal['rationale'].replace('|', '-') } | | |")
71
+ lines.extend([
72
+ "",
73
+ "## Required review gates",
74
+ "",
75
+ "1. Confirm the proposal is within peaceful civilian-energy scope.",
76
+ "2. Add or update deterministic tests before implementation.",
77
+ "3. Run safety, health, compile and regression checks.",
78
+ "4. Require human approval before merge or any external write.",
79
+ ])
80
+ return "\n".join(lines) + "\n"
81
+
82
+
83
+ def main() -> int:
84
+ root = Path(os.getenv("NI_PROJECT_ROOT", Path.cwd())).resolve()
85
+ output = root / "reports" / "developer_queue.md"
86
+ output.parent.mkdir(parents=True, exist_ok=True)
87
+ output.write_text(render(collect(root)), encoding="utf-8")
88
+ print(output)
89
+ return 0
90
+
91
+
92
+ if __name__ == "__main__":
93
+ raise SystemExit(main())
scripts/autonomy_tick.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Run one bounded autonomous research tick.
2
+
3
+ The scheduler calls this script. It performs one canonical cycle only and exits;
4
+ it does not become an unbounded daemon and it never publishes secrets.
5
+ """
6
+ from __future__ import annotations
7
+
8
+ import os
9
+ import sys
10
+ from pathlib import Path
11
+
12
+ from core.autonomy_control import guard, record_event, single_run_lock
13
+ from core.runtime import build_runtime
14
+
15
+
16
+ def main() -> int:
17
+ root = Path(os.getenv("NI_PROJECT_ROOT", Path.cwd())).resolve()
18
+ stop_code = guard(root)
19
+ if stop_code:
20
+ return stop_code
21
+ try:
22
+ with single_run_lock(root):
23
+ _, loop, _, settings = build_runtime()
24
+ result = loop.run_cycle(developer_mode=settings.developer_mode)
25
+ payload = result.to_dict()
26
+ record_event(
27
+ root,
28
+ "cycle_completed",
29
+ cycle_id=payload.get("cycle_id"),
30
+ minted=bool(payload.get("minted")),
31
+ provider=payload.get("answer", {}).get("provider"),
32
+ )
33
+ print(payload.get("cycle_id", "cycle-complete"))
34
+ return 0
35
+ except Exception as exc:
36
+ record_event(root, "cycle_failed", error_type=type(exc).__name__)
37
+ print("autonomous cycle failed safely", file=sys.stderr)
38
+ return 1
39
+
40
+
41
+ if __name__ == "__main__":
42
+ raise SystemExit(main())