cogpit 2.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (21) hide show
  1. package/dist/cli.js +93 -21
  2. package/dist/web/assets/{CommandPaletteHost-ChH6w0Bx.js → CommandPaletteHost-CyKWHB_t.js} +1 -1
  3. package/dist/web/assets/{ConfigBrowser-CPCH7_25.js → ConfigBrowser-CmApjOBh.js} +1 -1
  4. package/dist/web/assets/{HighlightedEditor-BPmH8BvC.js → HighlightedEditor-D4DdiaD3.js} +1 -1
  5. package/dist/web/assets/{KeyboardShortcutsDialog-CTbXz40Z.js → KeyboardShortcutsDialog-CaqJ90ox.js} +1 -1
  6. package/dist/web/assets/{MobileFileChanges-C5VoKbje.js → MobileFileChanges-BjHkXuyc.js} +1 -1
  7. package/dist/web/assets/{PreviewPanel-DoAf1W2k.js → PreviewPanel-DVORy2rT.js} +1 -1
  8. package/dist/web/assets/{ProjectFilesPanel-v_O7Awnm.js → ProjectFilesPanel-WiqiZyLW.js} +1 -1
  9. package/dist/web/assets/{ProjectSwitcherModal-CSZrCd3X.js → ProjectSwitcherModal-CxLemcBj.js} +1 -1
  10. package/dist/web/assets/{TerminalOutput-SImEU6_6.js → TerminalOutput-zSNcaPSy.js} +1 -1
  11. package/dist/web/assets/{ThemeSelectorModal-rjVBMgWC.js → ThemeSelectorModal-D0yWwDku.js} +1 -1
  12. package/dist/web/assets/{WorkflowsPanel-JVqgKAzY.js → WorkflowsPanel-Doy9QzhU.js} +1 -1
  13. package/dist/web/assets/{WorktreePanel-D94-oAau.js → WorktreePanel-CgWELvag.js} +1 -1
  14. package/dist/web/assets/{index-S7UMnH_y.js → index-BG9ZLZQ3.js} +1 -1
  15. package/dist/web/assets/{index-C5VcQtkE.js → index-BPqm0HzF.js} +1 -1
  16. package/dist/web/assets/{index-CNV6e3p0.js → index-C3E35E2A.js} +69 -69
  17. package/dist/web/assets/{index-C00ZsBZl.js → index-C4XoqTra.js} +1 -1
  18. package/dist/web/assets/session-parser.worker-DJxJ4O8Q.js +22 -0
  19. package/dist/web/index.html +1 -1
  20. package/package.json +1 -1
  21. package/dist/web/assets/session-parser.worker-BhyaigCR.js +0 -22
package/dist/cli.js CHANGED
@@ -4252,6 +4252,7 @@ function sendJson2(res, status, payload, deviceId) {
4252
4252
  res.statusCode = status;
4253
4253
  res.setHeader("Content-Type", "application/json");
4254
4254
  if (deviceId) res.setHeader("X-Cogpit-Device", deviceId);
4255
+ res.setHeader("X-Cogpit-Hub-Error", payload.code);
4255
4256
  res.end(JSON.stringify(payload));
4256
4257
  }
4257
4258
  function stripHubToken(rawQuery) {
@@ -4679,7 +4680,10 @@ var init_proxy = __esm({
4679
4680
  "proxy-authorization",
4680
4681
  // A downstream device must never be able to mint or overwrite the hub's
4681
4682
  // origin-scoped browser session cookie.
4682
- "set-cookie"
4683
+ "set-cookie",
4684
+ // Only the hub may claim a failure was the hub's own; otherwise a device
4685
+ // could forge an "unreachable" verdict about itself.
4686
+ "x-cogpit-hub-error"
4683
4687
  ]);
4684
4688
  }
4685
4689
  });
@@ -8551,6 +8555,14 @@ function extractUserText(obj) {
8551
8555
  if (extracted && SKIP_RE.test(extracted)) return "";
8552
8556
  return extracted;
8553
8557
  }
8558
+ function isPromptRecord(obj) {
8559
+ if (obj.origin?.kind === "task-notification") return false;
8560
+ const content = obj.message?.content;
8561
+ if (Array.isArray(content)) {
8562
+ return !content.some((block) => block?.type === "tool_result");
8563
+ }
8564
+ return true;
8565
+ }
8554
8566
  async function getSessionMeta(filePath) {
8555
8567
  let lines;
8556
8568
  let isPartialRead = false;
@@ -8641,12 +8653,14 @@ async function getSessionMeta(filePath) {
8641
8653
  }
8642
8654
  if (obj.type === "user" && !obj.isMeta) {
8643
8655
  if (obj.timestamp) lastTimestamp = obj.timestamp;
8644
- const extracted = extractUserText(obj);
8645
- if (extracted) {
8646
- if (!firstUserMessage) firstUserMessage = extracted;
8647
- lastUserMessage = extracted;
8656
+ if (isPromptRecord(obj)) {
8657
+ turnCount++;
8658
+ const extracted = extractUserText(obj);
8659
+ if (extracted) {
8660
+ if (!firstUserMessage) firstUserMessage = extracted;
8661
+ lastUserMessage = extracted;
8662
+ }
8648
8663
  }
8649
- turnCount++;
8650
8664
  }
8651
8665
  } catch {
8652
8666
  }
@@ -8700,7 +8714,7 @@ async function getSessionMeta(filePath) {
8700
8714
  lastTimestamp = obj.timestamp;
8701
8715
  foundTimestamp = true;
8702
8716
  }
8703
- if (!foundMessage) {
8717
+ if (!foundMessage && isPromptRecord(obj)) {
8704
8718
  const extracted = extractUserText(obj);
8705
8719
  if (extracted) {
8706
8720
  lastUserMessage = extracted;
@@ -9476,7 +9490,7 @@ var init_package = __esm({
9476
9490
  package_default = {
9477
9491
  name: "cogpit",
9478
9492
  private: true,
9479
- version: "2.0.0",
9493
+ version: "2.0.1",
9480
9494
  description: "Control center for Claude Code and OpenAI Codex agent sessions",
9481
9495
  license: "MIT",
9482
9496
  author: {
@@ -14367,9 +14381,10 @@ var init_devices = __esm({
14367
14381
  init_registry();
14368
14382
  init_device_client();
14369
14383
  init_connection_invalidation();
14384
+ init_proxy();
14370
14385
  DEFAULT_PORT2 = 19384;
14371
14386
  DEFAULT_TLS_PORT2 = 443;
14372
- PROBE_TIMEOUT_MS = 3e3;
14387
+ PROBE_TIMEOUT_MS = CONNECT_WATCHDOG_MS;
14373
14388
  PROBE_MESSAGES = {
14374
14389
  UNREACHABLE: "Could not reach the device. Check the host, port, and that it is running.",
14375
14390
  NOT_COGPIT: "That address responded, but it is not a Cogpit device.",
@@ -20407,6 +20422,12 @@ function isVisibleQueuedPrompt(content) {
20407
20422
  if (!trimmed.startsWith("<")) return true;
20408
20423
  return !trimmed.includes("<task-notification>") && !trimmed.startsWith("<system-reminder>") && !trimmed.startsWith("<local-command-");
20409
20424
  }
20425
+ function isTaskNotificationRecord(msg) {
20426
+ if (msg.origin?.kind === "task-notification") return true;
20427
+ const text = extractTextFromContent(msg.message.content);
20428
+ if (!text.includes("<task-notification>")) return false;
20429
+ return text.replace(TASK_NOTIFICATION_BLOCK_RE, "").replace(ANY_TAG_RE, "").trim() === "";
20430
+ }
20410
20431
  function queuedCommandPrompt(msg) {
20411
20432
  if (!isAttachmentMessage(msg)) return null;
20412
20433
  const attachment = msg.attachment;
@@ -20821,6 +20842,21 @@ function buildTurns(messages) {
20821
20842
  continue;
20822
20843
  }
20823
20844
  }
20845
+ if (isTaskNotificationRecord(msg)) {
20846
+ const notification = {
20847
+ kind: "task_notification",
20848
+ content: extractTextFromContent(content),
20849
+ timestamp: msg.timestamp
20850
+ };
20851
+ if (current) {
20852
+ current.contentBlocks.push(notification);
20853
+ continue;
20854
+ }
20855
+ current = createTurn2(msg, null);
20856
+ current.contentBlocks.push(notification);
20857
+ attachPendingCompaction(current);
20858
+ continue;
20859
+ }
20824
20860
  finalizeTurn2();
20825
20861
  current = createTurn2(msg, msg.message.content);
20826
20862
  attachPendingCompaction(current);
@@ -21043,7 +21079,9 @@ function buildTurns(messages) {
21043
21079
  continue;
21044
21080
  }
21045
21081
  if (isSystemMessage(msg) && msg.subtype === "turn_duration" && current) {
21046
- current.durationMs = msg.durationMs ?? null;
21082
+ if (msg.durationMs !== void 0 && msg.durationMs !== null) {
21083
+ current.durationMs = (current.durationMs ?? 0) + msg.durationMs;
21084
+ }
21047
21085
  continue;
21048
21086
  }
21049
21087
  }
@@ -21051,11 +21089,13 @@ function buildTurns(messages) {
21051
21089
  finalizeTurn2();
21052
21090
  return pairAgentMessageReplies(turns);
21053
21091
  }
21054
- var ATTRIBUTION_FIELDS, RESUME_PREAMBLE_RE, RESUME_INSTRUCTIONS_RE;
21092
+ var TASK_NOTIFICATION_BLOCK_RE, ANY_TAG_RE, ATTRIBUTION_FIELDS, RESUME_PREAMBLE_RE, RESUME_INSTRUCTIONS_RE;
21055
21093
  var init_turnBuilder = __esm({
21056
21094
  "../../shared/session/turnBuilder.ts"() {
21057
21095
  init_messageTypeGuards();
21058
21096
  init_agentEnvelope();
21097
+ TASK_NOTIFICATION_BLOCK_RE = /<task-notification>[\s\S]*?<\/task-notification>/g;
21098
+ ANY_TAG_RE = /<[^>]*>/g;
21059
21099
  ATTRIBUTION_FIELDS = [
21060
21100
  ["attributionAgent", "agent"],
21061
21101
  ["attributionSkill", "skill"],
@@ -21293,6 +21333,8 @@ function mapContentBlock(block) {
21293
21333
  };
21294
21334
  case "recap":
21295
21335
  return { kind: "recap", content: block.content, timestamp: block.timestamp ?? null };
21336
+ case "task_notification":
21337
+ return { kind: "task_notification", content: block.content, timestamp: block.timestamp ?? null };
21296
21338
  default: {
21297
21339
  const exhaustive = block;
21298
21340
  return exhaustive;
@@ -23656,8 +23698,12 @@ var init_undo = __esm({
23656
23698
  function finiteNumber(value) {
23657
23699
  return typeof value === "number" && Number.isFinite(value) ? value : null;
23658
23700
  }
23701
+ function entryRank(name, normalized, hasCacheRates) {
23702
+ return (hasCacheRates ? 2 : 0) + (name === normalized ? 1 : 0);
23703
+ }
23659
23704
  function parseRateTable(document) {
23660
23705
  const table = /* @__PURE__ */ new Map();
23706
+ const ranks = /* @__PURE__ */ new Map();
23661
23707
  if (typeof document !== "object" || document === null) return table;
23662
23708
  for (const [name, raw] of Object.entries(document)) {
23663
23709
  if (typeof raw !== "object" || raw === null) continue;
@@ -23665,14 +23711,22 @@ function parseRateTable(document) {
23665
23711
  const input = finiteNumber(entry.input_cost_per_token);
23666
23712
  const output = finiteNumber(entry.output_cost_per_token);
23667
23713
  if (input === null || output === null) continue;
23668
- table.set(normalizeModelName(name), {
23714
+ const cacheRead = finiteNumber(entry.cache_read_input_token_cost);
23715
+ const cacheCreation = finiteNumber(entry.cache_creation_input_token_cost);
23716
+ const normalized = normalizeModelName(name);
23717
+ const rank = entryRank(name.trim().toLowerCase(), normalized, cacheRead !== null);
23718
+ if (rank <= (ranks.get(normalized) ?? -1)) continue;
23719
+ ranks.set(normalized, rank);
23720
+ table.set(normalized, {
23669
23721
  inputCostPerToken: input,
23670
23722
  outputCostPerToken: output,
23671
23723
  // Anthropic bills cache reads at a discount and cache writes at a
23672
23724
  // premium. When a model omits them, cached input is priced as plain
23673
23725
  // input rather than as free.
23674
- cacheReadCostPerToken: finiteNumber(entry.cache_read_input_token_cost) ?? input,
23675
- cacheCreationCostPerToken: finiteNumber(entry.cache_creation_input_token_cost) ?? input
23726
+ cacheReadCostPerToken: cacheRead ?? input,
23727
+ cacheCreationCostPerToken: cacheCreation ?? input,
23728
+ // Models that sell only one cache TTL publish no premium rate.
23729
+ cacheCreation1hCostPerToken: finiteNumber(entry.cache_creation_input_token_cost_above_1hr) ?? cacheCreation ?? input
23676
23730
  });
23677
23731
  }
23678
23732
  return table;
@@ -23693,7 +23747,8 @@ function priceUsage(table, model, totals, reportedCostUsd) {
23693
23747
  }
23694
23748
  const rate = lookupRate(table, model);
23695
23749
  if (rate === null) return { costUsd: 0, costSource: "unpriced" };
23696
- const costUsd = totals.uncachedInputTokens * rate.inputCostPerToken + totals.cachedInputTokens * rate.cacheReadCostPerToken + totals.cacheCreationTokens * rate.cacheCreationCostPerToken + totals.outputTokens * rate.outputCostPerToken;
23750
+ const cacheCreation1h = Math.min(totals.cacheCreation1hTokens, totals.cacheCreationTokens);
23751
+ const costUsd = totals.uncachedInputTokens * rate.inputCostPerToken + totals.cachedInputTokens * rate.cacheReadCostPerToken + (totals.cacheCreationTokens - cacheCreation1h) * rate.cacheCreationCostPerToken + cacheCreation1h * rate.cacheCreation1hCostPerToken + totals.outputTokens * rate.outputCostPerToken;
23697
23752
  return { costUsd, costSource: "modelPriced" };
23698
23753
  }
23699
23754
  function cacheSavingsUsd(table, model, totals) {
@@ -23721,6 +23776,7 @@ function emptyUsageCostTotals() {
23721
23776
  uncachedInputTokens: 0,
23722
23777
  cachedInputTokens: 0,
23723
23778
  cacheCreationTokens: 0,
23779
+ cacheCreation1hTokens: 0,
23724
23780
  outputTokens: 0,
23725
23781
  reasoningTokens: 0
23726
23782
  };
@@ -23730,6 +23786,7 @@ function addUsageCostTotals(a, b) {
23730
23786
  uncachedInputTokens: a.uncachedInputTokens + b.uncachedInputTokens,
23731
23787
  cachedInputTokens: a.cachedInputTokens + b.cachedInputTokens,
23732
23788
  cacheCreationTokens: a.cacheCreationTokens + b.cacheCreationTokens,
23789
+ cacheCreation1hTokens: a.cacheCreation1hTokens + b.cacheCreation1hTokens,
23733
23790
  outputTokens: a.outputTokens + b.outputTokens,
23734
23791
  reasoningTokens: a.reasoningTokens + b.reasoningTokens
23735
23792
  };
@@ -23880,10 +23937,18 @@ function parseClaudeUsageLine(line) {
23880
23937
  const messageId = typeof message.id === "string" ? message.id : null;
23881
23938
  const requestId = typeof record.requestId === "string" ? record.requestId : null;
23882
23939
  const dedupeKey = messageId === null && requestId === null ? null : `${messageId ?? ""}:${requestId ?? ""}`;
23940
+ const cacheCreationTokens = int(usage.cache_creation_input_tokens);
23941
+ const byTtl = asRecord4(usage.cache_creation);
23883
23942
  const totals = {
23884
23943
  uncachedInputTokens: int(usage.input_tokens),
23885
23944
  cachedInputTokens: int(usage.cache_read_input_tokens),
23886
- cacheCreationTokens: int(usage.cache_creation_input_tokens),
23945
+ cacheCreationTokens,
23946
+ // Priced at a premium, so never let a malformed breakdown claim more of
23947
+ // the write than the write itself reports.
23948
+ cacheCreation1hTokens: Math.min(
23949
+ cacheCreationTokens,
23950
+ byTtl ? int(byTtl.ephemeral_1h_input_tokens) : 0
23951
+ ),
23887
23952
  outputTokens: int(usage.output_tokens),
23888
23953
  // Anthropic folds thinking tokens into output and does not break them out.
23889
23954
  reasoningTokens: 0
@@ -23961,6 +24026,8 @@ function parseCodexUsageLine(line, state) {
23961
24026
  uncachedInputTokens: Math.max(0, inputTokens - cachedInputTokens - cacheCreationTokens),
23962
24027
  cachedInputTokens,
23963
24028
  cacheCreationTokens,
24029
+ // Codex reports no cache TTL split.
24030
+ cacheCreation1hTokens: 0,
23964
24031
  outputTokens,
23965
24032
  // Reported inside output_tokens, surfaced separately for the token mix.
23966
24033
  reasoningTokens: Math.min(outputTokens, int(last.reasoning_output_tokens))
@@ -24046,14 +24113,19 @@ async function readTranscriptRecords(filePath, provider) {
24046
24113
  return records;
24047
24114
  }
24048
24115
  function dedupeWithinFile(records) {
24049
- const seen = /* @__PURE__ */ new Set();
24116
+ const slotByKey = /* @__PURE__ */ new Map();
24050
24117
  const kept = [];
24051
24118
  for (const record of records) {
24052
- if (record.dedupeKey !== null) {
24053
- if (seen.has(record.dedupeKey)) continue;
24054
- seen.add(record.dedupeKey);
24119
+ if (record.dedupeKey === null) {
24120
+ kept.push(record);
24121
+ continue;
24122
+ }
24123
+ const slot = slotByKey.get(record.dedupeKey);
24124
+ if (slot === void 0) {
24125
+ slotByKey.set(record.dedupeKey, kept.push(record) - 1);
24126
+ continue;
24055
24127
  }
24056
- kept.push(record);
24128
+ if (record.totals.outputTokens > kept[slot].totals.outputTokens) kept[slot] = record;
24057
24129
  }
24058
24130
  return kept;
24059
24131
  }
@@ -1 +1 @@
1
- import{c as oe,j as u,r as M}from"./vendor-react-gGw_S5I_.js";import{aq as h,ar as Q,ah as le,N as ce,J as re,as as de,at as me,O as ue,C as he,M as ge,x as fe,au as ve,av as Y,aw as W,ax as we,ay as Ce,az as je,aA as Se,w as ye}from"./index-CNV6e3p0.js";import{S as xe,p as Z,q as be,P as Pe,L as Te,H as Oe,F as Ne,r as ke,g as ee,G as Fe,e as Ie,l as Ee,s as $e,t as Re,u as Ae,v as De,w as te,x as Le,y as Me,z as He,K as qe,f as Ke,A as ze,B as Be,D as ne,I as Ge,J as pe,N as Ue}from"./vendor-ui-BmLOQ5Or.js";import"./vendor-shiki-DOn6sF-i.js";import"./vendor-markdown-BE1gYnO9.js";function a(t,e,s,c,i,m,d){return{id:t,label:e,icon:c,run:i,shortcut:m,description:d,value:`${e} ${s}`}}function _(...t){return t.filter(e=>e!==!1&&e!==void 0)}function We(t){const e=oe.c(40);let s,c,i,m,d,v,w,r,C,g,y,f,x,k,b;if(e[0]!==t){const $=_(a("home","Go to dashboard","home overview",Oe,t.onGoHome),a("mission-control",t.showMission?"Exit Mission Control":"Open Mission Control","live sessions blocked waiting answer everything at once",Te,t.onToggleMissionControl,h("missionControl")),a("new-session","Start a new session","project agent chat create",Pe,t.onNewSession,h("newSession")),t.onDuplicateSession&&a("duplicate-session","Duplicate this session","copy fork clone branch thread",be,t.onDuplicateSession),t.canFocusComposer&&a("focus-composer","Focus message composer","chat prompt input",Z,t.onFocusComposer,h("focusComposer")),t.onFindInConversation&&a("find-in-conversation","Find in conversation","search text transcript turns matches",xe,t.onFindInConversation,h("findInConversation"))),I=(t.projects??[]).slice(0,8).map(n=>a(`project-${n.dirName}`,n.shortName,`${n.path} ${n.dirName} project workspace`,Ne,()=>{var l;return(l=t.onOpenProject)==null?void 0:l.call(t,n.dirName)},void 0,`${n.path} · ${n.sessionCount} session${n.sessionCount===1?"":"s"}`)),o=(t.recentSessions??[]).slice(0,10).map(n=>{const j=(n.aiTitle||n.name||n.slug||n.lastUserMessage||n.firstUserMessage||n.sessionId).replace(/\s+/g," ").trim().slice(0,160)||n.sessionId,B=[n.projectShortName,n.gitBranch].filter(Boolean).join(" · ");return a(`session-${n.dirName}-${n.fileName}`,j,`${n.projectShortName} ${n.cwd??""} ${n.gitBranch??""} ${n.sessionId} recent thread conversation`,Z,()=>{var q;return(q=t.onOpenSession)==null?void 0:q.call(t,n.dirName,n.fileName)},void 0,B)}),E=t.devices??[],P=E.length>1&&t.onSwitchDevice?E.slice(0,Q.length).map((n,l)=>a(`device-${n.id}`,n.isActive?`${n.name} (current)`:`Switch to ${n.name}`,`device machine host remote ${n.id}`,n.isLocal?ke:ee,()=>{var j;return(j=t.onSwitchDevice)==null?void 0:j.call(t,n.id)},h(Q[l]))):[],R=_(a("toggle-sidebar",t.showSidebar?"Hide session sidebar":"Show session sidebar","projects navigation panel",Re,t.onToggleSidebar,h("toggleSidebar")),t.hasSession&&a("toggle-stats",t.showStats?"Hide session analytics":"Show session analytics","stats tokens usage panel",$e,t.onToggleStats,h("toggleStats")),t.onToggleProjectFiles&&a("project-files",t.showProjectFiles?"Close project files":"Open project files","browse edit save workspace source code",Ee,t.onToggleProjectFiles,h("projectFiles")),t.hasFileChanges&&a("toggle-file-changes",t.showFileChanges?"Hide file changes":"Show file changes","diff edits review panel",Ie,t.onToggleFileChanges),t.supportsWorktrees&&t.canOpenTerminal&&a("toggle-worktrees",t.showWorktrees?"Hide worktrees":"Show worktrees","git branches panel",Fe,t.onToggleWorktrees)),A=_(t.onOpenProjectInEditor&&a("open-project-editor","Open project in editor","code cursor vscode zed workspace",pe,t.onOpenProjectInEditor),t.onRevealProject&&a("reveal-project","Reveal project in file manager","finder explorer folder directory",Ge,t.onRevealProject),t.onCopyResumeCommand&&a("copy-resume-command","Copy resume command","cli claude codex terminal clipboard continue session",ne,t.onCopyResumeCommand),t.onCopyProjectPath&&a("copy-project-path","Copy project path","workspace directory clipboard",ne,t.onCopyProjectPath),t.onOpenIntegratedTerminal&&a("integrated-terminal","New integrated terminal","embedded shell command line process panel",Be,t.onOpenIntegratedTerminal,h("newIntegratedTerminal")),t.canOpenTerminal&&a("terminal","Open in system terminal","external shell command line app",ze,t.onOpenTerminal,h("systemTerminal")),t.onTogglePreview&&a("preview","Toggle development preview","browser localhost dev server website",Ke,t.onTogglePreview,h("preview")),t.onOpenKeyboardShortcuts&&a("keyboard-shortcuts","Customize keyboard shortcuts","keybindings hotkeys settings",qe,t.onOpenKeyboardShortcuts),t.onOpenConfig&&a("config",t.showConfig?"Close agent configuration":"Open agent configuration","skills commands claude settings files",He,t.onOpenConfig),a("settings","Open Cogpit settings","preferences network",Me,t.onOpenSettings),a("theme","Change theme & chat width","appearance light dark oled width narrow wide",Le,t.onOpenTheme,h("themeSelector")),a("expand","Expand all groups","conversation details",te,t.onExpandAll,h("expandAll")),a("expand-payloads","Expand all tool payloads","raw input result diff conversation details",te,t.onExpandToolPayloads,h("expandToolPayloads")),a("collapse","Collapse all","conversation groups payloads details",De,t.onCollapseAll),t.onKillAll&&a("kill-all","Kill all agent processes","stop terminate halt everything runaway",Ae,t.onKillAll),t.onOpenDevices&&a("manage-devices","Manage devices…","remote machines hub hosts edit rename remove switch",Ue,()=>{var n;return(n=t.onOpenDevices)==null?void 0:n.call(t,"manage")}),t.onOpenDevices&&a("add-device","Add device…","remote machine hub host connect pair new",ee,()=>{var n;return(n=t.onOpenDevices)==null?void 0:n.call(t,"add")})),D=[{value:"Navigation",items:$},...o.length>0?[{value:"Recent sessions",items:o}]:[],...I.length>0?[{value:"Projects",items:I}]:[],...P.length>0?[{value:"Devices",items:P}]:[],{value:"View",items:R},{value:"Tools",items:A}],F=function(l){t.onOpenChange(!1),l.run()};i=me,x=t.open,k=t.onOpenChange,b="Command palette",v="Search for a Cogpit action to run.",w="max-w-xl",c=ue,C="Search commands",g=!0,e[16]===Symbol.for("react.memo_cache_sentinel")?(y=u.jsx(he,{"aria-label":"Search commands",autoFocus:!0,placeholder:"Search commands..."}),e[16]=y):y=e[16],e[17]!==t.loadingNavigation?(f=t.loadingNavigation&&u.jsxs("div",{className:"motion-enter flex items-center gap-2 px-3 py-2 text-xs text-muted-foreground",role:"status",children:[u.jsx(le,{className:"size-3.5"}),"Loading projects and sessions..."]}),e[17]=t.loadingNavigation,e[18]=f):f=e[18],s=ge,m="max-h-[min(26rem,60vh)]",e[19]===Symbol.for("react.memo_cache_sentinel")?(d=u.jsx(fe,{children:"No matching actions."}),e[19]=d):d=e[19],r=D.map(n=>u.jsx(ce,{heading:n.value,children:n.items.map(l=>{const j=l.icon;return u.jsxs(re,{value:l.value,onSelect:()=>F(l),children:[u.jsx(j,{"aria-hidden":"true"}),u.jsxs("span",{className:"min-w-0 flex-1",children:[u.jsx("span",{className:"block truncate",children:l.label}),l.description&&u.jsx("span",{className:"block truncate text-xs text-muted-foreground",children:l.description})]}),l.shortcut&&u.jsx(de,{children:l.shortcut})]},l.id)})},n.value)),e[0]=t,e[1]=s,e[2]=c,e[3]=i,e[4]=m,e[5]=d,e[6]=v,e[7]=w,e[8]=r,e[9]=C,e[10]=g,e[11]=y,e[12]=f,e[13]=x,e[14]=k,e[15]=b}else s=e[1],c=e[2],i=e[3],m=e[4],d=e[5],v=e[6],w=e[7],r=e[8],C=e[9],g=e[10],y=e[11],f=e[12],x=e[13],k=e[14],b=e[15];let T;e[20]!==s||e[21]!==m||e[22]!==d||e[23]!==r?(T=u.jsxs(s,{className:m,children:[d,r]}),e[20]=s,e[21]=m,e[22]=d,e[23]=r,e[24]=T):T=e[24];let O;e[25]!==c||e[26]!==T||e[27]!==C||e[28]!==g||e[29]!==y||e[30]!==f?(O=u.jsxs(c,{label:C,loop:g,children:[y,f,T]}),e[25]=c,e[26]=T,e[27]=C,e[28]=g,e[29]=y,e[30]=f,e[31]=O):O=e[31];let N;return e[32]!==i||e[33]!==v||e[34]!==w||e[35]!==O||e[36]!==x||e[37]!==k||e[38]!==b?(N=u.jsx(i,{open:x,onOpenChange:k,title:b,description:v,className:w,children:O}),e[32]=i,e[33]=v,e[34]=w,e[35]=O,e[36]=x,e[37]=k,e[38]=b,e[39]=N):N=e[39],N}async function ae(t,e){const s=await ye(t,{signal:e});if(!s.ok)throw new Error(`Request failed (${s.status})`);const c=await s.json();return Array.isArray(c)?c:[]}function Ye(t){var J;const e=oe.c(48);let s,c,i,m,d,v;e[0]!==t?({open:i,currentProjectDirName:s,projectCwd:d,onProcessStarted:c,launchTerminalRequest:v,...m}=t,e[0]=t,e[1]=s,e[2]=c,e[3]=i,e[4]=m,e[5]=d,e[6]=v):(s=e[1],c=e[2],i=e[3],m=e[4],d=e[5],v=e[6]);const w=v===void 0?0:v,r=ve();let C;e[7]===Symbol.for("react.memo_cache_sentinel")?(C=[],e[7]=C):C=e[7];const[g,y]=M.useState(C);let f;e[8]===Symbol.for("react.memo_cache_sentinel")?(f=[],e[8]=f):f=e[8];const[x,k]=M.useState(f),[b,T]=M.useState(!1),O=M.useRef(0);let N,$;e[9]!==i?(N=()=>{if(!i)return;const S=new AbortController;return T(!0),Promise.allSettled([ae("/api/projects",S.signal),ae("/api/active-sessions?limit=12&perProject=3",S.signal)]).then(H=>{const[V,X]=H;S.signal.aborted||(y(V.status==="fulfilled"?V.value:[]),k(X.status==="fulfilled"?X.value:[]),T(!1))}),()=>S.abort()},$=[i],e[9]=i,e[10]=N,e[11]=$):(N=e[10],$=e[11]),M.useEffect(N,$);let I;e:{if(d){I=d;break e}if(!s){I=null;break e}let S;e[12]!==s||e[13]!==g?(S=((J=g.find(H=>H.dirName===s))==null?void 0:J.path)??null,e[12]=s,e[13]=g,e[14]=S):S=e[14],I=S}const o=I;let E;e[15]!==c||e[16]!==r||e[17]!==o?(E=()=>{if(!o)return;const S=r.spawnTerminal({cwd:o}),H=o.replace(/\/+$/,"").split("/").at(-1)||"Terminal";c({id:S,name:H,type:"terminal",status:"running",source:o})},e[15]=c,e[16]=r,e[17]=o,e[18]=E):E=e[18];const P=E;let R,A;e[19]!==P||e[20]!==w||e[21]!==r.status||e[22]!==o?(R=()=>{w<=O.current||!o||r.status!=="connected"||(O.current=w,P())},A=[P,w,r.status,o],e[19]=P,e[20]=w,e[21]=r.status,e[22]=o,e[23]=R,e[24]=A):(R=e[23],A=e[24]),M.useEffect(R,A);let D;e[25]!==s||e[26]!==o?(D={path:o,dirName:s},e[25]=s,e[26]=o,e[27]=D):D=e[27];const F=D;let n;e[28]!==F?(n=()=>Ce(F),e[28]=F,e[29]=n):n=e[29];const l=n;let j;e[30]!==F?(j=()=>je(F),e[30]=F,e[31]=j):j=e[31];const B=j,q=!Y()&&W("hostFiles"),se=W("hostFiles")&&(!Y()||we());let K;e[32]!==o?(K=()=>{o&&Se(o)},e[32]=o,e[33]=K):K=e[33];const ie=K;let L;e[34]!==P||e[35]!==r.status||e[36]!==o?(L=o&&r.status==="connected"&&W("terminal")?P:void 0,e[34]=P,e[35]=r.status,e[36]=o,e[37]=L):L=e[37];const G=o&&se?l:void 0,p=o&&q?B:void 0,U=o?ie:void 0;let z;return e[38]!==b||e[39]!==i||e[40]!==m||e[41]!==g||e[42]!==x||e[43]!==L||e[44]!==G||e[45]!==p||e[46]!==U?(z=u.jsx(We,{...m,open:i,projects:g,recentSessions:x,loadingNavigation:b,onOpenIntegratedTerminal:L,onOpenProjectInEditor:G,onRevealProject:p,onCopyProjectPath:U}),e[38]=b,e[39]=i,e[40]=m,e[41]=g,e[42]=x,e[43]=L,e[44]=G,e[45]=p,e[46]=U,e[47]=z):z=e[47],z}export{Ye as CommandPaletteHost};
1
+ import{c as oe,j as u,r as M}from"./vendor-react-gGw_S5I_.js";import{aq as h,ar as Q,ah as le,N as ce,J as re,as as de,at as me,O as ue,C as he,M as ge,x as fe,au as ve,av as Y,aw as W,ax as we,ay as Ce,az as je,aA as Se,w as ye}from"./index-C3E35E2A.js";import{S as xe,p as Z,q as be,P as Pe,L as Te,H as Oe,F as Ne,r as ke,g as ee,G as Fe,e as Ie,l as Ee,s as $e,t as Re,u as Ae,v as De,w as te,x as Le,y as Me,z as He,K as qe,f as Ke,A as ze,B as Be,D as ne,I as Ge,J as pe,N as Ue}from"./vendor-ui-BmLOQ5Or.js";import"./vendor-shiki-DOn6sF-i.js";import"./vendor-markdown-BE1gYnO9.js";function a(t,e,s,c,i,m,d){return{id:t,label:e,icon:c,run:i,shortcut:m,description:d,value:`${e} ${s}`}}function _(...t){return t.filter(e=>e!==!1&&e!==void 0)}function We(t){const e=oe.c(40);let s,c,i,m,d,v,w,r,C,g,y,f,x,k,b;if(e[0]!==t){const $=_(a("home","Go to dashboard","home overview",Oe,t.onGoHome),a("mission-control",t.showMission?"Exit Mission Control":"Open Mission Control","live sessions blocked waiting answer everything at once",Te,t.onToggleMissionControl,h("missionControl")),a("new-session","Start a new session","project agent chat create",Pe,t.onNewSession,h("newSession")),t.onDuplicateSession&&a("duplicate-session","Duplicate this session","copy fork clone branch thread",be,t.onDuplicateSession),t.canFocusComposer&&a("focus-composer","Focus message composer","chat prompt input",Z,t.onFocusComposer,h("focusComposer")),t.onFindInConversation&&a("find-in-conversation","Find in conversation","search text transcript turns matches",xe,t.onFindInConversation,h("findInConversation"))),I=(t.projects??[]).slice(0,8).map(n=>a(`project-${n.dirName}`,n.shortName,`${n.path} ${n.dirName} project workspace`,Ne,()=>{var l;return(l=t.onOpenProject)==null?void 0:l.call(t,n.dirName)},void 0,`${n.path} · ${n.sessionCount} session${n.sessionCount===1?"":"s"}`)),o=(t.recentSessions??[]).slice(0,10).map(n=>{const j=(n.aiTitle||n.name||n.slug||n.lastUserMessage||n.firstUserMessage||n.sessionId).replace(/\s+/g," ").trim().slice(0,160)||n.sessionId,B=[n.projectShortName,n.gitBranch].filter(Boolean).join(" · ");return a(`session-${n.dirName}-${n.fileName}`,j,`${n.projectShortName} ${n.cwd??""} ${n.gitBranch??""} ${n.sessionId} recent thread conversation`,Z,()=>{var q;return(q=t.onOpenSession)==null?void 0:q.call(t,n.dirName,n.fileName)},void 0,B)}),E=t.devices??[],P=E.length>1&&t.onSwitchDevice?E.slice(0,Q.length).map((n,l)=>a(`device-${n.id}`,n.isActive?`${n.name} (current)`:`Switch to ${n.name}`,`device machine host remote ${n.id}`,n.isLocal?ke:ee,()=>{var j;return(j=t.onSwitchDevice)==null?void 0:j.call(t,n.id)},h(Q[l]))):[],R=_(a("toggle-sidebar",t.showSidebar?"Hide session sidebar":"Show session sidebar","projects navigation panel",Re,t.onToggleSidebar,h("toggleSidebar")),t.hasSession&&a("toggle-stats",t.showStats?"Hide session analytics":"Show session analytics","stats tokens usage panel",$e,t.onToggleStats,h("toggleStats")),t.onToggleProjectFiles&&a("project-files",t.showProjectFiles?"Close project files":"Open project files","browse edit save workspace source code",Ee,t.onToggleProjectFiles,h("projectFiles")),t.hasFileChanges&&a("toggle-file-changes",t.showFileChanges?"Hide file changes":"Show file changes","diff edits review panel",Ie,t.onToggleFileChanges),t.supportsWorktrees&&t.canOpenTerminal&&a("toggle-worktrees",t.showWorktrees?"Hide worktrees":"Show worktrees","git branches panel",Fe,t.onToggleWorktrees)),A=_(t.onOpenProjectInEditor&&a("open-project-editor","Open project in editor","code cursor vscode zed workspace",pe,t.onOpenProjectInEditor),t.onRevealProject&&a("reveal-project","Reveal project in file manager","finder explorer folder directory",Ge,t.onRevealProject),t.onCopyResumeCommand&&a("copy-resume-command","Copy resume command","cli claude codex terminal clipboard continue session",ne,t.onCopyResumeCommand),t.onCopyProjectPath&&a("copy-project-path","Copy project path","workspace directory clipboard",ne,t.onCopyProjectPath),t.onOpenIntegratedTerminal&&a("integrated-terminal","New integrated terminal","embedded shell command line process panel",Be,t.onOpenIntegratedTerminal,h("newIntegratedTerminal")),t.canOpenTerminal&&a("terminal","Open in system terminal","external shell command line app",ze,t.onOpenTerminal,h("systemTerminal")),t.onTogglePreview&&a("preview","Toggle development preview","browser localhost dev server website",Ke,t.onTogglePreview,h("preview")),t.onOpenKeyboardShortcuts&&a("keyboard-shortcuts","Customize keyboard shortcuts","keybindings hotkeys settings",qe,t.onOpenKeyboardShortcuts),t.onOpenConfig&&a("config",t.showConfig?"Close agent configuration":"Open agent configuration","skills commands claude settings files",He,t.onOpenConfig),a("settings","Open Cogpit settings","preferences network",Me,t.onOpenSettings),a("theme","Change theme & chat width","appearance light dark oled width narrow wide",Le,t.onOpenTheme,h("themeSelector")),a("expand","Expand all groups","conversation details",te,t.onExpandAll,h("expandAll")),a("expand-payloads","Expand all tool payloads","raw input result diff conversation details",te,t.onExpandToolPayloads,h("expandToolPayloads")),a("collapse","Collapse all","conversation groups payloads details",De,t.onCollapseAll),t.onKillAll&&a("kill-all","Kill all agent processes","stop terminate halt everything runaway",Ae,t.onKillAll),t.onOpenDevices&&a("manage-devices","Manage devices…","remote machines hub hosts edit rename remove switch",Ue,()=>{var n;return(n=t.onOpenDevices)==null?void 0:n.call(t,"manage")}),t.onOpenDevices&&a("add-device","Add device…","remote machine hub host connect pair new",ee,()=>{var n;return(n=t.onOpenDevices)==null?void 0:n.call(t,"add")})),D=[{value:"Navigation",items:$},...o.length>0?[{value:"Recent sessions",items:o}]:[],...I.length>0?[{value:"Projects",items:I}]:[],...P.length>0?[{value:"Devices",items:P}]:[],{value:"View",items:R},{value:"Tools",items:A}],F=function(l){t.onOpenChange(!1),l.run()};i=me,x=t.open,k=t.onOpenChange,b="Command palette",v="Search for a Cogpit action to run.",w="max-w-xl",c=ue,C="Search commands",g=!0,e[16]===Symbol.for("react.memo_cache_sentinel")?(y=u.jsx(he,{"aria-label":"Search commands",autoFocus:!0,placeholder:"Search commands..."}),e[16]=y):y=e[16],e[17]!==t.loadingNavigation?(f=t.loadingNavigation&&u.jsxs("div",{className:"motion-enter flex items-center gap-2 px-3 py-2 text-xs text-muted-foreground",role:"status",children:[u.jsx(le,{className:"size-3.5"}),"Loading projects and sessions..."]}),e[17]=t.loadingNavigation,e[18]=f):f=e[18],s=ge,m="max-h-[min(26rem,60vh)]",e[19]===Symbol.for("react.memo_cache_sentinel")?(d=u.jsx(fe,{children:"No matching actions."}),e[19]=d):d=e[19],r=D.map(n=>u.jsx(ce,{heading:n.value,children:n.items.map(l=>{const j=l.icon;return u.jsxs(re,{value:l.value,onSelect:()=>F(l),children:[u.jsx(j,{"aria-hidden":"true"}),u.jsxs("span",{className:"min-w-0 flex-1",children:[u.jsx("span",{className:"block truncate",children:l.label}),l.description&&u.jsx("span",{className:"block truncate text-xs text-muted-foreground",children:l.description})]}),l.shortcut&&u.jsx(de,{children:l.shortcut})]},l.id)})},n.value)),e[0]=t,e[1]=s,e[2]=c,e[3]=i,e[4]=m,e[5]=d,e[6]=v,e[7]=w,e[8]=r,e[9]=C,e[10]=g,e[11]=y,e[12]=f,e[13]=x,e[14]=k,e[15]=b}else s=e[1],c=e[2],i=e[3],m=e[4],d=e[5],v=e[6],w=e[7],r=e[8],C=e[9],g=e[10],y=e[11],f=e[12],x=e[13],k=e[14],b=e[15];let T;e[20]!==s||e[21]!==m||e[22]!==d||e[23]!==r?(T=u.jsxs(s,{className:m,children:[d,r]}),e[20]=s,e[21]=m,e[22]=d,e[23]=r,e[24]=T):T=e[24];let O;e[25]!==c||e[26]!==T||e[27]!==C||e[28]!==g||e[29]!==y||e[30]!==f?(O=u.jsxs(c,{label:C,loop:g,children:[y,f,T]}),e[25]=c,e[26]=T,e[27]=C,e[28]=g,e[29]=y,e[30]=f,e[31]=O):O=e[31];let N;return e[32]!==i||e[33]!==v||e[34]!==w||e[35]!==O||e[36]!==x||e[37]!==k||e[38]!==b?(N=u.jsx(i,{open:x,onOpenChange:k,title:b,description:v,className:w,children:O}),e[32]=i,e[33]=v,e[34]=w,e[35]=O,e[36]=x,e[37]=k,e[38]=b,e[39]=N):N=e[39],N}async function ae(t,e){const s=await ye(t,{signal:e});if(!s.ok)throw new Error(`Request failed (${s.status})`);const c=await s.json();return Array.isArray(c)?c:[]}function Ye(t){var J;const e=oe.c(48);let s,c,i,m,d,v;e[0]!==t?({open:i,currentProjectDirName:s,projectCwd:d,onProcessStarted:c,launchTerminalRequest:v,...m}=t,e[0]=t,e[1]=s,e[2]=c,e[3]=i,e[4]=m,e[5]=d,e[6]=v):(s=e[1],c=e[2],i=e[3],m=e[4],d=e[5],v=e[6]);const w=v===void 0?0:v,r=ve();let C;e[7]===Symbol.for("react.memo_cache_sentinel")?(C=[],e[7]=C):C=e[7];const[g,y]=M.useState(C);let f;e[8]===Symbol.for("react.memo_cache_sentinel")?(f=[],e[8]=f):f=e[8];const[x,k]=M.useState(f),[b,T]=M.useState(!1),O=M.useRef(0);let N,$;e[9]!==i?(N=()=>{if(!i)return;const S=new AbortController;return T(!0),Promise.allSettled([ae("/api/projects",S.signal),ae("/api/active-sessions?limit=12&perProject=3",S.signal)]).then(H=>{const[V,X]=H;S.signal.aborted||(y(V.status==="fulfilled"?V.value:[]),k(X.status==="fulfilled"?X.value:[]),T(!1))}),()=>S.abort()},$=[i],e[9]=i,e[10]=N,e[11]=$):(N=e[10],$=e[11]),M.useEffect(N,$);let I;e:{if(d){I=d;break e}if(!s){I=null;break e}let S;e[12]!==s||e[13]!==g?(S=((J=g.find(H=>H.dirName===s))==null?void 0:J.path)??null,e[12]=s,e[13]=g,e[14]=S):S=e[14],I=S}const o=I;let E;e[15]!==c||e[16]!==r||e[17]!==o?(E=()=>{if(!o)return;const S=r.spawnTerminal({cwd:o}),H=o.replace(/\/+$/,"").split("/").at(-1)||"Terminal";c({id:S,name:H,type:"terminal",status:"running",source:o})},e[15]=c,e[16]=r,e[17]=o,e[18]=E):E=e[18];const P=E;let R,A;e[19]!==P||e[20]!==w||e[21]!==r.status||e[22]!==o?(R=()=>{w<=O.current||!o||r.status!=="connected"||(O.current=w,P())},A=[P,w,r.status,o],e[19]=P,e[20]=w,e[21]=r.status,e[22]=o,e[23]=R,e[24]=A):(R=e[23],A=e[24]),M.useEffect(R,A);let D;e[25]!==s||e[26]!==o?(D={path:o,dirName:s},e[25]=s,e[26]=o,e[27]=D):D=e[27];const F=D;let n;e[28]!==F?(n=()=>Ce(F),e[28]=F,e[29]=n):n=e[29];const l=n;let j;e[30]!==F?(j=()=>je(F),e[30]=F,e[31]=j):j=e[31];const B=j,q=!Y()&&W("hostFiles"),se=W("hostFiles")&&(!Y()||we());let K;e[32]!==o?(K=()=>{o&&Se(o)},e[32]=o,e[33]=K):K=e[33];const ie=K;let L;e[34]!==P||e[35]!==r.status||e[36]!==o?(L=o&&r.status==="connected"&&W("terminal")?P:void 0,e[34]=P,e[35]=r.status,e[36]=o,e[37]=L):L=e[37];const G=o&&se?l:void 0,p=o&&q?B:void 0,U=o?ie:void 0;let z;return e[38]!==b||e[39]!==i||e[40]!==m||e[41]!==g||e[42]!==x||e[43]!==L||e[44]!==G||e[45]!==p||e[46]!==U?(z=u.jsx(We,{...m,open:i,projects:g,recentSessions:x,loadingNavigation:b,onOpenIntegratedTerminal:L,onOpenProjectInEditor:G,onRevealProject:p,onCopyProjectPath:U}),e[38]=b,e[39]=i,e[40]=m,e[41]=g,e[42]=x,e[43]=L,e[44]=G,e[45]=p,e[46]=U,e[47]=z):z=e[47],z}export{Ye as CommandPaletteHost};
@@ -1 +1 @@
1
- import{c as G,j as t,r as o}from"./vendor-react-gGw_S5I_.js";import{T as P,a8 as je,a9 as W,aC as X,ac as be,ad as q,aG as se,B as z,w as A,a$ as ye,b0 as Ce,b1 as ke,b2 as ve,b3 as Ne,b4 as Se,b5 as V,b6 as we,b7 as Z,b8 as De,U as ee,Z as ae,b9 as Te,_ as le,$ as ie,a1 as re,a2 as oe,a3 as ce,a4 as de,a5 as ue,ah as Ee,E as Re,y as Ie,z as Oe,G as ze,H as Le,R as Ae,m as $e,I as te,n as Be,aa as Ge,q as Fe,ba as Me}from"./index-CNV6e3p0.js";import{af as Pe,B as Ue,b as _e,ab as Ve,ag as He,ah as Ke,ai as me,aj as xe,ak as Je,al as Qe,o as H,X as K,P as Ye,am as fe,an as We,T as Xe,a8 as qe,S as Ze}from"./vendor-ui-BmLOQ5Or.js";import{H as et}from"./HighlightedEditor-BPmH8BvC.js";import"./vendor-shiki-DOn6sF-i.js";import"./vendor-markdown-BE1gYnO9.js";const tt={agent:"bg-muted text-muted-foreground",skill:"bg-muted text-muted-foreground",command:"bg-muted text-muted-foreground",instructions:"bg-muted text-muted-foreground",settings:"bg-muted text-muted-foreground"},nt={agents:{subdir:"agents",fileType:"agent"},skills:{subdir:"skills",fileType:"skill"},commands:{subdir:"commands",fileType:"command"}},ne=["instructions","agents","skills","commands","settings"],st={instructions:{label:"Instructions",icon:He,color:"text-muted-foreground"},agents:{label:"Agents",icon:Ve,color:"text-muted-foreground"},skills:{label:"Skills",icon:_e,color:"text-muted-foreground"},commands:{label:"Commands",icon:Ue,color:"text-muted-foreground"},settings:{label:"Settings",icon:Pe,color:"text-muted-foreground"}};function J(l,e,i){const n=[];for(const s of l)s.type==="directory"&&s.children?n.push(...J(s.children,e,i)):s.type==="file"&&n.push({name:s.name,path:s.path,fileType:s.fileType||"unknown",description:s.description||"",scope:e,pluginName:i,readOnly:s.readOnly??e==="plugin",cli:s.cli,linkTarget:s.linkTarget});return n}function at(l){const e={instructions:[],agents:[],skills:[],commands:[],settings:[]};for(const i of l){const n=J(i.items,i.scope,i.pluginName);for(const s of n)switch(s.fileType){case"instructions":e.instructions.push(s);break;case"agent":e.agents.push(s);break;case"skill":e.skills.push(s);break;case"command":e.commands.push(s);break;case"settings":default:e.settings.push(s)}}return e}function he(l){const e=G.c(5),{scope:i,pluginName:n}=l;if(i==="plugin"&&n){let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r=t.jsx(Ke,{"data-icon":"inline-start",className:"size-3"}),e[0]=r):r=e[0];let u;return e[1]!==n?(u=t.jsxs("span",{className:"flex shrink-0 items-center gap-1 text-xs text-muted-foreground",children:[r,n]}),e[1]=n,e[2]=u):u=e[2],u}if(i==="project"){let r;return e[3]===Symbol.for("react.memo_cache_sentinel")?(r=t.jsxs("span",{className:"flex shrink-0 items-center gap-1 text-xs text-muted-foreground",children:[t.jsx(me,{"data-icon":"inline-start",className:"size-3"}),"project"]}),e[3]=r):r=e[3],r}let s;return e[4]===Symbol.for("react.memo_cache_sentinel")?(s=t.jsxs("span",{className:"flex shrink-0 items-center gap-1 text-xs text-muted-foreground",children:[t.jsx(xe,{"data-icon":"inline-start",className:"size-3"}),"global"]}),e[4]=s):s=e[4],s}const lt={claude:{letter:"C",label:"Loaded by Claude Code"},codex:{letter:"X",label:"Loaded by Codex CLI"}};function pe(l){const e=G.c(10),{cli:i,variant:n}=l,s=n===void 0?"compact":n;if(!i)return null;if(i.length===0){let m;e[0]===Symbol.for("react.memo_cache_sentinel")?(m=t.jsx(Je,{"data-icon":"inline-start",className:"size-3"}),e[0]=m):m=e[0];const c=s==="full"&&"unlinked";let d;return e[1]!==c?(d=t.jsxs("span",{className:"flex shrink-0 items-center gap-1 text-xs text-warning",title:"Present in the shared source directory but not linked into Claude or Codex",children:[m,c]}),e[1]=c,e[2]=d):d=e[2],d}let r;if(e[3]!==i||e[4]!==s){let m;e[6]!==s?(m=c=>{const d=lt[c];return t.jsx("span",{title:d.label,className:s==="full"?"flex h-5 items-center justify-center rounded border bg-muted px-1.5 text-xs font-medium text-muted-foreground":"flex size-5 items-center justify-center rounded border bg-muted text-xs font-medium text-muted-foreground",children:s==="full"?c:d.letter},c)},e[6]=s,e[7]=m):m=e[7],r=i.map(m),e[3]=i,e[4]=s,e[5]=r}else r=e[5];let u;return e[8]!==r?(u=t.jsx("span",{className:"flex items-center gap-0.5 shrink-0",children:r}),e[8]=r,e[9]=u):u=e[9],u}function ge(l){const e=G.c(10),{linkTarget:i,variant:n,className:s}=l,r=n===void 0?"compact":n;if(!i)return null;let u;e[0]!==s?(u=P("flex min-w-0 shrink-0 items-center gap-1 text-info",s),e[0]=s,e[1]=u):u=e[1];const m=`Symlink → ${i}`;let c;e[2]===Symbol.for("react.memo_cache_sentinel")?(c=t.jsx(Qe,{"data-icon":"inline-start",className:"size-3 shrink-0"}),e[2]=c):c=e[2];let d;e[3]!==i||e[4]!==r?(d=r==="full"&&t.jsxs("span",{className:"truncate font-mono text-xs",children:["→ ",i]}),e[3]=i,e[4]=r,e[5]=d):d=e[5];let g;return e[6]!==u||e[7]!==m||e[8]!==d?(g=t.jsxs("span",{className:u,title:m,children:[c,d]}),e[6]=u,e[7]=m,e[8]=d,e[9]=g):g=e[9],g}function it({globalDir:l,projectDir:e,fileType:i,onCreated:n,onCancel:s}){const[r,u]=o.useState(""),[m,c]=o.useState(e?"project":"global"),[d,g]=o.useState(!1),N=o.useRef(null),k=o.useId();o.useEffect(()=>{var h;(h=N.current)==null||h.focus()},[]);const S=m==="project"&&e?e:l,f=!!l&&!!e;async function w(){if(!(!r.trim()||!S)){g(!0);try{const h=await A("/api/config-browser/create",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({dir:S,fileType:i,name:r.trim()})});if(h.ok){const p=await h.json();n(p.path,i,m)}}finally{g(!1)}}}return t.jsxs(je,{className:"gap-3 px-3 py-2",children:[f&&t.jsxs(W,{children:[t.jsx(X,{children:"Scope"}),t.jsxs(be,{"aria-label":"File scope",value:[m],onValueChange:h=>{const p=h[0];(p==="global"||p==="project")&&c(p)},variant:"outline",size:"sm",spacing:0,className:"w-full",children:[t.jsxs(q,{value:"global",className:"flex-1",children:[t.jsx(xe,{"data-icon":"inline-start"}),"Global"]}),t.jsxs(q,{value:"project",className:"flex-1",children:[t.jsx(me,{"data-icon":"inline-start"}),"Project"]})]})]}),t.jsxs(W,{children:[t.jsxs(X,{htmlFor:k,children:[i.charAt(0).toUpperCase()+i.slice(1)," name"]}),t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsx(se,{id:k,ref:N,type:"text",value:r,onChange:h=>u(h.target.value),onKeyDown:h=>{h.key==="Enter"&&w(),h.key==="Escape"&&s()},placeholder:`${i} name...`,className:"h-7 min-w-0 flex-1 text-xs",disabled:d}),t.jsx(z,{variant:"ghost",size:"icon-xs","aria-label":`Create ${i}`,onClick:()=>void w(),disabled:d||!r.trim()||!S,children:t.jsx(H,{"data-icon":"inline-start"})}),t.jsx(z,{variant:"ghost",size:"icon-xs","aria-label":"Cancel create",onClick:s,children:t.jsx(K,{"data-icon":"inline-start"})})]})]})]})}function rt(l){const e=G.c(50),{category:i,items:n,selectedPath:s,onSelect:r,onNewFile:u,onDeleteItem:m,onRenameItem:c,renamingPath:d,renameValue:g,onRenameValueChange:N,onRenameSubmit:k,onRenameCancel:S,creatingInCategory:f,onCreated:w,onCancelCreate:h}=l,p=st[i],j=p.icon;if(n.length===0&&!u)return null;let D;e[0]!==p.color?(D=P("size-3.5",p.color),e[0]=p.color,e[1]=D):D=e[1];let T;e[2]!==j||e[3]!==D?(T=t.jsx(j,{"data-icon":"inline-start",className:D}),e[2]=j,e[3]=D,e[4]=T):T=e[4];let y;e[5]!==p.label?(y=t.jsx("span",{className:"flex-1 text-xs font-medium text-muted-foreground",children:p.label}),e[5]=p.label,e[6]=y):y=e[6];let R;e[7]!==n.length?(R=t.jsx("span",{className:"text-xs tabular-nums text-muted-foreground",children:n.length}),e[7]=n.length,e[8]=R):R=e[8];let C;e[9]!==i||e[10]!==u?(C=u&&t.jsxs(ye,{children:[t.jsx(Ce,{render:t.jsx(z,{variant:"ghost",size:"icon-xs",className:"opacity-0 transition-opacity group-hover:opacity-100","aria-label":`New ${i.slice(0,-1)}`,onClick:u}),children:t.jsx(Ye,{"data-icon":"inline-start"})}),t.jsxs(ke,{children:["New ",i.slice(0,-1)]})]}),e[9]=i,e[10]=u,e[11]=C):C=e[11];let v;e[12]!==T||e[13]!==y||e[14]!==R||e[15]!==C?(v=t.jsxs("div",{className:"group flex h-8 items-center gap-1.5 px-3",children:[T,y,R,C]}),e[12]=T,e[13]=y,e[14]=R,e[15]=C,e[16]=v):v=e[16];let E;if(e[17]!==n||e[18]!==m||e[19]!==S||e[20]!==c||e[21]!==k||e[22]!==N||e[23]!==r||e[24]!==g||e[25]!==d||e[26]!==s){let B;e[28]!==m||e[29]!==S||e[30]!==c||e[31]!==k||e[32]!==N||e[33]!==r||e[34]!==g||e[35]!==d||e[36]!==s?(B=b=>{const U=s===b.path;if(d===b.path)return t.jsxs("div",{className:"flex items-center gap-1 border-l-2 border-foreground/30 bg-accent px-3 py-1",children:[t.jsx(se,{value:g,onChange:L=>N(L.target.value),onKeyDown:L=>{L.key==="Enter"&&k(),L.key==="Escape"&&S()},autoFocus:!0,className:"h-7 min-w-0 flex-1 text-xs"}),t.jsx(z,{variant:"ghost",size:"icon-xs","aria-label":"Save name",onClick:k,disabled:!g.trim(),children:t.jsx(H,{"data-icon":"inline-start"})}),t.jsx(z,{variant:"ghost",size:"icon-xs","aria-label":"Cancel rename",onClick:S,children:t.jsx(K,{"data-icon":"inline-start"})})]},b.path);const F=t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"truncate text-sm",children:b.name}),t.jsx(ge,{linkTarget:b.linkTarget}),b.readOnly&&t.jsx(fe,{className:"size-2.5 shrink-0 text-muted-foreground/40"})]}),b.description&&t.jsx("p",{className:"mt-0.5 truncate text-xs text-muted-foreground",children:b.description})]}),t.jsx(pe,{cli:b.cli}),t.jsx(he,{scope:b.scope,pluginName:b.pluginName})]}),M=P("flex w-full items-center gap-2 border-l-2 px-3 py-2 text-left text-sm transition-colors",U?"border-foreground/30 bg-accent text-accent-foreground":"border-transparent text-muted-foreground hover:bg-accent hover:text-foreground");return!m||!c?t.jsx("button",{type:"button",className:M,onClick:()=>r(b),children:F},b.path):t.jsxs(ve,{children:[t.jsx(Ne,{render:t.jsx("button",{type:"button",className:M,onClick:()=>r(b)}),children:F}),t.jsx(Se,{className:"min-w-36",children:b.readOnly?t.jsx(V,{children:t.jsx(we,{children:"Read-only file"})}):t.jsxs(t.Fragment,{children:[t.jsx(V,{children:t.jsx(Z,{onClick:()=>c(b),children:"Rename"})}),t.jsx(De,{}),t.jsx(V,{children:t.jsx(Z,{variant:"destructive",onClick:()=>m(b),children:"Delete"})})]})})]},b.path)},e[28]=m,e[29]=S,e[30]=c,e[31]=k,e[32]=N,e[33]=r,e[34]=g,e[35]=d,e[36]=s,e[37]=B):B=e[37],E=n.map(B),e[17]=n,e[18]=m,e[19]=S,e[20]=c,e[21]=k,e[22]=N,e[23]=r,e[24]=g,e[25]=d,e[26]=s,e[27]=E}else E=e[27];let I;e[38]!==f||e[39]!==n.length?(I=n.length===0&&!f&&t.jsx("p",{className:"px-3 py-1 text-xs text-muted-foreground",children:"None configured"}),e[38]=f,e[39]=n.length,e[40]=I):I=e[40];let O;e[41]!==f||e[42]!==h||e[43]!==w?(O=f&&t.jsx(it,{globalDir:f.globalDir,projectDir:f.projectDir,fileType:f.fileType,onCreated:w,onCancel:h}),e[41]=f,e[42]=h,e[43]=w,e[44]=O):O=e[44];let $;return e[45]!==v||e[46]!==E||e[47]!==I||e[48]!==O?($=t.jsxs("section",{children:[v,E,I,O]}),e[45]=v,e[46]=E,e[47]=I,e[48]=O,e[49]=$):$=e[49],$}function ot({file:l,onDeleted:e,readOnly:i=!1}){const[n,s]=o.useState(null),[r,u]=o.useState(null),[m,c]=o.useState(!0),[d,g]=o.useState(!1),[N,k]=o.useState(!1),[S,f]=o.useState(!1),[w,h]=o.useState(!1),p=n!==null&&n!==r,j=i||l.readOnly;o.useEffect(()=>{c(!0),s(null),u(null),k(!1),f(!1),A(`/api/config-browser/file?path=${encodeURIComponent(l.path)}`).then(C=>C.json()).then(C=>{s(C.content??""),u(C.content??"")}).catch(()=>{s(""),u("")}).finally(()=>c(!1))},[l.path]);const D=o.useCallback(async()=>{if(!(!p||j)){g(!0);try{(await A("/api/config-browser/file",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:l.path,content:n})})).ok&&(u(n),k(!0),setTimeout(()=>k(!1),2e3))}finally{g(!1)}}},[n,l.path,p,j]),T=o.useCallback(()=>{s(r)},[r]),y=o.useCallback(async()=>{if(!j){h(!0);try{(await A(`/api/config-browser/file?path=${encodeURIComponent(l.path)}`,{method:"DELETE"})).ok&&(f(!1),e())}catch{}finally{h(!1)}}},[l.path,j,e]);o.useEffect(()=>{function C(v){!j&&(v.metaKey||v.ctrlKey)&&v.key==="s"&&(v.preventDefault(),D())}return window.addEventListener("keydown",C),()=>window.removeEventListener("keydown",C)},[D,j]);function R(){return N?"Saved!":d?"Saving...":"Save"}return t.jsxs("div",{className:"flex flex-1 flex-col min-h-0 min-w-0",children:[t.jsxs("div",{className:"flex min-h-11 shrink-0 items-center gap-2 border-b bg-card px-4 py-2",children:[t.jsx(ee,{variant:"outline",className:P("h-5 text-xs",tt[l.fileType]||"bg-muted text-muted-foreground"),children:l.fileType}),t.jsx(he,{scope:l.scope,pluginName:l.pluginName}),t.jsx(pe,{cli:l.cli,variant:"full"}),j&&t.jsxs(ee,{variant:"outline",className:"h-5 bg-muted text-xs text-muted-foreground",children:[t.jsx(fe,{"data-icon":"inline-start",className:"size-3"})," read-only"]}),p&&t.jsx("span",{className:"size-2 shrink-0 rounded-full bg-warning",title:"Unsaved changes"}),t.jsxs("div",{className:"flex items-center gap-2 ml-auto min-w-0",children:[t.jsx(ge,{linkTarget:l.linkTarget,variant:"full"}),t.jsx("span",{className:"truncate font-mono text-xs text-muted-foreground",title:l.path,children:l.path})]})]}),m?t.jsx("div",{className:"flex-1 flex items-center justify-center text-muted-foreground text-sm",children:"Loading..."}):t.jsxs("div",{className:"flex-1 min-h-0 overflow-hidden flex flex-col",children:[t.jsx(et,{value:n??"",onChange:s,readOnly:j,filePath:l.path}),!j&&t.jsxs("div",{className:"flex shrink-0 items-center gap-2 border-t bg-card px-4 py-2",children:[t.jsxs(z,{size:"xs",onClick:D,disabled:!p||d,children:[t.jsx(H,{"data-icon":"inline-start"}),R()]}),t.jsxs(z,{variant:"outline",size:"xs",onClick:T,disabled:!p,children:[t.jsx(We,{"data-icon":"inline-start"}),"Discard"]}),t.jsx("div",{className:"flex-1"}),t.jsxs(ae,{open:S,onOpenChange:f,children:[t.jsxs(Te,{render:t.jsx(z,{variant:"outline",size:"xs"}),children:[t.jsx(Xe,{"data-icon":"inline-start"}),"Delete"]}),t.jsxs(le,{size:"sm",children:[t.jsxs(ie,{children:[t.jsx(re,{children:"Delete configuration file?"}),t.jsxs(oe,{children:['Delete "',l.name,'" permanently? This action cannot be undone.']})]}),t.jsxs(ce,{children:[t.jsx(de,{size:"sm",disabled:w,children:"Cancel"}),t.jsxs(ue,{variant:"destructive",size:"sm",disabled:w,onClick:()=>void y(),children:[w&&t.jsx(Ee,{"data-icon":"inline-start"}),w?"Deleting...":"Delete file"]})]})]})]})]})]})]})}function ct(){const l=G.c(1);let e;return l[0]===Symbol.for("react.memo_cache_sentinel")?(e=t.jsx(Re,{className:"border-0",children:t.jsxs(Ie,{children:[t.jsx(Oe,{variant:"icon",children:t.jsx(qe,{})}),t.jsx(ze,{children:"Select a configuration file"}),t.jsx(Le,{children:"Browse instructions, agents, skills, commands, and settings from the sidebar."})]})}),l[0]=e):e=l[0],e}function dt(l){return l.cli?l.cli.length>0?l.cli.join(" "):"unlinked":""}function ut(l,e){if(!e)return l;const i=e.toLowerCase();return l.filter(n=>[n.name,n.description,n.path,n.linkTarget??"",dt(n)].some(r=>r.toLowerCase().includes(i)))}const jt=o.memo(function({projectPath:e,initialFilePath:i}){var L,Y;const n=Ae("configWrite"),[s,r]=o.useState([]),[u,m]=o.useState(!0),[c,d]=o.useState(null),[g,N]=o.useState(null),[k,S]=o.useState(""),[f,w]=o.useState(null),[h,p]=o.useState(""),[j,D]=o.useState(null),T=o.useRef(!1),y=o.useCallback(async()=>{if(!n){r([]),d(null),m(!1);return}m(!0);try{const a=e?`/api/config-browser/tree?cwd=${encodeURIComponent(e)}`:"/api/config-browser/tree",x=await A(a);if(x.ok){const _=await x.json();r(_.sections||[])}}finally{m(!1)}},[n,e]);o.useEffect(()=>{y()},[y]),o.useEffect(()=>{if(!i||u||T.current)return;const a=s.flatMap(x=>J(x.items,x.scope,x.pluginName)).find(x=>x.path===i);a&&(d(a),T.current=!0)},[i,u,s]);const R=at(s),C=Object.fromEntries(ne.map(a=>[a,ut(R[a],k)])),v=(L=s.find(a=>a.scope==="global"))==null?void 0:L.baseDir,E=(Y=s.find(a=>a.scope==="project"))==null?void 0:Y.baseDir,I=o.useCallback(a=>{d(a),N(null)},[]),O=o.useCallback((a,x,_)=>{N(null),y(),d({path:a,name:a.split("/").pop()||"",fileType:x,readOnly:!1,scope:_,description:""})},[y]),$=o.useCallback(()=>{d(null),y()},[y]),B=o.useCallback(a=>{if(!n||!v&&!E)return;const x=nt[a];x&&N({category:a,globalDir:v?`${v}/${x.subdir}`:null,projectDir:E?`${E}/${x.subdir}`:null,fileType:x.fileType})},[n,v,E]),b=o.useCallback(a=>{!n||a.readOnly||D(a)},[n]),U=o.useCallback(async()=>{if(!n||!j||j.readOnly)return;const a=j;D(null);try{(await A(`/api/config-browser/file?path=${encodeURIComponent(a.path)}`,{method:"DELETE"})).ok&&((c==null?void 0:c.path)===a.path&&d(null),y())}catch{}},[n,y,j,c]),Q=o.useCallback(a=>{if(!n||a.readOnly)return;const x=a.name==="SKILL.md"?a.path.split("/").slice(-2,-1)[0]||a.name:a.name.replace(/\.[^.]+$/,"");w(a),p(x)},[n]),F=o.useCallback(async()=>{if(!(!n||!f||!h.trim()))try{const a=await A("/api/config-browser/rename",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({oldPath:f.path,newName:h.trim()})});if(a.ok){const x=await a.json();w(null),p(""),await y(),x.newPath&&d({...f,path:x.newPath,name:x.newPath.split("/").pop()||f.name})}}catch{}},[n,f,h,y]),M=o.useCallback(()=>{w(null),p("")},[]);return n?t.jsxs("div",{className:"flex flex-1 min-h-0 min-w-0",children:[t.jsxs("div",{className:"flex min-h-0 w-80 shrink-0 flex-col border-r bg-sidebar",children:[t.jsxs("div",{className:"flex h-11 items-center gap-2 border-b px-3",children:[t.jsx("span",{className:"text-sm font-medium text-foreground",children:"Configuration"}),e&&t.jsx("span",{className:"ml-auto truncate text-xs text-muted-foreground",title:e,children:e.split("/").pop()})]}),t.jsx("div",{className:"border-b p-2",children:t.jsxs($e,{children:[t.jsx(te,{children:t.jsx(Ze,{"data-icon":"inline-start"})}),t.jsx(Be,{value:k,onChange:a=>S(a.target.value),placeholder:"Search configuration"}),k&&t.jsx(te,{align:"inline-end",children:t.jsx(Ge,{size:"icon-xs","aria-label":"Clear search",onClick:()=>S(""),children:t.jsx(K,{"data-icon":"inline-start"})})})]})}),t.jsx(Fe,{className:"flex-1",children:t.jsx("div",{className:"flex flex-col gap-1 py-2",children:u?t.jsx("div",{className:"flex flex-col gap-2 px-3 py-2","aria-label":"Loading configuration",children:Array.from({length:6},(a,x)=>t.jsx(Me,{className:"h-8 w-full"},x))}):ne.map(a=>{const x=a==="agents"||a==="skills"||a==="commands";return t.jsx(rt,{category:a,items:C[a],selectedPath:(c==null?void 0:c.path)??null,onSelect:I,onNewFile:n&&x?()=>B(a):void 0,onDeleteItem:n?b:void 0,onRenameItem:n?Q:void 0,renamingPath:(f==null?void 0:f.path)??null,renameValue:h,onRenameValueChange:p,onRenameSubmit:F,onRenameCancel:M,creatingInCategory:n&&(g==null?void 0:g.category)===a?g:null,onCreated:O,onCancelCreate:()=>N(null)},a)})})})]}),c?t.jsx(ot,{file:c,onDeleted:$,readOnly:!n}):t.jsx(ct,{}),t.jsx(ae,{open:j!==null,onOpenChange:a=>{a||D(null)},children:t.jsxs(le,{size:"sm",children:[t.jsxs(ie,{children:[t.jsx(re,{children:"Delete configuration file?"}),t.jsxs(oe,{children:['Delete "',j==null?void 0:j.name,'" permanently? This action cannot be undone.']})]}),t.jsxs(ce,{children:[t.jsx(de,{size:"sm",children:"Cancel"}),t.jsx(ue,{variant:"destructive",size:"sm",onClick:()=>void U(),children:"Delete file"})]})]})})]}):t.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:"Server configuration is available to administrators only."})});export{jt as ConfigBrowser};
1
+ import{c as G,j as t,r as o}from"./vendor-react-gGw_S5I_.js";import{T as P,a8 as je,a9 as W,aC as X,ac as be,ad as q,aG as se,B as z,w as A,a$ as ye,b0 as Ce,b1 as ke,b2 as ve,b3 as Ne,b4 as Se,b5 as V,b6 as we,b7 as Z,b8 as De,U as ee,Z as ae,b9 as Te,_ as le,$ as ie,a1 as re,a2 as oe,a3 as ce,a4 as de,a5 as ue,ah as Ee,E as Re,y as Ie,z as Oe,G as ze,H as Le,R as Ae,m as $e,I as te,n as Be,aa as Ge,q as Fe,ba as Me}from"./index-C3E35E2A.js";import{af as Pe,B as Ue,b as _e,ab as Ve,ag as He,ah as Ke,ai as me,aj as xe,ak as Je,al as Qe,o as H,X as K,P as Ye,am as fe,an as We,T as Xe,a8 as qe,S as Ze}from"./vendor-ui-BmLOQ5Or.js";import{H as et}from"./HighlightedEditor-D4DdiaD3.js";import"./vendor-shiki-DOn6sF-i.js";import"./vendor-markdown-BE1gYnO9.js";const tt={agent:"bg-muted text-muted-foreground",skill:"bg-muted text-muted-foreground",command:"bg-muted text-muted-foreground",instructions:"bg-muted text-muted-foreground",settings:"bg-muted text-muted-foreground"},nt={agents:{subdir:"agents",fileType:"agent"},skills:{subdir:"skills",fileType:"skill"},commands:{subdir:"commands",fileType:"command"}},ne=["instructions","agents","skills","commands","settings"],st={instructions:{label:"Instructions",icon:He,color:"text-muted-foreground"},agents:{label:"Agents",icon:Ve,color:"text-muted-foreground"},skills:{label:"Skills",icon:_e,color:"text-muted-foreground"},commands:{label:"Commands",icon:Ue,color:"text-muted-foreground"},settings:{label:"Settings",icon:Pe,color:"text-muted-foreground"}};function J(l,e,i){const n=[];for(const s of l)s.type==="directory"&&s.children?n.push(...J(s.children,e,i)):s.type==="file"&&n.push({name:s.name,path:s.path,fileType:s.fileType||"unknown",description:s.description||"",scope:e,pluginName:i,readOnly:s.readOnly??e==="plugin",cli:s.cli,linkTarget:s.linkTarget});return n}function at(l){const e={instructions:[],agents:[],skills:[],commands:[],settings:[]};for(const i of l){const n=J(i.items,i.scope,i.pluginName);for(const s of n)switch(s.fileType){case"instructions":e.instructions.push(s);break;case"agent":e.agents.push(s);break;case"skill":e.skills.push(s);break;case"command":e.commands.push(s);break;case"settings":default:e.settings.push(s)}}return e}function he(l){const e=G.c(5),{scope:i,pluginName:n}=l;if(i==="plugin"&&n){let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r=t.jsx(Ke,{"data-icon":"inline-start",className:"size-3"}),e[0]=r):r=e[0];let u;return e[1]!==n?(u=t.jsxs("span",{className:"flex shrink-0 items-center gap-1 text-xs text-muted-foreground",children:[r,n]}),e[1]=n,e[2]=u):u=e[2],u}if(i==="project"){let r;return e[3]===Symbol.for("react.memo_cache_sentinel")?(r=t.jsxs("span",{className:"flex shrink-0 items-center gap-1 text-xs text-muted-foreground",children:[t.jsx(me,{"data-icon":"inline-start",className:"size-3"}),"project"]}),e[3]=r):r=e[3],r}let s;return e[4]===Symbol.for("react.memo_cache_sentinel")?(s=t.jsxs("span",{className:"flex shrink-0 items-center gap-1 text-xs text-muted-foreground",children:[t.jsx(xe,{"data-icon":"inline-start",className:"size-3"}),"global"]}),e[4]=s):s=e[4],s}const lt={claude:{letter:"C",label:"Loaded by Claude Code"},codex:{letter:"X",label:"Loaded by Codex CLI"}};function pe(l){const e=G.c(10),{cli:i,variant:n}=l,s=n===void 0?"compact":n;if(!i)return null;if(i.length===0){let m;e[0]===Symbol.for("react.memo_cache_sentinel")?(m=t.jsx(Je,{"data-icon":"inline-start",className:"size-3"}),e[0]=m):m=e[0];const c=s==="full"&&"unlinked";let d;return e[1]!==c?(d=t.jsxs("span",{className:"flex shrink-0 items-center gap-1 text-xs text-warning",title:"Present in the shared source directory but not linked into Claude or Codex",children:[m,c]}),e[1]=c,e[2]=d):d=e[2],d}let r;if(e[3]!==i||e[4]!==s){let m;e[6]!==s?(m=c=>{const d=lt[c];return t.jsx("span",{title:d.label,className:s==="full"?"flex h-5 items-center justify-center rounded border bg-muted px-1.5 text-xs font-medium text-muted-foreground":"flex size-5 items-center justify-center rounded border bg-muted text-xs font-medium text-muted-foreground",children:s==="full"?c:d.letter},c)},e[6]=s,e[7]=m):m=e[7],r=i.map(m),e[3]=i,e[4]=s,e[5]=r}else r=e[5];let u;return e[8]!==r?(u=t.jsx("span",{className:"flex items-center gap-0.5 shrink-0",children:r}),e[8]=r,e[9]=u):u=e[9],u}function ge(l){const e=G.c(10),{linkTarget:i,variant:n,className:s}=l,r=n===void 0?"compact":n;if(!i)return null;let u;e[0]!==s?(u=P("flex min-w-0 shrink-0 items-center gap-1 text-info",s),e[0]=s,e[1]=u):u=e[1];const m=`Symlink → ${i}`;let c;e[2]===Symbol.for("react.memo_cache_sentinel")?(c=t.jsx(Qe,{"data-icon":"inline-start",className:"size-3 shrink-0"}),e[2]=c):c=e[2];let d;e[3]!==i||e[4]!==r?(d=r==="full"&&t.jsxs("span",{className:"truncate font-mono text-xs",children:["→ ",i]}),e[3]=i,e[4]=r,e[5]=d):d=e[5];let g;return e[6]!==u||e[7]!==m||e[8]!==d?(g=t.jsxs("span",{className:u,title:m,children:[c,d]}),e[6]=u,e[7]=m,e[8]=d,e[9]=g):g=e[9],g}function it({globalDir:l,projectDir:e,fileType:i,onCreated:n,onCancel:s}){const[r,u]=o.useState(""),[m,c]=o.useState(e?"project":"global"),[d,g]=o.useState(!1),N=o.useRef(null),k=o.useId();o.useEffect(()=>{var h;(h=N.current)==null||h.focus()},[]);const S=m==="project"&&e?e:l,f=!!l&&!!e;async function w(){if(!(!r.trim()||!S)){g(!0);try{const h=await A("/api/config-browser/create",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({dir:S,fileType:i,name:r.trim()})});if(h.ok){const p=await h.json();n(p.path,i,m)}}finally{g(!1)}}}return t.jsxs(je,{className:"gap-3 px-3 py-2",children:[f&&t.jsxs(W,{children:[t.jsx(X,{children:"Scope"}),t.jsxs(be,{"aria-label":"File scope",value:[m],onValueChange:h=>{const p=h[0];(p==="global"||p==="project")&&c(p)},variant:"outline",size:"sm",spacing:0,className:"w-full",children:[t.jsxs(q,{value:"global",className:"flex-1",children:[t.jsx(xe,{"data-icon":"inline-start"}),"Global"]}),t.jsxs(q,{value:"project",className:"flex-1",children:[t.jsx(me,{"data-icon":"inline-start"}),"Project"]})]})]}),t.jsxs(W,{children:[t.jsxs(X,{htmlFor:k,children:[i.charAt(0).toUpperCase()+i.slice(1)," name"]}),t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsx(se,{id:k,ref:N,type:"text",value:r,onChange:h=>u(h.target.value),onKeyDown:h=>{h.key==="Enter"&&w(),h.key==="Escape"&&s()},placeholder:`${i} name...`,className:"h-7 min-w-0 flex-1 text-xs",disabled:d}),t.jsx(z,{variant:"ghost",size:"icon-xs","aria-label":`Create ${i}`,onClick:()=>void w(),disabled:d||!r.trim()||!S,children:t.jsx(H,{"data-icon":"inline-start"})}),t.jsx(z,{variant:"ghost",size:"icon-xs","aria-label":"Cancel create",onClick:s,children:t.jsx(K,{"data-icon":"inline-start"})})]})]})]})}function rt(l){const e=G.c(50),{category:i,items:n,selectedPath:s,onSelect:r,onNewFile:u,onDeleteItem:m,onRenameItem:c,renamingPath:d,renameValue:g,onRenameValueChange:N,onRenameSubmit:k,onRenameCancel:S,creatingInCategory:f,onCreated:w,onCancelCreate:h}=l,p=st[i],j=p.icon;if(n.length===0&&!u)return null;let D;e[0]!==p.color?(D=P("size-3.5",p.color),e[0]=p.color,e[1]=D):D=e[1];let T;e[2]!==j||e[3]!==D?(T=t.jsx(j,{"data-icon":"inline-start",className:D}),e[2]=j,e[3]=D,e[4]=T):T=e[4];let y;e[5]!==p.label?(y=t.jsx("span",{className:"flex-1 text-xs font-medium text-muted-foreground",children:p.label}),e[5]=p.label,e[6]=y):y=e[6];let R;e[7]!==n.length?(R=t.jsx("span",{className:"text-xs tabular-nums text-muted-foreground",children:n.length}),e[7]=n.length,e[8]=R):R=e[8];let C;e[9]!==i||e[10]!==u?(C=u&&t.jsxs(ye,{children:[t.jsx(Ce,{render:t.jsx(z,{variant:"ghost",size:"icon-xs",className:"opacity-0 transition-opacity group-hover:opacity-100","aria-label":`New ${i.slice(0,-1)}`,onClick:u}),children:t.jsx(Ye,{"data-icon":"inline-start"})}),t.jsxs(ke,{children:["New ",i.slice(0,-1)]})]}),e[9]=i,e[10]=u,e[11]=C):C=e[11];let v;e[12]!==T||e[13]!==y||e[14]!==R||e[15]!==C?(v=t.jsxs("div",{className:"group flex h-8 items-center gap-1.5 px-3",children:[T,y,R,C]}),e[12]=T,e[13]=y,e[14]=R,e[15]=C,e[16]=v):v=e[16];let E;if(e[17]!==n||e[18]!==m||e[19]!==S||e[20]!==c||e[21]!==k||e[22]!==N||e[23]!==r||e[24]!==g||e[25]!==d||e[26]!==s){let B;e[28]!==m||e[29]!==S||e[30]!==c||e[31]!==k||e[32]!==N||e[33]!==r||e[34]!==g||e[35]!==d||e[36]!==s?(B=b=>{const U=s===b.path;if(d===b.path)return t.jsxs("div",{className:"flex items-center gap-1 border-l-2 border-foreground/30 bg-accent px-3 py-1",children:[t.jsx(se,{value:g,onChange:L=>N(L.target.value),onKeyDown:L=>{L.key==="Enter"&&k(),L.key==="Escape"&&S()},autoFocus:!0,className:"h-7 min-w-0 flex-1 text-xs"}),t.jsx(z,{variant:"ghost",size:"icon-xs","aria-label":"Save name",onClick:k,disabled:!g.trim(),children:t.jsx(H,{"data-icon":"inline-start"})}),t.jsx(z,{variant:"ghost",size:"icon-xs","aria-label":"Cancel rename",onClick:S,children:t.jsx(K,{"data-icon":"inline-start"})})]},b.path);const F=t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"truncate text-sm",children:b.name}),t.jsx(ge,{linkTarget:b.linkTarget}),b.readOnly&&t.jsx(fe,{className:"size-2.5 shrink-0 text-muted-foreground/40"})]}),b.description&&t.jsx("p",{className:"mt-0.5 truncate text-xs text-muted-foreground",children:b.description})]}),t.jsx(pe,{cli:b.cli}),t.jsx(he,{scope:b.scope,pluginName:b.pluginName})]}),M=P("flex w-full items-center gap-2 border-l-2 px-3 py-2 text-left text-sm transition-colors",U?"border-foreground/30 bg-accent text-accent-foreground":"border-transparent text-muted-foreground hover:bg-accent hover:text-foreground");return!m||!c?t.jsx("button",{type:"button",className:M,onClick:()=>r(b),children:F},b.path):t.jsxs(ve,{children:[t.jsx(Ne,{render:t.jsx("button",{type:"button",className:M,onClick:()=>r(b)}),children:F}),t.jsx(Se,{className:"min-w-36",children:b.readOnly?t.jsx(V,{children:t.jsx(we,{children:"Read-only file"})}):t.jsxs(t.Fragment,{children:[t.jsx(V,{children:t.jsx(Z,{onClick:()=>c(b),children:"Rename"})}),t.jsx(De,{}),t.jsx(V,{children:t.jsx(Z,{variant:"destructive",onClick:()=>m(b),children:"Delete"})})]})})]},b.path)},e[28]=m,e[29]=S,e[30]=c,e[31]=k,e[32]=N,e[33]=r,e[34]=g,e[35]=d,e[36]=s,e[37]=B):B=e[37],E=n.map(B),e[17]=n,e[18]=m,e[19]=S,e[20]=c,e[21]=k,e[22]=N,e[23]=r,e[24]=g,e[25]=d,e[26]=s,e[27]=E}else E=e[27];let I;e[38]!==f||e[39]!==n.length?(I=n.length===0&&!f&&t.jsx("p",{className:"px-3 py-1 text-xs text-muted-foreground",children:"None configured"}),e[38]=f,e[39]=n.length,e[40]=I):I=e[40];let O;e[41]!==f||e[42]!==h||e[43]!==w?(O=f&&t.jsx(it,{globalDir:f.globalDir,projectDir:f.projectDir,fileType:f.fileType,onCreated:w,onCancel:h}),e[41]=f,e[42]=h,e[43]=w,e[44]=O):O=e[44];let $;return e[45]!==v||e[46]!==E||e[47]!==I||e[48]!==O?($=t.jsxs("section",{children:[v,E,I,O]}),e[45]=v,e[46]=E,e[47]=I,e[48]=O,e[49]=$):$=e[49],$}function ot({file:l,onDeleted:e,readOnly:i=!1}){const[n,s]=o.useState(null),[r,u]=o.useState(null),[m,c]=o.useState(!0),[d,g]=o.useState(!1),[N,k]=o.useState(!1),[S,f]=o.useState(!1),[w,h]=o.useState(!1),p=n!==null&&n!==r,j=i||l.readOnly;o.useEffect(()=>{c(!0),s(null),u(null),k(!1),f(!1),A(`/api/config-browser/file?path=${encodeURIComponent(l.path)}`).then(C=>C.json()).then(C=>{s(C.content??""),u(C.content??"")}).catch(()=>{s(""),u("")}).finally(()=>c(!1))},[l.path]);const D=o.useCallback(async()=>{if(!(!p||j)){g(!0);try{(await A("/api/config-browser/file",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:l.path,content:n})})).ok&&(u(n),k(!0),setTimeout(()=>k(!1),2e3))}finally{g(!1)}}},[n,l.path,p,j]),T=o.useCallback(()=>{s(r)},[r]),y=o.useCallback(async()=>{if(!j){h(!0);try{(await A(`/api/config-browser/file?path=${encodeURIComponent(l.path)}`,{method:"DELETE"})).ok&&(f(!1),e())}catch{}finally{h(!1)}}},[l.path,j,e]);o.useEffect(()=>{function C(v){!j&&(v.metaKey||v.ctrlKey)&&v.key==="s"&&(v.preventDefault(),D())}return window.addEventListener("keydown",C),()=>window.removeEventListener("keydown",C)},[D,j]);function R(){return N?"Saved!":d?"Saving...":"Save"}return t.jsxs("div",{className:"flex flex-1 flex-col min-h-0 min-w-0",children:[t.jsxs("div",{className:"flex min-h-11 shrink-0 items-center gap-2 border-b bg-card px-4 py-2",children:[t.jsx(ee,{variant:"outline",className:P("h-5 text-xs",tt[l.fileType]||"bg-muted text-muted-foreground"),children:l.fileType}),t.jsx(he,{scope:l.scope,pluginName:l.pluginName}),t.jsx(pe,{cli:l.cli,variant:"full"}),j&&t.jsxs(ee,{variant:"outline",className:"h-5 bg-muted text-xs text-muted-foreground",children:[t.jsx(fe,{"data-icon":"inline-start",className:"size-3"})," read-only"]}),p&&t.jsx("span",{className:"size-2 shrink-0 rounded-full bg-warning",title:"Unsaved changes"}),t.jsxs("div",{className:"flex items-center gap-2 ml-auto min-w-0",children:[t.jsx(ge,{linkTarget:l.linkTarget,variant:"full"}),t.jsx("span",{className:"truncate font-mono text-xs text-muted-foreground",title:l.path,children:l.path})]})]}),m?t.jsx("div",{className:"flex-1 flex items-center justify-center text-muted-foreground text-sm",children:"Loading..."}):t.jsxs("div",{className:"flex-1 min-h-0 overflow-hidden flex flex-col",children:[t.jsx(et,{value:n??"",onChange:s,readOnly:j,filePath:l.path}),!j&&t.jsxs("div",{className:"flex shrink-0 items-center gap-2 border-t bg-card px-4 py-2",children:[t.jsxs(z,{size:"xs",onClick:D,disabled:!p||d,children:[t.jsx(H,{"data-icon":"inline-start"}),R()]}),t.jsxs(z,{variant:"outline",size:"xs",onClick:T,disabled:!p,children:[t.jsx(We,{"data-icon":"inline-start"}),"Discard"]}),t.jsx("div",{className:"flex-1"}),t.jsxs(ae,{open:S,onOpenChange:f,children:[t.jsxs(Te,{render:t.jsx(z,{variant:"outline",size:"xs"}),children:[t.jsx(Xe,{"data-icon":"inline-start"}),"Delete"]}),t.jsxs(le,{size:"sm",children:[t.jsxs(ie,{children:[t.jsx(re,{children:"Delete configuration file?"}),t.jsxs(oe,{children:['Delete "',l.name,'" permanently? This action cannot be undone.']})]}),t.jsxs(ce,{children:[t.jsx(de,{size:"sm",disabled:w,children:"Cancel"}),t.jsxs(ue,{variant:"destructive",size:"sm",disabled:w,onClick:()=>void y(),children:[w&&t.jsx(Ee,{"data-icon":"inline-start"}),w?"Deleting...":"Delete file"]})]})]})]})]})]})]})}function ct(){const l=G.c(1);let e;return l[0]===Symbol.for("react.memo_cache_sentinel")?(e=t.jsx(Re,{className:"border-0",children:t.jsxs(Ie,{children:[t.jsx(Oe,{variant:"icon",children:t.jsx(qe,{})}),t.jsx(ze,{children:"Select a configuration file"}),t.jsx(Le,{children:"Browse instructions, agents, skills, commands, and settings from the sidebar."})]})}),l[0]=e):e=l[0],e}function dt(l){return l.cli?l.cli.length>0?l.cli.join(" "):"unlinked":""}function ut(l,e){if(!e)return l;const i=e.toLowerCase();return l.filter(n=>[n.name,n.description,n.path,n.linkTarget??"",dt(n)].some(r=>r.toLowerCase().includes(i)))}const jt=o.memo(function({projectPath:e,initialFilePath:i}){var L,Y;const n=Ae("configWrite"),[s,r]=o.useState([]),[u,m]=o.useState(!0),[c,d]=o.useState(null),[g,N]=o.useState(null),[k,S]=o.useState(""),[f,w]=o.useState(null),[h,p]=o.useState(""),[j,D]=o.useState(null),T=o.useRef(!1),y=o.useCallback(async()=>{if(!n){r([]),d(null),m(!1);return}m(!0);try{const a=e?`/api/config-browser/tree?cwd=${encodeURIComponent(e)}`:"/api/config-browser/tree",x=await A(a);if(x.ok){const _=await x.json();r(_.sections||[])}}finally{m(!1)}},[n,e]);o.useEffect(()=>{y()},[y]),o.useEffect(()=>{if(!i||u||T.current)return;const a=s.flatMap(x=>J(x.items,x.scope,x.pluginName)).find(x=>x.path===i);a&&(d(a),T.current=!0)},[i,u,s]);const R=at(s),C=Object.fromEntries(ne.map(a=>[a,ut(R[a],k)])),v=(L=s.find(a=>a.scope==="global"))==null?void 0:L.baseDir,E=(Y=s.find(a=>a.scope==="project"))==null?void 0:Y.baseDir,I=o.useCallback(a=>{d(a),N(null)},[]),O=o.useCallback((a,x,_)=>{N(null),y(),d({path:a,name:a.split("/").pop()||"",fileType:x,readOnly:!1,scope:_,description:""})},[y]),$=o.useCallback(()=>{d(null),y()},[y]),B=o.useCallback(a=>{if(!n||!v&&!E)return;const x=nt[a];x&&N({category:a,globalDir:v?`${v}/${x.subdir}`:null,projectDir:E?`${E}/${x.subdir}`:null,fileType:x.fileType})},[n,v,E]),b=o.useCallback(a=>{!n||a.readOnly||D(a)},[n]),U=o.useCallback(async()=>{if(!n||!j||j.readOnly)return;const a=j;D(null);try{(await A(`/api/config-browser/file?path=${encodeURIComponent(a.path)}`,{method:"DELETE"})).ok&&((c==null?void 0:c.path)===a.path&&d(null),y())}catch{}},[n,y,j,c]),Q=o.useCallback(a=>{if(!n||a.readOnly)return;const x=a.name==="SKILL.md"?a.path.split("/").slice(-2,-1)[0]||a.name:a.name.replace(/\.[^.]+$/,"");w(a),p(x)},[n]),F=o.useCallback(async()=>{if(!(!n||!f||!h.trim()))try{const a=await A("/api/config-browser/rename",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({oldPath:f.path,newName:h.trim()})});if(a.ok){const x=await a.json();w(null),p(""),await y(),x.newPath&&d({...f,path:x.newPath,name:x.newPath.split("/").pop()||f.name})}}catch{}},[n,f,h,y]),M=o.useCallback(()=>{w(null),p("")},[]);return n?t.jsxs("div",{className:"flex flex-1 min-h-0 min-w-0",children:[t.jsxs("div",{className:"flex min-h-0 w-80 shrink-0 flex-col border-r bg-sidebar",children:[t.jsxs("div",{className:"flex h-11 items-center gap-2 border-b px-3",children:[t.jsx("span",{className:"text-sm font-medium text-foreground",children:"Configuration"}),e&&t.jsx("span",{className:"ml-auto truncate text-xs text-muted-foreground",title:e,children:e.split("/").pop()})]}),t.jsx("div",{className:"border-b p-2",children:t.jsxs($e,{children:[t.jsx(te,{children:t.jsx(Ze,{"data-icon":"inline-start"})}),t.jsx(Be,{value:k,onChange:a=>S(a.target.value),placeholder:"Search configuration"}),k&&t.jsx(te,{align:"inline-end",children:t.jsx(Ge,{size:"icon-xs","aria-label":"Clear search",onClick:()=>S(""),children:t.jsx(K,{"data-icon":"inline-start"})})})]})}),t.jsx(Fe,{className:"flex-1",children:t.jsx("div",{className:"flex flex-col gap-1 py-2",children:u?t.jsx("div",{className:"flex flex-col gap-2 px-3 py-2","aria-label":"Loading configuration",children:Array.from({length:6},(a,x)=>t.jsx(Me,{className:"h-8 w-full"},x))}):ne.map(a=>{const x=a==="agents"||a==="skills"||a==="commands";return t.jsx(rt,{category:a,items:C[a],selectedPath:(c==null?void 0:c.path)??null,onSelect:I,onNewFile:n&&x?()=>B(a):void 0,onDeleteItem:n?b:void 0,onRenameItem:n?Q:void 0,renamingPath:(f==null?void 0:f.path)??null,renameValue:h,onRenameValueChange:p,onRenameSubmit:F,onRenameCancel:M,creatingInCategory:n&&(g==null?void 0:g.category)===a?g:null,onCreated:O,onCancelCreate:()=>N(null)},a)})})})]}),c?t.jsx(ot,{file:c,onDeleted:$,readOnly:!n}):t.jsx(ct,{}),t.jsx(ae,{open:j!==null,onOpenChange:a=>{a||D(null)},children:t.jsxs(le,{size:"sm",children:[t.jsxs(ie,{children:[t.jsx(re,{children:"Delete configuration file?"}),t.jsxs(oe,{children:['Delete "',j==null?void 0:j.name,'" permanently? This action cannot be undone.']})]}),t.jsxs(ce,{children:[t.jsx(de,{size:"sm",children:"Cancel"}),t.jsx(ue,{variant:"destructive",size:"sm",onClick:()=>void U(),children:"Delete file"})]})]})})]}):t.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:"Server configuration is available to administrators only."})});export{jt as ConfigBrowser};
@@ -1,2 +1,2 @@
1
- import{c as z,r as v,j as f}from"./vendor-react-gGw_S5I_.js";import{an as F,ao as K,T as A,ap as O}from"./index-CNV6e3p0.js";const X=2e5;function Q(l){const e=z.c(35),{value:t,onChange:y,readOnly:u,filePath:E,ariaLabel:L,textareaRef:p,onKeyDown:S,onSelect:_}=l,h=F(),[d,I]=v.useState(null),m=v.useRef(null),x=v.useRef(null);let g;e[0]!==E?(g=K(E)??"markdown",e[0]=E,e[1]=g):g=e[1];const b=g,T=t.length>X;let j,k;e[2]!==h||e[3]!==b||e[4]!==T||e[5]!==t?(j=()=>{if(T){I(null);return}let r=!1;const M=setTimeout(()=>{O(t,b,h).then(P=>{r||I(P)})},80);return()=>{r=!0,clearTimeout(M)}},k=[t,b,h,T],e[2]=h,e[3]=b,e[4]=T,e[5]=t,e[6]=j,e[7]=k):(j=e[6],k=e[7]),v.useEffect(j,k);let R;e[8]===Symbol.for("react.memo_cache_sentinel")?(R=()=>{m.current&&x.current&&(x.current.scrollTop=m.current.scrollTop,x.current.scrollLeft=m.current.scrollLeft)},e[8]=R):R=e[8];const G=R;let w;e[9]!==p?(w=r=>{m.current=r,p&&(p.current=r)},e[9]=p,e[10]=w):w=e[10];const C=w,N=u&&"opacity-70";let n;e[11]!==N?(n=A("absolute inset-0 overflow-hidden font-mono text-[13px] leading-relaxed p-4 m-0 pointer-events-none whitespace-pre-wrap break-words",N),e[11]=N,e[12]=n):n=e[12];let s;e[13]!==d||e[14]!==t?(s=d?d.map($):f.jsx("code",{className:"text-foreground",children:t}),e[13]=d,e[14]=t,e[15]=s):s=e[15];let o;e[16]!==n||e[17]!==s?(o=f.jsx("pre",{ref:x,"aria-hidden":!0,className:n,children:s}),e[16]=n,e[17]=s,e[18]=o):o=e[18];let a;e[19]!==y?(a=r=>y(r.target.value),e[19]=y,e[20]=a):a=e[20];const D=u&&"cursor-default";let c;e[21]!==D?(c=A("absolute inset-0 w-full h-full resize-none bg-transparent font-mono text-[13px] leading-relaxed p-4 outline-none","text-transparent caret-foreground selection:bg-info/30","scrollbar-thin scrollbar-track-transparent scrollbar-thumb-border",D),e[21]=D,e[22]=c):c=e[22];let i;e[23]!==L||e[24]!==C||e[25]!==S||e[26]!==_||e[27]!==u||e[28]!==a||e[29]!==c||e[30]!==t?(i=f.jsx("textarea",{ref:C,"aria-label":L,value:t,onChange:a,onScroll:G,onKeyDown:S,onSelect:_,readOnly:u,spellCheck:!1,className:c,placeholder:"Empty file"}),e[23]=L,e[24]=C,e[25]=S,e[26]=_,e[27]=u,e[28]=a,e[29]=c,e[30]=t,e[31]=i):i=e[31];let H;return e[32]!==i||e[33]!==o?(H=f.jsxs("div",{className:"relative min-h-0 flex-1 bg-background",children:[o,i]}),e[32]=i,e[33]=o,e[34]=H):H=e[34],H}function $(l,e){return f.jsxs("span",{children:[l.map(q),`
1
+ import{c as z,r as v,j as f}from"./vendor-react-gGw_S5I_.js";import{an as F,ao as K,T as A,ap as O}from"./index-C3E35E2A.js";const X=2e5;function Q(l){const e=z.c(35),{value:t,onChange:y,readOnly:u,filePath:E,ariaLabel:L,textareaRef:p,onKeyDown:S,onSelect:_}=l,h=F(),[d,I]=v.useState(null),m=v.useRef(null),x=v.useRef(null);let g;e[0]!==E?(g=K(E)??"markdown",e[0]=E,e[1]=g):g=e[1];const b=g,T=t.length>X;let j,k;e[2]!==h||e[3]!==b||e[4]!==T||e[5]!==t?(j=()=>{if(T){I(null);return}let r=!1;const M=setTimeout(()=>{O(t,b,h).then(P=>{r||I(P)})},80);return()=>{r=!0,clearTimeout(M)}},k=[t,b,h,T],e[2]=h,e[3]=b,e[4]=T,e[5]=t,e[6]=j,e[7]=k):(j=e[6],k=e[7]),v.useEffect(j,k);let R;e[8]===Symbol.for("react.memo_cache_sentinel")?(R=()=>{m.current&&x.current&&(x.current.scrollTop=m.current.scrollTop,x.current.scrollLeft=m.current.scrollLeft)},e[8]=R):R=e[8];const G=R;let w;e[9]!==p?(w=r=>{m.current=r,p&&(p.current=r)},e[9]=p,e[10]=w):w=e[10];const C=w,N=u&&"opacity-70";let n;e[11]!==N?(n=A("absolute inset-0 overflow-hidden font-mono text-[13px] leading-relaxed p-4 m-0 pointer-events-none whitespace-pre-wrap break-words",N),e[11]=N,e[12]=n):n=e[12];let s;e[13]!==d||e[14]!==t?(s=d?d.map($):f.jsx("code",{className:"text-foreground",children:t}),e[13]=d,e[14]=t,e[15]=s):s=e[15];let o;e[16]!==n||e[17]!==s?(o=f.jsx("pre",{ref:x,"aria-hidden":!0,className:n,children:s}),e[16]=n,e[17]=s,e[18]=o):o=e[18];let a;e[19]!==y?(a=r=>y(r.target.value),e[19]=y,e[20]=a):a=e[20];const D=u&&"cursor-default";let c;e[21]!==D?(c=A("absolute inset-0 w-full h-full resize-none bg-transparent font-mono text-[13px] leading-relaxed p-4 outline-none","text-transparent caret-foreground selection:bg-info/30","scrollbar-thin scrollbar-track-transparent scrollbar-thumb-border",D),e[21]=D,e[22]=c):c=e[22];let i;e[23]!==L||e[24]!==C||e[25]!==S||e[26]!==_||e[27]!==u||e[28]!==a||e[29]!==c||e[30]!==t?(i=f.jsx("textarea",{ref:C,"aria-label":L,value:t,onChange:a,onScroll:G,onKeyDown:S,onSelect:_,readOnly:u,spellCheck:!1,className:c,placeholder:"Empty file"}),e[23]=L,e[24]=C,e[25]=S,e[26]=_,e[27]=u,e[28]=a,e[29]=c,e[30]=t,e[31]=i):i=e[31];let H;return e[32]!==i||e[33]!==o?(H=f.jsxs("div",{className:"relative min-h-0 flex-1 bg-background",children:[o,i]}),e[32]=i,e[33]=o,e[34]=H):H=e[34],H}function $(l,e){return f.jsxs("span",{children:[l.map(q),`
2
2
  `]},e)}function q(l,e){return f.jsx("span",{style:{color:l.color},children:l.content},e)}export{Q as H};
@@ -1 +1 @@
1
- import{c as q,j as t,r as k}from"./vendor-react-gGw_S5I_.js";import{D as F,g as $,K as T,e as Q,B as P,f as Y,r as _,h as H,i as M,j as U,k as J,l as V,I as W,m as X,n as Z,o as ee,A as te,p as se,q as ae,s as le,t as ne,u as re}from"./index-CNV6e3p0.js";import{R as O,K as oe,S as ce}from"./vendor-ui-BmLOQ5Or.js";import"./vendor-shiki-DOn6sF-i.js";import"./vendor-markdown-BE1gYnO9.js";const ie=new Set(["Alt","Control","Meta","Shift"]);function fe(e){const s=q.c(6),{open:f,onOpenChange:l}=e,x=f?"open":"closed";let a;s[0]!==x?(a=t.jsx(de,{},x),s[0]=x,s[1]=a):a=s[1];let r;return s[2]!==l||s[3]!==f||s[4]!==a?(r=t.jsx(F,{open:f,onOpenChange:l,children:a}),s[2]=l,s[3]=f,s[4]=a,s[5]=r):r=s[5],r}function de(){const e=q.c(45),[s,f]=k.useState(""),[l,x]=k.useState(null),[a,r]=k.useState(null),[B,G]=k.useState($);let E,I;e[0]!==l?(E=()=>{if(!l)return;const D=l,A=function(n){if(n.key==="Escape"){n.preventDefault(),n.stopPropagation(),x(null),r(null);return}if(ie.has(n.key))return;n.preventDefault(),n.stopPropagation();const c=le(n),p=ne(c,D);if(p){r(`Already assigned to “${p.label}”.`);return}re(D,c),G($()),x(null),r(null)};return window.addEventListener("keydown",A,!0),()=>window.removeEventListener("keydown",A,!0)},I=[l],e[0]=l,e[1]=E,e[2]=I):(E=e[1],I=e[2]),k.useEffect(E,I);let g,j,d,y,b,N,S,w,m,u,h;if(e[3]!==B||e[4]!==a||e[5]!==s||e[6]!==l){const D=s.trim().toLowerCase(),A=D?T.filter(i=>`${i.label} ${i.description} ${i.group}`.toLowerCase().includes(D)):T;j=H,S="max-w-2xl gap-0 overflow-hidden p-0",w=!1,e[18]===Symbol.for("react.memo_cache_sentinel")?(m=t.jsxs(M,{className:"p-4 pb-3",children:[t.jsxs(U,{className:"flex items-center gap-2",children:[t.jsx(oe,{"data-icon":"inline-start","aria-hidden":"true",className:"size-4"}),"Keyboard shortcuts"]}),t.jsx(J,{children:"Click a shortcut, then press a new key combination. Changes are saved on this device."})]}),u=t.jsx(V,{}),e[18]=m,e[19]=u):(m=e[18],u=e[19]);let K;e[20]===Symbol.for("react.memo_cache_sentinel")?(K=t.jsx(W,{children:t.jsx(ce,{"data-icon":"inline-start","aria-hidden":"true"})}),e[20]=K):K=e[20];let n;e[21]===Symbol.for("react.memo_cache_sentinel")?(n=i=>f(i.target.value),e[21]=n):n=e[21];let c;e[22]!==s?(c=t.jsxs(X,{className:"flex-1",children:[K,t.jsx(Z,{"aria-label":"Search keyboard shortcuts",value:s,onChange:n,placeholder:"Search shortcuts…"})]}),e[22]=s,e[23]=c):c=e[23];let p;e[24]===Symbol.for("react.memo_cache_sentinel")?(p=t.jsxs(P,{variant:"outline",size:"sm",onClick:()=>{ee(),G($()),r(null)},children:[t.jsx(O,{"data-icon":"inline-start"}),"Reset all"]}),e[24]=p):p=e[24],e[25]!==c?(h=t.jsxs("div",{className:"flex items-center gap-2 p-3",children:[c,p]}),e[25]=c,e[26]=h):h=e[26],e[27]!==a?(d=a&&t.jsx(te,{variant:"destructive",className:"mx-3 mb-2 w-auto",children:t.jsxs(se,{children:[a," Press another shortcut or Esc to cancel."]})}),e[27]=a,e[28]=d):d=e[28],g=ae,N="h-[min(28rem,60vh)]",y="flex flex-col gap-4 px-3 pb-4",b=Q.map(i=>{const L=A.filter(o=>o.group===i);return L.length===0?null:t.jsxs("section",{className:"flex flex-col gap-1",children:[t.jsx("h3",{className:"px-2 py-1 text-xs font-medium text-muted-foreground",children:i}),L.map(o=>{const z=l===o.command;return t.jsxs("div",{className:"flex min-h-12 items-center gap-3 rounded-md px-2 py-1.5 hover:bg-accent",children:[t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("p",{className:"truncate text-sm",children:o.label}),t.jsx("p",{className:"truncate text-xs text-muted-foreground",children:o.description})]}),t.jsx(P,{variant:z?"secondary":"outline",size:"sm",className:"min-w-28 font-mono text-xs",onClick:()=>{r(null),x(z?null:o.command)},"aria-label":`Change shortcut for ${o.label}`,children:z?"Press keys…":Y(B[o.command])}),t.jsx(P,{variant:"ghost",size:"icon-sm",onClick:()=>{_(o.command),G($()),r(null)},"aria-label":`Reset shortcut for ${o.label}`,children:t.jsx(O,{"data-icon":"inline-start"})})]},o.command)})]},i)}),e[3]=B,e[4]=a,e[5]=s,e[6]=l,e[7]=g,e[8]=j,e[9]=d,e[10]=y,e[11]=b,e[12]=N,e[13]=S,e[14]=w,e[15]=m,e[16]=u,e[17]=h}else g=e[7],j=e[8],d=e[9],y=e[10],b=e[11],N=e[12],S=e[13],w=e[14],m=e[15],u=e[16],h=e[17];let C;e[29]!==y||e[30]!==b?(C=t.jsx("div",{className:y,children:b}),e[29]=y,e[30]=b,e[31]=C):C=e[31];let v;e[32]!==g||e[33]!==C||e[34]!==N?(v=t.jsx(g,{className:N,children:C}),e[32]=g,e[33]=C,e[34]=N,e[35]=v):v=e[35];let R;return e[36]!==j||e[37]!==d||e[38]!==v||e[39]!==S||e[40]!==w||e[41]!==m||e[42]!==u||e[43]!==h?(R=t.jsxs(j,{className:S,showCloseButton:w,children:[m,u,h,d,v]}),e[36]=j,e[37]=d,e[38]=v,e[39]=S,e[40]=w,e[41]=m,e[42]=u,e[43]=h,e[44]=R):R=e[44],R}export{fe as KeyboardShortcutsDialog};
1
+ import{c as q,j as t,r as k}from"./vendor-react-gGw_S5I_.js";import{D as F,g as $,K as T,e as Q,B as P,f as Y,r as _,h as H,i as M,j as U,k as J,l as V,I as W,m as X,n as Z,o as ee,A as te,p as se,q as ae,s as le,t as ne,u as re}from"./index-C3E35E2A.js";import{R as O,K as oe,S as ce}from"./vendor-ui-BmLOQ5Or.js";import"./vendor-shiki-DOn6sF-i.js";import"./vendor-markdown-BE1gYnO9.js";const ie=new Set(["Alt","Control","Meta","Shift"]);function fe(e){const s=q.c(6),{open:f,onOpenChange:l}=e,x=f?"open":"closed";let a;s[0]!==x?(a=t.jsx(de,{},x),s[0]=x,s[1]=a):a=s[1];let r;return s[2]!==l||s[3]!==f||s[4]!==a?(r=t.jsx(F,{open:f,onOpenChange:l,children:a}),s[2]=l,s[3]=f,s[4]=a,s[5]=r):r=s[5],r}function de(){const e=q.c(45),[s,f]=k.useState(""),[l,x]=k.useState(null),[a,r]=k.useState(null),[B,G]=k.useState($);let E,I;e[0]!==l?(E=()=>{if(!l)return;const D=l,A=function(n){if(n.key==="Escape"){n.preventDefault(),n.stopPropagation(),x(null),r(null);return}if(ie.has(n.key))return;n.preventDefault(),n.stopPropagation();const c=le(n),p=ne(c,D);if(p){r(`Already assigned to “${p.label}”.`);return}re(D,c),G($()),x(null),r(null)};return window.addEventListener("keydown",A,!0),()=>window.removeEventListener("keydown",A,!0)},I=[l],e[0]=l,e[1]=E,e[2]=I):(E=e[1],I=e[2]),k.useEffect(E,I);let g,j,d,y,b,N,S,w,m,u,h;if(e[3]!==B||e[4]!==a||e[5]!==s||e[6]!==l){const D=s.trim().toLowerCase(),A=D?T.filter(i=>`${i.label} ${i.description} ${i.group}`.toLowerCase().includes(D)):T;j=H,S="max-w-2xl gap-0 overflow-hidden p-0",w=!1,e[18]===Symbol.for("react.memo_cache_sentinel")?(m=t.jsxs(M,{className:"p-4 pb-3",children:[t.jsxs(U,{className:"flex items-center gap-2",children:[t.jsx(oe,{"data-icon":"inline-start","aria-hidden":"true",className:"size-4"}),"Keyboard shortcuts"]}),t.jsx(J,{children:"Click a shortcut, then press a new key combination. Changes are saved on this device."})]}),u=t.jsx(V,{}),e[18]=m,e[19]=u):(m=e[18],u=e[19]);let K;e[20]===Symbol.for("react.memo_cache_sentinel")?(K=t.jsx(W,{children:t.jsx(ce,{"data-icon":"inline-start","aria-hidden":"true"})}),e[20]=K):K=e[20];let n;e[21]===Symbol.for("react.memo_cache_sentinel")?(n=i=>f(i.target.value),e[21]=n):n=e[21];let c;e[22]!==s?(c=t.jsxs(X,{className:"flex-1",children:[K,t.jsx(Z,{"aria-label":"Search keyboard shortcuts",value:s,onChange:n,placeholder:"Search shortcuts…"})]}),e[22]=s,e[23]=c):c=e[23];let p;e[24]===Symbol.for("react.memo_cache_sentinel")?(p=t.jsxs(P,{variant:"outline",size:"sm",onClick:()=>{ee(),G($()),r(null)},children:[t.jsx(O,{"data-icon":"inline-start"}),"Reset all"]}),e[24]=p):p=e[24],e[25]!==c?(h=t.jsxs("div",{className:"flex items-center gap-2 p-3",children:[c,p]}),e[25]=c,e[26]=h):h=e[26],e[27]!==a?(d=a&&t.jsx(te,{variant:"destructive",className:"mx-3 mb-2 w-auto",children:t.jsxs(se,{children:[a," Press another shortcut or Esc to cancel."]})}),e[27]=a,e[28]=d):d=e[28],g=ae,N="h-[min(28rem,60vh)]",y="flex flex-col gap-4 px-3 pb-4",b=Q.map(i=>{const L=A.filter(o=>o.group===i);return L.length===0?null:t.jsxs("section",{className:"flex flex-col gap-1",children:[t.jsx("h3",{className:"px-2 py-1 text-xs font-medium text-muted-foreground",children:i}),L.map(o=>{const z=l===o.command;return t.jsxs("div",{className:"flex min-h-12 items-center gap-3 rounded-md px-2 py-1.5 hover:bg-accent",children:[t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("p",{className:"truncate text-sm",children:o.label}),t.jsx("p",{className:"truncate text-xs text-muted-foreground",children:o.description})]}),t.jsx(P,{variant:z?"secondary":"outline",size:"sm",className:"min-w-28 font-mono text-xs",onClick:()=>{r(null),x(z?null:o.command)},"aria-label":`Change shortcut for ${o.label}`,children:z?"Press keys…":Y(B[o.command])}),t.jsx(P,{variant:"ghost",size:"icon-sm",onClick:()=>{_(o.command),G($()),r(null)},"aria-label":`Reset shortcut for ${o.label}`,children:t.jsx(O,{"data-icon":"inline-start"})})]},o.command)})]},i)}),e[3]=B,e[4]=a,e[5]=s,e[6]=l,e[7]=g,e[8]=j,e[9]=d,e[10]=y,e[11]=b,e[12]=N,e[13]=S,e[14]=w,e[15]=m,e[16]=u,e[17]=h}else g=e[7],j=e[8],d=e[9],y=e[10],b=e[11],N=e[12],S=e[13],w=e[14],m=e[15],u=e[16],h=e[17];let C;e[29]!==y||e[30]!==b?(C=t.jsx("div",{className:y,children:b}),e[29]=y,e[30]=b,e[31]=C):C=e[31];let v;e[32]!==g||e[33]!==C||e[34]!==N?(v=t.jsx(g,{className:N,children:C}),e[32]=g,e[33]=C,e[34]=N,e[35]=v):v=e[35];let R;return e[36]!==j||e[37]!==d||e[38]!==v||e[39]!==S||e[40]!==w||e[41]!==m||e[42]!==u||e[43]!==h?(R=t.jsxs(j,{className:S,showCloseButton:w,children:[m,u,h,d,v]}),e[36]=j,e[37]=d,e[38]=v,e[39]=S,e[40]=w,e[41]=m,e[42]=u,e[43]=h,e[44]=R):R=e[44],R}export{fe as KeyboardShortcutsDialog};
@@ -1 +1 @@
1
- import{r as x,c as d,j as s}from"./vendor-react-gGw_S5I_.js";import{S as p,a as f,b as j,c as g,F as C,d as S}from"./index-CNV6e3p0.js";import"./vendor-ui-BmLOQ5Or.js";import"./vendor-shiki-DOn6sF-i.js";import"./vendor-markdown-BE1gYnO9.js";const E=x.memo(function(c){const e=d.c(10),{open:l,onClose:a,session:r,sessionChangeKey:h}=c;let i;e[0]!==a?(i=m=>{m||a()},e[0]=a,e[1]=i):i=e[1];let t;e[2]===Symbol.for("react.memo_cache_sentinel")?(t=s.jsxs(p,{className:"shrink-0 px-4 py-3",children:[s.jsx(f,{children:"File changes"}),s.jsx(j,{className:"sr-only",children:"Review files changed in this session."})]}),e[2]=t):t=e[2];let n;e[3]!==r||e[4]!==h?(n=s.jsxs(g,{side:"bottom",className:"h-[72svh] max-h-[92svh] rounded-t-xl",children:[t,s.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:s.jsx(C,{session:r,sessionChangeKey:h})})]}),e[3]=r,e[4]=h,e[5]=n):n=e[5];let o;return e[6]!==l||e[7]!==i||e[8]!==n?(o=s.jsx(S,{open:l,onOpenChange:i,children:n}),e[6]=l,e[7]=i,e[8]=n,e[9]=o):o=e[9],o});export{E as MobileFileChanges};
1
+ import{r as x,c as d,j as s}from"./vendor-react-gGw_S5I_.js";import{S as p,a as f,b as j,c as g,F as C,d as S}from"./index-C3E35E2A.js";import"./vendor-ui-BmLOQ5Or.js";import"./vendor-shiki-DOn6sF-i.js";import"./vendor-markdown-BE1gYnO9.js";const E=x.memo(function(c){const e=d.c(10),{open:l,onClose:a,session:r,sessionChangeKey:h}=c;let i;e[0]!==a?(i=m=>{m||a()},e[0]=a,e[1]=i):i=e[1];let t;e[2]===Symbol.for("react.memo_cache_sentinel")?(t=s.jsxs(p,{className:"shrink-0 px-4 py-3",children:[s.jsx(f,{children:"File changes"}),s.jsx(j,{className:"sr-only",children:"Review files changed in this session."})]}),e[2]=t):t=e[2];let n;e[3]!==r||e[4]!==h?(n=s.jsxs(g,{side:"bottom",className:"h-[72svh] max-h-[92svh] rounded-t-xl",children:[t,s.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:s.jsx(C,{session:r,sessionChangeKey:h})})]}),e[3]=r,e[4]=h,e[5]=n):n=e[5];let o;return e[6]!==l||e[7]!==i||e[8]!==n?(o=s.jsx(S,{open:l,onOpenChange:i,children:n}),e[6]=l,e[7]=i,e[8]=n,e[9]=o):o=e[9],o});export{E as MobileFileChanges};
@@ -1 +1 @@
1
- import{r as s,j as t}from"./vendor-react-gGw_S5I_.js";import{a7 as ne,B as g,l as K,a8 as ie,a9 as oe,m as le,n as ce,I as de,aa as G,ab as ue,ac as he,ad as pe,T as me,E as fe,y as xe,z as we,G as ve,H as ge,ae as be,w as je,P as b}from"./index-CNV6e3p0.js";import{f as H,X as ye,c as Se,E as ke,g as Ie,M as Ne,h as Ee,i as Me,j as Pe,Z as ze,k as Re}from"./vendor-ui-BmLOQ5Or.js";import"./vendor-shiki-DOn6sF-i.js";import"./vendor-markdown-BE1gYnO9.js";const W=360,Ce=560,V="cogpit-preview-width",Y="cogpit-preview-viewport",_="cogpit-preview-zoom",N=.5,E=1.5,I=.1,h={responsive:{label:"Responsive",width:null,height:null,icon:Pe},phone:{label:"Phone",width:390,height:844,icon:Me},tablet:{label:"Tablet",width:768,height:1024,icon:Ee},desktop:{label:"Desktop",width:1280,height:800,icon:Ne}};function Te(){try{const a=Number(localStorage.getItem(V));if(Number.isFinite(a)&&a>=W)return a}catch{}return Ce}function De(){try{const a=localStorage.getItem(Y);if(a&&a in h)return a}catch{}return"responsive"}function We(){try{const a=localStorage.getItem(_);if(a===null)return 1;const i=Number(a);if(Number.isFinite(i))return Math.min(E,Math.max(N,i))}catch{}return 1}function X(a){return be(`cogpit-preview-url:${a}`)}function A(a){const i=a.trim();if(!i||/^[a-z][a-z\d+.-]*:/i.test(i)&&!/^https?:\/\//i.test(i)&&!/^[^/]+:\d+(?:\/|$)/.test(i))return null;const j=/^https?:\/\//i.test(i)?i:`http://${i}`;try{const n=new URL(j);return n.protocol!=="http:"&&n.protocol!=="https:"?null:n.href}catch{return null}}function B(a,i){return`http://${i||"localhost"}:${a}/`}function Le({cwd:a,onClose:i}){const[M,j]=s.useState([]),[n,P]=s.useState(""),[$,y]=s.useState(""),[z,R]=s.useState(null),[q,J]=s.useState(0),[Q,C]=s.useState(!1),[S,ee]=s.useState(Te),[l,te]=s.useState(De),[o,p]=s.useState(We),c=s.useRef(null),O=s.useRef(null),T=s.useRef(null),{activeDevice:m}=ne(),k=(m==null?void 0:m.host)??(window.location.hostname||"localhost"),re=m==null?void 0:m.id;s.useEffect(()=>{let e="";try{e=localStorage.getItem(X(a))??""}catch{}const r=e?A(e)??"":"";P(r),y(r),R(null)},[a,re]),s.useEffect(()=>{let e=!1;async function r(){try{const u=await je(`/api/background-tasks?cwd=${encodeURIComponent(a)}`);if(e||!u.ok)return;const x=await u.json(),f=Array.isArray(x)?x:[];j(f);const L=f.flatMap(w=>w.ports.filter(v=>w.portStatus[v])).at(0);if(L){const w=B(L,k);P(v=>v||w),y(v=>v||w)}}catch{e||j([])}}r();const d=window.setInterval(r,1e4);return()=>{e=!0,window.clearInterval(d)}},[a,k]),s.useEffect(()=>{if(n)try{localStorage.setItem(X(a),n)}catch{}},[a,n]),s.useEffect(()=>{try{localStorage.setItem(Y,l),localStorage.setItem(_,String(o))}catch{}},[l,o]);const Z=s.useMemo(()=>[...new Set(M.flatMap(e=>e.ports.filter(r=>e.portStatus[r])))].sort((e,r)=>e-r),[M]),U=s.useCallback(e=>{const r=A(e);if(!r){R("Enter a valid HTTP or HTTPS URL.");return}R(null),P(r),y(r),C(!0)},[]),D=s.useCallback(()=>{n&&(C(!0),J(e=>e+1))},[n]);s.useEffect(()=>{function e(r){var d,u,x;if((d=O.current)!=null&&d.contains(document.activeElement)){if(b("previewRefresh",r)){r.preventDefault(),D();return}if(b("previewFocusUrl",r)){r.preventDefault(),(u=T.current)==null||u.focus(),(x=T.current)==null||x.select();return}if(b("previewZoomIn",r)){r.preventDefault(),p(f=>Math.min(E,Number((f+I).toFixed(1))));return}if(b("previewZoomOut",r)){r.preventDefault(),p(f=>Math.max(N,Number((f-I).toFixed(1))));return}b("previewResetZoom",r)&&(r.preventDefault(),p(1))}}return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[D]);const ae=s.useCallback(e=>{e.preventDefault(),c.current={startX:e.clientX,startWidth:S,currentWidth:S},e.currentTarget.setPointerCapture(e.pointerId)},[S]),se=s.useCallback(e=>{if(!c.current)return;const r=Math.max(W,window.innerWidth*.7),d=c.current.startWidth+(c.current.startX-e.clientX),u=Math.min(r,Math.max(W,d));c.current.currentWidth=u,ee(u)},[]),F=s.useCallback(()=>{if(!c.current)return;const e=c.current.currentWidth;c.current=null;try{localStorage.setItem(V,String(e))}catch{}},[]);return t.jsxs("aside",{ref:O,"aria-label":"Development preview",className:"view-transition-right-panel panel-enter-right relative flex min-h-0 shrink-0 flex-col border-l bg-background",style:{width:S},children:[t.jsx("div",{"aria-hidden":"true",className:"absolute inset-y-0 left-0 w-1 cursor-col-resize hover:bg-primary/30",onPointerDown:ae,onPointerMove:se,onPointerUp:F,onPointerCancel:F}),t.jsxs("div",{className:"flex h-10 shrink-0 items-center gap-2 px-3",children:[t.jsx(H,{"aria-hidden":"true",className:"size-4 text-muted-foreground"}),t.jsx("h2",{className:"text-sm font-medium",children:"Preview"}),t.jsx("span",{className:"flex-1"}),t.jsx(g,{variant:"ghost",size:"icon-sm",onClick:i,"aria-label":"Close preview",children:t.jsx(ye,{"data-icon":"inline-start"})})]}),t.jsx(K,{}),t.jsx("form",{className:"p-2",onSubmit:e=>{e.preventDefault(),U($)},children:t.jsx(ie,{className:"gap-2",children:t.jsxs(oe,{"data-invalid":!!z,children:[t.jsxs(le,{children:[t.jsx(ce,{ref:T,"aria-label":"Preview URL","aria-invalid":!!z,value:$,onChange:e=>y(e.target.value),placeholder:"localhost:3000",spellCheck:!1}),t.jsxs(de,{align:"inline-end",children:[t.jsx(G,{size:"icon-xs",disabled:!n,onClick:D,"aria-label":"Refresh preview",children:t.jsx(Se,{"data-icon":"inline-start",className:Q?"animate-spin":void 0})}),t.jsx(G,{size:"icon-xs",disabled:!n,onClick:()=>window.open(n,"_blank","noopener,noreferrer"),"aria-label":"Open preview in browser",children:t.jsx(ke,{"data-icon":"inline-start"})})]})]}),t.jsx(ue,{children:z})]})})}),Z.length>0&&t.jsxs("div",{className:"flex shrink-0 items-center gap-1 overflow-x-auto px-2 pb-2",children:[t.jsx(Ie,{"aria-hidden":"true",className:"size-3.5 shrink-0 text-muted-foreground"}),Z.map(e=>t.jsxs(g,{variant:"outline",size:"xs",className:"font-mono text-xs",onClick:()=>U(B(e,k)),"aria-label":`Open ${k}:${e} preview`,children:[":",e]},e))]}),t.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-2 px-2 pb-2",children:[t.jsx(he,{"aria-label":"Preview viewport",value:[l],onValueChange:e=>{const r=e[0];r&&r in h&&te(r)},variant:"outline",size:"sm",spacing:0,children:Object.entries(h).map(([e,r])=>{const d=r.icon;return t.jsx(pe,{value:e,"aria-label":`${r.label} viewport`,title:r.width?`${r.label} · ${r.width}×${r.height}`:r.label,children:t.jsx(d,{})},e)})}),t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsx(g,{variant:"ghost",size:"icon-sm",disabled:o<=N,onClick:()=>p(e=>Math.max(N,Number((e-I).toFixed(1)))),"aria-label":"Zoom preview out",title:"Zoom out",children:t.jsx(ze,{"data-icon":"inline-start"})}),t.jsxs(g,{variant:"ghost",size:"sm",onClick:()=>p(1),"aria-label":"Reset preview zoom",children:[Math.round(o*100),"%"]}),t.jsx(g,{variant:"ghost",size:"icon-sm",disabled:o>=E,onClick:()=>p(e=>Math.min(E,Number((e+I).toFixed(1)))),"aria-label":"Zoom preview in",title:"Zoom in",children:t.jsx(Re,{"data-icon":"inline-start"})})]})]}),t.jsx(K,{}),t.jsx("div",{className:"min-h-0 flex-1 overflow-auto bg-muted/30 p-3",children:n?t.jsx("div",{className:me("relative mx-auto overflow-hidden bg-white ring-1 ring-border",l==="responsive"&&"size-full"),style:l==="responsive"?void 0:{width:h[l].width*o,height:h[l].height*o},children:t.jsx("iframe",{title:"Development preview",src:n,className:"block border-0 bg-white",style:l==="responsive"?{width:`${100/o}%`,height:`${100/o}%`,transform:`scale(${o})`,transformOrigin:"top left"}:{width:h[l].width,height:h[l].height,transform:`scale(${o})`,transformOrigin:"top left"},sandbox:"allow-downloads allow-forms allow-modals allow-popups allow-same-origin allow-scripts",referrerPolicy:"no-referrer",onLoad:()=>C(!1)},`${n}-${q}`)}):t.jsx(fe,{className:"size-full",children:t.jsxs(xe,{children:[t.jsx(we,{variant:"icon",children:t.jsx(H,{})}),t.jsx(ve,{children:"No preview selected"}),t.jsx(ge,{children:"Start a local development server or enter its URL above. Detected ports appear automatically."})]})})})]})}export{Le as PreviewPanel,A as normalizePreviewUrl};
1
+ import{r as s,j as t}from"./vendor-react-gGw_S5I_.js";import{a7 as ne,B as g,l as K,a8 as ie,a9 as oe,m as le,n as ce,I as de,aa as G,ab as ue,ac as he,ad as pe,T as me,E as fe,y as xe,z as we,G as ve,H as ge,ae as be,w as je,P as b}from"./index-C3E35E2A.js";import{f as H,X as ye,c as Se,E as ke,g as Ie,M as Ne,h as Ee,i as Me,j as Pe,Z as ze,k as Re}from"./vendor-ui-BmLOQ5Or.js";import"./vendor-shiki-DOn6sF-i.js";import"./vendor-markdown-BE1gYnO9.js";const W=360,Ce=560,V="cogpit-preview-width",Y="cogpit-preview-viewport",_="cogpit-preview-zoom",N=.5,E=1.5,I=.1,h={responsive:{label:"Responsive",width:null,height:null,icon:Pe},phone:{label:"Phone",width:390,height:844,icon:Me},tablet:{label:"Tablet",width:768,height:1024,icon:Ee},desktop:{label:"Desktop",width:1280,height:800,icon:Ne}};function Te(){try{const a=Number(localStorage.getItem(V));if(Number.isFinite(a)&&a>=W)return a}catch{}return Ce}function De(){try{const a=localStorage.getItem(Y);if(a&&a in h)return a}catch{}return"responsive"}function We(){try{const a=localStorage.getItem(_);if(a===null)return 1;const i=Number(a);if(Number.isFinite(i))return Math.min(E,Math.max(N,i))}catch{}return 1}function X(a){return be(`cogpit-preview-url:${a}`)}function A(a){const i=a.trim();if(!i||/^[a-z][a-z\d+.-]*:/i.test(i)&&!/^https?:\/\//i.test(i)&&!/^[^/]+:\d+(?:\/|$)/.test(i))return null;const j=/^https?:\/\//i.test(i)?i:`http://${i}`;try{const n=new URL(j);return n.protocol!=="http:"&&n.protocol!=="https:"?null:n.href}catch{return null}}function B(a,i){return`http://${i||"localhost"}:${a}/`}function Le({cwd:a,onClose:i}){const[M,j]=s.useState([]),[n,P]=s.useState(""),[$,y]=s.useState(""),[z,R]=s.useState(null),[q,J]=s.useState(0),[Q,C]=s.useState(!1),[S,ee]=s.useState(Te),[l,te]=s.useState(De),[o,p]=s.useState(We),c=s.useRef(null),O=s.useRef(null),T=s.useRef(null),{activeDevice:m}=ne(),k=(m==null?void 0:m.host)??(window.location.hostname||"localhost"),re=m==null?void 0:m.id;s.useEffect(()=>{let e="";try{e=localStorage.getItem(X(a))??""}catch{}const r=e?A(e)??"":"";P(r),y(r),R(null)},[a,re]),s.useEffect(()=>{let e=!1;async function r(){try{const u=await je(`/api/background-tasks?cwd=${encodeURIComponent(a)}`);if(e||!u.ok)return;const x=await u.json(),f=Array.isArray(x)?x:[];j(f);const L=f.flatMap(w=>w.ports.filter(v=>w.portStatus[v])).at(0);if(L){const w=B(L,k);P(v=>v||w),y(v=>v||w)}}catch{e||j([])}}r();const d=window.setInterval(r,1e4);return()=>{e=!0,window.clearInterval(d)}},[a,k]),s.useEffect(()=>{if(n)try{localStorage.setItem(X(a),n)}catch{}},[a,n]),s.useEffect(()=>{try{localStorage.setItem(Y,l),localStorage.setItem(_,String(o))}catch{}},[l,o]);const Z=s.useMemo(()=>[...new Set(M.flatMap(e=>e.ports.filter(r=>e.portStatus[r])))].sort((e,r)=>e-r),[M]),U=s.useCallback(e=>{const r=A(e);if(!r){R("Enter a valid HTTP or HTTPS URL.");return}R(null),P(r),y(r),C(!0)},[]),D=s.useCallback(()=>{n&&(C(!0),J(e=>e+1))},[n]);s.useEffect(()=>{function e(r){var d,u,x;if((d=O.current)!=null&&d.contains(document.activeElement)){if(b("previewRefresh",r)){r.preventDefault(),D();return}if(b("previewFocusUrl",r)){r.preventDefault(),(u=T.current)==null||u.focus(),(x=T.current)==null||x.select();return}if(b("previewZoomIn",r)){r.preventDefault(),p(f=>Math.min(E,Number((f+I).toFixed(1))));return}if(b("previewZoomOut",r)){r.preventDefault(),p(f=>Math.max(N,Number((f-I).toFixed(1))));return}b("previewResetZoom",r)&&(r.preventDefault(),p(1))}}return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[D]);const ae=s.useCallback(e=>{e.preventDefault(),c.current={startX:e.clientX,startWidth:S,currentWidth:S},e.currentTarget.setPointerCapture(e.pointerId)},[S]),se=s.useCallback(e=>{if(!c.current)return;const r=Math.max(W,window.innerWidth*.7),d=c.current.startWidth+(c.current.startX-e.clientX),u=Math.min(r,Math.max(W,d));c.current.currentWidth=u,ee(u)},[]),F=s.useCallback(()=>{if(!c.current)return;const e=c.current.currentWidth;c.current=null;try{localStorage.setItem(V,String(e))}catch{}},[]);return t.jsxs("aside",{ref:O,"aria-label":"Development preview",className:"view-transition-right-panel panel-enter-right relative flex min-h-0 shrink-0 flex-col border-l bg-background",style:{width:S},children:[t.jsx("div",{"aria-hidden":"true",className:"absolute inset-y-0 left-0 w-1 cursor-col-resize hover:bg-primary/30",onPointerDown:ae,onPointerMove:se,onPointerUp:F,onPointerCancel:F}),t.jsxs("div",{className:"flex h-10 shrink-0 items-center gap-2 px-3",children:[t.jsx(H,{"aria-hidden":"true",className:"size-4 text-muted-foreground"}),t.jsx("h2",{className:"text-sm font-medium",children:"Preview"}),t.jsx("span",{className:"flex-1"}),t.jsx(g,{variant:"ghost",size:"icon-sm",onClick:i,"aria-label":"Close preview",children:t.jsx(ye,{"data-icon":"inline-start"})})]}),t.jsx(K,{}),t.jsx("form",{className:"p-2",onSubmit:e=>{e.preventDefault(),U($)},children:t.jsx(ie,{className:"gap-2",children:t.jsxs(oe,{"data-invalid":!!z,children:[t.jsxs(le,{children:[t.jsx(ce,{ref:T,"aria-label":"Preview URL","aria-invalid":!!z,value:$,onChange:e=>y(e.target.value),placeholder:"localhost:3000",spellCheck:!1}),t.jsxs(de,{align:"inline-end",children:[t.jsx(G,{size:"icon-xs",disabled:!n,onClick:D,"aria-label":"Refresh preview",children:t.jsx(Se,{"data-icon":"inline-start",className:Q?"animate-spin":void 0})}),t.jsx(G,{size:"icon-xs",disabled:!n,onClick:()=>window.open(n,"_blank","noopener,noreferrer"),"aria-label":"Open preview in browser",children:t.jsx(ke,{"data-icon":"inline-start"})})]})]}),t.jsx(ue,{children:z})]})})}),Z.length>0&&t.jsxs("div",{className:"flex shrink-0 items-center gap-1 overflow-x-auto px-2 pb-2",children:[t.jsx(Ie,{"aria-hidden":"true",className:"size-3.5 shrink-0 text-muted-foreground"}),Z.map(e=>t.jsxs(g,{variant:"outline",size:"xs",className:"font-mono text-xs",onClick:()=>U(B(e,k)),"aria-label":`Open ${k}:${e} preview`,children:[":",e]},e))]}),t.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-2 px-2 pb-2",children:[t.jsx(he,{"aria-label":"Preview viewport",value:[l],onValueChange:e=>{const r=e[0];r&&r in h&&te(r)},variant:"outline",size:"sm",spacing:0,children:Object.entries(h).map(([e,r])=>{const d=r.icon;return t.jsx(pe,{value:e,"aria-label":`${r.label} viewport`,title:r.width?`${r.label} · ${r.width}×${r.height}`:r.label,children:t.jsx(d,{})},e)})}),t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsx(g,{variant:"ghost",size:"icon-sm",disabled:o<=N,onClick:()=>p(e=>Math.max(N,Number((e-I).toFixed(1)))),"aria-label":"Zoom preview out",title:"Zoom out",children:t.jsx(ze,{"data-icon":"inline-start"})}),t.jsxs(g,{variant:"ghost",size:"sm",onClick:()=>p(1),"aria-label":"Reset preview zoom",children:[Math.round(o*100),"%"]}),t.jsx(g,{variant:"ghost",size:"icon-sm",disabled:o>=E,onClick:()=>p(e=>Math.min(E,Number((e+I).toFixed(1)))),"aria-label":"Zoom preview in",title:"Zoom in",children:t.jsx(Re,{"data-icon":"inline-start"})})]})]}),t.jsx(K,{}),t.jsx("div",{className:"min-h-0 flex-1 overflow-auto bg-muted/30 p-3",children:n?t.jsx("div",{className:me("relative mx-auto overflow-hidden bg-white ring-1 ring-border",l==="responsive"&&"size-full"),style:l==="responsive"?void 0:{width:h[l].width*o,height:h[l].height*o},children:t.jsx("iframe",{title:"Development preview",src:n,className:"block border-0 bg-white",style:l==="responsive"?{width:`${100/o}%`,height:`${100/o}%`,transform:`scale(${o})`,transformOrigin:"top left"}:{width:h[l].width,height:h[l].height,transform:`scale(${o})`,transformOrigin:"top left"},sandbox:"allow-downloads allow-forms allow-modals allow-popups allow-same-origin allow-scripts",referrerPolicy:"no-referrer",onLoad:()=>C(!1)},`${n}-${q}`)}):t.jsx(fe,{className:"size-full",children:t.jsxs(xe,{children:[t.jsx(we,{variant:"icon",children:t.jsx(H,{})}),t.jsx(ve,{children:"No preview selected"}),t.jsx(ge,{children:"Start a local development server or enter its URL above. Detected ports appear automatically."})]})})})]})}export{Le as PreviewPanel,A as normalizePreviewUrl};
@@ -1,4 +1,4 @@
1
- import{r as s,j as e}from"./vendor-react-gGw_S5I_.js";import{w as Y,af as vt,ag as yt,B as w,l as q,U as A,m as wt,I as Ct,n as Nt,ac as Be,ad as le,q as St,ah as re,E as I,y as z,z as $,G as P,H as G,ai as kt,T as Et,aj as Dt,ak as Rt,D as Ft,h as Tt,i as Lt,j as Mt,k as Ut,al as At,am as It,Z as zt,_ as $t,$ as Pt,a1 as Gt,a2 as Ht,a3 as Kt,a4 as Ot,a5 as Wt,P as Bt}from"./index-CNV6e3p0.js";import{H as Xt}from"./HighlightedEditor-BPmH8BvC.js";import{l as Xe,X as Vt,G as Yt,S as qt,c as Ve,m as be,n as Ye,o as Qt,e as ve}from"./vendor-ui-BmLOQ5Or.js";import"./vendor-shiki-DOn6sF-i.js";import"./vendor-markdown-BE1gYnO9.js";const we=520,Jt=760,qe="cogpit-project-files-width",Zt={"?":{label:"Untracked",className:"text-info"},A:{label:"Added",className:"text-success"},M:{label:"Modified",className:"text-warning"},D:{label:"Deleted",className:"text-destructive"},R:{label:"Renamed",className:"text-info"},C:{label:"Copied",className:"text-info"},U:{label:"Conflicted",className:"text-destructive"}};function ye(r){const x=r.workTreeStatus.trim()||r.indexStatus.trim();return Zt[x]??{label:"Changed",className:"text-muted-foreground"}}function _t(){try{const r=Number(localStorage.getItem(qe));if(Number.isFinite(r)&&r>=we)return r}catch{}return Jt}async function Q(r,x){try{const u=await r.json();if(u&&typeof u=="object"&&typeof u.error=="string")return u.error}catch{}return x}function es(r){return r<1024?`${r} B`:`${(r/1024).toFixed(r<10*1024?1:0)} KB`}function ts(r,x){let u=0;for(let m=1;m<x;m+=1){const H=r.indexOf(`
1
+ import{r as s,j as e}from"./vendor-react-gGw_S5I_.js";import{w as Y,af as vt,ag as yt,B as w,l as q,U as A,m as wt,I as Ct,n as Nt,ac as Be,ad as le,q as St,ah as re,E as I,y as z,z as $,G as P,H as G,ai as kt,T as Et,aj as Dt,ak as Rt,D as Ft,h as Tt,i as Lt,j as Mt,k as Ut,al as At,am as It,Z as zt,_ as $t,$ as Pt,a1 as Gt,a2 as Ht,a3 as Kt,a4 as Ot,a5 as Wt,P as Bt}from"./index-C3E35E2A.js";import{H as Xt}from"./HighlightedEditor-D4DdiaD3.js";import{l as Xe,X as Vt,G as Yt,S as qt,c as Ve,m as be,n as Ye,o as Qt,e as ve}from"./vendor-ui-BmLOQ5Or.js";import"./vendor-shiki-DOn6sF-i.js";import"./vendor-markdown-BE1gYnO9.js";const we=520,Jt=760,qe="cogpit-project-files-width",Zt={"?":{label:"Untracked",className:"text-info"},A:{label:"Added",className:"text-success"},M:{label:"Modified",className:"text-warning"},D:{label:"Deleted",className:"text-destructive"},R:{label:"Renamed",className:"text-info"},C:{label:"Copied",className:"text-info"},U:{label:"Conflicted",className:"text-destructive"}};function ye(r){const x=r.workTreeStatus.trim()||r.indexStatus.trim();return Zt[x]??{label:"Changed",className:"text-muted-foreground"}}function _t(){try{const r=Number(localStorage.getItem(qe));if(Number.isFinite(r)&&r>=we)return r}catch{}return Jt}async function Q(r,x){try{const u=await r.json();if(u&&typeof u=="object"&&typeof u.error=="string")return u.error}catch{}return x}function es(r){return r<1024?`${r} B`:`${(r/1024).toFixed(r<10*1024?1:0)} KB`}function ts(r,x){let u=0;for(let m=1;m<x;m+=1){const H=r.indexOf(`
2
2
  `,u);if(H<0)return u;u=H+1}return u}function os({cwd:r,onClose:x,onAddToPrompt:u,openRequest:m}){const H=s.useRef(null),oe=s.useRef(null),ce=s.useRef(null),S=s.useRef(null),[J,Qe]=s.useState(_t),Ce=s.useRef(J),[K,Je]=s.useState(""),[Ne,Se]=s.useState([]),[Ze,ke]=s.useState(!0),[_e,Ee]=s.useState(null),[de,et]=s.useState(0),[De,tt]=s.useState(!1),[st,nt]=s.useState(0),ue=s.useRef(!1),[a,Re]=s.useState(null),[f,k]=s.useState(""),[at,O]=s.useState(""),[b,W]=s.useState(null),[it,Fe]=s.useState(0),[E,Te]=s.useState(!1),[D,Le]=s.useState(!1),[Me,R]=s.useState(null),[lt,F]=s.useState(!1),[p,fe]=s.useState("all"),[o,Ue]=s.useState(null),[Ae,Ie]=s.useState(!1),[rt,ze]=s.useState(null),[c,Z]=s.useState("edit"),[d,_]=s.useState(null),[B,$e]=s.useState(!1),[Pe,he]=s.useState(null),[X,C]=s.useState(null),[v,ee]=s.useState(null),[te,xe]=s.useState(""),[y,V]=s.useState(null),h=a!==null&&f!==at,g=s.useMemo(()=>new Map(((o==null?void 0:o.files)??[]).flatMap(t=>[[t.path,t],...t.originalPath?[[t.originalPath,t]]:[]])),[o==null?void 0:o.files]),T=s.useCallback(async()=>{Ie(!0),ze(null);try{const t=await Y(`/api/git-status?cwd=${encodeURIComponent(r)}`);if(!t.ok)throw new Error(await Q(t,"Unable to read git status"));const n=await t.json();Ue(n),n.isRepository||fe("all")}catch(t){Ue(null),fe("all"),ze(t instanceof Error?t.message:"Unable to read git status")}finally{Ie(!1)}},[r]);s.useEffect(()=>{T()},[T]),s.useEffect(()=>{const t=new AbortController,n=window.setTimeout(async()=>{ke(!0),Ee(null);const i=ue.current;ue.current=!1;try{const l=await Y(`/api/project-files?cwd=${encodeURIComponent(r)}&q=${encodeURIComponent(K)}&limit=100${i?"&refresh=1":""}`,{signal:t.signal});if(!l.ok)throw new Error(await Q(l,"Unable to list project files"));const j=await l.json();if(t.signal.aborted)return;const U=vt(j),ie=j.totalMatches;Se(U),et(typeof ie=="number"?ie:U.length),tt(j.scanLimited===!0)}catch(l){t.signal.aborted||(Se([]),Ee(l instanceof Error?l.message:"Unable to list project files"))}finally{t.signal.aborted||ke(!1)}},120);return()=>{window.clearTimeout(n),t.abort()}},[r,K,st]),s.useEffect(()=>{Re(null),k(""),O(""),W(null),R(null),C(null),Z("edit"),_(null),he(null),V(null)},[r]),s.useEffect(()=>{if(!h)return;const t=n=>n.preventDefault();return window.addEventListener("beforeunload",t),()=>window.removeEventListener("beforeunload",t)},[h]);const ot=s.useCallback((t,n)=>{const i=oe.current;if(!i)return;if(!n||n<1){i.focus();return}const l=ts(t,n);i.blur(),i.setSelectionRange(l,l),i.focus()},[]);s.useEffect(()=>{const t=ce.current;!t||!oe.current||(ce.current=null,ot(t.text,t.line))});const L=s.useCallback(async(t,n)=>{Te(!0),R(null),F(!1),C(null);try{const i=await Y(`/api/project-file?cwd=${encodeURIComponent(r)}&path=${encodeURIComponent(t)}`);if(!i.ok)throw new Error(await Q(i,"Unable to open file"));const l=await i.json();k(l.content),O(l.content),W(l.mtimeMs),Fe(l.size),ce.current={text:l.content,line:n}}catch(i){k(""),O(""),W(null),R(i instanceof Error?i.message:"Unable to open file")}finally{Te(!1)}},[r]),M=s.useCallback(async(t,n)=>{$e(!0),he(null),_(null);try{const i=n?`&originalPath=${encodeURIComponent(n)}`:"",l=await Y(`/api/git-diff?cwd=${encodeURIComponent(r)}&path=${encodeURIComponent(t)}${i}`);if(!l.ok)throw new Error(await Q(l,"Unable to diff file"));_(await l.json())}catch(i){he(i instanceof Error?i.message:"Unable to diff file")}finally{$e(!1)}},[r]),se=s.useCallback(({path:t,mode:n,line:i})=>{var l;if(Re(t),Z(n),n==="edit"){L(t,i);return}k(""),O(""),W(null),R(null),F(!1),C(null),M(t,(l=g.get(t))==null?void 0:l.originalPath)},[g,M,L]),ne=s.useCallback(t=>{if(h){V({type:"file",target:t});return}se(t)},[h,se]),ct=s.useCallback(t=>{if(t===a)return;const n=p==="changes"&&g.has(t)?"diff":"edit";ne({path:t,mode:n})},[g,p,ne,a]),Ge=s.useRef(0);s.useEffect(()=>{!m||m.token===Ge.current||(Ge.current=m.token,ne({path:m.file,mode:m.mode,line:m.line}))},[m,ne]);const dt=s.useCallback(()=>{var t;!a||c==="diff"||(Z("diff"),(d==null?void 0:d.path)!==a&&!B&&M(a,(t=g.get(a))==null?void 0:t.originalPath))},[g,d==null?void 0:d.path,B,M,a,c]),ut=s.useCallback(()=>{!a||c==="edit"||(Z("edit"),b===null&&!E&&L(a))},[E,L,b,a,c]),me=s.useCallback(()=>{var t;if(a){if(c==="diff"){M(a,(t=g.get(a))==null?void 0:t.originalPath);return}L(a)}},[g,M,L,a,c]),ft=s.useCallback(()=>{ue.current=!0,nt(t=>t+1),T(),c==="diff"&&me()},[T,me,c]),pe=s.useCallback(async()=>{if(!(!a||b===null||!h||D)){Le(!0),R(null),F(!1);try{const t=await Y("/api/project-file",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:r,path:a,content:f,expectedMtimeMs:b})});if(!t.ok)throw new Error(await Q(t,"Unable to save file"));const n=await t.json();O(f),W(n.mtimeMs),Fe(n.size),F(!0),_(null),T()}catch(t){R(t instanceof Error?t.message:"Unable to save file")}finally{Le(!1)}}},[f,r,h,T,b,D,a]);s.useEffect(()=>{function t(n){var i;(i=H.current)!=null&&i.contains(document.activeElement)&&Bt("projectFileSave",n)&&(n.preventDefault(),pe())}return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[pe]);const ht=s.useCallback(()=>{if(h){V({type:"close"});return}x()},[h,x]),xt=s.useCallback(()=>{if(!y)return;const t=y;if(V(null),t.type==="file"){se(t.target);return}x()},[x,se,y]),mt=s.useCallback(t=>{if(t.key!=="Tab")return;t.preventDefault();const n=t.currentTarget,i=n.selectionStart,l=n.selectionEnd,j=`${f.slice(0,i)} ${f.slice(l)}`;k(j),F(!1),C(null),requestAnimationFrame(()=>{n.selectionStart=i+2,n.selectionEnd=i+2})},[f]),pt=s.useCallback(t=>{const n=t.currentTarget;if(n.selectionStart===n.selectionEnd){C(null);return}const i=f.slice(n.selectionStart,n.selectionEnd),l=f.slice(0,n.selectionStart).split(`
3
3
  `).length,j=l+i.split(`
4
4
  `).length-1;C({text:i,startLine:l,endLine:j})},[f]),gt=s.useCallback(t=>{t.preventDefault(),S.current={startX:t.clientX,startWidth:J},t.currentTarget.setPointerCapture(t.pointerId)},[J]),jt=s.useCallback(t=>{if(!S.current)return;const n=Math.max(we,window.innerWidth*.9),i=S.current.startWidth+(S.current.startX-t.clientX),l=Math.min(n,Math.max(we,i));Ce.current=l,Qe(l)},[]),He=s.useCallback(()=>{if(S.current){S.current=null;try{localStorage.setItem(qe,String(Ce.current))}catch{}}},[]),ge=s.useMemo(()=>(a==null?void 0:a.split("/").at(-1))??null,[a]),ae=a?g.get(a):void 0,je=s.useMemo(()=>d&&!d.binary&&!d.tooLarge?yt(d.original??"",d.current??""):null,[d]),N=s.useMemo(()=>{if(p==="all")return Ne;const t=K.trim().toLowerCase();return((o==null?void 0:o.files)??[]).map(n=>n.path).filter((n,i,l)=>l.indexOf(n)===i).filter(n=>!t||n.toLowerCase().includes(t)).sort((n,i)=>n.localeCompare(i))},[p,Ne,o==null?void 0:o.files,K]),Ke=s.useMemo(()=>a&&!N.includes(a)?[a,...N]:N,[N,a]),bt=p==="changes"?Ae:Ze,Oe=p==="changes"?rt:_e,We=Ae;return e.jsxs("aside",{ref:H,"aria-label":"Project files",className:"view-transition-right-panel panel-enter-right relative flex min-h-0 shrink-0 flex-col border-l bg-background",style:{width:J},children:[e.jsx("div",{"aria-hidden":"true",className:"absolute inset-y-0 left-0 w-1 cursor-col-resize hover:bg-accent",onPointerDown:gt,onPointerMove:jt,onPointerUp:He,onPointerCancel:He}),e.jsxs("div",{className:"flex h-10 shrink-0 items-center gap-2 px-3",children:[e.jsx(Xe,{"data-icon":"inline-start","aria-hidden":"true",className:"size-4 text-muted-foreground"}),e.jsx("h2",{className:"text-sm font-medium",children:"Project files"}),e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-xs text-muted-foreground",title:r,children:r}),e.jsx(w,{variant:"ghost",size:"icon-sm",onClick:ht,"aria-label":"Close project files",children:e.jsx(Vt,{"data-icon":"inline-start"})})]}),e.jsx(q,{}),(o==null?void 0:o.isRepository)&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex h-8 shrink-0 items-center gap-2 px-3 text-xs text-muted-foreground",children:[e.jsx(Yt,{"data-icon":"inline-start","aria-hidden":"true",className:"size-3.5"}),e.jsx("span",{className:"max-w-40 truncate font-mono text-foreground",title:o.branch??"Detached HEAD",children:o.branch??"detached HEAD"}),o.upstream&&e.jsxs("span",{className:"truncate",children:["tracks ",o.upstream]}),(o.ahead??0)>0&&e.jsxs(A,{variant:"outline",children:["↑ ",o.ahead]}),(o.behind??0)>0&&e.jsxs(A,{variant:"outline",children:["↓ ",o.behind]}),e.jsx("span",{className:"flex-1"}),e.jsxs("span",{children:[o.files.length," changed"]})]}),e.jsx(q,{})]}),e.jsxs("div",{className:"flex min-h-0 flex-1",children:[e.jsxs("section",{"aria-label":"File browser",className:"flex w-56 shrink-0 flex-col",children:[e.jsxs("div",{className:"flex flex-col gap-2 p-2",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsxs(wt,{className:"min-w-0 flex-1",children:[e.jsx(Ct,{children:e.jsx(qt,{"data-icon":"inline-start"})}),e.jsx(Nt,{"aria-label":"Search project files",value:K,onChange:t=>Je(t.target.value),placeholder:"Filter files…",spellCheck:!1})]}),e.jsx(w,{variant:"ghost",size:"icon-sm",disabled:We,onClick:ft,"aria-label":"Refresh files and git status",title:"Refresh files and git status",children:e.jsx(Ve,{"data-icon":"inline-start",className:We?"animate-spin":void 0})})]}),(o==null?void 0:o.isRepository)&&e.jsxs(Be,{"aria-label":"File scope",value:[p],onValueChange:t=>{const n=t[0];(n==="all"||n==="changes")&&fe(n)},variant:"outline",size:"sm",spacing:0,className:"w-full",children:[e.jsx(le,{value:"all",className:"flex-1",children:"All files"}),e.jsx(le,{value:"changes",className:"flex-1",children:"Changes"})]})]}),e.jsx(q,{}),e.jsx(St,{className:"min-h-0 flex-1",children:bt?e.jsxs("div",{className:"flex items-center justify-center gap-2 p-6 text-xs text-muted-foreground",role:"status",children:[e.jsx(re,{}),"Loading files…"]}):Oe?e.jsx(I,{className:"min-h-48 rounded-none p-4",children:e.jsxs(z,{children:[e.jsx($,{variant:"icon",children:e.jsx(be,{})}),e.jsx(P,{children:"Could not load files"}),e.jsx(G,{children:Oe})]})}):Ke.length===0?e.jsx(I,{className:"min-h-48 rounded-none p-4",children:e.jsxs(z,{children:[e.jsx($,{variant:"icon",children:e.jsx(Xe,{})}),e.jsx(P,{children:p==="changes"?"No working-tree changes":"No matching files"}),e.jsx(G,{children:p==="changes"?"This project has no changed files matching the filter.":"Try a different path or filename."})]})}):e.jsxs("div",{className:"flex flex-col py-1",children:[Ke.map(t=>{const n=t.split("/").at(-1)??t,i=t.includes("/")?t.slice(0,t.lastIndexOf("/")):"",l=g.get(t),j=l?`${l.indexStatus}${l.workTreeStatus}`.trim()||"?":null,U=l?ye(l):null,ie=kt(t);return e.jsxs(w,{variant:a===t?"secondary":"ghost",size:"sm",className:"h-auto w-full justify-start rounded-none px-2 py-1.5 text-left",onClick:()=>ct(t),title:t,children:[e.jsx(ie,{"data-icon":"inline-start",className:"text-muted-foreground"}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-xs",children:n}),i&&e.jsx("span",{className:"block truncate font-mono text-xs text-muted-foreground",children:i})]}),j&&U&&e.jsx(A,{variant:"outline",className:Et("font-mono",U.className),title:U.label,children:j})]},t)}),p==="all"&&(de>N.length||De)&&e.jsxs("p",{className:"px-3 py-2 text-xs text-muted-foreground",children:[de>N.length&&`Showing ${N.length} of ${de} matches. Type to narrow the list. `,De&&"This project is too large to scan completely."]})]})})]}),e.jsx(q,{orientation:"vertical"}),e.jsx("section",{"aria-label":"File editor",className:"flex min-w-0 flex-1 flex-col",children:a?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex h-10 shrink-0 items-center gap-2 px-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-xs font-medium",title:a,children:ge}),e.jsx("p",{className:"truncate font-mono text-xs text-muted-foreground",children:a})]}),(ae||c==="diff")&&e.jsxs(Be,{"aria-label":"File view",value:[c],onValueChange:t=>{t[0]==="diff"?dt():t[0]==="edit"&&ut()},variant:"outline",size:"sm",spacing:0,children:[e.jsx(le,{value:"diff",children:"Diff"}),e.jsx(le,{value:"edit",children:"Edit"})]}),c==="diff"&&ae&&e.jsx(A,{variant:"outline",className:ye(ae).className,children:ye(ae).label}),c==="diff"&&je&&e.jsx(Dt,{add:je.add,del:je.del}),c==="edit"&&h&&e.jsx(A,{variant:"outline",children:"Unsaved"}),c==="edit"&&!h&&lt&&e.jsx(A,{variant:"secondary",children:"Saved"}),c==="edit"&&b!==null&&e.jsx("span",{className:"text-xs text-muted-foreground",children:es(it)}),u&&e.jsxs(w,{variant:"outline",size:"sm",disabled:c==="diff"?B||d===null:E||b===null,onClick:()=>{X?(xe(""),ee(X)):u({path:a})},"aria-label":X?"Add selected lines to prompt":"Reference file in prompt",title:X?"Add selected lines to prompt":"Reference file in prompt",children:[e.jsx(Ye,{"data-icon":"inline-start"}),X?"Add selection":"Reference"]}),e.jsx(w,{variant:"ghost",size:"icon-sm",disabled:c==="diff"?B:E||D,onClick:me,"aria-label":c==="diff"?"Reload diff":"Reload file",title:c==="diff"?"Reload diff":"Reload file",children:e.jsx(Ve,{"data-icon":"inline-start"})}),c==="edit"&&e.jsxs(w,{size:"sm",disabled:!h||E||D||b===null,onClick:()=>void pe(),children:[D?e.jsx(re,{"data-icon":"inline-start"}):e.jsx(Qt,{"data-icon":"inline-start"}),D?"Saving…":"Save"]})]}),e.jsx(q,{}),c==="edit"&&Me&&e.jsxs("div",{role:"alert",className:"flex items-center gap-2 px-3 py-2 text-xs text-destructive",children:[e.jsx(be,{"data-icon":"inline-start","aria-hidden":"true",className:"size-4 shrink-0"}),e.jsx("span",{children:Me})]}),c==="diff"?e.jsx("div",{className:"flex min-h-0 flex-1 flex-col",children:B?e.jsxs("div",{className:"flex size-full items-center justify-center gap-2 text-xs text-muted-foreground",role:"status",children:[e.jsx(re,{}),"Loading diff…"]}):Pe?e.jsx(I,{className:"rounded-none",children:e.jsxs(z,{children:[e.jsx($,{variant:"icon",children:e.jsx(be,{})}),e.jsx(P,{children:"Could not diff this file"}),e.jsx(G,{children:Pe})]})}):d===null?null:d.binary||d.tooLarge?e.jsx(I,{className:"rounded-none",children:e.jsxs(z,{children:[e.jsx($,{variant:"icon",children:e.jsx(ve,{})}),e.jsx(P,{children:d.binary?"Binary file":"File is too large to diff"}),e.jsx(G,{children:d.binary?"Git tracks this change, but there is no text diff to show.":"Review this change in your editor instead."})]})}):d.original===d.current?e.jsx(I,{className:"rounded-none",children:e.jsxs(z,{children:[e.jsx($,{variant:"icon",children:e.jsx(ve,{})}),e.jsx(P,{children:"No content changes"}),e.jsx(G,{children:"This file matches the last commit — only its mode or index entry differs."})]})}):e.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:e.jsx(Rt,{oldString:d.original??"",newString:d.current??"",filePath:a,compact:!1,hideHeader:!0})})}):e.jsx("div",{className:"flex min-h-0 flex-1 flex-col",children:E?e.jsxs("div",{className:"flex size-full items-center justify-center gap-2 text-xs text-muted-foreground",role:"status",children:[e.jsx(re,{}),"Opening file…"]}):b!==null?e.jsx(Xt,{textareaRef:oe,ariaLabel:`Editing ${a}`,filePath:a,value:f,readOnly:!1,onChange:t=>{k(t),F(!1),C(null)},onKeyDown:mt,onSelect:pt}):null})]}):e.jsx(I,{className:"rounded-none",children:e.jsxs(z,{children:[e.jsx($,{variant:"icon",children:e.jsx(ve,{})}),e.jsx(P,{children:"Select a file"}),e.jsx(G,{children:"Browse or filter project files, then open one to inspect and edit it."})]})})})]}),e.jsx(Ft,{open:v!==null,onOpenChange:t=>{t||ee(null)},children:e.jsxs(Tt,{children:[e.jsxs(Lt,{children:[e.jsx(Mt,{children:"Comment on selected lines"}),e.jsxs(Ut,{children:["Add a review instruction for ",a," lines ",v==null?void 0:v.startLine,"-",v==null?void 0:v.endLine,"."]})]}),e.jsxs("form",{className:"flex flex-col gap-4",onSubmit:t=>{t.preventDefault();const n=te.trim();!a||!v||!n||!u||(u({path:a,...v,comment:n}),ee(null),xe(""))},children:[e.jsx(At,{autoFocus:!0,"aria-label":"Review comment",value:te,onChange:t=>xe(t.target.value),placeholder:"Describe the change you want…",onKeyDown:t=>{var n;(t.metaKey||t.ctrlKey)&&t.key==="Enter"&&te.trim()&&(t.preventDefault(),(n=t.currentTarget.form)==null||n.requestSubmit())}}),e.jsxs(It,{children:[e.jsx(w,{type:"button",variant:"outline",onClick:()=>ee(null),children:"Cancel"}),e.jsxs(w,{type:"submit",disabled:!te.trim(),children:[e.jsx(Ye,{"data-icon":"inline-start"}),"Add to prompt"]})]})]})]})}),e.jsx(zt,{open:y!==null,onOpenChange:t=>{t||V(null)},children:e.jsxs($t,{size:"sm",children:[e.jsxs(Pt,{children:[e.jsx(Gt,{children:"Discard unsaved changes?"}),e.jsx(Ht,{children:(y==null?void 0:y.type)==="file"?`Your edits to ${ge??"this file"} will be lost when you open ${y.target.path}.`:`Your edits to ${ge??"this file"} will be lost when you close the file workspace.`})]}),e.jsxs(Kt,{children:[e.jsx(Ot,{size:"sm",children:"Keep editing"}),e.jsx(Wt,{variant:"destructive",size:"sm",onClick:xt,children:"Discard changes"})]})]})})]})}export{os as ProjectFilesPanel};