userforge 0.2.0 → 0.3.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 CHANGED
@@ -1,53 +1,20 @@
1
1
  # userforge
2
2
 
3
- The map's tools, command line, file format and test tools for a project built
4
- the Userforge way. The project keeps a map beside its code, in `spec/`: who it
5
- is for (personas), what each of them needs to be able to do (abilities, each
6
- with checks), and where that happens (places), one file per thing. An ability
7
- is a Gherkin file that reads as its user story; everything else is YAML,
8
- holding its data by key. Tests are named after the checks they prove, so the
9
- map always says what works.
3
+ The map of a product, kept beside its code in `spec/`: who it is for, what
4
+ they need to do, where, and why. One file per thing. This package is its
5
+ command line, its tools for coding agents, and its test helpers. No account,
6
+ and no network unless given a Userforge workspace.
10
7
 
11
- It needs nothing else: no account, and no network unless it is given a
12
- Userforge workspace.
13
-
14
- ## Install
8
+ ## Set up
15
9
 
16
10
  ```sh
17
11
  npm i -D userforge
18
12
  npx userforge init
19
13
  ```
20
14
 
21
- `init` creates `spec/` with a brief to start from, adds one line to
22
- `AGENTS.md`, points `CLAUDE.md` at it, and names the map's tools in
23
- `.mcp.json`. Nothing already there is written over. The line sends every
24
- coding agent here:
25
-
26
- > This project is built the Userforge way: run `npx userforge` and follow it.
27
-
28
- For a codebase that already exists, then ask your coding agent to **map this
29
- codebase**. It writes the brief, a place for each screen (with a screenshot,
30
- if it can run the app), personas, abilities with their checks, and names your
31
- tests after them, on a branch, and opens a pull request. Say "import" if you
32
- prefer, and add any direction: "Map this codebase, focusing on the admin side."
33
-
34
- ## The map's tools
35
-
36
- A coding agent reads and changes the map only through its tools, which
37
- `.mcp.json` names: `npx userforge mcp`, a Model Context Protocol server on
38
- stdin and stdout. Restart the agent after `init` so it picks them up.
39
-
40
- | | |
41
- |---|---|
42
- | `overview` | The brief, the personas, how many abilities stand at each stage, the places, the code work waiting, and what needs attention: abilities with a check that fails, no checks or no place, places with no picture, decisions still proposed, and code work whose checks all pass or that names none. |
43
- | `list`, `read` | Every thing of a kind, searched or tied to a persona, place or ability; one thing as its file holds it. |
44
- | `write_persona`, `write_story`, … | One for each kind, its input that kind's sheet. Makes a thing under the next id, or writes one again by its key. |
45
- | `change`, `remove` | A line or two changed by its path; a thing removed, and taken out of whatever pointed at it. |
46
-
47
- What a tool is given is fitted to its kind's sheet exactly as the Userforge
48
- app fits what a person writes there. What doesn't fit is turned down with what
49
- would, and nothing is written. Every write leaves `spec/README.md` written
50
- again.
15
+ `init` makes `spec/` with a brief and its front page, adds one line to `AGENTS.md`, points
16
+ `CLAUDE.md` at it, and names the map's tools in `.mcp.json`. Nothing already
17
+ there is written over. Then ask your coding agent to **map this codebase**.
51
18
 
52
19
  ## The map
53
20
 
@@ -55,19 +22,15 @@ again.
55
22
  |---|---|
56
23
  | `spec/why/` | The brief, documents, decisions, research and sources. |
57
24
  | `spec/who/` | Personas. |
58
- | `spec/what/` | Abilities, each with its checks (`S12.2` is check 2 of `S12`), in Gherkin. |
59
- | `spec/where/` | Places: screens, and a website's pages. Screenshots beside them, in `spec/where/shots/`. |
60
- | `spec/queue/` | Code work waiting for a coding agent, one file each. |
25
+ | `spec/what/` | Abilities, in Gherkin. |
26
+ | `spec/where/` | Places, with their screenshots in `shots/`. |
27
+ | `spec/queue/` | Code work waiting for a coding agent. |
61
28
  | `spec/results.json` | The last result of every check. |
62
- | `spec/README.md` | The front page, written from the files. Never edited by hand. |
29
+ | `spec/README.md` | Its front page: what each folder holds, and how to work here. Written for you. |
63
30
 
64
- Each file is named by its id, then what it is called, for people
65
- (`who/P2-weekday-regular.yaml`); it is found by its id, so a name that changes
66
- moves the file and nothing else. Everything points at things by their ids.
67
-
68
- An ability reads as its user story. Its tags are its id, its stage, its
69
- personas and its places; each check is a `Rule:` tagged with its id, and may
70
- hold examples that run as tests:
31
+ Each file is named by its id, then what it is called
32
+ (`who/P2-weekday-regular.yaml`), and found by its id. Everything points at
33
+ things by id. An ability reads as its user story:
71
34
 
72
35
  ```gherkin
73
36
  @S1 @planned @P2 @W1
@@ -76,9 +39,6 @@ Ability: reserve tomorrow’s sourdough with just my name and phone number
76
39
  When I’m on the sofa after dinner
77
40
  So that my loaf is waiting at 8:15
78
41
 
79
- @S1.1
80
- Rule: An order needs only a name and a phone number.
81
-
82
42
  @S1.3
83
43
  Rule: After the 7:30pm cutoff, tomorrow’s orders are closed.
84
44
 
@@ -88,40 +48,35 @@ Ability: reserve tomorrow’s sourdough with just my name and phone number
88
48
  Then it says Wednesday’s orders are closed
89
49
  ```
90
50
 
91
- The `As a …` line is written from the personas' roles; who an ability is for
92
- is its tags. Everything else is YAML, the thing's data by key, exactly as a
93
- workspace holds it:
51
+ Its tags are its id, stage, personas and places; the `As a …` line is written
52
+ from the personas. Each `Rule:` is a check, tagged with its id. Everything
53
+ else is YAML, by its data's own keys. An ability is building while a check
54
+ fails on main or a branch is at work on it, and live once every check passes
55
+ on main.
94
56
 
95
- ```yaml
96
- role: Weekday regular
97
- color: violet
98
- ```
99
-
100
- An ability's stage comes from its results. People say idea or planned; it is
101
- building while a check fails on main or a branch is at work on it, and live
102
- once every check passes on main.
57
+ Change the map only through its tools (`npx userforge mcp`, which `.mcp.json`
58
+ names); they fit what they are given to each kind's sheet, as the app does.
103
59
 
104
60
  ## Commands
105
61
 
106
62
  | | |
107
63
  |---|---|
108
- | `npx userforge` | What the map holds, how work is done here, what is waiting in `spec/queue/`, and where the map stands. |
109
- | `npx userforge init` | Sets the project up, or gives one that has its map what it lacks. |
110
- | `npx userforge mcp` | The map's tools, over stdin and stdout. |
111
- | `npx userforge format` | Writes every file again as the map writes it: named for what it is called, an ability in Gherkin. |
112
- | `npx userforge check` | Says what doesn't hold together: files that don't fit, pointers to nothing, pictures that aren't there, citations of what may not be cited, code work still waiting though its checks all pass, and checks of abilities being built that no test is named after (but those that waiting code work names). |
113
- | `npx userforge pull` | Writes a workspace's map into `spec/`. |
114
- | `npx userforge report [file]` | Tells a workspace the results in `spec/results.json`. |
115
- | `npx userforge site <address> [website]` | Writes a workspace's website into `site/`, for a host of your own. |
116
-
117
- `pull`, `report` and `site` need `USERFORGE_URL` and `USERFORGE_KEY`, your
118
- own key from Settings, Code. With them, the tools take each new thing's id
119
- from the workspace, so two branches never take the same one. `USERFORGE_SPEC` moves the
120
- map from `spec/`; `USERFORGE_TESTS` says where the tests are when they aren't
121
- in `tests/`, `test/` or `__tests__/`.
64
+ | `npx userforge` | How work is done here, what is waiting, and where the map stands. |
65
+ | `npx userforge init` | Sets the project up. |
66
+ | `npx userforge check` | What doesn't hold together. Run it before you commit. |
67
+ | `npx userforge pull` | A workspace's map, written into `spec/`. |
68
+ | `npx userforge report [file]` | `spec/results.json`, told to a workspace. |
69
+ | `npx userforge site <address> [website]` | A workspace's website, written into `site/`. |
70
+
71
+ `pull`, `report` and `site` need `USERFORGE_URL` and `USERFORGE_KEY` (Settings,
72
+ Code). With them, new ids come from the workspace, so two branches never take
73
+ the same one. `USERFORGE_SPEC` moves the map; `USERFORGE_TESTS` says where the
74
+ tests are.
122
75
 
123
76
  ## Tests
124
77
 
78
+ Name each test after the check it proves:
79
+
125
80
  ```ts
126
81
  import { check } from 'userforge/test';
127
82
 
@@ -130,19 +85,9 @@ check('S12.2', () => {
130
85
  });
131
86
  ```
132
87
 
133
- A test whose name starts with a check's id (`test('S12.2 …', …)`) proves it
134
- too. The vitest reporter keeps every result in `spec/results.json`; commit it
135
- with the code:
136
-
137
- ```ts
138
- // vitest.config.ts
139
- export default { test: { reporters: ['default', 'userforge/reporter'] } };
140
- ```
141
-
142
- A check's examples run under vitest with
143
- [QuickPickle](https://github.com/dnotes/quickpickle), each step defined once
144
- in `tests/steps.ts`. The reporter credits each example to the check it is
145
- under, by its tag:
88
+ A check's examples run with [QuickPickle](https://github.com/dnotes/quickpickle),
89
+ each step defined once. The reporter keeps every result in
90
+ `spec/results.json`; commit it with the code.
146
91
 
147
92
  ```ts
148
93
  // vitest.config.ts
@@ -152,36 +97,15 @@ import { exampled } from 'userforge/test';
152
97
  export default {
153
98
  plugins: [quickpickle()],
154
99
  test: {
155
- include: ['tests/**/*.test.ts', ...exampled()], // the ability files that hold examples
100
+ include: ['tests/**/*.test.ts', ...exampled()],
156
101
  setupFiles: ['tests/steps.ts'],
157
102
  reporters: ['default', 'userforge/reporter']
158
103
  }
159
104
  };
160
105
  ```
161
106
 
162
- ## What an agent is told
163
-
164
- [`map.md`](map.md) says what the map holds and how its tools are used;
165
- [`process.md`](process.md) says how work is done in a Userforge project,
166
- mapping an existing codebase included. `npx userforge` prints both, and the
167
- tools carry both as their instructions. Update this package to get newer ones.
168
-
169
- ## In code
170
-
171
- `import { … } from 'userforge'`: the tools (`tools`, `call`) over a map kept
172
- anywhere (`Store`; `filesStore` for `spec/`); fitting a thing to its kind's
173
- sheet (`fitThing`) and what on it needs someone (`needs`), also alone as
174
- `userforge/fit` for an app that has viewschema itself; the file format (`fromFile`, `toFile`, `featureOf`, `yamlOf`, `pathOf`,
175
- `overview`, `format`) and the kinds (`kinds`); a map read and checked (`readMap`,
176
- `faults`, `init`); checks and results (`checksIn`, `unproved`, `keep`,
177
- `resultsIn`); stages (`stageOf`, `storyStage`, also alone as
178
- `userforge/stage`); set-up (`setup`, `lineFor`); and what an agent is told
179
- (`MAP`, `PROCESS`).
180
-
181
107
  ## Working on this package
182
108
 
183
- `npm test` builds `dist/` and runs the tests, and runs before every
184
- `npm publish`. What is published is `dist/` alone, minified, with viewschema
185
- bundled into it; `dist/` is committed too, so the repository installs with no
186
- build step. `kinds.json` is written by the Userforge app (`npm run userforge:vendor`
187
- there) and never edited here.
109
+ `npm test` builds `dist/` and runs the tests. `dist/` is committed, so the
110
+ repository installs with no build step. `kinds.json` is written by the
111
+ Userforge app (`npm run userforge:vendor` there), never here.
package/dist/cli.js CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env node
2
- import{spawnSync as e}from"node:child_process";import{existsSync as t,mkdirSync as n,readFileSync as r,rmSync as i,writeFileSync as a}from"node:fs";import{dirname as o,join as s,relative as c}from"node:path";import{a as l,g as u,h as d,i as f,l as p,n as m,o as h,q as g,s as _,t as v,u as y}from"./map.js";import{createInterface as b}from"node:readline";import{a as x,i as S,n as C,r as w,t as T}from"./process.js";import{storyStage as E,workDone as D}from"./stage.js";import{a as O,n as k,o as A,s as j}from"./results.js";var M=`0.2.0`;const N=[`2025-11-25`,`2025-06-18`,`2025-03-26`,`2024-11-05`];async function P(e,t){let{id:n,method:r,params:i={}}=t??{};if(n==null)return null;let a=e=>({jsonrpc:`2.0`,id:n,result:e});try{switch(r){case`initialize`:return a({protocolVersion:N.includes(i.protocolVersion)?i.protocolVersion:N[0],capabilities:{tools:{}},serverInfo:{name:`userforge`,version:M},instructions:`${T}\n\n${C}`});case`ping`:return a({});case`tools/list`:return a({tools:S(e)});case`tools/call`:{let{text:t,failed:n}=await w(e,String(i.name??``),i.arguments);return a({content:[{type:`text`,text:t}],...n?{isError:!0}:{}})}default:return{jsonrpc:`2.0`,id:n,error:{code:-32601,message:`Method not found: ${r}`}}}}catch(e){return{jsonrpc:`2.0`,id:n,error:{code:-32603,message:e.message}}}}function F(e=x()){return new Promise(t=>{let n=b({input:process.stdin}),r=Promise.resolve();n.on(`line`,t=>{if(!t.trim())return;let n;try{n=JSON.parse(t)}catch{process.stdout.write(`${JSON.stringify({jsonrpc:`2.0`,id:null,error:{code:-32700,message:`Parse error`}})}\n`);return}r=r.then(()=>P(e,n)).then(e=>e&&process.stdout.write(`${JSON.stringify(e)}\n`))}),n.on(`close`,()=>void r.then(()=>t(0)))})}function I(e=m){let t=y(e);return Object.values(p(e).all).filter(e=>e.kind===`queue`).sort((e,t)=>Number(e.key.slice(1))-Number(t.key.slice(1))).map(e=>{let n=(e.data.queue.done??[]).filter(Boolean);return{id:e.key,asked:String(e.data.queue.asked??``),abilities:e.data.queue.for??[],done:n,finished:D(n,t)}})}const L=process.env.USERFORGE_TESTS??u(),R=c(process.cwd(),m)||`spec`,z=e=>e.length&&console.log(e.join(`
3
- `)),B=(e,t,n=`${t}s`)=>`${e} ${e===1?t:n}`,V=e=>k()?void 0:(console.error(`usage: USERFORGE_URL=… USERFORGE_KEY=… userforge ${e}`),2);function H(){let{all:e}=p(),t=t=>Object.values(e).filter(e=>e.kind===t),n=t(`story`),r=y(),i=n.filter(e=>E(e,r)===`live`).length,a=f(m,L).length;return[`The map holds ${B(t(`persona`).length,`persona`)}, ${B(n.length,`ability`,`abilities`)} (${i} live) with ${B(Object.keys(d(n)).length,`check`)}, and ${B(t(`place`).length,`place`)};`,a?`${B(a,`thing doesn't`,`things don't`)} hold together: \`npx userforge check\` says which.`:`it holds together.`].join(` `)}const U=e=>[e.abilities.length&&`for ${e.abilities.join(`, `)}`,e.finished?`done: ${e.done.join(`, `)} pass, so remove it`:e.done.length?`done when ${e.done.join(`, `)} pass`:`no checks say when it is done: write them first`].filter(Boolean).join(`; `),W=["The site is changed in Userforge and taken again with this command, never edited here. `_redirects` lists old address, new address, 301.",`Cloudflare Pages: npx wrangler pages deploy site --project-name <name>, then add the domain under the project’s custom domains.`,`Firebase Hosting: point hosting.public at the folder in firebase.json, with "cleanUrls": true, run firebase deploy --only hosting, then add the domain under Hosting’s custom domains and the DNS records it shows.`,`Then open the address: the home page loads, a link to another page works, and the sign-up form answers.`],G={"":()=>{let e=I(m);return z([T,``,C,``,`## Waiting in ${R}/queue/`,``,...e.length?e.map(e=>`- ${e.id}: ${e.asked.split(`
4
- `)[0]}${U(e)?` (${U(e)})`:``}`):[`Nothing is waiting.`],``,t(m)?H():`There is no map in ${R}/ yet: \`npx userforge init\` sets one up.`]),0},init:()=>{let n=t(m),r=n&&t(s(m,`README.before.md`)),i=[...n?[]:[`${R}/`],...h()],a=!Object.values(p().all).some(e=>[`persona`,`story`,`place`].includes(e.kind)),o=e(`git`,[`check-ignore`,`-q`,s(m,`README.md`)]).status===0;return z([i.length?`Set up ${i.join(`, `)}.`:`It is set up already.`,...!r&&t(s(m,`README.before.md`))?[`The README.md that was in ${R}/ is kept as ${R}/${v}; the map's own front page is ${R}/README.md.`]:[],...o?[`git leaves ${R}/ out (.gitignore): take it out, or the map never reaches the repository, nor a workspace linked to it.`]:[],...a?[``,`Next, ask your coding agent: “Map this codebase.” Add any direction you like, such as “Map this codebase, focusing on the admin side.” It maps it on a branch and opens a pull request.`,"For a new project with no code yet, run `npx userforge` and follow it."]:[]]),0},mcp:()=>F(),check:()=>{let e=f(m,L);return z(e),+!!e.length},format:()=>{let{wrote:e,left:t}=l();return z([e.length?`${B(e.length,`file`)} written again.`:`Every file is written as the map writes it.`,...t.length?[``,`Left as they are, until what is wrong in them is put right:`,...t]:[]]),+!!t.length},async pull(){let e=await O(k()),r=t(m)?p().paths:{};for(let t of Object.keys(e)){let e=r[g(_,t)?.key??``];e&&e!==t&&i(s(m,e),{force:!0})}for(let[t,r]of Object.entries(e))n(o(s(m,t)),{recursive:!0}),a(s(m,t),r);return console.log(`${B(Object.keys(e).length-1,`thing`)} written to ${R}/.`),0},report:async([e=s(m,`results.json`)])=>(console.log(await A(k(),JSON.parse(r(e,`utf8`)))),0),async site([e,t]){if(!/^https?:\/\/[^/\s]+$/.test(e??``))return console.error(`usage: userforge site <address, such as https://www.example.com> [website id]`),2;let r=await j(k(),e,t);for(let[e,t]of Object.entries(r))n(o(s(`site`,e)),{recursive:!0}),a(s(`site`,e),t);return z([`${B(Object.keys(r).length,`file`)} written to site/.`,``,...W]),0}},[K=``,...q]=process.argv.slice(2),J=G[K];J?Promise.resolve().then(()=>[`pull`,`report`,`site`].includes(K)?V(K)??J(q):J(q)).then(e=>void(process.exitCode=e),e=>(console.error(e.message),process.exitCode=1)):(console.error(`usage: userforge [init | mcp | check | format | pull | report [results.json] | site <address> [website]]`),process.exitCode=2);export{};
2
+ import{spawnSync as e}from"node:child_process";import{existsSync as t,mkdirSync as n,readFileSync as r,rmSync as i,writeFileSync as a}from"node:fs";import{dirname as o,join as s,relative as c}from"node:path";import{a as l,c as u,h as d,i as f,l as p,m,n as h,o as g,q as _,t as v}from"./map.js";import{createInterface as y}from"node:readline";import{a as b,i as x,n as S,r as C,t as w}from"./process.js";import{storyStage as T,workDone as E}from"./stage.js";import{a as D,n as O,o as k,s as A}from"./results.js";var j=`0.3.0`;const M=[`2025-11-25`,`2025-06-18`,`2025-03-26`,`2024-11-05`];async function N(e,t){let{id:n,method:r,params:i={}}=t??{};if(n==null)return null;let a=e=>({jsonrpc:`2.0`,id:n,result:e});try{switch(r){case`initialize`:return a({protocolVersion:M.includes(i.protocolVersion)?i.protocolVersion:M[0],capabilities:{tools:{}},serverInfo:{name:`userforge`,version:j},instructions:`${w}\n\n${S}`});case`ping`:return a({});case`tools/list`:return a({tools:x(e)});case`tools/call`:{let{text:t,failed:n}=await C(e,String(i.name??``),i.arguments);return a({content:[{type:`text`,text:t}],...n?{isError:!0}:{}})}default:return{jsonrpc:`2.0`,id:n,error:{code:-32601,message:`Method not found: ${r}`}}}}catch(e){return{jsonrpc:`2.0`,id:n,error:{code:-32603,message:e.message}}}}function P(e=b()){return new Promise(t=>{let n=y({input:process.stdin}),r=Promise.resolve();n.on(`line`,t=>{if(!t.trim())return;let n;try{n=JSON.parse(t)}catch{process.stdout.write(`${JSON.stringify({jsonrpc:`2.0`,id:null,error:{code:-32700,message:`Parse error`}})}\n`);return}r=r.then(()=>N(e,n)).then(e=>e&&process.stdout.write(`${JSON.stringify(e)}\n`))}),n.on(`close`,()=>void r.then(()=>t(0)))})}function F(e=h){let t=p(e);return Object.values(u(e).all).filter(e=>e.kind===`queue`).sort((e,t)=>Number(e.key.slice(1))-Number(t.key.slice(1))).map(e=>{let n=(e.data.queue.done??[]).filter(Boolean);return{id:e.key,asked:String(e.data.queue.asked??``),abilities:e.data.queue.for??[],done:n,finished:E(n,t)}})}const I=process.env.USERFORGE_TESTS??d(),L=c(process.cwd(),h)||`spec`,R=e=>e.length&&console.log(e.join(`
3
+ `)),z=(e,t,n=`${t}s`)=>`${e} ${e===1?t:n}`,B=e=>O()?void 0:(console.error(`usage: USERFORGE_URL=… USERFORGE_KEY=… userforge ${e}`),2);function V(){let{all:e}=u(),t=t=>Object.values(e).filter(e=>e.kind===t),n=t(`story`),r=p(),i=n.filter(e=>T(e,r)===`live`).length,a=f(h,I).length;return[`The map holds ${z(t(`persona`).length,`persona`)}, ${z(n.length,`ability`,`abilities`)} (${i} live) with ${z(Object.keys(m(n)).length,`check`)}, and ${z(t(`place`).length,`place`)};`,a?`${z(a,`thing doesn't`,`things don't`)} hold together: \`npx userforge check\` says which.`:`it holds together.`].join(` `)}const H=e=>[e.abilities.length&&`for ${e.abilities.join(`, `)}`,e.finished?`done: ${e.done.join(`, `)} pass, so remove it`:e.done.length?`done when ${e.done.join(`, `)} pass`:`no checks say when it is done: write them first`].filter(Boolean).join(`; `),U=["The site is changed in Userforge and taken again with this command, never edited here. `_redirects` lists old address, new address, 301.",`Cloudflare Pages: npx wrangler pages deploy site --project-name <name>, then add the domain under the project’s custom domains.`,`Firebase Hosting: point hosting.public at the folder in firebase.json, with "cleanUrls": true, run firebase deploy --only hosting, then add the domain under Hosting’s custom domains and the DNS records it shows.`,`Then open the address: the home page loads, a link to another page works, and the sign-up form answers.`],W={"":()=>{let e=F(h);return R([w,``,S,``,`## Waiting in ${L}/queue/`,``,...e.length?e.map(e=>`- ${e.id}: ${e.asked.split(`
4
+ `)[0]}${H(e)?` (${H(e)})`:``}`):[`Nothing is waiting.`],``,t(h)?V():`There is no map in ${L}/ yet: \`npx userforge init\` sets one up.`]),0},init:()=>{let n=t(h),r=n&&t(s(h,`README.before.md`)),i=[...n?[]:[`${L}/`],...l()],a=!Object.values(u().all).some(e=>[`persona`,`story`,`place`].includes(e.kind)),o=e(`git`,[`check-ignore`,`-q`,s(h,`README.md`)]).status===0;return R([i.length?`Set up ${i.join(`, `)}.`:`It is set up already.`,...!r&&t(s(h,`README.before.md`))?[`The README.md that was in ${L}/ is kept as ${L}/${v}; the map's own front page is ${L}/README.md.`]:[],...o?[`git leaves ${L}/ out (.gitignore): take it out, or the map never reaches the repository, nor a workspace linked to it.`]:[],...a?[``,`Next, ask your coding agent: “Map this codebase.” Add any direction you like, such as “Map this codebase, focusing on the admin side.” It maps it on a branch and opens a pull request.`,"For a new project with no code yet, run `npx userforge` and follow it."]:[]]),0},mcp:()=>P(),check:()=>{let e=f(h,I);return R(e),+!!e.length},async pull(){let e=await D(O()),r=t(h)?u().paths:{};for(let t of Object.keys(e)){let e=r[_(g,t)?.key??``];e&&e!==t&&i(s(h,e),{force:!0})}for(let[t,r]of Object.entries(e))n(o(s(h,t)),{recursive:!0}),a(s(h,t),r);return console.log(`${z(Object.keys(e).filter(e=>e!==`README.md`).length,`thing`)} written to ${L}/.`),0},report:async([e=s(h,`results.json`)])=>(console.log(await k(O(),JSON.parse(r(e,`utf8`)))),0),async site([e,t]){if(!/^https?:\/\/[^/\s]+$/.test(e??``))return console.error(`usage: userforge site <address, such as https://www.example.com> [website id]`),2;let r=await A(O(),e,t);for(let[e,t]of Object.entries(r))n(o(s(`site`,e)),{recursive:!0}),a(s(`site`,e),t);return R([`${z(Object.keys(r).length,`file`)} written to site/.`,``,...U]),0}},[G=``,...K]=process.argv.slice(2),q=W[G];q?Promise.resolve().then(()=>[`pull`,`report`,`site`].includes(G)?B(G)??q(K):q(K)).then(e=>void(process.exitCode=e),e=>(console.error(e.message),process.exitCode=1)):(console.error(`usage: userforge [init | mcp | check | pull | report [results.json] | site <address> [website]]`),process.exitCode=2);export{};
package/dist/files.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { type Kinds, type Thing } from './kinds.ts';
2
- import type { Results } from './results.ts';
3
2
  /** A thing's data as YAML, by its own keys, in one order: what its file holds, whether or not its kind is kept in files. */
4
3
  export declare function yamlOf(kinds: Kinds, thing: Thing): string;
5
4
  /**
@@ -10,6 +9,11 @@ export declare function toFile(kinds: Kinds, thing: Thing, all?: Record<string,
10
9
  path: string;
11
10
  text: string;
12
11
  } | undefined;
12
+ /**
13
+ * Whether two texts of one file say the same thing, however each is spaced, ordered or commented: what each holds as
14
+ * written, before it is fitted. (A check written without its number, or a persona without its colour, says less.)
15
+ */
16
+ export declare function sameFile(kinds: Kinds, path: string, a: string, b: string): boolean;
13
17
  /**
14
18
  * A file read back into the thing it holds, fitted to its kind's sheet: what doesn't fit is said, by its path. Given
15
19
  * everything there is (`all`), what it points at and cites is checked too.
@@ -19,7 +23,10 @@ export declare function fromFile(kinds: Kinds, path: string, text: string, all?:
19
23
  problems: string[];
20
24
  said?: string;
21
25
  } | undefined;
22
- /** The line the map's front page opens with, which says it is written from the files beside it. */
23
- export declare const FRONT = "<!-- Written from the files beside it; what is changed here is written over. -->";
24
- /** The map's front page: the idea, the documents, who it is for and what each of them can do (at the stage its results say), and where. Written, never edited. */
25
- export declare function overview(kinds: Kinds, all: Record<string, Thing>, results?: Results): string;
26
+ /** The line the map's front page opens with, which says it is written for it. */
27
+ export declare const FRONT = "<!-- Written by userforge; what is changed here is written over. -->";
28
+ /**
29
+ * The map's front page, for whoever finds the folder: what the product is, what each folder holds, and how to work
30
+ * here. It changes only when the map does: a folder is first used, or the brief says something new. Written, never read.
31
+ */
32
+ export declare function overview(kinds: Kinds, all: Record<string, Thing>): string;
package/dist/fit.js CHANGED
@@ -1,3 +1,3 @@
1
- import{CITATION as e,extractSchema as t,fit as n,resolveSchema as r}from"viewschema";const i=/^[A-Z]\d+$/,a=()=>new RegExp(e.source,`g`),o=e=>[...new Set(e.split(/[,;]/).map(e=>e.trim()).filter(e=>i.test(e)))],s=(e,t)=>`[${e}](cite:${t.join(`,`)})`,c=e=>[...String(e??``).matchAll(a())].map(e=>({words:e[1],keys:o(e[2])}));function l(e,t,n=``){if(typeof e==`string`)t(n,e);else if(Array.isArray(e))e.forEach((e,r)=>l(e,t,n?`${n}.${r}`:String(r)));else if(e&&typeof e==`object`)for(let[r,i]of Object.entries(e))l(i,t,n?`${n}.${r}`:r)}function u(e,t,n=``){if(typeof e==`string`)return t(e,n);if(Array.isArray(e)){let r=e.map((e,r)=>u(e,t,n?`${n}.${r}`:String(r)));return r.some((t,n)=>t!==e[n])?r:e}if(e&&typeof e==`object`){let r=!1,i=Object.fromEntries(Object.entries(e).map(([e,i])=>{let a=u(i,t,n?`${n}.${e}`:e);return r||=a!==i,[e,a]}));return r?i:e}return e}function d(e){let t=[];return l(e,(e,n)=>n.includes(`](cite:`)&&t.push(...c(n).map(t=>({...t,path:e})))),t}const f=e=>[...new Set(d(e).flatMap(e=>e.keys))],p=e=>u(e,e=>e.includes(`](cite:`)?e.replace(a(),`$1`):e),m=e=>String(e??``).normalize(`NFKC`).toLowerCase().replace(/[‘’ʼ']/g,``).replace(/[^\p{L}\p{N}]+/gu,` `).trim();function h(e,t){let n=m(t);return n.split(` `).length>=4&&` ${m(e)} `.includes(` ${n} `)}const g=(e,t=``)=>/^\s*["“«„‘][^"”»“«„]*["”»“’][.,;:!?]?\s*$/.test(e)||/(^|\.)(quote|said)$/.test(t);function _(e,t){return u(e,(e,n)=>e.includes(`](cite:`)?e.replace(a(),(e,r,i)=>{let a=o(i).filter(e=>t(e)!==void 0&&(!g(r,n)||h(t(e),r)));return a.length?s(r,a):r}):e)}const v=e=>e?.file?.format===`gherkin`?`.feature`:`.yaml`,y=[`.yaml`,`.feature`];function b(e){let t=e.normalize(`NFKD`).replace(/[\u0300-\u036f]/g,``).toLowerCase().replace(/['’‘`]/g,``).replace(/[^a-z0-9]+/g,`-`).replace(/^-|-$/g,``);if(t.length<=48)return t;let n=t.slice(0,49);return(n.includes(`-`)?n.slice(0,n.lastIndexOf(`-`)):n.slice(0,48)).replace(/-$/,``)}const x=(e,t)=>{let n=e[t.kind],r=n?.file;if(!r)return;if(r.name)return`${r.dir}/${r.name}${v(n)}`;let i=t.data?b(w(t)):``;return`${r.dir}/${t.key}${i&&i!==t.key.toLowerCase()?`-${i}`:``}${v(n)}`};function S(e,t){let[n,r=``]=t.split(`/`).slice(-2),i=y.find(e=>r.endsWith(e));if(!i)return;let a=r.slice(0,-i.length);for(let[t,r]of Object.entries(e))if(r.file?.dir===n&&(r.file.name?r.file.name===a:RegExp(`^${r.letter}\\d+(?:-.*)?$`).test(a)))return{kind:t,key:r.file.name?`${r.letter}1`:a.split(`-`)[0],...i===v(r)?{}:{old:!0}}}const C=(e,t)=>Object.keys(e).find(n=>RegExp(`^${e[n].letter}\\d+$`).test(t)),w=e=>{let t=e?.data[e.kind]??{};return String(t.role||t.name||t.title||t.what||t.question||t.summary||t.text||t.asked||e?.key||``).trim()},ee=/\bhttps?:\/\/[^\s<>()"']+|\bwww\.[^\s<>()"']+\.[a-z]{2,}[^\s<>()"']*/gi,T=/^([^\n(]{2,80}\(\s*https?:\/\/[^)\s]+\s*\)|\s*https?:\/\/\S+)\s*[-–—:|]/,E=/\[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 D(e){let t=String(e??``).trim();if(!t)return;let n=t.match(ee)??[];if(n.length>=3||n.join(``).length>=t.length*.4)return`links`;if(T.test(t))return`advert`;if(E.test(t))return`phrases`}const O=e=>!e.facts?.person&&!!D(e.data.feedback?.text),k=e=>e.data.feedback?.status!==`done`&&!O(e),A=`c-site`,j=e=>(e.data.place?.blocks??[]).some(e=>e?.is===A);function M(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(j(n))return n}const N=[`failing`,`unchecked`,`unplaced`,`bare`,`unsorted`,`undecided`];function P(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=>!M(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(k)),undecided:r(n(`decision`).filter(e=>(e.data.decision.status??`proposed`)===`proposed`))}}var F=class extends Error{};const I=(e,t)=>`This doesn’t fit the ${e} sheet:\n- ${t.join(`
1
+ import{CITATION as e,extractSchema as t,fit as n,resolveSchema as r}from"viewschema";const i=/^[A-Z]\d+$/,a=()=>new RegExp(e.source,`g`),o=e=>[...new Set(e.split(/[,;]/).map(e=>e.trim()).filter(e=>i.test(e)))],s=(e,t)=>`[${e}](cite:${t.join(`,`)})`,c=e=>[...String(e??``).matchAll(a())].map(e=>({words:e[1],keys:o(e[2])}));function l(e,t,n=``){if(typeof e==`string`)t(n,e);else if(Array.isArray(e))e.forEach((e,r)=>l(e,t,n?`${n}.${r}`:String(r)));else if(e&&typeof e==`object`)for(let[r,i]of Object.entries(e))l(i,t,n?`${n}.${r}`:r)}function u(e,t,n=``){if(typeof e==`string`)return t(e,n);if(Array.isArray(e)){let r=e.map((e,r)=>u(e,t,n?`${n}.${r}`:String(r)));return r.some((t,n)=>t!==e[n])?r:e}if(e&&typeof e==`object`){let r=!1,i=Object.fromEntries(Object.entries(e).map(([e,i])=>{let a=u(i,t,n?`${n}.${e}`:e);return r||=a!==i,[e,a]}));return r?i:e}return e}function d(e){let t=[];return l(e,(e,n)=>n.includes(`](cite:`)&&t.push(...c(n).map(t=>({...t,path:e})))),t}const f=e=>[...new Set(d(e).flatMap(e=>e.keys))],p=e=>u(e,e=>e.includes(`](cite:`)?e.replace(a(),`$1`):e),m=e=>String(e??``).normalize(`NFKC`).toLowerCase().replace(/[‘’ʼ']/g,``).replace(/[^\p{L}\p{N}]+/gu,` `).trim();function h(e,t){let n=m(t);return n.split(` `).length>=4&&` ${m(e)} `.includes(` ${n} `)}const g=(e,t=``)=>/^\s*["“«„‘][^"”»“«„]*["”»“’][.,;:!?]?\s*$/.test(e)||/(^|\.)(quote|said)$/.test(t);function _(e,t){return u(e,(e,n)=>e.includes(`](cite:`)?e.replace(a(),(e,r,i)=>{let a=o(i).filter(e=>t(e)!==void 0&&(!g(r,n)||h(t(e),r)));return a.length?s(r,a):r}):e)}const v=e=>e?.file?.format===`gherkin`?`.feature`:`.yaml`,y=[`.yaml`,`.feature`];function b(e){let t=e.normalize(`NFKD`).replace(/[\u0300-\u036f]/g,``).toLowerCase().replace(/['’‘`]/g,``).replace(/[^a-z0-9]+/g,`-`).replace(/^-|-$/g,``);if(t.length<=48)return t;let n=t.slice(0,49);return(n.includes(`-`)?n.slice(0,n.lastIndexOf(`-`)):n.slice(0,48)).replace(/-$/,``)}const x=(e,t)=>{let n=e[t.kind],r=n?.file;if(!r)return;if(r.name)return`${r.dir}/${r.name}${v(n)}`;let i=t.data?b(w(t)):``;return`${r.dir}/${t.key}${i&&i!==t.key.toLowerCase()?`-${i}`:``}${v(n)}`};function S(e,t){let[n,r=``]=t.split(`/`).slice(-2);for(let[t,i]of Object.entries(e)){let e=v(i);if(i.file?.dir!==n||!r.endsWith(e))continue;let a=r.slice(0,-e.length);if(i.file.name?i.file.name===a:RegExp(`^${i.letter}\\d+(?:-.*)?$`).test(a))return{kind:t,key:i.file.name?`${i.letter}1`:a.split(`-`)[0]}}}const C=(e,t)=>Object.keys(e).find(n=>RegExp(`^${e[n].letter}\\d+$`).test(t)),w=e=>{let t=e?.data[e.kind]??{};return String(t.role||t.name||t.title||t.what||t.question||t.summary||t.text||t.asked||e?.key||``).trim()},T=/\bhttps?:\/\/[^\s<>()"']+|\bwww\.[^\s<>()"']+\.[a-z]{2,}[^\s<>()"']*/gi,E=/^([^\n(]{2,80}\(\s*https?:\/\/[^)\s]+\s*\)|\s*https?:\/\/\S+)\s*[-–—:|]/,D=/\[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 O(e){let t=String(e??``).trim();if(!t)return;let n=t.match(T)??[];if(n.length>=3||n.join(``).length>=t.length*.4)return`links`;if(E.test(t))return`advert`;if(D.test(t))return`phrases`}const k=e=>!e.facts?.person&&!!O(e.data.feedback?.text),A=e=>e.data.feedback?.status!==`done`&&!k(e),j=`c-site`,M=e=>(e.data.place?.blocks??[]).some(e=>e?.is===j);function N(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(M(n))return n}const P=[`failing`,`unchecked`,`unplaced`,`bare`,`unsorted`,`undecided`];function F(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=>!N(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(A)),undecided:r(n(`decision`).filter(e=>(e.data.decision.status??`proposed`)===`proposed`))}}var I=class extends Error{};const ee=(e,t)=>`This doesn’t fit the ${e} sheet:\n- ${t.join(`
2
2
  - `)}`,L=e=>e?.kind===`source`&&e.data.source.cite!==`no`,R=(e,t)=>_(t,t=>L(e[t])?String(e[t].data.source.text??``):void 0);function z(e,t){let n=e.data[e.kind]??{},r=n.blocks?.[Number(t)-1]??{};if(e.kind===`story`)return n.checks?.find(e=>e.id===t)?.text;if(e.kind===`research`)return n.findings?.[Number(t)-1]?.claim;if(e.kind===`place`)return Object.entries(r).find(([e,t])=>e!==`is`&&typeof t==`string`&&t)?.[1];if(e.kind===`document`||e.kind===`brief`)return r.label||r.left?.label}function B(e,t){let[,n,r]=/^([A-Z]\d+)(?:\.(\d+))?$/.exec(String(t??``).trim())??[],i=e[n??``];return!!i&&(!r||!!z(i,r))}const V=new Set(`section div header footer h2 h3 h4 p ul ol li dl dt dd blockquote figure figcaption table thead tbody tr th td span b strong i em small hr a img template`.split(` `)),H=/* @__PURE__ */ new Set([`img`,`hr`]),U=/^(href|src|alt|datetime|data-[a-z-]+|aria-[a-z-]+)$/,W=/^(class|alt|colspan|rowspan|data-vs-add-label|view-(text|markdown|each|if|object|title|prompt|optional|readonly|static|examples|default|declare|type|format|max-length|min-items|max-items|items))$/,G=e=>W.test(e)||U.test(/^view-(?:attr|optional|readonly|title|prompt):(.+)$/.exec(e)?.[1]??``),K=/<(\/?)([a-zA-Z][\w-]*)((?:\s+[^\s"'=<>/]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'=<>`]+))?)*)\s*(\/?)>/g;function q(e){let n=String(e??``).trim();if(!n)return`It has no template yet.`;if(n.length>12e3)return`It is longer than a block can be.`;if(/\{@|<!|<\?/.test(n))return`It holds something only this app writes: {@…}, a comment or a declaration.`;let r=[],i=0,a=0,o=0;if(n.replace(K,(e,t,n,s,c,l)=>{let u=n.toLowerCase();V.has(u)||r.push(`<${u}> can’t be used in a block.`);for(let[,e]of s.matchAll(/\s+([^\s"'=<>/]+)(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'=<>`]+))?/g))G(e.toLowerCase())||r.push(`The attribute “${e}” can’t be used in a block.`);return t?--i===0&&!o&&(o=l+e.length):(i===0&&a++,!H.has(u)&&!c&&i++),``}).includes(`<`)&&r.push(`It holds a tag that isn’t well formed.`),i!==0&&r.push(`A tag is opened and never closed, or closed and never opened.`),a===1&&n.startsWith(`<`)&&o===n.length||r.push(`It needs one element around everything in it.`),r.length)return r[0];try{t(n,{},{emptyStrings:!0})}catch(e){return e.message}}function J(e,t,n){let r=t[n]?.kind,i=[];for(let a of Object.values(t)){if(a.key===n)continue;let t=a.data[a.kind]??{},o=[];for(let[i,s]of Object.entries(e[a.kind]?.refs??{})){let e=t[i];if([s].flat()[0]!==r||(Array.isArray(e)?!e.includes(n):e!==n))continue;let{[i]:a,...c}=t;t=Array.isArray(e)?{...c,[i]:e.filter(e=>e!==n)}:c,o.push(i)}o.length&&i.push({thing:{...a,data:{[a.kind]:t}},fields:o})}return i}function Y(e){let t=String(e??``).split(`
3
- `),n,r=!1;for(let[e,i]of t.entries()){let t=i.trim();if(n)t.startsWith(n)&&(n=void 0);else if(!(!t||t.startsWith(`#`)||t.startsWith(`|`))){if(t.startsWith(`"""`)||t.startsWith("```"))n=t.slice(0,3);else if(/^(Given|When|Then|And|But) \S/.test(t)||/^\* \S/.test(t))r=!0;else return`line ${e+1} isn’t a step: start it with Given, When, Then, And or But.`}}if(n)return`a doc string is opened and never closed.`;if(!r&&String(e??``).trim())return`it has no steps: Given what is so, When something happens, Then what is true.`}const X=(e,t,n=t?.$defs??{})=>{let i=t&&r(t,n,e);return typeof e==`string`?i?.contentMediaType||/^(https?:|\/|#)/.test(e)?e:e.replace(/(^|[\s([{—–-])"/g,`$1“`).replace(/"/g,`”`).replace(/(^|[\s([{—–-])'/g,`$1‘`).replace(/'/g,`’`):Array.isArray(e)?e.map(e=>X(e,i?.items,n)):e&&typeof e==`object`?Object.fromEntries(Object.entries(e).map(([e,t])=>[e,X(t,i?.properties?.[e],n)])):e};function Z(e,t){if(e===t)return!0;if(typeof e!=`object`||typeof t!=`object`||!e||!t||Array.isArray(e)!==Array.isArray(t))return!1;let n=Object.keys(e).filter(t=>e[t]!==void 0),r=Object.keys(t).filter(e=>t[e]!==void 0);return n.length===r.length&&n.every(n=>Z(e[n],t[n]))}function Q(e,t){if(e.kind===`place`)return te(e.data,t);if(e.kind!==`story`)return e.data;let n=e.data.story,r=Math.max(Number(n.n)||0,...(n.checks??[]).map(e=>Number(e.id)||0)),i=(n.checks??[]).map(e=>e.id?e:{...e,id:String(++r)});return r===n.n&&i.every((e,t)=>e===n.checks[t])?e.data:{story:{...n,checks:i,n:r}}}function te(e,t){let n=e.place?.blocks;if(!n?.some(e=>e?.is===`w-table`))return e;let r=t?.path.match(/^place\.blocks\.(\d+)\.columns\.(\d+)$/),i=n.map((e,n)=>{if(e?.is!==`w-table`)return e;let i=(e.columns??[]).length,a=(e.rows??[]).map(e=>{let a=[...e.cells??[]];if(r&&Number(r[1])===n){let e=Number(r[2]);t.op===`insert`?a.splice(e,0,``):t.op===`remove`?a.splice(e,1):t.op===`move`&&a.splice(t.to,0,...a.splice(e,1))}let o=[...a.slice(0,i),...Array(Math.max(0,i-a.length)).fill(``)];return Z(o,e.cells)?e:{...e,cells:o}});return a.every((t,n)=>t===e.rows[n])?e:{...e,rows:a}});return i.every((e,t)=>e===n[t])?e:{...e,place:{...e.place,blocks:i}}}function $(e,t,n,{all:r={},had:i,key:a=i?.key,whole:o=!1}={}){let s=[],c=e[t];for(let[e,t]of Object.entries(c.refs??{})){let i=[t].flat()[0];for(let t of[n[e]??[]].flat())t&&r[t]?.kind!==i&&s.push(`${e}: there is no ${i} "${t}". Use \`list\` to see the ones there are.`)}let l=t=>o||!!e[C(e,t.split(`.`)[0])??``]?.file;for(let e of c.points??[])for(let t of[n[e]??[]].flat().filter(Boolean))!B(r,t)&&l(String(t))&&s.push(`${e}: "${t}" points at nothing here. A pointer is a thing’s id (P1, S12, W3, R2, F4), or one line of it: a check (S12.2), a finding (R2.1), a block of a place or a page of the website (W3.2).`);let u=new Set(f(i?.data[t]));for(let e of f(n).filter(e=>!u.has(e)))r[e]?.kind===`source`?L(r[e])||s.push(`cite:${e}: ${e} is the team’s own material, which informs what is written and is never cited.`):s.push(`cite:${e}: there is no source "${e}". A claim cites a source of the library by its key, in the words it rests on: [the words](cite:C1). Use \`list\` to see the sources there are.`);if(t===`place`&&n.under){let e=/* @__PURE__ */ new Set([a]);for(let t=n.under;t;t=r[t]?.data.place?.under)if(e.has(t)){s.push(`under: ${n.under} already stands under this place. A place can’t stand under itself, or under anything that stands under it.`);break}else e.add(t)}return s}function ne(e,t,r,i={}){let a=e[t];if(!a)return{value:{},problems:[`there is no kind "${t}".`]};let o=a.schema.$defs??{},s=a.schema.properties??{},c=i.had?.data[t]??{},{order:l,n:u,...d}=r??{},f=Object.fromEntries(Object.keys(c).filter(e=>!(e in s)).map(e=>[e,c[e]]));for(let e of Object.keys(d))!(e in s)&&e in c&&delete d[e];let p=t===`story`&&Array.isArray(d.checks)?d.checks.map(e=>e&&typeof e==`object`?e.id:void 0):[];if(t===`story`&&Array.isArray(d.checks)&&(d.checks=d.checks.map(e=>typeof e==`string`?{text:e}:e&&typeof e==`object`?Object.fromEntries(Object.entries(e).filter(([e])=>e!==`id`)):e)),t===`persona`&&!d.color){let e=Object.values(i.all??{}).filter(e=>e.kind===`persona`&&e.key!==i.key).map(e=>e.data.persona?.color),t=s.color?.enum??[];d.color=c.color??t.find(t=>!e.includes(t))??t[e.length%t.length]}let m={};for(let[e,t]of Object.entries(s))t?.items?.oneOf&&Array.isArray(d[e])&&(m[e]=d[e].map((e,t)=>[t,e]).filter(([,e])=>typeof e?.is==`string`&&!(e.is in o)),m[e].length&&(d[e]=d[e].filter(t=>!m[e].some(([,e])=>e===t))));let{value:h,problems:g}=n(a.schema,d);for(let[e,t]of Object.entries(m))for(let[n,r]of t)h[e].splice(n,0,r);if(t===`block`&&q(h.html)&&g.push(`html: ${q(h.html)}`),t===`story`&&(h.checks??[]).forEach((e,t)=>(e.examples??[]).forEach((e,n)=>{let r=Y(e.steps);r&&g.push(`checks.${t}.examples.${n}.steps: ${r}`)})),i.all&&g.push(...$(e,t,h,i)),t===`story`){let e=c.checks??[],t=/* @__PURE__ */ new Set,n=e=>/^\d+$/.test(String(e??``))&&!t.has(String(e))?(t.add(String(e)),String(e)):void 0,r=p.map(n),i=!p.some(e=>e!==void 0);h.checks=(h.checks??[]).map((t,a)=>({...t,id:r[a]??n(e.find(e=>e.text===t.text)?.id)??(i&&e[a]&&!h.checks.some(t=>t.text===e[a].text)?n(e[a].id):void 0)}))}return Object.assign(h,f,typeof l==`number`?{order:l}:{}),{value:Q({kind:t,data:{[t]:h}},i.patch)[t],problems:g}}export{y as EXTS,F as Misfit,N as NEEDS,A as SITE_BLOCK,Z as alike,w as called,L as citable,d as citationsIn,c as citationsOf,s as cited,u as eachChanged,l as eachLine,v as extOf,q as faultIn,ne as fitThing,R as held,_ as heldTo,j as isSite,f as keysIn,o as keysOf,C as kindOf,z as lineAt,I as misfitOf,P as needs,x as pathOf,B as pointed,g as quoted,$ as references,h as says,M as siteOf,b as slugOf,D as spamOf,O as spammy,Y as stepsFault,S as thingAt,Q as tidy,X as typeset,p as uncited,J as unnamed,k as waiting};
3
+ `),n,r=!1;for(let[e,i]of t.entries()){let t=i.trim();if(n)t.startsWith(n)&&(n=void 0);else if(!(!t||t.startsWith(`#`)||t.startsWith(`|`))){if(t.startsWith(`"""`)||t.startsWith("```"))n=t.slice(0,3);else if(/^(Given|When|Then|And|But) \S/.test(t)||/^\* \S/.test(t))r=!0;else return`line ${e+1} isn’t a step: start it with Given, When, Then, And or But.`}}if(n)return`a doc string is opened and never closed.`;if(!r&&String(e??``).trim())return`it has no steps: Given what is so, When something happens, Then what is true.`}const X=(e,t,n=t?.$defs??{})=>{let i=t&&r(t,n,e);return typeof e==`string`?i?.contentMediaType||/^(https?:|\/|#)/.test(e)?e:e.replace(/(^|[\s([{—–-])"/g,`$1“`).replace(/"/g,`”`).replace(/(^|[\s([{—–-])'/g,`$1‘`).replace(/'/g,`’`):Array.isArray(e)?e.map(e=>X(e,i?.items,n)):e&&typeof e==`object`?Object.fromEntries(Object.entries(e).map(([e,t])=>[e,X(t,i?.properties?.[e],n)])):e};function Z(e,t){if(e===t)return!0;if(typeof e!=`object`||typeof t!=`object`||!e||!t||Array.isArray(e)!==Array.isArray(t))return!1;let n=Object.keys(e).filter(t=>e[t]!==void 0),r=Object.keys(t).filter(e=>t[e]!==void 0);return n.length===r.length&&n.every(n=>Z(e[n],t[n]))}function Q(e,t){if(e.kind===`place`)return te(e.data,t);if(e.kind!==`story`)return e.data;let n=e.data.story,r=Math.max(Number(n.n)||0,...(n.checks??[]).map(e=>Number(e.id)||0)),i=(n.checks??[]).map(e=>e.id?e:{...e,id:String(++r)});return r===n.n&&i.every((e,t)=>e===n.checks[t])?e.data:{story:{...n,checks:i,n:r}}}function te(e,t){let n=e.place?.blocks;if(!n?.some(e=>e?.is===`w-table`))return e;let r=t?.path.match(/^place\.blocks\.(\d+)\.columns\.(\d+)$/),i=n.map((e,n)=>{if(e?.is!==`w-table`)return e;let i=(e.columns??[]).length,a=(e.rows??[]).map(e=>{let a=[...e.cells??[]];if(r&&Number(r[1])===n){let e=Number(r[2]);t.op===`insert`?a.splice(e,0,``):t.op===`remove`?a.splice(e,1):t.op===`move`&&a.splice(t.to,0,...a.splice(e,1))}let o=[...a.slice(0,i),...Array(Math.max(0,i-a.length)).fill(``)];return Z(o,e.cells)?e:{...e,cells:o}});return a.every((t,n)=>t===e.rows[n])?e:{...e,rows:a}});return i.every((e,t)=>e===n[t])?e:{...e,place:{...e.place,blocks:i}}}function $(e,t,n,{all:r={},had:i,key:a=i?.key,whole:o=!1}={}){let s=[],c=e[t];for(let[e,t]of Object.entries(c.refs??{})){let i=[t].flat()[0];for(let t of[n[e]??[]].flat())t&&r[t]?.kind!==i&&s.push(`${e}: there is no ${i} "${t}". Use \`list\` to see the ones there are.`)}let l=t=>o||!!e[C(e,t.split(`.`)[0])??``]?.file;for(let e of c.points??[])for(let t of[n[e]??[]].flat().filter(Boolean))!B(r,t)&&l(String(t))&&s.push(`${e}: "${t}" points at nothing here. A pointer is a thing’s id (P1, S12, W3, R2, F4), or one line of it: a check (S12.2), a finding (R2.1), a block of a place or a page of the website (W3.2).`);let u=new Set(f(i?.data[t]));for(let e of f(n).filter(e=>!u.has(e)))r[e]?.kind===`source`?L(r[e])||s.push(`cite:${e}: ${e} is the team’s own material, which informs what is written and is never cited.`):s.push(`cite:${e}: there is no source "${e}". A claim cites a source of the library by its key, in the words it rests on: [the words](cite:C1). Use \`list\` to see the sources there are.`);if(t===`place`&&n.under){let e=/* @__PURE__ */ new Set([a]);for(let t=n.under;t;t=r[t]?.data.place?.under)if(e.has(t)){s.push(`under: ${n.under} already stands under this place. A place can’t stand under itself, or under anything that stands under it.`);break}else e.add(t)}return s}function ne(e,t,r,i={}){let a=e[t];if(!a)return{value:{},problems:[`there is no kind "${t}".`]};let o=a.schema.$defs??{},s=a.schema.properties??{},c=i.had?.data[t]??{},{order:l,n:u,...d}=r??{},f=Object.fromEntries(Object.keys(c).filter(e=>!(e in s)).map(e=>[e,c[e]]));for(let e of Object.keys(d))!(e in s)&&e in c&&delete d[e];let p=t===`story`&&Array.isArray(d.checks)?d.checks.map(e=>e&&typeof e==`object`?e.id:void 0):[];if(t===`story`&&Array.isArray(d.checks)&&(d.checks=d.checks.map(e=>typeof e==`string`?{text:e}:e&&typeof e==`object`?Object.fromEntries(Object.entries(e).filter(([e])=>e!==`id`)):e)),t===`persona`&&!d.color){let e=Object.values(i.all??{}).filter(e=>e.kind===`persona`&&e.key!==i.key).map(e=>e.data.persona?.color),t=s.color?.enum??[];d.color=c.color??t.find(t=>!e.includes(t))??t[e.length%t.length]}let m={};for(let[e,t]of Object.entries(s))t?.items?.oneOf&&Array.isArray(d[e])&&(m[e]=d[e].map((e,t)=>[t,e]).filter(([,e])=>typeof e?.is==`string`&&!(e.is in o)),m[e].length&&(d[e]=d[e].filter(t=>!m[e].some(([,e])=>e===t))));let{value:h,problems:g}=n(a.schema,d);for(let[e,t]of Object.entries(m))for(let[n,r]of t)h[e].splice(n,0,r);if(t===`block`&&q(h.html)&&g.push(`html: ${q(h.html)}`),t===`story`&&(h.checks??[]).forEach((e,t)=>(e.examples??[]).forEach((e,n)=>{let r=Y(e.steps);r&&g.push(`checks.${t}.examples.${n}.steps: ${r}`)})),i.all&&g.push(...$(e,t,h,i)),t===`story`){let e=c.checks??[],t=/* @__PURE__ */ new Set,n=e=>/^\d+$/.test(String(e??``))&&!t.has(String(e))?(t.add(String(e)),String(e)):void 0,r=p.map(n),i=!p.some(e=>e!==void 0);h.checks=(h.checks??[]).map((t,a)=>({...t,id:r[a]??n(e.find(e=>e.text===t.text)?.id)??(i&&e[a]&&!h.checks.some(t=>t.text===e[a].text)?n(e[a].id):void 0)}))}return Object.assign(h,f,typeof l==`number`?{order:l}:{}),{value:Q({kind:t,data:{[t]:h}},i.patch)[t],problems:g}}export{y as EXTS,I as Misfit,P as NEEDS,j as SITE_BLOCK,Z as alike,w as called,L as citable,d as citationsIn,c as citationsOf,s as cited,u as eachChanged,l as eachLine,v as extOf,q as faultIn,ne as fitThing,R as held,_ as heldTo,M as isSite,f as keysIn,o as keysOf,C as kindOf,z as lineAt,ee as misfitOf,F as needs,x as pathOf,B as pointed,g as quoted,$ as references,h as says,N as siteOf,b as slugOf,O as spamOf,k as spammy,Y as stepsFault,S as thingAt,Q as tidy,X as typeset,p as uncited,J as unnamed,A as waiting};
package/dist/index.d.ts CHANGED
@@ -5,9 +5,9 @@
5
5
  * command line `npx userforge`.
6
6
  */
7
7
  export * from './fit.ts';
8
- export { fromFile, overview, toFile, yamlOf } from './files.ts';
8
+ export { fromFile, overview, sameFile, toFile, yamlOf } from './files.ts';
9
9
  export { articleOf, asLine, featureOf, fromFeature } from './gherkin.ts';
10
- export { exampled, faults, format, init, kinds, nextId, readMap, resultsIn, SPEC, written } from './map.ts';
10
+ export { exampled, faults, init, kinds, nextId, readMap, resultsIn, SPEC, written } from './map.ts';
11
11
  export { filesStore, type Store } from './store.ts';
12
12
  export { call, tools, type Tool } from './tools.ts';
13
13
  export { MAP, PROCESS } from './process.ts';
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{$ as e,A as t,B as n,C as r,D as i,E as a,F as o,G as s,H as c,I as l,J as u,K as d,L as f,M as p,N as m,O as h,P as g,Q as _,R as v,S as y,T as b,U as x,V as S,W as C,X as w,Y as T,Z as E,_ as D,a as O,b as k,c as A,d as j,et as M,f as N,g as P,h as F,i as I,it as L,j as R,k as z,l as B,m as V,n as H,nt as U,o as W,p as G,q as K,r as q,rt as J,s as Y,tt as X,u as Z,v as Q,w as $,x as ee,y as te,z as ne}from"./map.js";import{a as re,c as ie,d as ae,f as oe,i as se,l as ce,n as le,o as ue,p as de,r as fe,s as pe,t as me,u as he}from"./process.js";import{STAGES as ge,stageOf as _e,storyStage as ve}from"./stage.js";import{c as ye,i as be,n as xe,o as Se,t as Ce}from"./results.js";export{S as EXTS,me as MAP,i as Misfit,ue as NEEDS,le as PROCESS,N as SETUP_FILES,pe as SITE_BLOCK,H as SPEC,ge as STAGES,h as alike,r as articleOf,$ as asLine,fe as call,c as called,Ce as checkOf,F as checksIn,z as citable,u as citationsIn,T as citationsOf,w as cited,xe as door,E as eachChanged,_ as eachLine,q as exampled,x as extOf,t as faultIn,I as faults,b as featureOf,re as filesStore,R as fitThing,O as format,a as fromFeature,te as fromFile,p as held,e as heldTo,W as init,ie as isSite,be as keep,M as keysIn,X as keysOf,C as kindOf,Y as kinds,m as lineAt,G as lineFor,g as misfitOf,ce as needs,A as nextId,k as overview,s as pathOf,o as pointed,U as quoted,B as readMap,l as references,Se as report,Z as resultsIn,J as says,V as setup,he as siteOf,d as slugOf,ae as spamOf,oe as spammy,_e as stageOf,f as stepsFault,ve as storyStage,ye as tally,P as testsAt,D as testsIn,K as thingAt,v as tidy,ee as toFile,se as tools,ne as typeset,L as uncited,n as unnamed,Q as unproved,de as waiting,j as written,y as yamlOf};
1
+ import{$ as e,A as t,B as n,C as r,D as i,E as a,F as o,G as s,H as c,I as l,J as u,K as d,L as f,M as p,N as m,O as h,P as g,Q as _,R as v,S as y,T as b,U as x,V as S,W as C,X as w,Y as T,Z as E,_ as D,a as O,b as k,c as A,d as j,et as M,f as N,g as P,h as F,i as I,it as L,j as R,k as z,l as B,m as V,n as H,nt as U,o as W,p as G,q as K,r as q,rt as J,s as Y,tt as X,u as Z,v as Q,w as $,x as ee,y as te,z as ne}from"./map.js";import{a as re,c as ie,d as ae,f as oe,i as se,l as ce,n as le,o as ue,p as de,r as fe,s as pe,t as me,u as he}from"./process.js";import{STAGES as ge,stageOf as _e,storyStage as ve}from"./stage.js";import{c as ye,i as be,n as xe,o as Se,t as Ce}from"./results.js";export{S as EXTS,me as MAP,i as Misfit,ue as NEEDS,le as PROCESS,j as SETUP_FILES,pe as SITE_BLOCK,H as SPEC,ge as STAGES,h as alike,r as articleOf,$ as asLine,fe as call,c as called,Ce as checkOf,V as checksIn,z as citable,u as citationsIn,T as citationsOf,w as cited,xe as door,E as eachChanged,_ as eachLine,q as exampled,x as extOf,t as faultIn,I as faults,b as featureOf,re as filesStore,R as fitThing,a as fromFeature,Q as fromFile,p as held,e as heldTo,O as init,ie as isSite,be as keep,M as keysIn,X as keysOf,C as kindOf,W as kinds,m as lineAt,N as lineFor,g as misfitOf,ce as needs,Y as nextId,te as overview,s as pathOf,o as pointed,U as quoted,A as readMap,l as references,Se as report,B as resultsIn,k as sameFile,J as says,G as setup,he as siteOf,d as slugOf,ae as spamOf,oe as spammy,_e as stageOf,f as stepsFault,ve as storyStage,ye as tally,F as testsAt,P as testsIn,K as thingAt,v as tidy,ee as toFile,se as tools,ne as typeset,L as uncited,n as unnamed,D as unproved,de as waiting,Z as written,y as yamlOf};
package/dist/kinds.d.ts CHANGED
@@ -58,14 +58,10 @@ export declare const pathOf: (kinds: Kinds, thing: {
58
58
  key: string;
59
59
  data?: Record<string, any>;
60
60
  }) => string | undefined;
61
- /**
62
- * The thing a file holds, from where it stands: by the id its name starts with, whatever follows it, or by a kind's
63
- * fixed name. `old` says it is kept in a format its kind no longer is (an ability still in YAML).
64
- */
61
+ /** The thing a file holds, from where it stands: by the id its name starts with, whatever follows it, or by a kind's fixed name. */
65
62
  export declare function thingAt(kinds: Kinds, path: string): {
66
63
  kind: string;
67
64
  key: string;
68
- old?: boolean;
69
65
  } | undefined;
70
66
  /** The kind an id belongs to, by its letter. */
71
67
  export declare const kindOf: (kinds: Kinds, key: string) => string | undefined;
package/dist/map.d.ts CHANGED
@@ -15,19 +15,12 @@ export declare function readMap(dir?: string, k?: Kinds): {
15
15
  paths: Record<string, string>;
16
16
  said: Record<string, string>;
17
17
  };
18
- /**
19
- * Every file of a map written again as the map writes it: under the name its thing is called by, in one order, an
20
- * ability in Gherkin saying who it is for from its tags. One kept the old way is moved. A file with anything else
21
- * wrong is left as it is, and said, since writing it from what could be read would lose the rest.
22
- */
23
- export declare function format(dir?: string, k?: Kinds): {
24
- wrote: string[];
25
- left: string[];
26
- };
27
18
  /** The results of the map's checks, as the test reporter keeps them beside it (`results.json`). */
28
19
  export declare const resultsIn: (dir?: string) => Results;
29
- /** The map's front page, written again from its files. */
30
- /** The map's front page, written from the files beside it. One the project wrote itself before the map was there is kept beside it, as README.before.md, never written over. */
20
+ /**
21
+ * The map's front page, written again from its files. One the project wrote itself in that folder before the map was
22
+ * there is kept beside it, as README.before.md, never written over.
23
+ */
31
24
  export declare const written: (dir?: string, k?: Kinds) => void;
32
25
  /** Where a README.md the project wrote in the map's folder before the map was is kept. */
33
26
  export declare const BEFORE = "README.before.md";
@@ -41,7 +34,7 @@ export declare const nextId: (k: Kinds, kind: string, all: Record<string, Thing>
41
34
  */
42
35
  export declare function faults(dir?: string, tests?: string): string[];
43
36
  /**
44
- * A project set up: its map's folders, a brief to begin from, the front page, the line in AGENTS.md, CLAUDE.md pointing
37
+ * A project set up: its map's folders, a brief to begin from, its front page, the line in AGENTS.md, CLAUDE.md pointing
45
38
  * at it, and `.mcp.json` giving every coding agent that reads it the map's tools. Nothing already there is written over.
46
39
  */
47
40
  export declare function init(root?: string, dir?: string): string[];