specpilot 2.10.0 → 2.12.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 +11 -8
- package/dist/__tests__/fixtures/allFields.d.ts +3 -0
- package/dist/__tests__/fixtures/allFields.d.ts.map +1 -0
- package/dist/__tests__/fixtures/allFields.js +31 -0
- package/dist/__tests__/fixtures/allFields.js.map +1 -0
- package/dist/commands/serve.js +2 -2
- package/dist/commands/serve.js.map +1 -1
- package/dist/core/chatFlow.d.ts +420 -0
- package/dist/core/chatFlow.d.ts.map +1 -0
- package/dist/core/chatFlow.js +1107 -0
- package/dist/core/chatFlow.js.map +1 -0
- package/dist/core/specFiles.js +21 -21
- package/dist/core/templateEngine.d.ts.map +1 -1
- package/dist/core/templateEngine.js +15 -4
- package/dist/core/templateEngine.js.map +1 -1
- package/dist/utils/addSpecsQuestions.d.ts +2 -1
- package/dist/utils/addSpecsQuestions.d.ts.map +1 -1
- package/dist/utils/addSpecsQuestions.js +2 -1
- package/dist/utils/addSpecsQuestions.js.map +1 -1
- package/dist/utils/initQuestions.d.ts +2 -1
- package/dist/utils/initQuestions.d.ts.map +1 -1
- package/dist/utils/initQuestions.js +2 -1
- package/dist/utils/initQuestions.js.map +1 -1
- package/dist/utils/slashCommandGenerator.d.ts +7 -1
- package/dist/utils/slashCommandGenerator.d.ts.map +1 -1
- package/dist/utils/slashCommandGenerator.js +95 -28
- package/dist/utils/slashCommandGenerator.js.map +1 -1
- package/dist/utils/specBackfiller.d.ts +1 -1
- package/dist/utils/specBackfiller.d.ts.map +1 -1
- package/dist/utils/specBackfiller.js.map +1 -1
- package/dist/utils/specReader.d.ts +4 -0
- package/dist/utils/specReader.d.ts.map +1 -1
- package/dist/utils/specReader.js +4 -4
- package/dist/utils/specReader.js.map +1 -1
- package/dist/utils/specServer.d.ts +31 -4
- package/dist/utils/specServer.d.ts.map +1 -1
- package/dist/utils/specServer.js +148 -16
- package/dist/utils/specServer.js.map +1 -1
- package/dist/utils/specSetup.d.ts +21 -4
- package/dist/utils/specSetup.d.ts.map +1 -1
- package/dist/utils/specSetup.js +113 -20
- package/dist/utils/specSetup.js.map +1 -1
- package/dist/utils/taskMover.d.ts +42 -0
- package/dist/utils/taskMover.d.ts.map +1 -1
- package/dist/utils/taskMover.js +177 -25
- package/dist/utils/taskMover.js.map +1 -1
- package/package.json +1 -1
- package/ui/OFL-Sixtyfour.txt +93 -0
- package/ui/app.css +59 -3
- package/ui/app.js +280 -59
- package/ui/index.html +33 -6
- package/ui/route.js +71 -8
package/ui/app.js
CHANGED
|
@@ -47,7 +47,7 @@ function renderProject(){
|
|
|
47
47
|
return `<button class="tile blue${cur?' cur':''}" data-project="${i}" data-tip="${esc(n)}" data-path="${esc(q.root+(q.branch?' · '+q.branch:''))}" aria-label="${esc(n)}"${cur?' aria-current="true"':''}><span aria-hidden="true">${esc(initials(n))}</span></button>`;}).join('');
|
|
48
48
|
$('#curGrp').textContent=name;$('#curGrp').title=p.root;
|
|
49
49
|
$('#curBranch').textContent=p.branch||'';
|
|
50
|
-
$('#subName').textContent=name;$('#subPath').textContent=where;
|
|
50
|
+
$('#subName').textContent=name;$('#subPath').textContent=where;$('#editorBtn').href=editorUrl(p.root);
|
|
51
51
|
$('#footAddr').textContent=$('#homeAddr').textContent=location.host;$('#footVer').textContent=$('#homeVer').textContent='v'+p.specpilotVersion;
|
|
52
52
|
document.title=name+' · SpecPilot Local';
|
|
53
53
|
}
|
|
@@ -78,8 +78,8 @@ function go(v,keep,sub){
|
|
|
78
78
|
$$('.content>.view').forEach(e=>e.classList.toggle('on',e.id==='v-'+(v==='new'||v==='setup'?'chat':v))); // one chat section for both flows (BL-PM-004)
|
|
79
79
|
syncNav();
|
|
80
80
|
$('#title').textContent=v==='file'?(TITLES[sub]||sub):v==='setup'?projectLabel(DATA.projects[PROJECT]):v==='new'?'New project':VIEWS[v];
|
|
81
|
-
$('#chatSub').hidden=!(v==='new'||v==='setup');if(v!=='new'&&v!=='setup'){$('#chatRestart').hidden=$('#chatClose').hidden=true;chat=null;}
|
|
82
|
-
$('#modeSeg').hidden=v!=='board';
|
|
81
|
+
$('#chatSub').hidden=!(v==='new'||v==='setup');if(v!=='new'&&v!=='setup'){$('#chatRestart').hidden=$('#chatClose').hidden=$('#chatSetups').hidden=true;chat=null;}
|
|
82
|
+
$('#modeSeg').hidden=v!=='board';$('#newTask').hidden=!(TOKEN&&v==='board');$('#editorBtn').hidden=NOPROJ.includes(v);
|
|
83
83
|
setNav(false);closeInsp();
|
|
84
84
|
if(v!=='file'||sub!==fileNoteFor)clearFileNote();
|
|
85
85
|
if(v==='home')loadRecent();
|
|
@@ -198,6 +198,7 @@ function openTask(col,i,quiet){
|
|
|
198
198
|
insp.innerHTML=`<div class="ih">${col==='completed'?`<span class="id" translate="no">${esc(t.num)}</span>`:''}<span class="id" translate="no">${mdi(t.id)}</span><span class="pill ${col==='completed'?'green':col==='currentSprint'?'orange':'gray'}">${esc(COLS[col])}</span><button type="button" class="ib x" id="inspX" aria-label="Close Details"><svg class="ico" aria-hidden="true" focusable="false"><use href="#i-x"/></svg></button></div>
|
|
199
199
|
<div class="ib2">
|
|
200
200
|
<div class="gl"><div class="gh">Description <span class="cnt" translate="no">tasks.md · ## ${esc(COLS[col])}</span></div><div class="box"><div class="desc md">${md(t.description)}</div></div></div>
|
|
201
|
+
<div class="actions"><a class="btn sm" href="${esc(editorUrl(DATA.project.root+'/.specs/planning/tasks.md',t.line))}">Open tasks.md in VS Code</a></div>
|
|
201
202
|
</div>`;
|
|
202
203
|
openInsp(quiet);
|
|
203
204
|
}
|
|
@@ -258,12 +259,32 @@ function fileRows(list){
|
|
|
258
259
|
return `<button type="button" class="row act" data-open="${esc(f.path)}"><span class="st hollow" aria-hidden="true"></span><div class="body"><div class="ttl"><span class="id" translate="no">${esc(f.path)}</span>${fm['argument-hint']!==undefined?`<span class="id" translate="no">${esc(fm['argument-hint'])}</span>`:''}</div>${fm.description!==undefined?`<div class="det">${esc(fm.description)}</div>`:''}</div><div class="trail">${fm['allowed-tools']!==undefined?`<span class="pill gray" translate="no">${esc(fm['allowed-tools'])}</span>`:''}${chev}</div></button>`;}).join('')
|
|
259
260
|
:'<div class="empty">No files here.</div>';
|
|
260
261
|
}
|
|
262
|
+
/* From SpecPilot / Yours (BL-PM-006): the server's `generated` flag decides; rows keep their full path. */
|
|
263
|
+
function fileGroup(list,box,cnt,ours){const l=list.filter(f=>!!f.generated===ours);$(box).innerHTML=fileRows(l);$(cnt).textContent=l.length;}
|
|
261
264
|
function renderAgentFiles(){
|
|
262
|
-
const N=DATA.nav;
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
265
|
+
const N=DATA.nav,cmds=[...N.commands,...N.prompts];
|
|
266
|
+
fileGroup(cmds,'#cmdBox','#cmdSpCnt',true);fileGroup(cmds,'#cmdMine','#cmdYouCnt',false);
|
|
267
|
+
fileGroup(N.skills,'#sklBox','#sklSpCnt',true);fileGroup(N.skills,'#sklMine','#sklYouCnt',false);
|
|
268
|
+
}
|
|
269
|
+
/* Regenerate All (BL-PM-006): the server runs specpilot backfill's command step; its result lines are shown as sent,
|
|
270
|
+
until the next run or a project switch. */
|
|
271
|
+
function setRegenNote(lines){const n=$('#regenNote');n.innerHTML=lines.map(l=>`<p class="note" translate="no">${esc(l)}</p>`).join('');n.hidden=!lines.length;}
|
|
272
|
+
async function regenerate(){
|
|
273
|
+
const b=$('#cmdRegen'),p=PROJECT,had=document.activeElement===b;if(b.disabled)return;
|
|
274
|
+
b.disabled=true; // drops focus; given back below
|
|
275
|
+
let r,body={};
|
|
276
|
+
try{
|
|
277
|
+
r=await fetch('/api/commands/regenerate?'+pq(),{method:'POST',cache:'no-store',headers:{'Content-Type':'application/json','X-SpecPilot-Token':TOKEN},body:'{}'});
|
|
278
|
+
body=await r.json().catch(()=>({}));
|
|
279
|
+
}catch(e){r=null;}
|
|
280
|
+
b.disabled=false;
|
|
281
|
+
if(p!==PROJECT)return;
|
|
282
|
+
if(!r)setRegenNote(['The server did not answer. Command files may have been partly written.']);
|
|
283
|
+
else if(r.status===200){await apply(body.specs,null);setRegenNote(body.message);}
|
|
284
|
+
else setRegenNote([(body.error||`Regenerate All did not run (HTTP ${r.status}).`)+(r.status===500?' Command files may have been partly written.':'')]);
|
|
285
|
+
if(had&&document.activeElement===document.body)b.focus();
|
|
286
|
+
}
|
|
287
|
+
$('#cmdRegen').onclick=regenerate;
|
|
267
288
|
/* Inspector for a generated file: its front matter raw, its body rendered. */
|
|
268
289
|
/* Is this generated file in the latest /api/specs listing? */
|
|
269
290
|
function listed(path){const N=DATA.nav;return N.instructions.some(f=>f.exists&&f.path===path)||[N.commands,N.prompts,N.skills].some(l=>l.some(f=>f.path===path));}
|
|
@@ -300,8 +321,8 @@ document.addEventListener('keydown',e=>{
|
|
|
300
321
|
const mod=e.metaKey||e.ctrlKey;const inField=/INPUT|SELECT|TEXTAREA/.test(e.target.tagName);
|
|
301
322
|
if(mod&&e.key.toLowerCase()==='k'){e.preventDefault();palVeil.classList.contains('open')?closePal():openPal();return}
|
|
302
323
|
if(mod&&/^[1-9]$/.test(e.key)){e.preventDefault();const n=NAV[+e.key-1];if(n)go(n[0],false,n[1]);return}
|
|
303
|
-
if(e.key==='Escape'){hideTip();closeInsp();closePal();closeSheet();if(chat&&chat.st.editing&&!chatBusy){chat.st.editing=null;drawChat();}setNav(false);return}
|
|
304
|
-
if(inField||mod||e.altKey)return;
|
|
324
|
+
if(e.key==='Escape'){hideTip();closeInsp();closePal();closeSheet();closeNewTask();if(chat&&chat.st.editing&&!chatBusy){chat.st.editing=null;comp=null;drawChat();}setNav(false);return}
|
|
325
|
+
if(inField||mod||e.altKey||taskVeil.classList.contains('open'))return;
|
|
305
326
|
if(e.key==='h'&&TOKEN&&!openVeil.classList.contains('open')){go('home');return;}
|
|
306
327
|
if(/^[1-9]$/.test(e.key)){const n=NAV[+e.key-1];if(n)go(n[0],false,n[1]);}
|
|
307
328
|
if((e.key==='j'||e.key==='k')&&curView==='board'){const rows=$$((mode==='board'?'#boardMode':'#listMode')+' .row[data-col]');if(!rows.length)return;let i=rows.findIndex(r=>r.dataset.col+':'+r.dataset.i===selected);i=e.key==='j'?Math.min(rows.length-1,i+1):Math.max(0,i-1);if(i<0)i=0;openTask(rows[i].dataset.col,+rows[i].dataset.i);rows[i].scrollIntoView({block:'nearest'});rows[i].focus();}
|
|
@@ -362,6 +383,47 @@ async function move(col,i,toSection,toIndex,isUndo){
|
|
|
362
383
|
}else toast(body.error||`The move was not made (HTTP ${r.status}).`);
|
|
363
384
|
}
|
|
364
385
|
|
|
386
|
+
/* ---------------- new task (BL-PM-005) ----------------
|
|
387
|
+
The server appends one row, `| <ID> | <description> |`, to the chosen section and picks the ID.
|
|
388
|
+
The description goes as typed; a refusal is shown in the form with what was typed kept. */
|
|
389
|
+
const taskVeil=$('#taskVeil'),taskIn=$('#taskIn');
|
|
390
|
+
let taskSection='backlog',adding=false;
|
|
391
|
+
function setTaskSection(s){taskSection=s;$$('#taskSec button').forEach(b=>{const on=b.dataset.s===s;b.classList.toggle('on',on);b.setAttribute('aria-pressed',on);});}
|
|
392
|
+
function taskError(m){const e=$('#taskErr');e.textContent=m||'';e.hidden=!m;}
|
|
393
|
+
function openNewTask(){if(!TOKEN||!DATA||!DATA.tasks)return;hideTip();taskIn.value='';taskError('');setTaskSection('backlog');taskVeil.classList.add('open');setTimeout(()=>taskIn.focus(),50);}
|
|
394
|
+
function closeNewTask(){if(!taskVeil.classList.contains('open')||adding)return;taskVeil.classList.remove('open');$('#newTask').focus();}
|
|
395
|
+
async function addTask(){
|
|
396
|
+
if(adding)return;
|
|
397
|
+
if(!taskIn.value.trim()){taskError('Type a description for the task.');taskIn.focus();return;}
|
|
398
|
+
const p=PROJECT,section=taskSection;
|
|
399
|
+
adding=true;$('#taskGo').disabled=true;taskError('');
|
|
400
|
+
let r,body={};
|
|
401
|
+
try{
|
|
402
|
+
r=await fetch('/api/tasks/new?'+pq(),{method:'POST',cache:'no-store',headers:{'Content-Type':'application/json','X-SpecPilot-Token':TOKEN,'If-Match':DATA.tasks.sha256},body:JSON.stringify({description:taskIn.value,section})});
|
|
403
|
+
body=await r.json().catch(()=>({}));
|
|
404
|
+
}catch(e){r=null;}
|
|
405
|
+
adding=false;$('#taskGo').disabled=false;
|
|
406
|
+
if(!r){taskError('The server did not answer. Nothing was added.');return;}
|
|
407
|
+
if(p!==PROJECT)return;
|
|
408
|
+
if(r.status===200){
|
|
409
|
+
if(section==='backlog'&&body.index>=6)showAllBacklog=true;
|
|
410
|
+
taskVeil.classList.remove('open');
|
|
411
|
+
await apply(body.specs,['.specs/planning/tasks.md']);
|
|
412
|
+
$('#newTask').focus(); // what closing the inspector returns to
|
|
413
|
+
openTask(section,body.index);
|
|
414
|
+
const el=$(`${mode==='board'?'#boardMode':'#listMode'} .row[data-col="${section}"][data-i="${body.index}"]`);if(el)el.scrollIntoView({block:'nearest'});
|
|
415
|
+
toast(`${body.id} added to ## ${COLS[section]} in planning/tasks.md`);
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
if(r.status===409&&body.specs)await apply(body.specs,null);
|
|
419
|
+
taskError(body.error||`The task was not added (HTTP ${r.status}).`);taskIn.focus();
|
|
420
|
+
}
|
|
421
|
+
$('#newTask').onclick=openNewTask;
|
|
422
|
+
$$('#taskSec button').forEach(b=>b.onclick=()=>setTaskSection(b.dataset.s));
|
|
423
|
+
$('#taskCancel').onclick=closeNewTask;
|
|
424
|
+
taskVeil.onclick=e=>{if(e.target===taskVeil)closeNewTask();};
|
|
425
|
+
$('#taskForm').onsubmit=e=>{e.preventDefault();addTask();};
|
|
426
|
+
|
|
365
427
|
/* ---------------- setup chat (BL-055, BL-PM-004) ----------------
|
|
366
428
|
The init.specpilot.dev chat over the CLI's own questions: for a new project (#new) and for a named
|
|
367
429
|
folder with no .specs/ yet (its setup view). The questions, their chat lines, choices, steps and file
|
|
@@ -382,38 +444,74 @@ async function getQuestions(url){
|
|
|
382
444
|
try{const r=await fetch(url,{cache:'no-store'});if(r.ok)return await r.json();return r.status===404?null:{error:(await r.json().catch(()=>({}))).error||'HTTP '+r.status};}
|
|
383
445
|
catch(e){return {error:'The server did not answer.'};}
|
|
384
446
|
}
|
|
385
|
-
/* The page's own question of a new project; every other one is the server's. */
|
|
447
|
+
/* The page's own question of a new project; every other one is the server's or the chat core's. */
|
|
386
448
|
const PARENT_Q={key:'parent',message:'Parent folder',label:'Folder',required:true,chat:"Nice, {name}. Where should it live? I'll create {name}/ inside this folder.",placeholder:'~/dev'};
|
|
387
|
-
const
|
|
388
|
-
|
|
449
|
+
const CC=window.SpecPilotChat; // the chat core (BL-PM-004b): src/core/chatFlow.ts, served as /assets/chat-core.js
|
|
450
|
+
/* Saved setups (BL-PM-004b): every setup the chat has started, kept in this browser under sp-setups. */
|
|
451
|
+
let storeOk=true,setups=[];
|
|
452
|
+
try{setups=setupsLoad(localStorage.getItem(SETUPS_KEY));}catch(e){storeOk=false;}
|
|
453
|
+
function storeSetups(){try{localStorage.setItem(SETUPS_KEY,JSON.stringify(setups));}catch(e){storeOk=false;}}
|
|
454
|
+
function saveSetup(st){if(!st.started)return;st.updatedAt=Date.now();setups=setupsPut(setups,setupRecord(st));storeSetups();}
|
|
455
|
+
function dropSetup(id){setups=setupsRemove(setups,id);storeSetups();}
|
|
456
|
+
const freshSetup=(kind,root,id)=>({id:id||(kind==='setup'?'s:'+root:'n'+Date.now().toString(36)+Math.random().toString(36).slice(2,6)),kind,root,answers:{},editing:null,started:false,seeded:{},preview:{done:false,changed:false},finished:false});
|
|
457
|
+
const restoreSetup=e=>({...JSON.parse(JSON.stringify(e)),editing:null});
|
|
458
|
+
const live={}; // the setups open in this page, by id
|
|
459
|
+
let curNew=null; // the new-project setup #new shows
|
|
460
|
+
let chat=null,chatBusy=false,comp=null;
|
|
389
461
|
/* Shown by go(): the chat for a new project, or for the project without .specs/. */
|
|
390
462
|
async function renderChat(isNew){
|
|
391
|
-
const pj=PROJECT,
|
|
392
|
-
$('#intro').hidden=$('#thread').hidden=$('#composer').hidden=note.hidden=true;$('#chatRestart').hidden=$('#chatClose').hidden=true;
|
|
393
|
-
chat=null;
|
|
463
|
+
const pj=PROJECT,note=$('#chatNote');
|
|
464
|
+
$('#intro').hidden=$('#thread').hidden=$('#composer').hidden=note.hidden=true;$('#chatRestart').hidden=$('#chatClose').hidden=$('#chatSetups').hidden=true;$('#cbody').hidden=true;
|
|
465
|
+
chat=null;comp=null;
|
|
394
466
|
if(!TOKEN){note.textContent='Started with --read-only, so nothing can be set up here.';note.hidden=false;return;}
|
|
395
467
|
const q=await getQuestions(isNew?'/api/projects/new':'/api/setup?project='+pj);
|
|
396
468
|
if(PROJECT!==pj||curView!==(isNew?'new':'setup'))return;
|
|
397
469
|
if(!q)return; // 404: not a folder named on the command line, so nothing to set up
|
|
398
470
|
if(q.error){note.textContent=q.error;note.hidden=false;return;}
|
|
399
|
-
|
|
471
|
+
let st;
|
|
472
|
+
if(isNew){
|
|
473
|
+
if(!curNew||!live[curNew]){const rec=curNew&&setups.find(e=>e.id===curNew);st=rec?restoreSetup(rec):freshSetup('new');curNew=st.id;live[st.id]=st;}
|
|
474
|
+
st=live[curNew];
|
|
475
|
+
}else{
|
|
476
|
+
const root=DATA.projects[pj].root,id='s:'+root,rec=setups.find(e=>e.id===id);
|
|
477
|
+
st=live[id]||(live[id]=rec?restoreSetup(rec):freshSetup('setup',root));
|
|
478
|
+
}
|
|
479
|
+
chat={id:st.id,isNew,project:pj,q,st};
|
|
480
|
+
$('#cbody').hidden=false;
|
|
400
481
|
drawChat();
|
|
401
482
|
}
|
|
402
|
-
|
|
483
|
+
/* The questions to ask now: the server's (the CLI's) through flowQuestions(), placed and completed by the chat core. */
|
|
484
|
+
function chatAsk(){
|
|
485
|
+
const st=chat.st,first=chat.isNew?[{...PARENT_Q,step:chat.q.steps[0]}]:[];
|
|
486
|
+
return CC.chatQuestions([...first,...chat.q.questions],flowQuestions(chat.q,st.answers,first),st.answers,chat.isNew?'new':'setup',chat.q.files.outside);
|
|
487
|
+
}
|
|
403
488
|
/* What fills {name} and {language} in the bot lines. */
|
|
404
489
|
function chatCtx(){
|
|
405
490
|
const a=chat.st.answers,lq=chat.q.questions.find(x=>x.key==='language'),c=lq&&lq.choices.find(x=>x.value===a.language);
|
|
406
491
|
return {name:chat.isNew?a.name:projectLabel(DATA.projects[chat.project]),language:c?c.name:(chat.q.detected?chat.q.detected.language:'')};
|
|
407
492
|
}
|
|
493
|
+
/* The list of saved setups beside the thread. */
|
|
494
|
+
function drawSetups(){
|
|
495
|
+
const el=$('#setupList');
|
|
496
|
+
if(!storeOk){el.innerHTML='<p class="note">Setups cannot be saved in this browser.</p>';return;}
|
|
497
|
+
const served=root=>DATA.projects.findIndex(p=>p.root===root);
|
|
498
|
+
el.innerHTML=setups.length?setups.map(e=>{
|
|
499
|
+
const off=e.kind==='setup'&&served(e.root)<0,t=setupTitle(e);
|
|
500
|
+
return `<div class="srow2${chat&&chat.st.id===e.id?' cur':''}"><button type="button" class="go" data-setup="${esc(e.id)}"${off?' disabled':''}><span class="t" translate="no">${esc(t)}</span><span class="d">${esc(off?`Open ${e.root} to resume`:`${setupStatus(e)} · ${when(new Date(e.updatedAt).toISOString())}`)}</span></button><button type="button" class="rm" data-rm-setup="${esc(e.id)}" aria-label="Remove ${esc(t)}">Remove</button></div>`;
|
|
501
|
+
}).join(''):'<p class="note">No saved setups yet.</p>';
|
|
502
|
+
}
|
|
408
503
|
function drawChat(){
|
|
409
504
|
const st=chat.st,isNew=chat.isNew,ctx=chatCtx();
|
|
410
|
-
$('#chatRestart').hidden=!st.started;$('#chatClose').hidden=!isNew;
|
|
505
|
+
$('#chatRestart').hidden=!st.started;$('#chatClose').hidden=!isNew;$('#chatSetups').hidden=false;
|
|
411
506
|
$('#title').textContent=isNew?(st.answers.name||'New project'):projectLabel(DATA.projects[chat.project]);
|
|
507
|
+
drawSetups();
|
|
412
508
|
if(!st.started){ // the intro
|
|
413
509
|
$('#intro').hidden=false;$('#thread').hidden=$('#composer').hidden=true;$('#chatSub').textContent='';$('#barI').style.width='0';$('#v-chat .bar').setAttribute('aria-valuenow','0');
|
|
414
510
|
const mono=t=>`<span class="mono" translate="no">${esc(t)}</span>`;
|
|
415
|
-
$('#
|
|
511
|
+
$('#introH').textContent=isNew?"Hey, I'm SpecPilot 👋":"Hey, I'm SpecPilot";
|
|
512
|
+
$('#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.'
|
|
416
513
|
:`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.`;
|
|
514
|
+
$('#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.`;
|
|
417
515
|
const det=$('#introDetected');det.hidden=!(chat.q.detected);det.textContent=chat.q.detected?chat.q.detected.line:'';
|
|
418
516
|
$('#nameLbl').hidden=$('#nameIn').parentElement.hidden=!isNew;$('#setupStart').hidden=isNew;$('#nameErr').textContent='';
|
|
419
517
|
if(isNew){$('#nameIn').value=st.answers.name||'';$('#nameGo').disabled=!$('#nameIn').value.trim();}
|
|
@@ -421,50 +519,123 @@ function drawChat(){
|
|
|
421
519
|
return;
|
|
422
520
|
}
|
|
423
521
|
$('#intro').hidden=true;$('#thread').hidden=$('#composer').hidden=false;
|
|
424
|
-
const list=
|
|
522
|
+
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;
|
|
523
|
+
if(st.finished!==!cur){st.finished=!cur;saveSetup(st);drawSetups();}
|
|
425
524
|
const bar=$('#v-chat .bar'),pct=Math.round(done/list.length*100);$('#barI').style.width=pct+'%';bar.setAttribute('aria-valuenow',pct);
|
|
426
525
|
$('#chatSub').textContent=cur?`Step ${steps.indexOf(cur.step)+1} of ${steps.length} · ${cur.step}`:'Review';
|
|
427
526
|
let html=threadRows(chat.q,list,st.answers,cur,ctx,isNew).map(r=>
|
|
428
527
|
r.kind==='divider'?`<div class="divider"><span>${esc(r.text)}</span></div>`
|
|
429
|
-
:r.kind==='
|
|
528
|
+
:r.kind==='note'?`<p class="cnote">${esc(r.text)}</p>`
|
|
529
|
+
: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>`
|
|
430
530
|
:`<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)}. Edit">${esc(r.text)}</button><span class="ed" aria-hidden="true">✎ tap to edit</span></div>`).join('');
|
|
431
531
|
if(!cur){
|
|
432
|
-
const files=previewFiles(chat.q,st.answers);
|
|
433
|
-
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).map(c=>`<div class="rc"><div class="t">${esc(c.title)}</div>${c.rows.map(r=>`<button type="button" class="l" data-k="${esc(r.key)}"><span>${esc(r.label)}</span><span translate="no">${esc(r.value)}</span></button>`).join('')}</div>`).join('')}</div
|
|
532
|
+
const files=previewFiles(chat.q,st.answers),pv=st.preview,again=pv.done&&pv.changed;
|
|
533
|
+
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).map(c=>`<div class="rc"><div class="t">${esc(c.title)}</div>${c.rows.map(r=>`<button type="button" class="l" data-k="${esc(r.key)}"><span>${esc(r.label)}</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>`;
|
|
434
534
|
}
|
|
435
535
|
$('#msgs').innerHTML=html;
|
|
536
|
+
const pvEl=$('#pv');if(pvEl)pvEl.addEventListener('toggle',()=>{if(pvEl.open)loadPreview();});
|
|
436
537
|
drawComposer(cur);
|
|
437
538
|
const th=$('#thread');th.scrollTop=th.scrollHeight;
|
|
438
539
|
}
|
|
540
|
+
/* The request body of a create or a preview: the CLI's answers, the optional fields and the folded context answers. */
|
|
541
|
+
function chatBody(){
|
|
542
|
+
const asked=chatAsk(),st=chat.st;
|
|
543
|
+
const body={...flowBody(asked.filter(x=>!x.core),st.answers),...CC.requestFields(asked,st.answers,chat.isNew?'new':'setup')};
|
|
544
|
+
if(chat.isNew)body.name=st.answers.name;
|
|
545
|
+
return body;
|
|
546
|
+
}
|
|
547
|
+
/* The recap's preview: POST /api/preview with the create body, each file then shown as render() gives it. */
|
|
548
|
+
async function loadPreview(){
|
|
549
|
+
const c=chat,body=chatBody(),list=$('#pvList');if(!list)return;
|
|
550
|
+
if(c.isNew)delete body.parent;
|
|
551
|
+
let r,res={};
|
|
552
|
+
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(()=>({}));}
|
|
553
|
+
catch(e){r=null;}
|
|
554
|
+
if(chat!==c||!$('#pvList'))return;
|
|
555
|
+
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;}
|
|
556
|
+
const kept=new Set(res.kept||[]);
|
|
557
|
+
$('#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>`;
|
|
558
|
+
if(c.st.preview.changed||!c.st.preview.done){c.st.preview={done:true,changed:false};saveSetup(c.st);}
|
|
559
|
+
const chg=$('#msgs .chg');if(chg)chg.remove();const sum=$('#pv summary');if(sum)sum.textContent=`Preview files (${res.files.length})`;
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
/* ---- the composer: one state per shown question (`comp`), drawn from the question and redrawn on every change */
|
|
563
|
+
const isMulti=t=>t==='multi'||t==='grouped-multi'||t==='platform-grid';
|
|
564
|
+
function initComp(cur){
|
|
565
|
+
const a=chat.st.answers,stored=cur.answered?a[cur.key]:undefined,seed=stored===undefined?cur.seed:stored;
|
|
566
|
+
const c={key:cur.key,tab:null,custom:'',showCustom:false};
|
|
567
|
+
if(cur.type==='categorized')c.v=JSON.parse(JSON.stringify(seed||{}));
|
|
568
|
+
else if(isMulti(cur.type))c.v=Array.isArray(seed)?[...seed]:[];
|
|
569
|
+
else if(cur.type==='text'||cur.type==='tabbed-chips')c.v=typeof stored==='string'&&stored!==cur.todo?stored:'';
|
|
570
|
+
else{c.v=typeof seed==='string'?seed:'';const ids=compOptions(cur).map(o=>o.id);if(cur.custom&&c.v&&!ids.includes(c.v)){c.custom=c.v;c.showCustom=true;c.v='';}}
|
|
571
|
+
const opts=compOptions(cur),sel=Array.isArray(c.v)?c.v:[c.v];
|
|
572
|
+
const withSel=opts.find(o=>o.group&&sel.includes(o.id))||opts.find(o=>o.group&&o.badge==='recommended')||opts.find(o=>o.group);
|
|
573
|
+
c.tab=cur.type==='categorized'?(cur.categories[0]&&cur.categories[0].id):withSel?withSel.group:null;
|
|
574
|
+
if(cur.type==='platform-grid'){const tabs=CC.platformGridGroups(a.projectCategory||null,c.v);c.tab=tabs.find(t=>c.v.some(id=>CC.PLATFORM_GROUPS.find(g=>g.group===t).items.some(i=>i.id===id)))||tabs[0];}
|
|
575
|
+
return c;
|
|
576
|
+
}
|
|
577
|
+
const compOptions=cur=>cur.core?(cur.options||[]):choiceOptions(cur);
|
|
439
578
|
function drawComposer(cur){
|
|
440
579
|
const st=chat.st,c=$('#comp'),editing=!!st.editing;
|
|
441
|
-
if(!cur){c.innerHTML=`<div class="act"><span class="hint">All answered. Review above, then ${chat.isNew?'Create Project':'Create .specs/'}.</span></div>`;return;}
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
580
|
+
if(!cur){comp=null;c.innerHTML=`<div class="act"><span class="hint">All answered. Review above, then ${chat.isNew?'Create Project':'Create .specs/'}.</span></div>`;return;}
|
|
581
|
+
if(!comp||comp.key!==cur.key)comp=initComp(cur);
|
|
582
|
+
const label=esc(cur.message||cur.chat||cur.label),k=comp,acts=(extra,ok)=>`<div class="act"><span class="hint">${editing?'Changing an earlier answer':''}</span><span class="err" id="compErr" role="alert"></span>${editing?'<button type="button" class="btn" id="chatCancel">Cancel</button>':''}${extra||''}<button type="submit" class="btn pri" id="chatGo"${ok?'':' disabled'}>${isMulti(cur.type)&&k.v.length?`Continue (${k.v.length+(k.custom.trim()?1:0)})`:'Continue'}</button></div>`;
|
|
583
|
+
const skip=cur.required?'':'<button type="button" class="btn" id="chatSkip">Skip</button>';
|
|
584
|
+
const other=cur.custom?`<button type="button" class="chip other" id="chatOther" aria-pressed="${k.showCustom}"><b>${cur.type==='grouped-multi'?'Add custom user type':'Other: ___'}</b></button>`:'';
|
|
585
|
+
const customIn=k.showCustom?`<div class="crow"><input type="text" id="chatCustom" maxlength="100" placeholder="Type your own" aria-label="Your own answer" value="${esc(k.custom)}"></div>`:'';
|
|
586
|
+
const note=cur.note?`<p class="cnote">${esc(cur.note)}</p>`:'';
|
|
587
|
+
let h='';
|
|
588
|
+
if(cur.type==='text'){
|
|
589
|
+
const max=cur.key==='parent'?4096:cur.key==='handle'?39:cur.key==='nonGoals'?870:1000;
|
|
590
|
+
h=`<div class="crow"><input type="text" id="chatIn" class="${cur.key==='parent'||cur.key==='handle'?'mono':''}" placeholder="${esc(cur.placeholder||'')}" aria-label="${label}" aria-describedby="compErr" maxlength="${max}"${cur.required?' aria-required="true"':''} value="${esc(k.v)}"></div>`
|
|
591
|
+
+acts((cur.todo?'<button type="button" class="btn" id="chatTodo">Not sure - skip for now</button>':'')+skip,true);
|
|
592
|
+
}else if(cur.type==='tabbed-chips'){
|
|
593
|
+
const groups=[...new Set(cur.options.map(o=>o.group))],tab=k.tab||groups[0];
|
|
594
|
+
h=`<p class="lbl">Pick a starter project type from below</p>${tabsHtml(groups.map(g=>({id:g,label:g})),tab)}<div class="chips" role="group" aria-label="${label}">${cur.options.filter(o=>o.group===tab).map(o=>optionHtml(o,k.v===o.id)).join('')}</div><p class="lbl">Or describe your project idea in plain words below</p><div class="crow"><input type="text" id="chatIn" placeholder="${esc(cur.placeholder||'')}" aria-label="${label}" aria-describedby="compErr" maxlength="1000" aria-required="true" value="${esc(k.v)}"></div>`+acts('',true);
|
|
595
|
+
}else if(cur.type==='platform-grid'){
|
|
596
|
+
const tabs=CC.platformGridGroups(st.answers.projectCategory||null,k.v),tab=tabs.includes(k.tab)?k.tab:tabs[0],g=CC.PLATFORM_GROUPS.find(x=>x.group===tab);
|
|
597
|
+
const line=CC.bundleLine(k.v);
|
|
598
|
+
h=tabsHtml(tabs.map(t=>{const grp=CC.PLATFORM_GROUPS.find(x=>x.group===t);return {id:t,label:`${grp.emoji} ${t}`,count:k.v.filter(id=>grp.items.some(i=>i.id===id)).length};}),tab)
|
|
599
|
+
+`<div class="chips grid2" role="group" aria-label="${label}">${g?g.items.map(i=>optionHtml({id:i.id,label:i.label,emoji:i.emoji,description:`[${i.lang}]`},k.v.includes(i.id))).join(''):''}</div>${line?`<p class="cnote">${esc(line)}</p>`:''}`+acts('',k.v.length>0);
|
|
600
|
+
}else if(cur.type==='categorized'){
|
|
601
|
+
const cats=cur.categories,tab=cats.some(x=>x.id===k.tab)?k.tab:cats[0]&&cats[0].id,cat=cats.find(x=>x.id===tab);
|
|
602
|
+
h=tabsHtml(cats.map(x=>({id:x.id,label:`${x.emoji} ${x.label}`,count:(k.v[x.id]||[]).length})),tab)
|
|
603
|
+
+`<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);
|
|
448
604
|
}else{
|
|
449
|
-
|
|
450
|
-
|
|
605
|
+
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})):[];
|
|
606
|
+
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];
|
|
607
|
+
let body;
|
|
608
|
+
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('')
|
|
609
|
+
+`<div class="chips">${[...opts.filter(o=>!o.group),...extra].map(o=>optionHtml(o,sel.includes(o.id))).join('')}${other}</div>`;
|
|
610
|
+
else body=(grouped?tabsHtml(groups.map(g=>({id:g,label:g,count:opts.filter(o=>o.group===g&&sel.includes(o.id)).length})),tab):'')
|
|
611
|
+
+`<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>`
|
|
612
|
+
+`<div class="chips">${(grouped?opts.filter(o=>!o.group):[]).concat(extra).map(o=>optionHtml(o,sel.includes(o.id))).join('')}${other}</div>`;
|
|
613
|
+
const any=isMulti(cur.type)?k.v.length>0||!!k.custom.trim():!!k.v||!!(k.showCustom&&k.custom.trim());
|
|
614
|
+
h=note+body+customIn+acts(isMulti(cur.type)?'':skip,any||isMulti(cur.type)&&!cur.required);
|
|
451
615
|
}
|
|
616
|
+
c.innerHTML=h;
|
|
452
617
|
}
|
|
453
|
-
/* An answer: stored,
|
|
618
|
+
/* An answer: stored, stale seeds replaced, the preview marked out of date, the setup saved, and the chat moves on. */
|
|
454
619
|
function chatAnswer(cur,value){
|
|
455
|
-
|
|
620
|
+
const st=chat.st;
|
|
621
|
+
Object.assign(st.answers,cur.core?CC.answerPatch(cur.key,value,st.answers):{[cur.key]:value});
|
|
622
|
+
if(cur.seed!==undefined&&JSON.stringify(value)===JSON.stringify(cur.seed))st.seeded[cur.key]=value;else delete st.seeded[cur.key];
|
|
623
|
+
const r=CC.reseed(chatAsk(),st.answers,st.seeded);st.answers=r.answers;st.seeded=r.seeded;
|
|
624
|
+
if(st.preview.done)st.preview.changed=true;
|
|
625
|
+
st.editing=null;comp=null;saveSetup(st);drawChat();
|
|
456
626
|
}
|
|
457
627
|
function chatEdit(key){
|
|
458
628
|
if(chatBusy)return;
|
|
629
|
+
comp=null;
|
|
459
630
|
if(key==='name'){chat.st.started=false;drawChat();return;}
|
|
460
631
|
chat.st.editing=key;drawChat();
|
|
461
632
|
}
|
|
462
633
|
/* The same POST the forms sent: /api/setup for a folder without .specs/, /api/projects/new for a new project. */
|
|
463
634
|
async function chatCreate(){
|
|
464
635
|
if(chatBusy)return;
|
|
465
|
-
const c=chat,
|
|
636
|
+
const c=chat,root=DATA.projects[c.project].root,btn=$('#chatCreate'),err=$('#chatErr');
|
|
466
637
|
chatBusy=true;btn.disabled=true;err.textContent='';
|
|
467
|
-
const body=
|
|
638
|
+
const body=chatBody();
|
|
468
639
|
let r,res={};
|
|
469
640
|
try{
|
|
470
641
|
r=await fetch(c.isNew?'/api/projects/new':'/api/setup?project='+c.project,{method:'POST',cache:'no-store',headers:{'Content-Type':'application/json','X-SpecPilot-Token':TOKEN},body:JSON.stringify(body)});
|
|
@@ -474,16 +645,17 @@ async function chatCreate(){
|
|
|
474
645
|
if(chat!==c)return; // the view changed meanwhile
|
|
475
646
|
btn.disabled=false;
|
|
476
647
|
if(!r){err.textContent=c.isNew?'The server did not answer.':'The server did not answer. Nothing was set up.';return;}
|
|
648
|
+
const done=()=>{dropSetup(c.st.id);delete live[c.st.id];if(curNew===c.st.id)curNew=null;};
|
|
477
649
|
if(c.isNew){
|
|
478
650
|
const o=openOutcome(r.status,res,true);
|
|
479
|
-
if(o.project===null){err.textContent=o.toast;return;}
|
|
480
|
-
if(r.status===200)
|
|
651
|
+
if(o.project===null){err.textContent=r.status===413?'The answers are too long to send. Shorten the longest ones and try again.':o.toast;return;}
|
|
652
|
+
if(r.status===200)done();
|
|
481
653
|
await showOutcome(o);
|
|
482
654
|
if(r.status===200)noteCreated(res);
|
|
483
655
|
return;
|
|
484
656
|
}
|
|
485
657
|
if(r.status!==200&&!(r.status===409&&res.specs)){err.textContent=res.error||`Nothing was set up (HTTP ${r.status}).`;return;}
|
|
486
|
-
|
|
658
|
+
done();
|
|
487
659
|
if(PROJECT!==c.project)return;
|
|
488
660
|
await apply(res.specs,null);
|
|
489
661
|
if(r.status!==200){toast(res.error||`Nothing was set up (HTTP ${r.status}).`);return;}
|
|
@@ -498,30 +670,76 @@ $('#introForm').onsubmit=e=>{
|
|
|
498
670
|
if(problem){$('#nameErr').textContent=problem;$('#nameIn').focus();return;}
|
|
499
671
|
chat.st.answers.name=v;
|
|
500
672
|
}
|
|
501
|
-
chat.st.started=true;chat.st.editing=null;drawChat();
|
|
673
|
+
chat.st.started=true;chat.st.editing=null;saveSetup(chat.st);drawChat();
|
|
502
674
|
};
|
|
503
675
|
$('#nameIn').addEventListener('input',()=>{$('#nameGo').disabled=!$('#nameIn').value.trim();$('#nameErr').textContent='';});
|
|
504
676
|
$('#setupStart').onclick=()=>$('#introForm').requestSubmit();
|
|
677
|
+
const curQuestion=()=>chat&&nextQuestion(chatAsk(),chat.st.answers,chat.st.editing);
|
|
505
678
|
$('#comp').onsubmit=e=>{
|
|
506
|
-
e.preventDefault();if(!chat||chatBusy)return;
|
|
507
|
-
const cur=
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
679
|
+
e.preventDefault();if(!chat||chatBusy||!comp)return;
|
|
680
|
+
const cur=curQuestion();if(!cur||cur.key!==comp.key)return;
|
|
681
|
+
const fail=m=>{$('#compErr').textContent=m;const i=$('#chatIn');if(i){i.setAttribute('aria-invalid','true');i.focus();}};
|
|
682
|
+
if(cur.type==='text'||cur.type==='tabbed-chips'){
|
|
683
|
+
const v=$('#chatIn').value,problem=answerError(cur,v);
|
|
684
|
+
if(problem)return fail(problem);
|
|
685
|
+
return chatAnswer(cur,v.trim());
|
|
686
|
+
}
|
|
687
|
+
const custom=comp.custom.trim();
|
|
688
|
+
if(cur.type==='categorized')return chatAnswer(cur,comp.v);
|
|
689
|
+
if(isMulti(cur.type)){
|
|
690
|
+
const v=custom&&!comp.v.includes(custom)?[...comp.v,custom]:comp.v;
|
|
691
|
+
if(cur.required&&!v.length)return;
|
|
692
|
+
return chatAnswer(cur,v);
|
|
693
|
+
}
|
|
694
|
+
const v=comp.showCustom&&custom?custom:comp.v;
|
|
695
|
+
if(v)chatAnswer(cur,v);
|
|
512
696
|
};
|
|
513
697
|
$('#comp').addEventListener('click',e=>{
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
698
|
+
if(!chat||!comp)return;
|
|
699
|
+
const cur=curQuestion();if(!cur)return;
|
|
700
|
+
const t=e.target.closest('button');if(!t)return;
|
|
701
|
+
const redraw=sel=>{drawComposer(cur);const el=sel&&$(`#comp ${sel}`);if(el)el.focus();};
|
|
702
|
+
if(t.dataset.tab!==undefined){comp.tab=t.dataset.tab;return redraw(`.tab[data-tab="${CSS.escape(t.dataset.tab)}"]`);}
|
|
703
|
+
if(t.id==='chatOther'){comp.showCustom=!comp.showCustom;if(!isMulti(cur.type)&&comp.showCustom)comp.v='';return redraw(comp.showCustom?'#chatCustom':'#chatOther');}
|
|
704
|
+
if(t.id==='chatSkip'){if(!cur.required)chatAnswer(cur,isMulti(cur.type)?[]:'');return;}
|
|
705
|
+
if(t.id==='chatTodo'){chatAnswer(cur,cur.todo);return;}
|
|
706
|
+
if(t.id==='chatNone'){chatAnswer(cur,CC.noneOfThese(comp.v,CC.visibleCategories(chat.st.answers.projectCategory||null,CC.hasMobilePlatform(chat.st.answers.platforms||[]))));return;}
|
|
707
|
+
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;}
|
|
708
|
+
const v=t.dataset.v;if(v===undefined)return;
|
|
709
|
+
if(cur.type==='tabbed-chips'){comp.v=v;$('#chatIn').value=v;}
|
|
710
|
+
else if(cur.type==='platform-grid')comp.v=CC.togglePlatform(comp.v,v);
|
|
711
|
+
else if(cur.type==='categorized')comp.v=CC.toggleIntegration(comp.v,comp.tab||cur.categories[0].id,v);
|
|
712
|
+
else if(isMulti(cur.type))comp.v=comp.v.includes(v)?comp.v.filter(x=>x!==v):[...comp.v,v];
|
|
713
|
+
else{comp.v=v;comp.showCustom=false;}
|
|
714
|
+
redraw(`.chip[data-v="${CSS.escape(v)}"]`);
|
|
715
|
+
});
|
|
716
|
+
$('#comp').addEventListener('input',e=>{
|
|
717
|
+
if(!comp)return;
|
|
718
|
+
if(e.target.id==='chatIn'){$('#compErr').textContent='';e.target.removeAttribute('aria-invalid');comp.v=e.target.value;}
|
|
719
|
+
if(e.target.id==='chatCustom'){comp.custom=e.target.value;const go=$('#chatGo');if(go&&comp.custom.trim())go.disabled=false;}
|
|
518
720
|
});
|
|
519
|
-
$('#comp').addEventListener('input',e=>{if(e.target.id==='chatIn'){$('#compErr').textContent='';e.target.removeAttribute('aria-invalid');}});
|
|
520
721
|
$('#msgs').addEventListener('click',e=>{
|
|
521
722
|
if(e.target.id==='chatCreate'){chatCreate();return;}
|
|
522
723
|
const b=e.target.closest('[data-k]');if(b)chatEdit(b.dataset.k);
|
|
523
724
|
});
|
|
524
|
-
$('#
|
|
725
|
+
$('#setupList').addEventListener('click',e=>{
|
|
726
|
+
if(chatBusy)return;
|
|
727
|
+
const rm=e.target.closest('[data-rm-setup]');
|
|
728
|
+
if(rm){
|
|
729
|
+
if(!confirm('Remove this setup?'))return;
|
|
730
|
+
const id=rm.dataset.rmSetup;dropSetup(id);delete live[id];
|
|
731
|
+
if(chat&&chat.st.id===id){if(curNew===id)curNew=null;renderChat(chat.isNew);}else drawSetups();
|
|
732
|
+
return;
|
|
733
|
+
}
|
|
734
|
+
const b=e.target.closest('[data-setup]');if(!b)return;
|
|
735
|
+
const s=setups.find(x=>x.id===b.dataset.setup);if(!s)return;
|
|
736
|
+
$('#cbody').classList.remove('lst');
|
|
737
|
+
if(s.kind==='new'){curNew=s.id;if(curView==='new')renderChat(true);else go('new');return;}
|
|
738
|
+
const i=DATA.projects.findIndex(p=>p.root===s.root);if(i>=0)location.hash='#'+i+'/board';
|
|
739
|
+
});
|
|
740
|
+
$('#setupNew').onclick=()=>{if(chatBusy)return;curNew=null;$('#cbody').classList.remove('lst');if(curView==='new')renderChat(true);else go('new');};
|
|
741
|
+
$('#chatSetups').onclick=()=>$('#cbody').classList.toggle('lst');
|
|
742
|
+
$('#chatRestart').onclick=()=>{if(!chat||chatBusy)return;dropSetup(chat.st.id);chat.st=live[chat.st.id]=freshSetup(chat.st.kind,chat.st.root,chat.st.id);comp=null;drawChat();};
|
|
525
743
|
$('#chatClose').onclick=()=>{if(!chatBusy)go('home');};
|
|
526
744
|
|
|
527
745
|
/* ---------------- live reload (BL-052) ----------------
|
|
@@ -604,7 +822,7 @@ async function switchProject(n,keepRoute){
|
|
|
604
822
|
/* Draw project PROJECT from payload d: the tail of a switch, also used with the payload an open returns (BL-067). */
|
|
605
823
|
function showProject(d,keepRoute){
|
|
606
824
|
Object.keys(fileCache).forEach(k=>{delete fileCache[k];});secShown.clear();
|
|
607
|
-
DATA=d;selected=null;
|
|
825
|
+
DATA=d;selected=null;setRegenNote([]);
|
|
608
826
|
renderProject();renderTasks();renderIde();renderAgentFiles();listen();
|
|
609
827
|
if(keepRoute)route();else go('board');
|
|
610
828
|
}
|
|
@@ -620,8 +838,8 @@ $('#projList').addEventListener('click',e=>{const b=e.target.closest('[data-proj
|
|
|
620
838
|
file content; the strings are the ones REQ-002.H.21, H.24 and H.26 list. */
|
|
621
839
|
const openVeil=$('#openVeil'),addBtn=$('#addBtn'),pathIn=$('#pathIn');
|
|
622
840
|
const TABS=['folder','clone'],GO={folder:'Open',clone:'Clone Repository'};
|
|
623
|
-
let openBusy=false,sheetFrom
|
|
624
|
-
if(TOKEN){addBtn.hidden=false;homeBtn.hidden=false;$('#rail>.logo').remove();} // the Home tile takes the logo's place (BL-PM-001)
|
|
841
|
+
let openBusy=false,sheetFrom=$('#homeOpen'),sheetTab='folder',cloneCtl=null,cloneNamed=false,cloneTick=null;
|
|
842
|
+
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)
|
|
625
843
|
function openSheet(from,tab){
|
|
626
844
|
hideTip();sheetFrom=from;openVeil.classList.add('open');
|
|
627
845
|
$$('#openForm .field input').forEach(el=>{el.value='';});cloneNamed=false;
|
|
@@ -636,7 +854,7 @@ function setTab(t){
|
|
|
636
854
|
}
|
|
637
855
|
function closeSheet(){if(!openVeil.classList.contains('open'))return;if(cloneCtl)cloneCtl.abort();openVeil.classList.remove('open');sheetFrom.focus();}
|
|
638
856
|
/* The registry as GET /api/projects sends it: in the sheet, or on Home (BL-PM-001), where a row opens
|
|
639
|
-
its folder at once
|
|
857
|
+
its folder at once and a served project also shows the branch the rail tooltip shows. */
|
|
640
858
|
function drawRecent(reg,home){
|
|
641
859
|
$(home?'#homePath':'#recentPath').textContent=reg.path||'';
|
|
642
860
|
$(home?'#homeBox':'#recentBox').innerHTML=recentHtml(reg,home,DATA?DATA.projects:[],chev);
|
|
@@ -702,7 +920,7 @@ async function removeRecent(path){
|
|
|
702
920
|
try{out=await postPath(path,'/api/projects/remove');}catch(e){toast('The server did not answer.');return;}
|
|
703
921
|
if(out.r.status===200){drawRecent(out.res);if(curView==='home')drawRecent(out.res,true);}else toast(out.res.error||`Nothing was removed (HTTP ${out.r.status}).`);
|
|
704
922
|
}
|
|
705
|
-
addBtn.onclick=()=>
|
|
923
|
+
addBtn.onclick=()=>{go('home');$('#homeOpen').focus();}; // every new project starts from Home (BL-PM-014); only Home's buttons open the sheet
|
|
706
924
|
homeBtn.onclick=()=>go('home');
|
|
707
925
|
$('#homeOpen').onclick=e=>openSheet(e.currentTarget);
|
|
708
926
|
$('#homeNew').onclick=()=>go('new');
|
|
@@ -716,7 +934,10 @@ $('#openTabs').addEventListener('keydown',e=>{
|
|
|
716
934
|
e.preventDefault();const n=TABS.length,i=TABS.indexOf(sheetTab),t=TABS[e.key==='Home'?0:e.key==='End'?n-1:(i+(e.key==='ArrowLeft'?n-1:1))%n];
|
|
717
935
|
setTab(t);$(`#openTabs [data-t="${t}"]`).focus();
|
|
718
936
|
});
|
|
719
|
-
$('#homeBox').addEventListener('click',e=>{
|
|
937
|
+
$('#homeBox').addEventListener('click',e=>{
|
|
938
|
+
const rm=e.target.closest('[data-remove]');if(rm){removeRecent(rm.dataset.remove);return;}
|
|
939
|
+
const row=e.target.closest('[data-path]');if(row)openPath(row.dataset.path);
|
|
940
|
+
});
|
|
720
941
|
$('#openCancel').onclick=closeSheet;
|
|
721
942
|
openVeil.onclick=e=>{if(e.target===openVeil)closeSheet();};
|
|
722
943
|
$('#openForm').onsubmit=e=>{e.preventDefault();if(sheetTab==='clone')cloneRepo();else openPath(pathIn.value.trim());};
|