userforge 0.1.0 → 0.2.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
@@ -3,7 +3,8 @@
3
3
  The map's tools, command line, file format and test tools for a project built
4
4
  the Userforge way. The project keeps a map beside its code, in `spec/`: who it
5
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 YAML file per thing,
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,
7
8
  holding its data by key. Tests are named after the checks they prove, so the
8
9
  map always says what works.
9
10
 
@@ -54,22 +55,46 @@ again.
54
55
  |---|---|
55
56
  | `spec/why/` | The brief, documents, decisions, research and sources. |
56
57
  | `spec/who/` | Personas. |
57
- | `spec/what/` | Abilities, each with its checks (`S12.2` is check 2 of `S12`). |
58
+ | `spec/what/` | Abilities, each with its checks (`S12.2` is check 2 of `S12`), in Gherkin. |
58
59
  | `spec/where/` | Places: screens, and a website's pages. Screenshots beside them, in `spec/where/shots/`. |
59
60
  | `spec/queue/` | Code work waiting for a coding agent, one file each. |
60
61
  | `spec/results.json` | The last result of every check. |
61
62
  | `spec/README.md` | The front page, written from the files. Never edited by hand. |
62
63
 
63
- A file is the thing's data by key, exactly as a workspace holds it:
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:
71
+
72
+ ```gherkin
73
+ @S1 @planned @P2 @W1
74
+ Ability: reserve tomorrow’s sourdough with just my name and phone number
75
+ As a Weekday regular
76
+ When I’m on the sofa after dinner
77
+ So that my loaf is waiting at 8:15
78
+
79
+ @S1.1
80
+ Rule: An order needs only a name and a phone number.
81
+
82
+ @S1.3
83
+ Rule: After the 7:30pm cutoff, tomorrow’s orders are closed.
84
+
85
+ Example: a late order on a Tuesday
86
+ Given it is 7:45pm on Tuesday
87
+ When I open the order page
88
+ Then it says Wednesday’s orders are closed
89
+ ```
90
+
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:
64
94
 
65
95
  ```yaml
66
- stage: planned
67
- who: [P1]
68
- what: see tomorrow’s orders
69
- where: [W1]
70
- checks:
71
- - id: "1"
72
- text: The orders for tomorrow are listed.
96
+ role: Weekday regular
97
+ color: violet
73
98
  ```
74
99
 
75
100
  An ability's stage comes from its results. People say idea or planned; it is
@@ -83,6 +108,7 @@ once every check passes on main.
83
108
  | `npx userforge` | What the map holds, how work is done here, what is waiting in `spec/queue/`, and where the map stands. |
84
109
  | `npx userforge init` | Sets the project up, or gives one that has its map what it lacks. |
85
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. |
86
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). |
87
113
  | `npx userforge pull` | Writes a workspace's map into `spec/`. |
88
114
  | `npx userforge report [file]` | Tells a workspace the results in `spec/results.json`. |
@@ -113,6 +139,26 @@ with the code:
113
139
  export default { test: { reporters: ['default', 'userforge/reporter'] } };
114
140
  ```
115
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:
146
+
147
+ ```ts
148
+ // vitest.config.ts
149
+ import { quickpickle } from 'quickpickle';
150
+ import { exampled } from 'userforge/test';
151
+
152
+ export default {
153
+ plugins: [quickpickle()],
154
+ test: {
155
+ include: ['tests/**/*.test.ts', ...exampled()], // the ability files that hold examples
156
+ setupFiles: ['tests/steps.ts'],
157
+ reporters: ['default', 'userforge/reporter']
158
+ }
159
+ };
160
+ ```
161
+
116
162
  ## What an agent is told
117
163
 
118
164
  [`map.md`](map.md) says what the map holds and how its tools are used;
@@ -125,8 +171,8 @@ tools carry both as their instructions. Update this package to get newer ones.
125
171
  `import { … } from 'userforge'`: the tools (`tools`, `call`) over a map kept
126
172
  anywhere (`Store`; `filesStore` for `spec/`); fitting a thing to its kind's
127
173
  sheet (`fitThing`) and what on it needs someone (`needs`), also alone as
128
- `userforge/fit` for an app that has viewschema itself; the file format (`fromFile`, `toFile`, `yamlOf`,
129
- `overview`) and the kinds (`kinds`); a map read and checked (`readMap`,
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`,
130
176
  `faults`, `init`); checks and results (`checksIn`, `unproved`, `keep`,
131
177
  `resultsIn`); stages (`stageOf`, `storyStage`, also alone as
132
178
  `userforge/stage`); set-up (`setup`, `lineFor`); and what an agent is told
package/dist/cli.js CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env node
2
- import{existsSync as e,mkdirSync as t,readFileSync as n,writeFileSync as r}from"node:fs";import{dirname as i,join as a,relative as o}from"node:path";import{f as s,n as c,o as l,p as u,r as d,s as f,t as p}from"./map.js";import{createInterface as m}from"node:readline";import{a as h,i as g,n as _,r as v,t as y}from"./process.js";import{storyStage as b,workDone as x}from"./stage.js";import{a as S,n as C,o as w,s as T}from"./results.js";var E=`0.1.0`;const D=[`2025-11-25`,`2025-06-18`,`2025-03-26`,`2024-11-05`];async function O(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:D.includes(i.protocolVersion)?i.protocolVersion:D[0],capabilities:{tools:{}},serverInfo:{name:`userforge`,version:E},instructions:`${y}\n\n${_}`});case`ping`:return a({});case`tools/list`:return a({tools:g(e)});case`tools/call`:{let{text:t,failed:n}=await v(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 k(e=h()){return new Promise(t=>{let n=m({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(()=>O(e,n)).then(e=>e&&process.stdout.write(`${JSON.stringify(e)}\n`))}),n.on(`close`,()=>void r.then(()=>t(0)))})}function A(e=p){let t=f(e);return Object.values(l(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:x(n,t)}})}const j=process.env.USERFORGE_TESTS??u(),M=o(process.cwd(),p)||`spec`,N=e=>e.length&&console.log(e.join(`
3
- `)),P=(e,t,n=`${t}s`)=>`${e} ${e===1?t:n}`,F=e=>C()?void 0:(console.error(`usage: USERFORGE_URL=… USERFORGE_KEY=… userforge ${e}`),2);function I(){let{all:e}=l(),t=t=>Object.values(e).filter(e=>e.kind===t),n=t(`story`),r=f(),i=n.filter(e=>b(e,r)===`live`).length,a=c(p,j).length;return[`The map holds ${P(t(`persona`).length,`persona`)}, ${P(n.length,`ability`,`abilities`)} (${i} live) with ${P(Object.keys(s(n)).length,`check`)}, and ${P(t(`place`).length,`place`)};`,a?`${P(a,`thing doesn't`,`things don't`)} hold together: \`npx userforge check\` says which.`:`it holds together.`].join(` `)}const L=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(`; `),R=["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.`],z={"":()=>{let t=A(p);return N([y,``,_,``,`## Waiting in ${M}/queue/`,``,...t.length?t.map(e=>`- ${e.id}: ${e.asked.split(`
4
- `)[0]}${L(e)?` (${L(e)})`:``}`):[`Nothing is waiting.`],``,e(p)?I():`There is no map in ${M}/ yet: \`npx userforge init\` sets one up.`]),0},init:()=>{let t=e(p),n=[...t?[]:[`${M}/`],...d()];return N(t?[n.length?`Set up ${n.join(`, `)}.`:`It is set up already.`]:[`Set up ${n.join(`, `)}.`,``,`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:()=>k(),check:()=>{let e=c(p,j);return N(e),+!!e.length},async pull(){let e=await S(C());for(let[n,o]of Object.entries(e))t(i(a(p,n)),{recursive:!0}),r(a(p,n),o);return console.log(`${Object.keys(e).length-1} things written to ${M}/.`),0},report:async([e=a(p,`results.json`)])=>(console.log(await w(C(),JSON.parse(n(e,`utf8`)))),0),async site([e,n]){if(!/^https?:\/\/[^/\s]+$/.test(e??``))return console.error(`usage: userforge site <address, such as https://www.example.com> [website id]`),2;let o=await T(C(),e,n);for(let[e,n]of Object.entries(o))t(i(a(`site`,e)),{recursive:!0}),r(a(`site`,e),n);return N([`${P(Object.keys(o).length,`file`)} written to site/.`,``,...R]),0}},[B=``,...V]=process.argv.slice(2),H=z[B];H?Promise.resolve().then(()=>[`pull`,`report`,`site`].includes(B)?F(B)??H(V):H(V)).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{};
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{};
package/dist/files.d.ts CHANGED
@@ -2,8 +2,11 @@ import { type Kinds, type Thing } from './kinds.ts';
2
2
  import type { Results } from './results.ts';
3
3
  /** 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
4
  export declare function yamlOf(kinds: Kinds, thing: Thing): string;
5
- /** A thing as its file says it: its path, and its YAML. Nothing, for a kind kept in the workspace alone. */
6
- export declare function toFile(kinds: Kinds, thing: Thing): {
5
+ /**
6
+ * A thing as its file says it: its path, and what it holds. Nothing, for a kind kept in the workspace alone. Given
7
+ * everything there is (`all`), an ability says who it is for by their roles too, as it always should be written.
8
+ */
9
+ export declare function toFile(kinds: Kinds, thing: Thing, all?: Record<string, Thing>): {
7
10
  path: string;
8
11
  text: string;
9
12
  } | undefined;
@@ -14,6 +17,9 @@ export declare function toFile(kinds: Kinds, thing: Thing): {
14
17
  export declare function fromFile(kinds: Kinds, path: string, text: string, all?: Record<string, Thing>): {
15
18
  thing: Thing;
16
19
  problems: string[];
20
+ said?: string;
17
21
  } | 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. -->";
18
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. */
19
25
  export declare function overview(kinds: Kinds, all: Record<string, Thing>, results?: Results): string;
package/dist/fit.d.ts CHANGED
@@ -28,6 +28,12 @@ export declare function unnamed(kinds: Kinds, all: Record<string, Thing>, key: s
28
28
  thing: Thing;
29
29
  fields: string[];
30
30
  }[];
31
+ /**
32
+ * What is wrong with an example's steps, as a sentence: each line a step (Given, When, Then, And, But or *), a row of
33
+ * a table under one (`| … |`), a comment, or inside a doc string (between `"""` or ```` ``` ````). Nothing, when they
34
+ * can be run, or when there are none yet.
35
+ */
36
+ export declare function stepsFault(steps: unknown): string | undefined;
31
37
  type Defs = Record<string, JSONSchemaProperty>;
32
38
  /**
33
39
  * What a writer wrote, with its quotation marks and apostrophes set as type. Addresses are left as they came, and so
@@ -72,6 +78,6 @@ export declare function fitThing(kinds: Kinds, kind: string, given: Record<strin
72
78
  problems: string[];
73
79
  };
74
80
  export { citationsIn, citationsOf, cited, eachChanged, eachLine, heldTo, keysIn, keysOf, quoted, says, uncited, type Citation } from './cite.ts';
75
- export { called, EXT, kindOf, pathOf, thingAt, type Kind, type Kinds, type Schema, type Thing } from './kinds.ts';
81
+ export { called, EXTS, extOf, kindOf, pathOf, slugOf, thingAt, type Kind, type Kinds, type Schema, type Thing } from './kinds.ts';
76
82
  export { isSite, needs, NEEDS, siteOf, SITE_BLOCK, type Need } from './needs.ts';
77
83
  export { spamOf, spammy, waiting } from './notes.ts';
package/dist/fit.js CHANGED
@@ -1,2 +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=`.yaml`,y=(e,t,n)=>{let r=e[t]?.file;return r&&`${r.dir}/${r.name??n}.yaml`};function b(e,t){let[n,r=``]=t.split(`/`).slice(-2);if(!r.endsWith(`.yaml`))return;let i=r.slice(0,-5);for(let[t,r]of Object.entries(e))if(r.file?.dir===n&&(r.file.name?r.file.name===i:RegExp(`^${r.letter}\\d+$`).test(i)))return{kind:t,key:r.file.name?`${r.letter}1`:i}}const x=(e,t)=>Object.keys(e).find(n=>RegExp(`^${e[n].letter}\\d+$`).test(t)),S=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()},C=/\bhttps?:\/\/[^\s<>()"']+|\bwww\.[^\s<>()"']+\.[a-z]{2,}[^\s<>()"']*/gi,w=/^([^\n(]{2,80}\(\s*https?:\/\/[^)\s]+\s*\)|\s*https?:\/\/\S+)\s*[-–—:|]/,T=/\[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 E(e){let t=String(e??``).trim();if(!t)return;let n=t.match(C)??[];if(n.length>=3||n.join(``).length>=t.length*.4)return`links`;if(w.test(t))return`advert`;if(T.test(t))return`phrases`}const D=e=>!e.facts?.person&&!!E(e.data.feedback?.text),O=e=>e.data.feedback?.status!==`done`&&!D(e),k=`c-site`,A=e=>(e.data.place?.blocks??[]).some(e=>e?.is===k);function j(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(A(n))return n}const M=[`failing`,`unchecked`,`unplaced`,`bare`,`unsorted`,`undecided`];function N(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=>!j(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(O)),undecided:r(n(`decision`).filter(e=>(e.data.decision.status??`proposed`)===`proposed`))}}var P=class extends Error{};const F=(e,t)=>`This doesn’t fit the ${e} sheet:\n- ${t.join(`
2
- - `)}`,I=e=>e?.kind===`source`&&e.data.source.cite!==`no`,L=(e,t)=>_(t,t=>I(e[t])?String(e[t].data.source.text??``):void 0);function R(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 z(e,t){let[,n,r]=/^([A-Z]\d+)(?:\.(\d+))?$/.exec(String(t??``).trim())??[],i=e[n??``];return!!i&&(!r||!!R(i,r))}const B=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(` `)),V=/* @__PURE__ */ new Set([`img`,`hr`]),H=/^(href|src|alt|datetime|data-[a-z-]+|aria-[a-z-]+)$/,U=/^(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))$/,W=e=>U.test(e)||H.test(/^view-(?:attr|optional|readonly|title|prompt):(.+)$/.exec(e)?.[1]??``),G=/<(\/?)([a-zA-Z][\w-]*)((?:\s+[^\s"'=<>/]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'=<>`]+))?)*)\s*(\/?)>/g;function K(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(G,(e,t,n,s,c,l)=>{let u=n.toLowerCase();B.has(u)||r.push(`<${u}> can’t be used in a block.`);for(let[,e]of s.matchAll(/\s+([^\s"'=<>/]+)(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'=<>`]+))?/g))W(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++,!V.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 q(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}const J=(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=>J(e,i?.items,n)):e&&typeof e==`object`?Object.fromEntries(Object.entries(e).map(([e,t])=>[e,J(t,i?.properties?.[e],n)])):e};function Y(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=>Y(e[n],t[n]))}function X(e,t){if(e.kind===`place`)return Z(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 Z(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 Y(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 Q(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[x(e,t.split(`.`)[0])??``]?.file;for(let e of c.points??[])for(let t of[n[e]??[]].flat().filter(Boolean))!z(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`?I(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 $(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`&&K(h.html)&&g.push(`html: ${K(h.html)}`),i.all&&g.push(...Q(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:X({kind:t,data:{[t]:h}},i.patch)[t],problems:g}}export{v as EXT,P as Misfit,M as NEEDS,k as SITE_BLOCK,Y as alike,S as called,I as citable,d as citationsIn,c as citationsOf,s as cited,u as eachChanged,l as eachLine,K as faultIn,$ as fitThing,L as held,_ as heldTo,A as isSite,f as keysIn,o as keysOf,x as kindOf,R as lineAt,F as misfitOf,N as needs,y as pathOf,z as pointed,g as quoted,Q as references,h as says,j as siteOf,E as spamOf,D as spammy,b as thingAt,X as tidy,J as typeset,p as uncited,q as unnamed,O as waiting};
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(`
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};
@@ -0,0 +1,18 @@
1
+ import type { Kinds, Thing } from './kinds.ts';
2
+ /** "a" or "an", as the first word of a role is said: an Owner, a User, an hour, an SEO lead. */
3
+ export declare function articleOf(role: string): 'a' | 'an';
4
+ /** The line an ability's file says who it is for in, from its personas' roles: "As a Solo Founder or a Product Lead". Nothing, when a role isn't known. */
5
+ export declare function asLine(roles: (string | undefined)[]): string | undefined;
6
+ /** The roles of an ability's personas, from everything there is. */
7
+ export declare const rolesOf: (story: Record<string, any>, all: Record<string, Thing>) => any;
8
+ /** An ability as its Gherkin file says it, in one order. Given everything there is, it says who it is for by their roles too. */
9
+ export declare function featureOf(kinds: Kinds, thing: Thing, all?: Record<string, Thing>): string;
10
+ /**
11
+ * An ability's file read back into its data by key, with what in it the map doesn't keep said (fitting it to the
12
+ * sheet is the caller's). `key` is the id its file's name gives it. `said` is the `As a …` line as the file has it.
13
+ */
14
+ export declare function fromFeature(kinds: Kinds, key: string, text: string): {
15
+ read: Record<string, any>;
16
+ problems: string[];
17
+ said?: string;
18
+ };
package/dist/index.d.ts CHANGED
@@ -6,11 +6,12 @@
6
6
  */
7
7
  export * from './fit.ts';
8
8
  export { fromFile, overview, toFile, yamlOf } from './files.ts';
9
- export { faults, init, kinds, nextId, readMap, resultsIn, SPEC, written } from './map.ts';
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
11
  export { filesStore, type Store } from './store.ts';
11
12
  export { call, tools, type Tool } from './tools.ts';
12
13
  export { MAP, PROCESS } from './process.ts';
13
14
  export { STAGES, stageOf, storyStage, type Stage } from './stage.ts';
14
15
  export { checksIn, testsAt, testsIn, unproved, type Checks } from './checks.ts';
15
- export { CHECK, door, keep, report, tally, type Door, type Result, type Results } from './results.ts';
16
+ export { checkOf, door, keep, report, tally, type Door, type Result, type Results } from './results.ts';
16
17
  export { lineFor, setup, SETUP_FILES } from './setup.ts';
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{A as e,B as t,C as n,D as r,E as i,F as a,G as o,H as s,I as c,J as l,K as u,L as d,M as f,N as p,O as m,P as h,R as g,S as _,T as v,U as y,V as b,W as x,_ as S,a as C,b as w,c as T,d as E,f as D,g as O,h as k,i as A,j,k as M,l as N,m as P,n as F,o as I,p as L,q as R,r as z,s as B,t as V,u as H,v as U,w as W,x as G,y as K,z as q}from"./map.js";import{a as J,c as Y,d as X,f as Z,i as Q,l as $,n as ee,o as te,p as ne,r as re,s as ie,t as ae,u as oe}from"./process.js";import{STAGES as se,stageOf as ce,storyStage as le}from"./stage.js";import{c as ue,i as de,n as fe,o as pe,t as me}from"./results.js";export{me as CHECK,p as EXT,ae as MAP,w as Misfit,te as NEEDS,ee as PROCESS,N as SETUP_FILES,ie as SITE_BLOCK,V as SPEC,se as STAGES,G as alike,re as call,h as called,D as checksIn,_ as citable,g as citationsIn,q as citationsOf,t as cited,fe as door,b as eachChanged,s as eachLine,n as faultIn,F as faults,J as filesStore,W as fitThing,O as fromFile,v as held,y as heldTo,z as init,Y as isSite,de as keep,x as keysIn,o as keysOf,a as kindOf,A as kinds,i as lineAt,H as lineFor,r as misfitOf,$ as needs,C as nextId,S as overview,c as pathOf,m as pointed,u as quoted,I as readMap,M as references,pe as report,B as resultsIn,R as says,E as setup,oe as siteOf,X as spamOf,Z as spammy,ce as stageOf,le as storyStage,ue as tally,L as testsAt,P as testsIn,d as thingAt,e as tidy,U as toFile,Q as tools,j as typeset,l as uncited,f as unnamed,k as unproved,ne as waiting,T as written,K 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,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};
package/dist/kinds.d.ts CHANGED
@@ -16,11 +16,15 @@ export interface Kind {
16
16
  letter: string;
17
17
  /** A map holds exactly one. */
18
18
  one?: boolean;
19
- /** Where its file is kept, and which fields it opens with; a kind kept in the workspace alone has none. */
19
+ /**
20
+ * Where its file is kept, and which fields it opens with; a kind kept in the workspace alone has none. A file is in
21
+ * YAML unless it says Gherkin (an ability, which then reads as its user story).
22
+ */
20
23
  file?: {
21
24
  dir: string;
22
25
  name?: string;
23
26
  lines?: string[];
27
+ format?: 'yaml' | 'gherkin';
24
28
  };
25
29
  /** The fields that hold the ids of other things, by the kind they hold (in a list when they hold several). */
26
30
  refs?: Record<string, string | string[]>;
@@ -34,14 +38,34 @@ export interface Thing {
34
38
  kind: string;
35
39
  data: Record<string, any>;
36
40
  }
37
- /** A map file's own ending. */
38
- export declare const EXT = ".yaml";
39
- /** Where a thing's file stands, under the map's folder; nothing for a kind kept in the workspace alone. */
40
- export declare const pathOf: (kinds: Kinds, kind: string, key: string) => string | undefined;
41
- /** The thing a file holds, from where it stands. */
41
+ /** A kind's file's own ending: `.feature` for one kept in Gherkin, `.yaml` for the rest. */
42
+ export declare const extOf: (kind: Kind | undefined) => ".yaml" | ".feature";
43
+ /** Every ending a map's file can have. */
44
+ export declare const EXTS: string[];
45
+ /**
46
+ * A name made for people from what a thing is called: lower case, accents and apostrophes dropped, anything else
47
+ * between words one hyphen, cut at a word to at most 48 characters ("reserve-tomorrows-sourdough").
48
+ */
49
+ export declare function slugOf(words: string): string;
50
+ /**
51
+ * Where a thing's file stands, under the map's folder: its id, then what it is called, for people
52
+ * (`what/S1-reserve-tomorrows-sourdough.feature`), or the fixed name of a kind the map holds one of
53
+ * (`why/brief.yaml`). Nothing, for a kind kept in the workspace alone. The name is only ever written from the
54
+ * thing: a file is found by the id it starts with.
55
+ */
56
+ export declare const pathOf: (kinds: Kinds, thing: {
57
+ kind: string;
58
+ key: string;
59
+ data?: Record<string, any>;
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
+ */
42
65
  export declare function thingAt(kinds: Kinds, path: string): {
43
66
  kind: string;
44
67
  key: string;
68
+ old?: boolean;
45
69
  } | undefined;
46
70
  /** The kind an id belongs to, by its letter. */
47
71
  export declare const kindOf: (kinds: Kinds, key: string) => string | undefined;
package/dist/map.d.ts CHANGED
@@ -4,15 +4,33 @@ import type { Results } from './results.ts';
4
4
  export declare const kinds: Kinds;
5
5
  /** Where the map is kept: `spec/`, unless `USERFORGE_SPEC` says otherwise. */
6
6
  export declare const SPEC: string;
7
- /** Every file of a map, read: what it holds, and what in it doesn't fit its sheet. */
7
+ /**
8
+ * Every file of a map, read: what it holds, by its id; where each is kept (`paths`, from the map's folder); what in it
9
+ * doesn't fit its sheet; and, for an ability, its `As a …` line as its file says it (`said`). A file is found by the
10
+ * id its name starts with, whatever follows: two files with one id are a problem, and the first is taken.
11
+ */
8
12
  export declare function readMap(dir?: string, k?: Kinds): {
9
13
  all: Record<string, Thing>;
10
14
  problems: string[];
15
+ paths: Record<string, string>;
16
+ said: Record<string, string>;
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[];
11
26
  };
12
27
  /** The results of the map's checks, as the test reporter keeps them beside it (`results.json`). */
13
28
  export declare const resultsIn: (dir?: string) => Results;
14
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. */
15
31
  export declare const written: (dir?: string, k?: Kinds) => void;
32
+ /** Where a README.md the project wrote in the map's folder before the map was is kept. */
33
+ export declare const BEFORE = "README.before.md";
16
34
  /** The id a new thing of a kind is given: the next one the files leave free. */
17
35
  export declare const nextId: (k: Kinds, kind: string, all: Record<string, Thing>) => string;
18
36
  /**
@@ -27,3 +45,10 @@ export declare function faults(dir?: string, tests?: string): string[];
27
45
  * at it, and `.mcp.json` giving every coding agent that reads it the map's tools. Nothing already there is written over.
28
46
  */
29
47
  export declare function init(root?: string, dir?: string): string[];
48
+ /**
49
+ * The ability files of a map that hold an example, by their path from where the tests run: what a Gherkin runner
50
+ * (QuickPickle) is given to run, so that it opens none that has nothing to run.
51
+ *
52
+ * include: ['tests/**\/*.test.ts', ...exampled()]
53
+ */
54
+ export declare function exampled(dir?: string, from?: string): string[];