@aicopycoders/exodus 2026.11.1100-beta.6 → 2026.11.1100-beta.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: exodus-video
3
- description: Make a video ad with Exodus from the terminal. One sentence ("swipe this ad as a microdrama for my brand", "make this a UGC video") is walked through the template door stop by stop, with a yes asked before each paid step. A competitor's video ad (a file, a link, or an ad in Exodus) is swiped with `exodus video swipe`, as Swipe a video does on the dashboard: broken down, matched to a kind of ad, read first, then one sheet of choices and one yes for the write and the whole video (or, when the member asks, step by step with a yes before each paid step). The main path is script-first: run a saved video workflow with `npx @aicopycoders/exodus workflow run`. You read and approve the storyboard, pull every finished piece (per-scene clips, the narration track and per-scene voice, keyframes, cast identity stills, word timings, the music bed) into a folder with `exodus video pull`, and upload a finished cut for approval. Exodus makes the pieces; the cut is made outside it, in whatever editor the user wants — this skill hands over the pieces and the facts about them, it does not prescribe an editor. Use it whenever the user has invoked Exodus and wants anything to do with a video ad, an ad run's clips or storyboard, "pull the pieces", "stitch it together", "make the cut", "upload my cut", or checking on a video run ("exodus, make a video ad from this script", "exodus, is my video run done", "exodus, pull the clips for run X and cut them", "exodus, what's wrong with scene 3", "exodus video status"). Also use it when the user ran an `npx @aicopycoders/exodus video` command or the `exodus` hub skill routed here. Admins get every video command; beta testers with video switched on get start, swipe, status, storyboard, approve, voices, retry-frame, pull and upload on their own brands (see "Beta testers"). "video isn't enabled for this key" means the run id is wrong, the command is admin-only, or video isn't switched on for that dashboard user, so check the id and then say so; do not retry. Never claim generic video-editing asks ("edit this mp4", "add captions to my reel") without Exodus context; in shared folders those belong to the user's other tools. Running or authoring workflows generally is `exodus-workflow`; static image ads are `exodus-image`; copy is `exodus-write`.
3
+ description: Make a video ad with Exodus from the terminal. One sentence ("swipe this ad as a microdrama for my brand", "make this a UGC video") is walked through the template door stop by stop, with a yes asked before each paid step. A competitor's video ad (a file, a link, or an ad in Exodus) is swiped with `exodus video swipe`, as Swipe a video does on the dashboard: broken down, matched to a kind of ad, read first, then one sheet of choices and one yes for the write and the whole video (or, when the member asks, step by step with a yes before each paid step). With no ad named ("find some ads to swipe for this product, give me options"), it first lists the video ads in the brand's swipe library with `exodus video swipe find` and offers at most six. The main path is script-first: run a saved video workflow with `npx @aicopycoders/exodus workflow run`. You read and approve the storyboard, pull every finished piece (per-scene clips, the narration track and per-scene voice, keyframes, cast identity stills, word timings, the music bed) into a folder with `exodus video pull`, and upload a finished cut for approval. Exodus makes the pieces; the cut is made outside it, in whatever editor the user wants — this skill hands over the pieces and the facts about them, it does not prescribe an editor. Use it whenever the user has invoked Exodus and wants anything to do with a video ad, an ad run's clips or storyboard, "pull the pieces", "stitch it together", "make the cut", "upload my cut", or checking on a video run ("exodus, make a video ad from this script", "exodus, is my video run done", "exodus, pull the clips for run X and cut them", "exodus, what's wrong with scene 3", "exodus video status"). Also use it when the user ran an `npx @aicopycoders/exodus video` command or the `exodus` hub skill routed here. Admins get every video command; beta testers with video switched on get start, swipe, status, storyboard, approve, voices, retry-frame, pull and upload on their own brands (see "Beta testers"). "video isn't enabled for this key" means the run id is wrong, the command is admin-only, or video isn't switched on for that dashboard user, so check the id and then say so; do not retry. Never claim generic video-editing asks ("edit this mp4", "add captions to my reel") without Exodus context; in shared folders those belong to the user's other tools. Running or authoring workflows generally is `exodus-workflow`; static image ads are `exodus-image`; copy is `exodus-write`.
4
4
  ---
5
5
 
6
6
  # Video: make the pieces, cut the ad, hand it back
@@ -369,8 +369,9 @@ sentence to a film") keeps the picks stop and the pilot clip.
369
369
 
370
370
  By default a swipe is one round: you read the ad, send the member one sheet,
371
371
  and on their one yes write the brand's version and make each video they
372
- picked. A member who asks to say yes before each paid step gets "Step by
373
- step" below.
372
+ picked. When the member names no ad, the options come first (step 0): video
373
+ ads from the brand's swipe library to pick from. A member who asks to say yes
374
+ before each paid step gets "Step by step" below.
374
375
 
375
376
  **Long waits.** The CLI waits up to 25 minutes for a breakdown, 10 for a
376
377
  template, 15 for a write (the write always waits; it has no `--wait`), and 60
@@ -380,6 +381,122 @@ was cut off or timed out is not a failure: the work goes on. Follow it by the
380
381
  id it printed, with the command the CLI names, and never by running the paid
381
382
  line again: a second run buys it a second time.
382
383
 
384
+ ### 0. No ad named: find some
385
+
386
+ When the member asks for ads to swipe without naming one ("find some ads to
387
+ swipe for this product, give me options"), offer options first. Skip this
388
+ step when the member named a file, a link or an id.
389
+
390
+ 1. The free product check comes first, as in step 1: `exodus video swipe
391
+ products`, and with no products, tell the member and stop. Then, free:
392
+ `exodus video swipe find --json`. It looks through up to 200 ads of the
393
+ brand's swipe library, shared fairly across the competitors (the whole
394
+ library when it holds fewer, and then `"wholeLibrary"` is true), and keeps
395
+ the video ads with a file, newest collected first, each with its id,
396
+ advertiser, first line, word count and the start of its transcript. Its
397
+ counts are of the ads it looked through, not of the whole library.
398
+ 2. Send the options in one message, then stop and wait:
399
+
400
+ > I found <V> video ads from <C> competitors in <your swipe library, or, when "wholeLibrary" is false: the 200 ads I looked through in your swipe library>. The <k> that fit <product> best:
401
+ > 1. **<Advertiser>**: "<first line>" (<w> words). Fits: <one reason, from the ad's words and the product>.
402
+ > 2. **<Advertiser>**: post text "<first line>" (no transcript yet).
403
+ > <V − k> more found. Say "more" for the next six, or name a competitor.
404
+ > Pick by number, or say "all" for these <k>. Your pick is your yes to read
405
+ > every ad you pick, one after another: each read costs a little, on the
406
+ > team's keys and on your model key. Nothing is written or started before
407
+ > your yes to the sheet.
408
+
409
+ The rules of the options:
410
+
411
+ - **At most six options in one message.** "More" sends the next six in the
412
+ same order you chose them by, leaving out every ad already shown; past
413
+ the rows the CLI showed, run `exodus video swipe find --limit 200
414
+ --json`. When the member names a competitor, run `exodus video
415
+ swipe find --brand "<name>" --json`. Leave out the "more found" line when
416
+ there are no more. When that find says none of the video ads is from that
417
+ name, say the CLI's line and offer the advertisers it lists.
418
+ - **"All" means the options the member last saw**, never every ad found.
419
+ - **The reason comes from the ad's words and the product.** A product fact
420
+ in it comes only from `exodus video swipe products` (the product's name
421
+ and description) or the primer. Say nothing about the competitor beyond
422
+ the ad's own words. Never call an ad a winner, a top ad or a proven ad:
423
+ the list holds no results (no spend, no views, no days running) and does
424
+ not rank by them. Its order is newest collected first, nothing more.
425
+ - **Post text is not spoken.** A first line with `"firstLineFrom": "post
426
+ text"` is the post's headline or text, not words said in the video: show
427
+ it as post text, never as something someone says.
428
+ - **An ad with no transcript goes last**, with no reason: its words are not
429
+ known before the read.
430
+ - **The kind of an ad is known only after it is read.** Never state a kind
431
+ as fact before a read.
432
+
433
+ **A find by kind.** When the member asks for a kind of ad ("find me some
434
+ authority yappers"), offer at most six whose words sound like that kind, and
435
+ say so in the message's first line, as "<kind>: sounds like, from the words;
436
+ the read confirms it." After the reads, the sheet's first
437
+ line names any ad the template read as another kind, so the member can drop
438
+ it ("drop video 3, go" is already a yes).
439
+
440
+ **What a pick is.** Only numbers given after an options message ("1, 3 and
441
+ 5"), or "all" (the options the member last saw), are picks. The numbering
442
+ goes on across "more" and across a new find (for a named competitor): the
443
+ next six are 7 to 12, and so on, never 1 again. Keep the id of every
444
+ number you showed, and read a pick by that id. "You pick" is not a
445
+ pick: name your own picks by number, each with its reason, and wait; read
446
+ nothing yet. A reply that takes them ("yes, those") is the pick. "Swipe all
447
+ of them" in the first message, before any options were shown, gets the
448
+ options first. A reply that picks nothing (a question, "tell me more about
449
+ 2", "maybe") is not a pick: answer it and wait.
450
+
451
+ **A pick is the yes to read every ad picked.** Say in one line what you are
452
+ about to read and who pays, in words like: "I'll read these 2 ads now, one
453
+ after another: each breakdown on the team's keys, each template on your own
454
+ model key." Then step 1 reads them in number order, by the ids the find
455
+ printed (`--ad <id>`), each breakdown then its template, without asking
456
+ again between them. Only what the member did not pick still gets the one
457
+ ask of "The limit: $0.50 for the read." in step 1: an ad found or named
458
+ after the pick, or a second pass over the same list. A pick whose read is
459
+ refused (its video expired or was removed; the read says so in one sentence
460
+ and buys nothing) or fails is left out, as step 1 says. Reading a failed ad
461
+ again is paid and needs its own yes.
462
+
463
+ **Into the sheet.** Every pick is on the sheet, in number order. The count is
464
+ ads × personas, and every rule of step 3 holds, above 6 videos too. In a
465
+ sheet file, each pick is `{"ad": "<id>"}` in `"sources"`, in the same order.
466
+
467
+ **Only part of the library was looked through.** When `"wholeLibrary"` is false
468
+ and none of those ads is a video with a file, the library is not empty:
469
+ the find looked through only part of it. Say the CLI's line, say that, and
470
+ offer a link or a file of an ad. Do not offer mining.
471
+
472
+ **An empty library.** When the find answers "The swipe library has no ads yet
473
+ for this brand.", or, with `"wholeLibrary"` true, that none of its ads is a
474
+ video with a file, tell the member in the CLI's own words, then offer
475
+ three ways and run none of them:
476
+
477
+ - a link or a file of an ad (step 1 reads it);
478
+ - `exodus swipe brands list` (free): the competitors this brand tracks, each
479
+ with the date it was last mined;
480
+ - `exodus swipe mine`: collects the tracked competitors' ads into the
481
+ library.
482
+
483
+ **Before any yes to mining**, tell the member in one message: it runs on
484
+ their own Scrape Creators key; the CLI prints no price for it; it mines every
485
+ active competitor on the watchlist, up to 50 in one run, the least recently
486
+ mined first; and it starts the moment it runs, in the background. Only a
487
+ reply that names mining after that message is the yes ("yes, mine them"), and
488
+ it buys the mining only, no read. After the mine, do not find again at
489
+ once: `exodus swipe latest` and `exodus swipe status <runId>` follow the
490
+ weekly swipe run, not mining, so they cannot show it is done. The mine
491
+ itself prints "Check progress: exodus swipe brands list". Tell the member
492
+ the mine has started and that you can look again in a few minutes. When
493
+ they ask, run `exodus swipe brands list` (a competitor that showed
494
+ `never-scraped` and now shows a `last=` date has been mined; the date has
495
+ no time, so one mined earlier the same day shows no change), then `exodus
496
+ video swipe find --json`. If it is still empty, say what the list shows and
497
+ stop; do not keep checking. Transcripts are made after the mine finishes, so
498
+ a newly mined ad can show "no transcript yet" for a while.
499
+
383
500
  ### 1. Read the ad
384
501
 
385
502
  First, free: `exodus video swipe products`. When it answers "This brand has
@@ -424,7 +541,10 @@ member once when the costs counted have reached $0.50, or when any read so
424
541
  far is unknown: an unknown cost counts as reaching the limit. Say what is
425
542
  left to read. A new template is always
426
543
  unknown, so with several ads you read the first and ask before the rest. The
427
- check comes before each read, so the total can pass $0.50 by one read.
544
+ check comes before each read, so the total can pass $0.50 by one read. Ads
545
+ the member picked by number from the options (step 0), or with "all", are
546
+ already a yes to read: read every picked ad without this ask. The ask still
547
+ comes before any ad they did not pick.
428
548
 
429
549
  A breakdown or a template that fails prints why. With one ad, tell the
430
550
  member and stop. With several, leave that ad out, say so in the sheet's first
@@ -580,17 +700,18 @@ step 3 comes once every video has started:
580
700
  to "End: watch and approve" (pull, cut, upload, the run page). A run that
581
701
  stopped at the storyboard goes to stop 3, then the end.
582
702
 
583
- **Never start the same swipe twice.** Each start is a second, paid video.
584
- Before any second start of a swipe, run `exodus video swipe show <swipeId>`:
585
- when it prints "It started run <runId>", the run started, so follow it with
586
- `exodus video status <runId>`. Before writing again after a write whose wait
587
- was cut off, run `exodus video swipe list`. It lists the newest first, and
588
- the writes run one at a time, so a row for that ad above the last swipe id
589
- you noted (any row for it, when you noted none), with no run and not marked
590
- refused, is that write. Show it with `exodus video swipe show <swipeId>` and
591
- start it instead of writing again. A row marked refused is that write's
592
- refusal: report it as a refused write. When no such row is there yet, the write may
593
- still finish: check again later.
703
+ **Never start the same swipe twice.** One swipe is one video. A start of a
704
+ swipe that already has a video is refused, starts nothing, and names the run:
705
+ follow that run with `exodus video status <runId>`. `--again` makes a second,
706
+ paid video from the same swipe: use it only when the member asks for a second
707
+ video. Before writing again after a write whose wait was cut off, run
708
+ `exodus video swipe list`. It lists the newest first, each with when it was
709
+ written and its product, and the writes run one at a time, so a row for that
710
+ ad and product above the last swipe id you noted (any row for it, when you
711
+ noted none), with no run and not marked refused, is that write. Show it with
712
+ `exodus video swipe show <swipeId>` and start it instead of writing again. A
713
+ row marked refused is that write's refusal: report it as a refused write. When
714
+ no such row is there yet, the write may still finish: check again later.
594
715
 
595
716
  At the end, report each video on one line: its ad and persona, its run id
596
717
  and its `Watch it:` link, or why it stopped.
@@ -768,8 +889,8 @@ prints no price, never guess one, and run the same line with `--yes` only
768
889
  after their yes.
769
890
 
770
891
  1. **Get the ad.** One of a video file, a link (Meta Ad Library, TikTok,
771
- Instagram or YouTube), or an ad in the brand's swipe library by the `id:`
772
- that `exodus genesis --list-swipes` prints:
892
+ Instagram or YouTube), or a video ad in the brand's swipe library by the
893
+ id that `exodus video swipe find` prints (free):
773
894
  `exodus video swipe --file <ad.mp4> | --url <link> | --ad <swipeAdId>`.
774
895
  The breakdown is paid on the team's keys, not the member's. A link or an
775
896
  ad this brand broke down before comes back at once and costs nothing.
@@ -807,7 +928,8 @@ after their yes.
807
928
  `--title "<name>"` names the ad, for admins only: a beta tester leaves it
808
929
  off, or the CLI refuses it with one sentence naming it. With `--one-shot`
809
930
  it buys the whole video with no stop: ask before passing it. `--wait` waits until the run needs the
810
- member.
931
+ member. A swipe that already has a video is refused, with its run; a
932
+ second video from it needs `--again` and the member's yes to a second video.
811
933
  6. **Then** stop 3 (the storyboard) and the end, as above.
812
934
 
813
935
  ### Every swipe command
@@ -822,9 +944,12 @@ exodus video swipe products the brand's products a
822
944
  exodus video swipe write <breakdownId> --product <id> [--mode <mode>] [--closeness <step>] [--look <slug>] [--script <file>] [--yes]
823
945
  the brand's version (member's key); waits for it
824
946
  exodus video swipe show <swipeId> one swipe again
825
- exodus video swipe list the brand's newest swipes; a refused one shows what it cost
826
- exodus video swipe start <swipeId> [--style <look>] [--title "<name>"] [--music] [--one-shot] [--yes] [--wait]
827
- start the run on the kind the swipe wrote
947
+ exodus video swipe list the brand's newest swipes, each with when it was written and its product;
948
+ a refused one shows what it cost
949
+ exodus video swipe find [--brand "<name>"] [--limit <n>] video ads in the swipe library to offer as options (free); no kind, no results
950
+ exodus video swipe start <swipeId> [--style <look>] [--title "<name>"] [--music] [--one-shot] [--again] [--yes] [--wait]
951
+ start the run on the kind the swipe wrote; --again for a
952
+ second, paid video of a swipe that already has one
828
953
  exodus video swipe run --sheet <file> [--status] [--persona <name>] [--yes] [--retry-refused] [--wait] every video of a sheet saved as a JSON file
829
954
  ```
830
955
 
@@ -1,4 +1,5 @@
1
1
  import type { FlagOccurrence } from "../lib/args.js";
2
+ import type { ApiResponse } from "../lib/client.js";
2
3
  import { type FlowResult, type VideoDeps } from "./video.js";
3
4
  export declare const SWIPE_BREAKDOWNS_PATH = "/api/v2/video/breakdowns";
4
5
  export declare const SWIPE_UPLOAD_URL_PATH = "/api/v2/video/breakdowns/upload-url";
@@ -6,6 +7,7 @@ export declare const SWIPE_TEMPLATE_PATH = "/api/v2/video/swipe-template";
6
7
  export declare const SWIPE_PRODUCTS_PATH = "/api/v2/video/swipe-products";
7
8
  export declare const SWIPES_PATH = "/api/v2/video/swipes";
8
9
  export declare const SWIPE_RUNS_PATH = "/api/v2/video/swipe-runs";
10
+ export declare const SWIPE_LIBRARY_PATH = "/api/v2/swipe-library";
9
11
  export interface SwipeBreakdown {
10
12
  _id: string;
11
13
  sourceKind: "url" | "file" | "ad";
@@ -105,6 +107,7 @@ export interface SwipeView {
105
107
  checksFound?: string[];
106
108
  workflowRunId: string | null;
107
109
  costUsd: number | null;
110
+ runHoldsStart?: boolean;
108
111
  }
109
112
  export interface SwipeListRow {
110
113
  _id: string;
@@ -119,11 +122,16 @@ export interface SwipeListRow {
119
122
  sourceKind: string;
120
123
  sourceUrl?: string;
121
124
  fileName?: string;
125
+ sourceAdId?: string;
122
126
  } | null;
123
127
  outcome?: {
124
128
  kind: "written" | "refused";
125
129
  };
126
130
  costUsd?: number | null;
131
+ product?: {
132
+ id: string;
133
+ name: string;
134
+ } | null;
127
135
  }
128
136
  type ServerMode = "whole" | "hook" | "their-format" | "new-look";
129
137
  export declare const SWIPE_MODES: ReadonlyArray<{
@@ -206,10 +214,15 @@ export type SwipePlan = {
206
214
  } | {
207
215
  kind: "list";
208
216
  opts: SwipeOpts;
217
+ } | {
218
+ kind: "find";
219
+ ask: FindAsk;
220
+ opts: SwipeOpts;
209
221
  } | {
210
222
  kind: "start";
211
223
  swipeId: string;
212
224
  ask: StartAsk;
225
+ again: boolean;
213
226
  opts: SwipeOpts;
214
227
  } | {
215
228
  kind: "run";
@@ -258,10 +271,55 @@ export declare function swipeStatusFlow(breakdownId: string, opts: SwipeRunOptio
258
271
  export declare function fullLines(data: Record<string, unknown>): string[];
259
272
  export declare function swipeTemplateFlow(breakdownId: string, opts: SwipeRunOptions, deps: VideoDeps): Promise<FlowResult>;
260
273
  export declare function swipeProductsFlow(opts: SwipeOpts, deps: VideoDeps): Promise<FlowResult>;
274
+ export declare const FIND_READ = 200;
275
+ export declare const FIND_PAID_FLAGS: readonly ["yes", "wait", "file", "url", "ad", "again"];
276
+ export declare const FIND_OTHER_FLAGS: readonly ["one-shot", "music", "mode", "closeness", "product", "look", "script", "style", "title", "sheet", "full", "status", "persona", "retry-refused"];
277
+ export declare const FIND_KIND_LINE = "The kind of an ad is known only after it is read.";
278
+ export declare const FIND_EMPTY_LIBRARY = "The swipe library has no ads yet for this brand.";
279
+ export interface FindAsk {
280
+ brand: string | null;
281
+ limit: number;
282
+ }
283
+ export interface SwipeLibraryRow {
284
+ _id: string;
285
+ brandName?: string;
286
+ format?: string;
287
+ transcript?: string;
288
+ bodyText?: string;
289
+ headline?: string;
290
+ ctaText?: string;
291
+ imageUrl?: string;
292
+ videoUrl?: string;
293
+ }
294
+ export interface SwipeCandidate {
295
+ n: number;
296
+ id: string;
297
+ advertiser: string | null;
298
+ firstLine: string | null;
299
+ firstLineFrom: "transcript" | "post text" | null;
300
+ words: number | null;
301
+ text: string | null;
302
+ }
303
+ export interface SwipeCandidates {
304
+ read: number;
305
+ wholeLibrary: boolean;
306
+ videos: number;
307
+ competitors: number;
308
+ candidates: SwipeCandidate[];
309
+ allVideos: number;
310
+ advertisers: string[];
311
+ }
312
+ export declare function swipeCandidatesOf(rows: unknown[], ask: FindAsk): SwipeCandidates;
313
+ export declare function swipeFindFlow(ask: FindAsk, opts: SwipeOpts, deps: VideoDeps): Promise<FlowResult>;
261
314
  export declare function swipeWriteFlow(breakdownId: string, ask: WriteAsk, opts: SwipeRunOptions, deps: VideoDeps): Promise<FlowResult>;
262
315
  export declare function swipeShowFlow(swipeId: string, opts: SwipeOpts, deps: VideoDeps): Promise<FlowResult>;
263
316
  export declare function swipeListFlow(opts: SwipeOpts, deps: VideoDeps): Promise<FlowResult>;
264
- export declare function swipeStartFlow(swipeId: string, ask: StartAsk, opts: SwipeRunOptions, deps: VideoDeps): Promise<FlowResult>;
317
+ export declare const SWIPE_ALREADY_STARTED_CODE = "SWIPE_ALREADY_STARTED";
318
+ export declare function alreadyStartedOf(res: ApiResponse<unknown>): {
319
+ runId: string;
320
+ url: string;
321
+ } | null;
322
+ export declare function swipeStartFlow(swipeId: string, ask: StartAsk, opts: SwipeRunOptions, deps: VideoDeps, again?: boolean): Promise<FlowResult>;
265
323
  export declare const SHEET_FIELDS: readonly ["sources", "product", "personas", "mechanism", "guidance", "mode", "closeness", "look", "script", "characters", "finish", "oneShot", "style", "title", "music"];
266
324
  export declare const SHEET_VIDEO_WARNING = 6;
267
325
  export interface SheetSource {
@@ -329,6 +387,7 @@ export interface WritePending {
329
387
  export interface StartPending {
330
388
  at: string;
331
389
  swipeId: string;
390
+ serverAt?: number;
332
391
  }
333
392
  export interface SheetRunState {
334
393
  runId: string | null;
@@ -380,6 +439,7 @@ export interface SheetFiles {
380
439
  host: string;
381
440
  isAlive(pid: number): boolean;
382
441
  realPath(file: string): string;
442
+ listDir(dir: string): string[];
383
443
  onStop(cleanup: () => void): () => void;
384
444
  }
385
445
  export type SheetDeps = VideoDeps & {
@@ -387,6 +447,7 @@ export type SheetDeps = VideoDeps & {
387
447
  };
388
448
  export declare const nodeSheetFiles: SheetFiles;
389
449
  export declare const sheetLockPath: (sheetFile: string) => string;
450
+ export declare const sheetTakeoverPath: (sheetFile: string) => string;
390
451
  export type SheetVideoState = "not started" | "breakdown" | "template" | "written" | "refused" | "running" | "storyboard" | "waiting" | "done" | "failed" | "unread";
391
452
  export interface SheetFlowOptions extends SwipeRunOptions {
392
453
  retryRefused: boolean;
@@ -12,6 +12,7 @@ export const SWIPE_TEMPLATE_PATH = "/api/v2/video/swipe-template";
12
12
  export const SWIPE_PRODUCTS_PATH = "/api/v2/video/swipe-products";
13
13
  export const SWIPES_PATH = "/api/v2/video/swipes";
14
14
  export const SWIPE_RUNS_PATH = "/api/v2/video/swipe-runs";
15
+ export const SWIPE_LIBRARY_PATH = "/api/v2/swipe-library";
15
16
  export const SWIPE_MODES = [
16
17
  { flag: "whole-ad", mode: "whole", label: "Whole ad", helper: "Every part of their ad, rewritten for your brand." },
17
18
  { flag: "hook-only", mode: "hook", label: "Hook only", helper: "Their opening hook. The rest is new, written for your product." },
@@ -73,7 +74,7 @@ export function needsYesResult(step, json, choice = []) {
73
74
  ],
74
75
  };
75
76
  }
76
- const VERBS = ["status", "template", "products", "write", "show", "list", "start", "run"];
77
+ const VERBS = ["status", "template", "products", "write", "show", "list", "start", "run", "find"];
77
78
  export function parseSwipeMode(value) {
78
79
  return SWIPE_MODES.find((m) => m.flag === value.trim().toLowerCase())?.mode ?? null;
79
80
  }
@@ -95,10 +96,11 @@ const SHEET_FLAGS = [
95
96
  ["url", 'list the ad in the sheet\'s "sources".'],
96
97
  ["ad", 'list the ad in the sheet\'s "sources".'],
97
98
  ["full", "--full is for exodus video swipe status."],
99
+ ["again", "a sheet never starts a swipe twice. For a second video of one swipe, use exodus video swipe start <swipeId> --again."],
98
100
  ];
99
101
  const OFF_WORDS = new Set(["false", "no", "off", "0"]);
100
102
  const ON_WORDS = new Set(["true", "yes", "on", "1"]);
101
- const SWITCHES = ["json", "yes", "wait", "full", "music", "one-shot", "retry-refused", "status"];
103
+ const SWITCHES = ["json", "yes", "wait", "full", "music", "one-shot", "retry-refused", "status", "again"];
102
104
  export function planSwipeCommand(rest, occurrences) {
103
105
  const last = (name) => occurrences.filter((o) => o.flag === name || o.flag === `no-${name}`).at(-1);
104
106
  const switchState = (name) => {
@@ -148,6 +150,33 @@ export function planSwipeCommand(rest, occurrences) {
148
150
  return { kind: "products", opts };
149
151
  if (verb === "list")
150
152
  return { kind: "list", opts };
153
+ if (verb === "find") {
154
+ const typedFlag = (names) => occurrences.find((o) => names.some((name) => o.flag === name || o.flag === `no-${name}`))?.flag;
155
+ const paid = typedFlag(FIND_PAID_FLAGS);
156
+ if (paid) {
157
+ return usage(`video swipe find only lists the swipe library and buys nothing, so it takes no --${paid}. Read a picked ad with exodus video swipe --ad <id>.`);
158
+ }
159
+ const other = typedFlag(FIND_OTHER_FLAGS);
160
+ if (other)
161
+ return usage(`video swipe find takes no --${other}: it only lists the swipe library. Its flags are --brand, --limit and --json.`);
162
+ const switchWord = (word) => ON_WORDS.has(word.toLowerCase()) || OFF_WORDS.has(word.toLowerCase());
163
+ const extra = rest
164
+ .slice(1)
165
+ .find((word) => !(switchWord(word) && occurrences.some((o) => SWITCHES.includes(o.flag) && o.value === word)));
166
+ if (extra !== undefined)
167
+ return usage(`video swipe find takes no id (got "${extra}"). Name a competitor with --brand "<name>".`);
168
+ const brand = value("brand");
169
+ if (brand === null)
170
+ return usage("video swipe find --brand needs a competitor's name.");
171
+ const limitWord = value("limit");
172
+ if (limitWord === null)
173
+ return usage(`video swipe find --limit needs a number from 1 to ${FIND_MAX}.`);
174
+ const limit = limitWord === undefined ? FIND_DEFAULT_LIMIT : /^\d+$/.test(limitWord.trim()) ? Number(limitWord.trim()) : NaN;
175
+ if (!(limit >= 1 && limit <= FIND_MAX)) {
176
+ return usage(`video swipe find --limit must be a whole number from 1 to ${FIND_MAX}, not "${limitWord}".`);
177
+ }
178
+ return { kind: "find", ask: { brand: brand?.trim() ?? null, limit }, opts };
179
+ }
151
180
  if (verb === "run") {
152
181
  const typed = SHEET_FLAGS.find(([flag]) => last(flag) !== undefined);
153
182
  if (typed) {
@@ -179,7 +208,7 @@ export function planSwipeCommand(rest, occurrences) {
179
208
  const start = startChoicesOf({ style: value("style"), title: value("title"), music: on("music"), oneShot: on("one-shot") }, CLI_WORDS.start);
180
209
  if ("problem" in start)
181
210
  return usage(start.problem);
182
- return { kind: "start", swipeId: id, ask: start.ask, opts };
211
+ return { kind: "start", swipeId: id, ask: start.ask, again: on("again"), opts };
183
212
  }
184
213
  const product = value("product");
185
214
  if (!product)
@@ -648,6 +677,123 @@ export async function swipeProductsFlow(opts, deps) {
648
677
  ],
649
678
  };
650
679
  }
680
+ export const FIND_READ = 200;
681
+ const FIND_MAX = FIND_READ;
682
+ const FIND_DEFAULT_LIMIT = 30;
683
+ const FIRST_LINE_MAX = 60;
684
+ export const FIND_PAID_FLAGS = ["yes", "wait", "file", "url", "ad", "again"];
685
+ export const FIND_OTHER_FLAGS = [
686
+ "one-shot",
687
+ "music",
688
+ "mode",
689
+ "closeness",
690
+ "product",
691
+ "look",
692
+ "script",
693
+ "style",
694
+ "title",
695
+ "sheet",
696
+ "full",
697
+ "status",
698
+ "persona",
699
+ "retry-refused",
700
+ ];
701
+ const TEXT_MAX = 400;
702
+ export const FIND_KIND_LINE = "The kind of an ad is known only after it is read.";
703
+ export const FIND_EMPTY_LIBRARY = "The swipe library has no ads yet for this brand.";
704
+ function textOf(value) {
705
+ return typeof value === "string" ? value.replace(/\s+/g, " ").trim() : "";
706
+ }
707
+ function cut(text, max) {
708
+ return text.length > max ? `${text.slice(0, max - 1)}…` : text;
709
+ }
710
+ export function swipeCandidatesOf(rows, ask) {
711
+ const videos = rows.filter((row) => isRecord(row) && typeof row._id === "string" && row.format === "video" && textOf(row.videoUrl) !== "");
712
+ const advertisers = [];
713
+ for (const row of videos) {
714
+ const name = textOf(row.brandName);
715
+ if (name && !advertisers.some((seen) => seen.toLowerCase() === name.toLowerCase()))
716
+ advertisers.push(name);
717
+ }
718
+ const wanted = ask.brand?.toLowerCase() ?? null;
719
+ const matched = wanted === null ? videos : videos.filter((row) => textOf(row.brandName).toLowerCase().includes(wanted));
720
+ const competitors = new Set(matched.map((row) => textOf(row.brandName).toLowerCase()).filter(Boolean)).size;
721
+ const candidates = matched.slice(0, ask.limit).map((row, i) => {
722
+ const transcript = textOf(row.transcript);
723
+ const first = transcript || textOf(row.headline) || textOf(row.bodyText);
724
+ return {
725
+ n: i + 1,
726
+ id: row._id,
727
+ advertiser: textOf(row.brandName) || null,
728
+ firstLine: first ? cut(first, FIRST_LINE_MAX) : null,
729
+ firstLineFrom: transcript ? "transcript" : first ? "post text" : null,
730
+ words: transcript ? transcript.split(" ").length : null,
731
+ text: transcript ? transcript.slice(0, TEXT_MAX) : null,
732
+ };
733
+ });
734
+ return { read: rows.length, wholeLibrary: rows.length < FIND_READ, videos: matched.length, competitors, candidates, allVideos: videos.length, advertisers };
735
+ }
736
+ function windowWords(found) {
737
+ if (!found.wholeLibrary) {
738
+ return `the ${found.read} ads looked through in the swipe library (shared across competitors; the library may hold more)`;
739
+ }
740
+ return found.read === 1 ? "the only ad in the swipe library" : `all ${found.read} ads in the swipe library`;
741
+ }
742
+ function findEmptyLine(found, ask) {
743
+ if (found.read === 0)
744
+ return FIND_EMPTY_LIBRARY;
745
+ if (found.allVideos === 0) {
746
+ return found.read === 1
747
+ ? "The only ad in the swipe library is not a video with a file."
748
+ : `None of ${windowWords(found)} is a video with a file.`;
749
+ }
750
+ if (found.videos === 0) {
751
+ const where = found.wholeLibrary ? "in the swipe library" : "looked through in the swipe library";
752
+ return `None of the ${plural(found.allVideos, "video ad", "video ads")} ${where} is from "${ask.brand}". They are from: ${found.advertisers.join(", ")}.`;
753
+ }
754
+ return null;
755
+ }
756
+ export async function swipeFindFlow(ask, opts, deps) {
757
+ const { json } = opts;
758
+ const res = await deps.get(`${SWIPE_LIBRARY_PATH}?limit=${FIND_READ}`);
759
+ if (!res.ok) {
760
+ const error = formatApiError(res);
761
+ return { code: 1, lines: json ? [JSON.stringify({ ok: false, status: res.status, error })] : [error] };
762
+ }
763
+ const rows = isRecord(res.data) && Array.isArray(res.data.swipes) ? res.data.swipes : null;
764
+ if (!rows)
765
+ return failed("The server's answer about the swipe library could not be read.", json);
766
+ const found = swipeCandidatesOf(rows, ask);
767
+ const empty = findEmptyLine(found, ask);
768
+ const { read, wholeLibrary, videos, competitors, candidates } = found;
769
+ if (json) {
770
+ return {
771
+ code: 0,
772
+ lines: [
773
+ JSON.stringify({ ok: true, read, wholeLibrary, videos, competitors, shown: candidates.length, candidates, ...(empty ? { empty } : {}) }),
774
+ ],
775
+ };
776
+ }
777
+ if (empty)
778
+ return { code: 0, lines: [empty] };
779
+ const width = Math.max(...candidates.map((c) => c.id.length));
780
+ return {
781
+ code: 0,
782
+ lines: [
783
+ `${plural(videos, "video ad", "video ads")}${ask.brand ? ` matching "${ask.brand}"` : ""}, from ${plural(competitors, "competitor", "competitors")}, newest collected first.`,
784
+ `The counts are of ${windowWords(found)}.`,
785
+ ...candidates.map((c) => {
786
+ const said = c.firstLine ? `${c.firstLineFrom === "post text" ? "post text " : ""}"${c.firstLine}"` : "";
787
+ const tail = c.words === null ? "no transcript yet" : plural(c.words, "word", "words");
788
+ return `${String(c.n).padStart(4)} ${c.id.padEnd(width)} ${c.advertiser ?? "(advertiser unknown)"}: ${said ? `${said} ${tail}` : tail}`;
789
+ }),
790
+ ...(candidates.length < videos ? [`Showing the first ${candidates.length}; --limit <n> shows up to ${FIND_MAX}.`] : []),
791
+ "Read one (paid, on the team's keys; ask first): exodus video swipe --ad <id> --yes --wait",
792
+ "An ad read before costs nothing to read again, unless that read failed: then reading it again is paid.",
793
+ `${FIND_KIND_LINE} This list holds no results, so it does not rank by them.`,
794
+ ],
795
+ };
796
+ }
651
797
  const WRITE_MAX_POLLS = 180;
652
798
  function choiceLines(ask) {
653
799
  const mode = modeOf(ask.mode);
@@ -700,9 +846,11 @@ function swipeLines(swipe, after) {
700
846
  ...(draft.lengthGap ? [`Length: ours is about ${draft.lengthGap.ours} s, theirs about ${draft.lengthGap.theirs} s.`] : []),
701
847
  costLine(swipe),
702
848
  "",
703
- swipe.workflowRunId
704
- ? `It started run ${swipe.workflowRunId}: exodus video status ${swipe.workflowRunId}. Another start is a second, paid video.`
705
- : `Start the video (paid; ask first): exodus video swipe start ${swipe._id} --yes`,
849
+ swipe.workflowRunId && swipe.runHoldsStart === false
850
+ ? `It started run ${swipe.workflowRunId}, which failed or was cancelled: exodus video status ${swipe.workflowRunId}. Starting the swipe again is paid (ask first): exodus video swipe start ${swipe._id} --yes`
851
+ : swipe.workflowRunId
852
+ ? `It started run ${swipe.workflowRunId}: exodus video status ${swipe.workflowRunId}. A second video from this swipe is paid on its own and needs --again (ask first): exodus video swipe start ${swipe._id} --again --yes`
853
+ : `Start the video (paid; ask first): exodus video swipe start ${swipe._id} --yes`,
706
854
  ];
707
855
  }
708
856
  export async function swipeWriteFlow(breakdownId, ask, opts, deps) {
@@ -768,6 +916,7 @@ export async function swipeShowFlow(swipeId, opts, deps) {
768
916
  return { code: 0, lines: [JSON.stringify({ ok: true, swipe })] };
769
917
  return { code: 0, lines: swipeLines(swipe, "show") };
770
918
  }
919
+ const writtenAt = (ms) => `${new Date(ms).toISOString().slice(0, 16).replace("T", " ")} UTC`;
771
920
  export async function swipeListFlow(opts, deps) {
772
921
  const res = await deps.get(SWIPES_PATH);
773
922
  if (!res.ok)
@@ -785,8 +934,10 @@ export async function swipeListFlow(opts, deps) {
785
934
  const ad = row.source?.sourceUrl ?? row.source?.fileName ?? "an ad";
786
935
  return [
787
936
  row._id,
937
+ ...(typeof row.createdAt === "number" ? [`written ${writtenAt(row.createdAt)}`] : []),
788
938
  `${mode.label}${step ? `, ${step.step} ${step.name}` : ""}`,
789
939
  ad,
940
+ ...(row.product !== undefined ? [row.product ? `for ${row.product.name}` : "for a product since deleted"] : []),
790
941
  ...(row.workflowRunId ? [`run ${row.workflowRunId}`] : []),
791
942
  ...(row.outcome?.kind === "refused"
792
943
  ? [`refused, ${typeof row.costUsd === "number" ? `cost ${usd(row.costUsd)}` : "cost unknown"}, nothing started`]
@@ -795,17 +946,42 @@ export async function swipeListFlow(opts, deps) {
795
946
  }),
796
947
  };
797
948
  }
798
- export async function swipeStartFlow(swipeId, ask, opts, deps) {
949
+ export const SWIPE_ALREADY_STARTED_CODE = "SWIPE_ALREADY_STARTED";
950
+ export function alreadyStartedOf(res) {
951
+ if (res.ok || res.status !== 409 || !isRecord(res.data) || !isRecord(res.data.error))
952
+ return null;
953
+ const { code, runId, url } = res.data.error;
954
+ if (code !== SWIPE_ALREADY_STARTED_CODE || typeof runId !== "string" || !runId)
955
+ return null;
956
+ return { runId, url: typeof url === "string" ? url : "" };
957
+ }
958
+ export async function swipeStartFlow(swipeId, ask, opts, deps, again = false) {
799
959
  const { json } = opts;
800
- if (!opts.yes)
801
- return needsYesResult(ask.oneShot ? "start-one-shot" : "start", json);
960
+ if (!opts.yes) {
961
+ return needsYesResult(ask.oneShot ? "start-one-shot" : "start", json, again ? ["With --again: a second video from this swipe, even if it already has one. It is paid on its own."] : []);
962
+ }
802
963
  const res = await deps.post(SWIPE_RUNS_PATH, {
803
964
  swipeId,
804
965
  ...(ask.style ? { style: ask.style } : {}),
805
966
  ...(ask.title ? { title: ask.title } : {}),
806
967
  ...(ask.music ? { music: true } : {}),
807
968
  ...(ask.oneShot ? {} : { reviewStoryboard: true }),
969
+ ...(again ? { again: true } : {}),
808
970
  });
971
+ const held = alreadyStartedOf(res);
972
+ if (held) {
973
+ const error = `Swipe ${swipeId} already has a video, so nothing was started: run ${held.runId}.`;
974
+ if (json)
975
+ return { code: 1, lines: [JSON.stringify({ ok: false, status: res.status, error, alreadyStarted: held })] };
976
+ return {
977
+ code: 1,
978
+ lines: [
979
+ error,
980
+ held.url ? `Watch it: ${held.url}` : `Check it: exodus video status ${held.runId}`,
981
+ `A second video from this swipe is paid on its own. Only on the member's yes to a second video: exodus video swipe start ${swipeId} --again --yes`,
982
+ ],
983
+ };
984
+ }
809
985
  if (!res.ok)
810
986
  return swipeError(res, json);
811
987
  const customer = customerAnswer(res.data);
@@ -1234,6 +1410,14 @@ export const nodeSheetFiles = {
1234
1410
  realPath(file) {
1235
1411
  return fs.realpathSync(file);
1236
1412
  },
1413
+ listDir(dir) {
1414
+ try {
1415
+ return fs.readdirSync(dir);
1416
+ }
1417
+ catch {
1418
+ return [];
1419
+ }
1420
+ },
1237
1421
  onStop(cleanup) {
1238
1422
  const handlers = ["SIGINT", "SIGTERM"].map((signal) => {
1239
1423
  const handler = () => {
@@ -1252,6 +1436,7 @@ export const nodeSheetFiles = {
1252
1436
  const sheetFilesOf = (deps) => deps.sheetFiles ?? nodeSheetFiles;
1253
1437
  export const sheetLockPath = (sheetFile) => `${sheetStatePath(sheetFile)}.lock`;
1254
1438
  const LOCK_SETTLE_MS = 250;
1439
+ export const sheetTakeoverPath = (sheetFile) => `${sheetLockPath(sheetFile)}.takeover`;
1255
1440
  async function takeSheetLock(sheetFile, deps) {
1256
1441
  const files = sheetFilesOf(deps);
1257
1442
  const lockFile = sheetLockPath(sheetFile);
@@ -1293,12 +1478,32 @@ async function takeSheetLock(sheetFile, deps) {
1293
1478
  const stale = holder.pid !== null && holder.host === files.host && !files.isAlive(holder.pid);
1294
1479
  if (!stale)
1295
1480
  return { problem: busy(holder.words) };
1296
- const still = holderOf();
1297
- const same = holder.token !== null ? still.token === holder.token : still.token === null && still.pid === holder.pid && still.at === holder.at;
1298
- if (!same)
1299
- return { problem: busy(still.words) };
1300
- files.remove(lockFile);
1301
- made = tryCreate();
1481
+ const takeoverFile = sheetTakeoverPath(sheetFile);
1482
+ let takeover;
1483
+ try {
1484
+ takeover = files.createNew(takeoverFile, text);
1485
+ }
1486
+ catch (err) {
1487
+ takeover = err instanceof Error ? err : new Error(String(err));
1488
+ }
1489
+ if (takeover !== true) {
1490
+ return {
1491
+ problem: takeover === false
1492
+ ? `Another run of this sheet is taking over the lock ${lockFile} left by a run that is no longer going, so this one sent nothing. If no run of this sheet is going, deleting ${takeoverFile} and ${lockFile} is safe; then run the command again.`
1493
+ : `The lock ${lockFile} could not be taken over (${takeover.message}). Nothing was sent.`,
1494
+ };
1495
+ }
1496
+ try {
1497
+ const still = holderOf();
1498
+ const same = holder.token !== null ? still.token === holder.token : still.token === null && still.pid === holder.pid && still.at === holder.at;
1499
+ if (!same)
1500
+ return { problem: busy(still.words) };
1501
+ files.remove(lockFile);
1502
+ made = tryCreate();
1503
+ }
1504
+ finally {
1505
+ files.remove(takeoverFile);
1506
+ }
1302
1507
  note = `A lock left by a run that is no longer going (${holder.words}) was taken.`;
1303
1508
  }
1304
1509
  if (made === false)
@@ -1375,8 +1580,10 @@ function stateFromJson(raw) {
1375
1580
  return `${whereRun} has a field of the wrong kind`;
1376
1581
  }
1377
1582
  const rp = run.pending;
1378
- if (rp !== null && !(isRecord(rp) && at(rp.at) && typeof rp.swipeId === "string"))
1583
+ if (rp !== null &&
1584
+ !(isRecord(rp) && at(rp.at) && typeof rp.swipeId === "string" && (rp.serverAt === undefined || (typeof rp.serverAt === "number" && Number.isFinite(rp.serverAt))))) {
1379
1585
  return `${whereRun} has a "pending" this CLI did not write`;
1586
+ }
1380
1587
  runs[index] = { ...run };
1381
1588
  }
1382
1589
  writes[persona] = { ...write, runs };
@@ -1392,8 +1599,9 @@ function readSheetState(sheetFile, deps) {
1392
1599
  text = deps.readFile(file);
1393
1600
  }
1394
1601
  catch (err) {
1395
- if (err.code === "ENOENT")
1396
- return { state: { version: 3, sheet: path.basename(sheetFile), sources: dict() } };
1602
+ if (err.code === "ENOENT") {
1603
+ return { state: { version: 3, sheet: path.basename(sheetFile), sources: dict() }, missing: true };
1604
+ }
1397
1605
  return {
1398
1606
  problem: `The state file ${file} is there but can't be opened (${err instanceof Error ? err.message : String(err)}). It keeps what this sheet already bought, so nothing was sent. Fix its permissions, then run the command again.`,
1399
1607
  };
@@ -1406,7 +1614,7 @@ function readSheetState(sheetFile, deps) {
1406
1614
  checked = "it is not valid JSON";
1407
1615
  }
1408
1616
  if (typeof checked !== "string")
1409
- return { state: checked };
1617
+ return { state: checked, missing: false };
1410
1618
  return {
1411
1619
  problem: `The state file ${file} can't be read: ${checked}. Fix it, or move it away; without it the next run buys every step again, even the ones already bought.`,
1412
1620
  };
@@ -1869,12 +2077,19 @@ async function readSwipe(swipeId, deps) {
1869
2077
  const res = await deps.get(`${SWIPES_PATH}?id=${encodeURIComponent(swipeId)}`);
1870
2078
  if (!res.ok)
1871
2079
  return { problem: swipeErrorLine(res) };
1872
- return isRecord(res.data) && isRecord(res.data.swipe) ? { swipe: res.data.swipe } : { problem: "Its answer could not be read." };
2080
+ if (!isRecord(res.data) || !isRecord(res.data.swipe))
2081
+ return { problem: "Its answer could not be read." };
2082
+ const now = res.data.now;
2083
+ return { swipe: res.data.swipe, serverNow: typeof now === "number" && Number.isFinite(now) ? now : null };
2084
+ }
2085
+ function startAge(pending, serverNow, deps) {
2086
+ const local = deps.now() - Date.parse(pending.at);
2087
+ return pending.serverAt !== undefined && serverNow !== null ? Math.min(local, serverNow - pending.serverAt) : local;
1873
2088
  }
1874
2089
  async function settlePendingStart(video, run, outcome, ctx) {
1875
2090
  const pending = run.pending;
1876
- const ago = minutesAgo(ctx.deps.now() - Date.parse(pending.at));
1877
2091
  const read = await readSwipe(pending.swipeId, ctx.deps);
2092
+ const ago = minutesAgo(startAge(pending, "problem" in read ? null : read.serverNow, ctx.deps));
1878
2093
  if ("problem" in read) {
1879
2094
  stopRun(video, run, outcome, `A start was sent ${ago} ago and its answer was not seen, and swipe ${pending.swipeId} could not be read to check it: ${read.problem} Nothing was sent again.`, ctx);
1880
2095
  return "stopped";
@@ -1891,7 +2106,7 @@ async function settlePendingStart(video, run, outcome, ctx) {
1891
2106
  await sayIfFailedAtStart(video, runId, pending.swipeId, ctx);
1892
2107
  return "taken";
1893
2108
  }
1894
- if (ctx.deps.now() - Date.parse(pending.at) < START_PENDING_MS) {
2109
+ if (startAge(pending, read.serverNow, ctx.deps) < START_PENDING_MS) {
1895
2110
  stopRun(video, run, outcome, `A start was sent ${ago} ago and its answer was not seen. It may still be starting, so nothing was sent again. Run the sheet again in a few minutes.`, ctx);
1896
2111
  return "stopped";
1897
2112
  }
@@ -1917,10 +2132,22 @@ async function startVideo(video, run, swipeId, outcome, ctx) {
1917
2132
  await sayIfFailedAtStart(video, existing, swipeId, ctx);
1918
2133
  return;
1919
2134
  }
1920
- run.pending = { at: stamp(ctx.deps), swipeId };
2135
+ run.pending = { at: stamp(ctx.deps), swipeId, ...(read.serverNow !== null ? { serverAt: read.serverNow } : {}) };
1921
2136
  run.updatedAt = stamp(ctx.deps);
1922
2137
  ctx.save();
1923
2138
  const started = answerOf(await swipeStartFlow(swipeId, ctx.sheet.start, { json: true, yes: true, wait: false }, ctx.deps));
2139
+ const held = isRecord(started.alreadyStarted) && typeof started.alreadyStarted.runId === "string" ? started.alreadyStarted : null;
2140
+ if (held) {
2141
+ const heldRunId = held.runId;
2142
+ const holder = heldIds(ctx.state).runs.get(heldRunId);
2143
+ if (holder && holder !== run) {
2144
+ stopRun(video, run, outcome, `Swipe ${swipeId} already has run ${heldRunId}, which is another video's in this sheet. One swipe is one video, so nothing was sent again.`, ctx);
2145
+ return;
2146
+ }
2147
+ takeRun(video, run, outcome, heldRunId, typeof held.url === "string" && held.url ? held.url : null, ctx);
2148
+ ctx.say(` Video ${video.n}: swipe ${swipeId} already has run ${heldRunId}; it is this video's run. Nothing more was started. Check it: exodus video status ${heldRunId}`);
2149
+ return;
2150
+ }
1924
2151
  if (started.ok !== true || typeof started.runId !== "string") {
1925
2152
  if (postRefused(started))
1926
2153
  run.pending = null;
@@ -2169,7 +2396,7 @@ export async function swipeSheetFlow(given, opts, deps) {
2169
2396
  return failed(stateRead.problem, json);
2170
2397
  if (opts.status)
2171
2398
  return sheetStatusFlow(sheet, sheetFile, videos, personas, stateRead.state, opts, deps);
2172
- return sheetPaidFlow(sheet, sheetFile, videos, personas, stateRead.state, null, opts, deps);
2399
+ return sheetPaidFlow(sheet, sheetFile, videos, personas, stateRead.state, null, opts, deps, stateRead.missing);
2173
2400
  }
2174
2401
  const lock = await takeSheetLock(sheetFile, deps);
2175
2402
  if ("problem" in lock)
@@ -2208,8 +2435,70 @@ async function startChecks(sheet, deps) {
2208
2435
  }
2209
2436
  return null;
2210
2437
  }
2438
+ async function lostProgressLines(sheet, sheetFile, state, missing, planned, deps) {
2439
+ const stateName = path.basename(sheetStatePath(sheetFile));
2440
+ const lines = [];
2441
+ if (missing) {
2442
+ const dir = path.dirname(sheetFile);
2443
+ const leftBehind = sheetFilesOf(deps)
2444
+ .listDir(dir)
2445
+ .filter((name) => name.endsWith(".state.json") && name !== stateName)
2446
+ .map((name) => ({ name, sheetName: name.slice(0, -".state.json".length) }))
2447
+ .filter(({ sheetName }) => sheetName && deps.statFile(path.join(dir, sheetName)) === null);
2448
+ for (const { name, sheetName } of leftBehind) {
2449
+ lines.push(`A saved progress file, ${name}, is beside this sheet for a sheet named ${sheetName} that is no longer there. If this sheet was renamed from ${sheetName}, rename ${name} to ${stateName} before the yes; without it the yes buys every step below again.`);
2450
+ }
2451
+ const res = await deps.get(SWIPES_PATH);
2452
+ const rows = res.ok && isRecord(res.data) && Array.isArray(res.data.swipes) ? res.data.swipes : [];
2453
+ const ours = rows.filter((row) => {
2454
+ if (row.outcome?.kind === "refused")
2455
+ return false;
2456
+ return planned.some(({ item, steps }) => {
2457
+ const breakdownId = steps.find((step) => step.step === "breakdown")?.have;
2458
+ if (breakdownId && row.breakdownId === breakdownId)
2459
+ return true;
2460
+ if (item.source.kind === "url")
2461
+ return row.source?.sourceUrl === item.source.url;
2462
+ if (item.source.kind === "file")
2463
+ return row.source?.fileName === path.basename(item.source.file);
2464
+ return row.source?.sourceAdId === item.source.swipeAdId;
2465
+ });
2466
+ });
2467
+ if (ours.length > 0) {
2468
+ const named = ours.map((row) => (row.workflowRunId ? `${row._id} (video run ${row.workflowRunId})` : `${row._id} (no video yet)`)).join(", ");
2469
+ lines.push(`No saved progress was found beside this sheet (${stateName}), but this brand already has swipes of these ads: ${named}. The yes writes and starts them again, which is paid. If this sheet was run before from another folder or under another name, put its saved progress here as ${stateName} first.`);
2470
+ }
2471
+ return lines;
2472
+ }
2473
+ const inSheet = new Set(sheet.personas.length > 0 ? sheet.personas.map((persona) => persona.name) : [""]);
2474
+ for (const item of sheet.sources) {
2475
+ const src = state.sources[item.key];
2476
+ if (!src)
2477
+ continue;
2478
+ for (const [key, write] of Object.entries(src.writes)) {
2479
+ if (inSheet.has(key))
2480
+ continue;
2481
+ const runs = Object.values(write.runs);
2482
+ const runIds = runs.map((run) => run.runId).filter((id) => id !== null);
2483
+ const unseen = runs.map((run) => run.pending?.swipeId).filter((id) => id !== undefined);
2484
+ if (!write.swipeId && !write.pending && runIds.length === 0 && unseen.length === 0)
2485
+ continue;
2486
+ const who = key ? `persona "${key}"` : "the write with no persona";
2487
+ const had = [
2488
+ ...(write.swipeId ? [`swipe ${write.swipeId}`] : []),
2489
+ ...runIds.map((id) => `video run ${id}`),
2490
+ ];
2491
+ lines.push([
2492
+ `The saved progress for ${item.key} has ${who}, which is no longer in the sheet${had.length > 0 ? ` (${had.join(", ")})` : ""}. If it was renamed, the yes writes and starts it again under its new name, which is paid.`,
2493
+ ...unseen.map((id) => `It also has a start for it whose answer was never seen: check exodus video swipe show ${id} before the yes.`),
2494
+ ...(write.pending ? ["It also has a write for it whose end was never seen: check exodus video swipe list before the yes."] : []),
2495
+ ].join(" "));
2496
+ }
2497
+ }
2498
+ return lines;
2499
+ }
2211
2500
  const shellWord = (word) => (/^[\w./@%+=:,-]+$/.test(word) ? word : `'${word.replace(/'/g, "'\\''")}'`);
2212
- async function sheetPaidFlow(sheet, sheetFile, videos, personas, state, lockNote, opts, deps) {
2501
+ async function sheetPaidFlow(sheet, sheetFile, videos, personas, state, lockNote, opts, deps, stateMissing = false) {
2213
2502
  const { json } = opts;
2214
2503
  const stateFile = sheetStatePath(sheetFile);
2215
2504
  for (const [index, item] of sheet.sources.entries()) {
@@ -2244,6 +2533,7 @@ async function sheetPaidFlow(sheet, sheetFile, videos, personas, state, lockNote
2244
2533
  }
2245
2534
  const needsYes = planned.some(({ steps }) => steps.some((step) => step.buy));
2246
2535
  const warning = videos.length > SHEET_VIDEO_WARNING ? [`That is ${videos.length} videos, more than ${SHEET_VIDEO_WARNING}. Check the count with the member before the yes.`] : [];
2536
+ const progressLost = await lostProgressLines(sheet, sheetFile, state, stateMissing, planned, deps);
2247
2537
  if (json) {
2248
2538
  return {
2249
2539
  code: 0,
@@ -2257,6 +2547,7 @@ async function sheetPaidFlow(sheet, sheetFile, videos, personas, state, lockNote
2257
2547
  count,
2258
2548
  videos: videosJson,
2259
2549
  ...(warning.length > 0 ? { warning: warning[0] } : {}),
2550
+ ...(progressLost.length > 0 ? { progressLost } : {}),
2260
2551
  notUsed,
2261
2552
  moved: sheet.moved,
2262
2553
  sources: planned.map(({ item, steps }) => ({ source: item.given, steps })),
@@ -2270,6 +2561,7 @@ async function sheetPaidFlow(sheet, sheetFile, videos, personas, state, lockNote
2270
2561
  lines: [
2271
2562
  ...head,
2272
2563
  ...warning,
2564
+ ...progressLost,
2273
2565
  "",
2274
2566
  ...planned.flatMap(({ item, steps }, i) => [`Ad ${i + 1}: ${item.key}`, ...plannedLines(steps)]),
2275
2567
  "",
@@ -2408,8 +2700,10 @@ export async function runSwipePlan(plan, deps, onProgressLine) {
2408
2700
  return swipeShowFlow(plan.swipeId, opts, deps);
2409
2701
  case "list":
2410
2702
  return swipeListFlow(opts, deps);
2703
+ case "find":
2704
+ return swipeFindFlow(plan.ask, opts, deps);
2411
2705
  case "start":
2412
- return swipeStartFlow(plan.swipeId, plan.ask, opts, deps);
2706
+ return swipeStartFlow(plan.swipeId, plan.ask, opts, deps, plan.again);
2413
2707
  case "run":
2414
2708
  return swipeSheetFlow(plan.sheetFile, { ...opts, retryRefused: plan.retryRefused, status: plan.status, persona: plan.persona }, deps);
2415
2709
  }
@@ -204,7 +204,8 @@ Usage:
204
204
  exodus video swipe write <breakdownId> --product <id> [--mode whole-ad|hook-only|their-format|new-look] [--closeness <1-5|mirror|close|same-beats|same-arc|pattern-only>] [--look <slug>] [--script <file>] [--yes] [--json]
205
205
  exodus video swipe show <swipeId> [--json]
206
206
  exodus video swipe list [--json]
207
- exodus video swipe start <swipeId> [--style <look>] [--title "<name>"] [--music] [--one-shot] [--yes] [--wait] [--json]
207
+ exodus video swipe find [--brand "<name>"] [--limit <n>] [--json]
208
+ exodus video swipe start <swipeId> [--style <look>] [--title "<name>"] [--music] [--one-shot] [--again] [--yes] [--wait] [--json]
208
209
  exodus video swipe run --sheet <file> [--status] [--persona <name>] [--yes] [--retry-refused] [--wait] [--json]
209
210
 
210
211
  Options:
@@ -449,7 +450,8 @@ what it buys and who pays. The CLI prints no price for any of them.
449
450
  YouTube (swipe). A link this brand broke down before is
450
451
  used again, and costs nothing
451
452
  --ad <swipeAdId> An ad in the brand's swipe library (swipe). An ad
452
- broken down before costs nothing
453
+ broken down before costs nothing. swipe find lists
454
+ the library's video ads and their ids
453
455
  --yes The member said yes to this paid step (swipe, swipe
454
456
  template, swipe write, swipe start), or to every paid
455
457
  step of the sheet (swipe run)
@@ -485,6 +487,9 @@ what it buys and who pays. The CLI prints no price for any of them.
485
487
  --script <file> Your own script (swipe write --mode their-format)
486
488
  --style <look> A look other than the swipe's own (swipe start)
487
489
  --title "<name>" The ad's name (swipe start). Admin-only
490
+ --again A second, paid video from a swipe that already has one
491
+ (swipe start). Without it the server refuses to start a
492
+ swipe whose video is there, and names that run
488
493
  --sheet <file> The whole swipe in one JSON file (swipe run): the ads
489
494
  (sources, each a url, an ad id or a file), the product,
490
495
  the personas, mode, closeness, look or script, the
@@ -502,6 +507,16 @@ what it buys and who pays. The CLI prints no price for any of them.
502
507
  --persona <name> Only that persona's videos (swipe run)
503
508
  --retry-refused Write again an ad the writer refused (swipe run). Paid,
504
509
  so it needs --yes too
510
+ --brand "<name>" Only that competitor's ads, by a case-blind piece of
511
+ its name (swipe find)
512
+ --limit <n> How many ads swipe find shows, 1 to 200. 30 if left off.
513
+ The counts are of every match
514
+ swipe find is free and buys nothing: it looks through up to 200 ads of the
515
+ brand's swipe library, shared fairly across its competitors (the whole
516
+ library when it holds fewer), keeping the video ads with a file, newest
517
+ collected first. Its counts are of the ads it looked through. It holds no
518
+ results and no kind, so it ranks by neither; the kind of an ad is known only
519
+ after it is read. It takes no other verb's flags.
505
520
  The template picks the kind of ad: swipe template prints it and its look, so
506
521
  ask the member before the write. A swipe run has no picks stop and no pilot
507
522
  clip; it stops at the storyboard unless --one-shot. --wait on swipe and swipe
@@ -549,6 +564,7 @@ Examples:
549
564
  exodus video swipe template bd_123 --yes
550
565
  exodus video swipe write bd_123 --product prod_1 --mode hook-only --closeness close --yes
551
566
  exodus video swipe start sw_123 --yes --wait
567
+ exodus video swipe find --brand "AG1" --json
552
568
  `.trim();
553
569
  const SHOWS_PATH = "/api/v2/shows";
554
570
  const RUNS_PATH = "/api/v2/video/runs";
@@ -6071,23 +6087,30 @@ const VALUE_FLAGS = new Set([
6071
6087
  "sheet",
6072
6088
  "persona",
6073
6089
  ]);
6090
+ const FIND_VALUE_FLAGS = new Set(["brand", "limit"]);
6074
6091
  export function parsePositional(args = process.argv.slice(3)) {
6075
- const out = [];
6076
- let i = 0;
6077
- while (i < args.length) {
6078
- const arg = args[i];
6079
- if (arg.startsWith("--")) {
6080
- const key = arg.slice(2).split("=", 1)[0] ?? "";
6081
- if (!arg.includes("=") && VALUE_FLAGS.has(key))
6082
- i += 2;
6083
- else
6084
- i++;
6085
- continue;
6092
+ const read = (valueFlags) => {
6093
+ const out = [];
6094
+ let i = 0;
6095
+ while (i < args.length) {
6096
+ const arg = args[i];
6097
+ if (arg.startsWith("--")) {
6098
+ const key = arg.slice(2).split("=", 1)[0] ?? "";
6099
+ if (!arg.includes("=") && (VALUE_FLAGS.has(key) || valueFlags.has(key)))
6100
+ i += 2;
6101
+ else
6102
+ i++;
6103
+ continue;
6104
+ }
6105
+ out.push(arg);
6106
+ i++;
6086
6107
  }
6087
- out.push(arg);
6088
- i++;
6089
- }
6090
- return out;
6108
+ return out;
6109
+ };
6110
+ const asFind = read(FIND_VALUE_FLAGS);
6111
+ if (asFind[0] === "swipe" && asFind[1] === "find")
6112
+ return asFind;
6113
+ return read(new Set());
6091
6114
  }
6092
6115
  function flagString(flags, name) {
6093
6116
  const value = flags[name];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aicopycoders/exodus",
3
- "version": "2026.11.1100-beta.6",
3
+ "version": "2026.11.1100-beta.8",
4
4
  "description": "CLI + Claude Code skills for the Copycoders Exodus ad pipeline",
5
5
  "repository": {
6
6
  "type": "git",