@decaf-ts/mcp-server 1.2.7 → 1.2.8

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.
Files changed (43) hide show
  1. package/dist/assets/code/patterns/builder.enc +0 -0
  2. package/dist/assets/prompts/agent/agent.enc +0 -0
  3. package/dist/assets/prompts/agent/init.enc +0 -0
  4. package/dist/assets/prompts/constitution_commands.enc +0 -0
  5. package/dist/assets/prompts/documentation/class.enc +0 -0
  6. package/dist/assets/prompts/documentation/constant.enc +0 -0
  7. package/dist/assets/prompts/documentation/decorator.enc +0 -0
  8. package/dist/assets/prompts/documentation/file.enc +0 -0
  9. package/dist/assets/prompts/documentation/function.enc +0 -0
  10. package/dist/assets/prompts/documentation/interface.enc +0 -0
  11. package/dist/assets/prompts/documentation/iterate.enc +0 -0
  12. package/dist/assets/prompts/documentation/module.enc +0 -0
  13. package/dist/assets/prompts/documentation/prefix.enc +0 -0
  14. package/dist/assets/prompts/documentation/repo.enc +0 -0
  15. package/dist/assets/prompts/documentation/suffix.enc +0 -0
  16. package/dist/assets/prompts/git_commands.enc +0 -0
  17. package/dist/assets/prompts/jira/operational_prompts.enc +0 -0
  18. package/dist/assets/prompts/jira/system_prompt.enc +0 -0
  19. package/dist/assets/prompts/mode_commands.enc +0 -0
  20. package/dist/assets/prompts/plan_commands.enc +0 -0
  21. package/dist/assets/prompts/repository/readme.enc +0 -0
  22. package/dist/assets/prompts/repository/release_notes.enc +0 -0
  23. package/dist/assets/prompts/repository/setup.enc +0 -0
  24. package/dist/assets/prompts/specification_commands.enc +0 -0
  25. package/dist/assets/prompts/startup_command.enc +0 -0
  26. package/dist/assets/prompts/task_commands.enc +0 -0
  27. package/dist/assets/prompts/tests/coverage.enc +0 -0
  28. package/dist/assets/templates/AGENTS.enc +0 -0
  29. package/dist/assets/templates/agents_template.enc +0 -0
  30. package/dist/assets/templates/constitution_template.enc +0 -0
  31. package/dist/assets/templates/decaf/context/logCtx.enc +0 -0
  32. package/dist/assets/templates/decaf/services/client_based_service.enc +0 -0
  33. package/dist/assets/templates/decaf/services/model_service.enc +3 -3
  34. package/dist/assets/templates/decaf/services/service.enc +0 -0
  35. package/dist/assets/templates/decaf_guidelines.enc +1 -1
  36. package/dist/assets/templates/instructions_template.enc +0 -0
  37. package/dist/assets/templates/jira_templates.enc +0 -0
  38. package/dist/assets/templates/plan_template.enc +0 -0
  39. package/dist/assets/templates/specification_template.enc +0 -0
  40. package/dist/assets/templates/task_template.enc +0 -0
  41. package/dist/mcp-server.cjs +1 -1
  42. package/dist/mcp-server.js +1 -1
  43. package/package.json +1 -1
Binary file
Binary file
Binary file
@@ -1,3 +1,3 @@
1
- DCAF1������j�͉J�ż�!&0������ ������Ց
2
- �`��rx�@U ��n���{j��HC
3
- 7w��x�rr��|�N���EE��l��>�몵���z�h*?pX��h�|�6�5�W��w���#�Ž룪�lZ4�L$!z&��0��E���Lꓑk�� ƞ��8�&U��Y@6�</���̽Vc�
1
+ DCAF1�O�J�+E%R��`rn�r-�b7��zxn|gt�v׍�.Z H2����ݏ#ZdP�e� �!��|LQ��]�}��u����{Q�[���;3�T9ӋI��n�
2
+ �u��� �q���2vه�*��p�t��{BYƲ��ըE�h͋�mO>N�u�%`���J�!?�g&k�:{U2$�����^2s���Ki
3
+ 2o#���(V�����O:�($�m�<�8d���dlZ�z$Â�B\��km��ۦtG���",�\�j�����Q��~��~* yBQpUr�;U�ó'f��Q@V
@@ -1 +1 @@
1
- DCAF1P(_���0F1�a�}S�{-R��|��KV�Ho��Д_Dk(��t��0} A�K�>O�{���wx
1
+ DCAF1������ x��{t�����\ �����ڱ�{��6C8��� PfT�l�0r�/kf$
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env node
2
- var e,t;e=this,t=function(e,t,r,s,n,i,o,a,c,l,p,d,u,m,h,f,g,y,b,v,w,S,j){"use strict";function x(e){var t=Object.create(null);return e&&Object.keys(e).forEach(r=>{if("default"!==r){var s=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,s.get?s:{enumerable:!0,get:()=>e[r]})}}),t.default=e,Object.freeze(t)}var _=x(t),I=x(n);class z extends r.MiniLogger{log(e,t,s,n){const i=this.config("level");r.NumericLogLevels[i],r.NumericLogLevels[e]}}const E=(e,t,...r)=>{const s=(e=>{if("string"==typeof e)return e;if(!e)return"unknown";if("function"==typeof e)return e.name||"unknown";if("object"==typeof e&&"constructor"in e){const t=e.constructor;if(t&&t.name)return t.name}return"unknown"})(e);return new z(s,t)},k=["\x1b[38;5;215m","\x1b[38;5;209m","\x1b[38;5;205m","\x1b[38;5;210m","\x1b[38;5;217m","\x1b[38;5;216m","\x1b[38;5;224m","\x1b[38;5;230m","\x1b[38;5;230m"];var T,A,O,N,C;(e=>{e[e.NONE=0]="NONE",e[e.BASIC=1]="BASIC",e[e.ADVANCED=2]="ADVANCED",e[e.HIGH=3]="HIGH"})(T||(T={})),(e=>{e[e.NONE=0]="NONE",e[e.LOW=1]="LOW",e[e.MEDIUM=2]="MEDIUM",e[e.HIGH=3]="HIGH"})(A||(A={})),(e=>{e[e.FREE=0]="FREE",e[e.LOW=1]="LOW",e[e.MEDIUM=2]="MEDIUM",e[e.HIGH=3]="HIGH"})(O||(O={}));class H extends o.Model{get log(){return this._log||(this._log=r.Logging.for(this)),this._log}constructor(e){super(e)}logFor(e){const{sessionId:t,requestId:r,authInfo:s}=e||{};let n="string"==typeof t&&t.length>0?this.log.for(t):this.log;return s&&s.clientId&&(n=n.for(s.clientId)),r&&(n=n.for(r.toString())),n}setDescription(e){return this.description=e,this}getDescription(){return this.description}setName(e){return this.name=e,this}getName(){return this.name}setTitle(e){return this.title=e,this}}i.__decorate([o.required(),i.__metadata("design:type",String)],H.prototype,"description",void 0),i.__decorate([o.required(),i.__metadata("design:type",String)],H.prototype,"name",void 0),i.__decorate([o.required(),i.__metadata("design:type",String)],H.prototype,"title",void 0);class D extends H{constructor(e){super(e),this.reasoning=T.NONE,this.effort=A.NONE,this.cost=O.FREE}setReasoning(e){return this.reasoning=e,this}setEffort(e){return this.effort=e,this}setCost(e){return this.cost=e,this}}function J(e){if(!e)return;let t=e,r=t&&t._def;for(;r&&"ZodObject"!==r.typeName;){if("ZodEffects"===r.typeName&&r.schema)t=r.schema;else if("ZodOptional"===r.typeName&&r.innerType)t=r.innerType;else if("ZodDefault"===r.typeName&&r.innerType)t=r.innerType;else if("ZodNullable"===r.typeName&&r.innerType)t=r.innerType;else{if(!r.schema)return;t=r.schema}r=t&&t._def}return r&&"ZodObject"===r.typeName?r:void 0}function q(e,t="schema"){if(J(e))return e;if(e&&"object"==typeof e){const t=e.def&&"object"==typeof e.def?e.def:void 0,r=t&&(t.shape||"object"===t.type)&&t.shape||("object"===e.type?e.shape:void 0)||(t&&"object"===t.type?{}:void 0);if(t||"object"===e.type||r){const e={};if(r&&"object"==typeof r)for(const[t,s]of Object.entries(r))e[t]=M(s)?s:a.z.any();return a.z.object(e)}}throw Error(`Registration error: provided a non-canonical ${t}. Export a ZodObject (z.object(...)).`)}function P(e){if(!e)return;if(e&&"object"==typeof e&&!e._def)return e.def&&"object"==typeof e.def&&e.def.shape?e.def.shape:e;const t=J(e);return t?"function"==typeof t.shape?t.shape():t.shape||void 0:void 0}function M(e){return!(!e||"object"!=typeof e||!e._def)}i.__decorate([o.required(),i.__metadata("design:type",Number)],D.prototype,"reasoning",void 0),i.__decorate([o.required(),i.__metadata("design:type",Number)],D.prototype,"effort",void 0),i.__decorate([o.required(),i.__metadata("design:type",Number)],D.prototype,"cost",void 0),(e=>{e.ASSETS="assets"})(N||(N={})),(e=>{e.PROMPT="prompts",e.DOCUMENTATION="documentation",e.CODE="code"})(C||(C={}));const R=Buffer.from("DCAF1","ascii");function $(e){let r=n.resolve(e);for(;;){if(t.existsSync(n.join(r,"package.json")))return r;const e=n.dirname(r);if(e===r)break;r=e}}const L=process.argv?.[1]?$(n.dirname(n.resolve(process.argv[1]))):void 0,F=(()=>{const e=Error().stack;if(!e)return;const t=e.split(/\r?\n/).slice(1);for(const e of t){const t=e.match(/\(?([^()]+?):\d+:\d+\)?/);if(!t)continue;let r=t[1];if(r.startsWith("file://"))try{r=m.fileURLToPath(r)}catch{continue}if(!r.includes("node:internal"))return n.dirname(r)}})(),B=F?$(F):void 0,W=L??B??process.cwd();function U(...e){return n.join(W,...e)}function K(e){let t=e;for(;;){const e=I.join(t,"lib","assets");if(_.existsSync(e))return e;const r=I.join(t,"src","assets");if(_.existsSync(r))return r;const s=I.join(t,"assets");if(_.existsSync(s))return s;const n=I.dirname(t);if(n===t)break;t=n}}function Y(){const e=process.env.DECAF_ASSET_DIR||process.env.MCP_ASSET_DIR||process.env.ASSET_DIR||"";if(e&&_.existsSync(e))return e;const t=K(__dirname);if(t)return t;const r=process.argv?.[1];if(r){const e=K(I.dirname(r));if(e)return e}const s=[W,process.env.INIT_CWD].filter(Boolean);for(const e of s){const t=K(e);if(t)return t}return U("assets")}let V=class extends r.LoggedClass{constructor(e){super(),this.basePath=e||Y()}listAssets(...e){const t=I.join(this.basePath,...e);return _.readdirSync(t)}listPrompts(){return this.listAssets(C.PROMPT)}getAsset(e,t="md",...r){const s=I.join(this.basePath,...r),n=(e,t=!1)=>{try{return t?(e=>{if(e.length<R.length+16+12+16)throw Error("Invalid prompt payload (too short)");if(!e.subarray(0,R.length).equals(R))throw Error("Invalid prompt payload (bad magic)");const t=process.env.ENCRYPTION_KEY||"";if(!t)throw Error("Missing encryption key. Set ENCRYPTION_KEY to load obfuscated assets.");let r=R.length;const s=e.subarray(r,r+16);r+=16;const n=e.subarray(r,r+12);r+=12;const i=e.subarray(r,r+16);r+=16;const o=e.subarray(r),a=((e,t)=>d.scryptSync(e,t,32))(t,s),c=d.createDecipheriv("aes-256-gcm",a,n);c.setAuthTag(i);const l=Buffer.concat([c.update(o),c.final()]);return u.gunzipSync(l)})(_.readFileSync(e)).toString("utf-8"):_.readFileSync(e,"utf-8")}catch(e){if("ENOENT"===e.code)return null;throw e}},i=n(I.join(s,`${e}.${t}`),"enc"===t);if(null!==i)return i;const o=n(I.join(s,e+".enc"),!0);if(null!==o)return o;throw Error("Asset not found: "+I.join(s,`${e}.${t}`))}getAllAssets(e,...t){return this.listAssets(e,...t).reduce((r,s)=>{const n=I.extname(s),i=I.basename(s,n),o=n.replace(/^\./,"")||void 0;return r[i]=this.getAsset(i,o??void 0,e,...t),r},{})}toPromptDef(e){const t=e=>"number"==typeof e?e:"string"==typeof e?(e=>{switch(e){case"none":return T.NONE;case"basic":return T.BASIC;case"advanced":return T.ADVANCED;case"high":return T.HIGH;case"medium":return A.MEDIUM;case"low":return O.LOW;case"free":return O.FREE;default:throw new p.InternalError("Cannon convert unknown level "+e)}})(e.toLowerCase()):T.NONE;return e.effort=t(e.effort),e.reasoning=t(e.reasoning),e.cost=t(e.cost),e}getPrompt(e,...t){const s=this.getAsset(r.toSnakeCase(e),"json",C.PROMPT,...t);let n;try{n=JSON.parse(s)}catch(r){throw new p.SerializationError(`Failed to parse prompt ${e} in categories ${t}: ${r}`)}return this.toPromptDef(n)}getAllPrompts(...e){const t=this.getAllAssets(C.PROMPT,...e);return Object.entries(t).reduce((t,[r,s])=>{try{t[r]=JSON.parse(s)}catch(t){throw new p.SerializationError(`Failed to parse prompt ${r} in categories ${e}: ${t}`)}return t},t)}};V=i.__decorate([c.injectable(),i.__metadata("design:paramtypes",[String])],V);class G extends D{constructor(e){super(e)}setCb(e){return this.cb=e,this}setArgsSchema(e){return this.argsSchema=e,this}static get builder(){return new G}static patchPrompt(e,t,s,n){const i=(t=Array.isArray(t)?t:Object.keys(t)).filter(e=>!Object.prototype.hasOwnProperty.call(s,e));if(i.length)throw new p.ValidationError("Missing replacements for placeholders: "+i.join(", "));n&&(n.verbose("Patching prompt with placeholders: "+JSON.stringify(t)),n.debug("Values: "+JSON.stringify(s)));const o=t.reduce((e,t)=>(e[t]=s[t],e),{});return r.sf(e,o)}patchPrompt(e,t,r,s){return G.patchPrompt(e,t,r,s||this.log.for(this.patchPrompt))}build(e,t){const r=this.log.for(this.build),s=this.hasErrors();if(s)throw new p.ValidationError(s.toString());try{this.argsSchema&&q(this.argsSchema,"argsSchema");const r=P(this.argsSchema);return e.registerPrompt(this.name,{title:this.title,description:this.description,argsSchema:r},async(e,r)=>{const s=this.logFor(r);e=Object.assign({},t,e||{}),s.verbose(`Executing prompt ${this.name} with args: ${JSON.stringify(e)}`),e._meta=Object.assign(e._meta||{},{usage:{reasoning:this.reasoning,effort:this.effort,cost:this.cost}});const n=await Promise.resolve(this.cb(e,r));return s.verbose(`Prompt ${this.name} executed successfully.`),s.debug("Prompt execution meta: "+JSON.stringify(n._meta)),n})}catch(e){throw r.error("Failed to register prompt "+(this.name||this.constructor.name),e),e}}}i.__decorate([c.inject(V),i.__metadata("design:type",V)],G.prototype,"assets",void 0),i.__decorate([o.required(),i.__metadata("design:type",Object)],G.prototype,"cb",void 0),i.__decorate([o.required(),i.__metadata("design:type",a.ZodObject)],G.prototype,"argsSchema",void 0),i.__decorate([l.prop(),i.__metadata("design:type",Object)],G.prototype,"placeholders",void 0);class Z extends G{setCategory(e){return this.promptCategory=e,this}addPrefix(e){return this.prefixes=this.prefixes||[],this.prefixes.push(e),this}addSuffix(e){return this.suffixes=this.suffixes||[],this.suffixes.push(e),this}constructor(e){super(e)}build(e){const t=this.assets.getPrompt(this.name,this.promptCategory);o.Model.fromObject(this,t);const r=new Set((l.Metadata.properties(Z)||[]).filter(e=>!["assets","promptCategory","prefixes","suffixes"].includes(e)));["cb","argsSchema"].forEach(e=>r.add(e));const s=this.hasErrors(...Array.from(r));if(s)throw new p.ValidationError(s.toString());const n=(this.prefixes||[]).map(e=>this.assets.getPrompt(e,this.promptCategory)),i=(this.suffixes||[]).map(e=>this.assets.getPrompt(e,this.promptCategory)),c=[...new Set([...t.placeholders,...n.map(e=>e.placeholders||[]),...i.map(e=>e.placeholders||[])].flat())].reduce((e,t)=>(e[t]=a.z.string().describe("The description for "+t),e),{});return this.setArgsSchema(a.z.object(c)),this.setCb((e,t)=>{const r=this.logFor(t).for(Z).for(this.promptCategory).for(this.name);function s(e=[]){return Array.isArray(e)?e:Object.keys(e)}const n=(this.prefixes||[]).map(e=>this.assets.getPrompt(e,this.promptCategory)),i=(this.suffixes||[]).map(e=>this.assets.getPrompt(e,this.promptCategory)),o=this.assets.getPrompt(this.name,this.promptCategory),a=[...new Set([...n.map(e=>s(e.placeholders)).flat(),...i.map(e=>s(e.placeholders)).flat(),...s(o.placeholders).flat()])];return{messages:[{role:"user",content:{type:"text",text:this.patchPrompt([...n.map(e=>e.prompt),o.prompt,...i.map(e=>e.prompt)].join("\n\n"),a,e,r)}}],_meta:{}}}),super.build(e)}setReasoning(e){throw new p.InternalError("Named prompt builders don't require callback")}setEffort(e){throw new p.InternalError("Named prompt builders don't require callback")}setCost(e){throw new p.InternalError("Named prompt builders don't require callback")}setDescription(e){throw new p.InternalError("Named prompt builders don't require callback")}setTitle(e){throw new p.InternalError("Named prompt builders don't require callback")}static get builder(){return new Z}}i.__decorate([o.required(),i.__metadata("design:type",String)],Z.prototype,"promptCategory",void 0),i.__decorate([o.list(String),o.minlength(1),i.__metadata("design:type",Array)],Z.prototype,"prefixes",void 0),i.__decorate([o.minlength(1),o.list(String),i.__metadata("design:type",Array)],Z.prototype,"suffixes",void 0);const Q=G.builder.setName("example.prompt").setTitle("Example prompt").setDescription("Example prompt for testing").setArgsSchema(a.z.object({message:a.z.string().optional()})).setCb(async e=>{const t=e.message??"default";return{messages:[{role:"assistant",content:{type:"text",text:t}}],content:[],structuredContent:{message:t},result:{message:t}}}),X=G.builder.setName("interactive.jsdoc").setTitle("Interactive JSDoc prompt").setDescription("Interactive prompt for jogging JSDoc helpers").setArgsSchema(a.z.object({gist:a.z.string().optional()})).setCb(async e=>{const t=e.gist??"interactive jsdoc response";return{messages:[{role:"assistant",content:{type:"text",text:t}}],content:[],structuredContent:{message:t},result:{message:t}}}),ee=Object.assign(X,{name:X.getName()});var te;function re(e,t=[],r=[]){const s=Z.builder.setCategory(te.DOCS).setName(e);return["prefix",...t].forEach(e=>s.addPrefix(e)),["suffix",...r].forEach(e=>s.addSuffix(e)),s}(e=>{e.DOCS="documentation",e.CODE="code"})(te||(te={}));const se=[re("class"),re("constant"),re("decorator"),re("function"),re("module"),re("file"),re("repo",[],["iterate"])],ne=a.z.object({className:a.z.string().describe("the class name to turn into a builder")}),ie=[Q,ee,...se,G.builder.setName("ts.code.dp.builder").setTitle("Typescript builder design patter prompt").setDescription("for a class, with a defined set of properties, scafold a builder design pattern").setArgsSchema(ne).setReasoning(T.BASIC).setCb((e,t)=>(e.className=r.toPascalCase(e.className),{messages:[{role:"user",content:{type:"text",text:`You're a senior TypeScript developer writing typescript code.You're a senior TypeScript developer writing typescript code.\nTransform the selected class into a builder design pattern implementation in Typescript.\nuse @decaf-ts validation decorators to enforce the validation of your builder.\n\n- must extend the Model Class from @decaf-ts/decorator-validation;\n- each property must be marked as protected;\n- each property must have a setter method that returns 'this' for chaining;\n- the build() method must validate the properties using hasErrors() method from Model class;\n- if validation fails, throw an error with the validation errors;\n- if validation passes, return an instance of the original class with the set properties;\n- optionally (but do so by default) add the static builder and from methods from the example;\n- if the clasee already follows the pattern but has properties without decoration or without setters, simple add them;\n\nexample:\n\noriginal class:\n\`\`\`typescript\nexport class ${e.className} {\n description!: string;\n name!: string = "default name";\n title!: string;\n age?: string;\n dateOfBirth!: Date;\n}}\n\`\`\` \n\nresulting builder pattern implementation:\n\`\`\`typescript\nexport class ${e.className}Builder extends Model {\n\n @minlength(10\n @required()\n protected description!: string;\n \n @required()\n protected name!: string = "default value;\n \n @required()\n protected title!: string;\n \n @min(18)\n protected age?: string;\n \n @date()\n protected dateOfBirth!: Date;\n\n protected constructor(arg?: ModelArg<${e.className}Builder>>) {\n super(arg);\n Model.fromModel(this, arg);\n }\n\n setDescription(value: string) {\n this.description = value;\n return this;\n }\n\n setName(value: string) {\n this.name = value;\n return this;\n }\n\n setTitle(value: string) {\n this.title = value;\n return this;\n }\n setAge(value: number) {\n this.age = value;\n return this;\n }\n setDate(value: Date) {\n this.age = value;\n return this;\n }\n \n build(...args: any[]): ${e.className}Builder | Promise<${e.className}Builder> {\n const errs = this.hasErrors();\n if (errs) throw new Error(errs.toString());\n \n return // code that builds OBJ here\n }\n \n static get builder(): ${e.className}Builder {\n return new ${e.className}Builder(); // static method to get a new builder instance\n }\n \n static from<K extends keyof ${e.className}Builder>(obj: K, ${e.className}Builder[K]): ${e.className}Builder {\n return new ${e.className}Builder(); // static method to create a builder from an object\n }\n}\n\`\`\` \n\n`}}],_meta:{}}))];class oe extends D{setAnnotations(e){return this.annotations=Object.assign(this.annotations,e),this}setCb(e){return this.cb=e,this}setInputSchema(e){return this.inputSchema=e,this}setOutputSchema(e){return this.outputSchema=e,this}constructor(e){super(e),this.annotations={readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1}}static get builder(){return new oe}build(e){const t=this.hasErrors();if(t)throw Error(t.toString());try{this.inputSchema&&q(this.inputSchema,"inputSchema"),this.outputSchema&&q(this.outputSchema,"outputSchema");const t=P(this.inputSchema),r=P(this.outputSchema);return e.registerTool(this.name,{title:this.title,description:this.description,inputSchema:t,outputSchema:r,annotations:this.annotations,_meta:{usage:{reasoning:this.reasoning,effort:this.effort,cost:this.cost}}},async(e,t)=>{const r=this.logFor(t);r.verbose(`Executing tool ${this.name} with args: ${JSON.stringify(e)}`),t._meta=Object.assign(t._meta||{},{usage:{reasoning:this.reasoning,effort:this.effort,cost:this.cost}});const s=await Promise.resolve(this.cb(e,t));return r.verbose(`Tool ${this.name} executed successfully.`),r.debug("Tool execution meta: "+JSON.stringify(s._meta)),s})}catch(e){const t=e?.message||e+"";if("string"==typeof t&&t.includes("already registered"))return r.Logging.for(this).warn(`Tool ${this.name} already registered - skipping duplicate registration`),{name:this.name};throw r.Logging.for(this).error("Error building tool",e),e}}}i.__decorate([o.required(),i.__metadata("design:type",Object)],oe.prototype,"annotations",void 0),i.__decorate([o.required(),i.__metadata("design:type",Object)],oe.prototype,"cb",void 0),i.__decorate([o.required(),i.__metadata("design:type",Function)],oe.prototype,"inputSchema",void 0);const ae=oe.builder.setName("example.tool").setTitle("Example tool").setDescription("A smoke tool used for quick testing").setInputSchema(a.z.object({})).setCb(async()=>({content:[{type:"text",text:"example tool ok"}],result:{status:"ok"}}));Object.assign(ae,{name:ae.getName()});const ce=oe.builder.setName("file.summarizer").setTitle("File summarizer").setDescription("Summaries files for quick previews").setInputSchema(a.z.object({filePath:a.z.string().optional()})).setCb(async()=>({content:[{type:"text",text:"file summary stub"}],result:{summary:"file summary stub"}}));Object.assign(ce,{name:ce.getName()});const le="##VERSION##";l.Metadata.registerLibrary("##PACKAGE##",le);const pe={mcpId:"decaf",name:"decaf-ts mcp server",title:"Decaf-TS MCP Server",description:"Provides precise coding assistance for the decaf-ts framework",version:le,websiteUrl:"https://decaf-ts.github.io",repositoryUrl:"https://github.com/decaf-ts/mcp-server",license:"AGPL-3.0",workingDir:W,assetDir:Y(),contacts:[{name:"Decaf-TS",url:"https://decaf-ts.github.io"}],tags:"server,official,decaf-ts",metadata:{},icons:[{src:"workdocs/assets/favicon.svg",mimeType:"image/svg+xml",sizes:"any"}],jira:{host:process.env.JIRA__HOST||"decaf-ts.atlassian.net",email:process.env.JIRA__EMAIL||"",apiKey:process.env.JIRA__API_KEY||process.env.JIRA__APIKEY||"",projectKey:process.env.JIRA__PROJECT_KEY||void 0,issueType:process.env.JIRA__ISSUE_TYPE||void 0,parentIssue:process.env.JIRA__PARENT_ISSUE||void 0},level:r.LogLevel.error},de=r.LoggedEnvironment.accumulate(pe);function ue(){const{host:e,email:t,apiKey:r,projectKey:s,issueType:n}=de.jira;return{host:e?.trim(),email:t?.trim(),apiKey:r?.trim(),projectKey:s?.trim(),issueType:n?.trim(),parentIssue:de.jira.parentIssue?.trim()}}function me(){const e=ue();return[{name:"JIRA__HOST",required:!0,description:"Atlassian host (e.g. decaf-ts.atlassian.net) where your Jira instance is hosted.",value:e.host},{name:"JIRA__EMAIL",required:!0,description:"Email address of the Jira account that has API access.",value:e.email},{name:"JIRA__API_KEY",required:!0,description:"API token created in your Atlassian profile (a.k.a. APIKEY alias) for authenticating requests.",sensitive:!0,value:e.apiKey},{name:"JIRA__PROJECT_KEY",required:!1,description:"Default Jira project key (e.g. DECAF) used when an issue creation request omits a project.",value:e.projectKey},{name:"JIRA__ISSUE_TYPE",required:!1,description:"Default Jira issue type (e.g. Task, Bug) used when creating issues without an explicit type.",value:e.issueType},{name:"JIRA__PARENT_ISSUE",required:!1,description:"Default parent issue key (e.g. DECAF-123) applied when a child issue is created without an explicit parent.",value:e.parentIssue}]}function he(e){const t=e.value?((e,t)=>{if(e)return t?"<configured>":e})(e.value,e.sensitive):"not set",r=e.required?"(required)":"(optional)";return`\u2022 ${e.name} ${r}: ${e.description} Current state: ${t}.`}r.Logging.setConfig(de);class fe extends Error{constructor(e){const t=me(),r=(e=>{const t=me();return`${e.length?`Missing Jira credentials: ${e.map(e=>e.name).join(", ")}.`:"Jira credentials are configured."}\n\nThis setup uses the following environment variables:\n${t.map(he).join("\n")}`})(e);super(r),this.name="MissingJiraEnvironmentError",this.descriptors=t,this.missing=e,"function"==typeof Error.captureStackTrace&&Error.captureStackTrace(this,fe)}}function ge(e){if(!e)return{code:"jira_error",message:"Unknown Jira error",details:{raw:e}};const t=e?.status??e?.statusCode??e?.response?.status??e?.response?.statusCode,r="number"==typeof t?t:Number(t)||void 0,s=e?.response?.data??e?.data??e?.response?.body??e?.body,n=[];"string"==typeof e?.message&&n.push(e.message),((e,t)=>{e&&(Array.isArray(e.errorMessages)&&e.errorMessages.forEach(e=>"string"==typeof e&&t.push(e)),"string"==typeof e.errorMessage&&t.push(e.errorMessage),e.errorCollection&&Array.isArray(e.errorCollection.errors)&&e.errorCollection.errors.forEach(e=>{"string"==typeof e?t.push(e):e&&"string"==typeof e.message&&t.push(e.message)}),e?.errors&&"object"==typeof e.errors&&Object.values(e.errors).forEach(e=>{"string"==typeof e?t.push(e):"string"==typeof e?.message&&t.push(e.message)}))})(s,n);const i=r?`Jira API error (${r})`:"Jira API error",o=n.length>0?n.join(" | "):i;return{code:r?"jira_"+r:e?.code??"jira_error",message:o,details:{httpStatus:r,body:s,raw:e}}}const ye=a.z.object({issueId:a.z.string().min(1),deleteSubtasks:a.z.boolean().optional().default(!0)}),be={name:"jira.issue-delete",inputSchema:ye,runTool:async(e,t)=>{try{const r=ye.parse(t),s=e.issues??e.issue??e,n=s?.delete??s?.deleteIssue;if("function"!=typeof n)throw Error("jira client delete endpoint is not available");return await n.call(s,{issueId:r.issueId,deleteSubtasks:r.deleteSubtasks}),{success:!0,message:`Issue ${t.issueId} deleted successfully`}}catch(e){throw ge(e)}}},ve=a.z.object({issueId:a.z.string().min(1),expand:a.z.string().optional(),fields:a.z.array(a.z.string()).optional(),properties:a.z.array(a.z.string()).optional()}),we={name:"jira.issue-read",inputSchema:ve,runTool:async(e,t)=>{try{const r=ve.parse(t),s={issueIdOrKey:r.issueId};r.expand&&(s.expand=r.expand),r.fields&&(s.fields=r.fields),r.properties&&(s.properties=r.properties);const n=await e.issues.get(s);return n?.data??n}catch(e){throw ge(e)}}};function Se(e,t,r){const s=((e.url??"")+"").match(/^(attachment|jira-attachment):(.+)$/i);if(!s)return null;const n=s[2],i=r.resolveAttachment?.(n);return i?{type:"block",node:{type:"mediaSingle",attrs:{layout:"center"},content:[{type:"media",attrs:{type:"file",id:i.id,collection:i.collection??"attachments"}}]}}:null}function je(e,t){if(!e)return[];if(!t.enableAtMentions&&!t.enableEmojiShortcodes)return[{type:"text",text:e}];let r=0;const s=[],n=/(^|[^A-Za-z0-9_])@([A-Za-z0-9._-]{1,64})/g,i=/:([a-z0-9_+-]{1,64}):/gi;for(;r<e.length;){const o=_e(t.enableAtMentions?xe(n,e,r):null,t.enableEmojiShortcodes?xe(i,e,r):null);if(!o){s.push({type:"text",text:e.slice(r)});break}if(o.index>r&&s.push({type:"text",text:e.slice(r,o.index)}),"mention"===o.kind){const{full:e,groups:n}=o,i=n[0]??"",a=n[1]??"";i&&s.push({type:"text",text:i});const c=t.resolveMention?.(a);c?s.push({type:"mention",attrs:{id:c.id,text:c.text}}):s.push({type:"text",text:"@"+a}),r=o.index+e.length;continue}if("emoji"===o.kind){const{full:e,groups:n}=o,i=`:${n[0]}:`,a=t.resolveEmoji?.(i);s.push({type:"emoji",attrs:a?{shortName:a.shortName,text:a.text}:{shortName:i}}),r=o.index+e.length;continue}}return(e=>{const t=[];for(const r of e){const e=t[t.length-1];"text"!==r.type||"text"!==e?.type||e.marks||r.marks?t.push(r):e.text=(e.text??"")+(r.text??"")}return t})(s)}function xe(e,t,r){e.lastIndex=r;const s=e.exec(t);if(!s)return null;const n=e.source.includes("@")?"mention":"emoji";return{index:s.index,full:s[0],groups:s.slice(1),kind:n}}function _e(e,t){return e?t&&e.index>t.index?t:e:t}function Ie(e){const t=(e.children??[])[0];return"text"===t?.type?(t.value??"")+"":"paragraph"===t?.type?((t.children??[]).map(e=>"text"===e.type?(e.value??"")+"":"").join("")||"")+"":""}function ze(e){const t=((e??"")+"").toLowerCase().trim();return t?"info"===t||"note"===t||"success"===t||"warning"===t||"error"===t?t:"danger"===t?"error":null:null}function Ee(e){const t=((e??"")+"").toLowerCase().trim();return!t||"neutral"!==t&&"green"!==t&&"yellow"!==t&&"red"!==t&&"blue"!==t&&"purple"!==t?null:t}function ke(e,t){const r=[];for(const s of e??[])if(s?.type)if("text"!==s.type)if("strong"!==s.type)if("emphasis"!==s.type)if("delete"!==s.type)if("inlineCode"!==s.type)if("break"!==s.type){if("link"===s.type){const e=(s.url??"")+"",n=Ae(s.children??[],e),i=Se(s,0,t);if(i){"inline"===i.type?r.push(i.node):r.push({type:"text",text:n,marks:[{type:"link",attrs:{href:e}}]});continue}if(t.enableSmartCards&&Oe(n,e)){r.push({type:"inlineCard",attrs:{url:e}});continue}r.push({type:"text",text:n,marks:[{type:"link",attrs:{href:e}}]});continue}if("textDirective"===s.type&&"status"===s.name){const e=Ie(s)||"Status",t=Ee(s.attributes?.color)??"neutral";r.push({type:"status",attrs:{text:e,color:t}});continue}if("textDirective"===s.type&&"emoji"===s.name){const e=Ne(s);r.push(Ce(e,t));continue}}else r.push({type:"hardBreak"});else r.push({type:"text",text:(s.value??"")+"",marks:[{type:"code"}]});else r.push(...Te(ke(s.children??[],t),{type:"strike"}));else r.push(...Te(ke(s.children??[],t),{type:"em"}));else r.push(...Te(ke(s.children??[],t),{type:"strong"}));else r.push(...je((s.value??"")+"",t));return r.filter(e=>!("text"===e.type&&""===(e.text??"")))}function Te(e,t){return e.map(e=>{if("text"!==e.type)return e;const r=e.marks?[...e.marks,t]:[t];return{...e,marks:r}})}function Ae(e,t){const r=[];for(const t of e??[])"text"===t.type||"inlineCode"===t.type?r.push((t.value??"")+""):"emphasis"!==t.type&&"strong"!==t.type&&"delete"!==t.type||r.push(Ae(t.children??[],""));return r.join("")||t}function Oe(e,t){const r=(e??"").trim(),s=(t??"").trim();return r===s&&/^https?:\/\//i.test(s)}function Ne(e){return(e.children??[]).map(e=>"text"===e.type?(e.value??"")+"":"").join("").trim()||""}function Ce(e,t){const r=e.startsWith(":")?e:`:${e}:`,s=t.resolveEmoji?.(r);return s?{type:"emoji",attrs:{shortName:s.shortName,text:s.text}}:{type:"emoji",attrs:{shortName:r}}}function He(e){return e?"string"==typeof e?e:"text"===e.type||"inlineCode"===e.type?(e.value??"")+"":Array.isArray(e.children)?e.children.map(He).join(""):"":""}function De(e,t){if(!e?.type)return null;if((e=>"containerDirective"===e?.type&&"panel"===e?.name)(e))return((e,t)=>{const r=e.attributes??{},s=ze(r.type)??"info",n="string"==typeof r.title?r.title:void 0,i=(e.children??[]).map(e=>De(e,t)).flat().filter(Boolean);return{type:"panel",attrs:{panelType:s,...n?{panelType:s,title:n}:{panelType:s}},content:i.length?i:[{type:"paragraph",content:[]}]}})(e,t);switch(e.type){case"heading":return{type:"heading",attrs:{level:qe(e.depth??1,1,6)},content:ke(e.children??[],t)};case"paragraph":{const r=(e=>{const t=e.children??[];if(1!==t.length)return null;const r=t[0];if("image"!==r?.type)return null;const s=(r.url??"")+"";return s?{type:"mediaSingle",attrs:{layout:"center"},content:[{type:"media",attrs:{type:"external",url:s}}]}:null})(e);return r||{type:"paragraph",content:ke(e.children??[],t)}}case"blockquote":return{type:"blockquote",content:(e.children??[]).map(e=>De(e,t)).flat().filter(Boolean)};case"list":return((e,t)=>t.enableTaskLists&&(e.children??[]).some(e=>"boolean"==typeof e.checked)?((e,t)=>{const r=[];let s=0;for(const n of e.children??[]){if("boolean"!=typeof n.checked)continue;s+=1;const e=(n.children??[]).map(e=>De(e,t)).flat().filter(Boolean);r.push({type:"taskItem",attrs:{localId:"task-"+s,state:n.checked?"DONE":"TODO"},content:e.length?e:[{type:"paragraph",content:[]}]})}return{type:"taskList",content:r}})(e,t):{type:e.ordered?"orderedList":"bulletList",content:(e.children??[]).map(e=>((e,t)=>{const r=(e.children??[]).map(e=>De(e,t)).flat().filter(Boolean);return{type:"listItem",content:r.length?r:[{type:"paragraph",content:[]}]}})(e,t))})(e,t);case"code":{const r=((e,t)=>{const r=(e??"").toString().trim().toLowerCase();return r?t.enableMermaid&&"mermaid"===r?"mermaid":(e=>{const t=e.trim().toLowerCase();return{js:"javascript",javascript:"javascript",jsx:"javascript",ts:"typescript",typescript:"typescript",tsx:"typescript",py:"python",python:"python",rb:"ruby",ruby:"ruby",sh:"bash",bash:"bash",zsh:"bash",shell:"bash",yml:"yaml",yaml:"yaml",json:"json",toml:"toml",xml:"xml",html:"html",css:"css",scss:"scss",sql:"sql",go:"go",rust:"rust",java:"java",c:"c",cpp:"cpp","c++":"cpp",cs:"csharp",csharp:"csharp",php:"php",kotlin:"kotlin",swift:"swift",md:"markdown",markdown:"markdown",graphql:"graphql",gql:"graphql",dockerfile:"docker",makefile:"make",ini:"ini"}[t]??t})(r):null})(e.lang,t);return{type:"codeBlock",attrs:{language:r},content:[{type:"text",text:(e.value??"")+""}]}}case"thematicBreak":return{type:"rule"};case"table":return((e,t)=>({type:"table",content:(e.children??[]).map((e,r)=>({type:"tableRow",content:(e.children??[]).map(e=>({type:0===r?"tableHeader":"tableCell",content:[{type:"paragraph",content:ke(e.children??[],t)}]}))}))}))(e,t);case"leafDirective":return"status"===e.name?(e=>{const t=Ee((e.attributes??{}).color)??"neutral";return{type:"paragraph",content:[{type:"status",attrs:{text:Ie(e)||"Status",color:t}}]}})(e):"panel"===e.name?((e,t)=>{const r=e.attributes??{},s=ze(r.type)??"info",n="string"==typeof r.title?r.title:void 0;return{type:"panel",attrs:{panelType:s,...n?{title:n}:{}},content:[{type:"paragraph",content:ke([{type:"text",value:Ie(e)}],t)}]}})(e,t):Je(e,t);default:return Je(e,t)}}function Je(e,t){if("drop"===t.unknownNodeStrategy)return null;const r=He(e);return r?{type:"paragraph",content:[{type:"text",text:r}]}:null}function qe(e,t,r){const s=Number.isFinite(e)?Math.trunc(e):t;return Math.max(t,Math.min(r,s))}const Pe={resolveMention:void 0,resolveAttachment:void 0,resolveEmoji:void 0,enableSmartCards:!0,enableMermaid:!0,enableEmojiShortcodes:!0,enableAtMentions:!0,enableTaskLists:!0,unknownNodeStrategy:"text"};function Me(e,t={}){const r={...Pe,...t},s=e??"",n=h.unified().use(y).use(g).use(f),i=n.parse(s),o=n.runSync(i);return Re(o),((e,t)=>{const r=[];for(const s of e.children??[]){const e=De(s,t);e&&(Array.isArray(e)?r.push(...e):r.push(e))}return((e,t)=>{if(!t.enableSmartCards)return e;const r=e.content.map(e=>(e=>{if("paragraph"!==e.type)return e;const t=e.content??[];if(1!==t.length)return e;const r=t[0];if("inlineCard"!==r?.type)return e;const s=r.attrs?.url;return s?[{type:"blockCard",attrs:{url:s}}]:e})(e)).flat();return{...e,content:r}})({version:1,type:"doc",content:r},t)})(o,r)}function Re(e){if(!e||!Array.isArray(e.children))return;const t=[];for(const r of e.children)"definition"!==r?.type&&("html"!==r?.type?(Re(r),t.push(r)):t.push({type:"text",value:(r.value??"")+""}));e.children=t}const $e=a.z.object({issueId:a.z.string().min(1),transitionId:a.z.union([a.z.string(),a.z.number()]),fields:a.z.record(a.z.any()).optional(),update:a.z.record(a.z.array(a.z.object({set:a.z.any().optional(),add:a.z.any().optional(),remove:a.z.any().optional()}))).optional(),comment:a.z.string().optional()}),Le={name:"jira.issue-transition",inputSchema:$e,runTool:async(e,t)=>{try{const r=$e.parse(t),s={id:r.transitionId};r.fields&&(s.fields=r.fields),r.update&&(s.update=r.update),r.comment&&(s.comment={body:Me(r.comment)});const n=await e.issues.transition({issueId:r.issueId,transition:s});return n?.data??n}catch(e){throw ge(e)}}},Fe=a.z.object({issueId:a.z.string().min(1),fields:a.z.record(a.z.any()).optional(),update:a.z.record(a.z.array(a.z.object({set:a.z.any().optional(),add:a.z.any().optional(),remove:a.z.any().optional(),edit:a.z.any().optional()}))).optional(),properties:a.z.array(a.z.any()).optional(),notifyUsers:a.z.boolean().optional().default(!0),issueTemplateId:a.z.string().optional(),overrideScreenSecurity:a.z.boolean().optional().default(!1),overrideEditableFlag:a.z.boolean().optional().default(!1)}),Be={name:"jira.issue-update",inputSchema:Fe,runTool:async(e,t)=>{try{const r=Fe.parse(t),s={issueId:r.issueId};r.fields&&(s.fields=r.fields),r.update&&(s.update=r.update),r.properties&&(s.properties=r.properties),void 0!==r.notifyUsers&&(s.notifyUsers=r.notifyUsers),r.issueTemplateId&&(s.issueTemplateId=r.issueTemplateId),void 0!==r.overrideScreenSecurity&&(s.overrideScreenSecurity=r.overrideScreenSecurity),void 0!==r.overrideEditableFlag&&(s.overrideEditableFlag=r.overrideEditableFlag);const n=await e.issues.update(s);return n?.data??n}catch(e){throw ge(e)}}},We=a.z.object({issueId:a.z.string().min(1),assignee:a.z.union([a.z.string(),a.z.object({accountId:a.z.string().min(1)}),a.z.object({accountType:a.z.string().min(1)})])}),Ue={name:"jira.assign-issue",inputSchema:We,runTool:async(e,t)=>{try{const r=We.parse(t);let s;s="string"==typeof r.assignee?{accountId:r.assignee}:r.assignee;const n=await e.issues.assign({issueId:r.issueId,assignee:s});return n?.data??n}catch(e){throw ge(e)}}},Ke=a.z.object({issueId:a.z.string().min(1)}),Ye={name:"jira.unassign-issue",inputSchema:Ke,runTool:async(e,t)=>{try{const r=Ke.parse(t),s=await e.issues.assign({issueId:r.issueId,assignee:{accountId:"-1"}});return s?.data??s}catch(e){throw ge(e)}}},Ve=a.z.object({issueId:a.z.string().min(1),body:a.z.string().min(1),visibility:a.z.object({type:a.z.enum(["role","group"]),value:a.z.string().min(1)}).optional()}),Ge={name:"jira.comment-add",inputSchema:Ve,runTool:async(e,t)=>{try{const r=Ve.parse(t),s={body:Me(r.body)};r.visibility&&(s.visibility=r.visibility);const n=await e.issues.addComment({issueId:r.issueId,comment:s});return n?.data??n}catch(e){throw ge(e)}}},Ze=a.z.object({issueId:a.z.string().min(1),start:a.z.number().optional().default(0),maxResults:a.z.number().optional().default(50),orderBy:a.z.string().optional(),expand:a.z.string().optional()}),Qe={name:"jira.comment-list",inputSchema:Ze,runTool:async(e,t)=>{try{const r=Ze.parse(t),s=await e.issues.getComments({issueId:r.issueId,start:r.start,maxResults:r.maxResults,orderBy:r.orderBy,expand:r.expand});return s?.data??s}catch(e){throw ge(e)}}},Xe=a.z.object({link:a.z.object({relationship:a.z.enum(["Blocks","Relates to","Duplicates","Is blocked by","Is related to","Is duplicated by","Causes","Is caused by","Clone","Required","Work on","Split","Roll up"]),inwardIssue:a.z.object({id:a.z.string().optional(),key:a.z.string().optional()}),outwardIssue:a.z.object({id:a.z.string().optional(),key:a.z.string().optional()}),comment:a.z.object({body:a.z.string().optional(),visibility:a.z.object({type:a.z.enum(["role","group"]),value:a.z.string().min(1)}).optional()}).optional()})}),et={name:"jira.link-create",inputSchema:Xe,runTool:async(e,t)=>{try{const r=Xe.parse(t).link,s={relationship:r.relationship,inwardIssue:r.inwardIssue.id||r.inwardIssue.key,outwardIssue:r.outwardIssue.id||r.outwardIssue.key};r.comment&&(r.comment.body&&(s.comment=Me(r.comment.body)),r.comment.visibility&&(s.visibility=r.comment.visibility));const n=await e.issues.link(s);return n?.data??n}catch(e){throw ge(e)}}},tt=a.z.object({issueId:a.z.string().min(1),file:a.z.string().min(1),mimeType:a.z.string().optional(),comment:a.z.string().optional()}),rt={name:"jira.attach",inputSchema:tt,runTool:async(e,r)=>{try{const s=tt.parse(r),i=n.resolve(s.file),o=await t.promises.readFile(i),a=n.basename(i),c=await e.issues.addAttachment({issueId:s.issueId,file:{name:a,content:o,mimeType:s.mimeType??"application/octet-stream"},comment:s.comment});return c?.data??c}catch(e){if(e&&e.code&&"string"==typeof e.code&&["ENOENT","EACCES"].includes(e.code))throw Error("Attachment file error: "+e.message);throw ge(e)}}},st=a.z.object({issueId:a.z.string().min(1)}),nt={name:"jira.attachment-list",inputSchema:st,runTool:async(e,t)=>{try{const r=st.parse(t),s=await e.issues.getAttachments({issueId:r.issueId});return s?.data??s}catch(e){throw ge(e)}}},it=a.z.object({issueId:a.z.string().min(1),attachmentId:a.z.string().min(1)}),ot={name:"jira.attachment-delete",inputSchema:it,runTool:async(e,t)=>{try{const r=it.parse(t);return await e.issues.deleteAttachment({issueId:r.issueId,attachmentId:r.attachmentId}),{success:!0,message:`Attachment ${t.attachmentId} deleted successfully`}}catch(e){throw ge(e)}}},at=a.z.object({issueId:a.z.string().min(1),timeSpent:a.z.string().min(1),comment:a.z.string().optional(),author:a.z.object({accountId:a.z.string().min(1)}).optional(),startingOn:a.z.string().optional(),artifact:a.z.string().optional()}),ct={name:"jira.worklog-add",inputSchema:at,runTool:async(e,t)=>{try{const r=at.parse(t),s={timeSpent:r.timeSpent};r.comment&&(s.comment=r.comment),r.author&&(s.author=r.author),r.startingOn&&(s.started=r.startingOn),r.artifact&&(s.artifact=r.artifact);const n=await e.issues.addWorklog({issueId:r.issueId,...s});return n?.data??n}catch(e){throw ge(e)}}},lt={[we.name]:{title:"Jira Issue Read",description:"Read a Jira issue with expandable fields and properties",annotations:{readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1}},[Be.name]:{title:"Jira Issue Update",description:"Update a Jira issue using fields, update ops, and property toggles",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}},[be.name]:{title:"Jira Issue Delete",description:"Delete a Jira issue and optionally remove its subtasks",annotations:{readOnlyHint:!1,destructiveHint:!0,idempotentHint:!1,openWorldHint:!0}},[Le.name]:{title:"Jira Issue Transition",description:"Transition a Jira issue while optionally adding a comment",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}},[Ue.name]:{title:"Jira Issue Assign",description:"Assign a Jira issue to a user or account",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}},[Ye.name]:{title:"Jira Issue Unassign",description:"Unassign the current owner from a Jira issue",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}},[Ge.name]:{title:"Jira Comment Add",description:"Add a comment to a Jira issue with optional visibility",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}},[Qe.name]:{title:"Jira Comment List",description:"List comments on a Jira issue with pagination support",annotations:{readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1}},[et.name]:{title:"Jira Link Create",description:"Create an issue link relationship with optional comment",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}},[rt.name]:{title:"Jira Attachment Add",description:"Attach a local file to a Jira issue",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}},[nt.name]:{title:"Jira Attachment List",description:"List attachments on a Jira issue",annotations:{readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1}},[ot.name]:{title:"Jira Attachment Delete",description:"Delete an attachment from a Jira issue",annotations:{readOnlyHint:!1,destructiveHint:!0,idempotentHint:!1,openWorldHint:!0}},[ct.name]:{title:"Jira Worklog Add",description:"Log time spent on a Jira issue",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}}};async function pt(e){const t=r.Logging.for(pt);let s,n=null;try{s=(()=>{let e;try{const t=require("jira.js");e=t?.Version3Client||t.default?.Version3Client||t.default||t}catch(e){throw Error("Unable to require 'jira.js' \u2014 ensure it is installed as a dependency: "+e)}const{host:t,email:r,apiKey:s}=(()=>{const e=ue(),t=me().filter(e=>e.required&&!e.value);if(t.length>0)throw new fe(t);return{host:e.host,email:e.email,apiKey:e.apiKey}})();return new e({host:t,authentication:{basic:{email:r,apiToken:s}}})})()}catch(e){if(!(e instanceof fe))return void t.warn("Skipping Jira tool registration; unable to create Jira client",{error:e});n=e,t.warn("Registering Jira tools without credentials; each tool will report configuration requirements.",{error:e})}const i=[we,Be,be,Le,Ue,Ye,Ge,Qe,et,rt,nt,ot,ct];for(const r of i){const i=lt[r.name];if(i)try{await e.registerTool(r.name,{title:i.title,description:i.description,inputSchema:P(r.inputSchema),annotations:i.annotations},async e=>{if(!s)throw n??Error("Jira client unavailable because credentials could not be loaded.");return r.runTool(s,e)}),t.info("Registered Jira tool "+r.name)}catch(e){t.error("Failed to register Jira tool "+r.name,{error:e})}}}async function dt(e){await(async e=>{e.registerTool("decaf.server-info",{title:"Decaf MCP Server Info",description:"Return server metadata, version, and registered prompt names for diagnostics.",inputSchema:{},outputSchema:void 0,annotations:{readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1}},async()=>{const e=ie.map(e=>e.getName()).sort();return{content:[{type:"text",text:["Name: "+de.name,"Title: "+de.title,"Version: "+de.version,"Prompts: "+(e.join(", ")||"<none>")].join("\n")}]}})})(e);const t=r.Logging.for(dt);try{await pt(e)}catch(e){t.error("Failed to register Jira tools",e)}}class ut extends H{setCb(e){return this.cb=e,this}setConfig(e){return this.config=e,this}setUriOtTemplate(e){return this.uriOrTemplate=e,this}constructor(e){super(e)}static get builder(){return new ut}build(e){const t=this.hasErrors();if(t)throw Error(t.toString());try{const t="string"==typeof this.uriOrTemplate&&this.uriOrTemplate.includes("{")?new v.ResourceTemplate(new b.UriTemplate(this.uriOrTemplate),{list:void 0}):this.uriOrTemplate,r=Object.assign(this.config,{_meta:{}}),s=async(e,t)=>{const r=this.logFor(t);r.verbose(`Requesting resource ${this.name} from ${e.toString()}`);const s=await Promise.resolve(this.cb(e,t));return r.verbose(`Resource ${this.name} retrieved successfully.`),r.debug("Resource retrieval meta: "+JSON.stringify(s._meta)),s};return e.resource(this.name,t,r,s)}catch(e){throw r.Logging.for(this).error("Error registering resource "+this.name,e),e}}}i.__decorate([o.required(),i.__metadata("design:type",String)],ut.prototype,"uriOrTemplate",void 0),i.__decorate([o.required(),i.__metadata("design:type",Function)],ut.prototype,"cb",void 0),i.__decorate([o.required(),i.__metadata("design:type",Object)],ut.prototype,"config",void 0);const mt=Y()??I.join(__dirname,"..","assets"),ht=I.join(mt,"templates"),ft=I.join(mt,"prompts"),gt=new WeakMap;class yt extends r.LoggedClass{get client(){const e=gt.get(this);if(!e)throw Error("Mcp server requires Mcp client");return e}constructor(){super()}async load(){const e=this.log.for(this.load);for(const t of ie)try{e.info("loading prompt "+t.getName());const r=t.build(this.client);e.verbose(`Loaded prompt ${r.title} from ${t.getName()} definition`)}catch(r){e.error("Failed to load prompt "+t.getName(),r)}try{await dt(this.client),e.verbose("Registered built-in tools")}catch(t){e.error("Failed to register tools",t)}try{await(async(e,t)=>{t.info("Registering agent templates as resources...");const r=_.readdirSync(ht).filter(e=>e.endsWith(".md"));for(const s of r){const r=I.basename(s,".md"),n=I.join(ht,s),i=ut.builder.setName(r).setTitle("Template: "+r).setDescription("Resource template for "+r).setUriOtTemplate("file:///"+n).setConfig({mimeType:"text/markdown",description:"Template for "+r}).setCb(async e=>{const t=_.readFileSync(e.pathname,"utf8");return{contents:[{uri:e.toString(),text:t,mimeType:"text/markdown"}],_meta:{}}});try{i.build(e),t.info("Registered template: "+r)}catch(e){t.error(`Failed to register template ${r}:`,e)}}t.info("Registering agent prompts...");const s=_.readdirSync(ft).filter(e=>e.endsWith(".md"));for(const r of s){const s=I.basename(r,".md"),n=I.join(ft,r),i=_.readFileSync(n,"utf8"),o=G.builder.setName(s).setTitle("Prompt: "+s).setDescription("Dynamic prompt for "+s).setArgsSchema(a.z.object({})).setCb(async e=>({messages:[{role:"user",content:{type:"text",text:i}}],_meta:{}}));try{o.build(e),t.info("Registered prompt: "+s)}catch(e){t.error(`Failed to register prompt ${s}:`,e)}}})(this.client,e),e.verbose("Registered agent-specific assets")}catch(t){e.error("Failed to register agent assets",t)}}async boot(e="stdio"){let t=this.log;this.log.for(this.boot).info("McpServer booting..."),((e=r.Logging.get())=>{let t;try{t=(()=>{let e,t=__dirname;try{for(;t&&t!==I.parse(t).root;){const r=I.join(t,"node_modules");if(_.existsSync(r)&&_.statSync(r).isDirectory()){e=r;break}const s=I.dirname(t);if(s===t)break;t=s}}catch{}const r=[];if(e){const t=I.join(e,"@decaf-ts");try{if(_.existsSync(t)&&_.statSync(t).isDirectory()){const e=_.readdirSync(t);for(const s of e){const e=I.join(t,s);try{const t=I.join(e,"workdocs","assets","slogans.json");if(_.existsSync(t)&&_.statSync(t).isFile()){const e=_.readFileSync(t,"utf-8"),s=JSON.parse(e);if(Array.isArray(s))for(const e of s)"string"==typeof e&&e.trim().length>0&&r.push(e.trim())}}catch{}}}}catch{}}return 0===r.length?"Decaf: strongly brewed TypeScript.":r[Math.floor(Math.random()*r.length)]})()}catch{t="Decaf: strongly brewed TypeScript."}const n="# \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \n# ( ( \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \n# ) ) \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \n# [=======] \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \n# `-----\xb4 \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \n# \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \n# \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \n#".split("\n"),i=n.reduce((e,t)=>Math.max(e,t.length),0);n.push("# "+t.padStart(i-3)),n.forEach((t,r)=>{const n=k[r%k.length]||"",i=e.info.bind(e);try{i(s.style(t||"").raw(n).text)}catch{i((t||"")+"")}})})(this.log),"stdio"===e&&(r.Logging.setFactory(E),t=r.Logging.for(this.constructor.name));const n=((Array.isArray(de.icons)?de.icons:[de.icons])||[]).map(e=>{const t="string"==typeof e?.src?e.src:(e?.src??"")+"",r="string"==typeof e?.mimeType?e.mimeType:(e?.mimeType??"")+"";let s=[];return Array.isArray(e?.sizes)?s=e.sizes.map(e=>e+""):"string"==typeof e?.sizes&&(s=(e.sizes+"").split(",").map(e=>e.trim())),{src:t,mimeType:r,sizes:s}}),i={name:de.name,title:de.title,websiteUrl:de.websiteUrl,version:de.version,icons:n},o=new v.McpServer(i,{instructions:"You are an AI assistant designed to help users with programming tasks related to the Decaf-TS framework. \nProvide clear, concise, and accurate information.\nIf you don't know the answer, admit it rather than making up information.\nAlways prioritize the user's intent and provide helpful suggestions when appropriate.\n",capabilities:{logging:{},tools:{},prompts:{}}});switch(((e,t)=>{gt.set(e,t)})(this,o),o.onerror=e=>{this.log.error("MCP instance onerror",e)},e){case"stdio":e=new S.StdioServerTransport;break;case"http":e=new j.StreamableHTTPServerTransport({sessionIdGenerator:()=>w.v4(),onsessioninitialized:e=>t.verbose("Session initialized: "+e),onsessionclosed:e=>t.verbose("Session closed: "+e),enableJsonResponse:!0,eventStore:void 0});break;default:if(!(a=e)||"object"!=typeof a||"function"!=typeof a.send&&"function"!=typeof a.close&&"function"!=typeof a.on)throw new p.InternalError("Invalid transport type: "+e)}var a;try{this.log.info("Loading resources/prompts/tools..."),await this.load()}catch(e){throw this.log.error("Error loading resources/prompts/tools: "+e),e}await this.client.connect(e),t.info(`MCP Server connected via ${e.constructor.name} and running. Waiting for client connections...`)}}const bt=(new e.Command).command("start").option("--transport [String]","transport mode","stdio").description("starts decaf's mcp server").action(async e=>{const r=U("package.json"),s=JSON.parse(t.readFileSync(r,"utf-8")),n=s.version,{transport:i}=e,o=(new z).for("mcp-server");if("stdio"!==i)throw Error("Unsupported transport mode: "+i);return o.info("Transport stdio"),o.debug(`running with options: ${JSON.stringify(e)} for ${s.name} version ${n}`),(new yt).boot(i)});(new e.Command).command("md-to-ast").description("pipes markdown to jira ast: `cat file.md` | npx decaf-mcp md-to-ast > ast.json").action(async e=>{const s=U("package.json"),n=JSON.parse(t.readFileSync(s,"utf-8")),i=n.version;r.Logging.for("md-to-ast").debug(`running with options: ${JSON.stringify(e)} for ${n.name} version ${i}`);const o=Me(await(async()=>{const e=[];for await(const t of process.stdin)e.push(Buffer.from(t));return Buffer.concat(e).toString("utf8")})(),{resolveMention:e=>({id:e,text:"@"+e}),resolveAttachment:e=>({id:e,collection:"attachments"})});process.stdout.write(JSON.stringify(o,null,2)+"\n")});const vt=(new e.Command).name("mcp-server").command("mcp-server").description("decaf mcp server and agentic functionality");vt.addCommand(bt),vt.parse(process.argv)},"object"==typeof exports&&"undefined"!=typeof module?t(require("commander"),require("fs"),require("@decaf-ts/logging"),require("styled-string-builder"),require("path"),require("tslib"),require("@decaf-ts/decorator-validation"),require("zod"),require("@decaf-ts/injectable-decorators"),require("@decaf-ts/decoration"),require("@decaf-ts/db-decorators"),require("crypto"),require("zlib"),require("url"),require("unified"),require("remark-directive"),require("remark-gfm"),require("remark-parse"),require("@modelcontextprotocol/sdk/shared/uriTemplate.js"),require("@modelcontextprotocol/sdk/server/mcp.js"),require("uuid"),require("@modelcontextprotocol/sdk/server/stdio.js"),require("@modelcontextprotocol/sdk/server/streamableHttp.js")):"function"==typeof define&&define.amd?define(["commander","fs","@decaf-ts/logging","styled-string-builder","path","tslib","@decaf-ts/decorator-validation","zod","@decaf-ts/injectable-decorators","@decaf-ts/decoration","@decaf-ts/db-decorators","crypto","zlib","url","unified","remark-directive","remark-gfm","remark-parse","@modelcontextprotocol/sdk/shared/uriTemplate.js","@modelcontextprotocol/sdk/server/mcp.js","uuid","@modelcontextprotocol/sdk/server/stdio.js","@modelcontextprotocol/sdk/server/streamableHttp.js"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).commander,e.fs,e.decafTsLogging,e.styledStringBuilder,e.path,e.tslib,e.decafTsDecoratorValidation,e.zod,e.decafTsInjectableDecorators,e.decafTsDecoration,e.decafTsDbDecorators,e.crypto,e.zlib,e.url,e.unified,e.remarkDirective,e.remarkGfm,e.remarkParse,e.uriTemplate_js,e.mcp_js,e.uuid,e.stdio_js,e.streamableHttp_js);
2
+ var e,t;e=this,t=function(e,t,r,s,n,i,o,a,c,l,p,d,u,m,h,f,g,y,b,v,w,S,j){"use strict";function x(e){var t=Object.create(null);return e&&Object.keys(e).forEach(r=>{if("default"!==r){var s=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,s.get?s:{enumerable:!0,get:()=>e[r]})}}),t.default=e,Object.freeze(t)}var _=x(t),I=x(n);class z extends r.MiniLogger{log(e,t,s,n){const i=this.config("level");r.NumericLogLevels[i],r.NumericLogLevels[e]}}const E=(e,t,...r)=>{const s=(e=>{if("string"==typeof e)return e;if(!e)return"unknown";if("function"==typeof e)return e.name||"unknown";if("object"==typeof e&&"constructor"in e){const t=e.constructor;if(t&&t.name)return t.name}return"unknown"})(e);return new z(s,t)},k=["\x1b[38;5;215m","\x1b[38;5;209m","\x1b[38;5;205m","\x1b[38;5;210m","\x1b[38;5;217m","\x1b[38;5;216m","\x1b[38;5;224m","\x1b[38;5;230m","\x1b[38;5;230m"];var T,A,O,N,C;(e=>{e[e.NONE=0]="NONE",e[e.BASIC=1]="BASIC",e[e.ADVANCED=2]="ADVANCED",e[e.HIGH=3]="HIGH"})(T||(T={})),(e=>{e[e.NONE=0]="NONE",e[e.LOW=1]="LOW",e[e.MEDIUM=2]="MEDIUM",e[e.HIGH=3]="HIGH"})(A||(A={})),(e=>{e[e.FREE=0]="FREE",e[e.LOW=1]="LOW",e[e.MEDIUM=2]="MEDIUM",e[e.HIGH=3]="HIGH"})(O||(O={}));class H extends o.Model{get log(){return this._log||(this._log=r.Logging.for(this)),this._log}constructor(e){super(e)}logFor(e){const{sessionId:t,requestId:r,authInfo:s}=e||{};let n="string"==typeof t&&t.length>0?this.log.for(t):this.log;return s&&s.clientId&&(n=n.for(s.clientId)),r&&(n=n.for(r.toString())),n}setDescription(e){return this.description=e,this}getDescription(){return this.description}setName(e){return this.name=e,this}getName(){return this.name}setTitle(e){return this.title=e,this}}i.__decorate([o.required(),i.__metadata("design:type",String)],H.prototype,"description",void 0),i.__decorate([o.required(),i.__metadata("design:type",String)],H.prototype,"name",void 0),i.__decorate([o.required(),i.__metadata("design:type",String)],H.prototype,"title",void 0);class D extends H{constructor(e){super(e),this.reasoning=T.NONE,this.effort=A.NONE,this.cost=O.FREE}setReasoning(e){return this.reasoning=e,this}setEffort(e){return this.effort=e,this}setCost(e){return this.cost=e,this}}function J(e){if(!e)return;let t=e,r=t&&t._def;for(;r&&"ZodObject"!==r.typeName;){if("ZodEffects"===r.typeName&&r.schema)t=r.schema;else if("ZodOptional"===r.typeName&&r.innerType)t=r.innerType;else if("ZodDefault"===r.typeName&&r.innerType)t=r.innerType;else if("ZodNullable"===r.typeName&&r.innerType)t=r.innerType;else{if(!r.schema)return;t=r.schema}r=t&&t._def}return r&&"ZodObject"===r.typeName?r:void 0}function q(e,t="schema"){if(J(e))return e;if(e&&"object"==typeof e){const t=e.def&&"object"==typeof e.def?e.def:void 0,r=t&&(t.shape||"object"===t.type)&&t.shape||("object"===e.type?e.shape:void 0)||(t&&"object"===t.type?{}:void 0);if(t||"object"===e.type||r){const e={};if(r&&"object"==typeof r)for(const[t,s]of Object.entries(r))e[t]=M(s)?s:a.z.any();return a.z.object(e)}}throw Error(`Registration error: provided a non-canonical ${t}. Export a ZodObject (z.object(...)).`)}function P(e){if(!e)return;if(e&&"object"==typeof e&&!e._def)return e.def&&"object"==typeof e.def&&e.def.shape?e.def.shape:e;const t=J(e);return t?"function"==typeof t.shape?t.shape():t.shape||void 0:void 0}function M(e){return!(!e||"object"!=typeof e||!e._def)}i.__decorate([o.required(),i.__metadata("design:type",Number)],D.prototype,"reasoning",void 0),i.__decorate([o.required(),i.__metadata("design:type",Number)],D.prototype,"effort",void 0),i.__decorate([o.required(),i.__metadata("design:type",Number)],D.prototype,"cost",void 0),(e=>{e.ASSETS="assets"})(N||(N={})),(e=>{e.PROMPT="prompts",e.DOCUMENTATION="documentation",e.CODE="code"})(C||(C={}));const R=Buffer.from("DCAF1","ascii");function $(e){let r=n.resolve(e);for(;;){if(t.existsSync(n.join(r,"package.json")))return r;const e=n.dirname(r);if(e===r)break;r=e}}const L=process.argv?.[1]?$(n.dirname(n.resolve(process.argv[1]))):void 0,F=(()=>{const e=Error().stack;if(!e)return;const t=e.split(/\r?\n/).slice(1);for(const e of t){const t=e.match(/\(?([^()]+?):\d+:\d+\)?/);if(!t)continue;let r=t[1];if(r.startsWith("file://"))try{r=m.fileURLToPath(r)}catch{continue}if(!r.includes("node:internal"))return n.dirname(r)}})(),B=F?$(F):void 0,W=L??B??process.cwd();function U(...e){return n.join(W,...e)}function K(e){let t=e;for(;;){const e=I.join(t,"lib","assets");if(_.existsSync(e))return e;const r=I.join(t,"src","assets");if(_.existsSync(r))return r;const s=I.join(t,"assets");if(_.existsSync(s))return s;const n=I.dirname(t);if(n===t)break;t=n}}function Y(){const e=process.env.DECAF_ASSET_DIR||process.env.MCP_ASSET_DIR||process.env.ASSET_DIR||"";if(e&&_.existsSync(e))return e;const t=K(__dirname);if(t)return t;const r=process.argv?.[1];if(r){const e=K(I.dirname(r));if(e)return e}const s=[W,process.env.INIT_CWD].filter(Boolean);for(const e of s){const t=K(e);if(t)return t}return U("assets")}let V=class extends r.LoggedClass{constructor(e){super(),this.basePath=e||Y()}listAssets(...e){const t=I.join(this.basePath,...e);return _.readdirSync(t)}listPrompts(){return this.listAssets(C.PROMPT)}getAsset(e,t="md",...r){const s=I.join(this.basePath,...r),n=(e,t=!1)=>{try{return t?(e=>{if(e.length<R.length+16+12+16)throw Error("Invalid prompt payload (too short)");if(!e.subarray(0,R.length).equals(R))throw Error("Invalid prompt payload (bad magic)");const t=process.env.ENCRYPTION_KEY||"";if(!t)throw Error("Missing encryption key. Set ENCRYPTION_KEY to load obfuscated assets.");let r=R.length;const s=e.subarray(r,r+16);r+=16;const n=e.subarray(r,r+12);r+=12;const i=e.subarray(r,r+16);r+=16;const o=e.subarray(r),a=((e,t)=>d.scryptSync(e,t,32))(t,s),c=d.createDecipheriv("aes-256-gcm",a,n);c.setAuthTag(i);const l=Buffer.concat([c.update(o),c.final()]);return u.gunzipSync(l)})(_.readFileSync(e)).toString("utf-8"):_.readFileSync(e,"utf-8")}catch(e){if("ENOENT"===e.code)return null;throw e}},i=n(I.join(s,`${e}.${t}`),"enc"===t);if(null!==i)return i;const o=n(I.join(s,e+".enc"),!0);if(null!==o)return o;throw Error("Asset not found: "+I.join(s,`${e}.${t}`))}getAllAssets(e,...t){return this.listAssets(e,...t).reduce((r,s)=>{const n=I.extname(s),i=I.basename(s,n),o=n.replace(/^\./,"")||void 0;return r[i]=this.getAsset(i,o??void 0,e,...t),r},{})}toPromptDef(e){const t=e=>"number"==typeof e?e:"string"==typeof e?(e=>{switch(e){case"none":return T.NONE;case"basic":return T.BASIC;case"advanced":return T.ADVANCED;case"high":return T.HIGH;case"medium":return A.MEDIUM;case"low":return O.LOW;case"free":return O.FREE;default:throw new p.InternalError("Cannon convert unknown level "+e)}})(e.toLowerCase()):T.NONE;return e.effort=t(e.effort),e.reasoning=t(e.reasoning),e.cost=t(e.cost),e}getPrompt(e,...t){const s=this.getAsset(r.toSnakeCase(e),"json",C.PROMPT,...t);let n;try{n=JSON.parse(s)}catch(r){throw new p.SerializationError(`Failed to parse prompt ${e} in categories ${t}: ${r}`)}return this.toPromptDef(n)}getAllPrompts(...e){const t=this.getAllAssets(C.PROMPT,...e);return Object.entries(t).reduce((t,[r,s])=>{try{t[r]=JSON.parse(s)}catch(t){throw new p.SerializationError(`Failed to parse prompt ${r} in categories ${e}: ${t}`)}return t},t)}};V=i.__decorate([c.injectable(),i.__metadata("design:paramtypes",[String])],V);class G extends D{constructor(e){super(e)}setCb(e){return this.cb=e,this}setArgsSchema(e){return this.argsSchema=e,this}static get builder(){return new G}static patchPrompt(e,t,s,n){const i=(t=Array.isArray(t)?t:Object.keys(t)).filter(e=>!Object.prototype.hasOwnProperty.call(s,e));if(i.length)throw new p.ValidationError("Missing replacements for placeholders: "+i.join(", "));n&&(n.verbose("Patching prompt with placeholders: "+JSON.stringify(t)),n.debug("Values: "+JSON.stringify(s)));const o=t.reduce((e,t)=>(e[t]=s[t],e),{});return r.sf(e,o)}patchPrompt(e,t,r,s){return G.patchPrompt(e,t,r,s||this.log.for(this.patchPrompt))}build(e,t){const r=this.log.for(this.build),s=this.hasErrors();if(s)throw new p.ValidationError(s.toString());try{this.argsSchema&&q(this.argsSchema,"argsSchema");const r=P(this.argsSchema);return e.registerPrompt(this.name,{title:this.title,description:this.description,argsSchema:r},async(e,r)=>{const s=this.logFor(r);e=Object.assign({},t,e||{}),s.verbose(`Executing prompt ${this.name} with args: ${JSON.stringify(e)}`),e._meta=Object.assign(e._meta||{},{usage:{reasoning:this.reasoning,effort:this.effort,cost:this.cost}});const n=await Promise.resolve(this.cb(e,r));return s.verbose(`Prompt ${this.name} executed successfully.`),s.debug("Prompt execution meta: "+JSON.stringify(n._meta)),n})}catch(e){throw r.error("Failed to register prompt "+(this.name||this.constructor.name),e),e}}}i.__decorate([c.inject(V),i.__metadata("design:type",V)],G.prototype,"assets",void 0),i.__decorate([o.required(),i.__metadata("design:type",Object)],G.prototype,"cb",void 0),i.__decorate([o.required(),i.__metadata("design:type",a.ZodObject)],G.prototype,"argsSchema",void 0),i.__decorate([l.prop(),i.__metadata("design:type",Object)],G.prototype,"placeholders",void 0);class Z extends G{setCategory(e){return this.promptCategory=e,this}addPrefix(e){return this.prefixes=this.prefixes||[],this.prefixes.push(e),this}addSuffix(e){return this.suffixes=this.suffixes||[],this.suffixes.push(e),this}constructor(e){super(e)}build(e){const t=this.assets.getPrompt(this.name,this.promptCategory);o.Model.fromObject(this,t);const r=new Set((l.Metadata.properties(Z)||[]).filter(e=>!["assets","promptCategory","prefixes","suffixes"].includes(e)));["cb","argsSchema"].forEach(e=>r.add(e));const s=this.hasErrors(...Array.from(r));if(s)throw new p.ValidationError(s.toString());const n=(this.prefixes||[]).map(e=>this.assets.getPrompt(e,this.promptCategory)),i=(this.suffixes||[]).map(e=>this.assets.getPrompt(e,this.promptCategory)),c=[...new Set([...t.placeholders,...n.map(e=>e.placeholders||[]),...i.map(e=>e.placeholders||[])].flat())].reduce((e,t)=>(e[t]=a.z.string().describe("The description for "+t),e),{});return this.setArgsSchema(a.z.object(c)),this.setCb((e,t)=>{const r=this.logFor(t).for(Z).for(this.promptCategory).for(this.name);function s(e=[]){return Array.isArray(e)?e:Object.keys(e)}const n=(this.prefixes||[]).map(e=>this.assets.getPrompt(e,this.promptCategory)),i=(this.suffixes||[]).map(e=>this.assets.getPrompt(e,this.promptCategory)),o=this.assets.getPrompt(this.name,this.promptCategory),a=[...new Set([...n.map(e=>s(e.placeholders)).flat(),...i.map(e=>s(e.placeholders)).flat(),...s(o.placeholders).flat()])];return{messages:[{role:"user",content:{type:"text",text:this.patchPrompt([...n.map(e=>e.prompt),o.prompt,...i.map(e=>e.prompt)].join("\n\n"),a,e,r)}}],_meta:{}}}),super.build(e)}setReasoning(e){throw new p.InternalError("Named prompt builders don't require callback")}setEffort(e){throw new p.InternalError("Named prompt builders don't require callback")}setCost(e){throw new p.InternalError("Named prompt builders don't require callback")}setDescription(e){throw new p.InternalError("Named prompt builders don't require callback")}setTitle(e){throw new p.InternalError("Named prompt builders don't require callback")}static get builder(){return new Z}}i.__decorate([o.required(),i.__metadata("design:type",String)],Z.prototype,"promptCategory",void 0),i.__decorate([o.list(String),o.minlength(1),i.__metadata("design:type",Array)],Z.prototype,"prefixes",void 0),i.__decorate([o.minlength(1),o.list(String),i.__metadata("design:type",Array)],Z.prototype,"suffixes",void 0);const Q=G.builder.setName("example.prompt").setTitle("Example prompt").setDescription("Example prompt for testing").setArgsSchema(a.z.object({message:a.z.string().optional()})).setCb(async e=>{const t=e.message??"default";return{messages:[{role:"assistant",content:{type:"text",text:t}}],content:[],structuredContent:{message:t},result:{message:t}}}),X=G.builder.setName("interactive.jsdoc").setTitle("Interactive JSDoc prompt").setDescription("Interactive prompt for jogging JSDoc helpers").setArgsSchema(a.z.object({gist:a.z.string().optional()})).setCb(async e=>{const t=e.gist??"interactive jsdoc response";return{messages:[{role:"assistant",content:{type:"text",text:t}}],content:[],structuredContent:{message:t},result:{message:t}}}),ee=Object.assign(X,{name:X.getName()});var te;function re(e,t=[],r=[]){const s=Z.builder.setCategory(te.DOCS).setName(e);return["prefix",...t].forEach(e=>s.addPrefix(e)),["suffix",...r].forEach(e=>s.addSuffix(e)),s}(e=>{e.DOCS="documentation",e.CODE="code"})(te||(te={}));const se=[re("class"),re("constant"),re("decorator"),re("function"),re("module"),re("file"),re("repo",[],["iterate"])],ne=a.z.object({className:a.z.string().describe("the class name to turn into a builder")}),ie=[Q,ee,...se,G.builder.setName("ts.code.dp.builder").setTitle("Typescript builder design patter prompt").setDescription("for a class, with a defined set of properties, scafold a builder design pattern").setArgsSchema(ne).setReasoning(T.BASIC).setCb((e,t)=>(e.className=r.toPascalCase(e.className),{messages:[{role:"user",content:{type:"text",text:`You're a senior TypeScript developer writing typescript code.You're a senior TypeScript developer writing typescript code.\nTransform the selected class into a builder design pattern implementation in Typescript.\nuse @decaf-ts validation decorators to enforce the validation of your builder.\n\n- must extend the Model Class from @decaf-ts/decorator-validation;\n- each property must be marked as protected;\n- each property must have a setter method that returns 'this' for chaining;\n- the build() method must validate the properties using hasErrors() method from Model class;\n- if validation fails, throw an error with the validation errors;\n- if validation passes, return an instance of the original class with the set properties;\n- optionally (but do so by default) add the static builder and from methods from the example;\n- if the clasee already follows the pattern but has properties without decoration or without setters, simple add them;\n\nexample:\n\noriginal class:\n\`\`\`typescript\nexport class ${e.className} {\n description!: string;\n name!: string = "default name";\n title!: string;\n age?: string;\n dateOfBirth!: Date;\n}}\n\`\`\` \n\nresulting builder pattern implementation:\n\`\`\`typescript\nexport class ${e.className}Builder extends Model {\n\n @minlength(10\n @required()\n protected description!: string;\n \n @required()\n protected name!: string = "default value;\n \n @required()\n protected title!: string;\n \n @min(18)\n protected age?: string;\n \n @date()\n protected dateOfBirth!: Date;\n\n protected constructor(arg?: ModelArg<${e.className}Builder>>) {\n super(arg);\n Model.fromModel(this, arg);\n }\n\n setDescription(value: string) {\n this.description = value;\n return this;\n }\n\n setName(value: string) {\n this.name = value;\n return this;\n }\n\n setTitle(value: string) {\n this.title = value;\n return this;\n }\n setAge(value: number) {\n this.age = value;\n return this;\n }\n setDate(value: Date) {\n this.age = value;\n return this;\n }\n \n build(...args: any[]): ${e.className}Builder | Promise<${e.className}Builder> {\n const errs = this.hasErrors();\n if (errs) throw new Error(errs.toString());\n \n return // code that builds OBJ here\n }\n \n static get builder(): ${e.className}Builder {\n return new ${e.className}Builder(); // static method to get a new builder instance\n }\n \n static from<K extends keyof ${e.className}Builder>(obj: K, ${e.className}Builder[K]): ${e.className}Builder {\n return new ${e.className}Builder(); // static method to create a builder from an object\n }\n}\n\`\`\` \n\n`}}],_meta:{}}))];class oe extends D{setAnnotations(e){return this.annotations=Object.assign(this.annotations,e),this}setCb(e){return this.cb=e,this}setInputSchema(e){return this.inputSchema=e,this}setOutputSchema(e){return this.outputSchema=e,this}constructor(e){super(e),this.annotations={readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1}}static get builder(){return new oe}build(e){const t=this.hasErrors();if(t)throw Error(t.toString());try{this.inputSchema&&q(this.inputSchema,"inputSchema"),this.outputSchema&&q(this.outputSchema,"outputSchema");const t=P(this.inputSchema),r=P(this.outputSchema);return e.registerTool(this.name,{title:this.title,description:this.description,inputSchema:t,outputSchema:r,annotations:this.annotations,_meta:{usage:{reasoning:this.reasoning,effort:this.effort,cost:this.cost}}},async(e,t)=>{const r=this.logFor(t);r.verbose(`Executing tool ${this.name} with args: ${JSON.stringify(e)}`),t._meta=Object.assign(t._meta||{},{usage:{reasoning:this.reasoning,effort:this.effort,cost:this.cost}});const s=await Promise.resolve(this.cb(e,t));return r.verbose(`Tool ${this.name} executed successfully.`),r.debug("Tool execution meta: "+JSON.stringify(s._meta)),s})}catch(e){const t=e?.message||e+"";if("string"==typeof t&&t.includes("already registered"))return r.Logging.for(this).warn(`Tool ${this.name} already registered - skipping duplicate registration`),{name:this.name};throw r.Logging.for(this).error("Error building tool",e),e}}}i.__decorate([o.required(),i.__metadata("design:type",Object)],oe.prototype,"annotations",void 0),i.__decorate([o.required(),i.__metadata("design:type",Object)],oe.prototype,"cb",void 0),i.__decorate([o.required(),i.__metadata("design:type",Function)],oe.prototype,"inputSchema",void 0);const ae=oe.builder.setName("example.tool").setTitle("Example tool").setDescription("A smoke tool used for quick testing").setInputSchema(a.z.object({})).setCb(async()=>({content:[{type:"text",text:"example tool ok"}],result:{status:"ok"}}));Object.assign(ae,{name:ae.getName()});const ce=oe.builder.setName("file.summarizer").setTitle("File summarizer").setDescription("Summaries files for quick previews").setInputSchema(a.z.object({filePath:a.z.string().optional()})).setCb(async()=>({content:[{type:"text",text:"file summary stub"}],result:{summary:"file summary stub"}}));Object.assign(ce,{name:ce.getName()});const le="##VERSION##";l.Metadata.registerLibrary("##PACKAGE##",le);const pe={mcpId:"decaf",name:"decaf-ts mcp server",title:"Decaf-TS MCP Server",description:"Provides precise coding assistance for the decaf-ts framework",version:le,websiteUrl:"https://decaf-ts.github.io",repositoryUrl:"https://github.com/decaf-ts/mcp-server",license:"AGPL-3.0",workingDir:W,assetDir:Y(),contacts:[{name:"Decaf-TS",url:"https://decaf-ts.github.io"}],tags:"server,official,decaf-ts",metadata:{},icons:[{src:"workdocs/assets/favicon.svg",mimeType:"image/svg+xml",sizes:"any"}],jira:{host:process.env.JIRA__HOST||"decaf-ts.atlassian.net",email:process.env.JIRA__EMAIL||"",apiKey:process.env.JIRA__API_KEY||process.env.JIRA__APIKEY||"",projectKey:process.env.JIRA__PROJECT_KEY||void 0,issueType:process.env.JIRA__ISSUE_TYPE||void 0,parentIssue:process.env.JIRA__PARENT_ISSUE||void 0},level:r.LogLevel.error},de=r.LoggedEnvironment.accumulate(pe);function ue(){const{host:e,email:t,apiKey:r,projectKey:s,issueType:n}=de.jira;return{host:e?.trim(),email:t?.trim(),apiKey:r?.trim(),projectKey:s?.trim(),issueType:n?.trim(),parentIssue:de.jira.parentIssue?.trim()}}function me(){const e=ue();return[{name:"JIRA__HOST",required:!0,description:"Atlassian host (e.g. decaf-ts.atlassian.net) where your Jira instance is hosted.",value:e.host},{name:"JIRA__EMAIL",required:!0,description:"Email address of the Jira account that has API access.",value:e.email},{name:"JIRA__API_KEY",required:!0,description:"API token created in your Atlassian profile (a.k.a. APIKEY alias) for authenticating requests.",sensitive:!0,value:e.apiKey},{name:"JIRA__PROJECT_KEY",required:!1,description:"Default Jira project key (e.g. DECAF) used when an issue creation request omits a project.",value:e.projectKey},{name:"JIRA__ISSUE_TYPE",required:!1,description:"Default Jira issue type (e.g. Task, Bug) used when creating issues without an explicit type.",value:e.issueType},{name:"JIRA__PARENT_ISSUE",required:!1,description:"Default parent issue key (e.g. DECAF-123) applied when a child issue is created without an explicit parent.",value:e.parentIssue}]}function he(e){const t=e.value?((e,t)=>{if(e)return t?"<configured>":e})(e.value,e.sensitive):"not set",r=e.required?"(required)":"(optional)";return`\u2022 ${e.name} ${r}: ${e.description} Current state: ${t}.`}r.Logging.setConfig(de);class fe extends Error{constructor(e){const t=me(),r=(e=>{const t=me();return`${e.length?`Missing Jira credentials: ${e.map(e=>e.name).join(", ")}.`:"Jira credentials are configured."}\n\nThis setup uses the following environment variables:\n${t.map(he).join("\n")}`})(e);super(r),this.name="MissingJiraEnvironmentError",this.descriptors=t,this.missing=e,"function"==typeof Error.captureStackTrace&&Error.captureStackTrace(this,fe)}}function ge(e){if(!e)return{code:"jira_error",message:"Unknown Jira error",details:{raw:e}};const t=e?.status??e?.statusCode??e?.response?.status??e?.response?.statusCode,r="number"==typeof t?t:Number(t)||void 0,s=e?.response?.data??e?.data??e?.response?.body??e?.body,n=[];"string"==typeof e?.message&&n.push(e.message),((e,t)=>{e&&(Array.isArray(e.errorMessages)&&e.errorMessages.forEach(e=>"string"==typeof e&&t.push(e)),"string"==typeof e.errorMessage&&t.push(e.errorMessage),e.errorCollection&&Array.isArray(e.errorCollection.errors)&&e.errorCollection.errors.forEach(e=>{"string"==typeof e?t.push(e):e&&"string"==typeof e.message&&t.push(e.message)}),e?.errors&&"object"==typeof e.errors&&Object.values(e.errors).forEach(e=>{"string"==typeof e?t.push(e):"string"==typeof e?.message&&t.push(e.message)}))})(s,n);const i=r?`Jira API error (${r})`:"Jira API error",o=n.length>0?n.join(" | "):i;return{code:r?"jira_"+r:e?.code??"jira_error",message:o,details:{httpStatus:r,body:s,raw:e}}}const ye=a.z.object({issueId:a.z.string().min(1),deleteSubtasks:a.z.boolean().optional().default(!0)}),be={name:"jira-issue-delete",inputSchema:ye,runTool:async(e,t)=>{try{const r=ye.parse(t),s=e.issues??e.issue??e,n=s?.delete??s?.deleteIssue;if("function"!=typeof n)throw Error("jira client delete endpoint is not available");return await n.call(s,{issueId:r.issueId,deleteSubtasks:r.deleteSubtasks}),{success:!0,message:`Issue ${t.issueId} deleted successfully`}}catch(e){throw ge(e)}}},ve=a.z.object({issueId:a.z.string().min(1),expand:a.z.string().optional(),fields:a.z.array(a.z.string()).optional(),properties:a.z.array(a.z.string()).optional()}),we={name:"jira-issue-read",inputSchema:ve,runTool:async(e,t)=>{try{const r=ve.parse(t),s={issueIdOrKey:r.issueId};r.expand&&(s.expand=r.expand),r.fields&&(s.fields=r.fields),r.properties&&(s.properties=r.properties);const n=await e.issues.get(s);return n?.data??n}catch(e){throw ge(e)}}};function Se(e,t,r){const s=((e.url??"")+"").match(/^(attachment|jira-attachment):(.+)$/i);if(!s)return null;const n=s[2],i=r.resolveAttachment?.(n);return i?{type:"block",node:{type:"mediaSingle",attrs:{layout:"center"},content:[{type:"media",attrs:{type:"file",id:i.id,collection:i.collection??"attachments"}}]}}:null}function je(e,t){if(!e)return[];if(!t.enableAtMentions&&!t.enableEmojiShortcodes)return[{type:"text",text:e}];let r=0;const s=[],n=/(^|[^A-Za-z0-9_])@([A-Za-z0-9._-]{1,64})/g,i=/:([a-z0-9_+-]{1,64}):/gi;for(;r<e.length;){const o=_e(t.enableAtMentions?xe(n,e,r):null,t.enableEmojiShortcodes?xe(i,e,r):null);if(!o){s.push({type:"text",text:e.slice(r)});break}if(o.index>r&&s.push({type:"text",text:e.slice(r,o.index)}),"mention"===o.kind){const{full:e,groups:n}=o,i=n[0]??"",a=n[1]??"";i&&s.push({type:"text",text:i});const c=t.resolveMention?.(a);c?s.push({type:"mention",attrs:{id:c.id,text:c.text}}):s.push({type:"text",text:"@"+a}),r=o.index+e.length;continue}if("emoji"===o.kind){const{full:e,groups:n}=o,i=`:${n[0]}:`,a=t.resolveEmoji?.(i);s.push({type:"emoji",attrs:a?{shortName:a.shortName,text:a.text}:{shortName:i}}),r=o.index+e.length;continue}}return(e=>{const t=[];for(const r of e){const e=t[t.length-1];"text"!==r.type||"text"!==e?.type||e.marks||r.marks?t.push(r):e.text=(e.text??"")+(r.text??"")}return t})(s)}function xe(e,t,r){e.lastIndex=r;const s=e.exec(t);if(!s)return null;const n=e.source.includes("@")?"mention":"emoji";return{index:s.index,full:s[0],groups:s.slice(1),kind:n}}function _e(e,t){return e?t&&e.index>t.index?t:e:t}function Ie(e){const t=(e.children??[])[0];return"text"===t?.type?(t.value??"")+"":"paragraph"===t?.type?((t.children??[]).map(e=>"text"===e.type?(e.value??"")+"":"").join("")||"")+"":""}function ze(e){const t=((e??"")+"").toLowerCase().trim();return t?"info"===t||"note"===t||"success"===t||"warning"===t||"error"===t?t:"danger"===t?"error":null:null}function Ee(e){const t=((e??"")+"").toLowerCase().trim();return!t||"neutral"!==t&&"green"!==t&&"yellow"!==t&&"red"!==t&&"blue"!==t&&"purple"!==t?null:t}function ke(e,t){const r=[];for(const s of e??[])if(s?.type)if("text"!==s.type)if("strong"!==s.type)if("emphasis"!==s.type)if("delete"!==s.type)if("inlineCode"!==s.type)if("break"!==s.type){if("link"===s.type){const e=(s.url??"")+"",n=Ae(s.children??[],e),i=Se(s,0,t);if(i){"inline"===i.type?r.push(i.node):r.push({type:"text",text:n,marks:[{type:"link",attrs:{href:e}}]});continue}if(t.enableSmartCards&&Oe(n,e)){r.push({type:"inlineCard",attrs:{url:e}});continue}r.push({type:"text",text:n,marks:[{type:"link",attrs:{href:e}}]});continue}if("textDirective"===s.type&&"status"===s.name){const e=Ie(s)||"Status",t=Ee(s.attributes?.color)??"neutral";r.push({type:"status",attrs:{text:e,color:t}});continue}if("textDirective"===s.type&&"emoji"===s.name){const e=Ne(s);r.push(Ce(e,t));continue}}else r.push({type:"hardBreak"});else r.push({type:"text",text:(s.value??"")+"",marks:[{type:"code"}]});else r.push(...Te(ke(s.children??[],t),{type:"strike"}));else r.push(...Te(ke(s.children??[],t),{type:"em"}));else r.push(...Te(ke(s.children??[],t),{type:"strong"}));else r.push(...je((s.value??"")+"",t));return r.filter(e=>!("text"===e.type&&""===(e.text??"")))}function Te(e,t){return e.map(e=>{if("text"!==e.type)return e;const r=e.marks?[...e.marks,t]:[t];return{...e,marks:r}})}function Ae(e,t){const r=[];for(const t of e??[])"text"===t.type||"inlineCode"===t.type?r.push((t.value??"")+""):"emphasis"!==t.type&&"strong"!==t.type&&"delete"!==t.type||r.push(Ae(t.children??[],""));return r.join("")||t}function Oe(e,t){const r=(e??"").trim(),s=(t??"").trim();return r===s&&/^https?:\/\//i.test(s)}function Ne(e){return(e.children??[]).map(e=>"text"===e.type?(e.value??"")+"":"").join("").trim()||""}function Ce(e,t){const r=e.startsWith(":")?e:`:${e}:`,s=t.resolveEmoji?.(r);return s?{type:"emoji",attrs:{shortName:s.shortName,text:s.text}}:{type:"emoji",attrs:{shortName:r}}}function He(e){return e?"string"==typeof e?e:"text"===e.type||"inlineCode"===e.type?(e.value??"")+"":Array.isArray(e.children)?e.children.map(He).join(""):"":""}function De(e,t){if(!e?.type)return null;if((e=>"containerDirective"===e?.type&&"panel"===e?.name)(e))return((e,t)=>{const r=e.attributes??{},s=ze(r.type)??"info",n="string"==typeof r.title?r.title:void 0,i=(e.children??[]).map(e=>De(e,t)).flat().filter(Boolean);return{type:"panel",attrs:{panelType:s,...n?{panelType:s,title:n}:{panelType:s}},content:i.length?i:[{type:"paragraph",content:[]}]}})(e,t);switch(e.type){case"heading":return{type:"heading",attrs:{level:qe(e.depth??1,1,6)},content:ke(e.children??[],t)};case"paragraph":{const r=(e=>{const t=e.children??[];if(1!==t.length)return null;const r=t[0];if("image"!==r?.type)return null;const s=(r.url??"")+"";return s?{type:"mediaSingle",attrs:{layout:"center"},content:[{type:"media",attrs:{type:"external",url:s}}]}:null})(e);return r||{type:"paragraph",content:ke(e.children??[],t)}}case"blockquote":return{type:"blockquote",content:(e.children??[]).map(e=>De(e,t)).flat().filter(Boolean)};case"list":return((e,t)=>t.enableTaskLists&&(e.children??[]).some(e=>"boolean"==typeof e.checked)?((e,t)=>{const r=[];let s=0;for(const n of e.children??[]){if("boolean"!=typeof n.checked)continue;s+=1;const e=(n.children??[]).map(e=>De(e,t)).flat().filter(Boolean);r.push({type:"taskItem",attrs:{localId:"task-"+s,state:n.checked?"DONE":"TODO"},content:e.length?e:[{type:"paragraph",content:[]}]})}return{type:"taskList",content:r}})(e,t):{type:e.ordered?"orderedList":"bulletList",content:(e.children??[]).map(e=>((e,t)=>{const r=(e.children??[]).map(e=>De(e,t)).flat().filter(Boolean);return{type:"listItem",content:r.length?r:[{type:"paragraph",content:[]}]}})(e,t))})(e,t);case"code":{const r=((e,t)=>{const r=(e??"").toString().trim().toLowerCase();return r?t.enableMermaid&&"mermaid"===r?"mermaid":(e=>{const t=e.trim().toLowerCase();return{js:"javascript",javascript:"javascript",jsx:"javascript",ts:"typescript",typescript:"typescript",tsx:"typescript",py:"python",python:"python",rb:"ruby",ruby:"ruby",sh:"bash",bash:"bash",zsh:"bash",shell:"bash",yml:"yaml",yaml:"yaml",json:"json",toml:"toml",xml:"xml",html:"html",css:"css",scss:"scss",sql:"sql",go:"go",rust:"rust",java:"java",c:"c",cpp:"cpp","c++":"cpp",cs:"csharp",csharp:"csharp",php:"php",kotlin:"kotlin",swift:"swift",md:"markdown",markdown:"markdown",graphql:"graphql",gql:"graphql",dockerfile:"docker",makefile:"make",ini:"ini"}[t]??t})(r):null})(e.lang,t);return{type:"codeBlock",attrs:{language:r},content:[{type:"text",text:(e.value??"")+""}]}}case"thematicBreak":return{type:"rule"};case"table":return((e,t)=>({type:"table",content:(e.children??[]).map((e,r)=>({type:"tableRow",content:(e.children??[]).map(e=>({type:0===r?"tableHeader":"tableCell",content:[{type:"paragraph",content:ke(e.children??[],t)}]}))}))}))(e,t);case"leafDirective":return"status"===e.name?(e=>{const t=Ee((e.attributes??{}).color)??"neutral";return{type:"paragraph",content:[{type:"status",attrs:{text:Ie(e)||"Status",color:t}}]}})(e):"panel"===e.name?((e,t)=>{const r=e.attributes??{},s=ze(r.type)??"info",n="string"==typeof r.title?r.title:void 0;return{type:"panel",attrs:{panelType:s,...n?{title:n}:{}},content:[{type:"paragraph",content:ke([{type:"text",value:Ie(e)}],t)}]}})(e,t):Je(e,t);default:return Je(e,t)}}function Je(e,t){if("drop"===t.unknownNodeStrategy)return null;const r=He(e);return r?{type:"paragraph",content:[{type:"text",text:r}]}:null}function qe(e,t,r){const s=Number.isFinite(e)?Math.trunc(e):t;return Math.max(t,Math.min(r,s))}const Pe={resolveMention:void 0,resolveAttachment:void 0,resolveEmoji:void 0,enableSmartCards:!0,enableMermaid:!0,enableEmojiShortcodes:!0,enableAtMentions:!0,enableTaskLists:!0,unknownNodeStrategy:"text"};function Me(e,t={}){const r={...Pe,...t},s=e??"",n=h.unified().use(y).use(g).use(f),i=n.parse(s),o=n.runSync(i);return Re(o),((e,t)=>{const r=[];for(const s of e.children??[]){const e=De(s,t);e&&(Array.isArray(e)?r.push(...e):r.push(e))}return((e,t)=>{if(!t.enableSmartCards)return e;const r=e.content.map(e=>(e=>{if("paragraph"!==e.type)return e;const t=e.content??[];if(1!==t.length)return e;const r=t[0];if("inlineCard"!==r?.type)return e;const s=r.attrs?.url;return s?[{type:"blockCard",attrs:{url:s}}]:e})(e)).flat();return{...e,content:r}})({version:1,type:"doc",content:r},t)})(o,r)}function Re(e){if(!e||!Array.isArray(e.children))return;const t=[];for(const r of e.children)"definition"!==r?.type&&("html"!==r?.type?(Re(r),t.push(r)):t.push({type:"text",value:(r.value??"")+""}));e.children=t}const $e=a.z.object({issueId:a.z.string().min(1),transitionId:a.z.union([a.z.string(),a.z.number()]),fields:a.z.record(a.z.any()).optional(),update:a.z.record(a.z.array(a.z.object({set:a.z.any().optional(),add:a.z.any().optional(),remove:a.z.any().optional()}))).optional(),comment:a.z.string().optional()}),Le={name:"jira-issue-transition",inputSchema:$e,runTool:async(e,t)=>{try{const r=$e.parse(t),s={id:r.transitionId};r.fields&&(s.fields=r.fields),r.update&&(s.update=r.update),r.comment&&(s.comment={body:Me(r.comment)});const n=await e.issues.transition({issueId:r.issueId,transition:s});return n?.data??n}catch(e){throw ge(e)}}},Fe=a.z.object({issueId:a.z.string().min(1),fields:a.z.record(a.z.any()).optional(),update:a.z.record(a.z.array(a.z.object({set:a.z.any().optional(),add:a.z.any().optional(),remove:a.z.any().optional(),edit:a.z.any().optional()}))).optional(),properties:a.z.array(a.z.any()).optional(),notifyUsers:a.z.boolean().optional().default(!0),issueTemplateId:a.z.string().optional(),overrideScreenSecurity:a.z.boolean().optional().default(!1),overrideEditableFlag:a.z.boolean().optional().default(!1)}),Be={name:"jira-issue-update",inputSchema:Fe,runTool:async(e,t)=>{try{const r=Fe.parse(t),s={issueId:r.issueId};r.fields&&(s.fields=r.fields),r.update&&(s.update=r.update),r.properties&&(s.properties=r.properties),void 0!==r.notifyUsers&&(s.notifyUsers=r.notifyUsers),r.issueTemplateId&&(s.issueTemplateId=r.issueTemplateId),void 0!==r.overrideScreenSecurity&&(s.overrideScreenSecurity=r.overrideScreenSecurity),void 0!==r.overrideEditableFlag&&(s.overrideEditableFlag=r.overrideEditableFlag);const n=await e.issues.update(s);return n?.data??n}catch(e){throw ge(e)}}},We=a.z.object({issueId:a.z.string().min(1),assignee:a.z.union([a.z.string(),a.z.object({accountId:a.z.string().min(1)}),a.z.object({accountType:a.z.string().min(1)})])}),Ue={name:"jira-assign-issue",inputSchema:We,runTool:async(e,t)=>{try{const r=We.parse(t);let s;s="string"==typeof r.assignee?{accountId:r.assignee}:r.assignee;const n=await e.issues.assign({issueId:r.issueId,assignee:s});return n?.data??n}catch(e){throw ge(e)}}},Ke=a.z.object({issueId:a.z.string().min(1)}),Ye={name:"jira-unassign-issue",inputSchema:Ke,runTool:async(e,t)=>{try{const r=Ke.parse(t),s=await e.issues.assign({issueId:r.issueId,assignee:{accountId:"-1"}});return s?.data??s}catch(e){throw ge(e)}}},Ve=a.z.object({issueId:a.z.string().min(1),body:a.z.string().min(1),visibility:a.z.object({type:a.z.enum(["role","group"]),value:a.z.string().min(1)}).optional()}),Ge={name:"jira-comment-add",inputSchema:Ve,runTool:async(e,t)=>{try{const r=Ve.parse(t),s={body:Me(r.body)};r.visibility&&(s.visibility=r.visibility);const n=await e.issues.addComment({issueId:r.issueId,comment:s});return n?.data??n}catch(e){throw ge(e)}}},Ze=a.z.object({issueId:a.z.string().min(1),start:a.z.number().optional().default(0),maxResults:a.z.number().optional().default(50),orderBy:a.z.string().optional(),expand:a.z.string().optional()}),Qe={name:"jira-comment-list",inputSchema:Ze,runTool:async(e,t)=>{try{const r=Ze.parse(t),s=await e.issues.getComments({issueId:r.issueId,start:r.start,maxResults:r.maxResults,orderBy:r.orderBy,expand:r.expand});return s?.data??s}catch(e){throw ge(e)}}},Xe=a.z.object({link:a.z.object({relationship:a.z.enum(["Blocks","Relates to","Duplicates","Is blocked by","Is related to","Is duplicated by","Causes","Is caused by","Clone","Required","Work on","Split","Roll up"]),inwardIssue:a.z.object({id:a.z.string().optional(),key:a.z.string().optional()}),outwardIssue:a.z.object({id:a.z.string().optional(),key:a.z.string().optional()}),comment:a.z.object({body:a.z.string().optional(),visibility:a.z.object({type:a.z.enum(["role","group"]),value:a.z.string().min(1)}).optional()}).optional()})}),et={name:"jira-link-create",inputSchema:Xe,runTool:async(e,t)=>{try{const r=Xe.parse(t).link,s={relationship:r.relationship,inwardIssue:r.inwardIssue.id||r.inwardIssue.key,outwardIssue:r.outwardIssue.id||r.outwardIssue.key};r.comment&&(r.comment.body&&(s.comment=Me(r.comment.body)),r.comment.visibility&&(s.visibility=r.comment.visibility));const n=await e.issues.link(s);return n?.data??n}catch(e){throw ge(e)}}},tt=a.z.object({issueId:a.z.string().min(1),file:a.z.string().min(1),mimeType:a.z.string().optional(),comment:a.z.string().optional()}),rt={name:"jira-attach",inputSchema:tt,runTool:async(e,r)=>{try{const s=tt.parse(r),i=n.resolve(s.file),o=await t.promises.readFile(i),a=n.basename(i),c=await e.issues.addAttachment({issueId:s.issueId,file:{name:a,content:o,mimeType:s.mimeType??"application/octet-stream"},comment:s.comment});return c?.data??c}catch(e){if(e&&e.code&&"string"==typeof e.code&&["ENOENT","EACCES"].includes(e.code))throw Error("Attachment file error: "+e.message);throw ge(e)}}},st=a.z.object({issueId:a.z.string().min(1)}),nt={name:"jira-attachment-list",inputSchema:st,runTool:async(e,t)=>{try{const r=st.parse(t),s=await e.issues.getAttachments({issueId:r.issueId});return s?.data??s}catch(e){throw ge(e)}}},it=a.z.object({issueId:a.z.string().min(1),attachmentId:a.z.string().min(1)}),ot={name:"jira-attachment-delete",inputSchema:it,runTool:async(e,t)=>{try{const r=it.parse(t);return await e.issues.deleteAttachment({issueId:r.issueId,attachmentId:r.attachmentId}),{success:!0,message:`Attachment ${t.attachmentId} deleted successfully`}}catch(e){throw ge(e)}}},at=a.z.object({issueId:a.z.string().min(1),timeSpent:a.z.string().min(1),comment:a.z.string().optional(),author:a.z.object({accountId:a.z.string().min(1)}).optional(),startingOn:a.z.string().optional(),artifact:a.z.string().optional()}),ct={name:"jira-worklog-add",inputSchema:at,runTool:async(e,t)=>{try{const r=at.parse(t),s={timeSpent:r.timeSpent};r.comment&&(s.comment=r.comment),r.author&&(s.author=r.author),r.startingOn&&(s.started=r.startingOn),r.artifact&&(s.artifact=r.artifact);const n=await e.issues.addWorklog({issueId:r.issueId,...s});return n?.data??n}catch(e){throw ge(e)}}},lt={[we.name]:{title:"Jira Issue Read",description:"Read a Jira issue with expandable fields and properties",annotations:{readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1}},[Be.name]:{title:"Jira Issue Update",description:"Update a Jira issue using fields, update ops, and property toggles",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}},[be.name]:{title:"Jira Issue Delete",description:"Delete a Jira issue and optionally remove its subtasks",annotations:{readOnlyHint:!1,destructiveHint:!0,idempotentHint:!1,openWorldHint:!0}},[Le.name]:{title:"Jira Issue Transition",description:"Transition a Jira issue while optionally adding a comment",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}},[Ue.name]:{title:"Jira Issue Assign",description:"Assign a Jira issue to a user or account",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}},[Ye.name]:{title:"Jira Issue Unassign",description:"Unassign the current owner from a Jira issue",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}},[Ge.name]:{title:"Jira Comment Add",description:"Add a comment to a Jira issue with optional visibility",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}},[Qe.name]:{title:"Jira Comment List",description:"List comments on a Jira issue with pagination support",annotations:{readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1}},[et.name]:{title:"Jira Link Create",description:"Create an issue link relationship with optional comment",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}},[rt.name]:{title:"Jira Attachment Add",description:"Attach a local file to a Jira issue",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}},[nt.name]:{title:"Jira Attachment List",description:"List attachments on a Jira issue",annotations:{readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1}},[ot.name]:{title:"Jira Attachment Delete",description:"Delete an attachment from a Jira issue",annotations:{readOnlyHint:!1,destructiveHint:!0,idempotentHint:!1,openWorldHint:!0}},[ct.name]:{title:"Jira Worklog Add",description:"Log time spent on a Jira issue",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}}};async function pt(e){const t=r.Logging.for(pt);let s,n=null;try{s=(()=>{let e;try{const t=require("jira.js");e=t?.Version3Client||t.default?.Version3Client||t.default||t}catch(e){throw Error("Unable to require 'jira.js' \u2014 ensure it is installed as a dependency: "+e)}const{host:t,email:r,apiKey:s}=(()=>{const e=ue(),t=me().filter(e=>e.required&&!e.value);if(t.length>0)throw new fe(t);return{host:e.host,email:e.email,apiKey:e.apiKey}})();return new e({host:t,authentication:{basic:{email:r,apiToken:s}}})})()}catch(e){if(!(e instanceof fe))return void t.warn("Skipping Jira tool registration; unable to create Jira client",{error:e});n=e,t.warn("Registering Jira tools without credentials; each tool will report configuration requirements.",{error:e})}const i=[we,Be,be,Le,Ue,Ye,Ge,Qe,et,rt,nt,ot,ct];for(const r of i){const i=lt[r.name];if(i)try{await e.registerTool(r.name,{title:i.title,description:i.description,inputSchema:P(r.inputSchema),annotations:i.annotations},async e=>{if(!s)throw n??Error("Jira client unavailable because credentials could not be loaded.");return r.runTool(s,e)}),t.info("Registered Jira tool "+r.name)}catch(e){t.error("Failed to register Jira tool "+r.name,{error:e})}}}async function dt(e){await(async e=>{e.registerTool("decaf-server-info",{title:"Decaf MCP Server Info",description:"Return server metadata, version, and registered prompt names for diagnostics.",inputSchema:{},outputSchema:void 0,annotations:{readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1}},async()=>{const e=ie.map(e=>e.getName()).sort();return{content:[{type:"text",text:["Name: "+de.name,"Title: "+de.title,"Version: "+de.version,"Prompts: "+(e.join(", ")||"<none>")].join("\n")}]}})})(e);const t=r.Logging.for(dt);try{await pt(e)}catch(e){t.error("Failed to register Jira tools",e)}}class ut extends H{setCb(e){return this.cb=e,this}setConfig(e){return this.config=e,this}setUriOtTemplate(e){return this.uriOrTemplate=e,this}constructor(e){super(e)}static get builder(){return new ut}build(e){const t=this.hasErrors();if(t)throw Error(t.toString());try{const t="string"==typeof this.uriOrTemplate&&this.uriOrTemplate.includes("{")?new v.ResourceTemplate(new b.UriTemplate(this.uriOrTemplate),{list:void 0}):this.uriOrTemplate,r=Object.assign(this.config,{_meta:{}}),s=async(e,t)=>{const r=this.logFor(t);r.verbose(`Requesting resource ${this.name} from ${e.toString()}`);const s=await Promise.resolve(this.cb(e,t));return r.verbose(`Resource ${this.name} retrieved successfully.`),r.debug("Resource retrieval meta: "+JSON.stringify(s._meta)),s};return e.resource(this.name,t,r,s)}catch(e){throw r.Logging.for(this).error("Error registering resource "+this.name,e),e}}}i.__decorate([o.required(),i.__metadata("design:type",String)],ut.prototype,"uriOrTemplate",void 0),i.__decorate([o.required(),i.__metadata("design:type",Function)],ut.prototype,"cb",void 0),i.__decorate([o.required(),i.__metadata("design:type",Object)],ut.prototype,"config",void 0);const mt=Y()??I.join(__dirname,"..","assets"),ht=I.join(mt,"templates"),ft=I.join(mt,"prompts"),gt=new WeakMap;class yt extends r.LoggedClass{get client(){const e=gt.get(this);if(!e)throw Error("Mcp server requires Mcp client");return e}constructor(){super()}async load(){const e=this.log.for(this.load);for(const t of ie)try{e.info("loading prompt "+t.getName());const r=t.build(this.client);e.verbose(`Loaded prompt ${r.title} from ${t.getName()} definition`)}catch(r){e.error("Failed to load prompt "+t.getName(),r)}try{await dt(this.client),e.verbose("Registered built-in tools")}catch(t){e.error("Failed to register tools",t)}try{await(async(e,t)=>{t.info("Registering agent templates as resources...");const r=_.readdirSync(ht).filter(e=>e.endsWith(".md"));for(const s of r){const r=I.basename(s,".md"),n=I.join(ht,s),i=ut.builder.setName(r).setTitle("Template: "+r).setDescription("Resource template for "+r).setUriOtTemplate("file:///"+n).setConfig({mimeType:"text/markdown",description:"Template for "+r}).setCb(async e=>{const t=_.readFileSync(e.pathname,"utf8");return{contents:[{uri:e.toString(),text:t,mimeType:"text/markdown"}],_meta:{}}});try{i.build(e),t.info("Registered template: "+r)}catch(e){t.error(`Failed to register template ${r}:`,e)}}t.info("Registering agent prompts...");const s=_.readdirSync(ft).filter(e=>e.endsWith(".md"));for(const r of s){const s=I.basename(r,".md"),n=I.join(ft,r),i=_.readFileSync(n,"utf8"),o=G.builder.setName(s).setTitle("Prompt: "+s).setDescription("Dynamic prompt for "+s).setArgsSchema(a.z.object({})).setCb(async e=>({messages:[{role:"user",content:{type:"text",text:i}}],_meta:{}}));try{o.build(e),t.info("Registered prompt: "+s)}catch(e){t.error(`Failed to register prompt ${s}:`,e)}}})(this.client,e),e.verbose("Registered agent-specific assets")}catch(t){e.error("Failed to register agent assets",t)}}async boot(e="stdio"){let t=this.log;this.log.for(this.boot).info("McpServer booting..."),((e=r.Logging.get())=>{let t;try{t=(()=>{let e,t=__dirname;try{for(;t&&t!==I.parse(t).root;){const r=I.join(t,"node_modules");if(_.existsSync(r)&&_.statSync(r).isDirectory()){e=r;break}const s=I.dirname(t);if(s===t)break;t=s}}catch{}const r=[];if(e){const t=I.join(e,"@decaf-ts");try{if(_.existsSync(t)&&_.statSync(t).isDirectory()){const e=_.readdirSync(t);for(const s of e){const e=I.join(t,s);try{const t=I.join(e,"workdocs","assets","slogans.json");if(_.existsSync(t)&&_.statSync(t).isFile()){const e=_.readFileSync(t,"utf-8"),s=JSON.parse(e);if(Array.isArray(s))for(const e of s)"string"==typeof e&&e.trim().length>0&&r.push(e.trim())}}catch{}}}}catch{}}return 0===r.length?"Decaf: strongly brewed TypeScript.":r[Math.floor(Math.random()*r.length)]})()}catch{t="Decaf: strongly brewed TypeScript."}const n="# \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \n# ( ( \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \n# ) ) \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \n# [=======] \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \n# `-----\xb4 \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \n# \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \n# \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \n#".split("\n"),i=n.reduce((e,t)=>Math.max(e,t.length),0);n.push("# "+t.padStart(i-3)),n.forEach((t,r)=>{const n=k[r%k.length]||"",i=e.info.bind(e);try{i(s.style(t||"").raw(n).text)}catch{i((t||"")+"")}})})(this.log),"stdio"===e&&(r.Logging.setFactory(E),t=r.Logging.for(this.constructor.name));const n=((Array.isArray(de.icons)?de.icons:[de.icons])||[]).map(e=>{const t="string"==typeof e?.src?e.src:(e?.src??"")+"",r="string"==typeof e?.mimeType?e.mimeType:(e?.mimeType??"")+"";let s=[];return Array.isArray(e?.sizes)?s=e.sizes.map(e=>e+""):"string"==typeof e?.sizes&&(s=(e.sizes+"").split(",").map(e=>e.trim())),{src:t,mimeType:r,sizes:s}}),i={name:de.name,title:de.title,websiteUrl:de.websiteUrl,version:de.version,icons:n},o=new v.McpServer(i,{instructions:"You are an AI assistant designed to help users with programming tasks related to the Decaf-TS framework. \nProvide clear, concise, and accurate information.\nIf you don't know the answer, admit it rather than making up information.\nAlways prioritize the user's intent and provide helpful suggestions when appropriate.\n",capabilities:{logging:{},tools:{},prompts:{}}});switch(((e,t)=>{gt.set(e,t)})(this,o),o.onerror=e=>{this.log.error("MCP instance onerror",e)},e){case"stdio":e=new S.StdioServerTransport;break;case"http":e=new j.StreamableHTTPServerTransport({sessionIdGenerator:()=>w.v4(),onsessioninitialized:e=>t.verbose("Session initialized: "+e),onsessionclosed:e=>t.verbose("Session closed: "+e),enableJsonResponse:!0,eventStore:void 0});break;default:if(!(a=e)||"object"!=typeof a||"function"!=typeof a.send&&"function"!=typeof a.close&&"function"!=typeof a.on)throw new p.InternalError("Invalid transport type: "+e)}var a;try{this.log.info("Loading resources/prompts/tools..."),await this.load()}catch(e){throw this.log.error("Error loading resources/prompts/tools: "+e),e}await this.client.connect(e),t.info(`MCP Server connected via ${e.constructor.name} and running. Waiting for client connections...`)}}const bt=(new e.Command).command("start").option("--transport [String]","transport mode","stdio").description("starts decaf's mcp server").action(async e=>{const r=U("package.json"),s=JSON.parse(t.readFileSync(r,"utf-8")),n=s.version,{transport:i}=e,o=(new z).for("mcp-server");if("stdio"!==i)throw Error("Unsupported transport mode: "+i);return o.info("Transport stdio"),o.debug(`running with options: ${JSON.stringify(e)} for ${s.name} version ${n}`),(new yt).boot(i)});(new e.Command).command("md-to-ast").description("pipes markdown to jira ast: `cat file.md` | npx decaf-mcp md-to-ast > ast.json").action(async e=>{const s=U("package.json"),n=JSON.parse(t.readFileSync(s,"utf-8")),i=n.version;r.Logging.for("md-to-ast").debug(`running with options: ${JSON.stringify(e)} for ${n.name} version ${i}`);const o=Me(await(async()=>{const e=[];for await(const t of process.stdin)e.push(Buffer.from(t));return Buffer.concat(e).toString("utf8")})(),{resolveMention:e=>({id:e,text:"@"+e}),resolveAttachment:e=>({id:e,collection:"attachments"})});process.stdout.write(JSON.stringify(o,null,2)+"\n")});const vt=(new e.Command).name("mcp-server").command("mcp-server").description("decaf mcp server and agentic functionality");vt.addCommand(bt),vt.parse(process.argv)},"object"==typeof exports&&"undefined"!=typeof module?t(require("commander"),require("fs"),require("@decaf-ts/logging"),require("styled-string-builder"),require("path"),require("tslib"),require("@decaf-ts/decorator-validation"),require("zod"),require("@decaf-ts/injectable-decorators"),require("@decaf-ts/decoration"),require("@decaf-ts/db-decorators"),require("crypto"),require("zlib"),require("url"),require("unified"),require("remark-directive"),require("remark-gfm"),require("remark-parse"),require("@modelcontextprotocol/sdk/shared/uriTemplate.js"),require("@modelcontextprotocol/sdk/server/mcp.js"),require("uuid"),require("@modelcontextprotocol/sdk/server/stdio.js"),require("@modelcontextprotocol/sdk/server/streamableHttp.js")):"function"==typeof define&&define.amd?define(["commander","fs","@decaf-ts/logging","styled-string-builder","path","tslib","@decaf-ts/decorator-validation","zod","@decaf-ts/injectable-decorators","@decaf-ts/decoration","@decaf-ts/db-decorators","crypto","zlib","url","unified","remark-directive","remark-gfm","remark-parse","@modelcontextprotocol/sdk/shared/uriTemplate.js","@modelcontextprotocol/sdk/server/mcp.js","uuid","@modelcontextprotocol/sdk/server/stdio.js","@modelcontextprotocol/sdk/server/streamableHttp.js"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).commander,e.fs,e.decafTsLogging,e.styledStringBuilder,e.path,e.tslib,e.decafTsDecoratorValidation,e.zod,e.decafTsInjectableDecorators,e.decafTsDecoration,e.decafTsDbDecorators,e.crypto,e.zlib,e.url,e.unified,e.remarkDirective,e.remarkGfm,e.remarkParse,e.uriTemplate_js,e.mcp_js,e.uuid,e.stdio_js,e.streamableHttp_js);
3
3
  //# sourceMappingURL=mcp-server.cjs.map
@@ -1,2 +1,2 @@
1
- import{Command as t}from"commander";import*as e from"fs";import r,{promises as s}from"fs";import{MiniLogger as n,NumericLogLevels as i,Logging as o,LoggedClass as a,toSnakeCase as c,sf as p,toPascalCase as l,LogLevel as u,LoggedEnvironment as d}from"@decaf-ts/logging";import{style as m}from"styled-string-builder";import*as h from"path";import f from"path";import{__decorate as y,__metadata as g}from"tslib";import{required as b,Model as v,list as w,minlength as S}from"@decaf-ts/decorator-validation";import{z as j,ZodObject as x}from"zod";import{injectable as I,inject as k}from"@decaf-ts/injectable-decorators";import{prop as A,Metadata as E}from"@decaf-ts/decoration";import{InternalError as T,SerializationError as N,ValidationError as O}from"@decaf-ts/db-decorators";import C from"crypto";import H from"zlib";import{fileURLToPath as J}from"url";import{unified as _}from"unified";import D from"remark-directive";import P from"remark-gfm";import R from"remark-parse";import{UriTemplate as $}from"@modelcontextprotocol/sdk/shared/uriTemplate.js";import{ResourceTemplate as M,McpServer as F}from"@modelcontextprotocol/sdk/server/mcp.js";import{v4 as q}from"uuid";import{StdioServerTransport as B}from"@modelcontextprotocol/sdk/server/stdio.js";import{StreamableHTTPServerTransport as W}from"@modelcontextprotocol/sdk/server/streamableHttp.js";class L extends n{log(t,e,r,s){const n=this.config("level");i[n],i[t]}}const U=(t,e,...r)=>{const s=(t=>{if("string"==typeof t)return t;if(!t)return"unknown";if("function"==typeof t)return t.name||"unknown";if("object"==typeof t&&"constructor"in t){const e=t.constructor;if(e&&e.name)return e.name}return"unknown"})(t);return new L(s,e)},K=["\x1b[38;5;215m","\x1b[38;5;209m","\x1b[38;5;205m","\x1b[38;5;210m","\x1b[38;5;217m","\x1b[38;5;216m","\x1b[38;5;224m","\x1b[38;5;230m","\x1b[38;5;230m"];var z,Y,G,Z,V;(t=>{t[t.NONE=0]="NONE",t[t.BASIC=1]="BASIC",t[t.ADVANCED=2]="ADVANCED",t[t.HIGH=3]="HIGH"})(z||(z={})),(t=>{t[t.NONE=0]="NONE",t[t.LOW=1]="LOW",t[t.MEDIUM=2]="MEDIUM",t[t.HIGH=3]="HIGH"})(Y||(Y={})),(t=>{t[t.FREE=0]="FREE",t[t.LOW=1]="LOW",t[t.MEDIUM=2]="MEDIUM",t[t.HIGH=3]="HIGH"})(G||(G={}));class Q extends v{get log(){return this._log||(this._log=o.for(this)),this._log}constructor(t){super(t)}logFor(t){const{sessionId:e,requestId:r,authInfo:s}=t||{};let n="string"==typeof e&&e.length>0?this.log.for(e):this.log;return s&&s.clientId&&(n=n.for(s.clientId)),r&&(n=n.for(r.toString())),n}setDescription(t){return this.description=t,this}getDescription(){return this.description}setName(t){return this.name=t,this}getName(){return this.name}setTitle(t){return this.title=t,this}}y([b(),g("design:type",String)],Q.prototype,"description",void 0),y([b(),g("design:type",String)],Q.prototype,"name",void 0),y([b(),g("design:type",String)],Q.prototype,"title",void 0);class X extends Q{constructor(t){super(t),this.reasoning=z.NONE,this.effort=Y.NONE,this.cost=G.FREE}setReasoning(t){return this.reasoning=t,this}setEffort(t){return this.effort=t,this}setCost(t){return this.cost=t,this}}function tt(t){if(!t)return;let e=t,r=e&&e._def;for(;r&&"ZodObject"!==r.typeName;){if("ZodEffects"===r.typeName&&r.schema)e=r.schema;else if("ZodOptional"===r.typeName&&r.innerType)e=r.innerType;else if("ZodDefault"===r.typeName&&r.innerType)e=r.innerType;else if("ZodNullable"===r.typeName&&r.innerType)e=r.innerType;else{if(!r.schema)return;e=r.schema}r=e&&e._def}return r&&"ZodObject"===r.typeName?r:void 0}function et(t,e="schema"){if(tt(t))return t;if(t&&"object"==typeof t){const e=t.def&&"object"==typeof t.def?t.def:void 0,r=e&&(e.shape||"object"===e.type)&&e.shape||("object"===t.type?t.shape:void 0)||(e&&"object"===e.type?{}:void 0);if(e||"object"===t.type||r){const t={};if(r&&"object"==typeof r)for(const[e,s]of Object.entries(r))t[e]=st(s)?s:j.any();return j.object(t)}}throw Error(`Registration error: provided a non-canonical ${e}. Export a ZodObject (z.object(...)).`)}function rt(t){if(!t)return;if(t&&"object"==typeof t&&!t._def)return t.def&&"object"==typeof t.def&&t.def.shape?t.def.shape:t;const e=tt(t);return e?"function"==typeof e.shape?e.shape():e.shape||void 0:void 0}function st(t){return!(!t||"object"!=typeof t||!t._def)}y([b(),g("design:type",Number)],X.prototype,"reasoning",void 0),y([b(),g("design:type",Number)],X.prototype,"effort",void 0),y([b(),g("design:type",Number)],X.prototype,"cost",void 0),(t=>{t.ASSETS="assets"})(Z||(Z={})),(t=>{t.PROMPT="prompts",t.DOCUMENTATION="documentation",t.CODE="code"})(V||(V={}));const nt=Buffer.from("DCAF1","ascii");function it(t){let e=f.resolve(t);for(;;){if(r.existsSync(f.join(e,"package.json")))return e;const t=f.dirname(e);if(t===e)break;e=t}}const ot=process.argv?.[1]?it(f.dirname(f.resolve(process.argv[1]))):void 0,at=(()=>{const t=Error().stack;if(!t)return;const e=t.split(/\r?\n/).slice(1);for(const t of e){const e=t.match(/\(?([^()]+?):\d+:\d+\)?/);if(!e)continue;let r=e[1];if(r.startsWith("file://"))try{r=J(r)}catch{continue}if(!r.includes("node:internal"))return f.dirname(r)}})(),ct=at?it(at):void 0,pt=ot??ct??process.cwd();function lt(...t){return f.join(pt,...t)}function ut(t){let r=t;for(;;){const t=h.join(r,"lib","assets");if(e.existsSync(t))return t;const s=h.join(r,"src","assets");if(e.existsSync(s))return s;const n=h.join(r,"assets");if(e.existsSync(n))return n;const i=h.dirname(r);if(i===r)break;r=i}}function dt(){const t=process.env.DECAF_ASSET_DIR||process.env.MCP_ASSET_DIR||process.env.ASSET_DIR||"";if(t&&e.existsSync(t))return t;const r=ut(__dirname);if(r)return r;const s=process.argv?.[1];if(s){const t=ut(h.dirname(s));if(t)return t}const n=[pt,process.env.INIT_CWD].filter(Boolean);for(const t of n){const e=ut(t);if(e)return e}return lt("assets")}let mt=class extends a{constructor(t){super(),this.basePath=t||dt()}listAssets(...t){const r=h.join(this.basePath,...t);return e.readdirSync(r)}listPrompts(){return this.listAssets(V.PROMPT)}getAsset(t,r="md",...s){const n=h.join(this.basePath,...s),i=(t,r=!1)=>{try{return r?(t=>{if(t.length<nt.length+16+12+16)throw Error("Invalid prompt payload (too short)");if(!t.subarray(0,nt.length).equals(nt))throw Error("Invalid prompt payload (bad magic)");const e=process.env.ENCRYPTION_KEY||"";if(!e)throw Error("Missing encryption key. Set ENCRYPTION_KEY to load obfuscated assets.");let r=nt.length;const s=t.subarray(r,r+16);r+=16;const n=t.subarray(r,r+12);r+=12;const i=t.subarray(r,r+16);r+=16;const o=t.subarray(r),a=((t,e)=>C.scryptSync(t,e,32))(e,s),c=C.createDecipheriv("aes-256-gcm",a,n);c.setAuthTag(i);const p=Buffer.concat([c.update(o),c.final()]);return H.gunzipSync(p)})(e.readFileSync(t)).toString("utf-8"):e.readFileSync(t,"utf-8")}catch(t){if("ENOENT"===t.code)return null;throw t}},o=i(h.join(n,`${t}.${r}`),"enc"===r);if(null!==o)return o;const a=i(h.join(n,t+".enc"),!0);if(null!==a)return a;throw Error("Asset not found: "+h.join(n,`${t}.${r}`))}getAllAssets(t,...e){return this.listAssets(t,...e).reduce((r,s)=>{const n=h.extname(s),i=h.basename(s,n),o=n.replace(/^\./,"")||void 0;return r[i]=this.getAsset(i,o??void 0,t,...e),r},{})}toPromptDef(t){const e=t=>"number"==typeof t?t:"string"==typeof t?(t=>{switch(t){case"none":return z.NONE;case"basic":return z.BASIC;case"advanced":return z.ADVANCED;case"high":return z.HIGH;case"medium":return Y.MEDIUM;case"low":return G.LOW;case"free":return G.FREE;default:throw new T("Cannon convert unknown level "+t)}})(t.toLowerCase()):z.NONE;return t.effort=e(t.effort),t.reasoning=e(t.reasoning),t.cost=e(t.cost),t}getPrompt(t,...e){const r=this.getAsset(c(t),"json",V.PROMPT,...e);let s;try{s=JSON.parse(r)}catch(r){throw new N(`Failed to parse prompt ${t} in categories ${e}: ${r}`)}return this.toPromptDef(s)}getAllPrompts(...t){const e=this.getAllAssets(V.PROMPT,...t);return Object.entries(e).reduce((e,[r,s])=>{try{e[r]=JSON.parse(s)}catch(e){throw new N(`Failed to parse prompt ${r} in categories ${t}: ${e}`)}return e},e)}};mt=y([I(),g("design:paramtypes",[String])],mt);class ht extends X{constructor(t){super(t)}setCb(t){return this.cb=t,this}setArgsSchema(t){return this.argsSchema=t,this}static get builder(){return new ht}static patchPrompt(t,e,r,s){const n=(e=Array.isArray(e)?e:Object.keys(e)).filter(t=>!Object.prototype.hasOwnProperty.call(r,t));if(n.length)throw new O("Missing replacements for placeholders: "+n.join(", "));s&&(s.verbose("Patching prompt with placeholders: "+JSON.stringify(e)),s.debug("Values: "+JSON.stringify(r)));const i=e.reduce((t,e)=>(t[e]=r[e],t),{});return p(t,i)}patchPrompt(t,e,r,s){return ht.patchPrompt(t,e,r,s||this.log.for(this.patchPrompt))}build(t,e){const r=this.log.for(this.build),s=this.hasErrors();if(s)throw new O(s.toString());try{this.argsSchema&&et(this.argsSchema,"argsSchema");const r=rt(this.argsSchema);return t.registerPrompt(this.name,{title:this.title,description:this.description,argsSchema:r},async(t,r)=>{const s=this.logFor(r);t=Object.assign({},e,t||{}),s.verbose(`Executing prompt ${this.name} with args: ${JSON.stringify(t)}`),t._meta=Object.assign(t._meta||{},{usage:{reasoning:this.reasoning,effort:this.effort,cost:this.cost}});const n=await Promise.resolve(this.cb(t,r));return s.verbose(`Prompt ${this.name} executed successfully.`),s.debug("Prompt execution meta: "+JSON.stringify(n._meta)),n})}catch(t){throw r.error("Failed to register prompt "+(this.name||this.constructor.name),t),t}}}y([k(mt),g("design:type",mt)],ht.prototype,"assets",void 0),y([b(),g("design:type",Object)],ht.prototype,"cb",void 0),y([b(),g("design:type",x)],ht.prototype,"argsSchema",void 0),y([A(),g("design:type",Object)],ht.prototype,"placeholders",void 0);class ft extends ht{setCategory(t){return this.promptCategory=t,this}addPrefix(t){return this.prefixes=this.prefixes||[],this.prefixes.push(t),this}addSuffix(t){return this.suffixes=this.suffixes||[],this.suffixes.push(t),this}constructor(t){super(t)}build(t){const e=this.assets.getPrompt(this.name,this.promptCategory);v.fromObject(this,e);const r=new Set((E.properties(ft)||[]).filter(t=>!["assets","promptCategory","prefixes","suffixes"].includes(t)));["cb","argsSchema"].forEach(t=>r.add(t));const s=this.hasErrors(...Array.from(r));if(s)throw new O(s.toString());const n=(this.prefixes||[]).map(t=>this.assets.getPrompt(t,this.promptCategory)),i=(this.suffixes||[]).map(t=>this.assets.getPrompt(t,this.promptCategory)),o=[...new Set([...e.placeholders,...n.map(t=>t.placeholders||[]),...i.map(t=>t.placeholders||[])].flat())].reduce((t,e)=>(t[e]=j.string().describe("The description for "+e),t),{});return this.setArgsSchema(j.object(o)),this.setCb((t,e)=>{const r=this.logFor(e).for(ft).for(this.promptCategory).for(this.name);function s(t=[]){return Array.isArray(t)?t:Object.keys(t)}const n=(this.prefixes||[]).map(t=>this.assets.getPrompt(t,this.promptCategory)),i=(this.suffixes||[]).map(t=>this.assets.getPrompt(t,this.promptCategory)),o=this.assets.getPrompt(this.name,this.promptCategory),a=[...new Set([...n.map(t=>s(t.placeholders)).flat(),...i.map(t=>s(t.placeholders)).flat(),...s(o.placeholders).flat()])];return{messages:[{role:"user",content:{type:"text",text:this.patchPrompt([...n.map(t=>t.prompt),o.prompt,...i.map(t=>t.prompt)].join("\n\n"),a,t,r)}}],_meta:{}}}),super.build(t)}setReasoning(t){throw new T("Named prompt builders don't require callback")}setEffort(t){throw new T("Named prompt builders don't require callback")}setCost(t){throw new T("Named prompt builders don't require callback")}setDescription(t){throw new T("Named prompt builders don't require callback")}setTitle(t){throw new T("Named prompt builders don't require callback")}static get builder(){return new ft}}y([b(),g("design:type",String)],ft.prototype,"promptCategory",void 0),y([w(String),S(1),g("design:type",Array)],ft.prototype,"prefixes",void 0),y([S(1),w(String),g("design:type",Array)],ft.prototype,"suffixes",void 0);const yt=ht.builder.setName("example.prompt").setTitle("Example prompt").setDescription("Example prompt for testing").setArgsSchema(j.object({message:j.string().optional()})).setCb(async t=>{const e=t.message??"default";return{messages:[{role:"assistant",content:{type:"text",text:e}}],content:[],structuredContent:{message:e},result:{message:e}}}),gt=ht.builder.setName("interactive.jsdoc").setTitle("Interactive JSDoc prompt").setDescription("Interactive prompt for jogging JSDoc helpers").setArgsSchema(j.object({gist:j.string().optional()})).setCb(async t=>{const e=t.gist??"interactive jsdoc response";return{messages:[{role:"assistant",content:{type:"text",text:e}}],content:[],structuredContent:{message:e},result:{message:e}}}),bt=Object.assign(gt,{name:gt.getName()});var vt;function wt(t,e=[],r=[]){const s=ft.builder.setCategory(vt.DOCS).setName(t);return["prefix",...e].forEach(t=>s.addPrefix(t)),["suffix",...r].forEach(t=>s.addSuffix(t)),s}(t=>{t.DOCS="documentation",t.CODE="code"})(vt||(vt={}));const St=[wt("class"),wt("constant"),wt("decorator"),wt("function"),wt("module"),wt("file"),wt("repo",[],["iterate"])],jt=j.object({className:j.string().describe("the class name to turn into a builder")}),xt=[yt,bt,...St,ht.builder.setName("ts.code.dp.builder").setTitle("Typescript builder design patter prompt").setDescription("for a class, with a defined set of properties, scafold a builder design pattern").setArgsSchema(jt).setReasoning(z.BASIC).setCb((t,e)=>(t.className=l(t.className),{messages:[{role:"user",content:{type:"text",text:`You're a senior TypeScript developer writing typescript code.You're a senior TypeScript developer writing typescript code.\nTransform the selected class into a builder design pattern implementation in Typescript.\nuse @decaf-ts validation decorators to enforce the validation of your builder.\n\n- must extend the Model Class from @decaf-ts/decorator-validation;\n- each property must be marked as protected;\n- each property must have a setter method that returns 'this' for chaining;\n- the build() method must validate the properties using hasErrors() method from Model class;\n- if validation fails, throw an error with the validation errors;\n- if validation passes, return an instance of the original class with the set properties;\n- optionally (but do so by default) add the static builder and from methods from the example;\n- if the clasee already follows the pattern but has properties without decoration or without setters, simple add them;\n\nexample:\n\noriginal class:\n\`\`\`typescript\nexport class ${t.className} {\n description!: string;\n name!: string = "default name";\n title!: string;\n age?: string;\n dateOfBirth!: Date;\n}}\n\`\`\` \n\nresulting builder pattern implementation:\n\`\`\`typescript\nexport class ${t.className}Builder extends Model {\n\n @minlength(10\n @required()\n protected description!: string;\n \n @required()\n protected name!: string = "default value;\n \n @required()\n protected title!: string;\n \n @min(18)\n protected age?: string;\n \n @date()\n protected dateOfBirth!: Date;\n\n protected constructor(arg?: ModelArg<${t.className}Builder>>) {\n super(arg);\n Model.fromModel(this, arg);\n }\n\n setDescription(value: string) {\n this.description = value;\n return this;\n }\n\n setName(value: string) {\n this.name = value;\n return this;\n }\n\n setTitle(value: string) {\n this.title = value;\n return this;\n }\n setAge(value: number) {\n this.age = value;\n return this;\n }\n setDate(value: Date) {\n this.age = value;\n return this;\n }\n \n build(...args: any[]): ${t.className}Builder | Promise<${t.className}Builder> {\n const errs = this.hasErrors();\n if (errs) throw new Error(errs.toString());\n \n return // code that builds OBJ here\n }\n \n static get builder(): ${t.className}Builder {\n return new ${t.className}Builder(); // static method to get a new builder instance\n }\n \n static from<K extends keyof ${t.className}Builder>(obj: K, ${t.className}Builder[K]): ${t.className}Builder {\n return new ${t.className}Builder(); // static method to create a builder from an object\n }\n}\n\`\`\` \n\n`}}],_meta:{}}))];class It extends X{setAnnotations(t){return this.annotations=Object.assign(this.annotations,t),this}setCb(t){return this.cb=t,this}setInputSchema(t){return this.inputSchema=t,this}setOutputSchema(t){return this.outputSchema=t,this}constructor(t){super(t),this.annotations={readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1}}static get builder(){return new It}build(t){const e=this.hasErrors();if(e)throw Error(e.toString());try{this.inputSchema&&et(this.inputSchema,"inputSchema"),this.outputSchema&&et(this.outputSchema,"outputSchema");const e=rt(this.inputSchema),r=rt(this.outputSchema);return t.registerTool(this.name,{title:this.title,description:this.description,inputSchema:e,outputSchema:r,annotations:this.annotations,_meta:{usage:{reasoning:this.reasoning,effort:this.effort,cost:this.cost}}},async(t,e)=>{const r=this.logFor(e);r.verbose(`Executing tool ${this.name} with args: ${JSON.stringify(t)}`),e._meta=Object.assign(e._meta||{},{usage:{reasoning:this.reasoning,effort:this.effort,cost:this.cost}});const s=await Promise.resolve(this.cb(t,e));return r.verbose(`Tool ${this.name} executed successfully.`),r.debug("Tool execution meta: "+JSON.stringify(s._meta)),s})}catch(t){const e=t?.message||t+"";if("string"==typeof e&&e.includes("already registered"))return o.for(this).warn(`Tool ${this.name} already registered - skipping duplicate registration`),{name:this.name};throw o.for(this).error("Error building tool",t),t}}}y([b(),g("design:type",Object)],It.prototype,"annotations",void 0),y([b(),g("design:type",Object)],It.prototype,"cb",void 0),y([b(),g("design:type",Function)],It.prototype,"inputSchema",void 0);const kt=It.builder.setName("example.tool").setTitle("Example tool").setDescription("A smoke tool used for quick testing").setInputSchema(j.object({})).setCb(async()=>({content:[{type:"text",text:"example tool ok"}],result:{status:"ok"}}));Object.assign(kt,{name:kt.getName()});const At=It.builder.setName("file.summarizer").setTitle("File summarizer").setDescription("Summaries files for quick previews").setInputSchema(j.object({filePath:j.string().optional()})).setCb(async()=>({content:[{type:"text",text:"file summary stub"}],result:{summary:"file summary stub"}}));Object.assign(At,{name:At.getName()});const Et="##VERSION##";E.registerLibrary("##PACKAGE##",Et);const Tt={mcpId:"decaf",name:"decaf-ts mcp server",title:"Decaf-TS MCP Server",description:"Provides precise coding assistance for the decaf-ts framework",version:Et,websiteUrl:"https://decaf-ts.github.io",repositoryUrl:"https://github.com/decaf-ts/mcp-server",license:"AGPL-3.0",workingDir:pt,assetDir:dt(),contacts:[{name:"Decaf-TS",url:"https://decaf-ts.github.io"}],tags:"server,official,decaf-ts",metadata:{},icons:[{src:"workdocs/assets/favicon.svg",mimeType:"image/svg+xml",sizes:"any"}],jira:{host:process.env.JIRA__HOST||"decaf-ts.atlassian.net",email:process.env.JIRA__EMAIL||"",apiKey:process.env.JIRA__API_KEY||process.env.JIRA__APIKEY||"",projectKey:process.env.JIRA__PROJECT_KEY||void 0,issueType:process.env.JIRA__ISSUE_TYPE||void 0,parentIssue:process.env.JIRA__PARENT_ISSUE||void 0},level:u.error},Nt=d.accumulate(Tt);function Ot(){const{host:t,email:e,apiKey:r,projectKey:s,issueType:n}=Nt.jira;return{host:t?.trim(),email:e?.trim(),apiKey:r?.trim(),projectKey:s?.trim(),issueType:n?.trim(),parentIssue:Nt.jira.parentIssue?.trim()}}function Ct(){const t=Ot();return[{name:"JIRA__HOST",required:!0,description:"Atlassian host (e.g. decaf-ts.atlassian.net) where your Jira instance is hosted.",value:t.host},{name:"JIRA__EMAIL",required:!0,description:"Email address of the Jira account that has API access.",value:t.email},{name:"JIRA__API_KEY",required:!0,description:"API token created in your Atlassian profile (a.k.a. APIKEY alias) for authenticating requests.",sensitive:!0,value:t.apiKey},{name:"JIRA__PROJECT_KEY",required:!1,description:"Default Jira project key (e.g. DECAF) used when an issue creation request omits a project.",value:t.projectKey},{name:"JIRA__ISSUE_TYPE",required:!1,description:"Default Jira issue type (e.g. Task, Bug) used when creating issues without an explicit type.",value:t.issueType},{name:"JIRA__PARENT_ISSUE",required:!1,description:"Default parent issue key (e.g. DECAF-123) applied when a child issue is created without an explicit parent.",value:t.parentIssue}]}function Ht(t){const e=t.value?((t,e)=>{if(t)return e?"<configured>":t})(t.value,t.sensitive):"not set",r=t.required?"(required)":"(optional)";return`\u2022 ${t.name} ${r}: ${t.description} Current state: ${e}.`}o.setConfig(Nt);class Jt extends Error{constructor(t){const e=Ct(),r=(t=>{const e=Ct();return`${t.length?`Missing Jira credentials: ${t.map(t=>t.name).join(", ")}.`:"Jira credentials are configured."}\n\nThis setup uses the following environment variables:\n${e.map(Ht).join("\n")}`})(t);super(r),this.name="MissingJiraEnvironmentError",this.descriptors=e,this.missing=t,"function"==typeof Error.captureStackTrace&&Error.captureStackTrace(this,Jt)}}function _t(t){if(!t)return{code:"jira_error",message:"Unknown Jira error",details:{raw:t}};const e=t?.status??t?.statusCode??t?.response?.status??t?.response?.statusCode,r="number"==typeof e?e:Number(e)||void 0,s=t?.response?.data??t?.data??t?.response?.body??t?.body,n=[];"string"==typeof t?.message&&n.push(t.message),((t,e)=>{t&&(Array.isArray(t.errorMessages)&&t.errorMessages.forEach(t=>"string"==typeof t&&e.push(t)),"string"==typeof t.errorMessage&&e.push(t.errorMessage),t.errorCollection&&Array.isArray(t.errorCollection.errors)&&t.errorCollection.errors.forEach(t=>{"string"==typeof t?e.push(t):t&&"string"==typeof t.message&&e.push(t.message)}),t?.errors&&"object"==typeof t.errors&&Object.values(t.errors).forEach(t=>{"string"==typeof t?e.push(t):"string"==typeof t?.message&&e.push(t.message)}))})(s,n);const i=r?`Jira API error (${r})`:"Jira API error",o=n.length>0?n.join(" | "):i;return{code:r?"jira_"+r:t?.code??"jira_error",message:o,details:{httpStatus:r,body:s,raw:t}}}const Dt=j.object({issueId:j.string().min(1),deleteSubtasks:j.boolean().optional().default(!0)}),Pt={name:"jira.issue-delete",inputSchema:Dt,runTool:async(t,e)=>{try{const r=Dt.parse(e),s=t.issues??t.issue??t,n=s?.delete??s?.deleteIssue;if("function"!=typeof n)throw Error("jira client delete endpoint is not available");return await n.call(s,{issueId:r.issueId,deleteSubtasks:r.deleteSubtasks}),{success:!0,message:`Issue ${e.issueId} deleted successfully`}}catch(t){throw _t(t)}}},Rt=j.object({issueId:j.string().min(1),expand:j.string().optional(),fields:j.array(j.string()).optional(),properties:j.array(j.string()).optional()}),$t={name:"jira.issue-read",inputSchema:Rt,runTool:async(t,e)=>{try{const r=Rt.parse(e),s={issueIdOrKey:r.issueId};r.expand&&(s.expand=r.expand),r.fields&&(s.fields=r.fields),r.properties&&(s.properties=r.properties);const n=await t.issues.get(s);return n?.data??n}catch(t){throw _t(t)}}};function Mt(t,e,r){const s=((t.url??"")+"").match(/^(attachment|jira-attachment):(.+)$/i);if(!s)return null;const n=s[2],i=r.resolveAttachment?.(n);return i?{type:"block",node:{type:"mediaSingle",attrs:{layout:"center"},content:[{type:"media",attrs:{type:"file",id:i.id,collection:i.collection??"attachments"}}]}}:null}function Ft(t,e){if(!t)return[];if(!e.enableAtMentions&&!e.enableEmojiShortcodes)return[{type:"text",text:t}];let r=0;const s=[],n=/(^|[^A-Za-z0-9_])@([A-Za-z0-9._-]{1,64})/g,i=/:([a-z0-9_+-]{1,64}):/gi;for(;r<t.length;){const o=Bt(e.enableAtMentions?qt(n,t,r):null,e.enableEmojiShortcodes?qt(i,t,r):null);if(!o){s.push({type:"text",text:t.slice(r)});break}if(o.index>r&&s.push({type:"text",text:t.slice(r,o.index)}),"mention"===o.kind){const{full:t,groups:n}=o,i=n[0]??"",a=n[1]??"";i&&s.push({type:"text",text:i});const c=e.resolveMention?.(a);c?s.push({type:"mention",attrs:{id:c.id,text:c.text}}):s.push({type:"text",text:"@"+a}),r=o.index+t.length;continue}if("emoji"===o.kind){const{full:t,groups:n}=o,i=`:${n[0]}:`,a=e.resolveEmoji?.(i);s.push({type:"emoji",attrs:a?{shortName:a.shortName,text:a.text}:{shortName:i}}),r=o.index+t.length;continue}}return(t=>{const e=[];for(const r of t){const t=e[e.length-1];"text"!==r.type||"text"!==t?.type||t.marks||r.marks?e.push(r):t.text=(t.text??"")+(r.text??"")}return e})(s)}function qt(t,e,r){t.lastIndex=r;const s=t.exec(e);if(!s)return null;const n=t.source.includes("@")?"mention":"emoji";return{index:s.index,full:s[0],groups:s.slice(1),kind:n}}function Bt(t,e){return t?e&&t.index>e.index?e:t:e}function Wt(t){const e=(t.children??[])[0];return"text"===e?.type?(e.value??"")+"":"paragraph"===e?.type?((e.children??[]).map(t=>"text"===t.type?(t.value??"")+"":"").join("")||"")+"":""}function Lt(t){const e=((t??"")+"").toLowerCase().trim();return e?"info"===e||"note"===e||"success"===e||"warning"===e||"error"===e?e:"danger"===e?"error":null:null}function Ut(t){const e=((t??"")+"").toLowerCase().trim();return!e||"neutral"!==e&&"green"!==e&&"yellow"!==e&&"red"!==e&&"blue"!==e&&"purple"!==e?null:e}function Kt(t,e){const r=[];for(const s of t??[])if(s?.type)if("text"!==s.type)if("strong"!==s.type)if("emphasis"!==s.type)if("delete"!==s.type)if("inlineCode"!==s.type)if("break"!==s.type){if("link"===s.type){const t=(s.url??"")+"",n=Yt(s.children??[],t),i=Mt(s,0,e);if(i){"inline"===i.type?r.push(i.node):r.push({type:"text",text:n,marks:[{type:"link",attrs:{href:t}}]});continue}if(e.enableSmartCards&&Gt(n,t)){r.push({type:"inlineCard",attrs:{url:t}});continue}r.push({type:"text",text:n,marks:[{type:"link",attrs:{href:t}}]});continue}if("textDirective"===s.type&&"status"===s.name){const t=Wt(s)||"Status",e=Ut(s.attributes?.color)??"neutral";r.push({type:"status",attrs:{text:t,color:e}});continue}if("textDirective"===s.type&&"emoji"===s.name){const t=Zt(s);r.push(Vt(t,e));continue}}else r.push({type:"hardBreak"});else r.push({type:"text",text:(s.value??"")+"",marks:[{type:"code"}]});else r.push(...zt(Kt(s.children??[],e),{type:"strike"}));else r.push(...zt(Kt(s.children??[],e),{type:"em"}));else r.push(...zt(Kt(s.children??[],e),{type:"strong"}));else r.push(...Ft((s.value??"")+"",e));return r.filter(t=>!("text"===t.type&&""===(t.text??"")))}function zt(t,e){return t.map(t=>{if("text"!==t.type)return t;const r=t.marks?[...t.marks,e]:[e];return{...t,marks:r}})}function Yt(t,e){const r=[];for(const e of t??[])"text"===e.type||"inlineCode"===e.type?r.push((e.value??"")+""):"emphasis"!==e.type&&"strong"!==e.type&&"delete"!==e.type||r.push(Yt(e.children??[],""));return r.join("")||e}function Gt(t,e){const r=(t??"").trim(),s=(e??"").trim();return r===s&&/^https?:\/\//i.test(s)}function Zt(t){return(t.children??[]).map(t=>"text"===t.type?(t.value??"")+"":"").join("").trim()||""}function Vt(t,e){const r=t.startsWith(":")?t:`:${t}:`,s=e.resolveEmoji?.(r);return s?{type:"emoji",attrs:{shortName:s.shortName,text:s.text}}:{type:"emoji",attrs:{shortName:r}}}function Qt(t){return t?"string"==typeof t?t:"text"===t.type||"inlineCode"===t.type?(t.value??"")+"":Array.isArray(t.children)?t.children.map(Qt).join(""):"":""}function Xt(t,e){if(!t?.type)return null;if((t=>"containerDirective"===t?.type&&"panel"===t?.name)(t))return((t,e)=>{const r=t.attributes??{},s=Lt(r.type)??"info",n="string"==typeof r.title?r.title:void 0,i=(t.children??[]).map(t=>Xt(t,e)).flat().filter(Boolean);return{type:"panel",attrs:{panelType:s,...n?{panelType:s,title:n}:{panelType:s}},content:i.length?i:[{type:"paragraph",content:[]}]}})(t,e);switch(t.type){case"heading":return{type:"heading",attrs:{level:ee(t.depth??1,1,6)},content:Kt(t.children??[],e)};case"paragraph":return(t=>{const e=t.children??[];if(1!==e.length)return null;const r=e[0];if("image"!==r?.type)return null;const s=(r.url??"")+"";return s?{type:"mediaSingle",attrs:{layout:"center"},content:[{type:"media",attrs:{type:"external",url:s}}]}:null})(t)||{type:"paragraph",content:Kt(t.children??[],e)};case"blockquote":return{type:"blockquote",content:(t.children??[]).map(t=>Xt(t,e)).flat().filter(Boolean)};case"list":return((t,e)=>e.enableTaskLists&&(t.children??[]).some(t=>"boolean"==typeof t.checked)?((t,e)=>{const r=[];let s=0;for(const n of t.children??[]){if("boolean"!=typeof n.checked)continue;s+=1;const t=(n.children??[]).map(t=>Xt(t,e)).flat().filter(Boolean);r.push({type:"taskItem",attrs:{localId:"task-"+s,state:n.checked?"DONE":"TODO"},content:t.length?t:[{type:"paragraph",content:[]}]})}return{type:"taskList",content:r}})(t,e):{type:t.ordered?"orderedList":"bulletList",content:(t.children??[]).map(t=>((t,e)=>{const r=(t.children??[]).map(t=>Xt(t,e)).flat().filter(Boolean);return{type:"listItem",content:r.length?r:[{type:"paragraph",content:[]}]}})(t,e))})(t,e);case"code":{const r=((t,e)=>{const r=(t??"").toString().trim().toLowerCase();return r?e.enableMermaid&&"mermaid"===r?"mermaid":(t=>{const e=t.trim().toLowerCase();return{js:"javascript",javascript:"javascript",jsx:"javascript",ts:"typescript",typescript:"typescript",tsx:"typescript",py:"python",python:"python",rb:"ruby",ruby:"ruby",sh:"bash",bash:"bash",zsh:"bash",shell:"bash",yml:"yaml",yaml:"yaml",json:"json",toml:"toml",xml:"xml",html:"html",css:"css",scss:"scss",sql:"sql",go:"go",rust:"rust",java:"java",c:"c",cpp:"cpp","c++":"cpp",cs:"csharp",csharp:"csharp",php:"php",kotlin:"kotlin",swift:"swift",md:"markdown",markdown:"markdown",graphql:"graphql",gql:"graphql",dockerfile:"docker",makefile:"make",ini:"ini"}[e]??e})(r):null})(t.lang,e);return{type:"codeBlock",attrs:{language:r},content:[{type:"text",text:(t.value??"")+""}]}}case"thematicBreak":return{type:"rule"};case"table":return((t,e)=>({type:"table",content:(t.children??[]).map((t,r)=>({type:"tableRow",content:(t.children??[]).map(t=>({type:0===r?"tableHeader":"tableCell",content:[{type:"paragraph",content:Kt(t.children??[],e)}]}))}))}))(t,e);case"leafDirective":return"status"===t.name?(t=>{const e=Ut((t.attributes??{}).color)??"neutral";return{type:"paragraph",content:[{type:"status",attrs:{text:Wt(t)||"Status",color:e}}]}})(t):"panel"===t.name?((t,e)=>{const r=t.attributes??{},s=Lt(r.type)??"info",n="string"==typeof r.title?r.title:void 0;return{type:"panel",attrs:{panelType:s,...n?{title:n}:{}},content:[{type:"paragraph",content:Kt([{type:"text",value:Wt(t)}],e)}]}})(t,e):te(t,e);default:return te(t,e)}}function te(t,e){if("drop"===e.unknownNodeStrategy)return null;const r=Qt(t);return r?{type:"paragraph",content:[{type:"text",text:r}]}:null}function ee(t,e,r){const s=Number.isFinite(t)?Math.trunc(t):e;return Math.max(e,Math.min(r,s))}const re={resolveMention:void 0,resolveAttachment:void 0,resolveEmoji:void 0,enableSmartCards:!0,enableMermaid:!0,enableEmojiShortcodes:!0,enableAtMentions:!0,enableTaskLists:!0,unknownNodeStrategy:"text"};function se(t,e={}){const r={...re,...e},s=t??"",n=_().use(R).use(P).use(D),i=n.parse(s),o=n.runSync(i);return ne(o),((t,e)=>{const r=[];for(const s of t.children??[]){const t=Xt(s,e);t&&(Array.isArray(t)?r.push(...t):r.push(t))}return((t,e)=>{if(!e.enableSmartCards)return t;const r=t.content.map(t=>(t=>{if("paragraph"!==t.type)return t;const e=t.content??[];if(1!==e.length)return t;const r=e[0];if("inlineCard"!==r?.type)return t;const s=r.attrs?.url;return s?[{type:"blockCard",attrs:{url:s}}]:t})(t)).flat();return{...t,content:r}})({version:1,type:"doc",content:r},e)})(o,r)}function ne(t){if(!t||!Array.isArray(t.children))return;const e=[];for(const r of t.children)"definition"!==r?.type&&("html"!==r?.type?(ne(r),e.push(r)):e.push({type:"text",value:(r.value??"")+""}));t.children=e}const ie=j.object({issueId:j.string().min(1),transitionId:j.union([j.string(),j.number()]),fields:j.record(j.any()).optional(),update:j.record(j.array(j.object({set:j.any().optional(),add:j.any().optional(),remove:j.any().optional()}))).optional(),comment:j.string().optional()}),oe={name:"jira.issue-transition",inputSchema:ie,runTool:async(t,e)=>{try{const r=ie.parse(e),s={id:r.transitionId};r.fields&&(s.fields=r.fields),r.update&&(s.update=r.update),r.comment&&(s.comment={body:se(r.comment)});const n=await t.issues.transition({issueId:r.issueId,transition:s});return n?.data??n}catch(t){throw _t(t)}}},ae=j.object({issueId:j.string().min(1),fields:j.record(j.any()).optional(),update:j.record(j.array(j.object({set:j.any().optional(),add:j.any().optional(),remove:j.any().optional(),edit:j.any().optional()}))).optional(),properties:j.array(j.any()).optional(),notifyUsers:j.boolean().optional().default(!0),issueTemplateId:j.string().optional(),overrideScreenSecurity:j.boolean().optional().default(!1),overrideEditableFlag:j.boolean().optional().default(!1)}),ce={name:"jira.issue-update",inputSchema:ae,runTool:async(t,e)=>{try{const r=ae.parse(e),s={issueId:r.issueId};r.fields&&(s.fields=r.fields),r.update&&(s.update=r.update),r.properties&&(s.properties=r.properties),void 0!==r.notifyUsers&&(s.notifyUsers=r.notifyUsers),r.issueTemplateId&&(s.issueTemplateId=r.issueTemplateId),void 0!==r.overrideScreenSecurity&&(s.overrideScreenSecurity=r.overrideScreenSecurity),void 0!==r.overrideEditableFlag&&(s.overrideEditableFlag=r.overrideEditableFlag);const n=await t.issues.update(s);return n?.data??n}catch(t){throw _t(t)}}},pe=j.object({issueId:j.string().min(1),assignee:j.union([j.string(),j.object({accountId:j.string().min(1)}),j.object({accountType:j.string().min(1)})])}),le={name:"jira.assign-issue",inputSchema:pe,runTool:async(t,e)=>{try{const r=pe.parse(e);let s;s="string"==typeof r.assignee?{accountId:r.assignee}:r.assignee;const n=await t.issues.assign({issueId:r.issueId,assignee:s});return n?.data??n}catch(t){throw _t(t)}}},ue=j.object({issueId:j.string().min(1)}),de={name:"jira.unassign-issue",inputSchema:ue,runTool:async(t,e)=>{try{const r=ue.parse(e),s=await t.issues.assign({issueId:r.issueId,assignee:{accountId:"-1"}});return s?.data??s}catch(t){throw _t(t)}}},me=j.object({issueId:j.string().min(1),body:j.string().min(1),visibility:j.object({type:j.enum(["role","group"]),value:j.string().min(1)}).optional()}),he={name:"jira.comment-add",inputSchema:me,runTool:async(t,e)=>{try{const r=me.parse(e),s={body:se(r.body)};r.visibility&&(s.visibility=r.visibility);const n=await t.issues.addComment({issueId:r.issueId,comment:s});return n?.data??n}catch(t){throw _t(t)}}},fe=j.object({issueId:j.string().min(1),start:j.number().optional().default(0),maxResults:j.number().optional().default(50),orderBy:j.string().optional(),expand:j.string().optional()}),ye={name:"jira.comment-list",inputSchema:fe,runTool:async(t,e)=>{try{const r=fe.parse(e),s=await t.issues.getComments({issueId:r.issueId,start:r.start,maxResults:r.maxResults,orderBy:r.orderBy,expand:r.expand});return s?.data??s}catch(t){throw _t(t)}}},ge=j.object({link:j.object({relationship:j.enum(["Blocks","Relates to","Duplicates","Is blocked by","Is related to","Is duplicated by","Causes","Is caused by","Clone","Required","Work on","Split","Roll up"]),inwardIssue:j.object({id:j.string().optional(),key:j.string().optional()}),outwardIssue:j.object({id:j.string().optional(),key:j.string().optional()}),comment:j.object({body:j.string().optional(),visibility:j.object({type:j.enum(["role","group"]),value:j.string().min(1)}).optional()}).optional()})}),be={name:"jira.link-create",inputSchema:ge,runTool:async(t,e)=>{try{const r=ge.parse(e).link,s={relationship:r.relationship,inwardIssue:r.inwardIssue.id||r.inwardIssue.key,outwardIssue:r.outwardIssue.id||r.outwardIssue.key};r.comment&&(r.comment.body&&(s.comment=se(r.comment.body)),r.comment.visibility&&(s.visibility=r.comment.visibility));const n=await t.issues.link(s);return n?.data??n}catch(t){throw _t(t)}}},ve=j.object({issueId:j.string().min(1),file:j.string().min(1),mimeType:j.string().optional(),comment:j.string().optional()}),we={name:"jira.attach",inputSchema:ve,runTool:async(t,e)=>{try{const r=ve.parse(e),n=f.resolve(r.file),i=await s.readFile(n),o=f.basename(n),a=await t.issues.addAttachment({issueId:r.issueId,file:{name:o,content:i,mimeType:r.mimeType??"application/octet-stream"},comment:r.comment});return a?.data??a}catch(t){if(t&&t.code&&"string"==typeof t.code&&["ENOENT","EACCES"].includes(t.code))throw Error("Attachment file error: "+t.message);throw _t(t)}}},Se=j.object({issueId:j.string().min(1)}),je={name:"jira.attachment-list",inputSchema:Se,runTool:async(t,e)=>{try{const r=Se.parse(e),s=await t.issues.getAttachments({issueId:r.issueId});return s?.data??s}catch(t){throw _t(t)}}},xe=j.object({issueId:j.string().min(1),attachmentId:j.string().min(1)}),Ie={name:"jira.attachment-delete",inputSchema:xe,runTool:async(t,e)=>{try{const r=xe.parse(e);return await t.issues.deleteAttachment({issueId:r.issueId,attachmentId:r.attachmentId}),{success:!0,message:`Attachment ${e.attachmentId} deleted successfully`}}catch(t){throw _t(t)}}},ke=j.object({issueId:j.string().min(1),timeSpent:j.string().min(1),comment:j.string().optional(),author:j.object({accountId:j.string().min(1)}).optional(),startingOn:j.string().optional(),artifact:j.string().optional()}),Ae={name:"jira.worklog-add",inputSchema:ke,runTool:async(t,e)=>{try{const r=ke.parse(e),s={timeSpent:r.timeSpent};r.comment&&(s.comment=r.comment),r.author&&(s.author=r.author),r.startingOn&&(s.started=r.startingOn),r.artifact&&(s.artifact=r.artifact);const n=await t.issues.addWorklog({issueId:r.issueId,...s});return n?.data??n}catch(t){throw _t(t)}}},Ee={[$t.name]:{title:"Jira Issue Read",description:"Read a Jira issue with expandable fields and properties",annotations:{readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1}},[ce.name]:{title:"Jira Issue Update",description:"Update a Jira issue using fields, update ops, and property toggles",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}},[Pt.name]:{title:"Jira Issue Delete",description:"Delete a Jira issue and optionally remove its subtasks",annotations:{readOnlyHint:!1,destructiveHint:!0,idempotentHint:!1,openWorldHint:!0}},[oe.name]:{title:"Jira Issue Transition",description:"Transition a Jira issue while optionally adding a comment",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}},[le.name]:{title:"Jira Issue Assign",description:"Assign a Jira issue to a user or account",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}},[de.name]:{title:"Jira Issue Unassign",description:"Unassign the current owner from a Jira issue",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}},[he.name]:{title:"Jira Comment Add",description:"Add a comment to a Jira issue with optional visibility",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}},[ye.name]:{title:"Jira Comment List",description:"List comments on a Jira issue with pagination support",annotations:{readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1}},[be.name]:{title:"Jira Link Create",description:"Create an issue link relationship with optional comment",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}},[we.name]:{title:"Jira Attachment Add",description:"Attach a local file to a Jira issue",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}},[je.name]:{title:"Jira Attachment List",description:"List attachments on a Jira issue",annotations:{readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1}},[Ie.name]:{title:"Jira Attachment Delete",description:"Delete an attachment from a Jira issue",annotations:{readOnlyHint:!1,destructiveHint:!0,idempotentHint:!1,openWorldHint:!0}},[Ae.name]:{title:"Jira Worklog Add",description:"Log time spent on a Jira issue",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}}};async function Te(t){const e=o.for(Te);let r,s=null;try{r=(()=>{let t;try{const e=require("jira.js");t=e?.Version3Client||e.default?.Version3Client||e.default||e}catch(t){throw Error("Unable to require 'jira.js' \u2014 ensure it is installed as a dependency: "+t)}const{host:e,email:r,apiKey:s}=(()=>{const t=Ot(),e=Ct().filter(t=>t.required&&!t.value);if(e.length>0)throw new Jt(e);return{host:t.host,email:t.email,apiKey:t.apiKey}})();return new t({host:e,authentication:{basic:{email:r,apiToken:s}}})})()}catch(t){if(!(t instanceof Jt))return void e.warn("Skipping Jira tool registration; unable to create Jira client",{error:t});s=t,e.warn("Registering Jira tools without credentials; each tool will report configuration requirements.",{error:t})}const n=[$t,ce,Pt,oe,le,de,he,ye,be,we,je,Ie,Ae];for(const i of n){const n=Ee[i.name];if(n)try{await t.registerTool(i.name,{title:n.title,description:n.description,inputSchema:rt(i.inputSchema),annotations:n.annotations},async t=>{if(!r)throw s??Error("Jira client unavailable because credentials could not be loaded.");return i.runTool(r,t)}),e.info("Registered Jira tool "+i.name)}catch(t){e.error("Failed to register Jira tool "+i.name,{error:t})}}}async function Ne(t){await(async t=>{t.registerTool("decaf.server-info",{title:"Decaf MCP Server Info",description:"Return server metadata, version, and registered prompt names for diagnostics.",inputSchema:{},outputSchema:void 0,annotations:{readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1}},async()=>{const t=xt.map(t=>t.getName()).sort();return{content:[{type:"text",text:["Name: "+Nt.name,"Title: "+Nt.title,"Version: "+Nt.version,"Prompts: "+(t.join(", ")||"<none>")].join("\n")}]}})})(t);const e=o.for(Ne);try{await Te(t)}catch(t){e.error("Failed to register Jira tools",t)}}class Oe extends Q{setCb(t){return this.cb=t,this}setConfig(t){return this.config=t,this}setUriOtTemplate(t){return this.uriOrTemplate=t,this}constructor(t){super(t)}static get builder(){return new Oe}build(t){const e=this.hasErrors();if(e)throw Error(e.toString());try{const e="string"==typeof this.uriOrTemplate&&this.uriOrTemplate.includes("{")?new M(new $(this.uriOrTemplate),{list:void 0}):this.uriOrTemplate,r=Object.assign(this.config,{_meta:{}}),s=async(t,e)=>{const r=this.logFor(e);r.verbose(`Requesting resource ${this.name} from ${t.toString()}`);const s=await Promise.resolve(this.cb(t,e));return r.verbose(`Resource ${this.name} retrieved successfully.`),r.debug("Resource retrieval meta: "+JSON.stringify(s._meta)),s};return t.resource(this.name,e,r,s)}catch(t){throw o.for(this).error("Error registering resource "+this.name,t),t}}}y([b(),g("design:type",String)],Oe.prototype,"uriOrTemplate",void 0),y([b(),g("design:type",Function)],Oe.prototype,"cb",void 0),y([b(),g("design:type",Object)],Oe.prototype,"config",void 0);const Ce=dt()??h.join(__dirname,"..","assets"),He=h.join(Ce,"templates"),Je=h.join(Ce,"prompts"),_e=new WeakMap;class De extends a{get client(){const t=_e.get(this);if(!t)throw Error("Mcp server requires Mcp client");return t}constructor(){super()}async load(){const t=this.log.for(this.load);for(const e of xt)try{t.info("loading prompt "+e.getName());const r=e.build(this.client);t.verbose(`Loaded prompt ${r.title} from ${e.getName()} definition`)}catch(r){t.error("Failed to load prompt "+e.getName(),r)}try{await Ne(this.client),t.verbose("Registered built-in tools")}catch(e){t.error("Failed to register tools",e)}try{await(async(t,r)=>{r.info("Registering agent templates as resources...");const s=e.readdirSync(He).filter(t=>t.endsWith(".md"));for(const n of s){const s=h.basename(n,".md"),i=h.join(He,n),o=Oe.builder.setName(s).setTitle("Template: "+s).setDescription("Resource template for "+s).setUriOtTemplate("file:///"+i).setConfig({mimeType:"text/markdown",description:"Template for "+s}).setCb(async t=>{const r=e.readFileSync(t.pathname,"utf8");return{contents:[{uri:t.toString(),text:r,mimeType:"text/markdown"}],_meta:{}}});try{o.build(t),r.info("Registered template: "+s)}catch(t){r.error(`Failed to register template ${s}:`,t)}}r.info("Registering agent prompts...");const n=e.readdirSync(Je).filter(t=>t.endsWith(".md"));for(const s of n){const n=h.basename(s,".md"),i=h.join(Je,s),o=e.readFileSync(i,"utf8"),a=ht.builder.setName(n).setTitle("Prompt: "+n).setDescription("Dynamic prompt for "+n).setArgsSchema(j.object({})).setCb(async t=>({messages:[{role:"user",content:{type:"text",text:o}}],_meta:{}}));try{a.build(t),r.info("Registered prompt: "+n)}catch(t){r.error(`Failed to register prompt ${n}:`,t)}}})(this.client,t),t.verbose("Registered agent-specific assets")}catch(e){t.error("Failed to register agent assets",e)}}async boot(t="stdio"){let r=this.log;this.log.for(this.boot).info("McpServer booting..."),((t=o.get())=>{let r;try{r=(()=>{let t,r=__dirname;try{for(;r&&r!==h.parse(r).root;){const s=h.join(r,"node_modules");if(e.existsSync(s)&&e.statSync(s).isDirectory()){t=s;break}const n=h.dirname(r);if(n===r)break;r=n}}catch{}const s=[];if(t){const r=h.join(t,"@decaf-ts");try{if(e.existsSync(r)&&e.statSync(r).isDirectory()){const t=e.readdirSync(r);for(const n of t){const t=h.join(r,n);try{const r=h.join(t,"workdocs","assets","slogans.json");if(e.existsSync(r)&&e.statSync(r).isFile()){const t=e.readFileSync(r,"utf-8"),n=JSON.parse(t);if(Array.isArray(n))for(const t of n)"string"==typeof t&&t.trim().length>0&&s.push(t.trim())}}catch{}}}}catch{}}return 0===s.length?"Decaf: strongly brewed TypeScript.":s[Math.floor(Math.random()*s.length)]})()}catch{r="Decaf: strongly brewed TypeScript."}const s="# \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \n# ( ( \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \n# ) ) \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \n# [=======] \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \n# `-----\xb4 \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \n# \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \n# \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \n#".split("\n"),n=s.reduce((t,e)=>Math.max(t,e.length),0);s.push("# "+r.padStart(n-3)),s.forEach((e,r)=>{const s=K[r%K.length]||"",n=t.info.bind(t);try{n(m(e||"").raw(s).text)}catch{n((e||"")+"")}})})(this.log),"stdio"===t&&(o.setFactory(U),r=o.for(this.constructor.name));const s=((Array.isArray(Nt.icons)?Nt.icons:[Nt.icons])||[]).map(t=>{const e="string"==typeof t?.src?t.src:(t?.src??"")+"",r="string"==typeof t?.mimeType?t.mimeType:(t?.mimeType??"")+"";let s=[];return Array.isArray(t?.sizes)?s=t.sizes.map(t=>t+""):"string"==typeof t?.sizes&&(s=(t.sizes+"").split(",").map(t=>t.trim())),{src:e,mimeType:r,sizes:s}}),n={name:Nt.name,title:Nt.title,websiteUrl:Nt.websiteUrl,version:Nt.version,icons:s},i=new F(n,{instructions:"You are an AI assistant designed to help users with programming tasks related to the Decaf-TS framework. \nProvide clear, concise, and accurate information.\nIf you don't know the answer, admit it rather than making up information.\nAlways prioritize the user's intent and provide helpful suggestions when appropriate.\n",capabilities:{logging:{},tools:{},prompts:{}}});switch(((t,e)=>{_e.set(t,e)})(this,i),i.onerror=t=>{this.log.error("MCP instance onerror",t)},t){case"stdio":t=new B;break;case"http":t=new W({sessionIdGenerator:()=>q(),onsessioninitialized:t=>r.verbose("Session initialized: "+t),onsessionclosed:t=>r.verbose("Session closed: "+t),enableJsonResponse:!0,eventStore:void 0});break;default:if(!(a=t)||"object"!=typeof a||"function"!=typeof a.send&&"function"!=typeof a.close&&"function"!=typeof a.on)throw new T("Invalid transport type: "+t)}var a;try{this.log.info("Loading resources/prompts/tools..."),await this.load()}catch(t){throw this.log.error("Error loading resources/prompts/tools: "+t),t}await this.client.connect(t),r.info(`MCP Server connected via ${t.constructor.name} and running. Waiting for client connections...`)}}const Pe=(new t).command("start").option("--transport [String]","transport mode","stdio").description("starts decaf's mcp server").action(async t=>{const e=lt("package.json"),s=JSON.parse(r.readFileSync(e,"utf-8")),n=s.version,{transport:i}=t,o=(new L).for("mcp-server");if("stdio"!==i)throw Error("Unsupported transport mode: "+i);return o.info("Transport stdio"),o.debug(`running with options: ${JSON.stringify(t)} for ${s.name} version ${n}`),(new De).boot(i)});(new t).command("md-to-ast").description("pipes markdown to jira ast: `cat file.md` | npx decaf-mcp md-to-ast > ast.json").action(async t=>{const e=lt("package.json"),s=JSON.parse(r.readFileSync(e,"utf-8")),n=s.version;o.for("md-to-ast").debug(`running with options: ${JSON.stringify(t)} for ${s.name} version ${n}`);const i=se(await(async()=>{const t=[];for await(const e of process.stdin)t.push(Buffer.from(e));return Buffer.concat(t).toString("utf8")})(),{resolveMention:t=>({id:t,text:"@"+t}),resolveAttachment:t=>({id:t,collection:"attachments"})});process.stdout.write(JSON.stringify(i,null,2)+"\n")});const Re=(new t).name("mcp-server").command("mcp-server").description("decaf mcp server and agentic functionality");Re.addCommand(Pe),Re.parse(process.argv);
1
+ import{Command as t}from"commander";import*as e from"fs";import r,{promises as s}from"fs";import{MiniLogger as n,NumericLogLevels as i,Logging as o,LoggedClass as a,toSnakeCase as c,sf as p,toPascalCase as l,LogLevel as u,LoggedEnvironment as d}from"@decaf-ts/logging";import{style as m}from"styled-string-builder";import*as h from"path";import f from"path";import{__decorate as y,__metadata as g}from"tslib";import{required as b,Model as v,list as w,minlength as S}from"@decaf-ts/decorator-validation";import{z as j,ZodObject as x}from"zod";import{injectable as I,inject as k}from"@decaf-ts/injectable-decorators";import{prop as A,Metadata as E}from"@decaf-ts/decoration";import{InternalError as T,SerializationError as N,ValidationError as O}from"@decaf-ts/db-decorators";import C from"crypto";import H from"zlib";import{fileURLToPath as J}from"url";import{unified as _}from"unified";import D from"remark-directive";import P from"remark-gfm";import R from"remark-parse";import{UriTemplate as $}from"@modelcontextprotocol/sdk/shared/uriTemplate.js";import{ResourceTemplate as M,McpServer as F}from"@modelcontextprotocol/sdk/server/mcp.js";import{v4 as q}from"uuid";import{StdioServerTransport as B}from"@modelcontextprotocol/sdk/server/stdio.js";import{StreamableHTTPServerTransport as W}from"@modelcontextprotocol/sdk/server/streamableHttp.js";class L extends n{log(t,e,r,s){const n=this.config("level");i[n],i[t]}}const U=(t,e,...r)=>{const s=(t=>{if("string"==typeof t)return t;if(!t)return"unknown";if("function"==typeof t)return t.name||"unknown";if("object"==typeof t&&"constructor"in t){const e=t.constructor;if(e&&e.name)return e.name}return"unknown"})(t);return new L(s,e)},K=["\x1b[38;5;215m","\x1b[38;5;209m","\x1b[38;5;205m","\x1b[38;5;210m","\x1b[38;5;217m","\x1b[38;5;216m","\x1b[38;5;224m","\x1b[38;5;230m","\x1b[38;5;230m"];var z,Y,G,Z,V;(t=>{t[t.NONE=0]="NONE",t[t.BASIC=1]="BASIC",t[t.ADVANCED=2]="ADVANCED",t[t.HIGH=3]="HIGH"})(z||(z={})),(t=>{t[t.NONE=0]="NONE",t[t.LOW=1]="LOW",t[t.MEDIUM=2]="MEDIUM",t[t.HIGH=3]="HIGH"})(Y||(Y={})),(t=>{t[t.FREE=0]="FREE",t[t.LOW=1]="LOW",t[t.MEDIUM=2]="MEDIUM",t[t.HIGH=3]="HIGH"})(G||(G={}));class Q extends v{get log(){return this._log||(this._log=o.for(this)),this._log}constructor(t){super(t)}logFor(t){const{sessionId:e,requestId:r,authInfo:s}=t||{};let n="string"==typeof e&&e.length>0?this.log.for(e):this.log;return s&&s.clientId&&(n=n.for(s.clientId)),r&&(n=n.for(r.toString())),n}setDescription(t){return this.description=t,this}getDescription(){return this.description}setName(t){return this.name=t,this}getName(){return this.name}setTitle(t){return this.title=t,this}}y([b(),g("design:type",String)],Q.prototype,"description",void 0),y([b(),g("design:type",String)],Q.prototype,"name",void 0),y([b(),g("design:type",String)],Q.prototype,"title",void 0);class X extends Q{constructor(t){super(t),this.reasoning=z.NONE,this.effort=Y.NONE,this.cost=G.FREE}setReasoning(t){return this.reasoning=t,this}setEffort(t){return this.effort=t,this}setCost(t){return this.cost=t,this}}function tt(t){if(!t)return;let e=t,r=e&&e._def;for(;r&&"ZodObject"!==r.typeName;){if("ZodEffects"===r.typeName&&r.schema)e=r.schema;else if("ZodOptional"===r.typeName&&r.innerType)e=r.innerType;else if("ZodDefault"===r.typeName&&r.innerType)e=r.innerType;else if("ZodNullable"===r.typeName&&r.innerType)e=r.innerType;else{if(!r.schema)return;e=r.schema}r=e&&e._def}return r&&"ZodObject"===r.typeName?r:void 0}function et(t,e="schema"){if(tt(t))return t;if(t&&"object"==typeof t){const e=t.def&&"object"==typeof t.def?t.def:void 0,r=e&&(e.shape||"object"===e.type)&&e.shape||("object"===t.type?t.shape:void 0)||(e&&"object"===e.type?{}:void 0);if(e||"object"===t.type||r){const t={};if(r&&"object"==typeof r)for(const[e,s]of Object.entries(r))t[e]=st(s)?s:j.any();return j.object(t)}}throw Error(`Registration error: provided a non-canonical ${e}. Export a ZodObject (z.object(...)).`)}function rt(t){if(!t)return;if(t&&"object"==typeof t&&!t._def)return t.def&&"object"==typeof t.def&&t.def.shape?t.def.shape:t;const e=tt(t);return e?"function"==typeof e.shape?e.shape():e.shape||void 0:void 0}function st(t){return!(!t||"object"!=typeof t||!t._def)}y([b(),g("design:type",Number)],X.prototype,"reasoning",void 0),y([b(),g("design:type",Number)],X.prototype,"effort",void 0),y([b(),g("design:type",Number)],X.prototype,"cost",void 0),(t=>{t.ASSETS="assets"})(Z||(Z={})),(t=>{t.PROMPT="prompts",t.DOCUMENTATION="documentation",t.CODE="code"})(V||(V={}));const nt=Buffer.from("DCAF1","ascii");function it(t){let e=f.resolve(t);for(;;){if(r.existsSync(f.join(e,"package.json")))return e;const t=f.dirname(e);if(t===e)break;e=t}}const ot=process.argv?.[1]?it(f.dirname(f.resolve(process.argv[1]))):void 0,at=(()=>{const t=Error().stack;if(!t)return;const e=t.split(/\r?\n/).slice(1);for(const t of e){const e=t.match(/\(?([^()]+?):\d+:\d+\)?/);if(!e)continue;let r=e[1];if(r.startsWith("file://"))try{r=J(r)}catch{continue}if(!r.includes("node:internal"))return f.dirname(r)}})(),ct=at?it(at):void 0,pt=ot??ct??process.cwd();function lt(...t){return f.join(pt,...t)}function ut(t){let r=t;for(;;){const t=h.join(r,"lib","assets");if(e.existsSync(t))return t;const s=h.join(r,"src","assets");if(e.existsSync(s))return s;const n=h.join(r,"assets");if(e.existsSync(n))return n;const i=h.dirname(r);if(i===r)break;r=i}}function dt(){const t=process.env.DECAF_ASSET_DIR||process.env.MCP_ASSET_DIR||process.env.ASSET_DIR||"";if(t&&e.existsSync(t))return t;const r=ut(__dirname);if(r)return r;const s=process.argv?.[1];if(s){const t=ut(h.dirname(s));if(t)return t}const n=[pt,process.env.INIT_CWD].filter(Boolean);for(const t of n){const e=ut(t);if(e)return e}return lt("assets")}let mt=class extends a{constructor(t){super(),this.basePath=t||dt()}listAssets(...t){const r=h.join(this.basePath,...t);return e.readdirSync(r)}listPrompts(){return this.listAssets(V.PROMPT)}getAsset(t,r="md",...s){const n=h.join(this.basePath,...s),i=(t,r=!1)=>{try{return r?(t=>{if(t.length<nt.length+16+12+16)throw Error("Invalid prompt payload (too short)");if(!t.subarray(0,nt.length).equals(nt))throw Error("Invalid prompt payload (bad magic)");const e=process.env.ENCRYPTION_KEY||"";if(!e)throw Error("Missing encryption key. Set ENCRYPTION_KEY to load obfuscated assets.");let r=nt.length;const s=t.subarray(r,r+16);r+=16;const n=t.subarray(r,r+12);r+=12;const i=t.subarray(r,r+16);r+=16;const o=t.subarray(r),a=((t,e)=>C.scryptSync(t,e,32))(e,s),c=C.createDecipheriv("aes-256-gcm",a,n);c.setAuthTag(i);const p=Buffer.concat([c.update(o),c.final()]);return H.gunzipSync(p)})(e.readFileSync(t)).toString("utf-8"):e.readFileSync(t,"utf-8")}catch(t){if("ENOENT"===t.code)return null;throw t}},o=i(h.join(n,`${t}.${r}`),"enc"===r);if(null!==o)return o;const a=i(h.join(n,t+".enc"),!0);if(null!==a)return a;throw Error("Asset not found: "+h.join(n,`${t}.${r}`))}getAllAssets(t,...e){return this.listAssets(t,...e).reduce((r,s)=>{const n=h.extname(s),i=h.basename(s,n),o=n.replace(/^\./,"")||void 0;return r[i]=this.getAsset(i,o??void 0,t,...e),r},{})}toPromptDef(t){const e=t=>"number"==typeof t?t:"string"==typeof t?(t=>{switch(t){case"none":return z.NONE;case"basic":return z.BASIC;case"advanced":return z.ADVANCED;case"high":return z.HIGH;case"medium":return Y.MEDIUM;case"low":return G.LOW;case"free":return G.FREE;default:throw new T("Cannon convert unknown level "+t)}})(t.toLowerCase()):z.NONE;return t.effort=e(t.effort),t.reasoning=e(t.reasoning),t.cost=e(t.cost),t}getPrompt(t,...e){const r=this.getAsset(c(t),"json",V.PROMPT,...e);let s;try{s=JSON.parse(r)}catch(r){throw new N(`Failed to parse prompt ${t} in categories ${e}: ${r}`)}return this.toPromptDef(s)}getAllPrompts(...t){const e=this.getAllAssets(V.PROMPT,...t);return Object.entries(e).reduce((e,[r,s])=>{try{e[r]=JSON.parse(s)}catch(e){throw new N(`Failed to parse prompt ${r} in categories ${t}: ${e}`)}return e},e)}};mt=y([I(),g("design:paramtypes",[String])],mt);class ht extends X{constructor(t){super(t)}setCb(t){return this.cb=t,this}setArgsSchema(t){return this.argsSchema=t,this}static get builder(){return new ht}static patchPrompt(t,e,r,s){const n=(e=Array.isArray(e)?e:Object.keys(e)).filter(t=>!Object.prototype.hasOwnProperty.call(r,t));if(n.length)throw new O("Missing replacements for placeholders: "+n.join(", "));s&&(s.verbose("Patching prompt with placeholders: "+JSON.stringify(e)),s.debug("Values: "+JSON.stringify(r)));const i=e.reduce((t,e)=>(t[e]=r[e],t),{});return p(t,i)}patchPrompt(t,e,r,s){return ht.patchPrompt(t,e,r,s||this.log.for(this.patchPrompt))}build(t,e){const r=this.log.for(this.build),s=this.hasErrors();if(s)throw new O(s.toString());try{this.argsSchema&&et(this.argsSchema,"argsSchema");const r=rt(this.argsSchema);return t.registerPrompt(this.name,{title:this.title,description:this.description,argsSchema:r},async(t,r)=>{const s=this.logFor(r);t=Object.assign({},e,t||{}),s.verbose(`Executing prompt ${this.name} with args: ${JSON.stringify(t)}`),t._meta=Object.assign(t._meta||{},{usage:{reasoning:this.reasoning,effort:this.effort,cost:this.cost}});const n=await Promise.resolve(this.cb(t,r));return s.verbose(`Prompt ${this.name} executed successfully.`),s.debug("Prompt execution meta: "+JSON.stringify(n._meta)),n})}catch(t){throw r.error("Failed to register prompt "+(this.name||this.constructor.name),t),t}}}y([k(mt),g("design:type",mt)],ht.prototype,"assets",void 0),y([b(),g("design:type",Object)],ht.prototype,"cb",void 0),y([b(),g("design:type",x)],ht.prototype,"argsSchema",void 0),y([A(),g("design:type",Object)],ht.prototype,"placeholders",void 0);class ft extends ht{setCategory(t){return this.promptCategory=t,this}addPrefix(t){return this.prefixes=this.prefixes||[],this.prefixes.push(t),this}addSuffix(t){return this.suffixes=this.suffixes||[],this.suffixes.push(t),this}constructor(t){super(t)}build(t){const e=this.assets.getPrompt(this.name,this.promptCategory);v.fromObject(this,e);const r=new Set((E.properties(ft)||[]).filter(t=>!["assets","promptCategory","prefixes","suffixes"].includes(t)));["cb","argsSchema"].forEach(t=>r.add(t));const s=this.hasErrors(...Array.from(r));if(s)throw new O(s.toString());const n=(this.prefixes||[]).map(t=>this.assets.getPrompt(t,this.promptCategory)),i=(this.suffixes||[]).map(t=>this.assets.getPrompt(t,this.promptCategory)),o=[...new Set([...e.placeholders,...n.map(t=>t.placeholders||[]),...i.map(t=>t.placeholders||[])].flat())].reduce((t,e)=>(t[e]=j.string().describe("The description for "+e),t),{});return this.setArgsSchema(j.object(o)),this.setCb((t,e)=>{const r=this.logFor(e).for(ft).for(this.promptCategory).for(this.name);function s(t=[]){return Array.isArray(t)?t:Object.keys(t)}const n=(this.prefixes||[]).map(t=>this.assets.getPrompt(t,this.promptCategory)),i=(this.suffixes||[]).map(t=>this.assets.getPrompt(t,this.promptCategory)),o=this.assets.getPrompt(this.name,this.promptCategory),a=[...new Set([...n.map(t=>s(t.placeholders)).flat(),...i.map(t=>s(t.placeholders)).flat(),...s(o.placeholders).flat()])];return{messages:[{role:"user",content:{type:"text",text:this.patchPrompt([...n.map(t=>t.prompt),o.prompt,...i.map(t=>t.prompt)].join("\n\n"),a,t,r)}}],_meta:{}}}),super.build(t)}setReasoning(t){throw new T("Named prompt builders don't require callback")}setEffort(t){throw new T("Named prompt builders don't require callback")}setCost(t){throw new T("Named prompt builders don't require callback")}setDescription(t){throw new T("Named prompt builders don't require callback")}setTitle(t){throw new T("Named prompt builders don't require callback")}static get builder(){return new ft}}y([b(),g("design:type",String)],ft.prototype,"promptCategory",void 0),y([w(String),S(1),g("design:type",Array)],ft.prototype,"prefixes",void 0),y([S(1),w(String),g("design:type",Array)],ft.prototype,"suffixes",void 0);const yt=ht.builder.setName("example.prompt").setTitle("Example prompt").setDescription("Example prompt for testing").setArgsSchema(j.object({message:j.string().optional()})).setCb(async t=>{const e=t.message??"default";return{messages:[{role:"assistant",content:{type:"text",text:e}}],content:[],structuredContent:{message:e},result:{message:e}}}),gt=ht.builder.setName("interactive.jsdoc").setTitle("Interactive JSDoc prompt").setDescription("Interactive prompt for jogging JSDoc helpers").setArgsSchema(j.object({gist:j.string().optional()})).setCb(async t=>{const e=t.gist??"interactive jsdoc response";return{messages:[{role:"assistant",content:{type:"text",text:e}}],content:[],structuredContent:{message:e},result:{message:e}}}),bt=Object.assign(gt,{name:gt.getName()});var vt;function wt(t,e=[],r=[]){const s=ft.builder.setCategory(vt.DOCS).setName(t);return["prefix",...e].forEach(t=>s.addPrefix(t)),["suffix",...r].forEach(t=>s.addSuffix(t)),s}(t=>{t.DOCS="documentation",t.CODE="code"})(vt||(vt={}));const St=[wt("class"),wt("constant"),wt("decorator"),wt("function"),wt("module"),wt("file"),wt("repo",[],["iterate"])],jt=j.object({className:j.string().describe("the class name to turn into a builder")}),xt=[yt,bt,...St,ht.builder.setName("ts.code.dp.builder").setTitle("Typescript builder design patter prompt").setDescription("for a class, with a defined set of properties, scafold a builder design pattern").setArgsSchema(jt).setReasoning(z.BASIC).setCb((t,e)=>(t.className=l(t.className),{messages:[{role:"user",content:{type:"text",text:`You're a senior TypeScript developer writing typescript code.You're a senior TypeScript developer writing typescript code.\nTransform the selected class into a builder design pattern implementation in Typescript.\nuse @decaf-ts validation decorators to enforce the validation of your builder.\n\n- must extend the Model Class from @decaf-ts/decorator-validation;\n- each property must be marked as protected;\n- each property must have a setter method that returns 'this' for chaining;\n- the build() method must validate the properties using hasErrors() method from Model class;\n- if validation fails, throw an error with the validation errors;\n- if validation passes, return an instance of the original class with the set properties;\n- optionally (but do so by default) add the static builder and from methods from the example;\n- if the clasee already follows the pattern but has properties without decoration or without setters, simple add them;\n\nexample:\n\noriginal class:\n\`\`\`typescript\nexport class ${t.className} {\n description!: string;\n name!: string = "default name";\n title!: string;\n age?: string;\n dateOfBirth!: Date;\n}}\n\`\`\` \n\nresulting builder pattern implementation:\n\`\`\`typescript\nexport class ${t.className}Builder extends Model {\n\n @minlength(10\n @required()\n protected description!: string;\n \n @required()\n protected name!: string = "default value;\n \n @required()\n protected title!: string;\n \n @min(18)\n protected age?: string;\n \n @date()\n protected dateOfBirth!: Date;\n\n protected constructor(arg?: ModelArg<${t.className}Builder>>) {\n super(arg);\n Model.fromModel(this, arg);\n }\n\n setDescription(value: string) {\n this.description = value;\n return this;\n }\n\n setName(value: string) {\n this.name = value;\n return this;\n }\n\n setTitle(value: string) {\n this.title = value;\n return this;\n }\n setAge(value: number) {\n this.age = value;\n return this;\n }\n setDate(value: Date) {\n this.age = value;\n return this;\n }\n \n build(...args: any[]): ${t.className}Builder | Promise<${t.className}Builder> {\n const errs = this.hasErrors();\n if (errs) throw new Error(errs.toString());\n \n return // code that builds OBJ here\n }\n \n static get builder(): ${t.className}Builder {\n return new ${t.className}Builder(); // static method to get a new builder instance\n }\n \n static from<K extends keyof ${t.className}Builder>(obj: K, ${t.className}Builder[K]): ${t.className}Builder {\n return new ${t.className}Builder(); // static method to create a builder from an object\n }\n}\n\`\`\` \n\n`}}],_meta:{}}))];class It extends X{setAnnotations(t){return this.annotations=Object.assign(this.annotations,t),this}setCb(t){return this.cb=t,this}setInputSchema(t){return this.inputSchema=t,this}setOutputSchema(t){return this.outputSchema=t,this}constructor(t){super(t),this.annotations={readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1}}static get builder(){return new It}build(t){const e=this.hasErrors();if(e)throw Error(e.toString());try{this.inputSchema&&et(this.inputSchema,"inputSchema"),this.outputSchema&&et(this.outputSchema,"outputSchema");const e=rt(this.inputSchema),r=rt(this.outputSchema);return t.registerTool(this.name,{title:this.title,description:this.description,inputSchema:e,outputSchema:r,annotations:this.annotations,_meta:{usage:{reasoning:this.reasoning,effort:this.effort,cost:this.cost}}},async(t,e)=>{const r=this.logFor(e);r.verbose(`Executing tool ${this.name} with args: ${JSON.stringify(t)}`),e._meta=Object.assign(e._meta||{},{usage:{reasoning:this.reasoning,effort:this.effort,cost:this.cost}});const s=await Promise.resolve(this.cb(t,e));return r.verbose(`Tool ${this.name} executed successfully.`),r.debug("Tool execution meta: "+JSON.stringify(s._meta)),s})}catch(t){const e=t?.message||t+"";if("string"==typeof e&&e.includes("already registered"))return o.for(this).warn(`Tool ${this.name} already registered - skipping duplicate registration`),{name:this.name};throw o.for(this).error("Error building tool",t),t}}}y([b(),g("design:type",Object)],It.prototype,"annotations",void 0),y([b(),g("design:type",Object)],It.prototype,"cb",void 0),y([b(),g("design:type",Function)],It.prototype,"inputSchema",void 0);const kt=It.builder.setName("example.tool").setTitle("Example tool").setDescription("A smoke tool used for quick testing").setInputSchema(j.object({})).setCb(async()=>({content:[{type:"text",text:"example tool ok"}],result:{status:"ok"}}));Object.assign(kt,{name:kt.getName()});const At=It.builder.setName("file.summarizer").setTitle("File summarizer").setDescription("Summaries files for quick previews").setInputSchema(j.object({filePath:j.string().optional()})).setCb(async()=>({content:[{type:"text",text:"file summary stub"}],result:{summary:"file summary stub"}}));Object.assign(At,{name:At.getName()});const Et="##VERSION##";E.registerLibrary("##PACKAGE##",Et);const Tt={mcpId:"decaf",name:"decaf-ts mcp server",title:"Decaf-TS MCP Server",description:"Provides precise coding assistance for the decaf-ts framework",version:Et,websiteUrl:"https://decaf-ts.github.io",repositoryUrl:"https://github.com/decaf-ts/mcp-server",license:"AGPL-3.0",workingDir:pt,assetDir:dt(),contacts:[{name:"Decaf-TS",url:"https://decaf-ts.github.io"}],tags:"server,official,decaf-ts",metadata:{},icons:[{src:"workdocs/assets/favicon.svg",mimeType:"image/svg+xml",sizes:"any"}],jira:{host:process.env.JIRA__HOST||"decaf-ts.atlassian.net",email:process.env.JIRA__EMAIL||"",apiKey:process.env.JIRA__API_KEY||process.env.JIRA__APIKEY||"",projectKey:process.env.JIRA__PROJECT_KEY||void 0,issueType:process.env.JIRA__ISSUE_TYPE||void 0,parentIssue:process.env.JIRA__PARENT_ISSUE||void 0},level:u.error},Nt=d.accumulate(Tt);function Ot(){const{host:t,email:e,apiKey:r,projectKey:s,issueType:n}=Nt.jira;return{host:t?.trim(),email:e?.trim(),apiKey:r?.trim(),projectKey:s?.trim(),issueType:n?.trim(),parentIssue:Nt.jira.parentIssue?.trim()}}function Ct(){const t=Ot();return[{name:"JIRA__HOST",required:!0,description:"Atlassian host (e.g. decaf-ts.atlassian.net) where your Jira instance is hosted.",value:t.host},{name:"JIRA__EMAIL",required:!0,description:"Email address of the Jira account that has API access.",value:t.email},{name:"JIRA__API_KEY",required:!0,description:"API token created in your Atlassian profile (a.k.a. APIKEY alias) for authenticating requests.",sensitive:!0,value:t.apiKey},{name:"JIRA__PROJECT_KEY",required:!1,description:"Default Jira project key (e.g. DECAF) used when an issue creation request omits a project.",value:t.projectKey},{name:"JIRA__ISSUE_TYPE",required:!1,description:"Default Jira issue type (e.g. Task, Bug) used when creating issues without an explicit type.",value:t.issueType},{name:"JIRA__PARENT_ISSUE",required:!1,description:"Default parent issue key (e.g. DECAF-123) applied when a child issue is created without an explicit parent.",value:t.parentIssue}]}function Ht(t){const e=t.value?((t,e)=>{if(t)return e?"<configured>":t})(t.value,t.sensitive):"not set",r=t.required?"(required)":"(optional)";return`\u2022 ${t.name} ${r}: ${t.description} Current state: ${e}.`}o.setConfig(Nt);class Jt extends Error{constructor(t){const e=Ct(),r=(t=>{const e=Ct();return`${t.length?`Missing Jira credentials: ${t.map(t=>t.name).join(", ")}.`:"Jira credentials are configured."}\n\nThis setup uses the following environment variables:\n${e.map(Ht).join("\n")}`})(t);super(r),this.name="MissingJiraEnvironmentError",this.descriptors=e,this.missing=t,"function"==typeof Error.captureStackTrace&&Error.captureStackTrace(this,Jt)}}function _t(t){if(!t)return{code:"jira_error",message:"Unknown Jira error",details:{raw:t}};const e=t?.status??t?.statusCode??t?.response?.status??t?.response?.statusCode,r="number"==typeof e?e:Number(e)||void 0,s=t?.response?.data??t?.data??t?.response?.body??t?.body,n=[];"string"==typeof t?.message&&n.push(t.message),((t,e)=>{t&&(Array.isArray(t.errorMessages)&&t.errorMessages.forEach(t=>"string"==typeof t&&e.push(t)),"string"==typeof t.errorMessage&&e.push(t.errorMessage),t.errorCollection&&Array.isArray(t.errorCollection.errors)&&t.errorCollection.errors.forEach(t=>{"string"==typeof t?e.push(t):t&&"string"==typeof t.message&&e.push(t.message)}),t?.errors&&"object"==typeof t.errors&&Object.values(t.errors).forEach(t=>{"string"==typeof t?e.push(t):"string"==typeof t?.message&&e.push(t.message)}))})(s,n);const i=r?`Jira API error (${r})`:"Jira API error",o=n.length>0?n.join(" | "):i;return{code:r?"jira_"+r:t?.code??"jira_error",message:o,details:{httpStatus:r,body:s,raw:t}}}const Dt=j.object({issueId:j.string().min(1),deleteSubtasks:j.boolean().optional().default(!0)}),Pt={name:"jira-issue-delete",inputSchema:Dt,runTool:async(t,e)=>{try{const r=Dt.parse(e),s=t.issues??t.issue??t,n=s?.delete??s?.deleteIssue;if("function"!=typeof n)throw Error("jira client delete endpoint is not available");return await n.call(s,{issueId:r.issueId,deleteSubtasks:r.deleteSubtasks}),{success:!0,message:`Issue ${e.issueId} deleted successfully`}}catch(t){throw _t(t)}}},Rt=j.object({issueId:j.string().min(1),expand:j.string().optional(),fields:j.array(j.string()).optional(),properties:j.array(j.string()).optional()}),$t={name:"jira-issue-read",inputSchema:Rt,runTool:async(t,e)=>{try{const r=Rt.parse(e),s={issueIdOrKey:r.issueId};r.expand&&(s.expand=r.expand),r.fields&&(s.fields=r.fields),r.properties&&(s.properties=r.properties);const n=await t.issues.get(s);return n?.data??n}catch(t){throw _t(t)}}};function Mt(t,e,r){const s=((t.url??"")+"").match(/^(attachment|jira-attachment):(.+)$/i);if(!s)return null;const n=s[2],i=r.resolveAttachment?.(n);return i?{type:"block",node:{type:"mediaSingle",attrs:{layout:"center"},content:[{type:"media",attrs:{type:"file",id:i.id,collection:i.collection??"attachments"}}]}}:null}function Ft(t,e){if(!t)return[];if(!e.enableAtMentions&&!e.enableEmojiShortcodes)return[{type:"text",text:t}];let r=0;const s=[],n=/(^|[^A-Za-z0-9_])@([A-Za-z0-9._-]{1,64})/g,i=/:([a-z0-9_+-]{1,64}):/gi;for(;r<t.length;){const o=Bt(e.enableAtMentions?qt(n,t,r):null,e.enableEmojiShortcodes?qt(i,t,r):null);if(!o){s.push({type:"text",text:t.slice(r)});break}if(o.index>r&&s.push({type:"text",text:t.slice(r,o.index)}),"mention"===o.kind){const{full:t,groups:n}=o,i=n[0]??"",a=n[1]??"";i&&s.push({type:"text",text:i});const c=e.resolveMention?.(a);c?s.push({type:"mention",attrs:{id:c.id,text:c.text}}):s.push({type:"text",text:"@"+a}),r=o.index+t.length;continue}if("emoji"===o.kind){const{full:t,groups:n}=o,i=`:${n[0]}:`,a=e.resolveEmoji?.(i);s.push({type:"emoji",attrs:a?{shortName:a.shortName,text:a.text}:{shortName:i}}),r=o.index+t.length;continue}}return(t=>{const e=[];for(const r of t){const t=e[e.length-1];"text"!==r.type||"text"!==t?.type||t.marks||r.marks?e.push(r):t.text=(t.text??"")+(r.text??"")}return e})(s)}function qt(t,e,r){t.lastIndex=r;const s=t.exec(e);if(!s)return null;const n=t.source.includes("@")?"mention":"emoji";return{index:s.index,full:s[0],groups:s.slice(1),kind:n}}function Bt(t,e){return t?e&&t.index>e.index?e:t:e}function Wt(t){const e=(t.children??[])[0];return"text"===e?.type?(e.value??"")+"":"paragraph"===e?.type?((e.children??[]).map(t=>"text"===t.type?(t.value??"")+"":"").join("")||"")+"":""}function Lt(t){const e=((t??"")+"").toLowerCase().trim();return e?"info"===e||"note"===e||"success"===e||"warning"===e||"error"===e?e:"danger"===e?"error":null:null}function Ut(t){const e=((t??"")+"").toLowerCase().trim();return!e||"neutral"!==e&&"green"!==e&&"yellow"!==e&&"red"!==e&&"blue"!==e&&"purple"!==e?null:e}function Kt(t,e){const r=[];for(const s of t??[])if(s?.type)if("text"!==s.type)if("strong"!==s.type)if("emphasis"!==s.type)if("delete"!==s.type)if("inlineCode"!==s.type)if("break"!==s.type){if("link"===s.type){const t=(s.url??"")+"",n=Yt(s.children??[],t),i=Mt(s,0,e);if(i){"inline"===i.type?r.push(i.node):r.push({type:"text",text:n,marks:[{type:"link",attrs:{href:t}}]});continue}if(e.enableSmartCards&&Gt(n,t)){r.push({type:"inlineCard",attrs:{url:t}});continue}r.push({type:"text",text:n,marks:[{type:"link",attrs:{href:t}}]});continue}if("textDirective"===s.type&&"status"===s.name){const t=Wt(s)||"Status",e=Ut(s.attributes?.color)??"neutral";r.push({type:"status",attrs:{text:t,color:e}});continue}if("textDirective"===s.type&&"emoji"===s.name){const t=Zt(s);r.push(Vt(t,e));continue}}else r.push({type:"hardBreak"});else r.push({type:"text",text:(s.value??"")+"",marks:[{type:"code"}]});else r.push(...zt(Kt(s.children??[],e),{type:"strike"}));else r.push(...zt(Kt(s.children??[],e),{type:"em"}));else r.push(...zt(Kt(s.children??[],e),{type:"strong"}));else r.push(...Ft((s.value??"")+"",e));return r.filter(t=>!("text"===t.type&&""===(t.text??"")))}function zt(t,e){return t.map(t=>{if("text"!==t.type)return t;const r=t.marks?[...t.marks,e]:[e];return{...t,marks:r}})}function Yt(t,e){const r=[];for(const e of t??[])"text"===e.type||"inlineCode"===e.type?r.push((e.value??"")+""):"emphasis"!==e.type&&"strong"!==e.type&&"delete"!==e.type||r.push(Yt(e.children??[],""));return r.join("")||e}function Gt(t,e){const r=(t??"").trim(),s=(e??"").trim();return r===s&&/^https?:\/\//i.test(s)}function Zt(t){return(t.children??[]).map(t=>"text"===t.type?(t.value??"")+"":"").join("").trim()||""}function Vt(t,e){const r=t.startsWith(":")?t:`:${t}:`,s=e.resolveEmoji?.(r);return s?{type:"emoji",attrs:{shortName:s.shortName,text:s.text}}:{type:"emoji",attrs:{shortName:r}}}function Qt(t){return t?"string"==typeof t?t:"text"===t.type||"inlineCode"===t.type?(t.value??"")+"":Array.isArray(t.children)?t.children.map(Qt).join(""):"":""}function Xt(t,e){if(!t?.type)return null;if((t=>"containerDirective"===t?.type&&"panel"===t?.name)(t))return((t,e)=>{const r=t.attributes??{},s=Lt(r.type)??"info",n="string"==typeof r.title?r.title:void 0,i=(t.children??[]).map(t=>Xt(t,e)).flat().filter(Boolean);return{type:"panel",attrs:{panelType:s,...n?{panelType:s,title:n}:{panelType:s}},content:i.length?i:[{type:"paragraph",content:[]}]}})(t,e);switch(t.type){case"heading":return{type:"heading",attrs:{level:ee(t.depth??1,1,6)},content:Kt(t.children??[],e)};case"paragraph":return(t=>{const e=t.children??[];if(1!==e.length)return null;const r=e[0];if("image"!==r?.type)return null;const s=(r.url??"")+"";return s?{type:"mediaSingle",attrs:{layout:"center"},content:[{type:"media",attrs:{type:"external",url:s}}]}:null})(t)||{type:"paragraph",content:Kt(t.children??[],e)};case"blockquote":return{type:"blockquote",content:(t.children??[]).map(t=>Xt(t,e)).flat().filter(Boolean)};case"list":return((t,e)=>e.enableTaskLists&&(t.children??[]).some(t=>"boolean"==typeof t.checked)?((t,e)=>{const r=[];let s=0;for(const n of t.children??[]){if("boolean"!=typeof n.checked)continue;s+=1;const t=(n.children??[]).map(t=>Xt(t,e)).flat().filter(Boolean);r.push({type:"taskItem",attrs:{localId:"task-"+s,state:n.checked?"DONE":"TODO"},content:t.length?t:[{type:"paragraph",content:[]}]})}return{type:"taskList",content:r}})(t,e):{type:t.ordered?"orderedList":"bulletList",content:(t.children??[]).map(t=>((t,e)=>{const r=(t.children??[]).map(t=>Xt(t,e)).flat().filter(Boolean);return{type:"listItem",content:r.length?r:[{type:"paragraph",content:[]}]}})(t,e))})(t,e);case"code":{const r=((t,e)=>{const r=(t??"").toString().trim().toLowerCase();return r?e.enableMermaid&&"mermaid"===r?"mermaid":(t=>{const e=t.trim().toLowerCase();return{js:"javascript",javascript:"javascript",jsx:"javascript",ts:"typescript",typescript:"typescript",tsx:"typescript",py:"python",python:"python",rb:"ruby",ruby:"ruby",sh:"bash",bash:"bash",zsh:"bash",shell:"bash",yml:"yaml",yaml:"yaml",json:"json",toml:"toml",xml:"xml",html:"html",css:"css",scss:"scss",sql:"sql",go:"go",rust:"rust",java:"java",c:"c",cpp:"cpp","c++":"cpp",cs:"csharp",csharp:"csharp",php:"php",kotlin:"kotlin",swift:"swift",md:"markdown",markdown:"markdown",graphql:"graphql",gql:"graphql",dockerfile:"docker",makefile:"make",ini:"ini"}[e]??e})(r):null})(t.lang,e);return{type:"codeBlock",attrs:{language:r},content:[{type:"text",text:(t.value??"")+""}]}}case"thematicBreak":return{type:"rule"};case"table":return((t,e)=>({type:"table",content:(t.children??[]).map((t,r)=>({type:"tableRow",content:(t.children??[]).map(t=>({type:0===r?"tableHeader":"tableCell",content:[{type:"paragraph",content:Kt(t.children??[],e)}]}))}))}))(t,e);case"leafDirective":return"status"===t.name?(t=>{const e=Ut((t.attributes??{}).color)??"neutral";return{type:"paragraph",content:[{type:"status",attrs:{text:Wt(t)||"Status",color:e}}]}})(t):"panel"===t.name?((t,e)=>{const r=t.attributes??{},s=Lt(r.type)??"info",n="string"==typeof r.title?r.title:void 0;return{type:"panel",attrs:{panelType:s,...n?{title:n}:{}},content:[{type:"paragraph",content:Kt([{type:"text",value:Wt(t)}],e)}]}})(t,e):te(t,e);default:return te(t,e)}}function te(t,e){if("drop"===e.unknownNodeStrategy)return null;const r=Qt(t);return r?{type:"paragraph",content:[{type:"text",text:r}]}:null}function ee(t,e,r){const s=Number.isFinite(t)?Math.trunc(t):e;return Math.max(e,Math.min(r,s))}const re={resolveMention:void 0,resolveAttachment:void 0,resolveEmoji:void 0,enableSmartCards:!0,enableMermaid:!0,enableEmojiShortcodes:!0,enableAtMentions:!0,enableTaskLists:!0,unknownNodeStrategy:"text"};function se(t,e={}){const r={...re,...e},s=t??"",n=_().use(R).use(P).use(D),i=n.parse(s),o=n.runSync(i);return ne(o),((t,e)=>{const r=[];for(const s of t.children??[]){const t=Xt(s,e);t&&(Array.isArray(t)?r.push(...t):r.push(t))}return((t,e)=>{if(!e.enableSmartCards)return t;const r=t.content.map(t=>(t=>{if("paragraph"!==t.type)return t;const e=t.content??[];if(1!==e.length)return t;const r=e[0];if("inlineCard"!==r?.type)return t;const s=r.attrs?.url;return s?[{type:"blockCard",attrs:{url:s}}]:t})(t)).flat();return{...t,content:r}})({version:1,type:"doc",content:r},e)})(o,r)}function ne(t){if(!t||!Array.isArray(t.children))return;const e=[];for(const r of t.children)"definition"!==r?.type&&("html"!==r?.type?(ne(r),e.push(r)):e.push({type:"text",value:(r.value??"")+""}));t.children=e}const ie=j.object({issueId:j.string().min(1),transitionId:j.union([j.string(),j.number()]),fields:j.record(j.any()).optional(),update:j.record(j.array(j.object({set:j.any().optional(),add:j.any().optional(),remove:j.any().optional()}))).optional(),comment:j.string().optional()}),oe={name:"jira-issue-transition",inputSchema:ie,runTool:async(t,e)=>{try{const r=ie.parse(e),s={id:r.transitionId};r.fields&&(s.fields=r.fields),r.update&&(s.update=r.update),r.comment&&(s.comment={body:se(r.comment)});const n=await t.issues.transition({issueId:r.issueId,transition:s});return n?.data??n}catch(t){throw _t(t)}}},ae=j.object({issueId:j.string().min(1),fields:j.record(j.any()).optional(),update:j.record(j.array(j.object({set:j.any().optional(),add:j.any().optional(),remove:j.any().optional(),edit:j.any().optional()}))).optional(),properties:j.array(j.any()).optional(),notifyUsers:j.boolean().optional().default(!0),issueTemplateId:j.string().optional(),overrideScreenSecurity:j.boolean().optional().default(!1),overrideEditableFlag:j.boolean().optional().default(!1)}),ce={name:"jira-issue-update",inputSchema:ae,runTool:async(t,e)=>{try{const r=ae.parse(e),s={issueId:r.issueId};r.fields&&(s.fields=r.fields),r.update&&(s.update=r.update),r.properties&&(s.properties=r.properties),void 0!==r.notifyUsers&&(s.notifyUsers=r.notifyUsers),r.issueTemplateId&&(s.issueTemplateId=r.issueTemplateId),void 0!==r.overrideScreenSecurity&&(s.overrideScreenSecurity=r.overrideScreenSecurity),void 0!==r.overrideEditableFlag&&(s.overrideEditableFlag=r.overrideEditableFlag);const n=await t.issues.update(s);return n?.data??n}catch(t){throw _t(t)}}},pe=j.object({issueId:j.string().min(1),assignee:j.union([j.string(),j.object({accountId:j.string().min(1)}),j.object({accountType:j.string().min(1)})])}),le={name:"jira-assign-issue",inputSchema:pe,runTool:async(t,e)=>{try{const r=pe.parse(e);let s;s="string"==typeof r.assignee?{accountId:r.assignee}:r.assignee;const n=await t.issues.assign({issueId:r.issueId,assignee:s});return n?.data??n}catch(t){throw _t(t)}}},ue=j.object({issueId:j.string().min(1)}),de={name:"jira-unassign-issue",inputSchema:ue,runTool:async(t,e)=>{try{const r=ue.parse(e),s=await t.issues.assign({issueId:r.issueId,assignee:{accountId:"-1"}});return s?.data??s}catch(t){throw _t(t)}}},me=j.object({issueId:j.string().min(1),body:j.string().min(1),visibility:j.object({type:j.enum(["role","group"]),value:j.string().min(1)}).optional()}),he={name:"jira-comment-add",inputSchema:me,runTool:async(t,e)=>{try{const r=me.parse(e),s={body:se(r.body)};r.visibility&&(s.visibility=r.visibility);const n=await t.issues.addComment({issueId:r.issueId,comment:s});return n?.data??n}catch(t){throw _t(t)}}},fe=j.object({issueId:j.string().min(1),start:j.number().optional().default(0),maxResults:j.number().optional().default(50),orderBy:j.string().optional(),expand:j.string().optional()}),ye={name:"jira-comment-list",inputSchema:fe,runTool:async(t,e)=>{try{const r=fe.parse(e),s=await t.issues.getComments({issueId:r.issueId,start:r.start,maxResults:r.maxResults,orderBy:r.orderBy,expand:r.expand});return s?.data??s}catch(t){throw _t(t)}}},ge=j.object({link:j.object({relationship:j.enum(["Blocks","Relates to","Duplicates","Is blocked by","Is related to","Is duplicated by","Causes","Is caused by","Clone","Required","Work on","Split","Roll up"]),inwardIssue:j.object({id:j.string().optional(),key:j.string().optional()}),outwardIssue:j.object({id:j.string().optional(),key:j.string().optional()}),comment:j.object({body:j.string().optional(),visibility:j.object({type:j.enum(["role","group"]),value:j.string().min(1)}).optional()}).optional()})}),be={name:"jira-link-create",inputSchema:ge,runTool:async(t,e)=>{try{const r=ge.parse(e).link,s={relationship:r.relationship,inwardIssue:r.inwardIssue.id||r.inwardIssue.key,outwardIssue:r.outwardIssue.id||r.outwardIssue.key};r.comment&&(r.comment.body&&(s.comment=se(r.comment.body)),r.comment.visibility&&(s.visibility=r.comment.visibility));const n=await t.issues.link(s);return n?.data??n}catch(t){throw _t(t)}}},ve=j.object({issueId:j.string().min(1),file:j.string().min(1),mimeType:j.string().optional(),comment:j.string().optional()}),we={name:"jira-attach",inputSchema:ve,runTool:async(t,e)=>{try{const r=ve.parse(e),n=f.resolve(r.file),i=await s.readFile(n),o=f.basename(n),a=await t.issues.addAttachment({issueId:r.issueId,file:{name:o,content:i,mimeType:r.mimeType??"application/octet-stream"},comment:r.comment});return a?.data??a}catch(t){if(t&&t.code&&"string"==typeof t.code&&["ENOENT","EACCES"].includes(t.code))throw Error("Attachment file error: "+t.message);throw _t(t)}}},Se=j.object({issueId:j.string().min(1)}),je={name:"jira-attachment-list",inputSchema:Se,runTool:async(t,e)=>{try{const r=Se.parse(e),s=await t.issues.getAttachments({issueId:r.issueId});return s?.data??s}catch(t){throw _t(t)}}},xe=j.object({issueId:j.string().min(1),attachmentId:j.string().min(1)}),Ie={name:"jira-attachment-delete",inputSchema:xe,runTool:async(t,e)=>{try{const r=xe.parse(e);return await t.issues.deleteAttachment({issueId:r.issueId,attachmentId:r.attachmentId}),{success:!0,message:`Attachment ${e.attachmentId} deleted successfully`}}catch(t){throw _t(t)}}},ke=j.object({issueId:j.string().min(1),timeSpent:j.string().min(1),comment:j.string().optional(),author:j.object({accountId:j.string().min(1)}).optional(),startingOn:j.string().optional(),artifact:j.string().optional()}),Ae={name:"jira-worklog-add",inputSchema:ke,runTool:async(t,e)=>{try{const r=ke.parse(e),s={timeSpent:r.timeSpent};r.comment&&(s.comment=r.comment),r.author&&(s.author=r.author),r.startingOn&&(s.started=r.startingOn),r.artifact&&(s.artifact=r.artifact);const n=await t.issues.addWorklog({issueId:r.issueId,...s});return n?.data??n}catch(t){throw _t(t)}}},Ee={[$t.name]:{title:"Jira Issue Read",description:"Read a Jira issue with expandable fields and properties",annotations:{readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1}},[ce.name]:{title:"Jira Issue Update",description:"Update a Jira issue using fields, update ops, and property toggles",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}},[Pt.name]:{title:"Jira Issue Delete",description:"Delete a Jira issue and optionally remove its subtasks",annotations:{readOnlyHint:!1,destructiveHint:!0,idempotentHint:!1,openWorldHint:!0}},[oe.name]:{title:"Jira Issue Transition",description:"Transition a Jira issue while optionally adding a comment",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}},[le.name]:{title:"Jira Issue Assign",description:"Assign a Jira issue to a user or account",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}},[de.name]:{title:"Jira Issue Unassign",description:"Unassign the current owner from a Jira issue",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}},[he.name]:{title:"Jira Comment Add",description:"Add a comment to a Jira issue with optional visibility",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}},[ye.name]:{title:"Jira Comment List",description:"List comments on a Jira issue with pagination support",annotations:{readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1}},[be.name]:{title:"Jira Link Create",description:"Create an issue link relationship with optional comment",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}},[we.name]:{title:"Jira Attachment Add",description:"Attach a local file to a Jira issue",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}},[je.name]:{title:"Jira Attachment List",description:"List attachments on a Jira issue",annotations:{readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1}},[Ie.name]:{title:"Jira Attachment Delete",description:"Delete an attachment from a Jira issue",annotations:{readOnlyHint:!1,destructiveHint:!0,idempotentHint:!1,openWorldHint:!0}},[Ae.name]:{title:"Jira Worklog Add",description:"Log time spent on a Jira issue",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}}};async function Te(t){const e=o.for(Te);let r,s=null;try{r=(()=>{let t;try{const e=require("jira.js");t=e?.Version3Client||e.default?.Version3Client||e.default||e}catch(t){throw Error("Unable to require 'jira.js' \u2014 ensure it is installed as a dependency: "+t)}const{host:e,email:r,apiKey:s}=(()=>{const t=Ot(),e=Ct().filter(t=>t.required&&!t.value);if(e.length>0)throw new Jt(e);return{host:t.host,email:t.email,apiKey:t.apiKey}})();return new t({host:e,authentication:{basic:{email:r,apiToken:s}}})})()}catch(t){if(!(t instanceof Jt))return void e.warn("Skipping Jira tool registration; unable to create Jira client",{error:t});s=t,e.warn("Registering Jira tools without credentials; each tool will report configuration requirements.",{error:t})}const n=[$t,ce,Pt,oe,le,de,he,ye,be,we,je,Ie,Ae];for(const i of n){const n=Ee[i.name];if(n)try{await t.registerTool(i.name,{title:n.title,description:n.description,inputSchema:rt(i.inputSchema),annotations:n.annotations},async t=>{if(!r)throw s??Error("Jira client unavailable because credentials could not be loaded.");return i.runTool(r,t)}),e.info("Registered Jira tool "+i.name)}catch(t){e.error("Failed to register Jira tool "+i.name,{error:t})}}}async function Ne(t){await(async t=>{t.registerTool("decaf-server-info",{title:"Decaf MCP Server Info",description:"Return server metadata, version, and registered prompt names for diagnostics.",inputSchema:{},outputSchema:void 0,annotations:{readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1}},async()=>{const t=xt.map(t=>t.getName()).sort();return{content:[{type:"text",text:["Name: "+Nt.name,"Title: "+Nt.title,"Version: "+Nt.version,"Prompts: "+(t.join(", ")||"<none>")].join("\n")}]}})})(t);const e=o.for(Ne);try{await Te(t)}catch(t){e.error("Failed to register Jira tools",t)}}class Oe extends Q{setCb(t){return this.cb=t,this}setConfig(t){return this.config=t,this}setUriOtTemplate(t){return this.uriOrTemplate=t,this}constructor(t){super(t)}static get builder(){return new Oe}build(t){const e=this.hasErrors();if(e)throw Error(e.toString());try{const e="string"==typeof this.uriOrTemplate&&this.uriOrTemplate.includes("{")?new M(new $(this.uriOrTemplate),{list:void 0}):this.uriOrTemplate,r=Object.assign(this.config,{_meta:{}}),s=async(t,e)=>{const r=this.logFor(e);r.verbose(`Requesting resource ${this.name} from ${t.toString()}`);const s=await Promise.resolve(this.cb(t,e));return r.verbose(`Resource ${this.name} retrieved successfully.`),r.debug("Resource retrieval meta: "+JSON.stringify(s._meta)),s};return t.resource(this.name,e,r,s)}catch(t){throw o.for(this).error("Error registering resource "+this.name,t),t}}}y([b(),g("design:type",String)],Oe.prototype,"uriOrTemplate",void 0),y([b(),g("design:type",Function)],Oe.prototype,"cb",void 0),y([b(),g("design:type",Object)],Oe.prototype,"config",void 0);const Ce=dt()??h.join(__dirname,"..","assets"),He=h.join(Ce,"templates"),Je=h.join(Ce,"prompts"),_e=new WeakMap;class De extends a{get client(){const t=_e.get(this);if(!t)throw Error("Mcp server requires Mcp client");return t}constructor(){super()}async load(){const t=this.log.for(this.load);for(const e of xt)try{t.info("loading prompt "+e.getName());const r=e.build(this.client);t.verbose(`Loaded prompt ${r.title} from ${e.getName()} definition`)}catch(r){t.error("Failed to load prompt "+e.getName(),r)}try{await Ne(this.client),t.verbose("Registered built-in tools")}catch(e){t.error("Failed to register tools",e)}try{await(async(t,r)=>{r.info("Registering agent templates as resources...");const s=e.readdirSync(He).filter(t=>t.endsWith(".md"));for(const n of s){const s=h.basename(n,".md"),i=h.join(He,n),o=Oe.builder.setName(s).setTitle("Template: "+s).setDescription("Resource template for "+s).setUriOtTemplate("file:///"+i).setConfig({mimeType:"text/markdown",description:"Template for "+s}).setCb(async t=>{const r=e.readFileSync(t.pathname,"utf8");return{contents:[{uri:t.toString(),text:r,mimeType:"text/markdown"}],_meta:{}}});try{o.build(t),r.info("Registered template: "+s)}catch(t){r.error(`Failed to register template ${s}:`,t)}}r.info("Registering agent prompts...");const n=e.readdirSync(Je).filter(t=>t.endsWith(".md"));for(const s of n){const n=h.basename(s,".md"),i=h.join(Je,s),o=e.readFileSync(i,"utf8"),a=ht.builder.setName(n).setTitle("Prompt: "+n).setDescription("Dynamic prompt for "+n).setArgsSchema(j.object({})).setCb(async t=>({messages:[{role:"user",content:{type:"text",text:o}}],_meta:{}}));try{a.build(t),r.info("Registered prompt: "+n)}catch(t){r.error(`Failed to register prompt ${n}:`,t)}}})(this.client,t),t.verbose("Registered agent-specific assets")}catch(e){t.error("Failed to register agent assets",e)}}async boot(t="stdio"){let r=this.log;this.log.for(this.boot).info("McpServer booting..."),((t=o.get())=>{let r;try{r=(()=>{let t,r=__dirname;try{for(;r&&r!==h.parse(r).root;){const s=h.join(r,"node_modules");if(e.existsSync(s)&&e.statSync(s).isDirectory()){t=s;break}const n=h.dirname(r);if(n===r)break;r=n}}catch{}const s=[];if(t){const r=h.join(t,"@decaf-ts");try{if(e.existsSync(r)&&e.statSync(r).isDirectory()){const t=e.readdirSync(r);for(const n of t){const t=h.join(r,n);try{const r=h.join(t,"workdocs","assets","slogans.json");if(e.existsSync(r)&&e.statSync(r).isFile()){const t=e.readFileSync(r,"utf-8"),n=JSON.parse(t);if(Array.isArray(n))for(const t of n)"string"==typeof t&&t.trim().length>0&&s.push(t.trim())}}catch{}}}}catch{}}return 0===s.length?"Decaf: strongly brewed TypeScript.":s[Math.floor(Math.random()*s.length)]})()}catch{r="Decaf: strongly brewed TypeScript."}const s="# \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \n# ( ( \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \n# ) ) \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \n# [=======] \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \n# `-----\xb4 \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \n# \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \n# \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \n#".split("\n"),n=s.reduce((t,e)=>Math.max(t,e.length),0);s.push("# "+r.padStart(n-3)),s.forEach((e,r)=>{const s=K[r%K.length]||"",n=t.info.bind(t);try{n(m(e||"").raw(s).text)}catch{n((e||"")+"")}})})(this.log),"stdio"===t&&(o.setFactory(U),r=o.for(this.constructor.name));const s=((Array.isArray(Nt.icons)?Nt.icons:[Nt.icons])||[]).map(t=>{const e="string"==typeof t?.src?t.src:(t?.src??"")+"",r="string"==typeof t?.mimeType?t.mimeType:(t?.mimeType??"")+"";let s=[];return Array.isArray(t?.sizes)?s=t.sizes.map(t=>t+""):"string"==typeof t?.sizes&&(s=(t.sizes+"").split(",").map(t=>t.trim())),{src:e,mimeType:r,sizes:s}}),n={name:Nt.name,title:Nt.title,websiteUrl:Nt.websiteUrl,version:Nt.version,icons:s},i=new F(n,{instructions:"You are an AI assistant designed to help users with programming tasks related to the Decaf-TS framework. \nProvide clear, concise, and accurate information.\nIf you don't know the answer, admit it rather than making up information.\nAlways prioritize the user's intent and provide helpful suggestions when appropriate.\n",capabilities:{logging:{},tools:{},prompts:{}}});switch(((t,e)=>{_e.set(t,e)})(this,i),i.onerror=t=>{this.log.error("MCP instance onerror",t)},t){case"stdio":t=new B;break;case"http":t=new W({sessionIdGenerator:()=>q(),onsessioninitialized:t=>r.verbose("Session initialized: "+t),onsessionclosed:t=>r.verbose("Session closed: "+t),enableJsonResponse:!0,eventStore:void 0});break;default:if(!(a=t)||"object"!=typeof a||"function"!=typeof a.send&&"function"!=typeof a.close&&"function"!=typeof a.on)throw new T("Invalid transport type: "+t)}var a;try{this.log.info("Loading resources/prompts/tools..."),await this.load()}catch(t){throw this.log.error("Error loading resources/prompts/tools: "+t),t}await this.client.connect(t),r.info(`MCP Server connected via ${t.constructor.name} and running. Waiting for client connections...`)}}const Pe=(new t).command("start").option("--transport [String]","transport mode","stdio").description("starts decaf's mcp server").action(async t=>{const e=lt("package.json"),s=JSON.parse(r.readFileSync(e,"utf-8")),n=s.version,{transport:i}=t,o=(new L).for("mcp-server");if("stdio"!==i)throw Error("Unsupported transport mode: "+i);return o.info("Transport stdio"),o.debug(`running with options: ${JSON.stringify(t)} for ${s.name} version ${n}`),(new De).boot(i)});(new t).command("md-to-ast").description("pipes markdown to jira ast: `cat file.md` | npx decaf-mcp md-to-ast > ast.json").action(async t=>{const e=lt("package.json"),s=JSON.parse(r.readFileSync(e,"utf-8")),n=s.version;o.for("md-to-ast").debug(`running with options: ${JSON.stringify(t)} for ${s.name} version ${n}`);const i=se(await(async()=>{const t=[];for await(const e of process.stdin)t.push(Buffer.from(e));return Buffer.concat(t).toString("utf8")})(),{resolveMention:t=>({id:t,text:"@"+t}),resolveAttachment:t=>({id:t,collection:"attachments"})});process.stdout.write(JSON.stringify(i,null,2)+"\n")});const Re=(new t).name("mcp-server").command("mcp-server").description("decaf mcp server and agentic functionality");Re.addCommand(Pe),Re.parse(process.argv);
2
2
  //# sourceMappingURL=mcp-server.js.map
package/package.json CHANGED
@@ -112,5 +112,5 @@
112
112
  "uuid": "^13.0.0"
113
113
  },
114
114
  "license": "AGPL-3.0",
115
- "version": "1.2.7"
115
+ "version": "1.2.8"
116
116
  }