specpilot 2.7.1 → 2.9.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 (45) hide show
  1. package/README.md +10 -6
  2. package/dist/commands/init.d.ts.map +1 -1
  3. package/dist/commands/init.js +31 -92
  4. package/dist/commands/init.js.map +1 -1
  5. package/dist/commands/serve.d.ts +3 -1
  6. package/dist/commands/serve.d.ts.map +1 -1
  7. package/dist/commands/serve.js +55 -6
  8. package/dist/commands/serve.js.map +1 -1
  9. package/dist/utils/addSpecsQuestions.d.ts +16 -0
  10. package/dist/utils/addSpecsQuestions.d.ts.map +1 -1
  11. package/dist/utils/addSpecsQuestions.js +28 -1
  12. package/dist/utils/addSpecsQuestions.js.map +1 -1
  13. package/dist/utils/gitClone.d.ts +62 -0
  14. package/dist/utils/gitClone.d.ts.map +1 -0
  15. package/dist/utils/gitClone.js +222 -0
  16. package/dist/utils/gitClone.js.map +1 -0
  17. package/dist/utils/initQuestions.d.ts +57 -0
  18. package/dist/utils/initQuestions.d.ts.map +1 -0
  19. package/dist/utils/initQuestions.js +49 -0
  20. package/dist/utils/initQuestions.js.map +1 -0
  21. package/dist/utils/projectRegistry.d.ts +65 -0
  22. package/dist/utils/projectRegistry.d.ts.map +1 -0
  23. package/dist/utils/projectRegistry.js +242 -0
  24. package/dist/utils/projectRegistry.js.map +1 -0
  25. package/dist/utils/specFileGenerator.d.ts +5 -4
  26. package/dist/utils/specFileGenerator.d.ts.map +1 -1
  27. package/dist/utils/specFileGenerator.js +53 -28
  28. package/dist/utils/specFileGenerator.js.map +1 -1
  29. package/dist/utils/specGenerator.d.ts +5 -0
  30. package/dist/utils/specGenerator.d.ts.map +1 -1
  31. package/dist/utils/specGenerator.js +7 -0
  32. package/dist/utils/specGenerator.js.map +1 -1
  33. package/dist/utils/specServer.d.ts +8 -2
  34. package/dist/utils/specServer.d.ts.map +1 -1
  35. package/dist/utils/specServer.js +284 -19
  36. package/dist/utils/specServer.js.map +1 -1
  37. package/dist/utils/specSetup.d.ts +69 -4
  38. package/dist/utils/specSetup.d.ts.map +1 -1
  39. package/dist/utils/specSetup.js +226 -18
  40. package/dist/utils/specSetup.js.map +1 -1
  41. package/package.json +1 -1
  42. package/ui/app.css +135 -9
  43. package/ui/app.js +301 -67
  44. package/ui/index.html +60 -8
  45. package/ui/route.js +179 -3
package/ui/route.js CHANGED
@@ -1,3 +1,4 @@
1
+ // @ts-check
1
2
  /* Hash routing for the serve UI, kept free of the DOM so Jest can require it.
2
3
  Loaded as /assets/route.js in the browser. */
3
4
  (function (root) {
@@ -8,10 +9,15 @@ const esc=s=>String(s).replace(/[&<>"]/g,c=>({'&':'&amp;','<':'&lt;','>':'&gt;',
8
9
  A file the latest /api/specs does not list stays on the file view with missing:true,
9
10
  so the page can say it no longer exists instead of silently showing something else.
10
11
  "#2/board" is project 2 of `count` (BL-054); no index, or "#0/", is project 0; an index
11
- that names no served project goes to project 0's Tasks view. */
12
- function resolveRoute(hash,files,count){
12
+ that names no served project goes to project 0's Tasks view. "#home" is the Home screen
13
+ (BL-PM-001) when `home` says the page has one, and "#new" the new-project chat (BL-PM-004) on the
14
+ same terms: both belong to no project, so an index before them and anything after is ignored;
15
+ without `home` they are unknown views. */
16
+ function resolveRoute(hash,files,count,home){
13
17
  let h=String(hash||'').replace(/^#/,''),project=0;
14
18
  const m=/^(\d+)\/(.*)$/.exec(h);
19
+ const top=/^(home|new)(\/|$)/.exec(m?m[2]:h);
20
+ if(home&&top)return {project:0,view:top[1],sub:'',missing:false};
15
21
  if(m){
16
22
  if(!/^(0|[1-9][0-9]*)$/.test(m[1])||Number(m[1])>=(count||1))return {project:0,view:'board',sub:'',missing:false};
17
23
  project=Number(m[1]);h=m[2];
@@ -28,6 +34,176 @@ function resolveRoute(hash,files,count){
28
34
  /* The whole content of a view whose file is gone: its path, and that it no longer exists. */
29
35
  function goneHtml(path){return `<p class="note"><span class="mono" translate="no">${esc(path)}</span> no longer exists.</p>`;}
30
36
 
31
- const api={resolveRoute,goneHtml};
37
+ /* A time as "4 Oct 2026, 07:08", local, the same in every locale; what Date cannot parse is shown as it is. */
38
+ const MONTHS=['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
39
+ function when(iso){
40
+ const d=new Date(iso),p=n=>String(n).padStart(2,'0');
41
+ return isNaN(d.getTime())?iso:`${d.getDate()} ${MONTHS[d.getMonth()]} ${d.getFullYear()}, ${p(d.getHours())}:${p(d.getMinutes())}`;
42
+ }
43
+
44
+ /* The registry as GET /api/projects sends it (BL-067): the rows of the sheet's list, or of Home's
45
+ (BL-PM-001), where a row is one button that opens its folder, has no Remove, and a project that
46
+ is open also shows the branch /api/specs gives for it (`projects`, as the rail tooltip does). */
47
+ function recentHtml(reg,home,projects,chev){
48
+ if(reg.error)return `<p class="note">${esc(reg.error)}</p>`;
49
+ if(!reg.entries.length)return '<div class="empty">No projects remembered yet.</div>';
50
+ return reg.entries.map(e=>{
51
+ const det=[when(e.lastOpened)];
52
+ if(e.project!==null)det.push('open as project '+e.project);
53
+ if(!e.exists)det.push('folder not found');
54
+ if(home){const q=e.project!==null&&projects?projects[e.project]:null;
55
+ return `<button type="button" class="row act" data-path="${esc(e.path)}"><div class="body"><div class="ttl" translate="no">${esc(e.root+(q&&q.branch?' · '+q.branch:''))}</div><div class="det">${esc(det.join(' · '))}</div></div><div class="trail">${chev||''}</div></button>`;}
56
+ return `<div class="row recent"><div class="body" data-path="${esc(e.path)}" role="button" tabindex="0"><div class="ttl" translate="no">${esc(e.root)}</div><div class="det">${esc(det.join(' · '))}</div></div><button type="button" class="btn sm" data-remove="${esc(e.path)}">Remove from list</button></div>`;
57
+ }).join('');
58
+ }
59
+
60
+ /* What the page does with the answer to POST /api/projects, from the sheet or a row on Home:
61
+ `project` is the one to show (null: nothing was opened, the page stays where it is), `specs` its
62
+ payload when the answer carries one, `toast` the message, the server's own when it sent one.
63
+ `created` says the answer is POST /api/projects/new's (BL-PM-003), or with 'cloned' POST
64
+ /api/projects/clone's (BL-PM-002): only the two texts differ. */
65
+ function openOutcome(status,res,created){
66
+ const did=created==='cloned'?'cloned':created?'created':'opened';
67
+ if(status===200)return {project:res.project,specs:res.specs,toast:`${res.specs.projects[res.project].root} ${did==='opened'?did:did+' and opened'} as project ${res.project}`+(res.registry&&res.registry.error?'. '+res.registry.error:'')};
68
+ if(status===409&&typeof res.project==='number')return {project:res.project,specs:null,toast:res.error||`Already open as project ${res.project}`};
69
+ return {project:null,specs:null,toast:res.error||`Nothing was ${did} (HTTP ${status}).`};
70
+ }
71
+
72
+ /* The view a live-reload payload forces, or null to stay: setup when .specs/ is gone, Tasks when it
73
+ appeared while the setup view was shown. Home and the new-project chat belong to no project, so they never move. */
74
+ function reloadView(curView,hadSpecs,hasSpecs){
75
+ if(!hasSpecs&&curView!=='setup'&&curView!=='home'&&curView!=='new')return 'setup';
76
+ if(!hadSpecs&&hasSpecs&&curView==='setup')return 'board';
77
+ return null;
78
+ }
79
+
80
+ /* The folder git clone makes for a repository URL: its last path segment without `.git`. The one copy
81
+ of the rule: the Clone tab fills Folder name with it and the server uses it for an empty name (BL-PM-002). */
82
+ function repoNameFromUrl(url){return String(url).replace(/\/+$/,'').replace(/\.git$/,'').split(/[/:]/).pop()||'';}
83
+
84
+ /* The name a project is shown under: the one in its project.yaml, else its folder's own name (the last
85
+ segment of its root), never the whole path, which stays in the tooltip and the sub-line. */
86
+ function projectLabel(p){return p.name!==null&&p.name!==undefined?p.name:String(p.root).split(/[/\\]/).filter(Boolean).pop()||p.root;}
87
+
88
+ /* ---- the setup chat (BL-PM-004): one question at a time over GET /api/setup or /api/projects/new ---- */
89
+
90
+ /* What is wrong with a project name, in `specpilot init`'s words (`hint` is the terminal's extra line), or
91
+ null. The one copy of the rule: init and the server load it from here, the page checks with it. */
92
+ const MAX_PROJECT_NAME_LENGTH=214; // npm limit
93
+ const PROJECT_NAME_PATTERN=/^[a-zA-Z0-9][a-zA-Z0-9._-]*$/;
94
+ function projectNameError(name){
95
+ if(!name)return {message:'Project name is required and cannot be empty',hint:'💡 Usage: specpilot init <project-name>'};
96
+ if(name.length>MAX_PROJECT_NAME_LENGTH)return {message:`Project name must be ${MAX_PROJECT_NAME_LENGTH} characters or fewer`};
97
+ if(!PROJECT_NAME_PATTERN.test(name))return {message:'Project name must start with a letter or number and contain only letters, numbers, dots, hyphens, and underscores',hint:'💡 Example: my-project, app_v2, project.name'};
98
+ return null;
99
+ }
100
+
101
+ /* What is wrong with a handle sent over HTTP, or null. Trimmed first, and an empty one is fine: the OS
102
+ username is used then. The one copy, as above. */
103
+ const HANDLE_PATTERN=/^[A-Za-z0-9][A-Za-z0-9._-]{0,38}$/;
104
+ function handleError(handle){
105
+ const h=String(handle).trim();
106
+ return h&&!HANDLE_PATTERN.test(h)?'The handle must be 1 to 39 characters of letters, digits, dots, underscores and hyphens, starting with a letter or digit.':null;
107
+ }
108
+
109
+ /* The answer a question has now: the one given, else the first choice (the one that comes pressed), else empty. */
110
+ function flowValue(qu,answers){
111
+ const v=answers[qu.key];
112
+ if(qu.choices)return qu.choices.some(c=>c.value===v)?v:qu.choices[0].value;
113
+ return v===undefined?'':v;
114
+ }
115
+
116
+ /* Whether a question has been answered: its key is there and, for a choice, the answer is one of the
117
+ choices now offered (a framework kept from another language is asked again). An empty optional answer counts. */
118
+ function answered(qu,answers){
119
+ if(!(qu.key in answers))return false;
120
+ return !qu.choices||qu.choices.some(c=>c.value===answers[qu.key]);
121
+ }
122
+
123
+ /* The questions to ask for the answers so far, in the chat's order (`order`, which groups them by step):
124
+ `first` (the page's own parent question of a new project) before the server's; the framework question with
125
+ the selected language's choices, left out when that language has none; a question with `when` only while
126
+ those answers are selected. */
127
+ function flowQuestions(q,answers,first){
128
+ const all=[...(first||[]),...q.questions],byKey=k=>all.find(x=>x.key===k),out=[];
129
+ const now=k=>{const x=byKey(k);return x?flowValue(x,answers):undefined;};
130
+ for(const qu of all){
131
+ if(qu.when&&!Object.keys(qu.when).every(k=>now(k)===qu.when[k]))continue;
132
+ if(qu.key==='framework'&&!qu.choices){
133
+ const list=q.frameworks&&q.frameworks[now('language')]||[];
134
+ if(list.length)out.push({...qu,choices:list.map(v=>({name:v,value:v}))});
135
+ }else out.push(qu);
136
+ }
137
+ return out.sort((a,b)=>(a.order??-1)-(b.order??-1));
138
+ }
139
+
140
+ /* The question the composer shows: the one being edited, else the first asked question without an answer,
141
+ else null, which means the recap. */
142
+ function nextQuestion(list,answers,editing){
143
+ if(editing){const qu=list.find(x=>x.key===editing);if(qu)return qu;}
144
+ return list.find(x=>!answered(x,answers))||null;
145
+ }
146
+
147
+ /* What Continue shows under the answer, or null: a required text left empty, a project name or a handle
148
+ the server would refuse (its own message; never the terminal's hint). */
149
+ function answerError(qu,value){
150
+ const v=String(value).trim();
151
+ if(qu.choices)return null;
152
+ if(!v)return qu.required?'This one is required.':null;
153
+ if(qu.key==='name'){const e=projectNameError(v);return e?e.message+'.':null;}
154
+ return qu.key==='handle'?handleError(v):null;
155
+ }
156
+
157
+ /* The bot bubble's line: `chat` with `{name}` and `{language}` filled. `ctx` is {name, language}: the project
158
+ name (the folder's label in guided setup) and the language choice's text, or the detected language. */
159
+ function chatText(qu,ctx){return String(qu.chat||'').replace(/\{name\}/g,ctx.name||'').replace(/\{language\}/g,ctx.language||'');}
160
+
161
+ /* The answer as a bubble or a recap row shows it: the choice's own text up to its " — " part (the chips
162
+ keep the whole), the typed text, or Skipped. */
163
+ function answerText(qu,answers){
164
+ const v=answers[qu.key];
165
+ if(qu.choices){const c=qu.choices.find(x=>x.value===v);return c?c.name.split(' — ')[0]:'';}
166
+ return String(v===undefined?'':v).trim()||'Skipped';
167
+ }
168
+
169
+ /* The thread up to the current question: the name bubble (a new project only: `named`), a divider per step,
170
+ a bot row per asked question and an answer row per answered one; after the last answer a Review divider. */
171
+ function threadRows(q,list,answers,cur,ctx,named){
172
+ const steps=[...new Set(list.map(x=>x.step))],rows=[];
173
+ if(named)rows.push({kind:'user',key:'name',text:ctx.name,mono:true,skipped:false});
174
+ let last=null;
175
+ for(const qu of list){
176
+ if(qu.step!==last){rows.push({kind:'divider',text:`Step ${steps.indexOf(qu.step)+1} · ${qu.step}`});last=qu.step;}
177
+ rows.push({kind:'bot',key:qu.key,text:chatText(qu,ctx),cli:qu.message});
178
+ if(cur&&qu.key===cur.key)break;
179
+ if(answered(qu,answers))rows.push({kind:'user',key:qu.key,text:answerText(qu,answers),mono:qu.key==='parent'||qu.key==='handle',skipped:!qu.choices&&!String(answers[qu.key]).trim()});
180
+ }
181
+ if(!cur)rows.push({kind:'divider',text:'Review'});
182
+ return rows;
183
+ }
184
+
185
+ /* The recap: one card per step in use, one row per asked question. */
186
+ function recapCards(list,answers){
187
+ const steps=[...new Set(list.map(x=>x.step))];
188
+ return steps.map(step=>({title:step,rows:list.filter(x=>x.step===step).map(qu=>({key:qu.key,label:qu.label,value:answerText(qu,answers)}))}));
189
+ }
190
+
191
+ /* The POST body: the answer of every question asked, text trimmed. */
192
+ function flowBody(list,answers){
193
+ const body={};
194
+ for(const qu of list)body[qu.key]=qu.choices?flowValue(qu,answers):String(flowValue(qu,answers)).trim();
195
+ return body;
196
+ }
197
+
198
+ /* The files that will be written for the answers so far: .specs/ for the API paradigm, then the files
199
+ outside it for the IDE; `kept` marks one that is already in the folder (guided setup's `keep`). */
200
+ function previewFiles(q,answers){
201
+ const pick=k=>{const x=q.questions.find(y=>y.key===k);return x?flowValue(x,answers):undefined;};
202
+ const ide=pick('ide'),keep=q.keep&&q.keep[ide]||[];
203
+ return [...(q.files.specs[pick('apiParadigm')]||[]),...(q.files.outside[ide]||[])].map(path=>({path,kept:keep.includes(path)}));
204
+ }
205
+
206
+ const api={resolveRoute,goneHtml,recentHtml,openOutcome,reloadView,repoNameFromUrl,projectLabel,
207
+ projectNameError,handleError,HANDLE_PATTERN,flowValue,answered,flowQuestions,nextQuestion,answerError,chatText,answerText,threadRows,recapCards,flowBody,previewFiles};
32
208
  if(typeof module==='object'&&module.exports)module.exports=api;else Object.assign(root,api);
33
209
  })(this);