novacode 0.11.0 → 0.11.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/main.mjs CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
- import{parseArgs as e}from"node:util";import t from"chalk";import{ToolLoopAgent as n,stepCountIs as r,tool as i}from"ai";import{createAnthropic as a}from"@ai-sdk/anthropic";import{createGoogleGenerativeAI as o}from"@ai-sdk/google";import{createOpenAI as s}from"@ai-sdk/openai";import c,{homedir as l}from"node:os";import{chmod as u,mkdir as d,readFile as f,readdir as p,stat as m,writeFile as h}from"node:fs/promises";import{basename as g,dirname as _,extname as v,isAbsolute as y,join as b,relative as x,resolve as S,sep as ee}from"node:path";import{DatabaseSync as C}from"node:sqlite";import{mkdirSync as te}from"node:fs";import{Box as w,Text as T,render as ne,useInput as E}from"ink";import{useMemo as re,useState as D}from"react";import{jsx as O,jsxs as k}from"react/jsx-runtime";import{z as A}from"zod";import{spawn as j}from"node:child_process";import{glob as ie}from"glob";import{fileURLToPath as ae}from"node:url";import oe from"semver";const M={glm:`glm`,gemini:`gemini`,deepseek:`deepseek`,openai:`openai`,anthropic:`anthropic`},N=[{id:M.glm,name:`GLM (Z.AI)`,envKey:`GLM_API_KEY`,models:[{id:`glm-5.2`,contextWindow:1e6,reasoning:!0,default:!0},{id:`glm-5.1`,contextWindow:204800,reasoning:!0},{id:`glm-5-turbo`,contextWindow:202800,reasoning:!0},{id:`glm-5`,contextWindow:202800,reasoning:!0},{id:`glm-4.7`,contextWindow:204800,reasoning:!0},{id:`glm-4.6`,contextWindow:204800,reasoning:!0}]},{id:M.gemini,name:`Gemini (Google)`,envKey:`GEMINI_API_KEY`,models:[{id:`gemini-3.5-flash`,contextWindow:1e6,reasoning:!0,default:!0},{id:`gemini-3.1-pro-preview`,contextWindow:1e6,reasoning:!0},{id:`gemini-3.1-flash-lite`,contextWindow:1e6,reasoning:!0},{id:`gemini-2.5-pro`,contextWindow:1e6,reasoning:!1},{id:`gemini-2.5-flash`,contextWindow:1e6,reasoning:!1},{id:`gemini-2.5-flash-lite`,contextWindow:1e6,reasoning:!1}]},{id:M.deepseek,name:`DeepSeek`,envKey:`DEEPSEEK_API_KEY`,models:[{id:`deepseek-v4-flash`,contextWindow:1e6,reasoning:!0,default:!0},{id:`deepseek-v4-pro`,contextWindow:1e6,reasoning:!0}]},{id:M.openai,name:`OpenAI`,envKey:`OPENAI_API_KEY`,models:[{id:`gpt-5.5`,contextWindow:1e6,reasoning:!0,default:!0},{id:`gpt-5.5-pro`,contextWindow:1e6,reasoning:!0},{id:`gpt-5.4`,contextWindow:1e6,reasoning:!0},{id:`gpt-5.4-pro`,contextWindow:1e6,reasoning:!0},{id:`gpt-5.4-mini`,contextWindow:4e5,reasoning:!0},{id:`gpt-5.4-nano`,contextWindow:4e5,reasoning:!0},{id:`gpt-5.3-codex`,contextWindow:4e5,reasoning:!0},{id:`gpt-5.2`,contextWindow:4e5,reasoning:!0},{id:`gpt-5.2-pro`,contextWindow:4e5,reasoning:!0},{id:`gpt-5.2-codex`,contextWindow:4e5,reasoning:!0},{id:`gpt-5.1-codex`,contextWindow:4e5,reasoning:!0},{id:`gpt-5.1-codex-max`,contextWindow:4e5,reasoning:!0},{id:`gpt-5.1-codex-mini`,contextWindow:4e5,reasoning:!0},{id:`gpt-5-codex`,contextWindow:4e5,reasoning:!0},{id:`gpt-5`,contextWindow:4e5,reasoning:!0},{id:`gpt-5-mini`,contextWindow:4e5,reasoning:!0},{id:`gpt-5-nano`,contextWindow:4e5,reasoning:!0}]},{id:M.anthropic,name:`Anthropic`,envKey:`ANTHROPIC_API_KEY`,models:[{id:`claude-fable-5`,contextWindow:1e6,reasoning:!0},{id:`claude-opus-4-8`,contextWindow:1e6,reasoning:!0,default:!0},{id:`claude-opus-4-7`,contextWindow:1e6,reasoning:!0},{id:`claude-sonnet-4-6`,contextWindow:1e6,reasoning:!0},{id:`claude-opus-4-6`,contextWindow:1e6,reasoning:!0},{id:`claude-haiku-4-5`,contextWindow:2e5,reasoning:!1},{id:`claude-sonnet-4-5`,contextWindow:1e6,reasoning:!1},{id:`claude-opus-4-5`,contextWindow:2e5,reasoning:!0},{id:`claude-opus-4-1`,contextWindow:2e5,reasoning:!1}]}],se={[M.glm]:`https://api.z.ai/api/coding/paas/v4`,[M.deepseek]:`https://api.deepseek.com`};function ce(e,t,n){switch(e){case M.anthropic:return a({apiKey:n})(t);case M.gemini:return o({apiKey:n})(t);case M.openai:return s({apiKey:n})(t);case M.glm:case M.deepseek:return s({apiKey:n,baseURL:se[e],name:e}).chat(t);default:throw Error(`Unknown provider: ${e}`)}}function le(e){switch(e){case M.anthropic:return{anthropic:{effort:`high`}};case M.gemini:return{google:{thinkingConfig:{thinkingLevel:`high`}}};case M.openai:case M.glm:case M.deepseek:return{openai:{reasoningEffort:`high`}};default:return{}}}function ue(e){return{type:`text`,text:e}}function de(e){return e.type===`text`?e.text:``}function P(e){return e.isError?{type:`error-text`,value:e.content.map(de).join(`
2
+ import{parseArgs as e}from"node:util";import t from"chalk";import{ToolLoopAgent as n,stepCountIs as r,tool as i}from"ai";import{createAnthropic as a}from"@ai-sdk/anthropic";import{createGoogleGenerativeAI as o}from"@ai-sdk/google";import{createOpenAI as s}from"@ai-sdk/openai";import c,{homedir as l}from"node:os";import{chmod as u,mkdir as d,readFile as f,readdir as p,stat as m,writeFile as h}from"node:fs/promises";import{basename as g,dirname as _,extname as v,isAbsolute as y,join as b,relative as x,resolve as S,sep as ee}from"node:path";import{DatabaseSync as C}from"node:sqlite";import{mkdirSync as te}from"node:fs";import{Box as w,Text as T,render as ne,useInput as E}from"ink";import{useMemo as re,useState as D}from"react";import{jsx as O,jsxs as k}from"react/jsx-runtime";import{z as A}from"zod";import{spawn as j}from"node:child_process";import{glob as ie}from"glob";import{fileURLToPath as ae}from"node:url";import oe from"semver";const M={glm:`glm`,gemini:`gemini`,deepseek:`deepseek`,openai:`openai`,anthropic:`anthropic`},N=[{id:M.glm,name:`GLM (Z.AI)`,envKey:`GLM_API_KEY`,models:[{id:`glm-5.2`,contextWindow:1e6,reasoning:!0,default:!0},{id:`glm-5.1`,contextWindow:204800,reasoning:!0},{id:`glm-5-turbo`,contextWindow:202800,reasoning:!0},{id:`glm-5`,contextWindow:202800,reasoning:!0},{id:`glm-4.7`,contextWindow:204800,reasoning:!0},{id:`glm-4.6`,contextWindow:204800,reasoning:!0}]},{id:M.gemini,name:`Gemini (Google)`,envKey:`GEMINI_API_KEY`,models:[{id:`gemini-3.5-flash`,contextWindow:1e6,reasoning:!0,default:!0},{id:`gemini-3.1-pro-preview`,contextWindow:1e6,reasoning:!0},{id:`gemini-3.1-flash-lite`,contextWindow:1e6,reasoning:!0},{id:`gemini-2.5-pro`,contextWindow:1e6,reasoning:!1},{id:`gemini-2.5-flash`,contextWindow:1e6,reasoning:!1},{id:`gemini-2.5-flash-lite`,contextWindow:1e6,reasoning:!1}]},{id:M.deepseek,name:`DeepSeek`,envKey:`DEEPSEEK_API_KEY`,models:[{id:`deepseek-v4-flash`,contextWindow:1e6,reasoning:!0,default:!0},{id:`deepseek-v4-pro`,contextWindow:1e6,reasoning:!0}]},{id:M.openai,name:`OpenAI`,envKey:`OPENAI_API_KEY`,models:[{id:`gpt-5.5`,contextWindow:1e6,reasoning:!0,default:!0},{id:`gpt-5.5-pro`,contextWindow:1e6,reasoning:!0},{id:`gpt-5.4`,contextWindow:1e6,reasoning:!0},{id:`gpt-5.4-pro`,contextWindow:1e6,reasoning:!0},{id:`gpt-5.4-mini`,contextWindow:4e5,reasoning:!0},{id:`gpt-5.4-nano`,contextWindow:4e5,reasoning:!0},{id:`gpt-5.3-codex`,contextWindow:4e5,reasoning:!0},{id:`gpt-5.2`,contextWindow:4e5,reasoning:!0},{id:`gpt-5.2-pro`,contextWindow:4e5,reasoning:!0},{id:`gpt-5.2-codex`,contextWindow:4e5,reasoning:!0},{id:`gpt-5.1-codex`,contextWindow:4e5,reasoning:!0},{id:`gpt-5.1-codex-max`,contextWindow:4e5,reasoning:!0},{id:`gpt-5.1-codex-mini`,contextWindow:4e5,reasoning:!0},{id:`gpt-5-codex`,contextWindow:4e5,reasoning:!0},{id:`gpt-5`,contextWindow:4e5,reasoning:!0},{id:`gpt-5-mini`,contextWindow:4e5,reasoning:!0},{id:`gpt-5-nano`,contextWindow:4e5,reasoning:!0}]},{id:M.anthropic,name:`Anthropic`,envKey:`ANTHROPIC_API_KEY`,models:[{id:`claude-fable-5`,contextWindow:1e6,reasoning:!0},{id:`claude-opus-4-8`,contextWindow:1e6,reasoning:!0,default:!0},{id:`claude-opus-4-7`,contextWindow:1e6,reasoning:!0},{id:`claude-sonnet-4-6`,contextWindow:1e6,reasoning:!0},{id:`claude-opus-4-6`,contextWindow:1e6,reasoning:!0},{id:`claude-haiku-4-5`,contextWindow:2e5,reasoning:!1},{id:`claude-sonnet-4-5`,contextWindow:1e6,reasoning:!1},{id:`claude-opus-4-5`,contextWindow:2e5,reasoning:!0},{id:`claude-opus-4-1`,contextWindow:2e5,reasoning:!1}]}],se={[M.glm]:`https://api.z.ai/api/coding/paas/v4`,[M.deepseek]:`https://api.deepseek.com`};function ce(e,t,n){switch(e){case M.anthropic:return a({apiKey:n})(t);case M.gemini:return o({apiKey:n})(t);case M.openai:return s({apiKey:n})(t);case M.glm:case M.deepseek:return s({apiKey:n,baseURL:se[e],name:e}).chat(t);default:throw Error(`Unknown provider: ${e}`)}}function le(e){switch(e){case M.anthropic:return{anthropic:{effort:`high`}};case M.gemini:return{google:{thinkingConfig:{thinkingLevel:`high`}}};case M.openai:case M.glm:case M.deepseek:return{openai:{reasoningEffort:`high`}};default:return{}}}function P(e){if(typeof e==`string`)return Math.ceil(e.length/4);let t=0;for(let n of e){let e=n.content;if(typeof e==`string`){t+=e.length;continue}for(let n of e)n.type===`text`?t+=n.text.length:n.type===`tool-call`?t+=JSON.stringify(n.input).length:n.type===`reasoning`&&(t+=n.text.length)}return Math.ceil(t/4)}function ue(e){return{type:`text`,text:e}}function de(e){return e.type===`text`?e.text:``}function F(e){return e.isError?{type:`error-text`,value:e.content.map(de).join(`
3
3
  `)}:e.content.some(e=>e.type===`image`)?{type:`content`,value:e.content.map(e=>e.type===`image`?{type:`media`,data:e.data,mediaType:e.mime}:{type:`text`,text:e.text})}:{type:`text`,value:e.content.map(de).join(`
4
4
  `)}}function fe(e){switch(e.type){case`text`:return{text:e.value,isError:!1};case`error-text`:return{text:e.value,isError:!0};case`error-json`:return{text:JSON.stringify(e.value),isError:!0};case`execution-denied`:return{text:e.reason??`execution denied`,isError:!0};case`json`:return{text:JSON.stringify(e.value),isError:!1};case`content`:return{text:e.value.map(e=>e.type===`text`?e.text:e.type===`media`?`[image]`:``).join(`
5
- `),isError:!1};default:return{text:``,isError:!1}}}function pe(e,t){if(!t)return e;let n={};for(let[r,i]of Object.entries(e)){let e=i.execute;if(!e){n[r]=i;continue}n[r]={...i,execute:async(n,i)=>{let a=await t.check({name:r,args:n});return a.allow?e(n,i):{content:[ue(a.reason??`Blocked`)],isError:!0}}}}return n}var me=class{#e;#t;#n;#r=[];#i;#a;#o;constructor(e){this.#e=e.provider,this.#t=e.model,this.#a=e.apiKey,this.#n=e.system,this.#i=e.tools,this.#r=e.messages??[],this.#o=e.policy??null}get model(){return this.#t}get messages(){return this.#r}get tools(){return this.#i}get apiKey(){return this.#a}get policy(){return this.#o}updateConfig(e){this.#e=e.provider,this.#t=e.model,this.#a=e.apiKey}setTools(e){this.#i=e}setMessages(e){this.#r=e}appendMessages(e){this.#r=[...this.#r,...e]}setModel(e){this.#t=e}async prompt(e,t){return new n({model:ce(this.#e,this.#t.id,this.#a),instructions:this.#n,tools:pe(this.#i,this.#o),stopWhen:r(50),providerOptions:this.#t.reasoning?le(this.#e):void 0}).stream({messages:this.#r,abortSignal:e,onStepFinish:t})}};function he(e,t,n=[],r){let i=Object.entries(t).map(([e,t])=>`- ${e}: ${t.description}`).join(`
5
+ `),isError:!1};default:return{text:``,isError:!1}}}function pe(e,t){if(!t)return e;let n={};for(let[r,i]of Object.entries(e)){let e=i.execute;if(!e){n[r]=i;continue}n[r]={...i,execute:async(n,i)=>{let a=await t.check({name:r,args:n});return a.allow?e(n,i):{content:[ue(a.reason??`Blocked`)],isError:!0}}}}return n}function me(e,t,n=[],r){let i=Object.entries(t).map(([e,t])=>`- ${e}: ${t.description}`).join(`
6
6
  `),a=c.platform(),o=c.arch();return`You are Nova, an expert coding assistant. Help users with coding tasks using the tools available.
7
7
 
8
8
  Format your responses with clean, standard markdown. Use headers (##, ###), bold text (**bold**), inline code (\`code\`), and code blocks (\`\`\`lang) to make your output clear and readable in the terminal.
@@ -52,8 +52,8 @@ ${n.length>0?n.map(e=>`- ${e.name}: ${e.description} (path: ${e.path}/SKILL.md)`
52
52
 
53
53
  **IMPORTANT:** Before responding to a task that matches any skill above, you MUST first read the skill's SKILL.md file using the read tool with the full absolute path, then follow its instructions exactly. Do not skip this step.
54
54
 
55
- ${r?`\n<project_context>\nProject-specific instructions and guidelines:\n\n<project_instructions path="AGENTS.md">\n${r}\n</project_instructions>\n</project_context>`:``}`}const ge=/^[a-z0-9]+(-[a-z0-9]+)*$/;function _e(e){return e.length>64?{valid:!1,warning:`Skill name exceeds 64 characters: "${e}"`}:ge.test(e)?{valid:!0}:{valid:!1,warning:`Skill name contains invalid characters (use lowercase, numbers, hyphens): "${e}"`}}function ve(e){let t=e.match(/^---\s*\n([\s\S]*?)\n---/);if(!t)return null;let n=t[1],r,i;for(let e of n.split(`
56
- `)){let t=e.match(/^name:\s*(.+)$/);t&&(r=t[1].trim());let n=e.match(/^description:\s*(.+)$/);n&&(i=n[1].trim())}return r?{name:r,description:i}:null}async function ye(e,t){let n=b(e,`SKILL.md`);try{let{readFile:r}=await import(`node:fs/promises`),i=ve(await r(n,`utf-8`));return i?.name?i.description?{name:i.name,description:i.description,path:e,source:t}:(console.warn(`Skill missing description, skipping: ${e}`),null):null}catch{return null}}async function be(e,t){let n=[];try{let r=await p(e,{withFileTypes:!0});for(let i of r){if(!i.isDirectory())continue;let r=await ye(b(e,i.name),t);r&&n.push(r)}}catch{}return n}async function xe(e){let t=[{dir:S(e,`.novacode`,`skills`),source:`project`},{dir:S(e,`.agents`,`skills`),source:`project`},{dir:b(l(),`.novacode`,`skills`),source:`global`},{dir:b(l(),`.agents`,`skills`),source:`global`}],n=[];for(let{dir:e,source:r}of t)n.push(...await be(e,r));let r=[];for(let e of n){let t=_e(e.name);t.valid||console.warn(t.warning),e.description.length>1024&&console.warn(`Skill description exceeds 1024 characters: "${e.name}"`),r.push({name:e.name,description:e.description,path:e.path,source:e.source})}return r}function Se(e){return(e.source===`project`?0:2)+ +!e.path.includes(`.novacode/skills`)}function Ce(e){let t=new Map;for(let n of e){let e=t.get(n.name);e?e.push(n):t.set(n.name,[n])}return[...t.values()].map(e=>e.sort((e,t)=>Se(e)-Se(t)))}function we(e){return Ce(e).map(e=>e[0])}async function Te(e){let[t,n]=await Promise.all([xe(e),Ee(e)]);return{skills:t,agentsMd:n}}async function Ee(e){try{return await f(b(e,`AGENTS.md`),`utf-8`)}catch{return null}}function F(e,t){return t===e||t.startsWith(`${e}/`)?x(e,t)||`.`:t}function De(e){if(typeof e!=`string`)return e;let t=e,n=``;if(e.startsWith(`file://`)&&(t=e.slice(7),n=`file://`),y(t)){let e=process.cwd();return n+F(e,t)}return e}function Oe(e){let t=process.cwd();if(e===t||e.startsWith(`${t}/`))return x(t,e)||`.`;let n=l();return e===n||e.startsWith(`${n}/`)?`~${e.slice(n.length)}`:e}function ke(e,n=!1){return e?Object.entries(e).map(([e,r])=>{let i=typeof r==`string`?De(r):JSON.stringify(r),a=i.length>40?`${i.slice(0,40)}…`:i;return`${n?t.dim(`${e}:`):`${e}:`} ${a}`}).join(` `):``}function Ae(e){let t=Date.now()-e,n=Math.floor(t/1e3),r=Math.floor(n/60),i=Math.floor(r/60);return n<60?`just now`:r<60?`${r}m ago`:i<24?`${i}h ago`:new Date(e).toLocaleDateString()}function je(e){return e===0?`-`:e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}async function Me(e,t,n={}){let[r,i]=t;if(r===`list`||r===`ls`){let t=n.limit??10,r=await e.list(t);if(r.length===0){console.log(`No sessions found.`);return}console.log(`ID`.padEnd(25),`TITLE / UPDATED`.padEnd(35),`TOKENS`),console.log(`-`.repeat(75));for(let e of r){let t=Ae(e.updated),n=e.title?`"${e.title}" (${t})`:t,r=je(e.inputTokens+e.outputTokens);console.log(e.id.padEnd(25),n.padEnd(35),r)}return}if(r===`delete`||r===`rm`){if(n.all){await e.deleteAll(),console.log(`All sessions deleted.`);return}i||(console.error(`Usage: nova --sessions rm <id> or --sessions rm --all`),process.exit(1)),await e.delete(i)?console.log(`Deleted session: ${i}`):(console.error(`Session not found: ${i}`),process.exit(1));return}console.error(`Unknown session subcommand.`),process.exit(1)}const I=()=>b(process.env.HOME??`~`,`.novacode`),L=()=>b(I(),`config.json`),R=()=>b(I(),`auth.json`),z={provider:``,model:``},Ne={apiKeys:{}};async function Pe(){try{return await m(L()),!0}catch{return!1}}async function Fe(){try{let e=JSON.parse(await f(L(),`utf-8`));return{provider:e.provider??z.provider,model:e.model??z.model}}catch{return{...z}}}async function Ie(){try{let e=JSON.parse(await f(R(),`utf-8`));return{...Ne,...e}}catch{return{...Ne}}}async function Le(){await d(I(),{recursive:!0})}async function Re(e){await Le(),await h(L(),JSON.stringify(e,null,2))}async function ze(e){await Le(),await h(R(),JSON.stringify(e,null,2));try{await u(R(),384)}catch{}}function Be(){return I()}let B=null;function Ve(e){if(B)return B;let t=e??b(process.env.HOME??`~`,`.novacode`,`state.db`);return te(b(t,`..`),{recursive:!0}),B=new C(t,{enableForeignKeyConstraints:!0}),B.exec(`PRAGMA journal_mode = WAL`),B.exec(`
55
+ ${r?`\n<project_context>\nProject-specific instructions and guidelines:\n\n<project_instructions path="AGENTS.md">\n${r}\n</project_instructions>\n</project_context>`:``}`}function he(e,t){let n=t[0];return n&&n.role===`user`&&typeof n.content==`string`&&n.content.startsWith(`[Prior context summary]`)?{instructions:`${e}\n\n${n.content}`,messages:t.slice(1)}:{instructions:e,messages:t}}function ge(e,t){if(e.length===0)return[];let n=e[0],r=!1,i=null;n&&n.role===`user`&&typeof n.content==`string`&&n.content.startsWith(`[Prior context summary]`)&&(r=!0,i=n);let a=+!!r;if(a>=e.length)return e;let o=[],s=[];for(let t=a;t<e.length;t++){let n=e[t];n&&(n.role===`user`?(s.length>0&&o.push(s),s=[n]):s.push(n))}s.length>0&&o.push(s);let c=o.length-1,l=i?P([i]):0;for(let e=o.length-1;e>=0;e--){let n=o[e];if(!n)continue;let r=P(n);if(l+r<=t)l+=r,c=e;else break}let u=[];i&&u.push(i);for(let e=c;e<o.length;e++){let t=o[e];t&&u.push(...t)}return u}var _e=class{#e;#t;#n;#r=[];#i;#a;#o;constructor(e){this.#e=e.provider,this.#t=e.model,this.#a=e.apiKey,this.#n=e.system,this.#i=e.tools,this.#r=e.messages??[],this.#o=e.policy??null}get model(){return this.#t}get messages(){return this.#r}get tools(){return this.#i}get apiKey(){return this.#a}get policy(){return this.#o}get system(){return this.#n}updateConfig(e){this.#e=e.provider,this.#t=e.model,this.#a=e.apiKey}setTools(e){this.#i=e}setMessages(e){this.#r=e}appendMessages(e){this.#r=[...this.#r,...e]}setModel(e){this.#t=e}async prompt(e,t){let i=P(this.#n),a=this.#t.contextWindow-i-4096,o=ge(this.#r,a),{instructions:s,messages:c}=he(this.#n,o);return new n({model:ce(this.#e,this.#t.id,this.#a),instructions:s,tools:pe(this.#i,this.#o),stopWhen:r(50),providerOptions:this.#t.reasoning?le(this.#e):void 0}).stream({messages:c,abortSignal:e,onStepFinish:t})}};const ve=/^[a-z0-9]+(-[a-z0-9]+)*$/;function ye(e){return e.length>64?{valid:!1,warning:`Skill name exceeds 64 characters: "${e}"`}:ve.test(e)?{valid:!0}:{valid:!1,warning:`Skill name contains invalid characters (use lowercase, numbers, hyphens): "${e}"`}}function be(e){let t=e.match(/^---\s*\n([\s\S]*?)\n---/);if(!t)return null;let n=t[1],r,i;for(let e of n.split(`
56
+ `)){let t=e.match(/^name:\s*(.+)$/);t&&(r=t[1].trim());let n=e.match(/^description:\s*(.+)$/);n&&(i=n[1].trim())}return r?{name:r,description:i}:null}async function xe(e,t){let n=b(e,`SKILL.md`);try{let{readFile:r}=await import(`node:fs/promises`),i=be(await r(n,`utf-8`));return i?.name?i.description?{name:i.name,description:i.description,path:e,source:t}:(console.warn(`Skill missing description, skipping: ${e}`),null):null}catch{return null}}async function Se(e,t){let n=[];try{let r=await p(e,{withFileTypes:!0});for(let i of r){if(!i.isDirectory())continue;let r=await xe(b(e,i.name),t);r&&n.push(r)}}catch{}return n}async function Ce(e){let t=[{dir:S(e,`.novacode`,`skills`),source:`project`},{dir:S(e,`.agents`,`skills`),source:`project`},{dir:b(l(),`.novacode`,`skills`),source:`global`},{dir:b(l(),`.agents`,`skills`),source:`global`}],n=[];for(let{dir:e,source:r}of t)n.push(...await Se(e,r));let r=[];for(let e of n){let t=ye(e.name);t.valid||console.warn(t.warning),e.description.length>1024&&console.warn(`Skill description exceeds 1024 characters: "${e.name}"`),r.push({name:e.name,description:e.description,path:e.path,source:e.source})}return r}function we(e){return(e.source===`project`?0:2)+ +!e.path.includes(`.novacode/skills`)}function Te(e){let t=new Map;for(let n of e){let e=t.get(n.name);e?e.push(n):t.set(n.name,[n])}return[...t.values()].map(e=>e.sort((e,t)=>we(e)-we(t)))}function Ee(e){return Te(e).map(e=>e[0])}async function De(e){let[t,n]=await Promise.all([Ce(e),Oe(e)]);return{skills:t,agentsMd:n}}async function Oe(e){try{return await f(b(e,`AGENTS.md`),`utf-8`)}catch{return null}}function I(e,t){return t===e||t.startsWith(`${e}/`)?x(e,t)||`.`:t}function ke(e){if(typeof e!=`string`)return e;let t=e,n=``;if(e.startsWith(`file://`)&&(t=e.slice(7),n=`file://`),y(t)){let e=process.cwd();return n+I(e,t)}return e}function Ae(e){let t=process.cwd();if(e===t||e.startsWith(`${t}/`))return x(t,e)||`.`;let n=l();return e===n||e.startsWith(`${n}/`)?`~${e.slice(n.length)}`:e}function je(e,n=!1){return e?Object.entries(e).map(([e,r])=>{let i=typeof r==`string`?ke(r):JSON.stringify(r),a=i.length>40?`${i.slice(0,40)}…`:i;return`${n?t.dim(`${e}:`):`${e}:`} ${a}`}).join(` `):``}function Me(e){let t=Date.now()-e,n=Math.floor(t/1e3),r=Math.floor(n/60),i=Math.floor(r/60);return n<60?`just now`:r<60?`${r}m ago`:i<24?`${i}h ago`:new Date(e).toLocaleDateString()}function Ne(e){return e===0?`-`:e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}async function Pe(e,t,n={}){let[r,i]=t;if(r===`list`||r===`ls`){let t=n.limit??10,r=await e.list(t);if(r.length===0){console.log(`No sessions found.`);return}console.log(`ID`.padEnd(25),`TITLE / UPDATED`.padEnd(35),`TOKENS`),console.log(`-`.repeat(75));for(let e of r){let t=Me(e.updated),n=e.title?`"${e.title}" (${t})`:t,r=Ne(e.inputTokens+e.outputTokens);console.log(e.id.padEnd(25),n.padEnd(35),r)}return}if(r===`delete`||r===`rm`){if(n.all){await e.deleteAll(),console.log(`All sessions deleted.`);return}i||(console.error(`Usage: nova --sessions rm <id> or --sessions rm --all`),process.exit(1)),await e.delete(i)?console.log(`Deleted session: ${i}`):(console.error(`Session not found: ${i}`),process.exit(1));return}console.error(`Unknown session subcommand.`),process.exit(1)}const L=()=>b(process.env.HOME??`~`,`.novacode`),R=()=>b(L(),`config.json`),z=()=>b(L(),`auth.json`),B={provider:``,model:``},Fe={apiKeys:{}};async function Ie(){try{return await m(R()),!0}catch{return!1}}async function Le(){try{let e=JSON.parse(await f(R(),`utf-8`));return{provider:e.provider??B.provider,model:e.model??B.model}}catch{return{...B}}}async function Re(){try{let e=JSON.parse(await f(z(),`utf-8`));return{...Fe,...e}}catch{return{...Fe}}}async function ze(){await d(L(),{recursive:!0})}async function Be(e){await ze(),await h(R(),JSON.stringify(e,null,2))}async function Ve(e){await ze(),await h(z(),JSON.stringify(e,null,2));try{await u(z(),384)}catch{}}function He(){return L()}let V=null;function Ue(e){if(V)return V;let t=e??b(process.env.HOME??`~`,`.novacode`,`state.db`);return te(b(t,`..`),{recursive:!0}),V=new C(t,{enableForeignKeyConstraints:!0}),V.exec(`PRAGMA journal_mode = WAL`),V.exec(`
57
57
  CREATE TABLE IF NOT EXISTS sessions (
58
58
  id TEXT PRIMARY KEY,
59
59
  cwd TEXT NOT NULL,
@@ -80,31 +80,31 @@ CREATE TABLE IF NOT EXISTS messages (
80
80
  CREATE INDEX IF NOT EXISTS idx_sessions_updated ON sessions(updated DESC);
81
81
  CREATE INDEX IF NOT EXISTS idx_sessions_parent ON sessions(parent_session_id);
82
82
  CREATE INDEX IF NOT EXISTS idx_messages_session ON messages(session_id, seq);
83
- `),B}function He(){B&&=(B.close(),null)}function Ue(){B=null}function We(){return`${Date.now().toString(36)}-${crypto.randomUUID().slice(0,8)}`}function V(e){return{id:e.id,cwd:e.cwd,model:e.model,provider:e.provider,title:e.title??null,parentSessionId:e.parent_session_id??null,endReason:e.end_reason??null,created:e.created,updated:e.updated,inputTokens:e.input_tokens??0,outputTokens:e.output_tokens??0,messageCount:e.message_count??0}}var Ge=class{#e;#t=new Map;constructor(e){e instanceof C?this.#e=e:this.#e=Ve(e)}#n(e){let t=this.#t.get(e);t&&(this.#e.prepare(`INSERT OR IGNORE INTO sessions (id, cwd, model, provider, title, parent_session_id, end_reason, created, updated, input_tokens, output_tokens, message_count)
84
- VALUES (?, ?, ?, ?, ?, ?, NULL, ?, ?, 0, 0, 0)`).run(e,t.cwd,t.model,t.provider,t.title,t.parentSessionId,t.created,t.created),this.#t.delete(e))}async create(e,t,n){let r=We(),i=Date.now();return this.#t.set(r,{cwd:e,model:t,provider:n,title:null,parentSessionId:null,created:i}),{id:r,cwd:e,model:t,provider:n,title:null,parentSessionId:null,endReason:null,created:i,updated:i,inputTokens:0,outputTokens:0,messageCount:0}}async get(e){let t=this.#e.prepare(`SELECT * FROM sessions WHERE id = ?`).get(e);if(t)return V(t);let n=this.#t.get(e);return n?{id:e,cwd:n.cwd,model:n.model,provider:n.provider,title:n.title,parentSessionId:n.parentSessionId,endReason:null,created:n.created,updated:n.created,inputTokens:0,outputTokens:0,messageCount:0}:null}async list(e=10){return this.#e.prepare(`SELECT * FROM sessions WHERE end_reason IS NULL ORDER BY updated DESC LIMIT ?`).all(e).map(V)}async latest(){let e=this.#e.prepare(`SELECT * FROM sessions WHERE end_reason IS NULL ORDER BY updated DESC LIMIT 1`).get();return e?V(e):null}async delete(e){let t=this.#t.delete(e),n=this.#e.prepare(`DELETE FROM sessions WHERE id = ?`).run(e);return t||n.changes>0}async deleteAll(){this.#t.clear(),this.#e.exec(`DELETE FROM messages; DELETE FROM sessions`)}async append(e,t){this.#n(e);let n=Date.now(),r=this.#e.prepare(`SELECT COALESCE(MAX(seq), 0) + 1 AS next_seq FROM messages WHERE session_id = ?`).get(e)?.next_seq;this.#i(e,r,t,n),this.#e.prepare(`UPDATE sessions SET message_count = message_count + 1, updated = ? WHERE id = ?`).run(n,e)}async addUsage(e,t,n){this.#n(e),this.#e.prepare(`UPDATE sessions SET input_tokens = input_tokens + ?, output_tokens = output_tokens + ?, updated = ? WHERE id = ?`).run(t,n,Date.now(),e)}async messages(e){return this.#e.prepare(`SELECT message FROM messages WHERE session_id = ? ORDER BY seq`).all(e).map(e=>JSON.parse(e.message))}async history(e){let t=this.#r(e);if(t.length<=1)return this.messages(e);let n=t.map((e,t)=>`WHEN '${e}' THEN ${t}`).join(` `);return this.#e.prepare(`SELECT message FROM messages m
83
+ `),V}function We(){V&&=(V.close(),null)}function Ge(){V=null}function Ke(){return`${Date.now().toString(36)}-${crypto.randomUUID().slice(0,8)}`}function H(e){return{id:e.id,cwd:e.cwd,model:e.model,provider:e.provider,title:e.title??null,parentSessionId:e.parent_session_id??null,endReason:e.end_reason??null,created:e.created,updated:e.updated,inputTokens:e.input_tokens??0,outputTokens:e.output_tokens??0,messageCount:e.message_count??0}}var qe=class{#e;#t=new Map;constructor(e){e instanceof C?this.#e=e:this.#e=Ue(e)}#n(e){let t=this.#t.get(e);t&&(this.#e.prepare(`INSERT OR IGNORE INTO sessions (id, cwd, model, provider, title, parent_session_id, end_reason, created, updated, input_tokens, output_tokens, message_count)
84
+ VALUES (?, ?, ?, ?, ?, ?, NULL, ?, ?, 0, 0, 0)`).run(e,t.cwd,t.model,t.provider,t.title,t.parentSessionId,t.created,t.created),this.#t.delete(e))}async create(e,t,n){let r=Ke(),i=Date.now();return this.#t.set(r,{cwd:e,model:t,provider:n,title:null,parentSessionId:null,created:i}),{id:r,cwd:e,model:t,provider:n,title:null,parentSessionId:null,endReason:null,created:i,updated:i,inputTokens:0,outputTokens:0,messageCount:0}}async get(e){let t=this.#e.prepare(`SELECT * FROM sessions WHERE id = ?`).get(e);if(t)return H(t);let n=this.#t.get(e);return n?{id:e,cwd:n.cwd,model:n.model,provider:n.provider,title:n.title,parentSessionId:n.parentSessionId,endReason:null,created:n.created,updated:n.created,inputTokens:0,outputTokens:0,messageCount:0}:null}async list(e=10){return this.#e.prepare(`SELECT * FROM sessions WHERE end_reason IS NULL ORDER BY updated DESC LIMIT ?`).all(e).map(H)}async latest(){let e=this.#e.prepare(`SELECT * FROM sessions WHERE end_reason IS NULL ORDER BY updated DESC LIMIT 1`).get();return e?H(e):null}async delete(e){let t=this.#t.delete(e),n=this.#e.prepare(`DELETE FROM sessions WHERE id = ?`).run(e);return t||n.changes>0}async deleteAll(){this.#t.clear(),this.#e.exec(`DELETE FROM messages; DELETE FROM sessions`)}async append(e,t){this.#n(e);let n=Date.now(),r=this.#e.prepare(`SELECT COALESCE(MAX(seq), 0) + 1 AS next_seq FROM messages WHERE session_id = ?`).get(e)?.next_seq;this.#i(e,r,t,n),this.#e.prepare(`UPDATE sessions SET message_count = message_count + 1, updated = ? WHERE id = ?`).run(n,e)}async addUsage(e,t,n){this.#n(e),this.#e.prepare(`UPDATE sessions SET input_tokens = input_tokens + ?, output_tokens = output_tokens + ?, updated = ? WHERE id = ?`).run(t,n,Date.now(),e)}async messages(e){return this.#e.prepare(`SELECT message FROM messages WHERE session_id = ? ORDER BY seq`).all(e).map(e=>JSON.parse(e.message))}async history(e){let t=this.#r(e);if(t.length<=1)return this.messages(e);let n=t.map((e,t)=>`WHEN '${e}' THEN ${t}`).join(` `);return this.#e.prepare(`SELECT message FROM messages m
85
85
  WHERE m.session_id IN (${t.map(()=>`?`).join(`,`)})
86
- ORDER BY CASE m.session_id ${n} END ASC, m.seq ASC`).all(...t).map(e=>JSON.parse(e.message))}async messageCount(e){return this.#e.prepare(`SELECT message_count FROM sessions WHERE id = ?`).get(e)?.message_count??0}async setTitle(e,t){this.#n(e),this.#e.prepare(`UPDATE sessions SET title = ?, updated = ? WHERE id = ?`).run(t,Date.now(),e)}async replaceMessages(e,t){t.length>0&&this.#n(e),this.#e.prepare(`DELETE FROM messages WHERE session_id = ?`).run(e);let n=Date.now(),r=0;for(let i of t)r++,this.#i(e,r,i,n);this.#e.prepare(`UPDATE sessions SET message_count = ?, updated = ? WHERE id = ?`).run(r,n,e)}async endSession(e,t){this.#n(e),this.#e.prepare(`UPDATE sessions SET end_reason = ?, updated = ? WHERE id = ?`).run(t,Date.now(),e)}async createContinuation(e,t,n,r){let i=We(),a=Date.now();return this.#t.set(i,{cwd:t,model:n,provider:r,title:null,parentSessionId:e,created:a}),{id:i,cwd:t,model:n,provider:r,title:null,parentSessionId:e,endReason:null,created:a,updated:a,inputTokens:0,outputTokens:0,messageCount:0}}#r(e){let t=[],n=e,r=new Set;for(;n&&!r.has(n);){t.push(n),r.add(n);let e=this.#e.prepare(`SELECT parent_session_id FROM sessions WHERE id = ?`).get(n);n=e?e.parent_session_id??``:this.#t.get(n)?.parentSessionId??``}return t.reverse(),t}#i(e,t,n,r){this.#e.prepare(`INSERT INTO messages (session_id, seq, message, ts) VALUES (?, ?, ?, ?)`).run(e,t,JSON.stringify(n),r)}async prune(){try{this.#e.exec(`DELETE FROM sessions WHERE message_count = 0`)}catch{}}close(){He()}};let H=null;async function Ke(e){return H||(H=new Ge(e?`${e}/state.db`:void 0),H)}function U(e){return N.find(t=>t.id===e)}function W(e){let t=U(e);return t?t.models.map(e=>({...e,provider:t.id})):[]}function G(e,t){return W(e).find(e=>e.id===t)}function qe(e){for(let t of N){let n=G(t.id,e);if(n)return n}}function Je(e){let t=W(e);return t.find(e=>e.default)??t[0]}function Ye({message:e,options:t,header:n,footer:r,onSelect:i}){let[a,o]=D(0);return E((e,n)=>{if(n.escape){i(null);return}if(n.upArrow){o(e=>(e-1+t.length)%t.length);return}if(n.downArrow){o(e=>(e+1)%t.length);return}n.return&&i(t[a]?.value??null)}),k(w,{flexDirection:`column`,paddingX:1,children:[n&&O(w,{marginBottom:1,children:O(T,{children:n})}),O(w,{marginBottom:1,children:O(T,{bold:!0,children:e})}),t.map((e,t)=>k(w,{children:[k(T,{color:t===a?`green`:void 0,children:[t===a?`❯ `:` `,e.label]}),e.hint&&t===a&&k(T,{dimColor:!0,children:[` `,e.hint]})]},e.value)),O(w,{marginTop:1,children:O(T,{dimColor:!0,children:`↑↓ navigate · Enter select · Esc cancel`})}),r&&O(w,{marginTop:1,children:O(T,{children:r})})]})}function Xe({message:e,options:t,header:n,footer:r,onSelect:i}){let[a,o]=D(``),[s,c]=D(0),l=re(()=>{let e=a.trim().toLowerCase();return e?t.filter(t=>t.label.toLowerCase().includes(e)):t},[t,a]),u=l.length===0?0:Math.min(s,l.length-1);return E((e,t)=>{if(t.escape){i(null);return}if(t.return){l.length>0&&i(l[u]?.value??null);return}if(t.upArrow){c(e=>l.length===0?0:(e-1+l.length)%l.length);return}if(t.downArrow){c(e=>l.length===0?0:(e+1)%l.length);return}if(t.backspace||t.delete){o(e=>e.slice(0,-1)),c(0);return}e&&!t.ctrl&&!t.meta&&e.trim()&&(o(t=>t+e),c(0))}),k(w,{flexDirection:`column`,paddingX:1,children:[n&&O(w,{marginBottom:1,children:O(T,{children:n})}),O(w,{marginBottom:1,children:O(T,{bold:!0,children:e})}),k(w,{marginBottom:1,children:[O(T,{color:`cyan`,children:`❯ `}),O(T,{children:a}),O(T,{color:`cyan`,children:`▏`})]}),l.length===0?O(w,{children:O(T,{dimColor:!0,children:`No matches`})}):l.map((e,t)=>k(w,{children:[k(T,{color:t===u?`green`:void 0,children:[t===u?`❯ `:` `,e.label]}),e.hint&&t===u&&k(T,{dimColor:!0,children:[` `,e.hint]})]},e.value)),O(w,{marginTop:1,children:O(T,{dimColor:!0,children:`type to filter · ↑↓ navigate · Enter select · Esc cancel`})}),r&&O(w,{marginTop:1,children:O(T,{children:r})})]})}function Ze({message:e,validate:t,onSubmit:n}){let[r,i]=D(``),[a,o]=D(``);return E((e,a)=>{if(a.escape){n(null);return}if(a.return){let e=t?.(r);if(e){o(e);return}n(r);return}if(a.backspace||a.delete){i(e=>e.slice(0,-1)),o(``);return}e&&(i(t=>t+e),o(``))}),k(w,{flexDirection:`column`,paddingX:1,children:[O(w,{marginBottom:1,children:O(T,{bold:!0,children:e})}),k(w,{children:[O(T,{color:`green`,children:`│ `}),O(T,{dimColor:!0,children:`*`.repeat(r.length)}),O(T,{color:`green`,children:`│`})]}),a&&O(w,{children:O(T,{color:`red`,children:a})}),O(w,{marginTop:1,children:O(T,{dimColor:!0,children:`Enter submit · Esc cancel`})})]})}function Qe({message:e,onConfirm:t}){let[n,r]=D(!0);return E((e,i)=>{if(i.escape){t(null);return}if(i.leftArrow||i.rightArrow||i.tab){r(e=>!e);return}i.return&&t(n)}),k(w,{flexDirection:`column`,paddingX:1,children:[O(w,{marginBottom:1,children:O(T,{bold:!0,children:e})}),O(w,{children:k(T,{color:n?`green`:void 0,children:[n?`❯ `:` `,`Yes`]})}),O(w,{children:k(T,{color:n?void 0:`red`,children:[n?` `:`❯ `,`No`]})}),O(w,{marginTop:1,children:O(T,{dimColor:!0,children:`←→ toggle · Enter confirm · Esc cancel`})})]})}const $e={safe:`cyan`,write:`magenta`,network:`yellow`,execution:`red`};function et({req:e,onResolve:t}){let[n,r]=D(!0),i=$e[e.risk];return E((e,i)=>{if(i.escape){t(null);return}if(i.upArrow||i.downArrow||i.leftArrow||i.rightArrow||i.tab){r(e=>!e);return}i.return&&t(n)}),k(w,{flexDirection:`column`,paddingX:1,children:[O(w,{marginBottom:1,children:O(T,{bold:!0,color:`yellow`,children:`⚠ Approve tool call?`})}),k(w,{marginBottom:1,children:[O(T,{bold:!0,color:i,children:e.tool}),k(T,{dimColor:!0,children:[` · `,e.risk]})]}),e.summary&&O(w,{marginBottom:1,borderStyle:`round`,borderColor:`gray`,paddingX:1,children:O(T,{wrap:`truncate-end`,children:e.summary})}),e.warning&&O(w,{marginBottom:1,children:O(T,{color:`red`,children:e.warning})}),O(w,{children:k(T,{color:n?`green`:void 0,children:[n?`❯ `:` `,`Allow once`]})}),O(w,{children:k(T,{color:n?void 0:`red`,children:[n?` `:`❯ `,`Deny`]})}),O(w,{marginTop:1,children:O(T,{dimColor:!0,children:`↑↓ toggle · Enter confirm · Esc deny`})})]})}function K(e,t,n,r){return new Promise(i=>{let{unmount:a}=ne(O(Ye,{message:e,options:t,header:n,footer:r,onSelect:e=>{a(),i(e)}}))})}function tt(e,t){return new Promise(n=>{let{unmount:r}=ne(O(Ze,{message:e,validate:t,onSubmit:e=>{r(),n(e)}}))})}async function nt(){console.log(t.bold.cyan(`
86
+ ORDER BY CASE m.session_id ${n} END ASC, m.seq ASC`).all(...t).map(e=>JSON.parse(e.message))}async messageCount(e){return this.#e.prepare(`SELECT message_count FROM sessions WHERE id = ?`).get(e)?.message_count??0}async setTitle(e,t){this.#n(e),this.#e.prepare(`UPDATE sessions SET title = ?, updated = ? WHERE id = ?`).run(t,Date.now(),e)}async endSession(e,t){this.#n(e),this.#e.prepare(`UPDATE sessions SET end_reason = ?, updated = ? WHERE id = ?`).run(t,Date.now(),e)}async createContinuation(e,t,n,r){let i=Ke(),a=Date.now();return this.#t.set(i,{cwd:t,model:n,provider:r,title:null,parentSessionId:e,created:a}),{id:i,cwd:t,model:n,provider:r,title:null,parentSessionId:e,endReason:null,created:a,updated:a,inputTokens:0,outputTokens:0,messageCount:0}}#r(e){let t=[],n=e,r=new Set;for(;n&&!r.has(n);){t.push(n),r.add(n);let e=this.#e.prepare(`SELECT parent_session_id FROM sessions WHERE id = ?`).get(n),i=null;if(i=e?e.parent_session_id:this.#t.get(n)?.parentSessionId??null,i){let e=this.#e.prepare(`SELECT end_reason FROM sessions WHERE id = ?`).get(i);n=e&&e.end_reason===`compacted`?``:i}else n=``}return t.reverse(),t}#i(e,t,n,r){this.#e.prepare(`INSERT INTO messages (session_id, seq, message, ts) VALUES (?, ?, ?, ?)`).run(e,t,JSON.stringify(n),r)}async prune(){try{this.#e.exec(`DELETE FROM sessions WHERE message_count = 0`)}catch{}}close(){We()}};let U=null;async function Je(e){return U||(U=new qe(e?`${e}/state.db`:void 0),U)}function W(e){return N.find(t=>t.id===e)}function G(e){let t=W(e);return t?t.models.map(e=>({...e,provider:t.id})):[]}function K(e,t){return G(e).find(e=>e.id===t)}function Ye(e){for(let t of N){let n=K(t.id,e);if(n)return n}}function Xe(e){let t=G(e);return t.find(e=>e.default)??t[0]}function Ze({message:e,options:t,header:n,footer:r,onSelect:i}){let[a,o]=D(0);return E((e,n)=>{if(n.escape){i(null);return}if(n.upArrow){o(e=>(e-1+t.length)%t.length);return}if(n.downArrow){o(e=>(e+1)%t.length);return}n.return&&i(t[a]?.value??null)}),k(w,{flexDirection:`column`,paddingX:1,children:[n&&O(w,{marginBottom:1,children:O(T,{children:n})}),O(w,{marginBottom:1,children:O(T,{bold:!0,color:`cyan`,children:e})}),t.map((e,t)=>k(w,{children:[k(T,{bold:t===a,color:t===a?`cyan`:void 0,children:[t===a?`❯ `:` `,e.label]}),e.hint&&t===a&&k(T,{dimColor:!0,children:[` `,e.hint]})]},e.value)),O(w,{marginTop:1,children:O(T,{children:`↑↓ navigate · Enter select · Esc cancel`})}),r&&O(w,{marginTop:1,children:O(T,{children:r})})]})}function Qe({message:e,options:t,header:n,footer:r,onSelect:i}){let[a,o]=D(``),[s,c]=D(0),l=re(()=>{let e=a.trim().toLowerCase();return e?t.filter(t=>t.label.toLowerCase().includes(e)):t},[t,a]),u=l.length===0?0:Math.min(s,l.length-1);return E((e,t)=>{if(t.escape){i(null);return}if(t.return){l.length>0&&i(l[u]?.value??null);return}if(t.upArrow){c(e=>l.length===0?0:(e-1+l.length)%l.length);return}if(t.downArrow){c(e=>l.length===0?0:(e+1)%l.length);return}if(t.backspace||t.delete){o(e=>e.slice(0,-1)),c(0);return}e&&!t.ctrl&&!t.meta&&e.trim()&&(o(t=>t+e),c(0))}),k(w,{flexDirection:`column`,paddingX:1,children:[n&&O(w,{marginBottom:1,children:O(T,{children:n})}),O(w,{marginBottom:1,children:O(T,{bold:!0,color:`cyan`,children:e})}),k(w,{marginBottom:1,children:[O(T,{color:`cyan`,children:`❯ `}),O(T,{bold:!0,children:a}),O(T,{color:`cyan`,children:`▏`})]}),l.length===0?O(w,{children:O(T,{dimColor:!0,children:`No matches`})}):l.map((e,t)=>k(w,{children:[k(T,{bold:t===u,color:t===u?`cyan`:void 0,children:[t===u?`❯ `:` `,e.label]}),e.hint&&t===u&&k(T,{dimColor:!0,children:[` `,e.hint]})]},e.value)),O(w,{marginTop:1,children:O(T,{children:`type to filter · ↑↓ navigate · Enter select · Esc cancel`})}),r&&O(w,{marginTop:1,children:O(T,{children:r})})]})}function $e({message:e,validate:t,onSubmit:n}){let[r,i]=D(``),[a,o]=D(``);return E((e,a)=>{if(a.escape){n(null);return}if(a.return){let e=t?.(r);if(e){o(e);return}n(r);return}if(a.backspace||a.delete){i(e=>e.slice(0,-1)),o(``);return}e&&(i(t=>t+e),o(``))}),k(w,{flexDirection:`column`,paddingX:1,children:[O(w,{marginBottom:1,children:O(T,{bold:!0,color:`cyan`,children:e})}),k(w,{children:[O(T,{color:`green`,children:`│ `}),O(T,{bold:!0,children:`*`.repeat(r.length)}),O(T,{color:`green`,children:`│`})]}),a&&O(w,{marginTop:1,children:k(T,{bold:!0,color:`red`,children:[`✗ `,a]})}),O(w,{marginTop:1,children:O(T,{children:`Enter submit · Esc cancel`})})]})}function et({message:e,onConfirm:t}){let[n,r]=D(!0);return E((e,i)=>{if(i.escape){t(null);return}if(i.leftArrow||i.rightArrow||i.tab){r(e=>!e);return}i.return&&t(n)}),k(w,{flexDirection:`column`,paddingX:1,children:[O(w,{marginBottom:1,children:O(T,{bold:!0,color:`cyan`,children:e})}),O(w,{children:O(T,{bold:n,color:n?`cyan`:void 0,children:n?`❯ Yes`:` Yes`})}),O(w,{children:O(T,{bold:!n,color:n?void 0:`cyan`,children:n?` No`:`❯ No`})}),O(w,{marginTop:1,children:O(T,{children:`←→ toggle · Enter confirm · Esc cancel`})})]})}function tt({req:e,onResolve:t}){let[n,r]=D(!0);return E((e,i)=>{if(i.escape){t(null);return}if(i.upArrow||i.downArrow||i.leftArrow||i.rightArrow||i.tab){r(e=>!e);return}i.return&&t(n)}),k(w,{flexDirection:`column`,paddingX:1,children:[e.warning&&O(w,{marginBottom:1,children:O(T,{bold:!0,color:`red`,children:e.warning})}),k(w,{flexDirection:`row`,children:[k(T,{bold:!0,color:`yellow`,children:[`Approve?`,` `]}),O(T,{bold:n,color:n?`cyan`:void 0,children:n?`❯ Allow once `:` Allow once `}),O(T,{bold:!n,color:n?void 0:`cyan`,children:n?` Deny`:`❯ Deny`}),O(T,{children:` (←→ toggle · Enter confirm · Esc deny)`})]})]})}function q(e,t,n,r){return new Promise(i=>{let{unmount:a}=ne(O(Ze,{message:e,options:t,header:n,footer:r,onSelect:e=>{a(),i(e)}}))})}function nt(e,t){return new Promise(n=>{let{unmount:r}=ne(O($e,{message:e,validate:t,onSubmit:e=>{r(),n(e)}}))})}async function rt(){console.log(t.bold.cyan(`
87
87
  ⚡ Nova — your coding companion
88
- `));let e=await K(`Pick a provider`,[...N].sort((e,t)=>e.name.localeCompare(t.name)).map(e=>({value:e.id,label:e.name})));e||(console.log(t.dim(`Cancelled`)),process.exit(0));let n=U(e);n||(console.log(t.red(`Unknown provider`)),process.exit(1));let r=await tt(`Enter ${n.name} API key`);r||(console.log(t.dim(`Cancelled`)),process.exit(0));let i=await K(`Pick a default model`,W(e).map(e=>({value:e.id,label:`${e.id} (${(e.contextWindow/1e3).toFixed(0)}k ctx)`})));i||(console.log(t.dim(`Cancelled`)),process.exit(0));let a={provider:e,model:i};return await Re(a),await ze({apiKeys:{[e]:r}}),console.log(t.green(`
88
+ `));let e=await q(`Pick a provider`,[...N].sort((e,t)=>e.name.localeCompare(t.name)).map(e=>({value:e.id,label:e.name})));e||(console.log(`Cancelled`),process.exit(0));let n=W(e);n||(console.log(t.red(`Unknown provider`)),process.exit(1));let r=await nt(`Enter ${n.name} API key`);r||(console.log(`Cancelled`),process.exit(0));let i=await q(`Pick a default model`,G(e).map(e=>({value:e.id,label:`${e.id} (${(e.contextWindow/1e3).toFixed(0)}k ctx)`})));i||(console.log(`Cancelled`),process.exit(0));let a={provider:e,model:i};return await Be(a),await Ve({apiKeys:{[e]:r}}),console.log(t.green(`
89
89
  ✓ Ready. Type your prompt or /help for commands
90
- `)),a}const rt=new Set([`.env.example`,`.env.sample`,`.env.template`]),it=/^\.env(\..*)?$/i,at=new Set([`.env`,`.npmrc`,`.pypirc`,`.netrc`,`.git-credentials`,`credentials`,`credentials.json`,`id_rsa`,`id_dsa`,`id_ecdsa`,`id_ed25519`,`.htpasswd`]),ot=new Set([`.pem`,`.key`,`.p12`,`.pfx`,`.keystore`,`.jks`,`.kdbx`]),st=new Set([`.ssh`,`.aws`,`.gnupg`,`secrets`,`.secrets`]);function ct(e){let t=g(e).toLowerCase();if(!t)return!1;if(it.test(t))return!rt.has(t);if(at.has(t))return!0;let n=t.lastIndexOf(`.`);return n>0&&ot.has(t.slice(n))?!0:e.toLowerCase().split(ee).some(e=>st.has(e))}function lt(e){switch(e.name){case`read`:case`ls`:case`glob`:case`grep`:case`tree`:return`safe`;case`write`:case`edit`:return`write`;case`git`:{let t=e.args.action??``;return t===`add`||t===`commit`?`write`:`safe`}case`bash`:return`execution`;case`web_search`:case`web_fetch`:return`network`;default:return`execution`}}function ut(e){let t=e.args;switch(e.name){case`bash`:return String(t.command??``);case`read`:return`read ${t.path??``}`;case`write`:return`write ${t.path??``}`;case`edit`:return`edit ${t.path??``}`;case`git`:return`git ${t.action??``} ${(t.args??[]).join(` `)}`.trim();case`web_fetch`:return`fetch ${t.url??``}`;case`web_search`:return`search "${t.query??``}"`;case`glob`:return`glob ${t.pattern??``}`;case`grep`:return`grep "${t.pattern??``}"${t.path?` in ${t.path}`:``}`;case`ls`:return`ls ${t.path??``}`;case`tree`:return`tree ${t.path??``}`;default:return e.name}}function dt(e){if(!e)return``;let t=[];/(^|[^.a-z])\.env($|[^.a-z])/i.test(e)&&t.push(`.env`);for(let n of at)n!==`.env`&&e.includes(n)&&t.push(n);for(let n of ot)if(e.includes(n)){t.push(`*${n}`);break}return t.length?`⚠ command may read secret file (${t.join(`, `)})`:``}var ft=class{#e;#t;#n=null;constructor(e,t){this.#e=e,this.#t=t}get mode(){return this.#e}setMode(e){this.#e=e}setApprover(e){this.#n=e}async check(e){if(this.#e===`unrestricted`)return{allow:!0};let t=this.#r(e);if(t)return{allow:!1,reason:`Blocked: "${t}" is a secret file and cannot be read in restricted mode.`};if(lt(e)===`safe`)return{allow:!0};if(!this.#n)return{allow:!1,reason:`Blocked: restricted mode requires interactive approval, but no approver is connected.`};let n=ut(e),r={tool:e.name,risk:lt(e),summary:n,warning:e.name===`bash`?dt(n):void 0};return await this.#n.request(r)?{allow:!0}:{allow:!1,reason:`Denied: ${e.name} was not approved by the user.`}}#r(e){if(e.name!==`read`&&e.name!==`grep`)return null;let t=e.args.path;return typeof t!=`string`||!t.trim()?null:ct(S(this.#t,t))?t:null}};const pt=new Set([`.jpg`,`.jpeg`,`.png`,`.gif`,`.webp`]),mt=e=>i({description:`Read file contents. Supports text and images (jpg, png, gif, webp). Text output is truncated to 2000 lines.`,inputSchema:A.object({path:A.string().describe(`Path to file (relative or absolute)`),offset:A.number().optional().describe(`Start line (1-based, default 1)`),limit:A.number().optional().describe(`Max lines to read (default 2000)`)}),execute:async t=>{try{let n=S(e,t.path),r=v(n).toLowerCase();if(pt.has(r))return{content:[{type:`image`,data:(await f(n)).toString(`base64`),mime:r===`.jpg`?`image/jpeg`:`image/${r.slice(1)}`}],isError:!1};let i=(await f(n,`utf-8`)).split(`
90
+ `)),a}const it=new Set([`.env.example`,`.env.sample`,`.env.template`]),at=/^\.env(\..*)?$/i,ot=new Set([`.env`,`.npmrc`,`.pypirc`,`.netrc`,`.git-credentials`,`credentials`,`credentials.json`,`id_rsa`,`id_dsa`,`id_ecdsa`,`id_ed25519`,`.htpasswd`]),st=new Set([`.pem`,`.key`,`.p12`,`.pfx`,`.keystore`,`.jks`,`.kdbx`]),ct=new Set([`.ssh`,`.aws`,`.gnupg`,`secrets`,`.secrets`]);function lt(e){let t=g(e).toLowerCase();if(!t)return!1;if(at.test(t))return!it.has(t);if(ot.has(t))return!0;let n=t.lastIndexOf(`.`);return n>0&&st.has(t.slice(n))?!0:e.toLowerCase().split(ee).some(e=>ct.has(e))}function ut(e){switch(e.name){case`read`:case`ls`:case`glob`:case`grep`:case`tree`:return`safe`;case`write`:case`edit`:return`write`;case`git`:{let t=e.args.action??``;return t===`add`||t===`commit`?`write`:`safe`}case`bash`:return`execution`;case`web_search`:case`web_fetch`:return`network`;default:return`execution`}}function dt(e){let t=e.args;switch(e.name){case`bash`:return String(t.command??``);case`read`:return`read ${t.path??``}`;case`write`:return`write ${t.path??``}`;case`edit`:return`edit ${t.path??``}`;case`git`:return`git ${t.action??``} ${(t.args??[]).join(` `)}`.trim();case`web_fetch`:return`fetch ${t.url??``}`;case`web_search`:return`search "${t.query??``}"`;case`glob`:return`glob ${t.pattern??``}`;case`grep`:return`grep "${t.pattern??``}"${t.path?` in ${t.path}`:``}`;case`ls`:return`ls ${t.path??``}`;case`tree`:return`tree ${t.path??``}`;default:return e.name}}function ft(e){if(!e)return``;let t=[];/(^|[^.a-z])\.env($|[^.a-z])/i.test(e)&&t.push(`.env`);for(let n of ot)n!==`.env`&&e.includes(n)&&t.push(n);for(let n of st)if(e.includes(n)){t.push(`*${n}`);break}return t.length?`⚠ command may read secret file (${t.join(`, `)})`:``}var pt=class{#e;#t;#n=null;constructor(e,t){this.#e=e,this.#t=t}get mode(){return this.#e}setMode(e){this.#e=e}setApprover(e){this.#n=e}async check(e){if(this.#e===`unrestricted`)return{allow:!0};let t=this.#r(e);if(t)return{allow:!1,reason:`Blocked: "${t}" is a secret file and cannot be read in restricted mode.`};if(ut(e)===`safe`)return{allow:!0};if(!this.#n)return{allow:!1,reason:`Blocked: restricted mode requires interactive approval, but no approver is connected.`};let n=dt(e),r={tool:e.name,risk:ut(e),summary:n,warning:e.name===`bash`?ft(n):void 0};return await this.#n.request(r)?{allow:!0}:{allow:!1,reason:`Denied: ${e.name} was not approved by the user.`}}#r(e){if(e.name!==`read`&&e.name!==`grep`)return null;let t=e.args.path;return typeof t!=`string`||!t.trim()?null:lt(S(this.#t,t))?t:null}};const mt=new Set([`.jpg`,`.jpeg`,`.png`,`.gif`,`.webp`]),ht=e=>i({description:`Read file contents. Supports text and images (jpg, png, gif, webp). Text output is truncated to 2000 lines.`,inputSchema:A.object({path:A.string().describe(`Path to file (relative or absolute)`),offset:A.number().optional().describe(`Start line (1-based, default 1)`),limit:A.number().optional().describe(`Max lines to read (default 2000)`)}),execute:async t=>{try{let n=S(e,t.path),r=v(n).toLowerCase();if(mt.has(r))return{content:[{type:`image`,data:(await f(n)).toString(`base64`),mime:r===`.jpg`?`image/jpeg`:`image/${r.slice(1)}`}],isError:!1};let i=(await f(n,`utf-8`)).split(`
91
91
  `),a=Math.max(0,(t.offset??1)-1),o=t.limit??2e3,s=i.slice(a,a+o),c=a+o<i.length;return{content:[{type:`text`,text:s.join(`
92
- `)+(c?`\n…${i.length-a-o} more lines`:``)}],isError:!1}}catch(e){return{content:[{type:`text`,text:`Error reading file: ${e.message}`}],isError:!0}}},toModelOutput:({output:e})=>P(e)}),ht=e=>i({description:`Write content to a file. Creates the file and parent directories if needed.`,inputSchema:A.object({path:A.string().describe(`Path to file`),content:A.string().describe(`Content to write`)}),execute:async t=>{try{let n=S(e,t.path);await d(_(n),{recursive:!0}),await h(n,t.content);let r=F(e,n);return{content:[{type:`text`,text:`Wrote ${t.content.length} bytes → ${r}`}],isError:!1}}catch(e){return{content:[{type:`text`,text:`Error writing file: ${e.message}`}],isError:!0}}},toModelOutput:({output:e})=>P(e)}),gt=e=>i({description:`Edit a file using exact text replacement. Each edit's oldText must be unique in the file.`,inputSchema:A.object({path:A.string().describe(`Path to file`),edits:A.array(A.object({oldText:A.string().describe(`Exact text to find (must be unique)`),newText:A.string().describe(`Replacement text`)})).describe(`Array of {oldText, newText} replacements. oldText must be unique. Non-overlapping.`)}),execute:async t=>{try{let n=S(e,t.path),r;try{r=await f(n,`utf-8`)}catch{return{content:[{type:`text`,text:`File not found: ${t.path}`}],isError:!0}}let i=t.edits;for(let e of i){let t=r.split(e.oldText).length-1;if(t===0)return{content:[{type:`text`,text:`oldText not found: "${e.oldText.slice(0,80)}…"`}],isError:!0};if(t>1)return{content:[{type:`text`,text:`oldText found ${t} times — add surrounding context to make it unique: "${e.oldText.slice(0,60)}…"`}],isError:!0}}for(let e of i)r=r.replace(e.oldText,e.newText);return await h(n,r),{content:[{type:`text`,text:`Edited ${F(e,n)} (${i.length} replacement${i.length>1?`s`:``})`}],isError:!1}}catch(e){return{content:[{type:`text`,text:`Error editing file: ${e.message}`}],isError:!0}}},toModelOutput:({output:e})=>P(e)}),_t=e=>i({description:`Execute safe, non-interactive git commands (status, diff, log, add, commit) in the repository.`,inputSchema:A.object({action:A.enum([`status`,`diff`,`log`,`add`,`commit`]).describe(`The git action to execute`),args:A.array(A.string()).optional().describe(`Optional additional arguments or file paths`)}),execute:async(t,{abortSignal:n})=>{let r=t.action,i=t.args??[];if(!new Set([`status`,`diff`,`log`,`add`,`commit`]).has(r))return{content:[{type:`text`,text:`Error: Git action '${r}' is not supported.`}],isError:!0};try{let t=[`git`,r,...i],a=j(t[0],t.slice(1),{cwd:e,stdio:[`ignore`,`pipe`,`pipe`],env:{...process.env,PAGER:`cat`}}),o=``,s=``;a.stdout.on(`data`,e=>{o+=e.toString()}),a.stderr.on(`data`,e=>{s+=e.toString()});let c=()=>{a.kill(`SIGKILL`),a.stdout.destroy(),a.stderr.destroy()};n?.addEventListener(`abort`,c,{once:!0});let l;try{l=await new Promise((e,t)=>{a.on(`error`,t),a.on(`close`,t=>e(t??-1))})}finally{n?.removeEventListener(`abort`,c)}let u=5e4,d=``;return o&&(d+=o.slice(0,u)),s&&(d&&(d+=`
92
+ `)+(c?`\n…${i.length-a-o} more lines`:``)}],isError:!1}}catch(e){return{content:[{type:`text`,text:`Error reading file: ${e.message}`}],isError:!0}}},toModelOutput:({output:e})=>F(e)}),gt=e=>i({description:`Write content to a file. Creates the file and parent directories if needed.`,inputSchema:A.object({path:A.string().describe(`Path to file`),content:A.string().describe(`Content to write`)}),execute:async t=>{try{let n=S(e,t.path);await d(_(n),{recursive:!0}),await h(n,t.content);let r=I(e,n);return{content:[{type:`text`,text:`Wrote ${t.content.length} bytes → ${r}`}],isError:!1}}catch(e){return{content:[{type:`text`,text:`Error writing file: ${e.message}`}],isError:!0}}},toModelOutput:({output:e})=>F(e)}),_t=e=>i({description:`Edit a file using exact text replacement. Each edit's oldText must be unique in the file.`,inputSchema:A.object({path:A.string().describe(`Path to file`),edits:A.array(A.object({oldText:A.string().describe(`Exact text to find (must be unique)`),newText:A.string().describe(`Replacement text`)})).describe(`Array of {oldText, newText} replacements. oldText must be unique. Non-overlapping.`)}),execute:async t=>{try{let n=S(e,t.path),r;try{r=await f(n,`utf-8`)}catch{return{content:[{type:`text`,text:`File not found: ${t.path}`}],isError:!0}}let i=t.edits;for(let e of i){let t=r.split(e.oldText).length-1;if(t===0)return{content:[{type:`text`,text:`oldText not found: "${e.oldText.slice(0,80)}…"`}],isError:!0};if(t>1)return{content:[{type:`text`,text:`oldText found ${t} times — add surrounding context to make it unique: "${e.oldText.slice(0,60)}…"`}],isError:!0}}for(let e of i)r=r.replace(e.oldText,e.newText);return await h(n,r),{content:[{type:`text`,text:`Edited ${I(e,n)} (${i.length} replacement${i.length>1?`s`:``})`}],isError:!1}}catch(e){return{content:[{type:`text`,text:`Error editing file: ${e.message}`}],isError:!0}}},toModelOutput:({output:e})=>F(e)}),vt=e=>i({description:`Execute safe, non-interactive git commands (status, diff, log, add, commit) in the repository.`,inputSchema:A.object({action:A.enum([`status`,`diff`,`log`,`add`,`commit`]).describe(`The git action to execute`),args:A.array(A.string()).optional().describe(`Optional additional arguments or file paths`)}),execute:async(t,{abortSignal:n})=>{let r=t.action,i=t.args??[];if(!new Set([`status`,`diff`,`log`,`add`,`commit`]).has(r))return{content:[{type:`text`,text:`Error: Git action '${r}' is not supported.`}],isError:!0};try{let t=[`git`,r,...i],a=j(t[0],t.slice(1),{cwd:e,stdio:[`ignore`,`pipe`,`pipe`],env:{...process.env,PAGER:`cat`}}),o=``,s=``;a.stdout.on(`data`,e=>{o+=e.toString()}),a.stderr.on(`data`,e=>{s+=e.toString()});let c=()=>{a.kill(`SIGKILL`),a.stdout.destroy(),a.stderr.destroy()};n?.addEventListener(`abort`,c,{once:!0});let l;try{l=await new Promise((e,t)=>{a.on(`error`,t),a.on(`close`,t=>e(t??-1))})}finally{n?.removeEventListener(`abort`,c)}let u=5e4,d=``;return o&&(d+=o.slice(0,u)),s&&(d&&(d+=`
93
93
  `),d+=s.slice(0,u-d.length)),d.length>=u&&(d+=`
94
- …truncated`),{content:[{type:`text`,text:d||`(no output)`}],isError:l!==0}}catch(e){return{content:[{type:`text`,text:`Error running git: ${e.message}`}],isError:!0}}},toModelOutput:({output:e})=>P(e)}),vt=e=>i({description:`Find files by glob pattern (e.g. **/*.ts, src/**/*.test.ts).`,inputSchema:A.object({pattern:A.string().describe(`Glob pattern (e.g. **/*.ts)`),path:A.string().optional().describe(`Directory to search in (default .)`),nocase:A.boolean().optional().describe(`Case-insensitive search (default false)`)}),execute:async t=>{try{let n=S(e,t.path??`.`),r=(await ie(t.pattern,{cwd:n,nocase:t.nocase??!1})).slice(0,500),i=x(e,n),a=i?`${i}/`:``,o=r.map(e=>a+e);return{content:[{type:`text`,text:o.length>0?o.join(`
95
- `):`No files found`}],isError:!1}}catch(e){return{content:[{type:`text`,text:`Error: ${e.message}`}],isError:!0}}},toModelOutput:({output:e})=>P(e)}),yt=e=>i({description:`Search file contents with a regex pattern. Returns matching lines with file paths and line numbers.`,inputSchema:A.object({pattern:A.string().describe(`Regex pattern to search for`),path:A.string().optional().describe(`Directory or file to search in (default .)`),glob:A.string().optional().describe(`File filter glob (e.g. *.ts)`)}),execute:async(t,{abortSignal:n})=>{try{let r=S(e,t.path??`.`),i=t.glob,a=x(e,r)||`.`;try{let r=[`rg`,`--line-number`,`--max-count`,`200`];i&&r.push(`--glob=${i}`),r.push(`--`,t.pattern,a);let o=j(r[0],r.slice(1),{cwd:e,stdio:[`ignore`,`pipe`,`pipe`]}),s=()=>{o.kill(),o.stdout.destroy(),o.stderr.destroy()};n?.addEventListener(`abort`,s,{once:!0});let c=``;o.stdout.on(`data`,e=>{c+=e.toString()});let l;try{l=await new Promise((e,t)=>{o.on(`error`,t),o.on(`close`,t=>e(t??-1))})}finally{n?.removeEventListener(`abort`,s)}if(l===0)return{content:[{type:`text`,text:c.split(`
94
+ …truncated`),{content:[{type:`text`,text:d||`(no output)`}],isError:l!==0}}catch(e){return{content:[{type:`text`,text:`Error running git: ${e.message}`}],isError:!0}}},toModelOutput:({output:e})=>F(e)}),yt=e=>i({description:`Find files by glob pattern (e.g. **/*.ts, src/**/*.test.ts).`,inputSchema:A.object({pattern:A.string().describe(`Glob pattern (e.g. **/*.ts)`),path:A.string().optional().describe(`Directory to search in (default .)`),nocase:A.boolean().optional().describe(`Case-insensitive search (default false)`)}),execute:async t=>{try{let n=S(e,t.path??`.`),r=(await ie(t.pattern,{cwd:n,nocase:t.nocase??!1})).slice(0,500),i=x(e,n),a=i?`${i}/`:``,o=r.map(e=>a+e);return{content:[{type:`text`,text:o.length>0?o.join(`
95
+ `):`No files found`}],isError:!1}}catch(e){return{content:[{type:`text`,text:`Error: ${e.message}`}],isError:!0}}},toModelOutput:({output:e})=>F(e)}),bt=e=>i({description:`Search file contents with a regex pattern. Returns matching lines with file paths and line numbers.`,inputSchema:A.object({pattern:A.string().describe(`Regex pattern to search for`),path:A.string().optional().describe(`Directory or file to search in (default .)`),glob:A.string().optional().describe(`File filter glob (e.g. *.ts)`)}),execute:async(t,{abortSignal:n})=>{try{let r=S(e,t.path??`.`),i=t.glob,a=x(e,r)||`.`;try{let r=[`rg`,`--line-number`,`--max-count`,`200`];i&&r.push(`--glob=${i}`),r.push(`--`,t.pattern,a);let o=j(r[0],r.slice(1),{cwd:e,stdio:[`ignore`,`pipe`,`pipe`]}),s=()=>{o.kill(),o.stdout.destroy(),o.stderr.destroy()};n?.addEventListener(`abort`,s,{once:!0});let c=``;o.stdout.on(`data`,e=>{c+=e.toString()});let l;try{l=await new Promise((e,t)=>{o.on(`error`,t),o.on(`close`,t=>e(t??-1))})}finally{n?.removeEventListener(`abort`,s)}if(l===0)return{content:[{type:`text`,text:c.split(`
96
96
  `).slice(0,200).join(`
97
97
  `)||`No matches`}],isError:!1}}catch{}let o=await ie(i||`**/*`,{cwd:r,ignore:[`**/node_modules/**`,`**/.git/**`]}),s=a===`.`?``:`${a}/`,c=new RegExp(t.pattern,`i`),l=[];for(let e of o.slice(0,500)){if(n?.aborted)break;try{let t=(await f(S(r,e),`utf-8`)).split(`
98
98
  `);for(let n=0;n<t.length&&l.length<200;n++){let r=t[n];r&&c.test(r)&&l.push(`${s}${e}:${n+1}:${r}`)}}catch{}}return{content:[{type:`text`,text:l.join(`
99
- `)||`No matches`}],isError:!1}}catch(e){return{content:[{type:`text`,text:`Error: ${e.message}`}],isError:!0}}},toModelOutput:({output:e})=>P(e)}),bt=e=>i({description:`List directory contents.`,inputSchema:A.object({path:A.string().optional().describe(`Directory to list (default .)`)}),execute:async t=>{try{return{content:[{type:`text`,text:(await p(S(e,t.path??`.`),{withFileTypes:!0})).map(e=>{let t=e.isDirectory()?`/`:e.isSymbolicLink()?`@`:``;return`${e.name}${t}`}).join(`
100
- `)||`(empty)`}],isError:!1}}catch(e){return{content:[{type:`text`,text:`Error: ${e.message}`}],isError:!0}}},toModelOutput:({output:e})=>P(e)}),xt=e=>i({description:`Print a visual directory tree structure, ignoring common ignored folders like node_modules and .git.`,inputSchema:A.object({path:A.string().optional().describe(`Directory to start tree from (default .)`),depth:A.number().optional().describe(`Maximum depth to traverse (default 3)`)}),execute:async t=>{try{let n=S(e,t.path??`.`),r=t.depth??3,i=new Set([`.git`,`node_modules`,`dist`,`build`,`.svelte-kit`,`.next`,`out`,`.scannerwork`,`coverage`]);async function a(e,t,n){if(t>r)return``;let o=``,s=(await p(e,{withFileTypes:!0})).filter(e=>!i.has(e.name)).sort((e,t)=>e.isDirectory()&&!t.isDirectory()?-1:!e.isDirectory()&&t.isDirectory()?1:e.name.localeCompare(t.name));for(let r=0;r<s.length;r++){let i=s[r],c=r===s.length-1,l=c?`└── `:`├── `,u=n+(c?` `:`│ `);o+=`${n}${l}${i.name}${i.isDirectory()?`/`:``}\n`,i.isDirectory()&&(o+=await a(S(e,i.name),t+1,u))}return o}return{content:[{type:`text`,text:await a(n,1,``)||`(empty)`}],isError:!1}}catch(e){return{content:[{type:`text`,text:`Error: ${e.message}`}],isError:!0}}},toModelOutput:({output:e})=>P(e)}),St=e=>i({description:`Execute a shell command. Returns stdout and stderr. Timeout after N seconds (default 120).`,inputSchema:A.object({command:A.string().describe(`Shell command to run`),timeout:A.number().optional().describe(`Timeout in seconds (default 120)`)}),execute:async(t,{abortSignal:n})=>{let r=t.command,i=(t.timeout??120)*1e3;try{let t=j(`sh`,[`-c`,r],{cwd:e,stdio:[`ignore`,`pipe`,`pipe`]}),a=``,o=``;t.stdout.on(`data`,e=>{a+=e.toString()}),t.stderr.on(`data`,e=>{o+=e.toString()});let s=!1,c=setTimeout(()=>{s=!0,t.kill(`SIGKILL`),t.stdout.destroy(),t.stderr.destroy()},i),l=()=>{s=!0,t.kill(`SIGKILL`),t.stdout.destroy(),t.stderr.destroy()};n?.addEventListener(`abort`,l,{once:!0});let u;try{u=await new Promise((e,n)=>{t.on(`error`,n),t.on(`close`,t=>e(t??-1))})}finally{clearTimeout(c),n?.removeEventListener(`abort`,l)}let d=5e4,f=``;return a&&(f+=a.slice(0,d)),o&&(f&&(f+=`
99
+ `)||`No matches`}],isError:!1}}catch(e){return{content:[{type:`text`,text:`Error: ${e.message}`}],isError:!0}}},toModelOutput:({output:e})=>F(e)}),xt=e=>i({description:`List directory contents.`,inputSchema:A.object({path:A.string().optional().describe(`Directory to list (default .)`)}),execute:async t=>{try{return{content:[{type:`text`,text:(await p(S(e,t.path??`.`),{withFileTypes:!0})).map(e=>{let t=e.isDirectory()?`/`:e.isSymbolicLink()?`@`:``;return`${e.name}${t}`}).join(`
100
+ `)||`(empty)`}],isError:!1}}catch(e){return{content:[{type:`text`,text:`Error: ${e.message}`}],isError:!0}}},toModelOutput:({output:e})=>F(e)}),St=e=>i({description:`Print a visual directory tree structure, ignoring common ignored folders like node_modules and .git.`,inputSchema:A.object({path:A.string().optional().describe(`Directory to start tree from (default .)`),depth:A.number().optional().describe(`Maximum depth to traverse (default 3)`)}),execute:async t=>{try{let n=S(e,t.path??`.`),r=t.depth??3,i=new Set([`.git`,`node_modules`,`dist`,`build`,`.svelte-kit`,`.next`,`out`,`.scannerwork`,`coverage`]);async function a(e,t,n){if(t>r)return``;let o=``,s=(await p(e,{withFileTypes:!0})).filter(e=>!i.has(e.name)).sort((e,t)=>e.isDirectory()&&!t.isDirectory()?-1:!e.isDirectory()&&t.isDirectory()?1:e.name.localeCompare(t.name));for(let r=0;r<s.length;r++){let i=s[r],c=r===s.length-1,l=c?`└── `:`├── `,u=n+(c?` `:`│ `);o+=`${n}${l}${i.name}${i.isDirectory()?`/`:``}\n`,i.isDirectory()&&(o+=await a(S(e,i.name),t+1,u))}return o}return{content:[{type:`text`,text:await a(n,1,``)||`(empty)`}],isError:!1}}catch(e){return{content:[{type:`text`,text:`Error: ${e.message}`}],isError:!0}}},toModelOutput:({output:e})=>F(e)}),Ct=e=>i({description:`Execute a shell command. Returns stdout and stderr. Timeout after N seconds (default 120).`,inputSchema:A.object({command:A.string().describe(`Shell command to run`),timeout:A.number().optional().describe(`Timeout in seconds (default 120)`)}),execute:async(t,{abortSignal:n})=>{let r=t.command,i=(t.timeout??120)*1e3;try{let t=j(`sh`,[`-c`,r],{cwd:e,stdio:[`ignore`,`pipe`,`pipe`]}),a=``,o=``;t.stdout.on(`data`,e=>{a+=e.toString()}),t.stderr.on(`data`,e=>{o+=e.toString()});let s=!1,c=setTimeout(()=>{s=!0,t.kill(`SIGKILL`),t.stdout.destroy(),t.stderr.destroy()},i),l=()=>{s=!0,t.kill(`SIGKILL`),t.stdout.destroy(),t.stderr.destroy()};n?.addEventListener(`abort`,l,{once:!0});let u;try{u=await new Promise((e,n)=>{t.on(`error`,n),t.on(`close`,t=>e(t??-1))})}finally{clearTimeout(c),n?.removeEventListener(`abort`,l)}let d=5e4,f=``;return a&&(f+=a.slice(0,d)),o&&(f&&(f+=`
101
101
  `),f+=o.slice(0,d-f.length)),f.length>=d&&(f+=`
102
- …truncated`),s&&(f+=`\n[timeout after ${i/1e3}s]`),f+=`\n[exit ${u}]`,{content:[{type:`text`,text:f}],isError:u!==0||s}}catch(e){return{content:[{type:`text`,text:`Error: ${e.message}`}],isError:!0}}},toModelOutput:({output:e})=>P(e)}),q=5e4;function J(e,t,n){let r;do r=e,e=e.replace(t,n);while(e!==r);return e}function Y(e){let t=e;return t=J(t,/<!--[\s\S]*?-->/g,``),t=J(t,/<script[\s\S]*?<\/script[^>]*>/gi,``),t=J(t,/<style[\s\S]*?<\/style[^>]*>/gi,``),t=t.replace(/<a[^>]*href=["']?([^"'>\s]*)["']?[^>]*>([\s\S]*?)<\/a>/gi,`[$2]($1)`).replace(/<\/?(p|div|br|h[1-6]|li|tr|blockquote|pre|hr)[^>]*>/gi,`
102
+ …truncated`),s&&(f+=`\n[timeout after ${i/1e3}s]`),f+=`\n[exit ${u}]`,{content:[{type:`text`,text:f}],isError:u!==0||s}}catch(e){return{content:[{type:`text`,text:`Error: ${e.message}`}],isError:!0}}},toModelOutput:({output:e})=>F(e)}),J=5e4;function Y(e,t,n){let r;do r=e,e=e.replace(t,n);while(e!==r);return e}function X(e){let t=e;return t=Y(t,/<!--[\s\S]*?-->/g,``),t=Y(t,/<script[\s\S]*?<\/script[^>]*>/gi,``),t=Y(t,/<style[\s\S]*?<\/style[^>]*>/gi,``),t=t.replace(/<a[^>]*href=["']?([^"'>\s]*)["']?[^>]*>([\s\S]*?)<\/a>/gi,`[$2]($1)`).replace(/<\/?(p|div|br|h[1-6]|li|tr|blockquote|pre|hr)[^>]*>/gi,`
103
103
  `).replace(/<[^>]+>/g,``).replace(/&lt;/g,`<`).replace(/&gt;/g,`>`).replace(/&quot;/g,`"`).replace(/&#34;/g,`"`).replace(/&#x22;/g,`"`).replace(/&#39;/g,`'`).replace(/&#x27;/g,`'`).replace(/&apos;/g,`'`).replace(/&ldquo;/g,`"`).replace(/&rdquo;/g,`"`).replace(/&lsquo;/g,`'`).replace(/&rsquo;/g,`'`).replace(/&nbsp;/g,` `).replace(/&amp;/g,`&`).replace(/[ \t]+/g,` `).replace(/\n{3,}/g,`
104
104
 
105
- `).trim(),t.length>q&&(t=`${t.slice(0,q)}\n…truncated`),t}const Ct=`Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36`,wt=()=>i({description:`Search the web using DuckDuckGo. Returns up to 10 results with titles, URLs, and snippets. Use this when you need information from the internet.`,inputSchema:A.object({query:A.string().describe(`Search query`)}),execute:async(e,{abortSignal:t})=>{let n=e.query;if(!n.trim())return{content:[{type:`text`,text:`Error: empty search query`}],isError:!0};try{let e=`https://html.duckduckgo.com/html/?q=${encodeURIComponent(n)}`,r=await fetch(e,{signal:t??void 0,headers:{"User-Agent":Ct}});if(!r.ok)return{content:[{type:`text`,text:`Search failed: HTTP ${r.status}`}],isError:!0};let i=await r.text(),a=/<div[^>]*class="[^"]*result__body[^"]*"[^>]*>/gi,o=[];for(let e of i.matchAll(a))e.index!==void 0&&o.push(e.index);let s=[];if(o.length>0)for(let e=0;e<o.length;e++){let t=o[e],n=o[e+1]??i.length;s.push(i.slice(t,n))}let c=[],l=/<a[^>]*class="result__a"[^>]*href="([^"]*)"[^>]*>([\s\S]*?)<\/a>/i,u=/<a[^>]*class="result__snippet"[^>]*>([\s\S]*?)<\/a>/i;for(let e of s){if(c.length>=10)break;let t=l.exec(e);if(!t)continue;let n=t[1],r=Y(t[2]),i=u.exec(e),a=i?Y(i[1]):``,o=n;try{let e=n.startsWith(`//`)?`https:${n}`:n.startsWith(`/`)?`https://duckduckgo.com${n}`:n,t=new URL(e).searchParams.get(`uddg`);t&&(o=t)}catch{}c.push(`## ${r}\n${o}\n${a}`)}return c.length===0?{content:[{type:`text`,text:`No results found.`}],isError:!1}:{content:[{type:`text`,text:c.join(`
105
+ `).trim(),t.length>J&&(t=`${t.slice(0,J)}\n…truncated`),t}const wt=`Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36`,Tt=()=>i({description:`Search the web using DuckDuckGo. Returns up to 10 results with titles, URLs, and snippets. Use this when you need information from the internet.`,inputSchema:A.object({query:A.string().describe(`Search query`)}),execute:async(e,{abortSignal:t})=>{let n=e.query;if(!n.trim())return{content:[{type:`text`,text:`Error: empty search query`}],isError:!0};try{let e=`https://html.duckduckgo.com/html/?q=${encodeURIComponent(n)}`,r=await fetch(e,{signal:t??void 0,headers:{"User-Agent":wt}});if(!r.ok)return{content:[{type:`text`,text:`Search failed: HTTP ${r.status}`}],isError:!0};let i=await r.text(),a=/<div[^>]*class="[^"]*result__body[^"]*"[^>]*>/gi,o=[];for(let e of i.matchAll(a))e.index!==void 0&&o.push(e.index);let s=[];if(o.length>0)for(let e=0;e<o.length;e++){let t=o[e],n=o[e+1]??i.length;s.push(i.slice(t,n))}let c=[],l=/<a[^>]*class="result__a"[^>]*href="([^"]*)"[^>]*>([\s\S]*?)<\/a>/i,u=/<a[^>]*class="result__snippet"[^>]*>([\s\S]*?)<\/a>/i;for(let e of s){if(c.length>=10)break;let t=l.exec(e);if(!t)continue;let n=t[1],r=X(t[2]),i=u.exec(e),a=i?X(i[1]):``,o=n;try{let e=n.startsWith(`//`)?`https:${n}`:n.startsWith(`/`)?`https://duckduckgo.com${n}`:n,t=new URL(e).searchParams.get(`uddg`);t&&(o=t)}catch{}c.push(`## ${r}\n${o}\n${a}`)}return c.length===0?{content:[{type:`text`,text:`No results found.`}],isError:!1}:{content:[{type:`text`,text:c.join(`
106
106
 
107
- `)}],isError:!1}}catch(e){let t=e.message;return t.includes(`abort`)?{content:[{type:`text`,text:`Search aborted.`}],isError:!0}:{content:[{type:`text`,text:`Search error: ${t}`}],isError:!0}}},toModelOutput:({output:e})=>P(e)}),Tt=()=>i({description:`Fetch and read the content of a web page. Returns the page text with HTML tags stripped. Useful for reading documentation, articles, or API references.`,inputSchema:A.object({url:A.string().describe(`URL to fetch`)}),execute:async(e,{abortSignal:t})=>{let n=e.url;if(!n.trim())return{content:[{type:`text`,text:`Error: empty URL`}],isError:!0};try{new URL(n)}catch{return{content:[{type:`text`,text:`Error: invalid URL: ${n}`}],isError:!0}}try{let e=await fetch(n,{signal:t??void 0,headers:{"User-Agent":Ct,Accept:`text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8`},redirect:`follow`});if(!e.ok)return{content:[{type:`text`,text:`Fetch failed: HTTP ${e.status} ${e.statusText}`}],isError:!0};let r=(e.headers.get(`content-type`)??``).toLowerCase(),i=await e.text();return r.includes(`text/html`)||r.includes(`application/xhtml+xml`)||i.trim().toLowerCase().startsWith(`<!doctype html`)||i.trim().toLowerCase().startsWith(`<html`)?{content:[{type:`text`,text:Y(i)}],isError:!1}:{content:[{type:`text`,text:i.length>q?`${i.slice(0,q)}\n…truncated`:i}],isError:!1}}catch(e){let t=e.message;return t.includes(`abort`)?{content:[{type:`text`,text:`Fetch aborted.`}],isError:!0}:{content:[{type:`text`,text:`Fetch error: ${t}`}],isError:!0}}},toModelOutput:({output:e})=>P(e)});function Et(e){return{read:mt(e),write:ht(e),edit:gt(e),bash:St(e),glob:vt(e),grep:yt(e),ls:bt(e),tree:xt(e),git:_t(e),web_search:wt(),web_fetch:Tt()}}const Dt=_(ae(import.meta.url));let X=null,Z=null;async function Q(){if(Z)return Z;try{let e=await f(b(Dt,`..`,`package.json`),`utf-8`);return Z=JSON.parse(e).version??`0.0.0`,Z}catch{return`0.0.0`}}async function Ot(){if(X)return X;try{let e=j(`npm`,[`info`,`novacode`,`version`],{stdio:[`ignore`,`pipe`,`ignore`]}),t=await new Promise((t,n)=>{let r=``;e.stdout.on(`data`,e=>{r+=e.toString()}),e.on(`error`,n),e.on(`close`,()=>t(r.trim()))});if(t)return X=t,t}catch{}return null}async function kt(){let e=await Q(),t=await Ot();return t?{hasUpdate:oe.gt(t,e),current:e,latest:t}:null}async function At(e=!1){try{let t=j(`npm`,[`update`,`-g`,`novacode`],{stdio:e?`ignore`:`inherit`}),n=await new Promise((e,n)=>{t.on(`error`,n),t.on(`close`,t=>e(t??-1))});return n===0?(e||console.log(`✓ novacode updated to latest version successfully.`),!0):(e||(console.error(`Update failed (exit code ${n})`),process.exit(1)),!1)}catch(t){return e||(console.error(`Update failed: ${t.message}`),process.exit(1)),!1}}function jt(){let{values:t,positionals:n}=e({options:{help:{type:`boolean`,short:`h`},version:{type:`boolean`,short:`v`},provider:{type:`string`},model:{type:`string`},"api-key":{type:`string`},sessions:{type:`string`,short:`s`},resume:{type:`boolean`,short:`r`},all:{type:`boolean`},restricted:{type:`boolean`},unrestricted:{type:`boolean`}},strict:!1,allowPositionals:!0});return{flags:t,args:n}}function Mt(e,t){return t?G(t,e):qe(e)}async function Nt(){let e=Number(process.versions.node.split(`.`)[0]);(!e||e<24)&&(console.error(`novacode requires Node.js >= 24. You have ${process.version}.`),console.error(`Upgrade: https://nodejs.org/`),process.exit(1));let{flags:n,args:r}=jt();if(n.version){let e=await Q();console.log(`nova ${e}`),process.exit(0)}if(n.help&&(console.log(`nova — open-source coding agent
107
+ `)}],isError:!1}}catch(e){let t=e.message;return t.includes(`abort`)?{content:[{type:`text`,text:`Search aborted.`}],isError:!0}:{content:[{type:`text`,text:`Search error: ${t}`}],isError:!0}}},toModelOutput:({output:e})=>F(e)}),Et=()=>i({description:`Fetch and read the content of a web page. Returns the page text with HTML tags stripped. Useful for reading documentation, articles, or API references.`,inputSchema:A.object({url:A.string().describe(`URL to fetch`)}),execute:async(e,{abortSignal:t})=>{let n=e.url;if(!n.trim())return{content:[{type:`text`,text:`Error: empty URL`}],isError:!0};try{new URL(n)}catch{return{content:[{type:`text`,text:`Error: invalid URL: ${n}`}],isError:!0}}try{let e=await fetch(n,{signal:t??void 0,headers:{"User-Agent":wt,Accept:`text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8`},redirect:`follow`});if(!e.ok)return{content:[{type:`text`,text:`Fetch failed: HTTP ${e.status} ${e.statusText}`}],isError:!0};let r=(e.headers.get(`content-type`)??``).toLowerCase(),i=await e.text();return r.includes(`text/html`)||r.includes(`application/xhtml+xml`)||i.trim().toLowerCase().startsWith(`<!doctype html`)||i.trim().toLowerCase().startsWith(`<html`)?{content:[{type:`text`,text:X(i)}],isError:!1}:{content:[{type:`text`,text:i.length>J?`${i.slice(0,J)}\n…truncated`:i}],isError:!1}}catch(e){let t=e.message;return t.includes(`abort`)?{content:[{type:`text`,text:`Fetch aborted.`}],isError:!0}:{content:[{type:`text`,text:`Fetch error: ${t}`}],isError:!0}}},toModelOutput:({output:e})=>F(e)});function Dt(e){return{read:ht(e),write:gt(e),edit:_t(e),bash:Ct(e),glob:yt(e),grep:bt(e),ls:xt(e),tree:St(e),git:vt(e),web_search:Tt(),web_fetch:Et()}}const Ot=_(ae(import.meta.url));let Z=null,Q=null;async function $(){if(Q)return Q;try{let e=await f(b(Ot,`..`,`package.json`),`utf-8`);return Q=JSON.parse(e).version??`0.0.0`,Q}catch{return`0.0.0`}}async function kt(){if(Z)return Z;try{let e=j(`npm`,[`info`,`novacode`,`version`],{stdio:[`ignore`,`pipe`,`ignore`]}),t=await new Promise((t,n)=>{let r=``;e.stdout.on(`data`,e=>{r+=e.toString()}),e.on(`error`,n),e.on(`close`,()=>t(r.trim()))});if(t)return Z=t,t}catch{}return null}async function At(){let e=await $(),t=await kt();return t?{hasUpdate:oe.gt(t,e),current:e,latest:t}:null}async function jt(e=!1){try{let t=j(`npm`,[`update`,`-g`,`novacode`],{stdio:e?`ignore`:`inherit`}),n=await new Promise((e,n)=>{t.on(`error`,n),t.on(`close`,t=>e(t??-1))});return n===0?(e||console.log(`✓ novacode updated to latest version successfully.`),!0):(e||(console.error(`Update failed (exit code ${n})`),process.exit(1)),!1)}catch(t){return e||(console.error(`Update failed: ${t.message}`),process.exit(1)),!1}}function Mt(){let{values:t,positionals:n}=e({options:{help:{type:`boolean`,short:`h`},version:{type:`boolean`,short:`v`},provider:{type:`string`},model:{type:`string`},"api-key":{type:`string`},sessions:{type:`string`,short:`s`},resume:{type:`boolean`,short:`r`},all:{type:`boolean`},restricted:{type:`boolean`},unrestricted:{type:`boolean`}},strict:!1,allowPositionals:!0});return{flags:t,args:n}}function Nt(e,t){return t?K(t,e):Ye(e)}async function Pt(){let e=Number(process.versions.node.split(`.`)[0]);(!e||e<24)&&(console.error(`novacode requires Node.js >= 24. You have ${process.version}.`),console.error(`Upgrade: https://nodejs.org/`),process.exit(1));let{flags:n,args:r}=Mt();if(n.version){let e=await $();console.log(`nova ${e}`),process.exit(0)}if(n.help&&(console.log(`nova — open-source coding agent
108
108
 
109
109
  Usage:
110
110
  nova Interactive mode
@@ -125,11 +125,11 @@ Options:
125
125
  -s, --sessions <id> Resume/manage sessions
126
126
  -r, --resume Resume the most recent session
127
127
  --restricted Start in restricted mode (approve every action)
128
- --unrestricted Start in unrestricted mode (no approvals)`),process.exit(0)),r[0]===`update`){await At();return}if(r[0]===`reset`){let{handleCliReset:e}=await import(`./reset-Bq0e9TIp.mjs`).then(e=>e.n);await e();return}r.length>0&&!n.sessions&&(console.error(t.yellow(`Unknown command: ${r.join(` `)}`)),console.error("Run `nova --help` for usage."),process.exit(1));let i=new AbortController,a=()=>{i.abort(),process.stderr.write(`
128
+ --unrestricted Start in unrestricted mode (no approvals)`),process.exit(0)),r[0]===`update`){await jt();return}if(r[0]===`reset`){let{handleCliReset:e}=await import(`./reset-Bq0e9TIp.mjs`).then(e=>e.n);await e();return}r.length>0&&!n.sessions&&(console.error(t.yellow(`Unknown command: ${r.join(` `)}`)),console.error("Run `nova --help` for usage."),process.exit(1));let i=new AbortController,a=()=>{i.abort(),process.stderr.write(`
129
129
  Aborted.
130
- `),process.exit(130)};process.on(`SIGINT`,a),process.on(`SIGTERM`,a);let o=await(await Pe()?Fe():nt()),s=await Ie(),c=await Ke();if(await c.prune(),n.sessions){let e=n.sessions;if(e===`ls`||e===`list`){let e=r[0]?parseInt(r[0],10):10;await Me(c,[`ls`],{limit:Number.isNaN(e)?10:e});return}if(e===`rm`||e===`delete`){let e=r[0],t=!!n.all;await Me(c,[`rm`,e??``],{all:t});return}}let l=null;n.resume?(l=await c.latest(),l||(console.error(`No recent session found to resume.`),process.exit(1))):n.sessions&&(l=await c.get(n.sessions),l||(console.error(`Session not found: ${n.sessions}`),process.exit(1)));let u=n.provider||l?.provider||o.provider,d=n.model||l?.model||o.model,f=n[`api-key`]||s.apiKeys[u],p=U(u);p||(console.error(`Unknown provider: ${u}`),console.error(`Available: ${N.map(e=>e.id).join(`, `)}`),process.exit(1)),f||(console.error(`No API key for ${p.name}. Set ${p.envKey} or run nova for onboarding.`),process.exit(1));let m=Mt(d,u);if(!m){console.error(`Unknown model: ${d}`),console.error(`Available models:`);for(let e of W(u))console.error(` ${e.id}`);process.exit(1)}let h=process.cwd(),g=await Pt(n);if(!g)return;let _=new ft(g,h),v=Et(h),{skills:y,agentsMd:b}=await Te(h),x=he(h,v,we(y),b??void 0);l||=await c.create(h,m.id,u);let S=l.id,ee=await c.messages(S),C=new me({provider:p.id,model:m,apiKey:f,system:x,tools:v,messages:ee,policy:_});process.off(`SIGINT`,a),process.off(`SIGTERM`,a);let{interactive:te}=await import(`./app-D8ECRVnz.mjs`);await te(C,c,S,y,!!b,_)}async function Pt(e){if(e.restricted)return`restricted`;if(e.unrestricted)return`unrestricted`;let n=await K(`Choose a permission mode`,[{value:`restricted`,label:`Restricted — ask permission before each action`},{value:`unrestricted`,label:`Unrestricted — run without approval (may be dangerous)`}],void 0,t.dim(`Use /permission to switch later, or --restricted/--unrestricted to skip this prompt.`));return n!==`restricted`&&n!==`unrestricted`?(console.log(t.dim(`Cancelled`)),null):n}function $(e,n){console.error(t.red(`\n✗ ${e}:`),n),console.error(t.yellow(`
130
+ `),process.exit(130)};process.on(`SIGINT`,a),process.on(`SIGTERM`,a);let o=await(await Ie()?Le():rt()),s=await Re(),c=await Je();if(await c.prune(),n.sessions){let e=n.sessions;if(e===`ls`||e===`list`){let e=r[0]?parseInt(r[0],10):10;await Pe(c,[`ls`],{limit:Number.isNaN(e)?10:e});return}if(e===`rm`||e===`delete`){let e=r[0],t=!!n.all;await Pe(c,[`rm`,e??``],{all:t});return}}let l=null;n.resume?(l=await c.latest(),l||(console.error(`No recent session found to resume.`),process.exit(1))):n.sessions&&(l=await c.get(n.sessions),l||(console.error(`Session not found: ${n.sessions}`),process.exit(1)));let u=n.provider||l?.provider||o.provider,d=n.model||l?.model||o.model,f=n[`api-key`]||s.apiKeys[u],p=W(u);p||(console.error(`Unknown provider: ${u}`),console.error(`Available: ${N.map(e=>e.id).join(`, `)}`),process.exit(1)),f||(console.error(`No API key for ${p.name}. Set ${p.envKey} or run nova for onboarding.`),process.exit(1));let m=Nt(d,u);if(!m){console.error(`Unknown model: ${d}`),console.error(`Available models:`);for(let e of G(u))console.error(` ${e.id}`);process.exit(1)}let h=process.cwd(),g=await Ft(n);if(!g)return;let _=new pt(g,h),v=Dt(h),{skills:y,agentsMd:b}=await De(h),x=me(h,v,Ee(y),b??void 0);l||=await c.create(h,m.id,u);let S=l.id,ee=await c.messages(S),C=new _e({provider:p.id,model:m,apiKey:f,system:x,tools:v,messages:ee,policy:_});process.off(`SIGINT`,a),process.off(`SIGTERM`,a);let{interactive:te}=await import(`./app-BKJfERuS.mjs`);await te(C,c,S,y,!!b,_)}async function Ft(e){if(e.restricted)return`restricted`;if(e.unrestricted)return`unrestricted`;let t=await q(`Choose a permission mode`,[{value:`restricted`,label:`Restricted — ask permission before each action`},{value:`unrestricted`,label:`Unrestricted — run without approval (may be dangerous)`}],void 0,`Use /permission to switch later, or --restricted/--unrestricted to skip this prompt.`);return t!==`restricted`&&t!==`unrestricted`?(console.log(`Cancelled`),null):t}function It(e,n){console.error(t.red(`\n✗ ${e}:`),n),console.error(t.yellow(`
131
131
  Nova hit an unexpected error and must exit.
132
132
  • Try starting `+t.bold.cyan(`nova`)+` again.
133
133
  • If it keeps failing, run `+t.bold.cyan(`nova reset`)+` — local data may be corrupted or out of date.
134
- `)),process.exit(1)}process.on(`unhandledRejection`,e=>{$(`Unhandled rejection`,e)}),process.on(`uncaughtException`,e=>{$(`Uncaught exception`,e)}),Nt().catch(e=>{$(`Fatal error`,e)});export{Oe as C,le as D,ce as E,N as O,ke as S,fe as T,Ie as _,Qe as a,Re as b,Ye as c,qe as d,W as f,Be as g,Ue as h,et as i,Je as l,He as m,Q as n,Ze as o,U as p,At as r,Xe as s,kt as t,G as u,Fe as v,Ce as w,Ae as x,ze as y};
134
+ `)),process.exit(1)}process.on(`unhandledRejection`,e=>{It(`Unhandled rejection`,e)}),process.on(`uncaughtException`,e=>{It(`Uncaught exception`,e)}),Pt().catch(e=>{It(`Fatal error`,e)});export{N as A,Ae as C,P as D,fe as E,ce as O,je as S,ge as T,Re as _,et as a,Be as b,Ze as c,Ye as d,G as f,He as g,Ge as h,tt as i,le as k,Xe as l,We as m,$ as n,$e as o,W as p,jt as r,Qe as s,At as t,K as u,Le as v,Te as w,Me as x,Ve as y};
135
135
  //# sourceMappingURL=main.mjs.map