goal: /goal is the primitive; per-topic autopilot vs copilot

Merged
MA
7mo ago
+279-81

Summary

Magnus laid out a simpler product model: agency isn't a separate mode, it's the default. The primitive is /goal, one goal lives in its own Telegram topic forever, and each topic has a per-topic execution mode the user can toggle.

  • One goal = one TG topic = one persistent session. Reply at any time, agent resumes with full context.
  • Two execution modes per topic:
    • copilot (default) — agent drafts, queries, scrapes privately, then posts one agency-report card with the action pre-completed and asks ✅ Yes / 🔁 More / ⏭ Skip. Stops at every visible boundary.
    • autopilot — agent acts directly on reversible work, posts short progress updates inline. Stops only at visible/external side effects (send email, post publicly, merge, pay).
  • Self-scheduling baked in. At the end of every cycle, the agent picks its own cadence (30m / 1h / 4h / daily) and fires tg-schedule itself. Resume keeps full session context.
  • One concrete action per cycle, not a batch of ten. The old prompt told the agent to "generate 10 cards" which produces filler.
  • Buttons collapse to one canonical set. ✅ Yes / 🔁 More / ⏭ Skip. No more spawn-topic label variants, no Edit. New more kind regenerates the same idea with a different angle.
  • /goal failure now surfaces. If createForumTopic fails (group lacks topics, bot isn't admin), the user is told instead of silently merging the goal into the current thread.

Changes

  • agent/telegram_bot.py — /autopilot, /copilot commands; _get_goal_mode / _set_goal_mode helpers; new mode column on the mini-app goals table with backfill; rewritten _agency_goal_prompt; _handle_agency_callback handles kind="more"; /goal surfaces topic-creation errors.
  • agent/agency-report — DEFAULT_BUTTONS (one canonical set); docstring updated; spawn-topic label variants removed.
  • agent/agency_db.py — record_decision maps "more" decisions to status regenerated.
  • agent/mini_app.py — matching mode column in its goals-table schema + backfill.
  • agent/CLAUDE.md — "Agency mode" section rewritten around the new primitive.

Saved for v2 (not in this PR)

  • Collapse AGENCY.md from 470 → ~120 lines (the doctrine cut).
  • Drop the old Mini App (index.html / app.js / app.css, ~2230 LOC; the canonical / already routes to tinder.html).
  • Merge install.sh + bootstrap.sh duplication.
  • Split telegram_bot.py (7741 LOC, 115 top-level fns).

Silent-failure paths still in the file (separate cleanup)

Scan turned up _handle_agency_callback and _start_agency_goal_from_command silent fallbacks. Fixed the /goal one as part of this PR; others (DB record_decision failures, callback segment-count mismatch with empty toast, refine context-injection swallowed) remain for a follow-up.

Test plan

  • pytest agent/test_telegram_bot.py agent/test_mini_app.py — 21 passed
  • python3 -c "ast.parse(...)" syntax check across all touched files
  • Send /goal write a sample post about X in a group with topics on a real box — verify new topic spawns and first cycle posts a card with ✅ Yes / 🔁 More / ⏭ Skip
  • Send /autopilot in that topic — verify ack + mode flip
  • Tap 🔁 More on a card — verify agent regenerates with a different angle

🤖 Generated with Claude Code


Summary by cubic

Make /goal the core flow: one goal per Telegram topic with a persistent session and per‑topic mode (copilot default, autopilot optional). Cards are simplified to ✅ Yes / 🔁 More / ⏭ Skip, and cycles self‑schedule.

  • New Features

    • Per-topic mode switches: /autopilot and /copilot; persisted as goals.mode (default copilot) with backfill.
    • Mode‑aware goal prompt: one concrete action per cycle, then self‑schedule via tg-schedule.
    • agency-report: default buttons now ✅ Yes (action), 🔁 More (regenerate with a different angle), ⏭ Skip (dismiss). Yes/More run in the same topic; spawn-topic flags kept for back‑compat.
    • /goal: creates a dedicated topic per goal; the topic is the goal’s permanent lane with full context resume.
  • Bug Fixes

    • /goal now surfaces createForumTopic failures instead of silently falling back to the current thread.