glimmervoid 0.51.1-next.651 → 0.51.1-next.652
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/glimmervoid.js +4 -4
- package/dist/chunks/{agent-api-cli-aja87UOL.js → agent-api-cli-DgVeVa0h.js} +1 -1
- package/dist/chunks/{agent-api-cli-BdwTL3M6.js → agent-api-cli-m2vQhZQA.js} +1 -1
- package/dist/chunks/{main-BbUntQYI.js → main-CzD_CUEb.js} +1 -1
- package/dist/chunks/{settings-cli-RY1YHU7C.js → settings-cli-79NvDbPA.js} +1 -1
- package/dist/chunks/{shown-files-core-COUHtaR5.js → shown-files-core-Dpas35wM.js} +72 -35
- package/dist/chunks/{ssh-sign-cli-DZaRTIqg.js → ssh-sign-cli-BoN-bVK9.js} +1 -1
- package/dist/client/assets/{benchmark-panel-lirp8NDT.js → benchmark-panel-Bz5I-9Zr.js} +1 -1
- package/dist/client/assets/benchmark-panel-Bz5I-9Zr.js.br +0 -0
- package/dist/client/assets/{boards-view-CkZ3K_7f.js → boards-view-DyRbW9T9.js} +1 -1
- package/dist/client/assets/boards-view-DyRbW9T9.js.br +0 -0
- package/dist/client/assets/{community-panel-DXl7ikzu.js → community-panel-Aazq1i2t.js} +1 -1
- package/dist/client/assets/community-panel-Aazq1i2t.js.br +0 -0
- package/dist/client/assets/{dialogs-CaI33kBT.js → dialogs-zwJu0RSL.js} +1 -1
- package/dist/client/assets/dialogs-zwJu0RSL.js.br +0 -0
- package/dist/client/assets/{doc-editor-ui-Wkvs9BkN.js → doc-editor-ui-DOJ-HDf2.js} +1 -1
- package/dist/client/assets/doc-editor-ui-DOJ-HDf2.js.br +0 -0
- package/dist/client/assets/{feature-hint-DzdXwDJp.js → feature-hint-oGaas9RI.js} +1 -1
- package/dist/client/assets/feature-hint-oGaas9RI.js.br +0 -0
- package/dist/client/assets/{first-run-checklist-CroxSY-O.js → first-run-checklist-BuiZgsm2.js} +1 -1
- package/dist/client/assets/first-run-checklist-BuiZgsm2.js.br +0 -0
- package/dist/client/assets/{hooks-panel-Ci6Uz95t.js → hooks-panel-BSREOnp4.js} +1 -1
- package/dist/client/assets/hooks-panel-BSREOnp4.js.br +0 -0
- package/dist/client/assets/{index-CNU2Do4s.js → index--tEVxxT-.js} +6 -6
- package/dist/client/assets/index--tEVxxT-.js.br +0 -0
- package/dist/client/assets/{issues-panel-B4GN5Mph.js → issues-panel-CFjNhImJ.js} +1 -1
- package/dist/client/assets/issues-panel-CFjNhImJ.js.br +0 -0
- package/dist/client/assets/{lane-read-token-step-h0E5LKWg.js → lane-read-token-step-CKPpsNUN.js} +1 -1
- package/dist/client/assets/lane-read-token-step-CKPpsNUN.js.br +0 -0
- package/dist/client/assets/{my-prs-panel-DiDJPc5X.js → my-prs-panel-Di00nsFC.js} +1 -1
- package/dist/client/assets/my-prs-panel-Di00nsFC.js.br +0 -0
- package/dist/client/assets/{nyan-cat-CKCmJrdo.js → nyan-cat-BGrzrm53.js} +1 -1
- package/dist/client/assets/nyan-cat-BGrzrm53.js.br +0 -0
- package/dist/client/assets/{phone-shell-CYpht3Aj.js → phone-shell-BdHQeaTL.js} +1 -1
- package/dist/client/assets/phone-shell-BdHQeaTL.js.br +0 -0
- package/dist/client/assets/{plan-face-B0xWXbrw.js → plan-face-DFwT8eB0.js} +1 -1
- package/dist/client/assets/plan-face-DFwT8eB0.js.br +0 -0
- package/dist/client/assets/{plan-render-Bre2f3li.js → plan-render-BAPRDzXJ.js} +1 -1
- package/dist/client/assets/plan-render-BAPRDzXJ.js.br +0 -0
- package/dist/client/assets/{pr-queue-columns-5ygGeYVp.js → pr-queue-columns-pYfkxw8K.js} +1 -1
- package/dist/client/assets/pr-queue-columns-pYfkxw8K.js.br +0 -0
- package/dist/client/assets/{radar-panel-h4bLRQYq.js → radar-panel-BjBc0c-A.js} +1 -1
- package/dist/client/assets/radar-panel-BjBc0c-A.js.br +0 -0
- package/dist/client/assets/{repo-roots-adder-C725oApt.js → repo-roots-adder-Bi-L90c6.js} +1 -1
- package/dist/client/assets/repo-roots-adder-Bi-L90c6.js.br +0 -0
- package/dist/client/assets/{resume-dialog-CX3yfT_L.js → resume-dialog-D36UVny8.js} +1 -1
- package/dist/client/assets/resume-dialog-D36UVny8.js.br +0 -0
- package/dist/client/assets/{review-queue-panel-DoSvwUNm.js → review-queue-panel-DAcZSOW9.js} +1 -1
- package/dist/client/assets/review-queue-panel-DAcZSOW9.js.br +0 -0
- package/dist/client/assets/{settings-panel-COutNGIS.js → settings-panel-B1GFg_6X.js} +2 -2
- package/dist/client/assets/settings-panel-B1GFg_6X.js.br +0 -0
- package/dist/client/assets/{shown-face-bwenQwGo.js → shown-face-DHtu4896.js} +1 -1
- package/dist/client/assets/shown-face-DHtu4896.js.br +0 -0
- package/dist/client/assets/{trace-panel-BoyfZaB0.js → trace-panel-D8EtcAlr.js} +1 -1
- package/dist/client/assets/trace-panel-D8EtcAlr.js.br +0 -0
- package/dist/client/assets/{usage-panel-U-xVvIny.js → usage-panel-CX451Hhp.js} +1 -1
- package/dist/client/assets/usage-panel-CX451Hhp.js.br +0 -0
- package/dist/client/assets/{your-day-tip-Bo4UPteV.js → your-day-tip-Cfetu0Ui.js} +1 -1
- package/dist/client/assets/your-day-tip-Cfetu0Ui.js.br +0 -0
- package/dist/client/index.html +1 -1
- package/dist/client/index.html.br +0 -0
- package/dist/server/index.js +1 -1
- package/package.json +1 -1
- package/dist/client/assets/benchmark-panel-lirp8NDT.js.br +0 -0
- package/dist/client/assets/boards-view-CkZ3K_7f.js.br +0 -0
- package/dist/client/assets/community-panel-DXl7ikzu.js.br +0 -0
- package/dist/client/assets/dialogs-CaI33kBT.js.br +0 -0
- package/dist/client/assets/doc-editor-ui-Wkvs9BkN.js.br +0 -0
- package/dist/client/assets/feature-hint-DzdXwDJp.js.br +0 -0
- package/dist/client/assets/first-run-checklist-CroxSY-O.js.br +0 -0
- package/dist/client/assets/hooks-panel-Ci6Uz95t.js.br +0 -0
- package/dist/client/assets/index-CNU2Do4s.js.br +0 -0
- package/dist/client/assets/issues-panel-B4GN5Mph.js.br +0 -0
- package/dist/client/assets/lane-read-token-step-h0E5LKWg.js.br +0 -0
- package/dist/client/assets/my-prs-panel-DiDJPc5X.js.br +0 -0
- package/dist/client/assets/nyan-cat-CKCmJrdo.js.br +0 -0
- package/dist/client/assets/phone-shell-CYpht3Aj.js.br +0 -0
- package/dist/client/assets/plan-face-B0xWXbrw.js.br +0 -0
- package/dist/client/assets/plan-render-Bre2f3li.js.br +0 -0
- package/dist/client/assets/pr-queue-columns-5ygGeYVp.js.br +0 -0
- package/dist/client/assets/radar-panel-h4bLRQYq.js.br +0 -0
- package/dist/client/assets/repo-roots-adder-C725oApt.js.br +0 -0
- package/dist/client/assets/resume-dialog-CX3yfT_L.js.br +0 -0
- package/dist/client/assets/review-queue-panel-DoSvwUNm.js.br +0 -0
- package/dist/client/assets/settings-panel-COutNGIS.js.br +0 -0
- package/dist/client/assets/shown-face-bwenQwGo.js.br +0 -0
- package/dist/client/assets/trace-panel-BoyfZaB0.js.br +0 -0
- package/dist/client/assets/usage-panel-U-xVvIny.js.br +0 -0
- package/dist/client/assets/your-day-tip-Bo4UPteV.js.br +0 -0
package/dist/bin/glimmervoid.js
CHANGED
|
@@ -73,11 +73,11 @@ var OWNED_COMMAND_RUNNERS = {
|
|
|
73
73
|
return runAgentSetupCli();
|
|
74
74
|
},
|
|
75
75
|
settings: async (parsed) => {
|
|
76
|
-
const { runParsedSettingsCli } = await import("../chunks/settings-cli-
|
|
76
|
+
const { runParsedSettingsCli } = await import("../chunks/settings-cli-79NvDbPA.js");
|
|
77
77
|
return runParsedSettingsCli(parsed);
|
|
78
78
|
},
|
|
79
79
|
"ssh-sign": async ({ rawArgs }) => {
|
|
80
|
-
const { runSshSignCli } = await import("../chunks/ssh-sign-cli-
|
|
80
|
+
const { runSshSignCli } = await import("../chunks/ssh-sign-cli-BoN-bVK9.js");
|
|
81
81
|
return runSshSignCli(rawArgs);
|
|
82
82
|
}
|
|
83
83
|
};
|
|
@@ -99,7 +99,7 @@ async function runOwnedCommand(name, subcommandArgs) {
|
|
|
99
99
|
return OWNED_COMMAND_RUNNERS[name](parsed);
|
|
100
100
|
}
|
|
101
101
|
var SUBCOMMAND_RUNNERS = new Map([...Object.keys(OWNED_COMMAND_SPECS).filter(isOwnedCommandName).map((name) => [name, (subcommandArgs) => runOwnedCommand(name, subcommandArgs)]), ...AGENT_API_VERBS.filter((verb) => !isOwnedCommandName(verb)).map((verb) => [verb, async (subcommandArgs, subcommandName) => {
|
|
102
|
-
const { runAgentApiCli } = await import("../chunks/agent-api-cli-
|
|
102
|
+
const { runAgentApiCli } = await import("../chunks/agent-api-cli-m2vQhZQA.js");
|
|
103
103
|
return runAgentApiCli([subcommandName, ...subcommandArgs]);
|
|
104
104
|
}])]);
|
|
105
105
|
var AGENT_INSTALL_COMMAND_BY_ID = {
|
|
@@ -113,7 +113,7 @@ function missingAgentText(agentId) {
|
|
|
113
113
|
}
|
|
114
114
|
async function printSessionLimits() {
|
|
115
115
|
if (!process.env["GLIMMERVOID_AGENT_URL"]) return;
|
|
116
|
-
const { sessionLimitsHelpLines } = await import("../chunks/agent-api-cli-
|
|
116
|
+
const { sessionLimitsHelpLines } = await import("../chunks/agent-api-cli-m2vQhZQA.js");
|
|
117
117
|
const limitsLines = await sessionLimitsHelpLines();
|
|
118
118
|
console.log(`\n${limitsLines.join("\n")}`);
|
|
119
119
|
}
|
|
@@ -2,7 +2,7 @@ import { Q as UNIT_STATUSES, l as AgentLimitsReply, nt as WhiteboardAgentReply,
|
|
|
2
2
|
import { J as formatSessionLimits, i as agentCommandSpec, m as isAgentApiVerb, rt as parseCommand, t as AGENT_COMMAND_HELP } from "./agent-api-core-CWPNeptA.js";
|
|
3
3
|
import { i as resolveHookTarget } from "./hook-relay-core-DA_bz2KA.js";
|
|
4
4
|
import { t as parseJsonOrNull } from "./json-core-If8h-Qgy.js";
|
|
5
|
-
import { g as layoutBoard, i as describeOverCap, m as boardSvgDocument, y as planSteps } from "./shown-files-core-
|
|
5
|
+
import { g as layoutBoard, i as describeOverCap, m as boardSvgDocument, y as planSteps } from "./shown-files-core-Dpas35wM.js";
|
|
6
6
|
import fs from "node:fs";
|
|
7
7
|
import path from "node:path";
|
|
8
8
|
import http from "node:http";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as askAgentApi, r as runAgentApiCli, i as sessionLimitsHelpLines } from "./agent-api-cli-
|
|
1
|
+
export { t as askAgentApi, r as runAgentApiCli, i as sessionLimitsHelpLines } from "./agent-api-cli-DgVeVa0h.js";
|
|
@@ -13,7 +13,7 @@ import { n as promptContextReplyOf, o as toolHookContextReplyOf, r as refocusRep
|
|
|
13
13
|
import { n as parseJsonRecord, t as parseJsonOrNull } from "./json-core-If8h-Qgy.js";
|
|
14
14
|
import { a as saneYoloFiles } from "./sane-yolo-BjUkqIoH.js";
|
|
15
15
|
import { r as knownWriteHookInput } from "./posthog-read-gate-core-CeSY56AB.js";
|
|
16
|
-
import { _ as cappedWarnings, a as filesAfterRetention, b as unitsOf, c as readPageTitle, d as thumbnailFilenameOf, f as thumbnailOwnerIdOf, g as layoutBoard, h as escapeMarkup, i as describeOverCap, l as shownMimeForFilename, m as boardSvgDocument, n as SHOWN_SNIFF_BYTES, o as isShownPageMime, p as thumbnailRecipeFor, r as decideShownKind, s as leavesVisibleRawTextOpen, t as SHOWN_PAGE_ZOOM_BRIDGE, u as sniffRasterImageMime, v as findDependencyCycle, y as planSteps$1 } from "./shown-files-core-
|
|
16
|
+
import { _ as cappedWarnings, a as filesAfterRetention, b as unitsOf, c as readPageTitle, d as thumbnailFilenameOf, f as thumbnailOwnerIdOf, g as layoutBoard, h as escapeMarkup, i as describeOverCap, l as shownMimeForFilename, m as boardSvgDocument, n as SHOWN_SNIFF_BYTES, o as isShownPageMime, p as thumbnailRecipeFor, r as decideShownKind, s as leavesVisibleRawTextOpen, t as SHOWN_PAGE_ZOOM_BRIDGE, u as sniffRasterImageMime, v as findDependencyCycle, y as planSteps$1 } from "./shown-files-core-Dpas35wM.js";
|
|
17
17
|
import { c as parsePresentedCredential, n as shellQuote, s as mcpLaunchFor } from "./hook-command-core-5G0De2KV.js";
|
|
18
18
|
import { C as parseCgroupBytes, D as DEFAULT_MAX_MS, E as DEFAULT_BASE_MS, O as nextBackoffMs, S as memoryReserveBytes, T as parseMemAvailableBytes, _ as createSpawnGate, a as jsonStateLoadError, b as cgroupLimitBytes, c as loadedJsonValue, d as writeJsonAtomicSync, g as createSerialQueue, h as createMemoryAdmission, i as createJsonStateWriter, m as createKeyedSerialQueue, n as appendJsonLines, o as loadJsonStateFile, p as writeTextAtomicSync, r as createJsonStateStore, s as loadJsonStateFileSync, t as appendJsonLine, u as writeJsonAtomic, v as isQueueAdmissionTimeout, w as parseCgroupV2Path, x as headroomFromReadings, y as cgroupAncestorPaths } from "./json-file-AKRVPqG1.js";
|
|
19
19
|
import { $ as buildBrowserExceptionProperties, D as validateSettingsBlock, E as settingsBlockSpecFor, G as describeDataAttach, H as DEEP_HISTORY_SCROLLBACK_LINES, J as FIRST_RUN_NOTICE, K as parseDataAttach, O as SETTINGS_INDEX, Q as buildAiGenerationEvents, R as valueAtPath, St as isSameDirectoryPath, T as mergeSettingsBlock, V as isExperimentalSetting, W as LOGGED_FAST_CLOSE_COUNTS, X as TELEMETRY_FLAGS_URL, Y as TELEMETRY_BATCH_URL, Z as adapterBucket, _ as usablePrefixes, a as generateProjectId, at as decideIsDevInstall, b as unrefTimer, bt as canonicalizePath, ct as exceptionFingerprint, d as DEFAULT_CONFIG, dt as resolveProjectToken, et as buildExceptionProperties, f as DEFAULT_BRANCH_GC_PREFIXES, ft as DashboardTelemetryReport, g as sessionIdFromBranch, h as planWorktreeGc, ht as TelemetryState, i as ensureProjectIds, it as codexUserIdOf, lt as nodeMajorVersion, m as planBranchGc, mt as TELEMETRY_EVENT_SCHEMAS, n as createConfigStore, nt as classifySessionExit, o as glimmervoidHomeDir$1, ot as decideRemoteTelemetryState, p as matchedPrefix, pt as PendingCrashReport, q as parseDataClientMessage, r as ABORT_CONFIG_SAVE, rt as claudeAccountUuidOf, st as decideTelemetryConsent, tt as buildPersonProperties, ut as parsePosthogReleaseId, v as worktreeIntegrationTips, vt as stableConfigKey, xt as comparableDirectoryPath, y as DEFAULT_TIMER_FNS } from "./config-store-DVWnxI-S.js";
|
|
@@ -303,7 +303,7 @@ function runParsedSettingsCommand(parsed, io) {
|
|
|
303
303
|
async function runParsedSettingsCli(parsed, io = processIo()) {
|
|
304
304
|
const serverRequest = settingsRequestForServer(parsed, process.env);
|
|
305
305
|
if (!serverRequest) return runParsedSettingsCommand(parsed, io);
|
|
306
|
-
const { askAgentApi } = await import("./agent-api-cli-
|
|
306
|
+
const { askAgentApi } = await import("./agent-api-cli-m2vQhZQA.js");
|
|
307
307
|
const reply = AgentSettingsReply.safeParse(await askAgentApi("settings", serverRequest).catch((error) => ({
|
|
308
308
|
ok: false,
|
|
309
309
|
error: errorMessage(error)
|
|
@@ -754,9 +754,9 @@ function reconstructNodes(cameFrom, goalState) {
|
|
|
754
754
|
for (let state = goalState; state !== -1; state = cameFrom[state] ?? -1) states.push(state);
|
|
755
755
|
return states.reverse();
|
|
756
756
|
}
|
|
757
|
-
function
|
|
757
|
+
function adjustUsage(grid, usage, plan, states, delta) {
|
|
758
758
|
const width = grid.xs.length;
|
|
759
|
-
const increment = (countByKey, key) => countByKey.set(key, (countByKey.get(key) ?? 0) +
|
|
759
|
+
const increment = (countByKey, key) => countByKey.set(key, (countByKey.get(key) ?? 0) + delta);
|
|
760
760
|
const remember = (usageByKey, key) => {
|
|
761
761
|
const keyUsage = usageByKey.get(key) ?? {
|
|
762
762
|
total: 0,
|
|
@@ -765,7 +765,7 @@ function recordUsage(grid, usage, plan, states) {
|
|
|
765
765
|
countByBusAndExitKey: /* @__PURE__ */ new Map()
|
|
766
766
|
};
|
|
767
767
|
usageByKey.set(key, keyUsage);
|
|
768
|
-
keyUsage.total +=
|
|
768
|
+
keyUsage.total += delta;
|
|
769
769
|
increment(keyUsage.countByExitKey, plan.exitKey);
|
|
770
770
|
if (plan.busKey === null) return;
|
|
771
771
|
increment(keyUsage.countByBusKey, plan.busKey);
|
|
@@ -813,6 +813,26 @@ function backInteriorOf(plan, loopFrames) {
|
|
|
813
813
|
if (!span) return null;
|
|
814
814
|
return loopFrames.find((frame) => frame.x <= span.x && frame.y <= span.y && frame.x + frame.width >= span.x + span.width && frame.y + frame.height >= span.y + span.height) ?? span;
|
|
815
815
|
}
|
|
816
|
+
function longestFirst(items, planOf) {
|
|
817
|
+
const routeLength = (plan) => Math.abs(plan.start.x - plan.end.x) + Math.abs(plan.start.y - plan.end.y);
|
|
818
|
+
return [...items].sort((left, right) => routeLength(planOf(right)) - routeLength(planOf(left)) || planOf(left).wire.id.localeCompare(planOf(right).wire.id));
|
|
819
|
+
}
|
|
820
|
+
function drawnWireOf(grid, plan, states) {
|
|
821
|
+
const points = grid && states ? withoutBends(states.map((state) => {
|
|
822
|
+
const node = state >> 2;
|
|
823
|
+
const xIndex = node % grid.xs.length;
|
|
824
|
+
return {
|
|
825
|
+
x: grid.xs[xIndex] ?? 0,
|
|
826
|
+
y: grid.ys[(node - xIndex) / grid.xs.length] ?? 0
|
|
827
|
+
};
|
|
828
|
+
})) : fallbackPoints(plan);
|
|
829
|
+
return {
|
|
830
|
+
plan,
|
|
831
|
+
points,
|
|
832
|
+
segments: segmentsOf(points),
|
|
833
|
+
states
|
|
834
|
+
};
|
|
835
|
+
}
|
|
816
836
|
function routeAll(plans, input, budget) {
|
|
817
837
|
const grid = buildGrid(plans, [...input.boxesById.values(), ...input.panels], input.softObstacles, input.contentTop);
|
|
818
838
|
const buffers = grid ? createSearchBuffers(grid) : null;
|
|
@@ -820,28 +840,44 @@ function routeAll(plans, input, budget) {
|
|
|
820
840
|
usageByEdge: /* @__PURE__ */ new Map(),
|
|
821
841
|
usageByNodeAndAxis: /* @__PURE__ */ new Map()
|
|
822
842
|
};
|
|
823
|
-
const routeLength = (plan) => Math.abs(plan.start.x - plan.end.x) + Math.abs(plan.start.y - plan.end.y);
|
|
824
|
-
const ordered = [...plans].sort((left, right) => routeLength(right) - routeLength(left) || left.wire.id.localeCompare(right.wire.id));
|
|
825
843
|
const drawnById = /* @__PURE__ */ new Map();
|
|
826
|
-
for (const plan of
|
|
844
|
+
for (const plan of longestFirst(plans, (plan) => plan)) {
|
|
827
845
|
const states = grid && buffers ? routeOnGrid(grid, plan, usage, backInteriorOf(plan, input.loopFrames), buffers, budget) : null;
|
|
828
|
-
if (grid && states)
|
|
829
|
-
|
|
830
|
-
const node = state >> 2;
|
|
831
|
-
const xIndex = node % grid.xs.length;
|
|
832
|
-
return {
|
|
833
|
-
x: grid.xs[xIndex] ?? 0,
|
|
834
|
-
y: grid.ys[(node - xIndex) / grid.xs.length] ?? 0
|
|
835
|
-
};
|
|
836
|
-
})) : fallbackPoints(plan);
|
|
837
|
-
drawnById.set(plan.wire.id, {
|
|
838
|
-
plan,
|
|
839
|
-
points,
|
|
840
|
-
segments: segmentsOf(points),
|
|
841
|
-
isFallback: !states
|
|
842
|
-
});
|
|
846
|
+
if (grid && states) adjustUsage(grid, usage, plan, states, 1);
|
|
847
|
+
drawnById.set(plan.wire.id, drawnWireOf(grid, plan, states));
|
|
843
848
|
}
|
|
844
|
-
return
|
|
849
|
+
return {
|
|
850
|
+
drawn: plans.flatMap((plan) => drawnById.get(plan.wire.id) ?? []),
|
|
851
|
+
grid,
|
|
852
|
+
usage
|
|
853
|
+
};
|
|
854
|
+
}
|
|
855
|
+
function bendCountOf(wire) {
|
|
856
|
+
return Math.max(0, wire.points.length - 2);
|
|
857
|
+
}
|
|
858
|
+
function crossingCostOf(wire, others, input) {
|
|
859
|
+
const wireCrossingCount = others.filter((other) => pairCrossingOf(wire, other) !== null).length;
|
|
860
|
+
return findBoxCrossings([wire], input).length * BOX_CROSSING_COST + wireCrossingCount;
|
|
861
|
+
}
|
|
862
|
+
function rerouteCrossedWires(routed, input) {
|
|
863
|
+
const { grid, usage } = routed;
|
|
864
|
+
if (!grid) return routed.drawn;
|
|
865
|
+
const buffers = createSearchBuffers(grid);
|
|
866
|
+
const budget = { remainingExpansions: MAX_TOTAL_EXPANSIONS };
|
|
867
|
+
const drawnById = new Map(routed.drawn.map((wire) => [wire.plan.wire.id, wire]));
|
|
868
|
+
for (const current of longestFirst(routed.drawn, (wire) => wire.plan)) {
|
|
869
|
+
if (!current.states || budget.remainingExpansions <= 0) continue;
|
|
870
|
+
const others = [...drawnById.values()].filter((other) => other.plan !== current.plan);
|
|
871
|
+
const currentCost = crossingCostOf(current, others, input);
|
|
872
|
+
if (currentCost === 0) continue;
|
|
873
|
+
adjustUsage(grid, usage, current.plan, current.states, -1);
|
|
874
|
+
const rerouted = drawnWireOf(grid, current.plan, routeOnGrid(grid, current.plan, usage, backInteriorOf(current.plan, input.loopFrames), buffers, budget));
|
|
875
|
+
const staysWithinBendLimit = bendCountOf(rerouted) <= Math.max(bendCountOf(current), MAX_BENDS);
|
|
876
|
+
const kept = rerouted.states && staysWithinBendLimit && crossingCostOf(rerouted, others, input) < currentCost ? rerouted : current;
|
|
877
|
+
adjustUsage(grid, usage, kept.plan, kept.states ?? current.states, 1);
|
|
878
|
+
drawnById.set(kept.plan.wire.id, kept);
|
|
879
|
+
}
|
|
880
|
+
return routed.drawn.map((wire) => drawnById.get(wire.plan.wire.id) ?? wire);
|
|
845
881
|
}
|
|
846
882
|
function labelWidthOf(label) {
|
|
847
883
|
return Math.ceil(label.length * LABEL_CHAR_WIDTH);
|
|
@@ -940,13 +976,14 @@ function areSiblings(first, second) {
|
|
|
940
976
|
if (first.plan.busKey !== null && first.plan.busKey === second.plan.busKey) return true;
|
|
941
977
|
return first.plan.exitKey === second.plan.exitKey;
|
|
942
978
|
}
|
|
979
|
+
function pairCrossingOf(first, second) {
|
|
980
|
+
if (areSiblings(first, second)) return null;
|
|
981
|
+
const pairs = first.segments.flatMap((firstSegment) => second.segments.map((secondSegment) => [firstSegment, secondSegment]));
|
|
982
|
+
if (pairs.some(([firstSegment, secondSegment]) => segmentsCross(firstSegment, secondSegment))) return `wire ${first.plan.wire.id} crosses wire ${second.plan.wire.id}`;
|
|
983
|
+
return pairs.some(([firstSegment, secondSegment]) => segmentsOverlap(firstSegment, secondSegment)) ? `wire ${first.plan.wire.id} overlaps wire ${second.plan.wire.id}` : null;
|
|
984
|
+
}
|
|
943
985
|
function findCrossings(drawn) {
|
|
944
|
-
return drawn.flatMap((first, index) => drawn.slice(index + 1).flatMap((second) =>
|
|
945
|
-
if (areSiblings(first, second)) return [];
|
|
946
|
-
const pairs = first.segments.flatMap((firstSegment) => second.segments.map((secondSegment) => [firstSegment, secondSegment]));
|
|
947
|
-
if (pairs.some(([firstSegment, secondSegment]) => segmentsCross(firstSegment, secondSegment))) return [`wire ${first.plan.wire.id} crosses wire ${second.plan.wire.id}`];
|
|
948
|
-
return pairs.some(([firstSegment, secondSegment]) => segmentsOverlap(firstSegment, secondSegment)) ? [`wire ${first.plan.wire.id} overlaps wire ${second.plan.wire.id}`] : [];
|
|
949
|
-
}));
|
|
986
|
+
return drawn.flatMap((first, index) => drawn.slice(index + 1).flatMap((second) => pairCrossingOf(first, second) ?? []));
|
|
950
987
|
}
|
|
951
988
|
function findBoxCrossings(drawn, input) {
|
|
952
989
|
const solids = [...input.boxesById.values(), ...input.panels];
|
|
@@ -958,8 +995,8 @@ function findBoxCrossings(drawn, input) {
|
|
|
958
995
|
}
|
|
959
996
|
function routeQualityWarnings(drawn) {
|
|
960
997
|
return drawn.flatMap((wire) => {
|
|
961
|
-
if (wire.
|
|
962
|
-
const bends =
|
|
998
|
+
if (!wire.states) return [`wire ${wire.plan.wire.id} found no clear route, so it is drawn as a straight dog-leg`];
|
|
999
|
+
const bends = bendCountOf(wire);
|
|
963
1000
|
return bends > MAX_BENDS ? [`wire ${wire.plan.wire.id} bends ${bends} times`] : [];
|
|
964
1001
|
});
|
|
965
1002
|
}
|
|
@@ -983,15 +1020,15 @@ function swapNeighbors(order, index) {
|
|
|
983
1020
|
function routeWithPortOrder(plans, input, requestsBySide, groupOrderBySide, budget) {
|
|
984
1021
|
assignPorts(requestsBySide, groupOrderBySide);
|
|
985
1022
|
alignLonePorts(plans, groupOrderBySide);
|
|
986
|
-
const
|
|
1023
|
+
const routed = routeAll(plans, input, budget);
|
|
987
1024
|
return {
|
|
988
|
-
|
|
989
|
-
crossingCost: findBoxCrossings(drawn, input).length * BOX_CROSSING_COST + findCrossings(drawn).length
|
|
1025
|
+
routed,
|
|
1026
|
+
crossingCost: findBoxCrossings(routed.drawn, input).length * BOX_CROSSING_COST + findCrossings(routed.drawn).length
|
|
990
1027
|
};
|
|
991
1028
|
}
|
|
992
1029
|
function routeWithFewestCrossings(plans, input, requestsBySide, groupOrderBySide, budget) {
|
|
993
1030
|
let best = routeWithPortOrder(plans, input, requestsBySide, groupOrderBySide, budget);
|
|
994
|
-
if (plans.length > MAX_WIRES_FOR_PORT_SEARCH) return best.
|
|
1031
|
+
if (plans.length > MAX_WIRES_FOR_PORT_SEARCH) return rerouteCrossedWires(best.routed, input);
|
|
995
1032
|
for (const groupOrder of groupOrderBySide.values()) for (let index = 0; best.crossingCost > 0 && index + 1 < groupOrder.length; index += 1) {
|
|
996
1033
|
swapNeighbors(groupOrder, index);
|
|
997
1034
|
const trial = routeWithPortOrder(plans, input, requestsBySide, groupOrderBySide, budget);
|
|
@@ -1001,7 +1038,7 @@ function routeWithFewestCrossings(plans, input, requestsBySide, groupOrderBySide
|
|
|
1001
1038
|
}
|
|
1002
1039
|
swapNeighbors(groupOrder, index);
|
|
1003
1040
|
}
|
|
1004
|
-
return routeWithPortOrder(plans, input, requestsBySide, groupOrderBySide, budget).
|
|
1041
|
+
return rerouteCrossedWires(routeWithPortOrder(plans, input, requestsBySide, groupOrderBySide, budget).routed, input);
|
|
1005
1042
|
}
|
|
1006
1043
|
function routeWires(input) {
|
|
1007
1044
|
const plans = planWires(input);
|
|
@@ -2,7 +2,7 @@ import { r as errorMessage } from "./text-DoirglWV.js";
|
|
|
2
2
|
import { L as SshSignReply, j as SIGN_URL_ENV } from "./session-D-C2x8yg.js";
|
|
3
3
|
import { c as spawn, r as execFileAsync } from "./child-process-safe-BCOoKfxG.js";
|
|
4
4
|
import { a as isLoopbackHostname } from "./hook-relay-core-DA_bz2KA.js";
|
|
5
|
-
import { n as postToAgentIngress } from "./agent-api-cli-
|
|
5
|
+
import { n as postToAgentIngress } from "./agent-api-cli-DgVeVa0h.js";
|
|
6
6
|
import { l as parseSshPublicKey } from "./ssh-signing-core-CRhVVWNW.js";
|
|
7
7
|
import path from "node:path";
|
|
8
8
|
import fs from "node:fs/promises";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./button-C22nHZZN.js";import{n as t,r as n,s as r}from"./dom-helpers-qjWTsLGI.js";import{Fi as i,Ii as a,Li as o}from"./index
|
|
1
|
+
import{t as e}from"./button-C22nHZZN.js";import{n as t,r as n,s as r}from"./dom-helpers-qjWTsLGI.js";import{Fi as i,Ii as a,Li as o}from"./index--tEVxxT-.js";var s={mine:`Mine`,run:`Run`,cancel:`Cancel`},c=null;function l(e){return e===null?`n/a`:`${Math.round(e*100)}%`}function u(e){if(e===null)return`n/a`;let t=Math.round(e*100);return t>0?`+${t}`:String(t)}function d(t,n,r){return e({variant:n===`cancel`?`secondary`:`primary`,size:`small`,label:s[n],action:`benchmark-${n}`,disabled:r,onClick:()=>a(t.id,n)})}function f(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 p(e){let t=r(`td`,`bench-score`,l(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 m(e){let t=e.armIds.filter(t=>t!==e.baselineArm),n=r(`table`,`bench-table`),i=r(`tr`);i.append(r(`th`,null,`Case`),...e.armIds.map(t=>r(`th`,null,t===e.baselineArm?`${t} (baseline)`:t))),i.append(...t.map(e=>r(`th`,null,`${e} vs baseline`))),n.append(i);for(let i of e.rows){let a=r(`tr`);a.append(r(`td`,`bench-case`,i.caseId),...e.armIds.map(e=>p(i.arms[e]))),a.append(...t.map(e=>r(`td`,`bench-delta`,u(i.deltaVsBaseline[e]??null)))),n.append(a)}let a=[...new Set(e.armIds.flatMap(t=>Object.keys(e.totals[t]?.recallByTag??{})))].sort(),o=r(`tr`,`bench-total`);o.append(r(`td`,`bench-case`,`Paired recall`),...e.armIds.map(t=>p(e.totals[t]))),n.append(o);for(let t of a){let i=r(`tr`,`bench-total`);i.append(r(`td`,`bench-case`,`Recall, ${t}`),...e.armIds.map(n=>r(`td`,`bench-score`,l(e.totals[n]?.recallByTag[t]??null)))),n.append(i)}return n}function h(e,t){let{isServerConnected:a,pendingActionBySuite:o,outcomeBySuite:s}=i(),c=r(`div`,`bench-suite`),l=e.inFlight?.suiteId===t.id,u=!!e.inFlight&&!l,p=o.has(t.id)||!a,h=r(`div`,`bench-summary`);h.append(r(`span`,`bench-suite-title`,t.title),n(`bench`,t.caseCount===1?`case`:`cases`,String(t.caseCount)),n(`bench`,t.candidateCount===1?`candidate`:`candidates`,String(t.candidateCount)),n(`bench`,`arms`,String(t.armIds.length))),c.append(h);let g=r(`div`,`bench-controls`),_=e.configured===!0&&t.error===null;g.append(d(t,`mine`,!_||p||l),d(t,`run`,!_||p||l||u||t.caseCount===0),d(t,`cancel`,p||!l));let v=r(`span`,`bench-status`,(a?``:`Not connected to the server. Reconnecting.`)||f(e,t)||s.get(t.id)||``);if(v.setAttribute(`role`,`status`),g.append(v),c.append(g),t.error)return c.append(r(`p`,`bench-error`,t.error)),c;let y=t.latestReport;return y?(c.append(r(`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(m(y)),c):(c.append(r(`p`,`bench-empty`,t.caseCount===0?`Move approved candidates into the cases folder, then choose Run.`:`No run yet.`)),c)}function g(){if(!c)return;c.textContent=``;let{status:e}=i(),n=t(`bench`,`Benchmarks`,`Suites from the benchmarks folder of the Glimmervoid home, one run at a time.`);if(c.append(n),!e)c.append(r(`p`,`bench-empty`,`Waiting for the server.`));else if(!e.configured)c.append(r(`p`,`bench-empty`,e.reason||`Benchmarks are off.`));else if(e.suites.length===0)c.append(r(`p`,`bench-empty`,`No suites yet. Create a folder holding suite.json under benchmarks in the Glimmervoid home.`));else for(let t of e.suites)c.append(h(e,t))}function _(e){c||(c=r(`div`,`bench-content`),e.append(c),o(g),g())}var v={mount:_};export{v as view};
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{B as e,P as t,R as n,_n as r,a as i,cn as a,gn as o,ln as s,mn as c,r as l,t as u,z as d}from"./button-C22nHZZN.js";import{f,s as p}from"./dom-helpers-qjWTsLGI.js";import{a as m,i as h,n as g}from"./modal-BOO8fI5C.js";import{a as _,r as v}from"./card-registry-CRupHUTh.js";import{i as y}from"./action-status-DaZn2p-M.js";import{En as b,Ln as x,Rn as S,_t as C,at as ee,ct as te,dt as w,ft as ne,gt as re,ht as T,it as E,lt as ie,mt as ae,ot as oe,pt as se,rt as D,st as ce,ut as le,vt as ue,yt as de}from"./index-CNU2Do4s.js";Object.freeze({unitWarnings:[],uncoveredPaths:[],worthALookPaths:[],flaggedUnitIds:[],notChecked:null});var fe=/^([^#\s]+)(?:#L([1-9]\d*)(?:-L([1-9]\d*))?)?$/;function pe(e){return e.startsWith(`/`)||e.startsWith(`\\`)||/^[A-Za-z]:/.test(e)}function me(e){return e.split(`/`).filter(e=>e!==``&&e!==`.`).join(`/`)}function he(e){let t=fe.exec(e);if(!t?.[1])return{error:`a ref is path, path#L12 or path#L12-L30`};let n=t[1];if(pe(n))return{error:`an absolute path is never read; name the file relative to the code session worktree`};if(n.split(/[\\/]/).includes(`..`))return{error:`a path with .. is never read; name the file relative to the code session worktree`};let r=t[2]?Number(t[2]):null,i=t[3]?Number(t[3]):r;return r!==null&&i!==null&&i<r?{error:`the line range ends before it starts`}:{path:me(n),startLine:r,endLine:i}}function O(e,t,n){return n.flatMap((n,r)=>n.ref?[{elementId:t,ref:n.ref,where:`line ${r+1} of ${e}`}]:[])}function ge(e){let t=`${e.kind} ${e.id}`;switch(e.kind){case`box`:case`unit`:return[...e.refs.map(n=>({elementId:e.id,ref:n,where:t})),...O(t,e.id,e.lines)];case`panel`:return O(t,e.id,e.lines);case`note`:return e.ref?[{elementId:e.id,ref:e.ref,where:t}]:[];case`frame`:case`wire`:return[]}}function _e(e){return[...new Set(ge(e).map(e=>e.ref))]}function ve(e){let t=he(e);return`path`in t?t.path:null}var ye=4,be=200,xe=2e4,Se=1.1,Ce=[`wire`,`note`,`frame`,`box`,`panel`,`unit`],we={v:`select`,r:`box`,d:`decision`,p:`panel`,a:`wire`};function k(e){let t=Math.random().toString(36).slice(2,8);return`${e}-${Date.now().toString(36)}${t}`}function A(){return document.documentElement.dataset.layout===`phone`}function Te(e){return e instanceof SVGCircleElement&&e.classList.contains(`wb-port`)?e:null}function Ee(e){return e===`box`||e===`decision`||e===`panel`}function De(e,t,n){if(e===`panel`){let e=Math.max(-1,...Object.values(t.elements).map(e=>e.kind===`panel`?e.order:-1));return{kind:`panel`,id:k(`panel`),title:`Panel`,lines:[],order:e+1}}return e===`decision`?Oe(n,`Decision`,null,!0):Oe(n,`Box`,null,!1)}function Oe(e,t,n,r){return{kind:`box`,id:k(`box`),title:t,lines:[],lane:null,refs:[],change:`none`,was:null,column:null,near:null,order:0,at:e,shape:r?`decision`:`box`,outputs:r?[{id:`yes`,label:`yes`},{id:`no`,label:`no`}]:[],image:n,width:null}}function ke(e){if(!(e instanceof Element))return null;let t=e.closest(`image.wb-image`),n=t?.getAttribute(`href`);return!t||!n?null:{href:n,alt:t.querySelector(`title`)?.textContent??``}}function Ae(e){return e instanceof SVGRectElement&&e.classList.contains(`wb-resize-handle`)}function je(e){return e instanceof Element?e.closest(`[data-linked-board-id]`)?.dataset.linkedBoardId??null:null}var Me=2,Ne=12/10;function Pe(e){let{svg:t,canvas:n,renderer:i}=e,a=new Map,o=new Set,s={x:0,y:0,width:1e3,height:600},c=null,l=null,u=null,d=`select`,f=null,m=!1;function h(n){d=n,t.dataset.tool=n,e.onToolChange(n)}function g(){t.setAttribute(`viewBox`,`${s.x} ${s.y} ${s.width} ${s.height}`)}function _(){let e=t.getBoundingClientRect(),r=[...n.querySelectorAll(`.wb-island`)].filter(e=>e.checkVisibility()).map(e=>e.getBoundingClientRect()),i=e.top+e.height/2,a=r.filter(e=>e.top+e.height/2<i).map(t=>t.bottom-e.top),o=r.filter(e=>e.top+e.height/2>=i).map(t=>t.top-e.top),s=Math.max(0,...a),c=Math.min(e.height,...o)-s;return c<e.height/2?{topPx:0,heightPx:e.height}:{topPx:s,heightPx:c}}function v(){let e=i.layout();if(!e)return;let{bounds:n}=e,r=t.clientWidth,a=t.clientHeight;if(r===0||a===0){s={...n},g(),m=!0;return}m=!1;let o=_(),c=e.elements.length===0?1:Me,l=Math.max(1/c,n.width/r,n.height/o.heightPx),u=l>Ne,d=u?Ne:l,f=r*d,p=n.y+n.height/2,h=o.topPx+o.heightPx/2;s={x:n.x-Math.max(0,f-n.width)/2,y:u?n.y-o.topPx*d:p-h*d,width:f,height:a*d},g()}function y(e,n){let r=t.getScreenCTM();if(!r)return{x:e,y:n};let i=new DOMPoint(e,n).matrixTransform(r.inverse());return{x:i.x,y:i.y}}function b(){let e=t.clientWidth||1,n=t.clientHeight||1;return Math.max(s.width/e,s.height/n)}function x(e,t){let n=Math.min(xe,Math.max(be,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},g()}function S(e,t){let n=b();s={...s,x:s.x-e*n,y:s.y-t*n},g()}function C(t){o=t,i.setSelection(o),e.onSelectionChange(o)}function ee(e,t){if(!t){C(o.has(e)&&o.size===1?new Set:new Set([e]));return}let n=new Set(o);n.delete(e)||n.add(e),C(n)}function te(e){return{x:Math.round(e.start.x+e.latest.x-e.origin.x),y:Math.round(e.start.y+e.latest.y-e.origin.y-e.pinnedOffsetY)}}function w(e){let t=Math.round(e.start.width+e.latest.x-e.origin.x);return Math.min(r.boxWidthMax,Math.max(r.boxWidthMin,t))}function ne(e){return e.mode===`resize`?{width:w(e)}:{at:te(e)}}function re(e,t,n){let r=e.elements[t];return r?.kind===`box`?{...e,elements:{...e.elements,[t]:{...r,...n}}}:e}function T(e){return c?.kind!==`drag`||!c.hasMoved?e:re(e,c.boxId,ne(c))}function E(){u!==null&&cancelAnimationFrame(u),u=null}function ie(){E();let t=e.currentBoard();t&&i.render(T(t))}function ae(){u===null&&(u=requestAnimationFrame(ie))}function oe(e){c?.kind===`drag`&&e?.elements[c.boxId]?.kind!==`box`&&(c=null);let t=new Set([...o].filter(t=>e?.elements[t]));t.size!==o.size&&C(t)}function se(e){let t=i.layout()?.elements.find(t=>t.id===e);return t?.kind===`box`?t:null}function D(){let[e,t]=[...a.values()];return!e||!t?0:Math.hypot(e.x-t.x,e.y-t.y)}function ce(){c?.kind===`wire`&&O(c,!1),c={kind:`pinch`,distance:D(),viewWidth:s.width}}function le(n){if(n.button!==0||l)return;let r=je(n.target);if(r){e.onOpenLinkedBoard(r);return}if(a.set(n.pointerId,{x:n.clientX,y:n.clientY}),t.setPointerCapture(n.pointerId),a.size===2){ce();return}let o=i.elementFromTarget(n.target);if(Ee(d)){ue(d,y(n.clientX,n.clientY));return}let s=o?.kind===`box`&&Ae(n.target)&&!A()?se(o.id):null;if(o&&s){let e=y(n.clientX,n.clientY);c={kind:`drag`,mode:`resize`,pointerId:n.pointerId,boxId:o.id,origin:e,start:s,pinnedOffsetY:0,latest:e,hasMoved:!1,isAdditive:!1,pressedImage:null};return}let u=Te(n.target);if(o?.kind===`box`&&u&&!A()){pe(n.pointerId,o.id,{x:u.cx.baseVal.value,y:u.cy.baseVal.value});return}let f=d===`wire`&&o?.kind===`box`?se(o.id):null;if(o&&f){pe(n.pointerId,o.id,{x:f.x+f.width/2,y:f.y+f.height/2});return}let p=o?.kind===`box`&&!A()?se(o.id):null;if(o&&p){let e=y(n.clientX,n.clientY),t=i.layout()?.pinnedOffsetY??0;c={kind:`drag`,mode:`move`,pointerId:n.pointerId,boxId:o.id,origin:e,start:p,pinnedOffsetY:t,latest:e,hasMoved:!1,isAdditive:n.shiftKey,pressedImage:ke(n.target)};return}if(o&&!A()){ee(o.id,n.shiftKey);return}let m=o?.kind===`box`?o.id:null;c={kind:`pan`,pointerId:n.pointerId,lastClient:{x:n.clientX,y:n.clientY},hasMoved:!1,tappedBoxId:m,pressedImage:ke(n.target)}}async function ue(t,n){h(`select`);let r=e.currentBoard();if(!r)return;let a=i.layout()?.pinnedOffsetY??0,o=De(t,r,{x:Math.round(n.x),y:Math.round(n.y-a)});f=o.id;let s=await e.sendOps([{op:`add`,element:o}]);s||(f=null),s&&C(new Set([o.id])),fe()}async function de(t,n,r){if(!e.currentBoard())return!1;let a=r?y(r.x,r.y):{x:s.x+s.width/2,y:s.y+s.height/2},o=i.layout()?.pinnedOffsetY??0,c=Oe({x:Math.round(a.x),y:Math.round(a.y-o)},t,n,!1),l=await e.sendOps([{op:`add`,element:c}]);return l&&C(new Set([c.id])),l}function fe(){if(!f||!i.nodeOf(f))return;let e=f;f=null,M(e)}function pe(e,n,r){let i=document.createElementNS(`http://www.w3.org/2000/svg`,`path`);i.setAttribute(`class`,`wb-wire-line wb-dashed wb-wire-draft`),i.setAttribute(`d`,`M ${r.x} ${r.y} L ${r.x} ${r.y}`),t.append(i),c={kind:`wire`,pointerId:e,fromBoxId:n,start:r,draftLine:i,targetBoxId:null}}function me(e,t){e.targetBoxId&&i.nodeOf(e.targetBoxId)?.classList.remove(`is-wire-target`),e.targetBoxId=t,t&&i.nodeOf(t)?.classList.add(`is-wire-target`)}function he(e,t){let n=y(t.clientX,t.clientY);e.draftLine.setAttribute(`d`,`M ${e.start.x} ${e.start.y} L ${n.x} ${n.y}`);let r=i.elementFromTarget(document.elementFromPoint(t.clientX,t.clientY));me(e,r?.kind===`box`&&r.id!==e.fromBoxId?r.id:null)}function O(t,n){let r=t.targetBoxId;me(t,null),t.draftLine.remove(),n&&r&&e.onConnectBoxes(t.fromBoxId,r)}function ge(e,t){let n=y(t.clientX,t.clientY);!e.hasMoved&&Math.hypot(n.x-e.origin.x,n.y-e.origin.y)<ye*b()||(e.hasMoved=!0,e.latest=n,ae())}function _e(e,t){let n=t.clientX-e.lastClient.x,r=t.clientY-e.lastClient.y;!e.hasMoved&&Math.hypot(n,r)<ye||(e.hasMoved=!0,e.lastClient={x:t.clientX,y:t.clientY},S(n,r))}function ve(e){let t=D();if(t<=0||e.distance<=0)return;let n=[...a.values()];x(y(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 k(e){a.has(e.pointerId)&&(a.set(e.pointerId,{x:e.clientX,y:e.clientY}),c?.kind===`pinch`?ve(c):c?.kind===`drag`&&c.pointerId===e.pointerId?ge(c,e):c?.kind===`wire`&&c.pointerId===e.pointerId?he(c,e):c?.kind===`pan`&&c.pointerId===e.pointerId&&_e(c,e))}async function Pe(t,n){if(!t.hasMoved&&t.mode===`resize`)return;if(!t.hasMoved){ee(t.boxId,t.isAdditive),t.pressedImage&&!t.isAdditive&&e.onOpenImage(t.pressedImage);return}E(),t.latest=y(n.clientX,n.clientY);let r=ne(t),a=e.currentBoard();a&&i.render(re(a,t.boxId,r)),await e.sendOps([{op:`set`,id:t.boxId,fields:r}])||ie()}function Fe(t){if(!a.delete(t.pointerId))return;let n=c;n?.kind===`pinch`?c=null:(c=null,n?.kind===`drag`&&n.pointerId===t.pointerId?Pe(n,t):n?.kind===`wire`?(O(n,n.pointerId===t.pointerId),d===`wire`&&h(`select`)):n?.kind!==`pan`||n.hasMoved||(n.pressedImage&&A()?e.onOpenImage(n.pressedImage):n.tappedBoxId&&A()?e.onPhoneTapBox(n.tappedBoxId):n.tappedBoxId||C(new Set)))}function Ie(e){a.delete(e.pointerId);let t=c?.kind===`drag`;c?.kind===`wire`&&O(c,!1),c=null,t&&ie()}function Le(e){e.preventDefault(),e.ctrlKey||e.metaKey?x(y(e.clientX,e.clientY),e.deltaY>0?Se:1/Se):S(-e.deltaX,-e.deltaY)}function j(){let e=l;l=null,e?.remove()}function M(r){let a=e.currentBoard()?.elements[r],o=i.nodeOf(r);if(a?.kind!==`box`&&a?.kind!==`panel`||!o)return;j();let s=n.getBoundingClientRect(),c=o.getBoundingClientRect(),u=p(`input`,`wb-title-input`);u.type=`text`,u.value=a.title,u.maxLength=80,u.setAttribute(`aria-label`,a.kind===`panel`?`Panel title`:`Box title`),u.style.left=`${c.left-s.left}px`,u.style.top=`${c.top-s.top}px`,u.style.width=`${Math.max(160,c.width)}px`,l=u,n.append(u),u.addEventListener(`keydown`,n=>{if(n.key===`Escape`){n.preventDefault(),j(),t.focus();return}if(n.key!==`Enter`)return;n.preventDefault();let i=u.value.trim();j(),t.focus(),i&&i!==a.title&&e.sendOps([{op:`set`,id:r,fields:{title:i}}])}),u.addEventListener(`blur`,j),u.focus(),u.select()}function Re(e){if(A())return;let t=i.elementFromTarget(document.elementFromPoint(e.clientX,e.clientY));(t?.kind===`box`||t?.kind===`panel`)&&M(t.id)}function ze(){let t=e.currentBoard();if(!t||o.size===0)return;let n=[...o].flatMap(e=>t.elements[e]??[]),r=Ce.flatMap(e=>n.filter(t=>t.kind===e)).map(e=>({op:`remove`,id:e.id}));C(new Set),e.sendOps(r)}function Be(e){if(e.target!==t||e.metaKey||e.ctrlKey||e.altKey)return;if(e.key===`Delete`||e.key===`Backspace`){e.preventDefault(),ze();return}let n=we[e.key.toLowerCase()];n&&!e.shiftKey?(e.preventDefault(),h(n)):e.key===`Escape`&&(C(new Set),h(`select`))}return t.tabIndex=0,t.addEventListener(`pointerdown`,le),t.addEventListener(`pointermove`,k),t.addEventListener(`pointerup`,Fe),t.addEventListener(`pointercancel`,Ie),t.addEventListener(`wheel`,Le,{passive:!1}),t.addEventListener(`dblclick`,Re),t.addEventListener(`keydown`,Be),new ResizeObserver(()=>{m&&t.clientWidth>0&&t.clientHeight>0&&v()}).observe(t),{fit:v,selectedIds:()=>o,clearSelection:()=>C(new Set),pruneSelection:oe,previewOf:T,closeTitleInput:j,setTool:h,placeImageBox:de,openPendingTitleEdit:fe,focusCanvas:()=>t.focus()}}var Fe=Object.freeze({undo:[],redo:[]}),Ie=new Set([`box`,`unit`,`panel`]),Le=[`wire`,`note`,`frame`,`box`,`panel`,`unit`],j=new Set([`kind`,`id`]);function M(e,t){return JSON.stringify(e)===JSON.stringify(t)}function Re(e){return e.kind===`box`?e.near?[e.near.of]:[]:e.kind===`unit`?e.after:[]}function ze(e){let t=new Set(e.map(e=>e.id)),n=[];for(;t.size>0;){let r=e.filter(e=>t.has(e.id)&&Re(e).every(e=>!t.has(e))),i=r.length>0?r:e.filter(e=>t.has(e.id));for(let e of i)t.delete(e.id);n.push(...i)}return n}function Be(e,t){let n={...e},r=Object.fromEntries(Object.entries(t).filter(([e,t])=>!j.has(e)&&!M(n[e],t)));return t.kind!==`note`||Object.keys(r).length===0?r:{...r,author:t.author,resolvedBy:t.resolvedBy}}function Ve(e,t){let n={...e.title===t.title?{}:{title:t.title},...e.caption===t.caption?{}:{caption:t.caption},...M(e.legend,t.legend)?{}:{legend:t.legend},...e.codeSessionId===t.codeSessionId?{}:{codeSessionId:t.codeSessionId}};return Object.keys(n).length===0?[]:[{op:`board`,...n}]}function He(e,t){if(M(e.columns,t.columns))return{widen:[],narrow:[]};let n=new Set(t.columns.map(e=>e.id));return{widen:[{op:`columns`,columns:[...t.columns,...e.columns.filter(e=>!n.has(e.id))],move:{}}],narrow:[{op:`columns`,columns:t.columns,move:{}}]}}function Ue(e,t){let n=Object.values(e.elements),r=Object.values(t.elements),i=Le.flatMap(e=>n.filter(n=>n.kind===e&&!t.elements[n.id])),a=ze(r.filter(t=>!e.elements[t.id])),o=r.flatMap(t=>{let n=e.elements[t.id];if(!n)return[];let r=Be(n,t);return Object.keys(r).length===0?[]:[{op:`set`,id:t.id,fields:r}]}),{widen:s,narrow:c}=He(e,t);return[...M(e.lanes,t.lanes)?[]:[{op:`lanes`,lanes:t.lanes}],...s,...i.map(e=>({op:`remove`,id:e.id})),...a.filter(e=>Ie.has(e.kind)).map(e=>({op:`add`,element:e})),...o,...a.filter(e=>!Ie.has(e.kind)).map(e=>({op:`add`,element:e})),...c,...Ve(e,t)]}function We(e,t){let n=C(e,t,re,e.updatedAt);return n.ok?Ue(n.board,e):[]}function Ge(e,t){return t.length===0?[...e]:[...e,t].slice(-100)}function Ke(e,t){return t.length===0?e:{undo:Ge(e.undo,t),redo:[]}}function qe(e,t){let n=e[t].at(-1);return n?{entry:n,history:{...e,[t]:e[t].slice(0,-1)}}:null}function Je(e,t,n){let r=t===`undo`?`redo`:`undo`;return{...e,[r]:Ge(e[r],n)}}var Ye=8,Xe=12,Ze=30,Qe=40,$e=40,et=400,tt=200,nt=8,rt=`README.md`,it=``,at=[`text`,`code`,`item`,`numbered`,`kv`],ot=[`plain`,`fail`,`join`,`lane`],st=N(at),ct=N(ot),lt=N([`box`,`decision`]),ut=N(s),dt=N(c),ft=[{value:``,text:`auto`},...N([`left`,`right`,`top`,`bottom`])],pt=[{id:`yes`,label:`yes`},{id:`no`,label:`no`}];function N(e){return e.map(e=>({value:e,text:e}))}function P(e){return p(`h3`,`wb-inspect-heading`,e)}function F(e,t){let n=p(`label`,`wb-inspect-field`);return n.append(p(`span`,`wb-inspect-label`,e),t),n}function I(e,t,n,r,i){let a=p(`input`,`wb-inspect-input`);return a.type=`text`,a.value=t,a.maxLength=n,a.dataset.field=e,i&&a.setAttribute(`aria-label`,i),a.addEventListener(`change`,()=>r(a.value)),a}function L(e,t,n,r,i){let a=p(`select`,`wb-inspect-select`);return a.dataset.field=e,i&&a.setAttribute(`aria-label`,i),a.append(...t.map(e=>{let t=p(`option`,null,e.text);return t.value=e.value,t.selected=e.value===n,t})),a.addEventListener(`change`,()=>r(a.value)),a}function mt(e,t,n,r){let i=p(`input`,`wb-inspect-check`);i.type=`checkbox`,i.checked=n,i.dataset.field=e,i.addEventListener(`change`,()=>r(i.checked));let a=p(`label`,`wb-inspect-toggle`);return a.append(i,p(`span`,null,t)),a}function R(e,t,n,r){let i=u({variant:`quiet`,size:`small`,label:t,action:t.replaceAll(` `,`-`),onClick:n});return i.dataset.field=e,r&&i.setAttribute(`aria-label`,r),i}function ht(e,t,n){let r=p(`div`,`wb-inspect-list`);return r.append(p(`span`,`wb-inspect-label`,e),...t,n),r}function gt(e,t){return{edit(n,r){let i=e(),a=i?.[n];i&&a!==void 0&&t(i.map((e,t)=>t===n?r(a):e))},remove(n){let r=e();r&&t(r.filter((e,t)=>t!==n))},append(n){let r=e();r&&t([...r,n(r)])}}}function _t(e){let t=e.trim();return a.safeParse(t).success?t:null}function vt(e,t,n,r){let i=I(e,t??``,tt,e=>{if(!e.trim()){n(null);return}let t=_t(e);t&&n(t)},r);return i.placeholder=`ref: path#L12`,i}function yt(e,t,n,r){let i=gt(n,r),a=t.map((e,t)=>{let n=p(`div`,`wb-inspect-row`);return n.append(I(`ref-${t}`,e,tt,e=>{let n=_t(e);n&&i.edit(t,()=>n)},`Ref ${t+1}`),R(`ref-${t}-remove`,`remove`,()=>i.remove(t),`Remove ref ${e}`)),n}),o=R(`ref-add`,`add ref`,()=>i.append(()=>rt),`Add a ref to ${e}`);return o.disabled=t.length>=nt,ht(`Refs`,a,o)}function bt(e,t){return t===`kv`?{...e,style:t,key:e.key||`key`}:{...e,style:t}}function xt(e,t,n,i){let a=gt(n,i),o=t.map((e,t)=>{let n=p(`div`,`wb-inspect-row`),i=t+1;return n.append(L(`line-${t}-style`,st,e.style,e=>{let n=at.find(t=>t===e);n&&a.edit(t,e=>bt(e,n))},`Line ${i} style`)),e.style===`kv`&&n.append(I(`line-${t}-key`,e.key??``,$e,e=>{e.trim()&&a.edit(t,t=>({...t,key:e.trim()}))},`Line ${i} key`)),n.append(I(`line-${t}-text`,e.text,r.line,e=>a.edit(t,t=>({...t,text:e})),`Line ${i} text`),vt(`line-${t}-ref`,e.ref,e=>a.edit(t,t=>({...t,ref:e})),`Line ${i} ref`),R(`line-${t}-remove`,`remove`,()=>a.remove(t),`Remove line ${i}`)),n}),s=R(`line-add`,`add line`,()=>a.append(()=>({text:`new line`,muted:!1,style:`text`,key:null,ref:null})),`Add a line to ${e}`);return s.disabled=t.length>=r.linesPerBox,ht(`Lines`,o,s)}function St(e){let t=new Set(e.map(e=>e.id)),n=e.length+1;for(;t.has(`exit-${n}`);)n+=1;return`exit-${n}`}function Ct(e,t,n){let r=gt(t,e=>n({outputs:e})),i=e.outputs.map((e,t)=>{let n=p(`div`,`wb-inspect-row`);return n.append(I(`output-${e.id}-label`,e.label,Ze,e=>{e.trim()&&r.edit(t,t=>({...t,label:e.trim()}))},`Output ${e.id} label`),R(`output-${e.id}-remove`,`remove`,()=>r.remove(t),`Remove output ${e.label}`)),n}),a=R(`output-add`,`add output`,()=>r.append(e=>({id:St(e),label:`exit`})));return a.disabled=e.outputs.length>=Ye,ht(`Outputs`,i,a)}function wt(e){return e.at===null&&e.near===null?e.column??it:it}function Tt(e,t,n,i,a){let o=()=>{let e=n();return e?.kind===`box`?e:null},s=[{value:it,text:`free`},...e.columns.map(e=>({value:e.id,text:e.title||e.id}))],c=[{value:``,text:`none`},...e.lanes.map(e=>({value:e.id,text:e.label||e.id}))];return[P(t.shape===`decision`?`Decision`:`Box`),F(`Title`,I(`title`,t.title,r.title,e=>{e.trim()&&a({title:e.trim()})})),F(`Shape`,L(`shape`,lt,t.shape,e=>{let t=o()?.outputs??[];e===`decision`&&a({shape:e,outputs:t.length>0?t:pt}),e===`box`&&a({shape:e,outputs:[]})})),F(`Column`,L(`column`,s,wt(t),e=>{if(e!==it){a({column:e,at:null,near:null});return}let n=i?.elements.find(e=>e.id===t.id);i&&n?.kind===`box`&&a({at:{x:n.x,y:n.y-i.pinnedOffsetY},near:null})})),F(`Lane`,L(`lane`,c,t.lane??``,e=>a({lane:e||null}))),F(`Change`,L(`change`,ut,t.change,e=>{a(e===`relabeled`?{change:e,was:o()?.was??t.title}:{change:e,was:null})})),...t.change===`relabeled`?[F(`Was`,I(`was`,t.was??``,r.title,e=>{e.trim()&&a({was:e.trim()})}))]:[],...t.shape===`decision`?[Ct(t,()=>o()?.outputs??null,a)]:[],yt(`this box`,t.refs,()=>o()?.refs??null,e=>a({refs:e})),xt(`this box`,t.lines,()=>o()?.lines??null,e=>a({lines:e}))]}function Et(e,t,n){let r=e.elements[t.from],i=r?.kind===`box`&&r.shape===`decision`?[{value:``,text:`none`},...r.outputs.map(e=>({value:e.id,text:e.label}))]:[];return[P(`Wire`),F(`Label`,I(`label`,t.label??``,Qe,e=>n({label:e.trim()||null}))),F(`Tone`,L(`tone`,ct,t.tone,e=>n({tone:e}))),mt(`dashed`,`dashed`,t.dashed,e=>n({dashed:e})),mt(`back`,`returns to an earlier step`,t.back,e=>n({back:e})),F(`Leaves from`,L(`fromSide`,ft,t.fromSide??``,e=>n({fromSide:e||null}))),F(`Arrives at`,L(`toSide`,ft,t.toSide??``,e=>n({toSide:e||null}))),...i.length>0?[F(`From output`,L(`fromOutput`,i,t.fromOutput??``,e=>n({fromOutput:e||null})))]:[]]}function Dt(e,t){return[P(`Frame`),F(`Title`,I(`title`,e.title,r.title,e=>t({title:e.trim()}))),mt(`loop`,`repeats as a loop`,e.loop,e=>t({loop:e}))]}function Ot(e,t,n){return[P(`Panel`),F(`Title`,I(`title`,e.title,r.title,e=>{e.trim()&&n({title:e.trim()})})),xt(`this panel`,e.lines,()=>{let e=t();return e?.kind===`panel`?e.lines:null},e=>n({lines:e}))]}function kt(e,t,n){let r=gt(t,n),i=e.map((e,t)=>{let n=p(`div`,`wb-inspect-row wb-inspect-legend-row`),i=t+1;return n.append(L(`legend-${t}-tone`,ct,e.tone,e=>{let n=ot.find(t=>t===e);n&&r.edit(t,e=>({...e,tone:n}))},`Legend entry ${i} tone`),I(`legend-${t}-label`,e.label,Qe,e=>{e.trim()&&r.edit(t,t=>({...t,label:e.trim()}))},`Legend entry ${i} label`),mt(`legend-${t}-dashed`,`dashed`,e.dashed,e=>r.edit(t,t=>({...t,dashed:e}))),mt(`legend-${t}-back`,`returns`,e.back,e=>r.edit(t,t=>({...t,back:e}))),R(`legend-${t}-remove`,`remove`,()=>r.remove(t),`Remove legend entry ${e.label}`)),n}),a=R(`legend-add`,`add entry`,()=>r.append(()=>({tone:`plain`,dashed:!1,back:!1,label:`meaning`})));return a.disabled=e.length>=Xe,ht(`Legend`,i,a)}function At(e,t){return[P(`Note`),F(`Ref`,vt(`ref`,e.ref,e=>t({ref:e}),`Ref`)),p(`p`,`wb-inspect-hint`,`Edit a note from its box.`)]}function jt(e,t,n){return[P(`Unit`),F(`Status`,L(`unit-status`,dt,e.status,e=>{let t=c.find(t=>t===e);t&&n({status:t})})),yt(`this unit`,e.refs,()=>{let e=t();return e?.kind===`unit`?e.refs:null},e=>n({refs:e})),p(`p`,`wb-inspect-hint`,`Agents edit units with glimmervoid whiteboard plan.`)]}function Mt(e,t,n,i,a){let o=[{value:``,text:`none`},...i];return[P(`Board`),R(`board-settings-close`,`close`,a,`Close board settings`),F(`Title`,I(`board-title`,e.title,r.title,e=>{e.trim()&&n([{op:`board`,title:e.trim()}])})),F(`Caption`,I(`board-caption`,e.caption??``,et,e=>n([{op:`board`,caption:e.trim()||null}]))),F(`Code session`,L(`board-code-session`,o,e.codeSessionId??``,e=>n([{op:`board`,codeSessionId:e||null}]))),kt(e.legend,()=>t()?.legend??null,e=>n([{op:`board`,legend:e}]))]}function Nt(e,t,n,r,i){let a=e=>i([{op:`set`,id:t.id,fields:e}]),o=()=>n()?.elements[t.id];switch(t.kind){case`box`:return Tt(e,t,o,r,a);case`wire`:return Et(e,t,a);case`frame`:return Dt(t,a);case`panel`:return Ot(t,o,a);case`note`:return At(t,a);case`unit`:return jt(t,o,a)}}function Pt(e,t,n){let r=_e(t);if(r.length===0)return[];let i=e.codeSessionId!==null,a=r.map((e,t)=>{let r=p(`div`,`wb-inspect-row wb-inspect-review-row`),a=R(`review-${t}`,`open in review`,()=>n(e),`Open ${e} in review`);return a.disabled=!i,r.append(p(`code`,`wb-inspect-ref`,e),a),r}),o=i?[]:[p(`p`,`wb-inspect-hint`,`Set the board code session to open refs in review.`)];return[P(`In review`),...a,...o]}function Ft(e,t,n){let r=p(`div`,`wb-inspect-review`);return r.append(...Pt(e,t,n)),r}function It(e){let t=document.activeElement;return e.contains(t)&&t instanceof HTMLInputElement&&t.type===`text`}function Lt(e){let{container:t}=e;t.setAttribute(`aria-label`,`Properties`);let n=t=>void e.sendOps(t),r=new Set,i=!1,a=!1;function o(e,t){if(t.size!==1)return;let[n]=t;return n===void 0?void 0:e.elements[n]}function s(n,r){let i=o(n,r),a=t.querySelector(`.wb-inspect-review`);i&&a&&a.replaceChildren(...Pt(n,i,e.openRef))}function c(t,r){if(r.size>1)return[P(`${r.size} selected`)];let i=o(t,r);return i?[...Nt(t,i,e.currentBoard,e.layout(),n),Ft(t,i,e.openRef)]:Mt(t,e.currentBoard,n,e.codeSessionChoices(),d)}function l(n){r=n,n.size>0&&(a=!1);let o=e.currentBoard();if(t.hidden=!o||n.size===0&&!a,!o||t.hidden)return;if(It(t)){s(o,n);return}let l=document.activeElement,u=l instanceof HTMLElement&&t.contains(l)?l.dataset.field:void 0;i=!0,t.replaceChildren(...c(o,n)),u&&t.querySelector(`[data-field="${CSS.escape(u)}"]`)?.focus(),i=!1}function u(){a=!0,l(r),t.querySelector(`[data-field="board-caption"]`)?.focus()}function d(){a&&(a=!1,l(r))}return t.addEventListener(`keydown`,e=>{e.key===`Escape`&&a&&(e.preventDefault(),d())}),t.addEventListener(`focusout`,e=>{i||t.hidden||e.relatedTarget instanceof Node&&t.contains(e.relatedTarget)||queueMicrotask(()=>l(r))}),{paint:l,openBoardSettings:u,closeBoardSettings:d}}var Rt=`http://www.w3.org/2000/svg`,z=12,zt=26,B=20,Bt=18,Vt=17,Ht=14,Ut=16,Wt=24,Gt=18,Kt=`Plan`,qt=`open linked board`,Jt=5,Yt=10,Xt=17,V=6,Zt=20,Qt=12,$t=4,en=3,tn=7.2,nn=13,rn=17,an=2.2,on=28,sn=()=>null,cn=`image`;function ln(e){return Object.entries(e).flatMap(([e,t])=>t===null?[]:[` ${e}="${b(t)}"`]).join(``)}function H(e,t,n=``){return`<${e}${ln(t)}>${n}</${e}>`}function U(e,t,n,r,i={}){return H(`text`,{x:t,y:n,class:r,...i},b(e))}function W(e,t,n){return H(`g`,{class:`wb-element ${t}`,"data-element-id":e.id,"data-element-kind":e.kind},n.join(``))}function un(e){return e?`stroke:${e}`:null}function dn(e){let t=e.x+e.width,n=e.y+e.headerHeight/2,r=`M${e.x+Qt},${e.y} H${t-Qt} L${t},${n}`;return e.outputs.length===0?`${r} L${t-Qt},${e.y+e.height} H${e.x+Qt} L${e.x},${n} Z`:`${r} V${e.y+e.height} H${e.x} V${n} Z`}function fn(e){return e.outputs.flatMap(t=>{let n=(e.height-e.headerHeight)/e.outputs.length/2,r=t.port.y-n;return[H(`line`,{x1:e.x,y1:r,x2:e.x+e.width,y2:r,class:`wb-output-divider`}),U(t.label,e.x+z,t.port.y+$t,`wb-output-label`),H(`circle`,{cx:t.port.x,cy:t.port.y,r:en,class:`wb-output-dot`})]})}function pn(e){return e.style===`code`?`wb-box-line wb-line-code`:e.muted?`wb-box-line wb-muted`:`wb-box-line`}function mn(e,t,n,r){let i=t+z+(e.muted?Ht:0),a=[];return e.style===`code`&&a.push(H(`rect`,{x:i-4,y:r-nn,width:t+n-z+4-i+4,height:rn,rx:3,class:`wb-code-band`})),e.style===`item`&&e.isFirstRow&&a.push(H(`circle`,{cx:i+4,cy:r-4,r:an,class:`wb-item-dot`})),e.marker!==null&&a.push(U(e.marker,i,r,e.style===`kv`?`wb-line-key`:`wb-line-marker`)),e.text&&a.push(U(e.text,i+e.indentChars*tn,r,pn(e))),a}function hn(e,t,n,r){return e.flatMap((e,i)=>mn(e,t,n,r+i*Bt))}function gn(e){let t=[H(`rect`,{x:e.x,y:e.y,width:e.width,height:e.height,rx:6,class:`wb-panel-outline`})];e.titleLines.forEach((n,r)=>{t.push(U(n,e.x+z,e.y+zt+r*B,`wb-box-title`))});let n=e.y+zt+e.titleLines.length*B;return e.bodyLines.length>0&&t.push(H(`line`,{x1:e.x+z,y1:n-12,x2:e.x+e.width-z,y2:n-12,class:`wb-panel-rule`})),t.push(...hn(e.bodyLines,e.x,e.width,n)),W(e,`wb-panel`,t)}function _n(e){return e.shape===`decision`?H(`path`,{d:dn(e),class:`wb-box-outline`,style:un(e.lane?.hex)}):H(`rect`,{x:e.x,y:e.y,width:e.width,height:e.height,rx:8,class:`wb-box-outline`,style:un(e.lane?.hex)})}function vn(e,t){let n=t(e.asset),r=H(`title`,{},b(e.alt||cn));return n?[H(`image`,{href:n,x:e.x,y:e.y,width:e.width,height:e.height,preserveAspectRatio:`xMidYMid meet`,class:`wb-image`},r)]:[H(`rect`,{x:e.x,y:e.y,width:e.width,height:e.height,rx:6,class:`wb-image-placeholder`},r),U(e.alt||cn,e.x+e.width/2,e.y+e.height/2+4,`wb-image-placeholder-text`,{"text-anchor":`middle`})]}function yn(e,t){let n=[_n(e),...fn(e)],r=e.x+e.width/2,i=e.y+e.height/2;for(let[t,a]of[[r,e.y],[e.x+e.width,i],[r,e.y+e.height],[e.x,i]])n.push(H(`circle`,{cx:t,cy:a,r:Jt,class:`wb-port`}));e.wasLines.forEach((t,r)=>{n.push(U(t,e.x+z,e.y+zt+r*B,`wb-box-was`))});let a=e.y+zt+e.wasLines.length*B;e.titleLines.forEach((t,r)=>{n.push(U(t,e.x+z,a+r*B,`wb-box-title`))});let o=a+e.titleLines.length*B;if(n.push(...hn(e.bodyLines,e.x,e.width,o)),e.image&&n.push(...vn(e.image,t)),e.lane&&e.showsLanePill){let t=e.y+e.headerHeight-28,r=Math.min(e.width-24,16+e.lane.label.length*8);n.push(H(`rect`,{x:e.x+z,y:t,width:r,height:18,rx:9,class:`wb-lane-pill`,style:un(e.lane.hex)}),U(e.lane.label,e.x+z+8,t+13,`wb-lane-pill-text`,{style:`fill:${e.lane.hex}`}))}return n.push(H(`rect`,{x:e.x+e.width-Yt,y:e.y+e.height-Yt,width:Yt,height:Yt,rx:2,class:`wb-resize-handle`})),W(e,e.change===`none`?`wb-box`:`wb-box wb-change-${e.change}`,n)}function bn(e){let t=e.x+e.width-Zt,n=e.y+V+6;return H(`path`,{d:`M ${t+V} ${n} A ${V} ${V} 0 1 1 ${t} ${n-V}`,"marker-end":`url(#wb-arrow)`,class:`wb-loop-badge`})}function xn(e){let t=[H(`rect`,{x:e.x,y:e.y,width:e.width,height:e.height,rx:12,class:`wb-frame-outline`}),U(e.title,e.x+14,e.y+18,`wb-frame-title`)];return e.isLoop&&t.push(bn(e)),W(e,e.isLoop?`wb-frame wb-loop`:`wb-frame`,t)}function Sn(e){let t=[H(`path`,{d:e.path,class:`wb-wire-hit`}),H(`path`,{d:e.path,"marker-end":e.hasArrowhead?`url(#wb-arrow)`:null,class:e.isDashed?`wb-wire-line wb-dashed`:`wb-wire-line`,style:un(e.strokeHex??void 0)}),H(`circle`,{cx:e.start.x,cy:e.start.y,r:3,class:`wb-wire-dot`})];return e.joinAt&&t.push(H(`circle`,{cx:e.joinAt.x,cy:e.joinAt.y,r:3,class:`wb-wire-dot`})),e.label&&t.push(U(e.label,e.labelAt.x,e.labelAt.y,`wb-wire-label`)),W(e,e.isBack?`wb-wire wb-back wb-tone-${e.tone}`:`wb-wire wb-tone-${e.tone}`,t)}function Cn(e){let t=[H(`rect`,{x:e.x,y:e.y,width:e.width,height:e.height,rx:4,class:`wb-note-card`})];return e.lines.forEach((n,r)=>{t.push(U(n,e.x+10,e.y+22+r*Vt,`wb-note-text`))}),e.byline&&t.push(U(e.byline,e.x+10,e.y+22+e.lines.length*Vt,`wb-note-byline`)),W(e,e.isResolved?`wb-note wb-resolved`:`wb-note`,t)}function wn(e){let t=[H(`rect`,{x:e.x,y:e.y,width:e.width,height:e.height,rx:8,class:`wb-unit-outline`}),U(e.label,e.x+z,e.y+Wt,`wb-unit-label`),U(e.status,e.x+e.width-z,e.y+Wt,`wb-unit-status wb-unit-${e.status}`,{"text-anchor":`end`})],n=e.y+Wt+Gt;e.titleLines.forEach((r,i)=>{t.push(U(r,e.x+z,n+i*B,`wb-box-title`))});let r=n+e.titleLines.length*B;return t.push(...hn(e.bodyLines,e.x,e.width,r)),e.linkedBoardId&&t.push(U(qt,e.x+z,r+e.bodyLines.length*Bt,`wb-unit-link`,{"data-linked-board-id":e.linkedBoardId})),W(e,`wb-unit`,t)}function Tn(e,t=sn){switch(e.kind){case`box`:return yn(e,t);case`frame`:return xn(e);case`wire`:return Sn(e);case`note`:return Cn(e);case`unit`:return wn(e);case`panel`:return gn(e)}}function En(e){let t=[];if(e.plan){t.push(U(Kt,e.plan.titleAt.x,e.plan.titleAt.y,`wb-column-title`));for(let n of e.plan.arrowPaths)t.push(H(`path`,{d:n,"marker-end":`url(#wb-arrow)`,class:`wb-wire-line`}))}for(let n of e.bands)t.push(H(`line`,{x1:n.x,y1:n.y,x2:n.x+n.width,y2:n.y,class:`wb-band-rule`})),n.label&&t.push(U(n.label,n.x,n.y+Xt,`wb-band-label`,{style:`fill:${n.hex}`}));for(let n of e.columns)n.titleLines.length!==0&&(n.titleLines.forEach((e,r)=>{t.push(U(e,n.x,n.titleBaselineY+r*Ut,`wb-column-title`))}),t.push(H(`line`,{x1:n.x,y1:n.ruleY,x2:n.x+n.width,y2:n.ruleY,class:`wb-column-rule`})));for(let n of e.legend)t.push(On(n));return e.caption&&t.push(U(e.caption.text,e.caption.x,e.caption.y+16,`wb-caption`)),H(`g`,{class:`wb-chrome`},t.join(``))}function Dn(e){let{swatch:t}=e;if(t.kind===`lane`)return H(`rect`,{x:e.x,y:e.y,width:14,height:14,rx:3,class:`wb-legend-swatch`,style:`fill:${t.hex}`});if(t.kind===`status`)return H(`rect`,{x:e.x,y:e.y,width:14,height:14,rx:3,class:`wb-legend-swatch wb-unit-outline wb-unit-${t.status}`});if(t.kind===`change`)return H(`g`,{class:`wb-change-${t.change}`},H(`rect`,{x:e.x,y:e.y,width:on,height:14,rx:3,class:`wb-legend-swatch wb-box-outline`}));let n=H(`path`,{d:`M${e.x},${e.y+7} H${e.x+on}`,"marker-end":`url(#wb-arrow)`,class:t.isDashed?`wb-wire-line wb-dashed`:`wb-wire-line`});return H(`g`,{class:t.isBack?`wb-back wb-tone-${t.tone}`:`wb-tone-${t.tone}`},n)}function On(e){let t=e.x+(e.swatch.kind===`lane`||e.swatch.kind===`status`?22:40);return Dn(e)+U(e.label,t,e.y+12,`wb-legend-text`)}function kn(){return H(`defs`,{},H(`marker`,{id:`wb-arrow`,viewBox:`0 0 10 10`,refX:9,refY:5,markerWidth:8,markerHeight:8,orient:`auto-start-reverse`},H(`path`,{d:`M 0 1 L 10 5 L 0 9 z`,fill:`context-stroke`})))}var An={worthALookIds:new Set,flaggedUnitIds:new Set},jn=9;function G(e,t=``){let n=document.createElementNS(Rt,e);return t&&n.setAttribute(`class`,t),n}function Mn(e){let t=G(`g`);return t.innerHTML=e,[...t.children]}function Nn(e){let[t]=Mn(e);if(!(t instanceof SVGGElement))throw Error(`the whiteboard markup did not draw a group`);return t}function Pn(e){return`${o}/${e}.webp`}var Fn={frame:`frames`,wire:`wires`,box:`boxes`,panel:`boxes`,note:`notes`,unit:`units`},In=[`box`,`frame`,`wire`,`note`,`unit`,`panel`];function Ln(e){let t={frames:G(`g`,`wb-layer`),wires:G(`g`,`wb-layer`),boxes:G(`g`,`wb-layer`),notes:G(`g`,`wb-layer`),units:G(`g`,`wb-layer`)},n=G(`g`);e.replaceChildren(...Mn(kn()),n,t.frames,t.wires,t.boxes,t.notes,t.units);let r=new Map,i=null,a=new Set,o=An;function s(e,t){t.classList.toggle(`is-selected`,a.has(e))}function c(e){let t=G(`g`,`wb-look-marker`),n=e.x+e.width,r=e.y,i=G(`circle`);i.setAttribute(`cx`,String(n)),i.setAttribute(`cy`,String(r)),i.setAttribute(`r`,String(jn));let a=G(`text`);a.setAttribute(`x`,String(n)),a.setAttribute(`y`,String(r+4)),a.setAttribute(`text-anchor`,`middle`),a.textContent=`!`;let o=G(`title`);return o.textContent=`worth a look in review`,t.append(o,i,a),t}function l(e,t){t.classList.toggle(`is-flagged`,o.flaggedUnitIds.has(e.id));let n=t.querySelector(`:scope > .wb-look-marker`);e.kind===`wire`||!o.worthALookIds.has(e.id)?n?.remove():n||t.append(c(e))}function u(e){let a=de(e),o=Nn(En(a));n.replaceWith(o),n=o;let c=new Set;for(let e of a.elements){c.add(e.id);let n=ue(e),i=r.get(e.id);if(i?.signature===n)continue;let a=Nn(Tn(e,Pn));s(e.id,a),l(e,a),i&&i.node.replaceWith(a),i||t[Fn[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 d(e){if(!(e instanceof Element))return null;let t=e.closest(`.wb-element`),n=t?.dataset.elementId,r=In.find(e=>e===t?.dataset.elementKind);return!n||!r?null:{id:n,kind:r}}function f(e){a=e;for(let[e,t]of r)s(e,t.node)}function p(e){o=e;for(let e of i?.elements??[]){let t=r.get(e.id)?.node;t&&l(e,t)}}function m(){for(let e of r.values())e.node.remove();r.clear();let e=G(`g`);n.replaceWith(e),n=e,i=null}return{render:u,layout:()=>i,elementFromTarget:d,nodeOf:e=>r.get(e)?.node??null,setSelection:f,setReviewMarks:p,clear:m}}var Rn=`http://www.w3.org/2000/svg`,zn=`No boards yet. Make one here, or have an agent run glimmervoid whiteboard new <title>.`,Bn=`Pick a board above.`,Vn=`wb-board-title-rename`,Hn=`M13.5 8H3 M7 4L3 8l4 4`,Un=`M4.5 6.5L8 10l3.5-3.5`,Wn=4,Gn=32,Kn=`M2.5 6V2.5H6 M10 2.5h3.5V6 M13.5 10v3.5H10 M6 13.5H2.5V10`,qn=`M5.5 3.5l-3 3l3 3 M2.5 6.5h7a3.5 3.5 0 0 1 0 7H7`,Jn=`M10.5 3.5l3 3l-3 3 M13.5 6.5h-7a3.5 3.5 0 0 0 0 7H9`,Yn=[{tool:`select`,label:`select`,key:`V`,iconPath:`M4 2.5l8.5 5.8l-4 0.7l2.2 4.3l-1.5 0.8l-2.2-4.3L4 12.5z`,hint:null},{tool:`box`,label:`box`,key:`R`,iconPath:`M2.5 4h11v8h-11z`,hint:`Click the board to place a box. Esc to cancel.`},{tool:`decision`,label:`decision`,key:`D`,iconPath:`M8 2l6 6l-6 6l-6-6z`,hint:`Click the board to place a decision. Esc to cancel.`},{tool:`panel`,label:`panel`,key:`P`,iconPath:`M2.5 3h11v10h-11z M2.5 6h11`,hint:`Click the board to place a panel. Esc to cancel.`},{tool:`wire`,label:`wire`,key:`A`,iconPath:`M2.5 13.5L13 3 M8.5 3H13v4.5`,hint:`Drag from one box to another to connect them. Esc to cancel.`}],K=null,q=null,J=null,Y=null,Xn=null,Zn=!0,X=null,Qn=null,$n=null,Z=y(`action-status wb-status`),er=y(`action-status wb-status`),Q=new Map,tr=Promise.resolve();function nr(e){let{dialog:t,close:n,actions:r,btnCancel:i}=g({title:e.title}),a=p(`input`,`dialog-input`);a.type=`text`,a.placeholder=e.placeholder,a.maxLength=e.maxLength,a.value=e.initialValue??``,a.autocomplete=`off`,a.setAttribute(`aria-label`,e.label);let o=p(`div`,`dialog-error`);o.setAttribute(`role`,`alert`);let s=e.choices?p(`select`,`dialog-input wb-dialog-select`):null;if(s&&e.choices){s.setAttribute(`aria-label`,e.choices.label);for(let t of e.choices.options){let e=p(`option`,null,t.text);e.value=t.value,s.append(e)}}let c=u({variant:`primary`,label:e.confirmLabel,action:`confirm-board-dialog`});r.append(c),t.append(p(`label`,`dialog-label`,e.label),a,...s?[s]:[],o,r);async function l(){let t=a.value.trim();if(!t){o.textContent=`${e.label} is empty.`;return}c.disabled=!0;let r=await e.onSubmit(t,s?.value??null);c.disabled=!1,r?o.textContent=r:n()}i.addEventListener(`click`,n),c.addEventListener(`click`,()=>void l()),a.addEventListener(`keydown`,e=>{e.key===`Enter`&&(e.preventDefault(),l())}),requestAnimationFrame(()=>a.focus())}function $(){return K?le(K):null}function rr(){return D().find(e=>e.id===K)??null}function ir(e){let t=tr.then(e);return tr=t.catch(()=>void 0),t}function ar(e,t){return ir(()=>or(e,t))}async function or(e,t){let n=$(),r=await se(e,t);return r.ok&&n?.id===e&&Q.set(e,Ke(Q.get(e)??Fe,We(n,t))),r}function sr(e){return ir(()=>cr(e))}async function cr(e){let t=K,n=$();if(!t||!n)return;let r=qe(Q.get(t)??Fe,e);if(!r)return;Q.set(t,r.history);let i=await se(t,r.entry);i.ok?(Z.clear(),Q.set(t,Je(Q.get(t)??Fe,e,We(n,r.entry)))):Z.show(`error`,`could not ${e} that change, so it was dropped: ${i.error}`)}async function lr(e){if(!K||e.length===0)return!1;let t=await ar(K,e);return t.ok?(Z.clear(),!0):(Z.show(`error`,t.error),!1)}async function ur(e){if(!K)return`No board is open.`;let t=await ar(K,e);return t.ok?null:t.error}function dr(e){let t=v(e);return t?_(t):`closed session`}function fr(){let e=rr()?.connectedSessionIds??[],t=$()?.codeSessionId;return(t&&!e.includes(t)?[t,...e]:e).map(e=>({value:e,text:dr(e)}))}function pr(e){let t=$();return[...Y?.selectedIds()??new Set].flatMap(e=>t?.elements[e]??[]).filter(t=>t.kind===e)}function mr(){if(!q)return;let e=$(),t=pr(`box`).length;for(let t of q.toolButtons.values())t.disabled=!e;q.buttons.note.disabled=t!==1,q.buttons.frame.disabled=t===0;for(let t of[q.buttons.unit,q.buttons.fit,q.buttons.undo,q.buttons.redo])t.disabled=!e;Xn?.paint(Y?.selectedIds()??new Set)}function hr(){if(!q)return;let e=D();K&&!e.some(e=>e.id===K)&&(K=null);let t=e.find(e=>X!==null&&e.connectedSessionIds.includes(X))??e[0];!K&&t&&Pr(t.id),q.boardMenu.paintBoards(e),Cr()}function gr(){return!!q?.boardIsland.querySelector(`.${Vn}`)}function _r(){let e=rr();if(!q||!e||gr())return;let{boardTitle:t}=q,n=p(`input`,Vn);n.type=`text`,n.value=e.title,n.maxLength=r.title,n.setAttribute(`aria-label`,`Board title`),t.replaceWith(n),n.focus(),n.select();let i=!1;function a(r){if(i||!e)return;i=!0;let a=n.value.trim();n.replaceWith(t),Cr(),r&&a&&a!==e.title&&lr([{op:`board`,title:a}])}n.addEventListener(`blur`,()=>a(!0)),n.addEventListener(`keydown`,e=>{e.stopPropagation(),(e.key===`Enter`||e.key===`Escape`)&&(e.preventDefault(),a(e.key===`Enter`))})}function vr(e){let t=x(e.title,`visible wb-board-menu-board`);t.setAttribute(`role`,`menuitemradio`),t.setAttribute(`aria-checked`,String(e.id===K));let n=e.connectedSessionIds.length;return n>0&&t.append(p(`span`,`wb-board-menu-count`,String(n))),t.addEventListener(`click`,()=>Pr(e.id)),t}function yr(e){let t=p(`div`,`session-overflow wb-board-menu`),n=p(`div`,`popup-menu session-overflow-menu`);n.setAttribute(`role`,`menu`),n.setAttribute(`aria-label`,`Board menu`);let r=()=>n.classList.contains(`open`),i=e=>{c.classList.toggle(`visible`,!ni()),n.classList.toggle(`open`,e),a.setAttribute(`aria-expanded`,String(e))},a=l({label:`board menu`,action:`open-board-menu`,onClick:()=>i(!r())});a.setAttribute(`aria-haspopup`,`menu`),a.setAttribute(`aria-expanded`,`false`);let o=(e,t,n=``)=>{let r=x(e,`visible ${n}`.trim());return r.addEventListener(`click`,t),r},s=p(`div`,`menu-divider`);s.setAttribute(`role`,`separator`);let c=o(`board settings`,e),u=[s,o(`new board`,Hr),c,o(`delete board`,Vr,`wb-board-menu-danger`)];return n.addEventListener(`click`,e=>{e.target instanceof HTMLElement&&e.target.closest(`[role^="menuitem"]`)&&i(!1)}),t.append(a,n),S({trigger:a,menu:n,menuItems:()=>[...n.querySelectorAll(`.visible[role^="menuitem"]`)],isOpen:r,open:()=>i(!0),close:()=>i(!1)}),document.addEventListener(`click`,e=>{r()&&e.target instanceof Node&&!t.contains(e.target)&&i(!1)}),{menuRoot:t,trigger:a,paintBoards:e=>n.replaceChildren(...e.map(vr),...u)}}function br(e){let n=p(`div`,`session-overflow wb-more-menu`),r=p(`div`,`popup-menu session-overflow-menu wb-more-menu-popup`);r.setAttribute(`role`,`menu`),r.setAttribute(`aria-label`,`More tools`);let i=()=>r.classList.contains(`open`),a=e=>{r.classList.toggle(`open`,e),o.setAttribute(`aria-expanded`,String(e)),e&&xr(r,o)},o=u({variant:`quiet`,size:`small`,label:`more`,icon:t(Un,`1.5`),action:`open-more-tools`,onClick:()=>a(!i())});return o.classList.add(`wb-more-trigger`),o.setAttribute(`aria-haspopup`,`menu`),o.setAttribute(`aria-expanded`,`false`),r.append(...e),r.addEventListener(`click`,e=>{e.target instanceof HTMLElement&&e.target.closest(`[role="menuitem"]`)&&a(!1)}),n.append(o),document.body.append(r),S({trigger:o,menu:r,menuItems:()=>[...r.querySelectorAll(`[role="menuitem"]:not(:disabled)`)],isOpen:i,open:()=>a(!0),close:()=>a(!1)}),document.addEventListener(`click`,e=>{i()&&e.target instanceof Node&&!n.contains(e.target)&&!r.contains(e.target)&&a(!1)}),window.addEventListener(`resize`,()=>a(!1)),n}function xr(e,t){let n=t.getBoundingClientRect(),r=n.bottom+Wn+e.offsetHeight<=window.innerHeight;e.style.right=`${Math.max(0,window.innerWidth-n.right)}px`,e.style.top=r?`${n.bottom+Wn}px`:`auto`,e.style.bottom=r?`auto`:`${window.innerHeight-n.top+Wn}px`}function Sr(e,t,n){let r=x(e,`visible`);return r.dataset.action=t,r.addEventListener(`click`,n),r}function Cr(){if(!q)return;let e=rr(),t=D().length>0;q.canvas.hidden=!e,q.empty.hidden=!!e,q.emptyText.textContent=t?Bn:zn,e&&(q.boardTitle.textContent=e.title,q.boardMeta.textContent=`v${e.version}`,mr(),Er())}function wr(e){if(!q)return;let t=e.map(dr),n=e.filter(e=>e!==X).map(dr),r=p(`span`,t.length===0?`wb-presence-count wb-presence-none`:`wb-presence-count wb-presence-pill`,`${t.length} connected`);r.title=t.join(`, `),q.presence.replaceChildren(...n.map(e=>p(`span`,`wb-presence-pill`,e)),r),t.length===0&&q.presence.prepend(p(`span`,`wb-presence-none`,`no sessions connected`))}function Tr(e,t){let n=dr(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 Er(){if(!q)return;let e=rr();wr(e?.connectedSessionIds??[]),q.agentIsland.hidden=!X,X&&(q.agentIsland.toggleAttribute(`data-idle`,!Dr(e,X)),q.queuedForSession.textContent=Tr(e,X),q.sendToAgent.disabled=!e?.connectedSessionIds.includes(X))}function Dr(e,t){return!e?.connectedSessionIds.includes(t)||(e.queuedBySessionId[t]??0)>0}async function Or(){if(!q||!K||!X)return;q.sendToAgent.disabled=!0,er.show(`busy`,`sending`);let e=await oe(K,X);Er(),e.ok?er.show(`ok`,`sent; the agent reads the board when it is ready`):er.show(`error`,e.error)}function kr(e,t){let n=new Set(t);return new Set(Object.values(e.elements).filter(e=>_e(e).some(e=>n.has(ve(e)??``))).map(e=>e.id))}function Ar(e){let t=$()?.codeSessionId,n=ve(e);t&&n&&w(t,n)}function jr(){if(!q||!J)return;let e=$(),t=e&&Qn?.boardId===e.id?Qn.review:null;J.setReviewMarks({worthALookIds:e&&t?kr(e,t.worthALookPaths):new Set,flaggedUnitIds:new Set(t?.flaggedUnitIds??[])})}function Mr(e){let t=`${e.id}@${e.version}`;$n!==t&&($n=t,ne(e.id).then(n=>{$n===t&&(n.ok?(Qn={boardId:e.id,review:n.review},jr()):$n=null)}))}function Nr(){if(!J)return;let e=$();e?(Mr(e),Y?.pruneSelection(e),J.render(Y?.previewOf(e)??e),q&&(q.emptyBoardHint.hidden=Object.keys(e.elements).length>0),jr(),Y?.openPendingTitleEdit(),Zn&&=(Y?.fit(),!1),mr()):(J.clear(),q&&(q.emptyBoardHint.hidden=!0))}function Pr(e){K!==e&&(K=e,Zn=!0,Y?.clearSelection(),Y?.closeTitleInput(),Xn?.closeBoardSettings(),J?.clear(),Z.clear(),hr(),ie(e).then(Nr))}function Fr(){let e=$();if(!e)return;let t=D().filter(t=>t.id!==e.id),n=[{value:``,text:`No linked board`},...t.map(e=>({value:e.id,text:e.title}))];nr({title:`Add a unit`,label:`Unit title`,placeholder:`index the diffs`,maxLength:r.title,confirmLabel:`Add unit`,choices:t.length>0?{label:`Linked board`,options:n}:void 0,onSubmit:(e,t)=>ur([{op:`add`,element:{kind:`unit`,id:k(`unit`),title:e,lines:[],refs:[],status:`planned`,after:[],linkedBoardId:t||null}}])})}function Ir(e){return e.replace(/\.webp$/,`.original`)}function Lr({href:e,alt:t}){let{dialog:n,close:r,actions:i,btnCancel:a}=g({title:t||`Picture`,dialogClass:`dialog wb-image-viewer`,cancelLabel:`Close`}),o=p(`img`,`wb-image-viewer-picture`);o.src=Ir(e),o.alt=t,n.append(o,i),a.addEventListener(`click`,r),requestAnimationFrame(()=>a.focus())}function Rr(e){nr({title:`Pin a note`,label:`Note`,placeholder:`what about retries?`,maxLength:r.noteText,confirmLabel:`Pin note`,onSubmit:t=>ur([{op:`add`,element:{kind:`note`,id:k(`note`),on:e,text:t,ref:null,author:``,resolvedBy:null}}])})}function zr(e,t){let n=$();n&&e!==t&&(Object.values(n.elements).some(n=>n.kind===`wire`&&n.from===e&&n.to===t)||lr([{op:`add`,element:{kind:`wire`,id:k(`wire`),from:e,to:t,fromOutput:null,dashed:!1,tone:`plain`,label:null,fromSide:null,toSide:null,back:!1}}]))}function Br(){let e=pr(`box`).map(e=>e.id);e.length!==0&&nr({title:`Frame the selected boxes`,label:`Frame title`,placeholder:`intake`,maxLength:r.title,confirmLabel:`Add frame`,onSubmit:async t=>{let n=await ur([{op:`add`,element:{kind:`frame`,id:k(`frame`),title:t,contains:e,loop:!1}}]);return n||Y?.clearSelection(),n}})}function Vr(){let e=rr();if(!e)return;let t=e.connectedSessionIds.map(dr),n=t.length>0?` ${t.join(`, `)} ${t.length===1?`is`:`are`} connected and will lose it.`:``;m({title:`Delete board`,message:`Delete "${e.title}" for good?${n}`,confirmLabel:`Delete board`,danger:!0,onConfirm:()=>{ee(e.id).then(e=>{e.ok||Z.show(`error`,e.error)})}})}function Hr(){Ur(Pr)}function Ur(e){nr({title:`New board`,label:`Board title`,placeholder:`knowledge writer`,maxLength:r.title,confirmLabel:`Create board`,onSubmit:async t=>{let n=await E(t);return n.ok?(e(n.boardId),null):n.error}})}function Wr(n,r,i,a){return u({variant:`icon`,label:e(n),icon:t(r,`1.5`),action:i,onClick:a})}function Gr(r,a,o,s){let c=i(`wb-tool`);c.setAttribute(`aria-label`,a),n(c,e(a),d(o));let l=p(`span`,`wb-tool-key`,o);return l.setAttribute(`aria-hidden`,`true`),c.append(t(s,`1.5`),l),c.setAttribute(`aria-keyshortcuts`,o),c.setAttribute(`aria-pressed`,String(r===`select`)),c.addEventListener(`click`,()=>{Y?.setTool(r),Y?.focusCanvas()}),c}function Kr(e,t,...n){let r=p(`div`,`wb-island ${e}`);return r.setAttribute(`role`,`toolbar`),r.setAttribute(`aria-label`,t),r.append(...n),r}function qr(e){if(!q)return;for(let[t,n]of q.toolButtons)n.setAttribute(`aria-pressed`,String(t===e));let t=Yn.find(({tool:t})=>t===e)?.hint??null;q.toolHint.textContent=t??``,q.toolHint.hidden=t===null}function Jr(e){return!(e.metaKey||e.ctrlKey)||e.altKey||e.code!==`KeyZ`?null:e.shiftKey?`redo`:`undo`}function Yr(e,t){let n=Jr(t);n&&e.checkVisibility()&&!h()&&!f(t)&&(document.activeElement?.classList.contains(`xterm-helper-textarea`)||(t.preventDefault(),sr(n)))}function Xr(e){return[...e?.files??[]].filter(e=>e.type.startsWith(`image/`))}function Zr(e){return(e.name.replace(/\.[^.]+$/,``)||`Picture`).slice(0,r.title)}async function Qr(e,t){if(K&&e.length!==0){Z.show(`busy`,e.length===1?`adding ${e[0]?.name}`:`adding ${e.length} pictures`);for(let[n,i]of e.entries()){let e=await T(i);if(!e.ok){Z.show(`error`,e.error);return}let a=n*Gn,o=t?{x:t.x+a,y:t.y+a}:null,s={asset:e.asset,width:e.width,height:e.height,alt:i.name.slice(0,r.line)};if(!await Y?.placeImageBox(Zr(i),s,o))return}Z.clear()}}function $r(e,t){t.addEventListener(`dragover`,e=>{K&&e.dataTransfer?.types.includes(`Files`)&&(e.preventDefault(),e.dataTransfer.dropEffect=`copy`)}),t.addEventListener(`drop`,e=>{let t=Xr(e.dataTransfer);t.length!==0&&(e.preventDefault(),Qr(t,{x:e.clientX,y:e.clientY}))}),document.addEventListener(`paste`,t=>{if(!e.checkVisibility()||h()||ei())return;let n=Xr(t.clipboardData);n.length!==0&&(t.preventDefault(),Qr(n,null))})}function ei(){let e=document.activeElement;return e?.classList.contains(`xterm-helper-textarea`)?!0:e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLElement&&e.isContentEditable}function ti(){if(q)return q.host;let e=p(`div`,`boards-view`),t=yr(()=>{Y?.clearSelection(),Xn?.openBoardSettings()});t.trigger.dataset.phoneVisible=``;let n=i(`wb-board-title pane-header-title`);n.title=`Click to rename`,n.addEventListener(`click`,_r);let r=p(`span`,`wb-board-meta pane-header-subtitle`),a=p(`div`,`wb-presence`),o=Kr(`wb-island-board`,`Board`,t.menuRoot,n,r,a,Z.element),s=new Map(Yn.map(({tool:e,label:t,key:n,iconPath:r})=>[e,Gr(e,t,n,r)])),c=p(`div`,`wb-tools`);c.setAttribute(`role`,`group`),c.setAttribute(`aria-label`,`Drawing tools`),c.append(...s.values());let l={note:Sr(`note on box`,`add-note`,()=>{let[e]=pr(`box`);e&&Rr(e.id)}),frame:Sr(`frame selected boxes`,`add-frame`,Br),unit:Sr(`plan step`,`add-unit`,Fr),fit:Wr(`fit`,Kn,`fit-board`,()=>Y?.fit()),undo:Wr(`undo`,qn,`undo-board-edit`,()=>void sr(`undo`)),redo:Wr(`redo`,Jn,`redo-board-edit`,()=>void sr(`redo`))};l.fit.dataset.phoneVisible=``;let d=p(`span`,`wb-divider`);d.setAttribute(`aria-hidden`,`true`);let f=Kr(`wb-island-tools`,`Board tools`,c,d,br([l.note,l.frame,l.unit])),m=p(`p`,`wb-tool-hint`);m.setAttribute(`aria-live`,`polite`),m.hidden=!0;let h=Kr(`wb-island-view`,`View`,l.fit,l.undo,l.redo),g=p(`div`,`wb-canvas`),_=document.createElementNS(Rn,`svg`);_.setAttribute(`class`,`wb-svg`),_.setAttribute(`role`,`img`),_.setAttribute(`aria-label`,`Whiteboard`),_.setAttribute(`preserveAspectRatio`,`xMidYMin meet`);let v=p(`aside`,`wb-inspect`),y=p(`span`,`wb-session-queued`),b=Wr(`send to agent`,Hn,`send-board-to-agent`,()=>void Or()),x=Kr(`wb-island-agent`,`Session`,b,y,er.element);x.hidden=!0;let S=p(`div`,`wb-bottom-left`);S.append(x);let C=p(`div`,`wb-top-left`);C.append(o,h,f,m);let ee=p(`div`,`wb-top-right`);ee.append(v);let w=p(`div`,`wb-empty-board`);w.hidden=!0;let ne=p(`p`,`wb-empty-board-desc`);ne.append(p(`span`,`wb-empty-board-keys`,`Pick box (R) and click the board to place one, or ask a session to draw here.`),p(`span`,`wb-empty-board-touch`,`Ask a session to draw here.`)),w.append(p(`p`,`wb-empty-board-title`,`This board is empty.`),ne),g.append(_,w,ee,C,S);let re=p(`p`,`wb-empty-text`,zn),T=p(`div`,`wb-empty`);T.append(re,u({variant:`secondary`,label:`new board`,action:`new-board`,onClick:Hr})),e.replaceChildren(g,T),q={boardIsland:o,boardMenu:t,boardTitle:n,boardMeta:r,presence:a,host:e,chrome:C,canvas:g,empty:T,emptyText:re,agentIsland:x,queuedForSession:y,sendToAgent:b,buttons:l,toolButtons:s,toolHint:m,emptyBoardHint:w};let E=Ln(_);return J=E,Xn=Lt({container:v,currentBoard:$,layout:()=>E.layout(),sendOps:lr,codeSessionChoices:fr,openRef:Ar}),Y=Pe({svg:_,canvas:g,renderer:E,currentBoard:$,sendOps:lr,onSelectionChange:mr,onPhoneTapBox:Rr,onOpenLinkedBoard:Pr,onOpenImage:Lr,onConnectBoxes:zr,onToolChange:qr}),document.addEventListener(`keydown`,t=>Yr(e,t)),$r(e,g),te(hr),ce(e=>{e===K&&Nr()}),hr(),e}function ni(){return document.documentElement.dataset.layout===`phone`}function ri(e){q&&(e?q.boardIsland.parentElement!==e&&e.append(q.boardIsland):q.chrome.firstElementChild!==q.boardIsland&&q.chrome.prepend(q.boardIsland))}function ii(e,t){t!==X&&er.clear(),X=t,e&&Pr(e),Er()}function ai(){hr(),$n=null,K&&ie(K).then(Nr)}var oi=null;function si(e){oi=e,e.replaceChildren(ti())}function ci(){let e=ti();oi&&e.parentElement!==oi&&oi.replaceChildren(e),ri(null),ii(ae()?.boardId??null,null),ai()}var li={mount:si,refresh:ci};export{Ur as createBoardFromDialog,ti as mountBoardHost,ri as placeBoardTitle,ai as reopenSelectedBoard,ii as showBoardBeside,li as view};
|
|
1
|
+
import{B as e,P as t,R as n,_n as r,a as i,cn as a,gn as o,ln as s,mn as c,r as l,t as u,z as d}from"./button-C22nHZZN.js";import{f,s as p}from"./dom-helpers-qjWTsLGI.js";import{a as m,i as h,n as g}from"./modal-BOO8fI5C.js";import{a as _,r as v}from"./card-registry-CRupHUTh.js";import{i as y}from"./action-status-DaZn2p-M.js";import{En as b,Ln as x,Rn as S,_t as C,at as ee,ct as te,dt as w,ft as ne,gt as re,ht as T,it as E,lt as ie,mt as ae,ot as oe,pt as se,rt as D,st as ce,ut as le,vt as ue,yt as de}from"./index--tEVxxT-.js";Object.freeze({unitWarnings:[],uncoveredPaths:[],worthALookPaths:[],flaggedUnitIds:[],notChecked:null});var fe=/^([^#\s]+)(?:#L([1-9]\d*)(?:-L([1-9]\d*))?)?$/;function pe(e){return e.startsWith(`/`)||e.startsWith(`\\`)||/^[A-Za-z]:/.test(e)}function me(e){return e.split(`/`).filter(e=>e!==``&&e!==`.`).join(`/`)}function he(e){let t=fe.exec(e);if(!t?.[1])return{error:`a ref is path, path#L12 or path#L12-L30`};let n=t[1];if(pe(n))return{error:`an absolute path is never read; name the file relative to the code session worktree`};if(n.split(/[\\/]/).includes(`..`))return{error:`a path with .. is never read; name the file relative to the code session worktree`};let r=t[2]?Number(t[2]):null,i=t[3]?Number(t[3]):r;return r!==null&&i!==null&&i<r?{error:`the line range ends before it starts`}:{path:me(n),startLine:r,endLine:i}}function O(e,t,n){return n.flatMap((n,r)=>n.ref?[{elementId:t,ref:n.ref,where:`line ${r+1} of ${e}`}]:[])}function ge(e){let t=`${e.kind} ${e.id}`;switch(e.kind){case`box`:case`unit`:return[...e.refs.map(n=>({elementId:e.id,ref:n,where:t})),...O(t,e.id,e.lines)];case`panel`:return O(t,e.id,e.lines);case`note`:return e.ref?[{elementId:e.id,ref:e.ref,where:t}]:[];case`frame`:case`wire`:return[]}}function _e(e){return[...new Set(ge(e).map(e=>e.ref))]}function ve(e){let t=he(e);return`path`in t?t.path:null}var ye=4,be=200,xe=2e4,Se=1.1,Ce=[`wire`,`note`,`frame`,`box`,`panel`,`unit`],we={v:`select`,r:`box`,d:`decision`,p:`panel`,a:`wire`};function k(e){let t=Math.random().toString(36).slice(2,8);return`${e}-${Date.now().toString(36)}${t}`}function A(){return document.documentElement.dataset.layout===`phone`}function Te(e){return e instanceof SVGCircleElement&&e.classList.contains(`wb-port`)?e:null}function Ee(e){return e===`box`||e===`decision`||e===`panel`}function De(e,t,n){if(e===`panel`){let e=Math.max(-1,...Object.values(t.elements).map(e=>e.kind===`panel`?e.order:-1));return{kind:`panel`,id:k(`panel`),title:`Panel`,lines:[],order:e+1}}return e===`decision`?Oe(n,`Decision`,null,!0):Oe(n,`Box`,null,!1)}function Oe(e,t,n,r){return{kind:`box`,id:k(`box`),title:t,lines:[],lane:null,refs:[],change:`none`,was:null,column:null,near:null,order:0,at:e,shape:r?`decision`:`box`,outputs:r?[{id:`yes`,label:`yes`},{id:`no`,label:`no`}]:[],image:n,width:null}}function ke(e){if(!(e instanceof Element))return null;let t=e.closest(`image.wb-image`),n=t?.getAttribute(`href`);return!t||!n?null:{href:n,alt:t.querySelector(`title`)?.textContent??``}}function Ae(e){return e instanceof SVGRectElement&&e.classList.contains(`wb-resize-handle`)}function je(e){return e instanceof Element?e.closest(`[data-linked-board-id]`)?.dataset.linkedBoardId??null:null}var Me=2,Ne=12/10;function Pe(e){let{svg:t,canvas:n,renderer:i}=e,a=new Map,o=new Set,s={x:0,y:0,width:1e3,height:600},c=null,l=null,u=null,d=`select`,f=null,m=!1;function h(n){d=n,t.dataset.tool=n,e.onToolChange(n)}function g(){t.setAttribute(`viewBox`,`${s.x} ${s.y} ${s.width} ${s.height}`)}function _(){let e=t.getBoundingClientRect(),r=[...n.querySelectorAll(`.wb-island`)].filter(e=>e.checkVisibility()).map(e=>e.getBoundingClientRect()),i=e.top+e.height/2,a=r.filter(e=>e.top+e.height/2<i).map(t=>t.bottom-e.top),o=r.filter(e=>e.top+e.height/2>=i).map(t=>t.top-e.top),s=Math.max(0,...a),c=Math.min(e.height,...o)-s;return c<e.height/2?{topPx:0,heightPx:e.height}:{topPx:s,heightPx:c}}function v(){let e=i.layout();if(!e)return;let{bounds:n}=e,r=t.clientWidth,a=t.clientHeight;if(r===0||a===0){s={...n},g(),m=!0;return}m=!1;let o=_(),c=e.elements.length===0?1:Me,l=Math.max(1/c,n.width/r,n.height/o.heightPx),u=l>Ne,d=u?Ne:l,f=r*d,p=n.y+n.height/2,h=o.topPx+o.heightPx/2;s={x:n.x-Math.max(0,f-n.width)/2,y:u?n.y-o.topPx*d:p-h*d,width:f,height:a*d},g()}function y(e,n){let r=t.getScreenCTM();if(!r)return{x:e,y:n};let i=new DOMPoint(e,n).matrixTransform(r.inverse());return{x:i.x,y:i.y}}function b(){let e=t.clientWidth||1,n=t.clientHeight||1;return Math.max(s.width/e,s.height/n)}function x(e,t){let n=Math.min(xe,Math.max(be,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},g()}function S(e,t){let n=b();s={...s,x:s.x-e*n,y:s.y-t*n},g()}function C(t){o=t,i.setSelection(o),e.onSelectionChange(o)}function ee(e,t){if(!t){C(o.has(e)&&o.size===1?new Set:new Set([e]));return}let n=new Set(o);n.delete(e)||n.add(e),C(n)}function te(e){return{x:Math.round(e.start.x+e.latest.x-e.origin.x),y:Math.round(e.start.y+e.latest.y-e.origin.y-e.pinnedOffsetY)}}function w(e){let t=Math.round(e.start.width+e.latest.x-e.origin.x);return Math.min(r.boxWidthMax,Math.max(r.boxWidthMin,t))}function ne(e){return e.mode===`resize`?{width:w(e)}:{at:te(e)}}function re(e,t,n){let r=e.elements[t];return r?.kind===`box`?{...e,elements:{...e.elements,[t]:{...r,...n}}}:e}function T(e){return c?.kind!==`drag`||!c.hasMoved?e:re(e,c.boxId,ne(c))}function E(){u!==null&&cancelAnimationFrame(u),u=null}function ie(){E();let t=e.currentBoard();t&&i.render(T(t))}function ae(){u===null&&(u=requestAnimationFrame(ie))}function oe(e){c?.kind===`drag`&&e?.elements[c.boxId]?.kind!==`box`&&(c=null);let t=new Set([...o].filter(t=>e?.elements[t]));t.size!==o.size&&C(t)}function se(e){let t=i.layout()?.elements.find(t=>t.id===e);return t?.kind===`box`?t:null}function D(){let[e,t]=[...a.values()];return!e||!t?0:Math.hypot(e.x-t.x,e.y-t.y)}function ce(){c?.kind===`wire`&&O(c,!1),c={kind:`pinch`,distance:D(),viewWidth:s.width}}function le(n){if(n.button!==0||l)return;let r=je(n.target);if(r){e.onOpenLinkedBoard(r);return}if(a.set(n.pointerId,{x:n.clientX,y:n.clientY}),t.setPointerCapture(n.pointerId),a.size===2){ce();return}let o=i.elementFromTarget(n.target);if(Ee(d)){ue(d,y(n.clientX,n.clientY));return}let s=o?.kind===`box`&&Ae(n.target)&&!A()?se(o.id):null;if(o&&s){let e=y(n.clientX,n.clientY);c={kind:`drag`,mode:`resize`,pointerId:n.pointerId,boxId:o.id,origin:e,start:s,pinnedOffsetY:0,latest:e,hasMoved:!1,isAdditive:!1,pressedImage:null};return}let u=Te(n.target);if(o?.kind===`box`&&u&&!A()){pe(n.pointerId,o.id,{x:u.cx.baseVal.value,y:u.cy.baseVal.value});return}let f=d===`wire`&&o?.kind===`box`?se(o.id):null;if(o&&f){pe(n.pointerId,o.id,{x:f.x+f.width/2,y:f.y+f.height/2});return}let p=o?.kind===`box`&&!A()?se(o.id):null;if(o&&p){let e=y(n.clientX,n.clientY),t=i.layout()?.pinnedOffsetY??0;c={kind:`drag`,mode:`move`,pointerId:n.pointerId,boxId:o.id,origin:e,start:p,pinnedOffsetY:t,latest:e,hasMoved:!1,isAdditive:n.shiftKey,pressedImage:ke(n.target)};return}if(o&&!A()){ee(o.id,n.shiftKey);return}let m=o?.kind===`box`?o.id:null;c={kind:`pan`,pointerId:n.pointerId,lastClient:{x:n.clientX,y:n.clientY},hasMoved:!1,tappedBoxId:m,pressedImage:ke(n.target)}}async function ue(t,n){h(`select`);let r=e.currentBoard();if(!r)return;let a=i.layout()?.pinnedOffsetY??0,o=De(t,r,{x:Math.round(n.x),y:Math.round(n.y-a)});f=o.id;let s=await e.sendOps([{op:`add`,element:o}]);s||(f=null),s&&C(new Set([o.id])),fe()}async function de(t,n,r){if(!e.currentBoard())return!1;let a=r?y(r.x,r.y):{x:s.x+s.width/2,y:s.y+s.height/2},o=i.layout()?.pinnedOffsetY??0,c=Oe({x:Math.round(a.x),y:Math.round(a.y-o)},t,n,!1),l=await e.sendOps([{op:`add`,element:c}]);return l&&C(new Set([c.id])),l}function fe(){if(!f||!i.nodeOf(f))return;let e=f;f=null,M(e)}function pe(e,n,r){let i=document.createElementNS(`http://www.w3.org/2000/svg`,`path`);i.setAttribute(`class`,`wb-wire-line wb-dashed wb-wire-draft`),i.setAttribute(`d`,`M ${r.x} ${r.y} L ${r.x} ${r.y}`),t.append(i),c={kind:`wire`,pointerId:e,fromBoxId:n,start:r,draftLine:i,targetBoxId:null}}function me(e,t){e.targetBoxId&&i.nodeOf(e.targetBoxId)?.classList.remove(`is-wire-target`),e.targetBoxId=t,t&&i.nodeOf(t)?.classList.add(`is-wire-target`)}function he(e,t){let n=y(t.clientX,t.clientY);e.draftLine.setAttribute(`d`,`M ${e.start.x} ${e.start.y} L ${n.x} ${n.y}`);let r=i.elementFromTarget(document.elementFromPoint(t.clientX,t.clientY));me(e,r?.kind===`box`&&r.id!==e.fromBoxId?r.id:null)}function O(t,n){let r=t.targetBoxId;me(t,null),t.draftLine.remove(),n&&r&&e.onConnectBoxes(t.fromBoxId,r)}function ge(e,t){let n=y(t.clientX,t.clientY);!e.hasMoved&&Math.hypot(n.x-e.origin.x,n.y-e.origin.y)<ye*b()||(e.hasMoved=!0,e.latest=n,ae())}function _e(e,t){let n=t.clientX-e.lastClient.x,r=t.clientY-e.lastClient.y;!e.hasMoved&&Math.hypot(n,r)<ye||(e.hasMoved=!0,e.lastClient={x:t.clientX,y:t.clientY},S(n,r))}function ve(e){let t=D();if(t<=0||e.distance<=0)return;let n=[...a.values()];x(y(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 k(e){a.has(e.pointerId)&&(a.set(e.pointerId,{x:e.clientX,y:e.clientY}),c?.kind===`pinch`?ve(c):c?.kind===`drag`&&c.pointerId===e.pointerId?ge(c,e):c?.kind===`wire`&&c.pointerId===e.pointerId?he(c,e):c?.kind===`pan`&&c.pointerId===e.pointerId&&_e(c,e))}async function Pe(t,n){if(!t.hasMoved&&t.mode===`resize`)return;if(!t.hasMoved){ee(t.boxId,t.isAdditive),t.pressedImage&&!t.isAdditive&&e.onOpenImage(t.pressedImage);return}E(),t.latest=y(n.clientX,n.clientY);let r=ne(t),a=e.currentBoard();a&&i.render(re(a,t.boxId,r)),await e.sendOps([{op:`set`,id:t.boxId,fields:r}])||ie()}function Fe(t){if(!a.delete(t.pointerId))return;let n=c;n?.kind===`pinch`?c=null:(c=null,n?.kind===`drag`&&n.pointerId===t.pointerId?Pe(n,t):n?.kind===`wire`?(O(n,n.pointerId===t.pointerId),d===`wire`&&h(`select`)):n?.kind!==`pan`||n.hasMoved||(n.pressedImage&&A()?e.onOpenImage(n.pressedImage):n.tappedBoxId&&A()?e.onPhoneTapBox(n.tappedBoxId):n.tappedBoxId||C(new Set)))}function Ie(e){a.delete(e.pointerId);let t=c?.kind===`drag`;c?.kind===`wire`&&O(c,!1),c=null,t&&ie()}function Le(e){e.preventDefault(),e.ctrlKey||e.metaKey?x(y(e.clientX,e.clientY),e.deltaY>0?Se:1/Se):S(-e.deltaX,-e.deltaY)}function j(){let e=l;l=null,e?.remove()}function M(r){let a=e.currentBoard()?.elements[r],o=i.nodeOf(r);if(a?.kind!==`box`&&a?.kind!==`panel`||!o)return;j();let s=n.getBoundingClientRect(),c=o.getBoundingClientRect(),u=p(`input`,`wb-title-input`);u.type=`text`,u.value=a.title,u.maxLength=80,u.setAttribute(`aria-label`,a.kind===`panel`?`Panel title`:`Box title`),u.style.left=`${c.left-s.left}px`,u.style.top=`${c.top-s.top}px`,u.style.width=`${Math.max(160,c.width)}px`,l=u,n.append(u),u.addEventListener(`keydown`,n=>{if(n.key===`Escape`){n.preventDefault(),j(),t.focus();return}if(n.key!==`Enter`)return;n.preventDefault();let i=u.value.trim();j(),t.focus(),i&&i!==a.title&&e.sendOps([{op:`set`,id:r,fields:{title:i}}])}),u.addEventListener(`blur`,j),u.focus(),u.select()}function Re(e){if(A())return;let t=i.elementFromTarget(document.elementFromPoint(e.clientX,e.clientY));(t?.kind===`box`||t?.kind===`panel`)&&M(t.id)}function ze(){let t=e.currentBoard();if(!t||o.size===0)return;let n=[...o].flatMap(e=>t.elements[e]??[]),r=Ce.flatMap(e=>n.filter(t=>t.kind===e)).map(e=>({op:`remove`,id:e.id}));C(new Set),e.sendOps(r)}function Be(e){if(e.target!==t||e.metaKey||e.ctrlKey||e.altKey)return;if(e.key===`Delete`||e.key===`Backspace`){e.preventDefault(),ze();return}let n=we[e.key.toLowerCase()];n&&!e.shiftKey?(e.preventDefault(),h(n)):e.key===`Escape`&&(C(new Set),h(`select`))}return t.tabIndex=0,t.addEventListener(`pointerdown`,le),t.addEventListener(`pointermove`,k),t.addEventListener(`pointerup`,Fe),t.addEventListener(`pointercancel`,Ie),t.addEventListener(`wheel`,Le,{passive:!1}),t.addEventListener(`dblclick`,Re),t.addEventListener(`keydown`,Be),new ResizeObserver(()=>{m&&t.clientWidth>0&&t.clientHeight>0&&v()}).observe(t),{fit:v,selectedIds:()=>o,clearSelection:()=>C(new Set),pruneSelection:oe,previewOf:T,closeTitleInput:j,setTool:h,placeImageBox:de,openPendingTitleEdit:fe,focusCanvas:()=>t.focus()}}var Fe=Object.freeze({undo:[],redo:[]}),Ie=new Set([`box`,`unit`,`panel`]),Le=[`wire`,`note`,`frame`,`box`,`panel`,`unit`],j=new Set([`kind`,`id`]);function M(e,t){return JSON.stringify(e)===JSON.stringify(t)}function Re(e){return e.kind===`box`?e.near?[e.near.of]:[]:e.kind===`unit`?e.after:[]}function ze(e){let t=new Set(e.map(e=>e.id)),n=[];for(;t.size>0;){let r=e.filter(e=>t.has(e.id)&&Re(e).every(e=>!t.has(e))),i=r.length>0?r:e.filter(e=>t.has(e.id));for(let e of i)t.delete(e.id);n.push(...i)}return n}function Be(e,t){let n={...e},r=Object.fromEntries(Object.entries(t).filter(([e,t])=>!j.has(e)&&!M(n[e],t)));return t.kind!==`note`||Object.keys(r).length===0?r:{...r,author:t.author,resolvedBy:t.resolvedBy}}function Ve(e,t){let n={...e.title===t.title?{}:{title:t.title},...e.caption===t.caption?{}:{caption:t.caption},...M(e.legend,t.legend)?{}:{legend:t.legend},...e.codeSessionId===t.codeSessionId?{}:{codeSessionId:t.codeSessionId}};return Object.keys(n).length===0?[]:[{op:`board`,...n}]}function He(e,t){if(M(e.columns,t.columns))return{widen:[],narrow:[]};let n=new Set(t.columns.map(e=>e.id));return{widen:[{op:`columns`,columns:[...t.columns,...e.columns.filter(e=>!n.has(e.id))],move:{}}],narrow:[{op:`columns`,columns:t.columns,move:{}}]}}function Ue(e,t){let n=Object.values(e.elements),r=Object.values(t.elements),i=Le.flatMap(e=>n.filter(n=>n.kind===e&&!t.elements[n.id])),a=ze(r.filter(t=>!e.elements[t.id])),o=r.flatMap(t=>{let n=e.elements[t.id];if(!n)return[];let r=Be(n,t);return Object.keys(r).length===0?[]:[{op:`set`,id:t.id,fields:r}]}),{widen:s,narrow:c}=He(e,t);return[...M(e.lanes,t.lanes)?[]:[{op:`lanes`,lanes:t.lanes}],...s,...i.map(e=>({op:`remove`,id:e.id})),...a.filter(e=>Ie.has(e.kind)).map(e=>({op:`add`,element:e})),...o,...a.filter(e=>!Ie.has(e.kind)).map(e=>({op:`add`,element:e})),...c,...Ve(e,t)]}function We(e,t){let n=C(e,t,re,e.updatedAt);return n.ok?Ue(n.board,e):[]}function Ge(e,t){return t.length===0?[...e]:[...e,t].slice(-100)}function Ke(e,t){return t.length===0?e:{undo:Ge(e.undo,t),redo:[]}}function qe(e,t){let n=e[t].at(-1);return n?{entry:n,history:{...e,[t]:e[t].slice(0,-1)}}:null}function Je(e,t,n){let r=t===`undo`?`redo`:`undo`;return{...e,[r]:Ge(e[r],n)}}var Ye=8,Xe=12,Ze=30,Qe=40,$e=40,et=400,tt=200,nt=8,rt=`README.md`,it=``,at=[`text`,`code`,`item`,`numbered`,`kv`],ot=[`plain`,`fail`,`join`,`lane`],st=N(at),ct=N(ot),lt=N([`box`,`decision`]),ut=N(s),dt=N(c),ft=[{value:``,text:`auto`},...N([`left`,`right`,`top`,`bottom`])],pt=[{id:`yes`,label:`yes`},{id:`no`,label:`no`}];function N(e){return e.map(e=>({value:e,text:e}))}function P(e){return p(`h3`,`wb-inspect-heading`,e)}function F(e,t){let n=p(`label`,`wb-inspect-field`);return n.append(p(`span`,`wb-inspect-label`,e),t),n}function I(e,t,n,r,i){let a=p(`input`,`wb-inspect-input`);return a.type=`text`,a.value=t,a.maxLength=n,a.dataset.field=e,i&&a.setAttribute(`aria-label`,i),a.addEventListener(`change`,()=>r(a.value)),a}function L(e,t,n,r,i){let a=p(`select`,`wb-inspect-select`);return a.dataset.field=e,i&&a.setAttribute(`aria-label`,i),a.append(...t.map(e=>{let t=p(`option`,null,e.text);return t.value=e.value,t.selected=e.value===n,t})),a.addEventListener(`change`,()=>r(a.value)),a}function mt(e,t,n,r){let i=p(`input`,`wb-inspect-check`);i.type=`checkbox`,i.checked=n,i.dataset.field=e,i.addEventListener(`change`,()=>r(i.checked));let a=p(`label`,`wb-inspect-toggle`);return a.append(i,p(`span`,null,t)),a}function R(e,t,n,r){let i=u({variant:`quiet`,size:`small`,label:t,action:t.replaceAll(` `,`-`),onClick:n});return i.dataset.field=e,r&&i.setAttribute(`aria-label`,r),i}function ht(e,t,n){let r=p(`div`,`wb-inspect-list`);return r.append(p(`span`,`wb-inspect-label`,e),...t,n),r}function gt(e,t){return{edit(n,r){let i=e(),a=i?.[n];i&&a!==void 0&&t(i.map((e,t)=>t===n?r(a):e))},remove(n){let r=e();r&&t(r.filter((e,t)=>t!==n))},append(n){let r=e();r&&t([...r,n(r)])}}}function _t(e){let t=e.trim();return a.safeParse(t).success?t:null}function vt(e,t,n,r){let i=I(e,t??``,tt,e=>{if(!e.trim()){n(null);return}let t=_t(e);t&&n(t)},r);return i.placeholder=`ref: path#L12`,i}function yt(e,t,n,r){let i=gt(n,r),a=t.map((e,t)=>{let n=p(`div`,`wb-inspect-row`);return n.append(I(`ref-${t}`,e,tt,e=>{let n=_t(e);n&&i.edit(t,()=>n)},`Ref ${t+1}`),R(`ref-${t}-remove`,`remove`,()=>i.remove(t),`Remove ref ${e}`)),n}),o=R(`ref-add`,`add ref`,()=>i.append(()=>rt),`Add a ref to ${e}`);return o.disabled=t.length>=nt,ht(`Refs`,a,o)}function bt(e,t){return t===`kv`?{...e,style:t,key:e.key||`key`}:{...e,style:t}}function xt(e,t,n,i){let a=gt(n,i),o=t.map((e,t)=>{let n=p(`div`,`wb-inspect-row`),i=t+1;return n.append(L(`line-${t}-style`,st,e.style,e=>{let n=at.find(t=>t===e);n&&a.edit(t,e=>bt(e,n))},`Line ${i} style`)),e.style===`kv`&&n.append(I(`line-${t}-key`,e.key??``,$e,e=>{e.trim()&&a.edit(t,t=>({...t,key:e.trim()}))},`Line ${i} key`)),n.append(I(`line-${t}-text`,e.text,r.line,e=>a.edit(t,t=>({...t,text:e})),`Line ${i} text`),vt(`line-${t}-ref`,e.ref,e=>a.edit(t,t=>({...t,ref:e})),`Line ${i} ref`),R(`line-${t}-remove`,`remove`,()=>a.remove(t),`Remove line ${i}`)),n}),s=R(`line-add`,`add line`,()=>a.append(()=>({text:`new line`,muted:!1,style:`text`,key:null,ref:null})),`Add a line to ${e}`);return s.disabled=t.length>=r.linesPerBox,ht(`Lines`,o,s)}function St(e){let t=new Set(e.map(e=>e.id)),n=e.length+1;for(;t.has(`exit-${n}`);)n+=1;return`exit-${n}`}function Ct(e,t,n){let r=gt(t,e=>n({outputs:e})),i=e.outputs.map((e,t)=>{let n=p(`div`,`wb-inspect-row`);return n.append(I(`output-${e.id}-label`,e.label,Ze,e=>{e.trim()&&r.edit(t,t=>({...t,label:e.trim()}))},`Output ${e.id} label`),R(`output-${e.id}-remove`,`remove`,()=>r.remove(t),`Remove output ${e.label}`)),n}),a=R(`output-add`,`add output`,()=>r.append(e=>({id:St(e),label:`exit`})));return a.disabled=e.outputs.length>=Ye,ht(`Outputs`,i,a)}function wt(e){return e.at===null&&e.near===null?e.column??it:it}function Tt(e,t,n,i,a){let o=()=>{let e=n();return e?.kind===`box`?e:null},s=[{value:it,text:`free`},...e.columns.map(e=>({value:e.id,text:e.title||e.id}))],c=[{value:``,text:`none`},...e.lanes.map(e=>({value:e.id,text:e.label||e.id}))];return[P(t.shape===`decision`?`Decision`:`Box`),F(`Title`,I(`title`,t.title,r.title,e=>{e.trim()&&a({title:e.trim()})})),F(`Shape`,L(`shape`,lt,t.shape,e=>{let t=o()?.outputs??[];e===`decision`&&a({shape:e,outputs:t.length>0?t:pt}),e===`box`&&a({shape:e,outputs:[]})})),F(`Column`,L(`column`,s,wt(t),e=>{if(e!==it){a({column:e,at:null,near:null});return}let n=i?.elements.find(e=>e.id===t.id);i&&n?.kind===`box`&&a({at:{x:n.x,y:n.y-i.pinnedOffsetY},near:null})})),F(`Lane`,L(`lane`,c,t.lane??``,e=>a({lane:e||null}))),F(`Change`,L(`change`,ut,t.change,e=>{a(e===`relabeled`?{change:e,was:o()?.was??t.title}:{change:e,was:null})})),...t.change===`relabeled`?[F(`Was`,I(`was`,t.was??``,r.title,e=>{e.trim()&&a({was:e.trim()})}))]:[],...t.shape===`decision`?[Ct(t,()=>o()?.outputs??null,a)]:[],yt(`this box`,t.refs,()=>o()?.refs??null,e=>a({refs:e})),xt(`this box`,t.lines,()=>o()?.lines??null,e=>a({lines:e}))]}function Et(e,t,n){let r=e.elements[t.from],i=r?.kind===`box`&&r.shape===`decision`?[{value:``,text:`none`},...r.outputs.map(e=>({value:e.id,text:e.label}))]:[];return[P(`Wire`),F(`Label`,I(`label`,t.label??``,Qe,e=>n({label:e.trim()||null}))),F(`Tone`,L(`tone`,ct,t.tone,e=>n({tone:e}))),mt(`dashed`,`dashed`,t.dashed,e=>n({dashed:e})),mt(`back`,`returns to an earlier step`,t.back,e=>n({back:e})),F(`Leaves from`,L(`fromSide`,ft,t.fromSide??``,e=>n({fromSide:e||null}))),F(`Arrives at`,L(`toSide`,ft,t.toSide??``,e=>n({toSide:e||null}))),...i.length>0?[F(`From output`,L(`fromOutput`,i,t.fromOutput??``,e=>n({fromOutput:e||null})))]:[]]}function Dt(e,t){return[P(`Frame`),F(`Title`,I(`title`,e.title,r.title,e=>t({title:e.trim()}))),mt(`loop`,`repeats as a loop`,e.loop,e=>t({loop:e}))]}function Ot(e,t,n){return[P(`Panel`),F(`Title`,I(`title`,e.title,r.title,e=>{e.trim()&&n({title:e.trim()})})),xt(`this panel`,e.lines,()=>{let e=t();return e?.kind===`panel`?e.lines:null},e=>n({lines:e}))]}function kt(e,t,n){let r=gt(t,n),i=e.map((e,t)=>{let n=p(`div`,`wb-inspect-row wb-inspect-legend-row`),i=t+1;return n.append(L(`legend-${t}-tone`,ct,e.tone,e=>{let n=ot.find(t=>t===e);n&&r.edit(t,e=>({...e,tone:n}))},`Legend entry ${i} tone`),I(`legend-${t}-label`,e.label,Qe,e=>{e.trim()&&r.edit(t,t=>({...t,label:e.trim()}))},`Legend entry ${i} label`),mt(`legend-${t}-dashed`,`dashed`,e.dashed,e=>r.edit(t,t=>({...t,dashed:e}))),mt(`legend-${t}-back`,`returns`,e.back,e=>r.edit(t,t=>({...t,back:e}))),R(`legend-${t}-remove`,`remove`,()=>r.remove(t),`Remove legend entry ${e.label}`)),n}),a=R(`legend-add`,`add entry`,()=>r.append(()=>({tone:`plain`,dashed:!1,back:!1,label:`meaning`})));return a.disabled=e.length>=Xe,ht(`Legend`,i,a)}function At(e,t){return[P(`Note`),F(`Ref`,vt(`ref`,e.ref,e=>t({ref:e}),`Ref`)),p(`p`,`wb-inspect-hint`,`Edit a note from its box.`)]}function jt(e,t,n){return[P(`Unit`),F(`Status`,L(`unit-status`,dt,e.status,e=>{let t=c.find(t=>t===e);t&&n({status:t})})),yt(`this unit`,e.refs,()=>{let e=t();return e?.kind===`unit`?e.refs:null},e=>n({refs:e})),p(`p`,`wb-inspect-hint`,`Agents edit units with glimmervoid whiteboard plan.`)]}function Mt(e,t,n,i,a){let o=[{value:``,text:`none`},...i];return[P(`Board`),R(`board-settings-close`,`close`,a,`Close board settings`),F(`Title`,I(`board-title`,e.title,r.title,e=>{e.trim()&&n([{op:`board`,title:e.trim()}])})),F(`Caption`,I(`board-caption`,e.caption??``,et,e=>n([{op:`board`,caption:e.trim()||null}]))),F(`Code session`,L(`board-code-session`,o,e.codeSessionId??``,e=>n([{op:`board`,codeSessionId:e||null}]))),kt(e.legend,()=>t()?.legend??null,e=>n([{op:`board`,legend:e}]))]}function Nt(e,t,n,r,i){let a=e=>i([{op:`set`,id:t.id,fields:e}]),o=()=>n()?.elements[t.id];switch(t.kind){case`box`:return Tt(e,t,o,r,a);case`wire`:return Et(e,t,a);case`frame`:return Dt(t,a);case`panel`:return Ot(t,o,a);case`note`:return At(t,a);case`unit`:return jt(t,o,a)}}function Pt(e,t,n){let r=_e(t);if(r.length===0)return[];let i=e.codeSessionId!==null,a=r.map((e,t)=>{let r=p(`div`,`wb-inspect-row wb-inspect-review-row`),a=R(`review-${t}`,`open in review`,()=>n(e),`Open ${e} in review`);return a.disabled=!i,r.append(p(`code`,`wb-inspect-ref`,e),a),r}),o=i?[]:[p(`p`,`wb-inspect-hint`,`Set the board code session to open refs in review.`)];return[P(`In review`),...a,...o]}function Ft(e,t,n){let r=p(`div`,`wb-inspect-review`);return r.append(...Pt(e,t,n)),r}function It(e){let t=document.activeElement;return e.contains(t)&&t instanceof HTMLInputElement&&t.type===`text`}function Lt(e){let{container:t}=e;t.setAttribute(`aria-label`,`Properties`);let n=t=>void e.sendOps(t),r=new Set,i=!1,a=!1;function o(e,t){if(t.size!==1)return;let[n]=t;return n===void 0?void 0:e.elements[n]}function s(n,r){let i=o(n,r),a=t.querySelector(`.wb-inspect-review`);i&&a&&a.replaceChildren(...Pt(n,i,e.openRef))}function c(t,r){if(r.size>1)return[P(`${r.size} selected`)];let i=o(t,r);return i?[...Nt(t,i,e.currentBoard,e.layout(),n),Ft(t,i,e.openRef)]:Mt(t,e.currentBoard,n,e.codeSessionChoices(),d)}function l(n){r=n,n.size>0&&(a=!1);let o=e.currentBoard();if(t.hidden=!o||n.size===0&&!a,!o||t.hidden)return;if(It(t)){s(o,n);return}let l=document.activeElement,u=l instanceof HTMLElement&&t.contains(l)?l.dataset.field:void 0;i=!0,t.replaceChildren(...c(o,n)),u&&t.querySelector(`[data-field="${CSS.escape(u)}"]`)?.focus(),i=!1}function u(){a=!0,l(r),t.querySelector(`[data-field="board-caption"]`)?.focus()}function d(){a&&(a=!1,l(r))}return t.addEventListener(`keydown`,e=>{e.key===`Escape`&&a&&(e.preventDefault(),d())}),t.addEventListener(`focusout`,e=>{i||t.hidden||e.relatedTarget instanceof Node&&t.contains(e.relatedTarget)||queueMicrotask(()=>l(r))}),{paint:l,openBoardSettings:u,closeBoardSettings:d}}var Rt=`http://www.w3.org/2000/svg`,z=12,zt=26,B=20,Bt=18,Vt=17,Ht=14,Ut=16,Wt=24,Gt=18,Kt=`Plan`,qt=`open linked board`,Jt=5,Yt=10,Xt=17,V=6,Zt=20,Qt=12,$t=4,en=3,tn=7.2,nn=13,rn=17,an=2.2,on=28,sn=()=>null,cn=`image`;function ln(e){return Object.entries(e).flatMap(([e,t])=>t===null?[]:[` ${e}="${b(t)}"`]).join(``)}function H(e,t,n=``){return`<${e}${ln(t)}>${n}</${e}>`}function U(e,t,n,r,i={}){return H(`text`,{x:t,y:n,class:r,...i},b(e))}function W(e,t,n){return H(`g`,{class:`wb-element ${t}`,"data-element-id":e.id,"data-element-kind":e.kind},n.join(``))}function un(e){return e?`stroke:${e}`:null}function dn(e){let t=e.x+e.width,n=e.y+e.headerHeight/2,r=`M${e.x+Qt},${e.y} H${t-Qt} L${t},${n}`;return e.outputs.length===0?`${r} L${t-Qt},${e.y+e.height} H${e.x+Qt} L${e.x},${n} Z`:`${r} V${e.y+e.height} H${e.x} V${n} Z`}function fn(e){return e.outputs.flatMap(t=>{let n=(e.height-e.headerHeight)/e.outputs.length/2,r=t.port.y-n;return[H(`line`,{x1:e.x,y1:r,x2:e.x+e.width,y2:r,class:`wb-output-divider`}),U(t.label,e.x+z,t.port.y+$t,`wb-output-label`),H(`circle`,{cx:t.port.x,cy:t.port.y,r:en,class:`wb-output-dot`})]})}function pn(e){return e.style===`code`?`wb-box-line wb-line-code`:e.muted?`wb-box-line wb-muted`:`wb-box-line`}function mn(e,t,n,r){let i=t+z+(e.muted?Ht:0),a=[];return e.style===`code`&&a.push(H(`rect`,{x:i-4,y:r-nn,width:t+n-z+4-i+4,height:rn,rx:3,class:`wb-code-band`})),e.style===`item`&&e.isFirstRow&&a.push(H(`circle`,{cx:i+4,cy:r-4,r:an,class:`wb-item-dot`})),e.marker!==null&&a.push(U(e.marker,i,r,e.style===`kv`?`wb-line-key`:`wb-line-marker`)),e.text&&a.push(U(e.text,i+e.indentChars*tn,r,pn(e))),a}function hn(e,t,n,r){return e.flatMap((e,i)=>mn(e,t,n,r+i*Bt))}function gn(e){let t=[H(`rect`,{x:e.x,y:e.y,width:e.width,height:e.height,rx:6,class:`wb-panel-outline`})];e.titleLines.forEach((n,r)=>{t.push(U(n,e.x+z,e.y+zt+r*B,`wb-box-title`))});let n=e.y+zt+e.titleLines.length*B;return e.bodyLines.length>0&&t.push(H(`line`,{x1:e.x+z,y1:n-12,x2:e.x+e.width-z,y2:n-12,class:`wb-panel-rule`})),t.push(...hn(e.bodyLines,e.x,e.width,n)),W(e,`wb-panel`,t)}function _n(e){return e.shape===`decision`?H(`path`,{d:dn(e),class:`wb-box-outline`,style:un(e.lane?.hex)}):H(`rect`,{x:e.x,y:e.y,width:e.width,height:e.height,rx:8,class:`wb-box-outline`,style:un(e.lane?.hex)})}function vn(e,t){let n=t(e.asset),r=H(`title`,{},b(e.alt||cn));return n?[H(`image`,{href:n,x:e.x,y:e.y,width:e.width,height:e.height,preserveAspectRatio:`xMidYMid meet`,class:`wb-image`},r)]:[H(`rect`,{x:e.x,y:e.y,width:e.width,height:e.height,rx:6,class:`wb-image-placeholder`},r),U(e.alt||cn,e.x+e.width/2,e.y+e.height/2+4,`wb-image-placeholder-text`,{"text-anchor":`middle`})]}function yn(e,t){let n=[_n(e),...fn(e)],r=e.x+e.width/2,i=e.y+e.height/2;for(let[t,a]of[[r,e.y],[e.x+e.width,i],[r,e.y+e.height],[e.x,i]])n.push(H(`circle`,{cx:t,cy:a,r:Jt,class:`wb-port`}));e.wasLines.forEach((t,r)=>{n.push(U(t,e.x+z,e.y+zt+r*B,`wb-box-was`))});let a=e.y+zt+e.wasLines.length*B;e.titleLines.forEach((t,r)=>{n.push(U(t,e.x+z,a+r*B,`wb-box-title`))});let o=a+e.titleLines.length*B;if(n.push(...hn(e.bodyLines,e.x,e.width,o)),e.image&&n.push(...vn(e.image,t)),e.lane&&e.showsLanePill){let t=e.y+e.headerHeight-28,r=Math.min(e.width-24,16+e.lane.label.length*8);n.push(H(`rect`,{x:e.x+z,y:t,width:r,height:18,rx:9,class:`wb-lane-pill`,style:un(e.lane.hex)}),U(e.lane.label,e.x+z+8,t+13,`wb-lane-pill-text`,{style:`fill:${e.lane.hex}`}))}return n.push(H(`rect`,{x:e.x+e.width-Yt,y:e.y+e.height-Yt,width:Yt,height:Yt,rx:2,class:`wb-resize-handle`})),W(e,e.change===`none`?`wb-box`:`wb-box wb-change-${e.change}`,n)}function bn(e){let t=e.x+e.width-Zt,n=e.y+V+6;return H(`path`,{d:`M ${t+V} ${n} A ${V} ${V} 0 1 1 ${t} ${n-V}`,"marker-end":`url(#wb-arrow)`,class:`wb-loop-badge`})}function xn(e){let t=[H(`rect`,{x:e.x,y:e.y,width:e.width,height:e.height,rx:12,class:`wb-frame-outline`}),U(e.title,e.x+14,e.y+18,`wb-frame-title`)];return e.isLoop&&t.push(bn(e)),W(e,e.isLoop?`wb-frame wb-loop`:`wb-frame`,t)}function Sn(e){let t=[H(`path`,{d:e.path,class:`wb-wire-hit`}),H(`path`,{d:e.path,"marker-end":e.hasArrowhead?`url(#wb-arrow)`:null,class:e.isDashed?`wb-wire-line wb-dashed`:`wb-wire-line`,style:un(e.strokeHex??void 0)}),H(`circle`,{cx:e.start.x,cy:e.start.y,r:3,class:`wb-wire-dot`})];return e.joinAt&&t.push(H(`circle`,{cx:e.joinAt.x,cy:e.joinAt.y,r:3,class:`wb-wire-dot`})),e.label&&t.push(U(e.label,e.labelAt.x,e.labelAt.y,`wb-wire-label`)),W(e,e.isBack?`wb-wire wb-back wb-tone-${e.tone}`:`wb-wire wb-tone-${e.tone}`,t)}function Cn(e){let t=[H(`rect`,{x:e.x,y:e.y,width:e.width,height:e.height,rx:4,class:`wb-note-card`})];return e.lines.forEach((n,r)=>{t.push(U(n,e.x+10,e.y+22+r*Vt,`wb-note-text`))}),e.byline&&t.push(U(e.byline,e.x+10,e.y+22+e.lines.length*Vt,`wb-note-byline`)),W(e,e.isResolved?`wb-note wb-resolved`:`wb-note`,t)}function wn(e){let t=[H(`rect`,{x:e.x,y:e.y,width:e.width,height:e.height,rx:8,class:`wb-unit-outline`}),U(e.label,e.x+z,e.y+Wt,`wb-unit-label`),U(e.status,e.x+e.width-z,e.y+Wt,`wb-unit-status wb-unit-${e.status}`,{"text-anchor":`end`})],n=e.y+Wt+Gt;e.titleLines.forEach((r,i)=>{t.push(U(r,e.x+z,n+i*B,`wb-box-title`))});let r=n+e.titleLines.length*B;return t.push(...hn(e.bodyLines,e.x,e.width,r)),e.linkedBoardId&&t.push(U(qt,e.x+z,r+e.bodyLines.length*Bt,`wb-unit-link`,{"data-linked-board-id":e.linkedBoardId})),W(e,`wb-unit`,t)}function Tn(e,t=sn){switch(e.kind){case`box`:return yn(e,t);case`frame`:return xn(e);case`wire`:return Sn(e);case`note`:return Cn(e);case`unit`:return wn(e);case`panel`:return gn(e)}}function En(e){let t=[];if(e.plan){t.push(U(Kt,e.plan.titleAt.x,e.plan.titleAt.y,`wb-column-title`));for(let n of e.plan.arrowPaths)t.push(H(`path`,{d:n,"marker-end":`url(#wb-arrow)`,class:`wb-wire-line`}))}for(let n of e.bands)t.push(H(`line`,{x1:n.x,y1:n.y,x2:n.x+n.width,y2:n.y,class:`wb-band-rule`})),n.label&&t.push(U(n.label,n.x,n.y+Xt,`wb-band-label`,{style:`fill:${n.hex}`}));for(let n of e.columns)n.titleLines.length!==0&&(n.titleLines.forEach((e,r)=>{t.push(U(e,n.x,n.titleBaselineY+r*Ut,`wb-column-title`))}),t.push(H(`line`,{x1:n.x,y1:n.ruleY,x2:n.x+n.width,y2:n.ruleY,class:`wb-column-rule`})));for(let n of e.legend)t.push(On(n));return e.caption&&t.push(U(e.caption.text,e.caption.x,e.caption.y+16,`wb-caption`)),H(`g`,{class:`wb-chrome`},t.join(``))}function Dn(e){let{swatch:t}=e;if(t.kind===`lane`)return H(`rect`,{x:e.x,y:e.y,width:14,height:14,rx:3,class:`wb-legend-swatch`,style:`fill:${t.hex}`});if(t.kind===`status`)return H(`rect`,{x:e.x,y:e.y,width:14,height:14,rx:3,class:`wb-legend-swatch wb-unit-outline wb-unit-${t.status}`});if(t.kind===`change`)return H(`g`,{class:`wb-change-${t.change}`},H(`rect`,{x:e.x,y:e.y,width:on,height:14,rx:3,class:`wb-legend-swatch wb-box-outline`}));let n=H(`path`,{d:`M${e.x},${e.y+7} H${e.x+on}`,"marker-end":`url(#wb-arrow)`,class:t.isDashed?`wb-wire-line wb-dashed`:`wb-wire-line`});return H(`g`,{class:t.isBack?`wb-back wb-tone-${t.tone}`:`wb-tone-${t.tone}`},n)}function On(e){let t=e.x+(e.swatch.kind===`lane`||e.swatch.kind===`status`?22:40);return Dn(e)+U(e.label,t,e.y+12,`wb-legend-text`)}function kn(){return H(`defs`,{},H(`marker`,{id:`wb-arrow`,viewBox:`0 0 10 10`,refX:9,refY:5,markerWidth:8,markerHeight:8,orient:`auto-start-reverse`},H(`path`,{d:`M 0 1 L 10 5 L 0 9 z`,fill:`context-stroke`})))}var An={worthALookIds:new Set,flaggedUnitIds:new Set},jn=9;function G(e,t=``){let n=document.createElementNS(Rt,e);return t&&n.setAttribute(`class`,t),n}function Mn(e){let t=G(`g`);return t.innerHTML=e,[...t.children]}function Nn(e){let[t]=Mn(e);if(!(t instanceof SVGGElement))throw Error(`the whiteboard markup did not draw a group`);return t}function Pn(e){return`${o}/${e}.webp`}var Fn={frame:`frames`,wire:`wires`,box:`boxes`,panel:`boxes`,note:`notes`,unit:`units`},In=[`box`,`frame`,`wire`,`note`,`unit`,`panel`];function Ln(e){let t={frames:G(`g`,`wb-layer`),wires:G(`g`,`wb-layer`),boxes:G(`g`,`wb-layer`),notes:G(`g`,`wb-layer`),units:G(`g`,`wb-layer`)},n=G(`g`);e.replaceChildren(...Mn(kn()),n,t.frames,t.wires,t.boxes,t.notes,t.units);let r=new Map,i=null,a=new Set,o=An;function s(e,t){t.classList.toggle(`is-selected`,a.has(e))}function c(e){let t=G(`g`,`wb-look-marker`),n=e.x+e.width,r=e.y,i=G(`circle`);i.setAttribute(`cx`,String(n)),i.setAttribute(`cy`,String(r)),i.setAttribute(`r`,String(jn));let a=G(`text`);a.setAttribute(`x`,String(n)),a.setAttribute(`y`,String(r+4)),a.setAttribute(`text-anchor`,`middle`),a.textContent=`!`;let o=G(`title`);return o.textContent=`worth a look in review`,t.append(o,i,a),t}function l(e,t){t.classList.toggle(`is-flagged`,o.flaggedUnitIds.has(e.id));let n=t.querySelector(`:scope > .wb-look-marker`);e.kind===`wire`||!o.worthALookIds.has(e.id)?n?.remove():n||t.append(c(e))}function u(e){let a=de(e),o=Nn(En(a));n.replaceWith(o),n=o;let c=new Set;for(let e of a.elements){c.add(e.id);let n=ue(e),i=r.get(e.id);if(i?.signature===n)continue;let a=Nn(Tn(e,Pn));s(e.id,a),l(e,a),i&&i.node.replaceWith(a),i||t[Fn[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 d(e){if(!(e instanceof Element))return null;let t=e.closest(`.wb-element`),n=t?.dataset.elementId,r=In.find(e=>e===t?.dataset.elementKind);return!n||!r?null:{id:n,kind:r}}function f(e){a=e;for(let[e,t]of r)s(e,t.node)}function p(e){o=e;for(let e of i?.elements??[]){let t=r.get(e.id)?.node;t&&l(e,t)}}function m(){for(let e of r.values())e.node.remove();r.clear();let e=G(`g`);n.replaceWith(e),n=e,i=null}return{render:u,layout:()=>i,elementFromTarget:d,nodeOf:e=>r.get(e)?.node??null,setSelection:f,setReviewMarks:p,clear:m}}var Rn=`http://www.w3.org/2000/svg`,zn=`No boards yet. Make one here, or have an agent run glimmervoid whiteboard new <title>.`,Bn=`Pick a board above.`,Vn=`wb-board-title-rename`,Hn=`M13.5 8H3 M7 4L3 8l4 4`,Un=`M4.5 6.5L8 10l3.5-3.5`,Wn=4,Gn=32,Kn=`M2.5 6V2.5H6 M10 2.5h3.5V6 M13.5 10v3.5H10 M6 13.5H2.5V10`,qn=`M5.5 3.5l-3 3l3 3 M2.5 6.5h7a3.5 3.5 0 0 1 0 7H7`,Jn=`M10.5 3.5l3 3l-3 3 M13.5 6.5h-7a3.5 3.5 0 0 0 0 7H9`,Yn=[{tool:`select`,label:`select`,key:`V`,iconPath:`M4 2.5l8.5 5.8l-4 0.7l2.2 4.3l-1.5 0.8l-2.2-4.3L4 12.5z`,hint:null},{tool:`box`,label:`box`,key:`R`,iconPath:`M2.5 4h11v8h-11z`,hint:`Click the board to place a box. Esc to cancel.`},{tool:`decision`,label:`decision`,key:`D`,iconPath:`M8 2l6 6l-6 6l-6-6z`,hint:`Click the board to place a decision. Esc to cancel.`},{tool:`panel`,label:`panel`,key:`P`,iconPath:`M2.5 3h11v10h-11z M2.5 6h11`,hint:`Click the board to place a panel. Esc to cancel.`},{tool:`wire`,label:`wire`,key:`A`,iconPath:`M2.5 13.5L13 3 M8.5 3H13v4.5`,hint:`Drag from one box to another to connect them. Esc to cancel.`}],K=null,q=null,J=null,Y=null,Xn=null,Zn=!0,X=null,Qn=null,$n=null,Z=y(`action-status wb-status`),er=y(`action-status wb-status`),Q=new Map,tr=Promise.resolve();function nr(e){let{dialog:t,close:n,actions:r,btnCancel:i}=g({title:e.title}),a=p(`input`,`dialog-input`);a.type=`text`,a.placeholder=e.placeholder,a.maxLength=e.maxLength,a.value=e.initialValue??``,a.autocomplete=`off`,a.setAttribute(`aria-label`,e.label);let o=p(`div`,`dialog-error`);o.setAttribute(`role`,`alert`);let s=e.choices?p(`select`,`dialog-input wb-dialog-select`):null;if(s&&e.choices){s.setAttribute(`aria-label`,e.choices.label);for(let t of e.choices.options){let e=p(`option`,null,t.text);e.value=t.value,s.append(e)}}let c=u({variant:`primary`,label:e.confirmLabel,action:`confirm-board-dialog`});r.append(c),t.append(p(`label`,`dialog-label`,e.label),a,...s?[s]:[],o,r);async function l(){let t=a.value.trim();if(!t){o.textContent=`${e.label} is empty.`;return}c.disabled=!0;let r=await e.onSubmit(t,s?.value??null);c.disabled=!1,r?o.textContent=r:n()}i.addEventListener(`click`,n),c.addEventListener(`click`,()=>void l()),a.addEventListener(`keydown`,e=>{e.key===`Enter`&&(e.preventDefault(),l())}),requestAnimationFrame(()=>a.focus())}function $(){return K?le(K):null}function rr(){return D().find(e=>e.id===K)??null}function ir(e){let t=tr.then(e);return tr=t.catch(()=>void 0),t}function ar(e,t){return ir(()=>or(e,t))}async function or(e,t){let n=$(),r=await se(e,t);return r.ok&&n?.id===e&&Q.set(e,Ke(Q.get(e)??Fe,We(n,t))),r}function sr(e){return ir(()=>cr(e))}async function cr(e){let t=K,n=$();if(!t||!n)return;let r=qe(Q.get(t)??Fe,e);if(!r)return;Q.set(t,r.history);let i=await se(t,r.entry);i.ok?(Z.clear(),Q.set(t,Je(Q.get(t)??Fe,e,We(n,r.entry)))):Z.show(`error`,`could not ${e} that change, so it was dropped: ${i.error}`)}async function lr(e){if(!K||e.length===0)return!1;let t=await ar(K,e);return t.ok?(Z.clear(),!0):(Z.show(`error`,t.error),!1)}async function ur(e){if(!K)return`No board is open.`;let t=await ar(K,e);return t.ok?null:t.error}function dr(e){let t=v(e);return t?_(t):`closed session`}function fr(){let e=rr()?.connectedSessionIds??[],t=$()?.codeSessionId;return(t&&!e.includes(t)?[t,...e]:e).map(e=>({value:e,text:dr(e)}))}function pr(e){let t=$();return[...Y?.selectedIds()??new Set].flatMap(e=>t?.elements[e]??[]).filter(t=>t.kind===e)}function mr(){if(!q)return;let e=$(),t=pr(`box`).length;for(let t of q.toolButtons.values())t.disabled=!e;q.buttons.note.disabled=t!==1,q.buttons.frame.disabled=t===0;for(let t of[q.buttons.unit,q.buttons.fit,q.buttons.undo,q.buttons.redo])t.disabled=!e;Xn?.paint(Y?.selectedIds()??new Set)}function hr(){if(!q)return;let e=D();K&&!e.some(e=>e.id===K)&&(K=null);let t=e.find(e=>X!==null&&e.connectedSessionIds.includes(X))??e[0];!K&&t&&Pr(t.id),q.boardMenu.paintBoards(e),Cr()}function gr(){return!!q?.boardIsland.querySelector(`.${Vn}`)}function _r(){let e=rr();if(!q||!e||gr())return;let{boardTitle:t}=q,n=p(`input`,Vn);n.type=`text`,n.value=e.title,n.maxLength=r.title,n.setAttribute(`aria-label`,`Board title`),t.replaceWith(n),n.focus(),n.select();let i=!1;function a(r){if(i||!e)return;i=!0;let a=n.value.trim();n.replaceWith(t),Cr(),r&&a&&a!==e.title&&lr([{op:`board`,title:a}])}n.addEventListener(`blur`,()=>a(!0)),n.addEventListener(`keydown`,e=>{e.stopPropagation(),(e.key===`Enter`||e.key===`Escape`)&&(e.preventDefault(),a(e.key===`Enter`))})}function vr(e){let t=x(e.title,`visible wb-board-menu-board`);t.setAttribute(`role`,`menuitemradio`),t.setAttribute(`aria-checked`,String(e.id===K));let n=e.connectedSessionIds.length;return n>0&&t.append(p(`span`,`wb-board-menu-count`,String(n))),t.addEventListener(`click`,()=>Pr(e.id)),t}function yr(e){let t=p(`div`,`session-overflow wb-board-menu`),n=p(`div`,`popup-menu session-overflow-menu`);n.setAttribute(`role`,`menu`),n.setAttribute(`aria-label`,`Board menu`);let r=()=>n.classList.contains(`open`),i=e=>{c.classList.toggle(`visible`,!ni()),n.classList.toggle(`open`,e),a.setAttribute(`aria-expanded`,String(e))},a=l({label:`board menu`,action:`open-board-menu`,onClick:()=>i(!r())});a.setAttribute(`aria-haspopup`,`menu`),a.setAttribute(`aria-expanded`,`false`);let o=(e,t,n=``)=>{let r=x(e,`visible ${n}`.trim());return r.addEventListener(`click`,t),r},s=p(`div`,`menu-divider`);s.setAttribute(`role`,`separator`);let c=o(`board settings`,e),u=[s,o(`new board`,Hr),c,o(`delete board`,Vr,`wb-board-menu-danger`)];return n.addEventListener(`click`,e=>{e.target instanceof HTMLElement&&e.target.closest(`[role^="menuitem"]`)&&i(!1)}),t.append(a,n),S({trigger:a,menu:n,menuItems:()=>[...n.querySelectorAll(`.visible[role^="menuitem"]`)],isOpen:r,open:()=>i(!0),close:()=>i(!1)}),document.addEventListener(`click`,e=>{r()&&e.target instanceof Node&&!t.contains(e.target)&&i(!1)}),{menuRoot:t,trigger:a,paintBoards:e=>n.replaceChildren(...e.map(vr),...u)}}function br(e){let n=p(`div`,`session-overflow wb-more-menu`),r=p(`div`,`popup-menu session-overflow-menu wb-more-menu-popup`);r.setAttribute(`role`,`menu`),r.setAttribute(`aria-label`,`More tools`);let i=()=>r.classList.contains(`open`),a=e=>{r.classList.toggle(`open`,e),o.setAttribute(`aria-expanded`,String(e)),e&&xr(r,o)},o=u({variant:`quiet`,size:`small`,label:`more`,icon:t(Un,`1.5`),action:`open-more-tools`,onClick:()=>a(!i())});return o.classList.add(`wb-more-trigger`),o.setAttribute(`aria-haspopup`,`menu`),o.setAttribute(`aria-expanded`,`false`),r.append(...e),r.addEventListener(`click`,e=>{e.target instanceof HTMLElement&&e.target.closest(`[role="menuitem"]`)&&a(!1)}),n.append(o),document.body.append(r),S({trigger:o,menu:r,menuItems:()=>[...r.querySelectorAll(`[role="menuitem"]:not(:disabled)`)],isOpen:i,open:()=>a(!0),close:()=>a(!1)}),document.addEventListener(`click`,e=>{i()&&e.target instanceof Node&&!n.contains(e.target)&&!r.contains(e.target)&&a(!1)}),window.addEventListener(`resize`,()=>a(!1)),n}function xr(e,t){let n=t.getBoundingClientRect(),r=n.bottom+Wn+e.offsetHeight<=window.innerHeight;e.style.right=`${Math.max(0,window.innerWidth-n.right)}px`,e.style.top=r?`${n.bottom+Wn}px`:`auto`,e.style.bottom=r?`auto`:`${window.innerHeight-n.top+Wn}px`}function Sr(e,t,n){let r=x(e,`visible`);return r.dataset.action=t,r.addEventListener(`click`,n),r}function Cr(){if(!q)return;let e=rr(),t=D().length>0;q.canvas.hidden=!e,q.empty.hidden=!!e,q.emptyText.textContent=t?Bn:zn,e&&(q.boardTitle.textContent=e.title,q.boardMeta.textContent=`v${e.version}`,mr(),Er())}function wr(e){if(!q)return;let t=e.map(dr),n=e.filter(e=>e!==X).map(dr),r=p(`span`,t.length===0?`wb-presence-count wb-presence-none`:`wb-presence-count wb-presence-pill`,`${t.length} connected`);r.title=t.join(`, `),q.presence.replaceChildren(...n.map(e=>p(`span`,`wb-presence-pill`,e)),r),t.length===0&&q.presence.prepend(p(`span`,`wb-presence-none`,`no sessions connected`))}function Tr(e,t){let n=dr(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 Er(){if(!q)return;let e=rr();wr(e?.connectedSessionIds??[]),q.agentIsland.hidden=!X,X&&(q.agentIsland.toggleAttribute(`data-idle`,!Dr(e,X)),q.queuedForSession.textContent=Tr(e,X),q.sendToAgent.disabled=!e?.connectedSessionIds.includes(X))}function Dr(e,t){return!e?.connectedSessionIds.includes(t)||(e.queuedBySessionId[t]??0)>0}async function Or(){if(!q||!K||!X)return;q.sendToAgent.disabled=!0,er.show(`busy`,`sending`);let e=await oe(K,X);Er(),e.ok?er.show(`ok`,`sent; the agent reads the board when it is ready`):er.show(`error`,e.error)}function kr(e,t){let n=new Set(t);return new Set(Object.values(e.elements).filter(e=>_e(e).some(e=>n.has(ve(e)??``))).map(e=>e.id))}function Ar(e){let t=$()?.codeSessionId,n=ve(e);t&&n&&w(t,n)}function jr(){if(!q||!J)return;let e=$(),t=e&&Qn?.boardId===e.id?Qn.review:null;J.setReviewMarks({worthALookIds:e&&t?kr(e,t.worthALookPaths):new Set,flaggedUnitIds:new Set(t?.flaggedUnitIds??[])})}function Mr(e){let t=`${e.id}@${e.version}`;$n!==t&&($n=t,ne(e.id).then(n=>{$n===t&&(n.ok?(Qn={boardId:e.id,review:n.review},jr()):$n=null)}))}function Nr(){if(!J)return;let e=$();e?(Mr(e),Y?.pruneSelection(e),J.render(Y?.previewOf(e)??e),q&&(q.emptyBoardHint.hidden=Object.keys(e.elements).length>0),jr(),Y?.openPendingTitleEdit(),Zn&&=(Y?.fit(),!1),mr()):(J.clear(),q&&(q.emptyBoardHint.hidden=!0))}function Pr(e){K!==e&&(K=e,Zn=!0,Y?.clearSelection(),Y?.closeTitleInput(),Xn?.closeBoardSettings(),J?.clear(),Z.clear(),hr(),ie(e).then(Nr))}function Fr(){let e=$();if(!e)return;let t=D().filter(t=>t.id!==e.id),n=[{value:``,text:`No linked board`},...t.map(e=>({value:e.id,text:e.title}))];nr({title:`Add a unit`,label:`Unit title`,placeholder:`index the diffs`,maxLength:r.title,confirmLabel:`Add unit`,choices:t.length>0?{label:`Linked board`,options:n}:void 0,onSubmit:(e,t)=>ur([{op:`add`,element:{kind:`unit`,id:k(`unit`),title:e,lines:[],refs:[],status:`planned`,after:[],linkedBoardId:t||null}}])})}function Ir(e){return e.replace(/\.webp$/,`.original`)}function Lr({href:e,alt:t}){let{dialog:n,close:r,actions:i,btnCancel:a}=g({title:t||`Picture`,dialogClass:`dialog wb-image-viewer`,cancelLabel:`Close`}),o=p(`img`,`wb-image-viewer-picture`);o.src=Ir(e),o.alt=t,n.append(o,i),a.addEventListener(`click`,r),requestAnimationFrame(()=>a.focus())}function Rr(e){nr({title:`Pin a note`,label:`Note`,placeholder:`what about retries?`,maxLength:r.noteText,confirmLabel:`Pin note`,onSubmit:t=>ur([{op:`add`,element:{kind:`note`,id:k(`note`),on:e,text:t,ref:null,author:``,resolvedBy:null}}])})}function zr(e,t){let n=$();n&&e!==t&&(Object.values(n.elements).some(n=>n.kind===`wire`&&n.from===e&&n.to===t)||lr([{op:`add`,element:{kind:`wire`,id:k(`wire`),from:e,to:t,fromOutput:null,dashed:!1,tone:`plain`,label:null,fromSide:null,toSide:null,back:!1}}]))}function Br(){let e=pr(`box`).map(e=>e.id);e.length!==0&&nr({title:`Frame the selected boxes`,label:`Frame title`,placeholder:`intake`,maxLength:r.title,confirmLabel:`Add frame`,onSubmit:async t=>{let n=await ur([{op:`add`,element:{kind:`frame`,id:k(`frame`),title:t,contains:e,loop:!1}}]);return n||Y?.clearSelection(),n}})}function Vr(){let e=rr();if(!e)return;let t=e.connectedSessionIds.map(dr),n=t.length>0?` ${t.join(`, `)} ${t.length===1?`is`:`are`} connected and will lose it.`:``;m({title:`Delete board`,message:`Delete "${e.title}" for good?${n}`,confirmLabel:`Delete board`,danger:!0,onConfirm:()=>{ee(e.id).then(e=>{e.ok||Z.show(`error`,e.error)})}})}function Hr(){Ur(Pr)}function Ur(e){nr({title:`New board`,label:`Board title`,placeholder:`knowledge writer`,maxLength:r.title,confirmLabel:`Create board`,onSubmit:async t=>{let n=await E(t);return n.ok?(e(n.boardId),null):n.error}})}function Wr(n,r,i,a){return u({variant:`icon`,label:e(n),icon:t(r,`1.5`),action:i,onClick:a})}function Gr(r,a,o,s){let c=i(`wb-tool`);c.setAttribute(`aria-label`,a),n(c,e(a),d(o));let l=p(`span`,`wb-tool-key`,o);return l.setAttribute(`aria-hidden`,`true`),c.append(t(s,`1.5`),l),c.setAttribute(`aria-keyshortcuts`,o),c.setAttribute(`aria-pressed`,String(r===`select`)),c.addEventListener(`click`,()=>{Y?.setTool(r),Y?.focusCanvas()}),c}function Kr(e,t,...n){let r=p(`div`,`wb-island ${e}`);return r.setAttribute(`role`,`toolbar`),r.setAttribute(`aria-label`,t),r.append(...n),r}function qr(e){if(!q)return;for(let[t,n]of q.toolButtons)n.setAttribute(`aria-pressed`,String(t===e));let t=Yn.find(({tool:t})=>t===e)?.hint??null;q.toolHint.textContent=t??``,q.toolHint.hidden=t===null}function Jr(e){return!(e.metaKey||e.ctrlKey)||e.altKey||e.code!==`KeyZ`?null:e.shiftKey?`redo`:`undo`}function Yr(e,t){let n=Jr(t);n&&e.checkVisibility()&&!h()&&!f(t)&&(document.activeElement?.classList.contains(`xterm-helper-textarea`)||(t.preventDefault(),sr(n)))}function Xr(e){return[...e?.files??[]].filter(e=>e.type.startsWith(`image/`))}function Zr(e){return(e.name.replace(/\.[^.]+$/,``)||`Picture`).slice(0,r.title)}async function Qr(e,t){if(K&&e.length!==0){Z.show(`busy`,e.length===1?`adding ${e[0]?.name}`:`adding ${e.length} pictures`);for(let[n,i]of e.entries()){let e=await T(i);if(!e.ok){Z.show(`error`,e.error);return}let a=n*Gn,o=t?{x:t.x+a,y:t.y+a}:null,s={asset:e.asset,width:e.width,height:e.height,alt:i.name.slice(0,r.line)};if(!await Y?.placeImageBox(Zr(i),s,o))return}Z.clear()}}function $r(e,t){t.addEventListener(`dragover`,e=>{K&&e.dataTransfer?.types.includes(`Files`)&&(e.preventDefault(),e.dataTransfer.dropEffect=`copy`)}),t.addEventListener(`drop`,e=>{let t=Xr(e.dataTransfer);t.length!==0&&(e.preventDefault(),Qr(t,{x:e.clientX,y:e.clientY}))}),document.addEventListener(`paste`,t=>{if(!e.checkVisibility()||h()||ei())return;let n=Xr(t.clipboardData);n.length!==0&&(t.preventDefault(),Qr(n,null))})}function ei(){let e=document.activeElement;return e?.classList.contains(`xterm-helper-textarea`)?!0:e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLElement&&e.isContentEditable}function ti(){if(q)return q.host;let e=p(`div`,`boards-view`),t=yr(()=>{Y?.clearSelection(),Xn?.openBoardSettings()});t.trigger.dataset.phoneVisible=``;let n=i(`wb-board-title pane-header-title`);n.title=`Click to rename`,n.addEventListener(`click`,_r);let r=p(`span`,`wb-board-meta pane-header-subtitle`),a=p(`div`,`wb-presence`),o=Kr(`wb-island-board`,`Board`,t.menuRoot,n,r,a,Z.element),s=new Map(Yn.map(({tool:e,label:t,key:n,iconPath:r})=>[e,Gr(e,t,n,r)])),c=p(`div`,`wb-tools`);c.setAttribute(`role`,`group`),c.setAttribute(`aria-label`,`Drawing tools`),c.append(...s.values());let l={note:Sr(`note on box`,`add-note`,()=>{let[e]=pr(`box`);e&&Rr(e.id)}),frame:Sr(`frame selected boxes`,`add-frame`,Br),unit:Sr(`plan step`,`add-unit`,Fr),fit:Wr(`fit`,Kn,`fit-board`,()=>Y?.fit()),undo:Wr(`undo`,qn,`undo-board-edit`,()=>void sr(`undo`)),redo:Wr(`redo`,Jn,`redo-board-edit`,()=>void sr(`redo`))};l.fit.dataset.phoneVisible=``;let d=p(`span`,`wb-divider`);d.setAttribute(`aria-hidden`,`true`);let f=Kr(`wb-island-tools`,`Board tools`,c,d,br([l.note,l.frame,l.unit])),m=p(`p`,`wb-tool-hint`);m.setAttribute(`aria-live`,`polite`),m.hidden=!0;let h=Kr(`wb-island-view`,`View`,l.fit,l.undo,l.redo),g=p(`div`,`wb-canvas`),_=document.createElementNS(Rn,`svg`);_.setAttribute(`class`,`wb-svg`),_.setAttribute(`role`,`img`),_.setAttribute(`aria-label`,`Whiteboard`),_.setAttribute(`preserveAspectRatio`,`xMidYMin meet`);let v=p(`aside`,`wb-inspect`),y=p(`span`,`wb-session-queued`),b=Wr(`send to agent`,Hn,`send-board-to-agent`,()=>void Or()),x=Kr(`wb-island-agent`,`Session`,b,y,er.element);x.hidden=!0;let S=p(`div`,`wb-bottom-left`);S.append(x);let C=p(`div`,`wb-top-left`);C.append(o,h,f,m);let ee=p(`div`,`wb-top-right`);ee.append(v);let w=p(`div`,`wb-empty-board`);w.hidden=!0;let ne=p(`p`,`wb-empty-board-desc`);ne.append(p(`span`,`wb-empty-board-keys`,`Pick box (R) and click the board to place one, or ask a session to draw here.`),p(`span`,`wb-empty-board-touch`,`Ask a session to draw here.`)),w.append(p(`p`,`wb-empty-board-title`,`This board is empty.`),ne),g.append(_,w,ee,C,S);let re=p(`p`,`wb-empty-text`,zn),T=p(`div`,`wb-empty`);T.append(re,u({variant:`secondary`,label:`new board`,action:`new-board`,onClick:Hr})),e.replaceChildren(g,T),q={boardIsland:o,boardMenu:t,boardTitle:n,boardMeta:r,presence:a,host:e,chrome:C,canvas:g,empty:T,emptyText:re,agentIsland:x,queuedForSession:y,sendToAgent:b,buttons:l,toolButtons:s,toolHint:m,emptyBoardHint:w};let E=Ln(_);return J=E,Xn=Lt({container:v,currentBoard:$,layout:()=>E.layout(),sendOps:lr,codeSessionChoices:fr,openRef:Ar}),Y=Pe({svg:_,canvas:g,renderer:E,currentBoard:$,sendOps:lr,onSelectionChange:mr,onPhoneTapBox:Rr,onOpenLinkedBoard:Pr,onOpenImage:Lr,onConnectBoxes:zr,onToolChange:qr}),document.addEventListener(`keydown`,t=>Yr(e,t)),$r(e,g),te(hr),ce(e=>{e===K&&Nr()}),hr(),e}function ni(){return document.documentElement.dataset.layout===`phone`}function ri(e){q&&(e?q.boardIsland.parentElement!==e&&e.append(q.boardIsland):q.chrome.firstElementChild!==q.boardIsland&&q.chrome.prepend(q.boardIsland))}function ii(e,t){t!==X&&er.clear(),X=t,e&&Pr(e),Er()}function ai(){hr(),$n=null,K&&ie(K).then(Nr)}var oi=null;function si(e){oi=e,e.replaceChildren(ti())}function ci(){let e=ti();oi&&e.parentElement!==oi&&oi.replaceChildren(e),ri(null),ii(ae()?.boardId??null,null),ai()}var li={mount:si,refresh:ci};export{Ur as createBoardFromDialog,ti as mountBoardHost,ri as placeBoardTitle,ai as reopenSelectedBoard,ii as showBoardBeside,li as view};
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{d as e,u as t}from"./control-ws-DjeFoTOi.js";import{a as n,t as r}from"./button-C22nHZZN.js";import{b as i,d as a,f as o,s}from"./dom-helpers-qjWTsLGI.js";import{i as c}from"./modal-BOO8fI5C.js";import{o as l}from"./card-registry-CRupHUTh.js";import{c as u,i as d,s as ee,t as f}from"./action-status-DaZn2p-M.js";import{$n as p,M as m,P as te,S as ne,Wn as h,a as g,ar as _,c as v,cr as y,d as b,gi as x,hi as S,ir as C,kt as re,l as ie,o as ae,s as w,sr as oe,tr as T,u as se,v as ce}from"./index-CNU2Do4s.js";import{n as E,o as le,r as ue,t as D}from"./lane-read-token-step-h0E5LKWg.js";import{t as de}from"./pr-queue-columns-5ygGeYVp.js";import{n as O}from"./setup-step-CzN01hWV.js";var fe={HIGH:`High confidence`,MEDIUM:`Medium confidence`,LOW:`Low confidence`},pe={HIGH:`ok`,MEDIUM:`warn`,LOW:`muted`},k={queued:`Waiting to be researched`,running:`Researching`,error:`Research failed`,aside:`Set aside`},me={forum:`Forum`,discord:`Discord`};function A(e){return e.status===`ready`&&e.verdict?{text:fe[e.verdict],tone:pe[e.verdict]}:e.status===`ready`?{text:`Researched`,tone:`muted`}:e.status===`error`?{text:k.error,tone:`danger`}:{text:k[e.status],tone:`muted`}}function j(e){let t=me[e.item.source];return e.item.channel?`${t} #${e.item.channel}`:t}function M(e){return e.entry.item.title||`Untitled question`}function he(e){return e.status!==`running`&&e.status!==`queued`}function ge(e){return e.status!==`aside`}function _e(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 N(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 ve(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 P=[`key`,`readToken`,`project`,`skill`,`discord`];function ye(e){let t=e===`finished`?P.length:P.indexOf(e),n=e=>e<t?`done`:e===t?`current`:`upcoming`;return{key:n(0),readToken:n(1),project:n(2),skill:n(3),discord:n(4)}}function be(e){let t=e.split(/[\s,]+/).map(e=>e.replace(/^#/,``)).filter(Boolean);return[...new Set(t)]}var F=2;function I(e){t({type:`dashboard-telemetry`,event:`operator_action`,properties:{surface:`onboarding`,action:e}})}function L(){let e=m().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:F,skill:typeof t.skill==`string`?t.skill:``,discordChannels:n}}function xe(e,t,n,r){let i=s(`input`,`dialog-input repo-roots-adder-input`);return i.id=e,i.type=r,i.value=t,i.placeholder=n,i.autocomplete=`off`,i.spellcheck=!1,i}function Se({onFinish:t}){let n=s(`section`,`first-run-checklist review-setup`);n.setAttribute(`aria-labelledby`,`community-setup-title`);let i=s(`h2`,`first-run-title`,`Answer community questions`);i.id=`community-setup-title`;let a=s(`ol`,`first-run-steps`),o=s(`p`,`first-run-step-hint review-setup-foot`,`Each question gets a researched draft reply. Nothing posts until you post it yourself. `);o.append(ce(`lanes-community`,`community-enabled`,`All community settings`));let c=s(`div`,`first-run-step-actions`),l=r({variant:`primary`,label:`Finish setup`,action:`finish-community-setup`});c.append(l),c.hidden=!0,n.append(s(`span`,`first-run-eyebrow`,`SET UP COMMUNITY`),i,a,c,o);let u=null;l.addEventListener(`click`,()=>{I(`finish-community-setup`),u=null,t()});function p(){return D(`posthog.apiKey`)?E()?null:`readToken`:`key`}function m(e){u=e===`readToken`&&E()?`project`:e,x(),(a.querySelector(`[aria-current="step"] input`)??(c.hidden?null:l))?.focus()}async function h(t,n,r,i){n.disabled=!0,r.show(`busy`,`Saving`);try{let n=await e(`update-settings`,{settings:t},{timeoutMs:f});if(n.type===`settings-error`){r.show(`error`,n.message);return}if(n.type!==`settings-updated`){r.show(`error`,`The server did not confirm the save.`);return}ne(n.settings),m(i)}catch(e){r.show(`error`,ee(e,f))}finally{n.disabled=!1}}function g(e){let t=xe(e.inputId,e.initialValue,e.placeholder,e.inputType),n=s(`label`,`repo-roots-adder-label`,e.label);n.htmlFor=t.id;let i=s(`div`,`first-run-step-actions`),a=d(),o=r({variant:`primary`,label:e.saveLabel,action:e.action}),c=()=>{let n=e.settingsPatch(t.value);typeof n==`string`?a.show(`error`,n):(I(e.action),h(n,o,a,e.nextProgress))};if(o.addEventListener(`click`,c),t.addEventListener(`keydown`,e=>{e.key===`Enter`&&(e.preventDefault(),c())}),i.append(o),e.isSkippable){let t=r({variant:`secondary`,label:`Skip`,action:`skip-community-setup-step`,onClick:()=>m(e.nextProgress)});i.append(t)}return i.append(a.element),[s(`p`,`first-run-step-text`,e.advice),n,t,i]}let _=()=>g({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:`readToken`,isSkippable:!1,settingsPatch:e=>e.trim()?{posthog:{apiKey:e.trim()}}:`Paste a PostHog personal API key.`}),v=()=>g({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(L().projectId),placeholder:String(F),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.`}}),y=()=>g({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:L().skill,placeholder:`skill name`,saveLabel:`Save skill`,action:`save-community-skill`,nextProgress:`discord`,isSkippable:!0,settingsPatch:e=>({community:{skill:e.trim().replace(/^\//,``)}})}),b=()=>g({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:L().discordChannels.join(`, `),placeholder:`community-questions, help`,saveLabel:`Save channels`,action:`save-community-discord`,nextProgress:`finished`,isSkippable:!0,settingsPatch:e=>{let t=be(e);return t.length>0?{community:{discordChannels:t}}:`Type at least one channel, or skip.`}});function x(){if(!u)return;let e=ye(u);a.replaceChildren(O({title:`1. PostHog personal API key`,state:e.key,summary:`Key saved`,badge:`NEEDED`,body:_}),O({title:`2. Read-only GitHub token`,state:e.readToken,summary:`Token saved`,badge:`REQUIRED`,body:()=>ue({laneWork:`Community research reads the GitHub issues, code and pages a question links.`,onSaved:()=>m(`project`)})}),O({title:`3. PostHog project`,state:e.project,summary:`Project ${L().projectId}`,badge:``,body:v}),O({title:`4. Research skill (optional)`,state:e.skill,summary:L().skill||`No skill`,badge:``,body:y}),O({title:`5. Discord (optional)`,state:e.discord,summary:L().discordChannels.map(e=>`#${e}`).join(` `)||`Forum only`,badge:``,body:b})),c.hidden=u!==`finished`}function S(){u=p()??`key`,x()}return te(e=>{e.kind===`broadcast`&&(u===`key`&&D(`posthog.apiKey`)&&m(`readToken`),u===`readToken`&&E()&&m(`project`))}),{element:n,open:S,isOpen:()=>u!==null,needsSetup:()=>p()!==null}}var R=null,z=null,B=null,V=[],H=null,U=!1,W=null,G=null,K=``,q=new Map,J=null;function Ce(){return ve([...l].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 Y(e,t,n){let r=s(`ul`,e);r.setAttribute(`aria-label`,t);for(let e of n)r.append(s(`li`,null,e));return r}function we(e){let t=s(`div`,`pr-detail-heading`),n=s(`div`,`pr-detail-title`);n.append(s(`h2`,null,e.item.title||`Untitled question`));let r=s(`div`,`pr-detail-meta`),i=Date.parse(e.item.createdAt);r.append(s(`span`,null,e.item.author),s(`span`,null,j(e))),Number.isNaN(i)||r.append(s(`span`,null,`Asked ${re(i)}`));for(let t of e.item.tags)r.append(s(`span`,`author-org-tag`,t));return t.append(n,r),t}function Te(e){let t=s(`section`,`community-question`);return t.setAttribute(`aria-label`,`Question as asked`),t.append(s(`h3`,`pr-section-heading`,`Question as asked`),s(`p`,`community-question-body`,e.item.body)),t}function Ee(e){let t=s(`section`,`pr-verdict-box`);t.setAttribute(`aria-label`,`Research`);let n=A(e),r=s(`div`,`pr-verdict-line`),i=s(`strong`,`community-badge`,n.text);if(i.dataset.tone=n.tone,r.append(i),t.append(r),e.error&&t.append(s(`p`,`pr-attention-detail`,e.error)),e.summary&&t.append(s(`p`,`pr-verdict-summary`,e.summary)),e.goal&&t.append(s(`p`,`community-goal`,`Goal: ${e.goal}`)),e.gaps.length>0&&t.append(Y(`pr-verdict-gaps`,`Not covered`,e.gaps)),e.checked.length===0)return t;let a=s(`details`,`pr-verdict-checked`);return a.append(s(`summary`,null,`What it checked (${e.checked.length})`),Y(`community-checked`,`What it checked`,e.checked)),t.append(a),t}function De(e){if(!e.draft)return null;let t=s(`section`,`community-draft`);t.setAttribute(`aria-label`,`Draft reply`),t.append(s(`h3`,`pr-section-heading`,`Draft reply`),s(`p`,`community-draft-body`,e.draft.body));let n=e.draft.publicLinks.filter(x);if(n.length===0)return t;let i=s(`ul`,`community-links`);for(let e of n){let t=s(`li`);t.append(r({variant:`secondary`,size:`small`,label:e,action:`open-public-link`,onClick:()=>S(e)})),i.append(t)}return t.append(i),t}function Oe(e,t){let n=e.draft?i(e.draft.body):null;n?n.then(()=>t.show(`ok`,`Draft copied. Post it yourself where the question was asked.`),()=>t.show(`error`,`Copying failed. Select the draft text instead.`)):t.show(`error`,`This browser does not allow copying here. Select the draft text instead.`)}async function ke(e,t){if(!K){t.show(`error`,`Pick a session to start from first.`);return}let n=await u(`open-community-session`,{key:e.item.key,projectId:K},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&&h()?.openTerminal(n.sessionId)):t.show(`error`,n.error??`The session did not start.`))}async function X(e,t,n){let r=t===`rerun`?`Queuing the research again.`:`Setting the question aside.`,i=await u(`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 Ae(){let e=s(`select`,`community-session-picker`);e.setAttribute(`aria-label`,`Session to start from`);let t=Ce();t.some(e=>e.id===K)||(K=t[0]?.id??``);for(let n of t){let t=s(`option`,null,n.name);t.value=n.id,t.selected=n.id===K,e.append(t)}return e.disabled=t.length===0,e.addEventListener(`change`,()=>{K=e.value}),e}function je(e){let t=s(`div`,`community-actions`),n=d(`pr-action-status`),i=s(`div`,`community-action-buttons`);return i.append(r({variant:`secondary`,label:`Copy draft`,action:`copy-draft`,disabled:e.draft===null,onClick:()=>Oe(e,n)}),r({variant:`secondary`,label:`Open thread`,action:`open-thread`,disabled:!x(e.item.url),onClick:()=>S(e.item.url)}),Ae(),r({variant:`primary`,label:`Start session`,action:`start-session`,onClick:()=>void ke(e,n)}),r({variant:`secondary`,label:`Re-run`,action:`rerun-community-research`,disabled:!he(e),onClick:()=>void X(e,`rerun`,n)}),r({variant:`secondary`,label:`Set aside`,action:`set-aside-community-question`,disabled:!ge(e),onClick:()=>void X(e,`set-aside`,n)})),t.append(i,n.element),t}function Me(e){let t=s(`article`,`pr-detail community-detail`),n=De(e);return t.append(we(e),je(e),...n?[n]:[],Ee(e),Te(e)),t}function Z(){if(!B)return;let e=C(V,H),t=e?JSON.stringify(e.entry):`empty:${y(V).length}`;if(t===G)return;if(G=t,e){B.replaceChildren(Me(e.entry));return}let n=V.some(e=>e.items.length>0);B.replaceChildren(n?le({title:`All caught up`,detail:_e(V)}):s(`p`,`pr-empty`,N(w())))}function Ne(e,t){se(T(e))&&t.querySelector(`.pr-queue-unseen`)?.remove()}function Q(e){H=e;for(let[t,n]of q)n.setAttribute(`aria-current`,String(t===e));let t=C(V,e),n=q.get(e);t&&n&&Ne(t,n),Z(),R&&(R.dataset.detailOpen=`true`)}function Pe(){R&&(R.dataset.detailOpen=`false`),H&&q.get(H)?.focus({preventScroll:!0})}function Fe(e){let t=C(V,e);if(!t)return;V.find(e=>e.items.includes(t))?.id===`aside`&&(U=!0),H=e,$(),Q(e);let n=q.get(e);n?.focus({preventScroll:!0}),n?.scrollIntoView({block:`nearest`})}function Ie(e){if(e.repeat||e.defaultPrevented||!R||a(R)||c()||o(e)||document.activeElement?.classList.contains(`xterm-helper-textarea`))return;let t=_(e);if(t!==`next-row`&&t!==`previous-row`)return;let n=oe([...q.keys()],H,t===`next-row`?1:-1);n&&(e.preventDefault(),n!==H&&Fe(n))}function Le(e,t){let r=n(`pr-queue-row pr-queue-row-quiet`);r.dataset.queueKey=e.key,r.setAttribute(`aria-current`,String(e.key===H));let i=A(e.entry),a=s(`span`,`review-queue-action community-badge`,i.text);a.dataset.tone=i.tone;let o=s(`span`,`pr-queue-top`);if(o.append(a,s(`span`,`pr-queue-title`,M(e))),r.append(o,s(`span`,`pr-queue-elapsed`,j(e.entry))),r.title=M(e),t&&ie(T(e))){let e=s(`span`,`tab-activity active pr-queue-unseen`);e.setAttribute(`aria-hidden`,`true`),r.append(e)}return r.addEventListener(`click`,()=>Q(e.key)),q.set(e.key,r),r}function Re(e){let t=s(`h3`,`pr-section-heading review-group-heading`),r=s(`span`,`review-group-count`,String(e.items.length));if(e.id!==`aside`)return t.append(s(`span`,null,e.title),r),t;let i=n(`review-group-toggle`),a=s(`span`,`review-group-chevron`,`▸`);return a.setAttribute(`aria-hidden`,`true`),i.append(a,e.title),i.setAttribute(`aria-expanded`,String(U)),i.addEventListener(`click`,()=>{U=!U,W=null,$()}),t.append(i,r),t}function ze(e){let t=s(`section`,`pr-queue-section`);if(t.dataset.group=e.id,t.append(Re(e)),e.id===`aside`&&!U)return t;for(let n of e.items)t.append(Le(n,e.id===`turn`));return t}function Be(){if(!R||!J)return!1;w()?.configured===!1&&J.needsSetup()&&!J.isOpen()&&J.open();let e=J.isOpen();return R.dataset.setup=String(e),J.element.hidden=!e,e}function $(){if(!z||Be())return;V=ae(),H=p(V.filter(e=>e.id!==`aside`||U),H);let e=JSON.stringify([V,H,U,v(),w()?.error??null]);if(e!==W){W=e,q.clear();let t=w()?.error,n=t?[s(`p`,`my-pr-note`,t)]:[],r=V.filter(e=>e.items.length>0).map(ze);z.replaceChildren(...n,...r.length>0?r:[s(`p`,`pr-empty`,N(w()))])}Z()}function Ve(e){if(R)return;R=s(`div`,`pr-content review-queue community-queue`),e.append(R);let t=de({queueLabel:`Community questions`,scopeTabs:null,resizerLabel:`Resize community queue`});z=t.queue,B=s(`div`,`review-queue-detail`);let n=s(`div`,`review-queue-phone-bar`);n.append(r({variant:`secondary`,label:`Back to queue`,action:`back-to-queue`,onClick:Pe})),t.detail.append(n,B),J=Se({onFinish:$}),J.element.hidden=!0,R.append(J.element,t.columns),R.dataset.detailOpen=`false`,g(()=>!a(R)),b(e=>{e.kind===`status`&&$()}),document.addEventListener(`keydown`,Ie),$()}var He={mount:Ve,refresh:()=>{G=null,$()}};export{He as view};
|
|
1
|
+
import{d as e,u as t}from"./control-ws-DjeFoTOi.js";import{a as n,t as r}from"./button-C22nHZZN.js";import{b as i,d as a,f as o,s}from"./dom-helpers-qjWTsLGI.js";import{i as c}from"./modal-BOO8fI5C.js";import{o as l}from"./card-registry-CRupHUTh.js";import{c as u,i as d,s as ee,t as f}from"./action-status-DaZn2p-M.js";import{$n as p,M as m,P as te,S as ne,Wn as h,a as g,ar as _,c as v,cr as y,d as b,gi as x,hi as S,ir as C,kt as re,l as ie,o as ae,s as w,sr as oe,tr as T,u as se,v as ce}from"./index--tEVxxT-.js";import{n as E,o as le,r as ue,t as D}from"./lane-read-token-step-CKPpsNUN.js";import{t as de}from"./pr-queue-columns-pYfkxw8K.js";import{n as O}from"./setup-step-CzN01hWV.js";var fe={HIGH:`High confidence`,MEDIUM:`Medium confidence`,LOW:`Low confidence`},pe={HIGH:`ok`,MEDIUM:`warn`,LOW:`muted`},k={queued:`Waiting to be researched`,running:`Researching`,error:`Research failed`,aside:`Set aside`},me={forum:`Forum`,discord:`Discord`};function A(e){return e.status===`ready`&&e.verdict?{text:fe[e.verdict],tone:pe[e.verdict]}:e.status===`ready`?{text:`Researched`,tone:`muted`}:e.status===`error`?{text:k.error,tone:`danger`}:{text:k[e.status],tone:`muted`}}function j(e){let t=me[e.item.source];return e.item.channel?`${t} #${e.item.channel}`:t}function M(e){return e.entry.item.title||`Untitled question`}function he(e){return e.status!==`running`&&e.status!==`queued`}function ge(e){return e.status!==`aside`}function _e(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 N(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 ve(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 P=[`key`,`readToken`,`project`,`skill`,`discord`];function ye(e){let t=e===`finished`?P.length:P.indexOf(e),n=e=>e<t?`done`:e===t?`current`:`upcoming`;return{key:n(0),readToken:n(1),project:n(2),skill:n(3),discord:n(4)}}function be(e){let t=e.split(/[\s,]+/).map(e=>e.replace(/^#/,``)).filter(Boolean);return[...new Set(t)]}var F=2;function I(e){t({type:`dashboard-telemetry`,event:`operator_action`,properties:{surface:`onboarding`,action:e}})}function L(){let e=m().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:F,skill:typeof t.skill==`string`?t.skill:``,discordChannels:n}}function xe(e,t,n,r){let i=s(`input`,`dialog-input repo-roots-adder-input`);return i.id=e,i.type=r,i.value=t,i.placeholder=n,i.autocomplete=`off`,i.spellcheck=!1,i}function Se({onFinish:t}){let n=s(`section`,`first-run-checklist review-setup`);n.setAttribute(`aria-labelledby`,`community-setup-title`);let i=s(`h2`,`first-run-title`,`Answer community questions`);i.id=`community-setup-title`;let a=s(`ol`,`first-run-steps`),o=s(`p`,`first-run-step-hint review-setup-foot`,`Each question gets a researched draft reply. Nothing posts until you post it yourself. `);o.append(ce(`lanes-community`,`community-enabled`,`All community settings`));let c=s(`div`,`first-run-step-actions`),l=r({variant:`primary`,label:`Finish setup`,action:`finish-community-setup`});c.append(l),c.hidden=!0,n.append(s(`span`,`first-run-eyebrow`,`SET UP COMMUNITY`),i,a,c,o);let u=null;l.addEventListener(`click`,()=>{I(`finish-community-setup`),u=null,t()});function p(){return D(`posthog.apiKey`)?E()?null:`readToken`:`key`}function m(e){u=e===`readToken`&&E()?`project`:e,x(),(a.querySelector(`[aria-current="step"] input`)??(c.hidden?null:l))?.focus()}async function h(t,n,r,i){n.disabled=!0,r.show(`busy`,`Saving`);try{let n=await e(`update-settings`,{settings:t},{timeoutMs:f});if(n.type===`settings-error`){r.show(`error`,n.message);return}if(n.type!==`settings-updated`){r.show(`error`,`The server did not confirm the save.`);return}ne(n.settings),m(i)}catch(e){r.show(`error`,ee(e,f))}finally{n.disabled=!1}}function g(e){let t=xe(e.inputId,e.initialValue,e.placeholder,e.inputType),n=s(`label`,`repo-roots-adder-label`,e.label);n.htmlFor=t.id;let i=s(`div`,`first-run-step-actions`),a=d(),o=r({variant:`primary`,label:e.saveLabel,action:e.action}),c=()=>{let n=e.settingsPatch(t.value);typeof n==`string`?a.show(`error`,n):(I(e.action),h(n,o,a,e.nextProgress))};if(o.addEventListener(`click`,c),t.addEventListener(`keydown`,e=>{e.key===`Enter`&&(e.preventDefault(),c())}),i.append(o),e.isSkippable){let t=r({variant:`secondary`,label:`Skip`,action:`skip-community-setup-step`,onClick:()=>m(e.nextProgress)});i.append(t)}return i.append(a.element),[s(`p`,`first-run-step-text`,e.advice),n,t,i]}let _=()=>g({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:`readToken`,isSkippable:!1,settingsPatch:e=>e.trim()?{posthog:{apiKey:e.trim()}}:`Paste a PostHog personal API key.`}),v=()=>g({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(L().projectId),placeholder:String(F),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.`}}),y=()=>g({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:L().skill,placeholder:`skill name`,saveLabel:`Save skill`,action:`save-community-skill`,nextProgress:`discord`,isSkippable:!0,settingsPatch:e=>({community:{skill:e.trim().replace(/^\//,``)}})}),b=()=>g({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:L().discordChannels.join(`, `),placeholder:`community-questions, help`,saveLabel:`Save channels`,action:`save-community-discord`,nextProgress:`finished`,isSkippable:!0,settingsPatch:e=>{let t=be(e);return t.length>0?{community:{discordChannels:t}}:`Type at least one channel, or skip.`}});function x(){if(!u)return;let e=ye(u);a.replaceChildren(O({title:`1. PostHog personal API key`,state:e.key,summary:`Key saved`,badge:`NEEDED`,body:_}),O({title:`2. Read-only GitHub token`,state:e.readToken,summary:`Token saved`,badge:`REQUIRED`,body:()=>ue({laneWork:`Community research reads the GitHub issues, code and pages a question links.`,onSaved:()=>m(`project`)})}),O({title:`3. PostHog project`,state:e.project,summary:`Project ${L().projectId}`,badge:``,body:v}),O({title:`4. Research skill (optional)`,state:e.skill,summary:L().skill||`No skill`,badge:``,body:y}),O({title:`5. Discord (optional)`,state:e.discord,summary:L().discordChannels.map(e=>`#${e}`).join(` `)||`Forum only`,badge:``,body:b})),c.hidden=u!==`finished`}function S(){u=p()??`key`,x()}return te(e=>{e.kind===`broadcast`&&(u===`key`&&D(`posthog.apiKey`)&&m(`readToken`),u===`readToken`&&E()&&m(`project`))}),{element:n,open:S,isOpen:()=>u!==null,needsSetup:()=>p()!==null}}var R=null,z=null,B=null,V=[],H=null,U=!1,W=null,G=null,K=``,q=new Map,J=null;function Ce(){return ve([...l].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 Y(e,t,n){let r=s(`ul`,e);r.setAttribute(`aria-label`,t);for(let e of n)r.append(s(`li`,null,e));return r}function we(e){let t=s(`div`,`pr-detail-heading`),n=s(`div`,`pr-detail-title`);n.append(s(`h2`,null,e.item.title||`Untitled question`));let r=s(`div`,`pr-detail-meta`),i=Date.parse(e.item.createdAt);r.append(s(`span`,null,e.item.author),s(`span`,null,j(e))),Number.isNaN(i)||r.append(s(`span`,null,`Asked ${re(i)}`));for(let t of e.item.tags)r.append(s(`span`,`author-org-tag`,t));return t.append(n,r),t}function Te(e){let t=s(`section`,`community-question`);return t.setAttribute(`aria-label`,`Question as asked`),t.append(s(`h3`,`pr-section-heading`,`Question as asked`),s(`p`,`community-question-body`,e.item.body)),t}function Ee(e){let t=s(`section`,`pr-verdict-box`);t.setAttribute(`aria-label`,`Research`);let n=A(e),r=s(`div`,`pr-verdict-line`),i=s(`strong`,`community-badge`,n.text);if(i.dataset.tone=n.tone,r.append(i),t.append(r),e.error&&t.append(s(`p`,`pr-attention-detail`,e.error)),e.summary&&t.append(s(`p`,`pr-verdict-summary`,e.summary)),e.goal&&t.append(s(`p`,`community-goal`,`Goal: ${e.goal}`)),e.gaps.length>0&&t.append(Y(`pr-verdict-gaps`,`Not covered`,e.gaps)),e.checked.length===0)return t;let a=s(`details`,`pr-verdict-checked`);return a.append(s(`summary`,null,`What it checked (${e.checked.length})`),Y(`community-checked`,`What it checked`,e.checked)),t.append(a),t}function De(e){if(!e.draft)return null;let t=s(`section`,`community-draft`);t.setAttribute(`aria-label`,`Draft reply`),t.append(s(`h3`,`pr-section-heading`,`Draft reply`),s(`p`,`community-draft-body`,e.draft.body));let n=e.draft.publicLinks.filter(x);if(n.length===0)return t;let i=s(`ul`,`community-links`);for(let e of n){let t=s(`li`);t.append(r({variant:`secondary`,size:`small`,label:e,action:`open-public-link`,onClick:()=>S(e)})),i.append(t)}return t.append(i),t}function Oe(e,t){let n=e.draft?i(e.draft.body):null;n?n.then(()=>t.show(`ok`,`Draft copied. Post it yourself where the question was asked.`),()=>t.show(`error`,`Copying failed. Select the draft text instead.`)):t.show(`error`,`This browser does not allow copying here. Select the draft text instead.`)}async function ke(e,t){if(!K){t.show(`error`,`Pick a session to start from first.`);return}let n=await u(`open-community-session`,{key:e.item.key,projectId:K},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&&h()?.openTerminal(n.sessionId)):t.show(`error`,n.error??`The session did not start.`))}async function X(e,t,n){let r=t===`rerun`?`Queuing the research again.`:`Setting the question aside.`,i=await u(`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 Ae(){let e=s(`select`,`community-session-picker`);e.setAttribute(`aria-label`,`Session to start from`);let t=Ce();t.some(e=>e.id===K)||(K=t[0]?.id??``);for(let n of t){let t=s(`option`,null,n.name);t.value=n.id,t.selected=n.id===K,e.append(t)}return e.disabled=t.length===0,e.addEventListener(`change`,()=>{K=e.value}),e}function je(e){let t=s(`div`,`community-actions`),n=d(`pr-action-status`),i=s(`div`,`community-action-buttons`);return i.append(r({variant:`secondary`,label:`Copy draft`,action:`copy-draft`,disabled:e.draft===null,onClick:()=>Oe(e,n)}),r({variant:`secondary`,label:`Open thread`,action:`open-thread`,disabled:!x(e.item.url),onClick:()=>S(e.item.url)}),Ae(),r({variant:`primary`,label:`Start session`,action:`start-session`,onClick:()=>void ke(e,n)}),r({variant:`secondary`,label:`Re-run`,action:`rerun-community-research`,disabled:!he(e),onClick:()=>void X(e,`rerun`,n)}),r({variant:`secondary`,label:`Set aside`,action:`set-aside-community-question`,disabled:!ge(e),onClick:()=>void X(e,`set-aside`,n)})),t.append(i,n.element),t}function Me(e){let t=s(`article`,`pr-detail community-detail`),n=De(e);return t.append(we(e),je(e),...n?[n]:[],Ee(e),Te(e)),t}function Z(){if(!B)return;let e=C(V,H),t=e?JSON.stringify(e.entry):`empty:${y(V).length}`;if(t===G)return;if(G=t,e){B.replaceChildren(Me(e.entry));return}let n=V.some(e=>e.items.length>0);B.replaceChildren(n?le({title:`All caught up`,detail:_e(V)}):s(`p`,`pr-empty`,N(w())))}function Ne(e,t){se(T(e))&&t.querySelector(`.pr-queue-unseen`)?.remove()}function Q(e){H=e;for(let[t,n]of q)n.setAttribute(`aria-current`,String(t===e));let t=C(V,e),n=q.get(e);t&&n&&Ne(t,n),Z(),R&&(R.dataset.detailOpen=`true`)}function Pe(){R&&(R.dataset.detailOpen=`false`),H&&q.get(H)?.focus({preventScroll:!0})}function Fe(e){let t=C(V,e);if(!t)return;V.find(e=>e.items.includes(t))?.id===`aside`&&(U=!0),H=e,$(),Q(e);let n=q.get(e);n?.focus({preventScroll:!0}),n?.scrollIntoView({block:`nearest`})}function Ie(e){if(e.repeat||e.defaultPrevented||!R||a(R)||c()||o(e)||document.activeElement?.classList.contains(`xterm-helper-textarea`))return;let t=_(e);if(t!==`next-row`&&t!==`previous-row`)return;let n=oe([...q.keys()],H,t===`next-row`?1:-1);n&&(e.preventDefault(),n!==H&&Fe(n))}function Le(e,t){let r=n(`pr-queue-row pr-queue-row-quiet`);r.dataset.queueKey=e.key,r.setAttribute(`aria-current`,String(e.key===H));let i=A(e.entry),a=s(`span`,`review-queue-action community-badge`,i.text);a.dataset.tone=i.tone;let o=s(`span`,`pr-queue-top`);if(o.append(a,s(`span`,`pr-queue-title`,M(e))),r.append(o,s(`span`,`pr-queue-elapsed`,j(e.entry))),r.title=M(e),t&&ie(T(e))){let e=s(`span`,`tab-activity active pr-queue-unseen`);e.setAttribute(`aria-hidden`,`true`),r.append(e)}return r.addEventListener(`click`,()=>Q(e.key)),q.set(e.key,r),r}function Re(e){let t=s(`h3`,`pr-section-heading review-group-heading`),r=s(`span`,`review-group-count`,String(e.items.length));if(e.id!==`aside`)return t.append(s(`span`,null,e.title),r),t;let i=n(`review-group-toggle`),a=s(`span`,`review-group-chevron`,`▸`);return a.setAttribute(`aria-hidden`,`true`),i.append(a,e.title),i.setAttribute(`aria-expanded`,String(U)),i.addEventListener(`click`,()=>{U=!U,W=null,$()}),t.append(i,r),t}function ze(e){let t=s(`section`,`pr-queue-section`);if(t.dataset.group=e.id,t.append(Re(e)),e.id===`aside`&&!U)return t;for(let n of e.items)t.append(Le(n,e.id===`turn`));return t}function Be(){if(!R||!J)return!1;w()?.configured===!1&&J.needsSetup()&&!J.isOpen()&&J.open();let e=J.isOpen();return R.dataset.setup=String(e),J.element.hidden=!e,e}function $(){if(!z||Be())return;V=ae(),H=p(V.filter(e=>e.id!==`aside`||U),H);let e=JSON.stringify([V,H,U,v(),w()?.error??null]);if(e!==W){W=e,q.clear();let t=w()?.error,n=t?[s(`p`,`my-pr-note`,t)]:[],r=V.filter(e=>e.items.length>0).map(ze);z.replaceChildren(...n,...r.length>0?r:[s(`p`,`pr-empty`,N(w()))])}Z()}function Ve(e){if(R)return;R=s(`div`,`pr-content review-queue community-queue`),e.append(R);let t=de({queueLabel:`Community questions`,scopeTabs:null,resizerLabel:`Resize community queue`});z=t.queue,B=s(`div`,`review-queue-detail`);let n=s(`div`,`review-queue-phone-bar`);n.append(r({variant:`secondary`,label:`Back to queue`,action:`back-to-queue`,onClick:Pe})),t.detail.append(n,B),J=Se({onFinish:$}),J.element.hidden=!0,R.append(J.element,t.columns),R.dataset.detailOpen=`false`,g(()=>!a(R)),b(e=>{e.kind===`status`&&$()}),document.addEventListener(`keydown`,Ie),$()}var He={mount:Ve,refresh:()=>{G=null,$()}};export{He as view};
|
|
Binary file
|