@pi-chamber/web 0.3.0 → 0.3.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 (65) hide show
  1. package/bin/lib/cli-startup.js +53 -10
  2. package/bin/lib/cli-startup.test.js +42 -0
  3. package/dist/assets/{CommitSection-BpbMC0et.js → CommitSection-DLIvjYbM.js} +1 -1
  4. package/dist/assets/{DiagramEditor-dFTMKHuO.js → DiagramEditor-Tw3ZWHML.js} +1 -1
  5. package/dist/assets/{DiagramView-DVw_8Px1.js → DiagramView-CK6R7taL.js} +1 -1
  6. package/dist/assets/{DiffView-CkoY1oAM.js → DiffView-vrxi5oWp.js} +2 -2
  7. package/dist/assets/{FilesView-C0hyg2pa.js → FilesView-BD_h3EVr.js} +6 -6
  8. package/dist/assets/{GitView-D36hpDsb.js → GitView-BwNKqK0K.js} +4 -4
  9. package/dist/assets/{JsonTreeView-BF8S-bPN.js → JsonTreeView-CmY7QgEX.js} +1 -1
  10. package/dist/assets/{MarkdownRendererImpl-BVNChdig.js → MarkdownRendererImpl-CpI-25Xk.js} +1 -1
  11. package/dist/assets/{PatchDiff-B--OaNB1.js → PatchDiff-CrIWbYj7.js} +1 -1
  12. package/dist/assets/{PierreDiffViewer-0Qkp9ICt.js → PierreDiffViewer-B410mdbq.js} +2 -2
  13. package/dist/assets/{SessionSwitcherDropdown-cFWgy1td.js → SessionSwitcherDropdown-DROjbyIu.js} +100 -100
  14. package/dist/assets/SettingsView-CsJItYZh.js +4 -0
  15. package/dist/assets/{SettingsWindow-BuJCvYoR.js → SettingsWindow-C9s4AX72.js} +1 -1
  16. package/dist/assets/{ToolOutputDialog-Bi9BoEe7.js → ToolOutputDialog-b_R4tAZu.js} +5 -5
  17. package/dist/assets/{ToolPartDiffPreview-DGX7N4zr.js → ToolPartDiffPreview-CfnliaE9.js} +1 -1
  18. package/dist/assets/{VirtualizedFileDiff-CxraYoDZ.js → VirtualizedFileDiff-CQz2fSZI.js} +4 -4
  19. package/dist/assets/{collapsible-d4-HChej.js → collapsible-CR4U9tjw.js} +1 -1
  20. package/dist/assets/{computeVirtualFileMetrics-BuD14qFL.js → computeVirtualFileMetrics-C7vXPUYT.js} +2 -2
  21. package/dist/assets/{contextFileOpenGuard-DirV-hCs.js → contextFileOpenGuard-DtTHRnq1.js} +1 -1
  22. package/dist/assets/{index-DEYblXCW.js → index-BAqpUCjs.js} +5 -5
  23. package/dist/assets/{index-BWmmf5yJ.js → index-DZG82DE1.js} +1 -1
  24. package/dist/assets/{index-DLKBsLKY.css → index-riABQmQ_.css} +1 -1
  25. package/dist/assets/{isDiffPlainText-LoMmNzmX.js → isDiffPlainText-zTq-4A04.js} +1 -1
  26. package/dist/assets/{isFilePlainText-3Hj9i02t.js → isFilePlainText-CLgIdzE5.js} +1 -1
  27. package/dist/assets/{main-BsszlAdQ.js → main-BVWtJYSk.js} +2 -2
  28. package/dist/assets/main-DXYHsqzA.js +133 -0
  29. package/dist/assets/{markdownCore-sGxk8jrc.js → markdownCore-CN0pApQE.js} +2 -2
  30. package/dist/assets/{miniChat-C6SDQL4G.js → miniChat-BrbRq5NQ.js} +2 -2
  31. package/dist/assets/{mobile-DBW3XDmZ.js → mobile-DTPtCn5N.js} +2 -2
  32. package/dist/assets/{renderElectronMiniChatApp-B1_fTdN-.js → renderElectronMiniChatApp-CM8qBaye.js} +1 -1
  33. package/dist/assets/{renderMobileApp-CFxZc_1a.js → renderMobileApp-KS_pt-qc.js} +4 -4
  34. package/dist/assets/{runtimeSurface-9aJdtQbh.js → runtimeSurface-CkHYYg0E.js} +1 -1
  35. package/dist/assets/{useInlineCommentController-Cl--s6vE.js → useInlineCommentController-CwNNjgc7.js} +2 -2
  36. package/dist/assets/usePanelSlide-DkorgQJ5.js +56 -0
  37. package/dist/assets/{useWindowTitle-C-AZD713.js → useWindowTitle-B9wt_3ZQ.js} +3 -3
  38. package/dist/assets/{vendor-codemirror-language-data-HC9JT4I3.js → vendor-codemirror-language-data-x89A7Wy0.js} +2 -2
  39. package/dist/assets/{vendor-sonner-dWA7qvjr.js → vendor-sonner-CW8w438f.js} +1 -1
  40. package/dist/assets/{web-components-skJ_VpnT.js → web-components-BEPfE4kU.js} +2 -2
  41. package/dist/index.html +4 -4
  42. package/dist/mini-chat.html +3 -3
  43. package/dist/mobile.html +3 -3
  44. package/package.json +1 -1
  45. package/server/index.js +33 -0
  46. package/server/lib/pi/routes.js +24 -2
  47. package/server/lib/pi/routes.test.js +14 -6
  48. package/server/lib/pi/session-daemon/DOCUMENTATION.md +4 -3
  49. package/server/lib/pi/session-daemon/message-entry-aliases.js +100 -0
  50. package/server/lib/pi/session-daemon/session-daemon.js +176 -46
  51. package/server/lib/pi/session-daemon/session-daemon.test.js +364 -6
  52. package/server/lib/pi/session-daemon/supervisor.js +20 -1
  53. package/server/lib/pi/session-daemon/supervisor.test.js +43 -0
  54. package/server/lib/pi/settings-store.js +17 -0
  55. package/server/lib/pi/settings-store.test.js +33 -0
  56. package/server/lib/server/core-routes.js +36 -4
  57. package/server/lib/server/tunnel-service.DOCUMENTATION.md +74 -0
  58. package/server/lib/server/tunnel-service.js +228 -0
  59. package/server/lib/server/tunnel-service.test.js +61 -0
  60. package/server/lib/ui-auth/DOCUMENTATION.md +2 -0
  61. package/server/lib/ui-auth/ui-auth.js +5 -1
  62. package/server/lib/ui-auth/ui-auth.test.js +17 -0
  63. package/dist/assets/SettingsView-D3ZZyjU3.js +0 -4
  64. package/dist/assets/main-CUvZIN16.js +0 -133
  65. package/dist/assets/usePanelSlide-D5ffPTGM.js +0 -56
@@ -1 +1 @@
1
- import{i,M as s}from"./index-DEYblXCW.js";const n="pichamber-mobile-layout",a=e=>e==="default"?"default":"new",c=()=>{if(typeof window>"u")return"new";try{return a(window.localStorage.getItem(n))}catch{return"new"}},l=e=>{if(typeof window>"u")return!1;try{return window.localStorage.setItem(n,e),!0}catch{return!1}},d=768,u=()=>{if(typeof window>"u")return!1;const e=typeof window.matchMedia=="function"?window.matchMedia("(pointer: coarse)").matches||window.matchMedia("(hover: none)").matches:!1,t=typeof navigator<"u"?navigator.maxTouchPoints??0:0;return e||t>0},r=()=>{if(typeof window>"u")return"desktop";const e=window.__PICHAMBER_SURFACE__;if(e==="mobile"||e==="desktop")return e;const t=new URLSearchParams(window.location.search).get("surface");if(t==="mobile"||t==="desktop")return t;if(i())return"mobile";if(s())return"desktop";const o=Math.min(window.innerWidth||Number.POSITIVE_INFINITY,window.screen?.width||Number.POSITIVE_INFINITY);return Number.isFinite(o)&&o<=d&&u()&&c()==="new"?"mobile":"desktop"},m=()=>{const e=r();return typeof window<"u"&&(window.__PICHAMBER_SURFACE__=e),e},h=()=>r()==="mobile";export{c as g,h as i,m as r,l as s};
1
+ import{i,J as s}from"./index-BAqpUCjs.js";const n="pichamber-mobile-layout",a=e=>e==="default"?"default":"new",c=()=>{if(typeof window>"u")return"new";try{return a(window.localStorage.getItem(n))}catch{return"new"}},l=e=>{if(typeof window>"u")return!1;try{return window.localStorage.setItem(n,e),!0}catch{return!1}},d=768,u=()=>{if(typeof window>"u")return!1;const e=typeof window.matchMedia=="function"?window.matchMedia("(pointer: coarse)").matches||window.matchMedia("(hover: none)").matches:!1,t=typeof navigator<"u"?navigator.maxTouchPoints??0:0;return e||t>0},r=()=>{if(typeof window>"u")return"desktop";const e=window.__PICHAMBER_SURFACE__;if(e==="mobile"||e==="desktop")return e;const t=new URLSearchParams(window.location.search).get("surface");if(t==="mobile"||t==="desktop")return t;if(i())return"mobile";if(s())return"desktop";const o=Math.min(window.innerWidth||Number.POSITIVE_INFINITY,window.screen?.width||Number.POSITIVE_INFINITY);return Number.isFinite(o)&&o<=d&&u()&&c()==="new"?"mobile":"desktop"},m=()=>{const e=r();return typeof window<"u"&&(window.__PICHAMBER_SURFACE__=e),e},h=()=>r()==="mobile";export{c as g,h as i,m as r,l as s};
@@ -1,2 +1,2 @@
1
- import{r as N,j as t,R as c}from"./vendor-react-DYyjh7Q0.js";import{bk as Q,f as F,B as E,I as w,as as J,at as W,au as Z,az as q,aV as ee,h as O,E as te,aQ as R,ev as se,ew as B,t as ne}from"./SessionSwitcherDropdown-cFWgy1td.js";import{p as oe,q as re,t as ae,v as V,N as ie}from"./usePanelSlide-D5ffPTGM.js";import{C as ce,a as le,b as de}from"./collapsible-d4-HChej.js";import{a as me}from"./index-DEYblXCW.js";function ve({draft:n,onEdit:a,onDelete:r,className:h,maxWidth:d}){const p=Q()?.currentTheme,[m,j]=N.useState(!1),[I,f]=N.useState(!1),u=typeof n.text=="string"?n.text:"",i=u.length>150||u.split(`
2
- `).length>3;return t.jsxs(oe,{open:I,onOpenChange:f,children:[t.jsx(re,{render:t.jsx("div",{className:F("rounded-lg border shadow-none w-full max-w-[min(100%,calc(var(--oc-context-panel-width,100vw)-var(--oc-editor-gutter-width,0px)))] overflow-hidden transition-all duration-200",h),style:{backgroundColor:p?.colors?.surface?.elevated,borderColor:p?.colors?.interactive?.border,maxWidth:d?`${Math.max(200,Math.floor(d))}px`:void 0},"data-comment-card":"true",onContextMenu:b=>{b.preventDefault(),f(!0)}}),children:t.jsxs("div",{className:"flex items-start justify-between gap-2 p-3",children:[t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-center gap-2 text-xs font-medium text-muted-foreground mb-1.5",children:[t.jsx("span",{className:"truncate max-w-[200px]",title:n.fileLabel,children:n.fileLabel}),t.jsx("span",{children:"•"}),t.jsx("span",{children:`Lines ${n.startLine}-${n.endLine}`}),n.side&&t.jsxs("span",{children:["(",n.side,")"]})]}),t.jsxs(ce,{open:m||!i,onOpenChange:j,children:[t.jsx("div",{className:F("text-sm whitespace-pre-wrap break-words leading-relaxed",!m&&i&&"line-clamp-3"),children:u}),i&&t.jsx(le,{asChild:!0,children:t.jsx(E,{variant:"ghost",size:"sm",className:"h-6 px-0 mt-1 text-xs text-muted-foreground hover:text-foreground w-full justify-start",children:m?t.jsxs(t.Fragment,{children:[t.jsx(w,{name:"arrow-up-s",className:"size-3 mr-1"}),"Show less"]}):t.jsxs(t.Fragment,{children:[t.jsx(w,{name:"arrow-down-s",className:"size-3 mr-1"}),"Show more"]})})}),t.jsx(de,{})]})]}),t.jsxs(J,{children:[t.jsx(W,{asChild:!0,children:t.jsx(E,{variant:"ghost",size:"icon",className:"h-6 w-6 -mr-1 text-muted-foreground hover:text-foreground",children:t.jsx(w,{name:"more",className:"size-4"})})}),t.jsxs(Z,{align:"end",children:[t.jsxs(q,{onClick:a,children:[t.jsx(w,{name:"edit",className:"size-4 mr-2"}),"Edit comment"]}),t.jsxs(q,{onClick:r,className:"text-destructive",children:[t.jsx(w,{name:"delete-bin",className:"size-4 mr-2"}),"Delete comment"]})]})]})]})}),t.jsxs(ae,{children:[t.jsxs(V,{onClick:a,children:[t.jsx(w,{name:"edit",className:"size-4 mr-2"}),"Edit comment"]}),t.jsxs(V,{onClick:r,className:"text-destructive focus:text-destructive",children:[t.jsx(w,{name:"delete-bin",className:"size-4 mr-2"}),"Delete comment"]})]})]})}function Ce({initialText:n="",onTextChange:a,onSave:r,onCancel:h,fileLabel:d,lineRange:l,isEditing:p=!1,className:m,maxWidth:j}){const f=Q()?.currentTheme,{isMobile:u}=ee(),[i,b]=c.useState(n),D=N.useRef(null),M=e=>{b(e),a?.(e)},L=N.useRef(l);N.useEffect(()=>{l&&(L.current=l)},[l]);const C=e=>{if(!e)return;const o=Math.min(e.start,e.end),g=Math.max(e.start,e.end);return{...e,start:o,end:g}},x=C(l);N.useEffect(()=>{const e=D.current;if(!e)return;const o=e.closest(".overlay-scrollbar-container"),g=o?.scrollTop??window.scrollY,k=o?.scrollLeft??window.scrollX;if(u){e.scrollIntoView({behavior:"auto",block:"nearest"});try{e.focus({preventScroll:!0})}catch{e.focus()}return}try{e.focus({preventScroll:!0})}catch{e.focus()}const z=e.value.length;try{e.setSelectionRange(z,z)}catch{}requestAnimationFrame(()=>{o?(o.scrollTop=g,o.scrollLeft=k):window.scrollTo({top:g,left:k})})},[u]);const T=e=>{(e.metaKey||e.ctrlKey)&&e.key==="Enter"?(e.preventDefault(),i.trim()&&r(i,C(L.current))):e.key==="Escape"&&(e.preventDefault(),h())},y=e=>{e.stopPropagation(),i.trim()&&r(i,C(L.current))};return t.jsx("div",{className:F("rounded-lg border shadow-none w-full max-w-[min(100%,calc(var(--oc-context-panel-width,100vw)-var(--oc-editor-gutter-width,0px)))] overflow-hidden animate-in fade-in zoom-in-95 duration-200",m),style:{backgroundColor:f?.colors?.surface?.elevated,borderColor:f?.colors?.interactive?.border,maxWidth:j?`${Math.max(200,Math.floor(j))}px`:void 0},"data-comment-input":"true",onPointerDown:e=>e.stopPropagation(),onTouchStart:e=>e.stopPropagation(),children:t.jsxs("div",{className:"p-3",children:[(d||l)&&t.jsxs("div",{className:"flex items-center gap-2 text-xs font-medium text-muted-foreground mb-2",children:[d&&t.jsx("span",{className:"truncate max-w-[200px]",children:d}),d&&l&&t.jsx("span",{children:"•"}),x&&t.jsx("span",{children:`Lines ${x.start}-${x.end}`})]}),t.jsx(ie,{simple:!0,ref:D,value:i,onChange:e=>M(e.target.value),onKeyDown:T,placeholder:u?"Add a comment...":"Add a comment... (Cmd+Enter to save)",outerClassName:"rounded-[var(--radius-xl)] bg-[var(--surface-subtle)] ring-1 ring-inset ring-border/60 focus-within:ring-2 focus-within:ring-[var(--interactive-focus-ring)]",className:"min-h-[80px] px-3 py-2.5 text-sm resize-y"}),t.jsxs("div",{className:"flex items-center justify-end gap-2 mt-3",children:[t.jsx(E,{variant:"ghost",size:"sm",onClick:h,onPointerDown:e=>e.stopPropagation(),onTouchStart:e=>e.stopPropagation(),className:"h-8 text-muted-foreground hover:text-foreground",children:"Cancel"}),t.jsx(E,{size:"sm",onClick:y,onPointerDown:e=>e.stopPropagation(),onTouchStart:e=>e.stopPropagation(),disabled:!i.trim(),className:"h-8 min-w-[80px]",style:{backgroundColor:f?.colors?.status?.success,color:f?.colors?.status?.successForeground},children:p?"Save":"Comment"})]})]})})}const ue=n=>{const a=Math.min(n.startLine,n.endLine),r=Math.max(n.startLine,n.endLine);return{...n,startLine:a,endLine:r}},Y=n=>{const a=Math.min(n.start,n.end),r=Math.max(n.start,n.end);return{...n,start:a,end:r}};function we(n){const{source:a,fileLabel:r,language:h,getCodeForRange:d,toStoreRange:l,fromDraftRange:p}=n,m=O(s=>s.currentSessionId),j=O(s=>s.newSessionDraft?.open),I=te(),f=O(c.useCallback(s=>m?s.getDirectoryForSession(m):null,[m])),u=R(s=>s.addDraft),i=R(s=>s.updateDraft),b=R(s=>s.removeDraft),[D,M]=c.useState(null),[L,C]=c.useState(""),[x,T]=c.useState(null),y=m??(j?"draft":null),e=f??I,o=c.useMemo(()=>!y||!e?null:{directory:e,sessionKey:y},[e,y]),g=o?se(me(),o.directory,o.sessionKey):null,k=R(c.useCallback(s=>g?s.drafts[g]??B:B,[g])),z=c.useMemo(()=>!o||!r?[]:k.filter(s=>s.source===a&&s.fileLabel===r),[r,k,a,o]),v=c.useCallback(()=>{M(null),C(""),T(null)},[]),U=c.useCallback(()=>{v()},[v]),X=c.useCallback(s=>{const P=Y(p(s));M(P),C(s.text),T(s.id)},[p]),G=c.useCallback(s=>{o&&(b(o,s.id),x===s.id&&v())},[x,b,v,o]),H=c.useCallback((s,P)=>{const $=P??D,K=s.trim();if(!$||!K||!r)return;if(!o){ne.error("Select a session to save comment");return}const A=Y($),S=ue(l(A)),_=d(A);x?i(o,x,{fileLabel:r,startLine:S.startLine,endLine:S.endLine,side:S.side,code:_,language:h,text:K}):u(o,{source:a,fileLabel:r,startLine:S.startLine,endLine:S.endLine,side:S.side,code:_,language:h,text:K}),v()},[u,x,r,d,h,v,D,a,o,l,i]);return{sessionKey:y,drafts:z,selection:D,setSelection:M,commentText:L,setCommentText:C,editingDraftId:x,setEditingDraftId:T,reset:v,cancel:U,startEdit:X,deleteDraft:G,saveComment:H,fromDraftRange:p}}export{Ce as I,ve as a,Y as n,we as u};
1
+ import{r as N,j as t,R as c}from"./vendor-react-DYyjh7Q0.js";import{be as U,f as F,B as E,I as w,as as J,at as W,au as Z,az as _,aQ as ee,h as O,E as te,aM as R,eA as se,eB as q,t as ne}from"./SessionSwitcherDropdown-DROjbyIu.js";import{p as oe,q as re,t as ae,v as Y,N as ie}from"./usePanelSlide-DkorgQJ5.js";import{C as ce,a as le,b as de}from"./collapsible-CR4U9tjw.js";import{a as me}from"./index-BAqpUCjs.js";function Ce({draft:n,onEdit:a,onDelete:r,className:h,maxWidth:d}){const p=U()?.currentTheme,[m,j]=N.useState(!1),[k,f]=N.useState(!1),u=typeof n.text=="string"?n.text:"",i=u.length>150||u.split(`
2
+ `).length>3;return t.jsxs(oe,{open:k,onOpenChange:f,children:[t.jsx(re,{render:t.jsx("div",{className:F("rounded-lg border shadow-none w-full max-w-[min(100%,calc(var(--oc-context-panel-width,100vw)-var(--oc-editor-gutter-width,0px)))] overflow-hidden transition-all duration-200",h),style:{backgroundColor:p?.colors?.surface?.elevated,borderColor:p?.colors?.interactive?.border,maxWidth:d?`${Math.max(200,Math.floor(d))}px`:void 0},"data-comment-card":"true",onContextMenu:b=>{b.preventDefault(),f(!0)}}),children:t.jsxs("div",{className:"flex items-start justify-between gap-2 p-3",children:[t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-center gap-2 text-xs font-medium text-muted-foreground mb-1.5",children:[t.jsx("span",{className:"truncate max-w-[200px]",title:n.fileLabel,children:n.fileLabel}),t.jsx("span",{children:"•"}),t.jsx("span",{children:`Lines ${n.startLine}-${n.endLine}`}),n.side&&t.jsxs("span",{children:["(",n.side,")"]})]}),t.jsxs(ce,{open:m||!i,onOpenChange:j,children:[t.jsx("div",{className:F("text-sm whitespace-pre-wrap break-words leading-relaxed",!m&&i&&"line-clamp-3"),children:u}),i&&t.jsx(le,{asChild:!0,children:t.jsx(E,{variant:"ghost",size:"sm",className:"h-6 px-0 mt-1 text-xs text-muted-foreground hover:text-foreground w-full justify-start",children:m?t.jsxs(t.Fragment,{children:[t.jsx(w,{name:"arrow-up-s",className:"size-3 mr-1"}),"Show less"]}):t.jsxs(t.Fragment,{children:[t.jsx(w,{name:"arrow-down-s",className:"size-3 mr-1"}),"Show more"]})})}),t.jsx(de,{})]})]}),t.jsxs(J,{children:[t.jsx(W,{asChild:!0,children:t.jsx(E,{variant:"ghost",size:"icon",className:"h-6 w-6 -mr-1 text-muted-foreground hover:text-foreground",children:t.jsx(w,{name:"more",className:"size-4"})})}),t.jsxs(Z,{align:"end",children:[t.jsxs(_,{onClick:a,children:[t.jsx(w,{name:"edit",className:"size-4 mr-2"}),"Edit comment"]}),t.jsxs(_,{onClick:r,className:"text-destructive",children:[t.jsx(w,{name:"delete-bin",className:"size-4 mr-2"}),"Delete comment"]})]})]})]})}),t.jsxs(ae,{children:[t.jsxs(Y,{onClick:a,children:[t.jsx(w,{name:"edit",className:"size-4 mr-2"}),"Edit comment"]}),t.jsxs(Y,{onClick:r,className:"text-destructive focus:text-destructive",children:[t.jsx(w,{name:"delete-bin",className:"size-4 mr-2"}),"Delete comment"]})]})]})}function ve({initialText:n="",onTextChange:a,onSave:r,onCancel:h,fileLabel:d,lineRange:l,isEditing:p=!1,className:m,maxWidth:j}){const f=U()?.currentTheme,{isMobile:u}=ee(),[i,b]=c.useState(n),D=N.useRef(null),M=e=>{b(e),a?.(e)},L=N.useRef(l);N.useEffect(()=>{l&&(L.current=l)},[l]);const v=e=>{if(!e)return;const o=Math.min(e.start,e.end),g=Math.max(e.start,e.end);return{...e,start:o,end:g}},x=v(l);N.useEffect(()=>{const e=D.current;if(!e)return;const o=e.closest(".overlay-scrollbar-container"),g=o?.scrollTop??window.scrollY,I=o?.scrollLeft??window.scrollX;if(u){e.scrollIntoView({behavior:"auto",block:"nearest"});try{e.focus({preventScroll:!0})}catch{e.focus()}return}try{e.focus({preventScroll:!0})}catch{e.focus()}const z=e.value.length;try{e.setSelectionRange(z,z)}catch{}requestAnimationFrame(()=>{o?(o.scrollTop=g,o.scrollLeft=I):window.scrollTo({top:g,left:I})})},[u]);const T=e=>{(e.metaKey||e.ctrlKey)&&e.key==="Enter"?(e.preventDefault(),i.trim()&&r(i,v(L.current))):e.key==="Escape"&&(e.preventDefault(),h())},y=e=>{e.stopPropagation(),i.trim()&&r(i,v(L.current))};return t.jsx("div",{className:F("rounded-lg border shadow-none w-full max-w-[min(100%,calc(var(--oc-context-panel-width,100vw)-var(--oc-editor-gutter-width,0px)))] overflow-hidden animate-in fade-in zoom-in-95 duration-200",m),style:{backgroundColor:f?.colors?.surface?.elevated,borderColor:f?.colors?.interactive?.border,maxWidth:j?`${Math.max(200,Math.floor(j))}px`:void 0},"data-comment-input":"true",onPointerDown:e=>e.stopPropagation(),onTouchStart:e=>e.stopPropagation(),children:t.jsxs("div",{className:"p-3",children:[(d||l)&&t.jsxs("div",{className:"flex items-center gap-2 text-xs font-medium text-muted-foreground mb-2",children:[d&&t.jsx("span",{className:"truncate max-w-[200px]",children:d}),d&&l&&t.jsx("span",{children:"•"}),x&&t.jsx("span",{children:`Lines ${x.start}-${x.end}`})]}),t.jsx(ie,{simple:!0,ref:D,value:i,onChange:e=>M(e.target.value),onKeyDown:T,placeholder:u?"Add a comment...":"Add a comment... (Cmd+Enter to save)",outerClassName:"rounded-[var(--radius-xl)] bg-[var(--surface-subtle)] ring-1 ring-inset ring-border/60 focus-within:ring-2 focus-within:ring-[var(--interactive-focus-ring)]",className:"min-h-[80px] px-3 py-2.5 text-sm resize-y"}),t.jsxs("div",{className:"flex items-center justify-end gap-2 mt-3",children:[t.jsx(E,{variant:"ghost",size:"sm",onClick:h,onPointerDown:e=>e.stopPropagation(),onTouchStart:e=>e.stopPropagation(),className:"h-8 text-muted-foreground hover:text-foreground",children:"Cancel"}),t.jsx(E,{size:"sm",onClick:y,onPointerDown:e=>e.stopPropagation(),onTouchStart:e=>e.stopPropagation(),disabled:!i.trim(),className:"h-8 min-w-[80px]",style:{backgroundColor:f?.colors?.status?.success,color:f?.colors?.status?.successForeground},children:p?"Save":"Comment"})]})]})})}const ue=n=>{const a=Math.min(n.startLine,n.endLine),r=Math.max(n.startLine,n.endLine);return{...n,startLine:a,endLine:r}},Q=n=>{const a=Math.min(n.start,n.end),r=Math.max(n.start,n.end);return{...n,start:a,end:r}};function we(n){const{source:a,fileLabel:r,language:h,getCodeForRange:d,toStoreRange:l,fromDraftRange:p}=n,m=O(s=>s.currentSessionId),j=O(s=>s.newSessionDraft?.open),k=te(),f=O(c.useCallback(s=>m?s.getDirectoryForSession(m):null,[m])),u=R(s=>s.addDraft),i=R(s=>s.updateDraft),b=R(s=>s.removeDraft),[D,M]=c.useState(null),[L,v]=c.useState(""),[x,T]=c.useState(null),y=m??(j?"draft":null),e=f??k,o=c.useMemo(()=>!y||!e?null:{directory:e,sessionKey:y},[e,y]),g=o?se(me(),o.directory,o.sessionKey):null,I=R(c.useCallback(s=>g?s.drafts[g]??q:q,[g])),z=c.useMemo(()=>!o||!r?[]:I.filter(s=>s.source===a&&s.fileLabel===r),[r,I,a,o]),C=c.useCallback(()=>{M(null),v(""),T(null)},[]),V=c.useCallback(()=>{C()},[C]),X=c.useCallback(s=>{const P=Q(p(s));M(P),v(s.text),T(s.id)},[p]),G=c.useCallback(s=>{o&&(b(o,s.id),x===s.id&&C())},[x,b,C,o]),H=c.useCallback((s,P)=>{const $=P??D,K=s.trim();if(!$||!K||!r)return;if(!o){ne.error("Select a session to save comment");return}const A=Q($),S=ue(l(A)),B=d(A);x?i(o,x,{fileLabel:r,startLine:S.startLine,endLine:S.endLine,side:S.side,code:B,language:h,text:K}):u(o,{source:a,fileLabel:r,startLine:S.startLine,endLine:S.endLine,side:S.side,code:B,language:h,text:K}),C()},[u,x,r,d,h,C,D,a,o,l,i]);return{sessionKey:y,drafts:z,selection:D,setSelection:M,commentText:L,setCommentText:v,editingDraftId:x,setEditingDraftId:T,reset:C,cancel:V,startEdit:X,deleteDraft:G,saveComment:H,fromDraftRange:p}}export{ve as I,Ce as a,Q as n,we as u};