appstore-precheck 1.19.0 → 1.20.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.
- package/CHANGELOG.md +46 -0
- package/README.md +81 -39
- package/package.json +2 -2
- package/skills/appstore-precheck/SKILL.md +39 -146
- package/skills/appstore-precheck/guidelines-baseline.json +284 -35
- package/skills/appstore-precheck/guidelines-fingerprints.json +307 -93
- package/skills/appstore-precheck/references/finding-commentary.md +93 -0
- package/skills/appstore-precheck/references/methodology.md +56 -19
- package/skills/appstore-precheck/references/optional-review.md +56 -0
- package/skills/appstore-precheck/references/pierre-deep-review.md +292 -47
- package/skills/appstore-precheck/references/review-catalog.json +500 -13
- package/skills/appstore-precheck/references/screenshot-vision-review.md +8 -8
- package/skills/appstore-precheck/references/simulator-dynamic-review.md +72 -12
- package/skills/appstore-precheck/references/typesafe.md +15 -0
- package/skills/appstore-precheck/scripts/artifact-review.sh +10 -0
- package/skills/appstore-precheck/scripts/augment-json.py +29 -0
- package/skills/appstore-precheck/scripts/build-run.sh +5 -0
- package/skills/appstore-precheck/scripts/coverage-sections.sh +6 -0
- package/skills/appstore-precheck/scripts/dynamic-run.sh +94 -9
- package/skills/appstore-precheck/scripts/dynamic.sh +25 -1
- package/skills/appstore-precheck/scripts/evidence.sh +8 -3
- package/skills/appstore-precheck/scripts/findings.sh +8 -0
- package/skills/appstore-precheck/scripts/lib/artifact-review.py +518 -0
- package/skills/appstore-precheck/scripts/lib/asc-client.py +293 -0
- package/skills/appstore-precheck/scripts/lib/build-evidence.py +50 -0
- package/skills/appstore-precheck/scripts/lib/build-exec.py +50 -0
- package/skills/appstore-precheck/scripts/lib/build-plan.py +106 -0
- package/skills/appstore-precheck/scripts/lib/build-plan.sh +15 -0
- package/skills/appstore-precheck/scripts/lib/build-run.py +177 -0
- package/skills/appstore-precheck/scripts/lib/coverage-run.sh +23 -0
- package/skills/appstore-precheck/scripts/lib/coverage-sections.py +244 -0
- package/skills/appstore-precheck/scripts/lib/dyn-demo-login.py +111 -0
- package/skills/appstore-precheck/scripts/lib/dyn-device.sh +32 -4
- package/skills/appstore-precheck/scripts/lib/dyn-explore.py +312 -0
- package/skills/appstore-precheck/scripts/lib/dyn-guideline-capture.py +301 -0
- package/skills/appstore-precheck/scripts/lib/dyn-guidelines.py +112 -0
- package/skills/appstore-precheck/scripts/lib/dyn-guidelines.sh +23 -0
- package/skills/appstore-precheck/scripts/lib/dyn-process.py +75 -0
- package/skills/appstore-precheck/scripts/lib/dyn-quorum.sh +28 -30
- package/skills/appstore-precheck/scripts/lib/dyn-scrub.py +79 -0
- package/skills/appstore-precheck/scripts/lib/dyn-signals.sh +2 -2
- package/skills/appstore-precheck/scripts/lib/metadata-review.py +369 -0
- package/skills/appstore-precheck/scripts/lib/optin-scan.sh +73 -0
- package/skills/appstore-precheck/scripts/lib/optional-records.py +60 -0
- package/skills/appstore-precheck/scripts/lib/runtime-blocking.py +26 -0
- package/skills/appstore-precheck/scripts/lib/safe_write.py +61 -0
- package/skills/appstore-precheck/scripts/lib/scan-guidelines.sh +199 -0
- package/skills/appstore-precheck/scripts/lib/static-guidelines.py +341 -0
- package/skills/appstore-precheck/scripts/lib/static-reader.py +39 -0
- package/skills/appstore-precheck/scripts/metadata-review.sh +4 -0
- package/skills/appstore-precheck/scripts/opt-in-review.py +160 -0
- package/skills/appstore-precheck/scripts/runtime-review.sh +5 -0
- package/skills/appstore-precheck/scripts/scan.sh +56 -23
- package/skills/appstore-precheck/scripts/semantic/client.py +3 -1
- package/skills/appstore-precheck/scripts/semantic/collect.py +82 -38
- package/skills/appstore-precheck/scripts/semantic/engine.py +165 -127
- package/skills/appstore-precheck/scripts/semantic/questions.py +5 -1
- package/skills/appstore-precheck/scripts/semantic/review_v4.py +81 -0
|
@@ -7,6 +7,7 @@ import tempfile
|
|
|
7
7
|
import time
|
|
8
8
|
from pathlib import Path
|
|
9
9
|
|
|
10
|
+
from .review_v4 import is_v4, evidence_gaps, compose_host_review
|
|
10
11
|
from .client import ServiceError, evaluate, validate_response
|
|
11
12
|
from .questions import MODEL, PRICE_PER_MILLION, VERSION, WORKFLOWS, questions_for
|
|
12
13
|
|
|
@@ -59,26 +60,30 @@ def validate_bundle(bundle):
|
|
|
59
60
|
or not isinstance(e.get('text'), str) or not e['text'].strip()):
|
|
60
61
|
raise ValueError('invalid evidence span')
|
|
61
62
|
ids.add(e['id'])
|
|
62
|
-
|
|
63
|
-
if job['workflow'] == 'rerank':
|
|
64
|
-
candidates = context['candidates']
|
|
65
|
-
if (not isinstance(candidates, list) or not 1 <= len(candidates) <= 32
|
|
66
|
-
or any(not isinstance(c, dict) or not isinstance(c.get('id'), str)
|
|
67
|
-
or not isinstance(c.get('text'), str) or not c['text'].strip() for c in candidates)
|
|
68
|
-
or len({c['id'] for c in candidates}) != len(candidates)):
|
|
69
|
-
raise ValueError('rerank needs 1..32 unique text candidates')
|
|
70
|
-
if job['workflow'] == 'drift':
|
|
71
|
-
if not isinstance(context['rule_catalog'], list) or len(context['rule_catalog']) > 64:
|
|
72
|
-
raise ValueError('drift rule_catalog must be an array of at most 64 entries')
|
|
73
|
-
if job['workflow'] == 'verify' and context['source_id'] not in ids:
|
|
74
|
-
raise ValueError('verification source_id is not a supplied evidence ID')
|
|
75
|
-
if job['workflow'] == 'disclosure':
|
|
76
|
-
terms = context['product_terms']
|
|
77
|
-
if not isinstance(terms, dict) or type(terms.get('trial')) is not bool:
|
|
78
|
-
raise ValueError('product_terms.trial must be a boolean')
|
|
63
|
+
validate_workflow_context(job, ids)
|
|
79
64
|
return bundle
|
|
80
65
|
|
|
81
66
|
|
|
67
|
+
def validate_workflow_context(job, ids):
|
|
68
|
+
context = job['context']
|
|
69
|
+
if job['workflow'] == 'rerank':
|
|
70
|
+
candidates = context['candidates']
|
|
71
|
+
if (not isinstance(candidates, list) or not 1 <= len(candidates) <= 32
|
|
72
|
+
or any(not isinstance(c, dict) or not isinstance(c.get('id'), str)
|
|
73
|
+
or not isinstance(c.get('text'), str) or not c['text'].strip() for c in candidates)
|
|
74
|
+
or len({c['id'] for c in candidates}) != len(candidates)):
|
|
75
|
+
raise ValueError('rerank needs 1..32 unique text candidates')
|
|
76
|
+
if job['workflow'] == 'drift':
|
|
77
|
+
if not isinstance(context['rule_catalog'], list) or len(context['rule_catalog']) > 64:
|
|
78
|
+
raise ValueError('drift rule_catalog must be an array of at most 64 entries')
|
|
79
|
+
if job['workflow'] == 'verify' and context['source_id'] not in ids:
|
|
80
|
+
raise ValueError('verification source_id is not a supplied evidence ID')
|
|
81
|
+
if job['workflow'] == 'disclosure':
|
|
82
|
+
terms = context['product_terms']
|
|
83
|
+
if not isinstance(terms, dict) or type(terms.get('trial')) is not bool:
|
|
84
|
+
raise ValueError('product_terms.trial must be a boolean')
|
|
85
|
+
|
|
86
|
+
|
|
82
87
|
def request_for(job, model=MODEL):
|
|
83
88
|
if not re.fullmatch(r'jev-\d+\.\d+\.\d+', model):
|
|
84
89
|
raise ValueError('pin a versioned Jev model, e.g. jev-1.13.0')
|
|
@@ -94,102 +99,115 @@ def fallback(job, reason):
|
|
|
94
99
|
return {'id': job['id'], 'workflow': job['workflow'], 'advisory': True,
|
|
95
100
|
'check_key': job.get('check_key'),
|
|
96
101
|
'guideline': definition.get('guideline') if isinstance(definition, dict) else None,
|
|
102
|
+
'catalog_version': 4 if is_v4(job) else job.get('catalog_version'),
|
|
103
|
+
'advisory_only': is_v4(job),
|
|
97
104
|
'outcome': 'insufficient_evidence', 'action': 'pierre_review', 'reason': reason,
|
|
98
105
|
'evidence': [], 'model_probability': None, 'model_confidence': None}
|
|
99
106
|
|
|
100
107
|
|
|
101
|
-
def
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
result['
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
if not job['coverage']['complete'] or job['coverage']['missing']:
|
|
109
|
-
result['reason'] = 'incomplete evidence coverage'
|
|
110
|
-
return result
|
|
111
|
-
evidence_answer = answers.get('evidence')
|
|
112
|
-
if evidence_answer and evidence_answer['choice'] != 'none':
|
|
113
|
-
selected = evidence_answer['choice']
|
|
114
|
-
if evidence_answer['probabilities'][selected] >= THRESHOLDS['positive']:
|
|
115
|
-
result['evidence'] = [e for e in job['evidence'] if e['id'] == selected]
|
|
108
|
+
def categorical(answers, result, key):
|
|
109
|
+
answer = answers[key]
|
|
110
|
+
probability = answer['probabilities'][answer['choice']]
|
|
111
|
+
result['model_probability'] = probability
|
|
112
|
+
result['model_confidence'] = answer['confidence']
|
|
113
|
+
return answer['choice'] if probability >= THRESHOLDS['positive'] and answer['confidence'] >= THRESHOLDS['confidence'] else None
|
|
114
|
+
|
|
116
115
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
def binary(keys, positive=True):
|
|
125
|
-
values = [answers[k]['noul'] for k in keys]
|
|
126
|
-
if positive:
|
|
127
|
-
return 'finding' if any(v >= THRESHOLDS['positive'] for v in values) else (
|
|
128
|
-
'pass' if all(v <= THRESHOLDS['negative'] for v in values) else None)
|
|
129
|
-
return 'finding' if any(v <= THRESHOLDS['negative'] for v in values) else (
|
|
130
|
-
'pass' if all(v >= THRESHOLDS['support'] for v in values) else None)
|
|
116
|
+
def binary(answers, keys, positive=True):
|
|
117
|
+
values = [answers[k]['noul'] for k in keys]
|
|
118
|
+
if positive:
|
|
119
|
+
return 'finding' if any(v >= THRESHOLDS['positive'] for v in values) else (
|
|
120
|
+
'pass' if all(v <= THRESHOLDS['negative'] for v in values) else None)
|
|
121
|
+
return 'finding' if any(v <= THRESHOLDS['negative'] for v in values) else (
|
|
122
|
+
'pass' if all(v >= THRESHOLDS['support'] for v in values) else None)
|
|
131
123
|
|
|
124
|
+
|
|
125
|
+
def disclosure_outcome(job, answers, result):
|
|
126
|
+
keys = ['renewal', 'cancellation']
|
|
127
|
+
if job['context']['product_terms']['trial']:
|
|
128
|
+
keys.append('trial_charge')
|
|
129
|
+
outcome = binary(answers, keys, positive=False)
|
|
130
|
+
if job['context'].get('locale_pair'):
|
|
131
|
+
relation = categorical(answers, result, 'locale_relation')
|
|
132
|
+
if relation in ('omission', 'contradiction'):
|
|
133
|
+
outcome = 'finding'
|
|
134
|
+
elif relation != 'equivalent' and outcome != 'finding':
|
|
135
|
+
outcome = None
|
|
136
|
+
return outcome
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def simple_outcome(job, answers, result):
|
|
132
140
|
workflow = job['workflow']
|
|
133
|
-
outcome = None
|
|
134
141
|
if workflow == 'review':
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
poor = sum(a['probabilities'][str(i)] for i in (0, 1))
|
|
142
|
+
return categorical(answers, result, 'outcome')
|
|
143
|
+
if workflow == 'copy':
|
|
144
|
+
return binary(answers, [k for k in answers if k != 'evidence'])
|
|
145
|
+
if workflow == 'purpose':
|
|
146
|
+
poor = sum(answers['specificity']['probabilities'][str(i)] for i in (0, 1))
|
|
141
147
|
match = answers['feature_match']['noul']
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
offering = categorical('offering')
|
|
148
|
+
return 'finding' if poor >= .90 or match <= .10 else ('pass' if poor <= .10 and match >= .95 else None)
|
|
149
|
+
if workflow == 'disclosure':
|
|
150
|
+
return disclosure_outcome(job, answers, result)
|
|
151
|
+
if workflow == 'consistency':
|
|
152
|
+
return {'supported': 'pass', 'contradicted': 'finding'}.get(categorical(answers, result, 'relation'))
|
|
153
|
+
if workflow == 'verify':
|
|
154
|
+
source = next(e for e in job['evidence'] if e['id'] == job['context']['source_id'])
|
|
155
|
+
result['evidence'] = [source]
|
|
156
|
+
supported, over = answers['supported']['noul'], answers['overstatement']['noul']
|
|
157
|
+
return 'finding' if supported <= .10 or over >= .90 else ('pass' if supported >= .95 and over <= .10 else None)
|
|
158
|
+
return None
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
def descriptive_result(job, answers, result):
|
|
162
|
+
workflow = job['workflow']
|
|
163
|
+
if workflow == 'routing':
|
|
164
|
+
offering = categorical(answers, result, 'offering')
|
|
159
165
|
result['route'] = {'digital': 'digital_purchase_review', 'physical': 'physical_service_review',
|
|
160
166
|
'mixed': 'combined_purchase_review'}.get(offering, 'pierre_review')
|
|
161
167
|
result['reason'] = 'routing hint only; exemption and account signals never waive a finding'
|
|
162
168
|
result['action'] = result['route']
|
|
163
|
-
return result
|
|
164
169
|
elif workflow == 'rerank':
|
|
165
170
|
candidates = job['context']['candidates']
|
|
166
171
|
ranked = [{**c, 'model_score': answers['candidate_%d' % i]['score'],
|
|
167
172
|
'model_confidence': answers['candidate_%d' % i]['confidence']}
|
|
168
173
|
for i, c in enumerate(candidates)]
|
|
169
|
-
# Keep the original candidate set and ordering if any rank is uncertain.
|
|
170
174
|
confident = all(c['model_confidence'] >= THRESHOLDS['confidence'] for c in ranked)
|
|
171
175
|
result['ranking'] = sorted(ranked, key=lambda c: -c['model_score']) if confident else ranked
|
|
172
176
|
result['action'] = 'ranked' if confident else 'original_order'
|
|
173
177
|
result['reason'] = 'ranking only; all candidate sections retained'
|
|
174
|
-
return result
|
|
175
|
-
elif workflow == 'verify':
|
|
176
|
-
source = next(e for e in job['evidence'] if e['id'] == job['context']['source_id'])
|
|
177
|
-
result['evidence'] = [source]
|
|
178
|
-
supported, over = answers['supported']['noul'], answers['overstatement']['noul']
|
|
179
|
-
outcome = 'finding' if supported <= 0.10 or over >= 0.90 else (
|
|
180
|
-
'pass' if supported >= 0.95 and over <= 0.10 else None)
|
|
181
178
|
elif workflow == 'drift':
|
|
182
|
-
change = categorical('change')
|
|
179
|
+
change = categorical(answers, result, 'change')
|
|
183
180
|
result['affected_rules'] = [r for i, r in enumerate(job['context']['rule_catalog'])
|
|
184
|
-
if answers['affected_%d' % i]['noul'] >=
|
|
181
|
+
if answers['affected_%d' % i]['noul'] >= .10]
|
|
185
182
|
result['change_type'] = change or 'unclear'
|
|
186
183
|
result['reason'] = 'human reconciliation required; deterministic drift warning retained'
|
|
187
|
-
return result
|
|
188
184
|
elif workflow == 'functionality':
|
|
189
185
|
result['functional_completeness_score'] = answers['completeness']['score']
|
|
190
|
-
result['category'] = categorical('category') or 'unknown'
|
|
186
|
+
result['category'] = categorical(answers, result, 'category') or 'unknown'
|
|
191
187
|
result['reason'] = 'functional evidence for Pierre; not a compliance or rejection score'
|
|
188
|
+
else:
|
|
189
|
+
return False
|
|
190
|
+
return True
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
def compose(job, body):
|
|
194
|
+
"""Thresholds are experimental; conclusions never resolve scanner findings."""
|
|
195
|
+
if is_v4(job):
|
|
196
|
+
return compose_host_review(job, body, text_only=True)
|
|
197
|
+
result = fallback(job, 'uncertain judgment')
|
|
198
|
+
answers = body['answers']
|
|
199
|
+
result.update(judgments=answers, model=body['model'], usage=body['usage'])
|
|
200
|
+
if not job['coverage']['complete'] or job['coverage']['missing']:
|
|
201
|
+
result['reason'] = 'incomplete evidence coverage'
|
|
192
202
|
return result
|
|
203
|
+
evidence_answer = answers.get('evidence')
|
|
204
|
+
if evidence_answer and evidence_answer['choice'] != 'none':
|
|
205
|
+
selected = evidence_answer['choice']
|
|
206
|
+
if evidence_answer['probabilities'][selected] >= THRESHOLDS['positive']:
|
|
207
|
+
result['evidence'] = [e for e in job['evidence'] if e['id'] == selected]
|
|
208
|
+
if descriptive_result(job, answers, result):
|
|
209
|
+
return result
|
|
210
|
+
outcome = simple_outcome(job, answers, result)
|
|
193
211
|
if outcome and outcome != 'insufficient_evidence':
|
|
194
212
|
if outcome == 'finding' and not result['evidence']:
|
|
195
213
|
result['reason'] = 'concern has no confidently selected evidence span'
|
|
@@ -213,60 +231,77 @@ def atomic_json(path, value):
|
|
|
213
231
|
os.unlink(name)
|
|
214
232
|
|
|
215
233
|
|
|
234
|
+
def preflight_result(job, key):
|
|
235
|
+
gaps = evidence_gaps(job)
|
|
236
|
+
result = None
|
|
237
|
+
if gaps or not job['coverage']['complete'] or job['coverage']['missing']:
|
|
238
|
+
result = fallback(job, '; '.join(gaps) if gaps else 'incomplete evidence coverage; complete the bundle or continue with Pierre')
|
|
239
|
+
context = job['context']
|
|
240
|
+
if result is None and job['workflow'] == 'verify' and context.get('quote'):
|
|
241
|
+
source = next(e for e in job['evidence'] if e['id'] == context['source_id'])
|
|
242
|
+
if ' '.join(context['quote'].split()) not in ' '.join(source['text'].split()):
|
|
243
|
+
result = fallback(job, 'quoted text is absent from the cited source; use original finding template')
|
|
244
|
+
result.update(outcome='finding', action='advisory_finding', evidence=[source])
|
|
245
|
+
if result is not None:
|
|
246
|
+
result.update(cached=False, request_sha256=key, latency_ms=0, estimated_cost_usd=0,
|
|
247
|
+
billed_input_tokens=0, request_attempted=False, transport_attempts=0,
|
|
248
|
+
retry_count=0, retry_billing_unknown=False)
|
|
249
|
+
return result
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
def load_response(path, key, request):
|
|
253
|
+
if path and path.is_file():
|
|
254
|
+
try:
|
|
255
|
+
record = json.loads(path.read_text(encoding='utf-8'))
|
|
256
|
+
if record['request_sha256'] != key or record['request'] != request:
|
|
257
|
+
raise ServiceError('cache request mismatch')
|
|
258
|
+
return validate_response(record['response'], request)
|
|
259
|
+
except (OSError, ValueError, KeyError, ServiceError):
|
|
260
|
+
pass # Bad cache is never trusted as a result.
|
|
261
|
+
return None
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
def get_response(request, path, key, live, call, transport, state):
|
|
265
|
+
body = load_response(path, key, request)
|
|
266
|
+
state['cached'] = body is not None
|
|
267
|
+
if body is not None:
|
|
268
|
+
return body
|
|
269
|
+
if not live:
|
|
270
|
+
raise ServiceError('no valid cached result; live inference not enabled')
|
|
271
|
+
if call is evaluate and not os.environ.get('TYPESAFE_API_KEY'):
|
|
272
|
+
raise ServiceError('TYPESAFE_API_KEY is not set')
|
|
273
|
+
state['attempted'] = True
|
|
274
|
+
body = validate_response(call(request, telemetry=transport) if call is evaluate else call(request), request)
|
|
275
|
+
if path:
|
|
276
|
+
try:
|
|
277
|
+
atomic_json(path, {'request_sha256': key, 'request': request, 'response': body})
|
|
278
|
+
except OSError:
|
|
279
|
+
pass # A cache failure never discards a valid answer.
|
|
280
|
+
return body
|
|
281
|
+
|
|
282
|
+
|
|
216
283
|
def run_job(job, model=MODEL, live=False, cache_dir=None, call=evaluate):
|
|
217
284
|
request = request_for(job, model)
|
|
218
285
|
key = digest({'request': request, 'questions_version': VERSION, 'thresholds': THRESHOLDS})
|
|
219
286
|
path = Path(cache_dir) / (key + '.json') if cache_dir else None
|
|
220
287
|
started = time.monotonic()
|
|
221
|
-
|
|
222
|
-
if
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
estimated_cost_usd=0, billed_input_tokens=0, request_attempted=False)
|
|
226
|
-
return result
|
|
227
|
-
if job['workflow'] == 'verify' and context.get('quote'):
|
|
228
|
-
source = next(e for e in job['evidence'] if e['id'] == context['source_id'])
|
|
229
|
-
if ' '.join(context['quote'].split()) not in ' '.join(source['text'].split()):
|
|
230
|
-
result = fallback(job, 'quoted text is absent from the cited source; use original finding template')
|
|
231
|
-
result.update(outcome='finding', action='advisory_finding', evidence=[source], cached=False,
|
|
232
|
-
request_sha256=key, latency_ms=0, estimated_cost_usd=0, billed_input_tokens=0,
|
|
233
|
-
request_attempted=False)
|
|
234
|
-
return result
|
|
288
|
+
early = preflight_result(job, key)
|
|
289
|
+
if early is not None:
|
|
290
|
+
return early
|
|
291
|
+
transport, state = {'attempts': 0}, {'attempted': False, 'cached': False}
|
|
235
292
|
try:
|
|
236
|
-
|
|
237
|
-
attempted = False
|
|
238
|
-
body = None
|
|
239
|
-
if path and path.is_file():
|
|
240
|
-
try:
|
|
241
|
-
record = json.loads(path.read_text(encoding='utf-8'))
|
|
242
|
-
if record['request_sha256'] != key or record['request'] != request:
|
|
243
|
-
raise ServiceError('cache request mismatch')
|
|
244
|
-
body = validate_response(record['response'], request)
|
|
245
|
-
cached = True
|
|
246
|
-
except (OSError, ValueError, KeyError, ServiceError):
|
|
247
|
-
body = None # Bad cache is never trusted as a result.
|
|
248
|
-
if body is None:
|
|
249
|
-
if not live:
|
|
250
|
-
raise ServiceError('no valid cached result; live inference not enabled')
|
|
251
|
-
if call is evaluate and not os.environ.get('TYPESAFE_API_KEY'):
|
|
252
|
-
raise ServiceError('TYPESAFE_API_KEY is not set')
|
|
253
|
-
attempted = True
|
|
254
|
-
body = validate_response(call(request), request)
|
|
255
|
-
if path:
|
|
256
|
-
try:
|
|
257
|
-
atomic_json(path, {'request_sha256': key, 'request': request, 'response': body})
|
|
258
|
-
except OSError:
|
|
259
|
-
path = None # Preserve a valid answer even if optional cache persistence fails.
|
|
293
|
+
body = get_response(request, path, key, live, call, transport, state)
|
|
260
294
|
result = compose(job, body)
|
|
261
|
-
result['
|
|
262
|
-
result['
|
|
263
|
-
result['request_attempted'] = attempted
|
|
264
|
-
result['billed_input_tokens'] = 0 if cached else body['usage']['input_tokens']
|
|
295
|
+
result.update(response=body, cached=state['cached'], request_attempted=state['attempted'])
|
|
296
|
+
result['billed_input_tokens'] = 0 if state['cached'] else body['usage']['input_tokens']
|
|
265
297
|
result['estimated_cost_usd'] = result['billed_input_tokens'] * PRICE_PER_MILLION / 1_000_000
|
|
266
298
|
except ServiceError as exc:
|
|
267
299
|
result = fallback(job, str(exc))
|
|
268
|
-
result.update(cached=False, estimated_cost_usd=None if attempted else 0,
|
|
269
|
-
billed_input_tokens=None if attempted else 0, request_attempted=attempted)
|
|
300
|
+
result.update(cached=False, estimated_cost_usd=None if state['attempted'] else 0,
|
|
301
|
+
billed_input_tokens=None if state['attempted'] else 0, request_attempted=state['attempted'])
|
|
302
|
+
result['transport_attempts'] = transport['attempts'] if call is evaluate else (1 if result.get('request_attempted') else 0)
|
|
303
|
+
result['retry_count'] = max(0, result['transport_attempts'] - 1)
|
|
304
|
+
result['retry_billing_unknown'] = result['retry_count'] > 0
|
|
270
305
|
result['request_sha256'] = key
|
|
271
306
|
result['latency_ms'] = round((time.monotonic() - started) * 1000, 3)
|
|
272
307
|
return result
|
|
@@ -277,6 +312,9 @@ def render_text(result):
|
|
|
277
312
|
pointer = ', '.join('%s:%s' % (e['path'], e['line']) for e in result['evidence'])
|
|
278
313
|
message = ' '.join(('%s — %s %s' % (result['id'], result['reason'], pointer)).split())
|
|
279
314
|
guideline = ' '.join(str(result.get('guideline') or 'semantic/' + result['workflow']).split())
|
|
315
|
+
if result.get('advisory_only') and result['outcome'] in ('insufficient_evidence', 'no_signal'):
|
|
316
|
+
label = 'REVIEW-SKIP' if result['outcome'] == 'insufficient_evidence' else 'REVIEW-NO-SIGNAL'
|
|
317
|
+
return label + ': ' + guideline + ' — ' + message
|
|
280
318
|
if result['outcome'] in ('pass', 'not_applicable'):
|
|
281
319
|
return 'REVIEW-PASS: ' + guideline + ' — ' + message + (' — not applicable' if result['outcome'] == 'not_applicable' else '')
|
|
282
320
|
return 'REVIEW-FINDING: ' + guideline + ' WARN — ' + message
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"""Versioned, bounded semantic judgments. These never control the upload gate."""
|
|
2
|
-
|
|
2
|
+
from .review_v4 import is_v4, outcome_question
|
|
3
|
+
|
|
4
|
+
VERSION = 2
|
|
3
5
|
MODEL = 'jev-1.13.0'
|
|
4
6
|
PRICE_PER_MILLION = 0.042 # USD/input Mtok, documentation checked 2026-09-18
|
|
5
7
|
|
|
@@ -132,6 +134,8 @@ WORKFLOWS = {
|
|
|
132
134
|
def questions_for(job):
|
|
133
135
|
questions = dict(WORKFLOWS[job['workflow']]['questions'])
|
|
134
136
|
context = job['context']
|
|
137
|
+
if is_v4(job):
|
|
138
|
+
questions['outcome'] = outcome_question(context['check_definition'], BOUNDARY)
|
|
135
139
|
if job['workflow'] == 'rerank':
|
|
136
140
|
for i, _ in enumerate(context['candidates']):
|
|
137
141
|
questions['candidate_%d' % i] = score(
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"""Executable v4 advisory gates, including a separate host-vision composition boundary."""
|
|
2
|
+
UNKNOWN = {'', 'unknown', 'unverified', 'unspecified', 'missing', 'not supplied'}
|
|
3
|
+
# Explicit host-provided kinds require direct visual observation; the local collector cannot supply them.
|
|
4
|
+
HOST_INPUT_KINDS = {'screenshots', 'runtime-screenshots', 'icon'}
|
|
5
|
+
VISUAL = HOST_INPUT_KINDS
|
|
6
|
+
OUTCOMES = {
|
|
7
|
+
'finding': 'The supplied evidence establishes a concrete concern under this bounded question.',
|
|
8
|
+
'no_signal': 'The reviewed evidence contains no concrete concern; this is not a compliance pass.',
|
|
9
|
+
'insufficient_evidence': 'Required inputs, context, applicability, or observations are missing or conflicting.',
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def is_v4(job):
|
|
14
|
+
check = job.get('context', {}).get('check_definition', {})
|
|
15
|
+
return job.get('workflow') == 'review' and isinstance(check, dict) and 'evidence_inputs' in check
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def known(value):
|
|
19
|
+
return value is not None and value is not False and str(value).strip().lower() not in UNKNOWN
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def evidence_gaps(job, text_only=True):
|
|
23
|
+
if not is_v4(job):
|
|
24
|
+
return []
|
|
25
|
+
check, context = job['context']['check_definition'], job['context']
|
|
26
|
+
evidence = job.get('evidence', [])
|
|
27
|
+
kinds = {kind for e in evidence if e.get('text', '').strip()
|
|
28
|
+
for kind in e.get('evidence_inputs', [e.get('kind')])}
|
|
29
|
+
gaps = ['missing evidence input: ' + kind for kind in check['evidence_inputs'] if kind not in kinds]
|
|
30
|
+
gaps += ['unknown required context: ' + key for key in check.get('required_context', [])
|
|
31
|
+
if not known(context.get(key))]
|
|
32
|
+
if check['requires_vision']:
|
|
33
|
+
if text_only:
|
|
34
|
+
gaps.append('requires host vision review; Jev is text-only')
|
|
35
|
+
else:
|
|
36
|
+
for kind in set(check['evidence_inputs']) & VISUAL:
|
|
37
|
+
if not any(e.get('kind') == kind and e.get('representation') == 'host visual observation'
|
|
38
|
+
for e in evidence):
|
|
39
|
+
gaps.append('missing host visual observation: ' + kind)
|
|
40
|
+
return gaps
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def outcome_question(check, boundary):
|
|
44
|
+
instructions = (boundary + check['question'] + ' Required evidence inputs: ' +
|
|
45
|
+
', '.join(check['evidence_inputs']) + '. Abstain when: ' +
|
|
46
|
+
' '.join(check['abstain_when']) + ' Required context: ' +
|
|
47
|
+
', '.join(check.get('required_context', [])) +
|
|
48
|
+
'. No signal is advisory and never establishes policy compliance.')
|
|
49
|
+
return {'type': 'choice', 'instructions': instructions, 'criteria': OUTCOMES}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def compose_host_review(job, body, text_only=False):
|
|
53
|
+
"""Compose explicit host observations; text-only clients must pass text_only=True."""
|
|
54
|
+
check = job['context']['check_definition']
|
|
55
|
+
result = {'id': job['id'], 'workflow': 'review', 'advisory': True, 'check_key': job.get('check_key'),
|
|
56
|
+
'guideline': check['guideline'], 'catalog_version': 4, 'advisory_only': True, 'outcome': 'insufficient_evidence',
|
|
57
|
+
'action': 'pierre_review', 'reason': 'incomplete evidence coverage', 'evidence': [],
|
|
58
|
+
'model_probability': None, 'model_confidence': None}
|
|
59
|
+
gaps = evidence_gaps(job, text_only)
|
|
60
|
+
if gaps or not job['coverage']['complete'] or job['coverage']['missing']:
|
|
61
|
+
result['reason'] = '; '.join(gaps or job['coverage']['missing'] or ['incomplete evidence coverage'])
|
|
62
|
+
return result
|
|
63
|
+
answer = body.get('answers', {}).get('outcome', {})
|
|
64
|
+
choice = answer.get('choice')
|
|
65
|
+
probability = answer.get('probabilities', {}).get(choice, 0)
|
|
66
|
+
confidence = answer.get('confidence', 0)
|
|
67
|
+
result.update(model_probability=probability, model_confidence=confidence)
|
|
68
|
+
if choice not in OUTCOMES or choice == 'insufficient_evidence' or probability < .90 or confidence < .50:
|
|
69
|
+
result['reason'] = 'uncertain or unsupported advisory judgment'
|
|
70
|
+
return result
|
|
71
|
+
citation = body.get('answers', {}).get('evidence', {})
|
|
72
|
+
selected = citation.get('choice')
|
|
73
|
+
if citation.get('probabilities', {}).get(selected, 0) >= .90 and citation.get('confidence', 0) >= .50:
|
|
74
|
+
result['evidence'] = [e for e in job['evidence'] if e['id'] == selected]
|
|
75
|
+
if choice == 'finding' and not result['evidence']:
|
|
76
|
+
result['reason'] = 'concern has no confidently selected evidence span'
|
|
77
|
+
return result
|
|
78
|
+
result.update(outcome=choice, action='advisory_finding' if choice == 'finding' else 'advisory_result',
|
|
79
|
+
reason='bounded advisory judgment; no scanner verdict or compliance pass',
|
|
80
|
+
judgments=body.get('answers', {}))
|
|
81
|
+
return result
|