specpilot 2.13.0 → 2.15.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/README.md +27 -22
- package/dist/cli.js +4 -2
- package/dist/cli.js.map +1 -1
- package/dist/commands/backfill.d.ts.map +1 -1
- package/dist/commands/backfill.js +24 -13
- package/dist/commands/backfill.js.map +1 -1
- package/dist/commands/serve.d.ts +3 -1
- package/dist/commands/serve.d.ts.map +1 -1
- package/dist/commands/serve.js +75 -4
- package/dist/commands/serve.js.map +1 -1
- package/dist/core/agentConfig.d.ts +10 -0
- package/dist/core/agentConfig.d.ts.map +1 -1
- package/dist/core/agentConfig.js +47 -3
- package/dist/core/agentConfig.js.map +1 -1
- package/dist/core/chatFlow.js +2 -2
- package/dist/core/chatFlow.js.map +1 -1
- package/dist/core/slashCommands.d.ts.map +1 -1
- package/dist/core/slashCommands.js +25 -16
- package/dist/core/slashCommands.js.map +1 -1
- package/dist/core/specFiles.js +3 -0
- package/dist/core/specFiles.js.map +1 -1
- package/dist/core/templateEngine.d.ts +5 -0
- package/dist/core/templateEngine.d.ts.map +1 -1
- package/dist/core/templateEngine.js +13 -1
- package/dist/core/templateEngine.js.map +1 -1
- package/dist/utils/addSpecsQuestions.d.ts.map +1 -1
- package/dist/utils/addSpecsQuestions.js +2 -0
- package/dist/utils/addSpecsQuestions.js.map +1 -1
- package/dist/utils/folderPicker.d.ts +28 -0
- package/dist/utils/folderPicker.d.ts.map +1 -0
- package/dist/utils/folderPicker.js +96 -0
- package/dist/utils/folderPicker.js.map +1 -0
- package/dist/utils/mcpLocal.d.ts +10 -0
- package/dist/utils/mcpLocal.d.ts.map +1 -1
- package/dist/utils/mcpLocal.js +61 -2
- package/dist/utils/mcpLocal.js.map +1 -1
- package/dist/utils/projectDetector.d.ts +11 -0
- package/dist/utils/projectDetector.d.ts.map +1 -1
- package/dist/utils/projectDetector.js +86 -0
- package/dist/utils/projectDetector.js.map +1 -1
- package/dist/utils/slashCommandGenerator.d.ts +21 -0
- package/dist/utils/slashCommandGenerator.d.ts.map +1 -1
- package/dist/utils/slashCommandGenerator.js +166 -0
- package/dist/utils/slashCommandGenerator.js.map +1 -1
- package/dist/utils/specArchiver.d.ts.map +1 -1
- package/dist/utils/specArchiver.js +2 -1
- package/dist/utils/specArchiver.js.map +1 -1
- package/dist/utils/specBackfiller.d.ts +9 -3
- package/dist/utils/specBackfiller.d.ts.map +1 -1
- package/dist/utils/specBackfiller.js +52 -48
- package/dist/utils/specBackfiller.js.map +1 -1
- package/dist/utils/specServer.d.ts +12 -7
- package/dist/utils/specServer.d.ts.map +1 -1
- package/dist/utils/specServer.js +263 -123
- package/dist/utils/specServer.js.map +1 -1
- package/dist/utils/specSetup.d.ts +21 -23
- package/dist/utils/specSetup.d.ts.map +1 -1
- package/dist/utils/specSetup.js +69 -57
- package/dist/utils/specSetup.js.map +1 -1
- package/dist/utils/specValidator.d.ts.map +1 -1
- package/dist/utils/specValidator.js +4 -1
- package/dist/utils/specValidator.js.map +1 -1
- package/package.json +1 -1
- package/ui/app.css +43 -109
- package/ui/app.js +155 -305
- package/ui/index.html +25 -29
- package/ui/route.js +3 -101
- package/dist/__tests__/fixtures/allFields.d.ts +0 -3
- package/dist/__tests__/fixtures/allFields.d.ts.map +0 -1
- package/dist/__tests__/fixtures/allFields.js +0 -31
- package/dist/__tests__/fixtures/allFields.js.map +0 -1
package/ui/app.js
CHANGED
|
@@ -10,6 +10,8 @@ const toast=(m,action)=>{
|
|
|
10
10
|
toastEl.classList.add('show');clearTimeout(toastT);toastT=setTimeout(()=>toastEl.classList.remove('show'),action?8000:2600);};
|
|
11
11
|
/* Task moves (BL-053) are on only when the server put a token in the page (not with --read-only). */
|
|
12
12
|
const TOKEN=(document.querySelector('meta[name="specpilot-token"]')||{}).content||null;
|
|
13
|
+
/* /mcp is on (BL-PM-007), and whose token it takes: `page` or `env` (SPECPILOT_MCP_TOKEN). */
|
|
14
|
+
const MCP=(document.querySelector('meta[name="specpilot-mcp"]')||{}).content||null;
|
|
13
15
|
const MOVABLE={backlog:true,currentSprint:true};
|
|
14
16
|
const chev='<svg class="ico chev" aria-hidden="true" focusable="false"><use href="#i-chev"/></svg>';
|
|
15
17
|
|
|
@@ -18,6 +20,20 @@ let theme=null;try{theme=localStorage.getItem('sp-theme');}catch(e){}
|
|
|
18
20
|
function setMeta(light){const m=document.querySelector('meta[name=theme-color]');if(m)m.content=light?'#f8fafc':'#0f172a';}
|
|
19
21
|
if(theme==='light'){document.documentElement.setAttribute('data-theme','light');setMeta(true);}
|
|
20
22
|
$('#themeBtn').onclick=()=>{const light=document.documentElement.getAttribute('data-theme')==='light';if(light)document.documentElement.removeAttribute('data-theme');else document.documentElement.setAttribute('data-theme','light');setMeta(!light);try{light?localStorage.removeItem('sp-theme'):localStorage.setItem('sp-theme','light');}catch(e){}toast('Appearance: '+(light?'dark':'light'));};
|
|
23
|
+
/* Quit (BL-098): the route `specpilot serve --stop` uses; the server then stops as on Ctrl+C. This page
|
|
24
|
+
closes its stream and says so; other open pages see a dropped stream, as before. */
|
|
25
|
+
let stopped=false;
|
|
26
|
+
if(TOKEN)$('#quitBtn').hidden=false;
|
|
27
|
+
$('#quitBtn').onclick=async()=>{
|
|
28
|
+
if(!confirm('Quit SpecPilot? Open pages stop updating.'))return;
|
|
29
|
+
let r;
|
|
30
|
+
try{r=await fetch('/api/quit',{method:'POST',cache:'no-store',headers:{'Content-Type':'application/json','X-SpecPilot-Token':TOKEN},body:'{}'});}
|
|
31
|
+
catch(e){return toast('The server did not answer.');}
|
|
32
|
+
if(r.status!==202){const t=await r.text().catch(()=>'');let m=t;try{m=JSON.parse(t).error||t;}catch(e){}return toast(m.trim()||'The server did not stop.');}
|
|
33
|
+
stopped=true;if(es){es.close();es=null;}
|
|
34
|
+
const p=document.createElement('p');p.className='stopped';p.setAttribute('role','status');p.textContent='SpecPilot has stopped. Run specpilot serve to start it again.';
|
|
35
|
+
document.querySelector('main.pane').replaceChildren(p);
|
|
36
|
+
};
|
|
21
37
|
|
|
22
38
|
/* ---------------- data: fetched, never embedded ---------------- */
|
|
23
39
|
let DATA=null;
|
|
@@ -70,21 +86,19 @@ function syncNav(){
|
|
|
70
86
|
}
|
|
71
87
|
function go(v,keep,sub){
|
|
72
88
|
if(v==='file'){if(!DATA||!sub)v='board';else curFile=sub;}
|
|
73
|
-
else if(NOPROJ.includes(v)){if(!TOKEN)v='board';} // no Home and no new
|
|
89
|
+
else if(NOPROJ.includes(v)){if(!TOKEN)v='board';} // no Home and no #new with --read-only
|
|
74
90
|
else if(!VIEWS[v]||v==='setup')v='board';
|
|
75
91
|
if(!NOPROJ.includes(v)&&DATA&&DATA.project.specs===false)v='setup'; // no .specs/ yet: every route of the project shows the setup view (BL-055)
|
|
76
92
|
curView=v;
|
|
77
|
-
$('#win').classList.toggle('home',v==='home');$('#win').classList.toggle('
|
|
78
|
-
$$('.content>.view').forEach(e=>e.classList.toggle('on',e.id==='v-'+(v==='new'
|
|
93
|
+
$('#win').classList.toggle('home',v==='home');$('#win').classList.toggle('insetup',v==='new'||v==='setup');
|
|
94
|
+
$$('.content>.view').forEach(e=>e.classList.toggle('on',e.id==='v-'+(v==='new'?'setup':v))); // one Setup view for both (BL-103)
|
|
79
95
|
syncNav();
|
|
80
|
-
$('#title').textContent=v==='file'?(TITLES[sub]||sub):v
|
|
81
|
-
|
|
96
|
+
$('#title').textContent=v==='file'?(TITLES[sub]||sub):VIEWS[v];$('#crumb').hidden=true;
|
|
97
|
+
if(v!=='new'&&browseCtl&&browseBtn&&browseBtn.id==='suBrowse')browseCtl.abort(); // leaving #new closes its folder dialog (BL-097)
|
|
82
98
|
$('#modeSeg').hidden=v!=='board';$('#newTask').hidden=!(TOKEN&&v==='board');$('#editorBtn').hidden=NOPROJ.includes(v);syncIde();
|
|
83
99
|
setNav(false);closeInsp();
|
|
84
|
-
if(v!=='file'||sub!==fileNoteFor)clearFileNote();
|
|
85
100
|
if(v==='home')loadRecent();
|
|
86
|
-
if(v==='setup')
|
|
87
|
-
if(v==='new')renderChat(true);
|
|
101
|
+
if(v==='setup'||v==='new')renderSetup();
|
|
88
102
|
if(v==='file')renderFile(sub);
|
|
89
103
|
if(v==='explorer')renderExplorer();
|
|
90
104
|
if(v==='security')renderSecurity();
|
|
@@ -102,7 +116,7 @@ function setHash(v,sub){const h='#'+(PROJECT&&!NOPROJ.includes(v)?PROJECT+'/':''
|
|
|
102
116
|
try{history.replaceState(null,'',h);}catch(e){urlOk=false;}}
|
|
103
117
|
function route(){
|
|
104
118
|
const r=resolveRoute(curHash(),DATA?DATA.files:{},DATA?DATA.projects.length:1,!!TOKEN);
|
|
105
|
-
if(NOPROJ.includes(r.view)){go(r.view);return;} // Home and
|
|
119
|
+
if(NOPROJ.includes(r.view)){go(r.view);return;} // Home and #new belong to no project: the shown one stays loaded behind them
|
|
106
120
|
if(r.project!==PROJECT){switchProject(r.project,true);return;}
|
|
107
121
|
if(r.view==='board'&&r.sub==='board'){mode='board';$$('#modeSeg button').forEach(x=>x.classList.toggle('on',x.dataset.m==='board'));renderTasks();}
|
|
108
122
|
go(r.view,true,r.sub);
|
|
@@ -368,7 +382,7 @@ document.addEventListener('keydown',e=>{
|
|
|
368
382
|
const mod=e.metaKey||e.ctrlKey;const inField=/INPUT|SELECT|TEXTAREA/.test(e.target.tagName);
|
|
369
383
|
if(mod&&e.key.toLowerCase()==='k'){e.preventDefault();palVeil.classList.contains('open')?closePal():openPal();return}
|
|
370
384
|
if(mod&&/^[1-9]$/.test(e.key)){e.preventDefault();const n=NAV[+e.key-1];if(n)go(n[0],false,n[1]);return}
|
|
371
|
-
if(e.key==='Escape'){if(!ideMenu.hidden){closeIde(true);return}hideTip();closeInsp();closePal();closeSheet();closeNewTask();
|
|
385
|
+
if(e.key==='Escape'){if(!ideMenu.hidden){closeIde(true);return}hideTip();closeInsp();closePal();closeSheet();closeNewTask();setNav(false);return}
|
|
372
386
|
if(inField||mod||e.altKey||taskVeil.classList.contains('open'))return;
|
|
373
387
|
if(e.key==='h'&&TOKEN&&!openVeil.classList.contains('open')){go('home');return;}
|
|
374
388
|
if(/^[1-9]$/.test(e.key)){const n=NAV[+e.key-1];if(n)go(n[0],false,n[1]);}
|
|
@@ -471,297 +485,106 @@ $('#taskCancel').onclick=closeNewTask;
|
|
|
471
485
|
taskVeil.onclick=e=>{if(e.target===taskVeil)closeNewTask();};
|
|
472
486
|
$('#taskForm').onsubmit=e=>{e.preventDefault();addTask();};
|
|
473
487
|
|
|
474
|
-
/* ----------------
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
if(
|
|
487
|
-
if(
|
|
488
|
-
if(
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
chat=null;comp=null;
|
|
509
|
-
if(!TOKEN){note.textContent='Started with --read-only, so nothing can be set up here.';note.hidden=false;return;}
|
|
510
|
-
const q=await getQuestions(isNew?'/api/projects/new':'/api/setup?project='+pj);
|
|
511
|
-
if(PROJECT!==pj||curView!==(isNew?'new':'setup'))return;
|
|
512
|
-
if(!q)return; // 404: not a folder named on the command line, so nothing to set up
|
|
513
|
-
if(q.error){note.textContent=q.error;note.hidden=false;return;}
|
|
514
|
-
let st;
|
|
515
|
-
if(isNew){
|
|
516
|
-
if(!curNew||!live[curNew]){st=freshSetup('new');curNew=st.id;live[st.id]=st;}
|
|
517
|
-
st=live[curNew];
|
|
518
|
-
}else{
|
|
519
|
-
const root=DATA.projects[pj].root,id='s:'+root;
|
|
520
|
-
st=live[id]||(live[id]=freshSetup('setup',root,id,seededAnswers(q.detected)));
|
|
521
|
-
}
|
|
522
|
-
chat={id:st.id,isNew,project:pj,q,st};
|
|
523
|
-
$('#cbody').hidden=false;
|
|
524
|
-
drawChat();
|
|
525
|
-
}
|
|
526
|
-
/* The questions to ask now: the server's (the CLI's) through flowQuestions(), placed and completed by the chat core. */
|
|
527
|
-
function chatAsk(){
|
|
528
|
-
const st=chat.st,first=chat.isNew?[{...PARENT_Q,step:chat.q.steps[0]}]:[];
|
|
529
|
-
return CC.chatQuestions([...first,...chat.q.questions],flowQuestions(chat.q,st.answers,first),st.answers,chat.isNew?'new':'setup',chat.q.files.outside);
|
|
530
|
-
}
|
|
531
|
-
/* What fills {name} and {language} in the bot lines. */
|
|
532
|
-
function chatCtx(){
|
|
533
|
-
const a=chat.st.answers,lq=chat.q.questions.find(x=>x.key==='language'),c=lq&&lq.choices.find(x=>x.value===a.language);
|
|
534
|
-
return {name:chat.isNew?a.name:projectLabel(DATA.projects[chat.project]),language:c?c.name:(chat.q.detected?chat.q.detected.language:'')};
|
|
535
|
-
}
|
|
536
|
-
/* What the detector filled in, for threadRows() and recapCards(): its rows, and the seeded answers not changed since. */
|
|
537
|
-
const chatDet=()=>chat.isNew?null:{rows:chat.q.detected?chat.q.detected.rows||[]:[],keys:detectedKeys(chat.st.seed,chat.st.answers)};
|
|
538
|
-
function drawChat(){
|
|
539
|
-
const st=chat.st,isNew=chat.isNew,ctx=chatCtx();
|
|
540
|
-
$('#chatRestart').hidden=!st.started;$('#chatClose').hidden=!isNew;
|
|
541
|
-
$('#title').textContent=isNew?(st.answers.name||'New project'):projectLabel(DATA.projects[chat.project]);
|
|
542
|
-
if(!st.started){ // the intro
|
|
543
|
-
$('#intro').hidden=false;$('#thread').hidden=$('#composer').hidden=true;$('#chatSub').textContent='';$('#barI').style.width='0';$('#v-chat .bar').setAttribute('aria-valuenow','0');
|
|
544
|
-
const mono=t=>`<span class="mono" translate="no">${esc(t)}</span>`;
|
|
545
|
-
// guided setup opens with its paragraph as the heading and no fine print (BL-PM-016); the New Project intro is as before
|
|
546
|
-
const setupLine=`There is no ${mono('.specs/')} folder in ${mono(DATA.projects[chat.project].root)} yet. I'll ask the same questions as ${mono('specpilot add-specs')}, one at a time, then write it and the files for your AI IDE. Existing files are never changed.`;
|
|
547
|
-
$('#introH').innerHTML=isNew?"Hey, I'm SpecPilot 👋":setupLine;$('#introH').classList.toggle('para',!isNew);
|
|
548
|
-
$('#introText').hidden=!isNew;$('#introText').innerHTML=isNew?'I turn your project requirements into a complete, structured spec suite - requirements, architecture, tests - and keep it in sync as you build.':'';
|
|
549
|
-
$('#introFine').hidden=!isNew;
|
|
550
|
-
$('#introText2').hidden=!isNew;$('#introText2').innerHTML=`I write your ${mono('.specs/')} folder, filled in from your answers, plus the files that keep your AI IDE following it.`;
|
|
551
|
-
const det=$('#introDetected');det.hidden=!(chat.q.detected);det.textContent=chat.q.detected?chat.q.detected.line:'';
|
|
552
|
-
$('#nameLbl').hidden=$('#nameIn').parentElement.hidden=!isNew;$('#setupStart').hidden=isNew;$('#nameErr').textContent='';
|
|
553
|
-
if(isNew){$('#nameIn').value=st.answers.name||'';$('#nameGo').disabled=!$('#nameIn').value.trim();}
|
|
554
|
-
setTimeout(()=>{if(chat&&!chat.st.started)(isNew?$('#nameIn'):$('#setupStart')).focus();},50);
|
|
555
|
-
return;
|
|
488
|
+
/* ---------------- Setup view (BL-103) ----------------
|
|
489
|
+
A project without .specs/ (Open, Clone, a folder named on the command line) and #new: the user's AI IDE
|
|
490
|
+
sets it up over /mcp, and this view says how. It sends no answers and writes no spec; the only request
|
|
491
|
+
is #new's pending path (POST /api/projects/pending). The Progress rows follow `event: setup`, which the
|
|
492
|
+
server's setup tools send (BL-104): state and counts only, kept in the page, so a reload starts them over. */
|
|
493
|
+
const mono=t=>`<span class="mono" translate="no">${esc(t)}</span>`;
|
|
494
|
+
const clonedFrom={}; // root → the URL this page cloned it from since it loaded: the Clone lead
|
|
495
|
+
const pend={name:'',parent:'',target:null,seq:0}; // #new's fields and its registered target
|
|
496
|
+
const ROWS=['read','questions','write','validate'];
|
|
497
|
+
const progress={}; // 'p<n>' or 'pending' → {row: {state, data}}
|
|
498
|
+
const progressKey=()=>curView==='new'?'pending':'p'+PROJECT;
|
|
499
|
+
function rowText(row,d){
|
|
500
|
+
if(row==='read')return `${d.detected} detected`;
|
|
501
|
+
if(row==='questions')return `${d.fromCode} from the code, ${d.fromUser} from you`+(d.fromUser&&d.topics&&d.topics.length?` (${d.topics.join(', ')})`:'');
|
|
502
|
+
if(row==='write')return `${d.files} files`;
|
|
503
|
+
return `${d.errors} errors, ${d.warnings} warnings`;
|
|
504
|
+
}
|
|
505
|
+
function drawProgress(){
|
|
506
|
+
const p=progress[progressKey()]||{};
|
|
507
|
+
$$('#suProgress li').forEach((li,i)=>{const r=p[ROWS[i]],st=r?r.state:'idle';
|
|
508
|
+
li.className=st==='running'?'run':st==='done'?'done':'wait';
|
|
509
|
+
let d=li.querySelector('.d');if(!d){d=document.createElement('span');d.className='d';li.appendChild(d);}
|
|
510
|
+
d.textContent=st==='done'?rowText(ROWS[i],r.data):'';});
|
|
511
|
+
}
|
|
512
|
+
/* An `event: setup` from the stream: the row of the folder it names; the last one of a new project opens it. */
|
|
513
|
+
function onSetupEvent(raw){
|
|
514
|
+
let d;try{d=JSON.parse(raw);}catch(_){return;}
|
|
515
|
+
if(!d||ROWS.indexOf(d.row)<0)return;
|
|
516
|
+
const key=d.pending?'pending':typeof d.project==='number'?'p'+d.project:null;if(!key)return;
|
|
517
|
+
(progress[key]=progress[key]||{})[d.row]={state:d.state,data:d};
|
|
518
|
+
if((curView==='setup'||curView==='new')&&key===progressKey())drawProgress();
|
|
519
|
+
if(d.pending&&typeof d.project==='number'&&d.row==='validate'&&d.state==='done'){
|
|
520
|
+
delete progress.pending;pend.target=null;pend.name=pend.parent='';
|
|
521
|
+
if(curView==='new')switchProject(d.project);
|
|
556
522
|
}
|
|
557
|
-
$('#intro').hidden=true;$('#thread').hidden=$('#composer').hidden=false;
|
|
558
|
-
const list=chatAsk(),cur=nextQuestion(list,st.answers,st.editing),steps=[...new Set(list.map(x=>x.step))],done=list.filter(x=>answered(x,st.answers)).length;
|
|
559
|
-
st.finished=!cur;
|
|
560
|
-
const bar=$('#v-chat .bar'),pct=Math.round(done/list.length*100);$('#barI').style.width=pct+'%';bar.setAttribute('aria-valuenow',pct);
|
|
561
|
-
$('#chatSub').textContent=cur?`Step ${steps.indexOf(cur.step)+1} of ${steps.length} · ${cur.step}`:'Review';
|
|
562
|
-
const det=chatDet(),detTag='<span class="det">detected</span>';
|
|
563
|
-
let html=threadRows(chat.q,list,st.answers,cur,ctx,isNew,det).map(r=>
|
|
564
|
-
r.kind==='divider'?`<div class="divider"><span>${esc(r.text)}</span></div>`
|
|
565
|
-
:r.kind==='note'?`<p class="cnote">${esc(r.text)}</p>`
|
|
566
|
-
:r.kind==='bot'?`<div class="bot"><svg class="logo" aria-hidden="true" focusable="false"><use href="#logo"/></svg><div class="msg">${esc(r.text)}${r.cli?`<span class="cli" translate="no">${esc(r.cli)}</span>`:''}${r.caption?`<span class="cap" translate="no">${esc(r.caption)}</span>`:''}</div></div>`
|
|
567
|
-
:r.key===null?`<div class="me fixed"><span class="b">${esc(r.text)}</span>${detTag}</div>` // detected, not editable
|
|
568
|
-
:`<div class="me${r.skipped?' skipped':''}"><button type="button" class="b${r.mono?' mono':''}" data-k="${esc(r.key)}" aria-label="Your answer: ${esc(r.text)}${r.detected?', detected':''}. Edit">${esc(r.text)}</button><span class="ed" aria-hidden="true">${r.detected?detTag+' ':''}✎ tap to edit</span></div>`).join('');
|
|
569
|
-
if(!cur){
|
|
570
|
-
const files=previewFiles(chat.q,st.answers),pv=st.preview,again=pv.done&&pv.changed;
|
|
571
|
-
html+=`<div class="recap"><svg class="logo" aria-hidden="true" focusable="false"><use href="#logo"/></svg><div class="card">That's everything I need. Here's a quick recap:<div class="pen">✎ Click any answer to change it. You come straight back here.</div><div class="grid">${recapCards(list,st.answers,det).map(c=>`<div class="rc"><div class="t">${esc(c.title)}</div>${c.rows.map(r=>r.key===null?`<div class="l fixed"><span>${esc(r.label)} ${detTag}</span><span translate="no">${esc(r.value)}</span></div>`:`<button type="button" class="l" data-k="${esc(r.key)}"><span>${esc(r.label)}${r.detected?' '+detTag:''}</span><span translate="no">${esc(r.value)}</span></button>`).join('')}</div>`).join('')}</div>${again?'<p class="chg">Answers changed since the last preview. Preview again to see the new files.</p>':''}<details id="pv"><summary>${again?'Preview again':'Preview files'} (${files.length})</summary><ul translate="no" id="pvList">${files.map(f=>`<li>${esc(f.path)}${f.kept?' <span class="kept">Already here, will be kept</span>':''}</li>`).join('')}</ul></details><button type="button" class="btn pri" id="chatCreate">${isNew?'Create Project':'Create .specs/'}</button><p class="err" id="chatErr" role="alert"></p></div></div>`;
|
|
572
|
-
}
|
|
573
|
-
$('#msgs').innerHTML=html;
|
|
574
|
-
const pvEl=$('#pv');if(pvEl)pvEl.addEventListener('toggle',()=>{if(pvEl.open)loadPreview();});
|
|
575
|
-
drawComposer(cur);
|
|
576
|
-
const th=$('#thread');th.scrollTop=th.scrollHeight;
|
|
577
|
-
}
|
|
578
|
-
/* The request body of a create or a preview: the CLI's answers, the optional fields and the folded context answers. */
|
|
579
|
-
function chatBody(){
|
|
580
|
-
const asked=chatAsk(),st=chat.st;
|
|
581
|
-
const body={...flowBody(asked.filter(x=>!x.core),st.answers),...CC.requestFields(asked,st.answers,chat.isNew?'new':'setup')};
|
|
582
|
-
if(chat.isNew)body.name=st.answers.name;
|
|
583
|
-
return body;
|
|
584
|
-
}
|
|
585
|
-
/* The recap's preview: POST /api/preview with the create body, each file then shown as render() gives it. */
|
|
586
|
-
async function loadPreview(){
|
|
587
|
-
const c=chat,body=chatBody(),list=$('#pvList');if(!list)return;
|
|
588
|
-
if(c.isNew)delete body.parent;
|
|
589
|
-
let r,res={};
|
|
590
|
-
try{r=await fetch(c.isNew?'/api/preview':'/api/preview?project='+c.project,{method:'POST',cache:'no-store',headers:{'Content-Type':'application/json','X-SpecPilot-Token':TOKEN},body:JSON.stringify(body)});res=await r.json().catch(()=>({}));}
|
|
591
|
-
catch(e){r=null;}
|
|
592
|
-
if(chat!==c||!$('#pvList'))return;
|
|
593
|
-
if(!r||r.status!==200){$('#pvList').insertAdjacentHTML('beforebegin',`<p class="err">${esc(r?res.error||`The preview could not be made (HTTP ${r.status}).`:'The server did not answer.')}</p>`);return;}
|
|
594
|
-
const kept=new Set(res.kept||[]);
|
|
595
|
-
$('#pvList').outerHTML=`<div class="pvl" id="pvList" translate="no">${res.files.map(f=>`<details class="pf"><summary>${esc(f.path)}${kept.has(f.path)?' <span class="kept">Already here, will be kept</span>':''}</summary>${kept.has(f.path)?'':/\.md$/.test(f.path)?`<div class="md">${md(f.content)}</div>`:`<pre>${esc(f.content)}</pre>`}</details>`).join('')}</div>`;
|
|
596
|
-
if(c.st.preview.changed||!c.st.preview.done)c.st.preview={done:true,changed:false};
|
|
597
|
-
const chg=$('#msgs .chg');if(chg)chg.remove();const sum=$('#pv summary');if(sum)sum.textContent=`Preview files (${res.files.length})`;
|
|
598
523
|
}
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
const
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
const
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
}
|
|
615
|
-
const
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
if(
|
|
619
|
-
|
|
620
|
-
const
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
h=tabsHtml(cats.map(x=>({id:x.id,label:`${x.emoji} ${x.label}`,count:(k.v[x.id]||[]).length})),tab)
|
|
641
|
-
+`<div class="chips" role="group" aria-label="${label}">${cat?cat.options.map(o=>optionHtml({id:o,label:o,emoji:o==='None'?'➖':''},(k.v[cat.id]||[]).includes(o))).join(''):''}</div>`+acts('<button type="button" class="btn" id="chatNone">None of these apply →</button>',true);
|
|
642
|
-
}else{
|
|
643
|
-
const opts=compOptions(cur),sel=isMulti(cur.type)?k.v:[k.v],extra=isMulti(cur.type)?k.v.filter(v=>!opts.some(o=>o.id===v)).map(v=>({id:v,label:v})):[];
|
|
644
|
-
const grouped=cur.type!=='grouped-multi'&&opts.some(o=>o.group),groups=[...new Set(opts.filter(o=>o.group).map(o=>o.group))],tab=groups.includes(k.tab)?k.tab:groups[0];
|
|
645
|
-
let body;
|
|
646
|
-
if(cur.type==='grouped-multi')body=groups.map(g=>`<p class="lbl">${esc(g)}</p><div class="chips">${opts.filter(o=>o.group===g).map(o=>optionHtml(o,sel.includes(o.id))).join('')}</div>`).join('')
|
|
647
|
-
+`<div class="chips">${[...opts.filter(o=>!o.group),...extra].map(o=>optionHtml(o,sel.includes(o.id))).join('')}${other}</div>`;
|
|
648
|
-
else body=(grouped?tabsHtml(groups.map(g=>({id:g,label:g,count:opts.filter(o=>o.group===g&&sel.includes(o.id)).length})),tab):'')
|
|
649
|
-
+`<div class="chips${cur.type==='cards'||opts.some(o=>o.description)?' grid2':''}" role="group" aria-label="${label}">${opts.filter(o=>!grouped||o.group===tab).map(o=>optionHtml(o,sel.includes(o.id))).join('')}</div>`
|
|
650
|
-
+`<div class="chips">${(grouped?opts.filter(o=>!o.group):[]).concat(extra).map(o=>optionHtml(o,sel.includes(o.id))).join('')}${other}</div>`;
|
|
651
|
-
const any=isMulti(cur.type)?k.v.length>0||!!k.custom.trim():!!k.v||!!(k.showCustom&&k.custom.trim());
|
|
652
|
-
h=note+body+customIn+acts(isMulti(cur.type)?'':skip,any||isMulti(cur.type)&&!cur.required);
|
|
653
|
-
}
|
|
654
|
-
c.innerHTML=h;
|
|
655
|
-
}
|
|
656
|
-
/* An answer: stored, stale seeds replaced, the preview marked out of date, the setup saved, and the chat moves on. */
|
|
657
|
-
function chatAnswer(cur,value){
|
|
658
|
-
const st=chat.st;
|
|
659
|
-
Object.assign(st.answers,cur.core?CC.answerPatch(cur.key,value,st.answers):{[cur.key]:value});
|
|
660
|
-
if(cur.seed!==undefined&&JSON.stringify(value)===JSON.stringify(cur.seed))st.seeded[cur.key]=value;else delete st.seeded[cur.key];
|
|
661
|
-
const r=CC.reseed(chatAsk(),st.answers,st.seeded);st.answers=r.answers;st.seeded=r.seeded;
|
|
662
|
-
if(st.preview.done)st.preview.changed=true;
|
|
663
|
-
st.editing=null;comp=null;drawChat();
|
|
664
|
-
}
|
|
665
|
-
function chatEdit(key){
|
|
666
|
-
if(chatBusy)return;
|
|
667
|
-
comp=null;
|
|
668
|
-
if(key==='name'){chat.st.started=false;drawChat();return;}
|
|
669
|
-
chat.st.editing=key;drawChat();
|
|
670
|
-
}
|
|
671
|
-
/* The same POST the forms sent: /api/setup for a folder without .specs/, /api/projects/new for a new project. */
|
|
672
|
-
async function chatCreate(){
|
|
673
|
-
if(chatBusy)return;
|
|
674
|
-
const c=chat,root=DATA.projects[c.project].root,btn=$('#chatCreate'),err=$('#chatErr');
|
|
675
|
-
chatBusy=true;btn.disabled=true;err.textContent='';
|
|
676
|
-
const body=chatBody();
|
|
524
|
+
const MCP_ON=!!(TOKEN&&MCP);
|
|
525
|
+
function suStatus(){
|
|
526
|
+
const c=DATA&&DATA.mcp&&DATA.mcp.client,el=$('#suStatus');
|
|
527
|
+
el.textContent=!MCP_ON?'':c?(c.name?'Connected · '+c.name:'Connected'):'Waiting for a connection';
|
|
528
|
+
el.classList.toggle('ok',!!c);
|
|
529
|
+
}
|
|
530
|
+
function suPrompt(){
|
|
531
|
+
const isNew=curView==='new';
|
|
532
|
+
$('#suPrompt').textContent=isNew?`Start a SpecPilot project called ${pend.name} in ${pend.parent}`:'Set up SpecPilot for '+DATA.project.root;
|
|
533
|
+
$('#suPromptCopy').disabled=!MCP_ON||isNew&&!pend.target;
|
|
534
|
+
const c=$('#crumb');c.hidden=isNew&&!pend.target;c.textContent=(isNew?pend.target:DATA.project.root)+' · no specs yet';
|
|
535
|
+
}
|
|
536
|
+
function renderSetup(){
|
|
537
|
+
const isNew=curView==='new',p=DATA.project,v=$('#v-setup');
|
|
538
|
+
const named=isNew||p.named!==false; // the current-directory default keeps REQ-002.H.17's heading only
|
|
539
|
+
$('#title').textContent=!named?`No .specs/ folder in ${DATA.projects[PROJECT].root}`:isNew?'Start a new project with SpecPilot':'Set up SpecPilot for this project';
|
|
540
|
+
const off=!TOKEN||!named;
|
|
541
|
+
[...v.children].forEach(el=>{if(el.id!=='suNote')el.hidden=off;});
|
|
542
|
+
$('#suNote').hidden=TOKEN||!named;$('#suNote').textContent='Started with --read-only, so nothing can be set up here.';
|
|
543
|
+
if(off){$('#crumb').hidden=!named;if(named)$('#crumb').textContent=p.root+' · no specs yet';return;}
|
|
544
|
+
const name=String(p.root).split(/[/\\]/).filter(Boolean).pop()||p.root,url=clonedFrom[p.root];
|
|
545
|
+
const tail=' Your AI IDE sets them up: it reads the code, answers what it can, and asks you the rest.';
|
|
546
|
+
$('#suLead').innerHTML=isNew?'Name the project and choose where it goes. Your AI IDE creates it and writes the specs from your answers.'
|
|
547
|
+
:url?`Cloned ${mono(url)}. It has no SpecPilot specs yet.${tail}`:`${mono(name)} has no SpecPilot specs yet.${tail}`;
|
|
548
|
+
$('#suNew').hidden=!isNew;
|
|
549
|
+
if(isNew){$('#suName').value=pend.name;$('#suParent').value=pend.parent;}
|
|
550
|
+
$('#suOff').hidden=MCP_ON;
|
|
551
|
+
$$('#v-setup .step').forEach(el=>{el.classList.toggle('off',!MCP_ON);el.inert=!MCP_ON;});
|
|
552
|
+
$('#suConfigBox').hidden=!MCP_ON;
|
|
553
|
+
if(MCP_ON){const env=MCP==='env',line=mcpConfigLine(location.host,env?'${SPECPILOT_MCP_TOKEN}':TOKEN);
|
|
554
|
+
$('#suConfig').textContent=JSON.stringify(JSON.parse(line),null,2);$('#suConfig').dataset.line=line;$('#suMcpNote').textContent=$('#mcpNote').textContent;}
|
|
555
|
+
else $('#suMcpNote').textContent='';
|
|
556
|
+
$('#suFoot').innerHTML=`Prefer the terminal? ${mono(isNew?'specpilot init':'specpilot add-specs')} in that folder asks the same questions one by one.`;
|
|
557
|
+
suStatus();suPrompt();drawProgress();
|
|
558
|
+
}
|
|
559
|
+
function copyText(text){(navigator.clipboard?navigator.clipboard.writeText(text):Promise.reject()).then(()=>toast('Copied.'),()=>toast('Could not copy. Select the line and copy it.'));}
|
|
560
|
+
$('#suConfigCopy').onclick=()=>copyText($('#suConfig').dataset.line);
|
|
561
|
+
$('#suPromptCopy').onclick=()=>copyText($('#suPrompt').textContent);
|
|
562
|
+
/* #new: when the name passes init's rule and a parent is typed, register <parent>/<name> as the one pending path. */
|
|
563
|
+
async function registerPending(){
|
|
564
|
+
const seq=++pend.seq,body={parent:pend.parent.trim(),name:pend.name};
|
|
677
565
|
let r,res={};
|
|
678
|
-
try{
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
toast('.specs/ created in '+root);
|
|
701
|
-
noteCreated(res);
|
|
702
|
-
$('#content').focus();
|
|
703
|
-
}
|
|
704
|
-
$('#introForm').onsubmit=e=>{
|
|
705
|
-
e.preventDefault();if(!chat)return;
|
|
706
|
-
if(chat.isNew){
|
|
707
|
-
const v=$('#nameIn').value.trim(),problem=answerError({key:'name',required:true},v);
|
|
708
|
-
if(problem){$('#nameErr').textContent=problem;$('#nameIn').focus();return;}
|
|
709
|
-
chat.st.answers.name=v;
|
|
710
|
-
}
|
|
711
|
-
chat.st.started=true;chat.st.editing=null;drawChat();
|
|
712
|
-
};
|
|
713
|
-
$('#nameIn').addEventListener('input',()=>{$('#nameGo').disabled=!$('#nameIn').value.trim();$('#nameErr').textContent='';});
|
|
714
|
-
$('#setupStart').onclick=()=>$('#introForm').requestSubmit();
|
|
715
|
-
const curQuestion=()=>chat&&nextQuestion(chatAsk(),chat.st.answers,chat.st.editing);
|
|
716
|
-
$('#comp').onsubmit=e=>{
|
|
717
|
-
e.preventDefault();if(!chat||chatBusy||!comp)return;
|
|
718
|
-
const cur=curQuestion();if(!cur||cur.key!==comp.key)return;
|
|
719
|
-
const fail=m=>{$('#compErr').textContent=m;const i=$('#chatIn');if(i){i.setAttribute('aria-invalid','true');i.focus();}};
|
|
720
|
-
if(cur.type==='text'||cur.type==='tabbed-chips'){
|
|
721
|
-
const v=$('#chatIn').value,problem=answerError(cur,v);
|
|
722
|
-
if(problem)return fail(problem);
|
|
723
|
-
return chatAnswer(cur,v.trim());
|
|
724
|
-
}
|
|
725
|
-
const custom=comp.custom.trim();
|
|
726
|
-
if(cur.type==='categorized')return chatAnswer(cur,comp.v);
|
|
727
|
-
if(isMulti(cur.type)){
|
|
728
|
-
const v=custom&&!comp.v.includes(custom)?[...comp.v,custom]:comp.v;
|
|
729
|
-
if(cur.required&&!v.length)return;
|
|
730
|
-
return chatAnswer(cur,v);
|
|
731
|
-
}
|
|
732
|
-
const v=comp.showCustom&&custom?custom:comp.v;
|
|
733
|
-
if(v)chatAnswer(cur,v);
|
|
734
|
-
};
|
|
735
|
-
$('#comp').addEventListener('click',e=>{
|
|
736
|
-
if(!chat||!comp)return;
|
|
737
|
-
const cur=curQuestion();if(!cur)return;
|
|
738
|
-
const t=e.target.closest('button');if(!t)return;
|
|
739
|
-
const redraw=sel=>{drawComposer(cur);const el=sel&&$(`#comp ${sel}`);if(el)el.focus();};
|
|
740
|
-
if(t.dataset.tab!==undefined){comp.tab=t.dataset.tab;return redraw(`.tab[data-tab="${CSS.escape(t.dataset.tab)}"]`);}
|
|
741
|
-
if(t.id==='chatOther'){comp.showCustom=!comp.showCustom;if(!isMulti(cur.type)&&comp.showCustom)comp.v='';return redraw(comp.showCustom?'#chatCustom':'#chatOther');}
|
|
742
|
-
if(t.id==='chatSkip'){if(!cur.required)chatAnswer(cur,isMulti(cur.type)?[]:'');return;}
|
|
743
|
-
if(t.id==='chatTodo'){chatAnswer(cur,cur.todo);return;}
|
|
744
|
-
if(t.id==='chatNone'){chatAnswer(cur,CC.noneOfThese(comp.v,CC.visibleCategories(chat.st.answers.projectCategory||null,CC.hasMobilePlatform(chat.st.answers.platforms||[]))));return;}
|
|
745
|
-
if(t.id==='chatCancel'){const k=chat.st.editing;chat.st.editing=null;comp=null;drawChat();const b=$(`#msgs [data-k="${k}"]`);if(b)b.focus();return;}
|
|
746
|
-
const v=t.dataset.v;if(v===undefined)return;
|
|
747
|
-
if(cur.type==='tabbed-chips'){comp.v=v;$('#chatIn').value=v;}
|
|
748
|
-
else if(cur.type==='platform-grid')comp.v=CC.togglePlatform(comp.v,v);
|
|
749
|
-
else if(cur.type==='categorized')comp.v=CC.toggleIntegration(comp.v,comp.tab||cur.categories[0].id,v);
|
|
750
|
-
else if(isMulti(cur.type))comp.v=comp.v.includes(v)?comp.v.filter(x=>x!==v):[...comp.v,v];
|
|
751
|
-
else{comp.v=v;comp.showCustom=false;}
|
|
752
|
-
redraw(`.chip[data-v="${CSS.escape(v)}"]`);
|
|
753
|
-
});
|
|
754
|
-
$('#comp').addEventListener('input',e=>{
|
|
755
|
-
if(!comp)return;
|
|
756
|
-
if(e.target.id==='chatIn'){$('#compErr').textContent='';e.target.removeAttribute('aria-invalid');comp.v=e.target.value;}
|
|
757
|
-
if(e.target.id==='chatCustom'){comp.custom=e.target.value;const go=$('#chatGo');if(go&&comp.custom.trim())go.disabled=false;}
|
|
758
|
-
});
|
|
759
|
-
$('#msgs').addEventListener('click',e=>{
|
|
760
|
-
if(e.target.id==='chatCreate'){chatCreate();return;}
|
|
761
|
-
const b=e.target.closest('[data-k]');if(b)chatEdit(b.dataset.k);
|
|
762
|
-
});
|
|
763
|
-
$('#chatRestart').onclick=()=>{if(!chat||chatBusy)return;chat.st=live[chat.st.id]=freshSetup(chat.st.kind,chat.st.root,chat.st.id,chat.st.seed);comp=null;drawChat();};
|
|
764
|
-
$('#chatClose').onclick=()=>{if(!chatBusy)go('home');};
|
|
566
|
+
try{r=await fetch('/api/projects/pending',{method:'POST',cache:'no-store',headers:{'Content-Type':'application/json','X-SpecPilot-Token':TOKEN},body:JSON.stringify(body)});res=await r.json().catch(()=>({}));}
|
|
567
|
+
catch(e){r=null;}
|
|
568
|
+
if(seq!==pend.seq)return; // the fields changed meanwhile
|
|
569
|
+
pend.target=r&&r.status===200?res.target:null;
|
|
570
|
+
delete progress.pending; // a new target starts its rows over
|
|
571
|
+
$('#suErr').textContent=!r?'The server did not answer.':r.status===200?'':res.error||`The folder was not accepted (HTTP ${r.status}).`;
|
|
572
|
+
if(curView==='new')suPrompt();
|
|
573
|
+
}
|
|
574
|
+
/* While typing: the line follows the fields and Copy waits; on `change` (or a Browse… pick) the path is registered (BL-104). */
|
|
575
|
+
function fieldsTyped(){
|
|
576
|
+
pend.name=$('#suName').value.trim();pend.parent=$('#suParent').value;pend.target=null;pend.seq++;
|
|
577
|
+
const e=pend.name?projectNameError(pend.name):null;
|
|
578
|
+
$('#suErr').textContent=e?e.message+'.':'';
|
|
579
|
+
suPrompt();
|
|
580
|
+
return !e&&pend.name&&pend.parent.trim();
|
|
581
|
+
}
|
|
582
|
+
function fieldsChanged(){if(fieldsTyped())registerPending();}
|
|
583
|
+
$('#suName').addEventListener('input',fieldsTyped);
|
|
584
|
+
$('#suParent').addEventListener('input',fieldsTyped);
|
|
585
|
+
$('#suName').addEventListener('change',fieldsChanged);
|
|
586
|
+
$('#suParent').addEventListener('change',fieldsChanged);
|
|
587
|
+
$('#suBrowse').onclick=()=>browseFolder($('#suBrowse'),()=>curView==='new'?$('#suParent'):null,()=>fieldsChanged());
|
|
765
588
|
|
|
766
589
|
/* ---------------- live reload (BL-052) ----------------
|
|
767
590
|
On a change event: re-fetch, redraw in place. Route, scroll, open inspector, selected row
|
|
@@ -823,10 +646,12 @@ async function apply(d,paths){
|
|
|
823
646
|
}
|
|
824
647
|
let es=null;
|
|
825
648
|
function listen(){
|
|
826
|
-
if(
|
|
649
|
+
if(stopped||!window.EventSource)return;
|
|
827
650
|
if(es)es.close(); // one stream, for the shown project
|
|
828
651
|
es=new EventSource('/api/events?'+pq());let dropped=false;
|
|
829
652
|
es.addEventListener('clone',e=>onCloneEvent(e.data));
|
|
653
|
+
es.addEventListener('setup',e=>onSetupEvent(e.data));
|
|
654
|
+
es.addEventListener('mcp',e=>{let d=null;try{d=JSON.parse(e.data);}catch(_){}if(d&&DATA){DATA.mcp=d;if(curView==='setup'||curView==='new')suStatus();}});
|
|
830
655
|
es.addEventListener('change',e=>{let paths=null;try{paths=JSON.parse(e.data).paths;}catch(_){}refresh(Array.isArray(paths)?paths:null);});
|
|
831
656
|
es.onerror=()=>{dropped=true;}; // EventSource retries by itself
|
|
832
657
|
es.onopen=()=>{if(dropped){dropped=false;refresh(null);}}; // catch up on anything missed
|
|
@@ -854,17 +679,16 @@ $('#projList').addEventListener('click',e=>{const b=e.target.closest('[data-proj
|
|
|
854
679
|
/* ---------------- open a project (BL-067) ----------------
|
|
855
680
|
The + tile opens the mockup's sheet on its Folder tab. The list is GET /api/projects; opening is
|
|
856
681
|
POST /api/projects, which serves one more folder and remembers it; Remove from list edits the
|
|
857
|
-
registry only. A new project
|
|
682
|
+
registry only. A new project starts in the Setup view above (BL-103). The Clone tab
|
|
858
683
|
(BL-PM-002) POSTs /api/projects/clone, which runs git clone and opens the folder; closing the sheet
|
|
859
684
|
meanwhile aborts the request, and the server then removes what was downloaded. Nothing here is
|
|
860
685
|
file content; the strings are the ones REQ-002.H.21, H.24 and H.26 list. */
|
|
861
686
|
const openVeil=$('#openVeil'),addBtn=$('#addBtn'),pathIn=$('#pathIn');
|
|
862
687
|
const TABS=['folder','clone'],GO={folder:'Open',clone:'Clone Repository'};
|
|
863
|
-
let openBusy=false,sheetFrom=$('#homeOpen'),sheetTab='folder',cloneCtl=null,cloneNamed=false,cloneTick=null,cloneT0=0,cloneProg=null;
|
|
688
|
+
let openBusy=false,sheetFrom=$('#homeOpen'),sheetTab='folder',cloneCtl=null,browseCtl=null,browseBtn=null,cloneNamed=false,cloneTick=null,cloneT0=0,cloneProg=null;
|
|
864
689
|
if(TOKEN){addBtn.hidden=false;homeBtn.hidden=false;$('#cmdRegen').hidden=false;$('#rail>.logo').remove();} // the Home tile takes the logo's place (BL-PM-001)
|
|
865
|
-
/* Connect Your AI IDE (BL-PM-007): the config line for this server's /mcp,
|
|
690
|
+
/* Connect Your AI IDE (BL-PM-007): the config line for this server's /mcp, unless --no-mcp (BL-105). No status here:
|
|
866
691
|
the page cannot know whether an IDE uses it. `env`: the token is SPECPILOT_MCP_TOKEN, so the line names it. */
|
|
867
|
-
const MCP=(document.querySelector('meta[name="specpilot-mcp"]')||{}).content||null;
|
|
868
692
|
if(TOKEN&&MCP){
|
|
869
693
|
const env=MCP==='env';
|
|
870
694
|
$('#mcpLine').textContent=mcpConfigLine(location.host,env?'${SPECPILOT_MCP_TOKEN}':TOKEN);
|
|
@@ -887,7 +711,7 @@ function setTab(t){
|
|
|
887
711
|
$('#openGo').textContent=GO[t];
|
|
888
712
|
if(t==='folder')loadRecent();
|
|
889
713
|
}
|
|
890
|
-
function closeSheet(){if(!openVeil.classList.contains('open'))return;if(cloneCtl)cloneCtl.abort();openVeil.classList.remove('open');sheetFrom.focus();}
|
|
714
|
+
function closeSheet(){if(!openVeil.classList.contains('open'))return;if(cloneCtl)cloneCtl.abort();if(browseCtl)browseCtl.abort();openVeil.classList.remove('open');sheetFrom.focus();}
|
|
891
715
|
/* The registry as GET /api/projects sends it: in the sheet, or on Home (BL-PM-001), where a row opens
|
|
892
716
|
its folder at once and a served project also shows the branch the rail tooltip shows. */
|
|
893
717
|
function drawRecent(reg,home){
|
|
@@ -930,7 +754,7 @@ async function showOutcome(o){
|
|
|
930
754
|
function setCloning(ctl){
|
|
931
755
|
cloneCtl=ctl;openBusy=!!ctl;
|
|
932
756
|
$('#openGo').disabled=!!ctl;
|
|
933
|
-
$$('#paneClone input, #openTabs button').forEach(el=>{el.disabled=!!ctl;});
|
|
757
|
+
$$('#paneClone input, #cloneBrowseBtn, #openTabs button').forEach(el=>{el.disabled=!!ctl;});
|
|
934
758
|
// The time since the click, and an indeterminate bar until git gives a percentage (BL-PM-009).
|
|
935
759
|
clearInterval(cloneTick);cloneTick=null;cloneProg=null;$('#cloneStatus').hidden=!ctl;
|
|
936
760
|
if(!ctl)return;
|
|
@@ -962,8 +786,32 @@ async function cloneRepo(){
|
|
|
962
786
|
}catch(e){setCloning(null);if(!ctl.signal.aborted)toast('The server did not answer.');return;}
|
|
963
787
|
setCloning(null);
|
|
964
788
|
if(ctl.signal.aborted)return; // the sheet was closed: the server removes the clone
|
|
789
|
+
if(r.status===200)clonedFrom[res.specs.project.root]=body.url; // the Setup view's Clone lead (BL-103)
|
|
965
790
|
await showOutcome(openOutcome(r.status,res,'cloned'));
|
|
966
791
|
}
|
|
792
|
+
/* Browse… (BL-PM-011, BL-097): the server opens the system's folder dialog; the folder picked fills the
|
|
793
|
+
button's field, and nothing is sent until the user does. One dialog at a time for the whole page. */
|
|
794
|
+
function setBrowsing(ctl,btn){
|
|
795
|
+
browseCtl=ctl;if(btn)browseBtn=btn;
|
|
796
|
+
const b=browseBtn;b.disabled=!!ctl||(b.id==='cloneBrowseBtn'&&!!cloneCtl); // a running clone keeps its sheet's button off
|
|
797
|
+
if(ctl)b.setAttribute('aria-busy','true');else b.removeAttribute('aria-busy');
|
|
798
|
+
}
|
|
799
|
+
/* `field()` is looked up after the answer: the view may have changed meanwhile. `pick` also sees the path. */
|
|
800
|
+
async function browseFolder(btn,field,pick){
|
|
801
|
+
if(browseCtl)return;
|
|
802
|
+
const ctl=new AbortController();setBrowsing(ctl,btn);
|
|
803
|
+
const back=()=>{if(btn.isConnected)btn.focus();};
|
|
804
|
+
let r,res={};
|
|
805
|
+
try{
|
|
806
|
+
r=await fetch('/api/projects/browse',{method:'POST',cache:'no-store',signal:ctl.signal,headers:{'Content-Type':'application/json','X-SpecPilot-Token':TOKEN},body:'{}'});
|
|
807
|
+
res=await r.json().catch(()=>({}));
|
|
808
|
+
}catch(e){setBrowsing(null);if(!ctl.signal.aborted){toast('The server did not answer.');back();}return;}
|
|
809
|
+
setBrowsing(null);
|
|
810
|
+
if(ctl.signal.aborted)return; // the sheet was closed or #new left: the server closes the dialog
|
|
811
|
+
if(r.status!==200){toast(res.error||`Nothing was chosen (HTTP ${r.status}).`);back();return;}
|
|
812
|
+
const f=res.path&&field();
|
|
813
|
+
if(f){f.value=res.path;if(pick)pick(res.path);f.focus();}else back();
|
|
814
|
+
}
|
|
967
815
|
async function removeRecent(path){
|
|
968
816
|
let out;
|
|
969
817
|
try{out=await postPath(path,'/api/projects/remove');}catch(e){toast('The server did not answer.');return;}
|
|
@@ -988,6 +836,8 @@ $('#homeBox').addEventListener('click',e=>{
|
|
|
988
836
|
const row=e.target.closest('[data-path]');if(row)openPath(row.dataset.path);
|
|
989
837
|
});
|
|
990
838
|
$('#openCancel').onclick=closeSheet;
|
|
839
|
+
$('#browseBtn').onclick=()=>browseFolder($('#browseBtn'),()=>pathIn);
|
|
840
|
+
$('#cloneBrowseBtn').onclick=()=>browseFolder($('#cloneBrowseBtn'),()=>$('#cloneParentIn'));
|
|
991
841
|
openVeil.onclick=e=>{if(e.target===openVeil)closeSheet();};
|
|
992
842
|
$('#openForm').onsubmit=e=>{e.preventDefault();if(sheetTab==='clone')cloneRepo();else openPath(pathIn.value.trim());};
|
|
993
843
|
$('#recentBox').addEventListener('click',e=>{
|