@gentbajko/slopify 4.5.1 → 4.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/edge/mcp/tools-runs.js +1 -1
- package/dist/extension/slopify-studio-chrome.zip +0 -0
- package/dist/extension/slopify-studio-firefox.zip +0 -0
- package/dist/kernel/db/migrations/0079-plan-history-indexes.sql +11 -0
- package/dist/kernel/db/migrations/0080-attempts-work-index.sql +4 -0
- package/dist/kernel/runner/providers.js +1 -1
- package/dist/kernel/runner/queue.js +31 -5
- package/dist/kernel/runner/work.js +52 -1
- package/dist/main.js +1 -1
- package/dist/patch-notes/4.5.2.md +17 -0
- package/dist/patch-notes/4.5.3.md +16 -0
- package/dist/patch-notes/index.json +12 -0
- package/dist/slices/article/production-note.js +75 -0
- package/dist/slices/loudness/level-pieces.js +12 -8
- package/dist/slices/loudness/sentence-level.js +35 -24
- package/dist/slices/narration/breaths-worker.js +126 -0
- package/dist/slices/narration/breaths.js +19 -81
- package/dist/slices/narration/clean-pieces.js +9 -10
- package/dist/slices/narration/pauses.js +18 -17
- package/dist/slices/narration/piece-jobs.js +54 -0
- package/dist/slices/narration/pronunciation.js +48 -3
- package/dist/slices/rebuild/admission-repo.js +14 -1
- package/dist/slices/rebuild/narration-history.js +72 -23
- package/dist/slices/rebuild/narration-reuse.js +16 -5
- package/dist/slices/rebuild/provided-review.js +14 -4
- package/dist/slices/rebuild/recipe-audio.js +6 -0
- package/dist/slices/rebuild/recipe-build.js +6 -2
- package/dist/slices/rebuild/recipe-document.js +23 -17
- package/dist/slices/rebuild/recipe-exports.js +8 -1
- package/dist/slices/rebuild/recipe-model.js +48 -4
- package/dist/slices/rebuild/recipe-preparation.js +28 -6
- package/dist/slices/rebuild/recipe-reviews.js +28 -24
- package/dist/slices/rebuild/recipe-save.js +16 -3
- package/dist/slices/rebuild/recipe-shorts.js +195 -8
- package/dist/slices/rebuild/recovery.js +35 -2
- package/dist/slices/rebuild/review-redo.js +15 -7
- package/dist/slices/rebuild/runtime-admission.js +5 -0
- package/dist/slices/rebuild/runtime-agent-review.js +4 -2
- package/dist/slices/rebuild/runtime-materialize.js +14 -0
- package/dist/slices/rebuild/runtime-plan.js +86 -40
- package/dist/slices/rebuild/runtime-provider.js +11 -4
- package/dist/slices/rebuild/runtime-review.js +3 -2
- package/dist/slices/rebuild/runtime-shorts.js +53 -13
- package/dist/slices/rebuild/transition-repo.js +13 -10
- package/dist/slices/reviews/outcome.js +5 -3
- package/dist/slices/reviews/repo.js +12 -0
- package/dist/slices/revisions/schema.js +1 -0
- package/dist/slices/revisions/view.js +3 -3
- package/dist/slices/settings/model.js +6 -2
- package/dist/slices/shorts/keep.js +37 -17
- package/dist/slices/storage/layout.js +15 -0
- package/dist/web/assets/{index-C0n0zeuZ.js → index-C8aMp7m3.js} +2 -2
- package/dist/web/index.html +1 -1
- package/package.json +1 -1
|
@@ -33,19 +33,25 @@ export function reviewHold(deps, work) {
|
|
|
33
33
|
// Starts the redos reviews asked for, once their review step has finished: the item is made
|
|
34
34
|
// again through Re-run's path (a new regeneration token saved as a new project version, then
|
|
35
35
|
// its dependents rebuilt), so the redone item, its new review and everything after it are
|
|
36
|
-
// ordinary recipe work. One at a time per
|
|
37
|
-
//
|
|
36
|
+
// ordinary recipe work. One at a time per project: two redos started together would each save
|
|
37
|
+
// a version on the one before, and the first one's admission would find the project changed,
|
|
38
|
+
// leaving its new draw held. A redo that cannot start leaves the item flagged with the reason
|
|
39
|
+
// and releases what was waiting on it.
|
|
38
40
|
export function createReviewRedos() {
|
|
39
41
|
let bound;
|
|
42
|
+
// The projects with a redo being started.
|
|
40
43
|
const running = new Set();
|
|
41
|
-
|
|
44
|
+
// `tried`: the verdicts this chain of redos already started. A redo that ended still
|
|
45
|
+
// waiting (its state never saved) is not started again by the chain, so two such redos
|
|
46
|
+
// can't start each other forever; the next review, run or restart starts a fresh chain.
|
|
47
|
+
const kick = (projectId, tried = new Set()) => {
|
|
42
48
|
const deps = bound;
|
|
43
49
|
if (deps === undefined)
|
|
44
50
|
return;
|
|
45
51
|
for (const verdict of pendingRedos(deps.db, projectId)) {
|
|
46
|
-
if (
|
|
52
|
+
if (tried.has(verdict.id) || running.has(verdict.projectId))
|
|
47
53
|
continue;
|
|
48
|
-
running.add(verdict.
|
|
54
|
+
running.add(verdict.projectId);
|
|
49
55
|
void startRedo(deps, verdict)
|
|
50
56
|
.catch((error) => {
|
|
51
57
|
deps.log.write("error", "review.redo", {
|
|
@@ -55,13 +61,15 @@ export function createReviewRedos() {
|
|
|
55
61
|
setRedoState(deps.db, verdict.id, "failed", "Slopify hit an internal error while making this item again. Use Redo beside it; if it happens again, use Download diagnostics in Settings and report it.");
|
|
56
62
|
})
|
|
57
63
|
.finally(() => {
|
|
58
|
-
running.delete(verdict.
|
|
64
|
+
running.delete(verdict.projectId);
|
|
59
65
|
try {
|
|
60
66
|
deps.runner.tick(verdict.projectId);
|
|
61
67
|
}
|
|
62
68
|
catch {
|
|
63
69
|
// The next tick of this project picks the released work up.
|
|
64
70
|
}
|
|
71
|
+
// The project's next waiting redo, on the version this one saved.
|
|
72
|
+
kick(verdict.projectId, new Set([...tried, verdict.id]));
|
|
65
73
|
});
|
|
66
74
|
}
|
|
67
75
|
};
|
|
@@ -69,7 +77,7 @@ export function createReviewRedos() {
|
|
|
69
77
|
bind: (deps) => {
|
|
70
78
|
bound = deps;
|
|
71
79
|
},
|
|
72
|
-
kick,
|
|
80
|
+
kick: (projectId) => kick(projectId),
|
|
73
81
|
};
|
|
74
82
|
}
|
|
75
83
|
// The verdicts whose redo is being started right now. Overrule may call off a redo only while
|
|
@@ -9,6 +9,11 @@ export function reservationKey(recipe, view) {
|
|
|
9
9
|
const key = recipe.input.kind === "tts" ? `${recipe.input.logicalKey}:1` : recipe.key;
|
|
10
10
|
if (view.revision.fingerprints[key] !== undefined)
|
|
11
11
|
return key;
|
|
12
|
+
// A picture check planned once its scene was written has no entry of its own in a version
|
|
13
|
+
// saved while the picture still waited on its scene: it is held to the picture it checks.
|
|
14
|
+
const checked = /^review:(image:.+)$/.exec(recipe.key)?.[1];
|
|
15
|
+
if (checked !== undefined && view.revision.fingerprints[checked] !== undefined)
|
|
16
|
+
return checked;
|
|
12
17
|
const future = recipe.input.kind === "tts"
|
|
13
18
|
? `audio:${recipe.input.segment}:future`
|
|
14
19
|
: recipe.input.kind === "llm" && recipe.input.preparation
|
|
@@ -6,7 +6,7 @@ import { openExternalReview } from "../reviews/external-repo.js";
|
|
|
6
6
|
import { externalReviewByFingerprint } from "../reviews/external-rows.js";
|
|
7
7
|
import { reviewStages } from "../reviews/model.js";
|
|
8
8
|
import { nextAttempt, reviewOutcome } from "../reviews/outcome.js";
|
|
9
|
-
import { latestVerdict, saveVerdict } from "../reviews/repo.js";
|
|
9
|
+
import { latestVerdict, reviewedSameFile, saveVerdict } from "../reviews/repo.js";
|
|
10
10
|
import { exportSnapshot } from "./runtime-export-inputs.js";
|
|
11
11
|
import { lateValuesOf } from "./runtime-keywords.js";
|
|
12
12
|
import { publishResult } from "./runtime-publication.js";
|
|
@@ -67,7 +67,9 @@ export async function executeAgentReviewRecipe(deps, context, piece) {
|
|
|
67
67
|
const verdict = autoPassed ? { passed: true, reasons: [] } : known.verdict;
|
|
68
68
|
if (known.state === "waiting" || verdict === null)
|
|
69
69
|
return "waiting";
|
|
70
|
-
const
|
|
70
|
+
const previous = latestVerdict(deps.db, projectId, itemKey);
|
|
71
|
+
const attempt = nextAttempt(previous, known.itemFingerprint, previous !== undefined &&
|
|
72
|
+
reviewedSameFile(deps.db, previous, context.work.revisionId, known.itemFingerprint));
|
|
71
73
|
const outcome = autoPassed
|
|
72
74
|
? "auto-passed"
|
|
73
75
|
: reviewOutcome({ passed: verdict.passed, mode, attempt, retries });
|
|
@@ -59,6 +59,16 @@ export function materializeAdmittedWork(deps, projectId) {
|
|
|
59
59
|
reservations.find((row) => row.origin_revision === origin.origin_revision && row.work_key === futureKey(recipe));
|
|
60
60
|
if (anchor === undefined || !desiredAnchor(deps, projectId, head, anchor))
|
|
61
61
|
continue;
|
|
62
|
+
// A picture's check is unfolded from its picture once: one already reserved (an
|
|
63
|
+
// agent's review waiting for its answer is held, so it isn't among the allowed rows
|
|
64
|
+
// read above) is the version's check, not a placeholder to replace.
|
|
65
|
+
if (own === undefined &&
|
|
66
|
+
anchor.work_key !== recipe.key &&
|
|
67
|
+
recipe.key.startsWith("review:image:") &&
|
|
68
|
+
deps.db
|
|
69
|
+
.prepare("SELECT 1 FROM revision_work_reservations WHERE revision_id=? AND work_key=?")
|
|
70
|
+
.get(head, recipe.key) !== undefined)
|
|
71
|
+
continue;
|
|
62
72
|
if (own !== undefined &&
|
|
63
73
|
workPieces(deps.db, own.work_id).some((piece) => piece.submittedAt !== null || piece.state === "done"))
|
|
64
74
|
continue;
|
|
@@ -151,6 +161,10 @@ function futureKey(recipe) {
|
|
|
151
161
|
return "research:planner";
|
|
152
162
|
if (recipe.key === "article:continuation")
|
|
153
163
|
return "article:body";
|
|
164
|
+
// A picture's check unfolds with the picture once its scene is written.
|
|
165
|
+
const picture = /^review:(image:.+)$/.exec(recipe.key);
|
|
166
|
+
if (picture?.[1] !== undefined)
|
|
167
|
+
return picture[1];
|
|
154
168
|
// A short's images and render unfold from its image prompts, admitted with them: under the
|
|
155
169
|
// pick on a first run, or on their own when one short is made again and the pick is kept.
|
|
156
170
|
// The prompts unfold from the pick's answer.
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
1
2
|
import { readFileSync } from "node:fs";
|
|
2
3
|
import { z } from "zod";
|
|
3
4
|
import { catalogueSchema } from "../../catalog/schema.js";
|
|
4
|
-
import {
|
|
5
|
-
import { getRevisionView, readyOutput
|
|
5
|
+
import { narrationJoinPiecesOfProject, narrationJoinsOfProject, } from "../revisions/manifest-repo.js";
|
|
6
|
+
import { getRevisionView, readyOutput } from "../revisions/view.js";
|
|
6
7
|
import { outputPath } from "../storage/layout.js";
|
|
7
|
-
import { referencedAssetsAvailable,
|
|
8
|
-
import {
|
|
8
|
+
import { forgetNarrationHistory, referencedAssetsAvailable, retainedNarrationHistory, } from "./narration-history.js";
|
|
9
|
+
import { applyReviews, providedReviews } from "./provided-review.js";
|
|
9
10
|
import { textRecipes } from "./recipe-text.js";
|
|
10
11
|
import { planRevisionWork } from "./recipe-work.js";
|
|
11
12
|
export function executionCatalogue(catalogue, config) {
|
|
@@ -57,18 +58,21 @@ export function workLlm(db, workId, choice, label) {
|
|
|
57
58
|
// few dozen times over a run; at 240 it happened tens of thousands of times and the server
|
|
58
59
|
// spent its whole time planning instead of answering.
|
|
59
60
|
//
|
|
60
|
-
// The plan is kept and handed back while
|
|
61
|
-
//
|
|
62
|
-
//
|
|
63
|
-
//
|
|
64
|
-
//
|
|
61
|
+
// The plan is kept and handed back while everything it is derived from is unchanged. It used
|
|
62
|
+
// to be thrown away on any write to the database at all, which during a run is every finished
|
|
63
|
+
// step of every project, and every write a step makes on its way (its attempt, its cost, its
|
|
64
|
+
// telemetry): a dozen runs at once derived the plan of a 2-hour video several times a second
|
|
65
|
+
// and the server stopped answering. Now the key is what the plan reads, each part read afresh
|
|
66
|
+
// on every call (`planInputs`): the version, its outputs and pieces and whether each file is on
|
|
67
|
+
// disk, the article and notes it reads off disk, the project's narration history and narration
|
|
68
|
+
// joins, the uploads it refers to, its saved provided-content reviews and the catalogue. What
|
|
69
|
+
// those were read from changes, the key changes. A stale plan would start the wrong work, so a
|
|
70
|
+
// test (`runtime-plan-inputs.test.ts`) lists every table a derivation reads: one read the key
|
|
71
|
+
// doesn't cover fails it.
|
|
65
72
|
// Per database, never shared between them: two of them (the app and a mirror, or two tests)
|
|
66
73
|
// can hold the same project under the same id, and one's plan is not the other's.
|
|
67
74
|
const kept = new WeakMap();
|
|
68
|
-
const
|
|
69
|
-
function writesSoFar(deps) {
|
|
70
|
-
return changeCount.parse(deps.db.prepare("SELECT total_changes() AS changes").get()).changes;
|
|
71
|
-
}
|
|
75
|
+
const keptPlans = 48;
|
|
72
76
|
// Two catalogues that differ give different plans, so the catalogue belongs in the key. Its
|
|
73
77
|
// date and shape identify it without hashing the whole of it on every call.
|
|
74
78
|
function catalogueMark(catalogue) {
|
|
@@ -80,47 +84,87 @@ function catalogueMark(catalogue) {
|
|
|
80
84
|
Object.keys(catalogue.providers).length,
|
|
81
85
|
].join("/");
|
|
82
86
|
}
|
|
83
|
-
|
|
84
|
-
//
|
|
85
|
-
//
|
|
86
|
-
//
|
|
87
|
+
const hash = (text) => createHash("sha256").update(text).digest("base64url");
|
|
88
|
+
// What the plan reads of the version: its settings and contents, whether each output and
|
|
89
|
+
// piece is selected and whether its file is still on disk. A file deleted by hand is no write at
|
|
90
|
+
// all, and the plan must stop reusing work whose output is gone. A saved output or piece never
|
|
91
|
+
// changes under its record id (only which are selected does), so the id stands for its record.
|
|
87
92
|
function viewMark(view) {
|
|
88
|
-
const rows = [
|
|
93
|
+
const rows = [
|
|
94
|
+
JSON.stringify(view.revision),
|
|
95
|
+
String(view.current),
|
|
96
|
+
view.articleMarkdown === null ? "-" : `+${view.articleMarkdown}`,
|
|
97
|
+
];
|
|
89
98
|
for (const row of view.outputs)
|
|
90
99
|
rows.push(`o${row.recordId}:${row.selected ? 1 : 0}${row.available ? 1 : 0}:${row.fingerprint}`);
|
|
91
100
|
for (const row of view.pieces)
|
|
92
101
|
rows.push(`p${row.recordId}:${row.selected ? 1 : 0}${row.available ? 1 : 0}:${row.fingerprint}`);
|
|
93
|
-
return
|
|
102
|
+
return hash(rows.join("\n"));
|
|
94
103
|
}
|
|
95
|
-
|
|
96
|
-
const key = `${view.revision.projectId}/${view.revision.id}/${catalogueMark(catalogue)}/${viewMark(view)}`;
|
|
97
|
-
const changes = writesSoFar(deps);
|
|
98
|
-
const forDb = kept.get(deps.db) ?? new Map();
|
|
99
|
-
kept.set(deps.db, forDb);
|
|
100
|
-
const held = forDb.get(key);
|
|
101
|
-
if (held !== undefined && held.changes === changes)
|
|
102
|
-
return held.plan;
|
|
103
|
-
const plan = derivePlan(deps, view, catalogue);
|
|
104
|
-
// A cache, not a store: a handful of revisions is all a run needs at once.
|
|
105
|
-
if (forDb.size > 8)
|
|
106
|
-
forDb.clear();
|
|
107
|
-
forDb.set(key, { changes, plan });
|
|
108
|
-
return plan;
|
|
109
|
-
}
|
|
110
|
-
function derivePlan(deps, view, catalogue) {
|
|
104
|
+
function planInputs(deps, view) {
|
|
111
105
|
const textOutput = (role) => {
|
|
112
106
|
const row = readyOutput(view, { role });
|
|
113
107
|
return row === undefined
|
|
114
108
|
? null
|
|
115
109
|
: readFileSync(outputPath(deps.paths, view.revision.projectId, row.output.path), "utf8");
|
|
116
110
|
};
|
|
117
|
-
const
|
|
118
|
-
|
|
111
|
+
const { projectId } = view.revision;
|
|
112
|
+
return {
|
|
119
113
|
articleMarkdown: view.revision.content.articleEdited === true ||
|
|
120
114
|
view.revision.config.sources.article !== "generate"
|
|
121
115
|
? view.articleMarkdown
|
|
122
116
|
: textOutput("article_md"),
|
|
123
117
|
researchNotes: textOutput("notes"),
|
|
118
|
+
history: retainedNarrationHistory(deps, projectId),
|
|
119
|
+
referenced: referencedAssetsAvailable(deps, projectId, Object.values(view.revision.content.narrationOverrides).flatMap((value) => value.kind === "asset" ? [value.assetId] : [])),
|
|
120
|
+
earlierJoins: narrationJoinsOfProject(deps.db, projectId),
|
|
121
|
+
earlierJoinPieces: narrationJoinPiecesOfProject(deps.db, projectId),
|
|
122
|
+
reviews: providedReviews(deps.db, view.revision.id),
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
function inputsMark(inputs) {
|
|
126
|
+
const record = (row) => `${row.recordId}:${row.selected ? 1 : 0}:${row.fingerprint}:${row.assetId}`;
|
|
127
|
+
return hash([
|
|
128
|
+
inputs.articleMarkdown === null ? "-" : `+${inputs.articleMarkdown}`,
|
|
129
|
+
inputs.researchNotes === null ? "-" : `+${inputs.researchNotes}`,
|
|
130
|
+
inputs.history.mark,
|
|
131
|
+
inputs.referenced.join(","),
|
|
132
|
+
inputs.earlierJoins.map((row) => `${record(row)}:${row.state}`).join(","),
|
|
133
|
+
inputs.earlierJoinPieces.map(record).join(","),
|
|
134
|
+
JSON.stringify(inputs.reviews),
|
|
135
|
+
].join("\n\u0000"));
|
|
136
|
+
}
|
|
137
|
+
// Forgets the plans and planning inputs kept for this database, so the next plan is derived
|
|
138
|
+
// from fresh reads (tests compare the two).
|
|
139
|
+
export function forgetPlanInputs(db) {
|
|
140
|
+
kept.delete(db);
|
|
141
|
+
forgetNarrationHistory(db);
|
|
142
|
+
}
|
|
143
|
+
export function executionPlan(deps, view, catalogue) {
|
|
144
|
+
const inputs = planInputs(deps, view);
|
|
145
|
+
const key = `${view.revision.projectId}/${view.revision.id}/${catalogueMark(catalogue)}/${viewMark(view)}/${inputsMark(inputs)}`;
|
|
146
|
+
const forDb = kept.get(deps.db) ?? new Map();
|
|
147
|
+
kept.set(deps.db, forDb);
|
|
148
|
+
const held = forDb.get(key);
|
|
149
|
+
if (held !== undefined) {
|
|
150
|
+
forDb.delete(key);
|
|
151
|
+
forDb.set(key, held);
|
|
152
|
+
return held;
|
|
153
|
+
}
|
|
154
|
+
const plan = derivePlan(view, catalogue, inputs);
|
|
155
|
+
// A cache, not a store, and the least recently used goes first: a dozen runs at once, each
|
|
156
|
+
// with the versions its held work came from (a redo plans those too). Clearing it all past
|
|
157
|
+
// nine threw every project's plan away before that project asked again.
|
|
158
|
+
forDb.set(key, plan);
|
|
159
|
+
if (forDb.size > keptPlans)
|
|
160
|
+
forDb.delete(forDb.keys().next().value);
|
|
161
|
+
return plan;
|
|
162
|
+
}
|
|
163
|
+
function derivePlan(view, catalogue, inputs) {
|
|
164
|
+
const payloads = view.pieces.filter((piece) => piece.selected && piece.piece.state === "done" && piece.piece.payload !== null);
|
|
165
|
+
const resolved = {
|
|
166
|
+
articleMarkdown: inputs.articleMarkdown,
|
|
167
|
+
researchNotes: inputs.researchNotes,
|
|
124
168
|
};
|
|
125
169
|
const research = matchingResearch({
|
|
126
170
|
config: view.revision.config,
|
|
@@ -129,18 +173,20 @@ function derivePlan(deps, view, catalogue) {
|
|
|
129
173
|
catalogue,
|
|
130
174
|
resolved,
|
|
131
175
|
}, payloads);
|
|
132
|
-
const history =
|
|
176
|
+
const history = inputs.history.pieces;
|
|
133
177
|
const available = new Set([
|
|
134
178
|
...history
|
|
135
179
|
.filter((row) => row.available && row.assetId !== null)
|
|
136
180
|
.flatMap((row) => (row.assetId === null ? [] : [row.assetId])),
|
|
137
|
-
...
|
|
181
|
+
...inputs.referenced,
|
|
138
182
|
...view.outputs.filter((row) => row.available).map((row) => row.assetId),
|
|
139
183
|
...view.pieces
|
|
140
184
|
.filter((row) => row.available && row.assetId !== null)
|
|
141
185
|
.flatMap((row) => (row.assetId === null ? [] : [row.assetId])),
|
|
142
186
|
]);
|
|
143
|
-
return
|
|
187
|
+
return applyReviews(inputs.reviews, planRevisionWork(view.revision,
|
|
188
|
+
// The view with the narration joins of every version of the project (`withEarlierJoins`).
|
|
189
|
+
{ ...view, earlierJoins: inputs.earlierJoins, earlierJoinPieces: inputs.earlierJoinPieces }, catalogue, available, {
|
|
144
190
|
...resolved,
|
|
145
191
|
...(research === undefined ? {} : { research }),
|
|
146
192
|
}, history));
|
|
@@ -3,6 +3,7 @@ import { internalError } from "../../kernel/errors.js";
|
|
|
3
3
|
import { editSettings } from "../../kernel/ports/settings-places.js";
|
|
4
4
|
import { referenceKey, thumbnailVariant } from "../admission/model.js";
|
|
5
5
|
import { plainText } from "../article/plain.js";
|
|
6
|
+
import { withoutProductionNote } from "../article/production-note.js";
|
|
6
7
|
import { splitEndMatter } from "../article/split.js";
|
|
7
8
|
import { checkAppearance } from "../images/appearance.js";
|
|
8
9
|
import { checkScenes, sceneCountOf } from "../images/scenes.js";
|
|
@@ -331,7 +332,9 @@ async function publishText(deps, context, piece, answer) {
|
|
|
331
332
|
return;
|
|
332
333
|
}
|
|
333
334
|
if (piece.key === "article:body") {
|
|
334
|
-
|
|
335
|
+
// A line the model wrote about its own work is never narrated.
|
|
336
|
+
const text = withoutProductionNote(answer.text);
|
|
337
|
+
const parts = splitEndMatter(text);
|
|
335
338
|
// A script is read before it is kept: one the narration could not speak fails here, with
|
|
336
339
|
// the line to fix, rather than at the narration.
|
|
337
340
|
if (piece.input.kind === "llm" && piece.input.script !== undefined) {
|
|
@@ -341,11 +344,11 @@ async function publishText(deps, context, piece, answer) {
|
|
|
341
344
|
}
|
|
342
345
|
await publishResult(deps, context, piece, preparedTexts(deps, context, piece, [
|
|
343
346
|
["instructions", "instructions.md", frozenInstructions(deps, context, piece)],
|
|
344
|
-
["article_md", "article.md",
|
|
347
|
+
["article_md", "article.md", text],
|
|
345
348
|
["article_txt", "article.txt", plainText(parts.body)],
|
|
346
349
|
...(parts.sources ? [["sources", "sources.md", parts.sources]] : []),
|
|
347
350
|
...(parts.glossary ? [["glossary", "glossary.md", parts.glossary]] : []),
|
|
348
|
-
]), { text
|
|
351
|
+
]), { text });
|
|
349
352
|
return;
|
|
350
353
|
}
|
|
351
354
|
if (piece.key === "script:attribute") {
|
|
@@ -380,9 +383,13 @@ async function publishText(deps, context, piece, answer) {
|
|
|
380
383
|
await publishResult(deps, context, piece, [], { title, notes: answer.text }, asset);
|
|
381
384
|
return;
|
|
382
385
|
}
|
|
386
|
+
// The intro and outro are spoken too, so a note about the work goes from them as well.
|
|
387
|
+
const spoken = piece.key === "entry:intro:text" || piece.key === "entry:outro:text"
|
|
388
|
+
? withoutProductionNote(answer.text)
|
|
389
|
+
: answer.text;
|
|
383
390
|
await publishResult(deps, context, piece, preparedTexts(deps, context, piece, [
|
|
384
391
|
["instructions", "instructions.md", frozenInstructions(deps, context, piece)],
|
|
385
|
-
]), { text:
|
|
392
|
+
]), { text: spoken, prompt: spoken });
|
|
386
393
|
}
|
|
387
394
|
function narrationLabel(deps, context, piece) {
|
|
388
395
|
if (piece.input.kind !== "tts")
|
|
@@ -6,7 +6,7 @@ import { editSettings } from "../../kernel/ports/settings-places.js";
|
|
|
6
6
|
import { plainText } from "../article/plain.js";
|
|
7
7
|
import { defaultReviewPrompts, narrationItemKey, reviewStages, } from "../reviews/model.js";
|
|
8
8
|
import { nextAttempt, reviewOutcome } from "../reviews/outcome.js";
|
|
9
|
-
import { latestVerdict, saveVerdict } from "../reviews/repo.js";
|
|
9
|
+
import { latestVerdict, reviewedSameFile, saveVerdict } from "../reviews/repo.js";
|
|
10
10
|
import { parseVerdict, reviewMessages } from "../reviews/verdict.js";
|
|
11
11
|
import { isReadyOutput } from "../revisions/view.js";
|
|
12
12
|
import { pickedShortsOf } from "../shorts/clips.js";
|
|
@@ -52,7 +52,8 @@ export async function executeReviewRecipe(deps, context, providers, piece) {
|
|
|
52
52
|
const snapshot = exportSnapshot(deps, context, piece);
|
|
53
53
|
const material = reviewMaterial(deps, context, snapshot, stage, itemKey, prompt);
|
|
54
54
|
const previous = latestVerdict(deps.db, context.work.projectId, itemKey);
|
|
55
|
-
const attempt = nextAttempt(previous, material.itemFingerprint
|
|
55
|
+
const attempt = nextAttempt(previous, material.itemFingerprint, previous !== undefined &&
|
|
56
|
+
reviewedSameFile(deps.db, previous, context.work.revisionId, material.itemFingerprint));
|
|
56
57
|
const level = thinking === null ? undefined : z.enum(thinkingModes).parse(thinking);
|
|
57
58
|
const call = workLlm(deps.db, context.work.workId, { provider, model, thinking: level }, piece.key);
|
|
58
59
|
if (!context.maySubmit(piece.id))
|
|
@@ -8,7 +8,7 @@ import { assetPathOrUndefined } from "../revisions/mutation-assets.js";
|
|
|
8
8
|
import { readyOutput } from "../revisions/view.js";
|
|
9
9
|
import { clipWords } from "../shorts/captions.js";
|
|
10
10
|
import { effectiveClips, pickedShortsOf } from "../shorts/clips.js";
|
|
11
|
-
import { anchorKept,
|
|
11
|
+
import { anchorKept, locateClip, withNewPicks } from "../shorts/keep.js";
|
|
12
12
|
import { defaultShortsPrompt, musicVolumeOf, shortImageCount, shortsSpeedOf, } from "../shorts/model.js";
|
|
13
13
|
import { checkPicks, keepNumbers, noPicksMessage, pickMessages, pickRetryMessages, } from "../shorts/pick.js";
|
|
14
14
|
import { checkImagePrompts } from "../shorts/prompts.js";
|
|
@@ -18,7 +18,7 @@ import { outputPath, projectDir } from "../storage/layout.js";
|
|
|
18
18
|
import { probeDurationMs } from "../video/ffmpeg.js";
|
|
19
19
|
import { usesVoices } from "../voices/model.js";
|
|
20
20
|
import { sentencesText, transcriptSentences } from "../youtube/transcript.js";
|
|
21
|
-
import { shortsPickKey } from "./recipe-shorts.js";
|
|
21
|
+
import { onBodyClock, shortsPickKey } from "./recipe-shorts.js";
|
|
22
22
|
import { exportMachine, warningsOf } from "./runtime-export.js";
|
|
23
23
|
import { figureShots } from "./runtime-export-edit.js";
|
|
24
24
|
import { exportSnapshot, revisionAudio } from "./runtime-export-inputs.js";
|
|
@@ -68,18 +68,21 @@ async function pick(deps, context, providers, piece, snapshot) {
|
|
|
68
68
|
const llm = config.llm;
|
|
69
69
|
if (llm === undefined || llm.provider.trim() === "" || llm.model.trim() === "")
|
|
70
70
|
throw new Error(`Shorts need an AI model to pick the clips, and none is chosen. Choose a Service and a Model in ${editSettings.writer}, then Try again.`);
|
|
71
|
-
const
|
|
71
|
+
const audio = await revisionAudio(deps, context, view);
|
|
72
|
+
const words = readTimingWords(deps, context, view, shortsTimingPurpose).words;
|
|
73
|
+
// On the body's clock the moments are picked from the body alone, timed from its start, so
|
|
74
|
+
// a new intro or outro leaves them where they are (`recipe-shorts.ts`).
|
|
75
|
+
const body = onBodyClock(input.values) ? bodyWindow(audio) : undefined;
|
|
76
|
+
const sentences = transcriptSentences(body === undefined ? words : bodyWords(words, body));
|
|
72
77
|
if (sentences.length === 0)
|
|
73
78
|
throw new Error("The narration's word timing holds no words, so there is nothing to cut shorts from. Press Make the video again in the project's Video section, then Try again.");
|
|
74
|
-
const
|
|
75
|
-
const durationSeconds = audio.reduce((sum, segment) => sum + segment.seconds, 0);
|
|
79
|
+
const durationSeconds = body?.seconds ?? audio.reduce((sum, segment) => sum + segment.seconds, 0);
|
|
76
80
|
// Kept shorts are found again in this timing; the model is asked only for the rest.
|
|
77
81
|
const keep = view.revision.content.shortsKeep;
|
|
78
82
|
const anchored = keep === undefined
|
|
79
83
|
? undefined
|
|
80
84
|
: anchorKept(keep.slice(0, shorts.count), sentences, durationSeconds);
|
|
81
|
-
|
|
82
|
-
throw new Error(lostMessage(anchored.lost, keep ?? []));
|
|
85
|
+
// A kept short whose own words changed is picked anew in its place; the others stay.
|
|
83
86
|
const keptPicks = anchored?.picks ?? [];
|
|
84
87
|
const wanted = shorts.count - keptPicks.length;
|
|
85
88
|
const taken = keptPicks.map(({ first, last }) => ({ first, last }));
|
|
@@ -243,16 +246,30 @@ async function render(deps, context, piece, snapshot, clip) {
|
|
|
243
246
|
return outputPath(deps.paths, context.work.projectId, row.output.path);
|
|
244
247
|
});
|
|
245
248
|
const allWords = readTimingWords(deps, context, view, shortsTimingPurpose).words;
|
|
246
|
-
|
|
249
|
+
// A clip on the body's clock is found by its sentences in the body as it is now, which
|
|
250
|
+
// starts after whatever intro: other chunks voiced again or words added before it may have
|
|
251
|
+
// moved it since it was picked.
|
|
252
|
+
const input = piece.input;
|
|
253
|
+
let start = clip.start;
|
|
254
|
+
let end = clip.end;
|
|
255
|
+
if (input.kind === "local" && onBodyClock(input.values)) {
|
|
256
|
+
const body = bodyWindow(await revisionAudio(deps, context, view));
|
|
257
|
+
const found = locateClip(transcriptSentences(bodyWords(allWords, body)), clip, body.seconds);
|
|
258
|
+
if (found === undefined)
|
|
259
|
+
throw new Error(`The words short ${String(clip.number)} was cut from are no longer in the narration. Use Pick different moments in ${editSettings.shorts}, then Try again.`);
|
|
260
|
+
start = found.start + body.start;
|
|
261
|
+
end = found.end + body.start;
|
|
262
|
+
}
|
|
263
|
+
const words = clipWords(allWords, start, end);
|
|
247
264
|
// The upright cards whose descriptions fall in the clip, on the clip's own timeline.
|
|
248
265
|
const figures = usesFigureCards(config)
|
|
249
|
-
? figureShots(deps, context, view, "9:16", allWords).flatMap((figure) => figure.end <=
|
|
266
|
+
? figureShots(deps, context, view, "9:16", allWords).flatMap((figure) => figure.end <= start || figure.start >= end
|
|
250
267
|
? []
|
|
251
268
|
: [
|
|
252
269
|
{
|
|
253
270
|
path: figure.path,
|
|
254
|
-
start: Math.max(0, figure.start -
|
|
255
|
-
end: Math.min(
|
|
271
|
+
start: Math.max(0, figure.start - start),
|
|
272
|
+
end: Math.min(end, figure.end) - start,
|
|
256
273
|
},
|
|
257
274
|
])
|
|
258
275
|
: [];
|
|
@@ -276,8 +293,8 @@ async function render(deps, context, piece, snapshot, clip) {
|
|
|
276
293
|
notice: machine.notice,
|
|
277
294
|
master: masterGoal(config, "video"),
|
|
278
295
|
timeline,
|
|
279
|
-
start
|
|
280
|
-
end
|
|
296
|
+
start,
|
|
297
|
+
end,
|
|
281
298
|
images,
|
|
282
299
|
imageSeconds: config.imageSeconds,
|
|
283
300
|
motionStyle: config.motionStyle,
|
|
@@ -362,6 +379,29 @@ async function backgroundMusic(deps, context, view) {
|
|
|
362
379
|
throw new Error(`The shorts' background music file holds no sound. ${fix}`);
|
|
363
380
|
return { path, volume: musicVolumeOf(shorts) };
|
|
364
381
|
}
|
|
382
|
+
// Where the body sits on the video's timeline: after the edge silence, the intro and the gap
|
|
383
|
+
// after it. The word timing is on this clock (`runtime-subtitles.ts`).
|
|
384
|
+
export function bodyWindow(audio) {
|
|
385
|
+
const at = audio.findIndex((segment) => segment.kind === "body");
|
|
386
|
+
const body = audio[at];
|
|
387
|
+
if (body === undefined)
|
|
388
|
+
throw setupError();
|
|
389
|
+
return {
|
|
390
|
+
start: audio.slice(0, at).reduce((sum, segment) => sum + segment.seconds, 0),
|
|
391
|
+
seconds: body.seconds,
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
// The body's words, timed from the body's start (to the microsecond, so the same body reads
|
|
395
|
+
// the same times after any intro).
|
|
396
|
+
export function bodyWords(words, body) {
|
|
397
|
+
const from = (seconds) => Math.max(0, Math.round((seconds - body.start) * 1e6) / 1e6);
|
|
398
|
+
return words.flatMap((word) => {
|
|
399
|
+
const middle = (word.start + word.end) / 2 - body.start;
|
|
400
|
+
return middle < 0 || middle > body.seconds
|
|
401
|
+
? []
|
|
402
|
+
: [{ ...word, start: from(word.start), end: from(word.end) }];
|
|
403
|
+
});
|
|
404
|
+
}
|
|
365
405
|
// What the shorts read the narration's word timing for, in the sentence a missing one fails with.
|
|
366
406
|
const shortsTimingPurpose = "the shorts are cut and captioned from";
|
|
367
407
|
// The project's text model, with the thinking settings saved for this step's catalogue.
|
|
@@ -63,16 +63,19 @@ export function transitionRevisionWork(deps, input) {
|
|
|
63
63
|
carried.add(row.work_key);
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
66
|
+
// Every step of the project the new version doesn't keep: its unfinished pieces and the
|
|
67
|
+
// step itself are held, or draining once something of them was sent or attempted. Two
|
|
68
|
+
// statements over the whole project, not three per step: a project made a few times over
|
|
69
|
+
// has thousands of steps, and the save held the server for seconds.
|
|
70
|
+
db.prepare(`UPDATE revision_work_pieces SET dispatch_state=CASE WHEN submitted_at IS NOT NULL THEN 'draining' ELSE 'held' END
|
|
71
|
+
WHERE work_id IN (SELECT id FROM revision_work WHERE project_id=?) AND state!='done'
|
|
72
|
+
AND id NOT IN (SELECT piece_id FROM revision_work_reservations WHERE revision_id=? AND piece_id IS NOT NULL)`).run(input.projectId, input.revisionId);
|
|
73
|
+
db.prepare(`UPDATE revision_work SET dispatch_state=CASE
|
|
74
|
+
WHEN EXISTS(SELECT 1 FROM attempts a WHERE a.work_id=revision_work.id)
|
|
75
|
+
OR EXISTS(SELECT 1 FROM revision_work_pieces p WHERE p.work_id=revision_work.id AND p.submitted_at IS NOT NULL)
|
|
76
|
+
THEN 'draining' ELSE 'held' END
|
|
77
|
+
WHERE project_id=? AND state!='done'
|
|
78
|
+
AND NOT EXISTS(SELECT 1 FROM revision_work_reservations r WHERE r.revision_id=? AND r.work_id=revision_work.id)`).run(input.projectId, input.revisionId);
|
|
76
79
|
db.prepare(`DELETE FROM revision_work_reservations WHERE project_id=? AND revision_id=? AND work_key NOT IN (SELECT work_key FROM revision_work_reservations WHERE revision_id=?)`).run(input.projectId, input.baseRevisionId, input.revisionId);
|
|
77
80
|
for (const [key, fp] of Object.entries(input.fingerprints)) {
|
|
78
81
|
if (carried.has(key))
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
// Which try at the item this review looks at. A redo Slopify started itself carries the
|
|
2
2
|
// count on; anything else (a first review, an item the person changed or had made again)
|
|
3
|
-
// starts at one. The same output reviewed again keeps its number
|
|
4
|
-
|
|
3
|
+
// starts at one. The same output reviewed again keeps its number, and so does the same file
|
|
4
|
+
// under another fingerprint (`sameFile`, from `reviewedSameFile`): an item flagged after its
|
|
5
|
+
// last try stays flagged rather than being sent back from the first try again.
|
|
6
|
+
export function nextAttempt(previous, itemFingerprint, sameFile = false) {
|
|
5
7
|
if (previous === undefined)
|
|
6
8
|
return 1;
|
|
7
|
-
if (previous.itemFingerprint === itemFingerprint)
|
|
9
|
+
if (previous.itemFingerprint === itemFingerprint || sameFile)
|
|
8
10
|
return previous.attempt;
|
|
9
11
|
if (previous.outcome === "redo" && previous.action === null && previous.redoState !== "failed")
|
|
10
12
|
return previous.attempt + 1;
|
|
@@ -2,6 +2,7 @@ import { z } from "zod";
|
|
|
2
2
|
import { internalError } from "../../kernel/errors.js";
|
|
3
3
|
import { actors } from "../agents/model.js";
|
|
4
4
|
import { reviewAnswerers, reviewStages } from "./model.js";
|
|
5
|
+
import { reviewedOutputKey } from "./view.js";
|
|
5
6
|
const rowSchema = z.object({
|
|
6
7
|
id: z.string(),
|
|
7
8
|
project_id: z.string(),
|
|
@@ -93,6 +94,17 @@ export function pendingRedos(db, projectId) {
|
|
|
93
94
|
.prepare("SELECT * FROM review_verdicts WHERE redo_state='pending' AND project_id=? ORDER BY rowid")
|
|
94
95
|
.all(projectId)).map(recordOf);
|
|
95
96
|
}
|
|
97
|
+
// Whether this verdict looked at the very file a version now holds under `itemFingerprint`. A
|
|
98
|
+
// version that keeps a file can stamp it with another fingerprint (a deferred article settles
|
|
99
|
+
// on its planned one), and the same file is no new try at the item (`nextAttempt`).
|
|
100
|
+
export function reviewedSameFile(db, verdict, revisionId, itemFingerprint) {
|
|
101
|
+
const workKey = reviewedOutputKey(verdict.itemKey);
|
|
102
|
+
return (db
|
|
103
|
+
.prepare(`SELECT 1 FROM revision_outputs a JOIN revision_outputs b ON b.asset_id=a.asset_id
|
|
104
|
+
WHERE a.project_id=? AND a.revision_id=? AND a.work_key=? AND a.fingerprint=?
|
|
105
|
+
AND b.project_id=? AND b.revision_id=? AND b.work_key=? AND b.fingerprint=? LIMIT 1`)
|
|
106
|
+
.get(verdict.projectId, verdict.revisionId, workKey, verdict.itemFingerprint, verdict.projectId, revisionId, workKey, itemFingerprint) !== undefined);
|
|
107
|
+
}
|
|
96
108
|
export function setRedoState(db, id, state, error = null) {
|
|
97
109
|
db.prepare("UPDATE review_verdicts SET redo_state=?, redo_error=? WHERE id=?").run(state, error, id);
|
|
98
110
|
}
|
|
@@ -41,6 +41,7 @@ const keptShortSchema = z
|
|
|
41
41
|
hashtags: z.array(z.string().max(100)).max(30),
|
|
42
42
|
why: z.string().max(2000),
|
|
43
43
|
seed: z.string().max(128).nullable().optional(),
|
|
44
|
+
text: z.string().max(100000).optional(),
|
|
44
45
|
})
|
|
45
46
|
.strict();
|
|
46
47
|
export const revisionContentSchema = z
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { readFileSync, statSync } from "node:fs";
|
|
2
|
-
import { outputPath } from "../storage/layout.js";
|
|
2
|
+
import { outputPath, outputPaths } from "../storage/layout.js";
|
|
3
3
|
import { narrationJoinPiecesOfProject, narrationJoinsOfProject } from "./manifest-repo.js";
|
|
4
4
|
import { currentRevisionId, outputsForRevision, piecesForRevision, revisionById } from "./repo.js";
|
|
5
5
|
export function getRevisionView(deps, projectId, revisionId) {
|
|
@@ -16,6 +16,7 @@ export function getRevisionView(deps, projectId, revisionId) {
|
|
|
16
16
|
if (typeof row.id === "string" && typeof row.path === "string")
|
|
17
17
|
paths.set(row.id, row.path);
|
|
18
18
|
const onDisk = new Map();
|
|
19
|
+
const pathOf = outputPaths(deps.paths, projectId);
|
|
19
20
|
const available = (assetId) => {
|
|
20
21
|
const known = onDisk.get(assetId);
|
|
21
22
|
if (known !== undefined)
|
|
@@ -23,8 +24,7 @@ export function getRevisionView(deps, projectId, revisionId) {
|
|
|
23
24
|
const path = paths.get(assetId);
|
|
24
25
|
if (path === undefined)
|
|
25
26
|
throw new Error(`Revision asset ${assetId} is not registered.`);
|
|
26
|
-
const found = statSync(
|
|
27
|
-
true;
|
|
27
|
+
const found = statSync(pathOf(path), { throwIfNoEntry: false })?.isFile() === true;
|
|
28
28
|
onDisk.set(assetId, found);
|
|
29
29
|
return found;
|
|
30
30
|
};
|
|
@@ -28,8 +28,12 @@ export function isLocalCliProvider(id) {
|
|
|
28
28
|
}
|
|
29
29
|
// How many calls to a command-line tool run at once. Each Codex image is its own job - its
|
|
30
30
|
// own folder and thread - so four are drawn side by side; the text CLIs keep three.
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
// SLOPIFY_CODEX_IMAGES_AT_ONCE (1 to 8) draws more or fewer when the account allows it.
|
|
32
|
+
export function localCliConcurrency(id, env) {
|
|
33
|
+
if (id !== "codex-image")
|
|
34
|
+
return 3;
|
|
35
|
+
const asked = env.SLOPIFY_CODEX_IMAGES_AT_ONCE ?? "";
|
|
36
|
+
return /^[1-8]$/.test(asked) ? Number(asked) : 4;
|
|
33
37
|
}
|
|
34
38
|
export const systemVoiceProvider = "system-voice";
|
|
35
39
|
// A provider Slopify's model list (models.yaml) does not carry: an agent CLI lists its own
|