@vpxa/aikit 0.1.29 → 0.1.30

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.29",
3
+ "version": "0.1.30",
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{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};
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";import{getGlobalDataDir as c}from"../../../core/dist/index.js";async function l(){let t=await import(`../../../flows/dist/index.js`),{FlowLoader:i,FlowRegistryManager:a,FlowStateMachine:s,GitInstaller:l}=t,u=typeof t.getBuiltinFlows==`function`?t.getBuiltinFlows:void 0,d=e(),f=o(d.stateDir??o(d.sources[0].path,`.aikit-state`),`flows`),p=o(c(),`flows`);r(p,{recursive:!0});let m=o(p,`registry.json`),h=o(f,`state.json`);n(f)||r(f,{recursive:!0});let g=d.sources[0].path;return{loader:new i,registry:new a(m),stateMachine:new s(h),git:new l(o(f,`installed`)),getBuiltinFlows:u,cwd:g}}const u=[e=>o(`skills`,e,`SKILL.md`),e=>o(`skills`,e,`README.md`),e=>o(e,`SKILL.md`),e=>o(e,`README.md`)];function d(e,i){for(let s of i.steps){let i=o(e,s.instruction);if(n(i))continue;let c=!1;for(let l of u){let u=o(e,l(s.id));if(n(u)){let e=a(i);n(e)||r(e,{recursive:!0}),t(u,i),c=!0;break}}c||console.warn(`Warning: instruction file for step "${s.id}" not found.\n Expected: ${s.instruction}\n Searched: ${u.map(e=>e(s.id)).join(`, `)}`)}}const f=[{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 l();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`),o=s(t),c=n(o);if(!a&&!c){console.error(`Source not found: ${t}`),console.error(`Provide a git URL or existing local path.`);return}let l,u;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}l=e.data,u=`git`}else{let n=e[2]||i(o);console.log(`Copying local flow from ${t}...`);let a=r.git.copyLocal(o,n);if(!a.success||!a.data){console.error(a.error??`Failed to copy local flow`);return}l=a.data,u=`local`}let f=await r.loader.load(l);if(!f.success||!f.data){console.error(f.error??`Failed to load flow`),r.git.remove(l);return}let{manifest:p,format:m}=f.data;if(d(l,p),p.install.length>0){console.log(`Installing ${p.install.length} dependencies...`);let e=r.git.runInstallDeps(p.install);if(!e.success){console.error(`Dependency install failed: ${e.error}`),r.git.remove(l);return}}let h=new Date().toISOString(),g=r.registry.register({name:p.name,version:p.version,source:t,sourceType:u,installPath:l,format:m,registeredAt:h,updatedAt:h,manifest:p});if(!g.success){console.error(g.error??`Failed to register flow`),r.git.remove(l);return}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=r.registry.get(t);if(!n){console.error(`Flow "${t}" not found`);return}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{f as flowCommands};
@@ -1 +1 @@
1
- import{getToolMeta as e}from"../tool-metadata.js";import{existsSync as t}from"node:fs";import{basename as n,join as r,resolve as i}from"node:path";import{z as a}from"zod";import{readFile as o}from"node:fs/promises";import{createLogger as s,serializeError as c}from"../../../core/dist/index.js";import{homedir as l}from"node:os";const u=s(`flow-tools`);function d(e){return{content:[{type:`text`,text:e}]}}function f(e){return e instanceof Error?e.message:String(e)}function p(s,p){let m=p.sources?.[0]?.path??process.cwd(),h=r(p.stateDir??r(p.sources[0].path,`.aikit-state`),`flows`),g=r(h,`registry.json`),_=r(h,`state.json`);function v(e,t){return i(y(e),t).replaceAll(`\\`,`/`)}function y(e){if(e.sourceType===`builtin`){let r=n(e.installPath),a=i(m,`.github`,`flows`,r);if(t(a))return a.replaceAll(`\\`,`/`);let o=i(l(),`.copilot`,`flows`,r);return t(o)?o.replaceAll(`\\`,`/`):a.replaceAll(`\\`,`/`)}return e.installPath.replaceAll(`\\`,`/`)}async function b(){let{FlowRegistryManager:e,FlowStateMachine:t}=await import(`../../../flows/dist/index.js`);return{registry:new e(g),stateMachine:new t(_)}}let x=e(`flow_list`);s.registerTool(`flow_list`,{title:x.title,description:`List all installed flows and their steps`,annotations:x.annotations,inputSchema:{}},async()=>{try{let{registry:e,stateMachine:t}=await b(),n=e.list(),r=t.getStatus(),i={flows:n.map(e=>({name:e.name,version:e.version,source:e.source,sourceType:e.sourceType,format:e.format,steps:e.manifest.steps.map(e=>e.id)})),activeFlow:r.success&&r.data?{flow:r.data.flow,status:r.data.status,currentStep:r.data.currentStep}:null};return d(JSON.stringify(i,null,2))}catch(e){return u.error(`flow_list failed`,c(e)),d(`Error: ${f(e)}`)}});let S=e(`flow_info`);s.registerTool(`flow_info`,{title:S.title,description:`Show detailed information about a specific flow`,annotations:S.annotations,inputSchema:{name:a.string().describe(`Flow name to get info for`)}},async({name:e})=>{try{let{registry:t}=await b(),n=t.get(e);if(!n)return d(`Flow "${e}" not found. Use flow_list to see available flows.`);let r={name:n.name,version:n.version,description:n.manifest.description,source:n.source,sourceType:n.sourceType,format:n.format,installPath:y(n),registeredAt:n.registeredAt,updatedAt:n.updatedAt,steps:n.manifest.steps.map(e=>({id:e.id,name:e.name,instruction:v(n,e.instruction),produces:e.produces,requires:e.requires,description:e.description})),agents:n.manifest.agents,artifactsDir:n.manifest.artifacts_dir,install:n.manifest.install};return d(JSON.stringify(r,null,2))}catch(e){return u.error(`flow_info failed`,c(e)),d(`Error: ${f(e)}`)}});let C=e(`flow_start`);s.registerTool(`flow_start`,{title:C.title,description:`Start a flow. Sets the active flow and positions at the first step.`,annotations:C.annotations,inputSchema:{flow:a.string().describe(`Flow name to start (use flow_list to see options)`)}},async({flow:e})=>{try{let{registry:t,stateMachine:n}=await b(),r=t.get(e);if(!r)return d(`Flow "${e}" not found. Use flow_list to see available flows.`);let i=n.start(r.name,r.manifest);if(!i.success||!i.data)return d(`Cannot start: ${i.error}`);let a=i.data,o=r.manifest.steps.find(e=>e.id===a.currentStep),s={started:!0,flow:a.flow,currentStep:a.currentStep,currentStepInstruction:r&&o?v(r,o.instruction):null,currentStepDescription:o?.description??null,totalSteps:r.manifest.steps.length,stepSequence:r.manifest.steps.map(e=>e.id),artifactsDir:r.manifest.artifacts_dir};return d(JSON.stringify(s,null,2))}catch(e){return u.error(`flow_start failed`,c(e)),d(`Error: ${f(e)}`)}});let w=e(`flow_step`);s.registerTool(`flow_step`,{title:w.title,description:`Advance the active flow: complete current step and move to next, skip current step, or redo current step.`,annotations:w.annotations,inputSchema:{action:a.enum([`next`,`skip`,`redo`]).describe(`next: mark current step done and advance. skip: skip current step. redo: repeat current step.`)}},async({action:e})=>{try{let{registry:t,stateMachine:n}=await b(),r=n.load();if(!r)return d(`No active flow. Use flow_start first.`);let i=t.get(r.flow);if(!i)return d(`Flow "${r.flow}" not found in registry.`);let a=n.step(e,i.manifest);if(!a.success||!a.data)return d(`Cannot ${e}: ${a.error}`);let o=a.data,s=o.currentStep?i.manifest.steps.find(e=>e.id===o.currentStep):null,c={flow:o.flow,status:o.status,action:e,currentStep:o.currentStep,currentStepInstruction:i&&s?v(i,s.instruction):null,currentStepDescription:s?.description??null,completedSteps:o.completedSteps,skippedSteps:o.skippedSteps,totalSteps:i.manifest.steps.length,remaining:i.manifest.steps.filter(e=>!o.completedSteps.includes(e.id)&&!o.skippedSteps.includes(e.id)&&e.id!==o.currentStep).map(e=>e.id)};return d(JSON.stringify(c,null,2))}catch(e){return u.error(`flow_step failed`,c(e)),d(`Error: ${f(e)}`)}});let T=e(`flow_status`);s.registerTool(`flow_status`,{title:T.title,description:`Show the current flow execution state — which flow is active, current step, completed steps, and artifacts.`,annotations:T.annotations,inputSchema:{}},async()=>{try{let{registry:e,stateMachine:t}=await b(),n=t.getStatus();if(!n.success||!n.data)return d(`No active flow. Use flow_start to begin one, or flow_list to see available flows.`);let r=n.data,i=e.get(r.flow),a=i?.manifest.steps.find(e=>e.id===r.currentStep),o=i&&a?v(i,a.instruction):null,s={flow:r.flow,status:r.status,currentStep:r.currentStep,currentStepInstruction:o,instructionPath:o,currentStepDescription:a?.description??null,completedSteps:r.completedSteps,skippedSteps:r.skippedSteps,artifacts:r.artifacts,startedAt:r.startedAt,updatedAt:r.updatedAt,totalSteps:i?.manifest.steps.length??0,progress:i?`${r.completedSteps.length+r.skippedSteps.length}/${i.manifest.steps.length}`:`unknown`};return d(JSON.stringify(s,null,2))}catch(e){return u.error(`flow_status failed`,c(e)),d(`Error: ${f(e)}`)}});let E=e(`flow_read_instruction`);s.registerTool(`flow_read_instruction`,{title:E.title===`flow_read_instruction`?`Flow Read Instruction`:E.title,description:`Read the instruction content for a flow step. If step is omitted, reads the current step.`,annotations:E.title===`flow_read_instruction`?{readOnlyHint:!0,idempotentHint:!0}:E.annotations,inputSchema:{step:a.string().optional().describe(`Step id or name to read. Defaults to the current step.`)}},async({step:e})=>{try{let{registry:t,stateMachine:n}=await b(),r=n.getStatus();if(!r.success||!r.data)return d(`No active flow. Use flow_start to begin one, or flow_list to see available flows.`);let i=r.data,a=t.get(i.flow);if(!a)return d(`Flow "${i.flow}" not found in registry.`);let s=e??i.currentStep;if(!s)return d(`No current step is available for the active flow.`);let c=a.manifest.steps.find(e=>e.id===s||e.name===s);return d(c?await o(v(a,c.instruction),`utf-8`):`Step "${s}" not found in flow "${i.flow}".`)}catch(e){return u.error(`flow_read_instruction failed`,c(e)),e instanceof Error&&`code`in e&&e.code===`ENOENT`?d(`Could not read instruction file: ${e.message}`):d(`Error: ${f(e)}`)}});let D=e(`flow_reset`);s.registerTool(`flow_reset`,{title:D.title,description:`Reset the active flow, clearing all state. Use to start over or switch to a different flow.`,annotations:D.annotations,inputSchema:{}},async()=>{try{let{stateMachine:e}=await b(),t=e.reset();return t.success?d(`Flow state reset. Use flow_start to begin a new flow.`):d(`Reset failed: ${t.error}`)}catch(e){return u.error(`flow_reset failed`,c(e)),d(`Error: ${f(e)}`)}})}export{p as registerFlowTools};
1
+ import{getToolMeta as e}from"../tool-metadata.js";import{existsSync as t}from"node:fs";import{join as n,resolve as r}from"node:path";import{z as i}from"zod";import{readFile as a}from"node:fs/promises";import{createLogger as o,getGlobalDataDir as s,serializeError as c}from"../../../core/dist/index.js";import{homedir as l}from"node:os";const u=o(`flow-tools`);function d(e){return{content:[{type:`text`,text:e}]}}function f(e){return e instanceof Error?e.message:String(e)}function p(o,p){function m(){return p.sources?.[0]?.path??process.cwd()}function h(){return n(s(),`flows`,`registry.json`)}function g(){return n(p.stateDir??n(m(),`.aikit-state`),`flows`,`state.json`)}function _(e,n){let i=r(l(),`.copilot`,`flows`,e).replaceAll(`\\`,`/`);if(t(i))return i;let a=r(l(),`.claude`,`flows`,e).replaceAll(`\\`,`/`);return t(a)?a:n?.installPath?n.installPath.replaceAll(`\\`,`/`):null}function v(e,t){let n=_(e.name,e);return n?r(n,t).replaceAll(`\\`,`/`):t}async function y(){let{FlowRegistryManager:e,FlowStateMachine:t}=await import(`../../../flows/dist/index.js`);return{registry:new e(h()),stateMachine:new t(g())}}let b=e(`flow_list`);o.registerTool(`flow_list`,{title:b.title,description:`List all installed flows and their steps`,annotations:b.annotations,inputSchema:{}},async()=>{try{let{registry:e,stateMachine:t}=await y(),n=e.list(),r=t.getStatus(),i={flows:n.map(e=>({name:e.name,version:e.version,source:e.source,sourceType:e.sourceType,format:e.format,steps:e.manifest.steps.map(e=>e.id)})),activeFlow:r.success&&r.data?{flow:r.data.flow,status:r.data.status,currentStep:r.data.currentStep}:null};return d(JSON.stringify(i,null,2))}catch(e){return u.error(`flow_list failed`,c(e)),d(`Error: ${f(e)}`)}});let x=e(`flow_info`);o.registerTool(`flow_info`,{title:x.title,description:`Show detailed information about a specific flow`,annotations:x.annotations,inputSchema:{name:i.string().describe(`Flow name to get info for`)}},async({name:e})=>{try{let{registry:t}=await y(),n=t.get(e);if(!n)return d(`Flow "${e}" not found. Use flow_list to see available flows.`);let r={name:n.name,version:n.version,description:n.manifest.description,source:n.source,sourceType:n.sourceType,format:n.format,installPath:_(n.name,n),registeredAt:n.registeredAt,updatedAt:n.updatedAt,steps:n.manifest.steps.map(e=>({id:e.id,name:e.name,instruction:v(n,e.instruction),produces:e.produces,requires:e.requires,description:e.description})),agents:n.manifest.agents,artifactsDir:n.manifest.artifacts_dir,install:n.manifest.install};return d(JSON.stringify(r,null,2))}catch(e){return u.error(`flow_info failed`,c(e)),d(`Error: ${f(e)}`)}});let S=e(`flow_start`);o.registerTool(`flow_start`,{title:S.title,description:`Start a flow. Sets the active flow and positions at the first step.`,annotations:S.annotations,inputSchema:{flow:i.string().describe(`Flow name to start (use flow_list to see options)`)}},async({flow:e})=>{try{let{registry:t,stateMachine:n}=await y(),r=t.get(e);if(!r)return d(`Flow "${e}" not found. Use flow_list to see available flows.`);let i=n.start(r.name,r.manifest);if(!i.success||!i.data)return d(`Cannot start: ${i.error}`);let a=i.data,o=r.manifest.steps.find(e=>e.id===a.currentStep),s={started:!0,flow:a.flow,currentStep:a.currentStep,currentStepInstruction:r&&o?v(r,o.instruction):null,currentStepDescription:o?.description??null,totalSteps:r.manifest.steps.length,stepSequence:r.manifest.steps.map(e=>e.id),artifactsDir:r.manifest.artifacts_dir};return d(JSON.stringify(s,null,2))}catch(e){return u.error(`flow_start failed`,c(e)),d(`Error: ${f(e)}`)}});let C=e(`flow_step`);o.registerTool(`flow_step`,{title:C.title,description:`Advance the active flow: complete current step and move to next, skip current step, or redo current step.`,annotations:C.annotations,inputSchema:{action:i.enum([`next`,`skip`,`redo`]).describe(`next: mark current step done and advance. skip: skip current step. redo: repeat current step.`)}},async({action:e})=>{try{let{registry:t,stateMachine:n}=await y(),r=n.load();if(!r)return d(`No active flow. Use flow_start first.`);let i=t.get(r.flow);if(!i)return d(`Flow "${r.flow}" not found in registry.`);let a=n.step(e,i.manifest);if(!a.success||!a.data)return d(`Cannot ${e}: ${a.error}`);let o=a.data,s=o.currentStep?i.manifest.steps.find(e=>e.id===o.currentStep):null,c={flow:o.flow,status:o.status,action:e,currentStep:o.currentStep,currentStepInstruction:i&&s?v(i,s.instruction):null,currentStepDescription:s?.description??null,completedSteps:o.completedSteps,skippedSteps:o.skippedSteps,totalSteps:i.manifest.steps.length,remaining:i.manifest.steps.filter(e=>!o.completedSteps.includes(e.id)&&!o.skippedSteps.includes(e.id)&&e.id!==o.currentStep).map(e=>e.id)};return d(JSON.stringify(c,null,2))}catch(e){return u.error(`flow_step failed`,c(e)),d(`Error: ${f(e)}`)}});let w=e(`flow_status`);o.registerTool(`flow_status`,{title:w.title,description:`Show the current flow execution state — which flow is active, current step, completed steps, and artifacts.`,annotations:w.annotations,inputSchema:{}},async()=>{try{let{registry:e,stateMachine:t}=await y(),n=t.getStatus();if(!n.success||!n.data)return d(`No active flow. Use flow_start to begin one, or flow_list to see available flows.`);let r=n.data,i=e.get(r.flow),a=i?.manifest.steps.find(e=>e.id===r.currentStep),o=i&&a?v(i,a.instruction):null,s={flow:r.flow,status:r.status,currentStep:r.currentStep,currentStepInstruction:o,instructionPath:o,currentStepDescription:a?.description??null,completedSteps:r.completedSteps,skippedSteps:r.skippedSteps,artifacts:r.artifacts,startedAt:r.startedAt,updatedAt:r.updatedAt,totalSteps:i?.manifest.steps.length??0,progress:i?`${r.completedSteps.length+r.skippedSteps.length}/${i.manifest.steps.length}`:`unknown`};return d(JSON.stringify(s,null,2))}catch(e){return u.error(`flow_status failed`,c(e)),d(`Error: ${f(e)}`)}});let T=e(`flow_read_instruction`);o.registerTool(`flow_read_instruction`,{title:T.title===`flow_read_instruction`?`Flow Read Instruction`:T.title,description:`Read the instruction content for a flow step. If step is omitted, reads the current step.`,annotations:T.title===`flow_read_instruction`?{readOnlyHint:!0,idempotentHint:!0}:T.annotations,inputSchema:{step:i.string().optional().describe(`Step id or name to read. Defaults to the current step.`)}},async({step:e})=>{try{let{registry:t,stateMachine:n}=await y(),r=n.getStatus();if(!r.success||!r.data)return d(`No active flow. Use flow_start to begin one, or flow_list to see available flows.`);let i=r.data,o=t.get(i.flow);if(!o)return d(`Flow "${i.flow}" not found in registry.`);let s=e??i.currentStep;if(!s)return d(`No current step is available for the active flow.`);let c=o.manifest.steps.find(e=>e.id===s||e.name===s);return d(c?await a(v(o,c.instruction),`utf-8`):`Step "${s}" not found in flow "${i.flow}".`)}catch(e){return u.error(`flow_read_instruction failed`,c(e)),e instanceof Error&&`code`in e&&e.code===`ENOENT`?d(`Could not read instruction file: ${e.message}`):d(`Error: ${f(e)}`)}});let E=e(`flow_reset`);o.registerTool(`flow_reset`,{title:E.title,description:`Reset the active flow, clearing all state. Use to start over or switch to a different flow.`,annotations:E.annotations,inputSchema:{}},async()=>{try{let{stateMachine:e}=await y(),t=e.reset();return t.success?d(`Flow state reset. Use flow_start to begin a new flow.`):d(`Reset failed: ${t.error}`)}catch(e){return u.error(`flow_reset failed`,c(e)),d(`Error: ${f(e)}`)}})}export{p as registerFlowTools};