Tools and features

Tools, skills, plugins and modes

Full reference

14 reviewed records from the desktop app and the Agent CLI: the tool schemas the agent is given, and how skills, plugins, project rules and modes are described to it. Each entry gives the exact shipped bytes and their location; schemas are decoded or reconstructed into tables above the bytes they come from.

Tool schemas

Grep tool schema (desktop)

Source: extensions/cursor-agent-exec/dist/main.js (desktop) · bytes 2984945–2985206 · SHA-256 3f700694c678…

Decoded from the shipped protobuf descriptor for GrepArgs; referenced types resolved through Cursor's own generated classes (agent.v1).

No. Field Type Label
1 pattern string —
2 path string optional
3 glob string optional
4 output_mode string optional
5 context_before int32 optional
6 context_after int32 optional
7 context int32 optional
8 case_insensitive bool optional
9 type string optional
10 head_limit int32 optional
11 multiline bool optional
12 sort string optional
13 sort_ascending bool optional
14 tool_call_id string —
15 sandbox_policy SandboxPolicy optional
16 offset int32 optional
Exact shipped text
GrepArgs|1 pattern 9|2 path 9?|3 glob 9?|4 output_mode 9?|5 context_before 5?|6 context_after 5?|7 context 5?|8 case_insensitive 8?|9 type 9?|10 head_limit 5?|11 multiline 8?|12 sort 9?|13 sort_ascending 8?|14 tool_call_id 9|15 sandbox_policy #0?|16 offset 5?

Grep tool schema (Agent CLI)

Source: index.js (Agent CLI) · bytes 5830996–5831257 · SHA-256 3f700694c678…

Decoded from the shipped protobuf descriptor for GrepArgs; referenced types resolved through Cursor's own generated classes (agent.v1).

No. Field Type Label
1 pattern string —
2 path string optional
3 glob string optional
4 output_mode string optional
5 context_before int32 optional
6 context_after int32 optional
7 context int32 optional
8 case_insensitive bool optional
9 type string optional
10 head_limit int32 optional
11 multiline bool optional
12 sort string optional
13 sort_ascending bool optional
14 tool_call_id string —
15 sandbox_policy SandboxPolicy optional
16 offset int32 optional
Exact shipped text
GrepArgs|1 pattern 9|2 path 9?|3 glob 9?|4 output_mode 9?|5 context_before 5?|6 context_after 5?|7 context 5?|8 case_insensitive 8?|9 type 9?|10 head_limit 5?|11 multiline 8?|12 sort 9?|13 sort_ascending 8?|14 tool_call_id 9|15 sandbox_policy #0?|16 offset 5?

MCP invocation schema (desktop)

Source: extensions/cursor-agent-exec/dist/main.js (desktop) · bytes 291909–292120 · SHA-256 e46353b6605e…

Decoded from the shipped protobuf descriptor for McpArgs. This build's fields differ from the Agent CLI's generated class, so referenced types are shown by position.

No. Field Type Label
1 name string —
2 args map<string, referenced type #0> —
3 tool_call_id string —
4 provider_identifier string —
5 tool_name string —
6 smart_mode_approval referenced type #1 optional
7 smart_mode_approval_only bool —
8 skip_approval bool —
9 server_identifier string —
10 symbolic_path_arguments referenced type #2 repeated
Exact shipped text
McpArgs|1 name 9|2 args 9,#0|3 tool_call_id 9|4 provider_identifier 9|5 tool_name 9|6 smart_mode_approval #1?|7 smart_mode_approval_only 8|8 skip_approval 8|9 server_identifier 9|10 symbolic_path_arguments #2*

MCP invocation schema (Agent CLI)

Source: index.js (Agent CLI) · bytes 5864243–5864423 · SHA-256 35298f7263f3…

Decoded from the shipped protobuf descriptor for McpArgs; referenced types resolved through Cursor's own generated classes (agent.v1).

No. Field Type Label
1 name string —
2 args map<string, google.protobuf.Value> —
3 tool_call_id string —
4 provider_identifier string —
5 tool_name string —
6 smart_mode_approval SmartModeApproval optional
7 smart_mode_approval_only bool —
8 skip_approval bool —
9 server_identifier string —
Exact shipped text
McpArgs|1 name 9|2 args 9,#0|3 tool_call_id 9|4 provider_identifier 9|5 tool_name 9|6 smart_mode_approval #1?|7 smart_mode_approval_only 8|8 skip_approval 8|9 server_identifier 9

MCP resource read schema (desktop)

Source: extensions/cursor-agent-exec/dist/main.js (desktop) · bytes 302543–302649 · SHA-256 e0d49a272259…

Decoded from the shipped protobuf descriptor for ReadMcpResourceExecArgs; referenced types resolved through Cursor's own generated classes (agent.v1).

No. Field Type Label
1 server string —
2 uri string —
3 download_path string optional
4 tool_call_id string —
5 smart_mode_approval SmartModeApproval optional
Exact shipped text
ReadMcpResourceExecArgs|1 server 9|2 uri 9|3 download_path 9?|4 tool_call_id 9|5 smart_mode_approval #0?

MCP resource read schema (Agent CLI)

Source: index.js (Agent CLI) · bytes 5874153–5874259 · SHA-256 e0d49a272259…

Decoded from the shipped protobuf descriptor for ReadMcpResourceExecArgs; referenced types resolved through Cursor's own generated classes (agent.v1).

No. Field Type Label
1 server string —
2 uri string —
3 download_path string optional
4 tool_call_id string —
5 smart_mode_approval SmartModeApproval optional
Exact shipped text
ReadMcpResourceExecArgs|1 server 9|2 uri 9|3 download_path 9?|4 tool_call_id 9|5 smart_mode_approval #0?

Shell tool and sandbox request schema (desktop)

Source: extensions/cursor-agent-exec/dist/main.js (desktop) · bytes 3440814–3441358 · SHA-256 e7658649d0c6…

Decoded from the shipped protobuf descriptor for ShellArgs; referenced types resolved through Cursor's own generated classes (agent.v1).

No. Field Type Label
1 command string —
2 working_directory string —
3 timeout int32 —
4 tool_call_id string —
5 simple_commands string repeated
6 has_input_redirect bool —
7 has_output_redirect bool —
8 parsing_result ShellCommandParsingResult —
9 requested_sandbox_policy SandboxPolicy optional
10 file_output_threshold_bytes uint64 optional
11 is_background bool —
12 skip_approval bool —
13 timeout_behavior enum TimeoutBehavior —
14 hard_timeout int32 optional
15 description string optional
16 classifier_result CommandClassifierResult optional
17 close_stdin bool —
18 output_notification ShellOutputNotificationConfig optional
19 smart_mode_approval SmartModeApproval optional
20 hook_approval_requirement ShellHookApprovalRequirement optional
21 conversation_id string optional
22 admin_command_denylist string repeated
23 request_id string optional
24 secret_scope_id string optional
Exact shipped text
ShellArgs|1 command 9|2 working_directory 9|3 timeout 5|4 tool_call_id 9|5 simple_commands 9*|6 has_input_redirect 8|7 has_output_redirect 8|8 parsing_result #0|9 requested_sandbox_policy #1?|10 file_output_threshold_bytes 4?|11 is_background 8|12 skip_approval 8|13 timeout_behavior #2|14 hard_timeout 5?|15 description 9?|16 classifier_result #3?|17 close_stdin 8|18 output_notification #4?|19 smart_mode_approval #5?|20 hook_approval_requirement #6?|21 conversation_id 9?|22 admin_command_denylist 9*|23 request_id 9?|24 secret_scope_id 9?

Shell tool and sandbox request schema (Agent CLI)

Source: index.js (Agent CLI) · bytes 5981410–5981954 · SHA-256 e7658649d0c6…

Decoded from the shipped protobuf descriptor for ShellArgs; referenced types resolved through Cursor's own generated classes (agent.v1).

No. Field Type Label
1 command string —
2 working_directory string —
3 timeout int32 —
4 tool_call_id string —
5 simple_commands string repeated
6 has_input_redirect bool —
7 has_output_redirect bool —
8 parsing_result ShellCommandParsingResult —
9 requested_sandbox_policy SandboxPolicy optional
10 file_output_threshold_bytes uint64 optional
11 is_background bool —
12 skip_approval bool —
13 timeout_behavior enum TimeoutBehavior —
14 hard_timeout int32 optional
15 description string optional
16 classifier_result CommandClassifierResult optional
17 close_stdin bool —
18 output_notification ShellOutputNotificationConfig optional
19 smart_mode_approval SmartModeApproval optional
20 hook_approval_requirement ShellHookApprovalRequirement optional
21 conversation_id string optional
22 admin_command_denylist string repeated
23 request_id string optional
24 secret_scope_id string optional
Exact shipped text
ShellArgs|1 command 9|2 working_directory 9|3 timeout 5|4 tool_call_id 9|5 simple_commands 9*|6 has_input_redirect 8|7 has_output_redirect 8|8 parsing_result #0|9 requested_sandbox_policy #1?|10 file_output_threshold_bytes 4?|11 is_background 8|12 skip_approval 8|13 timeout_behavior #2|14 hard_timeout 5?|15 description 9?|16 classifier_result #3?|17 close_stdin 8|18 output_notification #4?|19 smart_mode_approval #5?|20 hook_approval_requirement #6?|21 conversation_id 9?|22 admin_command_denylist 9*|23 request_id 9?|24 secret_scope_id 9?

Skills, plugins, rules and modes

Agent skills protocol schema

Source: index.js (Agent CLI) · bytes 5753764–5755083 · SHA-256 55ed38660531…

Decoded from Cursor's shipped generated module ../proto/dist/generated/agent/v1/agent_skills_pb.js: 1 message type.

AgentSkill

No. Field Type Label
1 full_path string —
2 content string —
3 description string —
4 parse_error string optional
5 environments string repeated
6 disabled_environments string repeated
7 git_remote_origin string optional
8 disable_model_invocation bool —
9 plugin string optional
10 marketplace string optional
11 plugin_id string optional
12 marketplace_id string optional
13 globs string repeated
14 scoped_to string repeated
Exact shipped text
"../proto/dist/generated/agent/v1/agent_skills_pb.js"(t,e,r){"use strict";r.d(e,{N:()=>a});var n=r("../../../../../../../../../../<build path>"),s=r("../proto/dist/runtime/compact.js");class i extends s.HL{static get runtime(){return(0,s.kU)(this,"runtime",n.C)}static $p(){return"agent.v1."}}class a extends i{constructor(t){super(),this.fullPath="",this.content="",this.description="",this.environments=[],this.disabledEnvironments=[],this.disableModelInvocation=!1,this.globs=[],this.scopedTo=[],n.C.util.initPartial(t,this)}static fromBinary(t,e){return(new a).fromBinary(t,e)}static fromJson(t,e){return(new a).fromJson(t,e)}static fromJsonString(t,e){return(new a).fromJsonString(t,e)}static equals(t,e){return n.C.util.equals(a,t,e)}static $(){return["AgentSkill|1 full_path 9|2 content 9|3 description 9|4 parse_error 9?|5 environments 9*|6 disabled_environments 9*|7 git_remote_origin 9?|8 disable_model_invocation 8|9 plugin 9?|10 marketplace 9?|11 plugin_id 9?|12 marketplace_id 9?|13 globs 9*|14 scoped_to 9*"]}}}

Cursor rules protocol schema

Source: index.js (Agent CLI) · bytes 5796337–5799606 · SHA-256 9bfa7a5cc52a…

Decoded from Cursor's shipped generated module ../proto/dist/generated/agent/v1/cursor_rules_pb.js: 6 message types.

CursorRule

No. Field Type Label
1 full_path string —
2 content string —
3 type CursorRuleType —
4 source enum CursorRuleSource —
5 git_remote_origin string optional
6 parse_error string optional
7 environments string repeated
8 disabled_environments string repeated
9 plugin string optional
10 marketplace string optional
11 plugin_id string optional
12 marketplace_id string optional
13 scoped_to string repeated
14 frontmatter string —
15 is_required bool optional

CursorRuleType

No. Field Type Label
1 global CursorRuleTypeGlobal oneof type
2 file_globbed CursorRuleTypeFileGlobs oneof type
3 agent_fetched CursorRuleTypeAgentFetched oneof type
4 manually_attached CursorRuleTypeManuallyAttached oneof type

CursorRuleTypeAgentFetched

No. Field Type Label
1 description string —

CursorRuleTypeFileGlobs

No. Field Type Label
1 globs string repeated

CursorRuleTypeGlobal

No fields.

CursorRuleTypeManuallyAttached

No fields.

Exact shipped text
"../proto/dist/generated/agent/v1/cursor_rules_pb.js"(t,e,r){"use strict";r.d(e,{DX:()=>p,Xo:()=>l,_u:()=>d,f5:()=>m,i9:()=>c,uT:()=>u});var n=r("../../../../../../../../../../<build path>"),s=r("../proto/dist/runtime/compact.js");const i="agent.v1.";class a extends s.HL{static get runtime(){return(0,s.kU)(this,"runtime",n.C)}static $p(){return i}}var o=(0,s.QT)(n.C,i,"CursorRuleSource",[[0,"UNSPECIFIED"],[1,"TEAM"],[2,"USER"]],1);class c extends a{constructor(t){super(),n.C.util.initPartial(t,this)}static fromBinary(t,e){return(new c).fromBinary(t,e)}static fromJson(t,e){return(new c).fromJson(t,e)}static fromJsonString(t,e){return(new c).fromJsonString(t,e)}static equals(t,e){return n.C.util.equals(c,t,e)}static $(){return["CursorRuleTypeGlobal"]}}class u extends a{constructor(t){super(),this.globs=[],n.C.util.initPartial(t,this)}static fromBinary(t,e){return(new u).fromBinary(t,e)}static fromJson(t,e){return(new u).fromJson(t,e)}static fromJsonString(t,e){return(new u).fromJsonString(t,e)}static equals(t,e){return n.C.util.equals(u,t,e)}static $(){return["CursorRuleTypeFileGlobs|1 globs 9*"]}}class l extends a{constructor(t){super(),this.description="",n.C.util.initPartial(t,this)}static fromBinary(t,e){return(new l).fromBinary(t,e)}static fromJson(t,e){return(new l).fromJson(t,e)}static fromJsonString(t,e){return(new l).fromJsonString(t,e)}static equals(t,e){return n.C.util.equals(l,t,e)}static $(){return["CursorRuleTypeAgentFetched|1 description 9"]}}class d extends a{constructor(t){super(),n.C.util.initPartial(t,this)}static fromBinary(t,e){return(new d).fromBinary(t,e)}static fromJson(t,e){return(new d).fromJson(t,e)}static fromJsonString(t,e){return(new d).fromJsonString(t,e)}static equals(t,e){return n.C.util.equals(d,t,e)}static $(){return["CursorRuleTypeManuallyAttached"]}}class m extends a{constructor(t){super(),this.type={case:void 0},n.C.util.initPartial(t,this)}static fromBinary(t,e){return(new m).fromBinary(t,e)}static fromJson(t,e){return(new m).fromJson(t,e)}static fromJsonString(t,e){return(new m).fromJsonString(t,e)}static equals(t,e){return n.C.util.equals(m,t,e)}static $(){return["CursorRuleType|1 global #0 type|2 file_globbed #1 type|3 agent_fetched #2 type|4 manually_attached #3 type",c,u,l,d]}}class p extends a{constructor(t){super(),this.fullPath="",this.content="",this.source=o.UNSPECIFIED,this.environments=[],this.disabledEnvironments=[],this.scopedTo=[],this.frontmatter="",n.C.util.initPartial(t,this)}static fromBinary(t,e){return(new p).fromBinary(t,e)}static fromJson(t,e){return(new p).fromJson(t,e)}static fromJsonString(t,e){return(new p).fromJsonString(t,e)}static equals(t,e){return n.C.util.equals(p,t,e)}static $(){return["CursorRule|1 full_path 9|2 content 9|3 type #0|4 source #1|5 git_remote_origin 9?|6 parse_error 9?|7 environments 9*|8 disabled_environments 9*|9 plugin 9?|10 marketplace 9?|11 plugin_id 9?|12 marketplace_id 9?|13 scoped_to 9*|14 frontmatter 9|15 is_required 8?",m,o]}}}

Custom mode request types

Source: 9577.index.js (Agent CLI) · bytes 13017–13333 · SHA-256 f20c1e13548f…

Minified Agent CLI webpack module ./src/custom-mode-types.ts (316 characters), the code behind the custom mode request types. Identifiers are minified; the exact shipped code is below.

Exact shipped text
"./src/custom-mode-types.ts"(e,t,r){r.d(t,{W:()=>o,t:()=>s});const s="cyan",n={default:s,green:"green",cyan:"cyan",blue:"blue",purple:"purple",magenta:"magenta",orange:"yellow",yellow:"yellow",red:"red",brand:s};function o(e){return{...void 0!==e.icon?{icon:e.icon}:{},colorId:(t=e.colorId,t&&t in n?n[t]:s)};var t}}

Plugin loading and configuration runtime

Source: index.js (Agent CLI) · bytes 4356863–4561763 · SHA-256 f420c9ceccab…

Minified Agent CLI webpack module ../cursor-plugins/dist/index.js (203,955 characters), the code behind the plugin loading and configuration runtime. Identifiers are minified; the exact shipped code is below.

Reconstructed from the minified zod schemas in this span; approximate. Builder names are minified, so types are inferred from how each builder is used. Every key is a literal from the shipped code.

Schema with mcpServers

Key Type Optional Default
mcpServers record<string, object> yes —
mcpServers.<key>.command string yes —
mcpServers.<key>.args array of string yes —
mcpServers.<key>.env record<string, string> yes —
mcpServers.<key>.url string yes —
mcpServers.<key>.headers record<string, string> yes —
mcpServers.<key>.cwd string yes —
mcpServers.<key>.envFile string yes —
mcpServers.<key>.auth object yes —
mcpServers.<key>.auth.CLIENT_ID string no —
mcpServers.<key>.auth.CLIENT_SECRET string yes —
mcpServers.<key>.auth.scopes array of string yes —
mcpServers.<key>.enabledTools array of string yes —
mcpServers.<key>.placement "server" | "client" yes —
mcpServers.<key>.tls object yes —
mcpServers.<key>.tls.caBundle string (min 1, max 131072) no —

Schema with cursor, sand

Key Type Optional Default
cursor string yes —
sand string yes —

Schema with name, email

Key Type Optional Default
name string (min 1) no —
email string yes —
Exact shipped text
"../cursor-plugins/dist/index.js"(t,e,r){"use strict";r.d(e,{WCg:()=>Ca,eWA:()=>Ea,n8G:()=>ga,QOY:()=>Ju,YUn:()=>Tu,kdU:()=>du,w4n:()=>cu,NwZ:()=>tc,RGj:()=>bo,kxb:()=>nu,i3y:()=>ju,ICo:()=>Xc,xJd:()=>h,s4m:()=>m,R3Q:()=>f,iUy:()=>g,dBY:()=>p,rJj:()=>Du,QY1:()=>vu,r6M:()=>bt,x2d:()=>mo,X3i:()=>b,wpN:()=>Yc,FY4:()=>Wc,Y__:()=>Gc,Zc4:()=>Zc,NzK:()=>i,V6q:()=>jo,U27:()=>uu,RAS:()=>ro,nSO:()=>jc,kXx:()=>Qu,ZyP:()=>qu,fXD:()=>lc,Iqv:()=>qt,DuR:()=>hu,Vwy:()=>pu,AkQ:()=>mu});var n=r("../../../../../../../../../../<build path>");const s=()=>{},i={log:()=>{},increment:()=>{},distribution:()=>{},captureException:()=>{}},a=n.Ik({command:n.Yj().optional(),args:n.YO(n.Yj()).optional(),env:n.g1(n.Yj(),n.Yj()).optional(),url:n.Yj().optional(),headers:n.g1(n.Yj(),n.Yj()).optional(),cwd:n.Yj().optional(),envFile:n.Yj().optional(),auth:n.Ik({CLIENT_ID:n.Yj(),CLIENT_SECRET:n.Yj().optional(),scopes:n.YO(n.Yj()).optional()}).optional(),enabledTools:n.YO(n.Yj()).optional(),placement:n.k5(["server","client"]).optional(),tls:n.Ik({caBundle:n.Yj().trim().min(1).max(131072)}).optional()}),o=n.Ik({mcpServers:n.g1(n.Yj(),a).optional()}),c=n.k5(["canvas"]),u=n.YO(c).transform((t=>[...new Set(t)].sort()));class l extends Error{constructor(t,e){super(`Invalid Claude Code plugin identifier "${e}": ${t}`),this.raw=e,this.name="CCPluginIdentifierError"}}function d(t){const e=t.trim();if(!e)throw new l("Empty identifier",t);const r=/^[a-zA-Z0-9_-]+$/,n=e.indexOf("@");if(n!==e.lastIndexOf("@"))throw new l("Plugin identifier cannot contain multiple @ symbols",t);if(-1===n){if(!r.test(e))throw new l("Plugin name must contain only alphanumeric characters, dashes, and underscores",t);if(e.length>100)throw new l("Plugin name must be 100 characters or less",t);return{name:e,sourceType:"marketplace",marketplace:"claude-plugins-official",raw:t}}const s=e.slice(0,n).trim(),i=e.slice(n+1).trim();if(!s)throw new l("Missing plugin name before @",t);if(!i)throw new l("Missing source after @",t);if(!r.test(s))throw new l("Plugin name must contain only alphanumeric characters, dashes, and underscores",t);if(s.length>100)throw new l("Plugin name must be 100 characters or less",t);if(i.startsWith("github:")){const e=i.slice(7).trim();if(!e||!/^[a-zA-Z0-9_.-]+\/[a-zA-Z0-9_.-]+$/.test(e))throw new l("Invalid GitHub repo format, expected 'org/repo' (e.g., 'anthropics/claude-plugins')",t);return{name:s,sourceType:"github",githubRepo:e,raw:t}}if(i.startsWith("local:")){const e=i.slice(6).trim();if(!e)throw new l("Missing path after 'local:'",t);return{name:s,sourceType:"local",localPath:e,raw:t}}if(i.startsWith("url:")){const e=i.slice(4).trim();if(!e)throw new l("Missing Git URL after 'url:'",t);try{new URL(e)}catch{throw new l("Invalid Git URL format",t)}return{name:s,sourceType:"url",gitUrl:e,raw:t}}const a=i.indexOf("#");let o,c;if(-1!==a?(o=i.slice(0,a).trim(),c=i.slice(a+1).trim()):o=i,!o)throw new l("Missing marketplace name",t);if(!r.test(o))throw new l("Marketplace name must contain only alphanumeric characters, dashes, and underscores",t);return{name:s,sourceType:"marketplace",marketplace:o,version:c,raw:t}}function m(t){if("claude-plugin"===t.source)return t.sourceInfo.raw;if("user-local"===t.source)return`user-local:${t.sourceInfo.name}`;if("extension"===t.source){const e=t.sourceInfo;return`extension:${e.extensionId}:${e.localPath}`}const e=t.sourceInfo;return`${e.name}-${e.version}`}function p(t){return t.sourceInfo.name}function f(t){switch(t.source){case"claude-plugin":case"cursor-first-party":case"cursor-third-party":return t.sourceInfo.marketplace;default:return}}function h(t){switch(t.source){case"cursor-first-party":case"cursor-third-party":return t.sourceInfo.pluginDbId;default:return}}function g(t){switch(t.source){case"cursor-first-party":case"cursor-third-party":return t.sourceInfo.marketplaceDbId;default:return}}const A=new Set(["CREDENTIAL","CREDENTIALS","KEY","PASSPHRASE","PASSWORD","SECRET","TOKEN"]);function b(t){return function(t){return t.replace(/([a-z\d])([A-Z])/g,"$1_$2").replace(/([A-Z]+)([A-Z][a-z])/g,"$1_$2").replace(/[^a-z\d]+/gi,"_").toUpperCase().split("_").filter((t=>t.length>0))}(t).some((t=>A.has(t)))}const y=/\$\{(?:env:([A-Z][A-Z0-9_]*)|([A-Z][A-Z0-9_]*)(?::-([^}]*))?)\}/g,_=new Set(["CURSOR_PLUGIN_ROOT","CLAUDE_PLUGIN_ROOT"]),w=new Set(["api","aws","db","dd","gcp","http","https","id","mcp","ssl","tls","uri","url"]);function C(t){return t.split("_").filter((t=>t.length>0)).map((t=>{const e=t.toLowerCase();return w.has(e)?t.toUpperCase():t.charAt(0).toUpperCase()+e.slice(1)})).join(" ")}function v(t,e){if("string"!=typeof t){if(Array.isArray(t))for(const r of t)v(r,e);else if(null!==t&&"object"==typeof t)for(const r of Object.values(t))v(r,e)}else for(const[,r,n,s]of t.matchAll(y)){const t=r??n;if(void 0===t||_.has(t)||e.has(t))continue;const i=void 0===r?`\${${t}}`:`\${env:${t}}`;e.set(t,{reference:i,defaultValue:s})}}function E(t){if(void 0===t?.mcpServers)return;const e=new Map;if(v(t.mcpServers,e),0===e.size)return;const r={};for(const t of[...e.keys()].sort()){const{reference:n,defaultValue:s}=e.get(t);r[t]={type:"string",title:C(t),description:void 0===s||0===s.length?`Referenced as \`${n}\` in this plugin's MCP configuration.`:`Referenced as \`${n}\` in this plugin's MCP configuration. Defaults to \`${s}\` when left blank.`,...b(t)?{writeOnly:!0}:{}}}return{type:"object",properties:r}}var S=r("../../../../../../../../../../<build path>"),I=r("node:crypto"),B=r("node:path"),k=r("../../../../../../../../../../<build path>");const P=new Set(["https://agent-plugins.org/schemas/1.0.0/plugin.schema.json","https://agent-plugins.org/schemas/1.0.0/mcp.schema.json"]),x=/^v?(\d+\.\d+(?:\.\d+)?)$/;function R(t){if("object"!=typeof t||null===t||Array.isArray(t))return;const e=t.$schema;return"string"==typeof e&&e.length>0?e:void 0}function J(t){let e;try{e=new URL(t).pathname.split("/")}catch{e=t.split("/")}for(const t of e){const e=x.exec(t);if(null!==e)return e[1]}}function T(t){return void 0===t?{kind:"absent"}:P.has(t)?{kind:"supported",id:t,version:J(t)??t}:{kind:"unsupported",id:t}}const q=10485760,j=/^[a-z0-9]([a-z0-9.-]*[a-z0-9])?$/,D=[".cursor-plugin/plugin.json",".claude-plugin/plugin.json","plugin.json"],Q=[".cursor-plugin",".claude-plugin"],N=[".cursor-plugin/marketplace.json",".claude-plugin/marketplace.json"],O=n.Ik({source:n.eu("github"),repo:n.Yj().regex(/^[^/]+\/[^/]+$/,"Must be in owner/repo format"),ref:n.Yj().optional(),sha:n.Yj().length(40,"SHA must be 40 characters").regex(/^[a-f0-9]+$/,"SHA must be hexadecimal").optional()}),M=n.Ik({source:n.eu("url"),url:n.Yj().url().endsWith(".git","URL must end with .git"),ref:n.Yj().optional(),sha:n.Yj().length(40,"SHA must be 40 characters").regex(/^[a-f0-9]+$/,"SHA must be hexadecimal").optional()}),U=n.Ik({source:n.eu("git-subdir"),url:n.Yj().url().endsWith(".git","URL must end with .git"),path:n.Yj().min(1),ref:n.Yj().optional(),sha:n.Yj().length(40,"SHA must be 40 characters").regex(/^[a-f0-9]+$/,"SHA must be hexadecimal").optional()}),L=n.KC([n.Yj(),O,M,U]),F=/^(\d+\.\d+\.\d+(-[0-9A-Za-z.-]+)?|never)$/,$='Must be a semver version (X.Y.Z) or "never"',G=n.Ik({cursor:n.Yj().regex(F,$).optional(),sand:n.Yj().regex(F,$).optional()}),K=n.Ik({name:n.Yj().min(1,"Author name is required"),email:n.Yj().email().optional()}),H=n.k5(["string","number","integer","boolean","object","array","null"]),z=n.KC([H,n.YO(H).nonempty().superRefine(((t,e)=>{new Set(t).size!==t.length&&e.addIssue({code:k.eq.custom,message:"Schema type arrays must not contain duplicates"})}))]);function W(t,e){if(void 0!==t.required)if(void 0===t.properties)for(const r of t.required)e.addIssue({code:k.eq.custom,message:`Required property "${r}" must be declared in properties`,path:["required"]});else for(const r of t.required)r in t.properties||e.addIssue({code:k.eq.custom,message:`Required property "${r}" must be declared in properties`,path:["required"]});void 0!==t.minLength&&void 0!==t.maxLength&&t.minLength>t.maxLength&&e.addIssue({code:k.eq.custom,message:"minLength must be less than or equal to maxLength",path:["minLength"]}),void 0!==t.minimum&&void 0!==t.maximum&&t.minimum>t.maximum&&e.addIssue({code:k.eq.custom,message:"minimum must be less than or equal to maximum",path:["minimum"]}),void 0!==t.exclusiveMinimum&&void 0!==t.exclusiveMaximum&&t.exclusiveMinimum>=t.exclusiveMaximum&&e.addIssue({code:k.eq.custom,message:"exclusiveMinimum must be less than exclusiveMaximum",path:["exclusiveMinimum"]}),void 0!==t.minItems&&void 0!==t.maxItems&&t.minItems>t.maxItems&&e.addIssue({code:k.eq.custom,message:"minItems must be less than or equal to maxItems",path:["minItems"]}),void 0!==t.minProperties&&void 0!==t.maxProperties&&t.minProperties>t.maxProperties&&e.addIssue({code:k.eq.custom,message:"minProperties must be less than or equal to maxProperties",path:["minProperties"]})}const Y=n.RZ((()=>n.Ik({type:z.optional(),title:n.Yj().optional(),description:n.Yj().optional(),format:n.Yj().optional(),writeOnly:n.zM().optional(),default:n.L5().optional(),enum:n.YO(n.bz()).nonempty().optional(),const:n.L5().optional(),properties:n.g1(n.Yj(),Y).optional(),required:n.YO(n.Yj()).optional(),additionalProperties:n.KC([n.zM(),Y]).optional(),items:n.KC([Y,n.YO(Y)]).optional(),minLength:n.ai().int().nonnegative().optional(),maxLength:n.ai().int().nonnegative().optional(),minimum:n.ai().optional(),maximum:n.ai().optional(),exclusiveMinimum:n.ai().optional(),exclusiveMaximum:n.ai().optional(),multipleOf:n.ai().positive().optional(),minItems:n.ai().int().nonnegative().optional(),maxItems:n.ai().int().nonnegative().optional(),uniqueItems:n.zM().optional(),minProperties:n.ai().int().nonnegative().optional(),maxProperties:n.ai().int().nonnegative().optional()}).strict().superRefine(W)));function V(t){const e=Y.superRefine(((t,e)=>{"object"!==t.type&&e.addIssue({code:k.eq.custom,message:'Plugin variable schemas must declare type "object"',path:["type"]})})).safeParse(t);return e.success?{success:!0,data:e.data}:e}const X=n.L5().superRefine(((t,e)=>{const r=V(t);if(!r.success)for(const t of r.error.issues)e.addIssue(t)})).transform((t=>t)),Z=(n.Ik({name:n.Yj().min(1).transform((t=>t.toLowerCase())).refine((t=>j.test(t)),"Name must be kebab-case (lowercase alphanumeric with hyphens and periods)"),displayName:n.Yj().optional(),source:L,description:n.Yj().optional(),version:n.Yj().optional(),author:K.optional(),publisher:n.Yj().min(1).optional(),homepage:n.Yj().url().optional(),repository:n.Yj().url().optional(),license:n.Yj().optional(),keywords:n.YO(n.Yj()).optional(),capabilities:u.optional(),logo:n.Yj().optional(),category:n.Yj().optional(),tags:n.YO(n.Yj()).optional(),minClientVersions:G.optional(),strict:n.zM().default(!0),commands:n.KC([n.Yj(),n.YO(n.Yj())]).optional(),agents:n.KC([n.Yj(),n.YO(n.Yj())]).optional(),skills:n.KC([n.Yj(),n.YO(n.Yj())]).optional(),rules:n.KC([n.Yj(),n.YO(n.Yj())]).optional(),hooks:n.KC([n.Yj(),n.g1(n.L5())]).optional(),variables:X.optional(),mcpServers:n.KC([n.Yj(),n.g1(n.L5()),n.YO(n.KC([n.Yj(),n.g1(n.L5())]))]).optional()}),n.Ik({description:n.Yj().optional(),version:n.Yj().optional(),pluginRoot:n.Yj().optional()}),n.Ik({name:n.Yj().min(1).regex(j,"Name must be kebab-case (lowercase alphanumeric with hyphens and periods)"),displayName:n.Yj().optional(),description:n.Yj().optional(),version:n.Yj().optional(),author:K.optional(),publisher:n.Yj().min(1).optional(),homepage:n.Yj().url().optional(),repository:n.Yj().url().optional(),license:n.Yj().optional(),logo:n.Yj().optional(),keywords:n.YO(n.Yj()).optional(),capabilities:u.optional(),minClientVersions:G.optional(),commands:n.KC([n.Yj(),n.YO(n.Yj())]).optional(),agents:n.KC([n.Yj(),n.YO(n.Yj())]).optional(),skills:n.KC([n.Yj(),n.YO(n.Yj())]).optional(),rules:n.KC([n.Yj(),n.YO(n.Yj())]).optional(),hooks:n.KC([n.Yj(),n.g1(n.L5())]).optional(),variables:X.optional(),mcpServers:n.KC([n.Yj(),n.g1(n.L5()),n.YO(n.KC([n.Yj(),n.g1(n.L5())]))]).optional()}));function tt(t){return"object"==typeof t&&null!==t&&!Array.isArray(t)}function et(t){return t.trim().toLowerCase().replace(/\s+/g,"-").replace(/[^a-z0-9-]+/g,"-").replace(/-+/g,"-").replace(/^-+|-+$/g,"")}function rt(t,e){if(tt(t)&&"string"==typeof t.name){const e=et(t.name);if(e.length>0)return e}return function(t){const e=void 0!==t.repoName?et(t.repoName):"";return e.length>0?e:`cursor-marketplace-${t.fallbackId??(0,I.randomUUID)()}`}(e)}function nt(t){if(tt(t)&&tt(t.owner)){const e="string"==typeof t.owner.name&&t.owner.name.trim().length>0?t.owner.name:"Unknown",r="string"==typeof t.owner.email&&t.owner.email.trim().length>0?t.owner.email:void 0;return{name:e,...void 0!==r?{email:r}:{}}}return{name:"Unknown"}}function st(t){return"string"==typeof t?t:void 0}function it(t){if(!Array.isArray(t))return;const e=t.filter((t=>"string"==typeof t));return e.length>0?e:void 0}function at(t){return"string"==typeof t?t:it(t)}function ot(t){if(!tt(t)||!tt(t.metadata))return;const e={description:st(t.metadata.description),version:st(t.metadata.version),pluginRoot:st(t.metadata.pluginRoot)};return void 0!==e.description||void 0!==e.version||void 0!==e.pluginRoot?e:void 0}function ct(t){if(!tt(t))return;const e=st(t.name);if(void 0===e||0===e.length)return;const r=st(t.email);return{name:e,...void 0!==r?{email:r}:{}}}function ut(t){if("string"==typeof t||tt(t))return t;if(Array.isArray(t)){const e=t.filter((t=>"string"==typeof t||tt(t)));return e.length>0?e:void 0}}function lt(t){if("string"==typeof t||tt(t))return t}function dt(t){if(void 0===t)return;const e=V(t);return e.success?e.data:void 0}function mt(t,e={}){if(t.length>q)return{success:!1,error:"Manifest exceeds maximum size of 10485760 bytes"};let r;try{r=JSON.parse(t)}catch(t){return{success:!1,error:`Invalid JSON: ${t instanceof Error?t.message:"Unknown error"}`}}if(!tt(r))return{success:!1,error:"Invalid marketplace manifest: expected a JSON object"};const n=[],s=[],i=new Set;return(Array.isArray(r.plugins)?r.plugins:[]).forEach(((t,e)=>{const r=function(t,e){if(!tt(t))return{skippedEntry:{index:e,error:`Plugin entry at index ${e} is not an object`}};const r="string"==typeof(n=t.source)?n:tt(n)?"github"===n.source&&"string"==typeof n.repo&&n.repo.length>0?{source:"github",repo:n.repo,ref:st(n.ref),sha:st(n.sha)}:("url"===n.source||void 0===n.source)&&"string"==typeof n.url&&n.url.length>0?{source:"url",url:n.url,ref:st(n.ref),sha:st(n.sha)}:"git-subdir"===n.source&&"string"==typeof n.url&&n.url.length>0&&"string"==typeof n.path&&n.path.length>0?{source:"git-subdir",url:n.url,path:n.path,ref:st(n.ref),sha:st(n.sha)}:"string"==typeof n.repo&&n.repo.length>0?{source:"github",repo:n.repo,ref:st(n.ref),sha:st(n.sha)}:void 0:void 0;var n;if(void 0===r){const r=st(t.name);return{skippedEntry:{index:e,...void 0!==r&&r.length>0?{name:r}:{},error:`Plugin entry at index ${e} has no usable source`}}}const s=("string"==typeof t.name?et(t.name):"")||function(t){if("string"==typeof t){const e=et((0,B.basename)(t));return e.length>0?e:void 0}if("github"===t.source){const e=et(t.repo.split("/").at(-1)??"");return e.length>0?e:void 0}if("git-subdir"===t.source){const e=et((0,B.basename)(t.path));return e.length>0?e:void 0}let e=t.url;try{e=new URL(t.url).pathname}catch{}for(;e.endsWith("/");)e=e.slice(0,-1);e.toLowerCase().endsWith(".git")&&(e=e.slice(0,-4));const r=et((0,B.basename)(e));return r.length>0?r:void 0}(r);if(void 0===s)return{skippedEntry:{index:e,error:`Plugin entry at index ${e} has no usable name`}};const i=u.safeParse(t.capabilities);if(void 0!==t.capabilities&&!i.success)return{skippedEntry:{index:e,name:s,error:`Plugin entry at index ${e} has invalid capabilities: ${i.error.issues.map((t=>`${t.path.join(".")}: ${t.message}`)).join(", ")}`}};const a=i.success?i.data:void 0,o=function(t){const e=G.safeParse(t);if(e.success&&(void 0!==e.data.cursor||void 0!==e.data.sand))return e.data}(t.minClientVersions);return{entry:{name:s,displayName:st(t.displayName),source:r,description:st(t.description),version:st(t.version),author:ct(t.author),publisher:st(t.publisher),homepage:st(t.homepage),repository:st(t.repository),license:st(t.license),keywords:it(t.keywords),logo:st(t.logo),category:st(t.category),tags:it(t.tags),strict:"boolean"!=typeof t.strict||t.strict,commands:at(t.commands),agents:at(t.agents),skills:at(t.skills),rules:at(t.rules),hooks:lt(t.hooks),variables:dt(t.variables),mcpServers:ut(t.mcpServers),...void 0!==a&&{capabilities:a},...void 0!==o&&{minClientVersions:o}}}}(t,e);"skippedEntry"in r?s.push(r.skippedEntry):i.has(r.entry.name)?s.push({index:e,name:r.entry.name,error:`Duplicate plugin name "${r.entry.name}" at index ${e}`}):(i.add(r.entry.name),n.push(r.entry))})),{success:!0,data:{name:rt(r,e),owner:nt(r),description:st(r.description),plugins:n,metadata:ot(r),skippedPluginEntries:s}}}function pt(t){if(t.length>q)return{success:!1,error:"Manifest exceeds maximum size of 10485760 bytes"};let e;try{e=JSON.parse(t)}catch(t){return{success:!1,error:`Invalid JSON: ${t instanceof Error?t.message:"Unknown error"}`}}const r=T(R(e)),n=Z.safeParse(e);return n.success?{success:!0,data:n.data,..."unsupported"===r.kind&&{unrecognizedSchemaId:r.id}}:{success:!1,error:`Invalid plugin manifest: ${n.error.errors.map((t=>`${t.path.join(".")}: ${t.message}`)).join(", ")}`,details:n.error}}function ft(t,e){if("string"!=typeof t)return null;let r=t;if(r.startsWith("./")&&(r=r.slice(2)),void 0!==e){let t=e;t.startsWith("./")&&(t=t.slice(2)),t.endsWith("/")&&(t=t.slice(0,-1)),r=`${t}/${r}`}return r||"."}function ht({logo:t,owner:e,repo:r,ref:n,basePath:s}){if(void 0===t)return;if(t.startsWith("http://")||t.startsWith("https://"))return t;let i=t;return i.startsWith("./")&&(i=i.slice(2)),s&&(i=`${s}/${i}`),`https://raw.githubusercontent.com/${e}/${r}/${n}/${i}`}function gt(t){return!t.includes("..")&&!(0,B.isAbsolute)(t)&&!t.includes("://")}function At(...t){for(const e of t)if(e.displayName)return e.displayName;for(const e of t)if(e.name)return e.name;return""}function bt(t,e){if((t.disabledEnvironments??[]).includes(e))return!1;const r=t.environments??[];return 0===r.length||r.includes(e)}new S.Ajv({allErrors:!0,strict:!1,validateSchema:!0});var yt=r("node:fs/promises"),_t=r("../../../../../../../../../../<build path>");const wt=/\$\{(?:env:([A-Za-z_][A-Za-z0-9_]*)|([^:}]+)(?::-([^}]*))?)\}/g;function Ct(t,e){return vt(t,"function"==typeof e?e:function(t){const e=new Map(Object.entries(t).map((([t,e])=>[t.toLowerCase(),e])));return r=>t[r]??e.get(r.toLowerCase())}(e))}function vt(t,e){if("string"==typeof t)return t.replace(wt,((t,r,n,s)=>{if(void 0!==r)return e(r)??t;const i=e(n);return void 0!==i?i:void 0!==s?s:t}));if(Array.isArray(t))return t.map((t=>vt(t,e)));if(null!==t&&"object"==typeof t){const r={};for(const[n,s]of Object.entries(t))r[n]=vt(s,e);return r}return t}function Et(t,e){return t.replace(/\$\{CLAUDE_PLUGIN_ROOT\}/g,(()=>e)).replace(/\$\{CURSOR_PLUGIN_ROOT\}/g,(()=>e))}const St=[".mcp.json","mcp.json"],It=new Set(["author","owner","source","metadata"].map((t=>t.toLowerCase())));function Bt(t,e){if(!function(t){return It.has(t.toLowerCase())}(t))return!1;if("object"!=typeof e||null===e)return!1;const r=e;switch(t.toLowerCase()){case"author":case"owner":return"string"==typeof r.name;case"source":return"string"==typeof r.source||"string"==typeof r.repo||"string"==typeof r.path||"string"==typeof r.ref||"string"==typeof r.sha;case"metadata":return"string"==typeof r.description||"string"==typeof r.version||"string"==typeof r.pluginRoot;default:return!1}}function kt(t){return"object"==typeof t&&null!==t&&("command"in t||"url"in t)}function Pt(t){const e=void 0!==t&&t.length>0?t.replace(/\/+$/,""):void 0;return St.map((t=>void 0!==e?`${e}/${t}`:t))}function xt(t,e,r){if(!t.mcpServers)return t;const n={};for(const[r,s]of Object.entries(t.mcpServers)){const t={...s};if("string"==typeof s.command&&(t.command=Et(s.command,e)),Array.isArray(s.args)&&(t.args=s.args.map((t=>"string"==typeof t?Et(t,e):t))),s.env&&"object"==typeof s.env){const r={};for(const[t,n]of Object.entries(s.env))r[t]="string"==typeof n?Et(n,e):n;t.env=r}"string"==typeof s.cwd&&(t.cwd=Et(s.cwd,e)),n[r]=t}return function(t,e){const r=e?.cloudAgentEnvLookup,n=e?.configuredVariables;return Ct(t,void 0!==r?r:t=>{const e=process.env[t];if(void 0!==e)return e;const r=n?.[t];return null!=r?"string"==typeof r?r:String(r):void 0})}({...t,mcpServers:n},r)}function Rt(t,e,r){try{const n=(0,_t.qg)(t),s=R(n);if(void 0!==s){const t=r?.log??i;"unsupported"===T(s).kind?t.log("debug",`mcp.json declares an unrecognized $schema, loading anyway: ${s}`):function(t,e){if(void 0===t||void 0===e)return!1;const r=J(t),n=J(e);return void 0!==r&&void 0!==n&&r!==n}(r?.pluginSchemaId,s)&&t.log("debug",`mcp.json $schema ${s} disagrees with plugin.json $schema ${r?.pluginSchemaId}, loading anyway`)}const a=o.safeParse(n),c=!0===r?.skipExpansion;if(a.success&&a.data.mcpServers&&Object.keys(a.data.mcpServers).length>0)return c?a.data:xt(a.data,e,r);const u={};for(const[t,e]of Object.entries(n))"mcpServers"!==t&&!Bt(t,e)&&kt(e)&&(u[t]=e);if(Object.keys(u).length>0){const t=o.safeParse({mcpServers:u});if(t.success)return c?t.data:xt(t.data,e,r)}return null}catch{return null}}function Jt(t,e,r){for(const[n,s]of Object.entries(e))t.mcpServers[n]=s,t.mcpServerSourcePaths[n]=r}async function Tt(t,e,r,n={}){const s=n.toSourcePath??(t=>t),i=n.installPathForExpansion??"",a=n.fallbackFileNames??St,o=n.manifestPrecedence??"override",c={},u={};for(const e of a){const r=await t(e);if(null===r)continue;const a=Rt(r,i,n.parserOptions);if(a?.mcpServers)for(const[t,r]of Object.entries(a.mcpServers))void 0===c[t]&&(c[t]=r,u[t]=s(e))}if(void 0!==e){const a=await async function(t,e,r={}){const n=r.toSourcePath??(t=>t),s=r.installPathForExpansion??"",i={mcpServers:{},mcpServerSourcePaths:{}},a=async t=>{const a=t.replace(/^\.\//,"");if(!gt(a))return;const o=await e(a);if(null===o)return;const c=Rt(o,s,r.parserOptions);c?.mcpServers&&Object.keys(c.mcpServers).length>0&&Jt(i,c.mcpServers,n(a))},o=t=>{const e=Rt(JSON.stringify(t),s,r.parserOptions);e?.mcpServers&&Object.keys(e.mcpServers).length>0&&Jt(i,e.mcpServers,r.manifestSourcePath??"manifest")};if("string"==typeof t)await a(t);else if(Array.isArray(t))for(const e of t)"string"==typeof e?await a(e):"object"==typeof e&&null!==e&&o(e);else"object"==typeof t&&null!==t&&o(t);return i}(e,t,{toSourcePath:s,manifestSourcePath:r,installPathForExpansion:i,parserOptions:n.parserOptions});for(const[t,e]of Object.entries(a.mcpServers))"fill"===o&&void 0!==c[t]||(c[t]=e,u[t]=a.mcpServerSourcePaths[t])}return 0===Object.keys(c).length?null:{mcpServers:c,...Object.keys(u).length>0&&{mcpServerSourcePaths:u}}}function qt(t,e,r,n,s,i){const a=[],o=t.mcpServers;if(!o)return a;for(const[t,c]of Object.entries(o)){const o=c,u=`plugin-${n}-${t}`,l=t;o.url?a.push({identifier:u,name:l,marketplace:e,marketplaceId:r,pluginName:n,pluginId:s,pluginSource:i,type:"streamableHttp",url:o.url,headers:o.headers,auth:o.auth,tls:o.tls,enabledTools:o.enabledTools,placement:o.placement,projectManaged:!1,pluginManaged:!0}):o.command&&a.push({identifier:u,name:l,marketplace:e,marketplaceId:r,pluginName:n,pluginId:s,pluginSource:i,type:"stdio",command:o.command,args:o.args??[],env:o.env??{},cwd:o.cwd,envFile:o.envFile,enabledTools:o.enabledTools,projectManaged:!1,pluginManaged:!0})}return a}var jt=r("node:stream"),Dt=r("node:stream/promises"),Qt=r("node:zlib"),Nt=r("../utils/dist/path-matchers.js"),Ot=r("events"),Mt=r("fs"),Ut=r("node:events");const Lt=require("node:string_decoder");var Ft=r("node:fs"),$t=r("path"),Gt=r("assert"),Kt=r("buffer"),Ht=r("zlib"),zt=r.t(Ht,2),Wt=r("node:assert"),Yt=Object.defineProperty,Vt="object"==typeof process&&process?process:{stdout:null,stderr:null},Xt=t=>!!t&&"object"==typeof t&&(t instanceof De||t instanceof jt||Zt(t)||te(t)),Zt=t=>!!t&&"object"==typeof t&&t instanceof Ut.EventEmitter&&"function"==typeof t.pipe&&t.pipe!==jt.Writable.prototype.pipe,te=t=>!!t&&"object"==typeof t&&t instanceof Ut.EventEmitter&&"function"==typeof t.write&&"function"==typeof t.end,ee=Symbol("EOF"),re=Symbol("maybeEmitEnd"),ne=Symbol("emittedEnd"),se=Symbol("emittingEnd"),ie=Symbol("emittedError"),ae=Symbol("closed"),oe=Symbol("read"),ce=Symbol("flush"),ue=Symbol("flushChunk"),le=Symbol("encoding"),de=Symbol("decoder"),me=Symbol("flowing"),pe=Symbol("paused"),fe=Symbol("resume"),he=Symbol("buffer"),ge=Symbol("pipes"),Ae=Symbol("bufferLength"),be=Symbol("bufferPush"),ye=Symbol("bufferShift"),_e=Symbol("objectMode"),we=Symbol("destroyed"),Ce=Symbol("error"),ve=Symbol("emitData"),Ee=Symbol("emitEnd"),Se=Symbol("emitEnd2"),Ie=Symbol("async"),Be=Symbol("abort"),ke=Symbol("aborted"),Pe=Symbol("signal"),xe=Symbol("dataListeners"),Re=Symbol("discarded"),Je=t=>Promise.resolve().then(t),Te=t=>t(),qe=class{src;dest;opts;ondrain;constructor(t,e,r){this.src=t,this.dest=e,this.opts=r,this.ondrain=()=>t[fe](),this.dest.on("drain",this.ondrain)}unpipe(){this.dest.removeListener("drain",this.ondrain)}proxyErrors(t){}end(){this.unpipe(),this.opts.end&&this.dest.end()}},je=class extends qe{unpipe(){this.src.removeListener("error",this.proxyErrors),super.unpipe()}constructor(t,e,r){super(t,e,r),this.proxyErrors=t=>this.dest.emit("error",t),t.on("error",this.proxyErrors)}},De=class extends Ut.EventEmitter{[me]=!1;[pe]=!1;[ge]=[];[he]=[];[_e];[le];[Ie];[de];[ee]=!1;[ne]=!1;[se]=!1;[ae]=!1;[ie]=null;[Ae]=0;[we]=!1;[Pe];[ke]=!1;[xe]=0;[Re]=!1;writable=!0;readable=!0;constructor(...t){let e=t[0]||{};if(super(),e.objectMode&&"string"==typeof e.encoding)throw new TypeError("Encoding and objectMode may not be used together");var r;e.objectMode?(this[_e]=!0,this[le]=null):!(r=e).objectMode&&r.encoding&&"buffer"!==r.encoding?(this[le]=e.encoding,this[_e]=!1):(this[_e]=!1,this[le]=null),this[Ie]=!!e.async,this[de]=this[le]?new Lt.StringDecoder(this[le]):null,e&&!0===e.debugExposeBuffer&&Object.defineProperty(this,"buffer",{get:()=>this[he]}),e&&!0===e.debugExposePipes&&Object.defineProperty(this,"pipes",{get:()=>this[ge]});let{signal:n}=e;n&&(this[Pe]=n,n.aborted?this[Be]():n.addEventListener("abort",(()=>this[Be]())))}get bufferLength(){return this[Ae]}get encoding(){return this[le]}set encoding(t){throw new Error("Encoding must be set at instantiation time")}setEncoding(t){throw new Error("Encoding must be set at instantiation time")}get objectMode(){return this[_e]}set objectMode(t){throw new Error("objectMode must be set at instantiation time")}get async(){return this[Ie]}set async(t){this[Ie]=this[Ie]||!!t}[Be](){this[ke]=!0,this.emit("abort",this[Pe]?.reason),this.destroy(this[Pe]?.reason)}get aborted(){return this[ke]}set aborted(t){}write(t,e,r){if(this[ke])return!1;if(this[ee])throw new Error("write after end");if(this[we])return this.emit("error",Object.assign(new Error("Cannot call write after a stream was destroyed"),{code:"ERR_STREAM_DESTROYED"})),!0;"function"==typeof e&&(r=e,e="utf8"),e||(e="utf8");let n=this[Ie]?Je:Te;if(!this[_e]&&!Buffer.isBuffer(t))if(s=t,!Buffer.isBuffer(s)&&ArrayBuffer.isView(s))t=Buffer.from(t.buffer,t.byteOffset,t.byteLength);else if((t=>t instanceof ArrayBuffer||!!t&&"object"==typeof t&&t.constructor&&"ArrayBuffer"===t.constructor.name&&t.byteLength>=0)(t))t=Buffer.from(t);else if("string"!=typeof t)throw new Error("Non-contiguous data written to non-objectMode stream");var s;return this[_e]?(this[me]&&0!==this[Ae]&&this[ce](!0),this[me]?this.emit("data",t):this[be](t),0!==this[Ae]&&this.emit("readable"),r&&n(r),this[me]):t.length?("string"==typeof t&&!(e===this[le]&&!this[de]?.lastNeed)&&(t=Buffer.from(t,e)),Buffer.isBuffer(t)&&this[le]&&(t=this[de].write(t)),this[me]&&0!==this[Ae]&&this[ce](!0),this[me]?this.emit("data",t):this[be](t),0!==this[Ae]&&this.emit("readable"),r&&n(r),this[me]):(0!==this[Ae]&&this.emit("readable"),r&&n(r),this[me])}read(t){if(this[we])return null;if(this[Re]=!1,0===this[Ae]||0===t||t&&t>this[Ae])return this[re](),null;this[_e]&&(t=null),this[he].length>1&&!this[_e]&&(this[he]=[this[le]?this[he].join(""):Buffer.concat(this[he],this[Ae])]);let e=this[oe](t||null,this[he][0]);return this[re](),e}[oe](t,e){if(this[_e])this[ye]();else{let r=e;t===r.length||null===t?this[ye]():"string"==typeof r?(this[he][0]=r.slice(t),e=r.slice(0,t),this[Ae]-=t):(this[he][0]=r.subarray(t),e=r.subarray(0,t),this[Ae]-=t)}return this.emit("data",e),!this[he].length&&!this[ee]&&this.emit("drain"),e}end(t,e,r){return"function"==typeof t&&(r=t,t=void 0),"function"==typeof e&&(r=e,e="utf8"),void 0!==t&&this.write(t,e),r&&this.once("end",r),this[ee]=!0,this.writable=!1,(this[me]||!this[pe])&&this[re](),this}[fe](){this[we]||(!this[xe]&&!this[ge].length&&(this[Re]=!0),this[pe]=!1,this[me]=!0,this.emit("resume"),this[he].length?this[ce]():this[ee]?this[re]():this.emit("drain"))}resume(){return this[fe]()}pause(){this[me]=!1,this[pe]=!0,this[Re]=!1}get destroyed(){return this[we]}get flowing(){return this[me]}get paused(){return this[pe]}[be](t){this[_e]?this[Ae]+=1:this[Ae]+=t.length,this[he].push(t)}[ye](){return this[_e]?this[Ae]-=1:this[Ae]-=this[he][0].length,this[he].shift()}[ce](t=!1){do{}while(this[ue](this[ye]())&&this[he].length);!t&&!this[he].length&&!this[ee]&&this.emit("drain")}[ue](t){return this.emit("data",t),this[me]}pipe(t,e){if(this[we])return t;this[Re]=!1;let r=this[ne];return e=e||{},t===Vt.stdout||t===Vt.stderr?e.end=!1:e.end=!1!==e.end,e.proxyErrors=!!e.proxyErrors,r?e.end&&t.end():(this[ge].push(e.proxyErrors?new je(this,t,e):new qe(this,t,e)),this[Ie]?Je((()=>this[fe]())):this[fe]()),t}unpipe(t){let e=this[ge].find((e=>e.dest===t));e&&(1===this[ge].length?(this[me]&&0===this[xe]&&(this[me]=!1),this[ge]=[]):this[ge].splice(this[ge].indexOf(e),1),e.unpipe())}addListener(t,e){return this.on(t,e)}on(t,e){let r=super.on(t,e);if("data"===t)this[Re]=!1,this[xe]++,!this[ge].length&&!this[me]&&this[fe]();else if("readable"===t&&0!==this[Ae])super.emit("readable");else if("end"!==(n=t)&&"finish"!==n&&"prefinish"!==n||!this[ne]){if("error"===t&&this[ie]){let t=e;this[Ie]?Je((()=>t.call(this,this[ie]))):t.call(this,this[ie])}}else super.emit(t),this.removeAllListeners(t);var n;return r}removeListener(t,e){return this.off(t,e)}off(t,e){let r=super.off(t,e);return"data"===t&&(this[xe]=this.listeners("data").length,0===this[xe]&&!this[Re]&&!this[ge].length&&(this[me]=!1)),r}removeAllListeners(t){let e=super.removeAllListeners(t);return("data"===t||void 0===t)&&(this[xe]=0,!this[Re]&&!this[ge].length&&(this[me]=!1)),e}get emittedEnd(){return this[ne]}[re](){!this[se]&&!this[ne]&&!this[we]&&0===this[he].length&&this[ee]&&(this[se]=!0,this.emit("end"),this.emit("prefinish"),this.emit("finish"),this[ae]&&this.emit("close"),this[se]=!1)}emit(t,...e){let r=e[0];if("error"!==t&&"close"!==t&&t!==we&&this[we])return!1;if("data"===t)return!(!this[_e]&&!r)&&(this[Ie]?(Je((()=>this[ve](r))),!0):this[ve](r));if("end"===t)return this[Ee]();if("close"===t){if(this[ae]=!0,!this[ne]&&!this[we])return!1;let t=super.emit("close");return this.removeAllListeners("close"),t}if("error"===t){this[ie]=r,super.emit(Ce,r);let t=!(this[Pe]&&!this.listeners("error").length)&&super.emit("error",r);return this[re](),t}if("resume"===t){let t=super.emit("resume");return this[re](),t}if("finish"===t||"prefinish"===t){let e=super.emit(t);return this.removeAllListeners(t),e}let n=super.emit(t,...e);return this[re](),n}[ve](t){for(let e of this[ge])!1===e.dest.write(t)&&this.pause();let e=!this[Re]&&super.emit("data",t);return this[re](),e}[Ee](){return!this[ne]&&(this[ne]=!0,this.readable=!1,this[Ie]?(Je((()=>this[Se]())),!0):this[Se]())}[Se](){if(this[de]){let t=this[de].end();if(t){for(let e of this[ge])e.dest.write(t);this[Re]||super.emit("data",t)}}for(let t of this[ge])t.end();let t=super.emit("end");return this.removeAllListeners("end"),t}async collect(){let t=Object.assign([],{dataLength:0});this[_e]||(t.dataLength=0);let e=this.promise();return this.on("data",(e=>{t.push(e),this[_e]||(t.dataLength+=e.length)})),await e,t}async concat(){if(this[_e])throw new Error("cannot concat in objectMode");let t=await this.collect();return this[le]?t.join(""):Buffer.concat(t,t.dataLength)}async promise(){return new Promise(((t,e)=>{this.on(we,(()=>e(new Error("stream destroyed")))),this.on("error",(t=>e(t))),this.on("end",(()=>t()))}))}[Symbol.asyncIterator](){this[Re]=!1;let t=!1,e=async()=>(this.pause(),t=!0,{value:void 0,done:!0});return{next:()=>{if(t)return e();let r=this.read();if(null!==r)return Promise.resolve({done:!1,value:r});if(this[ee])return e();let n,s,i=t=>{this.off("data",a),this.off("end",o),this.off(we,c),e(),s(t)},a=t=>{this.off("error",i),this.off("end",o),this.off(we,c),this.pause(),n({value:t,done:!!this[ee]})},o=()=>{this.off("error",i),this.off("data",a),this.off(we,c),e(),n({done:!0,value:void 0})},c=()=>i(new Error("stream destroyed"));return new Promise(((t,e)=>{s=e,n=t,this.once(we,c),this.once("error",i),this.once("end",o),this.once("data",a)}))},throw:e,return:e,[Symbol.asyncIterator](){return this},[Symbol.asyncDispose]:async()=>{}}}[Symbol.iterator](){this[Re]=!1;let t=!1,e=()=>(this.pause(),this.off(Ce,e),this.off(we,e),this.off("end",e),t=!0,{done:!0,value:void 0});return this.once("end",e),this.once(Ce,e),this.once(we,e),{next:()=>{if(t)return e();let r=this.read();return null===r?e():{done:!1,value:r}},throw:e,return:e,[Symbol.iterator](){return this},[Symbol.dispose]:()=>{}}}destroy(t){return this[we]?(t?this.emit("error",t):this.emit(we),this):(this[we]=!0,this[Re]=!0,this[he].length=0,this[Ae]=0,"function"==typeof this.close&&!this[ae]&&this.close(),t?this.emit("error",t):this.emit(we),this)}static get isStream(){return Xt}},Qe=Mt.writev,Ne=Symbol("_autoClose"),Oe=Symbol("_close"),Me=Symbol("_ended"),Ue=Symbol("_fd"),Le=Symbol("_finished"),Fe=Symbol("_flags"),$e=Symbol("_flush"),Ge=Symbol("_handleChunk"),Ke=Symbol("_makeBuf"),He=Symbol("_mode"),ze=Symbol("_needDrain"),We=Symbol("_onerror"),Ye=Symbol("_onopen"),Ve=Symbol("_onread"),Xe=Symbol("_onwrite"),Ze=Symbol("_open"),tr=Symbol("_path"),er=Symbol("_pos"),rr=Symbol("_queue"),nr=Symbol("_read"),sr=Symbol("_readSize"),ir=Symbol("_reading"),ar=Symbol("_remain"),or=Symbol("_size"),cr=Symbol("_write"),ur=Symbol("_writing"),lr=Symbol("_defaultFlag"),dr=Symbol("_errored"),mr=class extends De{[dr]=!1;[Ue];[tr];[sr];[ir]=!1;[or];[ar];[Ne];constructor(t,e){if(super(e=e||{}),this.readable=!0,this.writable=!1,"string"!=typeof t)throw new TypeError("path must be a string");this[dr]=!1,this[Ue]="number"==typeof e.fd?e.fd:void 0,this[tr]=t,this[sr]=e.readSize||16777216,this[ir]=!1,this[or]="number"==typeof e.size?e.size:1/0,this[ar]=this[or],this[Ne]="boolean"!=typeof e.autoClose||e.autoClose,"number"==typeof this[Ue]?this[nr]():this[Ze]()}get fd(){return this[Ue]}get path(){return this[tr]}write(){throw new TypeError("this is a readable stream")}end(){throw new TypeError("this is a readable stream")}[Ze](){Mt.open(this[tr],"r",((t,e)=>this[Ye](t,e)))}[Ye](t,e){t?this[We](t):(this[Ue]=e,this.emit("open",e),this[nr]())}[Ke](){return Buffer.allocUnsafe(Math.min(this[sr],this[ar]))}[nr](){if(!this[ir]){this[ir]=!0;let t=this[Ke]();if(0===t.length)return process.nextTick((()=>this[Ve](null,0,t)));Mt.read(this[Ue],t,0,t.length,null,((t,e,r)=>this[Ve](t,e,r)))}}[Ve](t,e,r){this[ir]=!1,t?this[We](t):this[Ge](e,r)&&this[nr]()}[Oe](){if(this[Ne]&&"number"==typeof this[Ue]){let t=this[Ue];this[Ue]=void 0,Mt.close(t,(t=>t?this.emit("error",t):this.emit("close")))}}[We](t){this[ir]=!0,this[Oe](),this.emit("error",t)}[Ge](t,e){let r=!1;return this[ar]-=t,t>0&&(r=super.write(t<e.length?e.subarray(0,t):e)),(0===t||this[ar]<=0)&&(r=!1,this[Oe](),super.end()),r}emit(t,...e){switch(t){case"prefinish":case"finish":return!1;case"drain":return"number"==typeof this[Ue]&&this[nr](),!1;case"error":return!this[dr]&&(this[dr]=!0,super.emit(t,...e));default:return super.emit(t,...e)}}},pr=class extends mr{[Ze](){let t=!0;try{this[Ye](null,Mt.openSync(this[tr],"r")),t=!1}finally{t&&this[Oe]()}}[nr](){let t=!0;try{if(!this[ir]){for(this[ir]=!0;;){let t=this[Ke](),e=0===t.length?0:Mt.readSync(this[Ue],t,0,t.length,null);if(!this[Ge](e,t))break}this[ir]=!1}t=!1}finally{t&&this[Oe]()}}[Oe](){if(this[Ne]&&"number"==typeof this[Ue]){let t=this[Ue];this[Ue]=void 0,Mt.closeSync(t),this.emit("close")}}},fr=class extends Ot{readable=!1;writable=!0;[dr]=!1;[ur]=!1;[Me]=!1;[rr]=[];[ze]=!1;[tr];[He];[Ne];[Ue];[lr];[Fe];[Le]=!1;[er];constructor(t,e){super(e=e||{}),this[tr]=t,this[Ue]="number"==typeof e.fd?e.fd:void 0,this[He]=void 0===e.mode?438:e.mode,this[er]="number"==typeof e.start?e.start:void 0,this[Ne]="boolean"!=typeof e.autoClose||e.autoClose;let r=void 0!==this[er]?"r+":"w";this[lr]=void 0===e.flags,this[Fe]=void 0===e.flags?r:e.flags,void 0===this[Ue]&&this[Ze]()}emit(t,...e){if("error"===t){if(this[dr])return!1;this[dr]=!0}return super.emit(t,...e)}get fd(){return this[Ue]}get path(){return this[tr]}[We](t){this[Oe](),this[ur]=!0,this.emit("error",t)}[Ze](){Mt.open(this[tr],this[Fe],this[He],((t,e)=>this[Ye](t,e)))}[Ye](t,e){this[lr]&&"r+"===this[Fe]&&t&&"ENOENT"===t.code?(this[Fe]="w",this[Ze]()):t?this[We](t):(this[Ue]=e,this.emit("open",e),this[ur]||this[$e]())}end(t,e){return t&&this.write(t,e),this[Me]=!0,!this[ur]&&!this[rr].length&&"number"==typeof this[Ue]&&this[Xe](null,0),this}write(t,e){return"string"==typeof t&&(t=Buffer.from(t,e)),this[Me]?(this.emit("error",new Error("write() after end()")),!1):void 0===this[Ue]||this[ur]||this[rr].length?(this[rr].push(t),this[ze]=!0,!1):(this[ur]=!0,this[cr](t),!0)}[cr](t){Mt.write(this[Ue],t,0,t.length,this[er],((t,e)=>this[Xe](t,e)))}[Xe](t,e){t?this[We](t):(void 0!==this[er]&&"number"==typeof e&&(this[er]+=e),this[rr].length?this[$e]():(this[ur]=!1,this[Me]&&!this[Le]?(this[Le]=!0,this[Oe](),this.emit("finish")):this[ze]&&(this[ze]=!1,this.emit("drain"))))}[$e](){if(0===this[rr].length)this[Me]&&this[Xe](null,0);else if(1===this[rr].length)this[cr](this[rr].pop());else{let t=this[rr];this[rr]=[],Qe(this[Ue],t,this[er],((t,e)=>this[Xe](t,e)))}}[Oe](){if(this[Ne]&&"number"==typeof this[Ue]){let t=this[Ue];this[Ue]=void 0,Mt.close(t,(t=>t?this.emit("error",t):this.emit("close")))}}},hr=class extends fr{[Ze](){let t;if(this[lr]&&"r+"===this[Fe])try{t=Mt.openSync(this[tr],this[Fe],this[He])}catch(t){if("ENOENT"===t?.code)return this[Fe]="w",this[Ze]();throw t}else t=Mt.openSync(this[tr],this[Fe],this[He]);this[Ye](null,t)}[Oe](){if(this[Ne]&&"number"==typeof this[Ue]){let t=this[Ue];this[Ue]=void 0,Mt.closeSync(t),this.emit("close")}}[cr](t){let e=!0;try{this[Xe](null,Mt.writeSync(this[Ue],t,0,t.length,this[er])),e=!1}finally{if(e)try{this[Oe]()}catch{}}}},gr=new Map([["C","cwd"],["f","file"],["z","gzip"],["P","preservePaths"],["U","unlink"],["strip-components","strip"],["stripComponents","strip"],["keep-newer","newer"],["keepNewer","newer"],["keep-newer-files","newer"],["keepNewerFiles","newer"],["k","keep"],["keep-existing","keep"],["keepExisting","keep"],["m","noMtime"],["no-mtime","noMtime"],["p","preserveOwner"],["L","follow"],["h","follow"],["onentry","onReadEntry"]]),Ar=t=>gr.get(t)||t,br=(t={})=>{if(!t)return{};let e={};for(let[r,n]of Object.entries(t))e[Ar(r)]=n;return void 0===e.chmod&&!1===e.noChmod&&(e.chmod=!0),delete e.noChmod,e},yr=(t,e,r,n,s)=>Object.assign(((i=[],a,o)=>{Array.isArray(i)&&(a=i,i={}),"function"==typeof a&&(o=a,a=void 0),a=a?Array.from(a):[];let c=br(i);if(s?.(c,a),(t=>!!t.sync&&!!t.file)(c)){if("function"==typeof o)throw new TypeError("callback not supported for sync tar functions");return t(c,a)}if((t=>!t.sync&&!!t.file)(c)){let t=e(c,a);return o?t.then((()=>o()),o):t}if((t=>!!t.sync&&!t.file)(c)){if("function"==typeof o)throw new TypeError("callback not supported for sync tar functions");return r(c,a)}if((t=>!t.sync&&!t.file)(c)){if("function"==typeof o)throw new TypeError("callback only supported with file option");return n(c,a)}throw new Error("impossible options??")}),{syncFile:t,asyncFile:e,syncNoFile:r,asyncNoFile:n,validate:s}),_r=Ht.constants||{ZLIB_VERNUM:4736},wr=Object.freeze(Object.assign(Object.create(null),{Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_VERSION_ERROR:-6,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,DEFLATE:1,INFLATE:2,GZIP:3,GUNZIP:4,DEFLATERAW:5,INFLATERAW:6,UNZIP:7,BROTLI_DECODE:8,BROTLI_ENCODE:9,Z_MIN_WINDOWBITS:8,Z_MAX_WINDOWBITS:15,Z_DEFAULT_WINDOWBITS:15,Z_MIN_CHUNK:64,Z_MAX_CHUNK:1/0,Z_DEFAULT_CHUNK:16384,Z_MIN_MEMLEVEL:1,Z_MAX_MEMLEVEL:9,Z_DEFAULT_MEMLEVEL:8,Z_MIN_LEVEL:-1,Z_MAX_LEVEL:9,Z_DEFAULT_LEVEL:-1,BROTLI_OPERATION_PROCESS:0,BROTLI_OPERATION_FLUSH:1,BROTLI_OPERATION_FINISH:2,BROTLI_OPERATION_EMIT_METADATA:3,BROTLI_MODE_GENERIC:0,BROTLI_MODE_TEXT:1,BROTLI_MODE_FONT:2,BROTLI_DEFAULT_MODE:0,BROTLI_MIN_QUALITY:0,BROTLI_MAX_QUALITY:11,BROTLI_DEFAULT_QUALITY:11,BROTLI_MIN_WINDOW_BITS:10,BROTLI_MAX_WINDOW_BITS:24,BROTLI_LARGE_MAX_WINDOW_BITS:30,BROTLI_DEFAULT_WINDOW:22,BROTLI_MIN_INPUT_BLOCK_BITS:16,BROTLI_MAX_INPUT_BLOCK_BITS:24,BROTLI_PARAM_MODE:0,BROTLI_PARAM_QUALITY:1,BROTLI_PARAM_LGWIN:2,BROTLI_PARAM_LGBLOCK:3,BROTLI_PARAM_DISABLE_LITERAL_CONTEXT_MODELING:4,BROTLI_PARAM_SIZE_HINT:5,BROTLI_PARAM_LARGE_WINDOW:6,BROTLI_PARAM_NPOSTFIX:7,BROTLI_PARAM_NDIRECT:8,BROTLI_DECODER_RESULT_ERROR:0,BROTLI_DECODER_RESULT_SUCCESS:1,BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT:2,BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT:3,BROTLI_DECODER_PARAM_DISABLE_RING_BUFFER_REALLOCATION:0,BROTLI_DECODER_PARAM_LARGE_WINDOW:1,BROTLI_DECODER_NO_ERROR:0,BROTLI_DECODER_SUCCESS:1,BROTLI_DECODER_NEEDS_MORE_INPUT:2,BROTLI_DECODER_NEEDS_MORE_OUTPUT:3,BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_NIBBLE:-1,BROTLI_DECODER_ERROR_FORMAT_RESERVED:-2,BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_META_NIBBLE:-3,BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_ALPHABET:-4,BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_SAME:-5,BROTLI_DECODER_ERROR_FORMAT_CL_SPACE:-6,BROTLI_DECODER_ERROR_FORMAT_HUFFMAN_SPACE:-7,BROTLI_DECODER_ERROR_FORMAT_CONTEXT_MAP_REPEAT:-8,BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_1:-9,BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_2:-10,BROTLI_DECODER_ERROR_FORMAT_TRANSFORM:-11,BROTLI_DECODER_ERROR_FORMAT_DICTIONARY:-12,BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS:-13,BROTLI_DECODER_ERROR_FORMAT_PADDING_1:-14,BROTLI_DECODER_ERROR_FORMAT_PADDING_2:-15,BROTLI_DECODER_ERROR_FORMAT_DISTANCE:-16,BROTLI_DECODER_ERROR_DICTIONARY_NOT_SET:-19,BROTLI_DECODER_ERROR_INVALID_ARGUMENTS:-20,BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MODES:-21,BROTLI_DECODER_ERROR_ALLOC_TREE_GROUPS:-22,BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MAP:-25,BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_1:-26,BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_2:-27,BROTLI_DECODER_ERROR_ALLOC_BLOCK_TYPE_TREES:-30,BROTLI_DECODER_ERROR_UNREACHABLE:-31},_r)),Cr=Kt.Buffer.concat,vr=Object.getOwnPropertyDescriptor(Kt.Buffer,"concat"),Er=t=>t,Sr=!0===vr?.writable||void 0!==vr?.set?t=>{Kt.Buffer.concat=t?Er:Cr}:t=>{},Ir=Symbol("_superWrite"),Br=class extends Error{code;errno;constructor(t,e){super("zlib: "+t.message,{cause:t}),this.code=t.code,this.errno=t.errno,this.code||(this.code="ZLIB_ERROR"),this.message="zlib: "+t.message,Error.captureStackTrace(this,e??this.constructor)}get name(){return"ZlibError"}},kr=Symbol("flushFlag"),Pr=class extends De{#R=!1;#J=!1;#T;#q;#j;#D;#Q;get sawError(){return this.#R}get handle(){return this.#D}get flushFlag(){return this.#T}constructor(t,e){if(!t||"object"!=typeof t)throw new TypeError("invalid options for ZlibBase constructor");if(super(t),this.#T=t.flush??0,this.#q=t.finishFlush??0,this.#j=t.fullFlushFlag??0,"function"!=typeof zt[e])throw new TypeError("Compression method not supported: "+e);try{this.#D=new zt[e](t)}catch(t){throw new Br(t,this.constructor)}this.#Q=t=>{this.#R||(this.#R=!0,this.close(),this.emit("error",t))},this.#D?.on("error",(t=>this.#Q(new Br(t)))),this.once("end",(()=>this.close))}close(){this.#D&&(this.#D.close(),this.#D=void 0,this.emit("close"))}reset(){if(!this.#R)return Gt(this.#D,"zlib binding closed"),this.#D.reset?.()}flush(t){this.ended||("number"!=typeof t&&(t=this.#j),this.write(Object.assign(Kt.Buffer.alloc(0),{[kr]:t})))}end(t,e,r){return"function"==typeof t&&(r=t,e=void 0,t=void 0),"function"==typeof e&&(r=e,e=void 0),t&&(e?this.write(t,e):this.write(t)),this.flush(this.#q),this.#J=!0,super.end(r)}get ended(){return this.#J}[Ir](t){return super.write(t)}write(t,e,r){if("function"==typeof e&&(r=e,e="utf8"),"string"==typeof t&&(t=Kt.Buffer.from(t,e)),this.#R)return;Gt(this.#D,"zlib binding closed");let n=this.#D._handle,s=n.close;n.close=()=>{};let i,a,o=this.#D.close;this.#D.close=()=>{},Sr(!0);try{let e="number"==typeof t[kr]?t[kr]:this.#T;i=this.#D._processChunk(t,e),Sr(!1)}catch(t){Sr(!1),this.#Q(new Br(t,this.write))}finally{this.#D&&(this.#D._handle=n,n.close=s,this.#D.close=o,this.#D.removeAllListeners("error"))}if(this.#D&&this.#D.on("error",(t=>this.#Q(new Br(t,this.write)))),i)if(Array.isArray(i)&&i.length>0){let t=i[0];a=this[Ir](Kt.Buffer.from(t));for(let t=1;t<i.length;t++)a=this[Ir](i[t])}else a=this[Ir](Kt.Buffer.from(i));return r&&r(),a}},xr=class extends Pr{#R;#J;constructor(t,e){(t=t||{}).flush=t.flush||wr.Z_NO_FLUSH,t.finishFlush=t.finishFlush||wr.Z_FINISH,t.fullFlushFlag=wr.Z_FULL_FLUSH,super(t,e),this.#R=t.level,this.#J=t.strategy}params(t,e){if(!this.sawError){if(!this.handle)throw new Error("cannot switch params when binding is closed");if(!this.handle.params)throw new Error("not supported in this implementation");if(this.#R!==t||this.#J!==e){this.flush(wr.Z_SYNC_FLUSH),Gt(this.handle,"zlib binding closed");let r=this.handle.flush;this.handle.flush=(t,e)=>{"function"==typeof t&&(e=t,t=this.flushFlag),this.flush(t),e?.()};try{this.handle.params(t,e)}finally{this.handle.flush=r}this.handle&&(this.#R=t,this.#J=e)}}}},Rr=class extends xr{#R;constructor(t){super(t,"Gzip"),this.#R=t&&!!t.portable}[Ir](t){return this.#R?(this.#R=!1,t[9]=255,super[Ir](t)):super[Ir](t)}},Jr=class extends xr{constructor(t){super(t,"Unzip")}},Tr=class extends Pr{constructor(t,e){(t=t||{}).flush=t.flush||wr.BROTLI_OPERATION_PROCESS,t.finishFlush=t.finishFlush||wr.BROTLI_OPERATION_FINISH,t.fullFlushFlag=wr.BROTLI_OPERATION_FLUSH,super(t,e)}},qr=class extends Tr{constructor(t){super(t,"BrotliCompress")}},jr=class extends Tr{constructor(t){super(t,"BrotliDecompress")}},Dr=class extends Pr{constructor(t,e){(t=t||{}).flush=t.flush||wr.ZSTD_e_continue,t.finishFlush=t.finishFlush||wr.ZSTD_e_end,t.fullFlushFlag=wr.ZSTD_e_flush,super(t,e)}},Qr=class extends Dr{constructor(t){super(t,"ZstdCompress")}},Nr=class extends Dr{constructor(t){super(t,"ZstdDecompress")}},Or=t=>255&(255^t),Mr=t=>1+(255^t)&255;((t,e)=>{for(var r in e)Yt(t,r,{get:e[r],enumerable:!0})})({},{code:()=>Gr,isCode:()=>Ur,isName:()=>Lr,name:()=>$r,normalFsTypes:()=>Fr});var Ur=t=>$r.has(t),Lr=t=>Gr.has(t),Fr=new Set(["0","","1","2","3","4","5","6","7","D"]),$r=new Map([["0","File"],["","OldFile"],["1","Link"],["2","SymbolicLink"],["3","CharacterDevice"],["4","BlockDevice"],["5","Directory"],["6","FIFO"],["7","ContiguousFile"],["g","GlobalExtendedHeader"],["x","ExtendedHeader"],["A","SolarisACL"],["D","GNUDumpDir"],["I","Inode"],["K","NextFileHasLongLinkpath"],["L","NextFileHasLongPath"],["M","ContinuationFile"],["N","OldGnuLongPath"],["S","SparseFile"],["V","TapeVolumeHeader"],["X","OldExtendedHeader"]]),Gr=new Map(Array.from($r).map((t=>[t[1],t[0]]))),Kr=class{cksumValid=!1;needPax=!1;nullBlock=!1;block;path;mode;uid;gid;size;cksum;#R="Unsupported";linkpath;uname;gname;devmaj=0;devmin=0;atime;ctime;mtime;charset;comment;constructor(t,e=0,r,n){Buffer.isBuffer(t)?this.decode(t,e||0,r,n):t&&this.#J(t)}decode(t,e,r,n){if(e||(e=0),!(t&&t.length>=e+512))throw new Error("need 512 bytes for header");let s=zr(t,e+156,1),i=Fr.has(s),a=i?r:void 0,o=i?n:void 0;if(this.path=a?.path??zr(t,e,100),this.mode=a?.mode??o?.mode??Vr(t,e+100,8),this.uid=a?.uid??o?.uid??Vr(t,e+108,8),this.gid=a?.gid??o?.gid??Vr(t,e+116,8),this.size=void 0===(c=a?.size??o?.size??Vr(t,e+124,12))||c<0?void 0:c,this.mtime=a?.mtime??o?.mtime??Wr(t,e+136,12),this.cksum=Vr(t,e+148,12),o&&this.#J(o,!0),a&&this.#J(a),Ur(s)&&(this.#R=s||"0"),"0"===this.#R&&"/"===this.path.slice(-1)&&(this.#R="5"),"5"===this.#R&&(this.size=0),this.linkpath=zr(t,e+157,100),"ustar\x0000"===t.subarray(e+257,e+265).toString())if(this.uname=a?.uname??o?.uname??zr(t,e+265,32),this.gname=a?.gname??o?.gname??zr(t,e+297,32),this.devmaj=a?.devmaj??o?.devmaj??Vr(t,e+329,8)??0,this.devmin=a?.devmin??o?.devmin??Vr(t,e+337,8)??0,0!==t[e+475]){let r=zr(t,e+345,155);this.path=r+"/"+this.path}else{let s=zr(t,e+345,130);s&&(this.path=s+"/"+this.path),this.atime=r?.atime??n?.atime??Wr(t,e+476,12),this.ctime=r?.ctime??n?.ctime??Wr(t,e+488,12)}var c;let u=256;for(let r=e;r<e+148;r++)u+=t[r];for(let r=e+156;r<e+512;r++)u+=t[r];this.cksumValid=u===this.cksum,void 0===this.cksum&&256===u&&(this.nullBlock=!0)}#J(t,e=!1){Object.assign(this,Object.fromEntries(Object.entries(t).filter((([t,r])=>!(null==r||"size"===t&&Number(r)<0||"path"===t&&e||"linkpath"===t&&e||"global"===t)))))}encode(t,e=0){if(t||(t=this.block=Buffer.alloc(512)),"Unsupported"===this.#R&&(this.#R="0"),!(t.length>=e+512))throw new Error("need 512 bytes for header");let r=this.ctime||this.atime?130:155,n=Hr(this.path||"",r),s=n[0],i=n[1];this.needPax=!!n[2],this.needPax=on(t,e,100,s)||this.needPax,this.needPax=tn(t,e+100,8,this.mode)||this.needPax,this.needPax=tn(t,e+108,8,this.uid)||this.needPax,this.needPax=tn(t,e+116,8,this.gid)||this.needPax,this.needPax=tn(t,e+124,12,this.size)||this.needPax,this.needPax=sn(t,e+136,12,this.mtime)||this.needPax,t[e+156]=Number(this.#R.codePointAt(0)),this.needPax=on(t,e+157,100,this.linkpath)||this.needPax,t.write("ustar\x0000",e+257,8),this.needPax=on(t,e+265,32,this.uname)||this.needPax,this.needPax=on(t,e+297,32,this.gname)||this.needPax,this.needPax=tn(t,e+329,8,this.devmaj)||this.needPax,this.needPax=tn(t,e+337,8,this.devmin)||this.needPax,this.needPax=on(t,e+345,r,i)||this.needPax,0!==t[e+475]?this.needPax=on(t,e+345,155,i)||this.needPax:(this.needPax=on(t,e+345,130,i)||this.needPax,this.needPax=sn(t,e+476,12,this.atime)||this.needPax,this.needPax=sn(t,e+488,12,this.ctime)||this.needPax);let a=256;for(let r=e;r<e+148;r++)a+=t[r];for(let r=e+156;r<e+512;r++)a+=t[r];return this.cksum=a,tn(t,e+148,8,this.cksum),this.cksumValid=!0,this.needPax}get type(){return"Unsupported"===this.#R?this.#R:$r.get(this.#R)}get typeKey(){return this.#R}set type(t){let e=String(Gr.get(t));if(Ur(e)||"Unsupported"===e)this.#R=e;else{if(!Ur(t))throw new TypeError("invalid entry type: "+t);this.#R=t}}},Hr=(t,e)=>{let r,n=t,s="",i=B.posix.parse(t).root||".";if(Buffer.byteLength(n)<100)r=[n,s,!1];else{s=B.posix.dirname(n),n=B.posix.basename(n);do{Buffer.byteLength(n)<=100&&Buffer.byteLength(s)<=e?r=[n,s,!1]:Buffer.byteLength(n)>100&&Buffer.byteLength(s)<=e?r=[n.slice(0,99),s,!0]:(n=B.posix.join(B.posix.basename(s),n),s=B.posix.dirname(s))}while(s!==i&&void 0===r);r||(r=[t.slice(0,99),"",!0])}return r},zr=(t,e,r)=>t.subarray(e,e+r).toString("utf8").replace(/\0.*/,""),Wr=(t,e,r)=>Yr(Vr(t,e,r)),Yr=t=>void 0===t?void 0:new Date(1e3*t),Vr=(t,e,r)=>128&Number(t[e])?(t=>{let e=t[0],r=128===e?(t=>{for(var e=t.length,r=0,n=e-1;n>-1;n--){var s=Number(t[n]);0!==s&&(r+=s*Math.pow(256,e-n-1))}return r})(t.subarray(1,t.length)):255===e?(t=>{for(var e=t.length,r=0,n=!1,s=e-1;s>-1;s--){var i,a=Number(t[s]);n?i=Or(a):0===a?i=a:(n=!0,i=Mr(a)),0!==i&&(r-=i*Math.pow(256,e-s-1))}return r})(t):null;if(null===r)throw Error("invalid base256 encoding");if(!Number.isSafeInteger(r))throw Error("parsed number outside of javascript safe integer range");return r})(t.subarray(e,e+r)):Xr(t,e,r),Xr=(t,e,r)=>(t=>isNaN(t)?void 0:t)(parseInt(t.subarray(e,e+r).toString("utf8").replace(/\0.*$/,"").trim(),8)),Zr={12:8589934591,8:2097151},tn=(t,e,r,n)=>void 0!==n&&(n>Zr[r]||n<0?(((t,e)=>{if(!Number.isSafeInteger(t))throw Error("cannot encode number outside of javascript safe integer range");t<0?((t,e)=>{e[0]=255;var r=!1;t*=-1;for(var n=e.length;n>1;n--){var s=255&t;t=Math.floor(t/256),r?e[n-1]=Or(s):0===s?e[n-1]=0:(r=!0,e[n-1]=Mr(s))}})(t,e):((t,e)=>{e[0]=128;for(var r=e.length;r>1;r--)e[r-1]=255&t,t=Math.floor(t/256)})(t,e)})(n,t.subarray(e,e+r)),!0):(en(t,e,r,n),!1)),en=(t,e,r,n)=>t.write(rn(n,r),e,r,"ascii"),rn=(t,e)=>nn(Math.floor(t).toString(8),e),nn=(t,e)=>(t.length===e-1?t:new Array(e-t.length-1).join("0")+t+" ")+"\0",sn=(t,e,r,n)=>void 0!==n&&tn(t,e,r,n.getTime()/1e3),an=new Array(156).join("\0"),on=(t,e,r,n)=>void 0!==n&&(t.write(n+an,e,r,"utf8"),n.length!==Buffer.byteLength(n)||n.length>r),cn=class t{atime;mtime;ctime;charset;comment;gid;uid;gname;uname;linkpath;dev;ino;nlink;path;size;mode;global;constructor(t,e=!1){this.atime=t.atime,this.charset=t.charset,this.comment=t.comment,this.ctime=t.ctime,this.dev=t.dev,this.gid=t.gid,this.global=e,this.gname=t.gname,this.ino=t.ino,this.linkpath=t.linkpath,this.mtime=t.mtime,this.nlink=t.nlink,this.path=t.path,this.size=t.size,this.uid=t.uid,this.uname=t.uname}encode(){let t=this.encodeBody();if(""===t)return Buffer.allocUnsafe(0);let e=Buffer.byteLength(t),r=512*Math.ceil(1+e/512),n=Buffer.allocUnsafe(r);for(let t=0;t<512;t++)n[t]=0;new Kr({path:("PaxHeader/"+(0,B.basename)(this.path??"")).slice(0,99),mode:this.mode||420,uid:this.uid,gid:this.gid,size:e,mtime:this.mtime,type:this.global?"GlobalExtendedHeader":"ExtendedHeader",linkpath:"",uname:this.uname||"",gname:this.gname||"",devmaj:0,devmin:0,atime:this.atime,ctime:this.ctime}).encode(n),n.write(t,512,e,"utf8");for(let t=e+512;t<n.length;t++)n[t]=0;return n}encodeBody(){return this.encodeField("path")+this.encodeField("ctime")+this.encodeField("atime")+this.encodeField("dev")+this.encodeField("ino")+this.encodeField("nlink")+this.encodeField("charset")+this.encodeField("comment")+this.encodeField("gid")+this.encodeField("gname")+this.encodeField("linkpath")+this.encodeField("mtime")+this.encodeField("size")+this.encodeField("uid")+this.encodeField("uname")}encodeField(t){if(void 0===this[t])return"";let e=this[t],r=" "+("dev"===t||"ino"===t||"nlink"===t?"SCHILY.":"")+t+"="+(e instanceof Date?e.getTime()/1e3:e)+"\n",n=Buffer.byteLength(r),s=Math.floor(Math.log(n)/Math.log(10))+1;return n+s>=Math.pow(10,s)&&(s+=1),s+n+r}static parse(e,r,n=!1){return new t(un(ln(e),r),n)}},un=(t,e)=>e?Object.assign({},e,t):t,ln=t=>t.replace(/\n$/,"").split("\n").reduce(dn,Object.create(null)),dn=(t,e)=>{let r=parseInt(e,10);if(r!==Buffer.byteLength(e)+1)return t;let n=(e=e.slice((r+" ").length)).split("="),s=n.shift();if(!s)return t;let i=s.replace(/^SCHILY\.(dev|ino|nlink)/,"$1"),a=n.join("=").replace(/\0.*/,"");switch(i){case"path":case"linkpath":case"type":case"charset":case"comment":case"gname":case"uname":t[i]=a;break;case"ctime":case"atime":case"mtime":t[i]=new Date(1e3*Number(a));break;case"size":let e=+a;e>=0&&(t[i]=e);break;case"gid":case"uid":case"dev":case"ino":case"nlink":case"mode":t[i]=+a}return t},mn="win32"!==(process.env.TESTING_TAR_FAKE_PLATFORM||"darwin")?t=>String(t):t=>String(t).replaceAll(/\\/g,"/"),pn=class extends De{extended;globalExtended;header;startBlockSize;blockRemain;remain;type;meta=!1;ignore=!1;path;mode;uid;gid;uname;gname;size=0;mtime;atime;ctime;linkpath;dev;ino;nlink;invalid=!1;absolute;unsupported=!1;constructor(t,e,r){switch(super({}),this.pause(),this.extended=e,this.globalExtended=r,this.header=t,this.remain=t.size??0,this.startBlockSize=512*Math.ceil(this.remain/512),this.blockRemain=this.startBlockSize,this.type=t.type,this.type){case"File":case"OldFile":case"Link":case"SymbolicLink":case"CharacterDevice":case"BlockDevice":case"Directory":case"FIFO":case"ContiguousFile":case"GNUDumpDir":break;case"NextFileHasLongLinkpath":case"NextFileHasLongPath":case"OldGnuLongPath":case"GlobalExtendedHeader":case"ExtendedHeader":case"OldExtendedHeader":this.meta=!0;break;default:this.ignore=!0}if(!t.path)throw new Error("no path provided for tar.ReadEntry");this.path=mn(t.path),this.mode=t.mode,this.mode&&(this.mode=4095&this.mode),this.uid=t.uid,this.gid=t.gid,this.uname=t.uname,this.gname=t.gname,this.size=this.remain,this.mtime=t.mtime,this.atime=t.atime,this.ctime=t.ctime,this.linkpath=t.linkpath?mn(t.linkpath):void 0,this.uname=t.uname,this.gname=t.gname,e&&this.#R(e),r&&this.#R(r,!0)}write(t){let e=t.length;if(e>this.blockRemain)throw new Error("writing more to entry than is appropriate");let r=this.remain,n=this.blockRemain;return this.remain=Math.max(0,r-e),this.blockRemain=Math.max(0,n-e),!!this.ignore||(r>=e?super.write(t):super.write(t.subarray(0,r)))}#R(t,e=!1){t.path&&(t.path=mn(t.path)),t.linkpath&&(t.linkpath=mn(t.linkpath)),Object.assign(this,Object.fromEntries(Object.entries(t).filter((([t,r])=>!(null==r||"path"===t&&e)))))}},fn=(t,e,r,n={})=>{t.file&&(n.file=t.file),t.cwd&&(n.cwd=t.cwd),n.code=r instanceof Error&&r.code||e,n.tarCode=e,t.strict||!1===n.recoverable?r instanceof Error?t.emit("error",Object.assign(r,n)):t.emit("error",Object.assign(new Error(`${e}: ${r}`),n)):(r instanceof Error&&(n=Object.assign(r,n),r=r.message),t.emit("warn",e,r,n))},hn=Buffer.from([31,139]),gn=Buffer.from([40,181,47,253]),An=Math.max(hn.length,gn.length),bn=Symbol("state"),yn=Symbol("writeEntry"),_n=Symbol("readEntry"),wn=Symbol("nextEntry"),Cn=Symbol("processEntry"),vn=Symbol("extendedHeader"),En=Symbol("globalExtendedHeader"),Sn=Symbol("meta"),In=Symbol("emitMeta"),Bn=Symbol("buffer"),kn=Symbol("queue"),Pn=Symbol("ended"),xn=Symbol("emittedEnd"),Rn=Symbol("emit"),Jn=Symbol("unzip"),Tn=Symbol("consumeChunk"),qn=Symbol("consumeChunkSub"),jn=Symbol("consumeBody"),Dn=Symbol("consumeMeta"),Qn=Symbol("consumeHeader"),Nn=Symbol("consuming"),On=Symbol("bufferConcat"),Mn=Symbol("maybeEnd"),Un=Symbol("writing"),Ln=Symbol("aborted"),Fn=Symbol("onDone"),$n=Symbol("sawValidEntry"),Gn=Symbol("sawNullBlock"),Kn=Symbol("sawEOF"),Hn=Symbol("closeStream"),zn=Symbol("compressedBytesRead"),Wn=Symbol("decompressedBytesRead"),Yn=Symbol("checkDecompressionRatio"),Vn=()=>!0,Xn=class extends Ot.EventEmitter{file;strict;maxMetaEntrySize;filter;brotli;zstd;maxDecompressionRatio;writable=!0;readable=!1;[kn]=[];[Bn];[_n];[yn];[bn]="begin";[Sn]="";[vn];[En];[Pn]=!1;[Jn];[Ln]=!1;[$n];[Gn]=!1;[Kn]=!1;[Un]=!1;[Nn]=!1;[xn]=!1;[zn]=0;[Wn]=0;constructor(t={}){super(),this.file=t.file||"",this.on(Fn,(()=>{("begin"===this[bn]||!1===this[$n])&&this.warn("TAR_BAD_ARCHIVE","Unrecognized archive format")})),t.ondone?this.on(Fn,t.ondone):this.on(Fn,(()=>{this.emit("prefinish"),this.emit("finish"),this.emit("end")})),this.strict=!!t.strict,this.maxDecompressionRatio="number"==typeof t.maxDecompressionRatio?t.maxDecompressionRatio:1e3,this.maxMetaEntrySize=t.maxMetaEntrySize||1048576,this.filter="function"==typeof t.filter?t.filter:Vn;let e=t.file&&(t.file.endsWith(".tar.br")||t.file.endsWith(".tbr"));this.brotli=t.gzip||t.zstd||void 0===t.brotli?!!e&&void 0:t.brotli;let r=t.file&&(t.file.endsWith(".tar.zst")||t.file.endsWith(".tzst"));this.zstd=t.gzip||t.brotli||void 0===t.zstd?!!r||void 0:t.zstd,this.on("end",(()=>this[Hn]())),"function"==typeof t.onwarn&&this.on("warn",t.onwarn),"function"==typeof t.onReadEntry&&this.on("entry",t.onReadEntry)}warn(t,e,r={}){fn(this,t,e,r)}[Qn](t,e){let r;void 0===this[$n]&&(this[$n]=!1);try{r=new Kr(t,e,this[vn],this[En])}catch(t){return this.warn("TAR_ENTRY_INVALID",t)}if(r.nullBlock)this[Gn]?(this[Kn]=!0,"begin"===this[bn]&&(this[bn]="header"),this[Rn]("eof")):(this[Gn]=!0,this[Rn]("nullBlock"));else if(this[Gn]=!1,r.cksumValid)if(r.path){let t=r.type;if(/^(Symbolic)?Link$/.test(t)&&!r.linkpath)this.warn("TAR_ENTRY_INVALID","linkpath required",{header:r});else if(/^(Symbolic)?Link$/.test(t)||/^(Global)?ExtendedHeader$/.test(t)||!r.linkpath){let t=this[yn]=new pn(r,this[vn],this[En]);if(!this[$n])if(t.remain){let e=()=>{t.invalid||(this[$n]=!0)};t.on("end",e)}else this[$n]=!0;t.meta?t.size>this.maxMetaEntrySize?(t.ignore=!0,this[Rn]("ignoredEntry",t),this[bn]="ignore",t.resume()):t.size>0&&(this[Sn]="",t.on("data",(t=>this[Sn]+=t)),this[bn]="meta"):(this[vn]=void 0,t.ignore=t.ignore||!this.filter(t.path,t),t.ignore?(this[Rn]("ignoredEntry",t),this[bn]=t.remain?"ignore":"header",t.resume()):(t.remain?this[bn]="body":(this[bn]="header",t.end()),this[_n]?this[kn].push(t):(this[kn].push(t),this[wn]())))}else this.warn("TAR_ENTRY_INVALID","linkpath forbidden",{header:r})}else this.warn("TAR_ENTRY_INVALID","path is required",{header:r});else this.warn("TAR_ENTRY_INVALID","checksum failure",{header:r})}[Hn](){queueMicrotask((()=>this.emit("close")))}[Cn](t){let e=!0;if(t)if(Array.isArray(t)){let[e,...r]=t;this.emit(e,...r)}else this[_n]=t,this.emit("entry",t),t.emittedEnd||(t.on("end",(()=>this[wn]())),e=!1);else this[_n]=void 0,e=!1;return e}[wn](){do{}while(this[Cn](this[kn].shift()));if(0===this[kn].length){let t=this[_n];!t||t.flowing||t.size===t.remain?this[Un]||this.emit("drain"):t.once("drain",(()=>this.emit("drain")))}}[jn](t,e){let r=this[yn];if(!r)throw new Error("attempt to consume body without entry??");let n=r.blockRemain??0,s=n>=t.length&&0===e?t:t.subarray(e,e+n);return r.write(s),r.blockRemain||(this[bn]="header",this[yn]=void 0,r.end()),s.length}[Dn](t,e){let r=this[yn],n=this[jn](t,e);return!this[yn]&&r&&this[In](r),n}[Rn](t,e,r){0!==this[kn].length||this[_n]?this[kn].push([t,e,r]):this.emit(t,e,r)}[In](t){switch(this[Rn]("meta",this[Sn]),t.type){case"ExtendedHeader":case"OldExtendedHeader":this[vn]=cn.parse(this[Sn],this[vn],!1);break;case"GlobalExtendedHeader":this[En]=cn.parse(this[Sn],this[En],!0);break;case"NextFileHasLongPath":case"OldGnuLongPath":{let t=this[vn]??Object.create(null);this[vn]=t,t.path=this[Sn].replace(/\0.*/,"");break}case"NextFileHasLongLinkpath":{let t=this[vn]||Object.create(null);this[vn]=t,t.linkpath=this[Sn].replace(/\0.*/,"");break}default:throw new Error("unknown meta: "+t.type)}}abort(t){if(!this[Ln]){if(this[Jn]){let t=this[Jn];t.write=()=>!0,t.end=()=>t,t.emit=()=>!1,t.destroy?.()}this[Ln]=!0,this.emit("abort",t),this.warn("TAR_ABORT",t,{recoverable:!1})}}[Yn](t){this[Wn]+=t.length;let e=this[Wn]/this[zn];return!(e>this.maxDecompressionRatio&&(this.abort(new Error(`max decompression ratio exceeded: ${e.toFixed(2)} > ${this.maxDecompressionRatio}`)),1))}write(t,e,r){if("function"==typeof e&&(r=e,e=void 0),"string"==typeof t&&(t=Buffer.from(t,"string"==typeof e?e:"utf8")),this[Ln])return r?.(),!1;if((void 0===this[Jn]||void 0===this.brotli&&!1===this[Jn])&&t){if(this[Bn]&&(t=Buffer.concat([this[Bn],t]),this[Bn]=void 0),t.length<An)return this[Bn]=t,r?.(),!0;for(let e=0;void 0===this[Jn]&&e<hn.length;e++)t[e]!==hn[e]&&(this[Jn]=!1);let e=!1;if(!1===this[Jn]&&!1!==this.zstd){e=!0;for(let r=0;r<gn.length;r++)if(t[r]!==gn[r]){e=!1;break}}let n=void 0===this.brotli&&!e;if(!1===this[Jn]&&n)if(t.length<512){if(!this[Pn])return this[Bn]=t,r?.(),!0;this.brotli=!0}else try{new Kr(t.subarray(0,512)),this.brotli=!1}catch{this.brotli=!0}if(void 0===this[Jn]||!1===this[Jn]&&(this.brotli||e)){let n=this[Pn];this[Pn]=!1,this[Jn]=void 0===this[Jn]?new Jr({}):e?new Nr({}):new jr({}),this[Jn].on("data",(t=>{this[Yn](t)&&this[Tn](t)})),this[Jn].on("error",(t=>{this[Ln]||this.abort(t)})),this[Jn].on("end",(()=>{this[Pn]=!0,this[Tn]()})),this[Un]=!0,this[zn]+=t.length;let s=!!this[Jn][n?"end":"write"](t);return this[Un]=!1,r?.(),s}}this[Un]=!0,this[Jn]?(this[zn]+=t.length,this[Jn].write(t)):this[Tn](t),this[Un]=!1;let n=!(this[kn].length>0)&&(!this[_n]||this[_n].flowing);return!n&&0===this[kn].length&&this[_n]?.once("drain",(()=>this.emit("drain"))),r?.(),n}[On](t){t&&!this[Ln]&&(this[Bn]=this[Bn]?Buffer.concat([this[Bn],t]):t)}[Mn](){if(this[Pn]&&!this[xn]&&!this[Ln]&&!this[Nn]){this[xn]=!0;let t=this[yn];if(t?.blockRemain){let e=this[Bn]?this[Bn].length:0;this.warn("TAR_BAD_ARCHIVE",`Truncated input (needed ${t.blockRemain} more bytes, only ${e} available)`,{entry:t}),this[Bn]&&t.write(this[Bn]),t.end()}this[Rn](Fn)}}[Tn](t){if(this[Nn]&&t)this[On](t);else if(t||this[Bn]){if(t){if(this[Nn]=!0,this[Bn]){this[On](t);let e=this[Bn];this[Bn]=void 0,this[qn](e)}else this[qn](t);for(;this[Bn]&&this[Bn]?.length>=512&&!this[Ln]&&!this[Kn];){let t=this[Bn];this[Bn]=void 0,this[qn](t)}this[Nn]=!1}}else this[Mn]();(!this[Bn]||this[Pn])&&this[Mn]()}[qn](t){let e=0,r=t.length;for(;e+512<=r&&!this[Ln]&&!this[Kn];)switch(this[bn]){case"begin":case"header":this[Qn](t,e),e+=512;break;case"ignore":case"body":e+=this[jn](t,e);break;case"meta":e+=this[Dn](t,e);break;default:throw new Error("invalid state: "+this[bn])}e<r&&(this[Bn]=this[Bn]?Buffer.concat([t.subarray(e),this[Bn]]):t.subarray(e))}end(t,e,r){return"function"==typeof t&&(r=t,e=void 0,t=void 0),"function"==typeof e&&(r=e,e=void 0),"string"==typeof t&&(t=Buffer.from(t,e)),r&&this.once("finish",r),this[Ln]||(this[Jn]?(t&&(this[zn]+=t.length,this[Jn].write(t)),this[Jn].end()):(this[Pn]=!0,(void 0===this.brotli||void 0===this.zstd)&&(t=t||Buffer.alloc(0)),t&&this.write(t),this[Mn]())),this}},Zn=t=>{let e=t.length-1,r=-1;for(;e>-1&&"/"===t.charAt(e);)r=e,e--;return-1===r?t:t.slice(0,r)},ts=(t,e)=>{let r=new Map(e.map((t=>[Zn(t),!0]))),n=t.filter,s=(t,e="",n=0)=>{if(n>=100)return r.set(t,!1),!1;let i,a=e||(0,$t.parse)(t).root||".";if(t===a)i=!1;else{let e=r.get(t);i=void 0!==e?e:s((0,$t.dirname)(t),a,n+1)}return r.set(t,i),i};t.filter=n?(t,e)=>n(t,e)&&s(Zn(t)):t=>s(Zn(t))},es=yr((t=>{let e,r=new Xn(t),n=t.file;try{e=Ft.openSync(n,"r");let s=Ft.fstatSync(e),i=t.maxReadSize||16777216;if(s.size<i){let t=Buffer.allocUnsafe(s.size),n=Ft.readSync(e,t,0,s.size,0);r.end(n===t.byteLength?t:t.subarray(0,n))}else{let t=0,n=Buffer.allocUnsafe(i);for(;t<s.size;){let s=Ft.readSync(e,n,0,i,t);if(0===s)break;t+=s,r.write(n.subarray(0,s))}r.end()}}finally{if("number"==typeof e)try{Ft.closeSync(e)}catch{}}}),((t,e)=>{let r=new Xn(t),n=t.maxReadSize||16777216,s=t.file;return new Promise(((t,e)=>{r.on("error",e),r.on("end",t),Ft.stat(s,((t,i)=>{if(t)e(t);else{let t=new mr(s,{readSize:n,size:i.size});t.on("error",e),t.pipe(r)}}))}))}),(t=>new Xn(t)),(t=>new Xn(t)),((t,e)=>{e?.length&&ts(t,e),t.noResume||(t=>{let e=t.onReadEntry;t.onReadEntry=e?t=>{e(t),t.resume()}:t=>t.resume()})(t)})),rs=(t,e,r)=>(t&=4095,r&&(t=-19&t|384),e&&(256&t&&(t|=64),32&t&&(t|=8),4&t&&(t|=1)),t),{isAbsolute:ns,parse:ss}=B.win32,is=t=>{let e="",r=ss(t);for(;ns(t)||r.root;){let n="/"===t.charAt(0)&&"//?/"!==t.slice(0,4)?"/":r.root;t=t.slice(n.length),e+=n,r=ss(t)}return[e,t]},as=["|","<",">","?",":"],os=as.map((t=>String.fromCodePoint(61440+Number(t.codePointAt(0))))),cs=new Map(as.map(((t,e)=>[t,os[e]]))),us=new Map(os.map(((t,e)=>[t,as[e]]))),ls=t=>as.reduce(((t,e)=>t.split(e).join(cs.get(e))),t),ds=(t,e)=>e?(t=mn(t).replace(/^\.(\/|$)/,""),Zn(e)+"/"+t):mn(t),ms=Symbol("process"),ps=Symbol("file"),fs=Symbol("directory"),hs=Symbol("symlink"),gs=Symbol("hardlink"),As=Symbol("header"),bs=Symbol("read"),ys=Symbol("lstat"),_s=Symbol("onlstat"),ws=Symbol("onread"),Cs=Symbol("onreadlink"),vs=Symbol("openfile"),Es=Symbol("onopenfile"),Ss=Symbol("close"),Is=Symbol("mode"),Bs=Symbol("awaitDrain"),ks=Symbol("ondrain"),Ps=Symbol("prefix"),xs=class extends De{path;portable;myuid=process.getuid&&process.getuid()||0;myuser=process.env.USER||"";maxReadSize;linkCache;statCache;preservePaths;cwd;strict;mtime;noPax;noMtime;prefix;fd;blockLen=0;blockRemain=0;buf;pos=0;remain=0;length=0;offset=0;win32;absolute;header;type;linkpath;stat;onWriteEntry;#R=!1;constructor(t,e={}){let r=br(e);super(),this.path=mn(t),this.portable=!!r.portable,this.maxReadSize=r.maxReadSize||16777216,this.linkCache=r.linkCache||new Map,this.statCache=r.statCache||new Map,this.preservePaths=!!r.preservePaths,this.cwd=mn(r.cwd||process.cwd()),this.strict=!!r.strict,this.noPax=!!r.noPax,this.noMtime=!!r.noMtime,this.mtime=r.mtime,this.prefix=r.prefix?mn(r.prefix):void 0,this.onWriteEntry=r.onWriteEntry,"function"==typeof r.onwarn&&this.on("warn",r.onwarn);let n=!1;if(!this.preservePaths){let[t,e]=is(this.path);t&&"string"==typeof e&&(this.path=e,n=t)}var s;this.win32=!!r.win32||!1,this.win32&&(this.path=(s=this.path.replaceAll(/\\/g,"/"),os.reduce(((t,e)=>t.split(e).join(us.get(e))),s)),t=t.replaceAll(/\\/g,"/")),this.absolute=mn(r.absolute||$t.resolve(this.cwd,t)),""===this.path&&(this.path="./"),n&&this.warn("TAR_ENTRY_INFO",`stripping ${n} from absolute path`,{entry:this,path:n+this.path});let i=this.statCache.get(this.absolute);i?this[_s](i):this[ys]()}warn(t,e,r={}){return fn(this,t,e,r)}emit(t,...e){return"error"===t&&(this.#R=!0),super.emit(t,...e)}[ys](){Mt.lstat(this.absolute,((t,e)=>{if(t)return this.emit("error",t);this[_s](e)}))}[_s](t){this.statCache.set(this.absolute,t),this.stat=t,t.isFile()||(t.size=0),this.type=Ts(t),this.emit("stat",t),this[ms]()}[ms](){switch(this.type){case"File":return this[ps]();case"Directory":return this[fs]();case"SymbolicLink":return this[hs]();default:return this.end()}}[Is](t){return rs(t,"Directory"===this.type,this.portable)}[Ps](t){return ds(t,this.prefix)}[As](){if(!this.stat)throw new Error("cannot write header before stat");"Directory"===this.type&&this.portable&&(this.noMtime=!0),this.onWriteEntry?.(this),this.header=new Kr({path:this[Ps](this.path),linkpath:"Link"===this.type&&void 0!==this.linkpath?this[Ps](this.linkpath):this.linkpath,mode:this[Is](this.stat.mode),uid:this.portable?void 0:this.stat.uid,gid:this.portable?void 0:this.stat.gid,size:this.stat.size,mtime:this.noMtime?void 0:this.mtime||this.stat.mtime,type:"Unsupported"===this.type?void 0:this.type,uname:this.portable?void 0:this.stat.uid===this.myuid?this.myuser:"",atime:this.portable?void 0:this.stat.atime,ctime:this.portable?void 0:this.stat.ctime}),this.header.encode()&&!this.noPax&&super.write(new cn({atime:this.portable?void 0:this.header.atime,ctime:this.portable?void 0:this.header.ctime,gid:this.portable?void 0:this.header.gid,mtime:this.noMtime?void 0:this.mtime||this.header.mtime,path:this[Ps](this.path),linkpath:"Link"===this.type&&void 0!==this.linkpath?this[Ps](this.linkpath):this.linkpath,size:this.header.size,uid:this.portable?void 0:this.header.uid,uname:this.portable?void 0:this.header.uname,dev:this.portable?void 0:this.stat.dev,ino:this.portable?void 0:this.stat.ino,nlink:this.portable?void 0:this.stat.nlink}).encode());let t=this.header?.block;if(!t)throw new Error("failed to encode header");super.write(t)}[fs](){if(!this.stat)throw new Error("cannot create directory entry without stat");"/"!==this.path.slice(-1)&&(this.path+="/"),this.stat.size=0,this[As](),this.end()}[hs](){Mt.readlink(this.absolute,((t,e)=>{if(t)return this.emit("error",t);this[Cs](e)}))}[Cs](t){this.linkpath=mn(t),this[As](),this.end()}[gs](t){if(!this.stat)throw new Error("cannot create link entry without stat");this.type="Link",this.linkpath=mn($t.relative(this.cwd,t)),this.stat.size=0,this[As](),this.end()}[ps](){if(!this.stat)throw new Error("cannot create file entry without stat");if(this.stat.nlink>1){let t=`${this.stat.dev}:${this.stat.ino}`,e=this.linkCache.get(t);if(0===e?.indexOf(this.cwd))return this[gs](e);this.linkCache.set(t,this.absolute)}if(this[As](),0===this.stat.size)return this.end();this[vs]()}[vs](){Mt.open(this.absolute,"r",((t,e)=>{if(t)return this.emit("error",t);this[Es](e)}))}[Es](t){if(this.fd=t,this.#R)return this[Ss]();if(!this.stat)throw new Error("should stat before calling onopenfile");this.blockLen=512*Math.ceil(this.stat.size/512),this.blockRemain=this.blockLen;let e=Math.min(this.blockLen,this.maxReadSize);this.buf=Buffer.allocUnsafe(e),this.offset=0,this.pos=0,this.remain=this.stat.size,this.length=this.buf.length,this[bs]()}[bs](){let{fd:t,buf:e,offset:r,length:n,pos:s}=this;if(void 0===t||void 0===e)throw new Error("cannot read file without first opening");Mt.read(t,e,r,n,s,((t,e)=>{if(t)return this[Ss]((()=>this.emit("error",t)));this[ws](e)}))}[Ss](t=()=>{}){void 0!==this.fd&&Mt.close(this.fd,t)}[ws](t){if(t<=0&&this.remain>0){let t=Object.assign(new Error("encountered unexpected EOF"),{path:this.absolute,syscall:"read",code:"EOF"});return this[Ss]((()=>this.emit("error",t)))}if(t>this.remain){let t=Object.assign(new Error("did not encounter expected EOF"),{path:this.absolute,syscall:"read",code:"EOF"});return this[Ss]((()=>this.emit("error",t)))}if(!this.buf)throw new Error("should have created buffer prior to reading");if(t===this.remain)for(let e=t;e<this.length&&t<this.blockRemain;e++)this.buf[e+this.offset]=0,t++,this.remain++;let e=0===this.offset&&t===this.buf.length?this.buf:this.buf.subarray(this.offset,this.offset+t);this.write(e)?this[ks]():this[Bs]((()=>this[ks]()))}[Bs](t){this.once("drain",t)}write(t,e,r){if("function"==typeof e&&(r=e,e=void 0),"string"==typeof t&&(t=Buffer.from(t,"string"==typeof e?e:"utf8")),this.blockRemain<t.length){let t=Object.assign(new Error("writing more data than expected"),{path:this.absolute});return this.emit("error",t)}return this.remain-=t.length,this.blockRemain-=t.length,this.pos+=t.length,this.offset+=t.length,super.write(t,null,r)}[ks](){if(!this.remain)return this.blockRemain&&super.write(Buffer.alloc(this.blockRemain)),this[Ss]((t=>t?this.emit("error",t):this.end()));if(!this.buf)throw new Error("buffer lost somehow in ONDRAIN");this.offset>=this.length&&(this.buf=Buffer.allocUnsafe(Math.min(this.blockRemain,this.buf.length)),this.offset=0),this.length=this.buf.length-this.offset,this[bs]()}},Rs=class extends xs{sync=!0;[ys](){this[_s](Mt.lstatSync(this.absolute))}[hs](){this[Cs](Mt.readlinkSync(this.absolute))}[vs](){this[Es](Mt.openSync(this.absolute,"r"))}[bs](){let t=!0;try{let{fd:e,buf:r,offset:n,length:s,pos:i}=this;if(void 0===e||void 0===r)throw new Error("fd and buf must be set in READ method");let a=Mt.readSync(e,r,n,s,i);this[ws](a),t=!1}finally{if(t)try{this[Ss]((()=>{}))}catch{}}}[Bs](t){t()}[Ss](t=()=>{}){void 0!==this.fd&&Mt.closeSync(this.fd),t()}},Js=class extends De{blockLen=0;blockRemain=0;buf=0;pos=0;remain=0;length=0;preservePaths;portable;strict;noPax;noMtime;readEntry;type;prefix;path;mode;uid;gid;uname;gname;header;mtime;atime;ctime;linkpath;size;onWriteEntry;warn(t,e,r={}){return fn(this,t,e,r)}constructor(t,e={}){let r=br(e);super(),this.preservePaths=!!r.preservePaths,this.portable=!!r.portable,this.strict=!!r.strict,this.noPax=!!r.noPax,this.noMtime=!!r.noMtime,this.onWriteEntry=r.onWriteEntry,this.readEntry=t;let{type:n}=t;if("Unsupported"===n)throw new Error("writing entry that should be ignored");this.type=n,"Directory"===this.type&&this.portable&&(this.noMtime=!0),this.prefix=r.prefix,this.path=mn(t.path),this.mode=void 0!==t.mode?this[Is](t.mode):void 0,this.uid=this.portable?void 0:t.uid,this.gid=this.portable?void 0:t.gid,this.uname=this.portable?void 0:t.uname,this.gname=this.portable?void 0:t.gname,this.size=t.size,this.mtime=this.noMtime?void 0:r.mtime||t.mtime,this.atime=this.portable?void 0:t.atime,this.ctime=this.portable?void 0:t.ctime,this.linkpath=void 0!==t.linkpath?mn(t.linkpath):void 0,"function"==typeof r.onwarn&&this.on("warn",r.onwarn);let s=!1;if(!this.preservePaths){let[t,e]=is(this.path);t&&"string"==typeof e&&(this.path=e,s=t)}this.remain=t.size,this.blockRemain=t.startBlockSize,this.onWriteEntry?.(this),this.header=new Kr({path:this[Ps](this.path),linkpath:"Link"===this.type&&void 0!==this.linkpath?this[Ps](this.linkpath):this.linkpath,mode:this.mode,uid:this.portable?void 0:this.uid,gid:this.portable?void 0:this.gid,size:this.size,mtime:this.noMtime?void 0:this.mtime,type:this.type,uname:this.portable?void 0:this.uname,atime:this.portable?void 0:this.atime,ctime:this.portable?void 0:this.ctime}),s&&this.warn("TAR_ENTRY_INFO",`stripping ${s} from absolute path`,{entry:this,path:s+this.path}),this.header.encode()&&!this.noPax&&super.write(new cn({atime:this.portable?void 0:this.atime,ctime:this.portable?void 0:this.ctime,gid:this.portable?void 0:this.gid,mtime:this.noMtime?void 0:this.mtime,path:this[Ps](this.path),linkpath:"Link"===this.type&&void 0!==this.linkpath?this[Ps](this.linkpath):this.linkpath,size:this.size,uid:this.portable?void 0:this.uid,uname:this.portable?void 0:this.uname,dev:this.portable?void 0:this.readEntry.dev,ino:this.portable?void 0:this.readEntry.ino,nlink:this.portable?void 0:this.readEntry.nlink}).encode());let i=this.header?.block;if(!i)throw new Error("failed to encode header");super.write(i),t.pipe(this)}[Ps](t){return ds(t,this.prefix)}[Is](t){return rs(t,"Directory"===this.type,this.portable)}write(t,e,r){"function"==typeof e&&(r=e,e=void 0),"string"==typeof t&&(t=Buffer.from(t,"string"==typeof e?e:"utf8"));let n=t.length;if(n>this.blockRemain)throw new Error("writing more to entry than is appropriate");return this.blockRemain-=n,super.write(t,r)}end(t,e,r){return this.blockRemain&&super.write(Buffer.alloc(this.blockRemain)),"function"==typeof t&&(r=t,e=void 0,t=void 0),"function"==typeof e&&(r=e,e=void 0),"string"==typeof t&&(t=Buffer.from(t,e??"utf8")),r&&this.once("finish",r),t?super.end(t,r):super.end(r),this}},Ts=t=>t.isFile()?"File":t.isDirectory()?"Directory":t.isSymbolicLink()?"SymbolicLink":"Unsupported",qs=class t{tail;head;length=0;static create(e=[]){return new t(e)}constructor(t=[]){for(let e of t)this.push(e)}*[Symbol.iterator](){for(let t=this.head;t;t=t.next)yield t.value}removeNode(t){if(t.list!==this)throw new Error("removing node which does not belong to this list");let e=t.next,r=t.prev;return e&&(e.prev=r),r&&(r.next=e),t===this.head&&(this.head=e),t===this.tail&&(this.tail=r),this.length--,t.next=void 0,t.prev=void 0,t.list=void 0,e}unshiftNode(t){if(t===this.head)return;t.list&&t.list.removeNode(t);let e=this.head;t.list=this,t.next=e,e&&(e.prev=t),this.head=t,this.tail||(this.tail=t),this.length++}pushNode(t){if(t===this.tail)return;t.list&&t.list.removeNode(t);let e=this.tail;t.list=this,t.prev=e,e&&(e.next=t),this.tail=t,this.head||(this.head=t),this.length++}push(...t){for(let e=0,r=t.length;e<r;e++)Ds(this,t[e]);return this.length}unshift(...t){for(var e=0,r=t.length;e<r;e++)Qs(this,t[e]);return this.length}pop(){if(!this.tail)return;let t=this.tail.value,e=this.tail;return this.tail=this.tail.prev,this.tail?this.tail.next=void 0:this.head=void 0,e.list=void 0,this.length--,t}shift(){if(!this.head)return;let t=this.head.value,e=this.head;return this.head=this.head.next,this.head?this.head.prev=void 0:this.tail=void 0,e.list=void 0,this.length--,t}forEach(t,e){e=e||this;for(let r=this.head,n=0;r;n++)t.call(e,r.value,n,this),r=r.next}forEachReverse(t,e){e=e||this;for(let r=this.tail,n=this.length-1;r;n--)t.call(e,r.value,n,this),r=r.prev}get(t){let e=0,r=this.head;for(;r&&e<t;e++)r=r.next;if(e===t&&r)return r.value}getReverse(t){let e=0,r=this.tail;for(;r&&e<t;e++)r=r.prev;if(e===t&&r)return r.value}map(e,r){r=r||this;let n=new t;for(let t=this.head;t;)n.push(e.call(r,t.value,this)),t=t.next;return n}mapReverse(e,r){r=r||this;var n=new t;for(let t=this.tail;t;)n.push(e.call(r,t.value,this)),t=t.prev;return n}reduce(t,e){let r,n=this.head;if(arguments.length>1)r=e;else{if(!this.head)throw new TypeError("Reduce of empty list with no initial value");n=this.head.next,r=this.head.value}for(var s=0;n;s++)r=t(r,n.value,s),n=n.next;return r}reduceReverse(t,e){let r,n=this.tail;if(arguments.length>1)r=e;else{if(!this.tail)throw new TypeError("Reduce of empty list with no initial value");n=this.tail.prev,r=this.tail.value}for(let e=this.length-1;n;e--)r=t(r,n.value,e),n=n.prev;return r}toArray(){let t=new Array(this.length);for(let e=0,r=this.head;r;e++)t[e]=r.value,r=r.next;return t}toArrayReverse(){let t=new Array(this.length);for(let e=0,r=this.tail;r;e++)t[e]=r.value,r=r.prev;return t}slice(e=0,r=this.length){r<0&&(r+=this.length),e<0&&(e+=this.length);let n=new t;if(r<e||r<0)return n;e<0&&(e=0),r>this.length&&(r=this.length);let s=this.head,i=0;for(i=0;s&&i<e;i++)s=s.next;for(;s&&i<r;i++,s=s.next)n.push(s.value);return n}sliceReverse(e=0,r=this.length){r<0&&(r+=this.length),e<0&&(e+=this.length);let n=new t;if(r<e||r<0)return n;e<0&&(e=0),r>this.length&&(r=this.length);let s=this.length,i=this.tail;for(;i&&s>r;s--)i=i.prev;for(;i&&s>e;s--,i=i.prev)n.push(i.value);return n}splice(t,e=0,...r){t>this.length&&(t=this.length-1),t<0&&(t=this.length+t);let n=this.head;for(let e=0;n&&e<t;e++)n=n.next;let s=[];for(let t=0;n&&t<e;t++)s.push(n.value),n=this.removeNode(n);n?n!==this.tail&&(n=n.prev):n=this.tail;for(let t of r)n=js(this,n,t);return s}reverse(){let t=this.head,e=this.tail;for(let e=t;e;e=e.prev){let t=e.prev;e.prev=e.next,e.next=t}return this.head=e,this.tail=t,this}};function js(t,e,r){let n=e,s=e?e.next:t.head,i=new Ns(r,n,s,t);return void 0===i.next&&(t.tail=i),void 0===i.prev&&(t.head=i),t.length++,i}function Ds(t,e){t.tail=new Ns(e,t.tail,void 0,t),t.head||(t.head=t.tail),t.length++}function Qs(t,e){t.head=new Ns(e,void 0,t.head,t),t.tail||(t.tail=t.head),t.length++}var Ns=class{list;next;prev;value;constructor(t,e,r,n){this.list=n,this.value=t,e?(e.next=this,this.prev=e):this.prev=void 0,r?(r.prev=this,this.next=r):this.next=void 0}},Os=class{path;absolute;entry;stat;readdir;pending=!1;pendingLink=!1;ignore=!1;piped=!1;constructor(t,e){this.path=t||"./",this.absolute=e}},Ms=Buffer.alloc(1024),Us=Symbol("onStat"),Ls=Symbol("ended"),Fs=Symbol("queue"),$s=Symbol("pendingLinks"),Gs=Symbol("current"),Ks=Symbol("process"),Hs=Symbol("processing"),zs=Symbol("processJob"),Ws=Symbol("jobs"),Ys=Symbol("jobDone"),Vs=Symbol("addFSEntry"),Xs=Symbol("addTarEntry"),Zs=Symbol("stat"),ti=Symbol("readdir"),ei=Symbol("onreaddir"),ri=Symbol("pipe"),ni=Symbol("entry"),si=Symbol("entryOpt"),ii=Symbol("writeEntryClass"),ai=Symbol("write"),oi=Symbol("ondrain"),ci=class extends De{sync=!1;opt;cwd;maxReadSize;preservePaths;strict;noPax;prefix;linkCache;statCache;file;portable;zip;readdirCache;noDirRecurse;follow;noMtime;mtime;filter;jobs;[ii];onWriteEntry;[Fs];[$s]=new Map;[Ws]=0;[Hs]=!1;[Ls]=!1;constructor(t={}){if(super(),this.opt=t,this.file=t.file||"",this.cwd=t.cwd||process.cwd(),this.maxReadSize=t.maxReadSize,this.preservePaths=!!t.preservePaths,this.strict=!!t.strict,this.noPax=!!t.noPax,this.prefix=mn(t.prefix||""),this.linkCache=t.linkCache||new Map,this.statCache=t.statCache||new Map,this.readdirCache=t.readdirCache||new Map,this.onWriteEntry=t.onWriteEntry,this[ii]=xs,"function"==typeof t.onwarn&&this.on("warn",t.onwarn),this.portable=!!t.portable,t.gzip||t.brotli||t.zstd){if((t.gzip?1:0)+(t.brotli?1:0)+(t.zstd?1:0)>1)throw new TypeError("gzip, brotli, zstd are mutually exclusive");if(t.gzip&&("object"!=typeof t.gzip&&(t.gzip={}),this.portable&&(t.gzip.portable=!0),this.zip=new Rr(t.gzip)),t.brotli&&("object"!=typeof t.brotli&&(t.brotli={}),this.zip=new qr(t.brotli)),t.zstd&&("object"!=typeof t.zstd&&(t.zstd={}),this.zip=new Qr(t.zstd)),!this.zip)throw new Error("impossible");let e=this.zip;e.on("data",(t=>super.write(t))),e.on("end",(()=>super.end())),e.on("drain",(()=>this[oi]())),this.on("resume",(()=>e.resume()))}else this.on("drain",this[oi]);this.noDirRecurse=!!t.noDirRecurse,this.follow=!!t.follow,this.noMtime=!!t.noMtime,t.mtime&&(this.mtime=t.mtime),this.filter="function"==typeof t.filter?t.filter:()=>!0,this[Fs]=new qs,this[Ws]=0,this.jobs=Number(t.jobs)||4,this[Hs]=!1,this[Ls]=!1}[ai](t){return super.write(t)}add(t){return this.write(t),this}end(t,e,r){return"function"==typeof t&&(r=t,t=void 0),"function"==typeof e&&(r=e,e=void 0),t&&this.add(t),this[Ls]=!0,this[Ks](),r&&r(),this}write(t){if(this[Ls])throw new Error("write after end");return"string"==typeof t?this[Vs](t):this[Xs](t),this.flowing}[Xs](t){let e=mn($t.resolve(this.cwd,t.path));if(this.filter(t.path,t)){let r=new Os(t.path,e);r.entry=new Js(t,this[si](r)),r.entry.on("end",(()=>this[Ys](r))),this[Ws]+=1,this[Fs].push(r)}else t.resume();this[Ks]()}[Vs](t){let e=mn($t.resolve(this.cwd,t));this[Fs].push(new Os(t,e)),this[Ks]()}[Zs](t){t.pending=!0,this[Ws]+=1;let e=this.follow?"stat":"lstat";Mt[e](t.absolute,((e,r)=>{t.pending=!1,this[Ws]-=1,e?this.emit("error",e):this[Us](t,r)}))}[Us](t,e){if(this.statCache.set(t.absolute,e),t.stat=e,this.filter(t.path,e)){if(e.isFile()&&e.nlink>1&&!this.linkCache.get(`${e.dev}:${e.ino}`)&&!this.sync)if(t===this[Gs])this[zs](t);else{let r=`${e.dev}:${e.ino}`,n=this[$s].get(r);n?n.push(t):this[$s].set(r,[t]),t.pendingLink=!0,t.pending=!0}}else t.ignore=!0;this[Ks]()}[ti](t){t.pending=!0,this[Ws]+=1,Mt.readdir(t.absolute,((e,r)=>{if(t.pending=!1,this[Ws]-=1,e)return this.emit("error",e);this[ei](t,r)}))}[ei](t,e){this.readdirCache.set(t.absolute,e),t.readdir=e,this[Ks]()}[Ks](){if(!this[Hs]){this[Hs]=!0;for(let t=this[Fs].head;t&&this[Ws]<this.jobs;t=t.next)if(this[zs](t.value),t.value.ignore){let e=t.next;this[Fs].removeNode(t),t.next=e}this[Hs]=!1,this[Ls]&&0===this[Fs].length&&0===this[Ws]&&(this.zip?this.zip.end(Ms):(super.write(Ms),super.end()))}}get[Gs](){return this[Fs]&&this[Fs].head&&this[Fs].head.value}[Ys](t){this[Fs].shift(),this[Ws]-=1;let{stat:e}=t;if(e&&e.isFile()&&e.nlink>1){let t=`${e.dev}:${e.ino}`,r=this[$s].get(t);if(r){this[$s].delete(t);for(let t of r)t.pending=!1,this[zs](t)}}this[Ks]()}[zs](t){if(t.pending&&t.pendingLink&&t===this[Gs]&&(t.pending=!1,t.pendingLink=!1),!t.pending){if(t.entry)return void(t===this[Gs]&&!t.piped&&this[ri](t));if(!t.stat){let e=this.statCache.get(t.absolute);e?this[Us](t,e):this[Zs](t)}if(t.stat&&!t.ignore){if(!this.noDirRecurse&&t.stat.isDirectory()&&!t.readdir){let e=this.readdirCache.get(t.absolute);if(e?this[ei](t,e):this[ti](t),!t.readdir)return}if(t.entry=this[ni](t),!t.entry)return void(t.ignore=!0);t===this[Gs]&&!t.piped&&this[ri](t)}}}[si](t){return{onwarn:(t,e,r)=>this.warn(t,e,r),noPax:this.noPax,cwd:this.cwd,absolute:t.absolute,preservePaths:this.preservePaths,maxReadSize:this.maxReadSize,strict:this.strict,portable:this.portable,linkCache:this.linkCache,statCache:this.statCache,noMtime:this.noMtime,mtime:this.mtime,prefix:this.prefix,onWriteEntry:this.onWriteEntry}}[ni](t){this[Ws]+=1;try{return new this[ii](t.path,this[si](t)).on("end",(()=>this[Ys](t))).on("error",(t=>this.emit("error",t)))}catch(t){this.emit("error",t)}}[oi](){this[Gs]&&this[Gs].entry&&this[Gs].entry.resume()}[ri](t){t.piped=!0,t.readdir&&t.readdir.forEach((e=>{let r=t.path,n="./"===r?"":r.replace(/\/*$/,"/");this[Vs](n+e)}));let e=t.entry,r=this.zip;if(!e)throw new Error("cannot pipe without source");r?e.on("data",(t=>{r.write(t)||e.pause()})):e.on("data",(t=>{super.write(t)||e.pause()}))}pause(){return this.zip&&this.zip.pause(),super.pause()}warn(t,e,r={}){fn(this,t,e,r)}},ui=class extends ci{sync=!0;constructor(t){super(t),this[ii]=Rs}pause(){}resume(){}[Zs](t){let e=this.follow?"statSync":"lstatSync";this[Us](t,Mt[e](t.absolute))}[ti](t){this[ei](t,Mt.readdirSync(t.absolute))}[ri](t){let e=t.entry,r=this.zip;if(t.readdir&&t.readdir.forEach((e=>{let r=t.path,n="./"===r?"":r.replace(/\/*$/,"/");this[Vs](n+e)})),!e)throw new Error("Cannot pipe without source");r?e.on("data",(t=>{r.write(t)})):e.on("data",(t=>{super[ai](t)}))}},li=(t,e)=>{e.forEach((e=>{"@"===e.charAt(0)?es({file:B.resolve(t.cwd,e.slice(1)),sync:!0,noResume:!0,onReadEntry:e=>t.add(e)}):t.add(e)})),t.end()},di=async(t,e)=>{for(let r of e)"@"===r.charAt(0)?await es({file:B.resolve(String(t.cwd),r.slice(1)),noResume:!0,onReadEntry:e=>{t.add(e)}}):t.add(r);t.end()},mi=(yr(((t,e)=>{let r=new ui(t),n=new hr(t.file,{mode:t.mode||438});r.pipe(n),li(r,e)}),((t,e)=>{let r=new ci(t),n=new fr(t.file,{mode:t.mode||438});r.pipe(n);let s=new Promise(((t,e)=>{n.on("error",e),n.on("close",t),r.on("error",e)}));return di(r,e).catch((t=>r.emit("error",t))),s}),((t,e)=>{let r=new ui(t);return li(r,e),r}),((t,e)=>{let r=new ci(t);return di(r,e).catch((t=>r.emit("error",t))),r}),((t,e)=>{if(!e?.length)throw new TypeError("no paths specified to add to archive")})),"win32"===(process.env.__FAKE_PLATFORM__||"darwin")),{O_CREAT:pi,O_NOFOLLOW:fi,O_TRUNC:hi,O_WRONLY:gi}=Mt.constants,Ai=Number(process.env.__FAKE_FS_O_FILENAME__)||Mt.constants.UV_FS_O_FILEMAP||0,bi=Ai|hi|pi|gi,yi=mi||"number"!=typeof fi?null:fi|hi|pi|gi,_i=null!==yi?()=>yi:mi&&Ai?t=>t<524288?bi:"w":()=>"w",wi=(t,e,r)=>{try{return Ft.lchownSync(t,e,r)}catch(t){if("ENOENT"!==t?.code)throw t}},Ci=(t,e,r,n)=>{Ft.lchown(t,e,r,(t=>{n(t&&"ENOENT"!==t?.code?t:null)}))},vi=(t,e,r,n,s)=>{if(e.isDirectory())Ei(B.resolve(t,e.name),r,n,(i=>{if(i)return s(i);let a=B.resolve(t,e.name);Ci(a,r,n,s)}));else{let i=B.resolve(t,e.name);Ci(i,r,n,s)}},Ei=(t,e,r,n)=>{Ft.readdir(t,{withFileTypes:!0},((s,i)=>{if(s){if("ENOENT"===s.code)return n();if("ENOTDIR"!==s.code&&"ENOTSUP"!==s.code)return n(s)}if(s||!i.length)return Ci(t,e,r,n);let a=i.length,o=null,c=s=>{if(!o){if(s)return n(o=s);if(0==--a)return Ci(t,e,r,n)}};for(let n of i)vi(t,n,e,r,c)}))},Si=(t,e,r,n)=>{e.isDirectory()&&Ii(B.resolve(t,e.name),r,n),wi(B.resolve(t,e.name),r,n)},Ii=(t,e,r)=>{let n;try{n=Ft.readdirSync(t,{withFileTypes:!0})}catch(n){let s=n;if("ENOENT"===s?.code)return;if("ENOTDIR"===s?.code||"ENOTSUP"===s?.code)return wi(t,e,r);throw s}for(let s of n)Si(t,s,e,r);return wi(t,e,r)},Bi=class extends Error{path;code;syscall="chdir";constructor(t,e){super(`${e}: Cannot cd into '${t}'`),this.path=t,this.code=e}get name(){return"CwdError"}},ki=class extends Error{path;symlink;syscall="symlink";code="TAR_SYMLINK_ERROR";constructor(t,e){super("TAR_SYMLINK_ERROR: Cannot extract through symbolic link"),this.symlink=t,this.path=e}get name(){return"SymlinkError"}},Pi=(t,e,r,n,s,i,a)=>{if(0===e.length)return a(null,i);let o=e.shift(),c=mn(B.resolve(t+"/"+o));Ft.mkdir(c,r,xi(c,e,r,n,s,i,a))},xi=(t,e,r,n,s,i,a)=>o=>{o?Ft.lstat(t,((c,u)=>{if(c)c.path=c.path&&mn(c.path),a(c);else if(u.isDirectory())Pi(t,e,r,n,s,i,a);else if(n)Ft.unlink(t,(o=>{if(o)return a(o);Ft.mkdir(t,r,xi(t,e,r,n,s,i,a))}));else{if(u.isSymbolicLink())return a(new ki(t,t+"/"+e.join("/")));a(o)}})):Pi(t,e,r,n,s,i=i||t,a)},Ri=Object.create(null),Ji=new Set,Ti="win32"===(process.env.TESTING_TAR_FAKE_PLATFORM||"darwin"),qi=class{#R=new Map;#J=new Map;#T=new Set;reserve(t,e){t=Ti?["win32 parallelization disabled"]:t.map((t=>Zn((0,B.join)((t=>{Ji.has(t)?Ji.delete(t):Ri[t]=t.normalize("NFD").toLocaleLowerCase("en").toLocaleUpperCase("en"),Ji.add(t);let e=Ri[t],r=Ji.size-1e4;if(r>1e3)for(let t of Ji)if(Ji.delete(t),delete Ri[t],--r<=0)break;return e})(t)))));let r=new Set(t.map((t=>t.split("/").slice(0,-1).reduce(((t,e)=>{let r=t.at(-1);return void 0!==r&&(e=(0,B.join)(r,e)),t.push(e||"/"),t}),[]))).reduce(((t,e)=>t.concat(e))));this.#J.set(e,{dirs:r,paths:t});for(let r of t){let t=this.#R.get(r);t?t.push(e):this.#R.set(r,[e])}for(let t of r){let r=this.#R.get(t);if(r){let t=r.at(-1);t instanceof Set?t.add(e):r.push(new Set([e]))}else this.#R.set(t,[new Set([e])])}return this.#j(e)}#q(t){let e=this.#J.get(t);if(!e)throw new Error("function does not have any path reservations");return{paths:e.paths.map((t=>this.#R.get(t))),dirs:[...e.dirs].map((t=>this.#R.get(t)))}}check(t){let{paths:e,dirs:r}=this.#q(t);return e.every((e=>e&&e[0]===t))&&r.every((e=>e&&e[0]instanceof Set&&e[0].has(t)))}#j(t){return!(this.#T.has(t)||!this.check(t)||(this.#T.add(t),t((()=>this.#D(t))),0))}#D(t){if(!this.#T.has(t))return!1;let e=this.#J.get(t);if(!e)throw new Error("invalid reservation");let{paths:r,dirs:n}=e,s=new Set;for(let e of r){let r=this.#R.get(e);if(!r||r?.[0]!==t)continue;let n=r[1];if(n)if(r.shift(),"function"==typeof n)s.add(n);else for(let t of n)s.add(t);else this.#R.delete(e)}for(let e of n){let r=this.#R.get(e),n=r?.[0];if(r&&n instanceof Set){if(1===n.size&&1===r.length){this.#R.delete(e);continue}if(1===n.size){r.shift();let t=r[0];"function"==typeof t&&s.add(t)}else n.delete(t)}}return this.#T.delete(t),s.forEach((t=>this.#j(t))),!0}},ji=Symbol("onEntry"),Di=Symbol("checkFs"),Qi=Symbol("checkFs2"),Ni=Symbol("isReusable"),Oi=Symbol("makeFs"),Mi=Symbol("file"),Ui=Symbol("directory"),Li=Symbol("link"),Fi=Symbol("symlink"),$i=Symbol("hardlink"),Gi=Symbol("ensureNoSymlink"),Ki=Symbol("unsupported"),Hi=Symbol("checkPath"),zi=Symbol("stripAbsolutePath"),Wi=Symbol("mkdir"),Yi=Symbol("onError"),Vi=Symbol("pending"),Xi=Symbol("pend"),Zi=Symbol("unpend"),ta=Symbol("ended"),ea=Symbol("maybeClose"),ra=Symbol("skip"),na=Symbol("doChown"),sa=Symbol("uid"),ia=Symbol("gid"),aa=Symbol("checkedCwd"),oa="win32"===(process.env.TESTING_TAR_FAKE_PLATFORM||"darwin"),ca=(t,e,r)=>void 0!==t&&t===t>>>0?t:void 0!==e&&e===e>>>0?e:r,ua=class extends Xn{[ta]=!1;[aa]=!1;[Vi]=0;reservations=new qi;transform;writable=!0;readable=!1;uid;gid;setOwner;preserveOwner;processGid;processUid;maxDepth;forceChown;win32;newer;keep;noMtime;preservePaths;unlink;cwd;strip;processUmask;umask;dmode;fmode;chmod;constructor(t={}){if(t.ondone=()=>{this[ta]=!0,this[ea]()},super(t),this.transform=t.transform,this.chmod=!!t.chmod,"number"==typeof t.uid||"number"==typeof t.gid){if("number"!=typeof t.uid||"number"!=typeof t.gid)throw new TypeError("cannot set owner without number uid and gid");if(t.preserveOwner)throw new TypeError("cannot preserve owner in archive and also set owner explicitly");this.uid=t.uid,this.gid=t.gid,this.setOwner=!0}else this.uid=void 0,this.gid=void 0,this.setOwner=!1;this.preserveOwner=void 0===t.preserveOwner&&"number"!=typeof t.uid?0===process.getuid?.():!!t.preserveOwner,this.processUid=(this.preserveOwner||this.setOwner)&&process.getuid?process.getuid():void 0,this.processGid=(this.preserveOwner||this.setOwner)&&process.getgid?process.getgid():void 0,this.maxDepth="number"==typeof t.maxDepth?t.maxDepth:1024,this.forceChown=!0===t.forceChown,this.win32=!!t.win32||oa,this.newer=!!t.newer,this.keep=!!t.keep,this.noMtime=!!t.noMtime,this.preservePaths=!!t.preservePaths,this.unlink=!!t.unlink,this.cwd=mn(B.resolve(t.cwd||process.cwd())),this.strip=Number(t.strip)||0,this.processUmask=this.chmod?"number"==typeof t.processUmask?t.processUmask:process.umask():0,this.umask="number"==typeof t.umask?t.umask:this.processUmask,this.dmode=t.dmode||511&~this.umask,this.fmode=t.fmode||438&~this.umask,this.on("entry",(t=>this[ji](t)))}warn(t,e,r={}){return("TAR_BAD_ARCHIVE"===t||"TAR_ABORT"===t)&&(r.recoverable=!1),super.warn(t,e,r)}[ea](){this[ta]&&0===this[Vi]&&(this.emit("prefinish"),this.emit("finish"),this.emit("end"))}[zi](t,e){let r=t[e],{type:n}=t;if(!r||this.preservePaths)return!0;let[s,i]=is(r),a=i.replaceAll(/\\/g,"/").split("/");if(a.includes("..")||oa&&/^[a-z]:\.\.$/i.test(a[0]??"")){if("path"===e||"Link"===n)return this.warn("TAR_ENTRY_ERROR",`${e} contains '..'`,{entry:t,[e]:r}),!1;let s=B.posix.dirname(t.path),i=B.posix.normalize(B.posix.join(s,a.join("/")));if(i.startsWith("../")||".."===i)return this.warn("TAR_ENTRY_ERROR",`${e} escapes extraction directory`,{entry:t,[e]:r}),!1}return s&&(t[e]=String(i),this.warn("TAR_ENTRY_INFO",`stripping ${s} from absolute ${e}`,{entry:t,[e]:r})),!0}[Hi](t){let e=mn(t.path),r=e.split("/");if(this.strip){if(r.length<this.strip)return!1;if("Link"===t.type){let e=mn(String(t.linkpath)).split("/");if(!(e.length>=this.strip))return!1;t.linkpath=e.slice(this.strip).join("/")}r.splice(0,this.strip),t.path=r.join("/")}if(isFinite(this.maxDepth)&&r.length>this.maxDepth)return this.warn("TAR_ENTRY_ERROR","path excessively deep",{entry:t,path:e,depth:r.length,maxDepth:this.maxDepth}),!1;if(!this[zi](t,"path")||!this[zi](t,"linkpath"))return!1;if(t.absolute=B.isAbsolute(t.path)?mn(B.resolve(t.path)):mn(B.resolve(this.cwd,t.path)),!this.preservePaths&&"string"==typeof t.absolute&&0!==t.absolute.indexOf(this.cwd+"/")&&t.absolute!==this.cwd)return this.warn("TAR_ENTRY_ERROR","path escaped extraction target",{entry:t,path:mn(t.path),resolvedPath:t.absolute,cwd:this.cwd}),!1;if(t.absolute===this.cwd&&"Directory"!==t.type&&"GNUDumpDir"!==t.type)return!1;if(this.win32){let{root:e}=B.win32.parse(String(t.absolute));t.absolute=e+ls(String(t.absolute).slice(e.length));let{root:r}=B.win32.parse(t.path);t.path=r+ls(t.path.slice(r.length))}return!0}[ji](t){if(!this[Hi](t))return t.resume();switch(Wt.equal(typeof t.absolute,"string"),t.type){case"Directory":case"GNUDumpDir":t.mode&&(t.mode=448|t.mode);case"File":case"OldFile":case"ContiguousFile":case"Link":case"SymbolicLink":return this[Di](t);default:return this[Ki](t)}}[Yi](t,e){"CwdError"===t.name?this.emit("error",t):(this.warn("TAR_ENTRY_ERROR",t,{entry:e}),this[Zi](),e.resume())}[Wi](t,e,r){((t,e,r)=>{t=mn(t);let n=e.umask??18,s=448|e.mode,i=!!(s&n),a=e.uid,o=e.gid,c="number"==typeof a&&"number"==typeof o&&(a!==e.processUid||o!==e.processGid),u=e.preserve,l=e.unlink,d=mn(e.cwd),m=(e,n)=>{e?r(e):n&&c?Ei(n,a,o,(t=>m(t))):i?Ft.chmod(t,s,r):r()};if(t===d)return((t,e)=>{Ft.stat(t,((r,n)=>{(r||!n.isDirectory())&&(r=new Bi(t,r?.code||"ENOTDIR")),e(r)}))})(t,m);if(u)return yt.mkdir(t,{mode:s,recursive:!0}).then((t=>m(null,t??void 0)),m);let p=mn(B.relative(d,t)).split("/");Pi(d,p,s,l,d,void 0,m)})(mn(t),{uid:this.uid,gid:this.gid,processUid:this.processUid,processGid:this.processGid,umask:this.processUmask,preserve:this.preservePaths,unlink:this.unlink,cwd:this.cwd,mode:e},r)}[na](t){return this.forceChown||this.preserveOwner&&("number"==typeof t.uid&&t.uid!==this.processUid||"number"==typeof t.gid&&t.gid!==this.processGid)||"number"==typeof this.uid&&this.uid!==this.processUid||"number"==typeof this.gid&&this.gid!==this.processGid}[sa](t){return ca(this.uid,t.uid,this.processUid)}[ia](t){return ca(this.gid,t.gid,this.processGid)}[Mi](t,e){let r="number"==typeof t.mode?4095&t.mode:this.fmode,n=new fr(String(t.absolute),{flags:_i(t.size),mode:r,autoClose:!1});n.on("error",(r=>{n.fd&&Ft.close(n.fd,(()=>{})),n.write=()=>!0,this[Yi](r,t),e()}));let s=1,i=r=>{if(r)return n.fd&&Ft.close(n.fd,(()=>{})),this[Yi](r,t),void e();0==--s&&void 0!==n.fd&&Ft.close(n.fd,(r=>{r?this[Yi](r,t):this[Zi](),e()}))};n.on("finish",(()=>{let e=String(t.absolute),r=n.fd;if("number"==typeof r&&t.mtime&&!this.noMtime){s++;let n=t.atime||new Date,a=t.mtime;Ft.futimes(r,n,a,(t=>t?Ft.utimes(e,n,a,(e=>i(e&&t))):i()))}if("number"==typeof r&&this[na](t)){s++;let n=this[sa](t),a=this[ia](t);"number"==typeof n&&"number"==typeof a&&Ft.fchown(r,n,a,(t=>t?Ft.chown(e,n,a,(e=>i(e&&t))):i()))}i()}));let a=this.transform&&this.transform(t)||t;a!==t&&(a.on("error",(r=>{this[Yi](r,t),e()})),t.pipe(a)),a.pipe(n)}[Ui](t,e){let r="number"==typeof t.mode?4095&t.mode:this.dmode;this[Wi](String(t.absolute),r,(r=>{if(r)return this[Yi](r,t),void e();let n=1,s=()=>{0==--n&&(e(),this[Zi](),t.resume())};t.mtime&&!this.noMtime&&(n++,Ft.utimes(String(t.absolute),t.atime||new Date,t.mtime,s)),this[na](t)&&(n++,Ft.chown(String(t.absolute),Number(this[sa](t)),Number(this[ia](t)),s)),s()}))}[Ki](t){t.unsupported=!0,this.warn("TAR_ENTRY_UNSUPPORTED",`unsupported entry type: ${t.type}`,{entry:t}),t.resume()}[Fi](t,e){let r=mn(B.relative(this.cwd,B.resolve(B.dirname(String(t.absolute)),String(t.linkpath)))).split("/");this[Gi](t,this.cwd,r,(()=>this[Li](t,String(t.linkpath),"symlink",e)),(r=>{this[Yi](r,t),e()}))}[$i](t,e){let r=mn(B.resolve(this.cwd,String(t.linkpath))),n=mn(String(t.linkpath)).split("/");this[Gi](t,this.cwd,n,(()=>this[Li](t,r,"link",e)),(r=>{this[Yi](r,t),e()}))}[Gi](t,e,r,n,s){let i=r.shift();if(this.preservePaths||void 0===i)return n();let a=B.resolve(e,i);Ft.lstat(a,((e,i)=>e?n():i?.isSymbolicLink()?s(new ki(a,B.resolve(a,r.join("/")))):void this[Gi](t,a,r,n,s)))}[Xi](){this[Vi]++}[Zi](){this[Vi]--,this[ea]()}[ra](t){this[Zi](),t.resume()}[Ni](t,e){return"File"===t.type&&!this.unlink&&e.isFile()&&e.nlink<=1&&!oa}[Di](t){this[Xi]();let e=[t.path];t.linkpath&&e.push(t.linkpath),this.reservations.reserve(e,(e=>this[Qi](t,e)))}[Qi](t,e){let r=t=>{e(t)},n=()=>{if(t.absolute!==this.cwd){let e=mn(B.dirname(String(t.absolute)));if(e!==this.cwd)return this[Wi](e,this.dmode,(e=>{if(e)return this[Yi](e,t),void r();s()}))}s()},s=()=>{Ft.lstat(String(t.absolute),((e,n)=>{if(n&&(this.keep||this.newer&&n.mtime>(t.mtime??n.mtime)))return this[ra](t),void r();if(e||this[Ni](t,n))return this[Oi](null,t,r);if(n.isDirectory()){if("Directory"===t.type){let e=e=>this[Oi](e??null,t,r);return this.chmod&&t.mode&&(4095&n.mode)!==t.mode?Ft.chmod(String(t.absolute),Number(t.mode),e):e()}if(t.absolute!==this.cwd)return Ft.rmdir(String(t.absolute),(e=>this[Oi](e??null,t,r)))}if(t.absolute===this.cwd)return this[Oi](null,t,r);((t,e)=>{if(!oa)return Ft.unlink(t,e);let r=t+".DELETE."+(0,I.randomBytes)(16).toString("hex");Ft.rename(t,r,(t=>{if(t)return e(t);Ft.unlink(r,e)}))})(String(t.absolute),(e=>this[Oi](e??null,t,r)))}))};this[aa]?n():(()=>{this[Wi](this.cwd,this.dmode,(e=>{if(e)return this[Yi](e,t),void r();this[aa]=!0,n()}))})()}[Oi](t,e,r){if(t)return this[Yi](t,e),void r();switch(e.type){case"File":case"OldFile":case"ContiguousFile":return this[Mi](e,r);case"Link":return this[$i](e,r);case"SymbolicLink":return this[Fi](e,r);case"Directory":case"GNUDumpDir":return this[Ui](e,r)}}[Li](t,e,r,n){Ft[r](e,String(t.absolute),(e=>{e?this[Yi](e,t):(this[Zi](),t.resume()),n()}))}},la=t=>{try{return[null,t()]}catch(t){return[t,null]}},da=class extends ua{sync=!0;[Oi](t,e){return super[Oi](t,e,(()=>{}))}[Di](t){if(!this[aa]){let e=this[Wi](this.cwd,this.dmode);if(e)return this[Yi](e,t);this[aa]=!0}if(t.absolute!==this.cwd){let e=mn(B.dirname(String(t.absolute)));if(e!==this.cwd){let r=this[Wi](e,this.dmode);if(r)return this[Yi](r,t)}}let[e,r]=la((()=>Ft.lstatSync(String(t.absolute))));if(r&&(this.keep||this.newer&&r.mtime>(t.mtime??r.mtime)))return this[ra](t);if(e||this[Ni](t,r))return this[Oi](null,t);if(r.isDirectory()){if("Directory"===t.type){let e=this.chmod&&t.mode&&(4095&r.mode)!==t.mode,[n]=e?la((()=>{Ft.chmodSync(String(t.absolute),Number(t.mode))})):[];return this[Oi](n,t)}let[e]=la((()=>Ft.rmdirSync(String(t.absolute))));this[Oi](e,t)}let[n]=t.absolute===this.cwd?[]:la((()=>(t=>{if(!oa)return Ft.unlinkSync(t);let e=t+".DELETE."+(0,I.randomBytes)(16).toString("hex");Ft.renameSync(t,e),Ft.unlinkSync(e)})(String(t.absolute))));this[Oi](n,t)}[Mi](t,e){let r,n="number"==typeof t.mode?4095&t.mode:this.fmode,s=n=>{let s;try{Ft.closeSync(r)}catch(t){s=t}(n||s)&&this[Yi](n||s,t),e()};try{r=Ft.openSync(String(t.absolute),_i(t.size),n)}catch(t){return s(t)}let i=this.transform&&this.transform(t)||t;i!==t&&(i.on("error",(e=>this[Yi](e,t))),t.pipe(i)),i.on("data",(t=>{try{Ft.writeSync(r,t,0,t.length)}catch(t){s(t)}})),i.on("end",(()=>{let e=null;if(t.mtime&&!this.noMtime){let n=t.atime||new Date,s=t.mtime;try{Ft.futimesSync(r,n,s)}catch(r){try{Ft.utimesSync(String(t.absolute),n,s)}catch{e=r}}}if(this[na](t)){let n=this[sa](t),s=this[ia](t);try{Ft.fchownSync(r,Number(n),Number(s))}catch(r){try{Ft.chownSync(String(t.absolute),Number(n),Number(s))}catch{e=e||r}}}s(e)}))}[Ui](t,e){let r="number"==typeof t.mode?4095&t.mode:this.dmode,n=this[Wi](String(t.absolute),r);if(n)return this[Yi](n,t),void e();if(t.mtime&&!this.noMtime)try{Ft.utimesSync(String(t.absolute),t.atime||new Date,t.mtime)}catch{}if(this[na](t))try{Ft.chownSync(String(t.absolute),Number(this[sa](t)),Number(this[ia](t)))}catch{}e(),t.resume()}[Wi](t,e){try{return((t,e)=>{t=mn(t);let r=e.umask??18,n=448|e.mode,s=!!(n&r),i=e.uid,a=e.gid,o="number"==typeof i&&"number"==typeof a&&(i!==e.processUid||a!==e.processGid),c=e.preserve,u=e.unlink,l=mn(e.cwd),d=e=>{e&&o&&Ii(e,i,a),s&&Ft.chmodSync(t,n)};if(t===l)return(t=>{let e,r=!1;try{r=Ft.statSync(t).isDirectory()}catch(t){e=t?.code}finally{if(!r)throw new Bi(t,e??"ENOTDIR")}})(l),d();if(c)return d(Ft.mkdirSync(t,{mode:n,recursive:!0})??void 0);let m,p=mn(B.relative(l,t)).split("/");for(let t=p.shift(),e=l;t&&(e+="/"+t);t=p.shift()){e=mn(B.resolve(e));try{Ft.mkdirSync(e,n),m=m||e}catch{let t=Ft.lstatSync(e);if(t.isDirectory())continue;if(u){Ft.unlinkSync(e),Ft.mkdirSync(e,n),m=m||e;continue}if(t.isSymbolicLink())return new ki(e,e+"/"+p.join("/"))}}return d(m)})(mn(t),{uid:this.uid,gid:this.gid,processUid:this.processUid,processGid:this.processGid,umask:this.processUmask,preserve:this.preservePaths,unlink:this.unlink,cwd:this.cwd,mode:e})}catch(t){return t}}[Gi](t,e,r,n,s){if(this.preservePaths||0===r.length)return n();let i=e;for(let t of r){i=B.resolve(i,t);let[a,o]=la((()=>Ft.lstatSync(i)));if(a)return n();if(o.isSymbolicLink())return s(new ki(i,B.resolve(e,r.join("/"))))}n()}[Li](t,e,r,n){let s=`${r}Sync`;try{Ft[s](e,String(t.absolute)),n(),t.resume()}catch(e){return this[Yi](e,t)}}},ma=yr((t=>{let e=new da(t),r=t.file,n=Ft.statSync(r),s=t.maxReadSize||16777216;new pr(r,{readSize:s,size:n.size}).pipe(e)}),((t,e)=>{let r=new ua(t),n=t.maxReadSize||16777216,s=t.file;return new Promise(((t,e)=>{r.on("error",e),r.on("close",t),Ft.stat(s,((t,i)=>{if(t)e(t);else{let t=new mr(s,{readSize:n,size:i.size});t.on("error",e),t.pipe(r)}}))}))}),(t=>new da(t)),(t=>new ua(t)),((t,e)=>{e?.length&&ts(t,e)})),pa=(t,e)=>{e.forEach((e=>{"@"===e.charAt(0)?es({file:B.resolve(t.cwd,e.slice(1)),sync:!0,noResume:!0,onReadEntry:e=>t.add(e)}):t.add(e)})),t.end()},fa=yr(((t,e)=>{let r,n,s=new ui(t),i=!0;try{try{r=Ft.openSync(t.file,"r+")}catch(e){if("ENOENT"!==e?.code)throw e;r=Ft.openSync(t.file,"w+")}let a=Ft.fstatSync(r),o=Buffer.alloc(512);t:for(n=0;n<a.size;n+=512){for(let t=0,e=0;t<512;t+=e){if(e=Ft.readSync(r,o,t,o.length-t,n+t),0===n&&31===o[0]&&139===o[1])throw new Error("cannot append to compressed archives");if(!e)break t}let e=new Kr(o);if(!e.cksumValid)break;let s=512*Math.ceil((e.size||0)/512);if(n+s+512>a.size)break;n+=s,t.mtimeCache&&e.mtime&&t.mtimeCache.set(String(e.path),e.mtime)}i=!1,((t,e,r,n,s)=>{let i=new hr(t.file,{fd:n,start:r});e.pipe(i),pa(e,s)})(t,s,n,r,e)}finally{if(i)try{Ft.closeSync(r)}catch{}}}),((t,e)=>{e=Array.from(e);let r=new ci(t);return new Promise(((n,s)=>{r.on("error",s);let i="r+",a=(o,c)=>o&&"ENOENT"===o.code&&"r+"===i?(i="w+",Ft.open(t.file,i,a)):o||!c?s(o):void Ft.fstat(c,((i,a)=>{if(i)return Ft.close(c,(()=>s(i)));((e,r,n)=>{let s=(t,r)=>{t?Ft.close(e,(e=>n(t))):n(null,r)},i=0;if(0===r)return s(null,0);let a=0,o=Buffer.alloc(512),c=(n,u)=>{if(n||void 0===u)return s(n);if(a+=u,a<512&&u)return Ft.read(e,o,a,o.length-a,i+a,c);if(0===i&&31===o[0]&&139===o[1])return s(new Error("cannot append to compressed archives"));if(a<512)return s(null,i);let l=new Kr(o);if(!l.cksumValid)return s(null,i);let d=512*Math.ceil((l.size??0)/512);if(i+d+512>r||(i+=d+512,i>=r))return s(null,i);t.mtimeCache&&l.mtime&&t.mtimeCache.set(String(l.path),l.mtime),a=0,Ft.read(e,o,0,512,i,c)};Ft.read(e,o,0,512,i,c)})(c,a.size,((i,a)=>{if(i)return s(i);let o=new fr(t.file,{fd:c,start:a});r.pipe(o),o.on("error",s),o.on("close",n),(async(t,e)=>{for(let r of e)"@"===r.charAt(0)?await es({file:B.resolve(String(t.cwd),r.slice(1)),noResume:!0,onReadEntry:e=>t.add(e)}):t.add(r);t.end()})(r,e)}))}));Ft.open(t.file,i,a)}))}),(()=>{throw new TypeError("file is required")}),(()=>{throw new TypeError("file is required")}),((t,e)=>{if(!(t=>!!t.file)(t))throw new TypeError("file is required");if(t.gzip||t.brotli||t.zstd||t.file.endsWith(".br")||t.file.endsWith(".tbr"))throw new TypeError("cannot append to compressed archives");if(!e?.length)throw new TypeError("no paths specified to add/replace")})),ha=(yr(fa.syncFile,fa.asyncFile,fa.syncNoFile,fa.asyncNoFile,((t,e=[])=>{fa.validate?.(t,e),ha(t)})),t=>{let e=t.filter;t.mtimeCache||(t.mtimeCache=new Map),t.filter=e?(r,n)=>e(r,n)&&!((t.mtimeCache?.get(r)??n.mtime??0)>(n.mtime??0)):(e,r)=>!((t.mtimeCache?.get(e)??r.mtime??0)>(r.mtime??0))});const ga="plugins/cache",Aa=".cache-complete";function ba(t){return t.replace(/[^a-zA-Z0-9_-]/g,"_")}function ya(t){return t.replace(/[^a-zA-Z0-9_-]/g,"_")}function _a(t){return(0,Nt.Nz)(t)}function wa(t,e){return function(t,e,r,n){const s=[t,e,r];return void 0!==n&&s.push(n),(0,B.join)(...s)}(t,ba(e.marketplaceSlug),ya(e.pluginId),void 0!==e.version?_a(e.version):void 0)}class Ca{constructor(t,e){const r=t??process.env.HOME??"";this.cacheRoot=e?.cacheRoot??(0,B.join)(r,".cursor",ga)}getCacheDir(t){return wa(this.cacheRoot,t)}async isCached(t){const e=this.getCacheDir(t);try{const t=(0,B.join)(e,Aa);return(await(0,yt.stat)(t)).isFile()}catch{return!1}}async extractToCache(t){const e=this.getCacheDir(t);await(0,yt.mkdir)(e,{recursive:!0});const r=jt.Readable.from(t.tarball);return await(0,Dt.pipeline)(r,(0,Qt.createGunzip)(),ma({cwd:e,strip:1})),await this.markCacheComplete(t),e}async listCachedVersions(t){const e=ba(t.marketplaceSlug),r=ya(t.pluginId),n=(0,B.join)(this.cacheRoot,e,r);try{return(await(0,yt.readdir)(n,{withFileTypes:!0})).filter((t=>t.isDirectory())).map((t=>t.name))}catch{return[]}}async removeVersion(t){const e=this.getCacheDir(t);try{await(0,yt.rm)(e,{recursive:!0,force:!0})}catch{}}async removeAllVersions(t){const e=wa(this.cacheRoot,t);await(0,yt.rm)(e,{recursive:!0,force:!0})}async pruneOldVersions(t){const e=await this.listCachedVersions({marketplaceSlug:t.marketplaceSlug,pluginId:t.pluginId}),r=new Set(t.keepVersions.map((t=>_a(t))));for(const n of e)r.has(n)||await this.removeVersion({marketplaceSlug:t.marketplaceSlug,pluginId:t.pluginId,version:n})}async markCacheComplete(t){const e=this.getCacheDir(t);await(0,yt.writeFile)((0,B.join)(e,Aa),"")}}var va=r("node:os");class Ea{constructor(t){this.filePath=function(t){return(0,B.join)(t??(0,va.homedir)(),".cursor","plugins","local-marketplaces.json")}(t)}async read(){try{const t=await(0,yt.readFile)(this.filePath,"utf-8"),e=JSON.parse(t);return Array.isArray(e.marketplaces)?{marketplaces:e.marketplaces}:{marketplaces:[]}}catch{return{marketplaces:[]}}}async write(t){await(0,yt.mkdir)((0,B.dirname)(this.filePath),{recursive:!0}),await(0,yt.writeFile)(this.filePath,`${JSON.stringify({version:1,marketplaces:t},null,2)}\n`,"utf-8")}async list(){return(await this.read()).marketplaces}async upsert(t){const{marketplaces:e}=await this.read(),r=e.findIndex((e=>e.name===t.name));if(r>=0){const n=e[r],s=new Map((n?.plugins??[]).map((t=>[t.name,t.enabled??!1])));e[r]={...t,plugins:t.plugins.map((t=>({...t,enabled:s.get(t.name)??t.enabled??!1})))}}else e.push(t);await this.write(e)}async setPluginEnabled(t,e,r){const{marketplaces:n}=await this.read(),s=n.find((e=>e.name===t)),i=s?.plugins.find((t=>t.name===e));return!!i&&(i.enabled=r,await this.write(n),!0)}async remove(t){const{marketplaces:e}=await this.read(),r=e.filter((e=>e.name!==t));return r.length!==e.length&&(await this.write(r),!0)}}var Sa=r("node:util");function Ia(t,e){const r=t.releaseTag??e;if(t.releaseRepo&&t.releaseAsset&&r)return{kind:"release",releaseRepo:t.releaseRepo,releaseAsset:t.releaseAsset,releaseTag:r}}function Ba(t){return"release"===(e=function(t,e={}){const r=Ia(t);return void 0!==r?r:{kind:"git",gitUrl:t.gitUrl,gitPath:t.gitPath,resolvedCommitSha:e.resolvedCommitSha??t.resolvedCommitSha,gitRef:t.gitRef}}(t)).kind?`release/${e.releaseTag}`:e.resolvedCommitSha;var e}var ka=r("../git-core/dist/git-exec.js");function Pa(t){return"function"==typeof t?t():t}async function xa(t,e){const r=function(t){const e={...process.env,GIT_TERMINAL_PROMPT:"0",GIT_ASKPASS:void 0,VSCODE_GIT_ASKPASS_NODE:void 0,VSCODE_GIT_ASKPASS_MAIN:void 0,VSCODE_GIT_ASKPASS_EXTRA_ARGS:void 0,GCM_INTERACTIVE:"Never"};if(e.GIT_CONFIG_NOSYSTEM=void 0,!0===t?.sshBatchMode){const t=process.env.GIT_SSH_COMMAND?.trim()||"ssh";e.GIT_SSH_COMMAND=`${t} -oBatchMode=yes`}if(void 0!==t?.extraGitConfig){const r=Object.entries(t.extraGitConfig).flatMap((([t,e])=>Array.isArray(e)?e.map((e=>[t,e])):[[t,e]]));e.GIT_CONFIG_COUNT=String(r.length);for(const[t,[n,s]]of r.entries())e[`GIT_CONFIG_KEY_${t}`]=n,e[`GIT_CONFIG_VALUE_${t}`]=s}return{cwd:t?.cwd,env:e}}({cwd:e?.cwd,sshBatchMode:e?.sshBatchMode,extraGitConfig:e?.extraGitConfig});return(0,ka.uM)("git",["-c","credential.interactive=false","-c","core.fsmonitor=false",...t],{...r,...void 0!==e?.timeoutMs&&{timeout:e.timeoutMs,killSignal:"SIGTERM"}})}const Ra=/^[0-9a-f]{7,40}$/i,Ja=/^[0-9a-f]{40}$/i;function Ta(t){for(const e of t.split(/\r?\n/)){const[t,r]=e.split("\t");if(!t?.startsWith("ref: ")||"HEAD"!==r)continue;const n=t.slice(5).trim();return n.startsWith("refs/heads/")?n.slice(11):n}}function qa(t){if(void 0===t||""===t)return;const e=t.split(/\r?\n/).map((t=>{const[e,r]=t.split("\t");if(e&&r&&/^[0-9a-f]{40}$/i.test(e))return{sha:e,refName:r}})).filter((t=>void 0!==t));return 0!==e.length?e.find((t=>t.refName.endsWith("^{}")))?.sha??e[0].sha:void 0}async function ja(t,e,r){const n=e.trim();if(Ja.test(n))return{fullSha:n.toLowerCase()};if(Ra.test(n)){try{const e=await async function(t,e,r){const{stdout:n}=await xa(["ls-remote",t,`refs/heads/${e}`,`refs/tags/${e}`,`refs/tags/${e}^{}`],{sshBatchMode:r?.sshBatchMode,extraGitConfig:r?.extraGitConfig,timeoutMs:r?.timeoutMs});return qa(n)?.toLowerCase()}(t,n,r);if(e)return{fullSha:e}}catch{}return{fullSha:n.toLowerCase()}}let s;try{if("HEAD"===n.toUpperCase()){const e=await xa(["ls-remote","--symref",t,"HEAD"],{sshBatchMode:r?.sshBatchMode,extraGitConfig:r?.extraGitConfig,timeoutMs:r?.timeoutMs}),n=qa(e.stdout);if(!n)throw new Error(`git ls-remote did not return a resolvable commit for HEAD (${t})`);return{fullSha:n.toLowerCase(),headSymrefStdout:e.stdout}}s=(await xa(["ls-remote",t,n],{sshBatchMode:r?.sshBatchMode,extraGitConfig:r?.extraGitConfig,timeoutMs:r?.timeoutMs})).stdout}catch(e){const r=e instanceof Error?e.message:String(e),s=new Error(`Failed to resolve git ref "${n}" for ${t}: ${r}`);throw s.cause=e,s}const i=qa(s);if(!i)throw new Error(`git ls-remote did not return a resolvable commit for ref "${n}" (${t})`);return{fullSha:i.toLowerCase()}}const Da=N.map((t=>t.split("/")[0]));let Qa;function Na(t){let e=t.trim().replaceAll("\\","/");for(;e.startsWith("./");)e=e.slice(2);return e=e.replace(/\/+$/,""),""===e||"."===e||e.startsWith("/")||/^[a-zA-Z]:/.test(e)||e.split("/").some((t=>""===t||"."===t||".."===t))?null:e}function Oa(t){const e=[];for(const r of t){const t=Na(r);if(null===t)return"all";e.push(t)}return e}async function Ma(t,e){const r="all"===t?"all":Oa(t),n=e&&"all"!==r&&await(process.env.CURSOR_DISABLE_SPARSE_PLUGIN_CLONES?Promise.resolve(!1):(Qa??=(async()=>{try{const{stdout:t}=await xa(["--version"]),e=function(t){const e=/git version (\d+)\.(\d+)/.exec(t);return e?{major:Number(e[1]),minor:Number(e[2])}:null}(t);return null!==e&&(e.major>2||2===e.major&&e.minor>=28)}catch{return!1}})(),Qa));return{materialize:r,sparse:n,sparseDirs:n?(s=r,[...new Set([...Da,...s])]):[]};var s}function Ua(t){return t.toLowerCase().includes("filtering not recognized by server")}async function La(t,e,r){await xa(["sparse-checkout","set","--cone","--",...e],{...r,cwd:t})}async function Fa(t){try{await(0,yt.access)((0,B.join)(t,".git","info","sparse-checkout"))}catch{return!1}try{const{stdout:e}=await xa(["config","--bool","--get","core.sparseCheckout"],{cwd:t});return"true"===e.trim()}catch{return!1}}async function $a(t,e,r){if("all"!==e&&0===e.length)return;if(!await Fa(t))return;const n={...r,cwd:t,sshBatchMode:!0};if("all"===e)return void await xa(["sparse-checkout","disable"],n);const s=Oa(e);"all"!==s?await xa(["sparse-checkout","add","--",...s],n):await xa(["sparse-checkout","disable"],n)}const Ga=/\.git$/i,Ka=new Set(["account","dashboard"]);function Ha(t){return t.replace(Ga,"")}function za(t){let e;try{e=decodeURIComponent(t)}catch{return}return e.length>0&&!e.includes("/")?e:void 0}function Wa(t){const e=t.toLowerCase();return"github.com"===e||e.endsWith(".github.com")}function Ya(t){return t.toLowerCase().split(".").includes("gitlab")}function Va(t){const e=t.toLowerCase();return"bitbucket.org"===e||"www.bitbucket.org"===e}function Xa(t){const e=t.findIndex((t=>"_git"===t.toLowerCase()));if(e<1||e>2)return;const r=t[0],n=t[e+1];if(!r||!n)return;const s=Ha(n);if(!s)return;const i=2===e?t[1]:s;return i?{organization:r,project:i,repo:s,hasSubpath:t.length>e+2}:void 0}var Za=r("../utils/dist/repo-url.js");function to(t){const e=t.toLowerCase();return Ya(t)?"GitLab":e.includes("bitbucket")?"Bitbucket":e.includes("gitea")||e.includes("codeberg")?"Gitea/Codeberg":e.includes("azure")&&e.includes("dev")?"Azure DevOps":null}function eo(t){return Wa(t)?"github":Ya(t)?"gitlab":Va(t)?"bitbucket":function(t){const e=t.toLowerCase();return"dev.azure.com"===e||"www.dev.azure.com"===e}(t)?"azure_devops":"generic"}function ro(t){let e;try{const r=t.startsWith("git@")?`ssh://${t.replace(":","/")}`:t;e=new URL(r.includes("://")?r:`https://${r}`)}catch{return null}const r=e.hostname;let n=e.pathname.split("/").filter(Boolean);(0,Za.ve)(r)&&"git"===n[0]?.toLowerCase()&&(n=n.slice(1)),n.length>=3&&"scm"===n[0].toLowerCase()&&(n=n.slice(1));const s=function(t){const e=t[0],r=t[1];if(!e||!r)return;const n=Ha(r);return n?{owner:e,repo:n,hasSubpath:t.length>2}:void 0}(n);return void 0===s?null:{provider:eo(r),owner:s.owner,repo:s.repo,host:r}}function no(t){const e=io(t);if(null===e)return!1;const r=e.pathname.split("/").filter(Boolean);return r.length>=3&&"scm"===r[0].toLowerCase()}function so(t){const e=t.trim();if(""===e)return{error:"URL cannot be empty"};const r=ro(e);if(null===r)return{error:"Invalid URL format. Expected: github.com/owner/repo or https://github.example.com/owner/repo"};const n=to(r.host);if(null!==n)return{error:`Only GitHub URLs are currently supported. ${n} is not supported yet.`};const s=po(r.host.replace(/^www\./i,""));return{url:`https://${s}/${no(e)?"scm/":""}${r.owner}/${r.repo}`,owner:r.owner,repo:r.repo,host:s}}function io(t){try{const e=t.startsWith("git@")?`ssh://${t.replace(":","/")}`:t;return new URL(e.includes("://")?e:`https://${e}`)}catch{return null}}function ao(t){const e=io(t.trim());if(null!==e&&Va(e.hostname))return function(t){const e=t[0],r=t[1];if(void 0===e||void 0===r)return;const n=za(e),s=za(r);if(void 0===n||void 0===s||Ka.has(n.toLowerCase()))return;const i=Ha(s);return i?{workspace:encodeURIComponent(n),repo:encodeURIComponent(i),hasSubpath:t.length>2}:void 0}(function(t){const e=t.pathname.split("/");return""===e[0]&&e.shift(),""===e[e.length-1]&&e.pop(),e}(e))}function oo(t){const e=io(t.trim());return null!==e&&void 0!==Xa(e.pathname.split("/").filter(Boolean))}function co(t){const e=t.trim();if(""===e)return{error:"URL cannot be empty"};const r=ro(e);if(null===r)return{error:"Invalid URL format. Expected: github.com/owner/repo or gitlab.com/namespace/repo"};if(Ya(r.host)){const t=io(e),r=null===t?void 0:function(t){const e=t.indexOf("-"),r=-1!==e,n=r?t.slice(0,e):[...t];if(n.length<2||n.some((t=>0===t.length)))return;const s=Ha(n[n.length-1]);return s?(n[n.length-1]=s,{repositorySegments:n,hasSpecialRouteSeparator:r}):void 0}(t.pathname.split("/").filter(Boolean));if(null===t||void 0===r)return{error:"Invalid GitLab repository URL format. Expected: https://gitlab.com/namespace/repo"};const n=t.host.replace(/^www\./i,"");return{url:`https://${n}/${r.repositorySegments.join("/")}`,owner:r.repositorySegments[0],repo:r.repositorySegments[r.repositorySegments.length-1],host:n,provider:"gitlab"}}if("bitbucket"===r.provider){const t=ao(e);if(void 0===t)return{error:"Invalid Bitbucket repository URL format. Expected: https://bitbucket.org/{workspace}/{repo}"};const n=r.host.replace(/^www\./i,"");return{url:`https://${n}/${t.workspace}/${t.repo}`,owner:t.workspace,repo:t.repo,host:n,provider:"bitbucket"}}if("azure_devops"===r.provider){const t=io(e),n=null===t?void 0:Xa(t.pathname.split("/").filter(Boolean));if(null===t||void 0===n)return{error:"Invalid Azure DevOps repository URL format. Expected: https://dev.azure.com/{organization}/{project}/_git/{repo}"};const s=r.host.replace(/^www\./i,"");return{url:`https://${s}/${n.organization}/${n.project}/_git/${n.repo}`,owner:n.organization,repo:n.repo,host:s,provider:"azure_devops",project:n.project}}if(uo(r)){const t=po(r.host.replace(/^www\./i,""));return{url:`https://${t}/${no(e)?"scm/":""}${r.owner}/${r.repo}`,owner:r.owner,repo:r.repo,host:t,provider:"github"}}const n=to(r.host);return{error:"Only GitHub, GitLab, Bitbucket, and Azure DevOps URLs are currently supported."+(null!==n?` ${n} is not supported yet.`:"")}}function uo(t){switch(t.provider){case"github":return!0;case"generic":return!(0,Za.ve)(t.host)&&null===to(t.host);case"gitlab":case"bitbucket":case"azure_devops":return!1;default:return t.provider,!1}}function lo(t){const e=co(t);if("error"in e)return null;switch(e.provider){case"github":return`git@${e.host}:${e.owner}/${e.repo}.git`;case"gitlab":return function(t){let e;try{e=new URL(t.url).pathname.replace(/^\//,"").replace(/\.git$/i,"")}catch{return null}if(0===e.length)return null;return`git@${t.host.replace(/:\d+$/,"")}:${e}.git`}(e);case"bitbucket":case"azure_devops":return null;default:return e.provider,null}}function mo(t){const e=t.trim();if(!e)return!1;try{const t=ro(e);return null!==t&&function(t,e){return"azure_devops"===t.provider?oo(e):"bitbucket"===t.provider?void 0!==ao(e):uo(t)||"gitlab"===t.provider}(t,e)}catch{if(e.startsWith("git@")||e.endsWith(".git"))return!0;const t=ro(e);return null!==t&&("azure_devops"===t.provider?oo(e):Wa(t.host)||"gitlab"===t.provider||"bitbucket"===t.provider)}}function po(t){return Wa(t)?"github.com":t}function fo(t){return!t.operatingSystems||0===t.operatingSystems.length||t.operatingSystems.includes(function(){const t=(0,va.platform)();return"win32"===t?"Windows":"darwin"===t?"Macintosh":"Linux"}())}function ho(t){return/[\n\r:#[\]{}&*!|>'"%@`]/.test(t)||t.startsWith(" ")||t.endsWith(" ")?`"${t.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`:t}var go=r("../utils/dist/promise-extras.js");function Ao(t,e){const r=(0,B.resolve)(t),n=(0,B.resolve)(t,e),s=(0,B.relative)(r,n);if(s.startsWith("..")||(0,B.isAbsolute)(s))throw new Error(`Invalid subPath: path traversal not allowed (${JSON.stringify(e)})`);return n}function bo(){return(0,B.join)((0,va.homedir)(),".cursor","plugins","marketplaces")}const yo=new Set(["con","prn","aux","nul","com1","com2","com3","com4","com5","com6","com7","com8","com9","lpt1","lpt2","lpt3","lpt4","lpt5","lpt6","lpt7","lpt8","lpt9"]);function _o(t){const e=(0,Nt.Nz)(t).replace(/[. ]+$/g,"");return""===e||"."===e||".."===e?"_":yo.has(e.toLowerCase())?`_${e}`:e}const wo=18e5,Co=6e5,vo={recursive:!0,force:!0,maxRetries:3},Eo=["terminal prompts disabled","could not read username","host key verification failed","could not read from remote repository","permission denied","repository not found","user cancelled dialog","spawn git enoent","authentication failed","unable to get password from user"],So=["enotempty: directory not empty, rename","/_staging/"],Io=["upload-pack: not our ref","server does not allow request for unadvertised object"];function Bo(t){const e=String(t).toLowerCase().replaceAll("\\","/");return Eo.some((t=>e.includes(t)))?"user_git_access":So.every((t=>e.includes(t)))?"local_cache_race":Io.some((t=>e.includes(t)))?"stale_pinned_ref":"infrastructure"}function ko(t){return"object"==typeof t&&null!==t&&(!0===t.killed||ko(t.cause))}function Po(t){return ko(t)?"killed_by_budget":Bo(t)}function xo(t){const e=co(t);if(!("error"in e)&&"gitlab"===e.provider){let r;try{r=new URL(e.url).pathname.replace(/^\//,"")}catch{throw new Error(`Invalid git URL: ${t}`)}const n=r.split("/").filter(Boolean).map((t=>t.toLowerCase()));if(n.length<2)throw new Error(`Invalid git URL: ${t}`);return{host:e.host.toLowerCase(),pathSegments:n}}const r=ro(t);if(null===r)throw new Error(`Invalid git URL: ${t}`);return{host:po(r.host.replace(/^www\./i,"")).toLowerCase(),pathSegments:[r.owner.toLowerCase(),r.repo.toLowerCase()]}}const Ro=new Map;class Jo{constructor(t,e){this.cacheRoot=t,this.options=e,this.manifestCache=new Map}get sparsePluginClones(){return this.options?.sparsePluginClones??!1}remoteTimeoutMs(){return this.sparsePluginClones?wo:void 0}localTimeoutMs(){return this.sparsePluginClones?Co:void 0}lsRemoteTimeoutMs(){return this.sparsePluginClones?3e4:void 0}async cloneResolvedRef(t,e,r,n){const s={cwd:t,sshBatchMode:n?.sshBatchMode,extraGitConfig:{...Pa(this.options?.extraGitConfig),"safe.directory":t}},{sparse:i,sparseDirs:a}=await Ma(n?.materialize??"all",this.sparsePluginClones);await xa(["init"],{...s,timeoutMs:this.localTimeoutMs()}),i&&await La(t,a,{sshBatchMode:n?.sshBatchMode,extraGitConfig:Pa(this.options?.extraGitConfig),timeoutMs:this.localTimeoutMs()});const{stderr:o}=await xa(["fetch","--depth","1",...i?["--filter=blob:none"]:[],e,r],{...s,timeoutMs:this.remoteTimeoutMs()});return await xa(["checkout","FETCH_HEAD"],{...s,timeoutMs:this.remoteTimeoutMs()}),{strategy:i?"sparse":"full",filterIgnoredByServer:i&&Ua(o??"")}}async createStagingDir(){const t=(0,B.join)(this.cacheRoot,"_staging",(0,I.randomUUID)());return await(0,yt.mkdir)(t,{recursive:!0}),t}async moveToCanonicalDir(t,e){return await(0,yt.mkdir)((0,B.dirname)(e),{recursive:!0}),await(0,yt.rm)(e,vo),await(0,yt.rename)(t,e),e}async cleanStaleStagingDirs(){const t=(0,B.join)(this.cacheRoot,"_staging");try{const e=await(0,yt.readdir)(t,{withFileTypes:!0}),r=Date.now();await Promise.all(e.filter((t=>t.isDirectory())).map((async e=>{try{const n=(0,B.join)(t,e.name),s=await(0,yt.stat)(n);r-s.mtimeMs>Jo.STALE_STAGING_THRESHOLD_MS&&await(0,yt.rm)(n,vo)}catch{}})))}catch{}}getLegacyCloneDir(t,e){return(0,B.join)(this.cacheRoot,_o(t),_o(e))}getCanonicalCloneDir(t,e){const{host:r,pathSegments:n}=xo(t);return(0,B.join)(this.cacheRoot,_o(r),...n.map(_o),_o(e))}getCanonicalRepoRootDir(t){const{host:e,pathSegments:r}=xo(t);return(0,B.join)(this.cacheRoot,_o(e),...r.map(_o))}async pruneSiblingCloneDirs(t,e,r){const n=this.getCanonicalRepoRootDir(t),s=_o(e);try{const t=await(0,yt.readdir)(n,{withFileTypes:!0});await Promise.all(t.filter((t=>t.isDirectory()&&t.name!==s)).map((t=>(0,yt.rm)((0,B.join)(n,t.name),vo))))}catch{}if(void 0!==r)try{await(0,yt.rm)(r,vo)}catch{}}async ensureCloned(t,e,r,n=i,s){const a=this.serializedOnRepo(this.getCanonicalRepoRootDir(e),(()=>this.ensureClonedImpl(t,e,r,n,s?.materialize??"all")));return this.sparsePluginClones?a:(0,go.wj)(a,3e4,`ensureCloned timed out after 30000ms for ${e} @ ${r}`)}async ensureMaterialized(t,e,r=i){const n=this.serializedOnRepo((0,B.dirname)(t),(async()=>{const n=performance.now();try{await $a(t,e,{extraGitConfig:Pa(this.options?.extraGitConfig),timeoutMs:this.remoteTimeoutMs()}),r.increment("marketplace_cache_manager.ensure_materialized.success",1),r.distribution("marketplace_cache_manager.ensure_materialized.duration",performance.now()-n)}catch(s){throw r.log("error","Failed to materialize plugin directories in sparse marketplace clone",{clonePath:t,spec:"all"===e?"all":e.join(","),error:String(s),errorCategory:Po(s)}),r.increment("marketplace_cache_manager.ensure_materialized.error",1,{error_category:Po(s)}),r.distribution("marketplace_cache_manager.ensure_materialized.duration",performance.now()-n,{outcome:"error"}),s}}));return this.sparsePluginClones?n:(0,go.wj)(n,3e4,`ensureMaterialized timed out after 30000ms for ${t}`)}async serializedOnRepo(t,e){const r=`${this.cacheRoot}:${t}`,n=(Ro.get(r)??Promise.resolve()).catch((()=>{})).then(e);Ro.set(r,n);try{return await n}finally{Ro.get(r)===n&&Ro.delete(r)}}async ensureClonedImpl(t,e,r,n,s){n.log("info",`MarketplaceCacheManager: Ensuring cloned ${t} at ${e}@${r}`,{marketplaceId:t,gitUrl:e,ref:r});const i=r.trim();let a,o=e.startsWith("git@")||e.startsWith("ssh://")?null:lo(e);if(null!==o)try{a=(await ja(o,i,{sshBatchMode:!0,extraGitConfig:Pa(this.options?.extraGitConfig),timeoutMs:this.lsRemoteTimeoutMs()})).fullSha}catch(t){if(this.sparsePluginClones&&ko(t))throw t;n.log("debug","Failed to resolve remote ref using SSH URL, falling back to HTTPS",{gitUrl:e,ref:r,error:String(t),errorCategory:Bo(t)}),o=null,a=(await ja(e,i,{extraGitConfig:Pa(this.options?.extraGitConfig),timeoutMs:this.lsRemoteTimeoutMs()})).fullSha}else a=(await ja(e,i,{extraGitConfig:Pa(this.options?.extraGitConfig),timeoutMs:this.lsRemoteTimeoutMs()})).fullSha;const c=this.getCanonicalCloneDir(e,a),u=this.getLegacyCloneDir(t,i);n.log("info",`MarketplaceCacheManager: Resolved clone directory for ${t} at ${e}@${r} to ${c}`,{marketplaceId:t,resolvedRef:a,originalRef:i});const l=performance.now(),d=(t,e)=>{n.increment(`marketplace_cache_manager.ensure_cloned.${t}`,1,e),n.distribution(`marketplace_cache_manager.ensure_cloned.${t}.duration`,performance.now()-l,e)};if(await this.isCloneComplete(c)){await this.pruneSiblingCloneDirs(e,a,u);const t=await Fa(c);return t&&await $a(c,s,{extraGitConfig:Pa(this.options?.extraGitConfig),timeoutMs:this.remoteTimeoutMs()}),d("cache_hit",{strategy:t?"sparse":"full"}),c}return n.increment("marketplace_cache_manager.ensure_cloned.cache_miss",1),this.cloneViaStaging(c,e,o,a,u,r,n,d,s)}async cloneViaStaging(t,e,r,n,s,i,a,o,c){await this.cleanStaleStagingDirs();const u=await this.createStagingDir();a.log("info",`MarketplaceCacheManager: Cloning ${e}@${i} into staging directory: ${u}`,{gitUrl:e,ref:i,cloneDir:t});const l=this.sparsePluginClones?setInterval((()=>{const t=new Date;(0,yt.utimes)(u,t,t).catch((()=>{}))}),Jo.STAGING_HEARTBEAT_INTERVAL_MS):void 0;l?.unref?.();try{let l;if(null!==r)try{l=await this.cloneResolvedRef(u,r,n,{sshBatchMode:!0,materialize:c})}catch(t){if(this.sparsePluginClones&&ko(t))throw t;a.log("debug","Falling back to HTTPS clone due to SSH clone failure",{gitUrl:e,ref:i,error:String(t),errorCategory:Po(t)}),await(0,yt.rm)(u,vo),await(0,yt.mkdir)(u,{recursive:!0}),l=await this.cloneResolvedRef(u,e,n,{materialize:c})}else l=await this.cloneResolvedRef(u,e,n,{materialize:c});l.filterIgnoredByServer&&(a.log("warn","Server ignored --filter=blob:none; sparse clone downloaded a full pack",{gitUrl:e,ref:i}),a.increment("marketplace_cache_manager.ensure_cloned.filter_ignored_by_server",1));const d=await this.moveToCanonicalDir(u,t);return await this.pruneSiblingCloneDirs(e,n,s),o("cache_write_success",{strategy:l.strategy}),d}catch(t){const r=Po(t);throw o("error",{error_category:r}),a.log("error","Failed to clone marketplace repository via staging clone",{gitUrl:e,ref:i,error:String(t),errorCategory:r}),a.captureException(t,{error_type:"clone_marketplace_repository",error_category:r}),t}finally{void 0!==l&&clearInterval(l);try{await(0,yt.rm)(u,vo)}catch{}}}async isCloneComplete(t){try{if(!(await(0,yt.stat)(t)).isDirectory())return!1;const e=await(0,yt.readdir)(t);if(!e.includes(".git"))return!1;if(e.length>1)return!0;try{return(await(0,yt.stat)((0,B.join)(t,".git","info","sparse-checkout"))).isFile()}catch{return!1}}catch{return!1}}getPluginDir(t,e){return Ao(t,e)}async copyPluginToDir(t,e){await(0,yt.mkdir)(e,{recursive:!0}),await(0,yt.cp)(t,e,{recursive:!0,verbatimSymlinks:!0})}async readManifest(t,e={}){const r=function(t,e){return JSON.stringify({clonePath:t,repoName:e.repoName??null,fallbackId:e.fallbackId??null})}(t,e);if(this.manifestCache.has(r))return this.manifestCache.get(r)??null;const n=await To(t,e);return this.manifestCache.set(r,n),n}async resolvePluginPath(t,e){const r=await this.readManifest(t);if(!r)return null;const n=r.plugins.find((t=>t.name===e.toLowerCase()));if(!n)return null;const s=ft(n.source,r.metadata?.pluginRoot);return s&&gt(s)?s:null}async discoverPlugins(t){const e=await this.readManifest(t);return e?function(t){const e=[],r=function(t,e){const r=[];for(const n of t){const t=n.source;if("string"!=typeof t)switch(t.source){case"github":r.push({entry:n,kind:"external-github",externalUrl:`https://github.com/${t.repo}.git`,externalRef:t.ref,externalSha:t.sha,effectiveRef:t.sha??t.ref});break;case"url":r.push({entry:n,kind:"external-url",externalUrl:t.url,externalRef:t.ref,externalSha:t.sha,effectiveRef:t.sha??t.ref});break;case"git-subdir":r.push({entry:n,kind:"external-git-subdir",externalUrl:t.url,externalRef:t.ref,externalSha:t.sha,effectiveRef:t.sha??t.ref,subdirPath:t.path})}else{const s=ft(t,e);null!==s?r.push({entry:n,kind:"local",localPath:s}):r.push({entry:n,kind:"unresolvable",rawSource:t})}}return r}(t.plugins,t.metadata?.pluginRoot);for(const t of r){const{name:r,displayName:n,description:s,version:i}=t.entry,a={name:r,displayName:n,description:s,version:i};switch(t.kind){case"local":gt(t.localPath)&&e.push({...a,sourceType:"local",gitPath:t.localPath});break;case"external-github":e.push({...a,sourceType:"github",gitUrl:t.externalUrl,gitRef:t.externalRef,sha:t.externalSha});break;case"external-url":e.push({...a,sourceType:"url",gitUrl:t.externalUrl,gitRef:t.externalRef,sha:t.externalSha});break;case"external-git-subdir":e.push({...a,sourceType:"git-subdir",gitUrl:t.externalUrl,gitRef:t.externalRef,sha:t.externalSha,subdirPath:t.subdirPath})}}return e}(e):[]}}async function To(t,e={}){for(const r of N){const n=(0,B.join)(t,r);let s;try{s=await(0,yt.readFile)(n,"utf-8")}catch{continue}const i=mt(s,e);if(i.success)return i.data}return null}Jo.STALE_STAGING_THRESHOLD_MS=3e5,Jo.STAGING_HEARTBEAT_INTERVAL_MS=6e4;const qo=(0,Sa.debuglog)("cursor-plugins");function jo(t){const e=t.plugins;if(!Array.isArray(e)||0===e.length)return t;const r=e.map((t=>{const e=t.configuredVariables;if(null==e)return t;if("object"==typeof e){const r=e;if("function"==typeof r.toJson){let e;try{e=r.toJson()}catch{return t}return{...t,configuredVariables:null===e||"object"!=typeof e||Array.isArray(e)?void 0:e}}}return t}));return{...t,plugins:r}}function Do(t){const e=t.name?.trim();return void 0!==e&&e.length>0?e:t.pluginId}function Qo(t,e){return void 0!==t?.marketplace?t.marketplace:void 0!==t?.marketplaceId?(e??[]).find((e=>void 0!==e.id&&String(e.id)===String(t.marketplaceId))):void 0}function No(t,e){const r=e?.distributionGitUrl?.trim();return r?e?.gitUrl&&!Wo(t,e.gitUrl)?t:r:t}function Oo(t){return t?.distributionGitUrl?.trim()||t?.gitUrl}function Mo(t,e){if(t.pinnedGitRef)return t.pinnedGitRef;if(t.plugin?.gitRef)return t.plugin.gitRef;const r=Qo(t.plugin,e),n=t.plugin?.gitUrl,s=r?.gitUrl;return n&&s&&n!==s||!r?.gitRef?"main":r.gitRef}const Uo="backend-git://";function Lo(t,e,r){const n=r?`#${encodeURIComponent(r)}`:"";return`${Uo}${encodeURIComponent(t)}@${encodeURIComponent(e)}${n}`}function Fo(t){if(!t.startsWith(Uo))return null;const e=t.slice(14),r=e.indexOf("#"),n=r>=0?e.slice(0,r):e,s=r>=0?e.slice(r+1):void 0,i=n.lastIndexOf("@");return i<0?null:{gitUrl:decodeURIComponent(n.slice(0,i)),ref:decodeURIComponent(n.slice(i+1)),gitPath:s?decodeURIComponent(s):void 0}}const $o="backend-release://";function Go(t){const e=t.tag?`@${encodeURIComponent(t.tag)}`:"";return`${$o}${encodeURIComponent(t.repo)}#${encodeURIComponent(t.asset)}${e}`}function Ko(t){if(!t.startsWith($o))return null;const e=t.slice(18),r=e.indexOf("#");if(r<0)return null;const n=decodeURIComponent(e.slice(0,r)),s=e.slice(r+1),i=s.lastIndexOf("@");return{repo:n,asset:i>=0?decodeURIComponent(s.slice(0,i)):decodeURIComponent(s),tag:i>=0?decodeURIComponent(s.slice(i+1)):void 0}}const Ho=/^[0-9a-f]{7,40}$/i;function zo(t){let e;try{e=xo(t)}catch{return null}return`${e.host}\0${e.pathSegments.join("\0")}`}function Wo(t,e){if(t.trim()===e.trim())return!0;const r=zo(t),n=zo(e);return null!==r&&r===n}const Yo=104857600;async function Vo(t,e,r,n,s,i){const a=await async function(t){const{repo:e,asset:r,tag:n}=t,{apiBase:s,ownerRepo:i,host:a}=function(t){const e=t.split("/");if(3===e.length)return{apiBase:`https://${e[0]}/api/v3`,ownerRepo:`${e[1]}/${e[2]}`,host:e[0]};if(2===e.length)return{apiBase:"https://api.github.com",ownerRepo:t,host:"github.com"};throw new Error(`Invalid release repo format: ${t}`)}(e),o="github.com"===a&&void 0!==t.githubToken&&t.githubToken.length>0?{Authorization:`token ${t.githubToken}`}:{},c=n?`${s}/repos/${i}/releases/tags/${encodeURIComponent(n)}`:`${s}/repos/${i}/releases/latest`,u=await fetch(c,{headers:{Accept:"application/vnd.github.v3+json","User-Agent":"CursorPluginInstaller",...o}});if(!u.ok)throw new Error(`Failed to fetch release from ${c}: ${u.status} ${u.statusText}`);const l=await u.json(),d=l.assets.find((t=>t.name===r));if(!d){const t=l.assets.map((t=>t.name)).join(", ");throw new Error(`Release asset "${r}" not found. Available assets: ${t}`)}if(d.size>Yo)throw new Error(`Release asset "${r}" exceeds maximum size of 104857600 bytes (actual: ${d.size})`);const m=new URL(d.browser_download_url);if("https:"!==m.protocol||!Xo(m.hostname,a))throw new Error(`Refusing to download release asset from untrusted host: ${m.hostname}`);const p=await fetch(d.browser_download_url,{headers:{"User-Agent":"CursorPluginInstaller",Accept:"application/octet-stream",...o}});if(!p.ok)throw new Error(`Failed to download release asset: ${p.status} ${p.statusText}`);if(p.url){const t=new URL(p.url);if("https:"!==t.protocol||!Xo(t.hostname,a))throw new Error(`Refusing to download release asset: redirected to untrusted host: ${t.hostname}`)}const f=Buffer.from(await p.arrayBuffer());if(f.byteLength>Yo)throw new Error(`Release asset "${r}" actual download size exceeds maximum of 104857600 bytes (actual: ${f.byteLength})`);if(t.expectedSha256){const e=(0,I.createHash)("sha256").update(f).digest("hex");if(e!==t.expectedSha256)throw new Error(`Release asset "${r}" integrity check failed: expected SHA-256 ${t.expectedSha256}, got ${e}`)}return f}({repo:t,asset:e,tag:r,expectedSha256:s,githubToken:i}),o=a.byteLength;await(0,yt.mkdir)(n,{recursive:!0});const c=await(0,yt.mkdtemp)((0,B.join)((0,va.tmpdir)(),"release-asset-")),u=(0,B.join)(c,"asset.tar.gz"),l=(0,B.join)(c,"extracted");try{await(0,yt.writeFile)(u,a),await(0,yt.mkdir)(l,{recursive:!0});let t=0,e=0;await ma({file:u,cwd:l,onReadEntry:r=>{if(e++,e>5e4)throw new Error("Release archive contains too many files (>50000).");if(t+=r.size,t>524288e3)throw new Error("Release archive uncompressed size exceeds maximum of 524288000 bytes.");if(o>0&&t/o>100)throw new Error("Release archive has suspicious compression ratio (>100x).")}});const r=await(0,yt.readdir)(l,{withFileTypes:!0}),s=r.filter((t=>t.isDirectory())),i=r.filter((t=>t.isFile()));let c=l;if(1===s.length&&0===i.length){const t=(0,B.join)(l,s[0].name);(await(0,yt.readdir)(t)).some((t=>Q.includes(t)))&&(c=t)}const d=await(0,yt.readdir)(c);await Promise.all(d.map((t=>(0,yt.cp)((0,B.join)(c,t),(0,B.join)(n,t),{recursive:!0,verbatimSymlinks:!0}))))}finally{await(0,yt.rm)(c,{recursive:!0,force:!0}).catch((()=>{}))}}function Xo(t,e){return!(t!==e&&!t.endsWith(".githubusercontent.com"))||("github.com"===e?"github.com"===t:t.endsWith(`.${e}`))}class Zo{constructor(t,e,r,n,s){this.getEffectiveUserPlugins=t;const a="string"==typeof e||void 0===e?{marketplaceCacheRoot:e,pluginLogger:r,marketplaceCacheOptions:n,listOptions:s}:e,o=a.marketplaceCacheOptions??n;this.pluginLogger=a.pluginLogger??r??i,this.extraGitConfig=a.extraGitConfig,this.awaitAuthReady=a.awaitAuthReady,this.githubToken=a.githubToken,this.sparsePluginClones=a.sparsePluginClones??!1,this.marketplaceCache=a.marketplaceCacheRoot?new Jo(a.marketplaceCacheRoot,{...o,extraGitConfig:o?.extraGitConfig??a.extraGitConfig,sparsePluginClones:this.sparsePluginClones}):void 0;const c=a.listOptions??s;this.allowedMarketplaceNames=c?.allowedMarketplaceNames?new Set(c.allowedMarketplaceNames):void 0,this.enableInlinePlugins=c?.enableInlinePlugins??!1}isMarketplaceAllowed(t){return void 0===this.allowedMarketplaceNames||void 0!==t?.name&&this.allowedMarketplaceNames.has(t.name)}async listEnabledPlugins(t,e){const r=await this.getEffectiveUserPlugins(),n=r.plugins??[],s=r.marketplaces??[],i=[],a=[],o=new Map,c=async(t,e)=>{const r=`${t}\0${e}`;let n=o.get(r);if(!n){const s=Pa(this.extraGitConfig),i=this.sparsePluginClones?3e4:void 0,a=t.startsWith("git@")||t.startsWith("ssh://")?null:lo(t),c=async(t,r)=>{const n={};return r&&(n.sshBatchMode=!0),void 0!==s&&(n.extraGitConfig=s),void 0!==i&&(n.timeoutMs=i),(Object.keys(n).length>0?await ja(t,e,n):await ja(t,e)).fullSha};if(null!==a)try{n=await c(a,!0)}catch(e){if(this.sparsePluginClones&&ko(e))throw e;n=await c(t,!1)}else n=await c(t,!1);o.set(r,n)}return n},u=async t=>{const{preferredGitUrl:e,sourceGitUrl:r,gitRef:n,pluginId:s}=t;if(e!==r){void 0!==this.awaitAuthReady&&await this.awaitAuthReady();const t=`${e}\0${n}`,i=!o.has(t);let a;i&&this.pluginLogger.increment("marketplace.origin_distribution.fetch",1);try{a={sha:await c(e,n),gitUrl:e}}catch(t){i&&this.pluginLogger.increment("marketplace.origin_distribution.fetch.error",1),this.pluginLogger.captureException(t,{error_type:"distribution_url_fallback"}),this.pluginLogger.log("warn",`Distribution mirror ${e}@${n} unavailable (not synced yet or unreachable); falling back to source ${r}`,{pluginId:s,preferredGitUrl:e,sourceGitUrl:r,gitRef:n,error:String(t)})}if(void 0!==a){if(i)try{this.pluginLogger.log("info",`Resolved plugin ${s} from Origin distribution mirror ${e}@${n}`,{pluginId:s,preferredGitUrl:e,gitRef:n})}catch{}return a}}return{sha:await c(r,n),gitUrl:r}};for(const t of n){if(!t.isEnabled||!t.plugin?.name)continue;const e=t.plugin,r=Qo(e,s);if(!this.isMarketplaceAllowed(r)){this.pluginLogger.log("info",`Skipping plugin ${e.name} because marketplace ${r?.name??"<none>"} is not allowed`,{pluginId:e.name,marketplaceName:r?.name,allowedMarketplaceNames:void 0!==this.allowedMarketplaceNames?Array.from(this.allowedMarketplaceNames):void 0});continue}const n=Do({name:e.name,pluginId:void 0!==e.id?String(e.id):e.name??""}),o=n;if(!e.gitUrl){if(!this.enableInlinePlugins){this.pluginLogger.log("info",`Skipping plugin ${n} without gitUrl (enableInlinePlugins=false)`,{pluginId:o});continue}const s=t.inlineContentJson;if(!s){this.pluginLogger.log("info",`Skipping DB-inline plugin ${n}: no inline content provided`,{pluginId:o});continue}const a=(0,I.createHash)("sha256").update(`${e.id??"0"}:${e.updatedAt??"0"}`).digest("hex").slice(0,40),c=r?.name?{id:void 0!==r.id?`${r.name}-${r.id}`:`${r.name}-inline`,name:r.name}:void 0;this.pluginLogger.log("info",`BackendMarketplaceClient: Adding DB-inline plugin: ${o}`,{pluginId:o,marketplaceId:c?.id??"unknown",version:a}),i.push({pluginId:o,pluginDbId:void 0!==e.id?String(e.id):void 0,configuredVariables:t.configuredVariables,isTeamRequired:t.isTeamRequired,name:n,version:a,downloadUrl:`inline://${e.id??o}`,marketplaceDbId:void 0!==r?.id?String(r.id):void 0,marketplace:c,inlineContentJson:s});continue}const c=e.gitUrl,l=No(c,r),d=Mo(t,s),m=Ia(e,d),p=r?.gitRef??d;let f,h,g=l;try{if(void 0!==m)f=`release/${m.releaseTag}`;else{const t=await u({preferredGitUrl:l,sourceGitUrl:c,gitRef:d,pluginId:o});f=t.sha,g=t.gitUrl}}catch(t){this.pluginLogger.captureException(t,{error_type:"resolve_version_sha"}),this.pluginLogger.log("error",`Failed to resolve version for plugin ${n}@${d}, skipping plugin`,{pluginId:o,ref:d,error:String(t)});const s=t instanceof Error?t.message:String(t);a.push({pluginName:n,pluginId:o,pluginDbId:void 0!==e.id?String(e.id):void 0,marketplaceName:r?.name,errorMessage:s,errorType:/timed?\s*out/i.test(s)?"timeout":"clone"});continue}h=void 0!==m?Go({repo:m.releaseRepo,asset:m.releaseAsset,tag:m.releaseTag}):Lo(g,d,e.gitPath??void 0);const A=Oo(r);let b=A,y=r?.gitUrl,_=p;if(r?.gitUrl&&A){const t=Wo(c,r.gitUrl),e=t?g:A,s=t?c:r.gitUrl,i=t?d:p;y=s;try{const t=await u({preferredGitUrl:e,sourceGitUrl:s,gitRef:i,pluginId:o});_=t.sha,b=t.gitUrl}catch(t){this.pluginLogger.captureException(t,{error_type:"resolve_marketplace_cache_ref"}),this.pluginLogger.log("warn",`Failed to resolve marketplace cache ref for plugin ${n} from ${e}@${i}, falling back to raw ref`,{pluginId:o,cacheRepoUrl:e,cacheRef:i,error:String(t)}),b=s}}const w=r?.name?{id:void 0!==r.id?`${r.name}-${r.id}`:`${r.name}-${encodeURIComponent(r.gitUrl??"project")}`,name:r.name,...b&&{gitUrl:b,gitRef:_}}:void 0,C=void 0!==m||g===c&&b===y?void 0:{downloadUrl:Lo(c,d,e.gitPath??void 0),marketplaceGitUrl:y};this.pluginLogger.log("info",`BackendMarketplaceClient: Adding enabled plugin: ${o} from ${_} at ${e.gitPath}`,{pluginId:o,marketplaceId:w?.id??"unknown",gitPath:e.gitPath??void 0,gitRef:_}),i.push({pluginId:o,pluginDbId:void 0!==e.id?String(e.id):void 0,configuredVariables:t.configuredVariables,isTeamRequired:t.isTeamRequired,name:n,version:f,downloadUrl:h,marketplaceDbId:void 0!==r?.id?String(r.id):void 0,marketplace:w,gitPath:e.gitPath??void 0,isOriginBacked:void 0===m&&g!==c||void 0,originSourceFallback:C})}return{plugins:i,listFailures:a}}isDirectInstallSameFetch(t){const e=t.marketplace;if(!e?.gitUrl||!e.gitRef)return!1;const r=Fo(t.downloadUrl);return!(!r||!Wo(r.gitUrl,e.gitUrl)||r.ref!==e.gitRef&&t.version!==e.gitRef)}async installPlugin(t,e){if(t.inlineContentJson)await async function(t){const{targetDir:e,inlineContentJson:r,pluginName:n}=t,s=JSON.parse(r);await(0,yt.mkdir)(e,{recursive:!0});const i={};if(s.rules&&s.rules.length>0){const t=(0,B.join)(e,"rules");await(0,yt.mkdir)(t,{recursive:!0});const r=[];for(const e of s.rules){if(!e.content)continue;if(!1===e.isActive)continue;const n=`${(0,Nt.Nz)(e.name)}.md`,s=[];s.push(`description: ${ho(e.name)}`),e.globs&&e.globs.length>0&&s.push(`globs: ${ho(e.globs.join(", "))}`),s.push(`alwaysApply: ${!0===e.isRequired}`);const i=`---\n${s.join("\n")}\n---\n\n`;await(0,yt.writeFile)((0,B.join)(t,n),i+e.content,"utf-8"),r.push(`rules/${n}`)}r.length>0&&(i.rules=r)}if(s.commands&&s.commands.length>0){const t=(0,B.join)(e,"commands");await(0,yt.mkdir)(t,{recursive:!0});const r=[];for(const e of s.commands){if(!e.content)continue;if(!1===e.isActive)continue;const n=`${(0,Nt.Nz)(e.name)}.md`,s=e.description?`---\ndescription: ${ho(e.description)}\n---\n\n`:"";await(0,yt.writeFile)((0,B.join)(t,n),s+e.content,"utf-8"),r.push(`commands/${n}`)}r.length>0&&(i.commands=r)}if(s.hooks&&s.hooks.length>0){const t=(0,B.join)(e,"hooks");await(0,yt.mkdir)(t,{recursive:!0});const r={};for(const t of s.hooks){const e=t.hookStep;e&&!1!==t.isActive&&fo(t)&&(r[e]||(r[e]=[]),"prompt"===t.hookType?r[e].push({type:"prompt",prompt:t.promptContent??"",...t.promptModel?{model:t.promptModel}:{}}):r[e].push({type:"command",command:t.scriptContent??""}))}await(0,yt.writeFile)((0,B.join)(t,"hooks.json"),JSON.stringify({version:1,hooks:r},null,2),"utf-8")}if(s.mcpServers&&s.mcpServers.length>0){const t={};for(const e of s.mcpServers)e.config&&(t[e.name]=e.config);Object.keys(t).length>0&&await(0,yt.writeFile)((0,B.join)(e,".mcp.json"),JSON.stringify({mcpServers:t},null,2),"utf-8")}const a={name:n,...i},o=(0,B.join)(e,".cursor-plugin");await(0,yt.mkdir)(o,{recursive:!0}),await(0,yt.writeFile)((0,B.join)(o,"plugin.json"),JSON.stringify(a,null,2),"utf-8")}({targetDir:e,inlineContentJson:t.inlineContentJson,pluginName:t.name});else{t.isOriginBacked&&void 0!==this.awaitAuthReady&&await this.awaitAuthReady();try{return void await this.installFromEntryUrls(t,e)}catch(r){const n=function(t){const e=t.originSourceFallback;if(void 0===e)return;let r=t.marketplace;if(void 0!==r)if(void 0!==e.marketplaceGitUrl)r={...r,gitUrl:e.marketplaceGitUrl};else{const{gitUrl:t,gitRef:e,...n}=r;r=n}return{...t,downloadUrl:e.downloadUrl,marketplace:r,isOriginBacked:void 0,originSourceFallback:void 0}}(t);if(void 0===n)throw r;this.pluginLogger.captureException(r,{error_type:"install_plugin_from_origin_distribution"}),this.pluginLogger.log("warn",`Failed to install plugin ${t.name} from the Origin distribution mirror, falling back to the source repo`,{pluginId:t.pluginId,version:t.version,sourceDownloadUrl:n.downloadUrl,sourceMarketplaceGitUrl:n.marketplace?.gitUrl,error:String(r)}),this.pluginLogger.increment("marketplace.origin_distribution.install.source_fallback",1),await(0,yt.rm)(e,{recursive:!0,force:!0});try{await this.installFromEntryUrls(n,e)}catch(t){throw this.pluginLogger.increment("marketplace.origin_distribution.install.source_fallback.error",1),t}}}}async installFromEntryUrls(t,e){if(null===Ko(t.downloadUrl))try{if(await this.tryInstallFromMarketplaceCache(t,e))return void this.emitOriginLoadIfApplicable(t)}catch(e){if(this.pluginLogger.captureException(e,{error_type:"install_plugin_from_marketplace_cache"}),this.sparsePluginClones&&this.isDirectInstallSameFetch(t)&&ko(e))throw this.pluginLogger.log("warn",`Failed to install plugin ${t.name} from marketplace cache; skipping direct install fallback because it would repeat the identical fetch`,{pluginId:t.pluginId,version:t.version,error:String(e)}),e;this.pluginLogger.log("warn",`Failed to install plugin ${t.name} from marketplace cache, falling back to direct install`,{pluginId:t.pluginId,version:t.version,error:String(e)})}await async function(t,e,r=i,n,s){const a=s?.sparsePluginClones??!1,o=a?wo:void 0,c=Ko(t.downloadUrl);if(c){if(t.gitPath){const r=await(0,yt.mkdtemp)((0,B.join)((0,va.tmpdir)(),"release-plugin-"));try{await Vo(c.repo,c.asset,c.tag,r,s?.expectedReleaseAssetSha256,s?.githubToken);const n=Ao(r,t.gitPath);await(0,yt.mkdir)(e,{recursive:!0}),await(0,yt.cp)(n,e,{recursive:!0,verbatimSymlinks:!0})}finally{await(0,yt.rm)(r,{recursive:!0,force:!0}).catch((()=>{}))}}else await Vo(c.repo,c.asset,c.tag,e,s?.expectedReleaseAssetSha256,s?.githubToken);return}const u=Fo(t.downloadUrl);if(!u)throw new Error(`Invalid download URL format for plugin ${t.pluginId}: ${t.downloadUrl}`);const l=await(0,yt.mkdtemp)((0,B.join)((0,va.tmpdir)(),"backend-plugin-"));try{let s;if(await async function(t,e,r,n=i,s,a="all",o=!1){const c=performance.now(),u=Ho.test(e),l="HEAD"===e.toUpperCase(),d={...s,"safe.directory":r},m=o?wo:void 0,p=o?Co:void 0,{sparse:f,sparseDirs:h}=await Ma(a,o),g=f?["--filter=blob:none","--sparse"]:[],A=!!f||void 0,b=async t=>{f&&await La(r,h,{extraGitConfig:d,timeoutMs:t,sshBatchMode:!0})},y=async(t,n)=>{let s="";return l?(({stderr:s}=await xa(["clone","--depth","1",...g,t,r],{extraGitConfig:d,timeoutMs:m,sshBatchMode:n})),await b(m)):u?(await xa(["init"],{cwd:r,extraGitConfig:d,timeoutMs:p}),await xa(["remote","add","origin",t],{cwd:r,extraGitConfig:d,timeoutMs:p}),await b(p),({stderr:s}=await xa(["fetch","--depth","1",...f?["--filter=blob:none"]:[],"origin",e],{cwd:r,extraGitConfig:d,timeoutMs:m,sshBatchMode:n})),await xa(["checkout","FETCH_HEAD"],{cwd:r,extraGitConfig:d,timeoutMs:m,sshBatchMode:n})):(({stderr:s}=await xa(["clone","--depth","1","--branch",e,...g,t,r],{extraGitConfig:d,timeoutMs:m,sshBatchMode:n})),await b(m)),s},_=t.startsWith("git@")||t.startsWith("ssh://")?null:lo(t);let w="";if(null!==_)try{w=await y(_,!0)}catch(e){if(o&&ko(e))throw e;await(0,yt.rm)(r,{recursive:!0,force:!0}),await(0,yt.mkdir)(r,{recursive:!0}),w=await y(t,A)}else w=await y(t,A);f&&Ua(w)&&(n.log("warn",`shallowClone: server ignored --filter=blob:none for ${t}; sparse clone downloaded a full pack`),n.increment("backend_marketplace_client.shallow_clone.filter_ignored_by_server",1));const C=(performance.now()-c).toFixed(1);qo("shallowClone %s@%s completed in %sms",t,e,C),n.log("info",`shallowClone ${t}@${e} completed in ${C}ms (${f?"sparse":"full"})`)}(u.gitUrl,u.ref,l,r,n,u.gitPath?Oa([u.gitPath]):[],a),u.gitPath)s=Ao(l,u.gitPath);else{const e=await async function(t,e){for(const r of N){const n=(0,B.join)(t,r);let s;try{s=await(0,yt.readFile)(n,"utf-8")}catch{continue}const i=mt(s);if(!i.success)return{type:"manifest-unresolved",reason:`Invalid marketplace manifest at ${r}: ${i.error}`};const a=i.data,o=a.plugins.find((t=>t.name===e.toLowerCase()));if(!o)return{type:"manifest-unresolved",reason:`Plugin ${JSON.stringify(e)} not found in ${r}`};if("string"!=typeof o.source&&"git-subdir"===o.source.source)return{type:"manifest-unresolved",reason:`Plugin ${JSON.stringify(e)} uses unsupported git-subdir source`};const c=ft(o.source,a.metadata?.pluginRoot);return c&&gt(c)?{type:"resolved",gitPath:c}:{type:"manifest-unresolved",reason:`Plugin ${JSON.stringify(e)} has unresolved or unsafe source path`}}return{type:"no-manifest"}}(l,t.name);if("resolved"===e.type)await $a(l,Oa([e.gitPath]),{extraGitConfig:n,timeoutMs:o}),s=Ao(l,e.gitPath);else{if("manifest-unresolved"===e.type)throw new Error(`Unable to install plugin ${JSON.stringify(t.name)} without gitPath: ${e.reason}`);await $a(l,"all",{extraGitConfig:n,timeoutMs:o}),s=l}}await(0,yt.mkdir)(e,{recursive:!0}),await(0,yt.cp)(s,e,{recursive:!0,verbatimSymlinks:!0})}finally{await(0,yt.rm)(l,{recursive:!0,force:!0}).catch((()=>{}))}}(t,e,this.pluginLogger,Pa(this.extraGitConfig),{githubToken:this.githubToken,sparsePluginClones:this.sparsePluginClones}),this.emitOriginLoadIfApplicable(t)}emitOriginLoadIfApplicable(t){if(t.isOriginBacked)try{this.pluginLogger.increment("marketplace.origin_distribution.load",1),this.pluginLogger.log("info",`Loaded plugin ${t.pluginId} from Origin distribution (fetch complete)`,{pluginId:t.pluginId})}catch{}}async prewarmMarketplaceClones(t){const e=this.marketplaceCache;if(!e)return;const r=new Map;for(const e of t){const t=e.marketplace;if(!t?.gitUrl)continue;const n=t.gitRef??"main",s=`${t.id}\0${t.gitUrl}\0${n}`;let i=r.get(s);void 0===i&&(i={marketplaceId:t.id,gitUrl:t.gitUrl,gitRef:n,gitPaths:[]},r.set(s,i)),e.gitPath&&i.gitPaths.push(e.gitPath)}for(const t of r.values()){const r=Oa(t.gitPaths),n=performance.now();try{await e.ensureCloned(t.marketplaceId,t.gitUrl,t.gitRef,this.pluginLogger,{materialize:r}),this.pluginLogger.log("info",`Prewarmed marketplace clone ${t.gitUrl}@${t.gitRef} for ${t.gitPaths.length} plugin directories`,{marketplaceId:t.marketplaceId,gitUrl:t.gitUrl,gitRef:t.gitRef,requestedDirs:t.gitPaths.length,materialize:"all"===r?"all":r.length}),this.pluginLogger.increment("marketplace_cache_manager.prewarm.success",1,{materialize:"all"===r?"all":"dirs"})}catch(e){this.pluginLogger.captureException(e,{error_type:"prewarm_marketplace_clone"}),this.pluginLogger.log("warn",`Failed to prewarm marketplace clone ${t.gitUrl}@${t.gitRef}; falling back to per-plugin materialization`,{marketplaceId:t.marketplaceId,gitUrl:t.gitUrl,gitRef:t.gitRef,error:String(e)}),this.pluginLogger.increment("marketplace_cache_manager.prewarm.error",1)}this.pluginLogger.distribution("marketplace_cache_manager.prewarm.duration",performance.now()-n)}}async tryInstallFromMarketplaceCache(t,e){const r=this.marketplaceCache,n=t.marketplace;if(!r||!n||!n.gitUrl)return this.pluginLogger.log("info","No marketplace cache or marketplace metadata, skipping cache check",{pluginId:t.pluginId,name:t.name,version:t.version,marketplaceId:t.marketplace?.id}),!1;const s=await r.ensureCloned(n.id,n.gitUrl,n.gitRef??"main",this.pluginLogger,{materialize:t.gitPath?Oa([t.gitPath]):[]}),i=t.gitPath??await r.resolvePluginPath(s,t.name);if(!i)return this.pluginLogger.log("info","No git path found for plugin, skipping cache check",{pluginId:t.pluginId,name:t.name,version:t.version,marketplaceId:t.marketplace?.id}),!1;void 0===t.gitPath&&await r.ensureMaterialized(s,Oa([i]),this.pluginLogger);const a=r.getPluginDir(s,i);return await r.copyPluginToDir(a,e),!0}async discoverMarketplacePlugins(t,e,r){const n=this.marketplaceCache;if(!n)throw new Error("discoverMarketplacePlugins requires a MarketplaceCacheManager (marketplaceCacheRoot)");const s=await n.ensureCloned(t,e,r,this.pluginLogger,{materialize:[]});return n.discoverPlugins(s)}}function tc(t,e,r,n,s){return new Zo(t,e,r,n,s)}var ec=r("node:url"),rc=r("../hooks/dist/index.js"),nc=r("../utils/dist/gray-matter.js");function sc(t){return t.replace(/\\/g,"/").replace(/\/+$/,"")||"/"}function ic(t,e,r,n){const s=t?.plugins;if(!s||"object"!=typeof s)return[];const i=e?.enabledPlugins??{},a={};r?.enabledPlugins&&Object.assign(a,r.enabledPlugins);const o=void 0!==n?sc(n):void 0,c=new Set,u=[];for(const[t,e]of Object.entries(s)){if(!Array.isArray(e)||0===e.length)continue;if(void 0!==o&&!1===a[t])continue;let r;void 0!==o&&(r=e.find((e=>!("project"!==e.scope&&"local"!==e.scope||!e.projectPath)&&(sc(e.projectPath)===o&&!0===a[t])))),r||!0!==i[t]||(r=e.find((t=>"user"===t.scope))),r?.installPath&&!c.has(t)&&(u.push({pluginId:t,installPath:r.installPath}),c.add(t))}return u}var ac=r("../../../../../../../../../../<build path>");const oc=[".md",".mdc",".markdown"],cc=[...oc,".txt"],uc=/^---\s*\n([\s\S]*?)\n---/;function lc(t){return t.trim().toLowerCase().replace(/\s+/g,"-").replace(/[^a-z0-9.-]/g,"")}function dc(t){const e=t.match(uc);if(!e)return{};try{const t=ac.Ay.load(e[1],{schema:ac.Ay.JSON_SCHEMA});if(!t||"object"!=typeof t)return{};const r=null!==t.metadata&&"object"==typeof t.metadata?t.metadata:void 0,n=mc(t.environments??r?.environments);return{disabledEnvironments:mc(t["disabled-environments"]??r?.disabledEnvironments),environments:n,name:"string"==typeof t.name?t.name:void 0,description:"string"==typeof t.description?t.description:void 0}}catch{const t=e[1],r=t.match(/^name:\s*(.+)$/m),n=t.match(/^description:\s*(.+)$/m);return r||n?{name:r?r[1].trim():void 0,description:n?n[1].trim():void 0}:{}}}function mc(t){if(Array.isArray(t)){const e=t.filter((t=>"string"==typeof t&&t.length>0));return 0===e.length?void 0:e}if("string"==typeof t){const e=t.split(",").map((t=>t.trim())).filter((t=>t.length>0));return 0===e.length?void 0:e}}function pc(t){return lc((0,B.basename)(t).replace(/\.(md|mdc|markdown|txt)$/i,""))}function fc(t){const e=new Set,r=[];for(const n of t)e.has(n.name)||(e.add(n.name),r.push(n));return r}class hc{constructor(t){this.fetcher=t}async discoverComponents(t={}){const e=t.basePath??"",r=e?`${e}/`:"",n=t.manifest;let s;try{s=await this.fetcher.listDirectory(e)}catch{s=[]}const i=new Set(s.filter((t=>"dir"===t.type)).map((t=>t.name.toLowerCase()))),a=St.filter((t=>s.some((e=>"file"===e.type&&e.name===t)))),o=s.some((t=>"file"===t.type&&"SKILL.md"===t.name)),[c,u,l,d,m,p,f]=await Promise.all([o&&void 0===n?.skills?this.discoverRootSkill(r):Promise.resolve(null),void 0!==n?.skills?this.discoverFromManifestPaths(r,n.skills,!0,oc):i.has("skills")?this.discoverSkills(`${r}skills`):Promise.resolve([]),void 0!==n?.agents?this.discoverFromManifestPaths(r,n.agents,!1,oc):i.has("agents")?this.discoverMarkdownComponents(`${r}agents`,oc):Promise.resolve([]),void 0!==n?.hooks?this.discoverHooksFromManifest(r,n.hooks):i.has("hooks")?this.discoverHooksFromJson(`${r}hooks/hooks.json`):Promise.resolve([]),void 0!==n?.commands?this.discoverFromManifestPaths(r,n.commands,!1,cc):i.has("commands")?this.discoverMarkdownComponents(`${r}commands`,cc):Promise.resolve([]),void 0!==n?.rules?this.discoverFromManifestPaths(r,n.rules,!1,oc):i.has("rules")?this.discoverMarkdownComponents(`${r}rules`,oc):Promise.resolve([]),this.discoverMcpServers(r,n?.mcpServers,a)]);return{skills:fc(c?[c,...u]:u),agents:fc(l),hooks:d,commands:fc(m),rules:fc(p),mcpServers:f.servers,mcpVariables:f.variables,mcpConfigs:f.configs}}async discoverHooksFromJson(t){try{if(!await this.fetcher.fileExists(t))return[];const{content:e}=await this.fetcher.fetchFile(t),r=JSON.parse(e);return!r.hooks||"object"!=typeof r.hooks||Array.isArray(r.hooks)?[]:Object.keys(r.hooks).map((e=>({name:lc(e),path:t,description:`Hook: ${e}`})))}catch{return[]}}async discoverHooksFromManifest(t,e){if("string"==typeof e){if(!gt(e))return[];const r=`${t}${e.replace(/^\.\//,"")}`;return r.endsWith(".json")?this.discoverHooksFromJson(r):this.discoverHooksFromJson(`${r}/hooks.json`)}const r=e.hooks??e;return!r||"object"!=typeof r||Array.isArray(r)?[]:Object.keys(r).map((t=>({name:lc(t),path:"manifest",description:`Hook: ${t}`})))}async discoverFromManifestPaths(t,e,r=!1,n=oc){if("string"==typeof e){if(!gt(e))return[];const s=`${t}${e.replace(/^\.\//,"")}`.replace(/\/$/,"");return r?this.discoverSkills(s):this.discoverMarkdownComponents(s,n)}const s=[];for(const n of e)try{if(!gt(n))continue;const e=`${t}${n.replace(/^\.\//,"")}`;if(r){const t=e.endsWith("SKILL.md")?e:`${e.replace(/\/$/,"")}/SKILL.md`;if(!await this.fetcher.fileExists(t)){const t=e.replace(/\/$/,""),r=await this.discoverSkills(t);s.push(...r);continue}let r=pc(e.endsWith("SKILL.md")?e.slice(0,-8).replace(/\/$/,""):e);const{content:n}=await this.fetcher.fetchFile(t),i=dc(n);if(r=i.name??r,r){const e={disabledEnvironments:i.disabledEnvironments,environments:i.environments,name:lc(r),path:t};void 0!==i.description&&(e.description=i.description),s.push(e)}}else{if(!await this.fetcher.fileExists(e))continue;let t=pc(e);const{content:r}=await this.fetcher.fetchFile(e),n=dc(r);t=n.name??t;const i=n.description;if(t){const r={name:lc(t),path:e};void 0!==i&&(r.description=i),s.push(r)}}}catch{}return s}async discoverMarkdownComponents(t,e=oc,r=new Set){let n;try{n=await this.fetcher.listDirectory(t,r)}catch{return[]}const s=n.filter((t=>"file"===t.type&&e.some((e=>t.name.endsWith(e))))),i=n.filter((t=>"dir"===t.type)),[a,o]=await Promise.all([Promise.all(s.map((async t=>{try{let e=pc(t.name);const{content:r}=await this.fetcher.fetchFile(t.path),n=dc(r);e=n.name?lc(n.name):e;const s=n.description;if(!e)return null;const i={name:e,path:t.path};return void 0!==s&&(i.description=s),i}catch{return null}}))),Promise.all(i.map((t=>this.discoverMarkdownComponents(t.path,e,r))))]);return[...a.filter((t=>null!==t)),...o.flat()]}async discoverRootSkill(t){try{const e=`${t}SKILL.md`;let r=lc((0,B.basename)(t.replace(/[\\/]+$/,"")));const{content:n}=await this.fetcher.fetchFile(e),s=dc(n);if(r=s.name?lc(s.name):r,!r)return null;const i={disabledEnvironments:s.disabledEnvironments,environments:s.environments,name:r,path:e};return void 0!==s.description&&(i.description=s.description),i}catch{return null}}async discoverSkills(t){let e;try{e=await this.fetcher.listDirectory(t)}catch{return[]}const r=e.filter((t=>"dir"===t.type));return(await Promise.all(r.map((async t=>{try{const e=`${t.path}/SKILL.md`;if(!await this.fetcher.fileExists(e))return null;const{content:r}=await this.fetcher.fetchFile(e),n=dc(r),s=n.name?lc(n.name):lc(t.name);if(!s)return null;const i={disabledEnvironments:n.disabledEnvironments,environments:n.environments,name:s,path:e};return void 0!==n.description&&(i.description=n.description),i}catch{return null}})))).filter((t=>null!==t))}async discoverMcpServers(t,e,r){const n=new Map,s=async e=>{const r=n.get(e);if(void 0!==r)return r;const s=this.fetcher.fetchFile(`${t}${e}`).then((({content:t})=>t)).catch((()=>null));return n.set(e,s),s},i=async n=>Tt(s,e,void 0!==e?"manifest":void 0,{fallbackFileNames:r,manifestPrecedence:n,toSourcePath:e=>`${t}${e}`,parserOptions:{skipExpansion:!0}}),a=await i("fill");if(void 0===a?.mcpServers)return{servers:[],variables:void 0,configs:void 0};const o=void 0===e?a:await i("override"),c=o?.mcpServers??a.mcpServers,u={};for(const[t,e]of Object.entries(c))u[t]=e;return{servers:Object.keys(a.mcpServers).map((t=>({name:lc(t),path:a.mcpServerSourcePaths?.[t]??"manifest"}))),variables:E(o??a),configs:u}}}function gc(t){const e=t??process.env.HOME??"";return(0,B.join)(e,".claude")}async function Ac(t){const e={enabledPlugins:{}};let r=!1;const n=(0,B.join)(t,".claude","settings.json");try{const t=await(0,yt.readFile)(n,"utf-8"),s=JSON.parse(t);s.enabledPlugins&&(Object.assign(e.enabledPlugins,s.enabledPlugins),r=!0)}catch{}const s=(0,B.join)(t,".claude","settings.local.json");try{const t=await(0,yt.readFile)(s,"utf-8"),n=JSON.parse(t);n.enabledPlugins&&(Object.assign(e.enabledPlugins,n.enabledPlugins),r=!0)}catch{}return r?e:null}async function bc(t){try{return(await(0,yt.lstat)(t)).isSymbolicLink()}catch{return!1}}async function yc(t){if(await bc(t))throw new Error(`Refusing to read symlink: ${t}`);return(0,yt.readFile)(t,"utf-8")}async function _c(t){if((await(0,yt.stat)(t)).size>10485760)throw new Error(`File ${t} exceeds maximum size of 10485760 bytes`)}function wc(t){const e=t instanceof Error?t.message:String(t);return/timed?\s*out/i.test(e)?"timeout":/clone|fetch|git/i.test(e)?"clone":/manifest|marketplace\.json/i.test(e)?"manifest":/parse|invalid|malformed/i.test(e)?"parse":/install|download|copy/i.test(e)?"install":"unknown"}function Cc(t,e){const r=new Map,n=(0,B.resolve)(t),s=(0,B.resolve)(e?.symlinkTargetRoot??n),i=(0,yt.realpath)(s).catch((()=>s));function a(t){const e=(0,B.resolve)(t);try{return Ao(n,e)}catch{throw new Error(`Path escapes plugin directory: ${t}`)}}async function o(t){const e=a(t),r=await i,n=await(0,yt.realpath)(e);try{return Ao(r,n)}catch{throw new Error(`Path escapes plugin directory via symlink: ${t}`)}}return{async listDirectory(e,r){const n=a(e?(0,B.join)(t,e):t);try{const t=await o(n);if(r?.has(t))return[];r?.add(t);const s=await(0,yt.readdir)(t,{withFileTypes:!0}),i=[];for(const t of s){const r=(0,B.join)(n,t.name);let s=t.isDirectory()?"dir":"file";if(t.isSymbolicLink())try{const t=await o(r);s=(await(0,yt.stat)(t)).isDirectory()?"dir":"file"}catch{continue}i.push({name:t.name,type:s,path:e?`${e}/${t.name}`:t.name})}return i}catch{return[]}},async fetchFile(e){const n=r.get(e);if(void 0!==n)return{content:n};const s=a((0,B.join)(t,e)),i=await o(s);await _c(i);const c=await(0,yt.readFile)(i,"utf-8");return r.set(e,c),{content:c}},async fileExists(e){try{const r=a((0,B.join)(t,e)),n=await o(r);return(await(0,yt.stat)(n)).isFile()}catch{return!1}}}}async function vc({installPath:t,logo:e}){const r=e?.trim();if(r&&!(0,B.isAbsolute)(r)&&!r.includes("://"))try{const e=await(0,yt.realpath)(t),n=Ao(e,r),s=await(0,yt.realpath)(n);if(Ao(e,s),!(await(0,yt.stat)(s)).isFile())return;return await _c(s),(0,ec.pathToFileURL)(s).href}catch{return}}function Ec(t){const e={};return void 0!==t.version&&(e.version=t.version),void 0!==t.homepage&&(e.homepage=t.homepage),void 0!==t.repository&&(e.repository=t.repository),e}function Sc(t){return void 0!==t.version||void 0!==t.homepage||void 0!==t.repository}function Ic(t,e){return Ec({version:t.version??e?.version,homepage:t.homepage??e?.homepage,repository:t.repository??e?.repository})}async function Bc(t,e,r){let n;for(const s of D){const i=(0,B.join)(t,s);let a;try{if(await bc(i))continue;if(!(await(0,yt.stat)(i)).isFile())continue;await _c(i),a=await yc(i)}catch{continue}const o=pt(a);if(!o.success)continue;const c=o.data,u=c.commands,l=c.agents,d=c.skills,m=c.rules,p=c.hooks,f=c.mcpServers,h=void 0!==u||void 0!==l||void 0!==d||void 0!==m||void 0!==p||void 0!==f,g="string"==typeof c.displayName?c.displayName:void 0,A="string"==typeof c.description?c.description:void 0,b=c.author?.name,y=await vc({installPath:t,logo:c.logo}),_=Ec(c),w=c.variables,C=c.capabilities,v=void 0!==g||void 0!==A||void 0!==b||void 0!==y||void 0!==w||void 0!==C;if(!h&&!v&&!Sc(_))continue;if(!h&&!v){n=n?{...n,fields:Ic(n.fields,_)}:{fields:_,path:i,relPath:s,unrecognizedSchemaId:o.unrecognizedSchemaId};continue}void 0!==o.unrecognizedSchemaId&&r.log("debug",`${e}: ${s} declares an unrecognized $schema, loading anyway: ${o.unrecognizedSchemaId}`);const E=Ic(_,n?.fields);return{manifestFilePath:i,...h&&{manifestOptions:{commands:u,agents:l,skills:d,rules:m,hooks:p,mcpServers:f}},...(v||Sc(E))&&{metadata:{displayName:g,description:A,authorName:b,logoUrl:y,...E,variables:w,capabilities:C}}}}if(void 0!==n)return void 0!==n.unrecognizedSchemaId&&r.log("debug",`${e}: ${n.relPath} declares an unrecognized $schema, loading anyway: ${n.unrecognizedSchemaId}`),{manifestFilePath:n.path,metadata:n.fields}}function kc(t){return{name:t.name,...t.description?{description:t.description}:{}}}async function Pc(t,e){const r=await async function(t){for(const e of D){const r=(0,B.join)(t,e);try{if(await bc(r))continue;if(!(await(0,yt.stat)(r)).isFile())continue;await _c(r);const t=pt(await yc(r));if(t.success)return t.data}catch{}}}(t)??{},n=void 0===r.commands&&void 0===r.agents&&void 0===r.skills&&void 0===r.rules&&void 0===r.hooks&&void 0===r.mcpServers?void 0:{commands:r.commands,agents:r.agents,skills:r.skills,rules:r.rules,hooks:r.hooks,mcpServers:r.mcpServers},s=new hc(Cc(t,{symlinkTargetRoot:e?.symlinkTargetRoot})),i=await s.discoverComponents({manifest:n});return{manifest:r,skills:i.skills.map(kc),subagents:i.agents.map(kc),hooks:i.hooks.map(kc),rules:i.rules.map(kc),mcpServers:i.mcpServers.map(kc),commands:i.commands.map(kc)}}async function xc(t,e){const r=Cc(t),n=new hc(r),s=await n.discoverComponents({manifest:e}),[i,a,o,c]=await Promise.all([Rc(r,s.skills,t),Tc(r,s.agents,t),qc(r,s.commands,t),Jc(r,s.rules,t)]);return{skills:i,agents:a,commands:o,rules:c}}async function Rc(t,e,r){const n=[];for(const s of e)try{const{content:e}=await t.fetchFile(s.path),i=Dc({content:Et(e,r),relativePath:s.path});i&&n.push(i)}catch{}return n}async function Jc(t,e,r){const n=[];for(const s of e)try{const{content:e}=await t.fetchFile(s.path),i=Dc({content:Et(e,r),relativePath:s.path});i&&n.push({...i,name:s.name})}catch{}return n}async function Tc(t,e,r){const n=[];for(const s of e)try{const{content:e}=await t.fetchFile(s.path),i=Qc({content:Et(e,r),relativePath:s.path});i&&n.push(i)}catch{}return n}async function qc(t,e,r){const n=[];for(const s of e)try{const{content:e}=await t.fetchFile(s.path),i=Nc({content:Et(e,r),relativePath:s.path});i&&n.push(i)}catch{}return n}function jc(t){if("string"==typeof t){const e=function(t){const e=[];let r=0,n=0;for(let s=0;s<t.length;s++){const i=t[s];if("{"===i)n++;else if("}"===i&&n>0)n--;else if(","===i&&0===n){const n=t.slice(r,s).trim();n&&e.push(n),r=s+1}}const s=t.slice(r).trim();return s&&e.push(s),e}(t);return e.length>0?e:void 0}if(Array.isArray(t)){const e=t.filter((t=>"string"==typeof t)).map((t=>t.trim())).filter(Boolean);return e.length>0?e:void 0}}function Dc({content:t,relativePath:e}){try{const r=(0,nc.be)(t),n=e.replace(/\\/g,"/"),s=n.split("/").filter((t=>t.length>0)),i=s.length>=2?s[s.length-2]:void 0,a=s[s.length-1]??n,o=i??a.replace(/\.md$/i,""),c="string"==typeof r.data.name?r.data.name.trim():void 0,u=mc(r.data.environments??r.data.metadata?.environments),l=mc(r.data["disabled-environments"]??r.data.metadata?.disabledEnvironments);return{path:e,name:c&&c.length>0?c:o,description:"string"==typeof r.data.description?r.data.description:void 0,globs:jc(r.data.globs),alwaysApply:!0===r.data.alwaysApply,content:t,environments:u,disabledEnvironments:l}}catch{return null}}function Qc({content:t,relativePath:e}){try{const n=(0,nc.be)(t),s=n.content.trim();if(!s)return null;let i;"string"==typeof n.data.tools?i=n.data.tools.split(",").map((t=>t.trim())).filter(Boolean):Array.isArray(n.data.tools)&&(i=n.data.tools.map((t=>"string"==typeof t?t.trim():String(t))).filter(Boolean));const a=n.data.permissionMode??n.data.permissionmode,o=(0,B.basename)(e);return{path:e,name:"string"==typeof n.data.name?n.data.name:(0,B.basename)(o,(0,B.extname)(o)).replace(/[\s_]+/g,"-"),description:"string"==typeof n.data.description?n.data.description:void 0,tools:i,model:"string"==typeof n.data.model?n.data.model:"inherit",prompt:s,permissionMode:(r=a,"readonly"===(r??"").trim().toLowerCase()?"readonly":"default")}}catch{return null}var r}function Nc({content:t,relativePath:e}){try{const r=(0,nc.be)(t);let n;const s=r.data["argument-hint"];"string"==typeof s?n=s:Array.isArray(s)&&(n=`[${s.join(" ")}]`);const i=(0,B.basename)(e);return{path:e,name:"string"==typeof r.data.name?r.data.name:(0,B.basename)(i,(0,B.extname)(i)),description:"string"==typeof r.data.description?r.data.description:void 0,argumentHint:n,content:r.content.trim()}}catch{return null}}function Oc(t){if(void 0!==t)return{configuredVariables:t.configuredVariables}}async function Mc(t,e,r){const n=r??Oc(e);return async function(t,e={}){const r=e.toSourcePath??(t=>t);let n,s,i;for(const e of D){const a=await t(e);if(null===a)continue;let o;try{o=JSON.parse(a)}catch{continue}i=R(o);const c=pt(a);if(c.success){void 0!==c.data.mcpServers&&(n=c.data.mcpServers,s=r(e));break}}return Tt(t,n,s,void 0===i?e:{...e,parserOptions:{...e.parserOptions,pluginSchemaId:i}})}(function(t){return async e=>{if(!gt(e))return null;const r=(0,B.join)(t,e);try{return await bc(r)?null:(await(0,yt.stat)(r)).isFile()?(await _c(r),await yc(r)):null}catch{return null}}}(t),{fallbackFileNames:Pt(),manifestPrecedence:"override",toSourcePath:e=>(0,B.join)(t,e),installPathForExpansion:t,parserOptions:n})}async function Uc(t,e,r){const n=await Mc(t,void 0,{log:r});if(n)return n;for(const n of N){const s=(0,B.join)(t,n);try{if(!(await(0,yt.stat)(s)).isFile())continue;const n=await(0,yt.readFile)(s,"utf-8"),i=JSON.parse(n).plugins;if(!Array.isArray(i))continue;const a=e.name,o=i.find((t=>t.name===a));if(!o?.mcpServers?.length)continue;for(const e of o.mcpServers){const n=e.replace(/^\.\//,"");if(!gt(n))continue;const s=(0,B.join)(t,n);try{await _c(s);const e=Rt(await yc(s),t,{log:r});if(e?.mcpServers&&Object.keys(e.mcpServers).length>0){const t=Object.fromEntries(Object.keys(e.mcpServers).map((t=>[t,s])));return{...e,mcpServerSourcePaths:t}}}catch{}}return null}catch{}}return null}function Lc(t,e){const r={};for(const[n,s]of Object.entries(t.hooks))Array.isArray(s)&&(r[n]=s.map((t=>"command"in t&&"string"==typeof t.command?{...t,command:Et(t.command,e)}:"prompt"in t&&"string"==typeof t.prompt?{...t,prompt:Et(t.prompt,e)}:t)));return{...t,hooks:r}}async function Fc(t,e,r,n){if("object"==typeof r){const s=$c(r,e);return s&&"config"in s?{config:Lc(s.config,t),...void 0!==n&&{sourcePath:n}}:s}let s,i,a;if("string"==typeof r){const e=r.replace(/^\.\//,"");if(!gt(e))return;s=e.endsWith(".json")?(0,B.join)(t,e):(0,B.join)(t,e,"hooks.json")}else s=(0,B.join)(t,"hooks","hooks.json");try{if(await bc(s))return;if(!(await(0,yt.stat)(s)).isFile())return}catch{return}try{await _c(s),i=await(0,yt.readFile)(s,"utf-8")}catch{return}try{a=JSON.parse(i)}catch{return{error:{source:"claude-plugin",message:`Plugin ${e} ${s}: invalid JSON`}}}const o=$c(a,e);return o&&"config"in o?{config:Lc(o.config,t),sourcePath:s}:o}function $c(t,e){const r=(0,rc.fp)(t);if("cursor"===r){const r=t,n=(0,rc.RV)(r);return n.isValid?{config:r}:{error:{source:"claude-plugin",message:`Plugin ${e} hooks: ${n.errors.join("; ")}`}}}if("claude-code"===r){const r=t,n=r?.hooks;if(!n||0===Object.keys(n).length)return;const s=(0,rc.sl)(n),i=(0,rc.RV)(s);return i.isValid?{config:s}:{error:{source:"claude-plugin",message:`Plugin ${e} hooks: ${i.errors.join("; ")}`}}}}async function Gc(t,e,r,n){const s=n?.log??i,a=await Bc(t,e,s),o={...Oc(r)??(n?.configuredVariables?{configuredVariables:n.configuredVariables}:void 0),log:s},[c,u,l]=await Promise.all([xc(t,a?.manifestOptions),Mc(t,r,o),Fc(t,e,a?.manifestOptions?.hooks,a?.manifestFilePath)]);return{...c,...void 0!==a?.metadata?.displayName&&{displayName:a.metadata.displayName},...void 0!==a?.metadata?.description&&{description:a.metadata.description},...void 0!==a?.metadata?.authorName&&{authorName:a.metadata.authorName},...void 0!==a?.metadata?.logoUrl&&{logoUrl:a.metadata.logoUrl},...void 0!==a?.metadata?.version&&{version:a.metadata.version},...void 0!==a?.metadata?.homepage&&{homepage:a.metadata.homepage},...void 0!==a?.metadata?.repository&&{repository:a.metadata.repository},variablesSchema:a?.metadata?.variables,mcpConfig:u,capabilities:a?.metadata?.capabilities??[],hooks:l}}async function Kc(t,e,r){const n=r?.log??i,s=await Bc(t,e.raw,n),[a,o,c]=await Promise.all([xc(t,s?.manifestOptions),Uc(t,e,n),Fc(t,e.raw,s?.manifestOptions?.hooks,s?.manifestFilePath)]);return{identifier:{source:"claude-plugin",sourceInfo:e},installPath:t,...void 0!==s?.metadata?.displayName&&{displayName:s.metadata.displayName},...void 0!==s?.metadata?.description&&{description:s.metadata.description},...void 0!==s?.metadata?.authorName&&{authorName:s.metadata.authorName},...void 0!==s?.metadata?.logoUrl&&{logoUrl:s.metadata.logoUrl},...void 0!==s?.metadata?.version&&{version:s.metadata.version},...void 0!==s?.metadata?.homepage&&{homepage:s.metadata.homepage},...void 0!==s?.metadata?.repository&&{repository:s.metadata.repository},...a,mcpConfig:o??void 0,capabilities:s?.metadata?.capabilities??[],hooks:c}}async function Hc(t,e,r,n){const s=`${r.name}@${r.version}`,{displayName:i,description:a,authorName:o,logoUrl:c,version:u,homepage:l,repository:d,variablesSchema:m,skills:p,rules:f,agents:h,commands:g,mcpConfig:A,capabilities:b,hooks:y}=await Gc(t,s,r,{log:n?.log});return{identifier:{source:e,sourceInfo:r},installPath:t,...void 0!==i&&{displayName:i},...void 0!==a&&{description:a},...void 0!==o&&{authorName:o},...void 0!==c&&{logoUrl:c},...void 0!==u&&{version:u},...void 0!==l&&{homepage:l},...void 0!==d&&{repository:d},variablesSchema:m,skills:p,rules:f,agents:h,commands:g,mcpConfig:A??void 0,capabilities:b,hooks:y}}async function zc(t,e,r={}){const n=r.log??i,s=performance.now(),a=await async function(t){const e=gc(t),r=(0,B.join)(e,"plugins","installed_plugins.json");try{const t=await(0,yt.readFile)(r,"utf-8");return JSON.parse(t)}catch(t){return t.code,null}}(r.userHomeDir);if(!a?.plugins)return n.log("info",`loadAllEnabledPlugins: no installed plugins metadata found (${(performance.now()-s).toFixed(1)}ms)`),[];const o=await async function(t){const e=gc(t),r=(0,B.join)(e,"settings.json");try{const t=await(0,yt.readFile)(r,"utf-8");return JSON.parse(t)}catch(t){return t.code,null}}(r.userHomeDir),c=function(t){if(void 0===t)return[];const e="string"==typeof t?[t]:t,r=new Set,n=[];for(const t of e){if(!t)continue;const e=(0,B.resolve)(t);r.has(e)||(r.add(e),n.push(e))}return n}(t),u=function(t,e,r){if(0===r.length)return ic(t,e,null,void 0);const n=new Set;for(const{settings:t}of r)for(const[e,r]of Object.entries(t?.enabledPlugins??{}))!1===r&&n.add(e);const s=new Set,i=[];for(const{workspacePath:a,settings:o}of r){const r=ic(t,e,o,a);for(const t of r)s.has(t.pluginId)||n.has(t.pluginId)||(s.add(t.pluginId),i.push(t))}return i}(a,o,await(0,go.PH)(c,(async t=>({workspacePath:t,settings:await Ac(t)})),{max:8})),l=[],m=r.onError;for(const{pluginId:t,installPath:e}of u)try{const r=performance.now(),s=d(t),i=await Kc(e,s,{log:n});l.push(i),n.log("info",`loadClaudePlugin ${t} loaded in ${(performance.now()-r).toFixed(1)}ms`)}catch(e){const r=e instanceof Error?e:new Error(String(e));if(m)try{m(d(t),r)}catch{m({name:t.split("@")[0]??t,sourceType:"marketplace",marketplace:"unknown",raw:t},r)}}return n.log("info",`loadAllEnabledPlugins completed in ${(performance.now()-s).toFixed(1)}ms (${u.length} resolved, ${l.length} loaded)`),l}Error;async function Wc(t){const e=t.log??i,r=performance.now(),{client:n,userId:s,teamId:a,onCursorError:o,pruneOldVersions:c,pluginFilter:u,onPluginsListed:l}=t,d=[],m=t.cacheManager??new Ca(t.userHomeDir),p=performance.now();let f;try{f=await n.listEnabledPlugins(s,a)}catch(t){return e.captureException(t,{error_type:"list_enabled_plugins"}),e.increment("marketplace.source_unavailable",1),e.log("error",`marketplace listEnabledPlugins failed after ${(performance.now()-p).toFixed(1)}ms; treating source as unavailable: ${t instanceof Error?t.message:String(t)}`),{plugins:[],failures:[],sourceUnavailable:!0}}e.log("info",`marketplace listEnabledPlugins completed in ${(performance.now()-p).toFixed(1)}ms (${f.plugins.length} plugins)`),l&&await l(f.plugins);const h=[];if(f.listFailures){d.push(...f.listFailures);for(const t of f.listFailures)h.push({identifier:{source:t.marketplaceName&&"cursor-public"!==t.marketplaceName?"cursor-third-party":"cursor-first-party",sourceInfo:{name:t.pluginName,version:"",...void 0!==t.pluginDbId&&{pluginDbId:t.pluginDbId},marketplace:t.marketplaceName}},installPath:"",loadError:t.errorMessage,skills:[],rules:[],agents:[],commands:[],capabilities:[]})}const g=new Map;for(const t of f.plugins)if(!u||u(t))try{const r=t.marketplace?.name;if(!r){const e=new Error(`Plugin ${t.name} has no marketplace metadata — cannot determine cache path`);d.push({pluginName:t.name,pluginId:t.pluginId,marketplaceName:void 0,errorMessage:e.message,errorType:"manifest"}),o&&o(t,e);continue}const s=`${r}/${t.pluginId}`;let i,a=g.get(s);if(a||(a={slug:r,pluginId:t.pluginId,versions:[]},g.set(s,a)),a.versions.push(t.version),await m.isCached({marketplaceSlug:r,pluginId:t.pluginId,version:t.version}))i=m.getCacheDir({marketplaceSlug:r,pluginId:t.pluginId,version:t.version}),e.log("info",`loadFromMarketplaceSource: Found cached plugin: ${t.pluginId} at ${i}`,{marketplaceSlug:r,pluginId:t.pluginId,gitRef:t.version,marketplaceId:t.marketplace?.id});else{const s=m.getCacheDir({marketplaceSlug:r,pluginId:t.pluginId,version:t.version});e.log("info",`loadFromMarketplaceSource: Plugin missing from cache, installing: ${t.pluginId} at ${s}`,{marketplaceSlug:r,pluginId:t.pluginId,gitRef:t.version,marketplaceId:t.marketplace?.id}),await(0,yt.mkdir)(s,{recursive:!0});try{await n.installPlugin(t,s),await m.markCacheComplete({marketplaceSlug:r,pluginId:t.pluginId,version:t.version})}catch(t){try{await(0,yt.rm)(s,{recursive:!0,force:!0})}catch{}throw t}i=s}const c=t.marketplace?.name,u=void 0!==c&&"cursor-public"!==c&&c.length>0?"cursor-third-party":"cursor-first-party",l={name:t.name,version:t.version,pluginDbId:t.pluginDbId,configuredVariables:t.configuredVariables,marketplace:c,marketplaceDbId:t.marketplaceDbId,isTeamRequired:t.isTeamRequired},p=await Hc(i,u,l,{log:e});h.push(p);try{await m.pruneOldVersions({marketplaceSlug:r,pluginId:t.pluginId,keepVersions:[t.version]})}catch{}}catch(r){e.captureException(r,{error_type:"load_plugin_from_marketplace"});const n=r instanceof Error?r:new Error(String(r));d.push({pluginName:t.name,pluginId:t.pluginId,marketplaceName:t.marketplace?.name,errorMessage:n.message,errorType:wc(n)});const s=t.marketplace?.name,i=void 0!==s&&"cursor-public"!==s&&s.length>0;h.push({identifier:{source:i?"cursor-third-party":"cursor-first-party",sourceInfo:{name:t.name,version:t.version,pluginDbId:t.pluginDbId,marketplace:s,marketplaceDbId:t.marketplaceDbId,isTeamRequired:t.isTeamRequired}},installPath:"",loadError:n.message||"Plugin load failed",skills:[],rules:[],agents:[],commands:[],capabilities:[]}),o&&o(t,n)}if(c)for(const{slug:t,pluginId:e,versions:r}of g.values())try{await m.pruneOldVersions({marketplaceSlug:t,pluginId:e,keepVersions:r})}catch{}return e.log("info",`loadFromMarketplaceSource completed in ${(performance.now()-r).toFixed(1)}ms (${h.length} plugins loaded, ${d.length} failures)`),{plugins:h,failures:d,sourceUnavailable:!1}}async function Yc(t,e={}){const r=e.log??i,n=performance.now(),s=e.loadClaude??!0,a=e.loadUserLocal??!0,o=e.marketplaceSources??[],c=e.loadCursorFirstParty??o.length>0,u=[],l=[];let d;s&&u.push(zc(t,0,{userHomeDir:e.userHomeDir,onError:e.onError,log:r})),c&&o.length>0&&(d=Promise.allSettled(o.map((t=>Wc({...t,userHomeDir:t.userHomeDir??e.userHomeDir,log:t.log??r}))))),a&&u.push(async function(t={}){const e=t.log??i,r=performance.now(),n=t.userHomeDir??process.env.HOME;if(!n)return e.log("info","loadUserLocalPlugins: no home directory available, skipping"),[];const s=(0,B.join)(n,".cursor","plugins","local");let a;try{a=await(0,yt.readdir)(s,{withFileTypes:!0})}catch{return e.log("info",`loadUserLocalPlugins: ${s} not found or not readable (${(performance.now()-r).toFixed(1)}ms)`),[]}const o=await(0,yt.realpath)(s).catch((()=>(0,B.resolve)(s))),c=[];for(const r of a){if(!r.isDirectory()&&!r.isSymbolicLink())continue;if(r.name.startsWith("."))continue;const n=(0,B.join)(s,r.name);try{if(r.isSymbolicLink()){let t;try{t=await(0,yt.realpath)(n)}catch(t){e.log("warn",`loadUserLocalPlugin ${r.name} rejected: failed to resolve symlink (${t instanceof Error?t.message:String(t)})`);continue}try{Ao(o,t)}catch{e.log("warn",`loadUserLocalPlugin ${r.name} rejected: symlink target ${t} is outside ${s}`);continue}}if(!(await(0,yt.stat)(n)).isDirectory()){r.isSymbolicLink()&&e.log("warn",`loadUserLocalPlugin ${r.name} rejected: symlink target is not a directory`);continue}const i=performance.now(),a=await(t.localPluginVariablesLookup?.(r.name)),{displayName:u,description:l,authorName:d,logoUrl:m,version:p,homepage:f,repository:h,variablesSchema:g,skills:A,rules:b,agents:y,commands:_,mcpConfig:w,capabilities:C,hooks:v}=await Gc(n,r.name,void 0,{configuredVariables:a,log:e}),E={source:"user-local",sourceInfo:{name:r.name,localPath:n}};c.push({identifier:E,installPath:n,...void 0!==u&&{displayName:u},...void 0!==l&&{description:l},...void 0!==d&&{authorName:d},...void 0!==m&&{logoUrl:m},...void 0!==p&&{version:p},...void 0!==f&&{homepage:f},...void 0!==h&&{repository:h},variablesSchema:g,skills:A,rules:b,agents:y,commands:_,mcpConfig:w??void 0,capabilities:C,hooks:v}),e.log("info",`loadUserLocalPlugin ${r.name} loaded in ${(performance.now()-i).toFixed(1)}ms`)}catch(t){e.log("error",`loadUserLocalPlugin ${r.name} failed: ${t instanceof Error?t.message:String(t)}`)}}return e.log("info",`loadUserLocalPlugins completed in ${(performance.now()-r).toFixed(1)}ms (${c.length} plugins loaded)`),c}({userHomeDir:e.userHomeDir,log:r,localPluginVariablesLookup:e.localPluginVariablesLookup}));const[m,p]=await Promise.all([Promise.allSettled(u),d??Promise.resolve([])]);let f=!1;const h=[];for(const t of p)"rejected"!==t.status?(t.value.sourceUnavailable&&(f=!0),h.push(...t.value.plugins),l.push(...t.value.failures)):(f=!0,r.log("error",`marketplace source threw while loading; treating it as unavailable: ${String(t.reason)}`));for(const t of m)"rejected"!==t.status?h.push(...t.value):(f=!0,r.log("error",`plugin source threw while loading; treating it as unavailable: ${String(t.reason)}`));const g=new Set,A=[];for(const t of h){if(!t.installPath){A.push(t);continue}const e=await(0,yt.realpath)(t.installPath).catch((()=>t.installPath));g.has(e)||(g.add(e),A.push(t))}const b=new Map,y=[];for(const t of A){const e=Vc(t);if(void 0!==e){const r=b.get(e),n=!t.loadError;if(!0===r)continue;if(!1===r&&n){const r=y.findIndex((t=>Vc(t)===e&&t.loadError));-1!==r&&y.splice(r,1),b.set(e,!0),y.push(t);continue}b.set(e,n)}y.push(t)}const _=performance.now()-n;return r.log("info",`loadAllPlugins completed in ${_.toFixed(1)}ms (claude=${s}, userLocal=${a}, marketplace=${o.length} sources, total=${y.length} plugins, failures=${l.length}, sourceUnavailable=${f})`),{plugins:y,failures:l,sourceUnavailable:f}}function Vc(t){const{identifier:e}=t;switch(e.source){case"claude-plugin":return"marketplace"===e.sourceInfo.sourceType&&e.sourceInfo.marketplace?`${e.sourceInfo.marketplace}/${e.sourceInfo.name}`:void 0;case"cursor-first-party":case"cursor-third-party":return e.sourceInfo.marketplace?`${e.sourceInfo.marketplace}/${e.sourceInfo.name}`:void 0;default:return}}function Xc(t){return Vc(t)??`path:${t.installPath}`}async function Zc(t,e,r={}){const n=r.log??s,i=[];for(const r of t.plugins){const t=Ba(r);if(!t){n(`Skipping unresolved plugin ${r.marketplaceSlug}/${r.pluginId}: no plugin version`);continue}const s=wa(e,{marketplaceSlug:r.marketplaceSlug,pluginId:r.pluginId,version:t}),o={name:r.pluginId,version:t,marketplace:r.marketplaceSlug};try{i.push(await Hc(s,(a=r.marketplaceSlug,"cursor-public"===a?"cursor-first-party":"cursor-third-party"),o))}catch(t){n(`Failed to load cached plugin ${r.marketplaceSlug}/${r.pluginId} from ${s}: ${t instanceof Error?t.message:String(t)}`)}}var a;return i}function tu(t,e={}){return{...t,model:e.stripModel?void 0:t.model,tools:e.stripTools?void 0:t.tools}}const eu=(0,B.join)((0,va.homedir)(),".claude","plugins","marketplaces"),ru={log:()=>{}};async function nu(t={}){const e=t.marketplacesDir??eu,r=void 0===t.existingUserMarketplaceNames?new Set:t.existingUserMarketplaceNames instanceof Set?t.existingUserMarketplaceNames:new Set(t.existingUserMarketplaceNames),n=t.logger??ru,s=t.maxConcurrent??4,i={payloads:[],marketplacesDir:e,totalDirectories:0,skippedExisting:0,unparseable:0};let a;n.log("cc-marketplace-import.start",{dir:e});try{a=await(0,yt.readdir)(e,{withFileTypes:!0})}catch(t){return n.log("cc-marketplace-import.readdirError",{dir:e,error:t instanceof Error?t.message:String(t)}),i}const o=[];for(const t of a)t.isDirectory()&&o.push((0,B.join)(e,t.name));if(0===o.length)return n.log("cc-marketplace-import.noMarketplaces"),{...i};n.log("cc-marketplace-import.foundMarketplaces",{count:o.length});const c=await(0,go.up)(o,(async t=>async function(t){const{dirPath:e,existingUserMarketplaceNames:r,logger:n}=t,s=(0,B.basename)(e),i=await async function(t){const e=(0,B.join)(t,".git","config");try{const t=(await(0,yt.readFile)(e,"utf-8")).match(/\[remote\s+"origin"\][^[]*\burl\s*=\s*(.+)/m);if(t?.[1])return t[1].trim()}catch{}}(e);if(!i)return n.log("cc-marketplace-import.noGitUrl",{dirPath:e}),{kind:"unparseable",reason:"no-git-url"};const a=await To(e,{repoName:s});if(null===a)return n.log("cc-marketplace-import.noManifest",{dirPath:e}),{kind:"unparseable",reason:"no-manifest"};if(r.has(a.name))return n.log("cc-marketplace-import.skippedExistingUserMarketplace",{marketplaceName:a.name,dirPath:e}),{kind:"skipped-existing",marketplaceName:a.name};const o=await async function(t){const e=(0,B.join)(t,".git","HEAD");try{const r=(await(0,yt.readFile)(e,"utf-8")).trim();if(r.startsWith("ref: ")){const e=(0,B.join)(t,".git",r.slice(5)),n=(await(0,yt.readFile)(e,"utf-8")).trim();return 40===n.length?n:void 0}return 40===r.length?r:void 0}catch{}}(e),c=await async function(t){const e=(0,B.join)(t,".git","HEAD");try{const t=(await(0,yt.readFile)(e,"utf-8")).trim();if(t.startsWith("ref: refs/heads/"))return t.slice(16)}catch{}return"main"}(e),u=[],l=a.metadata?.pluginRoot;for(const t of a.plugins){const r="string"==typeof t.name?t.name:t.name??s,i=ft(t.source,l);if(null===i){n.log("cc-marketplace-import.skippingExternalPlugin",{name:r,source:t.source});continue}if(!gt(i)){n.log("cc-marketplace-import.skippingUnsafePluginPath",{name:r,source:t.source,gitPath:i});continue}const a=(0,B.join)(e,i);try{if(!(await(0,yt.stat)(a)).isDirectory())continue}catch{continue}try{const e=await Pc(a),n=e.manifest.name??t.displayName??r,s=e.manifest.description??t.description??"";u.push({name:r,displayName:n,description:s,gitPath:i,gitUrl:"",gitRef:"",skills:e.skills,subagents:e.subagents,hooks:e.hooks,rules:e.rules,mcpServers:e.mcpServers,commands:e.commands,logoUrl:t.logo,variables:e.manifest.variables})}catch(t){n.log("cc-marketplace-import.pluginLoadError",{name:r,pluginPath:a,error:t instanceof Error?t.message:String(t)})}}return 0===u.length?(n.log("cc-marketplace-import.noPlugins",{dirPath:e}),{kind:"unparseable",reason:"no-plugins"}):{kind:"payload",payload:{gitUrl:i,gitRef:o??c,marketplaceName:a.name,commitSha:o??void 0,plugins:u}}}({dirPath:t,existingUserMarketplaceNames:r,logger:n})),{max:s}),u=[];let l=0,d=0;return c.forEach(((t,e)=>{if("fulfilled"!==t.status)return d+=1,void n.log("cc-marketplace-import.parseError",{dirPath:o[e],error:t.reason instanceof Error?t.reason.message:String(t.reason)});switch(t.value.kind){case"payload":u.push(t.value.payload);break;case"skipped-existing":l+=1;break;case"unparseable":d+=1;break;default:t.value}})),n.log("cc-marketplace-import.discoveryComplete",{totalDirectories:o.length,payloads:u.length,skippedExisting:l,unparseable:d}),{payloads:u,marketplacesDir:e,totalDirectories:o.length,skippedExisting:l,unparseable:d}}function su(t){const{pluginLogo:e,entryLogo:r,owner:n,repo:s,ref:i,basePath:a}=t;return e?.startsWith("http")?e:e?ht({logo:e,owner:n,repo:s,ref:i,basePath:a}):r?"string"==typeof r&&r.startsWith("http")?r:ht({logo:r,owner:n,repo:s,ref:i,basePath:a}):void 0}function iu(t){return"local"!==t.sourceType}const au={skills:[],subagents:[],hooks:[],rules:[],mcpServers:[],commands:[],variables:void 0,logoUrl:void 0};function ou(t,e,r,n){if(t?.startsWith("http"))return t;const s=so(e.gitUrl);return"error"in s?void 0:t?ht({logo:t,owner:s.owner,repo:s.repo,ref:e.gitRef??"HEAD",basePath:n}):void 0}function cu({gitRef:t,result:e}){const r=e.commitSha||e.defaultBranch||t||"";return{gitUrl:e.repositoryUrl,gitRef:r,marketplaceName:e.marketplaceName,commitSha:e.commitSha||void 0,plugins:e.plugins.filter((t=>!t.parseError)).map((t=>({name:t.name,displayName:t.displayName,description:t.description,gitPath:t.gitPath,gitUrl:t.externalUrl??"",gitRef:t.externalRef??"",skills:t.skills,subagents:t.subagents,hooks:t.hooks,rules:t.rules,mcpServers:t.mcpServers,commands:t.commands,logoUrl:t.logoUrl,variables:t.variables})))}}async function uu(t){const{pluginMetricsLogger:e=i,onParsedMarketplace:r}=t,n=so(t.gitUrl);if("error"in n)throw new Error(n.error);if(!t.allowNonGitHubHosts&&!Wa(n.host))throw new Error(`Only github.com repositories are supported for local preview. Host "${n.host}" is not allowed.`);const s=`${n.url}.git`,a=t.gitUrl.trim(),o=a.startsWith("git@")||a.startsWith("ssh://"),c=n.url.startsWith(`https://${n.host}/`),u=o?a:c?n.url:void 0,l=t.allowNonGitHubHosts&&!Wa(n.host)&&void 0!==u?lo(u)??void 0:void 0,d=await async function(t,e,r){const n=e?.trim()||"HEAD",s=await async function(t){const{primaryGitUrl:e,fallbackGitUrl:r,requestedRef:n}=t;try{return await ja(e,n,{sshBatchMode:e.startsWith("git@")||e.startsWith("ssh://")})}catch(t){if(void 0===r||r===e)throw t;return await ja(r,n)}}({primaryGitUrl:r??t,fallbackGitUrl:void 0===r?void 0:t,requestedRef:n});return"HEAD"===n.toUpperCase()?{requestedRef:n,cloneRef:s.fullSha,commitSha:s.fullSha,defaultBranch:Ta(s.headSymrefStdout??"")??"HEAD"}:{requestedRef:n,cloneRef:s.fullSha,commitSha:s.fullSha,defaultBranch:n}}(s,t.gitRef,l),m=`${n.owner}-${n.repo}-local`.toLowerCase();e.log("info","parseGitHubRepoForPluginsLocally: Resolved remote ref",{marketplaceRepo:n.repo,marketplaceId:m,resolvedRef:d,gitRef:t.gitRef,gitUrl:t.gitUrl});const p=new Jo(t.marketplaceCacheRoot,{sparsePluginClones:t.sparsePluginClones}),f=await p.ensureCloned(m,s,d.cloneRef,e,{materialize:[]});let h=d.commitSha??"";try{if(""===h){const{stdout:t}=await xa(["rev-parse","HEAD"],{cwd:f});h=t.trim()}}catch{h=d.commitSha??""}let g=d.defaultBranch;if("HEAD"===g)try{const{stdout:t}=await xa(["rev-parse","--abbrev-ref","HEAD"],{cwd:f}),e=t.trim();e&&"HEAD"!==e&&(g=e)}catch{}const A=n.url,{owner:b,repo:y}=n,_=await p.readManifest(f,{repoName:y});if(null!==_){const s=await p.discoverPlugins(f),a=s.filter((t=>"local"===t.sourceType)),o=s.filter(iu);a.length>0&&await p.ensureMaterialized(f,Oa(a.map((t=>t.gitPath))),e);const c=await async function(t){const e=t.logger??i,r=[];for(const n of t.localPlugins){const s=t.manifest.plugins.find((t=>t.name===n.name));if(void 0===s)continue;let i,a;try{i=Ao(t.rootDir,n.gitPath)}catch(t){e.log("warn","loadLocalPluginEntries: plugin path escapes marketplace folder, skipping",{plugin:n.name,gitPath:n.gitPath,error:t instanceof Error?t.message:String(t)});continue}try{a=await Pc(i,{symlinkTargetRoot:t.rootDir})}catch(t){e.log("warn","loadLocalPluginEntries: failed to load plugin preview, skipping",{plugin:n.name,error:t instanceof Error?t.message:String(t)});continue}const o=At(a.manifest,s),c=a.manifest.description??s.description??"";r.push({name:s.name,displayName:o||s.name,description:c,gitPath:n.gitPath,logoUrl:t.resolveEntryLogoUrl?.({manifestLogo:a.manifest.logo,entry:s,gitPath:n.gitPath}),variables:a.manifest.variables??s.variables,skills:a.skills,subagents:a.subagents,hooks:a.hooks,rules:a.rules,mcpServers:a.mcpServers,commands:a.commands})}return r}({rootDir:f,manifest:_,localPlugins:a,resolveEntryLogoUrl:({manifestLogo:t,entry:e,gitPath:r})=>su({pluginLogo:t,entryLogo:e.logo,owner:b,repo:y,ref:h||g,basePath:r}),logger:e});if(o.length>0){const r=await async function(t,e,r,n){const s=new Map;if(0===t.length)return s;const i=new Map;for(const[e,r]of t.entries()){const t=r.sha??r.gitRef??"HEAD",n=`${r.gitUrl}\0${t}`;let s=i.get(n);s||(s={gitUrl:r.gitUrl,ref:t,plugins:[]},i.set(n,s)),s.plugins.push({index:e,plugin:r})}for(const t of i.values()){const i=so(t.gitUrl);if("error"in i){r.log("warn","loadExternalPluginsLocally: Rejecting external plugin URL",{gitUrl:t.gitUrl,reason:i.error});for(const{index:e}of t.plugins)s.set(e,au);continue}if(!Wa(i.host)&&i.host!==n){r.log("warn","loadExternalPluginsLocally: Rejecting non-github.com external plugin URL",{gitUrl:t.gitUrl,host:i.host});for(const{index:e}of t.plugins)s.set(e,au);continue}const a=`${i.owner}-${i.repo}-external`.toLowerCase(),o=`${i.url}.git`,c=t.plugins.some((({plugin:t})=>"git-subdir"!==t.sourceType))?"all":Oa(t.plugins.flatMap((({plugin:t})=>"git-subdir"===t.sourceType?[t.subdirPath]:[])));let u;try{u=await e.ensureCloned(a,o,t.ref,r,{materialize:c})}catch(e){r.log("warn","loadExternalPluginsLocally: Failed to clone external repo, falling back to metadata only",{gitUrl:t.gitUrl,gitRef:t.ref,error:e instanceof Error?e.message:String(e)});for(const{index:e}of t.plugins)s.set(e,au);continue}for(const{index:n,plugin:i}of t.plugins){const a="git-subdir"===i.sourceType?i.subdirPath:void 0;let o;try{o=a?e.getPluginDir(u,a):u}catch{s.set(n,au);continue}try{const t=await Pc(o,{symlinkTargetRoot:u}),e=ou(t.manifest.logo,i,0,a);s.set(n,{skills:t.skills,subagents:t.subagents,hooks:t.hooks,rules:t.rules,mcpServers:t.mcpServers,commands:t.commands,variables:t.manifest.variables,logoUrl:e})}catch(e){r.log("warn","loadExternalPluginsLocally: Failed to discover external plugin components, falling back to metadata only",{gitUrl:t.gitUrl,pluginName:i.name,subdirPath:a,error:e instanceof Error?e.message:String(e)}),s.set(n,au)}}}return s}(o,p,e,t.allowNonGitHubHosts?n.host:void 0);for(const[t,e]of o.entries()){const n=_.plugins.find((t=>t.name===e.name)),s=r.get(t)??au,i="git-subdir"===e.sourceType?e.subdirPath:void 0;c.push({name:e.name,displayName:At({displayName:e.displayName},{name:e.name}),description:e.description??"",gitPath:i??"",logoUrl:s.logoUrl??n?.logo,variables:s.variables??n?.variables,externalUrl:e.gitUrl,externalRef:e.sha??e.gitRef??"HEAD",subdirPath:i,skills:s.skills,subagents:s.subagents,hooks:s.hooks,rules:s.rules,mcpServers:s.mcpServers,commands:s.commands})}}!function(t,e){const r=new Set(t.map((t=>t.name)));for(const s of e){let e=s.name;if(!e||r.has(e)){let t=s.index;do{e=`errored-plugin-${t}`,t++}while(r.has(e))}r.add(e),t.push({name:(n={name:e,displayName:s.name??e,parseError:s.error}).name,displayName:n.displayName,description:n.description??"",gitPath:"",skills:[],subagents:[],hooks:[],rules:[],mcpServers:[],commands:[],parseError:n.parseError})}var n}(c,_.skippedPluginEntries);const u={marketplaceName:_.name,marketplaceDescription:_.metadata?.description??_.description??"",defaultBranch:g,repositoryUrl:A,commitSha:h,plugins:c};return r&&r({gitUrl:t.gitUrl,gitRef:t.gitRef,result:u}).catch((t=>{e.log("warn","parseGitHubRepoForPluginsLocally: onParsedMarketplace callback failed",{error:t instanceof Error?t.message:String(t)})})),u}await p.ensureMaterialized(f,"all",e);const w=await Pc(f,{symlinkTargetRoot:f}),C=w.manifest.name?lc(w.manifest.name):lc(y),v=At(w.manifest,{name:y}),E=w.manifest.description??"",S=su({pluginLogo:w.manifest.logo,owner:b,repo:y,ref:h||g}),I={marketplaceName:C,marketplaceDescription:E,defaultBranch:g,repositoryUrl:A,commitSha:h,plugins:[{name:C,displayName:v||C,description:E,gitPath:"",logoUrl:S,variables:w.manifest.variables,skills:w.skills,subagents:w.subagents,hooks:w.hooks,rules:w.rules,mcpServers:w.mcpServers,commands:w.commands}]};return r&&r({gitUrl:t.gitUrl,gitRef:t.gitRef,result:I}).catch((t=>{e.log("warn","parseGitHubRepoForPluginsLocally: onParsedMarketplace callback failed",{error:t instanceof Error?t.message:String(t)})})),I}new Map([["api.origin.cursor.com","origin.cursor.com"],["api.origin-staging.cursor.com","origin-staging.cursor.com"],["api.origin-test.cursor.com","origin-test.cursor.com"]]);const lu=["origin.cursor.com"];function du(t,e=[]){const r=e.filter((t=>""!==t.trim())),n=function(t,e){if(void 0===e||0===e.length)return;const r=`Authorization: Basic ${n=`x-access-token:${e}`,"undefined"!=typeof Buffer?Buffer.from(n).toString("base64"):btoa(n)}`;var n;return Object.fromEntries(t.map((t=>[`http.https://${t}/.extraheader`,r])))}(0===r.length?lu:[...new Set([...lu,...r])],t);if(void 0!==n)return Object.fromEntries(Object.entries(n).map((([t,e])=>[t,[e,"x-prefer-origin-reads: true"]])))}function mu(t){return fu(t,(t=>t.skills))}function pu(t){return fu(t,(t=>t.rules))}function fu(t,e){const r=[];for(const s of t){const t=m(s.identifier),i=`plugin:${t}`,a=p(s.identifier),o=f(s.identifier),c=h(s.identifier),u=g(s.identifier);for(const l of e(s)){const e=(0,B.join)(s.installPath,l.path),{type:d,globs:m,description:p}=(n=l).alwaysApply?{type:"global"}:n.globs&&n.globs.length>0?{type:"fileGlobbed",globs:n.globs}:n.description?{type:"agentFetched",description:n.description}:{type:"manuallyAttached"};r.push({fullPath:e,content:l.content,type:d,globs:m,description:p,pluginIdentifier:t,gitRemoteOrigin:i,plugin:a,marketplace:o,pluginId:c,marketplaceId:u,environments:l.environments,disabledEnvironments:l.disabledEnvironments})}}var n;return r}function hu(t,e={stripModel:!0,stripTools:!0}){const r=[];for(const n of t){const t=p(n.identifier),s=f(n.identifier),i=h(n.identifier),a=g(n.identifier);for(const o of n.agents){const c=tu(o,e),u=(0,B.join)(n.installPath,c.path);r.push({name:c.name,description:c.description??"",prompt:c.prompt,fullPath:u,permissionMode:"readonly"===c.permissionMode?"readonly":"default",plugin:t,marketplace:s,pluginId:i,marketplaceId:a})}}return r}const gu=n.Ik({path:n.Yj(),name:n.Yj().optional(),description:n.Yj().optional(),globs:n.YO(n.Yj()).optional(),alwaysApply:n.zM().optional(),content:n.Yj(),environments:n.YO(n.Yj()).optional(),disabledEnvironments:n.YO(n.Yj()).optional()}),Au=gu.extend({name:n.Yj()}),bu=n.Ik({path:n.Yj(),name:n.Yj(),description:n.Yj().optional(),tools:n.YO(n.Yj()).optional(),model:n.Yj().optional(),prompt:n.Yj(),permissionMode:n.k5(["default","readonly"]).optional()}),yu=n.Ik({path:n.Yj(),name:n.Yj(),description:n.Yj().optional(),argumentHint:n.Yj().optional(),content:n.Yj()}),_u=n.Ie((t=>"object"==typeof t&&null!==t&&"object"==typeof t.hooks&&null!==t.hooks)),wu=n.Ik({config:_u,sourcePath:n.Yj().optional()}),Cu=n.Ie((t=>"object"==typeof t&&null!==t));function vu(t){const e=t.trim();if(!e)return!1;if(e.startsWith("git@"))return/^git@[a-zA-Z0-9.-]+:[a-zA-Z0-9._~\-/]+(?:\.git)?$/.test(e);try{const t=new URL(e);return"https:"===t.protocol&&""===t.username&&""===t.password&&""===t.search&&""===t.hash}catch{return!1}}n.Ik({schemaVersion:n.ai().int(),displayName:n.Yj().optional(),description:n.Yj().optional(),authorName:n.Yj().optional(),skills:n.YO(gu),rules:n.YO(Au),agents:n.YO(bu),commands:n.YO(yu),mcpConfig:o.extend({mcpServerSourcePaths:n.g1(n.Yj(),n.Yj()).optional()}).optional(),hooks:wu.optional(),hooksError:n.Yj().optional(),capabilities:n.YO(n.Yj()),variablesSchema:Cu.optional()}),Error;class Eu extends Error{constructor(t){super(t),this.name="SettingsParseError"}}const Su=".cursor",Iu={formattingOptions:{tabSize:2,insertSpaces:!0,eol:"\n",insertFinalNewline:!0}};function Bu(t){return(0,B.join)(t,Su,"settings.json")}function ku(t){return 65279===t.charCodeAt(0)?t.slice(1):t}async function Pu(t){try{return ku(await(0,yt.readFile)(Bu(t),"utf-8"))}catch(t){if(function(t){return t instanceof Error&&"code"in t}(t)&&("ENOENT"===t.code||"ENOTDIR"===t.code))return;throw t}}function xu(t){const e=ku(t);if(0===e.trim().length)return{};const r=[],n=(0,_t.qg)(e,r,{allowTrailingComma:!0});if(r.length>0){const t=r.slice(0,3).map((t=>`${(0,_t._n)(t.error)} at offset ${t.offset}`)).join("; ");throw new Eu(`.cursor/settings.json contains syntax errors: ${t}`)}if("object"!=typeof n||null===n||Array.isArray(n))return{};const s=n;return void 0===s.plugins||"object"==typeof s.plugins&&null!==s.plugins&&!Array.isArray(s.plugins)?s:{}}async function Ru(t,e){const r=(0,B.join)(t,Su);await(0,yt.mkdir)(r,{recursive:!0});const n=e.endsWith("\n")?e:`${e}\n`;await(0,yt.writeFile)(Bu(t),n,"utf-8")}async function Ju(t,e){const r=await Pu(t),n=r??"{}";void 0!==r&&xu(r);const s=(0,_t.JP)(n,["plugins",e],{enabled:!0},Iu),i=(0,_t.ct)(n,s);await Ru(t,i)}async function Tu(t,e,r){if(!vu(r.gitUrl))throw new Error(`Invalid project plugin git URL. Only https:// and git@ URLs are allowed: ${JSON.stringify(r.gitUrl)}`);const n=await Pu(t),s=n??"{}";void 0!==n&&xu(n);const i={enabled:!0,gitUrl:r.gitUrl,gitRef:r.gitRef},a=(0,_t.JP)(s,["plugins",e],i,Iu),o=(0,_t.ct)(s,a);await Ru(t,o)}async function qu(t,e){const r=await Pu(t);if(void 0===r)return;const n=xu(r);if(!n.plugins||!(e in n.plugins))return;let s=(0,_t.JP)(r,["plugins",e],void 0,Iu),i=(0,_t.ct)(r,s);const a=xu(i);if(a.plugins&&0===Object.keys(a.plugins).length){s=(0,_t.JP)(i,["plugins"],void 0,Iu),i=(0,_t.ct)(i,s);const t=xu(i);0===Object.keys(t).length&&/^\{\n\}\n?$/.test(i)&&(i="{}")}await Ru(t,i)}async function ju(t){const e=await Pu(t);return void 0===e?[]:function(t){const e=xu(t);return e.plugins?Object.entries(e.plugins).filter((([,t])=>!0===t.enabled)).filter((([,t])=>!t.gitUrl||vu(t.gitUrl))).map((([t,e])=>({key:t,entry:e}))):[]}(e)}function Du(t){const e=t.name;if(!e)return;const r=t.marketplace;return"cursor-public"===r?.name||"GLOBAL"===r?.type?e:r?.name?`${r.name}/${e}`:e}function Qu(t){const e=t.indexOf("/");return-1===e?{name:t}:{name:t.slice(e+1),marketplaceName:t.slice(0,e)}}}

Prompt skill references

Source: 9577.index.js (Agent CLI) · bytes 12720–13016 · SHA-256 863ce97484b0…

Minified Agent CLI webpack module ./src/commands/prompt-skill-references.ts (296 characters), the code behind the prompt skill references. Identifiers are minified; the exact shipped code is below.

Exact shipped text
"./src/commands/prompt-skill-references.ts"(e,t,r){r.d(t,{_:()=>n,i:()=>o});var s=r("./src/selected-skills.ts");function n(e){return/(?:^|\s)\/[a-zA-Z0-9_-]/.test(e)}function o(e,t){if(!n(t))return[];const{skills:r}=e.findSkillReferences(t);return 0===r.length?[]:(0,s.XE)({referencedSkills:r})}}

Selected skills request assembly

Source: 9577.index.js (Agent CLI) · bytes 54175–55527 · SHA-256 cf6439c62e7d…

Minified Agent CLI webpack module ./src/selected-skills.ts (1,352 characters), the code behind the selected skills request assembly. Identifiers are minified; the exact shipped code is below.

Exact shipped text
"./src/selected-skills.ts"(e,t,r){r.d(t,{DP:()=>d,XE:()=>u,b6:()=>c,w8:()=>l});var s=r("../custom-modes/dist/index.js"),n=r("../proto/dist/generated/agent/v1/agent_skills_pb.js"),o=r("../utils/dist/gray-matter.js"),a=r("./src/custom-mode-types.ts");function i(e){const t=e.fullPath?.trim();return t?`path:${t}`:`description:${(e.description??"").trim()}`}function d(e){return new n.N({fullPath:e.path,content:e.content,description:e.description??e.title??e.id??""})}function l(e){if("entered"===e?.lifecycle)return new n.N({fullPath:e.mode.fullPath,content:e.mode.body,description:e.mode.description??e.mode.label})}function c(e){return function(e,t){let r;try{r=(0,o.be)(e.body??"")}catch{return}const n=(0,s.UN)({frontmatter:r.data,body:r.content});if(void 0!==n)return{id:(0,s.Qw)(e.fullPath||e.filename),label:t,fullPath:e.fullPath,badgeAppearance:(0,a.W)(n.badgeAppearance),body:n.body,description:e.description}}({filename:e.id??e.path,fullPath:e.path,body:e.content,description:e.description??e.title},e.title??e.id??function(e){const t=e.replace(/\\/g,"/").split("/"),r=t.indexOf("SKILL.md");return r>0?t[r-1]??"Skill":"Skill"}(e.path))}function u({referencedSkills:e,selectedSkills:t}){return function(e){const t=[],r=new Set;for(const s of e){const e=i(s);"description:"===e||r.has(e)||(r.add(e),t.push(s))}return t}([...t??[],...e.map(d)])}}