@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/render.mjs
CHANGED
|
@@ -1,32 +1,60 @@
|
|
|
1
|
+
import {gradientAt,shimmerIntensity} from '../color/palette.mjs';
|
|
2
|
+
export {gradientAt,shimmerIntensity};
|
|
3
|
+
|
|
1
4
|
// Treat all screen content as data. Only terminal.mjs emits terminal commands.
|
|
2
5
|
export function escapeTerminalText(value=''){
|
|
3
6
|
return String(value).replace(/[\p{Cc}\p{Cf}\u2028\u2029]/gu,character=>{
|
|
4
7
|
const code=character.codePointAt(0);return code<=255?'\\x'+code.toString(16).padStart(2,'0'):'\\u{'+code.toString(16)+'}';
|
|
5
8
|
});
|
|
6
9
|
}
|
|
7
|
-
export function cellWidth(character){return /[\p{Mark}]/u.test(character)?0:/[
|
|
10
|
+
export function cellWidth(character){return /[\p{Mark}]/u.test(character)?0:/[←-↓─-▟■✦✧⠀-⣿]/u.test(character)?1:character.codePointAt(0)>=0x1100?2:1;}
|
|
8
11
|
function fit(text,columns){let used=0,result='';for(const character of text){const size=cellWidth(character);if(used+size>columns)return{text:result,complete:false};result+=character;used+=size;}return{text:result,complete:true};}
|
|
9
|
-
export function navigationHint(mode='menu',{backLabel='back'}={}){
|
|
12
|
+
export function navigationHint(mode='menu',{backLabel='back',horizontal=false}={}){
|
|
10
13
|
if(mode==='text')return'↑/↓: Select · Type/Paste Input · Backspace Delete · Enter Continue · Esc Home';
|
|
11
14
|
if(mode==='busy')return'Ctrl+C Interrupt';
|
|
12
15
|
if(mode==='page')return'↑/↓: Scroll · Enter Back · Esc Home';
|
|
13
|
-
return'↑/↓: Select · Enter
|
|
16
|
+
if(mode==='checklist')return'↑/↓: Select · Enter Toggle · Esc Home';
|
|
17
|
+
return'↑/↓: Select · '+(horizontal?'←/→: Change · ':'')+'Enter Continue · Esc '+(backLabel==='exit'?'Exit':'Home');
|
|
14
18
|
}
|
|
15
|
-
export function
|
|
16
|
-
|
|
17
|
-
|
|
19
|
+
export function arrowValue(text,frame,active){return active&&Math.floor(frame/5)%2===1?' <'+text+'> ':'< '+text+' >';}
|
|
20
|
+
export function wrapDetailRow(row,columns){
|
|
21
|
+
const available=Math.max(2,Math.floor(Number(columns)||80)-3),escaped=escapeTerminalText(row),characters=[...escaped],result=[];
|
|
22
|
+
const leading=/^ */.exec(escaped)[0].length,content=escaped.slice(leading),table=/^\S.*? {2,}(?=\S)/.exec(content);
|
|
23
|
+
const indent=Math.min(available-2,leading+(content.startsWith('• ')?2:table?[...table[0]].length:0));
|
|
24
|
+
let from=0;
|
|
25
|
+
do{
|
|
26
|
+
const prefix=result.length?indent:0;let to=from,used=prefix;
|
|
27
|
+
while(to<characters.length&&used+cellWidth(characters[to])<=available)used+=cellWidth(characters[to++]);
|
|
28
|
+
if(to<characters.length){
|
|
29
|
+
let boundary=to;
|
|
30
|
+
while(boundary>from&&characters[boundary]!==' ')boundary--;
|
|
31
|
+
let wordEnd=boundary;while(wordEnd<characters.length&&characters[wordEnd]===' ')wordEnd++;
|
|
32
|
+
let wordWidth=0;while(wordEnd<characters.length&&characters[wordEnd]!==' ')wordWidth+=cellWidth(characters[wordEnd++]);
|
|
33
|
+
if(boundary>from&&wordWidth<=available-indent&&characters.slice(from,boundary).some(character=>character!==' '))to=boundary;
|
|
34
|
+
while(to>from&&characters[to-1]===' ')to--;
|
|
35
|
+
}
|
|
36
|
+
result.push({text:' '.repeat(prefix)+characters.slice(from,to).join(''),from,to,prefix});
|
|
37
|
+
from=to;while(from<characters.length&&characters[from]===' ')from++;
|
|
38
|
+
}while(from<characters.length);
|
|
18
39
|
return result;
|
|
19
40
|
}
|
|
41
|
+
export function wrapDetailRows(rows,columns){return rows.flatMap(row=>wrapDetailRow(row,columns).map(line=>line.text));}
|
|
42
|
+
// Shorten a choice row with a trailing ellipsis so it fits one line after the selection marker.
|
|
43
|
+
export function fitChoiceRow(row,columns){const available=Math.max(2,Math.floor(Number(columns)||80)-3),characters=[...String(row)];let used=0;for(const character of characters)used+=cellWidth(character);if(used<=available)return String(row);const ellipsis=cellWidth('…');while(characters.length&&used+ellipsis>available)used-=cellWidth(characters.pop());return characters.join('')+'…';}
|
|
20
44
|
const wordmark=[' █████╗ ██████╗ ██████╗','██╔══██╗██╔══██╗██╔════╝','███████║██████╔╝██║ ','██╔══██║██╔══██╗██║ ','██║ ██║██║ ██║╚██████╗','╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝'];
|
|
21
45
|
const STATUS_TONES=Object.freeze({'Available':'ok','Not Available':'muted','Unauthorized':'error','Incomplete':'warn'});
|
|
22
46
|
export function statusSpans(row){
|
|
23
47
|
const spans=[];let start=0;for(const segment of escapeTerminalText(row).split(' / ')){const match=/^(.+?): (.+)$/.exec(segment);if(match)spans.push({from:start+[...match[1]].length+2,to:start+[...segment].length,role:Object.hasOwn(STATUS_TONES,match[2])?STATUS_TONES[match[2]]:'warn'});start+=[...segment].length+3;}return spans;
|
|
24
48
|
}
|
|
49
|
+
export function platformStatusSpans(row){
|
|
50
|
+
const match=/^(.+? {2,})(.+?)(?: · .+)?$/.exec(escapeTerminalText(row));
|
|
51
|
+
if(!match)return[];
|
|
52
|
+
const state=match[2],role=row.includes(' · auth unverified')?'warn':STATUS_TONES[state]??'warn';
|
|
53
|
+
return[{from:[...match[1]].length,to:[...match[1]+state].length,role}];
|
|
54
|
+
}
|
|
25
55
|
const TONE_FG={ok:[52,211,153],muted:[128,128,128],error:[248,113,113],warn:[251,191,36]};
|
|
26
|
-
const PANEL=38
|
|
56
|
+
const PANEL=38;
|
|
27
57
|
const mix=(from,to,t)=>from.map((value,index)=>Math.round(value+(to[index]-value)*t));
|
|
28
|
-
export function gradientAt(t){const position=Math.max(0,Math.min(1,Number(t)||0))*3,segment=Math.min(2,Math.floor(position));return mix(STOPS[segment],STOPS[segment+1],position-segment);}
|
|
29
|
-
export function shimmerIntensity(column,row,frame){const f=frame%36;if(f>=18)return 0;const c=-4+f*33.5/17,p=column+0.5*row;return Math.max(0,1-Math.abs(p-c)/3)**2;}
|
|
30
58
|
export function wordmarkRows({columns=80,rows=24}={}){return columns-1>=24&&rows>=18?8:2;}
|
|
31
59
|
|
|
32
60
|
export function renderScreen(screen={}, {columns=80,rows=24}={}){
|
|
@@ -37,10 +65,12 @@ export function renderScreen(screen={}, {columns=80,rows=24}={}){
|
|
|
37
65
|
const fullTag=tagline+(version?' '+version:''),tag=version&&!fit(fullTag,columns).complete?' ✦ '+version:fullTag;
|
|
38
66
|
const frame=screen.frame??0,f=frame%36,sparkleFrame=f>=18?0:f,spinner='⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏'[frame%10];
|
|
39
67
|
const heading=screen.wordmark?[...(full?[...wordmark,tag]:['ARC ✦'+(version?' '+version:'')]),'─'.repeat(Math.min(columns,PANEL))]:[(screen.mode==='busy'?spinner+' ':'')+escapeTerminalText(screen.title)],position=screen.position?[escapeTerminalText(screen.position)]:[];
|
|
40
|
-
const
|
|
41
|
-
const
|
|
42
|
-
const
|
|
43
|
-
const
|
|
68
|
+
const notices=wrapDetailRows(screen.notices??[],columns+1);while(notices.at(-1)==='')notices.pop();
|
|
69
|
+
const footer=screen.compactFooter?[]:screen.mode==='busy'||screen.hint==='Session ended'?[escapeTerminalText(hint)]:[...(screen.mode==='text'||screen.mode==='page'||notices.length?[]:['']),'─'.repeat(columns),escapeTerminalText(hint)];
|
|
70
|
+
const noticeStart=heading.length+entries.length+position.length,noticeLines=notices.length?['',...notices.map(row=>' '+row)]:[];
|
|
71
|
+
const showSelection=screen.showSelection!==false,lines=[...heading,...entries.map((row,index)=>(index===screen.selected&&showSelection?'> ':' ')+escapeTerminalText(row)),...position,...noticeLines,...footer];
|
|
72
|
+
const fitted=lines.map(line=>fit(line,columns)),tailSize=noticeLines.length+footer.length,bodySize=Math.max(0,rows-tailSize),bodyEnd=Math.min(noticeStart,bodySize);
|
|
73
|
+
const indices=[...Array.from({length:bodyEnd},(_,index)=>index),...(tailSize?Array.from({length:Math.min(rows,tailSize)},(_,index)=>lines.length-Math.min(rows,tailSize)+index):[])],visible=indices.map(index=>fitted[index].text),styles=[];
|
|
44
74
|
const selectedLine=heading.length+screen.selected;
|
|
45
75
|
for(let line=0;line<visible.length;line++){
|
|
46
76
|
const source=indices[line],runs=[];
|
|
@@ -66,15 +96,16 @@ export function renderScreen(screen={}, {columns=80,rows=24}={}){
|
|
|
66
96
|
}
|
|
67
97
|
else if(source>=heading.length&&source<heading.length+entries.length&&screen.rowTones?.[source-heading.length]){
|
|
68
98
|
const tone=screen.rowTones[source-heading.length],text=visible[line].slice(2);
|
|
69
|
-
if(tone==='status')for(const {from,to,role} of screen.rowStatusSpans?.[source-heading.length]??statusSpans(entries[source-heading.length]))add(from+2,to+2,role,TONE_FG[role]);
|
|
99
|
+
if(tone==='status'||tone==='platform-status')for(const {from,to,role} of screen.rowStatusSpans?.[source-heading.length]??(tone==='status'?statusSpans:platformStatusSpans)(entries[source-heading.length]))add(from+2,to+2,role,TONE_FG[role]);
|
|
70
100
|
else if(tone==='diagnostic'){const separator=text.indexOf(': ');if(separator>=0)add(2+[...text.slice(0,separator+2)].length,length,'warn',TONE_FG.warn);}
|
|
71
|
-
else if(tone==='diagnostic-cont')add(2,length,'warn',TONE_FG.warn);
|
|
101
|
+
else if(tone==='diagnostic-cont'||tone==='note')add(2,length,'warn',TONE_FG.warn);
|
|
72
102
|
}
|
|
103
|
+
else if(source>noticeStart&&source<noticeStart+noticeLines.length)add(0,length,'warn',TONE_FG.warn);
|
|
73
104
|
else if(position.length&&source===heading.length+entries.length)add(0,length,'position',[110,130,120]);
|
|
74
105
|
else if(footer.length&&source===lines.length-1){let start=0;for(const segment of visible[line].split(/( · )/)){const end=start+[...segment].length;add(start,end,segment===' · '?'hintSep':'hint',segment===' · '?[70,95,85]:[150,170,160]);start=end;}}
|
|
75
106
|
else if(footer.length>1&&source===lines.length-2)add(0,length,'rule',[36,140,106]);
|
|
76
107
|
if(runs.length)styles.push({line,runs});
|
|
77
108
|
}
|
|
78
|
-
const selectionEnabled=Number.isInteger(screen.selected)&&screen.selected>=0&&screen.selected<entries.length&&selectedLine<
|
|
109
|
+
const selectionEnabled=Number.isInteger(screen.selected)&&screen.selected>=0&&screen.selected<entries.length&&selectedLine<bodyEnd&&fitted[selectedLine].complete;
|
|
79
110
|
return{text:visible.join('\n'),selectionEnabled,styles};
|
|
80
111
|
}
|
package/lib/tui/setup.mjs
CHANGED
|
@@ -1,122 +1,189 @@
|
|
|
1
|
+
import {randomUUID} from 'node:crypto';
|
|
1
2
|
import {parsePositiveLimit} from '../limits.mjs';
|
|
2
3
|
import {readFileSync} from 'node:fs';
|
|
3
4
|
import path from 'node:path';
|
|
4
5
|
import {loadModelConfig,resolveModelSettings,ModelValidationError} from '../models/index.mjs';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
|
|
6
|
+
import {ROLES} from '../models/config.mjs';
|
|
7
|
+
import {DEFAULT_INSTALLER_REGISTRY,installerRegistryOf,platformLabel,sortByDisplay} from '../platforms/index.mjs';
|
|
8
|
+
import {platformAvailability,reasonDetail,REASON_TEXT} from '../platforms/availability.mjs';
|
|
9
|
+
import {createPlatformRegistry} from '../runtime/platform-registry.mjs';
|
|
10
|
+
import {buildRoleRoutingConfig} from '../runtime/role-routing-config.mjs';
|
|
11
|
+
import {deriveInstallPlan} from './derive-install-plan.mjs';
|
|
12
|
+
import {diagramRows} from './diagram.mjs';
|
|
13
|
+
import {editRole} from './custom-preset.mjs';
|
|
14
|
+
import {arrowValue,cellWidth,wrapDetailRows} from './render.mjs';
|
|
12
15
|
const languageLabel = value => value === 'ko' ? 'KR' : 'EN';
|
|
13
16
|
export function loadRoleDefaults({context,statuses,target,readText=filename=>readFileSync(filename,'utf8')}) {
|
|
14
|
-
if(!
|
|
17
|
+
if(!installerRegistryOf(context).isPlatformId(target))throw new ModelValidationError('Unsupported role target');
|
|
15
18
|
const installed=statuses.find(status=>status.platform===target)?.settings?.modelConfig;
|
|
16
|
-
const config=installed??loadModelConfig(readText(path.join(context.packageRoot,target,'skill/models.toml')),target);
|
|
17
|
-
const resolved=resolveModelSettings(config);if(resolved.platform!==target)throw new ModelValidationError('Model configuration platform does not match target');
|
|
19
|
+
const config=installed??loadModelConfig(readText(path.join(context.packageRoot,target,'skill/models.toml')),target,context);
|
|
20
|
+
const resolved=resolveModelSettings(config,context);if(resolved.platform!==target)throw new ModelValidationError('Model configuration platform does not match target');
|
|
18
21
|
return resolved.roles;
|
|
19
22
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return [`Diagram requires ${total+3} columns and ${requiredRows} rows.`];
|
|
31
|
-
}
|
|
32
|
-
const border=(left,right,junction,hidden,platform)=>{const line=[left,...'─'.repeat(width+2),right];if(junction)line[Math.floor(boxWidth/2)]=junction;if(platform)[...` ${platform} `].forEach((character,offset)=>{line[2+offset]=character;});return hidden?line.map((character,index)=>platform&&index>=2&&index<4+cells(platform)?character:' ').join(''):line.join('');};
|
|
33
|
-
const box=(value,index,up)=>{const hidden=index===selectedRole&&!blink,edge=hidden?' ':'│',label=(index===selectedRole?'> ':'')+value.role;return [border('┌','┐',up?'┴':null,hidden,value.platform),...[label,value.model,'effort: '+value.effort].map(text=>edge+' '+text+' '.repeat(width-cells(text))+' '+edge),border('└','┘',up?null:'┬',hidden)];};
|
|
34
|
-
const group=(indices,indent,up)=>{const boxes=indices.map(index=>box(values[index],index,up));return Array.from({length:5},(_,row)=>' '.repeat(indent)+boxes.map(lines=>lines[row]).join(' '));};
|
|
35
|
-
const center=Math.floor(boxWidth/2),middle=boxWidth+2+center,right=2*(boxWidth+2)+center,indent=Math.floor((total-(boxWidth*2+2))/2),bottomLeft=indent+center,bottomRight=bottomLeft+boxWidth+2;
|
|
36
|
-
const bus=(left,right,branches,up=false)=>{const line=Array(total).fill(' ');for(let index=left;index<=right;index++)line[index]='─';for(const index of branches)line[index]=index===middle?'┼':up?'┴':'┬';return line.join('').trimEnd();};
|
|
37
|
-
return [...group([0,1,2],0,false),bus(center,right,[center,middle,right],true),' '.repeat(Math.max(0,middle-6))+'Orchestrator',bus(bottomLeft,bottomRight,[bottomLeft,middle,bottomRight]),...group([3,4],indent,true)];
|
|
38
|
-
}
|
|
39
|
-
export function initialSettings(statuses) {
|
|
40
|
-
return Object.fromEntries(['codex','claude'].map(platform=>{
|
|
41
|
-
const settings=statuses.find(status=>status.platform===platform)?.settings;
|
|
42
|
-
return [platform,{language:settings?.language??'en',maxTotalSubagents:settings?.limits?.max_total_subagents??100,maxConcurrentSubagents:settings?.limits?.max_concurrent_subagents??5,skipGlobal:false}];
|
|
43
|
-
}));
|
|
23
|
+
const installSettingKeys=['language','maxTotalSubagents','maxConcurrentSubagents'];
|
|
24
|
+
const installRoleNames=['Scouter','Planner','Implementer','QA','Reviewer'];
|
|
25
|
+
|
|
26
|
+
export function installSettingsDraft(statuses,platforms){
|
|
27
|
+
const values=platforms.map(platform=>{
|
|
28
|
+
const settings=statuses.find(status=>status.platform===platform&&status.state==='installed')?.settings;
|
|
29
|
+
return {language:settings?.language??'en',maxTotalSubagents:settings?.limits?.max_total_subagents??100,maxConcurrentSubagents:settings?.limits?.max_concurrent_subagents??5};
|
|
30
|
+
});
|
|
31
|
+
const first=values[0]??{language:'en',maxTotalSubagents:100,maxConcurrentSubagents:5};
|
|
32
|
+
return {...first,mixed:new Set(installSettingKeys.filter(key=>values.some(value=>value[key]!==first[key]))),touched:new Set()};
|
|
44
33
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
34
|
+
|
|
35
|
+
export function installPrepareOptions(plan,draft,catalog){
|
|
36
|
+
const settings={skipGlobal:false};
|
|
37
|
+
for(const key of installSettingKeys)if(!draft.settings.mixed.has(key)||draft.settings.touched.has(key))settings[key]=draft.settings[key];
|
|
38
|
+
if(draft.settings.touched.has('maxConcurrentSubagents'))settings.concurrentSelected=true;
|
|
39
|
+
const registry=draft.registry??DEFAULT_INSTALLER_REGISTRY;
|
|
40
|
+
if(plan.rule==='D1-a'||plan.rule==='D1-b'){
|
|
41
|
+
const target=plan.platforms[0],field=registry.getPlatform(target).runtime.models.effortField;
|
|
42
|
+
const roles=Object.fromEntries(ROLES.map(role=>[role,{model:draft.roles[role].model,[field]:draft.roles[role].effort}]));
|
|
43
|
+
return {kind:'install',target,roles,verifiedCatalog:catalog?.[target]??catalog,...settings,...(plan.rule==='D1-b'?{switchFromComposite:true}:{})};
|
|
44
|
+
}
|
|
45
|
+
const runtimePlatforms=createPlatformRegistry(registry.byAnchorOrder().map(descriptor=>descriptor.runtime));
|
|
46
|
+
const config=buildRoleRoutingConfig({revision:randomUUID(),platforms:plan.platforms,roles:draft.roles},{runtimePlatforms});
|
|
47
|
+
return {kind:'install',target:'composite',platforms:plan.platforms,config,settings};
|
|
48
48
|
}
|
|
49
|
-
|
|
49
|
+
|
|
50
|
+
export async function editInstallSettings({ui,settings}){
|
|
50
51
|
let selected=0;
|
|
52
|
+
const display=(key,state)=>settings.mixed.has(key)&&!settings.touched.has(key)?'(mixed)':key==='language'?arrowValue(languageLabel(settings[key]),state.frame,state.selected===0):String(settings[key]);
|
|
53
|
+
const rows=(state={})=>['Language '+display('language',state),'Total subagents '+display('maxTotalSubagents',state),'Concurrent subagents '+display('maxConcurrentSubagents',state),'Back'];
|
|
54
|
+
const cycleLanguage=()=>{settings.language=settings.language==='ko'?'en':'ko';settings.touched.add('language');};
|
|
51
55
|
while(true){
|
|
52
|
-
const choice=await ui.menu('Settings
|
|
53
|
-
if(choice===null||choice===
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
|
|
56
|
+
const choice=await ui.menu('Settings',rows(),{selected,onHorizontal:({selected})=>{if(selected===0)cycleLanguage();},renderBody:state=>({rows:rows(state),selected:state.selected,position:null})});
|
|
57
|
+
if(choice===null||choice===3)return;
|
|
58
|
+
selected=choice;
|
|
59
|
+
if(choice===0){cycleLanguage();continue;}
|
|
60
|
+
const key=installSettingKeys[choice];if(!key)continue;
|
|
61
|
+
let raw=settings.mixed.has(key)&&!settings.touched.has(key)?'':String(settings[key]);
|
|
62
|
+
while(true){
|
|
63
|
+
raw=await ui.text(choice===1?'Total subagents':'Concurrent subagents',raw);if(raw===null)break;
|
|
64
|
+
let value;try{value=parsePositiveLimit(raw);}catch{await ui.page('Invalid limit',['Enter a positive whole number.']);continue;}
|
|
65
|
+
settings[key]=value;settings.touched.add(key);break;
|
|
66
|
+
}
|
|
62
67
|
}
|
|
63
68
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
|
|
69
|
+
|
|
70
|
+
export async function editHosts({ui,hosts,rolePlatforms,availabilityOf,registry=DEFAULT_INSTALLER_REGISTRY}){
|
|
71
|
+
const ids=registry.byDisplayOrder().map(descriptor=>descriptor.runtime.id),locked=new Set(rolePlatforms),checked=new Set([...hosts,...rolePlatforms]);
|
|
72
|
+
const labels=ids.map(id=>platformLabel(id,registry)),labelWidths=labels.map(label=>[...label].reduce((width,character)=>width+cellWidth(character),0)),suffixColumn=Math.max(0,...labelWidths)+2;
|
|
73
|
+
let selected=0,feedback;
|
|
74
|
+
while(true){
|
|
75
|
+
const availability=ids.map(id=>availabilityOf(id));
|
|
76
|
+
const noneChangeable=ids.every((id,index)=>locked.has(id)||!availability[index].selectable);
|
|
77
|
+
const rows=ids.map((id,index)=>{
|
|
78
|
+
const isLocked=locked.has(id),unavailable=!availability[index].selectable,glyph=isLocked?'■':unavailable?'-':checked.has(id)?'x':' ';
|
|
79
|
+
const suffix=[...(isLocked?[`(used by ${installRoleNames.filter((_,index)=>rolePlatforms[index]===id).join(', ')})`]:[]),...(unavailable?[`- Unavailable (${REASON_TEXT[availability[index].reason]})`]:[])].join(' ');
|
|
80
|
+
return `[${glyph}] ${labels[index]}`+(suffix?' '.repeat(suffixColumn-labelWidths[index])+suffix:'')+(availability[index].warning==='auth_unverified'?' (auth unverified)':'');
|
|
81
|
+
});
|
|
82
|
+
const info=({selected})=>{
|
|
83
|
+
const id=ids[selected],base=[noneChangeable?'No host can be changed now: all platforms are used by roles or unavailable.':"Roles' platforms are always included."];
|
|
84
|
+
if(!id)return base;
|
|
85
|
+
const detail=feedback?.id===id?feedback.message:noneChangeable?'':reasonDetail(id,availability[selected],availability[selected].status,registry);
|
|
86
|
+
return detail?[...base,detail]:base;
|
|
87
|
+
};
|
|
88
|
+
const choice=await ui.menu('Hosts — CLIs where you start ARC sessions',[...rows,'Done'],{selected,backRow:true,notice:info,fitRows:true,hint:'checklist'});
|
|
89
|
+
if(choice===null)return null;
|
|
90
|
+
if(choice===ids.length)return ids.filter(id=>checked.has(id));
|
|
91
|
+
selected=choice;feedback=undefined;const id=ids[choice];if(!id)continue;
|
|
92
|
+
if(locked.has(id)){feedback={id,message:`Change those roles' platform to remove ${platformLabel(id,registry)}.`};continue;}
|
|
93
|
+
if(!availability[choice].selectable)feedback={id,message:reasonDetail(id,availability[choice],availability[choice].status,registry)||`Unavailable (${REASON_TEXT[availability[choice].reason]})`};
|
|
94
|
+
if(checked.has(id))checked.delete(id);else if(availability[choice].selectable)checked.add(id);
|
|
79
95
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export async function runInstallFlow({ui,statuses,draft,installState,currentConfig,prepare,loadRoleDefaults:defaults,loadCatalog,registry=DEFAULT_INSTALLER_REGISTRY}){
|
|
99
|
+
const ids=registry.byDisplayOrder().map(descriptor=>descriptor.runtime.id),catalogs=new Map(),availability=new Map();
|
|
100
|
+
const statusOf=id=>statuses.find(status=>status.platform===id);
|
|
101
|
+
// editRole retains these objects while loading catalogs for synchronous arrow keys.
|
|
102
|
+
const availabilityOf=(id,usage='role')=>{
|
|
103
|
+
const key=usage+':'+id,value=platformAvailability(id,{status:statusOf(id),catalog:catalogs.get(id),usage,registry});
|
|
104
|
+
if(!availability.has(key))availability.set(key,{});
|
|
105
|
+
return Object.assign(availability.get(key),value,{status:statusOf(id)});
|
|
106
|
+
};
|
|
107
|
+
const catalogFor=async id=>{
|
|
108
|
+
if(catalogs.has(id))return catalogs.get(id);
|
|
109
|
+
let result;
|
|
110
|
+
try{
|
|
111
|
+
result=await loadCatalog(id);
|
|
112
|
+
const catalog=result?.catalog,runtime=registry.getPlatform(id).runtime;
|
|
113
|
+
if(result?.status!=='ready'||catalog?.platform!==id||!Array.isArray(catalog.pairs)||!catalog.pairs.length||catalog.pairs.some(pair=>!runtime.routing.validatePair(pair.model,pair.effort)))result={status:'catalog_error',code:'catalog_error'};
|
|
114
|
+
}catch{result={status:'catalog_error',code:'catalog_error'};}
|
|
115
|
+
catalogs.set(id,result);
|
|
116
|
+
for(const usage of ['role','host','standalone'])availabilityOf(id,usage);
|
|
117
|
+
return result;
|
|
118
|
+
};
|
|
119
|
+
const defaultsCache=new Map();
|
|
120
|
+
const defaultsFor=async id=>{
|
|
121
|
+
if(!defaultsCache.has(id))defaultsCache.set(id,await defaults(id));
|
|
122
|
+
return defaultsCache.get(id);
|
|
123
|
+
};
|
|
124
|
+
if(!draft.roles){
|
|
125
|
+
if(installState.mode==='composite'&¤tConfig){draft.roles=structuredClone(currentConfig.roles);draft.hosts??=[...installState.platforms];}
|
|
126
|
+
else{
|
|
127
|
+
const initial=ids.find(id=>statusOf(id)?.state==='installed')??ids.find(id=>availabilityOf(id).selectable)??ids[0];
|
|
128
|
+
const source=await defaultsFor(initial),field=registry.getPlatform(initial).runtime.models.effortField;
|
|
129
|
+
draft.roles=Object.fromEntries(ROLES.map(role=>[role,{platform:initial,model:source[role].model,effort:source[role][field]}]));
|
|
130
|
+
draft.hosts??=[initial];
|
|
99
131
|
}
|
|
100
132
|
}
|
|
101
|
-
|
|
133
|
+
draft.hosts??=[...new Set(Object.values(draft.roles).map(role=>role.platform))];
|
|
134
|
+
let selected=0;
|
|
102
135
|
while(true){
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
if(
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
136
|
+
const plan=deriveInstallPlan({roles:draft.roles,hosts:draft.hosts,current:installState,registry});
|
|
137
|
+
const settings=installSettingsDraft(statuses,plan.platforms);
|
|
138
|
+
if(draft.settings)for(const key of installSettingKeys)if(draft.settings.touched.has(key)){settings[key]=draft.settings[key];settings.touched.add(key);}
|
|
139
|
+
draft.settings=settings;
|
|
140
|
+
for(const id of plan.platforms)await catalogFor(id);
|
|
141
|
+
const rolePlatforms=new Set(Object.values(draft.roles).map(role=>role.platform));
|
|
142
|
+
const gates=new Map(plan.platforms.map(id=>[id,availabilityOf(id,plan.platforms.length===1?'standalone':rolePlatforms.has(id)?'role':'host')]));
|
|
143
|
+
const blocked=new Set(),roleRows=ROLES.map((role,index)=>{
|
|
144
|
+
if(!gates.get(draft.roles[role].platform).selectable)blocked.add(index);
|
|
145
|
+
return {role:installRoleNames[index],...draft.roles[role]};
|
|
146
|
+
});
|
|
147
|
+
const firstRole=[...blocked][0],firstId=firstRole===undefined?plan.platforms.find(id=>!gates.get(id).selectable):draft.roles[ROLES[firstRole]].platform;
|
|
148
|
+
const reason=firstId?`! ${firstRole===undefined?'Hosts':installRoleNames[firstRole]}: ${platformLabel(firstId,registry)} - Unavailable (${REASON_TEXT[gates.get(firstId).reason]})`:null;
|
|
149
|
+
const warningId=plan.platforms.find(id=>gates.get(id).warning==='auth_unverified');
|
|
150
|
+
const info=[...(installState.legacyAnchor&&plan.anchorMove?['Mixed routing files will move to the Claude home.']:[]),...(reason?[reason]:warningId?[`${platformLabel(warningId,registry)}: auth unverified`]:[])];
|
|
151
|
+
const controls=['Hosts: '+sortByDisplay(draft.hosts,registry).map(id=>platformLabel(id,registry)).join(', '),'Settings',`Apply - ${plan.modeLabel}`,'Back'];
|
|
152
|
+
const choice=await ui.menu('Install / Update',[...installRoleNames,...controls.slice(0,-1)],{
|
|
153
|
+
selected,backRow:true,refreshMs:600,notice:info,
|
|
154
|
+
renderBody:state=>{
|
|
155
|
+
const diagram=diagramRows(roleRows,{...state,selectedRole:state.selected<ROLES.length?state.selected:undefined,blocked,footerRows:wrapDetailRows(info,state.columns).length+controls.length,registry});
|
|
156
|
+
if(diagram.mode==='guard')return {rows:diagram.rows,notices:[],selected:undefined,position:null};
|
|
157
|
+
const diagramBody=diagram.mode==='compact'?diagram.rows.slice(0,ROLES.length):diagram.rows;
|
|
158
|
+
const rows=[...diagramBody,...controls];
|
|
159
|
+
const selected=state.selected<ROLES.length?(diagram.mode==='compact'?state.selected:state.selected<3?0:8):diagramBody.length+state.selected-ROLES.length;
|
|
160
|
+
const capacity=Math.max(1,state.rows-wrapDetailRows(info,state.columns).length-5),offset=Math.max(0,Math.min(selected-capacity+1,rows.length-capacity));
|
|
161
|
+
return {rows:rows.slice(offset,offset+capacity),selected:selected-offset,notices:info,showSelection:diagram.mode==='compact'||state.selected>=ROLES.length,position:rows.length>capacity?`${offset+1}-${Math.min(rows.length,offset+capacity)}/${rows.length}`:null};
|
|
162
|
+
},
|
|
163
|
+
});
|
|
164
|
+
if(choice===null)return null;
|
|
165
|
+
selected=choice;
|
|
166
|
+
if(choice<ROLES.length){
|
|
167
|
+
const role=ROLES[choice],edited=await editRole({ui,roleName:installRoleNames[choice],current:draft.roles[role],availabilityOf:id=>availabilityOf(id),loadCatalog:catalogFor,defaultsFor:async(id,name)=>{
|
|
168
|
+
const values=await defaultsFor(id),value=values[ROLES[installRoleNames.indexOf(name)]],field=registry.getPlatform(id).runtime.models.effortField;
|
|
169
|
+
return {model:value.model,effort:value[field]};
|
|
170
|
+
},registry});
|
|
171
|
+
if(edited)draft.roles[role]=edited;
|
|
172
|
+
}else if(choice===5){
|
|
173
|
+
const hosts=await editHosts({ui,hosts:draft.hosts,rolePlatforms:ROLES.map(role=>draft.roles[role].platform),availabilityOf:id=>availabilityOf(id,'host'),registry});
|
|
174
|
+
if(hosts!==null)draft.hosts=hosts;
|
|
175
|
+
}else if(choice===6)await editInstallSettings({ui,settings:draft.settings});
|
|
176
|
+
else if(choice===7){
|
|
177
|
+
if(reason)continue;
|
|
178
|
+
if(plan.rule==='D1-f'){
|
|
179
|
+
await ui.page('Operation unavailable',[installState.reason??'Mixed routing configuration cannot be verified.',...(installState.residualPaths??[]).map(value=>'Residual path: '+value),'No changes were applied.']);continue;
|
|
180
|
+
}
|
|
181
|
+
if(plan.rule==='D1-b'){
|
|
182
|
+
const confirm=await ui.menu('Switch to '+platformLabel(plan.platforms[0],registry),['Continue'],{backRow:true,selected:1,info:['Mixed routing will be turned off.']});
|
|
183
|
+
if(confirm!==0)continue;
|
|
184
|
+
}
|
|
185
|
+
const prepared=await prepare(installPrepareOptions(plan,{...draft,registry},Object.fromEntries([...catalogs].map(([id,result])=>[id,result.catalog]))));
|
|
186
|
+
if(prepared)return prepared;
|
|
120
187
|
}
|
|
121
188
|
}
|
|
122
189
|
}
|
package/lib/tui/terminal.mjs
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import {StringDecoder} from 'node:string_decoder';
|
|
2
2
|
import {renderScreen} from './render.mjs';
|
|
3
|
+
import {toAnsi256} from '../color/palette.mjs';
|
|
4
|
+
export {toAnsi256};
|
|
3
5
|
|
|
4
6
|
const BASIC={logo:'92',shadow:'32',sparkle:'92',tagline:'32',version:'32',rule:'32',title:'1;92',spinner:'32',selected:'42;30',selectedPad:'42',hint:'2',hintSep:'2',position:'2',ok:'32',muted:'2',error:'31',warn:'33'};
|
|
5
7
|
const rgb=color=>[0,1,2].map(index=>Math.max(0,Math.min(255,Math.round(Number(color[index])||0))));
|
|
6
|
-
export function toAnsi256(color){const [r,g,b]=rgb(color);return 16+36*Math.round(r/51)+6*Math.round(g/51)+Math.round(b/51);}
|
|
7
8
|
export function formatLine(line,style,depth){
|
|
8
9
|
if(depth==='none'||!style?.runs?.length)return line;
|
|
9
10
|
const characters=[...line];let result='',end=0,painted=false;
|
|
@@ -30,6 +31,7 @@ export function formatLine(line,style,depth){
|
|
|
30
31
|
export function createTerminalSession({input=process.stdin,output=process.stdout,signals=process,env=process.env}={}){
|
|
31
32
|
if(!input.isTTY||!output.isTTY)throw Object.assign(Error('An interactive terminal is required.'),{code:'ARC_TUI_TERMINAL'});
|
|
32
33
|
const wasRaw=Boolean(input.isRaw),wasFlowing=input.readableFlowing;
|
|
34
|
+
const useAlt=env.TERM!=='dumb',frameMs=useAlt?80:0;
|
|
33
35
|
const colorEnabled=env.NO_COLOR===undefined&&env.TERM!=='dumb';
|
|
34
36
|
const truecolor=colorEnabled&&(/^(truecolor|24bit)$/i.test(env.COLORTERM??'')||/^(ghostty|cmux)$/i.test(env.TERM_PROGRAM??'')||/-direct$/.test(env.TERM??'')||(output.getColorDepth?.()??0)>=24);
|
|
35
37
|
const colorDepth=!colorEnabled?'none':truecolor?'truecolor':/256color/i.test(env.TERM??'')||(output.getColorDepth?.()??0)>=8?'256':'16';
|
|
@@ -43,10 +45,10 @@ export function createTerminalSession({input=process.stdin,output=process.stdout
|
|
|
43
45
|
function dispose(){
|
|
44
46
|
if(disposed)return;disposed=true;clearTimer();pending='';paste=null;queue=[];
|
|
45
47
|
input.removeListener('data',onData);input.removeListener('end',onEnd);input.removeListener('close',onEnd);input.removeListener('error',onError);
|
|
46
|
-
output.removeListener('resize',onResize);output.removeListener('error',onError);signals.removeListener('SIGINT',onSigint);signals.removeListener('SIGTERM',onSigterm);
|
|
48
|
+
output.removeListener('resize',onResize);output.removeListener('error',onError);signals.removeListener('SIGINT',onSigint);signals.removeListener('SIGTERM',onSigterm);signals.removeListener('exit',onExit);
|
|
47
49
|
try{if(input.setRawMode&&!input.destroyed)input.setRawMode(wasRaw);}finally{
|
|
48
50
|
try{if(wasFlowing!==true)input.pause();}finally{
|
|
49
|
-
try{output.write('\x1b[0m\x1b[?2004l\x1b[?25h\
|
|
51
|
+
try{output.write('\x1b[0m\x1b[?2004l\x1b[?25h'+(useAlt?'\x1b[?1049l':''));}finally{if(waiter){const resolve=waiter;waiter=undefined;resolve({name:'eof',sequence});}}
|
|
50
52
|
}
|
|
51
53
|
}
|
|
52
54
|
}
|
|
@@ -55,6 +57,7 @@ export function createTerminalSession({input=process.stdin,output=process.stdout
|
|
|
55
57
|
function onError(error){if(!disposed)finish('error',{error});}
|
|
56
58
|
function onSigint(){if(!disposed)finish('interrupt',{signal:'SIGINT'});}
|
|
57
59
|
function onSigterm(){if(!disposed)finish('interrupt',{signal:'SIGTERM'});}
|
|
60
|
+
function onExit(){dispose();}
|
|
58
61
|
function draw(repaint=false){
|
|
59
62
|
const result=renderScreen(screen,{columns:output.columns,rows:output.rows});enterEnabled=screen?.mode==='page'||result.selectionEnabled;
|
|
60
63
|
const lines=result.text.split('\n'),frame=lines.map((line,index)=>'\x1b[2K'+formatLine(line,result.styles.find(style=>style.line===index),colorDepth)+'\n').join('');
|
|
@@ -88,7 +91,7 @@ export function createTerminalSession({input=process.stdin,output=process.stdout
|
|
|
88
91
|
}
|
|
89
92
|
}
|
|
90
93
|
function onData(chunk){if(disposed||busy)return;sequence++;clearTimer();pending+=typeof chunk==='string'?chunk:decoder.write(chunk);parsing=true;try{parse();}finally{parsing=false;if(waiter&&queue.length){const resolve=waiter;waiter=undefined;resolve(queue.shift());}}}
|
|
91
|
-
input.on('data',onData);input.on('end',onEnd);input.on('close',onEnd);input.on('error',onError);output.on('resize',onResize);output.on('error',onError);signals.on('SIGINT',onSigint);signals.on('SIGTERM',onSigterm);
|
|
92
|
-
try{input.setRawMode?.(true);input.resume();output.write('\x1b[?25l\x1b[?2004h');}catch(error){dispose();throw error;}
|
|
93
|
-
return{render,repaint,frameMs:
|
|
94
|
+
input.on('data',onData);input.on('end',onEnd);input.on('close',onEnd);input.on('error',onError);output.on('resize',onResize);output.on('error',onError);signals.on('SIGINT',onSigint);signals.on('SIGTERM',onSigterm);signals.on('exit',onExit);
|
|
95
|
+
try{input.setRawMode?.(true);input.resume();output.write((useAlt?'\x1b[?1049h\x1b[H\x1b[2J':'')+'\x1b[?25l\x1b[?2004h');}catch(error){dispose();throw error;}
|
|
96
|
+
return{render,repaint,frameMs,motion:frameMs>0&&colorDepth!=='none',discardInput,dispose,viewport(){return{columns:output.columns??80,rows:output.rows??24};},setBusy(value){busy=Boolean(value);discardInput();},nextEvent(){if(queue.length)return Promise.resolve(queue.shift());if(disposed)return Promise.resolve({name:'eof',sequence});if(waiter)return Promise.reject(Error('Only one terminal event reader is allowed.'));return new Promise(resolve=>{waiter=resolve;});}};
|
|
94
97
|
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import fsp from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import {DEFAULT_PLATFORM_REGISTRY} from '../runtime/platform-registry.mjs';
|
|
4
|
+
|
|
5
|
+
const exact = (value, keys) => value && typeof value === 'object' && !Array.isArray(value)
|
|
6
|
+
&& Object.keys(value).length === keys.length && keys.every(key => Object.hasOwn(value, key));
|
|
7
|
+
const validHash = value => typeof value === 'string' && /^sha256:[a-f0-9]{64}$/.test(value);
|
|
8
|
+
|
|
9
|
+
function validMarker(marker, platform, home) {
|
|
10
|
+
return exact(marker, ['version', 'revision', 'platform', 'targetHome', 'activeConfigPath', 'configHash', 'runtime', 'profiles'])
|
|
11
|
+
&& marker.version === 1 && typeof marker.revision === 'string' && marker.revision.length > 0
|
|
12
|
+
&& marker.platform === platform && marker.targetHome === home && validHash(marker.configHash)
|
|
13
|
+
&& exact(marker.runtime, ['version', 'hash', 'policyHash'])
|
|
14
|
+
&& typeof marker.runtime.version === 'string' && marker.runtime.version.length > 0
|
|
15
|
+
&& validHash(marker.runtime.hash) && validHash(marker.runtime.policyHash)
|
|
16
|
+
&& marker.profiles && typeof marker.profiles === 'object' && !Array.isArray(marker.profiles)
|
|
17
|
+
&& typeof marker.activeConfigPath === 'string' && path.isAbsolute(marker.activeConfigPath)
|
|
18
|
+
&& path.normalize(marker.activeConfigPath) === marker.activeConfigPath
|
|
19
|
+
&& path.basename(marker.activeConfigPath) === 'arc-role-platform-routing.json';
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Discover one registered anchor without locking or changing watched files. */
|
|
23
|
+
export async function resolveDispatchStore({homes, registry = DEFAULT_PLATFORM_REGISTRY,
|
|
24
|
+
readMarker = file => fsp.readFile(file, 'utf8')}) {
|
|
25
|
+
const platforms = registry.byAnchorOrder().filter(({id}) => typeof homes[id] === 'string' && path.isAbsolute(homes[id]));
|
|
26
|
+
const registeredHomes = new Set(platforms.map(({id}) => path.resolve(homes[id]))), candidates = new Set();
|
|
27
|
+
for (const {id} of platforms) {
|
|
28
|
+
const home = homes[id];
|
|
29
|
+
try {
|
|
30
|
+
const marker = JSON.parse(await readMarker(path.join(home, 'arc-role-platform-routing.prepared.json')));
|
|
31
|
+
if (!validMarker(marker, id, home)) continue;
|
|
32
|
+
const candidate = path.dirname(marker.activeConfigPath);
|
|
33
|
+
if (registeredHomes.has(candidate)) candidates.add(candidate);
|
|
34
|
+
} catch { /* An unavailable or invalid marker does not disable session sources. */ }
|
|
35
|
+
}
|
|
36
|
+
if (candidates.size > 1) return {kind:'ambiguous'};
|
|
37
|
+
if (candidates.size === 1) return {kind:'anchor', dir:path.join([...candidates][0], 'arc-role-dispatch')};
|
|
38
|
+
if (platforms.some(({id}) => id === 'codex')) {
|
|
39
|
+
const dir = path.join(homes.codex, 'arc-role-dispatch');
|
|
40
|
+
try { if ((await fsp.stat(dir)).isDirectory()) return {kind:'legacy', dir}; }
|
|
41
|
+
catch { /* An absent or unreadable legacy store is an empty source. */ }
|
|
42
|
+
}
|
|
43
|
+
return {kind:'none'};
|
|
44
|
+
}
|
package/lib/watch/dispatch.mjs
CHANGED
|
@@ -23,11 +23,11 @@ async function entries(dir) {
|
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
export function createDispatchIndex({
|
|
26
|
+
export function createDispatchIndex({storeDir} = {}) {
|
|
27
27
|
const refs = new Map(), leases = new Map(), tails = new Map(), records = new Map(), signatures = new Map();
|
|
28
28
|
|
|
29
29
|
async function readLeases() {
|
|
30
|
-
const dir =
|
|
30
|
+
const dir = storeDir, seen = new Set();
|
|
31
31
|
for (const entry of await entries(dir)) {
|
|
32
32
|
if (!entry.isFile() || entry.name.startsWith('.') || !entry.name.endsWith('.json') || entry.name.endsWith('.heartbeat.json')) continue;
|
|
33
33
|
const file = path.join(dir, entry.name);
|
|
@@ -80,7 +80,7 @@ export function createDispatchIndex({codexHome}) {
|
|
|
80
80
|
|
|
81
81
|
return {
|
|
82
82
|
async scan({gitCommonDirs, includeAllLeases}) {
|
|
83
|
-
const currentLeases =
|
|
83
|
+
const currentLeases = storeDir ? await readLeases() : new Map(), artifacts = new Map();
|
|
84
84
|
for (const gcd of gitCommonDirs) {
|
|
85
85
|
const workflows = path.join(gcd, 'arc', 'workflows');
|
|
86
86
|
for (const workflow of await entries(workflows)) {
|