userforge 0.0.0-stage → 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/mcp.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ import { type Store } from './store.ts';
2
+ /** The answer to one message; nothing for a notification. */
3
+ export declare function answer(store: Store, message: {
4
+ id?: unknown;
5
+ method?: string;
6
+ params?: Record<string, any>;
7
+ }): Promise<object | null>;
8
+ /** Serve the tools over stdin and stdout until stdin closes. */
9
+ export declare function serve(store?: Store): Promise<number>;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * What on a map needs someone, the same wherever it is asked (the app's front page and its lists, a coding agent's
3
+ * overview, the app's own model work): abilities with a check that fails, with no checks or with no place; places with
4
+ * no picture; notes to sort; and decisions still proposed.
5
+ */
6
+ import type { Thing } from './kinds.ts';
7
+ import type { Results } from './results.ts';
8
+ /** The block that makes a place a website: everything under it is its pages. */
9
+ export declare const SITE_BLOCK = "c-site";
10
+ /** A website: a place that carries the Site block. */
11
+ export declare const isSite: (place: Thing) => boolean;
12
+ /** The website a place is in: itself, or the nearest place it stands under, that is one. */
13
+ export declare function siteOf(all: Record<string, Thing>, place: Thing): Thing | undefined;
14
+ /** What something can need. */
15
+ export declare const NEEDS: readonly ["failing", "unchecked", "unplaced", "bare", "unsorted", "undecided"];
16
+ export type Need = (typeof NEEDS)[number];
17
+ /** The keys of everything that needs someone, by what it needs, given the last result of every check. */
18
+ export declare function needs(all: Record<string, Thing>, results: Results): Record<Need, string[]>;
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Notes, as people send them: whether one reads like a script's (mostly links, an advert for the sender's own site, or
3
+ * the stock phrases of selling links and traffic), and whether one still waits for someone. What reads like a script's
4
+ * is held apart as it arrives, and counts nowhere, unless someone has said a person wrote it.
5
+ */
6
+ /** Why a message looks like a script's (`links`, `advert`, `phrases`), or nothing for one a person wrote. */
7
+ export declare function spamOf(text: unknown): 'links' | 'advert' | 'phrases' | undefined;
8
+ type Note = {
9
+ data: {
10
+ feedback?: {
11
+ status?: unknown;
12
+ text?: unknown;
13
+ };
14
+ };
15
+ facts?: {
16
+ person?: boolean;
17
+ };
18
+ };
19
+ /** A note that reads like a script's, unless someone has said a person wrote it (`facts.person`). */
20
+ export declare const spammy: (note: Note) => boolean;
21
+ /** A note still waiting for someone: not dealt with, and not one that reads like a script's. */
22
+ export declare const waiting: (note: Note) => boolean;
23
+ export {};
@@ -0,0 +1,2 @@
1
+ export declare const MAP: string;
2
+ export declare const PROCESS: string;
@@ -0,0 +1,46 @@
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
+ It names no checks: write the checks that will say it is done on its abilities first.
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
+
6
+ What it holds, each thing by its id:
7
+ - A persona (P1) is one kind of person the product is for, named by their role.
8
+ - An ability (S12; a story in ids and tools) is one thing personas need to do, in the persona's own voice: who, what ("I can …"), when, and why ("so that …"). Its checks (S12.1, S12.2) say how anyone would know it works. Its stage is idea or planned, as people intend; building and live come from its checks' results on main and the branches at work on it, and are never written.
9
+ - A place (W3) is a screen, or anywhere else an ability happens; its route is the address people reach it at, with a colon before any part that varies (\`/orders/:id\`). A website is a place that carries the Site block, with its pages under it.
10
+ - The brief (B1) says why the product is being built. A document (M2) is one of the team's own; the storyline (N1), voice (V1) and look (L1) stand beside them.
11
+ - A question (R2) is something the team needs to find out; its findings (R2.1) say what was found, and how surely.
12
+ - A note (F7) is something a real person said, on the place they said it; the workspace keeps notes, and a repository doesn't.
13
+ - A source (C4) is something read, kept with its words. A claim cites one in the words it rests on, in any line: \`[the words](cite:C4)\`, several at once \`cite:C4,C9\`. Cite only a source that may be cited (never the team's own material), quote one only in its own words, and say a claim only as surely as its evidence allows.
14
+ - A decision (D3) is something settled, or proposed: what is decided, why, and what it rests on and affects, by id or one line of a thing (a check S12.2, a finding R2.1, a block of a place W3.2). Build to what is agreed. Where you think something a person wrote is wrong, propose a decision that points at it rather than change it.
15
+ - Code work (Q4) waits for a coding agent: what was asked, for which abilities, and the checks that say it is done.
16
+
17
+ How to use the tools: \`overview\` first, then \`list\` and \`read\`; read a thing before you change it. Make a thing, or write one again, with its \`write_\` tool: the fields you give replace those fields, and the rest stay. Change a line or two with \`change\`, and \`remove\` only what should go. Tie things together as you write them: an ability to its personas and places, a page to the personas it is written for and the abilities it serves.
18
+ `,te=`# How work is done here
19
+
20
+ This project is built from one map, kept in \`spec/\` beside the code, one file for each thing. Its tools come from \`npx userforge mcp\`, which \`.mcp.json\` names: connect them before you change the map.
21
+
22
+ However the work reaches you, it goes the same way:
23
+
24
+ 1. Pull main, then work on a branch of your own. \`npx userforge\` prints this, what is waiting and where the map stands.
25
+ 2. To take something waiting, \`read\` it (Q4): what was asked, by whom, for which abilities, and the checks that say it is done. If it names none, write them on its abilities first. Code work whose checks all pass is done: \`remove\` it.
26
+ 3. Read each ability before you build it: the ability, the places it names, and any decision that affects it.
27
+ 4. Change the map only through its tools, on your branch, beside the code it describes: its files reach main with the code. Never write those files yourself. Change a check's words before you change what it describes, and give a new check its test.
28
+ 5. Name each test after the check it proves, its id first: \`test('S12.2 shows who it is for', …)\`, or \`check('S12.2', …)\` from \`userforge/test\`. The reporter keeps every result in \`spec/results.json\`, the failing ones too: commit it with the code.
29
+ 6. Never set an ability's stage to building or live: those come from its checks' results.
30
+ 7. Build the least that makes a check pass, and delete what a change replaces, moot tests included. Never remove what a person wrote unless they ask.
31
+ 8. Run \`npx userforge check\` before you commit, and leave nothing it names.
32
+ 9. Open a pull request into main: what was asked, each ability it touched by its id, and each check's result. Taking something from the queue, name it (\`Q4\`) and \`remove\` it in the same pull request. Don't merge it yourself.
33
+ 10. When what was asked is a question, answer it to whoever asked, in markdown that reads by itself. A question changes nothing.
34
+
35
+ ## Mapping a codebase
36
+
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
+
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
+ 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
+ 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
+ 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
+ 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']\`, 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
+ 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
+ `;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};
@@ -0,0 +1,9 @@
1
+ export interface Waiting {
2
+ id: string;
3
+ asked: string;
4
+ abilities: string[];
5
+ done: string[];
6
+ /** Every check it names passes: the work is done, and only its file is left to remove. */
7
+ finished: boolean;
8
+ }
9
+ export declare function waiting(dir?: string): Waiting[];
@@ -0,0 +1,39 @@
1
+ /**
2
+ * A vitest reporter that keeps each check's result. A test named after a check ("S12.2 …") passes or fails that
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 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.
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.
10
+ */
11
+ import type { Reporter, TestCase } from 'vitest/node';
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
+ };
22
+ export default class implements Reporter {
23
+ ran: Results;
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;
28
+ constructor(options?: {
29
+ file?: string;
30
+ spec?: string;
31
+ });
32
+ onTestCaseResult(testCase: TestCase): void;
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>;
38
+ }
39
+ export {};
@@ -0,0 +1 @@
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};
@@ -0,0 +1,26 @@
1
+ export type Result = {
2
+ state: 'pass' | 'fail';
3
+ by: string;
4
+ at: number;
5
+ };
6
+ export type Results = Record<string, Result>;
7
+ /** A check's id at the start of a test's name. */
8
+ export declare const CHECK: RegExp;
9
+ /** One more test's result for a check: a check proved by several tests passes only when all of them do. */
10
+ export declare const tally: (ran: Results, id: string, passed: boolean, by: string) => Results;
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, checks?: Set<string>): Results;
13
+ /** Where Userforge is and which workspace to speak to: `USERFORGE_URL`, and a key to it (from Settings, Code) as `USERFORGE_KEY`. */
14
+ export interface Door {
15
+ url: string;
16
+ key: string;
17
+ }
18
+ export declare const door: (env?: Record<string, string | undefined>) => Door | undefined;
19
+ /** Tell the workspace these results: each check then shows its own. What Userforge said back. */
20
+ export declare const report: (to: Door, ran: Results) => Promise<string>;
21
+ /** The workspace's map, as the files a repo keeps it in: each by where it stands under `spec/`. */
22
+ export declare const pulled: (to: Door) => Promise<Record<string, string>>;
23
+ /** A website of the workspace as files, for a host of the team's own, with its sitemap written for that address (`origin`); the workspace's first website unless one is named. */
24
+ export declare const siteFrom: (to: Door, origin: string, website?: string) => Promise<Record<string, string>>;
25
+ /** The next id for a new thing of a kind, handed out by the workspace, so that no two branches take the same one. */
26
+ export declare const idFor: (to: Door, kind: string) => Promise<string>;
@@ -0,0 +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,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};
@@ -0,0 +1,12 @@
1
+ /**
2
+ * What a project needs to be built the Userforge way, besides its map: one line in AGENTS.md sending every coding agent
3
+ * to `npx userforge`, CLAUDE.md pointing at AGENTS.md (Claude Code reads only that), and `.mcp.json` giving every agent
4
+ * that reads it the map's tools (`npx userforge mcp`). What a project already has is added to, never written over.
5
+ * `userforge init` writes these, as does the Userforge app when it sets up a repository.
6
+ */
7
+ /** The line, for a map kept in `spec/` or in a folder of the project's own. */
8
+ export declare const lineFor: (spec?: string) => string;
9
+ /** The files set-up reads. */
10
+ export declare const SETUP_FILES: readonly ["AGENTS.md", "CLAUDE.md", ".mcp.json"];
11
+ /** The files to write, given what the project has (by path; absent is undefined): only those that change. */
12
+ export declare function setup(have: Partial<Record<(typeof SETUP_FILES)[number], string>>, spec?: string): Record<string, string>;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * How real an ability is. Idea and planned are what people say of it; building and live are facts, never set by hand:
3
+ * live once every one of its checks passes on main, building while one has a result that doesn't pass, or while a
4
+ * branch is at work on it.
5
+ */
6
+ import type { Results } from './results.ts';
7
+ export declare const STAGES: readonly ["idea", "planned", "building", "live"];
8
+ export type Stage = (typeof STAGES)[number];
9
+ /** A stage from what people intend (`idea` or `planned`), the results of its checks in order, and whether a branch touches it. */
10
+ export declare function stageOf(intent: unknown, results: (string | undefined)[], touched?: boolean): Stage;
11
+ /** Whether code work is done: it names the checks that say so, and every one of them passes. */
12
+ export declare const workDone: (checks: string[] | undefined, results: Results) => boolean;
13
+ /** An ability's stage, as its file and a file of results (`spec/results.json`, by check id) say. */
14
+ export declare const storyStage: (story: {
15
+ key: string;
16
+ data: {
17
+ story: {
18
+ stage?: string;
19
+ checks?: {
20
+ id: string;
21
+ }[];
22
+ };
23
+ };
24
+ }, results: Results) => Stage;
package/dist/stage.js ADDED
@@ -0,0 +1 @@
1
+ const e=[`idea`,`planned`,`building`,`live`];function t(e,t,n=!1){return t.length&&t.every(e=>e===`pass`)?`live`:n||t.some(Boolean)?`building`:e===`idea`?`idea`:`planned`}const n=(e,t)=>!!e?.some(Boolean)&&e.filter(Boolean).every(e=>t[e]?.state===`pass`),r=(e,n)=>t(e.data.story.stage,(e.data.story.checks??[]).map(t=>n[`${e.key}.${t.id}`]?.state));export{e as STAGES,t as stageOf,r as storyStage,n as workDone};
@@ -0,0 +1,34 @@
1
+ import { type Patch } from 'viewschema';
2
+ import type { Kinds, Thing } from './kinds.ts';
3
+ import { type Results } from './results.ts';
4
+ import { type Stage } from './stage.ts';
5
+ export interface Store {
6
+ /** The kinds it keeps, each with its sheet. */
7
+ kinds: Kinds;
8
+ /** Everything it holds, by key. */
9
+ all(): Record<string, Thing>;
10
+ /** The last result of every check, by its id (S12.2). */
11
+ results(): Results;
12
+ /** An ability's stage. */
13
+ stage(story: Thing): Stage;
14
+ /** Something new, under the next id for its kind. */
15
+ make(kind: string, data: Record<string, any>): Promise<Thing>;
16
+ /** Something written again under its id: what is given replaces what was there. */
17
+ put(key: string, data: Record<string, any>): Promise<Thing>;
18
+ /** Lines of something changed by their paths ("story.what", "story.checks.2.text"). */
19
+ change(key: string, patches: Patch[]): Promise<Thing>;
20
+ /** Something removed, and taken out of whatever pointed at it. */
21
+ drop(key: string): Promise<void>;
22
+ /** Code work put in the queue for a coding agent, in the name of whoever asked: only where someone asks for it (the app). */
23
+ queue?(work: {
24
+ asked: string;
25
+ for: string[];
26
+ done: string[];
27
+ }): Promise<Thing>;
28
+ }
29
+ /**
30
+ * A project's map, as its files keep it (`spec/`, or `USERFORGE_SPEC`). A new thing's id comes from the workspace
31
+ * when there is a key to it (`USERFORGE_URL`, `USERFORGE_KEY`), so two branches never take the same one; otherwise it
32
+ * is the next the files leave free. Every write leaves the front page written again.
33
+ */
34
+ export declare function filesStore(dir?: string, kinds?: Kinds): Store;
package/dist/test.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ import { type Checks } from './checks.ts';
2
+ export declare const checker: (checks: Checks) => (id: string, prove: () => unknown, timeout?: number) => void;
3
+ /** A test that proves one check of the map in `spec/` (or `USERFORGE_SPEC`). */
4
+ export declare const check: (id: string, prove: () => unknown, timeout?: number) => void;
package/dist/test.js ADDED
@@ -0,0 +1 @@
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};
@@ -0,0 +1,13 @@
1
+ import type { Store } from './store.ts';
2
+ export interface Tool {
3
+ name: string;
4
+ description: string;
5
+ inputSchema: Record<string, unknown>;
6
+ }
7
+ /** The tools a store offers: reading for anyone; writing each kind through its own sheet; code work queued where someone asks for it. */
8
+ export declare function tools(store: Store): Tool[];
9
+ /** One use of a tool: what it says back, and whether it turned the call down. */
10
+ export declare function call(store: Store, name: string, args?: Record<string, any>): Promise<{
11
+ text: string;
12
+ failed?: boolean;
13
+ }>;
package/package.json CHANGED
@@ -1,6 +1,66 @@
1
1
  {
2
- "name": "userforge",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
2
+ "name": "userforge",
3
+ "version": "0.1.1",
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
+ "type": "module",
6
+ "license": "UNLICENSED",
7
+ "homepage": "https://userforge.com",
8
+ "bin": {
9
+ "userforge": "dist/cli.js"
10
+ },
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/index.d.ts",
14
+ "default": "./dist/index.js"
15
+ },
16
+ "./fit": {
17
+ "types": "./dist/fit.d.ts",
18
+ "default": "./dist/fit.js"
19
+ },
20
+ "./stage": {
21
+ "types": "./dist/stage.d.ts",
22
+ "default": "./dist/stage.js"
23
+ },
24
+ "./test": {
25
+ "types": "./dist/test.d.ts",
26
+ "default": "./dist/test.js"
27
+ },
28
+ "./reporter": {
29
+ "types": "./dist/reporter.d.ts",
30
+ "default": "./dist/reporter.js"
31
+ },
32
+ "./package.json": "./package.json"
33
+ },
34
+ "files": [
35
+ "dist"
36
+ ],
37
+ "scripts": {
38
+ "build": "node build.js",
39
+ "test": "node build.js && vitest run",
40
+ "check": "tsc --noEmit",
41
+ "prepublishOnly": "npm test"
42
+ },
43
+ "peerDependencies": {
44
+ "viewschema": "*",
45
+ "vitest": ">=2"
46
+ },
47
+ "peerDependenciesMeta": {
48
+ "viewschema": {
49
+ "optional": true
50
+ },
51
+ "vitest": {
52
+ "optional": true
53
+ }
54
+ },
55
+ "devDependencies": {
56
+ "@types/node": "^24.0.0",
57
+ "rolldown": "^1.0.0-rc.1",
58
+ "typescript": "^6.0.3",
59
+ "viewschema": "file:vendor/viewschema-0.0.10.tgz",
60
+ "vitest": "^5.1.0",
61
+ "yaml": "^2.9.1"
62
+ },
63
+ "engines": {
64
+ "node": ">=22"
65
+ }
66
+ }