@eworkbase/plugin-ai-rules 0.3.3 → 0.3.4

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
@@ -7883,7 +7883,8 @@ var InjectionWriter = class {
7883
7883
  restoreContent({
7884
7884
  relativePath,
7885
7885
  managed,
7886
- current
7886
+ current,
7887
+ requireApplied: true
7887
7888
  });
7888
7889
  return true;
7889
7890
  } catch {
@@ -7913,6 +7914,17 @@ var InjectionWriter = class {
7913
7914
  writeFileBatch(this.root, desired);
7914
7915
  this.#managed = nextManaged;
7915
7916
  }
7917
+ /** 停止时逐文件撤销,保留冲突文件及其记录,不阻塞其他文件的清理。 */
7918
+ cleanup() {
7919
+ const failures = [];
7920
+ for (const relativePath of this.paths) try {
7921
+ writeFileBatch(this.root, /* @__PURE__ */ new Map([[relativePath, this.baseline(relativePath)]]));
7922
+ this.#managed.delete(relativePath);
7923
+ } catch (error) {
7924
+ failures.push(`${relativePath}:${error instanceof Error ? error.message : "撤销失败"}`);
7925
+ }
7926
+ if (failures.length) throw new Error(`AI Rules 已保留未能安全撤销的文件,请检查后重试:\n${failures.join("\n")}`);
7927
+ }
7916
7928
  };
7917
7929
  /** 只接受源树或客户端树内的相对路径,不跟随符号链接。 */
7918
7930
  function safeFilePath(root, relativePath) {
@@ -8004,13 +8016,15 @@ function mergeContent({ relativePath, before, fragment }) {
8004
8016
  if (before !== null && before !== fragment) throw conflict(relativePath);
8005
8017
  return fragment;
8006
8018
  }
8007
- function restoreContent({ relativePath, managed, current }) {
8019
+ function restoreContent({ relativePath, managed, current, requireApplied = false }) {
8008
8020
  const { before, after } = managed;
8009
8021
  if (current === null) return null;
8010
- if (before === after) return current;
8022
+ if (before === after || !requireApplied && current === before) return current;
8011
8023
  if (current === after) return before;
8012
8024
  if (isStructured(relativePath)) {
8013
8025
  const restored = restoreDocument({
8026
+ location: relativePath,
8027
+ requireApplied,
8014
8028
  original: parseDocument$1(relativePath, before ?? ""),
8015
8029
  applied: parseDocument$1(relativePath, after),
8016
8030
  current: parseDocument$1(relativePath, current)
@@ -8043,13 +8057,16 @@ function mergeDocument(original, patch) {
8043
8057
  }
8044
8058
  return merged;
8045
8059
  }
8046
- function restoreDocument({ original, applied, current }) {
8060
+ function restoreDocument({ location, original, applied, current, requireApplied }) {
8047
8061
  const restored = { ...current };
8048
8062
  Object.entries(applied).forEach(([key, value]) => {
8049
8063
  if (isDeepStrictEqual(original[key], value)) return;
8050
8064
  const actual = current[key];
8065
+ if (!requireApplied && (!Object.hasOwn(current, key) || isDeepStrictEqual(actual, original[key]))) return;
8051
8066
  if (isObject(value) && isObject(actual)) {
8052
8067
  const nested = restoreDocument({
8068
+ location: `${location}.${key}`,
8069
+ requireApplied,
8053
8070
  original: isObject(original[key]) ? original[key] : {},
8054
8071
  applied: value,
8055
8072
  current: actual
@@ -8058,7 +8075,7 @@ function restoreDocument({ original, applied, current }) {
8058
8075
  else delete restored[key];
8059
8076
  return;
8060
8077
  }
8061
- if (!isDeepStrictEqual(value, actual)) throw new Error("AI Rules 注入内容已被修改,请处理冲突后重试撤销。");
8078
+ if (!isDeepStrictEqual(value, actual)) throw new Error(`AI Rules 注入内容已被修改:${location}.${key};已保留当前内容,请处理冲突后重试撤销。`);
8062
8079
  if (Object.hasOwn(original, key)) restored[key] = original[key];
8063
8080
  else delete restored[key];
8064
8081
  });
@@ -8257,7 +8274,7 @@ var InjectionService = class {
8257
8274
  /** 清理不依赖进程或跨插件调用,因此宿主 shutdown 阶段仍可完成撤销。 */
8258
8275
  async cleanup() {
8259
8276
  return this.run(async () => {
8260
- this.#writer.apply(/* @__PURE__ */ new Map());
8277
+ this.#writer.cleanup();
8261
8278
  this.#requests.clear();
8262
8279
  this.#fragments.clear();
8263
8280
  this.#targets = [];
package/dist/ui/main.js CHANGED
@@ -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,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`,{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,{})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eworkbase/plugin-ai-rules",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
4
4
  "type": "module",
5
5
  "workbase": {
6
6
  "id": "ai-rules",