taskgraph-ai 0.52.23 → 0.54.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -34
- package/dist/ai-services-unified-443pp39A.js +1 -0
- package/dist/ai-services-unified-C29ea2f8.js +3 -0
- package/dist/assets/AGENTS.md +12 -13
- package/dist/commands-BQrpRKx2.js +126 -0
- package/dist/config-manager-1Zhw_Ob5.js +1 -0
- package/dist/config-manager-CecOyMub.js +1 -0
- package/dist/git-utils-CRR3iPaC.js +1 -0
- package/dist/{git-utils--i2q96hv.js → git-utils-NnZtE3nY.js} +1 -1
- package/dist/init-Dm0XBXMD.js +24 -0
- package/dist/mcp-server.js +2 -2
- package/dist/research-BY8APYWo.js +585 -0
- package/dist/research-CJ_GBjgH.js +1 -0
- package/dist/{response-language-ip84ug-k.js → response-language-29GrZl4K.js} +1 -1
- package/dist/response-language-mSXkRdue.js +1 -0
- package/dist/rolldown-runtime-BxhE39jg.js +1 -0
- package/dist/src-ZjjcZr3a.js +468 -0
- package/dist/src-xo9dUCIC.js +207 -0
- package/dist/tag-management-D4lpCywn.js +1 -0
- package/dist/task-manager-GG4EpQXs.js +168 -0
- package/dist/task-manager-gnhcGsE8.js +1 -0
- package/dist/taskgraph.js +1 -1
- package/package.json +3 -8
- package/dist/ai-services-unified-CigO4oTy.js +0 -1
- package/dist/ai-services-unified-kmQRPU0g.js +0 -3
- package/dist/assets/claude/TM_COMMANDS_GUIDE.md +0 -147
- package/dist/commands-dFNugMWF.js +0 -116
- package/dist/config-manager-C5Ih13nA.js +0 -1
- package/dist/config-manager-DhVH8AQp.js +0 -1
- package/dist/dependency-manager-CCREovZA.js +0 -758
- package/dist/git-utils-BezpEZd4.js +0 -1
- package/dist/init-p_pWjmVE.js +0 -3139
- package/dist/research-blv_5JOT.js +0 -1
- package/dist/response-language-D9UxmXBp.js +0 -1
- package/dist/src-TZm8h0X-.js +0 -207
- package/dist/src-yE1DeXKG.js +0 -468
- package/dist/tag-management-Br2FX-YC.js +0 -1
- package/dist/task-manager-DWPIhAB7.js +0 -1
- package/index.js +0 -157
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{A as e,T as t,c as n,u as r,w as i}from"./src-xo9dUCIC.js";import{t as a}from"./git-utils-NnZtE3nY.js";import o from"chalk";import s from"path";import{z as c}from"zod";import l from"dotenv";import u from"fs";import{fileURLToPath as d}from"url";const f=[`add-task`,`analyze-complexity`,`expand-task`,`parse-prd`,`research`,`research-save`,`update-subtask`,`update-task`,`update-tasks`],ee=`.taskgraph`,te=`.taskgraph/tasks`,p=`.taskgraph/docs`,ne=`.taskgraph/reports`,re=`.taskgraph/templates`,m=`.taskgraph/config.json`,ie=`.taskgraph/state.json`,h=`.taskgraph/reports/task-complexity-report.json`,ae=`.taskgraph/docs/prd.txt`,oe=`.taskgraph/templates/example_prd.txt`,g=`.taskgraph/tasks/tasks.json`,se=`.env.example`,ce=`.gitignore`,_={primary:`#0088CC`,accent:`#0096C7`,deep:`#0080C0`},le=[_.accent,_.primary,_.deep],ue=_.accent,de=[`dim`],fe={dimBorder:!0},v={brand:o.cyan,heading:o.cyan.bold,accent:o.magenta,active:o.cyan.bold,muted:o.dim,text:o};let y=!1;const pe={maxRetries:5,retryDelay:100,staleLockAge:1e4};function me(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 he(e,t,n={}){let{createIfMissing:r=!1}=n,i=s.dirname(e);if(u.existsSync(i)||u.mkdirSync(i,{recursive:!0}),r)try{u.writeFileSync(e,`{}`,{flag:`wx`})}catch(e){if(e.code!==`EEXIST`)throw e}let a=`${e}.lock`,{maxRetries:o,retryDelay:c,staleLockAge:l}=pe,d=!1;for(let e=0;e<o;e++)try{let e=JSON.stringify({pid:process.pid,timestamp:Date.now()});u.writeFileSync(a,e,{flag:`wx`}),d=!0;break}catch(t){if(t.code===`EEXIST`){try{let e=u.statSync(a);if(Date.now()-e.mtimeMs>l){let e=`${a}.stale.${process.pid}.${Date.now()}`;try{u.renameSync(a,e);try{u.unlinkSync(e)}catch{}continue}catch{}}}catch(e){if(e.code===`ENOENT`)continue;throw e}e<o-1&&me(c*2**e)}else throw t}if(!d)throw Error(`Failed to acquire lock on ${e} after ${o} attempts`);try{return t()}finally{try{u.unlinkSync(a)}catch(t){C(`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=s.join(n,`.env`);if(u.existsSync(t))try{let n=u.readFileSync(t,`utf-8`),r=l.parse(n);if(r&&r[e])return r[e]}catch(e){C(`warn`,`Could not read or parse ${t}: ${e.message}`)}}if(process.env[e])return process.env[e]}function x(e=process.cwd(),t=[`package.json`,`pyproject.toml`,`.git`]){let n=s.resolve(e),r=s.parse(n).root;for(;n!==r;){if(t.some(e=>{let t=s.join(n,e);return u.existsSync(t)}))return n;n=s.dirname(n)}return t.some(e=>{let t=s.join(r,e);return u.existsSync(t)})?r:null}const S={debug:0,info:1,warn:2,error:3,success:1};function ge(){y=!0}function _e(){y=!1}function ve(){return y}function C(e,...t){if(ve())return;let n=`info`;try{n=$e()||`info`}catch{n=`info`}let r={debug:v.muted(`[debug]`),info:``,warn:o.yellow(`⚠`),error:o.red(`✗`),success:o.green(`✓`)},i=S.hasOwnProperty(e)?e:`info`;if(S[i]>=(S[n]??S.info)){let e=r[i]||``,n=t.map(e=>typeof e==`object`?JSON.stringify(e):e).join(` `);console.log(e?`${e} ${n}`:n)}}function ye(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 be(e,t){let n=s.relative(process.cwd(),e),r=n&&!n.startsWith(`..`)&&!s.isAbsolute(n)?n:e,i=/\(line (\d+) column (\d+)\)/.exec(t.message),a=i?` (line ${i[1]}, column ${i[2]})`:``,o=Error(`${r} isn't valid JSON${a}`,{cause:t});return o.code=`JSON_PARSE_ERROR`,o}function T(e,t=null,n=null){let r=!1;try{r=$()}catch{}if(r&&console.log(`readJSON called with: ${e}, projectRoot: ${t}, tag: ${n}`),!e)return null;let i;try{i=JSON.parse(u.readFileSync(e,`utf8`)),r&&console.log(`Successfully read JSON from ${e}`)}catch(t){if(r&&console.log(`Failed to read JSON from ${e}: ${t.message}`),t instanceof SyntaxError&&s.basename(e)===`tasks.json`)throw be(e,t);return null}if(!e.includes(`tasks.json`)||!i)return r&&console.log(`File is not tasks.json or data is null, returning as-is`),i;if(Array.isArray(i.tasks)&&!i._rawTaggedData&&!ye(i)){r&&console.log(`File is in legacy format, performing migration...`),w(i.tasks);let n={master:{tasks:i.tasks,metadata:i.metadata||{created:(/* @__PURE__ */ new Date()).toISOString(),updated:(/* @__PURE__ */ new Date()).toISOString(),description:`Tasks for master context`}}};try{if(A(e,n),r&&console.log(`Successfully migrated legacy format to tagged format`),E(e),t)try{a(t,e)}catch{}O(e)}catch(e){r&&console.log(`Error writing migrated data: ${e.message}`)}i=n}if(typeof i==`object`&&!i.tasks){r&&console.log(`File is in tagged format, resolving tag...`);for(let e in i)if(i.hasOwnProperty(e)&&typeof i[e]==`object`&&i[e].tasks)try{F(i[e],{description:`Tasks for ${e} context`,skipUpdate:!0})}catch(t){r&&console.log(`Failed to ensure metadata for tag ${e}: ${t.message}`)}let o=JSON.parse(JSON.stringify(i));for(let e in o)o[e]&&Array.isArray(o[e].tasks)&&w(o[e].tasks);if(t)try{a(t,e)}catch{}try{let a=`master`;try{if(n)a=n;else if(t)a=P({projectRoot:t});else{let t=x(s.dirname(e));t&&(a=P({projectRoot:t}))}}catch(e){r&&console.log(`Tag resolution failed, using master: ${e.message}`)}r&&console.log(`Resolved tag: ${a}`);let c=i[a];if(c&&c.tasks){w(c.tasks);let e={...c,tag:a,_rawTaggedData:o};return r&&console.log(`Returning data for tag '${a}' with ${c.tasks.length} tasks`),e}{let e=i.master;return e&&e.tasks?(w(e.tasks),r&&console.log(`Tag '${a}' not found, falling back to master with ${e.tasks.length} tasks`),{...e,tag:`master`,_rawTaggedData:o}):(r&&console.log(`No valid tag data found, returning empty structure`),{tasks:[],tag:`master`,_rawTaggedData:o})}}catch(e){r&&console.log(`Error during tag resolution: ${e.message}`);let t=i.master;return t&&t.tasks?(w(t.tasks),{...t,_rawTaggedData:o}):{tasks:[],_rawTaggedData:o}}}return r&&console.log(`File format not recognized, returning as-is`),i}function E(e){try{let t=x(s.dirname(e))||s.dirname(e),n=s.join(t,`.taskgraph`,`config.json`);u.existsSync(n)&&xe(n);let r=s.join(t,`.taskgraph`,`state.json`);u.existsSync(r)||D(r),$()&&C(`debug`,`Complete tag migration performed for project: ${t}`)}catch(e){$()&&C(`warn`,`Error during complete tag migration: ${e.message}`)}}function xe(e){try{let t=u.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&&(u.writeFileSync(e,JSON.stringify(n,null,2),`utf8`),process.env.TASKGRAPH_DEBUG===`true`&&console.log(`[DEBUG] Updated config.json with tagged task system settings`))}catch(e){process.env.TASKGRAPH_DEBUG===`true`&&console.warn(`[WARN] Error migrating config.json: ${e.message}`)}}function D(e){try{let t={currentTag:`master`,lastSwitched:(/* @__PURE__ */ new Date()).toISOString(),branchTagMapping:{},migrationNoticeShown:!1};u.writeFileSync(e,JSON.stringify(t,null,2),`utf8`),process.env.TASKGRAPH_DEBUG===`true`&&console.log(`[DEBUG] Created initial state.json for tagged task system`)}catch(e){process.env.TASKGRAPH_DEBUG===`true`&&console.warn(`[WARN] Error creating state.json: ${e.message}`)}}function O(e){try{let t=s.join(s.dirname(s.dirname(e)),`state.json`);u.existsSync(t)||D(t);try{let e=u.readFileSync(t,`utf8`),n=JSON.parse(e)||{};n.migrationNoticePending=!0,n.migrationNoticeShown=!1,u.writeFileSync(t,JSON.stringify(n,null,2),`utf8`)}catch(e){process.env.TASKGRAPH_DEBUG===`true`&&console.warn(`[WARN] Error updating state for migration notice: ${e.message}`)}}catch(e){process.env.TASKGRAPH_DEBUG===`true`&&console.warn(`[WARN] Error marking migration for notice: ${e.message}`)}}let k=null;function Se(){return k||=new e,k}async function Ce(e,t){await Se().modifyJson(e,t)}function A(e,t,n=null,r=null){let i=process.env.TASKGRAPH_DEBUG===`true`;try{he(e,()=>{let a=t;if(t&&!t._rawTaggedData&&n&&Array.isArray(t.tasks)&&!ye(t)){let o=r||N(n);i&&console.log(`writeJSON: Detected resolved tag data missing _rawTaggedData. Re-reading raw data to prevent data loss for tag '${o}'.`);let s={};try{s=JSON.parse(u.readFileSync(e,`utf8`))}catch(e){i&&console.log(`writeJSON: Could not read existing file, starting fresh: ${e.message}`)}a={...s,[o]:{metadata:{...s[o]?.metadata||{},...t.metadata||{}},tasks:t.tasks}}}else if(t&&t._rawTaggedData&&n){let o=r||N(n),s;try{s=JSON.parse(u.readFileSync(e,`utf8`))}catch(e){s=t._rawTaggedData,i&&console.log(`writeJSON: Using _rawTaggedData as fallback: ${e.message}`)}if(!s[o]&&t.tag!==o)throw Error(`Tag "${o}" not found`);let{_rawTaggedData:c,tag:l,...d}=t;a={...s,[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 s=`${e}.tmp.${process.pid}`;try{u.writeFileSync(s,JSON.stringify(o,null,2),`utf8`),u.renameSync(s,e)}catch(e){try{u.existsSync(s)&&u.unlinkSync(s)}catch{}throw e}i&&console.log(`writeJSON: Successfully wrote to ${e}`)},{createIfMissing:!0})}catch(t){throw C(`error`,`Error writing JSON file ${e}:`,t.message),i&&C(`error`,`Full error details:`,t),t}}function we(e=null){let t=!1;try{t=$()}catch{t=!1}try{let n;if(n=e||s.join(process.cwd(),h),!u.existsSync(n))return t&&C(`debug`,`Complexity report not found at ${n}`),null;let r=T(n);return t&&C(`debug`,`Successfully read complexity report from ${n}`),r}catch(e){return t&&C(`error`,`Error reading complexity report: ${e.message}`),null}}function j(e,t){return!e||!e.complexityAnalysis||!Array.isArray(e.complexityAnalysis)?null:e.complexityAnalysis.find(e=>e.taskId===t)}function M(e,t){let n;n=e.isSubtask?e.parentTask.id:e.parentId?e.parentId:e.id;let r=j(t,n);r&&(e.complexityScore=r.complexityScore)}function Te(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 Ee(e){return typeof e==`string`&&e.includes(`.`)?e:typeof e==`number`?e.toString():e}function De(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&&M(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&&M(i,n),{task:i,originalSubtaskCount:a,originalSubtasks:o}}function Oe(e,t){return!e||e.length<=t?e:`${e.slice(0,t-3)}...`}function ke(e){return Array.isArray(e)?e.length===0:typeof e==`object`&&e?Object.keys(e).length===0:!1}function Ae(e,t,n={}){let{maxDepth:r=50,includeSelf:i=!1,direction:a=`forward`,logger:o=null}=n,s=/* @__PURE__ */ new Set,c=/* @__PURE__ */ 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):C!==void 0&&C.warn?C.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):C!==void 0&&C.warn?C.warn(t):console.warn(t)}else 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 je(e,t){if(!e||e.length===0)return null;let n={timestamp:(/* @__PURE__ */ new Date()).toISOString(),userId:e[0].userId,commandName:t,modelUsed:`Multiple`,providerName:`Multiple`,inputTokens:0,outputTokens:0,cachedInputTokens:0,totalTokens:0,totalCost:0,currency:e[0].currency||`USD`},r=/* @__PURE__ */ new Set,i=/* @__PURE__ */ new Set,a=/* @__PURE__ */ new Set;return e.forEach(e=>{n.inputTokens+=e.inputTokens||0,n.outputTokens+=e.outputTokens||0,n.cachedInputTokens+=e.cachedInputTokens||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 N(e){if(!e)throw Error(`projectRoot is required for getCurrentTag`);try{let t=s.join(e,`.taskgraph`,`state.json`);if(u.existsSync(t)){let e=u.readFileSync(t,`utf8`),n=JSON.parse(e);if(n&&n.currentTag)return n.currentTag}}catch{}try{let t=s.join(e,`.taskgraph`,`config.json`);if(u.existsSync(t)){let e=u.readFileSync(t,`utf8`),n=JSON.parse(e);if(n&&n.global&&n.global.defaultTag)return n.global.defaultTag}}catch{}return`master`}function P(e={}){let{projectRoot:t,tag:n}=e;if(!t)throw Error(`projectRoot is required for resolveTag`);return n||N(t)}function Me(e,t){return!e||!t?[]:e[t]&&e[t].tasks&&Array.isArray(e[t].tasks)?e[t].tasks:[]}function Ne(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 F(e,t={}){if(!e||typeof e!=`object`)throw Error(`tagObj must be a valid object`);let n=(/* @__PURE__ */ 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 Pe(){return{info:(e,...t)=>C(`info`,e,...t),warn:(e,...t)=>C(`warn`,e,...t),error:(e,...t)=>C(`error`,e,...t),debug:(e,...t)=>C(`debug`,e,...t),success:(e,...t)=>C(`success`,e,...t)}}function I(e=null){return e||Pe()}function L(e){return r(e)}function R(e=process.cwd()){return n(e)}function Fe(e=null,t=null,n=null){let r=I(n),i=t?.projectRoot||R();if(!i)return r.warn?.(`Could not determine project root directory`),null;let a=L(i);if(e){let t=s.isAbsolute(e)?e:s.resolve(a,e);if(u.existsSync(t))return r.info?.(`Using explicit tasks path: ${t}`),t;r.warn?.(`Explicit tasks path not found: ${t}, trying fallbacks`)}let o=s.join(a,g);return u.existsSync(o)?(r.info?.(`Found tasks file at: ${o}`),o):(r.warn?.(`No tasks.json found in project: ${a}`),null)}function Ie(e=null,t=null,n=null){let r=I(n);if(e){let t=process.env.TASKGRAPH_ORIGINAL_CWD||process.cwd(),n=s.isAbsolute(e)?e:s.resolve(t,e);if(u.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||R();if(!i)return r.warn?.(`Could not determine project root directory`),null;let a=L(i);for(let e of[`PRD.md`,`prd.md`,`PRD.txt`,`prd.txt`]){let t=s.join(a,p,e);if(u.existsSync(t))return r.info?.(`Found PRD document at: ${t}`),t}return r.warn?.(`No PRD document found in project: ${a}`),null}function Le(e=null,t=null,n=null){let r=I(n);if(e){let t=process.env.TASKGRAPH_ORIGINAL_CWD||process.cwd(),n=s.isAbsolute(e)?e:s.resolve(t,e);if(u.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||R();if(!i)return r.warn?.(`Could not determine project root directory`),null;let a=L(i),o=[`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){let t=s.join(a,ne,e);if(u.existsSync(t))return r.info?.(`Found complexity report at: ${t}`),t}return r.warn?.(`No complexity report found in project: ${a}`),null}function Re(e=null,t=null,n=null){let r=I(n),i=t?.tag;if(e){let t=process.env.TASKGRAPH_ORIGINAL_CWD||process.cwd(),n=s.isAbsolute(e)?e:s.resolve(t,e);return r.info?.(`Using explicit complexity report output path: ${n}`),n}let a=L(t?.projectRoot||R()||process.cwd()),o=`task-complexity-report.json`;i&&i!==`master`&&(o=`task-complexity-report_${i}.json`);let c=s.join(a,`.taskgraph/reports`,o);r.info?.(`Using tag-aware complexity report output path: ${c}`);let l=s.dirname(c);return u.existsSync(l)||(r.info?.(`Creating reports directory: ${l}`),u.mkdirSync(l,{recursive:!0})),c}function z(e=null,t=null,n=null){let r=I(n);if(e){let t=process.env.TASKGRAPH_ORIGINAL_CWD||process.cwd(),n=s.isAbsolute(e)?e:s.resolve(t,e);if(u.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||R();if(!i)return r.warn?.(`Could not determine project root directory`),null;let a=L(i),o=s.join(a,m);if(u.existsSync(o))return o;if(!W()){let e=`config_warning_${a}`;global._tmConfigWarningsThisRun||(global._tmConfigWarningsThisRun=/* @__PURE__ */ new Set),global._tmConfigWarningsThisRun.has(e)||(global._tmConfigWarningsThisRun.add(e),r.debug?.(`No configuration file found in project: ${a}`))}return null}var B={"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}]};const ze=d(import.meta.url);s.dirname(ze);const V={models:{main:{provider:`claude-code`,modelId:`sonnet`,maxTokens:64e3,temperature:.2},research:{provider:`claude-code`,modelId:`sonnet`,maxTokens:8700,temperature:.1},fallback:{provider:`claude-code`,modelId:`sonnet`,maxTokens:64e3,temperature:.2}},global:{logLevel:`info`,debug:!1,defaultNumTasks:10,defaultSubtasks:5,defaultPriority:`medium`,projectName:`TaskGraph`,responseLanguage:`English`,enableCodebaseAnalysis:!0,enableProxy:!1},claudeCode:{}};let H=null,U=null;function Be(e){global._tmSuppressConfigWarnings=e}function W(){return global._tmSuppressConfigWarnings===!0}var Ve=class extends Error{constructor(e){super(e),this.name=`ConfigurationError`}};function He(e=null){let t=V,n=e;e&&`${e}`,n||(n=x(),n||=process.cwd(),`${n}`);let r=null,i={...t};if(u.existsSync(s.join(n,`.taskgraph`))&&(r=z(null,{projectRoot:n})),r)try{let e=u.readFileSync(r,`utf-8`),n=JSON.parse(e);i={models:{main:{...t.models.main,...n?.models?.main},research:{...t.models.research,...n?.models?.research},fallback:n?.models?.fallback?.provider&&n?.models?.fallback?.modelId?{...t.models.fallback,...n.models.fallback}:{...t.models.fallback}},global:{...t.global,...n?.global},claudeCode:{...t.claudeCode,...n?.claudeCode}},`${r}`,q(i.models.main.provider)||(console.warn(o.yellow(`Warning: Invalid main provider "${i.models.main.provider}" in ${r}. Falling back to default. Run 'taskgraph models --setup' to choose a Claude Code model.`)),i.models.main={...t.models.main}),q(i.models.research.provider)||(console.warn(o.yellow(`Warning: Invalid research provider "${i.models.research.provider}" in ${r}. Falling back to default. Run 'taskgraph models --setup' to choose a Claude Code model.`)),i.models.research={...t.models.research}),i.models.fallback?.provider&&!q(i.models.fallback.provider)&&(console.warn(o.yellow(`Warning: Invalid fallback provider "${i.models.fallback.provider}" in ${r}. Fallback model configuration will be ignored. Run 'taskgraph models --setup' to choose a Claude Code model.`)),i.models.fallback.provider=void 0,i.models.fallback.modelId=void 0),i.claudeCode&&!ke(i.claudeCode)&&(i.claudeCode=J(i.claudeCode))}catch(e){console.error(o.red(`Error reading or parsing ${r}: ${e.message}. Using default configuration.`)),i={...t},`${r}`}else(e||u.existsSync(s.join(n,`.taskgraph/tasks/tasks.json`)))&&!W()&&Ue(e||n),i={...t},`${n}`;return i}const G=/* @__PURE__ */ new Set;function Ue(e){G.has(e)||(G.add(e),console.warn(`${o.yellow(`⚠`)} No .taskgraph/config.json in ${e}; using default settings\n`+o.dim(` Run taskgraph init to recreate it`)))}function K(e=null,t=!1){if(!H||t||e&&e!==U){let n=He(e);return(t||e)&&(H=n,U=e),n}return H}function q(e){return!!t.includes(e)}function We(e){return B[e]?B[e].filter(e=>e.supported!==!1).map(e=>e.id):[]}function J(e){let t=c.object({pathToClaudeCodeExecutable:c.string().optional(),maxTurns:c.number().int().positive().optional(),customSystemPrompt:c.string().optional(),appendSystemPrompt:c.string().optional(),permissionMode:c.enum([`default`,`acceptEdits`,`plan`,`bypassPermissions`]).optional(),allowedTools:c.array(c.string()).optional(),disallowedTools:c.array(c.string()).optional(),mcpServers:c.record(c.string(),c.object({type:c.enum([`stdio`,`sse`]).optional(),command:c.string(),args:c.array(c.string()).optional(),env:c.record(c.string(),c.string()).optional(),url:c.url().optional(),headers:c.record(c.string(),c.string()).optional()})).optional()}),n=c.record(c.string(),t).refine(e=>Object.keys(e||{}).every(e=>f.includes(e)),{message:`Invalid command name in commandSpecific`}),r=t.extend({commandSpecific:n.optional()}),i={};try{i=r.parse(e)}catch(e){console.warn(o.yellow(`Warning: Invalid Claude Code settings in config: ${e.message}. Falling back to default.`)),i={}}return i}function Y(e=null,t=!1){let n=K(e,t);return{...V.claudeCode,...n?.claudeCode||{}}}function Ge(e,t=null,n=!1){let r=Y(t,n),i=r?.commandSpecific||{};return{...r,...i[e]}}function X(e,t=null){return K(t)?.models?.[e]||(C(`warn`,`No model configuration found for role: ${e}. Returning default.`),V.models[e]||{})}function Z(e=null){return X(`main`,e).provider}function Ke(e=null){return X(`main`,e).modelId}function qe(e=null){return X(`research`,e).provider}function Je(e=null,t=null){let n=b(`TASKGRAPH_ENABLE_CODEBASE_ANALYSIS`,e,t);if(n!=null&&n!==``)return n.toLowerCase()===`true`||n===`1`;if(e?.env?.TASKGRAPH_ENABLE_CODEBASE_ANALYSIS){let t=e.env.TASKGRAPH_ENABLE_CODEBASE_ANALYSIS;return t.toLowerCase()===`true`||t===`1`}return Q(t).enableCodebaseAnalysis!==!1}function Ye(e=!1,t=null,n=null){return!Je(n,t)||e?!1:(e?qe(t):Z(t))===i.CLAUDE_CODE}function Xe(e=null){return X(`research`,e).modelId}function Ze(e=null){return X(`fallback`,e).provider}function Qe(e=null){return X(`fallback`,e).modelId}function Q(e=null){let t=K(e);return{...V.global,...t?.global||{}}}function $e(e=null){return Q(e).logLevel.toLowerCase()}function $(e=null){return Q(e).debug===!0}function et(e=null){let t=Q(e).defaultSubtasks,n=parseInt(t,10);return Number.isNaN(n)?V.global.defaultSubtasks:n}function tt(e=null){let t=Q(e).defaultNumTasks,n=parseInt(t,10);return Number.isNaN(n)?V.global.defaultNumTasks:n}function nt(e=null){return Q(e).defaultPriority}function rt(e=null){return Q(e).projectName}function it(e=null){return Q(e).responseLanguage}function at(e=null){return Q(e).enableProxy===!0}function ot(e=null,t=null){let n=b(`TASKGRAPH_ENABLE_PROXY`,e,t);if(n!=null&&n!==``)return n.toLowerCase()===`true`||n===`1`;if(e?.env?.TASKGRAPH_ENABLE_PROXY){let t=e.env.TASKGRAPH_ENABLE_PROXY;return t.toLowerCase()===`true`||t===`1`}return at(t)}function st(e,t=null){let n=X(e,t),r=n.maxTokens,i=n.temperature,a=n.modelId,o=n.provider,s=r,c=i;try{let e=B[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),C(`debug`,`Applying model-specific max_tokens (${e}) for ${a}. Effective limit: ${s}`)}else C(`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,C(`debug`,`Applying model-specific temperature (${t.temperature}) for ${a}`))}else C(`debug`,`No model definitions found for provider ${o} in MODEL_MAP. Using role default maxTokens: ${r}`)}catch(e){C(`warn`,`Error looking up model-specific parameters for ${a}: ${e.message}. Using role defaults.`),s=r,c=i}return{maxTokens:s,temperature:c}}function ct(){let e=[];for(let[t,n]of Object.entries(B))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||=r.split(`-`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `),e.push({id:r,name:s,provider:t,swe_score:i,cost_per_1m_tokens:a,allowed_roles:o,max_tokens:n.max_tokens})});return e}function lt(e,t=null){let n=t;if(t==null){let e=x();if(!e)return console.error(o.red(`Error: Could not determine project root. Configuration not saved.`)),!1;n=e}let r=s.join(n,`.taskgraph`),i=s.join(r,`config.json`);try{return u.existsSync(r)||u.mkdirSync(r,{recursive:!0}),u.writeFileSync(i,JSON.stringify(e,null,2)),H=e,!0}catch(e){return console.error(o.red(`Error writing configuration to ${i}: ${e.message}`)),!1}}function ut(e=null){return z(null,{projectRoot:e})!==null}function dt(e=null){let t=K(e);return t.global||={},t.global.userId||(t.global.userId=`1234567890`,lt(t,e)||C(`warning`,`Failed to write updated configuration with new userId. Please let the developers know.`)),t.global.userId}export{C as $,q as A,M as B,Ye as C,ee as Ct,ot as D,te as Dt,W as E,ie as Et,Ie as F,x as G,_e as H,R as I,Ne as J,De as K,Fe as L,B as M,Le as N,Be as O,g as Ot,z as P,ve as Q,L as R,dt as S,m as St,ut as T,ne as Tt,ge as U,je as V,F as W,N as X,Ee as Y,Me as Z,at as _,h as _t,K as a,b as at,it as b,ce as bt,nt as c,Ae as ct,Ze as d,le as dt,O as et,$e as f,ue as ft,rt as g,v as gt,st as h,de as ht,Ge as i,T as it,lt as j,J as k,re as kt,et as l,Oe as lt,Z as m,fe as mt,ct as n,E as nt,$ as o,P as ot,Ke as p,_ as pt,j as q,Y as r,we as rt,tt as s,Te as st,Ve as t,Ce as tt,Qe as u,A as ut,Xe as v,se as vt,Je as w,p as wt,We as x,ae as xt,qe as y,oe as yt,Re as z};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{n as getCurrentBranch,i as isGitRepository,a as isValidBranchForTag,o as sanitizeBranchNameForTag}from"./git-utils-NnZtE3nY.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import"path";import{exec as e,execSync as t}from"child_process";import{promisify as n}from"util";import"fs";const r=n(e);async function i(e){if(!e)throw Error(`projectRoot is required for isGitRepository`);try{return await r(`git rev-parse --git-dir`,{cwd:e}),!0}catch{return!1}}async function a(e){if(!e)throw Error(`projectRoot is required for getCurrentBranch`);try{let{stdout:t}=await r(`git rev-parse --abbrev-ref HEAD`,{cwd:e});return t.trim()}catch{return null}}function o(e){return!e||typeof e!=`string`?`unknown-branch`:e.replace(/[^a-zA-Z0-9_-]/g,`-`).replace(/^-+|-+$/g,``).replace(/-+/g,`-`).toLowerCase().substring(0,50)}function s(e){if(!e||typeof e!=`string`||[`main`,`master`,`develop`,`dev`,`
|
|
1
|
+
import"path";import{exec as e,execSync as t}from"child_process";import{promisify as n}from"util";import"fs";const r=n(e);async function i(e){if(!e)throw Error(`projectRoot is required for isGitRepository`);try{return await r(`git rev-parse --git-dir`,{cwd:e}),!0}catch{return!1}}async function a(e){if(!e)throw Error(`projectRoot is required for getCurrentBranch`);try{let{stdout:t}=await r(`git rev-parse --abbrev-ref HEAD`,{cwd:e});return t.trim()}catch{return null}}function o(e){return!e||typeof e!=`string`?`unknown-branch`:e.replace(/[^a-zA-Z0-9_-]/g,`-`).replace(/^-+|-+$/g,``).replace(/-+/g,`-`).toLowerCase().substring(0,50)}function s(e){if(!e||typeof e!=`string`||[`main`,`master`,`develop`,`dev`,`head`].includes(e.toLowerCase()))return!1;let t=o(e);return t.length>0&&t!==`unknown-branch`}function c(e,t){}function l(){try{return t(`git rev-parse --is-inside-work-tree`,{stdio:`ignore`,cwd:process.cwd()}),!0}catch{return!1}}export{s as a,i,a as n,o,l as r,c as t};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import{t as e}from"./rolldown-runtime-BxhE39jg.js";import{$ as t,Ct as n,Dt as r,Et as i,M as a,Ot as o,Q as s,St as c,Tt as l,bt as u,gt as d,kt as f,vt as p,wt as ee,yt as te}from"./config-manager-CecOyMub.js";import{r as m}from"./git-utils-NnZtE3nY.js";import{G as h,I as ne}from"./src-ZjjcZr3a.js";import g from"chalk";import{join as _}from"node:path";import v from"path";import{execSync as y}from"child_process";import{existsSync as b,readdirSync as x,rmSync as S,rmdirSync as C,statSync as re}from"node:fs";import w from"fs";import{fileURLToPath as ie}from"url";import T from"readline";import ae from"os";import{randomUUID as oe}from"crypto";const E=[`claude`];function se(e){return e.filter(e=>!ce(e))}function ce(e){return E.includes(e)}const D=`tasks.json`,O=`tasks/`;function k(e){return e.trim().replace(/^#/,``).trim()}function A(e){let t=k(e);return t===`tasks.json`||t===`tasks/`}function le(e,t){return e.map(e=>{if(A(e)){let n=k(e),r=e.match(/\s*$/)[0];return t?`# ${n}${r}`:`${n}${r}`}return e})}function ue(e){let t=[],n=!1;for(let r of e)r.trim()===`# Task files`?n=!0:A(r)||(!n||r.trim())&&(n&&r.trim()&&!A(r)&&(n=!1),n||t.push(r));return t}function de(e,t){return e.filter(e=>{let n=e.trim();return!n||A(e)||n===`# Task files`?!1:!t.has(n)})}function j(e){let t=[`# Task files`];return e?t.push(`# ${D}`,`# ${O} `):t.push(D,`${O} `),t}function fe(e,t){if(e.some(A))return e;let n=[...e];for(;n.length>0&&!n[n.length-1].trim();)n.pop();return M(n),n.push(...j(t)),n}function M(e){if(e.some(e=>e.trim())){let t=e[e.length-1];t&&t.trim()&&e.push(``)}}function pe(e,t,n){if(!e||typeof e!=`string`)throw Error(`targetPath must be a non-empty string`);if(!e.endsWith(`.gitignore`))throw Error(`targetPath must end with .gitignore`);if(!t||typeof t!=`string`)throw Error(`content must be a non-empty string`);if(typeof n!=`boolean`)throw Error(`storeTasksInGit must be a boolean`)}function me(e,t,n){try{w.writeFileSync(e,t.join(`
|
|
2
|
+
`)+`
|
|
3
|
+
`),typeof n==`function`&&n(`success`,`Created ${e} with full template`)}catch(t){throw typeof n==`function`&&n(`error`,`Failed to create ${e}: ${t.message}`),t}}function he(e,t,n,r){try{let i=ue(w.readFileSync(e,`utf8`).split(`
|
|
4
|
+
`)),a=de(t,new Set(i.map(e=>e.trim()).filter(e=>e))),o=[...i];a.length>0&&(M(o),o.push(...a)),M(o),o.push(...j(n)),w.writeFileSync(e,o.join(`
|
|
5
|
+
`)+`
|
|
6
|
+
`),typeof r==`function`&&r(`debug`,`Updated ${e} according to user preference${a.length>0?` and merged new content`:``}`)}catch(t){throw typeof r==`function`&&r(`error`,`Failed to merge content with ${e}: ${t.message}`),t}}function ge(e){try{if(!w.existsSync(e))return;let t=w.readFileSync(e,`utf8`).split(`
|
|
7
|
+
`).find(e=>k(e)===D);return t===void 0?void 0:t.trim().startsWith(`#`)}catch{return}}function _e(e,t,n=!0,r=null){pe(e,t,n);let i=le(t.split(`
|
|
8
|
+
`),n);w.existsSync(e)?he(e,i,n,r):me(e,fe(i,n),r)}const ve=ie(import.meta.url),N=v.dirname(ve);function P(){let e=[v.join(N,`assets`),v.join(N,`..`,`assets`),v.join(N,`..`,`..`,`public`,`assets`),v.join(process.cwd(),`assets`),v.join(process.cwd(),`node_modules`,`taskgraph-ai`,`dist`,`assets`),v.join(process.cwd(),`node_modules`,`taskgraph-ai`,`assets`)];for(let t of e)if(w.existsSync(t)){let e=v.join(t,`AGENTS.md`);if(w.existsSync(e))return t}throw Error(`Assets directory not found. This is likely a packaging issue.`)}function F(e){let t=P();return v.join(t,e)}function ye(e){try{let t=F(e);return w.existsSync(t)}catch{return!1}}function I(e,t=`utf8`){let n=F(e);return w.readFileSync(n,t)}const L=`taskgraph-ai`;function be(e){return Array.isArray(e?.args)&&e.args.some(e=>typeof e==`string`&&e.includes(`taskgraph-ai`))}function R(e){let t=JSON.stringify(e,null,` `);return t=t.replace(/(\[\n\t+)([^[\]]+?)(\n\t+\])/g,(e,t,n,r)=>!n.includes(`{`)&&!n.includes(`[`)?`[${n.replace(/\n\t+/g,` `).replace(/\s+/g,` `).trim()}]`:e),t}function xe(e,n){if(!n){t(`debug`,`[MCP Config] No mcpConfigPath provided, skipping MCP configuration setup`);return}let r=v.join(e,n),i=v.dirname(r);t(`debug`,`Setting up MCP configuration at ${r}...`);let a={[L]:{command:`npx`,args:[`-y`,L],env:{TASKGRAPH_TOOLS:`core`}}};if(w.existsSync(i)||w.mkdirSync(i,{recursive:!0}),w.existsSync(r)){t(`debug`,`MCP configuration file already exists, checking for existing taskgraph-ai...`);try{let e=JSON.parse(w.readFileSync(r,`utf8`));if(e.mcpServers||={},Object.values(e.mcpServers).some(be)){t(`debug`,`Found existing taskgraph-ai MCP configuration in mcp.json, leaving untouched`);return}e.mcpServers[`taskgraph-ai`]?t(`debug`,`taskgraph-ai server already configured in mcp.json`):(e.mcpServers[L]=a[L],t(`debug`,`Added taskgraph-ai server to existing MCP configuration`)),w.writeFileSync(r,R(e)+`
|
|
9
|
+
`),t(`debug`,`Updated MCP configuration file`)}catch(e){t(`error`,`Failed to update MCP configuration: ${e.message}`);let n=`${r}.backup-${Date.now()}`;w.existsSync(r)&&(w.copyFileSync(r,n),t(`warn`,`Saved the old file as ${n}`));let i={mcpServers:a};w.writeFileSync(r,R(i)+`
|
|
10
|
+
`),t(`warn`,`Created new MCP configuration file (backup of original file was created if it existed)`)}}else{let e={mcpServers:a};w.writeFileSync(r,R(e)+`
|
|
11
|
+
`),t(`debug`,`Created MCP configuration file at ${r}`)}t(`debug`,`MCP server will use the installed taskgraph-ai package`)}function Se(e){let{name:t,displayName:n=t,profileDir:r=`.${t.toLowerCase()}`,rulesDir:i=`${r}/rules`,mcpConfig:a=!0,mcpConfigName:o=a?`mcp.json`:null,fileMap:s={},onAdd:c,onPostConvert:l}=e;return{profileName:t,displayName:n,profileDir:r,rulesDir:i,mcpConfig:a,mcpConfigName:o,mcpConfigPath:o?v.join(r,o):null,fileMap:s,...c&&{onAddRulesProfile:c},...l&&{onPostConvertRulesProfile:l}}}function Ce(){let e=ae.homedir(),t=process.env.SHELL||``;if(t.includes(`zsh`))return v.join(e,`.zshrc`);if(t.includes(`bash`)){let t=v.join(e,`.bash_profile`);return process.platform===`darwin`?t:v.join(e,`.bashrc`)}if(t.includes(`fish`))return v.join(e,`.config`,`fish`,`config.fish`);if(process.platform===`win32`){if(process.env.PSModulePath){let t=process.env.PROFILE||v.join(e,`Documents`,`WindowsPowerShell`,`Microsoft.PowerShell_profile.ps1`),n=v.join(e,`Documents`,`PowerShell`,`Microsoft.PowerShell_profile.ps1`);return w.existsSync(n)?n:w.existsSync(t)?t:n}let t=v.join(e,`.bashrc`);if(w.existsSync(t))return t}let n=v.join(e,`.zshrc`);if(w.existsSync(n))return n;let r=v.join(e,`.bashrc`);return w.existsSync(r)?r:null}function z(e){return e.endsWith(`.ps1`)}function B(e){return e.includes(`config.fish`)}function we(e,t,n){if(!/^[A-Z_][A-Z0-9_]*$/i.test(e))return{success:!1,message:`Invalid environment variable name: ${e}. Must start with a letter or underscore and contain only alphanumeric characters and underscores.`};if(typeof t!=`string`||t.includes(`
|
|
12
|
+
`)||t.includes(`\r`))return{success:!1,message:`Invalid value: must be a single-line string without newlines`};let r=Ce();if(!r)return{success:!1,message:`Could not determine shell type (zsh, bash, fish, or PowerShell)`};try{let i=v.dirname(r);if(w.existsSync(i)||w.mkdirSync(i,{recursive:!0}),!w.existsSync(r)){let e=process.platform===`darwin`&&r.endsWith(`.bash_profile`);if(z(r)||e)w.writeFileSync(r,``);else return{success:!1,shellConfigFile:r,message:`Shell config file ${r} not found`}}let a=w.readFileSync(r,`utf8`),o;if(o=z(r)?RegExp(`^\\s*\\$env:${e}\\s*=`,`m`).test(a):B(r)?RegExp(`^\\s*set\\s+-[gux]*x[gux]*\\s+${e}\\s+`,`m`).test(a):RegExp(`^\\s*export\\s+${e}\\s*=`,`m`).test(a),o)return{success:!0,shellConfigFile:r,message:`${e} already configured`,alreadyExists:!0};let s,c;z(r)?(s=`$env:${e} = "${t.replace(/["`$]/g,"`$&")}"`,c=`#`):B(r)?(s=`set -gx ${e} '${t.replace(/'/g,`'\\''`)}'`,c=`#`):(s=`export ${e}='${t.replace(/'/g,`'\\''`)}'`,c=`#`);let l=`\n${n?`${c} ${n}\n`:``}${s}\n`;return w.appendFileSync(r,l),{success:!0,shellConfigFile:r,message:`Added ${e} to ${r}`}}catch(e){return{success:!1,shellConfigFile:r,message:`Failed to modify shell config: ${e.message}`}}}function Te(){return we(`ENABLE_EXPERIMENTAL_MCP_CLI`,`true`,`Claude Code deferred MCP loading (added by TaskGraph)`)}const V=[`task`,`master`].join(``),Ee=[`parse-prd`,`parse-prd-with-research`,`analyze-complexity`,`complexity-report`,`expand-task`,`expand-all-tasks`,`add-task`,`add-subtask`,`remove-task`,`remove-subtask`,`remove-subtasks`,`remove-all-subtasks`,`convert-task-to-subtask`,`add-dependency`,`remove-dependency`,`fix-dependencies`,`validate-dependencies`,`setup-models`,`view-models`,`install-taskgraph`,`quick-install-taskgraph`,`to-review`,`to-deferred`,`to-cancelled`,`init-project`,`init-project-quick`,`show-task`,`graph`,`list-tasks`,`list-tasks-with-subtasks`,`list-tasks-by-status`,`project-status`,`next-task`,`help`,`to-done`,`to-pending`,`to-in-progress`,`update-task`,`update-single-task`,`update-tasks-from-id`,`tm-main`,`smart-workflow`,`learn`,`command-pipeline`,`auto-implement-tasks`,`analyze-project`,`sync-readme`,`index`,`clear-subtasks`,`clear-all-subtasks`,`generate-tasks`,`install-${V}`,`quick-install-${V}`],De=new Set(Ee.map(e=>`${e}.md`));function H(e,t,n){for(let r of x(e,{withFileTypes:!0})){let i=_(e,r.name),a=t?`${t}/${r.name}`:r.name;r.isDirectory()?(H(i,a,n),x(i).length===0&&C(i)):De.has(r.name)&&(S(i),n.push(a))}}function Oe(e){let t=_(e,`.claude`,`commands`,`tm`),n=[];return!b(t)||!re(t).isDirectory()||(H(t,``,n),x(t).length===0&&C(t)),{removed:n}}function ke(e,n){try{let{removed:n}=Oe(e);n.length>0&&t(`debug`,`[Claude] Removed ${n.length} old slash command files from .claude/commands/tm`)}catch(e){t(`error`,`[Claude] Failed to remove old slash command files: ${e.message}`)}let r=v.join(n,`AGENTS.md`),i=v.join(e,`CLAUDE.md`),a=v.join(e,`.taskgraph`,`CLAUDE.md`),o=`@./.taskgraph/CLAUDE.md`,s=`\n## TaskGraph Instructions\n**Import TaskGraph's development workflow commands and guidelines, treat as if import is in the main CLAUDE.md file.**\n${o}`;if(w.existsSync(r))try{let n=v.join(e,`.taskgraph`);if(w.existsSync(n)||w.mkdirSync(n,{recursive:!0}),w.copyFileSync(r,a),t(`debug`,`[Claude] Created TaskGraph instructions at ${a}`),w.existsSync(i)){let e=w.readFileSync(i,`utf8`);if(e.includes(o))t(`debug`,`[Claude] TaskGraph import already present in ${i}`);else{let n=e.trim()+`
|
|
13
|
+
`+s+`
|
|
14
|
+
`;w.writeFileSync(i,n),t(`debug`,`[Claude] Added TaskGraph import to existing ${i}`)}}else{let e=`# Claude Code Instructions\n${s}\n`;w.writeFileSync(i,e),t(`debug`,`[Claude] Created ${i} with TaskGraph import`)}}catch(e){t(`error`,`[Claude] Failed to set up Claude instructions: ${e.message}`)}let c=Te();c.success?c.alreadyExists?t(`debug`,`[Claude] Deferred MCP loading already configured`):t(`debug`,`[Claude] Enabled deferred MCP loading in ${c.shellConfigFile}`):t(`debug`,`[Claude] Could not configure deferred loading: ${c.message}`)}function Ae(e){let t={};if(e.mcpServers){t.mcpServers={};for(let[n,r]of Object.entries(e.mcpServers)){let e={};e.type=`stdio`,r.command&&(e.command=r.command),r.args&&(e.args=r.args),r.env&&(e.env=r.env),Object.keys(r).forEach(t=>{[`command`,`args`,`env`,`type`].includes(t)||(e[t]=r[t])}),t.mcpServers[n]=e}}return t}function je(e,n){let r=v.join(e,`.mcp.json`);if(w.existsSync(r))try{let e=Ae(JSON.parse(w.readFileSync(r,`utf8`)));w.writeFileSync(r,JSON.stringify(e,null,` `)+`
|
|
15
|
+
`),t(`debug`,`[Claude] Transformed MCP configuration to Claude format at ${r}`)}catch(e){t(`error`,`[Claude] Failed to transform MCP configuration: ${e.message}`)}}const Me=Se({name:`claude`,displayName:`Claude Code`,profileDir:`.`,rulesDir:`.`,mcpConfigName:`.mcp.json`,fileMap:{"AGENTS.md":`.taskgraph/CLAUDE.md`},onAdd:ke,onPostConvert:je});var Ne=/* @__PURE__ */ e({claudeProfile:()=>Me});function Pe(e){return E.includes(e)}function Fe(e){if(!Pe(e))return null;let t=Ne[`${e}Profile`];if(!t)throw Error(`Profile not found: static import missing for '${e}'. Valid profiles: ${E.join(`, `)}`);return t}function Ie(e,n){let r=v.join(e,n.rulesDir),i=0;if(typeof n.onAddRulesProfile==`function`)try{n.onAddRulesProfile(r,P()),t(`debug`,`[Rule Transformer] Called onAddRulesProfile for ${n.profileName}`)}catch(e){t(`error`,`[Rule Transformer] onAddRulesProfile failed for ${n.profileName}: ${e.message}`),i++}if(n.mcpConfig!==!1)try{xe(e,n.mcpConfigPath),t(`debug`,`[Rule Transformer] Setup MCP configuration for ${n.profileName}`)}catch(e){t(`error`,`[Rule Transformer] MCP setup failed for ${n.profileName}: ${e.message}`)}if(typeof n.onPostConvertRulesProfile==`function`)try{n.onPostConvertRulesProfile(r,P()),t(`debug`,`[Rule Transformer] Called onPostConvertRulesProfile for ${n.profileName}`)}catch(e){t(`error`,`[Rule Transformer] onPostConvertRulesProfile failed for ${n.profileName}: ${e.message}`)}return{success:1,failed:i}}function Le(e){try{let t=JSON.parse(w.readFileSync(e,`utf-8`));for(let e of[`main`,`research`,`fallback`])if(t.models&&t.models[e]){let n=t.models[e].provider,r=t.models[e].modelId;if(a[n]){let i=a[n].find(e=>e.id===r);i&&i.max_tokens&&(t.models[e].maxTokens=i.max_tokens)}}return w.writeFileSync(e,JSON.stringify(t,null,2)),!0}catch(e){return console.error(`Error updating config maxTokens:`,e.message),!1}}const U=`alias tm='taskgraph'`,W=`ENABLE_EXPERIMENTAL_MCP_CLI`,G={debug:0,info:1,warn:2,error:3,success:4},Re=process.env.TASKGRAPH_LOG_LEVEL?G[process.env.TASKGRAPH_LOG_LEVEL.toLowerCase()]:G.info;function ze(){s()||h()}function K(e,...t){let n={debug:d.muted(`•`),info:d.brand(`→`),warn:g.yellow(`!`),error:g.red(`✗`),success:g.green(`✓`)};if(G[e]>=Re){let r=n[e]||``;s()||(e===`error`?console.error(r,g.red(...t)):e===`warn`?console.warn(r,g.yellow(...t)):e===`success`?console.log(r,g.green(...t)):e===`info`?console.log(r,d.brand(...t)):console.log(r,...t))}if(process.env.DEBUG===`true`){let n=`[${e.toUpperCase()}] ${t.join(` `)}\n`;w.appendFileSync(`init-debug.log`,n)}}function Be(e,...t){K(e===`warn`||e===`error`?e:`debug`,...t)}function q(e){w.existsSync(e)||(w.mkdirSync(e,{recursive:!0}),K(`debug`,`Created directory: ${e}`))}function J(){let e=process.env.HOME||process.env.USERPROFILE;return e?[`.zshrc`,`.bashrc`,`.bash_profile`,`.profile`].map(t=>v.join(e,t)):[]}function Ve(e){return[v.join(e,n),v.join(e,c),v.join(e,o),v.join(e,`.git`),v.join(e,u),v.join(e,p),v.join(e,`CLAUDE.md`),v.join(e,`.mcp.json`),...J()]}function Y(e){let t=/* @__PURE__ */ new Map;for(let n of e){let e=null;try{w.existsSync(n)&&(e=w.statSync(n).isDirectory()?``:w.readFileSync(n,`utf8`))}catch{e=null}t.set(n,e)}return t}function He(e,t,r){let i=t=>v.join(e,t),a=e=>t.get(e)==null&&r.get(e)!=null,o=e=>t.get(e)!=null&&r.get(e)!=null&&t.get(e)!==r.get(e),s=t.get(i(`.taskgraph/config.json`))!=null||t.get(i(`.taskgraph/tasks/tasks.json`))!=null,l=[];!s&&r.get(i(`.taskgraph/config.json`))!=null?l.push({path:`${n}/`,note:`tasks, settings and PRD templates`}):s&&a(i(`.taskgraph/config.json`))&&l.push({path:c,note:`restored`}),a(i(`.git`))&&l.push({path:`.git/`,note:`new Git repository`});let d=[[u,`created`,`added TaskGraph entries`],[p,`optional settings`,`updated`],[`CLAUDE.md`,`loads TaskGraph's instructions in Claude Code`,`now imports TaskGraph's instructions`],[`.mcp.json`,`TaskGraph MCP server for Claude Code`,`added the TaskGraph MCP server`]];for(let[e,t,n]of d){let r=i(e);a(r)?l.push({path:e,note:t}):o(r)&&l.push({path:e,note:n})}let f=process.env.HOME||process.env.USERPROFILE;for(let e of J()){let n=t.get(e)||``,i=r.get(e)||``;if(i===n)continue;let a=[];i.includes(U)&&!n.includes(U)&&a.push("the `tm` alias"),i.includes(W)&&!n.includes(W)&&a.push(`deferred MCP loading`),a.length!==0&&l.push({path:f?e.replace(f,`~`):e,note:`added ${a.join(` and `)}; open a new terminal`})}return{alreadySetUp:s,changes:l}}function Ue(){let e=process.env.HOME||process.env.USERPROFILE,t;if(process.env.SHELL?.includes(`zsh`))t=v.join(e,`.zshrc`);else if(process.env.SHELL?.includes(`bash`))t=v.join(e,`.bashrc`);else return K(`debug`,`Could not determine shell type. Aliases not added.`),!1;try{if(!w.existsSync(t))return K(`debug`,`Shell config file ${t} not found.`),!1;let e=w.readFileSync(t,`utf8`),n=[{name:`tm`,line:U}].filter(t=>!e.includes(t.line));if(n.length===0)return K(`debug`,`All TaskGraph aliases already exist.`),!0;let r=n.map(e=>e.line).join(`
|
|
16
|
+
`),i=`
|
|
17
|
+
# TaskGraph aliases added on ${(/* @__PURE__ */ new Date()).toLocaleDateString()}
|
|
18
|
+
${r}
|
|
19
|
+
`;return w.appendFileSync(t,i),K(`debug`,`Added ${n.length} alias(es): ${n.map(e=>e.name).join(`, `)}`),!0}catch(e){return K(`debug`,`Failed to add aliases: ${e.message}`),!1}}function We(e){let t=v.join(e,i);if(w.existsSync(t)){K(`debug`,`State file already exists, preserving current configuration`);return}let n={currentTag:`master`,lastSwitched:(/* @__PURE__ */ new Date()).toISOString(),branchTagMapping:{},migrationNoticeShown:!0};try{w.writeFileSync(t,JSON.stringify(n,null,2)),K(`debug`,`Created initial state file: ${t}`)}catch(e){K(`error`,`Failed to create state file: ${e.message}`)}}function Ge(e){let t=v.join(e,o);if(w.existsSync(t))return;let n={master:{tasks:[],metadata:{created:(/* @__PURE__ */ new Date()).toISOString(),description:`Tasks for master context`}}};try{w.writeFileSync(t,`${JSON.stringify(n,null,2)}\n`),K(`debug`,`Created empty tasks file: ${t}`)}catch(e){K(`error`,`Failed to create tasks file: ${e.message}`)}}function X(e,t,n={}){if(!ye(e)){K(`error`,`Source file not found: ${e}`);return}let r=I(e,`utf8`);if(Object.entries(n).forEach(([e,t])=>{let n=RegExp(`\\{\\{${e}\\}\\}`,`g`);r=r.replace(n,t)}),w.existsSync(t)){let e=v.basename(t);if(e===`.gitignore`){K(`debug`,`${t} already exists, merging content...`);let e=w.readFileSync(t,`utf8`),n=new Set(e.split(`
|
|
20
|
+
`).map(e=>e.trim())),i=r.split(`
|
|
21
|
+
`).filter(e=>!n.has(e.trim()));if(i.length>0){let n=`${e.trim()}\n\n# Added by TaskGraph\n${i.join(`
|
|
22
|
+
`)}`;w.writeFileSync(t,n),K(`debug`,`Updated ${t} with additional entries`)}else K(`debug`,`No new content to add to ${t}`);return}if(e===`README-taskgraph.md`){K(`debug`,`${t} already exists`);let e=v.join(v.dirname(t),`README-taskgraph.md`);w.writeFileSync(e,r),K(`debug`,`Created ${e} (preserved original README-taskgraph.md)`);return}K(`debug`,`${t} already exists, skipping.`)}else w.writeFileSync(t,r),K(`debug`,`Created file: ${t}`)}async function Ke(e={}){s()||ze(),e.git===!0?e.initGit=!0:e.git===!1&&(e.initGit=!1),e.gitTasks===!0?e.storeTasksInGit=!0:e.gitTasks===!1&&(e.storeTasksInGit=!1);let t=e.yes||e.name&&e.description,n;if(n=e.rulesExplicitlyProvided?e.rules:[],t){e.name,e.description,e.version,e.author;let t=e.dryRun||!1,r=e.initGit===void 0||e.initGit,i=e.storeTasksInGit??ge(v.join(process.cwd(),`.gitignore`))??!0;if(t)return $(r,i),{dryRun:!0};await Q(e.aliases!==!1,r,i,t,{...e,preferredLanguage:`English`},n)}else{K(`debug`,`Required options not provided, proceeding with prompts.`);let t;try{K(`debug`,`Init started - taskgraph_id: ${qe()}`),t=T.createInterface({input:process.stdin,output:process.stdout});let r=!0,i=!0;r=e.initGit===void 0?m()?!0:(await Z(t,g.cyan(`Initialize a Git repository in project root? (Y/n): `),e=>{let t=e.trim().toLowerCase()!==`n`,n=t?g.green(`✓`):g.dim(`–`);return g.cyan(`Initialize a Git repository in project root?`)+` `+n+` `+g.dim(t?`Yes`:`No`)})).trim().toLowerCase()!==`n`:e.initGit,i=e.storeTasksInGit===void 0?(await Z(t,g.cyan(`Store tasks in Git (tasks.json and tasks/ directory)? (Y/n): `),e=>{let t=e.trim().toLowerCase()!==`n`,n=t?g.green(`✓`):g.dim(`–`);return g.cyan(`Store tasks in Git (tasks.json and tasks/ directory)?`)+` `+n+` `+g.dim(t?`Yes`:`No`)})).trim().toLowerCase()!==`n`:e.storeTasksInGit;let a=!1;e.rulesExplicitlyProvided?K(`debug`,`Using rule profiles provided via command line: ${n.join(`, `)}`):a=(await Z(t,g.cyan(`Set up Claude Code integration (CLAUDE.md import)? (y/N): `),e=>{let t=e.trim().toLowerCase()===`y`,n=t?g.green(`✓`):g.dim(`–`);return g.cyan(`Set up Claude Code integration?`)+` `+n+` `+g.dim(t?`Yes`:`No`)})).trim().toLowerCase()===`y`;let o=(await Z(t,g.cyan(`Language for AI responses (English): `),e=>`${g.cyan(`Language for AI responses?`)} ${g.dim(e.trim()||`English`)}`)).trim()||`English`,s=e.dryRun||!1;if(s)return t.close(),$(r,i),{dryRun:!0};await Q(e.aliases!==!1,r,i,s,{...e,shouldSetupRules:a,preferredLanguage:o},a?E:n),t.close()}catch(e){t&&t.close(),K(`error`,`Error during initialization process: ${e.message}`),process.exit(1)}}}function Z(e,t,n){return new Promise(r=>{e.question(t,e=>{T.moveCursor(process.stdout,0,-1),T.cursorTo(process.stdout,0),T.clearLine(process.stdout,0),n&&process.stdout.write(n(e)+`
|
|
23
|
+
`),r(e)})})}function qe(){return oe()}function Je(e){try{if(!w.existsSync(e)){K(`warn`,`Config file does not exist, skipping storage configuration`);return}let t=w.readFileSync(e,`utf8`),n=JSON.parse(t);n.storage||={},n.storage.type=`file`,n.storage.operatingMode=`solo`,K(`debug`,`Configured storage for local file storage`),w.writeFileSync(e,JSON.stringify(n,null,2)),K(`debug`,`Storage configuration updated in config.json`)}catch(e){K(`error`,`Failed to update storage configuration: ${e.message}`)}}async function Q(e,t,i,a,o,d=E){let h=process.cwd();K(`debug`,`Initializing project in ${h}`);let g=s()?[]:Ve(h),_=Y(g);q(v.join(h,n)),q(v.join(h,r)),q(v.join(h,ee)),q(v.join(h,l)),q(v.join(h,f)),We(h),Ge(h);let b={year:(/* @__PURE__ */ new Date()).getFullYear()};function x(e){let t=Fe(e);t?Ie(h,t):K(`warn`,`Unknown rule profile: ${e}`)}X(`env.example`,v.join(h,p),b),X(`config.json`,v.join(h,c),{...b});let S=v.join(h,c);Le(S)?K(`debug`,`Updated config with correct maxTokens values`):K(`debug`,`Could not update maxTokens in config`),Je(S);try{let e=I(`gitignore`,`utf8`);_e(v.join(h,u),e,i,Be)}catch(e){K(`error`,`Failed to create .gitignore: ${e.message}`)}X(`example_prd.txt`,v.join(h,te)),X(`example_prd_rpg.txt`,v.join(h,f,`example_prd_rpg.txt`));try{t===!1?K(`debug`,`Git initialization skipped due to --no-git flag.`):m()?K(`debug`,`Existing Git repository detected; skipping git init.`):(y(`git init`,{cwd:h,stdio:`ignore`}),K(`debug`,`Git repository initialized`))}catch{K(`warn`,`Git not available, skipping repository initialization`)}if(d.length>0){K(`debug`,`Setting up Claude Code integration...`);for(let e of d)x(e)}if(o.preferredLanguage&&!a)try{let e=(await import(`./response-language-mSXkRdue.js`)).default;e(o.preferredLanguage,{projectRoot:h,silent:!0}),K(`debug`,`Response language set to: ${o.preferredLanguage}`)}catch(e){K(`warn`,`Failed to set response language: ${e.message}`)}if(!s()&&!a&&!o?.yes){console.log(``);try{y(`"${process.execPath}" "${process.argv[1]}" models --setup --no-banner`,{stdio:`inherit`,cwd:h}),console.log(``)}catch{K(`warn`,"Model setup did not finish; run `taskgraph models --setup` to retry")}}else s()&&!a&&K(`debug`,`Skipping interactive model setup in silent (MCP) mode.`);if(e&&!a&&Ue(),!s()){let{alreadySetUp:e,changes:t}=He(h,_,Y(g));console.log(`${ne({folder:v.basename(h),changes:t,alreadySetUp:e,claudeCode:d.includes(`claude`),defaultModels:!!o?.yes})}\n`)}}function $(e,t){if(s())return;let r=[`Dry run; nothing was changed. Init would:`,` create ${n}/ with tasks, settings and PRD templates`,` create or update ${u} and ${p}`];e!==!1&&!m()&&r.push(` start a Git repository`),r.push(t?` keep tasks in Git`:` keep tasks out of Git`),console.log(r.join(`
|
|
24
|
+
`))}export{E as n,se as r,Ke as t};
|