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
package/src/run.ts CHANGED
@@ -1,48 +1,73 @@
1
1
  import {
2
- type IScaffoldCompletedPublication,
3
- type IScaffoldPublicationReceipt,
4
- ScaffoldPublicationError,
5
- publishFiles,
6
- renderScaffold,
7
- renderWorkspaceProductionScaffold,
8
- renderWorkspaceScaffold,
9
- syncScaffold,
2
+ type IAutoMovieScaffoldProps,
3
+ createAutoMovieScaffold,
10
4
  } from "@automovie/template";
11
5
  import * as fs from "node:fs";
12
6
  import * as path from "node:path";
13
7
 
14
8
  import type { AutoMovieCommand } from "./AutoMovieCommand";
15
- import type { IAutoMoviePackageManager } from "./IAutoMoviePackageManager";
9
+ import { captureAutoMovie } from "./captureAutoMovie";
16
10
  import { deriveAutoMovieProjectName } from "./deriveAutoMovieProjectName";
11
+ import { inspectAutoMovie } from "./inspectAutoMovie";
17
12
  import { promptAutoMovieProjectName } from "./promptAutoMovieProjectName";
18
13
  import { readAutoMovieCommandArguments } from "./readAutoMovieCommandArguments";
14
+ import { renderAutoMovie } from "./renderAutoMovie";
19
15
  import { renderAutoMovieScaffoldNextSteps } from "./renderAutoMovieScaffoldNextSteps";
20
- import { selectAutoMoviePackageManager } from "./selectAutoMoviePackageManager";
16
+ import { reviewAutoMovie } from "./reviewAutoMovie";
21
17
  import { selectAutoMovieProjectName } from "./selectAutoMovieProjectName";
22
18
 
23
- const USAGE: string = `automovie: scaffold an automovie project
19
+ const USAGE: string = `automovie: scaffold an automovie project, and capture, render and review it
24
20
 
25
21
  Usage:
26
22
  npx automovie create <directory> [--workspace] [--name <name>] [--force]
27
23
  pnpm automovie add <shorts|series>/<name> [--name <name>] [--force]
28
- npx automovie sync <directory> [--check] [--baseline <directory>]
24
+ automovie capture --module <file> [--props <json>] [--backend software|gpu] [--out <dir>] [<request>]
25
+ automovie capture --file <video> [--out <dir>] [<request>]
26
+ automovie inspect --module <file> [--props <json>] [--port <n>] [<request>]
27
+ automovie render --module <file> [--subject <name>] [--props <json>] [--out <dir>] [--backend software|gpu]
28
+ automovie review --url <inspector address> --seconds <s> [--out <dir>]
29
29
 
30
30
  Commands:
31
31
  create A single production, or with --workspace a pnpm workspace
32
32
  root for movies/shorts, movies/series and packages.
33
33
  add From a workspace root, a production at movies/<family>/<name>:
34
34
  shorts run brief -> screenplay, series the long route.
35
- sync Update the generated instructions of a single production
36
- or a workspace root.
35
+ capture In a production, draw the subjects a module offers in headless
36
+ Chromium, or take a video file's own frames, into stills,
37
+ contact sheets and record.json. Needs @automovie/render, vite
38
+ and playwright-core in the production, and FFmpeg for --file.
39
+ inspect In a production or package, serve the inspector page over the
40
+ subjects a module offers and print its address, whose query
41
+ is the request. Needs @automovie/render, @automovie/viewer,
42
+ react, react-dom and vite there; Ctrl+C stops it.
43
+ render In a production, draw every frame of one subject through the
44
+ draw page in headless Chromium and encode film.mp4 with
45
+ render-report.json. Needs what capture needs, and FFmpeg.
46
+ review Record real-time playback of the running inspector page as a
47
+ video with playback.json. Needs playwright-core and
48
+ Playwright's ffmpeg (npx playwright-core install ffmpeg).
37
49
 
38
50
  Options:
39
51
  --workspace Create a pnpm workspace root instead of a single production.
40
52
  --name Package name; create asks for one when the target is the
41
53
  current directory, and add defaults to the directory name.
42
54
  --force Install into a non-empty directory, replacing same-path files.
43
- --check Report a sync plan; exit 1 when updates or conflicts remain.
44
- --baseline Previous adopted instructions the files came from; they
45
- override the stored sync state for the files they hold.
55
+ --module capture, inspect, render: the module whose subjects(props)
56
+ the page draws.
57
+ --port inspect: the port to serve on; default a free port.
58
+ --props capture, inspect, render: a JSON file the module's subjects(props) is
59
+ called with; default null.
60
+ --file capture: an encoded video file instead of a subject.
61
+ --backend capture, render: software (SwiftShader, the default) or gpu.
62
+ --out capture: the folder; default media/capture/<subject>.
63
+ render: default media/automovie/<subject>/videos.
64
+ review: default media/automovie/review.
65
+ --url review: the running inspector page's address.
66
+ --seconds review: wall-clock seconds of playback recorded.
67
+ <request> capture, inspect: --subject, --at, --from, --to, --rate, --events,
68
+ --views, --passes, --marks, --label, --round, --compare and
69
+ every other key of the capture request grammar; render takes
70
+ --subject alone, the subject rendered, default the only one.
46
71
  -h, --help Show this help as a standalone request.
47
72
  -v, --version Print the version as a standalone request.
48
73
  `;
@@ -51,24 +76,27 @@ Options:
51
76
  * The `automovie` CLI entry. `argv` is the full process vector; its first two positions (executable and script) are skipped.
52
77
  *
53
78
  * - `help` and `version` write to stdout; the version is read from this package's `package.json`.
54
- * - `create` renders a single production, or with `--workspace` a workspace root, and publishes it into the directory resolved against the working directory. The name is the typed `--name`, else derived from the target's basename; for the working directory itself the terminal is asked, offering `automovie-examples`, which is used without asking when no terminal is attached.
55
- * - `add` requires `pnpm-workspace.yaml` in the working directory, which it takes as the workspace root without searching elsewhere, and publishes a workspace production into `movies/<family>/<directory>`, named by `--name`, else by the npm-safe name derived from the directory segment as `create` derives one.
56
- * - `sync` plans explicit generated-instruction updates for the directory holding `AGENTS.md`, preserves project contracts and content and refuses local conflicts; check reports pending updates without writing.
79
+ * - `create` writes a single production, or with `--workspace` a workspace root, into the directory resolved against the working directory. The name is the typed `--name`, else derived from the target's basename; for the working directory itself the terminal is asked, offering `automovie-examples`, which is used without asking when no terminal is attached.
80
+ * - `add` requires `pnpm-workspace.yaml` in the working directory, which it takes as the workspace root without searching elsewhere, and writes a workspace production into `movies/<family>/<directory>`, named by `--name`, else by the npm-safe name derived from the directory segment as `create` derives one.
81
+ * - `capture` runs `captureAutoMovie` in the working directory as the production, resolving to its status: 1 when a cell was not drawn.
82
+ * - `inspect` runs `inspectAutoMovie` in the working directory, serving the inspector page until the process is interrupted.
83
+ * - `render` runs `renderAutoMovie` in the working directory as the production, resolving to 0 once the video is written.
84
+ * - `review` runs `reviewAutoMovie`, resolving to 1 when the recorded page reported a script error.
57
85
  *
58
- * `create` and `add` refuse a non-empty target without `--force`. On success they list the written files relative to the target, then the next steps. Completed and partial file effects stay after failure; the error names the completed files and the stopping entry. Prepared directories can remain even when no file was written.
86
+ * `create` and `add` take their files from `createAutoMovieScaffold` and refuse a non-empty target without `--force`, which writes over same-path files and keeps every other file. On success they list the written files relative to the target, then the next steps. A failed write stops there and leaves the files already written.
59
87
  *
60
88
  * Resolves to the process exit code, 0 after queuing the requested stdout text or 1 after queuing a caught error's message and distinct `cause` objects' messages without stacks. A repeated cause ends the chain. Reading or stringifying an unusual thrown value, or writing stderr, can itself throw. The executable assigns the result to `process.exitCode` so queued output can drain.
61
89
  *
62
90
  * @param argv The full process vector.
63
91
  * @returns The exit code.
64
92
  *
65
- * @evidence contracts/development/implementation.md#principled-implementation Parsing finishes before rendering or publication, and path.resolve binds every target to the current working directory. A non-completed receipt becomes ScaffoldPublicationError, preserving the completed prefix and stopping outcome; describeError follows distinct cause values with a set to terminate cycles, but assumes their message access and string conversion do not throw.
66
- * @evidence contracts/development/implementation.md#clear-and-simple-structure This dispatcher delegates admission, name choice, the prompt and closing text to CLI owners and rendering and publication to the template package. Only bin.ts invokes it at module load, so importing run does not execute a request.
67
- * @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts `add` checks only the working directory for `pnpm-workspace.yaml` and never searches ancestors; only `create`'s next steps detect a package manager. The catch reports failures without stacks and never retries publication or rolls back files.
68
- * @evidence contracts/development/common.md#meaningful-documentation The comment gives argv ownership, every command's effect, name and target choice, retained file and directory effects, and the returned status.
69
- * @evidence contracts/development/implementation.md#efficient-algorithms For n files, rendering reads total bytes and sorts directory entries and the n rendered paths for deterministic order and collision reporting. Publication encodes those bytes and checks each path's ancestors before writing; listing scans completed paths once. Sync adds linear instruction reads and digests and the existing conditional publication path. Failure formatting additionally walks the distinct cause chain.
70
- * @evidence contracts/development/implementation.md#reuse-equivalent-work Every command takes fresh filesystem observations and cannot reuse an earlier receipt. Check observes without publishing. Rendering reads the installed scaffold anew; only the template's per-call directory captures are reused and revalidated during that publication.
71
- * @evidence contracts/development/implementation.md#bound-retention-and-release-resources Rendered strings, encoded candidate bytes, receipt entries, and listing text scale with scaffold size; the cause set scales with chain length without a fixed cap. The prompt closes its terminal interface before returning. This dispatcher owns no descriptor; queued stdout and stderr bytes belong to the process streams.
93
+ * @evidence contracts/development/implementation.md#principled-implementation Parsing finishes before the scaffold is created, the whole file map exists before the first write, and path.resolve binds every target to the current working directory. describeError follows distinct cause values with a set to terminate cycles, but assumes their message access and string conversion do not throw.
94
+ * @evidence contracts/development/implementation.md#clear-and-simple-structure This dispatcher delegates admission, name choice, the prompt and closing text to CLI owners and the file map to the template package, keeping only the write. Only bin.ts invokes it at module load, so importing run does not execute a request.
95
+ * @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts `add` checks only the working directory for `pnpm-workspace.yaml` and never searches ancestors. The catch reports failures without stacks and never retries a write or rolls back files.
96
+ * @evidence contracts/development/common.md#meaningful-documentation The comment gives argv ownership, every command's effect, name and target choice, retained file effects, and the returned status.
97
+ * @evidence contracts/development/implementation.md#efficient-algorithms For n files, creation reads the scaffold once and each file is written once with its directory ensured; listing scans the written paths once. Failure formatting additionally walks the distinct cause chain.
98
+ * @evidenceExclude contracts/development/implementation.md#reuse-equivalent-work Every command takes fresh filesystem observations and reads the installed scaffold anew.
99
+ * @evidence contracts/development/implementation.md#bound-retention-and-release-resources The file map and listing text scale with scaffold size; the cause set scales with chain length without a fixed cap. The prompt closes its terminal interface before returning. This dispatcher owns no descriptor; queued stdout and stderr bytes belong to the process streams.
72
100
  */
73
101
  export async function run(argv: readonly string[]): Promise<number> {
74
102
  try {
@@ -83,80 +111,59 @@ export async function run(argv: readonly string[]): Promise<number> {
83
111
  process.stdout.write(`${packageVersion()}\n`);
84
112
  return 0;
85
113
  }
86
- if (command.command === "sync") {
87
- const targetDir: string = path.resolve(process.cwd(), command.directory);
88
- const result: ReturnType<typeof syncScaffold> = syncScaffold({
89
- location: targetDir,
90
- check: command.check,
91
- baseline: command.baseline,
114
+ if (command.command === "capture")
115
+ return await captureAutoMovie({
116
+ args: command.args,
117
+ root: process.cwd(),
118
+ env: process.env,
119
+ });
120
+ if (command.command === "inspect")
121
+ return await inspectAutoMovie({
122
+ args: command.args,
123
+ root: process.cwd(),
124
+ });
125
+ if (command.command === "render")
126
+ return await renderAutoMovie({
127
+ args: command.args,
128
+ root: process.cwd(),
129
+ env: process.env,
130
+ });
131
+ if (command.command === "review")
132
+ return await reviewAutoMovie({
133
+ args: command.args,
134
+ root: process.cwd(),
135
+ env: process.env,
92
136
  });
93
- process.stdout.write(
94
- `Scaffold sync ${result.status}: ${targetDir}\n` +
95
- [
96
- ...Object.keys(result.plan.files).map(
97
- (file: string): string => ` update ${file}`,
98
- ),
99
- ...result.plan.conflicts.map(
100
- (file: string): string => ` conflict ${file}`,
101
- ),
102
- ...result.plan.retired.map(
103
- (file: string): string =>
104
- ` retained retired instruction ${file}`,
105
- ),
106
- ].join("\n") +
107
- "\n",
108
- );
109
- if (result.receipt !== undefined && result.receipt.status !== "completed")
110
- throw new ScaffoldPublicationError(result.receipt);
111
- return result.status === "conflicted" ||
112
- (command.check && Object.keys(result.plan.files).length > 0)
113
- ? 1
114
- : 0;
115
- }
116
137
  if (command.command === "add") {
117
138
  const root: string = process.cwd();
118
139
  if (!fs.existsSync(path.join(root, "pnpm-workspace.yaml")))
119
140
  throw new Error(
120
141
  `add runs at an AutoMovie workspace root, and ${root} has no pnpm-workspace.yaml; create one with automovie create <directory> --workspace.`,
121
142
  );
122
- const targetDir: string = path.join(
123
- root,
124
- "movies",
125
- command.family,
126
- command.directory,
127
- );
128
- publish(
129
- targetDir,
130
- renderWorkspaceProductionScaffold({
143
+ write(
144
+ path.join(root, "movies", command.family, command.directory),
145
+ {
146
+ kind: "workspace-production",
131
147
  name: command.name ?? deriveAutoMovieProjectName(command.directory),
132
- }),
148
+ },
133
149
  command.force,
134
- "workspace-production",
135
150
  );
136
151
  return 0;
137
152
  }
138
153
 
139
154
  // Create: a typed or derived name, else the terminal's answer for the working directory itself.
140
- const targetDir: string = path.resolve(process.cwd(), command.directory);
141
- const name: string =
142
- selectAutoMovieProjectName({
143
- directory: command.directory,
144
- cwd: process.cwd(),
145
- ...(command.name === undefined ? {} : { name: command.name }),
146
- }) ?? (await promptAutoMovieProjectName());
147
- publish(
148
- targetDir,
149
- command.workspace
150
- ? renderWorkspaceScaffold({ name })
151
- : renderScaffold({ name }),
155
+ write(
156
+ path.resolve(process.cwd(), command.directory),
157
+ {
158
+ kind: command.workspace ? "workspace" : "production",
159
+ name:
160
+ selectAutoMovieProjectName({
161
+ directory: command.directory,
162
+ cwd: process.cwd(),
163
+ ...(command.name === undefined ? {} : { name: command.name }),
164
+ }) ?? (await promptAutoMovieProjectName()),
165
+ },
152
166
  command.force,
153
- command.workspace ? "workspace" : "production",
154
- selectAutoMoviePackageManager({
155
- directory: targetDir,
156
- ...(process.env.npm_config_user_agent === undefined
157
- ? {}
158
- : { userAgent: process.env.npm_config_user_agent }),
159
- }),
160
167
  );
161
168
  return 0;
162
169
  } catch (error) {
@@ -166,29 +173,33 @@ export async function run(argv: readonly string[]): Promise<number> {
166
173
  }
167
174
 
168
175
  /**
169
- * Publish one rendered installation, then list the written files and the next steps; a refused or partial receipt throws with its completed prefix.
176
+ * Write one created installation into `directory`, then list the written files and the next steps. A non-empty directory is refused unless `force` is set, which writes over same-path files and keeps every other file.
170
177
  */
171
- function publish(
172
- targetDir: string,
173
- files: Record<string, string>,
178
+ function write(
179
+ directory: string,
180
+ props: IAutoMovieScaffoldProps,
174
181
  force: boolean,
175
- kind: "production" | "workspace" | "workspace-production",
176
- packageManager?: IAutoMoviePackageManager,
177
182
  ): void {
178
- const receipt: IScaffoldPublicationReceipt = publishFiles(targetDir, files, {
179
- force,
180
- });
181
- if (receipt.status !== "completed")
182
- throw new ScaffoldPublicationError(receipt);
183
+ const files: Record<string, string> = createAutoMovieScaffold(props);
184
+ if (
185
+ force === false &&
186
+ fs.existsSync(directory) &&
187
+ fs.readdirSync(directory).length !== 0
188
+ )
189
+ throw new Error(
190
+ `${directory} is not empty; pass --force to write into it, replacing same-path files.`,
191
+ );
192
+ for (const [relative, content] of Object.entries(files)) {
193
+ const file: string = path.join(directory, relative);
194
+ fs.mkdirSync(path.dirname(file), { recursive: true });
195
+ fs.writeFileSync(file, content, "utf8");
196
+ }
183
197
  process.stdout.write(
184
- `Scaffolded ${receipt.completed.length} files into ${targetDir}\n\n` +
185
- receipt.completed
186
- .map(
187
- ({ entry }: IScaffoldCompletedPublication): string =>
188
- ` ${entry.relative}`,
189
- )
198
+ `Scaffolded ${Object.keys(files).length} files into ${directory}\n\n` +
199
+ Object.keys(files)
200
+ .map((relative: string): string => ` ${relative}`)
190
201
  .join("\n") +
191
- renderAutoMovieScaffoldNextSteps(targetDir, kind, packageManager),
202
+ renderAutoMovieScaffoldNextSteps(directory, props.kind),
192
203
  );
193
204
  }
194
205
 
@@ -0,0 +1,50 @@
1
+ import { spawn } from "node:child_process";
2
+
3
+ /** Lines of FFmpeg's error output kept for a failure message. */
4
+ const TAIL: number = 12;
5
+
6
+ /**
7
+ * Run FFmpeg once with the given arguments, resolving with its error output when it exits as `accept` allows and rejecting otherwise.
8
+ *
9
+ * FFmpeg writes its log, including a probe of every input, to its error output, so that text is what callers read. By default only exit status 0 is accepted; a probe that names no output exits 1 by design and accepts it. A rejection names the binary, the exit status and the last lines of the log.
10
+ *
11
+ * @evidence contracts/development/common.md#meaningful-documentation States what is resolved, the acceptance rule and its default, and what a rejection names.
12
+ * @evidence contracts/development/implementation.md#principled-implementation `child_process.spawn` without a shell passes each argument as it is, so a path with spaces or quotes needs no escaping.
13
+ * @evidence contracts/development/implementation.md#clear-and-simple-structure Spawn, collect the error output, settle on exit.
14
+ * @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts A failed run is never retried, and a failure to start rejects with its cause.
15
+ * @evidence contracts/development/implementation.md#efficient-algorithms Linear in the log FFmpeg writes.
16
+ * @evidenceExclude contracts/development/implementation.md#reuse-equivalent-work Each run is its own process.
17
+ * @evidence contracts/development/implementation.md#bound-retention-and-release-resources The child process ends before the promise settles; its log is held until then.
18
+ */
19
+ export function runAutoMovieFfmpeg(
20
+ binary: string,
21
+ args: readonly string[],
22
+ accept: (code: number | null) => boolean = (code: number | null): boolean =>
23
+ code === 0,
24
+ ): Promise<string> {
25
+ return new Promise<string>(
26
+ (resolve: (log: string) => void, reject: (error: Error) => void): void => {
27
+ const child: ReturnType<typeof spawn> = spawn(binary, [...args], {
28
+ stdio: ["ignore", "ignore", "pipe"],
29
+ windowsHide: true,
30
+ });
31
+ let log: string = "";
32
+ child.stderr!.setEncoding("utf8");
33
+ child.stderr!.on("data", (chunk: string): void => {
34
+ log += chunk;
35
+ });
36
+ child.on("error", (error: Error): void =>
37
+ reject(new Error(`FFmpeg ${binary} did not start`, { cause: error })),
38
+ );
39
+ child.on("close", (code: number | null): void => {
40
+ if (accept(code)) resolve(log);
41
+ else
42
+ reject(
43
+ new Error(
44
+ `FFmpeg ${binary} exited with ${code}:\n${log.trimEnd().split(/\r?\n/u).slice(-TAIL).join("\n")}`,
45
+ ),
46
+ );
47
+ });
48
+ },
49
+ );
50
+ }
@@ -0,0 +1,105 @@
1
+ import * as path from "node:path";
2
+ import { promisify } from "node:util";
3
+
4
+ import { findAutoMovieFreePort } from "./findAutoMovieFreePort";
5
+ import { planAutoMovieModulePageViteConfig } from "./planAutoMovieModulePageViteConfig";
6
+ import { writeAutoMovieModulePage } from "./writeAutoMovieModulePage";
7
+
8
+ /**
9
+ * The part of the production's `vite` the capture host calls, declared structurally so the command loads the production's own Vite at run time.
10
+ */
11
+ interface IVite {
12
+ build(config: object): Promise<unknown>;
13
+ preview(config: object): Promise<{
14
+ resolvedUrls: { local: string[] } | null;
15
+ httpServer: { close(callback: (error?: Error) => void): void };
16
+ }>;
17
+ }
18
+
19
+ /**
20
+ * Build a draw-only page for a subject module with the production's Vite, serve it with `vite preview`, and return its address and the call that stops the server and deletes the build.
21
+ *
22
+ * The page is generated in a scratch folder under `<root>/node_modules/.cache/automovie/`: an `index.html` with no interface and a script that calls `installAutoMovieDraw` with the module's `subjects` export. The build takes `planAutoMovieModulePageViteConfig`, the one configuration both page hosts share: the production's `vite.config.ts` when it has one and its `public` folder as its public files, with the generated page as the only input, so a subject loads the assets and plugins the production's own page does. The preview listens on 127.0.0.1 at a free port with `strictPort`, so it never moves to another server's port.
23
+ *
24
+ * It rejects when the module does not exist, naming it, and when the build or the server fails, after deleting the scratch folder.
25
+ *
26
+ * @evidence contracts/development/common.md#meaningful-documentation States what is generated and where, how the build is configured and why, where the server listens, what the return holds, and the refusals.
27
+ * @evidence contracts/development/implementation.md#principled-implementation A built page served by `vite preview` does not rebuild or reload while pages draw, which the development server does on a new import; the scratch folder sits inside the production so bare imports resolve from its own dependencies.
28
+ * @evidence contracts/development/implementation.md#clear-and-simple-structure Generate through `writeAutoMovieModulePage`, which the inspector page shares, build, find a port, preview; the draw function and subjects are the page's.
29
+ * @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts The production's page and configuration file are left untouched; the generated page replaces only the build input.
30
+ * @evidence contracts/development/implementation.md#efficient-algorithms One build per host; every capture of the host reuses the served page.
31
+ * @evidence contracts/development/implementation.md#reuse-equivalent-work The built page serves every subject and round of one host.
32
+ * @evidence contracts/development/implementation.md#bound-retention-and-release-resources The server and the scratch folder are owned by the returned `close`, which stops one and deletes the other; a failed start deletes the folder before rejecting.
33
+ */
34
+ export async function serveAutoMovieDrawPage(props: {
35
+ /** The production's root folder. */
36
+ root: string;
37
+
38
+ /** Path of the subject module, relative to `root` or absolute. */
39
+ module: string;
40
+
41
+ /** The production's `vite`. */
42
+ vite: unknown;
43
+ }): Promise<{
44
+ /** Address of the draw page. */
45
+ url: string;
46
+
47
+ /** Stop the server and delete the build. */
48
+ close: () => Promise<void>;
49
+ }> {
50
+ const vite: IVite = props.vite as IVite;
51
+
52
+ // The generated page, in a scratch folder of this process.
53
+ const page: ReturnType<typeof writeAutoMovieModulePage> =
54
+ writeAutoMovieModulePage({
55
+ root: props.root,
56
+ module: props.module,
57
+ kind: "draw",
58
+ title: "draw",
59
+ body: "",
60
+ script: (specifier: string): string =>
61
+ `import { installAutoMovieDraw } from "@automovie/render";\nimport { subjects } from ${JSON.stringify(specifier)};\n\ninstallAutoMovieDraw(subjects);\n`,
62
+ });
63
+ const scratch: string = page.folder;
64
+ const remove: () => void = page.remove;
65
+
66
+ try {
67
+ // The production's configuration, with the generated page as the only input.
68
+ const outDir: string = path.join(scratch, "dist");
69
+ await vite.build({
70
+ ...planAutoMovieModulePageViteConfig(page),
71
+ base: "./",
72
+ build: {
73
+ outDir,
74
+ emptyOutDir: true,
75
+ target: "es2022",
76
+ reportCompressedSize: false,
77
+ chunkSizeWarningLimit: Number.MAX_SAFE_INTEGER,
78
+ rollupOptions: { input: path.join(scratch, "index.html") },
79
+ },
80
+ });
81
+
82
+ const port: number = await findAutoMovieFreePort();
83
+ const server: Awaited<ReturnType<IVite["preview"]>> = await vite.preview({
84
+ root: scratch,
85
+ configFile: false,
86
+ base: "./",
87
+ logLevel: "warn",
88
+ clearScreen: false,
89
+ build: { outDir },
90
+ preview: { host: "127.0.0.1", port, strictPort: true, open: false },
91
+ });
92
+ return {
93
+ url: `http://127.0.0.1:${port}/index.html`,
94
+ close: async (): Promise<void> => {
95
+ await promisify((done: (error?: Error) => void): void =>
96
+ server.httpServer.close(done),
97
+ )();
98
+ remove();
99
+ },
100
+ };
101
+ } catch (error) {
102
+ remove();
103
+ throw error;
104
+ }
105
+ }
@@ -0,0 +1,82 @@
1
+ import { findAutoMovieFreePort } from "./findAutoMovieFreePort";
2
+ import { planAutoMovieModulePageViteConfig } from "./planAutoMovieModulePageViteConfig";
3
+ import { writeAutoMovieModulePage } from "./writeAutoMovieModulePage";
4
+
5
+ /**
6
+ * The part of the production's `vite` the inspector page calls, declared structurally so the command loads the production's own Vite at run time.
7
+ */
8
+ interface IVite {
9
+ createServer(config: object): Promise<{
10
+ listen(): Promise<unknown>;
11
+ close(): Promise<void>;
12
+ }>;
13
+ }
14
+
15
+ /**
16
+ * Serve the inspector page over a subject module with the production's Vite in development mode, and return its address and the call that stops it.
17
+ *
18
+ * The page is written by `writeAutoMovieModulePage`, as the draw page is: one `div` and a script that calls `@automovie/viewer`'s `mountAutoMovieInspectorPage` with the module's `subjects` called on `props` and the window's `location` and `history`, the same call the scaffold's own page makes. The development server takes `planAutoMovieModulePageViteConfig`: the production's `vite.config.ts` and `public` folder and the page as the dependency scanner's entry, so dependencies are pre-bundled before the first load; listens on 127.0.0.1 at `port` or a free port with `strictPort`, and transforms the production's sources on request, so an edit is seen on the next reload.
19
+ *
20
+ * It rejects when the module does not exist, naming it, and when the server cannot start, after deleting the scratch folder.
21
+ *
22
+ * @evidence contracts/development/common.md#meaningful-documentation States what the page runs, which configuration serves it, where it listens and why a development server is used, what the return holds, and the refusals.
23
+ * @evidence contracts/development/implementation.md#principled-implementation A person inspecting edits sources between looks, so the page is served by Vite's development server, which compiles each module when the page asks for it; capture draws a built page instead because it must not reload between cells.
24
+ * @evidence contracts/development/implementation.md#clear-and-simple-structure Write the page, find a port, start the server; the inspector and the subjects are the page's.
25
+ * @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts The production's own page and configuration file are left untouched, and a taken port fails the start instead of moving to another.
26
+ * @evidence contracts/development/implementation.md#efficient-algorithms One server for the command's life; Vite compiles what the page imports.
27
+ * @evidenceExclude contracts/development/implementation.md#reuse-equivalent-work One page per command.
28
+ * @evidence contracts/development/implementation.md#bound-retention-and-release-resources The server and the scratch folder are owned by the returned `close`, which stops one and deletes the other; a failed start deletes the folder before rejecting.
29
+ */
30
+ export async function serveAutoMovieInspectorPage(props: {
31
+ /** The production's root folder. */
32
+ root: string;
33
+
34
+ /** Path of the subject module, relative to `root` or absolute. */
35
+ module: string;
36
+
37
+ /** The production's `vite`. */
38
+ vite: unknown;
39
+
40
+ /** The port to listen on, or null for a free one. */
41
+ port: number | null;
42
+
43
+ /** The JSON value the module's `subjects` is called with, null for none. */
44
+ props: unknown;
45
+ }): Promise<{
46
+ /** Address of the inspector page, without a query. */
47
+ url: string;
48
+
49
+ /** Stop the server and delete the page. */
50
+ close: () => Promise<void>;
51
+ }> {
52
+ const vite: IVite = props.vite as IVite;
53
+ const page: ReturnType<typeof writeAutoMovieModulePage> =
54
+ writeAutoMovieModulePage({
55
+ root: props.root,
56
+ module: props.module,
57
+ kind: "inspect",
58
+ title: "AutoMovie inspector",
59
+ body: `<div id="root"></div>`,
60
+ script: (specifier: string): string =>
61
+ `import { mountAutoMovieInspectorPage } from "@automovie/viewer";\nimport { subjects } from ${JSON.stringify(specifier)};\n\nmountAutoMovieInspectorPage({\n root: document.getElementById("root"),\n subjects: subjects(${JSON.stringify(props.props ?? null)}),\n location: window.location,\n history: window.history,\n});\n`,
62
+ });
63
+ try {
64
+ const port: number = props.port ?? (await findAutoMovieFreePort());
65
+ const server: Awaited<ReturnType<IVite["createServer"]>> =
66
+ await vite.createServer({
67
+ ...planAutoMovieModulePageViteConfig(page),
68
+ server: { host: "127.0.0.1", port, strictPort: true, open: false },
69
+ });
70
+ await server.listen();
71
+ return {
72
+ url: `http://127.0.0.1:${port}/`,
73
+ close: async (): Promise<void> => {
74
+ await server.close();
75
+ page.remove();
76
+ },
77
+ };
78
+ } catch (error) {
79
+ page.remove();
80
+ throw error;
81
+ }
82
+ }
@@ -0,0 +1,83 @@
1
+ import * as fs from "node:fs";
2
+ import * as path from "node:path";
3
+
4
+ /**
5
+ * Write a one-script page over a subject module into a scratch folder of the production, with the Vite configuration and public folder the production's own page uses, for the draw page and the inspector page alike.
6
+ *
7
+ * The folder is `<root>/node_modules/.cache/automovie/<kind>-<pid>-<time>`, inside the production so the page's bare imports resolve from the production's own dependencies. It holds an `index.html` with `body` and a `main.js` whose text `script` writes from the module's import specifier, a path relative to the folder with the module's own extension, so the page imports exactly the named file even where a compiled `.js` lies beside it. `configFile` is the production's `vite.config.ts` when it has one, and `publicDir` its `public` folder when it has one, `false` otherwise.
8
+ *
9
+ * It throws naming the module when the module does not exist, before anything is written.
10
+ *
11
+ * @evidence contracts/development/common.md#meaningful-documentation States where the page is written and why, what it holds, what the specifier is, what the configuration fields hold, and the refusal.
12
+ * @evidence contracts/development/implementation.md#principled-implementation Node resolves a bare import from the importing file's folder upward, so a page written inside the production imports the production's installed packages; Vite compiles a relative import of a `.ts` file named with its extension, and the extension keeps resolution from preferring a stale `.js` beside it.
13
+ * @evidence contracts/development/implementation.md#clear-and-simple-structure Check, write two files, report the folder and its configuration; what the page runs is the caller's.
14
+ * @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts The production's own page and configuration file are only read, never changed.
15
+ * @evidence contracts/development/implementation.md#efficient-algorithms Two small writes and three existence checks.
16
+ * @evidenceExclude contracts/development/implementation.md#reuse-equivalent-work One page per host.
17
+ * @evidence contracts/development/implementation.md#bound-retention-and-release-resources The returned `remove` deletes the folder; the caller owns it from the return on.
18
+ */
19
+ export function writeAutoMovieModulePage(props: {
20
+ /** The production's root folder. */
21
+ root: string;
22
+
23
+ /** Path of the subject module, relative to `root` or absolute. */
24
+ module: string;
25
+
26
+ /** A short name for the page, the start of the scratch folder's name, such as `draw` or `inspect`. */
27
+ kind: string;
28
+
29
+ /** The page's title. */
30
+ title: string;
31
+
32
+ /** The body's markup before the script. */
33
+ body: string;
34
+
35
+ /** The text of `main.js`, given the module's import specifier. */
36
+ script: (specifier: string) => string;
37
+ }): {
38
+ /** The scratch folder, the page's Vite root. */
39
+ folder: string;
40
+
41
+ /** The production's `vite.config.ts`, or `false` when it has none. */
42
+ configFile: string | false;
43
+
44
+ /** The production's `public` folder, or `false` when it has none. */
45
+ publicDir: string | false;
46
+
47
+ /** Delete the scratch folder. */
48
+ remove: () => void;
49
+ } {
50
+ const module: string = path.resolve(props.root, props.module);
51
+ if (!fs.existsSync(module))
52
+ throw new Error(`The subject module ${module} does not exist`);
53
+
54
+ const folder: string = path.join(
55
+ props.root,
56
+ "node_modules",
57
+ ".cache",
58
+ "automovie",
59
+ `${props.kind}-${process.pid}-${Date.now()}`,
60
+ );
61
+ fs.mkdirSync(folder, { recursive: true });
62
+ const relative: string = path
63
+ .relative(folder, module)
64
+ .split(path.sep)
65
+ .join("/");
66
+ fs.writeFileSync(
67
+ path.join(folder, "index.html"),
68
+ `<!doctype html>\n<html><head><meta charset="utf-8" /><title>${props.title}</title></head><body>${props.body}<script type="module" src="./main.js"></script></body></html>\n`,
69
+ );
70
+ fs.writeFileSync(
71
+ path.join(folder, "main.js"),
72
+ props.script(relative.startsWith(".") ? relative : `./${relative}`),
73
+ );
74
+
75
+ const config: string = path.join(props.root, "vite.config.ts");
76
+ const publicDir: string = path.join(props.root, "public");
77
+ return {
78
+ folder,
79
+ configFile: fs.existsSync(config) ? config : false,
80
+ publicDir: fs.existsSync(publicDir) ? publicDir : false,
81
+ remove: (): void => fs.rmSync(folder, { recursive: true, force: true }),
82
+ };
83
+ }
@@ -1,14 +0,0 @@
1
- /**
2
- * The package manager a created production's next steps name, with the enclosing pnpm workspace root when one exists.
3
- *
4
- * @evidence contracts/development/design.md#principled-representation The manager and the optional workspace root are exactly what `renderAutoMovieScaffoldNextSteps` needs to print the install location and script commands.
5
- * @evidence contracts/development/design.md#minimal-and-owned-surface A closed pair of managers, the two the scaffold documents; `selectAutoMoviePackageManager` produces it and the next-steps renderer consumes it.
6
- * @evidence contracts/development/design.md#prohibited-design-shortcuts No free-form manager string or command template lets a caller print undocumented commands.
7
- * @evidence contracts/development/common.md#meaningful-documentation Each member states what it controls in the printed steps.
8
- */
9
- export interface IAutoMoviePackageManager {
10
- /** The manager whose install and script commands the next steps print. */
11
- manager: "npm" | "pnpm";
12
- /** Absolute root of the enclosing pnpm workspace, where `pnpm install` runs. */
13
- workspace?: string;
14
- }