-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheconomic_engine.py
More file actions
658 lines (563 loc) · 24.1 KB
/
economic_engine.py
File metadata and controls
658 lines (563 loc) · 24.1 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
#!/usr/bin/env python3
"""
Economic Reasoning Engine for Aurora
Every non-trivial action gets an explicit expected-value calculation:
- Estimated revenue potential
- Cost (API tokens, time, opportunity cost)
- Probability of success
- Expected value = (revenue * probability) - cost
Usage:
python3 economic_engine.py evaluate "Send writing application to Draft.dev"
python3 economic_engine.py log "Sent application" --cost 0.50 --potential 300 --probability 0.05
python3 economic_engine.py report
python3 economic_engine.py best # Show highest EV pending actions
"""
import json
import sqlite3
import sys
from datetime import datetime, timezone
from pathlib import Path
BASE_DIR = Path(__file__).parent
DB_PATH = BASE_DIR / "economic.db"
# Estimated costs per action type (in USD)
ACTION_COSTS = {
"send_email": 0.10, # API tokens + processing
"send_telegram": 0.05,
"write_article": 2.00, # ~1 session of focused work
"write_application": 0.50,
"build_feature": 3.00, # ~1-2 sessions
"research": 1.00,
"publish_content": 0.30,
"submit_pr": 0.20,
"api_session": 5.00, # Full Claude Opus session cost estimate
"idle_cycle": 0.10, # Triage-only cycle
}
def init_db():
"""Initialize the economic decisions database."""
conn = sqlite3.connect(DB_PATH)
conn.execute("""
CREATE TABLE IF NOT EXISTS decisions (
id INTEGER PRIMARY KEY AUTOINCREMENT,
timestamp TEXT NOT NULL,
action TEXT NOT NULL,
category TEXT DEFAULT 'general',
cost_usd REAL DEFAULT 0,
potential_revenue_usd REAL DEFAULT 0,
probability REAL DEFAULT 0.5,
expected_value REAL DEFAULT 0,
outcome TEXT DEFAULT 'pending',
actual_revenue REAL DEFAULT 0,
notes TEXT DEFAULT '',
session INTEGER DEFAULT 0,
time_to_cash_days INTEGER DEFAULT NULL
)
""")
# Add columns if missing (for existing DBs)
for col_stmt in [
"ALTER TABLE decisions ADD COLUMN time_to_cash_days INTEGER DEFAULT NULL",
"ALTER TABLE decisions ADD COLUMN bear_tested INTEGER DEFAULT 0",
"ALTER TABLE decisions ADD COLUMN bear_arguments TEXT DEFAULT ''",
]:
try:
conn.execute(col_stmt)
except sqlite3.OperationalError:
pass # Column already exists
conn.execute("""
CREATE TABLE IF NOT EXISTS action_history (
id INTEGER PRIMARY KEY AUTOINCREMENT,
timestamp TEXT NOT NULL,
action_type TEXT NOT NULL,
cost_usd REAL DEFAULT 0,
session INTEGER DEFAULT 0
)
""")
conn.execute("""
CREATE TABLE IF NOT EXISTS task_outcomes (
id INTEGER PRIMARY KEY AUTOINCREMENT,
timestamp TEXT NOT NULL,
session INTEGER NOT NULL,
task TEXT NOT NULL,
category TEXT DEFAULT 'general',
turns_spent INTEGER DEFAULT 1,
tangible_output INTEGER DEFAULT 0,
output_description TEXT DEFAULT '',
notes TEXT DEFAULT ''
)
""")
conn.commit()
return conn
# Time decay — discount EV for slow-to-cash opportunities
TIME_DECAY_BUCKETS = [
(14, 1.0), # ≤14 days: full value
(30, 0.85), # 15-30 days
(60, 0.65), # 31-60 days
(90, 0.45), # 61-90 days
]
TIME_DECAY_FLOOR = 0.30 # >90 days
TIME_DECAY_DEFAULT_DAYS = 30 # Conservative default when unspecified
def _time_decay_factor(days):
"""Return a multiplier (0.30-1.0) based on estimated time to cash."""
if days is None:
days = TIME_DECAY_DEFAULT_DAYS
days = max(1, int(days)) # Guard negative/zero/fractional inputs
for threshold, factor in TIME_DECAY_BUCKETS:
if days <= threshold:
return factor
return TIME_DECAY_FLOOR
def _validate_probability(probability, context=""):
"""Validate and normalize probability to 0-1 scale.
Auto-converts 0-100 scale inputs. Rejects out-of-bounds values.
Clamps edge cases to [0.0, 1.0] after conversion."""
if probability < 0:
raise ValueError(f"Probability cannot be negative: {probability} (context: {context})")
if probability > 1.0:
if probability <= 100:
corrected = probability / 100.0
print(f"WARNING: Probability {probability} appears to be a percentage. "
f"Auto-converting to {corrected} (context: {context})")
probability = corrected
else:
raise ValueError(f"Probability out of bounds: {probability} (context: {context})")
return max(0.0, min(1.0, probability))
def evaluate_action(action, cost=None, potential=None, probability=None,
category="general", session=0, time_to_cash_days=None):
"""
Evaluate an action's expected value with time decay.
Returns dict with cost, potential, probability, expected_value, and recommendation.
Time decay discounts EV for slow-to-cash opportunities (default: 30 days).
"""
# Use defaults if not provided
if cost is None:
# Try to match action type
for action_type, default_cost in ACTION_COSTS.items():
if action_type in action.lower().replace(" ", "_"):
cost = default_cost
break
else:
cost = 1.00 # Default session cost
if potential is None:
potential = 0.0
if probability is None:
probability = 0.1 # Conservative default
probability = _validate_probability(probability, action)
decay = _time_decay_factor(time_to_cash_days)
raw_ev = (potential * probability) - cost
adjusted_ev = (potential * probability * decay) - cost
roi = (adjusted_ev / cost * 100) if cost > 0 else float('inf')
days_used = time_to_cash_days if time_to_cash_days is not None else TIME_DECAY_DEFAULT_DAYS
result = {
"action": action,
"category": category,
"cost_usd": round(cost, 2),
"potential_revenue_usd": round(potential, 2),
"probability": round(probability, 3),
"time_to_cash_days": days_used,
"time_decay": decay,
"raw_ev": round(raw_ev, 2),
"expected_value": round(adjusted_ev, 2),
"roi_percent": round(roi, 1),
"recommendation": "PROCEED" if adjusted_ev > 0 else "SKIP" if adjusted_ev < -2 else "MARGINAL"
}
return result
def log_decision(action, cost=0, potential=0, probability=0.5, category="general",
outcome="pending", notes="", session=0, time_to_cash_days=None):
"""Log an economic decision to the database with time-decay-adjusted EV."""
probability = _validate_probability(probability, action)
decay = _time_decay_factor(time_to_cash_days)
ev = (potential * probability * decay) - cost
days_used = time_to_cash_days if time_to_cash_days is not None else TIME_DECAY_DEFAULT_DAYS
conn = init_db()
conn.execute("""
INSERT INTO decisions (timestamp, action, category, cost_usd, potential_revenue_usd,
probability, expected_value, outcome, notes, session, time_to_cash_days)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
""", (
datetime.now(timezone.utc).isoformat(),
action, category, cost, potential, probability, ev, outcome, notes, session, days_used
))
conn.commit()
conn.close()
# Bear case queue: significant commitments get adversarial review during idle cycles
if potential >= BEAR_CASE_THRESHOLD and outcome == "pending":
print(f"QUEUED FOR BEAR CASE: ${potential:.0f} potential — adversarial review will run automatically during next idle cycle.")
if decay < 1.0:
print(f"Time decay applied: {decay}x ({days_used}d to cash)")
return ev
def update_outcome(decision_id, outcome, actual_revenue=0):
"""Update the outcome of a previous decision."""
conn = init_db()
conn.execute("""
UPDATE decisions SET outcome = ?, actual_revenue = ?
WHERE id = ?
""", (outcome, actual_revenue, decision_id))
conn.commit()
conn.close()
def get_report():
"""Generate an economic performance report."""
conn = init_db()
# Overall stats
rows = conn.execute("""
SELECT COUNT(*), SUM(cost_usd), SUM(actual_revenue),
SUM(expected_value), AVG(probability)
FROM decisions
""").fetchone()
total_decisions = rows[0] or 0
total_cost = rows[1] or 0
total_revenue = rows[2] or 0
total_ev = rows[3] or 0
avg_probability = rows[4] or 0
# By category
categories = conn.execute("""
SELECT category, COUNT(*), SUM(cost_usd), SUM(actual_revenue),
SUM(expected_value), AVG(probability)
FROM decisions
GROUP BY category
ORDER BY SUM(expected_value) DESC
""").fetchall()
# Pending high-EV actions
pending = conn.execute("""
SELECT id, action, expected_value, potential_revenue_usd, probability
FROM decisions
WHERE outcome = 'pending'
ORDER BY expected_value DESC
LIMIT 10
""").fetchall()
# Accuracy: compare predicted probability with actual outcomes
completed = conn.execute("""
SELECT probability, outcome, actual_revenue, potential_revenue_usd
FROM decisions
WHERE outcome != 'pending'
""").fetchall()
conn.close()
report = f"""# Economic Reasoning Report
## Overview
- Total decisions tracked: {total_decisions}
- Total cost incurred: ${total_cost:.2f}
- Total revenue earned: ${total_revenue:.2f}
- Net P&L: ${total_revenue - total_cost:.2f}
- Total expected value: ${total_ev:.2f}
- Average predicted probability: {avg_probability:.1%}
## By Category
"""
for cat in categories:
report += f"- **{cat[0]}**: {cat[1]} decisions, ${cat[2] or 0:.2f} cost, ${cat[3] or 0:.2f} revenue, EV ${cat[4] or 0:.2f}\n"
if pending:
report += "\n## Top Pending Actions (by EV)\n"
for p in pending:
report += f"- [{p[0]}] {p[1]} — EV: ${p[2]:.2f} (potential ${p[3]:.2f} @ {p[4]:.0%})\n"
if completed:
successes = sum(1 for c in completed if c[1] == 'success')
failures = sum(1 for c in completed if c[1] == 'failure')
total_completed = successes + failures
if total_completed > 0:
actual_rate = successes / total_completed
predicted_rate = sum(c[0] for c in completed) / len(completed)
report += f"\n## Calibration\n"
report += f"- Predicted success rate: {predicted_rate:.1%}\n"
report += f"- Actual success rate: {actual_rate:.1%}\n"
report += f"- Calibration gap: {abs(predicted_rate - actual_rate):.1%}\n"
return report
BEAR_CASE_THRESHOLD = 50 # Only bear-test decisions with potential >= $50
def get_pending_bear_cases():
"""Return pending decisions that haven't been adversarially reviewed."""
conn = init_db()
rows = conn.execute("""
SELECT id, action, category, cost_usd, potential_revenue_usd,
probability, expected_value, notes, time_to_cash_days
FROM decisions
WHERE outcome = 'pending'
AND bear_tested = 0
AND potential_revenue_usd >= ?
ORDER BY expected_value DESC
LIMIT 3
""", (BEAR_CASE_THRESHOLD,)).fetchall()
conn.close()
return [{
"id": r[0], "action": r[1], "category": r[2], "cost": r[3],
"potential": r[4], "probability": r[5], "ev": r[6],
"notes": r[7], "days": r[8]
} for r in rows]
def save_bear_result(decision_id, arguments, verdict):
"""Save bear case result for a decision."""
conn = init_db()
# bear_tested: 1=reviewed/proceed, 2=killed
tested_val = 2 if "KILL" in verdict.upper() else 1
conn.execute("""
UPDATE decisions SET bear_tested = ?, bear_arguments = ?
WHERE id = ?
""", (tested_val, arguments, decision_id))
conn.commit()
conn.close()
def get_recent_bear_cases(hours=72):
"""Return recently completed bear cases for context injection."""
conn = init_db()
rows = conn.execute("""
SELECT id, action, bear_tested, bear_arguments, potential_revenue_usd
FROM decisions
WHERE bear_tested > 0
AND bear_arguments != ''
AND datetime(timestamp) >= datetime('now', ?)
ORDER BY id DESC
LIMIT 5
""", (f'-{hours} hours',)).fetchall()
conn.close()
return [{
"id": r[0], "action": r[1],
"verdict": "KILLED" if r[2] == 2 else "PROCEED",
"arguments": r[3], "potential": r[4]
} for r in rows]
def get_stale_decisions(max_age_hours=48):
"""Return pending decisions older than max_age_hours. Used by the watchdog."""
conn = init_db()
rows = conn.execute("""
SELECT id, action, timestamp, expected_value, potential_revenue_usd, probability
FROM decisions
WHERE outcome = 'pending'
ORDER BY timestamp ASC
""").fetchall()
conn.close()
stale = []
now = datetime.now(timezone.utc)
for row in rows:
try:
ts = datetime.fromisoformat(row[2])
if ts.tzinfo is None:
ts = ts.replace(tzinfo=timezone.utc)
age_hours = (now - ts).total_seconds() / 3600
if age_hours >= max_age_hours:
stale.append({
"id": row[0],
"action": row[1],
"age_days": round(age_hours / 24, 1),
"ev": row[3],
"potential": row[4],
"probability": row[5],
})
except (ValueError, TypeError):
continue
return stale
def get_best_actions():
"""Show the highest expected-value pending actions with focus diagnostic."""
conn = init_db()
pending = conn.execute("""
SELECT id, action, expected_value, potential_revenue_usd, probability, cost_usd,
category, time_to_cash_days
FROM decisions
WHERE outcome = 'pending'
ORDER BY expected_value DESC
LIMIT 5
""").fetchall()
# Focus diagnostic: count all pending opportunities and categories
focus_data = conn.execute("""
SELECT COUNT(*), COUNT(DISTINCT category)
FROM decisions
WHERE outcome = 'pending'
""").fetchone()
conn.close()
if not pending:
return "No pending actions tracked."
result = "Top actions by expected value (time-decay adjusted):\n"
for p in pending:
roi = (p[2] / p[5] * 100) if p[5] > 0 else float('inf')
days = p[7] if p[7] is not None else "?"
result += f" [{p[0]}] {p[1]}\n"
result += f" EV: ${p[2]:.2f} | Potential: ${p[3]:.2f} @ {p[4]:.0%} | Cost: ${p[5]:.2f} | {days}d to cash\n"
# Focus diagnostic — only trigger when genuinely fragmented
total_opps = focus_data[0] or 0
total_cats = focus_data[1] or 0
if total_opps > 3 and total_cats > 2:
result += (f"\nFocus check: {total_opps} active opportunities across "
f"{total_cats} categories. Consider consolidating.")
return result
def log_task_outcome(session, task, category="general", turns_spent=1,
tangible_output=False, output_description="", notes=""):
"""Log a task outcome with turns spent and whether it produced tangible output."""
conn = init_db()
conn.execute("""
INSERT INTO task_outcomes (timestamp, session, task, category, turns_spent,
tangible_output, output_description, notes)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
""", (
datetime.now(timezone.utc).isoformat(),
session, task, category, turns_spent,
1 if tangible_output else 0, output_description, notes
))
conn.commit()
conn.close()
def get_task_journal():
"""Analyze task outcomes — which categories produce results vs burn sessions."""
conn = init_db()
# Overall stats
total = conn.execute("SELECT COUNT(*), SUM(turns_spent) FROM task_outcomes").fetchone()
productive = conn.execute(
"SELECT COUNT(*), SUM(turns_spent) FROM task_outcomes WHERE tangible_output = 1"
).fetchone()
# By category
categories = conn.execute("""
SELECT category, COUNT(*), SUM(turns_spent),
SUM(tangible_output), AVG(tangible_output) * 100
FROM task_outcomes
GROUP BY category
ORDER BY AVG(tangible_output) DESC
""").fetchall()
# Recent tasks
recent = conn.execute("""
SELECT session, task, category, turns_spent, tangible_output, output_description
FROM task_outcomes
ORDER BY id DESC
LIMIT 10
""").fetchall()
conn.close()
total_tasks = total[0] or 0
total_turns = total[1] or 0
prod_tasks = productive[0] or 0
prod_turns = productive[1] or 0
report = f"""# Task Outcome Journal
## Overview
- Total tasks tracked: {total_tasks}
- Total turns spent: {total_turns}
- Productive tasks: {prod_tasks} ({prod_tasks/max(total_tasks,1)*100:.0f}%)
- Productive turns: {prod_turns} ({prod_turns/max(total_turns,1)*100:.0f}%)
- Wasted turns: {total_turns - prod_turns}
## By Category (sorted by productivity)
"""
for cat in categories:
report += f"- **{cat[0]}**: {cat[1]} tasks, {cat[2]} turns, {cat[3]}/{cat[1]} productive ({cat[4]:.0f}%)\n"
if recent:
report += "\n## Recent Tasks\n"
for r in recent:
marker = "+" if r[4] else "-"
report += f" [{marker}] S{r[0]} | {r[2]} | {r[3]}t | {r[1]}"
if r[5]:
report += f" → {r[5]}"
report += "\n"
return report
def seed_current_actions():
"""Seed the database with Aurora's current pending actions."""
actions = [
("Writing application: CircleCI", "writing", 0.50, 475, 0.05, "pending", "Applied S107"),
("Writing application: ContentLab.io", "writing", 0.50, 500, 0.05, "pending", "Applied S107"),
("Writing application: Honeybadger", "writing", 0.50, 500, 0.08, "pending", "Applied S108"),
("Writing application: StackAbuse", "writing", 0.50, 200, 0.08, "pending", "Applied S108"),
("Writing application: AppSignal", "writing", 0.50, 300, 0.07, "pending", "Applied S108"),
("Writing application: Smashing Magazine", "writing", 0.50, 225, 0.06, "pending", "Applied S108"),
("Writing application: MetalBear", "writing", 0.50, 225, 0.07, "pending", "Applied S108"),
("Writing application: Draft.dev", "writing", 0.50, 300, 0.08, "pending", "Applied S109"),
("Writing application: CodingSight", "writing", 0.50, 175, 0.08, "pending", "Applied S109"),
("x402 API server: agent-insights endpoint", "x402", 3.00, 100, 0.15, "pending", "Built S109, needs USDC"),
("x402 API server: code-review endpoint", "x402", 2.00, 200, 0.10, "pending", "Built S109, needs USDC"),
("Awesome list PR: alive framework (9 PRs)", "oss", 1.80, 50, 0.30, "pending", "Submitted S99-106"),
("Writing application: Airbyte", "writing", 0.50, 400, 0.0, "failure", "Email bounced"),
]
conn = init_db()
existing = conn.execute("SELECT COUNT(*) FROM decisions").fetchone()[0]
if existing > 0:
print(f"Database already has {existing} entries. Skipping seed.")
conn.close()
return
for action, cat, cost, potential, prob, outcome, notes in actions:
ev = (potential * prob) - cost
conn.execute("""
INSERT INTO decisions (timestamp, action, category, cost_usd, potential_revenue_usd,
probability, expected_value, outcome, notes, session)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, 110)
""", (datetime.now(timezone.utc).isoformat(), action, cat, cost, potential, prob, ev, outcome, notes))
conn.commit()
conn.close()
print(f"Seeded {len(actions)} decisions.")
if __name__ == "__main__":
if len(sys.argv) < 2:
print("Usage:")
print(" python3 economic_engine.py evaluate 'action description'")
print(" python3 economic_engine.py log 'action' --cost 0.50 --potential 300 --probability 0.05 --days 14")
print(" python3 economic_engine.py report")
print(" python3 economic_engine.py best")
print(" python3 economic_engine.py seed")
print(" python3 economic_engine.py task SESSION 'task' --category X --turns N --tangible --output 'desc'")
print(" python3 economic_engine.py journal")
sys.exit(0)
cmd = sys.argv[1]
if cmd == "evaluate":
if len(sys.argv) < 3:
print("Usage: python3 economic_engine.py evaluate 'action description' [--days N]")
sys.exit(1)
days = None
if "--days" in sys.argv:
idx = sys.argv.index("--days")
if idx + 1 < len(sys.argv):
days = int(sys.argv[idx + 1])
result = evaluate_action(sys.argv[2], time_to_cash_days=days)
print(json.dumps(result, indent=2))
elif cmd == "log":
if len(sys.argv) < 3:
print("Usage: python3 economic_engine.py log 'action' [--cost X] [--potential X] [--probability X]")
sys.exit(1)
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("cmd")
parser.add_argument("action")
parser.add_argument("--cost", type=float, default=0.5)
parser.add_argument("--potential", type=float, default=0)
parser.add_argument("--probability", type=float, default=0.5)
parser.add_argument("--category", default="general")
parser.add_argument("--notes", default="")
parser.add_argument("--session", type=int, default=0)
parser.add_argument("--days", type=int, default=None,
help="Estimated days to cash (default: 30)")
args = parser.parse_args()
ev = log_decision(args.action, args.cost, args.potential, args.probability,
args.category, notes=args.notes, session=args.session,
time_to_cash_days=args.days)
print(f"Logged: {args.action} (EV: ${ev:.2f})")
elif cmd == "report":
print(get_report())
elif cmd == "best":
print(get_best_actions())
elif cmd == "seed":
seed_current_actions()
elif cmd == "update":
if len(sys.argv) < 4:
print("Usage: python3 economic_engine.py update ID outcome [actual_revenue]")
sys.exit(1)
decision_id = int(sys.argv[2])
outcome = sys.argv[3]
actual = float(sys.argv[4]) if len(sys.argv) > 4 else 0
update_outcome(decision_id, outcome, actual)
print(f"Updated decision {decision_id}: {outcome} (${actual:.2f})")
elif cmd == "task":
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("cmd")
parser.add_argument("session", type=int)
parser.add_argument("task")
parser.add_argument("--category", default="general")
parser.add_argument("--turns", type=int, default=1)
parser.add_argument("--tangible", action="store_true")
parser.add_argument("--output", default="")
parser.add_argument("--notes", default="")
args = parser.parse_args()
log_task_outcome(args.session, args.task, args.category, args.turns,
args.tangible, args.output, args.notes)
marker = "productive" if args.tangible else "non-productive"
print(f"Logged: S{args.session} | {args.task} | {args.turns}t | {marker}")
elif cmd == "journal":
print(get_task_journal())
elif cmd == "bear":
pending = get_pending_bear_cases()
if pending:
print(f"Pending bear case reviews ({len(pending)}):")
for p in pending:
print(f" [{p['id']}] {p['action']} — ${p['potential']:.0f} potential, EV ${p['ev']:.2f}")
else:
print("No pending bear case reviews.")
recent = get_recent_bear_cases()
if recent:
print(f"\nRecent bear cases ({len(recent)}):")
for r in recent:
print(f" [{r['id']}] {r['action']} — {r['verdict']}")
# Show first 200 chars of arguments
if r['arguments']:
print(f" {r['arguments'][:200]}...")
else:
print(f"Unknown command: {cmd}")
sys.exit(1)