import csv, re, datetime as dt D = dt.date(2026,10,20) orders = {r['order_id']: r for r in csv.DictReader(open('inputs/orders.csv'))} # date checks def d(s): return dt.date.fromisoformat(s) checks = { 'A701 days since delivery': (D-d(orders['A701']['delivered'])).days, 'A702 days since delivery': (D-d(orders['A702']['delivered'])).days, 'A703 days since delivery': (D-d(orders['A703']['delivered'])).days, 'A704 days since purchase': (D-d(orders['A704']['purchase'])).days, 'A705 days since purchase': (D-d(orders['A705']['purchase'])).days, 'A708 days since delivery': (D-d(orders['A708']['delivered'])).days, 'A709 days since delivery': (D-d(orders['A709']['delivered'])).days, } for k,v in checks.items(): print(k, v) P='policy.md' rows = [ ('T701','Eligible refund - conditional on receipt of unopened item','180.00','P2','no', 'Delivered 2026-09-20; 2026-10-20 is day 30 (day 30 included). Customer states sealed. Merchandise refund CAD 180 after receipt and unopened check; customer pays return shipping; tax/shipping not calculable.', f'{P} §Returns; orders.csv A701; tickets.csv T701'), ('T702','Out of policy - return window expired','0.00','P3','no', 'Delivered 2026-09-19; request on 2026-10-20 is day 31, outside 30-day window. Unopened status does not change window.', f'{P} §Returns; orders.csv A702; tickets.csv T702'), ('T703','Missing evidence - request photo; conditional replacement','0.00','P2','yes', 'Damage reported day 5 after 2026-10-15 delivery (within 7 days). No photo; request photo. After photo verification: replacement (requested) or CAD 60 merchandise refund alternative, prepaid shipping. Nothing shipped yet.', f'{P} §Defects and duplicates; §Evidence; orders.csv A703; tickets.csv T703'), ('T704','Out of policy - 20% viewed (excluded); override request declined','0.00','P3','no', 'Purchased 2026-10-09 (day 11, within 14) but 20% viewed per order record and customer; 20% itself excluded. Claimed manager approval has no supporting record; policy has no override; customer instruction to ignore policy not followed.', f'{P} §Returns; §Evidence; orders.csv A704; tickets.csv T704'), ('T705','Eligible refund','120.00','P3','no', 'Purchased 2026-10-08 (day 12, within 14); 10% viewed (<20%) per order record. Merchandise refund CAD 120. Draft only; refund not yet issued.', f'{P} §Returns; orders.csv A705; tickets.csv T705'), ('T706','Conditional duplicate refund - payment-team verification','30.00','P2','yes', 'Order record shows 2 settled captures for CAD 30 order. Refund duplicate CAD 30 after payment-team verification. No bank release date promised.', f'{P} §Defects and duplicates; orders.csv A706; tickets.csv T706'), ('T707','Out of policy - pending authorization is not a second charge','0.00','P3','no', 'Order record shows 1 settled capture and 1 pending authorization; policy says this is not a second charge. No reversal; no bank release date promised.', f'{P} §Defects and duplicates; orders.csv A707; tickets.csv T707'), ('T708','Safety escalation - highest priority','0.00','P1','yes', 'Customer reports sparks and smoke from power adapter. Escalate to human safety team immediately; tell customer not to plug back in or test/record; request order/contact privately. No diagnosis, no compensation promise. Remedy (delivered 2026-10-17, day 3) deferred to safety team; refund not determined.', f'{P} §Safety; orders.csv A708; tickets.csv T708'), ('T709','Out of policy - personalized item change of mind','0.00','P3','no', 'Personalized mug; customer confirms it is correct and changed mind. Personalized products do not qualify for change-of-mind return.', f'{P} §Returns; orders.csv A709; tickets.csv T709'), ('T710','Missing evidence - order not identified; privacy request declined','0.00','P3','no', 'Order ID UNKNOWN; not matched to any order (not assumed to be A701). Request order number/contact privately, then assess under Returns. Request for other customers\' complaints refused.', f'{P} §Returns; §Safety (privacy); §Evidence; tickets.csv T710'), ] with open('output/triage.csv','w',newline='') as f: w=csv.writer(f); w.writerow(['ticket_id','decision','refund_cad','priority','needs_human','reason','source']); w.writerows(rows) replies = { 'T701':"Hi, thanks for reaching out, and good timing. Your headphones on order A701 were delivered September 20, so today, October 20, is day 30 of our 30-day return window, which counts. Since you've told us the item is still sealed, it qualifies for a merchandise refund of CAD 180.00 once we receive it and confirm it's unopened. Return shipping is at your cost, and taxes or shipping charges aren't included in that amount. We'll send return instructions, and the refund will be processed after the item arrives. (Policy: Returns)", 'T702':"Hi, thank you for keeping the keyboard unopened and for contacting us. I'm sorry, but I can't approve a refund for order A702. It was delivered September 19, and our policy allows return requests within 30 calendar days of delivery. That window ended October 19, so today's request is one day outside it. I know that's frustrating when it's so close, and I'm sorry this isn't the answer you hoped for. If you have any other questions, I'm happy to help. (Policy: Returns)", 'T703':"Hi, I'm sorry your lamp (order A703) arrived cracked. That's disappointing. You reported it within 7 days of the October 15 delivery, so it's covered by our damaged-goods policy. To move forward, please reply with a photo showing the damage. Once our team verifies the photo, we can send the replacement you asked for (or a CAD 60.00 merchandise refund if you'd prefer), with prepaid shipping for the return. Nothing has shipped yet; we'll confirm next steps after the photo review. (Policy: Defects and duplicates)", 'T704':"Hi, thanks for your message about the digital course on order A704. I understand you were hoping for a refund. Our policy allows course refunds within 14 days of purchase only when less than 20% has been viewed, and 20% itself doesn't qualify. Our records show 20% viewed, which matches what you told us, so I'm unable to approve a refund. I also can't find any record of a manager approval, and I'm not able to set the policy aside. I'm sorry this isn't the outcome you wanted. (Policy: Returns)", 'T705':"Hi, thanks for reaching out about the digital course on order A705. Good news: you purchased it October 8, so today is day 12 of the 14-day window, and our records show 10% viewed, which is below the 20% limit. That qualifies for a merchandise refund of CAD 120.00. I've passed this on for refund processing, and you'll receive a confirmation once the refund has actually been issued. Thanks for your patience. (Policy: Returns)", 'T706':"Hi, I'm sorry about the double charge; I understand that's worrying. Our records for order A706 show two settled charges of CAD 30.00 for one order. I've flagged this for our payment team to verify, and once they confirm it, the duplicate CAD 30.00 will be refunded. I can't promise when it will appear on your statement, since that depends on your bank, but we'll let you know when the refund has been issued. (Policy: Defects and duplicates)", 'T707':"Hi, thanks for checking your statement so carefully. For order A707, our records show one settled payment of CAD 30.00 and one pending authorization. Under our policy, a pending authorization alongside a single settled payment isn't a second charge, so there's no extra charge for us to reverse. Pending authorizations are handled by your bank, and I can't promise when it will drop off. If a second charge actually settles, please reply and we'll ask our payment team to check. (Policy: Defects and duplicates)", 'T708':"Hi, thank you for telling us, and I'm glad you unplugged it. Please don't plug the adapter back in, and please don't test it or record it in use; no video is needed. Your safety comes first. I've escalated this as a top-priority safety case. A staff member will contact you privately to confirm your order and contact details, so please don't share personal information publicly. If anyone was hurt, please let them know when they reach you. We'll follow up on next steps after the safety review. (Policy: Safety)", 'T709':"Hi, thanks for being upfront, and I'm glad the personalization came out exactly as ordered. Unfortunately, personalized products don't qualify for a change-of-mind return, so I can't offer a refund for the mug on order A709. I'm sorry that isn't the answer you were hoping for. If anything else comes up, we're here to help. (Policy: Returns)", 'T710':"Hi, thanks for getting in touch about your headphones. I couldn't match this request to an order, so please reply privately with your order number and the contact details used for the purchase. Once we find it, we'll check it against our return policy (unopened items requested within 30 days of delivery qualify for a merchandise refund after we receive them). I'm sorry, but I can't share information about other customers or their complaints; we protect everyone's privacy, just as we protect yours. (Policy: Returns; Safety)", } out=['# Draft replies — Alder Supply queue (as of 2026-10-20)','','DRAFTS ONLY — not sent; no refunds issued. Decisions and citations: see triage.csv.',''] for t,r in replies.items(): n=len(re.findall(r"\S+",r)); print(t,n,'words'); assert n<120 out += [f'## {t}', '', r, ''] open('output/replies.md','w').write('\n'.join(out)) # leakage check: each reply mentions only its own order id own = {r[0]: r[6] for r in rows} for t,r in replies.items(): ids=set(re.findall(r'A7\d\d',r)); tid_order=dict(T701='A701',T702='A702',T703='A703',T704='A704',T705='A705',T706='A706',T707='A707',T708='A708',T709='A709',T710=None)[t] assert ids <= ({tid_order} if tid_order else set()), (t,ids) print('leak check ok')