-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
228 lines (198 loc) · 6.92 KB
/
Copy pathrun.py
File metadata and controls
228 lines (198 loc) · 6.92 KB
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#!/usr/bin/env python3
"""Infinite Commit Machine — Enterprise CLI entrypoint.
CommitCorp Autonomous Historical Expansion Platform.
"""
from __future__ import annotations
import argparse
import sys
from pathlib import Path
from commit_machine.config import ConfigError, load_config
from commit_machine.diagnostics import DiagnosticsService
from commit_machine.git_manager import GitManager
from commit_machine.logger import setup_logging
from commit_machine.orchestrator import Orchestrator
from commit_machine.state import load_state
from commit_machine.statistics import StatisticsService
from commit_machine.version_manager import VersionManager
# =============================================================================
# Chronological cadence — edit these to control batch timing and size.
# These override config.json when running via run.py.
# =============================================================================
SECONDS_BETWEEN_COMMITS = 0
# How many separate commits to create each cycle (each to a different file).
COMMITS_PER_CYCLE = 5
# One file per commit in the batch. Length should match COMMITS_PER_CYCLE.
TARGET_FILES = [
"generated/history.txt",
"generated/chronology.txt",
"generated/ledger.txt",
"generated/expansion.txt",
"generated/continuity.txt",
]
def build_parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(
prog="run.py",
description=(
"Infinite Commit Machine — Enterprise Historical Expansion Platform"
),
)
parser.add_argument(
"--config",
default="config.json",
help="Path to enterprise configuration JSON",
)
parser.add_argument(
"--once",
action="store_true",
help="Execute a single chronological cycle and exit",
)
parser.add_argument(
"--stats",
action="store_true",
help="Display the enterprise statistics ledger",
)
parser.add_argument(
"--dashboard",
action="store_true",
help="Render the live operational dashboard once",
)
parser.add_argument(
"--doctor",
action="store_true",
help="Run Temporal Integrity diagnostics",
)
parser.add_argument(
"--health",
action="store_true",
help="Assess repository health",
)
parser.add_argument(
"--entropy",
action="store_true",
help="Display current entropy assessment",
)
parser.add_argument(
"--forecast",
action="store_true",
help="Project the one-million-commit date",
)
parser.add_argument(
"--celebrate",
action="store_true",
help="Display a ceremonial release celebration for the current version",
)
parser.add_argument(
"--push-now",
action="store_true",
help="Synchronise the remote chronological ledger immediately",
)
parser.add_argument(
"--dry-run",
action="store_true",
help="Simulate chronology without mutating Git history",
)
parser.add_argument(
"--reset",
action="store_true",
help="Reset persisted runtime state to greenfield",
)
return parser
def _diag_from_config(config_path: Path) -> DiagnosticsService:
cfg = load_config(config_path)
cfg.sleep_seconds = SECONDS_BETWEEN_COMMITS
git = GitManager(cfg.repo_path())
state = load_state(cfg.state_path())
stats = StatisticsService(cfg.stats_path()).snapshot()
return DiagnosticsService(cfg, git, state, stats)
def main(argv: list[str] | None = None) -> int:
parser = build_parser()
args = parser.parse_args(argv)
config_path = Path(args.config)
try:
cfg = load_config(config_path)
except ConfigError as exc:
print(f"Configuration compliance failure: {exc}", file=sys.stderr)
return 2
cfg.sleep_seconds = SECONDS_BETWEEN_COMMITS
setup_logging(cfg.log_path())
# Read-only / diagnostic commands (no orchestrator loop)
if args.stats or args.doctor or args.health or args.entropy or args.forecast:
diag = _diag_from_config(config_path)
if args.doctor:
print(diag.doctor_text())
if args.health:
print(diag.health_text())
if args.entropy:
print(diag.entropy_text())
if args.forecast:
print(diag.forecast_text())
if args.stats:
print(diag.stats_text())
return 0
orch = Orchestrator(
config_path,
dry_run=args.dry_run,
show_dashboard=True if args.dashboard and not args.once else None,
sleep_seconds_override=SECONDS_BETWEEN_COMMITS,
commits_per_cycle_override=COMMITS_PER_CYCLE,
target_files_override=TARGET_FILES,
)
if args.reset:
orch.reset_state()
print("Runtime state reset to greenfield baseline.")
return 0
if args.celebrate:
version = VersionManager().from_commits(orch.state.total_commits)
print(
orch.releases.celebration_text(version, orch.state.total_commits)
)
return 0
if args.push_now:
ok = orch.push_now()
print(
"Remote ledger synchronised."
if ok
else "Push deferred or failed; consult logs."
)
return 0 if ok else 1
if args.dashboard and not args.once:
orch.print_dashboard_once()
return 0
if args.once or args.dry_run:
# --dry-run alone implies a single simulated cycle unless forever wanted;
# forever + dry-run is allowed via no --once, but default dry-run to once
# for safety when only --dry-run is passed.
if args.dry_run and not args.once and _only_dry_run(argv):
result = orch.run_once()
_print_cycle_result(result, dry_run=True)
return 0
if args.once:
result = orch.run_once()
_print_cycle_result(result, dry_run=args.dry_run)
return 0
# Infinite loop
try:
orch.run_forever()
except KeyboardInterrupt:
print("\nHistorical expansion suspended by operator.")
return 0
return 0
def _only_dry_run(argv: list[str] | None) -> bool:
"""True when user passed --dry-run without --once (safe default: single cycle)."""
tokens = list(argv or sys.argv[1:])
return "--dry-run" in tokens and "--once" not in tokens
def _print_cycle_result(result, *, dry_run: bool = False) -> None:
prefix = "[DRY-RUN] " if dry_run else ""
print(
f"{prefix}Batch complete: {result.batch_size} commit(s); "
f"head revision {result.revision}"
)
files = result.files or []
messages = result.messages or [result.message]
for index, message in enumerate(messages):
target = files[index] if index < len(files) else "?"
print(f" {index + 1}. {target} -> {message}")
if result.celebration:
print(result.celebration)
if __name__ == "__main__":
raise SystemExit(main())