userforge 0.1.0 → 0.1.1

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/dist/process.js CHANGED
@@ -1,7 +1,7 @@
1
- import{D as e,M as t,P as n,T as r,a as i,b as a,c as o,i as s,j as c,o as l,s as u,t as d,v as f,w as p,y as m}from"./map.js";import{STAGES as h,storyStage as g,workDone as _}from"./stage.js";import{n as v,r as y}from"./results.js";import{existsSync as b,mkdirSync as x,rmSync as S,writeFileSync as C}from"node:fs";import{dirname as w,join as T}from"node:path";function E(e){return e===``||e===`.`?[]:e.split(`.`).map(e=>/^(0|[1-9]\d*)$/.test(e)?Number(e):e)}function D(e){return e.join(`.`)}function O(e,t){let n=typeof t==`string`?E(t):t,r=e;for(let e of n){if(r==null)return;r=r[e]}return r}function k(e,t){return Array.isArray(e)?e.slice():e&&typeof e==`object`?{...e}:typeof t==`number`?[]:{}}function A(e,t,n){if(t.length===0)throw Error(`A patch needs a path below the root`);let r=k(e,t[0]),i=r;for(let e=0;e<t.length-1;e++){let n=t[e];i[n]=k(i[n],t[e+1]),i=i[n]}return n(i,t[t.length-1]),r}function j(e,t){let n=e[e.length-1];if(typeof n!=`number`)throw Error(`${t} needs a list item path ending in an index`);return{listKeys:e.slice(0,-1),index:n}}function M(e,t){let n=E(t.path);if(t.op===`set`){let r=O(e,n);return{root:A(e,n,(e,n)=>{t.value===void 0?Array.isArray(e)?e[n]=void 0:delete e[n]:e[n]=t.value}),applied:{...t,previous:r}}}let{listKeys:r,index:i}=j(n,t.op),a=O(e,r);if(a!==void 0&&!Array.isArray(a))throw Error(`${t.op} at "${t.path}": "${D(r)}" is not a list`);let o=a??[];if(t.op===`insert`){if(i<0||i>o.length)throw Error(`insert index ${i} is out of range`);let n=o.slice();return n.splice(i,0,t.value),{root:r.length?A(e,r,(e,t)=>e[t]=n):n,applied:{...t}}}if(i<0||i>=o.length)throw Error(`${t.op} index ${i} is out of range`);if(t.op===`remove`){let n=o.slice(),[a]=n.splice(i,1);return{root:r.length?A(e,r,(e,t)=>e[t]=n):n,applied:{...t,previous:a}}}if(t.op===`move`){let n=t.to;if(typeof n!=`number`||n<0||n>=o.length)throw Error(`move to ${n} is out of range`);let a=o.slice(),[s]=a.splice(i,1);return a.splice(n,0,s),{root:r.length?A(e,r,(e,t)=>e[t]=a):a,applied:{...t}}}throw Error(`Unknown patch op "${t.op}"`)}function N(e,t){let n=e,r=[];for(let e of t){let t=M(n,e);n=t.root,r.push(t.applied)}return{root:n,applied:r}}const P=/\bhttps?:\/\/[^\s<>()"']+|\bwww\.[^\s<>()"']+\.[a-z]{2,}[^\s<>()"']*/gi,F=/^([^\n(]{2,80}\(\s*https?:\/\/[^)\s]+\s*\)|\s*https?:\/\/\S+)\s*[-–—:|]/,I=/\[url=|<a\s+href|\b(backlinks?|guest posts?|seo (services|agency|experts?)|link building|rank(ing)? (higher|first) on google|first page of google|website traffic|increase (your )?traffic|casino|viagra|cialis|forex|crypto (signals|investment)|bitcoin investment|whatsapp me|telegram me)\b/i;function L(e){let t=String(e??``).trim();if(!t)return;let n=t.match(P)??[];if(n.length>=3||n.join(``).length>=t.length*.4)return`links`;if(F.test(t))return`advert`;if(I.test(t))return`phrases`}const R=e=>!e.facts?.person&&!!L(e.data.feedback?.text),z=e=>e.data.feedback?.status!==`done`&&!R(e),B=`c-site`,V=e=>(e.data.place?.blocks??[]).some(e=>e?.is===B);function H(e,t){for(let n=t,r=/* @__PURE__ */ new Set;n?.kind===`place`&&!r.has(n.key);r.add(n.key),n=e[n.data.place?.under??``])if(V(n))return n}const U=[`failing`,`unchecked`,`unplaced`,`bare`,`unsorted`,`undecided`];function W(e,t){let n=t=>Object.values(e).filter(e=>e.kind===t),r=e=>e.map(e=>e.key).sort((e,t)=>Number(e.slice(1))-Number(t.slice(1))),i=n(`story`),a=n(`place`),o=e=>e.data.story.checks??[];return{failing:r(i.filter(e=>o(e).some(n=>t[`${e.key}.${n.id}`]?.state===`fail`))),unchecked:r(i.filter(e=>!o(e).length)),unplaced:r(i.filter(t=>!(t.data.story.where??[]).some(t=>e[t]))),bare:r(a.filter(t=>!H(e,t)&&!a.some(e=>e.key!==t.key&&e.data.place.under===t.key)&&!t.data.place.shot&&!t.data.place.blocks?.length)),unsorted:r(n(`feedback`).filter(z)),undecided:r(n(`decision`).filter(e=>(e.data.decision.status??`proposed`)===`proposed`))}}function G(n=d,r=s){let c=()=>l(n,r).all,m=e=>c()[e]??Promise.reject(new a(`There is nothing with the id "${e}".`)),h=(t,i,s,l,u)=>{let{value:d,problems:m}=p(r,t,s,{all:c(),had:l,key:i,patch:u});if(m.length)throw new a(e(t,m));let h={key:i,kind:t,data:{[t]:d}},g=f(r,h);return x(w(T(n,g.path)),{recursive:!0}),C(T(n,g.path),g.text),o(n,r),h};return{kinds:Object.fromEntries(Object.entries(r).filter(([,e])=>e.file)),all:c,results:()=>u(n),stage:e=>g(e,u(n)),async make(e,t){let n=r[e];if(!n?.file)throw new a(`There is no kind "${e}" in this map.`);let o=n.one?`${n.letter}1`:v()&&await y(v(),e).catch(()=>void 0)||i(r,e,c());return h(e,o,t)},async put(e,t){let n=await m(e);return h(n.kind,e,t,n)},async change(e,t){let n=await m(e),r;try{r=N(n.data,t).root}catch(e){throw new a(`That change couldn’t be made: ${e.message}`)}return h(n.kind,e,r[n.kind]??{},n,t.at(-1))},async drop(e){let i=c(),a=await m(e);S(T(n,f(r,a).path));for(let{thing:a}of t(r,i,e))C(T(n,f(r,a).path),f(r,a).text);b(n)&&o(n,r)}}}const K=[`source`,`feedback`,`queue`],q=e=>({type:`string`,description:`The id of ${e}, such as S12.`}),J={failing:`Abilities with a check that fails`,unchecked:`Abilities with no checks`,unplaced:`Abilities with no place`,bare:`Places with no picture`,unsorted:`Notes to sort`,undecided:`Decisions still proposed`},Y=e=>Array.isArray(e)?e.map(Y):e&&typeof e==`object`?Object.fromEntries(Object.entries(e).filter(([e])=>e!==`required`).map(([e,t])=>[e,Y(t)])):e;function X(e){let t=e.kinds,n=Object.keys(t).filter(e=>!K.includes(e)).map(e=>{let{$defs:n,...r}=Y(t[e].schema),{letter:i,one:a}=t[e],o={...r,properties:{key:{type:`string`,description:`The id of a ${e} there is, to write it again, such as ${i}3. Leave it out to make a new one.`},...r.properties}};return{name:`write_${e}`,description:`${r.description??``} ${a?`Writes the map's ${e}`:`Makes each ${e} given, or writes it again when it carries the key of one there is`}: the fields given replace what was there, and the rest stay.`.trim(),inputSchema:a?{type:`object`,properties:r.properties,$defs:n}:{type:`object`,properties:{items:{type:`array`,minItems:1,maxItems:20,items:o}},required:[`items`],$defs:n}}});return[{name:`overview`,description:`The map at a glance: why it is being built and for whom, how many abilities stand at each stage, its documents and decisions, the code work waiting, and what needs attention. Start here.`,inputSchema:{type:`object`,properties:{}}},{name:`list`,description:`Every thing of one kind, a line each, or those whose words hold what is searched for, or those tied to one persona, place or ability. Abilities can be narrowed to one stage.`,inputSchema:{type:`object`,properties:{kind:{type:`string`,enum:Object.keys(t)},search:{type:`string`,description:`Words the things listed hold, in any of their fields.`},persona:q(`a persona`),place:q(`a place`),story:q(`an ability`),stage:{type:`string`,enum:[...h]}},required:[`kind`]}},{name:`read`,description:`One thing in full, by its id: its fields as its file holds them, and for an ability its stage and each check’s result.`,inputSchema:{type:`object`,properties:{key:q(`the thing`)},required:[`key`]}},...n,{name:`change`,description:'Change lines of one thing without sending all of it. Each change names a path into its fields, with dots and list positions ("story.what", "story.checks.2.text"). `set` puts a value there, `insert` adds to a list at that position, `remove` takes out, `move` moves to `to`.',inputSchema:{type:`object`,properties:{key:q(`the thing to change`),changes:{type:`array`,minItems:1,items:{type:`object`,properties:{op:{type:`string`,enum:[`set`,`insert`,`remove`,`move`]},path:{type:`string`},value:{},to:{type:`string`}},required:[`op`,`path`]}}},required:[`key`,`changes`]}},{name:`remove`,description:`Remove one thing. It is taken out of whatever pointed at it.`,inputSchema:{type:`object`,properties:{key:q(`the thing to remove`)},required:[`key`]}},...e.queue?[{name:`queue`,description:`Put code work in the queue for the team’s coding agent, once the map’s part is done: what the code must do, the abilities it is for, and the checks that must pass on main for it to be done. Once for what was asked, last.`,inputSchema:(({by:e,...n})=>({type:`object`,properties:n,required:t.queue.schema.required??[]}))(t.queue.schema.properties??{})}]:[]]}function Z(e,t){let r=t.data[t.kind]??{},i={key:t.key,title:n(t),...r.status?{status:r.status}:{}};switch(t.kind){case`story`:return{...i,stage:e.stage(t),who:r.who??[],where:r.where??[],checks:(r.checks??[]).length};case`place`:return{...i,route:r.route,under:r.under};case`queue`:return{key:t.key,asked:r.asked,for:r.for??[],done:r.done??[],..._(r.done,e.results())?{finished:!0}:{}};default:return i}}async function Q(e,t,n={}){try{let r=await $(e,t,n??{});return{text:typeof r==`string`?r:JSON.stringify(r,null,2)}}catch(e){if(e instanceof a)return{text:e.message,failed:!0};throw e}}async function $(e,t,n){let i=e.all(),o=e=>Object.values(i).filter(t=>t.kind===e),s=e=>i[String(e??``)]??Promise.reject(new a(`There is no thing with the id "${e??``}".`)),l=(t,n)=>r(i,n?c(t,e.kinds[n].schema):t);if(t.startsWith(`write_`)){let r=t.slice(6);if(!e.kinds[r]||K.includes(r))throw new a(`There is no tool "${t}".`);let s=e.kinds[r].one?[{...n,key:o(r)[0]?.key}]:n.items;if(!Array.isArray(s)||!s.length)throw new a("Give `items`: a list of what to write.");let c=[];for(let{key:t,...n}of s){if(t&&i[t]?.kind!==r)throw new a(`There is no ${r} with the id "${t}". Leave the key out to make a new one.`);let{n:o,...s}=t?i[t].data[r]:{},u=t?await e.put(t,{...s,...l(n,r)}):await e.make(r,l(n,r));i[u.key]=u,c.push(Z(e,u))}return c}switch(t){case`overview`:{let t=i.B1?.data.brief,n=o(`story`),r=W(i,e.results()),a=o(`queue`),s=a.filter(t=>_(t.data.queue.done,e.results())).map(e=>e.key),c=a.filter(e=>!e.data.queue.done?.some(Boolean)).map(e=>e.key);return{why:t?{name:t.name,idea:t.idea}:`There is no brief yet.`,personas:o(`persona`).map(t=>Z(e,t)),abilities:Object.fromEntries(h.map(t=>[t,n.filter(n=>e.stage(n)===t).length])),places:o(`place`).length,documents:[`document`,`script`,`voice`,`look`].flatMap(o).map(t=>Z(e,t)),decisions:o(`decision`).map(t=>Z(e,t)),waiting:a.map(t=>Z(e,t)),needsAttention:[...U.filter(e=>r[e].length).map(e=>`${J[e]}: ${r[e].join(`, `)}`),...s.length?[`Code work whose checks all pass, to remove: ${s.join(`, `)}`]:[],...c.length?[`Code work that names no checks: ${c.join(`, `)}`]:[]]}}case`list`:{if(!e.kinds[n.kind])throw new a(`"${n.kind??``}" is not a kind. The kinds are ${Object.keys(e.kinds).join(`, `)}.`);let t=String(n.search??``).trim().toLowerCase(),r=(t,n,r)=>!r||Object.entries(e.kinds[t.kind].refs??{}).some(([e,i])=>[i].flat()[0]===n&&[t.data[t.kind][e]??[]].flat().includes(r));return o(n.kind).filter(n=>!t||m(e.kinds,n).toLowerCase().includes(t)).filter(t=>r(t,`persona`,n.persona)&&r(t,`place`,n.place)&&r(t,`story`,n.story)&&(!n.stage||t.kind!==`story`||e.stage(t)===n.stage)).sort((e,t)=>Number(e.key.slice(1))-Number(t.key.slice(1))).map(t=>Z(e,t))}case`read`:{let t=await s(n.key),r=e.results(),i=e=>`results:\n${e.map(e=>` ${e}: ${r[e]?.state??`not run`}`).join(`
2
- `)}\n`,a=t.kind===`queue`?(t.data.queue.done??[]).filter(Boolean):[],o=t.kind===`story`?`\nstage: ${e.stage(t)}\n${i((t.data.story.checks??[]).map(e=>`${t.key}.${e.id}`))}`:a.length?`\n${i(a)}`:t.kind===`queue`?`
1
+ import{E as e,F as t,M as n,N as r,O as i,T as a,a as o,b as s,c,l,n as u,o as d,s as f,x as p,y as m}from"./map.js";import{STAGES as h,storyStage as g,workDone as _}from"./stage.js";import{n as v,r as y}from"./results.js";import{existsSync as b,mkdirSync as x,rmSync as S,writeFileSync as C}from"node:fs";import{dirname as w,join as T}from"node:path";function E(e){return e===``||e===`.`?[]:e.split(`.`).map(e=>/^(0|[1-9]\d*)$/.test(e)?Number(e):e)}function D(e){return e.join(`.`)}function O(e,t){let n=typeof t==`string`?E(t):t,r=e;for(let e of n){if(r==null)return;r=r[e]}return r}function k(e,t){return Array.isArray(e)?e.slice():e&&typeof e==`object`?{...e}:typeof t==`number`?[]:{}}function A(e,t,n){if(t.length===0)throw Error(`A patch needs a path below the root`);let r=k(e,t[0]),i=r;for(let e=0;e<t.length-1;e++){let n=t[e];i[n]=k(i[n],t[e+1]),i=i[n]}return n(i,t[t.length-1]),r}function j(e,t){let n=e[e.length-1];if(typeof n!=`number`)throw Error(`${t} needs a list item path ending in an index`);return{listKeys:e.slice(0,-1),index:n}}function M(e,t){let n=E(t.path);if(t.op===`set`){let r=O(e,n);return{root:A(e,n,(e,n)=>{t.value===void 0?Array.isArray(e)?e[n]=void 0:delete e[n]:e[n]=t.value}),applied:{...t,previous:r}}}let{listKeys:r,index:i}=j(n,t.op),a=O(e,r);if(a!==void 0&&!Array.isArray(a))throw Error(`${t.op} at "${t.path}": "${D(r)}" is not a list`);let o=a??[];if(t.op===`insert`){if(i<0||i>o.length)throw Error(`insert index ${i} is out of range`);let n=o.slice();return n.splice(i,0,t.value),{root:r.length?A(e,r,(e,t)=>e[t]=n):n,applied:{...t}}}if(i<0||i>=o.length)throw Error(`${t.op} index ${i} is out of range`);if(t.op===`remove`){let n=o.slice(),[a]=n.splice(i,1);return{root:r.length?A(e,r,(e,t)=>e[t]=n):n,applied:{...t,previous:a}}}if(t.op===`move`){let n=t.to;if(typeof n!=`number`||n<0||n>=o.length)throw Error(`move to ${n} is out of range`);let a=o.slice(),[s]=a.splice(i,1);return a.splice(n,0,s),{root:r.length?A(e,r,(e,t)=>e[t]=a):a,applied:{...t}}}throw Error(`Unknown patch op "${t.op}"`)}function N(e,t){let n=e,r=[];for(let e of t){let t=M(n,e);n=t.root,r.push(t.applied)}return{root:n,applied:r}}const P=/\bhttps?:\/\/[^\s<>()"']+|\bwww\.[^\s<>()"']+\.[a-z]{2,}[^\s<>()"']*/gi,F=/^([^\n(]{2,80}\(\s*https?:\/\/[^)\s]+\s*\)|\s*https?:\/\/\S+)\s*[-–—:|]/,I=/\[url=|<a\s+href|\b(backlinks?|guest posts?|seo (services|agency|experts?)|link building|rank(ing)? (higher|first) on google|first page of google|website traffic|increase (your )?traffic|casino|viagra|cialis|forex|crypto (signals|investment)|bitcoin investment|whatsapp me|telegram me)\b/i;function L(e){let t=String(e??``).trim();if(!t)return;let n=t.match(P)??[];if(n.length>=3||n.join(``).length>=t.length*.4)return`links`;if(F.test(t))return`advert`;if(I.test(t))return`phrases`}const R=e=>!e.facts?.person&&!!L(e.data.feedback?.text),z=e=>e.data.feedback?.status!==`done`&&!R(e),B=`c-site`,V=e=>(e.data.place?.blocks??[]).some(e=>e?.is===B);function H(e,t){for(let n=t,r=/* @__PURE__ */ new Set;n?.kind===`place`&&!r.has(n.key);r.add(n.key),n=e[n.data.place?.under??``])if(V(n))return n}const U=[`failing`,`unchecked`,`unplaced`,`bare`,`unsorted`,`undecided`];function W(e,t){let n=t=>Object.values(e).filter(e=>e.kind===t),r=e=>e.map(e=>e.key).sort((e,t)=>Number(e.slice(1))-Number(t.slice(1))),i=n(`story`),a=n(`place`),o=e=>e.data.story.checks??[];return{failing:r(i.filter(e=>o(e).some(n=>t[`${e.key}.${n.id}`]?.state===`fail`))),unchecked:r(i.filter(e=>!o(e).length)),unplaced:r(i.filter(t=>!(t.data.story.where??[]).some(t=>e[t]))),bare:r(a.filter(t=>!H(e,t)&&!a.some(e=>e.key!==t.key&&e.data.place.under===t.key)&&!t.data.place.shot&&!t.data.place.blocks?.length)),unsorted:r(n(`feedback`).filter(z)),undecided:r(n(`decision`).filter(e=>(e.data.decision.status??`proposed`)===`proposed`))}}function G(e=u,t=o){let n=()=>f(e,t).all,s=e=>n()[e]??Promise.reject(new p(`There is nothing with the id "${e}".`)),h=(r,o,s,c,u)=>{let{value:d,problems:f}=a(t,r,s,{all:n(),had:c,key:o,patch:u});if(f.length)throw new p(i(r,f));let h={key:o,kind:r,data:{[r]:d}},g=m(t,h);return x(w(T(e,g.path)),{recursive:!0}),C(T(e,g.path),g.text),l(e,t),h};return{kinds:Object.fromEntries(Object.entries(t).filter(([,e])=>e.file)),all:n,results:()=>c(e),stage:t=>g(t,c(e)),async make(e,r){let i=t[e];if(!i?.file)throw new p(`There is no kind "${e}" in this map.`);let a=i.one?`${i.letter}1`:v()&&await y(v(),e).catch(()=>void 0)||d(t,e,n());return h(e,a,r)},async put(e,t){let n=await s(e);return h(n.kind,e,t,n)},async change(e,t){let n=await s(e),r;try{r=N(n.data,t).root}catch(e){throw new p(`That change couldn’t be made: ${e.message}`)}return h(n.kind,e,r[n.kind]??{},n,t.at(-1))},async drop(i){let a=n(),o=await s(i);S(T(e,m(t,o).path));for(let{thing:n}of r(t,a,i))C(T(e,m(t,n).path),m(t,n).text);b(e)&&l(e,t)}}}const K=[`source`,`feedback`,`queue`],q=e=>({type:`string`,description:`The id of ${e}, such as S12.`}),J={failing:`Abilities with a check that fails`,unchecked:`Abilities with no checks`,unplaced:`Abilities with no place`,bare:`Places with no picture`,unsorted:`Notes to sort`,undecided:`Decisions still proposed`},Y=e=>Array.isArray(e)?e.map(Y):e&&typeof e==`object`?Object.fromEntries(Object.entries(e).filter(([e])=>e!==`required`).map(([e,t])=>[e,Y(t)])):e;function X(e){let t=e.kinds,n=Object.keys(t).filter(e=>!K.includes(e)).map(e=>{let{$defs:n,...r}=Y(t[e].schema),{letter:i,one:a}=t[e],o={...r,properties:{key:{type:`string`,description:`The id of a ${e} there is, to write it again, such as ${i}3. Leave it out to make a new one.`},...r.properties}};return{name:`write_${e}`,description:`${r.description??``} ${a?`Writes the map's ${e}`:`Makes each ${e} given, or writes it again when it carries the key of one there is`}: the fields given replace what was there, and the rest stay.`.trim(),inputSchema:a?{type:`object`,properties:r.properties,$defs:n}:{type:`object`,properties:{items:{type:`array`,minItems:1,maxItems:20,items:o}},required:[`items`],$defs:n}}});return[{name:`overview`,description:`The map at a glance: why it is being built and for whom, how many abilities stand at each stage, its documents and decisions, the code work waiting, and what needs attention. Start here.`,inputSchema:{type:`object`,properties:{}}},{name:`list`,description:`Every thing of one kind, a line each, or those whose words hold what is searched for, or those tied to one persona, place or ability. Abilities can be narrowed to one stage.`,inputSchema:{type:`object`,properties:{kind:{type:`string`,enum:Object.keys(t)},search:{type:`string`,description:`Words the things listed hold, in any of their fields.`},persona:q(`a persona`),place:q(`a place`),story:q(`an ability`),stage:{type:`string`,enum:[...h]}},required:[`kind`]}},{name:`read`,description:`One thing in full, by its id: its fields as its file holds them, and for an ability its stage and each check’s result.`,inputSchema:{type:`object`,properties:{key:q(`the thing`)},required:[`key`]}},...n,{name:`change`,description:'Change lines of one thing without sending all of it. Each change names a path into its fields, with dots and list positions ("story.what", "story.checks.2.text"). `set` puts a value there, `insert` adds to a list at that position, `remove` takes out, `move` moves to `to`.',inputSchema:{type:`object`,properties:{key:q(`the thing to change`),changes:{type:`array`,minItems:1,items:{type:`object`,properties:{op:{type:`string`,enum:[`set`,`insert`,`remove`,`move`]},path:{type:`string`},value:{},to:{type:`string`}},required:[`op`,`path`]}}},required:[`key`,`changes`]}},{name:`remove`,description:`Remove one thing. It is taken out of whatever pointed at it.`,inputSchema:{type:`object`,properties:{key:q(`the thing to remove`)},required:[`key`]}},...e.queue?[{name:`queue`,description:`Put code work in the queue for the team’s coding agent, once the map’s part is done: what the code must do, the abilities it is for, and the checks that must pass on main for it to be done. Once for what was asked, last.`,inputSchema:(({by:e,...n})=>({type:`object`,properties:n,required:t.queue.schema.required??[]}))(t.queue.schema.properties??{})}]:[]]}function Z(e,n){let r=n.data[n.kind]??{},i={key:n.key,title:t(n),...r.status?{status:r.status}:{}};switch(n.kind){case`story`:return{...i,stage:e.stage(n),who:r.who??[],where:r.where??[],checks:(r.checks??[]).length};case`place`:return{...i,route:r.route,under:r.under};case`queue`:return{key:n.key,asked:r.asked,for:r.for??[],done:r.done??[],..._(r.done,e.results())?{finished:!0}:{}};default:return i}}async function Q(e,t,n={}){try{let r=await $(e,t,n??{});return{text:typeof r==`string`?r:JSON.stringify(r,null,2)}}catch(e){if(e instanceof p)return{text:e.message,failed:!0};throw e}}async function $(t,r,i){let a=t.all(),o=e=>Object.values(a).filter(t=>t.kind===e),c=e=>a[String(e??``)]??Promise.reject(new p(`There is no thing with the id "${e??``}".`)),l=(r,i)=>e(a,i?n(r,t.kinds[i].schema):r);if(r.startsWith(`write_`)){let e=r.slice(6);if(!t.kinds[e]||K.includes(e))throw new p(`There is no tool "${r}".`);let n=t.kinds[e].one?[{...i,key:o(e)[0]?.key}]:i.items;if(!Array.isArray(n)||!n.length)throw new p("Give `items`: a list of what to write.");let s=[];for(let{key:r,...i}of n){if(r&&a[r]?.kind!==e)throw new p(`There is no ${e} with the id "${r}". Leave the key out to make a new one.`);let{n,...o}=r?a[r].data[e]:{},c=r?await t.put(r,{...o,...l(i,e)}):await t.make(e,l(i,e));a[c.key]=c,s.push(Z(t,c))}return s}switch(r){case`overview`:{let e=a.B1?.data.brief,n=o(`story`),r=W(a,t.results()),i=o(`queue`),s=i.filter(e=>_(e.data.queue.done,t.results())).map(e=>e.key),c=i.filter(e=>!e.data.queue.done?.some(Boolean)).map(e=>e.key);return{why:e?{name:e.name,idea:e.idea}:`There is no brief yet.`,personas:o(`persona`).map(e=>Z(t,e)),abilities:Object.fromEntries(h.map(e=>[e,n.filter(n=>t.stage(n)===e).length])),places:o(`place`).length,documents:[`document`,`script`,`voice`,`look`].flatMap(o).map(e=>Z(t,e)),decisions:o(`decision`).map(e=>Z(t,e)),waiting:i.map(e=>Z(t,e)),needsAttention:[...U.filter(e=>r[e].length).map(e=>`${J[e]}: ${r[e].join(`, `)}`),...s.length?[`Code work whose checks all pass, to remove: ${s.join(`, `)}`]:[],...c.length?[`Code work that names no checks: ${c.join(`, `)}`]:[]]}}case`list`:{if(!t.kinds[i.kind])throw new p(`"${i.kind??``}" is not a kind. The kinds are ${Object.keys(t.kinds).join(`, `)}.`);let e=String(i.search??``).trim().toLowerCase(),n=(e,n,r)=>!r||Object.entries(t.kinds[e.kind].refs??{}).some(([t,i])=>[i].flat()[0]===n&&[e.data[e.kind][t]??[]].flat().includes(r));return o(i.kind).filter(n=>!e||s(t.kinds,n).toLowerCase().includes(e)).filter(e=>n(e,`persona`,i.persona)&&n(e,`place`,i.place)&&n(e,`story`,i.story)&&(!i.stage||e.kind!==`story`||t.stage(e)===i.stage)).sort((e,t)=>Number(e.key.slice(1))-Number(t.key.slice(1))).map(e=>Z(t,e))}case`read`:{let e=await c(i.key),n=t.results(),r=e=>`results:\n${e.map(e=>` ${e}: ${n[e]?.state??`not run`}`).join(`
2
+ `)}\n`,a=e.kind===`queue`?(e.data.queue.done??[]).filter(Boolean):[],o=e.kind===`story`?`\nstage: ${t.stage(e)}\n${r((e.data.story.checks??[]).map(t=>`${e.key}.${t.id}`))}`:a.length?`\n${r(a)}`:e.kind===`queue`?`
3
3
  It names no checks: write the checks that will say it is done on its abilities first.
4
- `:``;return`${t.key}, a ${t.kind}:\n\n${m(e.kinds,t)}${o}`}case`change`:{let t=await s(n.key);if(!Array.isArray(n.changes)||!n.changes.length)throw new a("Give `changes`: a list of `{ op, path, value }`.");return Z(e,await e.change(t.key,l(n.changes)))}case`remove`:{let t=await s(n.key);return await e.drop(t.key),`Removed ${t.key}.`}case`queue`:{if(!e.queue)break;let t=String(n.asked??``).trim();if(!t)throw new a("Give `asked`: what the code must do.");let r=(Array.isArray(n.done)?n.done:[]).map(String);for(let e of r)if(!i[e.split(`.`)[0]]?.data.story?.checks?.some(t=>t.id===e.split(`.`)[1]))throw new a(`done: "${e}" is no check here. Write the check on its ability first, then name it by its id, such as S12.2.`);return Z(e,await e.queue({asked:t,for:(Array.isArray(n.for)?n.for:[]).map(String),done:r}))}}throw new a(`There is no tool "${t}".`)}var ee=`The map is the product's: who it is for, what they need to do, where that happens, and why. Read it before you work on anything it describes, and change it only through these tools: each thing is written through its kind's sheet, and what doesn't fit is turned down with what would.
4
+ `:``;return`${e.key}, a ${e.kind}:\n\n${s(t.kinds,e)}${o}`}case`change`:{let e=await c(i.key);if(!Array.isArray(i.changes)||!i.changes.length)throw new p("Give `changes`: a list of `{ op, path, value }`.");return Z(t,await t.change(e.key,l(i.changes)))}case`remove`:{let e=await c(i.key);return await t.drop(e.key),`Removed ${e.key}.`}case`queue`:{if(!t.queue)break;let e=String(i.asked??``).trim();if(!e)throw new p("Give `asked`: what the code must do.");let n=(Array.isArray(i.done)?i.done:[]).map(String);for(let e of n)if(!a[e.split(`.`)[0]]?.data.story?.checks?.some(t=>t.id===e.split(`.`)[1]))throw new p(`done: "${e}" is no check here. Write the check on its ability first, then name it by its id, such as S12.2.`);return Z(t,await t.queue({asked:e,for:(Array.isArray(i.for)?i.for:[]).map(String),done:n}))}}throw new p(`There is no tool "${r}".`)}var ee=`The map is the product's: who it is for, what they need to do, where that happens, and why. Read it before you work on anything it describes, and change it only through these tools: each thing is written through its kind's sheet, and what doesn't fit is turned down with what would.
5
5
 
6
6
  What it holds, each thing by its id:
7
7
  - A persona (P1) is one kind of person the product is for, named by their role.
@@ -36,11 +36,11 @@ However the work reaches you, it goes the same way:
36
36
 
37
37
  Asked to map this codebase (or to import it, bring it in, or set it up the Userforge way: all the same ask), map what is true today, on a branch, without stopping to ask, and open one pull request at the end. Direction that comes with the ask comes first: areas to focus on or leave out, who the product is for, names to use, how deep to go. Follow it, and say in the pull request how you did. Keep everything small and true: a thing earns its place by being something the team would point at, a check by being something two people would agree passes. Leave out what you would have to invent, and write again what the map already holds rather than writing it twice.
38
38
 
39
- 1. Survey: how the project is run and tested, where its routes or screens are, what kinds of user it knows (roles, permissions, plans), and what its README says it is for. Write the brief: a working name, the idea in a sentence, and who it is for. Divide the product into the areas a person would name, and map one area at a time.
39
+ 1. Survey: how the project is run and tested, where its routes or screens are, what kinds of user it knows (roles, permissions, plans), and what its README says it is for. A spec the project already keeps in another shape (stories with acceptance criteria, personas, wireframes, a README beside them) is the first source: bring each thing in it into the map as what it is, its acceptance criteria as checks, and say in the pull request which of its files the map now holds. Write the brief: a working name, the idea in a sentence, and who it is for. Divide the product into the areas a person would name, and map one area at a time.
40
40
  2. Places: one for each screen a person can reach, with its route, the place it stands under, and a rough sketch of it as blocks with its real labels. Leave out routes no person sees.
41
41
  3. Screenshots: if you can run the app and drive a browser (Playwright, Puppeteer, or a browser tool of your own), take one of each place: 1440 pixels wide, the whole page, PNG or JPEG under 6 MB, signed in as the persona who uses it where you can, showing made-up data and never a real customer's. Save each beside the map, as \`spec/where/shots/orders.png\`, and give its place \`shot: shots/orders.png\`. Where you can't run the app, leave them out and say why in the pull request.
42
42
  4. Personas: one for each kind of person the code distinguishes, named by role, with only what the code and its docs support. Two or three is typical; never more than six. Give each a sentence of where they are when they use the product (\`shows\`), which a picture of them can be drawn from later.
43
43
  5. Abilities: one for each thing a persona can do, said from their side ("I can cancel an order before it ships"), with who, where, two to four checks taken from what the code enforces and its tests assert, and in its notes what you inferred.
44
- 6. Tests: where a test already proves a check, put the check's id at the start of its name and change nothing else. With vitest, add the reporter (\`reporters: ['default', 'userforge/reporter']\`); with another runner, write \`spec/results.json\` from its results, as \`{ "S12.2": { "state": "pass", "by": "tests/orders.test.ts", "at": 0 } }\`. Run them, so their results are kept.
44
+ 6. Tests: where a test already proves a check, put the check's id at the start of its name and change nothing else. With vitest, add the reporter (\`reporters: ['default', 'userforge/reporter']\`, or \`['userforge/reporter', { spec: '../spec' }]\` where the tests run from a folder below the map's); with another runner, write \`spec/results.json\` from its results, as \`{ "S12.2": { "state": "pass", "by": "tests/orders.test.ts", "at": 0 } }\`. Run them, so their results are kept.
45
45
  7. What is still missing (\`npx userforge check\`): close what the code can close, and stop when what is left is what the code can't answer, or after three rounds. Then open the pull request: what you mapped, what you left out and why, and where you are unsure who something is for or why it exists.
46
46
  `;const ne=ee.trim(),re=te.trim();export{G as a,V as c,L as d,R as f,X as i,W as l,re as n,U as o,z as p,Q as r,B as s,ne as t,H as u};
@@ -1,18 +1,39 @@
1
1
  /**
2
2
  * A vitest reporter that keeps each check's result. A test named after a check ("S12.2 …") passes or fails that
3
3
  * check. The results are kept in `spec/results.json` (or the file it is given), committed with the code they are the
4
- * results of; and, when the run is given `USERFORGE_URL` and a workspace's `USERFORGE_KEY`, told to that workspace.
4
+ * results of, and a check the map no longer has keeps none; and, when the run is given `USERFORGE_URL` and a
5
+ * workspace's `USERFORGE_KEY`, told to that workspace.
5
6
  *
6
7
  * reporters: ['default', 'userforge/reporter']
8
+ *
9
+ * It is told how a run went test by test under vitest 3, and once at its end under vitest 2.
7
10
  */
8
11
  import type { Reporter, TestCase } from 'vitest/node';
9
12
  import { type Results } from './results.ts';
13
+ /** A test as vitest 2 hands it over at the end of a run: a file's tasks, each a suite holding more or a test with how it went. */
14
+ type Task = {
15
+ type?: string;
16
+ name: string;
17
+ result?: {
18
+ state?: string;
19
+ };
20
+ tasks?: Task[];
21
+ };
10
22
  export default class implements Reporter {
11
23
  ran: Results;
12
24
  file: string;
25
+ spec: string;
26
+ /** Whether this run was told test by test (vitest 3), so its end needs walking for nothing. */
27
+ heard: boolean;
13
28
  constructor(options?: {
14
29
  file?: string;
30
+ spec?: string;
15
31
  });
16
32
  onTestCaseResult(testCase: TestCase): void;
17
33
  onTestRunEnd(): Promise<void>;
34
+ /** Vitest 2 tells how the run went only at its end: every test of every file, walked, kept as vitest 3's are told. */
35
+ onFinished(files?: (Task & {
36
+ name: string;
37
+ })[]): Promise<void>;
18
38
  }
39
+ export {};
package/dist/reporter.js CHANGED
@@ -1 +1 @@
1
- import{c as e,i as t,n,o as r,t as i}from"./results.js";import{t as a}from"./map.js";var o=class{ran={};file;constructor(e={}){this.file=e.file??`${a}/results.json`}onTestCaseResult(t){let n=i.exec(t.name)?.[1],r=t.result().state;n&&(r===`passed`||r===`failed`)&&(this.ran=e(this.ran,n,r===`passed`,t.module.relativeModuleId))}async onTestRunEnd(){if(!Object.keys(this.ran).length)return;t(this.file,this.ran);let e=n();e&&console.log(await r(e,this.ran).catch(e=>`Userforge was not told the results: ${e.message}`))}};export{o as default};
1
+ import{n as e,p as t,s as n}from"./map.js";import{c as r,i,n as a,o,t as s}from"./results.js";var c=class{ran={};file;spec;heard=!1;constructor(t={}){this.spec=t.spec??e,this.file=t.file??`${this.spec}/results.json`}onTestCaseResult(e){this.heard=!0;let t=s.exec(e.name)?.[1],n=e.result().state;t&&(n===`passed`||n===`failed`)&&(this.ran=r(this.ran,t,n===`passed`,e.module.relativeModuleId))}async onTestRunEnd(){if(this.heard=!0,!Object.keys(this.ran).length)return;let e=Object.keys(t(Object.values(n(this.spec).all).filter(e=>e.kind===`story`)));i(this.file,this.ran,e.length?new Set(e):void 0);let r=a();r&&console.log(await o(r,this.ran).catch(e=>`Userforge was not told the results: ${e.message}`))}async onFinished(e=[]){if(this.heard)return;let t=(e,n)=>{let i=e.type===`test`?s.exec(e.name)?.[1]:void 0,a=e.result?.state;i&&(a===`pass`||a===`fail`)&&(this.ran=r(this.ran,i,a===`pass`,n));for(let r of e.tasks??[])t(r,n)};for(let n of e)t(n,n.name);await this.onTestRunEnd()}};export{c as default};
package/dist/results.d.ts CHANGED
@@ -9,7 +9,7 @@ export declare const CHECK: RegExp;
9
9
  /** One more test's result for a check: a check proved by several tests passes only when all of them do. */
10
10
  export declare const tally: (ran: Results, id: string, passed: boolean, by: string) => Results;
11
11
  /** Results laid over the ones a file already keeps, in the order of their checks: a run of some tests changes only the checks it ran. */
12
- export declare function keep(file: string, ran: Results): Results;
12
+ export declare function keep(file: string, ran: Results, checks?: Set<string>): Results;
13
13
  /** Where Userforge is and which workspace to speak to: `USERFORGE_URL`, and a key to it (from Settings, Code) as `USERFORGE_KEY`. */
14
14
  export interface Door {
15
15
  url: string;
package/dist/results.js CHANGED
@@ -1,2 +1,2 @@
1
- import{existsSync as e,readFileSync as t,writeFileSync as n}from"node:fs";const r=/^(S\d+\.\d+) /,i=e=>e.slice(1).split(`.`).map(Number),a=(e,t,n,r)=>({...e,[t]:{state:n&&e[t]?.state!==`fail`?`pass`:`fail`,by:r,at:Date.now()}});function o(r,a){let o=e(r)?JSON.parse(t(r,`utf8`)):{},s=Object.fromEntries(Object.entries({...o,...a}).sort(([e],[t])=>i(e)[0]-i(t)[0]||i(e)[1]-i(t)[1]));return n(r,JSON.stringify(s,null,` `)+`
2
- `),s}const s=(e=process.env)=>e.USERFORGE_URL&&e.USERFORGE_KEY?{url:e.USERFORGE_URL.replace(/\/$/,``),key:e.USERFORGE_KEY}:void 0,c=async(e,t,n)=>{let r=await fetch(`${e.url}${t}`,{method:n?`POST`:`GET`,headers:{Authorization:`Bearer ${e.key}`,...n?{"Content-Type":`application/json`}:{}},body:n?JSON.stringify(n):void 0}),i=await r.json().catch(()=>({}));if(!r.ok)throw Error(i.message??`Userforge answered ${r.status}.`);return i},l=async(e,t)=>(await c(e,`/api/report`,{results:Object.entries(t).map(([e,{state:t,by:n}])=>({check:e,state:t,by:n}))})).message,u=async e=>(await c(e,`/api/spec`)).files,d=async(e,t,n)=>(await c(e,`/api/site?origin=${encodeURIComponent(t)}${n?`&website=${encodeURIComponent(n)}`:``}`)).files,f=async(e,t)=>(await c(e,`/api/ids`,{kind:t})).id;export{u as a,a as c,o as i,s as n,l as o,f as r,d as s,r as t};
1
+ import{existsSync as e,readFileSync as t,writeFileSync as n}from"node:fs";const r=/^(S\d+\.\d+) /,i=e=>e.slice(1).split(`.`).map(Number),a=(e,t,n,r)=>({...e,[t]:{state:n&&e[t]?.state!==`fail`?`pass`:`fail`,by:r,at:Date.now()}});function o(r,a,o){let s=e(r)?JSON.parse(t(r,`utf8`)):{},c=Object.fromEntries(Object.entries({...s,...a}).filter(([e])=>!o||o.has(e)||e in a).sort(([e],[t])=>i(e)[0]-i(t)[0]||i(e)[1]-i(t)[1]));return n(r,JSON.stringify(c,null,` `)+`
2
+ `),c}const s=(e=process.env)=>e.USERFORGE_URL&&e.USERFORGE_KEY?{url:e.USERFORGE_URL.replace(/\/$/,``),key:e.USERFORGE_KEY}:void 0,c=async(e,t,n)=>{let r=await fetch(`${e.url}${t}`,{method:n?`POST`:`GET`,headers:{Authorization:`Bearer ${e.key}`,...n?{"Content-Type":`application/json`}:{}},body:n?JSON.stringify(n):void 0}),i=await r.json().catch(()=>({}));if(!r.ok)throw Error(i.message??`Userforge answered ${r.status}.`);return i},l=async(e,t)=>(await c(e,`/api/report`,{results:Object.entries(t).map(([e,{state:t,by:n}])=>({check:e,state:t,by:n}))})).message,u=async e=>(await c(e,`/api/spec`)).files,d=async(e,t,n)=>(await c(e,`/api/site?origin=${encodeURIComponent(t)}${n?`&website=${encodeURIComponent(n)}`:``}`)).files,f=async(e,t)=>(await c(e,`/api/ids`,{kind:t})).id;export{u as a,a as c,o as i,s as n,l as o,f as r,d as s,r as t};
package/dist/test.js CHANGED
@@ -1 +1 @@
1
- import{test as e}from"vitest";import{f as t,o as n,t as r}from"./map.js";const i=t=>(n,r,i)=>{if(!t[n])throw Error(`There is no check ${n}.`);e(`${n} ${t[n]}`,r,i)};let a;const o=(e,o,s)=>(a??=i(t(Object.values(n(r).all).filter(e=>e.kind===`story`))))(e,o,s);export{o as check,i as checker};
1
+ import{test as e}from"vitest";import{n as t,p as n,s as r}from"./map.js";const i=t=>(n,r,i)=>{if(!t[n])throw Error(`There is no check ${n}.`);e(`${n} ${t[n]}`,r,i)};let a;const o=(e,o,s)=>(a??=i(n(Object.values(r(t).all).filter(e=>e.kind===`story`))))(e,o,s);export{o as check,i as checker};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "userforge",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Build software the Userforge way: the map of who it is for, what they can do and where, kept beside the code.",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",
@@ -42,7 +42,7 @@
42
42
  },
43
43
  "peerDependencies": {
44
44
  "viewschema": "*",
45
- "vitest": ">=3"
45
+ "vitest": ">=2"
46
46
  },
47
47
  "peerDependenciesMeta": {
48
48
  "viewschema": {