specpilot 2.3.0 → 2.4.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 (37) hide show
  1. package/README.md +7 -5
  2. package/dist/cli.js +2 -1
  3. package/dist/cli.js.map +1 -1
  4. package/dist/commands/archive.d.ts.map +1 -1
  5. package/dist/commands/archive.js +5 -1
  6. package/dist/commands/archive.js.map +1 -1
  7. package/dist/commands/serve.d.ts +1 -0
  8. package/dist/commands/serve.d.ts.map +1 -1
  9. package/dist/commands/serve.js +5 -3
  10. package/dist/commands/serve.js.map +1 -1
  11. package/dist/utils/slashCommandGenerator.d.ts.map +1 -1
  12. package/dist/utils/slashCommandGenerator.js +117 -26
  13. package/dist/utils/slashCommandGenerator.js.map +1 -1
  14. package/dist/utils/specArchiver.d.ts +22 -0
  15. package/dist/utils/specArchiver.d.ts.map +1 -1
  16. package/dist/utils/specArchiver.js +121 -26
  17. package/dist/utils/specArchiver.js.map +1 -1
  18. package/dist/utils/specReader.d.ts +21 -0
  19. package/dist/utils/specReader.d.ts.map +1 -1
  20. package/dist/utils/specReader.js +26 -3
  21. package/dist/utils/specReader.js.map +1 -1
  22. package/dist/utils/specServer.d.ts +5 -0
  23. package/dist/utils/specServer.d.ts.map +1 -1
  24. package/dist/utils/specServer.js +89 -3
  25. package/dist/utils/specServer.js.map +1 -1
  26. package/dist/utils/specValidator.d.ts +3 -1
  27. package/dist/utils/specValidator.d.ts.map +1 -1
  28. package/dist/utils/specValidator.js +44 -11
  29. package/dist/utils/specValidator.js.map +1 -1
  30. package/dist/utils/taskMover.d.ts +50 -0
  31. package/dist/utils/taskMover.d.ts.map +1 -0
  32. package/dist/utils/taskMover.js +131 -0
  33. package/dist/utils/taskMover.js.map +1 -0
  34. package/package.json +1 -1
  35. package/ui/app.css +7 -0
  36. package/ui/app.js +70 -2
  37. package/ui/index.html +1 -0
@@ -0,0 +1,50 @@
1
+ /** The write allowlist: exactly one file, separate from what the server may read. */
2
+ export declare const WRITABLE_TASKS_FILE = ".specs/planning/tasks.md";
3
+ export type MovableSection = 'backlog' | 'currentSprint';
4
+ /** The section headings as tasks.md writes them (what readSpecs() matches). */
5
+ export declare const SECTION_HEADINGS: {
6
+ readonly backlog: "Backlog";
7
+ readonly currentSprint: "Current Sprint";
8
+ readonly completed: "Completed";
9
+ };
10
+ export interface TaskMove {
11
+ id: string;
12
+ toSection: MovableSection;
13
+ /** The row's position in `toSection` after the move, 0-based. */
14
+ toIndex: number;
15
+ }
16
+ export type PlanResult = {
17
+ ok: true;
18
+ content: string;
19
+ from: MovableSection;
20
+ fromIndex: number;
21
+ noop: boolean;
22
+ } | {
23
+ ok: false;
24
+ error: string;
25
+ };
26
+ export declare const sha256: (data: string | Buffer) => string;
27
+ /** Check a request body's shape; returns a plain-words problem or null. */
28
+ export declare function moveShapeError(body: unknown): string | null;
29
+ /** Work out a move on tasks.md content in memory: the new content, or why it cannot be done. */
30
+ export declare function planMove(content: string, move: TaskMove): PlanResult;
31
+ export type MoveOutcome = {
32
+ status: 200;
33
+ sha256: string;
34
+ from: MovableSection;
35
+ fromIndex: number;
36
+ } | {
37
+ status: 409;
38
+ error: string;
39
+ } | {
40
+ status: 422;
41
+ error: string;
42
+ };
43
+ export declare const STALE_ERROR = "planning/tasks.md changed on disk since this page loaded. The move was not made.";
44
+ /**
45
+ * Apply a move to tasks.md on disk if `ifMatch` is its current sha256. Synchronous from the first
46
+ * read to the rename, so nothing else in this process runs in between; the caller's lock queues
47
+ * requests. Writes a temp file in the same folder, fsyncs it, keeps the mode, renames it over.
48
+ */
49
+ export declare function moveTask(root: string, move: TaskMove, ifMatch: string): MoveOutcome;
50
+ //# sourceMappingURL=taskMover.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"taskMover.d.ts","sourceRoot":"","sources":["../../src/utils/taskMover.ts"],"names":[],"mappings":"AASA,qFAAqF;AACrF,eAAO,MAAM,mBAAmB,6BAA6B,CAAC;AAE9D,MAAM,MAAM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,WAAW,CAkDnF"}
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.STALE_ERROR = exports.sha256 = exports.SECTION_HEADINGS = exports.WRITABLE_TASKS_FILE = void 0;
4
+ exports.moveShapeError = moveShapeError;
5
+ exports.planMove = planMove;
6
+ exports.moveTask = moveTask;
7
+ const fs_1 = require("fs");
8
+ const crypto_1 = require("crypto");
9
+ const path_1 = require("path");
10
+ const specReader_1 = require("./specReader");
11
+ const specValidator_1 = require("./specValidator");
12
+ // The one writer behind `specpilot serve` (BL-053, ARCH-003.18, ARCH-004.36). A move removes one
13
+ // line of tasks.md and inserts the identical line elsewhere; every other byte stays as it was.
14
+ /** The write allowlist: exactly one file, separate from what the server may read. */
15
+ exports.WRITABLE_TASKS_FILE = '.specs/planning/tasks.md';
16
+ /** The section headings as tasks.md writes them (what readSpecs() matches). */
17
+ exports.SECTION_HEADINGS = { backlog: 'Backlog', currentSprint: 'Current Sprint', completed: 'Completed' };
18
+ const sha256 = (data) => (0, crypto_1.createHash)('sha256').update(data).digest('hex');
19
+ exports.sha256 = sha256;
20
+ /** Check a request body's shape; returns a plain-words problem or null. */
21
+ function moveShapeError(body) {
22
+ const b = body;
23
+ if (!b || typeof b !== 'object')
24
+ return 'The request must be a JSON object with id, toSection and toIndex.';
25
+ if (typeof b.id !== 'string' || !b.id)
26
+ return 'The request has no task ID.';
27
+ if (b.toSection !== 'backlog' && b.toSection !== 'currentSprint')
28
+ return 'Tasks can only be moved to Backlog or Current Sprint.';
29
+ if (!Number.isInteger(b.toIndex) || b.toIndex < 0)
30
+ return 'The position must be a whole number, 0 or more.';
31
+ return null;
32
+ }
33
+ /** Work out a move on tasks.md content in memory: the new content, or why it cannot be done. */
34
+ function planMove(content, move) {
35
+ const lines = content.split('\n');
36
+ const where = (0, specReader_1.taskRowLines)(content);
37
+ const hits = ['backlog', 'currentSprint', 'completed'].flatMap(sec => (where[sec]?.rows ?? []).map((r, i) => ({ sec, i, line: r.line })).filter((_, i) => where[sec].rows[i].id === move.id));
38
+ if (!hits.length)
39
+ return { ok: false, error: `No task row in planning/tasks.md has the ID ${move.id}.` };
40
+ if (hits.length > 1)
41
+ return { ok: false, error: `${move.id} is on more than one row in planning/tasks.md, so SpecPilot cannot tell which to move.` };
42
+ const hit = hits[0];
43
+ if (hit.sec === 'completed')
44
+ return { ok: false, error: 'Completed rows cannot be moved.' };
45
+ const from = hit.sec;
46
+ const target = where[move.toSection];
47
+ if (!target)
48
+ return { ok: false, error: `planning/tasks.md has no ## ${exports.SECTION_HEADINGS[move.toSection]} section.` };
49
+ if (target.separator === null)
50
+ return { ok: false, error: `${exports.SECTION_HEADINGS[move.toSection]} has no table yet.` };
51
+ const others = target.rows.filter(r => r.line !== hit.line);
52
+ if (move.toIndex > others.length) {
53
+ return { ok: false, error: `Position ${move.toIndex} is past the end of ${exports.SECTION_HEADINGS[move.toSection]}, which would have ${others.length + 1} rows.` };
54
+ }
55
+ if (from === move.toSection && move.toIndex === hit.i)
56
+ return { ok: true, content, from, fromIndex: hit.i, noop: true };
57
+ // Insert before the row now at toIndex, or right after the last row (or the separator).
58
+ const at = move.toIndex < others.length ? others[move.toIndex].line : (others.length ? others[others.length - 1].line : target.separator) + 1;
59
+ const last = lines.length - 1; // with a trailing newline, lines[last] is '' and never a row
60
+ if (hit.line === last || at > last) {
61
+ return { ok: false, error: `This move would change which line ends the file, because planning/tasks.md has no line break after its last line. Add one and try again.` };
62
+ }
63
+ const out = lines.slice();
64
+ const [row] = out.splice(hit.line, 1);
65
+ out.splice(at > hit.line ? at - 1 : at, 0, row);
66
+ return { ok: true, content: out.join('\n'), from, fromIndex: hit.i, noop: false };
67
+ }
68
+ exports.STALE_ERROR = 'planning/tasks.md changed on disk since this page loaded. The move was not made.';
69
+ /**
70
+ * Apply a move to tasks.md on disk if `ifMatch` is its current sha256. Synchronous from the first
71
+ * read to the rename, so nothing else in this process runs in between; the caller's lock queues
72
+ * requests. Writes a temp file in the same folder, fsyncs it, keeps the mode, renames it over.
73
+ */
74
+ function moveTask(root, move, ifMatch) {
75
+ const file = (0, path_1.join)(root, exports.WRITABLE_TASKS_FILE);
76
+ let st;
77
+ try {
78
+ st = (0, fs_1.lstatSync)(file);
79
+ }
80
+ catch {
81
+ return { status: 422, error: 'planning/tasks.md does not exist.' };
82
+ }
83
+ if (st.isSymbolicLink())
84
+ return { status: 422, error: 'planning/tasks.md is a symbolic link, and SpecPilot will not replace it with a regular file.' };
85
+ const before = (0, fs_1.readFileSync)(file);
86
+ if ((0, exports.sha256)(before) !== ifMatch)
87
+ return { status: 409, error: exports.STALE_ERROR };
88
+ const content = before.toString('utf-8');
89
+ // Decoding and re-encoding must give back the same bytes, or the write would alter lines it never moved.
90
+ if (!Buffer.from(content, 'utf-8').equals(before)) {
91
+ return { status: 422, error: 'planning/tasks.md contains bytes that are not valid UTF-8, so SpecPilot cannot move a line without changing others.' };
92
+ }
93
+ const plan = planMove(content, move);
94
+ if (!plan.ok)
95
+ return { status: 422, error: plan.error };
96
+ if (plan.noop)
97
+ return { status: 200, sha256: ifMatch, from: plan.from, fromIndex: plan.fromIndex };
98
+ const was = new Set((0, specValidator_1.tasksChecks)(content));
99
+ const introduced = (0, specValidator_1.tasksChecks)(plan.content).filter(m => !was.has(m));
100
+ if (introduced.length)
101
+ return { status: 422, error: `The move was not made, because \`specpilot validate\` would then report: ${introduced.join(' ')}` };
102
+ const tmp = (0, path_1.join)((0, path_1.dirname)(file), `.tasks.md.${(0, crypto_1.randomBytes)(6).toString('hex')}.tmp`);
103
+ try {
104
+ const fd = (0, fs_1.openSync)(tmp, 'wx', st.mode & 0o777);
105
+ try {
106
+ (0, fs_1.writeSync)(fd, plan.content);
107
+ (0, fs_1.fsyncSync)(fd);
108
+ }
109
+ finally {
110
+ (0, fs_1.closeSync)(fd);
111
+ }
112
+ (0, fs_1.chmodSync)(tmp, st.mode & 0o7777);
113
+ // Last look: an editor may have saved while we were writing.
114
+ if ((0, exports.sha256)((0, fs_1.readFileSync)(file)) !== ifMatch) {
115
+ (0, fs_1.unlinkSync)(tmp);
116
+ return { status: 409, error: exports.STALE_ERROR };
117
+ }
118
+ (0, fs_1.renameSync)(tmp, file);
119
+ }
120
+ catch (err) {
121
+ try {
122
+ (0, fs_1.unlinkSync)(tmp);
123
+ }
124
+ catch {
125
+ /* never created, or already renamed */
126
+ }
127
+ throw err;
128
+ }
129
+ return { status: 200, sha256: (0, exports.sha256)(plan.content), from: plan.from, fromIndex: plan.fromIndex };
130
+ }
131
+ //# sourceMappingURL=taskMover.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"taskMover.js","sourceRoot":"","sources":["../../src/utils/taskMover.ts"],"names":[],"mappings":";;;AA+BA,wCAOC;AAGD,4BA+BC;AAcD,4BAkDC;AAxID,2BAA2H;AAC3H,mCAAiD;AACjD,+BAAqC;AACrC,6CAA4C;AAC5C,mDAA8C;AAE9C,iGAAiG;AACjG,+FAA+F;AAE/F,qFAAqF;AACxE,QAAA,mBAAmB,GAAG,0BAA0B,CAAC;AAI9D,+EAA+E;AAClE,QAAA,gBAAgB,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,gBAAgB,EAAE,SAAS,EAAE,WAAW,EAAW,CAAC;AAalH,MAAM,MAAM,GAAG,CAAC,IAAqB,EAAU,EAAE,CAAC,IAAA,mBAAU,EAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAA5F,QAAA,MAAM,UAAsF;AAEzG,2EAA2E;AAC3E,SAAgB,cAAc,CAAC,IAAa;IAC1C,MAAM,CAAC,GAAG,IAAgC,CAAC;IAC3C,IAAI,CAAC,CAAC,IAAI,OAAO,CAAC,KAAK,QAAQ;QAAE,OAAO,mEAAmE,CAAC;IAC5G,IAAI,OAAO,CAAC,CAAC,EAAE,KAAK,QAAQ,IAAI,CAAC,CAAC,CAAC,EAAE;QAAE,OAAO,6BAA6B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AAC;YACH,IAAA,eAAU,EAAC,GAAG,CAAC,CAAC;QAClB,CAAC;QAAC,MAAM,CAAC;YACP,uCAAuC;QACzC,CAAC;QACD,MAAM,GAAG,CAAC;IACZ,CAAC;IACD,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,IAAA,cAAM,EAAC,IAAI,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC;AACnG,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "specpilot",
3
- "version": "2.3.0",
3
+ "version": "2.4.0",
4
4
  "description": "A CLI tool for initializing specification-driven development projects with flexible, production-ready structures.",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
package/ui/app.css CHANGED
@@ -297,3 +297,10 @@ input.txt{width:100%}
297
297
  /* Group headers in the content and inspector carry file text (section headings, paths):
298
298
  show it as written instead of uppercasing it. Sidebar group labels stay uppercase. */
299
299
  .content .gl .gh,.insp .gl .gh{text-transform:none;letter-spacing:.02em}
300
+ /* Task moves (BL-053): drag state, drop target, and the toast's Undo. */
301
+ .row[draggable="true"]{cursor:grab}
302
+ .row[draggable="true"]:active{cursor:grabbing}
303
+ .row.drag{opacity:.4}
304
+ .gl.drop .box{border-color:var(--focus);box-shadow:inset 0 0 0 1px var(--focus)}
305
+ .toast.has-action.show{pointer-events:auto}
306
+ .toast .tact{margin-left:12px;color:var(--ground);font-weight:600;text-decoration:underline;text-underline-offset:2px}
package/ui/app.js CHANGED
@@ -4,7 +4,13 @@
4
4
  (function(){
5
5
  const $=(s,r=document)=>r.querySelector(s), $$=(s,r=document)=>[...r.querySelectorAll(s)];
6
6
  const toastEl=$('#toast');let toastT;
7
- const toast=m=>{toastEl.textContent=m;toastEl.classList.add('show');clearTimeout(toastT);toastT=setTimeout(()=>toastEl.classList.remove('show'),2600);};
7
+ const toast=(m,action)=>{
8
+ toastEl.textContent=m;toastEl.classList.toggle('has-action',!!action);
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);};
11
+ /* Task moves (BL-053) are on only when the server put a token in the page (not with --read-only). */
12
+ const TOKEN=(document.querySelector('meta[name="specpilot-token"]')||{}).content||null;
13
+ const MOVABLE={backlog:true,currentSprint:true};
8
14
  const chev='<svg class="ico chev" aria-hidden="true" focusable="false"><use href="#i-chev"/></svg>';
9
15
 
10
16
  /* theme: dark by default, light is a per-viewer toggle */
@@ -128,7 +134,8 @@ function rowsOf(col){
128
134
  return col==='completed'?items.reverse():items;
129
135
  }
130
136
  function taskRow({t,i},col){
131
- return `<button type="button" class="row act" data-col="${col}" data-i="${i}">
137
+ const mv=TOKEN&&MOVABLE[col];
138
+ 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"':''}>
132
139
  <span class="st ${DOT[col]}" aria-hidden="true"></span>
133
140
  <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>
134
141
  <div class="trail">${chev}</div>
@@ -175,6 +182,7 @@ function openInsp(quiet){insp.classList.add('open');insp.setAttribute('aria-hidd
175
182
  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;}}
176
183
  function bind(){
177
184
  $$('#v-board .row[data-col]').forEach(r=>r.onclick=()=>openTask(r.dataset.col,+r.dataset.i));
185
+ if(TOKEN)bindMoves();
178
186
  $$('[data-more]').forEach(b=>b.onclick=e=>{e.stopPropagation();if(b.dataset.more==='completed')showAllDone=true;else showAllBacklog=true;renderTasks();});
179
187
  $$('[data-disc]').forEach(b=>b.onclick=e=>{e.stopPropagation();const g=$('#gDone');g.classList.toggle('closed');b.setAttribute('aria-expanded',!g.classList.contains('closed'));});
180
188
  }
@@ -274,6 +282,60 @@ document.addEventListener('keydown',e=>{
274
282
  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();}
275
283
  });
276
284
 
285
+ /* ---------------- task moves (BL-053) ----------------
286
+ A move is one line of planning/tasks.md cut and pasted unchanged; the server does it and
287
+ answers with the new file hash and the fresh payload. Completed rows never move. */
288
+ let dragging=null,moving=false;
289
+ function bindMoves(){
290
+ $$('#v-board .row[draggable="true"]').forEach(r=>{
291
+ 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');};
292
+ r.ondragend=()=>{r.classList.remove('drag');dragging=null;$$('.gl.drop').forEach(g=>g.classList.remove('drop'));};
293
+ r.onkeydown=e=>{
294
+ if(!e.altKey||e.metaKey||e.ctrlKey)return;
295
+ const col=r.dataset.col,i=+r.dataset.i,n=DATA.tasks[col].length;
296
+ 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];
297
+ if(go2===undefined)return;
298
+ e.preventDefault();
299
+ if(go2)move(col,i,go2[0],go2[1]);
300
+ };
301
+ });
302
+ $$('#v-board .gl[data-col="backlog"],#v-board .gl[data-col="currentSprint"]').forEach(g=>{
303
+ g.ondragover=e=>{if(!dragging)return;e.preventDefault();e.dataTransfer.dropEffect='move';g.classList.add('drop');};
304
+ g.ondragleave=e=>{if(!g.contains(e.relatedTarget))g.classList.remove('drop');};
305
+ g.ondrop=e=>{
306
+ if(!dragging)return;e.preventDefault();g.classList.remove('drop');
307
+ const to=g.dataset.col,src=dragging;dragging=null;
308
+ // Position among the target's rows once the dragged row is out of the way.
309
+ const others=DATA.tasks[to].map((_,j)=>j).filter(j=>!(to===src.col&&j===src.i));
310
+ const over=e.target.closest&&e.target.closest('.row[data-col]');
311
+ let at=others.length;
312
+ 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);}}
313
+ move(src.col,src.i,to,at);
314
+ };
315
+ });
316
+ }
317
+ async function move(col,i,toSection,toIndex,isUndo){
318
+ const t=DATA.tasks[col][i];if(!t||moving)return;
319
+ moving=true;
320
+ let r,body={};
321
+ try{
322
+ r=await fetch('/api/tasks/move',{method:'POST',cache:'no-store',headers:{'Content-Type':'application/json','X-SpecPilot-Token':TOKEN,'If-Match':DATA.tasks.sha256},body:JSON.stringify({id:t.id,toSection,toIndex})});
323
+ body=await r.json().catch(()=>({}));
324
+ }catch(e){moving=false;toast('The server did not answer. Nothing was moved.');return;}
325
+ moving=false;
326
+ if(r.status===200){
327
+ if(toSection==='backlog'&&toIndex>=6)showAllBacklog=true;
328
+ await apply(body.specs,['.specs/planning/tasks.md']);
329
+ const j=DATA.tasks[toSection].findIndex(x=>x.id===t.id);
330
+ const el=$(`${mode==='board'?'#boardMode':'#listMode'} .row[data-col="${toSection}"][data-i="${j}"]`);if(el)el.focus();
331
+ 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`;
332
+ 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);}});
333
+ }else if(r.status===409){
334
+ if(body.specs)await apply(body.specs,null);
335
+ toast(body.error||'planning/tasks.md changed on disk since this page loaded. The move was not made.');
336
+ }else toast(body.error||`The move was not made (HTTP ${r.status}).`);
337
+ }
338
+
277
339
  /* ---------------- live reload (BL-052) ----------------
278
340
  On a change event: re-fetch, redraw in place. Route, scroll, open inspector, selected row
279
341
  and focus stay where they were. If the server is gone, the last content stays on screen. */
@@ -303,6 +365,12 @@ function refresh(paths){refreshing=refreshing.then(()=>redraw(paths)).catch(()=>
303
365
  async function redraw(paths){
304
366
  let d;
305
367
  try{const r=await fetch('/api/specs',{cache:'no-store'});if(!r.ok)return;d=await r.json();}catch(e){return;} // server gone: keep what is shown
368
+ // The poller's echo of a move this page just made: same tasks.md hash, nothing to redraw.
369
+ if(paths&&paths.length&&paths.every(p=>p==='.specs/planning/tasks.md')&&DATA&&DATA.tasks&&d.tasks&&d.tasks.sha256===DATA.tasks.sha256)return;
370
+ await apply(d,paths);
371
+ }
372
+ /* Draw a fresh /api/specs payload in place: same route, scroll, inspector, selection and focus. */
373
+ async function apply(d,paths){
306
374
  (paths||Object.keys(fileCache)).forEach(p=>{delete fileCache[p];});
307
375
  const key=focusKey(document.activeElement);
308
376
  const scroll=$('#content').scrollTop,ib0=insp.querySelector('.ib2'),inspScroll=ib0?ib0.scrollTop:0;
package/ui/index.html CHANGED
@@ -5,6 +5,7 @@
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1">
6
6
  <title>SpecPilot Local</title>
7
7
  <meta name="theme-color" content="#0f172a">
8
+ <!-- specpilot-token -->
8
9
  <link rel="icon" href="/assets/favicon.svg" type="image/svg+xml">
9
10
  <link rel="stylesheet" href="/assets/app.css">
10
11
  <script src="/assets/md.js" defer></script>