modify documents
This commit is contained in:
@@ -20,6 +20,7 @@ from msvc_harness.discovery import DiscoveryError, discover_project
|
||||
from msvc_harness.models import ProjectKind
|
||||
from msvc_harness.process import ValidationFailure, execute_plan
|
||||
from msvc_harness.toolchain import ToolchainError, discover_toolchain
|
||||
from hooks.validation_scope import is_document_only_turn
|
||||
|
||||
|
||||
REENTRY_ENV = "CODEX_STOP_VALIDATION_ACTIVE"
|
||||
@@ -112,9 +113,8 @@ def _emit_stop_response(message: str) -> None:
|
||||
print(
|
||||
json.dumps(
|
||||
{
|
||||
"continue": False,
|
||||
"stopReason": message,
|
||||
"systemMessage": message,
|
||||
"decision": "block",
|
||||
"reason": message,
|
||||
},
|
||||
ensure_ascii=False,
|
||||
)
|
||||
@@ -125,16 +125,36 @@ def main(*, run=subprocess.run, clock=time.monotonic) -> int:
|
||||
if os.environ.get(REENTRY_ENV) == "1":
|
||||
return 0
|
||||
|
||||
try:
|
||||
raw_payload = sys.stdin.read()
|
||||
payload = json.loads(raw_payload) if raw_payload.strip() else {}
|
||||
if not isinstance(payload, dict):
|
||||
raise TypeError("hook input must be a JSON object")
|
||||
cwd = payload.get("cwd")
|
||||
if cwd is not None and not isinstance(cwd, str):
|
||||
raise TypeError("hook cwd must be a string")
|
||||
stop_hook_active = payload.get("stop_hook_active", False)
|
||||
if not isinstance(stop_hook_active, bool):
|
||||
raise TypeError("stop_hook_active must be a boolean")
|
||||
except (json.JSONDecodeError, TypeError) as exc:
|
||||
_emit_stop_response(f"validation hook input rejected: {exc}")
|
||||
return 0
|
||||
|
||||
if stop_hook_active:
|
||||
return 0
|
||||
|
||||
deadline = clock() + TOTAL_TIMEOUT_SECONDS
|
||||
try:
|
||||
root = _project_root(
|
||||
Path.cwd(),
|
||||
Path(cwd or Path.cwd()),
|
||||
deadline=deadline,
|
||||
run=run,
|
||||
clock=clock,
|
||||
)
|
||||
if is_document_only_turn(payload, root):
|
||||
return 0
|
||||
ok, message = run_validations(root, deadline=deadline, clock=clock)
|
||||
except (OSError, ValidationFailure) as exc:
|
||||
except Exception as exc:
|
||||
_emit_stop_response(f"validation hook failed: {exc}")
|
||||
return 0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user