@joplo-app/core 0.4.1 → 0.6.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/dist/agent-skill.d.ts +7 -7
- package/dist/agent-skill.js +28 -25
- package/dist/authoring-works.d.ts +8 -0
- package/dist/authoring-works.js +46 -0
- package/dist/catalog.d.ts +2 -0
- package/dist/compile.d.ts +6 -3
- package/dist/compile.js +415 -327
- package/dist/content-i18n.js +9 -9
- package/dist/embed.d.ts +5 -5
- package/dist/embed.js +7 -7
- package/dist/entries.d.ts +63 -0
- package/dist/entries.js +78 -0
- package/dist/feature-diff.d.ts +7 -7
- package/dist/feature-diff.js +18 -17
- package/dist/features.d.ts +3 -3
- package/dist/features.js +3 -3
- package/dist/focus-check.js +2 -2
- package/dist/focus.d.ts +1 -5
- package/dist/focus.js +13 -35
- package/dist/guide.js +171 -67
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/load.js +42 -11
- package/dist/local-review-files.js +17 -4
- package/dist/local-review.d.ts +8 -7
- package/dist/local-review.js +7 -6
- package/dist/outline.d.ts +21 -13
- package/dist/outline.js +27 -31
- package/dist/pace.d.ts +10 -5
- package/dist/pace.js +12 -5
- package/dist/playback.d.ts +57 -0
- package/dist/playback.js +317 -0
- package/dist/player.d.ts +9 -180
- package/dist/player.js +8 -618
- package/dist/playground.d.ts +1 -1
- package/dist/playground.js +4 -4
- package/dist/plugins/compiler.d.ts +16 -0
- package/dist/plugins/compiler.js +48 -9
- package/dist/presentation.d.ts +73 -0
- package/dist/presentation.js +163 -0
- package/dist/publication.d.ts +8 -0
- package/dist/publication.js +45 -0
- package/dist/result.d.ts +1 -1
- package/dist/review.d.ts +18 -10
- package/dist/review.js +62 -23
- package/dist/runtime.d.ts +2 -0
- package/dist/runtime.js +2 -0
- package/dist/scene-query.d.ts +77 -0
- package/dist/scene-query.js +246 -0
- package/dist/schema-issues.js +1 -1
- package/dist/schema.d.ts +118 -76
- package/dist/schema.js +52 -37
- package/dist/scope.d.ts +9 -9
- package/dist/scope.js +82 -49
- package/dist/selection.d.ts +1 -1
- package/dist/sequencing.d.ts +6 -0
- package/dist/sequencing.js +21 -0
- package/dist/step-plan.d.ts +55 -0
- package/dist/step-plan.js +90 -0
- package/dist/traits.d.ts +10 -0
- package/dist/traits.js +3 -0
- package/dist/validate.d.ts +1 -1
- package/dist/validate.js +75 -65
- package/dist/voice.js +4 -0
- package/package.json +15 -3
package/dist/index.d.ts
CHANGED
|
@@ -15,6 +15,8 @@ export * from './review.js';
|
|
|
15
15
|
export * from './scope.js';
|
|
16
16
|
export * from './agent-skill.js';
|
|
17
17
|
export * from './pace.js';
|
|
18
|
+
export * from './step-plan.js';
|
|
19
|
+
export * from './entries.js';
|
|
18
20
|
export * from './outline.js';
|
|
19
21
|
export * from './voice.js';
|
|
20
22
|
export * from './content-i18n.js';
|
package/dist/index.js
CHANGED
|
@@ -15,6 +15,8 @@ export * from "./review.js";
|
|
|
15
15
|
export * from "./scope.js";
|
|
16
16
|
export * from "./agent-skill.js";
|
|
17
17
|
export * from "./pace.js";
|
|
18
|
+
export * from "./step-plan.js";
|
|
19
|
+
export * from "./entries.js";
|
|
18
20
|
export * from "./outline.js";
|
|
19
21
|
export * from "./voice.js";
|
|
20
22
|
export * from "./content-i18n.js";
|
package/dist/load.js
CHANGED
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
* layouts/<id>.tsx
|
|
7
7
|
* routes/**\/page.tsx routes/page.tsx → /,routes/members/page.tsx → /members
|
|
8
8
|
* features/<f>/feature.ts
|
|
9
|
-
* features/<f>/
|
|
9
|
+
* features/<f>/works/<o>.tsx
|
|
10
|
+
* works/<key>.tsx 影片 → 章节 → 步骤
|
|
10
11
|
* themes/<name>.css 作者主题(D51),按原文读取
|
|
11
12
|
* locales/<语言>.json 作者内容译文(D84):原文 → 译文
|
|
12
13
|
*/
|
|
@@ -44,10 +45,13 @@ export function discoverFiles(root) {
|
|
|
44
45
|
const ff = findFile(join(fd, 'feature'));
|
|
45
46
|
if (ff)
|
|
46
47
|
files.push(ff);
|
|
47
|
-
for (const o of list(join(fd, '
|
|
48
|
+
for (const o of list(join(fd, 'works')))
|
|
48
49
|
if (/\.(tsx|ts)$/.test(o))
|
|
49
|
-
files.push(join(fd, '
|
|
50
|
+
files.push(join(fd, 'works', o));
|
|
50
51
|
}
|
|
52
|
+
for (const f of list(join(r, 'works')))
|
|
53
|
+
if (/\.(tsx|ts)$/.test(f) && !isDir(join(r, 'works', f)))
|
|
54
|
+
files.push(join(r, 'works', f));
|
|
51
55
|
for (const f of list(join(r, 'themes')))
|
|
52
56
|
if (/\.css$/.test(f))
|
|
53
57
|
files.push(join(r, 'themes', f));
|
|
@@ -115,18 +119,33 @@ export async function loadAuthoring(root, importer) {
|
|
|
115
119
|
const diags = [];
|
|
116
120
|
const relp = (p) => relative(r, p).split(sep).join('/');
|
|
117
121
|
const fail = (file, message, code = 'LOAD_FAILED') => diags.push({ severity: 'error', code, message, source: 'schema', at: `${relp(file)}:1:1` });
|
|
122
|
+
const missingConfig = !existsSync(join(r, 'tsconfig.json'));
|
|
123
|
+
const configurationFailure = (file, detail) => {
|
|
124
|
+
if (diags.some(d => d.code === 'PROJECT_MODULE_CONFIG'))
|
|
125
|
+
return;
|
|
126
|
+
fail(file, `Cannot load this project. Add tsconfig.json using jsx: "react-jsxdev" and jsxImportSource: "@joplo-app/kit" and package.json with "type": "module", then run check again (underlying error: ${detail})`, 'PROJECT_MODULE_CONFIG');
|
|
127
|
+
};
|
|
118
128
|
const load = async (file, kind) => {
|
|
119
129
|
try {
|
|
120
130
|
const mod = await importer(file);
|
|
121
131
|
const v = (mod.default ?? null);
|
|
122
132
|
if (!v || v.kind !== kind) {
|
|
123
|
-
|
|
133
|
+
const detail = `Default export must be ${kind}(...); got ${v?.kind ?? typeof v}`;
|
|
134
|
+
if (missingConfig) {
|
|
135
|
+
configurationFailure(file, detail);
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
fail(file, detail, kind === 'work' ? 'WORK_INVALID' : 'WRONG_EXPORT');
|
|
124
139
|
return null;
|
|
125
140
|
}
|
|
126
141
|
return { ...v, file: relp(file) };
|
|
127
142
|
}
|
|
128
143
|
catch (e) {
|
|
129
|
-
|
|
144
|
+
const detail = e instanceof Error ? e.message : String(e);
|
|
145
|
+
if (missingConfig)
|
|
146
|
+
configurationFailure(file, detail);
|
|
147
|
+
else
|
|
148
|
+
fail(file, `Load failed: ${detail}`);
|
|
130
149
|
return null;
|
|
131
150
|
}
|
|
132
151
|
};
|
|
@@ -136,6 +155,8 @@ export async function loadAuthoring(root, importer) {
|
|
|
136
155
|
return { authoring: null, diagnostics: diags };
|
|
137
156
|
}
|
|
138
157
|
const config = await load(cfgFile, 'config');
|
|
158
|
+
if (!config && diags.some(d => d.code === 'PROJECT_MODULE_CONFIG'))
|
|
159
|
+
return { authoring: null, diagnostics: diags };
|
|
139
160
|
const layouts = {};
|
|
140
161
|
for (const f of list(join(r, 'layouts'))) {
|
|
141
162
|
if (!/\.(tsx|ts)$/.test(f))
|
|
@@ -172,22 +193,32 @@ export async function loadAuthoring(root, importer) {
|
|
|
172
193
|
fail(fd, `Feature directory ${fid} is missing feature.ts`, 'MISSING_FEATURE');
|
|
173
194
|
continue;
|
|
174
195
|
}
|
|
196
|
+
if (isDir(join(fd, 'options')))
|
|
197
|
+
fail(join(fd, 'options'), 'Rename this directory to works/ and migrate the authoring call to work({ title, summary })', 'OPTIONS_DIR_RENAMED');
|
|
175
198
|
const def = await load(ff, 'feature');
|
|
176
199
|
if (!def)
|
|
177
200
|
continue;
|
|
178
|
-
const
|
|
179
|
-
for (const o of list(join(fd, '
|
|
201
|
+
const works = {};
|
|
202
|
+
for (const o of list(join(fd, 'works'))) {
|
|
180
203
|
if (!/\.(tsx|ts)$/.test(o))
|
|
181
204
|
continue;
|
|
182
|
-
const v = await load(join(fd, '
|
|
205
|
+
const v = await load(join(fd, 'works', o), 'work');
|
|
183
206
|
if (v)
|
|
184
|
-
|
|
207
|
+
works[stem(o)] = v;
|
|
185
208
|
}
|
|
186
|
-
features[fid] = { def,
|
|
209
|
+
features[fid] = { def, works };
|
|
210
|
+
}
|
|
211
|
+
const works = {};
|
|
212
|
+
for (const f of list(join(r, 'works'))) {
|
|
213
|
+
if (!/\.(tsx|ts)$/.test(f) || isDir(join(r, 'works', f)))
|
|
214
|
+
continue;
|
|
215
|
+
const v = await load(join(r, 'works', f), 'work');
|
|
216
|
+
if (v)
|
|
217
|
+
works[stem(f)] = v;
|
|
187
218
|
}
|
|
188
219
|
if (!config)
|
|
189
220
|
return { authoring: null, diagnostics: diags };
|
|
190
221
|
const loc = loadLocales(r);
|
|
191
222
|
diags.push(...loc.diagnostics);
|
|
192
|
-
return { authoring: { root: r, config, layouts, routes, features, themes: loadThemes(r), ...(Object.keys(loc.files).length ? { locales: loc.locales, localeFiles: loc.files } : {}) }, diagnostics: diags };
|
|
223
|
+
return { authoring: { root: r, config, layouts, routes, features, ...(Object.keys(works).length ? { works } : {}), themes: loadThemes(r), ...(Object.keys(loc.files).length ? { locales: loc.locales, localeFiles: loc.files } : {}) }, diagnostics: diags };
|
|
193
224
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import crypto from 'node:crypto';
|
|
5
|
-
import { LOCAL_REVIEW_MAX_FILE_BYTES, LocalReviewId, LocalReviewSession } from "./local-review.js";
|
|
5
|
+
import { LOCAL_REVIEW_VERSION, LOCAL_REVIEW_MAX_FILE_BYTES, LocalReviewId, LocalReviewSession } from "./local-review.js";
|
|
6
6
|
import { JoploError } from "./result.js";
|
|
7
7
|
export const localReviewDir = (dir) => path.join(dir, '.joplo', 'reviews');
|
|
8
8
|
export function localReviewFile(dir, sessionId) {
|
|
@@ -29,15 +29,25 @@ export function writeLocalReview(file, value) {
|
|
|
29
29
|
fs.rmSync(tmp, { force: true });
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
|
-
|
|
32
|
+
function currentLocalReview(dir, sessionId) {
|
|
33
33
|
const file = localReviewFile(dir, sessionId);
|
|
34
34
|
if (fs.statSync(file).size > LOCAL_REVIEW_MAX_FILE_BYTES)
|
|
35
35
|
throw new JoploError('INVALID_SCHEMA', 'Local review file exceeds 16 MiB');
|
|
36
|
-
const
|
|
36
|
+
const value = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
37
|
+
// 只读版本号;不解释、不迁移旧记录,当前版本损坏仍照常报错。
|
|
38
|
+
if (value && typeof value === 'object' && 'v' in value && value.v !== LOCAL_REVIEW_VERSION)
|
|
39
|
+
return null;
|
|
40
|
+
const result = LocalReviewSession.safeParse(value);
|
|
37
41
|
if (!result.success || result.data.id !== sessionId || result.data.projectDir !== fs.realpathSync(dir))
|
|
38
42
|
throw new JoploError('INVALID_SCHEMA', `Invalid local review file: ${file}`);
|
|
39
43
|
return result.data;
|
|
40
44
|
}
|
|
45
|
+
export function readLocalReview(dir, sessionId) {
|
|
46
|
+
const session = currentLocalReview(dir, sessionId);
|
|
47
|
+
if (!session)
|
|
48
|
+
throw new JoploError('NOT_FOUND', 'This review session was created by an older version of Joplo; start a new review');
|
|
49
|
+
return session;
|
|
50
|
+
}
|
|
41
51
|
export function listLocalReviews(dir) {
|
|
42
52
|
let files;
|
|
43
53
|
try {
|
|
@@ -48,7 +58,10 @@ export function listLocalReviews(dir) {
|
|
|
48
58
|
return [];
|
|
49
59
|
throw e;
|
|
50
60
|
}
|
|
51
|
-
return files.filter(f => /^rv_[a-f0-9]{32}\.json$/.test(f)).
|
|
61
|
+
return files.filter(f => /^rv_[a-f0-9]{32}\.json$/.test(f)).flatMap(f => {
|
|
62
|
+
const session = currentLocalReview(dir, f.slice(0, -5));
|
|
63
|
+
return session ? [session] : [];
|
|
64
|
+
})
|
|
52
65
|
.sort((a, b) => b.createdAt.localeCompare(a.createdAt));
|
|
53
66
|
}
|
|
54
67
|
export function localReviewOwnerAlive(session) {
|
package/dist/local-review.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/** 本地评审的持久化契约。浏览器、服务端和 CLI 共用;不依赖 Node。 */
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
+
export declare const LOCAL_REVIEW_VERSION: 2;
|
|
3
4
|
export declare const LOCAL_REVIEW_MAX_BODY = 10000;
|
|
4
5
|
export declare const LOCAL_REVIEW_MAX_EVENTS = 1000;
|
|
5
6
|
export declare const LOCAL_REVIEW_MAX_FILE_BYTES: number;
|
|
@@ -49,7 +50,7 @@ export declare const LocalReviewEvent: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
49
50
|
reason: z.ZodEnum<{
|
|
50
51
|
source_changed: "source_changed";
|
|
51
52
|
compile_error: "compile_error";
|
|
52
|
-
|
|
53
|
+
work_removed: "work_removed";
|
|
53
54
|
server_stopped: "server_stopped";
|
|
54
55
|
}>;
|
|
55
56
|
sessionId: z.ZodString;
|
|
@@ -59,17 +60,17 @@ export declare const LocalReviewEvent: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
59
60
|
}, z.core.$strict>], "type">;
|
|
60
61
|
export type LocalReviewEvent = z.infer<typeof LocalReviewEvent>;
|
|
61
62
|
export declare const LocalReviewSession: z.ZodObject<{
|
|
62
|
-
v: z.ZodLiteral<
|
|
63
|
+
v: z.ZodLiteral<2>;
|
|
63
64
|
id: z.ZodString;
|
|
64
65
|
instanceId: z.ZodString;
|
|
65
66
|
ownerPid: z.ZodNumber;
|
|
66
67
|
projectId: z.ZodString;
|
|
67
68
|
projectDir: z.ZodString;
|
|
68
69
|
projectName: z.ZodString;
|
|
69
|
-
featureId: z.ZodString
|
|
70
|
-
featureName: z.ZodString
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
featureId: z.ZodNullable<z.ZodString>;
|
|
71
|
+
featureName: z.ZodNullable<z.ZodString>;
|
|
72
|
+
workId: z.ZodString;
|
|
73
|
+
workTitle: z.ZodString;
|
|
73
74
|
revision: z.ZodString;
|
|
74
75
|
createdAt: z.ZodISODateTime;
|
|
75
76
|
url: z.ZodString;
|
|
@@ -101,7 +102,7 @@ export declare const LocalReviewSession: z.ZodObject<{
|
|
|
101
102
|
reason: z.ZodEnum<{
|
|
102
103
|
source_changed: "source_changed";
|
|
103
104
|
compile_error: "compile_error";
|
|
104
|
-
|
|
105
|
+
work_removed: "work_removed";
|
|
105
106
|
server_stopped: "server_stopped";
|
|
106
107
|
}>;
|
|
107
108
|
sessionId: z.ZodString;
|
package/dist/local-review.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/** 本地评审的持久化契约。浏览器、服务端和 CLI 共用;不依赖 Node。 */
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
+
export const LOCAL_REVIEW_VERSION = 2;
|
|
3
4
|
export const LOCAL_REVIEW_MAX_BODY = 10_000;
|
|
4
5
|
export const LOCAL_REVIEW_MAX_EVENTS = 1000;
|
|
5
6
|
export const LOCAL_REVIEW_MAX_FILE_BYTES = 16 * 1024 * 1024;
|
|
@@ -26,20 +27,20 @@ const eventBase = {
|
|
|
26
27
|
export const LocalReviewEvent = z.discriminatedUnion('type', [
|
|
27
28
|
z.strictObject({ ...eventBase, type: z.literal('feedback'), body: z.string().trim().min(1).max(LOCAL_REVIEW_MAX_BODY), context: LocalReviewContext }),
|
|
28
29
|
z.strictObject({ ...eventBase, type: z.literal('approved') }),
|
|
29
|
-
z.strictObject({ ...eventBase, type: z.literal('closed'), reason: z.enum(['source_changed', 'compile_error', '
|
|
30
|
+
z.strictObject({ ...eventBase, type: z.literal('closed'), reason: z.enum(['source_changed', 'compile_error', 'work_removed', 'server_stopped']) }),
|
|
30
31
|
]);
|
|
31
32
|
export const LocalReviewSession = z.strictObject({
|
|
32
|
-
v: z.literal(
|
|
33
|
+
v: z.literal(LOCAL_REVIEW_VERSION),
|
|
33
34
|
id: LocalReviewId,
|
|
34
35
|
instanceId: z.string().uuid(),
|
|
35
36
|
ownerPid: z.number().int().positive(),
|
|
36
37
|
projectId: ref,
|
|
37
38
|
projectDir: z.string().min(1),
|
|
38
39
|
projectName: z.string(),
|
|
39
|
-
featureId: ref,
|
|
40
|
-
featureName: z.string(),
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
featureId: ref.nullable(),
|
|
41
|
+
featureName: z.string().nullable(),
|
|
42
|
+
workId: ref,
|
|
43
|
+
workTitle: z.string(),
|
|
43
44
|
revision: z.string().regex(/^[a-f0-9]{64}$/),
|
|
44
45
|
createdAt: z.iso.datetime(),
|
|
45
46
|
url: z.string().url(),
|
package/dist/outline.d.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* 大纲(D67,`joplo outline`):不看看板也能检查一个演示“讲给谁、讲什么、讲多久”。只读现有 IR,不新增作者概念:
|
|
3
|
+
* - 功能:goal(解决什么)、roles(给谁,旧的名字数组也算)、cases(PM 的验收条件:维度、优先级、expected = Then)与每个方案的覆盖;
|
|
4
|
+
* - 方案与场景:步数、估算时长(与自动播放同一份 stepDwell)、是否以过渡卡开场 / 收尾、结局、覆盖的情况。
|
|
5
|
+
* 估算按 1× 速度、用 IR 里的英文字幕兜底,不含鼠标移动与逐字输入,所以只是“约”。
|
|
6
|
+
*/
|
|
7
|
+
import { type Entry } from './entries.js';
|
|
8
|
+
import type { Coverage, Project, Scenario } from './schema.js';
|
|
2
9
|
export type OutlineCase = {
|
|
3
10
|
id: string;
|
|
4
11
|
key: string;
|
|
@@ -25,34 +32,35 @@ export type OutlineScenario = {
|
|
|
25
32
|
outcome: Scenario['mock']['outcome'];
|
|
26
33
|
caseIds: string[];
|
|
27
34
|
};
|
|
28
|
-
export type
|
|
35
|
+
export type OutlineWork = {
|
|
29
36
|
id: string;
|
|
30
37
|
key: string;
|
|
31
|
-
|
|
38
|
+
title: string;
|
|
32
39
|
picked: boolean;
|
|
33
40
|
ms: number;
|
|
34
41
|
missing: number;
|
|
35
42
|
undecided: number;
|
|
36
43
|
scenarios: OutlineScenario[];
|
|
37
44
|
};
|
|
38
|
-
export type
|
|
45
|
+
export type OutlineEntry = {
|
|
46
|
+
featureId: string | null;
|
|
47
|
+
sequencing: Entry['sequencing'];
|
|
48
|
+
draft: boolean;
|
|
39
49
|
id: string;
|
|
40
|
-
|
|
41
|
-
|
|
50
|
+
title: string;
|
|
51
|
+
summary: string;
|
|
42
52
|
roles: string[];
|
|
43
53
|
pick: string | null;
|
|
44
54
|
cases: OutlineCase[];
|
|
45
|
-
|
|
55
|
+
works: OutlineWork[];
|
|
46
56
|
};
|
|
47
57
|
export type Outline = {
|
|
48
58
|
name: string;
|
|
49
59
|
mode: Project['mode'];
|
|
50
|
-
|
|
60
|
+
entries: OutlineEntry[];
|
|
51
61
|
};
|
|
52
|
-
/**
|
|
53
|
-
export declare function
|
|
54
|
-
/** 一个场景按 1× 自动播放大约多久(毫秒):每一步取 hold、阅读停留(stepDwell)与旁白朗读估算(narrate / say)中最长的,再求和。 */
|
|
55
|
-
export declare function scenarioEstimateMs(scenario: Pick<Scenario, 'steps'>): number;
|
|
62
|
+
/** 一个场景按 1× 自动播放大约多久(毫秒):每一步的时间计划(stepPlan:操作演示 + 停留与朗读估算中较长者)之和。 */
|
|
63
|
+
export declare function scenarioEstimateMs(project: Pick<Project, 'plugins'>, scenario: Pick<Scenario, 'steps'>): number;
|
|
56
64
|
export declare function outline(project: Project, opts?: {
|
|
57
|
-
|
|
65
|
+
workId?: string;
|
|
58
66
|
}): Outline;
|
package/dist/outline.js
CHANGED
|
@@ -4,69 +4,65 @@
|
|
|
4
4
|
* - 方案与场景:步数、估算时长(与自动播放同一份 stepDwell)、是否以过渡卡开场 / 收尾、结局、覆盖的情况。
|
|
5
5
|
* 估算按 1× 速度、用 IR 里的英文字幕兜底,不含鼠标移动与逐字输入,所以只是“约”。
|
|
6
6
|
*/
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { stepDwell, voiceMs } from "./pace.js";
|
|
7
|
+
import { entriesOf, scenariosOf, sliceKey } from "./entries.js";
|
|
8
|
+
import { scenarioPlanMs } from "./step-plan.js";
|
|
10
9
|
import { JoploError } from "./result.js";
|
|
11
|
-
/**
|
|
12
|
-
export function
|
|
13
|
-
return
|
|
14
|
-
}
|
|
15
|
-
/** 一个场景按 1× 自动播放大约多久(毫秒):每一步取 hold、阅读停留(stepDwell)与旁白朗读估算(narrate / say)中最长的,再求和。 */
|
|
16
|
-
export function scenarioEstimateMs(scenario) {
|
|
17
|
-
return scenario.steps.reduce((sum, step) => sum + Math.max(holdMsOf(step), voiceMs(step.narrate ?? step.say), stepDwell({ texts: stepTexts(step), paced: step.hold !== undefined, cameraMoved: step.shots.length > 0 || !!step.directorLayer, streams: step.effects.flatMap((e) => (e.type === 'stream' ? [e.value] : [])) })), 0);
|
|
10
|
+
/** 一个场景按 1× 自动播放大约多久(毫秒):每一步的时间计划(stepPlan:操作演示 + 停留与朗读估算中较长者)之和。 */
|
|
11
|
+
export function scenarioEstimateMs(project, scenario) {
|
|
12
|
+
return scenarioPlanMs(project, scenario.steps);
|
|
18
13
|
}
|
|
19
14
|
export function outline(project, opts = {}) {
|
|
20
|
-
if (opts.
|
|
21
|
-
throw new JoploError('USAGE', `
|
|
22
|
-
const only = opts.
|
|
23
|
-
const
|
|
24
|
-
for (const
|
|
25
|
-
if (only &&
|
|
15
|
+
if (opts.workId && !Object.hasOwn(project.works, opts.workId))
|
|
16
|
+
throw new JoploError('USAGE', `Work does not exist: ${opts.workId}`);
|
|
17
|
+
const only = opts.workId ? project.works[opts.workId].featureId ?? opts.workId : null;
|
|
18
|
+
const entries = [];
|
|
19
|
+
for (const entry of entriesOf(project)) {
|
|
20
|
+
if (only && entry.id !== only)
|
|
26
21
|
continue;
|
|
27
|
-
const
|
|
28
|
-
const
|
|
22
|
+
const f = entry.featureId ? project.features[entry.featureId] : undefined;
|
|
23
|
+
const workIds = (f ? f.workIds : entry.workId ? [entry.workId] : []).filter(id => project.works[id] && (!opts.workId || id === opts.workId));
|
|
24
|
+
const cases = (f?.caseIds ?? []).flatMap((cid) => {
|
|
29
25
|
const c = project.cases[cid];
|
|
30
26
|
if (!c)
|
|
31
27
|
return [];
|
|
32
28
|
const coverage = {};
|
|
33
|
-
for (const oid of
|
|
34
|
-
const cov =
|
|
29
|
+
for (const oid of workIds) {
|
|
30
|
+
const cov = f?.alternatives[oid]?.coverage[cid];
|
|
35
31
|
if (cov)
|
|
36
32
|
coverage[oid] = cov.status;
|
|
37
33
|
}
|
|
38
34
|
return [{ id: c.id, key: c.id.slice(f.id.length + 1), title: c.title, dimension: c.dimension, priority: c.priority, expected: c.expected, coverage }];
|
|
39
35
|
});
|
|
40
|
-
const
|
|
41
|
-
const o = project.
|
|
42
|
-
const scenarios =
|
|
43
|
-
.filter((s) => s.optionId === oid)
|
|
36
|
+
const works = workIds.map((oid) => {
|
|
37
|
+
const o = project.works[oid];
|
|
38
|
+
const scenarios = scenariosOf(project, oid)
|
|
44
39
|
.map((s) => ({
|
|
45
40
|
id: s.id,
|
|
46
|
-
key: s
|
|
41
|
+
key: sliceKey(s),
|
|
47
42
|
name: s.name,
|
|
48
43
|
description: s.description,
|
|
49
44
|
steps: s.steps.length,
|
|
50
|
-
ms: scenarioEstimateMs(s),
|
|
45
|
+
ms: scenarioEstimateMs(project, s),
|
|
51
46
|
cards: s.steps.filter((st) => st.action.type === 'card').length,
|
|
52
47
|
opening: s.steps[0]?.action.type === 'card',
|
|
53
48
|
ending: s.steps.length > 0 && s.steps.at(-1).action.type === 'card',
|
|
54
49
|
outcome: s.mock.outcome,
|
|
55
50
|
caseIds: s.caseIds,
|
|
56
51
|
}));
|
|
57
|
-
const statuses = Object.values(
|
|
52
|
+
const statuses = Object.values(f?.alternatives[oid]?.coverage ?? {}).map((c) => c.status);
|
|
58
53
|
return {
|
|
59
54
|
id: oid,
|
|
60
55
|
key: o.key,
|
|
61
|
-
|
|
62
|
-
picked: f.pick === oid,
|
|
56
|
+
title: o.title,
|
|
57
|
+
picked: !f || f.pick === oid,
|
|
63
58
|
ms: scenarios.reduce((n, s) => n + s.ms, 0),
|
|
64
59
|
missing: statuses.filter((s) => s === 'missing').length,
|
|
65
60
|
undecided: statuses.filter((s) => s === 'undecided').length,
|
|
66
61
|
scenarios,
|
|
67
62
|
};
|
|
68
63
|
});
|
|
69
|
-
|
|
64
|
+
// Entry.workId may be a preview default; a feature decision must preserve its null pick.
|
|
65
|
+
entries.push({ featureId: entry.featureId, sequencing: entry.sequencing, draft: entry.draft, id: entry.id, title: entry.title, summary: entry.summary, roles: entry.roles, pick: f ? f.pick : entry.workId, cases, works });
|
|
70
66
|
}
|
|
71
|
-
return { name: project.name, mode: project.mode,
|
|
67
|
+
return { name: project.name, mode: project.mode, entries };
|
|
72
68
|
}
|
package/dist/pace.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 自动播放的阅读节奏(T-director2,纯函数):演示页、发布站、视频录制、`joplo outline` 与 check 共用这一份。
|
|
3
3
|
* - 阅读:说明 + 解说,中文每秒 8 字、拉丁文字每秒 15 个非空白字符,3–7 秒,再按速度缩放;
|
|
4
|
-
* - 同时至少等到镜头过渡结束(CAMERA_MS
|
|
4
|
+
* - 同时至少等到镜头过渡结束(CAMERA_MS)。插件画面里更长的动画(连线上的小点、逐字打代码、片段)由插件效果的 holdMs 声明,不在这里。
|
|
5
5
|
* 2026-11-06(D67)从 web 的 runtime/pace.ts 搬到 core,web 原地 re-export,数值与行为不变。
|
|
6
6
|
*/
|
|
7
7
|
export declare const MS_PER_CHAR = 125;
|
|
@@ -24,14 +24,14 @@ export declare function readingMs(...texts: (string | null | undefined)[]): numb
|
|
|
24
24
|
export declare function rawReadingMs(...texts: (string | null | undefined)[]): number;
|
|
25
25
|
/**
|
|
26
26
|
* 这一步提交之后至少停留多久(毫秒)。
|
|
27
|
-
*
|
|
27
|
+
* texts:说明与解说;cameraMoved:这一步镜头有变化(切层或换焦点)。
|
|
28
28
|
*/
|
|
29
29
|
export declare function stepDwell(o: {
|
|
30
30
|
texts: (string | null | undefined)[];
|
|
31
31
|
speed?: number;
|
|
32
|
-
cameraMoved?: boolean;
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
cameraMoved?: boolean; /** 本步流式输出的文字(D56):等它们出完再加阅读时间。 */
|
|
33
|
+
streams?: string[]; /** 已经算好的流式输出时长(1×,见 player 的 streamPlan,D100):给了就用它,不再按 streams 的字数算。 */
|
|
34
|
+
streamMs?: number; /** 作者写了 hold(D92):节奏由作者掌握,阅读时间不套 3 秒下限(仍按字数)。 */
|
|
35
35
|
paced?: boolean;
|
|
36
36
|
}): number;
|
|
37
37
|
/** 朗读估算(旁白 / 台词):中日韩约每秒 4.5 字、拉丁文字约每秒 13 个非空白字符(约 2.5 词),读完再留 0.45 秒换气。 */
|
|
@@ -39,3 +39,8 @@ export declare const VOICE_CJK_MS = 220;
|
|
|
39
39
|
export declare const VOICE_LATIN_MS = 75;
|
|
40
40
|
/** 一段旁白大约读多久(毫秒,1×);没有文字时为 0。自动播放以真实读完为准,这个只用于封面、outline 与 check 的估算。 */
|
|
41
41
|
export declare function voiceMs(text: string | null | undefined, speed?: number): number;
|
|
42
|
+
/**
|
|
43
|
+
* 跟着朗读出字(stream pace: 'voice',D100):一句话读完大约要多久(1×,不含换气),整段至少 STREAM_MIN。
|
|
44
|
+
* 用 voiceMs 的同一套估算,所以没开声音、或声音还没生成时,字出完的时间也和朗读估算一致。
|
|
45
|
+
*/
|
|
46
|
+
export declare function voicePacedMs(line: string | null | undefined): number;
|
package/dist/pace.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 自动播放的阅读节奏(T-director2,纯函数):演示页、发布站、视频录制、`joplo outline` 与 check 共用这一份。
|
|
3
3
|
* - 阅读:说明 + 解说,中文每秒 8 字、拉丁文字每秒 15 个非空白字符,3–7 秒,再按速度缩放;
|
|
4
|
-
* - 同时至少等到镜头过渡结束(CAMERA_MS
|
|
4
|
+
* - 同时至少等到镜头过渡结束(CAMERA_MS)。插件画面里更长的动画(连线上的小点、逐字打代码、片段)由插件效果的 holdMs 声明,不在这里。
|
|
5
5
|
* 2026-11-06(D67)从 web 的 runtime/pace.ts 搬到 core,web 原地 re-export,数值与行为不变。
|
|
6
6
|
*/
|
|
7
7
|
export const MS_PER_CHAR = 125;
|
|
@@ -51,17 +51,16 @@ export function rawReadingMs(...texts) {
|
|
|
51
51
|
}
|
|
52
52
|
/**
|
|
53
53
|
* 这一步提交之后至少停留多久(毫秒)。
|
|
54
|
-
*
|
|
54
|
+
* texts:说明与解说;cameraMoved:这一步镜头有变化(切层或换焦点)。
|
|
55
55
|
*/
|
|
56
56
|
export function stepDwell(o) {
|
|
57
57
|
const speed = o.speed && o.speed > 0 ? o.speed : 1;
|
|
58
58
|
const read = (o.paced ? rawReadingMs(...o.texts) : readingMs(...o.texts)) / speed;
|
|
59
59
|
const cam = o.cameraMoved ? CAMERA_MS + SETTLE : 0;
|
|
60
|
-
const dots = o.dotMs && o.dotMs > 0 ? o.dotMs + SETTLE : 0;
|
|
61
60
|
// 流式输出:先等最长的一段出完,再留出读完它的时间(按出完之后再读一遍的一半计)
|
|
62
|
-
const longest = Math.max(0, ...(o.streams ?? []).map((t) => streamMs(t, speed)));
|
|
61
|
+
const longest = o.streamMs !== undefined ? Math.round(o.streamMs / speed) : Math.max(0, ...(o.streams ?? []).map((t) => streamMs(t, speed)));
|
|
63
62
|
const streamed = longest ? longest + Math.max((o.paced ? 0 : MIN_DWELL) / speed, read / 2) : 0;
|
|
64
|
-
return Math.round(Math.max(read, cam,
|
|
63
|
+
return Math.round(Math.max(read, cam, streamed));
|
|
65
64
|
}
|
|
66
65
|
/** 朗读估算(旁白 / 台词):中日韩约每秒 4.5 字、拉丁文字约每秒 13 个非空白字符(约 2.5 词),读完再留 0.45 秒换气。 */
|
|
67
66
|
export const VOICE_CJK_MS = 220;
|
|
@@ -79,3 +78,11 @@ export function voiceMs(text, speed = 1) {
|
|
|
79
78
|
}
|
|
80
79
|
return ms ? Math.round((ms + VOICE_EST_BREATH_MS) / (speed > 0 ? speed : 1)) : 0;
|
|
81
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* 跟着朗读出字(stream pace: 'voice',D100):一句话读完大约要多久(1×,不含换气),整段至少 STREAM_MIN。
|
|
83
|
+
* 用 voiceMs 的同一套估算,所以没开声音、或声音还没生成时,字出完的时间也和朗读估算一致。
|
|
84
|
+
*/
|
|
85
|
+
export function voicePacedMs(line) {
|
|
86
|
+
const ms = voiceMs(line);
|
|
87
|
+
return ms ? Math.max(STREAM_MIN, ms - VOICE_EST_BREATH_MS) : 0;
|
|
88
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { Project, Scenario, SceneNode, Step } from './schema.js';
|
|
2
|
+
import { JoploError, type Diagnostic } from './result.js';
|
|
3
|
+
import { type PlayState } from './scene-query.js';
|
|
4
|
+
export declare function initialState(project: Project, scenarioId: string): PlayState;
|
|
5
|
+
export declare class PlaybackError extends JoploError {
|
|
6
|
+
constructor(message: string, diagnostic: Diagnostic);
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* 校验当前步骤能否在给定状态下执行;返回诊断(null 表示可执行)。
|
|
10
|
+
* 手动体验时,UI 也用它判断用户点击的是不是“当前步骤的目标”。
|
|
11
|
+
*/
|
|
12
|
+
export declare function checkStep(project: Project, scenario: Scenario, state: PlayState, step: Step): Diagnostic | null;
|
|
13
|
+
/** 执行 scenario.steps[state.position],返回新状态(不修改入参)。 */
|
|
14
|
+
export declare function applyStep(project: Project, scenario: Scenario, state: PlayState): PlayState;
|
|
15
|
+
/** 从初始状态重放到指定位置,不读也不写缓存。编译器在 IR 还没定稿(之后还会改场景的初始状态)时用它。 */
|
|
16
|
+
export declare function replayTo(project: Project, scenarioId: string, position: number): PlayState;
|
|
17
|
+
/** 挂在同一条时间线上的派生结果(例如每个位置的镜头):与状态一起缓存、一起作废。 */
|
|
18
|
+
export declare function timelineMemo<T>(project: Project, sc: Scenario, key: string, compute: () => T): T;
|
|
19
|
+
/** 时间线上第 position 步之后的状态(共享对象,调用方不得修改);这一步或之前的步骤回放失败时抛出当时的错误。 */
|
|
20
|
+
export declare function timelineState(project: Project, sc: Scenario, position: number): PlayState;
|
|
21
|
+
/** 第 position 步之后的状态(从时间线缓存取,返回独立副本)。 */
|
|
22
|
+
export declare function stateAt(project: Project, scenarioId: string, position: number): PlayState;
|
|
23
|
+
/** 时间线上每个位置的状态(0..步数);回放失败之后的位置为 null。共享对象,只读。 */
|
|
24
|
+
export declare function timelineStates(project: Project, scenarioId: string): (PlayState | null)[];
|
|
25
|
+
/** 步骤 ID → 该步骤执行之后的位置。 */
|
|
26
|
+
export declare function positionAfterStep(project: Project, scenarioId: string, stepId: string): number;
|
|
27
|
+
/** 完整回放一个场景,收集诊断而不抛出。供校验器使用。 */
|
|
28
|
+
export declare function replay(project: Project, scenarioId: string): {
|
|
29
|
+
finalState: PlayState | null;
|
|
30
|
+
reached: number;
|
|
31
|
+
diagnostics: Diagnostic[];
|
|
32
|
+
};
|
|
33
|
+
export type ClickVerdict = {
|
|
34
|
+
kind: 'advance';
|
|
35
|
+
} | {
|
|
36
|
+
kind: 'disabled';
|
|
37
|
+
reason: string | null;
|
|
38
|
+
} | {
|
|
39
|
+
kind: 'unmodeled';
|
|
40
|
+
label: string;
|
|
41
|
+
} | {
|
|
42
|
+
kind: 'out_of_order';
|
|
43
|
+
label: string;
|
|
44
|
+
expectedCaption: string | null;
|
|
45
|
+
} | {
|
|
46
|
+
kind: 'not_covered';
|
|
47
|
+
label: string;
|
|
48
|
+
} | {
|
|
49
|
+
kind: 'static';
|
|
50
|
+
};
|
|
51
|
+
/** 禁用原因的当前文字:字面量原样返回;绑定(`$ui.x`)读当前状态;空或不是文字时为 null(界面用默认说明)。 */
|
|
52
|
+
export declare function disabledReasonOf(node: SceneNode, state: Pick<PlayState, 'ui' | 'data' | 'inputs'>): string | null;
|
|
53
|
+
/**
|
|
54
|
+
* 演示模式下用户点击了某个元素:判断应推进步骤,还是提示“当前演示未覆盖”(PRD 8.2、AC-19)。
|
|
55
|
+
* 流程外点击绝不能被解释为成功。
|
|
56
|
+
*/
|
|
57
|
+
export declare function explainClick(project: Project, state: PlayState, nodeId: string, sceneId?: string): ClickVerdict;
|