@m13v/s4l 1.7.11 → 1.7.12-rc.10
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.
- package/browser-agent-configs/linkedin-harness-mcp.json +3 -1
- package/browser-agent-configs/twitter-harness-mcp.json +3 -1
- package/mcp/dist/index.js +155 -23
- package/mcp/dist/repo.js +65 -5
- package/mcp/dist/setup.js +35 -28
- package/mcp/dist/version.json +2 -2
- package/mcp/manifest.json +1 -1
- package/mcp/menubar/s4l_card.py +119 -1
- package/mcp/menubar/s4l_menubar.py +174 -2
- package/mcp/menubar/s4l_state.py +10 -1
- package/mcp/package.json +1 -1
- package/package.json +18 -1
- package/scripts/angles.py +8 -0
- package/scripts/cdp_drive.py +102 -0
- package/scripts/cdp_ready_check.py +56 -9
- package/scripts/claude_job.py +13 -29
- package/scripts/config.py +51 -3
- package/scripts/draft_prompt_core.py +15 -2
- package/scripts/dump_visitor_history.py +72 -0
- package/scripts/engage_github.py +62 -3
- package/scripts/harness_overlay.py +84 -39
- package/scripts/ingest_human_github_replies.py +205 -0
- package/scripts/invent_topics.py +10 -3
- package/scripts/pick_thread_target.py +4 -0
- package/scripts/pick_twitter_thread_target.py +4 -0
- package/scripts/post_reddit.py +40 -43
- package/scripts/project_topics.py +59 -1
- package/scripts/qualified_query_bank.py +53 -2
- package/scripts/reap_stale_claude_sessions.py +168 -6
- package/scripts/reddit_ban_check.py +28 -28
- package/scripts/reddit_query_bank.py +42 -2
- package/scripts/reply_db.py +19 -0
- package/scripts/s4l_box_update.sh +46 -4
- package/scripts/s4l_halt.sh +102 -0
- package/scripts/scan_github_replies.py +34 -8
- package/scripts/schedule_state.py +9 -5
- package/scripts/scrape_linkedin_comment_stats.py +25 -7
- package/scripts/session_index_prune.py +214 -0
- package/scripts/update_linkedin_stats_from_feed.py +20 -1
- package/scripts/voice_exemplars.py +8 -3
- package/skill/check-web-chats.sh +45 -0
- package/skill/run-twitter-cycle.sh +6 -0
- package/skill/run-twitter-threads.sh +51 -0
- package/scripts/tlh_freshness_284.py +0 -134
- package/scripts/tlh_pick_248.py +0 -92
package/mcp/menubar/s4l_card.py
CHANGED
|
@@ -714,6 +714,34 @@ def _age_expiry_display(iso, platform):
|
|
|
714
714
|
return text, urgent
|
|
715
715
|
|
|
716
716
|
|
|
717
|
+
# Local hard-expire at the countdown site (2026-08-17): when a card's clock
|
|
718
|
+
# crosses zero it is RETIRED locally (terminal, reason local_clock_expired)
|
|
719
|
+
# instead of just relabeling itself "expired" while staying approvable. The
|
|
720
|
+
# real freshness gate is cycle-driven (backend Phase 0 flip + merge-time
|
|
721
|
+
# prune), so any stretch where cycles don't run — machine asleep on a dead
|
|
722
|
+
# battery, producer down, hidden window absorbing drafts overnight — used to
|
|
723
|
+
# leave long-expired cards presentable; approving one is a silent no-op
|
|
724
|
+
# server-side (2026-07-09, and again on the 2026-08-17 hibernate wake, 14
|
|
725
|
+
# cards approved 6-19h stale). Corner-card mode only: canvas tiles keep the
|
|
726
|
+
# label-only behavior (the canvas is always an explicit user-opened surface
|
|
727
|
+
# with its own replace flow). The on-screen card additionally requires
|
|
728
|
+
# AUTO_EXPIRE_IDLE_SECONDS without interaction and an unedited draft before
|
|
729
|
+
# it self-retires, so it is never yanked out from under someone actively
|
|
730
|
+
# working the moment the clock crosses zero.
|
|
731
|
+
AUTO_EXPIRE_IDLE_SECONDS = 60
|
|
732
|
+
|
|
733
|
+
|
|
734
|
+
def _draft_expired(d):
|
|
735
|
+
"""True when this draft's Phase 0 hard-expire deadline has passed — the
|
|
736
|
+
same clock the header countdown renders (_expiry_secs_left). False when
|
|
737
|
+
the countdown doesn't apply (reddit cards, missing timestamp)."""
|
|
738
|
+
d = d or {}
|
|
739
|
+
secs = _expiry_secs_left(
|
|
740
|
+
(d.get("stats") or {}).get("tweet_posted_at"), d.get("platform")
|
|
741
|
+
)
|
|
742
|
+
return secs is not None and secs <= 0
|
|
743
|
+
|
|
744
|
+
|
|
717
745
|
# Hover popover on the header's age/expiry label (2026-07-15 per user): the
|
|
718
746
|
# reviewer sees the countdown but not necessarily WHY it exists, so the
|
|
719
747
|
# popover pairs the live seconds-granular clock with the reasoning behind the
|
|
@@ -1154,6 +1182,12 @@ class _ReviewController(NSObject):
|
|
|
1154
1182
|
self._add_snooze_accessory(panel)
|
|
1155
1183
|
self._panel = panel
|
|
1156
1184
|
self._render()
|
|
1185
|
+
if self._panel is None:
|
|
1186
|
+
# The hard-expire sweep retired the ENTIRE stack inside that
|
|
1187
|
+
# first _render (every draft past deadline, e.g. a wake after
|
|
1188
|
+
# hibernate) and _finish already closed the panel. Don't order
|
|
1189
|
+
# the dead panel back onto the screen.
|
|
1190
|
+
return
|
|
1157
1191
|
panel.orderFrontRegardless()
|
|
1158
1192
|
self._log_surface("presented")
|
|
1159
1193
|
if self._focus:
|
|
@@ -1371,7 +1405,41 @@ class _ReviewController(NSObject):
|
|
|
1371
1405
|
return eye
|
|
1372
1406
|
|
|
1373
1407
|
@objc.python_method
|
|
1408
|
+
@objc.python_method
|
|
1409
|
+
def _retire_expired_current(self):
|
|
1410
|
+
"""Stamp the CURRENT draft terminal as local_clock_expired and fire its
|
|
1411
|
+
decision, without advancing (callers own what happens next). The swept
|
|
1412
|
+
card was never reviewed, so per-card telemetry is cleared first: stale
|
|
1413
|
+
interactions/dwell from the previously shown card must not ride along
|
|
1414
|
+
on a machine decision."""
|
|
1415
|
+
d = self._drafts[self._idx]
|
|
1416
|
+
self._interactions = []
|
|
1417
|
+
self._card_shown_at = None
|
|
1418
|
+
self._selected_draft = None
|
|
1419
|
+
_log(
|
|
1420
|
+
f"auto-expired n={d.get('n')} cid={d.get('candidate_id')} "
|
|
1421
|
+
f"(card {self._idx + 1} of {len(self._drafts)})"
|
|
1422
|
+
)
|
|
1423
|
+
self._record(False, auto_expired=True)
|
|
1424
|
+
self._fire_decision()
|
|
1425
|
+
|
|
1374
1426
|
def _render(self):
|
|
1427
|
+
# Hard-expire sweep (2026-08-17, corner-card mode only — see the
|
|
1428
|
+
# AUTO_EXPIRE_IDLE_SECONDS block): retire every already-expired draft
|
|
1429
|
+
# at the front of the stack BEFORE building UI for it, so a stack
|
|
1430
|
+
# that sat through a sleep/hibernate never presents dead cards. No
|
|
1431
|
+
# idle guard here — nothing on screen is being yanked; this card was
|
|
1432
|
+
# about to be shown for the first time (or re-shown after a decision
|
|
1433
|
+
# on its predecessor).
|
|
1434
|
+
if self._host_view is None:
|
|
1435
|
+
while self._idx < len(self._drafts) and _draft_expired(
|
|
1436
|
+
self._drafts[self._idx]
|
|
1437
|
+
):
|
|
1438
|
+
self._retire_expired_current()
|
|
1439
|
+
self._idx += 1
|
|
1440
|
+
if self._idx >= len(self._drafts):
|
|
1441
|
+
self._finish()
|
|
1442
|
+
return
|
|
1375
1443
|
d = self._drafts[self._idx]
|
|
1376
1444
|
# Fresh card (not a card <-> reason-picker swap): reset telemetry.
|
|
1377
1445
|
if self._rendered_idx != self._idx:
|
|
@@ -1974,6 +2042,25 @@ class _ReviewController(NSObject):
|
|
|
1974
2042
|
return
|
|
1975
2043
|
try:
|
|
1976
2044
|
d = self._drafts[self._idx]
|
|
2045
|
+
# The on-screen card crossed its hard-expire deadline: retire it
|
|
2046
|
+
# (terminal, local_clock_expired) instead of letting it sit
|
|
2047
|
+
# approvable under an "expired" label — approving it is a silent
|
|
2048
|
+
# server-side no-op. Guarded so it never yanks a card someone is
|
|
2049
|
+
# actively working: requires AUTO_EXPIRE_IDLE_SECONDS with no
|
|
2050
|
+
# interaction AND an unedited draft body. While either guard
|
|
2051
|
+
# holds, the label keeps showing "expired"; the tick re-checks
|
|
2052
|
+
# every second and retires once the user goes idle. Corner-card
|
|
2053
|
+
# mode only (canvas tiles keep label-only behavior).
|
|
2054
|
+
if self._host_view is None and _draft_expired(d):
|
|
2055
|
+
idle_ok = (
|
|
2056
|
+
self._last_interaction_at is None
|
|
2057
|
+
or time.time() - self._last_interaction_at
|
|
2058
|
+
>= AUTO_EXPIRE_IDLE_SECONDS
|
|
2059
|
+
)
|
|
2060
|
+
if idle_ok and not self._draft_hand_edited(d):
|
|
2061
|
+
self._retire_expired_current()
|
|
2062
|
+
self._advance()
|
|
2063
|
+
return
|
|
1977
2064
|
stats = d.get("stats") or {}
|
|
1978
2065
|
text, urgent = _age_expiry_display(
|
|
1979
2066
|
stats.get("tweet_posted_at"), d.get("platform")
|
|
@@ -2236,7 +2323,25 @@ class _ReviewController(NSObject):
|
|
|
2236
2323
|
return d.get("reply_text") or ""
|
|
2237
2324
|
|
|
2238
2325
|
@objc.python_method
|
|
2239
|
-
def
|
|
2326
|
+
def _draft_hand_edited(self, d):
|
|
2327
|
+
"""True when the on-screen text no longer matches ANY of this draft's
|
|
2328
|
+
original bodies (reply_text plus each two-draft variant) — i.e. the
|
|
2329
|
+
reviewer has invested a hand edit. Used only as an auto-expire guard,
|
|
2330
|
+
so unknowable defaults to True (never yank what we can't verify)."""
|
|
2331
|
+
try:
|
|
2332
|
+
originals = {(d.get("reply_text") or "").strip()}
|
|
2333
|
+
for dd in d.get("drafts") or []:
|
|
2334
|
+
if isinstance(dd, dict):
|
|
2335
|
+
originals.add((dd.get("text") or "").strip())
|
|
2336
|
+
return (self._current_text() or "").strip() not in originals
|
|
2337
|
+
except Exception:
|
|
2338
|
+
return True
|
|
2339
|
+
|
|
2340
|
+
@objc.python_method
|
|
2341
|
+
def _record(
|
|
2342
|
+
self, approved, reject_category=None, reject_note=None, loved=False,
|
|
2343
|
+
auto_expired=False,
|
|
2344
|
+
):
|
|
2240
2345
|
d = self._drafts[self._idx]
|
|
2241
2346
|
# Two-draft cards: `orig` (what counts as "unedited") is whichever
|
|
2242
2347
|
# draft is CURRENTLY SELECTED, not always the plan's default
|
|
@@ -2311,6 +2416,13 @@ class _ReviewController(NSObject):
|
|
|
2311
2416
|
"drop_link": bool(approved and drop_link),
|
|
2312
2417
|
"reject_category": reject_category,
|
|
2313
2418
|
"reject_note": (reject_note or "").strip() or None,
|
|
2419
|
+
# Machine retirement, not a human judgment: the countdown
|
|
2420
|
+
# crossed zero (see the local hard-expire block above). The
|
|
2421
|
+
# store stamps terminal_reason=local_clock_expired and the
|
|
2422
|
+
# menu bar ships NO review event for it (an expiry says
|
|
2423
|
+
# nothing about draft quality; it must not reach the
|
|
2424
|
+
# feedback-digest -> learned_preferences rail).
|
|
2425
|
+
"auto_expired": bool(auto_expired),
|
|
2314
2426
|
"interactions": list(self._interactions),
|
|
2315
2427
|
"dwell_ms": self._dwell_ms(),
|
|
2316
2428
|
# Ride-along candidate context (from review_drafts) so the
|
|
@@ -2678,6 +2790,12 @@ def present_review(drafts, on_decision=None, on_complete=None, focus=False):
|
|
|
2678
2790
|
_active = _ReviewController.alloc().initWithDrafts_onDecision_onComplete_focus_(
|
|
2679
2791
|
drafts, on_decision, on_complete, focus
|
|
2680
2792
|
)
|
|
2793
|
+
if _active is not None and _active._panel is None:
|
|
2794
|
+
# The hard-expire sweep finished the whole stack during the initial
|
|
2795
|
+
# render (_finish set the module global to None, but this assignment
|
|
2796
|
+
# just overwrote it with the dead controller). Clear it so
|
|
2797
|
+
# extend/heal/status never operate on a closed surface.
|
|
2798
|
+
_active = None
|
|
2681
2799
|
|
|
2682
2800
|
|
|
2683
2801
|
def extend_active(drafts):
|
|
@@ -172,6 +172,17 @@ def _capture_msg(message, level="warning", _extra=None, **tags):
|
|
|
172
172
|
pass
|
|
173
173
|
|
|
174
174
|
|
|
175
|
+
def _log(msg):
|
|
176
|
+
"""Stderr breadcrumb in the menubar.err.log style (launchd routes stderr
|
|
177
|
+
there). Sentry-only reporting left the session-index prune invisible on
|
|
178
|
+
the box for a week (2026-11-04: every attempt failed on a missing module
|
|
179
|
+
and nothing local said so); anything a restart flow does on disk logs here."""
|
|
180
|
+
try:
|
|
181
|
+
print(f"[s4l-menubar] {msg}", file=sys.stderr, flush=True)
|
|
182
|
+
except Exception:
|
|
183
|
+
pass
|
|
184
|
+
|
|
185
|
+
|
|
175
186
|
def _registry_summary_for_capture():
|
|
176
187
|
"""The scheduled-task registry breakdown (scripts/scheduled_tasks_snapshot
|
|
177
188
|
build_summary) as a Sentry extra, so every needs-attention event carries the
|
|
@@ -636,6 +647,8 @@ class S4LMenuBar(rumps.App):
|
|
|
636
647
|
# a hitch every 5s tick.
|
|
637
648
|
self._resumed = False
|
|
638
649
|
self._loopback_check_due_at = 0.0
|
|
650
|
+
# Session-index prune on OBSERVED Claude downtime (see _tick).
|
|
651
|
+
self._pruned_this_downtime = False
|
|
639
652
|
# Periodic approved-backlog drain cadence (2026-07-17): the menubar is
|
|
640
653
|
# the single drainer now that the MCP boot-time drain is gone. 10 min
|
|
641
654
|
# keeps a transiently-failed approval's retry latency reasonable while
|
|
@@ -894,6 +907,7 @@ class S4LMenuBar(rumps.App):
|
|
|
894
907
|
except Exception:
|
|
895
908
|
user_data_dirs = None
|
|
896
909
|
self._quit_claude_and_wait()
|
|
910
|
+
self._prune_session_index()
|
|
897
911
|
self._relaunch_claude(user_data_dirs)
|
|
898
912
|
|
|
899
913
|
threading.Thread(target=work, daemon=True).start()
|
|
@@ -933,6 +947,7 @@ class S4LMenuBar(rumps.App):
|
|
|
933
947
|
# the currently-running code IS the current code; nothing to go
|
|
934
948
|
# stale against.
|
|
935
949
|
self._rewrite_scheduled_task_cwd()
|
|
950
|
+
self._prune_session_index()
|
|
936
951
|
self._relaunch_claude(user_data_dirs)
|
|
937
952
|
self._sig = None
|
|
938
953
|
# Verify rather than claim success unconditionally — the earlier,
|
|
@@ -1642,6 +1657,7 @@ class S4LMenuBar(rumps.App):
|
|
|
1642
1657
|
_capture(e, action="quit_stop_flag")
|
|
1643
1658
|
self._quit_claude_and_wait()
|
|
1644
1659
|
self._remove_scheduled_tasks()
|
|
1660
|
+
self._prune_session_index()
|
|
1645
1661
|
try:
|
|
1646
1662
|
os.remove(MENUBAR_PLIST)
|
|
1647
1663
|
except FileNotFoundError:
|
|
@@ -1690,6 +1706,30 @@ class S4LMenuBar(rumps.App):
|
|
|
1690
1706
|
verification on such machines.
|
|
1691
1707
|
"""
|
|
1692
1708
|
app_support = os.path.expanduser("~/Library/Application Support")
|
|
1709
|
+
# LIVE profile first (2026-09-28): on a multi-profile machine (account
|
|
1710
|
+
# rotator: Claude, Claude-mediar, Claude-mddy, ...) every profile keeps
|
|
1711
|
+
# its OWN copy of the extension, and "newest mtime" is simply the
|
|
1712
|
+
# profile that was updated most recently, not the one Claude is
|
|
1713
|
+
# running right now. The operator Mac sat on 1.7.7-rc.4 in the live
|
|
1714
|
+
# Claude-mediar profile for two months while every update landed in
|
|
1715
|
+
# Claude-mddy, and the updater kept reporting "already on latest".
|
|
1716
|
+
# Prefer the extension dir under a RUNNING Claude's --user-data-dir
|
|
1717
|
+
# (default profile == plain "Claude"); fall back to the newest-mtime
|
|
1718
|
+
# scan only when no Claude instance is running. Mirrors
|
|
1719
|
+
# scripts/s4l_box_update.sh; keep the two in sync.
|
|
1720
|
+
for udd in S4LMenuBar._claude_user_data_dirs():
|
|
1721
|
+
root = os.path.join(udd or os.path.join(app_support, "Claude"),
|
|
1722
|
+
"Claude Extensions")
|
|
1723
|
+
try:
|
|
1724
|
+
names = sorted(os.listdir(root))
|
|
1725
|
+
except OSError:
|
|
1726
|
+
continue
|
|
1727
|
+
for name in names:
|
|
1728
|
+
if not name.endswith("social-autoposter"):
|
|
1729
|
+
continue
|
|
1730
|
+
d = os.path.join(root, name)
|
|
1731
|
+
if os.path.exists(os.path.join(d, "manifest.json")):
|
|
1732
|
+
return d
|
|
1693
1733
|
best, best_mtime = None, -1.0
|
|
1694
1734
|
for root in glob.glob(os.path.join(app_support, "Claude*", "Claude Extensions")):
|
|
1695
1735
|
try:
|
|
@@ -1952,6 +1992,7 @@ class S4LMenuBar(rumps.App):
|
|
|
1952
1992
|
# this already-running (about to be replaced) process imported at
|
|
1953
1993
|
# ITS OWN startup — see _rewrite_scheduled_task_cwd_fresh's docstring.
|
|
1954
1994
|
self._rewrite_scheduled_task_cwd_fresh()
|
|
1995
|
+
self._prune_session_index()
|
|
1955
1996
|
if target:
|
|
1956
1997
|
# The graceful quit can eat minutes; restart the verify clock
|
|
1957
1998
|
# now that the host is actually down so UPDATE_VERIFY_GRACE_SEC
|
|
@@ -2160,6 +2201,94 @@ class S4LMenuBar(rumps.App):
|
|
|
2160
2201
|
except Exception:
|
|
2161
2202
|
pass
|
|
2162
2203
|
|
|
2204
|
+
@staticmethod
|
|
2205
|
+
def _claude_main_running():
|
|
2206
|
+
"""True while any Claude Desktop MAIN process is alive, by executable
|
|
2207
|
+
path suffix via ps (same approach as _claude_user_data_dirs). Helpers,
|
|
2208
|
+
renderers and claude-code CLI children have other paths."""
|
|
2209
|
+
try:
|
|
2210
|
+
out = subprocess.run(["ps", "-axo", "comm"], capture_output=True,
|
|
2211
|
+
text=True, timeout=10).stdout
|
|
2212
|
+
return any(l.rstrip().endswith("/Claude.app/Contents/MacOS/Claude")
|
|
2213
|
+
for l in out.splitlines())
|
|
2214
|
+
except Exception:
|
|
2215
|
+
return True # unknown: assume up, so we never prune a live app's store
|
|
2216
|
+
|
|
2217
|
+
_prune_lock = threading.Lock()
|
|
2218
|
+
|
|
2219
|
+
def _prune_session_index(self):
|
|
2220
|
+
"""Move archived s4l-worker session records out of Claude Desktop's
|
|
2221
|
+
session index. Run ONLY while Claude is DOWN, same rule as
|
|
2222
|
+
_rewrite_scheduled_task_cwd: the app loads the index at launch, keeps
|
|
2223
|
+
it in memory, and walks ALL of it (one stat per record's cwd) on
|
|
2224
|
+
every message of every session. Traced 2026-10-30: 32k records, 30k
|
|
2225
|
+
of them archived worker polls (~140/day), gave a 6 to 8 s UI freeze
|
|
2226
|
+
per message, twice per worker cycle; moving them out took it to zero.
|
|
2227
|
+
Delegates to scripts/session_index_prune.py::prune(), the single
|
|
2228
|
+
implementation (scripts/s4l_box_update.sh runs the same script).
|
|
2229
|
+
Best-effort: never raises. Non-reentrant: a restart flow and the
|
|
2230
|
+
_tick downtime hook can both fire in the same window; the second
|
|
2231
|
+
caller just skips (the first one's pass is complete and idempotent)."""
|
|
2232
|
+
if not self._prune_lock.acquire(blocking=False):
|
|
2233
|
+
return
|
|
2234
|
+
try:
|
|
2235
|
+
try:
|
|
2236
|
+
import session_index_prune
|
|
2237
|
+
r = session_index_prune.prune()
|
|
2238
|
+
except ImportError:
|
|
2239
|
+
# Not in S4L_REPO_DIR/scripts yet: the update that SHIPS the
|
|
2240
|
+
# script runs this hook before the new pipeline.tgz is
|
|
2241
|
+
# materialized (next server boot), exactly like the
|
|
2242
|
+
# scheduled-task self-heal (_rewrite_scheduled_task_cwd_fresh).
|
|
2243
|
+
# Run it from the just-downloaded bundle instead.
|
|
2244
|
+
r = self._prune_session_index_fresh()
|
|
2245
|
+
if r is None:
|
|
2246
|
+
_log("session_index_prune: script not installed "
|
|
2247
|
+
"(S4L_REPO_DIR/scripts or bundled pipeline.tgz); skipped")
|
|
2248
|
+
_capture_msg("S4L session index prune skipped: script not installed",
|
|
2249
|
+
phase="session_index_prune")
|
|
2250
|
+
return
|
|
2251
|
+
_log("session_index_prune: moved=%s skips_dropped=%s idx_moved=%s "
|
|
2252
|
+
"skipped_young=%s error=%s backup=%s" % (
|
|
2253
|
+
r.get("moved"), r.get("skips_dropped"), r.get("idx_moved"),
|
|
2254
|
+
r.get("skipped_young"), r.get("error"), r.get("backup_dir")))
|
|
2255
|
+
if r.get("moved") or r.get("error"):
|
|
2256
|
+
_capture_msg(
|
|
2257
|
+
"S4L pruned session index", level="info",
|
|
2258
|
+
phase="session_index_prune", _extra=r,
|
|
2259
|
+
)
|
|
2260
|
+
except Exception as e:
|
|
2261
|
+
_log(f"session_index_prune failed: {type(e).__name__}: {e}")
|
|
2262
|
+
_capture(e, action="session_index_prune")
|
|
2263
|
+
finally:
|
|
2264
|
+
self._prune_lock.release()
|
|
2265
|
+
|
|
2266
|
+
def _prune_session_index_fresh(self):
|
|
2267
|
+
"""Run scripts/session_index_prune.py as a subprocess from a fresh
|
|
2268
|
+
extract of the bundle's pipeline.tgz (see _fresh_pipeline_tmpdir).
|
|
2269
|
+
Returns the script's summary dict, or None when the bundle has no
|
|
2270
|
+
such script either (pre-prune bundle, or no .mcpb install at all)."""
|
|
2271
|
+
tmpd = self._fresh_pipeline_tmpdir()
|
|
2272
|
+
if not tmpd:
|
|
2273
|
+
return None
|
|
2274
|
+
try:
|
|
2275
|
+
script = os.path.join(tmpd, "package", "scripts", "session_index_prune.py")
|
|
2276
|
+
if not os.path.exists(script):
|
|
2277
|
+
return None
|
|
2278
|
+
py = os.environ.get("S4L_PYTHON") or sys.executable or "python3"
|
|
2279
|
+
r = subprocess.run([py, script], capture_output=True, text=True, timeout=600)
|
|
2280
|
+
try:
|
|
2281
|
+
return json.loads(r.stdout)
|
|
2282
|
+
except Exception:
|
|
2283
|
+
return {"ok": False, "moved": 0,
|
|
2284
|
+
"error": "fresh prune rc=%s: %s" % (r.returncode, (r.stderr or "")[-300:])}
|
|
2285
|
+
finally:
|
|
2286
|
+
try:
|
|
2287
|
+
import shutil
|
|
2288
|
+
shutil.rmtree(tmpd, ignore_errors=True)
|
|
2289
|
+
except Exception:
|
|
2290
|
+
pass
|
|
2291
|
+
|
|
2163
2292
|
def _fresh_pipeline_tmpdir(self):
|
|
2164
2293
|
"""Extract THIS UPDATE's embedded pipeline.tgz (already unpacked to
|
|
2165
2294
|
self._ext_dir() by the caller) into a throwaway temp dir and return
|
|
@@ -2282,6 +2411,7 @@ class S4LMenuBar(rumps.App):
|
|
|
2282
2411
|
# relaunch call site so this can never regress silently if that
|
|
2283
2412
|
# ever changes, rather than reasoning per call site about staleness.
|
|
2284
2413
|
self._rewrite_scheduled_task_cwd_fresh()
|
|
2414
|
+
self._prune_session_index()
|
|
2285
2415
|
self._relaunch_claude(user_data_dirs)
|
|
2286
2416
|
time.sleep(8) # let Claude reload the registry before we re-check
|
|
2287
2417
|
if not self._scheduled_task_cwd_needs_fix():
|
|
@@ -2678,6 +2808,22 @@ class S4LMenuBar(rumps.App):
|
|
|
2678
2808
|
pass
|
|
2679
2809
|
else:
|
|
2680
2810
|
self._resumed = False
|
|
2811
|
+
# Prune Claude's session index whenever Claude is OBSERVED down, not
|
|
2812
|
+
# only when one of our restart flows took it down (2026-10-30): a
|
|
2813
|
+
# manual Cmd+Q, an app-update relaunch or a crash is just as good a
|
|
2814
|
+
# window, and the prune only ever matters at the app's next launch.
|
|
2815
|
+
# Edge-triggered, once per down-window, checked every tick (one ps
|
|
2816
|
+
# call, ~10 ms; a manual quit-and-reopen can be under 15 s, so a
|
|
2817
|
+
# slower poll would miss it), in a thread (the scan reads every
|
|
2818
|
+
# record). ps rather than pgrep: BSD pgrep hides the caller's own
|
|
2819
|
+
# ancestors, so from anything Claude spawned (tests, a Claude-run
|
|
2820
|
+
# shell) `pgrep -x Claude` reports the host app as absent.
|
|
2821
|
+
if self._claude_main_running():
|
|
2822
|
+
self._pruned_this_downtime = False
|
|
2823
|
+
elif not self._pruned_this_downtime:
|
|
2824
|
+
self._pruned_this_downtime = True
|
|
2825
|
+
threading.Thread(target=self._prune_session_index, daemon=True,
|
|
2826
|
+
name="s4l-session-index-prune").start()
|
|
2681
2827
|
# Status-item visibility telemetry (60s-throttled inside; see __init__).
|
|
2682
2828
|
self._icon_watch_tick(now)
|
|
2683
2829
|
# The activity spinner owns the TITLE while a tool runs (we don't fight it at
|
|
@@ -3568,7 +3714,12 @@ class S4LMenuBar(rumps.App):
|
|
|
3568
3714
|
# built to avoid (2026-07-16 user report). Every other consequence of
|
|
3569
3715
|
# a decision (review event, posting-queue enqueue) still happens
|
|
3570
3716
|
# here, per draft, same as the normal single-card path.
|
|
3571
|
-
|
|
3717
|
+
# Auto-expiries (card countdown crossed the hard-expire deadline, see
|
|
3718
|
+
# s4l_card's local hard-expire block) are machine retirements, not
|
|
3719
|
+
# judgments: like Discard All, they must never reach the review-events
|
|
3720
|
+
# -> feedback-digest -> learned_preferences rail.
|
|
3721
|
+
if not decision.get("auto_expired"):
|
|
3722
|
+
self._ship_review_event(batch, decision)
|
|
3572
3723
|
if not decision.get("approved"):
|
|
3573
3724
|
n = decision.get("n")
|
|
3574
3725
|
# Durable local record FIRST, mirroring the approve branch below.
|
|
@@ -3585,6 +3736,15 @@ class S4LMenuBar(rumps.App):
|
|
|
3585
3736
|
except Exception as e:
|
|
3586
3737
|
_capture(e, phase="reject_stamp_decision")
|
|
3587
3738
|
|
|
3739
|
+
# Auto-expiries stop at the durable store stamp: no loopback call.
|
|
3740
|
+
# The backend row's own Phase 0 freshness gate flips it
|
|
3741
|
+
# status='expired' on the next cycle (same 6h/48h clock the card
|
|
3742
|
+
# counted down), and the loopback needs Claude Desktop up — which
|
|
3743
|
+
# is exactly what's NOT guaranteed in the sleep/wake and
|
|
3744
|
+
# dead-producer scenarios this path exists for.
|
|
3745
|
+
if decision.get("auto_expired"):
|
|
3746
|
+
return
|
|
3747
|
+
|
|
3588
3748
|
def _persist_reject():
|
|
3589
3749
|
try:
|
|
3590
3750
|
st.approve_drafts(batch, reject=[n], timeout=30)
|
|
@@ -3679,7 +3839,19 @@ class S4LMenuBar(rumps.App):
|
|
|
3679
3839
|
"Review sooner from the S4L menu.",
|
|
3680
3840
|
)
|
|
3681
3841
|
elif not any(d.get("approved") for d in decisions):
|
|
3682
|
-
|
|
3842
|
+
n_exp = sum(1 for d in decisions if d.get("auto_expired"))
|
|
3843
|
+
if n_exp and n_exp == len(decisions):
|
|
3844
|
+
# The whole stack self-retired (typically a wake after
|
|
3845
|
+
# sleep/hibernate): say what happened instead of the generic
|
|
3846
|
+
# line, or the vanished cards look like a bug.
|
|
3847
|
+
plural = "s" if n_exp != 1 else ""
|
|
3848
|
+
self._notify(
|
|
3849
|
+
"S4L",
|
|
3850
|
+
f"Discarded {n_exp} stale draft{plural} — past the "
|
|
3851
|
+
"freshness window, too old to post.",
|
|
3852
|
+
)
|
|
3853
|
+
else:
|
|
3854
|
+
self._notify("S4L", "No drafts approved — nothing posted.")
|
|
3683
3855
|
|
|
3684
3856
|
def _discard_all_pending(self, _=None):
|
|
3685
3857
|
"""Bulk-discard every pending draft card: rejected with NO reason,
|
package/mcp/menubar/s4l_state.py
CHANGED
|
@@ -895,6 +895,11 @@ def store_stamp_decision(batch, decision):
|
|
|
895
895
|
# None on single-draft cards. Durable locally so the choice
|
|
896
896
|
# survives even if the review-events flush never lands.
|
|
897
897
|
"draft_choice": decision.get("draft_choice"),
|
|
898
|
+
# Machine retirement (card countdown crossed the Phase 0 hard-
|
|
899
|
+
# expire deadline with no cycle around to prune it — sleep/wake,
|
|
900
|
+
# dead producer). Distinct from a human reject in terminal_reason
|
|
901
|
+
# below so dashboards/audits never count it as a judgment.
|
|
902
|
+
"auto_expired": bool(decision.get("auto_expired")),
|
|
898
903
|
"decided_at": time_iso(),
|
|
899
904
|
}
|
|
900
905
|
if decision.get("approved"):
|
|
@@ -903,7 +908,11 @@ def store_stamp_decision(batch, decision):
|
|
|
903
908
|
c.pop("post_error", None)
|
|
904
909
|
else:
|
|
905
910
|
c["terminal"] = True
|
|
906
|
-
c["terminal_reason"] =
|
|
911
|
+
c["terminal_reason"] = (
|
|
912
|
+
"local_clock_expired"
|
|
913
|
+
if decision.get("auto_expired")
|
|
914
|
+
else "human_rejected"
|
|
915
|
+
)
|
|
907
916
|
c["decision"] = payload
|
|
908
917
|
return True
|
|
909
918
|
|
package/mcp/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@m13v/s4l-mcp",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.12-rc.10",
|
|
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.
|
|
3
|
+
"version": "1.7.12-rc.10",
|
|
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",
|
|
@@ -41,6 +41,23 @@
|
|
|
41
41
|
"!scripts/_gsc_roi_query.py",
|
|
42
42
|
"!scripts/batch_send_dms.py",
|
|
43
43
|
"!scripts/finalize_post_*.py",
|
|
44
|
+
"!scripts/insert_[0-9]*.py",
|
|
45
|
+
"!scripts/insert[0-9]*.py",
|
|
46
|
+
"!scripts/ins[0-9]*.py",
|
|
47
|
+
"!scripts/tlh_pick_*.py",
|
|
48
|
+
"!scripts/tlh_freshness_*.py",
|
|
49
|
+
"!scripts/tlh_fresh.py",
|
|
50
|
+
"!scripts/tlh_stale.py",
|
|
51
|
+
"!scripts/fresh[0-9]*.py",
|
|
52
|
+
"!scripts/hist[0-9]*.py",
|
|
53
|
+
"!scripts/q[0-9]*.py",
|
|
54
|
+
"!scripts/show[0-9]*.py",
|
|
55
|
+
"!scripts/stale[0-9]*.py",
|
|
56
|
+
"!scripts/stale_[0-9]*.py",
|
|
57
|
+
"!scripts/stale_classes_*.py",
|
|
58
|
+
"!scripts/stale_clips_*.py",
|
|
59
|
+
"!scripts/r[0-9]*.py",
|
|
60
|
+
"!scripts/w[0-9]*.py",
|
|
44
61
|
"!scripts/insert_li_notifs.py",
|
|
45
62
|
"!scripts/li_notif_scan_process.py",
|
|
46
63
|
"!scripts/phase_d_edit.py",
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import os,psycopg2
|
|
2
|
+
from dotenv import load_dotenv
|
|
3
|
+
load_dotenv(os.path.expanduser('~/social-autoposter/.env'))
|
|
4
|
+
c=psycopg2.connect(os.environ['DATABASE_URL']).cursor()
|
|
5
|
+
c.execute("select distinct metadata->>'theme_angle' from media_posts")
|
|
6
|
+
print(' '.join(sorted(r[0] or '' for r in c.fetchall())))
|
|
7
|
+
c.execute("select distinct metadata->>'engagement_style' from media_posts")
|
|
8
|
+
print([r[0] for r in c.fetchall()])
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Minimal CDP driver for the harness Chrome on port 9556.
|
|
3
|
+
Usage:
|
|
4
|
+
cdp_drive.py nav <url> -> navigate active page tab, print final href
|
|
5
|
+
cdp_drive.py href -> print current href of active page tab
|
|
6
|
+
cdp_drive.py shot <path> -> screenshot active page tab to path
|
|
7
|
+
cdp_drive.py click <x> <y> -> dispatch mouse click at viewport coords
|
|
8
|
+
cdp_drive.py eval <expr> -> evaluate JS expression, print JSON result
|
|
9
|
+
"""
|
|
10
|
+
import sys, json, time, base64
|
|
11
|
+
import urllib.request
|
|
12
|
+
import websocket # websocket-client
|
|
13
|
+
|
|
14
|
+
PORT = 9556
|
|
15
|
+
BASE = f"http://localhost:{PORT}"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def list_tabs():
|
|
19
|
+
with urllib.request.urlopen(f"{BASE}/json/list", timeout=10) as r:
|
|
20
|
+
return json.load(r)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def active_page():
|
|
24
|
+
tabs = list_tabs()
|
|
25
|
+
pages = [t for t in tabs if t.get("type") == "page" and t.get("webSocketDebuggerUrl")]
|
|
26
|
+
# prefer a linkedin tab, else first page
|
|
27
|
+
for t in pages:
|
|
28
|
+
if "linkedin.com" in (t.get("url") or ""):
|
|
29
|
+
return t
|
|
30
|
+
if pages:
|
|
31
|
+
return pages[0]
|
|
32
|
+
raise RuntimeError("no page tab")
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class CDP:
|
|
36
|
+
def __init__(self, ws_url):
|
|
37
|
+
self.ws = websocket.create_connection(
|
|
38
|
+
ws_url, max_size=None, timeout=60, suppress_origin=True
|
|
39
|
+
)
|
|
40
|
+
self._id = 0
|
|
41
|
+
|
|
42
|
+
def cmd(self, method, **params):
|
|
43
|
+
self._id += 1
|
|
44
|
+
mid = self._id
|
|
45
|
+
self.ws.send(json.dumps({"id": mid, "method": method, "params": params}))
|
|
46
|
+
while True:
|
|
47
|
+
msg = json.loads(self.ws.recv())
|
|
48
|
+
if msg.get("id") == mid:
|
|
49
|
+
if "error" in msg:
|
|
50
|
+
raise RuntimeError(msg["error"])
|
|
51
|
+
return msg.get("result", {})
|
|
52
|
+
|
|
53
|
+
def close(self):
|
|
54
|
+
try:
|
|
55
|
+
self.ws.close()
|
|
56
|
+
except Exception:
|
|
57
|
+
pass
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def get_href(c):
|
|
61
|
+
r = c.cmd("Runtime.evaluate", expression="location.href", returnByValue=True)
|
|
62
|
+
return r.get("result", {}).get("value")
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def main():
|
|
66
|
+
action = sys.argv[1]
|
|
67
|
+
tab = active_page()
|
|
68
|
+
c = CDP(tab["webSocketDebuggerUrl"])
|
|
69
|
+
try:
|
|
70
|
+
if action in ("nav", "click"):
|
|
71
|
+
c.cmd("Page.enable")
|
|
72
|
+
if action == "nav":
|
|
73
|
+
url = sys.argv[2]
|
|
74
|
+
c.cmd("Page.navigate", url=url)
|
|
75
|
+
time.sleep(6)
|
|
76
|
+
print(get_href(c))
|
|
77
|
+
elif action == "href":
|
|
78
|
+
print(get_href(c))
|
|
79
|
+
elif action == "shot":
|
|
80
|
+
path = sys.argv[2]
|
|
81
|
+
r = c.cmd("Page.captureScreenshot", format="png")
|
|
82
|
+
with open(path, "wb") as f:
|
|
83
|
+
f.write(base64.b64decode(r["data"]))
|
|
84
|
+
print(path)
|
|
85
|
+
elif action == "click":
|
|
86
|
+
x = float(sys.argv[2]); y = float(sys.argv[3])
|
|
87
|
+
c.cmd("Input.dispatchMouseEvent", type="mousePressed", x=x, y=y, button="left", clickCount=1)
|
|
88
|
+
c.cmd("Input.dispatchMouseEvent", type="mouseReleased", x=x, y=y, button="left", clickCount=1)
|
|
89
|
+
time.sleep(4)
|
|
90
|
+
print(get_href(c))
|
|
91
|
+
elif action == "eval":
|
|
92
|
+
expr = sys.argv[2]
|
|
93
|
+
r = c.cmd("Runtime.evaluate", expression=expr, returnByValue=True, awaitPromise=True)
|
|
94
|
+
print(json.dumps(r.get("result", {}).get("value")))
|
|
95
|
+
else:
|
|
96
|
+
print("unknown action", file=sys.stderr); sys.exit(2)
|
|
97
|
+
finally:
|
|
98
|
+
c.close()
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
if __name__ == "__main__":
|
|
102
|
+
main()
|