demoman 0.7.1 → 0.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/demoman.mjs CHANGED
@@ -16,7 +16,7 @@ import { homedir as homedir4 } from "node:os";
16
16
  import { join as join29, resolve as resolve3 } from "node:path";
17
17
  import { createInterface } from "node:readline";
18
18
  import { fileURLToPath as fileURLToPath6 } from "node:url";
19
- import { parseArgs } from "node:util";
19
+ import { parseArgs as parseArgs2 } from "node:util";
20
20
 
21
21
  // ../mcp/dist/serve-cli.js
22
22
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
@@ -39,7 +39,7 @@ This server runs them in its own browser on this machine: signed in only where t
39
39
  3. run(script) \u2014 answers its report or {outcome: "stillRunning", id}; then call report(id) until the outcome is none of "running", "stillRunning". Fix what is the script's to fix. Stop after three runs, done or not.
40
40
  4. export(takeId) \u2014 may answer stillRunning; call report(id) until the outcome is none of "exporting", "stillRunning". On "saved", file.path is the video's absolute path (folder.path for stills; in ~/Downloads unless this server was started with --out-dir). End on summary, then its links as markdown links on one line (recipe: hand back).
41
41
 
42
- When the studio tool is listed and no links.studio is in hand, offer studio({ takeId }) after a run, a window where the user can edit and export the take; never open it unasked.
42
+ When the Studio tool is listed and no links.studio is in hand, offer studio({ takeId }) after a run, a window where the user can edit and export the take; never open it unasked.
43
43
 
44
44
  Before opening a pull request, check status.pullRequests; the recipe says when to record and attach.
45
45
 
@@ -60,6 +60,7 @@ function localLink(executor) {
60
60
  import { execFile } from "node:child_process";
61
61
  import { randomBytes } from "node:crypto";
62
62
  import { createServer } from "node:http";
63
+ import { pathToFileURL } from "node:url";
63
64
  var run = (file, args2) => new Promise((resolve4, reject) => {
64
65
  execFile(file, args2, (error, stdout, stderr) => {
65
66
  if (error === null)
@@ -68,9 +69,6 @@ var run = (file, args2) => new Promise((resolve4, reject) => {
68
69
  reject(new Error(stderr.trim() || error.message));
69
70
  });
70
71
  });
71
- async function revealInFinder(path) {
72
- await run("open", ["-R", path]);
73
- }
74
72
  async function copyFileToClipboard(path) {
75
73
  const said = await run("osascript", [
76
74
  "-e",
@@ -96,15 +94,15 @@ async function copyFileToClipboard(path) {
96
94
  }
97
95
  }
98
96
  var escapeHtml = (s) => s.replace(/[&<>"']/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" })[c]);
99
- var page = (text) => `<!doctype html>
97
+ var CLOSE = "<script>window.close()</script>";
98
+ var page = (text, close) => `<!doctype html>
100
99
  <meta charset="utf-8"><title>Demoman</title>
101
100
  <meta name="color-scheme" content="light dark">
102
101
  <body style="font:15px/1.5 system-ui,sans-serif;margin:40px">
103
- <p>${escapeHtml(text)}</p>`;
102
+ <p>${escapeHtml(text)}</p>${close ? CLOSE : ""}`;
104
103
  var messageOf = (e) => e instanceof Error ? e.message : String(e);
105
104
  var nameOf = (path) => path.split("/").pop() ?? path;
106
105
  function createSessionLinks(deps) {
107
- const reveal = deps.reveal ?? revealInFinder;
108
106
  const copy = deps.copy ?? copyFileToClipboard;
109
107
  const mac = (deps.platform ?? process.platform) === "darwin";
110
108
  const exports = /* @__PURE__ */ new Map();
@@ -114,15 +112,12 @@ function createSessionLinks(deps) {
114
112
  switch (action) {
115
113
  case "studio": {
116
114
  if (deps.studio === void 0)
117
- throw new Error("no studio here");
115
+ throw new Error("no Studio here");
118
116
  const answer = await deps.studio({ takeId: saved.takeId });
119
117
  if ("reason" in answer)
120
118
  throw new Error(answer.detail);
121
- return answer.note === void 0 ? "Opened in the studio." : `Opened in the studio. ${answer.note}`;
119
+ return answer.note === void 0 ? "Opened in the Studio." : `Opened in the Studio. ${answer.note}`;
122
120
  }
123
- case "reveal":
124
- await reveal(saved.path);
125
- return `Revealed ${nameOf(saved.path)} in Finder.`;
126
121
  case "copy":
127
122
  await copy(saved.path);
128
123
  return `Copied ${nameOf(saved.path)}.`;
@@ -137,7 +132,7 @@ function createSessionLinks(deps) {
137
132
  const saved = exports.get(token);
138
133
  const reply = (status, text) => {
139
134
  res.writeHead(status, { "Content-Type": "text/html; charset=utf-8" });
140
- res.end(page(text));
135
+ res.end(page(text, status === 200));
141
136
  };
142
137
  if (req.method !== "GET" || saved === void 0) {
143
138
  reply(404, "This is not a link this Demoman session made.");
@@ -175,7 +170,7 @@ function createSessionLinks(deps) {
175
170
  const at2 = (action) => `http://127.0.0.1:${port}/${action}/${token}`;
176
171
  return {
177
172
  ...deps.studio === void 0 ? {} : { studio: at2("studio") },
178
- ...mac ? { reveal: at2("reveal") } : {},
173
+ file: pathToFileURL(saved.path).href,
179
174
  ...mac && saved.isFile ? { copy: at2("copy") } : {}
180
175
  };
181
176
  },
@@ -1219,8 +1214,9 @@ var BRANDING_DEFAULTS = Object.freeze({
1219
1214
  background: NEUTRAL_BACKGROUND,
1220
1215
  logo: null,
1221
1216
  /**
1222
- * 8%: Screen Studio's margin, near enough (measured 8.4% on 2026-10-05),
1223
- * and the smallest padding that draws the default logo at full size.
1217
+ * 8%: the margin of a polished recording, near enough (8.4% measured on
1218
+ * 2026-10-05), and the smallest padding that draws the default logo at
1219
+ * full size.
1224
1220
  * `placeLogo` keeps a mark 0.02 × short in from the edge and clear of the
1225
1221
  * recording, so a logo of size `s` fits only when the padding is at least
1226
1222
  * `s + 0.02`, and `LOGO_DEFAULTS.size` is 0.06.
@@ -4646,6 +4642,15 @@ var SHARE_VERTICAL = {
4646
4642
  fit: "cover",
4647
4643
  encoder: { quality: 0.5 }
4648
4644
  };
4645
+ var HIGH_LANDSCAPE = {
4646
+ ...LANDSCAPE_1440P,
4647
+ bitrate: 8e6
4648
+ };
4649
+ var HIGH_MAX_BITRATE = 1e7;
4650
+ var HIGH_VERTICAL = {
4651
+ ...VERTICAL_1080,
4652
+ bitrate: HIGH_LANDSCAPE.bitrate
4653
+ };
4649
4654
  var GIF_800 = {
4650
4655
  format: "gif",
4651
4656
  width: 800,
@@ -5270,8 +5275,11 @@ function withSummary(report) {
5270
5275
  return { ...report, summary: exportVerdict(report) };
5271
5276
  }
5272
5277
  function exportCaveats(report) {
5273
- const { logo, unavailableSpans, migration, editedSinceRecorded: editedSinceRecorded2, masks, unplacedStills, gifSize } = report.warnings;
5278
+ const { logo, unavailableSpans, migration, editedSinceRecorded: editedSinceRecorded2, masks, unplacedStills, gifSize, videoSize } = report.warnings;
5274
5279
  return [
5280
+ ...videoSize?.settingUnreadable === void 0 ? [] : [
5281
+ `it is ${videoSize.quality} quality, not your Export quality setting, which could not be read (${videoSize.settingUnreadable.replace(/\.$/, "")})`
5282
+ ],
5275
5283
  ...logo === null ? [] : [`the logo is missing (${logo})`],
5276
5284
  ...unavailableSpans.length === 0 ? [] : [
5277
5285
  `${plural2(unavailableSpans.length, "stretch of motion is a still", "stretches of motion are stills")}`
@@ -5322,7 +5330,13 @@ function exportVerdict(report) {
5322
5330
  }
5323
5331
 
5324
5332
  // ../../packages/run-core/dist/export/target.js
5325
- var EXPORT_QUALITY_VALUES = ["share", "full"];
5333
+ var EXPORT_QUALITY_VALUES = ["share", "high", "full"];
5334
+ var EXPORT_QUALITY_LABELS = {
5335
+ share: "Sharing",
5336
+ high: "High",
5337
+ full: "Full"
5338
+ };
5339
+ var DEFAULT_EXPORT_QUALITY = "high";
5326
5340
  var isExportQuality = (v) => typeof v === "string" && EXPORT_QUALITY_VALUES.includes(v);
5327
5341
  function frameOf(scene) {
5328
5342
  return {
@@ -5356,15 +5370,19 @@ function shareTier(tier) {
5356
5370
  bitrate: Math.round(SHARE_LANDSCAPE.bitrate * tier.width * tier.height / (SHARE_LANDSCAPE.width * SHARE_LANDSCAPE.height))
5357
5371
  };
5358
5372
  }
5373
+ function highTier(tier) {
5374
+ return tier.width >= HIGH_LANDSCAPE.width ? HIGH_LANDSCAPE : { ...tier, bitrate: Math.min(tier.bitrate, HIGH_LANDSCAPE.bitrate) };
5375
+ }
5359
5376
  function targetFor(fileType, aspect, bundle, frame, options = {}) {
5360
- const share = fileType === "mp4" && options.quality === "share";
5377
+ const quality = fileType === "mp4" ? options.quality ?? "full" : "full";
5361
5378
  if (aspect !== "9:16") {
5362
5379
  const tier = landscapeTier(fileType, bundle, aspect, options.maxTier);
5363
- return landscapeFrame(aspect, share ? shareTier(tier) : tier, recordingOf(bundle, frame), frame.padding);
5380
+ const shaped = landscapeFrame(aspect, quality === "share" ? shareTier(tier) : quality === "high" ? highTier(tier) : tier, recordingOf(bundle, frame), frame.padding);
5381
+ return quality === "high" && shaped.bitrate > HIGH_MAX_BITRATE ? { ...shaped, bitrate: HIGH_MAX_BITRATE } : shaped;
5364
5382
  }
5365
5383
  switch (fileType) {
5366
5384
  case "mp4":
5367
- return share ? SHARE_VERTICAL : VERTICAL_1080;
5385
+ return quality === "share" ? SHARE_VERTICAL : quality === "high" ? HIGH_VERTICAL : VERTICAL_1080;
5368
5386
  case "gif":
5369
5387
  return GIF_VERTICAL_450;
5370
5388
  case "stills":
@@ -5436,6 +5454,11 @@ function checkLogoFile(file) {
5436
5454
 
5437
5455
  // ../../packages/run-core/dist/pull-requests.js
5438
5456
  var PULL_REQUESTS_VALUES = ["off", "ask", "attach"];
5457
+ var PULL_REQUESTS_LABELS = {
5458
+ off: "Off",
5459
+ ask: "Ask",
5460
+ attach: "Attach"
5461
+ };
5439
5462
  var PULL_REQUESTS_DEFAULT = "ask";
5440
5463
  var isPullRequestsValue = (v) => typeof v === "string" && PULL_REQUESTS_VALUES.includes(v);
5441
5464
 
@@ -10303,7 +10326,7 @@ var DESCRIPTIONS = {
10303
10326
  snapshot: `Open url in this server's own browser \u2014 signed in where the user ran npx demoman signin, or as a demo account (account; project: absolute path) \u2014 and ${SNAPSHOT_TARGETS} kits is {ok: true, kits: [{name, default, valid}]}: the user's brand kits; name one in a script's look.kit (with scriptVersion 2) only when the user asked for that look; {ok: false, reason} means unreadable: name none. landedElsewhere true means the app redirected: session "signedOut" (or a plain sign-in landedUrl with "none"/"unchecked") means a sign-in page: spend no run; set up a demo account (recipe) or give the user sessionDetail's command (npx demoman signin <the page>). signedIn means Demoman signed in first. If landedUrl is not a sign-in page, use it as the target. ${SNAPSHOT_TAIL} Past about 50 s it answers {outcome: "stillRunning", id}; then call report with that id.`,
10304
10327
  takes: "The takes this demoman-mcp's own browser made, newest first: id, name, createdAt, mode, actions. A folder that is not a readable take comes last as {id, unreadable}, saying why. Not the user's Demoman library in their browser.",
10305
10328
  run: `Run a DemoScript in this demoman-mcp's own browser (signed in where the user ran npx demoman signin, or as the account the script names, at scriptVersion 5; project is the absolute path of another checkout) and answer its report, which carries account and signedIn; the take is saved on disk. Pass {takeId} instead of {script} to re-record a take whose scene.json was edited: a new take, counted as a run. A second run or snapshot while one is in progress is refused (alreadyRunning). Answers {outcome: "stillRunning", id} if it takes longer than about 50 s; then call report with that id.`,
10306
- export: `Render a take this server made to an MP4, a GIF (fileType "gif") or a folder of PNG stills, one per step (fileType "stills"; stills.width in px or "native", stills.zoom "none" or "step"; MP4 quality "full" for the largest file, default "share": as small as stays crisp; maxMB caps an MP4's size, lowering fps, then size, then quality), and save it on this machine \u2014 in ~/Downloads, or the folder demoman-mcp was started with --out-dir \u2014 in the take's frame (Auto, 16:9 or 9:16) and branding, logo included. Answers the export report; on "saved", file.path is the file's absolute path, or folder.path the stills folder's, summary is the sentence to give the user, and links holds one-click links for them (studio, reveal, copy; linksError says why there are none). A second export, run or snapshot while one is in progress is refused (busy, alreadyRunning). Past about 50 s it answers {outcome: "stillRunning", id}; then call report with that id.`
10329
+ export: `Render a take this server made to an MP4, a GIF (fileType "gif") or a folder of PNG stills, one per step (fileType "stills"; stills.width in px or "native", stills.zoom "none" or "step"; MP4 quality: absent, the user's Export quality setting, "high" unless they changed it (60 fps, about 30 MB for 30 s); "share" as small as stays crisp, the default with maxMB; "full" the largest file; maxMB caps an MP4's size, lowering fps, then size, then quality), and save it on this machine \u2014 in ~/Downloads, or the folder demoman-mcp was started with --out-dir \u2014 in the take's frame (Auto, 16:9 or 9:16) and branding, logo included. Answers the export report; on "saved", file.path is the file's absolute path, or folder.path the stills folder's, summary is the sentence to give the user, and links holds one-click links for them (studio, file, copy; linksError says why there are none). A second export, run or snapshot while one is in progress is refused (busy, alreadyRunning). Past about 50 s it answers {outcome: "stillRunning", id}; then call report with that id.`
10307
10330
  };
10308
10331
  function registerTools(server, bare2, options) {
10309
10332
  const link = {
@@ -10755,11 +10778,11 @@ var PAGE_ENTRIES = [
10755
10778
  "render-entry",
10756
10779
  "mux-entry"
10757
10780
  ];
10758
- function pageBuildOptions(entryPath) {
10781
+ function pageBuildOptions(entryPath2) {
10759
10782
  return {
10760
10783
  absWorkingDir: APP_ROOT,
10761
10784
  bundle: true,
10762
- entryPoints: [entryPath],
10785
+ entryPoints: [entryPath2],
10763
10786
  format: "iife",
10764
10787
  // The runner drives the Chromium that Playwright pins, so nothing here
10765
10788
  // needs transpiling further back than that. Kept explicit so a bundle
@@ -10773,10 +10796,10 @@ var prebuiltDir = null;
10773
10796
  function usePrebuiltPages(dir) {
10774
10797
  prebuiltDir = dir;
10775
10798
  }
10776
- async function readPrebuilt(dir, entryPath) {
10777
- const name = basename(entryPath).replace(/\.(ts|js)$/, "");
10799
+ async function readPrebuilt(dir, entryPath2) {
10800
+ const name = basename(entryPath2).replace(/\.(ts|js)$/, "");
10778
10801
  if (!PAGE_ENTRIES.includes(name)) {
10779
- throw new Error(`${basename(entryPath)} has no prebuilt page bundle; this install ships ${PAGE_ENTRIES.join(", ")}`);
10802
+ throw new Error(`${basename(entryPath2)} has no prebuilt page bundle; this install ships ${PAGE_ENTRIES.join(", ")}`);
10780
10803
  }
10781
10804
  const file = join3(dir, `${name}.js`);
10782
10805
  const text = await readFile2(file, "utf8");
@@ -10784,14 +10807,14 @@ async function readPrebuilt(dir, entryPath) {
10784
10807
  throw new Error(`the prebuilt page bundle ${file} is empty`);
10785
10808
  return text;
10786
10809
  }
10787
- async function bundleEntry(entryPath) {
10810
+ async function bundleEntry(entryPath2) {
10788
10811
  if (prebuiltDir !== null)
10789
- return readPrebuilt(prebuiltDir, entryPath);
10812
+ return readPrebuilt(prebuiltDir, entryPath2);
10790
10813
  const { build } = await import("esbuild");
10791
- const result = await build(pageBuildOptions(entryPath));
10814
+ const result = await build(pageBuildOptions(entryPath2));
10792
10815
  const text = result.outputFiles?.[0]?.text;
10793
10816
  if (text === void 0 || text === "") {
10794
- throw new Error(`esbuild produced no output for ${entryPath} (it reported no error)`);
10817
+ throw new Error(`esbuild produced no output for ${entryPath2} (it reported no error)`);
10795
10818
  }
10796
10819
  return text;
10797
10820
  }
@@ -12611,7 +12634,7 @@ async function signInAccount(chosen, deps) {
12611
12634
  import { randomUUID as randomUUID3 } from "node:crypto";
12612
12635
  import { copyFile, mkdir as mkdir5, rm as rm4 } from "node:fs/promises";
12613
12636
  import { tmpdir } from "node:os";
12614
- import { basename as basename3, join as join9 } from "node:path";
12637
+ import { basename as basename3, join as join10 } from "node:path";
12615
12638
 
12616
12639
  // ../runner/dist/executor/export.js
12617
12640
  import { randomUUID as randomUUID2 } from "node:crypto";
@@ -12930,11 +12953,89 @@ async function checkExportFolder(dir) {
12930
12953
  return null;
12931
12954
  }
12932
12955
 
12956
+ // ../runner/dist/executor/user-settings.js
12957
+ import { readFile as readFile7 } from "node:fs/promises";
12958
+ import { join as join9 } from "node:path";
12959
+ var settingsWith = (settings, problems) => {
12960
+ const said = [problems.exportQuality, problems.pullRequests].filter((p) => p !== void 0);
12961
+ if (said.length === 0)
12962
+ return settings;
12963
+ return { ...settings, problems, unreadable: [...new Set(said)].join("; ") };
12964
+ };
12965
+ async function readUserSettings(home) {
12966
+ const path = join9(home, "settings.json");
12967
+ const defaults = {
12968
+ exportQuality: DEFAULT_EXPORT_QUALITY,
12969
+ pullRequests: null
12970
+ };
12971
+ let text;
12972
+ try {
12973
+ text = await readFile7(path, "utf8");
12974
+ } catch (error) {
12975
+ if (error.code === "ENOENT")
12976
+ return defaults;
12977
+ const said = `${path} could not be read (${messageOf4(error)})`;
12978
+ return settingsWith(defaults, { exportQuality: said, pullRequests: said });
12979
+ }
12980
+ const raw = parsed(path, text);
12981
+ if ("unreadable" in raw) {
12982
+ return settingsWith(defaults, {
12983
+ exportQuality: raw.unreadable,
12984
+ pullRequests: raw.unreadable
12985
+ });
12986
+ }
12987
+ const pr = pullRequestsIn(path, raw.object);
12988
+ const quality = raw.object.exportQuality;
12989
+ const qualityBad = quality !== void 0 && !isExportQuality(quality);
12990
+ return settingsWith({
12991
+ exportQuality: isExportQuality(quality) ? quality : DEFAULT_EXPORT_QUALITY,
12992
+ pullRequests: "unreadable" in pr ? null : pr.value
12993
+ }, {
12994
+ ...qualityBad ? {
12995
+ exportQuality: `${path}: exportQuality must be ${EXPORT_QUALITY_VALUES.join(", ")}; got ${JSON.stringify(quality)}`
12996
+ } : {},
12997
+ ..."unreadable" in pr ? { pullRequests: pr.unreadable } : {}
12998
+ });
12999
+ }
13000
+ function parsed(path, text) {
13001
+ let raw;
13002
+ try {
13003
+ raw = JSON.parse(text);
13004
+ } catch (error) {
13005
+ return { unreadable: `${path} is not valid JSON (${messageOf4(error)})` };
13006
+ }
13007
+ if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
13008
+ return { unreadable: `${path} must hold a JSON object` };
13009
+ }
13010
+ return { object: raw };
13011
+ }
13012
+ function pullRequestsIn(path, object) {
13013
+ const value = object.pullRequests;
13014
+ if (value === void 0)
13015
+ return { value: null };
13016
+ if (!isPullRequestsValue(value)) {
13017
+ return {
13018
+ unreadable: `${path}: pullRequests must be off, ask or attach; got ${JSON.stringify(value)}`
13019
+ };
13020
+ }
13021
+ return { value };
13022
+ }
13023
+ function parsePullRequests(path, text) {
13024
+ const raw = parsed(path, text);
13025
+ return "unreadable" in raw ? raw : pullRequestsIn(path, raw.object);
13026
+ }
13027
+
12933
13028
  // ../runner/dist/executor/export.js
12934
13029
  var FILE_TYPES = ["mp4", "gif", "stills"];
12935
13030
  async function exportTake(args2, deps, onProgress) {
12936
13031
  const { library } = deps;
12937
- const refused2 = (reason, detail) => withSummary({ outcome: "refusedBeforeExport", reason, detail });
13032
+ let settingUnreadable;
13033
+ const told = (answer) => settingUnreadable === void 0 || answer.outcome === "saved" ? answer : {
13034
+ ...answer,
13035
+ settingUnreadable,
13036
+ summary: `${answer.summary} Your Export quality setting could not be read either: ${settingUnreadable.replace(/\.$/, "")}.`
13037
+ };
13038
+ const refused2 = (reason, detail) => told(withSummary({ outcome: "refusedBeforeExport", reason, detail }));
12938
13039
  const takeId = typeof args2.takeId === "string" ? args2.takeId.trim() : "";
12939
13040
  if (takeId === "")
12940
13041
  return refused2("noTakeId", "no take id was given");
@@ -12952,7 +13053,9 @@ async function exportTake(args2, deps, onProgress) {
12952
13053
  const stills = stillsOptionsOf(args2.stills, asked);
12953
13054
  if (typeof stills === "string")
12954
13055
  return refused2("invalidStillsOptions", stills);
12955
- const quality = qualityOf(args2.quality, asked);
13056
+ const fallback = args2.maxMB !== void 0 ? { quality: "share" } : args2.quality === void 0 && asked === "mp4" ? await settingsQuality(deps) : { quality: DEFAULT_EXPORT_QUALITY };
13057
+ settingUnreadable = fallback.unreadable;
13058
+ const quality = qualityOf(args2.quality, asked, fallback.quality);
12956
13059
  if (typeof quality === "object") {
12957
13060
  return refused2("invalidQuality", quality.refusal);
12958
13061
  }
@@ -12992,6 +13095,7 @@ async function exportTake(args2, deps, onProgress) {
12992
13095
  asked,
12993
13096
  stills,
12994
13097
  quality,
13098
+ ...settingUnreadable === void 0 ? {} : { settingUnreadable },
12995
13099
  maxBytes,
12996
13100
  scene,
12997
13101
  notes,
@@ -13000,7 +13104,7 @@ async function exportTake(args2, deps, onProgress) {
13000
13104
  deps,
13001
13105
  onProgress
13002
13106
  });
13003
- return answer.outcome === "saved" ? await listed(answer, takeId, scene, deps) : answer;
13107
+ return answer.outcome === "saved" ? await listed(answer, takeId, scene, deps) : told(answer);
13004
13108
  } finally {
13005
13109
  try {
13006
13110
  await lease.release();
@@ -13034,7 +13138,7 @@ async function listed(answer, takeId, scene, deps) {
13034
13138
  }
13035
13139
  }
13036
13140
  async function exportLeased(a) {
13037
- const { takeId, asked, stills, quality, maxBytes, scene, notes, bundle, store, deps, onProgress } = a;
13141
+ const { takeId, asked, stills, quality, settingUnreadable, maxBytes, scene, notes, bundle, store, deps, onProgress } = a;
13038
13142
  const { library } = deps;
13039
13143
  const aspect = scene.canvas.aspect;
13040
13144
  const target = targetFor(asked, aspect, bundle, frameOf(scene), {
@@ -13198,17 +13302,26 @@ async function exportLeased(a) {
13198
13302
  videoSize: {
13199
13303
  quality,
13200
13304
  byteLength: file.bytes.byteLength,
13305
+ ...settingUnreadable === void 0 ? {} : { settingUnreadable },
13201
13306
  ...rendered.videoCap === void 0 ? {} : { cap: rendered.videoCap }
13202
13307
  }
13203
13308
  } : {}
13204
13309
  }));
13205
13310
  }
13206
- function qualityOf(given, fileType) {
13311
+ async function settingsQuality(deps) {
13312
+ const settings = await readUserSettings(deps.home);
13313
+ const unreadable = settings.problems?.exportQuality;
13314
+ if (unreadable === void 0)
13315
+ return { quality: settings.exportQuality };
13316
+ deps.log(`export: Export quality is ${settings.exportQuality}: ${unreadable}`);
13317
+ return { quality: settings.exportQuality, unreadable };
13318
+ }
13319
+ function qualityOf(given, fileType, fallback) {
13207
13320
  if (given === void 0)
13208
- return "share";
13321
+ return fallback;
13209
13322
  if (!isExportQuality(given)) {
13210
13323
  return {
13211
- refusal: `quality is "share" (as small as stays crisp, the default) or "full" (the largest file), not ${JSON.stringify(given) ?? typeof given}`
13324
+ refusal: `quality is "high" (60 fps, about 30 MB for 30 s, the default), "share" (as small as stays crisp, for GitHub) or "full" (the largest file), not ${JSON.stringify(given) ?? typeof given}`
13212
13325
  };
13213
13326
  }
13214
13327
  if (fileType !== "mp4") {
@@ -13380,7 +13493,12 @@ async function attachTake(raw, deps, onProgress) {
13380
13493
  if ("unreadable" in before) {
13381
13494
  return refuse("prUnreadable", `pull request ${pr.url} could not be read (${before.unreadable}); attach reads it before posting so it can tell afterwards what landed. Nothing was exported or posted.`);
13382
13495
  }
13383
- const exported = await exportTake({ takeId: a.takeId, ...a.maxMB === void 0 ? {} : { maxMB: a.maxMB } }, deps.export, (p) => onProgress({
13496
+ const exported = await exportTake({
13497
+ takeId: a.takeId,
13498
+ // GitHub's own size, whatever the default for other exports is.
13499
+ quality: "share",
13500
+ ...a.maxMB === void 0 ? {} : { maxMB: a.maxMB }
13501
+ }, deps.export, (p) => onProgress({
13384
13502
  outcome: "attaching",
13385
13503
  phase: p.phase,
13386
13504
  done: p.done,
@@ -13396,8 +13514,8 @@ async function attachTake(raw, deps, onProgress) {
13396
13514
  const { file } = exported;
13397
13515
  const label = await labelOf(a.takeId, deps, file.path);
13398
13516
  const into = a.into;
13399
- const folder = join9(deps.tmpDir ?? tmpdir(), `demoman-attach-${randomUUID3()}`);
13400
- const posted = join9(folder, plainName(file.path));
13517
+ const folder = join10(deps.tmpDir ?? tmpdir(), `demoman-attach-${randomUUID3()}`);
13518
+ const posted = join10(folder, plainName(file.path));
13401
13519
  try {
13402
13520
  try {
13403
13521
  await mkdir5(folder, { recursive: true });
@@ -13512,12 +13630,12 @@ async function labelOf(takeId, deps, path) {
13512
13630
 
13513
13631
  // ../runner/dist/executor/library.js
13514
13632
  import { createHash as createHash2, randomUUID as randomUUID4 } from "node:crypto";
13515
- import { mkdir as mkdir6, open as open2, readdir as readdir2, readFile as readFile7, rename as rename3, rm as rm5, stat as stat4, writeFile as writeFile4 } from "node:fs/promises";
13516
- import { join as join11, sep } from "node:path";
13633
+ import { mkdir as mkdir6, open as open2, readdir as readdir2, readFile as readFile8, rename as rename3, rm as rm5, stat as stat4, writeFile as writeFile4 } from "node:fs/promises";
13634
+ import { join as join12, sep } from "node:path";
13517
13635
 
13518
13636
  // ../runner/dist/frame-store.js
13519
13637
  import { promises as fs } from "node:fs";
13520
- import { dirname as dirname3, join as join10 } from "node:path";
13638
+ import { dirname as dirname3, join as join11 } from "node:path";
13521
13639
  var BUNDLES_DIR = "bundles";
13522
13640
  function fileNameOf(ref) {
13523
13641
  return encodeURIComponent(ref);
@@ -13554,9 +13672,9 @@ async function removeBlob(path) {
13554
13672
  }
13555
13673
  }
13556
13674
  function createFileFrameStore(root) {
13557
- const bundlesDir = join10(root, BUNDLES_DIR);
13558
- const blobPath = (ref) => join10(root, fileNameOf(ref));
13559
- const bundlePath = (sceneId) => join10(bundlesDir, `${fileNameOf(sceneId)}.json`);
13675
+ const bundlesDir = join11(root, BUNDLES_DIR);
13676
+ const blobPath = (ref) => join11(root, fileNameOf(ref));
13677
+ const bundlePath = (sceneId) => join11(bundlesDir, `${fileNameOf(sceneId)}.json`);
13560
13678
  async function writeBlob(ref, bytes) {
13561
13679
  const path = blobPath(ref);
13562
13680
  await ensureDir(dirname3(path));
@@ -13686,7 +13804,7 @@ var isMissing = (error) => error?.code === "ENOENT";
13686
13804
  async function readOutputRows(file) {
13687
13805
  let text;
13688
13806
  try {
13689
- text = await readFile7(file, "utf8");
13807
+ text = await readFile8(file, "utf8");
13690
13808
  } catch (error) {
13691
13809
  if (isMissing(error))
13692
13810
  return [];
@@ -13704,7 +13822,7 @@ async function readOutputRows(file) {
13704
13822
  return parsed2;
13705
13823
  }
13706
13824
  function createLibrary(home, options = {}) {
13707
- const root = join11(home, "takes");
13825
+ const root = join12(home, "takes");
13708
13826
  const isTakeId = (id) => !(id === "" || // `.`, `..`, and the library's own `.trash-*` folders.
13709
13827
  id.startsWith(".") || id.includes("/") || id.includes("\\") || id.includes(sep));
13710
13828
  const guard = (id, reason) => {
@@ -13714,13 +13832,13 @@ function createLibrary(home, options = {}) {
13714
13832
  };
13715
13833
  const takeDir = (id) => {
13716
13834
  guard(id, "libraryUnreadable");
13717
- return join11(root, id);
13835
+ return join12(root, id);
13718
13836
  };
13719
13837
  async function readTakeRaw(id) {
13720
- const path = join11(takeDir(id), "scene.json");
13838
+ const path = join12(takeDir(id), "scene.json");
13721
13839
  let text;
13722
13840
  try {
13723
- text = await readFile7(path, "utf8");
13841
+ text = await readFile8(path, "utf8");
13724
13842
  } catch (error) {
13725
13843
  if (isMissing(error))
13726
13844
  return null;
@@ -13743,7 +13861,7 @@ function createLibrary(home, options = {}) {
13743
13861
  const read = await readTakeRaw(id);
13744
13862
  return read === null ? null : untitleTimestampName(read.doc);
13745
13863
  }
13746
- const busyDir = (id) => join11(takeDir(id), ".busy");
13864
+ const busyDir = (id) => join12(takeDir(id), ".busy");
13747
13865
  async function holdersOf(id) {
13748
13866
  const dir = busyDir(id);
13749
13867
  let names;
@@ -13756,11 +13874,11 @@ function createLibrary(home, options = {}) {
13756
13874
  }
13757
13875
  const found = [];
13758
13876
  for (const name of names.filter((n) => n.endsWith(".json"))) {
13759
- const file = join11(dir, name);
13877
+ const file = join12(dir, name);
13760
13878
  try {
13761
13879
  found.push({
13762
13880
  file,
13763
- holder: JSON.parse(await readFile7(file, "utf8"))
13881
+ holder: JSON.parse(await readFile8(file, "utf8"))
13764
13882
  });
13765
13883
  } catch (error) {
13766
13884
  throw new LibraryError("libraryUnreadable", `could not read the lease ${file} (${messageOf4(error)})`);
@@ -13771,7 +13889,7 @@ function createLibrary(home, options = {}) {
13771
13889
  async function write(path, text) {
13772
13890
  const temp = `${path}.${process.pid}.${Date.now()}.${randomUUID4()}.tmp`;
13773
13891
  try {
13774
- await mkdir6(join11(path, ".."), { recursive: true });
13892
+ await mkdir6(join12(path, ".."), { recursive: true });
13775
13893
  await writeFile4(temp, text);
13776
13894
  await rename3(temp, path);
13777
13895
  } catch (error) {
@@ -13783,10 +13901,10 @@ function createLibrary(home, options = {}) {
13783
13901
  root,
13784
13902
  isTakeId,
13785
13903
  takeDir,
13786
- frameStore: (id) => createFileFrameStore(join11(takeDir(id), "frames")),
13904
+ frameStore: (id) => createFileFrameStore(join12(takeDir(id), "frames")),
13787
13905
  async putScene(doc) {
13788
13906
  guard(doc.meta.id, "libraryUnwritable");
13789
- await write(join11(takeDir(doc.meta.id), "scene.json"), JSON.stringify(doc));
13907
+ await write(join12(takeDir(doc.meta.id), "scene.json"), JSON.stringify(doc));
13790
13908
  },
13791
13909
  getScene: readTake,
13792
13910
  async getSceneRead(id) {
@@ -13799,10 +13917,10 @@ function createLibrary(home, options = {}) {
13799
13917
  },
13800
13918
  async putSceneIf(doc, ifMatch) {
13801
13919
  guard(doc.meta.id, "libraryUnwritable");
13802
- const path = join11(takeDir(doc.meta.id), "scene.json");
13920
+ const path = join12(takeDir(doc.meta.id), "scene.json");
13803
13921
  let current;
13804
13922
  try {
13805
- current = sha256(await readFile7(path, "utf8"));
13923
+ current = sha256(await readFile8(path, "utf8"));
13806
13924
  } catch (error) {
13807
13925
  if (!isMissing(error)) {
13808
13926
  throw new LibraryError("libraryUnreadable", `could not read ${path} (${messageOf4(error)})`);
@@ -13822,7 +13940,7 @@ function createLibrary(home, options = {}) {
13822
13940
  pid: process.pid,
13823
13941
  startedAt: (/* @__PURE__ */ new Date()).toISOString()
13824
13942
  };
13825
- const file = join11(busyDir(id), `${full.pid}-${full.jobId}.json`);
13943
+ const file = join12(busyDir(id), `${full.pid}-${full.jobId}.json`);
13826
13944
  await write(file, JSON.stringify(full));
13827
13945
  return {
13828
13946
  async release() {
@@ -13836,7 +13954,7 @@ function createLibrary(home, options = {}) {
13836
13954
  },
13837
13955
  async deleteTake(id) {
13838
13956
  guard(id, "libraryUnwritable");
13839
- const path = join11(root, id);
13957
+ const path = join12(root, id);
13840
13958
  try {
13841
13959
  await stat4(path);
13842
13960
  } catch (error) {
@@ -13860,7 +13978,7 @@ function createLibrary(home, options = {}) {
13860
13978
  }
13861
13979
  if (holders.length > 0)
13862
13980
  return { ok: false, holders };
13863
- const trash = join11(root, `.trash-${id}-${Date.now()}`);
13981
+ const trash = join12(root, `.trash-${id}-${Date.now()}`);
13864
13982
  try {
13865
13983
  await rename3(path, trash);
13866
13984
  } catch (error) {
@@ -13875,7 +13993,7 @@ function createLibrary(home, options = {}) {
13875
13993
  },
13876
13994
  async appendOutput(id, row) {
13877
13995
  guard(id, "libraryUnwritable");
13878
- const file = join11(takeDir(id), "outputs.json");
13996
+ const file = join12(takeDir(id), "outputs.json");
13879
13997
  const lock = `${file}.lock`;
13880
13998
  const deadline = Date.now() + LOCK_WAIT_MS;
13881
13999
  for (; ; ) {
@@ -13894,7 +14012,7 @@ function createLibrary(home, options = {}) {
13894
14012
  }
13895
14013
  let holderPid = null;
13896
14014
  try {
13897
- const parsed2 = JSON.parse(await readFile7(lock, "utf8"));
14015
+ const parsed2 = JSON.parse(await readFile8(lock, "utf8"));
13898
14016
  if (typeof parsed2.pid === "number")
13899
14017
  holderPid = parsed2.pid;
13900
14018
  } catch {
@@ -13925,7 +14043,7 @@ function createLibrary(home, options = {}) {
13925
14043
  throw failure3;
13926
14044
  },
13927
14045
  async outputs(id) {
13928
- const rows = await readOutputRows(join11(takeDir(id), "outputs.json"));
14046
+ const rows = await readOutputRows(join12(takeDir(id), "outputs.json"));
13929
14047
  const listed3 = [];
13930
14048
  for (const row of rows) {
13931
14049
  let exists2 = true;
@@ -13943,15 +14061,15 @@ function createLibrary(home, options = {}) {
13943
14061
  },
13944
14062
  async putJson(id, name, value) {
13945
14063
  guard(id, "libraryUnwritable");
13946
- await write(join11(takeDir(id), name), JSON.stringify(value, null, 2));
14064
+ await write(join12(takeDir(id), name), JSON.stringify(value, null, 2));
13947
14065
  },
13948
14066
  /** `script.json`: none (an old or extension take), one, or one that
13949
14067
  * will not read — never the same answer for the last two. */
13950
14068
  async getSkeleton(id) {
13951
- const path = join11(takeDir(id), "script.json");
14069
+ const path = join12(takeDir(id), "script.json");
13952
14070
  let text;
13953
14071
  try {
13954
- text = await readFile7(path, "utf8");
14072
+ text = await readFile8(path, "utf8");
13955
14073
  } catch (error) {
13956
14074
  if (isMissing(error))
13957
14075
  return { kind: "none" };
@@ -13974,7 +14092,7 @@ function createLibrary(home, options = {}) {
13974
14092
  },
13975
14093
  async removeTake(id) {
13976
14094
  guard(id, "libraryUnwritable");
13977
- const path = join11(root, id);
14095
+ const path = join12(root, id);
13978
14096
  try {
13979
14097
  await rm5(path, { recursive: true, force: true });
13980
14098
  } catch (error) {
@@ -14000,7 +14118,7 @@ function createLibrary(home, options = {}) {
14000
14118
  } catch (error) {
14001
14119
  unreadable.push({
14002
14120
  id,
14003
- unreadable: `${error instanceof LibraryError ? error.message : messageOf4(error)} \u2014 remove ${join11(root, id)} if the take is not wanted`
14121
+ unreadable: `${error instanceof LibraryError ? error.message : messageOf4(error)} \u2014 remove ${join12(root, id)} if the take is not wanted`
14004
14122
  });
14005
14123
  continue;
14006
14124
  }
@@ -14357,13 +14475,13 @@ function createGh(run2, cwd, env, checkTimeoutMs = GH_CHECK_TIMEOUT_MS, uploadTi
14357
14475
  }
14358
14476
 
14359
14477
  // ../runner/dist/executor/kits.js
14360
- import { readFile as readFile8 } from "node:fs/promises";
14361
- import { join as join12 } from "node:path";
14478
+ import { readFile as readFile9 } from "node:fs/promises";
14479
+ import { join as join13 } from "node:path";
14362
14480
  async function readKits(home) {
14363
- const path = join12(home, "kits.json");
14481
+ const path = join13(home, "kits.json");
14364
14482
  let text;
14365
14483
  try {
14366
- text = await readFile8(path, "utf8");
14484
+ text = await readFile9(path, "utf8");
14367
14485
  } catch (error) {
14368
14486
  if (error?.code === "ENOENT") {
14369
14487
  return coerceBrandKits(void 0, void 0);
@@ -14398,77 +14516,6 @@ function judgeKitsText(path, text) {
14398
14516
 
14399
14517
  // ../runner/dist/executor/pull-requests.js
14400
14518
  import { join as join14 } from "node:path";
14401
-
14402
- // ../runner/dist/executor/user-settings.js
14403
- import { readFile as readFile9 } from "node:fs/promises";
14404
- import { join as join13 } from "node:path";
14405
- var settingsWith = (settings, problems) => {
14406
- const said = [problems.exportQuality, problems.pullRequests].filter((p) => p !== void 0);
14407
- if (said.length === 0)
14408
- return settings;
14409
- return { ...settings, problems, unreadable: [...new Set(said)].join("; ") };
14410
- };
14411
- async function readUserSettings(home) {
14412
- const path = join13(home, "settings.json");
14413
- const defaults = { exportQuality: "share", pullRequests: null };
14414
- let text;
14415
- try {
14416
- text = await readFile9(path, "utf8");
14417
- } catch (error) {
14418
- if (error.code === "ENOENT")
14419
- return defaults;
14420
- const said = `${path} could not be read (${messageOf4(error)})`;
14421
- return settingsWith(defaults, { exportQuality: said, pullRequests: said });
14422
- }
14423
- const raw = parsed(path, text);
14424
- if ("unreadable" in raw) {
14425
- return settingsWith(defaults, {
14426
- exportQuality: raw.unreadable,
14427
- pullRequests: raw.unreadable
14428
- });
14429
- }
14430
- const pr = pullRequestsIn(path, raw.object);
14431
- const quality = raw.object.exportQuality;
14432
- const qualityBad = quality !== void 0 && !isExportQuality(quality);
14433
- return settingsWith({
14434
- exportQuality: isExportQuality(quality) ? quality : "share",
14435
- pullRequests: "unreadable" in pr ? null : pr.value
14436
- }, {
14437
- ...qualityBad ? {
14438
- exportQuality: `${path}: exportQuality must be share or full; got ${JSON.stringify(quality)}`
14439
- } : {},
14440
- ..."unreadable" in pr ? { pullRequests: pr.unreadable } : {}
14441
- });
14442
- }
14443
- function parsed(path, text) {
14444
- let raw;
14445
- try {
14446
- raw = JSON.parse(text);
14447
- } catch (error) {
14448
- return { unreadable: `${path} is not valid JSON (${messageOf4(error)})` };
14449
- }
14450
- if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
14451
- return { unreadable: `${path} must hold a JSON object` };
14452
- }
14453
- return { object: raw };
14454
- }
14455
- function pullRequestsIn(path, object) {
14456
- const value = object.pullRequests;
14457
- if (value === void 0)
14458
- return { value: null };
14459
- if (!isPullRequestsValue(value)) {
14460
- return {
14461
- unreadable: `${path}: pullRequests must be off, ask or attach; got ${JSON.stringify(value)}`
14462
- };
14463
- }
14464
- return { value };
14465
- }
14466
- function parsePullRequests(path, text) {
14467
- const raw = parsed(path, text);
14468
- return "unreadable" in raw ? raw : pullRequestsIn(path, raw.object);
14469
- }
14470
-
14471
- // ../runner/dist/executor/pull-requests.js
14472
14519
  var REPO_CONFIG = "config.json";
14473
14520
  async function resolvePullRequests(from, home) {
14474
14521
  const repo = await findDemomanFile(from, REPO_CONFIG);
@@ -16440,13 +16487,13 @@ function matchRoute(method, pathname) {
16440
16487
  var FILE_NAME_HEADER = "X-File-Name";
16441
16488
 
16442
16489
  // ../studio/dist/guard.js
16443
- var EXPIRED_LINE = "This studio link has expired; run `npx demoman studio`.";
16490
+ var EXPIRED_LINE = "This Studio link has expired; run `npx demoman studio`.";
16444
16491
  var SECURITY_HEADERS = {
16445
16492
  "Content-Security-Policy": "default-src 'self'; img-src 'self' blob: data:; media-src 'self' blob:; connect-src 'self'; frame-ancestors 'none'",
16446
16493
  "X-Content-Type-Options": "nosniff"
16447
16494
  };
16448
16495
  var REASON_DETAIL = {
16449
- hostRefused: "The request was not addressed to the studio's own address.",
16496
+ hostRefused: "The request was not addressed to the Studio's own address.",
16450
16497
  tokenMissing: EXPIRED_LINE,
16451
16498
  tokenWrong: EXPIRED_LINE,
16452
16499
  headerMissing: `The request lacked the ${STUDIO_HEADER} header.`,
@@ -16705,7 +16752,7 @@ async function readStudioState(home) {
16705
16752
  const v = JSON.parse(text);
16706
16753
  if (isState(v))
16707
16754
  return v;
16708
- return { unreadable: "studio.json is missing fields the studio writes" };
16755
+ return { unreadable: "studio.json is missing fields the Studio writes" };
16709
16756
  } catch {
16710
16757
  return { unreadable: "studio.json is not valid JSON" };
16711
16758
  }
@@ -16722,8 +16769,8 @@ async function removeStudioState(home, pid) {
16722
16769
  }
16723
16770
 
16724
16771
  // ../studio/dist/open.js
16725
- var STALE_NOTE = "A stale studio record was replaced.";
16726
- var REPLACED_LATER_NOTE = "An older studio is running an export; it stays open until that export ends and its window closes, and the next studio call starts the new version.";
16772
+ var STALE_NOTE = "A stale Studio record was replaced.";
16773
+ var REPLACED_LATER_NOTE = "An older Studio is running an export; it stays open until that export ends and its window closes, and the next Studio call starts the new version.";
16727
16774
  var PING_TIMEOUT_MS = 2e3;
16728
16775
  var WINDOW_TIMEOUT_MS = 3e4;
16729
16776
  var LOG_TAIL_LINES = 10;
@@ -16821,7 +16868,7 @@ async function startStudio(o) {
16821
16868
  if (error.code !== "ENOENT") {
16822
16869
  return {
16823
16870
  reason: "studioDidNotStart",
16824
- detail: `The studio's log ${logPath} could not be moved aside: ${messageOf7(error)}.`
16871
+ detail: `The Studio's log ${logPath} could not be moved aside: ${messageOf7(error)}.`
16825
16872
  };
16826
16873
  }
16827
16874
  }
@@ -16831,7 +16878,7 @@ async function startStudio(o) {
16831
16878
  } catch (error) {
16832
16879
  return {
16833
16880
  reason: "studioDidNotStart",
16834
- detail: `The studio's log ${logPath} could not be opened: ${messageOf7(error)}.`
16881
+ detail: `The Studio's log ${logPath} could not be opened: ${messageOf7(error)}.`
16835
16882
  };
16836
16883
  }
16837
16884
  const ended = {
@@ -16874,7 +16921,7 @@ async function startStudio(o) {
16874
16921
  }
16875
16922
  return {
16876
16923
  reason: "studioDidNotStart",
16877
- detail: `The studio ${why2}. The end of ${logPath}:
16924
+ detail: `The Studio ${why2}. The end of ${logPath}:
16878
16925
  ${await lastLines(logPath)}`
16879
16926
  };
16880
16927
  }
@@ -16891,7 +16938,7 @@ async function acquireStartLock(home, waitMs) {
16891
16938
  if (error.code !== "EEXIST") {
16892
16939
  return {
16893
16940
  reason: "studioDidNotStart",
16894
- detail: `The studio's start lock ${path} could not be taken: ${messageOf7(error)}.`
16941
+ detail: `The Studio's start lock ${path} could not be taken: ${messageOf7(error)}.`
16895
16942
  };
16896
16943
  }
16897
16944
  }
@@ -16908,7 +16955,7 @@ async function acquireStartLock(home, waitMs) {
16908
16955
  if (Date.now() > deadline) {
16909
16956
  return {
16910
16957
  reason: "studioDidNotStart",
16911
- detail: `Another demoman (pid ${holder}) has been starting the studio for over ${Math.round(waitMs / 1e3)} s; see ${join19(home, "studio.log")}.`
16958
+ detail: `Another demoman (pid ${holder}) has been starting the Studio for over ${Math.round(waitMs / 1e3)} s; see ${join19(home, "studio.log")}.`
16912
16959
  };
16913
16960
  }
16914
16961
  await sleep2(40);
@@ -16994,7 +17041,7 @@ async function openStudio(o) {
16994
17041
  if (!win.ok) {
16995
17042
  return {
16996
17043
  reason: "windowDidNotOpen",
16997
- detail: `The studio did not answer the request for a window: ${win.error}.`
17044
+ detail: `The Studio did not answer the request for a window: ${win.error}.`
16998
17045
  };
16999
17046
  }
17000
17047
  if (win.status !== 200) {
@@ -17002,14 +17049,14 @@ async function openStudio(o) {
17002
17049
  return win.json;
17003
17050
  return {
17004
17051
  reason: "windowDidNotOpen",
17005
- detail: `The studio answered ${win.status} to the request for a window.`
17052
+ detail: `The Studio answered ${win.status} to the request for a window.`
17006
17053
  };
17007
17054
  }
17008
17055
  const answer = win.json;
17009
17056
  if (typeof answer.url !== "string") {
17010
17057
  return {
17011
17058
  reason: "windowDidNotOpen",
17012
- detail: "The studio opened a window but did not say its address."
17059
+ detail: "The Studio opened a window but did not say its address."
17013
17060
  };
17014
17061
  }
17015
17062
  return {
@@ -17033,7 +17080,7 @@ async function stopStudio(o) {
17033
17080
  return {
17034
17081
  stopped: false,
17035
17082
  cutShort: 0,
17036
- why: `pid ${found.pid} is alive but did not answer as the studio, so it was left alone`
17083
+ why: `pid ${found.pid} is alive but did not answer as the Studio, so it was left alone`
17037
17084
  };
17038
17085
  }
17039
17086
  const signal = (sig) => {
@@ -17198,7 +17245,7 @@ function createExportQueue(o) {
17198
17245
  try {
17199
17246
  answer = await o.run(job.takeId, job.fileType, job.jobId, (p) => {
17200
17247
  send2(job, p.phase === "saving" ? { phase: "saving" } : { phase: "rendering", done: p.done, total: p.total });
17201
- });
17248
+ }, job.quality);
17202
17249
  } catch (error) {
17203
17250
  log2(`studio: export ${job.jobId} of ${job.takeId} threw: ${messageOf6(error)}`);
17204
17251
  send2(job, {
@@ -17257,7 +17304,12 @@ function createExportQueue(o) {
17257
17304
  if (read.revision !== body.revision) {
17258
17305
  return { reason: "sceneNotSaved", detail: SCENE_NOT_SAVED };
17259
17306
  }
17260
- const job = { takeId, fileType: body.fileType, jobId: randomUUID7() };
17307
+ const job = {
17308
+ takeId,
17309
+ fileType: body.fileType,
17310
+ ...body.quality === void 0 ? {} : { quality: body.quality },
17311
+ jobId: randomUUID7()
17312
+ };
17261
17313
  const position = waiting.length + (running === null ? 0 : 1);
17262
17314
  waiting.push(job);
17263
17315
  send2(job, { phase: "queued", position });
@@ -17305,7 +17357,7 @@ async function writeSettingNow(home, key, value) {
17305
17357
  if (key === "exportQuality" && !isExportQuality(value)) {
17306
17358
  return {
17307
17359
  reason: "exportQualityInvalid",
17308
- detail: `"${String(value)}" is not a choice \u2014 choose share or full.`
17360
+ detail: `"${String(value)}" is not a choice \u2014 choose ${EXPORT_QUALITY_VALUES.join(", ")}.`
17309
17361
  };
17310
17362
  }
17311
17363
  const path = settingsPath(home);
@@ -17386,7 +17438,7 @@ var unmeasured = (path, error) => new LibraryError("libraryUnreadable", `could n
17386
17438
  var CHANGED_ELSEWHERE = "This take changed in another window. Reopen it to keep editing.";
17387
17439
  var TAKE_BUSY = {
17388
17440
  agent: "This take is being exported by an agent.",
17389
- studio: "This take is being exported by the studio."
17441
+ studio: "This take is being exported by the Studio."
17390
17442
  };
17391
17443
  var FRAME_CACHE = "private, max-age=31536000, immutable";
17392
17444
  var json = (status, body) => ({
@@ -17397,7 +17449,7 @@ var refuse2 = (status, reason, detail) => {
17397
17449
  const body = { reason, detail };
17398
17450
  return { status, json: body };
17399
17451
  };
17400
- function revealInFinder2(path) {
17452
+ function revealInFinder(path) {
17401
17453
  return new Promise((resolve4, reject) => {
17402
17454
  execFile5("open", ["-R", path], (error, _stdout, stderr) => {
17403
17455
  if (error) {
@@ -17410,7 +17462,7 @@ function revealInFinder2(path) {
17410
17462
  }
17411
17463
  function createRoutes(o) {
17412
17464
  const { library, home, log: log2 } = o;
17413
- const reveal = o.reveal ?? revealInFinder2;
17465
+ const reveal = o.reveal ?? revealInFinder;
17414
17466
  const sceneWrites = createChains();
17415
17467
  const kits = createKitsFile(home);
17416
17468
  const noTake = (id) => refuse2(404, "takeNotFound", `There is no take "${id}" in ${library.root}.`);
@@ -17694,9 +17746,9 @@ function createRoutes(o) {
17694
17746
  async exportQualityGet() {
17695
17747
  const got = await readUserSettings(home);
17696
17748
  const unreadable = got.problems?.exportQuality;
17697
- const answer = unreadable === void 0 ? { exportQuality: got.exportQuality } : { exportQuality: "share", unreadable };
17749
+ const answer = unreadable === void 0 ? { exportQuality: got.exportQuality } : { exportQuality: DEFAULT_EXPORT_QUALITY, unreadable };
17698
17750
  if (unreadable !== void 0) {
17699
- log2(`studio: Export quality is Sharing: ${unreadable}`);
17751
+ log2(`studio: Export quality is ${DEFAULT_EXPORT_QUALITY}: ${unreadable}`);
17700
17752
  }
17701
17753
  return json(200, answer);
17702
17754
  },
@@ -17792,17 +17844,7 @@ import { join as join27 } from "node:path";
17792
17844
  // ../studio/dist/run-export.js
17793
17845
  function createRunExport(a) {
17794
17846
  const { exportTake: exportTake2, deps } = a;
17795
- return async (takeId, fileType, jobId, onProgress) => {
17796
- const settings = await readUserSettings(deps.home);
17797
- if (settings.problems?.exportQuality !== void 0) {
17798
- deps.log(`studio: exporting at Sharing quality: ${settings.problems.exportQuality}`);
17799
- }
17800
- return exportTake2({
17801
- takeId,
17802
- fileType,
17803
- ...fileType === "mp4" ? { quality: settings.exportQuality } : {}
17804
- }, { ...deps, jobId }, onProgress);
17805
- };
17847
+ return (takeId, fileType, jobId, onProgress, quality) => exportTake2({ takeId, fileType, ...quality === void 0 ? {} : { quality } }, { ...deps, jobId }, onProgress);
17806
17848
  }
17807
17849
 
17808
17850
  // ../studio/dist/server.js
@@ -17820,7 +17862,7 @@ code{font-family:"Geist Mono",ui-monospace,SFMono-Regular,Menlo,monospace;font-s
17820
17862
  `;
17821
17863
  var styleHash = `'sha256-${createHash4("sha256").update(STYLE).digest("base64")}'`;
17822
17864
  var escapeHtml2 = (s) => s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
17823
- var EXPIRED_HTML = `<!doctype html><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Demoman studio</title><style>${STYLE}</style><p>${escapeHtml2(EXPIRED_LINE).replace(/`([^`]*)`/g, "<code>$1</code>")}</p>`;
17865
+ var EXPIRED_HTML = `<!doctype html><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Demoman Studio</title><style>${STYLE}</style><p>${escapeHtml2(EXPIRED_LINE).replace(/`([^`]*)`/g, "<code>$1</code>")}</p>`;
17824
17866
  var EXPIRED_CSP = `${SECURITY_HEADERS["Content-Security-Policy"]}; style-src ${styleHash}`;
17825
17867
 
17826
17868
  // ../studio/dist/server.js
@@ -18268,7 +18310,7 @@ var PAGE_WAIT_MS = 1e4;
18268
18310
  var STOPPING = {
18269
18311
  ok: false,
18270
18312
  reason: "windowDidNotOpen",
18271
- detail: "the studio is stopping, so no window opens"
18313
+ detail: "the Studio is stopping, so no window opens"
18272
18314
  };
18273
18315
  function createStudioWindow(o) {
18274
18316
  const { log: log2 } = o;
@@ -18277,14 +18319,11 @@ function createStudioWindow(o) {
18277
18319
  let context = null;
18278
18320
  let starting = null;
18279
18321
  let closed = false;
18280
- const work = /* @__PURE__ */ new WeakSet();
18281
18322
  let hadViewer = false;
18282
- let openingWork = 0;
18283
18323
  const listeners = [];
18284
18324
  const livePages = () => context === null ? [] : context.pages().filter((p) => !p.isClosed());
18285
- const viewers = () => livePages().filter((p) => !work.has(p));
18286
18325
  const count = () => {
18287
- if (viewers().length > 0) {
18326
+ if (livePages().length > 0) {
18288
18327
  hadViewer = true;
18289
18328
  return;
18290
18329
  }
@@ -18295,13 +18334,19 @@ function createStudioWindow(o) {
18295
18334
  fn();
18296
18335
  };
18297
18336
  const watch = (ctx) => {
18298
- const onPage = (page2) => page2.on("close", () => count());
18337
+ const onPage = (page2) => {
18338
+ page2.on("close", () => count());
18339
+ page2.on("console", (message2) => {
18340
+ const text = message2.text();
18341
+ if (text.startsWith("[demoman] preview:"))
18342
+ log2(`studio: ${text}`);
18343
+ });
18344
+ };
18299
18345
  for (const page2 of ctx.pages())
18300
18346
  onPage(page2);
18301
18347
  ctx.on("page", (page2) => {
18302
18348
  onPage(page2);
18303
- if (openingWork === 0)
18304
- count();
18349
+ count();
18305
18350
  });
18306
18351
  ctx.on("close", () => {
18307
18352
  if (context === ctx)
@@ -18313,9 +18358,9 @@ function createStudioWindow(o) {
18313
18358
  if (closed)
18314
18359
  return Promise.resolve(STOPPING);
18315
18360
  if (context !== null) {
18316
- return Promise.resolve({ ok: true, context, launched: null });
18361
+ return Promise.resolve({ ok: true, context, launched: false });
18317
18362
  }
18318
- starting ??= launch2(appUrl?.()).finally(() => {
18363
+ starting ??= launch2(appUrl()).finally(() => {
18319
18364
  starting = null;
18320
18365
  });
18321
18366
  return starting;
@@ -18329,7 +18374,7 @@ function createStudioWindow(o) {
18329
18374
  viewport: null,
18330
18375
  args: [
18331
18376
  // A ticket, not the token: argv is readable by any local user.
18332
- ...appUrl === void 0 ? [] : [`--app=${appUrl}`],
18377
+ `--app=${appUrl}`,
18333
18378
  // A fresh macOS profile otherwise asks the login keychain for
18334
18379
  // "Chrome Safe Storage" in a modal prompt (CLAUDE.md).
18335
18380
  "--use-mock-keychain",
@@ -18338,7 +18383,7 @@ function createStudioWindow(o) {
18338
18383
  // Playwright opens a persistent context on about:blank; with an app
18339
18384
  // window that would be a second, blank window the person did not
18340
18385
  // ask for, and one that kept the studio alive after they closed it.
18341
- ...appUrl === void 0 ? {} : { ignoreDefaultArgs: ["about:blank"] },
18386
+ ignoreDefaultArgs: ["about:blank"],
18342
18387
  // runServe's own SIGTERM/SIGINT handlers close the browser, after
18343
18388
  // telling the pages the studio is stopping.
18344
18389
  handleSIGTERM: false,
@@ -18353,22 +18398,14 @@ function createStudioWindow(o) {
18353
18398
  });
18354
18399
  return STOPPING;
18355
18400
  }
18356
- if (appUrl === void 0) {
18357
- for (const page2 of ctx.pages())
18358
- work.add(page2);
18359
- }
18360
18401
  context = ctx;
18361
18402
  watch(ctx);
18362
- return {
18363
- ok: true,
18364
- context: ctx,
18365
- launched: appUrl === void 0 ? "work" : "app"
18366
- };
18403
+ return { ok: true, context: ctx, launched: true };
18367
18404
  }
18368
18405
  async function appWindow() {
18369
18406
  const deadline = Date.now() + pageWaitMs;
18370
18407
  for (; ; ) {
18371
- const page2 = viewers().find((p) => p.url().startsWith(o.origin));
18408
+ const page2 = livePages().find((p) => p.url().startsWith(o.origin));
18372
18409
  if (page2 !== void 0)
18373
18410
  return page2;
18374
18411
  if (Date.now() >= deadline)
@@ -18376,81 +18413,6 @@ function createStudioWindow(o) {
18376
18413
  await new Promise((r) => setTimeout(r, 100));
18377
18414
  }
18378
18415
  }
18379
- async function targetIdOf(ctx, page2) {
18380
- const cdp = await ctx.newCDPSession(page2);
18381
- try {
18382
- const { targetInfo } = await cdp.send("Target.getTargetInfo");
18383
- return targetInfo.targetId;
18384
- } finally {
18385
- await cdp.detach().catch((error) => {
18386
- log2(`studio: a page's session would not detach (${messageOf6(error)})`);
18387
- });
18388
- }
18389
- }
18390
- async function newWindow(ctx, url, background) {
18391
- const anchor2 = livePages()[0];
18392
- if (anchor2 === void 0) {
18393
- const page2 = await ctx.newPage();
18394
- if (url !== "about:blank")
18395
- await page2.goto(url);
18396
- return page2;
18397
- }
18398
- const arrived = [];
18399
- let wake = null;
18400
- const onPage = (page2) => {
18401
- arrived.push(page2);
18402
- wake?.();
18403
- };
18404
- ctx.on("page", onPage);
18405
- try {
18406
- const cdp = await ctx.newCDPSession(anchor2);
18407
- let targetId;
18408
- try {
18409
- ({ targetId } = await cdp.send("Target.createTarget", {
18410
- url,
18411
- newWindow: true,
18412
- ...background ? { background: true } : {}
18413
- }));
18414
- } finally {
18415
- await cdp.detach().catch((error) => {
18416
- log2(`studio: the session that opened a window would not detach (${messageOf6(error)})`);
18417
- });
18418
- }
18419
- const deadline = Date.now() + pageWaitMs;
18420
- let checked = 0;
18421
- for (; ; ) {
18422
- while (checked < arrived.length) {
18423
- const page2 = arrived[checked];
18424
- checked += 1;
18425
- if (page2.isClosed())
18426
- continue;
18427
- let id;
18428
- try {
18429
- id = await targetIdOf(ctx, page2);
18430
- } catch (error) {
18431
- log2(`studio: a page's target could not be read (${messageOf6(error)})`);
18432
- continue;
18433
- }
18434
- if (id === targetId)
18435
- return page2;
18436
- }
18437
- const left = deadline - Date.now();
18438
- if (left <= 0) {
18439
- throw new Error(`the browser opened window ${targetId}, but it did not reach Demoman within ${pageWaitMs / 1e3} s`);
18440
- }
18441
- await new Promise((resolve4) => {
18442
- const timer = setTimeout(resolve4, left);
18443
- wake = () => {
18444
- clearTimeout(timer);
18445
- resolve4();
18446
- };
18447
- });
18448
- wake = null;
18449
- }
18450
- } finally {
18451
- ctx.off("page", onPage);
18452
- }
18453
- }
18454
18416
  const didNotOpen = (detail) => ({
18455
18417
  reason: "windowDidNotOpen",
18456
18418
  detail
@@ -18461,15 +18423,15 @@ function createStudioWindow(o) {
18461
18423
  const got = await ensure(() => o.entryUrl(target.takeId));
18462
18424
  if (!got.ok)
18463
18425
  return { reason: got.reason, detail: got.detail };
18464
- if (got.launched === "app") {
18426
+ if (got.launched) {
18465
18427
  const page2 = await appWindow();
18466
18428
  if (page2 === null) {
18467
- return didNotOpen(`the studio's browser started, but its window did not appear within ${pageWaitMs / 1e3} s`);
18429
+ return didNotOpen(`the Studio's browser started, but its window did not appear within ${pageWaitMs / 1e3} s`);
18468
18430
  }
18469
18431
  count();
18470
18432
  return { ok: true, path };
18471
18433
  }
18472
- const live = viewers()[0];
18434
+ const live = livePages()[0];
18473
18435
  if (live !== void 0) {
18474
18436
  if (o.events.size() > 0) {
18475
18437
  o.events.send({ type: "open", path });
@@ -18477,49 +18439,25 @@ function createStudioWindow(o) {
18477
18439
  try {
18478
18440
  await live.goto(o.entryUrl(target.takeId));
18479
18441
  } catch (error) {
18480
- return didNotOpen(`the studio's window could not be sent to ${path} (${messageOf6(error)})`);
18442
+ return didNotOpen(`the Studio's window could not be sent to ${path} (${messageOf6(error)})`);
18481
18443
  }
18482
18444
  }
18483
18445
  try {
18484
18446
  await live.bringToFront();
18485
18447
  } catch (error) {
18486
- return didNotOpen(`the studio's window was sent to ${path} but could not be brought forward (${messageOf6(error)})`);
18448
+ return didNotOpen(`the Studio's window was sent to ${path} but could not be brought forward (${messageOf6(error)})`);
18487
18449
  }
18488
18450
  return { ok: true, path };
18489
18451
  }
18490
18452
  try {
18491
- await newWindow(got.context, o.entryUrl(target.takeId), false);
18453
+ const page2 = await got.context.newPage();
18454
+ await page2.goto(o.entryUrl(target.takeId));
18492
18455
  } catch (error) {
18493
- return didNotOpen(`the studio's window would not open: ${messageOf6(error)}`);
18456
+ return didNotOpen(`the Studio's window would not open: ${messageOf6(error)}`);
18494
18457
  }
18495
18458
  count();
18496
18459
  return { ok: true, path };
18497
18460
  },
18498
- async workPage() {
18499
- const got = await ensure();
18500
- if (!got.ok)
18501
- return got;
18502
- if (got.launched === "work") {
18503
- const first = livePages().find((p) => work.has(p));
18504
- if (first !== void 0)
18505
- return { ok: true, page: first };
18506
- }
18507
- openingWork += 1;
18508
- try {
18509
- const page2 = await newWindow(got.context, "about:blank", true);
18510
- work.add(page2);
18511
- return { ok: true, page: page2 };
18512
- } catch (error) {
18513
- return {
18514
- ok: false,
18515
- reason: "windowDidNotOpen",
18516
- detail: `the browser would not open a page to render in: ${messageOf6(error)}`
18517
- };
18518
- } finally {
18519
- openingWork -= 1;
18520
- count();
18521
- }
18522
- },
18523
18461
  onAllClosed(fn) {
18524
18462
  listeners.push(fn);
18525
18463
  },
@@ -18619,16 +18557,23 @@ function buildHandlers(o) {
18619
18557
  if (!body.ok) {
18620
18558
  return refuse4(400, "invalidFileType", `Nothing was exported: ${body.error}.`);
18621
18559
  }
18622
- const { fileType, revision } = body.value ?? {};
18560
+ const { fileType, revision, quality } = body.value ?? {};
18623
18561
  if (!FILE_TYPES2.includes(fileType)) {
18624
18562
  return refuse4(400, "invalidFileType", `Nothing was exported: ${JSON.stringify(fileType) ?? "no file type"} is not mp4, gif or stills.`);
18625
18563
  }
18564
+ if (quality !== void 0 && !isExportQuality(quality)) {
18565
+ return refuse4(400, "exportQualityInvalid", `Nothing was exported: ${JSON.stringify(quality)} is not ${EXPORT_QUALITY_VALUES.join(", ")}.`);
18566
+ }
18567
+ if (quality !== void 0 && fileType !== "mp4") {
18568
+ return refuse4(400, "exportQualityInvalid", `Nothing was exported: only an MP4 has a quality, not ${fileType === "gif" ? "a GIF" : "stills"}.`);
18569
+ }
18626
18570
  if (typeof revision !== "string" || revision === "") {
18627
18571
  return refuse4(428, "sceneNotSaved", "The export carried no revision, so it could not be checked against the take on disk.");
18628
18572
  }
18629
18573
  const started = await o.queue.start(id, {
18630
18574
  fileType,
18631
- revision
18575
+ revision,
18576
+ ...quality === void 0 ? {} : { quality }
18632
18577
  });
18633
18578
  if ("reason" in started) {
18634
18579
  return json2(QUEUE_STATUS[started.reason], started);
@@ -18677,19 +18622,21 @@ async function runServe(o) {
18677
18622
  let entry = null;
18678
18623
  const theWindow = () => {
18679
18624
  if (window === null)
18680
- throw new Error("the studio window is not made yet");
18625
+ throw new Error("the Studio window is not made yet");
18681
18626
  return window;
18682
18627
  };
18628
+ const renderer = createBrowserSession({
18629
+ headless: true,
18630
+ // Left to itself, headless launches the headless shell, which draws in
18631
+ // software (`fullChromiumPath`).
18632
+ executablePath: o.executablePath ?? fullChromiumPath(),
18633
+ log: log2
18634
+ });
18683
18635
  const run2 = o.run ?? createRunExport({
18684
18636
  exportTake,
18685
18637
  deps: {
18686
18638
  library,
18687
- session: {
18688
- openWorkPage: () => theWindow().workPage(),
18689
- // As the window opens (window.ts): visible unless asked headless,
18690
- // so a closed render page is worded as a window someone closed.
18691
- headless: o.headless ?? false
18692
- },
18639
+ session: renderer,
18693
18640
  home,
18694
18641
  outDir: o.outDir,
18695
18642
  log: log2,
@@ -18733,7 +18680,7 @@ async function runServe(o) {
18733
18680
  },
18734
18681
  entryUrl: (takeId) => {
18735
18682
  if (entry === null)
18736
- throw new Error("the studio server is not up yet");
18683
+ throw new Error("the Studio server is not up yet");
18737
18684
  return entry(takeId);
18738
18685
  },
18739
18686
  onWindowOpened: () => {
@@ -18809,6 +18756,11 @@ async function runServe(o) {
18809
18756
  } catch (error) {
18810
18757
  log2(`studio: the browser would not close cleanly (${messageOf6(error)})`);
18811
18758
  }
18759
+ try {
18760
+ await renderer.close();
18761
+ } catch (error) {
18762
+ log2(`studio: the render browser would not close cleanly (${messageOf6(error)})`);
18763
+ }
18812
18764
  try {
18813
18765
  await removeStudioState(home, process.pid);
18814
18766
  } catch (error) {
@@ -19005,27 +18957,34 @@ function marketplaceAutoUpdate(text, listed3) {
19005
18957
  obj.extraKnownMarketplaces = markets;
19006
18958
  return { text: serialise(obj), changed: true };
19007
18959
  }
18960
+ var entryPath = (nodeBin) => `${nodeBin}:/usr/bin:/bin:/usr/sbin:/sbin`;
19008
18961
  function cursorEntry(nodeBin) {
19009
18962
  return {
19010
18963
  type: "stdio",
19011
18964
  command: `${nodeBin}/npx`,
19012
18965
  args: ["-y", `${PACKAGE_NAME}@latest`, "mcp"],
19013
18966
  // DEMOMAN_CLIENT tells the server it is Cursor's, so it keeps
19014
- // ~/.cursor/skills/record-demo current (cursor-skill.ts).
19015
- env: {
19016
- PATH: `${nodeBin}:/usr/bin:/bin:/usr/sbin:/sbin`,
19017
- DEMOMAN_CLIENT: "cursor"
19018
- }
18967
+ // ~/.cursor/skills/record-demo current (agent-skill.ts).
18968
+ env: { PATH: entryPath(nodeBin), DEMOMAN_CLIENT: "cursor" }
19019
18969
  };
19020
18970
  }
19021
- function isOurCursorEntry(e) {
19022
- if (!isObject2(e) || typeof e.command !== "string") return false;
19023
- const args2 = e.args;
19024
- return basename4(e.command) === "npx" && Array.isArray(args2) && args2.filter((a) => typeof a === "string" && /^demoman@\S+$/.test(a)).length === 1 && args2.at(-1) === "mcp";
18971
+ var opencodeDir = (home, env) => `${env.XDG_CONFIG_HOME || `${home}/.config`}/opencode`;
18972
+ function opencodeEntry(nodeBin) {
18973
+ return {
18974
+ type: "local",
18975
+ command: [`${nodeBin}/npx`, "-y", `${PACKAGE_NAME}@latest`, "mcp"],
18976
+ environment: { PATH: entryPath(nodeBin), DEMOMAN_CLIENT: "opencode" }
18977
+ };
18978
+ }
18979
+ function isOurCommand(command2, args2) {
18980
+ return typeof command2 === "string" && basename4(command2) === "npx" && Array.isArray(args2) && args2.filter((a) => typeof a === "string" && /^demoman@\S+$/.test(a)).length === 1 && args2.at(-1) === "mcp";
19025
18981
  }
18982
+ var isOurCursorEntry = (e) => isObject2(e) && isOurCommand(e.command, e.args);
18983
+ var isOurOpencodeEntry = (e) => isObject2(e) && Array.isArray(e.command) && isOurCommand(e.command[0], e.command.slice(1));
19026
18984
  var describeEntry = (e) => {
19027
18985
  if (!isObject2(e)) return JSON.stringify(e);
19028
18986
  if (typeof e.url === "string") return e.url;
18987
+ if (Array.isArray(e.command)) return e.command.join(" ");
19029
18988
  return [e.command, ...Array.isArray(e.args) ? e.args : []].filter((p) => p !== void 0).join(" ");
19030
18989
  };
19031
18990
  function cursorServer(text, entry) {
@@ -19050,6 +19009,39 @@ function cursorServer(text, entry) {
19050
19009
  obj.mcpServers = servers;
19051
19010
  return { text: serialise(obj), changed: true };
19052
19011
  }
19012
+ function opencodeServer(text, entry) {
19013
+ const read = readObject(text);
19014
+ if ("refused" in read) return read;
19015
+ const { obj } = read;
19016
+ const mcp2 = obj.mcp ?? {};
19017
+ if (!isObject2(mcp2)) return { refused: "its mcp is not an object" };
19018
+ const servers = mcp2.servers ?? {};
19019
+ if (!isObject2(servers)) {
19020
+ return { refused: "its mcp.servers is not an object" };
19021
+ }
19022
+ for (const found of [servers.demoman, mcp2.demoman]) {
19023
+ if (found !== void 0 && !isOurOpencodeEntry(found)) {
19024
+ return { foreign: describeEntry(found) };
19025
+ }
19026
+ }
19027
+ const existing = servers.demoman;
19028
+ const next = isObject2(existing) ? {
19029
+ ...existing,
19030
+ ...entry,
19031
+ environment: {
19032
+ ...isObject2(existing.environment) ? existing.environment : {},
19033
+ ...entry.environment
19034
+ }
19035
+ } : entry;
19036
+ if (text !== null && mcp2.demoman === void 0 && JSON.stringify(existing) === JSON.stringify(next)) {
19037
+ return { text, changed: false };
19038
+ }
19039
+ delete mcp2.demoman;
19040
+ servers.demoman = next;
19041
+ mcp2.servers = servers;
19042
+ obj.mcp = mcp2;
19043
+ return { text: serialise(obj), changed: true };
19044
+ }
19053
19045
  function isOurSkill(text) {
19054
19046
  const m = /^---\r?\n([\s\S]*?)\r?\n---\r?\n([\s\S]*)$/.exec(text);
19055
19047
  if (m === null) return false;
@@ -19057,29 +19049,39 @@ function isOurSkill(text) {
19057
19049
  return /^name:\s*record-demo\s*$/m.test(front) && body.includes("Demoman");
19058
19050
  }
19059
19051
 
19060
- // src/cursor-skill.ts
19061
- function refreshCursorSkill(d) {
19062
- if (d.env.DEMOMAN_CLIENT !== "cursor") return null;
19063
- const path = `${d.home}/.cursor/skills/record-demo/SKILL.md`;
19052
+ // src/agent-skill.ts
19053
+ var SKILL_FOLDERS = {
19054
+ cursor: { agent: "Cursor", folder: (home) => `${home}/.cursor/skills` },
19055
+ opencode: {
19056
+ agent: "OpenCode",
19057
+ folder: (home, env) => `${opencodeDir(home, env)}/skills`
19058
+ }
19059
+ };
19060
+ function refreshAgentSkill(d) {
19061
+ const client = SKILL_FOLDERS[d.env.DEMOMAN_CLIENT ?? ""];
19062
+ if (client === void 0) return null;
19063
+ const path = `${client.folder(d.home, d.env)}/record-demo/SKILL.md`;
19064
+ const not = `${client.agent}'s record-demo skill was not refreshed`;
19064
19065
  if ("error" in d.skill) {
19065
- return `Cursor's record-demo skill was not refreshed: this install's copy could not be read (${d.skill.error})`;
19066
+ return `${not}: this install's copy could not be read (${d.skill.error})`;
19066
19067
  }
19067
19068
  const file = d.readText(path);
19068
19069
  if ("error" in file) {
19069
- return `Cursor's record-demo skill was not refreshed: ${path} could not be read (${file.error})`;
19070
+ return `${not}: ${path} could not be read (${file.error})`;
19070
19071
  }
19071
19072
  if ("missing" in file) {
19072
- return `Cursor's record-demo skill was not refreshed: ${path} is not there (\`npx demoman setup\` puts it back)`;
19073
+ return `${not}: ${path} is not there (\`npx demoman setup\` puts it back)`;
19073
19074
  }
19074
19075
  if (file.text === d.skill.text) return null;
19075
19076
  if (!isOurSkill(file.text)) {
19076
- return `Cursor's record-demo skill was not refreshed: ${path} is not Demoman's, so it was left alone`;
19077
+ return `${not}: ${path} is not Demoman's, so it was left alone`;
19077
19078
  }
19078
19079
  const wrote = d.writeText(path, d.skill.text);
19079
- return "error" in wrote ? `Cursor's record-demo skill was not refreshed: ${path} could not be written (${wrote.error})` : `Cursor's record-demo skill was refreshed to this version's (${path})`;
19080
+ return "error" in wrote ? `${not}: ${path} could not be written (${wrote.error})` : `${client.agent}'s record-demo skill was refreshed to this version's (${path})`;
19080
19081
  }
19081
19082
 
19082
19083
  // src/setup.ts
19084
+ import { parseArgs } from "node:util";
19083
19085
  var MIN_NODE = 20;
19084
19086
  var failed = (r) => r.notFound === true || r.error !== void 0 || r.status !== 0;
19085
19087
  var why = (r) => r.error ?? `${r.stderr}
@@ -19130,6 +19132,64 @@ function browser(d) {
19130
19132
  d.say("browser: Chromium installed");
19131
19133
  return true;
19132
19134
  }
19135
+ var AGENT_FLAGS = [
19136
+ ["claude", "Claude Code"],
19137
+ ["codex", "Codex"],
19138
+ ["cursor", "Cursor"],
19139
+ ["opencode", "OpenCode"]
19140
+ ];
19141
+ function parseSetupArgs(args2) {
19142
+ let values;
19143
+ try {
19144
+ ({ values } = parseArgs({
19145
+ args: args2,
19146
+ options: {
19147
+ yes: { type: "boolean" },
19148
+ agents: { type: "string" },
19149
+ quality: { type: "string" },
19150
+ "pull-requests": { type: "string" }
19151
+ },
19152
+ strict: true,
19153
+ allowPositionals: false
19154
+ }));
19155
+ } catch (error) {
19156
+ return { refused: error instanceof Error ? error.message : String(error) };
19157
+ }
19158
+ const flags = values.yes === true ? { yes: true } : {};
19159
+ if (values.agents !== void 0) {
19160
+ const words = values.agents.split(",").map((w) => w.trim());
19161
+ const unknown = words.find(
19162
+ (w) => !AGENT_FLAGS.some(([flag]) => flag === w)
19163
+ );
19164
+ if (unknown !== void 0) {
19165
+ return {
19166
+ refused: `--agents takes ${AGENT_FLAGS.map(([flag]) => flag).join(", ")}, comma-separated; got "${unknown}"`
19167
+ };
19168
+ }
19169
+ flags.agents = AGENT_FLAGS.filter(([flag]) => words.includes(flag)).map(
19170
+ ([, name]) => name
19171
+ );
19172
+ }
19173
+ const quality = values.quality;
19174
+ if (quality !== void 0) {
19175
+ if (!isExportQuality(quality)) {
19176
+ return {
19177
+ refused: `--quality must be ${EXPORT_QUALITY_VALUES.join(", ")}; got "${quality}"`
19178
+ };
19179
+ }
19180
+ flags.quality = quality;
19181
+ }
19182
+ const pr = values["pull-requests"];
19183
+ if (pr !== void 0) {
19184
+ if (!isPullRequestsValue(pr)) {
19185
+ return {
19186
+ refused: `--pull-requests must be ${PULL_REQUESTS_VALUES.join(", ")}; got "${pr}"`
19187
+ };
19188
+ }
19189
+ flags.pullRequests = pr;
19190
+ }
19191
+ return flags;
19192
+ }
19133
19193
  var CLAUDE_ALLOW_RULE = "mcp__plugin_demoman_demoman__*";
19134
19194
  function edited(d, path, edit) {
19135
19195
  const file = d.readText(path);
@@ -19368,9 +19428,9 @@ function duplicates(d) {
19368
19428
  }
19369
19429
  }
19370
19430
  }
19371
- function setup(d) {
19431
+ async function setup(d, flags = {}) {
19372
19432
  try {
19373
- return steps2(d);
19433
+ return await steps2(d, flags);
19374
19434
  } catch (error) {
19375
19435
  d.say(
19376
19436
  `Demoman setup stopped: ${error instanceof Error ? error.message : String(error)}`
@@ -19406,13 +19466,9 @@ var codex = (d) => {
19406
19466
  );
19407
19467
  return result("failed");
19408
19468
  }
19409
- const said = /(\d+)\.(\d+)\.(\d+)/.exec(version.stdout);
19410
- const rank = ([a = 0, b = 0, c = 0]) => a * 1e6 + b * 1e3 + c;
19411
- const older = said !== null && rank(said.slice(1, 4).map(Number)) < rank(CODEX_MIN);
19412
- if (said === null || older) {
19413
- const which = said?.[0] ?? `"${version.stdout.trim()}"`;
19469
+ if (older(version.stdout, CODEX_MIN)) {
19414
19470
  d.say(
19415
- `Codex: this is Codex ${which}, and Demoman needs ${CODEX_MIN.join(".")} or later for \`codex plugin\` \u2014 update Codex, then ${again}`
19471
+ `Codex: this is Codex ${versionIn(version.stdout)}, and Demoman needs ${CODEX_MIN.join(".")} or later for \`codex plugin\` \u2014 update Codex, then ${again}`
19416
19472
  );
19417
19473
  return result("failed");
19418
19474
  }
@@ -19493,6 +19549,24 @@ ${CODEX_APPROVAL_TABLE}
19493
19549
  );
19494
19550
  return result("partial");
19495
19551
  };
19552
+ var cursorApps = (d) => [
19553
+ "/Applications/Cursor.app",
19554
+ `${d.home}/Applications/Cursor.app`
19555
+ ];
19556
+ var cursorClis = (d) => [
19557
+ "agent",
19558
+ `${d.home}/.local/bin/agent`,
19559
+ "cursor-agent"
19560
+ ];
19561
+ function foundAgents(d) {
19562
+ const there = (command2) => !d.run(command2, ["--version"]).notFound;
19563
+ return [
19564
+ ...there("claude") ? ["Claude Code"] : [],
19565
+ ...there("codex") ? ["Codex"] : [],
19566
+ ...cursorApps(d).some((p) => d.exists(p)) || cursorClis(d).some(there) ? ["Cursor"] : [],
19567
+ ...there("opencode") ? ["OpenCode"] : []
19568
+ ];
19569
+ }
19496
19570
  var CURSOR_ALLOW_RULE = "Mcp(demoman:*)";
19497
19571
  var cursor = (d) => {
19498
19572
  const result = (state) => ({
@@ -19500,13 +19574,10 @@ var cursor = (d) => {
19500
19574
  state
19501
19575
  });
19502
19576
  const again = `run \`npx ${PACKAGE_NAME}@${d.version} setup\` again`;
19503
- const app = [
19504
- "/Applications/Cursor.app",
19505
- `${d.home}/Applications/Cursor.app`
19506
- ].some((p) => d.exists(p));
19577
+ const app = cursorApps(d).some((p) => d.exists(p));
19507
19578
  let cli = null;
19508
19579
  let odd = null;
19509
- for (const c of ["agent", `${d.home}/.local/bin/agent`, "cursor-agent"]) {
19580
+ for (const c of cursorClis(d)) {
19510
19581
  const r = d.run(c, ["--version"]);
19511
19582
  if (r.notFound) continue;
19512
19583
  if (!failed(r) && /^\d{4}\.\d{2}\.\d{2}/.test(r.stdout.trim())) {
@@ -19527,20 +19598,7 @@ var cursor = (d) => {
19527
19598
  d.say("Cursor: not installed");
19528
19599
  return result("absent");
19529
19600
  }
19530
- if ("error" in d.skill) {
19531
- d.say(
19532
- `Cursor: this install's record-demo skill could not be read (${d.skill.error}); reinstall Demoman, then ${again}`
19533
- );
19534
- return result("failed");
19535
- }
19536
- const shipped = d.skill.text;
19537
- const npx = `${d.nodeBin}/npx`;
19538
- if (!d.exists(npx)) {
19539
- d.say(
19540
- `Cursor: there is no npx beside the Node running setup (${npx}), so an entry naming it could not start \u2014 run setup with a Node that has npx`
19541
- );
19542
- return result("failed");
19543
- }
19601
+ if (!canWriteEntry(d, "Cursor", again)) return result("failed");
19544
19602
  const mcpPath = `${d.home}/.cursor/mcp.json`;
19545
19603
  const entry = cursorEntry(d.nodeBin);
19546
19604
  const pasteIn = `add this under "mcpServers" in ${mcpPath}, then ${again}:
@@ -19572,28 +19630,15 @@ var cursor = (d) => {
19572
19630
  return result("failed");
19573
19631
  }
19574
19632
  }
19575
- const skillDir = "~/.cursor/skills/record-demo";
19576
- const skillPath = `${d.home}/.cursor/skills/record-demo/SKILL.md`;
19577
- const skill = d.readText(skillPath);
19578
- if ("error" in skill) {
19579
- d.say(`Cursor: ${skillPath} could not be read (${skill.error})`);
19580
- return result("failed");
19581
- }
19582
- if ("text" in skill && !isOurSkill(skill.text)) {
19583
- d.say(
19584
- `Cursor: ${skillDir} already holds a skill that is not Demoman's, so it was left alone \u2014 rename that folder, then ${again}`
19585
- );
19633
+ if (!placeSkill(
19634
+ d,
19635
+ "Cursor",
19636
+ "~/.cursor/skills/record-demo",
19637
+ `${d.home}/.cursor/skills/record-demo/SKILL.md`,
19638
+ again
19639
+ )) {
19586
19640
  return result("failed");
19587
19641
  }
19588
- if (!("text" in skill) || skill.text !== shipped) {
19589
- const wrote = d.writeText(skillPath, shipped);
19590
- if ("error" in wrote) {
19591
- d.say(
19592
- `Cursor: the record-demo skill could not be written (${wrote.error})`
19593
- );
19594
- return result("failed");
19595
- }
19596
- }
19597
19642
  const reasons = [];
19598
19643
  if (cli !== null) {
19599
19644
  const enable = d.run(cli, ["mcp", "enable", "demoman"]);
@@ -19629,43 +19674,267 @@ var cursor = (d) => {
19629
19674
  d.say(`${connected}, but ${reasons.join("; ")}`);
19630
19675
  return result("partial");
19631
19676
  };
19677
+ var VERSION_RE = /(\d+)\.(\d+)\.(\d+)/;
19678
+ var versionIn = (stdout) => VERSION_RE.exec(stdout)?.[0] ?? `"${stdout.trim()}"`;
19679
+ function older(stdout, min) {
19680
+ const said = VERSION_RE.exec(stdout);
19681
+ if (said === null) return true;
19682
+ const rank = ([a = 0, b = 0, c = 0]) => a * 1e6 + b * 1e3 + c;
19683
+ return rank(said.slice(1, 4).map(Number)) < rank(min);
19684
+ }
19685
+ function canWriteEntry(d, agent, again) {
19686
+ if ("error" in d.skill) {
19687
+ d.say(
19688
+ `${agent}: this install's record-demo skill could not be read (${d.skill.error}); reinstall Demoman, then ${again}`
19689
+ );
19690
+ return false;
19691
+ }
19692
+ const npx = `${d.nodeBin}/npx`;
19693
+ if (!d.exists(npx)) {
19694
+ d.say(
19695
+ `${agent}: there is no npx beside the Node running setup (${npx}), so an entry naming it could not start \u2014 run setup with a Node that has npx`
19696
+ );
19697
+ return false;
19698
+ }
19699
+ return true;
19700
+ }
19701
+ function placeSkill(d, agent, folder, path, again) {
19702
+ if ("error" in d.skill) return false;
19703
+ const skill = d.readText(path);
19704
+ if ("error" in skill) {
19705
+ d.say(`${agent}: ${path} could not be read (${skill.error})`);
19706
+ return false;
19707
+ }
19708
+ if ("text" in skill && !isOurSkill(skill.text)) {
19709
+ d.say(
19710
+ `${agent}: ${folder} already holds a skill that is not Demoman's, so it was left alone \u2014 rename that folder, then ${again}`
19711
+ );
19712
+ return false;
19713
+ }
19714
+ if ("text" in skill && skill.text === d.skill.text) return true;
19715
+ const wrote = d.writeText(path, d.skill.text);
19716
+ if ("error" in wrote) {
19717
+ d.say(
19718
+ `${agent}: the record-demo skill could not be written (${wrote.error})`
19719
+ );
19720
+ return false;
19721
+ }
19722
+ return true;
19723
+ }
19724
+ var OPENCODE_MIN = [2, 0, 0];
19725
+ var opencode = (d) => {
19726
+ const result = (state) => ({
19727
+ agent: "OpenCode",
19728
+ state
19729
+ });
19730
+ const again = `run \`npx ${PACKAGE_NAME}@${d.version} setup\` again`;
19731
+ const version = d.run("opencode", ["--version"]);
19732
+ if (version.notFound) {
19733
+ d.say("OpenCode: not installed");
19734
+ return result("absent");
19735
+ }
19736
+ if (failed(version)) {
19737
+ d.say(
19738
+ `OpenCode: \`opencode --version\` failed (${why(version)}); fix that, then ${again}`
19739
+ );
19740
+ return result("failed");
19741
+ }
19742
+ if (older(version.stdout, OPENCODE_MIN)) {
19743
+ d.say(
19744
+ `OpenCode: this is OpenCode ${versionIn(version.stdout)}, and Demoman needs ${OPENCODE_MIN.join(".")} or later \u2014 update OpenCode, then ${again}`
19745
+ );
19746
+ return result("failed");
19747
+ }
19748
+ if (!canWriteEntry(d, "OpenCode", again)) return result("failed");
19749
+ const dir = opencodeDir(d.home, d.env);
19750
+ const config = `${dir}/opencode.json`;
19751
+ const entry = opencodeEntry(d.nodeBin);
19752
+ const pasteIn = (file2) => `add this under "mcp" \u2192 "servers" in ${file2}, then ${again}:
19753
+
19754
+ "demoman": ${JSON.stringify(entry, null, 2)}
19755
+ `;
19756
+ const jsonc = `${dir}/opencode.jsonc`;
19757
+ if (d.exists(jsonc)) {
19758
+ d.say(
19759
+ `OpenCode: ${jsonc} may hold comments an edit would lose, so it was left alone; ${pasteIn(jsonc)}`
19760
+ );
19761
+ return result("failed");
19762
+ }
19763
+ const file = d.readText(config);
19764
+ if ("error" in file) {
19765
+ d.say(
19766
+ `OpenCode: ${config} could not be read (${file.error}); ${pasteIn(config)}`
19767
+ );
19768
+ return result("failed");
19769
+ }
19770
+ const edit = opencodeServer("text" in file ? file.text : null, entry);
19771
+ if ("foreign" in edit) {
19772
+ d.say(
19773
+ `OpenCode: ${config} already has a "demoman" server that setup did not write (${edit.foreign}), so it was left alone \u2014 remove that entry, then ${again}`
19774
+ );
19775
+ return result("failed");
19776
+ }
19777
+ if ("refused" in edit) {
19778
+ d.say(
19779
+ `OpenCode: ${config} was left alone: ${edit.refused}; ${pasteIn(config)}`
19780
+ );
19781
+ return result("failed");
19782
+ }
19783
+ if (edit.changed) {
19784
+ const wrote = d.writeText(config, edit.text);
19785
+ if ("error" in wrote) {
19786
+ d.say(
19787
+ `OpenCode: ${config} could not be written (${wrote.error}); ${pasteIn(config)}`
19788
+ );
19789
+ return result("failed");
19790
+ }
19791
+ }
19792
+ if (!placeSkill(
19793
+ d,
19794
+ "OpenCode",
19795
+ `${dir}/skills/record-demo`,
19796
+ `${dir}/skills/record-demo/SKILL.md`,
19797
+ again
19798
+ )) {
19799
+ return result("failed");
19800
+ }
19801
+ d.say("OpenCode: Demoman is connected and updates itself");
19802
+ return result("wired");
19803
+ };
19632
19804
  var listed2 = (names) => names.length < 2 ? names.join("") : `${names.slice(0, -1).join(", ")} and ${names.at(-1)}`;
19633
- function steps2(d) {
19805
+ async function steps2(given, flags) {
19806
+ const d = flags.yes === true ? { ...given, ask: null } : given;
19634
19807
  const refusal = platformRefusal(d.platform, d.nodeVersion);
19635
19808
  if (refusal !== null) {
19636
19809
  d.say(`Demoman setup stopped: ${refusal}.`);
19637
19810
  return 1;
19638
19811
  }
19639
19812
  d.say(`Demoman ${d.version} setup`);
19813
+ const questions = {};
19814
+ const found = d.ask !== null && flags.agents === void 0 ? foundAgents(d) : [];
19815
+ if (found.length > 0) questions.agents = found;
19816
+ const wantsSettings = d.ask !== null || flags.quality !== void 0 || flags.pullRequests !== void 0;
19817
+ let preselected = {};
19818
+ if (wantsSettings) {
19819
+ const read = await d.settings.read();
19820
+ if (read.unreadable !== void 0) d.say(`settings: ${read.unreadable}`);
19821
+ preselected = {
19822
+ quality: read.exportQuality,
19823
+ pullRequests: read.pullRequests ?? PULL_REQUESTS_DEFAULT
19824
+ };
19825
+ if (d.ask !== null && flags.quality === void 0) {
19826
+ questions.quality = preselected.quality;
19827
+ }
19828
+ if (d.ask !== null && flags.pullRequests === void 0) {
19829
+ questions.pullRequests = preselected.pullRequests;
19830
+ }
19831
+ }
19832
+ let answers = {};
19833
+ if (d.ask !== null && Object.keys(questions).length > 0) {
19834
+ const got = await d.ask(questions);
19835
+ if (got === "cancelled") {
19836
+ d.say("Setup cancelled; nothing was changed.");
19837
+ return 1;
19838
+ }
19839
+ answers = got;
19840
+ }
19841
+ const chosen = flags.agents ?? answers.agents;
19842
+ const skip = (agent) => chosen !== void 0 && !chosen.includes(agent) && (flags.agents !== void 0 || found.includes(agent));
19640
19843
  if (!browser(d)) return 1;
19641
- const results = [claudeCode, codex, cursor].map((wire) => wire(d));
19844
+ const wires = [
19845
+ ["Claude Code", claudeCode],
19846
+ ["Codex", codex],
19847
+ ["Cursor", cursor],
19848
+ ["OpenCode", opencode]
19849
+ ];
19850
+ const results = wires.map(([agent, wire]) => {
19851
+ if (!skip(agent)) {
19852
+ const r = wire(d);
19853
+ return r.state === "absent" && flags.agents?.includes(agent) ? { agent, state: "failed" } : r;
19854
+ }
19855
+ d.say(`${agent}: not connected (not chosen)`);
19856
+ return { agent, state: "skipped" };
19857
+ });
19858
+ const settingsFailed = await saveSettings(d, preselected, {
19859
+ quality: flags.quality ?? answers.quality,
19860
+ pullRequests: flags.pullRequests ?? answers.pullRequests
19861
+ });
19642
19862
  const usable = results.filter((r) => r.state === "wired" || r.state === "partial").map((r) => r.agent);
19643
19863
  const failed2 = results.filter((r) => r.state === "failed").map((r) => r.agent);
19644
- if (usable.length === 0 && failed2.length === 0) {
19864
+ const notDone = [
19865
+ ...failed2.length > 0 ? [`${listed2(failed2)} could not be set up`] : [],
19866
+ ...settingsFailed
19867
+ ];
19868
+ if (notDone.length > 0) {
19869
+ if (usable.length > 0) warmStart(d, usable);
19645
19870
  d.say(
19646
19871
  `
19647
- No coding agent was found. Demoman works with Claude Code, Codex and Cursor: install one and run \`npx ${PACKAGE_NAME}@${d.version} setup\` again, or connect another MCP client with the block in the README (https://www.npmjs.com/package/${PACKAGE_NAME}).`
19872
+ Not done: ${notDone.join(", and ")} (above).${usable.length > 0 ? ` Restart ${listed2(usable)} to use Demoman there.` : ""}`
19648
19873
  );
19649
19874
  return 1;
19650
19875
  }
19651
- if (usable.length > 0) warmStart(d, usable);
19652
- if (failed2.length > 0) {
19876
+ if (usable.length === 0 && failed2.length === 0 && results.some((r) => r.state === "skipped")) {
19877
+ d.say(
19878
+ `
19879
+ Done. No agent was connected; run \`npx ${PACKAGE_NAME}@${d.version} setup\` again to connect one.`
19880
+ );
19881
+ return 0;
19882
+ }
19883
+ if (usable.length === 0 && failed2.length === 0) {
19653
19884
  d.say(
19654
19885
  `
19655
- Not done: ${listed2(failed2)} could not be set up (above).${usable.length > 0 ? ` Restart ${listed2(usable)} to use Demoman there.` : ""}`
19886
+ No coding agent was found. Demoman works with Claude Code, Codex and Cursor: install one and run \`npx ${PACKAGE_NAME}@${d.version} setup\` again, or connect another MCP client with the block in the README (https://www.npmjs.com/package/${PACKAGE_NAME}).`
19656
19887
  );
19657
19888
  return 1;
19658
19889
  }
19890
+ if (usable.length > 0) warmStart(d, usable);
19659
19891
  d.say(
19660
19892
  `
19661
- Done. Restart ${listed2(usable)}, then ask for a demo, for example: "make a demo of demoman.io/sample".`
19893
+ Done. Restart ${listed2(usable)}, then in your app's repo ask for a demo, for example: "make a demo of the feature we just built".`
19894
+ );
19895
+ d.say(
19896
+ `If your app needs a login, sign in once with \`npx ${PACKAGE_NAME} signin <url>\`.`
19662
19897
  );
19663
19898
  return 0;
19664
19899
  }
19900
+ async function saveSettings(d, preselected, answered) {
19901
+ const changes = [];
19902
+ if (answered.quality !== void 0 && answered.quality !== preselected.quality) {
19903
+ changes.push([
19904
+ "exportQuality",
19905
+ answered.quality,
19906
+ `export quality is now ${EXPORT_QUALITY_LABELS[answered.quality]}`
19907
+ ]);
19908
+ }
19909
+ if (answered.pullRequests !== void 0 && answered.pullRequests !== preselected.pullRequests) {
19910
+ changes.push([
19911
+ "pullRequests",
19912
+ answered.pullRequests,
19913
+ `pull requests is now ${PULL_REQUESTS_LABELS[answered.pullRequests]}`
19914
+ ]);
19915
+ }
19916
+ const failed2 = /* @__PURE__ */ new Set();
19917
+ for (const [key, value, said] of changes) {
19918
+ const wrote = await d.settings.write(key, value);
19919
+ if ("reason" in wrote) {
19920
+ d.say(`settings: ${wrote.detail}`);
19921
+ failed2.add("a setting was not saved");
19922
+ continue;
19923
+ }
19924
+ d.say(`settings: ${said}`);
19925
+ if (wrote.replaced !== void 0) {
19926
+ d.say(`settings: ${wrote.replaced}`);
19927
+ failed2.add("the settings file was replaced");
19928
+ }
19929
+ }
19930
+ return [...failed2];
19931
+ }
19932
+ var ON_LATEST = ["Cursor", "OpenCode"];
19665
19933
  function warmStart(d, usable) {
19934
+ const onLatest = usable.filter((a) => ON_LATEST.includes(a));
19666
19935
  const specs = [
19667
- ...usable.some((a) => a !== "Cursor") ? [d.version] : [],
19668
- ...usable.includes("Cursor") ? ["latest"] : []
19936
+ ...usable.some((a) => !ON_LATEST.includes(a)) ? [d.version] : [],
19937
+ ...onLatest.length > 0 ? ["latest"] : []
19669
19938
  ];
19670
19939
  const cold = [];
19671
19940
  for (const spec of specs) {
@@ -19678,7 +19947,7 @@ function warmStart(d, usable) {
19678
19947
  );
19679
19948
  } else if (!pinned && answer !== d.version) {
19680
19949
  d.say(
19681
- `Cursor: it runs Demoman ${answer}, the newest release on npm, and this setup is ${d.version}. A version published under npm's next tag alone does not reach Cursor.`
19950
+ `${listed2(onLatest)}: ${onLatest.length > 1 ? "they run" : "it runs"} Demoman ${answer}, the newest release on npm, and this setup is ${d.version}. A version published under npm's next tag alone does not reach ${onLatest.length > 1 ? "them" : onLatest[0]}.`
19682
19951
  );
19683
19952
  }
19684
19953
  }
@@ -19705,6 +19974,7 @@ import {
19705
19974
  import { createRequire as createRequire2 } from "node:module";
19706
19975
  import { homedir as homedir3 } from "node:os";
19707
19976
  import { dirname as dirname6, isAbsolute as isAbsolute3, join as join28 } from "node:path";
19977
+ import { isCancel, multiselect, select } from "@clack/prompts";
19708
19978
  var CAPTURED_TIMEOUT_MS = 18e4;
19709
19979
  function ran(command2, r, timeoutMs) {
19710
19980
  const code2 = r.error?.code;
@@ -19823,7 +20093,59 @@ function claudePaths(home, configDir) {
19823
20093
  managed: CLAUDE_MANAGED_SETTINGS
19824
20094
  };
19825
20095
  }
19826
- function realSetupDeps(version, distDir) {
20096
+ var SETUP_HINTS = {
20097
+ share: "Small enough for a chat or a pull request.",
20098
+ high: "1440p at 60 fps, about 30 MB for 30 seconds.",
20099
+ full: "The largest size the recording supports.",
20100
+ off: "Never attach a demo to a pull request.",
20101
+ ask: "Ask to attach a demo each time your agent creates a PR.",
20102
+ attach: "Always attach a demo whenever your agent creates a PR."
20103
+ };
20104
+ async function askInTerminal(q) {
20105
+ const answers = {};
20106
+ if (q.agents !== void 0) {
20107
+ const got = await multiselect({
20108
+ message: "Connect Demoman to",
20109
+ options: q.agents.map((a) => ({ value: a, label: a })),
20110
+ initialValues: q.agents,
20111
+ required: false
20112
+ });
20113
+ if (isCancel(got)) return "cancelled";
20114
+ answers.agents = got;
20115
+ }
20116
+ if (q.quality !== void 0) {
20117
+ const got = await select({
20118
+ message: "Export quality",
20119
+ options: EXPORT_QUALITY_VALUES.map((v) => ({
20120
+ value: v,
20121
+ label: EXPORT_QUALITY_LABELS[v],
20122
+ hint: SETUP_HINTS[v]
20123
+ })),
20124
+ initialValue: q.quality
20125
+ });
20126
+ if (isCancel(got)) return "cancelled";
20127
+ answers.quality = got;
20128
+ }
20129
+ if (q.pullRequests !== void 0) {
20130
+ const got = await select({
20131
+ message: "Pull requests",
20132
+ options: PULL_REQUESTS_VALUES.map((v) => ({
20133
+ value: v,
20134
+ label: PULL_REQUESTS_LABELS[v],
20135
+ hint: SETUP_HINTS[v]
20136
+ })),
20137
+ initialValue: q.pullRequests
20138
+ });
20139
+ if (isCancel(got)) return "cancelled";
20140
+ answers.pullRequests = got;
20141
+ }
20142
+ return answers;
20143
+ }
20144
+ function realSetupDeps(version, distDir, io = {
20145
+ stdinTTY: process.stdin.isTTY === true,
20146
+ stdoutTTY: process.stdout.isTTY === true,
20147
+ env: process.env
20148
+ }) {
19827
20149
  const home = homedir3();
19828
20150
  return {
19829
20151
  platform: process.platform,
@@ -19851,7 +20173,13 @@ function realSetupDeps(version, distDir) {
19851
20173
  readText: readTextFile,
19852
20174
  writeText: writeTextFile,
19853
20175
  say: (line2) => void process.stdout.write(`${line2}
19854
- `)
20176
+ `),
20177
+ // An agent's shell, a pipe or CI: nobody can answer, so nothing is asked.
20178
+ ask: io.stdinTTY && io.stdoutTTY && io.env.CI === void 0 ? askInTerminal : null,
20179
+ settings: {
20180
+ read: () => readUserSettings(demomanHome()),
20181
+ write: (key, value) => writeSetting(demomanHome(), key, value)
20182
+ }
19855
20183
  };
19856
20184
  }
19857
20185
 
@@ -19888,7 +20216,7 @@ function parseStudioArgs(args2) {
19888
20216
  }
19889
20217
 
19890
20218
  // src/version.ts
19891
- var VERSION = "0.7.1";
20219
+ var VERSION = "0.7.2";
19892
20220
 
19893
20221
  // src/main.ts
19894
20222
  var log = (line2) => {
@@ -19911,11 +20239,12 @@ function requirePageBundles(pages, say) {
19911
20239
  var USAGE = `demoman ${VERSION}
19912
20240
 
19913
20241
  npx demoman setup install the browser and connect your coding agents
20242
+ [--yes] [--agents claude,codex,cursor] [--quality share|high|full] [--pull-requests off|ask|attach]
19914
20243
  npx demoman signin <url> sign in to your app once, so agents can record behind the login
19915
20244
  npx demoman signin --account <name> [--site <origin>] [--project <dir>]
19916
20245
  sign in as a demo account from .demoman/accounts.json (CI, or a check)
19917
- npx demoman studio [take] open the studio, to look over and edit takes and export them
19918
- npx demoman studio --stop close the studio
20246
+ npx demoman studio [take] open the Studio, to look over and edit takes and export them
20247
+ npx demoman studio --stop close the Studio
19919
20248
  demoman mcp [--headed] serve Demoman's tools on stdio (your agent runs this);
19920
20249
  --headed shows the browser while it records
19921
20250
  demoman --version
@@ -19923,7 +20252,7 @@ var USAGE = `demoman ${VERSION}
19923
20252
  async function mcp(args2) {
19924
20253
  let values;
19925
20254
  try {
19926
- ({ values } = parseArgs({
20255
+ ({ values } = parseArgs2({
19927
20256
  args: args2,
19928
20257
  options: {
19929
20258
  // Accepted so a registration written for the archived extension
@@ -19966,7 +20295,7 @@ async function mcp(args2) {
19966
20295
  );
19967
20296
  process.exit(1);
19968
20297
  }
19969
- const skill = refreshCursorSkill({
20298
+ const skill = refreshAgentSkill({
19970
20299
  env: process.env,
19971
20300
  home: homedir4(),
19972
20301
  skill: readSkill(here),
@@ -19986,9 +20315,11 @@ async function mcp(args2) {
19986
20315
  // the runner's own answer, which `demoman-mcp` names too.
19987
20316
  executablePath: fullChromiumPath(),
19988
20317
  ...values["out-dir"] === void 0 ? {} : { outDir: resolve3(values["out-dir"]) },
19989
- installCommand: `npx ${PACKAGE_NAME}@${VERSION} setup`,
20318
+ // --yes: an agent may run it in a pseudo-terminal, where a menu would
20319
+ // wait for an answer nobody gives.
20320
+ installCommand: `npx ${PACKAGE_NAME}@${VERSION} setup --yes`,
19990
20321
  signinCommand: `npx ${PACKAGE_NAME}@${VERSION} signin`,
19991
- updateCommand: `npx ${PACKAGE_NAME}@latest setup`,
20322
+ updateCommand: `npx ${PACKAGE_NAME}@latest setup --yes`,
19992
20323
  updateCheck: createUpdateCheck({
19993
20324
  name: PACKAGE_NAME,
19994
20325
  current: VERSION,
@@ -20018,13 +20349,13 @@ ${USAGE}`);
20018
20349
  if (parsed2.kind === "stop") {
20019
20350
  const { stopped, cutShort, why: why2 } = await stopStudio({ home });
20020
20351
  if (!stopped && why2 !== void 0) {
20021
- process.stderr.write(`demoman: the studio was not stopped: ${why2}
20352
+ process.stderr.write(`demoman: the Studio was not stopped: ${why2}
20022
20353
  `);
20023
20354
  process.exit(1);
20024
20355
  }
20025
20356
  process.stdout.write(
20026
- stopped ? `Stopped the studio.${cutShort > 0 ? " An export was cut short." : ""}
20027
- ` : "No studio is running.\n"
20357
+ stopped ? `Stopped the Studio.${cutShort > 0 ? " An export was cut short." : ""}
20358
+ ` : "No Studio is running.\n"
20028
20359
  );
20029
20360
  process.exit(0);
20030
20361
  }
@@ -20037,7 +20368,7 @@ ${USAGE}`);
20037
20368
  if ("outcome" in answer) {
20038
20369
  process.stdout.write(
20039
20370
  `${answer.note === void 0 ? "" : `${answer.note}
20040
- `}Opened the studio. This link works once, for a minute: ${answer.url}
20371
+ `}Opened the Studio. This link works once, for a minute: ${answer.url}
20041
20372
  `
20042
20373
  );
20043
20374
  process.exit(0);
@@ -20073,6 +20404,12 @@ switch (command) {
20073
20404
  await studio(rest);
20074
20405
  break;
20075
20406
  case "setup": {
20407
+ const flags = parseSetupArgs(rest);
20408
+ if ("refused" in flags) {
20409
+ process.stdout.write(`Demoman setup stopped: ${flags.refused}.
20410
+ `);
20411
+ process.exit(1);
20412
+ }
20076
20413
  let deps;
20077
20414
  try {
20078
20415
  deps = realSetupDeps(
@@ -20086,7 +20423,7 @@ switch (command) {
20086
20423
  );
20087
20424
  process.exit(1);
20088
20425
  }
20089
- process.exit(setup(deps));
20426
+ process.exit(await setup(deps, flags));
20090
20427
  break;
20091
20428
  }
20092
20429
  case "signin": {
@@ -20094,7 +20431,7 @@ switch (command) {
20094
20431
  let values;
20095
20432
  let positionals;
20096
20433
  try {
20097
- ({ values, positionals } = parseArgs({
20434
+ ({ values, positionals } = parseArgs2({
20098
20435
  args: rest,
20099
20436
  options: {
20100
20437
  account: { type: "string" },