specpilot 2.2.4 → 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.
- package/README.md +25 -0
- package/dist/cli.js +10 -0
- package/dist/cli.js.map +1 -1
- package/dist/commands/archive.d.ts.map +1 -1
- package/dist/commands/archive.js +5 -1
- package/dist/commands/archive.js.map +1 -1
- package/dist/commands/serve.d.ts +9 -0
- package/dist/commands/serve.d.ts.map +1 -0
- package/dist/commands/serve.js +68 -0
- package/dist/commands/serve.js.map +1 -0
- package/dist/utils/slashCommandGenerator.d.ts.map +1 -1
- package/dist/utils/slashCommandGenerator.js +117 -26
- package/dist/utils/slashCommandGenerator.js.map +1 -1
- package/dist/utils/specArchiver.d.ts +22 -0
- package/dist/utils/specArchiver.d.ts.map +1 -1
- package/dist/utils/specArchiver.js +121 -26
- package/dist/utils/specArchiver.js.map +1 -1
- package/dist/utils/specPaths.d.ts +26 -0
- package/dist/utils/specPaths.d.ts.map +1 -0
- package/dist/utils/specPaths.js +92 -0
- package/dist/utils/specPaths.js.map +1 -0
- package/dist/utils/specPoller.d.ts +22 -0
- package/dist/utils/specPoller.d.ts.map +1 -0
- package/dist/utils/specPoller.js +119 -0
- package/dist/utils/specPoller.js.map +1 -0
- package/dist/utils/specReader.d.ts +21 -0
- package/dist/utils/specReader.d.ts.map +1 -1
- package/dist/utils/specReader.js +26 -3
- package/dist/utils/specReader.js.map +1 -1
- package/dist/utils/specServer.d.ts +65 -0
- package/dist/utils/specServer.d.ts.map +1 -0
- package/dist/utils/specServer.js +345 -0
- package/dist/utils/specServer.js.map +1 -0
- package/dist/utils/specValidator.d.ts +3 -1
- package/dist/utils/specValidator.d.ts.map +1 -1
- package/dist/utils/specValidator.js +44 -11
- package/dist/utils/specValidator.js.map +1 -1
- package/dist/utils/taskMover.d.ts +50 -0
- package/dist/utils/taskMover.d.ts.map +1 -0
- package/dist/utils/taskMover.js +131 -0
- package/dist/utils/taskMover.js.map +1 -0
- package/package.json +2 -3
- package/ui/app.css +306 -0
- package/ui/app.js +408 -0
- package/ui/favicon.svg +25 -0
- package/ui/index.html +172 -0
- package/ui/md.js +81 -0
- package/ui/route.js +25 -0
package/ui/app.js
ADDED
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
/* SpecPilot Local, read-only (BL-051). Ported from the approved mockup; every string a view
|
|
2
|
+
shows about the project comes from GET /api/specs (readSpecs() output) or GET /api/file
|
|
3
|
+
(the file itself). Views may group and order; they never reword. */
|
|
4
|
+
(function(){
|
|
5
|
+
const $=(s,r=document)=>r.querySelector(s), $$=(s,r=document)=>[...r.querySelectorAll(s)];
|
|
6
|
+
const toastEl=$('#toast');let toastT;
|
|
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};
|
|
14
|
+
const chev='<svg class="ico chev" aria-hidden="true" focusable="false"><use href="#i-chev"/></svg>';
|
|
15
|
+
|
|
16
|
+
/* theme: dark by default, light is a per-viewer toggle */
|
|
17
|
+
let theme=null;try{theme=localStorage.getItem('sp-theme');}catch(e){}
|
|
18
|
+
function setMeta(light){const m=document.querySelector('meta[name=theme-color]');if(m)m.content=light?'#f8fafc':'#0f172a';}
|
|
19
|
+
if(theme==='light'){document.documentElement.setAttribute('data-theme','light');setMeta(true);}
|
|
20
|
+
$('#themeBtn').onclick=()=>{const light=document.documentElement.getAttribute('data-theme')==='light';if(light)document.documentElement.removeAttribute('data-theme');else document.documentElement.setAttribute('data-theme','light');setMeta(!light);try{light?localStorage.removeItem('sp-theme'):localStorage.setItem('sp-theme','light');}catch(e){}toast('Appearance: '+(light?'dark':'light'));};
|
|
21
|
+
|
|
22
|
+
/* ---------------- data: fetched, never embedded ---------------- */
|
|
23
|
+
let DATA=null;
|
|
24
|
+
const fileCache={};
|
|
25
|
+
async function getText(p){
|
|
26
|
+
if(p in fileCache)return fileCache[p];
|
|
27
|
+
const r=await fetch('/api/file?p='+encodeURIComponent(p),{cache:'no-store'});
|
|
28
|
+
if(!r.ok)throw Object.assign(new Error(p+': HTTP '+r.status),{status:r.status});
|
|
29
|
+
return fileCache[p]=await r.text();
|
|
30
|
+
}
|
|
31
|
+
function showErr(msg){const e=$('#loadErr');e.textContent=msg;e.hidden=false;}
|
|
32
|
+
|
|
33
|
+
/* ---------------- project: only the one being served ---------------- */
|
|
34
|
+
function initials(n){const w=String(n).split(/[^A-Za-z0-9]+/).filter(Boolean);
|
|
35
|
+
if(!w.length)return '??';
|
|
36
|
+
if(w.length>1)return (w[0][0]+w[1][0]).toUpperCase();
|
|
37
|
+
return w[0].slice(0,2).toUpperCase();}
|
|
38
|
+
function renderProject(){
|
|
39
|
+
const p=DATA.project, name=p.name!==null?p.name:p.root, where=p.root+(p.branch?' · '+p.branch:'');
|
|
40
|
+
$('#projList').innerHTML=`<button class="tile blue cur" data-tip="${esc(name)}" data-path="${esc(where)}" aria-label="${esc(name)}" aria-current="true"><span aria-hidden="true">${esc(initials(name))}</span></button>`;
|
|
41
|
+
$('#curGrp').textContent=name;$('#curGrp').title=p.root;
|
|
42
|
+
$('#curBranch').textContent=p.branch||'';
|
|
43
|
+
$('#subName').textContent=name;$('#subPath').textContent=where;
|
|
44
|
+
$('#footAddr').textContent=location.host;$('#footVer').textContent='v'+p.specpilotVersion;
|
|
45
|
+
document.title=name+' · SpecPilot Local';
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/* ---------------- views ---------------- */
|
|
49
|
+
const VIEWS={board:'Tasks',explorer:'Explorer',security:'Security',instructions:'Instructions',commands:'Commands',skills:'Skills'};
|
|
50
|
+
const TITLES={'planning/roadmap.md':'Roadmap','project/requirements.md':'Requirements','architecture/architecture.md':'Architecture','quality/tests.md':'Tests'};
|
|
51
|
+
const NAV=[['board'],['file','planning/roadmap.md'],['file','project/requirements.md'],['explorer'],['file','architecture/architecture.md'],['file','quality/tests.md'],['security'],['instructions'],['commands'],['skills']];
|
|
52
|
+
let curView='board',curFile='';
|
|
53
|
+
function syncNav(){
|
|
54
|
+
$$('.src .srow').forEach(b=>{
|
|
55
|
+
const on=b.dataset.v==='file'?(curView==='file'&&b.dataset.f===curFile):(b.dataset.v===curView);
|
|
56
|
+
b.classList.toggle('on',on);b.setAttribute('aria-current',on?'page':'false');});
|
|
57
|
+
}
|
|
58
|
+
function go(v,keep,sub){
|
|
59
|
+
if(v==='file'){if(!DATA||!sub)v='board';else curFile=sub;}
|
|
60
|
+
else if(!VIEWS[v])v='board';
|
|
61
|
+
curView=v;
|
|
62
|
+
$$('.content>.view').forEach(e=>e.classList.toggle('on',e.id==='v-'+v));
|
|
63
|
+
syncNav();
|
|
64
|
+
$('#title').textContent=v==='file'?(TITLES[sub]||sub):VIEWS[v];
|
|
65
|
+
$('#modeSeg').hidden=v!=='board';
|
|
66
|
+
setNav(false);closeInsp();
|
|
67
|
+
if(v==='file')renderFile(sub);
|
|
68
|
+
if(v==='explorer')renderExplorer();
|
|
69
|
+
if(v==='security')renderSecurity();
|
|
70
|
+
setHash(v,v==='file'?sub:(keep?stateFor(v):null));
|
|
71
|
+
$('#content').scrollTop=0;
|
|
72
|
+
}
|
|
73
|
+
function stateFor(v){return v==='board'?(mode==='board'?'board':null):null}
|
|
74
|
+
/* URL state. Sandboxed frames refuse replaceState with a URL, so fall back to an in-memory hash. */
|
|
75
|
+
let urlOk=true,memHash='';
|
|
76
|
+
try{history.replaceState(null,'',location.href);}catch(e){urlOk=false;}
|
|
77
|
+
try{memHash=location.hash;}catch(e){memHash='';}
|
|
78
|
+
function curHash(){if(!urlOk)return memHash;try{return location.hash;}catch(e){return memHash;}}
|
|
79
|
+
function setHash(v,sub){const h='#'+v+(sub?'/'+sub:'');if(curHash()===h)return;memHash=h;
|
|
80
|
+
if(!urlOk)return;
|
|
81
|
+
try{history.replaceState(null,'',h);}catch(e){urlOk=false;}}
|
|
82
|
+
function route(){
|
|
83
|
+
const r=resolveRoute(curHash(),DATA?DATA.files:{});
|
|
84
|
+
if(r.view==='board'&&r.sub==='board'){mode='board';$$('#modeSeg button').forEach(x=>x.classList.toggle('on',x.dataset.m==='board'));renderTasks();}
|
|
85
|
+
go(r.view,true,r.sub);
|
|
86
|
+
}
|
|
87
|
+
if(urlOk)window.addEventListener('hashchange',route);
|
|
88
|
+
$$('.src .srow[data-v]').forEach(b=>b.onclick=()=>go(b.dataset.v,false,b.dataset.f));
|
|
89
|
+
function setNav(on){const w=$('#win');w.classList.toggle('nav',on);$('#scrim').hidden=!on;$('#menuBtn').setAttribute('aria-expanded',on?'true':'false');}
|
|
90
|
+
$('#menuBtn').onclick=()=>setNav(!$('#win').classList.contains('nav'));
|
|
91
|
+
$('#scrim').onclick=()=>setNav(false);
|
|
92
|
+
|
|
93
|
+
/* ---------------- rail tooltips + rail keys ---------------- */
|
|
94
|
+
let tipEl=null,tipFor=null;
|
|
95
|
+
function tipNode(){if(!tipEl){tipEl=document.createElement('div');tipEl.className='tip';tipEl.setAttribute('role','presentation');document.body.appendChild(tipEl);}return tipEl;}
|
|
96
|
+
function showTip(el){
|
|
97
|
+
if(window.matchMedia('(max-width:900px)').matches)return;
|
|
98
|
+
const label=el.dataset.tip;if(!label)return;
|
|
99
|
+
const t=tipNode();tipFor=el;
|
|
100
|
+
t.innerHTML=esc(label)+(el.dataset.path?`<span class="p">${esc(el.dataset.path)}</span>`:'');
|
|
101
|
+
t.classList.remove('on');t.style.left='-9999px';t.style.top='0px';
|
|
102
|
+
const r=el.getBoundingClientRect(),b=t.getBoundingClientRect();
|
|
103
|
+
let top=Math.round(r.top+r.height/2-b.height/2);
|
|
104
|
+
top=Math.max(8,Math.min(top,window.innerHeight-b.height-8));
|
|
105
|
+
const rail=$('#rail').getBoundingClientRect();
|
|
106
|
+
t.style.left=Math.round(Math.max(r.right,rail.right)+9)+'px';t.style.top=top+'px';
|
|
107
|
+
requestAnimationFrame(()=>t.classList.add('on'));
|
|
108
|
+
}
|
|
109
|
+
function hideTip(){if(tipEl){tipEl.classList.remove('on');tipEl.style.left='-9999px';}tipFor=null;}
|
|
110
|
+
document.addEventListener('mouseover',e=>{const el=e.target.closest&&e.target.closest('#rail [data-tip]');if(el&&el!==tipFor)showTip(el);else if(!el&&tipFor)hideTip();});
|
|
111
|
+
document.addEventListener('focusin',e=>{const el=e.target.closest&&e.target.closest('#rail [data-tip]');el?showTip(el):hideTip();});
|
|
112
|
+
document.addEventListener('focusout',e=>{if(e.target.closest&&e.target.closest('#rail [data-tip]'))hideTip();});
|
|
113
|
+
window.addEventListener('scroll',hideTip,true);window.addEventListener('resize',hideTip);
|
|
114
|
+
$('#rail').addEventListener('keydown',e=>{
|
|
115
|
+
if(e.key!=='ArrowDown'&&e.key!=='ArrowUp'&&e.key!=='Home'&&e.key!=='End')return;
|
|
116
|
+
const tiles=$$('#rail .tile');const i=tiles.indexOf(document.activeElement);if(i<0)return;
|
|
117
|
+
e.preventDefault();
|
|
118
|
+
const n=e.key==='Home'?0:e.key==='End'?tiles.length-1:(i+(e.key==='ArrowDown'?1:-1)+tiles.length)%tiles.length;
|
|
119
|
+
tiles[n].focus();
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
/* ---------------- tasks: the rows of planning/tasks.md ---------------- */
|
|
123
|
+
/* Cells are readSpecs() output, verbatim. Rows are keyed by section and position, never by
|
|
124
|
+
ID: IDs repeat in real files (two rows can share a # and an ID). */
|
|
125
|
+
let mode='list', selected=null, lastFocus=null, showAllBacklog=false, showAllDone=false;
|
|
126
|
+
const insp=$('#insp');
|
|
127
|
+
const COLS={currentSprint:'Current Sprint',backlog:'Backlog',completed:'Completed'};
|
|
128
|
+
const DOT={completed:'green',currentSprint:'orange',backlog:'hollow'};
|
|
129
|
+
function mdi(t){return md(String(t)).replace(/^<p>/,'').replace(/<\/p>$/,'');}
|
|
130
|
+
/* Completed is listed newest first (the file runs oldest first); the others in file order. */
|
|
131
|
+
function rowsOf(col){
|
|
132
|
+
const T=DATA.tasks;if(!T)return [];
|
|
133
|
+
const items=T[col].map((t,i)=>({t,i}));
|
|
134
|
+
return col==='completed'?items.reverse():items;
|
|
135
|
+
}
|
|
136
|
+
function taskRow({t,i},col){
|
|
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"':''}>
|
|
139
|
+
<span class="st ${DOT[col]}" aria-hidden="true"></span>
|
|
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>
|
|
141
|
+
<div class="trail">${chev}</div>
|
|
142
|
+
</button>`;
|
|
143
|
+
}
|
|
144
|
+
function group(col,items,opt){
|
|
145
|
+
opt=opt||{};
|
|
146
|
+
const shown=opt.limit&&!opt.all?items.slice(0,opt.limit):items;
|
|
147
|
+
const more=opt.limit&&!opt.all&&items.length>opt.limit?`<button type="button" class="more" data-more="${col}">Show All ${items.length}</button>`:'';
|
|
148
|
+
const gh=opt.disc
|
|
149
|
+
?`<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>`
|
|
150
|
+
:`<div class="gh">${esc(COLS[col])} <span class="cnt">${items.length}</span>${more}</div>`;
|
|
151
|
+
return gh+`<div class="box">${shown.length?shown.map(x=>taskRow(x,col)).join(''):'<div class="empty">No rows in this section.</div>'}</div>`;
|
|
152
|
+
}
|
|
153
|
+
function renderTasks(){
|
|
154
|
+
const S=rowsOf('currentSprint'),B=rowsOf('backlog'),D=rowsOf('completed');
|
|
155
|
+
$('#gSprint').innerHTML=group('currentSprint',S,{});
|
|
156
|
+
$('#gBacklog').innerHTML=group('backlog',B,{limit:6,all:showAllBacklog});
|
|
157
|
+
$('#gDone').innerHTML=group('completed',D,{disc:true,closed:$('#gDone').classList.contains('closed'),limit:8,all:showAllDone});
|
|
158
|
+
$('#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('');
|
|
159
|
+
$('#listMode').hidden=mode!=='list';$('#boardMode').hidden=mode!=='board';
|
|
160
|
+
const T=DATA.tasks;
|
|
161
|
+
const bad=T?T.malformed:[];
|
|
162
|
+
$('#gRaw').hidden=!bad.length;
|
|
163
|
+
$('#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>`:'';
|
|
164
|
+
$('#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>`:
|
|
165
|
+
(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>');
|
|
166
|
+
bind();
|
|
167
|
+
}
|
|
168
|
+
let inspOpen=null; // {kind:'task',col,i,id} | {kind:'file',path} | null
|
|
169
|
+
function openTask(col,i,quiet){
|
|
170
|
+
const t=DATA.tasks[col][i];if(!t)return;
|
|
171
|
+
if(!quiet)lastFocus=document.activeElement;
|
|
172
|
+
selected=col+':'+i;inspOpen={kind:'task',col,i,id:t.id};
|
|
173
|
+
$$('.row.sel').forEach(r=>r.classList.remove('sel'));
|
|
174
|
+
$$(`#v-board .row[data-col="${col}"][data-i="${i}"]`).forEach(r=>r.classList.add('sel'));
|
|
175
|
+
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>
|
|
176
|
+
<div class="ib2">
|
|
177
|
+
<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>
|
|
178
|
+
</div>`;
|
|
179
|
+
openInsp(quiet);
|
|
180
|
+
}
|
|
181
|
+
function openInsp(quiet){insp.classList.add('open');insp.setAttribute('aria-hidden','false');$('#inspX').onclick=closeInsp;if(!quiet)setTimeout(()=>$('#inspX').focus(),60);}
|
|
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;}}
|
|
183
|
+
function bind(){
|
|
184
|
+
$$('#v-board .row[data-col]').forEach(r=>r.onclick=()=>openTask(r.dataset.col,+r.dataset.i));
|
|
185
|
+
if(TOKEN)bindMoves();
|
|
186
|
+
$$('[data-more]').forEach(b=>b.onclick=e=>{e.stopPropagation();if(b.dataset.more==='completed')showAllDone=true;else showAllBacklog=true;renderTasks();});
|
|
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'));});
|
|
188
|
+
}
|
|
189
|
+
$$('#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'));});
|
|
190
|
+
|
|
191
|
+
/* ---------------- any .specs/ file, rendered as written ---------------- */
|
|
192
|
+
function metaLine(m){return ['fileID','version','lastUpdated'].filter(k=>m&&m[k]!==undefined).map(k=>`${k}: ${m[k]}`).join(' · ');}
|
|
193
|
+
async function renderFile(path){
|
|
194
|
+
let src=null;
|
|
195
|
+
if(path in DATA.files)try{src=await getText('.specs/'+path);}catch(e){if(e.status!==404){if(curView==='file'&&curFile===path){$('#fmBox').innerHTML='';$('#fileBody').innerHTML=`<p class="note">${esc(e.message)}</p>`;}return;}}
|
|
196
|
+
if(curView!=='file'||curFile!==path)return;
|
|
197
|
+
if(src===null){$('#fmBox').innerHTML='';$('#fileBody').innerHTML=gone('.specs/'+path);return;}
|
|
198
|
+
const isYaml=/\.ya?ml$/.test(path);
|
|
199
|
+
const {fm,body}=isYaml?{fm:'',body:src}:splitFm(src);
|
|
200
|
+
$('#fmBox').innerHTML=fm?`<div class="gh">Front matter <span class="cnt" translate="no">.specs/${esc(path)}</span></div><div class="box"><pre class="raw" translate="no">${esc(fm)}</pre></div>`:'';
|
|
201
|
+
$('#fileBody').innerHTML=isYaml?`<pre translate="no">${esc(src)}</pre>`:md(body);
|
|
202
|
+
}
|
|
203
|
+
const gone=goneHtml; // one definition of the "no longer exists" markup: ui/route.js
|
|
204
|
+
|
|
205
|
+
/* Explorer: the .specs/ tree, each row carrying that file's own front matter. */
|
|
206
|
+
function renderExplorer(){
|
|
207
|
+
const dirs={};
|
|
208
|
+
DATA.nav.specs.forEach(p=>{const ix=p.indexOf('/'),d=ix<0?'':p.slice(0,ix);(dirs[d]=dirs[d]||[]).push(p);});
|
|
209
|
+
$('#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=>{
|
|
210
|
+
const line=metaLine(DATA.files[p]);
|
|
211
|
+
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('');
|
|
212
|
+
$$('#exBody .row.act').forEach(b=>b.onclick=()=>go('file',false,b.dataset.file));
|
|
213
|
+
$('#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.`;
|
|
214
|
+
}
|
|
215
|
+
/* Security: both files in security/, each rendered as written. */
|
|
216
|
+
const secShown=new Set(); // security files this page has shown, so a deletion can be named
|
|
217
|
+
async function renderSecurity(){
|
|
218
|
+
const paths=['security/threat-model.md','security/security-decisions.md'].filter(p=>p in DATA.files||secShown.has(p));
|
|
219
|
+
const parts=await Promise.all(paths.map(p=>!(p in DATA.files)?Promise.resolve(gone('.specs/'+p)):getText('.specs/'+p).then(src=>(secShown.add(p),
|
|
220
|
+
`<div class="gl"><div class="gh" translate="no">${esc(p)} <span class="cnt" translate="no">${esc(metaLine(DATA.files[p]))}</span></div></div><div class="md doc doc-gap">${md(splitFm(src).body)}</div>`),
|
|
221
|
+
e=>`<p class="note">${esc(e.message)}</p>`)));
|
|
222
|
+
if(curView==='security')$('#secBody').innerHTML=parts.join('')||'<div class="box"><div class="empty">No files in <span class="mono" translate="no">.specs/security/</span>.</div></div>';
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/* ---------------- automation: generated files, read as they are ---------------- */
|
|
226
|
+
function renderIde(){
|
|
227
|
+
const I=DATA.nav.instructions;
|
|
228
|
+
$('#insBox').innerHTML=I.map(f=>f.exists
|
|
229
|
+
?`<button type="button" class="row act" data-open="${esc(f.path)}"><span class="st green" aria-hidden="true"></span><div class="body"><div class="ttl"><span class="id" translate="no">${esc(f.path)}</span></div><div class="det">${f.bytes} bytes</div></div><div class="trail">${chev}</div></button>`
|
|
230
|
+
:`<div class="row"><span class="st hollow" aria-hidden="true"></span><div class="body"><div class="ttl"><span class="id" translate="no">${esc(f.path)}</span></div></div><div class="trail"><span class="pill gray">not in this repo</span></div></div>`).join('');
|
|
231
|
+
$('#insMeta').textContent=I.filter(f=>f.exists).length+' of '+I.length;
|
|
232
|
+
}
|
|
233
|
+
function fileRows(list){
|
|
234
|
+
return list.length?list.map(f=>{const fm=f.frontMatter||{};
|
|
235
|
+
return `<button type="button" class="row act" data-open="${esc(f.path)}"><span class="st hollow" aria-hidden="true"></span><div class="body"><div class="ttl"><span class="id" translate="no">${esc(f.path)}</span>${fm['argument-hint']!==undefined?`<span class="id" translate="no">${esc(fm['argument-hint'])}</span>`:''}</div>${fm.description!==undefined?`<div class="det">${esc(fm.description)}</div>`:''}</div><div class="trail">${fm['allowed-tools']!==undefined?`<span class="pill gray" translate="no">${esc(fm['allowed-tools'])}</span>`:''}${chev}</div></button>`;}).join('')
|
|
236
|
+
:'<div class="empty">No files here.</div>';
|
|
237
|
+
}
|
|
238
|
+
function renderAgentFiles(){
|
|
239
|
+
const N=DATA.nav;
|
|
240
|
+
$('#cmdBox').innerHTML=fileRows(N.commands);$('#cmdCnt').textContent=N.commands.length;
|
|
241
|
+
$('#prmBox').innerHTML=fileRows(N.prompts);$('#prmCnt').textContent=N.prompts.length;
|
|
242
|
+
$('#sklBox').innerHTML=fileRows(N.skills);$('#sklCnt').textContent=N.skills.length;
|
|
243
|
+
}
|
|
244
|
+
/* Inspector for a generated file: its front matter raw, its body rendered. */
|
|
245
|
+
/* Is this generated file in the latest /api/specs listing? */
|
|
246
|
+
function listed(path){const N=DATA.nav;return N.instructions.some(f=>f.exists&&f.path===path)||[N.commands,N.prompts,N.skills].some(l=>l.some(f=>f.path===path));}
|
|
247
|
+
async function openFile(path,quiet){
|
|
248
|
+
if(!quiet)lastFocus=document.activeElement;
|
|
249
|
+
let src=null;
|
|
250
|
+
if(listed(path))try{src=await getText(path);}catch(e){if(e.status!==404){if(!quiet)toast(e.message);return;}}
|
|
251
|
+
inspOpen={kind:'file',path};
|
|
252
|
+
const head=`<div class="ih"><span class="id" translate="no">${esc(path)}</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>`;
|
|
253
|
+
if(src===null){insp.innerHTML=head+`<div class="ib2">${gone(path)}</div>`;openInsp(quiet);return;}
|
|
254
|
+
const {fm,body}=splitFm(src);
|
|
255
|
+
insp.innerHTML=head+`<div class="ib2">${fm?`<div class="gl"><div class="gh">Front matter</div><div class="box"><pre class="raw" translate="no">${esc(fm)}</pre></div></div>`:''}<div class="md doc">${md(body)}</div></div>`;
|
|
256
|
+
openInsp(quiet);
|
|
257
|
+
}
|
|
258
|
+
document.addEventListener('click',e=>{const b=e.target.closest&&e.target.closest('[data-open]');if(b)openFile(b.dataset.open);});
|
|
259
|
+
|
|
260
|
+
/* ---------------- palette + keys ---------------- */
|
|
261
|
+
const palVeil=$('#palVeil'),palIn=$('#palIn'),palList=$('#palList');
|
|
262
|
+
function items(q){q=q.toLowerCase();
|
|
263
|
+
const T=DATA?DATA.tasks:null;
|
|
264
|
+
const it=[
|
|
265
|
+
...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])}),
|
|
266
|
+
...(DATA?DATA.nav.specs:[]).filter(p=>!NAV.some(n=>n[1]===p)).map(p=>({l:'.specs/'+p,k:'file',go:()=>go('file',false,p)})),
|
|
267
|
+
...(T?['currentSprint','backlog','completed'].flatMap(c=>T[c].map((t,i)=>({l:t.id+' '+t.description,k:'task',go:()=>{go('board');openTask(c,i)}}))):[])
|
|
268
|
+
];
|
|
269
|
+
return it.filter(i=>!q||i.l.toLowerCase().includes(q)).slice(0,9);}
|
|
270
|
+
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()}}});}
|
|
271
|
+
function openPal(){palVeil.classList.add('open');palIn.value='';renderPal();palIn.focus();}
|
|
272
|
+
function closePal(){palVeil.classList.remove('open');}
|
|
273
|
+
$('#palBtn').onclick=openPal;palIn.oninput=renderPal;palVeil.onclick=e=>{if(e.target===palVeil)closePal()};
|
|
274
|
+
palIn.onkeydown=e=>{if(e.key==='Enter'){const it=items(palIn.value);it[0]&&it[0].go();closePal();}};
|
|
275
|
+
document.addEventListener('keydown',e=>{
|
|
276
|
+
const mod=e.metaKey||e.ctrlKey;const inField=/INPUT|SELECT|TEXTAREA/.test(e.target.tagName);
|
|
277
|
+
if(mod&&e.key.toLowerCase()==='k'){e.preventDefault();palVeil.classList.contains('open')?closePal():openPal();return}
|
|
278
|
+
if(mod&&/^[1-9]$/.test(e.key)){e.preventDefault();const n=NAV[+e.key-1];if(n)go(n[0],false,n[1]);return}
|
|
279
|
+
if(e.key==='Escape'){hideTip();closeInsp();closePal();setNav(false);return}
|
|
280
|
+
if(inField||mod||e.altKey)return;
|
|
281
|
+
if(/^[1-9]$/.test(e.key)){const n=NAV[+e.key-1];if(n)go(n[0],false,n[1]);}
|
|
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();}
|
|
283
|
+
});
|
|
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
|
+
|
|
339
|
+
/* ---------------- live reload (BL-052) ----------------
|
|
340
|
+
On a change event: re-fetch, redraw in place. Route, scroll, open inspector, selected row
|
|
341
|
+
and focus stay where they were. If the server is gone, the last content stays on screen. */
|
|
342
|
+
function focusKey(el){
|
|
343
|
+
if(!el||el===document.body)return null;
|
|
344
|
+
const row=el.closest&&el.closest('.row[data-col][data-i]');
|
|
345
|
+
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')};}
|
|
346
|
+
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))}"]`};
|
|
347
|
+
if(el.id)return {sel:'#'+CSS.escape(el.id)};
|
|
348
|
+
return null;
|
|
349
|
+
}
|
|
350
|
+
/* Where a row with this ID sits now in that section: the occurrence nearest its old position. */
|
|
351
|
+
function findRow(col,id,oldI){
|
|
352
|
+
const rows=DATA.tasks?DATA.tasks[col]:[];let best=-1;
|
|
353
|
+
rows.forEach((t,i)=>{if(t.id===id&&(best<0||Math.abs(i-oldI)<Math.abs(best-oldI)))best=i;});
|
|
354
|
+
return best;
|
|
355
|
+
}
|
|
356
|
+
function refocus(key){
|
|
357
|
+
if(!key||document.activeElement&&document.activeElement!==document.body)return;
|
|
358
|
+
let el=null;
|
|
359
|
+
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}"]`);}
|
|
360
|
+
else el=$(key.sel);
|
|
361
|
+
if(el)el.focus({preventScroll:true});
|
|
362
|
+
}
|
|
363
|
+
let refreshing=Promise.resolve();
|
|
364
|
+
function refresh(paths){refreshing=refreshing.then(()=>redraw(paths)).catch(()=>{});}
|
|
365
|
+
async function redraw(paths){
|
|
366
|
+
let d;
|
|
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){
|
|
374
|
+
(paths||Object.keys(fileCache)).forEach(p=>{delete fileCache[p];});
|
|
375
|
+
const key=focusKey(document.activeElement);
|
|
376
|
+
const scroll=$('#content').scrollTop,ib0=insp.querySelector('.ib2'),inspScroll=ib0?ib0.scrollTop:0;
|
|
377
|
+
const was=inspOpen;
|
|
378
|
+
DATA=d;
|
|
379
|
+
renderProject();renderTasks();renderIde();renderAgentFiles();
|
|
380
|
+
if(curView==='file')await renderFile(curFile);
|
|
381
|
+
if(curView==='explorer')renderExplorer();
|
|
382
|
+
if(curView==='security')await renderSecurity();
|
|
383
|
+
if(was&&was.kind==='task'){
|
|
384
|
+
const i=findRow(was.col,was.id,was.i);
|
|
385
|
+
if(i>=0){openTask(was.col,i,true);$$(`#v-board .row[data-col="${was.col}"][data-i="${i}"]`).forEach(r=>r.classList.add('sel'));}
|
|
386
|
+
else{insp.classList.remove('open');insp.setAttribute('aria-hidden','true');selected=null;inspOpen=null;}
|
|
387
|
+
}
|
|
388
|
+
if(was&&was.kind==='file'&&(!paths||paths.includes(was.path)))await openFile(was.path,true);
|
|
389
|
+
$('#content').scrollTop=scroll;
|
|
390
|
+
const ib=insp.querySelector('.ib2');if(ib)ib.scrollTop=inspScroll;
|
|
391
|
+
refocus(key);
|
|
392
|
+
}
|
|
393
|
+
function listen(){
|
|
394
|
+
if(!window.EventSource)return;
|
|
395
|
+
const es=new EventSource('/api/events');let dropped=false;
|
|
396
|
+
es.addEventListener('change',e=>{let paths=null;try{paths=JSON.parse(e.data).paths;}catch(_){}refresh(Array.isArray(paths)?paths:null);});
|
|
397
|
+
es.onerror=()=>{dropped=true;}; // EventSource retries by itself
|
|
398
|
+
es.onopen=()=>{if(dropped){dropped=false;refresh(null);}}; // catch up on anything missed
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/* boot */
|
|
402
|
+
insp.setAttribute('aria-hidden','true');
|
|
403
|
+
$('#gDone').classList.add('closed');
|
|
404
|
+
fetch('/api/specs',{cache:'no-store'})
|
|
405
|
+
.then(r=>{if(!r.ok)throw new Error('/api/specs: HTTP '+r.status);return r.json();})
|
|
406
|
+
.then(d=>{DATA=d;renderProject();renderTasks();renderIde();renderAgentFiles();route();listen();})
|
|
407
|
+
.catch(e=>showErr('Could not load the project: '+e.message));
|
|
408
|
+
})();
|
package/ui/favicon.svg
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="300" height="300" viewBox="0 0 300 300" fill="none">
|
|
2
|
+
<rect width="300" height="300" rx="60" fill="url(#paint0_linear_18_9)"/>
|
|
3
|
+
<g filter="url(#filter0_d_18_9)">
|
|
4
|
+
<rect x="46.5" y="73.5" width="207.888" height="153" rx="76.5" stroke="white" stroke-width="41"/>
|
|
5
|
+
<circle cx="116.376" cy="150" r="16.561" fill="#FFFEFE"/>
|
|
6
|
+
<circle cx="116.376" cy="150" r="16.561" stroke="black"/>
|
|
7
|
+
<path d="M184.985 133.439C194.131 133.439 201.546 140.853 201.546 150C201.546 159.146 194.131 166.561 184.985 166.561C175.839 166.561 168.424 159.146 168.424 150C168.425 140.854 175.839 133.439 184.985 133.439Z" fill="white"/>
|
|
8
|
+
<path d="M184.985 133.439C194.131 133.439 201.546 140.853 201.546 150C201.546 159.146 194.131 166.561 184.985 166.561C175.839 166.561 168.424 159.146 168.424 150C168.425 140.854 175.839 133.439 184.985 133.439Z" stroke="black"/>
|
|
9
|
+
</g>
|
|
10
|
+
<defs>
|
|
11
|
+
<filter id="filter0_d_18_9" x="24" y="52" width="252.888" height="198" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB">
|
|
12
|
+
<feFlood flood-opacity="0" result="BackgroundImageFix"/>
|
|
13
|
+
<feColorMatrix in="SourceAlpha" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0" result="hardAlpha"/>
|
|
14
|
+
<feOffset dy="1"/>
|
|
15
|
+
<feGaussianBlur stdDeviation="1"/>
|
|
16
|
+
<feColorMatrix type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.3 0"/>
|
|
17
|
+
<feBlend mode="normal" in2="BackgroundImageFix" result="effect1_dropShadow_18_9"/>
|
|
18
|
+
<feBlend mode="normal" in="SourceGraphic" in2="effect1_dropShadow_18_9" result="shape"/>
|
|
19
|
+
</filter>
|
|
20
|
+
<linearGradient id="paint0_linear_18_9" x1="150" y1="0" x2="150" y2="300" gradientUnits="userSpaceOnUse">
|
|
21
|
+
<stop stop-color="#1481FC"/>
|
|
22
|
+
<stop offset="1" stop-color="#0077FF"/>
|
|
23
|
+
</linearGradient>
|
|
24
|
+
</defs>
|
|
25
|
+
</svg>
|