specpilot 2.16.0 → 2.18.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 (41) hide show
  1. package/README.md +10 -7
  2. package/dist/commands/serve.d.ts +4 -2
  3. package/dist/commands/serve.d.ts.map +1 -1
  4. package/dist/commands/serve.js +71 -19
  5. package/dist/commands/serve.js.map +1 -1
  6. package/dist/commands/validate.d.ts.map +1 -1
  7. package/dist/commands/validate.js +59 -74
  8. package/dist/commands/validate.js.map +1 -1
  9. package/dist/core/ideConfig.js +1 -1
  10. package/dist/core/ideConfig.js.map +1 -1
  11. package/dist/core/specFiles.js +14 -5
  12. package/dist/core/specFiles.js.map +1 -1
  13. package/dist/utils/mcpLocal.d.ts +2 -0
  14. package/dist/utils/mcpLocal.d.ts.map +1 -1
  15. package/dist/utils/mcpLocal.js +14 -6
  16. package/dist/utils/mcpLocal.js.map +1 -1
  17. package/dist/utils/specArchiver.d.ts +9 -2
  18. package/dist/utils/specArchiver.d.ts.map +1 -1
  19. package/dist/utils/specArchiver.js +21 -13
  20. package/dist/utils/specArchiver.js.map +1 -1
  21. package/dist/utils/specReader.d.ts +62 -4
  22. package/dist/utils/specReader.d.ts.map +1 -1
  23. package/dist/utils/specReader.js +75 -2
  24. package/dist/utils/specReader.js.map +1 -1
  25. package/dist/utils/specServer.d.ts +10 -1
  26. package/dist/utils/specServer.d.ts.map +1 -1
  27. package/dist/utils/specServer.js +111 -14
  28. package/dist/utils/specServer.js.map +1 -1
  29. package/dist/utils/specValidator.d.ts +28 -0
  30. package/dist/utils/specValidator.d.ts.map +1 -1
  31. package/dist/utils/specValidator.js +79 -1
  32. package/dist/utils/specValidator.js.map +1 -1
  33. package/dist/utils/taskMover.d.ts +99 -12
  34. package/dist/utils/taskMover.d.ts.map +1 -1
  35. package/dist/utils/taskMover.js +276 -35
  36. package/dist/utils/taskMover.js.map +1 -1
  37. package/package.json +1 -1
  38. package/ui/app.css +80 -10
  39. package/ui/app.js +377 -91
  40. package/ui/index.html +20 -11
  41. package/ui/route.js +3 -1
package/ui/app.js CHANGED
@@ -7,12 +7,14 @@ const toastEl=$('#toast');let toastT;
7
7
  const toast=(m,action)=>{
8
8
  toastEl.textContent=m;toastEl.classList.toggle('has-action',!!action);
9
9
  if(action){const b=document.createElement('button');b.type='button';b.className='tact';b.textContent=action.label;b.onclick=()=>{toastEl.classList.remove('show');action.fn();};toastEl.appendChild(b);}
10
- toastEl.classList.add('show');clearTimeout(toastT);toastT=setTimeout(()=>toastEl.classList.remove('show'),action?8000:2600);};
10
+ // BL-UI-03: a close button on every toast; it hides the toast early and clears the timer, and never runs the action
11
+ const x=document.createElement('button');x.type='button';x.className='tx';x.setAttribute('aria-label','Dismiss');x.innerHTML='<svg class="ico" aria-hidden="true" focusable="false"><use href="#i-x"/></svg>';x.onclick=()=>{toastEl.classList.remove('show');clearTimeout(toastT);};toastEl.appendChild(x);
12
+ toastEl.classList.add('show');clearTimeout(toastT);toastT=setTimeout(()=>toastEl.classList.remove('show'),8000);}; // every toast stays 8 s (D13; 2.6 s for a plain one until 2026-10-21), the × ends it early (BL-UI-03)
11
13
  /* Task moves (BL-053) are on only when the server put a token in the page (not with --read-only). */
12
14
  const TOKEN=(document.querySelector('meta[name="specpilot-token"]')||{}).content||null;
13
15
  /* /mcp is on (BL-PM-007), and whose token it takes: `page` or `env` (SPECPILOT_MCP_TOKEN). */
14
16
  const MCP=(document.querySelector('meta[name="specpilot-mcp"]')||{}).content||null;
15
- const MOVABLE={backlog:true,currentSprint:true};
17
+ const ADDABLE={backlog:true,currentSprint:true}; // the sections POST /api/tasks/new writes to (REQ-002.H.29); which lanes move comes from the payload's table (BL-TB-11)
16
18
  const chev='<svg class="ico chev" aria-hidden="true" focusable="false"><use href="#i-chev"/></svg>';
17
19
 
18
20
  /* theme: dark by default, light is a per-viewer toggle */
@@ -58,15 +60,21 @@ function initials(n){const w=String(n).split(/[^A-Za-z0-9]+/).filter(Boolean);
58
60
  if(w.length>1)return (w[0][0]+w[1][0]).toUpperCase();
59
61
  return w[0].slice(0,2).toUpperCase();}
60
62
  function renderProject(){
61
- const p=DATA.project, name=projectLabel(p), where=p.root+(p.branch?' · '+p.branch:'');
63
+ $('#footAddr').textContent=$('#homeAddr').textContent=location.host;$('#footVer').textContent=$('#homeVer').textContent='v'+DATA.specpilotVersion;
64
+ const p=DATA.project;
65
+ if(!p){ // no project served (BL-080): an empty rail and top bar; Home is the view
66
+ $('#projList').innerHTML='';$('#curGrp').textContent='';$('#curGrp').title='';$('#curBranch').textContent='';
67
+ $('#subName').textContent='';$('#subPath').textContent='';document.title='SpecPilot Local';return;}
68
+ const name=projectLabel(p), where=p.root+(p.branch?' · '+p.branch:'');
62
69
  $('#projList').innerHTML=DATA.projects.map((q,i)=>{const n=projectLabel(q),cur=i===PROJECT&&!NOPROJ.includes(curView);
63
70
  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('');
64
71
  $('#curGrp').textContent=name;$('#curGrp').title=p.root;
65
72
  $('#curBranch').textContent=p.branch||'';
66
73
  $('#subName').textContent=name;$('#subPath').textContent=where;$('#editorBtn').href=editorUrl(p.root);syncIde();
67
- $('#footAddr').textContent=$('#homeAddr').textContent=location.host;$('#footVer').textContent=$('#homeVer').textContent='v'+p.specpilotVersion;
68
74
  document.title=name+' · SpecPilot Local';
69
75
  }
76
+ /* Everything a payload draws; with no project served (BL-080) only the rail, bar and footer. */
77
+ function renderAll(){renderProject();if(!DATA.project)return;renderTasks();renderIde();renderAgentFiles();}
70
78
 
71
79
  /* ---------------- views ---------------- */
72
80
  const homeBtn=$('#homeBtn');
@@ -84,28 +92,28 @@ function syncNav(){
84
92
  [homeBtn,...$$('#projList .tile')].forEach(t=>{const cur=t===homeBtn?home:!off&&+t.dataset.project===PROJECT;
85
93
  t.classList.toggle('cur',cur);if(cur)t.setAttribute('aria-current','true');else t.removeAttribute('aria-current');});
86
94
  }
87
- function go(v,keep,sub){
95
+ function go(v,sub){
88
96
  if(v==='file'){if(!DATA||!sub)v='board';else curFile=sub;}
89
97
  else if(NOPROJ.includes(v)){if(!TOKEN)v='board';} // no Home and no #new with --read-only
90
98
  else if(!VIEWS[v]||v==='setup')v='board';
91
- if(!NOPROJ.includes(v)&&DATA&&DATA.project.specs===false)v='setup'; // no .specs/ yet: every route of the project shows the setup view (BL-055)
99
+ if(!NOPROJ.includes(v)&&DATA&&!DATA.project)v='home'; // no project served: Home is the only view (BL-080)
100
+ 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)
92
101
  curView=v;
93
102
  $('#win').classList.toggle('home',v==='home');$('#win').classList.toggle('insetup',v==='new'||v==='setup');
94
103
  $$('.content>.view').forEach(e=>e.classList.toggle('on',e.id==='v-'+(v==='new'?'setup':v))); // one Setup view for both (BL-103)
95
104
  syncNav();
96
105
  $('#title').textContent=v==='file'?(TITLES[sub]||sub):VIEWS[v];$('#crumb').hidden=true;
97
106
  if(v!=='new'&&browseCtl&&browseBtn&&browseBtn.id==='suBrowse')browseCtl.abort(); // leaving #new closes its folder dialog (BL-097)
98
- $('#modeSeg').hidden=v!=='board';$('#newTask').hidden=!(TOKEN&&v==='board');$('#editorBtn').hidden=NOPROJ.includes(v);syncIde();
99
- setNav(false);closeInsp();
107
+ $('#editorBtn').hidden=NOPROJ.includes(v);syncIde();
108
+ setNav(false);closeInsp();closeCardMenu(false);
100
109
  if(v==='home')loadRecent();
101
110
  if(v==='setup'||v==='new')renderSetup();
102
111
  if(v==='file')renderFile(sub);
103
112
  if(v==='explorer')renderExplorer();
104
113
  if(v==='security')renderSecurity();
105
- setHash(v,v==='file'?sub:(keep?stateFor(v):null));
114
+ setHash(v,v==='file'?sub:null);
106
115
  $('#content').scrollTop=0;
107
116
  }
108
- function stateFor(v){return v==='board'?(mode==='board'?'board':null):null}
109
117
  /* URL state. Sandboxed frames refuse replaceState with a URL, so fall back to an in-memory hash. */
110
118
  let urlOk=true,memHash='';
111
119
  try{history.replaceState(null,'',location.href);}catch(e){urlOk=false;}
@@ -118,11 +126,10 @@ function route(){
118
126
  const r=resolveRoute(curHash(),DATA?DATA.files:{},DATA?DATA.projects.length:1,!!TOKEN);
119
127
  if(NOPROJ.includes(r.view)){go(r.view);return;} // Home and #new belong to no project: the shown one stays loaded behind them
120
128
  if(r.project!==PROJECT){switchProject(r.project,true);return;}
121
- if(r.view==='board'&&r.sub==='board'){mode='board';$$('#modeSeg button').forEach(x=>x.classList.toggle('on',x.dataset.m==='board'));renderTasks();}
122
- go(r.view,true,r.sub);
129
+ go(r.view,r.sub);
123
130
  }
124
131
  if(urlOk)window.addEventListener('hashchange',route);
125
- $$('.src .srow[data-v]').forEach(b=>b.onclick=()=>go(b.dataset.v,false,b.dataset.f));
132
+ $$('.src .srow[data-v]').forEach(b=>b.onclick=()=>go(b.dataset.v,b.dataset.f));
126
133
  function setNav(on){const w=$('#win');w.classList.toggle('nav',on);$('#scrim').hidden=!on;$('#menuBtn').setAttribute('aria-expanded',on?'true':'false');}
127
134
  $('#menuBtn').onclick=()=>setNav(!$('#win').classList.contains('nav'));
128
135
  $('#scrim').onclick=()=>setNav(false);
@@ -159,10 +166,16 @@ $('#rail').addEventListener('keydown',e=>{
159
166
  /* ---------------- tasks: the rows of planning/tasks.md ---------------- */
160
167
  /* Cells are readSpecs() output, verbatim. Rows are keyed by section and position, never by
161
168
  ID: IDs repeat in real files (two rows can share a # and an ID). */
162
- let mode='list', selected=null, lastFocus=null, showAllBacklog=false, showAllDone=false;
169
+ let selected=null, lastFocus=null;
163
170
  const insp=$('#insp');
164
- const COLS={currentSprint:'Current Sprint',backlog:'Backlog',completed:'Completed'};
165
- const DOT={completed:'green',currentSprint:'orange',backlog:'hollow'};
171
+ const COLS={currentSprint:'Current Sprint',backlog:'Backlog',review:'Review',completed:'Completed',wontDo:"Won't do"};
172
+ const DOT={completed:'green',currentSprint:'orange',backlog:'hollow',review:'violet',wontDo:'gray'};
173
+ const PILL={completed:'green',currentSprint:'orange',backlog:'gray',review:'violet',wontDo:'gray'};
174
+ /* BL-113: Review's human-in-the-loop pill and its empty text; Won't do is folded to a strip until opened (a page variable, so a reload folds it again). */
175
+ const HITL='Human-in-the-loop: you check the agent\'s work here before it counts as done';
176
+ let wontDoOpen=false;
177
+ /* A lane is drawn when its heading is in the file; the three of BL-TB-04 always, with BL-112's warning when one is missing. */
178
+ function laneDrawn(col){const T=DATA&&DATA.tasks;if(!T)return false;return col==='review'||col==='wontDo'?T.headings.found.includes('## '+COLS[col]):true;}
166
179
  function mdi(t){return md(String(t)).replace(/^<p>/,'').replace(/<\/p>$/,'');}
167
180
  /* Completed is listed newest first (the file runs oldest first); the others in file order. */
168
181
  function rowsOf(col){
@@ -170,38 +183,98 @@ function rowsOf(col){
170
183
  const items=T[col].map((t,i)=>({t,i}));
171
184
  return col==='completed'?items.reverse():items;
172
185
  }
186
+ /* A card: the row button and, beside it, the ⋯ menu button (BL-TB-11; a button cannot nest in a button). Drag handles for the lanes in the move table. */
173
187
  function taskRow({t,i},col){
174
- const mv=TOKEN&&MOVABLE[col];
175
- return `<button type="button" class="row act" data-col="${col}" data-i="${i}"${mv?' draggable="true" aria-keyshortcuts="Alt+ArrowUp Alt+ArrowDown Alt+ArrowLeft Alt+ArrowRight"':''}>
188
+ const mv=TOKEN&&canMove(col,col);
189
+ return `<div class="card"><button type="button" class="row act" data-col="${col}" data-i="${i}"${mv?' draggable="true" aria-keyshortcuts="Alt+ArrowUp Alt+ArrowDown Alt+ArrowLeft Alt+ArrowRight"':''}>
176
190
  <span class="st ${DOT[col]}" aria-hidden="true"></span>
177
191
  <div class="body"><div class="ttl clamp">${col==='completed'?`<span class="num" translate="no">${esc(t.num)}</span>`:''}<span class="id" translate="no">${mdi(t.id)}</span>${mdi(t.description)}</div></div>
178
- <div class="trail">${chev}</div>
179
- </button>`;
180
- }
181
- function group(col,items,opt){
182
- opt=opt||{};
183
- const shown=opt.limit&&!opt.all?items.slice(0,opt.limit):items;
184
- const more=opt.limit&&!opt.all&&items.length>opt.limit?`<button type="button" class="more" data-more="${col}">Show All ${items.length}</button>`:'';
185
- const gh=opt.disc
186
- ?`<div class="gh"><button type="button" class="disc" data-disc="${col}" aria-expanded="${!opt.closed}" aria-label="Toggle ${esc(COLS[col])}"><svg class="ico" aria-hidden="true" focusable="false"><use href="#i-chev"/></svg></button>${esc(COLS[col])} <span class="cnt">${items.length}</span>${more}</div>`
187
- :`<div class="gh">${esc(COLS[col])} <span class="cnt">${items.length}</span>${more}</div>`;
188
- return gh+`<div class="box">${shown.length?shown.map(x=>taskRow(x,col)).join(''):'<div class="empty">No rows in this section.</div>'}</div>`;
192
+ <div class="trail">${col==='review'&&t.approved?'<span class="pill green chip">Approved</span>':''}${chev}</div>
193
+ </button><button type="button" class="dots" data-menu="${col}:${i}" aria-haspopup="menu" aria-expanded="false" aria-label="Actions for ${esc(t.id)}"><svg class="ico" aria-hidden="true" focusable="false"><use href="#i-dots"/></svg></button></div>`;
194
+ }
195
+ function group(col,items){
196
+ // BL-TB-05: the two lanes a row can be added to carry `+ Add` at the right of their header; none with --read-only
197
+ const add=TOKEN&&ADDABLE[col]?`<button type="button" class="add" data-add="${col}" aria-label="Add new task to ${esc(COLS[col])}"><svg class="ico" aria-hidden="true" focusable="false"><use href="#i-plus"/></svg>Add</button>`:'';
198
+ // BL-TB-06 (D8): Completed always carries `Archive`, which opens the dialog with the gates; none with --read-only
199
+ const arch=col==='completed'&&TOKEN&&DATA.tasks?`<button type="button" class="arch" data-archive aria-label="Archive the oldest Completed rows to planning/tasks-archive.md"><svg class="ico" aria-hidden="true" focusable="false"><use href="#i-archive"/></svg>Archive</button>`:'';
200
+ // BL-113: Review carries the HITL pill; Won't do's title is the button that folds and unfolds its strip
201
+ const title=col==='wontDo'?`<button type="button" class="fold" data-fold aria-expanded="${wontDoOpen}">${esc(COLS[col])} <span class="cnt">${items.length}</span>${chev}</button>`
202
+ :`${esc(COLS[col])}${col==='review'?` <abbr class="hitl" title="${esc(HITL)}" aria-label="${esc(HITL)}">HITL</abbr>`:''} <span class="cnt">${items.length}</span>`;
203
+ const gh=`<div class="gh">${title}${add}${arch}</div>`;
204
+ const empty=col==='review'?'Nothing waiting for you. Agents move finished work here.':'No rows in this section.';
205
+ return gh+`<div class="box"${col==='wontDo'&&!wontDoOpen?' hidden':''}>${items.length?items.map(x=>taskRow(x,col)).join(''):`<div class="empty">${empty}</div>`}</div>`;
189
206
  }
190
207
  function renderTasks(){
191
- const S=rowsOf('currentSprint'),B=rowsOf('backlog'),D=rowsOf('completed');
192
- $('#gSprint').innerHTML=group('currentSprint',S,{});
193
- $('#gBacklog').innerHTML=group('backlog',B,{limit:6,all:showAllBacklog});
194
- $('#gDone').innerHTML=group('completed',D,{disc:true,closed:$('#gDone').classList.contains('closed'),limit:8,all:showAllDone});
195
- $('#boardMode').innerHTML=[['currentSprint',S,{}],['backlog',B,{}],['completed',D,{limit:8,all:showAllDone}]].map(([c,items,o])=>`<div class="gl" data-col="${c}">${group(c,items,o)}</div>`).join('');
196
- $('#listMode').hidden=mode!=='list';$('#boardMode').hidden=mode!=='board';
208
+ closeCardMenu(false); // BL-TB-11: its card is redrawn; focusKey() carries focus back to the card
209
+ const drawn=LANES.filter(laneDrawn);
210
+ $('#boardMode').innerHTML=drawn.map(c=>`<div class="gl${c==='wontDo'&&!wontDoOpen?' fold':''}" data-col="${c}">${group(c,rowsOf(c))}</div>`).join('');
211
+ $('#boardMode').style.setProperty('--cols',drawn.map(c=>c==='wontDo'&&!wontDoOpen?'44px':'minmax(0,1fr)').join(' ')||'none'); // BL-113: one column per drawn lane, a strip for the folded Won't do
197
212
  const T=DATA.tasks;
198
213
  const bad=T?T.malformed:[];
199
214
  $('#gRaw').hidden=!bad.length;
200
215
  $('#gRaw').innerHTML=bad.length?`<div class="gh">Rows that could not be parsed <span class="cnt">${bad.length}</span></div><div class="box">${bad.map(l=>`<pre class="raw" translate="no">${esc(l)}</pre>`).join('')}</div>`:'';
201
- $('#gConv').innerHTML=T&&T.intro.trim()?`<div class="gh"><span translate="no">planning/tasks.md</span></div><div class="box"><div class="desc md">${md(T.intro)}</div></div>`:
216
+ // BL-112 (D10): one Warning per missing heading, one Note per unknown one, from the reader's report; drawn only when the markup changes
217
+ const hm=headingMessages(T);
218
+ $('#gHead').hidden=!hm;
219
+ if(hm!==lastHead){lastHead=hm;$('#gHead').innerHTML=hm;}
220
+ const wasOpen=!!($('#gIntro')&&$('#gIntro').open); // BL-TB-03: the fold keeps its state through a redraw; closed on a fresh load
221
+ $('#gConv').innerHTML=T&&T.intro.trim()?`<details id="gIntro"${wasOpen?' open':''}><summary id="introSum"><span translate="no">planning/tasks.md</span></summary><div class="box"><div class="desc md">${md(T.intro)}</div></div></details>`:
202
222
  (T?'':'<div class="box"><div class="empty">No <span class="mono" translate="no">planning/tasks.md</span> in <span class="mono" translate="no">.specs/</span>.</div></div>');
223
+ if(taskVeil.classList.contains('open'))taskHint(); // BL-TB-05: a redraw (a 409, a live reload) refreshes the dialog's next ID
224
+ if(archVeil.classList.contains('open'))drawGates(); // BL-TB-06: and the Archive dialog's gates
203
225
  bind();
204
226
  }
227
+ // ---- BL-112 (D10): the Section headings messages. Warnings collapse for the session only; a note hides per project until the unknown set changes.
228
+ let warnHidden=false,lastHead='';
229
+ const TASKS_FILE='.specs/planning/tasks.md';
230
+ const joinAnd=a=>a.length>1?a.slice(0,-1).join(', ')+' and '+a[a.length-1]:a.join('');
231
+ const notesKey=()=>'sp-notes-'+DATA.project.root;
232
+ function notesStore(){try{const v=JSON.parse(localStorage.getItem(notesKey())||'null');return v&&Array.isArray(v.set)&&Array.isArray(v.hidden)?v:null;}catch(e){return null;}}
233
+ function hiddenNotes(cur){const s=notesStore();if(!s)return[];if(JSON.stringify(s.set)===JSON.stringify(cur))return s.hidden;try{localStorage.removeItem(notesKey());}catch(e){}return[];}
234
+ function hideNote(h){const cur=DATA.tasks.headings.unknown.slice().sort();const hidden=hiddenNotes(cur);try{localStorage.setItem(notesKey(),JSON.stringify({set:cur,hidden:hidden.includes(h)?hidden:hidden.concat([h])}));}catch(e){}renderTasks();}
235
+ function headingMessages(T){
236
+ const H=T&&T.headings;if(!H)return'';
237
+ const q=h=>`"${esc(h)}"`;
238
+ const openBtn=`<a class="btn sm" href="${esc(editorUrl(DATA.project.root+'/'+TASKS_FILE))}">Open tasks.md in VS Code</a>`;
239
+ const x=(attrs,label)=>`<button type="button" class="ib x mx" ${attrs} aria-label="${label}"><svg class="ico" aria-hidden="true" focusable="false"><use href="#i-x"/></svg></button>`;
240
+ const warns=H.missing.map(h=>{
241
+ const c=H.variants[h]||[],one=c.length===1?c[0]:null,lane=h.slice(3),cols=joinAnd(H.columns[h]||['ID','Description']);
242
+ const col=LANES.find(l=>'## '+COLS[l]===h),shown=col?laneDrawn(col):true; // BL-113: a Review lane is not drawn without its heading
243
+ const prompt=one?`In ${TASKS_FILE}, rename the heading "${one}" to "${h}" so SpecPilot's Tasks board reads the section, and update anything that refers to it.`
244
+ :`In ${TASKS_FILE}, add a "${h}" section (a table with ${cols} columns) so SpecPilot's Tasks board reads it, and update anything that refers to it.`;
245
+ return `<div class="msg warn"><svg class="ico" aria-hidden="true" focusable="false"><use href="#i-warn"/></svg><div class="mb"><div class="mt"><span class="mw">Warning</span> The ${esc(lane)} lane is ${shown?'empty':'not shown'}: tasks.md has no ${q(h)} heading</div>`+
246
+ `<p>${one?`The file has ${q(one)} instead, so the rows under it are not shown.`:`The board reads ${joinAnd(REQUIRED.map(l=>q('## '+COLS[l])))}.`}</p>`+
247
+ `<p>Fix: edit <span class="mono" translate="no">${TASKS_FILE}</span> and ${one?`rename ${q(one)} to ${q(h)}`:`add a ${q(h)} section`}, best done by your AI IDE so that anything referring to the section is updated too.</p>`+
248
+ `<div class="actions">${openBtn}<button type="button" class="btn sm" data-prompt="${esc(prompt)}">Copy prompt</button></div></div>${x('data-hidewarn','Hide the warnings for now')}</div>`;
249
+ });
250
+ // BL-116: a known section whose tasks are lines or a list, not a table, which the board cannot read
251
+ const lineWarns=Object.entries(H.untabled||{}).map(([h,n])=>{
252
+ const lane=h.slice(3),cols=joinAnd(H.columns[h]||['ID','Description']);
253
+ const prompt=`In ${TASKS_FILE}, turn the "${h}" section into a markdown table with ${cols} columns, one row per task, keeping every task and its ID, so SpecPilot's Tasks board reads it.`;
254
+ return `<div class="msg warn"><svg class="ico" aria-hidden="true" focusable="false"><use href="#i-warn"/></svg><div class="mb"><div class="mt"><span class="mw">Warning</span> The ${esc(lane)} lane shows none of the ${n===1?'1 line':n+' lines'} under ${q(h)}</div>`+
255
+ `<p>They are not table rows. The board reads a markdown table with ${esc(cols)} columns.</p>`+
256
+ `<p>Fix: edit <span class="mono" translate="no">${TASKS_FILE}</span> and turn the section into a table with ${esc(cols)} columns, one row per task, best done by your AI IDE so that every task keeps its ID and references.</p>`+
257
+ `<div class="actions">${openBtn}<button type="button" class="btn sm" data-prompt="${esc(prompt)}">Copy prompt</button></div></div>${x('data-hidewarn','Hide the warnings for now')}</div>`;
258
+ });
259
+ warns.push(...lineWarns);
260
+ const candidates=new Set([].concat(...Object.values(H.variants)));
261
+ const hidden=hiddenNotes(H.unknown.slice().sort());
262
+ const notes=H.unknown.filter(h=>!candidates.has(h)&&!hidden.includes(h)).map(h=>{
263
+ const n=H.unknownRows[h]||0;
264
+ const title=n===0?`${q(h)} is not a board lane, so its rows would not be shown here (it has no rows)`:`${q(h)} is not a board lane, so its ${n===1?'1 row is':n+' rows are'} not shown here`;
265
+ return `<div class="msg info"><svg class="ico" aria-hidden="true" focusable="false"><use href="#i-info"/></svg><div class="mb"><div class="mt"><span class="mw">Note</span> ${title}</div>`+
266
+ `<p>The board shows ${joinAnd(REQUIRED.map(l=>COLS[l]))}. The rows stay in tasks.md.</p><div class="actions">${openBtn}</div></div>${x(`data-hidenote="${esc(h)}"`,'Hide this note')}</div>`;
267
+ });
268
+ const bar=warns.length&&warnHidden?`<div class="msgbar"><span>${warns.length} warning${warns.length===1?'':'s'} about tasks.md</span><button type="button" class="btn sm" data-showwarn>Show</button></div>`:'';
269
+ return (warnHidden?bar:warns.join(''))+notes.join('');
270
+ }
271
+ $('#gHead').addEventListener('click',e=>{
272
+ const t=e.target.closest('[data-prompt],[data-hidewarn],[data-showwarn],[data-hidenote]');if(!t)return;
273
+ if(t.hasAttribute('data-prompt'))copyText(t.getAttribute('data-prompt'));
274
+ else if(t.hasAttribute('data-hidewarn')){warnHidden=true;renderTasks();const s=$('#gHead [data-showwarn]');if(s)s.focus();}
275
+ else if(t.hasAttribute('data-showwarn')){warnHidden=false;renderTasks();const c=$('#gHead [data-hidewarn]');if(c)c.focus();}
276
+ else hideNote(t.getAttribute('data-hidenote'));
277
+ });
205
278
  let inspOpen=null; // {kind:'task',col,i,id} | {kind:'file',path} | null
206
279
  function openTask(col,i,quiet){
207
280
  const t=DATA.tasks[col][i];if(!t)return;
@@ -209,22 +282,99 @@ function openTask(col,i,quiet){
209
282
  selected=col+':'+i;inspOpen={kind:'task',col,i,id:t.id};
210
283
  $$('.row.sel').forEach(r=>r.classList.remove('sel'));
211
284
  $$(`#v-board .row[data-col="${col}"][data-i="${i}"]`).forEach(r=>r.classList.add('sel'));
212
- 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>
285
+ // BL-113: a Won't do row shows its Reason; a Review row its History and, with a token, the Approve and Send back footer
286
+ const reason=col==='wontDo'?`<div class="gl"><div class="gh">Reason</div><div class="box"><div class="desc md">${md(t.reason)}</div></div></div>`:'';
287
+ const hist=col==='review'&&t.history.length?`<div class="gl"><div class="gh">History <span class="cnt">${t.history.length}</span></div><div class="box">${t.history.map(h=>`<div class="hist"><span class="hd" translate="no">Sent back ${esc(h.date)}</span>${h.note?`<div class="hn">${md(h.note)}</div>`:''}</div>`).join('')}</div></div>`:'';
288
+ // D14: an approved row says what happens next and hands over the one-line prompt for the agent
289
+ const done=t.approved?`<p class="rvdone" id="rvDone">Approved ${esc(t.approved)}. Tell your agent to wrap it up: it writes the Completed entry (number, CD ID, commit) and the row leaves Review.</p><div class="fb"><button type="button" class="btn sm" id="rvCopy">Copy prompt</button></div>`:'';
290
+ 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>
291
+ <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>
292
+ <p class="err" id="rvErr" role="alert" hidden></p></div>`:'';
293
+ 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>
213
294
  <div class="ib2">
214
295
  <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>
296
+ ${reason}${hist}
215
297
  <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>
216
- </div>`;
298
+ </div>${foot}`;
299
+ if(foot)bindReview(col,i);
217
300
  openInsp(quiet);
218
301
  }
219
- function openInsp(quiet){insp.classList.add('open');insp.setAttribute('aria-hidden','false');$('#inspX').onclick=closeInsp;if(!quiet)setTimeout(()=>$('#inspX').focus(),60);}
302
+ /* ---------------- review (BL-113) ----------------
303
+ Approve appends ` Approved <date>` to the row; Send back appends ` Sent back <date>: <note>` and moves the row to the
304
+ top of Current Sprint; each toast's Undo sends the inverse action, which removes exactly that marker. One route,
305
+ POST /api/tasks/review, with the move's checks; a refusal shows in the footer with the note kept. */
306
+ let reviewing=false;
307
+ function rvError(m){const e=$('#rvErr');if(!e)return;e.textContent=m||'';e.hidden=!m;}
308
+ function rvCount(){const n=$('#rvNote'),c=$('#rvCount');if(n&&c)c.textContent=[...n.value].length+'/200';}
309
+ function openSendBack(text){
310
+ const f=$('#rvForm');if(!f)return;f.hidden=false;$('#rvSend').hidden=true;const a=$('#rvApprove');if(a)a.hidden=true;
311
+ const n=$('#rvNote');n.value=text||'';rvCount();rvError('');n.focus();
312
+ if(document.activeElement!==n)setTimeout(()=>{if(n.isConnected&&!$('#rvForm').hidden)n.focus();},70); // the panel was still sliding in: focus once it is visible, unless the box closed meanwhile
313
+ }
314
+ function closeSendBack(refocus){
315
+ const f=$('#rvForm');if(!f||f.hidden)return;f.hidden=true;$('#rvSend').hidden=false;const a=$('#rvApprove');if(a)a.hidden=false;rvError('');
316
+ if(refocus)$('#rvSend').focus();
317
+ }
318
+ /* The sentence an approved row hands to the agent (D14): what the generated Tasks mandate asks of it, with this row's ID. */
319
+ const wrapUpPrompt=id=>`${id} is approved in .specs/planning/tasks.md: write its Completed entry with the number, CD ID and commit, and remove the row from ## Review.`;
320
+ function bindReview(col,i){
321
+ const a=$('#rvApprove');if(a)a.onclick=()=>review(col,i,'approve',{});
322
+ const c=$('#rvCopy');if(c)c.onclick=()=>copyText(wrapUpPrompt(DATA.tasks[col][i].id));
323
+ $('#rvSend').onclick=()=>openSendBack('');
324
+ $('#rvCancel').onclick=()=>closeSendBack(true);
325
+ $('#rvNote').oninput=rvCount;
326
+ $('#rvNote').onkeydown=e=>{
327
+ if(e.key==='Escape'){e.preventDefault();e.stopPropagation();closeSendBack(true);}
328
+ else if(e.key==='Enter'&&(e.metaKey||e.ctrlKey)){e.preventDefault();$('#rvForm').requestSubmit();}
329
+ };
330
+ $('#rvForm').onsubmit=e=>{e.preventDefault();review(col,i,'sendBack',{note:$('#rvNote').value});};
331
+ }
332
+ /* `col`/`i` locate the row now; `extra` is the action's own fields; the undo of an action is `isUndo`. */
333
+ async function review(col,i,action,extra,isUndo){
334
+ const t=DATA.tasks[col]&&DATA.tasks[col][i],p=PROJECT;if(!t||reviewing)return;
335
+ const typed=extra.note;
336
+ reviewing=true;$$('#inspFoot button').forEach(b=>{b.disabled=true;});
337
+ let r,body={};
338
+ try{
339
+ r=await fetch('/api/tasks/review?'+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,action,...extra})});
340
+ body=await r.json().catch(()=>({}));
341
+ }catch(e){r=null;}
342
+ reviewing=false;$$('#inspFoot button').forEach(b=>{b.disabled=false;});
343
+ if(!r){if(action==='sendBack')rvError('The server did not answer. Nothing was changed.');else toast('The server did not answer. Nothing was changed.');return;}
344
+ if(p!==PROJECT)return;
345
+ if(r.status===200){
346
+ const toLane=action==='sendBack'?'currentSprint':'review';
347
+ if(action==='sendBack'||action==='unsendBack'){lastFocus=null;closeInsp();}
348
+ await apply(body.specs,['.specs/planning/tasks.md']);
349
+ const j=DATA.tasks[toLane].findIndex(x=>x.id===t.id);
350
+ if(action==='sendBack'||action==='unsendBack'){const el=$(`#v-board .row[data-col="${toLane}"][data-i="${j}"]`);if(el)el.focus();}
351
+ else{const b=$(action==='approve'?'#rvSend':'#rvApprove')||$('#inspX');if(b&&insp.classList.contains('open'))b.focus();}
352
+ if(action==='approve')toast(`${t.id} approved: marked in planning/tasks.md. Next: tell your agent to wrap it up; it writes the Completed entry.`,isUndo?null:{label:'Undo',fn:()=>{const k=DATA.tasks.review.findIndex(x=>x.id===t.id);if(k>=0)review('review',k,'unapprove',{date:body.date},true);}});
353
+ else if(action==='unapprove')toast(`${t.id} is no longer marked Approved`);
354
+ else if(action==='sendBack')toast(`Sent ${t.id} back to Current Sprint`,isUndo?null:{label:'Undo',fn:()=>{const k=DATA.tasks.currentSprint.findIndex(x=>x.id===t.id);if(k>=0)review('currentSprint',k,'unsendBack',{date:body.date,note:body.note,toIndex:body.fromIndex},true);}});
355
+ else toast(`${t.id} is back in ## Review in planning/tasks.md`);
356
+ return;
357
+ }
358
+ if(r.status===409&&body.specs)await apply(body.specs,null); // the inspector is redrawn on the same row when it is still there
359
+ const msg=body.error||`Nothing was changed (HTTP ${r.status}).`;
360
+ if(action==='sendBack'&&$('#rvForm')){openSendBack(typed);rvError(msg);}
361
+ else if($('#inspFoot'))rvError(msg);
362
+ else toast(msg);
363
+ }
364
+ 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)
220
365
  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;}}
221
366
  function bind(){
222
- $$('#v-board .row[data-col]').forEach(r=>r.onclick=()=>openTask(r.dataset.col,+r.dataset.i));
367
+ $$('#v-board .row[data-col]').forEach(r=>{const col=r.dataset.col,i=+r.dataset.i;
368
+ r.onclick=()=>openTask(col,i);
369
+ r.onkeydown=e=>{if((e.shiftKey&&e.key==='F10')||e.key==='ContextMenu'){e.preventDefault();openCardMenu(col,i,menuAnchor(col,i));}else altMove(r,e);};}); // BL-TB-11: the menu key, else Alt+arrows
370
+ $$('#v-board .card').forEach(c=>{const r=$('.row[data-col]',c),col=r.dataset.col,i=+r.dataset.i;
371
+ c.oncontextmenu=e=>{e.preventDefault();openCardMenu(col,i,e.clientX||e.clientY?{x:e.clientX,y:e.clientY}:menuAnchor(col,i));};});
372
+ $$('#v-board [data-menu]').forEach(b=>b.onclick=()=>{const [col,i]=b.dataset.menu.split(':');if(menuOn&&menuOn.col===col&&menuOn.i===+i)closeCardMenu(true);else openCardMenu(col,+i,menuAnchor(col,+i));});
373
+ $$('#v-board [data-add]').forEach(b=>b.onclick=()=>openNewTask(b.dataset.add,`#v-board [data-add="${b.dataset.add}"]`));
374
+ $$('#v-board [data-archive]').forEach(b=>b.onclick=openArchive);
375
+ $$('#v-board [data-fold]').forEach(b=>b.onclick=()=>{wontDoOpen=!wontDoOpen;renderTasks();const f=$('#v-board [data-fold]');if(f)f.focus();}); // BL-113
223
376
  if(TOKEN)bindMoves();
224
- $$('[data-more]').forEach(b=>b.onclick=e=>{e.stopPropagation();if(b.dataset.more==='completed')showAllDone=true;else showAllBacklog=true;renderTasks();});
225
- $$('[data-disc]').forEach(b=>b.onclick=e=>{e.stopPropagation();const g=$('#gDone');g.classList.toggle('closed');b.setAttribute('aria-expanded',!g.classList.contains('closed'));});
226
377
  }
227
- $$('#modeSeg button').forEach(b=>b.onclick=()=>{mode=b.dataset.m;$$('#modeSeg button').forEach(x=>x.classList.toggle('on',x===b));renderTasks();setHash('board',stateFor('board'));});
228
378
 
229
379
  /* ---------------- any .specs/ file, rendered as written ---------------- */
230
380
  function metaLine(m){return ['fileID','version','lastUpdated'].filter(k=>m&&m[k]!==undefined).map(k=>`${k}: ${m[k]}`).join(' · ');}
@@ -249,7 +399,7 @@ function renderExplorer(){
249
399
  $('#exBody').innerHTML=Object.keys(dirs).map(d=>`<div class="gl mb18"><div class="gh" translate="no">${esc(d?d+'/':'.specs/')}</div><div class="box">${dirs[d].map(p=>{
250
400
  const line=metaLine(DATA.files[p]);
251
401
  return `<button type="button" class="row act" data-file="${esc(p)}"><span class="st hollow" aria-hidden="true"></span><div class="body"><div class="ttl" translate="no">${esc(d?p.slice(d.length+1):p)}</div>${line?`<div class="det" translate="no">${esc(line)}</div>`:''}</div><div class="trail">${chev}</div></button>`;}).join('')}</div></div>`).join('');
252
- $$('#exBody .row.act').forEach(b=>b.onclick=()=>go('file',false,b.dataset.file));
402
+ $$('#exBody .row.act').forEach(b=>b.onclick=()=>go('file',b.dataset.file));
253
403
  $('#exNote').innerHTML=`${DATA.nav.specs.length} files under <span class="mono" translate="no">.specs/</span>. Every ID, version and date is that file’s own front matter.`;
254
404
  }
255
405
  /* Security: both files in security/, each rendered as written. */
@@ -363,14 +513,80 @@ ideMenu.addEventListener('keydown',e=>{
363
513
  });
364
514
  document.addEventListener('click',e=>{if(!ideMenu.hidden&&!e.target.closest('#ideWrap'))closeIde(false);});
365
515
 
516
+ /* ---------------- card menu (BL-TB-11) ----------------
517
+ A task card's actions: the lanes the move table lets it go to, reorder, details, Copy ID.
518
+ Built from DATA.tasks.moves (the server's MOVES), so a new lane is a table entry, not page code. */
519
+ const LANES=['backlog','currentSprint','review','completed','wontDo']; // the drawn order (REQ-002.H.47; Review and Won't do since BL-113)
520
+ const REQUIRED=LANES.filter(c=>c!=='wontDo'); // the headings the board asks for (BL-112's sentences); Won't do is read when present
521
+ const moves=()=>(DATA&&DATA.tasks&&DATA.tasks.moves)||{};
522
+ /* An own key, never `in`: an inherited name (__proto__, toString) is not a lane. A lane in the table may reorder itself. */
523
+ const canMove=(from,to)=>{const m=moves();return Array.isArray(m[from])&&(from===to||m[from].includes(to));};
524
+ /* The nearest lane on that side (dir -1 or 1) of `col` in the drawn order that the table allows, or null. */
525
+ function laneBy(col,dir){for(let k=LANES.indexOf(col)+dir;k>=0&&k<LANES.length;k+=dir)if(canMove(col,LANES[k]))return LANES[k];return null;}
526
+ const cardMenu=$('#cardMenu');let menuOn=null; // {col,i} while open
527
+ const cardRow=(col,i)=>$(`#v-board .row[data-col="${col}"][data-i="${i}"]`);
528
+ const dotsBtn=(col,i)=>$(`#v-board .card [data-menu="${col}:${i}"]`);
529
+ const KEYS={'Alt+→':'Alt+ArrowRight','Alt+←':'Alt+ArrowLeft','Alt+↑':'Alt+ArrowUp','Alt+↓':'Alt+ArrowDown'};
530
+ function menuItems(col,i){
531
+ const t=DATA.tasks[col][i],n=DATA.tasks[col].length,it=[];
532
+ if(TOKEN&&col==='review'){ // BL-113: the reviewed exits first
533
+ if(!t.approved)it.push({label:'Approve',fn:()=>{openTask(col,i);review(col,i,'approve',{});}});
534
+ it.push({label:'Send back…',fn:()=>{openTask(col,i);openSendBack('');}});
535
+ }
536
+ if(TOKEN&&canMove(col,col)){
537
+ const right=laneBy(col,1),left=laneBy(col,-1),to=col==='review'?[]:moves()[col].filter(c=>COLS[c]&&DATA.tasks[c]); // D16: a Review card leaves only by Send back
538
+ if(to.length)it.push({head:'Move to'});
539
+ to.forEach(c=>{it.push({label:COLS[c],hint:c===right?'Alt+→':c===left?'Alt+←':'',fn:()=>move(col,i,c,DATA.tasks[c].length)});it.push({label:COLS[c]+', top',fn:()=>move(col,i,c,0)});});
540
+ if(i>0)it.push({label:'Move up',hint:'Alt+↑',fn:()=>move(col,i,col,i-1)});
541
+ if(i<n-1)it.push({label:'Move down',hint:'Alt+↓',fn:()=>move(col,i,col,i+1)});
542
+ }
543
+ it.push({label:'Open details',fn:()=>openTask(col,i)});
544
+ it.push({label:'Copy ID',fn:()=>copyText(t.id)});
545
+ return it;
546
+ }
547
+ /* Under the card's ⋯ button, its right edges aligned. */
548
+ function menuAnchor(col,i){const r=(dotsBtn(col,i)||cardRow(col,i)).getBoundingClientRect();return {x:r.right,y:r.bottom+4,right:true};}
549
+ function openCardMenu(col,i,at){
550
+ if(!DATA||!DATA.tasks||!DATA.tasks[col]||!DATA.tasks[col][i])return;
551
+ closeCardMenu(false);hideTip();
552
+ const items=menuItems(col,i),acts=items.filter(x=>!x.head);
553
+ cardMenu.innerHTML=items.map(x=>x.head?`<div class="mh" role="presentation">${esc(x.head)}</div>`
554
+ :`<button type="button" role="menuitem"${x.hint?` aria-keyshortcuts="${KEYS[x.hint]}"`:''}>${esc(x.label)}${x.hint?`<span class="hint">${esc(x.hint)}</span>`:''}</button>`).join('');
555
+ $$('[role=menuitem]',cardMenu).forEach((b,k)=>b.onclick=()=>{closeCardMenu(true);acts[k].fn();});
556
+ menuOn={col,i};
557
+ const btn=dotsBtn(col,i);if(btn)btn.setAttribute('aria-expanded','true');
558
+ cardMenu.hidden=false;
559
+ const w=cardMenu.offsetWidth,h=cardMenu.offsetHeight,m=8;
560
+ cardMenu.style.left=Math.max(m,Math.min(at.right?at.x-w:at.x,innerWidth-w-m))+'px';
561
+ cardMenu.style.top=Math.max(m,Math.min(at.y,innerHeight-h-m))+'px';
562
+ $('[role=menuitem]',cardMenu).focus();
563
+ }
564
+ /* Close; `refocus` puts focus back on the card. A redraw closes it too (renderTasks), the card refocused through focusKey(). */
565
+ function closeCardMenu(refocus){
566
+ if(cardMenu.hidden)return;
567
+ const was=menuOn;menuOn=null;cardMenu.hidden=true;
568
+ if(cardMenu.contains(document.activeElement))document.activeElement.blur(); // now, not at the next frame: a redraw's refocus() checks for a focus-less page
569
+ const btn=was&&dotsBtn(was.col,was.i);if(btn)btn.setAttribute('aria-expanded','false');
570
+ if(refocus&&was){const r=cardRow(was.col,was.i);if(r)r.focus();}
571
+ }
572
+ cardMenu.addEventListener('keydown',e=>{
573
+ const it=$$('[role=menuitem]',cardMenu),i=it.indexOf(document.activeElement);
574
+ if(e.key==='ArrowDown'||e.key==='ArrowUp'){e.preventDefault();it[(i+(e.key==='ArrowDown'?1:it.length-1))%it.length].focus();}
575
+ else if(e.key==='Home'||e.key==='End'){e.preventDefault();it[e.key==='Home'?0:it.length-1].focus();}
576
+ else if(e.key==='Escape'){e.preventDefault();e.stopPropagation();closeCardMenu(true);}
577
+ });
578
+ cardMenu.addEventListener('mousedown',e=>e.preventDefault()); // a press inside keeps focus in the menu: Safari and Firefox do not focus a pressed button, and a blur would close it before the click
579
+ cardMenu.addEventListener('focusout',e=>{if(!cardMenu.contains(e.relatedTarget))closeCardMenu(false);});
580
+ document.addEventListener('click',e=>{if(!cardMenu.hidden&&!(e.target.closest&&e.target.closest('#cardMenu,[data-menu]')))closeCardMenu(false);});
581
+
366
582
  /* ---------------- palette + keys ---------------- */
367
583
  const palVeil=$('#palVeil'),palIn=$('#palIn'),palList=$('#palList');
368
584
  function items(q){q=q.toLowerCase();
369
585
  const T=DATA?DATA.tasks:null;
370
586
  const it=[
371
- ...NAV.map(n=>n[0]==='file'?{l:'.specs/'+n[1],k:'file',go:()=>go('file',false,n[1])}:{l:VIEWS[n[0]],k:'view',go:()=>go(n[0])}),
372
- ...(DATA?DATA.nav.specs:[]).filter(p=>!NAV.some(n=>n[1]===p)).map(p=>({l:'.specs/'+p,k:'file',go:()=>go('file',false,p)})),
373
- ...(T?['currentSprint','backlog','completed'].flatMap(c=>T[c].map((t,i)=>({l:t.id+' '+t.description,k:'task',go:()=>{go('board');openTask(c,i)}}))):[])
587
+ ...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])}),
588
+ ...(DATA?DATA.nav.specs:[]).filter(p=>!NAV.some(n=>n[1]===p)).map(p=>({l:'.specs/'+p,k:'file',go:()=>go('file',p)})),
589
+ ...(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)}}))):[])
374
590
  ];
375
591
  return it.filter(i=>!q||i.l.toLowerCase().includes(q)).slice(0,9);}
376
592
  function renderPal(){const it=items(palIn.value);palList.innerHTML=it.map((i,n)=>`<li class="${n===0?'on':''}" role="option" aria-selected="${n===0}" tabindex="0"><span class="lbl">${esc(i.l)}</span><span class="k">${esc(i.k)}</span></li>`).join('')||'<li class="empty">No matches</li>';$$('#palList li').forEach((li,n)=>{li.onclick=()=>{it[n]&&it[n].go();closePal();};li.onkeydown=e=>{if(e.key==='Enter'||e.key===' '){e.preventDefault();li.click()}}});}
@@ -381,46 +597,55 @@ palIn.onkeydown=e=>{if(e.key==='Enter'){const it=items(palIn.value);it[0]&&it[0]
381
597
  document.addEventListener('keydown',e=>{
382
598
  const mod=e.metaKey||e.ctrlKey;const inField=/INPUT|SELECT|TEXTAREA/.test(e.target.tagName);
383
599
  if(mod&&e.key.toLowerCase()==='k'){e.preventDefault();palVeil.classList.contains('open')?closePal():openPal();return}
384
- if(mod&&/^[1-9]$/.test(e.key)){e.preventDefault();const n=NAV[+e.key-1];if(n)go(n[0],false,n[1]);return}
385
- if(e.key==='Escape'){if(!ideMenu.hidden){closeIde(true);return}hideTip();closeInsp();closePal();closeSheet();closeNewTask();setNav(false);return}
386
- if(inField||mod||e.altKey||taskVeil.classList.contains('open'))return;
600
+ if(mod&&/^[1-9]$/.test(e.key)){e.preventDefault();const n=NAV[+e.key-1];if(n)go(n[0],n[1]);return}
601
+ if(e.key==='Escape'){if(!ideMenu.hidden){closeIde(true);return}if(!cardMenu.hidden){closeCardMenu(true);return}hideTip();closeInsp();closePal();closeSheet();closeNewTask();closeArchive();setNav(false);return}
602
+ if(inField||mod||e.altKey||!cardMenu.hidden||taskVeil.classList.contains('open')||archVeil.classList.contains('open'))return;
387
603
  if(e.key==='h'&&TOKEN&&!openVeil.classList.contains('open')){go('home');return;}
388
- if(/^[1-9]$/.test(e.key)){const n=NAV[+e.key-1];if(n)go(n[0],false,n[1]);}
389
- 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();}
604
+ if(/^[1-9]$/.test(e.key)){const n=NAV[+e.key-1];if(n)go(n[0],n[1]);}
605
+ 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();}
390
606
  });
391
607
 
392
608
  /* ---------------- task moves (BL-053) ----------------
393
609
  A move is one line of planning/tasks.md cut and pasted unchanged; the server does it and
394
610
  answers with the new file hash and the fresh payload. Completed rows never move. */
395
- let dragging=null,moving=false;
611
+ let dragging=null,moving=false,hinted=false; // hinted: the Completed toast once per drag (D15)
612
+ /* D15: why a card cannot go to Completed from the page, said once per gesture instead of a silent refusal. */
613
+ const COMPLETED_HINT='Nothing moves to Completed from here. Approve the card in Review, then tell your agent to wrap it up: it writes the Completed entry.';
396
614
  function bindMoves(){
397
615
  $$('#v-board .row[draggable="true"]').forEach(r=>{
398
- r.ondragstart=e=>{dragging={col:r.dataset.col,i:+r.dataset.i};e.dataTransfer.setData('text/plain',DATA.tasks[dragging.col][dragging.i].id);e.dataTransfer.effectAllowed='move';r.classList.add('drag');};
616
+ r.ondragstart=e=>{dragging={col:r.dataset.col,i:+r.dataset.i};e.dataTransfer.setData('text/plain',DATA.tasks[dragging.col][dragging.i].id);e.dataTransfer.effectAllowed='move';r.classList.add('drag');hinted=false;};
399
617
  r.ondragend=()=>{r.classList.remove('drag');dragging=null;$$('.gl.drop').forEach(g=>g.classList.remove('drop'));};
400
- r.onkeydown=e=>{
401
- if(!e.altKey||e.metaKey||e.ctrlKey)return;
402
- const col=r.dataset.col,i=+r.dataset.i,n=DATA.tasks[col].length;
403
- const go2={ArrowUp:i>0&&[col,i-1],ArrowDown:i<n-1&&[col,i+1],ArrowRight:col==='backlog'&&['currentSprint',DATA.tasks.currentSprint.length],ArrowLeft:col==='currentSprint'&&['backlog',DATA.tasks.backlog.length]}[e.key];
404
- if(go2===undefined)return;
405
- e.preventDefault();
406
- if(go2)move(col,i,go2[0],go2[1]);
407
- };
408
618
  });
409
- $$('#v-board .gl[data-col="backlog"],#v-board .gl[data-col="currentSprint"]').forEach(g=>{
410
- g.ondragover=e=>{if(!dragging)return;e.preventDefault();e.dataTransfer.dropEffect='move';g.classList.add('drop');};
619
+ // Drop targets (BL-TB-11): every lane; a drop lands only where the move table lets the dragged row go.
620
+ $$('#v-board .gl[data-col]').forEach(g=>{
621
+ g.ondragenter=()=>{if(dragging&&g.dataset.col==='completed'&&!canMove(dragging.col,'completed')&&!hinted){hinted=true;toast(COMPLETED_HINT);}}; // D15
622
+ g.ondragover=e=>{if(!dragging||!canMove(dragging.col,g.dataset.col))return;e.preventDefault();e.dataTransfer.dropEffect='move';g.classList.add('drop');};
411
623
  g.ondragleave=e=>{if(!g.contains(e.relatedTarget))g.classList.remove('drop');};
412
624
  g.ondrop=e=>{
413
- if(!dragging)return;e.preventDefault();g.classList.remove('drop');
625
+ if(!dragging||!canMove(dragging.col,g.dataset.col))return;e.preventDefault();g.classList.remove('drop');
414
626
  const to=g.dataset.col,src=dragging;dragging=null;
415
627
  // Position among the target's rows once the dragged row is out of the way.
416
628
  const others=DATA.tasks[to].map((_,j)=>j).filter(j=>!(to===src.col&&j===src.i));
417
- const over=e.target.closest&&e.target.closest('.row[data-col]');
629
+ const card=e.target.closest&&e.target.closest('.card'),over=card&&card.querySelector('.row[data-col]');
418
630
  let at=others.length;
419
631
  if(over&&over.dataset.col===to){const j=+over.dataset.i,k=others.indexOf(j);if(k>=0){const b=over.getBoundingClientRect();at=k+(e.clientY>b.top+b.height/2?1:0);}}
420
- move(src.col,src.i,to,at);
632
+ if(src.col==='review'&&to!==src.col)review(src.col,src.i,'sendBack',{note:''}); // D16: out of Review only by Send back, so the Approved state ends with a marker
633
+ else move(src.col,src.i,to,at);
421
634
  };
422
635
  });
423
636
  }
637
+ /* Alt+arrows (BL-053): up/down reorder; left/right go to the end of the nearest lane on that side that the table allows (BL-TB-11). */
638
+ function altMove(r,e){
639
+ if(!e.altKey||e.metaKey||e.ctrlKey||!r.draggable)return;
640
+ const col=r.dataset.col,i=+r.dataset.i,n=DATA.tasks[col].length;
641
+ const lane=e.key==='ArrowRight'?laneBy(col,1):e.key==='ArrowLeft'?laneBy(col,-1):null;
642
+ const go2={ArrowUp:i>0&&[col,i-1],ArrowDown:i<n-1&&[col,i+1],ArrowRight:!!lane&&[lane,DATA.tasks[lane].length],ArrowLeft:!!lane&&[lane,DATA.tasks[lane].length]}[e.key];
643
+ if(go2===undefined)return;
644
+ e.preventDefault();
645
+ if(go2&&col==='review'&&go2[0]!==col)review(col,i,'sendBack',{note:''}); // D16
646
+ else if(go2)move(col,i,go2[0],go2[1]);
647
+ else if(e.key==='ArrowRight'&&LANES[LANES.indexOf(col)+1]==='completed')toast(COMPLETED_HINT); // D15: Alt+→ from the lane before Completed
648
+ }
424
649
  async function move(col,i,toSection,toIndex,isUndo){
425
650
  const t=DATA.tasks[col][i],p=PROJECT;if(!t||moving)return;
426
651
  moving=true;
@@ -432,10 +657,9 @@ async function move(col,i,toSection,toIndex,isUndo){
432
657
  moving=false;
433
658
  if(p!==PROJECT)return; // the page switched projects while the move was in flight
434
659
  if(r.status===200){
435
- if(toSection==='backlog'&&toIndex>=6)showAllBacklog=true;
436
660
  await apply(body.specs,['.specs/planning/tasks.md']);
437
661
  const j=DATA.tasks[toSection].findIndex(x=>x.id===t.id);
438
- const el=$(`${mode==='board'?'#boardMode':'#listMode'} .row[data-col="${toSection}"][data-i="${j}"]`);if(el)el.focus();
662
+ const el=$(`#v-board .row[data-col="${toSection}"][data-i="${j}"]`);if(el)el.focus();
439
663
  const msg=col===toSection?`${t.id} moved within ## ${COLS[col]} in planning/tasks.md`:`${t.id} moved from ## ${COLS[col]} to ## ${COLS[toSection]} in planning/tasks.md`;
440
664
  toast(msg,isUndo?null:{label:'Undo',fn:()=>{const k=DATA.tasks[toSection].findIndex(x=>x.id===t.id);if(k>=0)move(toSection,k,body.from,body.fromIndex,true);}});
441
665
  }else if(r.status===409){
@@ -448,11 +672,13 @@ async function move(col,i,toSection,toIndex,isUndo){
448
672
  The server appends one row, `| <ID> | <description> |`, to the chosen section and picks the ID.
449
673
  The description goes as typed; a refusal is shown in the form with what was typed kept. */
450
674
  const taskVeil=$('#taskVeil'),taskIn=$('#taskIn');
451
- let taskSection='backlog',adding=false;
452
- 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);});}
675
+ let taskSection='backlog',adding=false,taskFrom=null; // taskFrom: the opener, as a selector, since a lane button is redrawn (BL-TB-05)
453
676
  function taskError(m){const e=$('#taskErr');e.textContent=m||'';e.hidden=!m;}
454
- function openNewTask(){if(!TOKEN||!DATA||!DATA.tasks)return;hideTip();taskIn.value='';taskError('');setTaskSection('backlog');taskVeil.classList.add('open');setTimeout(()=>taskIn.focus(),50);}
455
- function closeNewTask(){if(!taskVeil.classList.contains('open')||adding)return;taskVeil.classList.remove('open');$('#newTask').focus();}
677
+ /* The ID the server would give now, from the last payload; a suggestion, the write picks the ID (BL-TB-05). */
678
+ function taskHint(){const n=DATA&&DATA.tasks&&DATA.tasks.nextIds;$('#taskNext').textContent=n?n[taskSection]:'';$('#taskNextWrap').hidden=!n;}
679
+ function openNewTask(section,from){if(!TOKEN||!DATA||!DATA.tasks||!ADDABLE[section])return;hideTip();taskIn.value='';taskError('');taskSection=section;taskFrom=from;$('#taskLane').textContent=COLS[section];taskHint();taskVeil.classList.add('open');setTimeout(()=>taskIn.focus(),50);}
680
+ function focusOpener(){const b=(taskFrom&&$(taskFrom))||$('#v-board [data-add]');if(b)b.focus();}
681
+ function closeNewTask(){if(!taskVeil.classList.contains('open')||adding)return;taskVeil.classList.remove('open');focusOpener();}
456
682
  async function addTask(){
457
683
  if(adding)return;
458
684
  if(!taskIn.value.trim()){taskError('Type a description for the task.');taskIn.focus();return;}
@@ -467,24 +693,81 @@ async function addTask(){
467
693
  if(!r){taskError('The server did not answer. Nothing was added.');return;}
468
694
  if(p!==PROJECT)return;
469
695
  if(r.status===200){
470
- if(section==='backlog'&&body.index>=6)showAllBacklog=true;
471
696
  taskVeil.classList.remove('open');
472
697
  await apply(body.specs,['.specs/planning/tasks.md']);
473
- $('#newTask').focus(); // what closing the inspector returns to
698
+ focusOpener(); // what closing the inspector returns to
474
699
  openTask(section,body.index);
475
- const el=$(`${mode==='board'?'#boardMode':'#listMode'} .row[data-col="${section}"][data-i="${body.index}"]`);if(el)el.scrollIntoView({block:'nearest'});
700
+ const el=$(`#v-board .row[data-col="${section}"][data-i="${body.index}"]`);if(el)el.scrollIntoView({block:'nearest'});
476
701
  toast(`${body.id} added to ## ${COLS[section]} in planning/tasks.md`);
477
702
  return;
478
703
  }
479
704
  if(r.status===409&&body.specs)await apply(body.specs,null);
480
705
  taskError(body.error||`The task was not added (HTTP ${r.status}).`);taskIn.focus();
481
706
  }
482
- $('#newTask').onclick=openNewTask;
483
- $$('#taskSec button').forEach(b=>b.onclick=()=>setTaskSection(b.dataset.s));
707
+ taskIn.onkeydown=e=>{if(e.key==='Enter'){e.preventDefault();addTask();}}; // a row cannot hold a line break: Enter adds, never breaks the line
484
708
  $('#taskCancel').onclick=closeNewTask;
485
709
  taskVeil.onclick=e=>{if(e.target===taskVeil)closeNewTask();};
486
710
  $('#taskForm').onsubmit=e=>{e.preventDefault();addTask();};
487
711
 
712
+ /* ---------------- archive Completed (BL-TB-06, D8) ----------------
713
+ The Completed step of `specpilot archive`, run by the server with the same plan and block as the CLI. The
714
+ dialog says what the action does and lists the gates from the latest payload: the CLI's branch guard and the
715
+ 40-line limit, each with a box to tick when it warns; a section within the limit is archived with {force:true}
716
+ once the user ticks that box. Every other answer than 200 is shown in the dialog, as New Task does. */
717
+ const archVeil=$('#archVeil');
718
+ let archiving=false;
719
+ function archGates(){
720
+ const b=DATA.project.branch,a=DATA.tasks.archive,n=DATA.tasks.completed.length,out=[];
721
+ if(!b)out.push({key:'branch',text:'No git branch.'});
722
+ else if(b==='main'||b==='master')out.push({key:'branch',text:`On ${b}.`});
723
+ else out.push({key:'branch:'+b,warn:true,text:`On branch ${b}. Archive is recommended only on the default branch after merging. Archive on this branch anyway.`});
724
+ 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.`});
725
+ 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.`});
726
+ 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.`});
727
+ return out;
728
+ }
729
+ /* Draw the gates from the latest payload; a tick stays on a gate still shown under the same key (a redraw while open). */
730
+ function drawGates(){
731
+ const kept=new Set($$('#archGates input:checked').map(i=>i.dataset.gate));
732
+ $('#archGates').innerHTML=archGates().map(g=>`<div class="gate ${g.off?'off':g.warn?'warn':'ok'}"><span class="st ${g.off?'gray':g.warn?'orange':'green'}" aria-hidden="true"></span>${g.warn?`<label><input type="checkbox" data-gate="${esc(g.key)}"${kept.has(g.key)?' checked':''}><span>${esc(g.text)}</span></label>`:`<span class="gt">${esc(g.text)}</span>`}</div>`).join('');
733
+ $$('#archGates input').forEach(i=>i.onchange=archReady);
734
+ archReady();
735
+ }
736
+ function archReady(){$('#archGo').disabled=archiving||!DATA.tasks.archive.rows||$$('#archGates input').some(i=>!i.checked);}
737
+ function archError(m){const e=$('#archErr');e.textContent=m||'';e.hidden=!m;}
738
+ function focusArchive(){const b=$('#v-board [data-archive]');if(b)b.focus();}
739
+ function openArchive(){
740
+ if(!TOKEN||!DATA||!DATA.tasks)return;
741
+ hideTip();archError('');$('#archGates').innerHTML='';archVeil.classList.add('open');drawGates(); // every box starts unticked
742
+ setTimeout(()=>{const f=$('#archGates input')||(!$('#archGo').disabled?$('#archGo'):$('#archCancel'));f.focus();},50);
743
+ }
744
+ function closeArchive(){if(!archVeil.classList.contains('open')||archiving)return;archVeil.classList.remove('open');focusArchive();}
745
+ async function archiveCompleted(){
746
+ if(archiving||!TOKEN||!DATA||!DATA.tasks||$('#archGo').disabled)return;
747
+ const p=PROJECT,force=!!$('#archGates input[data-gate="force"]'); // present only when the limit gate warns, and ticked, or the button is disabled
748
+ archiving=true;$('#archGo').disabled=true;archError('');
749
+ let r,body={};
750
+ try{
751
+ r=await fetch('/api/tasks/archive?'+pq(),{method:'POST',cache:'no-store',headers:{'Content-Type':'application/json','X-SpecPilot-Token':TOKEN,'If-Match':DATA.tasks.sha256},body:force?'{"force":true}':'{}'});
752
+ body=await r.json().catch(()=>({}));
753
+ }catch(e){r=null;}
754
+ archiving=false;archReady();
755
+ if(!r){archError('The server did not answer. Nothing was archived.');return;}
756
+ if(p!==PROJECT)return;
757
+ if(r.status===200){
758
+ archVeil.classList.remove('open');
759
+ await apply(body.specs,['.specs/planning/tasks.md','.specs/planning/tasks-archive.md']);
760
+ focusArchive();
761
+ toast(`Moved ${body.linesMoved} rows from ## Completed to planning/tasks-archive.md`);
762
+ return;
763
+ }
764
+ if(r.status===409&&body.specs)await apply(body.specs,null); // renderTasks() redraws the gates while the dialog is open
765
+ archError(body.error||`Nothing was archived (HTTP ${r.status}).`);
766
+ }
767
+ $('#archCancel').onclick=closeArchive;
768
+ archVeil.onclick=e=>{if(e.target===archVeil)closeArchive();};
769
+ $('#archForm').onsubmit=e=>{e.preventDefault();archiveCompleted();};
770
+
488
771
  /* ---------------- Setup view (BL-103) ----------------
489
772
  A project without .specs/ (Open, Clone, a folder named on the command line) and #new: the user's AI IDE
490
773
  sets it up over /mcp, and this view says how. It sends no answers and writes no spec; the only request
@@ -541,7 +824,7 @@ function renderSetup(){
541
824
  [...v.children].forEach(el=>{if(el.id!=='suNote')el.hidden=off;});
542
825
  $('#suNote').hidden=TOKEN||!named;$('#suNote').textContent='Started with --read-only, so nothing can be set up here.';
543
826
  if(off){$('#crumb').hidden=!named;if(named)$('#crumb').textContent=p.root+' · no specs yet';return;}
544
- const name=String(p.root).split(/[/\\]/).filter(Boolean).pop()||p.root,url=clonedFrom[p.root];
827
+ const name=p?String(p.root).split(/[/\\]/).filter(Boolean).pop()||p.root:'',url=p?clonedFrom[p.root]:null; // #new has no project behind it when none is served (BL-080)
545
828
  const tail=' Your AI IDE sets them up: it reads the code, answers what it can, and asks you the rest.';
546
829
  $('#suLead').innerHTML=isNew?'Name the project and choose where it goes. Your AI IDE creates it and writes the specs from your answers.'
547
830
  :url?`Cloned ${mono(url)}. It has no SpecPilot specs yet.${tail}`:`${mono(name)} has no SpecPilot specs yet.${tail}`;
@@ -592,8 +875,9 @@ $('#suBrowse').onclick=()=>browseFolder($('#suBrowse'),()=>curView==='new'?$('#s
592
875
  function focusKey(el){
593
876
  if(!el||el===document.body)return null;
594
877
  const row=el.closest&&el.closest('.row[data-col][data-i]');
595
- if(row){const t=DATA.tasks&&DATA.tasks[row.dataset.col][+row.dataset.i];return {row:row.dataset.col,id:t?t.id:null,i:+row.dataset.i,board:!!row.closest('#boardMode')};}
596
- for(const a of ['data-open','data-file','data-more','data-disc'])if(el.hasAttribute&&el.hasAttribute(a))return {sel:`[${a}="${CSS.escape(el.getAttribute(a))}"]`};
878
+ if(menuOn&&cardMenu.contains(el)){const t=DATA.tasks&&DATA.tasks[menuOn.col][menuOn.i];return {row:menuOn.col,id:t?t.id:null,i:menuOn.i};} // BL-TB-11: the open menu's card
879
+ if(row){const t=DATA.tasks&&DATA.tasks[row.dataset.col][+row.dataset.i];return {row:row.dataset.col,id:t?t.id:null,i:+row.dataset.i};}
880
+ for(const a of ['data-open','data-file','data-add','data-archive','data-menu'])if(el.hasAttribute&&el.hasAttribute(a))return {sel:`[${a}="${CSS.escape(el.getAttribute(a))}"]`};
597
881
  if(el.id)return {sel:'#'+CSS.escape(el.id)};
598
882
  return null;
599
883
  }
@@ -606,7 +890,7 @@ function findRow(col,id,oldI){
606
890
  function refocus(key){
607
891
  if(!key||document.activeElement&&document.activeElement!==document.body)return;
608
892
  let el=null;
609
- if(key.row){const i=findRow(key.row,key.id,key.i);if(i>=0)el=$(`${key.board?'#boardMode':'#listMode'} .row[data-col="${key.row}"][data-i="${i}"]`);}
893
+ if(key.row){const i=findRow(key.row,key.id,key.i);if(i>=0)el=$(`#v-board .row[data-col="${key.row}"][data-i="${i}"]`);}
610
894
  else el=$(key.sel);
611
895
  if(el)el.focus({preventScroll:true});
612
896
  }
@@ -625,11 +909,12 @@ async function apply(d,paths){
625
909
  (paths||Object.keys(fileCache)).forEach(p=>{delete fileCache[p];});
626
910
  const key=focusKey(document.activeElement);
627
911
  const scroll=$('#content').scrollTop,ib0=insp.querySelector('.ib2'),inspScroll=ib0?ib0.scrollTop:0;
912
+ const lanes=$$('#boardMode .gl[data-col] .box').map(b=>[b.closest('.gl').dataset.col,b.scrollTop]); // BL-TB-03: each lane's own scroll
628
913
  const was=inspOpen;
629
- const hadSpecs=!(DATA&&DATA.project.specs===false);
914
+ const hadSpecs=!(DATA&&DATA.project&&DATA.project.specs===false);
630
915
  DATA=d;
631
- renderProject();renderTasks();renderIde();renderAgentFiles();
632
- const to=reloadView(curView,hadSpecs,d.project.specs!==false); // .specs/ gone: offer setup; appeared another way: Tasks; Home stays
916
+ renderAll();
917
+ const to=reloadView(curView,hadSpecs,!d.project||d.project.specs!==false); // .specs/ gone: offer setup; appeared another way: Tasks; Home stays
633
918
  if(to){go(to);return;}
634
919
  if(curView==='file')await renderFile(curFile);
635
920
  if(curView==='explorer')renderExplorer();
@@ -641,6 +926,7 @@ async function apply(d,paths){
641
926
  }
642
927
  if(was&&was.kind==='file'&&(!paths||paths.includes(was.path)))await openFile(was.path,true);
643
928
  $('#content').scrollTop=scroll;
929
+ lanes.forEach(([c,top])=>{const b=$(`#boardMode .gl[data-col="${c}"] .box`);if(b)b.scrollTop=top;});
644
930
  const ib=insp.querySelector('.ib2');if(ib)ib.scrollTop=inspScroll;
645
931
  refocus(key);
646
932
  }
@@ -648,7 +934,7 @@ let es=null;
648
934
  function listen(){
649
935
  if(stopped||!window.EventSource)return;
650
936
  if(es)es.close(); // one stream, for the shown project
651
- es=new EventSource('/api/events?'+pq());let dropped=false;
937
+ es=new EventSource(DATA&&!DATA.project?'/api/events':'/api/events?'+pq());let dropped=false; // no project served: the server-level stream (BL-080)
652
938
  es.addEventListener('clone',e=>onCloneEvent(e.data));
653
939
  es.addEventListener('setup',e=>onSetupEvent(e.data));
654
940
  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();}});
@@ -670,7 +956,7 @@ async function switchProject(n,keepRoute){
670
956
  function showProject(d,keepRoute){
671
957
  Object.keys(fileCache).forEach(k=>{delete fileCache[k];});secShown.clear();
672
958
  DATA=d;selected=null;setRegenNote([]);
673
- renderProject();renderTasks();renderIde();renderAgentFiles();listen();
959
+ renderAll();listen();
674
960
  if(keepRoute)route();else go('board');
675
961
  }
676
962
  $('#projList').addEventListener('click',e=>{const b=e.target.closest('[data-project]');if(!b)return;
@@ -848,11 +1134,11 @@ $('#recentBox').addEventListener('keydown',e=>{const row=e.target.closest&&e.tar
848
1134
 
849
1135
  /* boot: the project count is unknown until the first load, so an index past the end falls back to project 0 */
850
1136
  insp.setAttribute('aria-hidden','true');
851
- $('#gDone').classList.add('closed');
852
1137
  PROJECT=resolveRoute(curHash(),{},Infinity).project;
853
- fetch('/api/specs?'+pq(),{cache:'no-store'})
854
- .then(r=>{if(!r.ok&&PROJECT){PROJECT=0;return fetch('/api/specs?'+pq(),{cache:'no-store'});}return r;})
1138
+ const bootQ=()=>PROJECT?'?'+pq():''; // project 0 is asked for without the parameter: with nothing served the server answers the no-project state (BL-080)
1139
+ fetch('/api/specs'+bootQ(),{cache:'no-store'})
1140
+ .then(r=>{if(!r.ok&&PROJECT){PROJECT=0;return fetch('/api/specs'+bootQ(),{cache:'no-store'});}return r;})
855
1141
  .then(r=>{if(!r.ok)throw new Error('/api/specs: HTTP '+r.status);return r.json();})
856
- .then(d=>{DATA=d;renderProject();renderTasks();renderIde();renderAgentFiles();route();listen();})
1142
+ .then(d=>{DATA=d;renderAll();route();listen();})
857
1143
  .catch(e=>showErr('Could not load the project: '+e.message));
858
1144
  })();