glimmervoid 0.48.4-next.362 → 0.48.4-next.364

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/dist/chunks/{main-BFniOErR.js → main-DBmWw1C0.js} +57 -49
  2. package/dist/client/assets/{benchmark-panel-BRTPARGF.js → benchmark-panel-CItUf5Z7.js} +1 -1
  3. package/dist/client/assets/benchmark-panel-CItUf5Z7.js.br +0 -0
  4. package/dist/client/assets/{boards-view-t6Kni_OG.js → boards-view-CJZSrNZp.js} +1 -1
  5. package/dist/client/assets/boards-view-CJZSrNZp.js.br +0 -0
  6. package/dist/client/assets/{community-panel-xT-w6RPr.js → community-panel-VbKfBlhk.js} +1 -1
  7. package/dist/client/assets/community-panel-VbKfBlhk.js.br +0 -0
  8. package/dist/client/assets/{dialogs-DRYpTh--.js → dialogs-uJsZW_qH.js} +1 -1
  9. package/dist/client/assets/dialogs-uJsZW_qH.js.br +0 -0
  10. package/dist/client/assets/{doc-editor-ui-BGIAVcg7.js → doc-editor-ui-DxgaVql0.js} +1 -1
  11. package/dist/client/assets/doc-editor-ui-DxgaVql0.js.br +0 -0
  12. package/dist/client/assets/{feature-hint-DmrtnjCy.js → feature-hint-CcU9GWDV.js} +1 -1
  13. package/dist/client/assets/feature-hint-CcU9GWDV.js.br +0 -0
  14. package/dist/client/assets/{first-run-checklist-3tiKot6p.js → first-run-checklist-DVRtnuj7.js} +1 -1
  15. package/dist/client/assets/first-run-checklist-DVRtnuj7.js.br +0 -0
  16. package/dist/client/assets/{hooks-panel-CKfErnuU.js → hooks-panel-CJttKHkf.js} +1 -1
  17. package/dist/client/assets/hooks-panel-CJttKHkf.js.br +0 -0
  18. package/dist/client/assets/{index-k2H9o6FW.js → index-BlbUd3zj.js} +5 -5
  19. package/dist/client/assets/index-BlbUd3zj.js.br +0 -0
  20. package/dist/client/assets/{issues-panel-DwO_6TTO.js → issues-panel-DR_QlGoi.js} +1 -1
  21. package/dist/client/assets/issues-panel-DR_QlGoi.js.br +0 -0
  22. package/dist/client/assets/{my-prs-panel-bKQK1yAe.js → my-prs-panel-CFieQZHq.js} +1 -1
  23. package/dist/client/assets/my-prs-panel-CFieQZHq.js.br +0 -0
  24. package/dist/client/assets/{nyan-cat-Brf_F8nH.js → nyan-cat-BylNueXg.js} +1 -1
  25. package/dist/client/assets/nyan-cat-BylNueXg.js.br +0 -0
  26. package/dist/client/assets/{phone-shell-BZNhRPSl.js → phone-shell-D4JR620j.js} +1 -1
  27. package/dist/client/assets/phone-shell-D4JR620j.js.br +0 -0
  28. package/dist/client/assets/{plan-face-bWTHQdEe.js → plan-face-Ck5f8fOJ.js} +1 -1
  29. package/dist/client/assets/plan-face-Ck5f8fOJ.js.br +0 -0
  30. package/dist/client/assets/{pr-queue-columns-WDQqbW0O.js → pr-queue-columns-DFjXXF3o.js} +1 -1
  31. package/dist/client/assets/pr-queue-columns-DFjXXF3o.js.br +0 -0
  32. package/dist/client/assets/{radar-panel-DmdHKxoV.js → radar-panel-DgFLKha7.js} +1 -1
  33. package/dist/client/assets/radar-panel-DgFLKha7.js.br +0 -0
  34. package/dist/client/assets/{repo-roots-adder-Dvp9iTxp.js → repo-roots-adder-Ly0caqtn.js} +1 -1
  35. package/dist/client/assets/repo-roots-adder-Ly0caqtn.js.br +0 -0
  36. package/dist/client/assets/{resume-dialog-DlXllNiY.js → resume-dialog-CTzp0RhE.js} +1 -1
  37. package/dist/client/assets/resume-dialog-CTzp0RhE.js.br +0 -0
  38. package/dist/client/assets/{review-queue-panel-CfW9Y9G3.js → review-queue-panel-DlAC6ZCL.js} +1 -1
  39. package/dist/client/assets/review-queue-panel-DlAC6ZCL.js.br +0 -0
  40. package/dist/client/assets/{settings-panel-Dk1tKjVD.js → settings-panel-Cf3sByHu.js} +2 -2
  41. package/dist/client/assets/settings-panel-Cf3sByHu.js.br +0 -0
  42. package/dist/client/assets/{shown-lightbox-GtYhWR5u.js → shown-lightbox-C7CJbtB5.js} +1 -1
  43. package/dist/client/assets/shown-lightbox-C7CJbtB5.js.br +0 -0
  44. package/dist/client/assets/{team-review-panel-BY5YWeyD.js → team-review-panel-DoJwTt6h.js} +1 -1
  45. package/dist/client/assets/team-review-panel-DoJwTt6h.js.br +0 -0
  46. package/dist/client/assets/{trace-panel-DP0A47qS.js → trace-panel-E1eTqqcN.js} +1 -1
  47. package/dist/client/assets/trace-panel-E1eTqqcN.js.br +0 -0
  48. package/dist/client/assets/{usage-panel-CA9ZuF2-.js → usage-panel-CHcJctyt.js} +1 -1
  49. package/dist/client/assets/usage-panel-CHcJctyt.js.br +0 -0
  50. package/dist/client/assets/{your-day-tip-Cn2MBjg4.js → your-day-tip-CTvvxY5Z.js} +1 -1
  51. package/dist/client/assets/your-day-tip-CTvvxY5Z.js.br +4 -0
  52. package/dist/client/index.html +1 -1
  53. package/dist/client/index.html.br +0 -0
  54. package/dist/server/index.js +1 -1
  55. package/package.json +1 -1
  56. package/dist/client/assets/benchmark-panel-BRTPARGF.js.br +0 -0
  57. package/dist/client/assets/boards-view-t6Kni_OG.js.br +0 -0
  58. package/dist/client/assets/community-panel-xT-w6RPr.js.br +0 -0
  59. package/dist/client/assets/dialogs-DRYpTh--.js.br +0 -0
  60. package/dist/client/assets/doc-editor-ui-BGIAVcg7.js.br +0 -0
  61. package/dist/client/assets/feature-hint-DmrtnjCy.js.br +0 -0
  62. package/dist/client/assets/first-run-checklist-3tiKot6p.js.br +0 -0
  63. package/dist/client/assets/hooks-panel-CKfErnuU.js.br +0 -0
  64. package/dist/client/assets/index-k2H9o6FW.js.br +0 -0
  65. package/dist/client/assets/issues-panel-DwO_6TTO.js.br +0 -0
  66. package/dist/client/assets/my-prs-panel-bKQK1yAe.js.br +0 -0
  67. package/dist/client/assets/nyan-cat-Brf_F8nH.js.br +0 -0
  68. package/dist/client/assets/phone-shell-BZNhRPSl.js.br +0 -0
  69. package/dist/client/assets/plan-face-bWTHQdEe.js.br +0 -0
  70. package/dist/client/assets/pr-queue-columns-WDQqbW0O.js.br +0 -0
  71. package/dist/client/assets/radar-panel-DmdHKxoV.js.br +0 -0
  72. package/dist/client/assets/repo-roots-adder-Dvp9iTxp.js.br +0 -0
  73. package/dist/client/assets/resume-dialog-DlXllNiY.js.br +0 -0
  74. package/dist/client/assets/review-queue-panel-CfW9Y9G3.js.br +0 -0
  75. package/dist/client/assets/settings-panel-Dk1tKjVD.js.br +0 -0
  76. package/dist/client/assets/shown-lightbox-GtYhWR5u.js.br +0 -0
  77. package/dist/client/assets/team-review-panel-BY5YWeyD.js.br +0 -0
  78. package/dist/client/assets/trace-panel-DP0A47qS.js.br +0 -0
  79. package/dist/client/assets/usage-panel-CA9ZuF2-.js.br +0 -0
  80. package/dist/client/assets/your-day-tip-Cn2MBjg4.js.br +0 -0
@@ -1850,68 +1850,59 @@ async function sweepSessionUploads(dir, justWritten) {
1850
1850
  function streamRequestToFile({ req, savedPath, capBytes }) {
1851
1851
  return new Promise((resolve) => {
1852
1852
  const writeStream = fs.createWriteStream(savedPath, { mode: 384 });
1853
+ const writeStreamClosed = new Promise((resolveClosed) => writeStream.once("close", resolveClosed));
1853
1854
  let bytesReceived = 0;
1854
1855
  let settled = false;
1855
- const settle = (outcome) => {
1856
+ const fail = (reason) => {
1856
1857
  if (settled) return;
1857
1858
  settled = true;
1858
- resolve(outcome);
1859
- };
1860
- let discardWanted = false;
1861
- let streamClosed = false;
1862
- const unlinkPartial = () => {
1863
- fs$1.unlink(savedPath).catch(() => {});
1859
+ const outcome = {
1860
+ ok: false,
1861
+ reason,
1862
+ bytesReceived
1863
+ };
1864
+ writeStreamClosed.then(() => fs$1.unlink(savedPath).catch(() => {})).then(() => resolve(outcome));
1864
1865
  };
1865
- const discardPartial = () => {
1866
- discardWanted = true;
1867
- if (streamClosed) unlinkPartial();
1866
+ const stopWritingAndDrain = () => {
1867
+ req.unpipe(writeStream);
1868
+ writeStream.destroy();
1869
+ req.resume();
1868
1870
  };
1869
- writeStream.on("close", () => {
1870
- streamClosed = true;
1871
- if (discardWanted) unlinkPartial();
1872
- });
1873
1871
  writeStream.on("error", () => {
1874
- settle({
1875
- ok: false,
1876
- reason: "write-failed"
1872
+ stopWritingAndDrain();
1873
+ fail("write-failed");
1874
+ });
1875
+ writeStream.on("finish", () => {
1876
+ if (settled) return;
1877
+ settled = true;
1878
+ resolve({
1879
+ ok: true,
1880
+ sizeBytes: bytesReceived
1877
1881
  });
1878
- discardPartial();
1879
1882
  });
1880
1883
  req.on("data", (chunk) => {
1881
1884
  bytesReceived += chunk.length;
1882
- if (!exceedsUploadCap(bytesReceived, capBytes)) return;
1883
- settle({
1884
- ok: false,
1885
- reason: "over-cap"
1886
- });
1887
- req.destroy();
1885
+ if (settled || !exceedsUploadCap(bytesReceived, capBytes)) return;
1886
+ stopWritingAndDrain();
1887
+ fail("over-cap");
1888
+ });
1889
+ req.on("error", () => {
1888
1890
  writeStream.destroy();
1889
- discardPartial();
1891
+ fail("aborted");
1890
1892
  });
1891
- pipeline(req, writeStream, (error) => {
1892
- if (error) {
1893
- settle({
1894
- ok: false,
1895
- reason: "aborted"
1896
- });
1897
- discardPartial();
1898
- return;
1899
- }
1900
- if (settled) {
1901
- discardPartial();
1902
- return;
1903
- }
1904
- settle({
1905
- ok: true,
1906
- sizeBytes: bytesReceived
1907
- });
1893
+ req.on("close", () => {
1894
+ if (req.complete) return;
1895
+ writeStream.destroy();
1896
+ fail("aborted");
1908
1897
  });
1898
+ req.pipe(writeStream);
1909
1899
  });
1910
1900
  }
1901
+ var UPLOAD_OVER_CAP_ERROR = `file is larger than ${MAX_UPLOAD_BYTES / 1048576}mb`;
1911
1902
  var UPLOAD_FAILURE_REPLIES = {
1912
1903
  "over-cap": {
1913
1904
  status: 413,
1914
- error: "file is too large"
1905
+ error: UPLOAD_OVER_CAP_ERROR
1915
1906
  },
1916
1907
  "write-failed": {
1917
1908
  status: 500,
@@ -1922,7 +1913,7 @@ var UPLOAD_FAILURE_REPLIES = {
1922
1913
  error: "upload failed"
1923
1914
  }
1924
1915
  };
1925
- function receiveUpload({ req, res, sess, dir, filename, savedPath }) {
1916
+ function receiveUpload({ req, res, sess, dir, filename, savedPath, logger }) {
1926
1917
  const answer = (status, body) => {
1927
1918
  if (!res.headersSent) res.status(status).json(body);
1928
1919
  };
@@ -1932,11 +1923,13 @@ function receiveUpload({ req, res, sess, dir, filename, savedPath }) {
1932
1923
  capBytes: MAX_UPLOAD_BYTES
1933
1924
  }).then((outcome) => {
1934
1925
  if (!outcome.ok) {
1926
+ logger.warn(`[upload] session ${sess.id} refused: ${outcome.reason} after ${outcome.bytesReceived} bytes`);
1935
1927
  const failure = UPLOAD_FAILURE_REPLIES[outcome.reason];
1936
1928
  answer(failure.status, { error: failure.error });
1937
1929
  return;
1938
1930
  }
1939
1931
  if (!sess.hasLivePty) {
1932
+ logger.warn(`[upload] session ${sess.id} refused: session has no live terminal, after ${outcome.sizeBytes} bytes`);
1940
1933
  answer(409, { error: "session has no live terminal" });
1941
1934
  fs$1.unlink(savedPath).catch(() => {});
1942
1935
  return;
@@ -2367,18 +2360,28 @@ function createBackendHttpApp(dependencies) {
2367
2360
  mountAgentIngressRoutes(app, dependencies);
2368
2361
  const uploadsRoot = configSiblingPath(configStore.configPath, "uploads");
2369
2362
  app.post("/upload/:sessionId", (req, res) => {
2363
+ const declaredBytes = declaredContentLength(req);
2364
+ const refuse = (sessionLabel, status, error) => {
2365
+ logger.warn(`[upload] session ${sessionLabel} refused: ${error}, declared ${declaredBytes ?? "unknown"} bytes`);
2366
+ res.status(status).json({ error });
2367
+ };
2370
2368
  const sess = getSession(req.params.sessionId);
2371
2369
  if (!sess || !isSafePathSegment(sess.id)) {
2372
- res.status(404).json({ error: "unknown session" });
2370
+ refuse(JSON.stringify(req.params.sessionId), 404, "unknown session");
2373
2371
  return;
2374
2372
  }
2375
2373
  const typeVerdict = decideUploadType(req.headers["content-type"], req.headers["x-glimmervoid-upload-name"]);
2376
2374
  if (!typeVerdict.ok) {
2377
- res.status(typeVerdict.status).json({ error: typeVerdict.error });
2375
+ refuse(sess.id, typeVerdict.status, typeVerdict.error);
2378
2376
  return;
2379
2377
  }
2380
2378
  if (!sess.hasLivePty) {
2381
- res.status(409).json({ error: "session has no live terminal" });
2379
+ refuse(sess.id, 409, "session has no live terminal");
2380
+ return;
2381
+ }
2382
+ if (declaredBytes !== null && exceedsUploadCap(declaredBytes)) {
2383
+ refuse(sess.id, 413, UPLOAD_OVER_CAP_ERROR);
2384
+ req.resume();
2382
2385
  return;
2383
2386
  }
2384
2387
  const dir = path.join(uploadsRoot, sess.id);
@@ -2397,7 +2400,10 @@ function createBackendHttpApp(dependencies) {
2397
2400
  recursive: true,
2398
2401
  mode: 448
2399
2402
  }).then(() => {
2400
- if (abortedBeforeReceive || req.destroyed) return;
2403
+ if (abortedBeforeReceive || req.destroyed) {
2404
+ logger.warn(`[upload] session ${sess.id} refused: aborted before any bytes`);
2405
+ return;
2406
+ }
2401
2407
  req.off("error", markAbortedBeforeReceive);
2402
2408
  receiveUpload({
2403
2409
  req,
@@ -2405,9 +2411,11 @@ function createBackendHttpApp(dependencies) {
2405
2411
  sess,
2406
2412
  dir,
2407
2413
  filename,
2408
- savedPath
2414
+ savedPath,
2415
+ logger
2409
2416
  });
2410
2417
  }).catch(() => {
2418
+ logger.warn(`[upload] session ${sess.id} refused: could not create ${dir}`);
2411
2419
  if (!res.headersSent) res.status(500).json({ error: "could not store the upload" });
2412
2420
  });
2413
2421
  });
@@ -1 +1 @@
1
- import"./updates-view-core-4oGJ3ZXL.js";import{n as e,r as t,s as n}from"./dom-helpers-DBbFg1c_.js";import{$ as r,Q as i,et as a}from"./index-k2H9o6FW.js";var o={mine:`Mine`,run:`Run`,cancel:`Cancel`},s=null;function c(e){return e===null?`n/a`:`${Math.round(e*100)}%`}function l(e){if(e===null)return`n/a`;let t=Math.round(e*100);return t>0?`+${t}`:String(t)}function u(e,t,i){let a=n(`button`,`bench-action-button`,o[t]);return a.type=`button`,a.disabled=i,a.addEventListener(`click`,()=>r(e.id,t)),a}function d(e,t){let n=e.inFlight;if(!n||n.suiteId!==t.id)return``;let r=n.caseId?`case ${n.caseId}, `:``;return`Cell ${n.cellIndex+1} of ${n.cellCount}: ${r}arm ${n.armId}, trial ${n.trial}, ${n.phase}.`}function f(e){let t=n(`td`,`bench-score`,c(e?.recall??null));return e&&e.invalid>0&&(t.title=`${e.invalid} invalid or failed cell(s)`),e&&e.degraded>0&&(t.dataset.degraded=`true`),t}function p(e){let t=e.armIds.filter(t=>t!==e.baselineArm),r=n(`table`,`bench-table`),i=n(`tr`);i.append(n(`th`,null,`Case`),...e.armIds.map(t=>n(`th`,null,t===e.baselineArm?`${t} (baseline)`:t))),i.append(...t.map(e=>n(`th`,null,`${e} vs baseline`))),r.append(i);for(let i of e.rows){let a=n(`tr`);a.append(n(`td`,`bench-case`,i.caseId),...e.armIds.map(e=>f(i.arms[e]))),a.append(...t.map(e=>n(`td`,`bench-delta`,l(i.deltaVsBaseline[e]??null)))),r.append(a)}let a=[...new Set(e.armIds.flatMap(t=>Object.keys(e.totals[t]?.recallByTag??{})))].sort(),o=n(`tr`,`bench-total`);o.append(n(`td`,`bench-case`,`Paired recall`),...e.armIds.map(t=>f(e.totals[t]))),r.append(o);for(let t of a){let i=n(`tr`,`bench-total`);i.append(n(`td`,`bench-case`,`Recall, ${t}`),...e.armIds.map(r=>n(`td`,`bench-score`,c(e.totals[r]?.recallByTag[t]??null)))),r.append(i)}return r}function m(e,r){let{isServerConnected:a,pendingActionBySuite:o,outcomeBySuite:s}=i(),c=n(`div`,`bench-suite`),l=e.inFlight?.suiteId===r.id,f=!!e.inFlight&&!l,m=o.has(r.id)||!a,h=n(`div`,`bench-summary`);h.append(n(`span`,`bench-suite-title`,r.title),t(`bench`,r.caseCount===1?`case`:`cases`,String(r.caseCount)),t(`bench`,r.candidateCount===1?`candidate`:`candidates`,String(r.candidateCount)),t(`bench`,`arms`,String(r.armIds.length))),c.append(h);let g=n(`div`,`bench-controls`),_=e.configured===!0&&r.error===null;g.append(u(r,`mine`,!_||m||l),u(r,`run`,!_||m||l||f||r.caseCount===0),u(r,`cancel`,m||!l));let v=n(`span`,`bench-status`,(a?``:`Not connected to the server. Reconnecting.`)||d(e,r)||s.get(r.id)||``);if(v.setAttribute(`role`,`status`),g.append(v),c.append(g),r.error)return c.append(n(`p`,`bench-error`,r.error)),c;let y=r.latestReport;return y?(c.append(n(`p`,`bench-run-line`,`Latest run ${y.runId}: ${y.status}. Only cases every arm scored count toward paired recall.`)),y.rows.length>0&&c.append(p(y)),c):(c.append(n(`p`,`bench-empty`,r.caseCount===0?`Move approved candidates into the cases folder, then choose Run.`:`No run yet.`)),c)}function h(){if(!s)return;s.textContent=``;let{status:t}=i(),r=e(`bench`,`Benchmarks`,`Suites from the benchmarks folder of the Glimmervoid home, one run at a time.`);if(s.append(r),!t)s.append(n(`p`,`bench-empty`,`Waiting for the server.`));else if(!t.configured)s.append(n(`p`,`bench-empty`,t.reason||`Benchmarks are off.`));else if(t.suites.length===0)s.append(n(`p`,`bench-empty`,`No suites yet. Create a folder holding suite.json under benchmarks in the Glimmervoid home.`));else for(let e of t.suites)s.append(m(t,e))}function g(e){s||(s=n(`div`,`bench-content`),e.append(s),a(h),h())}var _={mount:g};export{_ as view};
1
+ import"./updates-view-core-4oGJ3ZXL.js";import{n as e,r as t,s as n}from"./dom-helpers-DBbFg1c_.js";import{$ as r,Q as i,et as a}from"./index-BlbUd3zj.js";var o={mine:`Mine`,run:`Run`,cancel:`Cancel`},s=null;function c(e){return e===null?`n/a`:`${Math.round(e*100)}%`}function l(e){if(e===null)return`n/a`;let t=Math.round(e*100);return t>0?`+${t}`:String(t)}function u(e,t,i){let a=n(`button`,`bench-action-button`,o[t]);return a.type=`button`,a.disabled=i,a.addEventListener(`click`,()=>r(e.id,t)),a}function d(e,t){let n=e.inFlight;if(!n||n.suiteId!==t.id)return``;let r=n.caseId?`case ${n.caseId}, `:``;return`Cell ${n.cellIndex+1} of ${n.cellCount}: ${r}arm ${n.armId}, trial ${n.trial}, ${n.phase}.`}function f(e){let t=n(`td`,`bench-score`,c(e?.recall??null));return e&&e.invalid>0&&(t.title=`${e.invalid} invalid or failed cell(s)`),e&&e.degraded>0&&(t.dataset.degraded=`true`),t}function p(e){let t=e.armIds.filter(t=>t!==e.baselineArm),r=n(`table`,`bench-table`),i=n(`tr`);i.append(n(`th`,null,`Case`),...e.armIds.map(t=>n(`th`,null,t===e.baselineArm?`${t} (baseline)`:t))),i.append(...t.map(e=>n(`th`,null,`${e} vs baseline`))),r.append(i);for(let i of e.rows){let a=n(`tr`);a.append(n(`td`,`bench-case`,i.caseId),...e.armIds.map(e=>f(i.arms[e]))),a.append(...t.map(e=>n(`td`,`bench-delta`,l(i.deltaVsBaseline[e]??null)))),r.append(a)}let a=[...new Set(e.armIds.flatMap(t=>Object.keys(e.totals[t]?.recallByTag??{})))].sort(),o=n(`tr`,`bench-total`);o.append(n(`td`,`bench-case`,`Paired recall`),...e.armIds.map(t=>f(e.totals[t]))),r.append(o);for(let t of a){let i=n(`tr`,`bench-total`);i.append(n(`td`,`bench-case`,`Recall, ${t}`),...e.armIds.map(r=>n(`td`,`bench-score`,c(e.totals[r]?.recallByTag[t]??null)))),r.append(i)}return r}function m(e,r){let{isServerConnected:a,pendingActionBySuite:o,outcomeBySuite:s}=i(),c=n(`div`,`bench-suite`),l=e.inFlight?.suiteId===r.id,f=!!e.inFlight&&!l,m=o.has(r.id)||!a,h=n(`div`,`bench-summary`);h.append(n(`span`,`bench-suite-title`,r.title),t(`bench`,r.caseCount===1?`case`:`cases`,String(r.caseCount)),t(`bench`,r.candidateCount===1?`candidate`:`candidates`,String(r.candidateCount)),t(`bench`,`arms`,String(r.armIds.length))),c.append(h);let g=n(`div`,`bench-controls`),_=e.configured===!0&&r.error===null;g.append(u(r,`mine`,!_||m||l),u(r,`run`,!_||m||l||f||r.caseCount===0),u(r,`cancel`,m||!l));let v=n(`span`,`bench-status`,(a?``:`Not connected to the server. Reconnecting.`)||d(e,r)||s.get(r.id)||``);if(v.setAttribute(`role`,`status`),g.append(v),c.append(g),r.error)return c.append(n(`p`,`bench-error`,r.error)),c;let y=r.latestReport;return y?(c.append(n(`p`,`bench-run-line`,`Latest run ${y.runId}: ${y.status}. Only cases every arm scored count toward paired recall.`)),y.rows.length>0&&c.append(p(y)),c):(c.append(n(`p`,`bench-empty`,r.caseCount===0?`Move approved candidates into the cases folder, then choose Run.`:`No run yet.`)),c)}function h(){if(!s)return;s.textContent=``;let{status:t}=i(),r=e(`bench`,`Benchmarks`,`Suites from the benchmarks folder of the Glimmervoid home, one run at a time.`);if(s.append(r),!t)s.append(n(`p`,`bench-empty`,`Waiting for the server.`));else if(!t.configured)s.append(n(`p`,`bench-empty`,t.reason||`Benchmarks are off.`));else if(t.suites.length===0)s.append(n(`p`,`bench-empty`,`No suites yet. Create a folder holding suite.json under benchmarks in the Glimmervoid home.`));else for(let e of t.suites)s.append(m(t,e))}function g(e){s||(s=n(`div`,`bench-content`),e.append(s),a(h),h())}var _={mount:g};export{_ as view};
@@ -1 +1 @@
1
- import{bt as e}from"./updates-view-core-4oGJ3ZXL.js";import{s as t}from"./dom-helpers-DBbFg1c_.js";import{a as n,r}from"./card-registry-D5EJa_tx.js";import{i}from"./action-status-Cmp0b1QX.js";import{a,n as o}from"./modal-USMHOKBI.js";import{$r as s,Sn as c,ai as l,bi as u,ci as d,ei as f,ii as p,li as m,ni as h,oi as g,ri as _,si as v,ti as y,xi as ee,yi as te}from"./index-k2H9o6FW.js";var ne=4,re=200,ie=2e4,ae=1.1,oe=[`wire`,`note`,`frame`,`box`,`unit`];function b(e){let t=Math.random().toString(36).slice(2,8);return`${e}-${Date.now().toString(36)}${t}`}function x(){return document.documentElement.dataset.layout===`phone`}function se(e){return e instanceof Element?e.closest(`[data-linked-board-id]`)?.dataset.linkedBoardId??null:null}function ce(e){let{svg:n,canvas:r,renderer:i}=e,a=new Map,o=new Set,s={x:0,y:0,width:1e3,height:600},c=null,l=null;function u(){n.setAttribute(`viewBox`,`${s.x} ${s.y} ${s.width} ${s.height}`)}function d(){let e=i.layout();if(!e)return;let{bounds:t}=e,r=n.clientWidth,a=n.clientHeight;if(r===0||a===0){s={...t},u();return}let o=Math.max(1,t.width/r,t.height/a),c=r*o;s={x:t.x-(c-t.width)/2,y:t.y,width:c,height:a*o},u()}function f(e,t){let r=n.getScreenCTM();if(!r)return{x:e,y:t};let i=new DOMPoint(e,t).matrixTransform(r.inverse());return{x:i.x,y:i.y}}function p(){let e=n.clientWidth||1,t=n.clientHeight||1;return Math.max(s.width/e,s.height/t)}function m(e,t){let n=Math.min(ie,Math.max(re,s.width*t)),r=n/s.width;s={x:e.x-(e.x-s.x)*r,y:e.y-(e.y-s.y)*r,width:n,height:s.height*r},u()}function h(e,t){let n=p();s={...s,x:s.x-e*n,y:s.y-t*n},u()}function g(t){o=t,i.setSelection(o),e.onSelectionChange(o)}function _(e,t){if(!t){g(o.has(e)&&o.size===1?new Set:new Set([e]));return}let n=new Set(o);n.delete(e)||n.add(e),g(n)}function v(e){let t=new Set([...o].filter(t=>e?.elements[t]));t.size!==o.size&&g(t)}function y(e){let t=i.layout()?.elements.find(t=>t.id===e);return t?.kind===`box`?t:null}function ee(){let[e,t]=[...a.values()];return!e||!t?0:Math.hypot(e.x-t.x,e.y-t.y)}function te(){c={kind:`pinch`,distance:ee(),viewWidth:s.width}}function b(t){if(t.button!==0||l)return;let r=se(t.target);if(r){e.onOpenLinkedBoard(r);return}if(a.set(t.pointerId,{x:t.clientX,y:t.clientY}),n.setPointerCapture(t.pointerId),a.size===2){te();return}let o=i.elementFromTarget(t.target),s=o?.kind===`box`&&!x()?y(o.id):null;if(o&&s){c={kind:`drag`,pointerId:t.pointerId,boxId:o.id,origin:f(t.clientX,t.clientY),start:s,hasMoved:!1,isAdditive:t.shiftKey};return}if(o&&!x()){_(o.id,t.shiftKey);return}let u=o?.kind===`box`?o.id:null;c={kind:`pan`,pointerId:t.pointerId,lastClient:{x:t.clientX,y:t.clientY},hasMoved:!1,tappedBoxId:u}}function ce(e,t){let n=f(t.clientX,t.clientY),r=n.x-e.origin.x,a=n.y-e.origin.y;!e.hasMoved&&Math.hypot(r,a)<ne*p()||(e.hasMoved=!0,i.nodeOf(e.boxId)?.setAttribute(`transform`,`translate(${r} ${a})`))}function S(e,t){let n=t.clientX-e.lastClient.x,r=t.clientY-e.lastClient.y;!e.hasMoved&&Math.hypot(n,r)<ne||(e.hasMoved=!0,e.lastClient={x:t.clientX,y:t.clientY},h(n,r))}function le(e){let t=ee();if(t<=0||e.distance<=0)return;let n=[...a.values()];m(f(n.reduce((e,t)=>e+t.x,0)/n.length,n.reduce((e,t)=>e+t.y,0)/n.length),e.viewWidth*(e.distance/t)/s.width)}function C(e){a.has(e.pointerId)&&(a.set(e.pointerId,{x:e.clientX,y:e.clientY}),c?.kind===`pinch`?le(c):c?.kind===`drag`&&c.pointerId===e.pointerId?ce(c,e):c?.kind===`pan`&&c.pointerId===e.pointerId&&S(c,e))}async function w(t,n){if(!t.hasMoved){_(t.boxId,t.isAdditive);return}let r=f(n.clientX,n.clientY),a=i.layout()?.pinnedOffsetY??0,o={x:Math.round(t.start.x+r.x-t.origin.x),y:Math.round(t.start.y+r.y-t.origin.y-a)};await e.sendOps([{op:`set`,id:t.boxId,fields:{at:o}}])||i.nodeOf(t.boxId)?.removeAttribute(`transform`)}function ue(t){if(!a.delete(t.pointerId))return;let n=c;n?.kind===`pinch`?c=null:(c=null,n?.kind===`drag`&&n.pointerId===t.pointerId?w(n,t):n?.kind!==`pan`||n.hasMoved||(n.tappedBoxId&&x()?e.onPhoneTapBox(n.tappedBoxId):n.tappedBoxId||g(new Set)))}function de(e){a.delete(e.pointerId),c?.kind===`drag`&&i.nodeOf(c.boxId)?.removeAttribute(`transform`),c=null}function fe(e){e.preventDefault(),e.ctrlKey||e.metaKey?m(f(e.clientX,e.clientY),e.deltaY>0?ae:1/ae):h(-e.deltaX,-e.deltaY)}function T(){let e=l;l=null,e?.remove()}function pe(a){let o=e.currentBoard()?.elements[a],s=i.nodeOf(a);if(o?.kind!==`box`||!s)return;T();let c=r.getBoundingClientRect(),u=s.getBoundingClientRect(),d=t(`input`,`wb-title-input`);d.type=`text`,d.value=o.title,d.maxLength=80,d.setAttribute(`aria-label`,`Box title`),d.style.left=`${u.left-c.left}px`,d.style.top=`${u.top-c.top}px`,d.style.width=`${Math.max(160,u.width)}px`,l=d,r.append(d),d.addEventListener(`keydown`,t=>{if(t.key===`Escape`){t.preventDefault(),T(),n.focus();return}if(t.key!==`Enter`)return;t.preventDefault();let r=d.value.trim();T(),n.focus(),r&&r!==o.title&&e.sendOps([{op:`set`,id:a,fields:{title:r}}])}),d.addEventListener(`blur`,T),d.focus(),d.select()}function E(e){if(x())return;let t=i.elementFromTarget(document.elementFromPoint(e.clientX,e.clientY));t?.kind===`box`&&pe(t.id)}function D(){let t=e.currentBoard();if(!t||o.size===0)return;let n=[...o].flatMap(e=>t.elements[e]??[]),r=oe.flatMap(e=>n.filter(t=>t.kind===e)).map(e=>({op:`remove`,id:e.id}));g(new Set),e.sendOps(r)}function me(e){e.target===n&&(e.key===`Delete`||e.key===`Backspace`?(e.preventDefault(),D()):e.key===`Escape`&&g(new Set))}return n.tabIndex=0,n.addEventListener(`pointerdown`,b),n.addEventListener(`pointermove`,C),n.addEventListener(`pointerup`,ue),n.addEventListener(`pointercancel`,de),n.addEventListener(`wheel`,fe,{passive:!1}),n.addEventListener(`dblclick`,E),n.addEventListener(`keydown`,me),{fit:d,selectedIds:()=>o,clearSelection:()=>g(new Set),pruneSelection:v,closeTitleInput:T}}var S=40,le=44,C=220,w=90,ue=30,de=20,fe=18,T=20,pe=26,E=18,D=26,me=170,he=21,ge=17,_e=10,ve=22,ye=24,be=16,xe=16,Se=26,Ce=24,we=8,Te=10,Ee=14,De=4,Oe=14,ke=8,O=6,Ae=4,je=6,Me=12,Ne=10,Pe=6.6,k=5,A=10,Fe=2,Ie=100,Le=120,Re=4,ze=40,Be=[.5,.35,.65,.2,.8],Ve=Object.freeze({blue:`#60a5fa`,green:`#4ade80`,orange:`#fb923c`,pink:`#f472b6`,cyan:`#22d3ee`,yellow:`#facc15`});function j(e,t){let n=e.split(/\s+/).filter(Boolean),r=[],i=``;for(let e of n){let n=e.match(RegExp(`.{1,${t}}`,`g`))??[e];for(let e of n){let n=i?`${i} ${e}`:e;n.length<=t?i=n:(r.push(i),i=e)}}return i&&r.push(i),r.length>0?r:[``]}function He(e,t){let n=e.lanes.find(e=>e.id===t.lane);return n?{label:n.label||n.id,hex:Ve[n.color]}:null}function Ue(e,t){let n=j(t.title,T),r=t.lines.flatMap(e=>j(e.text,pe-(e.muted?2:0)).map(t=>({text:t,muted:e.muted}))),i=He(e,t);return{titleLines:n,bodyLines:r,lane:i,height:24+n.length*de+r.length*fe+(i?26:0)}}function M(e,t){return Object.values(e.elements).filter(e=>e.kind===t)}function We(e){let t=j(e.text,he);return{lines:t,height:24+(t.length+1)*ge}}function Ge(e){let t=new Map;for(let n of M(e,`note`)){let e=t.get(n.on),r=We(n).height;t.set(n.on,e===void 0?r:e+_e+r)}return t}function Ke(e){return e.columns.map(e=>e.title?j(e.title,ye):[])}function qe(e){return(Math.max(1,...e.map(e=>e.length))-1)*be}function N(e,t){let n=new Map;for(let r of e){let e=t(r),i=n.get(e);i?i.push(r):n.set(e,[r])}return n}function Je(e,t){let n=M(e,`box`).filter(e=>!e.at),r=new Set(n.filter(e=>t.has(e.id)).map(e=>e.column)),i=new Set(M(e,`frame`).flatMap(e=>e.contains)),a=new Set(n.filter(e=>i.has(e.id)).map(e=>e.column)),o=e=>Te+(e!==void 0&&a.has(e)?E:0);return e.columns.map((t,n)=>{let i=r.has(t.id);return{left:i?156:o(t.id),right:o(e.columns[n+1]?.id),minimumWidth:i?Math.max(w,186):w}})}function Ye(e,t,n){return e.map((e,r)=>{let i=t[r]??0,a=n[r]??0,o=i>0?e.left+e.right+(i+1)*Ee:0,s=a>0?e.left+e.right+a+20:0;return Math.max(e.minimumWidth,o,s)})}function Xe(e,t){let n=[],r=S;for(let[i]of e.columns.entries())n.push(r),r+=C+(t[i]??w);return n}function Ze(e,t,n){return e.map((e,r)=>{let i=n[r]??{left:Te,right:Te,minimumWidth:w},a=e+C+(t[r]??w);return{left:e+C+i.left,right:a-i.right}})}function Qe(e,t,n,r){if(!t.at)return Math.max(0,e.columns.findIndex(e=>e.id===t.column));let i=n.x+n.width/2,a=r.findLastIndex(e=>e<=i);return Math.max(0,a)}function $e(e){let t=new Map;for(let n of M(e,`frame`))for(let e of n.contains)t.has(e)||t.set(e,n.id);return t}function et(e,t){return e===t?0:(e?E:0)+(t?44:0)}function tt(e,t,n,r){let i=new Map,a=new Map,o=new Map,s=$e(e),c=M(e,`box`).map((e,t)=>({box:e,index:t})).sort((e,t)=>e.box.order-t.box.order||e.index-t.index);for(let{box:l}of c){let c=Math.max(0,e.columns.findIndex(e=>e.id===l.column)),u=Ue(e,l),d=s.get(l.id)??null,f=(a.get(l.column)??n)+et(o.get(l.column)??null,d),p=l.at??{x:t[c]??S,y:f};if(!l.at){let e=(r.get(l.id)??0)-we;a.set(l.column,f+Math.max(u.height,e)+ue),o.set(l.column,d)}i.set(l.id,{kind:`box`,id:l.id,x:p.x,y:p.y,width:C,height:u.height,titleLines:u.titleLines,bodyLines:u.bodyLines,lane:u.lane,isGhost:l.ghost})}return i}function nt(e){if(e.length===0)return null;let t=Math.min(...e.map(e=>e.x)),n=Math.min(...e.map(e=>e.y)),r=Math.max(...e.map(e=>e.x+e.width)),i=Math.max(...e.map(e=>e.y+e.height));return{x:t,y:n,width:r-t,height:i-n}}function rt(e,t){return M(e,`frame`).flatMap(e=>{let n=nt(e.contains.flatMap(e=>t.get(e)??[]));return n?[{kind:`frame`,id:e.id,title:e.title,x:n.x-E,y:n.y-E-D,width:n.width+36,height:n.height+36+D}]:[]})}function it(e){return e===`left`||e===`right`}function P(e){return{x:e.x+e.width/2,y:e.y+e.height/2}}function at(e,t,n,r){let i=e.y<t.y?e:t,a=i===e?t:e;return[...r.boxesById.values()].some(o=>o.id!==e.id&&o.id!==t.id&&r.columnIndexByBoxId.get(o.id)===n&&o.y<a.y&&o.y+o.height>i.y+i.height)}function ot(e,t,n){let r=n.columnIndexByBoxId.get(e.id)??0,i=n.columnIndexByBoxId.get(t.id)??0;if(r===i){if(e.id!==t.id&&!at(e,t,r,n)){let n=t.y>e.y;return{shape:`straight`,exitSide:n?`bottom`:`top`,entrySide:n?`top`:`bottom`,sourceGap:-1,targetGap:-1}}return{shape:`channel`,exitSide:`right`,entrySide:`right`,sourceGap:r,targetGap:r}}return i>r?{shape:i===r+1?`channel`:`long`,exitSide:`right`,entrySide:`left`,sourceGap:r,targetGap:i-1}:{shape:i===r-1?`channel`:`long`,exitSide:`left`,entrySide:`right`,sourceGap:r-1,targetGap:i}}function st(e){let t=e.wires.flatMap(t=>{let n=e.boxesById.get(t.from),r=e.boxesById.get(t.to);if(!n||!r)return[];let i=t.tone===`lane`?n.lane?.hex??null:null,a=P(n);return[{wire:t,from:n,to:r,strokeHex:i,styleKey:`${t.dashed}|${t.tone}|${i}`,...ot(n,r,e),busKey:null,start:a,end:P(r),crossingY:a.y}]}),n=new Map,r=e=>`${e.to.id}|${e.entrySide}|${e.styleKey}`;for(let e of t)e.shape!==`straight`&&n.set(r(e),(n.get(r(e))??0)+1);for(let e of t)e.shape!==`straight`&&(n.get(r(e))??0)>1&&(e.busKey=r(e));return t}function ct(e,t,n){let r=Array.from({length:n},(e,t)=>t);if(it(t)){let i=t===`left`?e.x:e.x+e.width,a=Math.min(Oe,(e.height-16)/Math.max(n-1,1)),o=e.y+Math.min(e.height/2,40)-(n-1)*a/2,s=Math.max(e.y+ke,Math.min(o,e.y+e.height-ke-(n-1)*a));return r.map(e=>({x:i,y:Math.round(s+e*a)}))}let i=t===`top`?e.y:e.y+e.height,a=e.x+e.width/2-(n-1)*Oe/2;return r.map(e=>({x:Math.round(a+e*Oe),y:i}))}function lt(e){return N(e.flatMap(e=>[{box:e.from,side:e.exitSide,groupKey:`exit|${e.styleKey}`,wireId:e.wire.id,farPoint:P(e.to),assign:t=>{e.start=t}},{box:e.to,side:e.entrySide,groupKey:e.busKey?`bus|${e.busKey}`:`entry|${e.wire.id}`,wireId:e.wire.id,farPoint:P(e.from),assign:t=>{e.end=t}}]),e=>`${e.box.id}|${e.side}`)}function ut(e){return new Map([...e.entries()].map(([e,t])=>[e,[...N(t,e=>e.groupKey).entries()].map(([e,t])=>({groupKey:e,firstWireId:t.map(e=>e.wireId).sort()[0]??e,farCoordinate:t.reduce((e,t)=>e+(it(t.side)?t.farPoint.y:t.farPoint.x),0)/t.length})).sort((e,t)=>e.farCoordinate-t.farCoordinate||e.firstWireId.localeCompare(t.firstWireId)||e.groupKey.localeCompare(t.groupKey)).map(e=>e.groupKey)]))}function dt(e,t){for(let[n,r]of e){let e=r[0],i=t.get(n)??[];if(!e)continue;let a=ct(e.box,e.side,i.length);for(let e of r){let t=a[i.indexOf(e.groupKey)];t&&e.assign(t)}}}function ft(e,t){let n=t[e.sourceGap]??{left:e.start.x,right:e.start.x},r=t[e.targetGap]??{left:e.end.x,right:e.end.x};return{left:Math.min(n.left,r.left),right:Math.max(n.right,r.right)}}function pt(e,t,n){return[...[...n.boxesById.values()].filter(t=>t.id!==e.from.id&&t.id!==e.to.id),...n.obstacles].filter(e=>e.x<t.right&&e.x+e.width>t.left)}function mt(e,t){return!t.some(t=>e>t.y-O&&e<t.y+t.height+O)}function ht(e){let t=e.map(e=>({top:e.y-O,bottom:e.y+e.height+O})).sort((e,t)=>e.top-t.top),n=[];for(let e of t){let t=n.at(-1);t&&e.top<=t.bottom?t.bottom=Math.max(t.bottom,e.bottom):n.push({...e})}return n.slice(1).flatMap((e,t)=>{let r=n[t];return!r||e.top-r.bottom<Ae?[]:[{top:r.bottom,bottom:e.top}]})}function gt(e,t){return e.left<t.right&&t.left<e.right}function _t(e,t){let n=[];return e.forEach((r,i)=>{let a=e.slice(0,i).flatMap((e,i)=>t(r,e)?[n[i]??0]:[]);n.push(a.length>0?Math.max(...a)+1:0)}),n}function vt(e,t){let n=[],r=[];for(let i of e){if(i.shape!==`long`)continue;let e=ft(i,t.gaps),a=pt(i,e,t),o=[i.start.y,i.end.y].find(e=>mt(e,a));if(o!==void 0){i.crossingY=o;continue}let s=(i.start.y+i.end.y)/2,c=ht(a).sort((e,t)=>Math.abs((e.top+e.bottom)/2-s)-Math.abs((t.top+t.bottom)/2-s))[0];c?n.push({plan:i,interval:c,span:e}):r.push({plan:i,span:e})}let i=N(n,e=>`${Math.round(e.interval.top)}|${Math.round(e.interval.bottom)}`);for(let e of i.values()){let t=[...e].sort((e,t)=>e.plan.start.y-t.plan.start.y||e.plan.wire.id.localeCompare(t.plan.wire.id)),n=_t(t,(e,t)=>gt(e.span,t.span)),i=t[0]?.interval??{top:0,bottom:0},a=i.bottom-i.top,o=Math.max(1,Math.floor(a/je)-1),s=Math.min(o,Math.max(...n)+1);t.forEach((e,t)=>{let c=n[t]??0;c>=o?r.push({plan:e.plan,span:e.span}):e.plan.crossingY=Math.round(i.top+a*(c+1)/(s+1))})}let a=[...r].sort((e,t)=>t.span.right-t.span.left-(e.span.right-e.span.left)||e.plan.wire.id.localeCompare(t.plan.wire.id)),o=_t(a,(e,t)=>gt(e.span,t.span)).map(e=>a.length-1-e);return a.forEach(({plan:e},n)=>{e.crossingY=t.topBandBottom-(o[n]??0)*Me}),r.length>0?Math.max(...o)+1:0}function yt(e,t){return t<=e?`left`:`right`}function bt(e,t){return{key:e,gap:t,top:1/0,bottom:-1/0,leftYs:[],rightYs:[],track:-1,x:0}}function F(e,t,n){(t===`left`?e.leftYs:e.rightYs).push(n),e.top=Math.min(e.top,n),e.bottom=Math.max(e.bottom,n)}function I(e){return e.busKey?`bus|${e.busKey}`:`wire|${e.wire.id}|target`}function xt(e,t){let n=new Map,r=(e,t)=>{let r=n.get(e);if(r)return r;let i=bt(e,t);return n.set(e,i),i},i=new Set;for(let n of e){if(n.shape===`straight`)continue;let e=t.columnIndexByBoxId.get(n.from.id)??0,a=t.columnIndexByBoxId.get(n.to.id)??0,o=n.exitSide===`right`&&n.entrySide===`left`,s=r(I(n),n.targetGap);if(n.shape===`channel`&&F(s,yt(n.targetGap,e),n.start.y),n.shape===`long`){let t=r(`wire|${n.wire.id}|source`,n.sourceGap);F(t,yt(n.sourceGap,e),n.start.y),F(t,o?`right`:`left`,n.crossingY),F(s,o?`left`:`right`,n.crossingY)}i.has(s.key)||(i.add(s.key),F(s,yt(n.targetGap,a),n.end.y))}return n}function St(e,t){return e.filter(e=>e>t.top&&e<t.bottom).length}function Ct(e,t){return St(t.leftYs,e)+St(e.rightYs,t)}function wt(e,t){let n=t.map(()=>0),r=N([...e.values()].filter(e=>e.bottom>e.top),e=>e.gap);for(let[e,i]of r){let r=[...i].sort((e,t)=>Ct(e,t)-Ct(t,e)||e.top-t.top||e.key.localeCompare(t.key)),a=_t(r,(e,t)=>e.top<t.bottom+De&&t.top<e.bottom+De),o=Math.max(...a)+1;n[e]=o;let s=t[e]??{left:0,right:0};r.forEach((e,t)=>{e.track=a[t]??0,e.x=Math.round(s.left+(s.right-s.left)*(e.track+1)/(o+1))})}for(let n of e.values()){if(n.track>=0)continue;let e=t[n.gap]??{left:0,right:0};n.x=Math.round((e.left+e.right)/2)}return n}function Tt(e){let t=e.filter((t,n)=>{let r=e[n-1];return!r||r.x!==t.x||r.y!==t.y});return t.filter((e,n)=>{let r=t[n-1],i=t[n+1];return!r||!i||!(r.x===e.x&&e.x===i.x||r.y===e.y&&e.y===i.y)})}function Et(e){return e.slice(1).flatMap((t,n)=>{let r=e[n];return r?[{from:r,to:t}]:[]})}function Dt(e){if(e.start.x===e.end.x)return[e.start,e.end];let t=Math.round((e.start.y+e.end.y)/2);return[e.start,{x:e.start.x,y:t},{x:e.end.x,y:t},e.end]}function Ot(e,t){if(e.shape===`straight`)return Dt(e);let n=t.get(I(e))?.x??e.end.x,r=e.shape===`long`?e.crossingY:e.start.y,i=t.get(`wire|${e.wire.id}|source`)?.x??n,a=e.shape===`long`?[e.start,{x:i,y:e.start.y},{x:i,y:r},{x:n,y:r}]:[e.start,{x:n,y:r}];return e.busKey?a:[...a,{x:n,y:e.end.y},e.end]}function kt(e){return e.map((e,t)=>`${t===0?`M`:`L`} ${e.x} ${e.y}`).join(` `)}function At(e,t){let n=new Map;for(let t of[...e].sort((e,t)=>e.wire.id.localeCompare(t.wire.id)))t.busKey&&!n.has(t.busKey)&&n.set(t.busKey,t.wire.id);return e.map(e=>{let r=Tt(Ot(e,t)),i=e.busKey?t.get(I(e)):void 0,a=e.busKey!==null&&n.get(e.busKey)===e.wire.id,o=i&&a?[{from:{x:i.x,y:i.top},to:{x:i.x,y:i.bottom}},{from:{x:i.x,y:e.end.y},to:e.end}].filter(e=>e.from.x!==e.to.x||e.from.y!==e.to.y):[];return{plan:e,points:r,trunk:o,segments:[...Et(r),...o]}})}function L(e){return e.from.y===e.to.y}function jt(e,t){let n=t.x+t.width,r=t.y+t.height;if(L(e)){let i=e.from.y;return t.y<i&&i<r&&Math.min(e.from.x,e.to.x)<n&&Math.max(e.from.x,e.to.x)>t.x}let i=e.from.x;return t.x<i&&i<n&&Math.min(e.from.y,e.to.y)<r&&Math.max(e.from.y,e.to.y)>t.y}function Mt(e,t){return e.x<t.x+t.width&&t.x<e.x+e.width&&e.y<t.y+t.height&&t.y<e.y+e.height}function Nt(e){return Math.ceil(e.length*Pe)}function Pt(e,t){return{x:e.x-t/2,y:e.y-A,width:t,height:13}}function Ft(e){return Math.abs(e.from.x-e.to.x)+Math.abs(e.from.y-e.to.y)}function It(e,t){let n=[...e].sort((e,t)=>Ft(t)-Ft(e));return[...e.slice(0,1),...n].flatMap(e=>[...Be.flatMap(n=>{let r=e.from.x+(e.to.x-e.from.x)*n,i=e.from.y+(e.to.y-e.from.y)*n;return L(e)?[{x:r,y:i-k},{x:r,y:i+k+A}]:[{x:r+k+t/2,y:i+A/2},{x:r-k-t/2,y:i+A/2}]}),...Lt(e,t)])}function Lt(e,t){if(!L(e))return[];let n=e.from.y;return[Math.min(e.from.x,e.to.x)+k+t/2,Math.max(e.from.x,e.to.x)-k-t/2].flatMap(e=>[{x:e,y:n-k},{x:e,y:n+k+A}])}function Rt(e,t){return{x:e.x-t,y:e.y-t,width:e.width+t*2,height:e.height+t*2}}function zt(e,t,n){let r=new Map,i=e.flatMap(e=>e.segments),a=[...t.boxesById.values(),...t.obstacles];for(let o of e){let e=o.plan.wire.label;if(!e)continue;let s=Nt(e),c=It(o.segments,s),l=c.find(e=>{let n=Pt(e,s);if(n.y<t.contentTop)return!1;let o=Rt(n,Fe);return i.some(e=>jt(e,o))||a.some(e=>Mt(n,e))?!1:![...r.values()].some(e=>Mt(n,e.bounds))}),u=l??c[0]??P(o.plan.from);l||n.push(`wire ${o.plan.wire.id} label "${e}" has no clear spot`),r.set(o.plan.wire.id,{at:{x:Math.round(u.x),y:Math.round(u.y)},bounds:Pt(u,s)})}return r}function Bt(e,t,n){return e>Math.min(t,n)+.5&&e<Math.max(t,n)-.5}function Vt(e,t){if(L(e)===L(t))return!1;let n=L(e)?e:t,r=n===e?t:e;return Bt(r.from.x,n.from.x,n.to.x)&&Bt(n.from.y,r.from.y,r.to.y)}function Ht(e,t){if(L(e)!==L(t))return!1;let n=L(e),r=e=>n?e.from.y:e.from.x,i=e=>Math.min(n?e.from.x:e.from.y,n?e.to.x:e.to.y),a=e=>Math.max(n?e.from.x:e.from.y,n?e.to.x:e.to.y);return r(e)===r(t)&&Math.min(a(e),a(t))-Math.max(i(e),i(t))>1}function Ut(e,t){return e.plan.styleKey===t.plan.styleKey&&e.plan.start.x===t.plan.start.x&&e.plan.start.y===t.plan.start.y}function Wt(e){return e.flatMap((t,n)=>e.slice(n+1).flatMap(e=>{if(t.plan.busKey!==null&&t.plan.busKey===e.plan.busKey)return[];let n=t.segments.flatMap(t=>e.segments.map(e=>[t,e]));return n.some(([e,t])=>Vt(e,t))?[`wire ${t.plan.wire.id} crosses wire ${e.plan.wire.id}`]:Ut(t,e)?[]:n.some(([e,t])=>Ht(e,t))?[`wire ${t.plan.wire.id} overlaps wire ${e.plan.wire.id}`]:[]}))}function Gt(e,t){let n=[...t.boxesById.values()];return e.flatMap(e=>n.flatMap(t=>{if(t.id===e.plan.from.id||t.id===e.plan.to.id)return[];let n=Rt(t,-2);return e.segments.some(e=>jt(e,n))?[`wire ${e.plan.wire.id} runs through box ${t.id}`]:[]}))}function Kt(t){if(t.length<=e.layoutWarnings)return[...t];let n=t.slice(0,e.layoutWarnings-1);return[...n,`and ${t.length-n.length} more`]}function qt(e,t){let n=t.map(()=>0);for(let t of e)t.wire.label&&t.shape===`channel`&&(n[t.targetGap]=Math.max(n[t.targetGap]??0,Nt(t.wire.label)));return n}function Jt(e,t){return nt([...e.flatMap(e=>e.segments.flatMap(e=>[e.from,e.to])).map(e=>({x:e.x,y:e.y,width:0,height:0})),...t])}function Yt(e,t,n,r){dt(n,r);let i=vt(e,t),a=xt(e,t),o=wt(a,t.gaps),s=At(e,a);return{runsByKey:a,tracksByGap:o,topTrackCount:i,drawn:s,crossingCost:Gt(s,t).length*Ie+Wt(s).length}}function Xt(e,t){let n=e[t],r=e[t+1];n!==void 0&&r!==void 0&&(e[t]=r,e[t+1]=n)}function Zt(e,t){let n=lt(e),r=ut(n),i=Yt(e,t,n,r).crossingCost,a=e.length<=Le;for(let o of r.values())for(let s=0;a&&i>0&&s+1<o.length;s+=1){Xt(o,s);let a=Yt(e,t,n,r).crossingCost;a<i?i=a:Xt(o,s)}return Yt(e,t,n,r)}function Qt(e){let t=st(e),{runsByKey:n,tracksByGap:r,topTrackCount:i,drawn:a}=Zt(t,e),o=[],s=zt(a,e,o),c=a.map(({plan:e,points:t,trunk:r})=>{let i=t.at(-1)??e.end,a=e.busKey?n.get(I(e)):void 0,o=r.length>0,c=a!==void 0&&i.y>a.top&&i.y<a.bottom;return{kind:`wire`,id:e.wire.id,path:[kt(t),...r.map(e=>kt([e.from,e.to]))].join(` `),start:e.start,end:o||!e.busKey?e.end:i,label:e.wire.label,labelAt:s.get(e.wire.id)?.at??P(e.from),isDashed:e.wire.dashed,strokeHex:e.strokeHex,tone:e.wire.tone,hasArrowhead:e.busKey===null||o,joinAt:c?i:null}}),l=[...s.values()].map(e=>e.bounds);return{wires:c,tracksByGap:r,topTrackCount:i,labelWidthByGap:qt(t,e.gaps),warnings:Kt([...Gt(a,e),...Wt(a),...o]),extent:Jt(a,l)}}function $t(e){return e.resolvedBy?`resolved by ${e.resolvedBy}`:e.author?`from ${e.author}`:``}function en(e,t){let n=new Map;return M(e,`note`).flatMap(e=>{let r=t.get(e.on);if(!r)return[];let{lines:i,height:a}=We(e),o=n.get(e.on)??r.y-we;return n.set(e.on,o+a+_e),[{kind:`note`,id:e.id,x:r.x+r.width-Ce,y:o,width:me,height:a,lines:i,byline:$t(e),isResolved:e.resolvedBy!==null}]})}function tn(e,t,n,r){let i=e.flatMap(e=>e.kind===`wire`?[]:[e]),a=(n.at(-1)??S)+C,o=nt([...i,...t?[t]:[],{x:0,y:0,width:a,height:r}]);return o?{x:Math.min(0,o.x-S),y:Math.min(0,o.y-S),width:o.width+80,height:o.height+80}:{x:0,y:0,width:a+S,height:80}}function nn(e,t){let n=Xe(e,t.gapWidths),r=tt(e,n,t.boxesTop,t.stackHeightByBoxId),i=rt(e,r),a=en(e,r),o=new Map(M(e,`box`).flatMap(t=>{let i=r.get(t.id);return i?[[t.id,Qe(e,t,i,n)]]:[]}));return{columnLeftEdges:n,boxesById:r,frames:i,notes:a,routing:Qt({wires:M(e,`wire`),boxesById:r,columnIndexByBoxId:o,obstacles:[...a,...i.map(e=>({x:e.x,y:e.y,width:e.width,height:D}))],gaps:Ze(n,t.gapWidths,t.reserves),topBandBottom:t.boxesTop-Ne,contentTop:t.contentTop})}}function rn(e,t){return Array.from({length:Math.max(e.length,t.length)},(n,r)=>Math.max(e[r]??0,t[r]??0))}function an(e,t,n){let r=t.tracksByGap,i=t.topTrackCount;for(let a=1;;a+=1){let o=Ye(n.reserves,r,t.labelWidthByGap),s=n.headerBoxesTop+fn(i),c=nn(e,{gapWidths:o,reserves:n.reserves,boxesTop:s,contentTop:n.contentTop,stackHeightByBoxId:n.stackHeightByBoxId}),l=c.routing.topTrackCount>i,u=c.routing.tracksByGap.some((e,t)=>e>(r[t]??0));if(a>=Re||!l&&!u)return{placed:c,boxesTop:s};i=Math.max(i,c.routing.topTrackCount),r=rn(r,c.routing.tracksByGap)}}function on(e){let t=j(e.title,T),n=e.lines.flatMap(e=>j(e.text,pe)),r=+!!e.linkedBoardId;return{titleLines:t,bodyLines:n,height:42+t.length*de+(n.length+r)*fe}}function sn(e){let t=new Map,n=new Map;for(let r of m(e)){let i=e.elements[r.unitId];if(i?.kind!==`unit`)continue;let a=on(i),o=n.get(r.level)??70;n.set(r.level,o+a.height+ue),t.set(i.id,{kind:`unit`,id:i.id,x:S+(r.level-1)*310,y:o,width:C,height:a.height,label:r.label,titleLines:a.titleLines,bodyLines:a.bodyLines,linkedBoardId:i.linkedBoardId})}return t}function cn(e,t){let n={x:e.x+e.width,y:e.y+Math.round(e.height/2)},r={x:t.x,y:t.y+Math.round(t.height/2)},i=t.x-Math.round(w/2);return kt(Tt([n,{x:i,y:n.y},{x:i,y:r.y},r]))}function ln(e,t){return M(e,`unit`).flatMap(e=>{let n=t.get(e.id);return n?e.after.flatMap(e=>{let r=t.get(e);return r?[cn(r,n)]:[]}):[]})}function un(e){return e.size===0?S:Math.max(...[...e.values()].map(e=>e.y+e.height))+ze}function dn(e,t){if(t===0)return e;let n=Object.fromEntries(Object.entries(e.elements).map(([e,n])=>n.kind!==`box`||!n.at?[e,n]:[e,{...n,at:{x:n.at.x,y:n.at.y+t}}]));return{...e,elements:n}}function fn(e){return e>0?e*Me+Ne:0}function pn(e){let t=sn(e),n=un(t),r=n-S,i=dn(e,r),a=Ge(i),o=Ke(i),s=qe(o),c=n+Se+s,l=n+le+s,u=Je(i,a),{placed:d,boxesTop:f}=an(i,nn(i,{gapWidths:Ye(u,[],[]),reserves:u,boxesTop:l,contentTop:c,stackHeightByBoxId:a}).routing,{reserves:u,headerBoxesTop:l,contentTop:c,stackHeightByBoxId:a}),{columnLeftEdges:p}=d,m=[...d.frames,...d.routing.wires,...d.boxesById.values(),...d.notes,...t.values()],h=tn(m,d.routing.extent,p,f),g=h.y+h.height,_=i.lanes.map((e,t)=>({label:e.label||e.id,hex:Ve[e.color],x:S,y:g+t*ve})),v=g+_.length*ve+(_.length>0?12:0),y=i.caption?{text:i.caption,x:S,y:v}:null,ee=_.length*ve+(y?30:0)+(_.length>0?12:0);return{columns:i.columns.map((e,t)=>({id:e.id,titleLines:o[t]??[],titleBaselineY:n+xe,ruleY:c,x:p[t]??S,width:C})),elements:m,legend:_,caption:y,pinnedOffsetY:r,plan:t.size>0?{titleAt:{x:S,y:56},arrowPaths:ln(i,t)}:null,bounds:{...h,height:h.height+ee},warnings:d.routing.warnings}}function mn(e){return JSON.stringify(e)}var hn=`http://www.w3.org/2000/svg`,R=12,gn=26,_n=20,vn=18,yn=17,bn=14,xn=16,Sn=24,Cn=18,wn=`Plan`,Tn=`open linked board`;function z(e,t={},n=``){let r=document.createElementNS(hn,e);for(let[e,n]of Object.entries(t))r.setAttribute(e,String(n));return n&&r.setAttribute(`class`,n),r}function B(e,t,n,r){let i=z(`text`,{x:t,y:n},r);return i.textContent=e,i}function V(e,t){let n=z(`g`,{},`wb-element ${t}`);return n.dataset.elementId=e.id,n.dataset.elementKind=e.kind,n}function En(e){let t=V(e,e.isGhost?`wb-box wb-ghost`:`wb-box`),n=z(`rect`,{x:e.x,y:e.y,width:e.width,height:e.height,rx:8},`wb-box-outline`);e.lane&&(n.style.stroke=e.lane.hex),t.append(n),e.titleLines.forEach((n,r)=>{t.append(B(n,e.x+R,e.y+gn+r*_n,`wb-box-title`))});let r=e.y+gn+e.titleLines.length*_n;if(e.bodyLines.forEach((n,i)=>{let a=e.x+R+(n.muted?bn:0);t.append(B(n.text,a,r+i*vn,n.muted?`wb-box-line wb-muted`:`wb-box-line`))}),!e.lane)return t;let i=e.y+e.height-28,a=Math.min(e.width-24,16+e.lane.label.length*8),o=z(`rect`,{x:e.x+R,y:i,width:a,height:18,rx:9},`wb-lane-pill`);o.style.stroke=e.lane.hex;let s=B(e.lane.label,e.x+R+8,i+13,`wb-lane-pill-text`);return s.style.fill=e.lane.hex,t.append(o,s),t}function Dn(e){let t=V(e,`wb-frame`);return t.append(z(`rect`,{x:e.x,y:e.y,width:e.width,height:e.height,rx:12},`wb-frame-outline`),B(e.title,e.x+14,e.y+18,`wb-frame-title`)),t}function On(e){let t=V(e,`wb-wire wb-tone-${e.tone}`),n=z(`path`,{d:e.path},`wb-wire-hit`),r=z(`path`,e.hasArrowhead?{d:e.path,"marker-end":`url(#wb-arrow)`}:{d:e.path},e.isDashed?`wb-wire-line wb-dashed`:`wb-wire-line`);return e.strokeHex&&(r.style.stroke=e.strokeHex),t.append(n,r,z(`circle`,{cx:e.start.x,cy:e.start.y,r:3},`wb-wire-dot`)),e.joinAt&&t.append(z(`circle`,{cx:e.joinAt.x,cy:e.joinAt.y,r:3},`wb-wire-dot`)),e.label&&t.append(B(e.label,e.labelAt.x,e.labelAt.y,`wb-wire-label`)),t}function kn(e){let t=V(e,e.isResolved?`wb-note wb-resolved`:`wb-note`);return t.append(z(`rect`,{x:e.x,y:e.y,width:e.width,height:e.height,rx:4},`wb-note-card`)),e.lines.forEach((n,r)=>{t.append(B(n,e.x+10,e.y+22+r*yn,`wb-note-text`))}),e.byline&&t.append(B(e.byline,e.x+10,e.y+22+e.lines.length*yn,`wb-note-byline`)),t}function An(e){let t=V(e,`wb-unit`);t.append(z(`rect`,{x:e.x,y:e.y,width:e.width,height:e.height,rx:8},`wb-unit-outline`),B(e.label,e.x+R,e.y+Sn,`wb-unit-label`));let n=e.y+Sn+Cn;e.titleLines.forEach((r,i)=>{t.append(B(r,e.x+R,n+i*_n,`wb-box-title`))});let r=n+e.titleLines.length*_n;if(e.bodyLines.forEach((n,i)=>{t.append(B(n,e.x+R,r+i*vn,`wb-box-line`))}),!e.linkedBoardId)return t;let i=B(Tn,e.x+R,r+e.bodyLines.length*vn,`wb-unit-link`);return i.dataset.linkedBoardId=e.linkedBoardId,t.append(i),t}var jn={frame:`frames`,wire:`wires`,box:`boxes`,note:`notes`,unit:`units`},Mn=[`box`,`frame`,`wire`,`note`,`unit`];function Nn(e){switch(e.kind){case`box`:return En(e);case`frame`:return Dn(e);case`wire`:return On(e);case`note`:return kn(e);case`unit`:return An(e)}}function Pn(e){let t=z(`g`,{},`wb-chrome`);if(e.plan){t.append(B(wn,e.plan.titleAt.x,e.plan.titleAt.y,`wb-column-title`));for(let n of e.plan.arrowPaths)t.append(z(`path`,{d:n,"marker-end":`url(#wb-arrow)`},`wb-wire-line`))}for(let n of e.columns)n.titleLines.length!==0&&(n.titleLines.forEach((e,r)=>{t.append(B(e,n.x,n.titleBaselineY+r*xn,`wb-column-title`))}),t.append(z(`line`,{x1:n.x,y1:n.ruleY,x2:n.x+n.width,y2:n.ruleY},`wb-column-rule`)));for(let n of e.legend){let e=z(`rect`,{x:n.x,y:n.y,width:14,height:14,rx:3},`wb-legend-swatch`);e.style.fill=n.hex,t.append(e,B(n.label,n.x+22,n.y+12,`wb-legend-text`))}return e.caption&&t.append(B(e.caption.text,e.caption.x,e.caption.y+16,`wb-caption`)),t}function Fn(){let e=z(`defs`),t=z(`marker`,{id:`wb-arrow`,viewBox:`0 0 10 10`,refX:9,refY:5,markerWidth:8,markerHeight:8,orient:`auto-start-reverse`});return t.append(z(`path`,{d:`M 0 1 L 10 5 L 0 9 z`,fill:`context-stroke`})),e.append(t),e}function In(e){let t={frames:z(`g`,{},`wb-layer`),wires:z(`g`,{},`wb-layer`),boxes:z(`g`,{},`wb-layer`),notes:z(`g`,{},`wb-layer`),units:z(`g`,{},`wb-layer`)},n=z(`g`);e.replaceChildren(Fn(),n,t.frames,t.wires,t.boxes,t.notes,t.units);let r=new Map,i=null,a=new Set;function o(e,t){t.classList.toggle(`is-selected`,a.has(e))}function s(e){let a=pn(e),s=Pn(a);n.replaceWith(s),n=s;let c=new Set;for(let e of a.elements){c.add(e.id);let n=mn(e),i=r.get(e.id);if(i?.signature===n)continue;let a=Nn(e);o(e.id,a),i&&i.node.replaceWith(a),i||t[jn[e.kind]].append(a),r.set(e.id,{signature:n,node:a})}for(let[e,t]of r)c.has(e)||(t.node.remove(),r.delete(e));return i=a,a}function c(e){if(!(e instanceof Element))return null;let t=e.closest(`.wb-element`),n=t?.dataset.elementId,r=Mn.find(e=>e===t?.dataset.elementKind);return!n||!r?null:{id:n,kind:r}}function l(e){a=e;for(let[e,t]of r)o(e,t.node)}function u(){for(let e of r.values())e.node.remove();r.clear();let e=z(`g`);n.replaceWith(e),n=e,i=null}return{render:s,layout:()=>i,elementFromTarget:c,nodeOf:e=>r.get(e)?.node??null,setSelection:l,clear:u}}var Ln=`http://www.w3.org/2000/svg`,Rn=`No boards yet. Make one here, or have an agent run glimmervoid whiteboard new <title>.`,zn=`Pick a board above.`,H=null,U=null,W=null,G=null,Bn=!0,K=null,q=i(`action-status wb-status`),J=i(`action-status wb-status`);function Y(e){let{dialog:n,close:r,actions:i,btnCancel:a}=o({title:e.title}),s=t(`input`,`dialog-input`);s.type=`text`,s.placeholder=e.placeholder,s.maxLength=e.maxLength,s.value=e.initialValue??``,s.autocomplete=`off`,s.setAttribute(`aria-label`,e.label);let c=t(`div`,`dialog-error`);c.setAttribute(`role`,`alert`);let l=e.choices?t(`select`,`dialog-input wb-dialog-select`):null;if(l&&e.choices){l.setAttribute(`aria-label`,e.choices.label);for(let n of e.choices.options){let e=t(`option`,null,n.text);e.value=n.value,l.append(e)}}let u=t(`button`,`btn-dialog btn-dialog-confirm`,e.confirmLabel);u.type=`button`,i.append(u),n.append(t(`label`,`dialog-label`,e.label),s,...l?[l]:[],c,i);async function d(){let t=s.value.trim();if(!t){c.textContent=`${e.label} is empty.`;return}u.disabled=!0;let n=await e.onSubmit(t,l?.value??null);u.disabled=!1,n?c.textContent=n:r()}a.addEventListener(`click`,r),u.addEventListener(`click`,()=>void d()),s.addEventListener(`keydown`,e=>{e.key===`Enter`&&(e.preventDefault(),d())}),requestAnimationFrame(()=>s.focus())}function X(){return H?g(H):null}function Vn(){return s().find(e=>e.id===H)??null}async function Hn(e){if(!H||e.length===0)return!1;let t=await v(H,e);return t.ok?(q.clear(),!0):(q.show(`error`,t.error),!1)}async function Un(e){if(!H)return`No board is open.`;let t=await v(H,e);return t.ok?null:t.error}function Wn(e){let t=r(e);return t?n(t):`closed session`}function Z(e){let t=X();return[...G?.selectedIds()??new Set].flatMap(e=>t?.elements[e]??[]).filter(t=>t.kind===e)}function Gn(){if(!U)return;let e=X(),t=Z(`box`).length,n=G?.selectedIds().size??0;U.buttons.box.disabled=!e,U.buttons.wire.disabled=t!==2,U.buttons.note.disabled=t!==1,U.buttons.frame.disabled=t===0,U.buttons.unit.disabled=!e,U.buttons.fit.disabled=!e,U.buttons.remove.disabled=!e,U.toolbar.dataset.selectedCount=String(n)}function Kn(){if(!U)return;let e=s();H&&!e.some(e=>e.id===H)&&(H=null),!H&&e[0]&&Q(e[0].id),U.list.replaceChildren(...e.map(e=>{let n=t(`button`,`wb-board-tab`,e.title);return n.type=`button`,n.setAttribute(`aria-pressed`,String(e.id===H)),e.connectedSessionIds.length>0&&n.append(t(`span`,`wb-board-tab-count`,String(e.connectedSessionIds.length))),n.addEventListener(`click`,()=>Q(e.id)),n})),qn()}function qn(){if(!U)return;let e=Vn(),n=s().length>0;U.boardHead.hidden=!e,U.canvas.hidden=!e,U.empty.hidden=!!e,U.empty.textContent=n?zn:Rn,e&&(U.boardMeta.textContent=`v${e.version}`,U.presence.replaceChildren(...e.connectedSessionIds.map(e=>t(`span`,`wb-presence-pill`,Wn(e)))),e.connectedSessionIds.length===0&&U.presence.append(t(`span`,`wb-presence-none`,`no sessions connected`)),Gn(),Yn())}function Jn(e,t){let n=Wn(t);if(!e?.connectedSessionIds.includes(t))return`${n} is not connected to this board`;let r=e.queuedBySessionId[t]??0;return r===0?`${n} has read every change`:`${r} board ${r===1?`edit`:`edits`} queued for ${n}`}function Yn(){if(!U||!K)return;let e=Vn();U.dockQueued.textContent=Jn(e,K),U.sendToAgent.disabled=!e?.connectedSessionIds.includes(K)}async function Xn(){if(!U||!H||!K)return;U.sendToAgent.disabled=!0,J.show(`busy`,`sending`);let e=await h(H,K);Yn(),e.ok?J.show(`ok`,`sent; the agent reads the board when it is ready`):J.show(`error`,e.error)}function Zn(){if(!W)return;let e=X();e?(W.render(e),G?.pruneSelection(e),Bn&&=(G?.fit(),!1),Gn()):W.clear()}function Q(e){H!==e&&(H=e,Bn=!0,G?.clearSelection(),G?.closeTitleInput(),W?.clear(),q.clear(),Kn(),l(e).then(Zn))}function Qn(){let t=X();if(!t)return;let n=Z(`box`)[0],r=t.columns.map(e=>({value:e.id,text:e.title||e.id})),i=n?.column;i&&r.sort((e,t)=>Number(t.value===i)-Number(e.value===i)),Y({title:`Add a box`,label:`Box title`,placeholder:`parse the feed`,maxLength:e.title,confirmLabel:`Add box`,choices:r.length>1?{label:`Column`,options:r}:void 0,onSubmit:(e,t)=>Un([{op:`add`,element:{kind:`box`,id:b(`box`),title:e,column:t??r[0]?.value??`main`,lines:[],lane:null,ghost:!1,order:0,at:null}}])})}function $n(){let t=X();if(!t)return;let n=s().filter(e=>e.id!==t.id),r=[{value:``,text:`No linked board`},...n.map(e=>({value:e.id,text:e.title}))];Y({title:`Add a unit`,label:`Unit title`,placeholder:`index the diffs`,maxLength:e.title,confirmLabel:`Add unit`,choices:n.length>0?{label:`Linked board`,options:r}:void 0,onSubmit:(e,t)=>Un([{op:`add`,element:{kind:`unit`,id:b(`unit`),title:e,lines:[],after:[],linkedBoardId:t||null}}])})}function er(t){Y({title:`Pin a note`,label:`Note`,placeholder:`what about retries?`,maxLength:e.noteText,confirmLabel:`Pin note`,onSubmit:e=>Un([{op:`add`,element:{kind:`note`,id:b(`note`),on:t,text:e,author:``,resolvedBy:null}}])})}function tr(){let[e,t]=Z(`box`);e&&t&&(G?.clearSelection(),Hn([{op:`add`,element:{kind:`wire`,id:b(`wire`),from:e.id,to:t.id,dashed:!1,tone:`plain`,label:null}}]))}function nr(){let t=Z(`box`).map(e=>e.id);t.length!==0&&Y({title:`Frame the selected boxes`,label:`Frame title`,placeholder:`intake`,maxLength:e.title,confirmLabel:`Add frame`,onSubmit:async e=>{let n=await Un([{op:`add`,element:{kind:`frame`,id:b(`frame`),title:e,contains:t}}]);return n||G?.clearSelection(),n}})}function rr(){let e=Vn();if(!e)return;let t=e.connectedSessionIds.map(Wn),n=t.length>0?` ${t.join(`, `)} ${t.length===1?`is`:`are`} connected and will lose it.`:``;a({title:`Delete board`,message:`Delete "${e.title}" for good?${n}`,confirmLabel:`Delete board`,danger:!0,onConfirm:()=>{y(e.id).then(e=>{e.ok||q.show(`error`,e.error)})}})}function ir(){Y({title:`New board`,label:`Board title`,placeholder:`knowledge writer`,maxLength:e.title,confirmLabel:`Create board`,onSubmit:async e=>{let t=await f(e);return t.ok?(Q(t.boardId),null):t.error}})}function $(e,n,r=``){let i=t(`button`,`wb-button ${r}`.trim(),e);return i.type=`button`,i.addEventListener(`click`,n),i}function ar(e){let n=t(`div`,`wb-top`),r=t(`div`,`wb-board-list`);r.setAttribute(`aria-label`,`Boards`);let i=t(`div`,`wb-board-head`),a=t(`div`,`wb-title-row`),o=t(`span`,`wb-board-meta`),s=t(`div`,`wb-presence`);a.append(o,s);let c=t(`div`,`wb-toolbar`),l={box:$(`box`,Qn),wire:$(`wire`,tr),note:$(`note`,()=>{let[e]=Z(`box`);e&&er(e.id)}),frame:$(`frame`,nr),unit:$(`unit`,$n),fit:$(`fit`,()=>G?.fit()),remove:$(`delete board`,rr,`wb-button-danger`)};l.fit.dataset.phoneVisible=``,c.append(l.box,l.wire,l.note,l.frame,l.unit,l.fit,l.remove,q.element),i.append(a,c),n.append(r,$(`new board`,ir),i);let u=t(`div`,`wb-canvas`),d=document.createElementNS(Ln,`svg`);d.setAttribute(`class`,`wb-svg`),d.setAttribute(`role`,`img`),d.setAttribute(`aria-label`,`Whiteboard`),d.setAttribute(`preserveAspectRatio`,`xMidYMin meet`),u.append(d);let f=t(`p`,`wb-empty`,Rn),m=t(`div`,`wb-dock`);m.hidden=!0;let h=t(`span`,`wb-dock-queued`),g=$(`send to agent`,()=>void Xn()),v=t(`div`,`wb-dock-bar`);v.append(h,g,J.element),m.append(v),e.replaceChildren(n,u,f,m),U={list:r,boardHead:i,boardMeta:o,presence:s,toolbar:c,canvas:u,empty:f,dock:m,dockQueued:h,sendToAgent:g,buttons:l};let y=In(d);W=y,G=ce({svg:d,canvas:u,renderer:y,currentBoard:X,sendOps:Hn,onSelectionChange:Gn,onPhoneTapBox:er,onOpenLinkedBoard:Q}),p(Kn),_(e=>{e===H&&Zn()}),Kn()}function or(){return document.documentElement.dataset.layout===`phone`}function sr(){K&&u()===K&&ee(),K=null,U&&(U.dock.hidden=!0)}function cr(e){if(!U||or())return;let t=r(e);t&&(K=e,U.dock.hidden=!1,J.clear(),Yn(),te(t,e,U.dock,{className:`wb-docked-card`}),c(t,e,!0))}function lr(){let e=d();e&&(Q(e.boardId),e.dockSessionId&&cr(e.dockSessionId)),Kn(),H&&l(H).then(Zn)}var ur={mount:ar,refresh:lr,deactivate:sr};export{ur as view};
1
+ import{bt as e}from"./updates-view-core-4oGJ3ZXL.js";import{s as t}from"./dom-helpers-DBbFg1c_.js";import{a as n,r}from"./card-registry-D5EJa_tx.js";import{i}from"./action-status-Cmp0b1QX.js";import{a,n as o}from"./modal-USMHOKBI.js";import{$r as s,Sn as c,ai as l,bi as u,ci as d,ei as f,ii as p,li as m,ni as h,oi as g,ri as _,si as v,ti as y,xi as ee,yi as te}from"./index-BlbUd3zj.js";var ne=4,re=200,ie=2e4,ae=1.1,oe=[`wire`,`note`,`frame`,`box`,`unit`];function b(e){let t=Math.random().toString(36).slice(2,8);return`${e}-${Date.now().toString(36)}${t}`}function x(){return document.documentElement.dataset.layout===`phone`}function se(e){return e instanceof Element?e.closest(`[data-linked-board-id]`)?.dataset.linkedBoardId??null:null}function ce(e){let{svg:n,canvas:r,renderer:i}=e,a=new Map,o=new Set,s={x:0,y:0,width:1e3,height:600},c=null,l=null;function u(){n.setAttribute(`viewBox`,`${s.x} ${s.y} ${s.width} ${s.height}`)}function d(){let e=i.layout();if(!e)return;let{bounds:t}=e,r=n.clientWidth,a=n.clientHeight;if(r===0||a===0){s={...t},u();return}let o=Math.max(1,t.width/r,t.height/a),c=r*o;s={x:t.x-(c-t.width)/2,y:t.y,width:c,height:a*o},u()}function f(e,t){let r=n.getScreenCTM();if(!r)return{x:e,y:t};let i=new DOMPoint(e,t).matrixTransform(r.inverse());return{x:i.x,y:i.y}}function p(){let e=n.clientWidth||1,t=n.clientHeight||1;return Math.max(s.width/e,s.height/t)}function m(e,t){let n=Math.min(ie,Math.max(re,s.width*t)),r=n/s.width;s={x:e.x-(e.x-s.x)*r,y:e.y-(e.y-s.y)*r,width:n,height:s.height*r},u()}function h(e,t){let n=p();s={...s,x:s.x-e*n,y:s.y-t*n},u()}function g(t){o=t,i.setSelection(o),e.onSelectionChange(o)}function _(e,t){if(!t){g(o.has(e)&&o.size===1?new Set:new Set([e]));return}let n=new Set(o);n.delete(e)||n.add(e),g(n)}function v(e){let t=new Set([...o].filter(t=>e?.elements[t]));t.size!==o.size&&g(t)}function y(e){let t=i.layout()?.elements.find(t=>t.id===e);return t?.kind===`box`?t:null}function ee(){let[e,t]=[...a.values()];return!e||!t?0:Math.hypot(e.x-t.x,e.y-t.y)}function te(){c={kind:`pinch`,distance:ee(),viewWidth:s.width}}function b(t){if(t.button!==0||l)return;let r=se(t.target);if(r){e.onOpenLinkedBoard(r);return}if(a.set(t.pointerId,{x:t.clientX,y:t.clientY}),n.setPointerCapture(t.pointerId),a.size===2){te();return}let o=i.elementFromTarget(t.target),s=o?.kind===`box`&&!x()?y(o.id):null;if(o&&s){c={kind:`drag`,pointerId:t.pointerId,boxId:o.id,origin:f(t.clientX,t.clientY),start:s,hasMoved:!1,isAdditive:t.shiftKey};return}if(o&&!x()){_(o.id,t.shiftKey);return}let u=o?.kind===`box`?o.id:null;c={kind:`pan`,pointerId:t.pointerId,lastClient:{x:t.clientX,y:t.clientY},hasMoved:!1,tappedBoxId:u}}function ce(e,t){let n=f(t.clientX,t.clientY),r=n.x-e.origin.x,a=n.y-e.origin.y;!e.hasMoved&&Math.hypot(r,a)<ne*p()||(e.hasMoved=!0,i.nodeOf(e.boxId)?.setAttribute(`transform`,`translate(${r} ${a})`))}function S(e,t){let n=t.clientX-e.lastClient.x,r=t.clientY-e.lastClient.y;!e.hasMoved&&Math.hypot(n,r)<ne||(e.hasMoved=!0,e.lastClient={x:t.clientX,y:t.clientY},h(n,r))}function le(e){let t=ee();if(t<=0||e.distance<=0)return;let n=[...a.values()];m(f(n.reduce((e,t)=>e+t.x,0)/n.length,n.reduce((e,t)=>e+t.y,0)/n.length),e.viewWidth*(e.distance/t)/s.width)}function C(e){a.has(e.pointerId)&&(a.set(e.pointerId,{x:e.clientX,y:e.clientY}),c?.kind===`pinch`?le(c):c?.kind===`drag`&&c.pointerId===e.pointerId?ce(c,e):c?.kind===`pan`&&c.pointerId===e.pointerId&&S(c,e))}async function w(t,n){if(!t.hasMoved){_(t.boxId,t.isAdditive);return}let r=f(n.clientX,n.clientY),a=i.layout()?.pinnedOffsetY??0,o={x:Math.round(t.start.x+r.x-t.origin.x),y:Math.round(t.start.y+r.y-t.origin.y-a)};await e.sendOps([{op:`set`,id:t.boxId,fields:{at:o}}])||i.nodeOf(t.boxId)?.removeAttribute(`transform`)}function ue(t){if(!a.delete(t.pointerId))return;let n=c;n?.kind===`pinch`?c=null:(c=null,n?.kind===`drag`&&n.pointerId===t.pointerId?w(n,t):n?.kind!==`pan`||n.hasMoved||(n.tappedBoxId&&x()?e.onPhoneTapBox(n.tappedBoxId):n.tappedBoxId||g(new Set)))}function de(e){a.delete(e.pointerId),c?.kind===`drag`&&i.nodeOf(c.boxId)?.removeAttribute(`transform`),c=null}function fe(e){e.preventDefault(),e.ctrlKey||e.metaKey?m(f(e.clientX,e.clientY),e.deltaY>0?ae:1/ae):h(-e.deltaX,-e.deltaY)}function T(){let e=l;l=null,e?.remove()}function pe(a){let o=e.currentBoard()?.elements[a],s=i.nodeOf(a);if(o?.kind!==`box`||!s)return;T();let c=r.getBoundingClientRect(),u=s.getBoundingClientRect(),d=t(`input`,`wb-title-input`);d.type=`text`,d.value=o.title,d.maxLength=80,d.setAttribute(`aria-label`,`Box title`),d.style.left=`${u.left-c.left}px`,d.style.top=`${u.top-c.top}px`,d.style.width=`${Math.max(160,u.width)}px`,l=d,r.append(d),d.addEventListener(`keydown`,t=>{if(t.key===`Escape`){t.preventDefault(),T(),n.focus();return}if(t.key!==`Enter`)return;t.preventDefault();let r=d.value.trim();T(),n.focus(),r&&r!==o.title&&e.sendOps([{op:`set`,id:a,fields:{title:r}}])}),d.addEventListener(`blur`,T),d.focus(),d.select()}function E(e){if(x())return;let t=i.elementFromTarget(document.elementFromPoint(e.clientX,e.clientY));t?.kind===`box`&&pe(t.id)}function D(){let t=e.currentBoard();if(!t||o.size===0)return;let n=[...o].flatMap(e=>t.elements[e]??[]),r=oe.flatMap(e=>n.filter(t=>t.kind===e)).map(e=>({op:`remove`,id:e.id}));g(new Set),e.sendOps(r)}function me(e){e.target===n&&(e.key===`Delete`||e.key===`Backspace`?(e.preventDefault(),D()):e.key===`Escape`&&g(new Set))}return n.tabIndex=0,n.addEventListener(`pointerdown`,b),n.addEventListener(`pointermove`,C),n.addEventListener(`pointerup`,ue),n.addEventListener(`pointercancel`,de),n.addEventListener(`wheel`,fe,{passive:!1}),n.addEventListener(`dblclick`,E),n.addEventListener(`keydown`,me),{fit:d,selectedIds:()=>o,clearSelection:()=>g(new Set),pruneSelection:v,closeTitleInput:T}}var S=40,le=44,C=220,w=90,ue=30,de=20,fe=18,T=20,pe=26,E=18,D=26,me=170,he=21,ge=17,_e=10,ve=22,ye=24,be=16,xe=16,Se=26,Ce=24,we=8,Te=10,Ee=14,De=4,Oe=14,ke=8,O=6,Ae=4,je=6,Me=12,Ne=10,Pe=6.6,k=5,A=10,Fe=2,Ie=100,Le=120,Re=4,ze=40,Be=[.5,.35,.65,.2,.8],Ve=Object.freeze({blue:`#60a5fa`,green:`#4ade80`,orange:`#fb923c`,pink:`#f472b6`,cyan:`#22d3ee`,yellow:`#facc15`});function j(e,t){let n=e.split(/\s+/).filter(Boolean),r=[],i=``;for(let e of n){let n=e.match(RegExp(`.{1,${t}}`,`g`))??[e];for(let e of n){let n=i?`${i} ${e}`:e;n.length<=t?i=n:(r.push(i),i=e)}}return i&&r.push(i),r.length>0?r:[``]}function He(e,t){let n=e.lanes.find(e=>e.id===t.lane);return n?{label:n.label||n.id,hex:Ve[n.color]}:null}function Ue(e,t){let n=j(t.title,T),r=t.lines.flatMap(e=>j(e.text,pe-(e.muted?2:0)).map(t=>({text:t,muted:e.muted}))),i=He(e,t);return{titleLines:n,bodyLines:r,lane:i,height:24+n.length*de+r.length*fe+(i?26:0)}}function M(e,t){return Object.values(e.elements).filter(e=>e.kind===t)}function We(e){let t=j(e.text,he);return{lines:t,height:24+(t.length+1)*ge}}function Ge(e){let t=new Map;for(let n of M(e,`note`)){let e=t.get(n.on),r=We(n).height;t.set(n.on,e===void 0?r:e+_e+r)}return t}function Ke(e){return e.columns.map(e=>e.title?j(e.title,ye):[])}function qe(e){return(Math.max(1,...e.map(e=>e.length))-1)*be}function N(e,t){let n=new Map;for(let r of e){let e=t(r),i=n.get(e);i?i.push(r):n.set(e,[r])}return n}function Je(e,t){let n=M(e,`box`).filter(e=>!e.at),r=new Set(n.filter(e=>t.has(e.id)).map(e=>e.column)),i=new Set(M(e,`frame`).flatMap(e=>e.contains)),a=new Set(n.filter(e=>i.has(e.id)).map(e=>e.column)),o=e=>Te+(e!==void 0&&a.has(e)?E:0);return e.columns.map((t,n)=>{let i=r.has(t.id);return{left:i?156:o(t.id),right:o(e.columns[n+1]?.id),minimumWidth:i?Math.max(w,186):w}})}function Ye(e,t,n){return e.map((e,r)=>{let i=t[r]??0,a=n[r]??0,o=i>0?e.left+e.right+(i+1)*Ee:0,s=a>0?e.left+e.right+a+20:0;return Math.max(e.minimumWidth,o,s)})}function Xe(e,t){let n=[],r=S;for(let[i]of e.columns.entries())n.push(r),r+=C+(t[i]??w);return n}function Ze(e,t,n){return e.map((e,r)=>{let i=n[r]??{left:Te,right:Te,minimumWidth:w},a=e+C+(t[r]??w);return{left:e+C+i.left,right:a-i.right}})}function Qe(e,t,n,r){if(!t.at)return Math.max(0,e.columns.findIndex(e=>e.id===t.column));let i=n.x+n.width/2,a=r.findLastIndex(e=>e<=i);return Math.max(0,a)}function $e(e){let t=new Map;for(let n of M(e,`frame`))for(let e of n.contains)t.has(e)||t.set(e,n.id);return t}function et(e,t){return e===t?0:(e?E:0)+(t?44:0)}function tt(e,t,n,r){let i=new Map,a=new Map,o=new Map,s=$e(e),c=M(e,`box`).map((e,t)=>({box:e,index:t})).sort((e,t)=>e.box.order-t.box.order||e.index-t.index);for(let{box:l}of c){let c=Math.max(0,e.columns.findIndex(e=>e.id===l.column)),u=Ue(e,l),d=s.get(l.id)??null,f=(a.get(l.column)??n)+et(o.get(l.column)??null,d),p=l.at??{x:t[c]??S,y:f};if(!l.at){let e=(r.get(l.id)??0)-we;a.set(l.column,f+Math.max(u.height,e)+ue),o.set(l.column,d)}i.set(l.id,{kind:`box`,id:l.id,x:p.x,y:p.y,width:C,height:u.height,titleLines:u.titleLines,bodyLines:u.bodyLines,lane:u.lane,isGhost:l.ghost})}return i}function nt(e){if(e.length===0)return null;let t=Math.min(...e.map(e=>e.x)),n=Math.min(...e.map(e=>e.y)),r=Math.max(...e.map(e=>e.x+e.width)),i=Math.max(...e.map(e=>e.y+e.height));return{x:t,y:n,width:r-t,height:i-n}}function rt(e,t){return M(e,`frame`).flatMap(e=>{let n=nt(e.contains.flatMap(e=>t.get(e)??[]));return n?[{kind:`frame`,id:e.id,title:e.title,x:n.x-E,y:n.y-E-D,width:n.width+36,height:n.height+36+D}]:[]})}function it(e){return e===`left`||e===`right`}function P(e){return{x:e.x+e.width/2,y:e.y+e.height/2}}function at(e,t,n,r){let i=e.y<t.y?e:t,a=i===e?t:e;return[...r.boxesById.values()].some(o=>o.id!==e.id&&o.id!==t.id&&r.columnIndexByBoxId.get(o.id)===n&&o.y<a.y&&o.y+o.height>i.y+i.height)}function ot(e,t,n){let r=n.columnIndexByBoxId.get(e.id)??0,i=n.columnIndexByBoxId.get(t.id)??0;if(r===i){if(e.id!==t.id&&!at(e,t,r,n)){let n=t.y>e.y;return{shape:`straight`,exitSide:n?`bottom`:`top`,entrySide:n?`top`:`bottom`,sourceGap:-1,targetGap:-1}}return{shape:`channel`,exitSide:`right`,entrySide:`right`,sourceGap:r,targetGap:r}}return i>r?{shape:i===r+1?`channel`:`long`,exitSide:`right`,entrySide:`left`,sourceGap:r,targetGap:i-1}:{shape:i===r-1?`channel`:`long`,exitSide:`left`,entrySide:`right`,sourceGap:r-1,targetGap:i}}function st(e){let t=e.wires.flatMap(t=>{let n=e.boxesById.get(t.from),r=e.boxesById.get(t.to);if(!n||!r)return[];let i=t.tone===`lane`?n.lane?.hex??null:null,a=P(n);return[{wire:t,from:n,to:r,strokeHex:i,styleKey:`${t.dashed}|${t.tone}|${i}`,...ot(n,r,e),busKey:null,start:a,end:P(r),crossingY:a.y}]}),n=new Map,r=e=>`${e.to.id}|${e.entrySide}|${e.styleKey}`;for(let e of t)e.shape!==`straight`&&n.set(r(e),(n.get(r(e))??0)+1);for(let e of t)e.shape!==`straight`&&(n.get(r(e))??0)>1&&(e.busKey=r(e));return t}function ct(e,t,n){let r=Array.from({length:n},(e,t)=>t);if(it(t)){let i=t===`left`?e.x:e.x+e.width,a=Math.min(Oe,(e.height-16)/Math.max(n-1,1)),o=e.y+Math.min(e.height/2,40)-(n-1)*a/2,s=Math.max(e.y+ke,Math.min(o,e.y+e.height-ke-(n-1)*a));return r.map(e=>({x:i,y:Math.round(s+e*a)}))}let i=t===`top`?e.y:e.y+e.height,a=e.x+e.width/2-(n-1)*Oe/2;return r.map(e=>({x:Math.round(a+e*Oe),y:i}))}function lt(e){return N(e.flatMap(e=>[{box:e.from,side:e.exitSide,groupKey:`exit|${e.styleKey}`,wireId:e.wire.id,farPoint:P(e.to),assign:t=>{e.start=t}},{box:e.to,side:e.entrySide,groupKey:e.busKey?`bus|${e.busKey}`:`entry|${e.wire.id}`,wireId:e.wire.id,farPoint:P(e.from),assign:t=>{e.end=t}}]),e=>`${e.box.id}|${e.side}`)}function ut(e){return new Map([...e.entries()].map(([e,t])=>[e,[...N(t,e=>e.groupKey).entries()].map(([e,t])=>({groupKey:e,firstWireId:t.map(e=>e.wireId).sort()[0]??e,farCoordinate:t.reduce((e,t)=>e+(it(t.side)?t.farPoint.y:t.farPoint.x),0)/t.length})).sort((e,t)=>e.farCoordinate-t.farCoordinate||e.firstWireId.localeCompare(t.firstWireId)||e.groupKey.localeCompare(t.groupKey)).map(e=>e.groupKey)]))}function dt(e,t){for(let[n,r]of e){let e=r[0],i=t.get(n)??[];if(!e)continue;let a=ct(e.box,e.side,i.length);for(let e of r){let t=a[i.indexOf(e.groupKey)];t&&e.assign(t)}}}function ft(e,t){let n=t[e.sourceGap]??{left:e.start.x,right:e.start.x},r=t[e.targetGap]??{left:e.end.x,right:e.end.x};return{left:Math.min(n.left,r.left),right:Math.max(n.right,r.right)}}function pt(e,t,n){return[...[...n.boxesById.values()].filter(t=>t.id!==e.from.id&&t.id!==e.to.id),...n.obstacles].filter(e=>e.x<t.right&&e.x+e.width>t.left)}function mt(e,t){return!t.some(t=>e>t.y-O&&e<t.y+t.height+O)}function ht(e){let t=e.map(e=>({top:e.y-O,bottom:e.y+e.height+O})).sort((e,t)=>e.top-t.top),n=[];for(let e of t){let t=n.at(-1);t&&e.top<=t.bottom?t.bottom=Math.max(t.bottom,e.bottom):n.push({...e})}return n.slice(1).flatMap((e,t)=>{let r=n[t];return!r||e.top-r.bottom<Ae?[]:[{top:r.bottom,bottom:e.top}]})}function gt(e,t){return e.left<t.right&&t.left<e.right}function _t(e,t){let n=[];return e.forEach((r,i)=>{let a=e.slice(0,i).flatMap((e,i)=>t(r,e)?[n[i]??0]:[]);n.push(a.length>0?Math.max(...a)+1:0)}),n}function vt(e,t){let n=[],r=[];for(let i of e){if(i.shape!==`long`)continue;let e=ft(i,t.gaps),a=pt(i,e,t),o=[i.start.y,i.end.y].find(e=>mt(e,a));if(o!==void 0){i.crossingY=o;continue}let s=(i.start.y+i.end.y)/2,c=ht(a).sort((e,t)=>Math.abs((e.top+e.bottom)/2-s)-Math.abs((t.top+t.bottom)/2-s))[0];c?n.push({plan:i,interval:c,span:e}):r.push({plan:i,span:e})}let i=N(n,e=>`${Math.round(e.interval.top)}|${Math.round(e.interval.bottom)}`);for(let e of i.values()){let t=[...e].sort((e,t)=>e.plan.start.y-t.plan.start.y||e.plan.wire.id.localeCompare(t.plan.wire.id)),n=_t(t,(e,t)=>gt(e.span,t.span)),i=t[0]?.interval??{top:0,bottom:0},a=i.bottom-i.top,o=Math.max(1,Math.floor(a/je)-1),s=Math.min(o,Math.max(...n)+1);t.forEach((e,t)=>{let c=n[t]??0;c>=o?r.push({plan:e.plan,span:e.span}):e.plan.crossingY=Math.round(i.top+a*(c+1)/(s+1))})}let a=[...r].sort((e,t)=>t.span.right-t.span.left-(e.span.right-e.span.left)||e.plan.wire.id.localeCompare(t.plan.wire.id)),o=_t(a,(e,t)=>gt(e.span,t.span)).map(e=>a.length-1-e);return a.forEach(({plan:e},n)=>{e.crossingY=t.topBandBottom-(o[n]??0)*Me}),r.length>0?Math.max(...o)+1:0}function yt(e,t){return t<=e?`left`:`right`}function bt(e,t){return{key:e,gap:t,top:1/0,bottom:-1/0,leftYs:[],rightYs:[],track:-1,x:0}}function F(e,t,n){(t===`left`?e.leftYs:e.rightYs).push(n),e.top=Math.min(e.top,n),e.bottom=Math.max(e.bottom,n)}function I(e){return e.busKey?`bus|${e.busKey}`:`wire|${e.wire.id}|target`}function xt(e,t){let n=new Map,r=(e,t)=>{let r=n.get(e);if(r)return r;let i=bt(e,t);return n.set(e,i),i},i=new Set;for(let n of e){if(n.shape===`straight`)continue;let e=t.columnIndexByBoxId.get(n.from.id)??0,a=t.columnIndexByBoxId.get(n.to.id)??0,o=n.exitSide===`right`&&n.entrySide===`left`,s=r(I(n),n.targetGap);if(n.shape===`channel`&&F(s,yt(n.targetGap,e),n.start.y),n.shape===`long`){let t=r(`wire|${n.wire.id}|source`,n.sourceGap);F(t,yt(n.sourceGap,e),n.start.y),F(t,o?`right`:`left`,n.crossingY),F(s,o?`left`:`right`,n.crossingY)}i.has(s.key)||(i.add(s.key),F(s,yt(n.targetGap,a),n.end.y))}return n}function St(e,t){return e.filter(e=>e>t.top&&e<t.bottom).length}function Ct(e,t){return St(t.leftYs,e)+St(e.rightYs,t)}function wt(e,t){let n=t.map(()=>0),r=N([...e.values()].filter(e=>e.bottom>e.top),e=>e.gap);for(let[e,i]of r){let r=[...i].sort((e,t)=>Ct(e,t)-Ct(t,e)||e.top-t.top||e.key.localeCompare(t.key)),a=_t(r,(e,t)=>e.top<t.bottom+De&&t.top<e.bottom+De),o=Math.max(...a)+1;n[e]=o;let s=t[e]??{left:0,right:0};r.forEach((e,t)=>{e.track=a[t]??0,e.x=Math.round(s.left+(s.right-s.left)*(e.track+1)/(o+1))})}for(let n of e.values()){if(n.track>=0)continue;let e=t[n.gap]??{left:0,right:0};n.x=Math.round((e.left+e.right)/2)}return n}function Tt(e){let t=e.filter((t,n)=>{let r=e[n-1];return!r||r.x!==t.x||r.y!==t.y});return t.filter((e,n)=>{let r=t[n-1],i=t[n+1];return!r||!i||!(r.x===e.x&&e.x===i.x||r.y===e.y&&e.y===i.y)})}function Et(e){return e.slice(1).flatMap((t,n)=>{let r=e[n];return r?[{from:r,to:t}]:[]})}function Dt(e){if(e.start.x===e.end.x)return[e.start,e.end];let t=Math.round((e.start.y+e.end.y)/2);return[e.start,{x:e.start.x,y:t},{x:e.end.x,y:t},e.end]}function Ot(e,t){if(e.shape===`straight`)return Dt(e);let n=t.get(I(e))?.x??e.end.x,r=e.shape===`long`?e.crossingY:e.start.y,i=t.get(`wire|${e.wire.id}|source`)?.x??n,a=e.shape===`long`?[e.start,{x:i,y:e.start.y},{x:i,y:r},{x:n,y:r}]:[e.start,{x:n,y:r}];return e.busKey?a:[...a,{x:n,y:e.end.y},e.end]}function kt(e){return e.map((e,t)=>`${t===0?`M`:`L`} ${e.x} ${e.y}`).join(` `)}function At(e,t){let n=new Map;for(let t of[...e].sort((e,t)=>e.wire.id.localeCompare(t.wire.id)))t.busKey&&!n.has(t.busKey)&&n.set(t.busKey,t.wire.id);return e.map(e=>{let r=Tt(Ot(e,t)),i=e.busKey?t.get(I(e)):void 0,a=e.busKey!==null&&n.get(e.busKey)===e.wire.id,o=i&&a?[{from:{x:i.x,y:i.top},to:{x:i.x,y:i.bottom}},{from:{x:i.x,y:e.end.y},to:e.end}].filter(e=>e.from.x!==e.to.x||e.from.y!==e.to.y):[];return{plan:e,points:r,trunk:o,segments:[...Et(r),...o]}})}function L(e){return e.from.y===e.to.y}function jt(e,t){let n=t.x+t.width,r=t.y+t.height;if(L(e)){let i=e.from.y;return t.y<i&&i<r&&Math.min(e.from.x,e.to.x)<n&&Math.max(e.from.x,e.to.x)>t.x}let i=e.from.x;return t.x<i&&i<n&&Math.min(e.from.y,e.to.y)<r&&Math.max(e.from.y,e.to.y)>t.y}function Mt(e,t){return e.x<t.x+t.width&&t.x<e.x+e.width&&e.y<t.y+t.height&&t.y<e.y+e.height}function Nt(e){return Math.ceil(e.length*Pe)}function Pt(e,t){return{x:e.x-t/2,y:e.y-A,width:t,height:13}}function Ft(e){return Math.abs(e.from.x-e.to.x)+Math.abs(e.from.y-e.to.y)}function It(e,t){let n=[...e].sort((e,t)=>Ft(t)-Ft(e));return[...e.slice(0,1),...n].flatMap(e=>[...Be.flatMap(n=>{let r=e.from.x+(e.to.x-e.from.x)*n,i=e.from.y+(e.to.y-e.from.y)*n;return L(e)?[{x:r,y:i-k},{x:r,y:i+k+A}]:[{x:r+k+t/2,y:i+A/2},{x:r-k-t/2,y:i+A/2}]}),...Lt(e,t)])}function Lt(e,t){if(!L(e))return[];let n=e.from.y;return[Math.min(e.from.x,e.to.x)+k+t/2,Math.max(e.from.x,e.to.x)-k-t/2].flatMap(e=>[{x:e,y:n-k},{x:e,y:n+k+A}])}function Rt(e,t){return{x:e.x-t,y:e.y-t,width:e.width+t*2,height:e.height+t*2}}function zt(e,t,n){let r=new Map,i=e.flatMap(e=>e.segments),a=[...t.boxesById.values(),...t.obstacles];for(let o of e){let e=o.plan.wire.label;if(!e)continue;let s=Nt(e),c=It(o.segments,s),l=c.find(e=>{let n=Pt(e,s);if(n.y<t.contentTop)return!1;let o=Rt(n,Fe);return i.some(e=>jt(e,o))||a.some(e=>Mt(n,e))?!1:![...r.values()].some(e=>Mt(n,e.bounds))}),u=l??c[0]??P(o.plan.from);l||n.push(`wire ${o.plan.wire.id} label "${e}" has no clear spot`),r.set(o.plan.wire.id,{at:{x:Math.round(u.x),y:Math.round(u.y)},bounds:Pt(u,s)})}return r}function Bt(e,t,n){return e>Math.min(t,n)+.5&&e<Math.max(t,n)-.5}function Vt(e,t){if(L(e)===L(t))return!1;let n=L(e)?e:t,r=n===e?t:e;return Bt(r.from.x,n.from.x,n.to.x)&&Bt(n.from.y,r.from.y,r.to.y)}function Ht(e,t){if(L(e)!==L(t))return!1;let n=L(e),r=e=>n?e.from.y:e.from.x,i=e=>Math.min(n?e.from.x:e.from.y,n?e.to.x:e.to.y),a=e=>Math.max(n?e.from.x:e.from.y,n?e.to.x:e.to.y);return r(e)===r(t)&&Math.min(a(e),a(t))-Math.max(i(e),i(t))>1}function Ut(e,t){return e.plan.styleKey===t.plan.styleKey&&e.plan.start.x===t.plan.start.x&&e.plan.start.y===t.plan.start.y}function Wt(e){return e.flatMap((t,n)=>e.slice(n+1).flatMap(e=>{if(t.plan.busKey!==null&&t.plan.busKey===e.plan.busKey)return[];let n=t.segments.flatMap(t=>e.segments.map(e=>[t,e]));return n.some(([e,t])=>Vt(e,t))?[`wire ${t.plan.wire.id} crosses wire ${e.plan.wire.id}`]:Ut(t,e)?[]:n.some(([e,t])=>Ht(e,t))?[`wire ${t.plan.wire.id} overlaps wire ${e.plan.wire.id}`]:[]}))}function Gt(e,t){let n=[...t.boxesById.values()];return e.flatMap(e=>n.flatMap(t=>{if(t.id===e.plan.from.id||t.id===e.plan.to.id)return[];let n=Rt(t,-2);return e.segments.some(e=>jt(e,n))?[`wire ${e.plan.wire.id} runs through box ${t.id}`]:[]}))}function Kt(t){if(t.length<=e.layoutWarnings)return[...t];let n=t.slice(0,e.layoutWarnings-1);return[...n,`and ${t.length-n.length} more`]}function qt(e,t){let n=t.map(()=>0);for(let t of e)t.wire.label&&t.shape===`channel`&&(n[t.targetGap]=Math.max(n[t.targetGap]??0,Nt(t.wire.label)));return n}function Jt(e,t){return nt([...e.flatMap(e=>e.segments.flatMap(e=>[e.from,e.to])).map(e=>({x:e.x,y:e.y,width:0,height:0})),...t])}function Yt(e,t,n,r){dt(n,r);let i=vt(e,t),a=xt(e,t),o=wt(a,t.gaps),s=At(e,a);return{runsByKey:a,tracksByGap:o,topTrackCount:i,drawn:s,crossingCost:Gt(s,t).length*Ie+Wt(s).length}}function Xt(e,t){let n=e[t],r=e[t+1];n!==void 0&&r!==void 0&&(e[t]=r,e[t+1]=n)}function Zt(e,t){let n=lt(e),r=ut(n),i=Yt(e,t,n,r).crossingCost,a=e.length<=Le;for(let o of r.values())for(let s=0;a&&i>0&&s+1<o.length;s+=1){Xt(o,s);let a=Yt(e,t,n,r).crossingCost;a<i?i=a:Xt(o,s)}return Yt(e,t,n,r)}function Qt(e){let t=st(e),{runsByKey:n,tracksByGap:r,topTrackCount:i,drawn:a}=Zt(t,e),o=[],s=zt(a,e,o),c=a.map(({plan:e,points:t,trunk:r})=>{let i=t.at(-1)??e.end,a=e.busKey?n.get(I(e)):void 0,o=r.length>0,c=a!==void 0&&i.y>a.top&&i.y<a.bottom;return{kind:`wire`,id:e.wire.id,path:[kt(t),...r.map(e=>kt([e.from,e.to]))].join(` `),start:e.start,end:o||!e.busKey?e.end:i,label:e.wire.label,labelAt:s.get(e.wire.id)?.at??P(e.from),isDashed:e.wire.dashed,strokeHex:e.strokeHex,tone:e.wire.tone,hasArrowhead:e.busKey===null||o,joinAt:c?i:null}}),l=[...s.values()].map(e=>e.bounds);return{wires:c,tracksByGap:r,topTrackCount:i,labelWidthByGap:qt(t,e.gaps),warnings:Kt([...Gt(a,e),...Wt(a),...o]),extent:Jt(a,l)}}function $t(e){return e.resolvedBy?`resolved by ${e.resolvedBy}`:e.author?`from ${e.author}`:``}function en(e,t){let n=new Map;return M(e,`note`).flatMap(e=>{let r=t.get(e.on);if(!r)return[];let{lines:i,height:a}=We(e),o=n.get(e.on)??r.y-we;return n.set(e.on,o+a+_e),[{kind:`note`,id:e.id,x:r.x+r.width-Ce,y:o,width:me,height:a,lines:i,byline:$t(e),isResolved:e.resolvedBy!==null}]})}function tn(e,t,n,r){let i=e.flatMap(e=>e.kind===`wire`?[]:[e]),a=(n.at(-1)??S)+C,o=nt([...i,...t?[t]:[],{x:0,y:0,width:a,height:r}]);return o?{x:Math.min(0,o.x-S),y:Math.min(0,o.y-S),width:o.width+80,height:o.height+80}:{x:0,y:0,width:a+S,height:80}}function nn(e,t){let n=Xe(e,t.gapWidths),r=tt(e,n,t.boxesTop,t.stackHeightByBoxId),i=rt(e,r),a=en(e,r),o=new Map(M(e,`box`).flatMap(t=>{let i=r.get(t.id);return i?[[t.id,Qe(e,t,i,n)]]:[]}));return{columnLeftEdges:n,boxesById:r,frames:i,notes:a,routing:Qt({wires:M(e,`wire`),boxesById:r,columnIndexByBoxId:o,obstacles:[...a,...i.map(e=>({x:e.x,y:e.y,width:e.width,height:D}))],gaps:Ze(n,t.gapWidths,t.reserves),topBandBottom:t.boxesTop-Ne,contentTop:t.contentTop})}}function rn(e,t){return Array.from({length:Math.max(e.length,t.length)},(n,r)=>Math.max(e[r]??0,t[r]??0))}function an(e,t,n){let r=t.tracksByGap,i=t.topTrackCount;for(let a=1;;a+=1){let o=Ye(n.reserves,r,t.labelWidthByGap),s=n.headerBoxesTop+fn(i),c=nn(e,{gapWidths:o,reserves:n.reserves,boxesTop:s,contentTop:n.contentTop,stackHeightByBoxId:n.stackHeightByBoxId}),l=c.routing.topTrackCount>i,u=c.routing.tracksByGap.some((e,t)=>e>(r[t]??0));if(a>=Re||!l&&!u)return{placed:c,boxesTop:s};i=Math.max(i,c.routing.topTrackCount),r=rn(r,c.routing.tracksByGap)}}function on(e){let t=j(e.title,T),n=e.lines.flatMap(e=>j(e.text,pe)),r=+!!e.linkedBoardId;return{titleLines:t,bodyLines:n,height:42+t.length*de+(n.length+r)*fe}}function sn(e){let t=new Map,n=new Map;for(let r of m(e)){let i=e.elements[r.unitId];if(i?.kind!==`unit`)continue;let a=on(i),o=n.get(r.level)??70;n.set(r.level,o+a.height+ue),t.set(i.id,{kind:`unit`,id:i.id,x:S+(r.level-1)*310,y:o,width:C,height:a.height,label:r.label,titleLines:a.titleLines,bodyLines:a.bodyLines,linkedBoardId:i.linkedBoardId})}return t}function cn(e,t){let n={x:e.x+e.width,y:e.y+Math.round(e.height/2)},r={x:t.x,y:t.y+Math.round(t.height/2)},i=t.x-Math.round(w/2);return kt(Tt([n,{x:i,y:n.y},{x:i,y:r.y},r]))}function ln(e,t){return M(e,`unit`).flatMap(e=>{let n=t.get(e.id);return n?e.after.flatMap(e=>{let r=t.get(e);return r?[cn(r,n)]:[]}):[]})}function un(e){return e.size===0?S:Math.max(...[...e.values()].map(e=>e.y+e.height))+ze}function dn(e,t){if(t===0)return e;let n=Object.fromEntries(Object.entries(e.elements).map(([e,n])=>n.kind!==`box`||!n.at?[e,n]:[e,{...n,at:{x:n.at.x,y:n.at.y+t}}]));return{...e,elements:n}}function fn(e){return e>0?e*Me+Ne:0}function pn(e){let t=sn(e),n=un(t),r=n-S,i=dn(e,r),a=Ge(i),o=Ke(i),s=qe(o),c=n+Se+s,l=n+le+s,u=Je(i,a),{placed:d,boxesTop:f}=an(i,nn(i,{gapWidths:Ye(u,[],[]),reserves:u,boxesTop:l,contentTop:c,stackHeightByBoxId:a}).routing,{reserves:u,headerBoxesTop:l,contentTop:c,stackHeightByBoxId:a}),{columnLeftEdges:p}=d,m=[...d.frames,...d.routing.wires,...d.boxesById.values(),...d.notes,...t.values()],h=tn(m,d.routing.extent,p,f),g=h.y+h.height,_=i.lanes.map((e,t)=>({label:e.label||e.id,hex:Ve[e.color],x:S,y:g+t*ve})),v=g+_.length*ve+(_.length>0?12:0),y=i.caption?{text:i.caption,x:S,y:v}:null,ee=_.length*ve+(y?30:0)+(_.length>0?12:0);return{columns:i.columns.map((e,t)=>({id:e.id,titleLines:o[t]??[],titleBaselineY:n+xe,ruleY:c,x:p[t]??S,width:C})),elements:m,legend:_,caption:y,pinnedOffsetY:r,plan:t.size>0?{titleAt:{x:S,y:56},arrowPaths:ln(i,t)}:null,bounds:{...h,height:h.height+ee},warnings:d.routing.warnings}}function mn(e){return JSON.stringify(e)}var hn=`http://www.w3.org/2000/svg`,R=12,gn=26,_n=20,vn=18,yn=17,bn=14,xn=16,Sn=24,Cn=18,wn=`Plan`,Tn=`open linked board`;function z(e,t={},n=``){let r=document.createElementNS(hn,e);for(let[e,n]of Object.entries(t))r.setAttribute(e,String(n));return n&&r.setAttribute(`class`,n),r}function B(e,t,n,r){let i=z(`text`,{x:t,y:n},r);return i.textContent=e,i}function V(e,t){let n=z(`g`,{},`wb-element ${t}`);return n.dataset.elementId=e.id,n.dataset.elementKind=e.kind,n}function En(e){let t=V(e,e.isGhost?`wb-box wb-ghost`:`wb-box`),n=z(`rect`,{x:e.x,y:e.y,width:e.width,height:e.height,rx:8},`wb-box-outline`);e.lane&&(n.style.stroke=e.lane.hex),t.append(n),e.titleLines.forEach((n,r)=>{t.append(B(n,e.x+R,e.y+gn+r*_n,`wb-box-title`))});let r=e.y+gn+e.titleLines.length*_n;if(e.bodyLines.forEach((n,i)=>{let a=e.x+R+(n.muted?bn:0);t.append(B(n.text,a,r+i*vn,n.muted?`wb-box-line wb-muted`:`wb-box-line`))}),!e.lane)return t;let i=e.y+e.height-28,a=Math.min(e.width-24,16+e.lane.label.length*8),o=z(`rect`,{x:e.x+R,y:i,width:a,height:18,rx:9},`wb-lane-pill`);o.style.stroke=e.lane.hex;let s=B(e.lane.label,e.x+R+8,i+13,`wb-lane-pill-text`);return s.style.fill=e.lane.hex,t.append(o,s),t}function Dn(e){let t=V(e,`wb-frame`);return t.append(z(`rect`,{x:e.x,y:e.y,width:e.width,height:e.height,rx:12},`wb-frame-outline`),B(e.title,e.x+14,e.y+18,`wb-frame-title`)),t}function On(e){let t=V(e,`wb-wire wb-tone-${e.tone}`),n=z(`path`,{d:e.path},`wb-wire-hit`),r=z(`path`,e.hasArrowhead?{d:e.path,"marker-end":`url(#wb-arrow)`}:{d:e.path},e.isDashed?`wb-wire-line wb-dashed`:`wb-wire-line`);return e.strokeHex&&(r.style.stroke=e.strokeHex),t.append(n,r,z(`circle`,{cx:e.start.x,cy:e.start.y,r:3},`wb-wire-dot`)),e.joinAt&&t.append(z(`circle`,{cx:e.joinAt.x,cy:e.joinAt.y,r:3},`wb-wire-dot`)),e.label&&t.append(B(e.label,e.labelAt.x,e.labelAt.y,`wb-wire-label`)),t}function kn(e){let t=V(e,e.isResolved?`wb-note wb-resolved`:`wb-note`);return t.append(z(`rect`,{x:e.x,y:e.y,width:e.width,height:e.height,rx:4},`wb-note-card`)),e.lines.forEach((n,r)=>{t.append(B(n,e.x+10,e.y+22+r*yn,`wb-note-text`))}),e.byline&&t.append(B(e.byline,e.x+10,e.y+22+e.lines.length*yn,`wb-note-byline`)),t}function An(e){let t=V(e,`wb-unit`);t.append(z(`rect`,{x:e.x,y:e.y,width:e.width,height:e.height,rx:8},`wb-unit-outline`),B(e.label,e.x+R,e.y+Sn,`wb-unit-label`));let n=e.y+Sn+Cn;e.titleLines.forEach((r,i)=>{t.append(B(r,e.x+R,n+i*_n,`wb-box-title`))});let r=n+e.titleLines.length*_n;if(e.bodyLines.forEach((n,i)=>{t.append(B(n,e.x+R,r+i*vn,`wb-box-line`))}),!e.linkedBoardId)return t;let i=B(Tn,e.x+R,r+e.bodyLines.length*vn,`wb-unit-link`);return i.dataset.linkedBoardId=e.linkedBoardId,t.append(i),t}var jn={frame:`frames`,wire:`wires`,box:`boxes`,note:`notes`,unit:`units`},Mn=[`box`,`frame`,`wire`,`note`,`unit`];function Nn(e){switch(e.kind){case`box`:return En(e);case`frame`:return Dn(e);case`wire`:return On(e);case`note`:return kn(e);case`unit`:return An(e)}}function Pn(e){let t=z(`g`,{},`wb-chrome`);if(e.plan){t.append(B(wn,e.plan.titleAt.x,e.plan.titleAt.y,`wb-column-title`));for(let n of e.plan.arrowPaths)t.append(z(`path`,{d:n,"marker-end":`url(#wb-arrow)`},`wb-wire-line`))}for(let n of e.columns)n.titleLines.length!==0&&(n.titleLines.forEach((e,r)=>{t.append(B(e,n.x,n.titleBaselineY+r*xn,`wb-column-title`))}),t.append(z(`line`,{x1:n.x,y1:n.ruleY,x2:n.x+n.width,y2:n.ruleY},`wb-column-rule`)));for(let n of e.legend){let e=z(`rect`,{x:n.x,y:n.y,width:14,height:14,rx:3},`wb-legend-swatch`);e.style.fill=n.hex,t.append(e,B(n.label,n.x+22,n.y+12,`wb-legend-text`))}return e.caption&&t.append(B(e.caption.text,e.caption.x,e.caption.y+16,`wb-caption`)),t}function Fn(){let e=z(`defs`),t=z(`marker`,{id:`wb-arrow`,viewBox:`0 0 10 10`,refX:9,refY:5,markerWidth:8,markerHeight:8,orient:`auto-start-reverse`});return t.append(z(`path`,{d:`M 0 1 L 10 5 L 0 9 z`,fill:`context-stroke`})),e.append(t),e}function In(e){let t={frames:z(`g`,{},`wb-layer`),wires:z(`g`,{},`wb-layer`),boxes:z(`g`,{},`wb-layer`),notes:z(`g`,{},`wb-layer`),units:z(`g`,{},`wb-layer`)},n=z(`g`);e.replaceChildren(Fn(),n,t.frames,t.wires,t.boxes,t.notes,t.units);let r=new Map,i=null,a=new Set;function o(e,t){t.classList.toggle(`is-selected`,a.has(e))}function s(e){let a=pn(e),s=Pn(a);n.replaceWith(s),n=s;let c=new Set;for(let e of a.elements){c.add(e.id);let n=mn(e),i=r.get(e.id);if(i?.signature===n)continue;let a=Nn(e);o(e.id,a),i&&i.node.replaceWith(a),i||t[jn[e.kind]].append(a),r.set(e.id,{signature:n,node:a})}for(let[e,t]of r)c.has(e)||(t.node.remove(),r.delete(e));return i=a,a}function c(e){if(!(e instanceof Element))return null;let t=e.closest(`.wb-element`),n=t?.dataset.elementId,r=Mn.find(e=>e===t?.dataset.elementKind);return!n||!r?null:{id:n,kind:r}}function l(e){a=e;for(let[e,t]of r)o(e,t.node)}function u(){for(let e of r.values())e.node.remove();r.clear();let e=z(`g`);n.replaceWith(e),n=e,i=null}return{render:s,layout:()=>i,elementFromTarget:c,nodeOf:e=>r.get(e)?.node??null,setSelection:l,clear:u}}var Ln=`http://www.w3.org/2000/svg`,Rn=`No boards yet. Make one here, or have an agent run glimmervoid whiteboard new <title>.`,zn=`Pick a board above.`,H=null,U=null,W=null,G=null,Bn=!0,K=null,q=i(`action-status wb-status`),J=i(`action-status wb-status`);function Y(e){let{dialog:n,close:r,actions:i,btnCancel:a}=o({title:e.title}),s=t(`input`,`dialog-input`);s.type=`text`,s.placeholder=e.placeholder,s.maxLength=e.maxLength,s.value=e.initialValue??``,s.autocomplete=`off`,s.setAttribute(`aria-label`,e.label);let c=t(`div`,`dialog-error`);c.setAttribute(`role`,`alert`);let l=e.choices?t(`select`,`dialog-input wb-dialog-select`):null;if(l&&e.choices){l.setAttribute(`aria-label`,e.choices.label);for(let n of e.choices.options){let e=t(`option`,null,n.text);e.value=n.value,l.append(e)}}let u=t(`button`,`btn-dialog btn-dialog-confirm`,e.confirmLabel);u.type=`button`,i.append(u),n.append(t(`label`,`dialog-label`,e.label),s,...l?[l]:[],c,i);async function d(){let t=s.value.trim();if(!t){c.textContent=`${e.label} is empty.`;return}u.disabled=!0;let n=await e.onSubmit(t,l?.value??null);u.disabled=!1,n?c.textContent=n:r()}a.addEventListener(`click`,r),u.addEventListener(`click`,()=>void d()),s.addEventListener(`keydown`,e=>{e.key===`Enter`&&(e.preventDefault(),d())}),requestAnimationFrame(()=>s.focus())}function X(){return H?g(H):null}function Vn(){return s().find(e=>e.id===H)??null}async function Hn(e){if(!H||e.length===0)return!1;let t=await v(H,e);return t.ok?(q.clear(),!0):(q.show(`error`,t.error),!1)}async function Un(e){if(!H)return`No board is open.`;let t=await v(H,e);return t.ok?null:t.error}function Wn(e){let t=r(e);return t?n(t):`closed session`}function Z(e){let t=X();return[...G?.selectedIds()??new Set].flatMap(e=>t?.elements[e]??[]).filter(t=>t.kind===e)}function Gn(){if(!U)return;let e=X(),t=Z(`box`).length,n=G?.selectedIds().size??0;U.buttons.box.disabled=!e,U.buttons.wire.disabled=t!==2,U.buttons.note.disabled=t!==1,U.buttons.frame.disabled=t===0,U.buttons.unit.disabled=!e,U.buttons.fit.disabled=!e,U.buttons.remove.disabled=!e,U.toolbar.dataset.selectedCount=String(n)}function Kn(){if(!U)return;let e=s();H&&!e.some(e=>e.id===H)&&(H=null),!H&&e[0]&&Q(e[0].id),U.list.replaceChildren(...e.map(e=>{let n=t(`button`,`wb-board-tab`,e.title);return n.type=`button`,n.setAttribute(`aria-pressed`,String(e.id===H)),e.connectedSessionIds.length>0&&n.append(t(`span`,`wb-board-tab-count`,String(e.connectedSessionIds.length))),n.addEventListener(`click`,()=>Q(e.id)),n})),qn()}function qn(){if(!U)return;let e=Vn(),n=s().length>0;U.boardHead.hidden=!e,U.canvas.hidden=!e,U.empty.hidden=!!e,U.empty.textContent=n?zn:Rn,e&&(U.boardMeta.textContent=`v${e.version}`,U.presence.replaceChildren(...e.connectedSessionIds.map(e=>t(`span`,`wb-presence-pill`,Wn(e)))),e.connectedSessionIds.length===0&&U.presence.append(t(`span`,`wb-presence-none`,`no sessions connected`)),Gn(),Yn())}function Jn(e,t){let n=Wn(t);if(!e?.connectedSessionIds.includes(t))return`${n} is not connected to this board`;let r=e.queuedBySessionId[t]??0;return r===0?`${n} has read every change`:`${r} board ${r===1?`edit`:`edits`} queued for ${n}`}function Yn(){if(!U||!K)return;let e=Vn();U.dockQueued.textContent=Jn(e,K),U.sendToAgent.disabled=!e?.connectedSessionIds.includes(K)}async function Xn(){if(!U||!H||!K)return;U.sendToAgent.disabled=!0,J.show(`busy`,`sending`);let e=await h(H,K);Yn(),e.ok?J.show(`ok`,`sent; the agent reads the board when it is ready`):J.show(`error`,e.error)}function Zn(){if(!W)return;let e=X();e?(W.render(e),G?.pruneSelection(e),Bn&&=(G?.fit(),!1),Gn()):W.clear()}function Q(e){H!==e&&(H=e,Bn=!0,G?.clearSelection(),G?.closeTitleInput(),W?.clear(),q.clear(),Kn(),l(e).then(Zn))}function Qn(){let t=X();if(!t)return;let n=Z(`box`)[0],r=t.columns.map(e=>({value:e.id,text:e.title||e.id})),i=n?.column;i&&r.sort((e,t)=>Number(t.value===i)-Number(e.value===i)),Y({title:`Add a box`,label:`Box title`,placeholder:`parse the feed`,maxLength:e.title,confirmLabel:`Add box`,choices:r.length>1?{label:`Column`,options:r}:void 0,onSubmit:(e,t)=>Un([{op:`add`,element:{kind:`box`,id:b(`box`),title:e,column:t??r[0]?.value??`main`,lines:[],lane:null,ghost:!1,order:0,at:null}}])})}function $n(){let t=X();if(!t)return;let n=s().filter(e=>e.id!==t.id),r=[{value:``,text:`No linked board`},...n.map(e=>({value:e.id,text:e.title}))];Y({title:`Add a unit`,label:`Unit title`,placeholder:`index the diffs`,maxLength:e.title,confirmLabel:`Add unit`,choices:n.length>0?{label:`Linked board`,options:r}:void 0,onSubmit:(e,t)=>Un([{op:`add`,element:{kind:`unit`,id:b(`unit`),title:e,lines:[],after:[],linkedBoardId:t||null}}])})}function er(t){Y({title:`Pin a note`,label:`Note`,placeholder:`what about retries?`,maxLength:e.noteText,confirmLabel:`Pin note`,onSubmit:e=>Un([{op:`add`,element:{kind:`note`,id:b(`note`),on:t,text:e,author:``,resolvedBy:null}}])})}function tr(){let[e,t]=Z(`box`);e&&t&&(G?.clearSelection(),Hn([{op:`add`,element:{kind:`wire`,id:b(`wire`),from:e.id,to:t.id,dashed:!1,tone:`plain`,label:null}}]))}function nr(){let t=Z(`box`).map(e=>e.id);t.length!==0&&Y({title:`Frame the selected boxes`,label:`Frame title`,placeholder:`intake`,maxLength:e.title,confirmLabel:`Add frame`,onSubmit:async e=>{let n=await Un([{op:`add`,element:{kind:`frame`,id:b(`frame`),title:e,contains:t}}]);return n||G?.clearSelection(),n}})}function rr(){let e=Vn();if(!e)return;let t=e.connectedSessionIds.map(Wn),n=t.length>0?` ${t.join(`, `)} ${t.length===1?`is`:`are`} connected and will lose it.`:``;a({title:`Delete board`,message:`Delete "${e.title}" for good?${n}`,confirmLabel:`Delete board`,danger:!0,onConfirm:()=>{y(e.id).then(e=>{e.ok||q.show(`error`,e.error)})}})}function ir(){Y({title:`New board`,label:`Board title`,placeholder:`knowledge writer`,maxLength:e.title,confirmLabel:`Create board`,onSubmit:async e=>{let t=await f(e);return t.ok?(Q(t.boardId),null):t.error}})}function $(e,n,r=``){let i=t(`button`,`wb-button ${r}`.trim(),e);return i.type=`button`,i.addEventListener(`click`,n),i}function ar(e){let n=t(`div`,`wb-top`),r=t(`div`,`wb-board-list`);r.setAttribute(`aria-label`,`Boards`);let i=t(`div`,`wb-board-head`),a=t(`div`,`wb-title-row`),o=t(`span`,`wb-board-meta`),s=t(`div`,`wb-presence`);a.append(o,s);let c=t(`div`,`wb-toolbar`),l={box:$(`box`,Qn),wire:$(`wire`,tr),note:$(`note`,()=>{let[e]=Z(`box`);e&&er(e.id)}),frame:$(`frame`,nr),unit:$(`unit`,$n),fit:$(`fit`,()=>G?.fit()),remove:$(`delete board`,rr,`wb-button-danger`)};l.fit.dataset.phoneVisible=``,c.append(l.box,l.wire,l.note,l.frame,l.unit,l.fit,l.remove,q.element),i.append(a,c),n.append(r,$(`new board`,ir),i);let u=t(`div`,`wb-canvas`),d=document.createElementNS(Ln,`svg`);d.setAttribute(`class`,`wb-svg`),d.setAttribute(`role`,`img`),d.setAttribute(`aria-label`,`Whiteboard`),d.setAttribute(`preserveAspectRatio`,`xMidYMin meet`),u.append(d);let f=t(`p`,`wb-empty`,Rn),m=t(`div`,`wb-dock`);m.hidden=!0;let h=t(`span`,`wb-dock-queued`),g=$(`send to agent`,()=>void Xn()),v=t(`div`,`wb-dock-bar`);v.append(h,g,J.element),m.append(v),e.replaceChildren(n,u,f,m),U={list:r,boardHead:i,boardMeta:o,presence:s,toolbar:c,canvas:u,empty:f,dock:m,dockQueued:h,sendToAgent:g,buttons:l};let y=In(d);W=y,G=ce({svg:d,canvas:u,renderer:y,currentBoard:X,sendOps:Hn,onSelectionChange:Gn,onPhoneTapBox:er,onOpenLinkedBoard:Q}),p(Kn),_(e=>{e===H&&Zn()}),Kn()}function or(){return document.documentElement.dataset.layout===`phone`}function sr(){K&&u()===K&&ee(),K=null,U&&(U.dock.hidden=!0)}function cr(e){if(!U||or())return;let t=r(e);t&&(K=e,U.dock.hidden=!1,J.clear(),Yn(),te(t,e,U.dock,{className:`wb-docked-card`}),c(t,e,!0))}function lr(){let e=d();e&&(Q(e.boardId),e.dockSessionId&&cr(e.dockSessionId)),Kn(),H&&l(H).then(Zn)}var ur={mount:ar,refresh:lr,deactivate:sr};export{ur as view};
@@ -1 +1 @@
1
- import{b as e,d as t,f as n,s as r}from"./dom-helpers-DBbFg1c_.js";import{d as i,u as a}from"./control-ws-2skDxNtN.js";import{o}from"./card-registry-D5EJa_tx.js";import{c as s,i as c,s as ee,t as l}from"./action-status-Cmp0b1QX.js";import{i as u}from"./modal-USMHOKBI.js";import{Bt as d,Ct as f,Dt as p,Lt as m,Nt as h,Pt as g,Qr as _,Rt as v,St as y,Vt as b,Zr as te,_ as ne,bt as x,dn as re,fn as ie,j as ae,jt as oe,lt as se,m as ce,vt as le,wt as ue,x as de,xt as fe,yt as pe}from"./index-k2H9o6FW.js";import{t as me}from"./team-review-panel-BY5YWeyD.js";import{t as he}from"./pr-queue-columns-WDQqbW0O.js";import{n as S}from"./setup-step-D0y3riKj.js";var ge={HIGH:`High confidence`,MEDIUM:`Medium confidence`,LOW:`Low confidence`},_e={HIGH:`ok`,MEDIUM:`warn`,LOW:`muted`},C={queued:`Waiting to be researched`,running:`Researching`,error:`Research failed`,aside:`Set aside`},ve={forum:`Forum`,discord:`Discord`};function w(e){return e.status===`ready`&&e.verdict?{text:ge[e.verdict],tone:_e[e.verdict]}:e.status===`ready`?{text:`Researched`,tone:`muted`}:e.status===`error`?{text:C.error,tone:`danger`}:{text:C[e.status],tone:`muted`}}function T(e){let t=ve[e.item.source];return e.item.channel?`${t} #${e.item.channel}`:t}function E(e){return e.entry.item.title||`Untitled question`}function ye(e){return e.status!==`running`&&e.status!==`queued`}function be(e){return e.status!==`aside`}function xe(e){let t=e.find(e=>e.id===`working`)?.items.length??0;return t===0?`No community question needs you right now.`:`No community question needs you right now. ${t} ${t===1?`question is`:`questions are`} being researched.`}function D(e){return e?e.configured===!1?e.reason??`The community lane is not set up yet.`:`No community questions yet. New ones asked after you turned this on show up here.`:`Waiting for the community lane to report.`}function Se(e){return e.filter(e=>!e.isWorkspace&&!e.isEphemeral).map(({id:e,name:t})=>({id:e,name:t})).toSorted((e,t)=>e.name.localeCompare(t.name))}var O=[`key`,`project`,`skill`,`discord`];function Ce(e){let t=e===`finished`?O.length:O.indexOf(e),n=e=>e<t?`done`:e===t?`current`:`upcoming`;return{key:n(0),project:n(1),skill:n(2),discord:n(3)}}function we(e){let t=e.split(/[\s,]+/).map(e=>e.replace(/^#/,``)).filter(Boolean);return[...new Set(t)]}var k=2;function A(e){a({type:`dashboard-telemetry`,event:`operator_action`,properties:{surface:`onboarding`,action:e}})}function j(){let e=ae().community,t=typeof e==`object`&&e?e:{},n=Array.isArray(t.discordChannels)?t.discordChannels.filter(e=>typeof e==`string`):[];return{projectId:typeof t.projectId==`number`?t.projectId:k,skill:typeof t.skill==`string`?t.skill:``,discordChannels:n}}function Te(e,t,n,i){let a=r(`input`,`dialog-input repo-roots-adder-input`);return a.id=e,a.type=i,a.value=t,a.placeholder=n,a.autocomplete=`off`,a.spellcheck=!1,a}function M(e,t){let n=r(`button`,`btn-dialog btn-dialog-${t}`,e);return n.type=`button`,n}function Ee({onFinish:e}){let t=r(`section`,`first-run-checklist review-setup`);t.setAttribute(`aria-labelledby`,`community-setup-title`);let n=r(`h2`,`first-run-title`,`Answer community questions`);n.id=`community-setup-title`;let a=r(`ol`,`first-run-steps`),o=r(`p`,`first-run-step-hint review-setup-foot`,`Each question gets a researched draft reply. Nothing posts until you post it yourself. `);o.append(ne(`lanes-community`,`community-enabled`,`All community settings`));let s=r(`div`,`first-run-step-actions`),u=M(`Finish setup`,`confirm`);s.append(u),s.hidden=!0,t.append(r(`span`,`first-run-eyebrow`,`SET UP COMMUNITY`),n,a,s,o);let d=null;u.addEventListener(`click`,()=>{A(`finish-community-setup`),d=null,e()});function f(e){d=e,y(),(a.querySelector(`[aria-current="step"] input`)??(s.hidden?null:u))?.focus()}async function p(e,t,n,r){t.disabled=!0,n.show(`busy`,`Saving`);try{let t=await i(`update-settings`,{settings:e},{timeoutMs:l});if(t.type===`settings-error`){n.show(`error`,t.message);return}if(t.type!==`settings-updated`){n.show(`error`,`The server did not confirm the save.`);return}de(t.settings),f(r)}catch(e){n.show(`error`,ee(e,l))}finally{t.disabled=!1}}function m(e){let t=Te(e.inputId,e.initialValue,e.placeholder,e.inputType),n=r(`label`,`repo-roots-adder-label`,e.label);n.htmlFor=t.id;let i=r(`div`,`first-run-step-actions`),a=c(),o=M(e.saveLabel,`confirm`),s=()=>{let n=e.settingsPatch(t.value);typeof n==`string`?a.show(`error`,n):(A(e.action),p(n,o,a,e.nextProgress))};if(o.addEventListener(`click`,s),t.addEventListener(`keydown`,e=>{e.key===`Enter`&&(e.preventDefault(),s())}),i.append(o),e.isSkippable){let t=M(`Skip`,`cancel`);t.addEventListener(`click`,()=>f(e.nextProgress)),i.append(t)}return i.append(a.element),[r(`p`,`first-run-step-text`,e.advice),n,t,i]}let h=()=>m({advice:`Glimmervoid reads new forum and Discord questions through your PostHog personal API key. Create one in PostHog under Settings, Personal API keys. Community needs only the query:read scope on the project that holds the questions. PostHog error monitoring shares this key, so add error tracking read and write if you turn that on.`,label:`PERSONAL API KEY`,inputId:`community-setup-key`,inputType:`password`,initialValue:``,placeholder:`phx_`,saveLabel:`Save key`,action:`save-community-key`,nextProgress:`project`,isSkippable:!1,settingsPatch:e=>e.trim()?{posthog:{apiKey:e.trim()}}:`Paste a PostHog personal API key.`}),g=()=>m({advice:`The PostHog project that holds the synced community forum table and the Discord bot events. PostHog's own community lives in project 2.`,label:`PROJECT ID`,inputId:`community-setup-project`,inputType:`number`,initialValue:String(j().projectId),placeholder:String(k),saveLabel:`Use project`,action:`save-community-project`,nextProgress:`skill`,isSkippable:!1,settingsPatch:e=>{let t=Number(e.trim());return Number.isInteger(t)&&t>0?{community:{projectId:t}}:`Type the project id as a whole number, such as 2.`}}),_=()=>m({advice:`The Claude Code skill the research agent follows for each question, typed by name. A skill that knows your docs and support playbook gives the best drafts. Skip to research with whatever skills the agent has.`,label:`SKILL`,inputId:`community-setup-skill`,inputType:`text`,initialValue:j().skill,placeholder:`skill name`,saveLabel:`Save skill`,action:`save-community-skill`,nextProgress:`discord`,isSkippable:!0,settingsPatch:e=>({community:{skill:e.trim().replace(/^\//,``)}})}),v=()=>m({advice:`Discord questions come from a Discord bot that sends message_sent and thread_created events into the project above. With that bot in place, list the channels to watch by name, without the #. A cheap model picks out the real questions; only those are researched.`,label:`CHANNELS`,inputId:`community-setup-discord`,inputType:`text`,initialValue:j().discordChannels.join(`, `),placeholder:`community-questions, help`,saveLabel:`Save channels`,action:`save-community-discord`,nextProgress:`finished`,isSkippable:!0,settingsPatch:e=>{let t=we(e);return t.length>0?{community:{discordChannels:t}}:`Type at least one channel, or skip.`}});function y(){if(!d)return;let e=Ce(d);a.replaceChildren(S({title:`1. PostHog personal API key`,state:e.key,summary:`Key saved`,badge:`NEEDED`,body:h}),S({title:`2. PostHog project`,state:e.project,summary:`Project ${j().projectId}`,badge:``,body:g}),S({title:`3. Research skill (optional)`,state:e.skill,summary:j().skill||`No skill`,badge:``,body:_}),S({title:`4. Discord (optional)`,state:e.discord,summary:j().discordChannels.map(e=>`#${e}`).join(` `)||`Forum only`,badge:``,body:v})),s.hidden=d!==`finished`}function b(){d=`key`,y()}return{element:t,open:b,isOpen:()=>d!==null}}var N=null,P=null,F=null,I=null,L=[],R=null,z=!1,B=null,V=null,H=``,U=new Map,W=null;function De(){return Se([...o].map(([e,t])=>({id:e,name:t.nameEl.textContent??e,isWorkspace:t.card.dataset.workspace!==void 0,isEphemeral:t.card.dataset.ephemeral!==void 0})))}function G(e,t){let n=r(`button`,`pr-action pr-action-ghost`,e);return n.type=`button`,n.disabled=!_(t),n.addEventListener(`click`,()=>te(t)),n}function K(e,t,n){let i=r(`button`,`pr-action`,e);return i.type=`button`,i.disabled=!t,i.addEventListener(`click`,n),i}function q(e,t,n){let i=r(`ul`,e);i.setAttribute(`aria-label`,t);for(let e of n)i.append(r(`li`,null,e));return i}function Oe(e){let t=r(`div`,`pr-detail-heading`),n=r(`div`,`pr-detail-title`);n.append(r(`h2`,null,e.item.title||`Untitled question`));let i=r(`div`,`pr-detail-meta`),a=Date.parse(e.item.createdAt);return i.append(r(`span`,null,e.item.author),r(`span`,null,T(e))),Number.isNaN(a)||i.append(r(`span`,null,`Asked ${ce(a)}`)),t.append(n,i),t}function ke(e){let t=r(`section`,`community-question`);return t.setAttribute(`aria-label`,`Question as asked`),t.append(r(`h3`,`pr-section-heading`,`Question as asked`),r(`p`,`community-question-body`,e.item.body)),t}function Ae(e){let t=r(`section`,`pr-verdict-box`);t.setAttribute(`aria-label`,`Research`);let n=w(e),i=r(`div`,`pr-verdict-line`),a=r(`strong`,`community-badge`,n.text);if(a.dataset.tone=n.tone,i.append(a),t.append(i),e.error&&t.append(r(`p`,`pr-attention-detail`,e.error)),e.summary&&t.append(r(`p`,`pr-verdict-summary`,e.summary)),e.goal&&t.append(r(`p`,`community-goal`,`Goal: ${e.goal}`)),e.gaps.length>0&&t.append(q(`pr-verdict-gaps`,`Not covered`,e.gaps)),e.checked.length===0)return t;let o=r(`details`,`pr-verdict-checked`);return o.append(r(`summary`,null,`What it checked (${e.checked.length})`),q(`community-checked`,`What it checked`,e.checked)),t.append(o),t}function je(e){if(!e.draft)return null;let t=r(`section`,`community-draft`);t.setAttribute(`aria-label`,`Draft reply`),t.append(r(`h3`,`pr-section-heading`,`Draft reply`),r(`p`,`community-draft-body`,e.draft.body));let n=e.draft.publicLinks.filter(_);if(n.length===0)return t;let i=r(`ul`,`community-links`);for(let e of n){let t=r(`li`);t.append(G(e,e)),i.append(t)}return t.append(i),t}function Me(t,n){let r=t.draft?e(t.draft.body):null;r?r.then(()=>n.show(`ok`,`Draft copied. Post it yourself where the question was asked.`),()=>n.show(`error`,`Copying failed. Select the draft text instead.`)):n.show(`error`,`This browser does not allow copying here. Select the draft text instead.`)}async function Ne(e,t){if(!H){t.show(`error`,`Pick a session to start from first.`);return}let n=await s(`open-community-session`,{key:e.item.key,projectId:H},t,{busyText:`Starting a session with the research.`});n?.type===`open-community-session-result`&&(n.ok?(t.show(`ok`,`Started ${n.sessionName??`a session`}.`),n.sessionId&&se()?.openTerminal(n.sessionId)):t.show(`error`,n.error??`The session did not start.`))}async function J(e,t,n){let r=t===`rerun`?`Queuing the research again.`:`Setting the question aside.`,i=await s(`community-action`,{key:e.item.key,action:t},n,{busyText:r});i?.type===`community-action-result`&&(i.ok||n.show(`error`,i.error??`The change did not apply.`))}function Pe(){let e=r(`select`,`community-session-picker`);e.setAttribute(`aria-label`,`Session to start from`);let t=De();t.some(e=>e.id===H)||(H=t[0]?.id??``);for(let n of t){let t=r(`option`,null,n.name);t.value=n.id,t.selected=n.id===H,e.append(t)}return e.disabled=t.length===0,e.addEventListener(`change`,()=>{H=e.value}),e}function Fe(e){let t=r(`div`,`community-actions`),n=c(`pr-action-status`),i=r(`div`,`community-action-buttons`);return i.append(K(`Copy draft`,e.draft!==null,()=>Me(e,n)),G(`Open thread`,e.item.url),Pe(),K(`Start session`,!0,()=>void Ne(e,n)),K(`Re-run`,ye(e),()=>void J(e,`rerun`,n)),K(`Set aside`,be(e),()=>void J(e,`set-aside`,n))),t.append(i,n.element),t}function Ie(e){let t=r(`article`,`pr-detail community-detail`),n=je(e);return t.append(Oe(e),Fe(e),...n?[n]:[],Ae(e),ke(e)),t}function Y(){if(!F)return;let e=m(L,R),t=e?JSON.stringify(e.entry):`empty:${b(L).length}`;if(t===V)return;if(V=t,e){F.replaceChildren(Ie(e.entry));return}let n=L.some(e=>e.items.length>0);F.replaceChildren(n?me({title:`All caught up`,detail:xe(L)}):r(`p`,`pr-empty`,D(x())))}function Le(e,t){f(h(e))&&t.querySelector(`.pr-queue-unseen`)?.remove()}function X(){if(!I)return;let e=g(L,E);ie(I,p(e),e.filter(e=>e.id!==R))}function Z(e){R=e;for(let[t,n]of U)n.setAttribute(`aria-current`,String(t===e));let t=m(L,e),n=U.get(e);t&&n&&Le(t,n),Y(),X(),N&&(N.dataset.detailOpen=`true`)}function Re(){N&&(N.dataset.detailOpen=`false`),R&&U.get(R)?.focus({preventScroll:!0})}function Q(e){let t=m(L,e);if(!t)return;L.find(e=>e.items.includes(t))?.id===`aside`&&(z=!0),R=e,$(),Z(e);let n=U.get(e);n?.focus({preventScroll:!0}),n?.scrollIntoView({block:`nearest`})}function ze(e){if(e.repeat||e.defaultPrevented||!N||t(N)||u()||n(e)||document.activeElement?.classList.contains(`xterm-helper-textarea`))return;let r=v(e);if(r!==`next-row`&&r!==`previous-row`)return;let i=d([...U.keys()],R,r===`next-row`?1:-1);i&&(e.preventDefault(),i!==R&&Q(i))}function Be(e,t){let n=r(`button`,`pr-queue-row pr-queue-row-quiet`);n.type=`button`,n.dataset.queueKey=e.key,n.setAttribute(`aria-current`,String(e.key===R));let i=w(e.entry),a=r(`span`,`review-queue-action community-badge`,i.text);a.dataset.tone=i.tone;let o=r(`span`,`pr-queue-top`);if(o.append(a,r(`span`,`pr-queue-title`,E(e))),n.append(o,r(`span`,`pr-queue-elapsed`,T(e.entry))),n.title=E(e),t&&y(h(e))){let e=r(`span`,`tab-activity active pr-queue-unseen`);e.setAttribute(`aria-hidden`,`true`),n.append(e)}return n.addEventListener(`click`,()=>Z(e.key)),U.set(e.key,n),n}function Ve(e){let t=r(`h3`,`pr-section-heading review-group-heading`),n=r(`span`,`review-group-count`,String(e.items.length));if(e.id!==`aside`)return t.append(r(`span`,null,e.title),n),t;let i=r(`button`,`review-group-toggle`),a=r(`span`,`review-group-chevron`,`▸`);return a.setAttribute(`aria-hidden`,`true`),i.append(a,e.title),i.type=`button`,i.setAttribute(`aria-expanded`,String(z)),i.addEventListener(`click`,()=>{z=!z,B=null,$()}),t.append(i,n),t}function He(e){let t=r(`section`,`pr-queue-section`);if(t.dataset.group=e.id,t.append(Ve(e)),e.id===`aside`&&!z)return t;for(let n of e.items)t.append(Be(n,e.id===`turn`));return t}function Ue(){if(!N||!W)return!1;x()?.configured===!1&&!W.isOpen()&&W.open();let e=W.isOpen();return N.dataset.setup=String(e),W.element.hidden=!e,e}function $(){if(!P||Ue())return;L=pe(),R=oe(L.filter(e=>e.id!==`aside`||z),R),X();let e=JSON.stringify([L,R,z,fe(),x()?.error??null]);if(e!==B){B=e,U.clear();let t=x()?.error,n=t?[r(`p`,`my-pr-note`,t)]:[],i=L.filter(e=>e.items.length>0).map(He);P.replaceChildren(...n,...i.length>0?i:[r(`p`,`pr-empty`,D(x()))])}Y()}function We(e){if(N)return;N=r(`div`,`pr-content review-queue community-queue`),e.append(N);let n=he({queueLabel:`Community questions`,scopeTabs:null,resizerLabel:`Resize community queue`});P=n.queue,F=r(`div`,`review-queue-detail`);let i=r(`div`,`review-queue-phone-bar`),a=r(`button`,`pr-action pr-action-ghost review-queue-back`,`Back to queue`);a.type=`button`,a.addEventListener(`click`,Re),i.append(a),n.detail.append(i,F),I=re({onJump:()=>{let e=g(L,E).find(e=>e.id!==R)?.id;e&&Q(e)},rowFor:e=>U.get(e)}),I.classList.add(`review-queue-banner`),n.queue.before(I),W=Ee({onFinish:$}),W.element.hidden=!0,N.append(W.element,n.columns),N.dataset.detailOpen=`false`,le(()=>!t(N)),ue(e=>{e.kind===`status`&&$()}),document.addEventListener(`keydown`,ze),$()}var Ge={mount:We,refresh:()=>{V=null,$()}};export{Ge as view};
1
+ import{b as e,d as t,f as n,s as r}from"./dom-helpers-DBbFg1c_.js";import{d as i,u as a}from"./control-ws-2skDxNtN.js";import{o}from"./card-registry-D5EJa_tx.js";import{c as s,i as c,s as ee,t as l}from"./action-status-Cmp0b1QX.js";import{i as u}from"./modal-USMHOKBI.js";import{Bt as d,Ct as f,Dt as p,Lt as m,Nt as h,Pt as g,Qr as _,Rt as v,St as y,Vt as b,Zr as te,_ as ne,bt as x,dn as re,fn as ie,j as ae,jt as oe,lt as se,m as ce,vt as le,wt as ue,x as de,xt as fe,yt as pe}from"./index-BlbUd3zj.js";import{t as me}from"./team-review-panel-DoJwTt6h.js";import{t as he}from"./pr-queue-columns-DFjXXF3o.js";import{n as S}from"./setup-step-D0y3riKj.js";var ge={HIGH:`High confidence`,MEDIUM:`Medium confidence`,LOW:`Low confidence`},_e={HIGH:`ok`,MEDIUM:`warn`,LOW:`muted`},C={queued:`Waiting to be researched`,running:`Researching`,error:`Research failed`,aside:`Set aside`},ve={forum:`Forum`,discord:`Discord`};function w(e){return e.status===`ready`&&e.verdict?{text:ge[e.verdict],tone:_e[e.verdict]}:e.status===`ready`?{text:`Researched`,tone:`muted`}:e.status===`error`?{text:C.error,tone:`danger`}:{text:C[e.status],tone:`muted`}}function T(e){let t=ve[e.item.source];return e.item.channel?`${t} #${e.item.channel}`:t}function E(e){return e.entry.item.title||`Untitled question`}function ye(e){return e.status!==`running`&&e.status!==`queued`}function be(e){return e.status!==`aside`}function xe(e){let t=e.find(e=>e.id===`working`)?.items.length??0;return t===0?`No community question needs you right now.`:`No community question needs you right now. ${t} ${t===1?`question is`:`questions are`} being researched.`}function D(e){return e?e.configured===!1?e.reason??`The community lane is not set up yet.`:`No community questions yet. New ones asked after you turned this on show up here.`:`Waiting for the community lane to report.`}function Se(e){return e.filter(e=>!e.isWorkspace&&!e.isEphemeral).map(({id:e,name:t})=>({id:e,name:t})).toSorted((e,t)=>e.name.localeCompare(t.name))}var O=[`key`,`project`,`skill`,`discord`];function Ce(e){let t=e===`finished`?O.length:O.indexOf(e),n=e=>e<t?`done`:e===t?`current`:`upcoming`;return{key:n(0),project:n(1),skill:n(2),discord:n(3)}}function we(e){let t=e.split(/[\s,]+/).map(e=>e.replace(/^#/,``)).filter(Boolean);return[...new Set(t)]}var k=2;function A(e){a({type:`dashboard-telemetry`,event:`operator_action`,properties:{surface:`onboarding`,action:e}})}function j(){let e=ae().community,t=typeof e==`object`&&e?e:{},n=Array.isArray(t.discordChannels)?t.discordChannels.filter(e=>typeof e==`string`):[];return{projectId:typeof t.projectId==`number`?t.projectId:k,skill:typeof t.skill==`string`?t.skill:``,discordChannels:n}}function Te(e,t,n,i){let a=r(`input`,`dialog-input repo-roots-adder-input`);return a.id=e,a.type=i,a.value=t,a.placeholder=n,a.autocomplete=`off`,a.spellcheck=!1,a}function M(e,t){let n=r(`button`,`btn-dialog btn-dialog-${t}`,e);return n.type=`button`,n}function Ee({onFinish:e}){let t=r(`section`,`first-run-checklist review-setup`);t.setAttribute(`aria-labelledby`,`community-setup-title`);let n=r(`h2`,`first-run-title`,`Answer community questions`);n.id=`community-setup-title`;let a=r(`ol`,`first-run-steps`),o=r(`p`,`first-run-step-hint review-setup-foot`,`Each question gets a researched draft reply. Nothing posts until you post it yourself. `);o.append(ne(`lanes-community`,`community-enabled`,`All community settings`));let s=r(`div`,`first-run-step-actions`),u=M(`Finish setup`,`confirm`);s.append(u),s.hidden=!0,t.append(r(`span`,`first-run-eyebrow`,`SET UP COMMUNITY`),n,a,s,o);let d=null;u.addEventListener(`click`,()=>{A(`finish-community-setup`),d=null,e()});function f(e){d=e,y(),(a.querySelector(`[aria-current="step"] input`)??(s.hidden?null:u))?.focus()}async function p(e,t,n,r){t.disabled=!0,n.show(`busy`,`Saving`);try{let t=await i(`update-settings`,{settings:e},{timeoutMs:l});if(t.type===`settings-error`){n.show(`error`,t.message);return}if(t.type!==`settings-updated`){n.show(`error`,`The server did not confirm the save.`);return}de(t.settings),f(r)}catch(e){n.show(`error`,ee(e,l))}finally{t.disabled=!1}}function m(e){let t=Te(e.inputId,e.initialValue,e.placeholder,e.inputType),n=r(`label`,`repo-roots-adder-label`,e.label);n.htmlFor=t.id;let i=r(`div`,`first-run-step-actions`),a=c(),o=M(e.saveLabel,`confirm`),s=()=>{let n=e.settingsPatch(t.value);typeof n==`string`?a.show(`error`,n):(A(e.action),p(n,o,a,e.nextProgress))};if(o.addEventListener(`click`,s),t.addEventListener(`keydown`,e=>{e.key===`Enter`&&(e.preventDefault(),s())}),i.append(o),e.isSkippable){let t=M(`Skip`,`cancel`);t.addEventListener(`click`,()=>f(e.nextProgress)),i.append(t)}return i.append(a.element),[r(`p`,`first-run-step-text`,e.advice),n,t,i]}let h=()=>m({advice:`Glimmervoid reads new forum and Discord questions through your PostHog personal API key. Create one in PostHog under Settings, Personal API keys. Community needs only the query:read scope on the project that holds the questions. PostHog error monitoring shares this key, so add error tracking read and write if you turn that on.`,label:`PERSONAL API KEY`,inputId:`community-setup-key`,inputType:`password`,initialValue:``,placeholder:`phx_`,saveLabel:`Save key`,action:`save-community-key`,nextProgress:`project`,isSkippable:!1,settingsPatch:e=>e.trim()?{posthog:{apiKey:e.trim()}}:`Paste a PostHog personal API key.`}),g=()=>m({advice:`The PostHog project that holds the synced community forum table and the Discord bot events. PostHog's own community lives in project 2.`,label:`PROJECT ID`,inputId:`community-setup-project`,inputType:`number`,initialValue:String(j().projectId),placeholder:String(k),saveLabel:`Use project`,action:`save-community-project`,nextProgress:`skill`,isSkippable:!1,settingsPatch:e=>{let t=Number(e.trim());return Number.isInteger(t)&&t>0?{community:{projectId:t}}:`Type the project id as a whole number, such as 2.`}}),_=()=>m({advice:`The Claude Code skill the research agent follows for each question, typed by name. A skill that knows your docs and support playbook gives the best drafts. Skip to research with whatever skills the agent has.`,label:`SKILL`,inputId:`community-setup-skill`,inputType:`text`,initialValue:j().skill,placeholder:`skill name`,saveLabel:`Save skill`,action:`save-community-skill`,nextProgress:`discord`,isSkippable:!0,settingsPatch:e=>({community:{skill:e.trim().replace(/^\//,``)}})}),v=()=>m({advice:`Discord questions come from a Discord bot that sends message_sent and thread_created events into the project above. With that bot in place, list the channels to watch by name, without the #. A cheap model picks out the real questions; only those are researched.`,label:`CHANNELS`,inputId:`community-setup-discord`,inputType:`text`,initialValue:j().discordChannels.join(`, `),placeholder:`community-questions, help`,saveLabel:`Save channels`,action:`save-community-discord`,nextProgress:`finished`,isSkippable:!0,settingsPatch:e=>{let t=we(e);return t.length>0?{community:{discordChannels:t}}:`Type at least one channel, or skip.`}});function y(){if(!d)return;let e=Ce(d);a.replaceChildren(S({title:`1. PostHog personal API key`,state:e.key,summary:`Key saved`,badge:`NEEDED`,body:h}),S({title:`2. PostHog project`,state:e.project,summary:`Project ${j().projectId}`,badge:``,body:g}),S({title:`3. Research skill (optional)`,state:e.skill,summary:j().skill||`No skill`,badge:``,body:_}),S({title:`4. Discord (optional)`,state:e.discord,summary:j().discordChannels.map(e=>`#${e}`).join(` `)||`Forum only`,badge:``,body:v})),s.hidden=d!==`finished`}function b(){d=`key`,y()}return{element:t,open:b,isOpen:()=>d!==null}}var N=null,P=null,F=null,I=null,L=[],R=null,z=!1,B=null,V=null,H=``,U=new Map,W=null;function De(){return Se([...o].map(([e,t])=>({id:e,name:t.nameEl.textContent??e,isWorkspace:t.card.dataset.workspace!==void 0,isEphemeral:t.card.dataset.ephemeral!==void 0})))}function G(e,t){let n=r(`button`,`pr-action pr-action-ghost`,e);return n.type=`button`,n.disabled=!_(t),n.addEventListener(`click`,()=>te(t)),n}function K(e,t,n){let i=r(`button`,`pr-action`,e);return i.type=`button`,i.disabled=!t,i.addEventListener(`click`,n),i}function q(e,t,n){let i=r(`ul`,e);i.setAttribute(`aria-label`,t);for(let e of n)i.append(r(`li`,null,e));return i}function Oe(e){let t=r(`div`,`pr-detail-heading`),n=r(`div`,`pr-detail-title`);n.append(r(`h2`,null,e.item.title||`Untitled question`));let i=r(`div`,`pr-detail-meta`),a=Date.parse(e.item.createdAt);return i.append(r(`span`,null,e.item.author),r(`span`,null,T(e))),Number.isNaN(a)||i.append(r(`span`,null,`Asked ${ce(a)}`)),t.append(n,i),t}function ke(e){let t=r(`section`,`community-question`);return t.setAttribute(`aria-label`,`Question as asked`),t.append(r(`h3`,`pr-section-heading`,`Question as asked`),r(`p`,`community-question-body`,e.item.body)),t}function Ae(e){let t=r(`section`,`pr-verdict-box`);t.setAttribute(`aria-label`,`Research`);let n=w(e),i=r(`div`,`pr-verdict-line`),a=r(`strong`,`community-badge`,n.text);if(a.dataset.tone=n.tone,i.append(a),t.append(i),e.error&&t.append(r(`p`,`pr-attention-detail`,e.error)),e.summary&&t.append(r(`p`,`pr-verdict-summary`,e.summary)),e.goal&&t.append(r(`p`,`community-goal`,`Goal: ${e.goal}`)),e.gaps.length>0&&t.append(q(`pr-verdict-gaps`,`Not covered`,e.gaps)),e.checked.length===0)return t;let o=r(`details`,`pr-verdict-checked`);return o.append(r(`summary`,null,`What it checked (${e.checked.length})`),q(`community-checked`,`What it checked`,e.checked)),t.append(o),t}function je(e){if(!e.draft)return null;let t=r(`section`,`community-draft`);t.setAttribute(`aria-label`,`Draft reply`),t.append(r(`h3`,`pr-section-heading`,`Draft reply`),r(`p`,`community-draft-body`,e.draft.body));let n=e.draft.publicLinks.filter(_);if(n.length===0)return t;let i=r(`ul`,`community-links`);for(let e of n){let t=r(`li`);t.append(G(e,e)),i.append(t)}return t.append(i),t}function Me(t,n){let r=t.draft?e(t.draft.body):null;r?r.then(()=>n.show(`ok`,`Draft copied. Post it yourself where the question was asked.`),()=>n.show(`error`,`Copying failed. Select the draft text instead.`)):n.show(`error`,`This browser does not allow copying here. Select the draft text instead.`)}async function Ne(e,t){if(!H){t.show(`error`,`Pick a session to start from first.`);return}let n=await s(`open-community-session`,{key:e.item.key,projectId:H},t,{busyText:`Starting a session with the research.`});n?.type===`open-community-session-result`&&(n.ok?(t.show(`ok`,`Started ${n.sessionName??`a session`}.`),n.sessionId&&se()?.openTerminal(n.sessionId)):t.show(`error`,n.error??`The session did not start.`))}async function J(e,t,n){let r=t===`rerun`?`Queuing the research again.`:`Setting the question aside.`,i=await s(`community-action`,{key:e.item.key,action:t},n,{busyText:r});i?.type===`community-action-result`&&(i.ok||n.show(`error`,i.error??`The change did not apply.`))}function Pe(){let e=r(`select`,`community-session-picker`);e.setAttribute(`aria-label`,`Session to start from`);let t=De();t.some(e=>e.id===H)||(H=t[0]?.id??``);for(let n of t){let t=r(`option`,null,n.name);t.value=n.id,t.selected=n.id===H,e.append(t)}return e.disabled=t.length===0,e.addEventListener(`change`,()=>{H=e.value}),e}function Fe(e){let t=r(`div`,`community-actions`),n=c(`pr-action-status`),i=r(`div`,`community-action-buttons`);return i.append(K(`Copy draft`,e.draft!==null,()=>Me(e,n)),G(`Open thread`,e.item.url),Pe(),K(`Start session`,!0,()=>void Ne(e,n)),K(`Re-run`,ye(e),()=>void J(e,`rerun`,n)),K(`Set aside`,be(e),()=>void J(e,`set-aside`,n))),t.append(i,n.element),t}function Ie(e){let t=r(`article`,`pr-detail community-detail`),n=je(e);return t.append(Oe(e),Fe(e),...n?[n]:[],Ae(e),ke(e)),t}function Y(){if(!F)return;let e=m(L,R),t=e?JSON.stringify(e.entry):`empty:${b(L).length}`;if(t===V)return;if(V=t,e){F.replaceChildren(Ie(e.entry));return}let n=L.some(e=>e.items.length>0);F.replaceChildren(n?me({title:`All caught up`,detail:xe(L)}):r(`p`,`pr-empty`,D(x())))}function Le(e,t){f(h(e))&&t.querySelector(`.pr-queue-unseen`)?.remove()}function X(){if(!I)return;let e=g(L,E);ie(I,p(e),e.filter(e=>e.id!==R))}function Z(e){R=e;for(let[t,n]of U)n.setAttribute(`aria-current`,String(t===e));let t=m(L,e),n=U.get(e);t&&n&&Le(t,n),Y(),X(),N&&(N.dataset.detailOpen=`true`)}function Re(){N&&(N.dataset.detailOpen=`false`),R&&U.get(R)?.focus({preventScroll:!0})}function Q(e){let t=m(L,e);if(!t)return;L.find(e=>e.items.includes(t))?.id===`aside`&&(z=!0),R=e,$(),Z(e);let n=U.get(e);n?.focus({preventScroll:!0}),n?.scrollIntoView({block:`nearest`})}function ze(e){if(e.repeat||e.defaultPrevented||!N||t(N)||u()||n(e)||document.activeElement?.classList.contains(`xterm-helper-textarea`))return;let r=v(e);if(r!==`next-row`&&r!==`previous-row`)return;let i=d([...U.keys()],R,r===`next-row`?1:-1);i&&(e.preventDefault(),i!==R&&Q(i))}function Be(e,t){let n=r(`button`,`pr-queue-row pr-queue-row-quiet`);n.type=`button`,n.dataset.queueKey=e.key,n.setAttribute(`aria-current`,String(e.key===R));let i=w(e.entry),a=r(`span`,`review-queue-action community-badge`,i.text);a.dataset.tone=i.tone;let o=r(`span`,`pr-queue-top`);if(o.append(a,r(`span`,`pr-queue-title`,E(e))),n.append(o,r(`span`,`pr-queue-elapsed`,T(e.entry))),n.title=E(e),t&&y(h(e))){let e=r(`span`,`tab-activity active pr-queue-unseen`);e.setAttribute(`aria-hidden`,`true`),n.append(e)}return n.addEventListener(`click`,()=>Z(e.key)),U.set(e.key,n),n}function Ve(e){let t=r(`h3`,`pr-section-heading review-group-heading`),n=r(`span`,`review-group-count`,String(e.items.length));if(e.id!==`aside`)return t.append(r(`span`,null,e.title),n),t;let i=r(`button`,`review-group-toggle`),a=r(`span`,`review-group-chevron`,`▸`);return a.setAttribute(`aria-hidden`,`true`),i.append(a,e.title),i.type=`button`,i.setAttribute(`aria-expanded`,String(z)),i.addEventListener(`click`,()=>{z=!z,B=null,$()}),t.append(i,n),t}function He(e){let t=r(`section`,`pr-queue-section`);if(t.dataset.group=e.id,t.append(Ve(e)),e.id===`aside`&&!z)return t;for(let n of e.items)t.append(Be(n,e.id===`turn`));return t}function Ue(){if(!N||!W)return!1;x()?.configured===!1&&!W.isOpen()&&W.open();let e=W.isOpen();return N.dataset.setup=String(e),W.element.hidden=!e,e}function $(){if(!P||Ue())return;L=pe(),R=oe(L.filter(e=>e.id!==`aside`||z),R),X();let e=JSON.stringify([L,R,z,fe(),x()?.error??null]);if(e!==B){B=e,U.clear();let t=x()?.error,n=t?[r(`p`,`my-pr-note`,t)]:[],i=L.filter(e=>e.items.length>0).map(He);P.replaceChildren(...n,...i.length>0?i:[r(`p`,`pr-empty`,D(x()))])}Y()}function We(e){if(N)return;N=r(`div`,`pr-content review-queue community-queue`),e.append(N);let n=he({queueLabel:`Community questions`,scopeTabs:null,resizerLabel:`Resize community queue`});P=n.queue,F=r(`div`,`review-queue-detail`);let i=r(`div`,`review-queue-phone-bar`),a=r(`button`,`pr-action pr-action-ghost review-queue-back`,`Back to queue`);a.type=`button`,a.addEventListener(`click`,Re),i.append(a),n.detail.append(i,F),I=re({onJump:()=>{let e=g(L,E).find(e=>e.id!==R)?.id;e&&Q(e)},rowFor:e=>U.get(e)}),I.classList.add(`review-queue-banner`),n.queue.before(I),W=Ee({onFinish:$}),W.element.hidden=!0,N.append(W.element,n.columns),N.dataset.detailOpen=`false`,le(()=>!t(N)),ue(e=>{e.kind===`status`&&$()}),document.addEventListener(`keydown`,ze),$()}var Ge={mount:We,refresh:()=>{V=null,$()}};export{Ge as view};
@@ -1,4 +1,4 @@
1
- import{C as e,F as t,I as n,L as r,at as i,it as a}from"./updates-view-core-4oGJ3ZXL.js";import{g as o,h as s,s as c}from"./dom-helpers-DBbFg1c_.js";import{d as l}from"./control-ws-2skDxNtN.js";import{i as u,s as d,t as f}from"./action-status-Cmp0b1QX.js";import{n as p,r as m,t as h}from"./modal-USMHOKBI.js";import{n as g}from"./session-tick-DbbSgMSO.js";import{Ar as _,Dr as v,In as y,Mr as b,Or as x,Tr as S,_r as C,gi as w,hi as T,jr as E,kr as D,m as O,mi as k}from"./index-k2H9o6FW.js";import{t as ee}from"./repo-roots-adder-Dvp9iTxp.js";import{t as te}from"./sandboxed-frame-D9MEfNuX.js";var ne=`<h2 class="dialog-title" id="add-session-title">Add Session</h2>
1
+ import{C as e,F as t,I as n,L as r,at as i,it as a}from"./updates-view-core-4oGJ3ZXL.js";import{g as o,h as s,s as c}from"./dom-helpers-DBbFg1c_.js";import{d as l}from"./control-ws-2skDxNtN.js";import{i as u,s as d,t as f}from"./action-status-Cmp0b1QX.js";import{n as p,r as m,t as h}from"./modal-USMHOKBI.js";import{n as g}from"./session-tick-DbbSgMSO.js";import{Ar as _,Dr as v,In as y,Mr as b,Or as x,Tr as S,_r as C,gi as w,hi as T,jr as E,kr as D,m as O,mi as k}from"./index-BlbUd3zj.js";import{t as ee}from"./repo-roots-adder-Ly0caqtn.js";import{t as te}from"./sandboxed-frame-D9MEfNuX.js";var ne=`<h2 class="dialog-title" id="add-session-title">Add Session</h2>
2
2
  <fieldset class="dialog-mode-controls add-session-agent-only" aria-label="Session kind">
3
3
  <button type="button" class="dialog-mode-button" id="add-session-single-mode" aria-pressed="true">Single repo</button>
4
4
  <button type="button" class="dialog-mode-button" id="add-session-workspace-mode" aria-pressed="false">Workspace</button>
@@ -1 +1 @@
1
- import{s as e}from"./dom-helpers-DBbFg1c_.js";import{d as t}from"./control-ws-2skDxNtN.js";import{s as n,t as r}from"./action-status-Cmp0b1QX.js";import{a as i,r as a,t as o}from"./modal-USMHOKBI.js";import{fi as s,wn as c}from"./index-k2H9o6FW.js";import{i as l,t as u}from"./plan-render-DfvVjoYs.js";var d=null;function f(t){let n=s(t.sessionId);t.select.replaceChildren(...n.map(n=>{let r=e(`option`,null,n.name);return r.value=n.path,r.selected=n.path===t.docPath,r})),t.select.hidden=n.length<2,t.title.textContent=n.find(e=>e.path===t.docPath)?.name??t.title.textContent}function p(e){let t=s(e.sessionId).some(t=>t.path===e.docPath);e.btnEdit.setAttribute(`aria-pressed`,String(e.mode===`edit`)),e.btnPreview.setAttribute(`aria-pressed`,String(e.mode===`preview`)),e.textarea.hidden=e.mode!==`edit`,e.preview.hidden=e.mode!==`preview`,e.select.disabled=e.isBusy,e.btnReload.disabled=e.isBusy||!t,e.btnSave.disabled=e.isBusy||!t||e.baseHash===null||!e.hasUnsavedChanges}function m(e,t,n=`quiet`){e.status.textContent=t,e.status.dataset.tone=n}function h(e){e.preview.replaceChildren(u(l(e.textarea.value)))}function g(e,t){i({title:e,message:`Your unsaved edits will be lost.`,confirmLabel:`Discard`,danger:!0,onConfirm:t})}function _(e,t,n){e.hasUnsavedChanges?g(t,n):n()}async function v(e,i){try{return{reply:await t(e,i,{timeoutMs:r}),failureText:null}}catch(e){return{reply:null,failureText:n(e,r)}}}async function y(e,t){e.docPath=t,e.isBusy=!0,e.baseHash=null,e.textarea.readOnly=!0,f(e),m(e,`Loading`),p(e);let{reply:n,failureText:r}=await v(`session-doc-read`,{id:e.sessionId,path:t});if(d!==e||e.docPath!==t)return;e.isBusy=!1,e.textarea.readOnly=!1;let i=n?.type===`session-doc-response`?n:null;!i?.ok||i.text===void 0||i.hash===void 0?(m(e,i?.error||r||`Could not open this doc`,`warn`),p(e)):(e.textarea.value=i.text,e.baseHash=i.hash,e.hasUnsavedChanges=!1,e.mode===`preview`&&h(e),m(e,``),p(e))}async function b(e){if(e.btnSave.disabled||e.baseHash===null)return;e.isBusy=!0,m(e,`Saving`),p(e);let t=e.docPath,n=e.textarea.value,{reply:r,failureText:i}=await v(`session-doc-save`,{id:e.sessionId,path:t,text:n,baseHash:e.baseHash});if(d!==e||e.docPath!==t)return;e.isBusy=!1;let a=r?.type===`session-doc-save-result`?r:null;!a?.ok||a.hash===void 0?(m(e,a?.conflict?`The agent changed this file since you opened it. Reload to see its version.`:a?.error||i||`Save failed`,`warn`),p(e)):(e.baseHash=a.hash,e.hasUnsavedChanges=e.textarea.value!==n,m(e,e.hasUnsavedChanges?`Unsaved changes`:`Saved`),p(e))}function x(e,t){e.mode=t,t===`preview`&&h(e),p(e),t===`edit`&&e.textarea.focus()}function S(t,n){let r=e(`button`,`plan-control ${n}`,t);return r.type=`button`,r}function C(t){let n=s(t)[0];if(!n||d)return;let r=()=>_(M,`Close this doc?`,()=>M.close()),i=a({dialogClass:`doc-editor`,closeOnBackdrop:!1,onEscape:r}),l=`doc-editor-title-${t}`,u=e(`h3`,`doc-editor-title`,n.name);u.id=l;let f=e(`select`,`plan-control doc-editor-picker`);f.setAttribute(`aria-label`,`Doc`);let h=e(`span`,`doc-editor-status`);h.setAttribute(`role`,`status`);let g=S(`Edit`,`doc-editor-mode`),v=S(`Preview`,`doc-editor-mode`),C=S(`Reload`,`doc-editor-reload`),w=S(`Save`,`doc-editor-save`),T=S(`Close`,`doc-editor-close`),E=e(`div`,`doc-editor-modes`);E.append(g,v);let D=e(`div`,`doc-editor-actions`);D.append(h,C,w,T);let O=e(`div`,`doc-editor-header`);O.append(u,f,E,D);let k=e(`textarea`,`plan-editor doc-editor-text`);k.spellcheck=!0,k.setAttribute(`aria-labelledby`,l);let A=e(`div`,`doc-editor-preview`),j=e(`div`,`doc-editor-body`);j.append(k,A),i.dialog.append(O,j),o(i.dialog,l);let M={sessionId:t,docPath:n.path,baseHash:null,hasUnsavedChanges:!1,isBusy:!1,mode:c()?`preview`:`edit`,title:u,select:f,textarea:k,preview:A,status:h,btnEdit:g,btnPreview:v,btnReload:C,btnSave:w,close:()=>{d=null,i.close()}};d=M,k.addEventListener(`input`,()=>{M.hasUnsavedChanges||(M.hasUnsavedChanges=!0,m(M,`Unsaved changes`),p(M))}),k.addEventListener(`keydown`,e=>{(e.ctrlKey||e.metaKey)&&e.key.toLowerCase()===`s`&&(e.preventDefault(),b(M))}),f.addEventListener(`change`,()=>{let e=f.value;f.value=M.docPath,_(M,`Open another doc?`,()=>{y(M,e)})}),g.addEventListener(`click`,()=>x(M,`edit`)),v.addEventListener(`click`,()=>x(M,`preview`)),C.addEventListener(`click`,()=>{_(M,`Reload this doc?`,()=>{y(M,M.docPath)})}),w.addEventListener(`click`,()=>{b(M)}),T.addEventListener(`click`,r),y(M,n.path),M.mode===`edit`&&k.focus()}function w(e){d&&d.sessionId===e&&(f(d),p(d),!s(e).some(e=>e.path===d?.docPath)&&m(d,`This doc is no longer surfaced, so it cannot be saved.`,`warn`))}export{w as applyDocsToOpenEditor,C as openDocEditor};
1
+ import{s as e}from"./dom-helpers-DBbFg1c_.js";import{d as t}from"./control-ws-2skDxNtN.js";import{s as n,t as r}from"./action-status-Cmp0b1QX.js";import{a as i,r as a,t as o}from"./modal-USMHOKBI.js";import{fi as s,wn as c}from"./index-BlbUd3zj.js";import{i as l,t as u}from"./plan-render-DfvVjoYs.js";var d=null;function f(t){let n=s(t.sessionId);t.select.replaceChildren(...n.map(n=>{let r=e(`option`,null,n.name);return r.value=n.path,r.selected=n.path===t.docPath,r})),t.select.hidden=n.length<2,t.title.textContent=n.find(e=>e.path===t.docPath)?.name??t.title.textContent}function p(e){let t=s(e.sessionId).some(t=>t.path===e.docPath);e.btnEdit.setAttribute(`aria-pressed`,String(e.mode===`edit`)),e.btnPreview.setAttribute(`aria-pressed`,String(e.mode===`preview`)),e.textarea.hidden=e.mode!==`edit`,e.preview.hidden=e.mode!==`preview`,e.select.disabled=e.isBusy,e.btnReload.disabled=e.isBusy||!t,e.btnSave.disabled=e.isBusy||!t||e.baseHash===null||!e.hasUnsavedChanges}function m(e,t,n=`quiet`){e.status.textContent=t,e.status.dataset.tone=n}function h(e){e.preview.replaceChildren(u(l(e.textarea.value)))}function g(e,t){i({title:e,message:`Your unsaved edits will be lost.`,confirmLabel:`Discard`,danger:!0,onConfirm:t})}function _(e,t,n){e.hasUnsavedChanges?g(t,n):n()}async function v(e,i){try{return{reply:await t(e,i,{timeoutMs:r}),failureText:null}}catch(e){return{reply:null,failureText:n(e,r)}}}async function y(e,t){e.docPath=t,e.isBusy=!0,e.baseHash=null,e.textarea.readOnly=!0,f(e),m(e,`Loading`),p(e);let{reply:n,failureText:r}=await v(`session-doc-read`,{id:e.sessionId,path:t});if(d!==e||e.docPath!==t)return;e.isBusy=!1,e.textarea.readOnly=!1;let i=n?.type===`session-doc-response`?n:null;!i?.ok||i.text===void 0||i.hash===void 0?(m(e,i?.error||r||`Could not open this doc`,`warn`),p(e)):(e.textarea.value=i.text,e.baseHash=i.hash,e.hasUnsavedChanges=!1,e.mode===`preview`&&h(e),m(e,``),p(e))}async function b(e){if(e.btnSave.disabled||e.baseHash===null)return;e.isBusy=!0,m(e,`Saving`),p(e);let t=e.docPath,n=e.textarea.value,{reply:r,failureText:i}=await v(`session-doc-save`,{id:e.sessionId,path:t,text:n,baseHash:e.baseHash});if(d!==e||e.docPath!==t)return;e.isBusy=!1;let a=r?.type===`session-doc-save-result`?r:null;!a?.ok||a.hash===void 0?(m(e,a?.conflict?`The agent changed this file since you opened it. Reload to see its version.`:a?.error||i||`Save failed`,`warn`),p(e)):(e.baseHash=a.hash,e.hasUnsavedChanges=e.textarea.value!==n,m(e,e.hasUnsavedChanges?`Unsaved changes`:`Saved`),p(e))}function x(e,t){e.mode=t,t===`preview`&&h(e),p(e),t===`edit`&&e.textarea.focus()}function S(t,n){let r=e(`button`,`plan-control ${n}`,t);return r.type=`button`,r}function C(t){let n=s(t)[0];if(!n||d)return;let r=()=>_(M,`Close this doc?`,()=>M.close()),i=a({dialogClass:`doc-editor`,closeOnBackdrop:!1,onEscape:r}),l=`doc-editor-title-${t}`,u=e(`h3`,`doc-editor-title`,n.name);u.id=l;let f=e(`select`,`plan-control doc-editor-picker`);f.setAttribute(`aria-label`,`Doc`);let h=e(`span`,`doc-editor-status`);h.setAttribute(`role`,`status`);let g=S(`Edit`,`doc-editor-mode`),v=S(`Preview`,`doc-editor-mode`),C=S(`Reload`,`doc-editor-reload`),w=S(`Save`,`doc-editor-save`),T=S(`Close`,`doc-editor-close`),E=e(`div`,`doc-editor-modes`);E.append(g,v);let D=e(`div`,`doc-editor-actions`);D.append(h,C,w,T);let O=e(`div`,`doc-editor-header`);O.append(u,f,E,D);let k=e(`textarea`,`plan-editor doc-editor-text`);k.spellcheck=!0,k.setAttribute(`aria-labelledby`,l);let A=e(`div`,`doc-editor-preview`),j=e(`div`,`doc-editor-body`);j.append(k,A),i.dialog.append(O,j),o(i.dialog,l);let M={sessionId:t,docPath:n.path,baseHash:null,hasUnsavedChanges:!1,isBusy:!1,mode:c()?`preview`:`edit`,title:u,select:f,textarea:k,preview:A,status:h,btnEdit:g,btnPreview:v,btnReload:C,btnSave:w,close:()=>{d=null,i.close()}};d=M,k.addEventListener(`input`,()=>{M.hasUnsavedChanges||(M.hasUnsavedChanges=!0,m(M,`Unsaved changes`),p(M))}),k.addEventListener(`keydown`,e=>{(e.ctrlKey||e.metaKey)&&e.key.toLowerCase()===`s`&&(e.preventDefault(),b(M))}),f.addEventListener(`change`,()=>{let e=f.value;f.value=M.docPath,_(M,`Open another doc?`,()=>{y(M,e)})}),g.addEventListener(`click`,()=>x(M,`edit`)),v.addEventListener(`click`,()=>x(M,`preview`)),C.addEventListener(`click`,()=>{_(M,`Reload this doc?`,()=>{y(M,M.docPath)})}),w.addEventListener(`click`,()=>{b(M)}),T.addEventListener(`click`,r),y(M,n.path),M.mode===`edit`&&k.focus()}function w(e){d&&d.sessionId===e&&(f(d),p(d),!s(e).some(e=>e.path===d?.docPath)&&m(d,`This doc is no longer surfaced, so it cannot be saved.`,`warn`))}export{w as applyDocsToOpenEditor,C as openDocEditor};
@@ -1 +1 @@
1
- import{lt as e}from"./updates-view-core-4oGJ3ZXL.js";import{s as t}from"./dom-helpers-DBbFg1c_.js";import{u as n}from"./control-ws-2skDxNtN.js";import{vt as r}from"./ui-prefs-CiiqXyOk.js";import{Fn as i,Pn as a,_i as o,i as s,vi as c}from"./index-k2H9o6FW.js";var l={teamReview:e=>`${e} pull requests reviewed this week. Reviews lines up every PR waiting on you, and it is off right now.`,issues:e=>`${e} issues touched this week. The Issues tab keeps them in one list and starts a session on any of them, and it is off right now.`,usage:()=>`Keeping an eye on tokens? Usage tracks spend per session and warns before a limit hits, and it is off right now.`,posthog:()=>`Hunting errors again? Radar watches PostHog error tracking and can investigate an issue for you, and it is off right now.`,benchmarks:()=>`Comparing agents by hand? Bench runs the same review cases across agent setups side by side, and it is off right now.`};function u(e){return`${l[e.feature](e.distinctTargetCount)} Show me takes you to its switch in Settings.`}function d(e){let t=s.find(t=>t.rule===e);return t?{sectionId:t.sectionId,settingId:t.settingId}:null}var f=null;function p(e,t){n({type:`dashboard-telemetry`,event:`operator_action`,properties:{surface:`hints`,action:t,feature:e}})}function m(e){try{return i(localStorage,a(`feature-hint`,`${e.feature}-${e.raisedAt}`),Date.now())}catch{return!0}}function h(t,n){if(n.isFeatureEnabled(t)){n.openView(e[t]);return}let r=d(t);r&&n.openSetting(r.sectionId,r.settingId)}function g(){return f?.isConnected===!0}function _({text:e,ariaLabel:n,onOpen:i,onDismiss:a}){let s=t(`aside`,`feature-hint`);s.setAttribute(`aria-live`,`polite`),s.setAttribute(`aria-label`,n);let l=t(`div`,`feature-hint-bubble`),u=t(`button`,`btn-dialog btn-dialog-confirm`,`Show me`),d=t(`button`,`btn-dialog btn-dialog-cancel`,`Nah`);u.type=`button`,d.type=`button`;let p=t(`div`,`feature-hint-actions`);p.append(d,u),l.append(t(`p`,`feature-hint-text`,e),p);let m=c()??r[0];s.append(l,o(m,`feature-hint-animal`));function h(){s.remove(),f=null}u.addEventListener(`click`,()=>{h(),i()}),d.addEventListener(`click`,()=>{h(),a()}),document.body.append(s),f=s}function v(e,t){g()||m(e)&&(_({text:u(e),ariaLabel:`Feature tip`,onOpen:()=>{p(e.feature,`open`),h(e.feature,t)},onDismiss:()=>p(e.feature,`dismiss`)}),p(e.feature,`shown`))}export{g as isHintCardShown,v as showFeatureHint,_ as showHintCard};
1
+ import{lt as e}from"./updates-view-core-4oGJ3ZXL.js";import{s as t}from"./dom-helpers-DBbFg1c_.js";import{u as n}from"./control-ws-2skDxNtN.js";import{vt as r}from"./ui-prefs-CiiqXyOk.js";import{Fn as i,Pn as a,_i as o,i as s,vi as c}from"./index-BlbUd3zj.js";var l={teamReview:e=>`${e} pull requests reviewed this week. Reviews lines up every PR waiting on you, and it is off right now.`,issues:e=>`${e} issues touched this week. The Issues tab keeps them in one list and starts a session on any of them, and it is off right now.`,usage:()=>`Keeping an eye on tokens? Usage tracks spend per session and warns before a limit hits, and it is off right now.`,posthog:()=>`Hunting errors again? Radar watches PostHog error tracking and can investigate an issue for you, and it is off right now.`,benchmarks:()=>`Comparing agents by hand? Bench runs the same review cases across agent setups side by side, and it is off right now.`};function u(e){return`${l[e.feature](e.distinctTargetCount)} Show me takes you to its switch in Settings.`}function d(e){let t=s.find(t=>t.rule===e);return t?{sectionId:t.sectionId,settingId:t.settingId}:null}var f=null;function p(e,t){n({type:`dashboard-telemetry`,event:`operator_action`,properties:{surface:`hints`,action:t,feature:e}})}function m(e){try{return i(localStorage,a(`feature-hint`,`${e.feature}-${e.raisedAt}`),Date.now())}catch{return!0}}function h(t,n){if(n.isFeatureEnabled(t)){n.openView(e[t]);return}let r=d(t);r&&n.openSetting(r.sectionId,r.settingId)}function g(){return f?.isConnected===!0}function _({text:e,ariaLabel:n,onOpen:i,onDismiss:a}){let s=t(`aside`,`feature-hint`);s.setAttribute(`aria-live`,`polite`),s.setAttribute(`aria-label`,n);let l=t(`div`,`feature-hint-bubble`),u=t(`button`,`btn-dialog btn-dialog-confirm`,`Show me`),d=t(`button`,`btn-dialog btn-dialog-cancel`,`Nah`);u.type=`button`,d.type=`button`;let p=t(`div`,`feature-hint-actions`);p.append(d,u),l.append(t(`p`,`feature-hint-text`,e),p);let m=c()??r[0];s.append(l,o(m,`feature-hint-animal`));function h(){s.remove(),f=null}u.addEventListener(`click`,()=>{h(),i()}),d.addEventListener(`click`,()=>{h(),a()}),document.body.append(s),f=s}function v(e,t){g()||m(e)&&(_({text:u(e),ariaLabel:`Feature tip`,onOpen:()=>{p(e.feature,`open`),h(e.feature,t)},onDismiss:()=>p(e.feature,`dismiss`)}),p(e.feature,`shown`))}export{g as isHintCardShown,v as showFeatureHint,_ as showHintCard};
@@ -1 +1 @@
1
- import{s as e}from"./dom-helpers-DBbFg1c_.js";import{d as t,u as n}from"./control-ws-2skDxNtN.js";import{i as r,s as i,t as a}from"./action-status-Cmp0b1QX.js";import{br as o,hr as s,jn as c,yr as l}from"./index-k2H9o6FW.js";import{n as u,t as d}from"./setup-step-D0y3riKj.js";import{a as f,c as p,i as m,l as h,n as g,o as _,r as v,s as y,t as b}from"./repo-roots-adder-Dvp9iTxp.js";var x=`npm install -g @anthropic-ai/claude-code`,S=null,C=null,w=null,T=null,E={steps:v,agentSummary:``,repoRoots:[],isShellAvailable:!1},D=0,O=!1,k=!1,A=new Set,j=r(`first-run-load-status`),M=c();function N(e){n({type:`dashboard-telemetry`,event:`operator_action`,properties:{surface:`onboarding`,action:e}})}function P(e){for(let t of y(A,e))n({type:`dashboard-telemetry`,event:`onboarding_step`,properties:t})&&A.add(p(t))}function F(){return s()?`No supported agent is on PATH of the machine running Glimmervoid. Install Claude Code, Codex or Grok there, then rescan.`:`No supported agent is on PATH. Install Claude Code, Codex or Grok, then rescan.`}function I(){let t=e(`button`,`btn-dialog btn-dialog-cancel`,`Open shell`);return t.type=`button`,t.addEventListener(`click`,()=>{N(`open-shell`),o()}),t}function L(){let t=e(`div`,`first-run-step-actions`);w=e(`button`,`btn-dialog btn-dialog-cancel`,`Rescan`),w.type=`button`,w.addEventListener(`click`,()=>{N(`rescan`),V({rescanAgents:!0})}),t.append(w),E.isShellAvailable&&t.append(I());let n=[e(`p`,`first-run-step-text`,F()),d(x),t];return O?[...n,e(`p`,`first-run-step-hint`,`Still missing after a rescan? Restart Glimmervoid from a terminal where the command runs. Other terminal agents go under customAgents.`)]:n}function R(){let t=T??b({onAdded:e=>{N(e===`typed`?`add-root-typed`:`add-root-suggested`),V({rescanAgents:!1})}});return T=t,[e(`p`,`first-run-step-text`,`The folder that holds your git checkouts. Each subfolder becomes a project you can start a session in.`),t.element]}function z(){let t=e(`div`,`first-run-step-actions`),n=e(`button`,`btn-dialog btn-dialog-confirm`,`+ Session`);return n.type=`button`,n.addEventListener(`click`,()=>{N(`add-session`),l()}),t.append(n),[e(`p`,`first-run-step-text`,`Pick a project and an agent. The session runs in its own git worktree, so your checkout is never touched.`),t]}function B(){if(!C)return;let{steps:e,agentSummary:t,repoRoots:n}=E;C.replaceChildren(u({title:`1. Agent CLI`,state:e.agent,summary:t,badge:`MISSING`,body:L}),u({title:`2. Repository roots`,state:e.repoRoots,summary:n.join(`, `),badge:`NEEDED`,body:R}),u({title:`3. First session`,state:e.firstSession,summary:``,badge:``,body:z}))}async function V({rescanAgents:e}){D+=1;let n=D;w&&(w.disabled=!0);try{let[r,i]=await Promise.all([t(`list-agents`,e?{rescan:!0}:{},{timeoutMs:a}),t(`scan-repo-roots`,{includeSuggestions:!0},{timeoutMs:a})]);if(n!==D)return;let o=i.type===`repo-roots-scanned`,s=o?i.directories.map(e=>e.root):[],c=o?i.suggestions??[]:[],l=h(s,c);if(l.length>0&&!k){k=!0;let e=await g(l).catch(e=>String(e));if(n!==D)return;if(!e){V({rescanAgents:!1});return}}let u=_({agentListing:r,repoRoots:s});e&&(O=u.agent===`current`),E={steps:u,agentSummary:m(r),repoRoots:s,isShellAvailable:f(r)},j.clear(),B(),P(E.steps),T?.setSuggestions(c)}catch(e){if(w&&(w.disabled=!1),n!==D)return;j.show(`error`,`The checklist could not load: ${i(e,a)} It loads again once the server answers. If it stays like this, check the terminal running Glimmervoid, or run glimmervoid doctor.`)}}function H(){if(S)return S;let t=e(`section`,`first-run-checklist`);t.setAttribute(`aria-labelledby`,`first-run-title`);let n=e(`h2`,`first-run-title`,`Get to your first session`);n.id=`first-run-title`,C=e(`ol`,`first-run-steps`);let r=e(`div`,`first-run-optional`);return r.append(e(`span`,`first-run-eyebrow`,`OPTIONAL`),M.element),t.append(e(`span`,`first-run-eyebrow`,`FIRST RUN`),n,C,j.element,r),S=t,B(),t}function U(e,t){if(!t){S?.parentElement===e&&!S.hidden&&(S.hidden=!0);return}let n=H(),r=!n.hidden&&n.parentElement===e;n.parentElement!==e&&e.append(n),n.hidden=!1,M.refresh(),r||V({rescanAgents:!1})}function W(){S&&!S.hidden&&S.isConnected&&V({rescanAgents:!1})}export{W as refreshFirstRunChecklist,U as showFirstRunChecklist};
1
+ import{s as e}from"./dom-helpers-DBbFg1c_.js";import{d as t,u as n}from"./control-ws-2skDxNtN.js";import{i as r,s as i,t as a}from"./action-status-Cmp0b1QX.js";import{br as o,hr as s,jn as c,yr as l}from"./index-BlbUd3zj.js";import{n as u,t as d}from"./setup-step-D0y3riKj.js";import{a as f,c as p,i as m,l as h,n as g,o as _,r as v,s as y,t as b}from"./repo-roots-adder-Ly0caqtn.js";var x=`npm install -g @anthropic-ai/claude-code`,S=null,C=null,w=null,T=null,E={steps:v,agentSummary:``,repoRoots:[],isShellAvailable:!1},D=0,O=!1,k=!1,A=new Set,j=r(`first-run-load-status`),M=c();function N(e){n({type:`dashboard-telemetry`,event:`operator_action`,properties:{surface:`onboarding`,action:e}})}function P(e){for(let t of y(A,e))n({type:`dashboard-telemetry`,event:`onboarding_step`,properties:t})&&A.add(p(t))}function F(){return s()?`No supported agent is on PATH of the machine running Glimmervoid. Install Claude Code, Codex or Grok there, then rescan.`:`No supported agent is on PATH. Install Claude Code, Codex or Grok, then rescan.`}function I(){let t=e(`button`,`btn-dialog btn-dialog-cancel`,`Open shell`);return t.type=`button`,t.addEventListener(`click`,()=>{N(`open-shell`),o()}),t}function L(){let t=e(`div`,`first-run-step-actions`);w=e(`button`,`btn-dialog btn-dialog-cancel`,`Rescan`),w.type=`button`,w.addEventListener(`click`,()=>{N(`rescan`),V({rescanAgents:!0})}),t.append(w),E.isShellAvailable&&t.append(I());let n=[e(`p`,`first-run-step-text`,F()),d(x),t];return O?[...n,e(`p`,`first-run-step-hint`,`Still missing after a rescan? Restart Glimmervoid from a terminal where the command runs. Other terminal agents go under customAgents.`)]:n}function R(){let t=T??b({onAdded:e=>{N(e===`typed`?`add-root-typed`:`add-root-suggested`),V({rescanAgents:!1})}});return T=t,[e(`p`,`first-run-step-text`,`The folder that holds your git checkouts. Each subfolder becomes a project you can start a session in.`),t.element]}function z(){let t=e(`div`,`first-run-step-actions`),n=e(`button`,`btn-dialog btn-dialog-confirm`,`+ Session`);return n.type=`button`,n.addEventListener(`click`,()=>{N(`add-session`),l()}),t.append(n),[e(`p`,`first-run-step-text`,`Pick a project and an agent. The session runs in its own git worktree, so your checkout is never touched.`),t]}function B(){if(!C)return;let{steps:e,agentSummary:t,repoRoots:n}=E;C.replaceChildren(u({title:`1. Agent CLI`,state:e.agent,summary:t,badge:`MISSING`,body:L}),u({title:`2. Repository roots`,state:e.repoRoots,summary:n.join(`, `),badge:`NEEDED`,body:R}),u({title:`3. First session`,state:e.firstSession,summary:``,badge:``,body:z}))}async function V({rescanAgents:e}){D+=1;let n=D;w&&(w.disabled=!0);try{let[r,i]=await Promise.all([t(`list-agents`,e?{rescan:!0}:{},{timeoutMs:a}),t(`scan-repo-roots`,{includeSuggestions:!0},{timeoutMs:a})]);if(n!==D)return;let o=i.type===`repo-roots-scanned`,s=o?i.directories.map(e=>e.root):[],c=o?i.suggestions??[]:[],l=h(s,c);if(l.length>0&&!k){k=!0;let e=await g(l).catch(e=>String(e));if(n!==D)return;if(!e){V({rescanAgents:!1});return}}let u=_({agentListing:r,repoRoots:s});e&&(O=u.agent===`current`),E={steps:u,agentSummary:m(r),repoRoots:s,isShellAvailable:f(r)},j.clear(),B(),P(E.steps),T?.setSuggestions(c)}catch(e){if(w&&(w.disabled=!1),n!==D)return;j.show(`error`,`The checklist could not load: ${i(e,a)} It loads again once the server answers. If it stays like this, check the terminal running Glimmervoid, or run glimmervoid doctor.`)}}function H(){if(S)return S;let t=e(`section`,`first-run-checklist`);t.setAttribute(`aria-labelledby`,`first-run-title`);let n=e(`h2`,`first-run-title`,`Get to your first session`);n.id=`first-run-title`,C=e(`ol`,`first-run-steps`);let r=e(`div`,`first-run-optional`);return r.append(e(`span`,`first-run-eyebrow`,`OPTIONAL`),M.element),t.append(e(`span`,`first-run-eyebrow`,`FIRST RUN`),n,C,j.element,r),S=t,B(),t}function U(e,t){if(!t){S?.parentElement===e&&!S.hidden&&(S.hidden=!0);return}let n=H(),r=!n.hidden&&n.parentElement===e;n.parentElement!==e&&e.append(n),n.hidden=!1,M.refresh(),r||V({rescanAgents:!1})}function W(){S&&!S.hidden&&S.isConnected&&V({rescanAgents:!1})}export{W as refreshFirstRunChecklist,U as showFirstRunChecklist};