@hypit/hypit 0.1.14 → 0.2.0
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/README.md +2 -2
- package/dist/public/browser-capture.d.ts +9 -3
- package/dist/public/caption.d.ts +2 -0
- package/dist/public/narrative.d.ts +2 -0
- package/dist/public/runtime-kit.d.ts +2 -2
- package/dist/public/speech.d.ts +2 -0
- package/examples/semantic-composition/packages/responsive-explainer/README.md +1 -1
- package/package.json +1 -1
- package/packages/browser-capture/README.md +9 -2
- package/packages/browser-capture/package.json +5 -0
- package/packages/browser-capture/src/browser.ts +22 -8
- package/packages/browser-capture/src/index.ts +8 -2
- package/packages/caption/README.md +1 -1
- package/packages/caption/src/display.ts +1 -0
- package/packages/caption-fine/README.md +19 -5
- package/packages/caption-fine/package.json +1 -0
- package/packages/caption-fine/src/joined-box.ts +114 -0
- package/packages/caption-fine/src/manifest.ts +1 -1
- package/packages/caption-fine/src/render.ts +99 -92
- package/packages/caption-fine/src/spacing.ts +8 -61
- package/packages/caption-fine-studio/src/index.ts +2 -4
- package/packages/cli/README.md +3 -2
- package/packages/cli/src/arguments.ts +2 -2
- package/packages/cli/src/command.ts +1 -1
- package/packages/cli/src/commands/environment.ts +9 -2
- package/packages/cli/src/machine-view.ts +1 -1
- package/packages/cli/src/output.ts +1 -0
- package/packages/credential-store-os/src/store.ts +5 -1
- package/packages/narrative/README.md +3 -1
- package/packages/narrative/src/schema.ts +1 -0
- package/packages/narrative/src/types.ts +2 -0
- package/packages/provider-whisperx-local/README.md +26 -10
- package/packages/provider-whisperx-local/src/activation.ts +10 -1
- package/packages/provider-whisperx-local/src/program.ts +8 -4
- package/packages/runtime-host-node/src/index.ts +1 -0
- package/packages/runtime-kit/README.md +6 -2
- package/packages/runtime-kit/src/index.ts +2 -2
- package/packages/runtime-local/README.md +6 -1
- package/packages/runtime-local/src/host.ts +2 -0
- package/packages/runtime-local/src/index.ts +1 -0
- package/packages/runtime-local/src/programs.ts +53 -17
- package/packages/script/README.md +81 -34
- package/packages/script/bin/migrate-0.2.mjs +90 -0
- package/packages/script/src/edit.ts +28 -60
- package/packages/script/src/lexical.ts +59 -130
- package/packages/script/src/manifest.ts +11 -11
- package/packages/script/src/narrative.ts +4 -2
- package/packages/script/src/parser.ts +140 -193
- package/packages/script/src/types.ts +2 -3
- package/packages/studio/src/ui/code.ts +1 -1
- package/packages/studio/src/ui/main.ts +2 -2
- package/packages/studio/src/ui/markers.ts +3 -3
- package/packages/studio/src/ui/selection.ts +1 -1
- package/packages/studio/src/ui/syntax.ts +42 -21
- package/packages/temporal-markup/README.md +1 -1
- package/packages/video-cli/README.md +9 -5
- package/packages/video-cli/src/capture.ts +17 -2
- package/packages/video-cli/src/creation.ts +4 -6
- package/packages/video-cli/src/media.ts +10 -3
- package/packages/whisperx/README.md +56 -3
- package/packages/whisperx/src/component.ts +2 -5
- package/packages/whisperx/src/evidence.ts +4 -3
- package/packages/whisperx/src/index.ts +1 -0
- package/packages/whisperx/src/manifest.ts +2 -3
- package/packages/whisperx/src/surface.ts +3 -6
- package/packages/whisperx/src/types.ts +9 -1
- package/packages/yt-dlp/README.md +9 -3
- package/packages/yt-dlp/package.json +2 -1
- package/packages/yt-dlp/src/download.ts +10 -24
- package/packages/yt-dlp/src/environment.ts +36 -0
- package/packages/yt-dlp/src/index.ts +1 -0
- package/services/whisperx/README.md +45 -12
- package/services/whisperx/src/hypit_whisperx_service/application.py +3 -0
- package/services/whisperx/src/hypit_whisperx_service/check.py +7 -0
- package/services/whisperx/src/hypit_whisperx_service/config.py +7 -0
- package/services/whisperx/src/hypit_whisperx_service/engine.py +21 -5
- package/services/whisperx/src/hypit_whisperx_service/models.py +131 -0
- package/services/whisperx/src/hypit_whisperx_service/prepare.py +21 -3
- package/services/whisperx/src/hypit_whisperx_service/resources.py +19 -3
- package/services/yt-dlp/README.md +14 -15
- package/services/yt-dlp/pyproject.toml +1 -1
- package/services/yt-dlp/uv.lock +513 -2
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { resolve } from "node:path";
|
|
1
2
|
import {
|
|
2
3
|
createRuntimeEndpointAdapterFacet,
|
|
3
4
|
runtimeConfigExact,
|
|
@@ -18,7 +19,7 @@ const localWhisperXRuntimeAdapter = createRuntimeEndpointAdapterFacet({
|
|
|
18
19
|
"baseUrl", "expectedModel", "expectedDevice", "expectedCompute", "expectedBatchSize",
|
|
19
20
|
"expectedServiceVersion", "expectedWhisperXVersion",
|
|
20
21
|
"defaultConcurrency", "requestTimeoutMs", "maxResponseBytes",
|
|
21
|
-
"serviceCommand",
|
|
22
|
+
"serviceCommand", "alignmentLanguages", "modelCacheDirectory",
|
|
22
23
|
], "local WhisperX");
|
|
23
24
|
const baseUrl = runtimeConfigString(config.baseUrl, "WhisperX baseUrl");
|
|
24
25
|
if (baseUrl !== undefined) {
|
|
@@ -37,6 +38,12 @@ const localWhisperXRuntimeAdapter = createRuntimeEndpointAdapterFacet({
|
|
|
37
38
|
const defaultConcurrency = runtimeConfigPositiveInteger(config.defaultConcurrency, "WhisperX defaultConcurrency");
|
|
38
39
|
const requestTimeoutMs = runtimeConfigPositiveInteger(config.requestTimeoutMs, "WhisperX requestTimeoutMs");
|
|
39
40
|
const maxResponseBytes = runtimeConfigPositiveInteger(config.maxResponseBytes, "WhisperX maxResponseBytes");
|
|
41
|
+
const modelCacheDirectory = runtimeConfigString(config.modelCacheDirectory, "WhisperX modelCacheDirectory");
|
|
42
|
+
const alignmentLanguages = config.alignmentLanguages;
|
|
43
|
+
if (alignmentLanguages !== undefined && (!Array.isArray(alignmentLanguages)
|
|
44
|
+
|| alignmentLanguages.some((item) => typeof item !== "string" || !/^[a-z]+$/u.test(item)))) {
|
|
45
|
+
throw new Error("WhisperX alignmentLanguages must be an array of lowercase language codes");
|
|
46
|
+
}
|
|
40
47
|
const serviceCommandValue = config.serviceCommand;
|
|
41
48
|
if (serviceCommandValue !== undefined
|
|
42
49
|
&& (!Array.isArray(serviceCommandValue) || serviceCommandValue.length === 0
|
|
@@ -80,6 +87,8 @@ const localWhisperXRuntimeAdapter = createRuntimeEndpointAdapterFacet({
|
|
|
80
87
|
expectedServiceVersion: selectedServiceVersion,
|
|
81
88
|
expectedWhisperXVersion: selectedWhisperXVersion,
|
|
82
89
|
...(serviceCommand === undefined ? {} : { serviceCommand }),
|
|
90
|
+
...(alignmentLanguages === undefined ? {} : { alignmentLanguages: alignmentLanguages as string[] }),
|
|
91
|
+
...(modelCacheDirectory === undefined ? {} : { modelCacheDirectory: resolve(context.dataRoot, modelCacheDirectory) }),
|
|
83
92
|
}),
|
|
84
93
|
};
|
|
85
94
|
},
|
|
@@ -52,6 +52,8 @@ export type LocalWhisperXProgramOptions = {
|
|
|
52
52
|
readonly expectedServiceVersion: string;
|
|
53
53
|
readonly expectedWhisperXVersion: string;
|
|
54
54
|
readonly serviceCommand?: ManagedProgramCommand;
|
|
55
|
+
readonly alignmentLanguages?: readonly string[];
|
|
56
|
+
readonly modelCacheDirectory?: string;
|
|
55
57
|
};
|
|
56
58
|
|
|
57
59
|
export function localWhisperXProgram(options: LocalWhisperXProgramOptions): ManagedProgram {
|
|
@@ -85,11 +87,13 @@ export function localWhisperXProgram(options: LocalWhisperXProgramOptions): Mana
|
|
|
85
87
|
HYPIT_WHISPERX_COMPUTE: expected.compute,
|
|
86
88
|
HYPIT_WHISPERX_BATCH_SIZE: String(expected.batchSize),
|
|
87
89
|
HYPIT_WHISPERX_NLTK_DATA: nltkData,
|
|
90
|
+
...(options.modelCacheDirectory === undefined ? {} : { HYPIT_WHISPERX_MODEL_CACHE: options.modelCacheDirectory }),
|
|
91
|
+
HYPIT_WHISPERX_ALIGNMENT_LANGUAGES: (options.alignmentLanguages ?? []).join(" "),
|
|
88
92
|
};
|
|
89
93
|
const check: ManagedProgramCommand = {
|
|
90
94
|
command: pythonEnvironmentCommand(environment, "hypit-whisperx-check"),
|
|
91
|
-
args: [],
|
|
92
|
-
env:
|
|
95
|
+
args: ["--models"],
|
|
96
|
+
env: serviceEnvironment,
|
|
93
97
|
};
|
|
94
98
|
const managedStart: ManagedProgramCommand = {
|
|
95
99
|
command: pythonEnvironmentCommand(environment, "hypit-whisperx-service"),
|
|
@@ -131,10 +135,10 @@ export function localWhisperXProgram(options: LocalWhisperXProgramOptions): Mana
|
|
|
131
135
|
args: ["sync", "--project", localWhisperXManagedProject, "--frozen", "--no-editable"],
|
|
132
136
|
env: { UV_PROJECT_ENVIRONMENT: environment },
|
|
133
137
|
}, {
|
|
134
|
-
label:
|
|
138
|
+
label: `Prepare WhisperX ${expected.model} and alignment resources for ${(options.alignmentLanguages ?? []).join(", ") || "no selected languages"}`,
|
|
135
139
|
command: pythonEnvironmentCommand(environment, "hypit-whisperx-prepare"),
|
|
136
140
|
args: ["--nltk-data", nltkData],
|
|
137
|
-
env:
|
|
141
|
+
env: serviceEnvironment,
|
|
138
142
|
}],
|
|
139
143
|
},
|
|
140
144
|
} : {}),
|
|
@@ -245,6 +245,7 @@ export type RuntimeController = {
|
|
|
245
245
|
down(options?: { readonly maxWaitMs?: number }): Promise<RuntimeWorkerState>;
|
|
246
246
|
};
|
|
247
247
|
readonly programs: {
|
|
248
|
+
prepare(options?: { readonly endpoints?: readonly string[]; readonly onProgress?: (event: ManagedProgramProgress) => void }): Promise<{ readonly dataRoot: string; readonly programs: readonly ManagedProgramReport[] }>;
|
|
248
249
|
up(options: {
|
|
249
250
|
readonly maxWaitMs?: number;
|
|
250
251
|
readonly onProgress?: (event: ManagedProgramProgress) => void;
|
|
@@ -43,8 +43,12 @@ video package by name.
|
|
|
43
43
|
|
|
44
44
|
`ManagedProgram.installation.prepareBeforeStart` lets a Provider reconcile its installed environment
|
|
45
45
|
before a cold start, even when the installation probe already passes. The declared commands use the
|
|
46
|
-
Provider's ordinary package manager.
|
|
47
|
-
|
|
46
|
+
Provider's ordinary package manager. `programs prepare` runs the declared installation independently
|
|
47
|
+
of process startup; `programs up` also checks its resources when the process is already healthy.
|
|
48
|
+
The installation probe covers the owner's selected execution resources, while the process probe
|
|
49
|
+
reports service readiness. Cold reconciliation still applies only before starting a new process.
|
|
50
|
+
Runtime does not name models, inspect source files or infer implementation versions. Preparation
|
|
51
|
+
may acquire resources; execution must consume already prepared resources and report what is missing.
|
|
48
52
|
`ManagedProgramCommand.label` optionally names a command's purpose for progress and log headings.
|
|
49
53
|
It is display text supplied by the Program owner, not a phase to persist or interpret. Runtime
|
|
50
54
|
reports generic process/probe facts; the service itself owns domain-specific progress in its logs.
|
|
@@ -42,11 +42,11 @@ export type ManagedProgramCommand = {
|
|
|
42
42
|
};
|
|
43
43
|
|
|
44
44
|
export type ManagedProgramInstallation = {
|
|
45
|
-
/**
|
|
45
|
+
/** Read-only inspection of the selected environment and resources; no downloads or receipts. */
|
|
46
46
|
probe(): Promise<ManagedProgramState>;
|
|
47
47
|
/** Reconcile an installed environment before a cold start, using its package manager's cache. */
|
|
48
48
|
readonly prepareBeforeStart?: boolean;
|
|
49
|
-
/**
|
|
49
|
+
/** Explicit preparation commands, run for missing resources or cold reconciliation above. */
|
|
50
50
|
readonly commands: readonly ManagedProgramCommand[];
|
|
51
51
|
};
|
|
52
52
|
|
|
@@ -242,7 +242,12 @@ controller returned by `await host.controller()`, and calls `build(...)` on the
|
|
|
242
242
|
`await host.createRuntime()`. There is one production process-lifecycle path.
|
|
243
243
|
|
|
244
244
|
Managed Programs have independent lifetimes. A healthy WhisperX service keeps its model loaded;
|
|
245
|
-
`
|
|
245
|
+
`programs prepare --endpoint <instance>` prepares selected resources without starting or stopping
|
|
246
|
+
that service. Its installation probe is independent of process health, so an online service does not
|
|
247
|
+
hide a newly requested language model. `programs up` prepares missing resources and starts the service
|
|
248
|
+
if needed. `prepareBeforeStart` additionally reconciles a cold installation through the package
|
|
249
|
+
manager's source-aware synchronization. The Provider owns the resource choices and commands;
|
|
250
|
+
Runtime only invokes them under the existing lifecycle lock.
|
|
246
251
|
`runtime down` stops the coordinator and asks its executors to stop; Programs are stopped separately.
|
|
247
252
|
Distribution changes and shell environment changes still concern the coordinator's bootstrap process.
|
|
248
253
|
Inspect active work before restarting it. Environment-backed credentials use that inherited process
|
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
} from "./config.js";
|
|
24
24
|
import {
|
|
25
25
|
bringManagedProgramsUp,
|
|
26
|
+
prepareManagedPrograms,
|
|
26
27
|
reportManagedPrograms,
|
|
27
28
|
takeManagedProgramsDown,
|
|
28
29
|
} from "./programs.js";
|
|
@@ -82,6 +83,7 @@ export async function openLocalRuntimeHost(
|
|
|
82
83
|
),
|
|
83
84
|
},
|
|
84
85
|
programs: {
|
|
86
|
+
prepare: async (programOptions) => await prepareManagedPrograms(profile, { ...programOptions, packageRoot, ...distribution }),
|
|
85
87
|
up: async (programOptions) => await bringManagedProgramsUp(profile, { ...programOptions, packageRoot, ...distribution }),
|
|
86
88
|
down: async (scope) => await takeManagedProgramsDown(profile, { ...scope, packageRoot, ...distribution }),
|
|
87
89
|
report: async (scope) => await reportManagedPrograms(profile, { ...scope, packageRoot, ...distribution }),
|
|
@@ -293,6 +293,8 @@ async function bringUpOwned(
|
|
|
293
293
|
onProgress?.({ id: program.id, phase: "checking" });
|
|
294
294
|
const initial = await program.probe();
|
|
295
295
|
if (initial.state === "ready") {
|
|
296
|
+
const prepared = await prepareOwned(root, program, endpoint, onProgress);
|
|
297
|
+
if (prepared.state.state !== "ready") return prepared;
|
|
296
298
|
onProgress?.({ id: program.id, phase: "ready" });
|
|
297
299
|
return { ...base, action: "already-running", state: initial };
|
|
298
300
|
}
|
|
@@ -306,6 +308,10 @@ async function bringUpOwned(
|
|
|
306
308
|
const installLogPath = join(directory(root, program), "install.log");
|
|
307
309
|
const existingPid = await readPid(root, program);
|
|
308
310
|
if (existingPid !== undefined && processAlive(existingPid)) {
|
|
311
|
+
if (program.installation !== undefined) {
|
|
312
|
+
const prepared = await prepareOwned(root, program, endpoint, onProgress);
|
|
313
|
+
if (prepared.state.state !== "ready") return prepared;
|
|
314
|
+
}
|
|
309
315
|
release();
|
|
310
316
|
onProgress?.({ id: program.id, phase: "waiting", logPath,
|
|
311
317
|
detail: `observing existing process ${existingPid}` });
|
|
@@ -320,23 +326,9 @@ async function bringUpOwned(
|
|
|
320
326
|
}
|
|
321
327
|
if (existingPid !== undefined) await rm(join(directory(root, program), "process.pid"), { force: true });
|
|
322
328
|
if (program.installation !== undefined) {
|
|
323
|
-
const
|
|
324
|
-
if (
|
|
325
|
-
|
|
326
|
-
await rotateLog(installLogPath);
|
|
327
|
-
for (const command of program.installation.commands) {
|
|
328
|
-
onProgress?.({ id: program.id, phase: "installing", logPath: installLogPath, detail: commandLabel(command) });
|
|
329
|
-
const result = await run(root, command, installLogPath);
|
|
330
|
-
if (!result.ok) {
|
|
331
|
-
return { ...base, action: "unchanged", state: initial, logPath: installLogPath, detail: `${command.command} failed: ${result.detail}` };
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
const after = await program.installation.probe();
|
|
335
|
-
if (after.state !== "ready") {
|
|
336
|
-
return { ...base, action: "unchanged", state: initial, logPath: installLogPath, detail: `installation is ${after.state}: ${after.detail}` };
|
|
337
|
-
}
|
|
338
|
-
installed = true;
|
|
339
|
-
}
|
|
329
|
+
const prepared = await prepareOwned(root, program, endpoint, onProgress, program.installation.prepareBeforeStart === true);
|
|
330
|
+
if (prepared.state.state !== "ready") return prepared;
|
|
331
|
+
installed = prepared.action === "installed";
|
|
340
332
|
}
|
|
341
333
|
if (program.start === undefined) {
|
|
342
334
|
// Nothing to keep running: installation was the whole job.
|
|
@@ -435,6 +427,50 @@ async function bringUp(
|
|
|
435
427
|
} finally { release(); }
|
|
436
428
|
}
|
|
437
429
|
|
|
430
|
+
/** Resource preparation is independent of process readiness. Caller owns the lifecycle lock. */
|
|
431
|
+
async function prepareOwned(
|
|
432
|
+
root: string, program: ManagedProgram, endpoint: string,
|
|
433
|
+
onProgress?: (event: ManagedProgramProgress) => void, reconcile = false,
|
|
434
|
+
): Promise<ManagedProgramReport> {
|
|
435
|
+
const base = { id: program.id, endpoint };
|
|
436
|
+
const installation = program.installation;
|
|
437
|
+
if (installation === undefined) return { ...base, action: "unchanged", state: await program.probe() };
|
|
438
|
+
const logPath = join(directory(root, program), "install.log");
|
|
439
|
+
const before = await installation.probe();
|
|
440
|
+
if (before.state === "ready" && !reconcile) return { ...base, action: "unchanged", state: before };
|
|
441
|
+
await mkdir(root, { recursive: true });
|
|
442
|
+
await rotateLog(logPath);
|
|
443
|
+
for (const command of installation.commands) {
|
|
444
|
+
onProgress?.({ id: program.id, phase: "installing", logPath, detail: commandLabel(command) });
|
|
445
|
+
const result = await run(root, command, logPath);
|
|
446
|
+
if (!result.ok) return { ...base, action: "unchanged", state: { state: "down", detail: `${command.command} failed: ${result.detail}` }, installationLogPath: logPath };
|
|
447
|
+
}
|
|
448
|
+
const state = await installation.probe();
|
|
449
|
+
return { ...base, action: state.state === "ready" ? "installed" : "unchanged", state, installationLogPath: logPath };
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
/** Prepare selected resources without starting, stopping or trusting a running process. */
|
|
453
|
+
export async function prepareManagedPrograms(
|
|
454
|
+
path: string, options: ManagedProgramOptions = {},
|
|
455
|
+
): Promise<{ readonly dataRoot: string; readonly programs: readonly ManagedProgramReport[] }> {
|
|
456
|
+
const { dataRoot, programs } = await declaredManagedPrograms(path, options);
|
|
457
|
+
const reports = await Promise.all(independentPrograms(programs).map(async ({ instance, program }): Promise<ManagedProgramReport> => {
|
|
458
|
+
const home = directory(dataRoot, program);
|
|
459
|
+
await mkdir(home, { recursive: true });
|
|
460
|
+
const { tryProgramLock } = await import("./program-lock.js");
|
|
461
|
+
const release = tryProgramLock(home);
|
|
462
|
+
if (release === undefined) return { id: program.id, endpoint: instance, action: "unchanged", state: { state: "down", detail: "another command owns this Program's preparation; inspect its logs" } };
|
|
463
|
+
try {
|
|
464
|
+
options.onProgress?.({ id: program.id, phase: "checking" });
|
|
465
|
+
const report = await prepareOwned(dataRoot, program, instance, options.onProgress);
|
|
466
|
+
if (report.state.state === "ready") options.onProgress?.({ id: program.id, phase: "ready" });
|
|
467
|
+
return report;
|
|
468
|
+
}
|
|
469
|
+
finally { release(); }
|
|
470
|
+
}));
|
|
471
|
+
return { dataRoot, programs: reports };
|
|
472
|
+
}
|
|
473
|
+
|
|
438
474
|
/** Install when needed and start every external program the Runtime Profile implies. */
|
|
439
475
|
export async function bringManagedProgramsUp(
|
|
440
476
|
path: string,
|
|
@@ -10,7 +10,7 @@ know that Script, Segment or Narrative exist.
|
|
|
10
10
|
|
|
11
11
|
```svml
|
|
12
12
|
<script id="story">
|
|
13
|
-
@answer
|
|
13
|
+
@{answer}
|
|
14
14
|
|
|
15
15
|
<opening>
|
|
16
16
|
<ALICE> I will make the first point.
|
|
@@ -18,7 +18,7 @@ know that Script, Segment or Narrative exist.
|
|
|
18
18
|
</opening>
|
|
19
19
|
|
|
20
20
|
<pause/>
|
|
21
|
-
|
|
21
|
+
@{/answer}
|
|
22
22
|
</script>
|
|
23
23
|
```
|
|
24
24
|
|
|
@@ -65,8 +65,8 @@ CaptionDocument contracts.
|
|
|
65
65
|
Role Cue or the Segment close ends that turn.
|
|
66
66
|
- **Dual Text**: one authored speech span with separate display and spoken projections, written
|
|
67
67
|
`<display text | spoken text>`. In `<display text|>`, omitted speech inherits the displayed prose.
|
|
68
|
-
- **Selection marker**: a named semantic range, written `@name ...
|
|
69
|
-
- **Moment marker**: a named semantic point, written `@name
|
|
68
|
+
- **Selection marker**: a named semantic range, written `@{name} ... @{/name}`.
|
|
69
|
+
- **Moment marker**: a named semantic point, written `@{name!}`.
|
|
70
70
|
- **CaptionDocument**: the Script-owned caption truth; it contains **Display Words**,
|
|
71
71
|
**Alignment Units** and **Cue Breaks**. It contains no seconds or frames.
|
|
72
72
|
- **Token attribute**: a flat postfix display-word annotation such as `really{emphasis}` or
|
|
@@ -86,7 +86,7 @@ Caption Styles choose whether to highlight, reveal or keep the text steady.
|
|
|
86
86
|
|
|
87
87
|
In a shared side, markers and display attributes do not enter either text projection. Its speech
|
|
88
88
|
Tokens retain offsets into the actually written left-hand text, so Studio can move an anchor inside
|
|
89
|
-
`<组@beat
|
|
89
|
+
`<组@{beat!}件化|>` without expanding the shorthand. Attributes still annotate the preceding display
|
|
90
90
|
word, not the whole group. Whitespace-only speech is omitted; a group with no spoken text on either
|
|
91
91
|
side is invalid. This adds no new public value type or protocol version.
|
|
92
92
|
|
|
@@ -101,8 +101,8 @@ Units; it does not split the Segment, cut the picture or end a Selection.
|
|
|
101
101
|
<script id="story">
|
|
102
102
|
<exchange>
|
|
103
103
|
<HOST> I use it || every day, || since <2012 | twenty twelve>.
|
|
104
|
-
<GUEST> Even @proof on holiday
|
|
105
|
-
<HOST> @answer! Especially then.
|
|
104
|
+
<GUEST> Even @{proof} on holiday @{/proof}?
|
|
105
|
+
<HOST> @{answer!} Especially then.
|
|
106
106
|
</exchange>
|
|
107
107
|
</script>
|
|
108
108
|
```
|
|
@@ -117,19 +117,53 @@ following characters. Display punctuation attaches to neighboring words without
|
|
|
117
117
|
These units support precise timing and highlighting. A Caption Cue can hold a whole phrase of them;
|
|
118
118
|
`||` chooses its handoff independently of character counts or visual line wrapping.
|
|
119
119
|
|
|
120
|
+
Annotations do not create speech boundaries. Comments are transparent (`hel<!--note-->lo`
|
|
121
|
+
remains `hello`); a postfix attribute or `||` inside a word is invalid. Script analyzes a complete
|
|
122
|
+
prose run before binding these constructs. An explicit Dual correspondence and a speaker/Segment
|
|
123
|
+
boundary remain authored structure. Shared Dual groups still expose their internal speech anchors.
|
|
124
|
+
|
|
125
|
+
A Dual display side is literal authored text, including symbols and emoji: `<😀|smile>` and
|
|
126
|
+
`<.|dot>` have explicit speech correspondence and require no invented speech token for the symbol.
|
|
127
|
+
A literal-only display is one display surface within that correspondence.
|
|
128
|
+
|
|
129
|
+
## Display spelling and separators
|
|
130
|
+
|
|
131
|
+
Script preserves the normalized display spelling independently of speech tokenization. Ordinary
|
|
132
|
+
whitespace runs become one space; leading/trailing whitespace in a Turn and padding at the edges
|
|
133
|
+
of a Dual Text side are omitted. No language-specific rule removes a Chinese space or inserts a
|
|
134
|
+
space between numeric and Korean/Latin tokens. `是的 就是这样`, `3개월`, `3 개월`, `3D` and `3 D`
|
|
135
|
+
therefore remain distinct as authored. Source newlines are prose formatting, not Caption Cue breaks.
|
|
136
|
+
Use `||` for Cues and a family's layout controls for visual rows.
|
|
137
|
+
|
|
138
|
+
Each `CaptionDisplayWord.separatorBefore` is `""` or `" "`, relative to the preceding displayed word
|
|
139
|
+
in its Turn. Together with `text`, it carries the display spelling to consumers; it is not a speech
|
|
140
|
+
Token and has no timing. A renderer suppresses the leading separator at a displayed line/Cue start.
|
|
141
|
+
Shared groups retain internal separators and individual speech anchors: `<New York|>` is one
|
|
142
|
+
Alignment Unit with a space inside, while `<3D|>` has none. Grouping is a creative choice, not a
|
|
143
|
+
workaround for preserving spelling.
|
|
144
|
+
|
|
120
145
|
## Selection and Moment affinity
|
|
121
146
|
|
|
147
|
+
Every marker starts with `@{` and ends with `}`. The complete marker is zero-width in speech and
|
|
148
|
+
display; surrounding prose whitespace remains prose. All control sigils belong inside the braces:
|
|
149
|
+
`@{beat!}` is a Moment, whereas `@{part}!` opens a Selection followed by a literal exclamation mark.
|
|
150
|
+
Names match `[a-z][a-z0-9_-]{0,63}`; whitespace and nesting inside a marker are invalid.
|
|
151
|
+
A marker cannot split a speech Token or separate it from attached punctuation: place
|
|
152
|
+
`@{beat!}“测试”`, not `“@{beat!}测试”`. `hello{emphasis}` is a postfix display attribute; `@{part}`
|
|
153
|
+
is consumed as one marker and cannot be mistaken for that attribute. Write a literal `@{part}` as
|
|
154
|
+
`\@\{part\}`.
|
|
155
|
+
|
|
122
156
|
A marker selects the adjacent semantic anchor; it does not write a timecode. Inside a spoken
|
|
123
157
|
passage, its affinity normally chooses a neighboring word boundary:
|
|
124
158
|
|
|
125
159
|
| Marker | Boundary |
|
|
126
160
|
| --- | --- |
|
|
127
|
-
| `@name` | Selection opens at the next word's start: right affinity. |
|
|
128
|
-
|
|
|
129
|
-
|
|
|
130
|
-
|
|
|
131
|
-
| `@name
|
|
132
|
-
|
|
|
161
|
+
| `@{name}` | Selection opens at the next word's start: right affinity. |
|
|
162
|
+
| `@{~name}` | Selection opens at the previous word's end: left affinity. |
|
|
163
|
+
| `@{/name}` | Selection closes at the previous word's end: left affinity. |
|
|
164
|
+
| `@{/name~}` | Selection closes at the next word's start: right affinity. |
|
|
165
|
+
| `@{name!}` | Moment at the next word's start: right affinity. |
|
|
166
|
+
| `@{~name!}` | Moment at the previous word's end: left affinity. |
|
|
133
167
|
|
|
134
168
|
At structural edges, the parser retains the corresponding Segment or program boundary rather than
|
|
135
169
|
inventing a neighboring word. Selection and Moment ids share one namespace. Selections can overlap,
|
|
@@ -138,37 +172,50 @@ cross and span Segments; unlike tags, they do not need to nest.
|
|
|
138
172
|
To join two visual Selections without exposing their inter-word pause, match affinity on both sides:
|
|
139
173
|
|
|
140
174
|
```text
|
|
141
|
-
@coffee my coffee
|
|
142
|
-
@coffee my coffee
|
|
175
|
+
@{coffee} my coffee @{/coffee} @{~smoothie} my smoothie @{/smoothie}
|
|
176
|
+
@{coffee} my coffee @{/coffee~} @{smoothie} my smoothie @{/smoothie}
|
|
143
177
|
```
|
|
144
178
|
|
|
145
179
|
These are alternative spellings, not two occurrences to put in the same Script. In the first,
|
|
146
180
|
“coffee” ends both the first Window and the gap's left boundary, so the smoothie Selection owns the
|
|
147
181
|
pause. In the second, the next “my” starts both touching boundaries, so the coffee Selection owns it.
|
|
148
|
-
Plain
|
|
182
|
+
Plain `@{/coffee} @{smoothie}` leaves the gap between previous word end and next word start outside both.
|
|
149
183
|
The media consumer still decides playback and visual coverage inside those projected Windows.
|
|
150
184
|
|
|
151
185
|
## Marker writeback
|
|
152
186
|
|
|
153
187
|
`adjustScriptSelection` and `adjustScriptMoment` accept explicit anchor identities. A Selection's
|
|
154
|
-
two endpoints are
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
188
|
+
two endpoints are moved together; unrelated markers and all source prose remain untouched. Names
|
|
189
|
+
terminate at `}`, so writeback never inserts a separating space or normalizes surrounding prose.
|
|
190
|
+
A no-op adjustment returns the original source. Script owns legal insertion sites: Tokens and
|
|
191
|
+
postfix attributes stay together, Dual Text markers follow the actual speech side, and coincident
|
|
192
|
+
markers written together have deterministic order. Empty self-closing Segments expand only when a
|
|
193
|
+
requested boundary needs an interior insertion site.
|
|
194
|
+
|
|
195
|
+
Writeback reparses the result to retain the requested bindings and unchanged speech, display and
|
|
196
|
+
Narrative/Caption content. Source offsets remain parser-private; no formatting history is stored.
|
|
197
|
+
|
|
198
|
+
## Explicit migration from 0.1
|
|
199
|
+
|
|
200
|
+
The 0.2 parser rejects bare `@name` markers. Preview migration from the repository or installed
|
|
201
|
+
Distribution root, then explicitly write the reviewed result:
|
|
202
|
+
|
|
203
|
+
```sh
|
|
204
|
+
node packages/script/bin/migrate-0.2.mjs /path/to/film.svml
|
|
205
|
+
node packages/script/bin/migrate-0.2.mjs /path/to/film.svml --write
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
Use `--body` for a file containing a raw Script body rather than outer SVML. The tool converts
|
|
209
|
+
markers only inside Script bodies, leaves comments and escapes intact, and does not touch provider
|
|
210
|
+
prompt references such as `@image1`. It neither installs anything nor runs during a build.
|
|
211
|
+
|
|
212
|
+
The tool changes marker spelling, not marker placement. Move a marker that separates a word from
|
|
213
|
+
its attached quote or punctuation to the complete word boundary before using that source.
|
|
214
|
+
|
|
215
|
+
Review authored whitespace after migration: spaces previously discarded by Chinese/punctuation
|
|
216
|
+
normalization now appear. The tool preserves source spaces rather than guessing the author's intent.
|
|
217
|
+
Regenerate affected Narrative, caption and Build results with the new reader/writer together;
|
|
218
|
+
protocol identities remain `@1`. Existing rendered media is not modified by source migration.
|
|
172
219
|
|
|
173
220
|
## Complete authored content and narrow exports
|
|
174
221
|
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/** Explicit, one-time marker migration. Never called by parsing, building, or Studio. */
|
|
3
|
+
import { readFile, writeFile } from "node:fs/promises";
|
|
4
|
+
import { resolve } from "node:path";
|
|
5
|
+
import { pathToFileURL } from "node:url";
|
|
6
|
+
|
|
7
|
+
export function migrateScriptBody(source) {
|
|
8
|
+
let result = "";
|
|
9
|
+
for (let cursor = 0; cursor < source.length;) {
|
|
10
|
+
if (source[cursor] === "\\") {
|
|
11
|
+
result += source.slice(cursor, cursor + 2);
|
|
12
|
+
cursor += 2;
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
if (source.startsWith("<!--", cursor)) {
|
|
16
|
+
const close = source.indexOf("-->", cursor + 4);
|
|
17
|
+
if (close < 0) throw new Error("Unclosed Script comment");
|
|
18
|
+
result += source.slice(cursor, close + 3);
|
|
19
|
+
cursor = close + 3;
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
if (source.startsWith("@{", cursor)) {
|
|
23
|
+
const close = source.indexOf("}", cursor + 2);
|
|
24
|
+
if (close < 0) throw new Error("Unclosed delimited Script marker");
|
|
25
|
+
result += source.slice(cursor, close + 1);
|
|
26
|
+
cursor = close + 1;
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
const rest = source.slice(cursor);
|
|
30
|
+
const match = /^@\/([a-z][a-z0-9_-]{0,63})(~)/u.exec(rest)
|
|
31
|
+
?? /^@\/([a-z][a-z0-9_-]{0,63})(?![A-Za-z0-9_-])/u.exec(rest);
|
|
32
|
+
const open = match ? undefined : /^(~)?@([a-z][a-z0-9_-]{0,63})(!)/u.exec(rest)
|
|
33
|
+
?? /^(~)?@([a-z][a-z0-9_-]{0,63})(?![A-Za-z0-9_-])/u.exec(rest);
|
|
34
|
+
if (match) {
|
|
35
|
+
result += `@{/${match[1]}${match[2] ?? ""}}`;
|
|
36
|
+
cursor += match[0].length;
|
|
37
|
+
} else if (open) {
|
|
38
|
+
result += `@{${open[1] ?? ""}${open[2]}${open[3] ?? ""}}`;
|
|
39
|
+
cursor += open[0].length;
|
|
40
|
+
} else {
|
|
41
|
+
result += source[cursor++];
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Change Script raw bodies only; package references and generation prompt tags stay untouched. */
|
|
48
|
+
export function migrateSvml(source) {
|
|
49
|
+
let result = "";
|
|
50
|
+
let cursor = 0;
|
|
51
|
+
const token = /<!--[\s\S]*?-->|<(?:[A-Za-z_][\w.-]*:)?script(?=[\s/>])(?:"[^"]*"|'[^']*'|[^'">])*>/gu;
|
|
52
|
+
for (let match = token.exec(source); match; match = token.exec(source)) {
|
|
53
|
+
if (match[0].startsWith("<!--") || match[0].endsWith("/>")) continue;
|
|
54
|
+
const name = /^<([^\s>]+)/u.exec(match[0])[1];
|
|
55
|
+
const close = `</${name}>`;
|
|
56
|
+
const start = match.index + match[0].length;
|
|
57
|
+
let end = start;
|
|
58
|
+
while (end < source.length) {
|
|
59
|
+
if (source[end] === "\\") { end += 2; continue; }
|
|
60
|
+
if (source.startsWith("<!--", end)) {
|
|
61
|
+
const stop = source.indexOf("-->", end + 4);
|
|
62
|
+
if (stop < 0) throw new Error("Unclosed Script comment");
|
|
63
|
+
end = stop + 3;
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
if (source.startsWith(close, end)) break;
|
|
67
|
+
end++;
|
|
68
|
+
}
|
|
69
|
+
if (end >= source.length) throw new Error(`Missing ${close}`);
|
|
70
|
+
result += source.slice(cursor, start) + migrateScriptBody(source.slice(start, end)) + close;
|
|
71
|
+
cursor = end + close.length;
|
|
72
|
+
token.lastIndex = cursor;
|
|
73
|
+
}
|
|
74
|
+
return result + source.slice(cursor);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(resolve(process.argv[1])).href) {
|
|
78
|
+
const args = process.argv.slice(2);
|
|
79
|
+
const flags = new Set(args.filter(arg => arg.startsWith("--")));
|
|
80
|
+
const paths = args.filter(arg => !arg.startsWith("--"));
|
|
81
|
+
if (paths.length !== 1 || [...flags].some(flag => !["--write", "--body"].includes(flag))) {
|
|
82
|
+
console.error("Usage: node migrate-0.2.mjs <source.svml> [--body] [--write]\nDefault: print migrated SVML. --body: input is a raw Script body. --write: replace the named file.");
|
|
83
|
+
process.exitCode = 2;
|
|
84
|
+
} else {
|
|
85
|
+
const source = await readFile(paths[0], "utf8");
|
|
86
|
+
const migrated = flags.has("--body") ? migrateScriptBody(source) : migrateSvml(source);
|
|
87
|
+
if (flags.has("--write")) await writeFile(paths[0], migrated);
|
|
88
|
+
else process.stdout.write(migrated);
|
|
89
|
+
}
|
|
90
|
+
}
|