Feature: Timeline agent task creation from selected media. Enable the timeline agent LLM to create generation tasks (style transfer, subject transfer, scene transfer, combinations, image-to-video) using the existing create-task edge function. When the user selects images/videos on the timeline and gives instructions, the agent should: 1) Create a new shot containing the selected anchor images, 2) Call the existing create-task edge function to submit style-transfer, subject-transfer, scene-transfer, or image-to-video tasks based on user intent and selected media. The agent needs tool definitions and system prompt instructions explaining how to use these task types, what parameters they need, and how to create shots. Should reuse the unified task creation system already in the codebase.
User notes and answers:
User answers: Q1: Default to qwen-image unless user suggests otherwise. Q2: Image-to-video IS in scope — use travel_between_images approach, part of the work is getting that resolving logic into the edge function. Q3: Shot creation is conditional — only create a new shot when the selected images don't already belong to a shot that matches what we need. Q4: Switch to the new family/input API format, fix the old generate command.
code
Plan:
# Implementation Plan: Timeline Agent Task Creation from Selected Media
Overview
The timeline agent currently has a single run tool with text commands for timeline editing. It has a basic generate command that creates image generation tasks, but it:
Uses the oldtask_type/params API format — the create-task edge function now requires family/input, so the current generate command is likely broken
Only supports basic text-to-image generation — no reference images, no style/subject/scene transfer, no image-to-video
Has no shot creation capability
The image_generation family resolver (create-task/resolvers/imageGeneration.ts) already supports reference_mode (style, subject, scene, style-character, custom) with style_reference_image/subject_reference_image parameters. There are no separate transfer task families — it's all the family with reference mode settings.
Assistant
{"checks":[],"flags":[{"id":"FLAG-001","concern":"Timeline agent shot linking: the plan never adds the clip->generation/shot resolution and multi-anchor linking needed to create or reuse a shot from selected timeline media, so the new shot path would either be empty or only attach a single anchor.","category":"correctness","severity_hint":"likely-significant","evidence":"The incoming selection payload only carries clip_id/url/media_type (), while the shot RPCs operate on generation IDs ( needs , needs : , ). The timeline registry can expose (), but the plan's Step 2/Step 4 only mentions or optional single-generation linking and never covers resolving selected clips to generation IDs, attaching multiple selected anchors, or checking whether the anchors already belong to a reusable shot as required by the user note."},{"id":"FLAG-002","concern":"Timeline agent i2v scope: the plan still narrows image-to-video out of the implementation and its proposed tool schema cannot express the existing contract, so it misses an explicitly in-scope feature.","category":"completeness","severity_hint":"likely-significant","evidence":"The accepted override says image-to-video is in scope via (), but the plan metadata still assumes 'Image-to-video is out of scope' () and the proposed schema only supports plus a single (). The repository already has a resolver, and it requires structured arrays like , , , and (, )."}],"verified_flag_ids":[],"disputed_flag_ids":[]}
image_generation
Approach: Add a structured create_task LLM tool (separate from the text-based run tool) that accepts JSON parameters for task creation. This is better than extending the text command parser because task creation has complex parameters (URLs, modes, counts) that are more reliably expressed as structured JSON. Also fix the existing generate command to use the new family/input API format.
Phase 1: Fix existing generation + extend for reference modes
Step 1: Update createGenerationTask to use family/input format (supabase/functions/ai-timeline-agent/tools/generation.ts)
Scope: Medium
Refactor the createGenerationTask function (lines 42-97) to:
Accept extended args including reference_image_url, reference_mode, shot_id, model_name
Build the request body using { family: "image_generation", project_id, input: { ... } } format
Map the input to match BatchImageGenerationTaskInput expected by the resolver:
model_name (default to "qwen-image" when using reference images, since only qwen-image and z-image support reference params per supportsReferenceParams() at imageGeneration.ts:102-104)
Update the CreateGenerationTaskArgs interface (lines 3-10) to include the new fields.
Keep backward compatibility: existing generate command still works (just prompt + count), but now also supports the extended params.
Step 2: Add shot creation capability (supabase/functions/ai-timeline-agent/tools/shots.ts — new file)
Add a second tool definition to TIMELINE_AGENT_TOOLS array (currently only has run):
typescript
{
type: "function",
function: {
name: "create_task",
description: "Create a generation task. Use with selected clip URLs for style/subject/scene transfer, or standalone for text-to-image.",
parameters: {
type: "object",
properties: {
prompt: { type: "string", description: "What to generate" },
task_type: { type: "string", enum: ["text-to-image", "style-transfer", "subject-transfer", "scene-transfer"], description: "Type of generation" },
reference_image_url: { type: "string", description: "URL of the reference image (from selected clips)" },
count: { type: "number", description: "Number of images to generate (default 1)" },
shot_name: { type: "string", description: "Optional: create a new shot with this name to hold results" },
},
required: ["prompt", "task_type"],
},
},
}
Step 4: Wire create_task tool in the agent loop (supabase/functions/ai-timeline-agent/loop.ts)
Scope: Medium
Update the tool call extraction and execution logic. Currently, the loop extracts commands from run tool calls and executes them via executeCommand. For create_task tool calls, route to a dedicated handler.
Key change in the loop's command extraction (around lines 203-215): when a tool call has name: "create_task", don't parse it as a text command — instead call createGenerationTask directly with the structured args.
Maptask_type to reference_mode:
"text-to-image" → no reference mode
"style-transfer" → reference_mode: "style", style_reference_image from reference_image_url
"subject-transfer" → reference_mode: "subject", style_reference_image + subject_reference_image from reference_image_url
"scene-transfer" → reference_mode: "scene", style_reference_image from reference_image_url
If shot_name provided: create the shot first via the shots utility, then pass shot_id to the task creation.
Step 5: Update the system prompt (supabase/functions/ai-timeline-agent/prompts.ts)
Scope: Small
Add instructions explaining the create_task tool to the system prompt (lines 24-44):
When user selects images and asks for style/subject/scene transfer, use create_task
Explain the task types and when to use each
Show example tool calls:
code
create_task(prompt="a sunset beach", task_type="style-transfer", reference_image_url="<url from selected clips>")
Remind the agent that selected clip URLs are available in the context
Step 6: Update command extraction to handle multi-tool responses (supabase/functions/ai-timeline-agent/loop.ts)
Scope: Small
Ensure the loop's tool call handling (lines 162-282) correctly processes both run and create_task tool calls in the same response.
The existing extraction handles structured tool_calls from the LLM response (line 203). This already supports multiple tool names in principle — verify it routes create_task calls to the right handler instead of trying to parse them as text commands.
Phase 3: Integration and testing
Step 7: Update the run tool description to exclude generate overlap (supabase/functions/ai-timeline-agent/tool-schemas.ts)
Scope: Small
Removegenerate from the run tool description since create_task supersedes it. Keep the generate command parser working for backward compat with in-flight sessions, but don't advertise it.
Update the run description to mention that generation should use create_task instead.
Step 8: Manual testing checklist
Scope: Info
Select an image on the timeline → ask "make variations in this style" → verify create_task is called with style-transfer and the clip URL
Select an image → ask "put this character in a forest" → verify subject-transfer
Select an image → ask "recreate this scene with different lighting" → verify scene-transfer
Ask "generate a sunset" with no selection → verify basic text-to-image still works
Ask "generate in this style and put it in a new shot called 'sunset'" → verify shot creation + task creation
Execution Order
Step 1 first (fix the broken generate command with new API format)
Steps 2-4 can proceed in parallel (shot creation, tool schema, loop wiring)
Step 5 after Step 4 (prompt depends on knowing the final tool shape)
Steps 6-7 after core wiring is done
Step 8 is manual verification
Key Files Changed
supabase/functions/ai-timeline-agent/tools/generation.ts — main refactor
supabase/functions/ai-timeline-agent/tools/shots.ts — new file
supabase/functions/ai-timeline-agent/prompts.ts — update system prompt
supabase/functions/ai-timeline-agent/types.ts — may need extended types
code
Plan metadata:
{
"version": 1,
"timestamp": "2026-04-03T21:30:11Z",
"hash": "sha256:8c576929e06c0116f6f0a34a420018b03b97b3fcd19d03b1a572f58f0a5826da",
"questions": [
"The image_generation resolver requires model_name to be 'qwen-image' or 'z-image' for reference params to work (style/subject/scene). Should the agent default to 'qwen-image' for reference tasks, or should the user/prompt control model selection?",
"The idea mentions image-to-video tasks. There's no simple i2v resolver in create-task \u2014 video generation uses complex orchestration (travel_between_images, join_clips, edit_video_orchestrator). Should we scope i2v out of this initial implementation and focus on image generation with reference modes?",
"Should shot creation be automatic (agent always creates a shot for task results) or explicit (agent decides based on user intent)? The idea says 'create a new shot containing the selected anchor images' but it's unclear if this should happen for every task.",
"The existing generate command appears to use the old task_type/params API format which the create-task edge function no longer accepts. Is this already known to be broken, or is there a fallback I'm missing?"
],
"success_criteria": [
{
"criterion": "Agent can create style-transfer tasks using selected clip URLs as reference images",
"priority": "must"
},
{
"criterion": "Agent can create subject-transfer tasks using selected clip URLs",
"priority": "must"
},
{
"criterion": "Agent can create scene-transfer tasks using selected clip URLs",
"priority": "must"
},
{
"criterion": "Basic text-to-image generation (no reference) still works via the agent",
"priority": "must"
},
{
"criterion": "Task creation uses the family/input API format expected by create-task edge function",
"priority": "must"
},
{
"criterion": "Agent can create a new shot and associate generated results with it",
"priority": "must"
},
{
"criterion": "System prompt clearly explains when and how to use each task type",
"priority": "must"
},
{
"criterion": "create_task tool has structured JSON parameters (not text parsing) for reliable LLM usage",
"priority": "should"
},
{
"criterion": "Selected clip URLs from the frontend are correctly passed through to the reference image parameters",
"priority": "must"
},
{
"criterion": "Existing timeline editing commands (move, trim, delete, etc.) are unaffected",
"priority": "must"
},
{
"criterion": "New tool integrates cleanly with the existing agent loop (tool_call/tool_result turn format, error handling, auto-continuation)",
"priority": "should"
},
{
"criterion": "No new files over ~300 lines",
"priority": "should"
},
{
"criterion": "Supabase edge function deployed and tested with real task creation",
"priority": "info"
}
],
"assumptions": [
"The create-task edge function now requires family/input format \u2014 the old task_type/params format the agent uses is broken or deprecated. Will fix as part of this work.",
"Style/subject/scene transfer are all handled by the image_generation family with reference_mode parameter \u2014 no new resolvers needed.",
"Image-to-video is out of scope for this initial implementation due to complexity of video orchestration resolvers.",
"The agent will default to qwen-image model when reference images are used, since only qwen-image and z-image support reference params in the resolver.",
"Shot creation will be optional/explicit \u2014 the agent creates a shot only when the user asks or when it makes contextual sense, not automatically for every task.",
"The create_task tool will be a separate structured tool alongside run, not a new text command, for reliability with complex parameters.",
"The agent already receives selected clip URLs via the selected_clips payload \u2014 no frontend changes needed."
],
"structure_warnings": []
}
code
Plan structure warnings from validator:
[]
Existing flags:
[]
Known accepted debt grouped by subsystem:
{
"agent-chat-rendering": [
{
"id": "DEBT-007",
"concern": "removing the duplicate assistant turn may hide message_user text if the frontend only renders assistant-role turns as chat bubbles.",
"occurrence_count": 1,
"plan_ids": [
"refactor-ai-timeline-agent-20260326-0157"
]
}
],
"agent-chat-undo-integration": [
{
"id": "DEBT-018",
"concern": "agent chat edits arrive via query invalidation/realtime polling and will bypass the undo stack because those paths are marked skiphistory.",
"occurrence_count": 1,
"plan_ids": [
"implement-undo-redo-history-20260326-2240"
]
}
],
"bulk-panel-tabs": [
{
"id": "DEBT-010",
"concern": "text clip multi-selections would miss the position tab under the plan's stated rule.",
"occurrence_count": 1,
"plan_ids": [
"multi-select-feature-parity-20260326-0548"
]
}
],
"bulk-properties-panel": [
{
"id": "DEBT-016",
"concern": "bulkclippanel still imports customeffecteditor; removing it without updating bulk mode would break the build.",
"occurrence_count": 1,
"plan_ids": [
"build-an-llm-powered-custom-20260326-2230"
]
}
],
"clip-drag-scroll-sync": [
{
"id": "DEBT-015",
"concern": "the plan's step 3 ontick callback only shows coordinator.update() but the full clip-drag state path (snap, lateststart, ghost positions) also needs re-running during stationary-pointer scroll.",
"occurrence_count": 1,
"plan_ids": [
"add-auto-scroll-to-the-20260326-2119"
]
}
],
"clip-param-schema-evolution": [
{
"id": "DEBT-019",
"concern": "clips with stale or partial params from a previous schema version will not be automatically normalized/backfilled when the effect schema changes.",
"occurrence_count": 1,
"plan_ids": [
"add-tuneable-parameters-to-20260326-2332"
]
}
],
"conflict-resolution": [
{
"id": "DEBT-004",
"concern": "silently reloading agent-originated timeline updates would discard dirty local edits.",
"occurrence_count": 1,
"plan_ids": [
"build-a-turn-based-timeline-20260326-0005"
]
},
{
"id": "DEBT-021",
"concern": "if all 3 conflict retries fail, the fallback path risks discarding dirty local edits unless the executor wires it into the existing conflict dialog.",
"occurrence_count": 1,
"plan_ids": [
"light-megaplan-fix-the-20260327-0056"
]
}
],
"context-menu-scope": [
{
"id": "DEBT-012",
"concern": "multi-clip copy is not included despite being mentioned in the original idea.",
"occurrence_count": 1,
"plan_ids": [
"multi-select-feature-parity-20260326-0548"
]
}
],
"drop-indicator-plumbing": [
{
"id": "DEBT-023",
"concern": "dropindicator reads position.trackid without it being declared on the dropindicatorposition interface or forwarded by toindicatorposition().",
"occurrence_count": 1,
"plan_ids": [
"two-ux-improvements-1-drop-to-20260327-0520"
]
}
],
"edit-mode-persistence": [
{
"id": "DEBT-026",
"concern": "legacy persisted 'enhance' values might exist in storage",
"occurrence_count": 1,
"plan_ids": [
"refactor-edit-mode-ownership-20260331-1842"
]
},
{
"id": "DEBT-027",
"concern": "no-migration assumption for enhance\u2192upscale is under-supported",
"occurrence_count": 1,
"plan_ids": [
"refactor-edit-mode-ownership-20260331-1842"
]
},
{
"id": "DEBT-030",
"concern": "enhance/upscale only partially resolved \u2014 persisted values not validated",
"occurrence_count": 1,
"plan_ids": [
"refactor-edit-mode-ownership-20260331-1842"
]
},
{
"id": "DEBT-032",
"concern": "no read-side normalization test for legacy 'enhance' values",
"occurrence_count": 1,
"plan_ids": [
"refactor-edit-mode-ownership-20260331-1842"
]
}
],
"edit-mode-validation": [
{
"id": "DEBT-028",
"concern": "validation grep for 'enhance' will false-fail due to video code",
"occurrence_count": 1,
"plan_ids": [
"refactor-edit-mode-ownership-20260331-1842"
]
},
{
"id": "DEBT-029",
"concern": "grep scope too broad \u2014 hits video submode code",
"occurrence_count": 1,
"plan_ids": [
"refactor-edit-mode-ownership-20260331-1842"
]
},
{
"id": "DEBT-031",
"concern": "validation scope reaches unrelated video code",
"occurrence_count": 1,
"plan_ids": [
"refactor-edit-mode-ownership-20260331-1842"
]
}
],
"effect-layer-overlap-enforcement": [
{
"id": "DEBT-022",
"concern": "the plan relies on same-track overlap being forbidden but does not explicitly specify the enforcement call (resolveoverlaps or range rejection) in the drop/create path.",
"occurrence_count": 1,
"plan_ids": [
"add-adjustment-layer-effect-20260327-0358"
]
}
],
"issue-detection": [
{
"id": "DEBT-006",
"concern": "mid-sentence-cut detection is not implementable without transcript/profile data that the current provider doesn't expose.",
"occurrence_count": 1,
"plan_ids": [
"build-a-turn-based-timeline-20260326-0005"
]
}
],
"legacy-effect-lifecycle": [
{
"id": "DEBT-017",
"concern": "removing customeffecteditor makes effects-table entries read-only \u2014 users can no longer edit legacy custom effects.",
"occurrence_count": 1,
"plan_ids": [
"build-an-llm-powered-custom-20260326-2230"
]
}
],
"optimistic-locking": [
{
"id": "DEBT-002",
"concern": "plan only specifies version checking at the db write layer; the ui load/state/save path doesn't carry config_version yet.",
"occurrence_count": 1,
"plan_ids": [
"build-a-turn-based-timeline-20260326-0005"
]
}
],
"properties-panel-scope": [
{
"id": "DEBT-011",
"concern": "crop and transition controls are not included in the bulk panel, narrowing the original idea's scope.",
"occurrence_count": 1,
"plan_ids": [
"multi-select-feature-parity-20260326-0548"
]
}
],
"realtime-subscriptions": [
{
"id": "DEBT-003",
"concern": "the shared realtime system doesn't know about timeline_agent_sessions; step 7 hooks need their own channel subscription.",
"occurrence_count": 1,
"plan_ids": [
"build-a-turn-based-timeline-20260326-0005"
]
}
],
"registry-patch-testing": [
{
"id": "DEBT-020",
"concern": "patchregistry() lacks automated regression tests \u2014 the duplicate-id bug's most likely reproduction path is covered only by pure-function tests on the assembler it delegates to, plus manual smoke testing.",
"occurrence_count": 1,
"plan_ids": [
"light-megaplan-consolidate-20260327-0022"
]
}
],
"selection-save-bridge": [
{
"id": "DEBT-009",
"concern": "the plan specifies passing pruneselection into usetimelinesave but doesn't detail the hook-layer bridge needed because usetimelinesave is instantiated inside usetimelinedata before usetimelinestate runs.",
"occurrence_count": 1,
"plan_ids": [
"multi-select-timeline-clips-20260326-0415"
]
}
],
"task-deduplication": [
{
"id": "DEBT-001",
"concern": "server-generated idempotency keys would break retry deduplication because retried requests get fresh keys.",
"occurrence_count": 1,
"plan_ids": [
"migrate-all-task-creation-20260325-2354"
]
}
],
"task-system-integration": [
{
"id": "DEBT-005",
"concern": "create_generation_task is underspecified against the actual task family system.",
"occurrence_count": 1,
"plan_ids": [
"build-a-turn-based-timeline-20260326-0005"
]
}
],
"tool-error-propagation": [
{
"id": "DEBT-008",
"concern": "a blanket catch in executetool would silently downgrade db/persistence failures into ordinary tool results, changing the session error/http 500 behavior.",
"occurrence_count": 1,
"plan_ids": [
"refactor-ai-timeline-agent-20260326-0157"
]
}
],
"track-reorder-accessibility": [
{
"id": "DEBT-013",
"concern": "replacing arrow buttons with drag-only handle removes keyboard-accessible reorder; plan only specifies pointersensor.",
"occurrence_count": 1,
"plan_ids": [
"fix-track-reordering-bugs-and-20260326-1856"
]
}
],
"track-reorder-testing": [
{
"id": "DEBT-014",
"concern": "no automated tests specified for same-kind boundary rules or save/load persistence of reordered tracks.",
"occurrence_count": 1,
"plan_ids": [
"fix-track-reordering-bugs-and-20260326-1856"
]
}
],
"vlm-cold-gpu-diagnostics": [
{
"id": "DEBT-025",
"concern": "the cold-gpu vlm import crash investigation is deferred \u2014 the plan ships the zombie fix without root-causing the specific import failure.",
"occurrence_count": 1,
"plan_ids": [
"fix-worker-zombie-bug-when-20260330-2035"
]
}
],
"workspace-git-hygiene": [
{
"id": "DEBT-024",
"concern": "step 2 discards unstaged edits in 6 files via git checkout head without first confirming the revert was unintentional.",
"occurrence_count": 1,
"plan_ids": [
"two-ux-improvements-1-drop-to-20260327-0520"
]
}
]
}
code
Escalated debt subsystems:
[
{
"subsystem": "edit-mode-persistence",
"total_occurrences": 4,
"plan_count": 1,
"entries": [
{
"id": "DEBT-026",
"concern": "legacy persisted 'enhance' values might exist in storage",
"occurrence_count": 1,
"plan_ids": [
"refactor-edit-mode-ownership-20260331-1842"
]
},
{
"id": "DEBT-027",
"concern": "no-migration assumption for enhance\u2192upscale is under-supported",
"occurrence_count": 1,
"plan_ids": [
"refactor-edit-mode-ownership-20260331-1842"
]
},
{
"id": "DEBT-030",
"concern": "enhance/upscale only partially resolved \u2014 persisted values not validated",
"occurrence_count": 1,
"plan_ids": [
"refactor-edit-mode-ownership-20260331-1842"
]
},
{
"id": "DEBT-032",
"concern": "no read-side normalization test for legacy 'enhance' values",
"occurrence_count": 1,
"plan_ids": [
"refactor-edit-mode-ownership-20260331-1842"
]
}
]
},
{
"subsystem": "edit-mode-validation",
"total_occurrences": 3,
"plan_count": 1,
"entries": [
{
"id": "DEBT-028",
"concern": "validation grep for 'enhance' will false-fail due to video code",
"occurrence_count": 1,
"plan_ids": [
"refactor-edit-mode-ownership-20260331-1842"
]
},
{
"id": "DEBT-029",
"concern": "grep scope too broad \u2014 hits video submode code",
"occurrence_count": 1,
"plan_ids": [
"refactor-edit-mode-ownership-20260331-1842"
]
},
{
"id": "DEBT-031",
"concern": "validation scope reaches unrelated video code",
"occurrence_count": 1,
"plan_ids": [
"refactor-edit-mode-ownership-20260331-1842"
]
}
]
}
]
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/reigh-workspace/reigh-app/.megaplan/plans/feature-timeline-agent-task-20260403-2324/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.