specpilot 2.5.0 → 2.7.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.
Files changed (59) hide show
  1. package/README.md +10 -6
  2. package/dist/cli.js +5 -3
  3. package/dist/cli.js.map +1 -1
  4. package/dist/commands/add-specs.d.ts.map +1 -1
  5. package/dist/commands/add-specs.js +17 -46
  6. package/dist/commands/add-specs.js.map +1 -1
  7. package/dist/commands/backfill.js +1 -1
  8. package/dist/commands/backfill.js.map +1 -1
  9. package/dist/commands/init.d.ts.map +1 -1
  10. package/dist/commands/init.js +3 -0
  11. package/dist/commands/init.js.map +1 -1
  12. package/dist/commands/serve.d.ts +6 -2
  13. package/dist/commands/serve.d.ts.map +1 -1
  14. package/dist/commands/serve.js +51 -9
  15. package/dist/commands/serve.js.map +1 -1
  16. package/dist/utils/addSpecsQuestions.d.ts +34 -0
  17. package/dist/utils/addSpecsQuestions.d.ts.map +1 -0
  18. package/dist/utils/addSpecsQuestions.js +55 -0
  19. package/dist/utils/addSpecsQuestions.js.map +1 -0
  20. package/dist/utils/agentConfigGenerator.d.ts +2 -0
  21. package/dist/utils/agentConfigGenerator.d.ts.map +1 -1
  22. package/dist/utils/agentConfigGenerator.js +23 -14
  23. package/dist/utils/agentConfigGenerator.js.map +1 -1
  24. package/dist/utils/ideConfigGenerator.d.ts +5 -3
  25. package/dist/utils/ideConfigGenerator.d.ts.map +1 -1
  26. package/dist/utils/ideConfigGenerator.js +37 -36
  27. package/dist/utils/ideConfigGenerator.js.map +1 -1
  28. package/dist/utils/slashCommandGenerator.d.ts +7 -0
  29. package/dist/utils/slashCommandGenerator.d.ts.map +1 -1
  30. package/dist/utils/slashCommandGenerator.js +24 -8
  31. package/dist/utils/slashCommandGenerator.js.map +1 -1
  32. package/dist/utils/specArchiver.d.ts +6 -1
  33. package/dist/utils/specArchiver.d.ts.map +1 -1
  34. package/dist/utils/specArchiver.js +10 -10
  35. package/dist/utils/specArchiver.js.map +1 -1
  36. package/dist/utils/specBackfiller.d.ts.map +1 -1
  37. package/dist/utils/specBackfiller.js +55 -69
  38. package/dist/utils/specBackfiller.js.map +1 -1
  39. package/dist/utils/specGenerator.d.ts +6 -0
  40. package/dist/utils/specGenerator.d.ts.map +1 -1
  41. package/dist/utils/specGenerator.js +14 -0
  42. package/dist/utils/specGenerator.js.map +1 -1
  43. package/dist/utils/specServer.d.ts +9 -4
  44. package/dist/utils/specServer.d.ts.map +1 -1
  45. package/dist/utils/specServer.js +154 -50
  46. package/dist/utils/specServer.js.map +1 -1
  47. package/dist/utils/specSetup.d.ts +59 -0
  48. package/dist/utils/specSetup.d.ts.map +1 -0
  49. package/dist/utils/specSetup.js +288 -0
  50. package/dist/utils/specSetup.js.map +1 -0
  51. package/dist/utils/specValidator.d.ts +6 -2
  52. package/dist/utils/specValidator.d.ts.map +1 -1
  53. package/dist/utils/specValidator.js +15 -5
  54. package/dist/utils/specValidator.js.map +1 -1
  55. package/package.json +1 -1
  56. package/ui/app.css +10 -0
  57. package/ui/app.js +120 -24
  58. package/ui/index.html +9 -0
  59. package/ui/route.js +15 -7
package/ui/app.js CHANGED
@@ -21,23 +21,30 @@ $('#themeBtn').onclick=()=>{const light=document.documentElement.getAttribute('d
21
21
 
22
22
  /* ---------------- data: fetched, never embedded ---------------- */
23
23
  let DATA=null;
24
+ /* The shown project: its index on the serve command line (BL-054); every /api/ call names it. */
25
+ let PROJECT=0;
26
+ const pq=()=>'project='+PROJECT;
24
27
  const fileCache={};
25
28
  async function getText(p){
26
29
  if(p in fileCache)return fileCache[p];
27
- const r=await fetch('/api/file?p='+encodeURIComponent(p),{cache:'no-store'});
30
+ const pj=PROJECT;
31
+ const r=await fetch('/api/file?project='+pj+'&p='+encodeURIComponent(p),{cache:'no-store'});
28
32
  if(!r.ok)throw Object.assign(new Error(p+': HTTP '+r.status),{status:r.status});
29
- return fileCache[p]=await r.text();
33
+ const text=await r.text();
34
+ if(PROJECT===pj)fileCache[p]=text; // never cache one project's file under another's
35
+ return text;
30
36
  }
31
37
  function showErr(msg){const e=$('#loadErr');e.textContent=msg;e.hidden=false;}
32
38
 
33
- /* ---------------- project: only the one being served ---------------- */
39
+ /* ---------------- projects: one rail tile per served project (BL-054) ---------------- */
34
40
  function initials(n){const w=String(n).split(/[^A-Za-z0-9]+/).filter(Boolean);
35
41
  if(!w.length)return '??';
36
42
  if(w.length>1)return (w[0][0]+w[1][0]).toUpperCase();
37
43
  return w[0].slice(0,2).toUpperCase();}
38
44
  function renderProject(){
39
45
  const p=DATA.project, name=p.name!==null?p.name:p.root, where=p.root+(p.branch?' · '+p.branch:'');
40
- $('#projList').innerHTML=`<button class="tile blue cur" data-tip="${esc(name)}" data-path="${esc(where)}" aria-label="${esc(name)}" aria-current="true"><span aria-hidden="true">${esc(initials(name))}</span></button>`;
46
+ $('#projList').innerHTML=DATA.projects.map((q,i)=>{const n=q.name!==null?q.name:q.root,cur=i===PROJECT;
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('');
41
48
  $('#curGrp').textContent=name;$('#curGrp').title=p.root;
42
49
  $('#curBranch').textContent=p.branch||'';
43
50
  $('#subName').textContent=name;$('#subPath').textContent=where;
@@ -46,7 +53,7 @@ function renderProject(){
46
53
  }
47
54
 
48
55
  /* ---------------- views ---------------- */
49
- const VIEWS={board:'Tasks',explorer:'Explorer',security:'Security',instructions:'Instructions',commands:'Commands',skills:'Skills'};
56
+ const VIEWS={board:'Tasks',explorer:'Explorer',security:'Security',instructions:'Instructions',commands:'Commands',skills:'Skills',setup:''};
50
57
  const TITLES={'planning/roadmap.md':'Roadmap','project/requirements.md':'Requirements','architecture/architecture.md':'Architecture','quality/tests.md':'Tests'};
51
58
  const NAV=[['board'],['file','planning/roadmap.md'],['file','project/requirements.md'],['explorer'],['file','architecture/architecture.md'],['file','quality/tests.md'],['security'],['instructions'],['commands'],['skills']];
52
59
  let curView='board',curFile='';
@@ -57,13 +64,16 @@ function syncNav(){
57
64
  }
58
65
  function go(v,keep,sub){
59
66
  if(v==='file'){if(!DATA||!sub)v='board';else curFile=sub;}
60
- else if(!VIEWS[v])v='board';
67
+ else if(!VIEWS[v]||v==='setup')v='board';
68
+ if(DATA&&DATA.project.specs===false)v='setup'; // no .specs/ yet: every route shows the setup view (BL-055)
61
69
  curView=v;
62
70
  $$('.content>.view').forEach(e=>e.classList.toggle('on',e.id==='v-'+v));
63
71
  syncNav();
64
- $('#title').textContent=v==='file'?(TITLES[sub]||sub):VIEWS[v];
72
+ $('#title').textContent=v==='file'?(TITLES[sub]||sub):v==='setup'?'No .specs/ folder in '+DATA.projects[PROJECT].root:VIEWS[v];
65
73
  $('#modeSeg').hidden=v!=='board';
66
74
  setNav(false);closeInsp();
75
+ if(v!=='file'||sub!==fileNoteFor)clearFileNote();
76
+ if(v==='setup')renderSetup();
67
77
  if(v==='file')renderFile(sub);
68
78
  if(v==='explorer')renderExplorer();
69
79
  if(v==='security')renderSecurity();
@@ -76,11 +86,12 @@ let urlOk=true,memHash='';
76
86
  try{history.replaceState(null,'',location.href);}catch(e){urlOk=false;}
77
87
  try{memHash=location.hash;}catch(e){memHash='';}
78
88
  function curHash(){if(!urlOk)return memHash;try{return location.hash;}catch(e){return memHash;}}
79
- function setHash(v,sub){const h='#'+v+(sub?'/'+sub:'');if(curHash()===h)return;memHash=h;
89
+ function setHash(v,sub){const h='#'+(PROJECT?PROJECT+'/':'')+v+(sub?'/'+sub:'');if(curHash()===h)return;memHash=h;
80
90
  if(!urlOk)return;
81
91
  try{history.replaceState(null,'',h);}catch(e){urlOk=false;}}
82
92
  function route(){
83
- const r=resolveRoute(curHash(),DATA?DATA.files:{});
93
+ const r=resolveRoute(curHash(),DATA?DATA.files:{},DATA?DATA.projects.length:1);
94
+ if(r.project!==PROJECT){switchProject(r.project,true);return;}
84
95
  if(r.view==='board'&&r.sub==='board'){mode='board';$$('#modeSeg button').forEach(x=>x.classList.toggle('on',x.dataset.m==='board'));renderTasks();}
85
96
  go(r.view,true,r.sub);
86
97
  }
@@ -191,9 +202,9 @@ $$('#modeSeg button').forEach(b=>b.onclick=()=>{mode=b.dataset.m;$$('#modeSeg bu
191
202
  /* ---------------- any .specs/ file, rendered as written ---------------- */
192
203
  function metaLine(m){return ['fileID','version','lastUpdated'].filter(k=>m&&m[k]!==undefined).map(k=>`${k}: ${m[k]}`).join(' · ');}
193
204
  async function renderFile(path){
194
- let src=null;
195
- if(path in DATA.files)try{src=await getText('.specs/'+path);}catch(e){if(e.status!==404){if(curView==='file'&&curFile===path){$('#fmBox').innerHTML='';$('#fileBody').innerHTML=`<p class="note">${esc(e.message)}</p>`;}return;}}
196
- if(curView!=='file'||curFile!==path)return;
205
+ let src=null;const pj=PROJECT; // callers below draw only if the page still shows this project (BL-054)
206
+ if(path in DATA.files)try{src=await getText('.specs/'+path);}catch(e){if(e.status!==404){if(PROJECT===pj&&curView==='file'&&curFile===path){$('#fmBox').innerHTML='';$('#fileBody').innerHTML=`<p class="note">${esc(e.message)}</p>`;}return;}}
207
+ if(PROJECT!==pj||curView!=='file'||curFile!==path)return;
197
208
  if(src===null){$('#fmBox').innerHTML='';$('#fileBody').innerHTML=gone('.specs/'+path);return;}
198
209
  const isYaml=/\.ya?ml$/.test(path);
199
210
  const {fm,body}=isYaml?{fm:'',body:src}:splitFm(src);
@@ -215,11 +226,11 @@ function renderExplorer(){
215
226
  /* Security: both files in security/, each rendered as written. */
216
227
  const secShown=new Set(); // security files this page has shown, so a deletion can be named
217
228
  async function renderSecurity(){
218
- const paths=['security/threat-model.md','security/security-decisions.md'].filter(p=>p in DATA.files||secShown.has(p));
219
- const parts=await Promise.all(paths.map(p=>!(p in DATA.files)?Promise.resolve(gone('.specs/'+p)):getText('.specs/'+p).then(src=>(secShown.add(p),
229
+ const pj=PROJECT,paths=['security/threat-model.md','security/security-decisions.md'].filter(p=>p in DATA.files||secShown.has(p));
230
+ const parts=await Promise.all(paths.map(p=>!(p in DATA.files)?Promise.resolve(gone('.specs/'+p)):getText('.specs/'+p).then(src=>(PROJECT===pj&&secShown.add(p),
220
231
  `<div class="gl"><div class="gh" translate="no">${esc(p)} <span class="cnt" translate="no">${esc(metaLine(DATA.files[p]))}</span></div></div><div class="md doc doc-gap">${md(splitFm(src).body)}</div>`),
221
232
  e=>`<p class="note">${esc(e.message)}</p>`)));
222
- if(curView==='security')$('#secBody').innerHTML=parts.join('')||'<div class="box"><div class="empty">No files in <span class="mono" translate="no">.specs/security/</span>.</div></div>';
233
+ if(PROJECT===pj&&curView==='security')$('#secBody').innerHTML=parts.join('')||'<div class="box"><div class="empty">No files in <span class="mono" translate="no">.specs/security/</span>.</div></div>';
223
234
  }
224
235
 
225
236
  /* ---------------- automation: generated files, read as they are ---------------- */
@@ -246,8 +257,9 @@ function renderAgentFiles(){
246
257
  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));}
247
258
  async function openFile(path,quiet){
248
259
  if(!quiet)lastFocus=document.activeElement;
249
- let src=null;
250
- if(listed(path))try{src=await getText(path);}catch(e){if(e.status!==404){if(!quiet)toast(e.message);return;}}
260
+ let src=null;const pj=PROJECT;
261
+ if(listed(path))try{src=await getText(path);}catch(e){if(e.status!==404){if(!quiet&&PROJECT===pj)toast(e.message);return;}}
262
+ if(PROJECT!==pj)return;
251
263
  inspOpen={kind:'file',path};
252
264
  const head=`<div class="ih"><span class="id" translate="no">${esc(path)}</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>`;
253
265
  if(src===null){insp.innerHTML=head+`<div class="ib2">${gone(path)}</div>`;openInsp(quiet);return;}
@@ -315,14 +327,15 @@ function bindMoves(){
315
327
  });
316
328
  }
317
329
  async function move(col,i,toSection,toIndex,isUndo){
318
- const t=DATA.tasks[col][i];if(!t||moving)return;
330
+ const t=DATA.tasks[col][i],p=PROJECT;if(!t||moving)return;
319
331
  moving=true;
320
332
  let r,body={};
321
333
  try{
322
- r=await fetch('/api/tasks/move',{method:'POST',cache:'no-store',headers:{'Content-Type':'application/json','X-SpecPilot-Token':TOKEN,'If-Match':DATA.tasks.sha256},body:JSON.stringify({id:t.id,toSection,toIndex})});
334
+ r=await fetch('/api/tasks/move?'+pq(),{method:'POST',cache:'no-store',headers:{'Content-Type':'application/json','X-SpecPilot-Token':TOKEN,'If-Match':DATA.tasks.sha256},body:JSON.stringify({id:t.id,toSection,toIndex})});
323
335
  body=await r.json().catch(()=>({}));
324
336
  }catch(e){moving=false;toast('The server did not answer. Nothing was moved.');return;}
325
337
  moving=false;
338
+ if(p!==PROJECT)return; // the page switched projects while the move was in flight
326
339
  if(r.status===200){
327
340
  if(toSection==='backlog'&&toIndex>=6)showAllBacklog=true;
328
341
  await apply(body.specs,['.specs/planning/tasks.md']);
@@ -336,6 +349,67 @@ async function move(col,i,toSection,toIndex,isUndo){
336
349
  }else toast(body.error||`The move was not made (HTTP ${r.status}).`);
337
350
  }
338
351
 
352
+ /* ---------------- guided setup (BL-055) ----------------
353
+ A named folder with no .specs/ yet. The questions, their choices and the detected line come from
354
+ GET /api/setup, which serves the CLI's own text; the page adds only the strings REQ-002.H.17 lists. */
355
+ let setupQ=null,setupBusy=false,fileNoteFor=null;
356
+ function clearFileNote(){const n=$('#fileNote');n.hidden=true;n.innerHTML='';fileNoteFor=null;}
357
+ function setFileNote(path,lines){const n=$('#fileNote');n.innerHTML=lines.map(l=>`<p class="note" translate="no">${esc(l)}</p>`).join('');n.hidden=false;fileNoteFor=path;}
358
+ async function renderSetup(){
359
+ const pj=PROJECT,intro=$('#setupIntro'),det=$('#setupDetected'),form=$('#setupForm'),note=$('#setupNote');
360
+ intro.hidden=det.hidden=form.hidden=note.hidden=true;form.innerHTML='';
361
+ if(!TOKEN){note.textContent='Started with --read-only, so nothing can be set up here.';note.hidden=false;return;}
362
+ let r,q=null;
363
+ try{r=await fetch('/api/setup?'+pq(),{cache:'no-store'});if(r.ok)q=await r.json();else if(r.status!==404)q={error:(await r.json().catch(()=>({}))).error||'HTTP '+r.status};}
364
+ catch(e){q={error:'The server did not answer.'};}
365
+ if(PROJECT!==pj||curView!=='setup')return;
366
+ if(!q)return; // 404: not a folder named on the command line, so no form
367
+ if(q.error){note.textContent=q.error;note.hidden=false;return;}
368
+ setupQ=q;intro.hidden=false;
369
+ if(q.detected){det.textContent=q.detected.line;det.hidden=false;}
370
+ form.innerHTML=q.questions.map(qu=>{
371
+ const body=qu.key==='handle'
372
+ ?`<input type="text" name="handle" aria-label="handle" maxlength="39">`
373
+ :qu.choices?qu.choices.map((c,i)=>`<label><input type="radio" name="${esc(qu.key)}" value="${esc(c.value)}"${i===0?' checked':''}>${esc(c.name)}</label>`).join('')
374
+ :'';
375
+ return `<fieldset data-key="${esc(qu.key)}"><legend>${esc(qu.message)}</legend><div class="opts">${body}</div>${qu.key==='ide'?'<div class="keep" id="setupKeep" hidden translate="no"></div>':''}</fieldset>`;
376
+ }).join('')+'<button type="submit" class="go">Create .specs/</button>';
377
+ form.hidden=false;
378
+ const sync=()=>{
379
+ const lang=form.language?form.language.value:null,fw=form.querySelector('fieldset[data-key="framework"]');
380
+ if(fw&&q.frameworks){const list=lang&&q.frameworks[lang]||[];fw.hidden=!list.length;
381
+ fw.querySelector('.opts').innerHTML=list.map((v,i)=>`<label><input type="radio" name="framework" value="${esc(v)}"${i===0?' checked':''}>${esc(v)}</label>`).join('');}
382
+ const ide=form.ide.value,keep=(q.keep&&q.keep[ide])||[],k=$('#setupKeep');
383
+ k.hidden=!keep.length;k.textContent=keep.length?'Already here, will be kept: '+keep.join(', '):'';
384
+ };
385
+ form.onchange=sync;sync();
386
+ form.onsubmit=e=>{e.preventDefault();submitSetup(form);};
387
+ }
388
+ async function submitSetup(form){
389
+ if(setupBusy)return;setupBusy=true;
390
+ const p=PROJECT,root=DATA.projects[PROJECT].root,btn=form.querySelector('button.go');btn.disabled=true;
391
+ const body={};$$('fieldset[data-key]',form).forEach(f=>{if(f.hidden)return;const k=f.dataset.key;const el=form[k];if(el)body[k]=el.value;});
392
+ let r,res={};
393
+ try{
394
+ r=await fetch('/api/setup?'+pq(),{method:'POST',cache:'no-store',headers:{'Content-Type':'application/json','X-SpecPilot-Token':TOKEN},body:JSON.stringify(body)});
395
+ res=await r.json().catch(()=>({}));
396
+ }catch(e){setupBusy=false;btn.disabled=false;toast('The server did not answer. Nothing was set up.');return;}
397
+ setupBusy=false;btn.disabled=false;
398
+ if(p!==PROJECT)return;
399
+ if(r.status===200){
400
+ await apply(res.specs,null);
401
+ toast('.specs/ created in '+root);
402
+ go('file',false,'development/onboarding.md');
403
+ const lines=[];
404
+ if(res.kept&&res.kept.length)lines.push('Kept as they were: '+res.kept.join(', ')+'. Run specpilot backfill there to add missing SpecPilot sections to the instruction and command files.');
405
+ if(res.notice)lines.push(res.notice);
406
+ if(lines.length)setFileNote('development/onboarding.md',lines);
407
+ }else{
408
+ if(r.status===409&&res.specs)await apply(res.specs,null);
409
+ toast(res.error||`Nothing was set up (HTTP ${r.status}).`);
410
+ }
411
+ }
412
+
339
413
  /* ---------------- live reload (BL-052) ----------------
340
414
  On a change event: re-fetch, redraw in place. Route, scroll, open inspector, selected row
341
415
  and focus stay where they were. If the server is gone, the last content stays on screen. */
@@ -363,8 +437,9 @@ function refocus(key){
363
437
  let refreshing=Promise.resolve();
364
438
  function refresh(paths){refreshing=refreshing.then(()=>redraw(paths)).catch(()=>{});}
365
439
  async function redraw(paths){
366
- let d;
367
- try{const r=await fetch('/api/specs',{cache:'no-store'});if(!r.ok)return;d=await r.json();}catch(e){return;} // server gone: keep what is shown
440
+ let d;const p=PROJECT;
441
+ try{const r=await fetch('/api/specs?'+pq(),{cache:'no-store'});if(!r.ok)return;d=await r.json();}catch(e){return;} // server gone: keep what is shown
442
+ if(p!==PROJECT)return; // switched projects meanwhile
368
443
  // The poller's echo of a move this page just made: same tasks.md hash, nothing to redraw.
369
444
  if(paths&&paths.length&&paths.every(p=>p==='.specs/planning/tasks.md')&&DATA&&DATA.tasks&&d.tasks&&d.tasks.sha256===DATA.tasks.sha256)return;
370
445
  await apply(d,paths);
@@ -375,8 +450,11 @@ async function apply(d,paths){
375
450
  const key=focusKey(document.activeElement);
376
451
  const scroll=$('#content').scrollTop,ib0=insp.querySelector('.ib2'),inspScroll=ib0?ib0.scrollTop:0;
377
452
  const was=inspOpen;
453
+ const hadSpecs=DATA&&DATA.project.specs!==false;
378
454
  DATA=d;
379
455
  renderProject();renderTasks();renderIde();renderAgentFiles();
456
+ if(d.project.specs===false&&curView!=='setup'){go('setup');return;} // .specs/ gone: offer setup
457
+ if(hadSpecs===false&&d.project.specs!==false&&curView==='setup'){go('board');return;} // .specs/ appeared another way
380
458
  if(curView==='file')await renderFile(curFile);
381
459
  if(curView==='explorer')renderExplorer();
382
460
  if(curView==='security')await renderSecurity();
@@ -390,18 +468,36 @@ async function apply(d,paths){
390
468
  const ib=insp.querySelector('.ib2');if(ib)ib.scrollTop=inspScroll;
391
469
  refocus(key);
392
470
  }
471
+ let es=null;
393
472
  function listen(){
394
473
  if(!window.EventSource)return;
395
- const es=new EventSource('/api/events');let dropped=false;
474
+ if(es)es.close(); // one stream, for the shown project
475
+ es=new EventSource('/api/events?'+pq());let dropped=false;
396
476
  es.addEventListener('change',e=>{let paths=null;try{paths=JSON.parse(e.data).paths;}catch(_){}refresh(Array.isArray(paths)?paths:null);});
397
477
  es.onerror=()=>{dropped=true;}; // EventSource retries by itself
398
478
  es.onopen=()=>{if(dropped){dropped=false;refresh(null);}}; // catch up on anything missed
399
479
  }
400
480
 
401
- /* boot */
481
+ /* Show another served project: fresh data, its own event stream, its Tasks view (or the routed view). */
482
+ async function switchProject(n,keepRoute){
483
+ const was=PROJECT;PROJECT=n;
484
+ let d;
485
+ try{const r=await fetch('/api/specs?'+pq(),{cache:'no-store'});if(!r.ok)throw new Error('/api/specs: HTTP '+r.status);d=await r.json();}
486
+ catch(e){if(PROJECT===n)PROJECT=was;toast('Could not load the project: '+e.message);return;}
487
+ if(PROJECT!==n)return;
488
+ Object.keys(fileCache).forEach(k=>{delete fileCache[k];});secShown.clear();
489
+ DATA=d;selected=null;
490
+ renderProject();renderTasks();renderIde();renderAgentFiles();listen();
491
+ if(keepRoute)route();else go('board');
492
+ }
493
+ $('#projList').addEventListener('click',e=>{const b=e.target.closest('[data-project]');if(b&&+b.dataset.project!==PROJECT)switchProject(+b.dataset.project);});
494
+
495
+ /* boot: the project count is unknown until the first load, so an index past the end falls back to project 0 */
402
496
  insp.setAttribute('aria-hidden','true');
403
497
  $('#gDone').classList.add('closed');
404
- fetch('/api/specs',{cache:'no-store'})
498
+ PROJECT=resolveRoute(curHash(),{},Infinity).project;
499
+ fetch('/api/specs?'+pq(),{cache:'no-store'})
500
+ .then(r=>{if(!r.ok&&PROJECT){PROJECT=0;return fetch('/api/specs?'+pq(),{cache:'no-store'});}return r;})
405
501
  .then(r=>{if(!r.ok)throw new Error('/api/specs: HTTP '+r.status);return r.json();})
406
502
  .then(d=>{DATA=d;renderProject();renderTasks();renderIde();renderAgentFiles();route();listen();})
407
503
  .catch(e=>showErr('Could not load the project: '+e.message));
package/ui/index.html CHANGED
@@ -137,8 +137,17 @@
137
137
  <div id="secBody"></div>
138
138
  </section>
139
139
 
140
+ <!-- SETUP (BL-055): a named folder with no .specs/ yet; the questions are the CLI's own -->
141
+ <section class="view" id="v-setup">
142
+ <p class="note" id="setupIntro" hidden>Runs what specpilot add-specs runs in this folder. Existing files are never changed.</p>
143
+ <p class="note" id="setupDetected" hidden translate="no"></p>
144
+ <form class="setup" id="setupForm" hidden autocomplete="off"></form>
145
+ <p class="note" id="setupNote" hidden></p>
146
+ </section>
147
+
140
148
  <!-- FILE: any .specs/ file, rendered as written -->
141
149
  <section class="view" id="v-file">
150
+ <div class="gl" id="fileNote" hidden></div>
142
151
  <div class="gl" id="fmBox"></div>
143
152
  <div class="md doc" id="fileBody"></div>
144
153
  </section>
package/ui/route.js CHANGED
@@ -4,17 +4,25 @@
4
4
  const VIEWS=['board','explorer','security','instructions','commands','skills'];
5
5
  const esc=s=>String(s).replace(/[&<>"]/g,c=>({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;'}[c]));
6
6
 
7
- /* "#file/quality/tests.md" → {view:'file', sub:'quality/tests.md', missing:false}.
7
+ /* "#file/quality/tests.md" → {project:0, view:'file', sub:'quality/tests.md', missing:false}.
8
8
  A file the latest /api/specs does not list stays on the file view with missing:true,
9
- so the page can say it no longer exists instead of silently showing something else. */
10
- function resolveRoute(hash,files){
11
- const h=String(hash||'').replace(/^#/,''),ix=h.indexOf('/');
9
+ so the page can say it no longer exists instead of silently showing something else.
10
+ "#2/board" is project 2 of `count` (BL-054); no index, or "#0/", is project 0; an index
11
+ that names no served project goes to project 0's Tasks view. */
12
+ function resolveRoute(hash,files,count){
13
+ let h=String(hash||'').replace(/^#/,''),project=0;
14
+ const m=/^(\d+)\/(.*)$/.exec(h);
15
+ if(m){
16
+ if(!/^(0|[1-9][0-9]*)$/.test(m[1])||Number(m[1])>=(count||1))return {project:0,view:'board',sub:'',missing:false};
17
+ project=Number(m[1]);h=m[2];
18
+ }
19
+ const ix=h.indexOf('/');
12
20
  const view=ix<0?h:h.slice(0,ix);
13
21
  let sub=ix<0?'':h.slice(ix+1);
14
22
  try{sub=decodeURIComponent(sub);}catch(e){}
15
- if(view==='file'&&sub)return {view:'file',sub,missing:!Object.prototype.hasOwnProperty.call(files||{},sub)};
16
- if(VIEWS.includes(view))return {view,sub,missing:false};
17
- return {view:'board',sub:'',missing:false};
23
+ if(view==='file'&&sub)return {project,view:'file',sub,missing:!Object.prototype.hasOwnProperty.call(files||{},sub)};
24
+ if(VIEWS.includes(view))return {project,view,sub,missing:false};
25
+ return {project,view:'board',sub:'',missing:false};
18
26
  }
19
27
 
20
28
  /* The whole content of a view whose file is gone: its path, and that it no longer exists. */