@riddledc/riddle-proof 0.8.31 → 0.8.32

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.
@@ -1,5 +1,5 @@
1
1
  export { b as runner } from '../runner-4LJ5z0D-.cjs';
2
2
  export { l as engineHarness } from '../engine-harness-LBfqbFSe.cjs';
3
3
  export { p as proofRunCore } from '../proof-run-core-B1GeqkR8.cjs';
4
- export { p as proofRunEngine } from '../proof-run-engine-4dM37pEx.cjs';
4
+ export { p as proofRunEngine } from '../proof-run-engine-DeHxtGnW.cjs';
5
5
  import '../types.cjs';
@@ -1,5 +1,5 @@
1
1
  export { b as runner } from '../runner-BdQpOkZD.js';
2
2
  export { l as engineHarness } from '../engine-harness-CMACHP6A.js';
3
3
  export { p as proofRunCore } from '../proof-run-core-B1GeqkR8.js';
4
- export { p as proofRunEngine } from '../proof-run-engine-BqaeqAze.js';
4
+ export { p as proofRunEngine } from '../proof-run-engine-DYfmd8d7.js';
5
5
  import '../types.js';
@@ -1,2 +1,2 @@
1
- export { R as RiddleProofEngine, c as createRiddleProofEngine, e as executeWorkflow } from '../proof-run-engine-4dM37pEx.cjs';
1
+ export { R as RiddleProofEngine, c as createRiddleProofEngine, e as executeWorkflow } from '../proof-run-engine-DeHxtGnW.cjs';
2
2
  import '../proof-run-core-B1GeqkR8.cjs';
@@ -1,2 +1,2 @@
1
- export { R as RiddleProofEngine, c as createRiddleProofEngine, e as executeWorkflow } from '../proof-run-engine-BqaeqAze.js';
1
+ export { R as RiddleProofEngine, c as createRiddleProofEngine, e as executeWorkflow } from '../proof-run-engine-DYfmd8d7.js';
2
2
  import '../proof-run-core-B1GeqkR8.js';
@@ -292,7 +292,7 @@ declare function executeWorkflow(params: WorkflowParams, pluginConfig: any, reso
292
292
  blocking?: boolean;
293
293
  details?: Record<string, unknown>;
294
294
  ok: boolean;
295
- action: "author" | "recon" | "ship" | "implement" | "verify" | "setup" | "run";
295
+ action: "recon" | "author" | "ship" | "implement" | "verify" | "setup" | "run";
296
296
  state_path: string;
297
297
  stage: any;
298
298
  summary: string;
@@ -382,7 +382,7 @@ declare function executeWorkflow(params: WorkflowParams, pluginConfig: any, reso
382
382
  continueWithStage?: WorkflowStage | null;
383
383
  blocking?: boolean;
384
384
  details?: Record<string, unknown>;
385
- action: "author" | "recon" | "ship" | "implement" | "verify" | "setup" | "run";
385
+ action: "recon" | "author" | "ship" | "implement" | "verify" | "setup" | "run";
386
386
  state_path: string;
387
387
  stage: any;
388
388
  checkpoint: string;
@@ -659,7 +659,7 @@ declare function executeWorkflow(params: WorkflowParams, pluginConfig: any, reso
659
659
  error?: undefined;
660
660
  } | {
661
661
  ok: boolean;
662
- action: "author" | "recon" | "ship" | "implement" | "verify" | "setup";
662
+ action: "recon" | "author" | "ship" | "implement" | "verify" | "setup";
663
663
  state_path: string;
664
664
  stage: any;
665
665
  summary: string;
@@ -292,7 +292,7 @@ declare function executeWorkflow(params: WorkflowParams, pluginConfig: any, reso
292
292
  blocking?: boolean;
293
293
  details?: Record<string, unknown>;
294
294
  ok: boolean;
295
- action: "author" | "recon" | "ship" | "implement" | "verify" | "setup" | "run";
295
+ action: "recon" | "author" | "ship" | "implement" | "verify" | "setup" | "run";
296
296
  state_path: string;
297
297
  stage: any;
298
298
  summary: string;
@@ -382,7 +382,7 @@ declare function executeWorkflow(params: WorkflowParams, pluginConfig: any, reso
382
382
  continueWithStage?: WorkflowStage | null;
383
383
  blocking?: boolean;
384
384
  details?: Record<string, unknown>;
385
- action: "author" | "recon" | "ship" | "implement" | "verify" | "setup" | "run";
385
+ action: "recon" | "author" | "ship" | "implement" | "verify" | "setup" | "run";
386
386
  state_path: string;
387
387
  stage: any;
388
388
  checkpoint: string;
@@ -659,7 +659,7 @@ declare function executeWorkflow(params: WorkflowParams, pluginConfig: any, reso
659
659
  error?: undefined;
660
660
  } | {
661
661
  ok: boolean;
662
- action: "author" | "recon" | "ship" | "implement" | "verify" | "setup";
662
+ action: "recon" | "author" | "ship" | "implement" | "verify" | "setup";
663
663
  state_path: string;
664
664
  stage: any;
665
665
  summary: string;
@@ -1,2 +1,2 @@
1
1
  import './proof-run-core-B1GeqkR8.cjs';
2
- export { R as RiddleProofEngine, c as createRiddleProofEngine, e as executeWorkflow } from './proof-run-engine-4dM37pEx.cjs';
2
+ export { R as RiddleProofEngine, c as createRiddleProofEngine, e as executeWorkflow } from './proof-run-engine-DeHxtGnW.cjs';
@@ -1,2 +1,2 @@
1
1
  import './proof-run-core-B1GeqkR8.js';
2
- export { R as RiddleProofEngine, c as createRiddleProofEngine, e as executeWorkflow } from './proof-run-engine-BqaeqAze.js';
2
+ export { R as RiddleProofEngine, c as createRiddleProofEngine, e as executeWorkflow } from './proof-run-engine-DYfmd8d7.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riddledc/riddle-proof",
3
- "version": "0.8.31",
3
+ "version": "0.8.32",
4
4
  "description": "Reusable Riddle Proof contracts and helpers for evidence-backed agent changes.",
5
5
  "license": "MIT",
6
6
  "author": "RiddleDC",
@@ -227,6 +227,6 @@
227
227
  "build": "npm --workspace @riddledc/riddle-proof-app-contract run build --if-present && tsup src/index.ts src/types.ts src/result.ts src/state.ts src/checkpoint.ts src/run-card.ts src/runner.ts src/engine-harness.ts src/codex-exec-agent.ts src/local-agent.ts src/cli.ts src/cli/index.ts src/diagnostics.ts src/proof-session.ts src/playability.ts src/basic-gameplay.ts src/profile.ts src/profile/index.ts src/openclaw.ts src/proof-run-core.ts src/proof-run-engine.ts src/riddle-client.ts src/runtime/riddle-client.ts src/spec/index.ts src/spec/types.ts src/spec/result.ts src/spec/state.ts src/spec/checkpoint.ts src/spec/run-card.ts src/runtime/index.ts src/app-contract/index.ts src/advanced/index.ts src/advanced/runner.ts src/advanced/engine-harness.ts src/advanced/proof-run-core.ts src/advanced/proof-run-engine.ts src/adapters/openclaw.ts src/adapters/local-agent.ts src/adapters/codex-exec-agent.ts src/adapters/codex.ts --format cjs,esm --dts --out-dir dist --clean",
228
228
  "clean": "rm -rf dist",
229
229
  "lint": "echo 'lint: (not configured)'",
230
- "test": "npm run build && node test.js && node proof-run.test.js && node trust-boundary.test.js && node regression-packs.test.js && python3 runtime/tests/trust_boundary_regression.py && (python3 runtime/tests/recon_verify_smoke.py >/tmp/riddle-proof-recon-verify-smoke.json || (tail -120 /tmp/riddle-proof-recon-verify-smoke.json; exit 1))"
230
+ "test": "npm run build && node test.js && node proof-run.test.js && node trust-boundary.test.js && node regression-packs.test.js && python3 runtime/tests/trust_boundary_regression.py && python3 runtime/tests/ship_artifact_publication.py && (python3 runtime/tests/recon_verify_smoke.py >/tmp/riddle-proof-recon-verify-smoke.json || (tail -120 /tmp/riddle-proof-recon-verify-smoke.json; exit 1))"
231
231
  }
232
232
  }
@@ -1,7 +1,8 @@
1
1
  """Ship: commit, create PR, post proof artifacts, wait for CI, mark ready, cleanup."""
2
2
 
3
- import json, subprocess as sp, time, os, sys, re
3
+ import json, subprocess as sp, time, os, sys, re, shutil, tempfile, hashlib
4
4
  import urllib.error
5
+ import urllib.parse
5
6
  import urllib.request
6
7
  sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
7
8
  from util import load_state, save_state, invoke, git
@@ -9,6 +10,7 @@ from util import load_state, save_state, invoke, git
9
10
 
10
11
  DISCORD_API = 'https://discord.com/api/v10'
11
12
  SHIP_NOISE_PATHS = ('.codex', '.oc-smoke')
13
+ MAX_GITHUB_PROOF_ARTIFACT_BYTES = 10 * 1024 * 1024
12
14
  VISUAL_FIRST_MODES = {
13
15
  'visual', 'render', 'ui', 'layout', 'screenshot',
14
16
  'canvas', 'animation',
@@ -185,6 +187,306 @@ def truthy(value):
185
187
  return str(value or '').strip().lower() in ('1', 'true', 'yes', 'y', 'on')
186
188
 
187
189
 
190
+ def safe_slug(value, fallback='artifact'):
191
+ slug = re.sub(r'[^a-zA-Z0-9._-]+', '-', str(value or '').strip()).strip('-._')
192
+ return slug[:80] or fallback
193
+
194
+
195
+ def is_http_url(value):
196
+ text = str(value or '').strip()
197
+ return text.startswith('https://') or text.startswith('http://')
198
+
199
+
200
+ def is_file_url(value):
201
+ return str(value or '').strip().startswith('file://')
202
+
203
+
204
+ def path_from_file_url(url):
205
+ parsed = urllib.parse.urlparse(str(url or '').strip())
206
+ if parsed.scheme != 'file':
207
+ return ''
208
+ return urllib.request.url2pathname(parsed.path)
209
+
210
+
211
+ def local_path_from_artifact(artifact):
212
+ if not isinstance(artifact, dict):
213
+ return ''
214
+ path_value = str(artifact.get('path') or '').strip()
215
+ if path_value and os.path.exists(path_value):
216
+ return path_value
217
+ url = str(artifact.get('url') or '').strip()
218
+ if is_file_url(url):
219
+ decoded = path_from_file_url(url)
220
+ if decoded and os.path.exists(decoded):
221
+ return decoded
222
+ return ''
223
+
224
+
225
+ def artifact_kind(name, path_value='', url=''):
226
+ target = (str(name or '') + ' ' + str(path_value or '') + ' ' + str(url or '')).lower()
227
+ if re.search(r'\.(png|jpe?g|gif|webp|avif|svg)(\?|$|\s)', target):
228
+ return 'image'
229
+ if re.search(r'\.(json|har|txt|md|html|log)(\?|$|\s)', target):
230
+ return 'data'
231
+ return 'artifact'
232
+
233
+
234
+ def artifact_name(name, path_value='', fallback='artifact'):
235
+ source = str(name or '').strip() or os.path.basename(str(path_value or '').strip()) or fallback
236
+ source = source.split('?', 1)[0].split('#', 1)[0]
237
+ return safe_slug(source, fallback)
238
+
239
+
240
+ def add_artifact_source(sources, seen, role, name='', url='', path_value='', source='state'):
241
+ local_path = path_value if path_value and os.path.exists(path_value) else ''
242
+ if not local_path and is_file_url(url):
243
+ local_path = path_from_file_url(url)
244
+ key = local_path or str(url or '').strip()
245
+ if not key or key in seen:
246
+ return
247
+ seen.add(key)
248
+ kind = artifact_kind(name, local_path, url)
249
+ sources.append({
250
+ 'role': role,
251
+ 'name': artifact_name(name, local_path, role + '-artifact'),
252
+ 'url': str(url or '').strip(),
253
+ 'path': local_path,
254
+ 'kind': kind,
255
+ 'source': source,
256
+ })
257
+
258
+
259
+ def collect_proof_artifact_sources(state):
260
+ sources = []
261
+ seen = set()
262
+ for role, key in (('before', 'before_cdn'), ('prod', 'prod_cdn'), ('after', 'after_cdn')):
263
+ value = str(state.get(key) or '').strip()
264
+ if value:
265
+ add_artifact_source(sources, seen, role, os.path.basename(path_from_file_url(value)) if is_file_url(value) else role + '.png', value, '', key)
266
+
267
+ verify_results = state.get('verify_results') or {}
268
+ after = verify_results.get('after') if isinstance(verify_results, dict) else {}
269
+ raw = after.get('raw') if isinstance(after, dict) else {}
270
+ if isinstance(raw, dict):
271
+ for artifact in raw.get('outputs') or []:
272
+ if isinstance(artifact, dict):
273
+ add_artifact_source(sources, seen, 'after', artifact.get('name', ''), artifact.get('url', ''), local_path_from_artifact(artifact), 'verify_results.after.raw.outputs')
274
+ for artifact in raw.get('screenshots') or []:
275
+ if isinstance(artifact, dict):
276
+ add_artifact_source(sources, seen, 'after', artifact.get('name', ''), artifact.get('url', ''), local_path_from_artifact(artifact), 'verify_results.after.raw.screenshots')
277
+
278
+ bundle = state.get('evidence_bundle') or {}
279
+ bundle_after = bundle.get('after') if isinstance(bundle, dict) else {}
280
+ supporting = bundle_after.get('supporting_artifacts') if isinstance(bundle_after, dict) else {}
281
+ if isinstance(supporting, dict):
282
+ for field, kind_role in (('image_outputs', 'after'), ('data_outputs', 'after'), ('other_outputs', 'after')):
283
+ for artifact in supporting.get(field) or []:
284
+ if isinstance(artifact, dict):
285
+ add_artifact_source(sources, seen, kind_role, artifact.get('name', ''), artifact.get('url', ''), local_path_from_artifact(artifact), 'evidence_bundle.after.supporting_artifacts.' + field)
286
+
287
+ request = state.get('proof_assessment_request') or {}
288
+ request_supporting = request.get('supporting_artifacts') if isinstance(request, dict) else {}
289
+ if isinstance(request_supporting, dict):
290
+ for field, kind_role in (('image_outputs', 'after'), ('data_outputs', 'after'), ('other_outputs', 'after')):
291
+ for artifact in request_supporting.get(field) or []:
292
+ if isinstance(artifact, dict):
293
+ add_artifact_source(sources, seen, kind_role, artifact.get('name', ''), artifact.get('url', ''), local_path_from_artifact(artifact), 'proof_assessment_request.supporting_artifacts.' + field)
294
+
295
+ return sources
296
+
297
+
298
+ def local_proof_artifact_sources(state):
299
+ return [artifact for artifact in collect_proof_artifact_sources(state) if artifact.get('path') and os.path.exists(artifact.get('path'))]
300
+
301
+
302
+ def local_artifact_sources_fingerprint(local_sources):
303
+ digest = hashlib.sha256()
304
+ for artifact in sorted(local_sources, key=lambda item: item.get('path') or ''):
305
+ path_value = artifact.get('path') or ''
306
+ if not path_value or not os.path.exists(path_value):
307
+ continue
308
+ digest.update(path_value.encode('utf-8'))
309
+ digest.update(str(artifact.get('name') or '').encode('utf-8'))
310
+ digest.update(str(os.path.getsize(path_value)).encode('utf-8'))
311
+ with open(path_value, 'rb') as f:
312
+ while True:
313
+ chunk = f.read(1024 * 1024)
314
+ if not chunk:
315
+ break
316
+ digest.update(chunk)
317
+ return digest.hexdigest()
318
+
319
+
320
+ def public_proof_artifacts(state):
321
+ published = state.get('proof_artifact_publication') or {}
322
+ artifacts = published.get('artifacts') if isinstance(published, dict) else []
323
+ public = [artifact for artifact in artifacts or [] if isinstance(artifact, dict) and (artifact.get('raw_url') or artifact.get('html_url'))]
324
+ for artifact in collect_proof_artifact_sources(state):
325
+ url = str(artifact.get('url') or '').strip()
326
+ if is_http_url(url):
327
+ public.append({
328
+ **artifact,
329
+ 'raw_url': url,
330
+ 'html_url': url,
331
+ 'published': False,
332
+ })
333
+ deduped = []
334
+ seen = set()
335
+ for artifact in public:
336
+ key = artifact.get('raw_url') or artifact.get('html_url') or artifact.get('url')
337
+ if key and key not in seen:
338
+ seen.add(key)
339
+ deduped.append(artifact)
340
+ return deduped
341
+
342
+
343
+ def first_public_artifact_url(state, role, kind=None):
344
+ for artifact in public_proof_artifacts(state):
345
+ if artifact.get('role') != role:
346
+ continue
347
+ if kind and artifact.get('kind') != kind:
348
+ continue
349
+ return artifact.get('raw_url') or artifact.get('html_url') or artifact.get('url') or ''
350
+ return ''
351
+
352
+
353
+ def resolve_github_repo_name(repo_dir):
354
+ result = sp.run(['gh', 'repo', 'view', '--json', 'nameWithOwner', '--jq', '.nameWithOwner'],
355
+ cwd=repo_dir, capture_output=True, text=True, timeout=30)
356
+ if result.returncode == 0 and result.stdout.strip():
357
+ return result.stdout.strip()
358
+ remote = git_stdout(['config', '--get', 'remote.origin.url'], repo_dir)
359
+ match = re.search(r'github\.com[:/]([^/]+)/([^/.]+)(?:\.git)?$', remote)
360
+ if match:
361
+ return match.group(1) + '/' + match.group(2)
362
+ return ''
363
+
364
+
365
+ def write_artifact_readme(path_value, state, artifacts):
366
+ lines = [
367
+ '# Riddle Proof Artifacts',
368
+ '',
369
+ 'Run id: `' + str(state.get('run_id') or '') + '`',
370
+ 'PR: ' + str(state.get('pr_url') or ''),
371
+ 'Goal: ' + str(state.get('change_request') or ''),
372
+ 'Verification mode: ' + str(state.get('verification_mode') or 'proof'),
373
+ '',
374
+ '## Artifacts',
375
+ '',
376
+ ]
377
+ for artifact in artifacts:
378
+ rel = artifact.get('filename') or artifact.get('published_path') or ''
379
+ label = artifact.get('role', 'artifact') + ' / ' + artifact.get('name', rel)
380
+ if artifact.get('kind') == 'image':
381
+ lines.append('- ' + label + ': `'+ rel + '`')
382
+ lines.append('')
383
+ lines.append(' ![' + label + '](' + rel + ')')
384
+ lines.append('')
385
+ else:
386
+ lines.append('- [' + label + '](' + rel + ')')
387
+ with open(path_value, 'w') as f:
388
+ f.write('\n'.join(lines).rstrip() + '\n')
389
+
390
+
391
+ def publish_local_proof_artifacts_to_github(state, repo_dir, pr_num):
392
+ local_sources = local_proof_artifact_sources(state)
393
+ if not local_sources:
394
+ state['proof_artifact_publication'] = {'ok': True, 'skipped': True, 'reason': 'no local file artifacts'}
395
+ save_state(state)
396
+ return state['proof_artifact_publication']
397
+
398
+ source_fingerprint = local_artifact_sources_fingerprint(local_sources)
399
+ existing = state.get('proof_artifact_publication') or {}
400
+ if existing.get('ok') and existing.get('artifacts') and existing.get('source_fingerprint') == source_fingerprint:
401
+ return existing
402
+
403
+ repo_name = resolve_github_repo_name(repo_dir)
404
+ if not repo_name:
405
+ raise SystemExit('Could not resolve GitHub repository name for proof artifact publication.')
406
+
407
+ run_id = safe_slug(state.get('run_id') or str(int(time.time())), 'run')
408
+ pr_slug = safe_slug('pr-' + str(pr_num or 'unknown'), 'pr')
409
+ artifact_branch = safe_slug('riddle-proof-artifacts-' + pr_slug + '-' + run_id, 'riddle-proof-artifacts')
410
+ artifact_dir_name = 'riddle-proof/' + run_id
411
+ tmp = tempfile.mkdtemp(prefix='riddle-proof-gh-artifacts-')
412
+ published = []
413
+ try:
414
+ git_checked(['init'], tmp)
415
+ origin = git_stdout(['config', '--get', 'remote.origin.url'], repo_dir)
416
+ git_checked(['remote', 'add', 'origin', origin], tmp)
417
+ git_checked(['checkout', '-b', artifact_branch], tmp)
418
+ git_checked(['config', 'user.name', 'Riddle Proof'], tmp)
419
+ git_checked(['config', 'user.email', 'riddle-proof@riddledc.com'], tmp)
420
+ target_dir = os.path.join(tmp, artifact_dir_name)
421
+ os.makedirs(target_dir, exist_ok=True)
422
+ used_names = set()
423
+ for artifact in local_sources:
424
+ source_path = artifact.get('path')
425
+ try:
426
+ size = os.path.getsize(source_path)
427
+ except Exception:
428
+ continue
429
+ if size > MAX_GITHUB_PROOF_ARTIFACT_BYTES:
430
+ published.append({**artifact, 'published': False, 'skipped': True, 'reason': 'artifact exceeds size limit'})
431
+ continue
432
+ base_name = artifact_name(artifact.get('name'), source_path, artifact.get('role', 'artifact') + '-artifact')
433
+ filename = base_name
434
+ stem, ext = os.path.splitext(base_name)
435
+ counter = 2
436
+ while filename in used_names:
437
+ filename = stem + '-' + str(counter) + ext
438
+ counter += 1
439
+ used_names.add(filename)
440
+ dest = os.path.join(target_dir, filename)
441
+ shutil.copyfile(source_path, dest)
442
+ published_path = artifact_dir_name + '/' + filename
443
+ digest = hashlib.sha256(open(source_path, 'rb').read()).hexdigest()
444
+ published.append({
445
+ **artifact,
446
+ 'filename': filename,
447
+ 'published_path': published_path,
448
+ 'size_bytes': size,
449
+ 'sha256': digest,
450
+ 'published': True,
451
+ })
452
+ write_artifact_readme(os.path.join(target_dir, 'README.md'), state, [a for a in published if a.get('published')])
453
+ with open(os.path.join(target_dir, 'proof-artifacts.json'), 'w') as f:
454
+ json.dump({
455
+ 'version': 'riddle-proof.github-artifacts.v1',
456
+ 'run_id': state.get('run_id', ''),
457
+ 'pr_url': state.get('pr_url', ''),
458
+ 'artifacts': published,
459
+ }, f, indent=2)
460
+ git_checked(['add', '.'], tmp)
461
+ git_checked(['commit', '-m', 'Publish Riddle Proof artifacts'], tmp)
462
+ commit = git_stdout(['rev-parse', 'HEAD'], tmp)
463
+ push = sp.run(['git', 'push', 'origin', 'HEAD:refs/heads/' + artifact_branch, '--force'],
464
+ cwd=tmp, capture_output=True, text=True, timeout=120)
465
+ if push.returncode != 0:
466
+ raise SystemExit('Failed to push proof artifact branch: ' + push.stderr[:300])
467
+ for artifact in published:
468
+ if artifact.get('published'):
469
+ published_path = artifact.get('published_path')
470
+ artifact['raw_url'] = 'https://raw.githubusercontent.com/' + repo_name + '/' + commit + '/' + published_path
471
+ artifact['html_url'] = 'https://github.com/' + repo_name + '/blob/' + commit + '/' + published_path
472
+ publication = {
473
+ 'ok': True,
474
+ 'branch': artifact_branch,
475
+ 'commit': commit,
476
+ 'repo': repo_name,
477
+ 'html_url': 'https://github.com/' + repo_name + '/tree/' + commit + '/' + artifact_dir_name,
478
+ 'manifest_url': 'https://github.com/' + repo_name + '/blob/' + commit + '/' + artifact_dir_name + '/proof-artifacts.json',
479
+ 'readme_url': 'https://github.com/' + repo_name + '/blob/' + commit + '/' + artifact_dir_name + '/README.md',
480
+ 'source_fingerprint': source_fingerprint,
481
+ 'artifacts': published,
482
+ }
483
+ state['proof_artifact_publication'] = publication
484
+ save_state(state)
485
+ return publication
486
+ finally:
487
+ shutil.rmtree(tmp, ignore_errors=True)
488
+
489
+
188
490
  def is_temp_proof_branch(branch):
189
491
  return str(branch or '').strip().startswith('riddle-proof/')
190
492
 
@@ -271,6 +573,10 @@ def build_ship_report(state, marked_ready=None):
271
573
  branch = state.get('target_branch') or state.get('branch') or ''
272
574
  if marked_ready is None:
273
575
  marked_ready = state.get('marked_ready')
576
+ before_artifact_url = first_public_artifact_url(state, 'before', 'image') or state.get('before_cdn', '')
577
+ prod_artifact_url = first_public_artifact_url(state, 'prod', 'image') or state.get('prod_cdn', '')
578
+ after_artifact_url = first_public_artifact_url(state, 'after', 'image') or state.get('after_cdn', '')
579
+ artifact_publication = state.get('proof_artifact_publication') or {}
274
580
  return {
275
581
  'pr_url': state.get('pr_url', ''),
276
582
  'pr_branch': branch,
@@ -282,9 +588,12 @@ def build_ship_report(state, marked_ready=None):
282
588
  'ci_status': state.get('ci_status', ''),
283
589
  'proof_comment_url': state.get('proof_comment_url', ''),
284
590
  'proof_assessment_comment_url': state.get('proof_assessment_comment_url', ''),
285
- 'before_artifact_url': state.get('before_cdn', ''),
286
- 'prod_artifact_url': state.get('prod_cdn', ''),
287
- 'after_artifact_url': state.get('after_cdn', ''),
591
+ 'before_artifact_url': before_artifact_url,
592
+ 'prod_artifact_url': prod_artifact_url,
593
+ 'after_artifact_url': after_artifact_url,
594
+ 'proof_artifacts_url': artifact_publication.get('html_url', '') if isinstance(artifact_publication, dict) else '',
595
+ 'proof_artifacts_manifest_url': artifact_publication.get('manifest_url', '') if isinstance(artifact_publication, dict) else '',
596
+ 'proof_artifact_publication': artifact_publication if isinstance(artifact_publication, dict) else {},
288
597
  }
289
598
 
290
599
 
@@ -515,12 +824,15 @@ def post_discord_ready_message(state, marked_ready):
515
824
  else:
516
825
  ci_line = 'CI was not confirmed green yet; review the PR checks before merging.'
517
826
  proof_bits = []
518
- if state.get('before_cdn'):
519
- proof_bits.append('before: ' + state['before_cdn'])
520
- if state.get('prod_cdn'):
521
- proof_bits.append('prod: ' + state['prod_cdn'])
522
- if state.get('after_cdn'):
523
- proof_bits.append('after: ' + state['after_cdn'])
827
+ before_url = first_public_artifact_url(state, 'before', 'image') or state.get('before_cdn')
828
+ prod_url = first_public_artifact_url(state, 'prod', 'image') or state.get('prod_cdn')
829
+ after_url = first_public_artifact_url(state, 'after', 'image') or state.get('after_cdn')
830
+ if before_url:
831
+ proof_bits.append('before: ' + before_url)
832
+ if prod_url:
833
+ proof_bits.append('prod: ' + prod_url)
834
+ if after_url:
835
+ proof_bits.append('after: ' + after_url)
524
836
  elif state_has_after_evidence(state):
525
837
  proof_bits.append('after: structured evidence bundle')
526
838
 
@@ -671,6 +983,8 @@ if s.get('finalized') and s.get('pr_url') and existing_after_dir and not os.path
671
983
  'proof_comment_url': report.get('proof_comment_url', ''),
672
984
  'before_artifact_url': report.get('before_artifact_url', ''),
673
985
  'after_artifact_url': report.get('after_artifact_url', ''),
986
+ 'proof_artifacts_url': report.get('proof_artifacts_url', ''),
987
+ 'proof_artifacts_manifest_url': report.get('proof_artifacts_manifest_url', ''),
674
988
  'finalized_retry': True,
675
989
  'proof_assessment_comment_posted': bool(s.get('proof_assessment_comment_posted')),
676
990
  'discord_notification': s.get('discord_notification'),
@@ -755,6 +1069,12 @@ pr_num = s.get('pr_number', '')
755
1069
  if not pr_num:
756
1070
  raise SystemExit('No PR created. Check gh auth.')
757
1071
 
1072
+ publication = publish_local_proof_artifacts_to_github(s, repo_dir, pr_num)
1073
+ if publication.get('ok') and not publication.get('skipped'):
1074
+ print('Proof artifacts published: ' + publication.get('html_url', ''))
1075
+ elif publication.get('skipped'):
1076
+ print('Proof artifact publication skipped: ' + publication.get('reason', 'unknown'))
1077
+
758
1078
  # Post proof comment on PR
759
1079
  body = '## Riddle Proof — Proof of Fix\n\n'
760
1080
  body += '**Goal:** ' + s.get('change_request', '') + '\n\n'
@@ -762,14 +1082,39 @@ if s.get('success_criteria'):
762
1082
  body += '**Success criteria:** ' + s['success_criteria'] + '\n\n'
763
1083
  body += '**Verification mode:** ' + s.get('verification_mode', 'proof') + '\n\n'
764
1084
  body += '**Merge recommendation:** ' + effective_merge_recommendation(s) + '\n\n'
765
- if before_cdn:
766
- body += '### Before\n![' + 'before' + '](' + before_cdn + ')\n\n'
767
- if prod_cdn:
768
- body += '### Prod\n![' + 'prod' + '](' + prod_cdn + ')\n\n'
769
- if after_cdn:
770
- body += '### After\n![' + 'after' + '](' + after_cdn + ')\n\n'
1085
+
1086
+ public_artifacts = public_proof_artifacts(s)
1087
+ if publication.get('ok') and not publication.get('skipped'):
1088
+ body += '**Proof artifacts:** '
1089
+ body += '[bundle](' + publication.get('html_url', '') + ')'
1090
+ if publication.get('manifest_url'):
1091
+ body += ' | [manifest](' + publication.get('manifest_url', '') + ')'
1092
+ body += '\n\n'
1093
+
1094
+ before_image = first_public_artifact_url(s, 'before', 'image')
1095
+ prod_image = first_public_artifact_url(s, 'prod', 'image')
1096
+ after_image = first_public_artifact_url(s, 'after', 'image')
1097
+ if before_image:
1098
+ body += '### Before\n![before](' + before_image + ')\n\n'
1099
+ if prod_image:
1100
+ body += '### Prod\n![prod](' + prod_image + ')\n\n'
1101
+ if after_image:
1102
+ body += '### After\n![after](' + after_image + ')\n\n'
771
1103
  else:
772
1104
  body += '### After evidence\nNo after screenshot was captured for this verification mode; structured evidence is summarized below.\n\n'
1105
+
1106
+ data_artifacts = [
1107
+ artifact for artifact in public_artifacts
1108
+ if artifact.get('kind') != 'image' and (artifact.get('html_url') or artifact.get('raw_url'))
1109
+ ]
1110
+ if data_artifacts:
1111
+ body += '### Structured artifacts\n'
1112
+ for artifact in data_artifacts[:12]:
1113
+ label = artifact.get('name') or artifact.get('filename') or artifact.get('kind') or 'artifact'
1114
+ url = artifact.get('html_url') or artifact.get('raw_url')
1115
+ body += '- [' + str(label) + '](' + str(url) + ')\n'
1116
+ body += '\n'
1117
+
773
1118
  bundle_text = evidence_bundle_text(s)
774
1119
  if bundle_text:
775
1120
  body += '### Evidence bundle\n```\n' + bundle_text + '\n```\n\n'
@@ -904,5 +1249,7 @@ print(json.dumps({
904
1249
  'before_artifact_url': report.get('before_artifact_url', ''),
905
1250
  'prod_artifact_url': report.get('prod_artifact_url', ''),
906
1251
  'after_artifact_url': report.get('after_artifact_url', ''),
1252
+ 'proof_artifacts_url': report.get('proof_artifacts_url', ''),
1253
+ 'proof_artifacts_manifest_url': report.get('proof_artifacts_manifest_url', ''),
907
1254
  'ship_report': report,
908
1255
  }))
@@ -12,7 +12,17 @@ steps:
12
12
  import json, os
13
13
  state_file = os.environ.get('RIDDLE_PROOF_STATE_FILE', '/tmp/riddle-proof-state.json')
14
14
  s = json.load(open(state_file))
15
- if not s.get('after_cdn'):
15
+ after = ((s.get('evidence_bundle') or {}).get('after') or {})
16
+ observation = after.get('observation') or {}
17
+ supporting = after.get('supporting_artifacts') or {}
18
+ has_structured_after = bool(
19
+ observation.get('valid') and (
20
+ supporting.get('has_structured_payload') or
21
+ supporting.get('proof_evidence_present') or
22
+ observation.get('telemetry_ready')
23
+ )
24
+ )
25
+ if not s.get('after_cdn') and not has_structured_after:
16
26
  raise SystemExit('No after evidence. Run verify first.')
17
27
  print('SHIP')
18
28
  print(' Proof goal: ' + s.get('change_request', ''))
@@ -0,0 +1,185 @@
1
+ import json
2
+ import os
3
+ import subprocess
4
+ import tempfile
5
+ from pathlib import Path
6
+
7
+
8
+ ROOT = Path(__file__).resolve().parents[2]
9
+ SHIP = ROOT / "runtime" / "lib" / "ship.py"
10
+
11
+
12
+ def run(args, cwd, env=None):
13
+ result = subprocess.run(args, cwd=cwd, env=env, capture_output=True, text=True, timeout=120)
14
+ if result.returncode != 0:
15
+ raise AssertionError(
16
+ f"{' '.join(args)} failed\nstdout:\n{result.stdout}\nstderr:\n{result.stderr}"
17
+ )
18
+ return result
19
+
20
+
21
+ def write_fake_gh(path):
22
+ path.write_text(
23
+ """#!/usr/bin/env python3
24
+ import json
25
+ import os
26
+ import sys
27
+
28
+ args = sys.argv[1:]
29
+ if args[:3] == ["repo", "view", "--json"]:
30
+ print("example/test-repo")
31
+ raise SystemExit(0)
32
+ if args[:2] == ["pr", "list"]:
33
+ print("")
34
+ raise SystemExit(0)
35
+ if args[:2] == ["pr", "create"]:
36
+ print("https://github.com/example/test-repo/pull/321")
37
+ raise SystemExit(0)
38
+ if args[:2] == ["pr", "comment"]:
39
+ body = ""
40
+ if "--body" in args:
41
+ body = args[args.index("--body") + 1]
42
+ with open(os.environ["FAKE_GH_COMMENT_BODY"], "w") as f:
43
+ f.write(body)
44
+ print("https://github.com/example/test-repo/pull/321#issuecomment-999")
45
+ raise SystemExit(0)
46
+ if args[:2] == ["pr", "checks"]:
47
+ print("[]")
48
+ raise SystemExit(0)
49
+ if args[:2] == ["pr", "ready"]:
50
+ raise SystemExit(0)
51
+ if args[:2] == ["pr", "edit"]:
52
+ raise SystemExit(0)
53
+ print("unknown gh command: " + " ".join(args), file=sys.stderr)
54
+ raise SystemExit(1)
55
+ """,
56
+ encoding="utf-8",
57
+ )
58
+ path.chmod(0o755)
59
+
60
+
61
+ def main():
62
+ with tempfile.TemporaryDirectory(prefix="riddle-proof-ship-artifacts-") as tmp:
63
+ root = Path(tmp)
64
+ origin = root / "origin.git"
65
+ repo = root / "repo"
66
+ artifacts = root / "artifacts"
67
+ bin_dir = root / "bin"
68
+ state_path = root / "state.json"
69
+ comment_body_path = root / "comment.md"
70
+ artifacts.mkdir()
71
+ bin_dir.mkdir()
72
+
73
+ run(["git", "init", "--bare", str(origin)], cwd=root)
74
+ run(["git", "init", str(repo)], cwd=root)
75
+ run(["git", "config", "user.name", "Test User"], cwd=repo)
76
+ run(["git", "config", "user.email", "test@example.com"], cwd=repo)
77
+ run(["git", "remote", "add", "origin", str(origin)], cwd=repo)
78
+ run(["git", "checkout", "-b", "agent/proof-artifact-test"], cwd=repo)
79
+ (repo / "README.md").write_text("initial\n", encoding="utf-8")
80
+ run(["git", "add", "README.md"], cwd=repo)
81
+ run(["git", "commit", "-m", "Initial"], cwd=repo)
82
+ (repo / "README.md").write_text("changed\n", encoding="utf-8")
83
+
84
+ # Tiny valid PNG header/body is enough for GitHub Markdown image embedding.
85
+ screenshot = artifacts / "after-proof.png"
86
+ screenshot.write_bytes(
87
+ bytes.fromhex(
88
+ "89504e470d0a1a0a0000000d4948445200000001000000010802000000907753de"
89
+ "0000000c49444154789c63606060000000040001f61738550000000049454e44ae426082"
90
+ )
91
+ )
92
+ proof_json = artifacts / "proof.json"
93
+ proof_json.write_text(
94
+ json.dumps(
95
+ {
96
+ "version": "riddle-proof.test.v1",
97
+ "assertions": [{"name": "proof image published", "passed": True}],
98
+ },
99
+ indent=2,
100
+ ),
101
+ encoding="utf-8",
102
+ )
103
+
104
+ write_fake_gh(bin_dir / "gh")
105
+ state = {
106
+ "repo_dir": str(repo),
107
+ "branch": "agent/proof-artifact-test",
108
+ "target_branch": "agent/proof-artifact-test",
109
+ "run_id": "rp_ship_artifact_test",
110
+ "change_request": "Prove PR artifact publication.",
111
+ "commit_message": "Test proof artifact publication",
112
+ "success_criteria": "The PR proof comment embeds a GitHub-hosted image.",
113
+ "verification_mode": "proof",
114
+ "requested_reference": "none",
115
+ "reference": "none",
116
+ "verify_status": "evidence_captured",
117
+ "after_cdn": screenshot.as_uri(),
118
+ "assertion_status": "passed",
119
+ "proof_summary": "All assertions passed.",
120
+ "proof_assessment_source": "supervising_agent",
121
+ "proof_assessment": {
122
+ "source": "supervising_agent",
123
+ "decision": "ready_to_ship",
124
+ "summary": "Evidence is strong enough to ship.",
125
+ },
126
+ "evidence_bundle": {
127
+ "verification_mode": "proof",
128
+ "after": {
129
+ "observation": {"valid": True, "reason": "ok", "telemetry_ready": True},
130
+ "supporting_artifacts": {
131
+ "has_structured_payload": True,
132
+ "proof_evidence_present": True,
133
+ "image_outputs": [{"name": "after-proof.png", "url": screenshot.as_uri()}],
134
+ "data_outputs": [{"name": "proof.json", "url": proof_json.as_uri()}],
135
+ },
136
+ },
137
+ },
138
+ "verify_results": {
139
+ "after": {
140
+ "raw": {
141
+ "outputs": [
142
+ {"name": "after-proof.png", "url": screenshot.as_uri(), "path": str(screenshot)},
143
+ {"name": "proof.json", "url": proof_json.as_uri(), "path": str(proof_json)},
144
+ ],
145
+ },
146
+ },
147
+ },
148
+ }
149
+ state_path.write_text(json.dumps(state, indent=2), encoding="utf-8")
150
+ env = {
151
+ **os.environ,
152
+ "PATH": str(bin_dir) + os.pathsep + os.environ.get("PATH", ""),
153
+ "RIDDLE_PROOF_STATE_FILE": str(state_path),
154
+ "FAKE_GH_COMMENT_BODY": str(comment_body_path),
155
+ "DISCORD_BOT_TOKEN": "",
156
+ "OPENCLAW_HOME": str(root / "openclaw-home"),
157
+ }
158
+
159
+ run(["python3", str(SHIP)], cwd=repo, env=env)
160
+
161
+ updated = json.loads(state_path.read_text(encoding="utf-8"))
162
+ publication = updated.get("proof_artifact_publication") or {}
163
+ assert publication.get("ok") is True, "proof artifact publication should be recorded"
164
+ assert publication.get("artifacts"), "published artifact list should be recorded"
165
+ assert updated.get("ship_report", {}).get("after_artifact_url", "").startswith(
166
+ "https://raw.githubusercontent.com/example/test-repo/"
167
+ ), "ship report should expose a public after artifact URL"
168
+
169
+ comment = comment_body_path.read_text(encoding="utf-8")
170
+ assert "file://" not in comment, "PR proof comment must not expose local file URLs"
171
+ assert "![after](https://raw.githubusercontent.com/example/test-repo/" in comment, (
172
+ "PR proof comment should embed the GitHub-hosted after screenshot"
173
+ )
174
+ assert "[proof.json](https://github.com/example/test-repo/blob/" in comment, (
175
+ "PR proof comment should link the structured proof JSON"
176
+ )
177
+ assert "Proof artifacts:" in comment, "PR proof comment should link the artifact bundle"
178
+
179
+ artifact_branch = publication.get("branch")
180
+ refs = run(["git", f"--git-dir={origin}", "show-ref", f"refs/heads/{artifact_branch}"], cwd=root)
181
+ assert artifact_branch in refs.stdout, "artifact branch should be pushed to origin"
182
+
183
+
184
+ if __name__ == "__main__":
185
+ main()