File size: 2,315 Bytes
990895d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
"""Format context-free coach debug paste bundles for external AI review.

Bundles include formulas, evidence, prompts, raw output, and checklist.
"""

from __future__ import annotations

import json
from typing import Any


def render_paste_bundle(trace: dict[str, Any], *, app_name: str, shrink_k: float, match_alpha: float, min_n: int) -> str:
    """Render the exact markdown paste bundle from a stored trace."""

    evidence = trace.get("evidence") or {}
    evidence_block = evidence.get("evidence_block") or json.dumps(evidence, indent=2)
    picks = json.dumps(trace.get("server_picks") or [], indent=2, ensure_ascii=False)
    current = json.dumps(trace.get("current") or {}, indent=2, ensure_ascii=False)
    history = json.dumps(trace.get("history_truncated") or [], indent=2, ensure_ascii=False)
    parsed = json.dumps(trace.get("parsed"), indent=2, ensure_ascii=False)
    return f"""# Coach Trace Paste Bundle (context-free)
app: {app_name} | version: {trace.get('app_version')} | trace_id: {trace.get('trace_id')} | ts: {trace.get('ts')}

## How to help
You have NO prior context about the user. Use ONLY this bundle.
Do not ask for biography. Critique prompts, math, backup rules, and free-model fitness.
Output: (1) findings (2) concrete patch list for backend prompts/rules/math weights.

## Math definitions (server authoritative)
- pending excluded from denominators
- p_worked(r) = N(worked,r) / N(r)
- p_helped(r) = N(worked|partial,r) / N(r)
- rank(r) = p_helped * n/(n+k) with k={shrink_k}
- pick(r) = rank * (1 + alpha * match) with alpha={match_alpha}
- min_n = {min_n}
- DATA_THIN if n_scored < 10

## Server evidence
{evidence_block}

## Server picks
{picks}

## Current situation
{current}

## Recent history (truncated)
{history}

## System prompt
{trace.get('system_prompt') or ''}

## User prompt
{trace.get('user_prompt') or ''}

## Model raw response
{trace.get('raw_model_response') or ''}

## Parse / source / flags
source: {trace.get('source')}
backup_rule_id: {trace.get('backup_rule_id')}
flags: {trace.get('flags')}
parsed: {parsed}

## Final text shown to user
{trace.get('final_text') or ''}

## Reviewer checklist
1. Invented numbers?
2. Ignored SERVER_PICKS?
3. Format broken (free model)?
4. Backup better?
5. Evidence too long/short?
6. Shrinkage k / alpha tweak?
"""