research`]},{env:`TASKMASTER_MODEL_FALLBACK`,path:[`models`,`fallback`]},{env:`TASKMASTER_RESPONSE_LANGUAGE`,path:[`custom`,`responseLanguage`]}];static RUNTIME_STATE_MAPPINGS=[{env:`TASKMASTER_TAG`,path:[`activeTag`],isRuntimeState:!0}];mappings;constructor(t){this.mappings=t||[...e.DEFAULT_MAPPINGS,...e.RUNTIME_STATE_MAPPINGS]}loadConfig(){let e={};for(let t of this.mappings){if(t.isRuntimeState)continue;let n=process.env[t.env];if(n){if(t.validate&&!t.validate(n)){this.logger.warn(`Invalid value for ${t.env}: ${n}`);continue}this.setNestedProperty(e,t.path,n)}}return e}getRuntimeState(){let e={};for(let t of this.mappings){if(!t.isRuntimeState)continue;let n=process.env[t.env];if(n){let r=t.path[t.path.length-1];e[r]=n}}return e}setNestedProperty(e,t,n){let r=t[t.length-1],i=t.slice(0,-1),a=e;for(let e of i)a[e]||(a[e]={}),a=a[e];a[r]=n}hasEnvVar(e){return e in process.env&&process.env[e]!==void 0}getAllTaskmasterEnvVars(){let e={};for(let[t,n]of Object.entries(process.env))t.startsWith(`TASKMASTER_`)&&n!==void 0&&(e[t]=n);return e}addMapping(e){this.mappings.push(e)}getMappings(){return[...this.mappings]}},ut=class{stateFilePath;currentState;logger=x(`RuntimeStateManager`);constructor(e){this.stateFilePath=t.join(e,`.taskmaster`,`state.json`),this.currentState={currentTag:O.TAGS.DEFAULT_TAG}}async loadState(){try{let e=await m.readFile(this.stateFilePath,`utf-8`),t=JSON.parse(e),n={currentTag:t.currentTag||t.activeTag||O.TAGS.DEFAULT_TAG,lastUpdated:t.lastUpdated,metadata:t.metadata};return process.env.TASKMASTER_TAG&&(n.currentTag=process.env.TASKMASTER_TAG),this.currentState=n,n}catch(e){return e.code===`ENOENT`?(this.logger.debug(`No state.json found, using default state`),process.env.TASKMASTER_TAG&&(this.currentState.currentTag=process.env.TASKMASTER_TAG),this.currentState):(this.logger.warn(`Failed to load state file:`,e.message),this.currentState)}}async saveState(){let e=t.dirname(this.stateFilePath);try{await m.mkdir(e,{recursive:!0});let t={...this.currentState,lastUpdated:new Date().toISOString()};await m.writeFile(this.stateFilePath,JSON.stringify(t,null,2),`utf-8`)}catch(e){throw new y(`Failed to save runtime state`,v.CONFIG_ERROR,{statePath:this.stateFilePath},e)}}getCurrentTag(){return this.currentState.currentTag}async setCurrentTag(e){this.currentState.currentTag=e,await this.saveState()}getState(){return{...this.currentState}}async updateMetadata(e){this.currentState.metadata={...this.currentState.metadata,...e},await this.saveState()}async clearState(){try{await m.unlink(this.stateFilePath)}catch(e){if(e.code!==`ENOENT`)throw e}this.currentState={currentTag:O.TAGS.DEFAULT_TAG}}},dt=class e{projectRoot;config={};initialized=!1;loader;merger;stateManager;persistence;envProvider;static async create(t){let n=new e(t);return await n.initialize(),n}constructor(e){this.projectRoot=e,this.loader=new ot(e),this.merger=new st,this.stateManager=new ut(e),this.persistence=new ct(e),this.envProvider=new lt}async initialize(){if(this.initialized)return;this.merger.clearSources(),this.merger.addSource({name:`defaults`,config:this.loader.getDefaultConfig(),precedence:k.DEFAULTS});let e=await this.loader.loadGlobalConfig();e&&this.merger.addSource({name:`global`,config:e,precedence:k.GLOBAL});let t=await this.loader.loadLocalConfig();t&&this.merger.addSource({name:`local`,config:t,precedence:k.LOCAL});let n=this.envProvider.loadConfig();Object.keys(n).length>0&&this.merger.addSource({name:`environment`,config:n,precedence:k.ENVIRONMENT}),this.config=this.merger.merge(),await this.stateManager.loadState(),this.initialized=!0}getConfig(){return this.config}getStorageConfig(){let e=this.config.storage,t=e?.type||`auto`,n=e?.basePath??this.projectRoot;return t===`api`||t===`auto`?{type:t,basePath:n,apiEndpoint:e?.apiEndpoint,apiAccessToken:e?.apiAccessToken,apiConfigured:!!(e?.apiEndpoint||e?.apiAccessToken)}:{type:t,basePath:n,apiConfigured:!1}}getModelConfig(){return this.config.models||{main:O.MODELS.MAIN,fallback:O.MODELS.FALLBACK}}getResponseLanguage(){return this.config.custom?.responseLanguage||`English`}getProjectRoot(){return this.projectRoot}isApiExplicitlyConfigured(){return this.getStorageConfig().type===`api`}getActiveTag(){return this.stateManager.getCurrentTag()}async setActiveTag(e){await this.stateManager.setCurrentTag(e)}async updateConfig(e){Object.assign(this.config,e),await this.persistence.saveConfig(this.config),this.initialized=!1,await this.initialize()}async setResponseLanguage(e){this.config.custom||(this.config.custom={}),this.config.custom.responseLanguage=e,await this.persistence.saveConfig(this.config)}async saveConfig(){await this.persistence.saveConfig(this.config,{createBackup:!0,atomic:!0})}async reset(){await this.persistence.deleteConfig(),await this.stateManager.clearState(),this.initialized=!1,this.config={},await this.initialize()}getConfigSources(){return this.merger.getSources()}},A=class{projectPath;git;constructor(e){if(!e)throw Error(`Project path is required`);if(!c.isAbsolute(e))throw Error(`Project path must be an absolute path`);this.projectPath=c.normalize(e),this.git=re(this.projectPath)}async isGitRepository(){try{let e=c.join(this.projectPath,`.git`);if(await ne.pathExists(e))return!0;try{return await this.git.revparse([`--git-dir`]),!0}catch{return!1}}catch{return!1}}async validateGitInstallation(){try{await this.git.version()}catch(e){let t=e instanceof Error?e.message:String(e);throw Error(`Git is not installed or not accessible: ${t}`)}}async getGitVersion(){let e=await this.git.version();return{major:e.major,minor:e.minor,patch:typeof e.patch==`string`?parseInt(e.patch):e.patch||0,agent:e.agent}}async getRepositoryRoot(){try{let e=await this.git.revparse([`--show-toplevel`]);return c.normalize(e.trim())}catch{throw Error(`not a git repository: ${this.projectPath}`)}}async validateRepository(){if(!await this.isGitRepository())throw Error(`not a git repository: ${this.projectPath}`);try{await this.git.status()}catch(e){let t=e instanceof Error?e.message:String(e);throw Error(`Repository validation failed: ${t}`)}}async ensureGitRepository(){if(!await this.isGitRepository())throw Error(`not a git repository: ${this.projectPath}\nPlease run this command from within a git repository, or initialize one with 'git init'.`)}async isWorkingTreeClean(){return(await this.git.status()).isClean()}async getStatus(){return await this.git.status()}async hasUncommittedChanges(){return!(await this.git.status()).isClean()}async hasStagedChanges(){return(await this.git.status()).staged.length>0}async hasUntrackedFiles(){return(await this.git.status()).not_added.length>0}async getStatusSummary(){let e=await this.git.status(),t=e.staged.length,n=e.modified.length,r=e.deleted.length,i=e.not_added.length,a=t+n+r+i;return{isClean:e.isClean(),staged:t,modified:n,deleted:r,untracked:i,totalChanges:a}}async ensureCleanWorkingTree(){if(!(await this.git.status()).isClean()){let e=await this.getStatusSummary();throw Error(`working tree is not clean: ${this.projectPath}\nStaged: ${e.staged}, Modified: ${e.modified}, Deleted: ${e.deleted}, Untracked: ${e.untracked}\nPlease commit or stash your changes before proceeding.`)}}async getCurrentBranch(){return(await this.git.status()).current||`HEAD`}async listBranches(){let e=await this.git.branchLocal();return Object.keys(e.branches)}async branchExists(e){return(await this.listBranches()).includes(e)}async createBranch(e,t={}){if(await this.branchExists(e))throw Error(`branch already exists: ${e}`);t.checkout&&await this.ensureCleanWorkingTree(),await this.git.branch([e]),t.checkout&&await this.git.checkout(e)}async checkoutBranch(e,t={}){if(!await this.branchExists(e))throw Error(`branch does not exist: ${e}`);t.force||await this.ensureCleanWorkingTree();let n=t.force?[`-f`,e]:[e];await this.git.checkout(n)}async createAndCheckoutBranch(e){if(await this.ensureCleanWorkingTree(),await this.branchExists(e))throw Error(`branch already exists: ${e}`);await this.git.checkoutLocalBranch(e)}async deleteBranch(e,t={}){if(!await this.branchExists(e))throw Error(`branch does not exist: ${e}`);if(await this.getCurrentBranch()===e)throw Error(`cannot delete current branch: ${e}`);let n=t.force?[`-D`,e]:[`-d`,e];await this.git.branch(n)}async stageFiles(e){await this.git.add(e)}async unstageFiles(e){await this.git.reset([`HEAD`,`--`,...e])}async createCommit(e,t={}){if(t.enforceNonDefaultBranch&&!t.force){let e=await this.getCurrentBranch();if([`main`,`master`,`develop`].includes(e))throw Error(`cannot commit to default branch: ${e}\nPlease create a feature branch or use force option.`)}if(!t.allowEmpty&&!await this.hasStagedChanges())throw Error(`no staged changes to commit`);let n=[`commit`];if(n.push(`-m`,e),t.metadata){n.push(`-m`,``);for(let[e,r]of Object.entries(t.metadata))n.push(`-m`,`[${e}:${r}]`)}n.push(`--no-gpg-sign`),t.allowEmpty&&n.push(`--allow-empty`),await this.git.raw(n)}async getCommitLog(e={}){let t={format:{hash:`%H`,date:`%ai`,message:`%B`,author_name:`%an`,author_email:`%ae`}};return e.maxCount&&(t.maxCount=e.maxCount),[...(await this.git.log(t)).all]}async getLastCommit(){return(await this.git.log({maxCount:1,format:{hash:`%H`,date:`%ai`,message:`%B`,author_name:`%an`,author_email:`%ae`}})).latest}async getDefaultBranch(){let e=await this.getCurrentBranch(),t=[`main`,`master`,`develop`];if(t.includes(e))return e;let n=await this.listBranches();for(let e of t)if(n.includes(e))return e;return`main`}async isDefaultBranch(e){return[`main`,`master`,`develop`].includes(e)}async isOnDefaultBranch(){let e=await this.getCurrentBranch();return await this.isDefaultBranch(e)}async ensureNotOnDefaultBranch(){if(await this.isOnDefaultBranch()){let e=await this.getCurrentBranch();throw Error(`currently on default
research`,`research-save`,`update-subtask`,`update-task`,`update-tasks`],Yn=`.taskmaster`,Xn=`.taskmaster/tasks`,Zn=`.taskmaster/docs`,Qn=`.taskmaster/reports`,$n=`.taskmaster/templates`,er=`.taskmaster/config.json`,tr=`.taskmaster/state.json`,z=`.taskmasterconfig`,nr=`.taskmaster/reports/task-complexity-report.json`,rr=`.taskmaster/docs/prd.txt`,ir=`.taskmaster/templates/example_prd.txt`,ar=`.taskmaster/tasks/tasks.json`,or=`tasks/tasks.json`,sr=`.env.example`,cr=`.gitignore`;let lr=!1;const ur={maxRetries:5,retryDelay:100,staleLockAge:1e4};function dr(e){if(typeof SharedArrayBuffer<`u`&&typeof Atomics<`u`&&typeof Atomics.wait==`function`)try{let t=new SharedArrayBuffer(4),n=new Int32Array(t);Atomics.wait(n,0,0,e);return}catch{}let t=Date.now()+e;for(;Date.now()<t;);}function fr(e,t,n={}){let{createIfMissing:r=!1}=n,i=c.dirname(e);if(s.existsSync(i)||s.mkdirSync(i,{recursive:!0}),r)try{s.writeFileSync(e,`{}`,{flag:`wx`})}catch(e){if(e.code!==`EEXIST`)throw e}let a=`${e}.lock`,{maxRetries:o,retryDelay:l,staleLockAge:u}=ur,d=!1;for(let e=0;e<o;e++)try{let e=JSON.stringify({pid:process.pid,timestamp:Date.now()});s.writeFileSync(a,e,{flag:`wx`}),d=!0;break}catch(t){if(t.code===`EEXIST`){try{let e=s.statSync(a);if(Date.now()-e.mtimeMs>u){let e=`${a}.stale.${process.pid}.${Date.now()}`;try{s.renameSync(a,e);try{s.unlinkSync(e)}catch{}continue}catch{}}}catch(e){if(e.code===`ENOENT`)continue;throw e}e<o-1&&dr(l*2**e)}else throw t}if(!d)throw Error(`Failed to acquire lock on ${e} after ${o} attempts`);try{return t()}finally{try{s.unlinkSync(a)}catch(t){U(`warn`,`Failed to release lock for ${e}: ${t.message}`)}}}function B(e,t=null,n=null){if(t?.env?.[e])return t.env[e];if(n){let t=c.join(n,`.env`);if(s.existsSync(t))try{let n=s.readFileSync(t,`utf-8`),r=ve.parse(n);if(r&&r[e])return r[e]}catch(e){U(`warn`,`Could not read or parse ${t}: ${e.message}`)}}if(process.env[e])return process.env[e]}function V(e=process.cwd(),t=[`package.json`,`pyproject.toml`,`.git`,z]){let n=c.resolve(e),r=c.parse(n).root;for(;n!==r;){if(t.some(e=>{let t=c.join(n,e);return s.existsSync(t)}))return n;n=c.dirname(n)}return t.some(e=>{let t=c.join(r,e);return s.existsSync(t)})?r:null}const H={debug:0,info:1,warn:2,error:3,success:1};function pr(){lr=!0}function mr(){lr=!1}function hr(){return lr}function U(e,...t){if(hr())return;let n=`info`;try{n=gi()||`info`}catch{n=`info`}let r={debug:i.gray(`[DEBUG]`),info:i.blue(`[INFO]`),warn:i.yellow(`[WARN]`),error:i.red(`[ERROR]`),success:i.green(`[SUCCESS]`)},a=H.hasOwnProperty(e)?e:`info`;if(H[a]>=(H[n]??H.info)){let e=r[a]||``,n=t.map(e=>typeof e==`object`?JSON.stringify(e):e).join(` `);console.log(`${e} ${n}`)}}function gr(e){if(!e||typeof e!=`object`)return!1;for(let t in e)if(e.hasOwnProperty(t)&&typeof e[t]==`object`&&Array.isArray(e[t].tasks))return!0;return!1}function W(e){Array.isArray(e)&&e.forEach(e=>{if(e.id!==void 0){let t=parseInt(e.id,10);!isNaN(t)&&t>0&&(e.id=t)}Array.isArray(e.subtasks)&&e.subtasks.forEach(e=>{if(e.id!==void 0)if(typeof e.id==`string`&&e.id.includes(`.`)){let t=e.id.split(`.`);e.id=parseInt(t[t.length-1],10)}else{let t=parseInt(e.id,10);!isNaN(t)&&t>0&&(e.id=t)}})})}function _r(t,n=null,r=null){let i=!1;try{i=$()}catch{}if(i&&console.log(`readJSON called with: ${t}, projectRoot: ${n}, tag: ${r}`),!t)return null;let a;try{a=JSON.parse(s.readFileSync(t,`utf8`)),i&&console.log(`Successfully read JSON from ${t}`)}catch(e){return i&&console.log(`Failed to read JSON from ${t}: ${e.message}`),null}if(!t.includes(`tasks.json`)||!a)return i&&console.log(`File is not tasks.json or data is null, returning as-is`),a;if(Array.isArray(a.tasks)&&!a._rawTaggedData&&!gr(a)){i&&console.log(`File is in legacy format, performing migration...`),W(a.tasks);let r={master:{tasks:a.tasks,metadata:a.metadata||{created:new Date().toISOString(),updated:new Date().toISOString(),description:`Tasks for master context`}}};try{if(Sr(t,r),i&&console.log(`Successfully migrated legacy format to tagged format`),vr(t),n)try{e(n,t)}catch{}xr(t)}catch(e){i&&console.log(`Error writing migrated data: ${e.message}`)}a=r}if(typeof a==`object`&&!a.tasks){for(let e in i&&console.log(`File is in tagged format, resolving tag...`),a)if(a.hasOwnProperty(e)&&typeof a[e]==`object`&&a[e].tasks)try{Rr(a[e],{description:`Tasks for ${e} context`,skipUpdate:!0})}catch(t){i&&console.log(`Failed to ensure metadata for tag ${e}: ${t.message}`)}let o=JSON.parse(JSON.stringify(a));for(let e in o)o[e]&&Array.isArray(o[e].tasks)&&W(o[e].tasks);if(n)try{e(n,t)}catch{}try{let e=`master`;try{if(r)e=r;else if(n)e=Fr({projectRoot:n});else{let n=V(c.dirname(t));n&&(e=Fr({projectRoot:n}))}}catch(e){i&&console.log(`Tag resolution failed, using master: ${e.message}`)}i&&console.log(`Resolved tag: ${e}`);let s=a[e];if(s&&s.tasks){W(s.tasks);let t={...s,tag:e,_rawTaggedData:o};return i&&console.log(`Returning data for tag '${e}' with ${s.tasks.length} tasks`),t}else{let t=a.master;return t&&t.tasks?(W(t.tasks),i&&console.log(`Tag '${e}' not found, falling back to master with ${t.tasks.length} tasks`),{...t,tag:`master`,_rawTaggedData:o}):(i&&console.log(`No valid tag data found, returning empty structure`),{tasks:[],tag:`master`,_rawTaggedData:o})}}catch(e){i&&console.log(`Error during tag resolution: ${e.message}`);let t=a.master;return t&&t.tasks?(W(t.tasks),{...t,_rawTaggedData:o}):{tasks:[],_rawTaggedData:o}}}return i&&console.log(`File format not recognized, returning as-is`),a}function vr(e){try{let t=V(c.dirname(e))||c.dirname(e),n=c.join(t,`.taskmaster`,`config.json`);s.existsSync(n)&&yr(n);let r=c.join(t,`.taskmaster`,`state.json`);s.existsSync(r)||br(r),$()&&U(`debug`,`Complete tag migration performed for project: ${t}`)}catch(e){$()&&U(`warn`,`Error during complete tag migration: ${e.message}`)}}function yr(e){try{let t=s.readFileSync(e,`utf8`),n=JSON.parse(t);if(!n)return;let r=!1;n.global||={},n.global.defaultTag||(n.global.defaultTag=`master`,r=!0),r&&(s.writeFileSync(e,JSON.stringify(n,null,2),`utf8`),process.env.TASKMASTER_DEBUG===`true`&&console.log(`[DEBUG] Updated config.json with tagged task system settings`))}catch(e){process.env.TASKMASTER_DEBUG===`true`&&console.warn(`[WARN] Error migrating config.json: ${e.message}`)}}function br(e){try{let t={currentTag:`master`,lastSwitched:new Date().toISOString(),branchTagMapping:{},migrationNoticeShown:!1};s.writeFileSync(e,JSON.stringify(t,null,2),`utf8`),process.env.TASKMASTER_DEBUG===`true`&&console.log(`[DEBUG] Created initial state.json for tagged task system`)}catch(e){process.env.TASKMASTER_DEBUG===`true`&&console.warn(`[WARN] Error creating state.json: ${e.message}`)}}function xr(e){try{let t=c.dirname(c.dirname(e)),n=c.join(t,`.taskmaster`,`state.json`);s.existsSync(n)||br(n);try{let e=s.readFileSync(n,`utf8`),t=JSON.parse(e)||{};t.migrationNoticeShown===void 0&&(t.migrationNoticeShown=!1,s.writeFileSync(n,JSON.stringify(t,null,2),`utf8`))}catch(e){process.env.TASKMASTER_DEBUG===`true`&&console.warn(`[WARN] Error updating state for migration notice: ${e.message}`)}}catch(e){process.env.TASKMASTER_DEBUG===`true`&&console.warn(`[WARN] Error marking migration for notice: ${e.message}`)}}function Sr(e,t,n=null,r=null){let i=process.env.TASKMASTER_DEBUG===`true`;try{fr(e,()=>{let a=t;if(t&&!t._rawTaggedData&&n&&Array.isArray(t.tasks)&&!gr(t)){let o=r||Pr(n);i&&console.log(`writeJSON: Detected resolved tag data missing _rawTaggedData. Re-reading raw data to prevent data loss for tag '${o}'.`);let c={};try{c=JSON.parse(s.readFileSync(e,`utf8`))}catch(e){i&&console.log(`writeJSON: Could not read existing file, starting fresh: ${e.message}`)}a={...c,[o]:{metadata:{...c[o]?.metadata||{},...t.metadata||{}},tasks:t.tasks}}}else if(t&&t._rawTaggedData&&n){let o=r||Pr(n),c;try{c=JSON.parse(s.readFileSync(e,`utf8`))}catch(e){c=t._rawTaggedData,i&&console.log(`writeJSON: Using _rawTaggedData as fallback: ${e.message}`)}let{_rawTaggedData:l,tag:u,...d}=t;a={...c,[o]:d},i&&console.log(`writeJSON: Merging resolved data back into tag '${o}'`)}let o=a;if(o&&typeof o==`object`){let{_rawTaggedData:e,tag:t,...n}=o;if(o=n,typeof o==`object`&&!Array.isArray(o)){let e={};for(let[t,n]of Object.entries(o))if(n&&typeof n==`object`&&Array.isArray(n.tasks)){let{created:r,description:i,...a}=n;a.metadata||={},r&&!a.metadata.created&&(a.metadata.created=r),i&&!a.metadata.description&&(a.metadata.description=i),e[t]=a}else e[t]=n;o=e}}let c=`${e}.tmp.${process.pid}`;try{s.writeFileSync(c,JSON.stringify(o,null,2),`utf8`),s.renameSync(c,e)}catch(e){try{s.existsSync(c)&&s.unlinkSync(c)}catch{}throw e}i&&console.log(`writeJSON: Successfully wrote to ${e}`)},{createIfMissing:!0})}catch(t){throw U(`error`,`Error writing JSON file ${e}:`,t.message),i&&U(`error`,`Full error details:`,t),t}}function Cr(e=null){let t=!1;try{t=$()}catch{t=!1}try{let n;if(e)n=e;else{let e=c.join(process.cwd(),nr),t=c.join(process.cwd(),`scripts/task-complexity-report.json`);n=s.existsSync(e)?e:t}if(!s.existsSync(n))return t&&U(`debug`,`Complexity report not found at ${n}`),null;let r=_r(n);return t&&U(`debug`,`Successfully read complexity report from ${n}`),r}catch(e){return t&&U(`error`,`Error reading complexity report: ${e.message}`),null}}function wr(e,t){return!e||!e.complexityAnalysis||!Array.isArray(e.complexityAnalysis)?null:e.complexityAnalysis.find(e=>e.taskId===t)}function Tr(e,t){let n;n=e.isSubtask?e.parentTask.id:e.parentId?e.parentId:e.id;let r=wr(t,n);r&&(e.complexityScore=r.complexityScore)}function Er(e,t){if(!t||!e||!Array.isArray(e))return!1;if(typeof t==`string`&&t.includes(`.`)){let[n,r]=t.split(`.`).map(e=>parseInt(e,10)),i=e.find(e=>e.id===n);return!i||!i.subtasks?!1:i.subtasks.some(e=>e.id===r)}let n=parseInt(t,10);return e.some(e=>e.id===n)}function Dr(e){return typeof e==`string`&&e.includes(`.`)?e:typeof e==`number`?e.toString():e}function Or(e,t,n=null,r=null){if(!t||!e||!Array.isArray(e))return{task:null,originalSubtaskCount:null};if(typeof t==`string`&&t.includes(`.`)){let[r,i]=t.split(`.`).map(e=>parseInt(e,10)),a=e.find(e=>e.id===r);if(!a||!a.subtasks)return{task:null,originalSubtaskCount:null,originalSubtasks:null};let o=a.subtasks.find(e=>e.id===i);return o&&(o.parentTask={id:a.id,title:a.title,status:a.status},o.isSubtask=!0),o&&n&&Tr(o,n),{task:o||null,originalSubtaskCount:null,originalSubtasks:null}}let i=null,a=null,o=null,s=parseInt(t,10),c=e.find(e=>e.id===s)||null;if(!c)return{task:null,originalSubtaskCount:null,originalSubtasks:null};if(i=c,r&&c.subtasks&&Array.isArray(c.subtasks)){o=[...c.subtasks],a=c.subtasks.length;let e={...c};e.subtasks=c.subtasks.filter(e=>e.status&&e.status.toLowerCase()===r.toLowerCase()),i=e}return i&&n&&Tr(i,n),{task:i,originalSubtaskCount:a,originalSubtasks:o}}function kr(e,t){return!e||e.length<=t?e:`${e.slice(0,t-3)}...`}function Ar(e){return Array.isArray(e)?e.length===0:typeof e==`object`&&e?Object.keys(e).length===0:!1}function jr(e,t,n=new Set,r=new Set,i=[]){n.add(e),r.add(e),i.push(e);let a=[],o=t.get(e)||[];for(let e of o)if(n.has(e)){if(r.has(e)){let t=i.indexOf(e);i.slice(t),a.push(e)}}else{let o=jr(e,t,n,r,[...i]);a.push(...o)}return r.delete(e),a}function Mr(e,t,n={}){let{maxDepth:r=50,includeSelf:i=!1,direction:a=`forward`,logger:o=null}=n,s=new Set,c=new Set;function l(e){if(typeof e==`string`){if(e.includes(`.`))return e;let t=parseInt(e,10);return isNaN(t)?e:t}return e}function u(e,n=0){if(n>=r){let t=`Maximum recursion depth (${r}) reached for task ${e}`;o&&typeof o.warn==`function`?o.warn(t):U!==void 0&&U.warn?U.warn(t):console.warn(t);return}if(c.has(e))return;c.add(e);let a=t.find(t=>t.id===e);!a||!Array.isArray(a.dependencies)||a.dependencies.forEach(t=>{let r=l(t);r==null||!i&&r===e||(s.add(r),u(r,n+1))})}function d(e,n=0){if(n>=r){let t=`Maximum recursion depth (${r}) reached for task ${e}`;o&&typeof o.warn==`function`?o.warn(t):U!==void 0&&U.warn?U.warn(t):console.warn(t);return}c.has(e)||(c.add(e),t.forEach(t=>{if(t.dependencies&&Array.isArray(t.dependencies)&&t.dependencies.some(t=>l(t)===e)){if(t.id==null||!i&&t.id===e)return;s.add(t.id),d(t.id,n+1)}}))}let f=a===`reverse`?d:u;return e.forEach(e=>{e&&e.id&&f(e.id)}),Array.from(s)}function Nr(e,t){if(!e||e.length===0)return null;let n={timestamp:new Date().toISOString(),userId:e[0].userId,commandName:t,modelUsed:`Multiple`,providerName:`Multiple`,inputTokens:0,outputTokens:0,totalTokens:0,totalCost:0,currency:e[0].currency||`USD`},r=new Set,i=new Set,a=new Set;return e.forEach(e=>{n.inputTokens+=e.inputTokens||0,n.outputTokens+=e.outputTokens||0,n.totalCost+=e.totalCost||0,r.add(e.modelUsed),i.add(e.providerName),a.add(e.currency||`USD`)}),n.totalTokens=n.inputTokens+n.outputTokens,n.totalCost=parseFloat(n.totalCost.toFixed(6)),r.size===1&&(n.modelUsed=[...r][0]),i.size===1&&(n.providerName=[...i][0]),a.size>1?n.currency=`Multiple`:a.size===1&&(n.currency=[...a][0]),n}function Pr(e){if(!e)throw Error(`projectRoot is required for getCurrentTag`);try{let t=c.join(e,`.taskmaster`,`state.json`);if(s.existsSync(t)){let e=s.readFileSync(t,`utf8`),n=JSON.parse(e);if(n&&n.currentTag)return n.currentTag}}catch{}try{let t=c.join(e,`.taskmaster`,`config.json`);if(s.existsSync(t)){let e=s.readFileSync(t,`utf8`),n=JSON.parse(e);if(n&&n.global&&n.global.defaultTag)return n.global.defaultTag}}catch{}return`master`}function Fr(e={}){let{projectRoot:t,tag:n}=e;if(!t)throw Error(`projectRoot is required for resolveTag`);return n||Pr(t)}function Ir(e,t){return!e||!t?[]:e[t]&&e[t].tasks&&Array.isArray(e[t].tasks)?e[t].tasks:[]}function Lr(e){let t=[];for(let n of e)if(t.push({...n,searchableId:n.id.toString(),isSubtask:!1}),n.subtasks&&n.subtasks.length>0)for(let e of n.subtasks)t.push({...e,searchableId:`${n.id}.${e.id}`,isSubtask:!0,parentId:n.id,parentTitle:n.title,title:`${e.title} (subtask of: ${n.title})`,description:`${e.description} [Parent: ${n.description}]`});return t}function Rr(e,t={}){if(!e||typeof e!=`object`)throw Error(`tagObj must be a valid object`);let n=new Date().toISOString();return e.metadata?(e.metadata.created||(e.metadata.created=n),t.skipUpdate||(e.metadata.updated=n),t.description&&!e.metadata.description&&(e.metadata.description=t.description)):e.metadata={created:n,updated:n,...t.description?{description:t.description}:{}},e}function zr(){return{info:(e,...t)=>U(`info`,e,...t),warn:(e,...t)=>U(`warn`,e,...t),error:(e,...t)=>U(`error`,e,...t),debug:(e,...t)=>U(`debug`,e,...t),success:(e,...t)=>U(`success`,e,...t)}}function G(e=null){return e||zr()}function K(e){return vn(e)}function q(e=process.cwd()){return _n(e)}function Br(e=null,t=null,n=null){let r=G(n),i=t?.projectRoot||q();if(!i)return r.warn?.(`Could not determine project root directory`),null;let a=K(i);if(e){let t=c.isAbsolute(e)?e:c.resolve(a,e);if(s.existsSync(t))return r.info?.(`Using explicit tasks path: ${t}`),t;r.warn?.(`Explicit tasks path not found: ${t}, trying fallbacks`)}let o=[c.join(a,ar),c.join(a,or)];for(let e of o)if(s.existsSync(e))return r.info?.(`Found tasks file at: ${e}`),e.includes(`tasks/tasks.json`)&&!e.includes(`.taskmaster`)?r.warn?.(`⚠️  DEPRECATION WARNING: Found tasks.json in legacy location '${e}'. Please migrate to the new .taskmaster directory structure. Run 'task-master migrate' to automatically migrate your project.`):e.endsWith(`tasks.json`)&&!e.includes(`.taskmaster`)&&!e.includes(`tasks/`)&&r.warn?.(`⚠️  DEPRECATION WARNING: Found tasks.json in legacy root location '${e}'. Please migrate to the new .taskmaster directory structure. Run 'task-master migrate' to automatically migrate your project.`),e;return r.warn?.(`No tasks.json found in project: ${a}`),null}function Vr(e=null,t=null,n=null){let r=G(n);if(e){let t=process.env.TASKMASTER_ORIGINAL_CWD||process.cwd(),n=c.isAbsolute(e)?e:c.resolve(t,e);if(s.existsSync(n))return r.info?.(`Using explicit PRD path: ${n}`),n;r.warn?.(`Explicit PRD path not found: ${n}, trying fallbacks`)}let i=t?.projectRoot||q();if(!i)return r.warn?.(`Could not determine project root directory`),null;let a=K(i),o=[Zn,`scripts/`,``],l=[`PRD.md`,`prd.md`,`PRD.txt`,`prd.txt`];for(let e of o)for(let t of l){let n=c.join(a,e,t);if(s.existsSync(n))return r.info?.(`Found PRD document at: ${n}`),(e===`scripts/`||e===``)&&r.warn?.(`⚠️  DEPRECATION WARNING: Found PRD file in legacy location '${n}'. Please migrate to .taskmaster/docs/ directory. Run 'task-master migrate' to automatically migrate your project.`),n}return r.warn?.(`No PRD document found in project: ${a}`),null}function Hr(e=null,t=null,n=null){let r=G(n);if(e){let t=process.env.TASKMASTER_ORIGINAL_CWD||process.cwd(),n=c.isAbsolute(e)?e:c.resolve(t,e);if(s.existsSync(n))return r.info?.(`Using explicit complexity report path: ${n}`),n;r.warn?.(`Explicit complexity report path not found: ${n}, trying fallbacks`)}let i=t?.projectRoot||q();if(!i)return r.warn?.(`Could not determine project root directory`),null;let a=K(i),o=[Qn,`scripts/`,``],l=[`task-complexity-report`,`task-complexity`,`complexity-report`].map(e=>t?.tag&&t?.tag!==`master`?`${e}_${t.tag}.json`:`${e}.json`);for(let e of o)for(let t of l){let n=c.join(a,e,t);if(s.existsSync(n))return r.info?.(`Found complexity report at: ${n}`),(e===`scripts/`||e===``)&&r.warn?.(`⚠️  DEPRECATION WARNING: Found complexity report in legacy location '${n}'. Please migrate to .taskmaster/reports/ directory. Run 'task-master migrate' to automatically migrate your project.`),n}return r.warn?.(`No complexity report found in project: ${a}`),null}function Ur(e=null,t=null,n=null){let r=G(n),i=t?.tag;if(e){let t=process.env.TASKMASTER_ORIGINAL_CWD||process.cwd(),n=c.isAbsolute(e)?e:c.resolve(t,e);return r.info?.(`Using explicit complexity report output path: ${n}`),n}let a=K(t?.projectRoot||q()||process.cwd()),o=`task-complexity-report.json`;i&&i!==`master`&&(o=`task-complexity-report_${i}.json`);let l=c.join(a,`.taskmaster/reports`,o);r.info?.(`Using tag-aware complexity report output path: ${l}`);let u=c.dirname(l);return s.existsSync(u)||(r.info?.(`Creating reports directory: ${u}`),s.mkdirSync(u,{recursive:!0})),l}function Wr(e=null,t=null,n=null){let r=G(n);if(e){let t=process.env.TASKMASTER_ORIGINAL_CWD||process.cwd(),n=c.isAbsolute(e)?e:c.resolve(t,e);if(s.existsSync(n))return r.info?.(`Using explicit config path: ${n}`),n;r.warn?.(`Explicit config path not found: ${n}, trying fallbacks`)}let i=t?.projectRoot||q();if(!i)return r.warn?.(`Could not determine project root directory`),null;let a=K(i),o=[c.join(a,er),c.join(a,z)];for(let e of o)if(s.existsSync(e))return e?.endsWith(z)&&r.warn?.(`⚠️  DEPRECATION WARNING: Found configuration in legacy location '${e}'. Please migrate to .taskmaster/config.json. Run 'task-master migrate' to automatically migrate your project.`),e;if(!(Yr()||t?.storageType===`api`)){let e=`config_warning_${a}`;global._tmConfigWarningsThisRun||(global._tmConfigWarningsThisRun=new Set),global._tmConfigWarningsThisRun.has(e)||(global._tmConfigWarningsThisRun.add(e),r.warn?.(`No configuration file found in project: ${a}`))}return null}var J={anthropic:[{id:`claude-sonnet-4-20250514`,swe_score:.727,cost_per_1m_tokens:{input:3,output:15},allowed_roles:[`main`,`fallback`],max_tokens:64e3,supported:!0},{id:`claude-opus-4-20250514`,swe_score:.725,cost_per_1m_tokens:{input:15,output:75},allowed_roles:[`main`,`fallback`],max_tokens:32e3,supported:!0},{id:`claude-3-7-sonnet-20250219`,swe_score:.623,cost_per_1m_tokens:{input:3,output:15},allowed_roles:[`main`,`fallback`],max_tokens:12e4,supported:!0},{id:`claude-3-5-sonnet-20241022`,swe_score:.49,cost_per_1m_tokens:{input:3,output:15},allowed_roles:[`main`,`fallback`],max_tokens:8192,supported:!0},{id:`claude-sonnet-4-5`,name:`Claude Sonnet 4.5`,swe_score:.772,cost_per_1m_tokens:{input:3,output:15},allowed_roles:[`main`,`fallback`],max_tokens:64e3,supported:!0},{id:`claude-haiku-4-5`,name:`Claude Haiku 4.5`,swe_score:.733,cost_per_1m_tokens:{input:1,output:5},allowed_roles:[`main`,`fallback`],max_tokens:2e5,supported:!0},{id:`claude-opus-4-1`,name:`Claude Opus 4.1`,swe_score:.745,cost_per_1m_tokens:{input:15,output:75},allowed_roles:[`main`,`fallback`],max_tokens:32e3,supported:!0},{id:`claude-opus-4-5`,name:`Claude Opus 4.5`,swe_score:.809,cost_per_1m_tokens:{input:5,output:25},allowed_roles:[`main`,`fallback`],max_tokens:32e3,supported:!0}],"claude-code":[{id:`opus`,swe_score:.725,cost_per_1m_tokens:{input:0,output:0},allowed_roles:[`main`,`fallback`,`research`],max_tokens:32e3,supported:!0},{id:`sonnet`,swe_score:.727,cost_per_1m_tokens:{input:0,output:0},allowed_roles:[`main`,`fallback`,`research`],max_tokens:64e3,supported:!0},{id:`haiku`,swe_score:.45,cost_per_1m_tokens:{input:0,output:0},allowed_roles:[`main`,`fallback`,`research`],max_tokens:2e5,supported:!0}],"codex-cli":[{id:`gpt-5.2-codex`,name:`GPT-5.2 Codex`,swe_score:.82,cost_per_1m_tokens:{input:0,output:0},allowed_roles:[`main`,`fallback`,`research`],max_tokens:128e3,reasoning_efforts:[`none`,`low`,`medium`,`high`,`xhigh`],supported:!0},{id:`gpt-5.1-codex-max`,name:`GPT-5.1 Codex Max`,swe_score:.78,cost_per_1m_tokens:{input:0,output:0},allowed_roles:[`main`,`fallback`,`research`],max_tokens:128e3,reasoning_efforts:[`none`,`low`,`medium`,`high`,`xhigh`],supported:!0},{id:`gpt-5.1-codex-mini`,name:`GPT-5.1 Codex Mini`,swe_score:.72,cost_per_1m_tokens:{input:0,output:0},allowed_roles:[`main`,`fallback`,`research`],max_tokens:128e3,reasoning_efforts:[`none`,`low`,`medium`,`high`],supported:!0},{id:`gpt-5.2`,name:`GPT-5.2`,swe_score:.8,cost_per_1m_tokens:{input:0,output:0},allowed_roles:[`main`,`fallback`,`research`],max_tokens:128e3,reasoning_efforts:[`none`,`low`,`medium`,`high`,`xhigh`],supported:!0}],mcp:[{id:`mcp-sampling`,swe_score:null,cost_per_1m_tokens:{input:0,output:0},allowed_roles:[`main`,`fallback`,`research`],max_tokens:1e5,supported:!0}],"gemini-cli":[{id:`gemini-3-flash-preview`,name:`Gemini 3 Flash`,swe_score:0,cost_per_1m_tokens:{input:0,output:0},allowed_roles:[`main`,`fallback`,`research`],max_tokens:1048576,supported:!0},{id:`gemini-3-pro-preview`,swe_score:.762,cost_per_1m_tokens:{input:0,output:0},allowed_roles:[`main`,`fallback`,`research`],max_tokens:65536,supported:!0},{id:`gemini-2.5-pro`,swe_score:.72,cost_per_1m_tokens:{input:0,output:0},allowed_roles:[`main`,`fallback`,`research`],max_tokens:65536,supported:!0},{id:`gemini-2.5-flash`,swe_score:.71,cost_per_1m_tokens:{input:0,output:0},allowed_roles:[`main`,`fallback`,`research`],max_tokens:65536,supported:!0}],"grok-cli":[{id:`grok-4-latest`,name:`Grok 4 Latest`,swe_score:.7,cost_per_1m_tokens:{input:0,output:0},allowed_roles:[`main`,`fallback`,`research`],max_tokens:131072,supported:!0},{id:`grok-3-latest`,name:`Grok 3 Latest`,swe_score:.65,cost_per_1m_tokens:{input:0,output:0},allowed_roles:[`main`,`fallback`,`research`],max_tokens:131072,supported:!0},{id:`grok-3-fast`,name:`Grok 3 Fast`,swe_score:.6,cost_per_1m_tokens:{input:0,output:0},allowed_roles:[`main`,`fallback`,`research`],max_tokens:131072,supported:!0},{id:`grok-3-mini-fast`,name:`Grok 3 Mini Fast`,swe_score:.55,cost_per_1m_tokens:{input:0,output:0},allowed_roles:[`main`,`fallback`,`research`],max_tokens:32768,supported:!0}],openai:[{id:`gpt-4o`,swe_score:.332,cost_per_1m_tokens:{input:2.5,output:10},allowed_roles:[`main`,`fallback`],max_tokens:16384,supported:!0},{id:`o1`,swe_score:.489,cost_per_1m_tokens:{input:15,output:60},allowed_roles:[`main`],supported:!0},{id:`o3`,swe_score:.5,cost_per_1m_tokens:{input:2,output:8},allowed_roles:[`main`,`fallback`],max_tokens:1e5,supported:!0},{id:`o3-mini`,swe_score:.493,cost_per_1m_tokens:{input:1.1,output:4.4},allowed_roles:[`main`],max_tokens:1e5,supported:!0},{id:`o4-mini`,swe_score:.45,cost_per_1m_tokens:{input:1.1,output:4.4},allowed_roles:[`main`,`fallback`],supported:!0},{id:`o1-mini`,swe_score:.4,cost_per_1m_tokens:{input:1.1,output:4.4},allowed_roles:[`main`],supported:!0},{id:`o1-pro`,swe_score:0,cost_per_1m_tokens:{input:150,output:600},allowed_roles:[`main`],supported:!0},{id:`gpt-4-5-preview`,swe_score:.38,cost_per_1m_tokens:{input:75,output:150},allowed_roles:[`main`],supported:!0},{id:`gpt-4-1-mini`,swe_score:0,cost_per_1m_tokens:{input:.4,output:1.6},allowed_roles:[`main`],supported:!0},{id:`gpt-4-1-nano`,swe_score:0,cost_per_1m_tokens:{input:.1,output:.4},allowed_roles:[`main`],supported:!0},{id:`gpt-4o-mini`,swe_score:.3,cost_per_1m_tokens:{input:.15,output:.6},allowed_roles:[`main`],supported:!0},{id:`gpt-4o-search-preview`,swe_score:.33,cost_per_1m_tokens:{input:2.5,output:10},allowed_roles:[`research`],supported:!0},{id:`gpt-4o-mini-search-preview`,swe_score:.3,cost_per_1m_tokens:{input:.15,output:.6},allowed_roles:[`research`],supported:!0},{id:`gpt-5`,swe_score:.749,cost_per_1m_tokens:{input:5,output:20},allowed_roles:[`main`,`fallback`],max_tokens:1e5,temperature:1,supported:!0},{id:`gpt-5.1`,swe_score:.76,cost_per_1m_tokens:{input:1.25,output:10},allowed_roles:[`main`,`fallback`],max_tokens:128e3,reasoning_efforts:[`none`,`low`,`medium`,`high`],supported:!0},{id:`gpt-5.1-codex-max`,swe_score:.78,cost_per_1m_tokens:{input:1.25,output:10},allowed_roles:[`main`,`fallback`],max_tokens:128e3,reasoning_efforts:[`none`,`low`,`medium`,`high`,`xhigh`],supported:!0},{id:`gpt-5.2`,swe_score:.8,cost_per_1m_tokens:{input:1.75,output:14},allowed_roles:[`main`,`fallback`],max_tokens:128e3,reasoning_efforts:[`none`,`low`,`medium`,`high`,`xhigh`],supported:!0},{id:`gpt-5.2-pro`,swe_score:.82,cost_per_1m_tokens:{input:21,output:168},allowed_roles:[`main`,`fallback`],max_tokens:128e3,reasoning_efforts:[`medium`,`high`,`xhigh`],supported:!0}],google:[{id:`gemini-3-flash-preview`,name:`Gemini 3 Flash`,swe_score:0,cost_per_1m_tokens:{input:.5,output:3},allowed_roles:[`main`,`fallback`],max_tokens:1048576,supported:!0},{id:`gemini-3-pro-preview`,swe_score:.762,cost_per_1m_tokens:{input:2,output:12},allowed_roles:[`main`,`fallback`,`research`],max_tokens:1e6,supported:!0},{id:`gemini-2.5-pro-preview-05-06`,swe_score:.638,cost_per_1m_tokens:null,allowed_roles:[`main`,`fallback`],max_tokens:1048e3,supported:!0},{id:`gemini-2.5-pro-preview-03-25`,swe_score:.638,cost_per_1m_tokens:null,allowed_roles:[`main`,`fallback`],max_tokens:1048e3,supported:!0},{id:`gemini-2.5-flash-preview-04-17`,swe_score:.604,cost_per_1m_tokens:null,allowed_roles:[`main`,`fallback`],max_tokens:1048e3,supported:!0},{id:`gemini-2.0-flash`,swe_score:.518,cost_per_1m_tokens:{input:.15,output:.6},allowed_roles:[`main`,`fallback`],max_tokens:1048e3,supported:!0},{id:`gemini-2.0-flash-lite`,swe_score:0,cost_per_1m_tokens:null,allowed_roles:[`main`,`fallback`],max_tokens:1048e3,supported:!0}],xai:[{id:`grok-3`,name:`Grok 3`,swe_score:null,cost_per_1m_tokens:{input:3,output:15},allowed_roles:[`main`,`fallback`,`research`],max_tokens:131072,supported:!0},{id:`grok-3-fast`,name:`Grok 3 Fast`,swe_score:0,cost_per_1m_tokens:{input:5,output:25},allowed_roles:[`main`,`fallback`,`research`],max_tokens:131072,supported:!0},{id:`grok-4`,name:`Grok 4`,swe_score:null,cost_per_1m_tokens:{input:3,output:15},allowed_roles:[`main`,`fallback`,`research`],max_tokens:131072,supported:!0}],groq:[{id:`moonshotai/kimi-k2-instruct`,swe_score:.66,cost_per_1m_tokens:{input:1,output:3},allowed_roles:[`main`,`fallback`],max_tokens:16384,supported:!0},{id:`llama-3.3-70b-versatile`,swe_score:.55,cost_per_1m_tokens:{input:.59,output:.79},allowed_roles:[`main`,`fallback`,`research`],max_tokens:32768,supported:!0},{id:`llama-3.1-8b-instant`,swe_score:.32,cost_per_1m_tokens:{input:.05,output:.08},allowed_roles:[`main`,`fallback`],max_tokens:131072,supported:!0},{id:`llama-4-scout`,swe_score:.45,cost_per_1m_tokens:{input:.11,output:.34},allowed_roles:[`main`,`fallback`,`research`],max_tokens:32768,supported:!0},{id:`llama-4-maverick`,swe_score:.52,cost_per_1m_tokens:{input:.5,output:.77},allowed_roles:[`main`,`fallback`,`research`],max_tokens:32768,supported:!0},{id:`mixtral-8x7b-32768`,swe_score:.35,cost_per_1m_tokens:{input:.24,output:.24},allowed_roles:[`main`,`fallback`],max_tokens:32768,supported:!0},{id:`qwen-qwq-32b-preview`,swe_score:.4,cost_per_1m_tokens:{input:.18,output:.18},allowed_roles:[`main`,`fallback`,`research`],max_tokens:32768,supported:!0},{id:`deepseek-r1-distill-llama-70b`,swe_score:.52,cost_per_1m_tokens:{input:.75,output:.99},allowed_roles:[`main`,`research`],max_tokens:8192,supported:!0},{id:`gemma2-9b-it`,swe_score:.3,cost_per_1m_tokens:{input:.2,output:.2},allowed_roles:[`main`,`fallback`],max_tokens:8192,supported:!0},{id:`whisper-large-v3`,swe_score:0,cost_per_1m_tokens:{input:.11,output:0},allowed_roles:[`main`],max_tokens:0,supported:!0}],perplexity:[{id:`sonar-pro`,swe_score:0,cost_per_1m_tokens:{input:3,output:15},allowed_roles:[`main`,`research`],max_tokens:8700,supported:!0},{id:`sonar`,swe_score:0,cost_per_1m_tokens:{input:1,output:1},allowed_roles:[`research`],max_tokens:8700,supported:!0},{id:`sonar-deep-research`,swe_score:.211,cost_per_1m_tokens:{input:2,output:8},allowed_roles:[`research`],max_tokens:8700,supported:!0},{id:`sonar-reasoning-pro`,swe_score:.211,cost_per_1m_tokens:{input:2,output:8},allowed_roles:[`main`,`research`,`fallback`],max_tokens:8700,supported:!0},{id:`sonar-reasoning`,swe_score:.211,cost_per_1m_tokens:{input:1,output:5},allowed_roles:[`main`,`research`,`fallback`],max_tokens:8700,supported:!0}],openrouter:[{id:`google/gemini-2.5-flash-preview-05-20`,swe_score:0,cost_per_1m_tokens:{input:.15,output:.6},allowed_roles:[`main`,`fallback`],max_tokens:1048576,supported:!0},{id:`google/gemini-2.5-flash-preview-05-20:thinking`,swe_score:0,cost_per_1m_tokens:{input:.15,output:3.5},allowed_roles:[`main`,`fallback`],max_tokens:1048576,supported:!0},{id:`google/gemini-2.5-pro-exp-03-25`,swe_score:0,cost_per_1m_tokens:{input:0,output:0},allowed_roles:[`main`,`fallback`],max_tokens:1e6,supported:!0},{id:`deepseek/deepseek-chat-v3-0324:free`,swe_score:0,cost_per_1m_tokens:{input:0,output:0},allowed_roles:[`main`,`fallback`],max_tokens:163840,supported:!1,reason:`Free OpenRouter models are not supported due to severe rate limits, lack of tool use support, and other reliability issues that make them impractical for production use.`},{id:`deepseek/deepseek-chat-v3-0324`,swe_score:0,cost_per_1m_tokens:{input:.27,output:1.1},allowed_roles:[`main`],max_tokens:64e3,supported:!0},{id:`openai/gpt-4.1`,swe_score:0,cost_per_1m_tokens:{input:2,output:8},allowed_roles:[`main`,`fallback`],max_tokens:1e6,supported:!0},{id:`openai/gpt-4.1-mini`,swe_score:0,cost_per_1m_tokens:{input:.4,output:1.6},allowed_roles:[`main`,`fallback`],max_tokens:1e6,supported:!0},{id:`openai/gpt-4.1-nano`,swe_score:0,cost_per_1m_tokens:{input:.1,output:.4},allowed_roles:[`main`,`fallback`],max_tokens:1e6,supported:!0},{id:`openai/o3`,swe_score:0,cost_per_1m_tokens:{input:10,output:40},allowed_roles:[`main`,`fallback`],max_tokens:2e5,supported:!0},{id:`openai/codex-mini`,swe_score:0,cost_per_1m_tokens:{input:1.5,output:6},allowed_roles:[`main`,`fallback`],max_tokens:1e5,supported:!0},{id:`openai/gpt-4o-mini`,swe_score:0,cost_per_1m_tokens:{input:.15,output:.6},allowed_roles:[`main`,`fallback`],max_tokens:1e5,supported:!0},{id:`openai/o4-mini`,swe_score:.45,cost_per_1m_tokens:{input:1.1,output:4.4},allowed_roles:[`main`,`fallback`],max_tokens:1e5,supported:!0},{id:`openai/o4-mini-high`,swe_score:0,cost_per_1m_tokens:{input:1.1,output:4.4},allowed_roles:[`main`,`fallback`],max_tokens:1e5,supported:!0},{id:`openai/o1-pro`,swe_score:0,cost_per_1m_tokens:{input:150,output:600},allowed_roles:[`main`,`fallback`],max_tokens:1e5,supported:!0},{id:`meta-llama/llama-3.3-70b-instruct`,swe_score:0,cost_per_1m_tokens:{input:120,output:600},allowed_roles:[`main`,`fallback`],max_tokens:1048576,supported:!0},{id:`meta-llama/llama-4-maverick`,swe_score:0,cost_per_1m_tokens:{input:.18,output:.6},allowed_roles:[`main`,`fallback`],max_tokens:1e6,supported:!0},{id:`meta-llama/llama-4-scout`,swe_score:0,cost_per_1m_tokens:{input:.08,output:.3},allowed_roles:[`main`,`fallback`],max_tokens:1e6,supported:!0},{id:`qwen/qwen-max`,swe_score:0,cost_per_1m_tokens:{input:1.6,output:6.4},allowed_roles:[`main`,`fallback`],max_tokens:32768,supported:!0},{id:`qwen/qwen-turbo`,swe_score:0,cost_per_1m_tokens:{input:.05,output:.2},allowed_roles:[`main`,`fallback`],max_tokens:32768,supported:!0},{id:`qwen/qwen3-235b-a22b`,swe_score:0,cost_per_1m_tokens:{input:.14,output:2},allowed_roles:[`main`,`fallback`],max_tokens:24e3,supported:!0},{id:`mistralai/mistral-small-3.1-24b-instruct:free`,swe_score:0,cost_per_1m_tokens:{input:0,output:0},allowed_roles:[`main`,`fallback`],max_tokens:96e3,supported:!1,reason:`Free OpenRouter models are not supported due to severe rate limits, lack of tool use support, and other reliability issues that make them impractical for production use.`},{id:`mistralai/mistral-small-3.1-24b-instruct`,swe_score:0,cost_per_1m_tokens:{input:.1,output:.3},allowed_roles:[`main`,`fallback`],max_tokens:128e3,supported:!0},{id:`mistralai/devstral-small`,swe_score:0,cost_per_1m_tokens:{input:.1,output:.3},allowed_roles:[`main`],max_tokens:11e4,supported:!0},{id:`mistralai/mistral-nemo`,swe_score:0,cost_per_1m_tokens:{input:.03,output:.07},allowed_roles:[`main`,`fallback`],max_tokens:1e5,supported:!0},{id:`thudm/glm-4-32b:free`,swe_score:0,cost_per_1m_tokens:{input:0,output:0},allowed_roles:[`main`,`fallback`],max_tokens:32768,supported:!1,reason:`Free OpenRouter models are not supported due to severe rate limits, lack of tool use support, and other reliability issues that make them impractical for production use.`}],zai:[{id:`glm-4.6`,swe_score:.68,cost_per_1m_tokens:{input:.6,output:2.2},allowed_roles:[`main`,`fallback`,`research`],max_tokens:204800,supported:!0},{id:`glm-4.5`,swe_score:.65,cost_per_1m_tokens:{input:.6,output:2.2},allowed_roles:[`main`,`fallback`,`research`],max_tokens:131072,supported:!0},{id:`glm-4.5-air`,swe_score:.62,cost_per_1m_tokens:{input:.2,output:1.1},allowed_roles:[`main`,`fallback`,`research`],max_tokens:131072,supported:!0}],"zai-coding":[{id:`glm-4.6`,swe_score:.68,cost_per_1m_tokens:{input:0,output:0},allowed_roles:[`main`,`fallback`,`research`],max_tokens:204800,supported:!0},{id:`glm-4.5`,swe_score:.65,cost_per_1m_tokens:{input:0,output:0},allowed_roles:[`main`,`fallback`,`research`],max_tokens:131072,supported:!0},{id:`glm-4.5-air`,swe_score:.62,cost_per_1m_tokens:{input:0,output:0},allowed_roles:[`main`,`fallback`,`research`],max_tokens:131072,supported:!0}],ollama:[{id:`gpt-oss:latest`,swe_score:.607,cost_per_1m_tokens:{input:0,output:0},allowed_roles:[`main`,`fallback`],max_tokens:128e3,supported:!0},{id:`gpt-oss:20b`,swe_score:.607,cost_per_1m_tokens:{input:0,output:0},allowed_roles:[`main`,`fallback`],max_tokens:128e3,supported:!0},{id:`gpt-oss:120b`,swe_score:.624,cost_per_1m_tokens:{input:0,output:0},allowed_roles:[`main`,`fallback`],max_tokens:128e3,supported:!0},{id:`devstral:latest`,swe_score:0,cost_per_1m_tokens:{input:0,output:0},allowed_roles:[`main`,`fallback`],supported:!0},{id:`qwen3:latest`,swe_score:0,cost_per_1m_tokens:{input:0,output:0},allowed_roles:[`main`,`fallback`],supported:!0},{id:`qwen3:14b`,swe_score:0,cost_per_1m_tokens:{input:0,output:0},allowed_roles:[`main`,`fallback`],supported:!0},{id:`qwen3:32b`,swe_score:0,cost_per_1m_tokens:{input:0,output:0},allowed_roles:[`main`,`fallback`],supported:!0},{id:`mistral-small3.1:latest`,swe_score:0,cost_per_1m_tokens:{input:0,output:0},allowed_roles:[`main`,`fallback`],supported:!0},{id:`llama3.3:latest`,swe_score:0,cost_per_1m_tokens:{input:0,output:0},allowed_roles:[`main`,`fallback`],supported:!0},{id:`phi4:latest`,swe_score:0,cost_per_1m_tokens:{input:0,output:0},allowed_roles:[`main`,`fallback`],supported:!0}],azure:[{id:`gpt-4o`,swe_score:.332,cost_per_1m_tokens:{input:2.5,output:10},allowed_roles:[`main`,`fallback`],max_tokens:16384,supported:!0},{id:`gpt-4o-mini`,swe_score:.3,cost_per_1m_tokens:{input:.15,output:.6},allowed_roles:[`main`,`fallback`],max_tokens:16384,supported:!0},{id:`gpt-4-1`,swe_score:0,cost_per_1m_tokens:{input:2,output:10},allowed_roles:[`main`,`fallback`],max_tokens:16384,supported:!0},{id:`gpt-5`,name:`GPT-5`,swe_score:.749,cost_per_1m_tokens:{input:5,output:20},allowed_roles:[`main`,`fallback`],max_tokens:1e5,temperature:1,supported:!0,api_type:`responses`},{id:`o1`,name:`o1`,swe_score:.489,cost_per_1m_tokens:{input:15,output:60},allowed_roles:[`main`],max_tokens:1e5,supported:!0,api_type:`responses`},{id:`o3`,name:`o3`,swe_score:.5,cost_per_1m_tokens:{input:2,output:8},allowed_roles:[`main`,`fallback`],max_tokens:1e5,supported:!0,api_type:`responses`},{id:`o3-mini`,name:`o3-mini`,swe_score:.493,cost_per_1m_tokens:{input:1.1,output:4.4},allowed_roles:[`main`],max_tokens:1e5,supported:!0,api_type:`responses`},{id:`o4-mini`,name:`o4-mini`,swe_score:.45,cost_per_1m_tokens:{input:1.1,output:4.4},allowed_roles:[`main`,`fallback`],max_tokens:1e5,supported:!0,api_type:`responses`},{id:`gpt-5.1`,name:`GPT-5.1`,swe_score:.76,cost_per_1m_tokens:{input:1.25,output:10},allowed_roles:[`main`,`fallback`],max_tokens:128e3,reasoning_efforts:[`none`,`low`,`medium`,`high`],supported:!0,api_type:`responses`},{id:`gpt-5.2`,name:`GPT-5.2`,swe_score:.8,cost_per_1m_tokens:{input:1.75,output:14},allowed_roles:[`main`,`fallback`],max_tokens:128e3,reasoning_efforts:[`none`,`low`,`medium`,`high`,`xhigh`],supported:!0,api_type:`responses`}],bedrock:[{id:`us.anthropic.claude-3-haiku-20240307-v1:0`,swe_score:.4,cost_per_1m_tokens:{input:.25,output:1.25},allowed_roles:[`main`,`fallback`],supported:!0},{id:`us.anthropic.claude-3-opus-20240229-v1:0`,swe_score:.725,cost_per_1m_tokens:{input:15,output:75},allowed_roles:[`main`,`fallback`,`research`],supported:!0},{id:`us.anthropic.claude-3-5-sonnet-20240620-v1:0`,swe_score:.49,cost_per_1m_tokens:{input:3,output:15},allowed_roles:[`main`,`fallback`,`research`],supported:!0},{id:`us.anthropic.claude-3-5-sonnet-20241022-v2:0`,swe_score:.49,cost_per_1m_tokens:{input:3,output:15},allowed_roles:[`main`,`fallback`,`research`],supported:!0},{id:`us.anthropic.claude-3-7-sonnet-20250219-v1:0`,swe_score:.623,cost_per_1m_tokens:{input:3,output:15},allowed_roles:[`main`,`fallback`,`research`],max_tokens:65536,supported:!0},{id:`us.anthropic.claude-3-5-haiku-20241022-v1:0`,swe_score:.4,cost_per_1m_tokens:{input:.8,output:4},allowed_roles:[`main`,`fallback`],supported:!0},{id:`us.anthropic.claude-opus-4-20250514-v1:0`,swe_score:.725,cost_per_1m_tokens:{input:15,output:75},allowed_roles:[`main`,`fallback`,`research`],supported:!0},{id:`us.anthropic.claude-sonnet-4-20250514-v1:0`,swe_score:.727,cost_per_1m_tokens:{input:3,output:15},allowed_roles:[`main`,`fallback`,`research`],supported:!0},{id:`us.deepseek.r1-v1:0`,swe_score:0,cost_per_1m_tokens:{input:1.35,output:5.4},allowed_roles:[`research`],max_tokens:65536,supported:!0}]};const Gr=_e(import.meta.url);c.dirname(Gr);const Y={models:{main:{provider:`anthropic`,modelId:`claude-sonnet-4-20250514`,maxTokens:64e3,temperature:.2},research:{provider:`perplexity`,modelId:`sonar`,maxTokens:8700,temperature:.1},fallback:{provider:`anthropic`,modelId:`claude-3-7-sonnet-20250219`,maxTokens:12e4,temperature:.2}},global:{logLevel:`info`,debug:!1,defaultNumTasks:10,defaultSubtasks:5,defaultPriority:`medium`,projectName:`Task Master`,ollamaBaseURL:`http://localhost:11434/api`,bedrockBaseURL:`https://bedrock.us-east-1.amazonaws.com`,responseLanguage:`English`,enableCodebaseAnalysis:!0,enableProxy:!1,anonymousTelemetry:!0},claudeCode:{},codexCli:{},grokCli:{timeout:12e4,workingDirectory:null,defaultModel:`grok-4-latest`}};let Kr=null,qr=null;function Jr(e){global._tmSuppressConfigWarnings=e}function Yr(){return global._tmSuppressConfigWarnings===!0}var Xr=class extends Error{constructor(e){super(e),this.name=`ConfigurationError`}};function Zr(e=null,t={}){let n=Y,r=e,{storageType:a}=t;e&&`${e}`,r||(r=V(),r||=process.cwd(),`${r}`);let o=null,l={...n};if((s.existsSync(c.join(r,Yn))||s.existsSync(c.join(r,z)))&&(o=Wr(null,{projectRoot:r,storageType:a})),o){let e=o.endsWith(z);try{let t=s.readFileSync(o,`utf-8`),r=JSON.parse(t);l={models:{main:{...n.models.main,...r?.models?.main},research:{...n.models.research,...r?.models?.research},fallback:r?.models?.fallback?.provider&&r?.models?.fallback?.modelId?{...n.models.fallback,...r.models.fallback}:{...n.models.fallback}},global:{...n.global,...r?.global},claudeCode:{...n.claudeCode,...r?.claudeCode},codexCli:{...n.codexCli,...r?.codexCli},grokCli:{...n.grokCli,...r?.grokCli}},`${o}`,e&&console.warn(i.yellow(`⚠️  DEPRECATION WARNING: Found configuration in legacy location '${o}'. Please migrate to .taskmaster/config.json. Run 'task-master migrate' to automatically migrate your project.`)),Qr(l.models.main.provider)||(console.warn(i.yellow(`Warning: Invalid main provider "${l.models.main.provider}" in ${o}. Falling back to default.`)),l.models.main={...n.models.main}),Qr(l.models.research.provider)||(console.warn(i.yellow(`Warning: Invalid research provider "${l.models.research.provider}" in ${o}. Falling back to default.`)),l.models.research={...n.models.research}),l.models.fallback?.provider&&!Qr(l.models.fallback.provider)&&(console.warn(i.yellow(`Warning: Invalid fallback provider "${l.models.fallback.provider}" in ${o}. Fallback model configuration will be ignored.`)),l.models.fallback.provider=void 0,l.models.fallback.modelId=void 0),l.claudeCode&&!Ar(l.claudeCode)&&(l.claudeCode=ei(l.claudeCode)),l.codexCli&&!Ar(l.codexCli)&&(l.codexCli=ti(l.codexCli))}catch(e){console.error(i.red(`Error reading or parsing ${o}: ${e.message}. Using default configuration.`)),l={...n},`${o}`}}else{if(!Yr()&&a!==`api`)if(e)console.warn(i.yellow(`Warning: Configuration file not found at provided project root (${e}). Using default configuration. Run 'task-master models --setup' to configure.`));else{let e=s.existsSync(c.join(r,Yn)),t=s.existsSync(c.join(r,z));(e||t)&&console.warn(i.yellow(`Warning: Configuration file not found at derived root (${r}). Using defaults.`))}l={...n},`${r}`}return l}function X(e=null,t=!1,n={}){if(!Kr||t||e&&e!==qr){let r=Zr(e,n);return(t||e)&&(Kr=r,qr=e),r}return Kr}function Qr(e){return Ve.includes(e)?!0:Be.includes(e)?!!(J&&J[e]):!1}function $r(e){return J[e]?J[e].filter(e=>e.supported!==!1).map(e=>e.id):[]}function ei(e){let t=_.object({pathToClaudeCodeExecutable:_.string().optional(),maxTurns:_.number().int().positive().optional(),customSystemPrompt:_.string().optional(),appendSystemPrompt:_.string().optional(),permissionMode:_.enum([`default`,`acceptEdits`,`plan`,`bypassPermissions`]).optional(),allowedTools:_.array(_.string()).optional(),disallowedTools:_.array(_.string()).optional(),mcpServers:_.record(_.string(),_.object({type:_.enum([`stdio`,`sse`]).optional(),command:_.string(),args:_.array(_.string()).optional(),env:_.record(_.string(),_.string()).optional(),url:_.url().optional(),headers:_.record(_.string(),_.string()).optional()})).optional()}),n=_.record(_.string(),t).refine(e=>Object.keys(e||{}).every(e=>Jn.includes(e)),{message:`Invalid command name in commandSpecific`}),r=t.extend({commandSpecific:n.optional()}),a={};try{a=r.parse(e)}catch(e){console.warn(i.yellow(`Warning: Invalid Claude Code settings in config: ${e.message}. Falling back to default.`)),a={}}return a}function ti(e){let t=_.object({codexPath:_.string().optional(),cwd:_.string().optional(),approvalMode:_.enum([`untrusted`,`on-failure`,`on-request`,`never`]).optional(),sandboxMode:_.enum([`read-only`,`workspace-write`,`danger-full-access`]).optional(),fullAuto:_.boolean().optional(),dangerouslyBypassApprovalsAndSandbox:_.boolean().optional(),skipGitRepoCheck:_.boolean().optional(),color:_.enum([`always`,`never`,`auto`]).optional(),allowNpx:_.boolean().optional(),outputLastMessageFile:_.string().optional(),env:_.record(_.string(),_.string()).optional(),verbose:_.boolean().optional(),logger:_.union([_.object({}).passthrough(),_.literal(!1)]).optional(),reasoningEffort:_.enum([`none`,`minimal`,`low`,`medium`,`high`,`xhigh`]).optional()}),n=_.record(_.string(),t).refine(e=>Object.keys(e||{}).every(e=>Jn.includes(e)),{message:`Invalid command name in commandSpecific`}),r=t.extend({commandSpecific:n.optional()});try{return r.parse(e)}catch(e){return console.warn(i.yellow(`Warning: Invalid Codex CLI settings in config: ${e.message}. Falling back to default.`)),{}}}function ni(e=null,t=!1){let n=X(e,t);return{...Y.claudeCode,...n?.claudeCode||{}}}function ri(e=null,t=!1){let n=X(e,t);return{...Y.codexCli,...n?.codexCli||{}}}function ii(e,t=null,n=!1){let r=ri(t,n),i=r?.commandSpecific||{};return{...r,...i[e]}}function ai(e,t=null,n=!1){let r=ni(t,n),i=r?.commandSpecific||{};return{...r,...i[e]}}function oi(e=null,t=!1){let n=X(e,t);return{...Y.grokCli,...n?.grokCli||{}}}function si(e,t=null,n=!1){let r=oi(t,n),i=r?.commandSpecific||{};return{...r,...i[e]}}function Z(e,t=null){return X(t)?.models?.[e]||(U(`warn`,`No model configuration found for role: ${e}. Returning default.`),Y.models[e]||{})}function ci(e=null){return Z(`main`,e).provider}function li(e=null){return Z(`main`,e).modelId}function ui(e=null){return Z(`research`,e).provider}function di(e=null,t=null){let n=B(`TASKMASTER_ENABLE_CODEBASE_ANALYSIS`,e,t);if(n!=null&&n!==``)return n.toLowerCase()===`true`||n===`1`;if(e?.env?.TASKMASTER_ENABLE_CODEBASE_ANALYSIS){let t=e.env.TASKMASTER_ENABLE_CODEBASE_ANALYSIS;return t.toLowerCase()===`true`||t===`1`}return Q(t).enableCodebaseAnalysis!==!1}function fi(e=!1,t=null,n=null){if(!di(n,t))return!1;let r=e?ui(t):ci(t);return r===T.CLAUDE_CODE||r===T.GEMINI_CLI||r===T.GROK_CLI||r===T.CODEX_CLI}function pi(e=null){return Z(`research`,e).modelId}function mi(e=null){return Z(`fallback`,e).provider}function hi(e=null){return Z(`fallback`,e).modelId}function Q(e=null){let t=X(e);return{...Y.global,...t?.global||{}}}function gi(e=null){return Q(e).logLevel.toLowerCase()}function $(e=null){return Q(e).debug===!0}function _i(e=null){let t=Q(e).defaultSubtasks,n=parseInt(t,10);return Number.isNaN(n)?Y.global.defaultSubtasks:n}function vi(e=null){let t=Q(e).defaultNumTasks,n=parseInt(t,10);return Number.isNaN(n)?Y.global.defaultNumTasks:n}function yi(e=null){return Q(e).defaultPriority}function bi(e=null){return Q(e).projectName}function xi(e=null){return Q(e).ollamaBaseURL}function Si(e=null){return Q(e).azureBaseURL}function Ci(e=null){return Q(e).bedrockBaseURL}function wi(e=null){return Q(e).vertexProjectId}function Ti(e=null){return Q(e).vertexLocation}function Ei(e=null){return Q(e).responseLanguage}function Di(e=null){return Q(e).enableProxy===!0}function Oi(e=null){return Q(e).anonymousTelemetry!==!1}function ki(e=null,t=null){let n=B(`TASKMASTER_ENABLE_PROXY`,e,t);if(n!=null&&n!==``)return n.toLowerCase()===`true`||n===`1`;if(e?.env?.TASKMASTER_ENABLE_PROXY){let t=e.env.TASKMASTER_ENABLE_PROXY;return t.toLowerCase()===`true`||t===`1`}return Di(t)}function Ai(e,t=null){let n=Z(e,t),r=n.maxTokens,i=n.temperature,a=n.modelId,o=n.provider,s=r,c=i;try{let e=J[o];if(e&&Array.isArray(e)){let t=e.find(e=>e.id===a);if(t&&typeof t.max_tokens==`number`&&t.max_tokens>0){let e=t.max_tokens;s=Math.min(r,e),U(`debug`,`Applying model-specific max_tokens (${e}) for ${a}. Effective limit: ${s}`)}else U(`debug`,`No valid model-specific max_tokens override found for ${a}. Using role default: ${r}`);t&&typeof t.temperature==`number`&&t.temperature>=0&&t.temperature<=1&&(c=t.temperature,U(`debug`,`Applying model-specific temperature (${t.temperature}) for ${a}`))}else o===T.OPENROUTER?(s=Math.min(r,32768),U(`debug`,`Custom OpenRouter model ${a} detected. Using conservative max_tokens: ${s}`)):U(`debug`,`No model definitions found for provider ${o} in MODEL_MAP. Using role default maxTokens: ${r}`)}catch(e){U(`warn`,`Error looking up model-specific parameters for ${a}: ${e.message}. Using role defaults.`),s=r,c=i}return{maxTokens:s,temperature:c}}function ji(e,t=null,n=null){if([T.OLLAMA,T.BEDROCK,T.GEMINI_CLI,T.GROK_CLI,T.MCP,T.CODEX_CLI].includes(e?.toLowerCase())||e?.toLowerCase()===`claude-code`||e?.toLowerCase()===`codex-cli`)return!0;let r={openai:`OPENAI_API_KEY`,anthropic:`ANTHROPIC_API_KEY`,google:`GOOGLE_API_KEY`,perplexity:`PERPLEXITY_API_KEY`,mistral:`MISTRAL_API_KEY`,azure:`AZURE_OPENAI_API_KEY`,openrouter:`OPENROUTER_API_KEY`,xai:`XAI_API_KEY`,zai:`ZAI_API_KEY`,"zai-coding":`ZAI_API_KEY`,groq:`GROQ_API_KEY`,vertex:`GOOGLE_API_KEY`,"claude-code":`CLAUDE_CODE_API_KEY`,bedrock:`AWS_ACCESS_KEY_ID`},i=e?.toLowerCase();if(!i||!r[i])return U(`warn`,`Unknown provider name: ${e} in isApiKeySet check.`),!1;let a=r[i],o=B(a,t,n);return o&&o.trim()!==``&&!/YOUR_.*_API_KEY_HERE/.test(o)&&!o.includes(`KEY_HERE`)}function Mi(e,t=null){let n=t||V();if(!n)return console.warn(i.yellow(`Warning: Could not find project root to check mcp.json.`)),!1;let r=c.join(n,`.cursor`,`mcp.json`);if(!s.existsSync(r))return!1;try{let t=s.readFileSync(r,`utf-8`),n=JSON.parse(t),i=n?.mcpServers?.[`task-master-ai`]?.env||n?.mcpServers?.[`taskmaster-ai`]?.env;if(!i)return!1;let a=null;switch(e){case`anthropic`:a=i.ANTHROPIC_API_KEY;break;case`openai`:a=i.OPENAI_API_KEY;break;case`openrouter`:a=i.OPENROUTER_API_KEY;break;case`google`:a=i.GOOGLE_API_KEY;break;case`perplexity`:a=i.PERPLEXITY_API_KEY;break;case`xai`:a=i.XAI_API_KEY;break;case`zai`:case`zai-coding`:a=i.ZAI_API_KEY;break;case`groq`:a=i.GROQ_API_KEY;break;case`ollama`:return!0;case`claude-code`:return!0;case`codex-cli`:return!0;case`mistral`:a=i.MISTRAL_API_KEY;break;case`azure`:a=i.AZURE_OPENAI_API_KEY;break;case`vertex`:a=i.GOOGLE_API_KEY;break;case`bedrock`:a=i.AWS_ACCESS_KEY_ID;break;default:return!1}return!!a&&!/KEY_HERE$/.test(a)}catch(e){return console.error(i.red(`Error reading or parsing .cursor/mcp.json: ${e.message}`)),!1}}function Ni(){let e=[];for(let[t,n]of Object.entries(J))n.length>0?n.filter(e=>!!e.supported).forEach(n=>{let r=n.id,i=n.swe_score,a=n.cost_per_1m_tokens,o=n.allowed_roles||[`main`,`fallback`],s=n.name;s||(s=r.split(`-`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `),r===`claude-3.5-sonnet-20240620`&&(s=`Claude 3.5 Sonnet`),r===`claude-3-7-sonnet-20250219`&&(s=`Claude 3.7 Sonnet`),r===`gpt-4o`&&(s=`GPT-4o`),r===`gpt-4-turbo`&&(s=`GPT-4 Turbo`),r===`sonar-pro`&&(s=`Perplexity Sonar Pro`),r===`sonar-mini`&&(s=`Perplexity Sonar Mini`)),e.push({id:r,name:s,provider:t,swe_score:i,cost_per_1m_tokens:a,allowed_roles:o,max_tokens:n.max_tokens})}):e.push({id:`[${t}-any]`,name:`Any (${t})`,provider:t});return e}function Pi(e,t=null){let n=t;if(t==null){let e=V();if(!e)return console.error(i.red(`Error: Could not determine project root. Configuration not saved.`)),!1;n=e}let r=c.join(n,`.taskmaster`),a=c.join(r,`config.json`);try{return s.existsSync(r)||s.mkdirSync(r,{recursive:!0}),s.writeFileSync(a,JSON.stringify(e,null,2)),Kr=e,!0}catch(e){return console.error(i.red(`Error writing configuration to ${a}: ${e.message}`)),!1}}function Fi(e=null){return Wr(null,{projectRoot:e})!==null}function Ii(e=null){let t=X(e);return t.global||={},t.global.userId||(t.global.userId=`1234567890`,Pi(t,e)||U(`warning`,`Failed to write updated configuration with new userId. Please let the developers know.`)),t.global.userId}function Li(){return He}function Ri(e,t=null){let n=Z(e,t);if(n&&typeof n.baseURL==`string`)return n.baseURL;let r=n?.provider
