@vpxa/aikit 0.1.26 → 0.1.29

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vpxa/aikit",
3
- "version": "0.1.26",
3
+ "version": "0.1.29",
4
4
  "type": "module",
5
5
  "description": "Local-first AI developer toolkit — knowledge base, code analysis, context management, and developer tools for LLM agents",
6
6
  "license": "MIT",
@@ -1 +1 @@
1
- import{loadConfig as e}from"../aikit-init.js";import{existsSync as t,mkdirSync as n}from"node:fs";import{basename as r,join as i,resolve as a}from"node:path";async function o(){let r=await import(`../../../flows/dist/index.js`),{FlowLoader:a,FlowRegistryManager:o,FlowStateMachine:s,GitInstaller:c,FoundationIntegration:l,SymlinkManager:u}=r,d=typeof r.getBuiltinFlows==`function`?r.getBuiltinFlows:void 0,f=e(),p=i(f.stateDir??i(f.sources[0].path,`.aikit-state`),`flows`),m=i(p,`registry.json`),h=i(p,`state.json`);t(p)||n(p,{recursive:!0});let g=f.sources[0].path;return{loader:new a,registry:new o(m),stateMachine:new s(h),git:new c(i(p,`installed`)),foundation:new l,symlinks:new u,getBuiltinFlows:d,cwd:g}}const s=[{name:`flow`,description:`Manage pluggable development flows`,usage:`flow <add|remove|list|info|use|update|status|start|reset> [args]`,run:async e=>{let n=e[0];if(!n){console.log(`Usage: aikit flow <add|remove|list|info|use|update|status|start|reset>`),console.log(``),console.log(`Commands:`),console.log(` add <source> Install a flow from git URL or local path`),console.log(` remove <name> Remove an installed flow`),console.log(` list List all installed flows`),console.log(` info <name> Show details of a flow`),console.log(` use <name> Set active flow (start it)`),console.log(` update <name> Update a flow from its source`),console.log(` status Show current flow execution status`),console.log(` start [name] Start a flow (or resume)`),console.log(` reset Reset the active flow`);return}let s=await o();switch(n){case`add`:{let n=e[1];if(!n){console.error(`Usage: aikit flow add <source>`),console.error(` source: git URL (https://...) or local path`);return}let o=n.startsWith(`http`)||n.startsWith(`git@`)||n.endsWith(`.git`),c=a(n),l=t(c);if(!o&&!l){console.error(`Source not found: ${n}`),console.error(`Provide a git URL or existing local path.`);return}let u,d;if(o){console.log(`Cloning ${n}...`);let e=s.git.clone(n);if(!e.success||!e.data){console.error(e.error??`Failed to clone flow`);return}u=e.data,d=`git`}else{let t=e[2]||r(c);console.log(`Copying local flow from ${n}...`);let i=s.git.copyLocal(c,t);if(!i.success||!i.data){console.error(i.error??`Failed to copy local flow`);return}u=i.data,d=`local`}let f=await s.loader.load(u);if(!f.success||!f.data){console.error(f.error??`Failed to load flow`),s.git.remove(u);return}let{manifest:p,format:m}=f.data;if(p.install.length>0){console.log(`Installing ${p.install.length} dependencies...`);let e=s.git.runInstallDeps(p.install);if(!e.success){console.error(`Dependency install failed: ${e.error}`),s.git.remove(u);return}}let h=new Date().toISOString(),g=s.registry.register({name:p.name,version:p.version,source:n,sourceType:d,installPath:u,format:m,registeredAt:h,updatedAt:h,manifest:p});if(!g.success){console.error(g.error??`Failed to register flow`),s.git.remove(u);return}s.foundation.injectPreamble(i(s.cwd,`AGENTS.md`),p),s.symlinks.createSymlinks(s.cwd,p.name,u,p),console.log(`✓ Flow "${p.name}" v${p.version} installed (${m} format)`),console.log(` Steps: ${p.steps.map(e=>e.id).join(` → `)}`);break}case`remove`:{let t=e[1];if(!t){console.error(`Usage: aikit flow remove <name>`);return}let n=s.registry.get(t);if(!n){console.error(`Flow "${t}" not found`);return}s.symlinks.removeSymlinks(s.cwd,t),s.foundation.removePreamble(i(s.cwd,`AGENTS.md`));let r=s.git.remove(n.installPath);if(!r.success){console.error(r.error??`Failed to remove flow files`);return}let a=s.registry.unregister(t);if(!a.success){console.error(a.error??`Failed to unregister flow`);return}console.log(`✓ Flow "${t}" removed`);break}case`list`:{let e=s.registry.list();if(e.length===0){console.log("No flows installed. Use `aikit flow add <source>` to install one.");return}console.log(`Installed Flows:`),console.log(`─`.repeat(60));for(let t of e){let e=t.manifest.steps.map(e=>e.id).join(` → `);console.log(` ${t.name} v${t.version} (${t.sourceType}, ${t.format})`),console.log(` Steps: ${e}`)}let t=s.stateMachine.getStatus();t.success&&t.data&&(console.log(``),console.log(`Active: ${t.data.flow} (${t.data.status}, step: ${t.data.currentStep??`done`})`));break}case`info`:{let t=e[1];if(!t){console.error(`Usage: aikit flow info <name>`);return}let n=s.registry.get(t);if(!n){console.error(`Flow "${t}" not found`);return}console.log(`Flow: ${n.name}`),console.log(`Version: ${n.version}`),console.log(`Source: ${n.source} (${n.sourceType})`),console.log(`Format: ${n.format}`),console.log(`Path: ${n.installPath}`),console.log(`Registered: ${n.registeredAt}`),console.log(`Updated: ${n.updatedAt}`),console.log(``),console.log(`Steps:`);for(let e of n.manifest.steps){let t=e.requires.length?` (requires: ${e.requires.join(`, `)})`:``;console.log(` ${e.id}: ${e.name}${t}`),console.log(` Skill: ${e.skill}`),console.log(` Produces: ${e.produces.join(`, `)}`)}if(n.manifest.install.length>0){console.log(``),console.log(`Dependencies:`);for(let e of n.manifest.install)console.log(` ${e}`)}break}case`use`:case`start`:{let t=e[1],r=t?s.registry.get(t):null;if(n===`use`&&!t){console.error(`Usage: aikit flow use <name>`);return}if(n===`start`&&!t){let e=s.stateMachine.getStatus();if(e.success&&e.data&&e.data.status===`active`){console.log(`Resuming flow: ${e.data.flow}`),console.log(`Current step: ${e.data.currentStep}`),console.log(`Completed: ${e.data.completedSteps.join(`, `)||`none`}`);return}console.error("No active flow. Use `aikit flow start <name>` to begin one.");return}if(!r){console.error(`Flow "${t}" not found. Use \`aikit flow list\` to see installed flows.`);return}let i=s.stateMachine.start(r.name,r.manifest);if(!i.success||!i.data){console.error(i.error??`Failed to start flow`);return}let a=i.data;console.log(`✓ Flow "${r.name}" started`),console.log(` Current step: ${a.currentStep}`),console.log(` Steps: ${r.manifest.steps.map(e=>e.id).join(` → `)}`);break}case`update`:{let t=e[1];if(!t){console.error(`Usage: aikit flow update <name>`);return}let n=s.registry.get(t);if(!n){console.error(`Flow "${t}" not found`);return}if(n.sourceType!==`git`){console.error(`Flow "${t}" is ${n.sourceType}, not updatable via git`);return}console.log(`Updating ${t}...`);let r=s.git.update(n.installPath);if(!r.success){console.error(r.error??`Failed to update flow`);return}let i=await s.loader.load(n.installPath);if(i.success&&i.data){let e=new Date().toISOString(),t=s.registry.register({...n,version:i.data.manifest.version,format:i.data.format,manifest:i.data.manifest,updatedAt:e});if(!t.success){console.error(t.error??`Failed to refresh flow registry entry`);return}}console.log(`✓ Flow "${t}" updated`);break}case`status`:{let e=s.stateMachine.getStatus();if(!e.success||!e.data){console.log(`No active flow.`);return}let t=e.data;if(console.log(`Flow: ${t.flow}`),console.log(`Status: ${t.status}`),console.log(`Current Step: ${t.currentStep??`(completed)`}`),console.log(`Completed: ${t.completedSteps.join(`, `)||`none`}`),t.skippedSteps.length>0&&console.log(`Skipped: ${t.skippedSteps.join(`, `)}`),console.log(`Started: ${t.startedAt}`),console.log(`Updated: ${t.updatedAt}`),Object.keys(t.artifacts).length>0){console.log(`Artifacts:`);for(let[e,n]of Object.entries(t.artifacts))console.log(` ${e}: ${n}`)}break}case`reset`:{let e=s.stateMachine.reset();if(!e.success){console.error(e.error??`Failed to reset flow state`);return}console.log(`✓ Flow state reset`);break}default:console.error(`Unknown flow command: ${n}`),console.log("Use `aikit flow` for help.")}}}];export{s as flowCommands};
1
+ import{loadConfig as e}from"../aikit-init.js";import{copyFileSync as t,existsSync as n,mkdirSync as r}from"node:fs";import{basename as i,dirname as a,join as o,resolve as s}from"node:path";async function c(){let t=await import(`../../../flows/dist/index.js`),{FlowLoader:i,FlowRegistryManager:a,FlowStateMachine:s,GitInstaller:c,FoundationIntegration:l,SymlinkManager:u}=t,d=typeof t.getBuiltinFlows==`function`?t.getBuiltinFlows:void 0,f=e(),p=o(f.stateDir??o(f.sources[0].path,`.aikit-state`),`flows`),m=o(p,`registry.json`),h=o(p,`state.json`);n(p)||r(p,{recursive:!0});let g=f.sources[0].path;return{loader:new i,registry:new a(m),stateMachine:new s(h),git:new c(o(p,`installed`)),foundation:new l,symlinks:new u,getBuiltinFlows:d,cwd:g}}const l=[e=>o(`skills`,e,`SKILL.md`),e=>o(`skills`,e,`README.md`),e=>o(e,`SKILL.md`),e=>o(e,`README.md`)];function u(e,i){for(let s of i.steps){let i=o(e,s.instruction);if(n(i))continue;let c=!1;for(let u of l){let l=o(e,u(s.id));if(n(l)){let e=a(i);n(e)||r(e,{recursive:!0}),t(l,i),c=!0;break}}c||console.warn(`Warning: instruction file for step "${s.id}" not found.\n Expected: ${s.instruction}\n Searched: ${l.map(e=>e(s.id)).join(`, `)}`)}}const d=[{name:`flow`,description:`Manage pluggable development flows`,usage:`flow <add|remove|list|info|use|update|status|start|reset> [args]`,run:async e=>{let t=e[0];if(!t){console.log(`Usage: aikit flow <add|remove|list|info|use|update|status|start|reset>`),console.log(``),console.log(`Commands:`),console.log(` add <source> Install a flow from git URL or local path`),console.log(` remove <name> Remove an installed flow`),console.log(` list List all installed flows`),console.log(` info <name> Show details of a flow`),console.log(` use <name> Set active flow (start it)`),console.log(` update <name> Update a flow from its source`),console.log(` status Show current flow execution status`),console.log(` start [name] Start a flow (or resume)`),console.log(` reset Reset the active flow`);return}let r=await c();switch(t){case`add`:{let t=e[1];if(!t){console.error(`Usage: aikit flow add <source>`),console.error(` source: git URL (https://...) or local path`);return}let a=t.startsWith(`http`)||t.startsWith(`git@`)||t.endsWith(`.git`),c=s(t),l=n(c);if(!a&&!l){console.error(`Source not found: ${t}`),console.error(`Provide a git URL or existing local path.`);return}let d,f;if(a){console.log(`Cloning ${t}...`);let e=r.git.clone(t);if(!e.success||!e.data){console.error(e.error??`Failed to clone flow`);return}d=e.data,f=`git`}else{let n=e[2]||i(c);console.log(`Copying local flow from ${t}...`);let a=r.git.copyLocal(c,n);if(!a.success||!a.data){console.error(a.error??`Failed to copy local flow`);return}d=a.data,f=`local`}let p=await r.loader.load(d);if(!p.success||!p.data){console.error(p.error??`Failed to load flow`),r.git.remove(d);return}let{manifest:m,format:h}=p.data;if(u(d,m),m.install.length>0){console.log(`Installing ${m.install.length} dependencies...`);let e=r.git.runInstallDeps(m.install);if(!e.success){console.error(`Dependency install failed: ${e.error}`),r.git.remove(d);return}}let g=new Date().toISOString(),_=r.registry.register({name:m.name,version:m.version,source:t,sourceType:f,installPath:d,format:h,registeredAt:g,updatedAt:g,manifest:m});if(!_.success){console.error(_.error??`Failed to register flow`),r.git.remove(d);return}r.foundation.injectPreamble(o(r.cwd,`AGENTS.md`),m),r.symlinks.createSymlinks(r.cwd,m.name,d,m),console.log(`✓ Flow "${m.name}" v${m.version} installed (${h} format)`),console.log(` Steps: ${m.steps.map(e=>e.id).join(` → `)}`);break}case`remove`:{let t=e[1];if(!t){console.error(`Usage: aikit flow remove <name>`);return}let n=r.registry.get(t);if(!n){console.error(`Flow "${t}" not found`);return}r.symlinks.removeSymlinks(r.cwd,t),r.foundation.removePreamble(o(r.cwd,`AGENTS.md`));let i=r.git.remove(n.installPath);if(!i.success){console.error(i.error??`Failed to remove flow files`);return}let a=r.registry.unregister(t);if(!a.success){console.error(a.error??`Failed to unregister flow`);return}console.log(`✓ Flow "${t}" removed`);break}case`list`:{let e=r.registry.list();if(e.length===0){console.log("No flows installed. Use `aikit flow add <source>` to install one.");return}console.log(`Installed Flows:`),console.log(`─`.repeat(60));for(let t of e){let e=t.manifest.steps.map(e=>e.id).join(` → `);console.log(` ${t.name} v${t.version} (${t.sourceType}, ${t.format})`),console.log(` Steps: ${e}`)}let t=r.stateMachine.getStatus();t.success&&t.data&&(console.log(``),console.log(`Active: ${t.data.flow} (${t.data.status}, step: ${t.data.currentStep??`done`})`));break}case`info`:{let t=e[1];if(!t){console.error(`Usage: aikit flow info <name>`);return}let n=r.registry.get(t);if(!n){console.error(`Flow "${t}" not found`);return}console.log(`Flow: ${n.name}`),console.log(`Version: ${n.version}`),console.log(`Source: ${n.source} (${n.sourceType})`),console.log(`Format: ${n.format}`),console.log(`Path: ${n.installPath}`),console.log(`Registered: ${n.registeredAt}`),console.log(`Updated: ${n.updatedAt}`),console.log(``),console.log(`Steps:`);for(let e of n.manifest.steps){let t=e.requires.length?` (requires: ${e.requires.join(`, `)})`:``;console.log(` ${e.id}: ${e.name}${t}`),console.log(` Skill: ${e.skill}`),console.log(` Produces: ${e.produces.join(`, `)}`)}if(n.manifest.install.length>0){console.log(``),console.log(`Dependencies:`);for(let e of n.manifest.install)console.log(` ${e}`)}break}case`use`:case`start`:{let n=e[1],i=n?r.registry.get(n):null;if(t===`use`&&!n){console.error(`Usage: aikit flow use <name>`);return}if(t===`start`&&!n){let e=r.stateMachine.getStatus();if(e.success&&e.data&&e.data.status===`active`){console.log(`Resuming flow: ${e.data.flow}`),console.log(`Current step: ${e.data.currentStep}`),console.log(`Completed: ${e.data.completedSteps.join(`, `)||`none`}`);return}console.error("No active flow. Use `aikit flow start <name>` to begin one.");return}if(!i){console.error(`Flow "${n}" not found. Use \`aikit flow list\` to see installed flows.`);return}let a=r.stateMachine.start(i.name,i.manifest);if(!a.success||!a.data){console.error(a.error??`Failed to start flow`);return}let o=a.data;console.log(`✓ Flow "${i.name}" started`),console.log(` Current step: ${o.currentStep}`),console.log(` Steps: ${i.manifest.steps.map(e=>e.id).join(` → `)}`);break}case`update`:{let t=e[1];if(!t){console.error(`Usage: aikit flow update <name>`);return}let n=r.registry.get(t);if(!n){console.error(`Flow "${t}" not found`);return}if(n.sourceType!==`git`){console.error(`Flow "${t}" is ${n.sourceType}, not updatable via git`);return}console.log(`Updating ${t}...`);let i=r.git.update(n.installPath);if(!i.success){console.error(i.error??`Failed to update flow`);return}let a=await r.loader.load(n.installPath);if(a.success&&a.data){let e=new Date().toISOString(),t=r.registry.register({...n,version:a.data.manifest.version,format:a.data.format,manifest:a.data.manifest,updatedAt:e});if(!t.success){console.error(t.error??`Failed to refresh flow registry entry`);return}}console.log(`✓ Flow "${t}" updated`);break}case`status`:{let e=r.stateMachine.getStatus();if(!e.success||!e.data){console.log(`No active flow.`);return}let t=e.data;if(console.log(`Flow: ${t.flow}`),console.log(`Status: ${t.status}`),console.log(`Current Step: ${t.currentStep??`(completed)`}`),console.log(`Completed: ${t.completedSteps.join(`, `)||`none`}`),t.skippedSteps.length>0&&console.log(`Skipped: ${t.skippedSteps.join(`, `)}`),console.log(`Started: ${t.startedAt}`),console.log(`Updated: ${t.updatedAt}`),Object.keys(t.artifacts).length>0){console.log(`Artifacts:`);for(let[e,n]of Object.entries(t.artifacts))console.log(` ${e}: ${n}`)}break}case`reset`:{let e=r.stateMachine.reset();if(!e.success){console.error(e.error??`Failed to reset flow state`);return}console.log(`✓ Flow state reset`);break}default:console.error(`Unknown flow command: ${t}`),console.log("Use `aikit flow` for help.")}}}];export{d as flowCommands};
@@ -6,6 +6,8 @@ declare class GitInstaller {
6
6
  constructor(flowsDir: string);
7
7
  /**
8
8
  * Clone a git repo into the flows directory.
9
+ * On auth failure, if GCM is available, retries interactively so the
10
+ * credential manager can open a browser / device-code flow.
9
11
  * Returns the local install path.
10
12
  */
11
13
  clone(repoUrl: string): FlowResult<string>;
@@ -1,2 +1,2 @@
1
- import{cpSync as e,existsSync as t,mkdirSync as n,rmSync as r}from"node:fs";import{basename as i,join as a}from"node:path";import{execSync as o}from"node:child_process";function s(e){if(!e||typeof e!=`object`||!(`stderr`in e))return``;let t=e.stderr;return Buffer.isBuffer(t)?t.toString().trim():typeof t==`string`?t.trim():``}function c(e){try{return new URL(e).hostname}catch{}return e.match(/^[^@]+@([^:]+):/)?.[1]??`<host>`}function l(e,t,n){let r=[`Git operation failed for: ${e}`],i=c(e),a=t.includes(`ETIMEDOUT`)||t.includes(`SIGTERM`)||t.toLowerCase().includes(`timed out`),o=n.includes(`Authentication failed`)||n.includes(`could not read Username`)||n.includes(`terminal prompts disabled`)||n.includes(`401`)||n.includes(`403`)||n.includes(`Permission denied`),s=n.includes(`SSL certificate`)||n.includes(`unable to access`)&&n.includes(`SSL`),l=n.includes(`Could not resolve host`)||n.includes(`Name or service not known`),u=n.includes(`SAML`)||n.includes(`single sign-on`);return o||u?(r.push(``),r.push(`Cause: Authentication required or credentials not configured.`),r.push(``),r.push(`To fix this, ensure git can access this repository:`),r.push(``),r.push(` Option 1 - SSH key:`),r.push(` 1. Generate an SSH key: ssh-keygen -t ed25519`),r.push(` 2. Add the public key to your Git hosting account`),r.push(` 3. Use the SSH URL instead: git@<host>:<org>/<repo>.git`),r.push(``),r.push(` Option 2 - Personal Access Token (PAT):`),r.push(` 1. Create a PAT in your Git hosting Settings > Developer settings > Tokens`),r.push(` 2. For GitHub Enterprise with SAML SSO, authorize the token for your org`),r.push(` 3. Configure git credentials:`),r.push(` git config --global credential.helper store`),r.push(` git clone ${e} (enter PAT as password)`),r.push(``),r.push(` Option 3 - Git Credential Manager:`),r.push(` 1. Install: https://github.com/git-ecosystem/git-credential-manager`),r.push(` 2. Run: git clone ${e}`),r.push(` 3. Follow the browser-based auth prompt`),r.push(``),r.push(`After configuring credentials, retry: aikit flow add ${e}`)):a?(r.push(``),r.push(`Cause: Connection timed out - the server did not respond within 60 seconds.`),r.push(``),r.push(`Possible reasons:`),r.push(` - The repository requires VPN access. Ensure your VPN is connected`),r.push(` - The host is behind a firewall or corporate proxy`),r.push(` - The URL may be incorrect`),r.push(``),r.push(`Diagnostics:`),r.push(` 1. Verify the URL is correct: ${e}`),r.push(` 2. Test connectivity: git ls-remote ${e}`),r.push(` 3. If behind a proxy, configure git:`),r.push(` git config --global http.proxy http://proxy:port`),r.push(``),r.push(`If this is a corporate/internal host, you may need to:`),r.push(` - Connect to the corporate VPN`),r.push(` - Add the host to your SSH config or git config`),r.push(` - Ask your IT team to allowlist your machine`),r.push(``),r.push(`After resolving, retry: aikit flow add ${e}`)):s?(r.push(``),r.push(`Cause: SSL/TLS certificate verification failed.`),r.push(``),r.push(`This often happens with corporate proxies or self-signed certificates.`),r.push(``),r.push(`To fix:`),r.push(` 1. If your company uses a custom CA, add it:`),r.push(` git config --global http.sslCAInfo /path/to/ca-bundle.crt`),r.push(` 2. As a last resort (not recommended for production):`),r.push(` git config --global http.sslVerify false`),r.push(``),r.push(`After resolving, retry: aikit flow add ${e}`)):l?(r.push(``),r.push(`Cause: Cannot resolve hostname.`),r.push(``),r.push(`Check:`),r.push(` 1. Is the URL correct? ${e}`),r.push(` 2. Are you connected to the internet/VPN?`),r.push(` 3. Can you resolve the host? ping ${i}`),r.push(``),r.push(`After resolving, retry: aikit flow add ${e}`)):(r.push(``),r.push(`Error: ${t}`),n&&r.push(`Details: ${n}`),r.push(``),r.push(`Troubleshooting:`),r.push(` 1. Verify the URL is a valid git repository: git ls-remote ${e}`),r.push(` 2. Check your git credentials and network connectivity`),r.push(` 3. If the repo requires auth, configure credentials first (PAT or SSH key)`),r.push(``),r.push(`After resolving, retry: aikit flow add ${e}`)),r.join(`
2
- `)}var u=class{constructor(e){this.flowsDir=e}clone(e){let n=this.repoNameFromUrl(e),i=a(this.flowsDir,n);if(t(i))if(!t(a(i,`.git`)))r(i,{recursive:!0,force:!0});else return{success:!1,error:`Flow "${n}" already installed at ${i}. Use update instead.`};try{return this.ensureFlowsDir(),o(`git clone --depth 1 ${e} ${i}`,{stdio:`pipe`,timeout:6e4,env:{...process.env,GIT_TERMINAL_PROMPT:`0`,GIT_ASKPASS:``}}),{success:!0,data:i}}catch(n){t(i)&&r(i,{recursive:!0,force:!0});let a=s(n);return{success:!1,error:l(e,n instanceof Error?n.message:String(n),a)}}}update(e){if(!t(e))return{success:!1,error:`Install path not found: ${e}`};try{return o(`git pull --ff-only`,{cwd:e,stdio:`pipe`,timeout:6e4,env:{...process.env,GIT_TERMINAL_PROMPT:`0`,GIT_ASKPASS:``}}),{success:!0}}catch(t){let n=e;try{n=o(`git remote get-url origin`,{cwd:e,stdio:`pipe`,timeout:1e4}).toString().trim()}catch{}let r=s(t),i=t instanceof Error?t.message:String(t);return{success:!1,error:l(n,i,r)}}}copyLocal(n,r){let i=a(this.flowsDir,r);if(t(i))return{success:!1,error:`Flow "${r}" already installed at ${i}`};try{return this.ensureFlowsDir(),e(n,i,{recursive:!0}),{success:!0,data:i}}catch(e){return{success:!1,error:`Copy failed: ${e instanceof Error?e.message:String(e)}`}}}remove(e){if(!t(e))return{success:!0};try{return r(e,{recursive:!0,force:!0}),{success:!0}}catch(e){return{success:!1,error:`Remove failed: ${e instanceof Error?e.message:String(e)}`}}}runInstallDeps(e){for(let t of e)try{if(t.startsWith(`npm:`)){o(`npx skills add ${t.slice(4)} -g`,{stdio:`pipe`,timeout:12e4});continue}if(t.endsWith(`.git`)||t.includes(`github.com`)){o(`npx skills add ${t} -g`,{stdio:`pipe`,timeout:12e4});continue}return{success:!1,error:`Unknown install entry format: ${t}`}}catch(e){return{success:!1,error:`Install dependency failed for "${t}": ${e instanceof Error?e.message:String(e)}`}}return{success:!0}}repoNameFromUrl(e){return i(e).replace(/\.git$/,``)}ensureFlowsDir(){t(this.flowsDir)||n(this.flowsDir,{recursive:!0})}};export{u as GitInstaller};
1
+ import{cpSync as e,existsSync as t,mkdirSync as n,rmSync as r}from"node:fs";import{basename as i,join as a}from"node:path";import{execSync as o,spawnSync as s}from"node:child_process";function c(e){if(!e||typeof e!=`object`||!(`stderr`in e))return``;let t=e.stderr;return Buffer.isBuffer(t)?t.toString().trim():typeof t==`string`?t.trim():``}function l(e){try{return new URL(e).hostname}catch{}return e.match(/^[^@]+@([^:]+):/)?.[1]??`<host>`}function u(e,t,n){let r=[`Git operation failed for: ${e}`],i=l(e),a=t.includes(`ETIMEDOUT`)||t.includes(`SIGTERM`)||t.toLowerCase().includes(`timed out`),o=n.includes(`Authentication failed`)||n.includes(`could not read Username`)||n.includes(`terminal prompts disabled`)||n.includes(`401`)||n.includes(`403`)||n.includes(`Permission denied`),s=n.includes(`SSL certificate`)||n.includes(`unable to access`)&&n.includes(`SSL`),c=n.includes(`Could not resolve host`)||n.includes(`Name or service not known`),u=n.includes(`SAML`)||n.includes(`single sign-on`);return o||u?(r.push(``),r.push(`Cause: Authentication required or credentials not configured.`),r.push(``),r.push(`To fix this, ensure git can access this repository:`),r.push(``),r.push(` Option 1 - SSH key:`),r.push(` 1. Generate an SSH key: ssh-keygen -t ed25519`),r.push(` 2. Add the public key to your Git hosting account`),r.push(` 3. Use the SSH URL instead: git@<host>:<org>/<repo>.git`),r.push(``),r.push(` Option 2 - Personal Access Token (PAT):`),r.push(` 1. Create a PAT in your Git hosting Settings > Developer settings > Tokens`),r.push(` 2. For GitHub Enterprise with SAML SSO, authorize the token for your org`),r.push(` 3. Configure git credentials:`),r.push(` git config --global credential.helper store`),r.push(` git clone ${e} (enter PAT as password)`),r.push(``),r.push(` Option 3 - Git Credential Manager:`),r.push(` 1. Install: https://github.com/git-ecosystem/git-credential-manager`),r.push(` 2. Run: git clone ${e}`),r.push(` 3. Follow the browser-based auth prompt`),r.push(``),r.push(`After configuring credentials, retry: aikit flow add ${e}`)):a?(r.push(``),r.push(`Cause: Connection timed out - the server did not respond within 60 seconds.`),r.push(``),r.push(`Possible reasons:`),r.push(` - The repository requires VPN access. Ensure your VPN is connected`),r.push(` - The host is behind a firewall or corporate proxy`),r.push(` - The URL may be incorrect`),r.push(``),r.push(`Diagnostics:`),r.push(` 1. Verify the URL is correct: ${e}`),r.push(` 2. Test connectivity: git ls-remote ${e}`),r.push(` 3. If behind a proxy, configure git:`),r.push(` git config --global http.proxy http://proxy:port`),r.push(``),r.push(`If this is a corporate/internal host, you may need to:`),r.push(` - Connect to the corporate VPN`),r.push(` - Add the host to your SSH config or git config`),r.push(` - Ask your IT team to allowlist your machine`),r.push(``),r.push(`After resolving, retry: aikit flow add ${e}`)):s?(r.push(``),r.push(`Cause: SSL/TLS certificate verification failed.`),r.push(``),r.push(`This often happens with corporate proxies or self-signed certificates.`),r.push(``),r.push(`To fix:`),r.push(` 1. If your company uses a custom CA, add it:`),r.push(` git config --global http.sslCAInfo /path/to/ca-bundle.crt`),r.push(` 2. As a last resort (not recommended for production):`),r.push(` git config --global http.sslVerify false`),r.push(``),r.push(`After resolving, retry: aikit flow add ${e}`)):c?(r.push(``),r.push(`Cause: Cannot resolve hostname.`),r.push(``),r.push(`Check:`),r.push(` 1. Is the URL correct? ${e}`),r.push(` 2. Are you connected to the internet/VPN?`),r.push(` 3. Can you resolve the host? ping ${i}`),r.push(``),r.push(`After resolving, retry: aikit flow add ${e}`)):(r.push(``),r.push(`Error: ${t}`),n&&r.push(`Details: ${n}`),r.push(``),r.push(`Troubleshooting:`),r.push(` 1. Verify the URL is a valid git repository: git ls-remote ${e}`),r.push(` 2. Check your git credentials and network connectivity`),r.push(` 3. If the repo requires auth, configure credentials first (PAT or SSH key)`),r.push(``),r.push(`After resolving, retry: aikit flow add ${e}`)),r.join(`
2
+ `)}function d(){try{return s(`git`,[`credential-manager`,`--version`],{stdio:`pipe`,timeout:5e3}).status===0}catch{return!1}}function f(e,t){let n=`${e}\n${t}`.toLowerCase();return n.includes(`authentication failed`)||n.includes(`could not read username`)||n.includes(`saml sso`)||n.includes(`terminal prompts disabled`)||n.includes(`host key verification failed`)||n.includes(`permission denied`)||n.includes(`403`)||n.includes(`401`)}var p=class{constructor(e){this.flowsDir=e}clone(e){let n=this.repoNameFromUrl(e),i=a(this.flowsDir,n);if(t(i))if(!t(a(i,`.git`)))r(i,{recursive:!0,force:!0});else return{success:!1,error:`Flow "${n}" already installed at ${i}. Use update instead.`};try{return this.ensureFlowsDir(),o(`git clone --depth 1 ${e} ${i}`,{stdio:`pipe`,timeout:6e4,env:{...process.env,GIT_TERMINAL_PROMPT:`0`,GIT_ASKPASS:``}}),{success:!0,data:i}}catch(n){t(i)&&r(i,{recursive:!0,force:!0});let a=c(n),o=n instanceof Error?n.message:String(n);if(f(o,a)&&d()){let n=l(e)||e;console.log(`\nAuthentication required for ${n}.\nGit Credential Manager detected - opening browser for login...\n(If a browser window does not open, check your terminal for a device code.)\n`);try{if(this.ensureFlowsDir(),s(`git`,[`clone`,`--depth`,`1`,e,i],{stdio:`inherit`,timeout:12e4,env:{...process.env,GIT_TERMINAL_PROMPT:`1`}}).status===0)return{success:!0,data:i};t(i)&&r(i,{recursive:!0,force:!0})}catch{t(i)&&r(i,{recursive:!0,force:!0})}}return{success:!1,error:u(e,o,a)}}}update(e){if(!t(e))return{success:!1,error:`Install path not found: ${e}`};try{return o(`git pull --ff-only`,{cwd:e,stdio:`pipe`,timeout:6e4,env:{...process.env,GIT_TERMINAL_PROMPT:`0`,GIT_ASKPASS:``}}),{success:!0}}catch(t){let n=e;try{n=o(`git remote get-url origin`,{cwd:e,stdio:`pipe`,timeout:1e4}).toString().trim()}catch{}let r=c(t),i=t instanceof Error?t.message:String(t);if(f(i,r)&&d()){let t=l(n)||n;console.log(`\nAuthentication required for ${t}.\nGit Credential Manager detected - opening browser for login...\n`);try{if(s(`git`,[`pull`,`--ff-only`],{cwd:e,stdio:`inherit`,timeout:12e4,env:{...process.env,GIT_TERMINAL_PROMPT:`1`}}).status===0)return{success:!0}}catch{}}return{success:!1,error:u(n,i,r)}}}copyLocal(n,r){let i=a(this.flowsDir,r);if(t(i))return{success:!1,error:`Flow "${r}" already installed at ${i}`};try{return this.ensureFlowsDir(),e(n,i,{recursive:!0}),{success:!0,data:i}}catch(e){return{success:!1,error:`Copy failed: ${e instanceof Error?e.message:String(e)}`}}}remove(e){if(!t(e))return{success:!0};try{return r(e,{recursive:!0,force:!0}),{success:!0}}catch(e){return{success:!1,error:`Remove failed: ${e instanceof Error?e.message:String(e)}`}}}runInstallDeps(e){for(let t of e)try{if(t.startsWith(`npm:`)){o(`npx skills add ${t.slice(4)} -g`,{stdio:`pipe`,timeout:12e4});continue}if(t.endsWith(`.git`)||t.includes(`github.com`)){o(`npx skills add ${t} -g`,{stdio:`pipe`,timeout:12e4});continue}return{success:!1,error:`Unknown install entry format: ${t}`}}catch(e){return{success:!1,error:`Install dependency failed for "${t}": ${e instanceof Error?e.message:String(e)}`}}return{success:!0}}repoNameFromUrl(e){return i(e).replace(/\.git$/,``)}ensureFlowsDir(){t(this.flowsDir)||n(this.flowsDir,{recursive:!0})}};export{p as GitInstaller};