@cmflow/agents 3.7.0 → 3.7.1
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/dist/bin/cm-agents.mjs
CHANGED
|
@@ -375,7 +375,7 @@ let Sy=/^[a-z0-9-_]+$/i;function Cy(e){let t=typeof e;if(t===`object`){if(Array.
|
|
|
375
375
|
`?r:r+`
|
|
376
376
|
`}const Ny=new class extends $v{constructor(){super(`codex`)}async version(){return this.tryGet(`--version`)}getConfig(){if(!L.default.pathExistsSync(Ci))return{};try{return xy(L.default.readFileSync(Ci,`utf8`))}catch{return{}}}updateConfig(e){L.default.ensureDirSync(v(Ci)),L.default.writeFileSync(Ci,My(e),`utf8`)}writeBaseConfig(e,t){let n=L.default.pathExistsSync(Ci)&&t;return n&&L.default.copyFileSync(Ci,`${Ci}.bak`),this.updateConfig(e),n}async listMcp(){return await this.tryGet(`mcp`,`list`)??``}async hasMcp(e){return(await this.listMcp()).includes(e)}async addMcp(e,t,n=!1){let{options:r,...i}=ji(t),a=this.getConfig(),o=a.mcp_servers??{};return!n&&o[e]?!1:(this.updateConfig({...a,mcp_servers:{...o,[e]:{...i,...r}}}),!0)}async removeMcp(e){let t=this.getConfig();if(!t.mcp_servers?.[e])return!1;let{[e]:n,...r}=t.mcp_servers;return this.updateConfig({...t,mcp_servers:r}),!0}},Py=new class extends $v{constructor(){super(`git`)}init(...e){return this.run(`init`,...e)}add(...e){return this.run(`add`,...e)}status(...e){return this.run(`status`,...e)}branch(...e){return this.run(`branch`,...e)}clean(...e){return this.run(`clean`,...e)}config(...e){return this.run(`config`,...e).get()}checkout(...e){return this.run(`checkout`,...e)}commit(...e){return this.run(`commit`,...e)}fetch(...e){return this.run(`fetch`,...e)}prune(...e){return this.run(`prune`,...e)}merge(...e){return this.run(`merge`,...e)}reset(...e){return this.run(`reset`,...e)}remote(...e){return this.run(`remote`,...e)}rebase(...e){return this.run(`rebase`,...e)}getCommitTag(e=`HEAD`){return this.get(`rev-parse`,`--short`,e)}getBranchName(e=`HEAD`){return this.get(`rev-parse`,`--abbrev-ref`,e)}getLastCommitMsg(){return this.get(`log`,`-1`,`--pretty=%B`)}push(...e){return this.run(`push`,...e)}clone(...e){return this.run(`clone`,...e)}async branchExists(e,t=`origin`){return(await this.run(`branch`,`-a`).getRaw()).includes(`remotes/${t}/${e}`)}async checkBranchRemoteStatus(e,t=`origin`){return this.run(`cherry`,e,`${t}/${e}`).get()}async branches(...e){return(await this.run(`branch`,...e).get()).split(`
|
|
377
377
|
`).map(e=>e.trim().replace(`* `,``)).filter(e=>!!e).filter(e=>!String(e).includes(`/HEAD`))}async show(e){return(await this.run(`show`,`--format="%ci|%cr|%an"`,e,`--`).getRaw()).split(`
|
|
378
|
-
`)[0].trim()}},Fy=new class extends $v{constructor(){super(`npm`)}newVersion(e){return this.version(`--no-git-tag-version`,e)}version(...e){return super.run(`version`,...e)}run(...e){return super.run(`run`,...e)}install(...e){return super.run(`install`,...e)}publish(...e){return super.run(`publish`,...e)}pack(...e){return super.run(`pack`,...e)}restore(){return super.run(`ci`)}},Iy=new class{step(e){console.log(`\n${F.bold.cyan(`${qa.pointer} ${e}`)}`)}ok(e){console.log(` ${F.green(qa.tick)} ${e}`)}warn(e){console.log(` ${F.yellow(qa.warning)} ${e}`)}info(e){console.log(` ${e}`)}err(e){console.error(` ${F.red(qa.cross)} ${e}`)}header(e){let t=`═`.repeat(47);console.log(`\n${F.bold(t)}`),console.log(`${F.bold(` ${e}`)}`),console.log(`${F.bold(t)}\n`)}table(e,t){let n=new hi.default({chars:{mid:``,"left-mid":``,"mid-mid":``,"right-mid":``},style:{border:[`grey`],head:[]},colWidths:t?.colWidths??[4,40,30]});for(let[t,r,i=``]of e){let e=r===`ok`?F.green(qa.tick):r===`warn`?F.yellow(qa.warning):F.red(qa.cross),a=r===`ok`?F.grey(i):r===`warn`?F.yellow(i):F.red(i);n.push([e,t,a])}console.log(n.toString())}section(e,t){console.log(`\n${F.bold(e)}`),this.table(t)}print(e){console.log(e)}break(){console.log()}};function Ly(e,t){let n=process.env[e];if(n!==void 0)return n;if(!gi)return t;try{let n=new $v(`powershell`).sync(`-NoProfile`,`-Command`,`[System.Environment]::GetEnvironmentVariable('${e}', 'User')`);return(typeof n.stdout==`string`?n.stdout.trim():``)||t}catch{return t}}function Ry(e=Ly(`SHARED_AGENTS_REPO_DIR`),t=yi){let n=e?[e]:t;return n.find(e=>L.default.pathExistsSync(y(e,`.git`)))??n[0]}const zy=new $v(`mise`),By=new $v(gi?`python`:`python3`);let Vy=[],Hy=`General`;var Uy=class extends Error{constructor(e,t){super(`${e}: ${t.join(`, `)}`),this.name=`CheckError`}};function B(e,t=``,n=Hy){Vy.push([n,e,`OK`,t])}function Wy(e,t=``,n=Hy){Vy.push([n,e,`WARN`,t])}function Gy(e,t,n=Hy){Vy.push([n,e,`FAIL`,t])}function Ky(e){return e===`OK`?F.green(e):e===`WARN`?F.yellow(e):F.red(e)}const qy=[`kibana_prod`,`kibana_staging`],Jy=`run: cm-agents kibana setup prod && cm-agents kibana setup staging`,Yy=[`Global`,`Codex`,`Claude`,`Envs`];function Xy(){let e=new hi.default({head:[`Group`,`Capability`,`Status`,`Details`],style:{border:[`grey`],head:[]}}),t=[...Vy].sort(([e],[t])=>Yy.indexOf(e)-Yy.indexOf(t));for(let[n,r,i,a]of t)e.push([n,r,Ky(i),a||`—`]);Iy.print(e.toString())}async function Zy(){let e=[],t=await Py.tryGet(`--version`);t?B(`git`,t.replace(`git version `,``),`Global`):(Gy(`git`,`not found`,`Global`),e.push(`git`)),parseInt(process.version.slice(1).split(`.`)[0],10)>=20?B(`node`,process.version,`Global`):(Gy(`node`,`${process.version} — minimum required: v20`,`Global`),e.push(`node`));let n=await Fy.tryGet(`--version`);n?B(`npm`,n,`Global`):(Gy(`npm`,gi?`npm -v failed — install mise then Node.js as described in README.md, remove the legacy Node.js user PATH entry, or run: cm-agents node reinstall`:`npm -v failed`,`Global`),e.push(`npm`));let r=await Ny.version();r?B(`CLI`,r,`Codex`):(Gy(`CLI`,`not found`,`Codex`),e.push(`codex`));let i=await ey.version();i?B(`CLI`,i,`Claude`):(Gy(`CLI`,`not found`,`Claude`),e.push(`claude`));let a=await zy.tryGet(`--version`);a?B(`mise`,a,`Global`):Wy(`mise`,`not installed (optional)`,`Global`);let o=await By.tryGet(`--version`);if(o?B(`python`,o,`Global`):Wy(`python`,`not installed (optional)`,`Global`),e.length)throw new Uy(`Tools`,e)}function Qy(){let e=[];for(let t of ki)Ly(t)?B(t):(Gy(t,`not set`),e.push(t));for(let e of Ai)Ly(e)?B(e):Wy(e,`not set (optional)`);if(e.length)throw new Uy(`Environment Variables`,e)}async function $y(){if(!Ny.getConfig())throw Gy(`config.toml`,`not found (~/.codex/config.toml)`),new Uy(`Codex`,[`config.toml missing`]);B(`config.toml`,Ci);let e=[];for(let t of[...Object.keys(Ti),...qy])await Ny.hasMcp(t)?B(`MCP ${t}`):(Gy(`MCP ${t}`,qy.includes(t)?`not configured — ${Jy}`:`not configured`),e.push(t));if(e.length)throw new Uy(`Codex MCPs`,e)}async function eb(){if(!await ey.version())throw Gy(`Claude MCPs`,`claude CLI not found`),new Uy(`Claude MCPs`,[`claude CLI not found`]);let e=await ey.listMcp(),t=[],n=[[`clubmed_api`,e.includes(`clubmed_api`)],[`cms_api`,e.includes(`cms_api`)],[`atlassian`,e.includes(`atlassian`)||e.includes(`plugin:atlassian`)],[`kibana_prod`,e.includes(`kibana_prod`)],[`kibana_staging`,e.includes(`kibana_staging`)]];for(let[e,r]of n)r?B(`MCP ${e}`):(Gy(`MCP ${e}`,qy.includes(e)?`not configured — ${Jy}`:`not configured`),t.push(e));if(t.length)throw new Uy(`Claude MCPs`,t)}function tb(){let e=Ny.getConfig();if(!e)throw Gy(`config.toml`,`not found — run: cm-agents codex init`),new Uy(`Codex LiteLLM`,[`config missing`]);let t=[];e.model_provider===`litellm`?B(`model_provider`,`litellm`):(Gy(`model_provider`,`${String(e.model_provider??`not set`)} — expected: litellm`),t.push(`model_provider`));let n=e.model_providers?.litellm;n?.base_url===`https://litellm-aiplatform.ai.clubmed.com`?B(`model_providers.litellm.base_url`,n.base_url):(Gy(`model_providers.litellm.base_url`,`${n?.base_url??`not set`} — expected: ${xi}`),t.push(`model_providers.litellm.base_url`));let r=e.model_catalog_json;if(r&&L.default.pathExistsSync(r)){B(`model_catalog_json`,`present`);try{let n=JSON.parse(L.default.readFileSync(r,`utf8`)).data.map(e=>e.id),i=e.model;i&&n.includes(i)?B(`model`,i):(Gy(`model`,`${i??`not set`} not in catalog — run: cm-agents codex models --refresh`),t.push(`model`))}catch{Wy(`model_catalog_json`,`could not parse — run: cm-agents codex models --refresh`)}}else Gy(`model_catalog_json`,`${r??`not set`} — run: cm-agents codex init`),t.push(`model_catalog_json`);if(t.length)throw new Uy(`Codex LiteLLM`,t)}function nb(){let e=Ry();if(e
|
|
378
|
+
`)[0].trim()}},Fy=new class extends $v{constructor(){super(`npm`)}newVersion(e){return this.version(`--no-git-tag-version`,e)}version(...e){return super.run(`version`,...e)}run(...e){return super.run(`run`,...e)}install(...e){return super.run(`install`,...e)}publish(...e){return super.run(`publish`,...e)}pack(...e){return super.run(`pack`,...e)}restore(){return super.run(`ci`)}},Iy=new class{step(e){console.log(`\n${F.bold.cyan(`${qa.pointer} ${e}`)}`)}ok(e){console.log(` ${F.green(qa.tick)} ${e}`)}warn(e){console.log(` ${F.yellow(qa.warning)} ${e}`)}info(e){console.log(` ${e}`)}err(e){console.error(` ${F.red(qa.cross)} ${e}`)}header(e){let t=`═`.repeat(47);console.log(`\n${F.bold(t)}`),console.log(`${F.bold(` ${e}`)}`),console.log(`${F.bold(t)}\n`)}table(e,t){let n=new hi.default({chars:{mid:``,"left-mid":``,"mid-mid":``,"right-mid":``},style:{border:[`grey`],head:[]},colWidths:t?.colWidths??[4,40,30]});for(let[t,r,i=``]of e){let e=r===`ok`?F.green(qa.tick):r===`warn`?F.yellow(qa.warning):F.red(qa.cross),a=r===`ok`?F.grey(i):r===`warn`?F.yellow(i):F.red(i);n.push([e,t,a])}console.log(n.toString())}section(e,t){console.log(`\n${F.bold(e)}`),this.table(t)}print(e){console.log(e)}break(){console.log()}};function Ly(e,t){let n=process.env[e];if(n!==void 0)return n;if(!gi)return t;try{let n=new $v(`powershell`).sync(`-NoProfile`,`-Command`,`[System.Environment]::GetEnvironmentVariable('${e}', 'User')`);return(typeof n.stdout==`string`?n.stdout.trim():``)||t}catch{return t}}function Ry(e=Ly(`SHARED_AGENTS_REPO_DIR`),t=yi){let n=e?[e]:t;return n.find(e=>L.default.pathExistsSync(y(e,`.git`)))??n[0]}const zy=new $v(`mise`),By=new $v(gi?`python`:`python3`);let Vy=[],Hy=`General`;var Uy=class extends Error{constructor(e,t){super(`${e}: ${t.join(`, `)}`),this.name=`CheckError`}};function B(e,t=``,n=Hy){Vy.push([n,e,`OK`,t])}function Wy(e,t=``,n=Hy){Vy.push([n,e,`WARN`,t])}function Gy(e,t,n=Hy){Vy.push([n,e,`FAIL`,t])}function Ky(e){return e===`OK`?F.green(e):e===`WARN`?F.yellow(e):F.red(e)}const qy=[`kibana_prod`,`kibana_staging`],Jy=`run: cm-agents kibana setup prod && cm-agents kibana setup staging`,Yy=[`Global`,`Codex`,`Claude`,`Envs`];function Xy(){let e=new hi.default({head:[`Group`,`Capability`,`Status`,`Details`],style:{border:[`grey`],head:[]}}),t=[...Vy].sort(([e],[t])=>Yy.indexOf(e)-Yy.indexOf(t));for(let[n,r,i,a]of t)e.push([n,r,Ky(i),a||`—`]);Iy.print(e.toString())}async function Zy(){let e=[],t=await Py.tryGet(`--version`);t?B(`git`,t.replace(`git version `,``),`Global`):(Gy(`git`,`not found`,`Global`),e.push(`git`)),parseInt(process.version.slice(1).split(`.`)[0],10)>=20?B(`node`,process.version,`Global`):(Gy(`node`,`${process.version} — minimum required: v20`,`Global`),e.push(`node`));let n=await Fy.tryGet(`--version`);n?B(`npm`,n,`Global`):(Gy(`npm`,gi?`npm -v failed — install mise then Node.js as described in README.md, remove the legacy Node.js user PATH entry, or run: cm-agents node reinstall`:`npm -v failed`,`Global`),e.push(`npm`));let r=await Ny.version();r?B(`CLI`,r,`Codex`):(Gy(`CLI`,`not found`,`Codex`),e.push(`codex`));let i=await ey.version();i?B(`CLI`,i,`Claude`):(Gy(`CLI`,`not found`,`Claude`),e.push(`claude`));let a=await zy.tryGet(`--version`);a?B(`mise`,a,`Global`):Wy(`mise`,`not installed (optional)`,`Global`);let o=await By.tryGet(`--version`);if(o?B(`python`,o,`Global`):Wy(`python`,`not installed (optional)`,`Global`),e.length)throw new Uy(`Tools`,e)}function Qy(){let e=[];for(let t of ki)Ly(t)?B(t):(Gy(t,`not set`),e.push(t));for(let e of Ai)Ly(e)?B(e):Wy(e,`not set (optional)`);if(e.length)throw new Uy(`Environment Variables`,e)}async function $y(){if(!Ny.getConfig())throw Gy(`config.toml`,`not found (~/.codex/config.toml)`),new Uy(`Codex`,[`config.toml missing`]);B(`config.toml`,Ci);let e=[];for(let t of[...Object.keys(Ti),...qy])await Ny.hasMcp(t)?B(`MCP ${t}`):(Gy(`MCP ${t}`,qy.includes(t)?`not configured — ${Jy}`:`not configured`),e.push(t));if(e.length)throw new Uy(`Codex MCPs`,e)}async function eb(){if(!await ey.version())throw Gy(`Claude MCPs`,`claude CLI not found`),new Uy(`Claude MCPs`,[`claude CLI not found`]);let e=await ey.listMcp(),t=[],n=[[`clubmed_api`,e.includes(`clubmed_api`)],[`cms_api`,e.includes(`cms_api`)],[`atlassian`,e.includes(`atlassian`)||e.includes(`plugin:atlassian`)],[`kibana_prod`,e.includes(`kibana_prod`)],[`kibana_staging`,e.includes(`kibana_staging`)]];for(let[e,r]of n)r?B(`MCP ${e}`):(Gy(`MCP ${e}`,qy.includes(e)?`not configured — ${Jy}`:`not configured`),t.push(e));if(t.length)throw new Uy(`Claude MCPs`,t)}function tb(){let e=Ny.getConfig();if(!e)throw Gy(`config.toml`,`not found — run: cm-agents codex init`),new Uy(`Codex LiteLLM`,[`config missing`]);let t=[];e.model_provider===`litellm`?B(`model_provider`,`litellm`):(Gy(`model_provider`,`${String(e.model_provider??`not set`)} — expected: litellm`),t.push(`model_provider`));let n=e.model_providers?.litellm;n?.base_url===`https://litellm-aiplatform.ai.clubmed.com`?B(`model_providers.litellm.base_url`,n.base_url):(Gy(`model_providers.litellm.base_url`,`${n?.base_url??`not set`} — expected: ${xi}`),t.push(`model_providers.litellm.base_url`));let r=e.model_catalog_json;if(r&&L.default.pathExistsSync(r)){B(`model_catalog_json`,`present`);try{let n=JSON.parse(L.default.readFileSync(r,`utf8`)).data.map(e=>e.id),i=e.model;i&&n.includes(i)?B(`model`,i):(Gy(`model`,`${i??`not set`} not in catalog — run: cm-agents codex models --refresh`),t.push(`model`))}catch{Wy(`model_catalog_json`,`could not parse — run: cm-agents codex models --refresh`)}}else Gy(`model_catalog_json`,`${r??`not set`} — run: cm-agents codex init`),t.push(`model_catalog_json`);if(t.length)throw new Uy(`Codex LiteLLM`,t)}function nb(){let e=Ry();if(!e)throw Gy(`Repository`,`Missing repository`,`Global`),new Uy(`Repository`,[`not cloned`]);B(`Repository`,e,`Global`)}var rb=e=>void e.command(`check`).description(`Check the installation state of the workstation`).action(async()=>{yn(`Club Med — AI Tools Check (${gi?`Windows`:`macOS/Linux`})`),Vy=[];let e=[],t=[[`Tools`,`Global`,Zy],[`Environment`,`Envs`,Qy],[`Codex configuration`,`Codex`,$y],[`Codex LiteLLM`,`Codex`,tb],[`Claude MCPs`,`Claude`,eb],[`Repository`,`Global`,nb]],n=On({max:t.length});n.start(`Run check tools`);for(let[r,i,a]of t){Hy=i;try{await a()}catch(t){if(t instanceof Uy)e.push(t);else throw t}n.advance(1,r)}n.stop(`Check tools complete`),M.step(`Capabilities`),Xy(),e.length?(bn(`Some checks failed — run cm-agents install to fix.`),process.exit(1)):bn(`Everything is correctly configured.`)});function ib(){let e=process.env.SHELL??``;return e.includes(`zsh`)?y(process.env.HOME??`~`,`.zshrc`):e.includes(`bash`)?y(process.env.HOME??`~`,`.bashrc`):null}function ab(e,t){Jv(`powershell`,[`-Command`,`[System.Environment]::SetEnvironmentVariable('${e}', '${t}', 'User')`]),process.env[e]=t}const ob=new class{load(){if(gi)return;let e=ib();if(!e||!L.default.pathExistsSync(e))return;let t=!1;for(let n of L.default.readFileSync(e,`utf8`).split(`
|
|
379
379
|
`)){if(n.includes(`# --- Club Med AI Tools ---`)){t=!0;continue}if(!t)continue;let e=n.match(/^export\s+([A-Z_]+)="(.*)"$/);e&&!process.env[e[1]]&&(process.env[e[1]]=e[2])}}save(e){if(gi){for(let[t,n]of Object.entries(e))ab(t,n);return{platform:`windows`}}let t=ib();if(!t)return{platform:`unknown`};if(L.default.readFileSync(t,`utf8`).includes(`# --- Club Med AI Tools ---`))return{platform:`unix`,rc:t,written:!1};let n=[`
|
|
380
380
|
# --- Club Med AI Tools ---`,...Object.entries(e).map(([e,t])=>`export ${e}="${t}"`)];return L.default.appendFileSync(t,n.join(`
|
|
381
381
|
`)+`
|