@autonomos/cli 0.3.2 → 0.3.4
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/index.mjs +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import{Command as e}from"commander";import t from"picocolors";import{AGENT_FILE as n,AUTONOMOS_DIR as r,MANIFEST_FILE as i,PROTOCOL_FILE as a,PROTOCOL_TEMPLATE as o,PROTOCOL_VERSION as s,TASKS_FILE as c,TASKS_TEMPLATE as l,TaskParser as u,WORKLOGS_DIR as d,createManifest as f,displayRelative as p,findAncestorAgents as m,findProjectRoot as h,generateAgentTemplate as g,generateManifestContent as _,isSamePath as v,listHarnesses as y,parseManifest as b,resolveTargets as x}from"@autonomos/core";import{existsSync as S,mkdirSync as C,readFileSync as w,readdirSync as T,statSync as E,writeFileSync as D}from"node:fs";import{basename as O,join as k,relative as A,resolve as j}from"node:path";import{checkbox as M,confirm as N}from"@inquirer/prompts";import{fileURLToPath as P}from"node:url";function F(e,t,r=0){let i=[],a=k(e,n);S(a)&&i.push({path:a,relativePath:A(t,a)||n,depth:r});try{let n=T(e);for(let a of n){if(a.startsWith(`.`)||a===`node_modules`||a===`dist`||a===`build`)continue;let n=k(e,a);try{E(n).isDirectory()&&i.push(...F(n,t,r+1))}catch{}}}catch{}return i}function I(e,t){if(e.length===0)return` (no AGENT.md files found)`;let r=O(t),i={name:r,isAgent:!1,children:{}};for(let t of e){let e=t.relativePath.split(`/`),r=i;for(let t of e){let e=t===n,i=r.children[t];i||(i={name:t,isAgent:e,children:{}},r.children[t]=i),r=i}}let a=[];a.push(`📁 ${r}/`);function o(e,t=``,n=!0){let r=Object.values(e.children);r.sort((e,t)=>!e.isAgent&&t.isAgent?-1:e.isAgent&&!t.isAgent?1:e.name.localeCompare(t.name)),r.forEach((e,n)=>{let i=n===r.length-1,s=i?`└── `:`├── `,c=e.isAgent?`📄`:`📁`,l=e.isAgent?e.name:`${e.name}/`;a.push(`${t}${s}${c} ${l}`),e.isAgent||o(e,t+(i?` `:`│ `),i)})}return o(i),a.join(`
|
|
3
3
|
`)}function L(e){return e.length===0?` (no AGENT.md files found in the ancestor chain)`:e.map((t,n)=>` ${(n+1).toString().padStart(e.length.toString().length,` `)}. ${t.relativeDir===`.`?`./AGENT.md`:`${t.relativeDir}/AGENT.md`}`).join(`
|
|
4
|
-
`)}function R(e={}){let t=e.cwd??process.cwd();if(e.target){let n=h(t)??t,r;try{r=m(j(t,e.target),n)}catch(e){return{success:!1,message:`Failed to look up ancestors: ${e instanceof Error?e.message:String(e)}`,mode:`ancestors`}}let i=L(r);return{success:!0,message:`Found ${r.length} ancestor AGENT.md file(s) for "${e.target}" (root → target):\n${i}`,count:r.length,ancestors:r,mode:`ancestors`}}let n;if(e.all){let e=h(t);if(!e)return{success:!1,message:`Could not find project root (.autonomos or .git directory).`,mode:`tree`};n=e}else n=t;let r=F(n,n);if(r.length===0)return{success:!0,message:`No AGENT.md files found.`,count:0,mode:`tree`};let i=I(r,n);return{success:!0,message:`Found ${r.length} AGENT.md file(s)`,tree:i,count:r.length,mode:`tree`}}var z=`0.3.
|
|
4
|
+
`)}function R(e={}){let t=e.cwd??process.cwd();if(e.target){let n=h(t)??t,r;try{r=m(j(t,e.target),n)}catch(e){return{success:!1,message:`Failed to look up ancestors: ${e instanceof Error?e.message:String(e)}`,mode:`ancestors`}}let i=L(r);return{success:!0,message:`Found ${r.length} ancestor AGENT.md file(s) for "${e.target}" (root → target):\n${i}`,count:r.length,ancestors:r,mode:`ancestors`}}let n;if(e.all){let e=h(t);if(!e)return{success:!1,message:`Could not find project root (.autonomos or .git directory).`,mode:`tree`};n=e}else n=t;let r=F(n,n);if(r.length===0)return{success:!0,message:`No AGENT.md files found.`,count:0,mode:`tree`};let i=I(r,n);return{success:!0,message:`Found ${r.length} AGENT.md file(s)`,tree:i,count:r.length,mode:`tree`}}var z=`0.3.4`;const B=z,V=[`protocol-session.md`,`protocol-task.md`,`protocol-crystallize.md`];function H(){let e=P(import.meta.url),t=[j(e,`..`,`..`,`..`,`..`,`core`,`src`,`workflows`),j(e,`..`,`..`,`..`,`core`,`dist`,`workflows`),j(e,`..`,`..`,`..`,`..`,`core`,`dist`,`workflows`)];for(let e of t)if(S(e))return e;throw Error(`Could not locate the workflows directory inside @autonomos/core`)}async function U(){return M({message:`Which AI harnesses do you want to install the protocol for? (space to toggle, enter to confirm)`,choices:y().map(({id:e,harness:t})=>({name:t.name,value:e,checked:t.preferred}))})}async function W(e,t){let n=[],r=h(e);if(!r)return S(k(e,`.git`))||n.push("No Git repository detected. Consider running `git init` first."),{installDir:e,warnings:n};if(v(r,e))return{installDir:e,warnings:n};let i=p(e,r);return t.force||process.env.AUTONOMOS_FORCE===`1`?(n.push(`Detected project root at ${p(r,e)} (AUTONOMOS_FORCE=1); installing there instead of "${i}".`),{installDir:r,warnings:n}):t.isInteractive&&!t.noPrompt?await N({message:`You're inside a project rooted at ${r}.\nThe protocol should be installed at the project root, not in "${i}".\nInstall at the project root instead?`,default:!0})?(n.push(`Detected project root above "${i}"; installing at ${r}.`),{installDir:r,warnings:n}):{installDir:e,warnings:n,abort:{message:`Aborted: refusing to install Autonomos inside a subdirectory. Run the command from ${r} (or pass --force / set AUTONOMOS_FORCE=1).`}}:{installDir:e,warnings:n,abort:{message:`Cannot initialize Autonomos from a subdirectory.\n Current directory : ${e}\n Detected root : ${r}\nRe-run from the project root, or pass --force (or set AUTONOMOS_FORCE=1) to install here anyway.`}}}async function G(e={}){let t=e.cwd??process.cwd(),u=e.dryRun??!1,p=e.interactiveOverride??(process.stdin.isTTY===!0&&!e.dryRun),m=await W(t,{force:e.force??!1,noPrompt:e.noPrompt??!1,isInteractive:p});if(m.abort)return{success:!1,message:m.abort.message,created:[],warnings:m.warnings,dryRun:u};let h=m.installDir,v=[...m.warnings],b=[],T=[],O=k(h,`package.json`),A=S(O)&&E(O).isFile(),j=k(h,r),M=S(j),N;if(N=e.all?y().map(({id:e})=>e):e.harnesses&&e.harnesses.length>0?e.harnesses:e.noPrompt||e.dryRun?[]:await U(),M&&N.length===0)return{success:!1,message:`Project already initialized with Protocol v${s}. Use \`autonomos update\` to update, or specify harnesses with --harness to install workflow files.`,created:[],warnings:[],dryRun:u};let P=x(N,h);if(u){M?(b.push(`${r}/${i} (update)`),b.push(`${r}/${a} (update)`)):(b.push(r),b.push(`${r}/${d}`),b.push(`${r}/${i}`),b.push(`${r}/${a}`),b.push(`${r}/${c}`)),S(k(h,n))?v.push(`${n} already exists, would skip.`):b.push(n);for(let e of P)for(let t of V){let n=K(t,e.fileExtension);T.push(`${e.path}/${n}`)}return{success:!0,message:`Would ${M?`update workflows in`:`initialize`} project with Agent Protocol v${s}${N.length?` (harnesses: ${N.join(`, `)})`:``}`,created:b,warnings:v,dryRun:!0,harnessFiles:T}}S(j)||(C(j,{recursive:!0}),b.push(r));let F=k(j,d);S(F)||(C(F,{recursive:!0}),b.push(`${r}/${d}`));let I=f(B);D(k(j,i),_(I)),b.push(`${r}/${i}`),D(k(j,a),o),b.push(`${r}/${a}`);let L=k(j,c);S(L)?v.push(`${c} already exists, skipping.`):(D(L,l),b.push(`${r}/${c}`));let R=k(h,n);if(S(R)?v.push(`${n} already exists, skipping.`):(D(R,g(h.split(`/`).pop()??`Project`)),b.push(n)),A)try{let t=w(O,`utf-8`),n=JSON.parse(t),r=!!n.scripts?.autonomos,i=n.devDependencies?.[`@autonomos/cli`],a=`^${B}`;n.scripts||={},e.noInstall||e.dryRun?(n.scripts.autonomos=`npx --yes @autonomos/cli`,D(O,JSON.stringify(n,null,4)+`
|
|
5
5
|
`),b.push(`package.json (scripts.autonomos via npx)`),r||v.push('Added "autonomos" npm script using npx (--no-install mode). Run `npm install` when ready.')):(n.scripts.autonomos=`autonomos`,n.devDependencies||={},n.devDependencies[`@autonomos/cli`]=a,D(O,JSON.stringify(n,null,4)+`
|
|
6
6
|
`),b.push(`package.json (scripts.autonomos + devDependencies.@autonomos/cli)`),!r&&!i?v.push('Added "autonomos" npm script and @autonomos/cli devDependency. Run `npm install` to install.'):i&&i!==a?v.push(`Bumped @autonomos/cli devDependency: ${i} → ${a}. Run \`npm install\` to apply.`):!r&&i&&v.push(`Added "autonomos" npm script (devDependency was already set).`))}catch{v.push(`Could not update package.json (invalid JSON or read error).`)}let z=H();for(let e of P){C(e.path,{recursive:!0});for(let t of V){let n=w(k(z,t),`utf-8`),r=K(t,e.fileExtension);D(k(e.path,r),n),T.push(`${e.path}/${r}`)}}return{success:!0,message:`Project initialized with Agent Protocol v${s}${N.length>0?` for harnesses: ${N.join(`, `)}`:` (no harness workflows installed)`}`,created:b,warnings:v,dryRun:!1,harnessFiles:T}}function K(e,t){return e.replace(/^protocol-/,``).replace(/\.[^.]+$/,``)+t}function ee(e={}){let t=k(e.cwd??process.cwd(),r),n=k(t,i);if(!S(n))return{success:!1,message:"Project not initialized. Run `autonomos init` first.",initialized:!1};let a;try{a=b(w(n,`utf-8`))}catch{return{success:!1,message:`Could not read manifest.json`,initialized:!0}}let o,s=k(t,c);if(S(s))try{let e=w(s,`utf-8`),t=u.parse(e);o={total:t.length,todo:t.filter(e=>e.status===`TODO`).length,inProgress:t.filter(e=>e.status===`IN_PROGRESS`).length,done:t.filter(e=>e.status===`DONE`).length,blocked:t.filter(e=>e.status===`BLOCKED`).length}}catch{}return{success:!0,message:`Project status retrieved`,protocolVersion:a.protocolVersion,cliVersion:a.cliVersion,initialized:!0,taskSummary:o}}const q=z,J=[`protocol-session.md`,`protocol-task.md`,`protocol-crystallize.md`];function Y(){let e=P(import.meta.url),t=[j(e,`..`,`..`,`..`,`..`,`core`,`src`,`workflows`),j(e,`..`,`..`,`..`,`core`,`dist`,`workflows`),j(e,`..`,`..`,`..`,`..`,`core`,`dist`,`workflows`)];for(let e of t)if(S(e))return e;throw Error(`Could not locate the workflows directory inside @autonomos/core`)}function X(e,t){return e.replace(/^protocol-/,``).replace(/\.[^.]+$/,``)+t}function te(e,t){let n=e.split(`.`).map(Number),r=t.split(`.`).map(Number);for(let e=0;e<3;e++){let t=n[e]??0,i=r[e]??0;if(t<i)return-1;if(t>i)return 1}return 0}function ne(e){let t=k(e,`package.json`);if(!S(t))return null;let n;try{n=JSON.parse(w(t,`utf-8`))}catch{return null}let r=`^${q}`,i=n.devDependencies?.[`@autonomos/cli`];if(i===r)return null;n.devDependencies||={},n.devDependencies[`@autonomos/cli`]=r;try{D(t,JSON.stringify(n,null,4)+`
|
|
7
7
|
`)}catch{return null}return i?`Bumped @autonomos/cli devDependency: ${i} → ${r}.`:`Added @autonomos/cli devDependency: ${r}.`}function Z(e,t){if(t.length===0)return[];let n=Y(),r=x(t,e),i=[];for(let e of r){C(e.path,{recursive:!0});for(let t of J){let r=w(k(n,t),`utf-8`),a=X(t,e.fileExtension);D(k(e.path,a),r),i.push(`${e.path}/${a}`)}}return i}function re(e={}){let t=e.cwd??process.cwd(),n=h(t)??t,c=k(n,r),l=k(c,i);if(!S(l))return{success:!1,message:"Project not initialized. Run `autonomos init` first."};let u=b(w(l,`utf-8`)),d=u.protocolVersion,f=ne(n),p=te(d,s);if(p===0){let t=Z(n,e.all?y().map(({id:e})=>e):e.harnesses??[]),r=t.length>0?` (installed: ${t.join(`, `)})`:``;return{success:!0,message:`Already up to date (Protocol v${s}).${f?` ${f}`:``}${r}`,previousVersion:d,newVersion:s,touchedHarnesses:t}}if(p>0)return{success:!1,message:`This project uses Protocol v${d}, but your CLI only knows v${s}. Update your CLI with \`npm i -g @autonomos/cli\`.`,previousVersion:d,newVersion:s,cliOutdated:!0};D(k(c,a),o),D(l,_({...u,protocolVersion:s,cliVersion:q,lastUpdated:new Date().toISOString()}));let m=[];try{let e=x(y().map(({id:e})=>e),n),t=Y();for(let n of e)if(S(n.path)){let e=!1;for(let t of J){let r=X(t,n.fileExtension);if(S(k(n.path,r))){e=!0;break}}if(e){C(n.path,{recursive:!0});for(let e of J){let r=w(k(t,e),`utf-8`),i=X(e,n.fileExtension);D(k(n.path,i),r)}m.push(n.path)}}}catch(e){console.warn(`Warning: Could not update harness workflows: ${e instanceof Error?e.message:String(e)}`)}let g=Z(n,e.all?y().map(({id:e})=>e):e.harnesses??[]);return{success:!0,message:`Protocol updated: v${d} → v${s}${m.length>0?` (updated workflows in ${m.join(`, `)})`:``}${g.length>0?` (installed: ${g.join(`, `)})`:``}${f?` ${f}`:``}`,previousVersion:d,newVersion:s,touchedHarnesses:[...m,...g]}}const Q=z,$=new e;$.name(`autonomos`).description(t.cyan(`CLI for the Autonomos Agent Protocol
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autonomos/cli",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4",
|
|
4
4
|
"description": "CLI tool for the Autonomos Agent Protocol",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"commander": "^14.0.2",
|
|
39
39
|
"picocolors": "1.1.1",
|
|
40
40
|
"@inquirer/prompts": "^7.0.0",
|
|
41
|
-
"@autonomos/core": "0.3.
|
|
41
|
+
"@autonomos/core": "0.3.2"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@tala-tools/eslint": "0.1.3",
|