@yunhozz/arc 0.3.4 → 0.4.0
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/MANIFEST.sha256 +133 -94
- package/README.md +56 -21
- package/claude/skill/SKILL.md +1 -1
- package/claude/skill/references/commit.md +10 -8
- package/claude/skill/references/coordination.md +6 -4
- package/claude/skill/references/handoff-prep.md +12 -12
- package/claude/skill/references/handoff.md +2 -0
- package/claude/skill/references/planning.md +8 -8
- package/claude/skill/references/verification.md +6 -6
- package/codex/skill/SKILL.md +1 -1
- package/codex/skill/references/commit.md +10 -8
- package/codex/skill/references/coordination.md +6 -4
- package/codex/skill/references/handoff-prep.md +12 -12
- package/codex/skill/references/handoff.md +2 -0
- package/codex/skill/references/planning.md +8 -8
- package/codex/skill/references/verification.md +6 -6
- package/gemini/GEMINI.md +8 -0
- package/gemini/agents/arc-implementer.md +37 -0
- package/gemini/agents/arc-planner.md +47 -0
- package/gemini/agents/arc-qa.md +37 -0
- package/gemini/agents/arc-reviewer.md +39 -0
- package/gemini/agents/arc-scouter.md +38 -0
- package/gemini/instructions.md +4 -0
- package/gemini/skill/SKILL.md +78 -0
- package/gemini/skill/models.toml +23 -0
- package/gemini/skill/references/arc-visual-companion.md +28 -0
- package/gemini/skill/references/commit.md +55 -0
- package/gemini/skill/references/coordination.md +149 -0
- package/gemini/skill/references/git-recovery.md +34 -0
- package/gemini/skill/references/handoff-prep.md +110 -0
- package/gemini/skill/references/handoff.md +227 -0
- package/gemini/skill/references/limits.md +31 -0
- package/gemini/skill/references/planning.md +168 -0
- package/gemini/skill/references/verification.md +155 -0
- package/gemini/skill/references/worktree-creation.md +8 -0
- package/lib/color/palette.mjs +6 -0
- package/lib/installer/acquisition.mjs +7 -5
- package/lib/installer/install-mode.mjs +49 -26
- package/lib/installer/install.mjs +3 -2
- package/lib/installer/manifest.mjs +20 -14
- package/lib/installer/plan.mjs +24 -21
- package/lib/installer/preset.mjs +9 -8
- package/lib/installer/role-routing.mjs +129 -77
- package/lib/installer/runtime-assets.mjs +2 -0
- package/lib/installer/runtime-config.mjs +3 -0
- package/lib/installer/skill-sources.mjs +4 -3
- package/lib/installer/superpowers.mjs +2 -1
- package/lib/installer/target-errors.mjs +1 -0
- package/lib/installer/targets.mjs +14 -6
- package/lib/installer/uninstall.mjs +5 -4
- package/lib/installer/upgrade-state.mjs +14 -10
- package/lib/installer/upgrade.mjs +9 -5
- package/lib/management/operations.mjs +91 -47
- package/lib/management/status.mjs +10 -8
- package/lib/management/update.mjs +8 -7
- package/lib/models/catalog-gemini.mjs +48 -0
- package/lib/models/catalog.mjs +27 -12
- package/lib/models/config.mjs +23 -22
- package/lib/models/gemini-models.json +12 -0
- package/lib/models/profiles.mjs +7 -5
- package/lib/models/static-catalog.mjs +13 -14
- package/lib/npm/upgrade.mjs +2 -2
- package/lib/platforms/availability.mjs +98 -0
- package/lib/platforms/claude.mjs +14 -0
- package/lib/platforms/codex.mjs +16 -0
- package/lib/platforms/formats/gemini-markdown.mjs +48 -0
- package/lib/platforms/formats/markdown.mjs +39 -0
- package/lib/platforms/formats/toml.mjs +39 -0
- package/lib/platforms/gemini.mjs +14 -0
- package/lib/platforms/index.mjs +27 -0
- package/lib/policy/placement.mjs +4 -4
- package/lib/policy/render.mjs +13 -8
- package/lib/policy/role-policy.json +40 -21
- package/lib/prompts/agent-fragments.json +71 -1
- package/lib/prompts/render.mjs +32 -11
- package/lib/runtime/bootstrap.mjs +1 -1
- package/lib/runtime/cooperative-schema.mjs +0 -23
- package/lib/runtime/cooperative.mjs +13 -34
- package/lib/runtime/evaluate.mjs +3 -69
- package/lib/runtime/gemini-stream.mjs +32 -0
- package/lib/runtime/git-evidence.mjs +0 -98
- package/lib/runtime/identity.mjs +2 -1
- package/lib/runtime/local-cli.mjs +14 -24
- package/lib/runtime/operations.mjs +2 -2
- package/lib/runtime/platform-registry.mjs +130 -0
- package/lib/runtime/role-bridge-args.mjs +57 -2
- package/lib/runtime/role-bridge.mjs +86 -65
- package/lib/runtime/role-dispatch-policy.mjs +17 -7
- package/lib/runtime/role-dispatch-store.mjs +20 -14
- package/lib/runtime/role-observe.mjs +1 -0
- package/lib/runtime/role-routing-config.mjs +36 -9
- package/lib/runtime/role-routing.mjs +62 -29
- package/lib/runtime/role-supervisor.mjs +114 -49
- package/lib/runtime/schema.mjs +5 -4
- package/lib/tui/app.mjs +37 -32
- package/lib/tui/custom-preset.mjs +114 -68
- package/lib/tui/derive-install-plan.mjs +19 -0
- package/lib/tui/diagram.mjs +68 -0
- package/lib/tui/mode.mjs +77 -0
- package/lib/tui/render.mjs +47 -16
- package/lib/tui/setup.mjs +167 -100
- package/lib/tui/terminal.mjs +9 -6
- package/lib/watch/anchor-store.mjs +44 -0
- package/lib/watch/dispatch.mjs +3 -3
- package/lib/watch/index.mjs +37 -24
- package/lib/watch/model.mjs +1 -0
- package/lib/watch/normalize-claude.mjs +50 -10
- package/lib/watch/normalize-codex.mjs +79 -5
- package/lib/watch/render.mjs +30 -13
- package/lib/watch/scope.mjs +2 -1
- package/lib/watch/status-line.mjs +51 -0
- package/lib/watch/tail.mjs +27 -0
- package/lib/watch/watcher.mjs +193 -53
- package/package.json +2 -1
- package/scripts/update-manifest.mjs +2 -2
- package/shared/skill/runtime/bootstrap.mjs +1 -1
- package/shared/skill/runtime/cooperative-schema.mjs +0 -23
- package/shared/skill/runtime/cooperative.mjs +13 -34
- package/shared/skill/runtime/evaluate.mjs +3 -69
- package/shared/skill/runtime/gemini-stream.mjs +32 -0
- package/shared/skill/runtime/git-evidence.mjs +0 -98
- package/shared/skill/runtime/identity.mjs +2 -1
- package/shared/skill/runtime/local-cli.mjs +14 -24
- package/shared/skill/runtime/operations.mjs +2 -2
- package/shared/skill/runtime/platform-registry.mjs +130 -0
- package/shared/skill/runtime/role-bridge-args.mjs +57 -2
- package/shared/skill/runtime/role-bridge.mjs +86 -65
- package/shared/skill/runtime/role-dispatch-policy.mjs +17 -7
- package/shared/skill/runtime/role-dispatch-store.mjs +20 -14
- package/shared/skill/runtime/role-observe.mjs +1 -0
- package/shared/skill/runtime/role-policy.json +40 -21
- package/shared/skill/runtime/role-routing-config.mjs +36 -9
- package/shared/skill/runtime/role-routing.mjs +62 -29
- package/shared/skill/runtime/role-supervisor.mjs +114 -49
- package/shared/skill/runtime/schema.mjs +5 -4
package/lib/tui/app.mjs
CHANGED
|
@@ -1,32 +1,35 @@
|
|
|
1
1
|
import {readFileSync} from 'node:fs';
|
|
2
2
|
import {createTerminalSession} from './terminal.mjs';
|
|
3
|
-
import {escapeTerminalText,navigationHint,statusSpans,wrapDetailRows,wordmarkRows} from './render.mjs';
|
|
4
|
-
import {createManagementContext,prepareOperation,executeOperation,readCompositeConfig,
|
|
3
|
+
import {escapeTerminalText,navigationHint,statusSpans,platformStatusSpans,wrapDetailRow,wrapDetailRows,wordmarkRows,fitChoiceRow} from './render.mjs';
|
|
4
|
+
import {createManagementContext,prepareOperation,executeOperation,readCompositeConfig,currentInstallState} from '../management/operations.mjs';
|
|
5
5
|
import {collectStatus} from '../management/status.mjs';
|
|
6
|
-
import {
|
|
6
|
+
import {runInstallFlow,loadRoleDefaults} from './setup.mjs';
|
|
7
7
|
import {loadStaticModelCatalog} from '../models/static-catalog.mjs';
|
|
8
|
+
import {statusInfo} from './mode.mjs';
|
|
9
|
+
import {installerRegistryOf,platformLabel} from '../platforms/index.mjs';
|
|
8
10
|
const packageVersion=JSON.parse(readFileSync(new URL('../../package.json',import.meta.url),'utf8')).version;
|
|
9
|
-
const home=['Install / Update','
|
|
11
|
+
const home=[{id:'install',label:'Install / Update'},{id:'status',label:'Status'},{id:'version',label:'Check Version'},{id:'uninstall',label:'Uninstall'},{id:'exit',label:'Exit'}];
|
|
10
12
|
function goHome(){throw Object.assign(Error('Return home'),{code:'ARC_TUI_HOME'});}
|
|
11
13
|
function interrupted(){return Object.assign(Error('Session interrupted'),{code:'ARC_CANCELLED'});}
|
|
12
14
|
export function createTuiInterface(session,{input,controller}={}){
|
|
13
15
|
async function event(){const e=await session.nextEvent();if(e.name==='interrupt')throw interrupted();if(e.name==='eof')throw Object.assign(Error('Session closed'),{code:'ARC_TUI_EOF'});if(e.name==='error')throw e.error;return e;}
|
|
14
|
-
async function menu(title,rows,{selected=0,info=[],infoTones,backRow=false,backLabel='back',wordmark=false,version,renderBody,onHorizontal,refreshMs}={}){
|
|
16
|
+
async function menu(title,rows,{selected=0,info=[],infoTones,notice=[],fitRows=false,backRow=false,backLabel='back',wordmark=false,version,renderBody,onHorizontal,refreshMs,hint='menu'}={}){
|
|
15
17
|
const actions=backRow?[...rows,'Back']:rows;
|
|
16
18
|
selected=actions.length?Math.max(0,Math.min(selected,actions.length-1)):0;
|
|
17
|
-
const animate=wordmark&&session.frameMs>0,tickMs=animate?session.frameMs:refreshMs;
|
|
18
|
-
let pending,settled,wake,timer,blink=true,frame=0,repainting=false;
|
|
19
|
+
const animate=wordmark&&session.frameMs>0,pulse=typeof onHorizontal==='function'&&session.motion===true,tickMs=animate||pulse?session.frameMs:refreshMs;
|
|
20
|
+
let pending,settled,wake,timer,blink=true,frame=0,blinkElapsed=0,repainting=false;
|
|
19
21
|
try{while(true){
|
|
20
22
|
const viewport=session.viewport(),display=actions,displayIndex=selected,information=[],tones=[],spans=[];
|
|
21
23
|
const details=typeof info==='function'?info({selected,...viewport}):info;
|
|
22
|
-
for(const [index,row] of details.entries()){const wrapped=
|
|
24
|
+
for(const [index,row] of details.entries()){const wrapped=wrapDetailRow(row,viewport.columns),tone=infoTones?.[index],states=tone==='status'?statusSpans(row):tone==='platform-status'?platformStatusSpans(row):[];for(const [line,{text,from,to,prefix}] of wrapped.entries()){information.push(text);tones.push(line&&tone==='diagnostic'?'diagnostic-cont':tone);spans.push(states.filter(span=>span.from<to&&span.to>from).map(span=>({...span,from:Math.max(span.from,from)-from+prefix,to:Math.min(span.to,to)-from+prefix})));}}
|
|
23
25
|
while(information.at(-1)===''){information.pop();tones.pop();}if(information.length){information.push('');tones.push(undefined);}
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
+
const notices=typeof notice==='function'?notice({selected,...viewport}):notice,noticeRows=wrapDetailRows(notices,viewport.columns);while(noticeRows.at(-1)==='')noticeRows.pop();
|
|
27
|
+
const capacity=Math.max(1,viewport.rows-(wordmark?wordmarkRows(viewport):1)-information.length-noticeRows.length-4),offset=Math.max(0,Math.min(displayIndex-capacity+1,display.length-capacity)),visible=display.slice(offset,offset+capacity).map(row=>fitRows?fitChoiceRow(row,viewport.columns):row);
|
|
28
|
+
const screen={title,wordmark,version,frame,notices,rows:[...information,...visible],selected:actions.length?information.length+displayIndex-offset:undefined,hint:navigationHint(hint,{backLabel,horizontal:typeof onHorizontal==='function'}),...(display.length>capacity?{position:(offset+1)+'-'+Math.min(offset+capacity,display.length)+'/'+display.length}:{})};
|
|
26
29
|
if(infoTones){screen.rowTones=[...tones,...visible.map(()=>undefined)];screen.rowStatusSpans=spans;}
|
|
27
|
-
const body=renderBody?.({selected,blink,...viewport});if(body){delete screen.rowTones;delete screen.rowStatusSpans;screen.rows=body.rows;screen.selected=body.selected;screen.showSelection=body.showSelection;screen.compactFooter=body.compactFooter;if(Object.hasOwn(body,'position'))screen.position=body.position;}
|
|
30
|
+
const body=renderBody?.({selected,blink,frame,...viewport});if(body){delete screen.rowTones;delete screen.rowStatusSpans;screen.rows=body.rows;screen.selected=body.selected;screen.showSelection=body.showSelection;screen.compactFooter=body.compactFooter;if(Object.hasOwn(body,'notices'))screen.notices=body.notices;if(Object.hasOwn(body,'position'))screen.position=body.position;}
|
|
28
31
|
const rendered=(repainting?(session.repaint??session.render):session.render).call(session,screen);pending??=event().then(e=>{settled={e};wake?.();},error=>{settled={error};wake?.();});
|
|
29
|
-
if(tickMs>0){if(!settled)await new Promise(resolve=>{wake=resolve;timer=setTimeout(resolve,tickMs);});clearTimeout(timer);timer=undefined;wake=undefined;if(!settled){if(animate)frame++;
|
|
32
|
+
if(tickMs>0){if(!settled)await new Promise(resolve=>{wake=resolve;timer=setTimeout(resolve,tickMs);});clearTimeout(timer);timer=undefined;wake=undefined;if(!settled){if(animate||pulse)frame++;if(refreshMs>0){blinkElapsed+=tickMs;while(blinkElapsed>=refreshMs){blink=!blink;blinkElapsed-=refreshMs;}}repainting=true;continue;}}else await pending;
|
|
30
33
|
if(Object.hasOwn(settled,'error'))throw settled.error;const e=settled.e;pending=undefined;settled=undefined;repainting=false;
|
|
31
34
|
if(e.name==='up'&&actions.length)selected=(selected+actions.length-1)%actions.length;else if(e.name==='down'&&actions.length)selected=(selected+1)%actions.length;else if((e.name==='left'||e.name==='right')&&onHorizontal)onHorizontal({direction:e.name,selected,...viewport});else if(e.name==='escape'){if(backLabel==='exit')return null;goHome();}else if(e.name==='enter'&&actions.length&&rendered.selectionEnabled!==false)return backRow&&selected===rows.length?null:selected;
|
|
32
35
|
}}finally{if(timer!==undefined)clearTimeout(timer);}
|
|
@@ -43,44 +46,46 @@ export function createTuiInterface(session,{input,controller}={}){
|
|
|
43
46
|
async function busy(action){let frame=0,timer;const screen={title:'Working',mode:'busy',rows:[],hint:navigationHint('busy'),frame};session.render(screen);session.setBusy(true);const wasFlowing=input?.readableFlowing;const abort=()=>{if(!controller?.signal.aborted)controller?.abort();},onData=chunk=>{if(String(chunk).includes('\x03')||String(chunk).includes('\x04'))abort();};input?.on('data',onData);input?.prependListener('end',abort);input?.prependListener('close',abort);try{if(input?.readableEnded||input?.destroyed){abort();throw interrupted();}if(controller?.signal.aborted)throw interrupted();if(session.frameMs>0)timer=setInterval(()=>{try{(session.repaint??session.render).call(session,{...screen,frame:++frame});}catch{clearInterval(timer);}},session.frameMs);const result=await (session.frameMs>0?Promise.resolve().then(action):action());if(controller?.signal.aborted){if(typeof result?.code!=='number')throw interrupted();return{...result,code:130,interrupted:true};}return result;}catch(error){if(controller?.signal.aborted&&(['ARC_CANCELLED','ARC_NPM_CANCELLED','ARC_ACQUISITION_CANCELLED','ARC_INSTALL_CANCELLED','ABORT_ERR'].includes(error?.code)||error?.name==='AbortError'))throw interrupted();throw error;}finally{clearInterval(timer);input?.removeListener('data',onData);input?.removeListener('end',abort);input?.removeListener('close',abort);if(wasFlowing!==true)input?.pause?.();session.setBusy(false);session.discardInput();}}
|
|
44
47
|
return{menu,text,page,busy};
|
|
45
48
|
}
|
|
46
|
-
export function resultRows(result){
|
|
47
|
-
|
|
49
|
+
export function resultRows(result,registry=installerRegistryOf(),{version}={}){
|
|
50
|
+
version=result.version??version;
|
|
51
|
+
const clean=text=>text.replace(/; rollback: [^\r\n]*/g,''),label=platform=>platformLabel(platform,registry),errorLine=error=>clean(error.message.split(/[\r\n]/)[0]);
|
|
48
52
|
const residualRows=new Set();
|
|
49
53
|
const removed=result.code===0&&['removed','absent'].includes(result.cli?.status);
|
|
50
|
-
return[...(result.messages??[]).map(s=>clean(s.trim())),...[result.stdout,result.stderr].flatMap(text=>text?text.trimEnd().split(/\r?\n/).map(clean):[]),...(result.results??[]).flatMap(item=>{const platform=item.platform??item.target?.platform??'Target';return[...(removed&&item.status==='uninstalled'?[]:[item.status==='installed'?`ARC installed for ${label(platform)}.`:item.status==='uninstalled'
|
|
54
|
+
return[...(result.messages??[]).map(s=>clean(s.trim())),...[result.stdout,result.stderr].flatMap(text=>text?text.trimEnd().split(/\r?\n/).map(clean):[]),...(result.results??[]).flatMap(item=>{const platform=item.platform??item.target?.platform??'Target';return[...(removed&&item.status==='uninstalled'?[]:[item.status==='installed'?`ARC${version==null?'':' '+version} installed for ${label(platform)}.`:item.status==='uninstalled'?`Removed from ${label(platform)}.`:`${platform}: ${item.status}`]),...(item.residualPaths??[]).map(p=>'Residual path: '+p),...(item.error?['Error: '+errorLine(item.error)]:[])];}),...(removed?[result.cli.status==='removed'?'Removed ARC and CLI.':'Removed ARC.']:result.cli?['CLI: '+result.cli.status,...(result.cli.error?['CLI error: '+errorLine(result.cli.error)]:[])]:[]),...(result.error?['Error: '+errorLine(result.error)]:[]),...(result.code!==0?['Exit code: '+result.code]:[]),...(result.exitSession?[result.cli?'CLI removal ended this session.':'CLI replacement ended this session.']:[])].filter(row=>{if(!row.startsWith('Residual path: '))return true;if(residualRows.has(row))return false;residualRows.add(row);return true;});
|
|
51
55
|
}
|
|
52
56
|
export async function runTui(options={}){
|
|
53
57
|
let session=options.session,code=0,finalReport;const controller=new AbortController(),signals=options.signals??process;const abort=()=>controller.abort();signals.on('SIGINT',abort);signals.on('SIGTERM',abort);
|
|
54
|
-
try{session??=createTerminalSession(options);const ui=createTuiInterface(session,{input:options.input??process.stdin,controller}),api={collectStatus,prepareOperation,executeOperation,
|
|
55
|
-
async function
|
|
58
|
+
try{session??=createTerminalSession(options);const ui=createTuiInterface(session,{input:options.input??process.stdin,controller}),api={collectStatus,prepareOperation,executeOperation,currentInstallState,...options.services},context=options.context?{...options.context,signal:controller.signal}:await createManagementContext({...options.contextOptions,signal:controller.signal});const registry=installerRegistryOf(context),draft={};let selected=0;
|
|
59
|
+
async function loadInstallState(){
|
|
56
60
|
// A failed preview is unverified; prepareOperation still validates at Apply.
|
|
57
|
-
try{return typeof api.
|
|
58
|
-
catch{return 'unverified';}
|
|
61
|
+
try{return typeof api.currentInstallState==='function'?await api.currentInstallState(context):{mode:'unverified',platforms:[]};}
|
|
62
|
+
catch{return {mode:'unverified',platforms:[]};}
|
|
59
63
|
}
|
|
60
64
|
async function execute(prepared){
|
|
61
65
|
if(!prepared)return;const result=await ui.busy(()=>api.executeOperation(context,prepared));code=result.code;
|
|
62
66
|
if(code===0&&['install','preset','switch','composite'].includes(prepared.kind))for(const key of Object.keys(draft))delete draft[key];
|
|
63
|
-
const rows=prepared.kind==='update'&&code===0?[
|
|
67
|
+
const rows=prepared.kind==='update'&&code===0?[`ARC updated: ${prepared.currentVersion} → ${prepared.latestVersion}.`]:resultRows(result,registry,{version:packageVersion});
|
|
64
68
|
if(code===130||result.exitSession){finalReport=rows;if(result.exitSession)session.render({title:'Result',rows:finalReport,hint:'Session ended'});return true;}
|
|
65
69
|
await ui.page('Result',rows);return false;
|
|
66
70
|
}
|
|
67
|
-
async function uninstall(){
|
|
68
|
-
let selected=0;
|
|
69
|
-
while(true){const choice=await ui.menu('Uninstall',['
|
|
70
|
-
const single=choice<
|
|
71
|
-
const
|
|
71
|
+
async function uninstall(statuses){
|
|
72
|
+
let selected=0;const platforms=registry.byDisplayOrder(),installed=id=>statuses.some(status=>status.platform===id&&status.state!=='absent');
|
|
73
|
+
while(true){const choice=await ui.menu('Uninstall',[...platforms.map(({runtime:{id,label}})=>label+(installed(id)?'':' (not installed)')),'Everything (incl. CLI)'],{selected,backRow:true});if(choice===null)return null;selected=choice;
|
|
74
|
+
const single=choice<platforms.length,target=single?platforms[choice].runtime.id:'all';if(single&&!installed(target))continue;
|
|
75
|
+
const state=single?await loadInstallState():null,switching=single&&state.mode==='composite'&&state.platforms.includes(target);
|
|
76
|
+
const proceed=await ui.menu('Uninstall',['Remove'],{backRow:true,selected:1,info:[single?`Remove ARC from ${platformLabel(target,registry)}?`:'Remove ARC from all platforms and the arc CLI?',...(switching?['Mixed routing will be turned off.']:[])]});
|
|
72
77
|
if(proceed===0)return ui.busy(()=>api.prepareOperation(context,{kind:'uninstall',target,removeCli:!single,...(switching?{switchFromComposite:true}:{})}));
|
|
73
78
|
}
|
|
74
79
|
}
|
|
75
|
-
while(true){const statuses=await api.collectStatus(context),
|
|
76
|
-
const
|
|
77
|
-
const
|
|
78
|
-
const info=ordered.length?[compositeAvailable?'Claude & Codex: Available':ordered.map(status=>label(status)+': '+state(status)).join(' / '),...ordered.flatMap(status=>[...(status.diagnostics??[]).map(error=>label(status)+': '+error.message),...(status.authentication?.authStatus==='unknown'&&status.authentication.reason?[label(status)+': '+status.authentication.reason]:[])])]:[];const choice=await ui.menu('ARC',home,{selected,info,infoTones:info.map((_,index)=>index===0?'status':'diagnostic'),backLabel:'exit',wordmark:true,version:packageVersion});if(choice===null||choice===4)return code;selected=choice;
|
|
80
|
+
while(true){const statuses=await api.collectStatus(context),installState=await loadInstallState();
|
|
81
|
+
const choice=await ui.menu('ARC',home.map(action=>action.label),{selected,backLabel:'exit',wordmark:true,version:packageVersion});
|
|
82
|
+
const action=home[choice]?.id;if(choice===null||action==='exit')return code;selected=choice;
|
|
79
83
|
try{
|
|
80
84
|
let prepared;
|
|
81
|
-
if(
|
|
82
|
-
else if(
|
|
83
|
-
else prepared=await
|
|
85
|
+
if(action==='install'){const currentConfig=installState.mode==='composite'?await (api.readCompositeConfig?api.readCompositeConfig(context):readCompositeConfig(context)):undefined;prepared=await runInstallFlow({ui,statuses,draft,installState,currentConfig,loadRoleDefaults:target=>loadRoleDefaults({context,statuses,target}),loadCatalog:target=>api.loadCatalog?api.loadCatalog(target):loadStaticModelCatalog(target,{signal:controller.signal}),prepare:settings=>ui.busy(()=>api.prepareOperation(context,settings)),registry});}
|
|
86
|
+
else if(action==='status')await ui.menu('Status',[],{backRow:true,...statusInfo(installState,statuses,registry)});
|
|
87
|
+
else if(action==='version'){prepared=await ui.busy(()=>api.prepareOperation(context,{kind:'update'}));const action=await ui.menu('Check Version',prepared.canUpgrade?['Upgrade']:[],{backRow:true,info:prepared.canUpgrade?[`${prepared.currentVersion} → ${prepared.latestVersion}`]:prepared.latestVersion!=null?[`Up to date (${prepared.currentVersion})`]:[`${prepared.currentVersion} (latest unavailable)`,...(prepared.latestError?[prepared.latestError.message.split(/[\r\n]/)[0]]:[])]});if(action!==0||!prepared.canUpgrade)prepared=null;}
|
|
88
|
+
else if(action==='uninstall')prepared=await uninstall(statuses);
|
|
84
89
|
if(await execute(prepared))return code;
|
|
85
90
|
}catch(error){if(error.code==='ARC_TUI_HOME')continue;if(['ARC_CANCELLED','ARC_TUI_EOF'].includes(error.code))throw error;code=error.code==='ARC_CLI_INPUT'?2:1;try{await ui.page('Operation unavailable',[error.message,...(error.residualPaths??[]).map(p=>'Residual path: '+p),'No changes were applied.']);}catch(navigation){if(navigation.code!=='ARC_TUI_HOME')throw navigation;}}
|
|
86
91
|
}
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { presetPreviewRows } from './setup.mjs';
|
|
1
|
+
import { loadStaticModelCatalog } from '../models/static-catalog.mjs';
|
|
2
|
+
import { arrowValue, escapeTerminalText, wrapDetailRows } from './render.mjs';
|
|
3
|
+
import { DEFAULT_INSTALLER_REGISTRY, platformLabel } from '../platforms/index.mjs';
|
|
4
|
+
import { REASON_TEXT, reasonDetail } from '../platforms/availability.mjs';
|
|
6
5
|
|
|
7
|
-
const names = ['Scouter', 'Planner', 'Implementer', 'QA', 'Reviewer'];
|
|
8
6
|
export function loadCustomCatalog({ platform, signal } = {}) { return loadStaticModelCatalog(platform, { signal }); }
|
|
9
|
-
function pairKey(model, effort) { return JSON.stringify([model, effort]); }
|
|
10
7
|
function short(value, limit = 12) {
|
|
11
8
|
const characters = [...escapeTerminalText(value)];
|
|
12
9
|
return characters.length > limit ? characters.slice(0, limit - 1).join('') + '…' : characters.join('');
|
|
@@ -36,7 +33,7 @@ function viewportGuard({ columns, rows }) {
|
|
|
36
33
|
const wrap = value => availableColumns === 1 ? [...value] : wrapDetailRows([value], columns);
|
|
37
34
|
const full = wrap('Menu requires 40 columns and 16 rows.'), short = wrap('Requires 40x16.'), minimum = wrap('40x16');
|
|
38
35
|
const guidance = full.length <= availableRows ? full : short.length <= availableRows ? short : minimum;
|
|
39
|
-
return { rows: guidance.slice(0, availableRows), selected: undefined, position: null, compactFooter: rows < guidance.length + 4 };
|
|
36
|
+
return { rows: guidance.slice(0, availableRows), notices: [], selected: undefined, position: null, compactFooter: rows < guidance.length + 4 };
|
|
40
37
|
}
|
|
41
38
|
|
|
42
39
|
function compactMenu(state, items, details, page) {
|
|
@@ -53,8 +50,9 @@ function compactMenu(state, items, details, page) {
|
|
|
53
50
|
const offset = Math.max(0, Math.min(focus - capacity + 1, items.length - capacity));
|
|
54
51
|
const visible = items.slice(offset, offset + capacity).map(row => compactRow(row, state.columns));
|
|
55
52
|
return {
|
|
56
|
-
rows: [...
|
|
57
|
-
|
|
53
|
+
rows: [...visible, 'Back'],
|
|
54
|
+
notices: [...information, `←/→: Details ${detailPage + 1}/${detailPages}`],
|
|
55
|
+
selected: selected === items.length ? visible.length : selected - offset,
|
|
58
56
|
position: items.length > capacity ? `${offset + 1}-${offset + visible.length}/${items.length}` : null,
|
|
59
57
|
compactFooter, detailPage, detailPages,
|
|
60
58
|
};
|
|
@@ -99,15 +97,15 @@ export async function selectCatalogPair({ ui, catalog, current, roleName }) {
|
|
|
99
97
|
lengths[index] = block.length;
|
|
100
98
|
display.push(...block);
|
|
101
99
|
}
|
|
102
|
-
const selected = Math.max(0, Math.min(state.selected, items.length - 1)), commonCapacity = Math.max(1, state.rows - information.length - 5), positionNeeded =
|
|
100
|
+
const selected = Math.max(0, Math.min(state.selected, items.length - 1)), commonCapacity = Math.max(1, state.rows - information.length - 5), positionNeeded = display.length > commonCapacity, reservedRows = positionNeeded ? 5 : 4, requiredRows = information.length + lengths[selected] + reservedRows;
|
|
103
101
|
if (state.rows < requiredRows) return modelPager.render(state, rows, compactDetails);
|
|
104
102
|
const capacity = Math.max(1, state.rows - information.length - reservedRows), maxOffset = Math.max(0, display.length - capacity);
|
|
105
103
|
const offset = Math.max(0, Math.min(maxOffset, starts[selected] + lengths[selected] - capacity));
|
|
106
104
|
modelPager.reset();
|
|
107
|
-
return { rows:
|
|
105
|
+
return { rows: display.slice(offset, offset + capacity), notices: info(state), selected: starts[selected] - offset, position: display.length > capacity ? `${offset + 1}-${Math.min(display.length, offset + capacity)}/${display.length}` : null };
|
|
108
106
|
};
|
|
109
107
|
const choice = await ui.menu(`Model — ${roleName}`, rows, {
|
|
110
|
-
selected: Math.max(0, models.indexOf(current.model)), backRow: true, info,
|
|
108
|
+
selected: Math.max(0, models.indexOf(current.model)), backRow: true, notice: info,
|
|
111
109
|
renderBody: renderModelMenu, onHorizontal: modelPager.move,
|
|
112
110
|
});
|
|
113
111
|
if (choice === null) return null;
|
|
@@ -123,71 +121,119 @@ export async function selectCatalogPair({ ui, catalog, current, roleName }) {
|
|
|
123
121
|
if(state.columns<40||state.rows<24||detailGuard(effortInfo)(state)||efforts.some(value=>wrapDetailRows([value],state.columns).length>1))return effortPager.render(state,efforts,[`Model: ${model}`,`Effort: ${efforts[state.selected]??'-'}`]);
|
|
124
122
|
effortPager.reset();
|
|
125
123
|
};
|
|
126
|
-
const effort=await ui.menu(`Effort — ${roleName}`,efforts,{selected:Math.max(0,efforts.indexOf(current.effort)),backRow:true,
|
|
124
|
+
const effort=await ui.menu(`Effort — ${roleName}`,efforts,{selected:Math.max(0,efforts.indexOf(current.effort)),backRow:true,notice:effortInfo,renderBody:renderEffortMenu,onHorizontal:effortPager.move});
|
|
127
125
|
if(effort!==null&&efforts[effort])return {model,effort:efforts[effort]};
|
|
128
126
|
}
|
|
129
127
|
}
|
|
130
128
|
}
|
|
131
129
|
|
|
132
|
-
function
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
if (diagram.length === 1 || diagram.length + controls.length + 6 > rows) {
|
|
136
|
-
if (columns < 40 || rows < 16) return viewportGuard({columns, rows});
|
|
137
|
-
const summary = presetPreviewRows(values, {columns, rows, compact: true}).slice(0, ROLES.length).map(row => compactRow(row, columns));
|
|
138
|
-
return {rows: [...summary, ...controls, 'Back'], selected: selected, position: null};
|
|
139
|
-
}
|
|
140
|
-
return {rows: [...diagram, '', ...controls, 'Back'], selected: selected < 3 ? 1 : selected < ROLES.length ? 9 : diagram.length + 1 + selected - ROLES.length, showSelection: selected >= ROLES.length};
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
const unavailable = ui => ui.page('Unavailable selection', ['Choose an available model for roles marked !.']);
|
|
144
|
-
export async function editPlatformRoles({ui, title, platform, initialRoles, catalog, settingsRow = false}) {
|
|
145
|
-
const field = effortField(platform), roles = validateRoles(initialRoles, platform);
|
|
146
|
-
const available = new Set(catalog.pairs.map(pair => pairKey(pair.model, pair.effort)));
|
|
147
|
-
let selectedRole = 0;
|
|
130
|
+
export async function selectPlatform({ui, roleName, current, availabilityOf, registry = DEFAULT_INSTALLER_REGISTRY}) {
|
|
131
|
+
const ids = registry.byDisplayOrder().map(descriptor => descriptor.runtime.id);
|
|
132
|
+
let selected = Math.max(0, ids.indexOf(current));
|
|
148
133
|
while (true) {
|
|
149
|
-
const
|
|
150
|
-
const
|
|
151
|
-
const
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
134
|
+
const availability = ids.map(id => availabilityOf(id));
|
|
135
|
+
const rows = ids.map((id, index) => platformLabel(id, registry) + (availability[index].selectable ? '' : ` - Unavailable (${REASON_TEXT[availability[index].reason]})`));
|
|
136
|
+
const info = state => {
|
|
137
|
+
const id = ids[state.selected], value = availability[state.selected];
|
|
138
|
+
const detail = id ? reasonDetail(id, value, undefined, registry) : '';
|
|
139
|
+
return detail ? [detail] : [];
|
|
140
|
+
};
|
|
141
|
+
const choice = await ui.menu(`Platform — ${roleName}`, rows, {
|
|
142
|
+
selected, backRow: true, notice: info,
|
|
143
|
+
renderBody: state => {
|
|
144
|
+
const information = info(state), items = [...rows, 'Back'];
|
|
145
|
+
const capacity = Math.max(1, state.rows - wrapDetailRows(information,state.columns).length - 5);
|
|
146
|
+
const offset = Math.max(0, Math.min(state.selected - capacity + 1, items.length - capacity));
|
|
147
|
+
return {rows: items.slice(offset, offset + capacity).map(row => compactRow(row, state.columns)), notices: information, selected: state.selected - offset, position: items.length > capacity ? `${offset + 1}-${Math.min(items.length, offset + capacity)}/${items.length}` : null};
|
|
148
|
+
},
|
|
149
|
+
});
|
|
150
|
+
if (choice === null) return null;
|
|
151
|
+
selected = choice;
|
|
152
|
+
if (availability[choice]?.selectable) return ids[choice];
|
|
163
153
|
}
|
|
164
154
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
155
|
+
|
|
156
|
+
export async function editRole({ui, roleName, current, availabilityOf, loadCatalog, defaultsFor, registry = DEFAULT_INSTALLER_REGISTRY}) {
|
|
157
|
+
const value = {...current}, reset = {model: false, effort: false};
|
|
158
|
+
const ids = registry.byDisplayOrder().map(descriptor => descriptor.runtime.id);
|
|
159
|
+
const availability = new Map(ids.map(id => [id, availabilityOf(id)]));
|
|
160
|
+
const catalogs = new Map(), defaults = new Map();
|
|
161
|
+
// Horizontal handlers are synchronous; prepare their catalogs before opening the menu.
|
|
162
|
+
for (const id of ids) {
|
|
163
|
+
const state = availability.get(id);
|
|
164
|
+
if (state.reason === 'catalog_error' || (id !== current.platform && !state.selectable)) continue;
|
|
165
|
+
const loaded = await loadCatalog(id);
|
|
166
|
+
catalogs.set(id, loaded?.catalog ?? loaded);
|
|
167
|
+
if (state.selectable) defaults.set(id, await defaultsFor(id, roleName));
|
|
168
|
+
}
|
|
169
|
+
const pairs = () => catalogs.get(value.platform)?.pairs ?? [];
|
|
170
|
+
const changePlatform = id => {
|
|
171
|
+
if (id === value.platform) return;
|
|
172
|
+
const catalog = catalogs.get(id), preferred = defaults.get(id);
|
|
173
|
+
const pair = catalog?.pairs?.find(pair => pair.model === preferred?.model && pair.effort === preferred?.effort) ?? catalog?.pairs?.[0];
|
|
174
|
+
value.platform = id;
|
|
175
|
+
if (pair) {value.model = pair.model; value.effort = pair.effort;}
|
|
176
|
+
reset.model = false; reset.effort = false;
|
|
177
|
+
};
|
|
178
|
+
const cycle = (items, current, direction) => {
|
|
179
|
+
const index = items.indexOf(current), step = direction === 'right' ? 1 : -1;
|
|
180
|
+
return items.length ? items[index < 0 ? (step > 0 ? 0 : items.length - 1) : (index + step + items.length) % items.length] : current;
|
|
181
|
+
};
|
|
182
|
+
const onHorizontal = ({selected, direction}) => {
|
|
183
|
+
if (selected === 0) {
|
|
184
|
+
const start = ids.indexOf(value.platform), step = direction === 'right' ? 1 : -1;
|
|
185
|
+
for (let distance = 1; distance <= ids.length; distance++) {
|
|
186
|
+
const id = ids[(start + step * distance + ids.length) % ids.length];
|
|
187
|
+
if (availability.get(id).selectable) {changePlatform(id); break;}
|
|
188
|
+
}
|
|
189
|
+
} else if (availability.get(value.platform)?.reason !== 'catalog_error') {
|
|
190
|
+
if (selected === 1) {
|
|
191
|
+
const model = cycle([...new Set(pairs().map(pair => pair.model))], value.model, direction);
|
|
192
|
+
if (model === value.model) return;
|
|
193
|
+
value.model = model; reset.model = false;
|
|
194
|
+
const efforts = pairs().filter(pair => pair.model === model).map(pair => pair.effort);
|
|
195
|
+
if (!efforts.includes(value.effort)) {value.effort = efforts[0]; reset.effort = true;}
|
|
196
|
+
} else if (selected === 2) {
|
|
197
|
+
const effort = cycle([...new Set(pairs().filter(pair => pair.model === value.model).map(pair => pair.effort))], value.effort, direction);
|
|
198
|
+
if (effort !== value.effort) {value.effort = effort; reset.effort = false;}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
const editorRows = ({columns = 80, frame = 0, selected} = {}) => {
|
|
203
|
+
const state = availability.get(value.platform), label = platformLabel(value.platform, registry);
|
|
204
|
+
const platform = label + (state?.selectable ? '' : ` - Unavailable (${REASON_TEXT[state?.reason]})`);
|
|
205
|
+
return [['Platform', platform], ['Model', value.model], ['Effort', value.effort]].map(([field, text], rowIndex) =>
|
|
206
|
+
(columns < 40 ? `${field}: ${escapeTerminalText(text)}` : `${field} ${arrowValue(escapeTerminalText(text), frame, selected === rowIndex)}`) + (reset[field.toLowerCase()] ? ' (reset)' : '')
|
|
207
|
+
).concat('Done', 'Back');
|
|
208
|
+
};
|
|
209
|
+
let selected = 0;
|
|
168
210
|
while (true) {
|
|
169
|
-
const
|
|
170
|
-
const
|
|
171
|
-
return
|
|
211
|
+
const info = () => {
|
|
212
|
+
const detail = reasonDetail(value.platform, availability.get(value.platform), undefined, registry);
|
|
213
|
+
return availability.get(value.platform)?.warning === 'auth_unverified' && detail ? [detail] : [];
|
|
214
|
+
};
|
|
215
|
+
const choice = await ui.menu(roleName, editorRows().slice(0, -1), {
|
|
216
|
+
selected, backRow: true, onHorizontal, notice: info,
|
|
217
|
+
renderBody: state => {
|
|
218
|
+
const notices = info(), items = editorRows(state).map(row => compactRow(row, state.columns));
|
|
219
|
+
const capacity = Math.max(1, state.rows - wrapDetailRows(notices, state.columns).length - 5);
|
|
220
|
+
const offset = Math.max(0, Math.min(state.selected - capacity + 1, items.length - capacity));
|
|
221
|
+
return {rows: items.slice(offset, offset + capacity), notices, selected: state.selected - offset, position: items.length > capacity ? `${offset + 1}-${Math.min(items.length, offset + capacity)}/${items.length}` : null};
|
|
222
|
+
},
|
|
172
223
|
});
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
if (
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
const chosen = await ui.menu(`Platform — ${names[selected]}`, ['Codex', 'Claude'], {selected: current.platform === 'claude' ? 1 : 0, backRow: true});
|
|
187
|
-
if (chosen === null) break;
|
|
188
|
-
const platform = ['codex', 'claude'][chosen]; if (!platform) continue;
|
|
189
|
-
const pair = await selectCatalogPair({ui, catalog: catalogs[platform], current, roleName: names[selected]});
|
|
190
|
-
if (pair) {roles[role] = {platform, ...pair}; break;}
|
|
224
|
+
if (choice === null) return null;
|
|
225
|
+
selected = choice;
|
|
226
|
+
if (choice === 3) return value;
|
|
227
|
+
if (choice === 0) {
|
|
228
|
+
const id = await selectPlatform({ui, roleName, current: value.platform, availabilityOf, registry});
|
|
229
|
+
if (id !== null) changePlatform(id);
|
|
230
|
+
} else if ((choice === 1 || choice === 2) && availability.get(value.platform)?.reason !== 'catalog_error' && pairs().length) {
|
|
231
|
+
const pair = await selectCatalogPair({ui, roleName, current: value, catalog: catalogs.get(value.platform)});
|
|
232
|
+
if (pair) {
|
|
233
|
+
if (pair.model !== value.model) reset.model = false;
|
|
234
|
+
if (pair.effort !== value.effort) reset.effort = false;
|
|
235
|
+
Object.assign(value, pair);
|
|
236
|
+
}
|
|
191
237
|
}
|
|
192
238
|
}
|
|
193
239
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import {installerRegistryOf, mixedLabel, platformLabel, sortByAnchor} from '../platforms/index.mjs';
|
|
2
|
+
|
|
3
|
+
export function deriveInstallPlan({roles, hosts, current, registry = installerRegistryOf()}) {
|
|
4
|
+
const platforms = sortByAnchor([...new Set([...Object.values(roles).map(role => role.platform), ...hosts])], registry);
|
|
5
|
+
const anchor = platforms[0];
|
|
6
|
+
const previous = sortByAnchor([...new Set(current.platforms ?? [])], registry);
|
|
7
|
+
const removed = previous.filter(id => !platforms.includes(id));
|
|
8
|
+
const added = platforms.filter(id => !previous.includes(id));
|
|
9
|
+
const same = removed.length === 0 && added.length === 0;
|
|
10
|
+
const rule = current.mode === 'unverified' ? 'D1-f'
|
|
11
|
+
: platforms.length === 1 ? (current.mode === 'composite' ? 'D1-b' : 'D1-a')
|
|
12
|
+
: current.mode !== 'composite' ? 'D1-c' : same ? 'D1-d' : 'D1-e';
|
|
13
|
+
return {
|
|
14
|
+
rule, platforms, anchor, previous, removed, added,
|
|
15
|
+
anchorMove: (rule === 'D1-d' || rule === 'D1-e') && (current.legacyAnchor === true || previous[0] !== anchor),
|
|
16
|
+
modeLabel: rule === 'D1-f' ? 'Unverified'
|
|
17
|
+
: platforms.length === 1 ? platformLabel(anchor, registry) : mixedLabel(platforms, registry),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import {installerRegistryOf,platformLabel} from '../platforms/index.mjs';
|
|
2
|
+
import {escapeTerminalText,cellWidth,wrapDetailRows} from './render.mjs';
|
|
3
|
+
|
|
4
|
+
const cells=value=>[...value].reduce((total,character)=>total+cellWidth(character),0);
|
|
5
|
+
|
|
6
|
+
function shorten(value,limit){
|
|
7
|
+
if(cells(value)<=limit)return value;
|
|
8
|
+
const suffix=cells('…')<=limit?'…':'';let result='',used=0;
|
|
9
|
+
for(const character of value){
|
|
10
|
+
const size=cellWidth(character);
|
|
11
|
+
if(used+size>Math.max(0,limit-cells(suffix)))break;
|
|
12
|
+
result+=character;used+=size;
|
|
13
|
+
}
|
|
14
|
+
return result+suffix;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function viewportGuard({columns,rows}){
|
|
18
|
+
const availableRows=Math.max(0,rows-1),availableColumns=columns-3;
|
|
19
|
+
const wrap=value=>availableColumns===1?[...value]:wrapDetailRows([value],columns);
|
|
20
|
+
const full=wrap('Menu requires 40 columns and 16 rows.'),short=wrap('Requires 40x16.'),minimum=wrap('40x16');
|
|
21
|
+
const guidance=full.length<=availableRows?full:short.length<=availableRows?short:minimum;
|
|
22
|
+
return {mode:'guard',rows:guidance.slice(0,availableRows)};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function diagramRows(roleRows,{columns=80,rows=24,selectedRole,blink=true,blocked=new Set(),footerRows=6,registry=installerRegistryOf()}={}){
|
|
26
|
+
if(columns<40||rows<16)return viewportGuard({columns,rows});
|
|
27
|
+
const values=roleRows.map(({role,platform,model,effort},index)=>({
|
|
28
|
+
label:escapeTerminalText(role)+(blocked.has(index)?' !':''),
|
|
29
|
+
platform:escapeTerminalText(platformLabel(platform,registry)),
|
|
30
|
+
model:escapeTerminalText(model),effort:escapeTerminalText(effort),
|
|
31
|
+
}));
|
|
32
|
+
const width=Math.max(20,...values.flatMap(value=>[
|
|
33
|
+
cells(value.label)+2+4,cells(value.platform),cells(value.model),cells('effort: '+value.effort),
|
|
34
|
+
])),boxWidth=width+4,total=boxWidth*3+4;
|
|
35
|
+
if(columns<boxWidth*3+7||rows<24||13+footerRows+5>rows){
|
|
36
|
+
const available=Math.max(2,Math.floor(Number(columns)||80)-3);
|
|
37
|
+
const roleRow=value=>{
|
|
38
|
+
const model=value.platform+' / '+value.model,prefix=value.label+': ',room=Math.max(0,available-cells(prefix)-cells(' / '));
|
|
39
|
+
const modelLimit=Math.min(cells(model),Math.ceil(room/2)),effortLimit=Math.min(cells(value.effort),room-modelLimit);
|
|
40
|
+
return shorten(prefix+shorten(model,room-effortLimit)+' / '+shorten(value.effort,effortLimit),available);
|
|
41
|
+
};
|
|
42
|
+
return {mode:'compact',rows:[...values.map(roleRow),'']};
|
|
43
|
+
}
|
|
44
|
+
const center=Math.floor(boxWidth/2),middle=boxWidth+2+center,right=2*(boxWidth+2)+center;
|
|
45
|
+
const indent=Math.floor((total-(boxWidth*2+2))/2),bottomLeft=indent+center,bottomRight=bottomLeft+boxWidth+2;
|
|
46
|
+
const box=(value,index,up)=>{
|
|
47
|
+
const hidden=index===selectedRole&&!blink,edge=hidden?' ':'│',label=(index===selectedRole?'> ':'')+value.label;
|
|
48
|
+
const top=hidden?' '+label+' '.repeat(boxWidth-3-cells(label)):'┌─ '+label+' '+'─'.repeat(boxWidth-cells(label)-5)+'┐';
|
|
49
|
+
const bottom=Array(boxWidth).fill(hidden?' ':'─');
|
|
50
|
+
if(!hidden){bottom[0]='└';bottom[boxWidth-1]='┘';if(!up)bottom[center]='┬';}
|
|
51
|
+
return [top,...[value.platform,value.model,'effort: '+value.effort].map(text=>edge+' '+text+' '.repeat(width-cells(text))+' '+edge),bottom.join('')];
|
|
52
|
+
};
|
|
53
|
+
const group=(indices,indent,up)=>{
|
|
54
|
+
const boxes=indices.map(index=>box(values[index],index,up));
|
|
55
|
+
return Array.from({length:5},(_,row)=>' '.repeat(indent)+boxes.map(lines=>lines[row]).join(' '));
|
|
56
|
+
};
|
|
57
|
+
const bus=(left,right,branches,up=false)=>{
|
|
58
|
+
const line=Array(total).fill(' ');
|
|
59
|
+
for(let index=left;index<=right;index++)line[index]='─';
|
|
60
|
+
for(const index of branches)line[index]=index===middle?'┼':up?'┴':'┬';
|
|
61
|
+
return line.join('').trimEnd();
|
|
62
|
+
};
|
|
63
|
+
return {mode:'full',rows:[
|
|
64
|
+
...group([0,1,2],0,false),bus(center,right,[center,middle,right],true),
|
|
65
|
+
' '.repeat(Math.max(0,middle-6))+'Orchestrator',bus(bottomLeft,bottomRight,[bottomLeft,middle,bottomRight]),
|
|
66
|
+
...group([3,4],indent,true),
|
|
67
|
+
]};
|
|
68
|
+
}
|
package/lib/tui/mode.mjs
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import {installerRegistryOf, mixedLabel} from '../platforms/index.mjs';
|
|
2
|
+
import {REASON_TEXT, supportedVersion} from '../platforms/availability.mjs';
|
|
3
|
+
import {cellWidth, escapeTerminalText} from './render.mjs';
|
|
4
|
+
|
|
5
|
+
// Preserve the State vocabulary and authentication precedence of the home renderer.
|
|
6
|
+
function stateLabel(status, runtime) {
|
|
7
|
+
if (runtime.capabilities.install.state !== 'verified') return 'Not verified';
|
|
8
|
+
if (runtime.auth.kind === 'none') {
|
|
9
|
+
if (status.authentication?.reason === 'cli_not_found' || status.cliVersion?.reason === 'cli_not_found') return 'Not Available';
|
|
10
|
+
if (!supportedVersion(status.cliVersion?.version, runtime.cli.supportedVersions)) return 'Unsupported version';
|
|
11
|
+
return 'Available (auth unverified)';
|
|
12
|
+
}
|
|
13
|
+
if (status.state !== 'installed') return {absent: 'Not Available', incomplete: 'Incomplete'}[status.state] ?? status.state;
|
|
14
|
+
if (status.authentication?.reason === 'cli_not_found') return 'Not Available';
|
|
15
|
+
if (status.authentication?.authStatus === 'unauthorized') return 'Unauthorized';
|
|
16
|
+
if (status.authentication?.authStatus === 'unknown') return 'Incomplete';
|
|
17
|
+
return 'Available';
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function homeStatusLine(statuses, registry = installerRegistryOf()) {
|
|
21
|
+
return registry.byDisplayOrder().flatMap(({runtime}) => {
|
|
22
|
+
const {id, label} = runtime;
|
|
23
|
+
const status = statuses.find(status => status.platform === id);
|
|
24
|
+
return status ? [`${label}: ${stateLabel(status, runtime)}`] : [];
|
|
25
|
+
}).join(' / ');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function homeModeLine(installState, statuses, registry = installerRegistryOf()) {
|
|
29
|
+
if (installState.mode === 'unverified') return 'Unverified';
|
|
30
|
+
if (installState.mode === 'composite') return mixedLabel(installState.platforms, registry);
|
|
31
|
+
const labels = registry.byDisplayOrder()
|
|
32
|
+
.filter(({runtime: {id}}) => statuses.some(status => status.platform === id && status.state === 'installed'))
|
|
33
|
+
.map(({runtime: {label}}) => label);
|
|
34
|
+
return labels.length ? labels.join(', ') : 'Not installed';
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function statusInfo(installState, statuses, registry = installerRegistryOf()) {
|
|
38
|
+
const platforms = registry.byDisplayOrder().flatMap(({runtime}) => {
|
|
39
|
+
const status = statuses.find(status => status.platform === runtime.id);
|
|
40
|
+
return status ? [{runtime, status, state: stateLabel(status, runtime)}] : [];
|
|
41
|
+
});
|
|
42
|
+
const width = text => [...escapeTerminalText(text)].reduce((sum, character) => sum + cellWidth(character), 0);
|
|
43
|
+
const labelWidth = Math.max(width('Mode'), ...platforms.map(({runtime}) => width(runtime.label)));
|
|
44
|
+
const row = (label, value) => label + ' '.repeat(labelWidth - width(label) + 3) + value;
|
|
45
|
+
const info = [row('Mode', homeModeLine(installState, statuses, registry)), ''];
|
|
46
|
+
const infoTones = [undefined, undefined], notes = new Map();
|
|
47
|
+
const humanize = value => value.replace(/\b[a-z]+(?:_[a-z0-9]+)+\b/g, token => REASON_TEXT[token] ?? token.replaceAll('_', ' '));
|
|
48
|
+
const diagnosticText = value => {
|
|
49
|
+
const code = value.trim();
|
|
50
|
+
return /^[a-z]+(?:_[a-z0-9]+)+$/.test(code) ? REASON_TEXT[code] ?? code.replaceAll('_', ' ') : value;
|
|
51
|
+
};
|
|
52
|
+
for (const {runtime, status, state} of platforms) {
|
|
53
|
+
const value = state.replace(' (auth unverified)', ' · auth unverified');
|
|
54
|
+
info.push(row(runtime.label, value));
|
|
55
|
+
infoTones.push('platform-status');
|
|
56
|
+
const repeated = new Set([state.toLowerCase(), ...(state.includes('auth unverified') ? ['auth unverified'] : []),
|
|
57
|
+
...(state === 'Not Available' ? ['not installed', 'cli not found'] : []),
|
|
58
|
+
...(state === 'Not verified' ? ['capability not verified'] : [])]);
|
|
59
|
+
const authReason = status.authentication?.reason;
|
|
60
|
+
const diagnostics = (status.diagnostics ?? []).map(error => error.message).filter(Boolean).map(diagnosticText);
|
|
61
|
+
for (const reason of [...diagnostics, ...(authReason ? [humanize(authReason)] : [])]) {
|
|
62
|
+
const message = reason.trim();
|
|
63
|
+
if (!message || repeated.has(message.toLowerCase())) continue;
|
|
64
|
+
if (!notes.has(message)) notes.set(message, new Set());
|
|
65
|
+
notes.get(message).add(runtime.label);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (notes.size) {
|
|
69
|
+
info.push('', 'Notes');
|
|
70
|
+
infoTones.push(undefined, undefined);
|
|
71
|
+
for (const [message, labels] of notes) {
|
|
72
|
+
info.push(`• ${message} (${[...labels].join(', ')})`);
|
|
73
|
+
infoTones.push('note');
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return {info, infoTones};
|
|
77
|
+
}
|