@eworkbase/plugin-ai-rules 0.3.4 → 0.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/plugin.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { createRequire } from "node:module";
2
- import { existsSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, realpathSync, rmSync, writeFileSync } from "node:fs";
2
+ import { existsSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, realpathSync, rmSync, rmdirSync, writeFileSync } from "node:fs";
3
3
  import path from "node:path";
4
4
  import os from "node:os";
5
5
  import { isDeepStrictEqual } from "node:util";
@@ -7840,9 +7840,10 @@ function stringify(obj, { maxDepth = 1e3, numbersAsFloat = false } = {}) {
7840
7840
  }
7841
7841
  //#endregion
7842
7842
  //#region src/injection-writer.ts
7843
- /** 合并客户端注入片段,按实际拥有的变化撤销,并保护路径和并发用户修改。 */
7843
+ /** 安全读写规则资源与客户端片段,清理空 Skill 目录并保护并发用户修改。 */
7844
7844
  const BLOCK_START = "<!-- WORKBASE_INJECT_START -->";
7845
7845
  const BLOCK_END = "<!-- WORKBASE_INJECT_END -->";
7846
+ const SKILLS_DIRECTORY = "skills";
7846
7847
  const INSTRUCTION_FILES = /* @__PURE__ */ new Set(["AGENTS.md", "CLAUDE.md"]);
7847
7848
  const JSON_EXTENSIONS = /* @__PURE__ */ new Set([".json", ".jsonc"]);
7848
7849
  const MAXIMUM_FILE_BYTES = 4194304;
@@ -7991,6 +7992,7 @@ function writeSafeFile({ root, relativePath, content }) {
7991
7992
  const filePath = safeFilePath(root, relativePath);
7992
7993
  if (content === null) {
7993
7994
  rmSync(filePath, { force: true });
7995
+ removeEmptySkillDirectories(root, relativePath);
7994
7996
  return;
7995
7997
  }
7996
7998
  mkdirSync(path.dirname(filePath), { recursive: true });
@@ -8000,6 +8002,16 @@ function writeSafeFile({ root, relativePath, content }) {
8000
8002
  mode: 384
8001
8003
  });
8002
8004
  }
8005
+ function removeEmptySkillDirectories(root, relativePath) {
8006
+ const segments = relativePath.split("/");
8007
+ const skillDirectoryIndex = segments.indexOf(SKILLS_DIRECTORY) + 1;
8008
+ if (skillDirectoryIndex === 0) return;
8009
+ for (let depth = segments.length - 1; depth > skillDirectoryIndex; depth -= 1) {
8010
+ const directory = safeFilePath(root, segments.slice(0, depth).join("/"));
8011
+ if (!lstatSync(directory, { throwIfNoEntry: false })?.isDirectory() || readdirSync(directory).length > 0) return;
8012
+ rmdirSync(directory);
8013
+ }
8014
+ }
8003
8015
  function mergeContent({ relativePath, before, fragment }) {
8004
8016
  if (isStructured(relativePath)) {
8005
8017
  const merged = mergeDocument(parseDocument$1(relativePath, before ?? ""), parseDocument$1(relativePath, fragment));
@@ -8083,7 +8095,7 @@ function restoreDocument({ location, original, applied, current, requireApplied
8083
8095
  }
8084
8096
  function isStructured(relativePath) {
8085
8097
  if (relativePath.split("/").some((segment) => [
8086
- "skills",
8098
+ SKILLS_DIRECTORY,
8087
8099
  "commands",
8088
8100
  "agents"
8089
8101
  ].includes(segment))) return false;
@@ -15678,7 +15690,7 @@ const CONFIGURATION_INPUT_SCHEMA = object({
15678
15690
  }).strict();
15679
15691
  var plugin_default = definePlugin({
15680
15692
  id: "ai-rules",
15681
- title: "AI Rules",
15693
+ title: "AI 规则",
15682
15694
  setup(context, hooks) {
15683
15695
  registerResources(context, hooks);
15684
15696
  const rulesRoot = path.join(context.project.root, RULES_DIRECTORY);
@@ -5,7 +5,7 @@
5
5
  <meta charset="UTF-8" />
6
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
7
  <link rel="stylesheet" href="./style.css" />
8
- <title>AI Rules</title>
8
+ <title>AI 规则</title>
9
9
  </head>
10
10
  <body>
11
11
  <div id="root"></div>
package/dist/ui/main.js CHANGED
@@ -1,4 +1,4 @@
1
- var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),s=(e,n)=>{let r={};for(var i in e)t(r,i,{get:e[i],enumerable:!0});return n||t(r,Symbol.toStringTag,{value:`Module`}),r},c=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},l=(n,r,o)=>(o=n==null?{}:e(i(n)),c(r||!n||!n.__esModule||!a.call(n,`default`)?t(o,`default`,{value:n,enumerable:!0}):o,n));function u(){Object.assign(window,{__webpack_nonce__:d()})}function d(){return document.querySelector(`meta[name="workbase-style-nonce"]`)?.content??``}const f={black:`#342f28`,primaryColor:`workbase`,primaryShade:4,autoContrast:!0,defaultRadius:`md`,radius:{xs:`0.25rem`,sm:`0.25rem`,md:`0.375rem`,lg:`0.5rem`,xl:`0.75rem`},fontFamily:`Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif`,fontSizes:{xs:`0.75rem`,sm:`0.875rem`,md:`0.875rem`,lg:`1rem`,xl:`1.25rem`},colors:{workbase:[`#fffde8`,`#fff7bf`,`#ffef94`,`#ffe76a`,`#ffde39`,`#ffca00`,`#d5a900`,`#aa8200`,`#805f00`,`#502e00`],gray:[`#faf9f5`,`#f3f2ed`,`#e2dfd6`,`#c9c4b8`,`#aaa49a`,`#756f66`,`#6c675f`,`#514b41`,`#342f28`,`#211d17`],red:[`#fff4ef`,`#f8ebe7`,`#f7b49a`,`#dc7756`,`#b9360a`,`#a52f09`,`#902908`,`#772207`,`#601b06`,`#491505`],teal:[`#eef9f7`,`#eaf5f4`,`#a2d8d0`,`#51aca2`,`#087c75`,`#076e68`,`#06615b`,`#05514c`,`#04423e`,`#033330`],orange:[`#fff7e9`,`#f5eee6`,`#e9c98b`,`#c4913d`,`#9a5600`,`#894d00`,`#784300`,`#643800`,`#522e00`,`#3f2300`],blue:[`#f0f7ff`,`#ebf3fc`,`#a6ccfa`,`#599be9`,`#0969da`,`#085ec2`,`#0752aa`,`#06458e`,`#053974`,`#042b59`]},components:{Badge:{defaultProps:{radius:`md`},classNames:m},Button:{defaultProps:{size:`sm`},classNames:p},ActionIcon:{classNames:p},Accordion:{defaultProps:{chevronSize:14}},Modal:{defaultProps:{radius:`xl`}}},headings:{fontWeight:`600`},respectReducedMotion:!0};function p(e,{color:t}){return{root:!t||t===`workbase`?`workbase-brand-control`:void 0}}function m(e,t){let{color:n,variant:r}=t;return r===`light`&&n&&[`teal`,`orange`,`red`,`blue`,`gray`].includes(n)?{root:`workbase-status-badge workbase-status-${n}`}:p(e,t)}function h(e){return Object.keys(e)}function g(e){return e&&typeof e==`object`&&!Array.isArray(e)}function _(e,t){let n={...e},r=t;return g(e)&&g(t)&&Object.keys(t).forEach(t=>{g(r[t])&&t in e?n[t]=_(n[t],r[t]):n[t]=r[t]}),n}function v(e){return e.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`)}function y(e){return typeof e!=`string`||!e.includes(`var(--mantine-scale)`)?e:e.match(/^calc\((.*?)\)$/)?.[1].split(`*`)[0].trim()}function b(e){let t=y(e);return typeof t==`number`?t:typeof t==`string`?t.includes(`calc`)||t.includes(`var`)?t:t.includes(`px`)?Number(t.replace(`px`,``)):t.includes(`rem`)?Number(t.replace(`rem`,``))*16:t.includes(`em`)?Number(t.replace(`em`,``))*16:Number(t):NaN}function x(e){return e===`0rem`?`0rem`:`calc(${e} * var(--mantine-scale))`}function S(e,{shouldScale:t=!1}={}){function n(r){if(r===0||r===`0`)return`0${e}`;if(typeof r==`number`){let n=`${r/16}${e}`;return t?x(n):n}if(typeof r==`string`){if(r===``||r.startsWith(`calc(`)||r.startsWith(`clamp(`)||r.includes(`rgba(`))return r;if(r.includes(`,`))return r.split(`,`).map(e=>n(e)).join(`,`);if(r.includes(` `))return r.split(` `).map(e=>n(e)).join(` `);let i=r.replace(`px`,``);if(!Number.isNaN(Number(i))){let n=`${Number(i)/16}${e}`;return t?x(n):n}}return r}return n}const C=S(`rem`,{shouldScale:!0}),w=S(`em`);function T(e){return Object.keys(e).reduce((t,n)=>(e[n]!==void 0&&(t[n]=e[n]),t),{})}function E(e){if(typeof e==`number`)return!0;if(typeof e==`string`){if(e.startsWith(`calc(`)||e.startsWith(`var(`)||e.includes(` `)&&e.trim()!==``)return!0;let t=/^[+-]?[0-9]+(\.[0-9]+)?(px|em|rem|ex|ch|lh|rlh|vw|vh|vmin|vmax|vb|vi|svw|svh|lvw|lvh|dvw|dvh|cm|mm|in|pt|pc|q|cqw|cqh|cqi|cqb|cqmin|cqmax|%)?$/;return e.trim().split(/\s+/).every(e=>t.test(e))}return!1}
1
+ var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),s=(e,n)=>{let r={};for(var i in e)t(r,i,{get:e[i],enumerable:!0});return n||t(r,Symbol.toStringTag,{value:`Module`}),r},c=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},l=(n,r,o)=>(o=n==null?{}:e(i(n)),c(r||!n||!n.__esModule||!a.call(n,`default`)?t(o,`default`,{value:n,enumerable:!0}):o,n));function u(){document.documentElement.setAttribute(`autocapitalize`,`none`),Object.assign(window,{__webpack_nonce__:d()})}function d(){return document.querySelector(`meta[name="workbase-style-nonce"]`)?.content??``}const f={black:`#342f28`,primaryColor:`workbase`,primaryShade:4,autoContrast:!0,defaultRadius:`md`,radius:{xs:`0.25rem`,sm:`0.25rem`,md:`0.375rem`,lg:`0.5rem`,xl:`0.75rem`},fontFamily:`Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif`,fontSizes:{xs:`0.75rem`,sm:`0.875rem`,md:`0.875rem`,lg:`1rem`,xl:`1.25rem`},colors:{workbase:[`#fffde8`,`#fff7bf`,`#ffef94`,`#ffe76a`,`#ffde39`,`#ffca00`,`#d5a900`,`#aa8200`,`#805f00`,`#502e00`],gray:[`#faf9f5`,`#f3f2ed`,`#e2dfd6`,`#c9c4b8`,`#aaa49a`,`#756f66`,`#6c675f`,`#514b41`,`#342f28`,`#211d17`],red:[`#fff4ef`,`#f8ebe7`,`#f7b49a`,`#dc7756`,`#b9360a`,`#a52f09`,`#902908`,`#772207`,`#601b06`,`#491505`],teal:[`#eef9f7`,`#eaf5f4`,`#a2d8d0`,`#51aca2`,`#087c75`,`#076e68`,`#06615b`,`#05514c`,`#04423e`,`#033330`],orange:[`#fff7e9`,`#f5eee6`,`#e9c98b`,`#c4913d`,`#9a5600`,`#894d00`,`#784300`,`#643800`,`#522e00`,`#3f2300`],blue:[`#f0f7ff`,`#ebf3fc`,`#a6ccfa`,`#599be9`,`#0969da`,`#085ec2`,`#0752aa`,`#06458e`,`#053974`,`#042b59`]},components:{Input:{defaultProps:{autoCapitalize:`none`}},Textarea:{defaultProps:{autoCapitalize:`none`}},Badge:{defaultProps:{radius:`md`},classNames:m},Button:{defaultProps:{size:`sm`},classNames:p},ActionIcon:{classNames:p},Accordion:{defaultProps:{chevronSize:14}},Modal:{defaultProps:{radius:`xl`}}},headings:{fontWeight:`600`},respectReducedMotion:!0};function p(e,{color:t}){return{root:!t||t===`workbase`?`workbase-brand-control`:void 0}}function m(e,t){let{color:n,variant:r}=t;return r===`light`&&n&&[`teal`,`orange`,`red`,`blue`,`gray`].includes(n)?{root:`workbase-status-badge workbase-status-${n}`}:p(e,t)}function h(e){return Object.keys(e)}function g(e){return e&&typeof e==`object`&&!Array.isArray(e)}function _(e,t){let n={...e},r=t;return g(e)&&g(t)&&Object.keys(t).forEach(t=>{g(r[t])&&t in e?n[t]=_(n[t],r[t]):n[t]=r[t]}),n}function v(e){return e.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`)}function y(e){return typeof e!=`string`||!e.includes(`var(--mantine-scale)`)?e:e.match(/^calc\((.*?)\)$/)?.[1].split(`*`)[0].trim()}function b(e){let t=y(e);return typeof t==`number`?t:typeof t==`string`?t.includes(`calc`)||t.includes(`var`)?t:t.includes(`px`)?Number(t.replace(`px`,``)):t.includes(`rem`)?Number(t.replace(`rem`,``))*16:t.includes(`em`)?Number(t.replace(`em`,``))*16:Number(t):NaN}function x(e){return e===`0rem`?`0rem`:`calc(${e} * var(--mantine-scale))`}function S(e,{shouldScale:t=!1}={}){function n(r){if(r===0||r===`0`)return`0${e}`;if(typeof r==`number`){let n=`${r/16}${e}`;return t?x(n):n}if(typeof r==`string`){if(r===``||r.startsWith(`calc(`)||r.startsWith(`clamp(`)||r.includes(`rgba(`))return r;if(r.includes(`,`))return r.split(`,`).map(e=>n(e)).join(`,`);if(r.includes(` `))return r.split(` `).map(e=>n(e)).join(` `);let i=r.replace(`px`,``);if(!Number.isNaN(Number(i))){let n=`${Number(i)/16}${e}`;return t?x(n):n}}return r}return n}const C=S(`rem`,{shouldScale:!0}),w=S(`em`);function T(e){return Object.keys(e).reduce((t,n)=>(e[n]!==void 0&&(t[n]=e[n]),t),{})}function E(e){if(typeof e==`number`)return!0;if(typeof e==`string`){if(e.startsWith(`calc(`)||e.startsWith(`var(`)||e.includes(` `)&&e.trim()!==``)return!0;let t=/^[+-]?[0-9]+(\.[0-9]+)?(px|em|rem|ex|ch|lh|rlh|vw|vh|vmin|vmax|vb|vi|svw|svh|lvw|lvh|dvw|dvh|cm|mm|in|pt|pc|q|cqw|cqh|cqi|cqb|cqmin|cqmax|%)?$/;return e.trim().split(/\s+/).every(e=>t.test(e))}return!1}
2
2
  /**
3
3
  * @license React
4
4
  * react.production.js
@@ -195,4 +195,4 @@ targets: ["*"]
195
195
  description: 描述适用场景
196
196
  ---
197
197
 
198
- `}function gT(e,t){if(e.kind===`mcp`)return`server.json`;if(e.kind!==`skills`)return`rules/.rulesync/${e.kind}/${e.id}.md`;let n=t?t.split(`/`).slice(4).join(`/`):`SKILL.md`;return`rules/.rulesync/skills/${e.id}/${n}`}function _T(e){try{let t=JSON.parse(e??`{}`);return t&&typeof t==`object`&&!Array.isArray(t)?t:null}catch{return null}}const vT=new Map([[`rules`,`Rules`],[`skills`,`Skills`],[`mcp`,`MCP`],[`commands`,`Commands`],[`subagents`,`Subagents`]]),yT=(0,O.memo)(function({host:e,isActive:t,workspaceId:n}){let{catalog:r,kind:i,selected:a,draft:o,mode:s,error:c,message:l,isBusy:u,isRefreshing:d,isReading:f,query:p,isSourceView:m,isEditing:h,refresh:g,handleOpen:_,handleKind:v,handleCreate:y,handleEdit:b,handleCancel:x,handleId:S,handleFile:C,handleSearch:w,handleSourceView:T,handleContent:E,handleMcpField:ee,handleImport:D,handleSave:O,handleDelete:k,handleWorkflows:A,resource:j,file:M,server:N,visibleItems:P,isMarkdown:F,fileName:I}=mT({host:e,isActive:t,workspaceId:n});return(0,z.jsxs)(`section`,{className:`configuration-manager`,"data-editing":h,"aria-label":`AI 资源配置`,children:[(0,z.jsxs)(`header`,{className:`configuration-navigation`,children:[(0,z.jsx)(`nav`,{className:`configuration-tabs`,"aria-label":`资源类型`,children:[...vT].map(([e,t])=>(0,z.jsxs)(`button`,{type:`button`,value:e,"aria-pressed":i===e,disabled:h||u,onClick:v,children:[t,(0,z.jsx)(`span`,{"aria-hidden":`true`,children:r?.resources.filter(t=>t.kind===e).length??0})]},e))}),(0,z.jsx)(qo,{variant:`subtle`,color:`gray`,size:`compact-sm`,loading:d,disabled:u,onClick:g,children:`刷新列表`})]}),c&&!h&&(0,z.jsxs)(po,{color:`red`,role:`alert`,children:[c,` `,(0,z.jsx)(qo,{variant:`subtle`,onClick:A,children:`查看工作流关联`})]}),l&&(0,z.jsx)(`p`,{className:`configuration-feedback`,role:`status`,children:l}),(0,z.jsxs)(`div`,{className:`configuration-resource-grid`,children:[(0,z.jsxs)(`aside`,{className:`configuration-list`,"aria-label":`资源目录`,children:[(0,z.jsxs)(`div`,{className:`configuration-list-heading`,children:[(0,z.jsx)(`h2`,{children:`资源目录`}),(0,z.jsx)(qo,{size:`compact-sm`,variant:`default`,disabled:h||u||f,onClick:y,children:`新增`})]}),(0,z.jsx)(`input`,{className:`configuration-search`,type:`search`,"aria-label":`搜索资源`,placeholder:`搜索资源名称…`,value:p,onChange:w,disabled:h}),(0,z.jsxs)(`div`,{className:`configuration-items`,children:[!r&&(0,z.jsx)(`p`,{className:`configuration-notice`,role:`status`,children:c?`资源尚未读取`:`正在读取资源…`}),r&&!P.length&&(0,z.jsx)(`p`,{className:`configuration-notice`,children:p?`没有匹配的资源,试试其他名称。`:`还没有资源,从新增开始。`}),P.map(e=>(0,z.jsxs)(`button`,{type:`button`,className:`configuration-row`,"data-id":e.id,"aria-current":a?.id===e.id?`true`:void 0,disabled:h||u,onClick:_,children:[(0,z.jsx)(`strong`,{children:e.id}),(0,z.jsxs)(`span`,{children:[vT.get(i),` · `,e.paths.length,` 个文件`]})]},e.id))]}),i===`skills`&&(0,z.jsx)(`div`,{className:`configuration-list-footer`,children:(0,z.jsx)(qo,{variant:`subtle`,size:`compact-sm`,disabled:h||u||f,onClick:D,children:`导入 Skill 目录`})})]}),(0,z.jsxs)(`div`,{className:`configuration-detail`,"aria-busy":f,children:[f&&(0,z.jsxs)(`p`,{className:`configuration-reading`,role:`status`,children:[(0,z.jsx)(pi,{size:`xs`}),`正在读取内容…`]}),!j&&!f&&(0,z.jsxs)(`div`,{className:`configuration-empty`,children:[(0,z.jsx)(`h2`,{children:`查看团队的 AI 资源`}),(0,z.jsx)(`p`,{children:`从左侧选择资源,阅读完整内容。需要调整时,再进入编辑。`}),(0,z.jsxs)(`p`,{children:[`也可以新增 `,vT.get(i),`,与团队共享使用。`]})]}),j&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(`header`,{className:h?`configuration-detail-header is-editing`:`configuration-detail-header`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`h2`,{children:s===xs.Create?`新增 ${vT.get(i)}`:j.id}),(0,z.jsxs)(`p`,{children:[vT.get(j.kind),(0,z.jsx)(`span`,{className:`configuration-mode`,children:h?`编辑中`:`只读查看`})]})]}),h?(0,z.jsxs)(`div`,{className:`configuration-actions`,children:[(0,z.jsx)(qo,{variant:`default`,disabled:u,onClick:x,children:`取消编辑`}),(0,z.jsx)(qo,{loading:u,disabled:!o?.id.trim(),onClick:O,children:`保存并同步`})]}):(0,z.jsx)(qo,{disabled:u||f,onClick:b,children:`编辑`}),h&&(0,z.jsxs)(`div`,{className:`configuration-header-feedback`,children:[(0,z.jsx)(`p`,{children:`保存后将同步到团队工作区,团队成员共享此配置。`}),c&&(0,z.jsxs)(po,{color:`red`,role:`alert`,children:[c,(0,z.jsx)(`div`,{children:`编辑内容已保留,可重试保存。`})]})]})]}),(0,z.jsxs)(`div`,{className:`configuration-detail-body`,children:[h&&(0,z.jsxs)(`section`,{className:`configuration-section`,children:[(0,z.jsx)(`h3`,{children:`基本信息`}),(0,z.jsxs)(`label`,{className:`configuration-field`,children:[`名称 / ID`,(0,z.jsx)(`input`,{disabled:u,value:j.id,onChange:S,readOnly:s!==xs.Create,placeholder:`例如 team-review`}),(0,z.jsx)(`span`,{className:`configuration-hint`,children:s===xs.Create?`使用字母、数字、短横线或下划线。`:`已有资源的 ID 保持不变,工作流通过它关联资源。`})]})]}),h&&i===`mcp`&&(0,z.jsxs)(`section`,{className:`configuration-section`,children:[(0,z.jsx)(`h3`,{children:`连接设置`}),(0,z.jsxs)(`div`,{className:`configuration-fields`,children:[(0,z.jsxs)(`label`,{className:`configuration-field`,children:[`启动命令`,(0,z.jsx)(`input`,{name:`command`,value:typeof N?.command==`string`?N.command:``,disabled:u||!N,onChange:ee,placeholder:`本机已安装的程序`})]}),(0,z.jsxs)(`label`,{className:`configuration-field`,children:[`服务地址`,(0,z.jsx)(`input`,{name:`url`,value:typeof N?.url==`string`?N.url:``,disabled:u||!N,onChange:ee,placeholder:`https://…`})]})]})]}),(0,z.jsxs)(`section`,{className:`configuration-section`,children:[(0,z.jsxs)(`div`,{className:`configuration-document-bar`,children:[j.files.length>1?(0,z.jsxs)(`label`,{className:`configuration-file-picker`,children:[`文件`,(0,z.jsx)(`select`,{disabled:u,value:M?.path??``,onChange:C,children:j.files.map(({path:e})=>(0,z.jsx)(`option`,{value:e,children:e.split(`/`).slice(4).join(`/`)||e},e))})]}):(0,z.jsx)(`span`,{children:I||(i===`mcp`?`MCP 配置`:`资源内容`)}),!h&&F&&(0,z.jsx)(qo,{variant:`subtle`,color:`gray`,size:`compact-sm`,onClick:T,children:m?`返回预览`:`查看源码`})]}),h?(0,z.jsxs)(`label`,{className:`configuration-field`,children:[i===`mcp`?`MCP JSON`:`正文与元数据`,(0,z.jsx)(`textarea`,{className:`configuration-code-editor`,disabled:u,rows:18,value:M?.content??``,onChange:E,spellCheck:!1}),(0,z.jsx)(`span`,{className:`configuration-hint`,children:i===`mcp`?`可粘贴完整服务配置,额外字段会保留。`:`直接编辑源文件,保留 Markdown 与文件头元数据。`})]}):F&&!m?(0,z.jsx)(pT,{content:M?.content??``}):(0,z.jsx)(`pre`,{className:`configuration-content`,tabIndex:0,children:M?.content||`(内容为空)`})]})]}),!h&&(0,z.jsxs)(`footer`,{className:`configuration-footer`,children:[(0,z.jsx)(`p`,{children:`保存后将同步到团队工作区,团队成员共享此配置。`}),(0,z.jsx)(`div`,{className:`configuration-actions`,children:(0,z.jsx)(qo,{variant:`subtle`,color:`red`,loading:u,disabled:f,onClick:k,children:`删除资源`})})]})]})]})]})]})});var bT=class extends Error{code;constructor(e,t){super(t),this.name=`PenpalError`,this.code=e}},xT=e=>({name:e.name,message:e.message,stack:e.stack,penpalCode:e instanceof bT?e.code:void 0}),ST=({name:e,message:t,stack:n,penpalCode:r})=>{let i=r?new bT(r,t):Error(t);return i.name=e,i.stack=n,i},CT=class{value;transferables;constructor(e,t){this.value=e,this.transferables=t?.transferables}},wT=`penpal`,TT=e=>typeof e==`object`&&!!e,ET=e=>typeof e==`function`,DT=e=>TT(e)&&e.namespace===wT,OT=e=>e.type===`SYN`,kT=e=>e.type===`ACK1`,AT=e=>e.type===`ACK2`,jT=e=>e.type===`CALL`,MT=e=>e.type===`REPLY`,NT=e=>e.type===`DESTROY`,PT=(e,t=[])=>{let n=[];for(let r of Object.keys(e)){let i=e[r];ET(i)?n.push([...t,r]):TT(i)&&n.push(...PT(i,[...t,r]))}return n},FT=(e,t)=>{let n=e.reduce((e,t)=>TT(e)?e[t]:void 0,t);return ET(n)?n:void 0},IT=e=>e.join(`.`),LT=(e,t,n)=>({namespace:wT,channel:e,type:`REPLY`,callId:t,isError:!0,...n instanceof Error?{value:xT(n),isSerializedErrorInstance:!0}:{value:n}}),RT=(e,t,n,r)=>{let i=!1,a=async a=>{if(i||!jT(a))return;r?.(`Received ${IT(a.methodPath)}() call`,a);let{methodPath:o,args:s,id:c}=a,l,u;try{let e=FT(o,t);if(!e)throw new bT(`METHOD_NOT_FOUND`,`Method \`${IT(o)}\` is not found.`);let r=await e(...s);r instanceof CT&&(u=r.transferables,r=await r.value),l={namespace:wT,channel:n,type:`REPLY`,callId:c,value:r}}catch(e){l=LT(n,c,e)}if(!i)try{r?.(`Sending ${IT(o)}() reply`,l),e.sendMessage(l,u)}catch(t){throw t.name===`DataCloneError`&&(l=LT(n,c,t),r?.(`Sending ${IT(o)}() reply`,l),e.sendMessage(l)),t}};return e.addMessageHandler(a),()=>{i=!0,e.removeMessageHandler(a)}},zT=crypto.randomUUID?.bind(crypto)??(()=>[,,,,].fill(0).map(()=>Math.floor(Math.random()*(2**53-1)).toString(16)).join(`-`)),BT=class{transferables;timeout;constructor(e){this.transferables=e?.transferables,this.timeout=e?.timeout}},VT=new Set([`apply`,`call`,`bind`]),HT=(e,t,n=[])=>new Proxy(n.length?()=>{}:Object.create(null),{get(r,i){if(i!==`then`)return n.length&&VT.has(i)?Reflect.get(r,i):HT(e,t,[...n,i])},apply(t,r,i){return e(n,i)}}),UT=e=>new bT(`CONNECTION_DESTROYED`,`Method call ${IT(e)}() failed due to destroyed connection`),WT=(e,t,n)=>{let r=!1,i=new Map,a=e=>{if(!MT(e))return;let{callId:t,value:r,isError:a,isSerializedErrorInstance:o}=e,s=i.get(t);s&&(i.delete(t),n?.(`Received ${IT(s.methodPath)}() call`,e),a?s.reject(o?ST(r):r):s.resolve(r))};return e.addMessageHandler(a),{remoteProxy:HT((a,o)=>{if(r)throw UT(a);let s=zT(),c=o[o.length-1],l=c instanceof BT,{timeout:u,transferables:d}=l?c:{},f=l?o.slice(0,-1):o;return new Promise((r,o)=>{let c=u===void 0?void 0:window.setTimeout(()=>{i.delete(s),o(new bT(`METHOD_CALL_TIMEOUT`,`Method call ${IT(a)}() timed out after ${u}ms`))},u);i.set(s,{methodPath:a,resolve:r,reject:o,timeoutId:c});try{let r={namespace:wT,channel:t,type:`CALL`,id:s,methodPath:a,args:f};n?.(`Sending ${IT(a)}() call`,r),e.sendMessage(r,d)}catch(e){o(new bT(`TRANSMISSION_FAILED`,e.message))}})},n),destroy:()=>{r=!0,e.removeMessageHandler(a);for(let{methodPath:e,reject:t,timeoutId:n}of i.values())clearTimeout(n),t(UT(e));i.clear()}}},GT=()=>{let e,t;return{promise:new Promise((n,r)=>{e=n,t=r}),resolve:e,reject:t}},KT=`deprecated-penpal`,qT=e=>TT(e)&&`penpal`in e,JT=e=>e.split(`.`),YT=e=>e.join(`.`),XT=e=>{try{return JSON.stringify(e)}catch{return String(e)}},ZT=e=>new bT(`TRANSMISSION_FAILED`,`Unexpected message to translate: ${XT(e)}`),QT=e=>{if(e.penpal===`syn`)return{namespace:wT,channel:void 0,type:`SYN`,participantId:KT};if(e.penpal===`ack`)return{namespace:wT,channel:void 0,type:`ACK2`};if(e.penpal===`call`)return{namespace:wT,channel:void 0,type:`CALL`,id:e.id,methodPath:JT(e.methodName),args:e.args};if(e.penpal===`reply`)return e.resolution===`fulfilled`?{namespace:wT,channel:void 0,type:`REPLY`,callId:e.id,value:e.returnValue}:{namespace:wT,channel:void 0,type:`REPLY`,callId:e.id,isError:!0,...e.returnValueIsError?{value:e.returnValue,isSerializedErrorInstance:!0}:{value:e.returnValue}};throw ZT(e)},$T=e=>{if(kT(e))return{penpal:`synAck`,methodNames:e.methodPaths.map(YT)};if(jT(e))return{penpal:`call`,id:e.id,methodName:YT(e.methodPath),args:e.args};if(MT(e))return e.isError?{penpal:`reply`,id:e.callId,resolution:`rejected`,...e.isSerializedErrorInstance?{returnValue:e.value,returnValueIsError:!0}:{returnValue:e.value}}:{penpal:`reply`,id:e.callId,resolution:`fulfilled`,returnValue:e.value};throw ZT(e)},eE=({messenger:e,methods:t,timeout:n,channel:r,log:i})=>{let a=zT(),o,s=[],c=!1,l=PT(t),{promise:u,resolve:d,reject:f}=GT(),p=n===void 0?void 0:setTimeout(()=>{f(new bT(`CONNECTION_TIMEOUT`,`Connection timed out after ${n}ms`))},n),m=()=>{for(let e of s)e()},h=()=>{if(c)return;s.push(RT(e,t,r,i));let{remoteProxy:n,destroy:a}=WT(e,r,i);s.push(a),clearTimeout(p),c=!0,d({remoteProxy:n,destroy:m})},g=()=>{let t={namespace:wT,type:`SYN`,channel:r,participantId:a};i?.(`Sending handshake SYN`,t);try{e.sendMessage(t)}catch(e){f(new bT(`TRANSMISSION_FAILED`,e.message))}},_=t=>{if(i?.(`Received handshake SYN`,t),t.participantId===o&&o!==KT||(o=t.participantId,g(),!(a>o||o===KT)))return;let n={namespace:wT,channel:r,type:`ACK1`,methodPaths:l};i?.(`Sending handshake ACK1`,n);try{e.sendMessage(n)}catch(e){f(new bT(`TRANSMISSION_FAILED`,e.message));return}},v=t=>{i?.(`Received handshake ACK1`,t);let n={namespace:wT,channel:r,type:`ACK2`};i?.(`Sending handshake ACK2`,n);try{e.sendMessage(n)}catch(e){f(new bT(`TRANSMISSION_FAILED`,e.message));return}h()},y=e=>{i?.(`Received handshake ACK2`,e),h()},b=e=>{OT(e)&&_(e),kT(e)&&v(e),AT(e)&&y(e)};return e.addMessageHandler(b),s.push(()=>e.removeMessageHandler(b)),g(),u},tE=e=>{let t=!1,n;return(...r)=>(t||(t=!0,n=e(...r)),n)},nE=new WeakSet,rE=({messenger:e,methods:t={},timeout:n,channel:r,log:i})=>{if(!e)throw new bT(`INVALID_ARGUMENT`,`messenger must be defined`);if(nE.has(e))throw new bT(`INVALID_ARGUMENT`,`A messenger can only be used for a single connection`);nE.add(e);let a=[e.destroy],o=tE(t=>{if(t){let t={namespace:wT,channel:r,type:`DESTROY`};try{e.sendMessage(t)}catch{}}for(let e of a)e();i?.(`Connection destroyed`)}),s=e=>DT(e)&&e.channel===r;return{promise:(async()=>{try{e.initialize({log:i,validateReceivedMessage:s}),e.addMessageHandler(e=>{NT(e)&&o(!1)});let{remoteProxy:c,destroy:l}=await eE({messenger:e,methods:t,timeout:n,channel:r,log:i});return a.push(l),c}catch(e){throw o(!0),e}})(),destroy:()=>{o(!0)}}},iE=class{#e;#t;#n;#r;#i;#a=new Set;#o;#s=!1;constructor({remoteWindow:e,allowedOrigins:t}){if(!e)throw new bT(`INVALID_ARGUMENT`,`remoteWindow must be defined`);this.#e=e,this.#t=t?.length?t:[window.origin]}initialize=({log:e,validateReceivedMessage:t})=>{this.#n=e,this.#r=t,window.addEventListener(`message`,this.#d)};sendMessage=(e,t)=>{if(OT(e)){let n=this.#l(e);this.#e.postMessage(e,{targetOrigin:n,transfer:t});return}if(kT(e)||this.#s){let n=this.#s?$T(e):e,r=this.#l(e);this.#e.postMessage(n,{targetOrigin:r,transfer:t});return}if(AT(e)){let{port1:n,port2:r}=new MessageChannel;this.#o=n,n.addEventListener(`message`,this.#f),n.start();let i=[r,...t||[]],a=this.#l(e);this.#e.postMessage(e,{targetOrigin:a,transfer:i});return}if(this.#o){this.#o.postMessage(e,{transfer:t});return}throw new bT(`TRANSMISSION_FAILED`,`Cannot send message because the MessagePort is not connected`)};addMessageHandler=e=>{this.#a.add(e)};removeMessageHandler=e=>{this.#a.delete(e)};destroy=()=>{window.removeEventListener(`message`,this.#d),this.#u(),this.#a.clear()};#c=e=>this.#t.some(t=>t instanceof RegExp?t.test(e):t===e||t===`*`);#l=e=>{if(OT(e))return`*`;if(!this.#i)throw new bT(`TRANSMISSION_FAILED`,`Cannot send message because the remote origin is not established`);return this.#i===`null`&&this.#t.includes(`*`)?`*`:this.#i};#u=()=>{this.#o?.removeEventListener(`message`,this.#f),this.#o?.close(),this.#o=void 0};#d=({source:e,origin:t,ports:n,data:r})=>{if(e===this.#e){if(qT(r)){this.#n?.(`Please upgrade the child window to the latest version of Penpal.`),this.#s=!0;try{r=QT(r)}catch(e){this.#n?.(`Failed to translate deprecated message: ${e.message}`);return}}if(this.#r?.(r)){if(!this.#c(t)){this.#n?.(`Received a message from origin \`${t}\` which did not match allowed origins \`[${this.#t.join(`, `)}]\``);return}if(OT(r)&&(this.#u(),this.#i=t),AT(r)&&!this.#s){if(this.#o=n[0],!this.#o){this.#n?.(`Ignoring ACK2 because it did not include a MessagePort`);return}this.#o.addEventListener(`message`,this.#f),this.#o.start()}for(let e of this.#a)e(r)}}};#f=({data:e})=>{if(this.#r?.(e))for(let t of this.#a)t(e)}};function aE(e,t){let n=e?.onInit,r=t?.connectToHost,i=t?.targetWindow;if(typeof n!=`function`)throw TypeError(`defineWorkbasePluginUi requires an onInit callback.`);if(!i||typeof r!=`function`)throw TypeError(`Plugin UI transport is unavailable.`);let a={fatalReportPromise:null,isInitialized:!1,contentHeight:null,recoverableHostErrors:new WeakSet},o=new Set,s=r({executionChanged:async e=>{a.isInitialized&&[...o].forEach(t=>t(e))},initialize:async e=>{hE(e),a.isInitialized=!0,await n(e),await dE(i),await mE(c,{targetWindow:i,state:a})}}),c=s.promise,l=oE(c,a);return lE({connection:s,state:a,targetWindow:i}),cE(l,{targetWindow:i,subscribe:async e=>{let t=t=>e(t);o.add(t);try{await l(`command.subscribe`,{enabled:!0})}catch(e){throw o.delete(t),e}return async()=>{o.delete(t)&&!o.size&&await l(`command.subscribe`,{enabled:!1})}}})}function oE(e,t){return async(n,r)=>{if(!t.isInitialized)throw Error(`Plugin UI is not initialized.`);let i=await(await e).call(n,r);if(yE(i)&&i.ok===!0)return i.result;let a=sE(i);throw t.recoverableHostErrors.add(a),a}}function sE(e){let t=yE(e)&&yE(e.error)?e.error:null,n=typeof t?.message==`string`?t.message:`Host action failed.`,r=typeof t?.code==`string`?t.code:`host_error`;return Object.assign(Error(n),{code:r})}function cE(e,{targetWindow:t,subscribe:n}){let r=Object.freeze({subscribe:n,reply:t=>e(`command.reply`,{executionId:t}),clear:t=>e(`command.clear`,t===void 0?{}:{executionId:t}),start:(n,r,i={})=>e(`command.start`,{commandId:n,input:r,executionId:i.executionId??t.crypto.randomUUID()}),query:t=>e(`command.query`,{executionId:t??null}),cancel:t=>e(`command.cancel`,{executionId:t}),execute:(n,r,i={})=>e(`command.execute`,{commandId:n,executionId:i.executionId??t.crypto.randomUUID(),input:r})}),i=Object.freeze({resolve:(t,n)=>e(`status.resolve`,{input:n,statusId:t})}),a=Object.freeze({call:(t,n)=>e(`view.call`,{input:n,method:t})});return Object.freeze({dismiss:()=>e(`interaction.dismiss`,{}),respond:t=>e(`interaction.respond`,{value:t}),closeOutput:t=>e(`output.close`,{id:t}),commands:r,desktop:Object.freeze({open:t=>e(`desktop.open`,t)}),navigate:(t,{replace:n=!1}={})=>e(`navigate`,{replace:n,to:t}),openOutput:t=>e(`output.open`,t),selectFiles:(t={})=>e(`file.select`,t),showPrompt:t=>e(`dialog.prompt`,t),showToast:t=>e(`toast.show`,t),status:i,updateOutput:t=>e(`output.update`,t),view:a})}function lE({connection:e,state:t,targetWindow:n}){let r=null,i=n=>{(n.error||n.message!==`ResizeObserver loop completed with undelivered notifications.`&&n.message!==`ResizeObserver loop limit exceeded`)&&fE(e.promise,t,n.error??n.message)},a=n=>{n.reason instanceof Error&&t.recoverableHostErrors.has(n.reason)||fE(e.promise,t,n.reason)},o=new n.ResizeObserver(()=>{r===null&&(r=n.requestAnimationFrame(()=>{r=null,t.isInitialized&&mE(e.promise,{targetWindow:n,state:t})}))}),s=()=>{n.removeEventListener(`error`,i,!0),n.removeEventListener(`unhandledrejection`,a),n.removeEventListener(`beforeunload`,s),o.disconnect(),r!==null&&n.cancelAnimationFrame(r),e.destroy(),t.fatalReportPromise=null,t.isInitialized=!1};uE(e.promise),o.observe(n.document.body??n.document.documentElement),n.addEventListener(`error`,i,!0),n.addEventListener(`unhandledrejection`,a),n.addEventListener(`beforeunload`,s,{once:!0})}async function uE(e){try{await e}catch{}}async function dE(e){await new Promise(t=>{e.requestAnimationFrame(()=>{e.requestAnimationFrame(()=>t())})})}async function fE(e,t,n){t.fatalReportPromise||=pE(e,bE(n).slice(0,1e3)),await t.fatalReportPromise}async function pE(e,t){try{await(await e).reportFatal(t)}catch{}}async function mE(e,{targetWindow:t,state:n}){let r=t.document.body??t.document.documentElement,i=Math.max(r.offsetHeight,r.scrollHeight);if(Number.isFinite(i))try{let t=await e,r=Math.min(Math.max(Math.ceil(i),1),1e4);if(!n.isInitialized||n.contentHeight===r)return;n.contentHeight=r,await t.reportContentHeight(r)}catch{}}function hE(e){if(!gE(e))throw TypeError(`Plugin UI initialization payload is invalid.`)}function gE(e){return yE(e)?_E(e.project)&&_E(e.workspace)&&vE(e.view):!1}function _E(e){return yE(e)&&typeof e.id==`string`&&e.id.length>0}function vE(e){return _E(e)&&yE(e)&&typeof e.pluginId==`string`&&e.pluginId.length>0&&typeof e.title==`string`&&e.title.length>0}function yE(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function bE(e){return e instanceof Error?e.message:typeof e==`string`&&e.trim().length>0?e:`Plugin UI failed.`}function xE(e){let t=window;return aE(e,{connectToHost:e=>SE(t,e),targetWindow:t})}function SE(e,t){let n=rE({channel:`workbase-plugin-ui-v1`,messenger:new iE({allowedOrigins:CE(e),remoteWindow:e.parent}),methods:t});return{destroy:n.destroy,promise:n.promise}}function CE(e){let t=new URL(e.location.href).searchParams.get(`__workbaseHostOrigin`);return t&&t!==`null`?[t]:[`*`]}function wE(e,t){return t?`配置有未保存修改,请先保存后再同步。`:e.configured?e.autoSync?`进入工作区时自动同步,也可手动同步当前变动。`:`自动同步已关闭,可手动同步当前变动。`:`初始化后即可生成所选客户端的规则与技能。`}function TE(e){if(!e)throw Error(`AI Rules UI 尚未初始化。`);return e}function EE(e){if(!qE(e)||typeof e.autoSync!=`boolean`||typeof e.configured!=`boolean`||typeof e.configPath!=`string`||typeof e.workspaceRoot!=`string`||!JE(e.features)||!JE(e.targets)||!YE(e.lastOperation))throw Error(`AI Rules 状态响应无效。`);return{autoSync:e.autoSync,configured:e.configured,configPath:e.configPath,features:e.features,lastOperation:e.lastOperation,targets:e.targets,workspaceRoot:e.workspaceRoot}}function DE(e){if(!qE(e))throw Error(`AI Rules 命令响应无效。`);return{result:FE(e.result),status:EE(e.status)}}function OE(e){let t=qE(e.details)?e.details:{},n=qE(t.generation)?t.generation:t,r=IE(n),i=LE(r.features),a=RE(r.diagnostics),o=UE(r.totalFiles)??i.reduce((e,t)=>e+t.count,0),s=GE([...e.warnings,...WE(t.warnings),...WE(n.warnings)]);return{description:BE(e.operation,o),diagnostics:a,features:i,title:VE(e.operation),totalFiles:o,warnings:s}}function kE(e){return{autoSync:e.autoSync,features:[...e.features],targets:[...e.targets]}}function AE(e,t){return e.autoSync===t.autoSync&&KE(e.features,t.features)&&KE(e.targets,t.targets)}function jE({values:e,value:t,isSelected:n}){return n?e.includes(t)?[...e]:[...e,t]:e.filter(e=>e!==t)}function ME(e){return{check:`一致性校验`,doctor:`配置诊断`,initialize:`初始化`,install:`安装来源`,inject:`注入 AI 上下文`,uninject:`撤销 AI 上下文注入`,preview:`预览`,"sources.update":`更新远端来源`,sync:`同步`}[e]??e}function NE(e){return new Date(e).toLocaleString(`zh-CN`)}function PE(e){return e instanceof Error?e.message:`AI Rules 操作失败。`}function FE(e){if(!qE(e)||typeof e.completedAt!=`string`||typeof e.operation!=`string`||typeof e.success!=`boolean`||!JE(e.warnings))throw Error(`AI Rules 执行结果无效。`);return{completedAt:e.completedAt,details:e.details,operation:e.operation,success:e.success,warnings:e.warnings}}function IE(e){return qE(e)?qE(e.data)?e.data:e:{}}function LE(e){return qE(e)?Object.entries(e).flatMap(([e,t])=>{if(!qE(t))return[];let n=UE(t.count)??0;return n===0?[]:[{count:n,id:e,label:HE(e),paths:WE(t.paths).slice(0,30)}]}):[]}function RE(e){return Array.isArray(e)?zE(e.flatMap(e=>!qE(e)||typeof e.message!=`string`?[]:[{hint:typeof e.hint==`string`?e.hint:null,message:e.message,severity:typeof e.severity==`string`?e.severity:`info`}])).slice(0,50):[]}function zE(e){let t=new Set;return e.filter(e=>{let n=`${e.severity}:${e.message}:${e.hint??``}`;return!t.has(n)&&(t.add(n),!0)})}function BE(e,t){return e===`preview`?t>0?`以下 ${t} 个文件会在同步时更新。`:`当前客户端配置已经是最新状态。`:e===`doctor`?`已完成 Rulesync 配置检查。`:e===`check`?t>0?`发现尚未同步的客户端文件。`:`客户端文件与规则源一致。`:t>0?`已处理 ${t} 个客户端文件。`:`操作已完成,没有文件需要更新。`}function VE(e){return{check:`一致性校验结果`,doctor:`配置诊断结果`,initialize:`初始化与同步结果`,preview:`变更预览`,"sources.update":`远端更新与同步结果`,sync:`同步结果`}[e]??`执行结果`}function HE(e){return{activation:`Activation`,checks:`Checks`,commands:`Commands`,hooks:`Hooks`,ignore:`Ignore`,mcp:`MCP`,permissions:`Permissions`,rules:`Rules`,skills:`技能`,subagents:`Subagents`}[e]??e}function UE(e){return typeof e==`number`&&Number.isFinite(e)?e:null}function WE(e){return JE(e)?e:[]}function GE(e){return[...new Set(e)]}function KE(e,t){return e.length===t.length&&e.every((e,n)=>e===t[n])}function qE(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function JE(e){return Array.isArray(e)&&e.every(e=>typeof e==`string`)}function YE(e){return e===null||qE(e)&&typeof e.completedAt==`string`&&typeof e.operation==`string`&&typeof e.success==`boolean`}function XE(){let[e,t]=(0,O.useState)(``),[n,r]=(0,O.useState)(``),[i,a]=(0,O.useState)(!0),[o,s]=(0,O.useState)(!1),c=(0,O.useCallback)(()=>a(!0),[]),l=(0,O.useCallback)(()=>a(!1),[]),u=(0,O.useCallback)(()=>s(!0),[]),d=(0,O.useRef)(null),f=(0,O.useRef)(null),p=(0,O.useRef)(0),m=(0,O.useRef)(null),h=(0,O.useRef)(!1),g=(0,O.useRef)(null),[_,v]=(0,O.useState)(!1),[y,b]=(0,O.useState)(null),[x,S]=(0,O.useState)(null),[C,w]=(0,O.useState)(null),[T,E]=(0,O.useState)(null),[ee,D]=(0,O.useState)(null),k=(0,O.useCallback)((e,t=!1)=>{let n=m.current;m.current=e,b(e),S(r=>!t&&r&&n&&!AE(n,r)?r:kE(e))},[]),A=(0,O.useCallback)(async()=>{if(h.current)return;if(g.current)return g.current;let e=TE(d.current),t=p.current;return v(!0),g.current=(async()=>{try{let n=EE(await e.status.resolve(`sync`,{}));if(t!==p.current)return;k(n),E(null)}catch(e){t===p.current&&E(PE(e))}finally{t===p.current&&(g.current=null,v(!1))}})(),g.current},[k]),j=(0,O.useCallback)(e=>{let n=JSON.stringify([e.project.id,e.workspace.id]);f.current!==n&&(f.current=n,p.current+=1,m.current=null,g.current=null,h.current=!1,t(n),r(e.workspace.id),s(!1),b(null),S(null),w(null),E(null),D(null),A())},[A]);(0,O.useEffect)(()=>(d.current=xE({onInit:j}),()=>{p.current+=1,d.current=null}),[j]);let M=(0,O.useCallback)(async({commandId:e})=>{if(h.current)return;h.current=!0;let t=++p.current;g.current=null,v(!1);let n=TE(d.current);w(e),E(null);try{let r=await n.commands.execute(e,{}),i=DE(r.value);if(t!==p.current)return;k(i.status),D({logId:r.logId,result:i.result})}catch(e){t===p.current&&E(PE(e))}finally{t===p.current&&(h.current=!1,w(null))}},[k]),N=(0,O.useCallback)(async({commandId:e,message:t,title:n})=>{let r=TE(d.current),i=p.current;try{await r.showPrompt({message:t,submitLabel:`继续`,title:n,type:`confirm`})===!0&&i===p.current&&await M({commandId:e})}catch(e){i===p.current&&E(PE(e))}},[M]);return{resourceKey:e,workspaceId:n,isResourceMode:i,isEditingSync:o,handleResourceMode:c,handleSyncMode:l,handleEditSync:u,pluginUiRef:d,contextKeyRef:f,isRefreshing:_,status:y,draft:x,busyCommand:C,error:T,operationDialog:ee,refreshStatus:A,handleSave:(0,O.useCallback)(async()=>{if(!x||h.current)return;h.current=!0;let e=++p.current;g.current=null,v(!1);let t=TE(d.current);w(`configuration.save`),E(null);try{let n=await t.commands.execute(`configuration.save`,x),r=EE(n.value);if(e!==p.current)return;k(r,!0),s(!1),await t.showToast({description:Ss(n.publication),title:`同步配置已保存`})}catch(t){e===p.current&&E(PE(t))}finally{e===p.current&&(h.current=!1,w(null))}},[k,x]),handleCancelSync:(0,O.useCallback)(()=>{y&&S(kE(y)),s(!1)},[y]),handleTargetToggle:(0,O.useCallback)((e,t)=>{S(n=>n&&{...n,targets:jE({values:n.targets,value:e,isSelected:t})})},[]),handleFeatureToggle:(0,O.useCallback)((e,t)=>{S(n=>n&&{...n,features:jE({values:n.features,value:e,isSelected:t})})},[]),handleAutoSyncChange:(0,O.useCallback)(e=>{let t=e.currentTarget.checked;S(e=>e&&{...e,autoSync:t})},[]),handleSync:(0,O.useCallback)(()=>N({commandId:`sync`,message:`将规则更新到当前 Workspace 中已选择客户端的 AI 上下文文件。`,title:`同步 AI 上下文`}),[N]),handleInitialize:(0,O.useCallback)(()=>N({commandId:`initialize`,message:`将在项目根目录的 rules 文件夹中创建 Rulesync 配置,并立即生成当前 Workspace 的 AI 上下文。`,title:`初始化并同步`}),[N]),handleUpdateSources:(0,O.useCallback)(()=>N({commandId:`sources.update`,message:`将更新远端规则版本、锁文件和当前 Workspace 的客户端配置。`,title:`更新远端并同步`}),[N]),handlePreview:(0,O.useCallback)(()=>M({commandId:`preview`}),[M]),handleDoctor:(0,O.useCallback)(()=>M({commandId:`doctor`}),[M]),handleCheck:(0,O.useCallback)(()=>M({commandId:`check`}),[M]),handleOpenLog:(0,O.useCallback)(async()=>{ee?.logId&&await TE(d.current).navigate(`/logs/${ee.logId}`)},[ee]),handleCloseResult:(0,O.useCallback)(()=>D(null),[]),isBusy:C!==null,isConfigurationValid:!!(x&&x.targets.length>0&&x.features.length>0),isDirty:(0,O.useMemo)(()=>y!==null&&x!==null&&!AE(y,x),[x,y]),operationPresentation:(0,O.useMemo)(()=>ee?OE(ee.result):null,[ee]),statusColor:y?.configured?`teal`:`orange`}}const ZE=[{label:`Codex CLI`,value:`codexcli`},{label:`Claude Code`,value:`claudecode`}],QE=[{label:`规则`,value:`rules`},{label:`MCP`,value:`mcp`},{label:`命令`,value:`commands`},{label:`子代理`,value:`subagents`},{label:`技能`,value:`skills`}],$E=(0,O.memo)(function(){let{resourceKey:e,workspaceId:t,isResourceMode:n,isEditingSync:r,handleResourceMode:i,handleSyncMode:a,handleEditSync:o,pluginUiRef:s,contextKeyRef:c,isRefreshing:l,status:u,draft:d,busyCommand:f,error:p,operationDialog:m,refreshStatus:h,handleSave:g,handleCancelSync:_,handleTargetToggle:v,handleFeatureToggle:y,handleAutoSyncChange:b,handleSync:x,handleInitialize:S,handleUpdateSources:C,handlePreview:w,handleDoctor:T,handleCheck:E,handleOpenLog:ee,handleCloseResult:D,isBusy:O,isConfigurationValid:k,isDirty:A,operationPresentation:j,statusColor:M}=XE(),N=u?.configured?`可同步`:`待初始化`,P=O?`正在处理`:N,F=f===`preview`?`预览中…`:`预览变更`,I=f===`sync`?`同步中…`:`同步当前变动`,te=f===`initialize`?`初始化中…`:`初始化并同步`,ne=u?.lastOperation?.success?`成功`:`失败`;return(0,z.jsxs)(`main`,{className:`app-shell`,children:[(0,z.jsxs)(`header`,{className:`page-header`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`h1`,{children:n?`AI 资源`:`AI 上下文同步`}),(0,z.jsx)(`p`,{className:`page-description`,children:n?`管理团队共享的规则、技能与 AI 连接。`:`将团队规则与技能同步到当前工作区的 AI 客户端。`})]}),(0,z.jsx)(qo,{hidden:n,variant:`subtle`,loading:l,disabled:O||!c.current,onClick:h,children:`刷新状态`})]}),(0,z.jsxs)(`nav`,{className:`configuration-page-tabs`,"aria-label":`AI Rules 模式`,children:[(0,z.jsx)(`button`,{type:`button`,"aria-pressed":n,onClick:i,children:`资源配置`}),(0,z.jsx)(`button`,{type:`button`,"aria-pressed":!n,onClick:a,children:`客户端同步`})]}),s.current&&t&&(0,z.jsx)(`div`,{className:`configuration-view`,hidden:!n,children:(0,z.jsx)(yT,{host:s.current,isActive:n,workspaceId:t},e)}),(0,z.jsxs)(`div`,{hidden:n,children:[p?(0,z.jsxs)(po,{color:`red`,title:u?`本次操作失败,保留当前配置`:`无法读取同步配置`,children:[p,` 请刷新状态重试。`]}):null,!u&&!p?(0,z.jsxs)(`p`,{className:`loading-message`,role:`status`,children:[(0,z.jsx)(pi,{size:`xs`}),`正在读取同步配置…`]}):null,u?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(`section`,{className:`sync-overview`,"aria-labelledby":`sync-title`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(Ro,{variant:`light`,color:O?`blue`:M,leftSection:O?(0,z.jsx)(pi,{size:12}):void 0,children:P}),(0,z.jsx)(`p`,{id:`sync-title`,children:wE(u,A)})]}),(0,z.jsx)(`div`,{className:`button-row`,children:u.configured?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(qo,{variant:`default`,className:`button button-secondary`,disabled:O||A,onClick:w,type:`button`,children:F}),(0,z.jsx)(qo,{variant:`filled`,loading:f===`sync`,"aria-busy":f===`sync`,className:`button button-primary`,disabled:O||A,onClick:x,type:`button`,children:I})]}):(0,z.jsx)(qo,{variant:`filled`,loading:f===`initialize`,"aria-busy":f===`initialize`,className:`button button-primary`,disabled:O||A,onClick:S,type:`button`,children:te})})]}),(0,z.jsxs)(`details`,{className:`maintenance configuration-panel`,children:[(0,z.jsxs)(`summary`,{children:[`同步配置`,A?(0,z.jsx)(`span`,{className:`configuration-unsaved`,children:`未保存修改`}):null]}),d?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(`label`,{className:`auto-sync-switch`,children:[(0,z.jsx)(`span`,{className:`auto-sync-copy`,children:(0,z.jsx)(`strong`,{children:`进入工作区时自动同步`})}),(0,z.jsx)(`span`,{className:`switch-control`,children:(0,z.jsx)(gs,{"aria-label":`进入工作区时自动同步`,checked:d.autoSync,disabled:O||!r,onChange:b})})]}),(0,z.jsxs)(`div`,{className:`configuration-layout`,children:[(0,z.jsxs)(`fieldset`,{className:`choice-section`,disabled:O||!r,children:[(0,z.jsx)(`legend`,{children:`目标客户端`}),(0,z.jsx)(`div`,{className:`choice-list`,children:ZE.map(e=>(0,z.jsx)(eD,{isSelected:d.targets.includes(e.value),option:e,onToggle:v},e.value))})]}),(0,z.jsxs)(`fieldset`,{className:`choice-section`,disabled:O||!r,children:[(0,z.jsx)(`legend`,{children:`同步内容`}),(0,z.jsx)(`div`,{className:`feature-grid`,children:QE.map(e=>(0,z.jsx)(eD,{isSelected:d.features.includes(e.value),option:e,onToggle:y},e.value))})]})]})]}):(0,z.jsx)(`p`,{className:`loading-card`,"aria-live":`polite`,children:`正在读取同步配置…`}),(0,z.jsx)(`p`,{className:`configuration-notice`,children:`保存后将同步到团队工作区,团队成员共享此配置。`}),(0,z.jsxs)(`div`,{className:`button-row configuration-actions`,children:[r&&(0,z.jsx)(qo,{variant:`default`,disabled:O,onClick:_,children:`取消编辑`}),!r&&(0,z.jsx)(qo,{variant:`default`,onClick:o,children:`编辑同步配置`}),(0,z.jsx)(qo,{variant:`filled`,className:`button button-primary`,disabled:O||!r||!A||!k,onClick:g,type:`button`,children:f===`configuration.save`?`保存中…`:`保存配置`})]})]}),(0,z.jsxs)(`details`,{className:`maintenance`,children:[(0,z.jsx)(`summary`,{children:`规则维护`}),(0,z.jsxs)(`div`,{className:`maintenance-content`,children:[(0,z.jsxs)(`div`,{className:`button-row`,children:[(0,z.jsx)(qo,{variant:`default`,className:`button button-secondary`,disabled:O||A||!u?.configured,onClick:C,type:`button`,children:f===`sources.update`?`更新中…`:`更新远端并同步`}),(0,z.jsx)(qo,{variant:`default`,className:`button button-secondary`,disabled:O||A||!u?.configured,onClick:T,type:`button`,children:`诊断配置`}),(0,z.jsx)(qo,{variant:`default`,className:`button button-secondary`,disabled:O||A||!u?.configured,onClick:E,type:`button`,children:`校验一致性`})]}),u?.lastOperation?(0,z.jsxs)(`p`,{className:`last-operation`,children:[`最近执行:`,ME(u.lastOperation.operation),` ·`,` `,ne,` · `,NE(u.lastOperation.completedAt)]}):null]})]})]}):null]}),(0,z.jsx)(Ts,{operationDialog:m,handleOpenLog:ee,handleCloseResult:D,operationPresentation:j})]})});function eD({isSelected:e,onToggle:t,option:n}){let r=(0,O.useCallback)(e=>{t(n.value,e.currentTarget.checked)},[t,n.value]);return(0,z.jsxs)(`label`,{className:`choice-field`,"data-selected":e,children:[(0,z.jsx)(Fo,{"aria-label":n.label,checked:e,onChange:r}),(0,z.jsx)(`span`,{children:(0,z.jsx)(`strong`,{children:n.label})})]})}const tD=document.querySelector(`#root`);if(!tD)throw Error(`AI Rules UI root element was not found.`);u(),(0,bs.createRoot)(tD).render((0,z.jsx)(Ut,{theme:f,getStyleNonce:d,forceColorScheme:`light`,children:(0,z.jsx)($E,{})}));
198
+ `}function gT(e,t){if(e.kind===`mcp`)return`server.json`;if(e.kind!==`skills`)return`rules/.rulesync/${e.kind}/${e.id}.md`;let n=t?t.split(`/`).slice(4).join(`/`):`SKILL.md`;return`rules/.rulesync/skills/${e.id}/${n}`}function _T(e){try{let t=JSON.parse(e??`{}`);return t&&typeof t==`object`&&!Array.isArray(t)?t:null}catch{return null}}const vT=new Map([[`rules`,`Rules`],[`skills`,`Skills`],[`mcp`,`MCP`],[`commands`,`Commands`],[`subagents`,`Subagents`]]),yT=(0,O.memo)(function({host:e,isActive:t,workspaceId:n}){let{catalog:r,kind:i,selected:a,draft:o,mode:s,error:c,message:l,isBusy:u,isRefreshing:d,isReading:f,query:p,isSourceView:m,isEditing:h,refresh:g,handleOpen:_,handleKind:v,handleCreate:y,handleEdit:b,handleCancel:x,handleId:S,handleFile:C,handleSearch:w,handleSourceView:T,handleContent:E,handleMcpField:ee,handleImport:D,handleSave:O,handleDelete:k,handleWorkflows:A,resource:j,file:M,server:N,visibleItems:P,isMarkdown:F,fileName:I}=mT({host:e,isActive:t,workspaceId:n});return(0,z.jsxs)(`section`,{className:`configuration-manager`,"data-editing":h,"aria-label":`AI 资源配置`,children:[(0,z.jsxs)(`header`,{className:`configuration-navigation`,children:[(0,z.jsx)(`nav`,{className:`configuration-tabs`,"aria-label":`资源类型`,children:[...vT].map(([e,t])=>(0,z.jsxs)(`button`,{type:`button`,value:e,"aria-pressed":i===e,disabled:h||u,onClick:v,children:[t,(0,z.jsx)(`span`,{"aria-hidden":`true`,children:r?.resources.filter(t=>t.kind===e).length??0})]},e))}),(0,z.jsx)(qo,{variant:`subtle`,color:`gray`,size:`compact-sm`,loading:d,disabled:u,onClick:g,children:`刷新列表`})]}),c&&!h&&(0,z.jsxs)(po,{color:`red`,role:`alert`,children:[c,` `,(0,z.jsx)(qo,{variant:`subtle`,onClick:A,children:`查看工作流关联`})]}),l&&(0,z.jsx)(`p`,{className:`configuration-feedback`,role:`status`,children:l}),(0,z.jsxs)(`div`,{className:`configuration-resource-grid`,children:[(0,z.jsxs)(`aside`,{className:`configuration-list`,"aria-label":`资源目录`,children:[(0,z.jsxs)(`div`,{className:`configuration-list-heading`,children:[(0,z.jsx)(`h2`,{children:`资源目录`}),(0,z.jsx)(qo,{size:`compact-sm`,variant:`default`,disabled:h||u||f,onClick:y,children:`新增`})]}),(0,z.jsx)(`input`,{autoCapitalize:`none`,className:`configuration-search`,type:`search`,"aria-label":`搜索资源`,placeholder:`搜索资源名称…`,value:p,onChange:w,disabled:h}),(0,z.jsxs)(`div`,{className:`configuration-items`,children:[!r&&(0,z.jsx)(`p`,{className:`configuration-notice`,role:`status`,children:c?`资源尚未读取`:`正在读取资源…`}),r&&!P.length&&(0,z.jsx)(`p`,{className:`configuration-notice`,children:p?`没有匹配的资源,试试其他名称。`:`还没有资源,从新增开始。`}),P.map(e=>(0,z.jsxs)(`button`,{type:`button`,className:`configuration-row`,"data-id":e.id,"aria-current":a?.id===e.id?`true`:void 0,disabled:h||u,onClick:_,children:[(0,z.jsx)(`strong`,{children:e.id}),(0,z.jsxs)(`span`,{children:[vT.get(i),` · `,e.paths.length,` 个文件`]})]},e.id))]}),i===`skills`&&(0,z.jsx)(`div`,{className:`configuration-list-footer`,children:(0,z.jsx)(qo,{variant:`subtle`,size:`compact-sm`,disabled:h||u||f,onClick:D,children:`导入 Skill 目录`})})]}),(0,z.jsxs)(`div`,{className:`configuration-detail`,"aria-busy":f,children:[f&&(0,z.jsxs)(`p`,{className:`configuration-reading`,role:`status`,children:[(0,z.jsx)(pi,{size:`xs`}),`正在读取内容…`]}),!j&&!f&&(0,z.jsxs)(`div`,{className:`configuration-empty`,children:[(0,z.jsx)(`h2`,{children:`查看团队的 AI 资源`}),(0,z.jsx)(`p`,{children:`从左侧选择资源,阅读完整内容。需要调整时,再进入编辑。`}),(0,z.jsxs)(`p`,{children:[`也可以新增 `,vT.get(i),`,与团队共享使用。`]})]}),j&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(`header`,{className:h?`configuration-detail-header is-editing`:`configuration-detail-header`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`h2`,{children:s===xs.Create?`新增 ${vT.get(i)}`:j.id}),(0,z.jsxs)(`p`,{children:[vT.get(j.kind),(0,z.jsx)(`span`,{className:`configuration-mode`,children:h?`编辑中`:`只读查看`})]})]}),h?(0,z.jsxs)(`div`,{className:`configuration-actions`,children:[(0,z.jsx)(qo,{variant:`default`,disabled:u,onClick:x,children:`取消编辑`}),(0,z.jsx)(qo,{loading:u,disabled:!o?.id.trim(),onClick:O,children:`保存并同步`})]}):(0,z.jsx)(qo,{disabled:u||f,onClick:b,children:`编辑`}),h&&(0,z.jsxs)(`div`,{className:`configuration-header-feedback`,children:[(0,z.jsx)(`p`,{children:`保存后将同步到团队工作区,团队成员共享此配置。`}),c&&(0,z.jsxs)(po,{color:`red`,role:`alert`,children:[c,(0,z.jsx)(`div`,{children:`编辑内容已保留,可重试保存。`})]})]})]}),(0,z.jsxs)(`div`,{className:`configuration-detail-body`,children:[h&&(0,z.jsxs)(`section`,{className:`configuration-section`,children:[(0,z.jsx)(`h3`,{children:`基本信息`}),(0,z.jsxs)(`label`,{className:`configuration-field`,children:[`名称 / ID`,(0,z.jsx)(`input`,{autoCapitalize:`none`,disabled:u,value:j.id,onChange:S,readOnly:s!==xs.Create,placeholder:`例如 team-review`}),(0,z.jsx)(`span`,{className:`configuration-hint`,children:s===xs.Create?`使用字母、数字、短横线或下划线。`:`已有资源的 ID 保持不变,工作流通过它关联资源。`})]})]}),h&&i===`mcp`&&(0,z.jsxs)(`section`,{className:`configuration-section`,children:[(0,z.jsx)(`h3`,{children:`连接设置`}),(0,z.jsxs)(`div`,{className:`configuration-fields`,children:[(0,z.jsxs)(`label`,{className:`configuration-field`,children:[`启动命令`,(0,z.jsx)(`input`,{autoCapitalize:`none`,name:`command`,value:typeof N?.command==`string`?N.command:``,disabled:u||!N,onChange:ee,placeholder:`本机已安装的程序`})]}),(0,z.jsxs)(`label`,{className:`configuration-field`,children:[`服务地址`,(0,z.jsx)(`input`,{autoCapitalize:`none`,name:`url`,value:typeof N?.url==`string`?N.url:``,disabled:u||!N,onChange:ee,placeholder:`https://…`})]})]})]}),(0,z.jsxs)(`section`,{className:`configuration-section`,children:[(0,z.jsxs)(`div`,{className:`configuration-document-bar`,children:[j.files.length>1?(0,z.jsxs)(`label`,{className:`configuration-file-picker`,children:[`文件`,(0,z.jsx)(`select`,{disabled:u,value:M?.path??``,onChange:C,children:j.files.map(({path:e})=>(0,z.jsx)(`option`,{value:e,children:e.split(`/`).slice(4).join(`/`)||e},e))})]}):(0,z.jsx)(`span`,{children:I||(i===`mcp`?`MCP 配置`:`资源内容`)}),!h&&F&&(0,z.jsx)(qo,{variant:`subtle`,color:`gray`,size:`compact-sm`,onClick:T,children:m?`返回预览`:`查看源码`})]}),h?(0,z.jsxs)(`label`,{className:`configuration-field`,children:[i===`mcp`?`MCP JSON`:`正文与元数据`,(0,z.jsx)(`textarea`,{autoCapitalize:`none`,className:`configuration-code-editor`,disabled:u,rows:18,value:M?.content??``,onChange:E,spellCheck:!1}),(0,z.jsx)(`span`,{className:`configuration-hint`,children:i===`mcp`?`可粘贴完整服务配置,额外字段会保留。`:`直接编辑源文件,保留 Markdown 与文件头元数据。`})]}):F&&!m?(0,z.jsx)(pT,{content:M?.content??``}):(0,z.jsx)(`pre`,{className:`configuration-content`,tabIndex:0,children:M?.content||`(内容为空)`})]})]}),!h&&(0,z.jsxs)(`footer`,{className:`configuration-footer`,children:[(0,z.jsx)(`p`,{children:`保存后将同步到团队工作区,团队成员共享此配置。`}),(0,z.jsx)(`div`,{className:`configuration-actions`,children:(0,z.jsx)(qo,{variant:`subtle`,color:`red`,loading:u,disabled:f,onClick:k,children:`删除资源`})})]})]})]})]})]})});var bT=class extends Error{code;constructor(e,t){super(t),this.name=`PenpalError`,this.code=e}},xT=e=>({name:e.name,message:e.message,stack:e.stack,penpalCode:e instanceof bT?e.code:void 0}),ST=({name:e,message:t,stack:n,penpalCode:r})=>{let i=r?new bT(r,t):Error(t);return i.name=e,i.stack=n,i},CT=class{value;transferables;constructor(e,t){this.value=e,this.transferables=t?.transferables}},wT=`penpal`,TT=e=>typeof e==`object`&&!!e,ET=e=>typeof e==`function`,DT=e=>TT(e)&&e.namespace===wT,OT=e=>e.type===`SYN`,kT=e=>e.type===`ACK1`,AT=e=>e.type===`ACK2`,jT=e=>e.type===`CALL`,MT=e=>e.type===`REPLY`,NT=e=>e.type===`DESTROY`,PT=(e,t=[])=>{let n=[];for(let r of Object.keys(e)){let i=e[r];ET(i)?n.push([...t,r]):TT(i)&&n.push(...PT(i,[...t,r]))}return n},FT=(e,t)=>{let n=e.reduce((e,t)=>TT(e)?e[t]:void 0,t);return ET(n)?n:void 0},IT=e=>e.join(`.`),LT=(e,t,n)=>({namespace:wT,channel:e,type:`REPLY`,callId:t,isError:!0,...n instanceof Error?{value:xT(n),isSerializedErrorInstance:!0}:{value:n}}),RT=(e,t,n,r)=>{let i=!1,a=async a=>{if(i||!jT(a))return;r?.(`Received ${IT(a.methodPath)}() call`,a);let{methodPath:o,args:s,id:c}=a,l,u;try{let e=FT(o,t);if(!e)throw new bT(`METHOD_NOT_FOUND`,`Method \`${IT(o)}\` is not found.`);let r=await e(...s);r instanceof CT&&(u=r.transferables,r=await r.value),l={namespace:wT,channel:n,type:`REPLY`,callId:c,value:r}}catch(e){l=LT(n,c,e)}if(!i)try{r?.(`Sending ${IT(o)}() reply`,l),e.sendMessage(l,u)}catch(t){throw t.name===`DataCloneError`&&(l=LT(n,c,t),r?.(`Sending ${IT(o)}() reply`,l),e.sendMessage(l)),t}};return e.addMessageHandler(a),()=>{i=!0,e.removeMessageHandler(a)}},zT=crypto.randomUUID?.bind(crypto)??(()=>[,,,,].fill(0).map(()=>Math.floor(Math.random()*(2**53-1)).toString(16)).join(`-`)),BT=class{transferables;timeout;constructor(e){this.transferables=e?.transferables,this.timeout=e?.timeout}},VT=new Set([`apply`,`call`,`bind`]),HT=(e,t,n=[])=>new Proxy(n.length?()=>{}:Object.create(null),{get(r,i){if(i!==`then`)return n.length&&VT.has(i)?Reflect.get(r,i):HT(e,t,[...n,i])},apply(t,r,i){return e(n,i)}}),UT=e=>new bT(`CONNECTION_DESTROYED`,`Method call ${IT(e)}() failed due to destroyed connection`),WT=(e,t,n)=>{let r=!1,i=new Map,a=e=>{if(!MT(e))return;let{callId:t,value:r,isError:a,isSerializedErrorInstance:o}=e,s=i.get(t);s&&(i.delete(t),n?.(`Received ${IT(s.methodPath)}() call`,e),a?s.reject(o?ST(r):r):s.resolve(r))};return e.addMessageHandler(a),{remoteProxy:HT((a,o)=>{if(r)throw UT(a);let s=zT(),c=o[o.length-1],l=c instanceof BT,{timeout:u,transferables:d}=l?c:{},f=l?o.slice(0,-1):o;return new Promise((r,o)=>{let c=u===void 0?void 0:window.setTimeout(()=>{i.delete(s),o(new bT(`METHOD_CALL_TIMEOUT`,`Method call ${IT(a)}() timed out after ${u}ms`))},u);i.set(s,{methodPath:a,resolve:r,reject:o,timeoutId:c});try{let r={namespace:wT,channel:t,type:`CALL`,id:s,methodPath:a,args:f};n?.(`Sending ${IT(a)}() call`,r),e.sendMessage(r,d)}catch(e){o(new bT(`TRANSMISSION_FAILED`,e.message))}})},n),destroy:()=>{r=!0,e.removeMessageHandler(a);for(let{methodPath:e,reject:t,timeoutId:n}of i.values())clearTimeout(n),t(UT(e));i.clear()}}},GT=()=>{let e,t;return{promise:new Promise((n,r)=>{e=n,t=r}),resolve:e,reject:t}},KT=`deprecated-penpal`,qT=e=>TT(e)&&`penpal`in e,JT=e=>e.split(`.`),YT=e=>e.join(`.`),XT=e=>{try{return JSON.stringify(e)}catch{return String(e)}},ZT=e=>new bT(`TRANSMISSION_FAILED`,`Unexpected message to translate: ${XT(e)}`),QT=e=>{if(e.penpal===`syn`)return{namespace:wT,channel:void 0,type:`SYN`,participantId:KT};if(e.penpal===`ack`)return{namespace:wT,channel:void 0,type:`ACK2`};if(e.penpal===`call`)return{namespace:wT,channel:void 0,type:`CALL`,id:e.id,methodPath:JT(e.methodName),args:e.args};if(e.penpal===`reply`)return e.resolution===`fulfilled`?{namespace:wT,channel:void 0,type:`REPLY`,callId:e.id,value:e.returnValue}:{namespace:wT,channel:void 0,type:`REPLY`,callId:e.id,isError:!0,...e.returnValueIsError?{value:e.returnValue,isSerializedErrorInstance:!0}:{value:e.returnValue}};throw ZT(e)},$T=e=>{if(kT(e))return{penpal:`synAck`,methodNames:e.methodPaths.map(YT)};if(jT(e))return{penpal:`call`,id:e.id,methodName:YT(e.methodPath),args:e.args};if(MT(e))return e.isError?{penpal:`reply`,id:e.callId,resolution:`rejected`,...e.isSerializedErrorInstance?{returnValue:e.value,returnValueIsError:!0}:{returnValue:e.value}}:{penpal:`reply`,id:e.callId,resolution:`fulfilled`,returnValue:e.value};throw ZT(e)},eE=({messenger:e,methods:t,timeout:n,channel:r,log:i})=>{let a=zT(),o,s=[],c=!1,l=PT(t),{promise:u,resolve:d,reject:f}=GT(),p=n===void 0?void 0:setTimeout(()=>{f(new bT(`CONNECTION_TIMEOUT`,`Connection timed out after ${n}ms`))},n),m=()=>{for(let e of s)e()},h=()=>{if(c)return;s.push(RT(e,t,r,i));let{remoteProxy:n,destroy:a}=WT(e,r,i);s.push(a),clearTimeout(p),c=!0,d({remoteProxy:n,destroy:m})},g=()=>{let t={namespace:wT,type:`SYN`,channel:r,participantId:a};i?.(`Sending handshake SYN`,t);try{e.sendMessage(t)}catch(e){f(new bT(`TRANSMISSION_FAILED`,e.message))}},_=t=>{if(i?.(`Received handshake SYN`,t),t.participantId===o&&o!==KT||(o=t.participantId,g(),!(a>o||o===KT)))return;let n={namespace:wT,channel:r,type:`ACK1`,methodPaths:l};i?.(`Sending handshake ACK1`,n);try{e.sendMessage(n)}catch(e){f(new bT(`TRANSMISSION_FAILED`,e.message));return}},v=t=>{i?.(`Received handshake ACK1`,t);let n={namespace:wT,channel:r,type:`ACK2`};i?.(`Sending handshake ACK2`,n);try{e.sendMessage(n)}catch(e){f(new bT(`TRANSMISSION_FAILED`,e.message));return}h()},y=e=>{i?.(`Received handshake ACK2`,e),h()},b=e=>{OT(e)&&_(e),kT(e)&&v(e),AT(e)&&y(e)};return e.addMessageHandler(b),s.push(()=>e.removeMessageHandler(b)),g(),u},tE=e=>{let t=!1,n;return(...r)=>(t||(t=!0,n=e(...r)),n)},nE=new WeakSet,rE=({messenger:e,methods:t={},timeout:n,channel:r,log:i})=>{if(!e)throw new bT(`INVALID_ARGUMENT`,`messenger must be defined`);if(nE.has(e))throw new bT(`INVALID_ARGUMENT`,`A messenger can only be used for a single connection`);nE.add(e);let a=[e.destroy],o=tE(t=>{if(t){let t={namespace:wT,channel:r,type:`DESTROY`};try{e.sendMessage(t)}catch{}}for(let e of a)e();i?.(`Connection destroyed`)}),s=e=>DT(e)&&e.channel===r;return{promise:(async()=>{try{e.initialize({log:i,validateReceivedMessage:s}),e.addMessageHandler(e=>{NT(e)&&o(!1)});let{remoteProxy:c,destroy:l}=await eE({messenger:e,methods:t,timeout:n,channel:r,log:i});return a.push(l),c}catch(e){throw o(!0),e}})(),destroy:()=>{o(!0)}}},iE=class{#e;#t;#n;#r;#i;#a=new Set;#o;#s=!1;constructor({remoteWindow:e,allowedOrigins:t}){if(!e)throw new bT(`INVALID_ARGUMENT`,`remoteWindow must be defined`);this.#e=e,this.#t=t?.length?t:[window.origin]}initialize=({log:e,validateReceivedMessage:t})=>{this.#n=e,this.#r=t,window.addEventListener(`message`,this.#d)};sendMessage=(e,t)=>{if(OT(e)){let n=this.#l(e);this.#e.postMessage(e,{targetOrigin:n,transfer:t});return}if(kT(e)||this.#s){let n=this.#s?$T(e):e,r=this.#l(e);this.#e.postMessage(n,{targetOrigin:r,transfer:t});return}if(AT(e)){let{port1:n,port2:r}=new MessageChannel;this.#o=n,n.addEventListener(`message`,this.#f),n.start();let i=[r,...t||[]],a=this.#l(e);this.#e.postMessage(e,{targetOrigin:a,transfer:i});return}if(this.#o){this.#o.postMessage(e,{transfer:t});return}throw new bT(`TRANSMISSION_FAILED`,`Cannot send message because the MessagePort is not connected`)};addMessageHandler=e=>{this.#a.add(e)};removeMessageHandler=e=>{this.#a.delete(e)};destroy=()=>{window.removeEventListener(`message`,this.#d),this.#u(),this.#a.clear()};#c=e=>this.#t.some(t=>t instanceof RegExp?t.test(e):t===e||t===`*`);#l=e=>{if(OT(e))return`*`;if(!this.#i)throw new bT(`TRANSMISSION_FAILED`,`Cannot send message because the remote origin is not established`);return this.#i===`null`&&this.#t.includes(`*`)?`*`:this.#i};#u=()=>{this.#o?.removeEventListener(`message`,this.#f),this.#o?.close(),this.#o=void 0};#d=({source:e,origin:t,ports:n,data:r})=>{if(e===this.#e){if(qT(r)){this.#n?.(`Please upgrade the child window to the latest version of Penpal.`),this.#s=!0;try{r=QT(r)}catch(e){this.#n?.(`Failed to translate deprecated message: ${e.message}`);return}}if(this.#r?.(r)){if(!this.#c(t)){this.#n?.(`Received a message from origin \`${t}\` which did not match allowed origins \`[${this.#t.join(`, `)}]\``);return}if(OT(r)&&(this.#u(),this.#i=t),AT(r)&&!this.#s){if(this.#o=n[0],!this.#o){this.#n?.(`Ignoring ACK2 because it did not include a MessagePort`);return}this.#o.addEventListener(`message`,this.#f),this.#o.start()}for(let e of this.#a)e(r)}}};#f=({data:e})=>{if(this.#r?.(e))for(let t of this.#a)t(e)}};function aE(e,t){let n=e?.onInit,r=t?.connectToHost,i=t?.targetWindow;if(typeof n!=`function`)throw TypeError(`defineWorkbasePluginUi requires an onInit callback.`);if(!i||typeof r!=`function`)throw TypeError(`Plugin UI transport is unavailable.`);let a={fatalReportPromise:null,isInitialized:!1,contentHeight:null,recoverableHostErrors:new WeakSet},o=new Set,s=r({executionChanged:async e=>{a.isInitialized&&[...o].forEach(t=>t(e))},initialize:async e=>{hE(e),a.isInitialized=!0,await n(e),await dE(i),await mE(c,{targetWindow:i,state:a})}}),c=s.promise,l=oE(c,a);return lE({connection:s,state:a,targetWindow:i}),cE(l,{targetWindow:i,subscribe:async e=>{let t=t=>e(t);o.add(t);try{await l(`command.subscribe`,{enabled:!0})}catch(e){throw o.delete(t),e}return async()=>{o.delete(t)&&!o.size&&await l(`command.subscribe`,{enabled:!1})}}})}function oE(e,t){return async(n,r)=>{if(!t.isInitialized)throw Error(`Plugin UI is not initialized.`);let i=await(await e).call(n,r);if(yE(i)&&i.ok===!0)return i.result;let a=sE(i);throw t.recoverableHostErrors.add(a),a}}function sE(e){let t=yE(e)&&yE(e.error)?e.error:null,n=typeof t?.message==`string`?t.message:`Host action failed.`,r=typeof t?.code==`string`?t.code:`host_error`;return Object.assign(Error(n),{code:r})}function cE(e,{targetWindow:t,subscribe:n}){let r=Object.freeze({subscribe:n,reply:t=>e(`command.reply`,{executionId:t}),clear:t=>e(`command.clear`,t===void 0?{}:{executionId:t}),start:(n,r,i={})=>e(`command.start`,{commandId:n,input:r,executionId:i.executionId??t.crypto.randomUUID()}),query:t=>e(`command.query`,{executionId:t??null}),cancel:t=>e(`command.cancel`,{executionId:t}),execute:(n,r,i={})=>e(`command.execute`,{commandId:n,executionId:i.executionId??t.crypto.randomUUID(),input:r})}),i=Object.freeze({resolve:(t,n)=>e(`status.resolve`,{input:n,statusId:t})}),a=Object.freeze({call:(t,n)=>e(`view.call`,{input:n,method:t})});return Object.freeze({dismiss:()=>e(`interaction.dismiss`,{}),respond:t=>e(`interaction.respond`,{value:t}),closeOutput:t=>e(`output.close`,{id:t}),commands:r,desktop:Object.freeze({open:t=>e(`desktop.open`,t)}),navigate:(t,{replace:n=!1}={})=>e(`navigate`,{replace:n,to:t}),openOutput:t=>e(`output.open`,t),selectFiles:(t={})=>e(`file.select`,t),showPrompt:t=>e(`dialog.prompt`,t),showToast:t=>e(`toast.show`,t),status:i,updateOutput:t=>e(`output.update`,t),view:a})}function lE({connection:e,state:t,targetWindow:n}){let r=null,i=n=>{(n.error||n.message!==`ResizeObserver loop completed with undelivered notifications.`&&n.message!==`ResizeObserver loop limit exceeded`)&&fE(e.promise,t,n.error??n.message)},a=n=>{n.reason instanceof Error&&t.recoverableHostErrors.has(n.reason)||fE(e.promise,t,n.reason)},o=new n.ResizeObserver(()=>{r===null&&(r=n.requestAnimationFrame(()=>{r=null,t.isInitialized&&mE(e.promise,{targetWindow:n,state:t})}))}),s=()=>{n.removeEventListener(`error`,i,!0),n.removeEventListener(`unhandledrejection`,a),n.removeEventListener(`beforeunload`,s),o.disconnect(),r!==null&&n.cancelAnimationFrame(r),e.destroy(),t.fatalReportPromise=null,t.isInitialized=!1};uE(e.promise),o.observe(n.document.body??n.document.documentElement),n.addEventListener(`error`,i,!0),n.addEventListener(`unhandledrejection`,a),n.addEventListener(`beforeunload`,s,{once:!0})}async function uE(e){try{await e}catch{}}async function dE(e){await new Promise(t=>{e.requestAnimationFrame(()=>{e.requestAnimationFrame(()=>t())})})}async function fE(e,t,n){t.fatalReportPromise||=pE(e,bE(n).slice(0,1e3)),await t.fatalReportPromise}async function pE(e,t){try{await(await e).reportFatal(t)}catch{}}async function mE(e,{targetWindow:t,state:n}){let r=t.document.body??t.document.documentElement,i=Math.max(r.offsetHeight,r.scrollHeight);if(Number.isFinite(i))try{let t=await e,r=Math.min(Math.max(Math.ceil(i),1),1e4);if(!n.isInitialized||n.contentHeight===r)return;n.contentHeight=r,await t.reportContentHeight(r)}catch{}}function hE(e){if(!gE(e))throw TypeError(`Plugin UI initialization payload is invalid.`)}function gE(e){return yE(e)?_E(e.project)&&_E(e.workspace)&&vE(e.view):!1}function _E(e){return yE(e)&&typeof e.id==`string`&&e.id.length>0}function vE(e){return _E(e)&&yE(e)&&typeof e.pluginId==`string`&&e.pluginId.length>0&&typeof e.title==`string`&&e.title.length>0}function yE(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function bE(e){return e instanceof Error?e.message:typeof e==`string`&&e.trim().length>0?e:`Plugin UI failed.`}function xE(e){let t=window;return aE(e,{connectToHost:e=>SE(t,e),targetWindow:t})}function SE(e,t){let n=rE({channel:`workbase-plugin-ui-v1`,messenger:new iE({allowedOrigins:CE(e),remoteWindow:e.parent}),methods:t});return{destroy:n.destroy,promise:n.promise}}function CE(e){let t=new URL(e.location.href).searchParams.get(`__workbaseHostOrigin`);return t&&t!==`null`?[t]:[`*`]}function wE(e,t){return t?`配置有未保存修改,请先保存后再同步。`:e.configured?e.autoSync?`进入工作区时自动同步,也可手动同步当前变动。`:`自动同步已关闭,可手动同步当前变动。`:`初始化后即可生成所选客户端的规则与技能。`}function TE(e){if(!e)throw Error(`AI Rules UI 尚未初始化。`);return e}function EE(e){if(!qE(e)||typeof e.autoSync!=`boolean`||typeof e.configured!=`boolean`||typeof e.configPath!=`string`||typeof e.workspaceRoot!=`string`||!JE(e.features)||!JE(e.targets)||!YE(e.lastOperation))throw Error(`AI Rules 状态响应无效。`);return{autoSync:e.autoSync,configured:e.configured,configPath:e.configPath,features:e.features,lastOperation:e.lastOperation,targets:e.targets,workspaceRoot:e.workspaceRoot}}function DE(e){if(!qE(e))throw Error(`AI Rules 命令响应无效。`);return{result:FE(e.result),status:EE(e.status)}}function OE(e){let t=qE(e.details)?e.details:{},n=qE(t.generation)?t.generation:t,r=IE(n),i=LE(r.features),a=RE(r.diagnostics),o=UE(r.totalFiles)??i.reduce((e,t)=>e+t.count,0),s=GE([...e.warnings,...WE(t.warnings),...WE(n.warnings)]);return{description:BE(e.operation,o),diagnostics:a,features:i,title:VE(e.operation),totalFiles:o,warnings:s}}function kE(e){return{autoSync:e.autoSync,features:[...e.features],targets:[...e.targets]}}function AE(e,t){return e.autoSync===t.autoSync&&KE(e.features,t.features)&&KE(e.targets,t.targets)}function jE({values:e,value:t,isSelected:n}){return n?e.includes(t)?[...e]:[...e,t]:e.filter(e=>e!==t)}function ME(e){return{check:`一致性校验`,doctor:`配置诊断`,initialize:`初始化`,install:`安装来源`,inject:`注入 AI 上下文`,uninject:`撤销 AI 上下文注入`,preview:`预览`,"sources.update":`更新远端来源`,sync:`同步`}[e]??e}function NE(e){return new Date(e).toLocaleString(`zh-CN`)}function PE(e){return e instanceof Error?e.message:`AI Rules 操作失败。`}function FE(e){if(!qE(e)||typeof e.completedAt!=`string`||typeof e.operation!=`string`||typeof e.success!=`boolean`||!JE(e.warnings))throw Error(`AI Rules 执行结果无效。`);return{completedAt:e.completedAt,details:e.details,operation:e.operation,success:e.success,warnings:e.warnings}}function IE(e){return qE(e)?qE(e.data)?e.data:e:{}}function LE(e){return qE(e)?Object.entries(e).flatMap(([e,t])=>{if(!qE(t))return[];let n=UE(t.count)??0;return n===0?[]:[{count:n,id:e,label:HE(e),paths:WE(t.paths).slice(0,30)}]}):[]}function RE(e){return Array.isArray(e)?zE(e.flatMap(e=>!qE(e)||typeof e.message!=`string`?[]:[{hint:typeof e.hint==`string`?e.hint:null,message:e.message,severity:typeof e.severity==`string`?e.severity:`info`}])).slice(0,50):[]}function zE(e){let t=new Set;return e.filter(e=>{let n=`${e.severity}:${e.message}:${e.hint??``}`;return!t.has(n)&&(t.add(n),!0)})}function BE(e,t){return e===`preview`?t>0?`以下 ${t} 个文件会在同步时更新。`:`当前客户端配置已经是最新状态。`:e===`doctor`?`已完成 Rulesync 配置检查。`:e===`check`?t>0?`发现尚未同步的客户端文件。`:`客户端文件与规则源一致。`:t>0?`已处理 ${t} 个客户端文件。`:`操作已完成,没有文件需要更新。`}function VE(e){return{check:`一致性校验结果`,doctor:`配置诊断结果`,initialize:`初始化与同步结果`,preview:`变更预览`,"sources.update":`远端更新与同步结果`,sync:`同步结果`}[e]??`执行结果`}function HE(e){return{activation:`Activation`,checks:`Checks`,commands:`Commands`,hooks:`Hooks`,ignore:`Ignore`,mcp:`MCP`,permissions:`Permissions`,rules:`Rules`,skills:`技能`,subagents:`Subagents`}[e]??e}function UE(e){return typeof e==`number`&&Number.isFinite(e)?e:null}function WE(e){return JE(e)?e:[]}function GE(e){return[...new Set(e)]}function KE(e,t){return e.length===t.length&&e.every((e,n)=>e===t[n])}function qE(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function JE(e){return Array.isArray(e)&&e.every(e=>typeof e==`string`)}function YE(e){return e===null||qE(e)&&typeof e.completedAt==`string`&&typeof e.operation==`string`&&typeof e.success==`boolean`}function XE(){let[e,t]=(0,O.useState)(``),[n,r]=(0,O.useState)(``),[i,a]=(0,O.useState)(!0),[o,s]=(0,O.useState)(!1),c=(0,O.useCallback)(()=>a(!0),[]),l=(0,O.useCallback)(()=>a(!1),[]),u=(0,O.useCallback)(()=>s(!0),[]),d=(0,O.useRef)(null),f=(0,O.useRef)(null),p=(0,O.useRef)(0),m=(0,O.useRef)(null),h=(0,O.useRef)(!1),g=(0,O.useRef)(null),[_,v]=(0,O.useState)(!1),[y,b]=(0,O.useState)(null),[x,S]=(0,O.useState)(null),[C,w]=(0,O.useState)(null),[T,E]=(0,O.useState)(null),[ee,D]=(0,O.useState)(null),k=(0,O.useCallback)((e,t=!1)=>{let n=m.current;m.current=e,b(e),S(r=>!t&&r&&n&&!AE(n,r)?r:kE(e))},[]),A=(0,O.useCallback)(async()=>{if(h.current)return;if(g.current)return g.current;let e=TE(d.current),t=p.current;return v(!0),g.current=(async()=>{try{let n=EE(await e.status.resolve(`sync`,{}));if(t!==p.current)return;k(n),E(null)}catch(e){t===p.current&&E(PE(e))}finally{t===p.current&&(g.current=null,v(!1))}})(),g.current},[k]),j=(0,O.useCallback)(e=>{let n=JSON.stringify([e.project.id,e.workspace.id]);f.current!==n&&(f.current=n,p.current+=1,m.current=null,g.current=null,h.current=!1,t(n),r(e.workspace.id),s(!1),b(null),S(null),w(null),E(null),D(null),A())},[A]);(0,O.useEffect)(()=>(d.current=xE({onInit:j}),()=>{p.current+=1,d.current=null}),[j]);let M=(0,O.useCallback)(async({commandId:e})=>{if(h.current)return;h.current=!0;let t=++p.current;g.current=null,v(!1);let n=TE(d.current);w(e),E(null);try{let r=await n.commands.execute(e,{}),i=DE(r.value);if(t!==p.current)return;k(i.status),D({logId:r.logId,result:i.result})}catch(e){t===p.current&&E(PE(e))}finally{t===p.current&&(h.current=!1,w(null))}},[k]),N=(0,O.useCallback)(async({commandId:e,message:t,title:n})=>{let r=TE(d.current),i=p.current;try{await r.showPrompt({message:t,submitLabel:`继续`,title:n,type:`confirm`})===!0&&i===p.current&&await M({commandId:e})}catch(e){i===p.current&&E(PE(e))}},[M]);return{resourceKey:e,workspaceId:n,isResourceMode:i,isEditingSync:o,handleResourceMode:c,handleSyncMode:l,handleEditSync:u,pluginUiRef:d,contextKeyRef:f,isRefreshing:_,status:y,draft:x,busyCommand:C,error:T,operationDialog:ee,refreshStatus:A,handleSave:(0,O.useCallback)(async()=>{if(!x||h.current)return;h.current=!0;let e=++p.current;g.current=null,v(!1);let t=TE(d.current);w(`configuration.save`),E(null);try{let n=await t.commands.execute(`configuration.save`,x),r=EE(n.value);if(e!==p.current)return;k(r,!0),s(!1),await t.showToast({description:Ss(n.publication),title:`同步配置已保存`})}catch(t){e===p.current&&E(PE(t))}finally{e===p.current&&(h.current=!1,w(null))}},[k,x]),handleCancelSync:(0,O.useCallback)(()=>{y&&S(kE(y)),s(!1)},[y]),handleTargetToggle:(0,O.useCallback)((e,t)=>{S(n=>n&&{...n,targets:jE({values:n.targets,value:e,isSelected:t})})},[]),handleFeatureToggle:(0,O.useCallback)((e,t)=>{S(n=>n&&{...n,features:jE({values:n.features,value:e,isSelected:t})})},[]),handleAutoSyncChange:(0,O.useCallback)(e=>{let t=e.currentTarget.checked;S(e=>e&&{...e,autoSync:t})},[]),handleSync:(0,O.useCallback)(()=>N({commandId:`sync`,message:`将规则更新到当前 Workspace 中已选择客户端的 AI 上下文文件。`,title:`同步 AI 上下文`}),[N]),handleInitialize:(0,O.useCallback)(()=>N({commandId:`initialize`,message:`将在项目根目录的 rules 文件夹中创建 Rulesync 配置,并立即生成当前 Workspace 的 AI 上下文。`,title:`初始化并同步`}),[N]),handleUpdateSources:(0,O.useCallback)(()=>N({commandId:`sources.update`,message:`将更新远端规则版本、锁文件和当前 Workspace 的客户端配置。`,title:`更新远端并同步`}),[N]),handlePreview:(0,O.useCallback)(()=>M({commandId:`preview`}),[M]),handleDoctor:(0,O.useCallback)(()=>M({commandId:`doctor`}),[M]),handleCheck:(0,O.useCallback)(()=>M({commandId:`check`}),[M]),handleOpenLog:(0,O.useCallback)(async()=>{ee?.logId&&await TE(d.current).navigate(`/logs/${ee.logId}`)},[ee]),handleCloseResult:(0,O.useCallback)(()=>D(null),[]),isBusy:C!==null,isConfigurationValid:!!(x&&x.targets.length>0&&x.features.length>0),isDirty:(0,O.useMemo)(()=>y!==null&&x!==null&&!AE(y,x),[x,y]),operationPresentation:(0,O.useMemo)(()=>ee?OE(ee.result):null,[ee]),statusColor:y?.configured?`teal`:`orange`}}const ZE=[{label:`Codex CLI`,value:`codexcli`},{label:`Claude Code`,value:`claudecode`}],QE=[{label:`规则`,value:`rules`},{label:`MCP`,value:`mcp`},{label:`命令`,value:`commands`},{label:`子代理`,value:`subagents`},{label:`技能`,value:`skills`}],$E=(0,O.memo)(function(){let{resourceKey:e,workspaceId:t,isResourceMode:n,isEditingSync:r,handleResourceMode:i,handleSyncMode:a,handleEditSync:o,pluginUiRef:s,contextKeyRef:c,isRefreshing:l,status:u,draft:d,busyCommand:f,error:p,operationDialog:m,refreshStatus:h,handleSave:g,handleCancelSync:_,handleTargetToggle:v,handleFeatureToggle:y,handleAutoSyncChange:b,handleSync:x,handleInitialize:S,handleUpdateSources:C,handlePreview:w,handleDoctor:T,handleCheck:E,handleOpenLog:ee,handleCloseResult:D,isBusy:O,isConfigurationValid:k,isDirty:A,operationPresentation:j,statusColor:M}=XE(),N=u?.configured?`可同步`:`待初始化`,P=O?`正在处理`:N,F=f===`preview`?`预览中…`:`预览变更`,I=f===`sync`?`同步中…`:`同步当前变动`,te=f===`initialize`?`初始化中…`:`初始化并同步`,ne=u?.lastOperation?.success?`成功`:`失败`;return(0,z.jsxs)(`main`,{className:`app-shell`,children:[(0,z.jsxs)(`header`,{className:`page-header`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`h1`,{children:n?`AI 资源`:`AI 上下文同步`}),(0,z.jsx)(`p`,{className:`page-description`,children:n?`管理团队共享的规则、技能与 AI 连接。`:`将团队规则与技能同步到当前工作区的 AI 客户端。`})]}),(0,z.jsx)(qo,{hidden:n,variant:`subtle`,loading:l,disabled:O||!c.current,onClick:h,children:`刷新状态`})]}),(0,z.jsxs)(`nav`,{className:`configuration-page-tabs`,"aria-label":`AI Rules 模式`,children:[(0,z.jsx)(`button`,{type:`button`,"aria-pressed":n,onClick:i,children:`资源配置`}),(0,z.jsx)(`button`,{type:`button`,"aria-pressed":!n,onClick:a,children:`客户端同步`})]}),s.current&&t&&(0,z.jsx)(`div`,{className:`configuration-view`,hidden:!n,children:(0,z.jsx)(yT,{host:s.current,isActive:n,workspaceId:t},e)}),(0,z.jsxs)(`div`,{hidden:n,children:[p?(0,z.jsxs)(po,{color:`red`,title:u?`本次操作失败,保留当前配置`:`无法读取同步配置`,children:[p,` 请刷新状态重试。`]}):null,!u&&!p?(0,z.jsxs)(`p`,{className:`loading-message`,role:`status`,children:[(0,z.jsx)(pi,{size:`xs`}),`正在读取同步配置…`]}):null,u?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(`section`,{className:`sync-overview`,"aria-labelledby":`sync-title`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(Ro,{variant:`light`,color:O?`blue`:M,leftSection:O?(0,z.jsx)(pi,{size:12}):void 0,children:P}),(0,z.jsx)(`p`,{id:`sync-title`,children:wE(u,A)})]}),(0,z.jsx)(`div`,{className:`button-row`,children:u.configured?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(qo,{variant:`default`,className:`button button-secondary`,disabled:O||A,onClick:w,type:`button`,children:F}),(0,z.jsx)(qo,{variant:`filled`,loading:f===`sync`,"aria-busy":f===`sync`,className:`button button-primary`,disabled:O||A,onClick:x,type:`button`,children:I})]}):(0,z.jsx)(qo,{variant:`filled`,loading:f===`initialize`,"aria-busy":f===`initialize`,className:`button button-primary`,disabled:O||A,onClick:S,type:`button`,children:te})})]}),(0,z.jsxs)(`details`,{className:`maintenance configuration-panel`,children:[(0,z.jsxs)(`summary`,{children:[`同步配置`,A?(0,z.jsx)(`span`,{className:`configuration-unsaved`,children:`未保存修改`}):null]}),d?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(`label`,{className:`auto-sync-switch`,children:[(0,z.jsx)(`span`,{className:`auto-sync-copy`,children:(0,z.jsx)(`strong`,{children:`进入工作区时自动同步`})}),(0,z.jsx)(`span`,{className:`switch-control`,children:(0,z.jsx)(gs,{"aria-label":`进入工作区时自动同步`,checked:d.autoSync,disabled:O||!r,onChange:b})})]}),(0,z.jsxs)(`div`,{className:`configuration-layout`,children:[(0,z.jsxs)(`fieldset`,{className:`choice-section`,disabled:O||!r,children:[(0,z.jsx)(`legend`,{children:`目标客户端`}),(0,z.jsx)(`div`,{className:`choice-list`,children:ZE.map(e=>(0,z.jsx)(eD,{isSelected:d.targets.includes(e.value),option:e,onToggle:v},e.value))})]}),(0,z.jsxs)(`fieldset`,{className:`choice-section`,disabled:O||!r,children:[(0,z.jsx)(`legend`,{children:`同步内容`}),(0,z.jsx)(`div`,{className:`feature-grid`,children:QE.map(e=>(0,z.jsx)(eD,{isSelected:d.features.includes(e.value),option:e,onToggle:y},e.value))})]})]})]}):(0,z.jsx)(`p`,{className:`loading-card`,"aria-live":`polite`,children:`正在读取同步配置…`}),(0,z.jsx)(`p`,{className:`configuration-notice`,children:`保存后将同步到团队工作区,团队成员共享此配置。`}),(0,z.jsxs)(`div`,{className:`button-row configuration-actions`,children:[r&&(0,z.jsx)(qo,{variant:`default`,disabled:O,onClick:_,children:`取消编辑`}),!r&&(0,z.jsx)(qo,{variant:`default`,onClick:o,children:`编辑同步配置`}),(0,z.jsx)(qo,{variant:`filled`,className:`button button-primary`,disabled:O||!r||!A||!k,onClick:g,type:`button`,children:f===`configuration.save`?`保存中…`:`保存配置`})]})]}),(0,z.jsxs)(`details`,{className:`maintenance`,children:[(0,z.jsx)(`summary`,{children:`规则维护`}),(0,z.jsxs)(`div`,{className:`maintenance-content`,children:[(0,z.jsxs)(`div`,{className:`button-row`,children:[(0,z.jsx)(qo,{variant:`default`,className:`button button-secondary`,disabled:O||A||!u?.configured,onClick:C,type:`button`,children:f===`sources.update`?`更新中…`:`更新远端并同步`}),(0,z.jsx)(qo,{variant:`default`,className:`button button-secondary`,disabled:O||A||!u?.configured,onClick:T,type:`button`,children:`诊断配置`}),(0,z.jsx)(qo,{variant:`default`,className:`button button-secondary`,disabled:O||A||!u?.configured,onClick:E,type:`button`,children:`校验一致性`})]}),u?.lastOperation?(0,z.jsxs)(`p`,{className:`last-operation`,children:[`最近执行:`,ME(u.lastOperation.operation),` ·`,` `,ne,` · `,NE(u.lastOperation.completedAt)]}):null]})]})]}):null]}),(0,z.jsx)(Ts,{operationDialog:m,handleOpenLog:ee,handleCloseResult:D,operationPresentation:j})]})});function eD({isSelected:e,onToggle:t,option:n}){let r=(0,O.useCallback)(e=>{t(n.value,e.currentTarget.checked)},[t,n.value]);return(0,z.jsxs)(`label`,{className:`choice-field`,"data-selected":e,children:[(0,z.jsx)(Fo,{"aria-label":n.label,checked:e,onChange:r}),(0,z.jsx)(`span`,{children:(0,z.jsx)(`strong`,{children:n.label})})]})}const tD=document.querySelector(`#root`);if(!tD)throw Error(`AI Rules UI root element was not found.`);u(),(0,bs.createRoot)(tD).render((0,z.jsx)(Ut,{theme:f,getStyleNonce:d,forceColorScheme:`light`,children:(0,z.jsx)($E,{})}));
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@eworkbase/plugin-ai-rules",
3
- "version": "0.3.4",
3
+ "version": "0.3.5",
4
4
  "type": "module",
5
5
  "workbase": {
6
6
  "id": "ai-rules",
7
- "title": "AI Rules",
7
+ "title": "AI 规则",
8
8
  "tools": [
9
9
  {
10
10
  "id": "rulesync",
@@ -19,16 +19,10 @@
19
19
  "workbaseVersion": "^0.6.8"
20
20
  },
21
21
  "exports": "./dist/plugin.mjs",
22
- "scripts": {
23
- "build": "tsdown",
24
- "typecheck": "tsc -p tsconfig.json --noEmit && tsc -p tsconfig.ui.json --noEmit",
25
- "pack:local": "pnpm build && pnpm pack"
26
- },
27
22
  "engines": {
28
23
  "node": ">=22"
29
24
  },
30
25
  "devDependencies": {
31
- "@eworkbase/sdk": "workspace:*",
32
26
  "@mantine/core": "^9.6.1",
33
27
  "@mantine/hooks": "^9.6.1",
34
28
  "@tsdown/css": "0.23.0",
@@ -43,7 +37,8 @@
43
37
  "smol-toml": "1.8.0",
44
38
  "tsdown": "0.23.0",
45
39
  "typescript": "^5.8.3",
46
- "yaml": "^2.8.1"
40
+ "yaml": "^2.8.1",
41
+ "@eworkbase/sdk": "0.3.5"
47
42
  },
48
43
  "publishConfig": {
49
44
  "access": "public"
@@ -51,5 +46,10 @@
51
46
  "files": [
52
47
  "dist"
53
48
  ],
54
- "description": "统一维护团队的 AI 规则、技能、命令与 MCP 配置,并生成 Codex、Claude Code 等客户端文件。支持初始化、预览生成结果、检查配置、同步规则和更新规则来源。"
55
- }
49
+ "description": "统一维护团队的 AI 规则、技能、命令与 MCP 配置,并生成 Codex、Claude Code 等客户端文件。支持初始化、预览生成结果、检查配置、同步规则和更新规则来源。",
50
+ "scripts": {
51
+ "build": "tsdown",
52
+ "typecheck": "tsc -p tsconfig.json --noEmit && tsc -p tsconfig.ui.json --noEmit",
53
+ "pack:local": "pnpm build && pnpm pack"
54
+ }
55
+ }