gitvouch 0.1.0__py3-none-any.whl
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.
- gitvouch/__init__.py +4 -0
- gitvouch/cli.py +381 -0
- gitvouch/core.py +131 -0
- gitvouch/ops.py +730 -0
- gitvouch/schemas/__init__.py +1 -0
- gitvouch/schemas/config.schema.json +35 -0
- gitvouch/schemas/event.schema.json +200 -0
- gitvouch/schemas/evidence.schema.json +44 -0
- gitvouch/schemas/milestone.schema.json +21 -0
- gitvouch/schemas/project.schema.json +20 -0
- gitvouch/schemas/state.schema.json +31 -0
- gitvouch/schemas/task.schema.json +74 -0
- gitvouch/verifier.py +687 -0
- gitvouch-0.1.0.dist-info/METADATA +190 -0
- gitvouch-0.1.0.dist-info/RECORD +19 -0
- gitvouch-0.1.0.dist-info/WHEEL +5 -0
- gitvouch-0.1.0.dist-info/entry_points.txt +2 -0
- gitvouch-0.1.0.dist-info/licenses/LICENSE +21 -0
- gitvouch-0.1.0.dist-info/top_level.txt +1 -0
gitvouch/__init__.py
ADDED
gitvouch/cli.py
ADDED
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
"""Command-line interface for gitvouch."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import json
|
|
7
|
+
import sys
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
from typing import Any
|
|
10
|
+
|
|
11
|
+
from . import __version__
|
|
12
|
+
from .ops import (
|
|
13
|
+
GitvouchError,
|
|
14
|
+
add_blocker,
|
|
15
|
+
add_evidence,
|
|
16
|
+
add_milestone,
|
|
17
|
+
collect_status,
|
|
18
|
+
create_task,
|
|
19
|
+
init_repo,
|
|
20
|
+
resolve_blocker,
|
|
21
|
+
review_memory,
|
|
22
|
+
run_evidence_command,
|
|
23
|
+
transition_task,
|
|
24
|
+
)
|
|
25
|
+
from .verifier import validate_repository
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
29
|
+
parser = argparse.ArgumentParser(
|
|
30
|
+
prog="gitvouch",
|
|
31
|
+
description=(
|
|
32
|
+
"Zero-daemon, Git-native acceptance-criteria locking, evidence-gated verification, "
|
|
33
|
+
"and durable repo memory for AI coding agents."
|
|
34
|
+
),
|
|
35
|
+
)
|
|
36
|
+
parser.add_argument("--version", action="version", version=f"%(prog)s {__version__}")
|
|
37
|
+
parser.add_argument(
|
|
38
|
+
"--repo",
|
|
39
|
+
default=".",
|
|
40
|
+
help="Path to the repository root (default: current directory).",
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
sub = parser.add_subparsers(dest="command", required=True)
|
|
44
|
+
|
|
45
|
+
# init
|
|
46
|
+
p_init = sub.add_parser("init", help="Initialize .gitvouch/ contract and AGENTS.md block.")
|
|
47
|
+
p_init.add_argument("--name", help="Project name (defaults to directory name).")
|
|
48
|
+
p_init.add_argument(
|
|
49
|
+
"--profile",
|
|
50
|
+
choices=["general", "application", "infrastructure", "migration"],
|
|
51
|
+
default="application",
|
|
52
|
+
)
|
|
53
|
+
p_init.add_argument("--mode", choices=["full", "control", "memory"], default="full")
|
|
54
|
+
p_init.add_argument("--milestone", default="Initial Milestone", help="Title for M-001.")
|
|
55
|
+
p_init.add_argument("--warn-after-days", type=int, default=14)
|
|
56
|
+
p_init.add_argument("--force", action="store_true")
|
|
57
|
+
|
|
58
|
+
# milestone
|
|
59
|
+
p_ms = sub.add_parser("milestone", help="Manage milestones.")
|
|
60
|
+
ms_sub = p_ms.add_subparsers(dest="ms_cmd", required=True)
|
|
61
|
+
p_ms_add = ms_sub.add_parser("add", help="Create a new milestone.")
|
|
62
|
+
p_ms_add.add_argument("--title", required=True)
|
|
63
|
+
p_ms_add.add_argument("--description", default="")
|
|
64
|
+
p_ms_add.add_argument(
|
|
65
|
+
"--status",
|
|
66
|
+
choices=["planned", "active", "completed", "cancelled"],
|
|
67
|
+
default="planned",
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
# task
|
|
71
|
+
p_task = sub.add_parser("task", help="Create, transition, block, and verify tasks.")
|
|
72
|
+
t_sub = p_task.add_subparsers(dest="task_cmd", required=True)
|
|
73
|
+
|
|
74
|
+
p_t_new = t_sub.add_parser("new", help="Create a new proposed task with acceptance criteria.")
|
|
75
|
+
p_t_new.add_argument("--title", required=True)
|
|
76
|
+
p_t_new.add_argument("--scope", required=True)
|
|
77
|
+
p_t_new.add_argument("--milestone", default="M-001")
|
|
78
|
+
p_t_new.add_argument("--weight", type=int, default=1)
|
|
79
|
+
p_t_new.add_argument("--owner", action="append", dest="owners")
|
|
80
|
+
p_t_new.add_argument("--dep", action="append", dest="dependencies")
|
|
81
|
+
p_t_new.add_argument(
|
|
82
|
+
"--criterion",
|
|
83
|
+
action="append",
|
|
84
|
+
dest="criteria",
|
|
85
|
+
required=True,
|
|
86
|
+
help="Acceptance criterion description (repeatable).",
|
|
87
|
+
)
|
|
88
|
+
p_t_new.add_argument("--max-age-days", type=int, default=None)
|
|
89
|
+
p_t_new.add_argument("--actor", default=None)
|
|
90
|
+
|
|
91
|
+
for cmd_name, help_text in (
|
|
92
|
+
("ready", "Lock acceptance criteria snapshot and transition proposed -> ready."),
|
|
93
|
+
("start", "Transition ready -> in_progress."),
|
|
94
|
+
("implement", "Transition in_progress -> implemented."),
|
|
95
|
+
("verifying", "Transition implemented -> verifying."),
|
|
96
|
+
("cancel", "Transition task -> cancelled."),
|
|
97
|
+
("supersede", "Transition task -> superseded."),
|
|
98
|
+
):
|
|
99
|
+
p_tr = t_sub.add_parser(cmd_name, help=help_text)
|
|
100
|
+
p_tr.add_argument("task_id")
|
|
101
|
+
p_tr.add_argument("--actor", default=None)
|
|
102
|
+
|
|
103
|
+
p_t_ver = t_sub.add_parser(
|
|
104
|
+
"verify",
|
|
105
|
+
help="Evidence-gated transition to verified (refuses without valid passing proof for every criterion).",
|
|
106
|
+
)
|
|
107
|
+
p_t_ver.add_argument("task_id")
|
|
108
|
+
p_t_ver.add_argument("--evidence", action="append", dest="evidence_ids")
|
|
109
|
+
p_t_ver.add_argument("--actor", default=None)
|
|
110
|
+
|
|
111
|
+
p_t_blk = t_sub.add_parser(
|
|
112
|
+
"block", help="Record an active blocker preventing forward transitions."
|
|
113
|
+
)
|
|
114
|
+
p_t_blk.add_argument("task_id")
|
|
115
|
+
p_t_blk.add_argument("--id", required=True, dest="blocker_id", help="Blocker ID, e.g. B-001")
|
|
116
|
+
p_t_blk.add_argument("--summary", required=True)
|
|
117
|
+
p_t_blk.add_argument("--actor", default=None)
|
|
118
|
+
|
|
119
|
+
p_t_unblk = t_sub.add_parser("unblock", help="Resolve an active blocker.")
|
|
120
|
+
p_t_unblk.add_argument("task_id")
|
|
121
|
+
p_t_unblk.add_argument("--id", required=True, dest="blocker_id")
|
|
122
|
+
p_t_unblk.add_argument("--resolution", required=True)
|
|
123
|
+
p_t_unblk.add_argument("--actor", default=None)
|
|
124
|
+
|
|
125
|
+
# evidence
|
|
126
|
+
p_ev = sub.add_parser("evidence", help="Capture or record verification evidence.")
|
|
127
|
+
ev_sub = p_ev.add_subparsers(dest="ev_cmd", required=True)
|
|
128
|
+
|
|
129
|
+
p_ev_run = ev_sub.add_parser(
|
|
130
|
+
"run",
|
|
131
|
+
help="Execute a command and record pass/fail evidence with git commit + SHA-256 digest.",
|
|
132
|
+
)
|
|
133
|
+
p_ev_run.add_argument("task_id")
|
|
134
|
+
p_ev_run.add_argument("--criterion", required=True, dest="criterion_id")
|
|
135
|
+
p_ev_run.add_argument("--cmd", required=True)
|
|
136
|
+
p_ev_run.add_argument("--collector", default=None)
|
|
137
|
+
p_ev_run.add_argument("--expires-days", type=int, default=None)
|
|
138
|
+
p_ev_run.add_argument("--timeout", type=int, default=300)
|
|
139
|
+
|
|
140
|
+
p_ev_add = ev_sub.add_parser("add", help="Record external/CI verification evidence manually.")
|
|
141
|
+
p_ev_add.add_argument("task_id")
|
|
142
|
+
p_ev_add.add_argument("--criterion", required=True, dest="criterion_id")
|
|
143
|
+
p_ev_add.add_argument("--result", choices=["pass", "fail", "inconclusive"], required=True)
|
|
144
|
+
p_ev_add.add_argument("--summary", required=True)
|
|
145
|
+
p_ev_add.add_argument("--commit", default=None)
|
|
146
|
+
p_ev_add.add_argument("--cmd", default=None)
|
|
147
|
+
p_ev_add.add_argument("--ci-job", default=None)
|
|
148
|
+
p_ev_add.add_argument("--url", default=None)
|
|
149
|
+
p_ev_add.add_argument("--sha256", default=None)
|
|
150
|
+
p_ev_add.add_argument("--collector", default=None)
|
|
151
|
+
p_ev_add.add_argument("--expires-days", type=int, default=None)
|
|
152
|
+
p_ev_add.add_argument("--not-applicable", action="store_true")
|
|
153
|
+
|
|
154
|
+
# memory
|
|
155
|
+
p_mem = sub.add_parser("memory", help="Update durable repository memory atomically.")
|
|
156
|
+
mem_sub = p_mem.add_subparsers(dest="mem_cmd", required=True)
|
|
157
|
+
p_mem_rev = mem_sub.add_parser(
|
|
158
|
+
"review",
|
|
159
|
+
help="Stamp last_reviewed across state_snapshot.json, current_state.md, and operation_log.md.",
|
|
160
|
+
)
|
|
161
|
+
p_mem_rev.add_argument("--note", required=True, help="What was actually re-verified.")
|
|
162
|
+
p_mem_rev.add_argument("--basis", default=None, help="Evidence basis for freshness.")
|
|
163
|
+
|
|
164
|
+
# status
|
|
165
|
+
p_stat = sub.add_parser(
|
|
166
|
+
"status", help="Display progress, verification debt, and task coverage."
|
|
167
|
+
)
|
|
168
|
+
p_stat.add_argument("--json", action="store_true", dest="as_json")
|
|
169
|
+
|
|
170
|
+
# check
|
|
171
|
+
p_chk = sub.add_parser("check", help="Run full offline deterministic contract validation.")
|
|
172
|
+
p_chk.add_argument("--strict-warnings", action="store_true")
|
|
173
|
+
p_chk.add_argument("--json", action="store_true", dest="as_json")
|
|
174
|
+
|
|
175
|
+
return parser
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
def _print_status(status: dict[str, Any]) -> None:
|
|
179
|
+
prog = status["progress"]
|
|
180
|
+
eligible = prog["eligible_weight"]
|
|
181
|
+
impl_pct = (100.0 * prog["implemented_weight"] / eligible) if eligible else 0.0
|
|
182
|
+
ver_pct = (100.0 * prog["verified_weight"] / eligible) if eligible else 0.0
|
|
183
|
+
print(f"Project: {status['project_name']} ({status['profile']})")
|
|
184
|
+
print(
|
|
185
|
+
f"Contract: {'PASS' if status['valid'] else 'FAIL'} "
|
|
186
|
+
f"(failures={status['failure_count']}, warnings={status['warning_count']})"
|
|
187
|
+
)
|
|
188
|
+
if status["memory_age_days"] is not None:
|
|
189
|
+
print(f"Memory age: {status['memory_age_days']} day(s) since last review")
|
|
190
|
+
print(
|
|
191
|
+
f"Progress: implemented={impl_pct:.1f}% ({prog['implemented_weight']}/{eligible}) | "
|
|
192
|
+
f"verified={ver_pct:.1f}% ({prog['verified_weight']}/{eligible}) | "
|
|
193
|
+
f"verification_debt={prog['verification_debt_weight']}"
|
|
194
|
+
)
|
|
195
|
+
if status["tasks"]:
|
|
196
|
+
print("\nTasks:")
|
|
197
|
+
for t in status["tasks"]:
|
|
198
|
+
blk = f" BLOCKED({','.join(t['active_blockers'])})" if t["blocked"] else ""
|
|
199
|
+
print(
|
|
200
|
+
f" {t['id']} [{t['state']:<11}] w={t['weight']} "
|
|
201
|
+
f"evidence={t['criteria_verified']}/{t['criteria_total']}{blk} {t['title']}"
|
|
202
|
+
)
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
def main(argv: list[str] | None = None) -> int:
|
|
206
|
+
parser = build_parser()
|
|
207
|
+
args = parser.parse_args(argv)
|
|
208
|
+
root = Path(args.repo).resolve()
|
|
209
|
+
|
|
210
|
+
try:
|
|
211
|
+
if args.command == "init":
|
|
212
|
+
cfg = init_repo(
|
|
213
|
+
root,
|
|
214
|
+
project_name=args.name,
|
|
215
|
+
profile=args.profile,
|
|
216
|
+
mode=args.mode,
|
|
217
|
+
milestone_title=args.milestone,
|
|
218
|
+
warn_after_days=args.warn_after_days,
|
|
219
|
+
force=args.force,
|
|
220
|
+
)
|
|
221
|
+
print(f"Initialized gitvouch for '{cfg['project_name']}' (mode={args.mode}).")
|
|
222
|
+
print("Run 'gitvouch check' to verify the contract.")
|
|
223
|
+
return 0
|
|
224
|
+
|
|
225
|
+
if args.command == "milestone" and args.ms_cmd == "add":
|
|
226
|
+
ms = add_milestone(
|
|
227
|
+
root, title=args.title, description=args.description, status=args.status
|
|
228
|
+
)
|
|
229
|
+
print(f"Created milestone {ms['id']}: {ms['title']} ({ms['status']})")
|
|
230
|
+
return 0
|
|
231
|
+
|
|
232
|
+
if args.command == "task":
|
|
233
|
+
if args.task_cmd == "new":
|
|
234
|
+
task = create_task(
|
|
235
|
+
root,
|
|
236
|
+
title=args.title,
|
|
237
|
+
scope=args.scope,
|
|
238
|
+
criteria=args.criteria,
|
|
239
|
+
milestone_id=args.milestone,
|
|
240
|
+
weight=args.weight,
|
|
241
|
+
owners=args.owners,
|
|
242
|
+
dependencies=args.dependencies,
|
|
243
|
+
max_age_days=args.max_age_days,
|
|
244
|
+
actor=args.actor,
|
|
245
|
+
)
|
|
246
|
+
print(
|
|
247
|
+
f"Created {task['id']} ({task['state']}, "
|
|
248
|
+
f"{len(task['acceptance_criteria'])} criteria): {task['title']}"
|
|
249
|
+
)
|
|
250
|
+
return 0
|
|
251
|
+
if args.task_cmd == "block":
|
|
252
|
+
add_blocker(root, args.task_id, args.blocker_id, args.summary, actor=args.actor)
|
|
253
|
+
print(f"Blocked {args.task_id} with {args.blocker_id}.")
|
|
254
|
+
return 0
|
|
255
|
+
if args.task_cmd == "unblock":
|
|
256
|
+
resolve_blocker(
|
|
257
|
+
root, args.task_id, args.blocker_id, args.resolution, actor=args.actor
|
|
258
|
+
)
|
|
259
|
+
print(f"Resolved blocker {args.blocker_id} on {args.task_id}.")
|
|
260
|
+
return 0
|
|
261
|
+
state_map = {
|
|
262
|
+
"ready": "ready",
|
|
263
|
+
"start": "in_progress",
|
|
264
|
+
"implement": "implemented",
|
|
265
|
+
"verifying": "verifying",
|
|
266
|
+
"verify": "verified",
|
|
267
|
+
"cancel": "cancelled",
|
|
268
|
+
"supersede": "superseded",
|
|
269
|
+
}
|
|
270
|
+
target = state_map[args.task_cmd]
|
|
271
|
+
task = transition_task(
|
|
272
|
+
root,
|
|
273
|
+
args.task_id,
|
|
274
|
+
target,
|
|
275
|
+
evidence_ids=getattr(args, "evidence_ids", None),
|
|
276
|
+
actor=args.actor,
|
|
277
|
+
)
|
|
278
|
+
print(f"{task['id']} -> {task['state']}")
|
|
279
|
+
return 0
|
|
280
|
+
|
|
281
|
+
if args.command == "evidence":
|
|
282
|
+
if args.ev_cmd == "run":
|
|
283
|
+
rec, code = run_evidence_command(
|
|
284
|
+
root,
|
|
285
|
+
task_id=args.task_id,
|
|
286
|
+
criterion_id=args.criterion_id,
|
|
287
|
+
command=args.cmd,
|
|
288
|
+
collector=args.collector,
|
|
289
|
+
expires_days=args.expires_days,
|
|
290
|
+
timeout=args.timeout,
|
|
291
|
+
)
|
|
292
|
+
print(
|
|
293
|
+
f"Recorded {rec['id']} for {rec['task_id']}/{rec['criterion_id']}: "
|
|
294
|
+
f"result={rec['result']} (exit={code})"
|
|
295
|
+
)
|
|
296
|
+
return 0 if code == 0 else 1
|
|
297
|
+
if args.ev_cmd == "add":
|
|
298
|
+
prov: dict[str, Any] = {}
|
|
299
|
+
if args.commit:
|
|
300
|
+
prov["commit"] = args.commit
|
|
301
|
+
if args.cmd:
|
|
302
|
+
prov["command"] = args.cmd
|
|
303
|
+
if args.ci_job:
|
|
304
|
+
prov["ci_job"] = args.ci_job
|
|
305
|
+
if args.url:
|
|
306
|
+
prov["url"] = args.url
|
|
307
|
+
if args.sha256:
|
|
308
|
+
prov["artifact_sha256"] = args.sha256
|
|
309
|
+
rec = add_evidence(
|
|
310
|
+
root,
|
|
311
|
+
task_id=args.task_id,
|
|
312
|
+
criterion_id=args.criterion_id,
|
|
313
|
+
result=args.result,
|
|
314
|
+
summary=args.summary,
|
|
315
|
+
provenance=prov,
|
|
316
|
+
collector=args.collector,
|
|
317
|
+
applicable=not args.not_applicable,
|
|
318
|
+
expires_days=args.expires_days,
|
|
319
|
+
)
|
|
320
|
+
print(
|
|
321
|
+
f"Recorded {rec['id']} for {rec['task_id']}/{rec['criterion_id']}: "
|
|
322
|
+
f"result={rec['result']}"
|
|
323
|
+
)
|
|
324
|
+
return 0
|
|
325
|
+
|
|
326
|
+
if args.command == "memory" and args.mem_cmd == "review":
|
|
327
|
+
res = review_memory(root, note=args.note, basis=args.basis)
|
|
328
|
+
print(f"Updated memory review date to {res['last_reviewed']}.")
|
|
329
|
+
return 0
|
|
330
|
+
|
|
331
|
+
if args.command == "status":
|
|
332
|
+
status = collect_status(root)
|
|
333
|
+
if args.as_json:
|
|
334
|
+
print(json.dumps(status, ensure_ascii=False, indent=2))
|
|
335
|
+
else:
|
|
336
|
+
_print_status(status)
|
|
337
|
+
return 0 if status["valid"] else 1
|
|
338
|
+
|
|
339
|
+
if args.command == "check":
|
|
340
|
+
report = validate_repository(root)
|
|
341
|
+
payload = {
|
|
342
|
+
"ok": report.ok and (not args.strict_warnings or not report.warnings),
|
|
343
|
+
"failures": report.failures,
|
|
344
|
+
"warnings": report.warnings,
|
|
345
|
+
"progress": report.progress,
|
|
346
|
+
"memory_age_days": report.memory_age_days,
|
|
347
|
+
}
|
|
348
|
+
if args.as_json:
|
|
349
|
+
print(json.dumps(payload, ensure_ascii=False, indent=2))
|
|
350
|
+
else:
|
|
351
|
+
for warning in report.warnings:
|
|
352
|
+
print(f"WARNING: {warning}")
|
|
353
|
+
if report.failures:
|
|
354
|
+
print("gitvouch check FAILED:")
|
|
355
|
+
for failure in report.failures:
|
|
356
|
+
print(f" - {failure}")
|
|
357
|
+
else:
|
|
358
|
+
prog = report.progress
|
|
359
|
+
eligible = prog["eligible_weight"]
|
|
360
|
+
impl_pct = (100.0 * prog["implemented_weight"] / eligible) if eligible else 0.0
|
|
361
|
+
ver_pct = (100.0 * prog["verified_weight"] / eligible) if eligible else 0.0
|
|
362
|
+
print("gitvouch check PASSED.")
|
|
363
|
+
print(
|
|
364
|
+
f"Progress: implemented={impl_pct:.1f}%, verified={ver_pct:.1f}%, "
|
|
365
|
+
f"verification_debt={prog['verification_debt_weight']}."
|
|
366
|
+
)
|
|
367
|
+
if not report.ok:
|
|
368
|
+
return 1
|
|
369
|
+
if args.strict_warnings and report.warnings:
|
|
370
|
+
return 1
|
|
371
|
+
return 0
|
|
372
|
+
|
|
373
|
+
parser.print_help()
|
|
374
|
+
return 2
|
|
375
|
+
except GitvouchError as exc:
|
|
376
|
+
print(f"error: {exc}", file=sys.stderr)
|
|
377
|
+
return 1
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
if __name__ == "__main__":
|
|
381
|
+
raise SystemExit(main())
|
gitvouch/core.py
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"""Shared constants, path guards, timestamps, and JSON Schema validation for gitvouch."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import re
|
|
7
|
+
from dataclasses import dataclass, field
|
|
8
|
+
from datetime import UTC, datetime
|
|
9
|
+
from importlib import resources
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
from typing import Any
|
|
12
|
+
|
|
13
|
+
from jsonschema import Draft202012Validator, FormatChecker
|
|
14
|
+
from jsonschema.exceptions import SchemaError
|
|
15
|
+
|
|
16
|
+
CONFIG_PATH = Path(".gitvouch/config.json")
|
|
17
|
+
TERMINAL_STATES = {"verified", "cancelled", "superseded"}
|
|
18
|
+
IMPLEMENTED_STATES = {"implemented", "verifying", "verified"}
|
|
19
|
+
ALLOWED_TRANSITIONS: dict[str, set[str]] = {
|
|
20
|
+
"proposed": {"ready", "cancelled", "superseded"},
|
|
21
|
+
"ready": {"in_progress", "cancelled", "superseded"},
|
|
22
|
+
"in_progress": {"implemented", "ready", "cancelled", "superseded"},
|
|
23
|
+
"implemented": {"verifying", "in_progress", "cancelled", "superseded"},
|
|
24
|
+
"verifying": {"verified", "implemented", "in_progress"},
|
|
25
|
+
"verified": set(),
|
|
26
|
+
"cancelled": set(),
|
|
27
|
+
"superseded": set(),
|
|
28
|
+
}
|
|
29
|
+
FORWARD_TRANSITIONS = {
|
|
30
|
+
("proposed", "ready"),
|
|
31
|
+
("ready", "in_progress"),
|
|
32
|
+
("in_progress", "implemented"),
|
|
33
|
+
("implemented", "verifying"),
|
|
34
|
+
("verifying", "verified"),
|
|
35
|
+
}
|
|
36
|
+
EVENT_FILENAME = re.compile(
|
|
37
|
+
r"^(?P<timestamp>[0-9]{8}T[0-9]{6}Z)--(?P<event_id>EVT-[A-Z0-9][A-Z0-9-]{0,62})\.json$"
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
@dataclass
|
|
42
|
+
class ValidationReport:
|
|
43
|
+
failures: list[str] = field(default_factory=list)
|
|
44
|
+
warnings: list[str] = field(default_factory=list)
|
|
45
|
+
progress: dict[str, int] = field(
|
|
46
|
+
default_factory=lambda: {
|
|
47
|
+
"eligible_weight": 0,
|
|
48
|
+
"implemented_weight": 0,
|
|
49
|
+
"verified_weight": 0,
|
|
50
|
+
"verification_debt_weight": 0,
|
|
51
|
+
}
|
|
52
|
+
)
|
|
53
|
+
memory_age_days: int | None = None
|
|
54
|
+
|
|
55
|
+
@property
|
|
56
|
+
def ok(self) -> bool:
|
|
57
|
+
return len(self.failures) == 0
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def utc_now() -> datetime:
|
|
61
|
+
return datetime.now(UTC).replace(microsecond=0)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def iso_utc(dt: datetime) -> str:
|
|
65
|
+
return dt.astimezone(UTC).replace(microsecond=0).isoformat().replace("+00:00", "Z")
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def compact_utc(dt: datetime) -> str:
|
|
69
|
+
return dt.astimezone(UTC).strftime("%Y%m%dT%H%M%SZ")
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def load_json(path: Path) -> Any:
|
|
73
|
+
return json.loads(path.read_text(encoding="utf-8"))
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def write_json(path: Path, data: Any) -> None:
|
|
77
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
78
|
+
path.write_text(json.dumps(data, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def load_schema(name: str) -> dict[str, Any]:
|
|
82
|
+
text = (
|
|
83
|
+
resources.files("gitvouch.schemas")
|
|
84
|
+
.joinpath(f"{name}.schema.json")
|
|
85
|
+
.read_text(encoding="utf-8")
|
|
86
|
+
)
|
|
87
|
+
return json.loads(text)
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def repo_path(root: Path, value: str) -> Path:
|
|
91
|
+
"""Resolve a repository-relative path while rejecting absolute paths and traversal."""
|
|
92
|
+
candidate_value = Path(value)
|
|
93
|
+
if candidate_value.is_absolute():
|
|
94
|
+
raise ValueError(f"absolute path is not allowed: {value!r}")
|
|
95
|
+
root_resolved = root.resolve()
|
|
96
|
+
candidate = (root_resolved / candidate_value).resolve()
|
|
97
|
+
try:
|
|
98
|
+
candidate.relative_to(root_resolved)
|
|
99
|
+
except ValueError as exc:
|
|
100
|
+
raise ValueError(f"path escapes repository root: {value!r}") from exc
|
|
101
|
+
return candidate
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def parse_time(value: str, label: str, failures: list[str]) -> datetime | None:
|
|
105
|
+
try:
|
|
106
|
+
parsed = datetime.fromisoformat(value.replace("Z", "+00:00"))
|
|
107
|
+
except ValueError:
|
|
108
|
+
failures.append(f"{label} is not a valid ISO-8601 date-time: {value!r}.")
|
|
109
|
+
return None
|
|
110
|
+
if parsed.tzinfo is None:
|
|
111
|
+
failures.append(f"{label} must include a UTC offset: {value!r}.")
|
|
112
|
+
return None
|
|
113
|
+
return parsed.astimezone(UTC)
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def normalized_criteria(criteria: list[dict[str, Any]]) -> list[dict[str, Any]]:
|
|
117
|
+
"""Compare criteria by stable ID without treating list ordering as semantic."""
|
|
118
|
+
return sorted((dict(item) for item in criteria), key=lambda item: item["id"])
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def schema_failures(instance: Any, schema: dict[str, Any], label: str) -> list[str]:
|
|
122
|
+
try:
|
|
123
|
+
Draft202012Validator.check_schema(schema)
|
|
124
|
+
except SchemaError as exc:
|
|
125
|
+
return [f"{label} schema is invalid: {exc.message}."]
|
|
126
|
+
validator = Draft202012Validator(schema, format_checker=FormatChecker())
|
|
127
|
+
failures: list[str] = []
|
|
128
|
+
for error in sorted(validator.iter_errors(instance), key=lambda item: list(item.path)):
|
|
129
|
+
location = ".".join(str(part) for part in error.path) or "<root>"
|
|
130
|
+
failures.append(f"{label} {location}: {error.message}.")
|
|
131
|
+
return failures
|