vigthoria-cli 2.3.7 → 2.3.11
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/README.md +4 -2
- package/package.json +2 -2
- package/public-dist/index.mjs +120 -80
- package/public-dist/account.mjs +0 -38
- package/public-dist/agent.mjs +0 -48
- package/public-dist/api-keys.mjs +0 -14
- package/public-dist/catalog.mjs +0 -121
- package/public-dist/commands.mjs +0 -49
- package/public-dist/continuity.mjs +0 -12
- package/public-dist/deck-channel.mjs +0 -16
- package/public-dist/diagnostics.mjs +0 -8
- package/public-dist/local-tools.mjs +0 -28
- package/public-dist/preferences.mjs +0 -13
- package/public-dist/presentation.mjs +0 -17
- package/public-dist/providers.mjs +0 -111
- package/public-dist/repl-input.mjs +0 -146
- package/public-dist/repository.mjs +0 -14
- package/public-dist/session-state.mjs +0 -11
- package/public-dist/task-progress.mjs +0 -61
- package/public-dist/terminal.mjs +0 -133
- package/public-dist/update.mjs +0 -13
- package/public-dist/workflows.mjs +0 -12
- package/public-dist/workspace-tools.mjs +0 -83
- package/public-dist/workspace.mjs +0 -55
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
/* Copyright (c) 2026 Vigthoria Technologies. All rights reserved. Proprietary. */
|
|
2
|
-
import {request,hiddenInput,accessToken} from './account.mjs';
|
|
3
|
-
import {preferences,setPreference} from './preferences.mjs';
|
|
4
|
-
import {choose,safe} from './terminal.mjs';
|
|
5
|
-
import {section,detail,notice,modelName,providerModelChoices} from './presentation.mjs';
|
|
6
|
-
import {replInput} from './repl-input.mjs';
|
|
7
|
-
const base='/api/v3-agent-cli/providers';
|
|
8
|
-
const providers={openai:'OpenAI',anthropic:'Anthropic',openrouter:'OpenRouter'};
|
|
9
|
-
const keyId=id=>{if(!/^pkey_[a-f0-9]{32}$/.test(id||''))throw Error('Choose a saved provider key.');return id;};
|
|
10
|
-
const modelId=id=>{if(typeof id!=='string'||!/^[A-Za-z0-9][A-Za-z0-9._:/+\-]{0,199}$/.test(id))throw Error('Choose a model from provider models KEY_ID.');return id;};
|
|
11
|
-
const print=data=>console.log(JSON.stringify(data,null,2));
|
|
12
|
-
export function providerRoute(settings=preferences()){
|
|
13
|
-
if(!settings.providerEnabled)return null;
|
|
14
|
-
return {enabled:true,keyId:keyId(settings.providerKeyId),plannerModel:modelId(settings.providerPlannerModel),executorModel:modelId(settings.providerExecutorModel)};
|
|
15
|
-
}
|
|
16
|
-
export function routingLabel(settings){return settings.providerEnabled?'Your provider · Plan: '+modelName(settings.providerPlannerModel)+' · Code: '+modelName(settings.providerExecutorModel):null;}
|
|
17
|
-
function sync(session){if(session)for(const k of ['providerEnabled','providerKeyId','providerPlannerModel','providerExecutorModel'])session[k]=preferences()[k];}
|
|
18
|
-
export function disableProvider(session){setPreference('providerEnabled',false);sync(session);}
|
|
19
|
-
export async function useProvider(id,planner,executor,session){
|
|
20
|
-
keyId(id);modelId(planner);modelId(executor);
|
|
21
|
-
const data=await request(base+'/'+id+'/models');
|
|
22
|
-
if(!data.models.some(m=>m.id===planner)||!data.models.some(m=>m.id===executor))throw Error('Both models must be available to this provider key.');
|
|
23
|
-
setPreference('providerEnabled',false);
|
|
24
|
-
setPreference('providerKeyId',id);setPreference('providerPlannerModel',planner);setPreference('providerExecutorModel',executor);setPreference('providerEnabled',true);sync(session);
|
|
25
|
-
notice('success','Your provider is ready.');detail('Planning',modelName(planner));detail('Coding',modelName(executor));console.log('Generation is billed by your provider.');
|
|
26
|
-
}
|
|
27
|
-
async function readSecret(){
|
|
28
|
-
if(process.stdin.isTTY)return hiddenInput('Provider API key (hidden): ');
|
|
29
|
-
let value='';for await(const chunk of process.stdin){value+=chunk.toString('utf8');if(value.length>1024)throw Error('Provider key input is too large.');}return value.trim();
|
|
30
|
-
}
|
|
31
|
-
export async function addProvider(provider,label,read=readSecret){
|
|
32
|
-
if(!Object.hasOwn(providers,provider))throw Error('Choose openai, anthropic or openrouter.');
|
|
33
|
-
if(!accessToken())throw Error('Sign in to Vigthoria before connecting a provider key.');
|
|
34
|
-
if(typeof label!=='string'||!label.trim()||label.length>80||/[\x00-\x1f\x7f]/.test(label))throw Error('Use a key name of 1–80 characters.');
|
|
35
|
-
let secret=await read();
|
|
36
|
-
try{
|
|
37
|
-
const prefix=provider==='anthropic'?'sk-ant-':provider==='openrouter'?'sk-or-v1-':'sk-';
|
|
38
|
-
if(typeof secret!=='string'||!new RegExp('^'+prefix+'[A-Za-z0-9_-]+$').test(secret)||secret.length<20||secret.length>1024||(provider==='openai'&&/^sk-(ant-|or-)/.test(secret)))throw Error('The key format does not match '+providers[provider]+'. Use a provider key, not a Vigthoria CLI key.');
|
|
39
|
-
// Only this HTTPS request contains the key. No preference/session/workspace write.
|
|
40
|
-
return await request(base,{body:{provider,key:secret,label:label.trim(),storageConsent:true}});
|
|
41
|
-
}finally{secret='';}
|
|
42
|
-
}
|
|
43
|
-
async function selectSaved(lines,theme){
|
|
44
|
-
const data=await request(base);
|
|
45
|
-
if(!data.keys.length){console.log('No provider keys connected. Choose Add a provider key first.');return null;}
|
|
46
|
-
return choose(lines,'Choose a provider key',data.keys.map(k=>({value:k.id,label:safe(k.label)+' · '+safe(providers[k.provider]||k.provider)+' · '+safe(k.maskedKey),description:String(k.modelCount||0)+' models found · key stored encrypted'})),preferences().providerKeyId,theme);
|
|
47
|
-
}
|
|
48
|
-
async function configureModels(lines,id,theme,session){
|
|
49
|
-
const data=await request(base+'/'+keyId(id)+'/models'),rows=providerModelChoices(data.models);
|
|
50
|
-
section('Choose your AI team','Planning decides the steps. Coding writes and reviews the code. The same model can do both.',theme);
|
|
51
|
-
const planner=await choose(lines,'Choose the planning model',rows,preferences().providerPlannerModel,theme);if(planner===null)return;
|
|
52
|
-
const executor=await choose(lines,'Choose the coding model',rows,preferences().providerExecutorModel||planner,theme);if(executor===null)return;
|
|
53
|
-
await useProvider(id,planner,executor,session);
|
|
54
|
-
}
|
|
55
|
-
export async function providerMenu(lines,theme='cyan',session){
|
|
56
|
-
while(true){
|
|
57
|
-
section('Provider API keys','Connect OpenAI, Anthropic or OpenRouter. Keys stay encrypted in your Vigthoria account vault.',theme);
|
|
58
|
-
console.log(routingLabel(preferences())||'Current route: Vigthoria account models');
|
|
59
|
-
const action=await choose(lines,'Choose a provider action',[
|
|
60
|
-
{value:'add',label:'Add a provider key',description:'Paste privately, validate access, then choose planning and coding models.'},
|
|
61
|
-
{value:'use',label:'Choose key & models',description:'Enable your own provider for agent and background coding tasks.'},
|
|
62
|
-
{value:'list',label:'List connected provider keys',description:'Show masked metadata only.'},
|
|
63
|
-
{value:'test',label:'Test a provider connection',description:'Check key access and model availability. No generation.'},
|
|
64
|
-
{value:'usage',label:'View provider request history',description:'See confirmed, rejected or uncertain calls. Provider billing remains authoritative.'},
|
|
65
|
-
{value:'off',label:'Use Vigthoria account models',description:'Disable your own provider route on this machine.'},
|
|
66
|
-
{value:'remove',label:'Remove a saved provider key',description:'Remove the encrypted key from your Vigthoria vault. Revoke at the provider to invalidate it.'},
|
|
67
|
-
{value:'back',label:'Back',description:'Return to Account & API.'},
|
|
68
|
-
],'add',theme);if(action===null||action==='back')return;
|
|
69
|
-
try{
|
|
70
|
-
if(action==='add'){
|
|
71
|
-
const provider=await choose(lines,'Choose the key provider',Object.entries(providers).map(([value,label])=>({value,label,description:'Use an API key issued by '+label+'.'})),'openai',theme);if(provider===null)continue;
|
|
72
|
-
const a=await lines.next('Key name (for example My OpenAI account): ');if(a.done||a.cancelled)continue;
|
|
73
|
-
const consent=await choose(lines,'Save this key encrypted in your Vigthoria account vault?',[{value:false,label:'Cancel',description:'Return without entering a key.'},{value:true,label:'Continue to hidden key entry',description:'The key travels over HTTPS to Vigthoria and is encrypted at rest. Your provider bills generation.'}],false,theme);if(consent!==true)continue;
|
|
74
|
-
// The picker has suspended its line reader before hidden input starts.
|
|
75
|
-
const data=await addProvider(provider,a.value.trim());notice('success',providers[provider]+' connected',theme);detail('Saved key',data.key.label+' · '+data.key.maskedKey,theme);detail('Available models',String(data.key.modelCount),theme);notice('info','Connection verified. No generation started.',theme);
|
|
76
|
-
await configureModels(lines,data.key.id,theme,session);
|
|
77
|
-
}else if(action==='list'){const data=await request(base);if(!data.keys.length)notice('info','No provider keys connected.',theme);for(const k of data.keys)detail(providers[k.provider]||k.provider,k.label+' · '+k.maskedKey,theme);}
|
|
78
|
-
else if(action==='usage')print(await request(base+'/usage'));
|
|
79
|
-
else if(action==='off'){disableProvider(session);console.log('Vigthoria account routing selected.');}
|
|
80
|
-
else{
|
|
81
|
-
const id=await selectSaved(lines,theme);if(id===null)continue;
|
|
82
|
-
if(action==='use')await configureModels(lines,id,theme,session);
|
|
83
|
-
else if(action==='test'){const data=await request(base+'/'+id+'/test',{body:{}});notice('success','Connection verified · '+data.modelCount+' models · no generation started.',theme);}
|
|
84
|
-
else if(action==='remove'){
|
|
85
|
-
const yes=await choose(lines,'Remove this saved key from the Vigthoria vault?',[{value:false,label:'Keep key'},{value:true,label:'Remove key'}],false,theme);if(yes!==true)continue;
|
|
86
|
-
await request(base+'/'+id,{method:'DELETE'});notice('success','Saved provider key removed.',theme);if(preferences().providerKeyId===id)disableProvider(session);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}catch(e){notice('error','Provider action failed: '+safe(e.message),theme);}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
export async function providerCommand(argv=[]){
|
|
93
|
-
const [action,...args]=argv;
|
|
94
|
-
if(!action||action==='setup'){
|
|
95
|
-
if(args.length||!process.stdin.isTTY||!process.stdout.isTTY)throw Error('Use provider setup in a terminal. See provider --help for automation.');
|
|
96
|
-
const lines=replInput();try{await providerMenu(lines,preferences().theme);}finally{lines.close();}return;
|
|
97
|
-
}
|
|
98
|
-
if(action==='list'&&!args.length)return print(await request(base));
|
|
99
|
-
if(action==='usage'&&!args.length)return print(await request(base+'/usage'));
|
|
100
|
-
if(action==='off'&&!args.length){disableProvider();console.log('Vigthoria account routing selected.');return;}
|
|
101
|
-
if(action==='add'){
|
|
102
|
-
if(!Object.hasOwn(providers,args[0])||args.length!==4||args[1]!=='--name'||args[3]!=='--accept-encrypted-storage')throw Error('Use provider add PROVIDER --name NAME --accept-encrypted-storage; supply the key only through hidden input or private stdin.');
|
|
103
|
-
return print(await addProvider(args[0],args[2]));
|
|
104
|
-
}
|
|
105
|
-
if(['test','models'].includes(action)&&args.length===1)return print(await request(base+'/'+keyId(args[0])+(action==='test'?'/test':'/models'),action==='test'?{body:{}}:{}));
|
|
106
|
-
if(action==='use'&&args.length===5&&args[1]==='--planner'&&args[3]==='--executor')return useProvider(args[0],args[2],args[4]);
|
|
107
|
-
if(action==='remove'&&args.length===2&&args[1]==='--yes'){
|
|
108
|
-
const id=keyId(args[0]);print(await request(base+'/'+id,{method:'DELETE'}));if(preferences().providerKeyId===id)disableProvider();return;
|
|
109
|
-
}
|
|
110
|
-
throw Error('Use provider setup, add, list, test, models, use, off, remove or usage. Keys are never accepted as command arguments.');
|
|
111
|
-
}
|
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
/* Copyright (c) 2026 Vigthoria Technologies. All rights reserved. Proprietary. */
|
|
2
|
-
import {createInterface} from 'node:readline';
|
|
3
|
-
import {PassThrough} from 'node:stream';
|
|
4
|
-
import {StringDecoder} from 'node:string_decoder';
|
|
5
|
-
const clean=s=>String(s??'').replace(/[\x00-\x1f\x7f-\x9f]/g,'');
|
|
6
|
-
|
|
7
|
-
// One consumer owns stdin: line editing for chat, bounded key selection for
|
|
8
|
-
// menus. A menu closes its temporary reader before any credential prompt.
|
|
9
|
-
export function replInput(input=process.stdin, output=process.stdout, cancel=()=>{}) {
|
|
10
|
-
let rl=null,waiting=null,selecting=null,closed=false,prompted=false,bytes=0,cancelled=false,busy=false,warned=false,suspending=false,releaseInput=null;
|
|
11
|
-
const queue=[];
|
|
12
|
-
function reader(){
|
|
13
|
-
if(rl)return rl;
|
|
14
|
-
// readline treats every pasted newline as Enter. Filter bracketed paste
|
|
15
|
-
// before its key decoder, preserving the whole brief until a real Enter.
|
|
16
|
-
// The bridge is removed before menus or private credential entry take stdin.
|
|
17
|
-
let source=input;
|
|
18
|
-
if(input.isTTY&&typeof input.setRawMode==='function'){
|
|
19
|
-
const bridge=new PassThrough(),decoder=new StringDecoder('utf8');
|
|
20
|
-
const start='\x1b[200~',end='\x1b[201~';let pending='',paste=null,timer=null,overflow=false;
|
|
21
|
-
bridge.isTTY=true;bridge.setRawMode=value=>input.setRawMode(value);
|
|
22
|
-
const warnBusy=()=>{if(!warned){output.write('\r\nAn agent request is already running. Wait for vigthoria> before sending another prompt, or press Ctrl+C to cancel.\r\n');warned=true;}};
|
|
23
|
-
function insert(value){
|
|
24
|
-
if(busy&&!waiting){warnBusy();return;}
|
|
25
|
-
value=value.replace(/\r\n?/g,'\n').replace(/[\x00-\x08\x0b-\x1f\x7f-\x9f]/g,'');
|
|
26
|
-
if(overflow||(rl.line||'').length+value.length>50000){output.write('\r\nPaste is too large. Send a brief of at most 50,000 characters.\r\n');return;}
|
|
27
|
-
const cursor=rl.cursor||0,line=rl.line||'';
|
|
28
|
-
rl.line=line.slice(0,cursor)+value+line.slice(cursor);rl.cursor=cursor+value.length;rl.prompt(true);
|
|
29
|
-
}
|
|
30
|
-
function forward(value){
|
|
31
|
-
if(busy&&!waiting){if(value.includes('\x03'))bridge.write('\x03');else if(value)warnBusy();return;}
|
|
32
|
-
const normalized=value.replace(/\r\n?/g,'\n');
|
|
33
|
-
if(/\n[\s\S]/.test(normalized))insert(normalized);
|
|
34
|
-
else if(value)bridge.write(value);
|
|
35
|
-
}
|
|
36
|
-
const suffix=(text,marker)=>{for(let n=Math.min(text.length,marker.length-1);n>0;n--)if(text.endsWith(marker.slice(0,n)))return n;return 0;};
|
|
37
|
-
function consume(){
|
|
38
|
-
clearTimeout(timer);
|
|
39
|
-
while(pending){
|
|
40
|
-
const marker=paste===null?start:end,index=pending.indexOf(marker);
|
|
41
|
-
if(index>=0){
|
|
42
|
-
const value=pending.slice(0,index);pending=pending.slice(index+marker.length);
|
|
43
|
-
if(paste===null){forward(value);paste='';overflow=false;}
|
|
44
|
-
else{if(paste.length+value.length>50000)overflow=true;if(!overflow)paste+=value;insert(paste);paste=null;overflow=false;}
|
|
45
|
-
continue;
|
|
46
|
-
}
|
|
47
|
-
const keep=suffix(pending,marker),value=pending.slice(0,pending.length-keep);pending=pending.slice(pending.length-keep);
|
|
48
|
-
if(paste===null)forward(value);
|
|
49
|
-
else if(paste.length+value.length>50000)overflow=true;
|
|
50
|
-
else if(!overflow)paste+=value;
|
|
51
|
-
if(paste===null&&pending)timer=setTimeout(()=>{const value=pending;pending='';forward(value);},80);
|
|
52
|
-
break;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
const data=chunk=>{pending+=decoder.write(Buffer.isBuffer(chunk)?chunk:Buffer.from(chunk));consume();};
|
|
56
|
-
const finish=()=>{pending+=decoder.end();consume();if(paste!==null){rl.line='';rl.cursor=0;output.write('\r\nIncomplete paste cancelled.\r\n');}bridge.end();};
|
|
57
|
-
const resume=()=>input.resume(),pause=()=>input.pause();
|
|
58
|
-
bridge.on('resume',resume);bridge.on('pause',pause);input.on('data',data);input.once('end',finish);
|
|
59
|
-
output.write('\x1b[?2004h');source=bridge;
|
|
60
|
-
releaseInput=()=>{clearTimeout(timer);input.off('data',data);input.off('end',finish);bridge.off('resume',resume);bridge.off('pause',pause);bridge.destroy();output.write('\x1b[?2004l');releaseInput=null;};
|
|
61
|
-
}
|
|
62
|
-
rl=createInterface({input:source,output,terminal:Boolean(input.isTTY),crlfDelay:Infinity,prompt:''});
|
|
63
|
-
rl.on('line',value=>{
|
|
64
|
-
prompted=false;rl.setPrompt('');
|
|
65
|
-
if(busy&&!waiting){if(!warned){output.write('\r\nAn agent request is already running. Wait for vigthoria> before sending another prompt, or press Ctrl+C to cancel.\r\n');warned=true;}return;}
|
|
66
|
-
if(waiting){const resolve=waiting;waiting=null;resolve({value,done:false});}
|
|
67
|
-
else if(bytes+value.length<=1000000){queue.push(value);bytes+=value.length;}
|
|
68
|
-
else{queue.length=0;bytes=0;output.write('\r\nInput buffer is full. Resend a shorter brief.\r\n');}
|
|
69
|
-
});
|
|
70
|
-
rl.on('close',()=>{releaseInput?.();if(suspending)return;closed=true;if(waiting){waiting({done:true});waiting=null;}});
|
|
71
|
-
rl.on('SIGINT',()=>{
|
|
72
|
-
cancel();prompted=false;rl.setPrompt('');rl.clearLine(0);queue.length=0;bytes=0;cancelled=true;
|
|
73
|
-
output.write('\r\nCancelled current input/request. Use /exit to close the agent.\r\n');
|
|
74
|
-
if(waiting){const resolve=waiting;waiting=null;cancelled=false;resolve({value:'',done:false,cancelled:true});}
|
|
75
|
-
});
|
|
76
|
-
return rl;
|
|
77
|
-
}
|
|
78
|
-
function suspend(){if(rl){suspending=true;rl.close();rl=null;suspending=false;}prompted=false;}
|
|
79
|
-
function show(prompt='vigthoria> '){if(!closed&&!prompted){prompted=true;output.write('\r\n');reader().setPrompt(prompt);rl.prompt(true);}}
|
|
80
|
-
return {
|
|
81
|
-
setBusy(value){busy=value;warned=false;if(value){queue.length=0;bytes=0;}},
|
|
82
|
-
next(primary=false){
|
|
83
|
-
if(selecting||waiting)throw Error('Concurrent terminal input readers are not permitted');
|
|
84
|
-
if(cancelled){cancelled=false;return Promise.resolve({value:'',done:false,cancelled:true});}
|
|
85
|
-
if(queue.length){const value=queue.shift();bytes-=value.length;return Promise.resolve({value,done:false});}
|
|
86
|
-
if(closed)return Promise.resolve({done:true});
|
|
87
|
-
reader();input.resume();if(primary)show(typeof primary==='string'?primary:'vigthoria> ');else rl.setPrompt('');
|
|
88
|
-
return new Promise(resolve=>{waiting=resolve;});
|
|
89
|
-
},
|
|
90
|
-
async select({message,choices,defaultValue,accent=36,plain=false}){
|
|
91
|
-
if(waiting||selecting)throw Error('Concurrent terminal input readers are not permitted');
|
|
92
|
-
if(closed)return null;
|
|
93
|
-
if(!choices.length||choices.every(c=>c.disabled))throw Error('Menu has no available choices');
|
|
94
|
-
// Non-TTY fallback stays line based; useful for accessible input and tests.
|
|
95
|
-
if(!input.isTTY||!output.isTTY||typeof input.setRawMode!=='function'){
|
|
96
|
-
output.write('\n'+clean(message)+'\n');choices.forEach((c,i)=>output.write(` ${i+1} ${clean(c.label)}${c.disabled?' (unavailable)':''}\n`));
|
|
97
|
-
while(true){const a=await this.next('? Number, or 0 to go back: ');if(a.done||a.cancelled||a.value.trim()==='0')return null;const c=choices[Number(a.value)-1];if(c&&!c.disabled)return c.value;output.write('Choose an available number.\n');}
|
|
98
|
-
}
|
|
99
|
-
suspend();
|
|
100
|
-
let index=choices.findIndex(c=>c.value===defaultValue&&!c.disabled);if(index<0)index=choices.findIndex(c=>!c.disabled);
|
|
101
|
-
const width=Math.max(20,Number(output.columns)||80),page=Math.max(3,Math.min(8,(Number(output.rows)||24)-8));
|
|
102
|
-
const fit=s=>{s=clean(s);return s.length>width-2?s.slice(0,width-3)+'…':s;};
|
|
103
|
-
const colour=(s,code)=>!plain&&!Object.hasOwn(process.env,'NO_COLOR')&&process.env.TERM!=='dumb'?'\x1b['+code+'m'+s+'\x1b[0m':s;
|
|
104
|
-
let rendered=0,digits='',pending='',escapeTimer=null;
|
|
105
|
-
function render(){
|
|
106
|
-
if(rendered)output.write('\x1b['+rendered+'A\r');
|
|
107
|
-
const start=Math.max(0,Math.min(index-Math.floor(page/2),choices.length-page));
|
|
108
|
-
const lines=[colour(fit(message),'1;97')];
|
|
109
|
-
for(let i=start;i<Math.min(choices.length,start+page);i++){
|
|
110
|
-
const c=choices[i],text=fit(`${i===index?'›':' '} ${String(i+1).padStart(2)} ${c.label}${c.disabled?' (unavailable)':''}`);
|
|
111
|
-
lines.push(colour(text,c.disabled?'90':i===index?(accent===35?'1;97;48;5;54':'1;97;48;5;24'):'37'));
|
|
112
|
-
}
|
|
113
|
-
lines.push(colour(fit(choices[index].description||''),'90'));
|
|
114
|
-
lines.push(colour(fit(`↑/↓ move · Enter select · Esc back${choices.length>page?' · '+(index+1)+'/'+choices.length:''}`),'90'));
|
|
115
|
-
lines.push(fit(digits?'Number: '+digits:'Or type a number and press Enter.'));
|
|
116
|
-
output.write(lines.map(s=>'\x1b[2K'+s+'\r\n').join(''));rendered=lines.length;
|
|
117
|
-
}
|
|
118
|
-
return await new Promise(resolve=>{
|
|
119
|
-
let finished=false;
|
|
120
|
-
const rawBefore=Boolean(input.isRaw);
|
|
121
|
-
function finish(value){if(finished)return;finished=true;clearTimeout(escapeTimer);input.off('data',data);input.off('end',end);input.setRawMode(rawBefore);input.pause();selecting=null;output.write('\x1b[?25h');resolve(value);}
|
|
122
|
-
const end=()=>{closed=true;finish(null);};
|
|
123
|
-
function step(direction){digits='';for(let n=0;n<choices.length;n++){index=(index+direction+choices.length)%choices.length;if(!choices[index].disabled)break;}render();}
|
|
124
|
-
function data(chunk){
|
|
125
|
-
pending+=chunk.toString('utf8');if(pending.length>256){pending='';return;}
|
|
126
|
-
clearTimeout(escapeTimer);
|
|
127
|
-
while(pending){
|
|
128
|
-
const sequence=pending.match(/^\x1b\[(?:\d+;?)*[A-Za-z~]/)?.[0];
|
|
129
|
-
if(sequence){pending=pending.slice(sequence.length);if(sequence==='\x1b[A')step(-1);else if(sequence==='\x1b[B')step(1);else if(sequence==='\x1b[5~')for(let j=0;j<page;j++)step(-1);else if(sequence==='\x1b[6~')for(let j=0;j<page;j++)step(1);continue;}
|
|
130
|
-
if(pending[0]==='\x1b'){if(pending==='\x1b'||/^\x1b\[[\d;]*$/.test(pending)){escapeTimer=setTimeout(()=>finish(null),80);return;}finish(null);return;}
|
|
131
|
-
const ch=pending[0];pending=pending.slice(1);
|
|
132
|
-
if(ch==='\x03'||ch==='\x04'){finish(null);return;}
|
|
133
|
-
if(ch==='\r'||ch==='\n'){
|
|
134
|
-
if(digits){const candidate=Number(digits)-1;if(!choices[candidate]||choices[candidate].disabled){digits='';render();continue;}index=candidate;}
|
|
135
|
-
finish(choices[index].value);return;
|
|
136
|
-
}
|
|
137
|
-
if(/[0-9]/.test(ch)){digits=(digits+ch).slice(-3);render();}
|
|
138
|
-
else if(ch==='\x7f'||ch==='\b'){digits=digits.slice(0,-1);render();}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
selecting=finish;input.on('data',data);input.once('end',end);input.setRawMode(true);output.write('\n\x1b[?25l');render();input.resume();
|
|
142
|
-
});
|
|
143
|
-
},
|
|
144
|
-
close(){if(selecting)selecting(null);closed=true;if(rl)rl.close();},
|
|
145
|
-
};
|
|
146
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/* Copyright (c) 2026 Vigthoria Technologies. All rights reserved. Proprietary. */
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import fs from 'node:fs';
|
|
4
|
-
import {randomUUID} from 'node:crypto';
|
|
5
|
-
import {request} from './account.mjs';
|
|
6
|
-
import {snapshot,applyFiles} from './workspace.mjs';
|
|
7
|
-
export async function repository(argv){const[action,...args]=argv;const list=()=>request('/api/community-repo/my-repos');if(action==='list'){console.log(JSON.stringify(await list(),null,2));return;}
|
|
8
|
-
if(action==='status'){console.log(JSON.stringify(await request('/api/repo/status/'+encodeURIComponent(path.basename(process.cwd()))),null,2));return;}
|
|
9
|
-
if(action==='push'){const snap=snapshot(args[0]&&!args[0].startsWith('-')?args[0]:process.cwd(),{binary:true,portablePlans:true});if(snap.excluded.length)throw Error('Repository push excludes oversized or credential-bearing files; review these files before pushing: '+snap.excluded.slice(0,10).join(', '));const option=(name,fallback)=>args.includes(name)?args[args.indexOf(name)+1]:fallback;const visibility=option('--visibility','private');if(!['private','restricted','public'].includes(visibility))throw Error('Invalid repository visibility');if(args.includes('--id')&&!/^[1-9][0-9]*$/.test(option('--id','')))throw Error('Invalid repository ID');if(!args.includes('--yes'))throw Error('Repository publication requires explicit --yes authorization');const data=await request('/api/community-repo/push',{signal:AbortSignal.timeout(120000),body:{operationId:randomUUID(),projectName:option('--name',path.basename(snap.root)),description:'',techStack:'',visibility,files:Object.entries(snap.files).map(([name,content])=>({path:name,content:Buffer.isBuffer(content)?content.toString('base64'):content,encoding:Buffer.isBuffer(content)?'base64':'utf8',size:Buffer.byteLength(content)})),...(option('--id',null)?{projectId:Number(option('--id',null))}:{}),clientSource:'community-cli',commitMessage:option('--message','Vigthoria CLI project snapshot')}});console.log(JSON.stringify(data,null,2));return;}
|
|
10
|
-
if(action==='review'){const review=args[0]&&!args[0].startsWith('-')?args[0]:null;if(review&&!/^[A-Za-z0-9._:-]{1,128}$/.test(review))throw Error('Invalid review id');console.log(JSON.stringify(await request('/api/community-repo/security-reviews'+(review?'/'+encodeURIComponent(review):'?mine=true')),null,2));return;}
|
|
11
|
-
if(action==='share'){if(!args[0]||!args.includes('--yes'))throw Error('Use repo share NAME --yes after reviewing the sharing destination');const expires=args.includes('--expires')?args[args.indexOf('--expires')+1]:'7d';console.log(JSON.stringify(await request('/api/community-repo/share',{body:{operationId:randomUUID(),projectName:args[0],expiresIn:expires}}),null,2));return;}
|
|
12
|
-
if(action==='delete'){if(!args[0]||!args.includes('--yes'))throw Error('Use repo delete NAME_OR_ID --yes');const data=await list(),repos=data.repos||data.projects||data.repositories||[];const match=repos.find(r=>[r.name,r.project_name,r.id].some(v=>String(v)===args[0]));if(!match)throw Error('Owned repository not found');console.log(JSON.stringify(await request('/api/community-repo/projects/'+encodeURIComponent(match.id),{method:'DELETE'}),null,2));return;}
|
|
13
|
-
if(action==='pull'){const name=args[0];if(!name)throw Error('Repository name is required');const data=await list();const repos=data.repos||data.projects||data.repositories||[];const match=repos.find(r=>[r.name,r.project_name,r.id].some(x=>String(x)===name));if(!match)throw Error('Repository not found');const result=await request('/api/community-repo/pull',{body:{projectId:match.id}});if(result.inlineComplete===false)throw Error('This repository requires the complete ZIP archive. Download it from Community; no partial files were written.');const target=args.includes('--output')?args[args.indexOf('--output')+1]:process.cwd();if(!target)throw Error('--output requires a directory');fs.mkdirSync(target,{recursive:true,mode:0o700});const snap=snapshot(target,{binary:true,portablePlans:true});const files=result.files||result.project?.files;if(!Array.isArray(files))throw Error('Repository response is not a supported complete file set');const map=Object.create(null);for(const f of files){if(!['utf8','base64',undefined].includes(f.encoding)||typeof f.path!=='string'||typeof f.content!=='string')throw Error('Invalid repository file');if(Object.hasOwn(map,f.path)||Object.hasOwn(snap.files,f.path))throw Error('Repository pull refuses duplicate paths or existing files');let content=f.content;if(f.encoding==='base64'){if(!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(content))throw Error('Invalid binary encoding');content=Buffer.from(content,'base64');}map[f.path]=content;}applyFiles(snap,map,{portablePlans:true});console.log(`Restored ${Object.keys(map).length} files without overwriting existing files.`);return;}
|
|
14
|
-
throw Error('Use repo list, status, push, pull, review, share or delete.');}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import {configDirectory} from './account.mjs';
|
|
2
|
-
/* Copyright (c) 2026 Vigthoria Technologies. All rights reserved. Proprietary. */
|
|
3
|
-
import fs from 'node:fs';
|
|
4
|
-
import os from 'node:os';
|
|
5
|
-
import path from 'node:path';
|
|
6
|
-
import {randomUUID} from 'node:crypto';
|
|
7
|
-
const directory=()=>path.join(configDirectory(),'cli-sessions');
|
|
8
|
-
const filename=id=>{if(!/^[a-f0-9-]{36}$/.test(id))throw Error('Invalid local session id');return path.join(directory(),id+'.json');};
|
|
9
|
-
export function saveSession(data){const dir=directory();fs.mkdirSync(dir,{recursive:true,mode:0o700});const file=filename(data.id);if(!fs.existsSync(file)&&fs.readdirSync(dir).filter(n=>n.endsWith('.json')).length>=100)throw Error('100 local sessions retained; remove selected sessions before saving more');const raw=JSON.stringify({...data,savedAt:new Date().toISOString()});if(Buffer.byteLength(raw)>256000)throw Error('Session exceeds local save limit; use /compact or start a new session');const temp=file+'.'+randomUUID()+'.tmp';fs.writeFileSync(temp,raw,{flag:'wx',mode:0o600});fs.renameSync(temp,file);}
|
|
10
|
-
export function loadSession(id){const raw=fs.readFileSync(filename(id),'utf8');if(Buffer.byteLength(raw)>256000)throw Error('Saved session exceeds limit');const d=JSON.parse(raw);if(d.id!==id||!Array.isArray(d.history)||typeof d.root!=='string')throw Error('Invalid saved session');return d;}
|
|
11
|
-
export function listSessions(){try{return fs.readdirSync(directory()).filter(n=>/^[a-f0-9-]{36}\.json$/.test(n)).map(n=>{const s=loadSession(n.slice(0,-5));return{id:s.id,workspace:s.root,model:s.model,savedAt:s.savedAt,messages:s.history.length};}).sort((a,b)=>b.savedAt.localeCompare(a.savedAt));}catch(e){if(e.code==='ENOENT')return[];throw e;}}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
/* Copyright (c) 2026 Vigthoria Technologies. All rights reserved. Proprietary. */
|
|
2
|
-
// Display only: task authority and acceptance remain on Vigthoria services.
|
|
3
|
-
import {paint} from './presentation.mjs';
|
|
4
|
-
const clean=value=>String(value??'').replace(/\x1b\[[0-?]*[ -/]*[@-~]/g,'').replace(/[\x00-\x1f\x7f-\x9f\u202a-\u202e\u2066-\u2069]/g,' ').replace(/\s+/g,' ').trim();
|
|
5
|
-
const width=value=>[...value].reduce((n,c)=>n+(/\p{Mark}/u.test(c)||c==='\u200d'?0:/\p{Emoji_Presentation}/u.test(c)||/[\u1100-\u115f\u2e80-\ua4cf\uac00-\ud7a3\uf900-\ufaff\uff01-\uff60]/u.test(c)?2:1),0);
|
|
6
|
-
function fit(value,columns){let result='',used=0;const text=' '.repeat(String(value).match(/^ */)?.[0].length||0)+clean(value);for(const c of text){const size=width(c);if(used+size>columns-1)return result+'…';result+=c;used+=size;}return result;}
|
|
7
|
-
const frames=['⠋','⠙','⠹','⠸','⠼','⠴','⠦','⠧','⠇','⠏'];
|
|
8
|
-
export function taskProgress({output=process.stdout,errorOutput=process.stderr,theme='cyan',now=Date.now,schedule=fn=>setInterval(fn,120),unschedule=clearInterval,enabled}={}){
|
|
9
|
-
enabled??=Boolean(output.isTTY&&theme!=='plain'&&!Object.hasOwn(process.env,'NO_COLOR')&&process.env.TERM!=='dumb'&&process.env.VIGTHORIA_DECK_MODE!=='1');
|
|
10
|
-
const tasks=new Map(),writers=new Map();let running=false,paused=false,mode='working',phase='Understanding your request',current=null,started=0,timer=null,frame=0,rendered=0,lastLines=[],partial=false;
|
|
11
|
-
const write=(...args)=>writers.get(output).apply(output,args);
|
|
12
|
-
function clear(){if(!rendered)return;write('\x1b['+rendered+'A\r\x1b[0J');rendered=0;}
|
|
13
|
-
function view(){
|
|
14
|
-
const list=[...tasks.values()],done=list.filter(t=>t.status==='completed').length,total=list.length;
|
|
15
|
-
const active=list.filter(t=>t.status==='in_progress'),index=current?list.findIndex(t=>t.id===current.id):-1;
|
|
16
|
-
const ordinal=mode==='success'?total:index>=0?index+1:Math.min(done+1,total);
|
|
17
|
-
const label=mode==='success'?'Complete':mode==='cancelled'?'Cancelled':mode==='failed'?'Needs attention':active.length>1?'Working · '+active.length+' tasks':'Working';
|
|
18
|
-
const seconds=Math.max(0,Math.floor((now()-started)/1000)),elapsed=String(Math.floor(seconds/60)).padStart(2,'0')+':'+String(seconds%60).padStart(2,'0');
|
|
19
|
-
const columns=Math.max(8,(Number(output.columns)||80)-2),barSize=Math.max(4,Math.min(18,columns-31)),filled=total?Math.floor(done/total*barSize):0;
|
|
20
|
-
const symbol=mode==='success'?'✓':mode==='failed'?'!':mode==='cancelled'?'■':frames[frame++%frames.length];
|
|
21
|
-
const title=mode==='success'?(total?'All planned tasks completed':'Request completed'):(current?.title||phase).replace(/^Apply evidence-grounded repair to /i,'Repair ');
|
|
22
|
-
const header=fit(' '+symbol+' '+(total?'TASK PLAN':'AGENT STATUS')+(total?' '+ordinal+'/'+total:'')+' · '+label+' '+elapsed,columns);
|
|
23
|
-
const subtitle=fit(' '+title,columns);
|
|
24
|
-
const tail=fit(' '+(total?(columns>39?'━'.repeat(filled)+'─'.repeat(barSize-filled)+' ':'')+done+' complete · '+(total-done)+' remaining':mode==='success'?'Ready for your next request':mode==='cancelled'?'Your request was stopped':'Your agent is preparing the next step'),columns);
|
|
25
|
-
return {lines:[header,subtitle,tail],done,total,ordinal,title,label};
|
|
26
|
-
}
|
|
27
|
-
function draw(){if(!enabled||!running||paused||partial)return;clear();const v=view();lastLines=v.lines;const tone=mode==='failed'?'warning':mode==='success'?'success':'accent';write(v.lines.map((line,i)=>'\x1b[2K'+paint(line,i===0?tone:i===1?'title':'muted',theme,output)+'\r\n').join(''));rendered=v.lines.length;}
|
|
28
|
-
function intercept(stream){if(!stream||writers.has(stream))return;const original=stream.write;writers.set(stream,original);stream.write=function(chunk,encoding,callback){
|
|
29
|
-
if(!running||paused)return original.apply(this,arguments);
|
|
30
|
-
clear();let result;try{result=original.apply(this,arguments);}finally{
|
|
31
|
-
const text=Buffer.isBuffer(chunk)?chunk.toString('utf8'):String(chunk??'');if(text)partial=!/[\r\n]$/.test(text);draw();
|
|
32
|
-
}return result;
|
|
33
|
-
};}
|
|
34
|
-
function resize(){if(rendered){const cols=Math.max(1,Number(output.columns)||80);rendered=lastLines.reduce((n,line)=>n+Math.max(1,Math.ceil(width(line)/cols)),0);}draw();}
|
|
35
|
-
function restore(){if(!enabled)return;try{if(writers.has(output))write('\x1b[?25h');}catch{}for(const [stream,original]of writers)stream.write=original;writers.clear();output.off?.('resize',resize);process.removeListener('exit',restore);}
|
|
36
|
-
const api={
|
|
37
|
-
start(){if(running)return;running=true;started=now();if(!enabled)return;intercept(output);intercept(errorOutput);output.on?.('resize',resize);process.once('exit',restore);write('\x1b[?25l');draw();timer=schedule(draw);timer?.unref?.();},
|
|
38
|
-
update(event){
|
|
39
|
-
if(event.type==='plan'&&event.plan?.mode==='planner-executor'&&Array.isArray(event.plan.tasks)){
|
|
40
|
-
const next=new Map();for(const t of event.plan.tasks.slice(0,5000)){if(typeof t.id!=='string'||!t.id)continue;next.set(t.id,{id:t.id,title:clean(t.title||'Planned task'),status:tasks.get(t.id)?.status||'pending'});}tasks.clear();for(const [id,t]of next)tasks.set(id,t);
|
|
41
|
-
}
|
|
42
|
-
if(event.type==='pipeline_stage')phase=({dispatcher:'Understanding your request',architect:'Preparing your plan',executor:'Working on your project'})[event.stage]||phase;
|
|
43
|
-
if(event.type==='executor_start'&&typeof event.task_id==='string'){
|
|
44
|
-
current=tasks.get(event.task_id)||{id:event.task_id,title:clean(event.title||'Working on the next task'),status:'pending'};current.status='in_progress';mode='working';
|
|
45
|
-
}
|
|
46
|
-
if(event.type==='executor_complete'&&event.summary?.status==='failed')mode='failed';
|
|
47
|
-
if(event.type==='task_progress'&&Array.isArray(event.tasks)){
|
|
48
|
-
for(const t of event.tasks.slice(0,5000)){if(typeof t.id!=='string'||!t.id)continue;const row=tasks.get(t.id)||{id:t.id,title:clean(t.title||'Planned task')};row.status=['completed','in_progress','pending','requeued','failed','blocked','skipped'].includes(t.status)?t.status:'pending';row.title=clean(t.title||row.title);tasks.set(t.id,row);}
|
|
49
|
-
current=tasks.get(event.current_task_id)||current;
|
|
50
|
-
mode=[...tasks.values()].some(t=>t.status==='failed')?'failed':'working';
|
|
51
|
-
if(tasks.size&&[...tasks.values()].every(t=>t.status==='completed')){current=null;phase='Final project checks';}
|
|
52
|
-
}
|
|
53
|
-
if(event.type==='error'||event.type==='terminal_error')mode='failed';draw();
|
|
54
|
-
},
|
|
55
|
-
pause(){if(!enabled||paused)return;clear();paused=true;write('\x1b[?25h');},
|
|
56
|
-
resume(){if(!enabled||!running||!paused)return;paused=false;partial=false;write('\x1b[?25l');draw();},
|
|
57
|
-
finish(outcome='success'){if(!running)return;unschedule(timer);timer=null;if(enabled){clear();paused=false;partial=false;mode=outcome;if(outcome==='success')for(const t of tasks.values())t.status='completed';draw();rendered=0;}running=false;restore();},
|
|
58
|
-
state(){const v=view();return {completed:v.done,total:v.total,current:v.ordinal,title:v.title,status:v.label};},
|
|
59
|
-
};
|
|
60
|
-
return api;
|
|
61
|
-
}
|
package/public-dist/terminal.mjs
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
/* Copyright (c) 2026 Vigthoria Technologies. All rights reserved. Proprietary. */
|
|
2
|
-
import fs from 'node:fs';
|
|
3
|
-
import path from 'node:path';
|
|
4
|
-
import os from 'node:os';
|
|
5
|
-
import {workspaceIssue} from './workspace.mjs';
|
|
6
|
-
import {projectInventory} from './workspace-tools.mjs';
|
|
7
|
-
import {paint,section,detail,notice,modelName,cloudProfile} from './presentation.mjs';
|
|
8
|
-
import {routingLabel,disableProvider,providerMenu} from './providers.mjs';
|
|
9
|
-
import {preferences,setPreference,configuredRoot} from './preferences.mjs';
|
|
10
|
-
export const VERSION='2.3.7';
|
|
11
|
-
export const safe=s=>String(s??'').replace(/[\x00-\x1f\x7f-\x9f]/g,'');
|
|
12
|
-
const colour=(s,code,output,theme)=>output.isTTY&&theme!=='plain'&&!Object.hasOwn(process.env,'NO_COLOR')&&process.env.TERM!=='dumb'?'\x1b['+code+'m'+s+'\x1b[0m':s;
|
|
13
|
-
const accent=theme=>theme==='violet'?35:36;
|
|
14
|
-
export function banner(output=process.stdout,theme='cyan'){
|
|
15
|
-
const width=Math.max(20,Math.min(54,(output.columns||80)-4));
|
|
16
|
-
const paint=(s,c)=>colour(s,c,output,theme),edge=s=>paint(s,accent(theme));
|
|
17
|
-
const center=(text,code)=>{text=safe(text);if(text.length>width)text=text.slice(0,width-1)+'…';const left=Math.floor((width-text.length)/2);return edge('║')+' '.repeat(left)+paint(text,code)+' '.repeat(width-text.length-left)+edge('║');};
|
|
18
|
-
output.write('\n'+edge('╔'+'═'.repeat(width)+'╗')+'\n'+center('','0')+'\n'+center('VIGTHORIA CLI','1;97')+'\n'+center('AI-Powered Coding Assistant',theme==='violet'?'95':'96')+'\n'+center('Version '+VERSION,'90')+'\n'+center('','0')+'\n'+edge('╚'+'═'.repeat(width)+'╝')+'\n\n');
|
|
19
|
-
}
|
|
20
|
-
export const modelLabel=id=>id==='agent'?'Automatic routing (recommended)':safe(id).startsWith('vigthoria-cloud-')?'Vigthoria Cloud':safe(id);
|
|
21
|
-
const onOff=v=>v?'On':'Off';
|
|
22
|
-
function heading(text,theme){console.log('\n'+colour(safe(text),'1;'+accent(theme),process.stdout,theme));}
|
|
23
|
-
export async function choose(lines,message,choices,defaultValue,theme='cyan'){
|
|
24
|
-
return lines.select({message,choices,defaultValue,accent:theme==='plain'?0:accent(theme),plain:theme==='plain'});
|
|
25
|
-
}
|
|
26
|
-
export function modelChoices(data={}){
|
|
27
|
-
const valid=s=>typeof s==='string'&&/^[A-Za-z0-9._:-]{1,128}$/.test(s);
|
|
28
|
-
const choices=[{value:'agent',label:'Automatic routing (recommended)',description:'Vigthoria chooses cloud models for planning and coding. No model ID needed.'}];
|
|
29
|
-
for(const m of data.allowedCloudModels||[])if(valid(m.alias))choices.push({value:m.alias,label:'Vigthoria Cloud · '+cloudProfile(m.alias),description:'Uses your account allowance.'+(m.available===false?' Currently unavailable':''),disabled:m.available===false||(data.cloudAccessAllowed===false&&data.isMasterAdmin!==true)});
|
|
30
|
-
for(const m of data.localModels||[])if(valid(m.id))choices.push({value:m.id,label:'Local · '+safe(m.label||m.id),description:'Runs on Vigthoria servers. Assistant model; coding planning may still use cloud.',disabled:m.available===false});
|
|
31
|
-
return choices.filter((v,i,a)=>a.findIndex(c=>c.value===v.value)===i);
|
|
32
|
-
}
|
|
33
|
-
export async function selectModel(lines,current='agent',{theme='cyan',loadCatalog}={}){
|
|
34
|
-
heading('AI model',theme);
|
|
35
|
-
console.log('These models use your Vigthoria account. Selecting one disables your own provider route. Picking a model does not start generation.');
|
|
36
|
-
let data;
|
|
37
|
-
try{data=await (loadCatalog||(async()=>{const {request}=await import('./account.mjs');return request('/api/user/credits/model-preferences');}))();}
|
|
38
|
-
catch(e){console.log('Could not load your available models: '+safe(e.message));console.log('Sign in through Account & API, then try again. Your current model is kept.');return null;}
|
|
39
|
-
if(data.isMasterAdmin)console.log('Master Admin · company funded · no customer credits required.');
|
|
40
|
-
else if(data.cloudAccessAllowed===false)console.log('Cloud access is disabled for this account.');
|
|
41
|
-
else console.log('Cloud requests use your account’s funding and consent settings.');
|
|
42
|
-
if(!data.isMasterAdmin&&data.cloudConsent===false)console.log('Cloud consent is not enabled. Manage it in your Vigthoria account before starting cloud work.');
|
|
43
|
-
const selected=await choose(lines,'Choose an AI model',modelChoices(data),current,theme);
|
|
44
|
-
return selected;
|
|
45
|
-
}
|
|
46
|
-
const settingInfo={
|
|
47
|
-
debugMode:['Debug logging','Show tool names and additional progress details.'],
|
|
48
|
-
autoSave:['Save sessions automatically','Keep private local conversation history for resuming later.'],
|
|
49
|
-
autoApprove:['Approve changes automatically','On applies returned file changes and approves cloud verification commands without asking.'],
|
|
50
|
-
};
|
|
51
|
-
export async function settingsMenu(lines,session){
|
|
52
|
-
while(true){
|
|
53
|
-
heading('Session settings',session.theme);
|
|
54
|
-
const rows=Object.entries(settingInfo).map(([value,[label,description]])=>({value,label:label+' · '+onOff(session[value]),description}));
|
|
55
|
-
rows.push({value:'model',label:'AI model · '+(routingLabel(session)||modelLabel(session.model)),description:'Choose Automatic routing or an available model from your account.'},{value:'theme',label:'Header colours · '+({cyan:'Cyan & white',violet:'Violet & white',plain:'No colour'}[session.theme]||'Cyan & white'),description:'Change terminal presentation.'},{value:'back',label:'Back',description:'Return to session setup.'});
|
|
56
|
-
const key=await choose(lines,'Choose a setting',rows,'back',session.theme);if(key===null||key==='back')return;
|
|
57
|
-
if(settingInfo[key]){
|
|
58
|
-
const [label,description]=settingInfo[key];console.log('\n'+description);
|
|
59
|
-
const v=await choose(lines,label,[{value:false,label:'Off',description:key==='autoApprove'?'Ask before applying file changes and running verification commands.':'Disable this setting.'},{value:true,label:'On',description}],session[key],session.theme);
|
|
60
|
-
if(v!==null){session[key]=v;setPreference(key,v);}
|
|
61
|
-
}else if(key==='theme'){
|
|
62
|
-
const v=await choose(lines,'Header colours',[{value:'cyan',label:'Cyan & white',description:'Cyan frame, bright title and subtle version.'},{value:'violet',label:'Violet & white',description:'Violet frame, bright title and subtle version.'},{value:'plain',label:'No colour',description:'Plain text for terminals and accessibility.'}],session.theme,session.theme);
|
|
63
|
-
if(v!==null){session.theme=v;setPreference('theme',v);banner(process.stdout,v);}
|
|
64
|
-
}else if(key==='model'){
|
|
65
|
-
const v=await selectModel(lines,session.model,{theme:session.theme});if(v!==null){disableProvider(session);session.model=v;setPreference('model',v);}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
export async function accountMenu(lines,theme='cyan',session){
|
|
70
|
-
while(true){
|
|
71
|
-
heading('Account & API',theme);
|
|
72
|
-
const a=await choose(lines,'Choose an account action',[
|
|
73
|
-
{value:'login',label:'Sign in with a Vigthoria account',description:'Your password is entered privately.'},
|
|
74
|
-
{value:'key',label:'Connect a CLI API key',description:'Enter a scoped Vigthoria CLI key privately; never a model-provider key.'},
|
|
75
|
-
{value:'providers',label:'Provider API keys (OpenAI, Anthropic, OpenRouter)',description:'Connect your own provider account and choose planning and coding models.'},
|
|
76
|
-
{value:'test',label:'Test API connection',description:'Check authentication, models and the agent. No generation request is started.'},
|
|
77
|
-
{value:'keys',label:'List my CLI API keys',description:'Show key names, expiry and revocation status; secrets are never displayed.'},
|
|
78
|
-
{value:'back',label:'Back',description:'Return to the previous menu.'},
|
|
79
|
-
],'test',theme);
|
|
80
|
-
if(a===null||a==='back')return;
|
|
81
|
-
try{
|
|
82
|
-
if(a==='providers')await providerMenu(lines,theme,session);
|
|
83
|
-
if(a==='login'){const {login}=await import('./account.mjs');await login([]);}
|
|
84
|
-
if(a==='key'||a==='keys'){const {apiKeys}=await import('./api-keys.mjs');await apiKeys([a==='key'?'login':'list']);}
|
|
85
|
-
if(a==='test'){const {diagnostics}=await import('./diagnostics.mjs');await diagnostics({checkApi:true});}
|
|
86
|
-
}catch(e){console.log('Account action failed: '+safe(e.message));}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
const directory=s=>{s=s.trim().replace(/^(["'])(.*)\1$/,'$2');if(s==='~'||s.startsWith('~/'))s=path.join(os.homedir(),s.slice(2));return path.resolve(s);};
|
|
90
|
-
export async function setup(lines,argv=[]){
|
|
91
|
-
const p=preferences();const session={...p,root:configuredRoot(argv),autoApprove:argv.includes('--auto-approve')||p.autoApprove,autoSave:!argv.includes('--no-save')&&!argv.includes('--no-auto-save')&&p.autoSave,debugMode:argv.includes('--debug')||p.debugMode};
|
|
92
|
-
const mi=argv.findIndex(v=>v==='--model'||v==='-m');if(mi>=0){session.providerEnabled=false;if(!argv[mi+1])throw Error('--model requires a model');session.model=argv[mi+1];}
|
|
93
|
-
if(!process.stdin.isTTY||!process.stdout.isTTY||argv.includes('--no-setup')||argv.includes('--prompt')||argv.includes('-p')||argv.includes('--command-json')||process.env.VIGTHORIA_DECK_MODE==='1')return session;
|
|
94
|
-
if(p.workspacePath&&!argv.includes('--workspace')&&!argv.includes('-w')){try{session.root=fs.realpathSync(p.workspacePath);if(!fs.statSync(session.root).isDirectory())throw Error();}catch{console.log('Saved workspace is unavailable. Using the current directory.');session.root=configuredRoot(argv);}}
|
|
95
|
-
if(process.env.VIGTHORIA_NO_BANNER!=='1')banner(process.stdout,session.theme);
|
|
96
|
-
async function answer(prompt){const r=await lines.next(prompt);return r.done||r.cancelled?null:r.value.trim();}
|
|
97
|
-
while(true){
|
|
98
|
-
heading('Agent Session Setup',session.theme);
|
|
99
|
-
detail('Project',safe(session.root),session.theme);
|
|
100
|
-
detail('AI',routingLabel(session)||modelLabel(session.model),session.theme);
|
|
101
|
-
console.log('File changes: '+(session.autoApprove?'Apply automatically':'Ask before applying')+' · Save sessions: '+onOff(session.autoSave)+' · Debug: '+onOff(session.debugMode));
|
|
102
|
-
const a=await choose(lines,'What would you like to do?',[
|
|
103
|
-
{value:'start',label:'Start agent',description:'Start a conversation in the workspace shown above.'},
|
|
104
|
-
{value:'workspace',label:'Choose an existing workspace',description:'Select the project folder the agent should work on.'},
|
|
105
|
-
{value:'create',label:'Create a workspace',description:'Create a new project folder and use it for this session.'},
|
|
106
|
-
{value:'model',label:'Choose AI model',description:'Automatic routing, available cloud models and the hosted Assistant 9B.'},
|
|
107
|
-
{value:'settings',label:'Session settings',description:'Debug logging, saved sessions, file approvals and header colours.'},
|
|
108
|
-
{value:'account',label:'Account & API',description:'Sign in, connect a provider key or CLI key, or test the connection.'},
|
|
109
|
-
{value:'guide',label:'Browse commands & capabilities',description:'Read grouped command help without leaving this setup.'},
|
|
110
|
-
{value:'exit',label:'Exit',description:'Close setup without starting an agent.'},
|
|
111
|
-
],'start',session.theme);
|
|
112
|
-
if(a===null||a==='exit')return null;
|
|
113
|
-
if(a==='start'){
|
|
114
|
-
let ready=false;
|
|
115
|
-
while(true){
|
|
116
|
-
try{const issue=workspaceIssue(session.root);if(issue)throw Error(issue);const index=projectInventory(session.root);notice('success',index.files.length+' source files available · large projects are read as needed.',session.theme);ready=true;break;}
|
|
117
|
-
catch(e){notice('warning',e.message,session.theme);const entered=await answer('Project folder: ');if(!entered)break;try{const root=directory(entered);if(!fs.statSync(root).isDirectory())throw Error('Choose a directory.');session.root=fs.realpathSync(root);setPreference('workspacePath',session.root);}catch(error){notice('error','Project not changed: '+error.message,session.theme);}}
|
|
118
|
-
}
|
|
119
|
-
if(ready)break;
|
|
120
|
-
continue;
|
|
121
|
-
}
|
|
122
|
-
if(a==='workspace'||a==='create'){
|
|
123
|
-
console.log(a==='create'?'Enter the full path of the new project folder.':'Enter a project folder path. Press Enter to keep the current workspace.');
|
|
124
|
-
const entered=await answer(a==='create'?'New workspace path: ':'Workspace path: ');if(entered===null)continue;if(!entered&&a==='workspace')continue;
|
|
125
|
-
try{if(!entered)throw Error('Enter a folder path.');let root=directory(entered);if(a==='create'){if(fs.existsSync(root))throw Error('That folder exists. Use Choose an existing workspace.');fs.mkdirSync(root,{recursive:true,mode:0o700});}root=fs.realpathSync(root);if(!fs.statSync(root).isDirectory())throw Error('Select a folder, not a file.');session.root=root;setPreference('workspacePath',root);}
|
|
126
|
-
catch(e){console.log('Workspace not changed: '+safe(e.message));}
|
|
127
|
-
}else if(a==='settings')await settingsMenu(lines,session);
|
|
128
|
-
else if(a==='model'){const v=await selectModel(lines,session.model,{theme:session.theme});if(v!==null){disableProvider(session);session.model=v;setPreference('model',v);}}
|
|
129
|
-
else if(a==='account')await accountMenu(lines,session.theme,session);
|
|
130
|
-
else if(a==='guide'){const {commandMenu}=await import('./catalog.mjs');await commandMenu(lines,{guideOnly:true});}
|
|
131
|
-
}
|
|
132
|
-
return session;
|
|
133
|
-
}
|
package/public-dist/update.mjs
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/* Copyright (c) 2026 Vigthoria Technologies. All rights reserved. Proprietary. */
|
|
2
|
-
import fs from 'node:fs';
|
|
3
|
-
import os from 'node:os';
|
|
4
|
-
import path from 'node:path';
|
|
5
|
-
import {fileURLToPath} from 'node:url';
|
|
6
|
-
import {createHash,createPublicKey,verify} from 'node:crypto';
|
|
7
|
-
import {spawnSync} from 'node:child_process';
|
|
8
|
-
import {VERSION} from './terminal.mjs';
|
|
9
|
-
const origin='https://extension.vigthoria.io';
|
|
10
|
-
const key=createPublicKey({key:Buffer.from('302a300506032b6570032100c338cab09089845dfced93db42819372226d38bc89157a78ce938aaeb8509bc2','hex'),format:'der',type:'spki'});
|
|
11
|
-
async function download(url,limit){const u=new URL(url);if(u.origin!==origin||!u.pathname.startsWith('/downloads/')||u.search||u.hash)throw Error('Untrusted release URL');const r=await fetch(u,{redirect:'error',signal:AbortSignal.timeout(30000)});if(!r.ok)throw Error('Release download failed ('+r.status+')');let bytes=0;const chunks=[];for await(const c of r.body){bytes+=c.length;if(bytes>limit)throw Error('Release download exceeds size limit');chunks.push(c);}return Buffer.concat(chunks);}
|
|
12
|
-
export function verifyRelease(bytes,signature){const sig=Buffer.from(String(signature).trim(),'base64');if(sig.length!==64||!verify(null,bytes,key,sig))throw Error('Vigthoria release signature mismatch');}
|
|
13
|
-
export async function update(argv=[]){const bytes=await download(origin+'/downloads/manifest.json',2000000);verifyRelease(bytes,(await download(origin+'/downloads/manifest.json.ed25519.sig',256)).toString());const release=JSON.parse(bytes).channels?.stable;if(!release||!/^\d+\.\d+\.\d+$/.test(release.version)||!Number.isSafeInteger(release.size)||release.size<1||release.size>5000000||!/^[a-f0-9]{64}$/.test(release.sha256))throw Error('Invalid signed CLI release');console.log('Installed: '+VERSION+'; stable: '+release.version);const newer=release.version.split('.').reduce((n,v,i)=>n||Math.sign(Number(v)-Number(VERSION.split('.')[i])),0)>0;if(argv.includes('--check')||!newer)return;if(process.env.VIGTHORIA_DECK_MODE==='1')throw Error('Update the managed CLI through Workbench Settings → Repair verified CLI.');const archive=await download(release.url,release.size);if(archive.length!==release.size||createHash('sha256').update(archive).digest('hex')!==release.sha256)throw Error('Release checksum mismatch');verifyRelease(archive,(await download(release.url+'.ed25519.sig',256)).toString());const temp=fs.mkdtempSync(path.join(os.tmpdir(),'vigthoria-cli-update-'));try{const file=path.join(temp,'vigthoria-cli-'+release.version+'.tgz');fs.writeFileSync(file,archive,{mode:0o600});const i=argv.indexOf('--prefix');let prefix=i>=0?argv[i+1]:null;if(!prefix){const parts=fileURLToPath(import.meta.url).split(path.sep),n=parts.lastIndexOf('node_modules');prefix=n>0?parts.slice(0,parts[n-1]==='lib'?n-1:n).join(path.sep):path.join(os.homedir(),'.local');}if(!prefix||!path.isAbsolute(prefix))throw Error('--prefix requires an absolute install prefix');let executable='npm',args=['install','--global','--ignore-scripts','--no-audit','--no-fund','--prefix',prefix,file];if(process.platform==='win32'){const npm=path.join(path.dirname(process.execPath),'node_modules/npm/bin/npm-cli.js');if(!fs.existsSync(npm))throw Error('Use the verified Windows installer to update this runtime.');executable=process.execPath;args=[npm,...args];}const r=spawnSync(executable,args,{stdio:'inherit',shell:false});if(r.status!==0)throw Error('Verified CLI installation failed');console.log('Installed verified Vigthoria CLI '+release.version+'. Reopen the terminal.');}finally{fs.rmSync(temp,{recursive:true,force:true});}}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/* Copyright (c) 2026 Vigthoria Technologies. All rights reserved. Proprietary. */
|
|
2
|
-
import {accessToken} from './account.mjs';
|
|
3
|
-
import {parse} from './commands.mjs';
|
|
4
|
-
async function transport(route,{token=accessToken(),body,method=body?'POST':'GET'}={}){const response=await fetch('https://workflow.vigthoria.io/api/'+route,{method,redirect:'error',signal:AbortSignal.timeout(120000),headers:{Authorization:'Bearer '+token,'Content-Type':'application/json',Accept:'application/json'},...(body?{body:JSON.stringify(body)}:{})});let bytes=0;const chunks=[];for await(const c of response.body){bytes+=c.length;if(bytes>2000000)throw Error('Workflow response exceeds transport limit');chunks.push(c);}let d;try{d=JSON.parse(Buffer.concat(chunks).toString());}catch{throw Error('Workflow service returned an invalid response ('+response.status+')');}if(!response.ok)throw Object.assign(Error(d.message||d.error||'Workflow request failed'),{status:response.status,code:d.code});return d;}
|
|
5
|
-
export async function workflow(argv=[]){const [action='list',...rest]=argv;const {args,options}=parse(rest,['--name','--variables','--data','--category','--search'],['--json','--yes']);const sso=await transport('auth/sso',{body:{}});if(!sso.token)throw Error('Workflow sign-in did not issue a service token');const token=sso.token,call=(route,o={})=>transport(route,{...o,token});const print=d=>console.log(JSON.stringify(d,null,2));const id=s=>{if(!s||s.length>200)throw Error('Select a workflow or execution id');return encodeURIComponent(s);};
|
|
6
|
-
if(action==='templates'){const q=new URLSearchParams();for(const k of ['category','search'])if(options[k])q.set(k,options[k]);return print(await call('templates'+(q.size?'?'+q:'')));}
|
|
7
|
-
if(action==='list')return print(await call('workflows'));
|
|
8
|
-
if(action==='status')return print(await call('executions/'+id(args[0])));
|
|
9
|
-
if(action==='use')return print(await call('templates/'+id(args[0])+'/use',{body:{name:options.name,variables:options.variables?JSON.parse(options.variables):{}}}));
|
|
10
|
-
if(action==='run')return print(await call('executions/run/'+id(args[0]),{body:{data:options.data?JSON.parse(options.data):{},options:{}}}));
|
|
11
|
-
if(action==='delete'){if(!options.yes)throw Error('Use workflow delete ID --yes');return print(await call('workflows/'+id(args[0]),{method:'DELETE'}));}
|
|
12
|
-
throw Error('Use workflow templates, list, use, run, status or delete.');}
|