socialcli 0.3.0__py3-none-any.whl
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.
Potentially problematic release.
This version of socialcli might be problematic. Click here for more details.
- socialcli-0.3.0.dist-info/METADATA +168 -0
- socialcli-0.3.0.dist-info/RECORD +224 -0
- socialcli-0.3.0.dist-info/WHEEL +4 -0
- socialcli-0.3.0.dist-info/entry_points.txt +3 -0
- socialcli-0.3.0.dist-info/licenses/LICENSE +21 -0
- socialctl/__init__.py +0 -0
- socialctl/__main__.py +6 -0
- socialctl/adapters/__init__.py +6 -0
- socialctl/adapters/base.py +68 -0
- socialctl/adapters/errores.py +56 -0
- socialctl/adapters/facebook.py +180 -0
- socialctl/adapters/instagram.py +442 -0
- socialctl/adapters/tiktok.py +535 -0
- socialctl/adapters/youtube.py +331 -0
- socialctl/agent_errors.py +176 -0
- socialctl/agent_guide.py +23 -0
- socialctl/approval_cli.py +27 -0
- socialctl/auth.py +139 -0
- socialctl/authflow.py +344 -0
- socialctl/brands.py +194 -0
- socialctl/capabilities.py +57 -0
- socialctl/capabilities.yml +5945 -0
- socialctl/cli.py +1766 -0
- socialctl/connection_service/__init__.py +0 -0
- socialctl/connection_service/__main__.py +33 -0
- socialctl/connection_service/app.py +496 -0
- socialctl/connection_service/assets/PLATFORM-LOGOS-LICENSE.txt +50 -0
- socialctl/connection_service/assets/connection.css +75 -0
- socialctl/connection_service/assets/facebook.webp +0 -0
- socialctl/connection_service/assets/instagram.svg +194 -0
- socialctl/connection_service/assets/socialcli-logo.png +0 -0
- socialctl/connection_service/assets/tiktok.png +0 -0
- socialctl/connection_service/assets/youtube.svg +1 -0
- socialctl/connection_service/landing.py +146 -0
- socialctl/connection_service/legacy.py +48 -0
- socialctl/connection_service/peer.py +13 -0
- socialctl/connection_service/providers.py +324 -0
- socialctl/connection_service/settings.py +76 -0
- socialctl/connection_service/store.py +124 -0
- socialctl/connections/__init__.py +0 -0
- socialctl/connections/account_cli.py +438 -0
- socialctl/connections/cli.py +379 -0
- socialctl/connections/client.py +126 -0
- socialctl/connections/credential_cli.py +224 -0
- socialctl/connections/credential_store.py +49 -0
- socialctl/connections/file_store.py +193 -0
- socialctl/connections/keychain.py +78 -0
- socialctl/connections/meta_user.py +81 -0
- socialctl/connections/rotation_cli.py +116 -0
- socialctl/connections/saas_client.py +91 -0
- socialctl/connections/temporary_media.py +62 -0
- socialctl/delivery_options.py +70 -0
- socialctl/engagement.py +200 -0
- socialctl/engagement_cli.py +50 -0
- socialctl/executor.py +135 -0
- socialctl/formatter.py +291 -0
- socialctl/hosted_media.py +152 -0
- socialctl/identity.py +200 -0
- socialctl/inbox.py +298 -0
- socialctl/inbox_cli.py +46 -0
- socialctl/inventory.py +155 -0
- socialctl/inventory_cli.py +171 -0
- socialctl/inventory_sources.py +101 -0
- socialctl/management/__init__.py +1 -0
- socialctl/management/batch_cli.py +115 -0
- socialctl/management/batches.py +325 -0
- socialctl/management/changes.py +485 -0
- socialctl/management/cli.py +227 -0
- socialctl/management/comments_cli.py +352 -0
- socialctl/management/community_batch_cli.py +63 -0
- socialctl/management/community_batches.py +294 -0
- socialctl/management/community_changes.py +370 -0
- socialctl/management/community_cli.py +142 -0
- socialctl/management/community_schema.py +119 -0
- socialctl/management/facebook_groups.py +1118 -0
- socialctl/management/groups_cli.py +274 -0
- socialctl/management/inbox_readers.py +87 -0
- socialctl/management/meta_changes.py +197 -0
- socialctl/management/meta_cli.py +342 -0
- socialctl/management/meta_client.py +631 -0
- socialctl/management/meta_comment_inbox.py +565 -0
- socialctl/management/meta_comments.py +587 -0
- socialctl/management/meta_errors.py +59 -0
- socialctl/management/meta_pagination.py +52 -0
- socialctl/management/meta_schema.py +128 -0
- socialctl/management/meta_webhooks.py +147 -0
- socialctl/management/metadata_parts.py +144 -0
- socialctl/management/owned_assets.py +85 -0
- socialctl/management/owned_changes.py +470 -0
- socialctl/management/owned_cli.py +128 -0
- socialctl/management/owned_reorder.py +62 -0
- socialctl/management/owned_schema.py +368 -0
- socialctl/management/reply_context.py +24 -0
- socialctl/management/reply_evidence.py +80 -0
- socialctl/management/resource_changes.py +407 -0
- socialctl/management/resource_cli.py +136 -0
- socialctl/management/snippet_readback.py +26 -0
- socialctl/management/stories.py +713 -0
- socialctl/management/stories_cli.py +172 -0
- socialctl/management/youtube.py +323 -0
- socialctl/management/youtube_community.py +326 -0
- socialctl/management/youtube_metadata.py +122 -0
- socialctl/management/youtube_owned.py +259 -0
- socialctl/management/youtube_resources.py +305 -0
- socialctl/media.py +269 -0
- socialctl/media_cli.py +183 -0
- socialctl/media_ingress.py +211 -0
- socialctl/media_preflight.py +114 -0
- socialctl/media_registry.py +301 -0
- socialctl/media_requirements.py +52 -0
- socialctl/metricas/__init__.py +6 -0
- socialctl/metricas/almacen.py +133 -0
- socialctl/metricas/analytics_changes.py +295 -0
- socialctl/metricas/analytics_cli.py +191 -0
- socialctl/metricas/analytics_client.py +304 -0
- socialctl/metricas/analytics_ingest.py +260 -0
- socialctl/metricas/analytics_schema.py +174 -0
- socialctl/metricas/base.py +147 -0
- socialctl/metricas/facebook.py +418 -0
- socialctl/metricas/insights.py +227 -0
- socialctl/metricas/instagram.py +133 -0
- socialctl/metricas/modelos.py +87 -0
- socialctl/metricas/piezas.py +134 -0
- socialctl/metricas/reach.py +94 -0
- socialctl/metricas/reporting_client.py +112 -0
- socialctl/metricas/resumen.py +251 -0
- socialctl/metricas/slugs.py +89 -0
- socialctl/metricas/tiktok.py +185 -0
- socialctl/metricas/youtube.py +403 -0
- socialctl/migration_cli.py +60 -0
- socialctl/migration_files.py +68 -0
- socialctl/models.py +150 -0
- socialctl/native_schedule/__init__.py +13 -0
- socialctl/native_schedule/api_delivery.py +15 -0
- socialctl/native_schedule/api_reconcile.py +40 -0
- socialctl/native_schedule/approval.py +160 -0
- socialctl/native_schedule/cadence.py +73 -0
- socialctl/native_schedule/cli.py +510 -0
- socialctl/native_schedule/dispatcher.py +120 -0
- socialctl/native_schedule/facebook.py +112 -0
- socialctl/native_schedule/facebook_reels.py +140 -0
- socialctl/native_schedule/first_comment.py +181 -0
- socialctl/native_schedule/handoff.py +193 -0
- socialctl/native_schedule/instagram_delivery.py +224 -0
- socialctl/native_schedule/instagram_runtime.py +66 -0
- socialctl/native_schedule/inventory.py +70 -0
- socialctl/native_schedule/migration.py +310 -0
- socialctl/native_schedule/models.py +103 -0
- socialctl/native_schedule/reconcile.py +83 -0
- socialctl/native_schedule/remote_data.py +177 -0
- socialctl/native_schedule/report.py +151 -0
- socialctl/native_schedule/store.py +560 -0
- socialctl/native_schedule/verification.py +32 -0
- socialctl/native_schedule/youtube.py +339 -0
- socialctl/operation_output.py +87 -0
- socialctl/plantillas/accounts.yml +33 -0
- socialctl/plantillas/brand.md +95 -0
- socialctl/plantillas/estrategia.md +64 -0
- socialctl/postfile.py +240 -0
- socialctl/preflight.py +73 -0
- socialctl/publication_policy.py +34 -0
- socialctl/publication_status.py +75 -0
- socialctl/publication_steps.py +398 -0
- socialctl/publish_output.py +96 -0
- socialctl/publisher.py +445 -0
- socialctl/queue_migration.py +302 -0
- socialctl/read_budget.py +224 -0
- socialctl/read_reports.py +91 -0
- socialctl/rutas.py +103 -0
- socialctl/saas/__init__.py +1 -0
- socialctl/saas/access.py +75 -0
- socialctl/saas/auth.py +213 -0
- socialctl/saas/backup.py +124 -0
- socialctl/saas/billing.py +327 -0
- socialctl/saas/billing_enrollment.py +1237 -0
- socialctl/saas/billing_enrollment_schema.py +519 -0
- socialctl/saas/billing_inventory.py +775 -0
- socialctl/saas/billing_reconcile.py +127 -0
- socialctl/saas/billing_routes.py +27 -0
- socialctl/saas/budget.py +66 -0
- socialctl/saas/connections.py +374 -0
- socialctl/saas/consent.py +52 -0
- socialctl/saas/lifecycle.py +341 -0
- socialctl/saas/mail.py +89 -0
- socialctl/saas/maintenance.py +68 -0
- socialctl/saas/meta_user.py +298 -0
- socialctl/saas/meta_webhooks.py +358 -0
- socialctl/saas/migration.py +107 -0
- socialctl/saas/models.py +8 -0
- socialctl/saas/operations.py +102 -0
- socialctl/saas/pages.py +126 -0
- socialctl/saas/pairing.py +158 -0
- socialctl/saas/permissions.py +57 -0
- socialctl/saas/reminders.py +128 -0
- socialctl/saas/renewal.py +74 -0
- socialctl/saas/restore_guard.py +229 -0
- socialctl/saas/revocation.py +97 -0
- socialctl/saas/rotation.py +114 -0
- socialctl/saas/routes.py +221 -0
- socialctl/saas/settings.py +34 -0
- socialctl/saas/store.py +106 -0
- socialctl/saas/temporary_media.py +245 -0
- socialctl/saas/webhooks.py +76 -0
- socialctl/schedule_remote.py +262 -0
- socialctl/schedule_sqlite.py +44 -0
- socialctl/scheduler.py +581 -0
- socialctl/scheduler_launchd.py +319 -0
- socialctl/scheduler_systemd.py +167 -0
- socialctl/source_links.py +119 -0
- socialctl/ui/__init__.py +1 -0
- socialctl/ui/assets/agent-manual.md +850 -0
- socialctl/ui/assets/agents.md +27 -0
- socialctl/ui/assets/components.css +20 -0
- socialctl/ui/assets/connection-layout.css +53 -0
- socialctl/ui/assets/otp.template.html +10 -0
- socialctl/ui/assets/tokens.css +1 -0
- socialctl/ui/assets/trial.template.html +11 -0
- socialctl/ui/assets/web-layout.css +38 -0
- socialctl/ui/email/otp.html +10 -0
- socialctl/ui/email/trial.html +11 -0
- socialctl/upload_consent.py +13 -0
- socialctl/workspace.py +8 -0
- socialctl/youtube_data.py +471 -0
- socialctl/youtube_data_service.py +225 -0
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
"""Local CLI for manual Facebook Group publication handoff."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import json
|
|
5
|
+
import os
|
|
6
|
+
import webbrowser
|
|
7
|
+
from datetime import datetime
|
|
8
|
+
from enum import Enum
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
import typer
|
|
12
|
+
from socialctl.approval_cli import read_approval
|
|
13
|
+
|
|
14
|
+
from socialctl.management.changes import ChangeError
|
|
15
|
+
from socialctl.management.cli import DEFAULT_ROOT, _brand, _fail
|
|
16
|
+
from socialctl.management.facebook_groups import (
|
|
17
|
+
CONFIRMATION_PHRASE,
|
|
18
|
+
GroupError,
|
|
19
|
+
GroupStore,
|
|
20
|
+
approve_handoff,
|
|
21
|
+
confirm_group,
|
|
22
|
+
export_queue,
|
|
23
|
+
load_group,
|
|
24
|
+
mark_handoff_opened,
|
|
25
|
+
prepare_group,
|
|
26
|
+
record_handoff_error,
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
group_app = typer.Typer(
|
|
31
|
+
help="Prepare manual Group publications; does not use or emulate the retired API."
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class ExportFormat(str, Enum):
|
|
36
|
+
JSON = "json"
|
|
37
|
+
TEXT = "text"
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _datetime(value: str, field: str) -> datetime:
|
|
41
|
+
try:
|
|
42
|
+
parsed = datetime.fromisoformat(value.replace("Z", "+00:00"))
|
|
43
|
+
except (TypeError, ValueError):
|
|
44
|
+
raise GroupError(f"{field} must be an ISO 8601 timestamp with timezone") from None
|
|
45
|
+
if parsed.utcoffset() is None:
|
|
46
|
+
raise GroupError(f"{field} must include a timezone")
|
|
47
|
+
return parsed
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def _json(value) -> str:
|
|
51
|
+
if hasattr(value, "model_dump"):
|
|
52
|
+
value = value.model_dump(mode="json")
|
|
53
|
+
return json.dumps(value, ensure_ascii=False, indent=2, sort_keys=True)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def render_group_preview(change) -> str:
|
|
57
|
+
if change.media:
|
|
58
|
+
dimensions = f"{change.media.width}x{change.media.height}"
|
|
59
|
+
duration = (
|
|
60
|
+
f"{change.media.duration_s} s"
|
|
61
|
+
if change.media.duration_s is not None
|
|
62
|
+
else "not applicable"
|
|
63
|
+
)
|
|
64
|
+
media = (
|
|
65
|
+
f"\n Path: {change.media.relative_path}\n"
|
|
66
|
+
f" SHA-256: {change.media.sha256}\n"
|
|
67
|
+
f" Size: {change.media.size_bytes} bytes\n"
|
|
68
|
+
f" Type: {change.media.kind}\n"
|
|
69
|
+
f" Dimensions: {dimensions}\n"
|
|
70
|
+
f" Duration: {duration}"
|
|
71
|
+
)
|
|
72
|
+
else:
|
|
73
|
+
media = " (no media)"
|
|
74
|
+
final_text = f"{change.copy_text}\n\n{change.youtube_url}"
|
|
75
|
+
return (
|
|
76
|
+
"FULL PREVIEW — manual Facebook Group publication\n"
|
|
77
|
+
f"ChangeSet: {change.id}\n"
|
|
78
|
+
f"Brand: {change.brand}\n"
|
|
79
|
+
f"Group: {change.destination.name}\n"
|
|
80
|
+
f"Group URL: {change.destination.url}\n"
|
|
81
|
+
f"Suggested window: {change.suggested_window.start.isoformat()} → "
|
|
82
|
+
f"{change.suggested_window.end.isoformat()}\n"
|
|
83
|
+
f"Existing media:{media}\n"
|
|
84
|
+
f"Status: {change.status}\n\n"
|
|
85
|
+
f"Final text to copy:\n{final_text}\n\n"
|
|
86
|
+
"Limitation: Meta retired the Groups API. socialcli will not send any POST, "
|
|
87
|
+
"scraping or private endpoint calls; user publishes manually.\n"
|
|
88
|
+
f"Exact fingerprint for approval: {change.fingerprint}"
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def render_handoff(change) -> str:
|
|
93
|
+
media = change.media.relative_path if change.media else "(no media)"
|
|
94
|
+
return (
|
|
95
|
+
"BROWSER HANDOFF — does not confirm publication\n"
|
|
96
|
+
f"1. Open: {change.destination.url}\n"
|
|
97
|
+
f"2. Copy exactly:\n{change.copy_text}\n\n{change.youtube_url}\n"
|
|
98
|
+
f"3. Attach existing media: {media}\n"
|
|
99
|
+
"4. Publish manually and save the post URL or a screenshot/PDF.\n"
|
|
100
|
+
f"5. Record the result with: socialcli group confirm {change.id} "
|
|
101
|
+
"--post-url URL --brand BRAND\n"
|
|
102
|
+
"Until confirmation, this status does not represent a publication."
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def _render_text(items: list[dict]) -> str:
|
|
107
|
+
if not items:
|
|
108
|
+
return "Groups queue is empty."
|
|
109
|
+
chunks = []
|
|
110
|
+
for item in items:
|
|
111
|
+
media = (item.get("media") or {}).get("relative_path") or "(no media)"
|
|
112
|
+
confirmation = item.get("confirmation") or {}
|
|
113
|
+
chunks.append(
|
|
114
|
+
f"[{item['status']}] {item['group']['name']} — {item['id']}\n"
|
|
115
|
+
f"Group: {item['group']['url']}\n"
|
|
116
|
+
f"Window: {item['suggested_window']['start']} → {item['suggested_window']['end']}\n"
|
|
117
|
+
f"Media: {media}\n"
|
|
118
|
+
f"Copy:\n{item['copy']}\n\n{item['youtube_url']}\n"
|
|
119
|
+
f"Confirmation supplied: {confirmation.get('post_url') or '(none)'}\n"
|
|
120
|
+
f"Reminder: {item['reminder']}"
|
|
121
|
+
)
|
|
122
|
+
return "\n\n".join(chunks)
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def _write_new(path: Path, content: str) -> None:
|
|
126
|
+
if ".secrets" in path.parts:
|
|
127
|
+
raise GroupError("export cannot be written inside .secrets")
|
|
128
|
+
if not path.parent.exists() or not path.parent.is_dir():
|
|
129
|
+
raise GroupError("export destination folder does not exist")
|
|
130
|
+
try:
|
|
131
|
+
descriptor = os.open(path, os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o600)
|
|
132
|
+
with os.fdopen(descriptor, "w", encoding="utf-8") as handle:
|
|
133
|
+
handle.write(content)
|
|
134
|
+
if not content.endswith("\n"):
|
|
135
|
+
handle.write("\n")
|
|
136
|
+
handle.flush()
|
|
137
|
+
os.fsync(handle.fileno())
|
|
138
|
+
except FileExistsError:
|
|
139
|
+
raise GroupError("export file already exists; it will not be overwritten") from None
|
|
140
|
+
except OSError as exc:
|
|
141
|
+
raise GroupError(f"failed to write export: {exc}") from None
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
@group_app.command("prepare")
|
|
145
|
+
def prepare(
|
|
146
|
+
group_name: str = typer.Option(..., "--group-name", help="Visible target Group name."),
|
|
147
|
+
group_url: str = typer.Option(..., "--group-url", help="Exact HTTPS URL /groups/GROUP."),
|
|
148
|
+
copy: str = typer.Option(..., "--copy", help="Exact supplied post text."),
|
|
149
|
+
youtube_url: str = typer.Option(..., "--youtube-url", help="Link to the long-form documentary."),
|
|
150
|
+
window_start: str = typer.Option(..., "--window-start", help="ISO 8601 start with timezone."),
|
|
151
|
+
window_end: str = typer.Option(..., "--window-end", help="ISO 8601 end with timezone."),
|
|
152
|
+
media: str | None = typer.Option(None, "--media", help="Optional path inside <Brand>/media/."),
|
|
153
|
+
brand: str = typer.Option(..., "--brand", help="Owning brand; never inferred."),
|
|
154
|
+
root: Path = typer.Option(DEFAULT_ROOT, "--root", help="Social project root."),
|
|
155
|
+
dry_run: bool = typer.Option(False, "--dry-run", help="Persist and display proposal; never publish."),
|
|
156
|
+
) -> None:
|
|
157
|
+
"""Validate and persist a local proposal without opening browser or accessing network."""
|
|
158
|
+
selected = _brand(root, brand)
|
|
159
|
+
try:
|
|
160
|
+
change = prepare_group(
|
|
161
|
+
selected,
|
|
162
|
+
GroupStore(selected.raiz),
|
|
163
|
+
group_name=group_name,
|
|
164
|
+
group_url=group_url,
|
|
165
|
+
copy=copy,
|
|
166
|
+
youtube_url=youtube_url,
|
|
167
|
+
window_start=_datetime(window_start, "window_start"),
|
|
168
|
+
window_end=_datetime(window_end, "window_end"),
|
|
169
|
+
media=media,
|
|
170
|
+
)
|
|
171
|
+
except (ChangeError, OSError, ValueError) as exc:
|
|
172
|
+
_fail(str(exc))
|
|
173
|
+
typer.echo("Remote DRY-RUN: local proposal persisted; no Facebook publication.")
|
|
174
|
+
typer.echo(render_group_preview(change))
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
@group_app.command("status")
|
|
178
|
+
def status(
|
|
179
|
+
change_id: str,
|
|
180
|
+
brand: str = typer.Option(..., "--brand"),
|
|
181
|
+
root: Path = typer.Option(DEFAULT_ROOT, "--root"),
|
|
182
|
+
) -> None:
|
|
183
|
+
"""Display ChangeSet and local journal without network access."""
|
|
184
|
+
selected = _brand(root, brand)
|
|
185
|
+
try:
|
|
186
|
+
change = load_group(selected, GroupStore(selected.raiz), change_id)
|
|
187
|
+
except (ChangeError, OSError, ValueError) as exc:
|
|
188
|
+
_fail(str(exc))
|
|
189
|
+
typer.echo(_json(change))
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
@group_app.command("export")
|
|
193
|
+
def export(
|
|
194
|
+
change_id: str | None = typer.Argument(None, help="Optional UUID; without it, export the entire queue."),
|
|
195
|
+
format: ExportFormat = typer.Option(ExportFormat.TEXT, "--format"),
|
|
196
|
+
output: Path | None = typer.Option(None, "--output", help="Optional new file; never overwritten."),
|
|
197
|
+
brand: str = typer.Option(..., "--brand"),
|
|
198
|
+
root: Path = typer.Option(DEFAULT_ROOT, "--root"),
|
|
199
|
+
) -> None:
|
|
200
|
+
"""Export JSON or readable views from local storage."""
|
|
201
|
+
selected = _brand(root, brand)
|
|
202
|
+
try:
|
|
203
|
+
items = export_queue(selected, GroupStore(selected.raiz), change_id)
|
|
204
|
+
content = _json({"version": 1, "authority": "local_manual_handoff", "items": items}) if format is ExportFormat.JSON else _render_text(items)
|
|
205
|
+
if output is not None:
|
|
206
|
+
_write_new(output, content)
|
|
207
|
+
else:
|
|
208
|
+
typer.echo(content)
|
|
209
|
+
except (ChangeError, OSError, ValueError) as exc:
|
|
210
|
+
_fail(str(exc))
|
|
211
|
+
if output is not None:
|
|
212
|
+
typer.echo(f"Local export written: {output}")
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
@group_app.command("handoff")
|
|
216
|
+
def handoff(
|
|
217
|
+
change_id: str,
|
|
218
|
+
approval_stdin: bool = typer.Option(False, "--approval-stdin", help="Explicitly read one approval line from stdin."),
|
|
219
|
+
approval_digest: str | None = typer.Option(None, "--approval-fingerprint", "--approval", "--approval-digest", help="Exact fingerprint from prepare."),
|
|
220
|
+
open_browser: bool = typer.Option(False, "--open-browser", help="Open a tab; do not publish or fill forms."),
|
|
221
|
+
brand: str = typer.Option(..., "--brand"),
|
|
222
|
+
root: Path = typer.Option(DEFAULT_ROOT, "--root"),
|
|
223
|
+
) -> None:
|
|
224
|
+
"""Approve package and hand it to user for manual publication."""
|
|
225
|
+
selected = _brand(root, brand)
|
|
226
|
+
store = GroupStore(selected.raiz)
|
|
227
|
+
try:
|
|
228
|
+
prepared = load_group(selected, store, change_id)
|
|
229
|
+
typer.echo(render_group_preview(prepared))
|
|
230
|
+
digest = read_approval(approval_digest, approval_stdin=approval_stdin)
|
|
231
|
+
change = approve_handoff(selected, store, change_id, digest)
|
|
232
|
+
typer.echo(render_handoff(change))
|
|
233
|
+
if open_browser and change.status == "handoff_ready":
|
|
234
|
+
try:
|
|
235
|
+
opened = webbrowser.open_new_tab(change.destination.url)
|
|
236
|
+
except OSError as exc:
|
|
237
|
+
record_handoff_error(selected, store, change_id, f"failed to open browser: {exc}")
|
|
238
|
+
raise GroupError("failed to open browser; handoff remains ready") from None
|
|
239
|
+
if not opened:
|
|
240
|
+
record_handoff_error(selected, store, change_id, "browser did not confirm opening")
|
|
241
|
+
raise GroupError("browser did not confirm opening; handoff remains ready")
|
|
242
|
+
change = mark_handoff_opened(selected, store, change_id)
|
|
243
|
+
typer.echo("Tab opened. socialcli has not published or filled the form.")
|
|
244
|
+
elif open_browser:
|
|
245
|
+
typer.echo("Handoff was already opened or confirmed; no additional tab will open.")
|
|
246
|
+
except (ChangeError, OSError, ValueError) as exc:
|
|
247
|
+
_fail(str(exc))
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
@group_app.command("confirm")
|
|
251
|
+
def confirm(
|
|
252
|
+
change_id: str,
|
|
253
|
+
post_url: str | None = typer.Option(None, "--post-url", help="Post URL in the same Group."),
|
|
254
|
+
evidence: str | None = typer.Option(None, "--evidence", help="Existing JPG/PNG/WebP/PDF, relative to the brand."),
|
|
255
|
+
confirmation: str | None = typer.Option(None, "--confirmation", help="Exact explicit confirmation phrase."),
|
|
256
|
+
brand: str = typer.Option(..., "--brand"),
|
|
257
|
+
root: Path = typer.Option(DEFAULT_ROOT, "--root"),
|
|
258
|
+
) -> None:
|
|
259
|
+
"""Record user-supplied evidence without querying or publishing to Facebook."""
|
|
260
|
+
selected = _brand(root, brand)
|
|
261
|
+
try:
|
|
262
|
+
phrase = confirmation or typer.prompt(f"Enter exactly {CONFIRMATION_PHRASE}")
|
|
263
|
+
change = confirm_group(
|
|
264
|
+
selected,
|
|
265
|
+
GroupStore(selected.raiz),
|
|
266
|
+
change_id,
|
|
267
|
+
confirmation_phrase=phrase,
|
|
268
|
+
post_url=post_url,
|
|
269
|
+
evidence=evidence,
|
|
270
|
+
)
|
|
271
|
+
except (ChangeError, OSError, ValueError) as exc:
|
|
272
|
+
_fail(str(exc))
|
|
273
|
+
typer.echo(_json(change))
|
|
274
|
+
typer.echo("Manual confirmation recorded; authority: user-supplied statement/evidence.")
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"""Command-local binding reuse for GET-only inbox scans.
|
|
2
|
+
|
|
3
|
+
These clients are never used for prepare/apply/reconcile. A pinned credential
|
|
4
|
+
and verified resource bindings last only for this scan, never across commands.
|
|
5
|
+
"""
|
|
6
|
+
from socialctl.management.youtube_community import YouTubeCommunityClient
|
|
7
|
+
from socialctl.management.youtube_resources import ResourceError
|
|
8
|
+
from socialctl.management.meta_comments import MetaCommentsClient, CommentError, _id
|
|
9
|
+
from socialctl.models import Platform
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class YouTubeInboxClient(YouTubeCommunityClient):
|
|
13
|
+
def __init__(self, brand, client):
|
|
14
|
+
super().__init__(brand, client)
|
|
15
|
+
self._scan_actor = None
|
|
16
|
+
self._scan_videos = {}
|
|
17
|
+
self._scan_threads = {}
|
|
18
|
+
|
|
19
|
+
def _request(self, method, url, **kwargs):
|
|
20
|
+
if method != 'GET':
|
|
21
|
+
raise ResourceError('Inbox scan is read-only')
|
|
22
|
+
return super()._request(method, url, **kwargs)
|
|
23
|
+
|
|
24
|
+
def _update_parts(self, *args, **kwargs):
|
|
25
|
+
raise ResourceError('Inbox scan is read-only')
|
|
26
|
+
|
|
27
|
+
def _authenticated_channel(self, token):
|
|
28
|
+
if self._scan_actor is None:
|
|
29
|
+
self._scan_actor = super()._authenticated_channel(token)
|
|
30
|
+
return self._scan_actor
|
|
31
|
+
|
|
32
|
+
def inspect(self, video_id):
|
|
33
|
+
if video_id not in self._scan_videos:
|
|
34
|
+
self._scan_videos[video_id] = super().inspect(video_id)
|
|
35
|
+
return self._scan_videos[video_id]
|
|
36
|
+
|
|
37
|
+
def list_threads(self, video_id, **kwargs):
|
|
38
|
+
report = super().list_threads(video_id, **kwargs)
|
|
39
|
+
for row in report['items']:
|
|
40
|
+
self._scan_threads[(video_id, row['id'])] = row
|
|
41
|
+
return report
|
|
42
|
+
|
|
43
|
+
def thread(self, video_id, thread_id):
|
|
44
|
+
key = (video_id, thread_id)
|
|
45
|
+
if key in self._scan_threads:
|
|
46
|
+
return self._scan_threads[key]
|
|
47
|
+
return super().thread(video_id, thread_id)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class MetaInboxClient(MetaCommentsClient):
|
|
51
|
+
def __init__(self, brand, platform, client):
|
|
52
|
+
super().__init__(brand, platform, client)
|
|
53
|
+
self._scan_media = {}
|
|
54
|
+
self._scan_parents = set()
|
|
55
|
+
|
|
56
|
+
def _request(self, method, path, **kwargs):
|
|
57
|
+
if method != 'GET':
|
|
58
|
+
raise CommentError('Inbox scan is read-only')
|
|
59
|
+
return super()._request(method, path, **kwargs)
|
|
60
|
+
|
|
61
|
+
def inspect_media(self, media_id):
|
|
62
|
+
media_id = _id(media_id)
|
|
63
|
+
if media_id not in self._scan_media:
|
|
64
|
+
self._scan_media[media_id] = super().inspect_media(media_id)
|
|
65
|
+
return self._scan_media[media_id]
|
|
66
|
+
|
|
67
|
+
def list_comments(self, media_id, *, parent_id=None, max_pages=100,
|
|
68
|
+
include_moderation=False, after=None):
|
|
69
|
+
if type(include_moderation) is not bool:
|
|
70
|
+
raise CommentError('include_moderation must be boolean')
|
|
71
|
+
media_id = _id(media_id)
|
|
72
|
+
self.inspect_media(media_id)
|
|
73
|
+
if parent_id is not None:
|
|
74
|
+
parent_id = _id(parent_id)
|
|
75
|
+
if (media_id, parent_id) not in self._scan_parents:
|
|
76
|
+
self.find_comment(media_id, parent_id)
|
|
77
|
+
result = self._list(parent_id or media_id,
|
|
78
|
+
'replies' if parent_id and self.platform is Platform.INSTAGRAM else 'comments',
|
|
79
|
+
max_pages, include_moderation=include_moderation, after=after)
|
|
80
|
+
if parent_id is None:
|
|
81
|
+
# Keep only unambiguous top-level rows with verifiable text and
|
|
82
|
+
# parent binding. Unknown parents still use the ordinary verifier.
|
|
83
|
+
from socialctl.management.meta_comment_inbox import verified_inbox_rows
|
|
84
|
+
rows, _ = verified_inbox_rows(result['data'], self.platform, media_id)
|
|
85
|
+
self._scan_parents.difference_update((media_id, row.get('id')) for row in result['data'] if isinstance(row.get('id'),str))
|
|
86
|
+
self._scan_parents.update((media_id, ident) for ident in rows)
|
|
87
|
+
return result
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
"""Immutable Meta proposals and durable operation receipts, independent of queues."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import hashlib
|
|
5
|
+
import hmac
|
|
6
|
+
import json
|
|
7
|
+
import re
|
|
8
|
+
import uuid
|
|
9
|
+
from contextlib import ExitStack
|
|
10
|
+
from datetime import datetime
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
from typing import Literal
|
|
13
|
+
|
|
14
|
+
from pydantic import BaseModel, ConfigDict, Field
|
|
15
|
+
|
|
16
|
+
from socialctl.management.changes import now_utc
|
|
17
|
+
from socialctl.management.resource_changes import ResourceStore
|
|
18
|
+
from socialctl.management.meta_schema import MetaError, MetaRejected, MetaUncertain, validate_edit
|
|
19
|
+
from socialctl.management.meta_errors import failure_details
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class MetaChange(BaseModel):
|
|
23
|
+
model_config = ConfigDict(extra="forbid")
|
|
24
|
+
id: str
|
|
25
|
+
version: Literal[1] = 1
|
|
26
|
+
kind: Literal["meta-management"] = "meta-management"
|
|
27
|
+
brand: str
|
|
28
|
+
brand_root: str
|
|
29
|
+
platform: Literal["facebook", "instagram"]
|
|
30
|
+
identity: dict
|
|
31
|
+
edit: dict
|
|
32
|
+
before: dict
|
|
33
|
+
created_at: datetime
|
|
34
|
+
updated_at: datetime
|
|
35
|
+
fingerprint: str = ""
|
|
36
|
+
status: Literal["proposed", "applying", "uncertain", "rejected", "conflict", "verified", "accepted_unverifiable"] = "proposed"
|
|
37
|
+
receipt: dict | None = None
|
|
38
|
+
result_id: str | None = None
|
|
39
|
+
native_schedule: dict | None = None
|
|
40
|
+
phases: list[dict] = Field(default_factory=list)
|
|
41
|
+
journal: list[dict] = Field(default_factory=list)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def fingerprint(change):
|
|
45
|
+
raw = change.model_dump(mode="json", exclude={"fingerprint", "updated_at", "status", "receipt", "result_id", "native_schedule", "phases", "journal"})
|
|
46
|
+
return hashlib.sha256(json.dumps(raw, sort_keys=True, ensure_ascii=False, separators=(",", ":")).encode()).hexdigest()
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class MetaStore(ResourceStore):
|
|
50
|
+
model_type = MetaChange
|
|
51
|
+
fingerprint_for = staticmethod(fingerprint)
|
|
52
|
+
|
|
53
|
+
def __init__(self, brand_root):
|
|
54
|
+
self.root = Path(brand_root) / ".socialctl" / "meta-management"
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def event(change, name, **details):
|
|
58
|
+
change.updated_at = now_utc()
|
|
59
|
+
change.journal.append({"at": change.updated_at.isoformat(), "event": name, **details})
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def prepare_meta(client, store, raw):
|
|
63
|
+
edit = validate_edit(raw)
|
|
64
|
+
client.require_write_capability(edit)
|
|
65
|
+
before = client.snapshot(edit)
|
|
66
|
+
moment = now_utc()
|
|
67
|
+
change = MetaChange(id=str(uuid.uuid4()), brand=client.brand.nombre,
|
|
68
|
+
brand_root=str(client.brand.raiz.resolve()), platform=client.platform.value,
|
|
69
|
+
identity=client.operation_identity(edit),
|
|
70
|
+
edit=edit.model_dump(exclude_none=True), before=before, created_at=moment, updated_at=moment)
|
|
71
|
+
change.fingerprint = fingerprint(change)
|
|
72
|
+
event(change, "prepared")
|
|
73
|
+
store.save(change)
|
|
74
|
+
return change
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def bound(client, change, *, read_only=False):
|
|
78
|
+
if (change.brand, change.brand_root, change.platform) != (client.brand.nombre, str(client.brand.raiz.resolve()), client.platform.value):
|
|
79
|
+
raise MetaError("brand/account does not match proposal")
|
|
80
|
+
edit = validate_edit(change.edit)
|
|
81
|
+
if read_only and client._uses_remote_user(edit):
|
|
82
|
+
if (client.account_id != change.identity['account_id'] or client.page_id != change.identity['page_id']):
|
|
83
|
+
raise MetaError('account changed since proposal')
|
|
84
|
+
# The status route authenticates the current connection and binds the
|
|
85
|
+
# exact approved identity. A historical receipt needs no new Graph grant.
|
|
86
|
+
return edit
|
|
87
|
+
if client.operation_identity(edit) != change.identity:
|
|
88
|
+
raise MetaError("token actor/account changed since proposal")
|
|
89
|
+
return edit
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def operation_key(change):
|
|
93
|
+
return json.dumps([change.brand_root, change.platform, change.identity["account_id"], change.edit["target_id"]])
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def normalized_readback_fields(edit, current, expected):
|
|
97
|
+
"""Recognize phone display separators, never infer a country code or digits."""
|
|
98
|
+
if edit.action != "profile-update" or "phone" not in (edit.patch or {}):
|
|
99
|
+
return {}
|
|
100
|
+
if {k:v for k,v in current.items() if k != "phone"} != {k:v for k,v in expected.items() if k != "phone"}:
|
|
101
|
+
return {}
|
|
102
|
+
values=[]
|
|
103
|
+
for value in (current.get("phone"), expected.get("phone")):
|
|
104
|
+
if not isinstance(value,str) or not re.fullmatch(r"\+[0-9][0-9 ().-]*",value):
|
|
105
|
+
return {}
|
|
106
|
+
number=re.sub(r"[ ().-]","",value)
|
|
107
|
+
if not re.fullmatch(r"\+[1-9][0-9]{6,14}",number):
|
|
108
|
+
return {}
|
|
109
|
+
values.append(number)
|
|
110
|
+
return {"phone":current["phone"]} if values[0] == values[1] and current != expected else {}
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def readback(client, store, change):
|
|
114
|
+
edit = bound(client, change, read_only=True)
|
|
115
|
+
if change.status in {"verified", "rejected", "conflict", "proposed"}:
|
|
116
|
+
return change
|
|
117
|
+
try:
|
|
118
|
+
if change.receipt is None or client._uses_remote_user(edit):
|
|
119
|
+
receipt = client.recover_receipt(edit, change)
|
|
120
|
+
if receipt is not None:
|
|
121
|
+
change.receipt = receipt
|
|
122
|
+
change.result_id = receipt.get('id', receipt.get('target_id', edit.target_id))
|
|
123
|
+
event(change, 'server_receipt_recovered_no_write')
|
|
124
|
+
if edit.action.endswith("-delete") or edit.action == "mention-reply" or edit.action == "schedule-cancel":
|
|
125
|
+
# A DELETE receipt confirms acceptance; an inaccessible node cannot
|
|
126
|
+
# independently prove absence. Preserve that distinction indefinitely.
|
|
127
|
+
if change.receipt:
|
|
128
|
+
change.status = "accepted_unverifiable"
|
|
129
|
+
event(change, "withdrawal_receipt_not_independent_absence_proof")
|
|
130
|
+
else:
|
|
131
|
+
current = client.snapshot(edit)
|
|
132
|
+
expected = client.expected(edit, change.before)
|
|
133
|
+
normalized = normalized_readback_fields(edit,current,expected) if change.receipt else {}
|
|
134
|
+
if (current == expected or normalized) and (change.receipt or current != change.before):
|
|
135
|
+
change.status = "verified"
|
|
136
|
+
event(change, "readback_verified", **({"normalized_fields":normalized} if normalized else {}))
|
|
137
|
+
else:
|
|
138
|
+
event(change, "readback_mismatch_no_retry")
|
|
139
|
+
except MetaError as exc:
|
|
140
|
+
event(change, "readback_unavailable", **failure_details(exc, token=client._token, read_only=True))
|
|
141
|
+
store.save(change)
|
|
142
|
+
return change
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def reconcile_meta(client, store, change_id):
|
|
146
|
+
with store.apply_lock(change_id):
|
|
147
|
+
change = store.load(change_id)
|
|
148
|
+
if change.status == "applying":
|
|
149
|
+
change.status = "uncertain"
|
|
150
|
+
return readback(client, store, change)
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def apply_meta(client, store, change_id, approval_digest):
|
|
154
|
+
with ExitStack() as locks:
|
|
155
|
+
locks.enter_context(store.apply_lock(change_id))
|
|
156
|
+
change = store.load(change_id)
|
|
157
|
+
if not hmac.compare_digest(change.fingerprint, approval_digest):
|
|
158
|
+
raise MetaError("approval does not match exact fingerprint")
|
|
159
|
+
edit = bound(client, change, read_only=change.status != 'proposed')
|
|
160
|
+
key = operation_key(change)
|
|
161
|
+
locks.enter_context(store.apply_lock(str(uuid.uuid5(uuid.NAMESPACE_URL, key))))
|
|
162
|
+
if change.status != "proposed":
|
|
163
|
+
if change.status == "applying":
|
|
164
|
+
change.status = "uncertain"
|
|
165
|
+
return readback(client, store, change)
|
|
166
|
+
client.require_write_capability(edit)
|
|
167
|
+
for path in store.root.glob("*.json"):
|
|
168
|
+
other = store.load(path.stem)
|
|
169
|
+
if other.id != change.id and operation_key(other) == key and other.status in {"applying", "uncertain"}:
|
|
170
|
+
raise MetaError(f"uncertain outcome pending {other.id}; another UUID cannot bypass it")
|
|
171
|
+
if client.snapshot(edit) != change.before:
|
|
172
|
+
change.status = "conflict"
|
|
173
|
+
event(change, "remote_changed_no_write")
|
|
174
|
+
store.save(change)
|
|
175
|
+
raise MetaError("resource changed since preview")
|
|
176
|
+
change.status = "applying"
|
|
177
|
+
event(change, "write_intent", approval_digest=approval_digest)
|
|
178
|
+
store.save(change)
|
|
179
|
+
try:
|
|
180
|
+
change.receipt = client.mutate(edit, change=change)
|
|
181
|
+
except MetaRejected as exc:
|
|
182
|
+
change.status = "rejected"
|
|
183
|
+
event(change, "write_rejected", **failure_details(exc, token=client._token, read_only=False))
|
|
184
|
+
except Exception as exc:
|
|
185
|
+
change.status = "uncertain"
|
|
186
|
+
event(change, "write_uncertain_no_retry", **failure_details(exc, token=client._token, read_only=False))
|
|
187
|
+
else:
|
|
188
|
+
change.status = "uncertain"
|
|
189
|
+
if edit.action in {"schedule-reprogram", "schedule-cancel"}:
|
|
190
|
+
change.native_schedule = {
|
|
191
|
+
"remote_id": edit.target_id,
|
|
192
|
+
"planner_visibility": "not_verifiable",
|
|
193
|
+
}
|
|
194
|
+
change.result_id = change.receipt.get("id", change.receipt.get('target_id', edit.target_id))
|
|
195
|
+
event(change, "write_receipt_saved")
|
|
196
|
+
store.save(change)
|
|
197
|
+
return readback(client, store, change)
|