@m13v/s4l 1.7.1-rc.9 → 1.7.1

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 (40) hide show
  1. package/mcp/dist/index.js +354 -24
  2. package/mcp/dist/panel.html +42 -31
  3. package/mcp/dist/product-link.html +1 -1
  4. package/mcp/dist/telemetry.js +80 -3
  5. package/mcp/dist/version.json +2 -2
  6. package/mcp/manifest.json +9 -1
  7. package/mcp/menubar/dashboard_server.py +12 -0
  8. package/mcp/menubar/s4l_card.py +539 -80
  9. package/mcp/menubar/s4l_menubar.py +299 -191
  10. package/mcp/menubar/s4l_state.py +228 -33
  11. package/mcp/package.json +1 -1
  12. package/package.json +4 -1
  13. package/scripts/active_users.py +3 -6
  14. package/scripts/autopilot_stall_watch.py +200 -16
  15. package/scripts/claude_job.py +6 -0
  16. package/scripts/feedback_digest.py +34 -6
  17. package/scripts/harness_overlay.py +45 -0
  18. package/scripts/identity.py +26 -0
  19. package/scripts/learned_preferences.py +241 -32
  20. package/scripts/link_tail.py +167 -91
  21. package/scripts/mark_event.py +128 -0
  22. package/scripts/memory_snapshot.py +27 -0
  23. package/scripts/merge_review_queue.py +42 -16
  24. package/scripts/pick_twitter_thread_target.py +1 -1
  25. package/scripts/s4l_mode.py +7 -5
  26. package/scripts/scan_pii.py +9 -1
  27. package/scripts/schedule_state.py +146 -69
  28. package/scripts/scheduled_task_selfheal.py +276 -0
  29. package/scripts/scheduled_tasks_snapshot.py +107 -0
  30. package/scripts/send_gmail_report.py +76 -0
  31. package/scripts/sentry_digest.py +81 -189
  32. package/scripts/sentry_init.py +43 -15
  33. package/scripts/snapshot.py +20 -0
  34. package/scripts/twitter_post_plan.py +39 -13
  35. package/skill/dm-outreach-twitter.sh +19 -0
  36. package/skill/engage-twitter.sh +27 -0
  37. package/skill/run-draft-and-publish.sh +13 -12
  38. package/skill/run-linkedin.sh +9 -1
  39. package/skill/run-twitter-cycle.sh +199 -27
  40. package/skill/sentry-digest.sh +125 -12
@@ -82,6 +82,85 @@ def state_dir() -> str:
82
82
  )
83
83
 
84
84
 
85
+ # ---- pause/resume: stop drafting/posting without touching Claude Desktop ---
86
+ # Real mechanics (flag file + launchctl bootout/bootstrap), NOT a loopback call
87
+ # to the MCP: this needs to work from BOTH the menu bar (s4l_menubar.py) and
88
+ # the Claude-independent dashboard_server.py, which share this process but
89
+ # are a different process from the MCP server, so there's no way to delegate
90
+ # to mcp/src/index.ts's pauseS4L/resumeS4L here. Mirrors those functions
91
+ # (same 4 labels, same flag path) for the common pause->resume case. What it
92
+ # deliberately does NOT do: mcp/src/index.ts's resumeS4L also re-runs the
93
+ # readiness-gated install logic (persona/project/X-verified checks, content-
94
+ # aware plist rewrite) via ensure*Installed() — that only matters for a box
95
+ # that was never fully set up before Pause, an edge case the next Claude
96
+ # boot / project_config call naturally heals once unpaused. This resume just
97
+ # reloads the exact plists Pause unloaded (Pause never deletes anything).
98
+ PAUSE_TARGET_LABELS = (
99
+ AUTOPILOT_LABEL,
100
+ "com.m13v.social-claude-reaper",
101
+ "com.m13v.social-autopilot-stall-watch",
102
+ "com.m13v.social-memory-snapshot",
103
+ )
104
+
105
+
106
+ def pause_flag_path() -> str:
107
+ return os.path.join(state_dir(), "paused.flag")
108
+
109
+
110
+ def is_paused() -> bool:
111
+ return os.path.exists(pause_flag_path())
112
+
113
+
114
+ def pause_s4l() -> dict:
115
+ if is_paused():
116
+ return {"ok": True, "paused": True, "detail": "already paused"}
117
+ try:
118
+ os.makedirs(state_dir(), exist_ok=True)
119
+ with open(pause_flag_path(), "w") as fh:
120
+ fh.write(f"paused at {time.strftime('%Y-%m-%dT%H:%M:%S%z')}\n")
121
+ except Exception as e:
122
+ return {"ok": False, "paused": is_paused(), "detail": f"could not write pause flag: {e}"}
123
+ uid = os.getuid()
124
+ results = []
125
+ for label in PAUSE_TARGET_LABELS:
126
+ try:
127
+ subprocess.run(
128
+ ["launchctl", "bootout", f"gui/{uid}/{label}"],
129
+ capture_output=True, timeout=15,
130
+ )
131
+ results.append(f"{label}: unloaded")
132
+ except Exception as e:
133
+ results.append(f"{label}: {e}")
134
+ return {"ok": True, "paused": True, "detail": "; ".join(results)}
135
+
136
+
137
+ def resume_s4l() -> dict:
138
+ try:
139
+ os.remove(pause_flag_path())
140
+ except FileNotFoundError:
141
+ pass
142
+ except Exception:
143
+ pass
144
+ uid = os.getuid()
145
+ la_dir = str(Path.home() / "Library" / "LaunchAgents")
146
+ results = []
147
+ for label in PAUSE_TARGET_LABELS:
148
+ plist = os.path.join(la_dir, f"{label}.plist")
149
+ if not os.path.exists(plist):
150
+ results.append(f"{label}: no plist, skip")
151
+ continue
152
+ try:
153
+ subprocess.run(["launchctl", "enable", f"gui/{uid}/{label}"], capture_output=True, timeout=15)
154
+ r = subprocess.run(
155
+ ["launchctl", "bootstrap", f"gui/{uid}", plist],
156
+ capture_output=True, timeout=15,
157
+ )
158
+ results.append(f"{label}: rc={r.returncode}")
159
+ except Exception as e:
160
+ results.append(f"{label}: {e}")
161
+ return {"ok": True, "paused": is_paused(), "detail": "; ".join(results)}
162
+
163
+
85
164
  def read_json(name: str):
86
165
  try:
87
166
  return json.loads((Path(state_dir()) / name).read_text())
@@ -153,16 +232,34 @@ def autopilot_loaded() -> bool:
153
232
  # serves the menu bar's own dashboard_server (single path, per user 2026-07-03).
154
233
  # panel-endpoint.json is last-writer-wins across many short-lived MCP instances,
155
234
  # so treat reachability as best-effort.
235
+ #
236
+ # Bypass any configured system/env HTTP proxy for these calls. On macOS,
237
+ # urllib.request honors the system proxy (via _scproxy) for ALL requests,
238
+ # 127.0.0.1 included, unless a proxy is explicitly disabled per-request — a
239
+ # plain urlopen() does NOT skip loopback the way browsers/curl typically do.
240
+ # A machine with any system-wide proxy configured (corporate VPN client,
241
+ # security software, a residential-IP proxy for platform fingerprinting,
242
+ # etc.) whose bypass list doesn't happen to include 127.0.0.1/localhost will
243
+ # have every loopback health check and post_drafts call silently routed out
244
+ # through that proxy instead of hitting the MCP server directly — surfacing
245
+ # as an opaque connection error/403 with no indication the proxy is at
246
+ # fault. This is a local process talking to its own local server: it must
247
+ # never go through any proxy, regardless of what's configured system-wide.
248
+ _NO_PROXY_OPENER = urllib.request.build_opener(urllib.request.ProxyHandler({}))
249
+
250
+
156
251
  def _endpoint_url():
157
252
  ep = read_json("panel-endpoint.json")
158
253
  url = (ep or {}).get("url")
159
254
  if not url:
160
255
  return None
161
256
  try:
162
- with urllib.request.urlopen(url + "health", timeout=1.5) as r:
257
+ with _NO_PROXY_OPENER.open(url + "health", timeout=1.5) as r:
163
258
  if r.status == 200:
164
259
  return url
165
- except Exception:
260
+ except Exception as e:
261
+ sys.stderr.write(f"[s4l-state] loopback health check failed: {type(e).__name__}: {e}\n")
262
+ sys.stderr.flush()
166
263
  return None
167
264
  return None
168
265
 
@@ -206,9 +303,11 @@ def loopback_tool(name: str, args=None, timeout: float = 20.0):
206
303
  headers={"Content-Type": "application/json"},
207
304
  method="POST",
208
305
  )
209
- with urllib.request.urlopen(req, timeout=timeout) as r:
306
+ with _NO_PROXY_OPENER.open(req, timeout=timeout) as r:
210
307
  return _parse_tool_result(json.loads(r.read().decode()))
211
- except Exception:
308
+ except Exception as e:
309
+ sys.stderr.write(f"[s4l-state] loopback_tool({name!r}) failed: {type(e).__name__}: {e}\n")
310
+ sys.stderr.flush()
212
311
  return None
213
312
 
214
313
 
@@ -246,6 +345,12 @@ def ver_key(v):
246
345
  return _snapshot_module()._ver_key(v)
247
346
 
248
347
 
348
+ def version():
349
+ """Installed version, delegated to scripts/snapshot.py::_resolve_version so
350
+ there is exactly ONE Python implementation, same pattern as ver_key above."""
351
+ return _snapshot_module()._resolve_version()
352
+
353
+
249
354
  def _refresh_snapshot_bg():
250
355
  try:
251
356
  snap = _compute_snapshot_full()
@@ -259,6 +364,43 @@ def _refresh_snapshot_bg():
259
364
  _snap_refreshing[0] = False
260
365
 
261
366
 
367
+ # ---- version/update check: refreshed independently of the full snapshot ----
368
+ # compute() calls _x_status() FIRST, which can block up to 90s in a subprocess
369
+ # (setup_twitter_auth.py -> CDP to Chrome) whenever a scan job has the browser
370
+ # busy. That stalls _refresh_snapshot_bg() for the whole duration, so
371
+ # update_available/latest_version stay frozen on a busy box even though the
372
+ # GitHub check itself is a ~1s curl. Poll scripts/snapshot.py::version_status()
373
+ # on its own short cadence, gated by its own lock, so the "Update available"
374
+ # banner never waits on X/Chrome state.
375
+ _ver_cache = {"val": None, "at": 0.0}
376
+ _ver_refreshing = [False]
377
+ _VER_REFRESH_TTL = 20.0
378
+
379
+
380
+ def _refresh_version_bg():
381
+ try:
382
+ val = _snapshot_module().version_status()
383
+ if isinstance(val, dict) and "update_available" in val:
384
+ with _snap_lock:
385
+ _ver_cache["val"] = val
386
+ _ver_cache["at"] = time.time()
387
+ except Exception:
388
+ pass
389
+ finally:
390
+ _ver_refreshing[0] = False
391
+
392
+
393
+ def _version_overlay():
394
+ now = time.time()
395
+ with _snap_lock:
396
+ cached = _ver_cache["val"]
397
+ age = now - _ver_cache["at"]
398
+ if (cached is None or age > _VER_REFRESH_TTL) and not _ver_refreshing[0]:
399
+ _ver_refreshing[0] = True
400
+ threading.Thread(target=_refresh_version_bg, daemon=True).start()
401
+ return cached
402
+
403
+
262
404
  def snapshot():
263
405
  """Full snapshot computed DIRECTLY from the stateful files via
264
406
  scripts/snapshot.py — the SAME single-source module the MCP shells out to, so
@@ -268,7 +410,9 @@ def snapshot():
268
410
  a BACKGROUND thread; this returns the last cached result instantly.
269
411
 
270
412
  Tiers: (1) the background-computed local snapshot; (2) the server's last
271
- persisted `status-summary.json`; (3) the onboarding ledger."""
413
+ persisted `status-summary.json`; (3) the onboarding ledger. The version/update
414
+ fields are always overlaid from the independent _version_overlay() cache
415
+ (see above) so they stay live even while tier (1)'s compute() is blocked."""
272
416
  now = time.time()
273
417
  with _snap_lock:
274
418
  cached = _snap_cache["val"]
@@ -276,29 +420,40 @@ def snapshot():
276
420
  if (cached is None or age > 4.0) and not _snap_refreshing[0]:
277
421
  _snap_refreshing[0] = True
278
422
  threading.Thread(target=_refresh_snapshot_bg, daemon=True).start()
423
+
279
424
  if cached is not None:
280
425
  out = dict(cached)
281
426
  out["_live"] = True
282
- return out
283
- summ = read_json("status-summary.json")
284
- if isinstance(summ, dict) and "projects_total" in summ:
285
- summ["_live"] = False
286
- summ["_from_summary"] = True
287
- return summ
288
- ob = read_onboarding()
289
- return {
290
- "_live": False,
291
- "runtime_ready": runtime_ready(),
292
- "onboarding": ob,
293
- "autopilot_on": autopilot_loaded(),
294
- "x_connected": False, # unknowable offline; State derives from onboarding
295
- "x_handle": None,
296
- "projects_ready": 0,
297
- "projects_total": 0,
298
- "version": version(),
299
- "update_available": False,
300
- "latest_version": None,
301
- }
427
+ else:
428
+ summ = read_json("status-summary.json")
429
+ if isinstance(summ, dict) and "projects_total" in summ:
430
+ out = dict(summ)
431
+ out["_live"] = False
432
+ out["_from_summary"] = True
433
+ else:
434
+ ob = read_onboarding()
435
+ out = {
436
+ "_live": False,
437
+ "runtime_ready": runtime_ready(),
438
+ "onboarding": ob,
439
+ "autopilot_on": autopilot_loaded(),
440
+ "x_connected": False, # unknowable offline; State derives from onboarding
441
+ "x_handle": None,
442
+ "projects_ready": 0,
443
+ "projects_total": 0,
444
+ "version": version(),
445
+ "update_available": False,
446
+ "latest_version": None,
447
+ }
448
+
449
+ ver = _version_overlay()
450
+ if ver is not None:
451
+ out["version"] = ver.get("version", out.get("version"))
452
+ out["channel"] = ver.get("channel", out.get("channel"))
453
+ out["latest_version"] = ver.get("latest_version", out.get("latest_version"))
454
+ out["latest_tag"] = ver.get("latest_tag", out.get("latest_tag"))
455
+ out["update_available"] = ver.get("update_available", out.get("update_available"))
456
+ return out
302
457
 
303
458
 
304
459
  def stats_7d():
@@ -836,6 +991,13 @@ def review_drafts(plan, batch="review-queue"):
836
991
  # scripts/active_experiments.py. Generic: the card renders
837
992
  # whatever is here, so new experiments surface with no UI work.
838
993
  "experiments": c.get("experiments") or {},
994
+ # Two-draft cards (2026-07-07; no-recommendation pass
995
+ # 2026-07-08): present only when the prep step wrote two
996
+ # independent drafts (fresh candidate, not a reused stale
997
+ # draft). The card shows both, defaulting to Draft A (slot 0,
998
+ # no model recommendation involved); absent on reused/legacy
999
+ # candidates, which fall back to the single-draft UI above.
1000
+ "drafts": c.get("drafts"),
839
1001
  }
840
1002
  )
841
1003
  # The review queue is append-only, so the highest stable index is newest and
@@ -1155,8 +1317,18 @@ def review_event_add(event):
1155
1317
  p.parent.mkdir(parents=True, exist_ok=True)
1156
1318
  with open(p, "a") as f:
1157
1319
  f.write(json.dumps(ev) + "\n")
1158
- except Exception:
1159
- pass
1320
+ except Exception as err:
1321
+ # Was a silent `pass` — a card's approve/reject decision could vanish
1322
+ # with zero trace anywhere (2026-07-08: two approved-and-posted cards
1323
+ # had no review_events row at all, and this was one of the candidate
1324
+ # causes with nothing to confirm or rule it out). Never never write to
1325
+ # the outbox again for THIS event, so it's worth saying loudly.
1326
+ sys.stderr.write(
1327
+ f"[s4l-state] review_event_add: failed to append to outbox ({type(err).__name__}: {err}); "
1328
+ f"event DROPPED event_uuid={ev.get('event_uuid')} decision={ev.get('decision')} "
1329
+ f"candidate_id={ev.get('candidate_id')}\n"
1330
+ )
1331
+ sys.stderr.flush()
1160
1332
  flush_review_events_async()
1161
1333
 
1162
1334
 
@@ -1177,16 +1349,29 @@ def flush_review_events():
1177
1349
  if not p.exists():
1178
1350
  return
1179
1351
  lines = [ln for ln in p.read_text().splitlines() if ln.strip()]
1180
- except Exception:
1352
+ except Exception as err:
1353
+ sys.stderr.write(f"[s4l-state] flush_review_events: failed to read outbox: {type(err).__name__}: {err}\n")
1354
+ sys.stderr.flush()
1181
1355
  return
1182
1356
  events = []
1183
1357
  for ln in lines:
1184
1358
  try:
1185
1359
  ev = json.loads(ln)
1186
- if isinstance(ev, dict) and ev.get("event_uuid"):
1187
- events.append(ev)
1188
- except Exception:
1360
+ except Exception as err:
1361
+ sys.stderr.write(
1362
+ f"[s4l-state] flush_review_events: dropping unparseable outbox line "
1363
+ f"({type(err).__name__}: {err}): {ln[:200]!r}\n"
1364
+ )
1365
+ sys.stderr.flush()
1189
1366
  continue # corrupt line: dropped on the next rewrite
1367
+ if isinstance(ev, dict) and ev.get("event_uuid"):
1368
+ events.append(ev)
1369
+ else:
1370
+ sys.stderr.write(
1371
+ f"[s4l-state] flush_review_events: dropping malformed outbox line "
1372
+ f"(not a dict, or missing event_uuid): {ln[:200]!r}\n"
1373
+ )
1374
+ sys.stderr.flush()
1190
1375
  if not events:
1191
1376
  if lines: # only corrupt lines left — clear the file
1192
1377
  _outbox_remove(set())
@@ -1195,7 +1380,12 @@ def flush_review_events():
1195
1380
  # import lazily so a missing pipeline repo degrades to buffer-only.
1196
1381
  try:
1197
1382
  from http_api import api_post
1198
- except Exception:
1383
+ except Exception as err:
1384
+ sys.stderr.write(
1385
+ f"[s4l-state] flush_review_events: http_api unavailable ({type(err).__name__}: {err}); "
1386
+ f"{len(events)} event(s) staying buffered in the outbox\n"
1387
+ )
1388
+ sys.stderr.flush()
1199
1389
  return
1200
1390
  shipped = set()
1201
1391
  for i in range(0, len(events), 100):
@@ -1203,7 +1393,12 @@ def flush_review_events():
1203
1393
  try:
1204
1394
  api_post("/api/v1/review-events", {"events": batch})
1205
1395
  shipped.update(e["event_uuid"] for e in batch)
1206
- except Exception:
1396
+ except Exception as err:
1397
+ sys.stderr.write(
1398
+ f"[s4l-state] flush_review_events: POST failed ({type(err).__name__}: {err}); "
1399
+ f"{len(batch)} event(s) in this batch (and any after it) staying buffered for the next kick\n"
1400
+ )
1401
+ sys.stderr.flush()
1207
1402
  break # network/API down: keep the rest for the next kick
1208
1403
  _outbox_remove(shipped, keep_only_valid=True)
1209
1404
  finally:
package/mcp/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@m13v/s4l-mcp",
3
- "version": "1.7.1-rc.9",
3
+ "version": "1.7.1",
4
4
  "private": true,
5
5
  "description": "Desktop MCP client for social-autoposter (X/Twitter rail): manual draft/review/approve loop, autopilot control, and stats. Thin wrapper over the existing pipeline scripts.",
6
6
  "license": "MIT",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@m13v/s4l",
3
- "version": "1.7.1-rc.9",
3
+ "version": "1.7.1",
4
4
  "description": "Automated social posting pipeline for Reddit, X/Twitter, LinkedIn, and Moltbook. Install as a Claude Code agent skill.",
5
5
  "bin": {
6
6
  "social-autoposter": "bin/cli.js",
@@ -18,6 +18,7 @@
18
18
  "!bin/auth.js",
19
19
  "scripts/*.py",
20
20
  "!scripts/db_direct.py",
21
+ "!scripts/sync_blocked_authors.py",
21
22
  "!scripts/backfill_real_clicks.py",
22
23
  "!scripts/historical_engagement.py",
23
24
  "!scripts/style_length_report.py",
@@ -117,6 +118,7 @@
117
118
  "requirements.txt",
118
119
  "SKILL.md",
119
120
  "skill/*.sh",
121
+ "!skill/sync-blocked-authors.sh",
120
122
  "skill/lib/*.sh",
121
123
  "setup/SKILL.md",
122
124
  "browser-agent-configs/",
@@ -153,6 +155,7 @@
153
155
  "node": ">=16"
154
156
  },
155
157
  "dependencies": {
158
+ "@sentry/node": "^10.64.0",
156
159
  "firebase-admin": "^13.8.0",
157
160
  "pg": "^8.20.0",
158
161
  "ws": "^8.0.0"
@@ -32,13 +32,10 @@ from urllib.parse import unquote
32
32
 
33
33
  sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
34
34
  from db import load_env, get_conn # noqa: E402
35
-
36
35
  # Our own installs, hidden by default so the roster is real external users.
37
- INTERNAL_EMAILS = {"i@m13v.com", "agent@mk0r.com", "matt@mediar.ai"}
38
- INTERNAL_HOSTNAME_SUBSTR = ("e2b.local", "71522") # mk0r E2B sandboxes; MacStadium QA box
39
- # MacStadium remote QA box (hostname "71522", no git_email). It actively runs the
40
- # pipeline and posts, so without this it masquerades as our only posting customer.
41
- INTERNAL_HARDWARE_UUIDS = {"07CB793D-6E32-5EF8-82E2-7CDEABD47FBC"}
36
+ # Shared with autopilot_stall_watch.py via identity.py so the two lists can't
37
+ # drift apart (see identity.is_internal_install).
38
+ from identity import INTERNAL_EMAILS, INTERNAL_HOSTNAME_SUBSTR, INTERNAL_HARDWARE_UUIDS # noqa: E402
42
39
 
43
40
  # Connected X handle resolves only from posts.our_account; drop scaffolding values.
44
41
  PLACEHOLDER_HANDLES = {"your-twitter-handle", "your_handle", "your-handle", "none", "null", ""}