@mevdragon/vidfarm-devcli 0.2.1 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/.env.example +6 -39
  2. package/GETTING_STARTED.developers.md +87 -0
  3. package/README.md +94 -238
  4. package/SKILL.developer.md +430 -104
  5. package/dist/src/account-pages.js +1 -1
  6. package/dist/src/app.js +93 -5
  7. package/dist/src/cli.js +456 -8
  8. package/dist/src/config.js +3 -2
  9. package/dist/src/context.js +30 -11
  10. package/dist/src/db.js +2 -57
  11. package/dist/src/dev-app.js +0 -1
  12. package/dist/src/index.js +4 -2
  13. package/dist/src/lib/template-paths.js +21 -0
  14. package/dist/src/runtime.js +3 -1
  15. package/dist/src/services/auth.js +4 -4
  16. package/dist/src/services/job-logs.js +186 -0
  17. package/dist/src/services/jobs.js +3 -2
  18. package/dist/src/services/providers.js +14 -6
  19. package/dist/src/services/storage.js +85 -2
  20. package/dist/src/services/template-sources.js +29 -3
  21. package/dist/templates/template_0000/src/lib/images.js +46 -86
  22. package/dist/templates/template_0000/src/template.js +277 -53
  23. package/package.json +5 -6
  24. package/templates/template_0000/README.md +8 -52
  25. package/templates/template_0000/SKILL.md +35 -3
  26. package/templates/template_0000/package.json +3 -6
  27. package/templates/template_0000/src/lib/images.js +46 -86
  28. package/templates/template_0000/src/lib/images.ts +55 -98
  29. package/templates/template_0000/src/template-dna.js +9 -0
  30. package/templates/template_0000/src/template.js +523 -199
  31. package/templates/template_0000/src/template.ts +356 -61
  32. package/templates/template_0000/template.config.json +7 -12
  33. package/AWS_REMOTION_HANDOFF.md +0 -311
  34. package/PLATFORM_SPEC.md +0 -1039
  35. package/SKILL.director.md +0 -599
  36. package/dist/infra/cdk/bin/vidfarm-prod.js +0 -59
  37. package/dist/infra/cdk/lib/vidfarm-prod-stack.js +0 -212
  38. package/templates/template_0000/package-lock.json +0 -5505
  39. package/templates/template_0000/scripts/create-site.mjs +0 -27
  40. package/templates/template_0000/scripts/render-cloud.mjs +0 -72
@@ -5,30 +5,79 @@ description: Build and extend Vidfarm templates as a third-party developer. Use
5
5
 
6
6
  # Vidfarm Third-Party Developer
7
7
 
8
- This skill is for third-party template developers authoring Vidfarm templates locally.
8
+ This skill is for AI agents and developers authoring Vidfarm templates locally.
9
9
 
10
- Scope this skill to:
10
+ Primary goal:
11
11
 
12
- - creating a new template
12
+ - make "here is a media file, turn this into a reusable template" a complete, executable workflow
13
+
14
+ Use this skill for:
15
+
16
+ - creating a new template under `templates/*`
13
17
  - extending an existing template under `templates/*`
14
- - adding or refining template operations and jobs
15
- - improving local template authoring workflow
16
- - wiring template behavior to the developer's own AI provider keys
17
- - validating template behavior through the local CLI and API
18
+ - revising a template from natural-language feedback
19
+ - analyzing source media into `viral_dna` and `visual_dna`
20
+ - wiring prompts, operations, jobs, and local Remotion output
21
+ - validating the template through the local CLI and REST API
18
22
 
19
23
  Do not use this skill for:
20
24
 
21
- - platform auth, billing, storage, webhook, or database internals
22
- - developer console work under `/dev`
23
- - production Docker or deployment changes
24
- - shared AWS or release-admin workflows
25
- - cloud Remotion publishing or cloud render setup
25
+ - platform auth, billing, database, or webhook internals
26
+ - production deploys, release admin, or shared cloud infrastructure
27
+ - asking for AWS, S3, Remotion cloud, or other platform secrets
26
28
 
27
- For third-party developers, Remotion is local. Do not require cloud Remotion credentials or shared AWS details in this skill.
29
+ For third-party developers, Remotion is local and storage should be accessed through Vidfarm helpers. Do not require cloud Remotion setup or hand-written S3 integration for normal template work.
28
30
 
29
- ## Required Developer Env
31
+ ## Agent Operating Rule
32
+
33
+ If the user gives you a media file, a screenshot, a folder of source assets, or a link to an original viral post and says some variant of "turn this into a template", you should default to this workflow:
34
+
35
+ 1. inspect the source media and extract the repeatable format
36
+ 2. scaffold a new template with `vidfarm-devcli generate-template`
37
+ 3. stage the source notes and preview media inside the template
38
+ 4. run `analyze-viral-dna`
39
+ 5. run `analyze-visual-dna`
40
+ 6. implement the template operations and jobs
41
+ 7. wire prompt logic, provider usage, storage writes, and local Remotion output
42
+ 8. expose the template through the standard REST routes
43
+ 9. validate the template locally with `validate-template` plus at least one real job run
44
+ 10. update the template-local `SKILL.md` so future agents can operate it
45
+
46
+ Do not stop after scaffolding. The expected outcome is a runnable template, not just a folder.
47
+
48
+ If the user gives revision feedback in natural language, treat that as a normal template-authoring input, not as a vague suggestion. Example revision prompts:
49
+
50
+ - "make the hook feel more curiosity-driven"
51
+ - "the captions are too low and get covered by TikTok UI"
52
+ - "preserve the exact composition from frame 3"
53
+ - "the pacing is too slow"
54
+ - "make this work for product screenshots instead of faces"
55
+
56
+ Your job is to translate that feedback into concrete template changes, rerun validation, and keep iterating until the template is reliable enough to reuse.
57
+
58
+ ## Minimum Inputs
30
59
 
31
- Third-party developers should only need their own API credentials and Vidfarm API auth.
60
+ You can start from any of these:
61
+
62
+ - one image file
63
+ - one video file
64
+ - multiple screenshots or clips in a folder
65
+ - a URL to the original post
66
+ - a short written explanation of the format
67
+ - a natural-language revision request against an existing template
68
+
69
+ When creating a brand-new template, prefer staging raw inspiration material in a repo-local `drafts/` folder first. This gives the developer one obvious place to drag in source media and rough notes before asking an agent to build the template.
70
+
71
+ Recommended intake layout:
72
+
73
+ - `drafts/source_notes.md` for rough notes, links, and adaptation goals
74
+ - `drafts/preview/` for raw screenshots, clips, frames, or other inspiration media
75
+
76
+ If the developer already has files elsewhere in the repo, relative paths are still fine. But when the user says some variant of "use the files in `drafts/` to make a template", treat that as the default starting point.
77
+
78
+ If the source is weak, still scaffold the template and create `research/source_notes.md` with the missing questions called out. Do not block template creation on perfect research.
79
+
80
+ ## Required Developer Env
32
81
 
33
82
  Typical `.env`:
34
83
 
@@ -38,69 +87,349 @@ OPENAI_API_KEY=""
38
87
  OPENROUTER_API_KEY=""
39
88
  PERPLEXITY_API_KEY=""
40
89
 
41
- VIDFARM_USER_ID=""
42
90
  VIDFARM_API_KEY=""
43
91
  ```
44
92
 
45
93
  Notes:
46
94
 
47
- - at least one AI provider key is usually enough
48
- - `VIDFARM_USER_ID` and `VIDFARM_API_KEY` are needed when calling the Vidfarm API directly
49
- - do not ask third-party developers for platform secrets like `ENCRYPTION_SECRET`, `API_KEY_SALT`, `WEBHOOK_SECRET`, admin emails, S3 config, or generic AWS credentials
50
- - do not ask third-party developers for `REMOTION_AWS_ACCESS_KEY_ID` or `REMOTION_AWS_SECRET_ACCESS_KEY`
95
+ - at least one runtime AI provider key is usually enough
96
+ - `GEMINI_API_KEY` is the key used by the built-in DNA analysis commands
97
+ - `VIDFARM_API_KEY` is needed when calling a hosted Vidfarm API directly, including when minting presigned preview-media uploads through `vidfarm-devcli presign-preview-media`
98
+ - local `vidfarm-devcli session` already gives you a seeded local API key for the local runtime
99
+ - when calling the hosted API directly, include both `vidfarm-user-id` and `vidfarm-api-key` headers
100
+ - for local `vidfarm-devcli` sessions, you usually do not need to supply `VIDFARM_USER_ID` manually
101
+ - template authoring is TypeScript-first; create and edit template source as `src/template.ts`, not `src/template.js`
102
+ - keep exploratory scripts, one-off test runners, scratch validation files, and temporary job-driving code out of `src/`; place them in a repo-local tmp folder that is a sibling to `src` instead, for example `templates/vidfarm_template_0007/tmp/`
103
+ - when registering a hosted template source, set `template_module_path` to the repo-relative TypeScript entrypoint inside the template folder, for example `templates/vidfarm_template_example/src/template.ts`; the platform build/import flow resolves the compiled `src/template.js` sibling after `npm run build`
104
+ - do not ask for platform secrets like `ENCRYPTION_SECRET`, `API_KEY_SALT`, `WEBHOOK_SECRET`, admin emails, S3 config, or generic AWS credentials
105
+ - do not ask for `REMOTION_AWS_ACCESS_KEY_ID` or `REMOTION_AWS_SECRET_ACCESS_KEY`
106
+
107
+ ## Template Deploy Cycle
108
+
109
+ If the user says "do a template deploy cycle", interpret that as:
110
+
111
+ 1. push the repo changes that contain the target template folder
112
+ 2. import that template commit into the hosted platform as a template source release
113
+ 3. approve and activate the new release
114
+ 4. run the prod deploy script if platform code changed, or reuse the current prod image for a formal restart if the change was template-only
115
+
116
+ Do not assume "template deploy cycle" means "deploy the entire dirty root repo". If the root worktree has unrelated changes and the release is template-only, prefer reusing the current prod image with:
117
+
118
+ ```bash
119
+ scripts/deploy-prod-inplace.sh --image-uri <current-prod-image> --skip-check --skip-build
120
+ ```
51
121
 
52
122
  ## First Read
53
123
 
54
- Read these files first when working on a template:
124
+ Read these files first when doing template work:
55
125
 
56
126
  1. [GETTING_STARTED.developers.md](/Users/localghost/Projects/OfficeX/OfficeX/ZoomGTM/vidfarm/GETTING_STARTED.developers.md)
57
- 2. [templates/template_0000/SKILL.md](/Users/localghost/Projects/OfficeX/OfficeX/ZoomGTM/vidfarm/templates/template_0000/SKILL.md)
58
- 3. [templates/template_0000/src/template.ts](/Users/localghost/Projects/OfficeX/OfficeX/ZoomGTM/vidfarm/templates/template_0000/src/template.ts)
59
- 4. [src/template-sdk.ts](/Users/localghost/Projects/OfficeX/OfficeX/ZoomGTM/vidfarm/src/template-sdk.ts)
60
- 5. [src/cli.ts](/Users/localghost/Projects/OfficeX/OfficeX/ZoomGTM/vidfarm/src/cli.ts)
127
+ 2. [README.md](/Users/localghost/Projects/OfficeX/OfficeX/ZoomGTM/vidfarm/README.md)
128
+ 3. [templates/template_0000/SKILL.md](/Users/localghost/Projects/OfficeX/OfficeX/ZoomGTM/vidfarm/templates/template_0000/SKILL.md)
129
+ 4. [templates/template_0000/src/template.ts](/Users/localghost/Projects/OfficeX/OfficeX/ZoomGTM/vidfarm/templates/template_0000/src/template.ts)
130
+ 5. [src/template-sdk.ts](/Users/localghost/Projects/OfficeX/OfficeX/ZoomGTM/vidfarm/src/template-sdk.ts)
131
+ 6. [src/cli.ts](/Users/localghost/Projects/OfficeX/OfficeX/ZoomGTM/vidfarm/src/cli.ts)
61
132
 
62
133
  If the task is narrow, read only the template files and CLI slice relevant to that task.
63
134
 
64
135
  ## Mental Model
65
136
 
66
- A template is an internal module loaded by Vidfarm, but third-party developers should work at the template layer, not the platform layer.
137
+ A Vidfarm template is a local module loaded by the platform. Work at the template layer, not the platform layer.
138
+
139
+ The contract is:
140
+
141
+ - `defineTemplate({...})` declares the public template
142
+ - `operations` define the public async API surface
143
+ - `jobs` implement the actual work
144
+ - `configSchema` defines editable per-user template config
145
+ - `about.viral_dna` and `about.visual_dna` explain why the format wins
146
+ - `SKILL.md` teaches humans and agents how to call the template correctly
147
+ - the canonical template entrypoint is `src/template.ts`
148
+
149
+ Every public template action should remain async and job-based. Prefer one or more named operations behind `POST /api/v1/templates/:templateId/operations/:operationName` instead of inventing custom synchronous endpoints.
150
+
151
+ Templates are expected to evolve through multiple revisions. One-shot generation is not the standard. The standard is:
152
+
153
+ - create a working first pass
154
+ - gather feedback in plain English
155
+ - modify the template
156
+ - re-run the job
157
+ - repeat until output is dependable
158
+
159
+ ## Provider And Model Dependency Rule
160
+
161
+ The current template standard does not have a first-class `dependencies`, `requirements`, or `supportedModels` field in `defineTemplate({...})`.
67
162
 
68
- The normal workflow is:
163
+ Until the standard grows one, agents should document AI dependencies in two places for every template that uses external models:
69
164
 
70
- 1. define template metadata and schemas
71
- 2. expose one or more operations
72
- 3. implement the job workflows behind those operations
73
- 4. test locally through the Vidfarm CLI and REST API
74
- 5. iterate until the template can be rerun reliably
165
+ 1. in the template-local `SKILL.md`
166
+ 2. near the top of `src/template.ts` as a checked-in constant or clearly named comment block
75
167
 
76
- Every public template action should remain async and job-based. Prefer fitting new behavior into the existing operation and job pattern instead of inventing one-off synchronous endpoints.
168
+ That documentation should describe:
169
+
170
+ - supported provider names
171
+ - allowed model IDs per provider
172
+ - which capability each model is intended for, such as `text`, `image`, `layout_analysis`, or `video`
173
+ - whether the list is strict, preferred, or just known-good defaults
174
+ - any runtime caveats, especially when a provider is only partially supported by the current platform adapter
175
+
176
+ Use this shape as the current documentation convention:
177
+
178
+ ```ts
179
+ const TEMPLATE_PROVIDER_REQUIREMENTS = {
180
+ text: [
181
+ { provider: "openai", models: ["gpt-5.4"], strict: false },
182
+ { provider: "gemini", models: ["gemini-3.1-flash-lite", "gemini-2.5-flash-lite"], strict: false },
183
+ { provider: "openrouter", models: ["qwen/qwen3.6-flash"], strict: false }
184
+ ],
185
+ image: [
186
+ { provider: "openai", models: ["gpt-image-1", "gpt-image-2"], strict: false },
187
+ { provider: "gemini", models: ["gemini-3.1-flash-image-preview", "gemini-2.5-flash-image"], strict: false },
188
+ { provider: "openrouter", models: ["bytedance/seedance-2.0", "bytedance-seed/seedream-4.5"], strict: false }
189
+ ],
190
+ video: [
191
+ { provider: "openai", models: ["sora-2"], strict: false },
192
+ { provider: "gemini", models: ["veo-3.0-generate-001"], strict: false }
193
+ ]
194
+ } as const;
195
+ ```
196
+
197
+ Important:
198
+
199
+ - this is documentation for humans and agents, not a framework-consumed schema field
200
+ - do not pretend a provider/model pair is supported if the runtime adapter does not actually implement that path yet
201
+ - if the runtime only supports a subset, mark the rest as planned or aspirational in `SKILL.md`
202
+ - when a template depends on reference-image attachments, call out whether that currently works for all providers or only some of them
203
+
204
+ ## Golden Path: Media To Template
205
+
206
+ Use this flow whenever the task is "make a new template from this source".
207
+
208
+ ### 1. Stage raw inspiration in `drafts/`
209
+
210
+ Before scaffolding, encourage the developer to place source material in a repo-local `drafts/` folder.
211
+
212
+ Suggested layout:
213
+
214
+ ```txt
215
+ drafts/
216
+ source_notes.md
217
+ preview/
218
+ screenshot-01.png
219
+ clip-01.mp4
220
+ ```
221
+
222
+ This is the preferred handoff shape for agent-driven template creation. A Vidfarm developer should be able to drag media into `drafts/preview/`, add rough notes to `drafts/source_notes.md`, then tell the agent to create a template from those relative paths.
223
+
224
+ If the source media is not already present in the repo, upload it into the authenticated developer preview-media namespace first instead of inventing ad hoc external hosting. Use:
225
+
226
+ ```bash
227
+ npx @mevdragon/vidfarm-devcli presign-preview-media \
228
+ --file ./local/path/to/screenshot-01.png \
229
+ --directory drafts/preview
230
+ ```
231
+
232
+ That command calls the hosted Vidfarm API with the user's `VIDFARM_API_KEY`, mints a presigned PUT URL scoped under `developer/<user_id>/preview_media/*`, and returns both the `storage_key` and a Vidfarm `preview_media_url`. Agents should prefer that path for hosted preview uploads.
233
+
234
+ ### 2. Start local runtime
235
+
236
+ ```bash
237
+ npx @mevdragon/vidfarm-devcli dev --port 3310 --reset
238
+ npx @mevdragon/vidfarm-devcli session
239
+ ```
240
+
241
+ This boots the local API, worker, SQLite state, provider-key seeding, and local Remotion rendering.
242
+
243
+ ### 3. Choose a new template slug and folder
244
+
245
+ Use a folder name that starts with `vidfarm_template_`, such as `templates/vidfarm_template_<nnnn>/`.
246
+
247
+ Example:
248
+
249
+ ```bash
250
+ npx @mevdragon/vidfarm-devcli generate-template \
251
+ --slug-id template_0007 \
252
+ --template-dir ./templates/vidfarm_template_0007 \
253
+ --link-to-original "https://www.tiktok.com/@example/video/1234567890" \
254
+ --source-notes-path ./drafts/source_notes.md \
255
+ --source-preview-dir ./drafts/preview
256
+ ```
257
+
258
+ What this does:
259
+
260
+ - copies the starter template into the new folder
261
+ - rewrites IDs, names, and repo metadata
262
+ - stages `research/source_notes.md`
263
+ - stages `research/preview/*`
264
+ - creates the generated template DNA module
265
+ - automatically runs viral and visual DNA analysis when preview media exists and `GEMINI_API_KEY` is available
266
+
267
+ If you only have one local media file, put it in a temporary preview folder first and point `--source-preview-dir` at that folder.
268
+
269
+ If you need to scaffold before DNA analysis is ready:
270
+
271
+ ```bash
272
+ npx @mevdragon/vidfarm-devcli generate-template \
273
+ --slug-id template_0007 \
274
+ --template-dir ./templates/vidfarm_template_0007 \
275
+ --skip-dna-analysis
276
+ ```
77
277
 
78
- ## When Adding A New Template
278
+ ### 4. Stage research cleanly
79
279
 
80
- Follow this checklist:
280
+ Every new template should have:
81
281
 
82
- 1. create a new folder under `templates/template_<nnnn>/`
83
- 2. put template code in that folder, not under `src/*`
84
- 3. export `defineTemplate({...})`
85
- 4. define:
86
- - `id`
87
- - `slugId`
88
- - `version`
89
- - `about`
90
- - `configSchema`
91
- - `operations`
92
- - `jobs`
93
- 5. add a template-local `SKILL.md`
94
- 6. put source research in `research/source_notes.md`
95
- 7. put source screenshots or videos in `research/preview/`
96
- 8. add `smokeTestPayload` for every operation
97
- 9. verify the template locally end to end
282
+ - `research/source_notes.md`
283
+ - `research/preview/`
284
+
285
+ `source_notes.md` should answer:
286
+
287
+ - original format URL
288
+ - creator/account
289
+ - why it wins
290
+ - what must survive adaptation
291
+ - what can change for new brands
292
+
293
+ `research/preview/` should contain screenshots, frames, or short source clips that capture the format clearly.
294
+
295
+ ### 5. Run DNA analysis explicitly when needed
296
+
297
+ If the scaffold skipped analysis, or if the source research changed, rerun:
298
+
299
+ ```bash
300
+ npx @mevdragon/vidfarm-devcli analyze-viral-dna --template-dir ./templates/vidfarm_template_0007
301
+ npx @mevdragon/vidfarm-devcli analyze-visual-dna --template-dir ./templates/vidfarm_template_0007
302
+ ```
303
+
304
+ These commands:
305
+
306
+ - upload the preview media for analysis
307
+ - generate structured viral and visual DNA JSON
308
+ - sync the generated DNA module back into the template
309
+ - populate the strings consumed by `about.viral_dna`, `about.visual_dna`, and `about.link_to_original`
310
+
311
+ Do not hand-write these summaries if the CLI can generate them from the source media.
312
+
313
+ ### 6. Implement the actual repeatable workflow
98
314
 
99
315
  Use [templates/template_0000/src/template.ts](/Users/localghost/Projects/OfficeX/OfficeX/ZoomGTM/vidfarm/templates/template_0000/src/template.ts) as the baseline pattern.
100
316
 
101
- ## Template Contract
317
+ For a new template, make sure it has:
318
+
319
+ - `id`
320
+ - `slugId`
321
+ - `version`
322
+ - `about`
323
+ - `configSchema`
324
+ - `operations`
325
+ - `jobs`
326
+ - template-local `SKILL.md`
327
+ - `smokeTestPayload` for every operation
328
+
329
+ Expected implementation work usually includes:
330
+
331
+ - input schema design
332
+ - prompt design
333
+ - image generation and attachment usage
334
+ - text generation where needed
335
+ - slide, frame, manifest, or script output shaping
336
+ - local Remotion render wiring where the template outputs video
337
+ - artifact persistence through `ctx.storage`
338
+ - revision-friendly config and prompt controls where repeated tuning is likely
339
+
340
+ ### 7. Expose standard REST routes only
341
+
342
+ The platform route shape is fixed. A template should work behind:
343
+
344
+ - `GET /api/v1/templates/:templateId`
345
+ - `GET /api/v1/templates/:templateId/skill`
346
+ - `POST /api/v1/templates/:templateId/config`
347
+ - `POST /api/v1/templates/:templateId/operations/:operationName`
348
+ - `GET /api/v1/templates/:templateId/jobs/:jobId`
349
+ - `GET /api/v1/templates/:templateId/jobs/:jobId/logs`
350
+ - `POST /api/v1/templates/:templateId/jobs/:jobId/cancel`
351
+
352
+ Do not invent one-off REST endpoints for template behavior that already fits an operation workflow.
353
+
354
+ ### 8. Validate end to end
355
+
356
+ Run:
357
+
358
+ ```bash
359
+ npx @mevdragon/vidfarm-devcli validate-template --template-id template_0007
360
+ ```
361
+
362
+ Then call the real operation through the local API using the local session headers from:
363
+
364
+ ```bash
365
+ npx @mevdragon/vidfarm-devcli session
366
+ ```
367
+
368
+ Minimum bar:
369
+
370
+ - save config if the template exposes config
371
+ - launch at least one real job
372
+ - poll job status
373
+ - inspect logs
374
+ - inspect produced artifacts
375
+ - if you need ad hoc scripts or test-run inputs to drive this validation, keep them under a sibling `tmp/` folder and not inside `src/`
376
+
377
+ The expected result is that another agent can rerun the template without reverse-engineering the workflow.
378
+
379
+ ## Golden Path: Natural-Language Revisions
380
+
381
+ Use this flow whenever the task is "change this template so it behaves differently" and the input is ordinary feedback rather than code-level instructions.
382
+
383
+ ### 1. Interpret the feedback as implementation work
102
384
 
103
- Each template should expose operations, not ad hoc endpoints.
385
+ Map the revision request onto one or more of these layers:
386
+
387
+ - source research or DNA misunderstanding
388
+ - prompt wording
389
+ - operation schema
390
+ - workflow logic
391
+ - image attachment handling
392
+ - layout or caption placement
393
+ - storage artifacts or output manifest shape
394
+ - Remotion composition, timing, or pacing
395
+ - template config defaults
396
+ - template-local `SKILL.md` examples and instructions
397
+
398
+ Do not just restate the feedback. Convert it into code changes.
399
+
400
+ ### 2. Change the template, not just the prompt
401
+
402
+ If the problem is structural, fix the template implementation. Examples:
403
+
404
+ - if outputs drift from the source format, tighten prompt construction or reference attachments
405
+ - if pacing is wrong, change duration logic or Remotion timing
406
+ - if captions clip or overlap UI, change safe areas and layout logic
407
+ - if the template needs more user control, extend `configSchema` or operation input schema
408
+ - if DNA summaries are now wrong, update source notes and rerun DNA analysis
409
+
410
+ Prefer durable fixes over fragile one-off prompt tweaks.
411
+
412
+ ### 3. Revalidate after each revision
413
+
414
+ After every meaningful revision:
415
+
416
+ - run `npx @mevdragon/vidfarm-devcli validate-template --template-id <templateIdOrSlug>`
417
+ - run a real local job
418
+ - inspect artifacts and logs
419
+ - confirm the requested behavior actually changed
420
+
421
+ If the revision changed the expected usage pattern, update the template-local `SKILL.md` in the same pass.
422
+
423
+ ### 4. Keep iterating until the template is reusable
424
+
425
+ A revision is not complete just because the code compiles. It is complete when:
426
+
427
+ - the requested change is visible in the output
428
+ - the change does not obviously regress the core format
429
+ - the template can still be rerun by another user or agent
430
+ - the usage instructions still match the implementation
431
+
432
+ ## Template Contract
104
433
 
105
434
  Use this shape:
106
435
 
@@ -114,7 +443,7 @@ export const myTemplate = defineTemplate({
114
443
  description: "Generate hooks, previews, and final render inputs.",
115
444
  viral_dna: "Fast creator-style hooks with simple repeatable structure.",
116
445
  visual_dna: "Presentation-led mobile layouts with recognizable creator-native framing.",
117
- preview_media: ["https://cdn.example.com/templates/ugc_hooks_v1/about/preview-01.jpg"],
446
+ preview_media: ["templates/ugc_hooks_v1/about/preview-01.jpg"],
118
447
  link_to_original: "https://www.tiktok.com/@example/video/1234567890"
119
448
  },
120
449
  configSchema: z.object({
@@ -148,55 +477,33 @@ export const myTemplate = defineTemplate({
148
477
  Keep these roles clear:
149
478
 
150
479
  - `id` is the UUID-style template identifier
151
- - `slugId` is the human-readable stable identifier
480
+ - `slugId` is the stable human-readable identifier
152
481
  - `operations` define the public API
153
482
  - `jobs` implement the actual work
483
+ - `smokeTestPayload` is required for each operation
154
484
 
155
- ## Local Workflow
156
-
157
- Preferred local third-party developer workflow:
158
-
159
- ```bash
160
- npx @mevdragon/vidfarm-devcli dev --port 3310 --reset
161
- npx @mevdragon/vidfarm-devcli session
162
- npx @mevdragon/vidfarm-devcli validate-template --template-id template_0000
163
- ```
164
-
165
- That CLI should be the default path because it:
166
-
167
- - boots the local API and worker
168
- - provisions local state automatically
169
- - creates a local developer session
170
- - seeds provider keys from local env vars when present
171
- - uses local Remotion rendering
172
-
173
- For third-party developers, local rendering is the default and expected path. Do not document or require cloud Remotion setup here.
174
-
175
- Reset local state when needed:
176
-
177
- ```bash
178
- rm -rf .vidfarm/local
179
- npx @mevdragon/vidfarm-devcli dev --port 3310 --reset
180
- ```
181
-
182
- ## Provider Usage
485
+ ## Provider Rules
183
486
 
184
- Templates should prefer the Vidfarm provider abstractions already available in context.
487
+ Templates should use the provider abstractions already available on `ctx.providers`.
185
488
 
186
489
  Rules:
187
490
 
188
491
  - use the configured provider path instead of hardcoding one provider everywhere
189
492
  - let templates work with whichever supported provider key the developer actually has
190
493
  - keep prompts and model choices configurable when useful
494
+ - use image attachments when the format depends on source references
191
495
  - avoid requiring multiple provider accounts unless the template genuinely needs them
192
496
 
193
- If a task only needs image generation, do not force extra model providers for text or research.
497
+ Important distinction:
194
498
 
195
- ## Storage Namespaces
499
+ - runtime template generation can use OpenAI, OpenRouter, Gemini, or Perplexity according to template logic
500
+ - built-in DNA analysis commands currently depend on `GEMINI_API_KEY`
196
501
 
197
- Use the built-in storage namespace conventions instead of inventing one-off key layouts.
502
+ ## Storage And Upload Rules
198
503
 
199
- Current namespaces:
504
+ Do not hand-write direct S3 upload logic in template code. Use `ctx.storage`.
505
+
506
+ Use the built-in namespace conventions:
200
507
 
201
508
  - `user/:user_id/*` for user-owned uploaded assets
202
509
  - `developer/:user_id/*` for developer-scoped authoring assets or scratch files
@@ -205,20 +512,26 @@ Current namespaces:
205
512
 
206
513
  Rules:
207
514
 
208
- - keep user uploads under the `user/` namespace
209
- - keep developer-only working files under the `developer/` namespace
210
- - keep generated job outputs under the template job namespace
515
+ - keep user uploads under `user/`
516
+ - keep developer-only working files under `developer/`
517
+ - keep generated outputs under the template job namespace
518
+ - keep about-page preview media under `templates/:template_id/about/`
519
+ - prefer `putJson`, `putText`, `putBuffer`, and `getPublicUrl`
211
520
  - do not scatter files across arbitrary top-level prefixes
212
- - prefer the shared storage helpers over handwritten string concatenation for new paths
521
+
522
+ The runtime may back these writes with local filesystem storage or S3 depending on environment. The template should not care.
213
523
 
214
524
  ## API Usage
215
525
 
216
- When testing through the API, use:
526
+ When calling a hosted Vidfarm API directly, use:
217
527
 
218
- - `vidfarm-user-id`
219
528
  - `vidfarm-api-key`
220
529
 
221
- The template-local `SKILL.md` should show the concrete routes and example payloads for that template.
530
+ If you need the authenticated customer identity for display or debugging, call:
531
+
532
+ - `GET /api/v1/user/me`
533
+
534
+ The template-local `SKILL.md` should show concrete request examples for that template's operations and payloads.
222
535
 
223
536
  ## Validation Checklist
224
537
 
@@ -227,26 +540,37 @@ After changes, validate with as many of these as apply:
227
540
  1. `npm run check`
228
541
  2. `npm run build`
229
542
  3. `npx @mevdragon/vidfarm-devcli validate-template --template-id <templateIdOrSlug>`
230
- 4. run the template locally through the CLI session
231
- 5. save template config if the template exposes config
232
- 6. launch a real job
233
- 7. poll job status and logs
543
+ 4. `npx @mevdragon/vidfarm-devcli session`
544
+ 5. save config if the template exposes config
545
+ 6. launch a real operation through the local REST API
546
+ 7. poll the job and fetch logs
234
547
  8. inspect produced artifacts
235
548
 
236
- If you changed slideshow or text-overlay behavior, also validate:
549
+ If you changed slideshow, overlay, or video output behavior, also validate:
237
550
 
238
551
  1. output images are the expected aspect ratio
239
552
  2. captions remain readable and do not clip
240
- 3. final local video output matches expected pacing and framing
553
+ 3. important subjects stay inside safe framing
554
+ 4. final local video output matches expected pacing and composition
555
+
556
+ If the task was a revision request, also validate:
557
+
558
+ 1. the specific natural-language feedback is reflected in the output
559
+ 2. the revision did not break the original core format
560
+ 3. the template-local `SKILL.md` still matches the current behavior
241
561
 
242
562
  ## What To Avoid
243
563
 
244
564
  - asking third-party developers for platform secrets
245
565
  - mixing admin release instructions into template authoring guidance
246
566
  - requiring cloud Remotion setup for normal template work
247
- - adding one-off custom endpoints when an operation already fits the job
567
+ - adding one-off custom endpoints when an operation already fits the job model
248
568
  - hardcoding a developer's personal provider choice into template logic
249
- - omitting `SKILL.md` or `smokeTestPayload`
569
+ - skipping DNA analysis when source media is available
570
+ - omitting `SKILL.md`, `research/source_notes.md`, or `smokeTestPayload`
571
+ - stopping after scaffold generation without making the template runnable
572
+ - treating revision feedback as "prompt advice" without changing the template when the fix belongs in code
573
+ - assuming the first pass is final
250
574
 
251
575
  ## Output Style For Vidfarm Work
252
576
 
@@ -254,5 +578,7 @@ When reporting back after Vidfarm template changes:
254
578
 
255
579
  - name the template changed
256
580
  - mention the operation or workflow affected
581
+ - state whether you used scaffold plus DNA analysis or a manual extension path
582
+ - summarize the natural-language revision request when the task was a revision
257
583
  - state how you verified it locally
258
- - call out any remaining gap such as mocked provider responses or unexercised optional paths
584
+ - call out any remaining gap such as mocked provider responses, missing preview media, or unexercised optional paths
@@ -496,7 +496,7 @@ export function renderSettingsPage(input) {
496
496
  <section class="settings-panel">
497
497
  <div class="pill">Vidfarm API</div>
498
498
  <h2>Your Vidfarm API key</h2>
499
- <p class="helper">Use this key with the <code>vidfarm-user-id</code> header pair when calling the Vidfarm API directly.</p>
499
+ <p class="helper">Use this key as the auth header when calling the Vidfarm API directly. If you need your customer ID, fetch it from <code>/api/v1/user/me</code>.</p>
500
500
  <label for="vidfarm-api-key">Current API key</label>
501
501
  <div class="secret-wrap">
502
502
  <input id="vidfarm-api-key" type="password" value="${escapeHtml(input.vidfarmApiKey)}" readonly />