import"./src-BOCweS1p.js";import{Hi as e,Ir as t,Nr as n,fo as r,ho as i,mo as a}from"./app-server-manager-signals-Yn0WSnoY.js";import"./jsx-runtime-CiQ1k8xo.js";import"./marked.esm-BR-H6018.js";import"./vscode-api-DjORcpSo.js";import"./lib-MoKmYgcO.js";import"./persisted-signal-CweW-bgN.js";import"./rpc-CJwVeoy_.js";import"./statsig-BP9zNYqZ.js";import"./request-CBZ5m5yv.js";import"./invalidate-queries-and-broadcast-CivBKbpC.js";import"./thread-context-inputs-C9hcxtXy.js";import"./config-queries-Br8rhpJn.js";import"./use-is-copilot-api-available-Cju6TzB2.js";import"./use-global-state-baOKTuK6.js";import"./toast-signal-ifUptee5.js";import"./setting-storage-CwKZnsvR.js";import"./reduced-motion-preference-Bd5_3c7y.js";import"./spinner-BAEL5-Nn.js";import"./remote-projects-B8AFbAx_.js";import"./thread-detail-level-CUYPl_o4.js";import"./permissions-mode-defaults-RHKS5B2I.js";import"./proxy-BMi4zsAT.js";import"./x-DypUcSQe.js";import"./projectless-thread-JZqZP2Qh.js";import"./app-intl-signal-B-4vWE81.js";import"./settings.cog-_MjPuK5w.js";import"./codex--dd_3IvO.js";import"./use-stable-callback-CvFJzJNa.js";import"./local-projects-8Dp63JZk.js";import"./check-md-BzLzXDM7.js";import"./chevron-right-CqaqXhBx.js";import"./build-worktree-label-from-input-f_xtfIvj.js";import"./read-service-tier-for-request-Bz5NZ-py.js";import"./pending-worktree-store-B7c-n7Re.js";import"./app-server-dynamic-tools-BGE4VTsB.js";import"./pinned-threads-query-xt9anzNF.js";import"./use-resize-observer-pZWTsQ9C.js";import"./check-circle-B_KjsLxa.js";import"./x-circle-CFq7Iwx-.js";import"./thinking-shimmer-BLzK6Vzl.js";import"./chat-C1CD_vcD.js";import"./globe-oc2o98t5.js";import"./set-pinned-thread-uATOh9_i.js";import"./thread-actions-w1ZofEWE.js";import"./chevron-AEenlp4G.js";import"./unselected-circle-BN-IdXY-.js";import"./workspace-dependencies-feature-CyIUlxNP.js";import"./thread-resource-card-Bzt36Zw4.js";import"./thread-handoff-composer-block-state-jCmoNgli.js";import"./mcp-tool-item-content-utils-B_xEtoSO.js";import"./get-move-to-local-targets-CRH-a0bJ.js";import"./thread-handoff-step-row-DPkSSkLD.js";import"./use-measured-element-height-DscTfu6m.js";import{c as o,d as s,i as ee,n as te,r as c,s as ne,t as re,u as ie}from"./split-items-into-render-groups-C_iFpjyN.js";var l=/::git-[a-z-]+\{[^}\n]*\}/g,u=`STEPS_PROSE`,d={cwd:null,homeDir:null},f=/\]\((<[^>\n]+>|[^)\s\n]+)([ \t]+(?:"[^"\n]*"|'[^'\n]*'|\([^)\n]*\)))?\)/g,p=/^\/(?:Users|home)\/[^/]+(?=\/|$)/,m=/^[A-Za-z]:\/Users\/[^/]+(?=\/|$)/,h=/^(.*?)(:\d+(?:-\d+)?)$/;function g({cwd:e=null,title:t,turns:n}){let r=[],i=W(e);r.push(`# ${me(t??`Codex conversation`)}`);for(let e of n){let t=_(e,i);t!=null&&r.push(t)}return`${r.join(`

`).trimEnd()}\n`}function _(e,t){let n=[],r=e.cwd==null?t:W(e.cwd),{userItems:i,assistantItem:a,agentItems:ee,automationUpdateItems:l,toolOutputItems:d,postAssistantItems:f,systemEventItem:p,remoteTaskCreatedItems:m,personalityChangedItems:h,forkedFromConversationItems:g,modelChangedItems:_,modelReroutedItems:y,todoListItem:b,proposedPlanItem:S,planImplementationItem:C,mcpServerElicitationItems:w,permissionRequestItems:T,approvalItem:E,userInputItem:D}=re(e.items,e.status);for(let e of _)F(n,v(e,r));for(let e of i)F(n,ae(e,r));for(let e of y)F(n,v(e,r));let O=[],{renderableAgentItems:k}=te({agentItems:ee,isTurnInProgress:e.status===`in_progress`,isAnyNonAgentItemInProgress:c(a)||c(S)}),A=ie({units:o({units:ne({units:s(k),isActivitySliceClosed:a!=null,conversationDetailLevel:u})}),isActivitySliceClosed:a!=null});for(let e of A)F(O,oe(e,r));for(let e of l)F(O,v(e,r));p!=null&&F(O,v(p,r));for(let e of d)F(O,v(e,r));for(let e of f)F(O,v(e,r));b!=null&&F(O,v(b,r)),S!=null&&F(O,v(S,r)),C!=null&&F(O,v(C,r));for(let e of w)F(O,v(e,r));for(let e of T)F(O,v(e,r));E!=null&&F(O,v(E,r)),D!=null&&F(O,v(D,r)),O.length>0&&n.push(he(we(O.length),O.join(`

`))),a!=null&&F(n,x(a,{pathContext:r}));for(let e of m)F(n,v(e,r));for(let e of h)F(n,v(e,r));for(let e of g)F(n,v(e,r));return n.length===0?null:n.join(`

`)}function v(e,t){switch(e.type){case`user-message`:return y(e,{escapeDetailsTags:!0,pathContext:t});case`assistant-message`:return x(e,{escapeDetailsTags:!0,pathContext:t});case`reasoning`:return null;case`proposed-plan`:return N(`Plan`,e.content);case`todo-list`:return T(e);case`exec`:return S(e);case`patch`:return C(e);case`turn-diff`:return w(e);case`web-search`:return`Searched web for ${q(e.query)}`;case`generated-image`:return k(e.src,e.status);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 E(e);case`automation-update`:return P(`Automation 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`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`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(`Forked 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`steered`:case`worked-for`:return null}}function ae(e,t){let n=y(e,{pathContext:t});return n==null?null:L(n)}function y(e,{escapeDetailsTags:t=!1,pathContext:n=d}={}){let r=[],i=z(e.message,n).trim();i.length>0&&r.push(i);let a=b(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 b(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 x(e,{escapeDetailsTags:t=!1,pathContext:n=d}={}){let r=z(e.content,n).trim();return r.length===0?null:t?K(r):r}function S(t){let n=[],r=e(t.cmd);n.push(Y(`bash`,`$ ${r}`));let i=t.output?.aggregatedOutput;if(i!=null){let e=R(i);e.trim().length>0&&n.push(Y(`text`,e))}return n.push(je(t)),I(`Ran ${J(r)}`,n.join(`

`))}function C(e){let t=Object.entries(e.changes).flatMap(([e,t])=>{let r=n(e,t);if(r==null||r.trim().length===0)return[];let i=Ae(r);return[I(`${ke(t.type)} ${J(e)} +${i.additions} -${i.deletions}`,Y(`diff`,r))]});return t.length===0?null:t.join(`
`)}function w(e){return I(`Diff`,Y(`diff`,e.unifiedDiff))}function T(e){let t=[];return e.explanation!=null&&e.explanation.trim().length>0&&t.push(G(e.explanation).trim()),t.push(e.plan.map(e=>`- [${pe(e.status)}] ${G(e.step)}`).join(`
`)),I(`Plan`,t.join(`

`))}function E(e){let t=[];if(t.push(`MCP tool call\n\n${G(`${e.invocation.server}.${e.invocation.tool}`)}`),t.push(Y(`json`,Z(e.invocation.arguments))),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(D).filter(e=>e.length>0).join(`

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

`)}function D(e){switch(e.type){case`text`:return Y(`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${Y(`text`,e.resource.text)}`:G(`Resource: ${t}`)}case`unknown`:return Y(`json`,Z(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,t){return e==null?P(`Generated image`,[`Status: ${t}`]):`Generated image\n\n![Generated image](${e})`}function oe(e,t){if(e.kind===`collapsed-tool-activity`){let n=Ee(e.summary);if(!ee(u,e.units)){let r=e.units.flatMap(e=>j(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=>A(e,t)).filter(e=>e!=null).join(`

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

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

`)):M(e,t)}function A(e,t){return e.kind===`entry`&&e.entry.kind===`item`&&(e.entry.item.type===`exec`||e.entry.item.type===`patch`)?se(e,t):M(e,t)}function se(e,t){let n=j(e,t);return n.length===0?null:n.map(e=>`- ${e}`).join(`
`)}function j(e,t){return e.kind!==`entry`||e.entry.kind!==`item`?[]:e.entry.item.type===`exec`?[`Ran ${q(ce(e.entry.item))}`]:e.entry.item.type===`patch`?le(e.entry.item,t):[]}function ce(t){let n=t.parsedCmd.cmd.trim();return n.length===0?e(t.cmd):n}function le(e,t){let r=e.grantRoot==null?t:W(e.grantRoot);return Object.entries(e.changes).flatMap(([e,t])=>{let i=n(e,t);if(i==null||i.trim().length===0)return[];let a=Ae(i);return[`${ue(t.type)} ${be(e,r)} (+${a.additions} -${a.deletions})`]})}function ue(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(Oe(e.items.length),e.items.map(e=>`- Searched web for ${q(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`?de(e.entry,t):v(e.entry.item,t)}function de(e,t){let n=e.items.map(e=>fe(e,t)).filter(e=>e!=null).map(e=>`- ${e}`);return n.length===0?null:I(Te(e.items),n.join(`
`))}function fe(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 pe(e){switch(e){case`completed`:return`x`;case`in_progress`:case`pending`:return` `}}function me(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 he(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,n){return _e(ge(R(t(e))),n)}function ge(e){return e.split(`
`).map(e=>{let t=e.replaceAll(l,``);return t.trim().length===0?``:t.trimEnd()}).join(`
`).replaceAll(/\n{3,}/g,`

`)}function _e(e,t){return e.replaceAll(f,(e,n,r)=>{let i=n.startsWith(`<`)&&n.endsWith(`>`),a=i?n.slice(1,-1):n,o=ve(a,t);return o===a?e:`](${ye(o,i)}${r??``})`})}function ve(e,t){let{path:n}=H(e);return r(n)?V(e,t):e}function ye(e,t){return t||/[\s()]/.test(e)?`<${e}>`:e}function B(e,t){return q(V(e,t))}function be(e,t){return q(xe(e,t))}function xe(e,t){let n=V(e,t);return n===`.`||n===`~`||n.startsWith(`./`)||n.startsWith(`../`)||n.startsWith(`~/`)||r(n)?n:`./${n}`}function V(e,t){let{path:n,lineSuffix:r}=H(e),a=i(n),o=U(a,t.cwd,`.`);if(o!=null)return`${o}${r}`;let s=U(a,t.homeDir,`~`);return s==null?`${a}${r}`:`${s}${r}`}function H(e){let t=h.exec(e);return t?.[1]==null||t[2]==null||!r(t[1])?{lineSuffix:``,path:e}:{lineSuffix:t[2],path:t[1]}}function U(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 W(e){if(e==null)return d;let t=Se(e);return t==null?d:{cwd:t,homeDir:Ce(t)}}function Se(e){let t=i(e).replace(/\/+$/,``);return r(t)?t:null}function Ce(e){let t=p.exec(e);if(t!=null)return t[0];let n=m.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=>Me(e))}function q(e){let t="`".repeat(X(e)+1);return`${t}${e}${t}`}function J(e){return`<code>${Me(e)}</code>`}function Y(e,t){let n=R(t).trimEnd(),r="`".repeat(Math.max(3,X(n)+1));return`${r}${e}\n${n}\n${r}`}function X(e){let t=0;for(let n of e.matchAll(/`+/g))t=Math.max(t,n[0].length);return t}function Z(e){return JSON.stringify(e,null,2)??`null`}function we(e){return`${e} previous ${e===1?`message`:`messages`}`}function Te(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=[$(t,`file`,`files`),$(n,`search`,`searches`),$(r,`list`,`lists`)].filter(e=>e!=null);return i.length===0?`Explored`:`Explored ${i.join(`, `)}`}function Ee(e){let t=[];Q(t,e.createdFileCount,`Created`,`created`,`file`,`files`),Q(t,e.editedFileCount,`Edited`,`edited`,`file`,`files`),Q(t,e.deletedFileCount,`Deleted`,`deleted`,`file`,`files`);let n=[$(e.exploredFileCount,`file`,`files`),$(e.searchCount,`search`,`searches`),$(e.listCount,`list`,`lists`)].filter(e=>e!=null);return n.length>0&&t.push(`${t.length===0?`Explored`:`explored`} ${n.join(`, `)}`),Q(t,e.approvedRequestCount,`Approved`,`approved`,`request`,`requests`),Q(t,e.deniedRequestCount,`Denied`,`denied`,`request`,`requests`),Q(t,e.commandCount,`Ran`,`ran`,`command`,`commands`),Q(t,e.mcpToolCallCount,`Called`,`called`,`tool`,`tools`),Q(t,e.webSearchCount,`Searched web`,`searched web`,`time`,`times`),t.length===0?`Tool activity`:t.join(`, `)}function Q(e,t,n,r,i,a){let o=$(t,i,a);o!=null&&e.push(`${e.length===0?n:r} ${o}`)}function $(e,t,n){return e===0?null:`${e} ${e===1?t:n}`}function De(e){return`Called ${e} ${e===1?`tool`:`tools`}`}function Oe(e){return`Searched web ${e} ${e===1?`time`:`times`}`}function ke(e){switch(e){case`add`:return`Created`;case`delete`:return`Deleted`;case`update`:return`Edited`}}function Ae(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 je(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 Me(e){return e.replaceAll(`&`,`&amp;`).replaceAll(`<`,`&lt;`).replaceAll(`>`,`&gt;`).replaceAll(`"`,`&quot;`)}export{g as renderConversationMarkdown};
//# sourceMappingURL=conversation-markdown-BdBjo7nZ.js.map