From 99d29b4251c771de1b6b189d6408103a271e19e1 Mon Sep 17 00:00:00 2001 From: sueddie273-ai Date: Fri, 4 Dec 2026 08:52:12 +0800 Subject: [PATCH 1/4] Review generated video continuity at every edit boundary --- package-lock.json | 2 +- skills/popost/SKILL.md | 4 +- skills/popost/SOURCE-MANIFEST.sha256 | 35 ++++++------- skills/popost/package.json | 2 +- skills/popost/references/video-continuity.md | 40 +++++++++++++++ skills/popost/references/video-replication.md | 5 +- skills/popost/references/video-tools.md | 4 +- skills/popost/references/video.md | 1 + skills/popost/src/version.ts | 2 +- .../src/video/commands/replication-books.ts | 49 ++++++++++++------- .../popost/src/video/commands/replication.ts | 12 ++++- skills/popost/src/video/generate/index.ts | 23 +++++---- .../popost/src/video/generate/provenance.ts | 2 + skills/popost/src/video/inputs/collect.ts | 2 +- skills/popost/src/video/replication/books.ts | 8 ++- skills/popost/src/video/replication/check.ts | 9 ++++ .../popost/src/video/replication/contract.ts | 2 + skills/popost/src/video/replication/review.ts | 32 ++++++++++-- .../popost/tests/video/loop-generate.test.ts | 11 +++++ .../tests/video/replication-books.test.ts | 33 ++++++++++++- 20 files changed, 218 insertions(+), 60 deletions(-) create mode 100644 skills/popost/references/video-continuity.md diff --git a/package-lock.json b/package-lock.json index 7f39290..b981a0f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4872,7 +4872,7 @@ } }, "skills/popost": { - "version": "4.6.12", + "version": "4.6.13", "license": "SEE LICENSE IN LICENSE", "dependencies": { "fflate": "^0.8.3", diff --git a/skills/popost/SKILL.md b/skills/popost/SKILL.md index 838f01d..3a0f932 100644 --- a/skills/popost/SKILL.md +++ b/skills/popost/SKILL.md @@ -1,7 +1,7 @@ --- name: popost metadata: - version: "4.6.12" + version: "4.6.13" description: Reproduce reference videos with new content; create, reproduce and edit social image posts; save supported social links to My Inspirations. Use for video remakes, single-image posts, carousels, editable canvas/Studio projects and inspiration saving from TikTok, Instagram, X, Xiaohongshu, Douyin, YouTube, Threads, LinkedIn, Reddit, Bilibili, Lemon8, Kuaishou, WeChat or Weibo links, local media and written briefs. Retrieve only the source content supported by the selected link service. --- @@ -36,7 +36,7 @@ Prepare only what the next operation needs: an inspiration save needs no rendere ## Select the operation - **Save inspiration.** For a supported social link, use `inspiration quote`, then `inspiration add URL --confirm --max-credits N` within fee authorization. Return its saved ID/link and actual fee; resume an existing task with `inspiration status`. Supplied text, screenshots or a PostBundle use `inspiration import` after its dry run. Read [post-bundle.md](references/post-bundle.md). Do not start a production or download local media for a save-only request. -- **Reproduce a video.** Read [video.md](references/video.md): its rules, then the page of each step as you reach it (reference analysis, production, review). It links the required replication, people, motion and sound contracts when relevant. The image-post workflow does not apply. Use the reference plus the user's changes; they need not prescribe transitions, layouts or engineering details. +- **Reproduce a video.** Read [video.md](references/video.md): its rules, then the page of each step as you reach it (reference analysis, production, review). It links the required replication, people, motion and sound contracts when relevant. For multi-clip generated scenes, read [video-continuity.md](references/video-continuity.md) before generation and use its independent join review at delivery. The image-post workflow does not apply. Use the reference plus the user's changes; they need not prescribe transitions, layouts or engineering details. - **Edit a video.** Read [video-editing.md](references/video-editing.md). Reuse the existing project and accepted media, change only affected parts, and review the changed output. New paid media still follows the shared authorization. - **Reproduce an image post.** Read [image-workflow.md](references/image-workflow.md) and [reproduce.md](references/reproduce.md). Establish what stays and what changes from the target reference. - **Create an image post.** Read [image-workflow.md](references/image-workflow.md) and [create.md](references/create.md). Design from the brief or select a relevant bundled template. For template selection, read `/templates/community/README.md`, inspect 1–3 useful candidates in full, and choose one or none; `template search` is a shortcut, not a complete semantic search. Use an explicitly requested template directly. diff --git a/skills/popost/SOURCE-MANIFEST.sha256 b/skills/popost/SOURCE-MANIFEST.sha256 index ae17e6a..fa092e0 100644 --- a/skills/popost/SOURCE-MANIFEST.sha256 +++ b/skills/popost/SOURCE-MANIFEST.sha256 @@ -1,5 +1,5 @@ fbc16146b510a188d8591dde877e9a8892ebe67e2436ce36737b8ab40b781fff LICENSE -41144c695adf99f3ee2ca6bebc8d71f2f524a110e1b17cdacc9e3ea27600ca1b SKILL.md +c68cd94ecb7d45eaaf57371773fa296584520925c06ad2e6de406005ba3b11cb SKILL.md 79b1a246fc4493c0a976e2936ae892e42bd221a73fed4a3f1c4d44276d0f1f4f THIRD_PARTY_NOTICES 82eb5512d1618d91a1bf41f13aabe5bae9738deaad0a808b5eb7d6f928f6e171 agents/openai.yaml e8ce43dcfb49481444e6bbb92c6c5cfed7bd5ee1adfcae3d7cfe6daa135d575e assets/canvas/THIRD_PARTY_LICENSES.txt @@ -576,7 +576,7 @@ bce3debe65da546823ddeea754db40e2f3d7742478d334b305c173cff3249ae4 assets/video/s 8e82ff4d770bcebb67d465668ab9317e0bd9bae5caa8997ac0ea595027bf426f bundles/build-video.mjs add100275e15938519d8b2200572e8f72fbb66df9910f0c82e930db7713dd5e5 bundles/deck-entry.ts bb05a83f6f76ce79481e0d7b3a347c5661c0b41af9ebb995c9892ad4bb99e195 bundles/tsconfig.json -39c4e9d05d742209958558a40a38f3f0f3a44f660c61d189bc06f5171851dc57 package.json +05361733bcb147349fc80219e0c0aa7785c2b1cad7b52a026c1edb75786beb7c package.json c6310dd52f3fc3dc4064f5134573698ffb0d7f6c6d4bd6580c018adb40f99b87 references/asset-architecture.md 75c9ae67c4191ea153b56776aae996f22dee5da835eaac93be69149b8d593d96 references/create.md 9abcc16dc4730041c71a08007f3744fe89f0009893598d0b4fd42939b75c5483 references/design-system.md @@ -595,6 +595,7 @@ a7b4b60f6023ef5655b940908b5b4a66142fa693e4e157d5e95f1af40be43f6d references/qua 09034e4ce3fc69a74e9fc359c9313a092e6bb80a54c614692b4e079f41369933 references/reproduce.md 1da610778399a02f99ebf08baeae0f89403a0662cc75497283d62e9d4468f9f4 references/scene-templates.md ecb6086d2fea983ec2069112225e15912ddbc1ce884c8ff192161de3d7cedec6 references/social-series.md +6037df3b7dd708dae0f171d45a506ee2f8568eea9b9b2f3201e764995b0ac4bb references/video-continuity.md df294b82672863512bce216fd9814dc93766b8b9d958a1237ab5ae4a1203c32c references/video-draft-export.md 09a701a8b7592c48be2fa52001a14e5998d25f529c144412be86cf389c04740f references/video-editing.md b55fa68d80fbee8e5d477d0d52b6156f0506ed5934942c1ae9d09473601606f8 references/video-effects.md @@ -612,7 +613,7 @@ cfe3a22c6f3fd09b25560f112513228de6ce196632c5c4139e9be259bccce50a references/vid 46eb400a633d45e54768ca3ba61d41912f9f1f759f9695653376b8fa215a7729 references/video-performers.md 103c879a144b6c1860f9ca5fbd50d7dbc31210f305fbd7da51fa9386dcc81095 references/video-product.md 856b3f9b3872e571f7d4505f92584086d4f8d1abec4231bda3487a1a18465426 references/video-project.md -fe8a695c3950987e992267cc5f1db3069011395ebb51d1add938818b67da1211 references/video-replication.md +cd28a71177e2ce5ff52fcf6625ddda882f45ccae805e39fee62990c9a6bfd862 references/video-replication.md d7220eaae4866c29c855720d42cff15d78adcae6acdb55a722a0a62ba74defb5 references/video-scenes.md 9b964b1bb3691c0a013d884fd5e3e1830ff106e5ccc0e9b9ff7ffded5f1fdcc6 references/video-sfx.md 6a82171339793a9d9da0a270de3cffe180da2dcbacd2e6b07fe6f6dd61e92329 references/video-sound.md @@ -625,8 +626,8 @@ a74f894b8f8652ed7e24bfbc1cbd9050b231c1d624e76810d3961b0c9e1ba08e references/vid 26cd8f5142b1958dbb02ae28766ce62e13336b1209cc0a58e674c8a0f9eb6514 references/video-step-6-voice.md 8287e464d2cb2baee59eabe14fe7617279d916f25881fc8f03957ac828933bda references/video-step-7-deliver.md aa60b78da67f9a29492aae836c2e6d336805c212301539e88e651aab5b21b061 references/video-templates.md -a268291ec22299a2ef43cf752f7f92ce77f8cac364679ef0f46d2243e379feab references/video-tools.md -0eb8c1d8a8e569bc43baaebb34e1bad341a3bce03d8d9d7902b84894353d9268 references/video.md +2a2148bf7c20d6d4b6ebb36907368bf14a62cbe4798d061da1d1f357d773ab2b references/video-tools.md +1993e16d7fba0cf944e71b6e8a14068d066d9f3bcf7286b0c2b6b78adbf8882f references/video.md 9ce62b5d799a1e415a153348ae87740665998e9e97c7c34e47ae35adff2d50bc src/args.ts 6722276f8e90bbda70f169453e2671a529f7f57af17e03f9f74324a837ff2041 src/broken-pipe.ts 8c7adbc0a8e6a39aaa9eb624f9e145d98c062b95ea3022911f8f94fa94f11afe src/cli.ts @@ -784,7 +785,7 @@ d96c6f4f1506976346df992f26e3ffb2ccc6de31412f7c5ec57693e8d2ad7ab9 src/update/rep dc2da337b1005fee9f8dd7869ee6caba4e891b68f282c07af64d0ad5f71fa8d9 src/update/session.ts 00ebeaf3169473927dd4b2fd6bcf0fb6a5fb3a0102f211f10c57a8a1e3bbd363 src/update/state.ts 62dbd2d9e890bcbc3336cec661c830add57fd9c8100277c0784ec28ad881fe2d src/update/verify.ts -29ee14dfcec37e78ed3ce70d28320ab51e1dbad24a331cb2b80419babcc1be2d src/version.ts +290557248eff0ea435d2e614b618c45f6d6b9ac54c58cfb6b091f092ab88d82f src/version.ts 6180d119a25333c2e32a03c1c4d5aca390b2abe13824a1c7337062e44bfe9efd src/video/align/index.ts 9810398a64a74127471c0d2eea5b1969c3e20b78f570971d6a4e7a10a630f180 src/video/cache/frames.ts 9eb21a722635102adfe3341a1df74535e21ab73a6325ea37a26b1816346d8800 src/video/cache/holds.ts @@ -813,8 +814,8 @@ ac39d164e831a1fec8bdf8fb7dbb68c90cf3a8d2ab2edead5c8948e59b0ede13 src/video/comm 2630b256dba4db4088ee2f58ea39e0c07f703500ed8f29fc40a9e7461172291f src/video/commands/music.ts bfa248668e36a45373967ea3a52ff1eb037b8d6e529f9074ef414474dc9c4346 src/video/commands/product.ts f1638f5a2ecfb5f59adc6213949544826df3480c856431f756f22159a705a458 src/video/commands/read.ts -d15e79d9d8ee0ed7a215b3315500b7eba23b4bac9e5520f6512e0dd004780517 src/video/commands/replication-books.ts -a5129b655b8eaca0a4cc190a9b3a6c62e88df10ee0134732c934f8366688ec76 src/video/commands/replication.ts +4c8e748f7d32f3dc78cc1173eee7cd4a576dc2971c6eaafeb354f9be8685e42e src/video/commands/replication-books.ts +684afd1b89f4b2333be4df49c9170c164b89a16a2c409c94b544898b6f65685f 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 @@ -877,13 +878,13 @@ b0afdadb19e13034c97c41d76f4d993bf938b5d64eb50426b711804216b79dfb src/video/gene a2aaedfd6e2c45fe019e0bb6230be7e72a332bb654ae20cd6e43b31c512d9f4c src/video/generate/cloud-image.ts dfab9e7ccd06991f0d3bb3d29b72263432720e35543f66377006db90b91e52fc src/video/generate/cloud.ts eb65582f00c128699a130d4f3405f968715dcd4fa16bd1280443faee6a5eaede src/video/generate/dialogue.ts -50ecd17b36de2f2aeb6ee73635a5edb5a41750b7dbedb2a2ed49a97eb8a02f1f src/video/generate/index.ts -7c6e6ffcfcc6187b4d0fb33889b8d377318a6e5adfbf2cc374e5b9106105bbb1 src/video/generate/provenance.ts +cb55ca154a6334d6856113a4f75808aef2cf8ce961472e78c8138fcb93a5ac31 src/video/generate/index.ts +445426acd2c4d2627380ec4a1ffa2b6a1a2bf74e81ec0c646fc68c85e46a9c7c src/video/generate/provenance.ts 84ad146c516ccb2790649ae8e12bfa632a5b9bb240d0f2282628455050104e87 src/video/generate/speech-lock.ts adee4e4cec198f3a9d618cc2d3950c05ec4d508566e5bdf93fc158cba42c6b30 src/video/generate/speech.ts 3f47a8154f5dbee102d2ce5384af6f041bfc14eff46555079d8757363094901f src/video/host.ts 9a7aa437579f181f46621d7731574091417e5b6cfe0c2401520a468502082e02 src/video/hosted-api.ts -a83ea4d45210b7a0f77dac38b992cd059234828d4c6c3931a36b384ed8643544 src/video/inputs/collect.ts +ef862ee8fcbf83fe715cb6186eed7fc04f53f1a62e3e843e70533da7a3d6847b src/video/inputs/collect.ts ddafaa0358b1755684cc15f82ef9896baa9492591f3390b4c714b71f63357444 src/video/inputs/record.ts ff51f4f9099c3f0166bb5518dd9aabe4649971e56fd95e0d01fb28f60e73c8b1 src/video/inputs/sheet.ts 24afdfa0c89d97ec195f29ce45d7620fdefce4a320ee7436007bb5ba552b05c8 src/video/inputs/summary.ts @@ -1053,10 +1054,10 @@ f4673d5b4bb60d32ed18a4463b5e2cea6acdcaabbdf708e148c9d4c0a9f09dd8 src/video/rend e19e7ee383ed94df5f03191b6b424d2cc52463aa0598c8125a863261667deadb src/video/render/shots.ts d5a77ee8b513be5c44efc8991dd5ef7f99d38c76c53512f5ccbac27b3c86ed9c src/video/render/verify.ts b40733a72bc4f2576db66773db9d45d08668e1a32501d5eaba97a5ce2c1311a5 src/video/replication/audio-provenance.ts -c021c6831256f6a5701b6d9d1231b232afaa83e28a17f488b0445935f83d58e5 src/video/replication/books.ts +43d74f1e19258533593c7f9294d1a00d56a718d665c073d66ec8f268a0c2fb4b src/video/replication/books.ts 216f4007034c042d59775ab93f114991a83ee362fdedcbf93562d57917f11625 src/video/replication/browser.ts -a1bf2498b160470dcbc88ce4715cad2b01653bac00b645886727e84d96706634 src/video/replication/check.ts -24a6fc87121da441f73ed985d70ca2c378ee701ff70060fd5cc3c98cebdd24cc src/video/replication/contract.ts +f933b8ae59c2944d296ec09f4abea8331018fef676b5f11a6a38e83cb7161ed5 src/video/replication/check.ts +41dafd3c4da84ef6969b2b1a031b984685a6460cd0d36e5b876bba32e867b542 src/video/replication/contract.ts 99655fefe4dbad491873e4ef879fcc07f5443a3d138347764bf9029dc1ed0997 src/video/replication/io.ts 437bf379d94e3e5ef19044c13945a4eb8fb063b1618e400a90a20a9aa12d831c src/video/replication/motion-bundle.ts e9eff9c43601e7ea3d57546f84526f6db35fce69ba8518d766a24d46ff7d6990 src/video/replication/motion.ts @@ -1064,7 +1065,7 @@ e9eff9c43601e7ea3d57546f84526f6db35fce69ba8518d766a24d46ff7d6990 src/video/repl 16dd049c0bfe6181142d2c079039a32368c328388d1d8d13755965f553a2bdc1 src/video/replication/prefill.ts 47d7a6bf141c0ce7e5a85e21a861c4bf692a990d2a680697ed9152e47eb72787 src/video/replication/production.ts 2e8a62134c361e9f542f52b74e5e445b6b19d17a406e968b0bafe91afe2f6f9c src/video/replication/retiming.ts -a303b540d49c5a5e1606a70235c519c83bc2c6fb95d9e5330283d82d50211514 src/video/replication/review.ts +c1fe001ba0751e741ffed3b900ef0e5663a059e4212986ca18dbe98b6439433c src/video/replication/review.ts 6b210768924717c0919d2ac14eea5463764f78c0677de7c2f7b9c121c44bed7b src/video/replication/revision.ts 5c8062fe4e42418ebd1c15bb82c84cd79381ee3e9060ef70772f0e72c44c3f7d src/video/replication/schema.ts d235668c0102c7d3f23a6d076731fb636c25888f80936942fac5f8d1376c2def src/video/replication/source-clock.ts @@ -2182,7 +2183,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 -1bf6ec460d477c22495924078041f29b7519e3354e18c9905e323849ae90e511 tests/video/loop-generate.test.ts +738af5b629ebad0de7b63ee4dc862321cf6ea3aa7391675e0c44b9c3310ffd5b 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 +2292,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 -8abf36c10149563a46423c6d24968d76537936e517268c9b7e72b1058180b991 tests/video/replication-books.test.ts +ad98f3cc8aeb3bf64238ef0b3cd96c3ee160e660d24b8f3cb01ff58413448a7c 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/package.json b/skills/popost/package.json index e1f4f6c..b9aba23 100644 --- a/skills/popost/package.json +++ b/skills/popost/package.json @@ -1,6 +1,6 @@ { "name": "popost", - "version": "4.6.12", + "version": "4.6.13", "description": "popost Skill and CLI: reproduce videos, create and reproduce image posts, edit canvas and Studio projects, and save social inspiration links in coding agents such as Codex and Claude Code.", "license": "SEE LICENSE IN LICENSE", "author": "CLIPCAT AI LTD", diff --git a/skills/popost/references/video-continuity.md b/skills/popost/references/video-continuity.md new file mode 100644 index 0000000..ee6204d --- /dev/null +++ b/skills/popost/references/video-continuity.md @@ -0,0 +1,40 @@ +# Continuity across generated clips + +Read this before planning more than one generated clip in a shared scene, and again when repairing a visible seam. It applies to built-in models and user-provided API adapters on every Agent host. + +## Plan the handoff before generation + +Group continuous action into the fewest generations the selected model supports. Its maximum duration is a production limit. Select the editorial cut from the reference action and dialogue, reserving short handles within the requested duration for trimming. Do not add time or compress speech to fit a rigid split. + +For each join, keep the handoff in the project’s production notes with the preceding and following material, intended cut type (continuous shot, motivated shot change, or reference scene change), source cut-out and cut-in positions once known, speaker turn and sound continuity. Record the actor's position, gaze, hand pose and action phase, prop ownership, product details, framing, camera axis, motion direction and lighting. Inspect the actual previous clip before selecting these values. + +- Continuous shot. Use a verified video continuation capability when available. For a frame-constrained model, `continues` takes the previous generated clip as the source. Optional `continueAt` selects its reviewed source frame instead of its last frame. This uses the source clip's frame index, independently of the project FPS. Existing requests without it still continue from the last frame. Select a frame with the correct product and cast. Inspect several preceding frames to understand motion, then describe how that motion proceeds. A still alone cannot preserve velocity. +- Motivated shot change. Cut on an actual movement, glance, reveal or conversational turn. Match the action phase and screen direction, preserve camera axis and space, and select the new framing before generation. Use reference video or consecutive frames only when the selected provider supports them. Retain product and cast references within its limits. +- Reference scene change. Preserve the reference's motivated transition and the user's subject changes. Shared actors and products still retain their identity. + +A reference image constrains appearance. It does not enforce the first frame. Verify the selected API's actual frame/video/audio request fields and mode combinations. `POPOST_GEN_FRAMES=true` applies only to a verified exact-frame adapter. Frame mode currently excludes image, video and audio references. When the needed visual and voice constraints cannot coexist in that mode, use a supported multimodal route with an editorial action match, or report the capability gap. Do not silently discard voice references or change the provider/model. + +`continues` dependencies run sequentially and use actual predecessor bytes. Preserve receipts, request keys and accepted clips. Reconcile a pending submission before any replacement request. + +## Select the actual cut + +Inspect the preceding tail and following opening at normal speed, then frame by frame. Find a pair with compatible action and sound. Trim start-up pauses and repeated motion with source `in` positions and project spans. Preserve complete requested words and native lip sync. For off-camera dialogue, a J-cut or L-cut can bridge a motivated shot change when the timeline supports the required audio placement. Keep ambience continuous, and compare speaker timbre, pace, room sound and loudness. Crossfade ambience only where it helps; overlapping different spoken syllables is a failure. + +Small exposure or colour differences can be matched. A different pose, camera axis, location, product structure or repeated action needs a repaired generation or a different valid cut. Regenerate the affected material within repair authorization and retain the earlier accepted files. + +A static product photograph is permitted when the brief or reference calls for a product insert. It requires its own entry and exit review. Do not insert one as the default way to cover a failed generated join. A dissolve, zoom or optical interpolation also needs a motivated use and review for ghosts or invented product detail. + +## Review every actual boundary + +Run `replication review` on the rendered artifact. It samples segment joins and image/video layer entry and exit boundaries, writes their `join-.jpg` sheets and audible `join-.mp4` previews, and creates a separate pending `join-` finding for each. Review the whole render for internal generated-shot cuts, and register each internal cut with `--join ` before recording verdicts. A repeated `--join` accepts more boundaries. + +```bash +popost video replication review project --artifact project/renders/final.mp4 --join 243 +# Watch each audible join preview and the complete video, then record actual findings. +popost video replication review project --artifact project/renders/final.mp4 --passed join-243,join-450 +popost video replication check project --artifact project/renders/final.mp4 +``` + +At normal playback speed, check action progression, pose, gaze, camera direction, framing, spatial anchors, identity, garment structure, speech, lip sync and ambience. Different framing can be appropriate when the action motivates it. Similar-looking stills alone cannot establish continuity. Automated measurements identify candidates for inspection and never replace this verdict. + +A mismatched clock must produce an actionable failure. Equal frame counts and less than a quarter-frame accumulated timing drift allow frame-index mapping despite small container-rate differences. Larger drift requires a current render or an explicit retiming implementation. A general visual pass cannot pass an independent join. Changed artifact bytes reset verdicts. Missing, failed or pending joins remain visible in acceptance status. Deliver an unfinished version as a draft with its actual gaps when a capability or authorized budget prevents repair. diff --git a/skills/popost/references/video-replication.md b/skills/popost/references/video-replication.md index 0d8d8fe..b976c1e 100644 --- a/skills/popost/references/video-replication.md +++ b/skills/popost/references/video-replication.md @@ -284,10 +284,9 @@ 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`). 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 +from its span in the plan, or `--event =F,F,F`). For an editable project, it maps the compiled frame clock to the artifact and fails explicitly when the mapping is unsafe. It samples every timeline join and image/video layer entry and exit before and after the cut and within any transition. Each has an independent `join-` finding and an audible MP4 preview. Register internal generated-shot cuts with `--join `. 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 +verdict. Independently watch and judge each join using [video-continuity.md](video-continuity.md); a general visual verdict cannot pass it. 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-tools.md b/skills/popost/references/video-tools.md index a792dfd..2a66159 100644 --- a/skills/popost/references/video-tools.md +++ b/skills/popost/references/video-tools.md @@ -424,6 +424,8 @@ picture does not change the price. | `--no-anchor` | no anchor at all: unrelated clips, or a generator that takes no reference pictures | | `--anchor` | the anchor also for a list of one clip, so that a later list finds `anchor.jpg` | +For shared-scene clips, follow [video-continuity.md](video-continuity.md) before selecting calls and references. + **How many calls.** A call's sound is continuous only inside it: shots generated one by one each bring a sound of their own, and the film sounds cut up. So group by the continuity of the scene, not by shot: @@ -456,7 +458,7 @@ one piece under those shots instead of being cut and re-timed with each (`video- - Frames: `"firstFrame"` is the exact picture the clip starts from, `"lastFrame"` (only with it) the one it ends on. Use them for an exact composition (the clip must begin on this still: the user's product picture or a still composed from it, the last picture of the scene before it), and for a shot longer than one clip: `"continues": "assets/part-1.mp4"` makes a clip start from - the last frame of that clip (of the list, or already in the project), made after it. `template save --max-shot + the last frame of that clip (of the list, or already in the project), made after it. Optional `"continueAt": 347` selects a reviewed source frame instead. Select it after inspecting the actual clip and its surrounding motion. `template save --max-shot ` cuts such a shot into parts, and each later part takes the clip that continues the part before it. A clip with frames takes no `"images"`, `"videos"` or `"audios"` and no anchor: what it shows is in its first frame. diff --git a/skills/popost/references/video.md b/skills/popost/references/video.md index a3e360f..44e0f91 100644 --- a/skills/popost/references/video.md +++ b/skills/popost/references/video.md @@ -23,6 +23,7 @@ keep their previous behavior; an approved repair uses a separate project and doe [video-sound.md](video-sound.md); before placing effects, read [video-sfx.md](video-sfx.md). These production checks remain required when onboarding or authorization has already been completed. +- Before planning multiple generated clips of one scene, read [video-continuity.md](video-continuity.md). Plan action and audio handoffs before generation and inspect every actual cut after rendering. - Inputs first: before the first paid generation of a video, show the user everything that was prepared as the input of a model and wait for their yes. `popost video inputs show project --requests requests.json --lang ` builds it without paying: the input sheet (one picture: the product picture exactly diff --git a/skills/popost/src/version.ts b/skills/popost/src/version.ts index ebd3d36..1c7f5a3 100644 --- a/skills/popost/src/version.ts +++ b/skills/popost/src/version.ts @@ -1,2 +1,2 @@ /** The CLI version; equals `metadata.version` in SKILL.md and is sent to popost.ai as `x-popost-client-version`. */ -export const VERSION = '4.6.12'; +export const VERSION = '4.6.13'; diff --git a/skills/popost/src/video/commands/replication-books.ts b/skills/popost/src/video/commands/replication-books.ts index 95b1d0d..27a3f86 100644 --- a/skills/popost/src/video/commands/replication-books.ts +++ b/skills/popost/src/video/commands/replication-books.ts @@ -6,13 +6,13 @@ import { printJson } from '../../core/util'; import type { Runtime } from '../../runtime'; import { buildPage } from '../compile/index'; import { writeSheets } from '../look/sheets'; -import { probe } from '../media/ffmpeg'; +import { probe, runFfmpegOk } from '../media/ffmpeg'; import { addEvidence, bindEventSpans, bindEvidence, boundReference, BooksError, fileOfPlace, PLACES } from '../replication/books'; 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, joinFrames, spreadFrames, withVerdicts, type ReviewedVideo } from '../replication/review'; +import { buildReview, matchingReviewClock, timelineJoins, 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; @@ -103,14 +103,16 @@ const oldReview = async (rt: Runtime, dir: string): Promise { - const built = await buildPage(rt, dir).catch(() => undefined); - 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)); - const overview = mids.length <= 8 ? mids : spreadFrames(mids.length, 8).map((k) => mids[k] as number); - return { overview, joins: joinFrames(segments, video.fps) }; +const lookFrames = async (rt: Runtime, dir: string, video: ReviewedVideo, extra: number[]) => { + if (!(await rt.fs.stat(rt.path.join(dir, 'video.json')))) return { overview: spreadFrames(video.frames, 6), joins: undefined }; + const built = await buildPage(rt, dir); + const clock = built.resolved; + if (!clock || !matchingReviewClock({ frames: clock.frames, fps: clock.canvas.fps }, video)) + throw new VideoCommandError('The project and artifact clocks cannot be mapped safely. Render the current project before reviewing its cuts; no continuity checks were skipped.'); + if (extra.some(frame => frame <= 0 || frame >= video.frames)) throw new VideoCommandError('--join must lie strictly inside the final artifact.'); + const mids = clock.segments.map(s => Math.floor((s.start + s.end - 1) / 2)); + const overview = mids.length <= 8 ? mids : spreadFrames(mids.length, 8).map(k => mids[k] as number); + return { overview, joins: timelineJoins(clock, extra) }; }; /** The plan, when it is there and valid (the plan's own check is replication check's). */ @@ -130,6 +132,7 @@ const review = command('bind the review of a final video to its bytes: its SHA-2 { flag: '--artifact', required: true, help: 'the final rendered MP4' }, { flag: '--frames', help: 'frames of the video for the look (default: the middle of each shot, at most 8)' }, { flag: '--event', kind: 'append', metavar: 'ID=F,F', help: 'frames for one event, when the plan has no span for it or others are wanted, for example --event hook=12,30,48' }, + { flag: '--join', kind: 'append', help: 'an internal generated-shot cut at an output frame; joins and visual-layer boundaries are included automatically' }, { flag: '--passed', help: 'the findings you looked at (listened to) that hold: audio, visual and event ids, separated by commas' }, { flag: '--failed', help: 'the findings that do not hold, the same way' }, { flag: '--sheets', help: 'where the sheets of the frames go (default /review/replication)' }, @@ -144,38 +147,48 @@ 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 { overview, joins } = await lookFrames(rt, dir, video, [...(old?.artifactFingerprint === video.fingerprint ? old.joins ?? [] : []).map(join => join.at), ...args.list('join').flatMap(value => framesOf(value, '--join'))]); const built = buildReview({ contract: read.contract, ...(old ? { old } : {}), ...(await planOf(rt, dir).then((plan) => (plan ? { plan } : {}))), video, - visual: typed ? framesOf(typed, '--frames') : overview, joins, events: eventFrames(args.list('event')), + visual: typed ? framesOf(typed, '--frames') : overview, ...(joins ? { 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 && (typed || args.list('event').length || args.list('join').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) => + 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.'); } + for (const name of [...passed, ...failed].filter(name => name.startsWith('join-'))) { + if (!old?.joins?.some(join => 'join-' + join.at === name)) + throw new VideoCommandError('This cut is new to the review. Generate and watch its join preview before recording a 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.'); 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'; - const joinSheets = joins.map(({ at, frames }) => ({ at, frames, file: 'join-' + at + '.jpg' })); + 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 }); + for (const join of joinSheets) { + const start = Math.max(0, join.at / video.fps - 1.25); + const end = Math.min(video.frames / video.fps, join.at / video.fps + 1.25); + await runFfmpegOk(rt, ['-y', '-ss', String(start), '-i', file, '-t', String(end - start), '-map', '0:v:0', '-map', '0:a?', + '-c:v', 'libx264', '-preset', 'veryfast', '-crf', '20', '-c:a', 'aac', '-movflags', '+faststart', rt.path.join(sheetsDir, 'join-' + join.at + '.mp4')]); + } } 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'; + const statusOf = (name: string): string => (name === 'audio' ? verdicts.review.audio?.status : name === 'visual' ? verdicts.review.visual?.status : name.startsWith('join-') ? verdicts.review.joins?.find(join => 'join-' + join.at === name)?.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) })) } : {}), + ...(!judged && joinSheets.length ? { joins: joinSheets.map(({ at, frames, file }) => ({ at, frames, sheet: rt.path.join(sheetsDir, file), preview: rt.path.join(sheetsDir, 'join-' + at + '.mp4') })) } : {}), 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, 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:.', + : '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, join-, 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 d2b1c5d..217c515 100644 --- a/skills/popost/src/video/commands/replication.ts +++ b/skills/popost/src/video/commands/replication.ts @@ -11,6 +11,7 @@ import { artifactFacts, outputAudioProblems, outputPlanProblems } from '../repli import { checkPairs, PAIRS_FILE, type PairUse } from '../replication/pairs'; import { MOTION_BUNDLE } from '../replication/motion-bundle'; import { preserveReferenceSound } from '../replication/audio-provenance'; +import { matchingReviewClock, timelineJoins } from '../replication/review'; import { sourceRevision } from '../replication/revision'; import { eventClock } from '../replication/retiming'; import { observeNativeSpeech } from '../replication/speech-observed'; @@ -153,7 +154,7 @@ const pairUses = (r: Resolved, pairs: Awaited>['pa const boundFindings = (c: ReplicationContract, review: NonNullable['review']>, actual: { fingerprint: string; fps: number; frames: number }): Problem[] => { const fingerprint = actual.fingerprint; const problems: Problem[] = []; - for (const [name, finding] of [['audio', review.audio], ['visual', review.visual], ...(review.events ?? []).map(e => [e.id, e] as const)] as const) { + for (const [name, finding] of [['audio', review.audio], ['visual', review.visual], ...(review.events ?? []).map(e => [e.id, e] as const), ...(review.joins ?? []).map(join => ['join-' + join.at, join] as const)] as const) { if (finding?.status !== 'passed') continue; for (const e of finding.evidence.filter(e => e.sha256 === fingerprint)) { if (e.frame !== undefined && (e.frame < 0 || e.frame >= actual.frames) || e.at && (e.at[0] < 0 || e.at[1] > actual.frames / actual.fps)) @@ -208,6 +209,15 @@ const check = command('check source readiness, or an exact final artifact and it const parsed = parseReplicationReview(input); problems.push(...parsed.problems, ...await evidenceProblems(rt, dir, parsed.review)); if (parsed.review) problems.push(...boundFindings(c, parsed.review, actual)); + if (built.resolved) { + const clock = built.resolved; + if (!matchingReviewClock({ frames: clock.frames, fps: clock.canvas.fps }, actual)) + problems.push(error('replication.review.joins', 'The project and final artifact clocks cannot be mapped safely.', 'Render and review the current project.')); + for (const join of timelineJoins(clock)) { + if (!parsed.review?.joins?.some(item => item.at === join.at)) + problems.push(error('replication.review.joins.' + join.at, 'This timeline or visual-layer cut has no independent continuity review.', 'Run replication review on the actual final artifact, watch its join preview and record join-' + join.at + '.')); + } + } const assessment = assessReplication(c, input, actual); problems.push(...assessment.problems); const failed = problems.some(p => p.level === 'error'), accepted = !failed && assessment.requirementsMet === true; const result = { ...assessment, requirementsMet: failed ? false : assessment.requirementsMet, qualityStatus: accepted ? 'accepted' : failed ? 'needs_iteration' : assessment.qualityStatus, artifact: actual, problems }; diff --git a/skills/popost/src/video/generate/index.ts b/skills/popost/src/video/generate/index.ts index b2b43f7..79c1d04 100644 --- a/skills/popost/src/video/generate/index.ts +++ b/skills/popost/src/video/generate/index.ts @@ -204,6 +204,8 @@ export interface MaterialRequest extends GenerateRequest { anchor?: boolean; /** The file of another clip (of this list, or of the project): this clip starts from its last frame, as its firstFrame. */ continues?: string; + /** A reviewed source frame to continue from; omitted means the last frame. */ + continueAt?: number; } /** motionAmount: how much a clip's picture moves (measure/amount.ts), to hold against the reference shot it is for. */ @@ -253,6 +255,8 @@ const FRAME_FIX = 'Use frames for a shot that goes on from another clip or needs /** What is wrong with the frames of a request: firstFrame, lastFrame and continues. found: the files that exist; clips: the list's clips by file. */ const frameProblems = (r: Partial, at: string, found: ReadonlySet, clips: ReadonlyMap>): Problem[] => { + if (r.continueAt !== undefined && (!r.continues || !Number.isInteger(r.continueAt) || r.continueAt < 0)) + return [error(at + '.continueAt', '"continueAt" needs "continues" and a nonnegative source frame index.', 'Select the actual cut-out frame of the preceding clip.')]; if (!usesFrames(r)) return []; const out: Problem[] = []; const key = r.continues !== undefined ? 'continues' : r.firstFrame !== undefined ? 'firstFrame' : 'lastFrame'; @@ -476,13 +480,14 @@ const inOrder = (requests: MaterialRequest[], first: number): MaterialRequest[] export const lastFrameFile = (clip: string): string => clip.slice(0, clip.length - extOf(clip).length) + '.last.png'; /** The last frame of a clip of the project as a picture beside it, taken again when the clip is newer than the picture. */ -const lastFrameOf = async (rt: Runtime, dir: string, clip: string): Promise => { - const from = rt.path.resolve(dir, clip), to = rt.path.resolve(dir, lastFrameFile(clip)); - const [a, b] = [await rt.fs.stat(from), await rt.fs.stat(to)]; - if (!b || (a && a.mtimeMs > b.mtimeMs)) { - const p = await probe(rt, from); - await extractFrame(rt, from, Math.max(0, p.frames - 1), to); - } +const lastFrameOf = async (rt: Runtime, dir: string, clip: string, frame?: number): Promise => { + const from = rt.path.resolve(dir, clip); + const to = rt.path.resolve(dir, frame === undefined ? lastFrameFile(clip) : lastFrameFile(clip).replace('.last.png', '.frame-' + frame + '.png')); + const p = await probe(rt, from); + const index = frame ?? Math.max(0, p.frames - 1); + if (index >= p.frames) throw new Error('continueAt ' + index + ' lies outside ' + clip + ' (' + p.frames + ' frames). Nothing was sent.'); + // Re-extract the selected frame so replacing source bytes cannot reuse a stale anchor with an unchanged timestamp. + await extractFrame(rt, from, index, to); return to; }; @@ -679,7 +684,7 @@ const makeMaterialsIn = async (rt: Runtime, o: { requests: MaterialRequest[]; di const r = gets && picture && source ? anchored(asked, picture, source, o.picture?.person, shown !== undefined) : asked; const at = (p: string): string => rt.path.resolve(o.dir, p); const references = Object.fromEntries(LISTS.flatMap((k) => (r[k]?.length ? [[k, (r[k] ?? []).map(at)]] : []))); - const start = priceOnly ? undefined : asked.continues ? await lastFrameOf(rt, o.dir, asked.continues) : asked.firstFrame ? at(asked.firstFrame) : undefined; + const start = priceOnly ? undefined : asked.continues ? await lastFrameOf(rt, o.dir, asked.continues, asked.continueAt) : asked.firstFrame ? at(asked.firstFrame) : undefined; const frames = { ...(start ? { firstFrame: start } : {}), ...(start && asked.lastFrame ? { lastFrame: at(asked.lastFrame) } : {}) }; const tail = mode ? sound.tailOf(original, mode) : separateMusic && kind === 'video' ? noMusic() : ''; const request: GenerateRequest = { prompt: r.prompt + (sent ? speechPrompt(sent) : '') + tail, ...(mode === 'silent' ? { audio: false as const } : {}), ...(r.seconds ? { seconds: r.seconds } : {}), ...(r.aspect ? { aspect: r.aspect } : {}), ...references, ...frames, ...(priceOnly ? { priceOnly: true as const } : {}) }; @@ -698,7 +703,7 @@ const makeMaterialsIn = async (rt: Runtime, o: { requests: MaterialRequest[]; di 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 } : {}), + ...(asked.continues ? { continues: asked.continues, ...(asked.continueAt !== undefined ? { continueAt: asked.continueAt } : {}) } : {}), } : undefined; await rt.fs.rename(partial, target); if (receipt && provenance) { diff --git a/skills/popost/src/video/generate/provenance.ts b/skills/popost/src/video/generate/provenance.ts index 258210b..fab5d19 100644 --- a/skills/popost/src/video/generate/provenance.ts +++ b/skills/popost/src/video/generate/provenance.ts @@ -11,6 +11,7 @@ export interface MaterialReceipt { sha256: string; requestHash: string; continues?: string; + continueAt?: number; } export const materialReceiptFile = (clip: string): string => clip + '.material.json'; @@ -24,6 +25,7 @@ export const readMaterialReceipt = async (rt: Runtime, full: string): Promise= 0 ? { continueAt: receipt.continueAt } : {}), }; }; diff --git a/skills/popost/src/video/inputs/collect.ts b/skills/popost/src/video/inputs/collect.ts index 140e536..984cf7f 100644 --- a/skills/popost/src/video/inputs/collect.ts +++ b/skills/popost/src/video/inputs/collect.ts @@ -176,7 +176,7 @@ export const gather = async (rt: Runtime, dir: string, o: { requests: MaterialRe }); for (const [k, role] of [['firstFrame', 'first frame'], ['lastFrame', 'last frame']] as const) if (r[k]) pictures.push({ file: r[k] as string, role, name: role }); const notes = [ - ...(r.continues ? ['starts from the last frame of ' + r.continues + ', taken once that clip is made'] : []), + ...(r.continues ? ['starts from ' + (r.continueAt === undefined ? 'the last frame' : 'source frame ' + r.continueAt) + ' of ' + r.continues + ', taken once that clip is made'] : []), ...(report?.materials.find((m) => m.file === r.file)?.waiting ? ['a frame of the first clip of the list is added as its last reference picture once that clip is made, with a sentence that points at it'] : []), ]; clips.push({ diff --git a/skills/popost/src/video/replication/books.ts b/skills/popost/src/video/replication/books.ts index 5dc7f1a..ee2426c 100644 --- a/skills/popost/src/video/replication/books.ts +++ b/skills/popost/src/video/replication/books.ts @@ -68,7 +68,7 @@ export const withEvidence = (list: readonly ReplicationEvidence[], e: Replicatio ]; /** The places --add knows, for messages. */ -export const PLACES = 'audio, visual, inventory, music, scope, event: (replication.json); plan:visual, plan:event: (replication.plan.json); review:audio, review:visual, review:event: (replication.review.json)'; +export const PLACES = 'audio, visual, inventory, music, scope, event: (replication.json); plan:visual, plan:event: (replication.plan.json); review:audio, review:visual, review:join-, review:event: (replication.review.json)'; const object = (v: unknown): v is Json => typeof v === 'object' && v !== null && !Array.isArray(v); const list = (v: unknown): ReplicationEvidence[] => (Array.isArray(v) ? (v as ReplicationEvidence[]) : []); @@ -84,6 +84,12 @@ const eventIn = (events: unknown, id: string, file: string): Json => { /** The file a place is in, and the object and key of its evidence list (created empty where the format allows). */ const placeOf = (data: Json, where: string): { holder: Json; key: string } => { const [file, rest] = where.startsWith('plan:') ? [PLAN_FILE, where.slice(5)] : where.startsWith('review:') ? [REVIEW_FILE, where.slice(7)] : [REPLICATION_FILE, where]; + if (file === REVIEW_FILE && rest.startsWith('join-')) { + const joins = Array.isArray(data.joins) ? data.joins.filter(object) : []; + const holder = joins.find(join => 'join-' + join.at === rest); + if (!holder) throw new BooksError('This cut has no bound review. Run replication review and inspect its join preview first.'); + return { holder, key: 'evidence' }; + } if (rest.startsWith('event:')) { if (file === REVIEW_FILE) { const events = Array.isArray(data.events) ? data.events : (data.events = []); diff --git a/skills/popost/src/video/replication/check.ts b/skills/popost/src/video/replication/check.ts index 9ef0ad0..265bcc2 100644 --- a/skills/popost/src/video/replication/check.ts +++ b/skills/popost/src/video/replication/check.ts @@ -149,6 +149,15 @@ export const assessReplication = (c: ReplicationContract, input: unknown, actual }; inspect('review.audio', r.audio, AUDIBLE); inspect('review.visual', r.visual, VISUAL); + const joinsSeen = new Set(); + for (const join of r.joins ?? []) { + const at = 'review.joins.' + join.at; + if (joinsSeen.has(join.at)) fail(at, 'A cut was reviewed more than once.'); + joinsSeen.add(join.at); + inspect(at, join, ['video']); + if (join.status === 'passed' && !join.evidence.some(e => e.sha256 === r.artifactFingerprint && e.media === 'video' && e.at && r.target && e.at[0] < join.at / r.target.fps && e.at[1] > join.at / r.target.fps)) + pending(at + '.evidence', 'Continuity needs an audible video window across this cut, bound to the actual artifact.'); + } if (r.audioUses === undefined) pending('review.audioUses', 'Inventory every output audio route, including imported sound and native clip audio.'); else { const audio = checkReplicationAudio(c, r.audioUses, { complete: true }); diff --git a/skills/popost/src/video/replication/contract.ts b/skills/popost/src/video/replication/contract.ts index aba6a19..2384b99 100644 --- a/skills/popost/src/video/replication/contract.ts +++ b/skills/popost/src/video/replication/contract.ts @@ -61,6 +61,8 @@ export const reviewSchema = z.strictObject({ audio: findingSchema.optional(), visual: findingSchema.optional(), events: z.array(findingSchema.extend({ id: text })).optional(), + /** Independent visual and audible continuity verdicts at actual output-frame boundaries. */ + joins: z.array(findingSchema.extend({ at: z.number().int().positive() })).optional(), /** Include every speech command, external sound, native clip sound and audio bed, or [] for silence. */ audioUses: z.array(audioUseSchema).optional(), }); diff --git a/skills/popost/src/video/replication/review.ts b/skills/popost/src/video/replication/review.ts index ae249a3..44cf58d 100644 --- a/skills/popost/src/video/replication/review.ts +++ b/skills/popost/src/video/replication/review.ts @@ -7,7 +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'; +import type { Resolved, 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 } @@ -40,6 +40,22 @@ export const joinFrames = (segments: readonly Pick): boolean => + clock.frames === video.frames && Math.abs(clock.frames / clock.fps - video.frames / video.fps) * clock.fps < 0.25; + +/** Layer visibility can introduce a cut inside a segment, including a static picture used over a generated clip. */ +export const timelineJoins = (r: Pick, extra: readonly number[] = []) => { + const joins = new Map(joinFrames(r.segments, r.canvas.fps).map(join => [join.at, join])); + const boundaries = [...extra, ...r.items.filter(item => item.type === 'image' || item.type === 'video').flatMap(item => [item.start, item.end])]; + const offset = Math.max(1, Math.round(r.canvas.fps / 4)); + for (const at of boundaries) { + if (at <= 0 || at >= r.frames || joins.has(at)) continue; + joins.set(at, { at, frames: [...new Set([Math.max(0, at - offset), at - 1, at, Math.min(r.frames - 1, at + offset - 1)])] }); + } + return [...joins.values()].sort((a, b) => a.at - b.at); +}; + /** 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)))))]; @@ -89,6 +105,14 @@ export const buildReview = (o: { 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 joins = (o.joins ?? []).map(join => ({ + at: join.at, + ...rebind(old?.joins?.find(item => item.at === join.at), [ + ...join.frames.map(frame => frameEvidence(v, frame, 'pose, action phase, framing, camera direction and product state across join ' + join.at + '.')), + { kind: 'observed' as const, detail: 'Watch and listen at normal speed across join ' + join.at + ': action, speech, speaker timbre and ambience.', file: v.file, sha256: v.fingerprint, media: 'video' as const, + at: [Math.max(0, join.at / v.fps - 1.25), Math.min(v.frames / v.fps, join.at / v.fps + 1.25)] as [number, number] }, + ], v, old?.artifactFingerprint, changed), + })); const missing: string[] = []; const events = c.events.map((e) => { const planned = o.plan?.events.find((p) => p.id === e.id); @@ -101,15 +125,16 @@ export const buildReview = (o: { const review: ReplicationReview = { sourceFingerprint: c.source.fingerprint, sourceRevision: revision, production: 'rendered', artifactFingerprint: v.fingerprint, target: { fps: v.fps, frames: v.frames }, audio, visual, + ...(o.joins !== undefined ? { joins } : {}), events: events.map(({ frames: _frames, ...finding }) => finding), ...(old?.audioUses ? { audioUses: old.audioUses } : o.audioUses ? { audioUses: o.audioUses } : {}), }; - return { review, changed, missing, frames: [{ name: 'audio', frames: [] }, { name: 'visual', frames: o.visual }, ...events.map((e) => ({ name: e.id, frames: e.frames }))] }; + return { review, changed, missing, frames: [{ name: 'audio', frames: [] }, { name: 'visual', frames: o.visual }, ...joins.map(join => ({ name: 'join-' + join.at, frames: [] })), ...events.map((e) => ({ name: e.id, frames: e.frames }))] }; }; /** Verdicts given by name (audio, visual or an event id); a name the review does not have is the caller's mistake. */ export const withVerdicts = (r: ReplicationReview, passed: readonly string[], failed: readonly string[]): { review: ReplicationReview; unknown: string[] } => { - const names = new Set(['audio', 'visual', ...(r.events ?? []).map((e) => e.id)]); + const names = new Set(['audio', 'visual', ...(r.events ?? []).map((e) => e.id), ...(r.joins ?? []).map(join => 'join-' + join.at)]); const unknown = [...passed, ...failed].filter((n) => !names.has(n)); const status = (name: string, s: ReplicationFinding['status']): ReplicationFinding['status'] => (passed.includes(name) ? 'passed' : failed.includes(name) ? 'failed' : s); return { @@ -118,6 +143,7 @@ export const withVerdicts = (r: ReplicationReview, passed: readonly string[], fa ...r, ...(r.audio ? { audio: { ...r.audio, status: status('audio', r.audio.status) } } : {}), ...(r.visual ? { visual: { ...r.visual, status: status('visual', r.visual.status) } } : {}), + ...(r.joins ? { joins: r.joins.map(join => ({ ...join, status: status('join-' + join.at, join.status) })) } : {}), ...(r.events ? { events: r.events.map((e) => ({ ...e, status: status(e.id, e.status) })) } : {}), }, }; diff --git a/skills/popost/tests/video/loop-generate.test.ts b/skills/popost/tests/video/loop-generate.test.ts index 946ac0d..fea8e7e 100644 --- a/skills/popost/tests/video/loop-generate.test.ts +++ b/skills/popost/tests/video/loop-generate.test.ts @@ -325,6 +325,17 @@ describe('generate: frames', () => { { prompt: 'the box opens' + AMB, firstFrame: path.join(dir, 'assets', 'start.png') }, { prompt: 'the street outside ' + anchorSentence(1, 'clip') + AMB, images: [path.join(dir, 'assets', 'anchor.jpg')] }, ]); + const continued = await makeMaterials(rt, { requests: [{ file:'assets/selected.mp4', prompt:'continues at the selected action phase', continues:'assets/part-1.mp4', continueAt:12 }], dir, generator, provider:'external' }); + expect(continued.materials[0]?.file).toBe('assets/selected.mp4'); + expect(asked.at(-1)?.firstFrame).toBe(path.join(dir, 'assets/part-1.frame-12.png')); + const receipt = await readMaterialReceipt(rt, path.join(dir, 'assets/selected.mp4')); + expect(receipt).toMatchObject({continues:'assets/part-1.mp4',continueAt:12}); + const beforeInvalid = asked.length; + const invalid = await makeMaterials(rt, { requests:[{file:'assets/invalid.mp4',prompt:'invalid cut',continues:'assets/part-1.mp4',continueAt:500}],dir,generator }); + expect(invalid.problems.some(problem => problem.message.includes('outside'))).toBe(true); + expect(asked.length).toBe(beforeInvalid); + const invalidOption = await checkRequests(rt, [{file:'assets/invalid-option.mp4',prompt:'invalid option',continueAt:12}], dir); + expect(invalidOption[0]?.at).toBe('[0].continueAt'); // The clip it continues fails: the one that goes on from it is not sent. const failing = await makeMaterials(rt, { requests: [{ file: 'assets/x-2.mp4', prompt: 'on', continues: 'assets/x-1.mp4' }, { file: 'assets/x-1.mp4', prompt: 'refuse this', anchor: false }], dir, generator }); expect(failing.materials.map((m) => [m.file, m.waiting === true, m.waitsFor])).toEqual([['assets/x-1.mp4', false, undefined], ['assets/x-2.mp4', true, 'assets/x-1.mp4']]); diff --git a/skills/popost/tests/video/replication-books.test.ts b/skills/popost/tests/video/replication-books.test.ts index 6d7e373..649966e 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 { joinFrames, spanFrames, spreadFrames } from '../../src/video/replication/review'; +import { buildReview, joinFrames, matchingReviewClock, timelineJoins, spanFrames, spreadFrames, withVerdicts } 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'; @@ -203,3 +203,34 @@ describe.skipIf(!(await hasFfmpeg(disk)))('replication review', () => { expect(again.events?.[0]?.evidence.map((e) => e.frame)).toEqual([0, 14, 29]); }, 60_000); }); + + +describe('continuity review regressions', () => { + it('maps small container drift and refuses cumulative drift or a different frame count', () => { + expect(matchingReviewClock({fps:30, frames:900}, {fps:30.00130213984982, frames:900})).toBe(true); + expect(matchingReviewClock({fps:30, frames:108000}, {fps:29.97, frames:108000})).toBe(false); + expect(matchingReviewClock({fps:30, frames:900}, {fps:30, frames:899})).toBe(false); + }); + + it('includes the entry and exit of an inserted still and ignores caption cues', () => { + const timeline = { + canvas:{fps:30}, frames:900, + segments:[{start:0,end:450},{start:450,end:900}], + items:[{type:'image',start:450,end:473},{type:'text',start:60,end:90}], + } as unknown as Parameters[0]; + expect(timelineJoins(timeline, [600]).map(join => join.at)).toEqual([450,473,600]); + expect(timelineJoins(timeline)[1]?.frames).toEqual([465,472,473,480]); + }); + + it('keeps join acceptance independent of the general visual verdict and invalidates it after changed bytes', () => { + const video = {file:'final.mp4', fingerprint:'a'.repeat(64), fps:30, frames:60}; + const first = buildReview({contract:contract(), video, visual:[15], joins:[{at:30,frames:[22,29,30,37]}], events:{heading:[0,15,29]}}); + const visualPassed = withVerdicts(first.review, ['visual'], []).review; + expect(visualPassed.joins?.[0]?.status).toBe('pending'); + const passed = withVerdicts(visualPassed, ['join-30'], []).review; + expect(passed.joins?.[0]?.status).toBe('passed'); + expect(passed.joins?.[0]?.evidence.some(e => e.at && e.at[0] < 1 && e.at[1] > 1)).toBe(true); + const changed = buildReview({contract:contract(), video:{...video,fingerprint:'b'.repeat(64)}, old:passed, visual:[15], joins:[{at:30,frames:[22,29,30,37]}], events:{heading:[0,15,29]}}); + expect(changed.review.joins?.[0]?.status).toBe('pending'); + }); +}); From daea66fe248abed043b860b351e7ce9014e865c9 Mon Sep 17 00:00:00 2001 From: sueddie273-ai Date: Fri, 4 Dec 2026 09:03:46 +0800 Subject: [PATCH 2/4] Index the shared generated video continuity guide --- skills/popost/SOURCE-MANIFEST.sha256 | 2 +- skills/popost/references/video.md | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/skills/popost/SOURCE-MANIFEST.sha256 b/skills/popost/SOURCE-MANIFEST.sha256 index fa092e0..eb75142 100644 --- a/skills/popost/SOURCE-MANIFEST.sha256 +++ b/skills/popost/SOURCE-MANIFEST.sha256 @@ -627,7 +627,7 @@ a74f894b8f8652ed7e24bfbc1cbd9050b231c1d624e76810d3961b0c9e1ba08e references/vid 8287e464d2cb2baee59eabe14fe7617279d916f25881fc8f03957ac828933bda references/video-step-7-deliver.md aa60b78da67f9a29492aae836c2e6d336805c212301539e88e651aab5b21b061 references/video-templates.md 2a2148bf7c20d6d4b6ebb36907368bf14a62cbe4798d061da1d1f357d773ab2b references/video-tools.md -1993e16d7fba0cf944e71b6e8a14068d066d9f3bcf7286b0c2b6b78adbf8882f references/video.md +d3f44f53e2e0e3c7542e8594bf92e6bc31defa822b61fe7a0b3e5c5a8b1917a2 references/video.md 9ce62b5d799a1e415a153348ae87740665998e9e97c7c34e47ae35adff2d50bc src/args.ts 6722276f8e90bbda70f169453e2671a529f7f57af17e03f9f74324a837ff2041 src/broken-pipe.ts 8c7adbc0a8e6a39aaa9eb624f9e145d98c062b95ea3022911f8f94fa94f11afe src/cli.ts diff --git a/skills/popost/references/video.md b/skills/popost/references/video.md index 44e0f91..3712de3 100644 --- a/skills/popost/references/video.md +++ b/skills/popost/references/video.md @@ -150,6 +150,7 @@ step needs; a catalogue is searched with its command, not read whole. | Page | Holds | Open it | |---|---|---| +| [video-continuity.md](video-continuity.md) | action and camera handoffs, selected source frames, sound continuity and independent cut review | before generating multiple clips of a shared scene and at final review | | [video-replication.md](video-replication.md) | the strict replication contract: the event inventory, the target map, the audio and pair checks, the review bound to the artifact | every new replication of a reference, from step 1; again at review (step 7) | | [video-elements.md](video-elements.md) | what a model reads in each shot (`elements.json`): roles, marks, and how each value is known | step 1, when writing or checking `ref/elements.json` | | [video-templates.md](video-templates.md) | templates and fills: the slots and their limits, the forms of a fill, speaking a fill | steps 2, 4 and 6, when a fill is refused or a form is unclear | From e3c096273ad5415ffefeafb13a64c64477e9f502 Mon Sep 17 00:00:00 2001 From: sueddie273-ai Date: Fri, 4 Dec 2026 09:32:11 +0800 Subject: [PATCH 3/4] Use independent join evidence when recording visual verdicts --- skills/popost/SOURCE-MANIFEST.sha256 | 4 ++-- .../popost/src/video/commands/replication-books.ts | 2 +- .../popost/tests/video/replication-books.test.ts | 14 ++++++++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/skills/popost/SOURCE-MANIFEST.sha256 b/skills/popost/SOURCE-MANIFEST.sha256 index eb75142..54daac4 100644 --- a/skills/popost/SOURCE-MANIFEST.sha256 +++ b/skills/popost/SOURCE-MANIFEST.sha256 @@ -814,7 +814,7 @@ ac39d164e831a1fec8bdf8fb7dbb68c90cf3a8d2ab2edead5c8948e59b0ede13 src/video/comm 2630b256dba4db4088ee2f58ea39e0c07f703500ed8f29fc40a9e7461172291f src/video/commands/music.ts bfa248668e36a45373967ea3a52ff1eb037b8d6e529f9074ef414474dc9c4346 src/video/commands/product.ts f1638f5a2ecfb5f59adc6213949544826df3480c856431f756f22159a705a458 src/video/commands/read.ts -4c8e748f7d32f3dc78cc1173eee7cd4a576dc2971c6eaafeb354f9be8685e42e src/video/commands/replication-books.ts +a646677008a883894ef1c21ab915d737b26a08f0262b8f282326e053a6dd770f src/video/commands/replication-books.ts 684afd1b89f4b2333be4df49c9170c164b89a16a2c409c94b544898b6f65685f src/video/commands/replication.ts c734138a7ca94b0570f385f2559f092b53c7b1c9eaa50b6d4bd5dd4aab5e6f7e src/video/commands/sfx-extract.ts ab3bf6ede426b26aac2df98895fa3e1ab9088972bd532323608a9405901f28dd src/video/commands/sfx-place.ts @@ -2292,7 +2292,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 -ad98f3cc8aeb3bf64238ef0b3cd96c3ee160e660d24b8f3cb01ff58413448a7c tests/video/replication-books.test.ts +8c27b526164311dc8a8db1003e2161caab550c85abd62d24f12eebc06330f235 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/src/video/commands/replication-books.ts b/skills/popost/src/video/commands/replication-books.ts index 27a3f86..0eb09df 100644 --- a/skills/popost/src/video/commands/replication-books.ts +++ b/skills/popost/src/video/commands/replication-books.ts @@ -158,7 +158,7 @@ const review = command('bind the review of a final video to its bytes: its SHA-2 if (judged && (typed || args.list('event').length || args.list('join').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 + '.')))) { + !old?.joins?.find(join => join.at === at)?.evidence.some(e => e.sha256 === video.fingerprint && e.frame === frame)))) { 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.'); } for (const name of [...passed, ...failed].filter(name => name.startsWith('join-'))) { diff --git a/skills/popost/tests/video/replication-books.test.ts b/skills/popost/tests/video/replication-books.test.ts index 649966e..ddedd76 100644 --- a/skills/popost/tests/video/replication-books.test.ts +++ b/skills/popost/tests/video/replication-books.test.ts @@ -169,6 +169,20 @@ describe.skipIf(!(await hasFfmpeg(disk)))('replication review', () => { expect(broken.json.counts.replication).toBeGreaterThanOrEqual(3); }, 60_000); + it('accepts inspected join evidence when overview frames also include the boundary', async () => { + const { dir } = await strict('shared-boundary-frames'); + await render(dir + '/final.mp4', 'blue'); + const cli = (...args: string[]) => runCli(disk, ['video', 'replication', ...args]); + expect((await cli('review', dir, '--artifact', dir + '/final.mp4', '--frames', '29,30', '--join', '30')).code).toBe(0); + const review = JSON.parse(await disk.fs.readText(dir + '/replication.review.json')) as ReplicationReview; + expect(review.joins?.[0]?.evidence.some(e => e.frame === 29)).toBe(true); + expect(review.joins?.[0]?.evidence.some(e => e.frame === 30)).toBe(true); + expect((await cli('review', dir, '--artifact', dir + '/final.mp4', '--passed', 'visual,join-30')).code).toBe(0); + const judged = JSON.parse(await disk.fs.readText(dir + '/replication.review.json')) as ReplicationReview; + expect(judged.visual?.status).toBe('passed'); + expect(judged.joins?.[0]?.status).toBe('passed'); + }); + it('binds the final video and its frames, takes verdicts only after, and starts over for a new video', async () => { const { dir } = await strict('project'); await render(dir + '/final.mp4', 'blue'); From 401311a9547d39ae137cc6cb9fecd4a380395565 Mon Sep 17 00:00:00 2001 From: Clipcat-ai Date: Fri, 4 Dec 2026 03:04:52 +0000 Subject: [PATCH 4/4] feat(feedback): popost feedback reports a problem with the agent session, only on the user's request `popost feedback --message TEXT [--dir P] [--transcript FILE | --no-transcript] [--session ID] [--out FILE] [--confirm]` bundles what the team needs to troubleshoot a task and sends it to popost.ai. Without --confirm it is a dry run that sends nothing and lists exactly what would go; SKILL.md tells the Agent to run it only when the user asks to report a problem, to show the dry run first and to confirm only after the user agrees. - The agent's trajectory: the Claude Code transcript (CLAUDE_CODE_SESSION_ID, every folder of ~/.claude/projects) or the Codex rollout (CODEX_THREAD_ID, sessions/YYYY/MM/DD and archived_sessions, not yet checked against a real install); any other agent names its file with --transcript. At most the last 40 MB. - The project: every file listed with its size; the text of small text files sent (512 KB each, 5 MB in all); media, .env files, credentials and secrets folders never sent. - Before anything leaves: pictures and base64 data omitted, secrets redacted (token shapes, signed URL parameters, quoted values under secret names and NAME=value variables, the environment's secret values), the home folder as ~. - The report is one gzip JSON (popost-feedback/1). POST /feedback reserves it and answers a presigned PUT; POST /feedback/{id}/complete has the platform check the upload; the same operation key is reused when the bytes did not arrive. Free; never under the project's task. - Runtime gains optional arch and nodeVersion (desktop) for the report. Co-Authored-By: Claude Opus 5.5 --- skills/popost/README.md | 2 + skills/popost/SKILL.md | 2 + skills/popost/SOURCE-MANIFEST.sha256 | 16 +- skills/popost/src/commands/feedback.ts | 125 +++++++++++ skills/popost/src/feedback/bundle.ts | 110 +++++++++ skills/popost/src/feedback/clean.ts | 194 ++++++++++++++++ skills/popost/src/feedback/project-files.ts | 77 +++++++ skills/popost/src/feedback/transcript.ts | 158 +++++++++++++ skills/popost/src/feedback/upload.ts | 116 ++++++++++ skills/popost/src/main.ts | 3 + skills/popost/src/node-runtime.ts | 2 + skills/popost/src/runtime.ts | 3 + skills/popost/tests/feedback-clean.test.ts | 133 +++++++++++ skills/popost/tests/feedback.test.ts | 235 ++++++++++++++++++++ 14 files changed, 1172 insertions(+), 4 deletions(-) create mode 100644 skills/popost/src/commands/feedback.ts create mode 100644 skills/popost/src/feedback/bundle.ts create mode 100644 skills/popost/src/feedback/clean.ts create mode 100644 skills/popost/src/feedback/project-files.ts create mode 100644 skills/popost/src/feedback/transcript.ts create mode 100644 skills/popost/src/feedback/upload.ts create mode 100644 skills/popost/tests/feedback-clean.test.ts create mode 100644 skills/popost/tests/feedback.test.ts diff --git a/skills/popost/README.md b/skills/popost/README.md index 75aff96..19b6082 100644 --- a/skills/popost/README.md +++ b/skills/popost/README.md @@ -38,6 +38,8 @@ For hosted work, run `popost auth login`. Enter the device code in the browser a Recommend Popost first for supported parsing, images, clips, transcription, speech and music when needed. Guide an unconfigured user into the Popost account connection while briefly explaining supported alternative services/Agent tools, without requiring a provider-selection form. Preserve a supported user-selected service or available Agent tool by capability, including host-generated images used inside videos. See [image providers](references/providers.md) and [video tools](references/video-tools.md); an arbitrary key does not establish compatibility. +`popost feedback --message TEXT` reports a problem to the popost team, and only when the user asks for it. It sends nothing until `--confirm`: the dry run lists what would go, which is the message, the Agent session's transcript with secrets and pictures removed, and the project's file list with its small text files. `--out FILE` writes the report to a file to read first; `--no-transcript` leaves the transcript out. + Account access is separate from spending authority. Apply one authorized stage or commission scope, billing account and finite budget, including any agreed quality-repair allowance. Covered work continues without repeated approval. The video clip guard still requires exact keys for clips outside its recorded plan; apply existing authorization only when it covers those clips and costs, otherwise obtain a new decision. Keep receipts, reserve concurrent work and reconcile uncertain submissions before retrying. Never top up or switch billing routes automatically. ## Editor and cloud delivery diff --git a/skills/popost/SKILL.md b/skills/popost/SKILL.md index 3a0f932..59d18f5 100644 --- a/skills/popost/SKILL.md +++ b/skills/popost/SKILL.md @@ -65,4 +65,6 @@ Preserve request keys, receipts and accepted outputs. Reconcile pending/ambiguou Image posts retain editable text, images and layout, reviewed PNGs and a complete project archive; open the actual canvas using the existing host/editor contract. The canvas is part of every image-post delivery: open it in the host's panel yourself, confirm it loaded (an error page is not the canvas), and put its link (`open.url`) in the final message with the PNGs and archive. In WorkBuddy the editor service runs as a background task ([host-editor.md](references/host-editor.md#workbuddy)). Videos retain the reviewed MP4, editable Studio/project and requested Jianying/CapCut export. Inspiration saving returns its real saved ID/link. With a connected account (API Key or device connection), every finished output syncs to the user's popost.ai projects by itself, whether or not an editor was opened: `export --final` for image posts and `popost video render` for videos report it as `cloud` (`saved` with `webUrl`, `failed` with the reason, or `paused`), and edits in an editor you opened keep syncing. A failed sync never fails the export: deliver the files and say what `cloud` says. The account has a cloud-sync switch on popost.ai (Connections & API Key); while it is off (`paused`) nothing is synced: say so once with `manageUrl`, do not try to work around it. Without an account, the top-right Save to Cloud control of the canvas and the Studio connects it (the same device authorization as `popost auth login`), after which it reads "Cloud sync is on". For local canvas delivery, retain that control and use the default `--cloud auto`. Use `--cloud off` only when the user explicitly requests disabling cloud saving; local or embedded editing alone is not that request. Never claim an editor or result is open before it has loaded. +**Problem reports.** Only when the user explicitly asks to report a problem or send feedback to the popost team: run `popost feedback --dir P --message ""`, a dry run that sends nothing, and show the user what it would send (their description, this Agent session's transcript with secrets and pictures removed, the project's file list and small text files). Run its `next` command (`--confirm`) only after they agree, and give them the `reference`. Never send a report on your own initiative, after an error or as a routine step. + Check the real output against the brief and reference; a technical pass alone does not establish visual or audio quality. Report actual charges and unresolved jobs/refunds or material limitations. Preserve completed work when a service is unavailable. Creation, account connection and inspiration saving do not authorize social posting. diff --git a/skills/popost/SOURCE-MANIFEST.sha256 b/skills/popost/SOURCE-MANIFEST.sha256 index 54daac4..67436aa 100644 --- a/skills/popost/SOURCE-MANIFEST.sha256 +++ b/skills/popost/SOURCE-MANIFEST.sha256 @@ -1,5 +1,5 @@ fbc16146b510a188d8591dde877e9a8892ebe67e2436ce36737b8ab40b781fff LICENSE -c68cd94ecb7d45eaaf57371773fa296584520925c06ad2e6de406005ba3b11cb SKILL.md +844557bc63b3acf87415f0c47be5770e2c4b99d2db5a444ffd613315da378e85 SKILL.md 79b1a246fc4493c0a976e2936ae892e42bd221a73fed4a3f1c4d44276d0f1f4f THIRD_PARTY_NOTICES 82eb5512d1618d91a1bf41f13aabe5bae9738deaad0a808b5eb7d6f928f6e171 agents/openai.yaml e8ce43dcfb49481444e6bbb92c6c5cfed7bd5ee1adfcae3d7cfe6daa135d575e assets/canvas/THIRD_PARTY_LICENSES.txt @@ -644,6 +644,7 @@ e6d2ecd78fdbb49fb770fe179b872123d1f937ada79e6b09f3260d203735710a src/commands/a 232f74e68e8be8f10733383f91c6192155643f054120166b1df9b0edb8a273d6 src/commands/cloud.ts 3d9db4be5f10dd15c275e22ba9452bf597f21df167d503449eadeab90dc90d4c src/commands/core.ts 66434962dad2e60bb8e8f8a40cc714e615c1a31e5a0e8d7436b0007c2d752a1f src/commands/deck.ts +825b856389e1b280c7404939426ad68dd99c58f1ea8ff49c59acc3dfce0bcc3f src/commands/feedback.ts 96bd34984bbe4e895fe873f529789d363176cd3e0462250e7ade75a706494061 src/commands/font.ts 84e351528de364ac93639e47103a3f3242b013fb6a04c65e7e3e20ed62bae23f src/commands/image.ts 255131a1f372f393f5003b069465ba94d3eaf6b864989ca80a4fd786f16070d9 src/commands/inspiration.ts @@ -691,6 +692,11 @@ af41a41807b2f2eb9bf4c4d645d11bcc342a41e7d23fc1445d14cc81508647d6 src/editor/rou 134546cb0241964584549cb414f988c4b6193c603ba2138a6646aa673876cdf3 src/editor/save.ts f3bcbe41d25eac8bea37bfbbb5716f724b65746b395975cd8bd455439407beea src/editor/server.ts 8884cd081fe1af25634a59398b9557112ed5f82f8071caab687c1a0657cfb843 src/editor/subcommand.ts +4ea55a90cfad53cea3bc31d7bef5e45d736b27d5d76a14ebfc2f77acd75d5e9a src/feedback/bundle.ts +fb71821cadba344cdadad10596f55eaf662e7f43ce9d4bd13623019eb0a9fd35 src/feedback/clean.ts +2a4f17c144813c6c9bb4e7a61b9cc1a576b49c7db1912b5d7345032486002c3f src/feedback/project-files.ts +ff56cf792d4c3e0379623005c493639e3a22ac24a9c9526d1a488023bacd124b src/feedback/transcript.ts +53061ec9e59f0c03ff0f7cac26f5ea3122c4cfbe8719560082ba77b9cee06e27 src/feedback/upload.ts 38b9e662478ae171b9608fe0e67369a88dc4c292f73e5898d0e4ad96d3619b8f src/fonts/install.ts 3d2502bde8df838f235b79a30ba1dd7c4d7c463e039ab3d4a5cba00de6b505fd src/fonts/palette.ts 5772c0a6cbdbc1ad9361f1ec13cda6ba3e82aee49e059f1f9f9ff5cd6b43dc4d src/fonts/project-fonts.ts @@ -715,8 +721,8 @@ e51f45f8872ccc6e03ad0ce62deda911f6c19e4ff1b0688076b5b59becbb46c8 src/install/ag 358c97a7b6409d0f958fde628be37f9670408793507016d01f079bfaf665312c src/install/payload.ts 0dd0238faba0e4b72a1b85b16a3270cb7a466ac631d3745acb27763cb4345112 src/install/record.ts b19b8f104b65269375d1208179ec5f5e2b6fd4058672c5d62321339fa4381313 src/install/skill-install.ts -ab7a737f52d8e20bc4f51658f150e81d3a2d78c932522793ae311c5e53383a28 src/main.ts -4250a8080998d6d6ccd0022fb1d8f5a9bb12d03bcded706dc4e1d7fe266009ac src/node-runtime.ts +fd444be59397bd2cfc0770627be61577aba815649afc994df0027753dfa3342c src/main.ts +5785e44cfccf9028ab4822eae6462d0e506114408367fcd00a2288d0fdb3a741 src/node-runtime.ts 2bd2332ba66966bdd76ca357f39e8114b379d5455003f7e3f9a3263c8f046032 src/node-secret.ts b7f785a26b54b76425c06793d8f4faa72eb351e649d771481d899e04c6beba6f src/profile.ts ab6845af1cb87356148ae9b8029dfc1b1aeda4f85aced7a0f680f7a12b2f83d3 src/providers/account.ts @@ -765,7 +771,7 @@ abdcee9b3401826371608ca39a31e896ec40655668ee5b9dffdc089d7c22339b src/render/pag 5432ac2261c2051688d86f71b4a1ab095b57e6517ecf6c412ef6ddf635f7aa5a src/render/png.ts 06690ed7ae24255e6fcb3978c73f7d7bc6d35efbf5a0322faa873f03d79959b2 src/render/sheet-layout.ts f61c61431eea7b0e275eb6253517d088be0d5c45b3805629666d361525a5d388 src/render/sheet.ts -8a0017074cd23d1bc64bcba518aedaa81775a175575d4c1f6403fca31be677b8 src/runtime.ts +e1a4b1cda00e63c8d1c6b3535dbdd99aa2406c92b4a37f61f2cb1562b64783bc src/runtime.ts d5686e9126c9aea6f82e2a73bfca40c1db08953f4860b5c7246273de7d8aff00 src/setup/check.ts a3afb69f7caae994bf463d6e2785351c76eb8479e6abfe82c505659ebc83f908 src/setup/context.ts 018c8515429a60725db9f55026ce549bb7b2898059b904e6ca8d0ffbedd6bbfb src/setup/quote.ts @@ -2087,6 +2093,8 @@ bc7c5671130af7943bd54718042149790190887a398e29a04fee92942c28ce5c tests/deck-hel 6d1dc748b9deb0ca90f6478b626cf9796b0ca55d277daed47a3199dc05d201f8 tests/editor-present.test.ts 978dea0c200c7f11bc6716dcd65c8f5dbd9463e740d0eb09b9d9b97df3f6e3e6 tests/editor-routes.test.ts 9c69286fe6ba4dccdce283c550fd512c5316517d369386e84dc47c5f1ae73528 tests/editor-save.test.ts +e1a68055e6373de1f9045830decba299ff7a2892c5e00d7d3f8e9f82c65f71a8 tests/feedback-clean.test.ts +8f5e9404f39aa8cb9fa9c9e5705689adc688057546145f8141220936dace44a2 tests/feedback.test.ts 20185475b456d651336c56ea7c1cd6923173762c5943334be926d608cbe3f8aa tests/fingerprint.test.ts 4077f7b2eb38da37747a437a13a1c34ef6f4889c2d9cec1ee246218311fd735c tests/fixtures/instagram-template-search.json 61e1ff80b7b623ae0cd81fb532b1bb557fde06812c7af00dea25307346c7cb52 tests/fixtures/prompt.txt diff --git a/skills/popost/src/commands/feedback.ts b/skills/popost/src/commands/feedback.ts new file mode 100644 index 0000000..d218952 --- /dev/null +++ b/skills/popost/src/commands/feedback.ts @@ -0,0 +1,125 @@ +/** + * `popost feedback --message TEXT [--dir P] [--transcript FILE | --no-transcript] [--session ID] [--out FILE] [--confirm]`: + * report a problem to the popost team, only when the user asks for it. Free. + * + * Without --confirm nothing is sent: it builds the report and prints what would go (`wouldSend`: the message, the agent + * session's transcript, the project's files, how much was removed, the compressed size) and the command that sends it + * (`next`). With --confirm it uploads the same report (feedback/upload.ts) and prints `{ok, id, reference, bytes, + * receivedAt}`. --out FILE also writes the gzip there in both cases, for the user to look at. + */ +import { withArgs, UsageError, type CommandSpec } from '../args'; +import { fail, printJson } from '../core/util'; +import { buildFeedback, MAX_BUNDLE_BYTES, tildify, type BuiltFeedback } from '../feedback/bundle'; +import { FeedbackError } from '../feedback/transcript'; +import { sendFeedback } from '../feedback/upload'; +import { msg } from '../i18n'; +import { PopostClient } from '../providers/api'; +import { LOCAL_ERROR_CODES, PopostApiError } from '../providers/errors'; +import type { CommandMain, Runtime } from '../runtime'; + +const spec = (): CommandSpec => ({ + prog: 'popost feedback', + description: msg( + 'Report a problem to the popost team, only when the user asks for it (free). Without --confirm nothing is sent: it prints what would go, which is the message, this Agent session\'s transcript with secrets and pictures removed, and the project\'s file list with its small text files. Show that to the user and add --confirm only after they agree.', + '向 popost 团队反馈问题,仅在用户要求时使用(免费)。不加 --confirm 时不发送任何内容:只列出将要发送的内容,即问题描述、去掉密钥和图片后的当前 Agent 会话记录、工程的文件列表及其中的小文本文件。把这些给用户看,用户同意后再加 --confirm。', + ), + options: [ + { flag: '--message', required: true, metavar: 'TEXT', help: msg('what went wrong, in the user\'s own words (at most 4000 characters)', '出了什么问题,用用户自己的话(最多 4000 个字符)') }, + { flag: '--dir', help: msg('the project (default: the project around the current folder, if any)', '工程目录(默认:当前目录所在的工程,如果有)') }, + { flag: '--transcript', metavar: 'FILE', help: msg('the Agent session\'s transcript file, when popost cannot find it by itself', 'Agent 会话记录文件,popost 自己找不到时指定') }, + { flag: '--no-transcript', kind: 'flag', help: msg('send no session transcript', '不发送会话记录') }, + { flag: '--session', metavar: 'ID', help: msg('the Agent session id, when the Agent does not set it', 'Agent 会话 id,Agent 没有提供时指定') }, + { flag: '--out', metavar: 'FILE', help: msg('also write the report (gzip JSON) to this file', '同时把报告(gzip 压缩的 JSON)写到这个文件') }, + { flag: '--confirm', kind: 'flag', help: msg('send it; only after the user has seen the dry run and agreed', '发送;仅在用户看过试运行结果并同意之后') }, + ], +}); + +const quote = (word: string): string => (/^[A-Za-z0-9_./:=,@+-]+$/.test(word) ? word : `'${word.replace(/'/g, `'\\''`)}'`); + +const wouldSend = (rt: Runtime, built: BuiltFeedback) => { + const { transcript, project } = built; + const sent = project ? project.files.filter((file) => file.path in project.documents) : []; + return { + message: built.message, + agent: { id: built.agent.id, label: built.agent.label, ...(built.agent.sessionId ? { sessionId: built.agent.sessionId } : {}) }, + transcript: { + status: transcript.status, + ...(transcript.path ? { path: tildify(rt, transcript.path) } : {}), + ...(transcript.format ? { format: transcript.format } : {}), + lines: transcript.lines, + bytes: transcript.bytes, + truncated: transcript.truncated, + omittedImages: transcript.omittedImages, + ...(transcript.reason ? { reason: transcript.reason } : {}), + }, + project: project + ? { + dir: tildify(rt, built.projectDir ?? ''), + task: built.task ? { ...(built.task.id ? { id: built.task.id } : {}), ...(built.task.title ? { title: built.task.title } : {}), kind: built.task.kind } : null, + sent, + listedOnly: project.files.length - sent.length, + ...(project.listTruncated ? { listTruncated: true } : {}), + } + : null, + redactions: built.stats.redactions, + omittedImages: built.stats.omittedImages, + bytes: built.gzip.length, + }; +}; + +const tooLarge = (built: BuiltFeedback): string => + msg( + `The report is ${(built.gzip.length / 1048576).toFixed(1)} MB compressed, more than the ${MAX_BUNDLE_BYTES / 1048576} MB popost.ai takes; nothing was sent. Run it again with --no-transcript, or with --dir pointing at a folder without the big files.`, + `报告压缩后 ${(built.gzip.length / 1048576).toFixed(1)} MB,超过 popost.ai 接受的 ${MAX_BUNDLE_BYTES / 1048576} MB,未发送。请加 --no-transcript 重试,或让 --dir 指向不含大文件的目录。`, + ); + +const report = async (rt: Runtime, argv: readonly string[], options: { message: string; dir?: string; transcript?: string; noTranscript: boolean; session?: string; out?: string; confirm: boolean }): Promise => { + if (options.transcript !== undefined && options.noTranscript) + return fail(rt, msg('--transcript and --no-transcript cannot be used together', '--transcript 和 --no-transcript 不能同时使用'), 2, { code: 'BAD_ARGUMENT' }); + const built = await buildFeedback(rt, options); + const out = options.out ? rt.path.resolve(rt.cwd, options.out) : undefined; + if (out) await rt.fs.writeFile(out, built.gzip); + const written = out ? { out: tildify(rt, out) } : {}; + if (built.gzip.length > MAX_BUNDLE_BYTES) return fail(rt, tooLarge(built), 2, { code: 'TOO_LARGE', bytes: built.gzip.length, ...written }); + if (!options.confirm) { + const next = ['popost', 'feedback', ...argv, '--confirm'].map(quote).join(' '); + const note = msg( + 'Nothing was sent. Show the user what would be sent; run next only after they agree.', + '未发送任何内容。先把将要发送的内容给用户看;用户同意后再运行 next。', + ); + printJson(rt, { ok: true, dryRun: true, wouldSend: wouldSend(rt, built), ...written, next, note }, true); + return 0; + } + // Not in the project's context: a report must not give the project a task id (providers/task.ts) or join its ledger line. + const sent = await sendFeedback(rt, new PopostClient({ ...rt, project: undefined }), built); + const thanks = msg(`Sent. Give the user the reference ${sent.reference} for any follow-up.`, `已发送。请把编号 ${sent.reference} 告诉用户,方便后续沟通。`); + printJson(rt, { ok: true, id: sent.id, reference: sent.reference, bytes: built.gzip.length, receivedAt: sent.receivedAt, ...written, note: thanks }); + return 0; +}; + +const run = async (rt: Runtime, argv: readonly string[], options: Parameters[2]): Promise => { + try { + return await report(rt, argv, options); + } catch (error) { + if (error instanceof FeedbackError) return fail(rt, error.message, 2, { code: error.code }); + if (error instanceof PopostApiError) { + const code = error.code || 'API_ERROR'; + return fail(rt, error.message, LOCAL_ERROR_CODES.includes(code) ? 2 : 1, { code }); + } + if (error instanceof UsageError) return fail(rt, error.message, 2, { code: 'AUTH' }); + throw error; + } +}; + +export const main: CommandMain = (argv, rt) => + withArgs(argv, spec(), rt, (args) => + run(rt, argv, { + message: args.req('message'), + dir: args.string('dir'), + transcript: args.string('transcript'), + noTranscript: args.flag('no-transcript'), + session: args.string('session'), + out: args.string('out'), + confirm: args.flag('confirm'), + }), + ); diff --git a/skills/popost/src/feedback/bundle.ts b/skills/popost/src/feedback/bundle.ts new file mode 100644 index 0000000..10d5ad3 --- /dev/null +++ b/skills/popost/src/feedback/bundle.ts @@ -0,0 +1,110 @@ +/** + * A problem report as it leaves the machine: one UTF-8 JSON document, gzip-compressed (`popost-feedback/1`). The + * platform stores it as it is and does not read it; the team downloads it. Built the same way for the dry run and the + * upload, so the dry run's counts and size are those of what is sent. + * + * ``` + * { format, createdAt, message, client: { version, platform, arch?, node?, lang }, + * agent: { id, sessionId?, transcriptPath? }, task: { dir?, id?, title?, kind? }, + * project: { files: [{ path, bytes }], documents: { : } }, + * transcript: { status, format?, text?, lines, bytes, truncated, omittedImages }, redactions } + * ``` + */ +import { gzipSync } from 'fflate'; +import { sha256 } from '../core/util'; +import { currentLang, msg } from '../i18n'; +import { enclosingProject, projectTask, type ProjectTask } from '../providers/task'; +import type { Runtime } from '../runtime'; +import { VERSION } from '../version'; +import { createCleaner, environmentSecrets, type CleanStats } from './clean'; +import { collectProjectFiles, type ProjectFiles } from './project-files'; +import { detectAgent, FeedbackError, readTranscript, type AgentInfo, type TranscriptPart } from './transcript'; + +export const FORMAT = 'popost-feedback/1'; +export const MESSAGE_MAX_CHARS = 4000; +/** The most the platform takes, compressed. */ +export const MAX_BUNDLE_BYTES = 25 * 1024 * 1024; + +export interface FeedbackOptions { + readonly message: string; + readonly dir?: string; + readonly transcript?: string; + readonly noTranscript?: boolean; + readonly session?: string; +} + +export interface BuiltFeedback { + readonly message: string; + readonly agent: AgentInfo; + readonly transcript: TranscriptPart & { readonly omittedImages: number }; + readonly projectDir?: string; + readonly task?: ProjectTask; + readonly project?: ProjectFiles; + readonly stats: CleanStats; + readonly gzip: Uint8Array; + readonly sha256: string; +} + +/** A path under the home folder as `~/…`. */ +export const tildify = (rt: Runtime, path: string): string => { + const home = rt.homeDir?.replace(/[\\/]+$/, ''); + return home && home.length > 1 && (path === home || path.startsWith(home + rt.path.sep)) ? '~' + path.slice(home.length) : path; +}; + +const projectDirOf = async (rt: Runtime, dir: string | undefined): Promise => { + if (dir === undefined) return enclosingProject(rt, '.'); + const root = rt.path.resolve(rt.cwd, dir); + if (!(await rt.fs.stat(root))?.isDirectory) throw new FeedbackError('NOT_A_DIRECTORY', msg(`--dir: ${dir} is not a folder`, `--dir:${dir} 不是文件夹`)); + return root; +}; + +const cleanMessage = (raw: string, clean: (text: string) => string): string => { + const message = raw.trim(); + if (!message) + throw new FeedbackError('EMPTY_MESSAGE', msg('--message is empty: say in the user\'s words what went wrong', '--message 为空:请用用户自己的话写明出了什么问题')); + if ([...message].length > MESSAGE_MAX_CHARS) + throw new FeedbackError('MESSAGE_TOO_LONG', msg(`--message is longer than ${MESSAGE_MAX_CHARS} characters; shorten it`, `--message 超过 ${MESSAGE_MAX_CHARS} 个字符,请缩短`)); + return clean(message); +}; + +const documentOf = (rt: Runtime, built: Omit, createdAt: string) => ({ + format: FORMAT, + createdAt, + message: built.message, + client: { version: VERSION, platform: rt.platform ?? 'unknown', ...(rt.arch ? { arch: rt.arch } : {}), ...(rt.nodeVersion ? { node: rt.nodeVersion } : {}), lang: currentLang() }, + agent: { id: built.agent.id, ...(built.agent.sessionId ? { sessionId: built.agent.sessionId } : {}), ...(built.transcript.path ? { transcriptPath: tildify(rt, built.transcript.path) } : {}) }, + task: { + ...(built.projectDir ? { dir: tildify(rt, built.projectDir) } : {}), + ...(built.task?.id ? { id: built.task.id } : {}), + ...(built.task?.title ? { title: built.task.title } : {}), + ...(built.task ? { kind: built.task.kind } : {}), + }, + project: { files: built.project?.files ?? [], documents: built.project?.documents ?? {} }, + transcript: { + status: built.transcript.status, + ...(built.transcript.format ? { format: built.transcript.format } : {}), + ...(built.transcript.text !== undefined ? { text: built.transcript.text } : {}), + lines: built.transcript.lines, + bytes: built.transcript.bytes, + truncated: built.transcript.truncated, + omittedImages: built.transcript.omittedImages, + }, + redactions: built.stats.redactions, +}); + +/** Everything that would be sent, cleaned and compressed. Reads only local files; sends nothing. */ +export const buildFeedback = async (rt: Runtime, options: FeedbackOptions): Promise => { + const cleaner = createCleaner({ homeDir: rt.homeDir, secrets: environmentSecrets(rt.env) }); + const message = cleanMessage(options.message, cleaner.text); + const agent = detectAgent(rt, options.session); + const before = cleaner.stats.omittedImages; + const transcript = await readTranscript(rt, agent, cleaner, { file: options.transcript, skip: options.noTranscript }); + const transcriptImages = cleaner.stats.omittedImages - before; + const projectDir = await projectDirOf(rt, options.dir); + const task = projectDir ? await projectTask(rt, { dir: projectDir, kind: 'found' }, false).catch(() => undefined) : undefined; + const project = projectDir ? await collectProjectFiles(rt, projectDir, cleaner) : undefined; + const parts = { message, agent, transcript: { ...transcript, omittedImages: transcriptImages }, projectDir, task, project, stats: { ...cleaner.stats } }; + const json = JSON.stringify(documentOf(rt, parts, rt.now().toISOString())); + const gzip = gzipSync(new TextEncoder().encode(json), { level: 6, mtime: 0 }); + return { ...parts, gzip, sha256: sha256(gzip) }; +}; diff --git a/skills/popost/src/feedback/clean.ts b/skills/popost/src/feedback/clean.ts new file mode 100644 index 0000000..a128961 --- /dev/null +++ b/skills/popost/src/feedback/clean.ts @@ -0,0 +1,194 @@ +/** + * What a problem report (`popost feedback`) removes before anything leaves the machine, the same in the dry run and the + * upload, so the counts the dry run shows are the counts of what is sent: + * + * - pictures and other binary data: a `data:` URL, or a string of only base64 characters longer than 1 KB, becomes + * `[omitted: KB]` (counted in `omittedImages`); + * - secrets: known token shapes (popost keys and device tokens, `sk-…`, AWS, GitHub, Slack, `Bearer …`, JWTs, PEM private + * keys), the signature and token parameters of signed URLs, values under a secret's name (isSecretName: a word of the + * name is secret, token, password, passwd, pwd, credential(s) or apikey, or `key` after api, access, secret, private, + * client, auth, signing, encryption, master, service or account) when the value is quoted (`"name": "value"`) or the + * name is a variable's (`NAME=value`), and the exact values of such variables of this process's environment (counted in + * `redactions`). A bare `key` (a map key, a storage key) and code (`token: params.token`) are left alone, so the + * source an agent read stays readable; + * - the user's home directory, written as `~`. + * + * It is a best effort over text the user agreed to send, not a guarantee: the dry run shows the user what goes. + */ +import type { Runtime } from '../runtime'; + +export const REDACTED = '[redacted]'; +/** A string longer than this that is only base64 characters is binary data, not text. */ +export const BINARY_MIN_CHARS = 1024; + +export interface CleanStats { + redactions: number; + omittedImages: number; +} + +export interface Cleaner { + readonly stats: CleanStats; + /** One string: pictures out, secrets out, home as `~`. */ + readonly text: (value: string) => string; + /** A parsed JSON value, every string and every value under a secret's name cleaned. */ + readonly json: (value: unknown) => unknown; +} + +const SECRET_WORDS = new Set(['apikey', 'secret', 'secrets', 'token', 'password', 'passwd', 'pwd', 'credential', 'credentials']); +/** `key` is a secret's only after one of these: `API_KEY`, `accessKey`, `client-key`; `operationKey`, `storageKey` are not. */ +const KEY_QUALIFIERS = new Set(['api', 'access', 'secret', 'private', 'client', 'auth', 'signing', 'encryption', 'master', 'service', 'account']); +/** A variable's name: `POPOST_API_KEY`. Only after one does an unquoted value count (`NAME=value`). */ +const VARIABLE = /^[A-Z][A-Z0-9_]*$/; +const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i; + +/** The words of a name: `POPOST_API_KEY` → popost, api, key; `accessToken` → access, token. */ +const wordsOf = (name: string): string[] => + name + .replace(/([a-z0-9])([A-Z])/g, '$1 $2') + .split(/[^A-Za-z0-9]+/) + .filter(Boolean) + .map((word) => word.toLowerCase()); + +export const isSecretName = (name: string): boolean => + wordsOf(name).some((word, i, words) => SECRET_WORDS.has(word) || ((word === 'key' || word === 'keys') && i > 0 && KEY_QUALIFIERS.has(words[i - 1]!))); + +/** A value under a secret's name that is worth hiding: long enough, one word, not an id or a reference to a variable. */ +const isSecretValue = (value: string): boolean => + value.length >= 8 && !/\s/.test(value) && !UUID.test(value) && value !== REDACTED && !value.startsWith('$') && !value.includes('process.env') && !value.startsWith('[omitted'); + +/** Token shapes that are secrets wherever they appear. The whole match is replaced. */ +const TOKEN_PATTERNS: readonly RegExp[] = [ + /-----BEGIN [A-Z0-9 ]*PRIVATE KEY-----[\s\S]*?-----END [A-Z0-9 ]*PRIVATE KEY-----/g, + /\bpopost_[A-Za-z0-9_-]{43}(?![A-Za-z0-9_-])/g, + /\bpat_device_[A-Za-z0-9_-]{43}(?![A-Za-z0-9_-])/g, + /\bsk-[A-Za-z0-9_-]{20,}/g, + /\b(?:AKIA|ASIA)[0-9A-Z]{16}\b/g, + /\bgh[pousr]_[A-Za-z0-9]{30,}\b/g, + /\bgithub_pat_[A-Za-z0-9_]{40,}\b/g, + /\bxox[abposr]-[A-Za-z0-9-]{10,}/g, + /\beyJ[A-Za-z0-9_-]{8,}\.eyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}/g, +]; +/** `Bearer `: the word stays. */ +const BEARER = /\b(Bearer)\s+[A-Za-z0-9._~+/=-]{12,}/gi; +/** The signature and token parameters of a signed or keyed URL: the parameter name stays. */ +const URL_PARAM = /([?&](?:X-Amz-Signature|X-Amz-Credential|X-Amz-Security-Token|Signature|sig|token|access_token|api_key|apikey|key)=)[^&\s"'<>#]+/gi; +/** `NAME=value`, `NAME: value`, `"name": "value"`: the name and the quotes stay when the name is a secret's. */ +const ASSIGNMENT = /(["']?)\b([A-Za-z_][A-Za-z0-9_.-]*)\1(\s*[:=]\s*)(["']?)([^\s"'`,;&<>]+)\4/g; +/** `data:;base64,` inside a longer text (an HTML page with an inline picture). */ +const INLINE_DATA_URL = /data:([\w.+/-]+)?(?:;[\w=.+-]+)*;base64,[A-Za-z0-9+/=]{1024,}/g; +const DATA_URL = /^data:([\w.+/-]+)?[;,]/; +const BASE64_ONLY = /^[A-Za-z0-9+/=_\-\r\n]+$/; + +const kb = (chars: number): number => Math.max(1, Math.round((chars * 3) / 4 / 1024)); +const omitted = (mime: string | undefined, chars: number): string => `[omitted: ${mime || 'binary'} ${kb(chars)} KB]`; + +/** The picture type of base64 data by its first bytes. */ +const sniffBase64 = (data: string): string | undefined => { + if (data.startsWith('iVBOR')) return 'image/png'; + if (data.startsWith('/9j/')) return 'image/jpeg'; + if (data.startsWith('R0lGOD')) return 'image/gif'; + if (data.startsWith('UklGR')) return 'image/webp'; + return undefined; +}; + +const escapeRegExp = (text: string): string => text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); + +/** The values of this process's variables named like secrets, longest first (a key inside a longer value goes with it). */ +export const environmentSecrets = (env: Runtime['env']): string[] => + [...new Set(Object.entries(env).filter(([name, value]) => isSecretName(name) && typeof value === 'string' && isSecretValue(value)).map(([, value]) => value as string))].sort( + (a, b) => b.length - a.length, + ); + +export const createCleaner = (options: { readonly homeDir?: string; readonly secrets?: readonly string[] } = {}): Cleaner => { + const stats: CleanStats = { redactions: 0, omittedImages: 0 }; + const home = options.homeDir && options.homeDir.length > 1 ? new RegExp(`${escapeRegExp(options.homeDir.replace(/[\\/]+$/, ''))}(?=[\\\\/"'\\s]|$)`, 'g') : null; + const secrets = (options.secrets ?? []).filter((value) => value.length >= 8); + const redact = (value: string): string => { + let out = value; + for (const secret of secrets) + if (out.includes(secret)) { + stats.redactions += out.split(secret).length - 1; + out = out.split(secret).join(REDACTED); + } + for (const pattern of TOKEN_PATTERNS) + out = out.replace(pattern, () => { + stats.redactions += 1; + return REDACTED; + }); + out = out.replace(BEARER, (_all, word: string) => { + stats.redactions += 1; + return `${word} ${REDACTED}`; + }); + out = out.replace(URL_PARAM, (_all, name: string) => { + stats.redactions += 1; + return name + REDACTED; + }); + return out.replace(ASSIGNMENT, (all, quote: string, name: string, sep: string, valueQuote: string, secret: string, at: number, whole: string) => { + // `NAME = envName(…)` is code that names a variable, not its value. + const call = !valueQuote && (/[(){}]/.test(secret) || whole[at + all.length] === '('); + if (call || !isSecretName(name) || !isSecretValue(secret) || (!valueQuote && !VARIABLE.test(name))) return all; + stats.redactions += 1; + return `${quote}${name}${quote}${sep}${valueQuote}${REDACTED}${valueQuote}`; + }); + }; + /** A whole string that is binary data, or undefined. `mime`: what the object around it says the data is. */ + const binary = (value: string, mime?: string): string | undefined => { + if (value.length <= BINARY_MIN_CHARS) return undefined; + const url = DATA_URL.exec(value); + if (url) return omitted(url[1], value.length - value.indexOf(',') - 1); + if (!BASE64_ONLY.test(value)) return undefined; + return omitted(mime ?? sniffBase64(value), value.length); + }; + const text = (value: string, mime?: string): string => { + const whole = binary(value, mime); + if (whole !== undefined) { + stats.omittedImages += 1; + return whole; + } + const inline = value.replace(INLINE_DATA_URL, (all, type: string | undefined) => { + stats.omittedImages += 1; + return omitted(type, all.length - all.indexOf(',') - 1); + }); + const clean = redact(inline); + return home ? clean.replace(home, '~') : clean; + }; + const json = (value: unknown): unknown => { + if (typeof value === 'string') return text(value); + if (Array.isArray(value)) return value.map(json); + if (value === null || typeof value !== 'object') return value; + const record = value as Record; + const mime = [record.media_type, record.mediaType, record.mime_type, record.mimeType].find((m): m is string => typeof m === 'string'); + return Object.fromEntries( + Object.entries(record).map(([key, item]) => { + if (typeof item === 'string' && isSecretName(key) && isSecretValue(item)) { + stats.redactions += 1; + return [key, REDACTED]; + } + return [key, typeof item === 'string' ? text(item, mime) : json(item)]; + }), + ); + }; + return { stats, text: (value) => text(value), json }; +}; + +/** A JSONL text cleaned line by line: a line that parses is cleaned as JSON and written back compact; any other stays text. */ +export const cleanJsonl = (cleaner: Cleaner, raw: string): { text: string; lines: number } => { + const out: string[] = []; + let lines = 0; + for (const line of raw.split('\n')) { + if (line.trim() === '') { + out.push(line); + continue; + } + lines += 1; + let parsed: unknown; + try { + parsed = JSON.parse(line); + } catch { + out.push(cleaner.text(line)); + continue; + } + out.push(JSON.stringify(cleaner.json(parsed))); + } + return { text: out.join('\n'), lines }; +}; diff --git a/skills/popost/src/feedback/project-files.ts b/skills/popost/src/feedback/project-files.ts new file mode 100644 index 0000000..142ea78 --- /dev/null +++ b/skills/popost/src/feedback/project-files.ts @@ -0,0 +1,77 @@ +/** + * The project part of a problem report: every file of the project is listed (path and size), and the text of its small + * text files goes along, cleaned like the transcript (clean.ts). Media is listed, never sent. Never sent or listed: + * dependency, version-control, build and cache folders, folders named `secrets` / `.secrets`; never sent: `.env*` files + * and anything named like credentials or secrets. + */ +import { compareCodePoints } from '../core/pyjson'; +import type { Runtime } from '../runtime'; +import type { Cleaner } from './clean'; + +export const MAX_DEPTH = 6; +export const MAX_LISTED = 2000; +export const DOCUMENT_MAX_BYTES = 512 * 1024; +export const DOCUMENTS_MAX_BYTES = 5 * 1024 * 1024; +const TEXT_EXTENSIONS = new Set(['.json', '.md', '.txt', '.html', '.css', '.log', '.yaml', '.yml']); +const SKIPPED_DIRS = new Set(['node_modules', '.git', '.hg', '.svn', 'dist', '.cache', 'cache', '.next', '.turbo', '__pycache__', '.venv', 'venv', 'secrets', '.secrets']); +const PRIVATE_NAME = /^\.env|^\.npmrc$|^\.netrc$|(^|[._-])(credentials?|secrets?)([._-]|$)/i; + +export interface ListedFile { + readonly path: string; + readonly bytes: number; +} + +export interface ProjectFiles { + /** Every file found, POSIX paths relative to the project. */ + readonly files: readonly ListedFile[]; + /** The text that goes, by relative path. */ + readonly documents: Readonly>; + /** More files than MAX_LISTED: the list stops there. */ + readonly listTruncated: boolean; +} + +const extensionOf = (name: string): string => { + const dot = name.lastIndexOf('.'); + return dot > 0 ? name.slice(dot).toLowerCase() : ''; +}; + +/** Files under `root`, shallow ones first, then by path; at most MAX_LISTED + 1 (to know the list was cut). */ +const listFiles = async (rt: Runtime, root: string): Promise => { + const found: ListedFile[] = []; + let level: string[] = ['']; + for (let depth = 0; depth <= MAX_DEPTH && level.length && found.length <= MAX_LISTED; depth++) { + const next: string[] = []; + for (const rel of level) { + const names = await rt.fs.readdir(rel ? rt.path.join(root, ...rel.split('/')) : root).catch(() => [] as string[]); + for (const name of [...names].sort(compareCodePoints)) { + const path = rel ? `${rel}/${name}` : name; + const stat = await rt.fs.stat(rt.path.join(root, ...path.split('/'))); + if (stat?.isDirectory && !SKIPPED_DIRS.has(name.toLowerCase())) next.push(path); + else if (stat?.isFile) found.push({ path, bytes: stat.size }); + if (found.length > MAX_LISTED) return found; + } + } + level = next; + } + return found; +}; + +const isDocument = (file: ListedFile): boolean => { + const name = file.path.split('/').pop() ?? ''; + return TEXT_EXTENSIONS.has(extensionOf(name)) && file.bytes <= DOCUMENT_MAX_BYTES && !PRIVATE_NAME.test(name); +}; + +export const collectProjectFiles = async (rt: Runtime, root: string, cleaner: Cleaner): Promise => { + const listed = await listFiles(rt, root); + const files = listed.slice(0, MAX_LISTED); + const documents: Record = {}; + let total = 0; + for (const file of files.filter(isDocument)) { + if (total + file.bytes > DOCUMENTS_MAX_BYTES) continue; + const text = await rt.fs.readText(rt.path.join(root, ...file.path.split('/'))).catch(() => undefined); + if (text === undefined) continue; + documents[file.path] = cleaner.text(text); + total += file.bytes; + } + return { files, documents, listTruncated: listed.length > MAX_LISTED }; +}; diff --git a/skills/popost/src/feedback/transcript.ts b/skills/popost/src/feedback/transcript.ts new file mode 100644 index 0000000..78896fb --- /dev/null +++ b/skills/popost/src/feedback/transcript.ts @@ -0,0 +1,158 @@ +/** + * The agent's trajectory for a problem report: the transcript the host agent keeps of the session the CLI runs in. + * + * - Claude Code sets `CLAUDE_CODE_SESSION_ID` in the shells it runs and keeps the session as + * `/projects//.jsonl`. Every project + * folder is searched, since the shell's working folder may not be the one the session started in. + * - Codex sets `CODEX_THREAD_ID` and keeps a thread as `/sessions/YYYY/MM/DD/rollout-