specpilot 2.15.0 → 2.17.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 (38) hide show
  1. package/README.md +8 -7
  2. package/dist/cli.js +0 -1
  3. package/dist/cli.js.map +1 -1
  4. package/dist/commands/add-specs.d.ts +1 -2
  5. package/dist/commands/add-specs.d.ts.map +1 -1
  6. package/dist/commands/add-specs.js +1 -1
  7. package/dist/commands/add-specs.js.map +1 -1
  8. package/dist/commands/init.d.ts.map +1 -1
  9. package/dist/commands/init.js +27 -33
  10. package/dist/commands/init.js.map +1 -1
  11. package/dist/commands/serve.d.ts +4 -2
  12. package/dist/commands/serve.d.ts.map +1 -1
  13. package/dist/commands/serve.js +71 -19
  14. package/dist/commands/serve.js.map +1 -1
  15. package/dist/core/slashCommands.d.ts.map +1 -1
  16. package/dist/core/slashCommands.js +0 -1
  17. package/dist/core/slashCommands.js.map +1 -1
  18. package/dist/utils/slashCommandGenerator.d.ts.map +1 -1
  19. package/dist/utils/slashCommandGenerator.js +6 -0
  20. package/dist/utils/slashCommandGenerator.js.map +1 -1
  21. package/dist/utils/specArchiver.d.ts +9 -2
  22. package/dist/utils/specArchiver.d.ts.map +1 -1
  23. package/dist/utils/specArchiver.js +21 -13
  24. package/dist/utils/specArchiver.js.map +1 -1
  25. package/dist/utils/specServer.d.ts +7 -1
  26. package/dist/utils/specServer.d.ts.map +1 -1
  27. package/dist/utils/specServer.js +73 -14
  28. package/dist/utils/specServer.js.map +1 -1
  29. package/dist/utils/specValidator.js +1 -1
  30. package/dist/utils/taskMover.d.ts +43 -4
  31. package/dist/utils/taskMover.d.ts.map +1 -1
  32. package/dist/utils/taskMover.js +116 -24
  33. package/dist/utils/taskMover.js.map +1 -1
  34. package/package.json +1 -1
  35. package/ui/app.css +35 -5
  36. package/ui/app.js +212 -79
  37. package/ui/index.html +17 -11
  38. package/ui/route.js +3 -1
package/ui/app.js CHANGED
@@ -12,7 +12,7 @@ const toast=(m,action)=>{
12
12
  const TOKEN=(document.querySelector('meta[name="specpilot-token"]')||{}).content||null;
13
13
  /* /mcp is on (BL-PM-007), and whose token it takes: `page` or `env` (SPECPILOT_MCP_TOKEN). */
14
14
  const MCP=(document.querySelector('meta[name="specpilot-mcp"]')||{}).content||null;
15
- const MOVABLE={backlog:true,currentSprint:true};
15
+ 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
16
  const chev='<svg class="ico chev" aria-hidden="true" focusable="false"><use href="#i-chev"/></svg>';
17
17
 
18
18
  /* theme: dark by default, light is a per-viewer toggle */
@@ -58,15 +58,21 @@ function initials(n){const w=String(n).split(/[^A-Za-z0-9]+/).filter(Boolean);
58
58
  if(w.length>1)return (w[0][0]+w[1][0]).toUpperCase();
59
59
  return w[0].slice(0,2).toUpperCase();}
60
60
  function renderProject(){
61
- const p=DATA.project, name=projectLabel(p), where=p.root+(p.branch?' · '+p.branch:'');
61
+ $('#footAddr').textContent=$('#homeAddr').textContent=location.host;$('#footVer').textContent=$('#homeVer').textContent='v'+DATA.specpilotVersion;
62
+ const p=DATA.project;
63
+ if(!p){ // no project served (BL-080): an empty rail and top bar; Home is the view
64
+ $('#projList').innerHTML='';$('#curGrp').textContent='';$('#curGrp').title='';$('#curBranch').textContent='';
65
+ $('#subName').textContent='';$('#subPath').textContent='';document.title='SpecPilot Local';return;}
66
+ const name=projectLabel(p), where=p.root+(p.branch?' · '+p.branch:'');
62
67
  $('#projList').innerHTML=DATA.projects.map((q,i)=>{const n=projectLabel(q),cur=i===PROJECT&&!NOPROJ.includes(curView);
63
68
  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
69
  $('#curGrp').textContent=name;$('#curGrp').title=p.root;
65
70
  $('#curBranch').textContent=p.branch||'';
66
71
  $('#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
72
  document.title=name+' · SpecPilot Local';
69
73
  }
74
+ /* Everything a payload draws; with no project served (BL-080) only the rail, bar and footer. */
75
+ function renderAll(){renderProject();if(!DATA.project)return;renderTasks();renderIde();renderAgentFiles();}
70
76
 
71
77
  /* ---------------- views ---------------- */
72
78
  const homeBtn=$('#homeBtn');
@@ -84,28 +90,28 @@ function syncNav(){
84
90
  [homeBtn,...$$('#projList .tile')].forEach(t=>{const cur=t===homeBtn?home:!off&&+t.dataset.project===PROJECT;
85
91
  t.classList.toggle('cur',cur);if(cur)t.setAttribute('aria-current','true');else t.removeAttribute('aria-current');});
86
92
  }
87
- function go(v,keep,sub){
93
+ function go(v,sub){
88
94
  if(v==='file'){if(!DATA||!sub)v='board';else curFile=sub;}
89
95
  else if(NOPROJ.includes(v)){if(!TOKEN)v='board';} // no Home and no #new with --read-only
90
96
  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)
97
+ if(!NOPROJ.includes(v)&&DATA&&!DATA.project)v='home'; // no project served: Home is the only view (BL-080)
98
+ 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
99
  curView=v;
93
100
  $('#win').classList.toggle('home',v==='home');$('#win').classList.toggle('insetup',v==='new'||v==='setup');
94
101
  $$('.content>.view').forEach(e=>e.classList.toggle('on',e.id==='v-'+(v==='new'?'setup':v))); // one Setup view for both (BL-103)
95
102
  syncNav();
96
103
  $('#title').textContent=v==='file'?(TITLES[sub]||sub):VIEWS[v];$('#crumb').hidden=true;
97
104
  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();
105
+ $('#editorBtn').hidden=NOPROJ.includes(v);syncIde();
106
+ setNav(false);closeInsp();closeCardMenu(false);
100
107
  if(v==='home')loadRecent();
101
108
  if(v==='setup'||v==='new')renderSetup();
102
109
  if(v==='file')renderFile(sub);
103
110
  if(v==='explorer')renderExplorer();
104
111
  if(v==='security')renderSecurity();
105
- setHash(v,v==='file'?sub:(keep?stateFor(v):null));
112
+ setHash(v,v==='file'?sub:null);
106
113
  $('#content').scrollTop=0;
107
114
  }
108
- function stateFor(v){return v==='board'?(mode==='board'?'board':null):null}
109
115
  /* URL state. Sandboxed frames refuse replaceState with a URL, so fall back to an in-memory hash. */
110
116
  let urlOk=true,memHash='';
111
117
  try{history.replaceState(null,'',location.href);}catch(e){urlOk=false;}
@@ -118,11 +124,10 @@ function route(){
118
124
  const r=resolveRoute(curHash(),DATA?DATA.files:{},DATA?DATA.projects.length:1,!!TOKEN);
119
125
  if(NOPROJ.includes(r.view)){go(r.view);return;} // Home and #new belong to no project: the shown one stays loaded behind them
120
126
  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);
127
+ go(r.view,r.sub);
123
128
  }
124
129
  if(urlOk)window.addEventListener('hashchange',route);
125
- $$('.src .srow[data-v]').forEach(b=>b.onclick=()=>go(b.dataset.v,false,b.dataset.f));
130
+ $$('.src .srow[data-v]').forEach(b=>b.onclick=()=>go(b.dataset.v,b.dataset.f));
126
131
  function setNav(on){const w=$('#win');w.classList.toggle('nav',on);$('#scrim').hidden=!on;$('#menuBtn').setAttribute('aria-expanded',on?'true':'false');}
127
132
  $('#menuBtn').onclick=()=>setNav(!$('#win').classList.contains('nav'));
128
133
  $('#scrim').onclick=()=>setNav(false);
@@ -159,7 +164,7 @@ $('#rail').addEventListener('keydown',e=>{
159
164
  /* ---------------- tasks: the rows of planning/tasks.md ---------------- */
160
165
  /* Cells are readSpecs() output, verbatim. Rows are keyed by section and position, never by
161
166
  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;
167
+ let selected=null, lastFocus=null;
163
168
  const insp=$('#insp');
164
169
  const COLS={currentSprint:'Current Sprint',backlog:'Backlog',completed:'Completed'};
165
170
  const DOT={completed:'green',currentSprint:'orange',backlog:'hollow'};
@@ -170,36 +175,35 @@ function rowsOf(col){
170
175
  const items=T[col].map((t,i)=>({t,i}));
171
176
  return col==='completed'?items.reverse():items;
172
177
  }
178
+ /* 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
179
  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"':''}>
180
+ const mv=TOKEN&&canMove(col,col);
181
+ 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
182
  <span class="st ${DOT[col]}" aria-hidden="true"></span>
177
183
  <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
184
  <div class="trail">${chev}</div>
179
- </button>`;
185
+ </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>`;
180
186
  }
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>`;
187
+ function group(col,items){
188
+ // BL-TB-05: the two lanes a row can be added to carry `+ Add` at the right of their header; none with --read-only
189
+ 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>`:'';
190
+ // BL-TB-06 (D8): Completed always carries `Archive`, which opens the dialog with the gates; none with --read-only
191
+ 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>`:'';
192
+ const gh=`<div class="gh">${esc(COLS[col])} <span class="cnt">${items.length}</span>${add}${arch}</div>`;
193
+ return gh+`<div class="box">${items.length?items.map(x=>taskRow(x,col)).join(''):'<div class="empty">No rows in this section.</div>'}</div>`;
189
194
  }
190
195
  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';
196
+ closeCardMenu(false); // BL-TB-11: its card is redrawn; focusKey() carries focus back to the card
197
+ $('#boardMode').innerHTML=LANES.map(c=>`<div class="gl" data-col="${c}">${group(c,rowsOf(c))}</div>`).join('');
197
198
  const T=DATA.tasks;
198
199
  const bad=T?T.malformed:[];
199
200
  $('#gRaw').hidden=!bad.length;
200
201
  $('#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>`:
202
+ const wasOpen=!!($('#gIntro')&&$('#gIntro').open); // BL-TB-03: the fold keeps its state through a redraw; closed on a fresh load
203
+ $('#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
204
  (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>');
205
+ if(taskVeil.classList.contains('open'))taskHint(); // BL-TB-05: a redraw (a 409, a live reload) refreshes the dialog's next ID
206
+ if(archVeil.classList.contains('open'))drawGates(); // BL-TB-06: and the Archive dialog's gates
203
207
  bind();
204
208
  }
205
209
  let inspOpen=null; // {kind:'task',col,i,id} | {kind:'file',path} | null
@@ -219,12 +223,16 @@ function openTask(col,i,quiet){
219
223
  function openInsp(quiet){insp.classList.add('open');insp.setAttribute('aria-hidden','false');$('#inspX').onclick=closeInsp;if(!quiet)setTimeout(()=>$('#inspX').focus(),60);}
220
224
  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
225
  function bind(){
222
- $$('#v-board .row[data-col]').forEach(r=>r.onclick=()=>openTask(r.dataset.col,+r.dataset.i));
226
+ $$('#v-board .row[data-col]').forEach(r=>{const col=r.dataset.col,i=+r.dataset.i;
227
+ r.onclick=()=>openTask(col,i);
228
+ 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
229
+ $$('#v-board .card').forEach(c=>{const r=$('.row[data-col]',c),col=r.dataset.col,i=+r.dataset.i;
230
+ c.oncontextmenu=e=>{e.preventDefault();openCardMenu(col,i,e.clientX||e.clientY?{x:e.clientX,y:e.clientY}:menuAnchor(col,i));};});
231
+ $$('#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));});
232
+ $$('#v-board [data-add]').forEach(b=>b.onclick=()=>openNewTask(b.dataset.add,`#v-board [data-add="${b.dataset.add}"]`));
233
+ $$('#v-board [data-archive]').forEach(b=>b.onclick=openArchive);
223
234
  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
235
  }
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
236
 
229
237
  /* ---------------- any .specs/ file, rendered as written ---------------- */
230
238
  function metaLine(m){return ['fileID','version','lastUpdated'].filter(k=>m&&m[k]!==undefined).map(k=>`${k}: ${m[k]}`).join(' · ');}
@@ -249,7 +257,7 @@ function renderExplorer(){
249
257
  $('#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
258
  const line=metaLine(DATA.files[p]);
251
259
  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));
260
+ $$('#exBody .row.act').forEach(b=>b.onclick=()=>go('file',b.dataset.file));
253
261
  $('#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
262
  }
255
263
  /* Security: both files in security/, each rendered as written. */
@@ -363,13 +371,74 @@ ideMenu.addEventListener('keydown',e=>{
363
371
  });
364
372
  document.addEventListener('click',e=>{if(!ideMenu.hidden&&!e.target.closest('#ideWrap'))closeIde(false);});
365
373
 
374
+ /* ---------------- card menu (BL-TB-11) ----------------
375
+ A task card's actions: the lanes the move table lets it go to, reorder, details, Copy ID.
376
+ Built from DATA.tasks.moves (the server's MOVES), so a new lane is a table entry, not page code. */
377
+ const LANES=['backlog','currentSprint','completed']; // the drawn order (REQ-002.H.47); BL-113 adds its lanes here
378
+ const moves=()=>(DATA&&DATA.tasks&&DATA.tasks.moves)||{};
379
+ /* An own key, never `in`: an inherited name (__proto__, toString) is not a lane. A lane in the table may reorder itself. */
380
+ const canMove=(from,to)=>{const m=moves();return Array.isArray(m[from])&&(from===to||m[from].includes(to));};
381
+ /* The nearest lane on that side (dir -1 or 1) of `col` in the drawn order that the table allows, or null. */
382
+ 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;}
383
+ const cardMenu=$('#cardMenu');let menuOn=null; // {col,i} while open
384
+ const cardRow=(col,i)=>$(`#v-board .row[data-col="${col}"][data-i="${i}"]`);
385
+ const dotsBtn=(col,i)=>$(`#v-board .card [data-menu="${col}:${i}"]`);
386
+ const KEYS={'Alt+→':'Alt+ArrowRight','Alt+←':'Alt+ArrowLeft','Alt+↑':'Alt+ArrowUp','Alt+↓':'Alt+ArrowDown'};
387
+ function menuItems(col,i){
388
+ const t=DATA.tasks[col][i],n=DATA.tasks[col].length,it=[];
389
+ if(TOKEN&&canMove(col,col)){
390
+ const right=laneBy(col,1),left=laneBy(col,-1),to=moves()[col].filter(c=>COLS[c]&&DATA.tasks[c]);
391
+ if(to.length)it.push({head:'Move to'});
392
+ 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)});});
393
+ if(i>0)it.push({label:'Move up',hint:'Alt+↑',fn:()=>move(col,i,col,i-1)});
394
+ if(i<n-1)it.push({label:'Move down',hint:'Alt+↓',fn:()=>move(col,i,col,i+1)});
395
+ }
396
+ it.push({label:'Open details',fn:()=>openTask(col,i)});
397
+ it.push({label:'Copy ID',fn:()=>copyText(t.id)});
398
+ return it;
399
+ }
400
+ /* Under the card's ⋯ button, its right edges aligned. */
401
+ function menuAnchor(col,i){const r=(dotsBtn(col,i)||cardRow(col,i)).getBoundingClientRect();return {x:r.right,y:r.bottom+4,right:true};}
402
+ function openCardMenu(col,i,at){
403
+ if(!DATA||!DATA.tasks||!DATA.tasks[col]||!DATA.tasks[col][i])return;
404
+ closeCardMenu(false);hideTip();
405
+ const items=menuItems(col,i),acts=items.filter(x=>!x.head);
406
+ cardMenu.innerHTML=items.map(x=>x.head?`<div class="mh" role="presentation">${esc(x.head)}</div>`
407
+ :`<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('');
408
+ $$('[role=menuitem]',cardMenu).forEach((b,k)=>b.onclick=()=>{closeCardMenu(true);acts[k].fn();});
409
+ menuOn={col,i};
410
+ const btn=dotsBtn(col,i);if(btn)btn.setAttribute('aria-expanded','true');
411
+ cardMenu.hidden=false;
412
+ const w=cardMenu.offsetWidth,h=cardMenu.offsetHeight,m=8;
413
+ cardMenu.style.left=Math.max(m,Math.min(at.right?at.x-w:at.x,innerWidth-w-m))+'px';
414
+ cardMenu.style.top=Math.max(m,Math.min(at.y,innerHeight-h-m))+'px';
415
+ $('[role=menuitem]',cardMenu).focus();
416
+ }
417
+ /* Close; `refocus` puts focus back on the card. A redraw closes it too (renderTasks), the card refocused through focusKey(). */
418
+ function closeCardMenu(refocus){
419
+ if(cardMenu.hidden)return;
420
+ const was=menuOn;menuOn=null;cardMenu.hidden=true;
421
+ if(cardMenu.contains(document.activeElement))document.activeElement.blur(); // now, not at the next frame: a redraw's refocus() checks for a focus-less page
422
+ const btn=was&&dotsBtn(was.col,was.i);if(btn)btn.setAttribute('aria-expanded','false');
423
+ if(refocus&&was){const r=cardRow(was.col,was.i);if(r)r.focus();}
424
+ }
425
+ cardMenu.addEventListener('keydown',e=>{
426
+ const it=$$('[role=menuitem]',cardMenu),i=it.indexOf(document.activeElement);
427
+ if(e.key==='ArrowDown'||e.key==='ArrowUp'){e.preventDefault();it[(i+(e.key==='ArrowDown'?1:it.length-1))%it.length].focus();}
428
+ else if(e.key==='Home'||e.key==='End'){e.preventDefault();it[e.key==='Home'?0:it.length-1].focus();}
429
+ else if(e.key==='Escape'){e.preventDefault();e.stopPropagation();closeCardMenu(true);}
430
+ });
431
+ 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
432
+ cardMenu.addEventListener('focusout',e=>{if(!cardMenu.contains(e.relatedTarget))closeCardMenu(false);});
433
+ document.addEventListener('click',e=>{if(!cardMenu.hidden&&!(e.target.closest&&e.target.closest('#cardMenu,[data-menu]')))closeCardMenu(false);});
434
+
366
435
  /* ---------------- palette + keys ---------------- */
367
436
  const palVeil=$('#palVeil'),palIn=$('#palIn'),palList=$('#palList');
368
437
  function items(q){q=q.toLowerCase();
369
438
  const T=DATA?DATA.tasks:null;
370
439
  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)})),
440
+ ...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])}),
441
+ ...(DATA?DATA.nav.specs:[]).filter(p=>!NAV.some(n=>n[1]===p)).map(p=>({l:'.specs/'+p,k:'file',go:()=>go('file',p)})),
373
442
  ...(T?['currentSprint','backlog','completed'].flatMap(c=>T[c].map((t,i)=>({l:t.id+' '+t.description,k:'task',go:()=>{go('board');openTask(c,i)}}))):[])
374
443
  ];
375
444
  return it.filter(i=>!q||i.l.toLowerCase().includes(q)).slice(0,9);}
@@ -381,12 +450,12 @@ palIn.onkeydown=e=>{if(e.key==='Enter'){const it=items(palIn.value);it[0]&&it[0]
381
450
  document.addEventListener('keydown',e=>{
382
451
  const mod=e.metaKey||e.ctrlKey;const inField=/INPUT|SELECT|TEXTAREA/.test(e.target.tagName);
383
452
  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;
453
+ if(mod&&/^[1-9]$/.test(e.key)){e.preventDefault();const n=NAV[+e.key-1];if(n)go(n[0],n[1]);return}
454
+ 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}
455
+ if(inField||mod||e.altKey||!cardMenu.hidden||taskVeil.classList.contains('open')||archVeil.classList.contains('open'))return;
387
456
  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();}
457
+ if(/^[1-9]$/.test(e.key)){const n=NAV[+e.key-1];if(n)go(n[0],n[1]);}
458
+ 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
459
  });
391
460
 
392
461
  /* ---------------- task moves (BL-053) ----------------
@@ -397,30 +466,33 @@ function bindMoves(){
397
466
  $$('#v-board .row[draggable="true"]').forEach(r=>{
398
467
  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');};
399
468
  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
469
  });
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');};
470
+ // Drop targets (BL-TB-11): every lane; a drop lands only where the move table lets the dragged row go.
471
+ $$('#v-board .gl[data-col]').forEach(g=>{
472
+ g.ondragover=e=>{if(!dragging||!canMove(dragging.col,g.dataset.col))return;e.preventDefault();e.dataTransfer.dropEffect='move';g.classList.add('drop');};
411
473
  g.ondragleave=e=>{if(!g.contains(e.relatedTarget))g.classList.remove('drop');};
412
474
  g.ondrop=e=>{
413
- if(!dragging)return;e.preventDefault();g.classList.remove('drop');
475
+ if(!dragging||!canMove(dragging.col,g.dataset.col))return;e.preventDefault();g.classList.remove('drop');
414
476
  const to=g.dataset.col,src=dragging;dragging=null;
415
477
  // Position among the target's rows once the dragged row is out of the way.
416
478
  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]');
479
+ const card=e.target.closest&&e.target.closest('.card'),over=card&&card.querySelector('.row[data-col]');
418
480
  let at=others.length;
419
481
  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
482
  move(src.col,src.i,to,at);
421
483
  };
422
484
  });
423
485
  }
486
+ /* 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). */
487
+ function altMove(r,e){
488
+ if(!e.altKey||e.metaKey||e.ctrlKey||!r.draggable)return;
489
+ const col=r.dataset.col,i=+r.dataset.i,n=DATA.tasks[col].length;
490
+ const lane=e.key==='ArrowRight'?laneBy(col,1):e.key==='ArrowLeft'?laneBy(col,-1):null;
491
+ 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];
492
+ if(go2===undefined)return;
493
+ e.preventDefault();
494
+ if(go2)move(col,i,go2[0],go2[1]);
495
+ }
424
496
  async function move(col,i,toSection,toIndex,isUndo){
425
497
  const t=DATA.tasks[col][i],p=PROJECT;if(!t||moving)return;
426
498
  moving=true;
@@ -432,10 +504,9 @@ async function move(col,i,toSection,toIndex,isUndo){
432
504
  moving=false;
433
505
  if(p!==PROJECT)return; // the page switched projects while the move was in flight
434
506
  if(r.status===200){
435
- if(toSection==='backlog'&&toIndex>=6)showAllBacklog=true;
436
507
  await apply(body.specs,['.specs/planning/tasks.md']);
437
508
  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();
509
+ const el=$(`#v-board .row[data-col="${toSection}"][data-i="${j}"]`);if(el)el.focus();
439
510
  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
511
  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
512
  }else if(r.status===409){
@@ -448,11 +519,13 @@ async function move(col,i,toSection,toIndex,isUndo){
448
519
  The server appends one row, `| <ID> | <description> |`, to the chosen section and picks the ID.
449
520
  The description goes as typed; a refusal is shown in the form with what was typed kept. */
450
521
  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);});}
522
+ let taskSection='backlog',adding=false,taskFrom=null; // taskFrom: the opener, as a selector, since a lane button is redrawn (BL-TB-05)
453
523
  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();}
524
+ /* The ID the server would give now, from the last payload; a suggestion, the write picks the ID (BL-TB-05). */
525
+ function taskHint(){const n=DATA&&DATA.tasks&&DATA.tasks.nextIds;$('#taskNext').textContent=n?n[taskSection]:'';$('#taskNextWrap').hidden=!n;}
526
+ 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);}
527
+ function focusOpener(){const b=(taskFrom&&$(taskFrom))||$('#v-board [data-add]');if(b)b.focus();}
528
+ function closeNewTask(){if(!taskVeil.classList.contains('open')||adding)return;taskVeil.classList.remove('open');focusOpener();}
456
529
  async function addTask(){
457
530
  if(adding)return;
458
531
  if(!taskIn.value.trim()){taskError('Type a description for the task.');taskIn.focus();return;}
@@ -467,24 +540,81 @@ async function addTask(){
467
540
  if(!r){taskError('The server did not answer. Nothing was added.');return;}
468
541
  if(p!==PROJECT)return;
469
542
  if(r.status===200){
470
- if(section==='backlog'&&body.index>=6)showAllBacklog=true;
471
543
  taskVeil.classList.remove('open');
472
544
  await apply(body.specs,['.specs/planning/tasks.md']);
473
- $('#newTask').focus(); // what closing the inspector returns to
545
+ focusOpener(); // what closing the inspector returns to
474
546
  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'});
547
+ const el=$(`#v-board .row[data-col="${section}"][data-i="${body.index}"]`);if(el)el.scrollIntoView({block:'nearest'});
476
548
  toast(`${body.id} added to ## ${COLS[section]} in planning/tasks.md`);
477
549
  return;
478
550
  }
479
551
  if(r.status===409&&body.specs)await apply(body.specs,null);
480
552
  taskError(body.error||`The task was not added (HTTP ${r.status}).`);taskIn.focus();
481
553
  }
482
- $('#newTask').onclick=openNewTask;
483
- $$('#taskSec button').forEach(b=>b.onclick=()=>setTaskSection(b.dataset.s));
554
+ taskIn.onkeydown=e=>{if(e.key==='Enter'){e.preventDefault();addTask();}}; // a row cannot hold a line break: Enter adds, never breaks the line
484
555
  $('#taskCancel').onclick=closeNewTask;
485
556
  taskVeil.onclick=e=>{if(e.target===taskVeil)closeNewTask();};
486
557
  $('#taskForm').onsubmit=e=>{e.preventDefault();addTask();};
487
558
 
559
+ /* ---------------- archive Completed (BL-TB-06, D8) ----------------
560
+ The Completed step of `specpilot archive`, run by the server with the same plan and block as the CLI. The
561
+ dialog says what the action does and lists the gates from the latest payload: the CLI's branch guard and the
562
+ 40-line limit, each with a box to tick when it warns; a section within the limit is archived with {force:true}
563
+ once the user ticks that box. Every other answer than 200 is shown in the dialog, as New Task does. */
564
+ const archVeil=$('#archVeil');
565
+ let archiving=false;
566
+ function archGates(){
567
+ const b=DATA.project.branch,a=DATA.tasks.archive,n=DATA.tasks.completed.length,out=[];
568
+ if(!b)out.push({key:'branch',text:'No git branch.'});
569
+ else if(b==='main'||b==='master')out.push({key:'branch',text:`On ${b}.`});
570
+ 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.`});
571
+ 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.`});
572
+ 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.`});
573
+ 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.`});
574
+ return out;
575
+ }
576
+ /* Draw the gates from the latest payload; a tick stays on a gate still shown under the same key (a redraw while open). */
577
+ function drawGates(){
578
+ const kept=new Set($$('#archGates input:checked').map(i=>i.dataset.gate));
579
+ $('#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('');
580
+ $$('#archGates input').forEach(i=>i.onchange=archReady);
581
+ archReady();
582
+ }
583
+ function archReady(){$('#archGo').disabled=archiving||!DATA.tasks.archive.rows||$$('#archGates input').some(i=>!i.checked);}
584
+ function archError(m){const e=$('#archErr');e.textContent=m||'';e.hidden=!m;}
585
+ function focusArchive(){const b=$('#v-board [data-archive]');if(b)b.focus();}
586
+ function openArchive(){
587
+ if(!TOKEN||!DATA||!DATA.tasks)return;
588
+ hideTip();archError('');$('#archGates').innerHTML='';archVeil.classList.add('open');drawGates(); // every box starts unticked
589
+ setTimeout(()=>{const f=$('#archGates input')||(!$('#archGo').disabled?$('#archGo'):$('#archCancel'));f.focus();},50);
590
+ }
591
+ function closeArchive(){if(!archVeil.classList.contains('open')||archiving)return;archVeil.classList.remove('open');focusArchive();}
592
+ async function archiveCompleted(){
593
+ if(archiving||!TOKEN||!DATA||!DATA.tasks||$('#archGo').disabled)return;
594
+ const p=PROJECT,force=!!$('#archGates input[data-gate="force"]'); // present only when the limit gate warns, and ticked, or the button is disabled
595
+ archiving=true;$('#archGo').disabled=true;archError('');
596
+ let r,body={};
597
+ try{
598
+ 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}':'{}'});
599
+ body=await r.json().catch(()=>({}));
600
+ }catch(e){r=null;}
601
+ archiving=false;archReady();
602
+ if(!r){archError('The server did not answer. Nothing was archived.');return;}
603
+ if(p!==PROJECT)return;
604
+ if(r.status===200){
605
+ archVeil.classList.remove('open');
606
+ await apply(body.specs,['.specs/planning/tasks.md','.specs/planning/tasks-archive.md']);
607
+ focusArchive();
608
+ toast(`Moved ${body.linesMoved} rows from ## Completed to planning/tasks-archive.md`);
609
+ return;
610
+ }
611
+ if(r.status===409&&body.specs)await apply(body.specs,null); // renderTasks() redraws the gates while the dialog is open
612
+ archError(body.error||`Nothing was archived (HTTP ${r.status}).`);
613
+ }
614
+ $('#archCancel').onclick=closeArchive;
615
+ archVeil.onclick=e=>{if(e.target===archVeil)closeArchive();};
616
+ $('#archForm').onsubmit=e=>{e.preventDefault();archiveCompleted();};
617
+
488
618
  /* ---------------- Setup view (BL-103) ----------------
489
619
  A project without .specs/ (Open, Clone, a folder named on the command line) and #new: the user's AI IDE
490
620
  sets it up over /mcp, and this view says how. It sends no answers and writes no spec; the only request
@@ -541,7 +671,7 @@ function renderSetup(){
541
671
  [...v.children].forEach(el=>{if(el.id!=='suNote')el.hidden=off;});
542
672
  $('#suNote').hidden=TOKEN||!named;$('#suNote').textContent='Started with --read-only, so nothing can be set up here.';
543
673
  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];
674
+ 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
675
  const tail=' Your AI IDE sets them up: it reads the code, answers what it can, and asks you the rest.';
546
676
  $('#suLead').innerHTML=isNew?'Name the project and choose where it goes. Your AI IDE creates it and writes the specs from your answers.'
547
677
  :url?`Cloned ${mono(url)}. It has no SpecPilot specs yet.${tail}`:`${mono(name)} has no SpecPilot specs yet.${tail}`;
@@ -592,8 +722,9 @@ $('#suBrowse').onclick=()=>browseFolder($('#suBrowse'),()=>curView==='new'?$('#s
592
722
  function focusKey(el){
593
723
  if(!el||el===document.body)return null;
594
724
  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))}"]`};
725
+ 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
726
+ 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};}
727
+ 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
728
  if(el.id)return {sel:'#'+CSS.escape(el.id)};
598
729
  return null;
599
730
  }
@@ -606,7 +737,7 @@ function findRow(col,id,oldI){
606
737
  function refocus(key){
607
738
  if(!key||document.activeElement&&document.activeElement!==document.body)return;
608
739
  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}"]`);}
740
+ 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
741
  else el=$(key.sel);
611
742
  if(el)el.focus({preventScroll:true});
612
743
  }
@@ -625,11 +756,12 @@ async function apply(d,paths){
625
756
  (paths||Object.keys(fileCache)).forEach(p=>{delete fileCache[p];});
626
757
  const key=focusKey(document.activeElement);
627
758
  const scroll=$('#content').scrollTop,ib0=insp.querySelector('.ib2'),inspScroll=ib0?ib0.scrollTop:0;
759
+ 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
760
  const was=inspOpen;
629
- const hadSpecs=!(DATA&&DATA.project.specs===false);
761
+ const hadSpecs=!(DATA&&DATA.project&&DATA.project.specs===false);
630
762
  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
763
+ renderAll();
764
+ const to=reloadView(curView,hadSpecs,!d.project||d.project.specs!==false); // .specs/ gone: offer setup; appeared another way: Tasks; Home stays
633
765
  if(to){go(to);return;}
634
766
  if(curView==='file')await renderFile(curFile);
635
767
  if(curView==='explorer')renderExplorer();
@@ -641,6 +773,7 @@ async function apply(d,paths){
641
773
  }
642
774
  if(was&&was.kind==='file'&&(!paths||paths.includes(was.path)))await openFile(was.path,true);
643
775
  $('#content').scrollTop=scroll;
776
+ lanes.forEach(([c,top])=>{const b=$(`#boardMode .gl[data-col="${c}"] .box`);if(b)b.scrollTop=top;});
644
777
  const ib=insp.querySelector('.ib2');if(ib)ib.scrollTop=inspScroll;
645
778
  refocus(key);
646
779
  }
@@ -648,7 +781,7 @@ let es=null;
648
781
  function listen(){
649
782
  if(stopped||!window.EventSource)return;
650
783
  if(es)es.close(); // one stream, for the shown project
651
- es=new EventSource('/api/events?'+pq());let dropped=false;
784
+ es=new EventSource(DATA&&!DATA.project?'/api/events':'/api/events?'+pq());let dropped=false; // no project served: the server-level stream (BL-080)
652
785
  es.addEventListener('clone',e=>onCloneEvent(e.data));
653
786
  es.addEventListener('setup',e=>onSetupEvent(e.data));
654
787
  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 +803,7 @@ async function switchProject(n,keepRoute){
670
803
  function showProject(d,keepRoute){
671
804
  Object.keys(fileCache).forEach(k=>{delete fileCache[k];});secShown.clear();
672
805
  DATA=d;selected=null;setRegenNote([]);
673
- renderProject();renderTasks();renderIde();renderAgentFiles();listen();
806
+ renderAll();listen();
674
807
  if(keepRoute)route();else go('board');
675
808
  }
676
809
  $('#projList').addEventListener('click',e=>{const b=e.target.closest('[data-project]');if(!b)return;
@@ -848,11 +981,11 @@ $('#recentBox').addEventListener('keydown',e=>{const row=e.target.closest&&e.tar
848
981
 
849
982
  /* boot: the project count is unknown until the first load, so an index past the end falls back to project 0 */
850
983
  insp.setAttribute('aria-hidden','true');
851
- $('#gDone').classList.add('closed');
852
984
  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;})
985
+ const bootQ=()=>PROJECT?'?'+pq():''; // project 0 is asked for without the parameter: with nothing served the server answers the no-project state (BL-080)
986
+ fetch('/api/specs'+bootQ(),{cache:'no-store'})
987
+ .then(r=>{if(!r.ok&&PROJECT){PROJECT=0;return fetch('/api/specs'+bootQ(),{cache:'no-store'});}return r;})
855
988
  .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();})
989
+ .then(d=>{DATA=d;renderAll();route();listen();})
857
990
  .catch(e=>showErr('Could not load the project: '+e.message));
858
991
  })();
package/ui/index.html CHANGED
@@ -54,6 +54,8 @@
54
54
  <symbol id="i-shield" viewBox="0 0 24 24"><path d="M12 3l8 3v6c0 5-3.5 8-8 9-4.5-1-8-4-8-9V6z"/><path d="M9 12l2 2 4-4"/></symbol>
55
55
  <symbol id="i-bot" viewBox="0 0 24 24"><rect x="4" y="8" width="16" height="12" rx="2"/><path d="M12 8V4M8 4h8"/><circle cx="9" cy="14" r="1"/><circle cx="15" cy="14" r="1"/></symbol>
56
56
  <symbol id="i-plus" viewBox="0 0 24 24"><path d="M12 5v14M5 12h14"/></symbol>
57
+ <symbol id="i-dots" viewBox="0 0 24 24"><path d="M5 12h.01M12 12h.01M19 12h.01"/></symbol>
58
+ <symbol id="i-archive" viewBox="0 0 24 24"><rect x="3" y="4" width="18" height="4" rx="1"/><path d="M5 8v11a1 1 0 001 1h12a1 1 0 001-1V8M10 12h4"/></symbol>
57
59
  <symbol id="i-gear" viewBox="0 0 24 24"><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.7 1.7 0 00.3 1.8l.1.1a2 2 0 11-2.8 2.8l-.1-.1a1.7 1.7 0 00-1.8-.3 1.7 1.7 0 00-1 1.5V21a2 2 0 11-4 0v-.1a1.7 1.7 0 00-1.1-1.5 1.7 1.7 0 00-1.8.3l-.1.1a2 2 0 11-2.8-2.8l.1-.1a1.7 1.7 0 00.3-1.8 1.7 1.7 0 00-1.5-1H3a2 2 0 110-4h.1a1.7 1.7 0 001.5-1.1 1.7 1.7 0 00-.3-1.8l-.1-.1a2 2 0 112.8-2.8l.1.1a1.7 1.7 0 001.8.3H9a1.7 1.7 0 001-1.5V3a2 2 0 114 0v.1a1.7 1.7 0 001 1.5 1.7 1.7 0 001.8-.3l.1-.1a2 2 0 112.8 2.8l-.1.1a1.7 1.7 0 00-.3 1.8V9a1.7 1.7 0 001.5 1H21a2 2 0 110 4h-.1a1.7 1.7 0 00-1.5 1z"/></symbol>
58
60
  <symbol id="i-sun" viewBox="0 0 24 24"><circle cx="12" cy="12" r="4"/><path d="M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4"/></symbol>
59
61
  <symbol id="i-x" viewBox="0 0 24 24"><path d="M6 6l12 12M18 6L6 18"/></symbol>
@@ -116,10 +118,8 @@
116
118
  <button class="ib menu" id="menuBtn" aria-label="Show sidebar"><svg class="ico" aria-hidden="true" focusable="false"><use href="#i-menu"/></svg></button>
117
119
  <div><h1 id="title">Tasks</h1><div class="sub"><span id="subName" translate="no"></span><span class="mono" id="subPath" translate="no"></span><span class="mono" id="crumb" translate="no" hidden></span></div></div>
118
120
  <div class="right">
119
- <div class="seg" id="modeSeg"><button class="on" data-m="list">List</button><button data-m="board">Board</button></div>
120
121
  <a class="ib" id="editorBtn" hidden aria-label="Open in VS Code" title="Open in VS Code"><svg class="ico" aria-hidden="true" focusable="false"><use href="#i-ext"/></svg></a>
121
122
  <div class="idewrap" id="ideWrap" hidden><button type="button" class="ib" id="ideBtn" aria-haspopup="menu" aria-expanded="false" aria-controls="ideMenu" aria-label="Open in AI IDE" title="Open in AI IDE"><svg class="ico" aria-hidden="true" focusable="false"><use href="#i-spark"/></svg></button><div class="idemenu" id="ideMenu" role="menu" aria-label="Open in AI IDE" hidden></div></div>
122
- <button type="button" class="btn line sm" id="newTask" hidden><svg class="ico ico-13" aria-hidden="true" focusable="false"><use href="#i-plus"/></svg>New Task</button>
123
123
  </div>
124
124
  </div>
125
125
  <div class="content" id="content" tabindex="-1">
@@ -145,14 +145,9 @@
145
145
 
146
146
  <!-- TASKS: the rows of planning/tasks.md, from readSpecs() -->
147
147
  <section class="view on" id="v-board">
148
- <div id="listMode">
149
- <div class="gl" id="gSprint" data-col="currentSprint"></div>
150
- <div class="gl mt18" id="gBacklog" data-col="backlog"></div>
151
- <div class="gl mt18" id="gDone" data-col="completed"></div>
152
- </div>
153
- <div id="boardMode" class="board" hidden></div>
154
148
  <div class="gl" id="gRaw" hidden></div>
155
149
  <div class="gl" id="gConv"></div>
150
+ <div id="boardMode" class="board"></div>
156
151
  </section>
157
152
 
158
153
  <!-- EXPLORER: the .specs/ folder -->
@@ -240,17 +235,28 @@
240
235
 
241
236
  <!-- NEW TASK (BL-PM-005): one row appended to Backlog or Current Sprint in planning/tasks.md -->
242
237
  <div class="veil" id="taskVeil"><div class="sheet task" role="dialog" aria-modal="true" aria-labelledby="taskTitle" tabindex="-1">
243
- <div class="sh"><div><h2 id="taskTitle">New Task</h2><p>Adds one row to <span class="mono" translate="no">planning/tasks.md</span>, as you type it.</p></div></div>
238
+ <div class="sh"><div><h2 id="taskTitle">New Task · <span id="taskLane">Backlog</span></h2><p>Adds one row to <span class="mono" translate="no">planning/tasks.md</span>, as you type it. <span id="taskNextWrap" hidden>Next ID <span class="mono" id="taskNext" translate="no"></span></span></p></div></div>
244
239
  <form class="sb" id="taskForm" autocomplete="off">
245
- <div class="gl"><div class="gh"><label for="taskIn">Description</label></div><div class="box"><div class="field"><input id="taskIn" name="task-description" type="text" aria-describedby="taskErr" placeholder="What needs doing"></div></div></div>
246
- <div class="gl"><div class="gh" id="taskSecL">Section</div><div class="seg" id="taskSec" role="group" aria-labelledby="taskSecL"><button type="button" class="on" data-s="backlog" aria-pressed="true">Backlog</button><button type="button" data-s="currentSprint" aria-pressed="false">Current Sprint</button></div></div>
240
+ <div class="gl"><div class="gh"><label for="taskIn">Description</label></div><div class="box"><div class="field"><textarea id="taskIn" name="task-description" rows="3" aria-describedby="taskErr" placeholder="What needs doing"></textarea></div></div></div>
247
241
  <p class="err" id="taskErr" role="alert" hidden></p>
248
242
  </form>
249
243
  <div class="sf"><button type="button" class="btn" id="taskCancel">Cancel</button><button type="submit" class="btn pri" id="taskGo" form="taskForm">Add Task</button></div>
250
244
  </div></div>
251
245
 
246
+ <!-- ARCHIVE COMPLETED (BL-TB-06, D8): what the action does, the gates that apply, a box to tick for each that warns -->
247
+ <div class="veil" id="archVeil"><div class="sheet task" role="dialog" aria-modal="true" aria-labelledby="archTitle" tabindex="-1">
248
+ <div class="sh"><div><h2 id="archTitle">Archive oldest Completed rows</h2><p>Moves the oldest rows of <span class="mono" translate="no">## Completed</span> in <span class="mono" translate="no">planning/tasks.md</span> into a dated block at the end of <span class="mono" translate="no">planning/tasks-archive.md</span>, as <span class="mono" translate="no">specpilot archive</span> does. The newest 20 stay; <span class="mono" translate="no">prompts.md</span> is not touched.</p></div></div>
249
+ <form class="sb" id="archForm" autocomplete="off">
250
+ <div class="gl"><div class="gh">Checks</div><div class="box" id="archGates"></div></div>
251
+ <p class="err" id="archErr" role="alert" hidden></p>
252
+ </form>
253
+ <div class="sf"><button type="button" class="btn" id="archCancel">Cancel</button><button type="submit" class="btn pri" id="archGo" form="archForm">Archive</button></div>
254
+ </div></div>
255
+
252
256
  <!-- PALETTE -->
253
257
  <div class="veil pal-veil" id="palVeil"><div class="pal"><input id="palIn" type="search" name="q" aria-label="Search views, spec files and tasks" placeholder="Jump to a view, spec file or task…" autocomplete="off" spellcheck="false"><ul id="palList"></ul></div></div>
258
+ <!-- CARD MENU (BL-TB-11): a task card's actions, built from the move table of /api/specs -->
259
+ <div class="idemenu cardmenu" id="cardMenu" role="menu" aria-label="Task actions" hidden></div>
254
260
  <div class="toast" id="toast" role="status" aria-live="polite"></div>
255
261
  </body>
256
262
  </html>