@openchamber/web 1.11.1 → 1.11.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/dist/assets/{JsonTreeView-bLRkNPS9.js → JsonTreeView-9F0tH9yA.js} +1 -1
  2. package/dist/assets/{MarkdownRendererImpl-FSTq-eVA.js → MarkdownRendererImpl-C3QofAGm.js} +1 -1
  3. package/dist/assets/{MultiRunWindow-DezP_Pyy.js → MultiRunWindow-wnUGv0Dl.js} +1 -1
  4. package/dist/assets/{OnboardingScreen-CeZMVgH8.js → OnboardingScreen-17dAs0NH.js} +2 -2
  5. package/dist/assets/{SettingsWindow-Dlfk0yzA.js → SettingsWindow-BgyVY5gz.js} +1 -1
  6. package/dist/assets/TerminalView-D11XIZuz.js +1 -0
  7. package/dist/assets/{ToolOutputDialog-CePopKV7.js → ToolOutputDialog-DFG7ANVw.js} +6 -6
  8. package/dist/assets/es-Chl2Hu6K.js +15 -0
  9. package/dist/assets/index-0bVkxg-Z.css +1 -0
  10. package/dist/assets/{index-CKlDk4Io.js → index-BV2XTsJJ.js} +1 -1
  11. package/dist/assets/ko-BSrH3F9n.js +15 -0
  12. package/dist/assets/{main-BvaFBcXN.js → main-BHkNwOz1.js} +2 -2
  13. package/dist/assets/main-Bqf4fXgq.js +225 -0
  14. package/dist/assets/miniChat-BmB-E5xo.js +2 -0
  15. package/dist/assets/{modelPrefsAutoSave-HUPrH1r2.js → modelPrefsAutoSave-2uwW8uD9.js} +98 -96
  16. package/dist/assets/pl-YlGvPmFg.js +15 -0
  17. package/dist/assets/pt-BR-BonIMDN_.js +15 -0
  18. package/dist/assets/{renderElectronMiniChatApp-EXGwfTjq.js → renderElectronMiniChatApp-B_qrXCU2.js} +2 -2
  19. package/dist/assets/uk-lPqA3MHn.js +15 -0
  20. package/dist/assets/{vendor-.bun-BFTPeDgG.js → vendor-.bun-Boz6Tqcq.js} +20 -20
  21. package/dist/assets/zh-CN-C5nQQsUL.js +15 -0
  22. package/dist/index.html +4 -4
  23. package/dist/mini-chat.html +4 -4
  24. package/package.json +1 -1
  25. package/server/lib/git/DOCUMENTATION.md +1 -0
  26. package/server/lib/git/routes.js +26 -0
  27. package/server/lib/git/service.js +96 -10
  28. package/server/lib/git/service.test.js +39 -0
  29. package/server/lib/opencode/settings-helpers.js +10 -1
  30. package/server/lib/opencode/settings-helpers.test.js +35 -0
  31. package/server/lib/opencode/skill-routes.js +43 -49
  32. package/server/lib/opencode/skills.js +78 -10
  33. package/dist/assets/TerminalView-CdCfCaFq.js +0 -1
  34. package/dist/assets/es-CyjenLd8.js +0 -15
  35. package/dist/assets/index-NnYXwoao.css +0 -1
  36. package/dist/assets/ko-Cs7yF9Jn.js +0 -15
  37. package/dist/assets/main-DcpUnRRo.js +0 -225
  38. package/dist/assets/miniChat-Dmzb8Mwv.js +0 -2
  39. package/dist/assets/pl-XjTt7Hsk.js +0 -15
  40. package/dist/assets/pt-BR-knvpJ94d.js +0 -15
  41. package/dist/assets/uk-DUPvcQAj.js +0 -15
  42. package/dist/assets/zh-CN-DWiTG93s.js +0 -15
@@ -69,6 +69,14 @@ function getClaudeSkillPath(workingDirectory, skillName) {
69
69
  return path.join(getClaudeSkillDir(workingDirectory, skillName), 'SKILL.md');
70
70
  }
71
71
 
72
+ function getUserClaudeSkillDir(skillName) {
73
+ return path.join(os.homedir(), '.claude', 'skills', skillName);
74
+ }
75
+
76
+ function getUserClaudeSkillPath(skillName) {
77
+ return path.join(getUserClaudeSkillDir(skillName), 'SKILL.md');
78
+ }
79
+
72
80
  function getUserAgentsSkillDir(skillName) {
73
81
  return path.join(os.homedir(), '.agents', 'skills', skillName);
74
82
  }
@@ -107,6 +115,16 @@ function getSkillScope(skillName, workingDirectory) {
107
115
  if (fs.existsSync(userPath)) {
108
116
  return { scope: SKILL_SCOPE.USER, path: userPath, source: 'opencode' };
109
117
  }
118
+
119
+ const userClaudePath = getUserClaudeSkillPath(skillName);
120
+ if (fs.existsSync(userClaudePath)) {
121
+ return { scope: SKILL_SCOPE.USER, path: userClaudePath, source: 'claude' };
122
+ }
123
+
124
+ const userAgentsPath = getUserAgentsSkillPath(skillName);
125
+ if (fs.existsSync(userAgentsPath)) {
126
+ return { scope: SKILL_SCOPE.USER, path: userAgentsPath, source: 'agents' };
127
+ }
110
128
 
111
129
  return { scope: null, path: null, source: null };
112
130
  }
@@ -226,11 +244,18 @@ function getSkillSources(skillName, workingDirectory, discoveredSkill = null) {
226
244
  const claudePath = workingDirectory ? getClaudeSkillPath(workingDirectory, skillName) : null;
227
245
  const claudeExists = claudePath && fs.existsSync(claudePath);
228
246
  const claudeDir = claudeExists ? path.dirname(claudePath) : null;
247
+ const userClaudePath = getUserClaudeSkillPath(skillName);
248
+ const userClaudeExists = fs.existsSync(userClaudePath);
249
+ const userClaudeDir = userClaudeExists ? path.dirname(userClaudePath) : null;
229
250
 
230
251
  const userPath = getUserSkillPath(skillName);
231
252
  const userExists = fs.existsSync(userPath);
232
253
  const userDir = userExists ? path.dirname(userPath) : null;
233
254
 
255
+ const userAgentsPath = getUserAgentsSkillPath(skillName);
256
+ const userAgentsExists = fs.existsSync(userAgentsPath);
257
+ const userAgentsDir = userAgentsExists ? path.dirname(userAgentsPath) : null;
258
+
234
259
  const matchedDiscovered = discoveredSkill && discoveredSkill.name === skillName
235
260
  ? discoveredSkill
236
261
  : discoverSkills(workingDirectory).find((skill) => skill.name === skillName);
@@ -240,7 +265,12 @@ function getSkillSources(skillName, workingDirectory, discoveredSkill = null) {
240
265
  let mdSource = null;
241
266
  let mdDir = null;
242
267
 
243
- if (projectExists) {
268
+ if (matchedDiscovered?.path) {
269
+ mdPath = matchedDiscovered.path;
270
+ mdScope = matchedDiscovered.scope || null;
271
+ mdSource = matchedDiscovered.source || null;
272
+ mdDir = path.dirname(matchedDiscovered.path);
273
+ } else if (projectExists) {
244
274
  mdPath = projectPath;
245
275
  mdScope = SKILL_SCOPE.PROJECT;
246
276
  mdSource = 'opencode';
@@ -255,14 +285,23 @@ function getSkillSources(skillName, workingDirectory, discoveredSkill = null) {
255
285
  mdScope = SKILL_SCOPE.USER;
256
286
  mdSource = 'opencode';
257
287
  mdDir = userDir;
258
- } else if (matchedDiscovered?.path) {
259
- mdPath = matchedDiscovered.path;
260
- mdScope = matchedDiscovered.scope || null;
261
- mdSource = matchedDiscovered.source || null;
262
- mdDir = path.dirname(matchedDiscovered.path);
288
+ } else if (userClaudeExists) {
289
+ mdPath = userClaudePath;
290
+ mdScope = SKILL_SCOPE.USER;
291
+ mdSource = 'claude';
292
+ mdDir = userClaudeDir;
293
+ } else if (userAgentsExists) {
294
+ mdPath = userAgentsPath;
295
+ mdScope = SKILL_SCOPE.USER;
296
+ mdSource = 'agents';
297
+ mdDir = userAgentsDir;
263
298
  }
264
299
 
265
- const mdExists = !!mdPath;
300
+ const mdExists = !!mdPath && fs.existsSync(mdPath);
301
+ if (!mdExists) {
302
+ mdPath = null;
303
+ mdDir = null;
304
+ }
266
305
 
267
306
  const sources = {
268
307
  md: {
@@ -288,6 +327,16 @@ function getSkillSources(skillName, workingDirectory, discoveredSkill = null) {
288
327
  exists: userExists,
289
328
  path: userPath,
290
329
  dir: userDir
330
+ },
331
+ userClaudeMd: {
332
+ exists: userClaudeExists,
333
+ path: userClaudePath,
334
+ dir: userClaudeDir
335
+ },
336
+ userAgentsMd: {
337
+ exists: userAgentsExists,
338
+ path: userAgentsPath,
339
+ dir: userAgentsDir
291
340
  }
292
341
  };
293
342
 
@@ -374,22 +423,34 @@ function createSkill(skillName, config, workingDirectory, scope) {
374
423
  console.log(`Created new skill: ${skillName} (scope: ${targetScope}, path: ${targetPath})`);
375
424
  }
376
425
 
377
- function updateSkill(skillName, updates, workingDirectory) {
426
+ function updateSkill(skillName, updates, workingDirectory, targetPath = null) {
378
427
  ensureDirs();
379
428
 
380
- const existing = getSkillScope(skillName, workingDirectory);
429
+ const requestedPath = typeof targetPath === 'string' && targetPath.trim()
430
+ ? path.resolve(targetPath.trim())
431
+ : null;
432
+ const existing = requestedPath && fs.existsSync(requestedPath)
433
+ ? { scope: null, path: requestedPath, source: null }
434
+ : getSkillScope(skillName, workingDirectory);
381
435
  if (!existing.path) {
382
436
  throw new Error(`Skill "${skillName}" not found`);
383
437
  }
438
+ if (path.basename(existing.path) !== 'SKILL.md') {
439
+ throw new Error(`Skill "${skillName}" target must be a SKILL.md file`);
440
+ }
384
441
 
385
442
  const mdPath = existing.path;
386
443
  const mdDir = path.dirname(mdPath);
387
444
  const mdData = parseMdFile(mdPath);
445
+ const frontmatterName = typeof mdData.frontmatter?.name === 'string' ? mdData.frontmatter.name : skillName;
446
+ if (frontmatterName !== skillName) {
447
+ throw new Error(`Skill "${skillName}" does not match ${mdPath}`);
448
+ }
388
449
 
389
450
  let mdModified = false;
390
451
 
391
452
  for (const [field, value] of Object.entries(updates)) {
392
- if (field === 'scope') {
453
+ if (field === 'scope' || field === 'source' || field === 'targetPath') {
393
454
  continue;
394
455
  }
395
456
 
@@ -464,6 +525,13 @@ function deleteSkill(skillName, workingDirectory) {
464
525
  deleted = true;
465
526
  }
466
527
 
528
+ const userClaudeDir = getUserClaudeSkillDir(skillName);
529
+ if (fs.existsSync(userClaudeDir)) {
530
+ fs.rmSync(userClaudeDir, { recursive: true, force: true });
531
+ console.log(`Deleted user-level claude skill directory: ${userClaudeDir}`);
532
+ deleted = true;
533
+ }
534
+
467
535
  if (!deleted) {
468
536
  throw new Error(`Skill "${skillName}" not found`);
469
537
  }
@@ -1 +0,0 @@
1
- import{R as n,j as a,s as yt,bv as ht,bw as bt,bx as gt}from"./vendor-.bun-BFTPeDgG.js";import{u as dt,v as xt,a_ as vt,c as Ue,M as Tt,bF as kt,eM as Ct,a as Ie,b as Et,V as ft,b8 as Rt,I as ie,eN as et,ct,at as Z}from"./modelPrefsAutoSave-HUPrH1r2.js";import{u as J,P as At,S as St}from"./main-DcpUnRRo.js";import{a3 as It}from"./index-CKlDk4Io.js";import"./JsonTreeView-bLRkNPS9.js";function Mt(f){const{colors:p}=f,m=p.syntax.base;return{background:p.surface.background,foreground:m.foreground,cursor:p.interactive.cursor,cursorAccent:p.surface.background,selectionBackground:p.interactive.selection,selectionForeground:p.interactive.selectionForeground,selectionInactiveBackground:p.interactive.selection+"50",black:p.surface.muted,red:p.status.error,green:p.status.success,yellow:p.status.warning,blue:m.function,magenta:m.keyword,cyan:m.type,white:m.foreground,brightBlack:m.comment,brightRed:p.status.error,brightGreen:p.status.success,brightYellow:p.status.warning,brightBlue:m.function,brightMagenta:m.keyword,brightCyan:m.type,brightWhite:p.surface.elevatedForeground}}function Bt(f,p,m,ee,de=!1){const ye=`${f}, "JetBrainsMonoNL Nerd Font", "FiraCode Nerd Font", "Cascadia Code PL", "Fira Code", "JetBrains Mono", "SFMono-Regular", Menlo, Consolas, "Liberation Mono", "Courier New", monospace`;return{cursorBlink:!1,cursorStyle:"bar",fontSize:p,lineHeight:1.15,fontFamily:ye,allowTransparency:!1,theme:{background:m.background,foreground:m.foreground,cursor:m.cursor,cursorAccent:m.cursorAccent,selectionBackground:m.selectionBackground,selectionForeground:m.selectionForeground,black:m.black,red:m.red,green:m.green,yellow:m.yellow,blue:m.blue,magenta:m.magenta,cyan:m.cyan,white:m.white,brightBlack:m.brightBlack,brightRed:m.brightRed,brightGreen:m.brightGreen,brightYellow:m.brightYellow,brightBlue:m.brightBlue,brightMagenta:m.brightMagenta,brightCyan:m.brightCyan,brightWhite:m.brightWhite},scrollback:1e4,ghostty:ee,disableStdin:de}}let lt=null;function Dt(){return lt||(lt=gt.load()),lt}function Nt(f){if(typeof window>"u")return null;const p=[f,...Array.from(f.querySelectorAll("*"))];let m=null;for(const ee of p){const Me=window.getComputedStyle(ee).overflowY;if(!(Me!=="auto"&&Me!=="scroll")){if(ee.scrollHeight-ee.clientHeight>2)return ee;m||(m=ee)}}return m}const pt=n.forwardRef(({sessionKey:f,chunks:p,onInput:m,onResize:ee,theme:de,fontFamily:Me,fontSize:ye,className:Be,enableTouchScroll:E,autoFocus:tt=!0,isVisible:je=!0},he)=>{const{t:F}=dt(),N=n.useRef(null),Fe=n.useRef(null),I=n.useRef(null),_e=n.useRef(null),P=n.useRef(m),ze=n.useRef(ee),h=n.useRef(null),be=n.useRef(""),te=n.useRef(null),Le=n.useRef(!1),Ke=n.useRef(null),pe=n.useRef(!0),ne=n.useRef(null),q=n.useRef(null),ge=n.useRef(0),re=n.useRef(null),qe=n.useRef(null),ce=n.useRef(!1),k=n.useRef(!1),R=n.useRef(null),me=n.useRef(null),Ye=n.useRef(null),j=n.useRef(""),Oe=n.useRef(null),xe=n.useRef(!E),$e=n.useRef(je),[,nt]=n.useReducer(e=>e+1,0),[We,O]=n.useReducer(e=>e+1,0);P.current=m,ze.current=ee;const at=typeof navigator<"u"&&(/Android/i.test(navigator.userAgent)||navigator.userAgentData?.platform==="Android"),y=!!E;n.useEffect(()=>{if(!E){xe.current=!0,$e.current=je;return}!$e.current&&je&&(xe.current=!1),$e.current=je},[E,je]);const ve=n.useCallback(()=>{if(!y)return;const e=N.current,o=re.current;if(!e)return;const s=[];e.getAttribute("contenteditable")==="true"&&s.push(e),s.push(...Array.from(e.querySelectorAll('[contenteditable="true"]'))),s.forEach(r=>{r.setAttribute("data-terminal-disabled-contenteditable","true"),r.setAttribute("contenteditable","false"),r.setAttribute("aria-hidden","true"),r.tabIndex=-1,r.style.setProperty("caret-color","transparent"),r.style.color="transparent",r.style.setProperty("-webkit-text-fill-color","transparent"),r.style.background="transparent",r.style.outline="none",r.style.boxShadow="none",r.style.textShadow="none",r.style.setProperty("user-select","none"),r.style.setProperty("-webkit-user-select","none")}),e.tabIndex=-1,e.removeAttribute("role"),e.removeAttribute("aria-multiline"),Array.from(e.querySelectorAll("textarea")).forEach(r=>{r.style.setProperty("caret-color","transparent"),r.style.color="transparent",r.style.setProperty("-webkit-text-fill-color","transparent"),r.style.background="transparent",r.style.border="0",r.style.outline="none",r.style.boxShadow="none",r.style.textShadow="none",r.style.fontSize="0",r.style.lineHeight="0",r!==o&&r.getAttribute("data-terminal-disabled-input")!=="true"&&(r.setAttribute("data-terminal-disabled-input","true"),r.setAttribute("aria-hidden","true"),r.tabIndex=-1,r.disabled=!0,r.style.position="absolute",r.style.opacity="0",r.style.width="0px",r.style.height="0px",r.style.pointerEvents="none",r.style.zIndex="-1")})},[y]),A=n.useCallback(e=>{if(Oe.current===e)return;const o=I.current;if(o)try{if(typeof o.setOption=="function"){o.setOption("cursorBlink",e),Oe.current=e;return}o.options&&(o.options.cursorBlink=e,Oe.current=e)}catch{}},[]),M=y&&at,C=n.useCallback((e,o)=>{const s=M?qe.current:re.current,c=N.current;if(!s||!c)return;const r=c.getBoundingClientRect(),v=typeof window<"u"?window.innerWidth:r.width,S=typeof window<"u"?window.innerHeight:r.height,D=r.left+r.width/2,G=r.top+r.height-12,l=typeof e=="number"?e:D,T=typeof o=="number"?o:G,V=8,H=Math.max(V,Math.min(v-V,l)),K=Math.max(V,Math.min(S-V,T));s.style.left=`${H}px`,s.style.top=`${K}px`,s.style.bottom="",(s instanceof HTMLTextAreaElement||s instanceof HTMLInputElement)&&(s.disabled=!1,s.readOnly=!1,s.removeAttribute("disabled"),s.removeAttribute("readonly"));try{s.focus({preventScroll:!0})}catch{try{s.focus()}catch{}}},[M]),Te=n.useCallback(()=>{if(y){C(),A(!0);return}I.current?.focus(),A(!0)},[C,A,y]),le=n.useCallback(e=>e instanceof HTMLTextAreaElement||e instanceof HTMLInputElement?e.value:e.textContent??"",[]),W=n.useCallback(e=>{if(e instanceof HTMLTextAreaElement||e instanceof HTMLInputElement){e.value="";return}e.textContent=""},[]),He=n.useCallback(e=>{if(typeof window>"u"||M)return;Ye.current!==null&&(window.clearTimeout(Ye.current),Ye.current=null);let o=0;const s=3,c=()=>{Ye.current=window.setTimeout(()=>{Ye.current=null;const r=le(e);if(!r){if(o+=1,o<s){c();return}return}const v=j.current;j.current=r;const S=r.startsWith(v)?r.slice(v.length):r;S&&P.current(S.replace(/\r\n|\r|\n/g,"\r")),W(e),j.current=""},o===0?0:24)};c()},[W,le,M]);n.useEffect(()=>{const e=N.current;if(!y||!e||E)return;const o=s=>{const c=s.target;if(c&&c.getAttribute("data-terminal-hidden-input")!=="true"&&e.contains(c)){try{c.blur()}catch{}C()}};return e.addEventListener("focusin",o,!0),()=>{e.removeEventListener("focusin",o,!0)}},[E,y,C]);const De=n.useCallback(()=>{const e=I.current;if(!e||typeof e.getSelection!="function")return"";const o=e.getSelection();return typeof o=="string"?o:""},[]),ue=n.useCallback(()=>{if(typeof window>"u")return"";const e=window.getSelection();if(!e)return"";const o=e.toString();if(!o.trim())return"";const s=N.current;if(!s)return"";const c=e.anchorNode,r=e.focusNode;return c&&!s.contains(c)||r&&!s.contains(r)?"":o},[]),ke=n.useCallback(async()=>{if(typeof document>"u")return;const e=De()||ue();e.trim()&&await xt(e)},[ue,De]),X=n.useCallback(()=>De().trim()?!0:!!ue().trim(),[ue,De]);n.useEffect(()=>{if(typeof window>"u")return;const e=o=>{X()&&(o.preventDefault(),ke())};return window.addEventListener("openchamber:copy",e),()=>{window.removeEventListener("openchamber:copy",e)}},[ke,X]);const U=n.useCallback(()=>{be.current="",te.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(te.current),te.current=null,Le.current=!1,Ke.current=null},[]),L=n.useCallback(()=>{const e=_e.current,o=I.current,s=N.current;if(!e||!o||!s)return;const c=s.getBoundingClientRect();if(!(c.width<24||c.height<24))try{e.fit();const r={cols:o.cols,rows:o.rows},v=h.current;(!v||v.cols!==r.cols||v.rows!==r.rows)&&(h.current=r,ze.current(r.cols,r.rows))}catch{}},[]),Ne=n.useCallback(()=>{if(Le.current)return;const e=I.current;if(!e){U();return}if(!be.current)return;const o=be.current;be.current="",Le.current=!0,e.write(o,()=>{Le.current=!1,be.current&&(typeof window<"u"?te.current=window.requestAnimationFrame(()=>{te.current=null,Ne()}):Ne())})},[U]),Ge=n.useCallback(()=>{te.current===null&&(typeof window<"u"?te.current=window.requestAnimationFrame(()=>{te.current=null,Ne()}):Ne())},[Ne]),Xe=n.useCallback(e=>{e&&(be.current+=e,Ge())},[Ge]),Ce=n.useCallback(()=>{if(ne.current?.(),ne.current=null,q.current!==null&&typeof window<"u"&&(window.clearTimeout(q.current),q.current=null),!E){ge.current=0;return}const e=N.current;if(!e)return;const o=I.current;if(!o)return;ge.current=0;const s=2.2,c=2.8,r=25,v=.25,S=8,D=.05,G=.015,l={lastY:null,lastTime:null,velocity:0,rafId:null,startX:null,startY:null,didMove:!1},T=()=>typeof performance<"u"?performance.now():Date.now(),V=Math.max(12,Math.round(ye*1.35));let H=0;const K=t=>{if(!t)return!1;const u=o.getViewportY(),i=H+t,b=Math.trunc(i/V);return H=i-b*V,b!==0&&o.scrollLines(b),o.getViewportY()!==u},Y=()=>{l.rafId!==null&&typeof window<"u"&&window.cancelAnimationFrame(l.rafId),l.rafId=null},x={passive:!1,capture:!1};if(typeof window<"u"&&"PointerEvent"in window){const t=Object.assign(l,{pointerId:null,startX:null,startY:null,moved:!1}),u=6,i=d=>{if(d.pointerType==="touch"){Y(),t.pointerId=d.pointerId,t.startX=d.clientX,t.startY=d.clientY,t.moved=!1,t.lastY=d.clientY,t.lastTime=T(),t.velocity=0;try{e.setPointerCapture(d.pointerId)}catch{}}},b=d=>{if(d.pointerType!=="touch"||t.pointerId!==d.pointerId)return;if(t.startX!==null&&t.startY!==null&&!t.moved){const mt=d.clientX-t.startX,wt=d.clientY-t.startY;Math.hypot(mt,wt)>=u&&(t.moved=!0)}if(t.lastY===null){t.lastY=d.clientY,t.lastTime=T();return}const _=t.lastY,oe=t.lastTime??T(),$=T();t.lastY=d.clientY,t.lastTime=$;const ae=_-d.clientY;if(Math.abs(ae)<1)return;const Se=Math.max($-oe,8),se=s+Math.min(c,Math.abs(ae)/r),Pe=ae*se,Je=Pe/Se;t.velocity=t.velocity*(1-v)+Je*v,t.velocity>S?t.velocity=S:t.velocity<-S&&(t.velocity=-S),t.moved&&(d.cancelable&&d.preventDefault(),d.stopPropagation()),K(Pe)},w=d=>{if(d.pointerType!=="touch"||t.pointerId!==d.pointerId)return;const _=!t.moved;t.pointerId=null,t.startX=null,t.startY=null,t.moved=!1,t.lastY=null,t.lastTime=null;try{e.releasePointerCapture(d.pointerId)}catch{}if(_){y?C(d.clientX,d.clientY):E&&!xe.current&&(xe.current=!0,I.current?.focus());return}if(typeof window>"u")return;if(Math.abs(t.velocity)<D){t.velocity=0;return}let oe=T();const $=()=>{const ae=T(),Se=Math.max(ae-oe,8);oe=ae;const se=K(t.velocity*Se)??!1,Pe=Math.sign(t.velocity),Je=Math.max(0,Math.abs(t.velocity)-G*Se);if(t.velocity=Je*Pe,!se||Je<=D){Y(),t.velocity=0;return}t.rafId=window.requestAnimationFrame($)};t.rafId=window.requestAnimationFrame($)};e.addEventListener("pointerdown",i,x),e.addEventListener("pointermove",b,x),e.addEventListener("pointerup",w,x),e.addEventListener("pointercancel",w,x);const g=e.style.touchAction;e.style.touchAction="manipulation",ne.current=()=>{Y(),q.current!==null&&typeof window<"u"&&(window.clearTimeout(q.current),q.current=null),ge.current=0,e.removeEventListener("pointerdown",i,x),e.removeEventListener("pointermove",b,x),e.removeEventListener("pointerup",w,x),e.removeEventListener("pointercancel",w,x),e.style.touchAction=g};return}const Re=6,z=t=>{t.touches.length===1&&(Y(),l.lastY=t.touches[0].clientY,l.lastTime=T(),l.velocity=0,l.startX=t.touches[0].clientX,l.startY=t.touches[0].clientY,l.didMove=!1)},Ve=t=>{if(t.touches.length!==1){l.lastY=null,l.lastTime=null,l.velocity=0,l.startX=null,l.startY=null,l.didMove=!1,Y();return}const u=t.touches[0].clientX,i=t.touches[0].clientY;if(l.startX!==null&&l.startY!==null&&!l.didMove){const Se=u-l.startX,se=i-l.startY;Math.hypot(Se,se)>=Re&&(l.didMove=!0)}if(l.lastY===null){l.lastY=i,l.lastTime=T();return}const b=l.lastY,w=l.lastTime??T(),g=T();l.lastY=i,l.lastTime=g;const d=b-i;if(Math.abs(d)<1)return;const _=Math.max(g-w,8),oe=s+Math.min(c,Math.abs(d)/r),$=d*oe,ae=$/_;l.velocity=l.velocity*(1-v)+ae*v,l.velocity>S?l.velocity=S:l.velocity<-S&&(l.velocity=-S),l.didMove&&(t.preventDefault(),t.stopPropagation()),K($)},Ae=t=>{const u=!l.didMove;l.lastY=null,l.lastTime=null;const i=l.velocity;if(l.startX=null,l.startY=null,l.didMove=!1,u){const g=t.changedTouches?.[0];y?C(g?.clientX,g?.clientY):E&&!xe.current&&(xe.current=!0,I.current?.focus());return}if(typeof window>"u")return;if(Math.abs(i)<D){l.velocity=0;return}let b=T();const w=()=>{const g=T(),d=Math.max(g-b,8);b=g;const _=K(l.velocity*d)??!1,oe=Math.sign(l.velocity),$=Math.max(0,Math.abs(l.velocity)-G*d);if(l.velocity=$*oe,!_||$<=D){Y(),l.velocity=0;return}l.rafId=window.requestAnimationFrame(w)};l.rafId=window.requestAnimationFrame(w)};e.addEventListener("touchstart",z,x),e.addEventListener("touchmove",Ve,x),e.addEventListener("touchend",Ae,x),e.addEventListener("touchcancel",Ae,x);const Q=e.style.touchAction;e.style.touchAction="manipulation",ne.current=()=>{Y(),q.current!==null&&typeof window<"u"&&(window.clearTimeout(q.current),q.current=null),ge.current=0,e.removeEventListener("touchstart",z,x),e.removeEventListener("touchmove",Ve,x),e.removeEventListener("touchend",Ae,x),e.removeEventListener("touchcancel",Ae,x),e.style.touchAction=Q}},[E,y,C,ye]);n.useEffect(()=>{let e=!1,o=null,s=null,c=null,r=[],v=null,S=null;const D=N.current;if(!D)return;if(D.tabIndex=y?-1:0,y){const Y=D.focus.bind(D),x=D;x.focus=((...B)=>{C()}),S=()=>{x.focus=Y}}const G=()=>{A(!0)},l=()=>{A(!1)},T=Y=>{const x=Y.target;if(x&&D.contains(x)){if(y&&x instanceof HTMLElement){window.setTimeout(()=>{x.blur(),C()},0),A(!1);return}if(E&&!xe.current&&x instanceof HTMLElement){window.setTimeout(()=>{x.blur()},0),A(!1);return}A(!0);return}A(!1)},V=()=>{A(!1)};let H=null;return(async()=>{try{const Y=await Dt();if(e)return;const x=Bt(Me,ye,de,Y,!1),B=new ht(x);pe.current=!0,y&&(B.focus=()=>{});const Re=B;if(typeof Re.scrollToBottom=="function"){const Q=Re.scrollToBottom.bind(Re);Re.scrollToBottom=()=>{pe.current&&Q()},v=()=>{Re.scrollToBottom=Q}}const z=new bt;o=B,I.current=B,_e.current=z,B.loadAddon(z),B.open(D),O(),Oe.current=!1,H=B.textarea??D.querySelector("textarea"),H&&(H.addEventListener("focus",G),H.addEventListener("blur",l)),ve(),typeof MutationObserver<"u"&&(c=new MutationObserver(()=>{ve()}),c.observe(D,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["contenteditable","role","tabindex","aria-label"]}));const Ve=Nt(D);Ve?(Ve.classList.add("overlay-scrollbar-target","overlay-scrollbar-container"),Fe.current=Ve,nt()):Fe.current=null,L();const Ae=z;typeof Ae.observeResize=="function"&&Ae.observeResize(),Ce(),r=[B.onData(Q=>{P.current(Q)}),B.onScroll(Q=>{if(typeof Q=="number"&&Number.isFinite(Q)){const t=typeof B.hasSelection=="function"&&B.hasSelection();pe.current=!t&&Q<=.5}}),B.onSelectionChange(()=>{if(typeof B.hasSelection=="function"&&B.hasSelection()){pe.current=!1;return}const t=typeof B.getViewportY=="function"?B.getViewportY():0;pe.current=t<=.5})],s=new ResizeObserver(()=>{L()}),s.observe(D),typeof window<"u"&&window.setTimeout(()=>{L()},0)}catch{}})(),document.addEventListener("focusin",T,!0),window.addEventListener("blur",V),()=>{e=!0,ne.current?.(),ne.current=null,document.removeEventListener("focusin",T,!0),window.removeEventListener("blur",V),r.forEach(Y=>Y.dispose()),v?.(),v=null,H&&(H.removeEventListener("focus",G),H.removeEventListener("blur",l)),s?.disconnect(),c?.disconnect(),S?.(),o?.dispose(),I.current=null,_e.current=null,Fe.current=null,h.current=null,Oe.current=null,U()}},[ve,E,L,C,Me,ye,Ce,de,U,A,y]),n.useEffect(()=>{const e=I.current;e&&(e.reset(),U(),h.current=null,L())},[f,We,L,U]),n.useEffect(()=>{!tt||!I.current||Te()},[tt,Te,f,We]),n.useEffect(()=>(Ce(),()=>{ne.current?.(),ne.current=null}),[Ce,f]),n.useEffect(()=>{const e=I.current;if(!e)return;if(p.length===0){Ke.current!==null&&(e.reset(),U(),L());return}const o=Ke.current;let s;if(o===null)s=p;else{const c=p.findIndex(r=>r.id===o);s=c>=0?p.slice(c+1):p}s.length>0&&Xe(s.map(c=>c.data).join("")),Ke.current=p[p.length-1].id},[p,We,Xe,L,U]),n.useImperativeHandle(he,()=>({focus:()=>{Te()},clear:()=>{const e=I.current;e&&(e.reset(),U(),L())},fit:()=>{L()}}),[Te,L,U]);const Qe=n.useCallback(e=>{if(!y)return;const o=N.current,s=e.relatedTarget,c=s?.tagName,r=c==="INPUT"||c==="TEXTAREA"||s?.isContentEditable,v=s?.getAttribute("data-terminal-hidden-input")==="true",S=!!(s&&o?.contains(s))},[y]),we=n.useCallback(e=>{const o=e.nativeEvent,s=o?.inputType??"",c=typeof o?.data=="string"?o.data:"";if(me.current=typeof performance<"u"?performance.now():Date.now(),s==="insertCompositionText"){ce.current=!0;return}if(!s&&c){if(ce.current)return;e.preventDefault(),P.current(c),R.current={type:"insertText",at:typeof performance<"u"?performance.now():Date.now()},k.current=!0;return}if(s==="insertText"&&c){if(ce.current)return;e.preventDefault(),P.current(c),R.current={type:s,at:typeof performance<"u"?performance.now():Date.now()},k.current=!0;return}if(s==="insertLineBreak"){if(ce.current)return;e.preventDefault(),P.current("\r"),R.current={type:s,at:typeof performance<"u"?performance.now():Date.now()},k.current=!0;return}if(s==="deleteContentBackward"){if(ce.current)return;e.preventDefault(),P.current(""),R.current={type:s,at:typeof performance<"u"?performance.now():Date.now()},k.current=!0}},[]),fe=n.useCallback(e=>{const o=e.currentTarget;if(me.current=typeof performance<"u"?performance.now():Date.now(),ce.current)return;if(k.current){const r=R.current,v=typeof performance<"u"?performance.now():Date.now();if(r&&v-r.at<50){k.current=!1,W(o);return}k.current=!1}const s=le(o);if(!s)return;j.current=s;const c=s.replace(/\r\n|\r|\n/g,"\r");P.current(c),W(o),j.current=""},[W,le]),rt=n.useCallback(e=>{e.stopPropagation();const o=e.key.toLowerCase(),s=e.metaKey&&!e.ctrlKey&&!e.altKey&&o==="c",c=e.ctrlKey&&e.shiftKey&&!e.metaKey&&!e.altKey&&o==="c";if((s||c)&&X()){e.preventDefault(),ke();return}if(e.ctrlKey&&!e.metaKey&&!e.altKey&&e.key.length===1){const V=e.key.toUpperCase();if(V>="A"&&V<="Z"){e.preventDefault(),e.nativeEvent?.stopImmediatePropagation(),P.current(String.fromCharCode(V.charCodeAt(0)-64)),W(e.currentTarget);return}}if(e.altKey&&!e.ctrlKey&&!e.metaKey&&e.key.length===1){e.preventDefault(),e.nativeEvent?.stopImmediatePropagation(),P.current("\x1B"+e.key),W(e.currentTarget);return}const v={ArrowUp:"\x1B[A",ArrowDown:"\x1B[B",ArrowRight:"\x1B[C",ArrowLeft:"\x1B[D",Escape:"\x1B",Tab:" ",Delete:"\x1B[3~",Home:"\x1B[H",End:"\x1B[F"}[e.key];if(v){e.preventDefault(),P.current(v),W(e.currentTarget);return}const S=e.currentTarget;if(e.nativeEvent?.isComposing)return;const G=R.current,l=typeof performance<"u"?performance.now():Date.now(),T=!!(G&&l-G.at<50);if(e.key==="Enter"){if(T&&G?.type==="insertLineBreak")return;e.preventDefault(),P.current("\r"),W(S);return}if(e.key==="Backspace"){if(e.preventDefault(),T&&G?.type==="deleteContentBackward")return;le(S)||P.current("")}if(e.key.length===1&&!e.ctrlKey&&!e.metaKey&&!e.altKey){const V=me.current;V&&l-V<50||(e.preventDefault(),P.current(e.key),k.current=!0,R.current={type:"keydown-text",at:l})}He(S)},[W,ke,X,le,He]),Ee=n.useCallback(e=>{e.stopPropagation();const o=e.currentTarget;e.nativeEvent?.isComposing||He(o)},[He]),ot=n.useCallback(e=>{const o=e.currentTarget;ce.current=!1;const s=e.data||le(o);if(me.current=typeof performance<"u"?performance.now():Date.now(),!s)return;const c=s.replace(/\r\n|\r|\n/g,"\r");P.current(c),W(o),R.current={type:"compositionend",at:typeof performance<"u"?performance.now():Date.now()},k.current=!0},[W,le]),st=n.useCallback(e=>{e.stopPropagation();const o=e.clipboardData?.getData("text")??"";if(!o)return;e.preventDefault();const c=I.current?.hasBracketedPaste?.()?`\x1B[200~${o}\x1B[201~`:o;P.current(c)},[]),Ze={position:"fixed",left:0,top:0,width:1,height:1,opacity:0,zIndex:-1,background:"transparent",color:"transparent",WebkitTextFillColor:"transparent",caretColor:"transparent",textShadow:"none",WebkitAppearance:"none",appearance:"none",resize:"none",overflow:"hidden",whiteSpace:"nowrap",border:"0",padding:0,margin:0,outline:"none",outlineOffset:0,fontSize:16,fontWeight:400,pointerEvents:"none",WebkitUserSelect:"none",userSelect:"none"};return a.jsxs("div",{ref:N,className:Ue("relative h-full w-full terminal-viewport-container",Be),"data-hidden-input-overlay-active":y?"true":void 0,style:{backgroundColor:de.background},onTouchStart:e=>{if(!(!y||E)&&!X()){const o=e.touches?.[0];C(o?.clientX,o?.clientY)}},onClick:e=>{if(!E)if(y){if(X())return;C(e.clientX,e.clientY)}else I.current?.focus()},onMouseUp:()=>{!E&&X()&&ke()},onTouchEnd:()=>{!E&&X()&&ke()},children:[y&&typeof document<"u"?yt.createPortal(a.jsxs(a.Fragment,{children:[a.jsx("input",{ref:qe,type:"text",inputMode:"text",autoCapitalize:"off",autoComplete:"off",autoCorrect:"off",spellCheck:!1,tabIndex:-1,enterKeyHint:"send","data-terminal-hidden-input":"true","aria-label":F("terminalView.viewport.inputAria"),"aria-hidden":"true",style:{...Ze,display:M?"block":"none"},onBlur:Qe,onBeforeInput:we,onCompositionStart:()=>{ce.current=!0},onInput:fe,onKeyDown:rt,onKeyUp:Ee,onCompositionEnd:ot,onPaste:st}),a.jsx("textarea",{ref:re,inputMode:"text",autoCapitalize:"off",autoComplete:"off",autoCorrect:"off",spellCheck:!1,tabIndex:-1,enterKeyHint:"send","data-terminal-hidden-input":"true","aria-label":F("terminalView.viewport.inputAria"),"aria-hidden":"true",style:{...Ze,display:M?"none":"block"},onBlur:Qe,onBeforeInput:we,onCompositionStart:()=>{ce.current=!0},onInput:fe,onKeyDown:rt,onKeyUp:Ee,onCompositionEnd:ot,onPaste:st})]}),document.body):null,Fe.current&&!E?a.jsx(vt,{containerRef:Fe,disableHorizontal:!0,className:"overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero"}):null]})});pt.displayName="TerminalViewport";const Vt={esc:"\x1B",tab:" ",enter:"\r","arrow-up":"\x1B[A","arrow-down":"\x1B[B","arrow-left":"\x1B[D","arrow-right":"\x1B[C"},it={ctrl:"5",cmd:"3"},ut={retry:{maxRetries:3,initialDelayMs:500,maxDelayMs:8e3},connectionTimeoutMs:1e4},Pt={retry:{...ut.retry,initialDelayMs:200,maxDelayMs:500},connectionTimeoutMs:1500},jt=(f,p)=>{if(p)switch(f){case"arrow-up":return`\x1B[1;${it[p]}A`;case"arrow-down":return`\x1B[1;${it[p]}B`;case"arrow-right":return`\x1B[1;${it[p]}C`;case"arrow-left":return`\x1B[1;${it[p]}D`}return Vt[f]??null},Ht=()=>{const{t:f}=dt(),{terminal:p,runtime:m}=Tt(),{currentTheme:ee}=kt(),{monoFont:de}=Ct(),Me=Ie(t=>t.terminalFontSize),ye=Ie(t=>t.bottomTerminalHeight),Be=Ie(t=>t.isBottomTerminalExpanded),{isMobile:E,isTablet:tt,hasTouchOnlyPointer:je}=Et(),he=E||tt,F=(he||je)&&m.platform==="web",N=m.platform!=="vscode",Fe=Ie(t=>t.showTerminalQuickKeysOnDesktop),I=he||Fe,_e=ft(t=>t.currentSessionId),P=ft(t=>t.newSessionDraft),ze=_e!==null||P?.open===!0,h=Rt()??null,be=J(t=>t.sessions),te=J(t=>t.hasHydrated),Le=J(t=>t.ensureDirectory),Ke=J(t=>t.createTab),pe=J(t=>t.setActiveTab),ne=J(t=>t.closeTab),q=J(t=>t.setTabSessionId),ge=J(t=>t.setTabLifecycle),re=J(t=>t.setConnecting),qe=J(t=>t.appendToBuffer),ce=Ie(t=>t.openContextPreview),k=n.useMemo(()=>{if(h)return be.get(h)},[be,h]),R=n.useMemo(()=>k?N?k.activeTabId??k.tabs[0]?.id??null:k.tabs[0]?.id??null:null,[k,N]),me=n.useMemo(()=>{if(k)return R?k.tabs.find(t=>t.id===R)??k.tabs[0]:k.tabs[0]},[k,R]),Ye=n.useMemo(()=>(k?.tabs??[]).map(t=>({icon:(()=>{const u=t.iconKey?At[t.iconKey]??"terminal":"terminal";return a.jsx(ie,{name:u,className:"h-4 w-4"})})(),id:t.id,label:t.label,title:t.label,closeLabel:f("terminalView.tabs.closeTabTitle")})),[k?.tabs,f]),j=me?.terminalSessionId??null,Oe=me?.lifecycle??"idle",xe=me?.bufferChunks??[],$e=me?.isConnecting??!1,nt=me?.previewUrl??null,[We,O]=n.useState(null),[at,y]=n.useState(!1),[ve,A]=n.useState(!1),[M,C]=n.useState(null),[Te,le]=n.useState(!1),[W,He]=n.useState(0),De=n.useRef(null),ue=n.useRef(null),ke=n.useRef(R),X=n.useRef(j),U=n.useRef(h),L=n.useRef(null),Ne=n.useRef(null),Ge=n.useRef(!1),Xe=n.useRef(null),Ce=n.useRef(new Set),Qe=n.useRef(!1),we=n.useCallback(()=>{F||typeof document<"u"&&!document.hasFocus()||L.current?.focus()},[F]),fe=n.useCallback(()=>{F||L.current?.focus()},[F]);n.useEffect(()=>{if(!te||Qe.current)return;Qe.current=!0;const t=new Set;for(const[,u]of J.getState().sessions.entries())for(const i of u.tabs)i.terminalSessionId&&t.add(i.terminalSessionId);Ce.current=t},[te]);const rt=Ie(t=>t.activeMainTab),Ee=Ie(t=>t.isBottomTerminalOpen),ot=Ie(t=>t.setBottomTerminalOpen),st=Ie(t=>t.setBottomTerminalExpanded),Ze=rt==="terminal",e=Ze||Ee,[o,s]=n.useState(e);n.useEffect(()=>{!e||m.platform==="vscode"||It()},[e,m.platform]),n.useEffect(()=>{e&&s(!0)},[e]),n.useEffect(()=>{Ge.current=e},[e]),n.useEffect(()=>{X.current=j},[j]),n.useEffect(()=>{ke.current=R},[R]),n.useEffect(()=>{U.current=h},[h]),n.useEffect(()=>{!I&&M!==null&&C(null)},[I,M,C]),n.useEffect(()=>{!j&&M!==null&&C(null)},[j,M,C]);const c=n.useCallback(()=>{De.current?.(),De.current=null,ue.current=null,A(!1)},[]);n.useEffect(()=>()=>{c(),X.current=null},[c]);const r=n.useCallback((t,u,i,b=ut)=>{if(ue.current===i)return;c(),ue.current=i;const w=p.connect(i,{onEvent:g=>{if(ue.current===i)switch(g.type){case"connected":{re(t,u,!1),O(null),y(!1),A(!1),we(),Xe.current===i&&(Xe.current=null,p.sendInput(i,"\r").catch(()=>{}));break}case"reconnecting":{O(null),y(!1),A(!0);break}case"data":{g.data&&qe(t,u,g.data);break}case"exit":{const d=typeof g.exitCode=="number"?g.exitCode:null,_=typeof g.signal=="number"?g.signal:null,$=!!J.getState().getDirectoryState(t)?.tabs.find(ae=>ae.id===u)?.label?.startsWith("Action:");qe(t,u,f("terminalView.stream.processExitedMessage",{exitCodeSegment:d!==null?f("terminalView.stream.processExitedWithCode",{exitCode:d}):"",signalSegment:_!==null?f("terminalView.stream.processExitedWithSignal",{signal:_}):""})),ge(t,u,"exited"),q(t,u,null),re(t,u,!1),O($?null:f("terminalView.error.sessionEnded")),y(!1),A(!1),c();break}}},onError:(g,d)=>{if(ue.current===i){if(!d){O(null),y(!1);return}A(!1),O(f("terminalView.error.connectionFailed",{message:g.message})),y(!0),re(t,u,!1),ge(t,u,"exited"),q(t,u,null),c()}}},b);De.current=()=>{w.close(),ue.current=null}},[qe,c,we,re,ge,q,f,p]);n.useEffect(()=>{let t=!1;if(!te||!o)return;if(!h){O(f(ze?"terminalView.empty.noWorkingDirectory":"terminalView.empty.selectSession")),c();return}return(async()=>{const i=h;if(!U.current||U.current!==i)return;Le(i);const b=J.getState().getDirectoryState(i);if(!b||b.tabs.length===0)return;const w=N?b.activeTabId??b.tabs[0]?.id??null:b.tabs[0]?.id??null;if(!w)return;const g=b.tabs.find(se=>se.id===w)??b.tabs[0];let d=g?.terminalSessionId??null;const _=g?.lifecycle??"idle",oe=!!g?.label?.startsWith("Action:"),$=(g?.bufferLength??0)>0||(g?.bufferChunks?.length??0)>0,ae=!!d&&Ce.current.has(d)&&(g?.bufferLength??0)===0&&(g?.bufferChunks?.length??0)===0,Se=!!d&&Ce.current.has(d);if(!d){if(_==="exited"){re(i,w,!1);return}if(oe&&$){re(i,w,!1);return}O(null),y(!1),A(!1),re(i,w,!0);try{const se=Ne.current,Pe=await p.createSession({cwd:i,cols:se?.cols,rows:se?.rows});if(!(!t&&U.current===i&&ke.current===w)){try{await p.close(Pe.sessionId)}catch{}return}q(i,w,Pe.sessionId),d=Pe.sessionId}catch(se){t||(O(se instanceof Error?se.message:f("terminalView.error.startSessionFailed")),y(!0),A(!1),re(i,w,!1));return}}!d||t||(X.current=d,Se&&Ce.current.delete(d),ae&&(Xe.current=d),r(i,w,d,Se?Pt:ut))})(),()=>{t=!0,X.current=null,c()}},[ze,h,j,Oe,R,o,N,te,Le,re,ge,q,r,c,f,p]),n.useEffect(()=>{if(!e||F)return;if(typeof window>"u"){we();return}const t=window.requestAnimationFrame(()=>{we()});return()=>{window.cancelAnimationFrame(t)}},[R,we,e,F]);const v=n.useCallback(async()=>{if(!h||Te)return;const t=J.getState().getDirectoryState(h),u=N?R??t?.activeTabId??t?.tabs[0]?.id??null:t?.tabs[0]?.id??null;if(u){le(!0),O(null),y(!1),A(!1),c();try{await ne(h,u)}catch(i){O(i instanceof Error?i.message:f("terminalView.error.restartFailed")),y(!0),A(!1)}finally{le(!1)}}},[R,ne,c,h,N,Te,f]),S=n.useCallback(async()=>{await v()},[v]),D=n.useCallback(()=>{if(!h)return;const t=Ke(h);pe(h,t),O(null),y(!1),A(!1),c()},[Ke,c,h,pe]),G=n.useCallback(t=>{h&&(pe(h,t),O(null),y(!1),A(!1),c())},[c,h,pe]),l=n.useCallback(t=>{h&&(t===R&&c(),O(null),y(!1),A(!1),ne(h,t))},[R,ne,c,h]),T=n.useCallback(t=>{if(!t||ve)return;let u=t,i=!1;if(M&&t.length>0){const w=t[0];if(w.length===1&&/[a-zA-Z]/.test(w)){const g=w.toUpperCase();(M==="ctrl"||M==="cmd")&&(u=String.fromCharCode(g.charCodeAt(0)&31),i=!0)}i||(i=!0)}const b=X.current;b&&(p.sendInput(b,u).catch(w=>{ve||O(w instanceof Error?w.message:f("terminalView.error.sendInputFailed"))}),i&&(C(null),fe()))},[M,fe,ve,C,f,p]),V=n.useCallback((t,u)=>{if(Ne.current={cols:t,rows:u},!Ge.current)return;const i=X.current;i&&p.resize({sessionId:i,cols:t,rows:u}).catch(()=>{})},[p]),H=n.useCallback(t=>{C(u=>u===t?null:t),fe()},[fe,C]),K=n.useCallback(t=>{const u=jt(t,M);u&&(T(u),C(null),fe())},[M,fe,T,C]);n.useEffect(()=>{if(!I||!M||!j)return;const t=u=>{if(u.repeat)return;const i=u.key;if(!i||i==="Control"||i==="Meta"||i==="Alt"||i==="Shift")return;const b=i.length===1?i.toLowerCase():i,w=u.code??"",g=w.startsWith("Key")&&w.length===4?w.slice(3).toUpperCase():null,d=i.length===1&&/[a-zA-Z]/.test(i)?i.toUpperCase():g,_={Tab:"tab",Enter:"enter",ArrowUp:"arrow-up",ArrowDown:"arrow-down",ArrowLeft:"arrow-left",ArrowRight:"arrow-right",Escape:"esc",tab:"tab",enter:"enter",arrowup:"arrow-up",arrowdown:"arrow-down",arrowleft:"arrow-left",arrowright:"arrow-right",escape:"esc"};if(b in _){u.preventDefault(),u.stopPropagation(),K(_[b]);return}if(M==="ctrl"&&d&&d.length===1&&d>="A"&&d<="Z"){const oe=String.fromCharCode(d.charCodeAt(0)&31);u.preventDefault(),u.stopPropagation(),T(oe),C(null),fe()}};return window.addEventListener("keydown",t),()=>{window.removeEventListener("keydown",t)}},[M,K,T,fe,I,C,j]);const Y=n.useMemo(()=>{const t=et[ct].stack;if(typeof window>"u")return(et[de]??et[ct]).stack;const i=window.getComputedStyle(document.documentElement).getPropertyValue("--font-family-mono");return i&&i.trim().length>0?i.trim():(et[de]??et[ct]).stack??t},[de]),x=n.useMemo(()=>Mt(ee),[ee]),B=n.useMemo(()=>`${h??"no-dir"}::${R??"no-tab"}::${j??"no-terminal"}`,[h,R,j]),Re=n.useMemo(()=>`${B}::layout-${W}`,[B,W]);if(n.useEffect(()=>{if(F||!Ee||!e)return;if(typeof window>"u"){He(u=>u+1);return}const t=window.setTimeout(()=>{He(u=>u+1)},140);return()=>{window.clearTimeout(t)}},[ye,Be,Ee,e,F]),n.useEffect(()=>{if(!e||F)return;const t=L.current;if(!t)return;const u=()=>{t.fit()};if(typeof window<"u"){const i=window.requestAnimationFrame(()=>{u(),we()}),b=[220,400].map(w=>window.setTimeout(u,w));return()=>{window.cancelAnimationFrame(i),b.forEach(w=>window.clearTimeout(w))}}u()},[we,e,F,B,j]),n.useEffect(()=>{if(F||!e||!Ee)return;const t=L.current;if(!t)return;const u=()=>{t.fit()};if(typeof window<"u"){const i=window.requestAnimationFrame(()=>{u()}),b=[0,80,180,320].map(w=>window.setTimeout(u,w));return()=>{window.cancelAnimationFrame(i),b.forEach(w=>window.clearTimeout(w))}}u()},[ye,Be,Ee,e,F]),!ze)return a.jsx("div",{className:"flex h-full items-center justify-center p-4 text-center text-sm text-muted-foreground",children:f("terminalView.empty.selectSession")});if(!h)return a.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 p-4 text-center text-sm text-muted-foreground",children:[a.jsx("p",{children:f("terminalView.empty.noWorkingDirectoryForSession")}),a.jsx("button",{onClick:v,className:"rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90",children:f("terminalView.actions.retry")})]});const z=!j||$e||Te||ve,Ve=o,Ae=!he&&Ee&&!Ze,Q=a.jsxs(a.Fragment,{children:[a.jsx(Z,{type:"button",size:"sm",variant:"outline",className:"h-6 px-2 text-xs",onClick:()=>K("esc"),disabled:z,children:f("terminalView.quickKeys.escape")}),a.jsxs(Z,{type:"button",size:"sm",variant:"outline",className:"h-6 w-9 p-0",onClick:()=>K("tab"),disabled:z,children:[a.jsx(ie,{name:"arrow-right",className:"h-4 w-4"}),a.jsx("span",{className:"sr-only",children:f("terminalView.quickKeys.tabAria")})]}),a.jsxs(Z,{type:"button",size:"sm",variant:"chip","aria-pressed":M==="ctrl",className:"h-6 w-9 p-0",onClick:()=>H("ctrl"),disabled:z,children:[a.jsx("span",{className:"text-xs font-medium",children:f("terminalView.quickKeys.controlLabel")}),a.jsx("span",{className:"sr-only",children:f("terminalView.quickKeys.controlModifierAria")})]}),a.jsxs(Z,{type:"button",size:"sm",variant:"chip","aria-pressed":M==="cmd",className:"h-6 w-9 p-0",onClick:()=>H("cmd"),disabled:z,children:[a.jsx(ie,{name:"command"}),a.jsx("span",{className:"sr-only",children:f("terminalView.quickKeys.commandModifierAria")})]}),a.jsxs(Z,{type:"button",size:"sm",variant:"outline",className:"h-6 w-9 p-0",onClick:()=>K("arrow-up"),disabled:z,children:[a.jsx(ie,{name:"arrow-up"}),a.jsx("span",{className:"sr-only",children:f("terminalView.quickKeys.arrowUpAria")})]}),a.jsxs(Z,{type:"button",size:"sm",variant:"outline",className:"h-6 w-9 p-0",onClick:()=>K("arrow-left"),disabled:z,children:[a.jsx(ie,{name:"arrow-left"}),a.jsx("span",{className:"sr-only",children:f("terminalView.quickKeys.arrowLeftAria")})]}),a.jsxs(Z,{type:"button",size:"sm",variant:"outline",className:"h-6 w-9 p-0",onClick:()=>K("arrow-down"),disabled:z,children:[a.jsx(ie,{name:"arrow-down"}),a.jsx("span",{className:"sr-only",children:f("terminalView.quickKeys.arrowDownAria")})]}),a.jsxs(Z,{type:"button",size:"sm",variant:"outline",className:"h-6 w-9 p-0",onClick:()=>K("arrow-right"),disabled:z,children:[a.jsx(ie,{name:"arrow-right"}),a.jsx("span",{className:"sr-only",children:f("terminalView.quickKeys.arrowRightAria")})]}),a.jsxs(Z,{type:"button",size:"sm",variant:"outline",className:"h-6 w-9 p-0",onClick:()=>K("enter"),disabled:z,children:[a.jsx(ie,{name:"arrow-go-back"}),a.jsx("span",{className:"sr-only",children:f("terminalView.quickKeys.enterAria")})]})]});return a.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-[var(--surface-background)]",children:[a.jsxs("div",{className:Ue("app-region-no-drag sticky top-0 z-20 shrink-0 bg-[var(--surface-background)] text-xs",he?"px-3 py-1.5":"pl-3 pr-1.5 py-1"),children:[N&&k?a.jsxs("div",{className:"flex items-center gap-2 pl-1 pr-1",children:[a.jsx("div",{className:Ue("min-w-0 flex-1",he?"h-8":"h-7"),children:a.jsx(St,{items:Ye,activeId:R,onSelect:G,onClose:l,layoutMode:"scrollable",variant:"default",className:"h-full bg-transparent"})}),a.jsx(Z,{type:"button",size:"xs",variant:"ghost",className:Ue("shrink-0",he?"h-8 w-8 p-0":"h-7 w-7 p-0"),onClick:D,title:f("terminalView.tabs.newTabTitle"),children:a.jsx(ie,{name:"add",className:`${he?"h-[18px] w-[18px]":"h-4 w-4"}`})}),a.jsxs("div",{className:"flex shrink-0 items-center gap-1 overflow-visible",children:[nt?a.jsxs(Z,{type:"button",size:"xs",variant:"outline",className:"h-6 shrink-0 gap-1 px-2",onClick:()=>{h&&ce(h,nt)},title:f("terminalView.preview.openTitle"),children:[a.jsx(ie,{name:"global",className:"h-3.5 w-3.5 shrink-0"}),a.jsx("span",{className:"whitespace-nowrap",children:f("terminalView.preview.open")})]}):null,Ae?a.jsxs(a.Fragment,{children:[a.jsx(Z,{type:"button",size:"xs",variant:"ghost",onClick:()=>st(!Be),className:Ue("shrink-0 p-0",E?"h-8 w-8":"h-7 w-7"),title:f(Be?"terminalView.bottomDock.restoreTitle":"terminalView.bottomDock.expandTitle"),"aria-label":f(Be?"terminalView.bottomDock.restoreAria":"terminalView.bottomDock.expandAria"),children:Be?a.jsx(ie,{name:"fullscreen-exit",className:"h-4 w-4"}):a.jsx(ie,{name:"fullscreen",className:"h-4 w-4"})}),a.jsx(Z,{type:"button",size:"xs",variant:"ghost",onClick:()=>ot(!1),className:Ue("shrink-0 p-0",E?"h-8 w-8":"h-7 w-7"),title:f("terminalView.bottomDock.closeTitle"),"aria-label":f("terminalView.bottomDock.closeAria"),children:a.jsx(ie,{name:"close",className:"h-4 w-4"})})]}):null]})]}):null,!E&&I&&N&&k?a.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-1 pl-1 pr-1",children:Q}):null,I&&(E||!N||!k)?a.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-1",children:Q}):null]}),a.jsxs("div",{className:"relative flex-1 overflow-hidden",style:{backgroundColor:x.background},children:[a.jsx("div",{className:"h-full w-full box-border pl-4 pr-1.5 pt-3 pb-4",children:Ve?a.jsx(pt,{ref:t=>{L.current=t},sessionKey:Re,chunks:xe,onInput:T,onResize:V,theme:x,fontFamily:Y,fontSize:Me,enableTouchScroll:F,autoFocus:!F&&e,isVisible:e}):null}),!ve&&We&&a.jsxs("div",{className:"absolute inset-x-0 bottom-0 bg-[var(--status-error-background)] px-3 py-2 text-xs text-[var(--status-error-foreground)] flex items-center justify-between gap-2",children:[a.jsx("span",{children:We}),at&&E&&a.jsx(Z,{size:"sm",variant:"secondary",className:"h-6 px-2 py-0 text-xs",onClick:S,disabled:Te,title:f("terminalView.actions.hardRestartTitle"),type:"button",children:f("terminalView.actions.hardRestart")})]})]})]})};export{Ht as TerminalView};