@decaf-ts/mcp-server 1.2.7 → 1.2.9

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 (45) 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 +1 -2
  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 +1 -3
  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 +2 -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.cjs.map +1 -1
  43. package/dist/mcp-server.js +1 -1
  44. package/dist/mcp-server.js.map +1 -1
  45. package/package.json +1 -1
Binary file
Binary file
@@ -1,2 +1 @@
1
- DCAF1|� g��t W��A8wYT��t ܫ X��*����%����z�� &�����������/��|Ǒ@D$��f�ӷ.������p�B�i�������D��{e,���`Tt���C�(gLc�Ǒc����]'���1��V��9��96���0Si��Uʯɋ>ߢ/ݩ�KVX������n��$�h�m!���bW��L�! 2g��U����TJsawFb�4�<x�3p���&��z�~������
2
- '��P��^?����:��.���Da�* �+��*�����5(�v9��j���M;�go[F��j&@��2.��c_�
1
+ DCAF1�d�.D�����^�1��3jk������o���n�d�c�TN*��6f����3#$/��7�k�W�t!���9?c6��I���X�sMR��9��9�B��!�R��m��<�N*��`����H�{���)�ɜ�㙪���^�)��w���P=���A_��X���-5< �}K���d���`/��.A���V=�=�ݭ��<����T3uV �h N�|��;��7�>V��.�:۟���Mb� i�)~u[����[��.�aW�f窷%ґI4ݺ���bjO�糮��ݛC* dZ��0oX���A869d
@@ -1,3 +1 @@
1
- DCAF1k9?sm6I��9�Ȯ�<���4��n�$/CR���U*��e\���_��!x��}��v -����r���̖�r�ǁ[�q@����A!��,� Gֿ!axCM��������VWX�ӑU�&с����ӱ�C+՛T��o�h�E i�bcN����Y���"F���W�Ф�� LD����������8Z���a����tb����
2
- 5ģ'�8�g��ḛb����}�E��%,���8{�#G :�2�+���hY��,�М�jg��bK$���{:=@ތ���~
3
- ��1���S�:�P{�ؓ���z���n�}�>\�ǚ����E��0A�b����%T��+�c
1
+ DCAF1����pgFm���ư� E��`yKb+��i[@ݢ�����w6�U=Y&����/��c(u�^�#=�g��=835 ��S��Yx��,[\5����LzJMYllzufSZ����B���赛[���p��=!uW���o٩��kA����pЁӁ˜%[/�ծY_�-���vGd%:��n.��[�����B��f�$�NC0nyy [d�'Ya���
Binary file
@@ -1,3 +1,2 @@
1
- DCAF1������j�͉J�ż�!&0������ ������Ց
2
- �`��rx�@U ��n���{j��H�C
3
- 7w��x�r�r��|�N���EE��l��>�몵���z�h*?p�X��h�|�6�5�W��w���#�Ž룪�lZ4�L$!z&��0��E���Lꓑk�� ƞ��8�&U��Y@6�</���̽Vc�
1
+ DCAF1D\������Վi�Ʌ.W��ƚ���j��Gm������! ^[FG A�ul��3.5j+�}mJc�
2
+ UƇ�<��?w�j�IK�D|7�����3��[
@@ -1 +1 @@
1
- DCAF1P(_���0F1a�}S�{-R��|��KV�Ho��Д_Dk(��t��0}� A�K�>O�{���wx
1
+ DCAF1KѬG�+9�ꦷ���%]Fq!��-�D<������.�"~*�Wlj�Pd���UiJ&YI��
@@ -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 k extends r.MiniLogger{log(e,t,s,n){const i=this.config("level");r.NumericLogLevels[i],r.NumericLogLevels[e]}}const z=(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 k(s,t)},E=["\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"}}));function le(){try{let e=process.argv[1]?n.dirname(n.resolve(process.argv[1])):process.cwd();for(;;){const r=n.join(e,"package.json");if(t.existsSync(r))return JSON.parse(t.readFileSync(r,"utf-8"));const s=n.dirname(e);if(s===e)break;e=s}}catch{}return{}}Object.assign(ce,{name:ce.getName()});const pe=le().version??"0.0.0",de=le().name??"unknown";l.Metadata.registerLibrary(de,pe);const ue={mcpId:"decaf",name:"decaf-ts mcp server",title:"Decaf-TS MCP Server",description:"Provides precise coding assistance for the decaf-ts framework",version:pe,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},me=r.LoggedEnvironment.accumulate(ue);function he(){const{host:e,email:t,apiKey:r,projectKey:s,issueType:n}=me.jira;return{host:e?.trim(),email:t?.trim(),apiKey:r?.trim(),projectKey:s?.trim(),issueType:n?.trim(),parentIssue:me.jira.parentIssue?.trim()}}function fe(){const e=he();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 ge(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(me);class ye extends Error{constructor(e){const t=fe(),r=(e=>{const t=fe();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(ge).join("\n")}`})(e);super(r),this.name="MissingJiraEnvironmentError",this.descriptors=t,this.missing=e,"function"==typeof Error.captureStackTrace&&Error.captureStackTrace(this,ye)}}function be(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 ve=a.z.object({issueId:a.z.string().min(1),deleteSubtasks:a.z.boolean().optional().default(!0)}),we={name:"jira-issue-delete",inputSchema:ve,runTool:async(e,t)=>{try{const r=ve.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 be(e)}}},Se=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()}),je={name:"jira-issue-read",inputSchema:Se,runTool:async(e,t)=>{try{const r=Se.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 be(e)}}};function xe(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 _e(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=ke(t.enableAtMentions?Ie(n,e,r):null,t.enableEmojiShortcodes?Ie(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 Ie(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 ke(e,t){return e?t&&e.index>t.index?t:e:t}function ze(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 Ee(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 Te(e){const t=((e??"")+"").toLowerCase().trim();return!t||"neutral"!==t&&"green"!==t&&"yellow"!==t&&"red"!==t&&"blue"!==t&&"purple"!==t?null:t}function Ae(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=Ne(s.children??[],e),i=xe(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&&Ce(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=ze(s)||"Status",t=Te(s.attributes?.color)??"neutral";r.push({type:"status",attrs:{text:e,color:t}});continue}if("textDirective"===s.type&&"emoji"===s.name){const e=He(s);r.push(De(e,t));continue}}else r.push({type:"hardBreak"});else r.push({type:"text",text:(s.value??"")+"",marks:[{type:"code"}]});else r.push(...Oe(Ae(s.children??[],t),{type:"strike"}));else r.push(...Oe(Ae(s.children??[],t),{type:"em"}));else r.push(...Oe(Ae(s.children??[],t),{type:"strong"}));else r.push(..._e((s.value??"")+"",t));return r.filter(e=>!("text"===e.type&&""===(e.text??"")))}function Oe(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 Ne(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(Ne(t.children??[],""));return r.join("")||t}function Ce(e,t){const r=(e??"").trim(),s=(t??"").trim();return r===s&&/^https?:\/\//i.test(s)}function He(e){return(e.children??[]).map(e=>"text"===e.type?(e.value??"")+"":"").join("").trim()||""}function De(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 Je(e){return e?"string"==typeof e?e:"text"===e.type||"inlineCode"===e.type?(e.value??"")+"":Array.isArray(e.children)?e.children.map(Je).join(""):"":""}function qe(e,t){if(!e?.type)return null;if((e=>"containerDirective"===e?.type&&"panel"===e?.name)(e))return((e,t)=>{const r=e.attributes??{},s=Ee(r.type)??"info",n="string"==typeof r.title?r.title:void 0,i=(e.children??[]).map(e=>qe(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:Me(e.depth??1,1,6)},content:Ae(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:Ae(e.children??[],t)}}case"blockquote":return{type:"blockquote",content:(e.children??[]).map(e=>qe(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=>qe(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=>qe(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:Ae(e.children??[],t)}]}))}))}))(e,t);case"leafDirective":return"status"===e.name?(e=>{const t=Te((e.attributes??{}).color)??"neutral";return{type:"paragraph",content:[{type:"status",attrs:{text:ze(e)||"Status",color:t}}]}})(e):"panel"===e.name?((e,t)=>{const r=e.attributes??{},s=Ee(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:Ae([{type:"text",value:ze(e)}],t)}]}})(e,t):Pe(e,t);default:return Pe(e,t)}}function Pe(e,t){if("drop"===t.unknownNodeStrategy)return null;const r=Je(e);return r?{type:"paragraph",content:[{type:"text",text:r}]}:null}function Me(e,t,r){const s=Number.isFinite(e)?Math.trunc(e):t;return Math.max(t,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 $e(e,t={}){const r={...Re,...t},s=e??"",n=h.unified().use(y).use(g).use(f),i=n.parse(s),o=n.runSync(i);return Le(o),((e,t)=>{const r=[];for(const s of e.children??[]){const e=qe(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 Le(e){if(!e||!Array.isArray(e.children))return;const t=[];for(const r of e.children)"definition"!==r?.type&&("html"!==r?.type?(Le(r),t.push(r)):t.push({type:"text",value:(r.value??"")+""}));e.children=t}const Fe=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()}),Be={name:"jira-issue-transition",inputSchema:Fe,runTool:async(e,t)=>{try{const r=Fe.parse(t),s={id:r.transitionId};r.fields&&(s.fields=r.fields),r.update&&(s.update=r.update),r.comment&&(s.comment={body:$e(r.comment)});const n=await e.issues.transition({issueId:r.issueId,transition:s});return n?.data??n}catch(e){throw be(e)}}},We=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)}),Ue={name:"jira-issue-update",inputSchema:We,runTool:async(e,t)=>{try{const r=We.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 be(e)}}},Ke=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)})])}),Ye={name:"jira-assign-issue",inputSchema:Ke,runTool:async(e,t)=>{try{const r=Ke.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 be(e)}}},Ve=a.z.object({issueId:a.z.string().min(1)}),Ge={name:"jira-unassign-issue",inputSchema:Ve,runTool:async(e,t)=>{try{const r=Ve.parse(t),s=await e.issues.assign({issueId:r.issueId,assignee:{accountId:"-1"}});return s?.data??s}catch(e){throw be(e)}}},Ze=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()}),Qe={name:"jira-comment-add",inputSchema:Ze,runTool:async(e,t)=>{try{const r=Ze.parse(t),s={body:$e(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 be(e)}}},Xe=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()}),et={name:"jira-comment-list",inputSchema:Xe,runTool:async(e,t)=>{try{const r=Xe.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 be(e)}}},tt=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()})}),rt={name:"jira-link-create",inputSchema:tt,runTool:async(e,t)=>{try{const r=tt.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=$e(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 be(e)}}},st=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()}),nt={name:"jira-attach",inputSchema:st,runTool:async(e,r)=>{try{const s=st.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 be(e)}}},it=a.z.object({issueId:a.z.string().min(1)}),ot={name:"jira-attachment-list",inputSchema:it,runTool:async(e,t)=>{try{const r=it.parse(t),s=await e.issues.getAttachments({issueId:r.issueId});return s?.data??s}catch(e){throw be(e)}}},at=a.z.object({issueId:a.z.string().min(1),attachmentId:a.z.string().min(1)}),ct={name:"jira-attachment-delete",inputSchema:at,runTool:async(e,t)=>{try{const r=at.parse(t);return await e.issues.deleteAttachment({issueId:r.issueId,attachmentId:r.attachmentId}),{success:!0,message:`Attachment ${t.attachmentId} deleted successfully`}}catch(e){throw be(e)}}},lt=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()}),pt={name:"jira-worklog-add",inputSchema:lt,runTool:async(e,t)=>{try{const r=lt.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 be(e)}}},dt={[je.name]:{title:"Jira Issue Read",description:"Read a Jira issue with expandable fields and properties",annotations:{readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1}},[Ue.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}},[we.name]:{title:"Jira Issue Delete",description:"Delete a Jira issue and optionally remove its subtasks",annotations:{readOnlyHint:!1,destructiveHint:!0,idempotentHint:!1,openWorldHint:!0}},[Be.name]:{title:"Jira Issue Transition",description:"Transition a Jira issue while optionally adding a comment",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}},[Ye.name]:{title:"Jira Issue Assign",description:"Assign a Jira issue to a user or account",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}},[Ge.name]:{title:"Jira Issue Unassign",description:"Unassign the current owner from a Jira issue",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}},[Qe.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}},[et.name]:{title:"Jira Comment List",description:"List comments on a Jira issue with pagination support",annotations:{readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1}},[rt.name]:{title:"Jira Link Create",description:"Create an issue link relationship with optional comment",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}},[nt.name]:{title:"Jira Attachment Add",description:"Attach a local file to a Jira issue",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}},[ot.name]:{title:"Jira Attachment List",description:"List attachments on a Jira issue",annotations:{readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1}},[ct.name]:{title:"Jira Attachment Delete",description:"Delete an attachment from a Jira issue",annotations:{readOnlyHint:!1,destructiveHint:!0,idempotentHint:!1,openWorldHint:!0}},[pt.name]:{title:"Jira Worklog Add",description:"Log time spent on a Jira issue",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}}};async function ut(e){const t=r.Logging.for(ut);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=he(),t=fe().filter(e=>e.required&&!e.value);if(t.length>0)throw new ye(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 ye))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=[je,Ue,we,Be,Ye,Ge,Qe,et,rt,nt,ot,ct,pt];for(const r of i){const i=dt[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 mt(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: "+me.name,"Title: "+me.title,"Version: "+me.version,"Prompts: "+(e.join(", ")||"<none>")].join("\n")}]}})})(e);const t=r.Logging.for(mt);try{await ut(e)}catch(e){t.error("Failed to register Jira tools",e)}}class ht 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 ht}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)],ht.prototype,"uriOrTemplate",void 0),i.__decorate([o.required(),i.__metadata("design:type",Function)],ht.prototype,"cb",void 0),i.__decorate([o.required(),i.__metadata("design:type",Object)],ht.prototype,"config",void 0);const ft=Y()??I.join(__dirname,"..","assets"),gt=I.join(ft,"templates"),yt=I.join(ft,"prompts"),bt=new WeakMap;class vt extends r.LoggedClass{get client(){const e=bt.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 mt(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(gt).filter(e=>e.endsWith(".md"));for(const s of r){const r=I.basename(s,".md"),n=I.join(gt,s),i=ht.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(yt).filter(e=>e.endsWith(".md"));for(const r of s){const s=I.basename(r,".md"),n=I.join(yt,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"){"stdio"===e&&r.Logging.setFactory(z);const t=r.Logging.for(this.constructor.name);t.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=E[r%E.length]||"",i=e.info.bind(e);try{i(s.style(t||"").raw(n).text)}catch{i((t||"")+"")}})})(t);const n=((Array.isArray(me.icons)?me.icons:[me.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:me.name,title:me.title,websiteUrl:me.websiteUrl,version:me.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)=>{bt.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 wt=(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 k).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 vt).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=$e(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 St=(new e.Command).name("mcp-server").command("mcp-server").description("decaf mcp server and agentic functionality");St.addCommand(wt),St.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