@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.
Files changed (45) hide show
  1. package/browser-agent-configs/linkedin-harness-mcp.json +3 -1
  2. package/browser-agent-configs/twitter-harness-mcp.json +3 -1
  3. package/mcp/dist/index.js +155 -23
  4. package/mcp/dist/repo.js +65 -5
  5. package/mcp/dist/setup.js +35 -28
  6. package/mcp/dist/version.json +2 -2
  7. package/mcp/manifest.json +1 -1
  8. package/mcp/menubar/s4l_card.py +119 -1
  9. package/mcp/menubar/s4l_menubar.py +174 -2
  10. package/mcp/menubar/s4l_state.py +10 -1
  11. package/mcp/package.json +1 -1
  12. package/package.json +18 -1
  13. package/scripts/angles.py +8 -0
  14. package/scripts/cdp_drive.py +102 -0
  15. package/scripts/cdp_ready_check.py +56 -9
  16. package/scripts/claude_job.py +13 -29
  17. package/scripts/config.py +51 -3
  18. package/scripts/draft_prompt_core.py +15 -2
  19. package/scripts/dump_visitor_history.py +72 -0
  20. package/scripts/engage_github.py +62 -3
  21. package/scripts/harness_overlay.py +84 -39
  22. package/scripts/ingest_human_github_replies.py +205 -0
  23. package/scripts/invent_topics.py +10 -3
  24. package/scripts/pick_thread_target.py +4 -0
  25. package/scripts/pick_twitter_thread_target.py +4 -0
  26. package/scripts/post_reddit.py +40 -43
  27. package/scripts/project_topics.py +59 -1
  28. package/scripts/qualified_query_bank.py +53 -2
  29. package/scripts/reap_stale_claude_sessions.py +168 -6
  30. package/scripts/reddit_ban_check.py +28 -28
  31. package/scripts/reddit_query_bank.py +42 -2
  32. package/scripts/reply_db.py +19 -0
  33. package/scripts/s4l_box_update.sh +46 -4
  34. package/scripts/s4l_halt.sh +102 -0
  35. package/scripts/scan_github_replies.py +34 -8
  36. package/scripts/schedule_state.py +9 -5
  37. package/scripts/scrape_linkedin_comment_stats.py +25 -7
  38. package/scripts/session_index_prune.py +214 -0
  39. package/scripts/update_linkedin_stats_from_feed.py +20 -1
  40. package/scripts/voice_exemplars.py +8 -3
  41. package/skill/check-web-chats.sh +45 -0
  42. package/skill/run-twitter-cycle.sh +6 -0
  43. package/skill/run-twitter-threads.sh +51 -0
  44. package/scripts/tlh_freshness_284.py +0 -134
  45. package/scripts/tlh_pick_248.py +0 -92
@@ -14,7 +14,9 @@
14
14
  "PATH": "__HOME__/.local/bin:/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin",
15
15
  "BU_NAME": "linkedin-harness",
16
16
  "BH_PORT": "9556",
17
- "BH_PROFILE_NAME": "browser-harness-linkedin"
17
+ "BH_PROFILE_NAME": "browser-harness-linkedin",
18
+ "BH_WINDOW_POS": "3814,-1050",
19
+ "BH_WINDOW_SIZE": "1024,1013"
18
20
  }
19
21
  }
20
22
  }
@@ -11,7 +11,9 @@
11
11
  "__HOME__/.claude/mcp-servers/browser-harness/server.py"
12
12
  ],
13
13
  "env": {
14
- "PATH": "__HOME__/.local/bin:__NODE_BIN__:/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin"
14
+ "PATH": "__HOME__/.local/bin:__NODE_BIN__:/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin",
15
+ "BH_WINDOW_POS": "3042,-1032",
16
+ "BH_WINDOW_SIZE": "1024,1013"
15
17
  }
16
18
  }
17
19
  }
package/mcp/dist/index.js CHANGED
@@ -3832,8 +3832,8 @@ async function autopilotLoaded() {
3832
3832
  // fires every minute, claims ONE job, runs the pipeline's own prompt as its
3833
3833
  // Claude turn, writes the result back, and stops.
3834
3834
  // ===========================================================================
3835
- const QUEUE_WORKER_PROMPT_VERSION = 9; // v9 (2026-07-17): poll window widened 240s -> 900s (see QUEUE_WORKER_POLL_SECONDS); version bump forces the prompt refresh that carries the new --wait-seconds onto existing installs. v8: worker polls internally (claude_job.py next --wait-seconds) instead of single-shot check-then-die. Empirically verified (2026-07-06) that a single long-running Bash call survives well past the host's ~90s between-tool-call inactivity kill — that timer only fires on MODEL silence, not on one in-flight tool call — so one Bash call can safely poll for QUEUE_WORKER_POLL_SECONDS before giving up. This cuts the every-minute spin-up-empty-then-die husk cycle down to roughly one session per poll window instead of one per cron tick. v7: universal type-blind worker. ONE task claims `--type any`; per-type execution notes (e.g. the v6 incremental-draft pacing for twitter-prep) moved into claude_job.py TYPE_TO_WORKER_NOTES and ride the prompt sidecar, so the worker prompt never mentions job types. Legacy per-type tasks get this same body on refresh and become interchangeable universal workers.
3836
- // v10 (PLANNED, NOT IMPLEMENTED): delegate the actual drafting to a fresh
3835
+ const QUEUE_WORKER_PROMPT_VERSION = 10; // v10 (2026-10-29): poll window 900s -> 540s so one `next` call fits inside the Bash tool's 600s default timeout, self-reap disabled (S4L_WORKER_SELF_REAP=0 on every claude_job call), and the session ends by archiving itself instead of a SIGTERM. v9 (2026-07-17): poll window widened 240s -> 900s; version bump forces the prompt refresh that carries the new --wait-seconds onto existing installs. v8: worker polls internally (claude_job.py next --wait-seconds) instead of single-shot check-then-die. Empirically verified (2026-07-06) that a single long-running Bash call survives well past the host's ~90s between-tool-call inactivity kill — that timer only fires on MODEL silence, not on one in-flight tool call — so one Bash call can safely poll for QUEUE_WORKER_POLL_SECONDS before giving up. This cuts the every-minute spin-up-empty-then-die husk cycle down to roughly one session per poll window instead of one per cron tick. v7: universal type-blind worker. ONE task claims `--type any`; per-type execution notes (e.g. the v6 incremental-draft pacing for twitter-prep) moved into claude_job.py TYPE_TO_WORKER_NOTES and ride the prompt sidecar, so the worker prompt never mentions job types. Legacy per-type tasks get this same body on refresh and become interchangeable universal workers.
3836
+ // v11 (PLANNED, NOT IMPLEMENTED): delegate the actual drafting to a fresh
3837
3837
  // sub-agent per claimed job (claim -> delegate -> wait -> claim next, looped
3838
3838
  // within one continuous worker session) instead of drafting inline. Validated
3839
3839
  // via throwaway probe tasks 2026-07-07/08 (10 loop iterations, ~210s of real
@@ -3842,10 +3842,19 @@ const QUEUE_WORKER_PROMPT_VERSION = 9; // v9 (2026-07-17): poll window widened 2
3842
3842
  // notification) or the host kills the whole parent+child chain in 1-3 min.
3843
3843
  // Never live-fire tested against a real production job. Full design, what's
3844
3844
  // validated vs not, and the implementation steps: docs/queue-worker-delegation-plan.md
3845
- // Bump this constant to 10 only once that plan is actually implemented.
3845
+ // Bump this constant to 11 only once that plan is actually implemented.
3846
3846
  const QUEUE_WORKER_PROMPT_MARKER = "s4l_queue_worker_prompt_version";
3847
3847
  // How long ONE `next --wait-seconds` call polls before giving up and exiting.
3848
- // 900s (15 min, per Matthew 2026-07-17, up from 240s): sits AT the single-
3848
+ // 540s (9 min, 2026-10-29, down from 900s): MUST stay below the Bash tool's
3849
+ // 600s default timeout. Measured on 2026-10-29 in Claude Desktop 4.29: the
3850
+ // 900s poll hit the 600s tool timeout on every empty cycle (81 of 106 runs
3851
+ // that day), the CLI then re-emitted a ~200KB prompt snapshot (a 7s
3852
+ // main-thread stall in the app), the poller kept running as an orphaned
3853
+ // background task for the remaining 300s, and its self-reap SIGTERM cost one
3854
+ // or two more 7s stalls plus an exit-143 re-attach. With the poll inside the
3855
+ // tool timeout the call returns normally, nothing is orphaned, and the worker
3856
+ // archives itself (step 5 of the prompt) at zero measured cost.
3857
+ // Earlier rationale (900s, per Matthew 2026-07-17, up from 240s): sits AT the single-
3849
3858
  // Bash-call survival ceiling verified live on 2026-07-06 (the host's ~90s
3850
3859
  // inactivity kill fires only on model silence, and one in-flight tool call
3851
3860
  // survived a full 900s probe). This covers the ~8min average real job
@@ -3861,7 +3870,7 @@ const QUEUE_WORKER_PROMPT_MARKER = "s4l_queue_worker_prompt_version";
3861
3870
  // poll window is legitimately still working, not a husk, and a too-tight
3862
3871
  // claim_grace would SIGTERM it mid-poll before it ever gets to claim.
3863
3872
  // (Bumped to 1020s alongside this change.)
3864
- const QUEUE_WORKER_POLL_SECONDS = 900;
3873
+ const QUEUE_WORKER_POLL_SECONDS = 540;
3865
3874
  // One spec per worker task. queueType MUST match scripts/claude_job.py TAG_TO_TYPE.
3866
3875
  const QUEUE_WORKERS = [
3867
3876
  { taskId: WORKER_TASK_ID, queueType: "any", human: "universal queue" },
@@ -3983,8 +3992,9 @@ function queueWorkerBody(spec) {
3983
3992
  `The deterministic pipeline runs on this Mac. When it needs a Claude turn it ` +
3984
3993
  `drops a job on a local file queue. Your only job: pick up the next job, do ` +
3985
3994
  `EXACTLY what its prompt says, hand the result back. You do this with Bash, ` +
3986
- `Read, and Write, and NOTHING else. This run is unattended — reaching for any ` +
3987
- `other tool, or trying to "investigate", STALLS it forever.`,
3995
+ `Read, and Write, and NOTHING else (except the single archive call in step 5). ` +
3996
+ `This run is unattended — reaching for any other tool, or trying to ` +
3997
+ `"investigate", STALLS it forever.`,
3988
3998
  ``,
3989
3999
  `PACING — CRITICAL: this unattended session is terminated ~90 seconds after ` +
3990
4000
  `your LAST tool call (a host inactivity timeout). That clock only runs BETWEEN ` +
@@ -4000,11 +4010,16 @@ function queueWorkerBody(spec) {
4000
4010
  `1. Look for the next job. Run this EXACT Bash command and let it run to ` +
4001
4011
  `completion — it polls internally for up to ${Math.round(QUEUE_WORKER_POLL_SECONDS / 60)} ` +
4002
4012
  `minutes before giving up, so it may take a while to return. That is normal: ` +
4003
- `do NOT interrupt it and do NOT make any other tool call while it is running.`,
4004
- ` ${py} ${job} next --type any --prompt-file --wait-seconds ${QUEUE_WORKER_POLL_SECONDS} --state-dir ${sd}`,
4013
+ `do NOT interrupt it and do NOT make any other tool call while it is running. ` +
4014
+ `Pass the Bash tool's timeout parameter as 600000 (its 10-minute maximum) so ` +
4015
+ `the call is never moved to the background. If the result nevertheless says ` +
4016
+ `the command was moved to the background (this happens when the Mac sleeps ` +
4017
+ `mid-poll; the timeout is wall-clock), do NOT wait for it: call TaskStop with ` +
4018
+ `the ID it gives you, report "no jobs" in one line, and go to step 5.`,
4019
+ ` S4L_WORKER_SELF_REAP=0 ${py} ${job} next --type any --prompt-file --wait-seconds ${QUEUE_WORKER_POLL_SECONDS} --state-dir ${sd}`,
4005
4020
  ` It prints one line of JSON once it returns. If it prints "{}" (empty), no ` +
4006
4021
  `job showed up during the whole poll window — report "no jobs" in one line ` +
4007
- `and STOP. You are done.`,
4022
+ `and go to step 5.`,
4008
4023
  `2. Otherwise it prints {"job_id":"...","prompt_file":"...","schema_file":...}. ` +
4009
4024
  `Use the Read tool to read prompt_file; it is the complete, self-contained ` +
4010
4025
  `instruction the pipeline wrote for you. If the Read result says it is partial ` +
@@ -4014,20 +4029,28 @@ function queueWorkerBody(spec) {
4014
4029
  `ONLY that JSON object — no prose, no markdown, no code fences.`,
4015
4030
  `3. Submit it. Write your JSON object to ${outDir}/out-<job_id>.json using the ` +
4016
4031
  `Write tool (substitute the real job_id), then run this EXACT Bash command:`,
4017
- ` ${py} ${job} result --job <job_id> --result-file ${outDir}/out-<job_id>.json --state-dir ${sd}`,
4032
+ ` S4L_WORKER_SELF_REAP=0 ${py} ${job} result --job <job_id> --result-file ${outDir}/out-<job_id>.json --state-dir ${sd}`,
4018
4033
  ` If it reports the result was rejected (bad JSON / missing keys), fix your JSON ` +
4019
4034
  `and submit again — at most twice. If it still fails, run ` +
4020
- `\`${py} ${job} result --job <job_id> --error --state-dir ${sd}\` (type a one-line ` +
4021
- `reason, then Ctrl-D) and STOP.`,
4022
- `4. Report in ONE short line what you did, then STOP. Do NOT claim another job, ` +
4023
- `do NOT loop, do NOT read other files, do NOT call any other tool.`,
4035
+ `\`S4L_WORKER_SELF_REAP=0 ${py} ${job} result --job <job_id> --error --state-dir ${sd}\` (type a one-line ` +
4036
+ `reason, then Ctrl-D) and go to step 5.`,
4037
+ `4. Report in ONE short line what you did. Do NOT claim another job, ` +
4038
+ `do NOT loop, do NOT read other files.`,
4039
+ `5. End this session yourself. Call ToolSearch with the query ` +
4040
+ `"select:mcp__ccd_session_mgmt__archive_session", then call ` +
4041
+ `mcp__ccd_session_mgmt__archive_session with session_id "self" and reason ` +
4042
+ `"s4l worker done". That archive call must be your very last tool call; it ` +
4043
+ `ends the session cleanly (no SIGTERM, no idle wait). If the tool is not ` +
4044
+ `available, just STOP.`,
4024
4045
  ``,
4025
4046
  `HARD RULES: use ONLY the Bash tool (to run claude_job.py AND any persist ` +
4026
4047
  `commands the job's prompt explicitly gives you), the Read tool (the ` +
4027
4048
  `prompt/schema sidecar + the SKILL/config files the prompt names), and the ` +
4028
- `Write tool (the result file). NEVER post, reply, open a browser, or run any ` +
4029
- `command the prompt does not explicitly give you. An empty queue is the ` +
4030
- `NORMAL, expected case most minutes — it is success, not a problem to debug.`,
4049
+ `Write tool (the result file), plus TaskStop ONLY for a backgrounded poll, and ` +
4050
+ `ToolSearch and mcp__ccd_session_mgmt__archive_session ONLY as the final step 5. NEVER post, ` +
4051
+ `reply, open a browser, or run any command the prompt does not explicitly ` +
4052
+ `give you. An empty queue is the NORMAL, expected case most minutes — it is ` +
4053
+ `success, not a problem to debug.`,
4031
4054
  ].join("\n");
4032
4055
  }
4033
4056
  // Full canonical SKILL.md (frontmatter + body + version marker) the MCP writes
@@ -5271,6 +5294,43 @@ function readPanelEndpoint() {
5271
5294
  return null;
5272
5295
  }
5273
5296
  }
5297
+ // A live pid is not enough to trust panel-endpoint.json: the exit-hook unlink
5298
+ // never runs on SIGKILL, so the file can point at a dead pid that the OS later
5299
+ // RECYCLES for an unrelated process — kill(pid, 0) then reports "alive" and
5300
+ // every instance would cede forever (no panel owner, no heartbeat/relay owner)
5301
+ // until the squatter happens to exit. Accept the registration only when the
5302
+ // pid's command line actually looks like an S4L MCP server; on ps failure fall
5303
+ // back to liveness alone rather than stealing a possibly-valid slot.
5304
+ function isS4lServerPid(pid) {
5305
+ if (!isPidAlive(pid))
5306
+ return false;
5307
+ try {
5308
+ const cmd = execFileSync("ps", ["-o", "command=", "-p", String(pid)], {
5309
+ encoding: "utf-8",
5310
+ timeout: 4000,
5311
+ });
5312
+ return cmd.includes("dist/index.js") || cmd.includes("@m13v/s4l-mcp");
5313
+ }
5314
+ catch {
5315
+ return true;
5316
+ }
5317
+ }
5318
+ // True when this process should run per-INSTALL periodic work (heartbeat,
5319
+ // transcript/provider relays, state snapshots). Several server instances are
5320
+ // routinely alive at once (Desktop, Code side-panel, per-minute queue workers —
5321
+ // each boots its own copy via the ~/.claude.json registration), and before this
5322
+ // gate every one of them ran every timer: 16 concurrent instances meant 48
5323
+ // heartbeat python spawns per 15 min and a measured ~11k fs-events/sec from
5324
+ // duplicate relay scans. Reuse the panel-endpoint election writePanelUrl already
5325
+ // maintains: the registered live S4L-server pid is the designated worker; when
5326
+ // the file is absent, stale, or squatted, anyone may run the work (the 120s
5327
+ // reclaim tick will elect a new owner shortly).
5328
+ function isInstallTickOwner() {
5329
+ const existing = readPanelEndpoint();
5330
+ if (!existing?.pid || existing.pid === process.pid)
5331
+ return true;
5332
+ return !isS4lServerPid(existing.pid);
5333
+ }
5274
5334
  // Publish the loopback URL to stable files so out-of-process readers can find
5275
5335
  // the ephemeral port without scraping `lsof`:
5276
5336
  // - panel-url plain text, for the Claude Code side-panel reverse proxy.
@@ -5295,7 +5355,7 @@ function writePanelUrl(url) {
5295
5355
  fs.mkdirSync(dir, { recursive: true });
5296
5356
  fs.writeFileSync(path.join(dir, "panel-url"), url, "utf-8");
5297
5357
  const existing = readPanelEndpoint();
5298
- if (existing?.pid && existing.pid !== process.pid && isPidAlive(existing.pid)) {
5358
+ if (existing?.pid && existing.pid !== process.pid && isS4lServerPid(existing.pid)) {
5299
5359
  // Someone else already holds a live registration (most likely a longer-
5300
5360
  // lived session than us) — don't clobber it. Our own panel is still up
5301
5361
  // and fully usable via `url` for anything that already has it (e.g. this
@@ -6212,6 +6272,67 @@ async function main() {
6212
6272
  const transport = new StdioServerTransport();
6213
6273
  await server.connect(transport);
6214
6274
  console.error(`[social-autoposter-mcp] connected. v=${VERSION} repo=${repoDir()}`);
6275
+ // Exit when the client goes away. The SDK's StdioServerTransport listens only
6276
+ // for stdin 'data'/'error' — never 'end'/'close' — so client death is invisible
6277
+ // to it, and the eagerly-started panel HTTP listener below holds the event loop
6278
+ // open forever. That combination orphaned 16 servers (33 GB RSS, duplicate
6279
+ // autopilot timers) on 2026-09-18: every client exit (clean close OR SIGKILL,
6280
+ // which just closes our stdin pipe) left a full server behind, reparented to
6281
+ // launchd. Handle EOF ourselves, plus signals, plus a ppid backstop for the
6282
+ // rare case where an inherited fd keeps the stdin pipe open past client death.
6283
+ let shutdownStarted = false;
6284
+ const exitNow = (reason) => {
6285
+ console.error(`[social-autoposter-mcp] client gone (${reason}); exiting`);
6286
+ try {
6287
+ localPanel?.server.close();
6288
+ }
6289
+ catch {
6290
+ /* best-effort */
6291
+ }
6292
+ process.exit(0);
6293
+ };
6294
+ const shutdown = (reason, force = false) => {
6295
+ if (shutdownStarted) {
6296
+ // A second signal while we wait out a drain means "stop now".
6297
+ if (force)
6298
+ exitNow(`${reason}, forced`);
6299
+ return;
6300
+ }
6301
+ shutdownStarted = true;
6302
+ if (!postingActive) {
6303
+ exitNow(reason);
6304
+ return;
6305
+ }
6306
+ // A posting drain is in flight: this process holds the shared
6307
+ // twitter-browser shell lock under its OWN pid while a python poster child
6308
+ // drives Chrome. Exiting now (a) lets the next per-minute cycle
6309
+ // stale-reclaim the lock mid-post and (b) crashes the poster on EPIPE
6310
+ // between a landed reply and its bookkeeping — the idempotent redrain then
6311
+ // double-posts. Wait for the drain to finish (the interval is deliberately
6312
+ // ref'd so it keeps the process alive), capped at the approve_drafts
6313
+ // worst-case timeout.
6314
+ console.error(`[social-autoposter-mcp] client gone (${reason}); waiting for in-flight posting drain before exit`);
6315
+ const started = Date.now();
6316
+ const wait = setInterval(() => {
6317
+ if (!postingActive || Date.now() - started > 2 * 3600_000) {
6318
+ clearInterval(wait);
6319
+ exitNow(`${reason}, drain done`);
6320
+ }
6321
+ }, 5_000);
6322
+ };
6323
+ process.stdin.on("end", () => shutdown("stdin end"));
6324
+ process.stdin.on("close", () => shutdown("stdin close"));
6325
+ process.on("SIGTERM", () => shutdown("SIGTERM", true));
6326
+ process.on("SIGINT", () => shutdown("SIGINT", true));
6327
+ // Skip the backstop when we were BORN with ppid 1 (a launchd-managed server is
6328
+ // legitimately parented to launchd; only a reparent-after-birth means orphaned).
6329
+ if (process.ppid !== 1) {
6330
+ const ppidWatch = setInterval(() => {
6331
+ if (process.ppid === 1)
6332
+ shutdown("orphaned (ppid=1)");
6333
+ }, 30_000);
6334
+ ppidWatch.unref();
6335
+ }
6215
6336
  // Eagerly start the loopback panel server so the Claude Code side panel (and any
6216
6337
  // reverse proxy in front of it) always has a backend to hit, without waiting for
6217
6338
  // a first `dashboard` call. Best-effort: a bind failure must never block boot.
@@ -6245,8 +6366,16 @@ async function main() {
6245
6366
  // (parity with the npx launchd heartbeat). Once on startup, then every 15m
6246
6367
  // while the desktop app keeps the server alive. unref() so it never holds the
6247
6368
  // process open past a normal exit.
6369
+ // Heartbeat + the relays + snapshots below are per-INSTALL work: gate every
6370
+ // tick on the panel-endpoint election (isInstallTickOwner) so N concurrent
6371
+ // instances produce 1x the spawns, not Nx. The startup heartbeat stays
6372
+ // unconditional — a fresh install must phone home before it ever wins an
6373
+ // election.
6248
6374
  void sendHeartbeat("startup");
6249
- const hb = setInterval(() => void sendHeartbeat("interval"), 15 * 60_000);
6375
+ const hb = setInterval(() => {
6376
+ if (isInstallTickOwner())
6377
+ void sendHeartbeat("interval");
6378
+ }, 15 * 60_000);
6250
6379
  hb.unref();
6251
6380
  // Ship Claude session transcripts (scheduled queue-worker runs + s4l repo
6252
6381
  // sessions) to the Cloud Logging relay so a user's session can be
@@ -6257,7 +6386,7 @@ async function main() {
6257
6386
  if ((process.env.S4L_TRANSCRIPT_RELAY ?? "1") !== "0") {
6258
6387
  let transcriptRelayRunning = false;
6259
6388
  const relayTranscripts = () => {
6260
- if (transcriptRelayRunning)
6389
+ if (transcriptRelayRunning || !isInstallTickOwner())
6261
6390
  return;
6262
6391
  transcriptRelayRunning = true;
6263
6392
  runPython("scripts/relay_session_transcripts.py", ["--max-lines", "600"], {
@@ -6283,7 +6412,7 @@ async function main() {
6283
6412
  if ((process.env.S4L_PROVIDER_LOG_RELAY ?? "1") !== "0") {
6284
6413
  let providerRelayRunning = false;
6285
6414
  const relayProviderLog = () => {
6286
- if (providerRelayRunning)
6415
+ if (providerRelayRunning || !isInstallTickOwner())
6287
6416
  return;
6288
6417
  providerRelayRunning = true;
6289
6418
  runPython("scripts/relay_provider_log.py", ["--max-lines", "500"], {
@@ -6306,7 +6435,10 @@ async function main() {
6306
6435
  // the recurring tick only POSTs when something actually changed; setup.ts
6307
6436
  // additionally fires it right after every config write.
6308
6437
  void sendStateSnapshot("startup");
6309
- const ss = setInterval(() => void sendStateSnapshot("interval"), 15 * 60_000);
6438
+ const ss = setInterval(() => {
6439
+ if (isInstallTickOwner())
6440
+ void sendStateSnapshot("interval");
6441
+ }, 15 * 60_000);
6310
6442
  ss.unref();
6311
6443
  // Voice-exemplar catch-up + periodic refresh, checked on every boot
6312
6444
  // (2026-07-16, extended from the original one-shot-for-legacy-installs
package/mcp/dist/repo.js CHANGED
@@ -85,6 +85,21 @@ export function run(cmd, args, opts = {}) {
85
85
  }
86
86
  let stdout = "";
87
87
  let stderr = "";
88
+ // Cap captured output to a tail. run() used to accumulate a child's full
89
+ // stdout+stderr unbounded for the child's lifetime; long-lived spawns (the
90
+ // 13h voice backfill) and stuck children pinned those strings and were the
91
+ // main driver of multi-GB server heaps. Callers that parse output read
92
+ // either whole small payloads or the LAST line, so keeping the tail
93
+ // preserves semantics. 8 MB per stream is far above any legitimate payload.
94
+ const MAX_CAPTURE_BYTES = 8 * 1024 * 1024;
95
+ const capTail = (s) => s.length > MAX_CAPTURE_BYTES ? s.slice(s.length - (MAX_CAPTURE_BYTES >> 1)) : s;
96
+ // The line-splitter buffers below only shed at '\n', so a child emitting
97
+ // long newline-free output (carriage-return progress bars, one huge line)
98
+ // would grow them unbounded for its lifetime — the same heap pathology the
99
+ // capture cap exists for. Keep only a tail of an oversized partial line
100
+ // (telemetry truncates lines to 8KB anyway).
101
+ const MAX_LINEBUF_BYTES = 1024 * 1024;
102
+ const capLineBuf = (buf) => buf.length > MAX_LINEBUF_BYTES ? buf.slice(-8192) : buf;
88
103
  // Per-stream partial-line buffers so onLine fires on whole lines only,
89
104
  // regardless of how the OS chunks the pipe reads.
90
105
  let outBuf = "";
@@ -104,7 +119,7 @@ export function run(cmd, args, opts = {}) {
104
119
  /* a progress sink must never break the wrapped command */
105
120
  }
106
121
  }
107
- return buf;
122
+ return capLineBuf(buf);
108
123
  };
109
124
  // Parallel whole-line splitter that tees to the telemetry sink (if any),
110
125
  // kept separate from the onLine pump so neither path can affect the other.
@@ -127,29 +142,56 @@ export function run(cmd, args, opts = {}) {
127
142
  /* the telemetry sink must never break the wrapped command */
128
143
  }
129
144
  }
130
- return buf;
145
+ return capLineBuf(buf);
131
146
  };
147
+ let settled = false;
132
148
  let timer;
149
+ let killTimer;
133
150
  if (opts.timeoutMs) {
134
151
  timer = setTimeout(() => {
135
152
  child.kill("SIGTERM");
153
+ // A child that ignores SIGTERM used to live (and hold its pipes and our
154
+ // buffers) forever. Escalate — but GENEROUSLY: children trap SIGTERM on
155
+ // purpose to finish critical bookkeeping (twitter_post_plan.py finishes
156
+ // the current candidate's post + recording, which can take minutes, so a
157
+ // fast SIGKILL would reopen the posted-but-unrecorded double-post
158
+ // window). 15 min covers every graceful path; only a truly wedged child
159
+ // gets hard-killed.
160
+ killTimer = setTimeout(() => {
161
+ try {
162
+ child.kill("SIGKILL");
163
+ }
164
+ catch {
165
+ /* already gone */
166
+ }
167
+ }, 15 * 60_000);
168
+ killTimer.unref();
136
169
  }, opts.timeoutMs);
137
170
  }
138
171
  child.stdout.on("data", (d) => {
172
+ if (settled)
173
+ return;
139
174
  const s = d.toString();
140
- stdout += s;
175
+ stdout = capTail(stdout + s);
141
176
  outBuf = pump(s, "stdout", outBuf);
142
177
  sinkOutBuf = sinkPump(s, "stdout", sinkOutBuf);
143
178
  });
144
179
  child.stderr.on("data", (d) => {
180
+ if (settled)
181
+ return;
145
182
  const s = d.toString();
146
- stderr += s;
183
+ stderr = capTail(stderr + s);
147
184
  errBuf = pump(s, "stderr", errBuf);
148
185
  sinkErrBuf = sinkPump(s, "stderr", sinkErrBuf);
149
186
  });
150
- child.on("close", (code) => {
187
+ const finish = (code) => {
188
+ if (settled)
189
+ return;
190
+ settled = true;
151
191
  if (timer)
152
192
  clearTimeout(timer);
193
+ if (killTimer)
194
+ clearTimeout(killTimer);
153
195
  // Flush any trailing partial line (output with no terminating newline).
154
196
  if (opts.onLine) {
155
197
  if (outBuf)
@@ -185,10 +227,28 @@ export function run(cmd, args, opts = {}) {
185
227
  }
186
228
  }
187
229
  resolve({ code: code ?? -1, stdout, stderr });
230
+ };
231
+ child.on("close", (code) => finish(code));
232
+ child.on("exit", (code) => {
233
+ // 'close' waits for the stdio pipes to drain, which never happens when a
234
+ // grandchild inherited them and outlives the child — the promise (and the
235
+ // captured output) then leaked for the grandchild's lifetime. After the
236
+ // child itself exits, give the pipes a grace to flush, then settle. The
237
+ // setImmediate hop matters: if the event loop was stalled past the grace
238
+ // by sync work, timers fire BEFORE the poll phase reads the data already
239
+ // sitting in the kernel buffer — hopping to the check phase lets those
240
+ // reads land first instead of truncating a successful child's output.
241
+ const drain = setTimeout(() => setImmediate(() => finish(code)), 10_000);
242
+ drain.unref();
188
243
  });
189
244
  child.on("error", (err) => {
245
+ if (settled)
246
+ return;
247
+ settled = true;
190
248
  if (timer)
191
249
  clearTimeout(timer);
250
+ if (killTimer)
251
+ clearTimeout(killTimer);
192
252
  resolve({ code: -1, stdout, stderr: stderr + String(err) });
193
253
  });
194
254
  });
package/mcp/dist/setup.js CHANGED
@@ -45,6 +45,37 @@ export function configPath() {
45
45
  return p; // not created yet: return the intended path unresolved
46
46
  }
47
47
  }
48
+ // Atomic config.json write (2026-10-30). Never write config.json in place:
49
+ // writeFileSync truncates the file first, so a reader in that window (or an
50
+ // interrupted write) sees a torn file and every pipeline lane dies on it.
51
+ // Write a same-directory temp file, fsync, then rename over the target so
52
+ // readers only ever see the old or the new complete file. Keeps the
53
+ // timestamped .bak- copy the call sites used to make.
54
+ export function writeConfigAtomic(cfg) {
55
+ const cfgPath = configPath();
56
+ if (fs.existsSync(cfgPath)) {
57
+ const stamp = new Date().toISOString().replace(/[:.]/g, "-");
58
+ fs.copyFileSync(cfgPath, `${cfgPath}.bak-${stamp}`);
59
+ }
60
+ fs.mkdirSync(path.dirname(cfgPath), { recursive: true });
61
+ const tmp = `${cfgPath}.tmp-${process.pid}`;
62
+ try {
63
+ const fd = fs.openSync(tmp, "w");
64
+ try {
65
+ fs.writeSync(fd, JSON.stringify(cfg, null, 2) + "\n");
66
+ fs.fsyncSync(fd);
67
+ }
68
+ finally {
69
+ fs.closeSync(fd);
70
+ }
71
+ fs.renameSync(tmp, cfgPath);
72
+ }
73
+ finally {
74
+ if (fs.existsSync(tmp))
75
+ fs.unlinkSync(tmp);
76
+ }
77
+ return cfgPath;
78
+ }
48
79
  // One-time (idempotent) migration to the state-dir home, run at server boot.
49
80
  // Cases:
50
81
  // - no state config, legacy is a REAL file -> move it up, leave a symlink
@@ -360,13 +391,7 @@ export function applySetup(input) {
360
391
  cfg.projects.push(entry);
361
392
  created = true;
362
393
  }
363
- const cfgPath = configPath();
364
- if (fs.existsSync(cfgPath)) {
365
- const stamp = new Date().toISOString().replace(/[:.]/g, "-");
366
- fs.copyFileSync(cfgPath, `${cfgPath}.bak-${stamp}`);
367
- }
368
- fs.mkdirSync(path.dirname(cfgPath), { recursive: true });
369
- fs.writeFileSync(cfgPath, JSON.stringify(cfg, null, 2) + "\n", "utf-8");
394
+ writeConfigAtomic(cfg);
370
395
  void sendStateSnapshot("config_write");
371
396
  if (!persona)
372
397
  recordManagedProject(input.name);
@@ -418,13 +443,7 @@ export function recordRedditAccount(username) {
418
443
  if (!reddit.login_method)
419
444
  reddit.login_method = "browser";
420
445
  try {
421
- const cfgPath = configPath();
422
- if (fs.existsSync(cfgPath)) {
423
- const stamp = new Date().toISOString().replace(/[:.]/g, "-");
424
- fs.copyFileSync(cfgPath, `${cfgPath}.bak-${stamp}`);
425
- }
426
- fs.mkdirSync(path.dirname(cfgPath), { recursive: true });
427
- fs.writeFileSync(cfgPath, JSON.stringify(cfg, null, 2) + "\n", "utf-8");
446
+ writeConfigAtomic(cfg);
428
447
  void sendStateSnapshot("config_write");
429
448
  return { written: true, detail: `accounts.reddit.username = ${clean}` };
430
449
  }
@@ -541,13 +560,7 @@ export function ensurePersonaProject(grounding) {
541
560
  name = PERSONA_DEFAULT_NAME;
542
561
  created = true;
543
562
  }
544
- const cfgPath = configPath();
545
- if (fs.existsSync(cfgPath)) {
546
- const stamp = new Date().toISOString().replace(/[:.]/g, "-");
547
- fs.copyFileSync(cfgPath, `${cfgPath}.bak-${stamp}`);
548
- }
549
- fs.mkdirSync(path.dirname(cfgPath), { recursive: true });
550
- fs.writeFileSync(cfgPath, JSON.stringify(cfg, null, 2) + "\n", "utf-8");
563
+ const cfgPath = writeConfigAtomic(cfg);
551
564
  // Raw dictation transcript -> persona_corpus.txt sidecar (NOT config.json).
552
565
  // Mirrors scripts/build_persona.py cmd_apply: config.json is inlined into many
553
566
  // prompts (ALL_PROJECTS_JSON), so a multi-KB corpus there would bloat every
@@ -598,13 +611,7 @@ export function ensureShortLinksDefault() {
598
611
  changed = true;
599
612
  }
600
613
  if (changed) {
601
- const cfgPath = configPath();
602
- if (fs.existsSync(cfgPath)) {
603
- const stamp = new Date().toISOString().replace(/[:.]/g, "-");
604
- fs.copyFileSync(cfgPath, `${cfgPath}.bak-${stamp}`);
605
- }
606
- fs.mkdirSync(path.dirname(cfgPath), { recursive: true });
607
- fs.writeFileSync(cfgPath, JSON.stringify(cfg, null, 2) + "\n", "utf-8");
614
+ writeConfigAtomic(cfg);
608
615
  void sendStateSnapshot("config_write");
609
616
  }
610
617
  }
@@ -1,4 +1,4 @@
1
1
  {
2
- "version": "1.7.11",
3
- "installedAt": "2026-08-14T18:28:05.705Z"
2
+ "version": "1.7.12-rc.10",
3
+ "installedAt": "2026-11-06T19:24:01.619Z"
4
4
  }
package/mcp/manifest.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "dxt_version": "0.1",
3
3
  "name": "social-autoposter",
4
4
  "display_name": "S4L",
5
- "version": "1.7.11",
5
+ "version": "1.7.12-rc.10",
6
6
  "description": "Draft, review, approve, and autopilot X/Twitter posts.",
7
7
  "long_description": "## **⚠️ The disclaimer above is generic Claude boilerplate.** Anthropic shows the same warning on every plugin regardless of what it does; any plugin has the same level of access as any app you download from the internet.\n\nS4L is an open source product developed by Mediar.ai Incorporated, a VC-backed San Francisco-based startup.\n\nTo get started:\n\n1\\. Copy this prompt: **Set me up on S4L plugin end to end**\n\n2\\. Quit with CMD+Q, reopen Claude, paste into a new chat.\n\nWhat happens next:\n\n* About every 5 minutes S4L scans X for posts that match your topics and drafts replies in your voice.\n* Drafts show up as review cards, usually the first within a few minutes. Nothing is posted automatically; you approve each one.\n* Posting autopilot stays off until you explicitly turn it on.",
8
8
  "author": {