You are already running inside the megaplan harness for this step. Do the requested planning/review/execution work directly. Do NOT invoke the megaplan CLI, do NOT read or activate the megaplan skill, do NOT start nested megaplan plans, and do NOT recurse into another planning harness. Treat mentions of megaplan in the repository or environment as implementation context only.
You are an independent reviewer. Critique the plan against the actual repository.
Add a direct post mode to share_to_social that accepts media URLs + tweet text directly, without requiring a Discord message. This is needed so we can post tweets (e.g. reply to a banodoco tweet with a video) using external media URLs (like Supabase video links) rather than needing a Discord message reference. The tool should still support scheduled_at, action (post/reply/retweet), target_post, and route_override. It should download the media from the URL to a temp file, then feed it through the existing upload/publish pipeline. Keep it minimal — don't restructure the existing message-based flow, just add an alternative entry path.
code
Plan:
# Implementation Plan: Direct Post Mode for share_to_social
Overview
The share_to_social tool (src/features/admin_chat/tools.py:189) currently requires a Discord message reference (message_link or message_id) as its entry point. All media, user context, and guild/channel metadata are derived from the fetched Discord message. We need to add an alternative "direct post" path that accepts media_urls (list of external URLs) and tweet_text directly, bypassing the Discord message entirely.
Key existing infrastructure:
sharer._download_media_from_url(url, message_id, item_index) (sharer.py:84) already downloads arbitrary URLs to temp files with the exact dict shape needed for media_hints
SocialPublishRequest (models.py:22) requires message_id, channel_id, guild_id, user_id — in direct mode these must be synthesized from admin context
Route resolution (_prepare_request_for_delivery) uses guild_id + channel_id to find a social route; with route_key override this is bypassed
Assistant
trusted_guild_id is available in the execute_tool dispatcher (tools.py:3923) but not currently passed to execute_share_to_social
Approach: Add media_urls (list of strings) to the tool schema. When media_urls is provided without a message reference, enter the direct-post path: download each URL via _download_media_from_url, construct a SocialPublishRequest using the admin's guild context, and feed it through the existing publish pipeline. Skip duplicate detection, announce policy, first-share notification, and legacy shared post tracking (all Discord-message-specific).
Addmedia_urls property to the share_to_social input schema:
json
"media_urls": {
"type": "array",
"items": {"type": "string"},
"description": "Direct media URLs to post (e.g. Supabase video links). Use instead of message_link/message_id for external media. tweet_text is required when using media_urls."
}
Update the tool description string to mention the direct-post mode: "Also supports direct posting with media_urls + tweet_text, bypassing Discord message lookup."
Step 2: Pass guild context to execute_share_to_social (src/features/admin_chat/tools.py:3956-3957)
Scope: Small
Update the dispatcher call at line 3957 to pass trusted_guild_id:
Update the execute_share_to_social signature (line 1799) to accept guild_id: Optional[int] = None.
Step 3: Implement direct-post branch in execute_share_to_social (src/features/admin_chat/tools.py:1879-1895)
Scope: Medium
Extractmedia_urls from params at the top of the function (near line 1807).
After the existing parameter validation block (around line 1878, after scheduled_at parsing), replace the current "Parse link or use direct ID" block (lines 1879-1895) with a three-way branch:
If media_urls is provided (direct-post mode):
Validate tweet_text is provided (required in direct mode, since there's no message to derive text from)
Validate action != 'retweet' or return error (retweet needs a target, not media)
Use the passed-in guild_id (from dispatcher) or return error if missing
Use a sentinel message_id = 0 and channel_id = 0 for the publication record
Download each URL via sharer._download_media_from_url(url, 'direct', index)
Collect results into downloaded_attachments; fail if any download fails
Skip duplicate detection (no real message_id to check)
announce_policy={'enabled': False} (no Discord message to link back to)
first_share_notification_policy={'enabled': False} (no Discord user)
legacy_shared_post_policy={'enabled': False}
source_context with metadata containing just {'guild_id': guild_id}
All other fields (action, target_post_ref, scheduled_at, route_override, text_only, platform) from the existing param parsing
Route to the same publish/enqueue path as the existing flow
Return the same response shape (tweet_url, tweet_id, publication_id, success)
Skip _announce_tweet_url and first-share notification (no Discord user/message)
Else if message_link or message_id — existing flow (unchanged)
Else — existing error: "Provide either message_link, message_id, or media_urls"
Ensure temp file cleanup runs in the finally block for the direct-post path too (mirror the existing pattern at lines 2030-2035).
Step 4: Update admin chat system prompt (src/features/admin_chat/agent.py:141)
Scope: Small
Update the share_to_social description in the agent system prompt to mention the direct-post capability, so the LLM knows it can use media_urls + tweet_text without a Discord message.
Step 5: Validate (tests/)
Scope: Small
Run existing tests to confirm no regressions: python -m pytest tests/ -x -q
Check that the tool schema is valid JSON (no syntax errors from the edit).
Manually trace the direct-post code path to verify:
Empty media_urls list → falls through to require message_link/message_id
Execution Order
Steps 1-2 first (schema + plumbing) — no behavioral change yet.
Step 3 (core implementation) — the actual new code path.
Step 4 (prompt update) — so the admin chat LLM can discover the feature.
Step 5 (validation) — run tests and verify.
Validation Order
Run existing test suite first to establish baseline.
After implementation, re-run tests to confirm no regressions.
Review the new code path for correctness of the SocialPublishRequest construction.
code
Plan metadata:
{
"version": 1,
"timestamp": "2026-04-12T19:28:33Z",
"hash": "sha256:1391a8bae0a76cace59a5a8c5e3fdf1caf8de4b09f2d9b81fa58df78bd33b385",
"questions": [
"Should media_urls support a single URL string as well as a list, or strictly require an array?",
"For the publication record, is message_id=0 acceptable for the database schema (e.g. foreign key constraints, unique indexes on message_id+platform+action), or should we use a synthetic ID?",
"Should route_key be required in direct-post mode (since there's no channel to resolve a route from), or should we fall back to the guild's default route?"
],
"success_criteria": [
{
"criterion": "share_to_social accepts media_urls + tweet_text and posts a tweet with the downloaded media without requiring a Discord message reference",
"priority": "must"
},
{
"criterion": "Existing message-based share_to_social flow is completely unchanged \u2014 all current parameters and behaviors work identically",
"priority": "must"
},
{
"criterion": "Direct-post mode supports scheduled_at, action (post/reply), target_post, and route_key parameters",
"priority": "must"
},
{
"criterion": "Direct-post mode returns error if tweet_text is missing",
"priority": "must"
},
{
"criterion": "Media files are cleaned up from temp directory after publish (both success and failure)",
"priority": "must"
},
{
"criterion": "All existing tests pass without modification",
"priority": "must"
},
{
"criterion": "New code path adds fewer than 80 lines to execute_share_to_social",
"priority": "should"
},
{
"criterion": "Tool schema description clearly documents when to use media_urls vs message_link/message_id",
"priority": "should"
},
{
"criterion": "Direct-post mode tested end-to-end with a real Supabase media URL posting to Twitter",
"priority": "info"
}
],
"assumptions": [
"media_urls will be a JSON array of URL strings; we will not accept a single string (the LLM can wrap it in an array)",
"route_key will be recommended but not strictly required in direct-post mode \u2014 if omitted, route resolution will use guild_id + channel_id=0 which should fall through to the guild's default route if one exists",
"message_id=0 and channel_id=0 are safe sentinel values for the publication record (no FK constraints in the social_publications table that would reject them)",
"user_id=0 is acceptable for direct posts since there is no Discord user associated with external media",
"The existing _download_media_from_url on sharer is reliable for Supabase URLs and does not need modification",
"Direct-post mode does not need duplicate detection since there is no stable message_id to deduplicate against"
],
"structure_warnings": []
}
code
Plan structure warnings from validator:
[]
Existing flags:
[]
Known accepted debt grouped by subsystem:
{
"admin-chat-classification": [
{
"id": "DEBT-006",
"concern": "anthropic client may not be initialized when interceptor fires before _ensure_agent.",
"occurrence_count": 1,
"plan_ids": [
"admin-triggered-payments-let-20260410-1448"
]
}
],
"admin-payments-intent-state": [
{
"id": "DEBT-004",
"concern": "button confirmation path does not directly update admin_payment_intents \u2014 intent sync happens indirectly via handle_payment_result on terminal state.",
"occurrence_count": 1,
"plan_ids": [
"admin-triggered-payments-let-20260410-1448"
]
},
{
"id": "DEBT-005",
"concern": "no direct bridge from paymentconfirmview to admin_payment_intents.",
"occurrence_count": 1,
"plan_ids": [
"admin-triggered-payments-let-20260410-1448"
]
},
{
"id": "DEBT-008",
"concern": "awaiting_admin_init stale cleanup only runs at cog_load, not periodically, so stranded verified-batch intents could remain active until restart",
"occurrence_count": 1,
"plan_ids": [
"identity-based-routing-for-20260411-0256"
]
},
{
"id": "DEBT-009",
"concern": "scheduling glue for periodic _reconcile_admin_chat_orphans invocation is not in the plan",
"occurrence_count": 1,
"plan_ids": [
"identity-based-routing-for-20260411-0256"
]
},
{
"id": "DEBT-010",
"concern": "awaiting_admin_init in the active set has broader effects on active-intent callers across the repo until restart",
"occurrence_count": 1,
"plan_ids": [
"identity-based-routing-for-20260411-0256"
]
}
],
"db-handler-social-publications": [
{
"id": "DEBT-001",
"concern": "mixing fluent client, raw sql, and rpc access patterns in one subsystem increases maintenance surface.",
"occurrence_count": 1,
"plan_ids": [
"implement-a-unified-social-20260409-1710"
]
}
],
"db-handler-supabase-infrastructure": [
{
"id": "DEBT-002",
"concern": "supabase rpc is untested in this codebase and may require dashboard configuration.",
"occurrence_count": 1,
"plan_ids": [
"implement-a-unified-social-20260409-1710"
]
}
],
"payment-service-confirmation": [
{
"id": "DEBT-007",
"concern": "success criterion bundles null-recipient dm wiring with cap-breach/collision dm wiring; step 1 only does log+return-none for null-recipient.",
"occurrence_count": 1,
"plan_ids": [
"harden-the-solana-payment-20260410-2147"
]
}
],
"social-channel-routes": [
{
"id": "DEBT-003",
"concern": "route management tooling is absent, leaving the routing system inert until manual db inserts.",
"occurrence_count": 1,
"plan_ids": [
"implement-a-unified-social-20260409-1710"
]
}
]
}
code
Escalated debt subsystems:
[
{
"subsystem": "admin-payments-intent-state",
"total_occurrences": 5,
"plan_count": 2,
"entries": [
{
"id": "DEBT-004",
"concern": "button confirmation path does not directly update admin_payment_intents \u2014 intent sync happens indirectly via handle_payment_result on terminal state.",
"occurrence_count": 1,
"plan_ids": [
"admin-triggered-payments-let-20260410-1448"
]
},
{
"id": "DEBT-005",
"concern": "no direct bridge from paymentconfirmview to admin_payment_intents.",
"occurrence_count": 1,
"plan_ids": [
"admin-triggered-payments-let-20260410-1448"
]
},
{
"id": "DEBT-008",
"concern": "awaiting_admin_init stale cleanup only runs at cog_load, not periodically, so stranded verified-batch intents could remain active until restart",
"occurrence_count": 1,
"plan_ids": [
"identity-based-routing-for-20260411-0256"
]
},
{
"id": "DEBT-009",
"concern": "scheduling glue for periodic _reconcile_admin_chat_orphans invocation is not in the plan",
"occurrence_count": 1,
"plan_ids": [
"identity-based-routing-for-20260411-0256"
]
},
{
"id": "DEBT-010",
"concern": "awaiting_admin_init in the active set has broader effects on active-intent callers across the repo until restart",
"occurrence_count": 1,
"plan_ids": [
"identity-based-routing-for-20260411-0256"
]
}
]
}
]
code
Debt guidance:
- These are known accepted limitations. Do not re-flag them unless the current plan makes them worse, broadens them, or fails to contain them.
- Prefix every new concern with a subsystem tag followed by a colon, for example `Timeout recovery: retry backoff remains brittle`.
- When a concern is recurring debt that still needs to be flagged, prefix it with `Recurring debt:` after the subsystem tag, for example `Timeout recovery: Recurring debt: retry backoff remains brittle`.
Your output template is at: /Users/user_c042661f/Documents/banodoco-workspace/brain-of-bndc/.megaplan/plans/add-a-direct-post-mode-to-20260412-2125/critique_output.json
Review the plan with a broad scope. Consider whether the approach is correct, whether it covers
all the places it needs to, whether it would break callers or violate codebase conventions,
and whether its verification strategy is adequate.
Place any concrete concerns in the flags array in the template file using the standard format
(id, concern, category, severity_hint, evidence). Leave checks as an empty array.
Workflow: read the file → investigate → read file again → add findings → write file back.
code
Additional guidelines:
- Robustness level: light. Be pragmatic. Only flag issues that would cause real failures. Ignore style, minor edge cases, and issues the executor will naturally resolve.
- Over-engineering: prefer the simplest approach that fully solves the problem.
- Reuse existing flag IDs when the same concern is still open.
- `verified_flag_ids`: list flag IDs from prior iterations that the revised plan actually resolves (e.g., if the plan was revised to fix FLAG-001, and you confirm the fix is correct, include "FLAG-001"). Only include flags you've verified — don't guess.
- Verify that the plan follows the expected structure when validator warnings or the outline suggest drift.
- Additional flags may use these categories: correctness, security, completeness, performance, maintainability, other.
- Focus on concrete issues, not structural formatting.
{"checks":[],"flags":[{"id":"FLAG-001","concern":"Sharing pipeline: direct mode's scheduled media path is not viable if it only downloads external URLs to temp files and enqueues the existing request payload.","category":"correctness","severity_hint":"likely-significant","evidence":"The plan says direct mode should download each media URL to a temp file, support scheduled posts, and clean temp files in a finally block. But SocialPublishService.enqueue() persists request_payload as-is (src/features/sharing/social_publish_service.py:128-144, 325-329), execute_publication() later reconstructs the request from that payload (src/features/sharing/social_publish_service.py:150-188, 464-485), and the X posting path requires each attachment's local_path to still exist when the queued job runs (src/features/sharing/subfeatures/social_poster.py:418-426). A queued direct post with downloaded temp media will therefore fail once those files are cleaned up or disappear between processes."},{"id":"FLAG-002","concern":"Social publishing metadata: the proposed direct request shape drops user_details, but the X provider currently refuses to publish without it.","category":"correctness","severity_hint":"likely-significant","evidence":"The plan's direct branch constructs source_context with only {'guild_id': guild_id} and uses user_id=0. In the actual pipeline, XProvider.publish() reads metadata.get('user_details') and returns failure if it is missing (src/features/sharing/providers/x_provider.py:29-33). The current admin-chat message path explicitly loads member data and passes it through source_context.metadata['user_details'] (src/features/admin_chat/tools.py:1944-2008). Passing only guild_id is not enough to reach a successful publish."},{"id":"FLAG-003","concern":"Admin chat social sharing: the plan narrows direct mode to media_urls-driven posts/replies and explicitly errors on retweets, which does not match the requested no-Discord direct mode support for action including retweet.","category":"completeness","severity_hint":"likely-significant","evidence":"The requested behavior says the tool should support direct posting without a Discord message while still supporting action (post/reply/retweet), target_post, and route override. The proposed branch only enters direct mode when media_urls is present, otherwise it keeps the current message_link/message_id requirement, and it additionally proposes returning an error for action='retweet'. That means retweets without a Discord message still are not supported, and text-only direct replies/posts without media_urls would also fall back to the old message-based requirement."}],"verified_flag_ids":[],"disputed_flag_ids":[]}