@clickminded/coauthor-cli 0.0.29 → 0.0.30

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.
package/dist/client.d.ts CHANGED
@@ -23,6 +23,11 @@ export declare class AgentClient {
23
23
  private readonly fetchImpl;
24
24
  constructor(options: AgentClientOptions);
25
25
  request(options: RequestOptions): Promise<JsonValue>;
26
+ /**
27
+ * Fetches a public file (for example a rendered MP4 on the CDN) as bytes.
28
+ * Sends no Authorization header: the URL is not an agent API endpoint.
29
+ */
30
+ download(url: string): Promise<Uint8Array>;
26
31
  }
27
32
  export declare function isLiveAction(method: string): boolean;
28
33
  export declare function normalizeBaseUrl(baseUrl: string): string;
package/dist/client.js CHANGED
@@ -57,6 +57,16 @@ export class AgentClient {
57
57
  }
58
58
  return parsedBody;
59
59
  }
60
+ /**
61
+ * Fetches a public file (for example a rendered MP4 on the CDN) as bytes.
62
+ * Sends no Authorization header: the URL is not an agent API endpoint.
63
+ */
64
+ async download(url) {
65
+ const response = await this.fetchImpl(url, { method: 'GET' });
66
+ if (!response.ok)
67
+ throw new Error(`Download failed with HTTP ${response.status} for ${url}`);
68
+ return new Uint8Array(await response.arrayBuffer());
69
+ }
60
70
  }
61
71
  export function isLiveAction(method) {
62
72
  return !['GET', 'HEAD', 'OPTIONS'].includes(method.toUpperCase());
package/dist/commands.js CHANGED
@@ -1501,17 +1501,30 @@ async function runRepurposeCommand(action, input, client) {
1501
1501
  }
1502
1502
  if (action === 'generate') {
1503
1503
  if (!format)
1504
- throw new Error(`Usage: coauthor repurpose generate <project-id> --format <${REPURPOSE_GENERATABLE.join('|')}|all> [--writing-model <id>]`);
1504
+ throw new Error(`Usage: coauthor repurpose generate <project-id> --format <${[...REPURPOSE_GENERATABLE, 'video'].join('|')}|all> [--writing-model <id>] [--cta save,follow]`);
1505
1505
  const formats = format === 'all' ? REPURPOSE_GENERATABLE : [format];
1506
1506
  const writingModel = getString(input.values, 'writing-model');
1507
+ const cta = getString(input.values, 'cta');
1508
+ if (cta !== undefined && format !== 'video')
1509
+ throw new Error('--cta only applies to --format video.');
1507
1510
  const results = {};
1508
1511
  for (const entry of formats) {
1509
1512
  results[entry] = await client.request({
1510
1513
  method: 'POST',
1511
1514
  path: `${base}/${encodeURIComponent(entry)}/generate`,
1512
- body: writingModel ? { writingModel } : {},
1515
+ body: {
1516
+ ...(writingModel ? { writingModel } : {}),
1517
+ ...(entry === 'video' && cta !== undefined ? { cta_variants: parseCtaList(cta) } : {}),
1518
+ },
1513
1519
  });
1514
1520
  }
1521
+ if (format === 'video') {
1522
+ return {
1523
+ ok: true,
1524
+ message: `Generated the video deck. Slide images are generating (usually 1-3 minutes). Next: coauthor repurpose render ${projectId} --format video --wait, then coauthor repurpose download ${projectId} --format video`,
1525
+ data: results.video,
1526
+ };
1527
+ }
1515
1528
  return {
1516
1529
  ok: true,
1517
1530
  message: `Generated ${formats.join(', ')}. Review with: coauthor repurpose show ${projectId} --format <format> --json, or save files with: coauthor repurpose download ${projectId} --format ${format}`,
@@ -1527,11 +1540,137 @@ async function runRepurposeCommand(action, input, client) {
1527
1540
  data: await client.request({ method: 'POST', path: `${base}/${encodeURIComponent(format)}/save`, body: parseJsonOption(input.values) }),
1528
1541
  };
1529
1542
  }
1543
+ if (action === 'status') {
1544
+ if (format !== 'video')
1545
+ throw new Error('Usage: coauthor repurpose status <project-id> --format video [--wait]');
1546
+ return videoStatus(client, base, getBoolean(input.values, 'wait'));
1547
+ }
1548
+ if (action === 'render') {
1549
+ if (format !== 'video')
1550
+ throw new Error('Usage: coauthor repurpose render <project-id> --format video [--variant <id>] [--wait]');
1551
+ return videoRender(client, projectId, base, getString(input.values, 'variant'), getBoolean(input.values, 'wait'));
1552
+ }
1530
1553
  if (action === 'download')
1531
- return downloadRepurposed(projectId, format ?? 'all', getString(input.values, 'out'), client);
1532
- throw new Error('Usage: coauthor repurpose <list|show|generate|save|download> <project-id> --format <format>');
1554
+ return downloadRepurposed(projectId, format ?? 'all', getString(input.values, 'out'), client, getString(input.values, 'variant'));
1555
+ throw new Error('Usage: coauthor repurpose <list|show|generate|save|download|status|render> <project-id> --format <format>');
1556
+ }
1557
+ /** "save,follow,custom:Reply with a question" -> ["save","follow","custom:Reply with a question"]. */
1558
+ function parseCtaList(value) {
1559
+ const items = value.split(',').map((item) => item.trim()).filter(Boolean);
1560
+ if (items.length === 0)
1561
+ throw new Error('--cta needs at least one intent, for example --cta save,follow (save, follow, comment, share, read_more, custom:<text>).');
1562
+ return items;
1563
+ }
1564
+ const VIDEO_ACTIVE_RENDER_STATUSES = ['pending', 'rendering', 'encoding', 'uploading'];
1565
+ function asVideoStatus(data) {
1566
+ return data;
1567
+ }
1568
+ function describeVideoStatus(status) {
1569
+ if (!status.exists)
1570
+ return 'No video yet. Generate one with: coauthor repurpose generate <project-id> --format video';
1571
+ const panels = status.panels;
1572
+ const lines = [panels ? `Panels: ${panels.done}/${panels.total} done, ${panels.generating} generating, ${panels.failed} failed.` : 'Panels: none.'];
1573
+ for (const render of status.renders) {
1574
+ lines.push(`Render ${render.variant_id}: ${render.status}${VIDEO_ACTIVE_RENDER_STATUSES.includes(render.status) ? ` (${render.progress}%)` : ''}${render.video_url ? ` ${render.video_url}` : ''}${render.error_message ? ` - ${render.error_message}` : ''}`);
1575
+ }
1576
+ return lines.join('\n');
1577
+ }
1578
+ // Polls until `settled(status)` or the deadline (9 minutes by default: the
1579
+ // shell limit for agents). Returns the last status and whether it settled.
1580
+ async function pollVideoStatus(client, base, settled, deadline) {
1581
+ const pollMs = Math.min(waitPollMs(), 15_000);
1582
+ for (;;) {
1583
+ const data = await client.request({ path: `${base}/video/status` });
1584
+ const status = asVideoStatus(data);
1585
+ if (settled(status))
1586
+ return { status, data, settled: true };
1587
+ if (Date.now() >= deadline)
1588
+ return { status, data, settled: false };
1589
+ await sleep(pollMs);
1590
+ }
1591
+ }
1592
+ const panelsSettled = (status) => !status.exists || !status.panels || status.panels.generating === 0;
1593
+ const noActiveRender = (status) => !status.renders.some((render) => VIDEO_ACTIVE_RENDER_STATUSES.includes(render.status));
1594
+ async function videoStatus(client, base, wait) {
1595
+ const deadline = Date.now() + waitTimeoutMs(9 * 60_000);
1596
+ const polled = await pollVideoStatus(client, base, (status) => !wait || (panelsSettled(status) && noActiveRender(status)), deadline);
1597
+ const data = polled.data;
1598
+ const stillRunning = wait && !polled.settled;
1599
+ return {
1600
+ ok: true,
1601
+ status: stillRunning ? 'still_running' : undefined,
1602
+ exitCode: stillRunning ? 2 : undefined,
1603
+ message: `${describeVideoStatus(polled.status)}${stillRunning ? '\nStill running. Check again with: coauthor repurpose status <project-id> --format video --wait' : ''}`,
1604
+ data,
1605
+ };
1606
+ }
1607
+ async function videoRender(client, projectId, base, variant, wait) {
1608
+ const deadline = Date.now() + waitTimeoutMs(9 * 60_000);
1609
+ if (wait) {
1610
+ // Slide images usually finish before the render is asked for; wait for stragglers.
1611
+ const panels = await pollVideoStatus(client, base, panelsSettled, deadline);
1612
+ if (!panels.settled) {
1613
+ return { ok: true, status: 'still_running', exitCode: 2, message: `Slide images are still generating.\n${describeVideoStatus(panels.status)}\nCheck again with: coauthor repurpose render ${projectId} --format video --wait`, data: panels.data };
1614
+ }
1615
+ }
1616
+ const started = await client.request({
1617
+ method: 'POST',
1618
+ path: `${base}/video/render`,
1619
+ body: variant ? { variant } : {},
1620
+ });
1621
+ const render = getResponseValue(started, 'render');
1622
+ const renderId = render ? getResponseString(render, 'id') : undefined;
1623
+ if (!wait) {
1624
+ return {
1625
+ ok: true,
1626
+ message: `Render started (usually about 3 minutes). Check with: coauthor repurpose status ${projectId} --format video --wait, then download with: coauthor repurpose download ${projectId} --format video`,
1627
+ data: started,
1628
+ };
1629
+ }
1630
+ const finished = await pollVideoStatus(client, base, (status) => {
1631
+ const row = status.renders.find((entry) => entry.id === renderId);
1632
+ return !row || row.status === 'done' || row.status === 'failed';
1633
+ }, deadline);
1634
+ const row = finished.status.renders.find((entry) => entry.id === renderId);
1635
+ if (!finished.settled) {
1636
+ return {
1637
+ ok: true,
1638
+ status: 'still_running',
1639
+ exitCode: 2,
1640
+ message: `Render still running (${row?.status ?? 'pending'}, ${row?.progress ?? 0}%). Check again with: coauthor repurpose status ${projectId} --format video --wait`,
1641
+ data: finished.data,
1642
+ };
1643
+ }
1644
+ if (row && row.status === 'failed') {
1645
+ return { ok: false, message: `Render failed: ${row.error_message ?? 'unknown error'}. Try again with: coauthor repurpose render ${projectId} --format video`, data: finished.data };
1646
+ }
1647
+ return {
1648
+ ok: true,
1649
+ message: `Render done${row?.video_url ? `: ${row.video_url}` : ''}. Download it with: coauthor repurpose download ${projectId} --format video`,
1650
+ data: finished.data,
1651
+ };
1652
+ }
1653
+ // Downloads each finished render's MP4 from its public URL (no agent auth) to
1654
+ // <out>/video-<variant>.mp4.
1655
+ async function downloadVideoRenders(client, shown, outDir, variant) {
1656
+ const renders = getResponseValue(shown, 'renders') ?? [];
1657
+ const files = [];
1658
+ const pending = [];
1659
+ for (const render of renders) {
1660
+ const variantId = render.variant_id ?? '';
1661
+ if (variant && variantId !== variant)
1662
+ continue;
1663
+ if (render.status !== 'done' || !render.video_url) {
1664
+ pending.push(variantId);
1665
+ continue;
1666
+ }
1667
+ const name = `video-${variantId.replace(/[^A-Za-z0-9_-]+/g, '_') || render.id || 'render'}.mp4`;
1668
+ await writeFile(join(outDir, name), await client.download(render.video_url));
1669
+ files.push(name);
1670
+ }
1671
+ return { files, pending };
1533
1672
  }
1534
- async function downloadRepurposed(projectId, format, outOption, client) {
1673
+ async function downloadRepurposed(projectId, format, outOption, client, variant) {
1535
1674
  const outDir = resolve(outOption ?? `coauthor-${projectId.slice(0, 8)}`);
1536
1675
  await mkdir(outDir, { recursive: true });
1537
1676
  const written = [];
@@ -1552,10 +1691,29 @@ async function downloadRepurposed(projectId, format, outOption, client) {
1552
1691
  const formats = format === 'all' ? REPURPOSE_FORMATS : format === 'article' ? [] : [format];
1553
1692
  const manifest = {};
1554
1693
  const missingLink = [];
1694
+ let noVideoFile = false;
1555
1695
  for (const entry of formats) {
1556
1696
  const shown = await client.request({ path: `projects/${encodeURIComponent(projectId)}/repurpose/${encodeURIComponent(entry)}` });
1557
1697
  const artifact = getResponseValue(shown, 'artifact');
1558
1698
  const copy = getResponseValue(shown, 'copy');
1699
+ if (entry === 'video') {
1700
+ if (!artifact) {
1701
+ skipped.push(entry);
1702
+ continue;
1703
+ }
1704
+ const videos = await downloadVideoRenders(client, shown, outDir, variant);
1705
+ written.push(...videos.files);
1706
+ await write('video.json', JSON.stringify(artifact, null, 2));
1707
+ manifest.video = {
1708
+ stale: Boolean(getResponseValue(artifact, 'stale_at')),
1709
+ updated_at: getResponseValue(artifact, 'updated_at') ?? null,
1710
+ files: videos.files,
1711
+ unfinished_variants: videos.pending,
1712
+ };
1713
+ if (videos.files.length === 0)
1714
+ noVideoFile = true;
1715
+ continue;
1716
+ }
1559
1717
  if (!artifact || !copy) {
1560
1718
  skipped.push(entry);
1561
1719
  continue;
@@ -1576,7 +1734,8 @@ async function downloadRepurposed(projectId, format, outOption, client) {
1576
1734
  ok: true,
1577
1735
  message: [
1578
1736
  `Wrote ${written.length} files to ${outDir}`,
1579
- skipped.length > 0 ? `Not generated yet: ${skipped.join(', ')} (coauthor repurpose generate ${projectId} --format <format>; slideshow and video are made in the web app).` : '',
1737
+ skipped.length > 0 ? `Not generated yet: ${skipped.join(', ')} (coauthor repurpose generate ${projectId} --format <format>; slideshows are made in the web app).` : '',
1738
+ noVideoFile ? `The video has no finished render yet: coauthor repurpose render ${projectId} --format video --wait, then download again.` : '',
1580
1739
  staleNote.length > 0 ? `Stale (the draft changed since they were made): ${staleNote.join(', ')}. Regenerate them before posting.` : '',
1581
1740
  missingLink.length > 0
1582
1741
  ? `No article link yet: ${missingLink.join(', ')} still contain {{POST_URL}}. Set it with coauthor repurpose save ${projectId} --format <format> --data '{"destination_url":"https://..."}' and download again, or replace it when posting.`
@@ -1855,7 +2014,7 @@ export function helpResult(command = []) {
1855
2014
  ' contract show|save|approve',
1856
2015
  ' outline show|generate|revise|save|approve',
1857
2016
  ' research-plan show|generate|revise|save|approve',
1858
- ' repurpose list|generate|show|save|download',
2017
+ ' repurpose list|generate|show|save|download|status|render',
1859
2018
  ' brief review|answer',
1860
2019
  ' profile list|show',
1861
2020
  ' source list|add|remove',
@@ -1968,11 +2127,16 @@ function commandHelp(command) {
1968
2127
  ' coauthor repurpose generate <project-id> --format <x-thread|x-post|linkedin|facebook|email|all> [--writing-model <id>] [--json]',
1969
2128
  ' coauthor repurpose show <project-id> --format <format> [--json]',
1970
2129
  ' coauthor repurpose save <project-id> --format <format> --data @edits.json [--json]',
1971
- ' coauthor repurpose download <project-id> [--format <format|article|all>] [--out <dir>]',
2130
+ ' coauthor repurpose download <project-id> [--format <format|article|all>] [--out <dir>] [--variant <id>]',
2131
+ ' coauthor repurpose generate <project-id> --format video [--cta save,follow] [--writing-model <id>] [--json]',
2132
+ ' coauthor repurpose status <project-id> --format video [--wait] [--json]',
2133
+ ' coauthor repurpose render <project-id> --format video [--variant <id>] [--wait] [--json]',
1972
2134
  '',
1973
2135
  'Turns the finished draft into social posts and an email newsletter. generate takes about 20-90 seconds per format and replaces the previous version.',
1974
2136
  'show returns data.copy (copy-ready text with the destination link filled in). download writes article.md, <format>.md, <format>.json, and manifest.json.',
1975
- 'Slideshows and videos are generated in the web app; download includes them only as JSON once they exist. Publish an X thread with coauthor publish thread.',
2137
+ 'Video: generate writes a short vertical deck and starts its slide images (1-3 minutes); --cta picks the ending call to action (comma-separated: save, follow, comment, share, read_more, custom:<text>; default save).',
2138
+ 'status shows panels done/failed/generating and each render; render makes the MP4 (about 3 minutes, one render at a time per account; --wait polls up to 9 minutes, exit code 2 if still running); download saves finished MP4s as <out>/video-<variant>.mp4.',
2139
+ 'Slideshows are generated in the web app; download includes them only as JSON once they exist. Publish an X thread with coauthor publish thread.',
1976
2140
  ].join('\n'),
1977
2141
  brief: [
1978
2142
  'Usage: coauthor brief review <project-id> [--json]',
package/dist/parser.js CHANGED
@@ -69,6 +69,8 @@ const OPTIONS = {
69
69
  feedback: { type: 'string' },
70
70
  profile: { type: 'string' },
71
71
  out: { type: 'string' },
72
+ cta: { type: 'string' },
73
+ variant: { type: 'string' },
72
74
  all: { type: 'boolean', default: false },
73
75
  kind: { type: 'string' },
74
76
  apply: { type: 'boolean', default: false },
@@ -166,7 +168,7 @@ function commandLength(positionals) {
166
168
  if (first === 'workflow')
167
169
  return second ? 2 : 1;
168
170
  if (first === 'repurpose')
169
- return second && ['list', 'show', 'generate', 'save', 'download'].includes(second) ? 2 : 1;
171
+ return second && ['list', 'show', 'generate', 'save', 'download', 'status', 'render'].includes(second) ? 2 : 1;
170
172
  if (first === 'draft' && second === 'revision')
171
173
  return positionals[2] && ['show', 'apply', 'discard'].includes(positionals[2]) ? 3 : 2;
172
174
  if (first === 'credits')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clickminded/coauthor-cli",
3
- "version": "0.0.29",
3
+ "version": "0.0.30",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "coauthor": "dist/index.js",
@@ -66,4 +66,4 @@ Everything else, including auth problems: `references/troubleshooting.md`. Credi
66
66
 
67
67
  ## Not in the CLI yet
68
68
 
69
- Creating or editing writer profiles, PDFs over about 3.3 MB, adding more images than CoAuthor planned, slideshows, and video. Point the user to the CoAuthor web app at https://tools.clickminded.com/coauthor for these instead of improvising.
69
+ Creating or editing writer profiles, PDFs over about 3.3 MB, adding more images than CoAuthor planned, and slideshows. Point the user to the CoAuthor web app at https://tools.clickminded.com/coauthor for these instead of improvising.
@@ -10,7 +10,7 @@ Once the draft is final, CoAuthor turns it into distribution copy in the project
10
10
  | Facebook post | `facebook` | Variations with alternate hooks |
11
11
  | Email newsletter | `email` | Variations with subject line, preheader, and body |
12
12
 
13
- Slideshows (carousels) and short videos are generated in the CoAuthor web app (open the project, then Promote). `repurpose download` includes them as JSON once they exist.
13
+ Slideshows (carousels) are generated in the CoAuthor web app (open the project, then Promote); `repurpose download` includes them as JSON once they exist. Short vertical videos can be made from the CLI (see below).
14
14
 
15
15
  ## Generate
16
16
 
@@ -44,6 +44,15 @@ coauthor repurpose save <id> --format x-thread --data '{"posts":[...]}' --json
44
44
 
45
45
  Add `"destination_url": "https://..."` to point the posts at the published article. Keep the `{{POST_URL}}` placeholder in stored text; it is replaced with the destination URL on copy.
46
46
 
47
+ ## Video
48
+
49
+ A short vertical video (1080x1920) of the article's key points, with illustrated panels and a closing call to action.
50
+
51
+ 1. `coauthor repurpose generate <id> --format video [--cta save,follow] --json` writes the video script and starts its panel images. CTA intents: `save`, `follow`, `comment`, `share`, `read_more`, `custom:<text>`; the default is `save`. Panel images cost image credits, which is why video is not part of `--format all`.
52
+ 2. `coauthor repurpose status <id> --format video --wait --json` waits until the panels are done (`ready_to_render`).
53
+ 3. `coauthor repurpose render <id> --format video [--variant <id>] --wait --json` renders the MP4. It takes about 3 minutes for a typical video and runs on a shared queue, so only one render per account at a time: `render_in_progress` (429) means wait for the current one. `panels_not_ready` (409) means the panel images aren't finished yet.
54
+ 4. `coauthor repurpose download <id> --format video --out <dir>` saves `video-<variant>.mp4`.
55
+
47
56
  ## Deliver
48
57
 
49
58
  `coauthor repurpose download <id> --out <dir>` writes:
@@ -68,7 +68,7 @@ Everything else, including auth problems: `references/troubleshooting.md`. Credi
68
68
 
69
69
  ## Not in the CLI yet
70
70
 
71
- Creating or editing writer profiles, PDFs over about 3.3 MB, adding more images than CoAuthor planned, slideshows, and video. Point the user to the CoAuthor web app at https://tools.clickminded.com/coauthor for these instead of improvising.
71
+ Creating or editing writer profiles, PDFs over about 3.3 MB, adding more images than CoAuthor planned, and slideshows. Point the user to the CoAuthor web app at https://tools.clickminded.com/coauthor for these instead of improvising.
72
72
 
73
73
  # Reference sections
74
74
 
@@ -410,7 +410,7 @@ Once the draft is final, CoAuthor turns it into distribution copy in the project
410
410
  | Facebook post | `facebook` | Variations with alternate hooks |
411
411
  | Email newsletter | `email` | Variations with subject line, preheader, and body |
412
412
 
413
- Slideshows (carousels) and short videos are generated in the CoAuthor web app (open the project, then Promote). `repurpose download` includes them as JSON once they exist.
413
+ Slideshows (carousels) are generated in the CoAuthor web app (open the project, then Promote); `repurpose download` includes them as JSON once they exist. Short vertical videos can be made from the CLI (see below).
414
414
 
415
415
  ### Generate
416
416
 
@@ -444,6 +444,15 @@ coauthor repurpose save <id> --format x-thread --data '{"posts":[...]}' --json
444
444
 
445
445
  Add `"destination_url": "https://..."` to point the posts at the published article. Keep the `{{POST_URL}}` placeholder in stored text; it is replaced with the destination URL on copy.
446
446
 
447
+ ### Video
448
+
449
+ A short vertical video (1080x1920) of the article's key points, with illustrated panels and a closing call to action.
450
+
451
+ 1. `coauthor repurpose generate <id> --format video [--cta save,follow] --json` writes the video script and starts its panel images. CTA intents: `save`, `follow`, `comment`, `share`, `read_more`, `custom:<text>`; the default is `save`. Panel images cost image credits, which is why video is not part of `--format all`.
452
+ 2. `coauthor repurpose status <id> --format video --wait --json` waits until the panels are done (`ready_to_render`).
453
+ 3. `coauthor repurpose render <id> --format video [--variant <id>] --wait --json` renders the MP4. It takes about 3 minutes for a typical video and runs on a shared queue, so only one render per account at a time: `render_in_progress` (429) means wait for the current one. `panels_not_ready` (409) means the panel images aren't finished yet.
454
+ 4. `coauthor repurpose download <id> --format video --out <dir>` saves `video-<variant>.mp4`.
455
+
447
456
  ### Deliver
448
457
 
449
458
  `coauthor repurpose download <id> --out <dir>` writes: