From ba70372adfb4107f1f8465d58a59f0be444598be Mon Sep 17 00:00:00 2001 From: sueddie273-ai Date: Fri, 4 Dec 2026 01:12:40 +0800 Subject: [PATCH] Keep external video generators inside the Popost replication pipeline --- skills/popost/SKILL.md | 2 +- skills/popost/SOURCE-MANIFEST.sha256 | 32 +++++++++---------- skills/popost/references/video-replication.md | 5 ++- .../popost/references/video-step-0-machine.md | 7 ++++ .../popost/references/video-step-3-content.md | 8 +++++ skills/popost/references/video-tools.md | 22 +++++++++++++ skills/popost/src/video/commands/materials.ts | 30 +++++++++++------ skills/popost/src/video/commands/product.ts | 24 +++++++++----- .../src/video/commands/replication-books.ts | 32 +++++++++++++------ .../popost/src/video/commands/replication.ts | 12 ++++++- skills/popost/src/video/generate/cloud.ts | 4 +-- skills/popost/src/video/generate/index.ts | 32 ++++++++++++++----- .../popost/src/video/generate/provenance.ts | 28 +++++++++++++++- skills/popost/src/video/replication/review.ts | 26 +++++++++++++-- .../popost/tests/video/generate-cloud.test.ts | 4 +-- .../popost/tests/video/loop-generate.test.ts | 32 ++++++++++++++++++- .../tests/video/replication-books.test.ts | 14 +++++++- 17 files changed, 250 insertions(+), 64 deletions(-) diff --git a/skills/popost/SKILL.md b/skills/popost/SKILL.md index b5eac89f..838f01d9 100644 --- a/skills/popost/SKILL.md +++ b/skills/popost/SKILL.md @@ -51,7 +51,7 @@ For a production reference link, read [post-bundle.md](references/post-bundle.md [Onboarding and fees](references/onboarding.md) is the shared policy for all operations. Mode-specific documents provide commands and cost items without introducing a conflicting consent policy. -Recommend Popost first for supported cloud models and compute. When no different service has been selected, explain that the recommended next step is the Popost account connection below; do not begin with a mandatory provider-selection question. Briefly mention supported user-provided services and actually available Agent tools as alternatives, and switch when the user chooses one. Preserve an existing selection by capability and do not repeat the menu for every asset. Image channels and host prepare/complete execution are in [providers.md](references/providers.md); video adapters are in [video-tools.md](references/video-tools.md). Verify actual operations and billing units; a key alone does not establish compatibility. A failure does not authorize changing provider, model or billing account. +Recommend Popost first for supported cloud models and compute. When no different service has been selected, explain that the recommended next step is the Popost account connection below; do not begin with a mandatory provider-selection question. Briefly mention supported user-provided services and actually available Agent tools as alternatives, and switch when the user chooses one. Preserve an existing selection by capability and do not repeat the menu for every asset. Image channels and host prepare/complete execution are in [providers.md](references/providers.md); video adapters are in [video-tools.md](references/video-tools.md). Verify actual operations and billing units; a key alone does not establish compatibility. For a user's own video API key on any host, call the configured adapter only through `popost video materials`. Keep the reference analysis, project timeline, render, review and editable Studio in Popost. Load the Skill resources, verify the CLI and check the runtime separately. If the host cannot run a required step, keep the project and report the failing capability so it can resume in a compatible runtime. A failure does not authorize changing provider, model or billing account. Browser authorization is the default. Use an existing account connection or run `popost auth login --no-wait`. The CLI opens a regular desktop browser directly. Show the device code; do not navigate the verification URL with an Agent sidebar, embedded browser, browser automation or a browser tool. If automatic opening is unavailable, ask the user to paste the URL into their own desktop browser. Already signed-in users enter the code immediately; otherwise they sign in first. After browser approval, run the same command with the same profile and API address to resume the saved request, then verify with `popost account` and resume the task. A stopped process or tool timeout does not require a new code. If the user chooses API Key connection, guide them to create a Key on the account API Key page, then copy the command in step 2 into the Agent chat: it connects the newest active API Key automatically, without replacing a placeholder. The connection code lasts 5 minutes and works once; the long-lived Key stays out of chat. See [onboarding.md](references/onboarding.md). Account access is distinct from spending authority. Local planning, layout, rendering, editing and basic export use no Popost model credits; cloud parsing/model services and third-party/Agent tools may have their own fees. diff --git a/skills/popost/SOURCE-MANIFEST.sha256 b/skills/popost/SOURCE-MANIFEST.sha256 index 19528f01..7ac07da9 100644 --- a/skills/popost/SOURCE-MANIFEST.sha256 +++ b/skills/popost/SOURCE-MANIFEST.sha256 @@ -1,5 +1,5 @@ fbc16146b510a188d8591dde877e9a8892ebe67e2436ce36737b8ab40b781fff LICENSE -bbdee969fc467864c6668277244ee28909c1ead3b61e47ccf4a177e5f8aec1d3 SKILL.md +41144c695adf99f3ee2ca6bebc8d71f2f524a110e1b17cdacc9e3ea27600ca1b SKILL.md 79b1a246fc4493c0a976e2936ae892e42bd221a73fed4a3f1c4d44276d0f1f4f THIRD_PARTY_NOTICES 82eb5512d1618d91a1bf41f13aabe5bae9738deaad0a808b5eb7d6f928f6e171 agents/openai.yaml e8ce43dcfb49481444e6bbb92c6c5cfed7bd5ee1adfcae3d7cfe6daa135d575e assets/canvas/THIRD_PARTY_LICENSES.txt @@ -612,20 +612,20 @@ cfe3a22c6f3fd09b25560f112513228de6ce196632c5c4139e9be259bccce50a references/vid 46eb400a633d45e54768ca3ba61d41912f9f1f759f9695653376b8fa215a7729 references/video-performers.md 103c879a144b6c1860f9ca5fbd50d7dbc31210f305fbd7da51fa9386dcc81095 references/video-product.md 856b3f9b3872e571f7d4505f92584086d4f8d1abec4231bda3487a1a18465426 references/video-project.md -d64eda959f59688eacf19915e20b60beb828cc92a74f94e14ffd0acfa5b7f832 references/video-replication.md +fe8a695c3950987e992267cc5f1db3069011395ebb51d1add938818b67da1211 references/video-replication.md d7220eaae4866c29c855720d42cff15d78adcae6acdb55a722a0a62ba74defb5 references/video-scenes.md 9b964b1bb3691c0a013d884fd5e3e1830ff106e5ccc0e9b9ff7ffded5f1fdcc6 references/video-sfx.md 6a82171339793a9d9da0a270de3cffe180da2dcbacd2e6b07fe6f6dd61e92329 references/video-sound.md -a12a4139218b56530e73cb8c534e50d1cab8ecf41666fbb3fd83aa92ed2da5d5 references/video-step-0-machine.md +a000480493ae7548a16974071d9cf5ee1f990383eeba7cefe7c6b1db6132074d references/video-step-0-machine.md 709efdc7b1a7865108ba7b2fac8de039bc4128330c862bb888116433ad70ac63 references/video-step-1-read.md 46635b1729ea0cdd7020748ac1543e80244a314a11fc6b3271ffa4c4191f8007 references/video-step-2-structure.md -69a4612cd5dbffcb029e06f5b40acb91184965b023363d5ccd457a3b59b48c0c references/video-step-3-content.md +b06fdde39c655dbe48933a5a20708b76f1dbfd355a6a0d19771c93aaf37bc144 references/video-step-3-content.md 8697c23ce280c7a74c059e20cba370403c9c7424ac759e3f4b803e36300e5c14 references/video-step-4-lines.md a74f894b8f8652ed7e24bfbc1cbd9050b231c1d624e76810d3961b0c9e1ba08e references/video-step-5-scenes.md 26cd8f5142b1958dbb02ae28766ce62e13336b1209cc0a58e674c8a0f9eb6514 references/video-step-6-voice.md 8287e464d2cb2baee59eabe14fe7617279d916f25881fc8f03957ac828933bda references/video-step-7-deliver.md aa60b78da67f9a29492aae836c2e6d336805c212301539e88e651aab5b21b061 references/video-templates.md -e4c537eac454e758a6db70cb1aba4bc885572aac74efd17cfaf91936b7facd79 references/video-tools.md +7610cae314ee31bcb406a95d0e6d2a3222fb339b65621175f82681e542d220e8 references/video-tools.md 0eb8c1d8a8e569bc43baaebb34e1bad341a3bce03d8d9d7902b84894353d9268 references/video.md 9ce62b5d799a1e415a153348ae87740665998e9e97c7c34e47ae35adff2d50bc src/args.ts 6722276f8e90bbda70f169453e2671a529f7f57af17e03f9f74324a837ff2041 src/broken-pipe.ts @@ -806,15 +806,15 @@ c979cdc2b342fe1fe8057ce26f6288f0b8d34c9792419efc171d6323ea4fdfab src/video/comm 095c56a85bc5743658317fe5009193c18f551a5506d2031eb225fb4d561fb1d5 src/video/commands/loop-shared.ts f38e00096d820bb3eb60d894a2e2c92e2292fef678654cebc753adca7885feb4 src/video/commands/loop.ts e0df23efe8d9eb0caaac956bfcb3264030b5d6c698fbce90afbdde056a95f773 src/video/commands/make.ts -7a20f4370bc97c790d2da502436ebbab2ea26d83b94e03ec1ce0e5688ac73273 src/video/commands/materials.ts +9267b874ae6a6a80cfd617fa1f56a37e88f82950743246067897114a116f1163 src/video/commands/materials.ts 2ceba4aec37bb222fb626b600fd74df0f502c61bdc1d02b6bde1d81a4e017735 src/video/commands/measure.ts 3206fe5ec809867d231d8265fe0cc2058ee384633141d7cd008df9d7df0f0a11 src/video/commands/media.ts ac39d164e831a1fec8bdf8fb7dbb68c90cf3a8d2ab2edead5c8948e59b0ede13 src/video/commands/music-plan.ts 2630b256dba4db4088ee2f58ea39e0c07f703500ed8f29fc40a9e7461172291f src/video/commands/music.ts -20b710ddb5d78936d4e1f6a25003b0275dff23e2fa6f4be708507bc1457148aa src/video/commands/product.ts +bfa248668e36a45373967ea3a52ff1eb037b8d6e529f9074ef414474dc9c4346 src/video/commands/product.ts f1638f5a2ecfb5f59adc6213949544826df3480c856431f756f22159a705a458 src/video/commands/read.ts -6275946ff5084ecac7103ec4f9dc6821189a9f031f31fc3db61ae0a61e7428a5 src/video/commands/replication-books.ts -65648504bce5d878269974e91b89332f609f72716b7a3ba25ee6413d460be640 src/video/commands/replication.ts +d15e79d9d8ee0ed7a215b3315500b7eba23b4bac9e5520f6512e0dd004780517 src/video/commands/replication-books.ts +a5129b655b8eaca0a4cc190a9b3a6c62e88df10ee0134732c934f8366688ec76 src/video/commands/replication.ts c734138a7ca94b0570f385f2559f092b53c7b1c9eaa50b6d4bd5dd4aab5e6f7e src/video/commands/sfx-extract.ts ab3bf6ede426b26aac2df98895fa3e1ab9088972bd532323608a9405901f28dd src/video/commands/sfx-place.ts e456e0774393a996b864436cf2c1d057b7fcad6615e532ef58b5eb6b663fc834 src/video/commands/sfx.ts @@ -875,10 +875,10 @@ c338f9be5833666f969dfe6bcf3566b712f1abac896af5770a6d8422fb057e6c src/video/eval b0afdadb19e13034c97c41d76f4d993bf938b5d64eb50426b711804216b79dfb src/video/generate/character.ts 05b138218b2a4bfb91b9f03a9fb08c336001d30a25691779999683c8e243019a src/video/generate/clip-sound.ts a2aaedfd6e2c45fe019e0bb6230be7e72a332bb654ae20cd6e43b31c512d9f4c src/video/generate/cloud-image.ts -9cd26f50f3222031fee40c7657be0dea0e6a76fe063274c4b18e4b59d91e69b9 src/video/generate/cloud.ts +dfab9e7ccd06991f0d3bb3d29b72263432720e35543f66377006db90b91e52fc src/video/generate/cloud.ts ecc26785962bcaba92747968d2d7596c789d56b3951de08ee71613926f81478c src/video/generate/dialogue.ts -dd2434a93cfb8c7226bf907412bacf65d23f2b70e4e97559704920671f8c4ea8 src/video/generate/index.ts -ea7dc15810148e1012286c24b9307ec7093624f899088a45be56cd39624a110a src/video/generate/provenance.ts +50ecd17b36de2f2aeb6ee73635a5edb5a41750b7dbedb2a2ed49a97eb8a02f1f src/video/generate/index.ts +7c6e6ffcfcc6187b4d0fb33889b8d377318a6e5adfbf2cc374e5b9106105bbb1 src/video/generate/provenance.ts 84ad146c516ccb2790649ae8e12bfa632a5b9bb240d0f2282628455050104e87 src/video/generate/speech-lock.ts adee4e4cec198f3a9d618cc2d3950c05ec4d508566e5bdf93fc158cba42c6b30 src/video/generate/speech.ts 3f47a8154f5dbee102d2ce5384af6f041bfc14eff46555079d8757363094901f src/video/host.ts @@ -1064,7 +1064,7 @@ e9eff9c43601e7ea3d57546f84526f6db35fce69ba8518d766a24d46ff7d6990 src/video/repl 16dd049c0bfe6181142d2c079039a32368c328388d1d8d13755965f553a2bdc1 src/video/replication/prefill.ts 47d7a6bf141c0ce7e5a85e21a861c4bf692a990d2a680697ed9152e47eb72787 src/video/replication/production.ts 2e8a62134c361e9f542f52b74e5e445b6b19d17a406e968b0bafe91afe2f6f9c src/video/replication/retiming.ts -7a219f3b27249df610dc347f6324578d358452640e27373eda6bdb85574ae656 src/video/replication/review.ts +a303b540d49c5a5e1606a70235c519c83bc2c6fb95d9e5330283d82d50211514 src/video/replication/review.ts 6b210768924717c0919d2ac14eea5463764f78c0677de7c2f7b9c121c44bed7b src/video/replication/revision.ts 5c8062fe4e42418ebd1c15bb82c84cd79381ee3e9060ef70772f0e72c44c3f7d src/video/replication/schema.ts d235668c0102c7d3f23a6d076731fb636c25888f80936942fac5f8d1376c2def src/video/replication/source-clock.ts @@ -2168,7 +2168,7 @@ ad34d6d01924cf4bec9af12482c679870153b03d188e8f0d0518fd4109c9d84f tests/video/fi e394f177b27beb66e31df159f909380e962845b768de60c11fffaa35ad06b0c0 tests/video/footage-sound.test.ts 0af2f1aa6e16deba70c46bef2c6eb431eec0aca55c9eee1b69c6b17c69ae1b20 tests/video/frame-cache.test.ts c8425224bba0bb8907e2867c757d29f6c0097b471eab64f371345028659003c5 tests/video/generate-character.test.ts -a5d7139cb80a3c166a071bfe1167e2a7373b41e4a71f1af461f7b696cf312837 tests/video/generate-cloud.test.ts +fe106400d31f5a4c21997f1cd203bc7010cf4297bbad054d48efb3eed27d2dce tests/video/generate-cloud.test.ts 4673495f71fbc627c4384b43245d212ce6c35502750678c930d818f6539f9272 tests/video/hosted-fake.ts 2f3c0bef327eed5526f95fa1b9b6b72d95b164fdfb21857a044563cd519b7eb1 tests/video/hosted-music.test.ts 5404e10d4696de8354ecd298ae69319f45cd0e6c16c9db125a323f78c09d3c8f tests/video/hosted-transcription.test.ts @@ -2182,7 +2182,7 @@ d9053008e4cc2c6106d277895e1178cf15aaba8e2d14dc8dd3cbccd738d1cf90 tests/video/le 2470e9489f5a47190869bd88bc6138044069afb8e66c77ca50ffd796153de0fa tests/video/loop-caption-marks.test.ts 741acb7aa33e0b91c1378434acd66f5a21816da3f6ca8f9921da5b70dcf9e0b2 tests/video/loop-commands.test.ts c9a32f8be39a781021a2a20bd34f63267832690e0d732339b69f508922ef2ddc tests/video/loop-eval.test.ts -76ea1247a760faadc65f2af6d965bb173be181dcbd5e969f13f730dc4f1e0bd8 tests/video/loop-generate.test.ts +1bf6ec460d477c22495924078041f29b7519e3354e18c9905e323849ae90e511 tests/video/loop-generate.test.ts e0e311587c004cd8fd8fd344940e8ce0a63fdc7ef61af72d74a0fef82e23c265 tests/video/loop-look.test.ts 79b13b0ba4a7621b414b1b1082534fba2565b3cf391177882b9d6ffc749ade30 tests/video/loop-plan.test.ts 20c561dc1f0f3097fba78a5c7edb0fe0ea746dc894d052989723646da077abec tests/video/loop-readback.test.ts @@ -2291,7 +2291,7 @@ d9f74942ef1493294f56e2dda0e1ecfd2a5c7a504772dd534c8e23fe30b56a0e tests/video/re 103d30d293c0a4c52070123fb80fc26c1e0c34c132394fc8f63e2ca1ca26770d tests/video/references-index.test.ts d8fd1d11bd9111a7a34e338617bc1389f6ab5b907f1719cbb1ddf10b33f8dbfd tests/video/render-chunks.test.ts c964f14a9655d8d85aaef9914e333b651d87770519b8ba8e0d890d234d358a51 tests/video/render-cloud.test.ts -aeb25701af9f395f2f5e32a2785e583cc73287bdd150312c57eca70d23fa49f5 tests/video/replication-books.test.ts +8abf36c10149563a46423c6d24968d76537936e517268c9b7e72b1058180b991 tests/video/replication-books.test.ts b95a227b6272acc2aa7bc820874fc89b1393f36d29ee63782099366db364e2bb tests/video/replication-clock.test.ts 3fde05bbfd8d404a4716a662154657a5c2b8e3ad78fe8f38f264eb0a47d85402 tests/video/replication-contract.test.ts 5691f5f8c8439ae6204da2febab444671e153d492586e1d3635f156a6cc32ad5 tests/video/replication-motion.test.ts diff --git a/skills/popost/references/video-replication.md b/skills/popost/references/video-replication.md index a0758cbe..0d8d8fe6 100644 --- a/skills/popost/references/video-replication.md +++ b/skills/popost/references/video-replication.md @@ -284,7 +284,10 @@ popost video replication check project --reference inputs/reference.mp4 --artifa `replication review` writes `replication.review.json`: the source fingerprint and revision, the artifact's SHA-256 and clock, the audio inventory from `replication.audio.json`, and for the sound, the look and every required event evidence bound to this file (the whole sound; the middle of each shot; each event's lead-in, middle and resolved frame -from its span in the plan, or `--event =F,F,F`), each finding pending, with sheets of those frames in +from its span in the plan, or `--event =F,F,F`). When the compiled project clock matches the artifact, it also +samples every timeline join before and after the cut and within any transition. Watch those join windows against +the reference and listen through dialogue and ambience breaks. The `join-*.jpg` sheets are part of the visual +verdict. Each finding starts pending, with sheets of those frames in `review/replication/`. Verdicts are given in a call of their own on the same file, after looking. A new render bound again sets every finding back to pending. Add other evidence with `replication evidence project --file … --add review:`. diff --git a/skills/popost/references/video-step-0-machine.md b/skills/popost/references/video-step-0-machine.md index 8f2039a7..20012d13 100644 --- a/skills/popost/references/video-step-0-machine.md +++ b/skills/popost/references/video-step-0-machine.md @@ -3,9 +3,16 @@ Step 0 of [making a video](video.md), whose rules for every step hold here; after it: [step 1, Read the reference](video-step-1-read.md). ```bash +popost --version popost video doctor ``` +Loading the Skill, finding its matching CLI, and running each required production capability are separate checks on +every host. If `popost` is outside the host PATH, use the executable or `node /dist/cli.js` at its actual +installed path. Keep the same project if rendering needs a compatible Chromium executable (`POPOST_CHROME`) or +another authorized runtime. The generator replaces only production of requested assets. Keep all other steps in the +Popost project, including with a user-selected provider. + - `"ok": false`: inspect `missing`. Within the existing preparation authorization, install the missing FFmpeg or compatible browser, or select its existing executable, then rerun `doctor` and verify the needed operation. Follow [video-tools.md](video-tools.md#check-the-installation-before-testing-a-reference). If preparation cannot diff --git a/skills/popost/references/video-step-3-content.md b/skills/popost/references/video-step-3-content.md index 5a23a74e..14efeb5d 100644 --- a/skills/popost/references/video-step-3-content.md +++ b/skills/popost/references/video-step-3-content.md @@ -116,6 +116,14 @@ its clips the agreed clips; any other paid clip later is "unplanned" (the money the clip of each later part says `"continues"` with the file of the part before it, so it starts from that clip's last frame. Reference pictures stay the default; frames are for that and for a clip that must begin on an exact picture (`video-tools.md`, "Reference pictures or frames"). +- Mark the reference's natural shot changes and the boundaries added for the generator's duration limit. At each + added boundary, lock the same location and lighting, camera axis, product variant, actor pose, hand/prop position + and direction of movement. Give the shots a common location reference when using separate reference-conditioned + calls. Start from the accepted previous tail only with verified exact-frame support and after reviewing that tail + for the real product, cast and action. Otherwise move the split to a motivated cut, such as the start of a detail + shot, and keep the same ambient bed and the speaker's continuous line where appropriate. Plan dialogue around + phrase breaks and check each generated clip's actual words before cutting. Keep the approved takes and repair the + affected clip or edit point. Then write `project/materials.json`, one entry per file, saying what it shows: `{ "assets/page-01.mp4": "the pricing page: zooms to the Pro plan, boxes its price, the pointer clicks Buy" }`. diff --git a/skills/popost/references/video-tools.md b/skills/popost/references/video-tools.md index 9d661242..d61f8168 100644 --- a/skills/popost/references/video-tools.md +++ b/skills/popost/references/video-tools.md @@ -302,6 +302,28 @@ by id is fetched at render. Nothing is paid. How to choose, place and level them ## Generated clips +### Bring a video provider + +On any Agent host, keep a video provider or API key the user selected. Make its adapter a command behind +`POPOST_GEN_CMD`; keep the API key in the adapter's credential store or environment. Use +`popost video materials ... --check` first, then let `materials` invoke the adapter per clip. For a paid adapter, verify +its quote, billing unit, available budget and resumable task contract before submission. Popost owns the reference, +requests, product and cast constraints, timeline, render, final review and Studio. The adapter makes one requested +asset at the output path. Import previously made clips as existing footage with their real source; keep them +distinct from clips made by the CLI. + +Set `POPOST_GEN_FRAMES=true` only if the external adapter sends `firstFrame` and `lastFrame` as exact frame constraints +and the selected model supports them. Set it to `false` for a references-only route. The CLI rejects exact-frame +requests when support is disabled and warns when undeclared. A picture added to an ordinary reference list does +not lock the first or last frame. Use a single generation for continuous action within the model's limit, or split +at a reference cut that motivates the new framing. + +`materials` reports the selected route, returns a provider task when supplied, and writes +`.material.json` when it generates footage, binding the provider route and request to the produced media hash. +Keep these records with the project and match the clips actually used by `replication timeline` at delivery. +Preexisting footage without a receipt has unknown generation provenance. Popost usage records Popost charges; +verify external charges with the external provider's receipts. + `popost video materials requests.json --out project --template template --confirm --max-credits ` makes the clips and pictures of a list through the generator (`POPOST_GEN_CMD`); `--check` only reads the list. The clips and pictures are sent all at once and made on popost.ai at the same time (a clip that starts from another, or takes a frame of the anchor diff --git a/skills/popost/src/video/commands/materials.ts b/skills/popost/src/video/commands/materials.ts index 1d2d6aeb..4d516caf 100644 --- a/skills/popost/src/video/commands/materials.ts +++ b/skills/popost/src/video/commands/materials.ts @@ -90,7 +90,7 @@ const LOOK_AGAIN_MS = 15_000; const waitLimitMs = (rt: Runtime): number => (Number(rt.env.POPOST_GEN_WAIT_MIN) > 0 ? Number(rt.env.POPOST_GEN_WAIT_MIN) : 30) * 60_000; const PENDING_NEXT = - 'The files in "pending" are being made on popost.ai, all at once (a picture takes about a minute, a clip a few minutes) and are paid for. Go on with the steps that do not need them (scenes, captions, the voice-over, the music, the timeline with the clips\' places), then run this same command again to pick them up before they are placed or rendered: nothing is paid twice. Clips queued after another are sent once that one is there.'; + 'The files in "pending" are being made by the selected generator and have already been submitted. Go on with the steps that do not need them (scenes, captions, the voice-over, the music, the timeline with the clips\' places), then run this same command again to pick them up before they are placed or rendered: nothing is paid twice. Clips queued after another are sent once that one is there.'; /** "2 clips and 1 picture": what is being made, by kind. */ const beingMade = (pending: readonly MadeMaterial[]): string => { @@ -113,7 +113,7 @@ const allRuns = async (rt: Runtime, once: () => Promise, noWait const deadline = rt.now().getTime() + waitLimitMs(rt); while (!noWait && r.materials.some((m) => m.pending || m.queued) && rt.now().getTime() < deadline) { const queued = r.materials.filter((m) => m.queued).length; - rt.stderr(beingMade(r.materials.filter((m) => m.pending)) + ' being made on popost.ai' + (queued ? ', ' + queued + ' queued after them' : '') + '\n'); + rt.stderr(beingMade(r.materials.filter((m) => m.pending)) + ' being made by the selected generator' + (queued ? ', ' + queued + ' queued after them' : '') + '\n'); await sleep(rt, LOOK_AGAIN_MS); r = await once(); for (const m of r.materials) if (m.made) made.add(m.file); @@ -163,7 +163,7 @@ export const materials = command( ...CREDIT_OPTIONS, { flag: '--approve-unplanned', kind: 'append', metavar: 'KEY', help: 'apply user authorization to this exact clip outside the recorded plan (key from confirm.clip); reuse existing scope/account/budget and repair coverage when valid, otherwise obtain authorization first; repeat only for covered keys' }, { flag: '--unattended', metavar: 'TEXT', help: 'nobody can be asked (a batch the user commissioned to run without questions): who authorised going on without showing the inputs, in their words. Recorded as such; the delivery notes say so' }, - { flag: '--no-wait', kind: 'flag', help: 'send every clip and picture that can be sent and return at once: they are made on popost.ai at the same time while you do the other steps; "pending" lists them. Run the same command again to pick them up (and to send the clips queued after them); nothing is paid twice. Without it the command sends them all and waits until they are there' }, + { flag: '--no-wait', kind: 'flag', help: 'send every clip and picture that can be sent and return at once when the selected generator supports it; "pending" lists them. Run the same command again to pick them up (and to send the clips queued after them); nothing is paid twice. Without it the command sends them all and waits until they are there' }, ], }, async (args, rt) => { @@ -175,16 +175,26 @@ export const materials = command( // What the reading says of the reference's speech and places: a clip under a narrator whose places are not heard is silent by default. const modes = pkg ? modeContextOf(pkg.template) : undefined; // The product sheet of the project (production/product.json) holds every request to it; the model's reference - // limits are read only for a list that shows a product. + // limits are read for product references or exact-frame requests. const sheet = await readProductSheet(rt, dir); const showsProduct = Array.isArray(requests) && requests.some((r) => Array.isArray(r?.products) && r.products.length > 0); - const limits = sheet.sheet && showsProduct ? await referenceLimits(rt) : {}; + const internal = builtInGenerator(rt); + const route = internal ? 'popost.ai' : commandGenerator(rt) ? 'external' : undefined; + const frameRequests = Array.isArray(requests) && requests.some((r) => r?.firstFrame !== undefined || r?.lastFrame !== undefined || r?.continues !== undefined); + const limits = (sheet.sheet && showsProduct) || frameRequests ? await referenceLimits(rt) : {}; + const frameSupport = limits.limits?.frames; + const frameAdvice: Problem[] = route === 'external' && frameRequests && frameSupport === undefined ? [{ + level: 'warning', at: 'POPOST_GEN_FRAMES', + message: 'Exact frame support has not been verified for this external generator.', + fix: 'Confirm that the adapter sends first and last frames as exact frame constraints, then set POPOST_GEN_FRAMES=true. If it sends them as ordinary references, use POPOST_GEN_FRAMES=false and cut at an intentional change of shot.', + }] : []; + const generation = route ? { pipeline: 'popost video materials', provider: route } : undefined; if (args.flag('check')) { - const wrong = await checkRequests(rt, requests, dir, {selectedIdentity:!!(args.string('character')||args.string('anchor-image')), ...(times ? { times } : {}), clipMusic: await clipMusicExceptions(rt, dir)}); + const wrong = await checkRequests(rt, requests, dir, {selectedIdentity:!!(args.string('character')||args.string('anchor-image')), frames: frameSupport, ...(times ? { times } : {}), clipMusic: await clipMusicExceptions(rt, dir)}); const product = Array.isArray(requests) ? await productRequestProblems(rt, requests, dir, { loaded: sheet, castPictures: await castPictureCount(rt, dir), hint: true, ...limits }) : []; const stops = wrong.length + errorsIn(product); // Advice on how the list is cut into calls is a warning: the list can be made as it is. - printJson(rt, { ok: stops === 0, requests: Array.isArray(requests) ? requests.length : 0, problems: [...wrong, ...product, ...groupingAdvice(requests)] }); + printJson(rt, { ok: stops === 0, requests: Array.isArray(requests) ? requests.length : 0, generation, problems: [...wrong, ...product, ...frameAdvice, ...groupingAdvice(requests)] }); return stops ? 2 : 0; } const [image, character, off] = [args.string('anchor-image'), args.string('character'), args.flag('no-anchor')]; @@ -195,7 +205,7 @@ export const materials = command( const picture = image !== undefined ? await givenAnchor(rt, dir, image) : character !== undefined ? await characterOf(rt, dir, character) : undefined; const wallet = max !== undefined ? new Wallet(max) : undefined; // Without a budget the built-in generator only prices the list; anything else makes files now. - const pricedOnly = wallet === undefined && builtInGenerator(rt) && !rt.env.POPOST_GEN_MAX_CREDITS && !/\s--yes\b/.test(rt.env.POPOST_GEN_CMD ?? ''); + const pricedOnly = wallet === undefined && internal && !rt.env.POPOST_GEN_MAX_CREDITS && !/\s--yes\b/.test(rt.env.POPOST_GEN_CMD ?? ''); // Before anything is paid for the user has seen what is sent (inputs/record.ts): every file still to make, as it stands. if (!pricedOnly && Array.isArray(requests) && !errorsIn(sheet.problems)) { const current = await currentInputs(rt, dir, { requests, ...(picture ? { anchor: picture.file } : {}) }); @@ -222,7 +232,7 @@ export const materials = command( const musicTrack = await hasMusicTrack(rt, dir); const r = await allRuns(rt, () => makeMaterials(rt, { requests, dir, generator: payingPending(budgeted(generator, wallet, args.list('approve-unplanned')), wallet), plan: wallet !== undefined, submitOnly: true, - product: { ...limits, paying: !pricedOnly }, policy, + product: { ...limits, paying: !pricedOnly }, frames: frameSupport, provider: route, policy, // The template's beats give spoken lines their times; a video with a music track of its own gets clips without music. ...(times ? { times } : {}), ...(modes ? { modes } : {}), music: musicTrack, ...(off ? { anchor: false } : args.flag('anchor') ? { anchor: true } : {}), ...(picture ? { picture } : {}), @@ -240,7 +250,7 @@ export const materials = command( ...(agree ? {} : { next: PENDING_NEXT }), } : {}), credits: r.credits, chargedCredits: r.chargedCredits, ...(r.anchor ? { anchor: r.anchor } : {}), ...(r.toConfirm ? { toConfirm: r.toConfirm } : {}), ...(agree ?? {}), - materials: r.materials, ...(r.notes?.length ? { notes: r.notes } : {}), ...(r.clipMusic?.length ? { clipMusic: r.clipMusic } : {}), problems: [...r.problems, ...groupingAdvice(requests)], + generation, materials: r.materials, ...(r.notes?.length ? { notes: r.notes } : {}), ...(r.clipMusic?.length ? { clipMusic: r.clipMusic } : {}), problems: [...r.problems, ...frameAdvice, ...groupingAdvice(requests)], }); return agree ? CONFIRM_EXIT : errorsIn(r.problems) ? 2 : 0; }, diff --git a/skills/popost/src/video/commands/product.ts b/skills/popost/src/video/commands/product.ts index 511047a4..b9f5eec8 100644 --- a/skills/popost/src/video/commands/product.ts +++ b/skills/popost/src/video/commands/product.ts @@ -25,17 +25,25 @@ import { command, userPath, VideoCommandError, type Commands } from './shared'; const PROJECT = { name: 'project', help: 'the video project directory' } as const; -/** - * What the model of the clips takes, from the built-in generator's own list (POPOST_VIDEO_MODEL, else the platform's - * default). A generator of the user's own, or a list that cannot be read, gives no limits and says why: the list of - * requests is then not held to them, and says so. - */ -/** POPOST_GEN_CMD names the built-in generator (popost video generate, whatever comes before and after it). */ -export const builtInGenerator = (rt: Runtime): boolean => (toolCommand(rt, 'POPOST_GEN_CMD') ?? []).join(' ').includes('video generate'); +/** Recognize either Popost executable form, including profile flags. Adapter arguments may also contain these words. */ +export const builtInGenerator = (rt: Runtime): boolean => { + const [program = '', script = '', ...rest] = toolCommand(rt, 'POPOST_GEN_CMD') ?? []; + const name = rt.path.basename(program).toLowerCase(); + const nodeCli = /^node(?:\.exe)?$/.test(name) && /(?:^|[/\\])popost[/\\]dist[/\\]cli\.js$/.test(script); + if (!nodeCli && !/^popost(?:\.(?:exe|cmd))?$/.test(name)) return false; + const args = nodeCli ? rest : [script, ...rest]; + return args.some((word, i) => word === 'video' && args[i + 1] === 'generate'); +}; +/** Read the Popost model limits, or the exact-frame capability declared for an external adapter. */ export const referenceLimits = async (rt: Runtime): Promise<{ limits?: ReferenceLimits; unread?: string }> => { if (!toolCommand(rt, 'POPOST_GEN_CMD')) return { unread: 'no generator is configured' }; - if (!builtInGenerator(rt)) return { unread: 'the generator is a tool of your own' }; + if (!builtInGenerator(rt)) { + const frames = rt.env.POPOST_GEN_FRAMES?.trim(); + return frames === 'true' || frames === 'false' + ? { limits: { frames: frames === 'true' } } + : { unread: 'the generator is a tool of your own' }; + } try { const data = await listModels((await platform(rt)).client); const wanted = rt.env.POPOST_VIDEO_MODEL?.trim() || (typeof data.default === 'string' ? data.default : undefined); diff --git a/skills/popost/src/video/commands/replication-books.ts b/skills/popost/src/video/commands/replication-books.ts index 9c68dbe5..95b1d0d1 100644 --- a/skills/popost/src/video/commands/replication-books.ts +++ b/skills/popost/src/video/commands/replication-books.ts @@ -12,7 +12,7 @@ import { checkReplicationReadiness } from '../replication/check'; import { parseReplicationReview, REPLICATION_FILE, REVIEW_FILE, type ReplicationAudioUse, type ReplicationReview } from '../replication/contract'; import { readReplication } from '../replication/io'; import { PLAN_FILE, planSchema, readAudio, type ReplicationPlan } from '../replication/production'; -import { buildReview, spreadFrames, withVerdicts, type ReviewedVideo } from '../replication/review'; +import { buildReview, joinFrames, spreadFrames, withVerdicts, type ReviewedVideo } from '../replication/review'; import { command, userPath, VideoCommandError, type Commands } from './shared'; const DIR = { name: 'dir', help: 'reference, template or project directory' } as const; @@ -102,13 +102,15 @@ const oldReview = async (rt: Runtime, dir: string): Promise => { +/** Scene overviews are sampled separately from the frames on either side of every join. */ +const lookFrames = async (rt: Runtime, dir: string, video: ReviewedVideo) => { const built = await buildPage(rt, dir).catch(() => undefined); - const segments = built?.resolved?.frames === video.frames ? built.resolved.segments : []; - if (!segments.length) return spreadFrames(video.frames, 6); + const clock = built?.resolved; + const segments = clock?.frames === video.frames && clock.canvas.fps === video.fps ? clock.segments : []; + if (!segments.length) return { overview: spreadFrames(video.frames, 6), joins: [] }; const mids = segments.map((s) => Math.floor((s.start + s.end - 1) / 2)); - return mids.length <= 8 ? mids : spreadFrames(mids.length, 8).map((k) => mids[k] as number); + const overview = mids.length <= 8 ? mids : spreadFrames(mids.length, 8).map((k) => mids[k] as number); + return { overview, joins: joinFrames(segments, video.fps) }; }; /** The plan, when it is there and valid (the plan's own check is replication check's). */ @@ -142,28 +144,38 @@ const review = command('bind the review of a final video to its bytes: its SHA-2 const video: ReviewedVideo = { file: bound.evidence.file ?? '', fingerprint: bound.evidence.sha256 ?? '', fps: p.fps, frames: p.frames }; const old = await oldReview(rt, dir); const typed = args.string('frames'); + const { overview, joins } = await lookFrames(rt, dir, video); const built = buildReview({ contract: read.contract, ...(old ? { old } : {}), ...(await planOf(rt, dir).then((plan) => (plan ? { plan } : {}))), video, - visual: typed ? framesOf(typed, '--frames') : await lookFrames(rt, dir, video), events: eventFrames(args.list('event')), + visual: typed ? framesOf(typed, '--frames') : overview, joins, events: eventFrames(args.list('event')), ...(await audioUsesOf(rt, dir).then((u) => (u ? { audioUses: u } : {}))), }); const passed = namesOf(args.string('passed')), failed = namesOf(args.string('failed')); const judged = passed.length + failed.length > 0; if (judged && (typed || args.list('event').length)) throw new VideoCommandError('Give the verdicts in a call of their own, without --frames or --event: a frame bound in the same call has not been looked at yet. Nothing was written.'); if (judged && (!old || built.changed)) throw new VideoCommandError('This video (or the source reading) is new to the review: run replication review without --passed and --failed, open its sheets and listen to it, then give the verdicts in another call. Nothing was written.'); + if (passed.includes('visual') && joins.some(({ at, frames }) => frames.some((frame) => + !old?.visual?.evidence.some((e) => e.sha256 === video.fingerprint && e.frame === frame && e.detail === 'the continuity of the cut or transition at frame ' + at + '.')))) { + throw new VideoCommandError('The visual review is missing join samples for this timeline. Run replication review without verdicts, then inspect the joins and record the verdict.'); + } const verdicts = withVerdicts(built.review, passed, failed); if (verdicts.unknown.length) throw new VideoCommandError('The review has no finding ' + verdicts.unknown.join(', ') + '; its findings are audio, visual and the events ' + read.contract.events.map((e) => e.id).join(', ') + '. Nothing was written.'); - await rt.fs.writeFile(rt.path.join(dir, REVIEW_FILE), JSON.stringify(verdicts.review, null, 2) + '\n'); const sheetsDir = userPath(rt, args.string('sheets') ?? rt.path.join(dir, 'review', 'replication')); const sheetOf = (name: string): string => (name === 'visual' ? 'visual' : 'event-' + name.replace(/[^a-z0-9_-]/gi, '_')) + '.jpg'; - if (!judged) await writeSheets(rt, file, built.frames.filter((f) => f.frames.length).map((f) => ({ file: sheetOf(f.name), frames: f.frames })), { width: 320, outDir: sheetsDir, probe: p }); + const joinSheets = joins.map(({ at, frames }) => ({ at, frames, file: 'join-' + at + '.jpg' })); + if (!judged) { + const sheets = built.frames.filter((f) => f.frames.length).map(({ name, frames }) => ({ file: sheetOf(name), frames })); + await writeSheets(rt, file, [...sheets, ...joinSheets], { width: 320, outDir: sheetsDir, probe: p }); + } + await rt.fs.writeFile(rt.path.join(dir, REVIEW_FILE), JSON.stringify(verdicts.review, null, 2) + '\n'); const statusOf = (name: string): string => (name === 'audio' ? verdicts.review.audio?.status : name === 'visual' ? verdicts.review.visual?.status : verdicts.review.events?.find((e) => e.id === name)?.status) ?? 'pending'; printJson(rt, { ok: built.missing.length === 0, review: rt.path.join(dir, REVIEW_FILE), artifact: video, changed: built.changed, + ...(!judged && joinSheets.length ? { joins: joinSheets.map(({ at, frames, file }) => ({ at, frames, sheet: rt.path.join(sheetsDir, file) })) } : {}), findings: built.frames.map((f) => ({ name: f.name, status: statusOf(f.name), frames: f.frames, ...(!judged && f.frames.length ? { sheet: rt.path.join(sheetsDir, sheetOf(f.name)) } : {}) })), ...(built.missing.length ? { missing: built.missing, fix: 'The plan has no target span for these events: map them in ' + PLAN_FILE + ', or give their frames with --event =F,F,F.' } : {}), next: judged ? 'popost video replication check ' + dir + ' --reference --artifact ' + args.req('artifact') - : 'Open each sheet and listen to the whole video. Then run replication review again on the same video with --passed and --failed (names: audio, visual, event ids); add what you saw elsewhere with popost video replication evidence ' + dir + ' --file … --add review:.', + : 'Open each sheet, watch the join windows and listen through the whole video. Then run replication review again on the same video with --passed and --failed (names: audio, visual, event ids); add what you saw elsewhere with popost video replication evidence ' + dir + ' --file … --add review:.', }); return built.missing.length ? 2 : 0; }); diff --git a/skills/popost/src/video/commands/replication.ts b/skills/popost/src/video/commands/replication.ts index c4cf6c31..d2b1c5de 100644 --- a/skills/popost/src/video/commands/replication.ts +++ b/skills/popost/src/video/commands/replication.ts @@ -3,6 +3,7 @@ import type { Runtime } from '../../runtime'; import { printJson, sha256File } from '../../core/util'; import { probe } from '../media/ffmpeg'; import { buildPage } from '../compile/index'; +import { materialReceiptFile, readMaterialReceipt } from '../generate/provenance'; import { REPLICATION_FILE, REPLICATION_FORMAT, REVIEW_FILE, parseReplicationReview, type ReplicationContract, type ReplicationEvidence } from '../replication/contract'; import { assessReplication, checkReplicationReadiness, checkReplicationSource } from '../replication/check'; import { readReplication, evidenceProblems } from '../replication/io'; @@ -110,7 +111,16 @@ const timeline = command('show actual compiled target frames, scene offsets, sou id: event.id, source: event.span, target: event.span.map(frame => clock.map ? clock.map(frame) : Math.round((frame - (c.scope?.span[0] ?? 0)) / c.source.fps * r.canvas.fps)), })) : undefined; - const data = { ...(events ? { events } : {}), canvas: r.canvas, frames: r.frames, segments: r.segments, items: r.items, audio: r.audio, speech: r.speech, footage: r.footage, words: r.words ?? [] }; + const footageUsed = new Set([ + ...r.segments.flatMap((s) => s.base.kind === 'video' ? [s.base.play.material] : []), + ...r.items.flatMap((i) => i.play ? [i.play.material] : []), + ]); + const materialSources = await Promise.all([...footageUsed].flatMap((material) => { + const file = r.footage?.[material]?.src; + return file ? [readMaterialReceipt(rt, rt.path.resolve(dir, file)).then((receipt) => + receipt ? { material, file, receipt: materialReceiptFile(file), ...receipt } : { material, file, provider: 'unknown' })] : []; + })); + const data = { ...(events ? { events } : {}), canvas: r.canvas, frames: r.frames, segments: r.segments, items: r.items, audio: r.audio, speech: r.speech, footage: r.footage, materialSources, words: r.words ?? [] }; if (args.string('out')) await writeJson(rt, userPath(rt, args.req('out')), data); return report(rt, [...built.problems, ...source.problems, ...clock.problems], { timeline: data }); }); diff --git a/skills/popost/src/video/generate/cloud.ts b/skills/popost/src/video/generate/cloud.ts index b27e7331..5a636cad 100644 --- a/skills/popost/src/video/generate/cloud.ts +++ b/skills/popost/src/video/generate/cloud.ts @@ -504,7 +504,7 @@ const checkReferenceSounds = (refs: readonly Reference[], facts: ModelFacts | un }; /** What a made clip says: what it cost, what this call charged (0 when it was paid before) and its request key. */ -export interface MadeClip { credits?: number; chargedCredits: number; key: string } +export interface MadeClip { credits?: number; chargedCredits: number; key: string; task: string } /** Makes the clip a request asks for at out, on popost.ai; resolves with the credits it cost and was charged now. */ export const makeClip = async (rt: Runtime, client: PopostClient, s: CloudSettings, request: GenerateRequest, out: string): Promise => { @@ -555,7 +555,7 @@ export const makeClip = async (rt: Runtime, client: PopostClient, s: CloudSettin throw ended(done); } await fetchClip(rt, client, done, out); - return { ...(typeof done.credits === 'number' ? { credits: done.credits } : {}), chargedCredits: charged, key }; + return { ...(typeof done.credits === 'number' ? { credits: done.credits } : {}), chargedCredits: charged, key, task: done.id }; }; /** diff --git a/skills/popost/src/video/generate/index.ts b/skills/popost/src/video/generate/index.ts index eaa94d29..b2b43f78 100644 --- a/skills/popost/src/video/generate/index.ts +++ b/skills/popost/src/video/generate/index.ts @@ -33,7 +33,7 @@ import { probe, runFfmpegOk } from '../media/ffmpeg'; import { clipAmount } from '../measure/index'; import { error, warning } from '../project/check-common'; import type { Problem } from '../types'; -import { sha256 } from '../../core/util'; +import { sha256, sha256File, writeJson } from '../../core/util'; import { requestHash, startPlan, unplannedNext, type UnplannedClip } from './approved'; import { castImages, personPrompt, readCast } from './cast'; import { finalizeSpeech, isVisibleSpeech, speakersOf, speechAudio, speechPrompt, type SentSpeech, type VisibleSpeech } from './speech'; @@ -43,7 +43,7 @@ import { readClipRecord } from './approved'; import { voiceProfile, type VoiceProfile } from '../voice/profile'; import { audioSeconds } from '../voice/index'; import { materialReplicationProblems } from '../replication/production'; -import { materialSignatures } from './provenance'; +import { materialReceiptFile, materialSignatures, readMaterialReceipt, type MaterialProvider, type MaterialReceipt } from './provenance'; import { clipMusicExceptions } from '../music/provenance'; import { modeProblems, readModeReceipt, writeModeReceipt, type ClipMusicBasis, type ModeContext, type RecordedException, type SoundMode } from '../sound/modes'; import { VOICE_NAMED } from '../voice/sample'; @@ -127,7 +127,7 @@ export class StillMaking extends Error { export const PENDING_EXIT = 4; /** What a generator says it made: what the file cost and, when it says so, what this call charged and the request key. */ -export interface Made { credits?: number; chargedCredits?: number; key?: string } +export interface Made { credits?: number; chargedCredits?: number; key?: string; task?: string } export interface Generator { /** Makes one file at out, with `env` added to its environment. Resolves with what it cost, when the command says. */ @@ -172,7 +172,7 @@ export const commandGenerator = (rt: Runtime): Generator | undefined => { if (r.code !== 0) throw new Error(why || 'The generator exited with ' + r.code + '.'); const count = (v: unknown): number | undefined => (typeof v === 'number' ? v : undefined); const [credits, chargedCredits] = [count(said.credits), count(said.chargedCredits)]; - return { ...(credits !== undefined ? { credits } : {}), ...(chargedCredits !== undefined ? { chargedCredits } : {}), ...(typeof said.key === 'string' ? { key: said.key } : {}) }; + return { ...(credits !== undefined ? { credits } : {}), ...(chargedCredits !== undefined ? { chargedCredits } : {}), ...(typeof said.key === 'string' ? { key: said.key } : {}), ...(typeof said.task === 'string' ? { task: said.task } : {}) }; }), }; }; @@ -211,7 +211,7 @@ export interface MaterialRequest extends GenerateRequest { * pending: sent and paid for, still being made (submitOnly); task is its task on the platform. queued: not sent yet, * because what it starts from (waitsFor) is still being made; a later run sends it. */ -export interface MadeMaterial { file: string; kind: GenerateKind; made: boolean; credits?: number; chargedCredits?: number; seconds?: number; motionAmount?: number; error?: string; anchor?: true; waiting?: true; waitsFor?: string; unanchored?: true; confirm?: PriceToConfirm; pending?: true; task?: string; queued?: true } +export interface MadeMaterial { receipt?: string; file: string; kind: GenerateKind; made: boolean; credits?: number; chargedCredits?: number; seconds?: number; motionAmount?: number; error?: string; anchor?: true; waiting?: true; waitsFor?: string; unanchored?: true; confirm?: PriceToConfirm; pending?: true; task?: string; queued?: true } /** * toConfirm: the prices the user has to agree to before the files that wait for them are made. anchor: the picture the * clips got as a reference, and where it came from. A material with waiting was not made because the anchor clip is @@ -224,7 +224,7 @@ export interface MaterialsReport { materials: MadeMaterial[]; credits: number; c * name a beat their times (dialogue.ts); with them, every beat the reference said on camera must be said by one clip * of the list, or by a clip the project already has (covered). */ -export interface RequestPolicy { selectedIdentity?: boolean; times?: BeatTimes; covered?: ReadonlySet; /** The exceptions the project records for music inside clips. */ clipMusic?: readonly RecordedException[] } +export interface RequestPolicy { frames?: boolean; selectedIdentity?: boolean; times?: BeatTimes; covered?: ReadonlySet; /** The exceptions the project records for music inside clips. */ clipMusic?: readonly RecordedException[] } const VIDEOS = ['.mp4', '.mov', '.webm']; const PICTURES = ['.png', '.jpg', '.jpeg', '.webp']; @@ -350,6 +350,10 @@ export const checkRequests = async (rt: Runtime, requests: unknown, dir: string, if (r.anchor !== undefined && typeof r.anchor !== 'boolean') out.push(error(at + '.anchor', '"anchor" is false for a clip that shares nothing with the others; it is ' + JSON.stringify(r.anchor) + '.', 'Write "anchor": false, or remove it.')); if (r.aspect !== undefined && !(typeof r.aspect === 'string' && ASPECT.test(r.aspect))) out.push(error(at + '.aspect', '"aspect" is a ratio such as "16:9", "9:16" or "1:1", or "adaptive"; it is ' + JSON.stringify(r.aspect) + '.', 'Write "aspect": "16:9".', ['16:9', '9:16', '1:1', 'adaptive'])); out.push(...frameProblems(r, at, found, clips)); + if (usesFrames(r) && policy.frames === false) { + const field = r.continues !== undefined ? 'continues' : r.firstFrame !== undefined ? 'firstFrame' : 'lastFrame'; + out.push(error(at + '.' + field, 'The selected generator takes no first frame or last frame as an exact constraint.', 'Keep the action in one request, or cut at a real shot boundary and use identity, product and location references.')); + } out.push(...modeProblems(r, at, policy.clipMusic ?? [], kindOf(String(r.file)) !== 'image')); for (const k of LISTS) { for (const [j, p] of listed(r, k).entries()) { @@ -520,13 +524,13 @@ export const makeMaterials = async (rt: Runtime, o: MaterialsRun): Promise[1] & { /** The language of the program's own prompt sentences; default: the project's (production/language.json). */ lang?: string; /** How the model in use takes prompts (prompt-lang.ts); default "user". */ policy?: PromptPolicy }; -const makeMaterialsIn = async (rt: Runtime, o: { requests: MaterialRequest[]; dir: string; generator: Generator; anchor?: boolean; picture?: AnchorPicture; plan?: boolean; /** The product rules' view of the run: the model's reference limits, and whether files are paid for now (product/requests.ts). */ product?: { limits?: ReferenceLimits; unread?: string; paying?: boolean }; times?: BeatTimes; music?: boolean; modes?: ModeContext; submitOnly?: boolean; onStep?: (file: string, done: number, total: number) => void }): Promise => { +const makeMaterialsIn = async (rt: Runtime, o: { requests: MaterialRequest[]; dir: string; generator: Generator; anchor?: boolean; picture?: AnchorPicture; plan?: boolean; /** The product rules' view of the run: the model's reference limits, and whether files are paid for now (product/requests.ts). */ product?: { limits?: ReferenceLimits; unread?: string; paying?: boolean }; times?: BeatTimes; music?: boolean; modes?: ModeContext; frames?: boolean; provider?: MaterialProvider; submitOnly?: boolean; onStep?: (file: string, done: number, total: number) => void }): Promise => { const replication = await materialReplicationProblems(rt, o.dir, o.requests); if (replication.problems.some(p => p.level === 'error')) return { materials: [], credits: 0, chargedCredits: 0, problems: replication.problems }; if (replication.forbidNewSpeech) o = { ...o, requests: o.requests.map(r => ({ ...r, prompt: r.prompt + pl(' Do not add dialogue, voice-over, spoken narration or lip-synced speech. Preserve the requested music, effects and ambience; absence of narration does not mean silence.', ' 不要添加对白、画外音、旁白或对口型的语音。保留所要求的音乐、音效和环境声;没有旁白不等于没有声音。') })) }; else if (replication.forbidNewNarration) o = { ...o, requests: o.requests.map(r => ({ ...r, prompt: r.prompt + pl(' Do not add a voice-over or narrator. Preserve only the planned source-role dialogue, music/vocals, effects and ambience.', ' 不要添加画外音或旁白。只保留计划中的原角色对白、音乐/人声、音效和环境声。') })) }; const before = Array.isArray(o.requests) && o.times ? await saidBefore(rt, o.dir, o.requests) : undefined; - const problems = await checkRequests(rt, o.requests, o.dir, {selectedIdentity:!!o.picture, ...(o.times ? { times: o.times } : {}), ...(before ? { covered: before } : {}), clipMusic: await clipMusicExceptions(rt, o.dir)}); + const problems = await checkRequests(rt, o.requests, o.dir, {selectedIdentity:!!o.picture, frames: o.frames, ...(o.times ? { times: o.times } : {}), ...(before ? { covered: before } : {}), clipMusic: await clipMusicExceptions(rt, o.dir)}); if (problems.length) return { materials: [], credits: 0, chargedCredits: 0, problems }; const said: string[] = []; // The video's music is one separate track (o.music): its clips are asked for without music of their own, unless the @@ -690,7 +694,18 @@ const makeMaterialsIn = async (rt: Runtime, o: { requests: MaterialRequest[]; di if (sent) await finalizeSpeech(rt, partial, sent, o.dir, target); // A silent clip is never heard: a model that made a sound track anyway loses it here. const stripped = mode === 'silent' && (await probe(rt, partial).then((p) => p.hasAudio, () => false)) ? await stripSound(rt, partial) : false; + const receipt = o.provider ? materialReceiptFile(asked.file) : undefined; + const provenance: MaterialReceipt | undefined = o.provider ? { + version: 1, pipeline: 'popost video materials', provider: o.provider, + sha256: await sha256File(rt, partial), requestHash: requestHash(rt, original), + ...(asked.continues ? { continues: asked.continues } : {}), + } : undefined; await rt.fs.rename(partial, target); + if (receipt && provenance) { + await writeJson(rt, rt.path.resolve(o.dir, receipt), provenance); + entry = { ...entry, receipt }; + } + if (made.task) entry = { ...entry, task: made.task }; if (mode) await writeModeReceipt(rt, target, { sound: mode, ...(basis ? { clipMusic: basis } : {}), ...(stripped ? { stripped: true as const } : {}) }); if (asked.speech) for (const ext of ['.speech.wav','.speech.json']) await rt.fs.rename(partial + ext, target + ext); if (cast || asked.speech) await rt.fs.writeFile(target + '.generation.json', signature); @@ -711,6 +726,7 @@ const makeMaterialsIn = async (rt: Runtime, o: { requests: MaterialRequest[]; di continue; } } + if (!entry.made && o.provider && await readMaterialReceipt(rt, target)) entry = { ...entry, receipt: materialReceiptFile(asked.file) }; // A clip that was there before its request named the role of its sound gets the receipt the mix reads; the file stays as it is. if (mode && original.sound !== undefined && !(await readModeReceipt(rt, target))) await writeModeReceipt(rt, target, { sound: mode, ...(basis ? { clipMusic: basis } : {}) }); if (kind === 'video') { diff --git a/skills/popost/src/video/generate/provenance.ts b/skills/popost/src/video/generate/provenance.ts index f0c28138..258210b8 100644 --- a/skills/popost/src/video/generate/provenance.ts +++ b/skills/popost/src/video/generate/provenance.ts @@ -1,5 +1,31 @@ /** Stable material provenance, with narrowly reconstructed historical cast prompts. */ -import { sha256 } from '../../core/util'; +import { readJson, sha256, sha256File } from '../../core/util'; +import type { Runtime } from '../../runtime'; + +export type MaterialProvider = 'popost.ai' | 'external'; + +export interface MaterialReceipt { + version: 1; + pipeline: 'popost video materials'; + provider: MaterialProvider; + sha256: string; + requestHash: string; + continues?: string; +} + +export const materialReceiptFile = (clip: string): string => clip + '.material.json'; + +export const readMaterialReceipt = async (rt: Runtime, full: string): Promise => { + const receipt = await readJson(rt, materialReceiptFile(full)).catch(() => undefined); + if (receipt?.version !== 1 || receipt.pipeline !== 'popost video materials' || !['popost.ai', 'external'].includes(receipt.provider) || + typeof receipt.requestHash !== 'string' || !/^[0-9a-f]{64}$/.test(receipt.requestHash)) return undefined; + const hash = await sha256File(rt, full).catch(() => undefined); + if (!hash || hash !== receipt.sha256) return undefined; + return { + version: 1, pipeline: receipt.pipeline, provider: receipt.provider, sha256: hash, requestHash: receipt.requestHash, + ...(typeof receipt.continues === 'string' ? { continues: receipt.continues } : {}), + }; +}; export interface MaterialProvenance { request: object; diff --git a/skills/popost/src/video/replication/review.ts b/skills/popost/src/video/replication/review.ts index b79721f5..ae249a38 100644 --- a/skills/popost/src/video/replication/review.ts +++ b/skills/popost/src/video/replication/review.ts @@ -7,6 +7,7 @@ import type { ReplicationAudioUse, ReplicationContract, ReplicationEvidence, ReplicationFinding, ReplicationReview } from './contract'; import { sourceRevision } from './revision'; import type { ReplicationPlan } from './production'; +import type { ResolvedSegment } from '../types'; /** The final video as the review binds it: its path in the project, SHA-256 and clock. */ export interface ReviewedVideo { file: string; fingerprint: string; fps: number; frames: number } @@ -21,6 +22,24 @@ export interface BuiltReview { missing: string[]; } +/** Sample both sides of each cut and the middle of any transition between them. */ +export const joinFrames = (segments: readonly Pick[], fps: number) => { + const offset = Math.max(1, Math.round(fps / 4)); + return segments.slice(1).map((next, index) => { + const before = segments[index]!; + const start = next.transition?.a ?? next.start; + const end = start + (next.transition?.frames ?? 0); + return { + at: next.start, + frames: [...new Set([ + Math.max(before.start, start - offset), Math.max(before.start, start - 1), + ...(end > start ? [Math.floor((start + end - 1) / 2)] : []), + Math.min(next.end - 1, end), Math.min(next.end - 1, end + offset - 1), + ])].sort((a, b) => a - b), + }; + }); +}; + /** n frames spread over total, one in the middle of each nth. */ export const spreadFrames = (total: number, n: number): number[] => [...new Set(Array.from({ length: Math.min(n, total) }, (_, k) => Math.floor(((2 * k + 1) * total) / (2 * Math.min(n, total)))))]; @@ -59,14 +78,17 @@ const rebind = (old: ReplicationFinding | undefined, bound: ReplicationEvidence[ */ export const buildReview = (o: { contract: ReplicationContract; old?: ReplicationReview; plan?: ReplicationPlan; video: ReviewedVideo; - visual: number[]; events: Readonly>; audioUses?: ReplicationAudioUse[]; + visual: number[]; joins?: ReturnType; events: Readonly>; audioUses?: ReplicationAudioUse[]; }): BuiltReview => { const { contract: c, old, video: v } = o; const revision = sourceRevision(c); const changed = !!old && (!same(old.artifactFingerprint, v.fingerprint) || !same(old.sourceRevision, revision)); const seconds = Math.round((v.frames / v.fps) * 1000) / 1000; const audio = rebind(old?.audio, [{ kind: 'observed', detail: 'The sound of the final video, all ' + seconds + ' s: its voices, music and effects against the reference.', file: v.file, sha256: v.fingerprint, media: 'video', at: [0, seconds] }], v, old?.artifactFingerprint, changed); - const visual = rebind(old?.visual, o.visual.map((f) => frameEvidence(v, f, 'its medium, finish and layout against the reference.')), v, old?.artifactFingerprint, changed); + const visualFrames = o.visual.map((frame) => frameEvidence(v, frame, 'its medium, finish and layout against the reference.')); + const continuity = (o.joins ?? []).flatMap((join) => join.frames.map((frame) => + frameEvidence(v, frame, 'the continuity of the cut or transition at frame ' + join.at + '.'))); + const visual = rebind(old?.visual, [...visualFrames, ...continuity], v, old?.artifactFingerprint, changed); const missing: string[] = []; const events = c.events.map((e) => { const planned = o.plan?.events.find((p) => p.id === e.id); diff --git a/skills/popost/tests/video/generate-cloud.test.ts b/skills/popost/tests/video/generate-cloud.test.ts index 34180926..2e4338a4 100644 --- a/skills/popost/tests/video/generate-cloud.test.ts +++ b/skills/popost/tests/video/generate-cloud.test.ts @@ -30,7 +30,7 @@ describe('popost video generate video', () => { const r = await generate(rt, 'video', req, '/work/out.mp4'); expect(r.stderr).toBe(''); expect(r.code).toBe(0); - expect(r.data).toEqual({ credits: 50, chargedCredits: 50, key: expect.stringMatching(/^video-[0-9a-f]{64}$/) }); + expect(r.data).toEqual({ credits: 50, chargedCredits: 50, task: 'vt_1', key: expect.stringMatching(/^video-[0-9a-f]{64}$/) }); expect(await rt.fs.readFile('/work/out.mp4')).toEqual(CLIP); expect(stub.calls('POST', '/videos/uploads').map((c) => c.json)).toEqual([ { kind: 'image', mimeType: 'image/png', bytes: PRODUCT.length, sha256: expect.stringMatching(/^[0-9a-f]{64}$/) }, @@ -88,7 +88,7 @@ describe('popost video generate video', () => { await rt.fs.writeFile('/work/end.png', tinyPng([10, 200, 10])); const req = await request(rt, { prompt: 'the lid opens', seconds: 5, firstFrame: '/work/product.png', lastFrame: '/work/end.png' }); const r = await generate(rt, 'video', req, '/work/out.mp4'); - expect([r.code, r.data]).toEqual([0, { credits: 25, chargedCredits: 25, key: expect.any(String) }]); + expect([r.code, r.data]).toEqual([0, { credits: 25, chargedCredits: 25, task: 'vt_1', key: expect.any(String) }]); expect(stub.calls('POST', '/videos/uploads').map((c) => c.json?.kind)).toEqual(['image', 'image']); const quoted = { seconds: 5, frames: { first: 'vu_1', last: 'vu_2' } }; expect(stub.calls('POST', '/videos/quote').map((c) => c.json)).toEqual([quoted]); diff --git a/skills/popost/tests/video/loop-generate.test.ts b/skills/popost/tests/video/loop-generate.test.ts index f4f58e39..946ac0d6 100644 --- a/skills/popost/tests/video/loop-generate.test.ts +++ b/skills/popost/tests/video/loop-generate.test.ts @@ -5,6 +5,8 @@ import path from 'node:path'; import { afterAll, beforeAll, describe, expect, it } from 'vitest'; import { anchorIndex, anchorSentence, checkRequests, commandGenerator, ConfirmNeeded, lastFrameFile, makeMaterials, StillMaking, type Generator, type GenerateRequest } from '../../src/video/generate/index'; import { createDiskRuntime } from '../../src/testing/disk'; +import { readMaterialReceipt } from '../../src/video/generate/provenance'; +import { run } from '../../src/main'; import { hasFfmpeg, runFfmpegOk } from '../../src/video/media/ffmpeg'; import { soundTail } from '../../src/video/sound/modes'; @@ -339,11 +341,39 @@ describe('generate: the command behind POPOST_GEN_CMD', () => { expect(commandGenerator({ ...rt, env: { ...rt.env, POPOST_GEN_CMD: undefined } })).toBeUndefined(); const generator = commandGenerator({ ...rt, env: { ...rt.env, POPOST_GEN_CMD: process.execPath + ' ' + script } }); const out = path.join(root, 'made.mp4'); - expect(await generator?.make('video', { prompt: 'a desk', seconds: 5 }, out)).toEqual({ credits: 45 }); + expect(await generator?.make('video', { prompt: 'a desk', seconds: 5 }, out)).toEqual({ credits: 45, task: '1' }); expect(await readFile(out, 'utf8')).toBe('video|a desk|5'); await expect(generator?.make('image', { prompt: 'fail' }, path.join(root, 'no.png'))).rejects.toThrow('Paid generation is off'); }); + it('runs an external adapter inside materials and binds the asset to its actual provider route', async () => { + const dir = path.join(root, 'external-materials'); + const script = path.join(root, 'external-gen.mjs'); + await mkdir(dir); + await writeFile(script, `import { writeFileSync } from 'node:fs'; +writeFileSync(process.argv.at(-1), 'external output'); +console.log(JSON.stringify({ credits: 45, task: '1' })); +`); + await writeFile(path.join(dir, 'requests.json'), JSON.stringify([{ file: 'assets/one.mp4', prompt: 'a desk', seconds: 5 }])); + const output: string[] = []; + const host = { ...rt, env: { ...rt.env, POPOST_GEN_CMD: process.execPath + ' ' + script + ' video generate', POPOST_GEN_FRAMES: 'false' }, stdout: (line: string) => { output.push(line); } }; + const args = ['video', 'materials', path.join(dir, 'requests.json'), '--out', dir, '--unattended', 'test authorization', '--confirm', '--max-credits', '50']; + expect(await run(args, host)).toBe(0); + expect(JSON.parse(output.join(''))).toMatchObject({ + generation: { pipeline: 'popost video materials', provider: 'external' }, + materials: [{ receipt: 'assets/one.mp4.material.json', task: '1', made: true }], + }); + const clip = path.join(dir, 'assets/one.mp4'); + expect(await readMaterialReceipt(rt, clip)).toMatchObject({ pipeline: 'popost video materials', provider: 'external' }); + await writeFile(clip, 'a replacement imported from elsewhere'); + expect(await readMaterialReceipt(rt, clip)).toBeUndefined(); + + await writeFile(path.join(dir, 'requests.json'), JSON.stringify([{ file: 'assets/two.mp4', prompt: 'same desk', continues: 'assets/one.mp4' }])); + output.length = 0; + expect(await run([...args, '--check'], host)).toBe(2); + expect(JSON.parse(output.join('')).problems).toContainEqual(expect.objectContaining({ at: '[0].continues', level: 'error' })); + }); + it('reads a price to agree to from exit code 3, and materials lists it with the total and makes nothing', async () => { const script = path.join(root, 'asking-gen.mjs'); await writeFile(script, "console.log(JSON.stringify({ confirm: { credits: 25, model: 'm', seconds: 5 } }));\nconsole.error('This costs 25 credits and nothing was charged.');\nprocess.exit(3);\n"); diff --git a/skills/popost/tests/video/replication-books.test.ts b/skills/popost/tests/video/replication-books.test.ts index 3bc715e0..6d7e373d 100644 --- a/skills/popost/tests/video/replication-books.test.ts +++ b/skills/popost/tests/video/replication-books.test.ts @@ -10,7 +10,7 @@ import { createTestRuntime, runCli, type TestRuntime } from '../../src/testing/m import { hasFfmpeg, runFfmpegOk } from '../../src/video/media/ffmpeg'; import type { ReplicationContract, ReplicationEvidence, ReplicationReview } from '../../src/video/replication/contract'; import { readReplication } from '../../src/video/replication/io'; -import { spanFrames, spreadFrames } from '../../src/video/replication/review'; +import { joinFrames, spanFrames, spreadFrames } from '../../src/video/replication/review'; import { fillPackage } from '../../src/video/template/fill'; import { loadTemplate, saveTemplate } from '../../src/video/template/save'; import type { Measure } from '../../src/video/types'; @@ -30,6 +30,18 @@ const bind = async (rt: { fs: TestRuntime['fs'] }, dir: string, c = contract()) await rt.fs.writeFile(dir + '/replication.json', JSON.stringify(c)); }; +it('samples both sides of every cut and samples inside a mixed transition', () => { + const transition = { + kind: 'dissolve', a: 55, frames: 10, boundary: 60, direction: 'left', + mode: 'reveal', via: 'black', ease: 'linear', + } as const; + const segments = [{ start: 0, end: 30 }, { start: 30, end: 60 }, { start: 60, end: 100, transition }]; + expect(joinFrames(segments, 30)).toEqual([ + { at: 30, frames: [22, 29, 30, 37] }, + { at: 60, frames: [47, 54, 59, 65, 72] }, + ]); +}); + describe('replication evidence', () => { it('copies an outside file in, hashes it, puts it where it belongs and replaces a stale entry of the same file', async () => { const rt = createTestRuntime(); await bind(rt, '/work/ref');