import{n as e}from"./rolldown-runtime-BG2f4sTM.js";import{pi as t,w as n}from"./app-initial~avatarOverlayCompositionSurface~artifact-tab-content.electron~notebook-preview-~ngwudnyz-D_QFwR2V.js";import{lt as r,mt as i,pt as a,ut as o}from"./app-initial~avatarOverlayCompositionSurface~artifact-tab-content.electron~notebook-preview-~l16cgjx9-XwSLyHyz.js";import{S as s,x as ee}from"./app-initial~avatarOverlayCompositionSurface~artifact-tab-content.electron~notebook-preview-~g8980z4e-CwatHxhA.js";import{Ji as te,Ks as c,Us as l,Vs as u,qi as ne,qs as re}from"./app-initial~artifact-tab-content.electron~notebook-preview-panel~app-main~business-checkout~oxnpxkxc-CRvN_72X.js";import{c as ie,d as ae,i as d,l as oe,n as f,r as p,t as m,u as h}from"./app-initial~app-main~onboarding-page~hotkey-window-thread-page~quick-chat-window-page~chatg~f5p8e1kp-B5dFi3Nu.js";import{_ as g,v as _}from"./app-initial~artifact-tab-content.electron~notebook-preview-panel~app-main~pull-request-rout~jvsvjxtt-e03gRhH3.js";import{c as se,f as v,l as ce,n as le,r as y,s as ue,t as de,u as fe}from"./app-initial~app-main~onboarding-page~hotkey-window-thread-page~thread-app-shell-chrome~remo~c1415s9d-BXGGUI4D.js";function pe({cwd:e=null,projectlessOutputDirectory:t=null,title:n,turns:r}){let i=[],a=U(e);i.push(`# ${Oe(n??`Codex conversation`)}`);for(let n of r){let r=b(n,e,a,t);r!=null&&i.push(r)}return`${i.join(`

`).trimEnd()}\n`}function b(e,n,r,i){let a=[],o=e.cwd==null?r:U(e.cwd),s=i==null?void 0:r=>te({cwd:e.cwd??(n==null?null:t(n)),projectlessOutputDirectory:i,resourcePath:r}),{userItems:ee,assistantItem:l,agentItems:u,automationUpdateItems:ne,toolOutputItems:re,postAssistantItems:ie,systemEventItem:d,remoteTaskCreatedItems:f,personalityChangedItems:p,forkedFromConversationItems:m,modelChangedItems:h,modelReroutedItems:g,todoListItem:_,proposedPlanItem:v,planImplementationItem:y,mcpServerElicitationItems:de,permissionRequestItems:pe,approvalItem:b,userInputItem:S}=le(s==null?e.items:e.items.map(e=>e.type===`assistant-message`?{...e,content:c(e.content,s)}:e),e.status);for(let e of h)F(a,x(e,o));for(let e of ee)F(a,me(e,o));for(let e of g)F(a,x(e,o));let C=[],{renderableAgentItems:T}=oe({agentItems:u,isTurnInProgress:e.status===`in_progress`,isAnyNonAgentItemInProgress:ae(l)||ae(v)}),E=ce({units:se({units:ue({units:fe(T),isActivitySliceClosed:l!=null,conversationDetailLevel:Q})}),isActivitySliceClosed:l!=null});for(let e of E)F(C,ye(e,o));for(let e of ne)F(C,x(e,o));d!=null&&F(C,x(d,o));for(let e of re)F(C,x(e,o));for(let e of ie)F(C,x(e,o));_!=null&&F(C,x(_,o)),v!=null&&F(C,x(v,o)),y!=null&&F(C,x(y,o));for(let e of de)F(C,x(e,o));for(let e of pe)F(C,x(e,o));b!=null&&F(C,x(b,o)),S!=null&&F(C,x(S,o)),C.length>0&&a.push(ke(Ve(C.length),C.join(`

`))),l!=null&&F(a,w(l,{pathContext:o}));for(let e of f)F(a,x(e,o));for(let e of p)F(a,x(e,o));for(let e of m)F(a,x(e,o));return a.length===0?null:a.join(`

`)}function x(e,t){switch(e.type){case`user-message`:return S(e,{escapeDetailsTags:!0,pathContext:t});case`assistant-message`:return w(e,{escapeDetailsTags:!0,pathContext:t});case`reasoning`:return null;case`proposed-plan`:return N(`Plan`,e.content);case`todo-list`:return ge(e);case`exec`:return T(e);case`patch`:return E(e);case`turn-diff`:return he(e);case`web-search`:return`Searched the web for ${K(e.query)}`;case`generated-image`:return ve(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 D(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 me(e,t){let n=S(e,{pathContext:t});return n==null?null:L(n)}function S(e,{escapeDetailsTags:t=!1,pathContext:n=$}={}){let r=[],i=z(e.message,n).trim();i.length>0&&r.push(i);let a=C(e,n);if(a.length>0&&r.push(P(`User context`,a)),r.length===0)return null;let o=r.join(`

`);return t?G(o):o}function C(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?``:` ${K(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 w(e,{escapeDetailsTags:t=!1,pathContext:n=$}={}){let r=z(f(d(e.content)),n).trim();return r.length===0?null:t?G(r):r}function T(e){let t=[],n=s(e.cmd);t.push(q(`bash`,`$ ${n}`));let r=e.output?.aggregatedOutput;if(r!=null){let e=R(r);e.trim().length>0&&t.push(q(`text`,e))}return t.push(qe(e)),F(t,k(e.automaticApprovalReviews)),I(`Ran ${ze(n)}`,t.join(`

`))}function E(e){let t=Object.entries(e.changes).flatMap(([e,t])=>{let n=u(e,t);if(n==null||n.trim().length===0)return[];let r=Z(n);return[I(`${Ke(t.type)} ${ze(e)} +${r.additions} -${r.deletions}`,q(`diff`,n))]});return F(t,k(e.automaticApprovalReviews)),t.length===0?null:t.join(`
`)}function he(e){return I(`Diff`,q(`diff`,e.unifiedDiff))}function ge(e){let t=[];return e.explanation!=null&&e.explanation.trim().length>0&&t.push(W(e.explanation).trim()),t.push(e.plan.map(e=>`- [${De(e.status)}] ${W(e.step)}`).join(`
`)),I(`Plan`,t.join(`

`))}function D(e){let t=[];if(t.push(`MCP tool call\n\n${W(`${e.invocation.server}.${e.invocation.tool}`)}`),t.push(q(`json`,J(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(W(`Error: ${e.result.error}`)),t.join(`

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

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

`)}function _e(e){switch(e.type){case`text`:return q(`text`,e.text);case`image`:return W(`Image output: ${e.mimeType}`);case`audio`:return W(`Audio output: ${e.mimeType}`);case`resource_link`:return W(`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?`${W(`Resource: ${t}`)}\n\n${q(`text`,e.resource.text)}`:W(`Resource: ${t}`)}case`unknown`:return q(`json`,J(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 ve(e,t){return e==null?P(`Generated image`,[`Status: ${t}`]):`Generated image\n\n![Generated image](${e})`}function ye(e,t){if(e.kind===`collapsed-tool-activity`){let n=Ue(e.summary);if(!y(Q,e.units)){let r=e.units.flatMap(e=>A(e,t)).map(e=>`- ${e}`);return r.length===0?n:I(n,r.join(`
`))}if(e.units.length===1){let n=e.units[0];if(n?.kind===`entry`&&n.entry.kind===`exploration`)return M(n,t)}return I(n,e.units.map(e=>be(e,t)).filter(e=>e!=null).join(`

`))}return e.kind===`pending-mcp-tool-calls`?I(Ge(e.items.length),e.items.map(e=>D(e)).join(`

`)):e.kind===`dynamic-tool-call-group`?I(Ge(e.items.length),e.items.map(e=>x(e,t)).join(`

`)):M(e,t)}function be(e,t){return e.kind===`entry`&&e.entry.kind===`item`&&(e.entry.item.type===`exec`||e.entry.item.type===`patch`)?xe(e,t):M(e,t)}function xe(e,t){let n=A(e,t);return n.length===0?null:n.map(e=>`- ${e}`).join(`
`)}function A(e,t){return e.kind!==`entry`||e.entry.kind!==`item`?[]:e.entry.item.type===`exec`?[`Ran ${K(Se(e.entry.item))}`,...j(e.entry.item.automaticApprovalReviews)]:e.entry.item.type===`patch`?[...Ce(e.entry.item,t),...j(e.entry.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: ${W(e.rationale)}`]])}function Se(e){let t=e.parsedCmd.cmd.trim();return t.length===0?s(e.cmd):t}function Ce(e,t){let n=e.grantRoot==null?t:U(e.grantRoot);return Object.entries(e.changes).flatMap(([e,t])=>{let r=u(e,t);if(r==null||r.trim().length===0)return[];let i=Z(r);return[`${we(t.type)} ${Pe(e,n)} (+${i.additions} -${i.deletions})`]})}function we(e){switch(e){case`add`:case`update`:return`Wrote`;case`delete`:return`Deleted`}}function M(e,t){if(e.kind===`web-search-group`)return I(`Searched the web`,e.items.map(e=>`- Searched the web for ${K(e.query)}`).join(`
`));if(e.kind===`multi-agent-group`){let t=e.items[0];return P(`Subagent action`,[t==null?null:`Action: ${t.action}`,t==null?null:`Status: ${t.status}`,`Receiver threads: ${e.items.length}`])}return e.entry.kind===`exploration`?Te(e.entry,t):x(e.entry.item,t)}function Te(e,t){let n=e.items.map(e=>Ee(e,t)).filter(e=>e!=null).map(e=>`- ${e}`);return n.length===0?null:I(He(e.items),n.join(`
`))}function Ee(e,t){if(e.type!==`exec`)return null;let n=e.parsedCmd,r=e.cwd==null?t:U(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 ${K(n.query)} in ${B(n.path,r)}`:n.query==null?`Searched for files`:`Searched for ${K(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 K(n.cmd)}}function N(e,t){let n=W(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=W(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 De(e){switch(e){case`completed`:return`x`;case`in_progress`:case`pending`:return` `}}function Oe(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 ke(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 je(Ae(R(c(e))),t)}function Ae(e){return _(e).split(`
`).map(e=>{let t=e.replaceAll(Ye,``);return t.trim().length===0?``:t.trimEnd()}).join(`
`).replaceAll(/\n{3,}/g,`

`)}function je(e,t){return e.replaceAll(Xe,(e,n,r)=>{let i=n.startsWith(`<`)&&n.endsWith(`>`),a=i?n.slice(1,-1):n,o=Me(a,t);return o===a?e:`](${Ne(o,i)}${r??``})`})}function Me(e,t){let{path:n}=H(e);return o(n)?V(e,t):e}function Ne(e,t){return t||/[\s()]/.test(e)?`<${e}>`:e}function B(e,t){return K(V(e,t))}function Pe(e,t){return K(Fe(e,t))}function Fe(e,t){let n=V(e,t);return n===`.`||n===`~`||n.startsWith(`./`)||n.startsWith(`../`)||n.startsWith(`~/`)||o(n)?n:`./${n}`}function V(e,t){let{path:n,lineSuffix:r}=H(e),a=i(n),o=Ie(a,t.cwd,`.`);if(o!=null)return`${o}${r}`;let s=Ie(a,t.homeDir,`~`);return s==null?`${a}${r}`:`${s}${r}`}function H(e){let t=$e.exec(e);return t?.[1]==null||t[2]==null||!o(t[1])?{lineSuffix:``,path:e}:{lineSuffix:t[2],path:t[1]}}function Ie(e,t,n){if(t==null||t===`/`)return null;let r=a(e),i=a(t);return r===i?n:r.startsWith(`${i}/`)?`${n}/${e.slice(t.length+1)}`:null}function U(e){if(e==null)return $;let t=Le(e);return t==null?$:{cwd:t,homeDir:Re(t)}}function Le(e){let t=i(e).replace(/\/+$/,``);return o(t)?t:null}function Re(e){let t=Ze.exec(e);if(t!=null)return t[0];let n=Qe.exec(e);return n==null?null:n[0]}function W(e){return G(R(e))}function G(e){return e.replaceAll(/<\/?details(?=[\s>])[^>]*>/gi,e=>Je(e))}function K(e){let t="`".repeat(Be(e)+1);return`${t}${e}${t}`}function ze(e){return`<code>${Je(e)}</code>`}function q(e,t){let n=R(t).trimEnd(),r="`".repeat(Math.max(3,Be(n)+1));return`${r}${e}\n${n}\n${r}`}function Be(e){let t=0;for(let n of e.matchAll(/`+/g))t=Math.max(t,n[0].length);return t}function J(e){return JSON.stringify(e,null,2)??`null`}function Ve(e){return`${e} previous ${e===1?`message`:`messages`}`}function He(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=[X(t,`file`,`files`),X(n,`search`,`searches`),X(r,`list`,`lists`)].filter(e=>e!=null);return i.length===0?`Explored`:`Explored ${i.join(`, `)}`}function Ue(e){let t=[];Y(t,e.createdFileCount,`Created`,`created`,`file`,`files`),Y(t,e.editedFileCount,`Edited`,`edited`,`file`,`files`),Y(t,e.deletedFileCount,`Deleted`,`deleted`,`file`,`files`);let n=[X(e.exploredFileCount,`file`,`files`),X(e.searchCount,`search`,`searches`),X(e.listCount,`list`,`lists`)].filter(e=>e!=null);return n.length>0&&t.push(`${t.length===0?`Explored`:`explored`} ${n.join(`, `)}`),Y(t,e.deniedRequestCount,`Denied`,`denied`,`request`,`requests`),We(t,e.timedOutRequestCount),Y(t,e.commandCount,`Ran`,`ran`,`command`,`commands`),Y(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 Y(e,t,n,r,i,a){let o=X(t,i,a);o!=null&&e.push(`${e.length===0?n:r} ${o}`)}function We(e,t){let n=X(t,`request`,`requests`);n!=null&&e.push(`${n} timed out`)}function X(e,t,n){return e===0?null:e===1?`a ${t}`:`${e} ${n}`}function Ge(e){return e===1?`Called a tool`:`Called ${e} tools`}function Ke(e){switch(e){case`add`:return`Created`;case`delete`:return`Deleted`;case`update`:return`Edited`}}function Z(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 qe(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 Je(e){return e.replaceAll(`&`,`&amp;`).replaceAll(`<`,`&lt;`).replaceAll(`>`,`&gt;`).replaceAll(`"`,`&quot;`)}var Ye,Q,$,Xe,Ze,Qe,$e;e((()=>{n(),p(),re(),r(),g(),m(),v(),l(),h(),ee(),ne(),ie(),de(),Ye=/::git-[a-z-]+\{[^}\n]*\}/g,Q=`STEPS_PROSE`,$={cwd:null,homeDir:null},Xe=/\]\((<[^>\n]+>|[^)\s\n]+)([ \t]+(?:"[^"\n]*"|'[^'\n]*'|\([^)\n]*\)))?\)/g,Ze=/^\/(?:Users|home)\/[^/]+(?=\/|$)/,Qe=/^[A-Za-z]:\/Users\/[^/]+(?=\/|$)/,$e=/^(.*?)(:\d+(?:-\d+)?)$/}))();export{pe as renderConversationMarkdown};
//# sourceMappingURL=conversation-markdown-B-TpbyV4.js.map