pr-proof 0.0.0-stage → 0.1.1-beta.0

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.
Files changed (137) hide show
  1. package/LICENSE +21 -0
  2. package/Procfile +2 -0
  3. package/README.md +300 -2
  4. package/app/__init__.py +1 -0
  5. package/app/api/__init__.py +1 -0
  6. package/app/api/cli.py +35 -0
  7. package/app/api/github.py +168 -0
  8. package/app/api/history.py +123 -0
  9. package/app/api/main.py +95 -0
  10. package/app/api/queue.py +45 -0
  11. package/app/api/responses.py +28 -0
  12. package/app/api/signature.py +19 -0
  13. package/app/api/sync.py +189 -0
  14. package/app/api/sync_rules_pure.py +71 -0
  15. package/app/api/webhook.py +172 -0
  16. package/app/setup/__init__.py +4 -0
  17. package/app/setup/cli.py +90 -0
  18. package/app/setup/configure.py +735 -0
  19. package/app/setup/files.py +104 -0
  20. package/app/setup/github_setup.py +153 -0
  21. package/app/setup/install_hints.json +32 -0
  22. package/app/setup/setup_pure.py +344 -0
  23. package/app/setup/start.py +113 -0
  24. package/app/shared/__init__.py +1 -0
  25. package/app/shared/comment_pure.py +29 -0
  26. package/app/shared/config.py +106 -0
  27. package/app/shared/db_pure.py +339 -0
  28. package/app/shared/embed_models_pure.py +55 -0
  29. package/app/shared/feedback_pure.py +84 -0
  30. package/app/shared/github_auth.py +74 -0
  31. package/app/shared/job_pure.py +43 -0
  32. package/app/shared/notify.py +97 -0
  33. package/app/shared/ops_alert_pure.py +38 -0
  34. package/app/shared/state_keys_pure.py +24 -0
  35. package/app/shared/version.py +27 -0
  36. package/app/worker/__init__.py +1 -0
  37. package/app/worker/access_pure.py +180 -0
  38. package/app/worker/ai/__init__.py +1 -0
  39. package/app/worker/ai/claude_cli.py +684 -0
  40. package/app/worker/ai/mcp_relay.py +42 -0
  41. package/app/worker/ai/path_hook.py +103 -0
  42. package/app/worker/ai/tool_server.py +139 -0
  43. package/app/worker/ai/workdir.py +333 -0
  44. package/app/worker/base_config.py +173 -0
  45. package/app/worker/budget.py +100 -0
  46. package/app/worker/cache_key_pure.py +34 -0
  47. package/app/worker/call_budget_pure.py +132 -0
  48. package/app/worker/checker_authoring_pure.py +599 -0
  49. package/app/worker/checker_pure.py +196 -0
  50. package/app/worker/cli.py +97 -0
  51. package/app/worker/command.py +191 -0
  52. package/app/worker/command_pure.py +38 -0
  53. package/app/worker/coverage.py +123 -0
  54. package/app/worker/coverage_pure.py +202 -0
  55. package/app/worker/deps.py +22 -0
  56. package/app/worker/diff_pure.py +419 -0
  57. package/app/worker/doc_rules_pure.py +201 -0
  58. package/app/worker/doc_rules_report.py +979 -0
  59. package/app/worker/eval_run_pure.py +241 -0
  60. package/app/worker/evaluation.py +151 -0
  61. package/app/worker/feedback.py +448 -0
  62. package/app/worker/feedback_pure.py +131 -0
  63. package/app/worker/feedback_report_pure.py +90 -0
  64. package/app/worker/feedback_triage.py +85 -0
  65. package/app/worker/feedback_triage_pure.py +363 -0
  66. package/app/worker/fix/__init__.py +1 -0
  67. package/app/worker/fix/decide.py +197 -0
  68. package/app/worker/fix/feedback_fix_pure.py +125 -0
  69. package/app/worker/fix/fix_decision_pure.py +386 -0
  70. package/app/worker/fix/fix_pure.py +70 -0
  71. package/app/worker/fix/mechanical_fix.py +214 -0
  72. package/app/worker/fix/model_fix.py +575 -0
  73. package/app/worker/fix/model_fix_pure.py +593 -0
  74. package/app/worker/fix/proposal.py +584 -0
  75. package/app/worker/fix/proposal_pure.py +103 -0
  76. package/app/worker/fix/scope.py +40 -0
  77. package/app/worker/fix/scope_pure.py +222 -0
  78. package/app/worker/generated_tests_pure.py +442 -0
  79. package/app/worker/github.py +471 -0
  80. package/app/worker/graph.py +963 -0
  81. package/app/worker/guard.py +91 -0
  82. package/app/worker/lang/__init__.py +0 -0
  83. package/app/worker/lang/install_pure.py +25 -0
  84. package/app/worker/lang/python.py +862 -0
  85. package/app/worker/loop.py +200 -0
  86. package/app/worker/main.py +76 -0
  87. package/app/worker/markdown_pure.py +29 -0
  88. package/app/worker/mcp_pure.py +150 -0
  89. package/app/worker/memory.py +503 -0
  90. package/app/worker/merged_fix_pure.py +236 -0
  91. package/app/worker/pr_check_report_pure.py +201 -0
  92. package/app/worker/pr_description_report_pure.py +112 -0
  93. package/app/worker/preflight.py +125 -0
  94. package/app/worker/rag_pure.py +285 -0
  95. package/app/worker/rag_switch_pure.py +203 -0
  96. package/app/worker/records.py +207 -0
  97. package/app/worker/records_pure.py +239 -0
  98. package/app/worker/repo.py +588 -0
  99. package/app/worker/repo_config_pure.py +269 -0
  100. package/app/worker/report.py +300 -0
  101. package/app/worker/retry.py +65 -0
  102. package/app/worker/rule_pure.py +223 -0
  103. package/app/worker/rule_reading_pure.py +503 -0
  104. package/app/worker/rules/__init__.py +1 -0
  105. package/app/worker/rules/checkers.py +615 -0
  106. package/app/worker/rules/detect.py +154 -0
  107. package/app/worker/rules/doc_rules.py +301 -0
  108. package/app/worker/rules/doc_sections_pure.py +168 -0
  109. package/app/worker/rules/judge.py +410 -0
  110. package/app/worker/rules/judge_pure.py +627 -0
  111. package/app/worker/rules/pr_check.py +404 -0
  112. package/app/worker/rules/pr_check_pure.py +922 -0
  113. package/app/worker/rules/pr_description.py +218 -0
  114. package/app/worker/rules/pr_description_pure.py +743 -0
  115. package/app/worker/rules/rules.py +314 -0
  116. package/app/worker/rules/run_check.py +95 -0
  117. package/app/worker/rules/run_check_pure.py +219 -0
  118. package/app/worker/rules/tool_choice_pure.py +135 -0
  119. package/app/worker/sandbox/__init__.py +1 -0
  120. package/app/worker/sandbox/checker_runner.py +412 -0
  121. package/app/worker/sandbox/container.py +130 -0
  122. package/app/worker/sandbox/docker_cli.py +170 -0
  123. package/app/worker/sandbox/safe_read.py +32 -0
  124. package/app/worker/sandbox/toolcache.py +425 -0
  125. package/app/worker/state.py +602 -0
  126. package/app/worker/test_lines.py +77 -0
  127. package/app/worker/test_run_pure.py +133 -0
  128. package/app/worker/text_edit_pure.py +66 -0
  129. package/app/worker/tools_pure.py +152 -0
  130. package/app/worker/update.py +305 -0
  131. package/app/worker/violation_pure.py +33 -0
  132. package/bin/pr-proof.js +173 -0
  133. package/docker/sandbox/Dockerfile +12 -0
  134. package/docker/sandbox/coveragerc +19 -0
  135. package/docker-compose.yml +5 -0
  136. package/package.json +31 -4
  137. package/pyproject.toml +60 -0
@@ -0,0 +1,91 @@
1
+ """외부 작성자 PR 가드레일의 워커 쪽 (docs/DESIGN.md 8.6, 위협 표 T2·T18).
2
+
3
+ `update`와 `command` 작업은 모두 시작에서, PR의 코드를 체크아웃하기 전에 `check`를 지난다. 작업이
4
+ 어느 경로로 들어왔든(웹훅, 동기화 루프, CLI 동기화, 재등록, 재개, `/fix`) 같은 지점이다. 판단은
5
+ 워커가 GitHub의 PR 조회에서 방금 읽은 값과 base의 `access`, `approvals`의 승인 기록으로만 한다.
6
+ `PRJob`에 실린 작성자 값은 기록용이다. 통과하지 못하면 `block`이 승인 안내 한 줄만 단다.
7
+ """
8
+
9
+ import logging
10
+ from dataclasses import dataclass
11
+ from typing import Final
12
+
13
+ from app.shared.job_pure import PRJob
14
+ from app.worker import base_config
15
+ from app.worker.access_pure import AccessSettings, Author, Decision, may_run
16
+ from app.worker.deps import Deps
17
+ from app.worker.github import PullRefs
18
+
19
+ NEEDS_APPROVAL: Final = "needs_approval"
20
+
21
+ log = logging.getLogger(__name__)
22
+
23
+
24
+ @dataclass(frozen=True)
25
+ class Gate:
26
+ refs: PullRefs # 이 작업에서 GitHub에 한 번 조회한 PR
27
+ access: AccessSettings
28
+ decision: Decision
29
+
30
+
31
+ def author(refs: PullRefs) -> Author:
32
+ return Author(refs.author_association, refs.author_login)
33
+
34
+
35
+ def check(job: PRJob, deps: Deps, refs: PullRefs) -> Gate:
36
+ """체크아웃 전에 부른다. base의 설정을 읽지 못하면 GitError가 올라가 실행하지 않는다."""
37
+ access = base_config.load_access(deps.settings.data_dir, job.repo, refs.base_sha)
38
+ approved = deps.store.approved_shas(job.repo, job.pr_number)
39
+ decision = may_run(refs.author_association, refs.author_login, refs.head_sha, access, approved)
40
+ if job.author_association is not None and job.author_association != refs.author_association:
41
+ log.info(
42
+ "작업에 실린 작성자 값과 GitHub의 값이 다름 (판단은 GitHub의 값): %s#%d %r → %r",
43
+ job.repo, job.pr_number, job.author_association, refs.author_association,
44
+ ) # fmt: skip
45
+ return Gate(refs, access, decision)
46
+
47
+
48
+ def block(job: PRJob, deps: Deps, refs: PullRefs) -> str:
49
+ """승인 안내 한 줄만 달고 끝낸다. 체크아웃, 컨테이너, 모델 호출이 없다. 막은 사실은 runs에
50
+ 남긴다.
51
+
52
+ 결과 코멘트와 같은 표식의 코멘트 하나를 고쳐 쓰므로 새 커밋이 와도 한 줄이고 해시만 바뀐다.
53
+ PR의 내용(제목, 브랜치 이름)은 읽지도 넣지도 않는다.
54
+ """
55
+ log.warning(
56
+ "신뢰되지 않은 작성자의 PR이라 승인을 기다림: %s#%d 작성자 %r (%r), head %s",
57
+ job.repo, job.pr_number, refs.author_login, refs.author_association, refs.head_sha[:7],
58
+ ) # fmt: skip
59
+ store = deps.store
60
+ comment_id = deps.github.upsert_comment(
61
+ job.repo, job.pr_number, approval_guide(refs.head_sha),
62
+ store.last_comment_id(job.repo, job.pr_number),
63
+ ) # fmt: skip
64
+ store.record_blocked(job, refs.head_sha, author(refs), comment_id)
65
+ return NEEDS_APPROVAL
66
+
67
+
68
+ def approval_guide(head_sha: str) -> str:
69
+ """승인 명령은 전체 해시만 받으므로(T31) 안내에도 그대로 복사할 수 있게 전체 해시를 적는다."""
70
+ return (
71
+ "외부 작성자의 PR이라 검사하지 않았습니다. 저장소 멤버가 코드를 확인한 뒤 "
72
+ f"`/recheck {head_sha}`를 달면 이 커밋을 검사합니다."
73
+ )
74
+
75
+
76
+ def missing_commit_reply(head_sha: str) -> str:
77
+ return f"> /recheck\n\n{approval_guide(head_sha)}"
78
+
79
+
80
+ def bad_commit_reply(head_sha: str) -> str:
81
+ return (
82
+ "> /recheck\n\n커밋은 전체 해시 40자로 적어 주세요. 짧은 해시로는 승인하지 않습니다. "
83
+ f"지금 head는 `{head_sha}`입니다. 확인한 뒤 `/recheck {head_sha}`을 달아 주세요."
84
+ )
85
+
86
+
87
+ def head_moved_reply(head_sha: str) -> str:
88
+ return (
89
+ f"> /recheck\n\n새 커밋이 왔습니다. 지금 head는 `{head_sha}`입니다. "
90
+ f"확인한 뒤 `/recheck {head_sha}`을 달아 주세요."
91
+ )
File without changes
@@ -0,0 +1,25 @@
1
+ """의존성 설치 실패를 PR 문제와 환경 오류로 나누는 규칙 (docs/DESIGN.md F8)."""
2
+
3
+ from typing import Final, Literal
4
+
5
+ InstallFailureKind = Literal["resolution", "source_only", "disallowed", "network", "unknown"]
6
+ InstallOutcome = Literal["unrunnable", "environment"]
7
+
8
+ # 원인을 판단할 수 없는 실패가 같은 의존성 해시로 이만큼 연속되면 PR 문제로 본다
9
+ UNKNOWN_FAILURE_LIMIT: Final = 2
10
+
11
+
12
+ def install_failure_outcome(kind: InstallFailureKind, consecutive_failures: int) -> InstallOutcome:
13
+ """설치 실패의 처리.
14
+
15
+ - resolution: PR의 의존성 파일 문제(없는 패키지, 버전 충돌, 잘못된 형식). 1회에 실행 불가
16
+ - source_only: wheel이 없고 소스 배포본만 있는 패키지 (8.1). 1회에 실행 불가
17
+ - disallowed: 의존성 파일에 바이너리만 설치하는 제한을 푸는 옵션이나 주소·경로 의존성 (8.1)
18
+ - network: 환경 오류. 큐에 되돌린다
19
+ - unknown: 판단할 수 없으면 consecutive_failures(이번 실패 포함)가 한도에 닿을 때만 실행 불가
20
+ """
21
+ if kind in ("resolution", "source_only", "disallowed"):
22
+ return "unrunnable"
23
+ if kind == "network":
24
+ return "environment"
25
+ return "unrunnable" if consecutive_failures >= UNKNOWN_FAILURE_LIMIT else "environment"