@m13v/s4l 1.7.9 → 1.7.10-rc.2

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.
@@ -1,4 +1,4 @@
1
1
  {
2
- "version": "1.7.9",
3
- "installedAt": "2026-08-10T22:28:09.611Z"
2
+ "version": "1.7.10-rc.2",
3
+ "installedAt": "2026-08-12T17:53:56.745Z"
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.9",
5
+ "version": "1.7.10-rc.2",
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": {
package/mcp/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@m13v/s4l-mcp",
3
- "version": "1.7.9",
3
+ "version": "1.7.10-rc.2",
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.9",
3
+ "version": "1.7.10-rc.2",
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",
@@ -16,8 +16,14 @@ docs/codex-port-design.md):
16
16
  (_run_codex_exec; gpt-5.6-sol default, schema rides
17
17
  the prompt — OpenAI strict schema mode rejects our
18
18
  lenient schemas).
19
-
20
- All three return byte-identical claude `--output-format json` envelopes and
19
+ gemini-api answer inline via the Gemini generateContent REST API
20
+ (_run_gemini_api; gemini-pro-latest default with a
21
+ one-shot flash downgrade on 404, schema rides the
22
+ prompt for the same lenient-schema reason). The
23
+ hosted-lane provider: key-authenticated, no local
24
+ app, runs headless on Linux.
25
+
26
+ All four return byte-identical claude `--output-format json` envelopes and
21
27
  the same 0/1/79 exit semantics, so callers can't tell them apart. The queue
22
28
  machinery below (next/result, worker notes, heartbeats) only runs for the
23
29
  default provider; the inline providers skip it entirely, which also means no
@@ -897,6 +903,160 @@ def _run_codex_exec(ns, qtype: str, prompt: str, schema_text: str | None) -> int
897
903
  _disarm_deathwatch(job_id)
898
904
 
899
905
 
906
+ def _run_gemini_api(ns, qtype: str, prompt: str, schema_text: str | None) -> int:
907
+ """gemini-api provider: answer the turn inline via the Gemini
908
+ generateContent REST API. Key-authenticated, fully headless: this is the
909
+ hosted-lane provider (no Claude Desktop, no ChatGPT app, runs on Linux).
910
+ Same envelope, same 0/1/79 exit semantics as the other inline providers.
911
+
912
+ Schema rides the prompt (not responseSchema): Gemini's structured-output
913
+ schema dialect is an OpenAPI subset that rejects parts of our lenient
914
+ claude-style schemas, so _validate_against_schema stays the single gate,
915
+ matching the codex-exec precedent. responseMimeType application/json still
916
+ forces bare-JSON output for schema'd jobs; schemaless jobs (link-tail)
917
+ stay plain text.
918
+ """
919
+ import urllib.error
920
+ import urllib.request
921
+
922
+ key = draft_provider.gemini_api_key()
923
+ if not key:
924
+ _plog(f"gemini-api provider active but no GEMINI_API_KEY / keychain gemini-api-key; failing {qtype}")
925
+ return 1
926
+
927
+ batch = (os.environ.get("BATCH_ID") or os.environ.get("SA_CYCLE_ID") or "-").strip() or "-"
928
+ job_id = uuid.uuid4().hex
929
+ _arm_deathwatch(job_id, qtype, batch)
930
+ _act_write(qtype)
931
+ try:
932
+ if schema_text:
933
+ prompt = (
934
+ f"{prompt}\n\n"
935
+ "FINAL ANSWER FORMAT: reply with ONLY a JSON value matching this "
936
+ "JSON Schema. No prose, no markdown fences, nothing else:\n"
937
+ f"{schema_text}"
938
+ )
939
+ # Model default mirrors codex-exec's probe-by-use pattern: try the pro
940
+ # alias first (drafting quality is the product), downgrade ONCE to the
941
+ # flash alias on a model-not-found 404 and log it loudly. The -latest
942
+ # aliases are Google-maintained so this never pins a dead model id.
943
+ model = os.environ.get("S4L_GEMINI_MODEL", "").strip() or "gemini-pro-latest"
944
+ fallback_model = "gemini-flash-latest"
945
+ gen_config = {"temperature": 0.7, "maxOutputTokens": 16384}
946
+ if schema_text:
947
+ gen_config["responseMimeType"] = "application/json"
948
+ body = json.dumps(
949
+ {
950
+ "contents": [{"role": "user", "parts": [{"text": prompt}]}],
951
+ "generationConfig": gen_config,
952
+ }
953
+ ).encode()
954
+
955
+ budget = max(60, ns.timeout - 60)
956
+ _plog(f"gemini-api start {qtype} job {job_id} batch={batch} model={model} timeout={budget}s")
957
+ started = time.time()
958
+ resp_obj = None
959
+ for attempt_model in (model, fallback_model if fallback_model != model else None):
960
+ if not attempt_model:
961
+ break
962
+ url = (
963
+ "https://generativelanguage.googleapis.com/v1beta/models/"
964
+ f"{attempt_model}:generateContent"
965
+ )
966
+ req = urllib.request.Request(
967
+ url,
968
+ data=body,
969
+ headers={"Content-Type": "application/json", "x-goog-api-key": key},
970
+ method="POST",
971
+ )
972
+ try:
973
+ with urllib.request.urlopen(
974
+ req, timeout=max(60, budget - int(time.time() - started))
975
+ ) as resp:
976
+ resp_obj = json.loads(resp.read().decode())
977
+ break
978
+ except urllib.error.HTTPError as e:
979
+ tail = ""
980
+ try:
981
+ tail = e.read().decode()[-400:]
982
+ except Exception:
983
+ pass
984
+ if e.code == 404 and attempt_model == model:
985
+ _plog(
986
+ f"gemini-api model {attempt_model} not found (404); "
987
+ f"retrying job {job_id} with {fallback_model}"
988
+ )
989
+ continue
990
+ _act_clear()
991
+ _plog(f"gemini-api HTTP {e.code} on job {job_id} ({qtype}); tail: {tail}")
992
+ return 1
993
+ except TimeoutError:
994
+ _act_clear()
995
+ _plog(f"gemini-api timed out after {budget}s on job {job_id} ({qtype})")
996
+ return 79 # mirror the queue path's "blocked, skip cleanly"
997
+ except Exception as e:
998
+ _act_clear()
999
+ _plog(f"gemini-api request failed on job {job_id} ({qtype}): {e}")
1000
+ return 1
1001
+ if resp_obj is None:
1002
+ _act_clear()
1003
+ _plog(f"gemini-api no response on job {job_id} ({qtype})")
1004
+ return 1
1005
+
1006
+ try:
1007
+ cand = resp_obj["candidates"][0]
1008
+ text = "".join(
1009
+ p.get("text", "") for p in cand.get("content", {}).get("parts", [])
1010
+ ).strip()
1011
+ finish = cand.get("finishReason", "?")
1012
+ except (KeyError, IndexError, TypeError):
1013
+ _act_clear()
1014
+ block = (resp_obj.get("promptFeedback") or {}).get("blockReason", "?")
1015
+ _plog(f"gemini-api no candidates on job {job_id} ({qtype}); blockReason={block}")
1016
+ return 1
1017
+ if not text:
1018
+ _act_clear()
1019
+ _plog(f"gemini-api empty answer on job {job_id} ({qtype}); finishReason={finish}")
1020
+ return 1
1021
+
1022
+ # Same lenient parse as codex-exec: JSON when it parses, fenced JSON
1023
+ # unwrapped, otherwise the raw text as a plain string (link-tail jobs).
1024
+ obj = None
1025
+ parsed = False
1026
+ for candidate in (text, re.sub(r"^```(?:json)?\s*|\s*```$", "", text).strip()):
1027
+ try:
1028
+ obj = json.loads(candidate)
1029
+ parsed = True
1030
+ break
1031
+ except Exception:
1032
+ continue
1033
+ if not parsed:
1034
+ obj = text
1035
+
1036
+ err = _validate_against_schema(obj, schema_text)
1037
+ if err:
1038
+ _act_clear()
1039
+ _plog(f"gemini-api result rejected for job {job_id} ({qtype}): {err}")
1040
+ return 1
1041
+
1042
+ _emit_envelope(obj)
1043
+ _mark_drain_success()
1044
+ _stamp_heartbeat("gemini-api", qtype)
1045
+ usage = resp_obj.get("usageMetadata") or {}
1046
+ tokens = usage.get("totalTokenCount", "?")
1047
+ try:
1048
+ _ncand = len(obj.get("candidates")) if isinstance(obj, dict) and isinstance(obj.get("candidates"), list) else "?"
1049
+ except Exception:
1050
+ _ncand = "?"
1051
+ _plog(
1052
+ f"gemini-api done job {job_id} batch={batch} ({qtype}) in {int(time.time() - started)}s "
1053
+ f"tokens={tokens} finish={finish}; {_ncand} candidates -> producer assembles the plan"
1054
+ )
1055
+ return 0
1056
+ finally:
1057
+ _disarm_deathwatch(job_id)
1058
+
1059
+
900
1060
  def _run_claude_p(ns, qtype: str, prompt: str, schema_text: str | None) -> int:
901
1061
  """claude-p provider: answer the turn inline via the real `claude -p`
902
1062
  (Claude Code CLI, subscription-authenticated). No queue, no worker, no
@@ -999,6 +1159,8 @@ def cmd_provider(ns) -> int:
999
1159
  return _run_codex_exec(ns, qtype, prompt, schema_text)
1000
1160
  if _prov == "claude-p":
1001
1161
  return _run_claude_p(ns, qtype, prompt, schema_text)
1162
+ if _prov == "gemini-api":
1163
+ return _run_gemini_api(ns, qtype, prompt, schema_text)
1002
1164
 
1003
1165
  job_id = uuid.uuid4().hex
1004
1166
  created = time.time()
@@ -18,6 +18,11 @@ Providers:
18
18
  (headless, subscription-authenticated). Requires the
19
19
  ChatGPT app installed and logged in. No queue, no
20
20
  worker, no app-open requirement.
21
+ gemini-api answer inline via the Gemini generateContent REST API
22
+ (key-authenticated, no local app at all). The hosted
23
+ lane's provider: works headless on any Linux box.
24
+ Key: $GEMINI_API_KEY, else macOS keychain
25
+ `gemini-api-key`.
21
26
 
22
27
  CLI:
23
28
  python3 scripts/draft_provider.py get -> prints the active provider
@@ -32,7 +37,7 @@ import os
32
37
  import sys
33
38
  import time
34
39
 
35
- VALID_PROVIDERS = ("claude-desktop-queue", "claude-p", "codex-exec")
40
+ VALID_PROVIDERS = ("claude-desktop-queue", "claude-p", "codex-exec", "gemini-api")
36
41
  DEFAULT_PROVIDER = "claude-desktop-queue"
37
42
 
38
43
  # The npm @openai/codex install is unreliable on macOS (XProtect false-positives
@@ -89,6 +94,27 @@ def codex_bin() -> str | None:
89
94
  return None
90
95
 
91
96
 
97
+ def gemini_api_key() -> str | None:
98
+ """Resolved Gemini API key, or None. Env wins (the hosted/Linux path);
99
+ macOS keychain `gemini-api-key` is the operator-Mac fallback."""
100
+ key = os.environ.get("GEMINI_API_KEY", "").strip()
101
+ if key:
102
+ return key
103
+ try:
104
+ import subprocess
105
+
106
+ out = subprocess.run(
107
+ ["security", "find-generic-password", "-s", "gemini-api-key", "-w"],
108
+ capture_output=True,
109
+ text=True,
110
+ timeout=10,
111
+ )
112
+ key = (out.stdout or "").strip()
113
+ return key or None
114
+ except Exception:
115
+ return None
116
+
117
+
92
118
  def main() -> int:
93
119
  if len(sys.argv) < 2 or sys.argv[1] not in ("get", "set", "codex-bin"):
94
120
  print(__doc__, file=sys.stderr)
@@ -2637,6 +2637,19 @@ def _post_iteration(plan, reddit_username):
2637
2637
  os.environ["CLAUDE_SESSION_ID"] = plan_session_id
2638
2638
 
2639
2639
  active_campaigns = load_active_reddit_campaigns()
2640
+ # S4L_SKIP_CAMPAIGN_SUFFIX=1: reviewed/approved posts never get the
2641
+ # active-campaign suffix (e.g. " written with ai"). The MCP approval
2642
+ # poster (mcp/src/index.ts::postApproved) has set this env since the
2643
+ # reddit card path shipped, but this script never read it, so reviewed
2644
+ # reddit posts kept getting a suffix the reviewer never saw on the card
2645
+ # (2026-08-10, carrabre). Mirrors twitter_browser.py's reply handler.
2646
+ # The cron/autopilot pipeline never sets it, so the A/B disclosure
2647
+ # experiment keeps running there.
2648
+ if os.environ.get("S4L_SKIP_CAMPAIGN_SUFFIX", "").strip().lower() in ("1", "true", "yes"):
2649
+ if active_campaigns:
2650
+ print("[post_reddit] S4L_SKIP_CAMPAIGN_SUFFIX set: campaign "
2651
+ "suffixes disabled for this plan (reviewed posts land clean)")
2652
+ active_campaigns = []
2640
2653
  # Persona posts never carry a product campaign suffix (2026-07-17): the
2641
2654
  # reddit analog of the X lane's TWITTER_TAIL_LINK_RATE=0. Resolved from
2642
2655
  # config (persona:true on the plan's project), NOT from lane env; the