specpilot 2.17.0 → 2.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/ui/app.js CHANGED
@@ -7,7 +7,9 @@ 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). */
@@ -166,8 +168,14 @@ $('#rail').addEventListener('keydown',e=>{
166
168
  ID: IDs repeat in real files (two rows can share a # and an ID). */
167
169
  let selected=null, lastFocus=null;
168
170
  const insp=$('#insp');
169
- const COLS={currentSprint:'Current Sprint',backlog:'Backlog',completed:'Completed'};
170
- 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;}
171
179
  function mdi(t){return md(String(t)).replace(/^<p>/,'').replace(/<\/p>$/,'');}
172
180
  /* Completed is listed newest first (the file runs oldest first); the others in file order. */
173
181
  function rowsOf(col){
@@ -181,7 +189,7 @@ function taskRow({t,i},col){
181
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"':''}>
182
190
  <span class="st ${DOT[col]}" aria-hidden="true"></span>
183
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>
184
- <div class="trail">${chev}</div>
192
+ <div class="trail">${chips(t)}${col==='review'&&t.approved?'<span class="pill green chip">Approved</span>':''}${chev}</div>
185
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>`;
186
194
  }
187
195
  function group(col,items){
@@ -189,16 +197,26 @@ function group(col,items){
189
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>`:'';
190
198
  // BL-TB-06 (D8): Completed always carries `Archive`, which opens the dialog with the gates; none with --read-only
191
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>`:'';
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>`;
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>`;
194
206
  }
195
207
  function renderTasks(){
196
208
  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('');
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
198
212
  const T=DATA.tasks;
199
213
  const bad=T?T.malformed:[];
200
214
  $('#gRaw').hidden=!bad.length;
201
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>`:'';
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;}
202
220
  const wasOpen=!!($('#gIntro')&&$('#gIntro').open); // BL-TB-03: the fold keeps its state through a redraw; closed on a fresh load
203
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>`:
204
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>');
@@ -206,6 +224,86 @@ function renderTasks(){
206
224
  if(archVeil.classList.contains('open'))drawGates(); // BL-TB-06: and the Archive dialog's gates
207
225
  bind();
208
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
+ // BL-120: a table whose header has another column count than the lane reads
260
+ // BL-125: for Backlog, Current Sprint and Review the header names neither shape; it is read in the plain one
261
+ const TYPED_COLS='ID, Type, Priority and Description';
262
+ const colWarns=Object.entries(H.columnsFound||{}).map(([h,{columns:n,names:found,unread:k}])=>{
263
+ const lane=h.slice(3),shaped=SHAPED.some(c=>'## '+COLS[c]===h),names=H.columns[h]||['ID','Description'],m=names.length,cols=shaped?TYPED_COLS:joinAnd(names);
264
+ const prompt=shaped?`In ${TASKS_FILE}, turn the "${h}" section into a markdown table with ${TYPED_COLS} columns, one row per task, keeping every task's ID and text; put an existing priority into Priority as P1, P2 or P3 (high, medium, low), and move any status that says more than "open" to the start of the description, so SpecPilot's Tasks board reads it.`
265
+ :`In ${TASKS_FILE}, turn the "${h}" section into a markdown table with ${cols} columns, one row per task${h==='## Completed'?' (numbered from 1 with the oldest entry first)':''}, keeping every task's ID and text, so SpecPilot's Tasks board reads it.`;
266
+ const body=n>m?'The extra columns show inside each row\'s description.':k?`${k===1?'1 row is':k+' rows are'} listed under Rows that could not be parsed.`:'';
267
+ const title=shaped?`it has ${n===1?'1 column':n+' columns'}, ${esc(joinAnd(found||[]))}; the board reads ${TYPED_COLS}, or ID and Description`:`it has ${n===1?'1 column':n+' columns'}, the board reads ${m}`;
268
+ 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 cannot read its table: ${title}</div>`+
269
+ (body?`<p>${body}</p>`:'')+
270
+ `<p>Fix: edit <span class="mono" translate="no">${TASKS_FILE}</span> and give the table ${esc(cols)} columns, one row per task, best done by your AI IDE so that every task keeps its ID and text.</p>`+
271
+ `<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>`;
272
+ });
273
+ // BL-125: the three lanes do not share one shape, so rows with a Type or Priority cannot move into the plain ones
274
+ const sh=H.shapes||{},plain=SHAPED.filter(c=>sh['## '+COLS[c]]==='plain').map(c=>COLS[c]);
275
+ const shapeWarns=plain.length&&SHAPED.some(c=>sh['## '+COLS[c]]==='typed')?[(()=>{
276
+ const prompt=`In ${TASKS_FILE}, give the ${joinAnd(plain)} table${plain.length===1?'':'s'} ${TYPED_COLS} columns, with empty Type and Priority cells in every row, so SpecPilot's Tasks board can move rows between lanes.`;
277
+ 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> Backlog, Current Sprint and Review have different table shapes</div>`+
278
+ `<p>${esc(joinAnd(plain))} ${plain.length===1?'has':'have'} no Type and Priority columns, so a row with a Type or Priority cannot move into ${plain.length===1?'it':'them'}.</p>`+
279
+ `<p>Fix: edit <span class="mono" translate="no">${TASKS_FILE}</span> and give ${plain.length===1?'that table':'those tables'} ${TYPED_COLS} columns, with empty cells in every row, best done by your AI IDE.</p>`+
280
+ `<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>`;
281
+ })()]:[];
282
+ warns.push(...lineWarns,...colWarns,...shapeWarns);
283
+ const candidates=new Set([].concat(...Object.values(H.variants)));
284
+ const hidden=hiddenNotes(H.unknown.slice().sort());
285
+ const notes=H.unknown.filter(h=>!candidates.has(h)&&!hidden.includes(h)).map(h=>{
286
+ const n=H.unknownRows[h]||0;
287
+ 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`;
288
+ 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>`+
289
+ `<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>`;
290
+ });
291
+ // BL-125 (d): every moving lane with a table is plain, so no card has Type or Priority; a note, since nothing is wrong
292
+ if(SHAPED.some(c=>sh['## '+COLS[c]]==='plain')&&!SHAPED.some(c=>sh['## '+COLS[c]]==='typed')&&!hidden.includes(PLAIN_NOTE)){
293
+ const prompt=`In ${TASKS_FILE}, give the Backlog, Current Sprint and Review tables ${TYPED_COLS} columns, with empty Type and Priority cells in every row, keeping every task's ID and text, so SpecPilot's Tasks board can show and set Type and Priority.`;
294
+ notes.push(`<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> Type and Priority are off: Backlog, Current Sprint and Review have no Type and Priority columns</div>`+
295
+ `<p>Add the columns to show Priority and Type on each card and set them in the task details. Rows keep their text; each gets two empty cells.</p><div class="actions">${openBtn}<button type="button" class="btn sm" data-prompt="${esc(prompt)}">Copy prompt</button></div></div>${x(`data-hidenote="${PLAIN_NOTE}"`,'Hide this note')}</div>`);
296
+ }
297
+ 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>`:'';
298
+ return (warnHidden?bar:warns.join(''))+notes.join('');
299
+ }
300
+ $('#gHead').addEventListener('click',e=>{
301
+ const t=e.target.closest('[data-prompt],[data-hidewarn],[data-showwarn],[data-hidenote]');if(!t)return;
302
+ if(t.hasAttribute('data-prompt'))copyText(t.getAttribute('data-prompt'));
303
+ else if(t.hasAttribute('data-hidewarn')){warnHidden=true;renderTasks();const s=$('#gHead [data-showwarn]');if(s)s.focus();}
304
+ else if(t.hasAttribute('data-showwarn')){warnHidden=false;renderTasks();const c=$('#gHead [data-hidewarn]');if(c)c.focus();}
305
+ else hideNote(t.getAttribute('data-hidenote'));
306
+ });
209
307
  let inspOpen=null; // {kind:'task',col,i,id} | {kind:'file',path} | null
210
308
  function openTask(col,i,quiet){
211
309
  const t=DATA.tasks[col][i];if(!t)return;
@@ -213,14 +311,139 @@ function openTask(col,i,quiet){
213
311
  selected=col+':'+i;inspOpen={kind:'task',col,i,id:t.id};
214
312
  $$('.row.sel').forEach(r=>r.classList.remove('sel'));
215
313
  $$(`#v-board .row[data-col="${col}"][data-i="${i}"]`).forEach(r=>r.classList.add('sel'));
216
- 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>
314
+ // 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
315
+ 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>`:'';
316
+ 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>`:'';
317
+ // D14: an approved row says what happens next and hands over the one-line prompt for the agent
318
+ 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>`:'';
319
+ 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>
320
+ <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>
321
+ <p class="err" id="rvErr" role="alert" hidden></p></div>`:'';
322
+ 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>
217
323
  <div class="ib2">
218
324
  <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>
325
+ ${fieldsBlock(col,t)}${reason}${hist}
219
326
  <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>
220
- </div>`;
327
+ </div>${foot}`;
328
+ if(foot)bindReview(col,i);
329
+ bindRadios(insp,(key,btn)=>chooseField(col,i,key,btn));
221
330
  openInsp(quiet);
222
331
  }
223
- function openInsp(quiet){insp.classList.add('open');insp.setAttribute('aria-hidden','false');$('#inspX').onclick=closeInsp;if(!quiet)setTimeout(()=>$('#inspX').focus(),60);}
332
+ /* ---------------- Type and Priority (BL-125) ----------------
333
+ A row of a typed Backlog, Current Sprint or Review table carries a Type and a Priority: chips on the card's bottom
334
+ line, two radio groups in the detail panel that write through POST /api/tasks/fields on choice, the same two in
335
+ New Task. A value outside the set is shown as written and checks no radio; a plain table has neither. */
336
+ const PRIORITIES=['P1','P2','P3'],TYPES=['feat','bug','chore'],SHAPED=['backlog','currentSprint','review'];
337
+ const PLAIN_NOTE='#plain-tables'; // the plain-tables note's key among the hidden notes: no heading starts with #
338
+ const shapeOf=col=>((DATA.tasks&&DATA.tasks.headings&&DATA.tasks.headings.shapes)||{})['## '+COLS[col]];
339
+ /* A value's colour class, shared by its chip and its chosen radio; none for a value outside the set, which stays muted. */
340
+ const tone=v=>[...PRIORITIES,...TYPES].includes(v)?' v-'+v.toLowerCase():'';
341
+ function chips(t){
342
+ return (t.priority?`<span class="pill chip pri${tone(t.priority)}" translate="no">${esc(t.priority)}</span>`:'')+(t.type?`<span class="pill chip ty${tone(t.type)}" translate="no">${esc(t.type)}</span>`:'');
343
+ }
344
+ /* One radio group: `id` names it (its buttons are `<id>-<value>`, `<id>-none`), `key` is the field it sets. */
345
+ function radios(id,key,label,vals,cur){
346
+ const all=[...vals,''],on=all.includes(cur||'')?(cur||''):null;
347
+ return `<div class="tfr"><span class="tfl" id="${id}L">${label}</span><div class="seg" role="radiogroup" aria-labelledby="${id}L" id="${id}" data-key="${key}">${all.map(v=>{const c=v===on,first=on===null&&v===all[0];
348
+ return `<button type="button" role="radio" id="${id}-${v||'none'}" data-v="${v}" aria-checked="${c}" tabindex="${c||first?0:-1}" class="${((c?'on':'')+tone(v)).trim()}" translate="no">${v||'None'}</button>`;}).join('')}</div></div>`;
349
+ }
350
+ function checkRadio(btn){btn.closest('[role="radiogroup"]').querySelectorAll('[role="radio"]').forEach(b=>{const c=b===btn;b.setAttribute('aria-checked',c);b.classList.toggle('on',c);b.tabIndex=c?0:-1;});}
351
+ /* Click chooses; arrow keys move and choose, as a radio group does. */
352
+ function bindRadios(root,choose){
353
+ root.querySelectorAll('[role="radiogroup"]').forEach(g=>{
354
+ const bs=[...g.querySelectorAll('[role="radio"]')];
355
+ bs.forEach((b,n)=>{
356
+ b.onclick=()=>choose(g.dataset.key,b);
357
+ b.onkeydown=e=>{const d={ArrowRight:1,ArrowDown:1,ArrowLeft:-1,ArrowUp:-1}[e.key];if(!d||e.altKey||e.metaKey||e.ctrlKey)return;e.preventDefault();e.stopPropagation();const nb=bs[(n+d+bs.length)%bs.length];nb.focus();choose(g.dataset.key,nb);};
358
+ });
359
+ });
360
+ }
361
+ function fieldsBlock(col,t){
362
+ if(!SHAPED.includes(col))return '';
363
+ if(shapeOf(col)!=='typed')return '<p class="tfnote" id="tfNote">This lane\'s table has no Type and Priority columns. Add them to set Priority and Type here.</p>';
364
+ if(!TOKEN)return `<div class="gl"><div class="gh">Priority and Type</div><div class="box"><p class="tfv" translate="no">Priority ${esc(t.priority||'None')} · Type ${esc(t.type||'None')}</p></div></div>`;
365
+ return `<div class="gl"><div class="gh">Priority and Type</div><div class="box tf" id="tfBox">${radios('tfPri','priority','Priority',PRIORITIES,t.priority)}${radios('tfType','type','Type',TYPES,t.type)}<p class="err" id="tfErr" role="alert" hidden></p></div></div>`;
366
+ }
367
+ let fielding=false;
368
+ async function chooseField(col,i,key,btn){
369
+ const t=DATA.tasks[col]&&DATA.tasks[col][i],p=PROJECT,v=btn.dataset.v;if(!t||fielding||(t[key]||'')===v)return;
370
+ fielding=true;checkRadio(btn);const box=$('#tfBox');if(box)box.setAttribute('aria-busy','true');
371
+ let r,body={};
372
+ try{
373
+ r=await fetch('/api/tasks/fields?'+pq(),{method:'POST',cache:'no-store',headers:{'Content-Type':'application/json','X-SpecPilot-Token':TOKEN,'If-Match':DATA.tasks.sha256},body:JSON.stringify({id:t.id,[key]:v})});
374
+ body=await r.json().catch(()=>({}));
375
+ }catch(e){r=null;}
376
+ fielding=false;
377
+ if(p!==PROJECT)return;
378
+ if(r&&r.status===200){wrote(['.specs/planning/tasks.md'],body.specs);await apply(body.specs,['.specs/planning/tasks.md']);return;} // the panel is redrawn from the file; focus stays on the chosen radio
379
+ if(r&&r.status===409&&body.specs)await apply(body.specs,null);
380
+ const k=findRow(col,t.id,i);if(k>=0&&inspOpen&&inspOpen.id===t.id)openTask(col,k,true); // the earlier choice, as the file has it
381
+ const e=$('#tfErr');if(e){e.textContent=!r?'The server did not answer. Nothing was changed.':body.error||`Nothing was changed (HTTP ${r.status}).`;e.hidden=false;}
382
+ const g='#'+(key==='priority'?'tfPri':'tfType'),f=$(`${g} [aria-checked="true"]`)||$(`${g} [role="radio"]`);if(f)f.focus();
383
+ }
384
+ /* ---------------- review (BL-113) ----------------
385
+ Approve appends ` Approved <date>` to the row; Send back appends ` Sent back <date>: <note>` and moves the row to the
386
+ top of Current Sprint; each toast's Undo sends the inverse action, which removes exactly that marker. One route,
387
+ POST /api/tasks/review, with the move's checks; a refusal shows in the footer with the note kept. */
388
+ let reviewing=false;
389
+ function rvError(m){const e=$('#rvErr');if(!e)return;e.textContent=m||'';e.hidden=!m;}
390
+ function rvCount(){const n=$('#rvNote'),c=$('#rvCount');if(n&&c)c.textContent=[...n.value].length+'/200';}
391
+ function openSendBack(text){
392
+ const f=$('#rvForm');if(!f)return;f.hidden=false;$('#rvSend').hidden=true;const a=$('#rvApprove');if(a)a.hidden=true;
393
+ const n=$('#rvNote');n.value=text||'';rvCount();rvError('');n.focus();
394
+ 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
395
+ }
396
+ function closeSendBack(refocus){
397
+ const f=$('#rvForm');if(!f||f.hidden)return;f.hidden=true;$('#rvSend').hidden=false;const a=$('#rvApprove');if(a)a.hidden=false;rvError('');
398
+ if(refocus)$('#rvSend').focus();
399
+ }
400
+ /* The sentence an approved row hands to the agent (D14): what the generated Tasks mandate asks of it, with this row's ID. */
401
+ 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.`;
402
+ function bindReview(col,i){
403
+ const a=$('#rvApprove');if(a)a.onclick=()=>review(col,i,'approve',{});
404
+ const c=$('#rvCopy');if(c)c.onclick=()=>copyText(wrapUpPrompt(DATA.tasks[col][i].id));
405
+ $('#rvSend').onclick=()=>openSendBack('');
406
+ $('#rvCancel').onclick=()=>closeSendBack(true);
407
+ $('#rvNote').oninput=rvCount;
408
+ $('#rvNote').onkeydown=e=>{
409
+ if(e.key==='Escape'){e.preventDefault();e.stopPropagation();closeSendBack(true);}
410
+ else if(e.key==='Enter'&&(e.metaKey||e.ctrlKey)){e.preventDefault();$('#rvForm').requestSubmit();}
411
+ };
412
+ $('#rvForm').onsubmit=e=>{e.preventDefault();review(col,i,'sendBack',{note:$('#rvNote').value});};
413
+ }
414
+ /* `col`/`i` locate the row now; `extra` is the action's own fields; the undo of an action is `isUndo`. */
415
+ async function review(col,i,action,extra,isUndo){
416
+ const t=DATA.tasks[col]&&DATA.tasks[col][i],p=PROJECT;if(!t||reviewing)return;
417
+ const typed=extra.note;
418
+ reviewing=true;$$('#inspFoot button').forEach(b=>{b.disabled=true;});
419
+ let r,body={};
420
+ try{
421
+ 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})});
422
+ body=await r.json().catch(()=>({}));
423
+ }catch(e){r=null;}
424
+ reviewing=false;$$('#inspFoot button').forEach(b=>{b.disabled=false;});
425
+ 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;}
426
+ if(p!==PROJECT)return;
427
+ if(r.status===200){
428
+ const toLane=action==='sendBack'?'currentSprint':'review';
429
+ if(action==='sendBack'||action==='unsendBack'){lastFocus=null;closeInsp();}
430
+ wrote(['.specs/planning/tasks.md'],body.specs);await apply(body.specs,['.specs/planning/tasks.md']);
431
+ const j=DATA.tasks[toLane].findIndex(x=>x.id===t.id);
432
+ if(action==='sendBack'||action==='unsendBack'){const el=$(`#v-board .row[data-col="${toLane}"][data-i="${j}"]`);if(el)el.focus();}
433
+ else{const b=$(action==='approve'?'#rvSend':'#rvApprove')||$('#inspX');if(b&&insp.classList.contains('open'))b.focus();}
434
+ 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);}});
435
+ else if(action==='unapprove')toast(`${t.id} is no longer marked Approved`);
436
+ 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);}});
437
+ else toast(`${t.id} is back in ## Review in planning/tasks.md`);
438
+ return;
439
+ }
440
+ if(r.status===409&&body.specs)await apply(body.specs,null); // the inspector is redrawn on the same row when it is still there
441
+ const msg=body.error||`Nothing was changed (HTTP ${r.status}).`;
442
+ if(action==='sendBack'&&$('#rvForm')){openSendBack(typed);rvError(msg);}
443
+ else if($('#inspFoot'))rvError(msg);
444
+ else toast(msg);
445
+ }
446
+ 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)
224
447
  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;}}
225
448
  function bind(){
226
449
  $$('#v-board .row[data-col]').forEach(r=>{const col=r.dataset.col,i=+r.dataset.i;
@@ -231,6 +454,7 @@ function bind(){
231
454
  $$('#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
455
  $$('#v-board [data-add]').forEach(b=>b.onclick=()=>openNewTask(b.dataset.add,`#v-board [data-add="${b.dataset.add}"]`));
233
456
  $$('#v-board [data-archive]').forEach(b=>b.onclick=openArchive);
457
+ $$('#v-board [data-fold]').forEach(b=>b.onclick=()=>{wontDoOpen=!wontDoOpen;renderTasks();const f=$('#v-board [data-fold]');if(f)f.focus();}); // BL-113
234
458
  if(TOKEN)bindMoves();
235
459
  }
236
460
 
@@ -374,7 +598,8 @@ document.addEventListener('click',e=>{if(!ideMenu.hidden&&!e.target.closest('#id
374
598
  /* ---------------- card menu (BL-TB-11) ----------------
375
599
  A task card's actions: the lanes the move table lets it go to, reorder, details, Copy ID.
376
600
  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
601
+ const LANES=['backlog','currentSprint','review','completed','wontDo']; // the drawn order (REQ-002.H.47; Review and Won't do since BL-113)
602
+ const REQUIRED=LANES.filter(c=>c!=='wontDo'); // the headings the board asks for (BL-112's sentences); Won't do is read when present
378
603
  const moves=()=>(DATA&&DATA.tasks&&DATA.tasks.moves)||{};
379
604
  /* An own key, never `in`: an inherited name (__proto__, toString) is not a lane. A lane in the table may reorder itself. */
380
605
  const canMove=(from,to)=>{const m=moves();return Array.isArray(m[from])&&(from===to||m[from].includes(to));};
@@ -386,8 +611,12 @@ const dotsBtn=(col,i)=>$(`#v-board .card [data-menu="${col}:${i}"]`);
386
611
  const KEYS={'Alt+→':'Alt+ArrowRight','Alt+←':'Alt+ArrowLeft','Alt+↑':'Alt+ArrowUp','Alt+↓':'Alt+ArrowDown'};
387
612
  function menuItems(col,i){
388
613
  const t=DATA.tasks[col][i],n=DATA.tasks[col].length,it=[];
614
+ if(TOKEN&&col==='review'){ // BL-113: the reviewed exits first
615
+ if(!t.approved)it.push({label:'Approve',fn:()=>{openTask(col,i);review(col,i,'approve',{});}});
616
+ it.push({label:'Send back…',fn:()=>{openTask(col,i);openSendBack('');}});
617
+ }
389
618
  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]);
619
+ 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
391
620
  if(to.length)it.push({head:'Move to'});
392
621
  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
622
  if(i>0)it.push({label:'Move up',hint:'Alt+↑',fn:()=>move(col,i,col,i-1)});
@@ -439,7 +668,7 @@ function items(q){q=q.toLowerCase();
439
668
  const it=[
440
669
  ...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
670
  ...(DATA?DATA.nav.specs:[]).filter(p=>!NAV.some(n=>n[1]===p)).map(p=>({l:'.specs/'+p,k:'file',go:()=>go('file',p)})),
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)}}))):[])
671
+ ...(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)}}))):[])
443
672
  ];
444
673
  return it.filter(i=>!q||i.l.toLowerCase().includes(q)).slice(0,9);}
445
674
  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()}}});}
@@ -451,8 +680,8 @@ document.addEventListener('keydown',e=>{
451
680
  const mod=e.metaKey||e.ctrlKey;const inField=/INPUT|SELECT|TEXTAREA/.test(e.target.tagName);
452
681
  if(mod&&e.key.toLowerCase()==='k'){e.preventDefault();palVeil.classList.contains('open')?closePal():openPal();return}
453
682
  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;
683
+ if(e.key==='Escape'){if(busyVeil.classList.contains('open')){closeBusy();return}if(!ideMenu.hidden){closeIde(true);return}if(!cardMenu.hidden){closeCardMenu(true);return}hideTip();closeInsp();closePal();closeSheet();closeNewTask();closeArchive();setNav(false);return}
684
+ if(inField||mod||e.altKey||!cardMenu.hidden||taskVeil.classList.contains('open')||archVeil.classList.contains('open')||busyVeil.classList.contains('open'))return;
456
685
  if(e.key==='h'&&TOKEN&&!openVeil.classList.contains('open')){go('home');return;}
457
686
  if(/^[1-9]$/.test(e.key)){const n=NAV[+e.key-1];if(n)go(n[0],n[1]);}
458
687
  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();}
@@ -461,14 +690,17 @@ document.addEventListener('keydown',e=>{
461
690
  /* ---------------- task moves (BL-053) ----------------
462
691
  A move is one line of planning/tasks.md cut and pasted unchanged; the server does it and
463
692
  answers with the new file hash and the fresh payload. Completed rows never move. */
464
- let dragging=null,moving=false;
693
+ let dragging=null,moving=false,hinted=false; // hinted: the Completed toast once per drag (D15)
694
+ /* D15: why a card cannot go to Completed from the page, said once per gesture instead of a silent refusal. */
695
+ 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.';
465
696
  function bindMoves(){
466
697
  $$('#v-board .row[draggable="true"]').forEach(r=>{
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');};
698
+ 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;};
468
699
  r.ondragend=()=>{r.classList.remove('drag');dragging=null;$$('.gl.drop').forEach(g=>g.classList.remove('drop'));};
469
700
  });
470
701
  // Drop targets (BL-TB-11): every lane; a drop lands only where the move table lets the dragged row go.
471
702
  $$('#v-board .gl[data-col]').forEach(g=>{
703
+ g.ondragenter=()=>{if(dragging&&g.dataset.col==='completed'&&!canMove(dragging.col,'completed')&&!hinted){hinted=true;toast(COMPLETED_HINT);}}; // D15
472
704
  g.ondragover=e=>{if(!dragging||!canMove(dragging.col,g.dataset.col))return;e.preventDefault();e.dataTransfer.dropEffect='move';g.classList.add('drop');};
473
705
  g.ondragleave=e=>{if(!g.contains(e.relatedTarget))g.classList.remove('drop');};
474
706
  g.ondrop=e=>{
@@ -479,7 +711,8 @@ function bindMoves(){
479
711
  const card=e.target.closest&&e.target.closest('.card'),over=card&&card.querySelector('.row[data-col]');
480
712
  let at=others.length;
481
713
  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);}}
482
- move(src.col,src.i,to,at);
714
+ 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
715
+ else move(src.col,src.i,to,at);
483
716
  };
484
717
  });
485
718
  }
@@ -491,10 +724,19 @@ function altMove(r,e){
491
724
  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
725
  if(go2===undefined)return;
493
726
  e.preventDefault();
494
- if(go2)move(col,i,go2[0],go2[1]);
727
+ if(go2&&col==='review'&&go2[0]!==col)review(col,i,'sendBack',{note:''}); // D16
728
+ else if(go2)move(col,i,go2[0],go2[1]);
729
+ else if(e.key==='ArrowRight'&&LANES[LANES.indexOf(col)+1]==='completed')toast(COMPLETED_HINT); // D15: Alt+→ from the lane before Completed
495
730
  }
496
- async function move(col,i,toSection,toIndex,isUndo){
731
+ async function move(col,i,toSection,toIndex,isUndo,asked){
497
732
  const t=DATA.tasks[col][i],p=PROJECT;if(!t||moving)return;
733
+ // BL-127: on a branch or while something else writes .specs/, ask first; an Undo is not asked again
734
+ if(!isUndo&&!asked){const s=busySignals();if(s.length)return askBusy(t,col,s,()=>{
735
+ if(p!==PROJECT)return; // asked for this project only
736
+ const k=DATA.tasks[col].findIndex(x=>x.id===t.id);
737
+ if(k<0){toast(`${t.id} is no longer in ## ${COLS[col]}. Nothing was moved.`);return;}
738
+ move(col,k,toSection,toIndex,false,true);
739
+ });}
498
740
  moving=true;
499
741
  let r,body={};
500
742
  try{
@@ -504,7 +746,7 @@ async function move(col,i,toSection,toIndex,isUndo){
504
746
  moving=false;
505
747
  if(p!==PROJECT)return; // the page switched projects while the move was in flight
506
748
  if(r.status===200){
507
- await apply(body.specs,['.specs/planning/tasks.md']);
749
+ wrote(['.specs/planning/tasks.md'],body.specs);await apply(body.specs,['.specs/planning/tasks.md']);
508
750
  const j=DATA.tasks[toSection].findIndex(x=>x.id===t.id);
509
751
  const el=$(`#v-board .row[data-col="${toSection}"][data-i="${j}"]`);if(el)el.focus();
510
752
  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`;
@@ -515,6 +757,53 @@ async function move(col,i,toSection,toIndex,isUndo){
515
757
  }else toast(body.error||`The move was not made (HTTP ${r.status}).`);
516
758
  }
517
759
 
760
+ /* ---------------- work in progress (BL-127) ----------------
761
+ Two signals before a move or Archive: a branch other than main or master, and a .specs/ change drawn in the last
762
+ 120 s that is not the echo of this page's own last write (same paths, the hash that write answered with). Only
763
+ what the page has seen counts; no git is run. */
764
+ const BUSY_MS=120000,busyVeil=$('#busyVeil');
765
+ let lastWrite=null,activity=null,busyGo=null,busyFrom=null; // activity: {p, at, paths}; busyFrom: the card's lane and ID, for focus
766
+ function wrote(paths,d){lastWrite={paths,sha:d&&d.tasks?d.tasks.sha256:null};}
767
+ function noteActivity(paths,d){
768
+ const sp=(paths||[]).filter(x=>x.startsWith('.specs/'));if(!sp.length)return;
769
+ if(lastWrite&&d.tasks&&d.tasks.sha256===lastWrite.sha&&sp.every(x=>lastWrite.paths.includes(x)))return; // our own write's echo
770
+ activity={p:PROJECT,at:Date.now(),paths:sp};
771
+ }
772
+ const branchOff=()=>{const b=DATA&&DATA.project&&DATA.project.branch;return b&&b!=='main'&&b!=='master'?b:null;};
773
+ const branchRisk=what=>`${what} is written to this branch's planning/tasks.md, so it is committed with this branch's work, and merging the branch can conflict with tasks.md changes made on the default branch.`;
774
+ /* `<file> changed on disk <n> seconds ago, not from this page`, or null outside the window. */
775
+ function recentActivity(){
776
+ if(!activity||activity.p!==PROJECT)return null;
777
+ const ms=Date.now()-activity.at;if(ms<0||ms>=BUSY_MS)return null;
778
+ const n=Math.floor(ms/1000),ps=activity.paths,f=ps.includes('.specs/planning/tasks.md')?'.specs/planning/tasks.md':ps[0],k=ps.length-1;
779
+ return `${f}${k?` and ${k} more ${k===1?'file':'files'}`:''} changed on disk ${n} ${n===1?'second':'seconds'} ago, not from this page`;
780
+ }
781
+ function busySignals(){
782
+ const out=[],b=branchOff(),a=recentActivity();
783
+ if(b)out.push(`You are on branch ${b}, not the default branch. ${branchRisk('The move')}`);
784
+ if(a)out.push(`${a}: an agent or editor may still be working on the specs. If it saves planning/tasks.md from a copy it read before your move, your move is lost; if it edits after, its edit can fail or land on the wrong row because the rows moved under it. Wait until it is done, or ask it to make the move.`);
785
+ return out;
786
+ }
787
+ function askBusy(t,col,signals,go){
788
+ closeCardMenu(false);hideTip();
789
+ busyGo=go;busyFrom={col,id:t.id};
790
+ $('#busyTitle').textContent=`Move ${t.id} while work is in progress?`;
791
+ $('#busyBody').innerHTML=signals.map(x=>`<div class="gate warn"><span class="st orange" aria-hidden="true"></span><span class="gt">${esc(x)}</span></div>`).join('');
792
+ busyVeil.classList.add('open');
793
+ setTimeout(()=>$('#busyCancel').focus(),50);
794
+ }
795
+ /* Cancel, Escape or the backdrop: nothing written, focus back on the card. */
796
+ function closeBusy(){
797
+ if(!busyVeil.classList.contains('open'))return;
798
+ busyVeil.classList.remove('open');busyGo=null;
799
+ const f=busyFrom;busyFrom=null;
800
+ const k=f&&DATA&&DATA.tasks&&DATA.tasks[f.col]?DATA.tasks[f.col].findIndex(x=>x.id===f.id):-1;
801
+ const el=k>=0&&$(`#v-board .row[data-col="${f.col}"][data-i="${k}"]`);if(el)el.focus();
802
+ }
803
+ $('#busyCancel').onclick=closeBusy;
804
+ busyVeil.onclick=e=>{if(e.target===busyVeil)closeBusy();};
805
+ $('#busyGo').onclick=()=>{const go=busyGo;busyGo=null;busyFrom=null;busyVeil.classList.remove('open');if(go)go();};
806
+
518
807
  /* ---------------- new task (BL-PM-005) ----------------
519
808
  The server appends one row, `| <ID> | <description> |`, to the chosen section and picks the ID.
520
809
  The description goes as typed; a refusal is shown in the form with what was typed kept. */
@@ -523,7 +812,10 @@ let taskSection='backlog',adding=false,taskFrom=null; // taskFrom: the opener, a
523
812
  function taskError(m){const e=$('#taskErr');e.textContent=m||'';e.hidden=!m;}
524
813
  /* The ID the server would give now, from the last payload; a suggestion, the write picks the ID (BL-TB-05). */
525
814
  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);}
815
+ 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();taskFields();taskVeil.classList.add('open');setTimeout(()=>taskIn.focus(),50);}
816
+ /* BL-125: Priority and Type, both None, for a typed lane; nothing for a plain one. */
817
+ function taskFields(){const f=$('#taskFields'),typed=shapeOf(taskSection)==='typed';f.innerHTML=typed?radios('ntPri','priority','Priority',PRIORITIES,'')+radios('ntType','type','Type',TYPES,''):'';f.hidden=!typed;bindRadios(f,(key,b)=>checkRadio(b));}
818
+ const taskValue=id=>{const b=$(`#${id} [aria-checked="true"]`);return b?b.dataset.v:'';};
527
819
  function focusOpener(){const b=(taskFrom&&$(taskFrom))||$('#v-board [data-add]');if(b)b.focus();}
528
820
  function closeNewTask(){if(!taskVeil.classList.contains('open')||adding)return;taskVeil.classList.remove('open');focusOpener();}
529
821
  async function addTask(){
@@ -533,7 +825,7 @@ async function addTask(){
533
825
  adding=true;$('#taskGo').disabled=true;taskError('');
534
826
  let r,body={};
535
827
  try{
536
- r=await fetch('/api/tasks/new?'+pq(),{method:'POST',cache:'no-store',headers:{'Content-Type':'application/json','X-SpecPilot-Token':TOKEN,'If-Match':DATA.tasks.sha256},body:JSON.stringify({description:taskIn.value,section})});
828
+ r=await fetch('/api/tasks/new?'+pq(),{method:'POST',cache:'no-store',headers:{'Content-Type':'application/json','X-SpecPilot-Token':TOKEN,'If-Match':DATA.tasks.sha256},body:JSON.stringify({description:taskIn.value,section,...(shapeOf(section)==='typed'?{priority:taskValue('ntPri'),type:taskValue('ntType')}:{})})});
537
829
  body=await r.json().catch(()=>({}));
538
830
  }catch(e){r=null;}
539
831
  adding=false;$('#taskGo').disabled=false;
@@ -541,7 +833,7 @@ async function addTask(){
541
833
  if(p!==PROJECT)return;
542
834
  if(r.status===200){
543
835
  taskVeil.classList.remove('open');
544
- await apply(body.specs,['.specs/planning/tasks.md']);
836
+ wrote(['.specs/planning/tasks.md'],body.specs);await apply(body.specs,['.specs/planning/tasks.md']);
545
837
  focusOpener(); // what closing the inspector returns to
546
838
  openTask(section,body.index);
547
839
  const el=$(`#v-board .row[data-col="${section}"][data-i="${body.index}"]`);if(el)el.scrollIntoView({block:'nearest'});
@@ -567,10 +859,12 @@ function archGates(){
567
859
  const b=DATA.project.branch,a=DATA.tasks.archive,n=DATA.tasks.completed.length,out=[];
568
860
  if(!b)out.push({key:'branch',text:'No git branch.'});
569
861
  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.`});
862
+ else out.push({key:'branch:'+b,warn:true,text:`On branch ${b}. Archive is recommended only on the default branch after merging. ${branchRisk('The archive')} Archive on this branch anyway.`});
571
863
  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
864
  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
865
  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.`});
866
+ const act=recentActivity();
867
+ if(act)out.push({key:'activity',warn:true,text:`${act}: an agent or editor may still be working on the specs. If it saves planning/tasks.md from a copy it read before the archive, the archive is lost; if it edits after, its edit can fail or land on the wrong row because the rows moved under it. Archive anyway.`});
574
868
  return out;
575
869
  }
576
870
  /* Draw the gates from the latest payload; a tick stays on a gate still shown under the same key (a redraw while open). */
@@ -603,7 +897,7 @@ async function archiveCompleted(){
603
897
  if(p!==PROJECT)return;
604
898
  if(r.status===200){
605
899
  archVeil.classList.remove('open');
606
- await apply(body.specs,['.specs/planning/tasks.md','.specs/planning/tasks-archive.md']);
900
+ wrote(['.specs/planning/tasks.md','.specs/planning/tasks-archive.md'],body.specs);await apply(body.specs,['.specs/planning/tasks.md','.specs/planning/tasks-archive.md']);
607
901
  focusArchive();
608
902
  toast(`Moved ${body.linesMoved} rows from ## Completed to planning/tasks-archive.md`);
609
903
  return;
@@ -747,6 +1041,7 @@ async function redraw(paths){
747
1041
  let d;const p=PROJECT;
748
1042
  try{const r=await fetch('/api/specs?'+pq(),{cache:'no-store'});if(!r.ok)return;d=await r.json();}catch(e){return;} // server gone: keep what is shown
749
1043
  if(p!==PROJECT)return; // switched projects meanwhile
1044
+ noteActivity(paths,d);
750
1045
  // The poller's echo of a move this page just made: same tasks.md hash, nothing to redraw.
751
1046
  if(paths&&paths.length&&paths.every(p=>p==='.specs/planning/tasks.md')&&DATA&&DATA.tasks&&d.tasks&&d.tasks.sha256===DATA.tasks.sha256)return;
752
1047
  await apply(d,paths);document.documentElement.dataset.rev=+(document.documentElement.dataset.rev||0)+1; // live reloads drawn: the browser tests wait on it
@@ -801,6 +1096,7 @@ async function switchProject(n,keepRoute){
801
1096
  }
802
1097
  /* Draw project PROJECT from payload d: the tail of a switch, also used with the payload an open returns (BL-067). */
803
1098
  function showProject(d,keepRoute){
1099
+ busyVeil.classList.remove('open');busyGo=null;busyFrom=null; // BL-127: a dialog never outlives its project
804
1100
  Object.keys(fileCache).forEach(k=>{delete fileCache[k];});secShown.clear();
805
1101
  DATA=d;selected=null;setRegenNote([]);
806
1102
  renderAll();listen();
package/ui/index.html CHANGED
@@ -59,6 +59,8 @@
59
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>
60
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>
61
61
  <symbol id="i-x" viewBox="0 0 24 24"><path d="M6 6l12 12M18 6L6 18"/></symbol>
62
+ <symbol id="i-warn" viewBox="0 0 24 24"><path d="M12 4l9 16H3z"/><path d="M12 10v4M12 17h.01"/></symbol>
63
+ <symbol id="i-info" viewBox="0 0 24 24"><circle cx="12" cy="12" r="9"/><path d="M12 11v5M12 8h.01"/></symbol>
62
64
  <symbol id="i-file" viewBox="0 0 24 24"><path d="M6 3h8l4 4v14H6z"/><path d="M14 3v4h4"/></symbol>
63
65
  <symbol id="i-play" viewBox="0 0 24 24"><path d="M7 5l12 7-12 7z"/></symbol>
64
66
  <symbol id="i-git" viewBox="0 0 24 24"><circle cx="6" cy="6" r="2.5"/><circle cx="6" cy="18" r="2.5"/><circle cx="18" cy="8" r="2.5"/><path d="M6 8.5v7M18 10.5c0 4-12 2-12 5"/></symbol>
@@ -146,6 +148,7 @@
146
148
  <!-- TASKS: the rows of planning/tasks.md, from readSpecs() -->
147
149
  <section class="view on" id="v-board">
148
150
  <div class="gl" id="gRaw" hidden></div>
151
+ <div class="gl" id="gHead" hidden role="status" aria-live="polite"></div>
149
152
  <div class="gl" id="gConv"></div>
150
153
  <div id="boardMode" class="board"></div>
151
154
  </section>
@@ -238,6 +241,7 @@
238
241
  <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>
239
242
  <form class="sb" id="taskForm" autocomplete="off">
240
243
  <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>
244
+ <div class="tf" id="taskFields" hidden></div>
241
245
  <p class="err" id="taskErr" role="alert" hidden></p>
242
246
  </form>
243
247
  <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>
@@ -253,6 +257,13 @@
253
257
  <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
258
  </div></div>
255
259
 
260
+ <!-- BUSY (BL-127): a move while on a branch or while something else writes .specs/; what could happen, Cancel or Move anyway -->
261
+ <div class="veil" id="busyVeil"><div class="sheet task" role="alertdialog" aria-modal="true" aria-labelledby="busyTitle" aria-describedby="busyBody" tabindex="-1">
262
+ <div class="sh"><div><h2 id="busyTitle">Move while work is in progress?</h2></div></div>
263
+ <div class="sb"><div class="gl"><div class="box" id="busyBody"></div></div></div>
264
+ <div class="sf"><button type="button" class="btn" id="busyCancel">Cancel</button><button type="button" class="btn pri" id="busyGo">Move anyway</button></div>
265
+ </div></div>
266
+
256
267
  <!-- PALETTE -->
257
268
  <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
269
  <!-- CARD MENU (BL-TB-11): a task card's actions, built from the move table of /api/specs -->