@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.
- package/mcp/dist/index.js +354 -24
- package/mcp/dist/panel.html +42 -31
- package/mcp/dist/product-link.html +1 -1
- package/mcp/dist/telemetry.js +80 -3
- package/mcp/dist/version.json +2 -2
- package/mcp/manifest.json +9 -1
- package/mcp/menubar/dashboard_server.py +12 -0
- package/mcp/menubar/s4l_card.py +539 -80
- package/mcp/menubar/s4l_menubar.py +299 -191
- package/mcp/menubar/s4l_state.py +228 -33
- package/mcp/package.json +1 -1
- package/package.json +4 -1
- package/scripts/active_users.py +3 -6
- package/scripts/autopilot_stall_watch.py +200 -16
- package/scripts/claude_job.py +6 -0
- package/scripts/feedback_digest.py +34 -6
- package/scripts/harness_overlay.py +45 -0
- package/scripts/identity.py +26 -0
- package/scripts/learned_preferences.py +241 -32
- package/scripts/link_tail.py +167 -91
- package/scripts/mark_event.py +128 -0
- package/scripts/memory_snapshot.py +27 -0
- package/scripts/merge_review_queue.py +42 -16
- package/scripts/pick_twitter_thread_target.py +1 -1
- package/scripts/s4l_mode.py +7 -5
- package/scripts/scan_pii.py +9 -1
- package/scripts/schedule_state.py +146 -69
- package/scripts/scheduled_task_selfheal.py +276 -0
- package/scripts/scheduled_tasks_snapshot.py +107 -0
- package/scripts/send_gmail_report.py +76 -0
- package/scripts/sentry_digest.py +81 -189
- package/scripts/sentry_init.py +43 -15
- package/scripts/snapshot.py +20 -0
- package/scripts/twitter_post_plan.py +39 -13
- package/skill/dm-outreach-twitter.sh +19 -0
- package/skill/engage-twitter.sh +27 -0
- package/skill/run-draft-and-publish.sh +13 -12
- package/skill/run-linkedin.sh +9 -1
- package/skill/run-twitter-cycle.sh +199 -27
- package/skill/sentry-digest.sh +125 -12
|
@@ -42,6 +42,7 @@ import time
|
|
|
42
42
|
# SAPS_->S4L_ env mirror (brand rename 2026-07-03): old launchd plists and
|
|
43
43
|
# scheduled-task prompts still export SAPS_*; this process reads S4L_*.
|
|
44
44
|
import s4l_env # noqa: E402 (lives next to this file in scripts/)
|
|
45
|
+
import identity # noqa: E402 (lives next to this file in scripts/)
|
|
45
46
|
|
|
46
47
|
s4l_env.mirror()
|
|
47
48
|
|
|
@@ -141,6 +142,45 @@ def _recent_rate_limit(window: int = 1200) -> bool:
|
|
|
141
142
|
return False
|
|
142
143
|
|
|
143
144
|
|
|
145
|
+
BATCH_PROGRESSION_MIN_BATCHES = 5
|
|
146
|
+
BATCH_PROGRESSED_PHASES = {"phase2b-gen", "phase2b-post"}
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def _recent_batches_not_progressing(min_batches: int = BATCH_PROGRESSION_MIN_BATCHES) -> bool:
|
|
150
|
+
"""True if the last `min_batches` twitter_batches for THIS install ALL failed
|
|
151
|
+
to reach phase2b-gen (real draft generation) or later. A second, independent
|
|
152
|
+
detection layer: the queue's consecutive_timeouts counter is one level
|
|
153
|
+
removed from the actual product outcome (did a batch progress). During the
|
|
154
|
+
Karol 2026-07-07 investigation the DB showed the stall the whole time — 46
|
|
155
|
+
consecutive batches dying at phase2b-prep — while this watchdog's other
|
|
156
|
+
signals took hours longer to latch. Requires network (via http_api); any
|
|
157
|
+
failure (offline, endpoint missing, not enough batch history yet) returns
|
|
158
|
+
False so this signal can only ever ADD confidence, never false-positive on
|
|
159
|
+
its own from a transient API hiccup.
|
|
160
|
+
|
|
161
|
+
NOTE: catches BaseException, not just Exception — scripts/http_api.py's
|
|
162
|
+
_request() deliberately raises SystemExit (not a plain Exception; it
|
|
163
|
+
inherits from BaseException) on a terminal 4xx/5xx, which is correct for
|
|
164
|
+
most one-shot pipeline callers but would silently kill this entire
|
|
165
|
+
best-effort watchdog process if left uncaught here. Caught by testing this
|
|
166
|
+
against a not-yet-deployed endpoint version during development."""
|
|
167
|
+
try:
|
|
168
|
+
repo = os.environ.get("S4L_REPO_DIR")
|
|
169
|
+
if repo:
|
|
170
|
+
scripts_dir = os.path.join(repo, "scripts")
|
|
171
|
+
if scripts_dir not in sys.path:
|
|
172
|
+
sys.path.insert(0, scripts_dir)
|
|
173
|
+
import http_api # noqa: E402
|
|
174
|
+
|
|
175
|
+
resp = http_api.api_get("/api/v1/twitter-batches", {"list": "1", "limit": str(min_batches)})
|
|
176
|
+
batches = (resp or {}).get("batches") or []
|
|
177
|
+
if len(batches) < min_batches:
|
|
178
|
+
return False # not enough history yet to conclude a stall
|
|
179
|
+
return all((b or {}).get("current_phase") not in BATCH_PROGRESSED_PHASES for b in batches)
|
|
180
|
+
except BaseException:
|
|
181
|
+
return False
|
|
182
|
+
|
|
183
|
+
|
|
144
184
|
def _oldest_pending_age() -> float | None:
|
|
145
185
|
"""Seconds since the oldest unclaimed pending draft job was written, or None
|
|
146
186
|
if nothing is pending (idle queue). The FAST signal: catches a fresh stall
|
|
@@ -162,6 +202,25 @@ def _oldest_pending_age() -> float | None:
|
|
|
162
202
|
return time.time() - oldest
|
|
163
203
|
|
|
164
204
|
|
|
205
|
+
def _pending_count() -> int:
|
|
206
|
+
"""Number of unclaimed pending draft jobs across all types. Cheap: same glob
|
|
207
|
+
shape as _oldest_pending_age, just counted instead of min'd. Feeds the
|
|
208
|
+
queue_health_samples row (see _report_queue_health_sample)."""
|
|
209
|
+
pend_root = os.path.join(_queue_root(), "pending")
|
|
210
|
+
n = 0
|
|
211
|
+
for sub in glob.glob(os.path.join(pend_root, "*")):
|
|
212
|
+
for jf in glob.glob(os.path.join(sub, "*.json")):
|
|
213
|
+
if not jf.endswith(".tmp"):
|
|
214
|
+
n += 1
|
|
215
|
+
return n
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
def _running_count() -> int:
|
|
219
|
+
"""Number of claimed-but-unfinished jobs. See _pending_count."""
|
|
220
|
+
run_root = os.path.join(_queue_root(), "running")
|
|
221
|
+
return sum(1 for jf in glob.glob(os.path.join(run_root, "*.json")) if not jf.endswith(".tmp"))
|
|
222
|
+
|
|
223
|
+
|
|
165
224
|
def _oldest_running_age() -> float | None:
|
|
166
225
|
"""Seconds since the oldest CLAIMED-but-unfinished job was written, or None if
|
|
167
226
|
nothing is in flight. A worker claims by moving a job pending/ -> running/ and
|
|
@@ -217,18 +276,97 @@ def _sentry():
|
|
|
217
276
|
return sentry_init
|
|
218
277
|
|
|
219
278
|
|
|
279
|
+
def _report_recovery(total_duration_s: float, paged_duration_s: float | None) -> None:
|
|
280
|
+
"""Log a recovery milestone (with duration) once per stall episode that
|
|
281
|
+
actually paged. Previously this had to be hand-reconstructed per incident by
|
|
282
|
+
diffing DB/log timestamps after the fact (see the Karol 2026-07-07
|
|
283
|
+
update-orphan investigation); this makes it a first-class, queryable Sentry
|
|
284
|
+
event so incident severity is trackable fleet-wide over time instead of
|
|
285
|
+
per-investigation. Only fires for episodes that crossed ALERT_AFTER — a
|
|
286
|
+
stall that self-clears before paging is normal jitter, not an incident."""
|
|
287
|
+
try:
|
|
288
|
+
sentry = _sentry()
|
|
289
|
+
sentry.init()
|
|
290
|
+
total_min = total_duration_s / 60.0
|
|
291
|
+
paged_str = f"{paged_duration_s / 60.0:.1f} min" if paged_duration_s is not None else "n/a"
|
|
292
|
+
sentry.capture_message(
|
|
293
|
+
"social-autoposter autopilot recovered: draft jobs draining again "
|
|
294
|
+
f"after {total_min:.1f} min stalled ({paged_str} since it paged).",
|
|
295
|
+
level="info",
|
|
296
|
+
tags={"component": "autopilot", "issue": "stall_recovered"},
|
|
297
|
+
extra={
|
|
298
|
+
"stall_total_duration_seconds": round(total_duration_s, 1),
|
|
299
|
+
"stall_paged_duration_seconds": (
|
|
300
|
+
round(paged_duration_s, 1) if paged_duration_s is not None else None
|
|
301
|
+
),
|
|
302
|
+
},
|
|
303
|
+
)
|
|
304
|
+
sentry.flush()
|
|
305
|
+
except Exception:
|
|
306
|
+
sys.stderr.write(f"[stall-watch] recovered after {total_duration_s:.0f}s but Sentry report failed\n")
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
def _report_queue_health_sample(
|
|
310
|
+
pending: int,
|
|
311
|
+
running: int,
|
|
312
|
+
timeouts: int,
|
|
313
|
+
age: float | None,
|
|
314
|
+
run_age: float | None,
|
|
315
|
+
stalled: bool,
|
|
316
|
+
batches_stuck: bool,
|
|
317
|
+
) -> None:
|
|
318
|
+
"""Best-effort POST of one queue_health_samples row, on EVERY tick (not
|
|
319
|
+
just while stalled) — a continuous baseline is the point: it's what makes
|
|
320
|
+
"was this box actually healthy at time T" a one-line SQL query instead of
|
|
321
|
+
absence-of-evidence. See migrations/2026-07-07-queue-health-samples.sql.
|
|
322
|
+
|
|
323
|
+
Catches BaseException, not just Exception — see _recent_batches_not_progressing
|
|
324
|
+
for why (http_api._request raises SystemExit on a terminal 4xx/5xx, which
|
|
325
|
+
must never be allowed to kill this watchdog process)."""
|
|
326
|
+
try:
|
|
327
|
+
repo = os.environ.get("S4L_REPO_DIR")
|
|
328
|
+
if repo:
|
|
329
|
+
scripts_dir = os.path.join(repo, "scripts")
|
|
330
|
+
if scripts_dir not in sys.path:
|
|
331
|
+
sys.path.insert(0, scripts_dir)
|
|
332
|
+
import http_api # noqa: E402
|
|
333
|
+
|
|
334
|
+
http_api.api_post(
|
|
335
|
+
"/api/v1/queue-health-samples",
|
|
336
|
+
{
|
|
337
|
+
"pending": pending,
|
|
338
|
+
"running": running,
|
|
339
|
+
"consecutive_timeouts": timeouts,
|
|
340
|
+
"oldest_pending_age_s": int(age) if age is not None else None,
|
|
341
|
+
"oldest_running_age_s": int(run_age) if run_age is not None else None,
|
|
342
|
+
"stalled": stalled,
|
|
343
|
+
"batches_stuck": batches_stuck,
|
|
344
|
+
},
|
|
345
|
+
)
|
|
346
|
+
except BaseException:
|
|
347
|
+
pass
|
|
348
|
+
|
|
349
|
+
|
|
220
350
|
def main() -> int:
|
|
221
351
|
age = _oldest_pending_age()
|
|
222
352
|
run_age = _oldest_running_age()
|
|
223
353
|
timeouts = _consecutive_timeouts()
|
|
224
|
-
|
|
354
|
+
configured = _autopilot_configured()
|
|
355
|
+
# batches_stuck is deliberately computed unconditionally (not short-circuited
|
|
356
|
+
# by the other signals) — it's a genuinely independent, outcome-level
|
|
357
|
+
# backstop, not a cheaper proxy for the same thing. It's what would have
|
|
358
|
+
# caught the Karol 2026-07-07 stall immediately instead of hours later.
|
|
359
|
+
batches_stuck = configured and _recent_batches_not_progressing()
|
|
360
|
+
# Four complementary signals, OR'd; all gated on the autopilot actually being
|
|
225
361
|
# configured here. (1) durable producer drain latch, (2) fast pending-age (job
|
|
226
|
-
# never claimed), (3) running-age (job claimed then wedged mid-run)
|
|
227
|
-
# only one that catches a worker dying after it picked
|
|
228
|
-
|
|
362
|
+
# never claimed), (3) running-age (job claimed then wedged mid-run) — (3) is
|
|
363
|
+
# the only one of the first three that catches a worker dying after it picked
|
|
364
|
+
# up the job — (4) batches_stuck, the outcome-level backstop above.
|
|
365
|
+
stalled = configured and (
|
|
229
366
|
timeouts >= 1
|
|
230
367
|
or (age is not None and age > STALL_SECONDS)
|
|
231
368
|
or (run_age is not None and run_age > RUNNING_STALL_SECONDS)
|
|
369
|
+
or batches_stuck
|
|
232
370
|
)
|
|
233
371
|
# A rate-limit stall is expected and self-heals at the quota reset — never page
|
|
234
372
|
# for it (and re-arm can't fix it). Treat it as "not an actionable stall" so the
|
|
@@ -236,45 +374,84 @@ def main() -> int:
|
|
|
236
374
|
if stalled and _recent_rate_limit():
|
|
237
375
|
stalled = False
|
|
238
376
|
|
|
377
|
+
# Record this tick regardless of outcome — see _report_queue_health_sample.
|
|
378
|
+
_report_queue_health_sample(
|
|
379
|
+
_pending_count(), _running_count(), timeouts, age, run_age, stalled, batches_stuck
|
|
380
|
+
)
|
|
381
|
+
|
|
239
382
|
st = _read_state()
|
|
240
383
|
consecutive = int(st.get("consecutive", 0))
|
|
241
384
|
alerted = bool(st.get("alerted", False))
|
|
385
|
+
# first_seen_at: first check this episode looked stalled at all (predates
|
|
386
|
+
# paging by ALERT_AFTER checks). alerted_at: the single moment we paged.
|
|
387
|
+
# Both are stamped once and carried forward untouched for the rest of the
|
|
388
|
+
# episode — NOT refreshed every check — so they measure the episode's
|
|
389
|
+
# start, not "last time we saw it stalled".
|
|
390
|
+
first_seen_at = st.get("first_seen_at")
|
|
391
|
+
alerted_at = st.get("alerted_at")
|
|
242
392
|
|
|
243
393
|
if not stalled:
|
|
244
394
|
# Recovered (or never stalled) -> reset the episode so the next stall pages.
|
|
245
395
|
if consecutive or alerted:
|
|
396
|
+
if alerted and first_seen_at:
|
|
397
|
+
total_duration = time.time() - float(first_seen_at)
|
|
398
|
+
paged_duration = (time.time() - float(alerted_at)) if alerted_at else None
|
|
399
|
+
_report_recovery(total_duration, paged_duration)
|
|
246
400
|
_write_state({"consecutive": 0, "alerted": False})
|
|
247
401
|
return 0
|
|
248
402
|
|
|
249
403
|
consecutive += 1
|
|
404
|
+
if first_seen_at is None:
|
|
405
|
+
first_seen_at = time.time()
|
|
250
406
|
age_str = f"{int(age)}s" if age is not None else "n/a (between cycles)"
|
|
251
407
|
run_age_str = f"{int(run_age)}s" if run_age is not None else "n/a (none in flight)"
|
|
252
|
-
# Distinguish the
|
|
253
|
-
# but-wedged job (running-age) is a mid-run worker death,
|
|
408
|
+
# Distinguish the shapes so the alert points at the right cause: a claimed-
|
|
409
|
+
# but-wedged job (running-age) is a mid-run worker death, batches_stuck is
|
|
410
|
+
# the outcome-level backstop firing independently of the queue signals, and
|
|
411
|
+
# the fallback is the classic orphaned-routine case.
|
|
254
412
|
wedged_inflight = run_age is not None and run_age > RUNNING_STALL_SECONDS
|
|
255
413
|
if consecutive >= ALERT_AFTER and not alerted:
|
|
256
414
|
try:
|
|
257
415
|
sentry = _sentry()
|
|
258
416
|
sentry.init()
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
417
|
+
if wedged_inflight:
|
|
418
|
+
cause = (
|
|
419
|
+
"a worker claimed a draft job and then died mid-run (claude -p child "
|
|
420
|
+
"never came up / crashed)"
|
|
421
|
+
)
|
|
422
|
+
stall_shape = "inflight_wedged"
|
|
423
|
+
elif batches_stuck:
|
|
424
|
+
cause = (
|
|
425
|
+
f"last {BATCH_PROGRESSION_MIN_BATCHES} twitter_batches all failed to "
|
|
426
|
+
"reach phase2b-gen — drafting is not actually happening even if the "
|
|
427
|
+
"queue-level counters look ambiguous"
|
|
428
|
+
)
|
|
429
|
+
stall_shape = "batches_not_progressing"
|
|
430
|
+
else:
|
|
431
|
+
cause = "scheduled-task routines likely orphaned — Claude Desktop account change?"
|
|
432
|
+
stall_shape = "not_draining"
|
|
433
|
+
# Our own staging/QA/dev boxes (identity.is_internal_install) get set
|
|
434
|
+
# up and rebuilt with nobody actively feeding the queue, which looks
|
|
435
|
+
# identical to a real stall on the signals above. Downgrade those to
|
|
436
|
+
# warning instead of error so they don't page as a customer incident
|
|
437
|
+
# (the digest only scans error/fatal) while still leaving a Sentry
|
|
438
|
+
# record if we ever need to look one up by hand.
|
|
439
|
+
is_internal = identity.is_internal_install()
|
|
265
440
|
sentry.capture_message(
|
|
266
441
|
"social-autoposter autopilot stalled: draft jobs are not being "
|
|
267
442
|
f"drained ({cause}). producer consecutive timeouts={timeouts}, "
|
|
268
443
|
f"oldest pending job age={age_str}, oldest in-flight (running) job "
|
|
269
444
|
f"age={run_age_str}, sustained {consecutive} checks.",
|
|
270
|
-
level="error",
|
|
445
|
+
level=("warning" if is_internal else "error"),
|
|
271
446
|
tags={
|
|
272
447
|
"component": "autopilot",
|
|
273
448
|
"issue": "stall",
|
|
274
|
-
"stall_shape":
|
|
449
|
+
"stall_shape": stall_shape,
|
|
275
450
|
"consecutive_timeouts": str(timeouts),
|
|
276
451
|
"oldest_pending_age_s": str(int(age)) if age is not None else "",
|
|
277
452
|
"oldest_running_age_s": str(int(run_age)) if run_age is not None else "",
|
|
453
|
+
"batches_stuck": str(batches_stuck),
|
|
454
|
+
"internal_install": str(is_internal),
|
|
278
455
|
},
|
|
279
456
|
)
|
|
280
457
|
sentry.flush()
|
|
@@ -285,8 +462,15 @@ def main() -> int:
|
|
|
285
462
|
f"pending_age={age_str}, running_age={run_age_str}) but Sentry report failed\n"
|
|
286
463
|
)
|
|
287
464
|
alerted = True
|
|
288
|
-
|
|
289
|
-
|
|
465
|
+
alerted_at = time.time()
|
|
466
|
+
|
|
467
|
+
_write_state({
|
|
468
|
+
"consecutive": consecutive,
|
|
469
|
+
"alerted": alerted,
|
|
470
|
+
"first_seen_at": first_seen_at,
|
|
471
|
+
"alerted_at": alerted_at,
|
|
472
|
+
"at": time.time(),
|
|
473
|
+
})
|
|
290
474
|
return 0
|
|
291
475
|
|
|
292
476
|
|
package/scripts/claude_job.py
CHANGED
|
@@ -920,6 +920,12 @@ def _attempt_claim(ns, qtype: str) -> bool:
|
|
|
920
920
|
|
|
921
921
|
def cmd_next(ns) -> int:
|
|
922
922
|
_apply_state_dir_override(ns)
|
|
923
|
+
# S4L paused (mcp/src/index.ts pauseAutopilot): report no work instead of
|
|
924
|
+
# claiming a job, so an already-queued draft can't drain/post while paused
|
|
925
|
+
# even though the scheduled task worker still fires on its own cadence.
|
|
926
|
+
if os.path.exists(os.path.join(state_dir(), "paused.flag")):
|
|
927
|
+
print(json.dumps({}))
|
|
928
|
+
return 0
|
|
923
929
|
qtype = ns.type
|
|
924
930
|
wait_seconds = max(0, ns.wait_seconds or 0)
|
|
925
931
|
# wait_seconds=0 (default) is the legacy single-shot behavior: one pass,
|
|
@@ -2,18 +2,28 @@
|
|
|
2
2
|
"""Feedback digest: distill human card decisions into learned_preferences.
|
|
3
3
|
|
|
4
4
|
The scheduled half of the review-events feedback loop (see
|
|
5
|
-
scripts/learned_preferences.py for the full loop).
|
|
5
|
+
scripts/learned_preferences.py for the full loop). learned_preferences is a
|
|
6
|
+
SINGLE install-wide block (2026-07-08), not one per project: events are
|
|
7
|
+
still fetched and prompted per project (that's where the candidates/cards
|
|
8
|
+
came from), but every project's digest writes into the same shared block, on
|
|
9
|
+
the theory that what a reviewer is actually correcting (voice, quality bar,
|
|
10
|
+
author-quality signals) is a fact about them, not about one product's
|
|
11
|
+
audience. main() runs learned_preferences.migrate_to_global() once per tick
|
|
12
|
+
(idempotent) to fold any pre-existing per-project blocks into the shared one.
|
|
13
|
+
|
|
14
|
+
Per run:
|
|
6
15
|
|
|
7
16
|
1. GET /api/v1/review-events?counts=true — which (project, platform) pairs
|
|
8
17
|
have unprocessed events. The API scopes to this installation, so a
|
|
9
18
|
customer box only ever digests its own user's decisions.
|
|
10
19
|
2. For each project that exists in the local config.json: fetch the
|
|
11
|
-
unprocessed events, build a conservative digest prompt (current
|
|
12
|
-
events + approval counter-evidence), run Claude headless via
|
|
20
|
+
unprocessed events, build a conservative digest prompt (current shared
|
|
21
|
+
block + events + approval counter-evidence), run Claude headless via
|
|
13
22
|
run_claude.sh (script_tag feedback-digest, cost-tracked like every other
|
|
14
23
|
pipeline Claude call).
|
|
15
24
|
3. Apply the returned mutation plan through
|
|
16
|
-
learned_preferences.apply_mutations() (whitelist, flock, backup, atomic)
|
|
25
|
+
learned_preferences.apply_mutations() (whitelist, flock, backup, atomic)
|
|
26
|
+
into the shared block.
|
|
17
27
|
4. PATCH the events processed (processed_batch=digest-<ts>) so they are
|
|
18
28
|
never digested twice. Events are marked processed even when the plan is
|
|
19
29
|
"no changes" — a considered no-op is a completed digestion, not a retry.
|
|
@@ -180,9 +190,11 @@ def build_prompt(project: dict, events: list[dict], overall_events: list[dict] |
|
|
|
180
190
|
f"{notes}"
|
|
181
191
|
)
|
|
182
192
|
|
|
183
|
-
return f"""You maintain the learned_preferences block for
|
|
193
|
+
return f"""You maintain the SINGLE, install-wide learned_preferences block for this social-posting pipeline (shared across every configured project, not just "{project.get('name')}"). It distills the user's own approve/reject decisions on draft cards into short standing preferences that steer future thread selection and drafting across ALL projects. It is SOFT guidance read by the drafting model, not a filter.
|
|
194
|
+
|
|
195
|
+
The events below all happened to come from project "{project.get('name')}"'s cards, but since the block is shared, only propose an entry that generalizes to a human reviewer's standing taste or quality bar (voice, tone, structural habits, author-quality signals, what counts as a good vs bad reply) — NOT something that is true only because of this one product's specific audience, niche, or content angle (e.g. "prefers accounts studying for nursing boards" belongs to one product's ICP, not to every project this reviewer runs). When the evidence is really project-specific, prefer NO change over forcing it into the shared block.
|
|
184
196
|
|
|
185
|
-
CURRENT learned_preferences:
|
|
197
|
+
CURRENT learned_preferences (shared by every project):
|
|
186
198
|
{json.dumps({k: block[k] for k in ("audience_avoid", "audience_prefer", "thread_avoid", "draft_style_notes")}, indent=2)}
|
|
187
199
|
|
|
188
200
|
CURRENT voice.never: {json.dumps(voice_never)}
|
|
@@ -203,6 +215,7 @@ Propose changes to the block. RULES, in priority order:
|
|
|
203
215
|
5. bad_draft events feed draft_style_notes (or, ONLY for a clearly recurring phrasing complaint, voice_never_add / guardrails_do_not_add; use those sparingly, they touch curated fields).
|
|
204
216
|
6. Each entry: one sentence, under 200 characters, plain language, no em dashes, no hashtags, understandable a month from now without these events.
|
|
205
217
|
7. Respect the cap: at most {lp.MAX_ENTRIES_PER_LIST} entries per list. If a list is full, fold the new signal into an existing entry via remove+add.
|
|
218
|
+
8. Scope check (this block is shared across every project): before proposing an entry, ask whether it would still make sense read from a totally different product's cards. If it only makes sense for "{project.get('name')}" specifically, don't add it.
|
|
206
219
|
|
|
207
220
|
OUTPUT: a single JSON object, nothing else. Schema:
|
|
208
221
|
{{"changes": {{"audience_avoid": {{"add": [], "remove": []}}, "audience_prefer": {{"add": [], "remove": []}}, "thread_avoid": {{"add": [], "remove": []}}, "draft_style_notes": {{"add": [], "remove": []}}}}, "voice_never_add": [], "guardrails_do_not_add": [], "block_authors": [{{"handle": "somehandle", "reason": "one short sentence citing the evidence"}}], "rationale": "one short sentence"}}
|
|
@@ -463,6 +476,21 @@ def main() -> int:
|
|
|
463
476
|
log("another digest run holds the lock; exiting")
|
|
464
477
|
return 0
|
|
465
478
|
|
|
479
|
+
# One-time, idempotent move from per-project learned_preferences to the
|
|
480
|
+
# single learned_preferences_global block (2026-07-08). Runs on every
|
|
481
|
+
# digest tick everywhere (this operator's box AND every customer install,
|
|
482
|
+
# since this file ships in the same release); a config already migrated
|
|
483
|
+
# (no project carries the old key) is a fast no-op. Skipped in --dry-run
|
|
484
|
+
# since that mode promises to change nothing.
|
|
485
|
+
if not args.dry_run:
|
|
486
|
+
try:
|
|
487
|
+
mig = lp.migrate_to_global()
|
|
488
|
+
if mig.get("migrated"):
|
|
489
|
+
log(f"learned_preferences migrated to global: projects={mig.get('projects_merged')} "
|
|
490
|
+
f"excluded={len(mig.get('excluded') or [])} dropped_at_cap={len(mig.get('dropped_at_cap') or [])}")
|
|
491
|
+
except Exception as e:
|
|
492
|
+
log(f"learned_preferences migration error (non-fatal): {e}")
|
|
493
|
+
|
|
466
494
|
cfg = load_config()
|
|
467
495
|
by_name = {p.get("name"): p for p in (cfg.get("projects") or [])}
|
|
468
496
|
|
|
@@ -43,6 +43,7 @@ import os
|
|
|
43
43
|
import re
|
|
44
44
|
import signal
|
|
45
45
|
import sys
|
|
46
|
+
import threading
|
|
46
47
|
import time
|
|
47
48
|
from pathlib import Path
|
|
48
49
|
|
|
@@ -306,6 +307,21 @@ class Harness:
|
|
|
306
307
|
ctx.add_init_script(script)
|
|
307
308
|
except Exception:
|
|
308
309
|
pass
|
|
310
|
+
# The overlay shares this CDP session with the real twitter-harness
|
|
311
|
+
# automation. When x.com throws up a native JS dialog, both clients'
|
|
312
|
+
# Playwright drivers race to auto-dismiss it (the default behavior
|
|
313
|
+
# when no listener is registered); the loser gets a
|
|
314
|
+
# "Page.handleJavaScriptDialog: No dialog is showing" protocol error
|
|
315
|
+
# that is an UNCAUGHT rejection in the Node driver, killing that
|
|
316
|
+
# whole driver process. A no-op listener opts this connection out of
|
|
317
|
+
# the race entirely (dialog handling stays the automation's job);
|
|
318
|
+
# once the driver's default-dismiss is suppressed here, evaluate()
|
|
319
|
+
# calls on the affected page resume normally as soon as the other
|
|
320
|
+
# side clears the dialog.
|
|
321
|
+
try:
|
|
322
|
+
ctx.on("dialog", lambda dialog: None)
|
|
323
|
+
except Exception:
|
|
324
|
+
pass
|
|
309
325
|
|
|
310
326
|
def paint(self, title: str, reassure: str, status: str) -> int:
|
|
311
327
|
"""Paint/refresh the overlay on every live page. Returns pages touched."""
|
|
@@ -473,11 +489,40 @@ def cmd_watch(interval: float = 2.0) -> int:
|
|
|
473
489
|
# Treat SIGTERM (launchd unload, `kill`) like Ctrl-C so the overlay is
|
|
474
490
|
# cleared on the way out instead of lingering until the next navigation.
|
|
475
491
|
signal.signal(signal.SIGTERM, lambda *_: (_ for _ in ()).throw(KeyboardInterrupt()))
|
|
492
|
+
|
|
493
|
+
# Hard watchdog: a wedged CDP call (e.g. a page whose JS is paused on a
|
|
494
|
+
# native dialog) can block the loop body indefinitely without ever raising,
|
|
495
|
+
# so the normal try/except reconnect logic below never gets a chance to
|
|
496
|
+
# run. That let a past incident spin a full core for ~3.5 hours with the
|
|
497
|
+
# overlay silently stuck instead of failing loudly. A background thread
|
|
498
|
+
# that self-terminates the process if the main loop hasn't ticked in too
|
|
499
|
+
# long is the only thing that reliably fires even when the main thread is
|
|
500
|
+
# stuck inside a blocking Playwright/CDP call; os._exit() skips Python-level
|
|
501
|
+
# cleanup on purpose since a stuck process can't be trusted to run it
|
|
502
|
+
# either. launchd's KeepAlive relaunches a clean instance immediately.
|
|
503
|
+
WATCHDOG_MAX_STALL_SEC = 60.0
|
|
504
|
+
_last_tick = {"t": time.time()}
|
|
505
|
+
|
|
506
|
+
def _watchdog() -> None:
|
|
507
|
+
while True:
|
|
508
|
+
time.sleep(10)
|
|
509
|
+
stalled = time.time() - _last_tick["t"]
|
|
510
|
+
if stalled > WATCHDOG_MAX_STALL_SEC:
|
|
511
|
+
print(
|
|
512
|
+
f"[watchdog] loop stalled {stalled:.0f}s (>{WATCHDOG_MAX_STALL_SEC:.0f}s); "
|
|
513
|
+
"self-terminating for a clean launchd restart",
|
|
514
|
+
file=sys.stderr,
|
|
515
|
+
)
|
|
516
|
+
os._exit(1)
|
|
517
|
+
|
|
518
|
+
threading.Thread(target=_watchdog, daemon=True).start()
|
|
519
|
+
|
|
476
520
|
last_status = None
|
|
477
521
|
h: Harness | None = None
|
|
478
522
|
registered = False
|
|
479
523
|
try:
|
|
480
524
|
while True:
|
|
525
|
+
_last_tick["t"] = time.time()
|
|
481
526
|
# Never let status computation (log globbing/stat, all racing against
|
|
482
527
|
# live log rotation) kill the watcher; fall back to a neutral status.
|
|
483
528
|
try:
|
package/scripts/identity.py
CHANGED
|
@@ -328,6 +328,32 @@ def get_identity_header(refresh: bool = False) -> str:
|
|
|
328
328
|
return base64.b64encode(raw).decode("ascii")
|
|
329
329
|
|
|
330
330
|
|
|
331
|
+
# Our own infra: operator Mac, mk0r E2B sandbox fleet, MacStadium remote QA boxes.
|
|
332
|
+
# Single source of truth for "is this install actually a customer", consumed by
|
|
333
|
+
# active_users.py (customer-roster dedupe) and autopilot_stall_watch.py (stall-page
|
|
334
|
+
# severity), so the two lists can't drift apart. "71522" was the MacStadium box
|
|
335
|
+
# retired by the 2026-07-06 hardware swap (ticket #10904); "71732" is its
|
|
336
|
+
# replacement, both listed since the old box's hostname could still appear in
|
|
337
|
+
# historical data.
|
|
338
|
+
INTERNAL_EMAILS = {"i@m13v.com", "agent@mk0r.com", "matt@mediar.ai"}
|
|
339
|
+
INTERNAL_HOSTNAME_SUBSTR = ("e2b.local", "71522", "71732")
|
|
340
|
+
INTERNAL_HARDWARE_UUIDS = {"07CB793D-6E32-5EF8-82E2-7CDEABD47FBC"}
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
def is_internal_install(ident: dict | None = None) -> bool:
|
|
344
|
+
"""True when this install is our own infra (staging/QA/dev), not a real
|
|
345
|
+
customer. Local-only (no DB), so it works on shipped .mcpb installs too."""
|
|
346
|
+
ident = ident if ident is not None else get_identity()
|
|
347
|
+
if (ident.get("git_email") or "").strip().lower() in INTERNAL_EMAILS:
|
|
348
|
+
return True
|
|
349
|
+
hostname = ident.get("hostname") or ""
|
|
350
|
+
if any(sub in hostname for sub in INTERNAL_HOSTNAME_SUBSTR):
|
|
351
|
+
return True
|
|
352
|
+
if (ident.get("hardware_uuid") or "") in INTERNAL_HARDWARE_UUIDS:
|
|
353
|
+
return True
|
|
354
|
+
return False
|
|
355
|
+
|
|
356
|
+
|
|
331
357
|
def main():
|
|
332
358
|
cmd = sys.argv[1] if len(sys.argv) > 1 else "show"
|
|
333
359
|
if cmd == "show":
|