agent-canvas 0.1.5 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/ci.yml +23 -0
- package/.github/workflows/release.yml +36 -0
- package/CLAUDE.md +86 -0
- package/LICENSE +21 -0
- package/README.md +71 -0
- package/bin/agent-canvas.ts +26 -353
- package/bin/lib/commands/daemon.ts +51 -0
- package/bin/lib/commands/fetch.ts +20 -0
- package/bin/lib/commands/install.ts +48 -0
- package/bin/lib/commands/push.ts +67 -0
- package/bin/lib/commands/watch.ts +23 -0
- package/bin/lib/config.ts +10 -0
- package/bin/lib/daemon-lifecycle.ts +74 -0
- package/bin/lib/helpers.ts +78 -0
- package/bun.lock +176 -0
- package/daemon/build.ts +27 -61
- package/daemon/bunfig.toml +2 -0
- package/daemon/client/AnnotationProvider.tsx +2 -2
- package/daemon/client/AnnotationSidebar.tsx +199 -31
- package/daemon/client/App.tsx +39 -3
- package/daemon/client/FileBrowser.tsx +8 -7
- package/daemon/client/FileViewer.tsx +153 -16
- package/daemon/client/PlanRenderer.tsx +6 -3
- package/daemon/client/ResponsePreview.tsx +5 -116
- package/daemon/client/SessionSwitcher.tsx +21 -10
- package/daemon/client/compat/preact-all.ts +4 -0
- package/daemon/client/components/Markdown.tsx +44 -0
- package/daemon/client/components/ResponseNote.tsx +3 -8
- package/daemon/client/components/UserInput.tsx +2 -4
- package/daemon/client/components/index.ts +1 -0
- package/daemon/client/domDiff.ts +82 -2
- package/daemon/client/generateMarkdown.ts +46 -9
- package/daemon/client/highlightRange.ts +8 -6
- package/daemon/client/runtime.ts +2 -0
- package/daemon/client/styles.css +126 -0
- package/daemon/client/unifiedDiff.ts +155 -2
- package/daemon/client/utils.ts +10 -0
- package/daemon/dist/client.css +1 -1
- package/daemon/dist/client.js +83 -36
- package/daemon/dist/components.js +63 -5
- package/daemon/dist/index.html +5 -12
- package/daemon/dist/jsx-runtime.js +3 -0
- package/daemon/dist/preact-compat.js +1 -0
- package/daemon/langMap.ts +8 -0
- package/daemon/src/compiler.ts +28 -2
- package/daemon/src/handlers/api.ts +150 -0
- package/daemon/src/handlers/files.ts +114 -0
- package/daemon/src/handlers/static.ts +61 -0
- package/daemon/src/handlers/utils.ts +14 -0
- package/daemon/src/router.ts +16 -0
- package/daemon/src/server.ts +28 -403
- package/daemon/src/session.ts +43 -24
- package/daemon/src/websocket.ts +83 -0
- package/daemon/tsconfig.json +20 -0
- package/package.json +4 -14
- package/skills/canvas/SKILL.md +47 -22
- package/skills/canvas/components.md +31 -0
- package/skills/canvas/flows.md +2 -2
- package/tsconfig.json +14 -0
- package/daemon/dist/jsx-dev-runtime-shim.js +0 -17
- package/daemon/dist/jsx-runtime-shim.js +0 -17
- package/daemon/dist/react-dom-client-shim.js +0 -4
- package/daemon/dist/react-dom-shim.js +0 -4
- package/daemon/dist/react-shim.js +0 -4
package/daemon/dist/client.js
CHANGED
|
@@ -1,4 +1,62 @@
|
|
|
1
|
-
import
|
|
1
|
+
import g1,{useEffect as X0,useLayoutEffect as m$,useState as Q1,useCallback as C0,useRef as d1,createContext as W2,useMemo as j$}from"react";import{createRoot as I$}from"react-dom/client";function I0(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var R1=I0();function U5(J){R1=J}var A1={exec:()=>null};function v(J,$=""){let Q=typeof J=="string"?J:J.source,Z={replace:(Y,X)=>{let q=typeof X=="string"?X:X.source;return q=q.replace(J1.caret,"$1"),Q=Q.replace(Y,q),Z},getRegex:()=>new RegExp(Q,$)};return Z}var y2=(()=>{try{return!!new RegExp("(?<=1)(?<!1)")}catch{return!1}})(),J1={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] +\S/,listReplaceTask:/^\[[ xX]\] +/,listTaskCheckbox:/\[[ xX]\]/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:(J)=>new RegExp(`^( {0,3}${J})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:(J)=>new RegExp(`^ {0,${Math.min(3,J-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),hrRegex:(J)=>new RegExp(`^ {0,${Math.min(3,J-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:(J)=>new RegExp(`^ {0,${Math.min(3,J-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:(J)=>new RegExp(`^ {0,${Math.min(3,J-1)}}#`),htmlBeginRegex:(J)=>new RegExp(`^ {0,${Math.min(3,J-1)}}<(?:[a-z].*>|!--)`,"i"),blockquoteBeginRegex:(J)=>new RegExp(`^ {0,${Math.min(3,J-1)}}>`)},M2=/^(?:[ \t]*(?:\n|$))+/,B2=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,L2=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,s1=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,P2=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,V0=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,G5=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,H5=v(G5).replace(/bull/g,V0).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/\|table/g,"").getRegex(),S2=v(G5).replace(/bull/g,V0).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),g0=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,b2=/^[^\n]+/,D0=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,A2=v(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",D0).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),w2=v(/^(bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,V0).getRegex(),H0="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",f0=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,R2=v("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$))","i").replace("comment",f0).replace("tag",H0).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),N5=v(g0).replace("hr",s1).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\t]").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",H0).getRegex(),C2=v(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",N5).getRegex(),k0={blockquote:C2,code:B2,def:A2,fences:L2,heading:P2,hr:s1,html:R2,lheading:H5,list:w2,newline:M2,paragraph:N5,table:A1,text:b2},Z5=v("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",s1).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code","(?: {4}| {0,3}\t)[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\t]").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",H0).getRegex(),m2={...k0,lheading:S2,table:Z5,paragraph:v(g0).replace("hr",s1).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",Z5).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\t]").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",H0).getRegex()},j2={...k0,html:v(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",f0).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:A1,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:v(g0).replace("hr",s1).replace("heading",` *#{1,6} *[^
|
|
2
|
+
]`).replace("lheading",H5).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},I2=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,V2=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,W5=/^( {2,}|\\)\n(?!\s*$)/,g2=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,N0=/[\p{P}\p{S}]/u,u0=/[\s\p{P}\p{S}]/u,T5=/[^\s\p{P}\p{S}]/u,D2=v(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,u0).getRegex(),O5=/(?!~)[\p{P}\p{S}]/u,f2=/(?!~)[\s\p{P}\p{S}]/u,k2=/(?:[^\s\p{P}\p{S}]|~)/u,F5=/(?![*_])[\p{P}\p{S}]/u,u2=/(?![*_])[\s\p{P}\p{S}]/u,v2=/(?:[^\s\p{P}\p{S}]|[*_])/u,E2=v(/link|precode-code|html/,"g").replace("link",/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-",y2?"(?<!`)()":"(^^|[^`])").replace("code",/(?<b>`+)[^`]+\k<b>(?!`)/).replace("html",/<(?! )[^<>]*?>/).getRegex(),y5=/^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/,x2=v(y5,"u").replace(/punct/g,N0).getRegex(),h2=v(y5,"u").replace(/punct/g,O5).getRegex(),M5="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",p2=v(M5,"gu").replace(/notPunctSpace/g,T5).replace(/punctSpace/g,u0).replace(/punct/g,N0).getRegex(),c2=v(M5,"gu").replace(/notPunctSpace/g,k2).replace(/punctSpace/g,f2).replace(/punct/g,O5).getRegex(),d2=v("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,T5).replace(/punctSpace/g,u0).replace(/punct/g,N0).getRegex(),r2=v(/^~~?(?:((?!~)punct)|[^\s~])/,"u").replace(/punct/g,F5).getRegex(),l2="^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)",a2=v(l2,"gu").replace(/notPunctSpace/g,v2).replace(/punctSpace/g,u2).replace(/punct/g,F5).getRegex(),i2=v(/\\(punct)/,"gu").replace(/punct/g,N0).getRegex(),o2=v(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace("scheme",/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace("email",/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),s2=v(f0).replace("(?:-->|$)","-->").getRegex(),t2=v("^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>").replace("comment",s2).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),K0=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+[^`]*?`+(?!`)|[^\[\]\\`])*?/,n2=v(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/).replace("label",K0).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),B5=v(/^!?\[(label)\]\[(ref)\]/).replace("label",K0).replace("ref",D0).getRegex(),L5=v(/^!?\[(ref)\](?:\[\])?/).replace("ref",D0).getRegex(),e2=v("reflink|nolink(?!\\()","g").replace("reflink",B5).replace("nolink",L5).getRegex(),q5=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,v0={_backpedal:A1,anyPunctuation:i2,autolink:o2,blockSkip:E2,br:W5,code:V2,del:A1,delLDelim:A1,delRDelim:A1,emStrongLDelim:x2,emStrongRDelimAst:p2,emStrongRDelimUnd:d2,escape:I2,link:n2,nolink:L5,punctuation:D2,reflink:B5,reflinkSearch:e2,tag:t2,text:g2,url:A1},$3={...v0,link:v(/^!?\[(label)\]\((.*?)\)/).replace("label",K0).getRegex(),reflink:v(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",K0).getRegex()},j0={...v0,emStrongRDelimAst:c2,emStrongLDelim:h2,delLDelim:r2,delRDelim:a2,url:v(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("protocol",q5).replace("email",/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/,text:v(/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace("protocol",q5).getRegex()},J3={...j0,br:v(W5).replace("{2,}","*").getRegex(),text:v(j0.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},_0={normal:k0,gfm:m2,pedantic:j2},a1={normal:v0,gfm:j0,breaks:J3,pedantic:$3},Y3={"&":"&","<":"<",">":">",'"':""","'":"'"},X5=(J)=>Y3[J];function G1(J,$){if($){if(J1.escapeTest.test(J))return J.replace(J1.escapeReplace,X5)}else if(J1.escapeTestNoEncode.test(J))return J.replace(J1.escapeReplaceNoEncode,X5);return J}function z5(J){try{J=encodeURI(J).replace(J1.percentDecode,"%")}catch{return null}return J}function _5(J,$){let Q=J.replace(J1.findPipe,(X,q,_)=>{let z=!1,K=q;for(;--K>=0&&_[K]==="\\";)z=!z;return z?"|":" |"}),Z=Q.split(J1.splitPipe),Y=0;if(Z[0].trim()||Z.shift(),Z.length>0&&!Z.at(-1)?.trim()&&Z.pop(),$)if(Z.length>$)Z.splice($);else for(;Z.length<$;)Z.push("");for(;Y<Z.length;Y++)Z[Y]=Z[Y].trim().replace(J1.slashPipe,"|");return Z}function i1(J,$,Q){let Z=J.length;if(Z===0)return"";let Y=0;for(;Y<Z;){let X=J.charAt(Z-Y-1);if(X===$&&!Q)Y++;else if(X!==$&&Q)Y++;else break}return J.slice(0,Z-Y)}function Q3(J,$){if(J.indexOf($[1])===-1)return-1;let Q=0;for(let Z=0;Z<J.length;Z++)if(J[Z]==="\\")Z++;else if(J[Z]===$[0])Q++;else if(J[Z]===$[1]&&(Q--,Q<0))return Z;return Q>0?-2:-1}function Z3(J,$=0){let Q=$,Z="";for(let Y of J)if(Y==="\t"){let X=4-Q%4;Z+=" ".repeat(X),Q+=X}else Z+=Y,Q++;return Z}function K5(J,$,Q,Z,Y){let X=$.href,q=$.title||null,_=J[1].replace(Y.other.outputLinkReplace,"$1");Z.state.inLink=!0;let z={type:J[0].charAt(0)==="!"?"image":"link",raw:Q,href:X,title:q,text:_,tokens:Z.inlineTokens(_)};return Z.state.inLink=!1,z}function q3(J,$,Q){let Z=J.match(Q.other.indentCodeCompensation);if(Z===null)return $;let Y=Z[1];return $.split(`
|
|
3
|
+
`).map((X)=>{let q=X.match(Q.other.beginningSpace);if(q===null)return X;let[_]=q;return _.length>=Y.length?X.slice(Y.length):X}).join(`
|
|
4
|
+
`)}var U0=class{options;rules;lexer;constructor(J){this.options=J||R1}space(J){let $=this.rules.block.newline.exec(J);if($&&$[0].length>0)return{type:"space",raw:$[0]}}code(J){let $=this.rules.block.code.exec(J);if($){let Q=$[0].replace(this.rules.other.codeRemoveIndent,"");return{type:"code",raw:$[0],codeBlockStyle:"indented",text:this.options.pedantic?Q:i1(Q,`
|
|
5
|
+
`)}}}fences(J){let $=this.rules.block.fences.exec(J);if($){let Q=$[0],Z=q3(Q,$[3]||"",this.rules);return{type:"code",raw:Q,lang:$[2]?$[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):$[2],text:Z}}}heading(J){let $=this.rules.block.heading.exec(J);if($){let Q=$[2].trim();if(this.rules.other.endingHash.test(Q)){let Z=i1(Q,"#");(this.options.pedantic||!Z||this.rules.other.endingSpaceChar.test(Z))&&(Q=Z.trim())}return{type:"heading",raw:$[0],depth:$[1].length,text:Q,tokens:this.lexer.inline(Q)}}}hr(J){let $=this.rules.block.hr.exec(J);if($)return{type:"hr",raw:i1($[0],`
|
|
6
|
+
`)}}blockquote(J){let $=this.rules.block.blockquote.exec(J);if($){let Q=i1($[0],`
|
|
7
|
+
`).split(`
|
|
8
|
+
`),Z="",Y="",X=[];for(;Q.length>0;){let q=!1,_=[],z;for(z=0;z<Q.length;z++)if(this.rules.other.blockquoteStart.test(Q[z]))_.push(Q[z]),q=!0;else if(!q)_.push(Q[z]);else break;Q=Q.slice(z);let K=_.join(`
|
|
9
|
+
`),U=K.replace(this.rules.other.blockquoteSetextReplace,`
|
|
10
|
+
$1`).replace(this.rules.other.blockquoteSetextReplace2,"");Z=Z?`${Z}
|
|
11
|
+
${K}`:K,Y=Y?`${Y}
|
|
12
|
+
${U}`:U;let H=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(U,X,!0),this.lexer.state.top=H,Q.length===0)break;let G=X.at(-1);if(G?.type==="code")break;if(G?.type==="blockquote"){let N=G,W=N.raw+`
|
|
13
|
+
`+Q.join(`
|
|
14
|
+
`),M=this.blockquote(W);X[X.length-1]=M,Z=Z.substring(0,Z.length-N.raw.length)+M.raw,Y=Y.substring(0,Y.length-N.text.length)+M.text;break}else if(G?.type==="list"){let N=G,W=N.raw+`
|
|
15
|
+
`+Q.join(`
|
|
16
|
+
`),M=this.list(W);X[X.length-1]=M,Z=Z.substring(0,Z.length-G.raw.length)+M.raw,Y=Y.substring(0,Y.length-N.raw.length)+M.raw,Q=W.substring(X.at(-1).raw.length).split(`
|
|
17
|
+
`);continue}}return{type:"blockquote",raw:Z,tokens:X,text:Y}}}list(J){let $=this.rules.block.list.exec(J);if($){let Q=$[1].trim(),Z=Q.length>1,Y={type:"list",raw:"",ordered:Z,start:Z?+Q.slice(0,-1):"",loose:!1,items:[]};Q=Z?`\\d{1,9}\\${Q.slice(-1)}`:`\\${Q}`,this.options.pedantic&&(Q=Z?Q:"[*+-]");let X=this.rules.other.listItemRegex(Q),q=!1;for(;J;){let z=!1,K="",U="";if(!($=X.exec(J))||this.rules.block.hr.test(J))break;K=$[0],J=J.substring(K.length);let H=Z3($[2].split(`
|
|
18
|
+
`,1)[0],$[1].length),G=J.split(`
|
|
19
|
+
`,1)[0],N=!H.trim(),W=0;if(this.options.pedantic?(W=2,U=H.trimStart()):N?W=$[1].length+1:(W=H.search(this.rules.other.nonSpaceChar),W=W>4?1:W,U=H.slice(W),W+=$[1].length),N&&this.rules.other.blankLine.test(G)&&(K+=G+`
|
|
20
|
+
`,J=J.substring(G.length+1),z=!0),!z){let M=this.rules.other.nextBulletRegex(W),F=this.rules.other.hrRegex(W),L=this.rules.other.fencesBeginRegex(W),y=this.rules.other.headingBeginRegex(W),S=this.rules.other.htmlBeginRegex(W),R=this.rules.other.blockquoteBeginRegex(W);for(;J;){let m=J.split(`
|
|
21
|
+
`,1)[0],k;if(G=m,this.options.pedantic?(G=G.replace(this.rules.other.listReplaceNesting," "),k=G):k=G.replace(this.rules.other.tabCharGlobal," "),L.test(G)||y.test(G)||S.test(G)||R.test(G)||M.test(G)||F.test(G))break;if(k.search(this.rules.other.nonSpaceChar)>=W||!G.trim())U+=`
|
|
22
|
+
`+k.slice(W);else{if(N||H.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||L.test(H)||y.test(H)||F.test(H))break;U+=`
|
|
23
|
+
`+G}N=!G.trim(),K+=m+`
|
|
24
|
+
`,J=J.substring(m.length+1),H=k.slice(W)}}Y.loose||(q?Y.loose=!0:this.rules.other.doubleBlankLine.test(K)&&(q=!0)),Y.items.push({type:"list_item",raw:K,task:!!this.options.gfm&&this.rules.other.listIsTask.test(U),loose:!1,text:U,tokens:[]}),Y.raw+=K}let _=Y.items.at(-1);if(_)_.raw=_.raw.trimEnd(),_.text=_.text.trimEnd();else return;Y.raw=Y.raw.trimEnd();for(let z of Y.items){if(this.lexer.state.top=!1,z.tokens=this.lexer.blockTokens(z.text,[]),z.task){if(z.text=z.text.replace(this.rules.other.listReplaceTask,""),z.tokens[0]?.type==="text"||z.tokens[0]?.type==="paragraph"){z.tokens[0].raw=z.tokens[0].raw.replace(this.rules.other.listReplaceTask,""),z.tokens[0].text=z.tokens[0].text.replace(this.rules.other.listReplaceTask,"");for(let U=this.lexer.inlineQueue.length-1;U>=0;U--)if(this.rules.other.listIsTask.test(this.lexer.inlineQueue[U].src)){this.lexer.inlineQueue[U].src=this.lexer.inlineQueue[U].src.replace(this.rules.other.listReplaceTask,"");break}}let K=this.rules.other.listTaskCheckbox.exec(z.raw);if(K){let U={type:"checkbox",raw:K[0]+" ",checked:K[0]!=="[ ]"};z.checked=U.checked,Y.loose?z.tokens[0]&&["paragraph","text"].includes(z.tokens[0].type)&&"tokens"in z.tokens[0]&&z.tokens[0].tokens?(z.tokens[0].raw=U.raw+z.tokens[0].raw,z.tokens[0].text=U.raw+z.tokens[0].text,z.tokens[0].tokens.unshift(U)):z.tokens.unshift({type:"paragraph",raw:U.raw,text:U.raw,tokens:[U]}):z.tokens.unshift(U)}}if(!Y.loose){let K=z.tokens.filter((H)=>H.type==="space"),U=K.length>0&&K.some((H)=>this.rules.other.anyLine.test(H.raw));Y.loose=U}}if(Y.loose)for(let z of Y.items){z.loose=!0;for(let K of z.tokens)K.type==="text"&&(K.type="paragraph")}return Y}}html(J){let $=this.rules.block.html.exec(J);if($)return{type:"html",block:!0,raw:$[0],pre:$[1]==="pre"||$[1]==="script"||$[1]==="style",text:$[0]}}def(J){let $=this.rules.block.def.exec(J);if($){let Q=$[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal," "),Z=$[2]?$[2].replace(this.rules.other.hrefBrackets,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",Y=$[3]?$[3].substring(1,$[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"):$[3];return{type:"def",tag:Q,raw:$[0],href:Z,title:Y}}}table(J){let $=this.rules.block.table.exec(J);if(!$||!this.rules.other.tableDelimiter.test($[2]))return;let Q=_5($[1]),Z=$[2].replace(this.rules.other.tableAlignChars,"").split("|"),Y=$[3]?.trim()?$[3].replace(this.rules.other.tableRowBlankLine,"").split(`
|
|
25
|
+
`):[],X={type:"table",raw:$[0],header:[],align:[],rows:[]};if(Q.length===Z.length){for(let q of Z)this.rules.other.tableAlignRight.test(q)?X.align.push("right"):this.rules.other.tableAlignCenter.test(q)?X.align.push("center"):this.rules.other.tableAlignLeft.test(q)?X.align.push("left"):X.align.push(null);for(let q=0;q<Q.length;q++)X.header.push({text:Q[q],tokens:this.lexer.inline(Q[q]),header:!0,align:X.align[q]});for(let q of Y)X.rows.push(_5(q,X.header.length).map((_,z)=>({text:_,tokens:this.lexer.inline(_),header:!1,align:X.align[z]})));return X}}lheading(J){let $=this.rules.block.lheading.exec(J);if($)return{type:"heading",raw:$[0],depth:$[2].charAt(0)==="="?1:2,text:$[1],tokens:this.lexer.inline($[1])}}paragraph(J){let $=this.rules.block.paragraph.exec(J);if($){let Q=$[1].charAt($[1].length-1)===`
|
|
26
|
+
`?$[1].slice(0,-1):$[1];return{type:"paragraph",raw:$[0],text:Q,tokens:this.lexer.inline(Q)}}}text(J){let $=this.rules.block.text.exec(J);if($)return{type:"text",raw:$[0],text:$[0],tokens:this.lexer.inline($[0])}}escape(J){let $=this.rules.inline.escape.exec(J);if($)return{type:"escape",raw:$[0],text:$[1]}}tag(J){let $=this.rules.inline.tag.exec(J);if($)return!this.lexer.state.inLink&&this.rules.other.startATag.test($[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&this.rules.other.endATag.test($[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&this.rules.other.startPreScriptTag.test($[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&this.rules.other.endPreScriptTag.test($[0])&&(this.lexer.state.inRawBlock=!1),{type:"html",raw:$[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:$[0]}}link(J){let $=this.rules.inline.link.exec(J);if($){let Q=$[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(Q)){if(!this.rules.other.endAngleBracket.test(Q))return;let X=i1(Q.slice(0,-1),"\\");if((Q.length-X.length)%2===0)return}else{let X=Q3($[2],"()");if(X===-2)return;if(X>-1){let q=($[0].indexOf("!")===0?5:4)+$[1].length+X;$[2]=$[2].substring(0,X),$[0]=$[0].substring(0,q).trim(),$[3]=""}}let Z=$[2],Y="";if(this.options.pedantic){let X=this.rules.other.pedanticHrefTitle.exec(Z);X&&(Z=X[1],Y=X[3])}else Y=$[3]?$[3].slice(1,-1):"";return Z=Z.trim(),this.rules.other.startAngleBracket.test(Z)&&(this.options.pedantic&&!this.rules.other.endAngleBracket.test(Q)?Z=Z.slice(1):Z=Z.slice(1,-1)),K5($,{href:Z&&Z.replace(this.rules.inline.anyPunctuation,"$1"),title:Y&&Y.replace(this.rules.inline.anyPunctuation,"$1")},$[0],this.lexer,this.rules)}}reflink(J,$){let Q;if((Q=this.rules.inline.reflink.exec(J))||(Q=this.rules.inline.nolink.exec(J))){let Z=(Q[2]||Q[1]).replace(this.rules.other.multipleSpaceGlobal," "),Y=$[Z.toLowerCase()];if(!Y){let X=Q[0].charAt(0);return{type:"text",raw:X,text:X}}return K5(Q,Y,Q[0],this.lexer,this.rules)}}emStrong(J,$,Q=""){let Z=this.rules.inline.emStrongLDelim.exec(J);if(!Z||Z[3]&&Q.match(this.rules.other.unicodeAlphaNumeric))return;if(!(Z[1]||Z[2])||!Q||this.rules.inline.punctuation.exec(Q)){let Y=[...Z[0]].length-1,X,q,_=Y,z=0,K=Z[0][0]==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(K.lastIndex=0,$=$.slice(-1*J.length+Y);(Z=K.exec($))!=null;){if(X=Z[1]||Z[2]||Z[3]||Z[4]||Z[5]||Z[6],!X)continue;if(q=[...X].length,Z[3]||Z[4]){_+=q;continue}else if((Z[5]||Z[6])&&Y%3&&!((Y+q)%3)){z+=q;continue}if(_-=q,_>0)continue;q=Math.min(q,q+_+z);let U=[...Z[0]][0].length,H=J.slice(0,Y+Z.index+U+q);if(Math.min(Y,q)%2){let N=H.slice(1,-1);return{type:"em",raw:H,text:N,tokens:this.lexer.inlineTokens(N)}}let G=H.slice(2,-2);return{type:"strong",raw:H,text:G,tokens:this.lexer.inlineTokens(G)}}}}codespan(J){let $=this.rules.inline.code.exec(J);if($){let Q=$[2].replace(this.rules.other.newLineCharGlobal," "),Z=this.rules.other.nonSpaceChar.test(Q),Y=this.rules.other.startingSpaceChar.test(Q)&&this.rules.other.endingSpaceChar.test(Q);return Z&&Y&&(Q=Q.substring(1,Q.length-1)),{type:"codespan",raw:$[0],text:Q}}}br(J){let $=this.rules.inline.br.exec(J);if($)return{type:"br",raw:$[0]}}del(J,$,Q=""){let Z=this.rules.inline.delLDelim.exec(J);if(!Z)return;if(!Z[1]||!Q||this.rules.inline.punctuation.exec(Q)){let Y=[...Z[0]].length-1,X,q,_=Y,z=this.rules.inline.delRDelim;for(z.lastIndex=0,$=$.slice(-1*J.length+Y);(Z=z.exec($))!=null;){if(X=Z[1]||Z[2]||Z[3]||Z[4]||Z[5]||Z[6],!X||(q=[...X].length,q!==Y))continue;if(Z[3]||Z[4]){_+=q;continue}if(_-=q,_>0)continue;q=Math.min(q,q+_);let K=[...Z[0]][0].length,U=J.slice(0,Y+Z.index+K+q),H=U.slice(Y,-Y);return{type:"del",raw:U,text:H,tokens:this.lexer.inlineTokens(H)}}}}autolink(J){let $=this.rules.inline.autolink.exec(J);if($){let Q,Z;return $[2]==="@"?(Q=$[1],Z="mailto:"+Q):(Q=$[1],Z=Q),{type:"link",raw:$[0],text:Q,href:Z,tokens:[{type:"text",raw:Q,text:Q}]}}}url(J){let $;if($=this.rules.inline.url.exec(J)){let Q,Z;if($[2]==="@")Q=$[0],Z="mailto:"+Q;else{let Y;do Y=$[0],$[0]=this.rules.inline._backpedal.exec($[0])?.[0]??"";while(Y!==$[0]);Q=$[0],$[1]==="www."?Z="http://"+$[0]:Z=$[0]}return{type:"link",raw:$[0],text:Q,href:Z,tokens:[{type:"text",raw:Q,text:Q}]}}}inlineText(J){let $=this.rules.inline.text.exec(J);if($){let Q=this.lexer.state.inRawBlock;return{type:"text",raw:$[0],text:$[0],escaped:Q}}}},_1=class J{tokens;options;state;inlineQueue;tokenizer;constructor($){this.tokens=[],this.tokens.links=Object.create(null),this.options=$||R1,this.options.tokenizer=this.options.tokenizer||new U0,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};let Q={other:J1,block:_0.normal,inline:a1.normal};this.options.pedantic?(Q.block=_0.pedantic,Q.inline=a1.pedantic):this.options.gfm&&(Q.block=_0.gfm,this.options.breaks?Q.inline=a1.breaks:Q.inline=a1.gfm),this.tokenizer.rules=Q}static get rules(){return{block:_0,inline:a1}}static lex($,Q){return new J(Q).lex($)}static lexInline($,Q){return new J(Q).inlineTokens($)}lex($){$=$.replace(J1.carriageReturn,`
|
|
27
|
+
`),this.blockTokens($,this.tokens);for(let Q=0;Q<this.inlineQueue.length;Q++){let Z=this.inlineQueue[Q];this.inlineTokens(Z.src,Z.tokens)}return this.inlineQueue=[],this.tokens}blockTokens($,Q=[],Z=!1){for(this.options.pedantic&&($=$.replace(J1.tabCharGlobal," ").replace(J1.spaceLine,""));$;){let Y;if(this.options.extensions?.block?.some((q)=>(Y=q.call({lexer:this},$,Q))?($=$.substring(Y.raw.length),Q.push(Y),!0):!1))continue;if(Y=this.tokenizer.space($)){$=$.substring(Y.raw.length);let q=Q.at(-1);Y.raw.length===1&&q!==void 0?q.raw+=`
|
|
28
|
+
`:Q.push(Y);continue}if(Y=this.tokenizer.code($)){$=$.substring(Y.raw.length);let q=Q.at(-1);q?.type==="paragraph"||q?.type==="text"?(q.raw+=(q.raw.endsWith(`
|
|
29
|
+
`)?"":`
|
|
30
|
+
`)+Y.raw,q.text+=`
|
|
31
|
+
`+Y.text,this.inlineQueue.at(-1).src=q.text):Q.push(Y);continue}if(Y=this.tokenizer.fences($)){$=$.substring(Y.raw.length),Q.push(Y);continue}if(Y=this.tokenizer.heading($)){$=$.substring(Y.raw.length),Q.push(Y);continue}if(Y=this.tokenizer.hr($)){$=$.substring(Y.raw.length),Q.push(Y);continue}if(Y=this.tokenizer.blockquote($)){$=$.substring(Y.raw.length),Q.push(Y);continue}if(Y=this.tokenizer.list($)){$=$.substring(Y.raw.length),Q.push(Y);continue}if(Y=this.tokenizer.html($)){$=$.substring(Y.raw.length),Q.push(Y);continue}if(Y=this.tokenizer.def($)){$=$.substring(Y.raw.length);let q=Q.at(-1);q?.type==="paragraph"||q?.type==="text"?(q.raw+=(q.raw.endsWith(`
|
|
32
|
+
`)?"":`
|
|
33
|
+
`)+Y.raw,q.text+=`
|
|
34
|
+
`+Y.raw,this.inlineQueue.at(-1).src=q.text):this.tokens.links[Y.tag]||(this.tokens.links[Y.tag]={href:Y.href,title:Y.title},Q.push(Y));continue}if(Y=this.tokenizer.table($)){$=$.substring(Y.raw.length),Q.push(Y);continue}if(Y=this.tokenizer.lheading($)){$=$.substring(Y.raw.length),Q.push(Y);continue}let X=$;if(this.options.extensions?.startBlock){let q=1/0,_=$.slice(1),z;this.options.extensions.startBlock.forEach((K)=>{z=K.call({lexer:this},_),typeof z=="number"&&z>=0&&(q=Math.min(q,z))}),q<1/0&&q>=0&&(X=$.substring(0,q+1))}if(this.state.top&&(Y=this.tokenizer.paragraph(X))){let q=Q.at(-1);Z&&q?.type==="paragraph"?(q.raw+=(q.raw.endsWith(`
|
|
35
|
+
`)?"":`
|
|
36
|
+
`)+Y.raw,q.text+=`
|
|
37
|
+
`+Y.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=q.text):Q.push(Y),Z=X.length!==$.length,$=$.substring(Y.raw.length);continue}if(Y=this.tokenizer.text($)){$=$.substring(Y.raw.length);let q=Q.at(-1);q?.type==="text"?(q.raw+=(q.raw.endsWith(`
|
|
38
|
+
`)?"":`
|
|
39
|
+
`)+Y.raw,q.text+=`
|
|
40
|
+
`+Y.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=q.text):Q.push(Y);continue}if($){let q="Infinite loop on byte: "+$.charCodeAt(0);if(this.options.silent){console.error(q);break}else throw Error(q)}}return this.state.top=!0,Q}inline($,Q=[]){return this.inlineQueue.push({src:$,tokens:Q}),Q}inlineTokens($,Q=[]){let Z=$,Y=null;if(this.tokens.links){let z=Object.keys(this.tokens.links);if(z.length>0)for(;(Y=this.tokenizer.rules.inline.reflinkSearch.exec(Z))!=null;)z.includes(Y[0].slice(Y[0].lastIndexOf("[")+1,-1))&&(Z=Z.slice(0,Y.index)+"["+"a".repeat(Y[0].length-2)+"]"+Z.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;(Y=this.tokenizer.rules.inline.anyPunctuation.exec(Z))!=null;)Z=Z.slice(0,Y.index)+"++"+Z.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);let X;for(;(Y=this.tokenizer.rules.inline.blockSkip.exec(Z))!=null;)X=Y[2]?Y[2].length:0,Z=Z.slice(0,Y.index+X)+"["+"a".repeat(Y[0].length-X-2)+"]"+Z.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);Z=this.options.hooks?.emStrongMask?.call({lexer:this},Z)??Z;let q=!1,_="";for(;$;){q||(_=""),q=!1;let z;if(this.options.extensions?.inline?.some((U)=>(z=U.call({lexer:this},$,Q))?($=$.substring(z.raw.length),Q.push(z),!0):!1))continue;if(z=this.tokenizer.escape($)){$=$.substring(z.raw.length),Q.push(z);continue}if(z=this.tokenizer.tag($)){$=$.substring(z.raw.length),Q.push(z);continue}if(z=this.tokenizer.link($)){$=$.substring(z.raw.length),Q.push(z);continue}if(z=this.tokenizer.reflink($,this.tokens.links)){$=$.substring(z.raw.length);let U=Q.at(-1);z.type==="text"&&U?.type==="text"?(U.raw+=z.raw,U.text+=z.text):Q.push(z);continue}if(z=this.tokenizer.emStrong($,Z,_)){$=$.substring(z.raw.length),Q.push(z);continue}if(z=this.tokenizer.codespan($)){$=$.substring(z.raw.length),Q.push(z);continue}if(z=this.tokenizer.br($)){$=$.substring(z.raw.length),Q.push(z);continue}if(z=this.tokenizer.del($,Z,_)){$=$.substring(z.raw.length),Q.push(z);continue}if(z=this.tokenizer.autolink($)){$=$.substring(z.raw.length),Q.push(z);continue}if(!this.state.inLink&&(z=this.tokenizer.url($))){$=$.substring(z.raw.length),Q.push(z);continue}let K=$;if(this.options.extensions?.startInline){let U=1/0,H=$.slice(1),G;this.options.extensions.startInline.forEach((N)=>{G=N.call({lexer:this},H),typeof G=="number"&&G>=0&&(U=Math.min(U,G))}),U<1/0&&U>=0&&(K=$.substring(0,U+1))}if(z=this.tokenizer.inlineText(K)){$=$.substring(z.raw.length),z.raw.slice(-1)!=="_"&&(_=z.raw.slice(-1)),q=!0;let U=Q.at(-1);U?.type==="text"?(U.raw+=z.raw,U.text+=z.text):Q.push(z);continue}if($){let U="Infinite loop on byte: "+$.charCodeAt(0);if(this.options.silent){console.error(U);break}else throw Error(U)}}return Q}},G0=class{options;parser;constructor(J){this.options=J||R1}space(J){return""}code({text:J,lang:$,escaped:Q}){let Z=($||"").match(J1.notSpaceStart)?.[0],Y=J.replace(J1.endingNewline,"")+`
|
|
41
|
+
`;return Z?'<pre><code class="language-'+G1(Z)+'">'+(Q?Y:G1(Y,!0))+`</code></pre>
|
|
42
|
+
`:"<pre><code>"+(Q?Y:G1(Y,!0))+`</code></pre>
|
|
43
|
+
`}blockquote({tokens:J}){return`<blockquote>
|
|
44
|
+
${this.parser.parse(J)}</blockquote>
|
|
45
|
+
`}html({text:J}){return J}def(J){return""}heading({tokens:J,depth:$}){return`<h${$}>${this.parser.parseInline(J)}</h${$}>
|
|
46
|
+
`}hr(J){return`<hr>
|
|
47
|
+
`}list(J){let{ordered:$,start:Q}=J,Z="";for(let q=0;q<J.items.length;q++){let _=J.items[q];Z+=this.listitem(_)}let Y=$?"ol":"ul",X=$&&Q!==1?' start="'+Q+'"':"";return"<"+Y+X+`>
|
|
48
|
+
`+Z+"</"+Y+`>
|
|
49
|
+
`}listitem(J){return`<li>${this.parser.parse(J.tokens)}</li>
|
|
50
|
+
`}checkbox({checked:J}){return"<input "+(J?'checked="" ':"")+'disabled="" type="checkbox"> '}paragraph({tokens:J}){return`<p>${this.parser.parseInline(J)}</p>
|
|
51
|
+
`}table(J){let $="",Q="";for(let Y=0;Y<J.header.length;Y++)Q+=this.tablecell(J.header[Y]);$+=this.tablerow({text:Q});let Z="";for(let Y=0;Y<J.rows.length;Y++){let X=J.rows[Y];Q="";for(let q=0;q<X.length;q++)Q+=this.tablecell(X[q]);Z+=this.tablerow({text:Q})}return Z&&(Z=`<tbody>${Z}</tbody>`),`<table>
|
|
52
|
+
<thead>
|
|
53
|
+
`+$+`</thead>
|
|
54
|
+
`+Z+`</table>
|
|
55
|
+
`}tablerow({text:J}){return`<tr>
|
|
56
|
+
${J}</tr>
|
|
57
|
+
`}tablecell(J){let $=this.parser.parseInline(J.tokens),Q=J.header?"th":"td";return(J.align?`<${Q} align="${J.align}">`:`<${Q}>`)+$+`</${Q}>
|
|
58
|
+
`}strong({tokens:J}){return`<strong>${this.parser.parseInline(J)}</strong>`}em({tokens:J}){return`<em>${this.parser.parseInline(J)}</em>`}codespan({text:J}){return`<code>${G1(J,!0)}</code>`}br(J){return"<br>"}del({tokens:J}){return`<del>${this.parser.parseInline(J)}</del>`}link({href:J,title:$,tokens:Q}){let Z=this.parser.parseInline(Q),Y=z5(J);if(Y===null)return Z;J=Y;let X='<a href="'+J+'"';return $&&(X+=' title="'+G1($)+'"'),X+=">"+Z+"</a>",X}image({href:J,title:$,text:Q,tokens:Z}){Z&&(Q=this.parser.parseInline(Z,this.parser.textRenderer));let Y=z5(J);if(Y===null)return G1(Q);J=Y;let X=`<img src="${J}" alt="${G1(Q)}"`;return $&&(X+=` title="${G1($)}"`),X+=">",X}text(J){return"tokens"in J&&J.tokens?this.parser.parseInline(J.tokens):("escaped"in J)&&J.escaped?J.text:G1(J.text)}},E0=class{strong({text:J}){return J}em({text:J}){return J}codespan({text:J}){return J}del({text:J}){return J}html({text:J}){return J}text({text:J}){return J}link({text:J}){return""+J}image({text:J}){return""+J}br(){return""}checkbox({raw:J}){return J}},K1=class J{options;renderer;textRenderer;constructor($){this.options=$||R1,this.options.renderer=this.options.renderer||new G0,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new E0}static parse($,Q){return new J(Q).parse($)}static parseInline($,Q){return new J(Q).parseInline($)}parse($){let Q="";for(let Z=0;Z<$.length;Z++){let Y=$[Z];if(this.options.extensions?.renderers?.[Y.type]){let q=Y,_=this.options.extensions.renderers[q.type].call({parser:this},q);if(_!==!1||!["space","hr","heading","code","table","blockquote","list","html","def","paragraph","text"].includes(q.type)){Q+=_||"";continue}}let X=Y;switch(X.type){case"space":{Q+=this.renderer.space(X);break}case"hr":{Q+=this.renderer.hr(X);break}case"heading":{Q+=this.renderer.heading(X);break}case"code":{Q+=this.renderer.code(X);break}case"table":{Q+=this.renderer.table(X);break}case"blockquote":{Q+=this.renderer.blockquote(X);break}case"list":{Q+=this.renderer.list(X);break}case"checkbox":{Q+=this.renderer.checkbox(X);break}case"html":{Q+=this.renderer.html(X);break}case"def":{Q+=this.renderer.def(X);break}case"paragraph":{Q+=this.renderer.paragraph(X);break}case"text":{Q+=this.renderer.text(X);break}default:{let q='Token with "'+X.type+'" type was not found.';if(this.options.silent)return console.error(q),"";throw Error(q)}}}return Q}parseInline($,Q=this.renderer){let Z="";for(let Y=0;Y<$.length;Y++){let X=$[Y];if(this.options.extensions?.renderers?.[X.type]){let _=this.options.extensions.renderers[X.type].call({parser:this},X);if(_!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(X.type)){Z+=_||"";continue}}let q=X;switch(q.type){case"escape":{Z+=Q.text(q);break}case"html":{Z+=Q.html(q);break}case"link":{Z+=Q.link(q);break}case"image":{Z+=Q.image(q);break}case"checkbox":{Z+=Q.checkbox(q);break}case"strong":{Z+=Q.strong(q);break}case"em":{Z+=Q.em(q);break}case"codespan":{Z+=Q.codespan(q);break}case"br":{Z+=Q.br(q);break}case"del":{Z+=Q.del(q);break}case"text":{Z+=Q.text(q);break}default:{let _='Token with "'+q.type+'" type was not found.';if(this.options.silent)return console.error(_),"";throw Error(_)}}}return Z}},o1=class{options;block;constructor(J){this.options=J||R1}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens","emStrongMask"]);static passThroughHooksRespectAsync=new Set(["preprocess","postprocess","processAllTokens"]);preprocess(J){return J}postprocess(J){return J}processAllTokens(J){return J}emStrongMask(J){return J}provideLexer(){return this.block?_1.lex:_1.lexInline}provideParser(){return this.block?K1.parse:K1.parseInline}},X3=class{defaults=I0();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=K1;Renderer=G0;TextRenderer=E0;Lexer=_1;Tokenizer=U0;Hooks=o1;constructor(...J){this.use(...J)}walkTokens(J,$){let Q=[];for(let Z of J)switch(Q=Q.concat($.call(this,Z)),Z.type){case"table":{let Y=Z;for(let X of Y.header)Q=Q.concat(this.walkTokens(X.tokens,$));for(let X of Y.rows)for(let q of X)Q=Q.concat(this.walkTokens(q.tokens,$));break}case"list":{let Y=Z;Q=Q.concat(this.walkTokens(Y.items,$));break}default:{let Y=Z;this.defaults.extensions?.childTokens?.[Y.type]?this.defaults.extensions.childTokens[Y.type].forEach((X)=>{let q=Y[X].flat(1/0);Q=Q.concat(this.walkTokens(q,$))}):Y.tokens&&(Q=Q.concat(this.walkTokens(Y.tokens,$)))}}return Q}use(...J){let $=this.defaults.extensions||{renderers:{},childTokens:{}};return J.forEach((Q)=>{let Z={...Q};if(Z.async=this.defaults.async||Z.async||!1,Q.extensions&&(Q.extensions.forEach((Y)=>{if(!Y.name)throw Error("extension name required");if("renderer"in Y){let X=$.renderers[Y.name];X?$.renderers[Y.name]=function(...q){let _=Y.renderer.apply(this,q);return _===!1&&(_=X.apply(this,q)),_}:$.renderers[Y.name]=Y.renderer}if("tokenizer"in Y){if(!Y.level||Y.level!=="block"&&Y.level!=="inline")throw Error("extension level must be 'block' or 'inline'");let X=$[Y.level];X?X.unshift(Y.tokenizer):$[Y.level]=[Y.tokenizer],Y.start&&(Y.level==="block"?$.startBlock?$.startBlock.push(Y.start):$.startBlock=[Y.start]:Y.level==="inline"&&($.startInline?$.startInline.push(Y.start):$.startInline=[Y.start]))}"childTokens"in Y&&Y.childTokens&&($.childTokens[Y.name]=Y.childTokens)}),Z.extensions=$),Q.renderer){let Y=this.defaults.renderer||new G0(this.defaults);for(let X in Q.renderer){if(!(X in Y))throw Error(`renderer '${X}' does not exist`);if(["options","parser"].includes(X))continue;let q=X,_=Q.renderer[q],z=Y[q];Y[q]=(...K)=>{let U=_.apply(Y,K);return U===!1&&(U=z.apply(Y,K)),U||""}}Z.renderer=Y}if(Q.tokenizer){let Y=this.defaults.tokenizer||new U0(this.defaults);for(let X in Q.tokenizer){if(!(X in Y))throw Error(`tokenizer '${X}' does not exist`);if(["options","rules","lexer"].includes(X))continue;let q=X,_=Q.tokenizer[q],z=Y[q];Y[q]=(...K)=>{let U=_.apply(Y,K);return U===!1&&(U=z.apply(Y,K)),U}}Z.tokenizer=Y}if(Q.hooks){let Y=this.defaults.hooks||new o1;for(let X in Q.hooks){if(!(X in Y))throw Error(`hook '${X}' does not exist`);if(["options","block"].includes(X))continue;let q=X,_=Q.hooks[q],z=Y[q];o1.passThroughHooks.has(X)?Y[q]=(K)=>{if(this.defaults.async&&o1.passThroughHooksRespectAsync.has(X))return(async()=>{let H=await _.call(Y,K);return z.call(Y,H)})();let U=_.call(Y,K);return z.call(Y,U)}:Y[q]=(...K)=>{if(this.defaults.async)return(async()=>{let H=await _.apply(Y,K);return H===!1&&(H=await z.apply(Y,K)),H})();let U=_.apply(Y,K);return U===!1&&(U=z.apply(Y,K)),U}}Z.hooks=Y}if(Q.walkTokens){let Y=this.defaults.walkTokens,X=Q.walkTokens;Z.walkTokens=function(q){let _=[];return _.push(X.call(this,q)),Y&&(_=_.concat(Y.call(this,q))),_}}this.defaults={...this.defaults,...Z}}),this}setOptions(J){return this.defaults={...this.defaults,...J},this}lexer(J,$){return _1.lex(J,$??this.defaults)}parser(J,$){return K1.parse(J,$??this.defaults)}parseMarkdown(J){return($,Q)=>{let Z={...Q},Y={...this.defaults,...Z},X=this.onError(!!Y.silent,!!Y.async);if(this.defaults.async===!0&&Z.async===!1)return X(Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));if(typeof $>"u"||$===null)return X(Error("marked(): input parameter is undefined or null"));if(typeof $!="string")return X(Error("marked(): input parameter is of type "+Object.prototype.toString.call($)+", string expected"));if(Y.hooks&&(Y.hooks.options=Y,Y.hooks.block=J),Y.async)return(async()=>{let q=Y.hooks?await Y.hooks.preprocess($):$,_=await(Y.hooks?await Y.hooks.provideLexer():J?_1.lex:_1.lexInline)(q,Y),z=Y.hooks?await Y.hooks.processAllTokens(_):_;Y.walkTokens&&await Promise.all(this.walkTokens(z,Y.walkTokens));let K=await(Y.hooks?await Y.hooks.provideParser():J?K1.parse:K1.parseInline)(z,Y);return Y.hooks?await Y.hooks.postprocess(K):K})().catch(X);try{Y.hooks&&($=Y.hooks.preprocess($));let q=(Y.hooks?Y.hooks.provideLexer():J?_1.lex:_1.lexInline)($,Y);Y.hooks&&(q=Y.hooks.processAllTokens(q)),Y.walkTokens&&this.walkTokens(q,Y.walkTokens);let _=(Y.hooks?Y.hooks.provideParser():J?K1.parse:K1.parseInline)(q,Y);return Y.hooks&&(_=Y.hooks.postprocess(_)),_}catch(q){return X(q)}}}onError(J,$){return(Q)=>{if(Q.message+=`
|
|
59
|
+
Please report this to https://github.com/markedjs/marked.`,J){let Z="<p>An error occurred:</p><pre>"+G1(Q.message+"",!0)+"</pre>";return $?Promise.resolve(Z):Z}if($)return Promise.reject(Q);throw Q}}},w1=new X3;function E(J,$){return w1.parse(J,$)}E.options=E.setOptions=function(J){return w1.setOptions(J),E.defaults=w1.defaults,U5(E.defaults),E};E.getDefaults=I0;E.defaults=R1;E.use=function(...J){return w1.use(...J),E.defaults=w1.defaults,U5(E.defaults),E};E.walkTokens=function(J,$){return w1.walkTokens(J,$)};E.parseInline=w1.parseInline;E.Parser=K1;E.parser=K1.parse;E.Renderer=G0;E.TextRenderer=E0;E.Lexer=_1;E.lexer=_1.lex;E.Tokenizer=U0;E.Hooks=o1;E.parse=E;var{options:v$,setOptions:E$,use:x$,walkTokens:h$,parseInline:p$}=E;var c$=K1.parse,d$=_1.lex;import{SessionContext as T2,ActiveViewCtx as V$}from"#canvas/runtime";import{useState as n1,useCallback as y1,useEffect as P5,useRef as S5}from"react";import{AnnotationCtx as z3}from"#canvas/runtime";function H1(){return`ann-${Date.now()}-${Math.random().toString(36).slice(2,6)}`}function t1(J,$){J.style.height="auto",J.style.height=($?Math.max($,J.scrollHeight):J.scrollHeight)+"px"}import{useAnnotations as q1}from"#canvas/runtime";import{jsxDEV as G3}from"react/jsx-dev-runtime";function x0(J,$){return`canvas:${J}:rev:${$}`}function e1(J,$){try{let Q=localStorage.getItem(x0(J,$));if(!Q)return null;return JSON.parse(Q)}catch{return null}}function _3(J,$,Q){try{localStorage.setItem(x0(J,$),JSON.stringify(Q))}catch{}}function K3(J,$){try{localStorage.removeItem(x0(J,$))}catch{}}function b5({sessionId:J,revision:$,isReadOnly:Q,children:Z}){let Y=S5(`${J}:${$}`),[X,q]=n1(()=>{return e1(J,$)?.annotations??[]}),[_,z]=n1(()=>{return e1(J,$)?.generalNote??""}),[K,U]=n1(null),[H,G]=n1(()=>{let w=e1(J,$);return w?.responses?new Map(w.responses):new Map}),[N,W]=n1(()=>{let w=e1(J,$);return w?.feedbackEntries?new Map(w.feedbackEntries):new Map});P5(()=>{let w=`${J}:${$}`;if(w===Y.current)return;Y.current=w;let I=e1(J,$);q(I?.annotations??[]),z(I?.generalNote??""),G(I?.responses?new Map(I.responses):new Map),W(I?.feedbackEntries?new Map(I.feedbackEntries):new Map),U(null)},[J,$]);let M=S5(null);P5(()=>{if(Q)return;if(M.current)clearTimeout(M.current);return M.current=setTimeout(()=>{_3(J,$,{annotations:X,generalNote:_,responses:Array.from(H.entries()),feedbackEntries:Array.from(N.entries())})},300),()=>{if(M.current)clearTimeout(M.current)}},[X,_,H,N,J,$,Q]);let F=y1((w,I,T,B,c)=>{q((o)=>[...o,{id:w,snippet:I,note:T,createdAt:new Date().toISOString(),filePath:B,context:c}])},[]),L=y1((w,I,T)=>{F(H1(),w,I,T)},[F]),y=y1((w,I)=>{q((T)=>T.map((B)=>B.id===w?{...B,note:I}:B))},[]),S=y1((w)=>{U3(w),q((I)=>I.filter((T)=>T.id!==w)),U((I)=>I===w?null:I)},[]),R=y1((w,I)=>{G((T)=>{let B=new Map(T);return B.set(w,I),B})},[]),m=y1((w,I)=>{W((T)=>{let B=T.get(w);if(B&&B.markdown===I.markdown&&B.label===I.label&&B.required===I.required)return T;let c=new Map(T);return c.set(w,I),c})},[]),k=y1((w)=>{W((I)=>{if(!I.has(w))return I;let T=new Map(I);return T.delete(w),T})},[]),V=y1(()=>{for(let w of document.querySelectorAll("[data-annotation-id]"))A5(w);q([]),z(""),U(null),G(new Map),W(new Map),K3(J,$)},[J,$]);return G3(z3.Provider,{value:{annotations:X,addAnnotation:L,addAnnotationWithId:F,updateAnnotation:y,removeAnnotation:S,generalNote:_,setGeneralNote:z,clearAll:V,activeAnnotationId:K,setActiveAnnotationId:U,responses:H,setResponse:R,feedbackEntries:N,setFeedbackEntry:m,removeFeedbackEntry:k},children:Z},void 0,!1,void 0,this)}function U3(J){let $=document.querySelectorAll(`[data-annotation-id="${J}"]`);for(let Q of $)A5(Q)}function A5(J){let $=J.parentNode;if(!$)return;let Q=document.createTextNode(J.textContent||"");$.replaceChild(Q,J),$.normalize()}import c0,{useEffect as U1,useState as X1,useRef as D5,useContext as O3,useCallback as F3,useMemo as B0}from"react";import{createPortal as y3}from"react-dom";import{SessionContext as M3}from"#canvas/runtime";function u1(J,$){let Q=[],Z=H3(J);for(let Y of Z){let X=document.createRange();if(X.selectNodeContents(Y),Y===J.startContainer)X.setStart(Y,J.startOffset);if(Y===J.endContainer)X.setEnd(Y,J.endOffset);let q=X.toString();if(!q||!q.trim())continue;let _=document.createElement("mark");_.setAttribute("data-annotation-id",$),_.style.cssText=`
|
|
2
60
|
background: var(--color-highlight-annotation);
|
|
3
61
|
border-bottom: 1.5px solid var(--color-highlight-bg);
|
|
4
62
|
border-radius: 2px;
|
|
@@ -6,7 +64,7 @@ import U1,{useEffect as c1,useLayoutEffect as P2,useState as i,useCallback as d1
|
|
|
6
64
|
transition: background 150ms ease;
|
|
7
65
|
color: inherit;
|
|
8
66
|
padding: 1px 0;
|
|
9
|
-
`;try{X.surroundContents(
|
|
67
|
+
`;try{X.surroundContents(_)}catch{let z=X.extractContents();_.appendChild(z),X.insertNode(_)}Q.push(_)}return Q}function H3(J){let $=[],Q=J.commonAncestorContainer;if(Q.nodeType===Node.TEXT_NODE)return $.push(Q),$;let Z=document.createTreeWalker(Q,NodeFilter.SHOW_TEXT),Y;while(Y=Z.nextNode()){if(Y.parentElement?.classList.contains("select-none"))continue;if(J.intersectsNode(Y))$.push(Y)}return $}function C1(J,$){let Q=document.querySelectorAll(`[data-annotation-id="${J}"]`);for(let Z of Q)Z.style.cssText=$?`
|
|
10
68
|
background: var(--color-highlight-bg);
|
|
11
69
|
border-bottom: 1.5px solid var(--color-highlight-border);
|
|
12
70
|
border-radius: 2px;
|
|
@@ -22,47 +80,36 @@ import U1,{useEffect as c1,useLayoutEffect as P2,useState as i,useCallback as d1
|
|
|
22
80
|
transition: background 150ms ease;
|
|
23
81
|
color: inherit;
|
|
24
82
|
padding: 1px 0;
|
|
25
|
-
`}function I1($){let J=document.querySelectorAll("[data-annotation-id]");for(let Q of J){let Z=Q.getAttribute("data-annotation-id");Q.style.cssText=Z===$?`
|
|
26
|
-
background: var(--color-highlight-bg);
|
|
27
|
-
border-bottom: 1.5px solid var(--color-highlight-border);
|
|
28
|
-
border-radius: 2px;
|
|
29
|
-
cursor: pointer;
|
|
30
|
-
transition: background 150ms ease;
|
|
31
|
-
color: inherit;
|
|
32
|
-
padding: 1px 0;
|
|
33
|
-
`:`
|
|
34
|
-
background: var(--color-highlight-annotation);
|
|
35
|
-
border-bottom: 1.5px solid var(--color-highlight-bg);
|
|
36
|
-
border-radius: 2px;
|
|
37
|
-
cursor: pointer;
|
|
38
|
-
transition: background 150ms ease;
|
|
39
|
-
color: inherit;
|
|
40
|
-
padding: 1px 0;
|
|
41
|
-
`}}function R1($,J){let Q=document.querySelectorAll(`[data-annotation-id="${$}"]`);for(let Z of Q)Z.setAttribute("data-annotation-id",J)}function b1($,J){let Q=J.filter((q)=>!document.querySelector(`[data-annotation-id="${q.id}"]`));if(!Q.length)return;let Z=[],Y="",X=document.createTreeWalker($,NodeFilter.SHOW_TEXT),z;while(z=X.nextNode()){if(z.parentElement?.classList.contains("select-none"))continue;Z.push({node:z,start:Y.length}),Y+=z.textContent||""}for(let q of Q){let _=q.snippet;if(!_)continue;let U=[],K=0;while(!0){let O=Y.indexOf(_,K);if(O===-1)break;U.push(O),K=O+1}if(U.length===0)continue;let G=U[0];if(U.length>1&&q.context){let O=-1;for(let P of U){let w=0;if(q.context.before){let B=Y.slice(Math.max(0,P-80),P);if(B.includes(q.context.before))w+=2;else if(q.context.before.length>10&&B.includes(q.context.before.slice(-10)))w+=1}if(q.context.after){let B=Y.slice(P+_.length,P+_.length+80);if(B.includes(q.context.after))w+=2;else if(q.context.after.length>10&&B.includes(q.context.after.slice(0,10)))w+=1}if(w>O)O=w,G=P}}let W=G,T=G+_.length,N=W0(Z,W),S=W0(Z,T);if(!N||!S)continue;try{let O=document.createRange();O.setStart(N.node,N.offset),O.setEnd(S.node,S.offset),L1(O,q.id)}catch{}}}function W0($,J){for(let Q=$.length-1;Q>=0;Q--)if($[Q].start<=J){let Z=J-$[Q].start,Y=$[Q].node.textContent?.length??0;if(Z<=Y)return{node:$[Q].node,offset:Z}}return null}function j1($){let J=document.querySelectorAll(`[data-annotation-id="${$}"]`);for(let Q of J){let Z=Q.parentNode;if(!Z)continue;while(Q.firstChild)Z.insertBefore(Q.firstChild,Q);Z.removeChild(Q),Z.normalize()}}function F0($,J){let Q=T0($,"before",60),Z=T0($,"after",60),Y=K5($.startContainer,J);return{before:Q,after:Z,hierarchy:Y}}function T0($,J,Q){let Z=U5(J==="before"?$.startContainer:$.endContainer);if(!Z)return"";let Y="";if(J==="before"){let X=document.createTreeWalker(Z,NodeFilter.SHOW_TEXT),z;while(z=X.nextNode()){if(z===$.startContainer){Y+=(z.textContent||"").slice(0,$.startOffset);break}if(z.parentElement?.hasAttribute("data-annotation-id"))continue;Y+=z.textContent||""}if(Y.length>Q){Y=Y.slice(-Q);let q=Y.indexOf(" ");if(q>0)Y=Y.slice(q+1)}}else{let X=document.createTreeWalker(Z,NodeFilter.SHOW_TEXT),z=!1,q;while(q=X.nextNode()){if(q===$.endContainer){Y+=(q.textContent||"").slice($.endOffset),z=!0;continue}if(z){if(q.parentElement?.hasAttribute("data-annotation-id"))continue;Y+=q.textContent||""}}if(Y.length>Q){Y=Y.slice(0,Q);let _=Y.lastIndexOf(" ");if(_>0)Y=Y.slice(0,_)}}return Y.trim()}function U5($){let J=new Set(["DIV","P","LI","PRE","BLOCKQUOTE","SECTION","ARTICLE"]),Q=$.parentElement;while(Q){if(J.has(Q.tagName))return Q;Q=Q.parentElement}return null}function K5($,J){let Q=[],Z=$ instanceof Element?$:$.parentElement;while(Z&&Z!==J){let Y=Z.getAttribute?.("data-task-id");if(Y){let X=Z.querySelector(".font-semibold");if(X)Q.unshift(X.textContent?.trim()||Y)}if(Z.tagName==="DIV"&&Z.querySelector(":scope > button .font-heading, :scope > div .font-heading")){let X=Z.querySelector(".font-heading");if(X)Q.unshift(X.textContent?.trim()||"")}Z=Z.parentElement}return Q}function N0($){let J=$.snippet.trim(),Q=$.context,Z=J.length<30;if(Q&&Z&&(Q.before||Q.after)){let Y=[];if(Q.before)Y.push(`...${Q.before} `);if(Y.push(J),Q.after)Y.push(` ${Q.after}...`);return Y.join("")}return J}import{useEffect as m1,useRef as V1,useState as O1,useCallback as i1,useMemo as O0}from"react";import{createPortal as G5}from"react-dom";function L0($,J){let Y=J||document.body,X=$.getBoundingClientRect(),z=Y.getBoundingClientRect(),q=Y===document.body?window.scrollY:Y.scrollTop,_=X.bottom-z.top+q+8,U=Math.max(0,Math.min(X.left-z.left,z.width-280-12));return Y.style.position="relative",{style:{position:"absolute",top:`${_}px`,left:`${U}px`},parent:Y}}import{jsxDEV as r}from"react/jsx-dev-runtime";function B0({anchorEl:$,scrollContainer:J,onClose:Q,ignoreSelector:Z,zIndex:Y="50",padding:X="12px",width:z="280px",children:q}){let _=V1(null),U=V1(Q);U.current=Q;let{style:K,parent:G}=L0($,J);return m1(()=>{let W=setTimeout(()=>{let T=(N)=>{if(_.current&&!_.current.contains(N.target)){if(Z&&N.target.closest?.(Z))return;U.current(),document.removeEventListener("mousedown",T)}};return document.addEventListener("mousedown",T),()=>document.removeEventListener("mousedown",T)},0);return()=>clearTimeout(W)},[Z]),G5(r("div",{ref:_,style:{...K,zIndex:Y,width:z,background:"var(--color-bg-elevated)",border:"1px solid var(--color-border-hover)",borderRadius:"8px",boxShadow:"0 4px 12px var(--color-shadow)",padding:X,fontFamily:"'Inter', sans-serif"},children:q},void 0,!1,void 0,this),G)}var y0=[{label:"Clarity",items:["Unclear","Why?","Needs example","Missing context"]},{label:"Scope",items:["Overkill","Out of scope","Important","Risky"]},{label:"Action",items:["Simplify","Rethink","Expand on this","Skip this"]}],M0=y0.flatMap(($)=>$.items);function M1({anchorEl:$,scrollContainer:J,snippet:Q,truncateAt:Z=100,header:Y,onAdd:X,onCancel:z}){let[q,_]=O1(""),[U,K]=O1(null),[G,W]=O1(!1),T=V1(null);m1(()=>{T.current?.focus()},[]);let N=i1(()=>{if(q.trim())X(q.trim());else z()},[q,X,z]),S=q.trim().length>0?M0.filter((H)=>H.toLowerCase().startsWith(q.trim().toLowerCase())):M0,O=G?[]:S.length===1&&S[0].toLowerCase()===q.trim().toLowerCase()?[]:S,P=new Set(O),w=y0.map((H)=>({label:H.label,items:H.items.filter((y)=>P.has(y))})).filter((H)=>H.items.length>0),B=w.map((H)=>H.items),R=B.flat(),D=O0(()=>{if(U===null)return 0;let H=0;for(let y=0;y<B.length;y++){if(U<H+B[y].length)return y;H+=B[y].length}return 0},[U,B]),m=O0(()=>{if(U===null)return 0;let H=0;for(let y=0;y<D;y++)H+=B[y].length;return U-H},[U,D,B]),j=(H,y)=>{let E=0;for(let c=0;c<H;c++)E+=B[c].length;return E+y};m1(()=>{K(null),W(!1)},[q]);let C=i1((H)=>{_(H)},[]),I=Q.length>Z?Q.slice(0,Z)+"...":Q;return r(B0,{anchorEl:$,scrollContainer:J,onClose:z,width:"420px",children:[Y??r("div",{style:{fontSize:"11px",color:"var(--color-text-tertiary)",fontStyle:"italic",marginBottom:"8px",lineHeight:"1.4",display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical",overflow:"hidden"},children:["“",I,"”"]},void 0,!0,void 0,this),r("textarea",{ref:T,value:q,onChange:(H)=>_(H.target.value),onKeyDown:(H)=>{if(R.length>0&&(H.key==="ArrowDown"||H.key==="ArrowUp"||H.key==="ArrowLeft"||H.key==="ArrowRight")){if(H.preventDefault(),U===null){K(0);return}if(H.key==="ArrowDown"){let y=Math.min(m+1,B[D].length-1);K(j(D,y))}else if(H.key==="ArrowUp"){let y=Math.max(m-1,0);K(j(D,y))}else if(H.key==="ArrowRight"){let y=Math.min(D+1,B.length-1),E=Math.min(m,B[y].length-1);K(j(y,E))}else if(H.key==="ArrowLeft"){let y=Math.max(D-1,0),E=Math.min(m,B[y].length-1);K(j(y,E))}return}if(U!==null&&R.length>0){if(H.key==="Tab"){H.preventDefault(),C(R[U]);return}if(H.key==="Enter"&&!H.shiftKey){H.preventDefault(),X(R[U]);return}}if(H.key==="Enter"&&!H.shiftKey){H.preventDefault(),N();return}if(H.key==="Escape")if(R.length>0&&!G)W(!0);else z()},style:{width:"100%",minHeight:"60px",background:"transparent",border:"none",color:"var(--color-text-primary)",fontFamily:"'Inter', sans-serif",fontSize:"13px",lineHeight:"1.5",resize:"vertical",outline:"none"},placeholder:"Add your note..."},void 0,!1,void 0,this),r("div",{style:{display:"flex",justifyContent:"flex-end",gap:"8px",marginTop:"8px"},children:[r("button",{onClick:z,style:{fontSize:"11px",color:"var(--color-text-tertiary)",background:"none",border:"none",cursor:"pointer",padding:"4px 12px",fontFamily:"'Inter', sans-serif"},children:"Cancel"},void 0,!1,void 0,this),r("button",{onClick:N,style:{fontSize:"11px",fontWeight:500,padding:"4px 12px",borderRadius:"6px",background:"var(--color-highlight-bg)",color:"var(--color-text-primary)",border:"1px solid var(--color-highlight-border)",cursor:"pointer",fontFamily:"'Inter', sans-serif"},children:"Add"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),R.length>0&&r("div",{style:{marginTop:"6px",borderTop:"1px solid var(--color-border-subtle)",paddingTop:"8px",display:"flex",gap:"4px"},children:w.map((H)=>r("div",{style:{flex:1},children:[r("div",{style:{fontSize:"10px",fontWeight:600,color:"var(--color-text-disabled)",textTransform:"uppercase",letterSpacing:"0.05em",padding:"2px 6px",marginBottom:"2px",fontFamily:"'Inter', sans-serif"},children:H.label},void 0,!1,void 0,this),H.items.map((y)=>{let E=R.indexOf(y);return r("div",{onMouseDown:(c)=>{c.preventDefault(),c.stopPropagation(),C(y)},onMouseEnter:()=>K(E),style:{padding:"3px 6px",fontSize:"12px",borderRadius:"4px",fontFamily:"'Inter', sans-serif",color:E===U?"var(--color-text-primary)":"var(--color-text-secondary)",background:E===U?"var(--color-highlight-selected)":"transparent",cursor:"pointer"},children:[r("span",{style:{fontWeight:500},children:y.slice(0,q.trim().length)},void 0,!1,void 0,this),y.slice(q.trim().length)]},y,!0,void 0,this)})]},H.label,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function B1({anchorEl:$,scrollContainer:J,initialNote:Q,onUpdate:Z,onDelete:Y,onClose:X}){let[z,q]=O1(Q),_=V1(null),[U,K]=O1(!1);m1(()=>{let W=_.current;if(W)W.style.height="auto",W.style.height=W.scrollHeight+"px",W.focus(),W.setSelectionRange(W.value.length,W.value.length)},[]);let G=i1(()=>{if(!z.trim()){Y(),X();return}Z(z),X()},[z,Z,Y,X]);return r(B0,{anchorEl:$,scrollContainer:J,onClose:G,ignoreSelector:"[data-annotation-id]",zIndex:"60",padding:"10px 12px",children:[r("textarea",{ref:_,value:z,onChange:(W)=>{q(W.target.value),Z(W.target.value),W.target.style.height="auto",W.target.style.height=W.target.scrollHeight+"px"},onKeyDown:(W)=>{if(W.key==="Enter"&&!W.shiftKey)W.preventDefault(),G();if(W.key==="Escape")G()},style:{width:"100%",background:"transparent",border:"none",color:"var(--color-text-primary)",fontFamily:"'Inter', sans-serif",fontSize:"13px",lineHeight:"1.5",resize:"none",outline:"none",overflow:"hidden"}},void 0,!1,void 0,this),r("div",{style:{display:"flex",justifyContent:"flex-end",marginTop:"6px"},children:r("button",{onClick:()=>{Y(),X()},onMouseEnter:()=>K(!0),onMouseLeave:()=>K(!1),style:{fontSize:"11px",color:U?"var(--color-accent-red)":"var(--color-text-tertiary)",background:"none",border:"none",cursor:"pointer",padding:"2px 0",fontFamily:"'Inter', sans-serif"},children:"Delete"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{jsxDEV as x,Fragment as S0}from"react/jsx-dev-runtime";var s1="[data-md='item'], [data-md='section'], [data-md='table'] tbody tr, [data-md='callout'], [data-md='note'], [data-md='checklist-item'], [data-md='choice-option'], [data-md='multichoice-option'], [data-md='userinput'], [data-md='rangeinput'], [data-md='image']",o1="[data-md='item'], [data-md='section'], [data-md='table'] tbody tr, [data-md='callout'], [data-md='note'], [data-md='checklist-item'], [data-md='image']";function P0({revision:$}){let J=W5(N5),[Q,Z]=s(null),[Y,X]=s(null),[z,q]=s(!0),_=H5(null),{annotations:U,addAnnotationWithId:K,removeAnnotation:G,updateAnnotation:W,activeAnnotationId:T,setActiveAnnotationId:N}=o(),[S,O]=s(null),[P,w]=s(null),[B,R]=s(null),[D,m]=s(null),[j,C]=s(null),[I,H]=s(null),[y,E]=s(!1);n(()=>{q(!0),X(null),H(null),import(`/api/session/${J}/plan.js?rev=${$}&t=${Date.now()}`).then((L)=>{Z(()=>L.default),q(!1)}).catch((L)=>{X(L.message),q(!1)})},[J,$]),n(()=>{if(!Q||!_.current)return;let L=setTimeout(()=>{if(_.current)b1(_.current,U)},50);return()=>clearTimeout(L)},[Q]),n(()=>{I1(T)},[T]),n(()=>{let L=_.current;if(!L)return;let A=(b)=>{let V=b.target.closest("[data-annotation-id]");if(!V)return;b.stopPropagation();let p=V.getAttribute("data-annotation-id");if(p===T)w({anchorEl:V,annId:p});else N(p)},u=(b)=>{let V=b.target.closest("[data-annotation-id]");if(V){let p=V.getAttribute("data-annotation-id");N(p)}},h=(b)=>{let V=b.target.closest("[data-annotation-id]"),p=b.relatedTarget?.closest?.("[data-annotation-id]");if(V&&!p){if(!document.getElementById("ann-inline-popover"))N(null)}};return L.addEventListener("click",A),L.addEventListener("mouseover",u),L.addEventListener("mouseout",h),()=>{L.removeEventListener("click",A),L.removeEventListener("mouseover",u),L.removeEventListener("mouseout",h)}},[Q,U,T]);let c=D1(()=>{let L=new Map;for(let A of U)if(A.snippet.startsWith("["))L.set(A.snippet,A.id);return L},[U]);n(()=>{let L=_.current;if(!L)return;let A=(h)=>{if(j||B||P)return;let b=h.target;if(b.closest("[data-block-comment-btn]"))return;E(!1);let V=b.closest(s1);if(V&&L.contains(V)){let a=z1(L).indexOf(V);H(a>=0?a:null)}else H(null);let p=b.closest(o1);if(p&&L.contains(p)){m(p);let d=K1(p),a=d?c.get(d):void 0;if(a&&a!==T)N(a)}else m(null)},u=(h)=>{if(j||B||P)return;if(h.relatedTarget?.closest("[data-block-comment-btn]"))return;m(null),N(null)};return L.addEventListener("mousemove",A),L.addEventListener("mouseleave",u),()=>{L.removeEventListener("mousemove",A),L.removeEventListener("mouseleave",u)}},[Q,j,B,P,c,T]),n(()=>{let L=(A)=>{let u=A.target.tagName;if(u==="INPUT"||u==="TEXTAREA"||A.target.isContentEditable)return;if(j||B||P)return;let h=_.current;if(!h)return;if(A.key==="ArrowDown"){A.preventDefault(),E(!0);let b=z1(h);if(b.length===0)return;H((V)=>{if(V===null)return 0;return Math.min(V+1,b.length-1)})}else if(A.key==="ArrowUp"){A.preventDefault(),E(!0);let b=z1(h);if(b.length===0)return;H((V)=>{if(V===null)return b.length-1;return Math.max(V-1,0)})}else if(A.key==="a"||A.key==="A"){if(I===null||!h)return;A.preventDefault();let V=z1(h)[I];if(!V)return;let p=K1(V);if(!p)return;let d=c.get(p);if(d)N(d),C({anchorEl:V,snippet:p,annId:d});else C({anchorEl:V,snippet:p})}else if(A.key===" "||A.key==="Enter"){if(I===null)return;let V=z1(h)[I];if(!V)return;let p=V.getAttribute("data-md");if(p==="choice-option"||p==="multichoice-option")A.preventDefault(),V.dispatchEvent(new CustomEvent("kb-select",{bubbles:!0}));else if(p==="userinput"){A.preventDefault();let d=V.querySelector("textarea");if(d){d.focus();let a=(X1)=>{if(X1.key==="Escape")X1.preventDefault(),d.blur(),E(!0)};d.addEventListener("keydown",a),d.addEventListener("blur",()=>d.removeEventListener("keydown",a),{once:!0})}}else if(p==="rangeinput"){A.preventDefault();let d=V.querySelector("input[type='range']");if(d){d.focus();let a=(X1)=>{if(X1.key==="Escape"||X1.key==="ArrowUp"||X1.key==="ArrowDown")X1.preventDefault(),d.blur(),E(!0)};d.addEventListener("keydown",a),d.addEventListener("blur",()=>d.removeEventListener("keydown",a),{once:!0})}}}else if(A.key==="Escape")H(null),E(!1),N(null)};return document.addEventListener("keydown",L),()=>document.removeEventListener("keydown",L)},[I,j,B,P,c]),n(()=>{let L=_.current;if(!L||I===null||!y)return;let u=z1(L)[I];if(!u)return;u.style.outline="2px solid var(--color-accent-blue)",u.style.outlineOffset="-2px",u.style.borderRadius="8px",u.scrollIntoView({block:"nearest",behavior:"smooth"});let h=K1(u),b=h?c.get(h):void 0;if(b)N(b);return()=>{u.style.outline="",u.style.outlineOffset="",u.style.borderRadius=""}},[I,y,c]),n(()=>{let L=()=>$1();return document.addEventListener("mouseup",L),()=>document.removeEventListener("mouseup",L)},[]);let $1=T5(()=>{let L=window.getSelection();if(!L||L.isCollapsed||!L.toString().trim())return;if(!_.current)return;let A=L.getRangeAt(0);if(!_.current.contains(A.startContainer))return;if(A.startContainer.parentElement?.closest?.("[data-annotation-id]"))return;let u=L.toString().trim();if(u.length<2)return;let h=A.cloneRange(),b=F0(A,_.current),V=`__pending_${Date.now()}`;try{L1(h,V)}catch{}window.getSelection()?.removeAllRanges();let p=document.querySelectorAll(`[data-annotation-id="${V}"]`),d=p[p.length-1];if(!d)return;R({anchorEl:d,tempId:V,snippet:u,ctx:b})},[K]),Q1=D1(()=>Q?x(Q,{},void 0,!1,void 0,this):null,[Q]);if(z)return x("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-body",children:"Loading plan..."},void 0,!1,void 0,this);if(Y)return x("div",{className:"bg-accent-red-muted rounded-lg p-5",children:[x("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Compilation Error"},void 0,!1,void 0,this),x("pre",{className:"text-code font-mono text-text-secondary whitespace-pre-wrap",children:Y},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(!Q)return x("div",{className:"text-text-tertiary text-center py-8 font-body text-body",children:"No plan loaded"},void 0,!1,void 0,this);let M=document.getElementById("plan-scroll-container");return x(S0,{children:[x("div",{ref:_,className:"plan-content plan-updated",children:Q1},void 0,!1,void 0,this),S&&x(M5,{note:S.note,onSave:(L)=>{W(S.id,L),O(null)},onCancel:()=>O(null)},void 0,!1,void 0,this),P&&(()=>{let L=U.find((A)=>A.id===P.annId);if(!L)return null;return x(B1,{anchorEl:P.anchorEl,scrollContainer:M,initialNote:L.note,onUpdate:(A)=>W(P.annId,A),onDelete:()=>{G(P.annId),N(null)},onClose:()=>w(null)},void 0,!1,void 0,this)})(),B&&x(M1,{anchorEl:B.anchorEl,scrollContainer:M,snippet:B.snippet,truncateAt:80,onAdd:(L)=>{let A=`ann-${Date.now()}-${Math.random().toString(36).slice(2,6)}`;R1(B.tempId,A),K(A,B.snippet,L,void 0,B.ctx),R(null)},onCancel:()=>{j1(B.tempId),R(null)}},void 0,!1,void 0,this),x(L5,{containerRef:_,hoveredBlock:D,focusedBlockIndex:I,blockPopover:j,blockAnnotationMap:c,activeAnnotationId:T,onOpen:(L,A,u)=>{if(u)N(u),C({anchorEl:L,snippet:A,annId:u});else C({anchorEl:L,snippet:A})}},void 0,!1,void 0,this),j&&!j.annId&&x(M1,{anchorEl:j.anchorEl,scrollContainer:M,snippet:j.snippet,truncateAt:80,onAdd:(L)=>{let A=`ann-${Date.now()}-${Math.random().toString(36).slice(2,6)}`;K(A,j.snippet,L),C(null)},onCancel:()=>C(null)},void 0,!1,void 0,this),j?.annId&&(()=>{let L=U.find((A)=>A.id===j.annId);if(!L)return null;return x(B1,{anchorEl:j.anchorEl,scrollContainer:M,initialNote:L.note,onUpdate:(A)=>W(j.annId,A),onDelete:()=>{G(j.annId),N(null),C(null)},onClose:()=>C(null)},void 0,!1,void 0,this)})()]},void 0,!0,void 0,this)}function z1($){return Array.from($.querySelectorAll(s1))}function K1($){let J=$.getAttribute("data-md");if(J==="item"){let Q=$.getAttribute("data-md-label");return Q?`[Item] ${Q}`:null}if(J==="section"){let Q=$.getAttribute("data-md-title");return Q?`[Section] ${Q}`:null}if(J==="callout"){let Q=$.getAttribute("data-md-type")||"info",Z=$.textContent?.trim().slice(0,60)||"Callout";return`[Callout:${Q}] ${Z}`}if(J==="note")return`[Note] ${$.textContent?.trim().slice(0,60)||"Note"}`;if($.tagName==="TR"){let Q=Array.from($.querySelectorAll("td")).map((Z)=>Z.textContent?.trim()).filter(Boolean);return Q.length?`[Row] ${Q.join(" | ")}`:null}if(J==="checklist-item"){let Q=$.getAttribute("data-md-label");return Q?`[Checklist] ${Q}`:null}if(J==="choice-option"||J==="multichoice-option"){let Q=$.getAttribute("data-md-label");return Q?`[Option] ${Q}`:null}if(J==="userinput"){let Q=$.getAttribute("data-md-label");return Q?`[Input] ${Q}`:null}if(J==="rangeinput"){let Q=$.getAttribute("data-md-label");return Q?`[Range] ${Q}`:null}if(J==="image"){let Q=$.getAttribute("data-md-src");return Q?`[Image] ${Q}`:null}return null}function L5({containerRef:$,hoveredBlock:J,focusedBlockIndex:Q,blockPopover:Z,blockAnnotationMap:Y,activeAnnotationId:X,onOpen:z}){let[q,_]=s([]);n(()=>{let T=$.current;if(!T||Y.size===0){_([]);return}let N=[];for(let S of T.querySelectorAll(o1)){let O=K1(S);if(O&&Y.has(O))N.push(S)}_(N)},[Y,$.current]);let[U,K]=s(null);n(()=>{if(!X||!$.current){K(null);return}for(let T of $.current.querySelectorAll(s1)){let N=K1(T);if(N&&Y.get(N)===X){K(T);return}}K(null)},[X,Y]),n(()=>{if(!U)return;return U.style.boxShadow="inset 0 0 0 1.5px var(--color-highlight-bg)",U.style.borderRadius="8px",()=>{U.style.boxShadow="",U.style.borderRadius=""}},[U]);let G=D1(()=>{if(Q===null||!$.current)return null;let T=z1($.current)[Q];if(!T)return null;return T.matches(o1)?T:null},[Q,$.current]),W=D1(()=>{let T=new Set(q);if(J)T.add(J);if(G)T.add(G);if(Z?.anchorEl)T.add(Z.anchorEl);return Array.from(T)},[q,J,G,Z]);return x(S0,{children:W.map((T)=>x(O5,{block:T,isHovered:T===J||T===G||T===Z?.anchorEl,blockAnnotationMap:Y,activeAnnotationId:X,onOpen:z},T.getAttribute("data-task-id")||T.getAttribute("data-md-title")||T.textContent?.slice(0,30)||"block",!1,void 0,this))},void 0,!1,void 0,this)}function O5({block:$,isHovered:J,blockAnnotationMap:Q,activeAnnotationId:Z,onOpen:Y}){let X=K1($);if(!X)return null;let z=Q.get(X),q=!!z;return F5(x("button",{"data-block-comment-btn":!0,onClick:(U)=>{U.stopPropagation(),Y(U.currentTarget,X,z)},className:`absolute top-1 right-1 z-10 w-6 h-6 flex items-center justify-center rounded transition-all duration-150 ${q?z===Z?"text-accent-amber bg-accent-amber-muted":"text-accent-amber opacity-60 hover:opacity-100":J?"text-text-disabled hover:text-text-tertiary opacity-50 hover:opacity-100":"text-text-disabled opacity-0 group-hover/section:opacity-20 hover:!opacity-80"}`,title:q?"Edit annotation":"Add annotation",children:x("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:q?"currentColor":"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:x("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),$)}function M5({note:$,onSave:J,onCancel:Q}){let[Z,Y]=a1.useState($),X=a1.useRef(null);return a1.useEffect(()=>{X.current?.focus(),X.current?.select()},[]),x("div",{className:"fixed inset-0 z-50 bg-black/40 flex items-center justify-center",onClick:Q,children:x("div",{className:"bg-bg-elevated border border-border-hover rounded-lg shadow-md p-4 w-80",onClick:(z)=>z.stopPropagation(),children:[x("div",{className:"text-tiny uppercase tracking-widest text-text-tertiary font-body mb-2",children:"Edit annotation"},void 0,!1,void 0,this),x("textarea",{ref:X,value:Z,onChange:(z)=>Y(z.target.value),className:"w-full bg-transparent border-none text-body font-body text-text-primary resize-vertical focus:outline-none min-h-[60px]",onKeyDown:(z)=>{if(z.key==="Enter"&&(z.ctrlKey||z.metaKey))J(Z.trim());if(z.key==="Escape")Q()}},void 0,!1,void 0,this),x("div",{className:"flex justify-end gap-2 mt-2",children:[x("button",{onClick:Q,className:"text-meta text-text-tertiary font-body px-3 py-1",children:"Cancel"},void 0,!1,void 0,this),x("button",{onClick:()=>J(Z.trim()),className:"text-meta font-medium font-body px-3 py-1 rounded-md bg-highlight-bg text-text-primary border border-highlight-border",children:"Save"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}import R5,{useRef as R0,useEffect as m0,useCallback as b0,useState as $0,useContext as j0}from"react";function y1($,J,Q,Z){let Y=[],X=$.filter((K)=>!K.filePath),z=$.filter((K)=>K.filePath),q=Q?Array.from(Q.values()).filter((K)=>t1(K)):[],_=Z?Array.from(Z.values()).filter((K)=>K.markdown.trim()):[];if(q.length>0||_.length>0){Y.push("## Responses"),Y.push("");for(let K of q)Y.push(B5(K));for(let K of _)Y.push(K.markdown.trim()),Y.push("")}if(X.length>0){Y.push("## Plan annotations"),Y.push("");let K=y5(X);Y.push(w0(K))}if(z.length>0){let K={};for(let G of z){let W=G.filePath;if(!K[W])K[W]=[];K[W].push(G)}Y.push("## File annotations"),Y.push("");for(let[G,W]of Object.entries(K)){Y.push(`### ${G}`),Y.push("");for(let T of W)Y.push(A0(T))}}if(J.trim())Y.push("## General notes"),Y.push(""),Y.push(J.trim()),Y.push("");return Y.join(`
|
|
83
|
+
`}function W0(J,$){if($!=null&&$!==J)C1($,!1);if(J!=null)C1(J,!0)}function T0(J,$){let Q=document.querySelectorAll(`[data-annotation-id="${J}"]`);for(let Z of Q)Z.setAttribute("data-annotation-id",$)}function O0(J,$){let Q=$.filter((_)=>!document.querySelector(`[data-annotation-id="${_.id}"]`));if(!Q.length)return;let Z=[],Y="",X=document.createTreeWalker(J,NodeFilter.SHOW_TEXT),q;while(q=X.nextNode()){if(q.parentElement?.classList.contains("select-none"))continue;Z.push({node:q,start:Y.length}),Y+=q.textContent||""}for(let _ of Q){let z=_.snippet;if(!z)continue;let K=[],U=0;while(!0){let F=Y.indexOf(z,U);if(F===-1)break;K.push(F),U=F+1}if(K.length===0)continue;let H=K[0];if(K.length>1&&_.context){let F=-1;for(let L of K){let y=0;if(_.context.before){let S=Y.slice(Math.max(0,L-80),L);if(S.includes(_.context.before))y+=2;else if(_.context.before.length>10&&S.includes(_.context.before.slice(-10)))y+=1}if(_.context.after){let S=Y.slice(L+z.length,L+z.length+80);if(S.includes(_.context.after))y+=2;else if(_.context.after.length>10&&S.includes(_.context.after.slice(0,10)))y+=1}if(y>F)F=y,H=L}}let G=H,N=H+z.length,W=w5(Z,G),M=w5(Z,N);if(!W||!M)continue;try{let F=document.createRange();F.setStart(W.node,W.offset),F.setEnd(M.node,M.offset),u1(F,_.id)}catch{}}}function w5(J,$){for(let Q=J.length-1;Q>=0;Q--)if(J[Q].start<=$){let Z=$-J[Q].start,Y=J[Q].node.textContent?.length??0;if(Z<=Y)return{node:J[Q].node,offset:Z}}return null}function F0(J){let $=document.querySelectorAll(`[data-annotation-id="${J}"]`);for(let Q of $){let Z=Q.parentNode;if(!Z)continue;while(Q.firstChild)Z.insertBefore(Q.firstChild,Q);Z.removeChild(Q),Z.normalize()}}function C5(J,$){let Q=R5(J,"before",60),Z=R5(J,"after",60),Y=W3(J.startContainer,$);return{before:Q,after:Z,hierarchy:Y}}function R5(J,$,Q){let Z=N3($==="before"?J.startContainer:J.endContainer);if(!Z)return"";let Y="";if($==="before"){let X=document.createTreeWalker(Z,NodeFilter.SHOW_TEXT),q;while(q=X.nextNode()){if(q===J.startContainer){Y+=(q.textContent||"").slice(0,J.startOffset);break}if(q.parentElement?.hasAttribute("data-annotation-id"))continue;Y+=q.textContent||""}if(Y.length>Q){Y=Y.slice(-Q);let _=Y.indexOf(" ");if(_>0)Y=Y.slice(_+1)}}else{let X=document.createTreeWalker(Z,NodeFilter.SHOW_TEXT),q=!1,_;while(_=X.nextNode()){if(_===J.endContainer){Y+=(_.textContent||"").slice(J.endOffset),q=!0;continue}if(q){if(_.parentElement?.hasAttribute("data-annotation-id"))continue;Y+=_.textContent||""}}if(Y.length>Q){Y=Y.slice(0,Q);let z=Y.lastIndexOf(" ");if(z>0)Y=Y.slice(0,z)}}return Y.trim()}function N3(J){let $=new Set(["DIV","P","LI","PRE","BLOCKQUOTE","SECTION","ARTICLE"]),Q=J.parentElement;while(Q){if($.has(Q.tagName))return Q;Q=Q.parentElement}return null}function W3(J,$){let Q=[],Z=J instanceof Element?J:J.parentElement;while(Z&&Z!==$){let Y=Z.getAttribute?.("data-task-id");if(Y){let X=Z.querySelector(".font-semibold");if(X)Q.unshift(X.textContent?.trim()||Y)}if(Z.tagName==="DIV"&&Z.querySelector(":scope > button .font-heading, :scope > div .font-heading")){let X=Z.querySelector(".font-heading");if(X)Q.unshift(X.textContent?.trim()||"")}Z=Z.parentElement}return Q}function h0(J){let $=J.snippet.trim(),Q=J.context,Z=$.length<30;if(Q&&Z&&(Q.before||Q.after)){let Y=[];if(Q.before)Y.push(`...${Q.before} `);if(Y.push($),Q.after)Y.push(` ${Q.after}...`);return Y.join("")}return $}import{useEffect as y0,useRef as M0,useState as $0,useCallback as p0,useMemo as j5}from"react";import{createPortal as T3}from"react-dom";function m5(J,$){let Y=$||document.body,X=J.getBoundingClientRect(),q=Y.getBoundingClientRect(),_=Y===document.body?window.scrollY:Y.scrollTop,z=X.bottom-q.top+_+8,K=Math.max(0,Math.min(X.left-q.left,q.width-280-12));return Y.style.position="relative",{style:{position:"absolute",top:`${z}px`,left:`${K}px`},parent:Y}}import{jsxDEV as e}from"react/jsx-dev-runtime";function V5({anchorEl:J,scrollContainer:$,onClose:Q,ignoreSelector:Z,zIndex:Y="50",padding:X="12px",width:q="280px",children:_}){let z=M0(null),K=M0(Q);K.current=Q;let{style:U,parent:H}=m5(J,$);return y0(()=>{let G=setTimeout(()=>{let N=(W)=>{if(z.current&&!z.current.contains(W.target)){if(Z&&W.target.closest?.(Z))return;K.current(),document.removeEventListener("mousedown",N)}};return document.addEventListener("mousedown",N),()=>document.removeEventListener("mousedown",N)},0);return()=>clearTimeout(G)},[Z]),T3(e("div",{ref:z,style:{...U,zIndex:Y,width:q,background:"var(--color-bg-elevated)",border:"1px solid var(--color-border-hover)",borderRadius:"8px",boxShadow:"0 4px 12px var(--color-shadow)",padding:X,fontFamily:"'Inter', sans-serif"},children:_},void 0,!1,void 0,this),H)}var g5=[{label:"Clarity",items:["Unclear","Why?","Needs example","Missing context"]},{label:"Scope",items:["Overkill","Out of scope","Important","Risky"]},{label:"Action",items:["Simplify","Rethink","Expand on this","Skip this"]}],I5=g5.flatMap((J)=>J.items);function J0({anchorEl:J,scrollContainer:$,snippet:Q,truncateAt:Z=100,header:Y,onAdd:X,onCancel:q}){let[_,z]=$0(""),[K,U]=$0(null),[H,G]=$0(!1),N=M0(null);y0(()=>{N.current?.focus()},[]);let W=p0(()=>{if(_.trim())X(_.trim());else q()},[_,X,q]),M=_.trim().length>0?I5.filter((T)=>T.toLowerCase().startsWith(_.trim().toLowerCase())):I5,F=H?[]:M.length===1&&M[0].toLowerCase()===_.trim().toLowerCase()?[]:M,L=new Set(F),y=g5.map((T)=>({label:T.label,items:T.items.filter((B)=>L.has(B))})).filter((T)=>T.items.length>0),S=y.map((T)=>T.items),R=S.flat(),m=j5(()=>{if(K===null)return 0;let T=0;for(let B=0;B<S.length;B++){if(K<T+S[B].length)return B;T+=S[B].length}return 0},[K,S]),k=j5(()=>{if(K===null)return 0;let T=0;for(let B=0;B<m;B++)T+=S[B].length;return K-T},[K,m,S]),V=(T,B)=>{let c=0;for(let o=0;o<T;o++)c+=S[o].length;return c+B};y0(()=>{U(null),G(!1)},[_]);let w=p0((T)=>{z(T)},[]),I=Q.length>Z?Q.slice(0,Z)+"...":Q;return e(V5,{anchorEl:J,scrollContainer:$,onClose:q,width:"420px",children:[Y??e("div",{style:{fontSize:"11px",color:"var(--color-text-tertiary)",fontStyle:"italic",marginBottom:"8px",lineHeight:"1.4",display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical",overflow:"hidden"},children:["“",I,"”"]},void 0,!0,void 0,this),e("textarea",{ref:N,value:_,onChange:(T)=>z(T.target.value),onKeyDown:(T)=>{if(R.length>0&&(T.key==="ArrowDown"||T.key==="ArrowUp"||T.key==="ArrowLeft"||T.key==="ArrowRight")){if(T.preventDefault(),K===null){U(0);return}if(T.key==="ArrowDown"){let B=Math.min(k+1,S[m].length-1);U(V(m,B))}else if(T.key==="ArrowUp"){let B=Math.max(k-1,0);U(V(m,B))}else if(T.key==="ArrowRight"){let B=Math.min(m+1,S.length-1),c=Math.min(k,S[B].length-1);U(V(B,c))}else if(T.key==="ArrowLeft"){let B=Math.max(m-1,0),c=Math.min(k,S[B].length-1);U(V(B,c))}return}if(K!==null&&R.length>0){if(T.key==="Tab"){T.preventDefault(),w(R[K]);return}if(T.key==="Enter"&&!T.shiftKey){T.preventDefault(),X(R[K]);return}}if(T.key==="Enter"&&!T.shiftKey){T.preventDefault(),W();return}if(T.key==="Escape")if(R.length>0&&!H)G(!0);else q()},style:{width:"100%",minHeight:"60px",background:"transparent",border:"none",color:"var(--color-text-primary)",fontFamily:"'Inter', sans-serif",fontSize:"13px",lineHeight:"1.5",resize:"vertical",outline:"none"},placeholder:"Add your note..."},void 0,!1,void 0,this),e("div",{style:{display:"flex",justifyContent:"flex-end",gap:"8px",marginTop:"8px"},children:[e("button",{onClick:q,style:{fontSize:"11px",color:"var(--color-text-tertiary)",background:"none",border:"none",cursor:"pointer",padding:"4px 12px",fontFamily:"'Inter', sans-serif"},children:"Cancel"},void 0,!1,void 0,this),e("button",{onClick:W,style:{fontSize:"11px",fontWeight:500,padding:"4px 12px",borderRadius:"6px",background:"var(--color-highlight-bg)",color:"var(--color-text-primary)",border:"1px solid var(--color-highlight-border)",cursor:"pointer",fontFamily:"'Inter', sans-serif"},children:"Add"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),R.length>0&&e("div",{style:{marginTop:"6px",borderTop:"1px solid var(--color-border-subtle)",paddingTop:"8px",display:"flex",gap:"4px"},children:y.map((T)=>e("div",{style:{flex:1},children:[e("div",{style:{fontSize:"10px",fontWeight:600,color:"var(--color-text-disabled)",textTransform:"uppercase",letterSpacing:"0.05em",padding:"2px 6px",marginBottom:"2px",fontFamily:"'Inter', sans-serif"},children:T.label},void 0,!1,void 0,this),T.items.map((B)=>{let c=R.indexOf(B);return e("div",{onMouseDown:(o)=>{o.preventDefault(),o.stopPropagation(),w(B)},onMouseEnter:()=>U(c),style:{padding:"3px 6px",fontSize:"12px",borderRadius:"4px",fontFamily:"'Inter', sans-serif",color:c===K?"var(--color-text-primary)":"var(--color-text-secondary)",background:c===K?"var(--color-highlight-selected)":"transparent",cursor:"pointer"},children:[e("span",{style:{fontWeight:500},children:B.slice(0,_.trim().length)},void 0,!1,void 0,this),B.slice(_.trim().length)]},B,!0,void 0,this)})]},T.label,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Y0({anchorEl:J,scrollContainer:$,initialNote:Q,onUpdate:Z,onDelete:Y,onClose:X}){let[q,_]=$0(Q),z=M0(null),[K,U]=$0(!1);y0(()=>{let G=z.current;if(G)G.style.height="auto",G.style.height=G.scrollHeight+"px",G.focus(),G.setSelectionRange(G.value.length,G.value.length)},[]);let H=p0(()=>{if(!q.trim()){Y(),X();return}Z(q),X()},[q,Z,Y,X]);return e(V5,{anchorEl:J,scrollContainer:$,onClose:H,ignoreSelector:"[data-annotation-id]",zIndex:"60",padding:"10px 12px",children:[e("textarea",{ref:z,value:q,onChange:(G)=>{_(G.target.value),Z(G.target.value),G.target.style.height="auto",G.target.style.height=G.target.scrollHeight+"px"},onKeyDown:(G)=>{if(G.key==="Enter"&&!G.shiftKey)G.preventDefault(),H();if(G.key==="Escape")H()},style:{width:"100%",background:"transparent",border:"none",color:"var(--color-text-primary)",fontFamily:"'Inter', sans-serif",fontSize:"13px",lineHeight:"1.5",resize:"none",outline:"none",overflow:"hidden"}},void 0,!1,void 0,this),e("div",{style:{display:"flex",justifyContent:"flex-end",marginTop:"6px"},children:e("button",{onClick:()=>{Y(),X()},onMouseEnter:()=>U(!0),onMouseLeave:()=>U(!1),style:{fontSize:"11px",color:K?"var(--color-accent-red)":"var(--color-text-tertiary)",background:"none",border:"none",cursor:"pointer",padding:"2px 0",fontFamily:"'Inter', sans-serif"},children:"Delete"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{jsxDEV as l,Fragment as k5}from"react/jsx-dev-runtime";var r0="[data-md='item'], [data-md='section'], [data-md='table'] tbody tr, [data-md='callout'], [data-md='note'], [data-md='checklist-item'], [data-md='choice-option'], [data-md='multichoice-option'], [data-md='userinput'], [data-md='rangeinput'], [data-md='image']",d0="[data-md='item'], [data-md='section'], [data-md='table'] tbody tr, [data-md='callout'], [data-md='note'], [data-md='checklist-item'], [data-md='image']";function f5({revision:J}){let $=O3(M3),[Q,Z]=X1(null),[Y,X]=X1(null),[q,_]=X1(!0),z=D5(null),{annotations:K,addAnnotationWithId:U,removeAnnotation:H,updateAnnotation:G,activeAnnotationId:N,setActiveAnnotationId:W}=q1(),[M,F]=X1(null),[L,y]=X1(null),[S,R]=X1(null),[m,k]=X1(null),[V,w]=X1(null),[I,T]=X1(null),[B,c]=X1(!1);U1(()=>{_(!0),X(null),T(null),import(`/api/session/${$}/plan.js?rev=${J}&t=${Date.now()}`).then((b)=>{Z(()=>b.default),_(!1)}).catch((b)=>{X(b.message),_(!1)})},[$,J]),U1(()=>{if(!Q||!z.current)return;let b=setTimeout(()=>{if(z.current)O0(z.current,K)},50);return()=>clearTimeout(b)},[Q]);let o=D5(null);U1(()=>{W0(N,o.current),o.current=N},[N]),U1(()=>{let b=z.current;if(!b)return;let C=(p)=>{let u=p.target.closest("[data-annotation-id]");if(!u)return;p.stopPropagation();let r=u.getAttribute("data-annotation-id");if(r===N)y({anchorEl:u,annId:r});else W(r)},h=(p)=>{let u=p.target.closest("[data-annotation-id]");if(u){let r=u.getAttribute("data-annotation-id");W(r)}},x=(p)=>{let u=p.target.closest("[data-annotation-id]"),r=p.relatedTarget?.closest?.("[data-annotation-id]");if(u&&!r){if(!document.getElementById("ann-inline-popover"))W(null)}};return b.addEventListener("click",C),b.addEventListener("mouseover",h),b.addEventListener("mouseout",x),()=>{b.removeEventListener("click",C),b.removeEventListener("mouseover",h),b.removeEventListener("mouseout",x)}},[Q,K,N]);let Z1=B0(()=>{let b=new Map;for(let C of K)if(C.snippet.startsWith("["))b.set(C.snippet,C.id);return b},[K]);U1(()=>{let b=z.current;if(!b)return;let C=(x)=>{if(V||S||L)return;let p=x.target;if(p.closest("[data-block-comment-btn]"))return;c(!1);let u=p.closest(r0);if(u&&b.contains(u)){let A=m1(b).indexOf(u);T(A>=0?A:null)}else T(null);let r=p.closest(d0);if(r&&b.contains(r)){k(r);let d=v1(r),A=d?Z1.get(d):void 0;if(A&&A!==N)W(A)}else k(null)},h=(x)=>{if(V||S||L)return;if(x.relatedTarget?.closest("[data-block-comment-btn]"))return;k(null),W(null)};return b.addEventListener("mousemove",C),b.addEventListener("mouseleave",h),()=>{b.removeEventListener("mousemove",C),b.removeEventListener("mouseleave",h)}},[Q,V,S,L,Z1,N]),U1(()=>{let b=(C)=>{let h=C.target.tagName;if(h==="INPUT"||h==="TEXTAREA"||C.target.isContentEditable)return;if(V||S||L)return;let x=z.current;if(!x)return;if(C.key==="ArrowDown"){C.preventDefault(),c(!0);let p=m1(x);if(p.length===0)return;T((u)=>{if(u===null)return 0;return Math.min(u+1,p.length-1)})}else if(C.key==="ArrowUp"){C.preventDefault(),c(!0);let p=m1(x);if(p.length===0)return;T((u)=>{if(u===null)return p.length-1;return Math.max(u-1,0)})}else if(C.key==="a"||C.key==="A"){if(I===null||!x)return;C.preventDefault();let u=m1(x)[I];if(!u)return;let r=v1(u);if(!r)return;let d=Z1.get(r);if(d)W(d),w({anchorEl:u,snippet:r,annId:d});else w({anchorEl:u,snippet:r})}else if(C.key===" "||C.key==="Enter"){if(I===null)return;let u=m1(x)[I];if(!u)return;let r=u.getAttribute("data-md");if(r==="choice-option"||r==="multichoice-option")C.preventDefault(),u.dispatchEvent(new CustomEvent("kb-select",{bubbles:!0}));else if(r==="userinput"){C.preventDefault();let d=u.querySelector("textarea");if(d){d.focus();let A=(g)=>{if(g.key==="Escape")g.preventDefault(),d.blur(),c(!0)};d.addEventListener("keydown",A),d.addEventListener("blur",()=>d.removeEventListener("keydown",A),{once:!0})}}else if(r==="rangeinput"){C.preventDefault();let d=u.querySelector("input[type='range']");if(d){d.focus();let A=(g)=>{if(g.key==="Escape"||g.key==="ArrowUp"||g.key==="ArrowDown")g.preventDefault(),d.blur(),c(!0)};d.addEventListener("keydown",A),d.addEventListener("blur",()=>d.removeEventListener("keydown",A),{once:!0})}}}else if(C.key==="Escape")T(null),c(!1),W(null)};return document.addEventListener("keydown",b),()=>document.removeEventListener("keydown",b)},[I,V,S,L,Z1]),U1(()=>{let b=z.current;if(!b||I===null||!B)return;let h=m1(b)[I];if(!h)return;h.style.outline="2px solid var(--color-accent-blue)",h.style.outlineOffset="-2px",h.style.borderRadius="8px",h.scrollIntoView({block:"nearest",behavior:"smooth"});let x=v1(h),p=x?Z1.get(x):void 0;if(p)W(p);return()=>{h.style.outline="",h.style.outlineOffset="",h.style.borderRadius=""}},[I,B,Z1]),U1(()=>{let b=()=>P1();return document.addEventListener("mouseup",b),()=>document.removeEventListener("mouseup",b)},[]);let P1=F3(()=>{let b=window.getSelection();if(!b||b.isCollapsed||!b.toString().trim())return;if(!z.current)return;let C=b.getRangeAt(0);if(!z.current.contains(C.startContainer))return;if(C.startContainer.parentElement?.closest?.("[data-annotation-id]"))return;let h=b.toString().trim();if(h.length<2)return;let x=C.cloneRange(),p=C5(C,z.current),u=`__pending_${Date.now()}`;try{u1(x,u)}catch{}window.getSelection()?.removeAllRanges();let r=document.querySelectorAll(`[data-annotation-id="${u}"]`),d=r[r.length-1];if(!d)return;R({anchorEl:d,tempId:u,snippet:h,ctx:p})},[U]),j=B0(()=>Q?l(Q,{},void 0,!1,void 0,this):null,[Q]);if(q)return l("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-body",children:"Loading plan..."},void 0,!1,void 0,this);if(Y)return l("div",{className:"bg-accent-red-muted rounded-lg p-5",children:[l("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Compilation Error"},void 0,!1,void 0,this),l("pre",{className:"text-code font-mono text-text-secondary whitespace-pre-wrap",children:Y},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(!Q)return l("div",{className:"text-text-tertiary text-center py-8 font-body text-body",children:"No plan loaded"},void 0,!1,void 0,this);let i=document.getElementById("plan-scroll-container");return l(k5,{children:[l("div",{ref:z,className:"plan-content plan-updated",children:j},void 0,!1,void 0,this),M&&l(P3,{note:M.note,onSave:(b)=>{G(M.id,b),F(null)},onCancel:()=>F(null)},void 0,!1,void 0,this),L&&(()=>{let b=K.find((C)=>C.id===L.annId);if(!b)return null;return l(Y0,{anchorEl:L.anchorEl,scrollContainer:i,initialNote:b.note,onUpdate:(C)=>G(L.annId,C),onDelete:()=>{H(L.annId),W(null)},onClose:()=>y(null)},void 0,!1,void 0,this)})(),S&&l(J0,{anchorEl:S.anchorEl,scrollContainer:i,snippet:S.snippet,truncateAt:80,onAdd:(b)=>{let C=H1();T0(S.tempId,C),U(C,S.snippet,b,void 0,S.ctx),R(null)},onCancel:()=>{F0(S.tempId),R(null)}},void 0,!1,void 0,this),l(B3,{containerRef:z,hoveredBlock:m,focusedBlockIndex:I,blockPopover:V,blockAnnotationMap:Z1,activeAnnotationId:N,onOpen:(b,C,h)=>{if(h)W(h),w({anchorEl:b,snippet:C,annId:h});else w({anchorEl:b,snippet:C})}},void 0,!1,void 0,this),V&&!V.annId&&l(J0,{anchorEl:V.anchorEl,scrollContainer:i,snippet:V.snippet,truncateAt:80,onAdd:(b)=>{let C=H1();U(C,V.snippet,b),w(null)},onCancel:()=>w(null)},void 0,!1,void 0,this),V?.annId&&(()=>{let b=K.find((C)=>C.id===V.annId);if(!b)return null;return l(Y0,{anchorEl:V.anchorEl,scrollContainer:i,initialNote:b.note,onUpdate:(C)=>G(V.annId,C),onDelete:()=>{H(V.annId),W(null),w(null)},onClose:()=>w(null)},void 0,!1,void 0,this)})()]},void 0,!0,void 0,this)}function m1(J){return Array.from(J.querySelectorAll(r0))}function v1(J){let $=J.getAttribute("data-md");if($==="item"){let Q=J.getAttribute("data-md-label");return Q?`[Item] ${Q}`:null}if($==="section"){let Q=J.getAttribute("data-md-title");return Q?`[Section] ${Q}`:null}if($==="callout"){let Q=J.getAttribute("data-md-type")||"info",Z=J.textContent?.trim().slice(0,60)||"Callout";return`[Callout:${Q}] ${Z}`}if($==="note")return`[Note] ${J.textContent?.trim().slice(0,60)||"Note"}`;if(J.tagName==="TR"){let Q=Array.from(J.querySelectorAll("td")).map((Z)=>Z.textContent?.trim()).filter(Boolean);return Q.length?`[Row] ${Q.join(" | ")}`:null}if($==="checklist-item"){let Q=J.getAttribute("data-md-label");return Q?`[Checklist] ${Q}`:null}if($==="choice-option"||$==="multichoice-option"){let Q=J.getAttribute("data-md-label");return Q?`[Option] ${Q}`:null}if($==="userinput"){let Q=J.getAttribute("data-md-label");return Q?`[Input] ${Q}`:null}if($==="rangeinput"){let Q=J.getAttribute("data-md-label");return Q?`[Range] ${Q}`:null}if($==="image"){let Q=J.getAttribute("data-md-src");return Q?`[Image] ${Q}`:null}return null}function B3({containerRef:J,hoveredBlock:$,focusedBlockIndex:Q,blockPopover:Z,blockAnnotationMap:Y,activeAnnotationId:X,onOpen:q}){let[_,z]=X1([]);U1(()=>{let N=J.current;if(!N||Y.size===0){z([]);return}let W=[];for(let M of N.querySelectorAll(d0)){let F=v1(M);if(F&&Y.has(F))W.push(M)}z(W)},[Y,J.current]);let[K,U]=X1(null);U1(()=>{if(!X||!J.current){U(null);return}for(let N of J.current.querySelectorAll(r0)){let W=v1(N);if(W&&Y.get(W)===X){U(N);return}}U(null)},[X,Y]),U1(()=>{if(!K)return;return K.style.boxShadow="inset 0 0 0 1.5px var(--color-highlight-bg)",K.style.borderRadius="8px",()=>{K.style.boxShadow="",K.style.borderRadius=""}},[K]);let H=B0(()=>{if(Q===null||!J.current)return null;let N=m1(J.current)[Q];if(!N)return null;return N.matches(d0)?N:null},[Q,J.current]),G=B0(()=>{let N=new Set(_);if($)N.add($);if(H)N.add(H);if(Z?.anchorEl)N.add(Z.anchorEl);return Array.from(N)},[_,$,H,Z]);return l(k5,{children:G.map((N)=>l(L3,{block:N,isHovered:N===$||N===H||N===Z?.anchorEl,blockAnnotationMap:Y,activeAnnotationId:X,onOpen:q},N.getAttribute("data-task-id")||N.getAttribute("data-md-title")||N.textContent?.slice(0,30)||"block",!1,void 0,this))},void 0,!1,void 0,this)}function L3({block:J,isHovered:$,blockAnnotationMap:Q,activeAnnotationId:Z,onOpen:Y}){let X=v1(J);if(!X)return null;let q=Q.get(X),_=!!q;return y3(l("button",{"data-block-comment-btn":!0,onClick:(K)=>{K.stopPropagation(),Y(K.currentTarget,X,q)},className:`absolute top-1 right-1 z-10 w-6 h-6 flex items-center justify-center rounded transition-all duration-150 ${_?q===Z?"text-accent-amber bg-accent-amber-muted":"text-accent-amber opacity-60 hover:opacity-100":$?"text-text-disabled hover:text-text-tertiary opacity-50 hover:opacity-100":"text-text-disabled opacity-0 group-hover/section:opacity-20 hover:!opacity-80"}`,title:_?"Edit annotation":"Add annotation",children:l("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:_?"currentColor":"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:l("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),J)}function P3({note:J,onSave:$,onCancel:Q}){let[Z,Y]=c0.useState(J),X=c0.useRef(null);return c0.useEffect(()=>{X.current?.focus(),X.current?.select()},[]),l("div",{className:"fixed inset-0 z-50 bg-black/40 flex items-center justify-center",onClick:Q,children:l("div",{className:"bg-bg-elevated border border-border-hover rounded-lg shadow-md p-4 w-80",onClick:(q)=>q.stopPropagation(),children:[l("div",{className:"text-tiny uppercase tracking-widest text-text-tertiary font-body mb-2",children:"Edit annotation"},void 0,!1,void 0,this),l("textarea",{ref:X,value:Z,onChange:(q)=>Y(q.target.value),className:"w-full bg-transparent border-none text-body font-body text-text-primary resize-vertical focus:outline-none min-h-[60px]",onKeyDown:(q)=>{if(q.key==="Enter"&&(q.ctrlKey||q.metaKey))$(Z.trim());if(q.key==="Escape")Q()}},void 0,!1,void 0,this),l("div",{className:"flex justify-end gap-2 mt-2",children:[l("button",{onClick:Q,className:"text-meta text-text-tertiary font-body px-3 py-1",children:"Cancel"},void 0,!1,void 0,this),l("button",{onClick:()=>$(Z.trim()),className:"text-meta font-medium font-body px-3 py-1 rounded-md bg-highlight-bg text-text-primary border border-highlight-border",children:"Save"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}import I3,{useRef as x5,useEffect as o0,useCallback as h5,useState as x1,useContext as i0}from"react";function Q0(J,$,Q,Z){let Y=[],X=J.filter((U)=>!U.filePath),q=J.filter((U)=>U.filePath),_=Q?Array.from(Q.values()).filter((U)=>l0(U)):[],z=Z?Array.from(Z.values()).filter((U)=>U.markdown.trim()):[];if(_.length>0||z.length>0){Y.push("## Responses"),Y.push("");for(let U of _)Y.push(A3(U));for(let U of z)Y.push(U.markdown.trim()),Y.push("")}if(X.length>0){Y.push("## Plan annotations"),Y.push("");let U=w3(X);Y.push(v5(U))}if(q.length>0){let U={};for(let H of q){let G=H.filePath;if(!U[G])U[G]=[];U[G].push(H)}Y.push("## File annotations"),Y.push("");for(let[H,G]of Object.entries(U)){Y.push(`### ${H}`),Y.push("");for(let N of G)Y.push(u5(N))}}if($.trim())Y.push("## General notes"),Y.push(""),Y.push($.trim()),Y.push("");return Y.join(`
|
|
42
84
|
`).trim()+`
|
|
43
|
-
`}function
|
|
44
|
-
`)}function
|
|
45
|
-
`).length<=3)
|
|
85
|
+
`}function l0(J){if(J.note?.trim())return!0;if(J.value===null||J.value===void 0)return!1;if(J.type==="text"&&!J.value.trim())return!1;if(J.type==="checkbox"&&J.value.length===0)return!1;return!0}function S3(J){let $=[];for(let Q of J.values()){if(!Q.required)continue;if(Q.value===null||Q.value===void 0){$.push(Q);continue}if(Q.type==="text"&&!Q.value.trim()){$.push(Q);continue}if(Q.type==="checkbox"&&Q.value.length===0){$.push(Q);continue}}return $}function b3(J){let $=[];for(let Q of J.values())if(Q.required&&!Q.markdown.trim())$.push(Q);return $}function L0(J,$){let Q=S3(J),Z=b3($);return[...Q.map((Y)=>Y.label),...Z.map((Y)=>Y.label||Y.id)]}function A3(J){let $=[];switch($.push(`**${J.label}**`),J.type){case"radio":case"select":$.push(`Answer: ${J.value}`);break;case"checkbox":for(let Q of J.value)$.push(`- [x] ${Q}`);break;case"text":$.push(""),$.push(J.value.trim());break;case"range":$.push(`Answer: ${J.value}`);break}if(J.note?.trim())$.push(""),$.push(`Note: ${J.note.trim()}`);return $.push(""),$.join(`
|
|
86
|
+
`)}function u5(J){let $=[],Q=J.snippet.trim(),Z=J.context,Y=Z?.lineStart!=null;if(J.filePath&&Y){let X=Z.lineStart,q=Z.lineEnd??X,_=Q.split(`
|
|
87
|
+
`);if(Q.length<30&&X===q&&(Z.before||Z.after)){let K=h0(J);$.push(`> L${X}: ${K}`)}else if(_.length<=6)for(let K=0;K<_.length;K++)$.push(`> ${X+K} | ${_[K]}`);else{for(let K=0;K<3;K++)$.push(`> ${X+K} | ${_[K]}`);$.push(`> ... (${_.length} lines)`);for(let K=_.length-3;K<_.length;K++)$.push(`> ${X+K} | ${_[K]}`)}}else{let X=h0(J);if(Q.split(`
|
|
88
|
+
`).length<=3)$.push(`> ${X.split(`
|
|
46
89
|
`).join(`
|
|
47
|
-
> `)}`);else{let
|
|
48
|
-
`)
|
|
49
|
-
`)}function
|
|
50
|
-
`)}import{SessionContext as b5}from"#canvas/runtime";import{useEffect as n1,useState as k1,useRef as P5,useMemo as S5}from"react";import{jsxDEV as f,Fragment as w5}from"react/jsx-dev-runtime";function I0({open:$,onClose:J,onSubmit:Q}){let{annotations:Z,generalNote:Y,responses:X,feedbackEntries:z}=o(),[q,_]=k1(""),[U,K]=k1(!1),[G,W]=k1(!1),[T,N]=k1(null),S=P5(null);if(n1(()=>{if(!$){K(!1),W(!1),N(null);return}if(U)return;_(y1(Z,Y,X,z))},[Z,Y,X,z,U,$]),n1(()=>{if($&&G&&S.current)S.current.focus()},[$,G]),n1(()=>{if(!$)return;let P=(w)=>{if(w.key==="Escape")J()};return window.addEventListener("keydown",P),()=>window.removeEventListener("keydown",P)},[$,J]),!$)return null;let O=q.trim().length>0;return f("div",{className:"fixed inset-0 z-50 bg-black/50 backdrop-blur-sm flex items-center justify-center p-8",onClick:J,children:f("div",{className:"bg-bg-surface border border-border-medium rounded-xl shadow-lg w-full max-w-2xl flex flex-col",style:{height:"80vh"},onClick:(P)=>P.stopPropagation(),children:[f("div",{className:"flex items-center justify-between px-5 py-3 border-b border-border-subtle flex-shrink-0",children:[f("div",{className:"flex items-center gap-3",children:[f("span",{className:"text-[13px] font-medium text-text-primary font-body",children:"Response preview"},void 0,!1,void 0,this),U&&f("button",{onClick:()=>{K(!1),W(!1)},className:"text-[11px] text-text-tertiary hover:text-text-secondary font-body",children:"Reset"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),f("div",{className:"flex items-center gap-2",children:[f("div",{className:"flex items-center bg-bg-base rounded-md p-0.5",children:[f("button",{onClick:()=>W(!1),className:`px-2.5 py-1 rounded text-[11px] font-body font-medium transition-colors ${!G?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Preview"},void 0,!1,void 0,this),f("button",{onClick:()=>W(!0),className:`px-2.5 py-1 rounded text-[11px] font-body font-medium transition-colors ${G?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Edit"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),f("button",{onClick:J,className:"text-text-tertiary hover:text-text-secondary w-7 h-7 flex items-center justify-center rounded-md hover:bg-border-subtle transition-colors",children:"✕"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),G?f("textarea",{ref:S,value:q,onChange:(P)=>{_(P.target.value),K(!0)},className:"flex-1 w-full bg-bg-base p-5 text-[13px] font-mono text-text-code resize-none focus:outline-none leading-relaxed placeholder:text-text-disabled",placeholder:"Your feedback will appear here..."},void 0,!1,void 0,this):f("div",{className:"flex-1 overflow-y-auto p-5",children:f(e1,{text:q},void 0,!1,void 0,this)},void 0,!1,void 0,this),T&&f("div",{className:"px-5 py-2 text-[12px] text-accent-red font-body border-t border-border-subtle flex-shrink-0 flex items-center justify-between gap-2",children:[f("span",{children:T},void 0,!1,void 0,this),f("button",{onClick:()=>{N(null),Q(q)},className:"text-[11px] text-text-tertiary hover:text-text-secondary font-body whitespace-nowrap underline",children:"Submit anyway"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),f("div",{className:"flex justify-end gap-2 px-5 py-3 border-t border-border-subtle flex-shrink-0",children:[f("button",{onClick:J,className:"px-4 py-2 rounded-lg text-[13px] font-body text-text-tertiary hover:text-text-secondary transition-colors",children:"Cancel"},void 0,!1,void 0,this),f("button",{onClick:()=>{let P=g1(X),w=f1(z),B=[...P.map((R)=>R.label),...w.map((R)=>R.label||R.id)];if(B.length>0){N(`Please answer: ${B.join(", ")}`);return}N(null),Q(q)},disabled:!O,className:`px-6 py-2 rounded-lg font-body text-[13px] font-medium transition-all ${O?"bg-btn-primary text-btn-primary-text hover:opacity-90":"bg-bg-input text-text-disabled cursor-default"}`,children:"Submit feedback"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function e1({text:$}){let J=S5(()=>A5($),[$]);return f("div",{className:"font-body text-body text-text-primary leading-relaxed",children:J},void 0,!1,void 0,this)}function C0({text:$}){let J=[],Q=/(\*\*(.+?)\*\*|`(.+?)`)/g,Z=0,Y,X=0;while((Y=Q.exec($))!==null){if(Y.index>Z)J.push($.slice(Z,Y.index));if(Y[2])J.push(f("strong",{className:"font-semibold text-text-primary",children:Y[2]},X++,!1,void 0,this));else if(Y[3])J.push(f("code",{className:"font-mono text-code bg-bg-code px-1 py-px rounded",children:Y[3]},X++,!1,void 0,this));Z=Q.lastIndex}if(Z<$.length)J.push($.slice(Z));return f(w5,{children:J},void 0,!1,void 0,this)}function A5($){let J=$.split(`
|
|
51
|
-
`),Q=[],Z=0,Y=0;while(Z<J.length){let X=J[Z];if(X.startsWith("#### ")){Q.push(f("h4",{className:"text-[13px] font-body font-semibold text-text-primary mt-5 mb-1",children:X.slice(5)},Y++,!1,void 0,this)),Z++;continue}if(X.startsWith("### ")){Q.push(f("h3",{className:"text-[14px] font-body font-semibold text-text-primary mt-5 mb-1",children:X.slice(4)},Y++,!1,void 0,this)),Z++;continue}if(X.startsWith("## ")){Q.push(f("h2",{className:"text-task-label font-body font-semibold text-text-primary mt-6 mb-2 pb-1 border-b border-border-subtle",children:X.slice(3)},Y++,!1,void 0,this)),Z++;continue}if(X.startsWith("> ")){let z=[];while(Z<J.length&&J[Z].startsWith("> "))z.push(J[Z].slice(2)),Z++;Q.push(f("blockquote",{className:"border-l-2 border-border-hover pl-3 my-2 text-text-secondary italic text-[13px]",children:z.map((q,_)=>f("div",{children:q},_,!1,void 0,this))},Y++,!1,void 0,this));continue}if(X.startsWith("- [x] ")||X.startsWith("- [ ] ")){let z=[];while(Z<J.length&&(J[Z].startsWith("- [x] ")||J[Z].startsWith("- [ ] ")))z.push({checked:J[Z].startsWith("- [x] "),label:J[Z].slice(6)}),Z++;Q.push(f("ul",{className:"my-1 space-y-0.5",children:z.map((q,_)=>f("li",{className:"flex items-center gap-2 text-[13px]",children:[f("span",{className:`w-3.5 h-3.5 rounded flex items-center justify-center flex-shrink-0 ${q.checked?"bg-accent-amber":"border border-border-hover"}`,children:q.checked&&f("svg",{width:"8",height:"8",viewBox:"0 0 10 10",fill:"none",children:f("path",{d:"M2.5 5L4.5 7L7.5 3",style:{stroke:"var(--color-text-inverse)"},strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),f("span",{className:q.checked?"text-text-primary":"text-text-tertiary",children:q.label},void 0,!1,void 0,this)]},_,!0,void 0,this))},Y++,!1,void 0,this));continue}if(X.startsWith("- ")){let z=[];while(Z<J.length&&J[Z].startsWith("- "))z.push(J[Z].slice(2)),Z++;Q.push(f("ul",{className:"my-1 space-y-0.5 list-disc list-inside",children:z.map((q,_)=>f("li",{className:"text-[13px] text-text-secondary",children:f(C0,{text:q},void 0,!1,void 0,this)},_,!1,void 0,this))},Y++,!1,void 0,this));continue}if(X.trim()===""){Z++;continue}Q.push(f("p",{className:"my-1.5 text-[13px]",children:f(C0,{text:X},void 0,!1,void 0,this)},Y++,!1,void 0,this)),Z++}return Q}import{jsxDEV as q1}from"react/jsx-dev-runtime";var C5={ts:"#3178c6",tsx:"#3178c6",js:"#e8a32e",jsx:"#4ba0c8",html:"#e34c26",css:"#264de4",scss:"#c69",json:"#7a7568",yaml:"#cb171e",yml:"#cb171e",toml:"#9c4221",rs:"#dea584",go:"#00add8",c:"#6a6a6a",cpp:"#f34b7d",h:"#6a6a6a",py:"#3572a5",rb:"#cc342d",sh:"#5a8c3c",bash:"#5a8c3c",md:"#3573b5",txt:"#6b6560",lock:"#6b6560",gitignore:"#6b6560",svg:"#d9952e",png:"#6a9c2e",jpg:"#6a9c2e",gif:"#6a9c2e"},I5={ts:"TS",tsx:"TX",js:"JS",jsx:"JX",py:"PY",rs:"RS",go:"GO",rb:"RB",json:"{}",yaml:"YM",yml:"YM",toml:"TM",html:"<>",css:"#",scss:"#",md:"M↓",sh:"$",bash:"$",c:"C",cpp:"C+",h:"H",svg:"◇",png:"▣",jpg:"▣"};function P1({name:$,type:J,expanded:Q,className:Z=""}){if(J==="dir")return q1("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",className:`flex-shrink-0 ${Z}`,children:Q?q1("path",{d:"M1.5 3.5h5l1.5 1.5h6.5v8h-13z",style:{fill:"var(--color-folder-fill-active)",stroke:"var(--color-folder-stroke-active)"},strokeWidth:"1"},void 0,!1,void 0,this):q1("path",{d:"M1.5 3.5h5l1.5 1.5h6.5v8h-13z",style:{fill:"var(--color-folder-fill)",stroke:"var(--color-folder-stroke)"},strokeWidth:"1"},void 0,!1,void 0,this)},void 0,!1,void 0,this);let Y=$.includes(".")?$.split(".").pop().toLowerCase():"",X=C5[Y]||"#6b6560",z=I5[Y];return q1("svg",{width:"14",height:"14",viewBox:"0 0 16 16",className:`flex-shrink-0 ${Z}`,children:[q1("path",{d:"M2 1.5h8l3.5 3.5v9.5a1 1 0 01-1 1H3a1 1 0 01-1-1v-12a1 1 0 011-1z",fill:X,opacity:"0.85"},void 0,!1,void 0,this),q1("path",{d:"M10 1.5v2.5a1 1 0 001 1h2.5",fill:"none",stroke:"white",strokeWidth:"0.5",opacity:"0.5"},void 0,!1,void 0,this),z&&q1("text",{x:"8",y:"11.5",textAnchor:"middle",fill:"white",fontSize:"5.5",fontFamily:"monospace",fontWeight:"600",children:z},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{jsxDEV as g}from"react/jsx-dev-runtime";function J0({onPreview:$,onSubmit:J,collapseButton:Q}){let{isReadOnly:Z,selectedRevision:Y,currentRevision:X,revisions:z}=j0(H1),q=j0(b5),_=Z&&Y===X,K=z.find((G)=>G.revision===Y)?.label||`Round ${Y}`;if(Z)return g(j5,{sessionId:q,revision:Y,label:K,waitingForUpdate:_,collapseButton:Q},void 0,!1,void 0,this);return g(m5,{onPreview:$,onSubmit:J,collapseButton:Q},void 0,!1,void 0,this)}function j5({sessionId:$,revision:J,label:Q,waitingForUpdate:Z,collapseButton:Y}){let[X,z]=$0(null),[q,_]=$0(!0);return m0(()=>{_(!0),fetch(`/api/session/${$}/revision/${J}/feedback`).then((U)=>U.json()).then((U)=>{z(U.feedback||null),_(!1)}).catch(()=>{z(null),_(!1)})},[$,J]),g("div",{className:"flex flex-col h-full",children:[g("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[g("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:Z?"Feedback sent":`Feedback — ${Q}`},void 0,!1,void 0,this),Y]},void 0,!0,void 0,this),Z&&g("div",{className:"mx-4 mb-3 px-3 py-2.5 rounded-lg bg-accent-green-muted flex items-center gap-2 flex-shrink-0",children:[g("span",{className:"w-2 h-2 rounded-full bg-accent-green animate-pulse"},void 0,!1,void 0,this),g("span",{className:"text-[12px] font-body text-accent-green",children:"Waiting for next revision..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),g("div",{className:"flex-1 overflow-y-auto px-4",children:q?g("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"Loading..."},void 0,!1,void 0,this):X?g(e1,{text:X},void 0,!1,void 0,this):g("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"No feedback was submitted for this revision."},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function m5({onPreview:$,onSubmit:J,collapseButton:Q}){let{annotations:Z,updateAnnotation:Y,removeAnnotation:X,generalNote:z,setGeneralNote:q,activeAnnotationId:_,setActiveAnnotationId:U,responses:K,feedbackEntries:G}=o(),{setActiveView:W}=R5.useContext(G1),T=R0(null),N=R0(new Map),S=Z.filter((H)=>!H.filePath),O=Z.filter((H)=>H.filePath),P={};for(let H of O){let y=H.filePath;if(!P[y])P[y]=[];P[y].push(H)}m0(()=>{if(!_)return;let H=N.current.get(_);if(H)H.scrollIntoView({behavior:"smooth",block:"nearest"})},[_]);let w=b0((H)=>{U(H),l1(H,!0);let y=document.querySelector(`[data-annotation-id="${H}"]`);if(y)y.scrollIntoView({behavior:"smooth",block:"nearest"})},[U]),B=b0((H)=>{U(null),l1(H,!1)},[_]),R=Array.from(K.values()).some(t1),D=G.size>0,m=Z.length>0||z.trim().length>0||R||D,[j,C]=$0(null),I=(H)=>g("div",{ref:(y)=>{if(y)N.current.set(H.id,y);else N.current.delete(H.id)},className:`group/ann relative px-3 py-2.5 transition-colors duration-150 ${_===H.id?"bg-highlight-selected":"odd:bg-bg-elevated-half hover:bg-bg-input"}`,onMouseEnter:()=>w(H.id),onMouseLeave:()=>B(H.id),onClick:()=>{if(H.id===_)U(null);else if(U(H.id),H.filePath)W({type:"file",path:H.filePath}),setTimeout(()=>{let y=document.querySelector(`[data-annotation-id="${H.id}"]`);if(y)y.scrollIntoView({behavior:"smooth",block:"center"})},150)},children:[g("div",{className:"text-[11px] text-text-tertiary italic line-clamp-2 mb-1.5 leading-snug font-body border-l-2 border-border-medium pl-2",children:H.snippet.length>80?H.snippet.slice(0,80)+"...":H.snippet},void 0,!1,void 0,this),g("textarea",{value:H.note,onChange:(y)=>Y(H.id,y.target.value),onClick:(y)=>y.stopPropagation(),className:"w-full bg-transparent text-[13px] font-body text-text-primary resize-none focus:outline-none leading-relaxed p-0 border-none min-h-[20px]",rows:1,style:{height:"auto",overflow:"hidden"},onInput:(y)=>{let E=y.target;E.style.height="auto",E.style.height=E.scrollHeight+"px"},ref:(y)=>{if(y)y.style.height="auto",y.style.height=y.scrollHeight+"px"}},void 0,!1,void 0,this),g("div",{className:"absolute top-1.5 right-1.5 opacity-0 group-hover/ann:opacity-100 transition-opacity duration-100",children:g("button",{onClick:(y)=>{y.stopPropagation(),X(H.id)},className:"w-5 h-5 flex items-center justify-center rounded text-text-tertiary hover:text-accent-red hover:bg-accent-red-muted transition-colors",title:"Delete annotation",children:g("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[g("polyline",{points:"3 6 5 6 21 6"},void 0,!1,void 0,this),g("path",{d:"M19 6v14a2 2 0 01-2 2H7a2 2 0 01-2-2V6m3 0V4a2 2 0 012-2h4a2 2 0 012 2v2"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},H.id,!0,void 0,this);return g("div",{className:"flex flex-col h-full",children:[g("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[g("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body flex items-center gap-2",children:["Annotations",Z.length>0&&g("span",{className:"inline-flex items-center justify-center min-w-[18px] h-[18px] px-1 rounded-full bg-border-subtle text-[10px] font-medium text-text-secondary",children:Z.length},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Q]},void 0,!0,void 0,this),g("div",{ref:T,className:"flex-1 overflow-y-auto",children:[Z.length===0&&g("p",{className:"text-[12px] text-text-tertiary px-3 py-4 leading-relaxed font-body",children:"Select text in the plan or in files to add annotations."},void 0,!1,void 0,this),S.length>0&&O.length>0&&g("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body px-3 mb-1 mt-1",children:"Plan"},void 0,!1,void 0,this),S.map(I),Object.entries(P).map(([H,y])=>g("div",{children:[g("button",{onClick:()=>W({type:"file",path:H}),className:"flex items-center gap-1.5 text-[10px] uppercase tracking-widest text-text-tertiary hover:text-text-secondary font-body px-3 pt-3 pb-1 truncate transition-colors w-full text-left",title:H,children:[g(P1,{name:H.split("/").pop()||H,type:"file"},void 0,!1,void 0,this),g("span",{className:"truncate",children:H},void 0,!1,void 0,this)]},void 0,!0,void 0,this),y.map(I)]},H,!0,void 0,this))]},void 0,!0,void 0,this),g("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:g("textarea",{value:z,onChange:(H)=>q(H.target.value),className:"w-full bg-transparent text-[13px] font-body text-text-primary resize-none leading-relaxed p-0 border-none ring-0 shadow-none outline-none focus:outline-none focus:ring-0 focus:border-none placeholder:text-text-disabled min-h-[40px]",placeholder:"General notes...",onInput:(H)=>{let y=H.target;y.style.height="auto",y.style.height=Math.max(40,y.scrollHeight)+"px"},ref:(H)=>{if(H)H.style.height="auto",H.style.height=Math.max(40,H.scrollHeight)+"px"}},void 0,!1,void 0,this)},void 0,!1,void 0,this),j&&g("div",{className:"px-4 py-2 text-[12px] text-accent-red font-body border-t border-border-subtle flex-shrink-0 flex items-center justify-between gap-2",children:[g("span",{children:j},void 0,!1,void 0,this),g("button",{onClick:()=>{C(null);let H=y1(Z,z,K,G);J(H)},className:"text-[11px] text-text-tertiary hover:text-text-secondary font-body whitespace-nowrap underline",children:"Submit anyway"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),g("div",{className:"px-4 py-3 border-t border-border-subtle flex-shrink-0",children:m?g("div",{className:"flex gap-2",children:[g("button",{onClick:$,className:"flex-1 py-2 rounded-lg font-body text-[13px] font-medium transition-all bg-border-subtle text-text-secondary hover:bg-border-medium hover:text-text-primary",children:"Preview"},void 0,!1,void 0,this),g("button",{onClick:()=>{let H=g1(K),y=f1(G),E=[...H.map(($1)=>$1.label),...y.map(($1)=>$1.label||$1.id)];if(E.length>0){C(`Please answer: ${E.join(", ")}`);return}C(null);let c=y1(Z,z,K,G);J(c)},className:"flex-1 py-2 rounded-lg font-body text-[13px] font-medium transition-all bg-btn-primary text-btn-primary-text hover:opacity-90 hover:-translate-y-px shadow-sm",children:"Submit"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):g("button",{onClick:()=>J("No feedback — looks good."),className:"w-full py-2 rounded-lg font-body text-[13px] font-medium border border-border-medium text-text-secondary hover:text-text-primary hover:border-border-hover hover:bg-bg-input transition-all",children:"Submit without feedback"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{useEffect as V5,useState as V0,useContext as D0}from"react";import{SessionContext as D5}from"#canvas/runtime";import{jsxDEV as v,Fragment as Q0}from"react/jsx-dev-runtime";function g0({embedded:$}={}){let J=D0(D5),{annotations:Q,addAnnotation:Z}=o(),{setActiveView:Y}=D0(G1),[X,z]=V0(!1),[q,_]=V0({}),U=Q.filter((B)=>B.filePath),K=new Map;for(let B of U)K.set(B.filePath,(K.get(B.filePath)||0)+1);let G=[...K.keys()],W=async(B)=>{let D=await(await fetch(`/api/tree?session=${J}&path=${encodeURIComponent(B)}`)).json();if(D.entries)_((m)=>({...m,[B]:{entries:D.entries,expanded:!0,loaded:!0}}))};V5(()=>{if(!X&&!q[""])W("")},[X]);let T=(B)=>{if(q[B]?.loaded)_((R)=>({...R,[B]:{...R[B],expanded:!R[B].expanded}}));else W(B)},N=(B)=>{Y({type:"file",path:B})},S=async(B)=>{let D=await(await fetch(`/api/file?session=${J}&path=${encodeURIComponent(B)}`)).json();if(!D.error){let m=D.content.split(`
|
|
90
|
+
> `)}`);else{let q=Q.split(`
|
|
91
|
+
`);$.push(`> ${q[0]}`),$.push(`> ... (${q.length} lines)`),$.push(`> ${q[q.length-1]}`)}}if(J.note.trim())$.push(""),$.push(J.note.trim());return $.push(""),$.join(`
|
|
92
|
+
`)}function w3(J){let $={label:"",annotations:[],children:new Map};for(let Q of J){let Z=Q.context?.hierarchy||[],Y=$;for(let X of Z){if(!Y.children.has(X))Y.children.set(X,{label:X,annotations:[],children:new Map});Y=Y.children.get(X)}Y.annotations.push(Q)}return $}function v5(J,$=0){let Q=[];for(let Z of J.annotations)Q.push(u5(Z));for(let[,Z]of J.children){let Y=$===0?"###":"####";Q.push(`${Y} ${Z.label}`),Q.push(""),Q.push(v5(Z,$+1))}return Q.join(`
|
|
93
|
+
`)}import{SessionContext as V3}from"#canvas/runtime";import{useEffect as a0,useState as P0,useRef as R3,useMemo as C3}from"react";import{jsxDEV as s}from"react/jsx-dev-runtime";function E5({open:J,onClose:$,onSubmit:Q}){let{annotations:Z,generalNote:Y,responses:X,feedbackEntries:q}=q1(),[_,z]=P0(""),[K,U]=P0(!1),[H,G]=P0(!1),[N,W]=P0(null),M=R3(null);if(a0(()=>{if(!J){U(!1),G(!1),W(null);return}if(K)return;z(Q0(Z,Y,X,q))},[Z,Y,X,q,K,J]),a0(()=>{if(J&&H&&M.current)M.current.focus()},[J,H]),a0(()=>{if(!J)return;let L=(y)=>{if(y.key==="Escape")$()};return window.addEventListener("keydown",L),()=>window.removeEventListener("keydown",L)},[J,$]),!J)return null;let F=_.trim().length>0;return s("div",{className:"fixed inset-0 z-50 bg-black/50 backdrop-blur-sm flex items-center justify-center p-8",onClick:$,children:s("div",{className:"bg-bg-surface border border-border-medium rounded-xl shadow-lg w-full max-w-2xl flex flex-col",style:{height:"80vh"},onClick:(L)=>L.stopPropagation(),children:[s("div",{className:"flex items-center justify-between px-5 py-3 border-b border-border-subtle flex-shrink-0",children:[s("div",{className:"flex items-center gap-3",children:[s("span",{className:"text-[13px] font-medium text-text-primary font-body",children:"Response preview"},void 0,!1,void 0,this),K&&s("button",{onClick:()=>{U(!1),G(!1)},className:"text-[11px] text-text-tertiary hover:text-text-secondary font-body",children:"Reset"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),s("div",{className:"flex items-center gap-2",children:[s("div",{className:"flex items-center bg-bg-base rounded-md p-0.5",children:[s("button",{onClick:()=>G(!1),className:`px-2.5 py-1 rounded text-[11px] font-body font-medium transition-colors ${!H?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Preview"},void 0,!1,void 0,this),s("button",{onClick:()=>G(!0),className:`px-2.5 py-1 rounded text-[11px] font-body font-medium transition-colors ${H?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Edit"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),s("button",{onClick:$,className:"text-text-tertiary hover:text-text-secondary w-7 h-7 flex items-center justify-center rounded-md hover:bg-border-subtle transition-colors",children:"✕"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),H?s("textarea",{ref:M,value:_,onChange:(L)=>{z(L.target.value),U(!0)},className:"flex-1 w-full bg-bg-base p-5 text-[13px] font-mono text-text-code resize-none focus:outline-none leading-relaxed placeholder:text-text-disabled",placeholder:"Your feedback will appear here..."},void 0,!1,void 0,this):s("div",{className:"flex-1 overflow-y-auto p-5",children:s(S0,{text:_},void 0,!1,void 0,this)},void 0,!1,void 0,this),N&&s("div",{className:"px-5 py-2 text-[12px] text-accent-red font-body border-t border-border-subtle flex-shrink-0 flex items-center justify-between gap-2",children:[s("span",{children:N},void 0,!1,void 0,this),s("button",{onClick:()=>{W(null),Q(_)},className:"text-[11px] text-text-tertiary hover:text-text-secondary font-body whitespace-nowrap underline",children:"Submit anyway"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),s("div",{className:"flex justify-end gap-2 px-5 py-3 border-t border-border-subtle flex-shrink-0",children:[s("button",{onClick:$,className:"px-4 py-2 rounded-lg text-[13px] font-body text-text-tertiary hover:text-text-secondary transition-colors",children:"Cancel"},void 0,!1,void 0,this),s("button",{onClick:()=>{let L=L0(X,q);if(L.length>0){W(`Please answer: ${L.join(", ")}`);return}W(null),Q(_)},disabled:!F,className:`px-6 py-2 rounded-lg font-body text-[13px] font-medium transition-all ${F?"bg-btn-primary text-btn-primary-text hover:opacity-90":"bg-bg-input text-text-disabled cursor-default"}`,children:"Submit feedback"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function S0({text:J}){let $=C3(()=>E.parse(J,{async:!1}),[J]);return s("div",{className:"prose-canvas font-body text-body text-text-primary leading-relaxed",dangerouslySetInnerHTML:{__html:$}},void 0,!1,void 0,this)}import{jsxDEV as j1}from"react/jsx-dev-runtime";var m3={ts:"#3178c6",tsx:"#3178c6",js:"#e8a32e",jsx:"#4ba0c8",html:"#e34c26",css:"#264de4",scss:"#c69",json:"#7a7568",yaml:"#cb171e",yml:"#cb171e",toml:"#9c4221",rs:"#dea584",go:"#00add8",c:"#6a6a6a",cpp:"#f34b7d",h:"#6a6a6a",py:"#3572a5",rb:"#cc342d",sh:"#5a8c3c",bash:"#5a8c3c",md:"#3573b5",txt:"#6b6560",lock:"#6b6560",gitignore:"#6b6560",svg:"#d9952e",png:"#6a9c2e",jpg:"#6a9c2e",gif:"#6a9c2e"},j3={ts:"TS",tsx:"TX",js:"JS",jsx:"JX",py:"PY",rs:"RS",go:"GO",rb:"RB",json:"{}",yaml:"YM",yml:"YM",toml:"TM",html:"<>",css:"#",scss:"#",md:"M↓",sh:"$",bash:"$",c:"C",cpp:"C+",h:"H",svg:"◇",png:"▣",jpg:"▣"};function E1({name:J,type:$,expanded:Q,className:Z=""}){if($==="dir")return j1("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",className:`flex-shrink-0 ${Z}`,children:Q?j1("path",{d:"M1.5 3.5h5l1.5 1.5h6.5v8h-13z",style:{fill:"var(--color-folder-fill-active)",stroke:"var(--color-folder-stroke-active)"},strokeWidth:"1"},void 0,!1,void 0,this):j1("path",{d:"M1.5 3.5h5l1.5 1.5h6.5v8h-13z",style:{fill:"var(--color-folder-fill)",stroke:"var(--color-folder-stroke)"},strokeWidth:"1"},void 0,!1,void 0,this)},void 0,!1,void 0,this);let Y=J.includes(".")?J.split(".").pop().toLowerCase():"",X=m3[Y]||"#6b6560",q=j3[Y];return j1("svg",{width:"14",height:"14",viewBox:"0 0 16 16",className:`flex-shrink-0 ${Z}`,children:[j1("path",{d:"M2 1.5h8l3.5 3.5v9.5a1 1 0 01-1 1H3a1 1 0 01-1-1v-12a1 1 0 011-1z",fill:X,opacity:"0.85"},void 0,!1,void 0,this),j1("path",{d:"M10 1.5v2.5a1 1 0 001 1h2.5",fill:"none",stroke:"white",strokeWidth:"0.5",opacity:"0.5"},void 0,!1,void 0,this),q&&j1("text",{x:"8",y:"11.5",textAnchor:"middle",fill:"white",fontSize:"5.5",fontFamily:"monospace",fontWeight:"600",children:q},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{jsxDEV as P,Fragment as v3}from"react/jsx-dev-runtime";function s0({onPreview:J,onSubmit:$,collapseButton:Q}){let{isReadOnly:Z,selectedRevision:Y,currentRevision:X,revisions:q}=i0(h1),_=i0(V3),z=Z&&Y===X,U=q.find((H)=>H.revision===Y)?.label||`Round ${Y}`;if(Z)return P(D3,{sessionId:_,revision:Y,label:U,waitingForUpdate:z,collapseButton:Q},void 0,!1,void 0,this);return P(u3,{onPreview:J,onSubmit:$,collapseButton:Q},void 0,!1,void 0,this)}function g3({sessionId:J,revision:$,label:Q,waitingForUpdate:Z,collapseButton:Y}){let[X,q]=x1(null),[_,z]=x1(!0);return o0(()=>{z(!0),fetch(`/api/session/${J}/revision/${$}/feedback`).then((K)=>K.json()).then((K)=>{q(K.feedback||null),z(!1)}).catch(()=>{q(null),z(!1)})},[J,$]),P("div",{className:"flex flex-col h-full",children:[P("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[P("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:Z?"Feedback sent":`Feedback — ${Q}`},void 0,!1,void 0,this),Y]},void 0,!0,void 0,this),Z&&P("div",{className:"mx-4 mb-3 px-3 py-2.5 rounded-lg bg-accent-green-muted flex items-center gap-2 flex-shrink-0",children:[P("span",{className:"w-2 h-2 rounded-full bg-accent-green animate-pulse"},void 0,!1,void 0,this),P("span",{className:"text-[12px] font-body text-accent-green",children:"Waiting for next revision..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),P("div",{className:"flex-1 overflow-y-auto px-4",children:_?P("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"Loading..."},void 0,!1,void 0,this):X?P(S0,{text:X},void 0,!1,void 0,this):P("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"No feedback was submitted for this revision."},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function D3({sessionId:J,revision:$,label:Q,waitingForUpdate:Z,collapseButton:Y}){let{annotations:X,generalNote:q,activeAnnotationId:_,setActiveAnnotationId:z}=q1(),{setActiveView:K}=i0(I1),U=X.length>0||q.trim().length>0,[H,G]=x1("feedback");if(!U)return P(g3,{sessionId:J,revision:$,label:Q,waitingForUpdate:Z,collapseButton:Y},void 0,!1,void 0,this);return P("div",{className:"flex flex-col h-full",children:[P("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[P("div",{className:"flex items-center gap-1 bg-bg-input rounded-md p-0.5",children:[P("button",{onClick:()=>G("feedback"),className:`px-2.5 py-1 rounded text-[11px] font-medium font-body transition-colors ${H==="feedback"?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Feedback"},void 0,!1,void 0,this),P("button",{onClick:()=>G("annotations"),className:`px-2.5 py-1 rounded text-[11px] font-medium font-body transition-colors flex items-center gap-1.5 ${H==="annotations"?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:["Annotations",P("span",{className:"inline-flex items-center justify-center min-w-[16px] h-[16px] px-1 rounded-full bg-border-subtle text-[10px] font-medium",children:X.length},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),Y]},void 0,!0,void 0,this),Z&&P("div",{className:"mx-4 mb-3 px-3 py-2.5 rounded-lg bg-accent-green-muted flex items-center gap-2 flex-shrink-0",children:[P("span",{className:"w-2 h-2 rounded-full bg-accent-green animate-pulse"},void 0,!1,void 0,this),P("span",{className:"text-[12px] font-body text-accent-green",children:"Waiting for next revision..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),H==="feedback"?P(f3,{sessionId:J,revision:$},void 0,!1,void 0,this):P(k3,{annotations:X,generalNote:q,activeAnnotationId:_,setActiveAnnotationId:z,setActiveView:K},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function f3({sessionId:J,revision:$}){let[Q,Z]=x1(null),[Y,X]=x1(!0);return o0(()=>{X(!0),fetch(`/api/session/${J}/revision/${$}/feedback`).then((q)=>q.json()).then((q)=>{Z(q.feedback||null),X(!1)}).catch(()=>{Z(null),X(!1)})},[J,$]),P("div",{className:"flex-1 overflow-y-auto px-4",children:Y?P("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"Loading..."},void 0,!1,void 0,this):Q?P(S0,{text:Q},void 0,!1,void 0,this):P("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"No feedback was submitted for this revision."},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function k3({annotations:J,generalNote:$,activeAnnotationId:Q,setActiveAnnotationId:Z,setActiveView:Y}){let X=J.filter((G)=>!G.filePath),q=J.filter((G)=>G.filePath),_={};for(let G of q){let N=G.filePath;if(!_[N])_[N]=[];_[N].push(G)}let z=(G)=>{Z(G),C1(G,!0);let N=document.querySelector(`[data-annotation-id="${G}"]`);if(N)N.scrollIntoView({behavior:"smooth",block:"nearest"})},K=(G)=>{Z(null),C1(G,!1)},U=(G)=>{if(G.id===Q)Z(null);else if(Z(G.id),G.filePath)Y({type:"file",path:G.filePath}),setTimeout(()=>{let N=document.querySelector(`[data-annotation-id="${G.id}"]`);if(N)N.scrollIntoView({behavior:"smooth",block:"center"})},150)},H=(G)=>P("div",{className:`relative px-3 py-2.5 transition-colors duration-150 cursor-pointer ${Q===G.id?"bg-highlight-selected":"odd:bg-bg-elevated-half hover:bg-bg-input"}`,onMouseEnter:()=>z(G.id),onMouseLeave:()=>K(G.id),onClick:()=>U(G),children:[P("div",{className:"text-[11px] text-text-tertiary italic line-clamp-2 mb-1.5 leading-snug font-body border-l-2 border-border-medium pl-2",children:G.snippet.length>80?G.snippet.slice(0,80)+"...":G.snippet},void 0,!1,void 0,this),G.note.trim()&&P("div",{className:"text-[13px] font-body text-text-primary leading-relaxed",children:G.note},void 0,!1,void 0,this)]},G.id,!0,void 0,this);return P(v3,{children:[P("div",{className:"flex-1 overflow-y-auto",children:[X.length>0&&q.length>0&&P("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body px-3 mb-1 mt-1",children:"Plan"},void 0,!1,void 0,this),X.map(H),Object.entries(_).map(([G,N])=>P("div",{children:[P("button",{onClick:()=>Y({type:"file",path:G}),className:"flex items-center gap-1.5 text-[10px] uppercase tracking-widest text-text-tertiary hover:text-text-secondary font-body px-3 pt-3 pb-1 truncate transition-colors w-full text-left",title:G,children:[P(E1,{name:G.split("/").pop()||G,type:"file"},void 0,!1,void 0,this),P("span",{className:"truncate",children:G},void 0,!1,void 0,this)]},void 0,!0,void 0,this),N.map(H)]},G,!0,void 0,this))]},void 0,!0,void 0,this),$.trim()&&P("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:P("div",{className:"text-[13px] font-body text-text-primary leading-relaxed",children:$},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function u3({onPreview:J,onSubmit:$,collapseButton:Q}){let{annotations:Z,updateAnnotation:Y,removeAnnotation:X,generalNote:q,setGeneralNote:_,activeAnnotationId:z,setActiveAnnotationId:K,responses:U,feedbackEntries:H}=q1(),{setActiveView:G}=I3.useContext(I1),N=x5(null),W=x5(new Map),M=Z.filter((T)=>!T.filePath),F=Z.filter((T)=>T.filePath),L={};for(let T of F){let B=T.filePath;if(!L[B])L[B]=[];L[B].push(T)}o0(()=>{if(!z)return;let T=W.current.get(z);if(T)T.scrollIntoView({behavior:"smooth",block:"nearest"})},[z]);let y=h5((T)=>{K(T),C1(T,!0);let B=document.querySelector(`[data-annotation-id="${T}"]`);if(B)B.scrollIntoView({behavior:"smooth",block:"nearest"})},[K]),S=h5((T)=>{K(null),C1(T,!1)},[z]),R=Array.from(U.values()).some(l0),m=H.size>0,k=Z.length>0||q.trim().length>0||R||m,[V,w]=x1(null),I=(T)=>P("div",{ref:(B)=>{if(B)W.current.set(T.id,B);else W.current.delete(T.id)},className:`group/ann relative px-3 py-2.5 transition-colors duration-150 ${z===T.id?"bg-highlight-selected":"odd:bg-bg-elevated-half hover:bg-bg-input"}`,onMouseEnter:()=>y(T.id),onMouseLeave:()=>S(T.id),onClick:()=>{if(T.id===z)K(null);else if(K(T.id),T.filePath)G({type:"file",path:T.filePath}),setTimeout(()=>{let B=document.querySelector(`[data-annotation-id="${T.id}"]`);if(B)B.scrollIntoView({behavior:"smooth",block:"center"})},150)},children:[P("div",{className:"text-[11px] text-text-tertiary italic line-clamp-2 mb-1.5 leading-snug font-body border-l-2 border-border-medium pl-2",children:T.snippet.length>80?T.snippet.slice(0,80)+"...":T.snippet},void 0,!1,void 0,this),P("textarea",{value:T.note,onChange:(B)=>Y(T.id,B.target.value),onClick:(B)=>B.stopPropagation(),className:"w-full bg-transparent text-[13px] font-body text-text-primary resize-none focus:outline-none leading-relaxed p-0 border-none min-h-[20px]",rows:1,style:{height:"auto",overflow:"hidden"},onInput:(B)=>t1(B.target),ref:(B)=>{if(B)t1(B)}},void 0,!1,void 0,this),P("div",{className:"absolute top-1.5 right-1.5 opacity-0 group-hover/ann:opacity-100 transition-opacity duration-100",children:P("button",{onClick:(B)=>{B.stopPropagation(),X(T.id)},className:"w-5 h-5 flex items-center justify-center rounded text-text-tertiary hover:text-accent-red hover:bg-accent-red-muted transition-colors",title:"Delete annotation",children:P("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[P("polyline",{points:"3 6 5 6 21 6"},void 0,!1,void 0,this),P("path",{d:"M19 6v14a2 2 0 01-2 2H7a2 2 0 01-2-2V6m3 0V4a2 2 0 012-2h4a2 2 0 012 2v2"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},T.id,!0,void 0,this);return P("div",{className:"flex flex-col h-full",children:[P("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[P("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body flex items-center gap-2",children:["Annotations",Z.length>0&&P("span",{className:"inline-flex items-center justify-center min-w-[18px] h-[18px] px-1 rounded-full bg-border-subtle text-[10px] font-medium text-text-secondary",children:Z.length},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Q]},void 0,!0,void 0,this),P("div",{ref:N,className:"flex-1 overflow-y-auto",children:[Z.length===0&&P("p",{className:"text-[12px] text-text-tertiary px-3 py-4 leading-relaxed font-body",children:"Select text in the plan or in files to add annotations."},void 0,!1,void 0,this),M.length>0&&F.length>0&&P("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body px-3 mb-1 mt-1",children:"Plan"},void 0,!1,void 0,this),M.map(I),Object.entries(L).map(([T,B])=>P("div",{children:[P("button",{onClick:()=>G({type:"file",path:T}),className:"flex items-center gap-1.5 text-[10px] uppercase tracking-widest text-text-tertiary hover:text-text-secondary font-body px-3 pt-3 pb-1 truncate transition-colors w-full text-left",title:T,children:[P(E1,{name:T.split("/").pop()||T,type:"file"},void 0,!1,void 0,this),P("span",{className:"truncate",children:T},void 0,!1,void 0,this)]},void 0,!0,void 0,this),B.map(I)]},T,!0,void 0,this))]},void 0,!0,void 0,this),P("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:P("textarea",{value:q,onChange:(T)=>_(T.target.value),className:"w-full bg-transparent text-[13px] font-body text-text-primary resize-none leading-relaxed p-0 border-none ring-0 shadow-none outline-none focus:outline-none focus:ring-0 focus:border-none placeholder:text-text-disabled min-h-[40px]",placeholder:"General notes...",onInput:(T)=>t1(T.target,40),ref:(T)=>{if(T)t1(T,40)}},void 0,!1,void 0,this)},void 0,!1,void 0,this),V&&P("div",{className:"px-4 py-2 text-[12px] text-accent-red font-body border-t border-border-subtle flex-shrink-0 flex items-center justify-between gap-2",children:[P("span",{children:V},void 0,!1,void 0,this),P("button",{onClick:()=>{w(null);let T=Q0(Z,q,U,H);$(T)},className:"text-[11px] text-text-tertiary hover:text-text-secondary font-body whitespace-nowrap underline",children:"Submit anyway"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),P("div",{className:"px-4 py-3 border-t border-border-subtle flex-shrink-0",children:k?P("div",{className:"flex gap-2",children:[P("button",{onClick:J,className:"flex-1 py-2 rounded-lg font-body text-[13px] font-medium transition-all bg-border-subtle text-text-secondary hover:bg-border-medium hover:text-text-primary",children:"Preview"},void 0,!1,void 0,this),P("button",{onClick:()=>{let T=L0(U,H);if(T.length>0){w(`Please answer: ${T.join(", ")}`);return}w(null);let B=Q0(Z,q,U,H);$(B)},className:"flex-1 py-2 rounded-lg font-body text-[13px] font-medium transition-all bg-btn-primary text-btn-primary-text hover:opacity-90 hover:-translate-y-px shadow-sm",children:"Submit"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):P("button",{onClick:()=>$("No feedback — looks good."),className:"w-full py-2 rounded-lg font-body text-[13px] font-medium border border-border-medium text-text-secondary hover:text-text-primary hover:border-border-hover hover:bg-bg-input transition-all",children:"Submit without feedback"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{useEffect as E3,useState as p5,useContext as c5,useMemo as x3}from"react";import{SessionContext as h3}from"#canvas/runtime";import{jsxDEV as f,Fragment as t0}from"react/jsx-dev-runtime";function d5({embedded:J}={}){let $=c5(h3),{annotations:Q,addAnnotation:Z}=q1(),{setActiveView:Y}=c5(I1),[X,q]=p5(!1),[_,z]=p5({}),{annCountMap:K,annotatedFiles:U}=x3(()=>{let y=new Map;for(let S of Q)if(S.filePath)y.set(S.filePath,(y.get(S.filePath)||0)+1);return{annCountMap:y,annotatedFiles:[...y.keys()]}},[Q]),H=async(y)=>{let R=await(await fetch(`/api/tree?session=${$}&path=${encodeURIComponent(y)}`)).json();if(R.entries)z((m)=>({...m,[y]:{entries:R.entries,expanded:!0,loaded:!0}}))};E3(()=>{if(!X&&!_[""])H("")},[X]);let G=(y)=>{if(_[y]?.loaded)z((S)=>({...S,[y]:{...S[y],expanded:!S[y].expanded}}));else H(y)},N=(y)=>{Y({type:"file",path:y})},W=async(y)=>{let R=await(await fetch(`/api/file?session=${$}&path=${encodeURIComponent(y)}`)).json();if(!R.error){let m=R.content.split(`
|
|
52
94
|
`).slice(0,3).join(`
|
|
53
|
-
`)+(
|
|
95
|
+
`)+(R.content.split(`
|
|
54
96
|
`).length>3?`
|
|
55
|
-
...`:"");Z(m,"Include this file for context",
|
|
56
|
-
`)
|
|
57
|
-
`)
|
|
97
|
+
...`:"");Z(m,"Include this file for context",y)}},M=async(y)=>{let S=[];if(_[y]?.loaded)S=_[y].entries;else{let m=await(await fetch(`/api/tree?session=${$}&path=${encodeURIComponent(y)}`)).json();if(m.entries)S=m.entries}await Promise.all(S.filter((R)=>R.type==="file").map((R)=>W(y?`${y}/${R.name}`:R.name)))},F=(y)=>K.get(y)||0,L=(y,S=0)=>{let R=_[y];if(!R?.expanded)return null;return R.entries.map((m)=>{let k=y?`${y}/${m.name}`:m.name,V=F(k);return f("div",{children:[f("div",{className:"group/item flex items-center py-[3px] hover:bg-bg-elevated text-[13px] font-body cursor-default transition-colors duration-100",style:{paddingLeft:`${16+S*16}px`,paddingRight:"8px"},children:m.type==="dir"?f(t0,{children:[f("span",{onClick:()=>G(k),className:"flex items-center gap-1.5 flex-1 text-text-secondary hover:text-text-primary cursor-pointer truncate",children:[f(E1,{name:m.name,type:"dir",expanded:_[k]?.expanded},void 0,!1,void 0,this),f("span",{className:"truncate",children:m.name},void 0,!1,void 0,this)]},void 0,!0,void 0,this),f("button",{onClick:(w)=>{w.stopPropagation(),M(k)},className:"text-[11px] text-text-tertiary hover:text-text-secondary opacity-0 group-hover/item:opacity-100 transition-opacity px-1 flex-shrink-0",title:"Add all files in folder",children:"+"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):f(t0,{children:[f("span",{onClick:()=>N(k),className:`flex-1 truncate cursor-pointer flex items-center gap-1.5 ${V>0?"text-text-primary":"text-text-secondary hover:text-text-primary"}`,children:[f(E1,{name:m.name,type:"file"},void 0,!1,void 0,this),f("span",{className:"truncate",children:m.name},void 0,!1,void 0,this)]},void 0,!0,void 0,this),f("div",{className:"flex items-center gap-1 flex-shrink-0 ml-1",children:[V>0&&f("span",{className:"text-[10px] font-medium bg-badge-bg text-accent-amber px-1.5 py-px rounded-full min-w-[18px] text-center",children:V},void 0,!1,void 0,this),f("button",{onClick:(w)=>{w.stopPropagation(),W(k)},className:"text-[11px] text-text-tertiary hover:text-text-secondary opacity-0 group-hover/item:opacity-100 transition-opacity px-1",title:"Add file to context",children:"+"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),m.type==="dir"&&L(k,S+1)]},k,!0,void 0,this)})};if(J)return f(t0,{children:[f("div",{className:"flex items-center justify-between px-4 pt-3 pb-2 flex-shrink-0",children:f("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:"Files"},void 0,!1,void 0,this)},void 0,!1,void 0,this),f("div",{className:"flex-1 overflow-y-auto",children:L("")},void 0,!1,void 0,this),U.length>0&&f("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:[f("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body mb-1.5",children:"Referenced"},void 0,!1,void 0,this),U.map((y)=>f("div",{onClick:()=>N(y),className:"flex items-center justify-between text-[12px] font-body text-text-secondary hover:text-text-primary cursor-pointer py-0.5",children:[f("span",{className:"truncate",children:y.split("/").pop()},void 0,!1,void 0,this),f("span",{className:"text-[10px] font-medium bg-badge-bg text-accent-amber px-1.5 py-px rounded-full min-w-[18px] text-center flex-shrink-0 ml-1",children:F(y)},void 0,!1,void 0,this)]},y,!0,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);if(X)return f("div",{className:"hidden lg:flex w-8 border-r border-border-subtle bg-bg-surface flex-col items-center flex-shrink-0",children:f("button",{onClick:()=>q(!1),className:"mt-3 p-1 text-text-tertiary hover:text-text-secondary transition-colors",children:f("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:f("path",{d:"M5 3l4 4-4 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this);return f("div",{className:"hidden lg:flex w-60 border-r border-border-subtle bg-bg-surface flex-col flex-shrink-0 overflow-hidden",children:[f("div",{className:"flex items-center justify-between px-4 pt-4 pb-3 flex-shrink-0",children:[f("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:"Files"},void 0,!1,void 0,this),f("button",{onClick:()=>q(!0),className:"text-text-tertiary hover:text-text-secondary transition-colors p-0.5",children:f("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:f("path",{d:"M9 3l-4 4 4 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),f("div",{className:"flex-1 overflow-y-auto",children:L("")},void 0,!1,void 0,this),U.length>0&&f("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:[f("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body mb-1.5",children:"Referenced"},void 0,!1,void 0,this),U.map((y)=>f("div",{onClick:()=>N(y),className:"flex items-center justify-between text-[12px] font-body text-text-secondary hover:text-text-primary cursor-pointer py-0.5",children:[f("span",{className:"truncate",children:y.split("/").pop()},void 0,!1,void 0,this),f("span",{className:"text-[10px] font-medium bg-badge-bg text-accent-amber px-1.5 py-px rounded-full min-w-[18px] text-center flex-shrink-0 ml-1",children:F(y)},void 0,!1,void 0,this)]},y,!0,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}import{useEffect as p1,useState as T1,useContext as p3,useCallback as r5,useRef as M1,useMemo as l5}from"react";import{SessionContext as c3}from"#canvas/runtime";var b0={ts:"typescript",tsx:"typescript",js:"javascript",jsx:"javascript",py:"python",rs:"rust",go:"go",rb:"ruby",java:"java",json:"json",yaml:"yaml",yml:"yaml",md:"markdown",css:"css",html:"html",sh:"bash",bash:"bash",toml:"toml",sql:"sql",xml:"xml",c:"c",cpp:"cpp",h:"c"};import{jsxDEV as N1}from"react/jsx-dev-runtime";function a5(J){let $=J instanceof HTMLElement?J:J.parentElement;while($){if($.hasAttribute("data-line-num"))return $;$=$.parentElement}return null}function i5({path:J}){let $=p3(c3),{annotations:Q,addAnnotationWithId:Z,removeAnnotation:Y,updateAnnotation:X,activeAnnotationId:q,setActiveAnnotationId:_}=q1(),[z,K]=T1(null),[U,H]=T1("text"),[G,N]=T1(!0),[W,M]=T1(null),F=M1(null),[L,y]=T1(null),S=M1(""),[R,m]=T1(null),[k,V]=T1(null),w=M1(null),I=M1(null),T=M1([]),[B,c]=T1(null),[o,Z1]=T1(null),P1=Q.filter((A)=>A.filePath===J);p1(()=>{N(!0),M(null),fetch(`/api/file?session=${$}&path=${encodeURIComponent(J)}`).then((A)=>A.json()).then((A)=>{if(A.error)M(A.error),N(!1);else K(A.content),H(A.language||"text"),N(!1)}).catch(()=>{M("Failed to fetch file"),N(!1)})},[$,J]),p1(()=>{if(!z||!F.current)return;let A=setTimeout(()=>{if(F.current)O0(F.current,P1)},50);return()=>clearTimeout(A)},[z,J]);let j=M1(null);p1(()=>{W0(q,j.current),j.current=q},[q]),p1(()=>{let A=F.current;if(!A)return;let g=(t)=>{let $1=t.target.closest("[data-annotation-id]");if(!$1)return;t.stopPropagation();let O1=$1.getAttribute("data-annotation-id");if(O1===q)c({anchorEl:$1,annId:O1});else _(O1)},a=(t)=>{let $1=t.target.closest("[data-annotation-id]");if($1)_($1.getAttribute("data-annotation-id"))},n=(t)=>{let $1=t.target.closest("[data-annotation-id]"),O1=t.relatedTarget?.closest?.("[data-annotation-id]");if($1&&!O1&&!document.getElementById("ann-inline-popover"))_(null)};return A.addEventListener("click",g),A.addEventListener("mouseover",a),A.addEventListener("mouseout",n),()=>{A.removeEventListener("click",g),A.removeEventListener("mouseover",a),A.removeEventListener("mouseout",n)}},[z,Q,q]),p1(()=>{let A=()=>C();return document.addEventListener("mouseup",A),()=>document.removeEventListener("mouseup",A)},[]);let i=M1(J);i.current=J;let b=M1(Z);b.current=Z;let C=r5(()=>{let A=window.getSelection();if(!A||A.isCollapsed||!A.toString().trim())return;if(!F.current)return;let g=A.getRangeAt(0);if(!F.current.contains(g.startContainer))return;if(g.startContainer.parentElement?.closest?.("[data-annotation-id]"))return;let a=A.toString().trim();if(a.length<2)return;let n=a5(g.startContainer),t=a5(g.endContainer),$1=n?parseInt(n.getAttribute("data-line-num"),10):void 0,O1=t?parseInt(t.getAttribute("data-line-num"),10):void 0,D1="",f1="";if(a.length<30&&n&&n===t){let k1=n.querySelector("code");if(k1){let S1=k1.textContent||"",b1=S1.indexOf(a);if(b1>=0)D1=S1.slice(0,b1).trimStart(),f1=S1.slice(b1+a.length).trimEnd()}}let m0={before:D1,after:f1,hierarchy:[],lineStart:$1,lineEnd:O1},F1=`__pending_${Date.now()}`,z0=g.cloneRange();try{u1(z0,F1)}catch{}A.removeAllRanges();let r1=document.querySelectorAll(`[data-annotation-id="${F1}"]`),l1=r1[r1.length-1];if(!l1)return;S.current=a,y(F1),Z1({anchorEl:l1,tempId:F1,snippet:a,ctx:m0})},[]),h=r5((A,g)=>{A.preventDefault(),w.current=g,I.current=g,m(g),V(g)},[]);p1(()=>{let A=(a)=>{if(w.current===null)return;let n=a.target.closest("[data-line-num]");if(n){let t=parseInt(n.getAttribute("data-line-num"),10);I.current=t,V(t)}},g=()=>{let a=w.current;if(a===null)return;w.current=null;let n=I.current??a,t=Math.min(a,n),$1=Math.max(a,n),D1=T.current.slice(t-1,$1).join(`
|
|
98
|
+
`);if(!D1.trim()){m(null),V(null);return}let f1=`__pending_${Date.now()}`,m0={before:"",after:"",hierarchy:[],lineStart:t,lineEnd:$1};if(F.current){let F1=F.current.querySelectorAll("[data-line-num]"),z0=F1[t-1],r1=F1[$1-1];if(z0&&r1){let k1=z0.querySelector("code"),S1=r1.querySelector("code");if(k1&&S1)try{let b1=document.createRange();b1.setStartBefore(k1.firstChild||k1),b1.setEndAfter(S1.lastChild||S1),u1(b1,f1)}catch{}}let l1=F1[$1-1];if(l1)S.current=D1,y(f1),Z1({anchorEl:l1,tempId:f1,snippet:D1,ctx:m0})}m(null),V(null)};return document.addEventListener("mousemove",A),document.addEventListener("mouseup",g),()=>{document.removeEventListener("mousemove",A),document.removeEventListener("mouseup",g)}},[]);let x=l5(()=>{if(!z)return null;let A=window.hljs;if(!A)return null;let g=J.split(".").pop()||"",a=b0[g];try{return(a?A.highlight(z,{language:a}):A.highlightAuto(z)).value.split(`
|
|
99
|
+
`)}catch{return null}},[z,J]);if(G)return N1("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-[13px]",children:["Loading ",J,"..."]},void 0,!0,void 0,this);if(W)return N1("div",{className:"p-8 text-accent-red font-body text-[13px]",children:W},void 0,!1,void 0,this);if(!z)return null;let p=z.split(`
|
|
100
|
+
`);T.current=p;let u=l5(()=>{if(R===null)return null;let A=k??R;return{start:Math.min(R,A),end:Math.max(R,A)}},[R,k]),r=()=>{let A=z.split(`
|
|
58
101
|
`).slice(0,3).join(`
|
|
59
|
-
`)+(
|
|
60
|
-
...`:""),
|
|
102
|
+
`)+(p.length>3?`
|
|
103
|
+
...`:""),g=H1();Z(g,A,"",J),_(g)},d=F.current?.closest("#plan-scroll-container");return N1("div",{children:[N1("pre",{ref:F,className:"text-code font-mono text-text-code bg-bg-base select-text cursor-text py-3 hljs",children:p.map((A,g)=>{let a=g+1,n=u&&a>=u.start&&a<=u.end;return N1("div",{"data-line-num":a,className:`flex px-5 ${n?"bg-accent-blue/10":"hover:bg-bg-elevated-half"}`,children:[N1("span",{className:"text-text-tertiary select-none w-10 text-right pr-4 shrink-0 py-px text-[12px] cursor-pointer opacity-40 hover:opacity-100 hover:text-accent-blue",onMouseDown:(t)=>h(t,a),children:a},void 0,!1,void 0,this),x?N1("code",{className:"py-px",dangerouslySetInnerHTML:{__html:x[g]||" "}},void 0,!1,void 0,this):N1("code",{className:"py-px",children:A||" "},void 0,!1,void 0,this)]},g,!0,void 0,this)})},void 0,!1,void 0,this),B&&(()=>{let A=Q.find((g)=>g.id===B.annId);if(!A)return null;return N1(Y0,{anchorEl:B.anchorEl,scrollContainer:d,initialNote:A.note,onUpdate:(g)=>X(B.annId,g),onDelete:()=>{Y(B.annId),_(null)},onClose:()=>c(null)},void 0,!1,void 0,this)})(),o&&N1(J0,{anchorEl:o.anchorEl,scrollContainer:d,snippet:o.snippet,onAdd:(A)=>{let g=H1();T0(o.tempId,g),Z(g,o.snippet,A,J,o.ctx),y(null),Z1(null)},onCancel:()=>{F0(o.tempId),y(null),Z1(null)}},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{useEffect as o5,useState as s5,useRef as d3}from"react";import{jsxDEV as W1}from"react/jsx-dev-runtime";function t5(J,$){if($){let Q=$.replace(/\/+$/,"").split("/");return Q[Q.length-1]||J}return J.length>30?J.slice(0,30)+"...":J}function n0({currentSessionId:J,projectRoot:$}){let[Q,Z]=s5([]),[Y,X]=s5(!1),q=d3(null);o5(()=>{let K=async()=>{try{let G=await(await fetch("/api/sessions")).json();Z((N)=>{let W=JSON.stringify(G);return JSON.stringify(N)===W?N:G})}catch{}};K();let U=setInterval(K,5000);return()=>clearInterval(U)},[]),o5(()=>{if(!Y)return;let K=(U)=>{if(q.current&&!q.current.contains(U.target))X(!1)};return document.addEventListener("mousedown",K),()=>document.removeEventListener("mousedown",K)},[Y]);let _=Q.filter((K)=>K.id!==J),z=t5(J,$);return W1("div",{className:"relative",ref:q,children:[W1("div",{className:"flex items-center gap-1.5 font-body text-body font-medium",children:[W1("a",{href:`/s/${J}`,className:"text-text-primary hover:text-text-secondary transition-colors",children:z},void 0,!1,void 0,this),_.length>0&&W1("button",{onClick:()=>X(!Y),className:"flex items-center justify-center text-text-tertiary hover:text-text-secondary transition-colors",children:W1("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",className:`transition-transform duration-200 ${Y?"rotate-180":""}`,children:W1("path",{d:"M3 5l3 3 3-3",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Y&&_.length>0&&W1("div",{className:"absolute top-full left-0 mt-2 w-64 bg-bg-elevated border border-border-hover rounded-lg shadow-lg z-50 py-1 overflow-hidden",children:_.map((K)=>W1("a",{href:`/s/${K.id}`,className:"flex items-center gap-2.5 px-4 py-2.5 text-body font-body text-text-secondary hover:bg-bg-surface hover:text-text-primary transition-colors",children:[W1("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${K.currentRevision>0?"bg-accent-green":"bg-border-hover"}`},void 0,!1,void 0,this),W1("span",{className:"truncate",children:t5(K.id,K.projectRoot)},void 0,!1,void 0,this)]},K.id,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function n5(J){let $=[];return A0(J,$,0),$.join(`
|
|
61
104
|
`).replace(/\n{3,}/g,`
|
|
62
105
|
|
|
63
106
|
`).trim()+`
|
|
64
|
-
`}var E5=new Set(["CODE","SPAN","STRONG","EM","A","B","I","U","SMALL","SUB","SUP","MARK","ABBR"]);function E1($,J,Q){if(h5($)){let Z=x5($);if(Z)J.push(Z,"");return}for(let Z of $.childNodes)if(Z.nodeType===Node.ELEMENT_NODE)p5(Z,J,Q);else if(Z.nodeType===Node.TEXT_NODE){let Y=Z.textContent?.trim();if(Y)J.push(Y,"")}}function h5($){for(let J of $.childNodes){if(J.nodeType===Node.TEXT_NODE)continue;if(J.nodeType===Node.ELEMENT_NODE){let Q=J;if(!E5.has(Q.tagName)||Q.hasAttribute("data-md"))return!1}}return $.childNodes.length>0}function x5($){let J="";for(let Q of $.childNodes)if(Q.nodeType===Node.TEXT_NODE)J+=Q.textContent||"";else if(Q.nodeType===Node.ELEMENT_NODE){let Z=Q;if(Z.tagName==="CODE")J+="`"+(Z.textContent||"")+"`";else J+=Z.textContent||""}return J.trim()}function p5($,J,Q){let Z=$.getAttribute("data-md");if(Z)switch(Z){case"section":return c5($,J,Q);case"item":return d5($,J);case"codeblock":return r5($,J);case"callout":return l5($,J);case"note":return i5($,J);case"table":return a5($,J);case"checklist":return o5($,J);case"diff":return s5($,J);case"mermaid":return t5($,J);case"choice":return n5($,J);case"multichoice":return e5($,J);case"choice-option":case"multichoice-option":return;case"userinput":return $2($,J);case"rangeinput":return J2($,J);case"checklist-item":return;case"filepreview":return Q2($,J);case"priority":return Y2($,J)}if($.querySelector("button, input, select, textarea"))return;if($.children.length>0)E1($,J,Q);else{let Y=$.textContent?.trim();if(Y)J.push(Y,"")}}function c5($,J,Q){let Z=$.getAttribute("data-md-title")||"Untitled",Y=Q===0?"##":"###";J.push(`${Y} ${Z}`,"");let X=$.querySelector(":scope > div:last-of-type");if(X)E1(X,J,Q+1)}function d5($,J){let Q=$.getAttribute("data-md-label")||"",Z=$.getAttribute("data-md-status"),Y=$.getAttribute("data-md-badge"),X="-";if(Z==="done")X="- [x]";else if(Z)X="- [ ]";let z=`${X} **${Q}**`;if(Y)z+=` \`${Y}\``;J.push(z);let q=$.querySelector(".text-text-secondary");if(q){let _=[];E1(q,_,0);for(let U of _)J.push(U?` ${U}`:"")}J.push("")}function r5($,J){let Q=$.getAttribute("data-md-language")||"",Y=$.querySelector("code")?.textContent||"";J.push(`\`\`\`${Q}`,Y,"```","")}function l5($,J){let Q=$.getAttribute("data-md-type")||"info",Z={info:"Info",warning:"Warning",danger:"Danger",tip:"Tip"},Y=Z2($.querySelector(".text-text-secondary")||$);J.push(`> **${Z[Q]||Q}:** ${Y}`,"")}function i5($,J){let Q=$.textContent?.trim()||"";J.push(`> *${Q}*`,"")}function a5($,J){let Q=$.querySelector("table");if(!Q)return;let Z=[];for(let Y of Q.querySelectorAll("thead th"))Z.push(Y.textContent?.trim()||"");if(Z.length===0)return;J.push(`| ${Z.join(" | ")} |`),J.push(`| ${Z.map(()=>"---").join(" | ")} |`);for(let Y of Q.querySelectorAll("tbody tr")){let X=[];for(let z of Y.querySelectorAll("td"))X.push(z.textContent?.trim()||"");J.push(`| ${X.join(" | ")} |`)}J.push("")}function o5($,J){for(let Q of $.querySelectorAll("li")){let Z=Q.querySelector(".bg-accent-green")!==null,Y=Q.textContent?.trim()||"";J.push(`- [${Z?"x":" "}] ${Y}`)}J.push("")}function s5($,J){let Q=$.getAttribute("data-md-language")||"";J.push(`\`\`\`diff${Q?` (${Q})`:""}`);for(let Z of $.querySelectorAll("[class*='flex']")){let Y=Z.querySelector(".text-accent-red")?"-":Z.querySelector(".text-accent-green")?"+":" ",X=Z.querySelector("code");if(X)J.push(`${Y} ${X.textContent}`)}J.push("```","")}function t5($,J){let Q=$.getAttribute("data-md-source")||"";if(Q)J.push("```mermaid",Q,"```","")}function n5($,J){let Q=$.getAttribute("data-md-label")||"";J.push(`**${Q}:**`);for(let Z of $.querySelectorAll("[data-md='choice-option']")){let Y=Z.getAttribute("data-md-label")||Z.textContent?.trim()||"",X=Z.querySelector(".bg-accent-amber")!==null;J.push(`- ${X?"(x)":"( )"} ${Y}`)}J.push("")}function e5($,J){let Q=$.getAttribute("data-md-label")||"";J.push(`**${Q}:**`);for(let Z of $.querySelectorAll("[data-md='multichoice-option']")){let Y=Z.getAttribute("data-md-label")||Z.textContent?.trim()||"",X=Z.querySelector(".bg-accent-amber")!==null;J.push(`- [${X?"x":" "}] ${Y}`)}J.push("")}function $2($,J){let Q=$.getAttribute("data-md-label")||"",Y=$.querySelector("textarea")?.value?.trim()||"";J.push(`**${Q}:** ${Y||"_empty_"}`,"")}function J2($,J){let Q=$.getAttribute("data-md-label")||"",Z=$.querySelector("input[type='range']"),X=$.querySelector(".font-mono")?.textContent?.trim()||Z?.value||"—";J.push(`**${Q}:** ${X}`,"")}function Q2($,J){let Q=$.getAttribute("data-md-path")||"",Z=$.getAttribute("data-md-lines")||"",X=$.querySelector("code")?.textContent||"",z=Q.split(".").pop()||"",q=u1[z]||"",_=Z?`${Q} (L${Z})`:Q;J.push(_,"",`\`\`\`${q}`,X,"```","")}function Y2($,J){}function Z2($){return $?.textContent?.trim()||""}import O2,{useEffect as W1,useState as l,useRef as Z1}from"react";import{useEffect as X2,useState as z2,useRef as q2,useContext as _2}from"react";import{jsxDEV as t,Fragment as h0}from"react/jsx-dev-runtime";function U2($){return $.label||`Round ${$.revision}`}function K2($){let J=Date.now()-new Date($).getTime(),Q=Math.floor(J/1000);if(Q<60)return"just now";let Z=Math.floor(Q/60);if(Z<60)return`${Z}m ago`;let Y=Math.floor(Z/60);if(Y<24)return`${Y}h ago`;return`${Math.floor(Y/24)}d ago`}function A1({value:$,onChange:J,accent:Q="default",className:Z}){let{currentRevision:Y,revisions:X}=_2(H1),[z,q]=z2(!1),_=q2(null);X2(()=>{if(!z)return;let G=(W)=>{if(_.current&&!_.current.contains(W.target))q(!1)};return document.addEventListener("mousedown",G),()=>document.removeEventListener("mousedown",G)},[z]);let U=X.find((G)=>G.revision===$);return t("div",{className:"relative",ref:_,children:[t("button",{onClick:()=>q(!z),className:`flex items-center gap-1.5 text-[12px] font-body font-medium px-2 py-1 rounded-md transition-colors hover:bg-bg-elevated ${{default:"text-text-secondary hover:text-text-primary",red:"text-accent-red",green:"text-accent-green",amber:"text-accent-amber bg-highlight-selected"}[Q]} ${Z||""}`,children:[U?U2(U):`Round ${$}`,t("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",className:`text-text-tertiary transition-transform duration-200 ${z?"rotate-180":""}`,children:t("path",{d:"M2.5 4l2.5 2.5L7.5 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z&&t("div",{className:"absolute top-full left-0 mt-1 w-64 bg-bg-elevated border border-border-hover rounded-lg shadow-lg z-50 py-1 max-h-80 overflow-y-auto",children:[...X].reverse().map((G)=>t("button",{onClick:()=>{J(G.revision),q(!1)},className:`w-full flex items-center gap-2 px-3 py-2 text-[12px] font-body transition-colors ${G.revision===$?"bg-bg-surface text-text-primary":"text-text-secondary hover:bg-bg-surface hover:text-text-primary"}`,children:[t("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${G.revision===Y?"bg-accent-green":G.hasFeedback?"bg-accent-amber":"bg-border-hover"}`},void 0,!1,void 0,this),t("span",{className:"flex-1 text-left truncate",children:G.label?t(h0,{children:[G.label," ",t("span",{className:"text-text-tertiary",children:["#",G.revision]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):t(h0,{children:["Round ",G.revision]},void 0,!0,void 0,this)},void 0,!1,void 0,this),t("span",{className:"text-[10px] text-text-tertiary flex-shrink-0",children:G.revision===Y?"current":G.hasFeedback?"sent":K2(G.createdAt)},void 0,!1,void 0,this)]},G.revision,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function h1($,J){let Q=$.length,Z=J.length;if(Q===0||Z===0)return[];let Y=Array.from({length:Q+1},()=>Array(Z+1).fill(0));for(let _=1;_<=Q;_++)for(let U=1;U<=Z;U++)Y[_][U]=$[_-1]===J[U-1]?Y[_-1][U-1]+1:Math.max(Y[_-1][U],Y[_][U-1]);let X=[],z=Q,q=Z;while(z>0&&q>0)if($[z-1]===J[q-1])X.unshift($[z-1]),z--,q--;else if(Y[z-1][q]>Y[z][q-1])z--;else q--;return X}function x0($){let J=[],Q=[],Z=document.createTreeWalker($,NodeFilter.SHOW_TEXT,{acceptNode(X){let z=X.parentElement;if(!z)return NodeFilter.FILTER_REJECT;if(z.closest("svg, .select-none, [data-no-diff]"))return NodeFilter.FILTER_REJECT;return NodeFilter.FILTER_ACCEPT}}),Y;while(Y=Z.nextNode()){let z=(Y.nodeValue||"").match(/\S+|\s+/g);if(!z)continue;let q=0;for(let _ of z)J.push(_),Q.push({text:_,node:Y,offset:q}),q+=_.length}return{words:J,map:Q}}function Z0($,J){if($.length>5000||J.length>5000)return G2($,J);return d0($,J)}function d0($,J){let Q=x1($,J),Z=[],Y=[],X=0,z=0,q=0;while(X<$.length||z<J.length)if(q<Q.length&&X<$.length&&z<J.length&&$[X]===Q[q]&&J[z]===Q[q])Z.push({type:"same",index:X}),Y.push({type:"same",index:z}),X++,z++,q++;else if(X<$.length&&(q>=Q.length||$[X]!==Q[q]))Z.push({type:"removed",index:X}),X++;else if(z<J.length)Y.push({type:"added",index:z}),z++;return{oldOps:Z,newOps:Y}}function x1($,J){let Q=$.length,Z=J.length;if(Q===0||Z===0)return[];if(Q===1)return J.includes($[0])?[$[0]]:[];if(Z===1)return $.includes(J[0])?[J[0]]:[];if(Q*Z<=1e6)return h1($,J);let Y=Math.floor(Q/2),X=$.slice(0,Y),z=$.slice(Y),q=p0(X,J),_=p0([...z].reverse(),[...J].reverse()),U=0,K=0;for(let T=0;T<=Z;T++){let N=q[T]+_[Z-T];if(N>U)U=N,K=T}let G=J.slice(0,K),W=J.slice(K);return[...x1(X,G),...x1(z,W)]}function p0($,J){let Q=J.length,Z=Array(Q+1).fill(0),Y=Array(Q+1).fill(0);for(let X=0;X<$.length;X++){for(let z=1;z<=Q;z++)Y[z]=$[X]===J[z-1]?Z[z-1]+1:Math.max(Z[z],Y[z-1]);[Z,Y]=[Y,Z],Y.fill(0)}return Z}function G2($,J){let Z=(N)=>{let S=[];for(let O=0;O<N.length;O+=200){let P=Math.min(O+200,N.length);S.push({start:O,end:P,text:N.slice(O,P).join("")})}return S},Y=Z($),X=Z(J),z=Y.map((N)=>N.text),q=X.map((N)=>N.text),_=x1(z,q),U=[],K=[],G=0,W=0,T=0;while(G<Y.length||W<X.length)if(T<_.length&&G<Y.length&&W<X.length&&z[G]===_[T]&&q[W]===_[T]){for(let N=Y[G].start;N<Y[G].end;N++)U.push({type:"same",index:N});for(let N=X[W].start;N<X[W].end;N++)K.push({type:"same",index:N});G++,W++,T++}else if(G<Y.length&&(T>=_.length||z[G]!==_[T]))if(W<X.length&&(T>=_.length||q[W]!==_[T])){let N=d0($.slice(Y[G].start,Y[G].end),J.slice(X[W].start,X[W].end));for(let S of N.oldOps)U.push({type:S.type,index:S.index+Y[G].start});for(let S of N.newOps)K.push({type:S.type,index:S.index+X[W].start});G++,W++}else{for(let N=Y[G].start;N<Y[G].end;N++)U.push({type:"removed",index:N});G++}else if(W<X.length){for(let N=X[W].start;N<X[W].end;N++)K.push({type:"added",index:N});W++}return{oldOps:U,newOps:K}}function c0($,J,Q){let Z=new Map;for(let Y of $){if(Y.type==="same")continue;let X=J[Y.index];if(!X||!X.node.parentNode)continue;let z=Z.get(X.node);if(!z)z=[],Z.set(X.node,z);z.push({offset:X.offset,length:X.text.length})}for(let[Y,X]of Z){if(!Y.parentNode)continue;let z=Y.nodeValue||"";X.sort((G,W)=>G.offset-W.offset);let q=[];for(let G of X){let W=q[q.length-1];if(W&&G.offset<=W.offset+W.length)W.length=Math.max(W.length,G.offset+G.length-W.offset);else q.push({...G})}let _=Y.parentNode,U=document.createDocumentFragment(),K=0;for(let G of q){if(G.offset>K)U.appendChild(document.createTextNode(z.slice(K,G.offset)));let W=document.createElement("span");W.className=Q,W.textContent=z.slice(G.offset,G.offset+G.length),U.appendChild(W),K=G.offset+G.length}if(K<z.length)U.appendChild(document.createTextNode(z.slice(K)));_.replaceChild(U,Y)}}function r0($,J){let Q=x0($),Z=x0(J),{oldOps:Y,newOps:X}=Z0(Q.words,Z.words),z=Y.some((q)=>q.type==="removed")||X.some((q)=>q.type==="added");return c0(Y,Q.map,"diff-removed"),c0(X,Z.map,"diff-added"),z}function X0($){let J=[],Q=$.querySelectorAll(":scope > [data-md]");for(let Z of Q)J.push(w1(Z));if(J.length===0){let Z=$.querySelectorAll("[data-md]"),Y=new Set;for(let X of Z){let z=X.parentElement?.closest("[data-md]");if(z&&$.contains(z))continue;if(Y.has(X))continue;Y.add(X),J.push(w1(X))}}return J}function w1($){let J=$.getAttribute("data-md")||"unknown",Q=H2($,J),Z=[];if(J==="section"){let Y=$.querySelector(":scope > div.mt-6, :scope > div:last-child");if(Y)for(let X of Y.querySelectorAll(":scope > [data-md]"))Z.push(w1(X))}else if(J==="table")for(let Y of $.querySelectorAll(":scope table > tbody > tr"))Z.push({key:"tr:"+(Y.textContent||"").slice(0,80),type:"tr",element:Y,children:[]});else if(J==="checklist")for(let Y of $.querySelectorAll(":scope > [data-md='checklist-item']"))Z.push(w1(Y));else for(let Y of $.querySelectorAll("[data-md]"))if(Y.parentElement?.closest("[data-md]")===$)Z.push(w1(Y));return{key:Q,type:J,element:$,children:Z}}function H2($,J){switch(J){case"section":return"section:"+($.getAttribute("data-md-title")||"");case"item":return"item:"+($.getAttribute("data-task-id")||$.getAttribute("data-md-label")||"");case"codeblock":case"diff":return J+":"+($.textContent||"").slice(0,80);case"checklist-item":return"checklist-item:"+($.getAttribute("data-md-label")||$.textContent?.slice(0,60)||"");case"checklist":return"checklist:"+$.querySelectorAll("[data-md='checklist-item']").length;case"callout":return"callout:"+($.getAttribute("data-md-type")||"")+":"+($.textContent||"").slice(0,60);default:return J+":"+($.getAttribute("data-md-label")||$.textContent?.slice(0,60)||"")}}function z0($,J){let Q=$.map((U)=>U.key),Z=J.map((U)=>U.key),Y=h1(Q,Z),X=[],z=0,q=0,_=0;while(z<$.length||q<J.length)if(_<Y.length&&z<$.length&&q<J.length&&Q[z]===Y[_]&&Z[q]===Y[_]){let U=$[z],K=J[q],G=U.children.length>0||K.children.length>0?z0(U.children,K.children):void 0;X.push({kind:"matched",oldBlock:U,newBlock:K,childMatches:G}),z++,q++,_++}else if(z<$.length&&(_>=Y.length||Q[z]!==Y[_]))X.push({kind:"removed",oldBlock:$[z]}),z++;else if(q<J.length)X.push({kind:"added",newBlock:J[q]}),q++;return X}function i0($){let J=document.createDocumentFragment(),Q=!1;for(let Z of $)if(Z.kind==="removed")Q=!0,J.appendChild(a0(Z.oldBlock.element));else if(Z.kind==="added")Q=!0,J.appendChild(W2(Z.newBlock.element));else{let Y=Z.newBlock.element.cloneNode(!0),X=Z.newBlock.type;if(Z.childMatches&&Z.childMatches.length>0&&(X==="table"||X==="checklist")){if(s0(Y,Z.childMatches,X))Q=!0}else if(Z.childMatches&&Z.childMatches.length>0){if(o0(Z.oldBlock,Y,Z.childMatches,X))Q=!0}else if(C1(Z.oldBlock.element,Y,!1))Q=!0;J.appendChild(Y)}return{fragment:J,hasChanges:Q}}function a0($){let J=$.cloneNode(!0);return J.classList.add("diff-block-removed"),J.style.position="relative",q0(J,"Removed","var(--color-accent-red)"),J}function W2($){let J=$.cloneNode(!0);return J.classList.add("diff-block-added"),J.style.position="relative",q0(J,"Added","var(--color-accent-green)"),J}function o0($,J,Q,Z){let Y=!1,X=T2($,J),z,q;if(Z==="section"){let _=$.element.querySelector(":scope > div:first-child"),U=J.querySelector(":scope > div:first-child");if(_&&U){if(C1(_,U,!1))Y=!0}z=$.element.querySelector(":scope > div.mt-6, :scope > div:last-child"),q=J.querySelector(":scope > div.mt-6, :scope > div:last-child")}else z=$.element,q=J;if(!z||!q)return Y;for(let _ of Q)if(_.kind==="matched"){let U=X.newMap.get(_.newBlock.element);if(U){if(_.childMatches&&_.childMatches.length>0&&(_.newBlock.type==="table"||_.newBlock.type==="checklist")){if(s0(U,_.childMatches,_.newBlock.type))Y=!0}else if(_.childMatches&&_.childMatches.length>0){if(o0(_.oldBlock,U,_.childMatches,_.newBlock.type))Y=!0}else if(C1(_.oldBlock.element,U,!1))Y=!0}}else if(_.kind==="removed"){Y=!0;let U=a0(_.oldBlock.element),K=N2(Q,_,X.newMap);q.insertBefore(U,K)}else if(_.kind==="added"){Y=!0;let U=X.newMap.get(_.newBlock.element);if(U)U.classList.add("diff-block-added"),U.style.position="relative",q0(U,"Added","var(--color-accent-green)")}if(C1(z,q,!0))Y=!0;return Y}function s0($,J,Q){let Z=Q==="table"?$.querySelector(":scope table > tbody"):$;if(!Z)return!1;let Y=!1;Z.innerHTML="";for(let X of J)if(X.kind==="removed"){Y=!0;let z=X.oldBlock.element.cloneNode(!0);z.classList.add(Q==="table"?"diff-row-removed":"diff-item-removed"),Z.appendChild(z)}else if(X.kind==="added"){Y=!0;let z=X.newBlock.element.cloneNode(!0);z.classList.add(Q==="table"?"diff-row-added":"diff-item-added"),Z.appendChild(z)}else{let z=X.newBlock.element.cloneNode(!0);if(C1(X.oldBlock.element,z,!1))Y=!0;Z.appendChild(z)}return Y}function T2($,J){let Q=new Map,Z=$.element.querySelectorAll("[data-md]"),Y=J.querySelectorAll("[data-md]");return{newMap:{get(X){return F2(J,X)}}}}function F2($,J){let Q=J.getAttribute("data-md");if(!Q)return null;let Z=J.getAttribute("data-md-label"),Y=J.getAttribute("data-md-title"),X=`[data-md="${Q}"]`;if(Y)X+=`[data-md-title="${CSS.escape(Y)}"]`;else if(Z)X+=`[data-md-label="${CSS.escape(Z)}"]`;let z=$.querySelectorAll(X);if(z.length===1)return z[0];let q=(J.textContent||"").slice(0,100),_=null,U=-1;for(let K of z){let G=(K.textContent||"").slice(0,100),W=0;for(let T=0;T<Math.min(q.length,G.length);T++)if(q[T]===G[T])W++;if(W>U)U=W,_=K}return _}function N2($,J,Q){let Z=$.indexOf(J);for(let Y=Z+1;Y<$.length;Y++){let X=$[Y];if((X.kind==="matched"||X.kind==="added")&&X.newBlock)return Q.get(X.newBlock.element)||null}return null}function l0($,J){let Q=J?new Set(Array.from($.querySelectorAll("[data-md]"))):new Set,Z=[],Y=[],X=document.createTreeWalker($,NodeFilter.SHOW_TEXT,{acceptNode(q){let _=q.parentElement;if(!_)return NodeFilter.FILTER_REJECT;if(_.closest("svg, .select-none, [data-no-diff]"))return NodeFilter.FILTER_REJECT;if(J){for(let U of Q)if(U.contains(q))return NodeFilter.FILTER_REJECT}return NodeFilter.FILTER_ACCEPT}}),z;while(z=X.nextNode()){let _=(z.nodeValue||"").match(/\S+|\s+/g);if(!_)continue;let U=0;for(let K of _)Z.push(K),Y.push({text:K,node:z,offset:U}),U+=K.length}return{words:Z,map:Y}}function C1($,J,Q){let Z=l0($,Q),Y=l0(J,Q);if(Z.words.length===0&&Y.words.length===0)return!1;let{oldOps:X,newOps:z}=Z0(Z.words,Y.words),q=X.some((O)=>O.type==="removed"),_=z.some((O)=>O.type==="added");if(!q&&!_)return!1;let U=[],K=[];for(let O of X)if(O.type==="same")U.push(O.index);for(let O of z)if(O.type==="same")K.push(O.index);let G=new Map;for(let O=0;O<U.length&&O<K.length;O++)G.set(U[O],K[O]);let W=[];{let O=[],P=-1;for(let w of X)if(w.type==="same"){if(O.length>0)W.push({text:O.join(""),anchorNewIdx:P>=0?G.get(P)??null:null}),O=[];P=w.index}else if(w.type==="removed")O.push(Z.words[w.index]);if(O.length>0)W.push({text:O.join(""),anchorNewIdx:P>=0?G.get(P)??null:null})}let T=new Map,N=new Map;for(let O of z){if(O.type!=="added")continue;let P=Y.map[O.index];if(!P?.node.parentNode)continue;let w=T.get(P.node);if(!w)w=[],T.set(P.node,w);w.push({start:P.offset,end:P.offset+P.text.length})}for(let O of W)if(O.anchorNewIdx===null){if(Y.map.length>0){let P=Y.map[0].node,w=N.get(P);if(!w)w=[],N.set(P,w);w.push({offset:0,text:O.text})}}else{let P=Y.map[O.anchorNewIdx];if(!P)continue;let w=N.get(P.node);if(!w)w=[],N.set(P.node,w);w.push({offset:P.offset+P.text.length,text:O.text})}let S=new Set([...T.keys(),...N.keys()]);for(let O of S)L2(O,T.get(O)||[],N.get(O)||[]);return!0}function L2($,J,Q){if(!$.parentNode)return;let Z=$.nodeValue||"";J.sort((K,G)=>K.start-G.start);let Y=[];for(let K of J){let G=Y[Y.length-1];if(G&&K.start<=G.end)G.end=Math.max(G.end,K.end);else Y.push({...K})}Q.sort((K,G)=>K.offset-G.offset);let X=$.parentNode,z=document.createDocumentFragment(),q=0,_=0,U=0;while(q<=Z.length){let K=_<Y.length?Y[_].start:1/0,G=U<Q.length?Q[U].offset:1/0,W=Math.min(K,G);if(W===1/0){if(q<Z.length)z.appendChild(document.createTextNode(Z.slice(q)));break}let T=Math.max(W,q);if(T>q)z.appendChild(document.createTextNode(Z.slice(q,T))),q=T;while(U<Q.length&&Q[U].offset<=q){let N=document.createElement("span");N.className="diff-removed",N.textContent=Q[U].text,z.appendChild(N),U++}if(_<Y.length&&Y[_].start<=q){let N=Y[_],S=document.createElement("span");S.className="diff-added",S.textContent=Z.slice(q,N.end),z.appendChild(S),q=N.end,_++;while(U<Q.length&&Q[U].offset<=q){let O=document.createElement("span");O.className="diff-removed",O.textContent=Q[U].text,z.appendChild(O),U++}}}while(U<Q.length){let K=document.createElement("span");K.className="diff-removed",K.textContent=Q[U].text,z.appendChild(K),U++}X.replaceChild(z,$)}function q0($,J,Q){let Z=document.createElement("span");Z.className="diff-block-label",Z.textContent=J,Z.style.color=Q,Z.style.backgroundColor=`color-mix(in srgb, ${Q} 12%, transparent)`,$.appendChild(Z)}import{jsxDEV as k}from"react/jsx-dev-runtime";function t0({initialLeft:$,initialRight:J,sessionId:Q,onExit:Z}){let[Y,X]=l($),[z,q]=l(J),[_,U]=l("unified"),[K,G]=l(!0),[W,T]=l(!1);return k("div",{className:"flex flex-col h-screen",children:[k("div",{className:"flex items-center justify-between px-6 py-3 border-b border-border-subtle bg-bg-surface flex-shrink-0",children:[k("div",{className:"flex items-center gap-3",children:[k("span",{className:"text-[13px] font-body font-medium text-text-primary",children:"Compare"},void 0,!1,void 0,this),k(A1,{value:Y,onChange:X,accent:"red"},void 0,!1,void 0,this),k("span",{className:"text-text-tertiary text-[13px]",children:"→"},void 0,!1,void 0,this),k(A1,{value:z,onChange:q,accent:"green"},void 0,!1,void 0,this),W&&!K&&k("span",{className:"text-[11px] font-body text-text-tertiary bg-bg-elevated px-2 py-0.5 rounded",children:"No changes"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),k("div",{className:"flex items-center gap-4",children:[k("div",{className:"flex items-center bg-bg-elevated rounded-md p-0.5",children:[k("button",{onClick:()=>U("unified"),className:`text-[11px] font-body px-2.5 py-1 rounded transition-colors ${_==="unified"?"bg-bg-surface text-text-primary font-medium shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Unified"},void 0,!1,void 0,this),k("button",{onClick:()=>U("side-by-side"),className:`text-[11px] font-body px-2.5 py-1 rounded transition-colors ${_==="side-by-side"?"bg-bg-surface text-text-primary font-medium shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Side-by-side"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),_==="side-by-side"&&k(M2,{},void 0,!1,void 0,this),k("button",{onClick:Z,className:"text-[12px] font-body font-medium text-text-secondary hover:text-text-primary px-3 py-1.5 rounded-md hover:bg-bg-elevated transition-colors",children:"Exit Compare"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),_==="unified"?k(B2,{sessionId:Q,leftRev:Y,rightRev:z,onDiffResult:(N,S)=>{T(N),G(S)}},`unified-${Y}-${z}`,!1,void 0,this):k(y2,{sessionId:Q,leftRev:Y,rightRev:z,onDiffResult:(N,S)=>{T(N),G(S)}},`sbs-${Y}-${z}`,!1,void 0,this)]},void 0,!0,void 0,this)}function M2(){let[$,J]=l(!0);return W1(()=>{return document.documentElement.dataset.syncScroll=$?"1":"0",()=>{delete document.documentElement.dataset.syncScroll}},[$]),k("label",{className:"flex items-center gap-1.5 cursor-pointer select-none",children:[k("input",{type:"checkbox",checked:$,onChange:(Q)=>J(Q.target.checked),className:"accent-accent-amber w-3.5 h-3.5"},void 0,!1,void 0,this),k("span",{className:"text-[11px] font-body text-text-secondary",children:"Sync scroll"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function B2({sessionId:$,leftRev:J,rightRev:Q,onDiffResult:Z}){let Y=Z1(null),X=Z1(null),z=Z1(null),[q,_]=l(!1),[U,K]=l(!1),[G,W]=l(!1);return W1(()=>{if(!q||!U||G)return;if(!Y.current||!X.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!Y.current||!X.current||!z.current)return;let T=X0(Y.current),N=X0(X.current),S=z0(T,N),{fragment:O,hasChanges:P}=i0(S);z.current.innerHTML="",z.current.appendChild(O),W(!0),Z(!0,P)})})},[q,U,G]),k("div",{className:"flex-1 min-h-0 overflow-y-auto",children:[k("div",{style:{position:"absolute",left:-9999,visibility:"hidden",pointerEvents:"none",width:720},children:[k(p1,{ref:Y,sessionId:$,revision:J,onReady:()=>_(!0)},void 0,!1,void 0,this),k(p1,{ref:X,sessionId:$,revision:Q,onReady:()=>K(!0)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),k("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:[!G&&k("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-body",children:"Loading..."},void 0,!1,void 0,this),k("div",{ref:z},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function y2({sessionId:$,leftRev:J,rightRev:Q,onDiffResult:Z}){let Y=Z1(null),X=Z1(null),[z,q]=l(!1),[_,U]=l(!1),[K,G]=l(!1),W=Z1(null),T=Z1(null),N=Z1(!1);return W1(()=>{if(!z||!_||K)return;if(!Y.current||!X.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!Y.current||!X.current)return;let S=r0(Y.current,X.current);G(!0),Z(!0,S)})})},[z,_,K]),W1(()=>{let S=W.current,O=T.current;if(!S||!O)return;let P=(R,D)=>{if(document.documentElement.dataset.syncScroll==="0")return;if(N.current)return;N.current=!0;let m=R.scrollHeight-R.clientHeight,j=D.scrollHeight-D.clientHeight;if(m>0&&j>0)D.scrollTop=R.scrollTop/m*j;requestAnimationFrame(()=>{N.current=!1})},w=()=>P(S,O),B=()=>P(O,S);return S.addEventListener("scroll",w),O.addEventListener("scroll",B),()=>{S.removeEventListener("scroll",w),O.removeEventListener("scroll",B)}},[]),k("div",{className:"flex flex-1 min-h-0",children:[k("div",{ref:W,className:"w-1/2 overflow-y-auto border-r border-border-subtle",children:k("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:k(p1,{ref:Y,sessionId:$,revision:J,onReady:()=>q(!0)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),k("div",{ref:T,className:"w-1/2 overflow-y-auto",children:k("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:k(p1,{ref:X,sessionId:$,revision:Q,onReady:()=>U(!0)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var p1=O2.forwardRef(({sessionId:$,revision:J,onReady:Q},Z)=>{let[Y,X]=l(null),[z,q]=l(null),[_,U]=l(!0);if(W1(()=>{U(!0),q(null),import(`/api/session/${$}/plan.js?rev=${J}&t=${Date.now()}`).then((K)=>{X(()=>K.default),U(!1)}).catch((K)=>{q(K.message),U(!1)})},[$,J]),W1(()=>{if(!Y)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{Q()})})},[Y]),_)return k("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-body",children:"Loading..."},void 0,!1,void 0,this);if(z)return k("div",{className:"bg-accent-red-muted rounded-lg p-5",children:[k("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Error"},void 0,!1,void 0,this),k("pre",{className:"text-code font-mono text-text-secondary whitespace-pre-wrap",children:z},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(!Y)return k("div",{className:"text-text-tertiary text-center py-8 font-body text-body",children:"No plan loaded"},void 0,!1,void 0,this);return k("div",{ref:Z,children:k(Y,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)});import{jsxDEV as F,Fragment as _0}from"react/jsx-dev-runtime";var G1=e0({activeView:{type:"plan"},setActiveView:()=>{},openFiles:[],closeFile:()=>{}}),H1=e0({currentRevision:1,selectedRevision:1,revisions:[],setSelectedRevision:()=>{},isReadOnly:!1,compareRevision:null,setCompareRevision:()=>{}});function J5(){let[$,J]=i(()=>localStorage.getItem("canvas-theme")||document.documentElement.dataset.theme||"dark");return F("button",{onClick:()=>{let Z=$==="dark"?"light":"dark";document.documentElement.dataset.theme=Z,localStorage.setItem("canvas-theme",Z),J(Z)},className:"w-7 h-7 flex items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:$==="dark"?"Switch to light theme":"Switch to dark theme",children:$==="dark"?F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[F("circle",{cx:"12",cy:"12",r:"5"},void 0,!1,void 0,this),F("line",{x1:"12",y1:"1",x2:"12",y2:"3"},void 0,!1,void 0,this),F("line",{x1:"12",y1:"21",x2:"12",y2:"23"},void 0,!1,void 0,this),F("line",{x1:"4.22",y1:"4.22",x2:"5.64",y2:"5.64"},void 0,!1,void 0,this),F("line",{x1:"18.36",y1:"18.36",x2:"19.78",y2:"19.78"},void 0,!1,void 0,this),F("line",{x1:"1",y1:"12",x2:"3",y2:"12"},void 0,!1,void 0,this),F("line",{x1:"21",y1:"12",x2:"23",y2:"12"},void 0,!1,void 0,this),F("line",{x1:"4.22",y1:"19.78",x2:"5.64",y2:"18.36"},void 0,!1,void 0,this),F("line",{x1:"18.36",y1:"5.64",x2:"19.78",y2:"4.22"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:F("path",{d:"M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function Q5(){let{currentRevision:$,selectedRevision:J,revisions:Q,setSelectedRevision:Z,setCompareRevision:Y}=U1.useContext(H1);if(Q.length<=1){let q=Q[0]?.label||`Round ${$}`;return F("span",{className:"text-[11px] text-text-tertiary font-body",children:q},void 0,!1,void 0,this)}return F("div",{className:"flex items-center gap-1.5",children:[F(A1,{value:J,onChange:Z,accent:J===$?"default":"amber"},void 0,!1,void 0,this),F("button",{onClick:()=>{let q=Q.find((U)=>U.revision===J)?.sourceFile,_;if(J===$)_=[...Q].reverse().find((K)=>K.revision<$&&(!q||K.sourceFile===q))?.revision??Math.max(1,$-1);else _=J;Y({left:_,right:$})},className:"text-[11px] font-body font-medium px-2 py-0.5 rounded-md text-accent-blue hover:bg-accent-blue-muted transition-colors",children:"Compare"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function w2(){let $=window.location.pathname.replace("/s/","")||"",[J,Q]=i(1),[Z,Y]=i(1),[X,z]=i([]),[q,_]=i(null),[U,K]=i(!1),[G,W]=i(!1),[T,N]=i({type:"plan"}),[S,O]=i([]),P=T1(null),[w,B]=i(),[R,D]=i(!1),[m,j]=i(!1),[C,I]=i(!1);c1(()=>{let M=["Agent Canvas"];if(w){let L=w.replace(/\/+$/,"").split("/");M.push(L[L.length-1]||$)}else if($)M.push($);if(T.type==="file")M.push(T.path.split("/").pop()||T.path);else if(q)M.push("Compare");document.title=M.join(" — ")},[$,w,T,q]);let H=T1(new Map),y=X.find((M)=>M.revision===Z),E=Z!==J||!!y?.hasFeedback,c=d1((M)=>{if(H.current.set(T.type==="plan"?"plan":`file:${T.path}`,window.scrollY),N(M),M.type==="file")O((L)=>L.includes(M.path)?L:[...L,M.path])},[T]),$1=d1((M)=>{H.current.delete(`file:${M}`),O((L)=>L.filter((A)=>A!==M)),N((L)=>{if(L.type==="file"&&L.path===M)return H.current.set(`file:${M}`,window.scrollY),{type:"plan"};return L})},[]);P2(()=>{let M=T.type==="plan"?"plan":`file:${T.path}`;window.scrollTo(0,H.current.get(M)||0)},[T]),c1(()=>{if(!$)return;fetch(`/api/session/${$}/meta`).then((M)=>M.json()).then((M)=>{if(M.currentRevision)Q(M.currentRevision),Y(M.currentRevision),z(M.revisions||[]);if(M.projectRoot)B(M.projectRoot)}).catch(()=>{})},[$]),c1(()=>{if(!$)return;let M=null,L=()=>{let A=window.location.protocol==="https:"?"wss:":"ws:",u=new WebSocket(`${A}//${window.location.host}/ws/session/${$}`);P.current=u,u.onopen=()=>K(!0),u.onclose=()=>{K(!1),M=setTimeout(L,2000)},u.onmessage=(h)=>{try{let b=JSON.parse(h.data);if(b.type==="plan-updated"){if(Q(b.currentRevision),Y(b.currentRevision),_(null),b.revisions)z(b.revisions)}if(b.type==="revision-updated"){if(b.revisions)z(b.revisions)}}catch{}}};return L(),()=>{if(M)clearTimeout(M);P.current?.close()}},[$]);let Q1=d1((M)=>{if(P.current?.readyState===WebSocket.OPEN)P.current.send(JSON.stringify({type:"submit",feedback:M})),W(!1)},[]);if(!$)return F("div",{className:"flex items-center justify-center h-screen text-text-tertiary font-body",children:"No session selected."},void 0,!1,void 0,this);return F($5.Provider,{value:$,children:F(H1.Provider,{value:{currentRevision:J,selectedRevision:Z,revisions:X,setSelectedRevision:Y,isReadOnly:E,compareRevision:q,setCompareRevision:_},children:F(G0,{sessionId:$,revision:Z,isReadOnly:E,children:F(G1.Provider,{value:{activeView:T,setActiveView:c,openFiles:S,closeFile:$1},children:F(A2.Provider,{value:{setActiveView:c},children:F("div",{className:"min-h-screen bg-bg-base",children:[F(C2,{sessionId:$,projectRoot:w,connected:U,onMobileSidebar:()=>D(!R),collapsed:m,onToggle:()=>j((M)=>!M)},void 0,!1,void 0,this),q===null&&F(I2,{collapsed:C,onToggle:()=>I((M)=>!M),children:F(J0,{onPreview:()=>W(!0),onSubmit:Q1},void 0,!1,void 0,this)},void 0,!1,void 0,this),q!==null?F("div",{className:`${m?"lg:ml-0":"lg:ml-60"} transition-[margin] duration-200`,children:F(t0,{initialLeft:q.left,initialRight:q.right,sessionId:$,onExit:()=>_(null)},void 0,!1,void 0,this)},void 0,!1,void 0,this):F("div",{className:`relative ${m?"lg:ml-0":"lg:ml-60"} ${C?"lg:mr-0":"lg:mr-[var(--sidebar-width,320px)]"} transition-[margin] duration-200`,id:"plan-scroll-container",children:[F("div",{className:"lg:hidden sticky top-0 z-20 flex items-center justify-between px-4 py-2 border-b border-border-subtle bg-bg-surface",children:[F("div",{className:"flex items-center gap-2",children:[F(Y0,{currentSessionId:$,projectRoot:w},void 0,!1,void 0,this),F("span",{className:`w-1.5 h-1.5 rounded-full ${U?"bg-accent-green":"bg-accent-red"}`},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F("div",{className:"flex items-center gap-1",children:[F(Q5,{},void 0,!1,void 0,this),F("button",{onClick:()=>D(!R),className:"w-7 h-7 flex items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:"Annotations",children:F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:F("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),F(J5,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),F(R2,{},void 0,!1,void 0,this),F("div",{style:{display:T.type==="plan"?void 0:"none"},children:F("div",{className:"relative max-w-[720px] mx-auto px-6 pt-12 pb-32",children:[F("button",{onClick:()=>{let M=document.querySelector(".plan-content");if(!M)return;let L=E0(M);navigator.clipboard.writeText(L).then(()=>{let A=document.getElementById("export-md-btn");if(A)A.setAttribute("data-copied","true"),setTimeout(()=>{A.removeAttribute("data-copied")},1500)})},id:"export-md-btn",className:"group absolute top-3 right-6 p-1.5 text-text-tertiary hover:text-text-secondary transition-colors z-10",title:"Copy as Markdown",children:[F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"group-[[data-copied=true]]:hidden",children:[F("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"},void 0,!1,void 0,this),F("path",{d:"M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"hidden group-[[data-copied=true]]:block text-green-500",children:F("polyline",{points:"20 6 9 17 4 12"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F(P0,{revision:Z},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),S.map((M)=>F("div",{style:{display:T.type==="file"&&T.path===M?void 0:"none"},children:F(f0,{path:M},void 0,!1,void 0,this)},M,!1,void 0,this))]},void 0,!0,void 0,this),R&&F("div",{className:"lg:hidden fixed inset-0 z-40 flex",children:[F("div",{className:"flex-1",onClick:()=>D(!1)},void 0,!1,void 0,this),F("div",{className:"w-80 max-w-[85vw] bg-bg-surface border-l border-border-subtle flex flex-col shadow-lg",children:[F("div",{className:"flex items-center justify-between px-4 py-2 border-b border-border-subtle flex-shrink-0",children:[F("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:"Sidebar"},void 0,!1,void 0,this),F("button",{onClick:()=>D(!1),className:"text-text-tertiary hover:text-text-secondary w-7 h-7 flex items-center justify-center",children:"✕"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F("div",{className:"flex-1 overflow-hidden",children:F(J0,{onPreview:()=>W(!0),onSubmit:Q1},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),F(I0,{open:G,onClose:()=>W(!1),onSubmit:Q1},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},`${$}:${Z}`,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function C2({sessionId:$,projectRoot:J,connected:Q,onMobileSidebar:Z,collapsed:Y,onToggle:X}){return F(_0,{children:[Y&&F("button",{onClick:X,className:"hidden lg:flex fixed top-3 left-3 z-20 w-7 h-7 items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors bg-bg-surface border border-border-subtle",title:"Show sidebar",children:F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[F("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"},void 0,!1,void 0,this),F("line",{x1:"9",y1:"3",x2:"9",y2:"21"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),F("div",{className:`hidden lg:flex w-60 flex-col fixed top-0 left-0 bottom-0 bg-bg-surface border-r border-border-subtle z-10 transition-transform duration-200 ${Y?"-translate-x-full":""}`,children:[F("div",{className:"px-4 pt-4 pb-3 flex-shrink-0 border-b border-border-subtle",children:[F("div",{className:"flex items-center gap-2 mb-2",children:[F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",className:"text-text-tertiary flex-shrink-0",children:F("path",{d:"M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this),F(Y0,{currentSessionId:$,projectRoot:J},void 0,!1,void 0,this),F("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${Q?"bg-accent-green":"bg-accent-red"}`},void 0,!1,void 0,this),F("button",{onClick:X,className:"ml-auto w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:"Hide sidebar",children:F("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[F("polyline",{points:"11 17 6 12 11 7"},void 0,!1,void 0,this),F("polyline",{points:"18 17 13 12 18 7"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F(Q5,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F("div",{className:"flex-1 flex flex-col overflow-hidden",children:F(g0,{embedded:!0},void 0,!1,void 0,this)},void 0,!1,void 0,this),F("div",{className:"px-4 py-3 border-t border-border-subtle flex items-center justify-between flex-shrink-0",children:[F("span",{className:"text-[10px] text-text-tertiary font-body uppercase tracking-widest",children:"Theme"},void 0,!1,void 0,this),F(J5,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function I2({children:$,collapsed:J,onToggle:Q}){let[Z,Y]=i(()=>{let K=localStorage.getItem("canvas-sidebar-width");return K?parseInt(K,10):320}),X=T1(!1),z=T1(0),q=T1(0),_=T1(Z);_.current=Z;let U=d1((K)=>{K.preventDefault(),X.current=!0,z.current=K.clientX,q.current=_.current;let G=(T)=>{if(!X.current)return;let N=z.current-T.clientX,S=Math.max(240,Math.min(600,q.current+N));Y(S),_.current=S},W=()=>{X.current=!1,localStorage.setItem("canvas-sidebar-width",String(_.current)),document.removeEventListener("mousemove",G),document.removeEventListener("mouseup",W),document.body.style.cursor="",document.body.style.userSelect=""};document.addEventListener("mousemove",G),document.addEventListener("mouseup",W),document.body.style.cursor="col-resize",document.body.style.userSelect="none"},[]);return c1(()=>{return document.documentElement.style.setProperty("--sidebar-width",`${Z}px`),()=>{document.documentElement.style.removeProperty("--sidebar-width")}},[Z]),F(_0,{children:[J&&F("button",{onClick:Q,className:"hidden lg:flex fixed top-3 right-3 z-20 w-7 h-7 items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors bg-bg-surface border border-border-subtle",title:"Show annotations",children:F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:F("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),F("div",{className:`hidden lg:flex flex-col fixed top-0 right-0 bottom-0 bg-bg-surface border-l border-border-subtle z-10 transition-transform duration-200 ${J?"translate-x-full":""}`,style:{width:Z},children:[F("div",{onMouseDown:U,className:"absolute left-0 top-0 bottom-0 w-1 cursor-col-resize hover:bg-accent-blue/30 transition-colors z-20",style:{marginLeft:"-2px"}},void 0,!1,void 0,this),U1.Children.map($,(K)=>U1.isValidElement(K)?U1.cloneElement(K,{collapseButton:F("button",{onClick:Q,className:"w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:"Hide annotations",children:F("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[F("polyline",{points:"13 17 18 12 13 7"},void 0,!1,void 0,this),F("polyline",{points:"6 17 11 12 6 7"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}):K)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function R2(){let{activeView:$,setActiveView:J,openFiles:Q,closeFile:Z}=U1.useContext(G1),Y=U1.useContext($5),{addAnnotationWithId:X,setActiveAnnotationId:z}=o(),q=Q.length>0;if(!q)return null;return F("div",{className:"flex items-center border-b border-border-medium bg-bg-surface overflow-x-auto sticky top-0 z-10",children:[q&&F("button",{onClick:()=>J({type:"plan"}),className:`flex items-center gap-1.5 px-4 py-2.5 text-[13px] font-body whitespace-nowrap transition-colors relative ${$.type==="plan"?"text-text-primary":"text-text-tertiary hover:text-text-secondary"}`,children:[F("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",className:"opacity-60",children:F("path",{d:"M12 2L2 7l10 5 10-5-10-5z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this),"Plan",$.type==="plan"&&F("span",{className:"absolute bottom-0 left-3 right-3 h-[2px] bg-text-primary rounded-full"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),q&&F(_0,{children:[F("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this),Q.map((_,U)=>{let K=_.split("/").pop()||_,G=$.type==="file"&&$.path===_;return F(U1.Fragment,{children:[F("div",{className:"flex items-center",children:[F("button",{onClick:()=>J({type:"file",path:_}),className:`flex items-center gap-1.5 pl-3 pr-1 py-2.5 text-[13px] font-mono whitespace-nowrap transition-colors relative ${G?"text-text-primary":"text-text-tertiary hover:text-text-secondary"}`,children:[K,G&&F("span",{className:"absolute bottom-0 left-3 right-1 h-[2px] bg-text-primary rounded-full"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F("button",{onClick:(W)=>{W.stopPropagation(),Z(_)},className:"text-text-tertiary hover:text-text-secondary px-1.5 py-1 text-[10px] transition-colors rounded hover:bg-bg-input",children:"✕"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),U<Q.length-1&&F("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this)]},_,!0,void 0,this)})]},void 0,!0,void 0,this),F("div",{className:"ml-auto flex items-center gap-1 flex-shrink-0",children:$.type==="file"&&F("button",{onClick:async()=>{let _=$.path;try{let K=await(await fetch(`/api/file?session=${Y}&path=${encodeURIComponent(_)}`)).json();if(!K.error){let G=K.content.split(`
|
|
107
|
+
`}var r3=new Set(["CODE","SPAN","STRONG","EM","A","B","I","U","SMALL","SUB","SUP","MARK","ABBR"]);function A0(J,$,Q){if(l3(J)){let Z=a3(J);if(Z)$.push(Z,"");return}for(let Z of J.childNodes)if(Z.nodeType===Node.ELEMENT_NODE)i3(Z,$,Q);else if(Z.nodeType===Node.TEXT_NODE){let Y=Z.textContent?.trim();if(Y)$.push(Y,"")}}function l3(J){for(let $ of J.childNodes){if($.nodeType===Node.TEXT_NODE)continue;if($.nodeType===Node.ELEMENT_NODE){let Q=$;if(!r3.has(Q.tagName)||Q.hasAttribute("data-md"))return!1}}return J.childNodes.length>0}function a3(J){let $="";for(let Q of J.childNodes)if(Q.nodeType===Node.TEXT_NODE)$+=Q.textContent||"";else if(Q.nodeType===Node.ELEMENT_NODE){let Z=Q;if(Z.tagName==="CODE")$+="`"+(Z.textContent||"")+"`";else $+=Z.textContent||""}return $.trim()}function i3(J,$,Q){let Z=J.getAttribute("data-md");if(Z)switch(Z){case"section":return o3(J,$,Q);case"item":return s3(J,$);case"codeblock":return t3(J,$);case"callout":return n3(J,$);case"note":return e3(J,$);case"table":return $$(J,$);case"checklist":return J$(J,$);case"diff":return Y$(J,$);case"mermaid":return Q$(J,$);case"choice":return Z$(J,$);case"multichoice":return q$(J,$);case"choice-option":case"multichoice-option":return;case"userinput":return X$(J,$);case"rangeinput":return z$(J,$);case"checklist-item":return;case"filepreview":return _$(J,$);case"priority":return K$(J,$)}if(J.querySelector("button, input, select, textarea"))return;if(J.children.length>0)A0(J,$,Q);else{let Y=J.textContent?.trim();if(Y)$.push(Y,"")}}function o3(J,$,Q){let Z=J.getAttribute("data-md-title")||"Untitled",Y=Q===0?"##":"###";$.push(`${Y} ${Z}`,"");let X=J.querySelector(":scope > div:last-of-type");if(X)A0(X,$,Q+1)}function s3(J,$){let Q=J.getAttribute("data-md-label")||"",Z=J.getAttribute("data-md-status"),Y=J.getAttribute("data-md-badge"),X="-";if(Z==="done")X="- [x]";else if(Z)X="- [ ]";let q=`${X} **${Q}**`;if(Y)q+=` \`${Y}\``;$.push(q);let _=J.querySelector(".text-text-secondary");if(_){let z=[];A0(_,z,0);for(let K of z)$.push(K?` ${K}`:"")}$.push("")}function t3(J,$){let Q=J.getAttribute("data-md-language")||"",Y=J.querySelector("code")?.textContent||"";$.push(`\`\`\`${Q}`,Y,"```","")}function n3(J,$){let Q=J.getAttribute("data-md-type")||"info",Z={info:"Info",warning:"Warning",danger:"Danger",tip:"Tip"},Y=U$(J.querySelector(".text-text-secondary")||J);$.push(`> **${Z[Q]||Q}:** ${Y}`,"")}function e3(J,$){let Q=J.textContent?.trim()||"";$.push(`> *${Q}*`,"")}function $$(J,$){let Q=J.querySelector("table");if(!Q)return;let Z=[];for(let Y of Q.querySelectorAll("thead th"))Z.push(Y.textContent?.trim()||"");if(Z.length===0)return;$.push(`| ${Z.join(" | ")} |`),$.push(`| ${Z.map(()=>"---").join(" | ")} |`);for(let Y of Q.querySelectorAll("tbody tr")){let X=[];for(let q of Y.querySelectorAll("td"))X.push(q.textContent?.trim()||"");$.push(`| ${X.join(" | ")} |`)}$.push("")}function J$(J,$){for(let Q of J.querySelectorAll("li")){let Z=Q.querySelector(".bg-accent-green")!==null,Y=Q.textContent?.trim()||"";$.push(`- [${Z?"x":" "}] ${Y}`)}$.push("")}function Y$(J,$){let Q=J.getAttribute("data-md-language")||"";$.push(`\`\`\`diff${Q?` (${Q})`:""}`);for(let Z of J.querySelectorAll("[class*='flex']")){let Y=Z.querySelector(".text-accent-red")?"-":Z.querySelector(".text-accent-green")?"+":" ",X=Z.querySelector("code");if(X)$.push(`${Y} ${X.textContent}`)}$.push("```","")}function Q$(J,$){let Q=J.getAttribute("data-md-source")||"";if(Q)$.push("```mermaid",Q,"```","")}function Z$(J,$){let Q=J.getAttribute("data-md-label")||"";$.push(`**${Q}:**`);for(let Z of J.querySelectorAll("[data-md='choice-option']")){let Y=Z.getAttribute("data-md-label")||Z.textContent?.trim()||"",X=Z.querySelector(".bg-accent-amber")!==null;$.push(`- ${X?"(x)":"( )"} ${Y}`)}$.push("")}function q$(J,$){let Q=J.getAttribute("data-md-label")||"";$.push(`**${Q}:**`);for(let Z of J.querySelectorAll("[data-md='multichoice-option']")){let Y=Z.getAttribute("data-md-label")||Z.textContent?.trim()||"",X=Z.querySelector(".bg-accent-amber")!==null;$.push(`- [${X?"x":" "}] ${Y}`)}$.push("")}function X$(J,$){let Q=J.getAttribute("data-md-label")||"",Y=J.querySelector("textarea")?.value?.trim()||"";$.push(`**${Q}:** ${Y||"_empty_"}`,"")}function z$(J,$){let Q=J.getAttribute("data-md-label")||"",Z=J.querySelector("input[type='range']"),X=J.querySelector(".font-mono")?.textContent?.trim()||Z?.value||"—";$.push(`**${Q}:** ${X}`,"")}function _$(J,$){let Q=J.getAttribute("data-md-path")||"",Z=J.getAttribute("data-md-lines")||"",X=J.querySelector("code")?.textContent||"",q=Q.split(".").pop()||"",_=b0[q]||"",z=Z?`${Q} (L${Z})`:Q;$.push(z,"",`\`\`\`${_}`,X,"```","")}function K$(J,$){}function U$(J){return J?.textContent?.trim()||""}import A$,{useEffect as c1,useState as Y1,useRef as L1}from"react";import{useEffect as G$,useState as H$,useRef as N$,useContext as W$}from"react";import{jsxDEV as z1,Fragment as e5}from"react/jsx-dev-runtime";function T$(J){return J.label||`Round ${J.revision}`}function O$(J){let $=Date.now()-new Date(J).getTime(),Q=Math.floor($/1000);if(Q<60)return"just now";let Z=Math.floor(Q/60);if(Z<60)return`${Z}m ago`;let Y=Math.floor(Z/60);if(Y<24)return`${Y}h ago`;return`${Math.floor(Y/24)}d ago`}function Z0({value:J,onChange:$,accent:Q="default",className:Z}){let{currentRevision:Y,revisions:X}=W$(h1),[q,_]=H$(!1),z=N$(null);G$(()=>{if(!q)return;let H=(G)=>{if(z.current&&!z.current.contains(G.target))_(!1)};return document.addEventListener("mousedown",H),()=>document.removeEventListener("mousedown",H)},[q]);let K=X.find((H)=>H.revision===J);return z1("div",{className:"relative",ref:z,children:[z1("button",{onClick:()=>_(!q),className:`flex items-center gap-1.5 text-[12px] font-body font-medium px-2 py-1 rounded-md transition-colors hover:bg-bg-elevated ${{default:"text-text-secondary hover:text-text-primary",red:"text-accent-red",green:"text-accent-green",amber:"text-accent-amber bg-highlight-selected"}[Q]} ${Z||""}`,children:[K?T$(K):`Round ${J}`,z1("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",className:`text-text-tertiary transition-transform duration-200 ${q?"rotate-180":""}`,children:z1("path",{d:"M2.5 4l2.5 2.5L7.5 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),q&&z1("div",{className:"absolute top-full left-0 mt-1 w-64 bg-bg-elevated border border-border-hover rounded-lg shadow-lg z-50 py-1 max-h-80 overflow-y-auto",children:[...X].reverse().map((H)=>z1("button",{onClick:()=>{$(H.revision),_(!1)},className:`w-full flex items-center gap-2 px-3 py-2 text-[12px] font-body transition-colors ${H.revision===J?"bg-bg-surface text-text-primary":"text-text-secondary hover:bg-bg-surface hover:text-text-primary"}`,children:[z1("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${H.revision===Y?"bg-accent-green":H.hasFeedback?"bg-accent-amber":"bg-border-hover"}`},void 0,!1,void 0,this),z1("span",{className:"flex-1 text-left truncate",children:H.label?z1(e5,{children:[H.label," ",z1("span",{className:"text-text-tertiary",children:["#",H.revision]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):z1(e5,{children:["Round ",H.revision]},void 0,!0,void 0,this)},void 0,!1,void 0,this),z1("span",{className:"text-[10px] text-text-tertiary flex-shrink-0",children:H.revision===Y?"current":H.hasFeedback?"sent":O$(H.createdAt)},void 0,!1,void 0,this)]},H.revision,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function B1(J,$){let Q=J.length,Z=$.length;if(Q===0||Z===0)return[];let Y=Array.from({length:Q+1},()=>Array(Z+1).fill(0));for(let z=1;z<=Q;z++)for(let K=1;K<=Z;K++)Y[z][K]=J[z-1]===$[K-1]?Y[z-1][K-1]+1:Math.max(Y[z-1][K],Y[z][K-1]);let X=[],q=Q,_=Z;while(q>0&&_>0)if(J[q-1]===$[_-1])X.unshift(J[q-1]),q--,_--;else if(Y[q-1][_]>Y[q][_-1])q--;else _--;return X}function $2(J){let $=[],Q=[],Z=document.createTreeWalker(J,NodeFilter.SHOW_TEXT,{acceptNode(X){let q=X.parentElement;if(!q)return NodeFilter.FILTER_REJECT;if(q.closest("svg, .select-none, [data-no-diff]"))return NodeFilter.FILTER_REJECT;return NodeFilter.FILTER_ACCEPT}}),Y;while(Y=Z.nextNode()){let q=(Y.nodeValue||"").match(/\S+|\s+/g);if(!q)continue;let _=0;for(let z of q)$.push(z),Q.push({text:z,node:Y,offset:_}),_+=z.length}return{words:$,map:Q}}function e0(J,$){if(J.length>5000||$.length>5000)return F$(J,$);return Q2(J,$)}function Q2(J,$){let Q=w0(J,$),Z=[],Y=[],X=0,q=0,_=0;while(X<J.length||q<$.length)if(_<Q.length&&X<J.length&&q<$.length&&J[X]===Q[_]&&$[q]===Q[_])Z.push({type:"same",index:X}),Y.push({type:"same",index:q}),X++,q++,_++;else if(X<J.length&&(_>=Q.length||J[X]!==Q[_]))Z.push({type:"removed",index:X}),X++;else if(q<$.length)Y.push({type:"added",index:q}),q++;return{oldOps:Z,newOps:Y}}function w0(J,$){let Q=J.length,Z=$.length;if(Q===0||Z===0)return[];if(Q===1)return $.includes(J[0])?[J[0]]:[];if(Z===1)return J.includes($[0])?[$[0]]:[];if(Q*Z<=1e6)return B1(J,$);let Y=Math.floor(Q/2),X=J.slice(0,Y),q=J.slice(Y),_=J2(X,$),z=J2([...q].reverse(),[...$].reverse()),K=0,U=0;for(let N=0;N<=Z;N++){let W=_[N]+z[Z-N];if(W>K)K=W,U=N}let H=$.slice(0,U),G=$.slice(U);return[...w0(X,H),...w0(q,G)]}function J2(J,$){let Q=$.length,Z=Array(Q+1).fill(0),Y=Array(Q+1).fill(0);for(let X=0;X<J.length;X++){for(let q=1;q<=Q;q++)Y[q]=J[X]===$[q-1]?Z[q-1]+1:Math.max(Z[q],Y[q-1]);[Z,Y]=[Y,Z],Y.fill(0)}return Z}function F$(J,$){let Z=(W)=>{let M=[];for(let F=0;F<W.length;F+=200){let L=Math.min(F+200,W.length);M.push({start:F,end:L,text:W.slice(F,L).join("")})}return M},Y=Z(J),X=Z($),q=Y.map((W)=>W.text),_=X.map((W)=>W.text),z=w0(q,_),K=[],U=[],H=0,G=0,N=0;while(H<Y.length||G<X.length)if(N<z.length&&H<Y.length&&G<X.length&&q[H]===z[N]&&_[G]===z[N]){for(let W=Y[H].start;W<Y[H].end;W++)K.push({type:"same",index:W});for(let W=X[G].start;W<X[G].end;W++)U.push({type:"same",index:W});H++,G++,N++}else if(H<Y.length&&(N>=z.length||q[H]!==z[N]))if(G<X.length&&(N>=z.length||_[G]!==z[N])){let W=Q2(J.slice(Y[H].start,Y[H].end),$.slice(X[G].start,X[G].end));for(let M of W.oldOps)K.push({type:M.type,index:M.index+Y[H].start});for(let M of W.newOps)U.push({type:M.type,index:M.index+X[G].start});H++,G++}else{for(let W=Y[H].start;W<Y[H].end;W++)K.push({type:"removed",index:W});H++}else if(G<X.length){for(let W=X[G].start;W<X[G].end;W++)U.push({type:"added",index:W});G++}return{oldOps:K,newOps:U}}function Y2(J,$,Q){let Z=new Map;for(let Y of J){if(Y.type==="same")continue;let X=$[Y.index];if(!X||!X.node.parentNode)continue;let q=Z.get(X.node);if(!q)q=[],Z.set(X.node,q);q.push({offset:X.offset,length:X.text.length})}for(let[Y,X]of Z){if(!Y.parentNode)continue;let q=Y.nodeValue||"";X.sort((H,G)=>H.offset-G.offset);let _=[];for(let H of X){let G=_[_.length-1];if(G&&H.offset<=G.offset+G.length)G.length=Math.max(G.length,H.offset+H.length-G.offset);else _.push({...H})}let z=Y.parentNode,K=document.createDocumentFragment(),U=0;for(let H of _){if(H.offset>U)K.appendChild(document.createTextNode(q.slice(U,H.offset)));let G=document.createElement("span");G.className=Q,G.textContent=q.slice(H.offset,H.offset+H.length),K.appendChild(G),U=H.offset+H.length}if(U<q.length)K.appendChild(document.createTextNode(q.slice(U)));z.replaceChild(K,Y)}}function Z2(J,$){let Q=y$(J,$),Z=$2(J),Y=$2($),{oldOps:X,newOps:q}=e0(Z.words,Y.words),_=X.some((z)=>z.type==="removed")||q.some((z)=>z.type==="added");return Y2(X,Z.map,"diff-removed"),Y2(q,Y.map,"diff-added"),_||Q}function y$(J,$){let Q=Array.from(J.querySelectorAll('[data-md="mermaid"]')),Z=Array.from($.querySelectorAll('[data-md="mermaid"]')),Y=!1,X=Math.max(Q.length,Z.length);for(let q=0;q<X;q++){let _=Q[q],z=Z[q];if(!_&&z){z.classList.add("diff-block-added"),z.style.position="relative",Y=!0;continue}if(_&&!z){_.classList.add("diff-block-removed"),_.style.position="relative",Y=!0;continue}if(!_||!z)continue;let K=(_.getAttribute("data-md-source")||"").trim(),U=(z.getAttribute("data-md-source")||"").trim();if(K===U)continue;Y=!0,_.style.borderLeft="3px solid var(--color-accent-red)",_.style.paddingLeft="8px",z.style.borderLeft="3px solid var(--color-accent-green)",z.style.paddingLeft="8px";let H=K.split(`
|
|
108
|
+
`),G=U.split(`
|
|
109
|
+
`),N=B1(H,G),W=(M,F,L)=>{let y=document.createElement("div");y.className="mt-2 bg-bg-code rounded-md overflow-hidden text-tiny font-mono",y.setAttribute("data-no-diff","true");let S=0,R=0;while(R<M.length){let m=document.createElement("div");if(m.className="px-3 py-0.5 whitespace-pre-wrap",S<F.length&&M[R]===F[S])m.textContent=" "+M[R],R++,S++;else m.classList.add(L==="old"?"diff-removed":"diff-added"),m.textContent=(L==="old"?"- ":"+ ")+M[R],R++;y.appendChild(m)}return y};_.appendChild(W(H,N,"old")),z.appendChild(W(G,N,"new"))}return Y}function $5(J){let $=[],Q=J.querySelectorAll(":scope > [data-md]");for(let Z of Q)$.push(q0(Z));if($.length===0){let Z=J.querySelectorAll("[data-md]"),Y=new Set;for(let X of Z){let q=X.parentElement?.closest("[data-md]");if(q&&J.contains(q))continue;if(Y.has(X))continue;Y.add(X),$.push(q0(X))}}return $}function q0(J){let $=J.getAttribute("data-md")||"unknown",Q=M$(J,$),Z=[];if($==="section"){let Y=J.querySelector(":scope > div.mt-6, :scope > div:last-child");if(Y)for(let X of Y.querySelectorAll(":scope > [data-md]"))Z.push(q0(X))}else if($==="table")for(let Y of J.querySelectorAll(":scope table > tbody > tr"))Z.push({key:"tr:"+(Y.textContent||"").slice(0,80),type:"tr",element:Y,children:[]});else if($==="checklist")for(let Y of J.querySelectorAll(":scope > [data-md='checklist-item']"))Z.push(q0(Y));else for(let Y of J.querySelectorAll("[data-md]"))if(Y.parentElement?.closest("[data-md]")===J)Z.push(q0(Y));return{key:Q,type:$,element:J,children:Z}}function M$(J,$){switch($){case"section":return"section:"+(J.getAttribute("data-md-title")||"");case"item":return"item:"+(J.getAttribute("data-task-id")||J.getAttribute("data-md-label")||"");case"codeblock":case"diff":return $+":"+(J.textContent||"").slice(0,80);case"checklist-item":return"checklist-item:"+(J.getAttribute("data-md-label")||J.textContent?.slice(0,60)||"");case"checklist":return"checklist:"+J.querySelectorAll("[data-md='checklist-item']").length;case"markdown":return"markdown:"+(J.getAttribute("data-md-file")||"inline");case"mermaid":return"mermaid:"+(J.getAttribute("data-md-source")||"").slice(0,80);case"callout":return"callout:"+(J.getAttribute("data-md-type")||"")+":"+(J.textContent||"").slice(0,60);default:return $+":"+(J.getAttribute("data-md-label")||J.textContent?.slice(0,60)||"")}}function J5(J,$){let Q=J.map((K)=>K.key),Z=$.map((K)=>K.key),Y=B1(Q,Z),X=[],q=0,_=0,z=0;while(q<J.length||_<$.length)if(z<Y.length&&q<J.length&&_<$.length&&Q[q]===Y[z]&&Z[_]===Y[z]){let K=J[q],U=$[_],H=K.children.length>0||U.children.length>0?J5(K.children,U.children):void 0;X.push({kind:"matched",oldBlock:K,newBlock:U,childMatches:H}),q++,_++,z++}else if(q<J.length&&(z>=Y.length||Q[q]!==Y[z]))X.push({kind:"removed",oldBlock:J[q]}),q++;else if(_<$.length)X.push({kind:"added",newBlock:$[_]}),_++;return X}function X2(J){let $=document.createDocumentFragment(),Q=!1;for(let Z of J)if(Z.kind==="removed")Q=!0,$.appendChild(z2(Z.oldBlock.element));else if(Z.kind==="added")Q=!0,$.appendChild(B$(Z.newBlock.element));else{let Y=Z.newBlock.element.cloneNode(!0),X=Z.newBlock.type;if(X==="mermaid"){if(G2(Z.oldBlock.element,Y))Q=!0}else if(Z.childMatches&&Z.childMatches.length>0&&(X==="table"||X==="checklist")){if(K2(Y,Z.childMatches,X))Q=!0}else if(Z.childMatches&&Z.childMatches.length>0){if(_2(Z.oldBlock,Y,Z.childMatches,X))Q=!0}else if(X==="markdown"){if(U2(Z.oldBlock.element,Y))Q=!0}else if(V1(Z.oldBlock.element,Y,!1))Q=!0;$.appendChild(Y)}return{fragment:$,hasChanges:Q}}function z2(J){let $=J.cloneNode(!0);return $.classList.add("diff-block-removed"),$.style.position="relative",Y5($,"Removed","var(--color-accent-red)"),$}function B$(J){let $=J.cloneNode(!0);return $.classList.add("diff-block-added"),$.style.position="relative",Y5($,"Added","var(--color-accent-green)"),$}function _2(J,$,Q,Z){let Y=!1,X=L$(J,$),q,_;if(Z==="section"){let z=J.element.querySelector(":scope > div:first-child"),K=$.querySelector(":scope > div:first-child");if(z&&K){if(V1(z,K,!1))Y=!0}q=J.element.querySelector(":scope > div.mt-6, :scope > div:last-child"),_=$.querySelector(":scope > div.mt-6, :scope > div:last-child")}else q=J.element,_=$;if(!q||!_)return Y;for(let z of Q)if(z.kind==="matched"){let K=X.newMap.get(z.newBlock.element);if(K){if(z.newBlock.type==="mermaid"){if(G2(z.oldBlock.element,K))Y=!0}else if(z.childMatches&&z.childMatches.length>0&&(z.newBlock.type==="table"||z.newBlock.type==="checklist")){if(K2(K,z.childMatches,z.newBlock.type))Y=!0}else if(z.childMatches&&z.childMatches.length>0){if(_2(z.oldBlock,K,z.childMatches,z.newBlock.type))Y=!0}else if(z.newBlock.type==="markdown"){if(U2(z.oldBlock.element,K))Y=!0}else if(V1(z.oldBlock.element,K,!1))Y=!0}}else if(z.kind==="removed"){Y=!0;let K=z2(z.oldBlock.element),U=S$(Q,z,X.newMap);_.insertBefore(K,U)}else if(z.kind==="added"){Y=!0;let K=X.newMap.get(z.newBlock.element);if(K)K.classList.add("diff-block-added"),K.style.position="relative",Y5(K,"Added","var(--color-accent-green)")}if(V1(q,_,!0))Y=!0;return Y}function K2(J,$,Q){let Z=Q==="table"?J.querySelector(":scope table > tbody"):J;if(!Z)return!1;let Y=!1;Z.innerHTML="";for(let X of $)if(X.kind==="removed"){Y=!0;let q=X.oldBlock.element.cloneNode(!0);q.classList.add(Q==="table"?"diff-row-removed":"diff-item-removed"),Z.appendChild(q)}else if(X.kind==="added"){Y=!0;let q=X.newBlock.element.cloneNode(!0);q.classList.add(Q==="table"?"diff-row-added":"diff-item-added"),Z.appendChild(q)}else{let q=X.newBlock.element.cloneNode(!0);if(V1(X.oldBlock.element,q,!1))Y=!0;Z.appendChild(q)}return Y}function L$(J,$){let Q=new Map,Z=J.element.querySelectorAll("[data-md]"),Y=$.querySelectorAll("[data-md]");return{newMap:{get(X){return P$($,X)}}}}function P$(J,$){let Q=$.getAttribute("data-md");if(!Q)return null;let Z=$.getAttribute("data-md-label"),Y=$.getAttribute("data-md-title"),X=`[data-md="${Q}"]`;if(Y)X+=`[data-md-title="${CSS.escape(Y)}"]`;else if(Z)X+=`[data-md-label="${CSS.escape(Z)}"]`;let q=J.querySelectorAll(X);if(q.length===1)return q[0];let _=($.textContent||"").slice(0,100),z=null,K=-1;for(let U of q){let H=(U.textContent||"").slice(0,100),G=0;for(let N=0;N<Math.min(_.length,H.length);N++)if(_[N]===H[N])G++;if(G>K)K=G,z=U}return z}function S$(J,$,Q){let Z=J.indexOf($);for(let Y=Z+1;Y<J.length;Y++){let X=J[Y];if((X.kind==="matched"||X.kind==="added")&&X.newBlock)return Q.get(X.newBlock.element)||null}return null}function U2(J,$){let Q=Array.from(J.children),Z=Array.from($.children);if(Q.length===0&&Z.length===0)return V1(J,$,!1);let Y=Q.map((G)=>G.tagName.toLowerCase()),X=Z.map((G)=>G.tagName.toLowerCase()),q=B1(Y,X),_=[],z=0,K=0,U=0;while(z<Q.length||K<Z.length)if(U<q.length&&z<Q.length&&K<Z.length&&Y[z]===q[U]&&X[K]===q[U])_.push({kind:"matched",oldChild:Q[z],newChild:Z[K]}),z++,K++,U++;else if(z<Q.length&&(U>=q.length||Y[z]!==q[U]))_.push({kind:"removed",oldChild:Q[z]}),z++;else if(K<Z.length)_.push({kind:"added",newChild:Z[K]}),K++;let H=!1;while($.firstChild)$.removeChild($.firstChild);for(let G of _)if(G.kind==="matched"){let N=(G.oldChild.textContent||"").match(/\S+/g)||[],W=(G.newChild.textContent||"").match(/\S+/g)||[],M=B1(N,W),F=Math.max(N.length,W.length);if((F>0?1-M.length/F:0)>0.5){H=!0;let y=G.oldChild.cloneNode(!0);y.classList.add("diff-block-removed"),$.appendChild(y),G.newChild.classList.add("diff-block-added"),$.appendChild(G.newChild)}else{if(V1(G.oldChild,G.newChild,!1))H=!0;$.appendChild(G.newChild)}}else if(G.kind==="removed"){H=!0;let N=G.oldChild.cloneNode(!0);N.classList.add("diff-block-removed"),$.appendChild(N)}else H=!0,G.newChild.classList.add("diff-block-added"),$.appendChild(G.newChild);return H}function q2(J,$){let Q=$?new Set(Array.from(J.querySelectorAll("[data-md]"))):new Set,Z=[],Y=[],X=document.createTreeWalker(J,NodeFilter.SHOW_TEXT,{acceptNode(_){let z=_.parentElement;if(!z)return NodeFilter.FILTER_REJECT;if(z.closest("svg, .select-none, [data-no-diff]"))return NodeFilter.FILTER_REJECT;if($){for(let K of Q)if(K.contains(_))return NodeFilter.FILTER_REJECT}return NodeFilter.FILTER_ACCEPT}}),q;while(q=X.nextNode()){let z=(q.nodeValue||"").match(/\S+|\s+/g);if(!z)continue;let K=0;for(let U of z)Z.push(U),Y.push({text:U,node:q,offset:K}),K+=U.length}return{words:Z,map:Y}}function V1(J,$,Q){let Z=q2(J,Q),Y=q2($,Q);if(Z.words.length===0&&Y.words.length===0)return!1;let{oldOps:X,newOps:q}=e0(Z.words,Y.words),_=X.some((F)=>F.type==="removed"),z=q.some((F)=>F.type==="added");if(!_&&!z)return!1;let K=[],U=[];for(let F of X)if(F.type==="same")K.push(F.index);for(let F of q)if(F.type==="same")U.push(F.index);let H=new Map;for(let F=0;F<K.length&&F<U.length;F++)H.set(K[F],U[F]);let G=[];{let F=[],L=-1;for(let y of X)if(y.type==="same"){if(F.length>0)G.push({text:F.join(""),anchorNewIdx:L>=0?H.get(L)??null:null}),F=[];L=y.index}else if(y.type==="removed")F.push(Z.words[y.index]);if(F.length>0)G.push({text:F.join(""),anchorNewIdx:L>=0?H.get(L)??null:null})}let N=new Map,W=new Map;for(let F of q){if(F.type!=="added")continue;let L=Y.map[F.index];if(!L?.node.parentNode)continue;let y=N.get(L.node);if(!y)y=[],N.set(L.node,y);y.push({start:L.offset,end:L.offset+L.text.length})}for(let F of G)if(F.anchorNewIdx===null){if(Y.map.length>0){let L=Y.map[0].node,y=W.get(L);if(!y)y=[],W.set(L,y);y.push({offset:0,text:F.text})}}else{let L=Y.map[F.anchorNewIdx];if(!L)continue;let y=W.get(L.node);if(!y)y=[],W.set(L.node,y);y.push({offset:L.offset+L.text.length,text:F.text})}let M=new Set([...N.keys(),...W.keys()]);for(let F of M)b$(F,N.get(F)||[],W.get(F)||[]);return!0}function b$(J,$,Q){if(!J.parentNode)return;let Z=J.nodeValue||"";$.sort((U,H)=>U.start-H.start);let Y=[];for(let U of $){let H=Y[Y.length-1];if(H&&U.start<=H.end)H.end=Math.max(H.end,U.end);else Y.push({...U})}Q.sort((U,H)=>U.offset-H.offset);let X=J.parentNode,q=document.createDocumentFragment(),_=0,z=0,K=0;while(_<=Z.length){let U=z<Y.length?Y[z].start:1/0,H=K<Q.length?Q[K].offset:1/0,G=Math.min(U,H);if(G===1/0){if(_<Z.length)q.appendChild(document.createTextNode(Z.slice(_)));break}let N=Math.max(G,_);if(N>_)q.appendChild(document.createTextNode(Z.slice(_,N))),_=N;while(K<Q.length&&Q[K].offset<=_){let W=document.createElement("span");W.className="diff-removed",W.textContent=Q[K].text,q.appendChild(W),K++}if(z<Y.length&&Y[z].start<=_){let W=Y[z],M=document.createElement("span");M.className="diff-added",M.textContent=Z.slice(_,W.end),q.appendChild(M),_=W.end,z++;while(K<Q.length&&Q[K].offset<=_){let F=document.createElement("span");F.className="diff-removed",F.textContent=Q[K].text,q.appendChild(F),K++}}}while(K<Q.length){let U=document.createElement("span");U.className="diff-removed",U.textContent=Q[K].text,q.appendChild(U),K++}X.replaceChild(q,J)}function G2(J,$){let Q=(J.getAttribute("data-md-source")||"").trim(),Z=($.getAttribute("data-md-source")||"").trim();if(Q===Z)return!1;let Y=Q.split(`
|
|
110
|
+
`),X=Z.split(`
|
|
111
|
+
`),q=B1(Y,X),_=[],z=0,K=0,U=0;while(z<Y.length||K<X.length)if(U<q.length&&z<Y.length&&K<X.length&&Y[z]===q[U]&&X[K]===q[U])_.push({type:"same",line:Y[z]}),z++,K++,U++;else if(z<Y.length&&(U>=q.length||Y[z]!==q[U]))_.push({type:"removed",line:Y[z]}),z++;else if(K<X.length)_.push({type:"added",line:X[K]}),K++;let H=document.createElement("div");H.className="mt-2 bg-bg-code rounded-md overflow-hidden text-tiny font-mono",H.setAttribute("data-no-diff","true");for(let G of _){let N=document.createElement("div");if(N.className="px-3 py-0.5 whitespace-pre-wrap",G.type==="removed")N.classList.add("diff-removed"),N.textContent="- "+G.line;else if(G.type==="added")N.classList.add("diff-added"),N.textContent="+ "+G.line;else N.textContent=" "+G.line;H.appendChild(N)}return $.appendChild(H),!0}function Y5(J,$,Q){let Z=document.createElement("span");Z.className="diff-block-label",Z.textContent=$,Z.style.color=Q,Z.style.backgroundColor=`color-mix(in srgb, ${Q} 12%, transparent)`,J.appendChild(Z)}import{jsxDEV as D}from"react/jsx-dev-runtime";function H2({initialLeft:J,initialRight:$,sessionId:Q,onExit:Z}){let[Y,X]=Y1(J),[q,_]=Y1($),[z,K]=Y1("unified"),[U,H]=Y1(!0),[G,N]=Y1(!1);return D("div",{className:"flex flex-col h-screen",children:[D("div",{className:"flex items-center justify-between px-6 py-3 border-b border-border-subtle bg-bg-surface flex-shrink-0",children:[D("div",{className:"flex items-center gap-3",children:[D("span",{className:"text-[13px] font-body font-medium text-text-primary",children:"Compare"},void 0,!1,void 0,this),D(Z0,{value:Y,onChange:X,accent:"red"},void 0,!1,void 0,this),D("span",{className:"text-text-tertiary text-[13px]",children:"→"},void 0,!1,void 0,this),D(Z0,{value:q,onChange:_,accent:"green"},void 0,!1,void 0,this),G&&!U&&D("span",{className:"text-[11px] font-body text-text-tertiary bg-bg-elevated px-2 py-0.5 rounded",children:"No changes"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),D("div",{className:"flex items-center gap-4",children:[D("div",{className:"flex items-center bg-bg-elevated rounded-md p-0.5",children:[D("button",{onClick:()=>K("unified"),className:`text-[11px] font-body px-2.5 py-1 rounded transition-colors ${z==="unified"?"bg-bg-surface text-text-primary font-medium shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Unified"},void 0,!1,void 0,this),D("button",{onClick:()=>K("side-by-side"),className:`text-[11px] font-body px-2.5 py-1 rounded transition-colors ${z==="side-by-side"?"bg-bg-surface text-text-primary font-medium shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Side-by-side"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z==="side-by-side"&&D(w$,{},void 0,!1,void 0,this),D("button",{onClick:Z,className:"text-[12px] font-body font-medium text-text-secondary hover:text-text-primary px-3 py-1.5 rounded-md hover:bg-bg-elevated transition-colors",children:"Exit Compare"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),z==="unified"?D(R$,{sessionId:Q,leftRev:Y,rightRev:q,onDiffResult:(W,M)=>{N(W),H(M)}},`unified-${Y}-${q}`,!1,void 0,this):D(C$,{sessionId:Q,leftRev:Y,rightRev:q,onDiffResult:(W,M)=>{N(W),H(M)}},`sbs-${Y}-${q}`,!1,void 0,this)]},void 0,!0,void 0,this)}function w$(){let[J,$]=Y1(!0);return c1(()=>{return document.documentElement.dataset.syncScroll=J?"1":"0",()=>{delete document.documentElement.dataset.syncScroll}},[J]),D("label",{className:"flex items-center gap-1.5 cursor-pointer select-none",children:[D("input",{type:"checkbox",checked:J,onChange:(Q)=>$(Q.target.checked),className:"accent-accent-amber w-3.5 h-3.5"},void 0,!1,void 0,this),D("span",{className:"text-[11px] font-body text-text-secondary",children:"Sync scroll"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function R$({sessionId:J,leftRev:$,rightRev:Q,onDiffResult:Z}){let Y=L1(null),X=L1(null),q=L1(null),[_,z]=Y1(!1),[K,U]=Y1(!1),[H,G]=Y1(!1);return c1(()=>{if(!_||!K||H)return;if(!Y.current||!X.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!Y.current||!X.current||!q.current)return;let N=$5(Y.current),W=$5(X.current),M=J5(N,W),{fragment:F,hasChanges:L}=X2(M);q.current.innerHTML="",q.current.appendChild(F),G(!0),Z(!0,L)})})},[_,K,H]),D("div",{className:"flex-1 min-h-0 overflow-y-auto",children:[D("div",{style:{position:"absolute",left:-9999,visibility:"hidden",pointerEvents:"none",width:720},children:[D(R0,{ref:Y,sessionId:J,revision:$,onReady:()=>z(!0)},void 0,!1,void 0,this),D(R0,{ref:X,sessionId:J,revision:Q,onReady:()=>U(!0)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),D("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:[!H&&D("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-body",children:"Loading..."},void 0,!1,void 0,this),D("div",{ref:q},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function C$({sessionId:J,leftRev:$,rightRev:Q,onDiffResult:Z}){let Y=L1(null),X=L1(null),[q,_]=Y1(!1),[z,K]=Y1(!1),[U,H]=Y1(!1),G=L1(null),N=L1(null),W=L1(!1);return c1(()=>{if(!q||!z||U)return;if(!Y.current||!X.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!Y.current||!X.current)return;let M=Z2(Y.current,X.current);H(!0),Z(!0,M)})})},[q,z,U]),c1(()=>{let M=G.current,F=N.current;if(!M||!F)return;let L=(R,m)=>{if(document.documentElement.dataset.syncScroll==="0")return;if(W.current)return;W.current=!0;let k=R.scrollHeight-R.clientHeight,V=m.scrollHeight-m.clientHeight;if(k>0&&V>0)m.scrollTop=R.scrollTop/k*V;requestAnimationFrame(()=>{W.current=!1})},y=()=>L(M,F),S=()=>L(F,M);return M.addEventListener("scroll",y),F.addEventListener("scroll",S),()=>{M.removeEventListener("scroll",y),F.removeEventListener("scroll",S)}},[]),D("div",{className:"flex flex-1 min-h-0",children:[D("div",{ref:G,className:"w-1/2 overflow-y-auto border-r border-border-subtle",children:D("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:D(R0,{ref:Y,sessionId:J,revision:$,onReady:()=>_(!0)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),D("div",{ref:N,className:"w-1/2 overflow-y-auto",children:D("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:D(R0,{ref:X,sessionId:J,revision:Q,onReady:()=>K(!0)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var R0=A$.forwardRef(({sessionId:J,revision:$,onReady:Q},Z)=>{let[Y,X]=Y1(null),[q,_]=Y1(null),[z,K]=Y1(!0);if(c1(()=>{K(!0),_(null),import(`/api/session/${J}/plan.js?rev=${$}&t=${Date.now()}`).then((U)=>{X(()=>U.default),K(!1)}).catch((U)=>{_(U.message),K(!1)})},[J,$]),c1(()=>{if(!Y)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{Q()})})},[Y]),z)return D("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-body",children:"Loading..."},void 0,!1,void 0,this);if(q)return D("div",{className:"bg-accent-red-muted rounded-lg p-5",children:[D("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Error"},void 0,!1,void 0,this),D("pre",{className:"text-code font-mono text-text-secondary whitespace-pre-wrap",children:q},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(!Y)return D("div",{className:"text-text-tertiary text-center py-8 font-body text-body",children:"No plan loaded"},void 0,!1,void 0,this);return D("div",{ref:Z,children:D(Y,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)});import{jsxDEV as O,Fragment as Q5}from"react/jsx-dev-runtime";var I1=W2({activeView:{type:"plan"},setActiveView:()=>{},openFiles:[],closeFile:()=>{}}),h1=W2({currentRevision:1,selectedRevision:1,revisions:[],setSelectedRevision:()=>{},isReadOnly:!1,compareRevision:null,setCompareRevision:()=>{}});function O2(){let[J,$]=Q1(()=>localStorage.getItem("canvas-theme")||document.documentElement.dataset.theme||"dark");return O("button",{onClick:()=>{let Z=J==="dark"?"light":"dark";document.documentElement.dataset.theme=Z,localStorage.setItem("canvas-theme",Z),$(Z)},className:"w-7 h-7 flex items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:J==="dark"?"Switch to light theme":"Switch to dark theme",children:J==="dark"?O("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[O("circle",{cx:"12",cy:"12",r:"5"},void 0,!1,void 0,this),O("line",{x1:"12",y1:"1",x2:"12",y2:"3"},void 0,!1,void 0,this),O("line",{x1:"12",y1:"21",x2:"12",y2:"23"},void 0,!1,void 0,this),O("line",{x1:"4.22",y1:"4.22",x2:"5.64",y2:"5.64"},void 0,!1,void 0,this),O("line",{x1:"18.36",y1:"18.36",x2:"19.78",y2:"19.78"},void 0,!1,void 0,this),O("line",{x1:"1",y1:"12",x2:"3",y2:"12"},void 0,!1,void 0,this),O("line",{x1:"21",y1:"12",x2:"23",y2:"12"},void 0,!1,void 0,this),O("line",{x1:"4.22",y1:"19.78",x2:"5.64",y2:"18.36"},void 0,!1,void 0,this),O("line",{x1:"18.36",y1:"5.64",x2:"19.78",y2:"4.22"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):O("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:O("path",{d:"M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function F2(){let{currentRevision:J,selectedRevision:$,revisions:Q,setSelectedRevision:Z,setCompareRevision:Y}=g1.useContext(h1);if(Q.length<=1){let _=Q[0]?.label||`Round ${J}`;return O("span",{className:"text-[11px] text-text-tertiary font-body",children:_},void 0,!1,void 0,this)}return O("div",{className:"flex flex-col gap-1",children:[O(Z0,{value:$,onChange:Z,accent:$===J?"default":"amber"},void 0,!1,void 0,this),O("button",{onClick:()=>{let _=Q.find((K)=>K.revision===$)?.sourceFile,z;if($===J)z=[...Q].reverse().find((U)=>U.revision<J&&(!_||U.sourceFile===_))?.revision??Math.max(1,J-1);else z=$;Y({left:z,right:J})},className:"text-[11px] font-body font-medium px-2 py-0.5 rounded-md text-accent-blue hover:bg-accent-blue-muted transition-colors self-start",children:"Compare"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function g$(){let J=window.location.pathname.replace("/s/","")||"",[$,Q]=Q1(1),[Z,Y]=Q1(1),[X,q]=Q1([]),[_,z]=Q1(null),[K,U]=Q1(!1),[H,G]=Q1(!1),[N,W]=Q1({type:"plan"}),[M,F]=Q1([]),L=d1(null),[y,S]=Q1(),[R,m]=Q1(!1),[k,V]=Q1(!1),[w,I]=Q1(!1);X0(()=>{let j=["Agent Canvas"];if(y){let i=y.replace(/\/+$/,"").split("/");j.push(i[i.length-1]||J)}else if(J)j.push(J);if(N.type==="file")j.push(N.path.split("/").pop()||N.path);else if(_)j.push("Compare");document.title=j.join(" — ")},[J,y,N,_]);let T=d1(new Map),B=X.find((j)=>j.revision===Z),c=Z!==$||!!B?.hasFeedback,o=C0((j)=>{if(T.current.set(N.type==="plan"?"plan":`file:${N.path}`,window.scrollY),W(j),j.type==="file")F((i)=>i.includes(j.path)?i:[...i,j.path])},[N]),Z1=C0((j)=>{T.current.delete(`file:${j}`),F((i)=>i.filter((b)=>b!==j)),W((i)=>{if(i.type==="file"&&i.path===j)return T.current.set(`file:${j}`,window.scrollY),{type:"plan"};return i})},[]);m$(()=>{let j=N.type==="plan"?"plan":`file:${N.path}`;window.scrollTo(0,T.current.get(j)||0)},[N]),X0(()=>{if(!J)return;fetch(`/api/session/${J}/meta`).then((j)=>j.json()).then((j)=>{if(j.currentRevision)Q(j.currentRevision),Y(j.currentRevision),q(j.revisions||[]);if(j.projectRoot)S(j.projectRoot)}).catch(()=>{})},[J]),X0(()=>{if(!J)return;let j=null,i=()=>{let b=window.location.protocol==="https:"?"wss:":"ws:",C=new WebSocket(`${b}//${window.location.host}/ws/session/${J}`);L.current=C,C.onopen=()=>U(!0),C.onclose=()=>{U(!1),j=setTimeout(i,2000)},C.onmessage=(h)=>{try{let x=JSON.parse(h.data);if(x.type==="plan-updated"){if(Q(x.currentRevision),Y(x.currentRevision),z(null),x.revisions)q(x.revisions)}if(x.type==="revision-updated"){if(x.revisions)q(x.revisions)}}catch{}}};return i(),()=>{if(j)clearTimeout(j);L.current?.close()}},[J]);let P1=C0((j)=>{if(L.current?.readyState===WebSocket.OPEN)L.current.send(JSON.stringify({type:"submit",feedback:j})),G(!1)},[]);if(!J)return O("div",{className:"flex items-center justify-center h-screen text-text-tertiary font-body",children:"No session selected."},void 0,!1,void 0,this);return O(T2.Provider,{value:J,children:O(h1.Provider,{value:{currentRevision:$,selectedRevision:Z,revisions:X,setSelectedRevision:Y,isReadOnly:c,compareRevision:_,setCompareRevision:z},children:O(b5,{sessionId:J,revision:Z,isReadOnly:c,children:O(I1.Provider,{value:{activeView:N,setActiveView:o,openFiles:M,closeFile:Z1},children:O(V$.Provider,{value:{setActiveView:o},children:O("div",{className:"min-h-screen bg-bg-base",children:[O(D$,{sessionId:J,projectRoot:y,connected:K,onMobileSidebar:()=>m(!R),collapsed:k,onToggle:()=>V((j)=>!j)},void 0,!1,void 0,this),_===null&&O(f$,{collapsed:w,onToggle:()=>I((j)=>!j),children:O(s0,{onPreview:()=>G(!0),onSubmit:P1},void 0,!1,void 0,this)},void 0,!1,void 0,this),_!==null?O("div",{className:`${k?"lg:ml-0":"lg:ml-60"} transition-[margin] duration-200`,children:O(H2,{initialLeft:_.left,initialRight:_.right,sessionId:J,onExit:()=>z(null)},void 0,!1,void 0,this)},void 0,!1,void 0,this):O("div",{className:`relative ${k?"lg:ml-0":"lg:ml-60"} ${w?"lg:mr-0":"lg:mr-[var(--sidebar-width,320px)]"} transition-[margin] duration-200`,id:"plan-scroll-container",children:[O("div",{className:"lg:hidden sticky top-0 z-20 flex items-center justify-between px-4 py-2 border-b border-border-subtle bg-bg-surface",children:[O("div",{className:"flex items-center gap-2",children:[O(n0,{currentSessionId:J,projectRoot:y},void 0,!1,void 0,this),O("span",{className:`w-1.5 h-1.5 rounded-full ${K?"bg-accent-green":"bg-accent-red"}`},void 0,!1,void 0,this)]},void 0,!0,void 0,this),O("div",{className:"flex items-center gap-1",children:[O(F2,{},void 0,!1,void 0,this),O("button",{onClick:()=>m(!R),className:"w-7 h-7 flex items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:"Annotations",children:O("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:O("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),O(O2,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),O(u$,{},void 0,!1,void 0,this),O("div",{style:{display:N.type==="plan"?void 0:"none"},children:O("div",{className:"relative max-w-[720px] mx-auto px-6 pt-12 pb-32",children:[O("button",{onClick:()=>{let j=document.querySelector(".plan-content");if(!j)return;let i=n5(j);navigator.clipboard.writeText(i).then(()=>{let b=document.getElementById("export-md-btn");if(b)b.setAttribute("data-copied","true"),setTimeout(()=>{b.removeAttribute("data-copied")},1500)})},id:"export-md-btn",className:"group absolute top-3 right-6 p-1.5 text-text-tertiary hover:text-text-secondary transition-colors z-10",title:"Copy as Markdown",children:[O("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"group-[[data-copied=true]]:hidden",children:[O("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"},void 0,!1,void 0,this),O("path",{d:"M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),O("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"hidden group-[[data-copied=true]]:block text-green-500",children:O("polyline",{points:"20 6 9 17 4 12"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),B?.response&&O(k$,{markdown:B.response},void 0,!1,void 0,this),O(f5,{revision:Z},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),M.map((j)=>O("div",{style:{display:N.type==="file"&&N.path===j?void 0:"none"},children:O(i5,{path:j},void 0,!1,void 0,this)},j,!1,void 0,this))]},void 0,!0,void 0,this),R&&O("div",{className:"lg:hidden fixed inset-0 z-40 flex",children:[O("div",{className:"flex-1",onClick:()=>m(!1)},void 0,!1,void 0,this),O("div",{className:"w-80 max-w-[85vw] bg-bg-surface border-l border-border-subtle flex flex-col shadow-lg",children:[O("div",{className:"flex items-center justify-between px-4 py-2 border-b border-border-subtle flex-shrink-0",children:[O("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:"Sidebar"},void 0,!1,void 0,this),O("button",{onClick:()=>m(!1),className:"text-text-tertiary hover:text-text-secondary w-7 h-7 flex items-center justify-center",children:"✕"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),O("div",{className:"flex-1 overflow-hidden",children:O(s0,{onPreview:()=>G(!0),onSubmit:P1},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),O(E5,{open:H,onClose:()=>G(!1),onSubmit:P1},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},`${J}:${Z}`,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function D$({sessionId:J,projectRoot:$,connected:Q,onMobileSidebar:Z,collapsed:Y,onToggle:X}){return O(Q5,{children:[Y&&O("button",{onClick:X,className:"hidden lg:flex fixed top-3 left-3 z-20 w-7 h-7 items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors bg-bg-surface border border-border-subtle",title:"Show sidebar",children:O("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[O("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"},void 0,!1,void 0,this),O("line",{x1:"9",y1:"3",x2:"9",y2:"21"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),O("div",{className:`hidden lg:flex w-60 flex-col fixed top-0 left-0 bottom-0 bg-bg-surface border-r border-border-subtle z-10 transition-transform duration-200 ${Y?"-translate-x-full":""}`,children:[O("div",{className:"px-4 pt-4 pb-3 flex-shrink-0 border-b border-border-subtle",children:[O("div",{className:"flex items-center gap-2 mb-2",children:[O("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",className:"text-text-tertiary flex-shrink-0",children:O("path",{d:"M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this),O(n0,{currentSessionId:J,projectRoot:$},void 0,!1,void 0,this),O("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${Q?"bg-accent-green":"bg-accent-red"}`},void 0,!1,void 0,this),O("button",{onClick:X,className:"ml-auto w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:"Hide sidebar",children:O("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[O("polyline",{points:"11 17 6 12 11 7"},void 0,!1,void 0,this),O("polyline",{points:"18 17 13 12 18 7"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),O(F2,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this),O("div",{className:"flex-1 flex flex-col overflow-hidden",children:O(d5,{embedded:!0},void 0,!1,void 0,this)},void 0,!1,void 0,this),O("div",{className:"px-4 py-3 border-t border-border-subtle flex items-center justify-between flex-shrink-0",children:[O("span",{className:"text-[10px] text-text-tertiary font-body uppercase tracking-widest",children:"Theme"},void 0,!1,void 0,this),O(O2,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function f$({children:J,collapsed:$,onToggle:Q}){let[Z,Y]=Q1(()=>{let U=localStorage.getItem("canvas-sidebar-width");return U?parseInt(U,10):320}),X=d1(!1),q=d1(0),_=d1(0),z=d1(Z);z.current=Z;let K=C0((U)=>{U.preventDefault(),X.current=!0,q.current=U.clientX,_.current=z.current;let H=(N)=>{if(!X.current)return;let W=q.current-N.clientX,M=Math.max(240,Math.min(600,_.current+W));Y(M),z.current=M},G=()=>{X.current=!1,localStorage.setItem("canvas-sidebar-width",String(z.current)),document.removeEventListener("mousemove",H),document.removeEventListener("mouseup",G),document.body.style.cursor="",document.body.style.userSelect=""};document.addEventListener("mousemove",H),document.addEventListener("mouseup",G),document.body.style.cursor="col-resize",document.body.style.userSelect="none"},[]);return X0(()=>{return document.documentElement.style.setProperty("--sidebar-width",`${Z}px`),()=>{document.documentElement.style.removeProperty("--sidebar-width")}},[Z]),O(Q5,{children:[$&&O("button",{onClick:Q,className:"hidden lg:flex fixed top-3 right-3 z-20 w-7 h-7 items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors bg-bg-surface border border-border-subtle",title:"Show annotations",children:O("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:O("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),O("div",{className:`hidden lg:flex flex-col fixed top-0 right-0 bottom-0 bg-bg-surface border-l border-border-subtle z-10 transition-transform duration-200 ${$?"translate-x-full":""}`,style:{width:Z},children:[O("div",{onMouseDown:K,className:"absolute left-0 top-0 bottom-0 w-1 cursor-col-resize hover:bg-accent-blue/30 transition-colors z-20",style:{marginLeft:"-2px"}},void 0,!1,void 0,this),g1.Children.map(J,(U)=>g1.isValidElement(U)?g1.cloneElement(U,{collapseButton:O("button",{onClick:Q,className:"w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:"Hide annotations",children:O("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[O("polyline",{points:"13 17 18 12 13 7"},void 0,!1,void 0,this),O("polyline",{points:"6 17 11 12 6 7"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}):U)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function k$({markdown:J}){let[$,Q]=Q1(!1),Z=j$(()=>E.parse(J,{async:!1}),[J]);if(X0(()=>{Q(!1)},[J]),$)return null;return O("div",{className:"mb-6 rounded-lg border border-accent-blue/20 bg-accent-blue/5 relative",children:[O("button",{onClick:()=>Q(!0),className:"absolute top-2 right-2 w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",children:O("span",{className:"text-xs",children:"✕"},void 0,!1,void 0,this)},void 0,!1,void 0,this),O("div",{className:"px-4 py-3 pr-10",children:[O("div",{className:"flex items-center gap-2 mb-1.5",children:[O("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-accent-blue flex-shrink-0",children:O("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},void 0,!1,void 0,this)},void 0,!1,void 0,this),O("span",{className:"text-[11px] font-medium uppercase tracking-widest text-accent-blue font-body",children:"Agent Response"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),O("div",{className:"prose-canvas text-sm",dangerouslySetInnerHTML:{__html:Z}},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function u$(){let{activeView:J,setActiveView:$,openFiles:Q,closeFile:Z}=g1.useContext(I1),Y=g1.useContext(T2),{addAnnotationWithId:X,setActiveAnnotationId:q}=q1(),_=Q.length>0;if(!_)return null;return O("div",{className:"flex items-center border-b border-border-medium bg-bg-surface overflow-x-auto sticky top-0 z-10",children:[_&&O("button",{onClick:()=>$({type:"plan"}),className:`flex items-center gap-1.5 px-4 py-2.5 text-[13px] font-body whitespace-nowrap transition-colors relative ${J.type==="plan"?"text-text-primary":"text-text-tertiary hover:text-text-secondary"}`,children:[O("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",className:"opacity-60",children:O("path",{d:"M12 2L2 7l10 5 10-5-10-5z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this),"Plan",J.type==="plan"&&O("span",{className:"absolute bottom-0 left-3 right-3 h-[2px] bg-text-primary rounded-full"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),_&&O(Q5,{children:[O("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this),Q.map((z,K)=>{let U=z.split("/").pop()||z,H=J.type==="file"&&J.path===z;return O(g1.Fragment,{children:[O("div",{className:"flex items-center",children:[O("button",{onClick:()=>$({type:"file",path:z}),className:`flex items-center gap-1.5 pl-3 pr-1 py-2.5 text-[13px] font-mono whitespace-nowrap transition-colors relative ${H?"text-text-primary":"text-text-tertiary hover:text-text-secondary"}`,children:[U,H&&O("span",{className:"absolute bottom-0 left-3 right-1 h-[2px] bg-text-primary rounded-full"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),O("button",{onClick:(G)=>{G.stopPropagation(),Z(z)},className:"text-text-tertiary hover:text-text-secondary px-1.5 py-1 text-[10px] transition-colors rounded hover:bg-bg-input",children:"✕"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),K<Q.length-1&&O("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this)]},z,!0,void 0,this)})]},void 0,!0,void 0,this),O("div",{className:"ml-auto flex items-center gap-1 flex-shrink-0",children:J.type==="file"&&O("button",{onClick:async()=>{let z=J.path;try{let U=await(await fetch(`/api/file?session=${Y}&path=${encodeURIComponent(z)}`)).json();if(!U.error){let H=U.content.split(`
|
|
65
112
|
`).slice(0,3).join(`
|
|
66
|
-
`)+(
|
|
113
|
+
`)+(U.content.split(`
|
|
67
114
|
`).length>3?`
|
|
68
|
-
...`:""),
|
|
115
|
+
...`:""),G=H1();X(G,H,"",z),q(G)}}catch{}},className:"flex items-center gap-1 px-3 py-1.5 text-[11px] font-medium font-body text-text-tertiary hover:text-text-secondary whitespace-nowrap transition-colors",children:[O("span",{className:"text-[13px] leading-none",children:"+"},void 0,!1,void 0,this),"Add to context"]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var N2=document.getElementById("root");if(N2)I$(N2).render(O(g$,{},void 0,!1,void 0,this));export{h1 as RevisionContext,I1 as ActiveViewContext};
|