@x-otto/cli 0.0.1-alpha.13 → 0.0.1-alpha.14-debug

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.
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import{c as e}from"./extension-plugin-D76MKjOB.js";export{e as runPluginInstall};
@@ -2,6 +2,6 @@
2
2
  import{t as e}from"./discover-with-bundled-wSuXDvNc.js";import{n as t}from"./extension-DAex6RFK.js";import{homedir as n}from"node:os";import{InstallManager as r,POINT as i,buildExtensionContext as a,defaultPostInstallExecutor as o,dispatch as s,evaluatePluginTrust as c,findWorkspaceRoot as l,grantPluginCapabilities as u,installPluginFromPackage as d,openTarget as f,readHighRiskCapabilities as p,readPluginLogTail as m,recordPluginInstalled as h,recordPluginUninstalled as g,resolveActions as _,resolvePackageDir as v,runPluginScript as y,trustPlugin as b,uninstall as x,untrustPlugin as S}from"@x-otto/coding";import{join as C}from"node:path";import{existsSync as w,readFileSync as T}from"node:fs";import{i18next as E}from"@x-otto/tui";function D(e){switch(e){case`global`:return E.t(`cmd.scopeGlobal`);case`repository`:return E.t(`cmd.scopeRepository`);default:return E.t(`cmd.scopeProject`)}}function O(e,t,n){return{workspaceDir:e.app.workspaceDir,workspaceRoot:t===`repository`?l(e.app.workspaceDir):void 0,global:t===`global`,dryRun:n}}async function k(e){let{name:t,type:n,scope:r,ctx:i,onDone:a}=e,o=i.app.settings.get(`mcp_servers`),s=await x(t,n,O(i,r,!0),()=>o,async()=>{});if(!s.success){i.tui.info.showToast(E.t(`cmd.titleUninstall`),E.t(`cmd.uninstallFailed`,{err:s.error??E.t(`cmd.unknownError`)})),a?.();return}let c=s.plan??[];i.tui.modal.openModal({kind:`confirm`,title:E.t(`cmd.uninstallConfirmTitle`,{type:n,name:t}),message:[E.t(`cmd.uninstallConfirmScope`,{scopeLabel:D(r)}),...c].join(`
3
3
  `),confirmLabel:E.t(`cmd.uninstallConfirmYes`),dangerous:!0,onConfirm:()=>{A(e)},onCancel:()=>a?.()})}async function A(e){let{name:t,type:n,scope:r,ctx:i,onDone:a}=e,o=i.app.settings.get(`mcp_servers`),s=await x(t,n,O(i,r,!1),()=>o,async e=>{await i.app.settings.persist({mcp_servers:e})});if(!s.success){i.tui.info.showToast(E.t(`cmd.titleUninstall`),E.t(`cmd.uninstallFailed`,{err:s.error??E.t(`cmd.unknownError`)})),a?.();return}i.tui.info.showToast(E.t(`cmd.titleUninstall`),E.t(`cmd.uninstalled`,{type:n,name:t,scope:D(r)})),n===`plugin`&&await g(i.app.settings,t);try{await i.app.reloadCapabilities(),i.tui.plugins.setPluginRegistrations(i.app.getPluginRegistrations()),n===`plugin`&&i.app.pluginModuleManager.emitMonitorEvent({type:`plugin.uninstalled`,pluginId:t}),i.tui.info.showToast(E.t(`cmd.titleUninstall`),E.t(`cmd.uninstallRefreshed`))}catch(e){i.tui.messages.pushMessage({role:`command_echo`,command:`/extension`,status:`error`,summary:E.t(`cmd.uninstalledRefreshErr`,{err:e instanceof Error?e.message:String(e)})})}a?.()}function j(e){return e===`project`?`project`:e===`global`?`global`:null}function M(e,t){let n={project:`project`,global:`global`,plugin:`plugin`,inline:`inline`}[e]??e;return t?`${n} (${t})`:n}function N(e){let t=[];return e.providerApis>0&&t.push(`provider(${e.providerApis})`),e.tools>0&&t.push(`tools(${e.tools})`),e.renderers>0&&t.push(`renderers(${e.renderers})`),e.statusItems>0&&t.push(`statusItems(${e.statusItems})`),e.fileViewers&&e.fileViewers>0&&t.push(`fileViewers(${e.fileViewers})`),t.length?t.join(`, `):void 0}function P(e){switch(e){case`provider`:return E.t(`cmd.pluginCapabilityProvider`);case`tools`:return E.t(`cmd.pluginCapabilityTools`);case`tui.renderer`:return E.t(`cmd.pluginCapabilityTuiRenderer`);case`network`:return E.t(`cmd.pluginCapabilityNetwork`);case`wire-protocol`:return E.t(`cmd.pluginCapabilityWireProtocol`);case`a2ui.component`:return E.t(`cmd.pluginCapabilityA2uiComponent`);case`panel.backend`:return E.t(`cmd.pluginCapabilityPanelBackend`);case`input.resolver`:return E.t(`cmd.pluginCapabilityInputResolver`);case`a2ui.renderer`:return E.t(`cmd.pluginCapabilityA2uiRenderer`);default:return}}function F(e,t){let n=c(t),r=n.pendingCapabilities,i=()=>{b(t.dir),r.length>0&&u(t.dir,r),e.tui.info.showToast(E.t(`cmd.titlePlugin`),E.t(`cmd.pluginTrusting`,{id:t.id})),e.app.reloadCapabilities().then(n=>{e.tui.plugins.setPluginRegistrations(e.app.getPluginRegistrations()),e.tui.info.showToast(E.t(`cmd.titlePlugin`),E.t(`cmd.pluginTrusted`,{id:t.id,count:n.mcpTools}))},t=>e.tui.info.showToast(E.t(`cmd.titlePlugin`),E.t(`cmd.compatReloadFailed`,{err:t instanceof Error?t.message:String(t)})))},a=n.surface;if(!a.any&&r.length===0){i();return}let o=[E.t(`cmd.pluginTrustConfirmIntro`)];if(a.mcpJson&&o.push(`• ${E.t(`cmd.pluginSurfaceMcp`)}`),a.commands&&o.push(`• ${E.t(`cmd.pluginSurfaceCommands`)}`),a.scripts&&o.push(`• ${E.t(`cmd.pluginSurfaceScripts`)}`),a.panels&&o.push(`• ${E.t(`cmd.pluginSurfacePanels`)}`),a.skills&&o.push(`• ${E.t(`cmd.pluginSurfaceSkills`)}`),a.agents&&o.push(`• ${E.t(`cmd.pluginSurfaceAgents`)}`),r.length>0){o.push(``,E.t(`cmd.pluginCapabilityIntro`));for(let e of r){let t=P(e);t&&o.push(`• ${t}`)}}o.push(``,E.t(`cmd.pluginTrustConfirmHint`)),e.tui.modal.openModal({kind:`select`,title:E.t(`cmd.pluginTrustConfirmTitle`,{id:t.id}),subtitle:o.join(`
4
4
  `),layout:`buttons`,options:[{label:E.t(`cmd.pluginTrustConfirmAction`),value:`trust`,color:`accent`},{label:E.t(`cmd.commonCancel`),value:`cancel`,color:`gray`}],onSelect:e=>{e===`trust`&&i()},onCancel:()=>{}})}async function I(e,t,n){if(t.length===0)return!0;let r=[E.t(`cmd.pluginCapabilityIntro`)];for(let e of t){let t=P(e);t&&r.push(`• ${t}`)}return new Promise(t=>{n.tui.modal.openModal({kind:`select`,title:E.t(`cmd.pluginInstallConfirmTitle`,{name:e}),subtitle:r.join(`
5
- `),layout:`buttons`,options:[{label:E.t(`cmd.pluginInstallConfirmAction`),value:`install`,color:`accent`},{label:E.t(`cmd.commonCancel`),value:`cancel`,color:`gray`}],onSelect:e=>t(e===`install`),onCancel:()=>t(!1)})})}async function L(e,n,i){let a=i?.autoTrust??!1,s=i?.onProgress,c=i?.onPendingCapabilities;if(e.includes(`..`)||e.startsWith(`/`)||e.startsWith(`./`)||e.startsWith(`~/`))return a||n.tui.info.showToast(E.t(`cmd.titleInstall`),E.t(`cmd.pluginInstallInvalidName`,{name:e})),!1;let l=t[e]?.pkg??e,f=v(l),m;if(!f)try{s?.(`Downloading from npm registry`);let e=await new r().install(l,{global:!0,as:`plugin`,postInstallExecutor:o});e.success&&e.targetPath?(f=e.targetPath,m={id:e.name??l,dir:e.targetPath,created:!0,compileWarnings:[],version:e.manifest?.version}):a||n.tui.info.showToast(E.t(`cmd.titleInstall`),E.t(`cmd.pluginInstallFailed`,{err:e.error??`未知错误`}))}catch(e){a||n.tui.info.showToast(E.t(`cmd.titleInstall`),E.t(`cmd.pluginInstallFailed`,{err:e instanceof Error?e.message:String(e)}))}if(!f)return a||n.tui.info.showToast(E.t(`cmd.titleInstall`),E.t(`cmd.pluginInstallNotFound`,{pkg:l})),!1;let g=p(f);if(!a&&!await I(e,g,n))return n.tui.info.showToast(E.t(`cmd.titleInstall`),E.t(`cmd.pluginInstallCancelled`)),!1;let _;if(m)_=m;else try{s?.(`Installing plugin`),_=await d({pkg:l})}catch(e){return a||n.tui.info.showToast(E.t(`cmd.titleInstall`),E.t(`cmd.pluginInstallFailed`,{err:e instanceof Error?e.message:String(e)})),!1}a||n.tui.info.showToast(E.t(`cmd.titleInstall`),E.t(`cmd.pluginInstalled`,{seg:_.created?`Installed ${_.id}`:`${_.id} already up to date`})),await h(n.app.settings,{id:_.id,source:`npm`,sourceSpec:l,version:_.version,scope:`global`,capabilities:g}),n.app.pluginModuleManager.emitMonitorEvent({type:`plugin.installed`,pluginId:_.id});for(let e of _.compileWarnings)a||n.tui.info.showToast(E.t(`cmd.titleInstall`),E.t(`cmd.pluginInstallFailed`,{err:e}));g.length>0&&(s?.(`Authorizing capabilities`),b(_.dir),u(_.dir,g));try{s?.(`Reloading capabilities`),(await n.app.reloadCapabilities()).pendingProviderCapabilities.includes(_.id)&&(a||n.tui.info.showToast(E.t(`cmd.titleInstall`),E.t(`cmd.pluginInstallPendingCaps`,{id:_.id})),c?.(_.id))}catch(e){a||n.tui.info.showToast(E.t(`cmd.titleInstall`),E.t(`cmd.compatReloadFailed`,{err:e instanceof Error?e.message:String(e)}))}if(await n.callbacks.refreshModelsNow().catch(()=>{}),e===`plugin-feishu-use`){try{let{launchFeishuSetup:e}=await import(`./feishu-setup-DIcd3PMK.js`);await e(n)}catch{}return!0}if(!a){await new Promise(e=>setImmediate(e));let{handleModel:e}=await import(`./model-auth-C0FiDKd9.js`);await e([],n)}return!0}async function R(e,t){t.tui.panes.togglePane(`backgroundTasks`)}async function z(e,t){let n=e.join(` `);if(!n){t.tui.info.showToast(E.t(`cmd.titleJob`),E.t(`cmd.jobUsage`));return}let r=/^revert\s+(\S+)$/.exec(n);if(r){let e=r[1],n=t.app.agentJobs.revert(e);if(n.applied)t.tui.info.showToast(E.t(`cmd.titleReverted`),E.t(`cmd.jobReverted`,{id:e,msg:n.message}));else{let r=n.conflictPaths.length?E.t(`cmd.jobConflictFiles`,{joinedPaths:n.conflictPaths.join(`
6
- `)}):``;t.tui.messages.pushMessage({role:`command_echo`,command:`/go revert ${e}`,status:`error`,summary:E.t(`cmd.jobRevertFailed`,{id:e,status:n.status,msg:n.message,conflicts:r})})}return}try{let e=t.app.agentJobs.start({title:n.slice(0,60),prompt:n,sessionId:t.state.session.id,origin:`user`});t.tui.info.showToast(E.t(`cmd.titleDelegated`),E.t(`cmd.delegated`,{title:e.title}))}catch(e){t.tui.messages.pushMessage({role:`command_echo`,command:`/go`,status:`error`,summary:E.t(`cmd.delegateFailed`,{err:e instanceof Error?e.message:String(e)})})}}async function B(t,r){let o=(e,t)=>r.tui.info.showToast(e,t),l=e=>r.tui.messages.pushMessage({role:`command_echo`,command:`/extension`,status:`error`,summary:e}),u=()=>{let e=r.app.extensions.list(),t=r.app.getGlobalMenuItems?.()??[],n=new Map(t.map(e=>[e.id,e.command]));r.tui.modal.openModal({kind:`extensionsList`,entries:e.map(e=>({category:e.category,id:e.id,name:e.name,enabled:e.enabled,description:e.description,applies:e.applies})),menuContributions:[{id:`__discover__`,title:`Discover plugins (search registries)…`},...t.map(e=>({id:e.id,title:e.title}))],onSelect:e=>{if(!e)return;if(e===`contrib:__discover__`){d();return}if(e.startsWith(`contrib:`)){let t=e.slice(8),i=n.get(t);if(!i)return;s(i,{open:e=>f(e),runCommand:async(e,t)=>{let{dispatchSlashCommand:n}=await import(`./command-dispatcher-Cc1elmRw.js`).then(e=>e.a);await n(e,t?t.split(/\s+/).filter(Boolean):[],r)}}).catch(e=>o(E.t(`cmd.titlePlugin`),e instanceof Error?e.message:String(e)));return}let t=e.indexOf(`:`);g(e.slice(0,t),e.slice(t+1))},onCancel:()=>{}})},d=async()=>{let e=await r.tui.modal.openModal({kind:`input`,title:`Discover plugins`,description:[`搜索已注册 registry(/registry list 查看源;/registry add 注册第三方源)`],placeholder:`keyword… (e.g. weather / oauth / provider)`});if(!e?.trim()){u();return}let{searchRegistries:t}=await import(`./registry-B3nfN62q.js`),{hits:n,warnings:i}=await t(r,e.trim());if(n.length===0){o(E.t(`cmd.titlePlugin`),`No registry entries match '${e.trim()}'${i.length?` (${i.length} source warning)`:``}`),u();return}r.tui.modal.openModal({kind:`select`,title:`Discover: '${e.trim()}' (${n.length})`,subtitle:i.length>0?`⚠ ${i.join(` · `)}`:void 0,options:n.map((e,t)=>({label:`${e.entry.id} (${e.entry.type}) [${(e.entry.capabilities??[]).join(`, `)||`-`}] @${e.sourceName}${e.stale?` (stale)`:``}`,description:e.entry.description,value:String(t)})),onSelect:e=>{let t=n[Number(e)];if(!t)return;let i=[`--as`,t.entry.type,...t.entry.subPath?[`--sub-path`,t.entry.subPath]:[],t.entry.source];(async()=>{let{dispatchSlashCommand:e}=await import(`./command-dispatcher-Cc1elmRw.js`).then(e=>e.a);await e(`install`,i,r)})().catch(e=>o(E.t(`cmd.titlePlugin`),e instanceof Error?e.message:String(e)))},onCancel:()=>u()})},p=e=>{let t=r.app.skillRegistry?.get(e);if(!t){u();return}let n=t.status!==`disabled`,i=t.definition.metadata,a=[{kind:`group`,title:E.t(`cmd.extSkillGroupOverview`)},{kind:`row`,label:E.t(`cmd.extSkillLabelDesc`),value:i.description||`—`},{kind:`row`,label:E.t(`cmd.extSkillLabelStatus`),value:t.status,tone:t.status===`error`||t.status===`disabled`?`error`:`success`},{kind:`row`,label:E.t(`cmd.extSkillLabelSource`),value:E.t(`cmd.extSkillSourceLabel`,{seg:M(t.source.type,t.source.id)}),tone:`muted`},{kind:`group`,title:E.t(`cmd.extSkillGroupTrigger`)},{kind:`row`,label:E.t(`cmd.extSkillLabelTriggerMode`),value:i.trigger===`manual`?E.t(`cmd.extSkillTriggerManual`):E.t(`cmd.extSkillTriggerAuto`)},...i.priority===void 0?[]:[{kind:`row`,label:E.t(`cmd.extSkillLabelPriority`),value:String(i.priority)}],{kind:`group`,title:E.t(`cmd.extSkillGroupDependencies`)},{kind:`row`,label:E.t(`cmd.extSkillLabelDependencies`),value:i.dependencies?.length?i.dependencies.join(`, `):E.t(`cmd.extSkillNoDependencies`),tone:i.dependencies?.length?void 0:`muted`},{kind:`group`,title:E.t(`cmd.extSkillGroupTags`)},{kind:`row`,label:E.t(`cmd.extSkillLabelTags`),value:i.tags?.length?i.tags.join(`, `):E.t(`cmd.extSkillNoTags`),tone:i.tags?.length?void 0:`muted`}];t.status===`error`&&t.error&&a.push({kind:`group`,title:E.t(`cmd.extSkillGroupError`)},{kind:`text`,value:t.error,tone:`error`}),r.tui.modal.openModal({kind:`extensionDetail`,title:E.t(`cmd.extSkillTitle`,{name:e,state:n?`enabled`:`disabled`}),meta:`skill · ${t.source.type}`,metaStatus:{label:n?E.t(`cmd.extEnableLabel`):E.t(`cmd.extDisableLabel`),enabled:n},actions:[{label:n?E.t(`cmd.extDisableLabel`):E.t(`cmd.extEnableLabel`),value:`toggle`,color:n?`amber`:`green`},{label:E.t(`cmd.extViewFullTextLabel`),value:`view-full-text`,color:`gray`},...j(t.source.type)?[{label:E.t(`cmd.uninstallActionLabel`),value:`uninstall`,color:`red`}]:[]],dataListEntries:a,fullText:{title:E.t(`cmd.extSkillFullTextTitle`,{name:e}),content:t.definition.body||E.t(`cmd.extSkillNoBody`)},onAction:async i=>{if(i===`toggle`){try{await r.app.extensions.setEnabled(`skill`,e,!n),o(E.t(`cmd.titleExtension`),E.t(`cmd.extToggled`,{name:e,verb:n?`Disabled`:`Enabled`,seg:` — applies next turn`}))}catch(e){l(E.t(`cmd.extToggleFailed`,{err:e instanceof Error?e.message:String(e)}))}p(e);return}if(i===`uninstall`){let n=j(t.source.type);if(!n)return;await k({name:e,type:`skill`,scope:n,ctx:r,onDone:()=>u()})}},onClose:()=>u()})},h=e=>{let t=r.app.declarativeAgentProfiles.find(t=>t.name===e);if(!t){u();return}let n=!new Set(r.app.settings.get(`disabled_agents`)??[]).has(e),i=[{kind:`group`,title:E.t(`cmd.extAgentGroupOverview`)},{kind:`row`,label:E.t(`cmd.extAgentLabelDesc`),value:t.description||`—`},{kind:`row`,label:E.t(`cmd.extAgentLabelStatus`),value:n?E.t(`cmd.extEnableLabel`):E.t(`cmd.extDisableLabel`),tone:n?`success`:`error`},{kind:`group`,title:E.t(`cmd.extAgentGroupCapabilities`)},{kind:`row`,label:E.t(`cmd.extAgentLabelTaskTypes`),value:t.taskTypes.length?t.taskTypes.join(`, `):E.t(`cmd.extAgentNoTaskTypes`),tone:t.taskTypes.length?void 0:`muted`},{kind:`row`,label:E.t(`cmd.extAgentLabelCapabilities`),value:t.capabilities.length?t.capabilities.join(`, `):E.t(`cmd.extAgentNoCapabilities`),tone:t.capabilities.length?void 0:`muted`},{kind:`group`,title:E.t(`cmd.extAgentGroupTools`)},{kind:`row`,label:E.t(`cmd.extAgentLabelDefaultTools`),value:t.defaultTools?.length?t.defaultTools.join(`, `):E.t(`cmd.extAgentAllTools`),tone:t.defaultTools?.length?void 0:`muted`},{kind:`row`,label:E.t(`cmd.extAgentLabelDisallowedTools`),value:t.disallowedTools?.length?t.disallowedTools.join(`, `):E.t(`cmd.extAgentNoDisallowedTools`),tone:t.disallowedTools?.length?void 0:`muted`},{kind:`group`,title:E.t(`cmd.extAgentGroupExecution`)},{kind:`row`,label:E.t(`cmd.extAgentLabelPromptMode`),value:t.promptMode??`append`,tone:`muted`},...t.preferredModelTier?[{kind:`row`,label:E.t(`cmd.extAgentLabelModelTier`),value:t.preferredModelTier}]:[],{kind:`row`,label:E.t(`cmd.extAgentLabelAllowSubagents`),value:t.allowSubagents?E.t(`cmd.extEnableLabel`):E.t(`cmd.extDisableLabel`),tone:t.allowSubagents?void 0:`muted`}];r.tui.modal.openModal({kind:`extensionDetail`,title:E.t(`cmd.extAgentTitle`,{name:e,state:n?`enabled`:`disabled`}),meta:`agent`,metaStatus:{label:n?E.t(`cmd.extEnableLabel`):E.t(`cmd.extDisableLabel`),enabled:n},actions:[{label:n?E.t(`cmd.extDisableLabel`):E.t(`cmd.extEnableLabel`),value:`toggle`,color:n?`amber`:`green`},{label:E.t(`cmd.extViewFullTextLabel`),value:`view-full-text`,color:`gray`}],dataListEntries:i,fullText:{title:E.t(`cmd.extAgentFullTextTitle`,{name:e}),content:t.systemPromptTemplate||E.t(`cmd.extSkillNoBody`)},onAction:async t=>{if(t===`toggle`){try{await r.app.extensions.setEnabled(`agent`,e,!n),o(E.t(`cmd.titleExtension`),E.t(`cmd.extToggled`,{name:e,verb:n?`Disabled`:`Enabled`,seg:` — applies next turn`}))}catch(e){l(E.t(`cmd.extToggleFailed`,{err:e instanceof Error?e.message:String(e)}))}h(e)}},onClose:()=>u()})},g=(e,t)=>{let n=r.app.extensions.list().find(n=>n.category===e&&n.id===t);if(!n){u();return}let i={label:n.enabled?E.t(`cmd.extDisableLabel`):E.t(`cmd.extEnableLabel`),value:`toggle`};if(e===`mcp`){let a=r.app.mcpManager?.getServerInfos().find(e=>e.name===t),s=n.enabled?a?String(a.status):`disconnected`:`disabled`;r.tui.modal.openModal({kind:`select`,title:E.t(`cmd.extMcpTitle`,{name:n.name,status:s}),options:[{label:E.t(`cmd.extReconnectLabel`),value:`reconnect`},i,...n.readonly?[]:[{label:E.t(`cmd.uninstallActionLabel`),value:`uninstall`}]],onSelect:async i=>{if(i===`toggle`){try{await r.app.extensions.setEnabled(n.category,t,!n.enabled),o(E.t(`cmd.titleExtension`),E.t(`cmd.extToggled`,{name:n.name,verb:n.enabled?`Disabled`:`Enabled`,seg:``}))}catch(e){l(E.t(`cmd.extToggleFailed`,{err:e instanceof Error?e.message:String(e)}))}g(e,t);return}if(i===`reconnect`){let n=r.app.mcpManager,i=(r.app.settings.get(`mcp_servers`)??{})[t];if(!n||!i){o(E.t(`cmd.titleExtension`),E.t(`cmd.extReconnectUnavailable`,{id:t})),g(e,t);return}try{await n.disconnect(t).catch(()=>{}),await n.connect(t,i),o(E.t(`cmd.titleExtension`),E.t(`cmd.extReconnected`,{id:t}))}catch(e){l(E.t(`cmd.extReconnectFailed`,{id:t,err:e instanceof Error?e.message:String(e)}))}g(e,t);return}if(i===`uninstall`){await k({name:t,type:`mcp`,scope:`project`,ctx:r,onDone:()=>u()});return}},onCancel:()=>u()})}else e===`plugin`?v(t,n.enabled,n.name,n.description):e===`skill`?p(t):e===`agent`?h(t):r.tui.modal.openModal({kind:`select`,title:E.t(`cmd.extItemTitle`,{name:n.name}),options:[i],onSelect:async i=>{if(i===`toggle`){try{await r.app.extensions.setEnabled(n.category,t,!n.enabled),o(E.t(`cmd.titleExtension`),E.t(`cmd.extToggled`,{name:n.name,verb:n.enabled?`Disabled`:`Enabled`,seg:n.applies===`live`?``:` — applies next turn`}))}catch(e){l(E.t(`cmd.extToggleFailed`,{err:e instanceof Error?e.message:String(e)}))}g(e,t);return}},onCancel:()=>u()})},v=(t,d,p,h,g)=>{let b=r.app.workspaceDir??process.cwd(),x=e({cwd:b,homedir:n()}).find(e=>e.id===t);if(!x){u();return}let D=c(x),O=D.surface.any?D.gated?E.t(`cmd.extPluginUntrusted`):D.pendingCapabilities.length>0?E.t(`cmd.extPluginCapabilityPending`,{caps:D.pendingCapabilities.join(`, `)}):E.t(`cmd.extPluginTrusted`):E.t(`cmd.extPluginNoSurface`),A=D.surface,j=[[A.mcpJson,`mcp`],[A.commands,`commands`],[A.scripts,`scripts`],[A.panels,`panels`],[A.skills,`skills`],[A.agents,`agents`]].filter(([e])=>e).map(([,e])=>e),M=j.length?` ${j.join(`, `)}`:` —`,P=(r.app.getPluginPanelRegistrations?.()??[]).filter(e=>e.pluginId===t),I=N({providerApis:r.app.providerRegistry.getApisBySource(t).length,tools:r.app.toolRegistry.getAll().filter(e=>e.metadata.source===t).length,renderers:r.app.getPluginRenderers().filter(e=>e.pluginId===t).length,statusItems:r.app.getPluginStatusItems().filter(e=>e.id.startsWith(`${t}:`)).length,fileViewers:(r.app.getPluginFileViewers?.()??[]).filter(e=>e.pluginId===t).length}),L=x.scope===`builtin`?[]:[{label:d?E.t(`cmd.extDisableLabel`):E.t(`cmd.extEnableLabel`),value:`toggle`,color:d?`amber`:`green`}];if(D.surface.any&&(x.scope===`project`||x.scope===`repository`||D.pendingCapabilities.length>0)){let e=x.scope===`project`||x.scope===`repository`?!D.trusted:D.pendingCapabilities.length>0;L.push({label:e?E.t(`cmd.extPluginTrustLabel`):E.t(`cmd.extPluginUntrustLabel`),value:e?`trust`:`untrust`,color:e?`accent`:`gray`})}L.push({label:E.t(`cmd.extReloadLabel`),value:`reload`}),x.scope!==`builtin`&&L.push({label:E.t(`cmd.uninstallActionLabel`),value:`uninstall`,color:`red`});let R=a(x,{"extension.id":t,"extension.enabled":d,"extension.trusted":D.trusted,"extension.scope":x.scope,"extension.category":`plugin`}),z=x.manifest.contributes,B=_(i.extensionDetailActions,z?.menus,z?.actions,R),V=new Map(B.map(e=>[e.id,e.command]));for(let e of B){let t=`${x.id}:action.${e.id}.title`,n=r.app.i18nRegistry.t(t),i=n===t?e.title:n;L.push({label:i,value:`contrib:${e.id}`,color:e.color})}let H={open:e=>f(e),runCommand:async(e,t)=>{let{dispatchSlashCommand:n}=await import(`./command-dispatcher-Cc1elmRw.js`).then(e=>e.a);await n(e,t?t.split(/\s+/).filter(Boolean):[],r)},runScript:async e=>{if(c(x).gated){o(E.t(`cmd.titlePlugin`),E.t(`cmd.extPluginUntrusted`));return}await y(x,e)}},U=P[0];U&&r.app.firePluginActivationEvent?.(`onView:${U.id}`);let W;if(t===`plugin-feishu-use`){let e=C(b,`.otto`,`feishu-use.json`),t=!1;try{if(w(e)){let n=JSON.parse(T(e,`utf8`));if(n.app_id){t=!0;let r=typeof n.app_id==`string`&&n.app_id.length>12?n.app_id.slice(0,8)+`***`+n.app_id.slice(-4):String(n.app_id),i=Array.isArray(n.allowed_chats)?n.allowed_chats.length:0,a=Array.isArray(n.trusted_chats)?n.trusted_chats.length:0,o=x.scope===`user`?`全局`:x.scope===`repository`?`仓库`:`项目`;W=[{kind:`row`,label:`App ID`,value:r},{kind:`row`,label:`消息白名单`,value:i>0?`${i} 个`:`空 — 拒绝所有消息`,tone:i>0?void 0:`warning`},...a>0?[{kind:`row`,label:`可信任 chat`,value:`${a} 个`}]:[],{kind:`row`,label:`配置`,value:`${o}级 · ${e}`,tone:`muted`}]}}}catch{}t||(W=[{kind:`text`,value:`未配置 — 点击 [重新配置] 引导设置`,tone:`warning`},{kind:`row`,label:`预期配置路径`,value:e,tone:`muted`}]),L.push({label:`重新配置`,value:`feishu-reconfigure`,color:`amber`})}let G=()=>{let e=r.app.pluginHealthTracker?.query(t)??{hookTimeouts:0,toolTimeouts:0},n=m(t);return{healthStats:{hookTimeouts:e.hookTimeouts,toolTimeouts:e.toolTimeouts,lastError:e.lastError},logEntries:n.map(e=>({ts:e.ts,level:e.level,msg:e.msg}))}},K=[{kind:`group`,title:E.t(`cmd.extPluginGroupTitle`)},{kind:`row`,label:E.t(`cmd.extPluginLabelDesc`),value:h},{kind:`row`,label:E.t(`cmd.extPluginLabelScope`),value:x.scope},{kind:`row`,label:E.t(`cmd.extPluginLabelTrust`),value:O},{kind:`row`,label:E.t(`cmd.extPluginLabelSurfaces`),value:M.trim()||`—`},...I?[{kind:`row`,label:E.t(`cmd.extPluginLabelContributions`),value:I}]:[],{kind:`row`,label:E.t(`cmd.extPluginLabelStatus`),value:d?E.t(`cmd.extEnableLabel`):E.t(`cmd.extDisableLabel`),tone:d?`success`:`error`}],q=g?[{kind:`text`,value:g.message,tone:g.kind===`success`?`success`:`error`}]:[];r.tui.modal.openModal({kind:`extensionDetail`,title:E.t(`cmd.extPluginTitle`,{name:p,state:d?`enabled`:`disabled`}),meta:`plugin · ${x.scope}`,metaStatus:{label:d?E.t(`cmd.extEnableLabel`):E.t(`cmd.extDisableLabel`),enabled:d},metaSuffix:O,actions:L,panelInfo:U?{title:U.title,modulePath:U.modulePath,exportName:U.exportName,pluginId:t}:void 0,dataListEntries:[...q,...W??K],...G(),onRefresh:()=>v(t,d,p,h),onAction:async e=>{if(e.startsWith(`contrib:`)){let n=V.get(e.slice(8));if(n)try{await s(n,H)}catch(e){l(E.t(`cmd.extToggleFailed`,{err:e instanceof Error?e.message:String(e)}))}v(t,d,p,h)}else if(e===`trust`)F(r,x);else if(e===`untrust`)S(x.dir),r.app.reloadCapabilities?.().then(()=>{r.tui.plugins.setPluginRegistrations(r.app.getPluginRegistrations())}).finally(()=>{v(t,d,p,h,{kind:`success`,message:E.t(`cmd.pluginUntrusted`,{id:t})})});else if(e===`toggle`)try{await r.app.extensions.setEnabled(`plugin`,t,!d);try{await r.app.reloadCapabilities(),v(t,!d,p,h,{kind:`success`,message:E.t(`cmd.extToggled`,{name:p,verb:d?`Disabled`:`Enabled`,seg:``})})}catch(e){v(t,!d,p,h,{kind:`error`,message:E.t(`cmd.extToggleReloadFailed`,{verb:d?`Disabled`:`Enabled`,name:p,err:e instanceof Error?e.message:String(e)})})}}catch(e){v(t,d,p,h,{kind:`error`,message:E.t(`cmd.extToggleFailed`,{err:e instanceof Error?e.message:String(e)})})}else if(e===`feishu-reconfigure`)try{let{launchFeishuSetup:e}=await import(`./feishu-setup-DIcd3PMK.js`);await e(r),o(`plugin-feishu-use`,`配置完成。`)}catch(e){l(`feishu-use 配置向导失败:${e instanceof Error?e.message:String(e)}`)}else e===`reload`?r.app.reloadCapabilities?.().then(e=>{v(t,d,p,h,{kind:`success`,message:E.t(`cmd.pluginTrusted`,{id:t,count:e.mcpTools})})}).catch(e=>{v(t,d,p,h,{kind:`error`,message:E.t(`cmd.compatReloadFailed`,{err:e instanceof Error?e.message:String(e)})})}):e===`uninstall`&&await k({name:t,type:`plugin`,scope:x.scope===`project`||x.scope===`repository`?x.scope:`global`,ctx:r,onDone:()=>u()})},onClose:()=>u()})};u()}export{z as a,L as c,B as i,N as n,P as o,R as r,F as s,I as t};
7
- //# sourceMappingURL=extension-plugin-ByMTqmpu.js.map
5
+ `),layout:`buttons`,options:[{label:E.t(`cmd.pluginInstallConfirmAction`),value:`install`,color:`accent`},{label:E.t(`cmd.commonCancel`),value:`cancel`,color:`gray`}],onSelect:e=>t(e===`install`),onCancel:()=>t(!1)})})}async function L(e,n,i){let a=i?.autoTrust??!1,s=i?.onProgress,c=i?.onPendingCapabilities;if(e.includes(`..`)||e.startsWith(`/`)||e.startsWith(`./`)||e.startsWith(`~/`))return a||n.tui.info.showToast(E.t(`cmd.titleInstall`),E.t(`cmd.pluginInstallInvalidName`,{name:e})),!1;let l=t[e]?.pkg??e,f=v(l),m;if(!f)try{s?.(`Downloading from npm registry`);let e=await new r().install(l,{global:!0,as:`plugin`,postInstallExecutor:o});e.success&&e.targetPath?(f=e.targetPath,m={id:e.name??l,dir:e.targetPath,created:!0,compileWarnings:[],version:e.manifest?.version}):a||n.tui.info.showToast(E.t(`cmd.titleInstall`),E.t(`cmd.pluginInstallFailed`,{err:e.error??`未知错误`}))}catch(e){a||n.tui.info.showToast(E.t(`cmd.titleInstall`),E.t(`cmd.pluginInstallFailed`,{err:e instanceof Error?e.message:String(e)}))}if(!f)return a||n.tui.info.showToast(E.t(`cmd.titleInstall`),E.t(`cmd.pluginInstallNotFound`,{pkg:l})),!1;let g=p(f);if(!a&&!await I(e,g,n))return n.tui.info.showToast(E.t(`cmd.titleInstall`),E.t(`cmd.pluginInstallCancelled`)),!1;let _;if(m)_=m;else try{s?.(`Installing plugin`),_=await d({pkg:l})}catch(e){return a||n.tui.info.showToast(E.t(`cmd.titleInstall`),E.t(`cmd.pluginInstallFailed`,{err:e instanceof Error?e.message:String(e)})),!1}a||n.tui.info.showToast(E.t(`cmd.titleInstall`),E.t(`cmd.pluginInstalled`,{seg:_.created?`Installed ${_.id}`:`${_.id} already up to date`})),await h(n.app.settings,{id:_.id,source:`npm`,sourceSpec:l,version:_.version,scope:`global`,capabilities:g}),n.app.pluginModuleManager.emitMonitorEvent({type:`plugin.installed`,pluginId:_.id});for(let e of _.compileWarnings)a||n.tui.info.showToast(E.t(`cmd.titleInstall`),E.t(`cmd.pluginInstallFailed`,{err:e}));g.length>0&&(s?.(`Authorizing capabilities`),b(_.dir),u(_.dir,g));try{s?.(`Reloading capabilities`),(await n.app.reloadCapabilities()).pendingProviderCapabilities.includes(_.id)&&(a||n.tui.info.showToast(E.t(`cmd.titleInstall`),E.t(`cmd.pluginInstallPendingCaps`,{id:_.id})),c?.(_.id))}catch(e){a||n.tui.info.showToast(E.t(`cmd.titleInstall`),E.t(`cmd.compatReloadFailed`,{err:e instanceof Error?e.message:String(e)}))}if(await n.callbacks.refreshModelsNow().catch(()=>{}),e===`plugin-feishu-use`){try{let{launchFeishuSetup:e}=await import(`./feishu-setup-DIcd3PMK.js`);await e(n)}catch{}return!0}if(!a){await new Promise(e=>setImmediate(e));let{handleModel:e}=await import(`./model-auth-CQaQ5KuC.js`);await e([],n)}return!0}async function R(e,t){t.tui.panes.togglePane(`backgroundTasks`)}async function z(e,t){let n=e.join(` `);if(!n){t.tui.info.showToast(E.t(`cmd.titleJob`),E.t(`cmd.jobUsage`));return}let r=/^revert\s+(\S+)$/.exec(n);if(r){let e=r[1],n=t.app.agentJobs.revert(e);if(n.applied)t.tui.info.showToast(E.t(`cmd.titleReverted`),E.t(`cmd.jobReverted`,{id:e,msg:n.message}));else{let r=n.conflictPaths.length?E.t(`cmd.jobConflictFiles`,{joinedPaths:n.conflictPaths.join(`
6
+ `)}):``;t.tui.messages.pushMessage({role:`command_echo`,command:`/go revert ${e}`,status:`error`,summary:E.t(`cmd.jobRevertFailed`,{id:e,status:n.status,msg:n.message,conflicts:r})})}return}try{let e=t.app.agentJobs.start({title:n.slice(0,60),prompt:n,sessionId:t.state.session.id,origin:`user`});t.tui.info.showToast(E.t(`cmd.titleDelegated`),E.t(`cmd.delegated`,{title:e.title}))}catch(e){t.tui.messages.pushMessage({role:`command_echo`,command:`/go`,status:`error`,summary:E.t(`cmd.delegateFailed`,{err:e instanceof Error?e.message:String(e)})})}}async function B(t,r){let o=(e,t)=>r.tui.info.showToast(e,t),l=e=>r.tui.messages.pushMessage({role:`command_echo`,command:`/extension`,status:`error`,summary:e}),u=()=>{let e=r.app.extensions.list(),t=r.app.getGlobalMenuItems?.()??[],n=new Map(t.map(e=>[e.id,e.command]));r.tui.modal.openModal({kind:`extensionsList`,entries:e.map(e=>({category:e.category,id:e.id,name:e.name,enabled:e.enabled,description:e.description,applies:e.applies})),menuContributions:[{id:`__discover__`,title:`Discover plugins (search registries)…`},...t.map(e=>({id:e.id,title:e.title}))],onSelect:e=>{if(!e)return;if(e===`contrib:__discover__`){d();return}if(e.startsWith(`contrib:`)){let t=e.slice(8),i=n.get(t);if(!i)return;s(i,{open:e=>f(e),runCommand:async(e,t)=>{let{dispatchSlashCommand:n}=await import(`./command-dispatcher-ZigPcRaU.js`).then(e=>e.a);await n(e,t?t.split(/\s+/).filter(Boolean):[],r)}}).catch(e=>o(E.t(`cmd.titlePlugin`),e instanceof Error?e.message:String(e)));return}let t=e.indexOf(`:`);g(e.slice(0,t),e.slice(t+1))},onCancel:()=>{}})},d=async()=>{let e=await r.tui.modal.openModal({kind:`input`,title:`Discover plugins`,description:[`搜索已注册 registry(/registry list 查看源;/registry add 注册第三方源)`],placeholder:`keyword… (e.g. weather / oauth / provider)`});if(!e?.trim()){u();return}let{searchRegistries:t}=await import(`./registry-B3nfN62q.js`),{hits:n,warnings:i}=await t(r,e.trim());if(n.length===0){o(E.t(`cmd.titlePlugin`),`No registry entries match '${e.trim()}'${i.length?` (${i.length} source warning)`:``}`),u();return}r.tui.modal.openModal({kind:`select`,title:`Discover: '${e.trim()}' (${n.length})`,subtitle:i.length>0?`⚠ ${i.join(` · `)}`:void 0,options:n.map((e,t)=>({label:`${e.entry.id} (${e.entry.type}) [${(e.entry.capabilities??[]).join(`, `)||`-`}] @${e.sourceName}${e.stale?` (stale)`:``}`,description:e.entry.description,value:String(t)})),onSelect:e=>{let t=n[Number(e)];if(!t)return;let i=[`--as`,t.entry.type,...t.entry.subPath?[`--sub-path`,t.entry.subPath]:[],t.entry.source];(async()=>{let{dispatchSlashCommand:e}=await import(`./command-dispatcher-ZigPcRaU.js`).then(e=>e.a);await e(`install`,i,r)})().catch(e=>o(E.t(`cmd.titlePlugin`),e instanceof Error?e.message:String(e)))},onCancel:()=>u()})},p=e=>{let t=r.app.skillRegistry?.get(e);if(!t){u();return}let n=t.status!==`disabled`,i=t.definition.metadata,a=[{kind:`group`,title:E.t(`cmd.extSkillGroupOverview`)},{kind:`row`,label:E.t(`cmd.extSkillLabelDesc`),value:i.description||`—`},{kind:`row`,label:E.t(`cmd.extSkillLabelStatus`),value:t.status,tone:t.status===`error`||t.status===`disabled`?`error`:`success`},{kind:`row`,label:E.t(`cmd.extSkillLabelSource`),value:E.t(`cmd.extSkillSourceLabel`,{seg:M(t.source.type,t.source.id)}),tone:`muted`},{kind:`group`,title:E.t(`cmd.extSkillGroupTrigger`)},{kind:`row`,label:E.t(`cmd.extSkillLabelTriggerMode`),value:i.trigger===`manual`?E.t(`cmd.extSkillTriggerManual`):E.t(`cmd.extSkillTriggerAuto`)},...i.priority===void 0?[]:[{kind:`row`,label:E.t(`cmd.extSkillLabelPriority`),value:String(i.priority)}],{kind:`group`,title:E.t(`cmd.extSkillGroupDependencies`)},{kind:`row`,label:E.t(`cmd.extSkillLabelDependencies`),value:i.dependencies?.length?i.dependencies.join(`, `):E.t(`cmd.extSkillNoDependencies`),tone:i.dependencies?.length?void 0:`muted`},{kind:`group`,title:E.t(`cmd.extSkillGroupTags`)},{kind:`row`,label:E.t(`cmd.extSkillLabelTags`),value:i.tags?.length?i.tags.join(`, `):E.t(`cmd.extSkillNoTags`),tone:i.tags?.length?void 0:`muted`}];t.status===`error`&&t.error&&a.push({kind:`group`,title:E.t(`cmd.extSkillGroupError`)},{kind:`text`,value:t.error,tone:`error`}),r.tui.modal.openModal({kind:`extensionDetail`,title:E.t(`cmd.extSkillTitle`,{name:e,state:n?`enabled`:`disabled`}),meta:`skill · ${t.source.type}`,metaStatus:{label:n?E.t(`cmd.extEnableLabel`):E.t(`cmd.extDisableLabel`),enabled:n},actions:[{label:n?E.t(`cmd.extDisableLabel`):E.t(`cmd.extEnableLabel`),value:`toggle`,color:n?`amber`:`green`},{label:E.t(`cmd.extViewFullTextLabel`),value:`view-full-text`,color:`gray`},...j(t.source.type)?[{label:E.t(`cmd.uninstallActionLabel`),value:`uninstall`,color:`red`}]:[]],dataListEntries:a,fullText:{title:E.t(`cmd.extSkillFullTextTitle`,{name:e}),content:t.definition.body||E.t(`cmd.extSkillNoBody`)},onAction:async i=>{if(i===`toggle`){try{await r.app.extensions.setEnabled(`skill`,e,!n),o(E.t(`cmd.titleExtension`),E.t(`cmd.extToggled`,{name:e,verb:n?`Disabled`:`Enabled`,seg:` — applies next turn`}))}catch(e){l(E.t(`cmd.extToggleFailed`,{err:e instanceof Error?e.message:String(e)}))}p(e);return}if(i===`uninstall`){let n=j(t.source.type);if(!n)return;await k({name:e,type:`skill`,scope:n,ctx:r,onDone:()=>u()})}},onClose:()=>u()})},h=e=>{let t=r.app.declarativeAgentProfiles.find(t=>t.name===e);if(!t){u();return}let n=!new Set(r.app.settings.get(`disabled_agents`)??[]).has(e),i=[{kind:`group`,title:E.t(`cmd.extAgentGroupOverview`)},{kind:`row`,label:E.t(`cmd.extAgentLabelDesc`),value:t.description||`—`},{kind:`row`,label:E.t(`cmd.extAgentLabelStatus`),value:n?E.t(`cmd.extEnableLabel`):E.t(`cmd.extDisableLabel`),tone:n?`success`:`error`},{kind:`group`,title:E.t(`cmd.extAgentGroupCapabilities`)},{kind:`row`,label:E.t(`cmd.extAgentLabelTaskTypes`),value:t.taskTypes.length?t.taskTypes.join(`, `):E.t(`cmd.extAgentNoTaskTypes`),tone:t.taskTypes.length?void 0:`muted`},{kind:`row`,label:E.t(`cmd.extAgentLabelCapabilities`),value:t.capabilities.length?t.capabilities.join(`, `):E.t(`cmd.extAgentNoCapabilities`),tone:t.capabilities.length?void 0:`muted`},{kind:`group`,title:E.t(`cmd.extAgentGroupTools`)},{kind:`row`,label:E.t(`cmd.extAgentLabelDefaultTools`),value:t.defaultTools?.length?t.defaultTools.join(`, `):E.t(`cmd.extAgentAllTools`),tone:t.defaultTools?.length?void 0:`muted`},{kind:`row`,label:E.t(`cmd.extAgentLabelDisallowedTools`),value:t.disallowedTools?.length?t.disallowedTools.join(`, `):E.t(`cmd.extAgentNoDisallowedTools`),tone:t.disallowedTools?.length?void 0:`muted`},{kind:`group`,title:E.t(`cmd.extAgentGroupExecution`)},{kind:`row`,label:E.t(`cmd.extAgentLabelPromptMode`),value:t.promptMode??`append`,tone:`muted`},...t.preferredModelTier?[{kind:`row`,label:E.t(`cmd.extAgentLabelModelTier`),value:t.preferredModelTier}]:[],{kind:`row`,label:E.t(`cmd.extAgentLabelAllowSubagents`),value:t.allowSubagents?E.t(`cmd.extEnableLabel`):E.t(`cmd.extDisableLabel`),tone:t.allowSubagents?void 0:`muted`}];r.tui.modal.openModal({kind:`extensionDetail`,title:E.t(`cmd.extAgentTitle`,{name:e,state:n?`enabled`:`disabled`}),meta:`agent`,metaStatus:{label:n?E.t(`cmd.extEnableLabel`):E.t(`cmd.extDisableLabel`),enabled:n},actions:[{label:n?E.t(`cmd.extDisableLabel`):E.t(`cmd.extEnableLabel`),value:`toggle`,color:n?`amber`:`green`},{label:E.t(`cmd.extViewFullTextLabel`),value:`view-full-text`,color:`gray`}],dataListEntries:i,fullText:{title:E.t(`cmd.extAgentFullTextTitle`,{name:e}),content:t.systemPromptTemplate||E.t(`cmd.extSkillNoBody`)},onAction:async t=>{if(t===`toggle`){try{await r.app.extensions.setEnabled(`agent`,e,!n),o(E.t(`cmd.titleExtension`),E.t(`cmd.extToggled`,{name:e,verb:n?`Disabled`:`Enabled`,seg:` — applies next turn`}))}catch(e){l(E.t(`cmd.extToggleFailed`,{err:e instanceof Error?e.message:String(e)}))}h(e)}},onClose:()=>u()})},g=(e,t)=>{let n=r.app.extensions.list().find(n=>n.category===e&&n.id===t);if(!n){u();return}let i={label:n.enabled?E.t(`cmd.extDisableLabel`):E.t(`cmd.extEnableLabel`),value:`toggle`};if(e===`mcp`){let a=r.app.mcpManager?.getServerInfos().find(e=>e.name===t),s=n.enabled?a?String(a.status):`disconnected`:`disabled`;r.tui.modal.openModal({kind:`select`,title:E.t(`cmd.extMcpTitle`,{name:n.name,status:s}),options:[{label:E.t(`cmd.extReconnectLabel`),value:`reconnect`},i,...n.readonly?[]:[{label:E.t(`cmd.uninstallActionLabel`),value:`uninstall`}]],onSelect:async i=>{if(i===`toggle`){try{await r.app.extensions.setEnabled(n.category,t,!n.enabled),o(E.t(`cmd.titleExtension`),E.t(`cmd.extToggled`,{name:n.name,verb:n.enabled?`Disabled`:`Enabled`,seg:``}))}catch(e){l(E.t(`cmd.extToggleFailed`,{err:e instanceof Error?e.message:String(e)}))}g(e,t);return}if(i===`reconnect`){let n=r.app.mcpManager,i=(r.app.settings.get(`mcp_servers`)??{})[t];if(!n||!i){o(E.t(`cmd.titleExtension`),E.t(`cmd.extReconnectUnavailable`,{id:t})),g(e,t);return}try{await n.disconnect(t).catch(()=>{}),await n.connect(t,i),o(E.t(`cmd.titleExtension`),E.t(`cmd.extReconnected`,{id:t}))}catch(e){l(E.t(`cmd.extReconnectFailed`,{id:t,err:e instanceof Error?e.message:String(e)}))}g(e,t);return}if(i===`uninstall`){await k({name:t,type:`mcp`,scope:`project`,ctx:r,onDone:()=>u()});return}},onCancel:()=>u()})}else e===`plugin`?v(t,n.enabled,n.name,n.description):e===`skill`?p(t):e===`agent`?h(t):r.tui.modal.openModal({kind:`select`,title:E.t(`cmd.extItemTitle`,{name:n.name}),options:[i],onSelect:async i=>{if(i===`toggle`){try{await r.app.extensions.setEnabled(n.category,t,!n.enabled),o(E.t(`cmd.titleExtension`),E.t(`cmd.extToggled`,{name:n.name,verb:n.enabled?`Disabled`:`Enabled`,seg:n.applies===`live`?``:` — applies next turn`}))}catch(e){l(E.t(`cmd.extToggleFailed`,{err:e instanceof Error?e.message:String(e)}))}g(e,t);return}},onCancel:()=>u()})},v=(t,d,p,h,g)=>{let b=r.app.workspaceDir??process.cwd(),x=e({cwd:b,homedir:n()}).find(e=>e.id===t);if(!x){u();return}let D=c(x),O=D.surface.any?D.gated?E.t(`cmd.extPluginUntrusted`):D.pendingCapabilities.length>0?E.t(`cmd.extPluginCapabilityPending`,{caps:D.pendingCapabilities.join(`, `)}):E.t(`cmd.extPluginTrusted`):E.t(`cmd.extPluginNoSurface`),A=D.surface,j=[[A.mcpJson,`mcp`],[A.commands,`commands`],[A.scripts,`scripts`],[A.panels,`panels`],[A.skills,`skills`],[A.agents,`agents`]].filter(([e])=>e).map(([,e])=>e),M=j.length?` ${j.join(`, `)}`:` —`,P=(r.app.getPluginPanelRegistrations?.()??[]).filter(e=>e.pluginId===t),I=N({providerApis:r.app.providerRegistry.getApisBySource(t).length,tools:r.app.toolRegistry.getAll().filter(e=>e.metadata.source===t).length,renderers:r.app.getPluginRenderers().filter(e=>e.pluginId===t).length,statusItems:r.app.getPluginStatusItems().filter(e=>e.id.startsWith(`${t}:`)).length,fileViewers:(r.app.getPluginFileViewers?.()??[]).filter(e=>e.pluginId===t).length}),L=x.scope===`builtin`?[]:[{label:d?E.t(`cmd.extDisableLabel`):E.t(`cmd.extEnableLabel`),value:`toggle`,color:d?`amber`:`green`}];if(D.surface.any&&(x.scope===`project`||x.scope===`repository`||D.pendingCapabilities.length>0)){let e=x.scope===`project`||x.scope===`repository`?!D.trusted:D.pendingCapabilities.length>0;L.push({label:e?E.t(`cmd.extPluginTrustLabel`):E.t(`cmd.extPluginUntrustLabel`),value:e?`trust`:`untrust`,color:e?`accent`:`gray`})}L.push({label:E.t(`cmd.extReloadLabel`),value:`reload`}),x.scope!==`builtin`&&L.push({label:E.t(`cmd.uninstallActionLabel`),value:`uninstall`,color:`red`});let R=a(x,{"extension.id":t,"extension.enabled":d,"extension.trusted":D.trusted,"extension.scope":x.scope,"extension.category":`plugin`}),z=x.manifest.contributes,B=_(i.extensionDetailActions,z?.menus,z?.actions,R),V=new Map(B.map(e=>[e.id,e.command]));for(let e of B){let t=`${x.id}:action.${e.id}.title`,n=r.app.i18nRegistry.t(t),i=n===t?e.title:n;L.push({label:i,value:`contrib:${e.id}`,color:e.color})}let H={open:e=>f(e),runCommand:async(e,t)=>{let{dispatchSlashCommand:n}=await import(`./command-dispatcher-ZigPcRaU.js`).then(e=>e.a);await n(e,t?t.split(/\s+/).filter(Boolean):[],r)},runScript:async e=>{if(c(x).gated){o(E.t(`cmd.titlePlugin`),E.t(`cmd.extPluginUntrusted`));return}await y(x,e)}},U=P[0];U&&r.app.firePluginActivationEvent?.(`onView:${U.id}`);let W;if(t===`plugin-feishu-use`){let e=C(b,`.otto`,`feishu-use.json`),t=!1;try{if(w(e)){let n=JSON.parse(T(e,`utf8`));if(n.app_id){t=!0;let r=typeof n.app_id==`string`&&n.app_id.length>12?n.app_id.slice(0,8)+`***`+n.app_id.slice(-4):String(n.app_id),i=Array.isArray(n.allowed_chats)?n.allowed_chats.length:0,a=Array.isArray(n.trusted_chats)?n.trusted_chats.length:0,o=x.scope===`user`?`全局`:x.scope===`repository`?`仓库`:`项目`;W=[{kind:`row`,label:`App ID`,value:r},{kind:`row`,label:`消息白名单`,value:i>0?`${i} 个`:`空 — 拒绝所有消息`,tone:i>0?void 0:`warning`},...a>0?[{kind:`row`,label:`可信任 chat`,value:`${a} 个`}]:[],{kind:`row`,label:`配置`,value:`${o}级 · ${e}`,tone:`muted`}]}}}catch{}t||(W=[{kind:`text`,value:`未配置 — 点击 [重新配置] 引导设置`,tone:`warning`},{kind:`row`,label:`预期配置路径`,value:e,tone:`muted`}]),L.push({label:`重新配置`,value:`feishu-reconfigure`,color:`amber`})}let G=()=>{let e=r.app.pluginHealthTracker?.query(t)??{hookTimeouts:0,toolTimeouts:0},n=m(t);return{healthStats:{hookTimeouts:e.hookTimeouts,toolTimeouts:e.toolTimeouts,lastError:e.lastError},logEntries:n.map(e=>({ts:e.ts,level:e.level,msg:e.msg}))}},K=[{kind:`group`,title:E.t(`cmd.extPluginGroupTitle`)},{kind:`row`,label:E.t(`cmd.extPluginLabelDesc`),value:h},{kind:`row`,label:E.t(`cmd.extPluginLabelScope`),value:x.scope},{kind:`row`,label:E.t(`cmd.extPluginLabelTrust`),value:O},{kind:`row`,label:E.t(`cmd.extPluginLabelSurfaces`),value:M.trim()||`—`},...I?[{kind:`row`,label:E.t(`cmd.extPluginLabelContributions`),value:I}]:[],{kind:`row`,label:E.t(`cmd.extPluginLabelStatus`),value:d?E.t(`cmd.extEnableLabel`):E.t(`cmd.extDisableLabel`),tone:d?`success`:`error`}],q=g?[{kind:`text`,value:g.message,tone:g.kind===`success`?`success`:`error`}]:[];r.tui.modal.openModal({kind:`extensionDetail`,title:E.t(`cmd.extPluginTitle`,{name:p,state:d?`enabled`:`disabled`}),meta:`plugin · ${x.scope}`,metaStatus:{label:d?E.t(`cmd.extEnableLabel`):E.t(`cmd.extDisableLabel`),enabled:d},metaSuffix:O,actions:L,panelInfo:U?{title:U.title,modulePath:U.modulePath,exportName:U.exportName,pluginId:t}:void 0,dataListEntries:[...q,...W??K],...G(),onRefresh:()=>v(t,d,p,h),onAction:async e=>{if(e.startsWith(`contrib:`)){let n=V.get(e.slice(8));if(n)try{await s(n,H)}catch(e){l(E.t(`cmd.extToggleFailed`,{err:e instanceof Error?e.message:String(e)}))}v(t,d,p,h)}else if(e===`trust`)F(r,x);else if(e===`untrust`){try{S(x.dir)}catch(e){v(t,d,p,h,{kind:`error`,message:`撤销信任失败,权限未收回:${e instanceof Error?e.message:String(e)}`});return}r.app.reloadCapabilities?.().then(()=>{r.tui.plugins.setPluginRegistrations(r.app.getPluginRegistrations())}).finally(()=>{v(t,d,p,h,{kind:`success`,message:E.t(`cmd.pluginUntrusted`,{id:t})})})}else if(e===`toggle`)try{await r.app.extensions.setEnabled(`plugin`,t,!d);try{await r.app.reloadCapabilities(),v(t,!d,p,h,{kind:`success`,message:E.t(`cmd.extToggled`,{name:p,verb:d?`Disabled`:`Enabled`,seg:``})})}catch(e){v(t,!d,p,h,{kind:`error`,message:E.t(`cmd.extToggleReloadFailed`,{verb:d?`Disabled`:`Enabled`,name:p,err:e instanceof Error?e.message:String(e)})})}}catch(e){v(t,d,p,h,{kind:`error`,message:E.t(`cmd.extToggleFailed`,{err:e instanceof Error?e.message:String(e)})})}else if(e===`feishu-reconfigure`)try{let{launchFeishuSetup:e}=await import(`./feishu-setup-DIcd3PMK.js`);await e(r),o(`plugin-feishu-use`,`配置完成。`)}catch(e){l(`feishu-use 配置向导失败:${e instanceof Error?e.message:String(e)}`)}else e===`reload`?r.app.reloadCapabilities?.().then(e=>{v(t,d,p,h,{kind:`success`,message:E.t(`cmd.pluginTrusted`,{id:t,count:e.mcpTools})})}).catch(e=>{v(t,d,p,h,{kind:`error`,message:E.t(`cmd.compatReloadFailed`,{err:e instanceof Error?e.message:String(e)})})}):e===`uninstall`&&await k({name:t,type:`plugin`,scope:x.scope===`project`||x.scope===`repository`?x.scope:`global`,ctx:r,onDone:()=>u()})},onClose:()=>u()})};u()}export{z as a,L as c,B as i,N as n,P as o,R as r,F as s,I as t};
7
+ //# sourceMappingURL=extension-plugin-D76MKjOB.js.map