-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcli.py
More file actions
217 lines (198 loc) · 7.61 KB
/
Copy pathcli.py
File metadata and controls
217 lines (198 loc) · 7.61 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
"""Controller-facing command router for codex-refactor-loop."""
from __future__ import annotations
import argparse
import sys
from dataclasses import dataclass
from pathlib import Path
from typing import Callable, Sequence
from . import github_body, project_rules, spawn, statusline
from .closed_label_reconciler import main as closed_label_reconciler_main
from .checks.degradation import main as degradation_main
from .checks.manifest import main as manifest_main
from .daemon_status import main as daemon_status_main
from .gh_accounting import activate_controller_accounting
from .gh_accounting import main as gh_stats_main
from .labels import main as labels_main
from .monitors.comment import main as comment_monitor_main
from .monitors.concurrency import main as concurrency_main
from .monitors.progress import main as progress_reporter_main
from .peek import main as peek_main
from .pr_checks import main as pr_checks_main
from .release.gate import main as release_gate_main
from .release.required_checks import main as release_required_checks_main
from .restart import main as restart_main
from .runtime_retention import main as runtime_retention_main
from .sync.dev import main as dev_sync_main
from .phase9.router import main as phase9_router_main
from .update_check import main as update_check_main
from .wakeup_plan import main as wakeup_plan_main
from .wakeup_runner import main as wakeup_runner_main
SCRIPT_DIR = Path(__file__).resolve().parents[1]
def release_commits_command(argv: Sequence[str] | None) -> int:
from .release.commits import main as release_commits_main
return release_commits_main(argv)
@dataclass(frozen=True)
class CommandSpec:
handler: Callable[[Sequence[str] | None], int]
description: str
authority: tuple[str, ...]
COMMANDS: dict[str, CommandSpec] = {
"spawn-codex": CommandSpec(spawn.main, "run the Python codex spawn supervisor", ("spawn", "write-log")),
"peek": CommandSpec(peek_main, "run the Python read-only state sweep", ("read-state", "read-gh")),
"gh-stats": CommandSpec(gh_stats_main, "read local gh usage accounting", ("read-state",)),
"wakeup-plan": CommandSpec(wakeup_plan_main, "emit the read-only prioritized wakeup plan", ("read-state", "read-gh")),
"wakeup-runner": CommandSpec(
wakeup_runner_main,
"apply the #396 wakeup-plan closed action projection",
(
"read-state",
"read-log",
"read-gh",
"read-git",
"write-artifact",
"write-event",
"spawn",
"git-commit-worker-output",
"git-push",
"gh-open",
"gh-merge",
"gh-close-linked",
"gh-label-owned",
"controller-lifecycle-runner",
),
),
"pr-checks": CommandSpec(
pr_checks_main,
"read PR-head check-runs through the narrow Checks API projection",
("read-gh",),
),
"restart-daemons": CommandSpec(
restart_main,
"run the Python daemon restart helper",
("spawn-daemon", "write-state", "delete-runtime"),
),
"daemon-status": CommandSpec(
daemon_status_main,
"read restart-helper-managed daemon status",
("read-state", "read-process"),
),
"statusline": CommandSpec(statusline.main, "read the Python statusline snapshot", ("read-state", "read-git")),
"comment-monitor": CommandSpec(
comment_monitor_main,
"run the Python comment monitor daemon",
("read-gh", "gh-reaction", "gh-comment", "write-state", "write-event"),
),
"closed-label-reconciler": CommandSpec(
closed_label_reconciler_main,
"run the closed managed item phase-label reconciler",
("read-gh", "gh-label-closed-reconcile", "write-state"),
),
"concurrency": CommandSpec(
concurrency_main,
"run the Python concurrency monitor or read-only counter",
("read-process", "read-gh", "write-state", "write-event", "write-artifact"),
),
"progress-reporter": CommandSpec(
progress_reporter_main,
"run the Python progress reporter daemon",
("read-gh", "gh-comment", "write-state"),
),
"dev-sync": CommandSpec(
dev_sync_main,
"run the Python integration sync daemon",
(
"read-git",
"read-gh",
"git-fetch",
"git-worktree",
"git-merge",
"git-push",
"git-rebase",
"git-reset",
"write-event",
"write-artifact",
"spawn",
),
),
"phase9-router": CommandSpec(
phase9_router_main,
"compatibility alias for the Python design-consensus router",
("read-log", "read-gh", "write-event", "write-artifact"),
),
"release-gate": CommandSpec(
release_gate_main,
"run the Python auto release gate",
("read-state", "read-gh", "write-artifact"),
),
"release-commits": CommandSpec(
release_commits_command,
"write the git-derived release commits projection",
("read-git", "write-artifact"),
),
"release-required-checks": CommandSpec(
release_required_checks_main,
"check exact release required check-runs",
("read-gh",),
),
"update-check": CommandSpec(
update_check_main,
"run the notify-only version update check probe",
("read-source", "read-gh", "write-state"),
),
"render-github-body": CommandSpec(
github_body.main,
"render a self-contained GitHub body from local artifacts",
("read-artifact",),
),
"labels": CommandSpec(
labels_main,
"validate or plan loop-owned GitHub labels",
("read-source", "read-gh"),
),
"check-degradation": CommandSpec(
degradation_main,
"run the static skill degradation check",
("read-source", "read-state"),
),
"check-manifest": CommandSpec(manifest_main, "run manifest version sync check", ("read-source",)),
"runtime-retention": CommandSpec(
runtime_retention_main,
"run canonical RuntimeRetention for skill-private generated artifacts",
("delete-runtime", "git-worktree"),
),
"log-retention": CommandSpec(
runtime_retention_main,
"one-release compatibility alias for runtime-retention",
("delete-runtime", "git-worktree"),
),
"check-project-rules": CommandSpec(
project_rules.main,
"check host project rules fixed points and write patch artifact when needed",
("read-source", "write-artifact"),
),
}
class RuntimeCommandRouter:
"""Stable command-name router for Python runtime modules."""
def __init__(self, script_dir: Path = SCRIPT_DIR) -> None:
self.script_dir = script_dir
def main(self, argv: Sequence[str] | None = None) -> int:
parser = argparse.ArgumentParser(
prog="consensus-rnd-cli",
description="codex-refactor-loop controller command router",
)
parser.add_argument("command", nargs="?")
parser.add_argument("args", nargs=argparse.REMAINDER)
args = parser.parse_args(argv)
if not args.command:
parser.print_help()
return 0
return self.run(args.command, list(args.args))
def run(self, command: str, args: Sequence[str]) -> int:
activate_controller_accounting(skill_root=self.script_dir.parent)
spec = COMMANDS.get(command)
if spec is None:
sys.stderr.write(f"unknown command: {command}\n")
return 2
return spec.handler(args)
def main(argv: Sequence[str] | None = None) -> int:
return RuntimeCommandRouter().main(argv)