The open source AI video agent: turns any coding agent into a video agent, with an editor to change anything it makes.
Patterns that read long input once: clip names, tool receipts, chat markdown (#44)
riverisbuilding0f6ff68fe2f8
diff --git a/apps/desktop/scripts/release.mjs b/apps/desktop/scripts/release.mjsindex c4d43f1..eec083b 100644--- a/apps/desktop/scripts/release.mjs+++ b/apps/desktop/scripts/release.mjs@@ -200,7 +200,7 @@ if (!unsigned && !win && FEED) {const sha512 = createHash('sha512').update(bytes).digest('base64');const feed = join(out, 'latest-mac.yml');const name = basename(dmg);- writeFileSync(feed, readFileSync(feed, 'utf8').replace(new RegExp(`(- url: ${name.replace(/[.]/g, '\\.')}\\n\\s+sha512: )\\S+(\\n\\s+size: )\\d+`), `$1${sha512}$2${bytes.length}`));+ writeFileSync(feed, readFileSync(feed, 'utf8').replace(new RegExp(`(- url: ${name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\n\\s+sha512: )\\S+(\\n\\s+size: )\\d+`), `$1${sha512}$2${bytes.length}`));if (!readFileSync(feed, 'utf8').includes(sha512)) throw new Error('the feed does not list the signed .dmg');}console.log(`\n${readdirSync(out).filter((f) => /\.(dmg|zip|exe|yml)$/.test(f)).map((f) => join(out, f)).join('\n')}`);diff --git a/packages/openfilm/src/film-doc.mjs b/packages/openfilm/src/film-doc.mjsindex 8582a71..05fd718 100644--- a/packages/openfilm/src/film-doc.mjs+++ b/packages/openfilm/src/film-doc.mjs@@ -237,13 +237,21 @@ function readClip(raw, where, problems) {/** Seconds, to the millisecond. @param {number} s */const toMs = (s) => Math.round(s * 1000) / 1000 || 0;+/** A name without the dashes at its ends (by index: a pattern for it backtracks over a long run of them). */+function trimDashes(/** @type {string} */ name) {+ let start = 0, end = name.length;+ while (start < end && name[start] === '-') start++;+ while (end > start && name[end - 1] === '-') end--;+ return name.slice(start, end);+}+/*** The name a clip gets when it has none: its source's file name (`assets/audio/vo/02-turn.m4a` → `02-turn`), with* `-2`, `-3` when taken. Letters are Unicode letters: a file named in Chinese keeps its name.*/export function clipIdFor(src, used) {const base = (src ?? '').split(/[/\\]/).pop() ?? '';- const stem = base.replace(/\.[A-Za-z0-9]+$/, '').replace(/[^\p{L}\p{N}_-]+/gu, '-').replace(/^-+|-+$/g, '') || 'clip';+ const stem = trimDashes(base.replace(/\.[A-Za-z0-9]+$/, '').replace(/[^\p{L}\p{N}_-]+/gu, '-')) || 'clip';const taken = new Set(used);if (!taken.has(stem)) return stem;let n = 2;diff --git a/packages/openfilm/src/film-doc.test.mjs b/packages/openfilm/src/film-doc.test.mjsindex f408ae5..4001d0a 100644--- a/packages/openfilm/src/film-doc.test.mjs+++ b/packages/openfilm/src/film-doc.test.mjs@@ -1,6 +1,6 @@import { test } from 'node:test';import assert from 'node:assert/strict';-import { clipFade, clipKind, clipSpan, fadeGain, filmHtml, kindOf, parseFilm, pictureRect, readFilm, readFilmFile, soundRole, sourceAt } from './film-doc.mjs';+import { clipFade, clipIdFor, clipKind, clipSpan, fadeGain, filmHtml, kindOf, parseFilm, pictureRect, readFilm, readFilmFile, soundRole, sourceAt } from './film-doc.mjs';const film = (clip) => ({ stage: { w: 1920, h: 1080 }, tracks: [{ clips: [clip] }] });const problems = (value) => readFilm(value).problems.join('\n');@@ -305,3 +305,10 @@ test('soundRole: the nearest folder named for a role decides, then the name, elsassert.equal(soundRole('assets/audio/pop.wav'), 'voice');assert.equal(soundRole('assets/effective/line.wav'), 'voice');});++test('a clip named after its file has no dashes at its ends, however many there are', () => {+ assert.equal(clipIdFor('assets/--intro--.mp4', []), 'intro');+ assert.equal(clipIdFor('assets/片头.mp4', ['片头']), '片头-2');+ assert.equal(clipIdFor(`a${'-'.repeat(200_000)}b`, []), `a${'-'.repeat(200_000)}b`);+ assert.equal(clipIdFor('----.mp4', []), 'clip');+});diff --git a/packages/shared/src/agent-activity.test.ts b/packages/shared/src/agent-activity.test.tsindex 5e430f8..3fd374c 100644--- a/packages/shared/src/agent-activity.test.ts+++ b/packages/shared/src/agent-activity.test.ts@@ -84,3 +84,11 @@ test('asking the person: the question and options only, each clipped', () => {assert.equal(long.question.length, AGENT_ASK_QUESTION_MAX);assert.equal(long.options[0]!.label.length, AGENT_ASK_LABEL_MAX);});++test('made media: image references after the receipt are taken off, however much space is around them', () => {+ const ref = `[image:${'a'.repeat(64)}]`;+ const receipt = JSON.stringify({ src: 'assets/image/wall.png' });+ assert.deepEqual(publicActivityResult('image_gen', `${receipt}\n${ref} \n ${ref}\n`), { kind: 'image', src: 'assets/image/wall.png' });+ // a long run of spaces is read once, not again from each of them+ assert.equal(publicActivityResult('image_gen', `${receipt}${' '.repeat(200_000)}x`), null);+});diff --git a/packages/shared/src/agent-activity.ts b/packages/shared/src/agent-activity.tsindex 9125223..f0e0743 100644--- a/packages/shared/src/agent-activity.ts+++ b/packages/shared/src/agent-activity.ts@@ -209,6 +209,10 @@ export function producesAsset(name: string): boolean {return PRODUCING_TOOLS.has(hostedToolName(name));}+/** An image reference at the very end of a tool's output; taken off one at a time (a single pattern for a run of+ * them backtracks over long whitespace). */+const IMAGE_REF_AT_END = /\[image:[a-f0-9]{64}\]$/i;+/*** A tool call's receipt → the media it made, or null. Picked out like `publicActivity`: only for the tools that make* media, only the receipt's `src` (a media file under `assets/`) and its duration; nothing else of the receipt.@@ -219,7 +223,9 @@ export function publicActivityResult(name: string, resultText: string | undefinetry {// Archived tool output appends image references after the JSON receipt.// They identify the same image; they must not hide its public preview.- receipt = JSON.parse(resultText.trim().replace(/(?:\s*\[image:[a-f0-9]{64}\])+\s*$/i, '').trim());+ let text = resultText.trim();+ for (let ref = IMAGE_REF_AT_END.exec(text); ref; ref = IMAGE_REF_AT_END.exec(text)) text = text.slice(0, ref.index).trimEnd();+ receipt = JSON.parse(text);} catch {return null;}diff --git a/packages/shared/src/markdown-blocks.ts b/packages/shared/src/markdown-blocks.tsindex 9497ece..3f1166f 100644--- a/packages/shared/src/markdown-blocks.ts+++ b/packages/shared/src/markdown-blocks.ts@@ -75,7 +75,7 @@ export function scanMarkdownBlocks(continue;}if (/^---+$/.test(trimmed)) { push({ kind: 'hr' }); i += 1; continue; }- const heading = /^(#{1,6})\s+(.+)$/.exec(trimmed);+ const heading = /^(#{1,6})\s+(\S.*)$/.exec(trimmed);if (heading) { pushHeading(heading[1]!.length, heading[2]!); i += 1; continue; }if (trimmed.startsWith('>')) {const quoted: string[] = [];@@ -185,7 +185,7 @@ export type MarkdownInline =* Inline tokens. Code comes first (`` `**x**` `` is code, not emphasis). Italics take a single `*` only, never `_`,* which would split identifiers like `file_path`.*/-const INLINE_TOKEN = /`([^`]+)`|\*\*([^*]+)\*\*|\*([^*\s][^*]*)\*|\[([^\]\n]*)\]\(([^()\s]*)\)/g;+const INLINE_TOKEN = /`([^`]+)`|\*\*([^*]+)\*\*|\*([^*\s][^*]*)\*|\[([^[\]\n]*)\]\(([^()\s]*)\)/g;/** A line → inline pieces. Anything not recognized stays plain text, so half-written syntax spoils nothing. */export function parseInlineMarkdown(text: string): MarkdownInline[] {diff --git a/scripts/audit-public.mjs b/scripts/audit-public.mjsindex 030992d..84d3880 100644--- a/scripts/audit-public.mjs+++ b/scripts/audit-public.mjs@@ -105,7 +105,7 @@ function textOf(file) {/** The line without the contents of its string literals (a rough scan: quotes, template strings, regex classes). */function withoutStrings(line) {- return line.replace(/(["'`])(?:\\.|(?!\1).)*\1/g, '$1$1').replace(/\/\[(?:\\.|[^\]])*\]/g, '/[]');+ return line.replace(/(["'`])(?:\\.|(?!\1)[^\\])*\1/g, '$1$1').replace(/\/\[(?:\\.|[^\]\\])*\]/g, '/[]');}function isProse(text) {