@director.run/cli 1.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +134 -73
- package/dist/cli.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -61,55 +61,75 @@ The easiest way to author a playbook is via the UI (`director studio`). But you
|
|
|
61
61
|
# Client <> Playbook mappings (enforced on startup)
|
|
62
62
|
#
|
|
63
63
|
clients:
|
|
64
|
-
|
|
65
|
-
cursor: [ production-support ]
|
|
64
|
+
cursor: [ demo ]
|
|
66
65
|
|
|
67
|
-
#
|
|
68
|
-
# Playbooks
|
|
69
|
-
#
|
|
70
66
|
playbooks:
|
|
71
|
-
- id:
|
|
72
|
-
name:
|
|
73
|
-
description:
|
|
67
|
+
- id: demo
|
|
68
|
+
name: demo
|
|
69
|
+
description: A demonstration playbook
|
|
74
70
|
#
|
|
75
|
-
#
|
|
71
|
+
# Prompts
|
|
76
72
|
#
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
type: stdio
|
|
86
|
-
command: uvx
|
|
87
|
-
args: ["awslabs.cloudwatch-mcp-server@latest"]
|
|
88
|
-
env:
|
|
89
|
-
AWS_PROFILE: "[The AWS Profile Name to use for AWS access]",
|
|
90
|
-
include: [search_logs, get_metrics] # No write access
|
|
73
|
+
prompts:
|
|
74
|
+
- name: changelog
|
|
75
|
+
title: changelog
|
|
76
|
+
description: ""
|
|
77
|
+
body: "write a short changelog based on recent changes on the
|
|
78
|
+
director-run/director repository and the post it to to the slack
|
|
79
|
+
#general channel. Make sure the message will format correctly inside
|
|
80
|
+
of slack"
|
|
91
81
|
|
|
92
|
-
|
|
82
|
+
#
|
|
83
|
+
# MCP Servers
|
|
84
|
+
#
|
|
85
|
+
servers:
|
|
86
|
+
# GitHub server
|
|
93
87
|
- name: github
|
|
94
88
|
type: http
|
|
95
89
|
url: https://api.githubcopilot.com/mcp/
|
|
90
|
+
headers:
|
|
91
|
+
Authorization: Bearer
|
|
92
|
+
<YOUR_GITHUB_TOKEN>
|
|
93
|
+
# This server is enabled
|
|
94
|
+
disabled: false
|
|
95
|
+
# Only include the tools you need
|
|
96
96
|
tools:
|
|
97
|
-
include:
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
97
|
+
include:
|
|
98
|
+
- list_commits
|
|
99
|
+
- search_pull_requests
|
|
100
|
+
- get_latest_release
|
|
101
|
+
# Prompts from MCP server are disabled by default
|
|
102
|
+
prompts:
|
|
103
|
+
include: []
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
- name: slack
|
|
107
|
+
type: stdio
|
|
108
|
+
command: npx
|
|
109
|
+
args:
|
|
110
|
+
- -y
|
|
111
|
+
- "@modelcontextprotocol/server-slack"
|
|
112
|
+
env:
|
|
113
|
+
SLACK_TEAM_ID: <YOUR_SLACK_TEAM_ID>
|
|
114
|
+
SLACK_BOT_TOKEN: <YOUR_SLACK_BOT_TOKEN>
|
|
115
|
+
SLACK_CHANNEL_IDS: <YOUR_SLACK_CHANNEL_ID>
|
|
116
|
+
# This server is enabled
|
|
117
|
+
disabled: false
|
|
118
|
+
# Only include the tools you need
|
|
119
|
+
tools:
|
|
120
|
+
include:
|
|
121
|
+
- slack_list_channels
|
|
122
|
+
- slack_post_message
|
|
123
|
+
# Prompts from MCP server are disabled by default
|
|
124
|
+
prompts:
|
|
125
|
+
include: []
|
|
106
126
|
```
|
|
107
127
|
|
|
108
128
|
## Architecture
|
|
109
129
|
|
|
110
130
|
At a high level, Director is a service that sits between your agents and MCP servers. It's transparent to clients, requiring no additional tokens. It models playbooks, which can be thought of as standalone, portable skills that enhance your AI agent with new capabilities.
|
|
111
131
|
|
|
112
|
-
<img src="https://github.com/director-run/director/blob/main/apps/docs/images/director-highlevel-overview.
|
|
132
|
+
<img src="https://github.com/director-run/director/blob/main/apps/docs/images/director-highlevel-overview.png" width="100%" alt="director demo">
|
|
113
133
|
|
|
114
134
|
# Usage
|
|
115
135
|
|
|
@@ -194,40 +214,75 @@ EXAMPLES
|
|
|
194
214
|
# Server config
|
|
195
215
|
#
|
|
196
216
|
server:
|
|
217
|
+
# Defaults to 3673
|
|
197
218
|
port: 1234
|
|
198
219
|
|
|
199
220
|
#
|
|
200
|
-
# Client
|
|
201
|
-
#
|
|
221
|
+
# Client <> Playbook mappings (enforced on startup)
|
|
222
|
+
#
|
|
202
223
|
clients:
|
|
203
|
-
|
|
224
|
+
cursor: [ demo ]
|
|
204
225
|
|
|
205
|
-
#
|
|
206
|
-
# Playbooks
|
|
207
|
-
#
|
|
208
226
|
playbooks:
|
|
209
|
-
-
|
|
210
|
-
|
|
227
|
+
- id: demo
|
|
228
|
+
name: demo
|
|
229
|
+
description: A demonstration playbook
|
|
230
|
+
#
|
|
231
|
+
# Prompts
|
|
232
|
+
#
|
|
233
|
+
prompts:
|
|
234
|
+
- name: changelog
|
|
235
|
+
title: changelog
|
|
236
|
+
description: ""
|
|
237
|
+
body: "write a short changelog based on recent changes on the
|
|
238
|
+
director-run/director repository and the post it to to the slack
|
|
239
|
+
#general channel. Make sure the message will format correctly inside
|
|
240
|
+
of slack"
|
|
241
|
+
|
|
242
|
+
#
|
|
243
|
+
# MCP Servers
|
|
244
|
+
#
|
|
211
245
|
servers:
|
|
212
|
-
|
|
213
|
-
type: stdio
|
|
214
|
-
command: npx
|
|
215
|
-
args: [ "@modelcontextprotocol/server-filesystem", "./src" ]
|
|
216
|
-
|
|
246
|
+
# GitHub server
|
|
217
247
|
- name: github
|
|
218
248
|
type: http
|
|
219
249
|
url: https://api.githubcopilot.com/mcp/
|
|
250
|
+
headers:
|
|
251
|
+
Authorization: Bearer
|
|
252
|
+
<YOUR_GITHUB_TOKEN>
|
|
253
|
+
# This server is enabled
|
|
254
|
+
disabled: false
|
|
255
|
+
# Only include the tools you need
|
|
220
256
|
tools:
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
257
|
+
include:
|
|
258
|
+
- list_commits
|
|
259
|
+
- search_pull_requests
|
|
260
|
+
- get_latest_release
|
|
261
|
+
# Prompts from MCP server are disabled by default
|
|
262
|
+
prompts:
|
|
263
|
+
include: []
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
- name: slack
|
|
267
|
+
type: stdio
|
|
268
|
+
command: npx
|
|
269
|
+
args:
|
|
270
|
+
- -y
|
|
271
|
+
- "@modelcontextprotocol/server-slack"
|
|
272
|
+
env:
|
|
273
|
+
SLACK_TEAM_ID: <YOUR_SLACK_TEAM_ID>
|
|
274
|
+
SLACK_BOT_TOKEN: <YOUR_SLACK_BOT_TOKEN>
|
|
275
|
+
SLACK_CHANNEL_IDS: <YOUR_SLACK_CHANNEL_ID>
|
|
276
|
+
# This server is enabled
|
|
277
|
+
disabled: false
|
|
278
|
+
# Only include the tools you need
|
|
279
|
+
tools:
|
|
280
|
+
include:
|
|
281
|
+
- slack_list_channels
|
|
282
|
+
- slack_post_message
|
|
283
|
+
# Prompts from MCP server are disabled by default
|
|
284
|
+
prompts:
|
|
285
|
+
include: []
|
|
231
286
|
```
|
|
232
287
|
|
|
233
288
|
### TypeScript SDK
|
|
@@ -235,24 +290,30 @@ playbooks:
|
|
|
235
290
|
Programmatic control for advanced use cases:
|
|
236
291
|
|
|
237
292
|
```typescript
|
|
238
|
-
import {
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
293
|
+
import { Gateway } from "@director.run/sdk";
|
|
294
|
+
|
|
295
|
+
// Start the gateway
|
|
296
|
+
const gateway = await Gateway.start({
|
|
297
|
+
config: await Config.createMemoryBasedConfig({
|
|
298
|
+
defaults: {
|
|
299
|
+
server: {
|
|
300
|
+
port: 3673,
|
|
301
|
+
},
|
|
302
|
+
},
|
|
303
|
+
}),
|
|
304
|
+
baseUrl: "http://localhost:3673",
|
|
250
305
|
});
|
|
251
306
|
|
|
252
|
-
//
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
307
|
+
// Add a new playbook
|
|
308
|
+
await gateway.playbookStore.create({
|
|
309
|
+
name: "test",
|
|
310
|
+
servers: [
|
|
311
|
+
{
|
|
312
|
+
name: "notion",
|
|
313
|
+
type: "http",
|
|
314
|
+
url: "https://mcp.notion.com/mcp",
|
|
315
|
+
},
|
|
316
|
+
],
|
|
256
317
|
});
|
|
257
318
|
```
|
|
258
319
|
|
package/dist/cli.js
CHANGED
|
@@ -591,7 +591,7 @@ Please see the 3.x to 4.x migration guide for details on how to update your app.
|
|
|
591
591
|
]))`;continue}else if(J[K]==="$"){Q+=`($|(?=[\r
|
|
592
592
|
]))`;continue}}if(w.s&&J[K]==="."){Q+=Y?`${J[K]}\r
|
|
593
593
|
`:`[${J[K]}\r
|
|
594
|
-
]`;continue}if(Q+=J[K],J[K]==="\\")X=!0;else if(Y&&J[K]==="]")Y=!1;else if(!Y&&J[K]==="[")Y=!0}try{new RegExp(Q)}catch{return console.warn(`Could not convert regex pattern at ${F.currentPath.join("/")} to a flag-independent form! Falling back to the flag-ignorant source`),D.source}return Q}function aH(D,F){if(F.target==="openAi")console.warn("Warning: OpenAI may not support records in schemas! Try an array of key-value pairs instead.");if(F.target==="openApi3"&&D.keyType?._def.typeName===G1.ZodEnum)return{type:"object",required:D.keyType._def.values,properties:D.keyType._def.values.reduce((J,Q)=>({...J,[Q]:f1(D.valueType._def,{...F,currentPath:[...F.currentPath,"properties",Q]})??X2(F)}),{}),additionalProperties:F.rejectedAdditionalProperties};let w={type:"object",additionalProperties:f1(D.valueType._def,{...F,currentPath:[...F.currentPath,"additionalProperties"]})??F.allowedAdditionalProperties};if(F.target==="openApi3")return w;if(D.keyType?._def.typeName===G1.ZodString&&D.keyType._def.checks?.length){let{type:J,...Q}=lH(D.keyType._def,F);return{...w,propertyNames:Q}}else if(D.keyType?._def.typeName===G1.ZodEnum)return{...w,propertyNames:{enum:D.keyType._def.values}};else if(D.keyType?._def.typeName===G1.ZodBranded&&D.keyType._def.type._def.typeName===G1.ZodString&&D.keyType._def.type._def.checks?.length){let{type:J,...Q}=cH(D.keyType._def,F);return{...w,propertyNames:Q}}return w}function Pb(D,F){if(F.mapStrategy==="record")return aH(D,F);let w=f1(D.keyType._def,{...F,currentPath:[...F.currentPath,"items","items","0"]})||X2(F),J=f1(D.valueType._def,{...F,currentPath:[...F.currentPath,"items","items","1"]})||X2(F);return{type:"array",maxItems:125,items:{type:"array",items:[w,J],minItems:2,maxItems:2}}}function Ob(D){let F=D.values,J=Object.keys(D.values).filter((X)=>{return typeof F[F[X]]!=="number"}).map((X)=>F[X]),Q=Array.from(new Set(J.map((X)=>typeof X)));return{type:Q.length===1?Q[0]==="string"?"string":"number":["string","number"],enum:J}}function Ab(D){return D.target==="openAi"?void 0:{not:X2({...D,currentPath:[...D.currentPath,"not"]})}}function vb(D){return D.target==="openApi3"?{enum:["null"],nullable:!0}:{type:"null"}}var qX={ZodString:"string",ZodNumber:"number",ZodBigInt:"integer",ZodBoolean:"boolean",ZodNull:"null"};function Rb(D,F){if(F.target==="openApi3")return Lb(D,F);let w=D.options instanceof Map?Array.from(D.options.values()):D.options;if(w.every((J)=>(J._def.typeName in qX)&&(!J._def.checks||!J._def.checks.length))){let J=w.reduce((Q,X)=>{let Y=qX[X._def.typeName];return Y&&!Q.includes(Y)?[...Q,Y]:Q},[]);return{type:J.length>1?J:J[0]}}else if(w.every((J)=>J._def.typeName==="ZodLiteral"&&!J.description)){let J=w.reduce((Q,X)=>{let Y=typeof X._def.value;switch(Y){case"string":case"number":case"boolean":return[...Q,Y];case"bigint":return[...Q,"integer"];case"object":if(X._def.value===null)return[...Q,"null"];case"symbol":case"undefined":case"function":default:return Q}},[]);if(J.length===w.length){let Q=J.filter((X,Y,W)=>W.indexOf(X)===Y);return{type:Q.length>1?Q:Q[0],enum:w.reduce((X,Y)=>{return X.includes(Y._def.value)?X:[...X,Y._def.value]},[])}}}else if(w.every((J)=>J._def.typeName==="ZodEnum"))return{type:"string",enum:w.reduce((J,Q)=>[...J,...Q._def.values.filter((X)=>!J.includes(X))],[])};return Lb(D,F)}var Lb=(D,F)=>{let w=(D.options instanceof Map?Array.from(D.options.values()):D.options).map((J,Q)=>f1(J._def,{...F,currentPath:[...F.currentPath,"anyOf",`${Q}`]})).filter((J)=>!!J&&(!F.strictUnions||typeof J==="object"&&Object.keys(J).length>0));return w.length?{anyOf:w}:void 0};function xb(D,F){if(["ZodString","ZodNumber","ZodBigInt","ZodBoolean","ZodNull"].includes(D.innerType._def.typeName)&&(!D.innerType._def.checks||!D.innerType._def.checks.length)){if(F.target==="openApi3")return{type:qX[D.innerType._def.typeName],nullable:!0};return{type:[qX[D.innerType._def.typeName],"null"]}}if(F.target==="openApi3"){let J=f1(D.innerType._def,{...F,currentPath:[...F.currentPath]});if(J&&"$ref"in J)return{allOf:[J],nullable:!0};return J&&{...J,nullable:!0}}let w=f1(D.innerType._def,{...F,currentPath:[...F.currentPath,"anyOf","0"]});return w&&{anyOf:[w,{type:"null"}]}}function Tb(D,F){let w={type:"number"};if(!D.checks)return w;for(let J of D.checks)switch(J.kind){case"int":w.type="integer",zM(w,"type",J.message,F);break;case"min":if(F.target==="jsonSchema7")if(J.inclusive)U0(w,"minimum",J.value,J.message,F);else U0(w,"exclusiveMinimum",J.value,J.message,F);else{if(!J.inclusive)w.exclusiveMinimum=!0;U0(w,"minimum",J.value,J.message,F)}break;case"max":if(F.target==="jsonSchema7")if(J.inclusive)U0(w,"maximum",J.value,J.message,F);else U0(w,"exclusiveMaximum",J.value,J.message,F);else{if(!J.inclusive)w.exclusiveMaximum=!0;U0(w,"maximum",J.value,J.message,F)}break;case"multipleOf":U0(w,"multipleOf",J.value,J.message,F);break}return w}function _b(D,F){let w=F.target==="openAi",J={type:"object",properties:{}},Q=[],X=D.shape();for(let W in X){let K=X[W];if(K===void 0||K._def===void 0)continue;let V=Mx1(K);if(V&&w){if(K._def.typeName==="ZodOptional")K=K._def.innerType;if(!K.isNullable())K=K.nullable();V=!1}let B=f1(K._def,{...F,currentPath:[...F.currentPath,"properties",W],propertyPath:[...F.currentPath,"properties",W]});if(B===void 0)continue;if(J.properties[W]=B,!V)Q.push(W)}if(Q.length)J.required=Q;let Y=$x1(D,F);if(Y!==void 0)J.additionalProperties=Y;return J}function $x1(D,F){if(D.catchall._def.typeName!=="ZodNever")return f1(D.catchall._def,{...F,currentPath:[...F.currentPath,"additionalProperties"]});switch(D.unknownKeys){case"passthrough":return F.allowedAdditionalProperties;case"strict":return F.rejectedAdditionalProperties;case"strip":return F.removeAdditionalStrategy==="strict"?F.allowedAdditionalProperties:F.rejectedAdditionalProperties}}function Mx1(D){try{return D.isOptional()}catch{return!0}}var Cb=(D,F)=>{if(F.currentPath.toString()===F.propertyPath?.toString())return f1(D.innerType._def,F);let w=f1(D.innerType._def,{...F,currentPath:[...F.currentPath,"anyOf","1"]});return w?{anyOf:[{not:X2(F)},w]}:X2(F)};var Ib=(D,F)=>{if(F.pipeStrategy==="input")return f1(D.in._def,F);else if(F.pipeStrategy==="output")return f1(D.out._def,F);let w=f1(D.in._def,{...F,currentPath:[...F.currentPath,"allOf","0"]}),J=f1(D.out._def,{...F,currentPath:[...F.currentPath,"allOf",w?"1":"0"]});return{allOf:[w,J].filter((Q)=>Q!==void 0)}};function fb(D,F){return f1(D.type._def,F)}function Sb(D,F){let J={type:"array",uniqueItems:!0,items:f1(D.valueType._def,{...F,currentPath:[...F.currentPath,"items"]})};if(D.minSize)U0(J,"minItems",D.minSize.value,D.minSize.message,F);if(D.maxSize)U0(J,"maxItems",D.maxSize.value,D.maxSize.message,F);return J}function jb(D,F){if(D.rest)return{type:"array",minItems:D.items.length,items:D.items.map((w,J)=>f1(w._def,{...F,currentPath:[...F.currentPath,"items",`${J}`]})).reduce((w,J)=>J===void 0?w:[...w,J],[]),additionalItems:f1(D.rest._def,{...F,currentPath:[...F.currentPath,"additionalItems"]})};else return{type:"array",minItems:D.items.length,maxItems:D.items.length,items:D.items.map((w,J)=>f1(w._def,{...F,currentPath:[...F.currentPath,"items",`${J}`]})).reduce((w,J)=>J===void 0?w:[...w,J],[])}}function mb(D){return{not:X2(D)}}function db(D){return X2(D)}var ub=(D,F)=>{return f1(D.innerType._def,F)};var kb=(D,F,w)=>{switch(F){case G1.ZodString:return lH(D,w);case G1.ZodNumber:return Tb(D,w);case G1.ZodObject:return _b(D,w);case G1.ZodBigInt:return pb(D,w);case G1.ZodBoolean:return Zb();case G1.ZodDate:return qM(D,w);case G1.ZodUndefined:return mb(w);case G1.ZodNull:return vb(w);case G1.ZodArray:return Gb(D,w);case G1.ZodUnion:case G1.ZodDiscriminatedUnion:return Rb(D,w);case G1.ZodIntersection:return $b(D,w);case G1.ZodTuple:return jb(D,w);case G1.ZodRecord:return aH(D,w);case G1.ZodLiteral:return Mb(D,w);case G1.ZodEnum:return qb(D);case G1.ZodNativeEnum:return Ob(D);case G1.ZodNullable:return xb(D,w);case G1.ZodOptional:return Cb(D,w);case G1.ZodMap:return Pb(D,w);case G1.ZodSet:return Sb(D,w);case G1.ZodLazy:return()=>D.getter()._def;case G1.ZodPromise:return fb(D,w);case G1.ZodNaN:case G1.ZodNever:return Ab(w);case G1.ZodEffects:return zb(D,w);case G1.ZodAny:return X2(w);case G1.ZodUnknown:return db(w);case G1.ZodDefault:return Ub(D,w);case G1.ZodBranded:return cH(D,w);case G1.ZodReadonly:return ub(D,w);case G1.ZodCatch:return Nb(D,w);case G1.ZodPipeline:return Ib(D,w);case G1.ZodFunction:case G1.ZodVoid:case G1.ZodSymbol:return;default:return((J)=>{return})(F)}};function f1(D,F,w=!1){let J=F.seen.get(D);if(F.override){let W=F.override?.(D,F,J,w);if(W!==Vb)return W}if(J&&!w){let W=Ex1(J,F);if(W!==void 0)return W}let Q={def:D,path:F.currentPath,jsonSchema:void 0};F.seen.set(D,Q);let X=kb(D,D.typeName,F),Y=typeof X==="function"?f1(X(),F):X;if(Y)Px1(D,F,Y);if(F.postProcess){let W=F.postProcess(Y,D,F);return Q.jsonSchema=Y,W}return Q.jsonSchema=Y,Y}var Ex1=(D,F)=>{switch(F.$refStrategy){case"root":return{$ref:D.path.join("/")};case"relative":return{$ref:gH(F.currentPath,D.path)};case"none":case"seen":{if(D.path.length<F.currentPath.length&&D.path.every((w,J)=>F.currentPath[J]===w))return console.warn(`Recursive reference detected at ${F.currentPath.join("/")}! Defaulting to any`),X2(F);return F.$refStrategy==="seen"?X2(F):void 0}}},Px1=(D,F,w)=>{if(D.description){if(w.description=D.description,F.markdownDescription)w.markdownDescription=D.description}return w};var iH=(D,F)=>{let w=Bb(F),J=typeof F==="object"&&F.definitions?Object.entries(F.definitions).reduce((K,[V,B])=>({...K,[V]:f1(B._def,{...w,currentPath:[...w.basePath,w.definitionPath,V]},!0)??X2(w)}),{}):void 0,Q=typeof F==="string"?F:F?.nameStrategy==="title"?void 0:F?.name,X=f1(D._def,Q===void 0?w:{...w,currentPath:[...w.basePath,w.definitionPath,Q]},!1)??X2(w),Y=typeof F==="object"&&F.name!==void 0&&F.nameStrategy==="title"?F.name:void 0;if(Y!==void 0)X.title=Y;if(w.flags.hasReferencedOpenAiAnyType){if(!J)J={};if(!J[w.openAiAnyTypeName])J[w.openAiAnyTypeName]={type:["string","number","integer","boolean","array","null"],items:{$ref:w.$refStrategy==="relative"?"1":[...w.basePath,w.definitionPath,w.openAiAnyTypeName].join("/")}}}let W=Q===void 0?J?{...X,[w.definitionPath]:J}:X:{$ref:[...w.$refStrategy==="relative"?[]:w.basePath,w.definitionPath,Q].join("/"),[w.definitionPath]:{...J,[Q]:X}};if(w.target==="jsonSchema7")W.$schema="http://json-schema.org/draft-07/schema#";else if(w.target==="jsonSchema2019-09"||w.target==="openAi")W.$schema="https://json-schema.org/draft/2019-09/schema#";if(w.target==="openAi"&&(("anyOf"in W)||("oneOf"in W)||("allOf"in W)||("type"in W)&&Array.isArray(W.type)))console.warn("Warning: OpenAI may not support schemas with unions as roots! Try wrapping it in an object property.");return W};var EM;(function(D){D.Completable="McpCompletable"})(EM||(EM={}));class $X extends s1{_parse(D){let{ctx:F}=this._processInputParams(D),w=F.data;return this._def.type._parse({data:w,path:F.path,parent:F})}unwrap(){return this._def.type}}$X.create=(D,F)=>{return new $X({type:D,typeName:EM.Completable,complete:F.complete,...Ox1(F)})};function Ox1(D){if(!D)return{};let{errorMap:F,invalid_type_error:w,required_error:J,description:Q}=D;if(F&&(w||J))throw Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);if(F)return{errorMap:F,description:Q};return{errorMap:(Y,W)=>{var K,V;let{message:B}=D;if(Y.code==="invalid_enum_value")return{message:B!==null&&B!==void 0?B:W.defaultError};if(typeof W.data>"u")return{message:(K=B!==null&&B!==void 0?B:J)!==null&&K!==void 0?K:W.defaultError};if(Y.code!=="invalid_type")return{message:W.defaultError};return{message:(V=B!==null&&B!==void 0?B:w)!==null&&V!==void 0?V:W.defaultError}},description:Q}}class PM{constructor(D,F){this._registeredResources={},this._registeredResourceTemplates={},this._registeredTools={},this._registeredPrompts={},this._toolHandlersInitialized=!1,this._completionHandlerInitialized=!1,this._resourceHandlersInitialized=!1,this._promptHandlersInitialized=!1,this.server=new zX(D,F)}async connect(D){return await this.server.connect(D)}async close(){await this.server.close()}setToolRequestHandlers(){if(this._toolHandlersInitialized)return;this.server.assertCanSetRequestHandler(eF.shape.method.value),this.server.assertCanSetRequestHandler(Dw.shape.method.value),this.server.registerCapabilities({tools:{listChanged:!0}}),this.server.setRequestHandler(eF,()=>({tools:Object.entries(this._registeredTools).filter(([,D])=>D.enabled).map(([D,F])=>{let w={name:D,title:F.title,description:F.description,inputSchema:F.inputSchema?iH(F.inputSchema,{strictUnions:!0}):Ax1,annotations:F.annotations,_meta:F._meta};if(F.outputSchema)w.outputSchema=iH(F.outputSchema,{strictUnions:!0});return w})})),this.server.setRequestHandler(Dw,async(D,F)=>{let w=this._registeredTools[D.params.name];if(!w)throw new S1(j1.InvalidParams,`Tool ${D.params.name} not found`);if(!w.enabled)throw new S1(j1.InvalidParams,`Tool ${D.params.name} disabled`);let J;if(w.inputSchema){let Q=await w.inputSchema.safeParseAsync(D.params.arguments);if(!Q.success)throw new S1(j1.InvalidParams,`Invalid arguments for tool ${D.params.name}: ${Q.error.message}`);let X=Q.data,Y=w.callback;try{J=await Promise.resolve(Y(X,F))}catch(W){J={content:[{type:"text",text:W instanceof Error?W.message:String(W)}],isError:!0}}}else{let Q=w.callback;try{J=await Promise.resolve(Q(F))}catch(X){J={content:[{type:"text",text:X instanceof Error?X.message:String(X)}],isError:!0}}}if(w.outputSchema&&!J.isError){if(!J.structuredContent)throw new S1(j1.InvalidParams,`Tool ${D.params.name} has an output schema but no structured content was provided`);let Q=await w.outputSchema.safeParseAsync(J.structuredContent);if(!Q.success)throw new S1(j1.InvalidParams,`Invalid structured content for tool ${D.params.name}: ${Q.error.message}`)}return J}),this._toolHandlersInitialized=!0}setCompletionRequestHandler(){if(this._completionHandlerInitialized)return;this.server.assertCanSetRequestHandler(wH.shape.method.value),this.server.registerCapabilities({completions:{}}),this.server.setRequestHandler(wH,async(D)=>{switch(D.params.ref.type){case"ref/prompt":return this.handlePromptCompletion(D,D.params.ref);case"ref/resource":return this.handleResourceCompletion(D,D.params.ref);default:throw new S1(j1.InvalidParams,`Invalid completion reference: ${D.params.ref}`)}}),this._completionHandlerInitialized=!0}async handlePromptCompletion(D,F){let w=this._registeredPrompts[F.name];if(!w)throw new S1(j1.InvalidParams,`Prompt ${F.name} not found`);if(!w.enabled)throw new S1(j1.InvalidParams,`Prompt ${F.name} disabled`);if(!w.argsSchema)return nH;let J=w.argsSchema.shape[D.params.argument.name];if(!(J instanceof $X))return nH;let X=await J._def.complete(D.params.argument.value,D.params.context);return hb(X)}async handleResourceCompletion(D,F){let w=Object.values(this._registeredResourceTemplates).find((X)=>X.resourceTemplate.uriTemplate.toString()===F.uri);if(!w){if(this._registeredResources[F.uri])return nH;throw new S1(j1.InvalidParams,`Resource template ${D.params.ref.uri} not found`)}let J=w.resourceTemplate.completeCallback(D.params.argument.name);if(!J)return nH;let Q=await J(D.params.argument.value,D.params.context);return hb(Q)}setResourceRequestHandlers(){if(this._resourceHandlersInitialized)return;this.server.assertCanSetRequestHandler(nF.shape.method.value),this.server.assertCanSetRequestHandler(sF.shape.method.value),this.server.assertCanSetRequestHandler(oF.shape.method.value),this.server.registerCapabilities({resources:{listChanged:!0}}),this.server.setRequestHandler(nF,async(D,F)=>{let w=Object.entries(this._registeredResources).filter(([Q,X])=>X.enabled).map(([Q,X])=>({uri:Q,name:X.name,...X.metadata})),J=[];for(let Q of Object.values(this._registeredResourceTemplates)){if(!Q.resourceTemplate.listCallback)continue;let X=await Q.resourceTemplate.listCallback(F);for(let Y of X.resources)J.push({...Q.metadata,...Y})}return{resources:[...w,...J]}}),this.server.setRequestHandler(sF,async()=>{return{resourceTemplates:Object.entries(this._registeredResourceTemplates).map(([F,w])=>({name:F,uriTemplate:w.resourceTemplate.uriTemplate.toString(),...w.metadata}))}}),this.server.setRequestHandler(oF,async(D,F)=>{let w=new URL(D.params.uri),J=this._registeredResources[w.toString()];if(J){if(!J.enabled)throw new S1(j1.InvalidParams,`Resource ${w} disabled`);return J.readCallback(w,F)}for(let Q of Object.values(this._registeredResourceTemplates)){let X=Q.resourceTemplate.uriTemplate.match(w.toString());if(X)return Q.readCallback(w,X,F)}throw new S1(j1.InvalidParams,`Resource ${w} not found`)}),this.setCompletionRequestHandler(),this._resourceHandlersInitialized=!0}setPromptRequestHandlers(){if(this._promptHandlersInitialized)return;this.server.assertCanSetRequestHandler(rF.shape.method.value),this.server.assertCanSetRequestHandler(tF.shape.method.value),this.server.registerCapabilities({prompts:{listChanged:!0}}),this.server.setRequestHandler(rF,()=>({prompts:Object.entries(this._registeredPrompts).filter(([,D])=>D.enabled).map(([D,F])=>{return{name:D,title:F.title,description:F.description,arguments:F.argsSchema?Lx1(F.argsSchema):void 0}})})),this.server.setRequestHandler(tF,async(D,F)=>{let w=this._registeredPrompts[D.params.name];if(!w)throw new S1(j1.InvalidParams,`Prompt ${D.params.name} not found`);if(!w.enabled)throw new S1(j1.InvalidParams,`Prompt ${D.params.name} disabled`);if(w.argsSchema){let J=await w.argsSchema.safeParseAsync(D.params.arguments);if(!J.success)throw new S1(j1.InvalidParams,`Invalid arguments for prompt ${D.params.name}: ${J.error.message}`);let Q=J.data,X=w.callback;return await Promise.resolve(X(Q,F))}else{let J=w.callback;return await Promise.resolve(J(F))}}),this.setCompletionRequestHandler(),this._promptHandlersInitialized=!0}resource(D,F,...w){let J;if(typeof w[0]==="object")J=w.shift();let Q=w[0];if(typeof F==="string"){if(this._registeredResources[F])throw Error(`Resource ${F} is already registered`);let X=this._createRegisteredResource(D,void 0,F,J,Q);return this.setResourceRequestHandlers(),this.sendResourceListChanged(),X}else{if(this._registeredResourceTemplates[D])throw Error(`Resource template ${D} is already registered`);let X=this._createRegisteredResourceTemplate(D,void 0,F,J,Q);return this.setResourceRequestHandlers(),this.sendResourceListChanged(),X}}registerResource(D,F,w,J){if(typeof F==="string"){if(this._registeredResources[F])throw Error(`Resource ${F} is already registered`);let Q=this._createRegisteredResource(D,w.title,F,w,J);return this.setResourceRequestHandlers(),this.sendResourceListChanged(),Q}else{if(this._registeredResourceTemplates[D])throw Error(`Resource template ${D} is already registered`);let Q=this._createRegisteredResourceTemplate(D,w.title,F,w,J);return this.setResourceRequestHandlers(),this.sendResourceListChanged(),Q}}_createRegisteredResource(D,F,w,J,Q){let X={name:D,title:F,metadata:J,readCallback:Q,enabled:!0,disable:()=>X.update({enabled:!1}),enable:()=>X.update({enabled:!0}),remove:()=>X.update({uri:null}),update:(Y)=>{if(typeof Y.uri<"u"&&Y.uri!==w){if(delete this._registeredResources[w],Y.uri)this._registeredResources[Y.uri]=X}if(typeof Y.name<"u")X.name=Y.name;if(typeof Y.title<"u")X.title=Y.title;if(typeof Y.metadata<"u")X.metadata=Y.metadata;if(typeof Y.callback<"u")X.readCallback=Y.callback;if(typeof Y.enabled<"u")X.enabled=Y.enabled;this.sendResourceListChanged()}};return this._registeredResources[w]=X,X}_createRegisteredResourceTemplate(D,F,w,J,Q){let X={resourceTemplate:w,title:F,metadata:J,readCallback:Q,enabled:!0,disable:()=>X.update({enabled:!1}),enable:()=>X.update({enabled:!0}),remove:()=>X.update({name:null}),update:(Y)=>{if(typeof Y.name<"u"&&Y.name!==D){if(delete this._registeredResourceTemplates[D],Y.name)this._registeredResourceTemplates[Y.name]=X}if(typeof Y.title<"u")X.title=Y.title;if(typeof Y.template<"u")X.resourceTemplate=Y.template;if(typeof Y.metadata<"u")X.metadata=Y.metadata;if(typeof Y.callback<"u")X.readCallback=Y.callback;if(typeof Y.enabled<"u")X.enabled=Y.enabled;this.sendResourceListChanged()}};return this._registeredResourceTemplates[D]=X,X}_createRegisteredPrompt(D,F,w,J,Q){let X={title:F,description:w,argsSchema:J===void 0?void 0:M.object(J),callback:Q,enabled:!0,disable:()=>X.update({enabled:!1}),enable:()=>X.update({enabled:!0}),remove:()=>X.update({name:null}),update:(Y)=>{if(typeof Y.name<"u"&&Y.name!==D){if(delete this._registeredPrompts[D],Y.name)this._registeredPrompts[Y.name]=X}if(typeof Y.title<"u")X.title=Y.title;if(typeof Y.description<"u")X.description=Y.description;if(typeof Y.argsSchema<"u")X.argsSchema=M.object(Y.argsSchema);if(typeof Y.callback<"u")X.callback=Y.callback;if(typeof Y.enabled<"u")X.enabled=Y.enabled;this.sendPromptListChanged()}};return this._registeredPrompts[D]=X,X}_createRegisteredTool(D,F,w,J,Q,X,Y,W){let K={title:F,description:w,inputSchema:J===void 0?void 0:M.object(J),outputSchema:Q===void 0?void 0:M.object(Q),annotations:X,_meta:Y,callback:W,enabled:!0,disable:()=>K.update({enabled:!1}),enable:()=>K.update({enabled:!0}),remove:()=>K.update({name:null}),update:(V)=>{if(typeof V.name<"u"&&V.name!==D){if(delete this._registeredTools[D],V.name)this._registeredTools[V.name]=K}if(typeof V.title<"u")K.title=V.title;if(typeof V.description<"u")K.description=V.description;if(typeof V.paramsSchema<"u")K.inputSchema=M.object(V.paramsSchema);if(typeof V.callback<"u")K.callback=V.callback;if(typeof V.annotations<"u")K.annotations=V.annotations;if(typeof V._meta<"u")K._meta=V._meta;if(typeof V.enabled<"u")K.enabled=V.enabled;this.sendToolListChanged()}};return this._registeredTools[D]=K,this.setToolRequestHandlers(),this.sendToolListChanged(),K}tool(D,...F){if(this._registeredTools[D])throw Error(`Tool ${D} is already registered`);let w,J,Q,X;if(typeof F[0]==="string")w=F.shift();if(F.length>1){let W=F[0];if(bb(W)){if(J=F.shift(),F.length>1&&typeof F[0]==="object"&&F[0]!==null&&!bb(F[0]))X=F.shift()}else if(typeof W==="object"&&W!==null)X=F.shift()}let Y=F[0];return this._createRegisteredTool(D,void 0,w,J,Q,X,void 0,Y)}registerTool(D,F,w){if(this._registeredTools[D])throw Error(`Tool ${D} is already registered`);let{title:J,description:Q,inputSchema:X,outputSchema:Y,annotations:W,_meta:K}=F;return this._createRegisteredTool(D,J,Q,X,Y,W,K,w)}prompt(D,...F){if(this._registeredPrompts[D])throw Error(`Prompt ${D} is already registered`);let w;if(typeof F[0]==="string")w=F.shift();let J;if(F.length>1)J=F.shift();let Q=F[0],X=this._createRegisteredPrompt(D,void 0,w,J,Q);return this.setPromptRequestHandlers(),this.sendPromptListChanged(),X}registerPrompt(D,F,w){if(this._registeredPrompts[D])throw Error(`Prompt ${D} is already registered`);let{title:J,description:Q,argsSchema:X}=F,Y=this._createRegisteredPrompt(D,J,Q,X,w);return this.setPromptRequestHandlers(),this.sendPromptListChanged(),Y}isConnected(){return this.server.transport!==void 0}async sendLoggingMessage(D,F){return this.server.sendLoggingMessage(D,F)}sendResourceListChanged(){if(this.isConnected())this.server.sendResourceListChanged()}sendToolListChanged(){if(this.isConnected())this.server.sendToolListChanged()}sendPromptListChanged(){if(this.isConnected())this.server.sendPromptListChanged()}}var Ax1={type:"object",properties:{}};function bb(D){if(typeof D!=="object"||D===null)return!1;return Object.keys(D).length===0||Object.values(D).some(vx1)}function vx1(D){return D!==null&&typeof D==="object"&&"parse"in D&&typeof D.parse==="function"&&"safeParse"in D&&typeof D.safeParse==="function"}function Lx1(D){return Object.entries(D.shape).map(([F,w])=>({name:F,description:w.description,required:!w.isOptional()}))}function hb(D){return{completion:{values:D.slice(0,100),total:D.length,hasMore:D.length>100}}}var nH={completion:{values:[],hasMore:!1}};var OM=A1(p3(),1);var Zw="__prompts__",AM=M.object({name:p4,title:p4,description:M.string().trim().optional(),body:p4}),Vq0=M.object({prompts:M.array(AM).optional()});class vM extends yH{_promptList;constructor(D=[]){super({name:Zw},{server:yb(OM.default.cloneDeep(D))});this._promptList=OM.default.cloneDeep(D)}get promptList(){return this._promptList}async addPromptEntry(D){if(this._promptList.find((w)=>w.name===D.name))throw new p1("DUPLICATE",`Prompt ${D.name} already exists`);return this._promptList.push(D),await this.reconnectToServer(),D}async updatePrompt(D,F){let w=this._promptList.findIndex((J)=>J.name===D);if(w===-1)throw new p1("NOT_FOUND",`Prompt ${D} not found`);return this._promptList[w]={...this._promptList[w],...F},await this.reconnectToServer(),this._promptList[w]}async removePromptEntry(D){let F=this._promptList.findIndex((w)=>w.name===D);if(F===-1)throw new p1("NOT_FOUND",`Prompt ${D} not found`);this._promptList.splice(F,1),await this.reconnectToServer()}getPromptEntry(D){let F=this._promptList.find((w)=>w.name===D);if(!F)throw new p1("NOT_FOUND",`Prompt ${D} not found`);return F}async reconnectToServer(){await this.close(),await this.server.close(),this.server=yb(this._promptList),await this.connectToTarget({throwOnError:!0})}}function yb(D){let F=new PM({name:"prompt-manager",version:"1.0.0"},{capabilities:{logging:{}}});for(let w of D)F.registerPrompt(w.name,{title:w.title,description:w.description},async()=>{return await{messages:[{role:"user",content:{type:"text",text:w.body}}]}});return F.server}var gb=Uk.extend({type:M.literal("http")}),cb=Yb.extend({type:M.literal("stdio")}),lb=M.union([gb,cb]),LM=M.object({id:p4,name:p4,description:um,prompts:M.array(AM).optional(),servers:M.array(lb)});var g2=A1(p3(),1);class RM{schema;storage;defaults;constructor(D){this.schema=D.schema,this.storage=D.storage,this.defaults=D.defaults??{}}get data(){return this.storage.getData()}async init(){await this.storage.init(),this.validate({...this.defaults,...this.storage.getData()})}async set(D,F){if(!(D in this.schema))throw new p1("INVALID_ARGUMENT",`Key "${D}" is not allowed`,{key:D});let J=this.schema[D].parse(F),Q=this.storage.getData();g2.set(Q,D,J),this.storage.setData(Q),await this.storage.persist()}get(D){if(!(D in this.schema))throw new p1("INVALID_ARGUMENT",`Key "${D}" is not allowed`,{key:D});let F=g2.get({...this.defaults,...this.storage.getData()},D);if(F!==void 0)return F;let J=this.schema[D].safeParse(void 0);if(J.success)return J.data;return}async purge(){await this.storage.purge()}async push(D,F){if(!(D in this.schema))throw new p1("INVALID_ARGUMENT",`Key "${D}" is not allowed`,{key:D});let w=this.schema[D],J=this.unwrapArraySchema(w);if(!J)throw new p1("INVALID_ARGUMENT",`Key "${D}" is not an array`,{key:D});let Q=J.element.parse(F),X=this.storage.getData(),W=[...g2.get({...this.defaults,...X},D)??[],Q];g2.set(X,D,W),this.storage.setData(X),await this.storage.persist()}async remove(D,F){if(!(D in this.schema))throw new p1("INVALID_ARGUMENT",`Key "${D}" is not allowed`,{key:D});let w=this.schema[D];if(!this.unwrapArraySchema(w))throw new p1("INVALID_ARGUMENT",`Key "${D}" is not an array`,{key:D});let Q=this.storage.getData(),W=[...g2.get({...this.defaults,...Q},D)??[]].filter((K)=>{if(!g2.isObject(K)||K===null)return!g2.isEqual(K,F);return!g2.isMatch(K,F)});g2.set(Q,D,W),this.storage.setData(Q),await this.storage.persist()}find(D,F){if(!(D in this.schema))throw new p1("INVALID_ARGUMENT",`Key "${D}" is not allowed`,{key:D});let w=this.schema[D];if(!this.unwrapArraySchema(w))throw new p1("INVALID_ARGUMENT",`Key "${D}" is not an array`,{key:D});let Q=this.storage.getData();return[...g2.get({...this.defaults,...Q},D)??[]].find((K)=>{if(!g2.isObject(K)||K===null)return g2.isEqual(K,F);return g2.isMatch(K,F)})}unwrapArraySchema(D){while(!0){if(D instanceof M.ZodArray)return D;if(D instanceof M.ZodDefault){D=D._def.innerType;continue}if(D instanceof M.ZodOptional||D instanceof M.ZodNullable){D=D._def.innerType;continue}if(D instanceof M.ZodEffects){D=D._def.schema;continue}return null}}validate(D){let F={...this.defaults,...D};for(let w in this.schema){let J=g2.get(F,w),Q=this.schema[w];try{Q.parse(J)}catch(X){throw new p1("INVALID_CONFIGURATION",`Invalid data for key "${w}": ${X instanceof Error?X.message:String(X)}`,{key:w,value:J})}}}}var mB=A1(Dg(),1);import Fg from"fs";import{existsSync as Ld1}from"node:fs";class kE{data;constructor(D){this.data={...D?.data}}init(){return Promise.resolve()}persist(){return Promise.resolve()}purge(){return this.data={},Promise.resolve()}getData(){return structuredClone(this.data)}setData(D){this.data=structuredClone(D)}toPlainObject(){return{type:"in-memory",data:this.data}}}class bE{filePath;data={};constructor(D){if(!D.filePath)throw Error("Config filePath is not defined");this.filePath=D.filePath}async init(){if(Ld1(this.filePath)){let D=await Fg.promises.readFile(this.filePath,"utf8"),F=mB.default.parse(D);this.data=F&&typeof F==="object"&&!Array.isArray(F)?F:{}}}async persist(){let F=this.filePath.endsWith(".json")?JSON.stringify(this.data):mB.default.stringify(this.data);await Fg.promises.writeFile(this.filePath,F)}async purge(){this.data={},await this.persist()}getData(){return structuredClone(this.data)}setData(D){this.data=structuredClone(D)}toPlainObject(){return{type:"yaml",path:this.filePath,data:this.data}}}class cX extends RM{playbooks;constructor(D){super({schema:Rd1,storage:D.storage,defaults:D.defaults});this.playbooks=new Qg(this)}static async createFileBasedConfig(D){let F=new cX({storage:new bE({filePath:D.filePath}),defaults:D.defaults});return await F.init(),F}static async createMemoryBasedConfig(D){let F=new cX({storage:new kE,defaults:D.defaults});return await F.init(),F}toPlainObject(){return{defaults:this.defaults,storage:this.storage.toPlainObject()}}prettyPrint(){console.log("*************************************************"),console.log(),console.log(g0("STORAGE")),console.log(JSON.stringify(dB.default.omit(this.storage.toPlainObject(),"data"),null,2)),console.log(),console.log(g0("DEFAULTS")),console.log(JSON.stringify(this.defaults,null,2)),console.log(),console.log("*************************************************")}}class Qg{config;constructor(D){this.config=D}async create(D){let F=wg(D.name);if(await this.config.find("playbooks",{id:F}))throw new p1("DUPLICATE","Playbook with this name already exists");let w={id:F,...D,servers:dB.default.map(D.servers||[],(J)=>({...J,name:wg(J.name)}))};return await this.config.push("playbooks",w),w}async getPlaybook(D){let F=await this.all(),w=dB.default.find(F,{id:D});if(!w)throw Error("Playbook not found");return w}async update(D,F){if(F.id!==D)throw Error("Id mismatch");return await this.config.remove("playbooks",{id:D}),await this.config.push("playbooks",F),F}async remove(D){await this.config.remove("playbooks",{id:D})}async count(){return(await this.all()).length}async all(){return await this.config.get("playbooks")||[]}}function wg(D){return Jg.default(D,{lower:!0,strict:!0,trim:!0})}var Rd1={version:M.string().default("1.0.0"),playbooks:M.array(LM).default([]),debug:M.boolean().default(!1),"server.port":M.number().min(0),"registry.url":M.string(),"registry.apiKey":M.string().optional(),"telemetry.writeKey":M.string(),"telemetry.enabled":M.boolean(),"oauth.storage":M.literal("disk").or(M.literal("memory")).default("disk"),"oauth.tokenDirectory":M.string().default("./tokens"),"clients.claude":M.array(M.string()).default([]),"clients.claude-code":M.array(M.string()).default([]),"clients.cursor":M.array(M.string()).default([]),"clients.vscode":M.array(M.string()).default([])};import xd1 from"fs";function uB(D){for(let F of D)try{if(xd1.existsSync(F))return F}catch{continue}return}var xr=A1(Lr(),1),Tr=A1(Rr(),1);import SO from"os";class cw{analytics;machineId;enabled;traits;constructor(D){this.analytics=new xr.Analytics({writeKey:D.writeKey}),this.enabled=D.enabled,this.traits=D.traits||{}}async initialize(){if(this.machineId)return;if(this.machineId=await Tr.machineId(),this.enabled)this.analytics.identify({userId:this.machineId,traits:{...this.traits,os:SO.platform(),osVersion:SO.release(),arch:SO.arch()}})}static noTelemetry(){return new cw({writeKey:"--",enabled:!1})}async trackEvent(D,F={}){if(await this.initialize(),this.enabled)this.analytics.track({userId:this.machineId,event:D,properties:F})}}var C6={name:"@director.run/cli",type:"module",version:"1.0.1",files:["dist","README.md","package.json"],bin:{director:"./dist/cli.js"},author:"Barnaby Malet <barnaby@director.run>",license:"AGPL-3.0",repository:{type:"git",url:"https://github.com/director-run/director"},description:"Playbooks for AI agents",homepage:"https://director.run",publishConfig:{access:"public"},scripts:{lint:"biome check .",format:"biome format --write .",clean:"rm -rf .turbo dist/*",test:"bun run vitest --fileParallelism=false",cli:"LOG_LEVEL=debug NODE_ENV=development bun run bin/cli.ts","cli:dev":"NODE_ENV=development bun --watch bin/cli.ts",typecheck:"tsc --noEmit",build:"bun run clean && bun build --production --target=node bin/cli.ts --outdir dist && cp -r ../studio/dist dist/studio",release:"changeset publish",dev:"bun --watch bin/cli.ts",spellcheck:'cspell "**"'},peerDependencies:{typescript:"^5"},devDependencies:{"@director.run/gateway":"workspace:*","@director.run/client-configurator":"workspace:*","@director.run/mcp":"workspace:*","@director.run/registry":"workspace:*","@director.run/utilities":"workspace:*","@inquirer/prompts":"^7.5.2","@modelcontextprotocol/sdk":"1.20.0","@segment/analytics-node":"^2.3.0","@trpc/server":"^11.0.2","@types/semver":"^7.5.8","@types/update-notifier":"^6.0.8",boxen:"^8.0.1",chalk:"^5.4.1","cli-table3":"^0.6.5",commander:"^13.1.0","node-machine-id":"^1.1.12",semver:"^7.7.2",superjson:"^2.2.2","type-fest":"^4.40.0",typescript:"^5.8.3","update-notifier":"^7.3.1",vitest:"^3.1.1",zod:"^3.25.76",zx:"^8.8.0",cspell:"^9.2.2"}};var __dirname="/home/runner/work/director/director/apps/cli/src",Ts1="Z8wjEfWMFnlltCpGPPWlvsEQH1aVEUH3";function KD(){if(t6())return WD.join(__dirname,"../../../director.config.test.yaml");else if(aF())return WD.join(__dirname,"../../../director.config.development.yaml");else{let D=WD.join(xs1.homedir(),".director/director.config.yaml"),F=WD.join(process.cwd(),"director.config.yaml");return uB([F,D])??D}}function _s1(){if(t6())return{storage:"memory"};else return{storage:"disk",tokenDirectory:WD.join(WD.dirname(KD()),".secrets/director-oauth-tokens")}}var Cs1=WD.dirname(KD());await Rs1.mkdir(Cs1,{recursive:!0});var n4=await cX.createFileBasedConfig({filePath:KD(),defaults:{debug:aF(),registry:{url:"https://registry.director.run"},server:{port:t6()?3675:parseInt(process.env.GATEWAY_PORT??"3673")},telemetry:{writeKey:oq()?Ts1:"--",enabled:oq()},oauth:_s1()}});function a2(){return`http://localhost:${n4.get("server.port")}`}function jO(){return`${a2()}/studio`}function _r(){return new cw({writeKey:n4.get("telemetry.writeKey")??"--",enabled:!!n4.get("telemetry.enabled"),traits:{cliVersion:C6.version}})}var ir=A1(ar(),1),{program:IO0,createCommand:fO0,createArgument:SO0,createOption:jO0,CommanderError:mO0,InvalidArgumentError:dO0,InvalidOptionArgumentError:uO0,Command:cO,Argument:kO0,Option:nr,Help:bO0}=ir.default;var lO=" ".repeat(2);function rr(D){let F=[];if(D._enableDebugCommands)F.push(B4("\uD83D\uDEA7 debug commands appear in yellow \uD83D\uDEA7")),F.push("");if(F.push(D.description().trim()),F.push(""),F.push(lw("usage")),F.push(lO+ZY([D.parent?D.parent.name():"",D.name(),er("command"),"[subcommand]","[flags]"])),F.push(""),D.parent)F.push(lw(`${D.name()} commands`));else F.push(lw("core commands"));D.commands.toSorted((J,Q)=>Number(!!J.commands.length)-Number(!!Q.commands.length)).forEach((J)=>{if(J.commands.length)F.push(""),F.push(lw(J.name())),J.commands.forEach((Q)=>{F.push(sr(Q))});else F.push(sr(J))}),F.push("");let w=[D._helpOption,...D.options].filter((J)=>J!==void 0);if(w.length)F.push(lw("flags")),w.forEach((J)=>{F.push(ZY([lO,J.flags,tr(J.description,J.flags.length)]))}),F.push("");if(D.examples)F.push(lw("examples")),F.push(" "+D.examples.trim()),F.push("");return F.push(""),F.join(`
|
|
594
|
+
]`;continue}if(Q+=J[K],J[K]==="\\")X=!0;else if(Y&&J[K]==="]")Y=!1;else if(!Y&&J[K]==="[")Y=!0}try{new RegExp(Q)}catch{return console.warn(`Could not convert regex pattern at ${F.currentPath.join("/")} to a flag-independent form! Falling back to the flag-ignorant source`),D.source}return Q}function aH(D,F){if(F.target==="openAi")console.warn("Warning: OpenAI may not support records in schemas! Try an array of key-value pairs instead.");if(F.target==="openApi3"&&D.keyType?._def.typeName===G1.ZodEnum)return{type:"object",required:D.keyType._def.values,properties:D.keyType._def.values.reduce((J,Q)=>({...J,[Q]:f1(D.valueType._def,{...F,currentPath:[...F.currentPath,"properties",Q]})??X2(F)}),{}),additionalProperties:F.rejectedAdditionalProperties};let w={type:"object",additionalProperties:f1(D.valueType._def,{...F,currentPath:[...F.currentPath,"additionalProperties"]})??F.allowedAdditionalProperties};if(F.target==="openApi3")return w;if(D.keyType?._def.typeName===G1.ZodString&&D.keyType._def.checks?.length){let{type:J,...Q}=lH(D.keyType._def,F);return{...w,propertyNames:Q}}else if(D.keyType?._def.typeName===G1.ZodEnum)return{...w,propertyNames:{enum:D.keyType._def.values}};else if(D.keyType?._def.typeName===G1.ZodBranded&&D.keyType._def.type._def.typeName===G1.ZodString&&D.keyType._def.type._def.checks?.length){let{type:J,...Q}=cH(D.keyType._def,F);return{...w,propertyNames:Q}}return w}function Pb(D,F){if(F.mapStrategy==="record")return aH(D,F);let w=f1(D.keyType._def,{...F,currentPath:[...F.currentPath,"items","items","0"]})||X2(F),J=f1(D.valueType._def,{...F,currentPath:[...F.currentPath,"items","items","1"]})||X2(F);return{type:"array",maxItems:125,items:{type:"array",items:[w,J],minItems:2,maxItems:2}}}function Ob(D){let F=D.values,J=Object.keys(D.values).filter((X)=>{return typeof F[F[X]]!=="number"}).map((X)=>F[X]),Q=Array.from(new Set(J.map((X)=>typeof X)));return{type:Q.length===1?Q[0]==="string"?"string":"number":["string","number"],enum:J}}function Ab(D){return D.target==="openAi"?void 0:{not:X2({...D,currentPath:[...D.currentPath,"not"]})}}function vb(D){return D.target==="openApi3"?{enum:["null"],nullable:!0}:{type:"null"}}var qX={ZodString:"string",ZodNumber:"number",ZodBigInt:"integer",ZodBoolean:"boolean",ZodNull:"null"};function Rb(D,F){if(F.target==="openApi3")return Lb(D,F);let w=D.options instanceof Map?Array.from(D.options.values()):D.options;if(w.every((J)=>(J._def.typeName in qX)&&(!J._def.checks||!J._def.checks.length))){let J=w.reduce((Q,X)=>{let Y=qX[X._def.typeName];return Y&&!Q.includes(Y)?[...Q,Y]:Q},[]);return{type:J.length>1?J:J[0]}}else if(w.every((J)=>J._def.typeName==="ZodLiteral"&&!J.description)){let J=w.reduce((Q,X)=>{let Y=typeof X._def.value;switch(Y){case"string":case"number":case"boolean":return[...Q,Y];case"bigint":return[...Q,"integer"];case"object":if(X._def.value===null)return[...Q,"null"];case"symbol":case"undefined":case"function":default:return Q}},[]);if(J.length===w.length){let Q=J.filter((X,Y,W)=>W.indexOf(X)===Y);return{type:Q.length>1?Q:Q[0],enum:w.reduce((X,Y)=>{return X.includes(Y._def.value)?X:[...X,Y._def.value]},[])}}}else if(w.every((J)=>J._def.typeName==="ZodEnum"))return{type:"string",enum:w.reduce((J,Q)=>[...J,...Q._def.values.filter((X)=>!J.includes(X))],[])};return Lb(D,F)}var Lb=(D,F)=>{let w=(D.options instanceof Map?Array.from(D.options.values()):D.options).map((J,Q)=>f1(J._def,{...F,currentPath:[...F.currentPath,"anyOf",`${Q}`]})).filter((J)=>!!J&&(!F.strictUnions||typeof J==="object"&&Object.keys(J).length>0));return w.length?{anyOf:w}:void 0};function xb(D,F){if(["ZodString","ZodNumber","ZodBigInt","ZodBoolean","ZodNull"].includes(D.innerType._def.typeName)&&(!D.innerType._def.checks||!D.innerType._def.checks.length)){if(F.target==="openApi3")return{type:qX[D.innerType._def.typeName],nullable:!0};return{type:[qX[D.innerType._def.typeName],"null"]}}if(F.target==="openApi3"){let J=f1(D.innerType._def,{...F,currentPath:[...F.currentPath]});if(J&&"$ref"in J)return{allOf:[J],nullable:!0};return J&&{...J,nullable:!0}}let w=f1(D.innerType._def,{...F,currentPath:[...F.currentPath,"anyOf","0"]});return w&&{anyOf:[w,{type:"null"}]}}function Tb(D,F){let w={type:"number"};if(!D.checks)return w;for(let J of D.checks)switch(J.kind){case"int":w.type="integer",zM(w,"type",J.message,F);break;case"min":if(F.target==="jsonSchema7")if(J.inclusive)U0(w,"minimum",J.value,J.message,F);else U0(w,"exclusiveMinimum",J.value,J.message,F);else{if(!J.inclusive)w.exclusiveMinimum=!0;U0(w,"minimum",J.value,J.message,F)}break;case"max":if(F.target==="jsonSchema7")if(J.inclusive)U0(w,"maximum",J.value,J.message,F);else U0(w,"exclusiveMaximum",J.value,J.message,F);else{if(!J.inclusive)w.exclusiveMaximum=!0;U0(w,"maximum",J.value,J.message,F)}break;case"multipleOf":U0(w,"multipleOf",J.value,J.message,F);break}return w}function _b(D,F){let w=F.target==="openAi",J={type:"object",properties:{}},Q=[],X=D.shape();for(let W in X){let K=X[W];if(K===void 0||K._def===void 0)continue;let V=Mx1(K);if(V&&w){if(K._def.typeName==="ZodOptional")K=K._def.innerType;if(!K.isNullable())K=K.nullable();V=!1}let B=f1(K._def,{...F,currentPath:[...F.currentPath,"properties",W],propertyPath:[...F.currentPath,"properties",W]});if(B===void 0)continue;if(J.properties[W]=B,!V)Q.push(W)}if(Q.length)J.required=Q;let Y=$x1(D,F);if(Y!==void 0)J.additionalProperties=Y;return J}function $x1(D,F){if(D.catchall._def.typeName!=="ZodNever")return f1(D.catchall._def,{...F,currentPath:[...F.currentPath,"additionalProperties"]});switch(D.unknownKeys){case"passthrough":return F.allowedAdditionalProperties;case"strict":return F.rejectedAdditionalProperties;case"strip":return F.removeAdditionalStrategy==="strict"?F.allowedAdditionalProperties:F.rejectedAdditionalProperties}}function Mx1(D){try{return D.isOptional()}catch{return!0}}var Cb=(D,F)=>{if(F.currentPath.toString()===F.propertyPath?.toString())return f1(D.innerType._def,F);let w=f1(D.innerType._def,{...F,currentPath:[...F.currentPath,"anyOf","1"]});return w?{anyOf:[{not:X2(F)},w]}:X2(F)};var Ib=(D,F)=>{if(F.pipeStrategy==="input")return f1(D.in._def,F);else if(F.pipeStrategy==="output")return f1(D.out._def,F);let w=f1(D.in._def,{...F,currentPath:[...F.currentPath,"allOf","0"]}),J=f1(D.out._def,{...F,currentPath:[...F.currentPath,"allOf",w?"1":"0"]});return{allOf:[w,J].filter((Q)=>Q!==void 0)}};function fb(D,F){return f1(D.type._def,F)}function Sb(D,F){let J={type:"array",uniqueItems:!0,items:f1(D.valueType._def,{...F,currentPath:[...F.currentPath,"items"]})};if(D.minSize)U0(J,"minItems",D.minSize.value,D.minSize.message,F);if(D.maxSize)U0(J,"maxItems",D.maxSize.value,D.maxSize.message,F);return J}function jb(D,F){if(D.rest)return{type:"array",minItems:D.items.length,items:D.items.map((w,J)=>f1(w._def,{...F,currentPath:[...F.currentPath,"items",`${J}`]})).reduce((w,J)=>J===void 0?w:[...w,J],[]),additionalItems:f1(D.rest._def,{...F,currentPath:[...F.currentPath,"additionalItems"]})};else return{type:"array",minItems:D.items.length,maxItems:D.items.length,items:D.items.map((w,J)=>f1(w._def,{...F,currentPath:[...F.currentPath,"items",`${J}`]})).reduce((w,J)=>J===void 0?w:[...w,J],[])}}function mb(D){return{not:X2(D)}}function db(D){return X2(D)}var ub=(D,F)=>{return f1(D.innerType._def,F)};var kb=(D,F,w)=>{switch(F){case G1.ZodString:return lH(D,w);case G1.ZodNumber:return Tb(D,w);case G1.ZodObject:return _b(D,w);case G1.ZodBigInt:return pb(D,w);case G1.ZodBoolean:return Zb();case G1.ZodDate:return qM(D,w);case G1.ZodUndefined:return mb(w);case G1.ZodNull:return vb(w);case G1.ZodArray:return Gb(D,w);case G1.ZodUnion:case G1.ZodDiscriminatedUnion:return Rb(D,w);case G1.ZodIntersection:return $b(D,w);case G1.ZodTuple:return jb(D,w);case G1.ZodRecord:return aH(D,w);case G1.ZodLiteral:return Mb(D,w);case G1.ZodEnum:return qb(D);case G1.ZodNativeEnum:return Ob(D);case G1.ZodNullable:return xb(D,w);case G1.ZodOptional:return Cb(D,w);case G1.ZodMap:return Pb(D,w);case G1.ZodSet:return Sb(D,w);case G1.ZodLazy:return()=>D.getter()._def;case G1.ZodPromise:return fb(D,w);case G1.ZodNaN:case G1.ZodNever:return Ab(w);case G1.ZodEffects:return zb(D,w);case G1.ZodAny:return X2(w);case G1.ZodUnknown:return db(w);case G1.ZodDefault:return Ub(D,w);case G1.ZodBranded:return cH(D,w);case G1.ZodReadonly:return ub(D,w);case G1.ZodCatch:return Nb(D,w);case G1.ZodPipeline:return Ib(D,w);case G1.ZodFunction:case G1.ZodVoid:case G1.ZodSymbol:return;default:return((J)=>{return})(F)}};function f1(D,F,w=!1){let J=F.seen.get(D);if(F.override){let W=F.override?.(D,F,J,w);if(W!==Vb)return W}if(J&&!w){let W=Ex1(J,F);if(W!==void 0)return W}let Q={def:D,path:F.currentPath,jsonSchema:void 0};F.seen.set(D,Q);let X=kb(D,D.typeName,F),Y=typeof X==="function"?f1(X(),F):X;if(Y)Px1(D,F,Y);if(F.postProcess){let W=F.postProcess(Y,D,F);return Q.jsonSchema=Y,W}return Q.jsonSchema=Y,Y}var Ex1=(D,F)=>{switch(F.$refStrategy){case"root":return{$ref:D.path.join("/")};case"relative":return{$ref:gH(F.currentPath,D.path)};case"none":case"seen":{if(D.path.length<F.currentPath.length&&D.path.every((w,J)=>F.currentPath[J]===w))return console.warn(`Recursive reference detected at ${F.currentPath.join("/")}! Defaulting to any`),X2(F);return F.$refStrategy==="seen"?X2(F):void 0}}},Px1=(D,F,w)=>{if(D.description){if(w.description=D.description,F.markdownDescription)w.markdownDescription=D.description}return w};var iH=(D,F)=>{let w=Bb(F),J=typeof F==="object"&&F.definitions?Object.entries(F.definitions).reduce((K,[V,B])=>({...K,[V]:f1(B._def,{...w,currentPath:[...w.basePath,w.definitionPath,V]},!0)??X2(w)}),{}):void 0,Q=typeof F==="string"?F:F?.nameStrategy==="title"?void 0:F?.name,X=f1(D._def,Q===void 0?w:{...w,currentPath:[...w.basePath,w.definitionPath,Q]},!1)??X2(w),Y=typeof F==="object"&&F.name!==void 0&&F.nameStrategy==="title"?F.name:void 0;if(Y!==void 0)X.title=Y;if(w.flags.hasReferencedOpenAiAnyType){if(!J)J={};if(!J[w.openAiAnyTypeName])J[w.openAiAnyTypeName]={type:["string","number","integer","boolean","array","null"],items:{$ref:w.$refStrategy==="relative"?"1":[...w.basePath,w.definitionPath,w.openAiAnyTypeName].join("/")}}}let W=Q===void 0?J?{...X,[w.definitionPath]:J}:X:{$ref:[...w.$refStrategy==="relative"?[]:w.basePath,w.definitionPath,Q].join("/"),[w.definitionPath]:{...J,[Q]:X}};if(w.target==="jsonSchema7")W.$schema="http://json-schema.org/draft-07/schema#";else if(w.target==="jsonSchema2019-09"||w.target==="openAi")W.$schema="https://json-schema.org/draft/2019-09/schema#";if(w.target==="openAi"&&(("anyOf"in W)||("oneOf"in W)||("allOf"in W)||("type"in W)&&Array.isArray(W.type)))console.warn("Warning: OpenAI may not support schemas with unions as roots! Try wrapping it in an object property.");return W};var EM;(function(D){D.Completable="McpCompletable"})(EM||(EM={}));class $X extends s1{_parse(D){let{ctx:F}=this._processInputParams(D),w=F.data;return this._def.type._parse({data:w,path:F.path,parent:F})}unwrap(){return this._def.type}}$X.create=(D,F)=>{return new $X({type:D,typeName:EM.Completable,complete:F.complete,...Ox1(F)})};function Ox1(D){if(!D)return{};let{errorMap:F,invalid_type_error:w,required_error:J,description:Q}=D;if(F&&(w||J))throw Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);if(F)return{errorMap:F,description:Q};return{errorMap:(Y,W)=>{var K,V;let{message:B}=D;if(Y.code==="invalid_enum_value")return{message:B!==null&&B!==void 0?B:W.defaultError};if(typeof W.data>"u")return{message:(K=B!==null&&B!==void 0?B:J)!==null&&K!==void 0?K:W.defaultError};if(Y.code!=="invalid_type")return{message:W.defaultError};return{message:(V=B!==null&&B!==void 0?B:w)!==null&&V!==void 0?V:W.defaultError}},description:Q}}class PM{constructor(D,F){this._registeredResources={},this._registeredResourceTemplates={},this._registeredTools={},this._registeredPrompts={},this._toolHandlersInitialized=!1,this._completionHandlerInitialized=!1,this._resourceHandlersInitialized=!1,this._promptHandlersInitialized=!1,this.server=new zX(D,F)}async connect(D){return await this.server.connect(D)}async close(){await this.server.close()}setToolRequestHandlers(){if(this._toolHandlersInitialized)return;this.server.assertCanSetRequestHandler(eF.shape.method.value),this.server.assertCanSetRequestHandler(Dw.shape.method.value),this.server.registerCapabilities({tools:{listChanged:!0}}),this.server.setRequestHandler(eF,()=>({tools:Object.entries(this._registeredTools).filter(([,D])=>D.enabled).map(([D,F])=>{let w={name:D,title:F.title,description:F.description,inputSchema:F.inputSchema?iH(F.inputSchema,{strictUnions:!0}):Ax1,annotations:F.annotations,_meta:F._meta};if(F.outputSchema)w.outputSchema=iH(F.outputSchema,{strictUnions:!0});return w})})),this.server.setRequestHandler(Dw,async(D,F)=>{let w=this._registeredTools[D.params.name];if(!w)throw new S1(j1.InvalidParams,`Tool ${D.params.name} not found`);if(!w.enabled)throw new S1(j1.InvalidParams,`Tool ${D.params.name} disabled`);let J;if(w.inputSchema){let Q=await w.inputSchema.safeParseAsync(D.params.arguments);if(!Q.success)throw new S1(j1.InvalidParams,`Invalid arguments for tool ${D.params.name}: ${Q.error.message}`);let X=Q.data,Y=w.callback;try{J=await Promise.resolve(Y(X,F))}catch(W){J={content:[{type:"text",text:W instanceof Error?W.message:String(W)}],isError:!0}}}else{let Q=w.callback;try{J=await Promise.resolve(Q(F))}catch(X){J={content:[{type:"text",text:X instanceof Error?X.message:String(X)}],isError:!0}}}if(w.outputSchema&&!J.isError){if(!J.structuredContent)throw new S1(j1.InvalidParams,`Tool ${D.params.name} has an output schema but no structured content was provided`);let Q=await w.outputSchema.safeParseAsync(J.structuredContent);if(!Q.success)throw new S1(j1.InvalidParams,`Invalid structured content for tool ${D.params.name}: ${Q.error.message}`)}return J}),this._toolHandlersInitialized=!0}setCompletionRequestHandler(){if(this._completionHandlerInitialized)return;this.server.assertCanSetRequestHandler(wH.shape.method.value),this.server.registerCapabilities({completions:{}}),this.server.setRequestHandler(wH,async(D)=>{switch(D.params.ref.type){case"ref/prompt":return this.handlePromptCompletion(D,D.params.ref);case"ref/resource":return this.handleResourceCompletion(D,D.params.ref);default:throw new S1(j1.InvalidParams,`Invalid completion reference: ${D.params.ref}`)}}),this._completionHandlerInitialized=!0}async handlePromptCompletion(D,F){let w=this._registeredPrompts[F.name];if(!w)throw new S1(j1.InvalidParams,`Prompt ${F.name} not found`);if(!w.enabled)throw new S1(j1.InvalidParams,`Prompt ${F.name} disabled`);if(!w.argsSchema)return nH;let J=w.argsSchema.shape[D.params.argument.name];if(!(J instanceof $X))return nH;let X=await J._def.complete(D.params.argument.value,D.params.context);return hb(X)}async handleResourceCompletion(D,F){let w=Object.values(this._registeredResourceTemplates).find((X)=>X.resourceTemplate.uriTemplate.toString()===F.uri);if(!w){if(this._registeredResources[F.uri])return nH;throw new S1(j1.InvalidParams,`Resource template ${D.params.ref.uri} not found`)}let J=w.resourceTemplate.completeCallback(D.params.argument.name);if(!J)return nH;let Q=await J(D.params.argument.value,D.params.context);return hb(Q)}setResourceRequestHandlers(){if(this._resourceHandlersInitialized)return;this.server.assertCanSetRequestHandler(nF.shape.method.value),this.server.assertCanSetRequestHandler(sF.shape.method.value),this.server.assertCanSetRequestHandler(oF.shape.method.value),this.server.registerCapabilities({resources:{listChanged:!0}}),this.server.setRequestHandler(nF,async(D,F)=>{let w=Object.entries(this._registeredResources).filter(([Q,X])=>X.enabled).map(([Q,X])=>({uri:Q,name:X.name,...X.metadata})),J=[];for(let Q of Object.values(this._registeredResourceTemplates)){if(!Q.resourceTemplate.listCallback)continue;let X=await Q.resourceTemplate.listCallback(F);for(let Y of X.resources)J.push({...Q.metadata,...Y})}return{resources:[...w,...J]}}),this.server.setRequestHandler(sF,async()=>{return{resourceTemplates:Object.entries(this._registeredResourceTemplates).map(([F,w])=>({name:F,uriTemplate:w.resourceTemplate.uriTemplate.toString(),...w.metadata}))}}),this.server.setRequestHandler(oF,async(D,F)=>{let w=new URL(D.params.uri),J=this._registeredResources[w.toString()];if(J){if(!J.enabled)throw new S1(j1.InvalidParams,`Resource ${w} disabled`);return J.readCallback(w,F)}for(let Q of Object.values(this._registeredResourceTemplates)){let X=Q.resourceTemplate.uriTemplate.match(w.toString());if(X)return Q.readCallback(w,X,F)}throw new S1(j1.InvalidParams,`Resource ${w} not found`)}),this.setCompletionRequestHandler(),this._resourceHandlersInitialized=!0}setPromptRequestHandlers(){if(this._promptHandlersInitialized)return;this.server.assertCanSetRequestHandler(rF.shape.method.value),this.server.assertCanSetRequestHandler(tF.shape.method.value),this.server.registerCapabilities({prompts:{listChanged:!0}}),this.server.setRequestHandler(rF,()=>({prompts:Object.entries(this._registeredPrompts).filter(([,D])=>D.enabled).map(([D,F])=>{return{name:D,title:F.title,description:F.description,arguments:F.argsSchema?Lx1(F.argsSchema):void 0}})})),this.server.setRequestHandler(tF,async(D,F)=>{let w=this._registeredPrompts[D.params.name];if(!w)throw new S1(j1.InvalidParams,`Prompt ${D.params.name} not found`);if(!w.enabled)throw new S1(j1.InvalidParams,`Prompt ${D.params.name} disabled`);if(w.argsSchema){let J=await w.argsSchema.safeParseAsync(D.params.arguments);if(!J.success)throw new S1(j1.InvalidParams,`Invalid arguments for prompt ${D.params.name}: ${J.error.message}`);let Q=J.data,X=w.callback;return await Promise.resolve(X(Q,F))}else{let J=w.callback;return await Promise.resolve(J(F))}}),this.setCompletionRequestHandler(),this._promptHandlersInitialized=!0}resource(D,F,...w){let J;if(typeof w[0]==="object")J=w.shift();let Q=w[0];if(typeof F==="string"){if(this._registeredResources[F])throw Error(`Resource ${F} is already registered`);let X=this._createRegisteredResource(D,void 0,F,J,Q);return this.setResourceRequestHandlers(),this.sendResourceListChanged(),X}else{if(this._registeredResourceTemplates[D])throw Error(`Resource template ${D} is already registered`);let X=this._createRegisteredResourceTemplate(D,void 0,F,J,Q);return this.setResourceRequestHandlers(),this.sendResourceListChanged(),X}}registerResource(D,F,w,J){if(typeof F==="string"){if(this._registeredResources[F])throw Error(`Resource ${F} is already registered`);let Q=this._createRegisteredResource(D,w.title,F,w,J);return this.setResourceRequestHandlers(),this.sendResourceListChanged(),Q}else{if(this._registeredResourceTemplates[D])throw Error(`Resource template ${D} is already registered`);let Q=this._createRegisteredResourceTemplate(D,w.title,F,w,J);return this.setResourceRequestHandlers(),this.sendResourceListChanged(),Q}}_createRegisteredResource(D,F,w,J,Q){let X={name:D,title:F,metadata:J,readCallback:Q,enabled:!0,disable:()=>X.update({enabled:!1}),enable:()=>X.update({enabled:!0}),remove:()=>X.update({uri:null}),update:(Y)=>{if(typeof Y.uri<"u"&&Y.uri!==w){if(delete this._registeredResources[w],Y.uri)this._registeredResources[Y.uri]=X}if(typeof Y.name<"u")X.name=Y.name;if(typeof Y.title<"u")X.title=Y.title;if(typeof Y.metadata<"u")X.metadata=Y.metadata;if(typeof Y.callback<"u")X.readCallback=Y.callback;if(typeof Y.enabled<"u")X.enabled=Y.enabled;this.sendResourceListChanged()}};return this._registeredResources[w]=X,X}_createRegisteredResourceTemplate(D,F,w,J,Q){let X={resourceTemplate:w,title:F,metadata:J,readCallback:Q,enabled:!0,disable:()=>X.update({enabled:!1}),enable:()=>X.update({enabled:!0}),remove:()=>X.update({name:null}),update:(Y)=>{if(typeof Y.name<"u"&&Y.name!==D){if(delete this._registeredResourceTemplates[D],Y.name)this._registeredResourceTemplates[Y.name]=X}if(typeof Y.title<"u")X.title=Y.title;if(typeof Y.template<"u")X.resourceTemplate=Y.template;if(typeof Y.metadata<"u")X.metadata=Y.metadata;if(typeof Y.callback<"u")X.readCallback=Y.callback;if(typeof Y.enabled<"u")X.enabled=Y.enabled;this.sendResourceListChanged()}};return this._registeredResourceTemplates[D]=X,X}_createRegisteredPrompt(D,F,w,J,Q){let X={title:F,description:w,argsSchema:J===void 0?void 0:M.object(J),callback:Q,enabled:!0,disable:()=>X.update({enabled:!1}),enable:()=>X.update({enabled:!0}),remove:()=>X.update({name:null}),update:(Y)=>{if(typeof Y.name<"u"&&Y.name!==D){if(delete this._registeredPrompts[D],Y.name)this._registeredPrompts[Y.name]=X}if(typeof Y.title<"u")X.title=Y.title;if(typeof Y.description<"u")X.description=Y.description;if(typeof Y.argsSchema<"u")X.argsSchema=M.object(Y.argsSchema);if(typeof Y.callback<"u")X.callback=Y.callback;if(typeof Y.enabled<"u")X.enabled=Y.enabled;this.sendPromptListChanged()}};return this._registeredPrompts[D]=X,X}_createRegisteredTool(D,F,w,J,Q,X,Y,W){let K={title:F,description:w,inputSchema:J===void 0?void 0:M.object(J),outputSchema:Q===void 0?void 0:M.object(Q),annotations:X,_meta:Y,callback:W,enabled:!0,disable:()=>K.update({enabled:!1}),enable:()=>K.update({enabled:!0}),remove:()=>K.update({name:null}),update:(V)=>{if(typeof V.name<"u"&&V.name!==D){if(delete this._registeredTools[D],V.name)this._registeredTools[V.name]=K}if(typeof V.title<"u")K.title=V.title;if(typeof V.description<"u")K.description=V.description;if(typeof V.paramsSchema<"u")K.inputSchema=M.object(V.paramsSchema);if(typeof V.callback<"u")K.callback=V.callback;if(typeof V.annotations<"u")K.annotations=V.annotations;if(typeof V._meta<"u")K._meta=V._meta;if(typeof V.enabled<"u")K.enabled=V.enabled;this.sendToolListChanged()}};return this._registeredTools[D]=K,this.setToolRequestHandlers(),this.sendToolListChanged(),K}tool(D,...F){if(this._registeredTools[D])throw Error(`Tool ${D} is already registered`);let w,J,Q,X;if(typeof F[0]==="string")w=F.shift();if(F.length>1){let W=F[0];if(bb(W)){if(J=F.shift(),F.length>1&&typeof F[0]==="object"&&F[0]!==null&&!bb(F[0]))X=F.shift()}else if(typeof W==="object"&&W!==null)X=F.shift()}let Y=F[0];return this._createRegisteredTool(D,void 0,w,J,Q,X,void 0,Y)}registerTool(D,F,w){if(this._registeredTools[D])throw Error(`Tool ${D} is already registered`);let{title:J,description:Q,inputSchema:X,outputSchema:Y,annotations:W,_meta:K}=F;return this._createRegisteredTool(D,J,Q,X,Y,W,K,w)}prompt(D,...F){if(this._registeredPrompts[D])throw Error(`Prompt ${D} is already registered`);let w;if(typeof F[0]==="string")w=F.shift();let J;if(F.length>1)J=F.shift();let Q=F[0],X=this._createRegisteredPrompt(D,void 0,w,J,Q);return this.setPromptRequestHandlers(),this.sendPromptListChanged(),X}registerPrompt(D,F,w){if(this._registeredPrompts[D])throw Error(`Prompt ${D} is already registered`);let{title:J,description:Q,argsSchema:X}=F,Y=this._createRegisteredPrompt(D,J,Q,X,w);return this.setPromptRequestHandlers(),this.sendPromptListChanged(),Y}isConnected(){return this.server.transport!==void 0}async sendLoggingMessage(D,F){return this.server.sendLoggingMessage(D,F)}sendResourceListChanged(){if(this.isConnected())this.server.sendResourceListChanged()}sendToolListChanged(){if(this.isConnected())this.server.sendToolListChanged()}sendPromptListChanged(){if(this.isConnected())this.server.sendPromptListChanged()}}var Ax1={type:"object",properties:{}};function bb(D){if(typeof D!=="object"||D===null)return!1;return Object.keys(D).length===0||Object.values(D).some(vx1)}function vx1(D){return D!==null&&typeof D==="object"&&"parse"in D&&typeof D.parse==="function"&&"safeParse"in D&&typeof D.safeParse==="function"}function Lx1(D){return Object.entries(D.shape).map(([F,w])=>({name:F,description:w.description,required:!w.isOptional()}))}function hb(D){return{completion:{values:D.slice(0,100),total:D.length,hasMore:D.length>100}}}var nH={completion:{values:[],hasMore:!1}};var OM=A1(p3(),1);var Zw="__prompts__",AM=M.object({name:p4,title:p4,description:M.string().trim().optional(),body:p4}),Vq0=M.object({prompts:M.array(AM).optional()});class vM extends yH{_promptList;constructor(D=[]){super({name:Zw},{server:yb(OM.default.cloneDeep(D))});this._promptList=OM.default.cloneDeep(D)}get promptList(){return this._promptList}async addPromptEntry(D){if(this._promptList.find((w)=>w.name===D.name))throw new p1("DUPLICATE",`Prompt ${D.name} already exists`);return this._promptList.push(D),await this.reconnectToServer(),D}async updatePrompt(D,F){let w=this._promptList.findIndex((J)=>J.name===D);if(w===-1)throw new p1("NOT_FOUND",`Prompt ${D} not found`);return this._promptList[w]={...this._promptList[w],...F},await this.reconnectToServer(),this._promptList[w]}async removePromptEntry(D){let F=this._promptList.findIndex((w)=>w.name===D);if(F===-1)throw new p1("NOT_FOUND",`Prompt ${D} not found`);this._promptList.splice(F,1),await this.reconnectToServer()}getPromptEntry(D){let F=this._promptList.find((w)=>w.name===D);if(!F)throw new p1("NOT_FOUND",`Prompt ${D} not found`);return F}async reconnectToServer(){await this.close(),await this.server.close(),this.server=yb(this._promptList),await this.connectToTarget({throwOnError:!0})}}function yb(D){let F=new PM({name:"prompt-manager",version:"1.0.0"},{capabilities:{logging:{}}});for(let w of D)F.registerPrompt(w.name,{title:w.title,description:w.description},async()=>{return await{messages:[{role:"user",content:{type:"text",text:w.body}}]}});return F.server}var gb=Uk.extend({type:M.literal("http")}),cb=Yb.extend({type:M.literal("stdio")}),lb=M.union([gb,cb]),LM=M.object({id:p4,name:p4,description:um,prompts:M.array(AM).optional(),servers:M.array(lb)});var g2=A1(p3(),1);class RM{schema;storage;defaults;constructor(D){this.schema=D.schema,this.storage=D.storage,this.defaults=D.defaults??{}}get data(){return this.storage.getData()}async init(){await this.storage.init(),this.validate({...this.defaults,...this.storage.getData()})}async set(D,F){if(!(D in this.schema))throw new p1("INVALID_ARGUMENT",`Key "${D}" is not allowed`,{key:D});let J=this.schema[D].parse(F),Q=this.storage.getData();g2.set(Q,D,J),this.storage.setData(Q),await this.storage.persist()}get(D){if(!(D in this.schema))throw new p1("INVALID_ARGUMENT",`Key "${D}" is not allowed`,{key:D});let F=g2.get({...this.defaults,...this.storage.getData()},D);if(F!==void 0)return F;let J=this.schema[D].safeParse(void 0);if(J.success)return J.data;return}async purge(){await this.storage.purge()}async push(D,F){if(!(D in this.schema))throw new p1("INVALID_ARGUMENT",`Key "${D}" is not allowed`,{key:D});let w=this.schema[D],J=this.unwrapArraySchema(w);if(!J)throw new p1("INVALID_ARGUMENT",`Key "${D}" is not an array`,{key:D});let Q=J.element.parse(F),X=this.storage.getData(),W=[...g2.get({...this.defaults,...X},D)??[],Q];g2.set(X,D,W),this.storage.setData(X),await this.storage.persist()}async remove(D,F){if(!(D in this.schema))throw new p1("INVALID_ARGUMENT",`Key "${D}" is not allowed`,{key:D});let w=this.schema[D];if(!this.unwrapArraySchema(w))throw new p1("INVALID_ARGUMENT",`Key "${D}" is not an array`,{key:D});let Q=this.storage.getData(),W=[...g2.get({...this.defaults,...Q},D)??[]].filter((K)=>{if(!g2.isObject(K)||K===null)return!g2.isEqual(K,F);return!g2.isMatch(K,F)});g2.set(Q,D,W),this.storage.setData(Q),await this.storage.persist()}find(D,F){if(!(D in this.schema))throw new p1("INVALID_ARGUMENT",`Key "${D}" is not allowed`,{key:D});let w=this.schema[D];if(!this.unwrapArraySchema(w))throw new p1("INVALID_ARGUMENT",`Key "${D}" is not an array`,{key:D});let Q=this.storage.getData();return[...g2.get({...this.defaults,...Q},D)??[]].find((K)=>{if(!g2.isObject(K)||K===null)return g2.isEqual(K,F);return g2.isMatch(K,F)})}unwrapArraySchema(D){while(!0){if(D instanceof M.ZodArray)return D;if(D instanceof M.ZodDefault){D=D._def.innerType;continue}if(D instanceof M.ZodOptional||D instanceof M.ZodNullable){D=D._def.innerType;continue}if(D instanceof M.ZodEffects){D=D._def.schema;continue}return null}}validate(D){let F={...this.defaults,...D};for(let w in this.schema){let J=g2.get(F,w),Q=this.schema[w];try{Q.parse(J)}catch(X){throw new p1("INVALID_CONFIGURATION",`Invalid data for key "${w}": ${X instanceof Error?X.message:String(X)}`,{key:w,value:J})}}}}var mB=A1(Dg(),1);import Fg from"fs";import{existsSync as Ld1}from"node:fs";class kE{data;constructor(D){this.data={...D?.data}}init(){return Promise.resolve()}persist(){return Promise.resolve()}purge(){return this.data={},Promise.resolve()}getData(){return structuredClone(this.data)}setData(D){this.data=structuredClone(D)}toPlainObject(){return{type:"in-memory",data:this.data}}}class bE{filePath;data={};constructor(D){if(!D.filePath)throw Error("Config filePath is not defined");this.filePath=D.filePath}async init(){if(Ld1(this.filePath)){let D=await Fg.promises.readFile(this.filePath,"utf8"),F=mB.default.parse(D);this.data=F&&typeof F==="object"&&!Array.isArray(F)?F:{}}}async persist(){let F=this.filePath.endsWith(".json")?JSON.stringify(this.data):mB.default.stringify(this.data);await Fg.promises.writeFile(this.filePath,F)}async purge(){this.data={},await this.persist()}getData(){return structuredClone(this.data)}setData(D){this.data=structuredClone(D)}toPlainObject(){return{type:"yaml",path:this.filePath,data:this.data}}}class cX extends RM{playbooks;constructor(D){super({schema:Rd1,storage:D.storage,defaults:D.defaults});this.playbooks=new Qg(this)}static async createFileBasedConfig(D){let F=new cX({storage:new bE({filePath:D.filePath}),defaults:D.defaults});return await F.init(),F}static async createMemoryBasedConfig(D){let F=new cX({storage:new kE,defaults:D.defaults});return await F.init(),F}toPlainObject(){return{defaults:this.defaults,storage:this.storage.toPlainObject()}}prettyPrint(){console.log("*************************************************"),console.log(),console.log(g0("STORAGE")),console.log(JSON.stringify(dB.default.omit(this.storage.toPlainObject(),"data"),null,2)),console.log(),console.log(g0("DEFAULTS")),console.log(JSON.stringify(this.defaults,null,2)),console.log(),console.log("*************************************************")}}class Qg{config;constructor(D){this.config=D}async create(D){let F=wg(D.name);if(await this.config.find("playbooks",{id:F}))throw new p1("DUPLICATE","Playbook with this name already exists");let w={id:F,...D,servers:dB.default.map(D.servers||[],(J)=>({...J,name:wg(J.name)}))};return await this.config.push("playbooks",w),w}async getPlaybook(D){let F=await this.all(),w=dB.default.find(F,{id:D});if(!w)throw Error("Playbook not found");return w}async update(D,F){if(F.id!==D)throw Error("Id mismatch");return await this.config.remove("playbooks",{id:D}),await this.config.push("playbooks",F),F}async remove(D){await this.config.remove("playbooks",{id:D})}async count(){return(await this.all()).length}async all(){return await this.config.get("playbooks")||[]}}function wg(D){return Jg.default(D,{lower:!0,strict:!0,trim:!0})}var Rd1={version:M.string().default("1.0.0"),playbooks:M.array(LM).default([]),debug:M.boolean().default(!1),"server.port":M.number().min(0),"registry.url":M.string(),"registry.apiKey":M.string().optional(),"telemetry.writeKey":M.string(),"telemetry.enabled":M.boolean(),"oauth.storage":M.literal("disk").or(M.literal("memory")).default("disk"),"oauth.tokenDirectory":M.string().default("./tokens"),"clients.claude":M.array(M.string()).default([]),"clients.claude-code":M.array(M.string()).default([]),"clients.cursor":M.array(M.string()).default([]),"clients.vscode":M.array(M.string()).default([])};import xd1 from"fs";function uB(D){for(let F of D)try{if(xd1.existsSync(F))return F}catch{continue}return}var xr=A1(Lr(),1),Tr=A1(Rr(),1);import SO from"os";class cw{analytics;machineId;enabled;traits;constructor(D){this.analytics=new xr.Analytics({writeKey:D.writeKey}),this.enabled=D.enabled,this.traits=D.traits||{}}async initialize(){if(this.machineId)return;if(this.machineId=await Tr.machineId(),this.enabled)this.analytics.identify({userId:this.machineId,traits:{...this.traits,os:SO.platform(),osVersion:SO.release(),arch:SO.arch()}})}static noTelemetry(){return new cw({writeKey:"--",enabled:!1})}async trackEvent(D,F={}){if(await this.initialize(),this.enabled)this.analytics.track({userId:this.machineId,event:D,properties:F})}}var C6={name:"@director.run/cli",type:"module",version:"1.1.0",files:["dist","README.md","package.json"],bin:{director:"./dist/cli.js"},author:"Barnaby Malet <barnaby@director.run>",license:"AGPL-3.0",repository:{type:"git",url:"https://github.com/director-run/director"},description:"Playbooks for AI agents",homepage:"https://director.run",publishConfig:{access:"public"},scripts:{lint:"biome check .",format:"biome format --write .",clean:"rm -rf .turbo dist/*",test:"bun run vitest --fileParallelism=false",cli:"LOG_LEVEL=debug NODE_ENV=development bun run bin/cli.ts","cli:dev":"NODE_ENV=development bun --watch bin/cli.ts",typecheck:"tsc --noEmit",build:"bun run clean && bun build --production --target=node bin/cli.ts --outdir dist && cp -r ../studio/dist dist/studio",release:"changeset publish",dev:"bun --watch bin/cli.ts",spellcheck:'cspell "**"'},peerDependencies:{typescript:"^5"},devDependencies:{"@director.run/gateway":"workspace:*","@director.run/client-configurator":"workspace:*","@director.run/mcp":"workspace:*","@director.run/registry":"workspace:*","@director.run/utilities":"workspace:*","@inquirer/prompts":"^7.5.2","@modelcontextprotocol/sdk":"1.20.0","@segment/analytics-node":"^2.3.0","@trpc/server":"^11.0.2","@types/semver":"^7.5.8","@types/update-notifier":"^6.0.8",boxen:"^8.0.1",chalk:"^5.4.1","cli-table3":"^0.6.5",commander:"^13.1.0","node-machine-id":"^1.1.12",semver:"^7.7.2",superjson:"^2.2.2","type-fest":"^4.40.0",typescript:"^5.8.3","update-notifier":"^7.3.1",vitest:"^3.1.1",zod:"^3.25.76",zx:"^8.8.0",cspell:"^9.2.2"}};var __dirname="/home/runner/work/director/director/apps/cli/src",Ts1="Z8wjEfWMFnlltCpGPPWlvsEQH1aVEUH3";function KD(){if(t6())return WD.join(__dirname,"../../../director.config.test.yaml");else if(aF())return WD.join(__dirname,"../../../director.config.development.yaml");else{let D=WD.join(xs1.homedir(),".director/director.config.yaml"),F=WD.join(process.cwd(),"director.config.yaml");return uB([F,D])??D}}function _s1(){if(t6())return{storage:"memory"};else return{storage:"disk",tokenDirectory:WD.join(WD.dirname(KD()),".secrets/director-oauth-tokens")}}var Cs1=WD.dirname(KD());await Rs1.mkdir(Cs1,{recursive:!0});var n4=await cX.createFileBasedConfig({filePath:KD(),defaults:{debug:aF(),registry:{url:"https://registry.director.run"},server:{port:t6()?3675:parseInt(process.env.GATEWAY_PORT??"3673")},telemetry:{writeKey:oq()?Ts1:"--",enabled:oq()},oauth:_s1()}});function a2(){return`http://localhost:${n4.get("server.port")}`}function jO(){return`${a2()}/studio`}function _r(){return new cw({writeKey:n4.get("telemetry.writeKey")??"--",enabled:!!n4.get("telemetry.enabled"),traits:{cliVersion:C6.version}})}var ir=A1(ar(),1),{program:IO0,createCommand:fO0,createArgument:SO0,createOption:jO0,CommanderError:mO0,InvalidArgumentError:dO0,InvalidOptionArgumentError:uO0,Command:cO,Argument:kO0,Option:nr,Help:bO0}=ir.default;var lO=" ".repeat(2);function rr(D){let F=[];if(D._enableDebugCommands)F.push(B4("\uD83D\uDEA7 debug commands appear in yellow \uD83D\uDEA7")),F.push("");if(F.push(D.description().trim()),F.push(""),F.push(lw("usage")),F.push(lO+ZY([D.parent?D.parent.name():"",D.name(),er("command"),"[subcommand]","[flags]"])),F.push(""),D.parent)F.push(lw(`${D.name()} commands`));else F.push(lw("core commands"));D.commands.toSorted((J,Q)=>Number(!!J.commands.length)-Number(!!Q.commands.length)).forEach((J)=>{if(J.commands.length)F.push(""),F.push(lw(J.name())),J.commands.forEach((Q)=>{F.push(sr(Q))});else F.push(sr(J))}),F.push("");let w=[D._helpOption,...D.options].filter((J)=>J!==void 0);if(w.length)F.push(lw("flags")),w.forEach((J)=>{F.push(ZY([lO,J.flags,tr(J.description,J.flags.length)]))}),F.push("");if(D.examples)F.push(lw("examples")),F.push(" "+D.examples.trim()),F.push("");return F.push(""),F.join(`
|
|
595
595
|
`)}var lw=(D)=>{return g0(D.toLocaleUpperCase())},sr=(D)=>{let F=D.registeredArguments.map((X)=>X.required?er(X.name()):or(X.name())).filter((X)=>X!=="").join(" "),w=ZY([ZY([D.parent&&D.parent.parent?D.parent?.name():void 0,D.name()]),F,D.options.length?or("options"):""]),J=D.description()||K5("TODO"),Q=ZY([lO,w,tr(J,w.length)]);return D._debug?B4(Q):Q},tr=(D,F)=>{return" ".repeat(Math.max(0,45-F))+D},er=(D)=>["<",D,">"].join(""),or=(D)=>["[",D,"]"].join(""),ZY=(D)=>D.filter(Boolean).join(" ");class g8 extends cO{debug=!0;examples="";constructor(D){super(D);this.helpCommand(!1)}showDebugCommands(D){return this._enableDebugCommands=D,this}debugCommand(D,F){if(this._enableDebugCommands){let w=super.command(D,F);return w._enableDebugCommands=!0,w._debug=!0,w}else return new cO(D)}helpInformation(D){return rr(this)}addExamples(D){this.examples=D}addCommand(D,F){return D._enableDebugCommands=this._enableDebugCommands,D._debug=this._debug,super.addCommand(D,F)}}function I6({flags:D,description:F,defaultValue:w,choices:J,mandatory:Q,variadic:X}){let Y=new nr(D,F);if(Q&&Y.makeOptionMandatory(),w&&Y.default(w),J&&Y.choices(J),X)Y.argParser((W,K)=>{if(K===void 0||K===null)return[W];return K.concat(W)});return Y}import TG from"node:process";function aO({onlyFirst:D=!1}={}){return new RegExp("(?:\\u001B\\][\\s\\S]*?(?:\\u0007|\\u001B\\u005C|\\u009C))|[\\u001B\\u009B][[\\]()#;?]*(?:\\d{1,4}(?:[;:]\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]",D?void 0:"g")}var Po1=aO();function VD(D){if(typeof D!=="string")throw TypeError(`Expected a \`string\`, got \`${typeof D}\``);return D.replace(Po1,"")}function Dt(D){return D===161||D===164||D===167||D===168||D===170||D===173||D===174||D>=176&&D<=180||D>=182&&D<=186||D>=188&&D<=191||D===198||D===208||D===215||D===216||D>=222&&D<=225||D===230||D>=232&&D<=234||D===236||D===237||D===240||D===242||D===243||D>=247&&D<=250||D===252||D===254||D===257||D===273||D===275||D===283||D===294||D===295||D===299||D>=305&&D<=307||D===312||D>=319&&D<=322||D===324||D>=328&&D<=331||D===333||D===338||D===339||D===358||D===359||D===363||D===462||D===464||D===466||D===468||D===470||D===472||D===474||D===476||D===593||D===609||D===708||D===711||D>=713&&D<=715||D===717||D===720||D>=728&&D<=731||D===733||D===735||D>=768&&D<=879||D>=913&&D<=929||D>=931&&D<=937||D>=945&&D<=961||D>=963&&D<=969||D===1025||D>=1040&&D<=1103||D===1105||D===8208||D>=8211&&D<=8214||D===8216||D===8217||D===8220||D===8221||D>=8224&&D<=8226||D>=8228&&D<=8231||D===8240||D===8242||D===8243||D===8245||D===8251||D===8254||D===8308||D===8319||D>=8321&&D<=8324||D===8364||D===8451||D===8453||D===8457||D===8467||D===8470||D===8481||D===8482||D===8486||D===8491||D===8531||D===8532||D>=8539&&D<=8542||D>=8544&&D<=8555||D>=8560&&D<=8569||D===8585||D>=8592&&D<=8601||D===8632||D===8633||D===8658||D===8660||D===8679||D===8704||D===8706||D===8707||D===8711||D===8712||D===8715||D===8719||D===8721||D===8725||D===8730||D>=8733&&D<=8736||D===8739||D===8741||D>=8743&&D<=8748||D===8750||D>=8756&&D<=8759||D===8764||D===8765||D===8776||D===8780||D===8786||D===8800||D===8801||D>=8804&&D<=8807||D===8810||D===8811||D===8814||D===8815||D===8834||D===8835||D===8838||D===8839||D===8853||D===8857||D===8869||D===8895||D===8978||D>=9312&&D<=9449||D>=9451&&D<=9547||D>=9552&&D<=9587||D>=9600&&D<=9615||D>=9618&&D<=9621||D===9632||D===9633||D>=9635&&D<=9641||D===9650||D===9651||D===9654||D===9655||D===9660||D===9661||D===9664||D===9665||D>=9670&&D<=9672||D===9675||D>=9678&&D<=9681||D>=9698&&D<=9701||D===9711||D===9733||D===9734||D===9737||D===9742||D===9743||D===9756||D===9758||D===9792||D===9794||D===9824||D===9825||D>=9827&&D<=9829||D>=9831&&D<=9834||D===9836||D===9837||D===9839||D===9886||D===9887||D===9919||D>=9926&&D<=9933||D>=9935&&D<=9939||D>=9941&&D<=9953||D===9955||D===9960||D===9961||D>=9963&&D<=9969||D===9972||D>=9974&&D<=9977||D===9979||D===9980||D===9982||D===9983||D===10045||D>=10102&&D<=10111||D>=11094&&D<=11097||D>=12872&&D<=12879||D>=57344&&D<=63743||D>=65024&&D<=65039||D===65533||D>=127232&&D<=127242||D>=127248&&D<=127277||D>=127280&&D<=127337||D>=127344&&D<=127373||D===127375||D===127376||D>=127387&&D<=127404||D>=917760&&D<=917999||D>=983040&&D<=1048573||D>=1048576&&D<=1114109}function Ft(D){return D===12288||D>=65281&&D<=65376||D>=65504&&D<=65510}function wt(D){return D>=4352&&D<=4447||D===8986||D===8987||D===9001||D===9002||D>=9193&&D<=9196||D===9200||D===9203||D===9725||D===9726||D===9748||D===9749||D>=9776&&D<=9783||D>=9800&&D<=9811||D===9855||D>=9866&&D<=9871||D===9875||D===9889||D===9898||D===9899||D===9917||D===9918||D===9924||D===9925||D===9934||D===9940||D===9962||D===9970||D===9971||D===9973||D===9978||D===9981||D===9989||D===9994||D===9995||D===10024||D===10060||D===10062||D>=10067&&D<=10069||D===10071||D>=10133&&D<=10135||D===10160||D===10175||D===11035||D===11036||D===11088||D===11093||D>=11904&&D<=11929||D>=11931&&D<=12019||D>=12032&&D<=12245||D>=12272&&D<=12287||D>=12289&&D<=12350||D>=12353&&D<=12438||D>=12441&&D<=12543||D>=12549&&D<=12591||D>=12593&&D<=12686||D>=12688&&D<=12773||D>=12783&&D<=12830||D>=12832&&D<=12871||D>=12880&&D<=42124||D>=42128&&D<=42182||D>=43360&&D<=43388||D>=44032&&D<=55203||D>=63744&&D<=64255||D>=65040&&D<=65049||D>=65072&&D<=65106||D>=65108&&D<=65126||D>=65128&&D<=65131||D>=94176&&D<=94180||D>=94192&&D<=94198||D>=94208&&D<=101589||D>=101631&&D<=101662||D>=101760&&D<=101874||D>=110576&&D<=110579||D>=110581&&D<=110587||D===110589||D===110590||D>=110592&&D<=110882||D===110898||D>=110928&&D<=110930||D===110933||D>=110948&&D<=110951||D>=110960&&D<=111355||D>=119552&&D<=119638||D>=119648&&D<=119670||D===126980||D===127183||D===127374||D>=127377&&D<=127386||D>=127488&&D<=127490||D>=127504&&D<=127547||D>=127552&&D<=127560||D===127568||D===127569||D>=127584&&D<=127589||D>=127744&&D<=127776||D>=127789&&D<=127797||D>=127799&&D<=127868||D>=127870&&D<=127891||D>=127904&&D<=127946||D>=127951&&D<=127955||D>=127968&&D<=127984||D===127988||D>=127992&&D<=128062||D===128064||D>=128066&&D<=128252||D>=128255&&D<=128317||D>=128331&&D<=128334||D>=128336&&D<=128359||D===128378||D===128405||D===128406||D===128420||D>=128507&&D<=128591||D>=128640&&D<=128709||D===128716||D>=128720&&D<=128722||D>=128725&&D<=128728||D>=128732&&D<=128735||D===128747||D===128748||D>=128756&&D<=128764||D>=128992&&D<=129003||D===129008||D>=129292&&D<=129338||D>=129340&&D<=129349||D>=129351&&D<=129535||D>=129648&&D<=129660||D>=129664&&D<=129674||D>=129678&&D<=129734||D===129736||D>=129741&&D<=129756||D>=129759&&D<=129770||D>=129775&&D<=129784||D>=131072&&D<=196605||D>=196608&&D<=262141}function Oo1(D){if(!Number.isSafeInteger(D))throw TypeError(`Expected a code point, got \`${typeof D}\`.`)}function Jt(D,{ambiguousAsWide:F=!1}={}){if(Oo1(D),Ft(D)||wt(D)||F&&Dt(D))return 2;return 1}var Yt=A1(Xt(),1),Ao1=new Intl.Segmenter,vo1=/^\p{Default_Ignorable_Code_Point}$/u;function z4(D,F={}){if(typeof D!=="string"||D.length===0)return 0;let{ambiguousIsNarrow:w=!0,countAnsiEscapeCodes:J=!1}=F;if(!J)D=VD(D);if(D.length===0)return 0;let Q=0,X={ambiguousAsWide:!w};for(let{segment:Y}of Ao1.segment(D)){let W=Y.codePointAt(0);if(W<=31||W>=127&&W<=159)continue;if(W>=8203&&W<=8207||W===65279)continue;if(W>=768&&W<=879||W>=6832&&W<=6911||W>=7616&&W<=7679||W>=8400&&W<=8447||W>=65056&&W<=65071)continue;if(W>=55296&&W<=57343)continue;if(W>=65024&&W<=65039)continue;if(vo1.test(Y))continue;if(Yt.default().test(Y)){Q+=2;continue}Q+=Jt(W,X)}return Q}function AG(D){let F=0;for(let w of D.split(`
|
|
596
596
|
`))F=Math.max(F,z4(w));return F}var St=A1(nO(),1);var Ro1=/[\p{Lu}]/u,xo1=/[\p{Ll}]/u,Vt=/^[\p{Lu}](?![\p{Lu}])/gu,Gt=/([\p{Alpha}\p{N}_]|$)/u,sO=/[_.\- ]+/,To1=new RegExp("^"+sO.source),Ht=new RegExp(sO.source+Gt.source,"gu"),Bt=new RegExp("\\d+"+Gt.source,"gu"),_o1=(D,F,w,J)=>{let Q=!1,X=!1,Y=!1,W=!1;for(let K=0;K<D.length;K++){let V=D[K];if(W=K>2?D[K-3]==="-":!0,Q&&Ro1.test(V))D=D.slice(0,K)+"-"+D.slice(K),Q=!1,Y=X,X=!0,K++;else if(X&&Y&&xo1.test(V)&&(!W||J))D=D.slice(0,K-1)+"-"+D.slice(K-1),Y=X,X=!1,Q=!0;else Q=F(V)===V&&w(V)!==V,Y=X,X=w(V)===V&&F(V)!==V}return D},Co1=(D,F)=>{return Vt.lastIndex=0,D.replaceAll(Vt,(w)=>F(w))},Io1=(D,F)=>{return Ht.lastIndex=0,Bt.lastIndex=0,D.replaceAll(Bt,(w,J,Q)=>["_","-"].includes(D.charAt(Q+w.length))?w:F(w)).replaceAll(Ht,(w,J)=>F(J))};function oO(D,F){if(!(typeof D==="string"||Array.isArray(D)))throw TypeError("Expected the input to be `string | string[]`");if(F={pascalCase:!1,preserveConsecutiveUppercase:!1,...F},Array.isArray(D))D=D.map((X)=>X.trim()).filter((X)=>X.length).join("-");else D=D.trim();if(D.length===0)return"";let w=F.locale===!1?(X)=>X.toLowerCase():(X)=>X.toLocaleLowerCase(F.locale),J=F.locale===!1?(X)=>X.toUpperCase():(X)=>X.toLocaleUpperCase(F.locale);if(D.length===1){if(sO.test(D))return"";return F.pascalCase?J(D):w(D)}if(D!==w(D))D=_o1(D,w,J,F.preserveConsecutiveUppercase);if(D=D.replace(To1,""),D=F.preserveConsecutiveUppercase?Co1(D,w):w(D),F.pascalCase)D=J(D.charAt(0))+D.slice(1);return Io1(D,J)}var wA=A1(Pt(),1);var Ot=(D=0)=>(F)=>`\x1B[${F+D}m`,At=(D=0)=>(F)=>`\x1B[${38+D};5;${F}m`,vt=(D=0)=>(F,w,J)=>`\x1B[${38+D};2;${F};${w};${J}m`,Y2={modifier:{reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],overline:[53,55],inverse:[7,27],hidden:[8,28],strikethrough:[9,29]},color:{black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],blackBright:[90,39],gray:[90,39],grey:[90,39],redBright:[91,39],greenBright:[92,39],yellowBright:[93,39],blueBright:[94,39],magentaBright:[95,39],cyanBright:[96,39],whiteBright:[97,39]},bgColor:{bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],bgBlackBright:[100,49],bgGray:[100,49],bgGrey:[100,49],bgRedBright:[101,49],bgGreenBright:[102,49],bgYellowBright:[103,49],bgBlueBright:[104,49],bgMagentaBright:[105,49],bgCyanBright:[106,49],bgWhiteBright:[107,49]}},UA0=Object.keys(Y2.modifier),bo1=Object.keys(Y2.color),ho1=Object.keys(Y2.bgColor),zA0=[...bo1,...ho1];function yo1(){let D=new Map;for(let[F,w]of Object.entries(Y2)){for(let[J,Q]of Object.entries(w))Y2[J]={open:`\x1B[${Q[0]}m`,close:`\x1B[${Q[1]}m`},w[J]=Y2[J],D.set(Q[0],Q[1]);Object.defineProperty(Y2,F,{value:w,enumerable:!1})}return Object.defineProperty(Y2,"codes",{value:D,enumerable:!1}),Y2.color.close="\x1B[39m",Y2.bgColor.close="\x1B[49m",Y2.color.ansi=Ot(),Y2.color.ansi256=At(),Y2.color.ansi16m=vt(),Y2.bgColor.ansi=Ot(10),Y2.bgColor.ansi256=At(10),Y2.bgColor.ansi16m=vt(10),Object.defineProperties(Y2,{rgbToAnsi256:{value(F,w,J){if(F===w&&w===J){if(F<8)return 16;if(F>248)return 231;return Math.round((F-8)/247*24)+232}return 16+36*Math.round(F/255*5)+6*Math.round(w/255*5)+Math.round(J/255*5)},enumerable:!1},hexToRgb:{value(F){let w=/[a-f\d]{6}|[a-f\d]{3}/i.exec(F.toString(16));if(!w)return[0,0,0];let[J]=w;if(J.length===3)J=[...J].map((X)=>X+X).join("");let Q=Number.parseInt(J,16);return[Q>>16&255,Q>>8&255,Q&255]},enumerable:!1},hexToAnsi256:{value:(F)=>Y2.rgbToAnsi256(...Y2.hexToRgb(F)),enumerable:!1},ansi256ToAnsi:{value(F){if(F<8)return 30+F;if(F<16)return 90+(F-8);let w,J,Q;if(F>=232)w=((F-232)*10+8)/255,J=w,Q=w;else{F-=16;let W=F%36;w=Math.floor(F/36)/5,J=Math.floor(W/6)/5,Q=W%6/5}let X=Math.max(w,J,Q)*2;if(X===0)return 30;let Y=30+(Math.round(Q)<<2|Math.round(J)<<1|Math.round(w));if(X===2)Y+=60;return Y},enumerable:!1},rgbToAnsi:{value:(F,w,J)=>Y2.ansi256ToAnsi(Y2.rgbToAnsi256(F,w,J)),enumerable:!1},hexToAnsi:{value:(F)=>Y2.ansi256ToAnsi(Y2.hexToAnsi256(F)),enumerable:!1}}),Y2}var go1=yo1(),Lt=go1;var RG=new Set(["\x1B",""]),co1=39,FA="\x07",Tt="[",lo1="]",_t="m",LG=`${lo1}8;;`,Rt=(D)=>`${RG.values().next().value}${Tt}${D}${_t}`,xt=(D)=>`${RG.values().next().value}${LG}${D}${FA}`,ao1=(D)=>D.split(" ").map((F)=>z4(F)),DA=(D,F,w)=>{let J=[...F],Q=!1,X=!1,Y=z4(VD(D.at(-1)));for(let[W,K]of J.entries()){let V=z4(K);if(Y+V<=w)D[D.length-1]+=K;else D.push(K),Y=0;if(RG.has(K))Q=!0,X=J.slice(W+1,W+1+LG.length).join("")===LG;if(Q){if(X){if(K===FA)Q=!1,X=!1}else if(K===_t)Q=!1;continue}if(Y+=V,Y===w&&W<J.length-1)D.push(""),Y=0}if(!Y&&D.at(-1).length>0&&D.length>1)D[D.length-2]+=D.pop()},io1=(D)=>{let F=D.split(" "),w=F.length;while(w>0){if(z4(F[w-1])>0)break;w--}if(w===F.length)return D;return F.slice(0,w).join(" ")+F.slice(w).join("")},no1=(D,F,w={})=>{if(w.trim!==!1&&D.trim()==="")return"";let J="",Q,X,Y=ao1(D),W=[""];for(let[p,N]of D.split(" ").entries()){if(w.trim!==!1)W[W.length-1]=W.at(-1).trimStart();let Z=z4(W.at(-1));if(p!==0){if(Z>=F&&(w.wordWrap===!1||w.trim===!1))W.push(""),Z=0;if(Z>0||w.trim===!1)W[W.length-1]+=" ",Z++}if(w.hard&&Y[p]>F){let U=F-Z,z=1+Math.floor((Y[p]-U-1)/F);if(Math.floor((Y[p]-1)/F)<z)W.push("");DA(W,N,F);continue}if(Z+Y[p]>F&&Z>0&&Y[p]>0){if(w.wordWrap===!1&&Z<F){DA(W,N,F);continue}W.push("")}if(Z+Y[p]>F&&w.wordWrap===!1){DA(W,N,F);continue}W[W.length-1]+=N}if(w.trim!==!1)W=W.map((p)=>io1(p));let K=W.join(`
|
|
597
597
|
`),V=[...K],B=0;for(let[p,N]of V.entries()){if(J+=N,RG.has(N)){let{groups:U}=new RegExp(`(?:\\${Tt}(?<code>\\d+)m|\\${LG}(?<uri>.*)${FA})`).exec(K.slice(B))||{groups:{}};if(U.code!==void 0){let z=Number.parseFloat(U.code);Q=z===co1?void 0:z}else if(U.uri!==void 0)X=U.uri.length===0?void 0:U.uri}let Z=Lt.codes.get(Number(Q));if(V[p+1]===`
|