automovie 0.0.0 → 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.
Files changed (160) hide show
  1. package/README.md +145 -18
  2. package/lib/AUTOMOVIE_CAPTURE_OPTIONS.d.ts +6 -0
  3. package/lib/AUTOMOVIE_CAPTURE_OPTIONS.js +16 -0
  4. package/lib/AUTOMOVIE_CAPTURE_OPTIONS.js.map +1 -0
  5. package/lib/AUTOMOVIE_INSPECT_OPTIONS.d.ts +6 -0
  6. package/lib/AUTOMOVIE_INSPECT_OPTIONS.js +14 -0
  7. package/lib/AUTOMOVIE_INSPECT_OPTIONS.js.map +1 -0
  8. package/lib/AUTOMOVIE_RENDER_OPTIONS.d.ts +6 -0
  9. package/lib/AUTOMOVIE_RENDER_OPTIONS.js +15 -0
  10. package/lib/AUTOMOVIE_RENDER_OPTIONS.js.map +1 -0
  11. package/lib/AUTOMOVIE_REVIEW_OPTIONS.d.ts +6 -0
  12. package/lib/AUTOMOVIE_REVIEW_OPTIONS.js +14 -0
  13. package/lib/AUTOMOVIE_REVIEW_OPTIONS.js.map +1 -0
  14. package/lib/AutoMovieCaptureBackend.d.ts +9 -0
  15. package/lib/{IAutoMoviePackageManager.js → AutoMovieCaptureBackend.js} +1 -1
  16. package/lib/AutoMovieCaptureBackend.js.map +1 -0
  17. package/lib/AutoMovieCaptureHost.d.ts +114 -0
  18. package/lib/AutoMovieCaptureHost.js +219 -0
  19. package/lib/AutoMovieCaptureHost.js.map +1 -0
  20. package/lib/AutoMovieCommand.d.ts +24 -13
  21. package/lib/IAutoMovieChromium.d.ts +75 -0
  22. package/lib/IAutoMovieChromium.js +3 -0
  23. package/lib/IAutoMovieChromium.js.map +1 -0
  24. package/lib/captureAutoMovie.d.ts +23 -0
  25. package/lib/captureAutoMovie.js +133 -0
  26. package/lib/captureAutoMovie.js.map +1 -0
  27. package/lib/deriveAutoMovieProjectName.d.ts +1 -1
  28. package/lib/deriveAutoMovieProjectName.js +1 -1
  29. package/lib/findAutoMovieFreePort.d.ts +14 -0
  30. package/lib/findAutoMovieFreePort.js +61 -0
  31. package/lib/findAutoMovieFreePort.js.map +1 -0
  32. package/lib/formatAutoMovieInspectUrl.d.ts +14 -0
  33. package/lib/formatAutoMovieInspectUrl.js +24 -0
  34. package/lib/formatAutoMovieInspectUrl.js.map +1 -0
  35. package/lib/index.d.ts +30 -2
  36. package/lib/index.js +30 -2
  37. package/lib/index.js.map +1 -1
  38. package/lib/inspectAutoMovie.d.ts +19 -0
  39. package/lib/inspectAutoMovie.js +97 -0
  40. package/lib/inspectAutoMovie.js.map +1 -0
  41. package/lib/launchAutoMovieChromium.d.ts +28 -0
  42. package/lib/launchAutoMovieChromium.js +42 -0
  43. package/lib/launchAutoMovieChromium.js.map +1 -0
  44. package/lib/loadAutoMovieProductionModule.d.ts +14 -0
  45. package/lib/loadAutoMovieProductionModule.js +61 -0
  46. package/lib/loadAutoMovieProductionModule.js.map +1 -0
  47. package/lib/planAutoMovieChromiumLaunch.d.ts +27 -0
  48. package/lib/planAutoMovieChromiumLaunch.js +34 -0
  49. package/lib/planAutoMovieChromiumLaunch.js.map +1 -0
  50. package/lib/planAutoMovieModulePageViteConfig.d.ts +37 -0
  51. package/lib/planAutoMovieModulePageViteConfig.js +27 -0
  52. package/lib/planAutoMovieModulePageViteConfig.js.map +1 -0
  53. package/lib/readAutoMovieAddArguments.d.ts +1 -1
  54. package/lib/readAutoMovieAddArguments.js +1 -1
  55. package/lib/readAutoMovieCaptureHostOptions.d.ts +36 -0
  56. package/lib/readAutoMovieCaptureHostOptions.js +57 -0
  57. package/lib/readAutoMovieCaptureHostOptions.js.map +1 -0
  58. package/lib/readAutoMovieCommandArguments.d.ts +1 -1
  59. package/lib/readAutoMovieCommandArguments.js +10 -5
  60. package/lib/readAutoMovieCommandArguments.js.map +1 -1
  61. package/lib/readAutoMovieCreateArguments.d.ts +1 -1
  62. package/lib/readAutoMovieCreateArguments.js +1 -1
  63. package/lib/readAutoMovieInspectHostOptions.d.ts +29 -0
  64. package/lib/readAutoMovieInspectHostOptions.js +48 -0
  65. package/lib/readAutoMovieInspectHostOptions.js.map +1 -0
  66. package/lib/readAutoMovieRenderOptions.d.ts +33 -0
  67. package/lib/readAutoMovieRenderOptions.js +51 -0
  68. package/lib/readAutoMovieRenderOptions.js.map +1 -0
  69. package/lib/readAutoMovieReviewOptions.d.ts +27 -0
  70. package/lib/readAutoMovieReviewOptions.js +54 -0
  71. package/lib/readAutoMovieReviewOptions.js.map +1 -0
  72. package/lib/readAutoMovieRevision.d.ts +12 -0
  73. package/lib/readAutoMovieRevision.js +32 -0
  74. package/lib/readAutoMovieRevision.js.map +1 -0
  75. package/lib/readAutoMovieVideoProbe.d.ts +23 -0
  76. package/lib/readAutoMovieVideoProbe.js +39 -0
  77. package/lib/readAutoMovieVideoProbe.js.map +1 -0
  78. package/lib/recordAutoMoviePlayback.d.ts +37 -0
  79. package/lib/recordAutoMoviePlayback.js +122 -0
  80. package/lib/recordAutoMoviePlayback.js.map +1 -0
  81. package/lib/renderAutoMovie.d.ts +21 -0
  82. package/lib/renderAutoMovie.js +95 -0
  83. package/lib/renderAutoMovie.js.map +1 -0
  84. package/lib/renderAutoMovieScaffoldNextSteps.d.ts +3 -5
  85. package/lib/renderAutoMovieScaffoldNextSteps.js +5 -14
  86. package/lib/renderAutoMovieScaffoldNextSteps.js.map +1 -1
  87. package/lib/renderAutoMovieVideo.d.ts +35 -0
  88. package/lib/renderAutoMovieVideo.js +110 -0
  89. package/lib/renderAutoMovieVideo.js.map +1 -0
  90. package/lib/resolveAutoMovieFfmpeg.d.ts +19 -0
  91. package/lib/resolveAutoMovieFfmpeg.js +32 -0
  92. package/lib/resolveAutoMovieFfmpeg.js.map +1 -0
  93. package/lib/reviewAutoMovie.d.ts +21 -0
  94. package/lib/reviewAutoMovie.js +71 -0
  95. package/lib/reviewAutoMovie.js.map +1 -0
  96. package/lib/run.d.ts +14 -11
  97. package/lib/run.js +103 -67
  98. package/lib/run.js.map +1 -1
  99. package/lib/runAutoMovieFfmpeg.d.ts +14 -0
  100. package/lib/runAutoMovieFfmpeg.js +40 -0
  101. package/lib/runAutoMovieFfmpeg.js.map +1 -0
  102. package/lib/serveAutoMovieDrawPage.d.ts +28 -0
  103. package/lib/serveAutoMovieDrawPage.js +108 -0
  104. package/lib/serveAutoMovieDrawPage.js.map +1 -0
  105. package/lib/serveAutoMovieInspectorPage.d.ts +32 -0
  106. package/lib/serveAutoMovieInspectorPage.js +52 -0
  107. package/lib/serveAutoMovieInspectorPage.js.map +1 -0
  108. package/lib/writeAutoMovieModulePage.d.ts +38 -0
  109. package/lib/writeAutoMovieModulePage.js +75 -0
  110. package/lib/writeAutoMovieModulePage.js.map +1 -0
  111. package/package.json +27 -6
  112. package/src/AUTOMOVIE_CAPTURE_OPTIONS.ts +12 -0
  113. package/src/AUTOMOVIE_INSPECT_OPTIONS.ts +10 -0
  114. package/src/AUTOMOVIE_RENDER_OPTIONS.ts +11 -0
  115. package/src/AUTOMOVIE_REVIEW_OPTIONS.ts +10 -0
  116. package/src/AutoMovieCaptureBackend.ts +9 -0
  117. package/src/AutoMovieCaptureHost.ts +245 -0
  118. package/src/AutoMovieCommand.ts +28 -13
  119. package/src/IAutoMovieChromium.ts +78 -0
  120. package/src/captureAutoMovie.ts +148 -0
  121. package/src/deriveAutoMovieProjectName.ts +1 -1
  122. package/src/findAutoMovieFreePort.ts +27 -0
  123. package/src/formatAutoMovieInspectUrl.ts +25 -0
  124. package/src/index.ts +30 -2
  125. package/src/inspectAutoMovie.ts +81 -0
  126. package/src/launchAutoMovieChromium.ts +61 -0
  127. package/src/loadAutoMovieProductionModule.ts +30 -0
  128. package/src/planAutoMovieChromiumLaunch.ts +45 -0
  129. package/src/planAutoMovieModulePageViteConfig.ts +53 -0
  130. package/src/readAutoMovieAddArguments.ts +1 -1
  131. package/src/readAutoMovieCaptureHostOptions.ts +76 -0
  132. package/src/readAutoMovieCommandArguments.ts +6 -4
  133. package/src/readAutoMovieCreateArguments.ts +1 -1
  134. package/src/readAutoMovieInspectHostOptions.ts +66 -0
  135. package/src/readAutoMovieRenderOptions.ts +67 -0
  136. package/src/readAutoMovieReviewOptions.ts +70 -0
  137. package/src/readAutoMovieRevision.ts +29 -0
  138. package/src/readAutoMovieVideoProbe.ts +55 -0
  139. package/src/recordAutoMoviePlayback.ts +168 -0
  140. package/src/renderAutoMovie.ts +86 -0
  141. package/src/renderAutoMovieScaffoldNextSteps.ts +4 -18
  142. package/src/renderAutoMovieVideo.ts +127 -0
  143. package/src/resolveAutoMovieFfmpeg.ts +33 -0
  144. package/src/reviewAutoMovie.ts +65 -0
  145. package/src/run.ts +116 -105
  146. package/src/runAutoMovieFfmpeg.ts +50 -0
  147. package/src/serveAutoMovieDrawPage.ts +105 -0
  148. package/src/serveAutoMovieInspectorPage.ts +82 -0
  149. package/src/writeAutoMovieModulePage.ts +83 -0
  150. package/lib/IAutoMoviePackageManager.d.ts +0 -14
  151. package/lib/IAutoMoviePackageManager.js.map +0 -1
  152. package/lib/readAutoMovieSyncArguments.d.ts +0 -13
  153. package/lib/readAutoMovieSyncArguments.js +0 -49
  154. package/lib/readAutoMovieSyncArguments.js.map +0 -1
  155. package/lib/selectAutoMoviePackageManager.d.ts +0 -23
  156. package/lib/selectAutoMoviePackageManager.js +0 -70
  157. package/lib/selectAutoMoviePackageManager.js.map +0 -1
  158. package/src/IAutoMoviePackageManager.ts +0 -15
  159. package/src/readAutoMovieSyncArguments.ts +0 -48
  160. package/src/selectAutoMoviePackageManager.ts +0 -45
@@ -0,0 +1,53 @@
1
+ /**
2
+ * The Vite configuration every page `writeAutoMovieModulePage` writes is served or built with: the page's folder as the root, the production's configuration file and public folder, quiet logging, and the page itself as the dependency scanner's entry.
3
+ *
4
+ * The page lives under `node_modules/.cache/automovie/`, and Vite's own entry search skips everything under `node_modules`, so without an entry it finds none, logs "Could not auto-determine entry point" and skips pre-bundling, which makes the first load of a development server slow. `optimizeDeps.entries` is `index.html`, a name without glob characters, which Vite resolves against the root as it is instead of globbing with that skip; it also wins over the production's own `build.rollupOptions.input`, so the scan starts from this page rather than the production's. A host adds its own `server`, `build` or `base` beside these members.
5
+ *
6
+ * @evidence contracts/development/common.md#meaningful-documentation States every member, why the entry is needed and why it is written as a plain name, its precedence over the production's input, and what a host adds.
7
+ * @evidence contracts/development/implementation.md#principled-implementation Vite's scanner takes explicit `optimizeDeps.entries` first, resolving a pattern without glob characters directly against `root`, and only globs with the `node_modules` skip otherwise; naming the page's own `index.html` makes the scan start where the page does, whatever folder holds it.
8
+ * @evidence contracts/development/implementation.md#clear-and-simple-structure One record from the written page, shared by the draw page's build and the inspector's development server.
9
+ * @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts The production's configuration file is loaded, not replaced; only the root, the public folder and the scan entry are set for the page.
10
+ * @evidence contracts/development/implementation.md#efficient-algorithms Constant.
11
+ * @evidenceExclude contracts/development/implementation.md#reuse-equivalent-work A pure function of one page.
12
+ * @evidenceExclude contracts/development/implementation.md#bound-retention-and-release-resources Returns a fresh record and keeps nothing.
13
+ */
14
+ export function planAutoMovieModulePageViteConfig(page: {
15
+ /** The page's folder, the root it is served from. */
16
+ folder: string;
17
+
18
+ /** The production's `vite.config.ts`, or `false` when it has none. */
19
+ configFile: string | false;
20
+
21
+ /** The production's `public` folder, or `false` when it has none. */
22
+ publicDir: string | false;
23
+ }): {
24
+ /** The page's folder. */
25
+ root: string;
26
+
27
+ /** The production's configuration file, or `false`. */
28
+ configFile: string | false;
29
+
30
+ /** The production's public folder, or `false`. */
31
+ publicDir: string | false;
32
+
33
+ /** Only warnings and errors. */
34
+ logLevel: "warn";
35
+
36
+ /** Keep earlier output on screen. */
37
+ clearScreen: false;
38
+
39
+ /** The dependency scanner's entry. */
40
+ optimizeDeps: {
41
+ /** The page's own `index.html`, relative to `root`. */
42
+ entries: string[];
43
+ };
44
+ } {
45
+ return {
46
+ root: page.folder,
47
+ configFile: page.configFile,
48
+ publicDir: page.publicDir,
49
+ logLevel: "warn",
50
+ clearScreen: false,
51
+ optimizeDeps: { entries: ["index.html"] },
52
+ };
53
+ }
@@ -13,7 +13,7 @@ import { readAutoMovieNameOption } from "./readAutoMovieNameOption";
13
13
  * @throws On an unknown or repeated option, a missing name value, a target count other than one, an unknown family, or a refused directory segment.
14
14
  *
15
15
  * @evidence contracts/development/implementation.md#principled-implementation The directory segment passes the same portable-segment rule as a project name and must equal its trimmed form, so no separator, `.`, `..` or padding reaches the joined path.
16
- * @evidence contracts/development/implementation.md#clear-and-simple-structure The add grammar is separate from create and sync; the template owns the segment rule and `run` owns the workspace path.
16
+ * @evidence contracts/development/implementation.md#clear-and-simple-structure The add grammar is separate from create; the template owns the segment rule and `run` owns the workspace path.
17
17
  * @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts No family is inferred from the name and no workspace is searched for; the family is typed explicitly.
18
18
  * @evidence contracts/development/common.md#meaningful-documentation The comment states the grammar, the family pair, the segment rule and why it matters, and what throws.
19
19
  * @evidence contracts/development/implementation.md#efficient-algorithms One scan over the tokens and one split of the target.
@@ -0,0 +1,76 @@
1
+ import { AUTOMOVIE_CAPTURE_OPTIONS } from "./AUTOMOVIE_CAPTURE_OPTIONS";
2
+ import type { AutoMovieCaptureBackend } from "./AutoMovieCaptureBackend";
3
+
4
+ /**
5
+ * Split the options of `automovie capture` into the host's own, `AUTOMOVIE_CAPTURE_OPTIONS`, and the capture request's, which `parseAutoMovieCapturePlanRequest` reads.
6
+ *
7
+ * | Option | Meaning | Absent |
8
+ * | --- | --- | --- |
9
+ * | `--module <file>` | The subject module whose `subjects` the draw page offers | Required unless `--file` |
10
+ * | `--file <video>` | An encoded video file captured from its own frames instead of a drawn subject | A drawn subject |
11
+ * | `--props <file>` | A JSON file whose value the module's `subjects` is called with, for subjects built from data a host computes | `null` |
12
+ * | `--out <folder>` | The capture's root folder | `media/capture/<subject>` |
13
+ * | `--backend <software\|gpu>` | How the browser draws | `software` |
14
+ *
15
+ * Every other option is left for the request reader, which refuses one it does not know. It throws for `--module` beside `--file`, neither of them, an empty value of any host option, and a backend that is not `software` or `gpu`.
16
+ *
17
+ * @evidence contracts/development/common.md#meaningful-documentation Tabulates the host's options with their meaning and absent value, says where the rest go, and states every refusal.
18
+ * @evidence contracts/development/implementation.md#principled-implementation The host's keys are removed before the request is read, so the request grammar stays one grammar for the address, the command and props, and a host key cannot be mistaken for a request key.
19
+ * @evidence contracts/development/implementation.md#clear-and-simple-structure One pass over the listed options that takes the host's keys out, then the checks; the list is the one the README test reads.
20
+ * @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts No subject module is guessed from the folder: a capture names what it draws.
21
+ * @evidence contracts/development/implementation.md#efficient-algorithms Linear in the options.
22
+ * @evidenceExclude contracts/development/implementation.md#reuse-equivalent-work Read once per command.
23
+ * @evidenceExclude contracts/development/implementation.md#bound-retention-and-release-resources Returns a fresh map and keeps nothing.
24
+ */
25
+ export function readAutoMovieCaptureHostOptions(
26
+ values: ReadonlyMap<string, string>,
27
+ ): {
28
+ /** Subject module path, or null for a video file. */
29
+ module: string | null;
30
+
31
+ /** Video file path, or null for a drawn subject. */
32
+ file: string | null;
33
+
34
+ /** Path of the props JSON file, or null for none. */
35
+ props: string | null;
36
+
37
+ /** Root folder, or null for the default. */
38
+ out: string | null;
39
+
40
+ /** How the browser draws. */
41
+ backend: AutoMovieCaptureBackend;
42
+
43
+ /** The request's own options, for the request reader. */
44
+ request: Map<string, string>;
45
+ } {
46
+ const request: Map<string, string> = new Map(values);
47
+ const taken: Map<string, string> = new Map();
48
+ for (const key of AUTOMOVIE_CAPTURE_OPTIONS) {
49
+ const value: string | undefined = request.get(key);
50
+ request.delete(key);
51
+ if (value === undefined) continue;
52
+ if (value.trim() === "")
53
+ throw new Error(`Capture option --${key} needs a value`);
54
+ taken.set(key, value);
55
+ }
56
+ const module: string | null = taken.get("module") ?? null;
57
+ const file: string | null = taken.get("file") ?? null;
58
+ const out: string | null = taken.get("out") ?? null;
59
+ const backend: string = taken.get("backend") ?? "software";
60
+ if (module !== null && file !== null)
61
+ throw new Error("Capture takes --module or --file, not both");
62
+ if (module === null && file === null)
63
+ throw new Error(
64
+ "Capture needs --module <subject module> to draw a subject, or --file <video> to capture a video file",
65
+ );
66
+ if (backend !== "software" && backend !== "gpu")
67
+ throw new Error(`Capture --backend "${backend}" is not software or gpu`);
68
+ return {
69
+ module,
70
+ file,
71
+ props: taken.get("props") ?? null,
72
+ out,
73
+ backend,
74
+ request,
75
+ };
76
+ }
@@ -1,12 +1,11 @@
1
1
  import { type AutoMovieCommand } from "./AutoMovieCommand";
2
2
  import { readAutoMovieAddArguments } from "./readAutoMovieAddArguments";
3
3
  import { readAutoMovieCreateArguments } from "./readAutoMovieCreateArguments";
4
- import { readAutoMovieSyncArguments } from "./readAutoMovieSyncArguments";
5
4
 
6
5
  /**
7
6
  * Resolve one complete CLI request before any scaffold publication begins.
8
7
  *
9
- * `args` excludes the node executable and script positions. No arguments, or a lone `-h`/`--help`, means help; a lone `-v`/`--version` means version. `create`, `add` and `sync` delegate their grammars to {@link readAutoMovieCreateArguments}, {@link readAutoMovieAddArguments} and {@link readAutoMovieSyncArguments}. Every refusal throws an `Error` whose message names the correction.
8
+ * `args` excludes the node executable and script positions. No arguments, or a lone `-h`/`--help`, means help; a lone `-v`/`--version` means version. `create` and `add` delegate their grammars to {@link readAutoMovieCreateArguments} and {@link readAutoMovieAddArguments}; `capture`, `inspect`, `render` and `review` keep their tokens for the production's option reader, which `run` loads. Every refusal throws an `Error` whose message names the correction.
10
9
  *
11
10
  * @param args The command-line tokens after the executable and script.
12
11
  * @returns The admitted request.
@@ -31,9 +30,12 @@ export function readAutoMovieCommandArguments(
31
30
  return standalone(command, rest, { command: "version" });
32
31
  if (command === "create") return readAutoMovieCreateArguments(rest);
33
32
  if (command === "add") return readAutoMovieAddArguments(rest);
34
- if (command === "sync") return readAutoMovieSyncArguments(rest);
33
+ if (command === "capture") return { command: "capture", args: [...rest] };
34
+ if (command === "inspect") return { command: "inspect", args: [...rest] };
35
+ if (command === "render") return { command: "render", args: [...rest] };
36
+ if (command === "review") return { command: "review", args: [...rest] };
35
37
  throw new Error(
36
- `Unknown command ${JSON.stringify(command)}; the commands are create, add and sync (see --help).`,
38
+ `Unknown command ${JSON.stringify(command)}; the commands are create, add, capture, inspect, render and review (see --help).`,
37
39
  );
38
40
  }
39
41
 
@@ -11,7 +11,7 @@ import { readAutoMovieNameOption } from "./readAutoMovieNameOption";
11
11
  * @throws On an unknown or repeated option, a missing name value, or anything other than one non-blank directory.
12
12
  *
13
13
  * @evidence contracts/development/implementation.md#principled-implementation A complete left-to-right scan admits each flag once and consumes `--name`'s value, so every token is classified before any filesystem work.
14
- * @evidence contracts/development/implementation.md#clear-and-simple-structure The create grammar is separate from add and sync; `readAutoMovieNameOption` owns the shared value rule and `run` owns resolution.
14
+ * @evidence contracts/development/implementation.md#clear-and-simple-structure The create grammar is separate from add; `readAutoMovieNameOption` owns the shared value rule and `run` owns resolution.
15
15
  * @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts No default directory, inferred workspace mode or derived name is introduced here.
16
16
  * @evidence contracts/development/common.md#meaningful-documentation The comment states the grammar, the dash-leading spelling and that refusals name their correction.
17
17
  * @evidence contracts/development/implementation.md#efficient-algorithms One scan over the tokens.
@@ -0,0 +1,66 @@
1
+ import { AUTOMOVIE_INSPECT_OPTIONS } from "./AUTOMOVIE_INSPECT_OPTIONS";
2
+
3
+ /** Highest TCP port. */
4
+ const PORTS: number = 65_535;
5
+
6
+ /**
7
+ * Split the options of `automovie inspect` into the command's own, `AUTOMOVIE_INSPECT_OPTIONS`, and the request the page opens on, which `parseAutoMovieCapturePlanRequest` reads.
8
+ *
9
+ * | Option | Meaning | Absent |
10
+ * | --- | --- | --- |
11
+ * | `--module <file>` | The subject module whose `subjects` the inspector page offers | Required |
12
+ * | `--port <n>` | The port the page is served on, 1 to 65535 | A free port |
13
+ * | `--props <file>` | A JSON file whose value the module's `subjects` is called with, for a module whose subjects are built from data a host computes, such as a motion case | `null` |
14
+ *
15
+ * Every other option is left for the request reader, which refuses one it does not know. It throws for a missing `--module`, an empty value of any of its options, and a port that is not a whole number from 1 to 65535.
16
+ *
17
+ * @evidence contracts/development/common.md#meaningful-documentation Tabulates the command's options with their meaning and absent value, says where the rest go, and states every refusal.
18
+ * @evidence contracts/development/implementation.md#principled-implementation The command's keys are removed before the request is read, as the capture command does, so the address and the command line share one grammar and a command key cannot be mistaken for a request key.
19
+ * @evidence contracts/development/implementation.md#clear-and-simple-structure One pass that takes the command's keys out, then the checks.
20
+ * @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts No module is guessed from the folder: the page shows what the command names.
21
+ * @evidence contracts/development/implementation.md#efficient-algorithms Linear in the options.
22
+ * @evidenceExclude contracts/development/implementation.md#reuse-equivalent-work Read once per command.
23
+ * @evidenceExclude contracts/development/implementation.md#bound-retention-and-release-resources Returns a fresh map and keeps nothing.
24
+ */
25
+ export function readAutoMovieInspectHostOptions(
26
+ values: ReadonlyMap<string, string>,
27
+ ): {
28
+ /** Subject module path, relative to the production or absolute. */
29
+ module: string;
30
+
31
+ /** The port to serve on, or null for a free one. */
32
+ port: number | null;
33
+
34
+ /** Path of the props JSON file, relative to the production or absolute, or null for none. */
35
+ props: string | null;
36
+
37
+ /** The request's own options, for the request reader. */
38
+ request: Map<string, string>;
39
+ } {
40
+ const request: Map<string, string> = new Map(values);
41
+ const taken: Map<string, string> = new Map();
42
+ for (const key of AUTOMOVIE_INSPECT_OPTIONS) {
43
+ const value: string | undefined = request.get(key);
44
+ request.delete(key);
45
+ if (value === undefined) continue;
46
+ if (value.trim() === "")
47
+ throw new Error(`Inspect option --${key} needs a value`);
48
+ taken.set(key, value);
49
+ }
50
+
51
+ const module: string | undefined = taken.get("module");
52
+ if (module === undefined)
53
+ throw new Error(
54
+ "Inspect needs --module <subject module>, the module whose subjects the page offers",
55
+ );
56
+ const text: string | undefined = taken.get("port");
57
+ const port: number | null = text === undefined ? null : Number(text);
58
+ if (
59
+ port !== null &&
60
+ !(Number.isSafeInteger(port) && port >= 1 && port <= PORTS)
61
+ )
62
+ throw new Error(
63
+ `Inspect --port "${text}" is not a whole number from 1 to ${PORTS}`,
64
+ );
65
+ return { module, port, props: taken.get("props") ?? null, request };
66
+ }
@@ -0,0 +1,67 @@
1
+ import { AUTOMOVIE_RENDER_OPTIONS } from "./AUTOMOVIE_RENDER_OPTIONS";
2
+ import type { AutoMovieCaptureBackend } from "./AutoMovieCaptureBackend";
3
+
4
+ /**
5
+ * Split the options of `automovie render` into the command's own, `AUTOMOVIE_RENDER_OPTIONS`, and the request's, which `parseAutoMovieCapturePlanRequest` reads for the request's `subject`.
6
+ *
7
+ * | Option | Meaning | Absent |
8
+ * | --- | --- | --- |
9
+ * | `--module <file>` | The subject module whose `subjects` the draw page offers | Required |
10
+ * | `--props <file>` | A JSON file whose value the module's `subjects` is called with | `null` |
11
+ * | `--out <folder>` | Where `film.mp4` and `render-report.json` go | `media/automovie/<subject>/videos` |
12
+ * | `--backend <software\|gpu>` | How the browser draws | `software` |
13
+ *
14
+ * Every other option is left for the request reader, which names the subject as `capture` and the inspector do; a render draws the subject's whole clock through its own camera, so `renderAutoMovie` refuses any request key but `subject`. It throws for an empty value of its own options, a missing `--module`, and a backend that is not `software` or `gpu`.
15
+ *
16
+ * @evidence contracts/development/common.md#meaningful-documentation Tabulates the command's options with their meaning and absent value, says where the rest go and which of them a render admits, and states every refusal.
17
+ * @evidence contracts/development/implementation.md#principled-implementation The command's keys are removed before the request is read, as `capture` and `inspect` do, so the subject has one name and one reader in every host.
18
+ * @evidence contracts/development/implementation.md#clear-and-simple-structure One pass over the listed options that takes them out, then the checks.
19
+ * @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts No module is guessed from the folder.
20
+ * @evidence contracts/development/implementation.md#efficient-algorithms Linear in the options.
21
+ * @evidenceExclude contracts/development/implementation.md#reuse-equivalent-work Read once per command.
22
+ * @evidenceExclude contracts/development/implementation.md#bound-retention-and-release-resources Returns a fresh record and keeps nothing.
23
+ */
24
+ export function readAutoMovieRenderOptions(
25
+ values: ReadonlyMap<string, string>,
26
+ ): {
27
+ /** Subject module path, relative to the production or absolute. */
28
+ module: string;
29
+
30
+ /** Path of the props JSON file, or null for none. */
31
+ props: string | null;
32
+
33
+ /** The output folder, or null for the default. */
34
+ out: string | null;
35
+
36
+ /** How the browser draws. */
37
+ backend: AutoMovieCaptureBackend;
38
+
39
+ /** The request's own options, for the request reader. */
40
+ request: Map<string, string>;
41
+ } {
42
+ const request: Map<string, string> = new Map(values);
43
+ const taken: Map<string, string> = new Map();
44
+ for (const key of AUTOMOVIE_RENDER_OPTIONS) {
45
+ const value: string | undefined = request.get(key);
46
+ request.delete(key);
47
+ if (value === undefined) continue;
48
+ if (value.trim() === "")
49
+ throw new Error(`Render option --${key} needs a value`);
50
+ taken.set(key, value);
51
+ }
52
+ const module: string | undefined = taken.get("module");
53
+ if (module === undefined)
54
+ throw new Error(
55
+ "Render needs --module <subject module>, the module whose subjects the draw page offers",
56
+ );
57
+ const backend: string = taken.get("backend") ?? "software";
58
+ if (backend !== "software" && backend !== "gpu")
59
+ throw new Error(`Render --backend "${backend}" is not software or gpu`);
60
+ return {
61
+ module,
62
+ props: taken.get("props") ?? null,
63
+ out: taken.get("out") ?? null,
64
+ backend,
65
+ request,
66
+ };
67
+ }
@@ -0,0 +1,70 @@
1
+ import { AUTOMOVIE_REVIEW_OPTIONS } from "./AUTOMOVIE_REVIEW_OPTIONS";
2
+
3
+ /** Longest observation in seconds: one day, beyond any film's playback a person reviews. */
4
+ const LONGEST: number = 86_400;
5
+
6
+ /**
7
+ * Read the options of `automovie review`, `AUTOMOVIE_REVIEW_OPTIONS`.
8
+ *
9
+ * | Option | Meaning | Absent |
10
+ * | --- | --- | --- |
11
+ * | `--url <address>` | The running inspector page, with the request it opens on | Required |
12
+ * | `--seconds <s>` | Wall-clock seconds of playback recorded, positive, at most a day | Required |
13
+ * | `--out <folder>` | Where the recording and `playback.json` go | `media/automovie/review` |
14
+ *
15
+ * It throws naming the option for an option outside the list, an empty value, a missing `--url` or `--seconds`, an address that is not HTTP on this machine, and seconds out of range.
16
+ *
17
+ * @evidence contracts/development/common.md#meaningful-documentation Tabulates every option with its meaning and absent value, and states every refusal.
18
+ * @evidence contracts/development/implementation.md#principled-implementation A review records the page a person would watch, so the command names that page and how long to watch it; only a loopback address is admitted, so the command never drives a page elsewhere.
19
+ * @evidence contracts/development/implementation.md#clear-and-simple-structure One pass admitting the listed options, then the checks.
20
+ * @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts No address or duration is guessed.
21
+ * @evidence contracts/development/implementation.md#efficient-algorithms Linear in the options.
22
+ * @evidenceExclude contracts/development/implementation.md#reuse-equivalent-work Read once per command.
23
+ * @evidenceExclude contracts/development/implementation.md#bound-retention-and-release-resources Returns a fresh record and keeps nothing.
24
+ */
25
+ export function readAutoMovieReviewOptions(
26
+ values: ReadonlyMap<string, string>,
27
+ ): {
28
+ /** The page's address. */
29
+ url: string;
30
+
31
+ /** Seconds of playback recorded. */
32
+ seconds: number;
33
+
34
+ /** The output folder, or null for the default. */
35
+ out: string | null;
36
+ } {
37
+ for (const [key, value] of values) {
38
+ if (!AUTOMOVIE_REVIEW_OPTIONS.includes(key))
39
+ throw new Error(
40
+ `Review takes no option --${key}; it takes ${AUTOMOVIE_REVIEW_OPTIONS.map((option: string): string => `--${option}`).join(", ")}`,
41
+ );
42
+ if (value.trim() === "")
43
+ throw new Error(`Review option --${key} needs a value`);
44
+ }
45
+ const url: string | undefined = values.get("url");
46
+ const text: string | undefined = values.get("seconds");
47
+ if (url === undefined || text === undefined)
48
+ throw new Error("Review needs --url <inspector address> and --seconds <s>");
49
+ let address: URL;
50
+ try {
51
+ address = new URL(url);
52
+ } catch (error) {
53
+ throw new Error(`Review --url "${url}" is not an address`, {
54
+ cause: error,
55
+ });
56
+ }
57
+ if (
58
+ address.protocol !== "http:" ||
59
+ !["127.0.0.1", "localhost", "[::1]"].includes(address.hostname)
60
+ )
61
+ throw new Error(
62
+ `Review --url "${url}" is not an HTTP page on this machine`,
63
+ );
64
+ const seconds: number = Number(text);
65
+ if (!(Number.isFinite(seconds) && seconds > 0 && seconds <= LONGEST))
66
+ throw new Error(
67
+ `Review --seconds "${text}" is not a number of seconds above 0 and at most ${LONGEST}`,
68
+ );
69
+ return { url: address.href, seconds, out: values.get("out") ?? null };
70
+ }
@@ -0,0 +1,29 @@
1
+ import { execFileSync } from "node:child_process";
2
+
3
+ /**
4
+ * The source revision a capture records: the production's git commit, with `+changes` when its working tree differs from that commit, or `unrecorded` when the folder is not in a git checkout or git is not installed.
5
+ *
6
+ * @evidence contracts/development/common.md#meaningful-documentation States the three forms and when each is written.
7
+ * @evidence contracts/development/implementation.md#principled-implementation `git rev-parse HEAD` names the commit and `git status --porcelain` is empty exactly when nothing differs from it, so the revision says whether the commit alone repeats the capture.
8
+ * @evidence contracts/development/implementation.md#clear-and-simple-structure Two git calls, one fallback.
9
+ * @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts A missing revision is written as `unrecorded`, never as a guessed commit.
10
+ * @evidence contracts/development/implementation.md#efficient-algorithms Two short processes per capture.
11
+ * @evidenceExclude contracts/development/implementation.md#reuse-equivalent-work Read once per capture, since the tree may change between captures.
12
+ * @evidence contracts/development/implementation.md#bound-retention-and-release-resources Both processes end before it returns.
13
+ */
14
+ export function readAutoMovieRevision(root: string): string {
15
+ const git: (args: string[]) => string = (args: string[]): string =>
16
+ execFileSync("git", ["-C", root, ...args], {
17
+ encoding: "utf8",
18
+ stdio: ["ignore", "pipe", "ignore"],
19
+ windowsHide: true,
20
+ }).trim();
21
+ try {
22
+ const commit: string = git(["rev-parse", "HEAD"]);
23
+ return git(["status", "--porcelain", "--", "."]) === ""
24
+ ? commit
25
+ : `${commit}+changes`;
26
+ } catch {
27
+ return "unrecorded";
28
+ }
29
+ }
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Read a video file's clock and raster from the log FFmpeg writes when it opens the file: the `Duration:` of the input and the size and rate of its first video stream.
3
+ *
4
+ * The rate is the stream's `fps` value, or its `tbr` when FFmpeg prints no `fps`. It throws naming what is missing when the log holds no duration, no video stream, or a stream without a size or a rate.
5
+ *
6
+ * @evidence contracts/development/common.md#meaningful-documentation States what is read from where, the rate's fallback and the refusal.
7
+ * @evidence contracts/development/implementation.md#principled-implementation FFmpeg prints `Duration: HH:MM:SS.ss` for every input and, for a video stream, `WxH` followed by `fps` and `tbr`, its frame and base rates; reading the log FFmpeg already writes needs no `ffprobe`, which `ffmpeg-static` does not ship.
8
+ * @evidence contracts/development/implementation.md#clear-and-simple-structure One expression per value.
9
+ * @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts A missing value throws instead of taking a default raster or rate.
10
+ * @evidence contracts/development/implementation.md#efficient-algorithms Linear in the log.
11
+ * @evidenceExclude contracts/development/implementation.md#reuse-equivalent-work A pure reading of one log.
12
+ * @evidenceExclude contracts/development/implementation.md#bound-retention-and-release-resources Returns four numbers.
13
+ */
14
+ export function readAutoMovieVideoProbe(log: string): {
15
+ /** Running time in seconds. */
16
+ durationSeconds: number;
17
+
18
+ /** Frames per second. */
19
+ fps: number;
20
+
21
+ /** Width in pixels. */
22
+ width: number;
23
+
24
+ /** Height in pixels. */
25
+ height: number;
26
+ } {
27
+ const duration: RegExpMatchArray | null = log.match(
28
+ /Duration:\s*(\d+):(\d{2}):(\d{2}(?:\.\d+)?)/u,
29
+ );
30
+ if (duration === null)
31
+ throw new Error("FFmpeg reported no duration for the video");
32
+ const stream: string | undefined = log
33
+ .split(/\r?\n/u)
34
+ .find((line: string): boolean => /Stream #.*Video:/u.test(line));
35
+ if (stream === undefined)
36
+ throw new Error("FFmpeg reported no video stream in the file");
37
+ const size: RegExpMatchArray | null = stream.match(
38
+ /[ ,](\d{2,5})x(\d{2,5})[ ,[]/u,
39
+ );
40
+ const rate: RegExpMatchArray | null =
41
+ stream.match(/([\d.]+) fps/u) ?? stream.match(/([\d.]+) tbr/u);
42
+ if (size === null || rate === null)
43
+ throw new Error(
44
+ `FFmpeg reported no size or rate for the video stream: ${stream.trim()}`,
45
+ );
46
+ return {
47
+ durationSeconds:
48
+ Number(duration[1]) * 3600 +
49
+ Number(duration[2]) * 60 +
50
+ Number(duration[3]),
51
+ fps: Number(rate[1]),
52
+ width: Number(size[1]),
53
+ height: Number(size[2]),
54
+ };
55
+ }
@@ -0,0 +1,168 @@
1
+ import * as fs from "node:fs/promises";
2
+
3
+ import { planAutoMovieChromiumLaunch } from "./planAutoMovieChromiumLaunch";
4
+
5
+ /** Milliseconds the page may take to load and show its controls: ten minutes, room for a film that prepares its performance before its first frame. */
6
+ const PREPARE: number = 600_000;
7
+
8
+ /** Longest pause between two readings of the time readout, milliseconds. */
9
+ const READING: number = 500;
10
+
11
+ /** The time readout the inspector shows: the second and the duration, such as `1.25 / 12.00 s`. */
12
+ const READOUT: RegExp = /\d+\.\d+ \/ \d+\.\d+ s/u;
13
+
14
+ /** The part of `playwright-core`'s `chromium` a playback recording calls. */
15
+ interface IRecordingChromium {
16
+ launch(options: {
17
+ headless: true;
18
+ args: string[];
19
+ executablePath?: string;
20
+ }): Promise<IRecordingBrowser>;
21
+ }
22
+
23
+ /** A launched browser that opens recording contexts. */
24
+ interface IRecordingBrowser {
25
+ newContext(options: {
26
+ viewport: { width: number; height: number };
27
+ recordVideo: { dir: string; size: { width: number; height: number } };
28
+ }): Promise<IRecordingContext>;
29
+ close(): Promise<void>;
30
+ }
31
+
32
+ /** A recording browser context. */
33
+ interface IRecordingContext {
34
+ newPage(): Promise<IRecordingPage>;
35
+ close(): Promise<void>;
36
+ }
37
+
38
+ /** The page calls a recording makes. */
39
+ interface IRecordingPage {
40
+ on(event: "pageerror", listener: (error: Error) => void): unknown;
41
+ goto(
42
+ url: string,
43
+ options: { waitUntil: "domcontentloaded"; timeout: number },
44
+ ): Promise<unknown>;
45
+ getByRole(
46
+ role: "button",
47
+ options: { name: string; exact: true },
48
+ ): IRecordingLocator;
49
+ locator(selector: string, options: { hasText: RegExp }): IRecordingLocator;
50
+ waitForTimeout(milliseconds: number): Promise<void>;
51
+ video(): { path(): Promise<string> } | null;
52
+ }
53
+
54
+ /** A located element. */
55
+ interface IRecordingLocator {
56
+ first(): IRecordingLocator;
57
+ waitFor(options: { timeout: number }): Promise<void>;
58
+ click(): Promise<void>;
59
+ innerText(): Promise<string>;
60
+ }
61
+
62
+ /**
63
+ * Record real-time playback of the running inspector page: load it, press its Play button, and record the page as a video while reading its time readout, for a person to watch.
64
+ *
65
+ * The browser draws on the GPU backend, since playback is judged in real time; the recording is Playwright's own video of the page at a 1280 by 900 viewport, which `npx playwright-core install ffmpeg` provides. The page's Play button is found by its role and name, and the readout as the `output` showing `<second> / <duration> s`, both as the inspector renders them. The readout is read at most every half second for `seconds` of wall time after the click, and the page's script errors are collected. The video begins at navigation, so it includes the page's preparation; a reading's elapsed seconds count from the click.
66
+ *
67
+ * It rejects when the page shows no Play button or readout within ten minutes and when the browser produced no video. The browser is closed on every outcome.
68
+ *
69
+ * @evidence contracts/development/common.md#meaningful-documentation States what is recorded and how, which backend and why, how the controls are found, the reading cadence, the clocks of the video and the readings, the refusals and the release.
70
+ * @evidence contracts/development/implementation.md#principled-implementation Playback is observed on the page a person uses, through its own controls, so the recording shows the real loop's pacing instead of seeks turned into a supposed playback; Playwright closes the context to finish writing the video.
71
+ * @evidence contracts/development/implementation.md#clear-and-simple-structure Launch, open a recording context, load, press Play, read for the duration, close.
72
+ * @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts A missing control or video is an error, never a recording of nothing.
73
+ * @evidence contracts/development/implementation.md#efficient-algorithms One reading per half second.
74
+ * @evidenceExclude contracts/development/implementation.md#reuse-equivalent-work Each review records afresh.
75
+ * @evidence contracts/development/implementation.md#bound-retention-and-release-resources The browser and its context are closed on every outcome; the readings grow by two per second of observation.
76
+ */
77
+ export async function recordAutoMoviePlayback(props: {
78
+ /** Playwright's `chromium`, loaded from the production. */
79
+ chromium: unknown;
80
+
81
+ /** The inspector page's address. */
82
+ url: string;
83
+
84
+ /** Wall-clock seconds observed after Play is pressed. */
85
+ seconds: number;
86
+
87
+ /** Folder the video is written into. */
88
+ out: string;
89
+
90
+ /** The environment, read for `CHROME_PATH`. */
91
+ env: Readonly<Record<string, string | undefined>>;
92
+ }): Promise<{
93
+ /** The recording. */
94
+ video: string;
95
+
96
+ /** Each reading of the time readout, with wall seconds since Play was pressed. */
97
+ readings: { elapsedSeconds: number; text: string }[];
98
+
99
+ /** The page's script errors. */
100
+ errors: string[];
101
+ }> {
102
+ const chromium: IRecordingChromium = props.chromium as IRecordingChromium;
103
+ const plan: ReturnType<typeof planAutoMovieChromiumLaunch> =
104
+ planAutoMovieChromiumLaunch("gpu", props.env);
105
+ await fs.mkdir(props.out, { recursive: true });
106
+ const browser: IRecordingBrowser = await chromium.launch({
107
+ headless: true,
108
+ args: [
109
+ ...plan.args,
110
+ "--autoplay-policy=no-user-gesture-required",
111
+ "--disable-background-timer-throttling",
112
+ ],
113
+ ...(plan.executablePath === undefined
114
+ ? {}
115
+ : { executablePath: plan.executablePath }),
116
+ });
117
+ try {
118
+ const viewport: { width: number; height: number } = {
119
+ width: 1280,
120
+ height: 900,
121
+ };
122
+ const context: IRecordingContext = await browser.newContext({
123
+ viewport,
124
+ recordVideo: { dir: props.out, size: viewport },
125
+ });
126
+ const page: IRecordingPage = await context.newPage();
127
+ const errors: string[] = [];
128
+ page.on("pageerror", (error: Error): void => {
129
+ errors.push(error.message);
130
+ });
131
+ await page.goto(props.url, {
132
+ waitUntil: "domcontentloaded",
133
+ timeout: PREPARE,
134
+ });
135
+ const play: IRecordingLocator = page
136
+ .getByRole("button", { name: "Play", exact: true })
137
+ .first();
138
+ const readout: IRecordingLocator = page
139
+ .locator("output", { hasText: READOUT })
140
+ .first();
141
+ await play.waitFor({ timeout: PREPARE });
142
+ await readout.waitFor({ timeout: PREPARE });
143
+
144
+ // Press Play and read the readout for the observed seconds.
145
+ await play.click();
146
+ const started: number = performance.now();
147
+ const readings: { elapsedSeconds: number; text: string }[] = [];
148
+ while (performance.now() - started < props.seconds * 1000) {
149
+ readings.push({
150
+ elapsedSeconds: (performance.now() - started) / 1000,
151
+ text: await readout.innerText(),
152
+ });
153
+ await page.waitForTimeout(
154
+ Math.min(
155
+ READING,
156
+ Math.max(1, props.seconds * 1000 - (performance.now() - started)),
157
+ ),
158
+ );
159
+ }
160
+ const video: { path(): Promise<string> } | null = page.video();
161
+ await context.close();
162
+ if (video === null)
163
+ throw new Error("The browser produced no playback recording");
164
+ return { video: await video.path(), readings, errors };
165
+ } finally {
166
+ await browser.close();
167
+ }
168
+ }