pr-proof 0.0.0-stage → 0.1.0-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 +166 -0
  16. package/app/setup/__init__.py +4 -0
  17. package/app/setup/cli.py +90 -0
  18. package/app/setup/configure.py +720 -0
  19. package/app/setup/files.py +93 -0
  20. package/app/setup/github_setup.py +149 -0
  21. package/app/setup/install_hints.json +32 -0
  22. package/app/setup/setup_pure.py +312 -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,201 @@
1
+ """규칙 경로의 결과 (docs/DESIGN.md 5.1 load_rules → author_checker → detect).
2
+
3
+ 규칙은 문서에서 읽은 것과 도구 설정에서 온 것(ruff 설정)이다. 그래프 상태에 들어가므로 데이터만
4
+ 둔다. 검사기 본문은 상태에 넣지 않고 `checkers` 테이블의 키만 넣는다 (5.5). 결과 코멘트의 규칙 절은
5
+ `DocRules` 값 하나로만 그린다.
6
+ """
7
+
8
+ from collections.abc import Iterable, Sequence
9
+ from dataclasses import dataclass
10
+ from typing import Final, Literal
11
+
12
+ from app.shared.db_pure import ModelCall
13
+ from app.worker.checker_authoring_pure import JudgeRoute, UncheckedKind
14
+ from app.worker.checker_pure import CheckerKind
15
+ from app.worker.rag_pure import Retrieval
16
+ from app.worker.rule_pure import Rule, UnreadDoc
17
+ from app.worker.rules.judge_pure import JudgeUsage
18
+ from app.worker.violation_pure import Violation
19
+
20
+ # 규칙 읽기와 검사기 작성 (규칙 묶음 상한에서 세는 단계)
21
+ DOC_RULE_STAGES: Final = frozenset({"rules", "checker"})
22
+
23
+
24
+ @dataclass(frozen=True)
25
+ class CheckerRef:
26
+ """채택한 검사기. 본문과 예시는 `checkers` 테이블에서 key로 찾는다."""
27
+
28
+ key: str # `checkers` 테이블의 키 (검사기 작성, 도구 선택, 도구 설정)
29
+ id: str
30
+ kind: CheckerKind
31
+ cached: bool # 저장된 검사기를 썼다 (모델 호출 0)
32
+ codes: tuple[str, ...] = () # 도구(ruff)로 확인하는 문서 규칙의 ruff 코드. 코멘트에 보인다
33
+
34
+
35
+ @dataclass(frozen=True)
36
+ class RuleChecked:
37
+ rule: Rule
38
+ checker: CheckerRef
39
+
40
+
41
+ @dataclass(frozen=True)
42
+ class RuleUnchecked:
43
+ rule: Rule
44
+ kind: UncheckedKind
45
+ detail: str
46
+
47
+
48
+ # 모델 판단을 다 하지 못한 이유: 호출 상한, 모델 호출 실패 (4.5 "실패 시")
49
+ JudgeGap = Literal["cap", "model_failed"]
50
+
51
+
52
+ @dataclass(frozen=True)
53
+ class RuleJudged:
54
+ """검사기를 채택하지 않아 모델이 바뀐 hunk를 직접 보는 규칙 (4.4의 3번, 4.5 모델의 직접 판단).
55
+
56
+ route는 모델 판단으로 보낸 까닭이다(`JudgeRoute`). left는 이번 검사에서 판단하지 못한 (이
57
+ 규칙, hunk) 쌍의 수다(호출 상한, 모델 호출 실패). 0이면 다 물었다. pairs는 본 쌍의 수,
58
+ undecided는 그중 모델이 이 자료로는 판단할 수 없다고 답한 쌍의 수와 그 까닭이다.
59
+ """
60
+
61
+ rule: Rule
62
+ # none·part면 검사기 작성 모델이 적은 "검사기로 가릴 수 없는 부분", 아니면 검사기 작성의
63
+ # 마지막 실패
64
+ reason: str
65
+ # 기본값은 이 필드를 더하기 전에 저장된 그래프 상태(체크포인트)를 읽기 위한 것이다. 그때의 뜻은
66
+ # "회차를 다 씀"이었다
67
+ route: JudgeRoute = "attempts"
68
+ left: int = 0
69
+ left_kind: JudgeGap | None = None
70
+ left_detail: str = ""
71
+ pairs: int = 0
72
+ undecided: int = 0
73
+ undecided_why: str = ""
74
+
75
+
76
+ RuleOutcome = RuleChecked | RuleUnchecked | RuleJudged
77
+
78
+
79
+ @dataclass(frozen=True)
80
+ class RunJudged:
81
+ """run 규칙 하나에 모델이 테스트 뒤에 낸 답 (4.5 "실행 결과의 규칙"). kept는 지킴, broken은
82
+ 어김, undecided는 모델이 이 자료로는 판단할 수 없다고 답함, left는 묻지 못함(호출 상한, 모델
83
+ 호출 실패). facts는 모델에게 준 실행 결과의 요약, why는 모델의 까닭이나 묻지 못한 이유다."""
84
+
85
+ rule_id: str
86
+ verdict: Literal["kept", "broken", "undecided", "left"]
87
+ why: str
88
+ facts: str
89
+
90
+
91
+ @dataclass(frozen=True)
92
+ class RulesRead:
93
+ """규칙 읽기의 결과. 검사 방법 정하기와 위반 찾기로 넘어간다."""
94
+
95
+ key: str # 문서 규칙 묶음의 캐시 키. 문서를 읽지 못했으면 ""
96
+ rules: tuple[Rule, ...] # `rules.disabled`를 뺀 것. 문서 규칙 다음에 도구 설정의 규칙
97
+ disabled: int # `rules.disabled`로 뺀 규칙 수
98
+ # 도구 설정의 규칙만으로 검사할 때 규칙 문서를 읽지 못한 이유 (4.3 "실패 시")
99
+ note: str = ""
100
+ sections: tuple[str, ...] = () # 규칙 문서가 커서 관련 절만 읽었으면 그 절 (6.3)
101
+
102
+
103
+ @dataclass(frozen=True)
104
+ class CallUsage:
105
+ """이번 검사에서 규칙 읽기와 검사기 작성이 쓴 모델 호출 (9.4)."""
106
+
107
+ calls: int # 상한에서 센 값의 합
108
+ limit: int # 규칙 묶음 상한
109
+ cache_hits: int
110
+ models: tuple[str, ...]
111
+ input_tokens: int
112
+ output_tokens: int
113
+
114
+
115
+ @dataclass(frozen=True)
116
+ class NotRun:
117
+ """이 경로를 끝까지 돌지 못했다. v1 결과와 테스트는 그대로 나온다."""
118
+
119
+ reason: str
120
+
121
+
122
+ @dataclass(frozen=True)
123
+ class NoRuleDocs:
124
+ unread: tuple[UnreadDoc, ...] = () # 있었지만 읽지 못한 문서
125
+
126
+
127
+ @dataclass(frozen=True)
128
+ class NoRulesFound:
129
+ dropped: int = 0 # 모델이 답했지만 원문 확인에서 버린 규칙 수
130
+
131
+
132
+ @dataclass(frozen=True)
133
+ class Found:
134
+ outcomes: tuple[RuleOutcome, ...] # 적용한 규칙마다 하나, 읽은 순서
135
+ violations: tuple[Violation, ...]
136
+ disabled: int
137
+ usage: CallUsage
138
+ note: str = "" # RulesRead.note
139
+ judge: JudgeUsage | None = None # 모델 판단을 한 검사만
140
+ retrievals: tuple[Retrieval, ...] = () # 검사기 작성이 넣은 과거 기록 (검색을 켠 저장소)
141
+ sections: tuple[str, ...] = () # RulesRead.sections
142
+ runs: tuple[RunJudged, ...] = () # run 규칙의 답. 테스트 뒤에 채운다
143
+
144
+
145
+ DocRules = NotRun | NoRuleDocs | NoRulesFound | Found
146
+
147
+ # 체크포인트에서 되살릴 수 있게 graph.py가 등록하는 타입
148
+ STATE_TYPES: Final = (
149
+ ("app.worker.doc_rules_pure", "CheckerRef"),
150
+ ("app.worker.doc_rules_pure", "RuleChecked"),
151
+ ("app.worker.doc_rules_pure", "RuleUnchecked"),
152
+ ("app.worker.doc_rules_pure", "RuleJudged"),
153
+ ("app.worker.doc_rules_pure", "RunJudged"),
154
+ ("app.worker.rules.judge_pure", "JudgeUsage"),
155
+ ("app.worker.doc_rules_pure", "RulesRead"),
156
+ ("app.worker.doc_rules_pure", "CallUsage"),
157
+ ("app.worker.doc_rules_pure", "NotRun"),
158
+ ("app.worker.doc_rules_pure", "NoRuleDocs"),
159
+ ("app.worker.doc_rules_pure", "NoRulesFound"),
160
+ ("app.worker.doc_rules_pure", "Found"),
161
+ ("app.worker.rule_pure", "Rule"),
162
+ ("app.worker.rule_pure", "RuleSource"),
163
+ ("app.worker.rule_pure", "CheckMethod"),
164
+ ("app.worker.rule_pure", "Example"),
165
+ ("app.worker.rule_pure", "UnreadDoc"),
166
+ ("app.worker.violation_pure", "Violation"),
167
+ )
168
+
169
+
170
+ def outcomes_by_rule(found: Found) -> dict[str, RuleOutcome]:
171
+ """위반의 규칙 id → 그 규칙의 결과. 도구 설정 규칙의 위반은 ruff 코드가 규칙 id라(4.3) 그 코드도
172
+ 도구 설정 규칙을 가리킨다."""
173
+ by_id = {o.rule.id: o for o in found.outcomes}
174
+ config = next((o for o in found.outcomes if o.rule.origin == "tool_config"), None)
175
+ if config is not None:
176
+ for v in found.violations:
177
+ if v.rule_id not in by_id and v.rule_id == v.code:
178
+ by_id[v.rule_id] = config
179
+ return by_id
180
+
181
+
182
+ def with_run_failures(
183
+ outcomes: Sequence[RuleOutcome], failed: Iterable[RuleUnchecked]
184
+ ) -> tuple[RuleOutcome, ...]:
185
+ """검사기가 있었지만 이 PR의 파일에서 돌지 못한 규칙을 검사하지 못한 규칙으로 바꾼다."""
186
+ by_id = {u.rule.id: u for u in failed}
187
+ return tuple(by_id.get(o.rule.id, o) for o in outcomes)
188
+
189
+
190
+ def call_usage(calls: Iterable[ModelCall], limit: int) -> CallUsage:
191
+ """calls는 이번 검사의 규칙 읽기·검사기 작성 호출 기록이다."""
192
+ rows = [c for c in calls if c.stage in DOC_RULE_STAGES]
193
+ made = [c for c in rows if not c.cache_hit]
194
+ return CallUsage(
195
+ calls=sum(c.counted for c in made),
196
+ limit=limit,
197
+ cache_hits=sum(1 for c in rows if c.cache_hit),
198
+ models=tuple(sorted({c.model_id or c.model for c in made})),
199
+ input_tokens=sum(c.input_tokens or 0 for c in made),
200
+ output_tokens=sum(c.output_tokens or 0 for c in made),
201
+ )