import{n as e}from"./rolldown-runtime-BG2f4sTM.js";import{Bdt as t,Cd as n,Dd as r,Ed as i,Fot as a,Fst as o,Gl as s,H8 as c,Iot as l,K8 as u,Lmt as ee,Pst as d,Td as f,U8 as p,Udt as m,Vdt as h,Wdt as g,Wl as te,mN as ne,mc as re,n6 as _,npt as v,pN as y,pc as b,q8 as x,r6 as ie,wd as S,xd as C}from"./app-initial-BHB6SClA.js";function w({cwd:e=null,projectlessOutputDirectory:t=null,title:n,turns:r}){let i=[],a=W(e);i.push(`# ${Se(n??`Codex conversation`)}`);for(let n of r){let r=T(n,e,a,t);r!=null&&i.push(r)}return`${i.join(`

`).trimEnd()}\n`}function T(e,t,n,r){let i=[],a=e.cwd==null?n:W(e.cwd),o=r==null?void 0:n=>ie({cwd:e.cwd??(t==null?null:ee(t)),projectlessOutputDirectory:r,resourcePath:n}),{userItems:s,assistantItem:c,agentItems:l,automationUpdateItems:d,toolOutputItems:f,postAssistantItems:p,systemEventItem:m,remoteTaskCreatedItems:h,personalityChangedItems:g,forkedFromConversationItems:te,modelChangedItems:ne,modelReroutedItems:_,todoListItem:v,proposedPlanItem:y,planImplementationItem:b,mcpServerElicitationItems:x,permissionRequestItems:S,approvalItem:w,userInputItem:T}=re(o==null?e.items:e.items.map(e=>e.type===`assistant-message`?{...e,content:u(e.content,o)}:e),e.status);for(let e of ne)F(i,E(e,a));for(let e of s)F(i,ae(e,a));for(let e of _)F(i,E(e,a));let D=[];for(let e of C(l))F(D,A(e,a));for(let e of d)F(D,E(e,a));m!=null&&F(D,E(m,a));for(let e of f)F(D,E(e,a));for(let e of C(p))F(D,A(e,a));v!=null&&F(D,E(v,a)),y!=null&&F(D,E(y,a)),b!=null&&F(D,E(b,a));for(let e of x)F(D,E(e,a));for(let e of S)F(D,E(e,a));w!=null&&F(D,E(w,a)),T!=null&&F(D,E(T,a)),D.length>0&&i.push(Ce(Pe(D.length),D.join(`

`))),c!=null&&F(i,se(c,{pathContext:a}));for(let e of h)F(i,E(e,a));for(let e of g)F(i,E(e,a));for(let e of te)F(i,E(e,a));return i.length===0?null:i.join(`

`)}function E(e,t){switch(e.type){case`user-message`:return D(e,{escapeDetailsTags:!0,pathContext:t});case`assistant-message`:return se(e,{escapeDetailsTags:!0,pathContext:t});case`reasoning`:return null;case`proposed-plan`:return N(`Plan`,e.content);case`todo-list`:return de(e);case`exec`:return ce(e);case`patch`:return le(e);case`turn-diff`:return ue(e);case`web-search`:return`Searched the web for ${q(e.query)}`;case`generated-image`:return me(e.src,e.status);case`image-view`:return e.imageCount===1?`Viewed an image`:`Viewed ${e.imageCount} images`;case`userInput`:return P(e.completed?`User input request`:`User input requested`,e.questions.map(e=>`- ${e.question}`));case`user-input-response`:return P(`User input response`,e.questionsAndAnswers.flatMap(e=>[`- ${e.question}`,...e.answers.map(e=>`  - ${e}`)]));case`mcp-server-elicitation`:return P(`MCP server elicitation`,[e.completed?`Status: completed`:`Status: pending`,`Action: ${e.action??`none`}`]);case`permission-request`:return P(`Permission request`,[e.completed?`Status: completed`:`Status: pending`,`Reason: ${e.reason??`Not provided`}`,`Response: ${e.response==null?`none`:`granted`}`]);case`mcp-tool-call`:return fe(e);case`automation-update`:return P(`Scheduled task update`,[`Mode: ${e.result?.mode??`pending`}`,`Automation ID: ${e.result?.automationId??`pending`}`]);case`dynamic-tool-call`:return P(`Tool call`,[`Tool: ${e.tool}`,e.completed?`Status: completed`:`Status: running`]);case`worktree-init`:return P(`Worktree initialization`,[`Worktree: created`,e.setup==null?null:`Environment setup: ${e.setup.outcome}`]);case`automatic-approval-review`:return O(e);case`multi-agent-action`:return P(`Subagent action`,[`Action: ${e.action}`,`Status: ${e.status}`,`Receiver threads: ${e.receiverThreads.length}`,e.prompt==null?null:`Prompt: ${e.prompt}`]);case`subagent-activity`:return null;case`plan-implementation`:return P(`Plan implementation`,[e.isCompleted?`Status: completed`:`Status: running`,e.planContent]);case`remote-task-created`:return P(`Remote task created`,[`Task ID: ${e.taskId}`]);case`context-compaction`:return P(`Context compaction`,[`Source: ${e.source}`,e.completed?`Status: completed`:`Status: running`]);case`personality-changed`:return P(`Personality changed`,[`Personality: ${e.personality}`]);case`forked-from-conversation`:return P(`Copied conversation`,[`Source conversation: ${e.sourceConversationId}`]);case`model-changed`:return P(`Model changed`,[`${e.fromModel} -> ${e.toModel}`]);case`model-rerouted`:return P(`Model rerouted`,[`${e.fromModel} -> ${e.toModel}`,`Reason: ${e.reason}`]);case`auto-review-interruption-warning`:return null;case`system-error`:return N(`System error`,e.content);case`stream-error`:return P(`Stream error`,[e.content,e.additionalDetails]);case`realtime-transcript`:return P(`Realtime transcript`,e.entries.map(({role:e,text:t})=>`${e}: ${t}`));case`steered`:case`worked-for`:return null}}function ae(e,t){let n=D(e,{pathContext:t});return n==null?null:L(n)}function D(e,{escapeDetailsTags:t=!1,pathContext:n=Q}={}){let r=[],i=z(e.message,n).trim();i.length>0&&r.push(i);let a=oe(e,n);if(a.length>0&&r.push(P(`User context`,a)),r.length===0)return null;let o=r.join(`

`);return t?K(o):o}function oe(e,t){let n=[];if(e.attachments.length>0){n.push(`Attachments:`);for(let r of e.attachments)n.push(`- ${r.label}: ${B(r.path,t)}`)}if(e.images.length>0){n.push(`Images:`);for(let r of e.images)n.push(`- ${B(r,t)}`)}if(e.comments!=null&&e.comments.length>0){n.push(`Comments:`);for(let r of e.comments){let e=r.lineRange==null?``:` ${q(r.lineRange)}`;n.push(`- ${V(r.path,t)}${e}: ${R(r.body).replaceAll(`
`,` `)}`)}}return e.referencesPriorConversation&&n.push(`Referenced prior conversation`),e.reviewMode&&n.push(`Mode: code review`),e.pullRequestFixMode&&n.push(`Mode: pull request fix`),e.autoResolveSync&&n.push(`Mode: auto resolve merge`),e.pullRequestCheckNames!=null&&e.pullRequestCheckNames.length>0&&n.push(`Pull request checks: ${e.pullRequestCheckNames.join(`, `)}`),e.pullRequestMergeConflictNumber!==void 0&&n.push(e.pullRequestMergeConflictNumber==null?`Pull request merge conflict`:`Pull request merge conflict: #${e.pullRequestMergeConflictNumber}`),n}function se(e,{escapeDetailsTags:t=!1,pathContext:n=Q}={}){let r=z(o(s(e.content)),n).trim();return r.length===0?null:t?K(r):r}function ce(e){let t=[],n=l(e.cmd);t.push(J(`bash`,`$ ${n}`));let r=e.output?.aggregatedOutput;if(r!=null){let e=R(r);e.trim().length>0&&t.push(J(`text`,e))}return t.push(Ve(e)),F(t,k(e.automaticApprovalReviews)),I(`Ran ${Me(n)}`,t.join(`

`))}function le(e){let t=Object.entries(e.changes).flatMap(([e,t])=>{let n=c(e,t);if(n==null||n.trim().length===0)return[];let r=Be(n);return[I(`${ze(t.type)} ${Me(e)} +${r.additions} -${r.deletions}`,J(`diff`,n))]});return F(t,k(e.automaticApprovalReviews)),t.length===0?null:t.join(`
`)}function ue(e){return I(`Diff`,J(`diff`,e.unifiedDiff))}function de(e){let t=[];return e.explanation!=null&&e.explanation.trim().length>0&&t.push(G(e.explanation).trim()),t.push(e.plan.map(e=>`- [${xe(e.status)}] ${G(e.step)}`).join(`
`)),I(`Plan`,t.join(`

`))}function fe(e){let t=[];if(t.push(`MCP tool call\n\n${G(`${e.invocation.server}.${e.invocation.tool}`)}`),t.push(J(`json`,Y(e.invocation.arguments))),F(t,k(e.automaticApprovalReviews)),e.result==null)return t.push(e.completed?`Result: none`:`Status: running`),t.join(`

`);if(e.result.type===`error`)return t.push(G(`Error: ${e.result.error}`)),t.join(`

`);let n=e.result.content.map(pe).filter(e=>e.length>0).join(`

`);return n.length>0&&t.push(n),e.result.structuredContent!=null&&t.push(J(`json`,Y(e.result.structuredContent))),t.join(`

`)}function pe(e){switch(e.type){case`text`:return J(`text`,e.text);case`image`:return G(`Image output: ${e.mimeType}`);case`audio`:return G(`Audio output: ${e.mimeType}`);case`resource_link`:return G(`Resource: ${e.title??e.name??e.uri} (${e.uri})`);case`embedded_resource`:{let t=e.resource.title??e.resource.name??e.resource.uri;return e.resource.text!=null&&e.resource.text.trim().length>0?`${G(`Resource: ${t}`)}\n\n${J(`text`,e.resource.text)}`:G(`Resource: ${t}`)}case`unknown`:return J(`json`,Y(e.raw))}}function O(e){return P(`Auto-review`,[`Status: ${e.status}`,e.riskLevel==null?null:`Risk: ${e.riskLevel}`,e.rationale==null?null:`Rationale: ${e.rationale}`])}function k(e){return e==null?null:e.map(O).join(`

`)}function me(e,t){return e==null?P(`Generated image`,[`Status: ${t}`]):`Generated image\n\n![Generated image](${e})`}function A(e,t){if(e.kind===`standalone`)return E(e.item.item,t);let n=e.items.map(({item:e})=>e),{renderableAgentItems:i}=r({agentItems:n,isTurnInProgress:!1,isAnyNonAgentItemInProgress:!1}),a=i[0];if(i.length===1&&a?.kind===`exploration`)return M(a,t);let o=n.filter(e=>e.type===`dynamic-tool-call`).length,s=Ie(S(e.items).toolActivity),c=s===`Tool activity`&&o>0?Re(o):s,l=i.map(e=>he(e,t)).filter(e=>e!=null),u=l.join(l.every(e=>e.startsWith(`- `))?`
`:`

`);return u.length===0?c:I(c,u)}function he(e,t){if(e.kind===`exploration`)return M(e,t);if(e.item.type!==`exec`&&e.item.type!==`patch`)return E(e.item,t);let n=ge(e,t);return n.length===0?null:n.map(e=>`- ${e}`).join(`
`)}function ge(e,t){return e.kind===`item`?e.item.type===`exec`?[`Ran ${q(_e(e.item))}`,...j(e.item.automaticApprovalReviews)]:e.item.type===`patch`?[...ve(e.item,t),...j(e.item.automaticApprovalReviews)]:[]:[]}function j(e){return e==null?[]:e.flatMap(e=>[`Auto-review: ${e.status}`,...e.riskLevel==null?[]:[`Auto-review risk: ${e.riskLevel}`],...e.rationale==null?[]:[`Auto-review rationale: ${G(e.rationale)}`]])}function _e(e){let t=e.parsedCmd.cmd.trim();return t.length===0?l(e.cmd):t}function ve(e,t){let n=e.grantRoot==null?t:W(e.grantRoot);return Object.entries(e.changes).flatMap(([e,t])=>{let r=c(e,t);if(r==null||r.trim().length===0)return[];let i=Be(r);return[`${ye(t.type)} ${Oe(e,n)} (+${i.additions} -${i.deletions})`]})}function ye(e){switch(e){case`add`:case`update`:return`Wrote`;case`delete`:return`Deleted`}}function M(e,t){let n=e.items.map(e=>be(e,t)).filter(e=>e!=null).map(e=>`- ${e}`);return n.length===0?null:I(Fe(e.items),n.join(`
`))}function be(e,t){if(e.type!==`exec`)return null;let n=e.parsedCmd,r=e.cwd==null?t:W(e.cwd);switch(n.type){case`read`:return`Read ${B(n.path??n.name,r)}`;case`search`:return n.query!=null&&n.path!=null?`Searched for ${q(n.query)} in ${B(n.path,r)}`:n.query==null?`Searched for files`:`Searched for ${q(n.query)}`;case`list_files`:return n.path==null?`Listed files`:`Listed files in ${B(n.path,r)}`;case`format`:case`test`:case`lint`:case`noop`:case`unknown`:return q(n.cmd)}}function N(e,t){let n=G(t).trim();return n.length===0?null:`${e}\n\n${n}`}function P(e,t){let n=t.flatMap(e=>{if(e==null)return[];let t=G(e);return t.trim().length===0?[]:[t]});return n.length===0?e:`${e}\n\n${n.join(`
`)}`}function F(e,t){t!=null&&t.trim().length>0&&e.push(t)}function xe(e){switch(e){case`completed`:return`x`;case`in_progress`:case`pending`:return` `}}function Se(e){let t=e.replaceAll(/\s+/g,` `).trim();return t.length===0?`Codex conversation`:t.replaceAll(`#`,`\\#`)}function I(e,t){return`<details><summary>${e}</summary>\n\n${R(t).trim()}\n\n</details>`}function Ce(e,t){return`<details><summary>${e}</summary>\n\n${L(t)}\n</details>`}function L(e){return R(e).trim().split(`
`).map(e=>e.length===0?`>`:`> ${e}`).join(`
`)}function R(e){return e.replaceAll(/\r\n?/g,`
`)}function z(e,t){return Te(we(R(u(e))),t)}function we(e){return ne(e).split(`
`).map(e=>{let t=e.replaceAll(Ue,``);return t.trim().length===0?``:t.trimEnd()}).join(`
`).replaceAll(/\n{3,}/g,`

`)}function Te(e,t){return e.replaceAll(We,(e,n,r)=>{let i=n.startsWith(`<`)&&n.endsWith(`>`),a=i?n.slice(1,-1):n,o=Ee(a,t);return o===a?e:`](${De(o,i)}${r??``})`})}function Ee(e,t){let{path:n}=H(e);return h(n)?V(e,t):e}function De(e,t){return t||/[\s()]/.test(e)?`<${e}>`:e}function B(e,t){return q(V(e,t))}function Oe(e,t){return q(ke(e,t))}function ke(e,t){let n=V(e,t);return n===`.`||n===`~`||n.startsWith(`./`)||n.startsWith(`../`)||n.startsWith(`~/`)||h(n)?n:`./${n}`}function V(e,t){let{path:n,lineSuffix:r}=H(e),i=g(n),a=U(i,t.cwd,`.`);if(a!=null)return`${a}${r}`;let o=U(i,t.homeDir,`~`);return o==null?`${i}${r}`:`${o}${r}`}function H(e){let t=$.exec(e);return t?.[1]==null||t[2]==null||!h(t[1])?{lineSuffix:``,path:e}:{lineSuffix:t[2],path:t[1]}}function U(e,t,n){if(t==null||t===`/`)return null;let r=m(e),i=m(t);return r===i?n:r.startsWith(`${i}/`)?`${n}/${e.slice(t.length+1)}`:null}function W(e){if(e==null)return Q;let t=Ae(e);return t==null?Q:{cwd:t,homeDir:je(t)}}function Ae(e){let t=g(e).replace(/\/+$/,``);return h(t)?t:null}function je(e){let t=Ge.exec(e);if(t!=null)return t[0];let n=Ke.exec(e);return n==null?null:n[0]}function G(e){return K(R(e))}function K(e){return e.replaceAll(/<\/?details(?=[\s>])[^>]*>/gi,e=>He(e))}function q(e){let t="`".repeat(Ne(e)+1);return`${t}${e}${t}`}function Me(e){return`<code>${He(e)}</code>`}function J(e,t){let n=R(t).trimEnd(),r="`".repeat(Math.max(3,Ne(n)+1));return`${r}${e}\n${n}\n${r}`}function Ne(e){let t=0;for(let n of e.matchAll(/`+/g))t=Math.max(t,n[0].length);return t}function Y(e){return JSON.stringify(e,null,2)??`null`}function Pe(e){return`${e} previous ${e===1?`message`:`messages`}`}function Fe(e){let t=0,n=0,r=0;for(let i of e)if(i.type===`exec`)switch(i.parsedCmd.type){case`read`:t+=1;break;case`search`:n+=1;break;case`list_files`:r+=1;break;case`format`:case`test`:case`lint`:case`noop`:case`unknown`:break}let i=[Z(t,`file`,`files`),Z(n,`search`,`searches`),Z(r,`list`,`lists`)].filter(e=>e!=null);return i.length===0?`Explored`:`Explored ${i.join(`, `)}`}function Ie(e){let t=[];X(t,e.createdFileCount,`Created`,`created`,`file`,`files`),X(t,e.editedFileCount,`Edited`,`edited`,`file`,`files`),X(t,e.deletedFileCount,`Deleted`,`deleted`,`file`,`files`);let n=[Z(e.exploredFileCount,`file`,`files`),Z(e.searchCount,`search`,`searches`),Z(e.listCount,`list`,`lists`)].filter(e=>e!=null);return n.length>0&&t.push(`${t.length===0?`Explored`:`explored`} ${n.join(`, `)}`),X(t,e.deniedRequestCount,`Denied`,`denied`,`request`,`requests`),Le(t,e.timedOutRequestCount),X(t,e.commandCount,`Ran`,`ran`,`command`,`commands`),X(t,e.mcpToolCallCount,`Called`,`called`,`tool`,`tools`),e.webSearchCount>0&&t.push(t.length===0?`Searched the web`:`searched the web`),t.length===0?`Tool activity`:t.join(`, `)}function X(e,t,n,r,i,a){let o=Z(t,i,a);o!=null&&e.push(`${e.length===0?n:r} ${o}`)}function Le(e,t){let n=Z(t,`request`,`requests`);n!=null&&e.push(`${n} timed out`)}function Z(e,t,n){return e===0?null:e===1?`a ${t}`:`${e} ${n}`}function Re(e){return e===1?`Called a tool`:`Called ${e} tools`}function ze(e){switch(e){case`add`:return`Created`;case`delete`:return`Deleted`;case`update`:return`Edited`}}function Be(e){let t=0,n=0;for(let r of R(e).split(`
`)){if(r.startsWith(`+`)&&!r.startsWith(`+++`)){t+=1;continue}r.startsWith(`-`)&&!r.startsWith(`---`)&&(n+=1)}return{additions:t,deletions:n}}function Ve(e){return e.executionStatus===`interrupted`?`Stopped`:e.output?.exitCode==null?e.executionStatus===`completed`?`Success`:`Running`:e.output.exitCode===0?`Success`:`Failed with exit code ${e.output.exitCode}`}function He(e){return e.replaceAll(`&`,`&amp;`).replaceAll(`<`,`&lt;`).replaceAll(`>`,`&gt;`).replaceAll(`"`,`&quot;`)}var Ue,Q,We,Ge,Ke,$;e((()=>{v(),d(),te(),x(),t(),y(),f(),n(),p(),a(),_(),i(),b(),Ue=/::git-[a-z-]+\{[^}\n]*\}/g,Q={cwd:null,homeDir:null},We=/\]\((<[^>\n]+>|[^)\s\n]+)([ \t]+(?:"[^"\n]*"|'[^'\n]*'|\([^)\n]*\)))?\)/g,Ge=/^\/(?:Users|home)\/[^/]+(?=\/|$)/,Ke=/^[A-Za-z]:\/Users\/[^/]+(?=\/|$)/,$=/^(.*?)(:\d+(?:-\d+)?)$/}))();export{w as renderConversationMarkdown};
//# sourceMappingURL=conversation-markdown-U92vPKLm.js.map