switchroom 0.20.2 → 0.20.4

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.
Files changed (27) hide show
  1. package/bin/handoff-briefing.sh +41 -1
  2. package/dist/cli/switchroom.js +10259 -1232
  3. package/dist/host-control/main.js +1 -1
  4. package/package.json +3 -3
  5. package/profiles/default/CLAUDE.md.hbs +13 -11
  6. package/telegram-plugin/dist/gateway/gateway.js +429 -98
  7. package/telegram-plugin/edit-flood-fuse.ts +332 -14
  8. package/telegram-plugin/gateway/feed-open-gate.ts +28 -8
  9. package/telegram-plugin/gateway/feed-reopen-gate.ts +88 -6
  10. package/telegram-plugin/gateway/gateway.ts +128 -104
  11. package/telegram-plugin/gateway/narrative-lane.ts +4 -0
  12. package/telegram-plugin/gateway/progress-fallback-cap.ts +195 -0
  13. package/telegram-plugin/gateway/stream-render.ts +67 -12
  14. package/telegram-plugin/gateway/subagent-handback-inbound-builder.ts +13 -0
  15. package/telegram-plugin/gateway/subagent-origin-surface.ts +181 -0
  16. package/telegram-plugin/gateway/subagent-progress-inbound-builder.ts +7 -0
  17. package/telegram-plugin/registry/subagents-schema.ts +61 -0
  18. package/telegram-plugin/registry/turns-schema.ts +26 -0
  19. package/telegram-plugin/tests/edit-flood-fuse-cosmetic-fairness.test.ts +229 -0
  20. package/telegram-plugin/tests/feed-open-gate.test.ts +42 -0
  21. package/telegram-plugin/tests/feed-reopen-gate.test.ts +114 -0
  22. package/telegram-plugin/tests/progress-cap.test.ts +182 -0
  23. package/telegram-plugin/tests/progress-fallback-cap.test.ts +91 -0
  24. package/telegram-plugin/tests/progress-update.test.ts +108 -12
  25. package/telegram-plugin/tests/subagent-handback-inbound-builder.test.ts +46 -0
  26. package/telegram-plugin/tests/subagent-progress-inbound-builder.test.ts +26 -0
  27. package/telegram-plugin/tests/worker-origin-gap-dispatch.test.ts +304 -0
@@ -104,6 +104,18 @@ try:
104
104
  conn.row_factory = sqlite3.Row
105
105
  cur = conn.cursor()
106
106
 
107
+ # Probe ONCE whether this history DB carries the native-reply columns
108
+ # (reply_to_message_id / reply_to_text, added with issue #119). A DB
109
+ # predating them would raise OperationalError on the extended SELECT and,
110
+ # via the outer `except → sys.exit(0)`, silently drop the ENTIRE
111
+ # Telegram-history section. Detect the columns explicitly here and degrade
112
+ # to the legacy column list (skipping the antecedent render) rather than
113
+ # swallowing a real query failure. The outer try/except still catches
114
+ # genuine errors — this only distinguishes "columns absent" from those.
115
+ cur.execute("PRAGMA table_info(messages)")
116
+ _msg_cols = {r[1] for r in cur.fetchall()}
117
+ has_reply_cols = "reply_to_message_id" in _msg_cols and "reply_to_text" in _msg_cols
118
+
107
119
  # Resolve the surface to scope to.
108
120
  # - explicit env target (pending-turn chat/thread) wins — UNLESS that chat
109
121
  # has zero rows (rotated/fresh DB), in which case we fall through to
@@ -191,8 +203,11 @@ try:
191
203
  % (scope_chat, "NULL" if scope_thread_is_null else (scope_thread if scope_thread_known else "any"), scope_source)
192
204
  )
193
205
 
206
+ select_cols = "role, user, ts, text"
207
+ if has_reply_cols:
208
+ select_cols += ", reply_to_message_id, reply_to_text"
194
209
  cur.execute(
195
- "SELECT role, user, ts, text FROM messages WHERE "
210
+ "SELECT " + select_cols + " FROM messages WHERE "
196
211
  + " AND ".join(where)
197
212
  + " ORDER BY ts DESC LIMIT ?",
198
213
  params,
@@ -209,7 +224,32 @@ try:
209
224
  text = text[:600] + "… [truncated]"
210
225
  # Escape any literal backslash to keep the shell echo safe
211
226
  text = text.replace("\\", "\\\\")
227
+ # Reply antecedent (issue #119 native reply). recordInbound persists
228
+ # reply_to_message_id/reply_to_text — the latter recovered from the
229
+ # history buffer even when the reply target was the bot's OWN message
230
+ # (Telegram omits its text on the live update). Surfacing it as an
231
+ # indented "↪ replying to" line carries the antecedent STRUCTURE into
232
+ # the post-reset briefing, so a fresh session reading this transcript
233
+ # knows what "this"/"that" in the reply refers to instead of guessing.
234
+ # Without it the flat dump loses the thread of any native reply.
212
235
  print(f"[{ts_str}] {label}: {text}")
236
+ if not has_reply_cols:
237
+ # Legacy DB (pre-#119): no reply columns were selected, so the
238
+ # antecedent render is skipped entirely. The history section still
239
+ # renders every message above — just without "↪ replying to" lines.
240
+ continue
241
+ reply_id = row["reply_to_message_id"]
242
+ reply_text = row["reply_to_text"]
243
+ if reply_text is not None and reply_text != "":
244
+ rt = reply_text
245
+ if len(rt) > 200:
246
+ rt = rt[:200] + "…"
247
+ rt = rt.replace("\\", "\\\\").replace("\n", " ")
248
+ print(f" ↪ replying to: {rt}")
249
+ elif reply_id is not None:
250
+ # Antecedent known by id only (text unavailable — reply target had
251
+ # no text, or predates the reply_to_text buffer backfill).
252
+ print(f" ↪ replying to message #{reply_id}")
213
253
  except Exception as e:
214
254
  sys.stderr.write(f"handoff-briefing: sqlite query failed: {e}\n")
215
255
  sys.exit(0)