specpilot 2.20.0 → 2.21.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 (92) hide show
  1. package/README.md +35 -14
  2. package/dist/cli.js +6 -2
  3. package/dist/cli.js.map +1 -1
  4. package/dist/commands/add-specs.d.ts +1 -0
  5. package/dist/commands/add-specs.d.ts.map +1 -1
  6. package/dist/commands/add-specs.js +8 -2
  7. package/dist/commands/add-specs.js.map +1 -1
  8. package/dist/commands/backfill.js +8 -9
  9. package/dist/commands/backfill.js.map +1 -1
  10. package/dist/commands/init.d.ts +1 -0
  11. package/dist/commands/init.d.ts.map +1 -1
  12. package/dist/commands/init.js +10 -4
  13. package/dist/commands/init.js.map +1 -1
  14. package/dist/commands/refine.d.ts.map +1 -1
  15. package/dist/commands/refine.js +6 -1
  16. package/dist/commands/refine.js.map +1 -1
  17. package/dist/commands/serve.d.ts +1 -1
  18. package/dist/commands/serve.d.ts.map +1 -1
  19. package/dist/commands/serve.js +22 -7
  20. package/dist/commands/serve.js.map +1 -1
  21. package/dist/commands/validate.d.ts.map +1 -1
  22. package/dist/commands/validate.js +4 -0
  23. package/dist/commands/validate.js.map +1 -1
  24. package/dist/core/chatFlow.js +1 -1
  25. package/dist/core/chatFlow.js.map +1 -1
  26. package/dist/core/ideConfig.d.ts +0 -1
  27. package/dist/core/ideConfig.d.ts.map +1 -1
  28. package/dist/core/ideConfig.js +1 -2
  29. package/dist/core/ideConfig.js.map +1 -1
  30. package/dist/core/render.d.ts +2 -0
  31. package/dist/core/render.d.ts.map +1 -1
  32. package/dist/core/render.js +1 -0
  33. package/dist/core/render.js.map +1 -1
  34. package/dist/core/slashCommands.js +7 -7
  35. package/dist/core/specFiles.js +8 -6
  36. package/dist/core/specFiles.js.map +1 -1
  37. package/dist/core/templateEngine.d.ts +1 -0
  38. package/dist/core/templateEngine.d.ts.map +1 -1
  39. package/dist/core/templateEngine.js +4 -0
  40. package/dist/core/templateEngine.js.map +1 -1
  41. package/dist/utils/addSpecsQuestions.d.ts +7 -0
  42. package/dist/utils/addSpecsQuestions.d.ts.map +1 -1
  43. package/dist/utils/addSpecsQuestions.js +7 -1
  44. package/dist/utils/addSpecsQuestions.js.map +1 -1
  45. package/dist/utils/folderPicker.d.ts.map +1 -1
  46. package/dist/utils/folderPicker.js +3 -1
  47. package/dist/utils/folderPicker.js.map +1 -1
  48. package/dist/utils/ideConfigGenerator.d.ts +2 -8
  49. package/dist/utils/ideConfigGenerator.d.ts.map +1 -1
  50. package/dist/utils/ideConfigGenerator.js +2 -9
  51. package/dist/utils/ideConfigGenerator.js.map +1 -1
  52. package/dist/utils/mcpLocal.js +1 -1
  53. package/dist/utils/mcpLocal.js.map +1 -1
  54. package/dist/utils/nodeCheck.d.ts +20 -0
  55. package/dist/utils/nodeCheck.d.ts.map +1 -0
  56. package/dist/utils/nodeCheck.js +50 -0
  57. package/dist/utils/nodeCheck.js.map +1 -0
  58. package/dist/utils/projectRegistry.d.ts +2 -0
  59. package/dist/utils/projectRegistry.d.ts.map +1 -1
  60. package/dist/utils/projectRegistry.js +3 -1
  61. package/dist/utils/projectRegistry.js.map +1 -1
  62. package/dist/utils/slashCommandGenerator.d.ts.map +1 -1
  63. package/dist/utils/slashCommandGenerator.js +12 -0
  64. package/dist/utils/slashCommandGenerator.js.map +1 -1
  65. package/dist/utils/specArchiver.d.ts +17 -4
  66. package/dist/utils/specArchiver.d.ts.map +1 -1
  67. package/dist/utils/specArchiver.js +20 -4
  68. package/dist/utils/specArchiver.js.map +1 -1
  69. package/dist/utils/specBackfiller.d.ts +19 -12
  70. package/dist/utils/specBackfiller.d.ts.map +1 -1
  71. package/dist/utils/specBackfiller.js +54 -56
  72. package/dist/utils/specBackfiller.js.map +1 -1
  73. package/dist/utils/specPaths.d.ts.map +1 -1
  74. package/dist/utils/specPaths.js +5 -2
  75. package/dist/utils/specPaths.js.map +1 -1
  76. package/dist/utils/specServer.d.ts +24 -0
  77. package/dist/utils/specServer.d.ts.map +1 -1
  78. package/dist/utils/specServer.js +205 -62
  79. package/dist/utils/specServer.js.map +1 -1
  80. package/dist/utils/specValidator.d.ts +6 -0
  81. package/dist/utils/specValidator.d.ts.map +1 -1
  82. package/dist/utils/specValidator.js +153 -8
  83. package/dist/utils/specValidator.js.map +1 -1
  84. package/dist/utils/taskMover.d.ts +9 -3
  85. package/dist/utils/taskMover.d.ts.map +1 -1
  86. package/dist/utils/taskMover.js +42 -18
  87. package/dist/utils/taskMover.js.map +1 -1
  88. package/package.json +3 -3
  89. package/ui/app.css +107 -11
  90. package/ui/app.js +320 -43
  91. package/ui/index.html +41 -23
  92. package/ui/route.js +41 -12
package/ui/app.js CHANGED
@@ -28,12 +28,13 @@ const chev='<svg class="ico chev" aria-hidden="true" focusable="false"><use href
28
28
  let theme=null;try{theme=localStorage.getItem('sp-theme');}catch(e){}
29
29
  function setMeta(light){const m=document.querySelector('meta[name=theme-color]');if(m)m.content=light?'#f8fafc':'#0f172a';}
30
30
  if(theme==='light'){document.documentElement.setAttribute('data-theme','light');setMeta(true);}
31
- $('#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'));};
31
+ $('#themeBtn').onclick=()=>{closeSet(true);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'));};
32
32
  /* Quit (BL-098): the route `specpilot serve --stop` uses; the server then stops as on Ctrl+C. This page
33
33
  closes its stream and says so; other open pages see a dropped stream, as before. */
34
34
  let stopped=false;
35
35
  if(TOKEN)$('#quitBtn').hidden=false;
36
36
  $('#quitBtn').onclick=async()=>{
37
+ closeSet(true);
37
38
  if(!confirm('Quit SpecPilot? Open pages stop updating.'))return;
38
39
  let r;
39
40
  try{r=await fetch('/api/quit',{method:'POST',cache:'no-store',headers:{'Content-Type':'application/json','X-SpecPilot-Token':TOKEN},body:'{}'});}
@@ -44,6 +45,35 @@ $('#quitBtn').onclick=async()=>{
44
45
  document.querySelector('main.pane').replaceChildren(p);
45
46
  };
46
47
 
48
+ /* Settings (BL-UI-02, REQ-002.H.72): the rail's cog opens a menu holding the theme item and Quit. It sits outside
49
+ the rail (position: fixed), since the rail scrolls and would clip it; keys as the card menu's. */
50
+ const setBtn=$('#setBtn'),setMenu=$('#setMenu');
51
+ function openSet(){
52
+ hideTip();
53
+ $('#themeBtn').textContent=document.documentElement.getAttribute('data-theme')==='light'?'Dark appearance':'Light appearance';
54
+ setMenu.hidden=false;setBtn.setAttribute('aria-expanded','true');
55
+ const r=setBtn.getBoundingClientRect(),w=setMenu.offsetWidth,h=setMenu.offsetHeight,m=8;
56
+ setMenu.style.left=Math.max(m,Math.min(r.right+6,innerWidth-w-m))+'px';
57
+ setMenu.style.top=Math.max(m,Math.min(r.bottom-h,innerHeight-h-m))+'px';
58
+ $('[role=menuitem]:not([hidden])',setMenu).focus();
59
+ }
60
+ function closeSet(refocus){
61
+ if(setMenu.hidden)return;
62
+ setMenu.hidden=true;setBtn.setAttribute('aria-expanded','false');
63
+ if(setMenu.contains(document.activeElement))document.activeElement.blur();
64
+ if(refocus)setBtn.focus();
65
+ }
66
+ setBtn.onclick=()=>setMenu.hidden?openSet():closeSet(true);
67
+ setMenu.addEventListener('keydown',e=>{
68
+ const it=$$('[role=menuitem]:not([hidden])',setMenu),i=it.indexOf(document.activeElement);
69
+ if(e.key==='ArrowDown'||e.key==='ArrowUp'){e.preventDefault();it[(i+(e.key==='ArrowDown'?1:it.length-1))%it.length].focus();}
70
+ else if(e.key==='Home'||e.key==='End'){e.preventDefault();it[e.key==='Home'?0:it.length-1].focus();}
71
+ else if(e.key==='Escape'){e.preventDefault();e.stopPropagation();closeSet(true);}
72
+ });
73
+ setMenu.addEventListener('mousedown',e=>e.preventDefault()); // a press inside keeps focus in the menu, as the card menu's
74
+ setMenu.addEventListener('focusout',e=>{if(!setMenu.contains(e.relatedTarget)&&e.relatedTarget!==setBtn)closeSet(false);});
75
+ document.addEventListener('click',e=>{if(!setMenu.hidden&&!(e.target.closest&&e.target.closest('#setMenu,#setBtn')))closeSet(false);});
76
+
47
77
  /* ---------------- data: fetched, never embedded ---------------- */
48
78
  let DATA=null;
49
79
  /* The shown project: its index on the serve command line (BL-054); every /api/ call names it. */
@@ -66,30 +96,43 @@ function initials(n){const w=String(n).split(/[^A-Za-z0-9]+/).filter(Boolean);
66
96
  if(!w.length)return '??';
67
97
  if(w.length>1)return (w[0][0]+w[1][0]).toUpperCase();
68
98
  return w[0].slice(0,2).toUpperCase();}
99
+ /* BL-190 (REQ-002.H.78): the banner for a server Node.js outside engines.node; its words and versions from the payload, set as text. */
100
+ const orList=xs=>xs.length>1?xs.slice(0,-1).join(', ')+' or '+xs[xs.length-1]:xs.join('');
101
+ function drawNodeBar(){
102
+ const n=DATA&&DATA.node,bar=$('#nodeBar');
103
+ let gone=false;try{gone=!!n&&sessionStorage.getItem('sp-node-dismissed')===n.version;}catch(e){}
104
+ if(!n||n.ok!==false||gone){bar.hidden=true;return;}
105
+ $('#nodeLong').textContent='Node.js '+n.version+' on this server has known security vulnerabilities, including TLS certificate bypass, memory disclosure and denial of service (Node.js security releases, '+n.release+'). Update to '+orList(n.patched)+' or later.';
106
+ $('#nodeShort').textContent='Node.js '+n.version+' has known security vulnerabilities. Update to '+orList(n.patched)+'+.';
107
+ $('#nodeLink').href='https://nodejs.org/en/blog/vulnerability'; // set here: index.html carries no external src or href (the page-shell test in specServer.test.ts); a link loads nothing (SEC-004.39)
108
+ bar.hidden=false;}
109
+ $('#nodeX').addEventListener('click',()=>{try{sessionStorage.setItem('sp-node-dismissed',DATA.node.version);}catch(e){}$('#nodeBar').hidden=true;});
69
110
  function renderProject(){
111
+ drawNodeBar();
70
112
  $('#footAddr').textContent=$('#homeAddr').textContent=location.host;$('#footVer').textContent=$('#homeVer').textContent='v'+DATA.specpilotVersion;
71
113
  const p=DATA.project;
72
114
  if(!p){ // no project served (BL-080): an empty rail and top bar; Home is the view
73
115
  $('#projList').innerHTML='';$('#curGrp').textContent='';$('#curGrp').title='';$('#curBranch').textContent='';
74
- $('#subName').textContent='';$('#subPath').textContent='';document.title='SpecPilot Local';return;}
116
+ $('#subName').textContent='';$('#subPath').textContent='';document.title='SpecPilot';return;}
75
117
  const name=projectLabel(p), where=p.root+(p.branch?' · '+p.branch:'');
76
- $('#projList').innerHTML=DATA.projects.map((q,i)=>{const n=projectLabel(q),cur=i===PROJECT&&!NOPROJ.includes(curView);
118
+ $('#projList').innerHTML=DATA.projects.map((q,i)=>{if(q.closed)return ''; // BL-166: a closed project keeps its slot, no tile
119
+ const n=projectLabel(q),cur=i===PROJECT&&!NOPROJ.includes(curView);
77
120
  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('');
78
121
  $('#curGrp').textContent=name;$('#curGrp').title=p.root;
79
122
  $('#curBranch').textContent=p.branch||'';
80
123
  $('#subName').textContent=name;$('#subPath').textContent=where;$('#editorBtn').href=editorUrl(p.root);syncIde();
81
- document.title=name+' · SpecPilot Local';
124
+ document.title=name+' · SpecPilot';
82
125
  }
83
126
  /* Everything a payload draws; with no project served (BL-080) only the rail, bar and footer. */
84
- function renderAll(){renderProject();if(!DATA.project)return;renderTasks();renderIde();renderAgentFiles();}
127
+ function renderAll(){drawMcp();renderProject();if(!DATA.project)return;renderTasks();renderIde();renderAgentFiles();}
85
128
 
86
129
  /* ---------------- views ---------------- */
87
130
  const homeBtn=$('#homeBtn');
88
- const VIEWS={board:'Tasks',explorer:'Explorer',security:'Security',instructions:'Instructions',commands:'Commands',skills:'Skills',setup:'',home:'',new:''};
131
+ const VIEWS={overview:'Overview',board:'Tasks',explorer:'Explorer',security:'Security',instructions:'Instructions',commands:'Commands',skills:'Skills',setup:'',home:'',new:''};
89
132
  const NOPROJ=['home','new']; // views that belong to no project (BL-PM-001, BL-PM-004)
90
133
  const TITLES={'planning/roadmap.md':'Roadmap','project/requirements.md':'Requirements','architecture/architecture.md':'Architecture','quality/tests.md':'Tests'};
91
134
  const NAV=[['board'],['file','planning/roadmap.md'],['file','project/requirements.md'],['explorer'],['file','architecture/architecture.md'],['file','quality/tests.md'],['security'],['instructions'],['commands'],['skills']];
92
- let curView='board',curFile='';
135
+ let curView='overview',curFile='';
93
136
  function syncNav(){
94
137
  $$('.src .srow').forEach(b=>{
95
138
  const on=b.dataset.v==='file'?(curView==='file'&&b.dataset.f===curFile):(b.dataset.v===curView);
@@ -100,9 +143,9 @@ function syncNav(){
100
143
  t.classList.toggle('cur',cur);if(cur)t.setAttribute('aria-current','true');else t.removeAttribute('aria-current');});
101
144
  }
102
145
  function go(v,sub){
103
- if(v==='file'){if(!DATA||!sub)v='board';else curFile=sub;}
104
- else if(NOPROJ.includes(v)){if(!TOKEN)v='board';} // no Home and no #new with --read-only
105
- else if(!VIEWS[v]||v==='setup')v='board';
146
+ if(v==='file'){if(!DATA||!sub)v='overview';else curFile=sub;} // Overview is the landing (BL-171)
147
+ else if(NOPROJ.includes(v)){if(!TOKEN)v='overview';} // no Home and no #new with --read-only
148
+ else if(!VIEWS[v]||v==='setup')v='overview';
106
149
  if(!NOPROJ.includes(v)&&DATA&&!DATA.project)v='home'; // no project served: Home is the only view (BL-080)
107
150
  else 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)
108
151
  curView=v;
@@ -118,6 +161,7 @@ function go(v,sub){
118
161
  if(v==='file')renderFile(sub);
119
162
  if(v==='explorer')renderExplorer();
120
163
  if(v==='security')renderSecurity();
164
+ if(v==='overview')renderOverview();
121
165
  setHash(v,v==='file'?sub:null);
122
166
  $('#content').scrollTop=0;
123
167
  }
@@ -125,16 +169,34 @@ function go(v,sub){
125
169
  let urlOk=true,memHash='';
126
170
  try{history.replaceState(null,'',location.href);}catch(e){urlOk=false;}
127
171
  try{memHash=location.hash;}catch(e){memHash='';}
172
+ /* The indices of closed projects (BL-166): their slots stay in DATA.projects as {closed: true}. */
173
+ function closedProjects(){return DATA&&DATA.projects?DATA.projects.flatMap((q,i)=>q.closed?[i]:[]):[];}
174
+ /* Project n closed (BL-166): the rail redrawn from `projects`; if it was the shown one, Home and a toast naming it. */
175
+ function projectClosed(n,projects){
176
+ const q=DATA.projects[n];if(!q||q.closed)return;
177
+ DATA.projects=projects||DATA.projects.map((x,i)=>i===n?{closed:true}:x);renderProject();
178
+ toast(`${projectLabel(q)} was closed.`);
179
+ if(n!==PROJECT)return;
180
+ if(es){es.close();es=null;}
181
+ replacing(()=>go('home')); // the page's own move: no history entry (BL-192)
182
+ // behind Home, the first open project's data (or the no-project state), so no view shows the closed one's
183
+ // the index from the server's list, not this page's: a close this page did not hear of may have moved the first open one
184
+ fetch('/api/specs',{cache:'no-store'}).then(r=>r.ok?r.json():null).then(d=>{if(d&&PROJECT===n){PROJECT=d.project?d.projects.findIndex(q=>!q.closed):0;showProject(d,true);}}).catch(()=>{});
185
+ }
128
186
  function curHash(){if(!urlOk)return memHash;try{return location.hash;}catch(e){return memHash;}}
187
+ /* BL-192 (REQ-002.H.77): a section the person opens adds a history entry, so Back and Forward walk them; what the page does
188
+ on its own (route() resolving a hash, the go-Home when the shown project closes, a forced view on live reload) replaces it. */
189
+ let navReplace=false;
190
+ function replacing(fn){const was=navReplace;navReplace=true;try{return fn();}finally{navReplace=was;}}
129
191
  function setHash(v,sub){const h='#'+(PROJECT&&!NOPROJ.includes(v)?PROJECT+'/':'')+v+(sub?'/'+sub:'');if(curHash()===h)return;memHash=h;
130
192
  if(!urlOk)return;
131
- try{history.replaceState(null,'',h);}catch(e){urlOk=false;}}
132
- function route(){
133
- const r=resolveRoute(curHash(),DATA?DATA.files:{},DATA?DATA.projects.length:1,!!TOKEN);
193
+ try{history[navReplace?'replaceState':'pushState'](null,'',h);}catch(e){urlOk=false;}}
194
+ function route(){replacing(()=>{ // inside route() itself, so showProject()'s re-entry after a project's fetch replaces too
195
+ const r=resolveRoute(curHash(),DATA?DATA.files:{},DATA?DATA.projects.length:1,!!TOKEN,closedProjects());
134
196
  if(NOPROJ.includes(r.view)){go(r.view);return;} // Home and #new belong to no project: the shown one stays loaded behind them
135
197
  if(r.project!==PROJECT){switchProject(r.project,true);return;}
136
198
  go(r.view,r.sub);
137
- }
199
+ });}
138
200
  if(urlOk)window.addEventListener('hashchange',route);
139
201
  $$('.src .srow[data-v]').forEach(b=>b.onclick=()=>go(b.dataset.v,b.dataset.f));
140
202
  function setNav(on){const w=$('#win');w.classList.toggle('nav',on);$('#scrim').hidden=!on;$('#menuBtn').setAttribute('aria-expanded',on?'true':'false');}
@@ -326,16 +388,165 @@ function openTask(col,i,quiet){
326
388
  const foot=col==='review'&&TOKEN?`<div class="if" id="inspFoot">${done}<div class="fb">${t.approved?'':'<button type="button" class="btn pri" id="rvApprove">Approve</button>'}<button type="button" class="btn" id="rvSend">Send back</button></div>
327
389
  <form id="rvForm" autocomplete="off" hidden><label for="rvNote">What needs fixing? (optional)</label><textarea id="rvNote" name="review-note" rows="3" maxlength="200" aria-describedby="rvCount rvErr"></textarea><div class="fc" id="rvCount" aria-live="polite">0/200</div><div class="fb"><button type="submit" class="btn pri" id="rvGo">Send back to Current Sprint</button><button type="button" class="btn" id="rvCancel">Cancel</button></div></form>
328
390
  <p class="err" id="rvErr" role="alert" hidden></p></div>`:'';
391
+ const editable=col==='backlog'&&!!TOKEN; // BL-TB-08: a Backlog row's description, with a token
329
392
  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 ${PILL[col]}">${esc(COLS[col])}</span>${col==='review'&&t.approved?'<span class="pill green">Approved</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>
330
393
  <div class="ib2">
331
- <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>
394
+ <div class="gl"><div class="gh">Description <span class="cnt" translate="no">tasks.md · ## ${esc(COLS[col])}</span>${editable?'<button type="button" class="btn sm" id="edBtn">Edit</button>':''}</div><div class="box"${editable?' id="edBox"':''}><div class="desc md">${md(t.description)}</div></div>${editable?editForm():''}</div>
332
395
  ${fieldsBlock(col,t)}${reason}${hist}
333
396
  <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>
334
397
  </div>${foot}`;
335
398
  if(foot)bindReview(col,i);
399
+ if(editable)bindEdit(col,i);
336
400
  bindRadios(insp,(key,btn)=>chooseField(col,i,key,btn));
337
401
  openInsp(quiet);
338
402
  }
403
+ /* ---------------- Edit a Backlog description (BL-TB-08, REQ-002.H.73) ----------------
404
+ The cell's text in a one-line form; Save writes through POST /api/tasks/fields by New Task's rules. A redraw while
405
+ the form is open keeps it open with the typed text (apply); a closed panel or another card drops it. */
406
+ const editForm=()=>`<form id="edForm" autocomplete="off" hidden><textarea id="edText" name="task-description" rows="4" maxlength="4000" aria-label="Description" aria-describedby="edCount edErr"></textarea><div class="fc" id="edCount" aria-live="polite">0/4000</div><div class="fb"><button type="submit" class="btn pri" id="edSave">Save</button><button type="button" class="btn" id="edCancel">Cancel</button></div><p class="err" id="edErr" role="alert" hidden></p></form>`;
407
+ function edError(m){const e=$('#edErr');if(!e)return;e.textContent=m||'';e.hidden=!m;}
408
+ function edCount(){const n=$('#edText'),c=$('#edCount');if(n&&c)c.textContent=[...n.value].length+'/4000';}
409
+ function openEdit(text,err){
410
+ const f=$('#edForm');if(!f)return;f.hidden=false;$('#edBox').hidden=true;$('#edBtn').hidden=true;
411
+ const n=$('#edText');n.value=text;edCount();edError(err||'');n.focus();n.setSelectionRange(n.value.length,n.value.length);
412
+ }
413
+ function closeEdit(refocus){
414
+ const f=$('#edForm');if(!f||f.hidden)return;f.hidden=true;$('#edBox').hidden=false;$('#edBtn').hidden=false;edError('');
415
+ if(refocus)$('#edBtn').focus();
416
+ }
417
+ function bindEdit(col,i){
418
+ $('#edBtn').onclick=()=>openEdit(DATA.tasks[col][i].description);
419
+ $('#edCancel').onclick=()=>closeEdit(true);
420
+ $('#edText').oninput=edCount;
421
+ $('#edText').onkeydown=e=>{
422
+ if(e.key==='Escape'){e.preventDefault();e.stopPropagation();closeEdit(true);}
423
+ else if(e.key==='Enter'&&!e.isComposing){e.preventDefault();if(!e.shiftKey)$('#edForm').requestSubmit();} // one line: Enter never breaks it
424
+ };
425
+ $('#edForm').onsubmit=e=>{e.preventDefault();saveEdit(col,i);};
426
+ }
427
+ let editingDesc=false;
428
+ async function saveEdit(col,i){
429
+ const t=DATA.tasks[col]&&DATA.tasks[col][i],p=PROJECT;if(!t||editingDesc)return;
430
+ const typed=$('#edText').value;
431
+ editingDesc=true;$('#edForm').setAttribute('aria-busy','true');$('#edSave').disabled=true;
432
+ let r,body={};
433
+ try{
434
+ r=await fetch('/api/tasks/fields?'+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,description:typed})});
435
+ body=await r.json().catch(()=>({}));
436
+ }catch(e){r=null;}
437
+ editingDesc=false;
438
+ if(p!==PROJECT)return;
439
+ const f=$('#edForm');if(f){f.removeAttribute('aria-busy');$('#edSave').disabled=false;}
440
+ if(r&&r.status===200){
441
+ closeEdit(false); // before the redraw, which would keep an open form open
442
+ wrote(['.specs/planning/tasks.md'],body.specs);await apply(body.specs,['.specs/planning/tasks.md']);
443
+ const b=$('#edBtn');if(b)b.focus();toast('Description saved.');return;
444
+ }
445
+ if(r&&r.status===409&&body.specs)await apply(body.specs,null); // still in Backlog: the redraw keeps the form and the typed text
446
+ const msg=!r?'The server did not answer. Nothing was changed.':body.error||`Nothing was changed (HTTP ${r.status}).`;
447
+ if($('#edForm')&&!$('#edForm').hidden&&inspOpen&&inspOpen.id===t.id){edError(msg);return;}
448
+ // the row left Backlog: the panel on its new lane, with no Edit; gone, the panel is closed. The typed text is dropped.
449
+ const c=Object.keys(COLS).find(k=>Array.isArray(DATA.tasks[k])&&DATA.tasks[k].some(x=>x.id===t.id));
450
+ if(c){openTask(c,findRow(c,t.id,0),true);$('#inspX').focus();}
451
+ toast(msg);
452
+ }
453
+ /* ---------------- Overview (BL-171, REQ-002.H.76) ----------------
454
+ The landing: cards from the payload (and roadmap.md's text), every text the files' own; a card with nothing to show is left
455
+ out. Counts are of rows or files another view lists, and each opens that view (REQ-002.H.5's Overview exception). */
456
+ const OV_TYPES=['feat','bug','chore'],OV_PRIS=['P1','P2','P3'];
457
+ /* BL-191 redesign (REQ-002.H.76): a top band, two columns that stack on their own, Spec files last; every card the same parts. */
458
+ const ovIco=id=>`<svg class="ico" aria-hidden="true" focusable="false"><use href="#${id}"/></svg>`;
459
+ function ovCard(key,icon,title,src,body,o={}){
460
+ return body?`<section class="ovcard${o.flag?' flag':''}" data-card="${key}"><div class="ovch">${ovIco(icon)}<h3>${esc(title)}</h3>${o.count!==undefined?`<span class="ovcount">${o.count}</span>`:''}${src?`<span class="ovsrc" translate="no">${esc(src)}</span>`:''}</div><div class="ovcb">${body}</div>${o.foot?`<div class="ovcf">${o.foot}</div>`:''}</section>`:'';
461
+ }
462
+ function ovLink(go,label,f){return `<button type="button" class="ovlink" data-go="${go}"${f?` data-f="${esc(f)}"`:''}>${esc(label)}${ovIco('i-chev')}</button>`;}
463
+ function ovRow(col,i,t){return `<button type="button" class="ovrow" data-task="${col}:${i}"><span class="id" translate="no">${mdi(t.id)}</span><span class="d">${mdi(t.description)}</span><span class="ovchips">${chips(t)}</span></button>`;}
464
+ const OV_LINKLESS=['claude-code','codex','windsurf','antigravity']; // IDEs the page has no open link for (README: Windsurf has none yet)
465
+ function ovIdeBtn(){
466
+ const p=DATA.project;
467
+ if(p.cursor)return `<a class="btn" href="${esc(editorUrl(p.root,0,'cursor'))}">${ovIco('i-ext')}Open in Cursor</a>`;
468
+ if(OV_LINKLESS.includes((p.uses||[])[0]))return `<button type="button" class="btn" data-copypath>${ovIco('i-copy')}Copy folder path</button>`;
469
+ return `<a class="btn" href="${esc(editorUrl(p.root))}">${ovIco('i-ext')}Open in VS Code</a>`;
470
+ }
471
+ function renderOverview(){
472
+ const box=$('#ovBox');if(!box||!DATA||!DATA.project)return;
473
+ const O=DATA.overview||{project:{},commits:[],prompts:[]},P=O.project||{},T=DATA.tasks,N=DATA.nav,F=DATA.files||{};
474
+ const label=projectLabel(DATA.project),pm=F['project/project.yaml']||{},has=v=>v!==null&&v!==undefined;
475
+ const facts=[has(P.version)?`version ${P.version}`:null,has(P.language)?String(P.language):null,has(P.framework)?String(P.framework):null,has(P.license)?String(P.license):null,has(pm.lastUpdated)?`lastUpdated ${pm.lastUpdated}`:null].filter(x=>x!==null);
476
+ let lanes='',mixes='',review='',sprint='';
477
+ if(T){
478
+ lanes=`<div class="ovlanes">${['backlog','currentSprint','review','completed'].map(c=>`<button type="button" class="ovlane" data-go="board"><span class="n">${(T[c]||[]).length}</span><span class="l"><span class="st ${DOT[c]}" aria-hidden="true"></span>${esc(COLS[c])}</span></button>`).join('')}</div>`;
479
+ const open=[...(T.backlog||[]),...(T.currentSprint||[]),...(T.review||[])];
480
+ const line=(key,label,cls,vals)=>{const parts=vals.map(v=>[v,open.filter(t=>t[key]===v).length]).filter(([,n])=>n);
481
+ return parts.length?`<button type="button" class="ovmix" data-go="board" data-mix="${key}"><span class="k">${label}</span>${parts.map(([v,n])=>`<span class="pill chip ${cls}${tone(v)}" translate="no">${esc(v)} ${n}</span>`).join('')}</button>`:'';};
482
+ const ty=line('type','Type','ty',OV_TYPES),pr=line('priority','Priority','pri',OV_PRIS);
483
+ mixes=ty||pr?`<div class="ovmixes">${ty}${pr}</div>`:'';
484
+ const rv=T.review||[],cs=T.currentSprint||[];
485
+ review=ovCard('review','i-check','Review','## Review',rv.length?`<div class="ovrows">${rv.map((t,i)=>ovRow('review',i,t)).join('')}</div>`:`<div class="ovempty">${ovIco('i-check')}<span>Nothing waiting for you. Agents move finished work here.</span></div>`,{count:rv.length,foot:ovLink('board','Open Review in Tasks')});
486
+ sprint=cs.length?ovCard('sprint','i-arrow','Current Sprint','## Current Sprint',`<div class="ovrows">${cs.slice(0,5).map((t,i)=>ovRow('currentSprint',i,t)).join('')}</div>`,{count:cs.length,foot:ovLink('board',`All ${cs.length} in Tasks`)}):'';
487
+ }
488
+ const hero=`<section class="ovcard ovhero" data-card="project"><div class="ovident"><div class="ovbig" aria-hidden="true">${esc(initials(label))}</div><div class="ovtxt"><h2 class="ovname">${esc(label)}</h2>${has(P.description)?`<p class="ovdesc">${esc(String(P.description))}</p>`:''}${facts.length?`<div class="ovfacts">${facts.map(f=>`<span class="ovfact" translate="no">${esc(f)}</span>`).join('')}</div>`:''}</div>`
489
+ +`<div class="ovacts"><button type="button" class="btn pri" data-go="board">${ovIco('i-board')}Open Tasks</button>${ovIdeBtn()}</div></div>${lanes}${mixes}</section>`;
490
+ const commits=(O.commits||[]).map(c=>`<div class="ovrow ovcommit"><span class="id" translate="no">${esc(c.hash)}</span><span class="d">${esc(c.message)}</span><span class="when">${esc(when(c.date))}</span></div>`).join('');
491
+ const prompts=(O.prompts||[]).map(p=>`<button type="button" class="ovrow ovprompt" data-go="file" data-f="development/prompts.md"><span class="d">${esc(p)}</span></button>`).join('');
492
+ const done=T?(T.completed||[]).slice().sort((a,b)=>Number(b.num)-Number(a.num)).slice(0,3).map(t=>`<button type="button" class="ovrow ovdone" data-go="board"><span class="id" translate="no">#${esc(t.num)} ${mdi(t.id)}</span><span class="d">${mdi(t.description)}</span></button>`).join(''):'';
493
+ const group=(icon,title,rows)=>rows?`<div class="ovsub">${ovIco(icon)}${title}</div><div class="ovrows">${rows}</div>`:'';
494
+ const recent=ovCard('recent','i-git','Recent activity',[commits?'.git/logs/HEAD':'',prompts?'prompts.md':'',done?'## Completed':''].filter(Boolean).join(' · '),group('i-git','Commits',commits)+group('i-file','Prompt log',prompts)+group('i-check','Completed',done));
495
+ const secFiles=['security/threat-model.md','security/security-decisions.md'].filter(p=>p in F);
496
+ const security=secFiles.length?ovCard('security','i-shield','Security','security/',`<div class="ovsecs">${secFiles.map(p=>{const m=metaLine(F[p]);return `<button type="button" class="ovfile" data-go="security"><span class="p" translate="no">${esc(p)}</span>${m?`<span class="m" translate="no">${esc(m)}</span>`:''}</button>`;}).join('')}</div>`
497
+ +('security/security-decisions.md' in F?`<div class="ovtiles"><button type="button" class="ovtile wide" data-go="security" id="ovDec" hidden><span class="k">Decisions</span><span class="v"></span></button></div>`:''),{foot:ovLink('security','Open Security')}):'';
498
+ const I=N.instructions,gen=a=>a.filter(f=>f.generated).length,cmds=[...N.commands,...N.prompts],S=N.skills;
499
+ const tile=(go,k,v,small,wide)=>`<button type="button" class="ovtile${wide?' wide':''}" data-go="${go}"><span class="k">${esc(k)}</span><span class="v">${esc(v)}</span>${small?`<small translate="no">${esc(small)}</small>`:''}</button>`;
500
+ const guide=ovCard('guide','i-bot','Agent Guidance','',`<div class="ovtiles">`+tile('instructions','Instructions',`${I.filter(f=>f.exists).length} of ${I.length}`,I.filter(f=>f.exists).map(f=>f.path).join(' · '),true)
501
+ +tile('commands','Commands',String(cmds.length),`From SpecPilot ${gen(cmds)} · Yours ${cmds.length-gen(cmds)}`)
502
+ +tile('skills','Skills',String(S.length),[`From SpecPilot ${gen(S)} · Yours ${S.length-gen(S)}`,...S.map(f=>f.path.split('/').slice(-2,-1)[0])].join(' · '))+`</div>`);
503
+ const specs=N.specs.slice().sort((a,b)=>{const x=(F[a]||{}).lastUpdated,y=(F[b]||{}).lastUpdated;
504
+ if(x&&y&&x!==y)return x<y?1:-1;if(!x!==!y)return x?-1:1;return a<b?-1:a>b?1:0;});
505
+ const files=specs.length?ovCard('files','i-file','Spec files','newest first',`<div class="ovfiles">${specs.slice(0,8).map(p=>{const m=metaLine(F[p]);return `<button type="button" class="ovfile" data-go="file" data-f="${esc(p)}"><span class="p" translate="no">${esc(p)}</span>${m?`<span class="m" translate="no">${esc(m)}</span>`:''}</button>`;}).join('')}</div>`,{count:specs.length,foot:ovLink('explorer',`All ${specs.length} in Explorer`)}):'';
506
+ box.innerHTML=`<div id="ovFlag"></div>`+hero+`<div class="ovcols"><div class="ovcol">${review}${sprint}${recent}</div><div class="ovcol"><div id="ovRoad"></div>${security}${guide}</div></div>`+files;
507
+ ovRoadmap();ovDecisions();
508
+ }
509
+ /* Roadmap, always (BL-191): the last ### under ## Timeline and its first five lines, or the board's Warning box saying what to fix. */
510
+ const OV_ROAD={
511
+ norel:['## Timeline in planning/roadmap.md has no ### release','The card shows the last ### heading under ## Timeline and its first lines, and there is none.','add a ### heading for the next release under ## Timeline, with its first lines'],
512
+ notl:['planning/roadmap.md has no ## Timeline','The card shows the last ### release under ## Timeline, and the file has no such section.','add a ## Timeline section with a ### heading for the next release'],
513
+ nofile:['No planning/roadmap.md in .specs/','Every project needs a roadmap; the card shows its latest release.','create planning/roadmap.md with a ## Timeline section and a ### heading for the next release']};
514
+ function ovRoadCard(body,flag){return ovCard('roadmap','i-map','Roadmap','planning/roadmap.md',body,flag?{flag:true}:{foot:ovLink('file','Open Roadmap','planning/roadmap.md')});}
515
+ function ovRoadFlag(kind){
516
+ const [title,what,fix]=OV_ROAD[kind];
517
+ const prompt=kind==='nofile'?'Create .specs/planning/roadmap.md with a ## Timeline section and a ### heading for the next release, so SpecPilot’s Overview shows it.':`In .specs/planning/roadmap.md, ${fix}, so SpecPilot’s Overview shows the next release.`;
518
+ return ovRoadCard(`<div class="msg warn">${ovIco('i-warn')}<div class="mb"><div class="mt"><span class="mw">Warning</span> ${esc(title)}</div><p>${esc(what)}</p><p>Fix: ${esc(fix)}, best done by your AI IDE.</p>`
519
+ +`<div class="actions"><button type="button" class="btn sm" data-prompt="${esc(prompt)}">Copy prompt</button>${kind==='nofile'?'':`<button type="button" class="btn sm" data-go="file" data-f="planning/roadmap.md">Open Roadmap</button>`}</div></div></div>`,true);
520
+ }
521
+ async function ovRoadmap(){
522
+ const pj=PROJECT,place=(card,flagged)=>{const slot=$('#ovRoad');if(PROJECT!==pj||curView!=='overview'||!slot)return;slot.outerHTML=card;
523
+ const f=$('#ovFlag');if(f)f.innerHTML=flagged?`<div class="msg warn ovbanner">${ovIco('i-warn')}<div class="mb"><div class="mt">This project’s roadmap has no release to show. The Roadmap card says what to fix.</div></div></div>`:'';};
524
+ if(!('planning/roadmap.md' in (DATA.files||{})))return place(ovRoadFlag('nofile'),true);
525
+ let src;try{src=await getText('.specs/planning/roadmap.md');}catch(e){return place(ovRoadFlag('nofile'),true);}
526
+ const lines=src.split('\n');
527
+ const t=lines.findIndex(l=>/^## Timeline\b/.test(l.trim()));if(t<0)return place(ovRoadFlag('notl'),true);
528
+ let end=lines.findIndex((l,i)=>i>t&&/^## /.test(l.trim()));if(end<0)end=lines.length;
529
+ let h=-1;for(let i=t+1;i<end;i++)if(/^### /.test(lines[i].trim()))h=i;
530
+ if(h<0)return place(ovRoadFlag('norel'),true);
531
+ let stop=lines.findIndex((l,i)=>i>h&&/^#{1,3} /.test(l.trim()));if(stop<0||stop>end)stop=end;
532
+ const body=lines.slice(h+1,stop).filter(l=>l.trim()).slice(0,5);
533
+ place(ovRoadCard(`<div class="ovroad md">${md([lines[h],...body].join('\n'))}</div>`,false),false);
534
+ }
535
+ /* Decisions <n>: the ### heading lines outside code fences in security-decisions.md, the headings the Security view renders. */
536
+ async function ovDecisions(){
537
+ const pj=PROJECT;if(!('security/security-decisions.md' in (DATA.files||{})))return;
538
+ let src;try{src=await getText('.specs/security/security-decisions.md');}catch(e){return;}
539
+ let fence=false,n=0;for(const l of src.split('\n')){if(/^\s*(```|~~~)/.test(l))fence=!fence;else if(!fence&&/^### /.test(l))n++;}
540
+ const t=$('#ovDec');if(PROJECT!==pj||curView!=='overview'||!t)return;t.querySelector('.v').textContent=String(n);t.hidden=false;
541
+ }
542
+ $('#ovBox').addEventListener('click',e=>{
543
+ const t=e.target.closest('[data-task]');
544
+ if(t){const [col,i]=t.dataset.task.split(':');go('board');openTask(col,+i);return;}
545
+ const p=e.target.closest('[data-prompt]');if(p){copyText(p.getAttribute('data-prompt'));return;}
546
+ if(e.target.closest('[data-copypath]')){copyText(DATA.project.root);return;}
547
+ const g=e.target.closest('[data-go]');if(g)go(g.dataset.go,g.dataset.f);
548
+ });
549
+
339
550
  /* ---------------- Type and Priority (BL-125) ----------------
340
551
  A row of a typed Backlog, Current Sprint or Review table carries a Type and a Priority: chips on the card's bottom
341
552
  line, two radio groups in the detail panel that write through POST /api/tasks/fields on choice, the same two in
@@ -450,7 +661,42 @@ async function review(col,i,action,extra,isUndo){
450
661
  else if($('#inspFoot'))rvError(msg);
451
662
  else toast(msg);
452
663
  }
453
- function openInsp(quiet){insp.classList.add('open');insp.setAttribute('aria-hidden','false');$('#inspX').onclick=closeInsp;if(!quiet)setTimeout(()=>{if(insp.classList.contains('open')&&!insp.contains(document.activeElement))$('#inspX').focus();},60);} // the close button takes focus unless the panel closed meanwhile or something in it already has focus (the Send back box, BL-113)
664
+ /* Resize the details panel (BL-TB-02, REQ-002.H.74): a handle on its left edge; the chosen width is kept per browser
665
+ in sp-insp-width and applied clamped to the pane on each open and window resize, a clamp never rewriting it. */
666
+ const grip=$('#inspGrip'),INSP_W=400,INSP_MIN=320,INSP_GAP=160;
667
+ let inspW=INSP_W;try{const v=parseInt(localStorage.getItem('sp-insp-width'),10);if(v>0)inspW=v;}catch(e){}
668
+ function sizeInsp(){
669
+ const max=insp.parentElement.clientWidth-INSP_GAP,narrow=max<INSP_MIN,w=narrow?INSP_W:Math.max(INSP_MIN,Math.min(inspW,max));
670
+ grip.classList.toggle('off',narrow); // a narrow pane: min(400px, 100%) as before, no handle
671
+ insp.parentElement.style.setProperty('--insp-w',w+'px');
672
+ grip.setAttribute('aria-valuemin',INSP_MIN);grip.setAttribute('aria-valuemax',Math.max(INSP_MIN,max));grip.setAttribute('aria-valuenow',w);
673
+ return w;
674
+ }
675
+ const setInsp=w=>{inspW=w;inspW=sizeInsp();};
676
+ const keepInsp=()=>{try{localStorage.setItem('sp-insp-width',String(inspW));}catch(e){}};
677
+ grip.addEventListener('pointerdown',e=>{
678
+ if(e.button!==0)return;e.preventDefault();grip.focus();grip.setPointerCapture(e.pointerId);
679
+ const x0=e.clientX,w0=sizeInsp();let done=false;
680
+ const move=ev=>setInsp(w0+x0-ev.clientX); // the handle is on the left edge: left widens
681
+ const end=keep=>{
682
+ if(done)return;done=true;
683
+ grip.removeEventListener('pointermove',move);grip.removeEventListener('pointerup',up);grip.removeEventListener('lostpointercapture',up);document.removeEventListener('keydown',esc,true);
684
+ insp.classList.remove('drag');grip.classList.remove('drag');document.body.classList.remove('resizing');
685
+ if(keep)keepInsp();else setInsp(w0);
686
+ };
687
+ const up=()=>end(true);
688
+ const esc=ev=>{if(ev.key==='Escape'){ev.preventDefault();ev.stopPropagation();end(false);}}; // capture: before the page's Escape, which closes the panel
689
+ insp.classList.add('drag');grip.classList.add('drag');document.body.classList.add('resizing');
690
+ grip.addEventListener('pointermove',move);grip.addEventListener('pointerup',up);grip.addEventListener('lostpointercapture',up);document.addEventListener('keydown',esc,true);
691
+ });
692
+ grip.addEventListener('keydown',e=>{
693
+ const cur=+grip.getAttribute('aria-valuenow'),to={ArrowLeft:cur+16,ArrowRight:cur-16,Home:INSP_MIN,End:Infinity}[e.key];
694
+ if(to===undefined)return;e.preventDefault();e.stopPropagation();setInsp(to);keepInsp();
695
+ });
696
+ grip.addEventListener('dblclick',()=>{inspW=INSP_W;sizeInsp();try{localStorage.removeItem('sp-insp-width');}catch(e){}});
697
+ window.addEventListener('resize',()=>sizeInsp());
698
+ sizeInsp();
699
+ function openInsp(quiet){sizeInsp();insp.classList.add('open');insp.setAttribute('aria-hidden','false');$('#inspX').onclick=closeInsp;if(!quiet)setTimeout(()=>{if(insp.classList.contains('open')&&!insp.contains(document.activeElement))$('#inspX').focus();},60);} // the close button takes focus unless the panel closed meanwhile or something in it already has focus (the Send back box, BL-113)
454
700
  function closeInsp(){const was=insp.classList.contains('open');insp.classList.remove('open');insp.setAttribute('aria-hidden','true');selected=null;inspOpen=null;$$('.row.sel').forEach(r=>r.classList.remove('sel'));if(was&&lastFocus&&lastFocus.focus){lastFocus.focus();lastFocus=null;}}
455
701
  function bind(){
456
702
  $$('#v-board .row[data-col]').forEach(r=>{const col=r.dataset.col,i=+r.dataset.i;
@@ -502,11 +748,19 @@ async function renderSecurity(){
502
748
  }
503
749
 
504
750
  /* ---------------- automation: generated files, read as they are ---------------- */
751
+ /* An absent file says why (BL-161, REQ-002.H.69): missing for an IDE the project uses, else not needed, else
752
+ (no IDE known) not in this repo. The server decides which IDEs; the page only names them. */
753
+ function absentTrail(f,uses){
754
+ const names=a=>a.map(v=>IDE_NAME[v]||v).join(', ');
755
+ if(!uses.length)return {pill:'<span class="pill gray">not in this repo</span>',det:''};
756
+ return f.ides.length?{pill:'<span class="pill orange">missing</span>',det:`SpecPilot writes it for ${esc(names(f.ides))}.`}
757
+ :{pill:'<span class="pill gray">not needed</span>',det:`This project uses ${esc(names(uses))}.`};
758
+ }
505
759
  function renderIde(){
506
- const I=DATA.nav.instructions;
760
+ const I=DATA.nav.instructions,uses=DATA.project&&DATA.project.uses||[];
507
761
  $('#insBox').innerHTML=I.map(f=>f.exists
508
762
  ?`<button type="button" class="row act" data-open="${esc(f.path)}"><span class="st green" aria-hidden="true"></span><div class="body"><div class="ttl"><span class="id" translate="no">${esc(f.path)}</span></div><div class="det">${f.bytes} bytes</div></div><div class="trail">${chev}</div></button>`
509
- :`<div class="row"><span class="st hollow" aria-hidden="true"></span><div class="body"><div class="ttl"><span class="id" translate="no">${esc(f.path)}</span></div></div><div class="trail"><span class="pill gray">not in this repo</span></div></div>`).join('');
763
+ :(a=>`<div class="row"><span class="st hollow" aria-hidden="true"></span><div class="body"><div class="ttl"><span class="id" translate="no">${esc(f.path)}</span></div>${a.det?`<div class="det">${a.det}</div>`:''}</div><div class="trail">${a.pill}</div></div>`)(absentTrail(f,uses))).join('');
510
764
  $('#insMeta').textContent=I.filter(f=>f.exists).length+' of '+I.length;
511
765
  }
512
766
  function fileRows(list){
@@ -673,6 +927,7 @@ const palVeil=$('#palVeil'),palIn=$('#palIn'),palList=$('#palList');
673
927
  function items(q){q=q.toLowerCase();
674
928
  const T=DATA?DATA.tasks:null;
675
929
  const it=[
930
+ {l:'Overview',k:'view',go:()=>go('overview')}, // BL-171: first, with no digit key, so NAV and 1 to 9 stay
676
931
  ...NAV.map(n=>n[0]==='file'?{l:'.specs/'+n[1],k:'file',go:()=>go('file',n[1])}:{l:VIEWS[n[0]],k:'view',go:()=>go(n[0])}),
677
932
  ...(DATA?DATA.nav.specs:[]).filter(p=>!NAV.some(n=>n[1]===p)).map(p=>({l:'.specs/'+p,k:'file',go:()=>go('file',p)})),
678
933
  ...(T?['currentSprint','review','backlog','completed','wontDo'].flatMap(c=>(T[c]||[]).map((t,i)=>({l:t.id+' '+t.description,k:'task',go:()=>{go('board');openTask(c,i)}}))):[])
@@ -687,8 +942,8 @@ document.addEventListener('keydown',e=>{
687
942
  const mod=e.metaKey||e.ctrlKey;const inField=/INPUT|SELECT|TEXTAREA/.test(e.target.tagName);
688
943
  if(mod&&e.key.toLowerCase()==='k'){e.preventDefault();palVeil.classList.contains('open')?closePal():openPal();return}
689
944
  if(mod&&/^[1-9]$/.test(e.key)){e.preventDefault();const n=NAV[+e.key-1];if(n)go(n[0],n[1]);return}
690
- if(e.key==='Escape'){if(busyVeil.classList.contains('open')){closeBusy();return}if(!ideMenu.hidden){closeIde(true);return}if(!cardMenu.hidden){closeCardMenu(true);return}hideTip();closeInsp();closePal();closeSheet();closeNewTask();closeArchive();setNav(false);return}
691
- if(inField||mod||e.altKey||!cardMenu.hidden||taskVeil.classList.contains('open')||archVeil.classList.contains('open')||busyVeil.classList.contains('open'))return;
945
+ if(e.key==='Escape'){if(busyVeil.classList.contains('open')){closeBusy();return}if(!ideMenu.hidden){closeIde(true);return}if(!cardMenu.hidden){closeCardMenu(true);return}if(!setMenu.hidden){closeSet(true);return}hideTip();closeInsp();closePal();closeSheet();closeNewTask();closeArchive();setNav(false);return}
946
+ if(inField||mod||e.altKey||!cardMenu.hidden||!setMenu.hidden||taskVeil.classList.contains('open')||archVeil.classList.contains('open')||busyVeil.classList.contains('open'))return;
692
947
  if(e.key==='h'&&TOKEN&&!openVeil.classList.contains('open')){go('home');return;}
693
948
  if(/^[1-9]$/.test(e.key)){const n=NAV[+e.key-1];if(n)go(n[0],n[1]);}
694
949
  if((e.key==='j'||e.key==='k')&&curView==='board'){const rows=$$('#v-board .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();}
@@ -858,7 +1113,7 @@ $('#taskForm').onsubmit=e=>{e.preventDefault();addTask();};
858
1113
  /* ---------------- archive Completed (BL-TB-06, D8) ----------------
859
1114
  The Completed step of `specpilot archive`, run by the server with the same plan and block as the CLI. The
860
1115
  dialog says what the action does and lists the gates from the latest payload: the CLI's branch guard and the
861
- 40-line limit, each with a box to tick when it warns; a section within the limit is archived with {force:true}
1116
+ line limit (its numbers from tasks.archive, BL-123), each with a box to tick when it warns; a section within the limit is archived with {force:true}
862
1117
  once the user ticks that box. Every other answer than 200 is shown in the dialog, as New Task does. */
863
1118
  const archVeil=$('#archVeil');
864
1119
  let archiving=false;
@@ -867,9 +1122,9 @@ function archGates(){
867
1122
  if(!b)out.push({key:'branch',text:'No git branch.'});
868
1123
  else if(b==='main'||b==='master')out.push({key:'branch',text:`On ${b}.`});
869
1124
  else out.push({key:'branch:'+b,warn:true,text:`On branch ${b}. Archive is recommended only on the default branch after merging. ${branchRisk('The archive')} Archive on this branch anyway.`});
870
- if(!a.rows)out.push({key:'none',off:true,text:`Nothing to archive: ## Completed has ${n} ${n===1?'row':'rows'}, and an archive keeps the newest 20.`});
871
- else if(a.lines>40)out.push({key:'limit',text:`## Completed is ${a.lines} lines, over its 40-line limit: ${a.rows} rows move, the newest 20 stay.`});
872
- else out.push({key:'force',warn:true,text:`## Completed is ${a.lines} lines, within its 40-line limit. Archive ${a.rows} rows anyway; the newest 20 stay.`});
1125
+ if(!a.rows)out.push({key:'none',off:true,text:`Nothing to archive: ## Completed has ${n} ${n===1?'row':'rows'}, and an archive keeps the newest ${a.keep}.`});
1126
+ else if(a.lines>a.limit)out.push({key:'limit',text:`## Completed is ${a.lines} lines, over its ${a.limit}-line limit: ${a.rows} rows move, the newest ${n-a.rows} stay.`});
1127
+ else out.push({key:'force',warn:true,text:`## Completed is ${a.lines} lines, within its ${a.limit}-line limit. Archive ${a.rows} rows anyway; the newest ${n-a.rows} stay.`});
873
1128
  const act=recentActivity();
874
1129
  if(act)out.push({key:'activity',warn:true,text:`${act}: an agent or editor may still be working on the specs. If it saves planning/tasks.md from a copy it read before the archive, the archive is lost; if it edits after, its edit can fail or land on the wrong row because the rows moved under it. Archive anyway.`});
875
1130
  return out;
@@ -981,14 +1236,13 @@ function renderSetup(){
981
1236
  $('#suOff').hidden=MCP_ON;
982
1237
  $$('#v-setup .step').forEach(el=>{el.classList.toggle('off',!MCP_ON);el.inert=!MCP_ON;});
983
1238
  $('#suConfigBox').hidden=!MCP_ON;
984
- if(MCP_ON){const env=MCP==='env',line=mcpConfigLine(location.host,env?'${SPECPILOT_MCP_TOKEN}':TOKEN);
985
- $('#suConfig').textContent=JSON.stringify(JSON.parse(line),null,2);$('#suConfig').dataset.line=line;$('#suMcpNote').textContent=$('#mcpNote').textContent;}
986
- else $('#suMcpNote').textContent='';
1239
+ $('#suIde').hidden=!MCP_ON;
1240
+ if(MCP_ON)drawMcp();else $('#suMcpNote').textContent='';
987
1241
  $('#suFoot').innerHTML=`Prefer the terminal? ${mono(isNew?'specpilot init':'specpilot add-specs')} in that folder asks the same questions one by one.`;
988
1242
  suStatus();suPrompt();drawProgress();
989
1243
  }
990
1244
  function copyText(text){(navigator.clipboard?navigator.clipboard.writeText(text):Promise.reject()).then(()=>toast('Copied.'),()=>toast('Could not copy. Select the line and copy it.'));}
991
- $('#suConfigCopy').onclick=()=>copyText($('#suConfig').dataset.line);
1245
+ $('#suConfigCopy').onclick=()=>copyText($('#suConfig').textContent);
992
1246
  $('#suPromptCopy').onclick=()=>copyText($('#suPrompt').textContent);
993
1247
  /* #new: when the name passes init's rule and a parent is typed, register <parent>/<name> as the one pending path. */
994
1248
  async function registerPending(){
@@ -1060,17 +1314,19 @@ async function apply(d,paths){
1060
1314
  const scroll=$('#content').scrollTop,ib0=insp.querySelector('.ib2'),inspScroll=ib0?ib0.scrollTop:0;
1061
1315
  const lanes=$$('#boardMode .gl[data-col] .box').map(b=>[b.closest('.gl').dataset.col,b.scrollTop]); // BL-TB-03: each lane's own scroll
1062
1316
  const was=inspOpen;
1317
+ const edF=$('#edForm'),edTyped=edF&&!edF.hidden?$('#edText').value:null; // BL-TB-08: an open edit survives a redraw
1063
1318
  const hadSpecs=!(DATA&&DATA.project&&DATA.project.specs===false);
1064
1319
  DATA=d;
1065
1320
  renderAll();
1066
1321
  const to=reloadView(curView,hadSpecs,!d.project||d.project.specs!==false); // .specs/ gone: offer setup; appeared another way: Tasks; Home stays
1067
- if(to){go(to);return;}
1322
+ if(to){replacing(()=>go(to));return;} // a forced view replaces the entry (BL-192)
1068
1323
  if(curView==='file')await renderFile(curFile);
1069
1324
  if(curView==='explorer')renderExplorer();
1325
+ if(curView==='overview')renderOverview();
1070
1326
  if(curView==='security')await renderSecurity();
1071
1327
  if(was&&was.kind==='task'){
1072
1328
  const i=findRow(was.col,was.id,was.i);
1073
- if(i>=0){openTask(was.col,i,true);$$(`#v-board .row[data-col="${was.col}"][data-i="${i}"]`).forEach(r=>r.classList.add('sel'));}
1329
+ if(i>=0){openTask(was.col,i,true);$$(`#v-board .row[data-col="${was.col}"][data-i="${i}"]`).forEach(r=>r.classList.add('sel'));if(edTyped!==null)openEdit(edTyped);}
1074
1330
  else{insp.classList.remove('open');insp.setAttribute('aria-hidden','true');selected=null;inspOpen=null;}
1075
1331
  }
1076
1332
  if(was&&was.kind==='file'&&(!paths||paths.includes(was.path)))await openFile(was.path,true);
@@ -1087,6 +1343,7 @@ function listen(missed){
1087
1343
  es.addEventListener('clone',e=>onCloneEvent(e.data));
1088
1344
  es.addEventListener('setup',e=>onSetupEvent(e.data));
1089
1345
  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();}});
1346
+ es.addEventListener('closed',()=>projectClosed(PROJECT)); // this project was closed from another page (BL-166)
1090
1347
  es.addEventListener('change',e=>{let paths=null;try{paths=JSON.parse(e.data).paths;}catch(_){}refresh(Array.isArray(paths)?paths:null);});
1091
1348
  const mine=es; // a refusal or a 503 closes it for good: reopen it in 5 s unless it was replaced meanwhile (BL-144)
1092
1349
  es.onerror=()=>{dropped=true;if(mine.readyState===2)setTimeout(()=>{if(es===mine)listen(true);},5000);}; // otherwise EventSource retries by itself
@@ -1108,10 +1365,10 @@ function showProject(d,keepRoute){
1108
1365
  Object.keys(fileCache).forEach(k=>{delete fileCache[k];});secShown.clear();
1109
1366
  DATA=d;selected=null;setRegenNote([]);
1110
1367
  renderAll();listen();
1111
- if(keepRoute)route();else go('board');
1368
+ if(keepRoute)route();else go('overview');
1112
1369
  }
1113
1370
  $('#projList').addEventListener('click',e=>{const b=e.target.closest('[data-project]');if(!b)return;
1114
- if(+b.dataset.project!==PROJECT)switchProject(+b.dataset.project);else if(NOPROJ.includes(curView))go('board');});
1371
+ if(+b.dataset.project!==PROJECT)switchProject(+b.dataset.project);else if(NOPROJ.includes(curView))go('overview');});
1115
1372
 
1116
1373
  /* ---------------- open a project (BL-067) ----------------
1117
1374
  The + tile opens the mockup's sheet on its Folder tab. The list is GET /api/projects; opening is
@@ -1124,17 +1381,37 @@ const openVeil=$('#openVeil'),addBtn=$('#addBtn'),pathIn=$('#pathIn');
1124
1381
  const TABS=['folder','clone'],GO={folder:'Open',clone:'Clone Repository'};
1125
1382
  let openBusy=false,sheetFrom=$('#homeOpen'),sheetTab='folder',cloneCtl=null,browseCtl=null,browseBtn=null,cloneNamed=false,cloneTick=null,cloneT0=0,cloneProg=null;
1126
1383
  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)
1127
- /* Connect Your AI IDE (BL-PM-007): the config line for this server's /mcp, unless --no-mcp (BL-105). No status here:
1128
- the page cannot know whether an IDE uses it. `env`: the token is SPECPILOT_MCP_TOKEN, so the line names it. */
1384
+ /* Connect Your AI IDE (BL-PM-007): the config for this server's /mcp, unless --no-mcp (BL-105). No status here:
1385
+ the page cannot know whether an IDE uses it. Per IDE since BL-157 (REQ-002.H.68), one choice for Home and the Setup
1386
+ view: kept in the browser, else the first IDE the project's project.yaml lists (BL-158, REQ-002.A.13), else
1387
+ without a list the IDE of the first instruction file the project in front has, else Claude Code; nothing labels
1388
+ that guess. `env`: the token is SPECPILOT_MCP_TOKEN, whose value the page never holds. */
1389
+ const IDE_NAME={'claude-code':'Claude Code',cursor:'Cursor',vscode:'VS Code',windsurf:'Windsurf',codex:'Codex',antigravity:'Antigravity'};
1390
+ const IDE_OF={'CLAUDE.md':'Claude Code','AGENTS.md':'Codex','.github/copilot-instructions.md':'VS Code','.cursor/rules/specpilot.mdc':'Cursor','.windsurfrules':'Windsurf','.antigravity/rules.md':'Antigravity','CODEX_INSTRUCTIONS.md':'Codex'};
1391
+ let mcpIde=null;try{const v=localStorage.getItem('sp-mcp-ide');if(MCP_IDES.includes(v))mcpIde=v;}catch(e){}
1392
+ function mcpChoice(){
1393
+ if(mcpIde)return mcpIde;
1394
+ const ides=DATA&&DATA.project?DATA.project.ides:null;
1395
+ if(ides)return IDE_NAME[ides[0]]||'Claude Code';
1396
+ const f=DATA&&DATA.nav?DATA.nav.instructions.find(i=>i.exists):null;
1397
+ return f&&IDE_OF[f.path]||'Claude Code';
1398
+ }
1399
+ function drawMcp(){
1400
+ if(!TOKEN||!MCP)return;
1401
+ const ide=mcpChoice(),c=mcpConfig(ide,location.host,MCP==='env'?null:TOKEN);
1402
+ const a=document.activeElement,fg=a&&a.closest?a.closest('#mcpIde,#suIde'):null,fv=fg&&a.dataset.v; // a redraw keeps focus (live reload, a choice)
1403
+ for(const [g,box] of [['#mcpIde','#homeMcp'],['#suIde','#suConnect']]){
1404
+ $(g).innerHTML=MCP_IDES.map(v=>`<button type="button" role="radio" data-v="${v}" aria-checked="${v===ide}" tabindex="${v===ide?0:-1}" class="${v===ide?'on':''}">${v}</button>`).join('');
1405
+ bindRadios($(box),(key,b)=>{mcpIde=b.dataset.v;try{localStorage.setItem('sp-mcp-ide',mcpIde);}catch(e){}drawMcp();});
1406
+ }
1407
+ if(fg)$(`#${fg.id} [data-v="${fv}"]`).focus();
1408
+ $('#mcpLine').textContent=c.text;$('#mcpNote').textContent=c.note;
1409
+ $('#suConfig').textContent=c.text;$('#suMcpNote').textContent=c.note;
1410
+ }
1129
1411
  if(TOKEN&&MCP){
1130
- const env=MCP==='env';
1131
- $('#mcpLine').textContent=mcpConfigLine(location.host,env?'${SPECPILOT_MCP_TOKEN}':TOKEN);
1132
- $('#mcpNote').textContent=env
1133
- ?'Add this to your IDE\u2019s MCP settings or to .mcp.json in your project. Claude Code fills in ${SPECPILOT_MCP_TOKEN} from the environment; for other IDEs, put the token in its place.'
1134
- :'Add this to your IDE\u2019s MCP settings, or to .mcp.json in your project and add .mcp.json to .gitignore. The token changes each time specpilot serve starts.';
1412
+ drawMcp();
1135
1413
  $('#homeMcp').hidden=false;
1136
- $('#mcpCopy').onclick=()=>(navigator.clipboard?navigator.clipboard.writeText($('#mcpLine').textContent):Promise.reject())
1137
- .then(()=>toast('Copied.'),()=>toast('Could not copy. Select the line and copy it.'));
1414
+ $('#mcpCopy').onclick=()=>copyText($('#mcpLine').textContent);
1138
1415
  }
1139
1416
  function openSheet(from,tab){
1140
1417
  hideTip();sheetFrom=from;openVeil.classList.add('open');
@@ -1183,7 +1460,7 @@ async function showOutcome(o){
1183
1460
  closeSheet();
1184
1461
  if(o.specs){PROJECT=o.project;showProject(o.specs,false);}
1185
1462
  else if(o.project!==PROJECT)await switchProject(o.project);
1186
- else if(wasHome)go('board');
1463
+ else if(wasHome)go('overview');
1187
1464
  toast(o.toast);
1188
1465
  if(wasHome)$('#content').focus(); // Home is gone from the screen: focus goes to the project's view, not to a hidden control
1189
1466
  }
@@ -1252,7 +1529,7 @@ async function browseFolder(btn,field,pick){
1252
1529
  async function removeRecent(path){
1253
1530
  let out;
1254
1531
  try{out=await postPath(path,'/api/projects/remove');}catch(e){toast('The server did not answer.');return;}
1255
- 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}).`);
1532
+ if(out.r.status===200){if(out.res.closed!=null)projectClosed(out.res.closed,out.res.projects);drawRecent(out.res);if(curView==='home')drawRecent(out.res,true);}else toast(out.res.error||`Nothing was removed (HTTP ${out.r.status}).`);
1256
1533
  }
1257
1534
  addBtn.onclick=()=>{go('home');$('#homeOpen').focus();}; // every new project starts from Home (BL-PM-014); only Home's buttons open the sheet
1258
1535
  homeBtn.onclick=()=>go('home');