@nervur.org/installer-browser 0.37.11 → 0.37.12

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.
@@ -2620,7 +2620,7 @@ var checkBlueprint = (value, node2, longest) => {
2620
2620
  };
2621
2621
  };
2622
2622
 
2623
- var GENOME_VERSION = "0.37.11";
2623
+ var GENOME_VERSION = "0.37.12";
2624
2624
 
2625
2625
  var endFrame = (asker, method3) => ({ end: { asker, method: method3 } });
2626
2626
 
@@ -3577,7 +3577,7 @@ var keepHalf = (gear, id, host, connected, added3, failed2) => {
3577
3577
 
3578
3578
  var EAR_BLUEPRINT = {
3579
3579
  name: "nervur.ear",
3580
- version: "0.37.11",
3580
+ version: "0.37.12",
3581
3581
  description: "The ear: it opens and seals the boxes of Quo, and the brain keeps every relation.",
3582
3582
  methods: {
3583
3583
  arrived: {
@@ -4146,13 +4146,13 @@ var readFaculty = (engine, crypto2, source, memory) => {
4146
4146
  };
4147
4147
  var facultyReaderOn = (engine, crypto2, memory) => (source) => readFaculty(engine.apart(), crypto2, source, memory);
4148
4148
 
4149
- var EAR_TEXT = "class Ear extends Faculty {\n static #bytes = {\n type: 'string',\n contentEncoding: 'base16',\n maxLength: 1048576,\n };\n static #arrival = { ...Ear.#bytes, maxLength: 1048576 + 1 };\n static #text = { type: 'string', minLength: 1 };\n static #name = { type: 'string', pattern: '^[0-9a-f]{128}$' };\n static #reference = { type: 'string', pattern: '^[a-z2-7]{26}$' };\n static #says = {\n anyOf: [{ type: 'object' }, { type: 'array' }, { type: 'string' }, { type: 'number' }, { type: 'boolean' }],\n };\n static #again = {\n type: 'object',\n properties: { node: Ear.#text, far: Ear.#text },\n required: ['node', 'far'],\n additionalProperties: false,\n };\n\n static blueprint = {\n name: 'nervur.ear',\n version: '0.37.11',\n description: 'The ear: it opens and seals the boxes of Quo, and the brain keeps every relation.',\n methods: {\n arrived: {\n description:\n \"A box arrived on an exchange, sent to the ward named, the public ward where none is: opened, judged by Quo and handed on, or replied. Answers `{opened: true}` where it handed on an ask it admitted on a relation, so the carrier counts what that ask came on as carried, and null otherwise. The brain's alone, with `answer`: what a node answered of an ask the ear handed on, sealed and replied on its exchange.\",\n kind: 'reading',\n args: {\n anyOf: [\n {\n type: 'object',\n properties: {\n exchange: { type: 'integer', minimum: 0 },\n bytes: Ear.#arrival,\n ward: Ear.#name,\n },\n required: ['exchange', 'bytes'],\n additionalProperties: false,\n },\n {\n type: 'object',\n properties: {\n exchange: { type: 'integer', minimum: 0 },\n door: {},\n admitted: {},\n front: { type: 'boolean' },\n answer: {},\n },\n required: ['exchange', 'door', 'admitted', 'answer'],\n additionalProperties: false,\n },\n ],\n },\n result: {\n anyOf: [\n { type: 'null' },\n {\n type: 'object',\n properties: { opened: { const: true } },\n required: ['opened'],\n additionalProperties: false,\n },\n ],\n },\n errors: ['refused'],\n },\n named: {\n description:\n \"The brain's alone, for its owners' `addresses`. Keeps the addresses of the organism's own an owner named, in place of those before, beside what `network` reports.\",\n kind: 'writing',\n askers: ['brain'],\n args: {\n type: 'object',\n properties: { at: { type: 'array', items: Ear.#text } },\n required: ['at'],\n additionalProperties: false,\n },\n result: { type: 'null' },\n errors: ['refused'],\n },\n addresses: {\n description: 'The addresses `network` last reported.',\n kind: 'writing',\n args: {\n type: 'object',\n properties: { addresses: { type: 'array', items: Ear.#text } },\n required: ['addresses'],\n additionalProperties: false,\n },\n result: { type: 'null' },\n errors: ['refused'],\n },\n line: {\n description:\n 'A line, accepted at an endpoint or held, that names `wards` came up or went down, told by `network` alone. The ear asks the brain `line {wards, up}`, up and down alike: on up the brain asks each lobe granted a standing on one of them `back`, and either way it asks the lobe that gave an occupant drawn through that line `line {far, up}`.',\n kind: 'reading',\n askers: ['network'],\n args: {\n type: 'object',\n properties: { wards: { type: 'array', items: Ear.#name }, up: { type: 'boolean' } },\n required: ['wards', 'up'],\n additionalProperties: false,\n },\n result: { type: 'null' },\n errors: ['refused'],\n },\n challenged: {\n description:\n 'A line `network` holds to `address` was challenged by its listener with `nonce` and `identity`, told by `network` alone. The ear asks the brain `lines {}` for the wards drawn through that address and `key` `prove {wards, nonce, identity}`, and answers `{proofs: [{ward, proof}]}`, each ward with its proof under that challenge alone; a line the brain holds no ward on is answered with none. It writes no cell.',\n kind: 'reading',\n askers: ['network'],\n args: {\n type: 'object',\n properties: {\n address: { type: 'string', minLength: 1 },\n nonce: { type: 'string', contentEncoding: 'base16', minLength: 32, maxLength: 32 },\n identity: { type: 'string', contentEncoding: 'base16', minLength: 32, maxLength: 32 },\n },\n required: ['address', 'nonce', 'identity'],\n additionalProperties: false,\n },\n result: {\n type: 'object',\n properties: {\n proofs: {\n type: 'array',\n items: {\n type: 'object',\n properties: {\n ward: Ear.#name,\n proof: { type: 'string', contentEncoding: 'base16', minLength: 64, maxLength: 64 },\n },\n required: ['ward', 'proof'],\n additionalProperties: false,\n },\n },\n },\n required: ['proofs'],\n additionalProperties: false,\n },\n errors: ['refused'],\n },\n relisten: {\n description:\n \"The brain's alone, told once a change has landed that moved a line, a relation drawn through an address related or ended (`drop`, `left`, a lapse, a reinvite that replaced its keys). The ear asks the brain `lines {}` and `network` `listen {lines}`, durable, the whole set, which replaces the one kept. It writes no cell; it is writing so that it runs alone, behind the reading asks, and nothing waits on it.\",\n kind: 'writing',\n args: { type: 'object', properties: {}, additionalProperties: false },\n result: { type: 'null' },\n errors: ['refused'],\n },\n invite: {\n description:\n \"Draws an invitation to the asker alone, from a ward drawn fresh for it, or the public ward with `public`, kept by the brain for `waits`, null until it is knocked on or ended, and its relation for `lives`, null for good, each span any the asker names, and answers it beside its far organism's ID; the brain asks it with `anchor` for the next anchor. The invitation's text, which `key` has its ward sign whole, carries the two spans it names, `waits` and `lives`, so the side that accepts lapses it by its own clock, and the anchor's mark, `anchor: true`, where it is the next anchor's or, with `first`, the brain's alone, the first invitation. With `note`, free data of at most 4 KiB as its canonical text by default, `note` an owner's word over it, and never a secret, what the standing is for and to whom it is given: the brain keeps it beside the standing, null where none is named, and it never enters the invitation. With `says`, free data never null and never a secret, at most a quarter of the note's bound, 1 KiB by default, which the brain refuses past that bound: what the invitation says to whoever holds it before the yes, carried in the invitation beside its spans, and kept by neither brain but as the offer of a reference. With `again`, `{node, far}`, the brain's alone, the invitation gives again in its place the standing `node` gave of the far organism `far`: it is drawn as ever, and the brain replaces that standing's relation, keeping its far organism, its wires and its note, so `note` is never sent with it. A ward drawn fresh is reached at the address of its own the lobe wired to `relay` gives it, `address {}` answering `{at}`, and where none is wired, where the organism is. With `through`, the address of the organism always on, the ward is reached at that address alone, `at` is `[through]` and no relay is asked, and the brain is told beside the relation which address it was drawn through, so it alone keeps the lines; `through` is refused with `public` or `anchor`, and the brain's `reinvite` of a standing drawn through a line names that `through` again. With `refer`, the invitation is drawn exactly so, a line's or a relay's address among it, but `key` keeps it sealed behind a reference it draws by chance, 128 bits as twenty-six lowercase base32, which the brain holds for `waits` (null until redeemed or dropped), and the answer is `{link: {card, reference}, far}`, never the invitation: `card` is the ward drawn for it and where that ward is reached, so no two links name one ward. A stranger redeems the reference once, on that ward's zero head, by `#redeem {reference}`, which the ear answers itself, the reply's object the invitation; and while it waits reads its offer there as often as it asks, spending nothing, by `#offer {reference}`, the reply's object `{says, waits, lives}`: what the invitation says, null where nothing, what is left of its wait and how long its relation lives, each null for none. With `public` beside `refer`, as for a link on a domain, the invitation is still drawn on a ward fresh for it, and `card` is what `card` answers, the public ward and its addresses, whose zero head redeems it. `refer` is refused with `anchor` and `first`.\",\n kind: 'reading',\n args: {\n type: 'object',\n properties: {\n waits: { anyOf: [{ type: 'integer', minimum: 0 }, { type: 'null' }] },\n lives: { anyOf: [{ type: 'integer', minimum: 0 }, { type: 'null' }] },\n anchor: { type: 'boolean' },\n first: { type: 'boolean' },\n public: { type: 'boolean' },\n refer: { type: 'boolean' },\n through: Ear.#text,\n note: {},\n says: Ear.#says,\n again: Ear.#again,\n },\n required: ['waits', 'lives'],\n additionalProperties: false,\n },\n result: {\n anyOf: [\n {\n type: 'object',\n properties: { invitation: Ear.#text, far: Ear.#text },\n required: ['invitation', 'far'],\n additionalProperties: false,\n },\n {\n type: 'object',\n properties: {\n link: {\n type: 'object',\n properties: {\n card: {\n type: 'object',\n properties: { ward: Ear.#name, at: { type: 'array', items: Ear.#text } },\n required: ['ward', 'at'],\n additionalProperties: false,\n },\n reference: Ear.#reference,\n },\n required: ['card', 'reference'],\n additionalProperties: false,\n },\n far: Ear.#text,\n },\n required: ['link', 'far'],\n additionalProperties: false,\n },\n ],\n },\n errors: ['refused'],\n },\n card: {\n description:\n \"The brain's alone, for its owners' `card`. Answers `{ward, at}`, the public ward's name and the addresses `network` last reported, empty where none was: the very ward and addresses an invitation drawn with `public` carries. It writes no cell and asks no one.\",\n kind: 'reading',\n args: { type: 'object', properties: {}, additionalProperties: false },\n result: {\n type: 'object',\n properties: { ward: Ear.#name, at: { type: 'array', items: Ear.#text } },\n required: ['ward', 'at'],\n additionalProperties: false,\n },\n errors: ['refused'],\n },\n ward: {\n description:\n \"The brain's alone, for its owners' `ward`. `key` draws a new ward, answered as `{name, sealed}`, which the brain lays in the ear's cell: an ask from far runs through the ear, which could write nothing until it ended.\",\n kind: 'reading',\n args: { type: 'object', properties: {}, additionalProperties: false },\n result: { type: 'object' },\n errors: ['refused'],\n },\n drop: {\n irreversible: true,\n description:\n \"Ends the asker's relation with a far organism. One it gave ends here, and an ask arriving while it ends hears `removed`; a standing it holds ends as the mouth's `drop` ends one, its `#leave` sent first. The brain takes a relation given through a line off its line when it ends. With `reference` instead of `far`, the reference the asker minted is taken off, so a `#redeem` or an `#offer` of it is silence; another node's or an unknown one is refused. The relation of its invitation stays, as any unknocked one does, and lapses by its `waits`.\",\n kind: 'reading',\n args: {\n anyOf: [\n {\n type: 'object',\n properties: { far: Ear.#text },\n required: ['far'],\n additionalProperties: false,\n },\n {\n type: 'object',\n properties: { reference: Ear.#reference },\n required: ['reference'],\n additionalProperties: false,\n },\n ],\n },\n result: { type: 'null' },\n errors: ['refused'],\n },\n },\n placeholders: {\n brain: 'nervur.brain',\n network: 'nervur.network',\n front: null,\n key: 'nervur.key',\n relay: null,\n },\n };\n\n static #network = 'network';\n static #silence = { silence: true };\n static #redeem = '#redeem';\n static #offer = '#offer';\n static #handed = { handed: true };\n static #opened = { opened: true };\n static #zeros = '0'.repeat(64);\n static #lid = 32;\n\n static #at(data , key ) {\n return Ear.field(data, key) ?? null;\n }\n\n static #heard(answer ) {\n return 'result' in answer ? answer.result : undefined;\n }\n\n #refused({ code, message } ) {\n return this.error(code === 'busy' ? 'busy' : 'refused', message);\n }\n\n #choice(answer , seen , door ) {\n if (Ear.#at(Ear.#at(answer, 'error'), 'code') === 'silent') return Ear.#silence;\n const at = this.#reachedAt(door.at);\n return { object: this.codec.text(answer), seen, ...(at === undefined ? {} : { at }) };\n }\n\n static #described(admitted , answer ) {\n return Ear.#at(admitted, 'method') === null ? (Ear.#at(answer, 'result') ?? answer) : answer;\n }\n\n #reachedAt(own ) {\n const at = Array.isArray(own) ? own : this.cells.get(['addresses']);\n const named = this.cells.get(['named']);\n if (!Array.isArray(named) || named.length === 0) return Array.isArray(at) ? at : undefined;\n return [...(Array.isArray(at) ? at : []), ...named.filter((one) => !Array.isArray(at) || !at.includes(one))];\n }\n\n *#wired(placeholder ) {\n const read = yield {\n placeholder: 'nerves',\n method: 'read',\n args: {},\n };\n const wires = Ear.#heard(read);\n if (!Array.isArray(wires)) return undefined;\n return wires.some((wire) => Ear.#at(wire, 'placeholder') === placeholder && Ear.#at(wire, 'termination') !== null);\n }\n\n #argsOf(admitted ) {\n const text = Ear.#at(admitted, 'args');\n return typeof text === 'string' ? this.codec.read(text) : { why: 'the args are no text' };\n }\n\n *#lookup(heir , zero , door ) {\n if (door.drawn !== null) {\n const occupant = Ear.#at(door.drawn, 'occupant');\n const held = heir !== null && Ear.#at(occupant, 'heir') === heir;\n return { occupants: held ? { [heir]: occupant } : {}, zero: zero && Ear.#at(door.drawn, 'linked') === true };\n }\n if (heir !== null) {\n const relation = yield {\n placeholder: 'brain',\n method: 'relation',\n args: { heir },\n };\n const found = Ear.#heard(relation);\n if (found === undefined) return undefined;\n const held = found !== null && Ear.#at(found, 'ward') === null;\n return { occupants: held ? { [heir]: Ear.#at(found, 'occupant') } : {}, zero: false };\n }\n return { occupants: {}, zero };\n }\n\n *#doorOf(named , ward ) {\n if (typeof named !== 'string' || named === Ear.#at(ward, 'name')) return { ward, drawn: null, at: undefined };\n const relation = yield {\n placeholder: 'brain',\n method: 'relation',\n args: { ward: named },\n };\n const found = Ear.#heard(relation);\n if (found === undefined || found === null) return found;\n const kept = Ear.#at(found, 'ward');\n const own = { name: Ear.#at(kept, 'name'), sealed: Ear.#at(kept, 'sealed') };\n return { ward: own, drawn: found, at: Ear.field(kept, 'at') };\n }\n\n static #after(exchange , door , admitted ) {\n const { ward, at } = door;\n const kept = ['heir', 'by', 'seq', 'method', 'next', 'sealed'].map((name) => [name, Ear.#at(admitted, name)]);\n return {\n exchange,\n door: { ward, ...(at === undefined ? {} : { at }) },\n admitted: { ...Object.fromEntries(kept), args: '' },\n };\n }\n\n *#passed(heir , admitted , door , exchange ) {\n const args = this.#argsOf(admitted);\n const given = 'data' in args ? { args: args.data } : { args: null, refused: args.why };\n yield {\n placeholder: 'brain',\n method: 'pass',\n args: {\n heir,\n method: Ear.#at(admitted, 'method'),\n ...given,\n next: Ear.#at(admitted, 'next'),\n },\n after: Ear.#after(exchange, door, admitted),\n };\n return Ear.#opened;\n }\n\n *#front(admitted , door , exchange ) {\n const method = Ear.#at(admitted, 'method');\n if (method !== null && typeof method !== 'string') return Ear.#silence;\n if ((yield* this.#wired('front')) !== true) return Ear.#silence;\n const args = this.#argsOf(admitted);\n if ('why' in args) return this.#choice({ error: { code: 'refused', message: args.why } }, null, door);\n yield {\n placeholder: 'front',\n method,\n args: args.data,\n after: { ...Ear.#after(exchange, door, admitted), front: true },\n };\n return Ear.#handed;\n }\n\n #answered(args , door ) {\n const admitted = Ear.#at(args, 'admitted');\n const answer = Ear.#at(args, 'answer');\n if (Ear.#at(args, 'front') === true) return this.#choice(Ear.#described(admitted, answer), null, door);\n const heard = Ear.#at(answer, 'result');\n if (heard === null) return undefined;\n const seen = Ear.#at(heard, 'seen');\n return this.#choice(\n Ear.#described(admitted, Ear.#at(heard, 'answer')),\n typeof seen === 'string' ? seen : null,\n door,\n );\n }\n\n *#told(args ) {\n const kept = Ear.#at(args, 'door');\n const door = { ward: Ear.#at(kept, 'ward'), drawn: null, at: Ear.field(kept, 'at') };\n const choice = this.#answered(args, door);\n const reply = choice === undefined ? null : yield* this.#sealed(door.ward, Ear.#at(args, 'admitted'), choice);\n yield { placeholder: 'network', method: 'reply', args: { exchange: Ear.#at(args, 'exchange'), bytes: reply } };\n return null;\n }\n\n *#redeemed(door , admitted ) {\n const asked = this.#referenceOf(door, admitted);\n if (asked === null) return yield* this.#sealed(door.ward, admitted, Ear.#silence);\n const { reference } = asked;\n const kept = yield { placeholder: 'brain', method: 'redeem', args: asked };\n const heard = Ear.#heard(kept);\n if (heard === undefined) return undefined;\n const sealed = Ear.#at(heard, 'sealed');\n if (!(sealed instanceof Uint8Array)) return yield* this.#sealed(door.ward, admitted, Ear.#silence);\n const reply = yield* this.#key('redeem', { ward: door.ward, admitted, reference, sealed });\n const redeemed = Ear.#at(reply, 'reply');\n return redeemed instanceof Uint8Array ? redeemed : yield* this.#sealed(door.ward, admitted, Ear.#silence);\n }\n\n *#offered(door , admitted ) {\n const asked = this.#referenceOf(door, admitted);\n if (asked === null) return yield* this.#sealed(door.ward, admitted, Ear.#silence);\n const kept = yield { placeholder: 'brain', method: 'offered', args: asked };\n const heard = Ear.#heard(kept);\n if (heard === undefined) return undefined;\n const choice = heard === null ? Ear.#silence : { object: this.codec.text(heard), seen: null };\n return yield* this.#sealed(door.ward, admitted, choice);\n }\n\n #referenceOf(door , admitted ) {\n const args = this.#argsOf(admitted);\n const reference = 'data' in args ? Ear.#at(args.data, 'reference') : null;\n if (typeof reference !== 'string' || !/^[a-z2-7]{26}$/.test(reference)) return null;\n return { reference, ward: door.drawn === null ? null : Ear.#at(door.ward, 'name') };\n }\n\n *#key(method , args ) {\n const answer = yield { placeholder: 'key', method, args };\n return Ear.#heard(answer);\n }\n\n *#sealed(ward , admitted , choice ) {\n const chosen = yield* this.#key('choose', { ward, admitted, choice });\n const reply = Ear.#at(chosen, 'reply');\n if (reply instanceof Uint8Array) return reply;\n const silence = yield* this.#key('choose', { ward, admitted, choice: Ear.#silence });\n return Ear.#at(silence, 'reply');\n }\n\n #notNetwork(method ) {\n return this.error('refused', `${method} is network's alone, and ${this.stamp.asker} asks it`);\n }\n\n *arrived(args ) {\n if (this.stamp.asker === 'brain' && Ear.field(args, 'answer') !== undefined) return yield* this.#told(args);\n if (this.stamp.asker !== Ear.#network) return this.#notNetwork('arrived');\n const exchange = Ear.#at(args, 'exchange');\n const bytes = Ear.#at(args, 'bytes');\n const own = this.cells.get(['ward']);\n if (typeof exchange !== 'number' || !(bytes instanceof Uint8Array))\n return this.error('refused', 'arrived takes an exchange and its bytes');\n if (own === undefined) return this.error('refused', 'the ear holds no ward');\n const door = yield* this.#doorOf(Ear.#at(args, 'ward'), own);\n const box = bytes.length > 1048576 ? bytes.subarray(0, Ear.#lid) : bytes;\n const reply = door === undefined || door === null ? null : yield* this.#door(door, box, exchange);\n if (reply === Ear.#handed) return null;\n if (reply === Ear.#opened) return Ear.#opened;\n yield {\n placeholder: 'network',\n method: 'reply',\n args: { exchange, bytes: reply },\n };\n return null;\n }\n\n *#door(door , bytes , exchange ) {\n const { ward } = door;\n const opened = yield* this.#key('openHead', { ward, box: bytes });\n const named = opened === undefined || opened === null ? null : Ear.hex(Ear.#at(opened, 'head'));\n const zero = named === Ear.#zeros;\n const heir = named === null || zero ? null : named;\n const lookup = opened === undefined ? undefined : yield* this.#lookup(heir, zero, door);\n const arrival =\n lookup === undefined\n ? undefined\n : yield* this.#key('arrive', { ward, box: bytes, lookup, opened: opened ?? null });\n if (arrival === undefined || Ear.#at(arrival, 'refused') === true) return Ear.#at(arrival, 'reply');\n const admitted = Ear.#at(arrival, 'admitted');\n const method = Ear.#at(admitted, 'method');\n if (heir === null && method === Ear.#redeem) return (yield* this.#redeemed(door, admitted)) ?? null;\n if (heir === null && method === Ear.#offer) return (yield* this.#offered(door, admitted)) ?? null;\n if (heir === null && door.drawn !== null) return yield* this.#sealed(ward, admitted, Ear.#silence);\n const choice =\n heir === null\n ? yield* this.#front(admitted, door, exchange)\n : yield* this.#passed(heir, admitted, door, exchange);\n return choice === Ear.#handed || choice === Ear.#opened ? choice : yield* this.#sealed(ward, admitted, choice);\n }\n\n named(args ) {\n this.cells.set(['named'], Ear.#at(args, 'at') ?? []);\n return null;\n }\n\n addresses(args ) {\n if (this.stamp.asker !== Ear.#network) return this.#notNetwork('addresses');\n const addresses = Ear.#at(args, 'addresses');\n if (!Array.isArray(addresses)) return this.error('refused', 'addresses takes a list');\n this.cells.set(['addresses'], addresses);\n return null;\n }\n\n *#reached() {\n const wired = yield* this.#wired('relay');\n if (wired === undefined) return { why: 'the nerves answer no wiring' };\n if (!wired) return null;\n const answer = yield {\n placeholder: 'relay',\n method: 'address',\n args: {},\n };\n const heard = Ear.#heard(answer);\n const at = Ear.#at(heard, 'at');\n const through = Ear.#at(heard, 'through');\n const addresses = Array.isArray(at) && at.length > 0 && at.every((one) => typeof one === 'string' && one !== '');\n if (!addresses) return { why: 'the relay gives the ward no address' };\n if (through === null) return { at };\n return typeof through === 'string' && through !== '' ? { at, through } : { why: 'the relay names no line to hold' };\n }\n\n *#drawn(open , through ) {\n const own = this.cells.get(['ward']);\n if (own === undefined) return { why: 'the ear holds no ward' };\n if (open) return { ward: own, at: this.#reachedAt(undefined), kept: null };\n const drawn = yield* this.#key('draw', {});\n const ward = Ear.#at(drawn, 'ward');\n if (ward === null) return { why: 'key draws no ward' };\n if (through !== null) {\n const at = [through];\n return { ward, at, kept: { name: Ear.#at(ward, 'name'), sealed: Ear.#at(ward, 'sealed'), at, through } };\n }\n const reached = yield* this.#reached();\n if (reached !== null && 'why' in reached) return reached;\n const held = reached?.through === undefined ? {} : { through: reached.through };\n const at = reached === null ? {} : { at: reached.at, ...held };\n const kept = { name: Ear.#at(ward, 'name'), sealed: Ear.#at(ward, 'sealed'), ...at };\n return { ward, at: this.#reachedAt(reached?.at), kept };\n }\n\n #againRefusal(args , first ) {\n const again = Ear.#at(args, 'again');\n if (again === null) return null;\n if (this.stamp.asker !== 'brain') return \"again is the brain's alone\";\n if (typeof Ear.#at(again, 'node') !== 'string' || typeof Ear.#at(again, 'far') !== 'string')\n return 'again takes the node and the far organism of a standing';\n const open = first || Ear.#at(args, 'anchor') === true || Ear.#at(args, 'public') === true;\n return open ? 'an occupant given again is never an anchor, nor on the public ward' : null;\n }\n\n #holderOf(args ) {\n const again = Ear.#at(args, 'again');\n if (again === null) return { node: this.stamp.asker, note: Ear.#at(args, 'note') };\n return { node: Ear.#at(again, 'node'), again: Ear.#at(again, 'far') };\n }\n\n #lineOf(args , first ) {\n const asked = Ear.#at(args, 'through');\n if (asked === null) return { through: null };\n if (typeof asked !== 'string' || asked === '') return { why: 'through takes an address' };\n if (first || Ear.#at(args, 'anchor') === true || Ear.#at(args, 'public') === true)\n return { why: 'a ward reached through a line is never an anchor, nor the public ward' };\n return { through: asked };\n }\n\n #referRefusal(args , first ) {\n if (Ear.#at(args, 'refer') !== true) return null;\n return first || Ear.#at(args, 'anchor') === true ? \"a reference is never an anchor's\" : null;\n }\n\n *card() {\n if (this.stamp.asker !== 'brain') return this.error('refused', \"card is the brain's alone\");\n const card = yield* this.#cardOf();\n return 'why' in card ? this.error('refused', card.why) : card;\n }\n\n *ward() {\n if (this.stamp.asker !== 'brain') return this.error('refused', \"ward is the brain's alone\");\n const drawn = yield* this.#key('draw', {});\n const ward = Ear.#at(drawn, 'ward');\n if (ward === null) return this.error('refused', 'key draws no ward');\n return { name: Ear.#at(ward, 'name'), sealed: Ear.#at(ward, 'sealed') };\n }\n\n *invite(args ) {\n const waits = Ear.#at(args, 'waits');\n const lives = Ear.#at(args, 'lives');\n const marked = Ear.#at(args, 'anchor') === true ? { anchor: true } : {};\n const spans = [waits, lives].every((span) => span === null || typeof span === 'number');\n if (!spans) return this.error('refused', 'invite takes two spans');\n const says = Ear.field(args, 'says');\n if (says === null) return this.error('refused', 'says is never null: an invitation that says nothing names none');\n const first = Ear.#at(args, 'first') === true;\n if (first && this.stamp.asker !== 'brain') return this.error('refused', \"first is the brain's alone\");\n const refusal = this.#againRefusal(args, first);\n if (refusal !== null) return this.error('refused', refusal);\n const line = this.#lineOf(args, first);\n if ('why' in line) return this.error('refused', line.why);\n const barred = this.#referRefusal(args, first);\n if (barred !== null) return this.error('refused', barred);\n const { through } = line;\n const refer = Ear.#at(args, 'refer') === true;\n const open = Ear.#at(args, 'public') === true;\n const drawn = yield* this.#drawn(open && !refer, through);\n if ('why' in drawn) return this.error('refused', drawn.why);\n const at = drawn.at === undefined ? {} : { at: drawn.at };\n const said = says === undefined ? {} : { says };\n const beside = {\n ...(waits === null ? {} : { waits }),\n ...(lives === null ? {} : { lives }),\n ...said,\n ...(first || Ear.#at(args, 'anchor') === true ? { anchor: true } : {}),\n };\n const invited = yield* this.#key('invite', { ward: drawn.ward, ...at, beside });\n const text = Ear.#at(invited, 'invitation');\n const heir = Ear.#at(invited, 'heir');\n if (typeof text !== 'string' || typeof heir !== 'string') return this.error('refused', 'key draws no invitation');\n const ward = drawn.kept === null ? {} : { ward: drawn.kept };\n const kept = this.#holderOf(args);\n const named = first ? { first: true } : {};\n const related = yield {\n placeholder: 'brain',\n method: 'relate',\n args: { ...kept, heir, waits, lives, ...said, ...marked, ...ward, ...named },\n };\n if ('error' in related) return this.#refused(related.error);\n const far = Ear.#at(related.result, 'far');\n if (!refer) return { invitation: text, far };\n const name = Ear.#at(drawn.ward, 'name');\n const door = open ? yield* this.#cardOf() : { ward: name, at: Array.isArray(drawn.at) ? drawn.at : [] };\n if ('why' in door) return this.error('refused', door.why);\n const minted = { node: kept.node, waits, lives, says: says ?? null, far, ward: name, public: open };\n return yield* this.#referred(text, door, minted);\n }\n\n *#referred(\n text ,\n card ,\n minted \n \n \n \n \n \n \n \n ,\n ) {\n const referred = yield* this.#key('refer', { invitation: text });\n const reference = Ear.#at(referred, 'reference');\n const sealed = Ear.#at(referred, 'sealed');\n if (typeof reference !== 'string' || !(sealed instanceof Uint8Array))\n return this.error('refused', 'key keeps no reference');\n const kept = yield {\n placeholder: 'brain',\n method: 'refer',\n args: {\n node: minted.node,\n reference,\n sealed,\n waits: minted.waits,\n ward: minted.ward,\n public: minted.public,\n says: minted.says,\n lives: minted.lives,\n },\n };\n if ('error' in kept) return this.#refused(kept.error);\n return { link: { card, reference }, far: minted.far };\n }\n\n *#cardOf() {\n const drawn = yield* this.#drawn(true, null);\n if ('why' in drawn) return drawn;\n return { ward: Ear.#at(drawn.ward, 'name'), at: Array.isArray(drawn.at) ? drawn.at : [] };\n }\n\n *drop(args ) {\n const far = Ear.#at(args, 'far');\n const reference = Ear.#at(args, 'reference');\n if (typeof reference === 'string' && far === null) {\n const unrefer = yield {\n placeholder: 'brain',\n method: 'unrefer',\n args: { reference, node: this.stamp.asker },\n };\n return 'error' in unrefer ? this.#refused(unrefer.error) : null;\n }\n if (typeof far !== 'string' || reference !== null)\n return this.error('refused', 'drop takes a far organism or a reference');\n const ended = yield {\n placeholder: 'brain',\n method: 'end',\n args: { far, node: this.stamp.asker },\n };\n return 'error' in ended ? this.#refused(ended.error) : null;\n }\n\n *relisten(_args ) {\n if (this.stamp.asker !== 'brain') return this.error('refused', \"relisten is the brain's alone\");\n const held = yield { placeholder: 'brain', method: 'lines', args: {} };\n if ('error' in held) return this.#refused(held.error);\n if (!Array.isArray(held.result)) return this.error('refused', 'the brain answers no lines');\n const lines = held.result.map((line) => {\n const wards = Ear.#at(line, 'wards');\n const names = Array.isArray(wards) ? wards.map((ward) => Ear.#at(ward, 'name')) : [];\n return { address: Ear.#at(line, 'address'), wards: names };\n });\n const listened = yield {\n placeholder: Ear.#network,\n method: 'listen',\n args: { lines },\n durable: true,\n };\n return 'error' in listened ? this.#refused(listened.error) : null;\n }\n\n *challenged(args ) {\n if (this.stamp.asker !== Ear.#network) return this.#notNetwork('challenged');\n const [address, nonce, identity] = [Ear.#at(args, 'address'), Ear.#at(args, 'nonce'), Ear.#at(args, 'identity')];\n const held = yield { placeholder: 'brain', method: 'lines', args: {} };\n if ('error' in held) return this.#refused(held.error);\n const line = Array.isArray(held.result)\n ? held.result.find((one) => Ear.#at(one, 'address') === address)\n : undefined;\n const wards = Ear.#at(line, 'wards');\n if (!Array.isArray(wards) || wards.length === 0) return { proofs: [] };\n const proofs = Ear.#at(yield* this.#key('prove', { wards, nonce, identity }), 'proofs');\n if (!Array.isArray(proofs)) return this.error('refused', 'key proves no ward of the line');\n return { proofs: wards.map((ward, at) => ({ ward: Ear.#at(ward, 'name'), proof: proofs[at] ?? null })) };\n }\n\n *line(args ) {\n if (this.stamp.asker !== Ear.#network) return this.#notNetwork('line');\n const wards = Ear.#at(args, 'wards');\n const up = Ear.#at(args, 'up');\n if (!Array.isArray(wards) || typeof up !== 'boolean') return this.error('refused', 'line takes wards and up');\n const told = yield {\n placeholder: 'brain',\n method: 'line',\n args: { wards, up },\n };\n return 'error' in told ? this.#refused(told.error) : null;\n }\n}";
4149
+ var EAR_TEXT = "class Ear extends Faculty {\n static #bytes = {\n type: 'string',\n contentEncoding: 'base16',\n maxLength: 1048576,\n };\n static #arrival = { ...Ear.#bytes, maxLength: 1048576 + 1 };\n static #text = { type: 'string', minLength: 1 };\n static #name = { type: 'string', pattern: '^[0-9a-f]{128}$' };\n static #reference = { type: 'string', pattern: '^[a-z2-7]{26}$' };\n static #says = {\n anyOf: [{ type: 'object' }, { type: 'array' }, { type: 'string' }, { type: 'number' }, { type: 'boolean' }],\n };\n static #again = {\n type: 'object',\n properties: { node: Ear.#text, far: Ear.#text },\n required: ['node', 'far'],\n additionalProperties: false,\n };\n\n static blueprint = {\n name: 'nervur.ear',\n version: '0.37.12',\n description: 'The ear: it opens and seals the boxes of Quo, and the brain keeps every relation.',\n methods: {\n arrived: {\n description:\n \"A box arrived on an exchange, sent to the ward named, the public ward where none is: opened, judged by Quo and handed on, or replied. Answers `{opened: true}` where it handed on an ask it admitted on a relation, so the carrier counts what that ask came on as carried, and null otherwise. The brain's alone, with `answer`: what a node answered of an ask the ear handed on, sealed and replied on its exchange.\",\n kind: 'reading',\n args: {\n anyOf: [\n {\n type: 'object',\n properties: {\n exchange: { type: 'integer', minimum: 0 },\n bytes: Ear.#arrival,\n ward: Ear.#name,\n },\n required: ['exchange', 'bytes'],\n additionalProperties: false,\n },\n {\n type: 'object',\n properties: {\n exchange: { type: 'integer', minimum: 0 },\n door: {},\n admitted: {},\n front: { type: 'boolean' },\n answer: {},\n },\n required: ['exchange', 'door', 'admitted', 'answer'],\n additionalProperties: false,\n },\n ],\n },\n result: {\n anyOf: [\n { type: 'null' },\n {\n type: 'object',\n properties: { opened: { const: true } },\n required: ['opened'],\n additionalProperties: false,\n },\n ],\n },\n errors: ['refused'],\n },\n named: {\n description:\n \"The brain's alone, for its owners' `addresses`. Keeps the addresses of the organism's own an owner named, in place of those before, beside what `network` reports.\",\n kind: 'writing',\n askers: ['brain'],\n args: {\n type: 'object',\n properties: { at: { type: 'array', items: Ear.#text } },\n required: ['at'],\n additionalProperties: false,\n },\n result: { type: 'null' },\n errors: ['refused'],\n },\n addresses: {\n description: 'The addresses `network` last reported.',\n kind: 'writing',\n args: {\n type: 'object',\n properties: { addresses: { type: 'array', items: Ear.#text } },\n required: ['addresses'],\n additionalProperties: false,\n },\n result: { type: 'null' },\n errors: ['refused'],\n },\n line: {\n description:\n 'A line, accepted at an endpoint or held, that names `wards` came up or went down, told by `network` alone. The ear asks the brain `line {wards, up}`, up and down alike: on up the brain asks each lobe granted a standing on one of them `back`, and either way it asks the lobe that gave an occupant drawn through that line `line {far, up}`.',\n kind: 'reading',\n askers: ['network'],\n args: {\n type: 'object',\n properties: { wards: { type: 'array', items: Ear.#name }, up: { type: 'boolean' } },\n required: ['wards', 'up'],\n additionalProperties: false,\n },\n result: { type: 'null' },\n errors: ['refused'],\n },\n challenged: {\n description:\n 'A line `network` holds to `address` was challenged by its listener with `nonce` and `identity`, told by `network` alone. The ear asks the brain `lines {}` for the wards drawn through that address and `key` `prove {wards, nonce, identity}`, and answers `{proofs: [{ward, proof}]}`, each ward with its proof under that challenge alone; a line the brain holds no ward on is answered with none. It writes no cell.',\n kind: 'reading',\n askers: ['network'],\n args: {\n type: 'object',\n properties: {\n address: { type: 'string', minLength: 1 },\n nonce: { type: 'string', contentEncoding: 'base16', minLength: 32, maxLength: 32 },\n identity: { type: 'string', contentEncoding: 'base16', minLength: 32, maxLength: 32 },\n },\n required: ['address', 'nonce', 'identity'],\n additionalProperties: false,\n },\n result: {\n type: 'object',\n properties: {\n proofs: {\n type: 'array',\n items: {\n type: 'object',\n properties: {\n ward: Ear.#name,\n proof: { type: 'string', contentEncoding: 'base16', minLength: 64, maxLength: 64 },\n },\n required: ['ward', 'proof'],\n additionalProperties: false,\n },\n },\n },\n required: ['proofs'],\n additionalProperties: false,\n },\n errors: ['refused'],\n },\n relisten: {\n description:\n \"The brain's alone, told once a change has landed that moved a line, a relation drawn through an address related or ended (`drop`, `left`, a lapse, a reinvite that replaced its keys). The ear asks the brain `lines {}` and `network` `listen {lines}`, durable, the whole set, which replaces the one kept. It writes no cell; it is writing so that it runs alone, behind the reading asks, and nothing waits on it.\",\n kind: 'writing',\n args: { type: 'object', properties: {}, additionalProperties: false },\n result: { type: 'null' },\n errors: ['refused'],\n },\n invite: {\n description:\n \"Draws an invitation to the asker alone, from a ward drawn fresh for it, or the public ward with `public`, kept by the brain for `waits`, null until it is knocked on or ended, and its relation for `lives`, null for good, each span any the asker names, and answers it beside its far organism's ID; the brain asks it with `anchor` for the next anchor. The invitation's text, which `key` has its ward sign whole, carries the two spans it names, `waits` and `lives`, so the side that accepts lapses it by its own clock, and the anchor's mark, `anchor: true`, where it is the next anchor's or, with `first`, the brain's alone, the first invitation. With `note`, free data of at most 4 KiB as its canonical text by default, `note` an owner's word over it, and never a secret, what the standing is for and to whom it is given: the brain keeps it beside the standing, null where none is named, and it never enters the invitation. With `says`, free data never null and never a secret, at most a quarter of the note's bound, 1 KiB by default, which the brain refuses past that bound: what the invitation says to whoever holds it before the yes, carried in the invitation beside its spans, and kept by neither brain but as the offer of a reference. With `again`, `{node, far}`, the brain's alone, the invitation gives again in its place the standing `node` gave of the far organism `far`: it is drawn as ever, and the brain replaces that standing's relation, keeping its far organism, its wires and its note, so `note` is never sent with it. A ward drawn fresh is reached at the address of its own the lobe wired to `relay` gives it, `address {}` answering `{at}`, and where none is wired, where the organism is. With `through`, the address of the organism always on, the ward is reached at that address alone, `at` is `[through]` and no relay is asked, and the brain is told beside the relation which address it was drawn through, so it alone keeps the lines; `through` is refused with `public` or `anchor`, and the brain's `reinvite` of a standing drawn through a line names that `through` again. With `refer`, the invitation is drawn exactly so, a line's or a relay's address among it, but `key` keeps it sealed behind a reference it draws by chance, 128 bits as twenty-six lowercase base32, which the brain holds for `waits` (null until redeemed or dropped), and the answer is `{link: {card, reference}, far}`, never the invitation: `card` is the ward drawn for it and where that ward is reached, so no two links name one ward. A stranger redeems the reference once, on that ward's zero head, by `#redeem {reference}`, which the ear answers itself, the reply's object the invitation; and while it waits reads its offer there as often as it asks, spending nothing, by `#offer {reference}`, the reply's object `{says, waits, lives}`: what the invitation says, null where nothing, what is left of its wait and how long its relation lives, each null for none. With `public` beside `refer`, as for a link on a domain, the invitation is still drawn on a ward fresh for it, and `card` is what `card` answers, the public ward and its addresses, whose zero head redeems it. `refer` is refused with `anchor` and `first`.\",\n kind: 'reading',\n args: {\n type: 'object',\n properties: {\n waits: { anyOf: [{ type: 'integer', minimum: 0 }, { type: 'null' }] },\n lives: { anyOf: [{ type: 'integer', minimum: 0 }, { type: 'null' }] },\n anchor: { type: 'boolean' },\n first: { type: 'boolean' },\n public: { type: 'boolean' },\n refer: { type: 'boolean' },\n through: Ear.#text,\n note: {},\n says: Ear.#says,\n again: Ear.#again,\n },\n required: ['waits', 'lives'],\n additionalProperties: false,\n },\n result: {\n anyOf: [\n {\n type: 'object',\n properties: { invitation: Ear.#text, far: Ear.#text },\n required: ['invitation', 'far'],\n additionalProperties: false,\n },\n {\n type: 'object',\n properties: {\n link: {\n type: 'object',\n properties: {\n card: {\n type: 'object',\n properties: { ward: Ear.#name, at: { type: 'array', items: Ear.#text } },\n required: ['ward', 'at'],\n additionalProperties: false,\n },\n reference: Ear.#reference,\n },\n required: ['card', 'reference'],\n additionalProperties: false,\n },\n far: Ear.#text,\n },\n required: ['link', 'far'],\n additionalProperties: false,\n },\n ],\n },\n errors: ['refused'],\n },\n card: {\n description:\n \"The brain's alone, for its owners' `card`. Answers `{ward, at}`, the public ward's name and the addresses `network` last reported, empty where none was: the very ward and addresses an invitation drawn with `public` carries. It writes no cell and asks no one.\",\n kind: 'reading',\n args: { type: 'object', properties: {}, additionalProperties: false },\n result: {\n type: 'object',\n properties: { ward: Ear.#name, at: { type: 'array', items: Ear.#text } },\n required: ['ward', 'at'],\n additionalProperties: false,\n },\n errors: ['refused'],\n },\n ward: {\n description:\n \"The brain's alone, for its owners' `ward`. `key` draws a new ward, answered as `{name, sealed}`, which the brain lays in the ear's cell: an ask from far runs through the ear, which could write nothing until it ended.\",\n kind: 'reading',\n args: { type: 'object', properties: {}, additionalProperties: false },\n result: { type: 'object' },\n errors: ['refused'],\n },\n drop: {\n irreversible: true,\n description:\n \"Ends the asker's relation with a far organism. One it gave ends here, and an ask arriving while it ends hears `removed`; a standing it holds ends as the mouth's `drop` ends one, its `#leave` sent first. The brain takes a relation given through a line off its line when it ends. With `reference` instead of `far`, the reference the asker minted is taken off, so a `#redeem` or an `#offer` of it is silence; another node's or an unknown one is refused. The relation of its invitation stays, as any unknocked one does, and lapses by its `waits`.\",\n kind: 'reading',\n args: {\n anyOf: [\n {\n type: 'object',\n properties: { far: Ear.#text },\n required: ['far'],\n additionalProperties: false,\n },\n {\n type: 'object',\n properties: { reference: Ear.#reference },\n required: ['reference'],\n additionalProperties: false,\n },\n ],\n },\n result: { type: 'null' },\n errors: ['refused'],\n },\n },\n placeholders: {\n brain: 'nervur.brain',\n network: 'nervur.network',\n front: null,\n key: 'nervur.key',\n relay: null,\n },\n };\n\n static #network = 'network';\n static #silence = { silence: true };\n static #redeem = '#redeem';\n static #offer = '#offer';\n static #handed = { handed: true };\n static #opened = { opened: true };\n static #zeros = '0'.repeat(64);\n static #lid = 32;\n\n static #at(data , key ) {\n return Ear.field(data, key) ?? null;\n }\n\n static #heard(answer ) {\n return 'result' in answer ? answer.result : undefined;\n }\n\n #refused({ code, message } ) {\n return this.error(code === 'busy' ? 'busy' : 'refused', message);\n }\n\n #choice(answer , seen , door ) {\n if (Ear.#at(Ear.#at(answer, 'error'), 'code') === 'silent') return Ear.#silence;\n const at = this.#reachedAt(door.at);\n return { object: this.codec.text(answer), seen, ...(at === undefined ? {} : { at }) };\n }\n\n static #described(admitted , answer ) {\n return Ear.#at(admitted, 'method') === null ? (Ear.#at(answer, 'result') ?? answer) : answer;\n }\n\n #reachedAt(own ) {\n const at = Array.isArray(own) ? own : this.cells.get(['addresses']);\n const named = this.cells.get(['named']);\n if (!Array.isArray(named) || named.length === 0) return Array.isArray(at) ? at : undefined;\n return [...(Array.isArray(at) ? at : []), ...named.filter((one) => !Array.isArray(at) || !at.includes(one))];\n }\n\n *#wired(placeholder ) {\n const read = yield {\n placeholder: 'nerves',\n method: 'read',\n args: {},\n };\n const wires = Ear.#heard(read);\n if (!Array.isArray(wires)) return undefined;\n return wires.some((wire) => Ear.#at(wire, 'placeholder') === placeholder && Ear.#at(wire, 'termination') !== null);\n }\n\n #argsOf(admitted ) {\n const text = Ear.#at(admitted, 'args');\n return typeof text === 'string' ? this.codec.read(text) : { why: 'the args are no text' };\n }\n\n *#lookup(heir , zero , door ) {\n if (door.drawn !== null) {\n const occupant = Ear.#at(door.drawn, 'occupant');\n const held = heir !== null && Ear.#at(occupant, 'heir') === heir;\n return { occupants: held ? { [heir]: occupant } : {}, zero: zero && Ear.#at(door.drawn, 'linked') === true };\n }\n if (heir !== null) {\n const relation = yield {\n placeholder: 'brain',\n method: 'relation',\n args: { heir },\n };\n const found = Ear.#heard(relation);\n if (found === undefined) return undefined;\n const held = found !== null && Ear.#at(found, 'ward') === null;\n return { occupants: held ? { [heir]: Ear.#at(found, 'occupant') } : {}, zero: false };\n }\n return { occupants: {}, zero };\n }\n\n *#doorOf(named , ward ) {\n if (typeof named !== 'string' || named === Ear.#at(ward, 'name')) return { ward, drawn: null, at: undefined };\n const relation = yield {\n placeholder: 'brain',\n method: 'relation',\n args: { ward: named },\n };\n const found = Ear.#heard(relation);\n if (found === undefined || found === null) return found;\n const kept = Ear.#at(found, 'ward');\n const own = { name: Ear.#at(kept, 'name'), sealed: Ear.#at(kept, 'sealed') };\n return { ward: own, drawn: found, at: Ear.field(kept, 'at') };\n }\n\n static #after(exchange , door , admitted ) {\n const { ward, at } = door;\n const kept = ['heir', 'by', 'seq', 'method', 'next', 'sealed'].map((name) => [name, Ear.#at(admitted, name)]);\n return {\n exchange,\n door: { ward, ...(at === undefined ? {} : { at }) },\n admitted: { ...Object.fromEntries(kept), args: '' },\n };\n }\n\n *#passed(heir , admitted , door , exchange ) {\n const args = this.#argsOf(admitted);\n const given = 'data' in args ? { args: args.data } : { args: null, refused: args.why };\n yield {\n placeholder: 'brain',\n method: 'pass',\n args: {\n heir,\n method: Ear.#at(admitted, 'method'),\n ...given,\n next: Ear.#at(admitted, 'next'),\n },\n after: Ear.#after(exchange, door, admitted),\n };\n return Ear.#opened;\n }\n\n *#front(admitted , door , exchange ) {\n const method = Ear.#at(admitted, 'method');\n if (method !== null && typeof method !== 'string') return Ear.#silence;\n if ((yield* this.#wired('front')) !== true) return Ear.#silence;\n const args = this.#argsOf(admitted);\n if ('why' in args) return this.#choice({ error: { code: 'refused', message: args.why } }, null, door);\n yield {\n placeholder: 'front',\n method,\n args: args.data,\n after: { ...Ear.#after(exchange, door, admitted), front: true },\n };\n return Ear.#handed;\n }\n\n #answered(args , door ) {\n const admitted = Ear.#at(args, 'admitted');\n const answer = Ear.#at(args, 'answer');\n if (Ear.#at(args, 'front') === true) return this.#choice(Ear.#described(admitted, answer), null, door);\n const heard = Ear.#at(answer, 'result');\n if (heard === null) return undefined;\n const seen = Ear.#at(heard, 'seen');\n return this.#choice(\n Ear.#described(admitted, Ear.#at(heard, 'answer')),\n typeof seen === 'string' ? seen : null,\n door,\n );\n }\n\n *#told(args ) {\n const kept = Ear.#at(args, 'door');\n const door = { ward: Ear.#at(kept, 'ward'), drawn: null, at: Ear.field(kept, 'at') };\n const choice = this.#answered(args, door);\n const reply = choice === undefined ? null : yield* this.#sealed(door.ward, Ear.#at(args, 'admitted'), choice);\n yield { placeholder: 'network', method: 'reply', args: { exchange: Ear.#at(args, 'exchange'), bytes: reply } };\n return null;\n }\n\n *#redeemed(door , admitted ) {\n const asked = this.#referenceOf(door, admitted);\n if (asked === null) return yield* this.#sealed(door.ward, admitted, Ear.#silence);\n const { reference } = asked;\n const kept = yield { placeholder: 'brain', method: 'redeem', args: asked };\n const heard = Ear.#heard(kept);\n if (heard === undefined) return undefined;\n const sealed = Ear.#at(heard, 'sealed');\n if (!(sealed instanceof Uint8Array)) return yield* this.#sealed(door.ward, admitted, Ear.#silence);\n const reply = yield* this.#key('redeem', { ward: door.ward, admitted, reference, sealed });\n const redeemed = Ear.#at(reply, 'reply');\n return redeemed instanceof Uint8Array ? redeemed : yield* this.#sealed(door.ward, admitted, Ear.#silence);\n }\n\n *#offered(door , admitted ) {\n const asked = this.#referenceOf(door, admitted);\n if (asked === null) return yield* this.#sealed(door.ward, admitted, Ear.#silence);\n const kept = yield { placeholder: 'brain', method: 'offered', args: asked };\n const heard = Ear.#heard(kept);\n if (heard === undefined) return undefined;\n const choice = heard === null ? Ear.#silence : { object: this.codec.text(heard), seen: null };\n return yield* this.#sealed(door.ward, admitted, choice);\n }\n\n #referenceOf(door , admitted ) {\n const args = this.#argsOf(admitted);\n const reference = 'data' in args ? Ear.#at(args.data, 'reference') : null;\n if (typeof reference !== 'string' || !/^[a-z2-7]{26}$/.test(reference)) return null;\n return { reference, ward: door.drawn === null ? null : Ear.#at(door.ward, 'name') };\n }\n\n *#key(method , args ) {\n const answer = yield { placeholder: 'key', method, args };\n return Ear.#heard(answer);\n }\n\n *#sealed(ward , admitted , choice ) {\n const chosen = yield* this.#key('choose', { ward, admitted, choice });\n const reply = Ear.#at(chosen, 'reply');\n if (reply instanceof Uint8Array) return reply;\n const silence = yield* this.#key('choose', { ward, admitted, choice: Ear.#silence });\n return Ear.#at(silence, 'reply');\n }\n\n #notNetwork(method ) {\n return this.error('refused', `${method} is network's alone, and ${this.stamp.asker} asks it`);\n }\n\n *arrived(args ) {\n if (this.stamp.asker === 'brain' && Ear.field(args, 'answer') !== undefined) return yield* this.#told(args);\n if (this.stamp.asker !== Ear.#network) return this.#notNetwork('arrived');\n const exchange = Ear.#at(args, 'exchange');\n const bytes = Ear.#at(args, 'bytes');\n const own = this.cells.get(['ward']);\n if (typeof exchange !== 'number' || !(bytes instanceof Uint8Array))\n return this.error('refused', 'arrived takes an exchange and its bytes');\n if (own === undefined) return this.error('refused', 'the ear holds no ward');\n const door = yield* this.#doorOf(Ear.#at(args, 'ward'), own);\n const box = bytes.length > 1048576 ? bytes.subarray(0, Ear.#lid) : bytes;\n const reply = door === undefined || door === null ? null : yield* this.#door(door, box, exchange);\n if (reply === Ear.#handed) return null;\n if (reply === Ear.#opened) return Ear.#opened;\n yield {\n placeholder: 'network',\n method: 'reply',\n args: { exchange, bytes: reply },\n };\n return null;\n }\n\n *#door(door , bytes , exchange ) {\n const { ward } = door;\n const opened = yield* this.#key('openHead', { ward, box: bytes });\n const named = opened === undefined || opened === null ? null : Ear.hex(Ear.#at(opened, 'head'));\n const zero = named === Ear.#zeros;\n const heir = named === null || zero ? null : named;\n const lookup = opened === undefined ? undefined : yield* this.#lookup(heir, zero, door);\n const arrival =\n lookup === undefined\n ? undefined\n : yield* this.#key('arrive', { ward, box: bytes, lookup, opened: opened ?? null });\n if (arrival === undefined || Ear.#at(arrival, 'refused') === true) return Ear.#at(arrival, 'reply');\n const admitted = Ear.#at(arrival, 'admitted');\n const method = Ear.#at(admitted, 'method');\n if (heir === null && method === Ear.#redeem) return (yield* this.#redeemed(door, admitted)) ?? null;\n if (heir === null && method === Ear.#offer) return (yield* this.#offered(door, admitted)) ?? null;\n if (heir === null && door.drawn !== null) return yield* this.#sealed(ward, admitted, Ear.#silence);\n const choice =\n heir === null\n ? yield* this.#front(admitted, door, exchange)\n : yield* this.#passed(heir, admitted, door, exchange);\n return choice === Ear.#handed || choice === Ear.#opened ? choice : yield* this.#sealed(ward, admitted, choice);\n }\n\n named(args ) {\n this.cells.set(['named'], Ear.#at(args, 'at') ?? []);\n return null;\n }\n\n addresses(args ) {\n if (this.stamp.asker !== Ear.#network) return this.#notNetwork('addresses');\n const addresses = Ear.#at(args, 'addresses');\n if (!Array.isArray(addresses)) return this.error('refused', 'addresses takes a list');\n this.cells.set(['addresses'], addresses);\n return null;\n }\n\n *#reached() {\n const wired = yield* this.#wired('relay');\n if (wired === undefined) return { why: 'the nerves answer no wiring' };\n if (!wired) return null;\n const answer = yield {\n placeholder: 'relay',\n method: 'address',\n args: {},\n };\n const heard = Ear.#heard(answer);\n const at = Ear.#at(heard, 'at');\n const through = Ear.#at(heard, 'through');\n const addresses = Array.isArray(at) && at.length > 0 && at.every((one) => typeof one === 'string' && one !== '');\n if (!addresses) return { why: 'the relay gives the ward no address' };\n if (through === null) return { at };\n return typeof through === 'string' && through !== '' ? { at, through } : { why: 'the relay names no line to hold' };\n }\n\n *#drawn(open , through ) {\n const own = this.cells.get(['ward']);\n if (own === undefined) return { why: 'the ear holds no ward' };\n if (open) return { ward: own, at: this.#reachedAt(undefined), kept: null };\n const drawn = yield* this.#key('draw', {});\n const ward = Ear.#at(drawn, 'ward');\n if (ward === null) return { why: 'key draws no ward' };\n if (through !== null) {\n const at = [through];\n return { ward, at, kept: { name: Ear.#at(ward, 'name'), sealed: Ear.#at(ward, 'sealed'), at, through } };\n }\n const reached = yield* this.#reached();\n if (reached !== null && 'why' in reached) return reached;\n const held = reached?.through === undefined ? {} : { through: reached.through };\n const at = reached === null ? {} : { at: reached.at, ...held };\n const kept = { name: Ear.#at(ward, 'name'), sealed: Ear.#at(ward, 'sealed'), ...at };\n return { ward, at: this.#reachedAt(reached?.at), kept };\n }\n\n #againRefusal(args , first ) {\n const again = Ear.#at(args, 'again');\n if (again === null) return null;\n if (this.stamp.asker !== 'brain') return \"again is the brain's alone\";\n if (typeof Ear.#at(again, 'node') !== 'string' || typeof Ear.#at(again, 'far') !== 'string')\n return 'again takes the node and the far organism of a standing';\n const open = first || Ear.#at(args, 'anchor') === true || Ear.#at(args, 'public') === true;\n return open ? 'an occupant given again is never an anchor, nor on the public ward' : null;\n }\n\n #holderOf(args ) {\n const again = Ear.#at(args, 'again');\n if (again === null) return { node: this.stamp.asker, note: Ear.#at(args, 'note') };\n return { node: Ear.#at(again, 'node'), again: Ear.#at(again, 'far') };\n }\n\n #lineOf(args , first ) {\n const asked = Ear.#at(args, 'through');\n if (asked === null) return { through: null };\n if (typeof asked !== 'string' || asked === '') return { why: 'through takes an address' };\n if (first || Ear.#at(args, 'anchor') === true || Ear.#at(args, 'public') === true)\n return { why: 'a ward reached through a line is never an anchor, nor the public ward' };\n return { through: asked };\n }\n\n #referRefusal(args , first ) {\n if (Ear.#at(args, 'refer') !== true) return null;\n return first || Ear.#at(args, 'anchor') === true ? \"a reference is never an anchor's\" : null;\n }\n\n *card() {\n if (this.stamp.asker !== 'brain') return this.error('refused', \"card is the brain's alone\");\n const card = yield* this.#cardOf();\n return 'why' in card ? this.error('refused', card.why) : card;\n }\n\n *ward() {\n if (this.stamp.asker !== 'brain') return this.error('refused', \"ward is the brain's alone\");\n const drawn = yield* this.#key('draw', {});\n const ward = Ear.#at(drawn, 'ward');\n if (ward === null) return this.error('refused', 'key draws no ward');\n return { name: Ear.#at(ward, 'name'), sealed: Ear.#at(ward, 'sealed') };\n }\n\n *invite(args ) {\n const waits = Ear.#at(args, 'waits');\n const lives = Ear.#at(args, 'lives');\n const marked = Ear.#at(args, 'anchor') === true ? { anchor: true } : {};\n const spans = [waits, lives].every((span) => span === null || typeof span === 'number');\n if (!spans) return this.error('refused', 'invite takes two spans');\n const says = Ear.field(args, 'says');\n if (says === null) return this.error('refused', 'says is never null: an invitation that says nothing names none');\n const first = Ear.#at(args, 'first') === true;\n if (first && this.stamp.asker !== 'brain') return this.error('refused', \"first is the brain's alone\");\n const refusal = this.#againRefusal(args, first);\n if (refusal !== null) return this.error('refused', refusal);\n const line = this.#lineOf(args, first);\n if ('why' in line) return this.error('refused', line.why);\n const barred = this.#referRefusal(args, first);\n if (barred !== null) return this.error('refused', barred);\n const { through } = line;\n const refer = Ear.#at(args, 'refer') === true;\n const open = Ear.#at(args, 'public') === true;\n const drawn = yield* this.#drawn(open && !refer, through);\n if ('why' in drawn) return this.error('refused', drawn.why);\n const at = drawn.at === undefined ? {} : { at: drawn.at };\n const said = says === undefined ? {} : { says };\n const beside = {\n ...(waits === null ? {} : { waits }),\n ...(lives === null ? {} : { lives }),\n ...said,\n ...(first || Ear.#at(args, 'anchor') === true ? { anchor: true } : {}),\n };\n const invited = yield* this.#key('invite', { ward: drawn.ward, ...at, beside });\n const text = Ear.#at(invited, 'invitation');\n const heir = Ear.#at(invited, 'heir');\n if (typeof text !== 'string' || typeof heir !== 'string') return this.error('refused', 'key draws no invitation');\n const ward = drawn.kept === null ? {} : { ward: drawn.kept };\n const kept = this.#holderOf(args);\n const named = first ? { first: true } : {};\n const related = yield {\n placeholder: 'brain',\n method: 'relate',\n args: { ...kept, heir, waits, lives, ...said, ...marked, ...ward, ...named },\n };\n if ('error' in related) return this.#refused(related.error);\n const far = Ear.#at(related.result, 'far');\n if (!refer) return { invitation: text, far };\n const name = Ear.#at(drawn.ward, 'name');\n const door = open ? yield* this.#cardOf() : { ward: name, at: Array.isArray(drawn.at) ? drawn.at : [] };\n if ('why' in door) return this.error('refused', door.why);\n const minted = { node: kept.node, waits, lives, says: says ?? null, far, ward: name, public: open };\n return yield* this.#referred(text, door, minted);\n }\n\n *#referred(\n text ,\n card ,\n minted \n \n \n \n \n \n \n \n ,\n ) {\n const referred = yield* this.#key('refer', { invitation: text });\n const reference = Ear.#at(referred, 'reference');\n const sealed = Ear.#at(referred, 'sealed');\n if (typeof reference !== 'string' || !(sealed instanceof Uint8Array))\n return this.error('refused', 'key keeps no reference');\n const kept = yield {\n placeholder: 'brain',\n method: 'refer',\n args: {\n node: minted.node,\n reference,\n sealed,\n waits: minted.waits,\n ward: minted.ward,\n public: minted.public,\n says: minted.says,\n lives: minted.lives,\n },\n };\n if ('error' in kept) return this.#refused(kept.error);\n return { link: { card, reference }, far: minted.far };\n }\n\n *#cardOf() {\n const drawn = yield* this.#drawn(true, null);\n if ('why' in drawn) return drawn;\n return { ward: Ear.#at(drawn.ward, 'name'), at: Array.isArray(drawn.at) ? drawn.at : [] };\n }\n\n *drop(args ) {\n const far = Ear.#at(args, 'far');\n const reference = Ear.#at(args, 'reference');\n if (typeof reference === 'string' && far === null) {\n const unrefer = yield {\n placeholder: 'brain',\n method: 'unrefer',\n args: { reference, node: this.stamp.asker },\n };\n return 'error' in unrefer ? this.#refused(unrefer.error) : null;\n }\n if (typeof far !== 'string' || reference !== null)\n return this.error('refused', 'drop takes a far organism or a reference');\n const ended = yield {\n placeholder: 'brain',\n method: 'end',\n args: { far, node: this.stamp.asker },\n };\n return 'error' in ended ? this.#refused(ended.error) : null;\n }\n\n *relisten(_args ) {\n if (this.stamp.asker !== 'brain') return this.error('refused', \"relisten is the brain's alone\");\n const held = yield { placeholder: 'brain', method: 'lines', args: {} };\n if ('error' in held) return this.#refused(held.error);\n if (!Array.isArray(held.result)) return this.error('refused', 'the brain answers no lines');\n const lines = held.result.map((line) => {\n const wards = Ear.#at(line, 'wards');\n const names = Array.isArray(wards) ? wards.map((ward) => Ear.#at(ward, 'name')) : [];\n return { address: Ear.#at(line, 'address'), wards: names };\n });\n const listened = yield {\n placeholder: Ear.#network,\n method: 'listen',\n args: { lines },\n durable: true,\n };\n return 'error' in listened ? this.#refused(listened.error) : null;\n }\n\n *challenged(args ) {\n if (this.stamp.asker !== Ear.#network) return this.#notNetwork('challenged');\n const [address, nonce, identity] = [Ear.#at(args, 'address'), Ear.#at(args, 'nonce'), Ear.#at(args, 'identity')];\n const held = yield { placeholder: 'brain', method: 'lines', args: {} };\n if ('error' in held) return this.#refused(held.error);\n const line = Array.isArray(held.result)\n ? held.result.find((one) => Ear.#at(one, 'address') === address)\n : undefined;\n const wards = Ear.#at(line, 'wards');\n if (!Array.isArray(wards) || wards.length === 0) return { proofs: [] };\n const proofs = Ear.#at(yield* this.#key('prove', { wards, nonce, identity }), 'proofs');\n if (!Array.isArray(proofs)) return this.error('refused', 'key proves no ward of the line');\n return { proofs: wards.map((ward, at) => ({ ward: Ear.#at(ward, 'name'), proof: proofs[at] ?? null })) };\n }\n\n *line(args ) {\n if (this.stamp.asker !== Ear.#network) return this.#notNetwork('line');\n const wards = Ear.#at(args, 'wards');\n const up = Ear.#at(args, 'up');\n if (!Array.isArray(wards) || typeof up !== 'boolean') return this.error('refused', 'line takes wards and up');\n const told = yield {\n placeholder: 'brain',\n method: 'line',\n args: { wards, up },\n };\n return 'error' in told ? this.#refused(told.error) : null;\n }\n}";
4150
4150
 
4151
4151
  var EAR_SOURCE = facultySource(EAR_TEXT);
4152
4152
 
4153
4153
  var MOUTH_BLUEPRINT = {
4154
4154
  name: "nervur.mouth",
4155
- version: "0.37.11",
4155
+ version: "0.37.12",
4156
4156
  description: "The mouth: it seals the asks of the relations this organism holds as the standing, and opens their replies; the brain keeps every standing.",
4157
4157
  methods: {
4158
4158
  accept: {
@@ -4310,7 +4310,7 @@ var MOUTH_BLUEPRINT = {
4310
4310
  placeholders: { brain: "nervur.brain", network: "nervur.network", key: "nervur.key" }
4311
4311
  };
4312
4312
 
4313
- var MOUTH_TEXT = "class Mouth extends Faculty {\n static #text = { type: 'string', minLength: 1 };\n static #named = { type: 'string', pattern: '^[0-9a-f]{2432}$' };\n static #bytes = { type: 'string', contentEncoding: 'base16' };\n\n static blueprint = {\n name: 'nervur.mouth',\n version: '0.37.11',\n description:\n 'The mouth: it seals the asks of the relations this organism holds as the standing, and opens their replies; the brain keeps every standing.',\n methods: {\n accept: {\n description:\n \"The organism accepts an invitation, at the ask of the asker, never the asker: the brain makes a far organism for its relation, keeps the standing as the organism's, and grants it to the asker by wiring the asker's placeholder to it, one wire each; an owner grants it to other lobes by `grant`. Its text is read past every ASCII whitespace, so one a mail wrapped or a hand spaced reads as it was written. The spans the invitation carries go to the brain, so the standing lapses here by this side's clock: unknocked past `waits`, bound past `lives`; and its anchor's mark, so it ends only once the far brain answered its owner's `drop`. With `note`, free data of at most 4 KiB as its canonical text by default and never a secret, what the organism holds, from whom and what for: the brain keeps it beside the standing as its own, null where none is named, and it never travels to the inviter; the asker's own note on it starts empty and is written through its `nerves`. With `node`, asked by the brain alone for an owner from afar, the standing is granted to that lobe rather than to the asker.\",\n kind: 'reading',\n args: {\n type: 'object',\n properties: { invitation: Mouth.#text, placeholder: Mouth.#text, note: {}, node: Mouth.#text },\n required: ['invitation', 'placeholder'],\n additionalProperties: false,\n },\n result: {\n type: 'object',\n properties: { far: Mouth.#text },\n required: ['far'],\n additionalProperties: false,\n },\n errors: ['refused'],\n },\n carry: {\n askers: ['brain'],\n description:\n \"The brain's alone: seals an ask on a standing, has the brain keep before its box goes what it needs kept, the bound its number lies below or the standing whole with its knock or probe, sends it to the first address that takes it, the same box again after the brain's pause where a door replied nothing, and answers what the asker hears, the standing moved, the being's newest addresses, and `answered` where the being's object came back, so the brain marks a standing fallen silent bound again.\",\n kind: 'reading',\n args: {\n type: 'object',\n properties: {\n far: Mouth.#text,\n standing: { type: 'object' },\n at: { anyOf: [{ type: 'array', items: Mouth.#text }, { type: 'null' }] },\n method: { anyOf: [Mouth.#text, { type: 'null' }] },\n args: {},\n timeout: { type: 'number', minimum: 0 },\n room: { type: 'integer', minimum: 1 },\n },\n required: ['far', 'standing', 'at', 'method', 'args', 'timeout', 'room'],\n additionalProperties: false,\n },\n result: {\n type: 'object',\n properties: {\n heard: {},\n standing: { type: 'object' },\n at: { anyOf: [{ type: 'array', items: Mouth.#text }, { type: 'null' }] },\n answered: { const: true },\n },\n required: ['heard', 'standing', 'at'],\n additionalProperties: false,\n },\n errors: ['refused'],\n },\n cede: {\n askers: ['brain'],\n description:\n \"The brain's alone: has `key` seal a standing whole, its numbers as the brain hands them, with what the brain keeps `beside` it, to `to`, the public half of a key another organism's `taking` drew, and answers `{handed}`, which no lobe reads; refused where `to` is no named key.\",\n kind: 'reading',\n args: {\n type: 'object',\n properties: { standing: { type: 'object' }, beside: { type: 'object' }, to: Mouth.#named },\n required: ['standing', 'beside', 'to'],\n additionalProperties: false,\n },\n result: { type: 'object' },\n errors: ['refused'],\n },\n drop: {\n irreversible: true,\n description:\n \"The asker gives up the standing of a far organism it is granted, accepted through the mouth: its wire and its note go and it is asked `left`; where it was the last lobe wired, the brain sends the inviting side one last letter, `#leave`, then forgets the standing whatever answers, with its notes, and asks each other lobe that was wired `left`. One its invitation marked an anchor's the brain first asks the far brain its owner's `drop`, and forgets only once it answered or had ended it; refused, with the far brain's why or as unheard, it is kept.\",\n kind: 'reading',\n args: {\n type: 'object',\n properties: { far: Mouth.#text },\n required: ['far'],\n additionalProperties: false,\n },\n result: { type: 'null' },\n errors: ['refused'],\n },\n once: {\n description:\n \"Asks once with no relation: the ask goes on the zero head of the card's ward, at the first of its addresses that takes it, and the asker hears what the being answered. No far organism is made.\",\n kind: 'reading',\n args: {\n type: 'object',\n properties: {\n card: {\n type: 'object',\n properties: {\n ward: { type: 'string', pattern: '^[0-9a-f]{128}$' },\n at: { type: 'array', items: Mouth.#text },\n },\n required: ['ward', 'at'],\n additionalProperties: false,\n },\n method: Mouth.#text,\n args: { type: 'object' },\n },\n required: ['card'],\n additionalProperties: false,\n },\n errors: ['refused'],\n },\n take: {\n askers: ['brain'],\n description:\n \"The brain's alone: has `key` open a standing `cede` handed by the key `taking` drew, the secret it sealed named in `taking`, and seal it again under this organism's record key, and answers `{standing, beside}`; refused where it is not sealed to that key.\",\n kind: 'reading',\n args: {\n type: 'object',\n properties: {\n taking: {\n type: 'object',\n properties: { key: Mouth.#named, sealed: Mouth.#bytes },\n required: ['key', 'sealed'],\n additionalProperties: false,\n },\n handed: Mouth.#bytes,\n },\n required: ['taking', 'handed'],\n additionalProperties: false,\n },\n result: { type: 'object' },\n errors: ['refused'],\n },\n taking: {\n askers: ['brain'],\n description:\n \"The brain's alone: has `key` draw a key a standing is handed to, and answers `{key, sealed}`, its public half and its secret sealed, which only that `key` opens.\",\n kind: 'reading',\n args: { type: 'object', properties: {}, additionalProperties: false },\n result: { type: 'object' },\n errors: ['refused'],\n },\n vouch: {\n askers: ['brain'],\n description:\n \"The brain's alone: reads a domain's vouch, `https://<domain>/.well-known/quo`, through `network`, and answers its body as bytes, or null where it answered no 200 or nothing at all.\",\n kind: 'reading',\n args: {\n type: 'object',\n properties: { domain: Mouth.#text },\n required: ['domain'],\n additionalProperties: false,\n },\n result: { anyOf: [{ type: 'object' }, { type: 'null' }] },\n errors: ['refused'],\n },\n },\n placeholders: { brain: 'nervur.brain', network: 'nervur.network', key: 'nervur.key' },\n };\n\n static #ward = /^[0-9a-f]{128}$/;\n static #code = /^(?=.{1,64}$)[a-z0-9]+(-[a-z0-9]+)*$/;\n static #blank = /[\\t\\n\\f\\r]/gu;\n static #unreached = 'unreached';\n static #in = '#in';\n static #whole = '#whole';\n static #out = '#out';\n\n static #at(data , key ) {\n return Mouth.field(data, key) ?? null;\n }\n\n static #spans(given ) \n \n \n \n {\n let parsed = null;\n try {\n const outer = JSON.parse(given);\n const text = typeof outer === 'object' && outer !== null ? Reflect.get(outer, 'text') : null;\n parsed = typeof text === 'string' ? JSON.parse(text) : null;\n } catch {\n parsed = null;\n }\n const span = (key ) => {\n const value = typeof parsed === 'object' && parsed !== null ? Reflect.get(parsed, key) : null;\n return typeof value === 'number' && Number.isInteger(value) && value >= 0 ? value : null;\n };\n const marked = typeof parsed === 'object' && parsed !== null ? Reflect.get(parsed, 'anchor') : null;\n return { waits: span('waits'), lives: span('lives'), anchor: marked === true };\n }\n\n static #failed(code , message ) {\n return { error: { code, message } };\n }\n\n *#key(method , args ) {\n const answer = yield { placeholder: 'key', method, args };\n return 'result' in answer ? answer.result : { why: answer.error.message };\n }\n\n static #nervur(object ) {\n const keys = typeof object === 'object' && object !== null ? Object.keys(object) : [];\n if (keys.length !== 1) return false;\n if (keys[0] === 'result' || (keys[0] === '#pieces' && typeof Mouth.#at(object, '#pieces') === 'number'))\n return true;\n const failed = Mouth.#at(object, 'error');\n const code = Mouth.#at(failed, 'code');\n const whole = typeof failed === 'object' && failed !== null && Object.keys(failed).length === 2;\n return (\n whole && typeof code === 'string' && Mouth.#code.test(code) && typeof Mouth.#at(failed, 'message') === 'string'\n );\n }\n\n static #canonical(value ) {\n if (typeof value === 'number' && !Number.isFinite(value)) throw new TypeError('no data holds this number');\n if (Array.isArray(value)) return `[${value.map((one) => Mouth.#canonical(one)).join(',')}]`;\n if (typeof value !== 'object' || value === null) return JSON.stringify(value);\n const fields = Object.entries(value).toSorted(([one], [other]) => (one < other ? -1 : 1));\n return `{${fields.map(([key, one]) => `${JSON.stringify(key)}:${Mouth.#canonical(one)}`).join(',')}}`;\n }\n\n #read(object ) {\n const read = this.codec.read(object);\n if ('data' in read) return read;\n try {\n return this.codec.read(Mouth.#canonical(JSON.parse(object)));\n } catch {\n return read;\n }\n }\n\n #heard(read ) {\n const object = Mouth.#at(read, 'object');\n if (typeof object === 'string') {\n const answer = this.#read(object);\n if (!('data' in answer)) return Mouth.#failed('unavailable', `the being answered no data: ${answer.why}`);\n return Mouth.#nervur(answer.data) ? answer.data : { result: answer.data };\n }\n if (Mouth.#at(read, 'silence') === true) return Mouth.#failed('silent', 'the being said nothing');\n const word = Mouth.#at(read, 'quo');\n if (word === 'removed' || word === 'repeated') return Mouth.#failed(word, `the being's door said ${word}`);\n if (typeof word === 'string') return Mouth.#failed('unavailable', `the being's door said ${word}`);\n return Mouth.#failed('unavailable', 'no reply came, so the ask may have run');\n }\n\n *#sent(ward , addresses , box , timeout , landed ) {\n let carried = false;\n for (const [at, address] of addresses.entries()) {\n const sent = yield {\n placeholder: 'network',\n method: 'send',\n args: { address, ward, bytes: box },\n timeout,\n };\n const reply = 'result' in sent ? Mouth.#at(sent.result, 'reply') : null;\n if (reply !== null) {\n if (landed !== undefined) landed.at = at;\n return reply;\n }\n if ('error' in sent && sent.error.code === 'timeout') return 'timeout';\n carried ||= 'result' in sent;\n }\n return carried ? null : Mouth.#unreached;\n }\n\n *#kept(far , knock ) {\n const kept = yield {\n placeholder: 'brain',\n method: 'keep',\n args: { far, standing: knock },\n };\n return 'error' in kept ? kept.error.message : null;\n }\n\n *#lapsed(standing , pending ) {\n const lapsed = yield* this.#key('lapsed', { standing, pending });\n return typeof Mouth.#at(lapsed, 'why') === 'string' ? standing : lapsed;\n }\n\n *#past(\n first ,\n on ,\n ) {\n const silent = (read ) => Mouth.#at(Mouth.#at(read, 'read'), 'silence') === true;\n for (let rest = on.addresses; silent(first) && rest.length > 0; rest = rest.slice(1)) {\n const reply = yield* this.#sent(on.ward, rest.slice(0, 1), on.box, on.timeout);\n if (reply === null || reply === Mouth.#unreached || reply === 'timeout') continue;\n const read = yield* this.#key('read', { standing: on.moved, pending: on.pending, reply });\n if (typeof Mouth.#at(read, 'why') !== 'string' && !silent(read)) return read;\n }\n return first;\n }\n\n *#box(far , standing , newest , ask , timeout ) {\n const sealed = yield* this.#key('seal', { standing, ask });\n const why = Mouth.#at(sealed, 'why');\n if (typeof why === 'string') return { heard: Mouth.#failed('refused', why), standing, at: newest };\n const moved = Mouth.#at(sealed, 'standing');\n const pending = Mouth.#at(sealed, 'pending');\n const knock = Mouth.#at(pending, 'kind') === 'knock';\n const again = knock && Mouth.#at(standing, 'phase') === 'uncertain';\n const unkept = !again ? yield* this.#kept(far, moved) : null;\n if (unkept !== null) return { heard: Mouth.#failed('unavailable', unkept), standing, at: newest };\n const invitation = Mouth.#at(moved, 'invitation');\n const offered = Array.isArray(newest) ? newest : Mouth.#at(invitation, 'at');\n const addresses = Array.isArray(offered) ? offered : [];\n const ward = Mouth.#at(invitation, 'ward');\n const box = Mouth.#at(sealed, 'box');\n const landed = { at: 0 };\n let sent = yield* this.#sent(ward, addresses, box, timeout, landed);\n for (let tries = 0; sent === null; tries += 1) {\n const paused = yield { placeholder: 'brain', method: 'pause', args: { far, tries } };\n if ('error' in paused) return { heard: { error: paused.error }, standing: moved, at: newest };\n const left = Mouth.#at(paused.result, 'left');\n if (typeof left !== 'number' || left <= 0) break;\n sent = yield* this.#sent(ward, addresses, box, left, landed);\n }\n const reply = sent === Mouth.#unreached ? null : sent;\n if (reply === 'timeout')\n return {\n heard: Mouth.#failed('timeout', 'no reply came within the timeout'),\n standing: yield* this.#lapsed(moved, pending),\n at: newest,\n };\n const first = yield* this.#key('read', { standing: moved, pending, reply });\n const read = yield* this.#past(first, {\n ward,\n addresses: addresses.slice(landed.at + 1),\n box,\n timeout,\n moved,\n pending,\n });\n const unread = Mouth.#at(read, 'why');\n if (typeof unread === 'string') return { heard: Mouth.#failed('unavailable', unread), standing: moved, at: newest };\n const heard = Mouth.#at(read, 'read');\n const at = Mouth.#at(heard, 'at');\n const kept = Array.isArray(at) && at.length > 0 ? at : newest;\n return { read: heard, standing: Mouth.#at(read, 'standing'), at: kept, again };\n }\n\n #answered(heard ) {\n const failed = Mouth.#at(heard, 'error');\n const code = Mouth.#at(failed, 'code');\n const message = Mouth.#at(failed, 'message');\n if (typeof code === 'string') return this.error(code, typeof message === 'string' ? message : code);\n const plain = typeof heard === 'object' && heard !== null && Object.hasOwn(heard, 'result');\n return plain ? Mouth.#at(heard, 'result') : this.error('unavailable', 'the being answered no answer');\n }\n\n *once(args ) {\n const card = Mouth.#at(args, 'card');\n const ward = Mouth.#at(card, 'ward');\n const at = Mouth.#at(card, 'at');\n const method = Mouth.#at(args, 'method');\n const addresses = Array.isArray(at) ? at.filter((one) => typeof one === 'string') : null;\n if (\n typeof ward !== 'string' ||\n !Mouth.#ward.test(ward) ||\n addresses?.length !== (Array.isArray(at) ? at.length : -1)\n )\n return this.error('refused', 'once takes a card: a ward and its addresses');\n if (method !== null && typeof method !== 'string') return this.error('refused', 'the method of an ask is text');\n const given = method === null ? {} : (Mouth.#at(args, 'args') ?? {});\n const ask = { ...(method === null ? {} : { method }), args: this.codec.text(given) };\n const zero = yield* this.#key('askZero', { ward, ask });\n const why = Mouth.#at(zero, 'why');\n if (typeof why === 'string') return this.error('refused', why);\n const sent = yield* this.#sent(ward, addresses, Mouth.#at(zero, 'box'));\n const reply = sent === Mouth.#unreached ? null : sent;\n if (reply === 'timeout') return this.error('timeout', 'no reply came within the timeout');\n const pending = Mouth.#at(zero, 'pending');\n const read = yield* this.#key('readZero', { ward, pending, reply });\n const unread = Mouth.#at(read, 'why');\n if (typeof unread === 'string') return this.error('unavailable', unread);\n return this.#answered(this.#heard(read));\n }\n\n *accept(args ) {\n const given = Mouth.#at(args, 'invitation');\n const placeholder = Mouth.#at(args, 'placeholder');\n if (typeof given !== 'string' || typeof placeholder !== 'string')\n return this.error('refused', 'accept takes an invitation and a placeholder');\n const text = given.replace(Mouth.#blank, '');\n const named = Mouth.#at(args, 'node');\n if (named !== null && this.stamp.asker !== 'brain') return this.error('refused', \"node is the brain's alone\");\n const node = this.stamp.asker === 'brain' ? named : this.stamp.asker;\n if (typeof node !== 'string') return this.error('refused', 'the brain names the lobe it accepts for');\n const standing = yield* this.#key('standingOn', { invitation: text });\n const unsealed = Mouth.#at(standing, 'why');\n if (typeof unsealed === 'string') return this.error('refused', unsealed);\n const note = Mouth.#at(args, 'note');\n const { waits, lives, anchor } = Mouth.#spans(text);\n const stood = yield {\n placeholder: 'brain',\n method: 'stand',\n args: { node, placeholder, standing, note, waits, lives, anchor },\n };\n if ('error' in stood) return this.error('refused', stood.error.message);\n return { far: Mouth.#at(stood.result, 'far') };\n }\n\n *vouch(args ) {\n const domain = Mouth.#at(args, 'domain');\n if (typeof domain !== 'string') return this.error('refused', 'vouch takes a domain');\n const request = { method: 'GET', url: `https://${domain}/.well-known/quo`, headers: {}, body: new Uint8Array(0) };\n const sent = yield { placeholder: 'network', method: 'send', args: request };\n if ('error' in sent || Mouth.#at(sent.result, 'status') !== 200) return null;\n return { body: Mouth.#at(sent.result, 'body') };\n }\n\n *#handed(method , args ) {\n const answer = yield { placeholder: 'key', method, args };\n return 'result' in answer ? answer.result : this.error('refused', answer.error.message);\n }\n\n *taking() {\n return yield* this.#handed('taking', {});\n }\n\n *cede(args ) {\n return yield* this.#handed('cede', args);\n }\n\n *take(args ) {\n return yield* this.#handed('take', args);\n }\n\n *drop(args ) {\n const far = Mouth.#at(args, 'far');\n if (typeof far !== 'string') return this.error('refused', 'drop takes a far organism');\n const left = yield {\n placeholder: 'brain',\n method: 'leave',\n args: { node: this.stamp.asker, far },\n };\n return 'error' in left ? this.error('refused', left.error.message) : null;\n }\n\n *carry(args ) {\n const far = Mouth.#at(args, 'far');\n const method = Mouth.#at(args, 'method');\n const timeout = Mouth.#at(args, 'timeout');\n const room = Mouth.#at(args, 'room');\n if (typeof far !== 'string' || typeof timeout !== 'number' || typeof room !== 'number')\n return this.error('refused', 'carry takes a far organism, a timeout and the room of a box');\n const given = method === null ? {} : Mouth.#at(args, 'args');\n const ask = { ...(typeof method === 'string' ? { method } : {}), args: this.codec.text(given) };\n let sent = { standing: Mouth.#at(args, 'standing'), at: Mouth.#at(args, 'at') };\n if (typeof method !== 'string' || this.#cost(ask.args) <= room)\n sent = yield* this.#asked(far, Mouth.#at(sent, 'standing'), Mouth.#at(sent, 'at'), ask, timeout);\n else {\n for (let at = 0, from = 0; from < ask.args.length; at += 1) {\n const end = this.#end(ask.args, from, room);\n sent = yield* this.#next(far, sent, Mouth.#in, { at, part: ask.args.slice(from, end) }, timeout);\n if (Mouth.#broken(sent) && !Mouth.#repeated(sent)) return sent;\n from = end;\n }\n sent = yield* this.#next(far, sent, Mouth.#whole, { method, units: ask.args.length }, timeout);\n if (Mouth.#repeated(sent)) {\n const told = yield* this.#next(far, sent, Mouth.#out, {}, timeout);\n const length = Mouth.#at(Mouth.#at(told, 'heard'), 'result');\n sent = Mouth.#hearing(told, typeof length === 'number' ? { '#pieces': length } : Mouth.#at(sent, 'heard'));\n }\n }\n const units = Mouth.#at(Mouth.#at(sent, 'heard'), '#pieces');\n if (typeof units !== 'number' || Mouth.#broken(sent)) return sent;\n const parts = [];\n for (let from = 0; from < units;) {\n sent = yield* this.#next(far, sent, Mouth.#out, { from }, timeout);\n if (Mouth.#repeated(sent)) continue;\n const part = Mouth.#at(Mouth.#at(sent, 'heard'), 'result');\n if (Mouth.#broken(sent)) return sent;\n if (typeof part !== 'string' || part === '')\n return Mouth.#hearing(sent, Mouth.#failed('unavailable', 'a piece of the answer is no text'));\n parts.push(part);\n from += part.length;\n }\n const whole = parts.join('');\n const read = this.codec.read(whole);\n const heard =\n whole.length === units && 'data' in read\n ? read.data\n : Mouth.#failed('unavailable', 'the answer came back in pieces that make no whole');\n return Mouth.#hearing(sent, heard);\n }\n\n #cost(text ) {\n const bytes = this.codec.utf8(this.codec.text(text));\n if ('why' in bytes) throw new TypeError(bytes.why);\n return bytes.bytes.length - 2;\n }\n\n #end(text , from , room ) {\n let units = Math.min(text.length - from, room);\n for (;;) {\n let end = from + units;\n const last = text.charCodeAt(end - 1);\n if (end < text.length && last >= 0xd800 && last < 0xdc00) end += end - 1 > from ? -1 : 1;\n const cost = this.#cost(text.slice(from, end));\n if (cost <= room || units === 1) return end;\n units = Math.max(1, Math.floor(((end - from) * room) / cost));\n }\n }\n\n static #hearing(sent , heard ) {\n return { heard, standing: Mouth.#at(sent, 'standing'), at: Mouth.#at(sent, 'at'), answered: true };\n }\n\n *#next(far , before , method , args , timeout ) {\n const ask = { method, args: this.codec.text(args) };\n return yield* this.#asked(far, Mouth.#at(before, 'standing'), Mouth.#at(before, 'at'), ask, timeout);\n }\n\n static #broken(sent ) {\n return Mouth.#at(Mouth.#at(sent, 'heard'), 'error') !== null;\n }\n\n static #repeated(sent ) {\n return Mouth.#at(Mouth.#at(Mouth.#at(sent, 'heard'), 'error'), 'code') === 'repeated';\n }\n\n *#asked(far , standing , newest , ask , timeout ) {\n const first = yield* this.#box(far, standing, newest, ask, timeout);\n const read = Mouth.#at(first, 'read');\n const resolved = Mouth.#at(first, 'again') === true && Mouth.#at(read, 'nothing') !== true;\n const moved = Mouth.#at(first, 'standing');\n const last = resolved ? yield* this.#box(far, moved, Mouth.#at(first, 'at'), ask, timeout) : first;\n const heard = Mouth.#at(last, 'heard') ?? this.#heard(Mouth.#at(last, 'read'));\n const answered = typeof Mouth.#at(Mouth.#at(last, 'read'), 'object') === 'string' ? { answered: true } : {};\n return { heard, standing: Mouth.#at(last, 'standing'), at: Mouth.#at(last, 'at'), ...answered };\n }\n}";
4313
+ var MOUTH_TEXT = "class Mouth extends Faculty {\n static #text = { type: 'string', minLength: 1 };\n static #named = { type: 'string', pattern: '^[0-9a-f]{2432}$' };\n static #bytes = { type: 'string', contentEncoding: 'base16' };\n\n static blueprint = {\n name: 'nervur.mouth',\n version: '0.37.12',\n description:\n 'The mouth: it seals the asks of the relations this organism holds as the standing, and opens their replies; the brain keeps every standing.',\n methods: {\n accept: {\n description:\n \"The organism accepts an invitation, at the ask of the asker, never the asker: the brain makes a far organism for its relation, keeps the standing as the organism's, and grants it to the asker by wiring the asker's placeholder to it, one wire each; an owner grants it to other lobes by `grant`. Its text is read past every ASCII whitespace, so one a mail wrapped or a hand spaced reads as it was written. The spans the invitation carries go to the brain, so the standing lapses here by this side's clock: unknocked past `waits`, bound past `lives`; and its anchor's mark, so it ends only once the far brain answered its owner's `drop`. With `note`, free data of at most 4 KiB as its canonical text by default and never a secret, what the organism holds, from whom and what for: the brain keeps it beside the standing as its own, null where none is named, and it never travels to the inviter; the asker's own note on it starts empty and is written through its `nerves`. With `node`, asked by the brain alone for an owner from afar, the standing is granted to that lobe rather than to the asker.\",\n kind: 'reading',\n args: {\n type: 'object',\n properties: { invitation: Mouth.#text, placeholder: Mouth.#text, note: {}, node: Mouth.#text },\n required: ['invitation', 'placeholder'],\n additionalProperties: false,\n },\n result: {\n type: 'object',\n properties: { far: Mouth.#text },\n required: ['far'],\n additionalProperties: false,\n },\n errors: ['refused'],\n },\n carry: {\n askers: ['brain'],\n description:\n \"The brain's alone: seals an ask on a standing, has the brain keep before its box goes what it needs kept, the bound its number lies below or the standing whole with its knock or probe, sends it to the first address that takes it, the same box again after the brain's pause where a door replied nothing, and answers what the asker hears, the standing moved, the being's newest addresses, and `answered` where the being's object came back, so the brain marks a standing fallen silent bound again.\",\n kind: 'reading',\n args: {\n type: 'object',\n properties: {\n far: Mouth.#text,\n standing: { type: 'object' },\n at: { anyOf: [{ type: 'array', items: Mouth.#text }, { type: 'null' }] },\n method: { anyOf: [Mouth.#text, { type: 'null' }] },\n args: {},\n timeout: { type: 'number', minimum: 0 },\n room: { type: 'integer', minimum: 1 },\n },\n required: ['far', 'standing', 'at', 'method', 'args', 'timeout', 'room'],\n additionalProperties: false,\n },\n result: {\n type: 'object',\n properties: {\n heard: {},\n standing: { type: 'object' },\n at: { anyOf: [{ type: 'array', items: Mouth.#text }, { type: 'null' }] },\n answered: { const: true },\n },\n required: ['heard', 'standing', 'at'],\n additionalProperties: false,\n },\n errors: ['refused'],\n },\n cede: {\n askers: ['brain'],\n description:\n \"The brain's alone: has `key` seal a standing whole, its numbers as the brain hands them, with what the brain keeps `beside` it, to `to`, the public half of a key another organism's `taking` drew, and answers `{handed}`, which no lobe reads; refused where `to` is no named key.\",\n kind: 'reading',\n args: {\n type: 'object',\n properties: { standing: { type: 'object' }, beside: { type: 'object' }, to: Mouth.#named },\n required: ['standing', 'beside', 'to'],\n additionalProperties: false,\n },\n result: { type: 'object' },\n errors: ['refused'],\n },\n drop: {\n irreversible: true,\n description:\n \"The asker gives up the standing of a far organism it is granted, accepted through the mouth: its wire and its note go and it is asked `left`; where it was the last lobe wired, the brain sends the inviting side one last letter, `#leave`, then forgets the standing whatever answers, with its notes, and asks each other lobe that was wired `left`. One its invitation marked an anchor's the brain first asks the far brain its owner's `drop`, and forgets only once it answered or had ended it; refused, with the far brain's why or as unheard, it is kept.\",\n kind: 'reading',\n args: {\n type: 'object',\n properties: { far: Mouth.#text },\n required: ['far'],\n additionalProperties: false,\n },\n result: { type: 'null' },\n errors: ['refused'],\n },\n once: {\n description:\n \"Asks once with no relation: the ask goes on the zero head of the card's ward, at the first of its addresses that takes it, and the asker hears what the being answered. No far organism is made.\",\n kind: 'reading',\n args: {\n type: 'object',\n properties: {\n card: {\n type: 'object',\n properties: {\n ward: { type: 'string', pattern: '^[0-9a-f]{128}$' },\n at: { type: 'array', items: Mouth.#text },\n },\n required: ['ward', 'at'],\n additionalProperties: false,\n },\n method: Mouth.#text,\n args: { type: 'object' },\n },\n required: ['card'],\n additionalProperties: false,\n },\n errors: ['refused'],\n },\n take: {\n askers: ['brain'],\n description:\n \"The brain's alone: has `key` open a standing `cede` handed by the key `taking` drew, the secret it sealed named in `taking`, and seal it again under this organism's record key, and answers `{standing, beside}`; refused where it is not sealed to that key.\",\n kind: 'reading',\n args: {\n type: 'object',\n properties: {\n taking: {\n type: 'object',\n properties: { key: Mouth.#named, sealed: Mouth.#bytes },\n required: ['key', 'sealed'],\n additionalProperties: false,\n },\n handed: Mouth.#bytes,\n },\n required: ['taking', 'handed'],\n additionalProperties: false,\n },\n result: { type: 'object' },\n errors: ['refused'],\n },\n taking: {\n askers: ['brain'],\n description:\n \"The brain's alone: has `key` draw a key a standing is handed to, and answers `{key, sealed}`, its public half and its secret sealed, which only that `key` opens.\",\n kind: 'reading',\n args: { type: 'object', properties: {}, additionalProperties: false },\n result: { type: 'object' },\n errors: ['refused'],\n },\n vouch: {\n askers: ['brain'],\n description:\n \"The brain's alone: reads a domain's vouch, `https://<domain>/.well-known/quo`, through `network`, and answers its body as bytes, or null where it answered no 200 or nothing at all.\",\n kind: 'reading',\n args: {\n type: 'object',\n properties: { domain: Mouth.#text },\n required: ['domain'],\n additionalProperties: false,\n },\n result: { anyOf: [{ type: 'object' }, { type: 'null' }] },\n errors: ['refused'],\n },\n },\n placeholders: { brain: 'nervur.brain', network: 'nervur.network', key: 'nervur.key' },\n };\n\n static #ward = /^[0-9a-f]{128}$/;\n static #code = /^(?=.{1,64}$)[a-z0-9]+(-[a-z0-9]+)*$/;\n static #blank = /[\\t\\n\\f\\r]/gu;\n static #unreached = 'unreached';\n static #in = '#in';\n static #whole = '#whole';\n static #out = '#out';\n\n static #at(data , key ) {\n return Mouth.field(data, key) ?? null;\n }\n\n static #spans(given ) \n \n \n \n {\n let parsed = null;\n try {\n const outer = JSON.parse(given);\n const text = typeof outer === 'object' && outer !== null ? Reflect.get(outer, 'text') : null;\n parsed = typeof text === 'string' ? JSON.parse(text) : null;\n } catch {\n parsed = null;\n }\n const span = (key ) => {\n const value = typeof parsed === 'object' && parsed !== null ? Reflect.get(parsed, key) : null;\n return typeof value === 'number' && Number.isInteger(value) && value >= 0 ? value : null;\n };\n const marked = typeof parsed === 'object' && parsed !== null ? Reflect.get(parsed, 'anchor') : null;\n return { waits: span('waits'), lives: span('lives'), anchor: marked === true };\n }\n\n static #failed(code , message ) {\n return { error: { code, message } };\n }\n\n *#key(method , args ) {\n const answer = yield { placeholder: 'key', method, args };\n return 'result' in answer ? answer.result : { why: answer.error.message };\n }\n\n static #nervur(object ) {\n const keys = typeof object === 'object' && object !== null ? Object.keys(object) : [];\n if (keys.length !== 1) return false;\n if (keys[0] === 'result' || (keys[0] === '#pieces' && typeof Mouth.#at(object, '#pieces') === 'number'))\n return true;\n const failed = Mouth.#at(object, 'error');\n const code = Mouth.#at(failed, 'code');\n const whole = typeof failed === 'object' && failed !== null && Object.keys(failed).length === 2;\n return (\n whole && typeof code === 'string' && Mouth.#code.test(code) && typeof Mouth.#at(failed, 'message') === 'string'\n );\n }\n\n static #canonical(value ) {\n if (typeof value === 'number' && !Number.isFinite(value)) throw new TypeError('no data holds this number');\n if (Array.isArray(value)) return `[${value.map((one) => Mouth.#canonical(one)).join(',')}]`;\n if (typeof value !== 'object' || value === null) return JSON.stringify(value);\n const fields = Object.entries(value).toSorted(([one], [other]) => (one < other ? -1 : 1));\n return `{${fields.map(([key, one]) => `${JSON.stringify(key)}:${Mouth.#canonical(one)}`).join(',')}}`;\n }\n\n #read(object ) {\n const read = this.codec.read(object);\n if ('data' in read) return read;\n try {\n return this.codec.read(Mouth.#canonical(JSON.parse(object)));\n } catch {\n return read;\n }\n }\n\n #heard(read ) {\n const object = Mouth.#at(read, 'object');\n if (typeof object === 'string') {\n const answer = this.#read(object);\n if (!('data' in answer)) return Mouth.#failed('unavailable', `the being answered no data: ${answer.why}`);\n return Mouth.#nervur(answer.data) ? answer.data : { result: answer.data };\n }\n if (Mouth.#at(read, 'silence') === true) return Mouth.#failed('silent', 'the being said nothing');\n const word = Mouth.#at(read, 'quo');\n if (word === 'removed' || word === 'repeated') return Mouth.#failed(word, `the being's door said ${word}`);\n if (typeof word === 'string') return Mouth.#failed('unavailable', `the being's door said ${word}`);\n return Mouth.#failed('unavailable', 'no reply came, so the ask may have run');\n }\n\n *#sent(ward , addresses , box , timeout , landed ) {\n let carried = false;\n for (const [at, address] of addresses.entries()) {\n const sent = yield {\n placeholder: 'network',\n method: 'send',\n args: { address, ward, bytes: box },\n timeout,\n };\n const reply = 'result' in sent ? Mouth.#at(sent.result, 'reply') : null;\n if (reply !== null) {\n if (landed !== undefined) landed.at = at;\n return reply;\n }\n if ('error' in sent && sent.error.code === 'timeout') return 'timeout';\n carried ||= 'result' in sent;\n }\n return carried ? null : Mouth.#unreached;\n }\n\n *#kept(far , knock ) {\n const kept = yield {\n placeholder: 'brain',\n method: 'keep',\n args: { far, standing: knock },\n };\n return 'error' in kept ? kept.error.message : null;\n }\n\n *#lapsed(standing , pending ) {\n const lapsed = yield* this.#key('lapsed', { standing, pending });\n return typeof Mouth.#at(lapsed, 'why') === 'string' ? standing : lapsed;\n }\n\n *#past(\n first ,\n on ,\n ) {\n const silent = (read ) => Mouth.#at(Mouth.#at(read, 'read'), 'silence') === true;\n for (let rest = on.addresses; silent(first) && rest.length > 0; rest = rest.slice(1)) {\n const reply = yield* this.#sent(on.ward, rest.slice(0, 1), on.box, on.timeout);\n if (reply === null || reply === Mouth.#unreached || reply === 'timeout') continue;\n const read = yield* this.#key('read', { standing: on.moved, pending: on.pending, reply });\n if (typeof Mouth.#at(read, 'why') !== 'string' && !silent(read)) return read;\n }\n return first;\n }\n\n *#box(far , standing , newest , ask , timeout ) {\n const sealed = yield* this.#key('seal', { standing, ask });\n const why = Mouth.#at(sealed, 'why');\n if (typeof why === 'string') return { heard: Mouth.#failed('refused', why), standing, at: newest };\n const moved = Mouth.#at(sealed, 'standing');\n const pending = Mouth.#at(sealed, 'pending');\n const knock = Mouth.#at(pending, 'kind') === 'knock';\n const again = knock && Mouth.#at(standing, 'phase') === 'uncertain';\n const unkept = !again ? yield* this.#kept(far, moved) : null;\n if (unkept !== null) return { heard: Mouth.#failed('unavailable', unkept), standing, at: newest };\n const invitation = Mouth.#at(moved, 'invitation');\n const offered = Array.isArray(newest) ? newest : Mouth.#at(invitation, 'at');\n const addresses = Array.isArray(offered) ? offered : [];\n const ward = Mouth.#at(invitation, 'ward');\n const box = Mouth.#at(sealed, 'box');\n const landed = { at: 0 };\n let sent = yield* this.#sent(ward, addresses, box, timeout, landed);\n for (let tries = 0; sent === null; tries += 1) {\n const paused = yield { placeholder: 'brain', method: 'pause', args: { far, tries } };\n if ('error' in paused) return { heard: { error: paused.error }, standing: moved, at: newest };\n const left = Mouth.#at(paused.result, 'left');\n if (typeof left !== 'number' || left <= 0) break;\n sent = yield* this.#sent(ward, addresses, box, left, landed);\n }\n const reply = sent === Mouth.#unreached ? null : sent;\n if (reply === 'timeout')\n return {\n heard: Mouth.#failed('timeout', 'no reply came within the timeout'),\n standing: yield* this.#lapsed(moved, pending),\n at: newest,\n };\n const first = yield* this.#key('read', { standing: moved, pending, reply });\n const read = yield* this.#past(first, {\n ward,\n addresses: addresses.slice(landed.at + 1),\n box,\n timeout,\n moved,\n pending,\n });\n const unread = Mouth.#at(read, 'why');\n if (typeof unread === 'string') return { heard: Mouth.#failed('unavailable', unread), standing: moved, at: newest };\n const heard = Mouth.#at(read, 'read');\n const at = Mouth.#at(heard, 'at');\n const kept = Array.isArray(at) && at.length > 0 ? at : newest;\n return { read: heard, standing: Mouth.#at(read, 'standing'), at: kept, again };\n }\n\n #answered(heard ) {\n const failed = Mouth.#at(heard, 'error');\n const code = Mouth.#at(failed, 'code');\n const message = Mouth.#at(failed, 'message');\n if (typeof code === 'string') return this.error(code, typeof message === 'string' ? message : code);\n const plain = typeof heard === 'object' && heard !== null && Object.hasOwn(heard, 'result');\n return plain ? Mouth.#at(heard, 'result') : this.error('unavailable', 'the being answered no answer');\n }\n\n *once(args ) {\n const card = Mouth.#at(args, 'card');\n const ward = Mouth.#at(card, 'ward');\n const at = Mouth.#at(card, 'at');\n const method = Mouth.#at(args, 'method');\n const addresses = Array.isArray(at) ? at.filter((one) => typeof one === 'string') : null;\n if (\n typeof ward !== 'string' ||\n !Mouth.#ward.test(ward) ||\n addresses?.length !== (Array.isArray(at) ? at.length : -1)\n )\n return this.error('refused', 'once takes a card: a ward and its addresses');\n if (method !== null && typeof method !== 'string') return this.error('refused', 'the method of an ask is text');\n const given = method === null ? {} : (Mouth.#at(args, 'args') ?? {});\n const ask = { ...(method === null ? {} : { method }), args: this.codec.text(given) };\n const zero = yield* this.#key('askZero', { ward, ask });\n const why = Mouth.#at(zero, 'why');\n if (typeof why === 'string') return this.error('refused', why);\n const sent = yield* this.#sent(ward, addresses, Mouth.#at(zero, 'box'));\n const reply = sent === Mouth.#unreached ? null : sent;\n if (reply === 'timeout') return this.error('timeout', 'no reply came within the timeout');\n const pending = Mouth.#at(zero, 'pending');\n const read = yield* this.#key('readZero', { ward, pending, reply });\n const unread = Mouth.#at(read, 'why');\n if (typeof unread === 'string') return this.error('unavailable', unread);\n return this.#answered(this.#heard(read));\n }\n\n *accept(args ) {\n const given = Mouth.#at(args, 'invitation');\n const placeholder = Mouth.#at(args, 'placeholder');\n if (typeof given !== 'string' || typeof placeholder !== 'string')\n return this.error('refused', 'accept takes an invitation and a placeholder');\n const text = given.replace(Mouth.#blank, '');\n const named = Mouth.#at(args, 'node');\n if (named !== null && this.stamp.asker !== 'brain') return this.error('refused', \"node is the brain's alone\");\n const node = this.stamp.asker === 'brain' ? named : this.stamp.asker;\n if (typeof node !== 'string') return this.error('refused', 'the brain names the lobe it accepts for');\n const standing = yield* this.#key('standingOn', { invitation: text });\n const unsealed = Mouth.#at(standing, 'why');\n if (typeof unsealed === 'string') return this.error('refused', unsealed);\n const note = Mouth.#at(args, 'note');\n const { waits, lives, anchor } = Mouth.#spans(text);\n const stood = yield {\n placeholder: 'brain',\n method: 'stand',\n args: { node, placeholder, standing, note, waits, lives, anchor },\n };\n if ('error' in stood) return this.error('refused', stood.error.message);\n return { far: Mouth.#at(stood.result, 'far') };\n }\n\n *vouch(args ) {\n const domain = Mouth.#at(args, 'domain');\n if (typeof domain !== 'string') return this.error('refused', 'vouch takes a domain');\n const request = { method: 'GET', url: `https://${domain}/.well-known/quo`, headers: {}, body: new Uint8Array(0) };\n const sent = yield { placeholder: 'network', method: 'send', args: request };\n if ('error' in sent || Mouth.#at(sent.result, 'status') !== 200) return null;\n return { body: Mouth.#at(sent.result, 'body') };\n }\n\n *#handed(method , args ) {\n const answer = yield { placeholder: 'key', method, args };\n return 'result' in answer ? answer.result : this.error('refused', answer.error.message);\n }\n\n *taking() {\n return yield* this.#handed('taking', {});\n }\n\n *cede(args ) {\n return yield* this.#handed('cede', args);\n }\n\n *take(args ) {\n return yield* this.#handed('take', args);\n }\n\n *drop(args ) {\n const far = Mouth.#at(args, 'far');\n if (typeof far !== 'string') return this.error('refused', 'drop takes a far organism');\n const left = yield {\n placeholder: 'brain',\n method: 'leave',\n args: { node: this.stamp.asker, far },\n };\n return 'error' in left ? this.error('refused', left.error.message) : null;\n }\n\n *carry(args ) {\n const far = Mouth.#at(args, 'far');\n const method = Mouth.#at(args, 'method');\n const timeout = Mouth.#at(args, 'timeout');\n const room = Mouth.#at(args, 'room');\n if (typeof far !== 'string' || typeof timeout !== 'number' || typeof room !== 'number')\n return this.error('refused', 'carry takes a far organism, a timeout and the room of a box');\n const given = method === null ? {} : Mouth.#at(args, 'args');\n const ask = { ...(typeof method === 'string' ? { method } : {}), args: this.codec.text(given) };\n let sent = { standing: Mouth.#at(args, 'standing'), at: Mouth.#at(args, 'at') };\n if (typeof method !== 'string' || this.#cost(ask.args) <= room)\n sent = yield* this.#asked(far, Mouth.#at(sent, 'standing'), Mouth.#at(sent, 'at'), ask, timeout);\n else {\n for (let at = 0, from = 0; from < ask.args.length; at += 1) {\n const end = this.#end(ask.args, from, room);\n sent = yield* this.#next(far, sent, Mouth.#in, { at, part: ask.args.slice(from, end) }, timeout);\n if (Mouth.#broken(sent) && !Mouth.#repeated(sent)) return sent;\n from = end;\n }\n sent = yield* this.#next(far, sent, Mouth.#whole, { method, units: ask.args.length }, timeout);\n if (Mouth.#repeated(sent)) {\n const told = yield* this.#next(far, sent, Mouth.#out, {}, timeout);\n const length = Mouth.#at(Mouth.#at(told, 'heard'), 'result');\n sent = Mouth.#hearing(told, typeof length === 'number' ? { '#pieces': length } : Mouth.#at(sent, 'heard'));\n }\n }\n const units = Mouth.#at(Mouth.#at(sent, 'heard'), '#pieces');\n if (typeof units !== 'number' || Mouth.#broken(sent)) return sent;\n const parts = [];\n for (let from = 0; from < units;) {\n sent = yield* this.#next(far, sent, Mouth.#out, { from }, timeout);\n if (Mouth.#repeated(sent)) continue;\n const part = Mouth.#at(Mouth.#at(sent, 'heard'), 'result');\n if (Mouth.#broken(sent)) return sent;\n if (typeof part !== 'string' || part === '')\n return Mouth.#hearing(sent, Mouth.#failed('unavailable', 'a piece of the answer is no text'));\n parts.push(part);\n from += part.length;\n }\n const whole = parts.join('');\n const read = this.codec.read(whole);\n const heard =\n whole.length === units && 'data' in read\n ? read.data\n : Mouth.#failed('unavailable', 'the answer came back in pieces that make no whole');\n return Mouth.#hearing(sent, heard);\n }\n\n #cost(text ) {\n const bytes = this.codec.utf8(this.codec.text(text));\n if ('why' in bytes) throw new TypeError(bytes.why);\n return bytes.bytes.length - 2;\n }\n\n #end(text , from , room ) {\n let units = Math.min(text.length - from, room);\n for (;;) {\n let end = from + units;\n const last = text.charCodeAt(end - 1);\n if (end < text.length && last >= 0xd800 && last < 0xdc00) end += end - 1 > from ? -1 : 1;\n const cost = this.#cost(text.slice(from, end));\n if (cost <= room || units === 1) return end;\n units = Math.max(1, Math.floor(((end - from) * room) / cost));\n }\n }\n\n static #hearing(sent , heard ) {\n return { heard, standing: Mouth.#at(sent, 'standing'), at: Mouth.#at(sent, 'at'), answered: true };\n }\n\n *#next(far , before , method , args , timeout ) {\n const ask = { method, args: this.codec.text(args) };\n return yield* this.#asked(far, Mouth.#at(before, 'standing'), Mouth.#at(before, 'at'), ask, timeout);\n }\n\n static #broken(sent ) {\n return Mouth.#at(Mouth.#at(sent, 'heard'), 'error') !== null;\n }\n\n static #repeated(sent ) {\n return Mouth.#at(Mouth.#at(Mouth.#at(sent, 'heard'), 'error'), 'code') === 'repeated';\n }\n\n *#asked(far , standing , newest , ask , timeout ) {\n const first = yield* this.#box(far, standing, newest, ask, timeout);\n const read = Mouth.#at(first, 'read');\n const resolved = Mouth.#at(first, 'again') === true && Mouth.#at(read, 'nothing') !== true;\n const moved = Mouth.#at(first, 'standing');\n const last = resolved ? yield* this.#box(far, moved, Mouth.#at(first, 'at'), ask, timeout) : first;\n const heard = Mouth.#at(last, 'heard') ?? this.#heard(Mouth.#at(last, 'read'));\n const answered = typeof Mouth.#at(Mouth.#at(last, 'read'), 'object') === 'string' ? { answered: true } : {};\n return { heard, standing: Mouth.#at(last, 'standing'), at: Mouth.#at(last, 'at'), ...answered };\n }\n}";
4314
4314
 
4315
4315
  var MOUTH_SOURCE = facultySource(MOUTH_TEXT);
4316
4316
 
@@ -5627,7 +5627,7 @@ var Library = class _Library extends Faculty {
5627
5627
 
5628
5628
  var LIBRARY_BLUEPRINT = {
5629
5629
  name: "nervur.library",
5630
- version: "0.37.11",
5630
+ version: "0.37.12",
5631
5631
  description: "The library: it keeps the organism's faculties with their assets, and its organs, as data, each version by its digest, and the versions its sources told it.",
5632
5632
  methods: {
5633
5633
  add: {
@@ -5884,13 +5884,13 @@ var LIBRARY_BLUEPRINT = {
5884
5884
  placeholders: { brain: "nervur.brain", mouth: "nervur.mouth", ear: "nervur.ear" }
5885
5885
  };
5886
5886
 
5887
- var LIBRARY_TEXT = "class Library extends Faculty {\n static #digest = { type: 'string', pattern: '^[0-9a-f]{64}$' };\n\n static #road = { type: 'string', minLength: 1, maxLength: 256 };\n\n static #assets = {\n type: 'array',\n items: { type: 'array', items: { type: 'string', minLength: 1 }, minItems: 2, maxItems: 2 },\n };\n\n static #faculty = {\n type: 'object',\n properties: {\n source: { type: 'string', minLength: 1 },\n digest: Library.#digest,\n blueprint: { type: 'object' },\n road: Library.#road,\n label: { type: 'string', minLength: 1, maxLength: 64 },\n assets: Library.#assets,\n },\n required: ['source', 'digest', 'blueprint', 'road'],\n additionalProperties: false,\n };\n\n static #organ = {\n type: 'object',\n properties: {\n id: { type: 'string', minLength: 1, maxLength: 64 },\n digest: Library.#digest,\n graph: { type: 'string', minLength: 1 },\n blueprint: { type: 'object' },\n reach: {},\n half: { anyOf: [Library.#digest, { type: 'null' }] },\n road: Library.#road,\n },\n required: ['id', 'digest', 'graph', 'blueprint', 'half', 'road'],\n additionalProperties: false,\n };\n\n static #asset = {\n type: 'object',\n properties: { digest: Library.#digest, bytes: { type: 'string', contentEncoding: 'base16' } },\n required: ['digest', 'bytes'],\n additionalProperties: false,\n };\n\n static #lobe = { type: 'string', pattern: '^[A-Z][A-Z0-9]*$', maxLength: 64 };\n\n static #given = {\n type: 'object',\n properties: {\n kind: { const: 'faculty' },\n given: {\n type: 'object',\n properties: {\n place: Library.#lobe,\n digest: Library.#digest,\n items: { type: 'array', items: { type: 'object' }, maxItems: 1001 },\n },\n required: ['place', 'digest', 'items'],\n additionalProperties: false,\n },\n },\n required: ['kind', 'given'],\n additionalProperties: false,\n };\n\n static #hand = {\n type: 'object',\n properties: {\n source: { type: 'string', minLength: 1 },\n assets: { type: 'array', items: { type: 'object' } },\n second: { type: 'boolean' },\n },\n required: ['source'],\n additionalProperties: false,\n };\n\n static #version = {\n type: 'string',\n pattern: '^(0|[1-9][0-9]*)\\\\.(0|[1-9][0-9]*)\\\\.(0|[1-9][0-9]*)$',\n };\n\n static #named = {\n type: 'string',\n pattern: '^[a-z][a-z0-9]*([.-][a-z0-9]+)*$',\n maxLength: 64,\n };\n\n static #half = {\n type: 'object',\n properties: {\n form: { enum: ['component', 'native'] },\n code: {\n anyOf: [\n { type: 'string', minLength: 1 },\n { type: 'string', contentEncoding: 'base16' },\n ],\n },\n },\n required: ['form', 'code'],\n additionalProperties: false,\n };\n\n static blueprint = {\n name: 'nervur.library',\n version: '0.37.11',\n description:\n \"The library: it keeps the organism's faculties with their assets, and its organs, as data, each version by its digest, and the versions its sources told it.\",\n methods: {\n add: {\n description:\n \"On an owner's ask through the brain alone. From a source, `road`, any lobe of the organism's own whose describe names `get` and `told`: a faculty by its label or an organ by its ID, at a version, read from it over a wire the library orders, its digest checked and its blueprint's version, and kept under the road `<lobe>@<version>`, with that lobe kept as a source of the owners' own where its `state` answers a name, once; a faculty whose blueprint names `assets` has each asset read whole by its path and checked against its SHA-256, and their canonical digest against the blueprint's, or none of it is kept. From a far source, `road`, the library holds a standing on: a faculty or an organ at a version it told, read over the standing, each digest checked against what it told, an organ by its graph.json alone, never its host half, a faculty's assets as from near. Or by an owner's hand, `source`: a faculty's text carried in the ask, with its `assets` where it has any, kept under the road `hand@<version>` by the same walls. Or a host half's form and code under the digest of its code. A code the library keeps already, added from another road, takes that road, all else as it stands; boot's laying changes no road. Answers the digest; refuses a code whose blueprint's name and version the library keeps under another digest, but with `second`, an owner's word on a faculty, which takes it as a name of its own, kept by its source.\",\n kind: 'writing',\n args: {\n anyOf: [\n {\n type: 'object',\n properties: {\n road: Library.#lobe,\n kind: { const: 'faculty' },\n label: Library.#named,\n version: Library.#version,\n second: { type: 'boolean' },\n },\n required: ['road', 'kind', 'label', 'version'],\n additionalProperties: false,\n },\n {\n type: 'object',\n properties: {\n road: Library.#lobe,\n kind: { const: 'organ' },\n id: Library.#named,\n version: Library.#version,\n },\n required: ['road', 'kind', 'id', 'version'],\n additionalProperties: false,\n },\n Library.#given,\n Library.#hand,\n ],\n },\n result: {\n type: 'object',\n properties: { digest: Library.#digest },\n required: ['digest'],\n additionalProperties: false,\n },\n errors: ['refused'],\n },\n accept: {\n description:\n \"On an owner's ask through the brain alone: accepts a far source's invitation to a library's standing through the mouth, holding the relation itself on a placeholder of its own. It asks the far lobe at once what it told, `told`, and again at an add of a version not told it yet, since an organism that cannot be dialed can be told nothing. One that can names `tells`: since a relation runs one way, it draws through the ear a standing back on itself for the far lobe, the one before for that far lobe ended, and hands it as `told { tells }`, over which the far lobe tells each version it tells after, `changed`. With `note`, the owner's, which the brain keeps beside the standing, null where none is named. Answers the far organism the brain made up for it, the road an add names it by.\",\n kind: 'writing',\n args: {\n type: 'object',\n properties: { invitation: { type: 'string', minLength: 1 }, note: {}, tells: { const: true } },\n required: ['invitation'],\n additionalProperties: false,\n },\n result: {\n type: 'object',\n properties: { far: Library.#lobe },\n required: ['far'],\n additionalProperties: false,\n },\n errors: ['refused'],\n },\n changed: {\n description:\n \"A source's word that its `main` holds a faculty or an organ at a version it never told: a near one's over its wire, a far one's over the occupant the library's `accept` gave it, by an ask; kept for the owners to see, by `list` with `told`, never added.\",\n kind: 'writing',\n args: {\n type: 'object',\n properties: {\n kind: { enum: ['faculty', 'organ'] },\n label: Library.#named,\n version: Library.#version,\n digest: Library.#digest,\n },\n required: ['kind', 'label', 'version', 'digest'],\n additionalProperties: false,\n },\n errors: ['refused'],\n },\n remove: {\n irreversible: true,\n description:\n \"Deletes a version no lobe stands on with its assets no other kept faculty names, an organ's record, or a host half's code no organ names, on the brain's ask alone.\",\n kind: 'writing',\n args: Library.#byDigest(),\n errors: ['refused', 'used'],\n },\n spare: {\n description:\n \"On an owner's ask through the brain alone: keeps a version the library holds from the sweep, or, with `spared: false`, gives it back. An owner may still remove it.\",\n kind: 'writing',\n args: {\n type: 'object',\n properties: { digest: Library.#digest, spared: { type: 'boolean' } },\n required: ['digest'],\n additionalProperties: false,\n },\n errors: ['refused'],\n },\n evidence: {\n description:\n \"The asset that carries a kept faculty's evidence, `evidence.json`, by its SHA-256, which `get` answers, or null where it carries none; refused to a far asker.\",\n kind: 'reading',\n args: {\n type: 'object',\n properties: { faculty: Library.#digest },\n required: ['faculty'],\n additionalProperties: false,\n },\n result: {\n type: 'object',\n properties: { evidence: { anyOf: [Library.#digest, { type: 'null' }] } },\n required: ['evidence'],\n additionalProperties: false,\n },\n errors: ['refused'],\n },\n get: {\n description:\n \"The version of a digest with its assets, an organ's record, an asset's bytes, or a host half's form and code, or null; refused to a far asker.\",\n kind: 'reading',\n args: {\n type: 'object',\n properties: { digest: Library.#digest },\n required: ['digest'],\n additionalProperties: false,\n },\n result: {\n anyOf: [Library.#faculty, Library.#organ, Library.#asset, Library.#half, { type: 'null' }],\n },\n errors: ['refused'],\n },\n old: {\n description:\n \"The old versions the library keeps, on the brain's ask alone: of each name, a faculty's or an organ's blueprint name, every version but the newest by semver; the brain removes each no lobe stands on.\",\n kind: 'reading',\n args: { type: 'object', additionalProperties: false },\n result: { type: 'object', properties: { digests: { type: 'array', items: { type: 'string' } } } },\n },\n list: {\n description:\n \"The versions kept, by their blueprint's name, each with its road, an organ's marked, one an owner spared marked `spared`, a faculty a source or an owner's hand brought with no evidence marked `unproven`, a page at a time; with `told`, the versions the sources told, each with whether the library keeps it; refused to a far asker.\",\n kind: 'reading',\n args: {\n type: 'object',\n properties: {\n cursor: { anyOf: [{ type: 'string' }, { type: 'null' }] },\n limit: { type: 'integer', minimum: 1 },\n told: { type: 'boolean' },\n },\n additionalProperties: false,\n },\n result: {\n anyOf: [\n {\n type: 'object',\n properties: {\n faculties: { type: 'array', items: { type: 'object' } },\n cursor: { anyOf: [{ type: 'string' }, { type: 'null' }] },\n },\n required: ['faculties', 'cursor'],\n additionalProperties: false,\n },\n {\n type: 'object',\n properties: {\n told: { type: 'array', items: { type: 'object' } },\n cursor: { anyOf: [{ type: 'string' }, { type: 'null' }] },\n },\n required: ['told', 'cursor'],\n additionalProperties: false,\n },\n ],\n },\n errors: ['refused'],\n },\n },\n placeholders: { brain: 'nervur.brain', mouth: 'nervur.mouth', ear: 'nervur.ear' },\n };\n\n static #owner = 'brain';\n\n static #contract = ['get', 'told'];\n\n static #evidence = 'evidence.json';\n\n static #handRoad = 'hand';\n\n static #versionText = /^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)$/;\n static #namedText = /^[a-z][a-z0-9]*(?:[.-][a-z0-9]+)*$/;\n static #lobeText = /^[A-Z][A-Z0-9]*$/;\n\n static #sent(value ) {\n if (value === undefined) return 'nothing';\n const read = JSON.stringify(value);\n return read.length > 64 ? `${read.slice(0, 63)}\u2026` : read;\n }\n\n #page() {\n return Math.min(1000, Math.floor(this.memory / 4 / 1024));\n }\n\n static #byDigest() {\n return {\n type: 'object',\n properties: { digest: Library.#digest },\n required: ['digest'],\n additionalProperties: false,\n };\n }\n\n static #digestIn(args ) {\n const digest = Library.field(args, 'digest');\n return typeof digest === 'string' && /^[0-9a-f]{64}$/.test(digest) ? digest : undefined;\n }\n\n static #utf8(text ) {\n const bytes = [];\n for (const char of text) {\n const point = char.codePointAt(0) ?? 0;\n if (point < 0x80) bytes.push(point);\n else if (point < 0x800) bytes.push(0xc0 | (point >> 6), 0x80 | (point & 0x3f));\n else if (point < 0x10000) bytes.push(0xe0 | (point >> 12), 0x80 | ((point >> 6) & 0x3f), 0x80 | (point & 0x3f));\n else\n bytes.push(\n 0xf0 | (point >> 18),\n 0x80 | ((point >> 12) & 0x3f),\n 0x80 | ((point >> 6) & 0x3f),\n 0x80 | (point & 0x3f),\n );\n }\n return new Uint8Array(bytes);\n }\n\n static digestOf(crypto , code ) {\n return Library.hex(crypto.sha256(typeof code === 'string' ? Library.#utf8(code) : code));\n }\n\n static assetsDigest(\n crypto ,\n assets ,\n ) {\n const sorted = assets.toSorted((one, other) => (one[0] < other[0] ? -1 : 1));\n return Library.digestOf(crypto, JSON.stringify(sorted));\n }\n\n static keep(\n cells ,\n digest ,\n kept ,\n bytes = new Map(),\n ) {\n if (!('source' in kept)) {\n if (cells.get(['half', digest]) === undefined) cells.set(['half', digest], { form: kept.form, code: kept.code });\n return null;\n }\n const { source, blueprint, road, label, assets, second } = kept;\n const name = Library.field(blueprint, 'name');\n if (typeof name !== 'string') throw new TypeError('a version kept is one whose blueprint is named');\n if (cells.get(['faculty', digest]) !== undefined) return null;\n const named = Library.field(blueprint, 'assets') !== undefined;\n if (named !== (assets !== undefined))\n return named\n ? `the blueprint of ${name} names assets the faculty carries not`\n : `${name} carries assets its blueprint names not`;\n for (const [, sha] of assets ?? [])\n if (!bytes.has(sha) && cells.get(['asset', sha]) === undefined)\n return `${name} has no bytes for its asset ${sha}`;\n const indexed = Library.#indexed(cells, name, Library.field(blueprint, 'version'), digest, second);\n if (typeof indexed === 'string') return indexed;\n for (const [, sha] of assets ?? []) {\n const held = bytes.get(sha);\n if (held !== undefined && cells.get(['asset', sha]) === undefined) cells.set(['asset', sha], held);\n }\n cells.set(['faculty', digest], {\n source,\n digest,\n blueprint,\n road,\n ...(label === undefined ? {} : { label }),\n ...(assets === undefined ? {} : { assets: assets.map(([path, sha]) => [path, sha]) }),\n ...(indexed.second === undefined ? {} : { second: indexed.second }),\n });\n cells.set(['name', name, digest], label ?? null);\n return null;\n }\n\n static #indexed(\n cells ,\n name ,\n version ,\n digest ,\n second ,\n ) {\n if (typeof version !== 'string') return `the blueprint of ${name} names no version`;\n const named = cells.get(['version', name, version]);\n if (typeof named !== 'string' || named === digest) {\n cells.set(['version', name, version], digest);\n return {};\n }\n if (second === undefined) return `the library keeps ${name} ${version} under another digest, ${named}`;\n const own = cells.get(['second', name, version, second]);\n if (typeof own === 'string' && own !== digest)\n return `the library keeps ${name} ${version} of ${second} under another digest, ${own}`;\n cells.set(['second', name, version, second], digest);\n return { second };\n }\n\n *add(args ) {\n if (this.stamp.asker !== Library.#owner)\n return this.error('refused', \"the library adds on an owner's ask through the brain alone\");\n if (Library.field(args, 'given') !== undefined) return yield* this.#addGiven(args);\n if (Library.field(args, 'source') !== undefined) return yield* this.#addHand(args);\n return yield* this.#addFrom(args);\n }\n\n *#read(source ) {\n const answered = yield { read: source };\n const read = 'result' in answered ? answered.result : undefined;\n const blueprint = Library.field(read, 'blueprint');\n if (blueprint !== undefined && typeof Library.field(blueprint, 'name') === 'string') return blueprint;\n const why = Library.field(read, 'why');\n return `the source is no faculty: ${typeof why === 'string' ? why : 'it declares no blueprint'}`;\n }\n\n static #fromArgs(\n args ,\n ) {\n const kind = Library.field(args, 'kind');\n const key = kind === 'organ' ? 'id' : 'label';\n const [road, named, version] = ['road', key, 'version'].map((one) => Library.field(args, one));\n const keys = typeof args === 'object' && args !== null ? Object.keys(args).length : 0;\n const second = Library.field(args, 'second');\n if ((kind !== 'faculty' && kind !== 'organ') || keys !== (second === undefined ? 4 : 5))\n return 'add takes a road, a kind, a faculty or an organ, its label or ID, and a version';\n if (second !== undefined && ((second !== true && second !== false) || kind !== 'faculty'))\n return `\\`second\\` is an owner's word on a faculty, true or false, not ${Library.#sent(second)}`;\n if (typeof road !== 'string' || road.length > 64 || !Library.#lobeText.test(road))\n return `a road is a lobe of this organism, by the ID the brain made up for it, not ${Library.#sent(road)}`;\n if (typeof named !== 'string' || named.length > 64 || !Library.#namedText.test(named))\n return `a ${key} is a folder's name, lowercase, not ${Library.#sent(named)}`;\n if (typeof version !== 'string' || !Library.#versionText.test(version))\n return `a version is three whole numbers joined by dots, not ${Library.#sent(version)}`;\n return { road, kind, named, version, second: second === true };\n }\n\n *#addFrom(args ) {\n const asked = Library.#fromArgs(args);\n if (typeof asked === 'string') return this.error('refused', asked);\n if (this.cells.get(['far', asked.road]) !== undefined) return yield* this.#addFar(asked);\n const { road, kind, named, version, second } = asked;\n const unreached = yield* this.#reach(road);\n if (unreached !== null) return this.error('refused', unreached);\n const got = yield {\n placeholder: road,\n method: 'get',\n args: { kind, label: named, version },\n };\n if ('error' in got)\n return this.error('refused', `the source ${road} answers ${got.error.code}: ${got.error.message}`);\n const from = `${road}@${version}`;\n const taken =\n kind === 'organ'\n ? this.#takeOrgan(got.result, named, version, from)\n : yield* this.#takeFaculty(got.result, from, {\n lobe: road,\n label: named,\n version,\n ...(second ? { second: road } : {}),\n });\n if (Library.#added(taken)) yield* this.#kindOf(road);\n return taken;\n }\n\n static #added(taken ) {\n return typeof taken === 'object' && taken !== null && 'digest' in taken;\n }\n\n *#kindOf(lobe ) {\n if (this.cells.get(['source', lobe]) !== undefined) return;\n const state = yield {\n placeholder: lobe,\n method: 'state',\n args: {},\n };\n const name = 'result' in state ? Library.field(state.result, 'name') : undefined;\n if (typeof name === 'string' && name !== '') this.cells.set(['source', lobe], 'owners');\n }\n\n *#reach(lobe ) {\n const order = { termination: lobe };\n const ordered = yield {\n placeholder: 'nerves',\n method: 'order',\n args: { order },\n };\n if ('error' in ordered) return `the library reaches no ${lobe}: ${ordered.error.message}`;\n const described = yield {\n placeholder: lobe,\n method: null,\n args: null,\n };\n const methods = 'result' in described ? Library.field(described.result, 'methods') : undefined;\n const lacking = Library.#contract.filter((method) => Library.field(methods, method) === undefined);\n if (lacking.length === 0) return null;\n yield {\n placeholder: 'nerves',\n method: 'unwire',\n args: { placeholder: lobe },\n };\n return `${lobe} is no source: its describe names no ${lacking.join(' and no ')}`;\n }\n\n *#takeFaculty(answered , road , at ) {\n const { label, version } = at;\n const source = Library.field(answered, 'source');\n const told = Library.field(answered, 'digest');\n if (typeof source !== 'string' || source === '') return this.error('refused', 'the source answered no source');\n const digest = Library.digestOf(this.crypto, source);\n if (told !== digest)\n return this.error('refused', `the source the source answered is not its digest, ${JSON.stringify(told ?? null)}`);\n if (this.cells.get(['faculty', digest]) !== undefined) return this.#reroad(digest, road, version);\n const blueprint = yield* this.#read(source);\n if (typeof blueprint === 'string') return this.error('refused', blueprint);\n const named = Library.field(blueprint, 'version');\n if (named !== version)\n return this.error('refused', `the faculty names version ${JSON.stringify(named ?? null)}, not ${version}`);\n const carried = yield* this.#assetsTaken(answered, blueprint, at);\n if (typeof carried === 'string') return this.error('refused', carried);\n const refused = Library.keep(\n this.cells,\n digest,\n { source, blueprint, road, label, ...carried.kept, ...(at.second === undefined ? {} : { second: at.second }) },\n carried.bytes,\n );\n return refused === null ? { digest } : this.error('refused', refused);\n }\n\n #reroad(digest , road , version ) {\n const kept = this.cells.get(['faculty', digest]);\n const named = Library.field(Library.field(kept, 'blueprint'), 'version');\n if (named !== version)\n return this.error('refused', `the faculty names version ${JSON.stringify(named ?? null)}, not ${version}`);\n if (Library.field(kept, 'road') === road) return { digest };\n const record = {};\n for (const field of ['source', 'digest', 'blueprint', 'label', 'assets', 'second']) {\n const value = Library.field(kept, field);\n if (value !== undefined) record[field] = value;\n }\n this.cells.set(['faculty', digest], { ...record, road });\n return { digest };\n }\n\n *#assetsTaken(\n answered ,\n blueprint ,\n at ,\n ) \n \n \n \n {\n const bytes = new Map ();\n const named = Library.field(blueprint, 'assets');\n const told = Library.field(answered, 'assets');\n if (named === undefined)\n return told === undefined ? { kept: {}, bytes } : 'the source answered assets the blueprint names not';\n const assets = this.#assetsOf(told);\n if (assets === null) return 'the source answered no assets whole: each a path and a SHA-256, one path once';\n if (Library.assetsDigest(this.crypto, assets) !== named)\n return `the assets are not the digest the blueprint names, ${JSON.stringify(named)}`;\n for (const [path, sha] of assets) {\n if (bytes.has(sha) || this.cells.get(['asset', sha]) !== undefined) continue;\n const got = yield {\n placeholder: at.lobe,\n method: 'get',\n args: { kind: 'faculty', label: at.label, version: at.version, path },\n };\n if ('error' in got)\n return `the source ${at.lobe} answers ${got.error.code} for the asset ${path}: ${got.error.message}`;\n const [given, digest, held] = ['path', 'digest', 'bytes'].map((one) => Library.field(got.result, one));\n if (given !== path || digest !== sha || !(held instanceof Uint8Array))\n return `the source answered another asset than ${path}`;\n if (Library.digestOf(this.crypto, held) !== sha) return `the asset ${path} is not its digest, ${sha}`;\n bytes.set(sha, held);\n }\n return { kept: { assets }, bytes };\n }\n\n static #json(text ) {\n try {\n const read = JSON.parse(text);\n return typeof read === 'object' && read !== null && !Array.isArray(read) ? read : null;\n } catch {\n return null;\n }\n }\n\n #takeOrgan(answered , id , version , road ) {\n const graph = Library.field(answered, 'blueprint');\n const half = Library.field(answered, 'half') ?? null;\n if (typeof graph !== 'string') return this.error('refused', \"the source answered no organ's graph.json\");\n if (half !== null && (typeof half !== 'string' || !/^[0-9a-f]{64}$/.test(half)))\n return this.error('refused', 'the source answered a built half that is no digest');\n const read = Library.#json(graph);\n const inner = Library.field(read, 'blueprint');\n const blueprint = inner !== undefined && Library.#json(JSON.stringify(inner)) !== null ? inner : read;\n const name = Library.field(blueprint, 'name');\n const named = Library.field(blueprint, 'version');\n if (blueprint === null || blueprint === undefined || typeof name !== 'string')\n return this.error('refused', 'its graph.json holds no blueprint, named');\n if (named !== version)\n return this.error('refused', `the organ names version ${JSON.stringify(named ?? null)}, not ${version}`);\n const digest = Library.digestOf(this.crypto, graph);\n const kept = this.#organAt(digest);\n if (kept !== undefined) {\n if (half !== null || kept['road'] !== road)\n this.cells.set(['organ', digest], { ...kept, ...(half === null ? {} : { half }), road });\n return { digest };\n }\n const clash = Library.#indexed(this.cells, name, named, digest, undefined);\n if (typeof clash === 'string') return this.error('refused', clash);\n const reach = inner === undefined ? undefined : Library.field(read, 'reach');\n this.cells.set(['organ', digest], {\n id,\n digest,\n graph,\n blueprint,\n ...(reach === undefined ? {} : { reach }),\n half,\n road,\n });\n this.cells.set(['name', name, digest], id);\n return { digest };\n }\n\n #assetsOf(data ) {\n if (!Array.isArray(data) || data.length > this.#page()) return null;\n const assets = [];\n for (const one of data) {\n const [path, sha] = Array.isArray(one) && one.length === 2 ? one : [];\n if (typeof path !== 'string' || path === '') return null;\n if (typeof sha !== 'string' || !/^[0-9a-f]{64}$/.test(sha)) return null;\n assets.push([path, sha]);\n }\n const sorted = assets.toSorted((one, other) => (one[0] < other[0] ? -1 : 1));\n return sorted.every((one, at) => sorted[at - 1]?.[0] !== one[0]) ? sorted : null;\n }\n\n #assetsNamed() {\n const named = new Set ();\n let cursor = null;\n do {\n const page = this.cells.range({\n prefix: ['faculty'],\n limit: this.#page(),\n ...(cursor === null ? {} : { cursor }),\n });\n for (const { value } of page.cells)\n for (const [, sha] of this.#assetsOf(Library.field(value, 'assets')) ?? []) named.add(sha);\n cursor = page.cursor;\n } while (cursor !== null);\n return named;\n }\n\n *accept(args ) {\n if (this.stamp.asker !== Library.#owner)\n return this.error('refused', \"the library accepts a standing on an owner's ask through the brain alone\");\n const invitation = Library.field(args, 'invitation');\n const note = Library.field(args, 'note');\n const keys = typeof args === 'object' && args !== null ? Object.keys(args).length : 0;\n const tells = Library.field(args, 'tells');\n const named = 1 + (note === undefined ? 0 : 1) + (tells === undefined ? 0 : 1);\n if (typeof invitation !== 'string' || invitation === '' || keys !== named || (tells ?? true) !== true)\n return this.error(\n 'refused',\n 'accept takes an invitation, a note where one is named, and `tells` where it can be told',\n );\n const held = this.cells.get(['standings']);\n const count = typeof held === 'number' ? held + 1 : 1;\n this.cells.set(['standings'], count);\n const placeholder = `far-${count}`;\n const accepted = yield* this.#accepted({ invitation, placeholder, note: note ?? null });\n if ('error' in accepted) return this.error('refused', `the mouth accepts no standing: ${accepted.error.message}`);\n const far = Library.field(accepted.result, 'far');\n if (typeof far !== 'string' || !Library.#lobeText.test(far))\n return this.error('refused', 'the mouth named no far organism');\n this.cells.set(['far', far], { placeholder });\n this.cells.set(['source', far], 'far');\n yield* this.#untold(far);\n if (tells === true) yield* this.#tellsBack(far, placeholder);\n else yield* this.#asksTold(far, placeholder);\n return { far };\n }\n\n *#accepted(args ) {\n const answer = yield { placeholder: 'mouth', method: 'accept', args };\n return answer;\n }\n\n *#tellsBack(far , placeholder ) {\n const invited = yield {\n placeholder: 'ear',\n method: 'invite',\n args: { waits: null, lives: null, note: { library: far } },\n };\n const tells = 'result' in invited ? Library.field(invited.result, 'invitation') : undefined;\n const back = 'result' in invited ? Library.field(invited.result, 'far') : undefined;\n if (typeof tells !== 'string') return;\n const asked = yield { placeholder, method: 'told', args: { tells } };\n if ('error' in asked) {\n if (typeof back === 'string') yield { placeholder: 'ear', method: 'drop', args: { far: back } };\n return;\n }\n yield* this.#readOn(far, placeholder, asked.result);\n }\n\n *#asksTold(far , placeholder ) {\n const asked = yield { placeholder, method: 'told', args: {} };\n if ('result' in asked) yield* this.#readOn(far, placeholder, asked.result);\n }\n\n *#readOn(far , placeholder , first ) {\n const seen = new Set ();\n let page = first;\n for (;;) {\n this.#heardAll(far, Library.field(page, 'told') ?? null);\n const cursor = Library.field(page, 'cursor');\n if (typeof cursor !== 'string' || seen.has(cursor)) return;\n seen.add(cursor);\n const next = yield { placeholder, method: 'told', args: { cursor } };\n if (!('result' in next)) return;\n page = next.result;\n }\n }\n\n #heardAll(far , answered ) {\n for (const one of Array.isArray(answered) ? answered.slice(0, this.#page()) : []) {\n const told = Library.#toldFar(one);\n if (told !== null) this.#heard(far, told.kind, told.label, told.version, told.digest);\n }\n }\n\n *#untold(far ) {\n let cursor = null;\n const seen = new Set ();\n const given = [];\n do {\n const page = yield {\n placeholder: 'nerves',\n method: 'relations',\n args: cursor === null ? {} : { cursor },\n };\n if ('error' in page) break;\n const relations = Library.field(page.result, 'relations');\n for (const one of Array.isArray(relations) ? relations : []) {\n const back = Library.field(one, 'far');\n const mine = Library.field(Library.field(one, 'note'), 'library') === far;\n if (Library.field(one, 'side') === 'occupant' && mine && typeof back === 'string') given.push(back);\n }\n const next = Library.field(page.result, 'cursor');\n cursor = typeof next === 'string' && !seen.has(next) ? next : null;\n if (cursor !== null) seen.add(cursor);\n } while (cursor !== null);\n for (const back of given) yield { placeholder: 'ear', method: 'drop', args: { far: back } };\n }\n\n #heard(far , kind , label , version , digest ) {\n const key = ['told', far, kind, label, version];\n if (this.cells.get(key) !== undefined) return;\n const telling = this.cells.get(['telling', far]) ?? { first: 0, next: 0 };\n let first = Number(Library.field(telling, 'first'));\n const next = Number(Library.field(telling, 'next'));\n for (; next - first >= this.#page(); first += 1) {\n const oldest = this.cells.get(['telling', far, first]);\n if (Array.isArray(oldest)) this.cells.delete(oldest);\n this.cells.delete(['telling', far, first]);\n }\n this.cells.set(['telling', far, next], key);\n this.cells.set(['telling', far], { first, next: next + 1 });\n this.cells.set(key, { digest, at: this.stamp.time });\n }\n\n static #isDigest(text ) {\n return typeof text === 'string' && /^[0-9a-f]{64}$/.test(text);\n }\n\n static #toldFar(one ) {\n const [kind, label, version, digest] = ['kind', 'label', 'version', 'digest'].map((name) =>\n Library.field(one, name),\n );\n if (kind !== 'faculty' && kind !== 'organ') return null;\n if (typeof label !== 'string' || label.length > 64 || !Library.#namedText.test(label)) return null;\n if (typeof version !== 'string' || !Library.#versionText.test(version)) return null;\n return Library.#isDigest(digest) ? { kind, label, version, digest } : null;\n }\n\n *#addFar(asked \n \n \n \n \n \n ) {\n const { road, kind, named, version, second } = asked;\n const placeholder = Library.field(this.cells.get(['far', road]), 'placeholder');\n if (this.#toldRowOf(road, kind, named, version) === undefined && typeof placeholder === 'string')\n yield* this.#asksTold(road, placeholder);\n const toldAt = this.#toldAt(road, kind, named, version);\n if (typeof toldAt === 'string') return this.error('refused', toldAt);\n const got = yield {\n placeholder: toldAt.placeholder,\n method: 'get',\n args: { kind, label: named, version },\n };\n if ('error' in got)\n return this.error('refused', `the far source ${road} answers ${got.error.code}: ${got.error.message}`);\n const at = { lobe: toldAt.placeholder, label: named, version, ...(second ? { second: road } : {}) };\n return yield* this.#takeFar(got.result, toldAt.told, { road, kind, named, version }, at);\n }\n\n #toldRowOf(road , kind , named , version ) {\n return Library.#toldRow(this.cells.get(['told', road, kind, named, version]));\n }\n\n #toldAt(road , kind , named , version ) {\n const told = this.#toldRowOf(road, kind, named, version);\n const placeholder = Library.field(this.cells.get(['far', road]), 'placeholder');\n if (told === undefined || typeof placeholder !== 'string')\n return `the far source ${road} told no ${kind} ${named} ${version}`;\n return { told, placeholder };\n }\n\n *#takeFar(\n answered ,\n told ,\n at \n \n \n \n \n ,\n asked ,\n ) {\n const { road, kind, named, version } = at;\n const from = `${road}@${version}`;\n const [source, graph] = ['source', 'blueprint'].map((one) => Library.field(answered, one));\n const matches = (code , name ) =>\n typeof code === 'string' && Library.digestOf(this.crypto, code) === Library.field(told, name);\n if (kind === 'faculty')\n return matches(source, 'digest')\n ? yield* this.#takeFaculty(\n { ...Library.#only(answered, 'assets'), source, digest: Library.field(told, 'digest') ?? null },\n from,\n asked,\n )\n : this.error('refused', `the source the far source ${road} answered is not the digest it told`);\n if (!matches(graph, 'digest'))\n return this.error('refused', `the organ the far source ${road} answered is not the digests it told`);\n return this.#takeOrgan({ blueprint: graph, half: null }, named, version, from);\n }\n\n static #only(answered , name ) {\n const found = Library.field(answered, name);\n return found === undefined ? {} : { [name]: found };\n }\n\n *changed(args ) {\n const [kind, label, version, digest] = ['kind', 'label', 'version', 'digest'].map((one) =>\n Library.field(args, one),\n );\n const keys = typeof args === 'object' && args !== null ? Object.keys(args).length : 0;\n if (\n (kind !== 'faculty' && kind !== 'organ') ||\n keys !== 4 ||\n typeof label !== 'string' ||\n !Library.#namedText.test(label) ||\n typeof version !== 'string' ||\n !Library.#versionText.test(version) ||\n !Library.#isDigest(digest)\n )\n return this.error('refused', `changed takes a kind, a label, a version and a digest, not ${Library.#sent(args)}`);\n const { asker, occupant } = this.stamp;\n if (occupant !== null && occupant.far === asker) {\n const road = Library.field(occupant.note, 'library');\n if (typeof road !== 'string' || this.cells.get(['far', road]) === undefined)\n return this.error('refused', 'changed comes over an occupant the library gave a far source');\n this.#heard(road, kind, label, version, digest);\n return null;\n }\n if (!Library.#lobeText.test(asker)) return this.error('refused', \"changed is a source's word\");\n const unreached = yield* this.#reach(asker);\n if (unreached !== null) return this.error('refused', unreached);\n this.#heard(asker, kind, label, version, digest);\n return null;\n }\n\n static #unbase64(text ) {\n if (!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/u.test(text)) return null;\n const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';\n const bytes = [];\n let [word, bits] = [0, 0];\n for (const char of text.replaceAll('=', '')) {\n word = (word << 6) | alphabet.indexOf(char);\n bits += 6;\n if (bits >= 8) {\n bits -= 8;\n bytes.push((word >> bits) & 0xff);\n word &= (1 << bits) - 1;\n }\n }\n return new Uint8Array(bytes);\n }\n\n static #givenAssets(\n crypto ,\n items ,\n ) {\n let source ;\n const bytes = new Map ();\n const assets = [];\n for (const item of items) {\n const sourceText = Library.field(item, 'source');\n if (typeof sourceText === 'string') {\n if (source !== undefined) return 'a faculty given holds one source';\n source = sourceText;\n continue;\n }\n const [path, digest, text, base64] = ['path', 'digest', 'text', 'base64'].map((one) => Library.field(item, one));\n const held =\n typeof text === 'string' ? Library.#utf8(text) : typeof base64 === 'string' ? Library.#unbase64(base64) : null;\n if (typeof path !== 'string' || path === '' || typeof digest !== 'string' || held === null)\n return 'a faculty given holds an asset that is none';\n if (Library.digestOf(crypto, held) !== digest) return `the asset ${path} is not its digest, ${digest}`;\n if (assets.some(([seen]) => seen === path)) return `the asset ${path} is given twice`;\n assets.push([path, digest]);\n bytes.set(digest, held);\n }\n return source === undefined ? 'a faculty given holds its source' : { source, bytes, assets };\n }\n\n *#addGiven(args ) {\n const given = Library.field(args, 'given');\n const [place, digest, items] = ['place', 'digest', 'items'].map((one) => Library.field(given, one));\n if (typeof place !== 'string' || typeof digest !== 'string')\n return this.error('refused', 'a faculty given names its place and its digest');\n const kind = this.cells.get(['source', place]);\n if (kind !== undefined && kind !== 'far')\n return this.error('refused', `the place ${place} is a source of the owners' own, which offers no faculty`);\n if (!Array.isArray(items)) return this.error('refused', 'a faculty given holds its items');\n const taken = Library.#givenAssets(this.crypto, items);\n if (typeof taken === 'string') return this.error('refused', taken);\n const { source, bytes, assets } = taken;\n if (Library.digestOf(this.crypto, source) !== digest)\n return this.error('refused', `the faculty given is not its digest, ${digest}`);\n const blueprint = yield* this.#read(source);\n if (typeof blueprint === 'string') return this.error('refused', blueprint);\n const version = Library.field(blueprint, 'version');\n if (typeof version !== 'string' || !Library.#versionText.test(version))\n return this.error('refused', `a version is three whole numbers joined by dots, not ${Library.#sent(version)}`);\n const road = `${place}@${version}`;\n if (this.cells.get(['faculty', digest]) !== undefined) return this.#reroad(digest, road, version);\n const named = Library.field(blueprint, 'assets');\n if (!(named === undefined && assets.length === 0) && Library.assetsDigest(this.crypto, assets) !== named)\n return this.error('refused', \"the assets given are not the digest the faculty's blueprint names\");\n const sorted = assets.toSorted((one, other) => (one[0] < other[0] ? -1 : 1));\n const refused = Library.keep(\n this.cells,\n digest,\n { source, blueprint, road, ...(named === undefined ? {} : { assets: sorted }) },\n bytes,\n );\n return refused === null ? { digest } : this.error('refused', refused);\n }\n\n *#addHand(args ) {\n const [source, assets, second] = ['source', 'assets', 'second'].map((one) => Library.field(args, one));\n if (typeof source !== 'string' || source === '') return this.error('refused', \"an owner's hand carries a source\");\n if (assets !== undefined && (!Array.isArray(assets) || assets.length > this.#page()))\n return this.error(\n 'refused',\n `assets carried are a list, of as many as a faculty holds, not ${Library.#sent(assets)}`,\n );\n if (second !== undefined && typeof second !== 'boolean')\n return this.error('refused', `\\`second\\` is an owner's word, true or false, not ${Library.#sent(second)}`);\n const taken = Library.#givenAssets(this.crypto, [{ source }, ...(assets ?? [])]);\n if (typeof taken === 'string') return this.error('refused', taken);\n const blueprint = yield* this.#read(source);\n if (typeof blueprint === 'string') return this.error('refused', blueprint);\n const version = Library.field(blueprint, 'version');\n if (typeof version !== 'string' || !Library.#versionText.test(version))\n return this.error('refused', `a version is three whole numbers joined by dots, not ${Library.#sent(version)}`);\n const road = `${Library.#handRoad}@${version}`;\n const digest = Library.digestOf(this.crypto, source);\n if (this.cells.get(['faculty', digest]) !== undefined) return this.#reroad(digest, road, version);\n const named = Library.field(blueprint, 'assets');\n if (named !== undefined && Library.assetsDigest(this.crypto, taken.assets) !== named)\n return this.error('refused', \"the assets carried are not the digest the faculty's blueprint names\");\n const refused = Library.keep(\n this.cells,\n digest,\n {\n source,\n blueprint,\n road,\n ...(named === undefined && taken.assets.length === 0\n ? {}\n : { assets: taken.assets.toSorted((one, other) => (one[0] < other[0] ? -1 : 1)) }),\n ...(second === true ? { second: Library.#handRoad } : {}),\n },\n taken.bytes,\n );\n return refused === null ? { digest } : this.error('refused', refused);\n }\n\n *remove(args ) {\n if (this.stamp.asker !== 'brain')\n return this.error('unavailable', \"the library removes a faculty on the brain's ask alone\");\n const digest = Library.#digestIn(args);\n if (digest === undefined) return this.error('refused', 'remove takes a digest');\n const record = this.cells.get(['faculty', digest]) ?? this.#organAt(digest);\n const blueprint = Library.field(record, 'blueprint');\n const name = Library.field(blueprint, 'name');\n const half = this.cells.get(['half', digest]) !== undefined;\n if (typeof name !== 'string' && !half) return this.error('refused', `the library keeps nothing under ${digest}`);\n const uses = yield {\n placeholder: 'brain',\n method: 'uses',\n args: { digest },\n };\n if ('error' in uses) return this.error(uses.error.code, uses.error.message);\n if (uses.result !== false) return this.error('used', `a lobe or an organ stands on ${digest}`);\n if (typeof name !== 'string') this.cells.delete(['half', digest]);\n else {\n this.cells.delete(['faculty', digest]);\n this.cells.delete(['organ', digest]);\n const held = this.#assetsOf(Library.field(record, 'assets')) ?? [];\n const named = held.length === 0 ? new Set () : this.#assetsNamed();\n for (const [, sha] of held) if (!named.has(sha)) this.cells.delete(['asset', sha]);\n this.cells.delete(['name', name, digest]);\n this.cells.delete(['spared', digest]);\n }\n return null;\n }\n\n spare(args ) {\n if (this.stamp.asker !== Library.#owner)\n return this.error('refused', \"the library spares a version on an owner's ask through the brain alone\");\n const digest = Library.#digestIn(args);\n const spared = Library.field(args, 'spared') ?? true;\n if (digest === undefined || typeof spared !== 'boolean')\n return this.error('refused', 'spare takes a digest, and `spared` where it gives one back');\n if (!this.#keeps(digest)) return this.error('refused', `the library keeps nothing under ${digest}`);\n if (spared) this.cells.set(['spared', digest], true);\n else this.cells.delete(['spared', digest]);\n return null;\n }\n\n #keeps(digest ) {\n return this.cells.get(['faculty', digest]) !== undefined || this.cells.get(['organ', digest]) !== undefined;\n }\n\n static proven(record ) {\n const road = Library.field(record, 'road');\n const taken = typeof road === 'string' && /^(?:hand|[A-Z][A-Z0-9]*)@/u.test(road);\n const assets = Library.field(record, 'assets');\n return (\n !taken || (Array.isArray(assets) && assets.some((one) => Array.isArray(one) && one[0] === Library.#evidence))\n );\n }\n\n #evidenceOf(record ) {\n const carried = this.#assetsOf(Library.field(record, 'assets')) ?? [];\n return carried.find(([path]) => path === Library.#evidence)?.[1] ?? null;\n }\n\n evidence(args ) {\n if (this.stamp.occupant !== null) return this.error('refused', 'evidence is kept from a far asker');\n const digest = Library.field(args, 'faculty');\n const record = Library.#isDigest(digest) ? this.cells.get(['faculty', digest]) : undefined;\n if (record === undefined) return this.error('refused', 'evidence takes the digest of a faculty the library keeps');\n return { evidence: this.#evidenceOf(record) };\n }\n\n old() {\n if (this.stamp.asker !== Library.#owner)\n return this.error('unavailable', 'the library names its old versions to the brain alone');\n return { digests: this.#olderIn() };\n }\n\n #olderIn() {\n const newest = new Map ();\n const older = [];\n let cursor = null;\n do {\n const page = this.cells.range({\n prefix: ['version'],\n limit: this.#page(),\n ...(cursor === null ? {} : { cursor }),\n });\n for (const { key, value } of page.cells) {\n const at = Library.#semver(key[2]);\n if (typeof value !== 'string' || at === null || !this.#keeps(value)) continue;\n const name = String(key[1]);\n const top = newest.get(name);\n if (top === undefined) newest.set(name, { at, digest: value });\n else if (Library.#newer(at, top.at)) {\n older.push(top.digest);\n newest.set(name, { at, digest: value });\n } else older.push(value);\n }\n cursor = page.cursor;\n } while (cursor !== null);\n return older.filter((digest) => this.cells.get(['spared', digest]) === undefined);\n }\n\n static #semver(version ) {\n if (typeof version !== 'string' || !Library.#versionText.test(version)) return null;\n return version.split('.').map(Number);\n }\n\n static #newer(one , other ) {\n for (let at = 0; at < 3; at += 1) if ((one[at] ?? 0) !== (other[at] ?? 0)) return (one[at] ?? 0) > (other[at] ?? 0);\n return false;\n }\n\n get(args ) {\n if (this.stamp.occupant !== null) return this.error('refused', 'get is kept from a far asker');\n const digest = Library.#digestIn(args);\n if (digest === undefined) return this.error('refused', 'get takes a digest');\n return (\n this.cells.get(['faculty', digest]) ??\n this.#organAt(digest) ??\n this.#assetAt(digest) ??\n this.cells.get(['half', digest]) ??\n null\n );\n }\n\n #assetAt(digest ) {\n const kept = this.cells.get(['asset', digest]);\n return kept instanceof Uint8Array ? { digest, bytes: kept } : undefined;\n }\n\n list(args ) {\n if (this.stamp.occupant !== null) return this.error('refused', 'list is kept from a far asker');\n const cursor = Library.field(args, 'cursor') ?? null;\n const most = this.#page();\n const limit = Library.field(args, 'limit') ?? most;\n const told = Library.field(args, 'told') ?? false;\n if (cursor !== null && typeof cursor !== 'string')\n return this.error('refused', `a cursor is a text, or null, not ${Library.#sent(cursor)}`);\n if (typeof limit !== 'number' || !Number.isInteger(limit) || limit < 1 || limit > most)\n return this.error('refused', `a limit is a whole number from 1 to ${most}, not ${Library.#sent(limit)}`);\n if (typeof told !== 'boolean') return this.error('refused', `told is true or false, not ${Library.#sent(told)}`);\n const page = this.cells.range({\n prefix: [told ? 'told' : 'name'],\n limit,\n ...(cursor === null ? {} : { cursor }),\n });\n if (told) return { told: page.cells.map((cell) => this.#told(cell)), cursor: page.cursor };\n const faculties = page.cells.map(({ key, value }) => {\n const digest = String(key[2]);\n const organ = this.#organAt(digest);\n const record = organ ?? this.cells.get(['faculty', digest]);\n const road = Library.field(record, 'road');\n return {\n name: String(key[1]),\n digest,\n ...(typeof value === 'string' ? { label: value } : {}),\n ...(typeof road === 'string' ? { road } : {}),\n ...(organ === undefined ? {} : { kind: 'organ' }),\n ...(this.cells.get(['spared', digest]) === undefined ? {} : { spared: true }),\n ...(organ === undefined && !Library.proven(record) ? { unproven: true } : {}),\n };\n });\n return { faculties, cursor: page.cursor };\n }\n\n #organAt(digest ) {\n const row = this.cells.get(['organ', digest]);\n if (row === undefined) return undefined;\n const record = {};\n for (const field of ['id', 'digest', 'graph', 'blueprint', 'reach', 'half', 'road']) {\n const value = Library.field(row, field);\n if (value !== undefined) record[field] = value;\n }\n return record;\n }\n\n static #toldRow(row ) {\n if (row === undefined) return undefined;\n const [digest, at] = ['digest', 'at'].map((one) => Library.field(row, one));\n return {\n ...(digest === undefined ? {} : { digest }),\n ...(at === undefined ? {} : { at }),\n };\n }\n\n #told({ key, value } ) {\n const row = Library.#toldRow(value) ?? {};\n const { at } = row;\n const { digest } = row;\n const kept =\n typeof digest === 'string' &&\n (this.cells.get(['faculty', digest]) !== undefined || this.cells.get(['organ', digest]) !== undefined);\n const [lobe = '', kind = '', label = '', version = ''] = key.slice(1).map(String);\n return {\n lobe,\n kind,\n label,\n version,\n digest: digest ?? null,\n at: at ?? null,\n kept,\n };\n }\n}";
5887
+ var LIBRARY_TEXT = "class Library extends Faculty {\n static #digest = { type: 'string', pattern: '^[0-9a-f]{64}$' };\n\n static #road = { type: 'string', minLength: 1, maxLength: 256 };\n\n static #assets = {\n type: 'array',\n items: { type: 'array', items: { type: 'string', minLength: 1 }, minItems: 2, maxItems: 2 },\n };\n\n static #faculty = {\n type: 'object',\n properties: {\n source: { type: 'string', minLength: 1 },\n digest: Library.#digest,\n blueprint: { type: 'object' },\n road: Library.#road,\n label: { type: 'string', minLength: 1, maxLength: 64 },\n assets: Library.#assets,\n },\n required: ['source', 'digest', 'blueprint', 'road'],\n additionalProperties: false,\n };\n\n static #organ = {\n type: 'object',\n properties: {\n id: { type: 'string', minLength: 1, maxLength: 64 },\n digest: Library.#digest,\n graph: { type: 'string', minLength: 1 },\n blueprint: { type: 'object' },\n reach: {},\n half: { anyOf: [Library.#digest, { type: 'null' }] },\n road: Library.#road,\n },\n required: ['id', 'digest', 'graph', 'blueprint', 'half', 'road'],\n additionalProperties: false,\n };\n\n static #asset = {\n type: 'object',\n properties: { digest: Library.#digest, bytes: { type: 'string', contentEncoding: 'base16' } },\n required: ['digest', 'bytes'],\n additionalProperties: false,\n };\n\n static #lobe = { type: 'string', pattern: '^[A-Z][A-Z0-9]*$', maxLength: 64 };\n\n static #given = {\n type: 'object',\n properties: {\n kind: { const: 'faculty' },\n given: {\n type: 'object',\n properties: {\n place: Library.#lobe,\n digest: Library.#digest,\n items: { type: 'array', items: { type: 'object' }, maxItems: 1001 },\n },\n required: ['place', 'digest', 'items'],\n additionalProperties: false,\n },\n },\n required: ['kind', 'given'],\n additionalProperties: false,\n };\n\n static #hand = {\n type: 'object',\n properties: {\n source: { type: 'string', minLength: 1 },\n assets: { type: 'array', items: { type: 'object' } },\n second: { type: 'boolean' },\n },\n required: ['source'],\n additionalProperties: false,\n };\n\n static #version = {\n type: 'string',\n pattern: '^(0|[1-9][0-9]*)\\\\.(0|[1-9][0-9]*)\\\\.(0|[1-9][0-9]*)$',\n };\n\n static #named = {\n type: 'string',\n pattern: '^[a-z][a-z0-9]*([.-][a-z0-9]+)*$',\n maxLength: 64,\n };\n\n static #half = {\n type: 'object',\n properties: {\n form: { enum: ['component', 'native'] },\n code: {\n anyOf: [\n { type: 'string', minLength: 1 },\n { type: 'string', contentEncoding: 'base16' },\n ],\n },\n },\n required: ['form', 'code'],\n additionalProperties: false,\n };\n\n static blueprint = {\n name: 'nervur.library',\n version: '0.37.12',\n description:\n \"The library: it keeps the organism's faculties with their assets, and its organs, as data, each version by its digest, and the versions its sources told it.\",\n methods: {\n add: {\n description:\n \"On an owner's ask through the brain alone. From a source, `road`, any lobe of the organism's own whose describe names `get` and `told`: a faculty by its label or an organ by its ID, at a version, read from it over a wire the library orders, its digest checked and its blueprint's version, and kept under the road `<lobe>@<version>`, with that lobe kept as a source of the owners' own where its `state` answers a name, once; a faculty whose blueprint names `assets` has each asset read whole by its path and checked against its SHA-256, and their canonical digest against the blueprint's, or none of it is kept. From a far source, `road`, the library holds a standing on: a faculty or an organ at a version it told, read over the standing, each digest checked against what it told, an organ by its graph.json alone, never its host half, a faculty's assets as from near. Or by an owner's hand, `source`: a faculty's text carried in the ask, with its `assets` where it has any, kept under the road `hand@<version>` by the same walls. Or a host half's form and code under the digest of its code. A code the library keeps already, added from another road, takes that road, all else as it stands; boot's laying changes no road. Answers the digest; refuses a code whose blueprint's name and version the library keeps under another digest, but with `second`, an owner's word on a faculty, which takes it as a name of its own, kept by its source.\",\n kind: 'writing',\n args: {\n anyOf: [\n {\n type: 'object',\n properties: {\n road: Library.#lobe,\n kind: { const: 'faculty' },\n label: Library.#named,\n version: Library.#version,\n second: { type: 'boolean' },\n },\n required: ['road', 'kind', 'label', 'version'],\n additionalProperties: false,\n },\n {\n type: 'object',\n properties: {\n road: Library.#lobe,\n kind: { const: 'organ' },\n id: Library.#named,\n version: Library.#version,\n },\n required: ['road', 'kind', 'id', 'version'],\n additionalProperties: false,\n },\n Library.#given,\n Library.#hand,\n ],\n },\n result: {\n type: 'object',\n properties: { digest: Library.#digest },\n required: ['digest'],\n additionalProperties: false,\n },\n errors: ['refused'],\n },\n accept: {\n description:\n \"On an owner's ask through the brain alone: accepts a far source's invitation to a library's standing through the mouth, holding the relation itself on a placeholder of its own. It asks the far lobe at once what it told, `told`, and again at an add of a version not told it yet, since an organism that cannot be dialed can be told nothing. One that can names `tells`: since a relation runs one way, it draws through the ear a standing back on itself for the far lobe, the one before for that far lobe ended, and hands it as `told { tells }`, over which the far lobe tells each version it tells after, `changed`. With `note`, the owner's, which the brain keeps beside the standing, null where none is named. Answers the far organism the brain made up for it, the road an add names it by.\",\n kind: 'writing',\n args: {\n type: 'object',\n properties: { invitation: { type: 'string', minLength: 1 }, note: {}, tells: { const: true } },\n required: ['invitation'],\n additionalProperties: false,\n },\n result: {\n type: 'object',\n properties: { far: Library.#lobe },\n required: ['far'],\n additionalProperties: false,\n },\n errors: ['refused'],\n },\n changed: {\n description:\n \"A source's word that its `main` holds a faculty or an organ at a version it never told: a near one's over its wire, a far one's over the occupant the library's `accept` gave it, by an ask; kept for the owners to see, by `list` with `told`, never added.\",\n kind: 'writing',\n args: {\n type: 'object',\n properties: {\n kind: { enum: ['faculty', 'organ'] },\n label: Library.#named,\n version: Library.#version,\n digest: Library.#digest,\n },\n required: ['kind', 'label', 'version', 'digest'],\n additionalProperties: false,\n },\n errors: ['refused'],\n },\n remove: {\n irreversible: true,\n description:\n \"Deletes a version no lobe stands on with its assets no other kept faculty names, an organ's record, or a host half's code no organ names, on the brain's ask alone.\",\n kind: 'writing',\n args: Library.#byDigest(),\n errors: ['refused', 'used'],\n },\n spare: {\n description:\n \"On an owner's ask through the brain alone: keeps a version the library holds from the sweep, or, with `spared: false`, gives it back. An owner may still remove it.\",\n kind: 'writing',\n args: {\n type: 'object',\n properties: { digest: Library.#digest, spared: { type: 'boolean' } },\n required: ['digest'],\n additionalProperties: false,\n },\n errors: ['refused'],\n },\n evidence: {\n description:\n \"The asset that carries a kept faculty's evidence, `evidence.json`, by its SHA-256, which `get` answers, or null where it carries none; refused to a far asker.\",\n kind: 'reading',\n args: {\n type: 'object',\n properties: { faculty: Library.#digest },\n required: ['faculty'],\n additionalProperties: false,\n },\n result: {\n type: 'object',\n properties: { evidence: { anyOf: [Library.#digest, { type: 'null' }] } },\n required: ['evidence'],\n additionalProperties: false,\n },\n errors: ['refused'],\n },\n get: {\n description:\n \"The version of a digest with its assets, an organ's record, an asset's bytes, or a host half's form and code, or null; refused to a far asker.\",\n kind: 'reading',\n args: {\n type: 'object',\n properties: { digest: Library.#digest },\n required: ['digest'],\n additionalProperties: false,\n },\n result: {\n anyOf: [Library.#faculty, Library.#organ, Library.#asset, Library.#half, { type: 'null' }],\n },\n errors: ['refused'],\n },\n old: {\n description:\n \"The old versions the library keeps, on the brain's ask alone: of each name, a faculty's or an organ's blueprint name, every version but the newest by semver; the brain removes each no lobe stands on.\",\n kind: 'reading',\n args: { type: 'object', additionalProperties: false },\n result: { type: 'object', properties: { digests: { type: 'array', items: { type: 'string' } } } },\n },\n list: {\n description:\n \"The versions kept, by their blueprint's name, each with its road, an organ's marked, one an owner spared marked `spared`, a faculty a source or an owner's hand brought with no evidence marked `unproven`, a page at a time; with `told`, the versions the sources told, each with whether the library keeps it; refused to a far asker.\",\n kind: 'reading',\n args: {\n type: 'object',\n properties: {\n cursor: { anyOf: [{ type: 'string' }, { type: 'null' }] },\n limit: { type: 'integer', minimum: 1 },\n told: { type: 'boolean' },\n },\n additionalProperties: false,\n },\n result: {\n anyOf: [\n {\n type: 'object',\n properties: {\n faculties: { type: 'array', items: { type: 'object' } },\n cursor: { anyOf: [{ type: 'string' }, { type: 'null' }] },\n },\n required: ['faculties', 'cursor'],\n additionalProperties: false,\n },\n {\n type: 'object',\n properties: {\n told: { type: 'array', items: { type: 'object' } },\n cursor: { anyOf: [{ type: 'string' }, { type: 'null' }] },\n },\n required: ['told', 'cursor'],\n additionalProperties: false,\n },\n ],\n },\n errors: ['refused'],\n },\n },\n placeholders: { brain: 'nervur.brain', mouth: 'nervur.mouth', ear: 'nervur.ear' },\n };\n\n static #owner = 'brain';\n\n static #contract = ['get', 'told'];\n\n static #evidence = 'evidence.json';\n\n static #handRoad = 'hand';\n\n static #versionText = /^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)$/;\n static #namedText = /^[a-z][a-z0-9]*(?:[.-][a-z0-9]+)*$/;\n static #lobeText = /^[A-Z][A-Z0-9]*$/;\n\n static #sent(value ) {\n if (value === undefined) return 'nothing';\n const read = JSON.stringify(value);\n return read.length > 64 ? `${read.slice(0, 63)}\u2026` : read;\n }\n\n #page() {\n return Math.min(1000, Math.floor(this.memory / 4 / 1024));\n }\n\n static #byDigest() {\n return {\n type: 'object',\n properties: { digest: Library.#digest },\n required: ['digest'],\n additionalProperties: false,\n };\n }\n\n static #digestIn(args ) {\n const digest = Library.field(args, 'digest');\n return typeof digest === 'string' && /^[0-9a-f]{64}$/.test(digest) ? digest : undefined;\n }\n\n static #utf8(text ) {\n const bytes = [];\n for (const char of text) {\n const point = char.codePointAt(0) ?? 0;\n if (point < 0x80) bytes.push(point);\n else if (point < 0x800) bytes.push(0xc0 | (point >> 6), 0x80 | (point & 0x3f));\n else if (point < 0x10000) bytes.push(0xe0 | (point >> 12), 0x80 | ((point >> 6) & 0x3f), 0x80 | (point & 0x3f));\n else\n bytes.push(\n 0xf0 | (point >> 18),\n 0x80 | ((point >> 12) & 0x3f),\n 0x80 | ((point >> 6) & 0x3f),\n 0x80 | (point & 0x3f),\n );\n }\n return new Uint8Array(bytes);\n }\n\n static digestOf(crypto , code ) {\n return Library.hex(crypto.sha256(typeof code === 'string' ? Library.#utf8(code) : code));\n }\n\n static assetsDigest(\n crypto ,\n assets ,\n ) {\n const sorted = assets.toSorted((one, other) => (one[0] < other[0] ? -1 : 1));\n return Library.digestOf(crypto, JSON.stringify(sorted));\n }\n\n static keep(\n cells ,\n digest ,\n kept ,\n bytes = new Map(),\n ) {\n if (!('source' in kept)) {\n if (cells.get(['half', digest]) === undefined) cells.set(['half', digest], { form: kept.form, code: kept.code });\n return null;\n }\n const { source, blueprint, road, label, assets, second } = kept;\n const name = Library.field(blueprint, 'name');\n if (typeof name !== 'string') throw new TypeError('a version kept is one whose blueprint is named');\n if (cells.get(['faculty', digest]) !== undefined) return null;\n const named = Library.field(blueprint, 'assets') !== undefined;\n if (named !== (assets !== undefined))\n return named\n ? `the blueprint of ${name} names assets the faculty carries not`\n : `${name} carries assets its blueprint names not`;\n for (const [, sha] of assets ?? [])\n if (!bytes.has(sha) && cells.get(['asset', sha]) === undefined)\n return `${name} has no bytes for its asset ${sha}`;\n const indexed = Library.#indexed(cells, name, Library.field(blueprint, 'version'), digest, second);\n if (typeof indexed === 'string') return indexed;\n for (const [, sha] of assets ?? []) {\n const held = bytes.get(sha);\n if (held !== undefined && cells.get(['asset', sha]) === undefined) cells.set(['asset', sha], held);\n }\n cells.set(['faculty', digest], {\n source,\n digest,\n blueprint,\n road,\n ...(label === undefined ? {} : { label }),\n ...(assets === undefined ? {} : { assets: assets.map(([path, sha]) => [path, sha]) }),\n ...(indexed.second === undefined ? {} : { second: indexed.second }),\n });\n cells.set(['name', name, digest], label ?? null);\n return null;\n }\n\n static #indexed(\n cells ,\n name ,\n version ,\n digest ,\n second ,\n ) {\n if (typeof version !== 'string') return `the blueprint of ${name} names no version`;\n const named = cells.get(['version', name, version]);\n if (typeof named !== 'string' || named === digest) {\n cells.set(['version', name, version], digest);\n return {};\n }\n if (second === undefined) return `the library keeps ${name} ${version} under another digest, ${named}`;\n const own = cells.get(['second', name, version, second]);\n if (typeof own === 'string' && own !== digest)\n return `the library keeps ${name} ${version} of ${second} under another digest, ${own}`;\n cells.set(['second', name, version, second], digest);\n return { second };\n }\n\n *add(args ) {\n if (this.stamp.asker !== Library.#owner)\n return this.error('refused', \"the library adds on an owner's ask through the brain alone\");\n if (Library.field(args, 'given') !== undefined) return yield* this.#addGiven(args);\n if (Library.field(args, 'source') !== undefined) return yield* this.#addHand(args);\n return yield* this.#addFrom(args);\n }\n\n *#read(source ) {\n const answered = yield { read: source };\n const read = 'result' in answered ? answered.result : undefined;\n const blueprint = Library.field(read, 'blueprint');\n if (blueprint !== undefined && typeof Library.field(blueprint, 'name') === 'string') return blueprint;\n const why = Library.field(read, 'why');\n return `the source is no faculty: ${typeof why === 'string' ? why : 'it declares no blueprint'}`;\n }\n\n static #fromArgs(\n args ,\n ) {\n const kind = Library.field(args, 'kind');\n const key = kind === 'organ' ? 'id' : 'label';\n const [road, named, version] = ['road', key, 'version'].map((one) => Library.field(args, one));\n const keys = typeof args === 'object' && args !== null ? Object.keys(args).length : 0;\n const second = Library.field(args, 'second');\n if ((kind !== 'faculty' && kind !== 'organ') || keys !== (second === undefined ? 4 : 5))\n return 'add takes a road, a kind, a faculty or an organ, its label or ID, and a version';\n if (second !== undefined && ((second !== true && second !== false) || kind !== 'faculty'))\n return `\\`second\\` is an owner's word on a faculty, true or false, not ${Library.#sent(second)}`;\n if (typeof road !== 'string' || road.length > 64 || !Library.#lobeText.test(road))\n return `a road is a lobe of this organism, by the ID the brain made up for it, not ${Library.#sent(road)}`;\n if (typeof named !== 'string' || named.length > 64 || !Library.#namedText.test(named))\n return `a ${key} is a folder's name, lowercase, not ${Library.#sent(named)}`;\n if (typeof version !== 'string' || !Library.#versionText.test(version))\n return `a version is three whole numbers joined by dots, not ${Library.#sent(version)}`;\n return { road, kind, named, version, second: second === true };\n }\n\n *#addFrom(args ) {\n const asked = Library.#fromArgs(args);\n if (typeof asked === 'string') return this.error('refused', asked);\n if (this.cells.get(['far', asked.road]) !== undefined) return yield* this.#addFar(asked);\n const { road, kind, named, version, second } = asked;\n const unreached = yield* this.#reach(road);\n if (unreached !== null) return this.error('refused', unreached);\n const got = yield {\n placeholder: road,\n method: 'get',\n args: { kind, label: named, version },\n };\n if ('error' in got)\n return this.error('refused', `the source ${road} answers ${got.error.code}: ${got.error.message}`);\n const from = `${road}@${version}`;\n const taken =\n kind === 'organ'\n ? this.#takeOrgan(got.result, named, version, from)\n : yield* this.#takeFaculty(got.result, from, {\n lobe: road,\n label: named,\n version,\n ...(second ? { second: road } : {}),\n });\n if (Library.#added(taken)) yield* this.#kindOf(road);\n return taken;\n }\n\n static #added(taken ) {\n return typeof taken === 'object' && taken !== null && 'digest' in taken;\n }\n\n *#kindOf(lobe ) {\n if (this.cells.get(['source', lobe]) !== undefined) return;\n const state = yield {\n placeholder: lobe,\n method: 'state',\n args: {},\n };\n const name = 'result' in state ? Library.field(state.result, 'name') : undefined;\n if (typeof name === 'string' && name !== '') this.cells.set(['source', lobe], 'owners');\n }\n\n *#reach(lobe ) {\n const order = { termination: lobe };\n const ordered = yield {\n placeholder: 'nerves',\n method: 'order',\n args: { order },\n };\n if ('error' in ordered) return `the library reaches no ${lobe}: ${ordered.error.message}`;\n const described = yield {\n placeholder: lobe,\n method: null,\n args: null,\n };\n const methods = 'result' in described ? Library.field(described.result, 'methods') : undefined;\n const lacking = Library.#contract.filter((method) => Library.field(methods, method) === undefined);\n if (lacking.length === 0) return null;\n yield {\n placeholder: 'nerves',\n method: 'unwire',\n args: { placeholder: lobe },\n };\n return `${lobe} is no source: its describe names no ${lacking.join(' and no ')}`;\n }\n\n *#takeFaculty(answered , road , at ) {\n const { label, version } = at;\n const source = Library.field(answered, 'source');\n const told = Library.field(answered, 'digest');\n if (typeof source !== 'string' || source === '') return this.error('refused', 'the source answered no source');\n const digest = Library.digestOf(this.crypto, source);\n if (told !== digest)\n return this.error('refused', `the source the source answered is not its digest, ${JSON.stringify(told ?? null)}`);\n if (this.cells.get(['faculty', digest]) !== undefined) return this.#reroad(digest, road, version);\n const blueprint = yield* this.#read(source);\n if (typeof blueprint === 'string') return this.error('refused', blueprint);\n const named = Library.field(blueprint, 'version');\n if (named !== version)\n return this.error('refused', `the faculty names version ${JSON.stringify(named ?? null)}, not ${version}`);\n const carried = yield* this.#assetsTaken(answered, blueprint, at);\n if (typeof carried === 'string') return this.error('refused', carried);\n const refused = Library.keep(\n this.cells,\n digest,\n { source, blueprint, road, label, ...carried.kept, ...(at.second === undefined ? {} : { second: at.second }) },\n carried.bytes,\n );\n return refused === null ? { digest } : this.error('refused', refused);\n }\n\n #reroad(digest , road , version ) {\n const kept = this.cells.get(['faculty', digest]);\n const named = Library.field(Library.field(kept, 'blueprint'), 'version');\n if (named !== version)\n return this.error('refused', `the faculty names version ${JSON.stringify(named ?? null)}, not ${version}`);\n if (Library.field(kept, 'road') === road) return { digest };\n const record = {};\n for (const field of ['source', 'digest', 'blueprint', 'label', 'assets', 'second']) {\n const value = Library.field(kept, field);\n if (value !== undefined) record[field] = value;\n }\n this.cells.set(['faculty', digest], { ...record, road });\n return { digest };\n }\n\n *#assetsTaken(\n answered ,\n blueprint ,\n at ,\n ) \n \n \n \n {\n const bytes = new Map ();\n const named = Library.field(blueprint, 'assets');\n const told = Library.field(answered, 'assets');\n if (named === undefined)\n return told === undefined ? { kept: {}, bytes } : 'the source answered assets the blueprint names not';\n const assets = this.#assetsOf(told);\n if (assets === null) return 'the source answered no assets whole: each a path and a SHA-256, one path once';\n if (Library.assetsDigest(this.crypto, assets) !== named)\n return `the assets are not the digest the blueprint names, ${JSON.stringify(named)}`;\n for (const [path, sha] of assets) {\n if (bytes.has(sha) || this.cells.get(['asset', sha]) !== undefined) continue;\n const got = yield {\n placeholder: at.lobe,\n method: 'get',\n args: { kind: 'faculty', label: at.label, version: at.version, path },\n };\n if ('error' in got)\n return `the source ${at.lobe} answers ${got.error.code} for the asset ${path}: ${got.error.message}`;\n const [given, digest, held] = ['path', 'digest', 'bytes'].map((one) => Library.field(got.result, one));\n if (given !== path || digest !== sha || !(held instanceof Uint8Array))\n return `the source answered another asset than ${path}`;\n if (Library.digestOf(this.crypto, held) !== sha) return `the asset ${path} is not its digest, ${sha}`;\n bytes.set(sha, held);\n }\n return { kept: { assets }, bytes };\n }\n\n static #json(text ) {\n try {\n const read = JSON.parse(text);\n return typeof read === 'object' && read !== null && !Array.isArray(read) ? read : null;\n } catch {\n return null;\n }\n }\n\n #takeOrgan(answered , id , version , road ) {\n const graph = Library.field(answered, 'blueprint');\n const half = Library.field(answered, 'half') ?? null;\n if (typeof graph !== 'string') return this.error('refused', \"the source answered no organ's graph.json\");\n if (half !== null && (typeof half !== 'string' || !/^[0-9a-f]{64}$/.test(half)))\n return this.error('refused', 'the source answered a built half that is no digest');\n const read = Library.#json(graph);\n const inner = Library.field(read, 'blueprint');\n const blueprint = inner !== undefined && Library.#json(JSON.stringify(inner)) !== null ? inner : read;\n const name = Library.field(blueprint, 'name');\n const named = Library.field(blueprint, 'version');\n if (blueprint === null || blueprint === undefined || typeof name !== 'string')\n return this.error('refused', 'its graph.json holds no blueprint, named');\n if (named !== version)\n return this.error('refused', `the organ names version ${JSON.stringify(named ?? null)}, not ${version}`);\n const digest = Library.digestOf(this.crypto, graph);\n const kept = this.#organAt(digest);\n if (kept !== undefined) {\n if (half !== null || kept['road'] !== road)\n this.cells.set(['organ', digest], { ...kept, ...(half === null ? {} : { half }), road });\n return { digest };\n }\n const clash = Library.#indexed(this.cells, name, named, digest, undefined);\n if (typeof clash === 'string') return this.error('refused', clash);\n const reach = inner === undefined ? undefined : Library.field(read, 'reach');\n this.cells.set(['organ', digest], {\n id,\n digest,\n graph,\n blueprint,\n ...(reach === undefined ? {} : { reach }),\n half,\n road,\n });\n this.cells.set(['name', name, digest], id);\n return { digest };\n }\n\n #assetsOf(data ) {\n if (!Array.isArray(data) || data.length > this.#page()) return null;\n const assets = [];\n for (const one of data) {\n const [path, sha] = Array.isArray(one) && one.length === 2 ? one : [];\n if (typeof path !== 'string' || path === '') return null;\n if (typeof sha !== 'string' || !/^[0-9a-f]{64}$/.test(sha)) return null;\n assets.push([path, sha]);\n }\n const sorted = assets.toSorted((one, other) => (one[0] < other[0] ? -1 : 1));\n return sorted.every((one, at) => sorted[at - 1]?.[0] !== one[0]) ? sorted : null;\n }\n\n #assetsNamed() {\n const named = new Set ();\n let cursor = null;\n do {\n const page = this.cells.range({\n prefix: ['faculty'],\n limit: this.#page(),\n ...(cursor === null ? {} : { cursor }),\n });\n for (const { value } of page.cells)\n for (const [, sha] of this.#assetsOf(Library.field(value, 'assets')) ?? []) named.add(sha);\n cursor = page.cursor;\n } while (cursor !== null);\n return named;\n }\n\n *accept(args ) {\n if (this.stamp.asker !== Library.#owner)\n return this.error('refused', \"the library accepts a standing on an owner's ask through the brain alone\");\n const invitation = Library.field(args, 'invitation');\n const note = Library.field(args, 'note');\n const keys = typeof args === 'object' && args !== null ? Object.keys(args).length : 0;\n const tells = Library.field(args, 'tells');\n const named = 1 + (note === undefined ? 0 : 1) + (tells === undefined ? 0 : 1);\n if (typeof invitation !== 'string' || invitation === '' || keys !== named || (tells ?? true) !== true)\n return this.error(\n 'refused',\n 'accept takes an invitation, a note where one is named, and `tells` where it can be told',\n );\n const held = this.cells.get(['standings']);\n const count = typeof held === 'number' ? held + 1 : 1;\n this.cells.set(['standings'], count);\n const placeholder = `far-${count}`;\n const accepted = yield* this.#accepted({ invitation, placeholder, note: note ?? null });\n if ('error' in accepted) return this.error('refused', `the mouth accepts no standing: ${accepted.error.message}`);\n const far = Library.field(accepted.result, 'far');\n if (typeof far !== 'string' || !Library.#lobeText.test(far))\n return this.error('refused', 'the mouth named no far organism');\n this.cells.set(['far', far], { placeholder });\n this.cells.set(['source', far], 'far');\n yield* this.#untold(far);\n if (tells === true) yield* this.#tellsBack(far, placeholder);\n else yield* this.#asksTold(far, placeholder);\n return { far };\n }\n\n *#accepted(args ) {\n const answer = yield { placeholder: 'mouth', method: 'accept', args };\n return answer;\n }\n\n *#tellsBack(far , placeholder ) {\n const invited = yield {\n placeholder: 'ear',\n method: 'invite',\n args: { waits: null, lives: null, note: { library: far } },\n };\n const tells = 'result' in invited ? Library.field(invited.result, 'invitation') : undefined;\n const back = 'result' in invited ? Library.field(invited.result, 'far') : undefined;\n if (typeof tells !== 'string') return;\n const asked = yield { placeholder, method: 'told', args: { tells } };\n if ('error' in asked) {\n if (typeof back === 'string') yield { placeholder: 'ear', method: 'drop', args: { far: back } };\n return;\n }\n yield* this.#readOn(far, placeholder, asked.result);\n }\n\n *#asksTold(far , placeholder ) {\n const asked = yield { placeholder, method: 'told', args: {} };\n if ('result' in asked) yield* this.#readOn(far, placeholder, asked.result);\n }\n\n *#readOn(far , placeholder , first ) {\n const seen = new Set ();\n let page = first;\n for (;;) {\n this.#heardAll(far, Library.field(page, 'told') ?? null);\n const cursor = Library.field(page, 'cursor');\n if (typeof cursor !== 'string' || seen.has(cursor)) return;\n seen.add(cursor);\n const next = yield { placeholder, method: 'told', args: { cursor } };\n if (!('result' in next)) return;\n page = next.result;\n }\n }\n\n #heardAll(far , answered ) {\n for (const one of Array.isArray(answered) ? answered.slice(0, this.#page()) : []) {\n const told = Library.#toldFar(one);\n if (told !== null) this.#heard(far, told.kind, told.label, told.version, told.digest);\n }\n }\n\n *#untold(far ) {\n let cursor = null;\n const seen = new Set ();\n const given = [];\n do {\n const page = yield {\n placeholder: 'nerves',\n method: 'relations',\n args: cursor === null ? {} : { cursor },\n };\n if ('error' in page) break;\n const relations = Library.field(page.result, 'relations');\n for (const one of Array.isArray(relations) ? relations : []) {\n const back = Library.field(one, 'far');\n const mine = Library.field(Library.field(one, 'note'), 'library') === far;\n if (Library.field(one, 'side') === 'occupant' && mine && typeof back === 'string') given.push(back);\n }\n const next = Library.field(page.result, 'cursor');\n cursor = typeof next === 'string' && !seen.has(next) ? next : null;\n if (cursor !== null) seen.add(cursor);\n } while (cursor !== null);\n for (const back of given) yield { placeholder: 'ear', method: 'drop', args: { far: back } };\n }\n\n #heard(far , kind , label , version , digest ) {\n const key = ['told', far, kind, label, version];\n if (this.cells.get(key) !== undefined) return;\n const telling = this.cells.get(['telling', far]) ?? { first: 0, next: 0 };\n let first = Number(Library.field(telling, 'first'));\n const next = Number(Library.field(telling, 'next'));\n for (; next - first >= this.#page(); first += 1) {\n const oldest = this.cells.get(['telling', far, first]);\n if (Array.isArray(oldest)) this.cells.delete(oldest);\n this.cells.delete(['telling', far, first]);\n }\n this.cells.set(['telling', far, next], key);\n this.cells.set(['telling', far], { first, next: next + 1 });\n this.cells.set(key, { digest, at: this.stamp.time });\n }\n\n static #isDigest(text ) {\n return typeof text === 'string' && /^[0-9a-f]{64}$/.test(text);\n }\n\n static #toldFar(one ) {\n const [kind, label, version, digest] = ['kind', 'label', 'version', 'digest'].map((name) =>\n Library.field(one, name),\n );\n if (kind !== 'faculty' && kind !== 'organ') return null;\n if (typeof label !== 'string' || label.length > 64 || !Library.#namedText.test(label)) return null;\n if (typeof version !== 'string' || !Library.#versionText.test(version)) return null;\n return Library.#isDigest(digest) ? { kind, label, version, digest } : null;\n }\n\n *#addFar(asked \n \n \n \n \n \n ) {\n const { road, kind, named, version, second } = asked;\n const placeholder = Library.field(this.cells.get(['far', road]), 'placeholder');\n if (this.#toldRowOf(road, kind, named, version) === undefined && typeof placeholder === 'string')\n yield* this.#asksTold(road, placeholder);\n const toldAt = this.#toldAt(road, kind, named, version);\n if (typeof toldAt === 'string') return this.error('refused', toldAt);\n const got = yield {\n placeholder: toldAt.placeholder,\n method: 'get',\n args: { kind, label: named, version },\n };\n if ('error' in got)\n return this.error('refused', `the far source ${road} answers ${got.error.code}: ${got.error.message}`);\n const at = { lobe: toldAt.placeholder, label: named, version, ...(second ? { second: road } : {}) };\n return yield* this.#takeFar(got.result, toldAt.told, { road, kind, named, version }, at);\n }\n\n #toldRowOf(road , kind , named , version ) {\n return Library.#toldRow(this.cells.get(['told', road, kind, named, version]));\n }\n\n #toldAt(road , kind , named , version ) {\n const told = this.#toldRowOf(road, kind, named, version);\n const placeholder = Library.field(this.cells.get(['far', road]), 'placeholder');\n if (told === undefined || typeof placeholder !== 'string')\n return `the far source ${road} told no ${kind} ${named} ${version}`;\n return { told, placeholder };\n }\n\n *#takeFar(\n answered ,\n told ,\n at \n \n \n \n \n ,\n asked ,\n ) {\n const { road, kind, named, version } = at;\n const from = `${road}@${version}`;\n const [source, graph] = ['source', 'blueprint'].map((one) => Library.field(answered, one));\n const matches = (code , name ) =>\n typeof code === 'string' && Library.digestOf(this.crypto, code) === Library.field(told, name);\n if (kind === 'faculty')\n return matches(source, 'digest')\n ? yield* this.#takeFaculty(\n { ...Library.#only(answered, 'assets'), source, digest: Library.field(told, 'digest') ?? null },\n from,\n asked,\n )\n : this.error('refused', `the source the far source ${road} answered is not the digest it told`);\n if (!matches(graph, 'digest'))\n return this.error('refused', `the organ the far source ${road} answered is not the digests it told`);\n return this.#takeOrgan({ blueprint: graph, half: null }, named, version, from);\n }\n\n static #only(answered , name ) {\n const found = Library.field(answered, name);\n return found === undefined ? {} : { [name]: found };\n }\n\n *changed(args ) {\n const [kind, label, version, digest] = ['kind', 'label', 'version', 'digest'].map((one) =>\n Library.field(args, one),\n );\n const keys = typeof args === 'object' && args !== null ? Object.keys(args).length : 0;\n if (\n (kind !== 'faculty' && kind !== 'organ') ||\n keys !== 4 ||\n typeof label !== 'string' ||\n !Library.#namedText.test(label) ||\n typeof version !== 'string' ||\n !Library.#versionText.test(version) ||\n !Library.#isDigest(digest)\n )\n return this.error('refused', `changed takes a kind, a label, a version and a digest, not ${Library.#sent(args)}`);\n const { asker, occupant } = this.stamp;\n if (occupant !== null && occupant.far === asker) {\n const road = Library.field(occupant.note, 'library');\n if (typeof road !== 'string' || this.cells.get(['far', road]) === undefined)\n return this.error('refused', 'changed comes over an occupant the library gave a far source');\n this.#heard(road, kind, label, version, digest);\n return null;\n }\n if (!Library.#lobeText.test(asker)) return this.error('refused', \"changed is a source's word\");\n const unreached = yield* this.#reach(asker);\n if (unreached !== null) return this.error('refused', unreached);\n this.#heard(asker, kind, label, version, digest);\n return null;\n }\n\n static #unbase64(text ) {\n if (!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/u.test(text)) return null;\n const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';\n const bytes = [];\n let [word, bits] = [0, 0];\n for (const char of text.replaceAll('=', '')) {\n word = (word << 6) | alphabet.indexOf(char);\n bits += 6;\n if (bits >= 8) {\n bits -= 8;\n bytes.push((word >> bits) & 0xff);\n word &= (1 << bits) - 1;\n }\n }\n return new Uint8Array(bytes);\n }\n\n static #givenAssets(\n crypto ,\n items ,\n ) {\n let source ;\n const bytes = new Map ();\n const assets = [];\n for (const item of items) {\n const sourceText = Library.field(item, 'source');\n if (typeof sourceText === 'string') {\n if (source !== undefined) return 'a faculty given holds one source';\n source = sourceText;\n continue;\n }\n const [path, digest, text, base64] = ['path', 'digest', 'text', 'base64'].map((one) => Library.field(item, one));\n const held =\n typeof text === 'string' ? Library.#utf8(text) : typeof base64 === 'string' ? Library.#unbase64(base64) : null;\n if (typeof path !== 'string' || path === '' || typeof digest !== 'string' || held === null)\n return 'a faculty given holds an asset that is none';\n if (Library.digestOf(crypto, held) !== digest) return `the asset ${path} is not its digest, ${digest}`;\n if (assets.some(([seen]) => seen === path)) return `the asset ${path} is given twice`;\n assets.push([path, digest]);\n bytes.set(digest, held);\n }\n return source === undefined ? 'a faculty given holds its source' : { source, bytes, assets };\n }\n\n *#addGiven(args ) {\n const given = Library.field(args, 'given');\n const [place, digest, items] = ['place', 'digest', 'items'].map((one) => Library.field(given, one));\n if (typeof place !== 'string' || typeof digest !== 'string')\n return this.error('refused', 'a faculty given names its place and its digest');\n const kind = this.cells.get(['source', place]);\n if (kind !== undefined && kind !== 'far')\n return this.error('refused', `the place ${place} is a source of the owners' own, which offers no faculty`);\n if (!Array.isArray(items)) return this.error('refused', 'a faculty given holds its items');\n const taken = Library.#givenAssets(this.crypto, items);\n if (typeof taken === 'string') return this.error('refused', taken);\n const { source, bytes, assets } = taken;\n if (Library.digestOf(this.crypto, source) !== digest)\n return this.error('refused', `the faculty given is not its digest, ${digest}`);\n const blueprint = yield* this.#read(source);\n if (typeof blueprint === 'string') return this.error('refused', blueprint);\n const version = Library.field(blueprint, 'version');\n if (typeof version !== 'string' || !Library.#versionText.test(version))\n return this.error('refused', `a version is three whole numbers joined by dots, not ${Library.#sent(version)}`);\n const road = `${place}@${version}`;\n if (this.cells.get(['faculty', digest]) !== undefined) return this.#reroad(digest, road, version);\n const named = Library.field(blueprint, 'assets');\n if (!(named === undefined && assets.length === 0) && Library.assetsDigest(this.crypto, assets) !== named)\n return this.error('refused', \"the assets given are not the digest the faculty's blueprint names\");\n const sorted = assets.toSorted((one, other) => (one[0] < other[0] ? -1 : 1));\n const refused = Library.keep(\n this.cells,\n digest,\n { source, blueprint, road, ...(named === undefined ? {} : { assets: sorted }) },\n bytes,\n );\n return refused === null ? { digest } : this.error('refused', refused);\n }\n\n *#addHand(args ) {\n const [source, assets, second] = ['source', 'assets', 'second'].map((one) => Library.field(args, one));\n if (typeof source !== 'string' || source === '') return this.error('refused', \"an owner's hand carries a source\");\n if (assets !== undefined && (!Array.isArray(assets) || assets.length > this.#page()))\n return this.error(\n 'refused',\n `assets carried are a list, of as many as a faculty holds, not ${Library.#sent(assets)}`,\n );\n if (second !== undefined && typeof second !== 'boolean')\n return this.error('refused', `\\`second\\` is an owner's word, true or false, not ${Library.#sent(second)}`);\n const taken = Library.#givenAssets(this.crypto, [{ source }, ...(assets ?? [])]);\n if (typeof taken === 'string') return this.error('refused', taken);\n const blueprint = yield* this.#read(source);\n if (typeof blueprint === 'string') return this.error('refused', blueprint);\n const version = Library.field(blueprint, 'version');\n if (typeof version !== 'string' || !Library.#versionText.test(version))\n return this.error('refused', `a version is three whole numbers joined by dots, not ${Library.#sent(version)}`);\n const road = `${Library.#handRoad}@${version}`;\n const digest = Library.digestOf(this.crypto, source);\n if (this.cells.get(['faculty', digest]) !== undefined) return this.#reroad(digest, road, version);\n const named = Library.field(blueprint, 'assets');\n if (named !== undefined && Library.assetsDigest(this.crypto, taken.assets) !== named)\n return this.error('refused', \"the assets carried are not the digest the faculty's blueprint names\");\n const refused = Library.keep(\n this.cells,\n digest,\n {\n source,\n blueprint,\n road,\n ...(named === undefined && taken.assets.length === 0\n ? {}\n : { assets: taken.assets.toSorted((one, other) => (one[0] < other[0] ? -1 : 1)) }),\n ...(second === true ? { second: Library.#handRoad } : {}),\n },\n taken.bytes,\n );\n return refused === null ? { digest } : this.error('refused', refused);\n }\n\n *remove(args ) {\n if (this.stamp.asker !== 'brain')\n return this.error('unavailable', \"the library removes a faculty on the brain's ask alone\");\n const digest = Library.#digestIn(args);\n if (digest === undefined) return this.error('refused', 'remove takes a digest');\n const record = this.cells.get(['faculty', digest]) ?? this.#organAt(digest);\n const blueprint = Library.field(record, 'blueprint');\n const name = Library.field(blueprint, 'name');\n const half = this.cells.get(['half', digest]) !== undefined;\n if (typeof name !== 'string' && !half) return this.error('refused', `the library keeps nothing under ${digest}`);\n const uses = yield {\n placeholder: 'brain',\n method: 'uses',\n args: { digest },\n };\n if ('error' in uses) return this.error(uses.error.code, uses.error.message);\n if (uses.result !== false) return this.error('used', `a lobe or an organ stands on ${digest}`);\n if (typeof name !== 'string') this.cells.delete(['half', digest]);\n else {\n this.cells.delete(['faculty', digest]);\n this.cells.delete(['organ', digest]);\n const held = this.#assetsOf(Library.field(record, 'assets')) ?? [];\n const named = held.length === 0 ? new Set () : this.#assetsNamed();\n for (const [, sha] of held) if (!named.has(sha)) this.cells.delete(['asset', sha]);\n this.cells.delete(['name', name, digest]);\n this.cells.delete(['spared', digest]);\n }\n return null;\n }\n\n spare(args ) {\n if (this.stamp.asker !== Library.#owner)\n return this.error('refused', \"the library spares a version on an owner's ask through the brain alone\");\n const digest = Library.#digestIn(args);\n const spared = Library.field(args, 'spared') ?? true;\n if (digest === undefined || typeof spared !== 'boolean')\n return this.error('refused', 'spare takes a digest, and `spared` where it gives one back');\n if (!this.#keeps(digest)) return this.error('refused', `the library keeps nothing under ${digest}`);\n if (spared) this.cells.set(['spared', digest], true);\n else this.cells.delete(['spared', digest]);\n return null;\n }\n\n #keeps(digest ) {\n return this.cells.get(['faculty', digest]) !== undefined || this.cells.get(['organ', digest]) !== undefined;\n }\n\n static proven(record ) {\n const road = Library.field(record, 'road');\n const taken = typeof road === 'string' && /^(?:hand|[A-Z][A-Z0-9]*)@/u.test(road);\n const assets = Library.field(record, 'assets');\n return (\n !taken || (Array.isArray(assets) && assets.some((one) => Array.isArray(one) && one[0] === Library.#evidence))\n );\n }\n\n #evidenceOf(record ) {\n const carried = this.#assetsOf(Library.field(record, 'assets')) ?? [];\n return carried.find(([path]) => path === Library.#evidence)?.[1] ?? null;\n }\n\n evidence(args ) {\n if (this.stamp.occupant !== null) return this.error('refused', 'evidence is kept from a far asker');\n const digest = Library.field(args, 'faculty');\n const record = Library.#isDigest(digest) ? this.cells.get(['faculty', digest]) : undefined;\n if (record === undefined) return this.error('refused', 'evidence takes the digest of a faculty the library keeps');\n return { evidence: this.#evidenceOf(record) };\n }\n\n old() {\n if (this.stamp.asker !== Library.#owner)\n return this.error('unavailable', 'the library names its old versions to the brain alone');\n return { digests: this.#olderIn() };\n }\n\n #olderIn() {\n const newest = new Map ();\n const older = [];\n let cursor = null;\n do {\n const page = this.cells.range({\n prefix: ['version'],\n limit: this.#page(),\n ...(cursor === null ? {} : { cursor }),\n });\n for (const { key, value } of page.cells) {\n const at = Library.#semver(key[2]);\n if (typeof value !== 'string' || at === null || !this.#keeps(value)) continue;\n const name = String(key[1]);\n const top = newest.get(name);\n if (top === undefined) newest.set(name, { at, digest: value });\n else if (Library.#newer(at, top.at)) {\n older.push(top.digest);\n newest.set(name, { at, digest: value });\n } else older.push(value);\n }\n cursor = page.cursor;\n } while (cursor !== null);\n return older.filter((digest) => this.cells.get(['spared', digest]) === undefined);\n }\n\n static #semver(version ) {\n if (typeof version !== 'string' || !Library.#versionText.test(version)) return null;\n return version.split('.').map(Number);\n }\n\n static #newer(one , other ) {\n for (let at = 0; at < 3; at += 1) if ((one[at] ?? 0) !== (other[at] ?? 0)) return (one[at] ?? 0) > (other[at] ?? 0);\n return false;\n }\n\n get(args ) {\n if (this.stamp.occupant !== null) return this.error('refused', 'get is kept from a far asker');\n const digest = Library.#digestIn(args);\n if (digest === undefined) return this.error('refused', 'get takes a digest');\n return (\n this.cells.get(['faculty', digest]) ??\n this.#organAt(digest) ??\n this.#assetAt(digest) ??\n this.cells.get(['half', digest]) ??\n null\n );\n }\n\n #assetAt(digest ) {\n const kept = this.cells.get(['asset', digest]);\n return kept instanceof Uint8Array ? { digest, bytes: kept } : undefined;\n }\n\n list(args ) {\n if (this.stamp.occupant !== null) return this.error('refused', 'list is kept from a far asker');\n const cursor = Library.field(args, 'cursor') ?? null;\n const most = this.#page();\n const limit = Library.field(args, 'limit') ?? most;\n const told = Library.field(args, 'told') ?? false;\n if (cursor !== null && typeof cursor !== 'string')\n return this.error('refused', `a cursor is a text, or null, not ${Library.#sent(cursor)}`);\n if (typeof limit !== 'number' || !Number.isInteger(limit) || limit < 1 || limit > most)\n return this.error('refused', `a limit is a whole number from 1 to ${most}, not ${Library.#sent(limit)}`);\n if (typeof told !== 'boolean') return this.error('refused', `told is true or false, not ${Library.#sent(told)}`);\n const page = this.cells.range({\n prefix: [told ? 'told' : 'name'],\n limit,\n ...(cursor === null ? {} : { cursor }),\n });\n if (told) return { told: page.cells.map((cell) => this.#told(cell)), cursor: page.cursor };\n const faculties = page.cells.map(({ key, value }) => {\n const digest = String(key[2]);\n const organ = this.#organAt(digest);\n const record = organ ?? this.cells.get(['faculty', digest]);\n const road = Library.field(record, 'road');\n return {\n name: String(key[1]),\n digest,\n ...(typeof value === 'string' ? { label: value } : {}),\n ...(typeof road === 'string' ? { road } : {}),\n ...(organ === undefined ? {} : { kind: 'organ' }),\n ...(this.cells.get(['spared', digest]) === undefined ? {} : { spared: true }),\n ...(organ === undefined && !Library.proven(record) ? { unproven: true } : {}),\n };\n });\n return { faculties, cursor: page.cursor };\n }\n\n #organAt(digest ) {\n const row = this.cells.get(['organ', digest]);\n if (row === undefined) return undefined;\n const record = {};\n for (const field of ['id', 'digest', 'graph', 'blueprint', 'reach', 'half', 'road']) {\n const value = Library.field(row, field);\n if (value !== undefined) record[field] = value;\n }\n return record;\n }\n\n static #toldRow(row ) {\n if (row === undefined) return undefined;\n const [digest, at] = ['digest', 'at'].map((one) => Library.field(row, one));\n return {\n ...(digest === undefined ? {} : { digest }),\n ...(at === undefined ? {} : { at }),\n };\n }\n\n #told({ key, value } ) {\n const row = Library.#toldRow(value) ?? {};\n const { at } = row;\n const { digest } = row;\n const kept =\n typeof digest === 'string' &&\n (this.cells.get(['faculty', digest]) !== undefined || this.cells.get(['organ', digest]) !== undefined);\n const [lobe = '', kind = '', label = '', version = ''] = key.slice(1).map(String);\n return {\n lobe,\n kind,\n label,\n version,\n digest: digest ?? null,\n at: at ?? null,\n kept,\n };\n }\n}";
5888
5888
 
5889
5889
  var LIBRARY_SOURCE = facultySource(LIBRARY_TEXT);
5890
5890
 
5891
5891
  var SCHEDULER_BLUEPRINT = {
5892
5892
  name: "nervur.scheduler",
5893
- version: "0.37.11",
5893
+ version: "0.37.12",
5894
5894
  description: "The scheduler: every lobe's alarms, over the brain's one durable wake.",
5895
5895
  methods: {
5896
5896
  set: {
@@ -5974,7 +5974,7 @@ var SCHEDULER_BLUEPRINT = {
5974
5974
  placeholders: { brain: "nervur.brain", cage: "nervur.cage" }
5975
5975
  };
5976
5976
 
5977
- var SCHEDULER_TEXT = "class Scheduler extends Faculty {\n static #count = { type: 'integer', minimum: 0 };\n\n static #cursor = { anyOf: [{ type: 'string' }, { type: 'null' }] };\n\n static #object(properties , required ) {\n return { type: 'object', properties, required, additionalProperties: false };\n }\n\n static blueprint = {\n name: 'nervur.scheduler',\n version: '0.37.11',\n description: \"The scheduler: every lobe's alarms, over the brain's one durable wake.\",\n methods: {\n set: {\n description:\n \"Keeps an alarm of the asker's: when, on the wall clock, which of its methods to ring, and its args. Answers the alarm's ID.\",\n kind: 'writing',\n args: Scheduler.#object({ at: Scheduler.#count, method: { type: 'string', minLength: 1 }, args: {} }, [\n 'at',\n 'method',\n ]),\n result: Scheduler.#object({ id: Scheduler.#count }, ['id']),\n errors: ['refused'],\n },\n cancel: {\n description:\n \"Removes an alarm of the asker's, by its ID; asked by the brain for an owner, an alarm of the lobe it names.\",\n kind: 'writing',\n args: Scheduler.#object({ id: Scheduler.#count, lobe: { type: 'string', minLength: 1 } }, ['id']),\n result: { type: 'null' },\n errors: ['refused'],\n },\n list: {\n description:\n \"The asker's own alarms, never another lobe's, a page at a time: `limit` of them, as many as a part of what this lobe holds at most where it names none, and never more.\",\n kind: 'reading',\n args: Scheduler.#object({ cursor: Scheduler.#cursor, limit: { type: 'integer', minimum: 1 } }, []),\n result: Scheduler.#object(\n {\n alarms: {\n type: 'array',\n items: Scheduler.#object(\n {\n id: Scheduler.#count,\n at: Scheduler.#count,\n method: { type: 'string' },\n args: {},\n },\n ['id', 'at', 'method', 'args'],\n ),\n },\n cursor: Scheduler.#cursor,\n },\n ['alarms', 'cursor'],\n ),\n errors: ['refused'],\n },\n now: {\n description: 'The time, on the wall clock, for a lobe deep in a long ask.',\n kind: 'reading',\n result: { type: 'number' },\n },\n wake: {\n askers: ['brain'],\n args: Scheduler.#object({}, []),\n description:\n \"The brain's alone, when its wake is due: ends every alarm due and posts its ring, a letter to its lobe, in this answer's batch, and waits on no lobe. One whose lobe is torn down ends unrung. Then it asks the brain the next wake.\",\n kind: 'writing',\n result: { type: 'null' },\n },\n },\n placeholders: { brain: 'nervur.brain', cage: 'nervur.cage' },\n };\n\n static #lives = Math.floor(Number.MAX_SAFE_INTEGER / 2);\n\n static #rings = 20;\n\n #page() {\n return Math.min(1000, Math.floor(this.memory / 4 / 1024));\n }\n\n static #sent(value ) {\n if (value === undefined) return 'nothing';\n const read = JSON.stringify(value);\n return read.length > 64 ? `${read.slice(0, 63)}\u2026` : read;\n }\n\n static #isCount(value ) {\n return typeof value === 'number' && Number.isSafeInteger(value) && value >= 0;\n }\n\n static #ask(placeholder , method , args ) {\n return { placeholder, method, args };\n }\n\n #earliest(limit ) {\n return this.cells.range({ prefix: ['due'], limit }).cells.map(({ key }) => {\n const [, at, lobe, id] = key;\n if (typeof at !== 'number' || typeof lobe !== 'string' || typeof id !== 'number')\n throw new TypeError(`the row ${JSON.stringify(key)} is no alarm's`);\n const kept = this.cells.get(['alarm', lobe, id]);\n const method = Scheduler.field(kept, 'method');\n if (typeof method !== 'string') throw new TypeError(`the alarm ${id} of ${lobe} is not kept`);\n return { lobe, id, at, method, args: Scheduler.field(kept, 'args') ?? null };\n });\n }\n\n #holds(lobe ) {\n return this.cells.range({ prefix: ['alarm', lobe], limit: 1 }).cells.length > 0;\n }\n\n #remove(lobe , id , at ) {\n this.cells.delete(['alarm', lobe, id]);\n this.cells.delete(['due', at, lobe, id]);\n }\n\n #coming(asked ) {\n return Scheduler.#isCount(asked) && asked > this.stamp.time;\n }\n\n *#wakeAt(at ) {\n const asked = yield Scheduler.#ask('brain', 'wake', { at });\n if ('result' in asked) this.cells.set(['wake'], at);\n return asked;\n }\n\n *#unwire(lobe ) {\n yield Scheduler.#ask('nerves', 'unwire', { placeholder: lobe });\n return null;\n }\n\n *#ring(lobe , method , args ) {\n const ring = { ...Scheduler.#ask(lobe, method, args), letter: { lives: Scheduler.#lives } };\n const rang = yield ring;\n if (!('error' in rang) || rang.error.code !== 'unavailable') return rang;\n const ordered = yield Scheduler.#ask('nerves', 'order', { order: { termination: lobe } });\n return 'error' in ordered ? rang : yield ring;\n }\n\n *set(args ) {\n const { asker } = this.stamp;\n if (asker === 'brain')\n return this.error('refused', 'the scheduler keeps the alarms of lobes, and the brain is none');\n const at = Scheduler.field(args, 'at');\n const method = Scheduler.field(args, 'method');\n if (!Scheduler.#isCount(at))\n return this.error(\n 'refused',\n `at is a time on the wall clock, whole milliseconds from 0, not ${Scheduler.#sent(at)}`,\n );\n if (typeof method !== 'string' || method === '')\n return this.error('refused', `method is the name of one of your methods, not ${Scheduler.#sent(method)}`);\n if (!this.#holds(asker)) {\n const ordered = yield Scheduler.#ask('nerves', 'order', {\n order: { termination: asker },\n });\n if ('error' in ordered) return this.error(ordered.error.code, ordered.error.message);\n }\n const next = this.cells.get(['next']);\n const id = (Scheduler.#isCount(next) ? next : 0) + 1;\n this.cells.set(['next'], id);\n const given = Scheduler.field(args, 'args');\n this.cells.set(['alarm', asker, id], { at, method, args: given === undefined ? {} : given });\n this.cells.set(['due', at, asker, id], null);\n const asked = this.cells.get(['wake']);\n if (this.#coming(asked) && asked <= at) return { id };\n const woken = yield* this.#wakeAt(this.#earliest(1)[0]?.at ?? at);\n return 'error' in woken ? this.error(woken.error.code, woken.error.message) : { id };\n }\n\n *cancel(args ) {\n const { asker } = this.stamp;\n const lobe = asker === 'brain' ? Scheduler.field(args, 'lobe') : asker;\n const id = Scheduler.field(args, 'id');\n if (typeof lobe !== 'string') return this.error('refused', 'an owner names the lobe whose alarm ends');\n const kept = Scheduler.#isCount(id) ? this.cells.get(['alarm', lobe, id]) : undefined;\n const at = Scheduler.field(kept, 'at');\n if (!Scheduler.#isCount(id) || !Scheduler.#isCount(at))\n return this.error('refused', `${lobe} holds no alarm ${JSON.stringify(id ?? null)}`);\n this.#remove(lobe, id, at);\n if (!this.#holds(lobe)) yield* this.#unwire(lobe);\n const first = this.#earliest(1)[0]?.at ?? null;\n const asked = this.cells.get(['wake']);\n if (!Scheduler.#isCount(asked) || (this.#coming(asked) && first !== null && first <= asked)) return null;\n const woken = yield* this.#wakeAt(first);\n return 'error' in woken ? this.error(woken.error.code, woken.error.message) : null;\n }\n\n list(args ) {\n const cursor = Scheduler.field(args, 'cursor') ?? null;\n const most = this.#page();\n const limit = Scheduler.field(args, 'limit') ?? most;\n if (cursor !== null && typeof cursor !== 'string')\n return this.error('refused', `a cursor is a text, or null, not ${Scheduler.#sent(cursor)}`);\n if (!Scheduler.#isCount(limit) || limit < 1 || limit > most)\n return this.error('refused', `a limit is a whole number from 1 to ${most}, not ${Scheduler.#sent(limit)}`);\n const prefix = ['alarm', this.stamp.asker];\n const page = this.cells.range({ prefix, limit, ...(cursor === null ? {} : { cursor }) });\n const alarms = page.cells.map(({ key, value }) => ({\n id: key[2] ?? null,\n at: Scheduler.field(value, 'at') ?? null,\n method: Scheduler.field(value, 'method') ?? null,\n args: Scheduler.field(value, 'args') ?? null,\n }));\n return { alarms, cursor: page.cursor };\n }\n\n now() {\n return this.stamp.time;\n }\n\n *wake() {\n const now = this.stamp.time;\n const due = this.#earliest(Scheduler.#rings + 1).filter((alarm) => alarm.at <= now);\n const ringing = due.slice(0, Scheduler.#rings);\n const touched = new Set ();\n for (const { lobe, id, at, method, args } of ringing) {\n const rang = yield* this.#ring(lobe, method, args);\n if ('error' in rang && rang.error.code !== 'unavailable') continue;\n this.#remove(lobe, id, at);\n touched.add(lobe);\n }\n for (const lobe of touched) if (!this.#holds(lobe)) yield* this.#unwire(lobe);\n const later = this.#earliest(Scheduler.#rings + 1).find((alarm) => alarm.at > now);\n const times = [...(due.length > ringing.length ? [now] : []), ...(later === undefined ? [] : [later.at])];\n yield* this.#wakeAt(times.length === 0 ? null : Math.min(...times));\n return null;\n }\n}";
5977
+ var SCHEDULER_TEXT = "class Scheduler extends Faculty {\n static #count = { type: 'integer', minimum: 0 };\n\n static #cursor = { anyOf: [{ type: 'string' }, { type: 'null' }] };\n\n static #object(properties , required ) {\n return { type: 'object', properties, required, additionalProperties: false };\n }\n\n static blueprint = {\n name: 'nervur.scheduler',\n version: '0.37.12',\n description: \"The scheduler: every lobe's alarms, over the brain's one durable wake.\",\n methods: {\n set: {\n description:\n \"Keeps an alarm of the asker's: when, on the wall clock, which of its methods to ring, and its args. Answers the alarm's ID.\",\n kind: 'writing',\n args: Scheduler.#object({ at: Scheduler.#count, method: { type: 'string', minLength: 1 }, args: {} }, [\n 'at',\n 'method',\n ]),\n result: Scheduler.#object({ id: Scheduler.#count }, ['id']),\n errors: ['refused'],\n },\n cancel: {\n description:\n \"Removes an alarm of the asker's, by its ID; asked by the brain for an owner, an alarm of the lobe it names.\",\n kind: 'writing',\n args: Scheduler.#object({ id: Scheduler.#count, lobe: { type: 'string', minLength: 1 } }, ['id']),\n result: { type: 'null' },\n errors: ['refused'],\n },\n list: {\n description:\n \"The asker's own alarms, never another lobe's, a page at a time: `limit` of them, as many as a part of what this lobe holds at most where it names none, and never more.\",\n kind: 'reading',\n args: Scheduler.#object({ cursor: Scheduler.#cursor, limit: { type: 'integer', minimum: 1 } }, []),\n result: Scheduler.#object(\n {\n alarms: {\n type: 'array',\n items: Scheduler.#object(\n {\n id: Scheduler.#count,\n at: Scheduler.#count,\n method: { type: 'string' },\n args: {},\n },\n ['id', 'at', 'method', 'args'],\n ),\n },\n cursor: Scheduler.#cursor,\n },\n ['alarms', 'cursor'],\n ),\n errors: ['refused'],\n },\n now: {\n description: 'The time, on the wall clock, for a lobe deep in a long ask.',\n kind: 'reading',\n result: { type: 'number' },\n },\n wake: {\n askers: ['brain'],\n args: Scheduler.#object({}, []),\n description:\n \"The brain's alone, when its wake is due: ends every alarm due and posts its ring, a letter to its lobe, in this answer's batch, and waits on no lobe. One whose lobe is torn down ends unrung. Then it asks the brain the next wake.\",\n kind: 'writing',\n result: { type: 'null' },\n },\n },\n placeholders: { brain: 'nervur.brain', cage: 'nervur.cage' },\n };\n\n static #lives = Math.floor(Number.MAX_SAFE_INTEGER / 2);\n\n static #rings = 20;\n\n #page() {\n return Math.min(1000, Math.floor(this.memory / 4 / 1024));\n }\n\n static #sent(value ) {\n if (value === undefined) return 'nothing';\n const read = JSON.stringify(value);\n return read.length > 64 ? `${read.slice(0, 63)}\u2026` : read;\n }\n\n static #isCount(value ) {\n return typeof value === 'number' && Number.isSafeInteger(value) && value >= 0;\n }\n\n static #ask(placeholder , method , args ) {\n return { placeholder, method, args };\n }\n\n #earliest(limit ) {\n return this.cells.range({ prefix: ['due'], limit }).cells.map(({ key }) => {\n const [, at, lobe, id] = key;\n if (typeof at !== 'number' || typeof lobe !== 'string' || typeof id !== 'number')\n throw new TypeError(`the row ${JSON.stringify(key)} is no alarm's`);\n const kept = this.cells.get(['alarm', lobe, id]);\n const method = Scheduler.field(kept, 'method');\n if (typeof method !== 'string') throw new TypeError(`the alarm ${id} of ${lobe} is not kept`);\n return { lobe, id, at, method, args: Scheduler.field(kept, 'args') ?? null };\n });\n }\n\n #holds(lobe ) {\n return this.cells.range({ prefix: ['alarm', lobe], limit: 1 }).cells.length > 0;\n }\n\n #remove(lobe , id , at ) {\n this.cells.delete(['alarm', lobe, id]);\n this.cells.delete(['due', at, lobe, id]);\n }\n\n #coming(asked ) {\n return Scheduler.#isCount(asked) && asked > this.stamp.time;\n }\n\n *#wakeAt(at ) {\n const asked = yield Scheduler.#ask('brain', 'wake', { at });\n if ('result' in asked) this.cells.set(['wake'], at);\n return asked;\n }\n\n *#unwire(lobe ) {\n yield Scheduler.#ask('nerves', 'unwire', { placeholder: lobe });\n return null;\n }\n\n *#ring(lobe , method , args ) {\n const ring = { ...Scheduler.#ask(lobe, method, args), letter: { lives: Scheduler.#lives } };\n const rang = yield ring;\n if (!('error' in rang) || rang.error.code !== 'unavailable') return rang;\n const ordered = yield Scheduler.#ask('nerves', 'order', { order: { termination: lobe } });\n return 'error' in ordered ? rang : yield ring;\n }\n\n *set(args ) {\n const { asker } = this.stamp;\n if (asker === 'brain')\n return this.error('refused', 'the scheduler keeps the alarms of lobes, and the brain is none');\n const at = Scheduler.field(args, 'at');\n const method = Scheduler.field(args, 'method');\n if (!Scheduler.#isCount(at))\n return this.error(\n 'refused',\n `at is a time on the wall clock, whole milliseconds from 0, not ${Scheduler.#sent(at)}`,\n );\n if (typeof method !== 'string' || method === '')\n return this.error('refused', `method is the name of one of your methods, not ${Scheduler.#sent(method)}`);\n if (!this.#holds(asker)) {\n const ordered = yield Scheduler.#ask('nerves', 'order', {\n order: { termination: asker },\n });\n if ('error' in ordered) return this.error(ordered.error.code, ordered.error.message);\n }\n const next = this.cells.get(['next']);\n const id = (Scheduler.#isCount(next) ? next : 0) + 1;\n this.cells.set(['next'], id);\n const given = Scheduler.field(args, 'args');\n this.cells.set(['alarm', asker, id], { at, method, args: given === undefined ? {} : given });\n this.cells.set(['due', at, asker, id], null);\n const asked = this.cells.get(['wake']);\n if (this.#coming(asked) && asked <= at) return { id };\n const woken = yield* this.#wakeAt(this.#earliest(1)[0]?.at ?? at);\n return 'error' in woken ? this.error(woken.error.code, woken.error.message) : { id };\n }\n\n *cancel(args ) {\n const { asker } = this.stamp;\n const lobe = asker === 'brain' ? Scheduler.field(args, 'lobe') : asker;\n const id = Scheduler.field(args, 'id');\n if (typeof lobe !== 'string') return this.error('refused', 'an owner names the lobe whose alarm ends');\n const kept = Scheduler.#isCount(id) ? this.cells.get(['alarm', lobe, id]) : undefined;\n const at = Scheduler.field(kept, 'at');\n if (!Scheduler.#isCount(id) || !Scheduler.#isCount(at))\n return this.error('refused', `${lobe} holds no alarm ${JSON.stringify(id ?? null)}`);\n this.#remove(lobe, id, at);\n if (!this.#holds(lobe)) yield* this.#unwire(lobe);\n const first = this.#earliest(1)[0]?.at ?? null;\n const asked = this.cells.get(['wake']);\n if (!Scheduler.#isCount(asked) || (this.#coming(asked) && first !== null && first <= asked)) return null;\n const woken = yield* this.#wakeAt(first);\n return 'error' in woken ? this.error(woken.error.code, woken.error.message) : null;\n }\n\n list(args ) {\n const cursor = Scheduler.field(args, 'cursor') ?? null;\n const most = this.#page();\n const limit = Scheduler.field(args, 'limit') ?? most;\n if (cursor !== null && typeof cursor !== 'string')\n return this.error('refused', `a cursor is a text, or null, not ${Scheduler.#sent(cursor)}`);\n if (!Scheduler.#isCount(limit) || limit < 1 || limit > most)\n return this.error('refused', `a limit is a whole number from 1 to ${most}, not ${Scheduler.#sent(limit)}`);\n const prefix = ['alarm', this.stamp.asker];\n const page = this.cells.range({ prefix, limit, ...(cursor === null ? {} : { cursor }) });\n const alarms = page.cells.map(({ key, value }) => ({\n id: key[2] ?? null,\n at: Scheduler.field(value, 'at') ?? null,\n method: Scheduler.field(value, 'method') ?? null,\n args: Scheduler.field(value, 'args') ?? null,\n }));\n return { alarms, cursor: page.cursor };\n }\n\n now() {\n return this.stamp.time;\n }\n\n *wake() {\n const now = this.stamp.time;\n const due = this.#earliest(Scheduler.#rings + 1).filter((alarm) => alarm.at <= now);\n const ringing = due.slice(0, Scheduler.#rings);\n const touched = new Set ();\n for (const { lobe, id, at, method, args } of ringing) {\n const rang = yield* this.#ring(lobe, method, args);\n if ('error' in rang && rang.error.code !== 'unavailable') continue;\n this.#remove(lobe, id, at);\n touched.add(lobe);\n }\n for (const lobe of touched) if (!this.#holds(lobe)) yield* this.#unwire(lobe);\n const later = this.#earliest(Scheduler.#rings + 1).find((alarm) => alarm.at > now);\n const times = [...(due.length > ringing.length ? [now] : []), ...(later === undefined ? [] : [later.at])];\n yield* this.#wakeAt(times.length === 0 ? null : Math.min(...times));\n return null;\n }\n}";
5978
5978
 
5979
5979
  var SCHEDULER_SOURCE = facultySource(SCHEDULER_TEXT);
5980
5980
 
@@ -25021,7 +25021,7 @@ var genomeIn = (cells) => {
25021
25021
  return found;
25022
25022
  };
25023
25023
  var layGenome = (cells) => putRow(cells, ROW4, GENOME_VERSION, "brain");
25024
- var FLOOR = "0.37.2";
25024
+ var FLOOR = "0.37.11";
25025
25025
  var BELOW_FLOOR = "below the floor";
25026
25026
  var keepGenome = (cells) => {
25027
25027
  const kept3 = genomeIn(cells);
@@ -27509,7 +27509,7 @@ var FLOOR_FILES = [
27509
27509
  "design.json",
27510
27510
  `{
27511
27511
  "name": "floor",
27512
- "version": "0.37.11",
27512
+ "version": "0.37.12",
27513
27513
  "publisher": "nervur",
27514
27514
  "description": "The genome's one design: plain, clean and accessible, host-agnostic, given away with the packages. Its look is the describe look.",
27515
27515
  "languages": [
@@ -27642,7 +27642,7 @@ var FLOOR_FILES = [
27642
27642
 
27643
27643
  var FLOOR_LOOK_SOURCE = `import { Faculty } from 'nervur:faculty';
27644
27644
  export default class FloorLook extends Faculty {
27645
- static #identity = {"design":"floor","name":"nervur.floor-look","version":"0.37.11","description":"The genome's one design: plain, clean and accessible, host-agnostic, given away with the packages. Its look is the describe look.","components":["lobe","organism","surround"],"tints":["blue"],"densities":["compact","regular","roomy"]};
27645
+ static #identity = {"design":"floor","name":"nervur.floor-look","version":"0.37.12","description":"The genome's one design: plain, clean and accessible, host-agnostic, given away with the packages. Its look is the describe look.","components":["lobe","organism","surround"],"tints":["blue"],"densities":["compact","regular","roomy"]};
27646
27646
  static #components = (() => {
27647
27647
  const $m = {};
27648
27648
  $m["_tree.ts"] = (() => {
@@ -28107,8 +28107,8 @@ return { "lobe": $m["lobe.ts"].default, "organism": $m["organism.ts"].default, "
28107
28107
 
28108
28108
  static blueprint = {
28109
28109
  name: "nervur.floor-look",
28110
- version: "0.37.11",
28111
- assets: "e9ff5479b6724f7b5803989330fae021c32047dbeb0c262ee86a258ee2331952",
28110
+ version: "0.37.12",
28111
+ assets: "d7763e7adec2f811ad7aecc692620253a7825cba712998c966c56ce4640d0ca7",
28112
28112
  ...FloorLook.#rest(),
28113
28113
  };
28114
28114
 
@@ -28729,7 +28729,7 @@ var FLOOR_DESIGN = {
28729
28729
  assets: FLOOR_FILES
28730
28730
  };
28731
28731
 
28732
- var WINDOW_SOURCE = 'var LOBE_SHARE = 4;\nvar LOBE_WAIT = 3500;\nvar NAME_WAIT = 1e3;\nvar DESCRIBING = 16;\nvar KEPT_ANSWER = 16384;\nvar KEPT_SHARE = 32;\nvar MOST_FACULTIES = 100;\nvar MOST_LISTED = 10;\nvar MOST_RELATIONS = 100;\nvar MOST_RELATION_PAGES = 20;\nvar STATE_SHARE = 256;\n\nimport { Faculty } from "nervur:faculty";\nvar Window = class _Window extends Faculty {\n #lang = "en";\n static #themed(given) {\n return given === "dark" ? "dark" : "light";\n }\n static #wayAt = "bottom-end";\n async #draws(asked) {\n return this.ask("design", "draw", { ...asked, lang: this.#lang });\n }\n static #langOf(given) {\n return typeof given === "string" ? given : "en";\n }\n #keptReads() {\n return Math.floor(this.memory / KEPT_SHARE / _Window.#keptAnswer);\n }\n #mostState() {\n return Math.floor(this.memory / KEPT_SHARE / STATE_SHARE);\n }\n #keptHalf() {\n return Math.floor(this.#keptReads() / 2);\n }\n static #organ = "screen";\n static #lobeWithin = LOBE_WAIT;\n static #nameWithin = NAME_WAIT;\n static #describing = DESCRIBING;\n static #keptAnswer = KEPT_ANSWER;\n static #mostFaculties = MOST_FACULTIES;\n static #unmadeKey = ["unmade"];\n static #aboutKey = ["about"];\n static #world = "network";\n static #mostListed = MOST_LISTED;\n static #mostRelations = MOST_RELATIONS;\n static #mostRelationPages = MOST_RELATION_PAGES;\n static #id = { type: "string", minLength: 1, maxLength: 64 };\n static #name = { type: "string", minLength: 1, maxLength: 200 };\n static #wires = { type: "object", additionalProperties: { type: "string" } };\n static #relation = { type: "string", pattern: "^[A-Za-z][A-Za-z0-9_-]{0,63}$", maxLength: 64 };\n static #own = ["screen", "brain", "design", "mouth", "ear", "cells", "nerves"];\n static #step = {\n anyOf: [\n {\n type: "object",\n properties: { relation: _Window.#relation },\n required: ["relation"],\n additionalProperties: false\n },\n { type: "object", properties: { lobe: _Window.#id }, required: ["lobe"], additionalProperties: false }\n ]\n };\n static #route = { type: "array", items: _Window.#step, maxItems: 2 };\n static #relationName = /^[A-Za-z][A-Za-z0-9_-]{0,63}$/u;\n static #theme = { enum: ["light", "dark"] };\n static #cursor = { anyOf: [{ type: "string", maxLength: 200 }, { type: "null" }] };\n static #cells = { anyOf: [{ type: "string", maxLength: 200 }, { type: "null" }] };\n static #digest = { type: "string", pattern: "^[0-9a-f]{64}$" };\n static #pressId = { type: "string", minLength: 1, maxLength: 64 };\n static #link = {\n type: "object",\n properties: {\n card: {\n type: "object",\n properties: {\n ward: { type: "string", pattern: "^[0-9a-f]{128}$" },\n at: { type: "array", items: { type: "string", minLength: 1 } }\n },\n required: ["ward", "at"],\n additionalProperties: false\n },\n reference: { type: "string", pattern: "^[a-z0-9]{1,64}$" }\n },\n required: ["card", "reference"],\n additionalProperties: false\n };\n static #span = { anyOf: [{ type: "integer", minimum: 0 }, { type: "null" }] };\n static #components = ["surround", "organism", "lobe"];\n static #chosen = ["chosen"];\n static #openWalk = "The person walks to a route: `route`, a path of at most a relation the window holds and a lobe, or `lobe` alone, the route `[{lobe}]` at home, `[]` the home. The screen shows it from now on.";\n static #openDescribe = "A walk to a route that reaches a lobe over a relation describes that lobe and keeps its describe in the cells (by the relation and the lobe, with the version it answers; a walk hears again the version that stands and keeps that one), and keeps what a far lobe answers its `state`, so a sight asks no describe.";\n static #openTold = "`told` `{size, language, standard}` is what the home tells a place of its screen: a far lobe the walk reaches that declares a writing method `told` is asked it with those three, the first time and again only where one moved.";\n static #seePage = "What the screen shows at a route (the one walked to where none is given): the page in the slot `main`, inside the home\'s surround, drawn by the design lobe the window wears, only where the home has something to say, a warning or a consent; else `tree` is the slot `main` alone. An organism\'s page holds its state, its lobes each as its describe says, and the relations the window holds at home, each with `place` where it is a far lobe; a lobe\'s (a far lobe\'s too, at `/<relation>`), its description, its state at once, the answers kept of its other reading methods, and its writing methods, unless the lobe draws itself, which then draws the page. Where any method of a lobe declares a seat for a person, only the methods whose seat is for a person or both are drawn, each with its seat\'s `label` in `args.lang`\'s words; a method whose seat is for a machine is never drawn. An ask the describe names and says nothing of (no `kind`) is among its writing methods, never read, kept or asked unpressed, and a lobe draws itself only by a `draw` it declares a reading. Over a relation the describe is the one the walk kept, asked again only by a walk. A far lobe tells no cells digest: an answer of its reading methods kept at a walk or by a `read` press is drawn by every sight and asked again only once a press that wrote landed or the person walked in again, the walk asking it once more and keeping it. Answers `{route, text, tree, main, version, design, way?, channel?}`: `main` names the lobe that draws the slot, over which relation, and with which args; `design` the design lobe the window wears, by which the host dresses the home. `args.cursor` is the place in a long list, `args.cells` the cells digest the screen holds of the lobe, `args.theme` the theme, `args.lang` the person\'s language, which every draw asked of the design carries as `lang`. The home\'s own words are English, whatever `args.lang` names; a seat\'s words are the place\'s, picked in `args.lang`. Where the last press of a place answered a file or an upload, the answer holds `channel`, the checked shape, for the host to follow.";\n static #seeLeave = "A place the window holds that is a far lobe is left by one press of the window\'s own, `leave {press, say}`, `press` `{method: \'leave\', args: {relation}}` and `say` the home\'s word: `see` answers it beside the way out as `way.leave`, in the region the host lays above the page outside every tree, and forces no surround. The surround is drawn while its consent is asked, as any consent is. A press `leave {relation}` on the lobe that drew the page is the window\'s own act, as `wear` is: unconsented, or carrying a consent the home\'s local state asks not for that relation, it sets the consent in the local state of the region `#consent`, which the surround then carries as `consent` whose `yes` is the same press with `consented: true`, and answers `{asking: \'leave\'}`; consented it ends the standing whole, by the brain\'s `drop` naming it, so no lobe keeps a place its person left, forgets what the window kept of it, walks the person home where the route stood on it, and answers `{left: relation}`. A relation that reaches a far organism is an owner\'s standing and is never left so: the press is refused.";\n static #seeHome = "At home the floor\'s page is the organism\'s describe page whole, titled and crumbed `Home`: its state, its organs, its lobes, its relations, the faculties the library keeps, of the first page of its `list`, and `about`. A far organism\'s page is its own, whole.";\n static #seeWay = "`way {at, say, leave?}` stands above every page but the home\'s own, for the host to lay outside every tree: `at` `bottom-end`, fixed in the window, `say` the way out home in the home\'s word, and `leave` a place\'s leave. Beside `way`, a window may hand `world {say, yes, no}`, the three words of the ask the screen puts above the page before a link of the world opens, in the language of its choice: `say` holds `{href}`, where the screen puts the address the link leads to; this window hands none, and the screen\'s English stands.";\n static #pressCarried = "A press, asked of the lobe that drew it, or of the lobe wired at its `to` among that lobe\'s placeholders, through the brain\'s `ask` or over `over`, with its `args` and of the `values` the person committed around it those its method declares in its args, by name, fitted as a form\'s are; a field it does not declare stays on the device. Answers what the lobe answered.";\n static #pressConsent = "The describe is read first (over a relation the one the walk kept, else asked; a press refused where none answers): a press on a method its describe declares `irreversible`, or, over a relation, on an ask the place says nothing of, asks nothing, sets the home\'s consent as `send` does with the args it carried, and answers `{method, asking: true}`; its `yes` is the declared ask.";\n static #pressKept = "A press over a far lobe on a method it declares no reading moves what was kept of its answers, asked again at the next sight.";\n static #pressAbout = "A press `about {faculty}` on the lobe that drew the home is the window\'s own act, as `create` is: the faculty the library keeps under that digest, before a lobe stands on it, answered and kept for the home\'s next page as `about {faculty, name, version, placeholders, skins, world}`, its placeholders each with what it expects, the organs of this organism it is a skin lobe of (each placeholder under an organ\'s fixed ID expecting that organ\'s blueprint name), and whether it talks to the world, a skin lobe of `network`; it shows and never locks, so `create` makes the lobe whether or not it was looked at. One the library keeps not is told as `create`\'s refusal is. The next walk or `create` forgets it.";\n static #sendMarked = "The second step: the press kept under `id` is marked sent, and the mark is committed by this ask\'s answer, before the ask of the lobe is made (by `deliver`), so a cut off ask never rolls it back to unsent. Answers `{method, sending: true}` once; a press already sent and not answered answers `{method, unknown: true}`, the outcome not known, and asks nothing; one answered answers what was kept. A yes sent takes the home\'s consent it answers, which stands drawn until its ask is answered: a yes that finds it taken answers `{method, taken: true}`, is kept no more and asks nothing.";\n static #sendDeclared = "A press on a method its describe declares `irreversible`, or on an ask its place names and says nothing of (its describe\'s entry names no `kind`, as a door of a kit that is no Nervur\'s describes every ask), is not sent: the home\'s consent is set in the local state of the region `#consent` (no method of a place is so named) where the route\'s surround reads it, `{asking, lobe, args, label?, irreversible?}`, `args` the values the press carried made to fit, and the surround is drawn with `consent {say, yes, no, yesSay, noSay}`, the home\'s words saying it cannot be undone, or that the place does not say what it does and that it may change something, `yes` the same ask (`ask`, with those args and `consented: true`), `no` clearing it; answers `{method, asking: true}` and nothing leaves. Only a press with that consent, while the home\'s own local state still asks it, is sent (a `local` press never sets it), and the consent is spent with the ask.";\n static #offerRead = "What a link offers, read before its reference is spent: the mouth\'s `once` asks `#offer` of the card\'s ward on its zero head, which spends nothing, and what is answered is `{says, waits, lives}`, what the invitation says (null for nothing) as the place\'s own word, the milliseconds left of its wait and those its relation lives, each null for none, the screen\'s to show in the consent; `{reached: false}` where the place was not reached or no reply came in time, nothing else in it, for the consent to say so before the yes; null where the place answered and gave no offer, a place of another kit among them, which still redeems: the consent is drawn without an offer.";\n static #offerRefused = "Only the screen asks it; it refuses only a link that names no card and reference.";\n static #acceptTaken = "The person\'s consent: the mouth accepts `invitation` under the placeholder `placeholder`, with `note` (kept by the brain beside the standing, never sent to the inviter; null where none), and the first ask over it is the knock, a describe; one never answered is ended whole, by the brain\'s `drop`, and refused; the describe the knock of a far lobe heard is kept as a walk keeps it.";\n static #acceptRefused = "Refused for one of the window\'s own placeholders (`screen`, `brain`, `design`, `mouth`) and one it holds already. Only the screen asks it.";\n static #acceptKnock = "Everything the window kept of a relation of that name before is forgotten first, so the new standing reads nothing of the last. A knock that answers a blueprint other than `nervur.brain` makes the relation a far lobe, kept in the cells until the window is asked `left` of it. Answers `{far, route, text}`: the organism or lobe now held, and the route and text that reach it at once.";\n static blueprint = {\n name: "nervur.window",\n version: "0.35.14",\n description: "The screen\'s present lobe: it keeps the route the person walked, draws the organism or the lobe at its end by the describe look of the design lobe it wears, inside the home\'s surround where the home has something to say, asks each lobe the screen draws its draw through the brain\'s `ask`, or through the far brain\'s over a relation it holds, and, over a relation that reaches a far lobe, directly over the placeholder, and carries each press: a press that reads keeps its answer, one that writes is kept before it leaves and asked once, one that binds the person waits for their yes. Presence is one person: it holds the relations its owners hold, wired under the placeholders the console holds them by, and its `design` is wired to the design lobe that dresses what it draws.",\n methods: {\n open: {\n description: [_Window.#openWalk, _Window.#openDescribe, _Window.#openTold].join(" "),\n kind: "writing",\n args: {\n type: "object",\n properties: {\n route: _Window.#route,\n lobe: _Window.#id,\n told: {\n type: "object",\n properties: {\n size: { enum: ["compact", "medium", "expanded"] },\n language: { type: "string", maxLength: 35 },\n standard: { type: "string", maxLength: 35 }\n },\n required: ["size", "language", "standard"],\n additionalProperties: false\n }\n },\n additionalProperties: false\n },\n result: _Window.#routed(),\n errors: ["refused"]\n },\n root: {\n description: "The route the person walked to, `[]` where they walked nowhere, the home, and its text.",\n kind: "reading",\n args: { type: "object", properties: {}, additionalProperties: false },\n result: _Window.#routed(),\n errors: ["refused"]\n },\n see: {\n description: [_Window.#seePage, _Window.#seeLeave, _Window.#seeHome, _Window.#seeWay].join(" "),\n kind: "reading",\n args: {\n type: "object",\n properties: {\n route: _Window.#route,\n args: {\n type: "object",\n properties: {\n cursor: _Window.#cursor,\n cells: _Window.#cells,\n theme: _Window.#theme,\n lang: { type: "string", pattern: "^[A-Za-z]{2,3}(-[A-Za-z0-9]{2,8})*$", maxLength: 35 }\n },\n additionalProperties: false\n }\n },\n additionalProperties: false\n },\n errors: ["refused"]\n },\n show: {\n description: "A lobe\'s draw, its args what its parent\'s slot gives it, asked through the brain\'s `ask`, or the far brain\'s over `over`: its tree, and the lobe wired at each of its placeholders, where the screen draws its slots. A draw\'s error is answered as heard.",\n kind: "reading",\n args: {\n type: "object",\n properties: { lobe: _Window.#id, args: {}, over: _Window.#relation },\n required: ["lobe", "args"],\n additionalProperties: false\n },\n result: {\n type: "object",\n properties: { tree: {}, wires: _Window.#wires },\n required: ["tree", "wires"],\n additionalProperties: false\n },\n errors: ["refused"]\n },\n press: {\n description: [_Window.#pressCarried, _Window.#pressConsent, _Window.#pressKept, _Window.#pressAbout].join(" "),\n kind: "writing",\n args: {\n type: "object",\n properties: {\n lobe: _Window.#id,\n method: _Window.#name,\n args: {},\n values: { type: "object" },\n to: _Window.#id,\n over: _Window.#relation\n },\n required: ["lobe", "method", "args"],\n additionalProperties: false\n },\n errors: ["refused"]\n },\n read: {\n description: "The press the look draws on a reading method: the lobe at `path`, a route\'s text, is asked the method, which must be one it declares a reading (an ask a door says nothing of is none), the describe over a relation the one its walk kept, with `values`, the fields the person filled of its args (none where it takes none), and its answer or error is kept in the cells under the lobe, the method and `cells`, the cells digest the screen holds of the lobe, with the values it was asked with, so each `see` shows it and asks again, with the same values, only once the cells moved. Answers whether an answer or an error was kept.",\n kind: "writing",\n args: {\n type: "object",\n properties: {\n path: { type: "string", maxLength: 300 },\n method: _Window.#name,\n cells: _Window.#cells,\n values: { type: "object" }\n },\n required: ["path", "method"],\n additionalProperties: false\n },\n errors: ["refused"]\n },\n write: {\n description: "The first half of the press the look draws on a writing method: it keeps the press in the cells, under `id`, naming the lobe at `path`, the method, the `values` the screen collected and `seen`, the version of the lobe the screen showed, before anything leaves. A press kept under an `id` is kept once. Answers the `id`.",\n kind: "writing",\n args: {\n type: "object",\n properties: {\n id: _Window.#pressId,\n path: { type: "string", maxLength: 300 },\n method: _Window.#name,\n values: { type: "object" },\n seen: { anyOf: [{ type: "string", maxLength: 200 }, { type: "null" }] },\n declared: { type: "boolean" },\n consented: { type: "boolean" }\n },\n required: ["id", "path", "method", "values", "seen"],\n additionalProperties: false\n },\n errors: ["refused"]\n },\n local: {\n description: "A change of the local state of a region of the page at the route walked: `state` is merged into the state the window keeps for `region` (a key set to null is dropped), bounded in size and keys, kept while the route stands and forgotten at the next walk; no lobe and no place hears it. `field` names the key of `state` that holds text a person typed, kept as any other. The region `#consent` is the home\u2019s: a `local` press may only clear it.",\n kind: "writing",\n args: {\n type: "object",\n properties: {\n region: { type: "string", minLength: 1, maxLength: 64 },\n state: { type: "object" },\n field: _Window.#name\n },\n required: ["region", "state"],\n additionalProperties: false\n },\n errors: ["refused"]\n },\n send: {\n description: [_Window.#sendMarked, _Window.#sendDeclared].join(" "),\n kind: "writing",\n args: {\n type: "object",\n properties: { id: _Window.#pressId },\n required: ["id"],\n additionalProperties: false\n },\n errors: ["refused"]\n },\n deliver: {\n description: "The third step, posted once after `send` answered `sending`: the lobe is described (over a relation, by the describe its walk kept, so the press reaches the place as its one ask) and asked the writing method once, a method that binds the person only with the consent `send` asked, if it still stands at the version seen (else `stale`, with the version that stands), and what it answered is kept beside the press, shown on the next `see` of that lobe. A press is kept with the standing it was made under: one whose standing ended while it was in flight is forgotten and its answer kept nowhere, so a place given again under that name never reads it. Cut off, it leaves the press sent with the outcome unknown, and nothing asks again.",\n kind: "writing",\n args: {\n type: "object",\n properties: { id: _Window.#pressId },\n required: ["id"],\n additionalProperties: false\n },\n errors: ["refused"]\n },\n piece: {\n description: "Asked by the host for a piece of a file the place\'s own lobe holds, which a press answered and the host has not told: `at` the byte it starts at, below the file\'s size. The lobe is asked its reading method `piece` with `{sha256, at, length}`, `length` the file\'s bytes left from `at` and at most a share of the window\'s memory, and the piece is answered as those bytes; a piece that is not exactly that many bytes, or that the lobe refuses, is refused in words, none handed on. A press that answered no such file, or one told already, is refused, and the lobe is asked nothing.",\n kind: "reading",\n args: {\n type: "object",\n properties: { id: _Window.#pressId, at: { type: "integer", minimum: 0 } },\n required: ["id", "at"],\n additionalProperties: false\n },\n errors: ["refused"]\n },\n landed: {\n description: "Posted by the host once it sent the file of an upload a press answered, or refused to, or refused a file it fetched for the page: `landed` whether it landed, `why` the words of a refusal. The press is marked told, so `see` hands the channel on no more and it is followed once; for an upload the lobe is asked `landed` with `{sha256, landed}`, never a byte; a file that did not land, either way, is kept as the press\'s refusal, said in words. Answers `{landed}`, for an upload with what the lobe answered; a press that answered no file or upload, or one told already, is refused.",\n kind: "writing",\n args: {\n type: "object",\n properties: {\n id: _Window.#pressId,\n landed: { type: "boolean" },\n why: { type: "string", maxLength: 300 }\n },\n required: ["id", "landed"],\n additionalProperties: false\n },\n errors: ["refused"]\n },\n worn: {\n description: "The design the window wears, for the screen to lay: the lobe wired at `design` is asked its `files`, and what it answered is answered, the design\u2019s parts with the lobe\u2019s settings laid over them; an error is answered as heard.",\n kind: "reading",\n args: { type: "object", properties: {}, additionalProperties: false },\n errors: ["refused"]\n },\n wear: {\n description: "An owner\'s word through the brain\'s `ask`, or the screen\'s: the window wears the design whose look has the faculty digest `design`, one the library keeps (refused where its look draws not `surround`, `organism` and `lobe`, or where a sheet of it loads outside its bundle): it finds a lobe on that look, or has the brain make one, and orders its own wire `design` to that lobe, which only the window orders; answers `{design, lobe}`, and changes nothing where that design is worn already. A design it cannot wear is told as `create`\'s refusal is: the answer `{refused: why}`, nothing changed, the why kept for the home\'s next page. A press `{method: \'wear\', args: {design}}` on the lobe wired at `design` is this ask; the floor\'s design draws none.",\n kind: "writing",\n askers: ["screen", "brain"],\n args: {\n type: "object",\n properties: { design: _Window.#digest },\n required: ["design"],\n additionalProperties: false\n },\n errors: ["refused"]\n },\n back: {\n description: "The brain\'s alone: where the placeholder that came back is `screen`, the window lays the design its port gave it by the name `design`: where its `design` is wired to nothing it creates its own child on that look, sealed, wires `design` to it and sets the tint the port named; where its own child stands on another digest it moves the child to the port\'s, unless the person chose another design. A connect that finds the design as it should be changes nothing.",\n kind: "writing",\n askers: ["brain"],\n args: {\n type: "object",\n properties: { placeholder: { type: "string", minLength: 1 } },\n additionalProperties: true\n },\n errors: ["refused"]\n },\n redeem: {\n description: "The link a person opened, `card` and `reference`, redeemed once: the mouth\'s `once` asks `#redeem` of the card\'s ward on its zero head, and what is answered is `{invitation}`, the invitation the reply\'s object is, the screen\'s to show for consent. Every failure is answered `refused`, in words that say whether to try again: a far side not reached, the link unspent; a reply that came not in time, the link maybe spent; silence, or an answer that is no invitation, the link spent, ended or wrong. Only the screen asks it.",\n kind: "writing",\n args: _Window.#link,\n result: {\n type: "object",\n properties: { invitation: { type: "string", minLength: 1 } },\n required: ["invitation"],\n additionalProperties: false\n },\n errors: ["refused"]\n },\n offer: {\n description: [_Window.#offerRead, _Window.#offerRefused].join(" "),\n kind: "reading",\n args: _Window.#link,\n result: {\n anyOf: [\n {\n type: "object",\n properties: {\n says: {},\n waits: _Window.#span,\n lives: _Window.#span\n },\n required: ["says", "waits", "lives"],\n additionalProperties: false\n },\n {\n type: "object",\n properties: { reached: { const: false } },\n required: ["reached"],\n additionalProperties: false\n },\n { type: "null" }\n ]\n },\n errors: ["refused"]\n },\n standings: {\n description: "Its screen\'s alone. The relations the window holds, read of its nerves and their notes, drawing nothing and asking no far organism: `{relations}`, each its `placeholder`, its `note` and `place` where it is a place, so a page of a site finds the standing it gave.",\n kind: "reading",\n args: { type: "object", properties: {}, additionalProperties: false },\n result: {\n type: "object",\n properties: {\n relations: {\n type: "array",\n items: {\n type: "object",\n properties: { placeholder: { type: "string" }, note: {}, place: { const: true } },\n required: ["placeholder", "note"],\n additionalProperties: false\n }\n }\n },\n required: ["relations"],\n additionalProperties: false\n },\n errors: ["refused"]\n },\n left: {\n description: "The brain\u2019s alone: the standing of `far` ended; everything the window kept of the relation it was held at is forgotten, its far lobe or far organism, their describes, reads, presses and answers and local state; nothing else is asked or written.",\n kind: "writing",\n askers: ["brain"],\n args: {\n type: "object",\n properties: { far: { type: "string", minLength: 1 }, note: {} },\n required: ["far"],\n additionalProperties: false\n },\n result: { type: "null" }\n },\n accept: {\n description: [_Window.#acceptTaken, _Window.#acceptRefused, _Window.#acceptKnock].join(" "),\n kind: "writing",\n args: {\n type: "object",\n properties: {\n invitation: { type: "string", minLength: 1 },\n placeholder: _Window.#relation,\n note: {}\n },\n required: ["invitation", "placeholder"],\n additionalProperties: false\n },\n result: {\n type: "object",\n properties: {\n far: { type: "string", minLength: 1 },\n route: _Window.#route,\n text: { type: "string", maxLength: 300 }\n },\n required: ["far", "route", "text"],\n additionalProperties: false\n },\n errors: ["refused"]\n }\n },\n placeholders: {\n screen: "nervur.screen",\n brain: "nervur.brain",\n design: null,\n mouth: "nervur.mouth",\n ear: "nervur.ear"\n }\n };\n static #routed() {\n return {\n type: "object",\n properties: { route: _Window.#route, text: { type: "string", maxLength: 300 } },\n required: ["route", "text"],\n additionalProperties: false\n };\n }\n static #fields(data) {\n return typeof data === "object" && data !== null && !Array.isArray(data) && !(data instanceof Uint8Array);\n }\n static #at(data, key) {\n return _Window.#fields(data) ? data[key] : void 0;\n }\n #foreign() {\n return this.stamp.asker === _Window.#organ ? null : this.error("refused", "only the screen opens, draws and presses");\n }\n static #over(args) {\n const over = _Window.#at(args, "over");\n if (over === void 0 || over === null) return null;\n return typeof over === "string" && !_Window.#own.includes(over) ? over : void 0;\n }\n #farLobe(over) {\n return over !== null && _Window.#fields(this.cells.get(["far-lobe", over]));\n }\n async #through(over, lobe, method, args) {\n if (over !== null && this.#farLobe(over)) {\n const heard = await this.ask(over, method, args, _Window.#lobeWithin);\n if ("error" in heard && heard.error.code === "removed") await this.#ended(over);\n return method === null ? _Window.#blueprintOf(heard) : heard;\n }\n const asked = { lobe, method, args, timeout: _Window.#lobeWithin };\n return this.ask(over ?? "brain", "ask", asked, _Window.#lobeWithin);\n }\n async #ended(over) {\n const far = _Window.#at(this.cells.get(["far-lobe", over]), "far");\n if (typeof far === "string" && far !== "") await this.#ends(far);\n }\n async #ends(far) {\n return this.ask("brain", "drop", { far });\n }\n static #blueprintOf(heard) {\n if (!("result" in heard)) return heard;\n const asks = _Window.#at(heard.result, "asks");\n if (!Array.isArray(asks) || !_Window.#fields(heard.result)) return heard;\n const { asks: _, lang: __, ...about } = heard.result;\n const methods = {};\n for (const one of asks) {\n const method = _Window.#at(one, "method");\n if (typeof method !== "string" || !_Window.#fields(one)) continue;\n const { method: ___, ...entry } = one;\n methods[method] = entry;\n }\n return { result: { ...about, methods } };\n }\n static #lobeName(lobe) {\n return lobe.length >= 1 && lobe.length <= 64 && Array.from(lobe).every((one) => one.charCodeAt(0) > 31 && one.charCodeAt(0) !== 127);\n }\n static #routeOf(value) {\n if (!Array.isArray(value) || value.length > 2) return void 0;\n const steps = [];\n for (const step of value) {\n const relation = _Window.#at(step, "relation");\n const lobe = _Window.#at(step, "lobe");\n if (typeof relation === "string" && lobe === void 0 && _Window.#relationName.test(relation) && !_Window.#own.includes(relation))\n steps.push({ relation });\n else if (typeof lobe === "string" && relation === void 0 && _Window.#lobeName(lobe)) steps.push({ lobe });\n else return void 0;\n }\n const [first, second] = steps;\n if (second !== void 0 && (first === void 0 || !("relation" in first) || !("lobe" in second)))\n return void 0;\n return steps;\n }\n static #segment(id) {\n return encodeURIComponent(id).replaceAll(/[!\'()*]/gu, (one) => `%${one.charCodeAt(0).toString(16).toUpperCase()}`);\n }\n static #text(route) {\n const [first, second] = route;\n const relation = _Window.#at(first, "relation");\n const lobe = _Window.#at(second, "lobe") ?? _Window.#at(first, "lobe");\n if (typeof lobe !== "string") return typeof relation === "string" ? `/${relation}` : "/";\n return typeof relation === "string" ? `/${relation}/${_Window.#segment(lobe)}` : `/~/${_Window.#segment(lobe)}`;\n }\n static #read(text) {\n if (typeof text !== "string" || !text.startsWith("/")) return void 0;\n if (text === "/") return [];\n const [first = "", second, ...rest] = text.slice(1).split("/");\n if (rest.length > 0) return void 0;\n let step;\n if (second !== void 0) {\n let lobe;\n try {\n lobe = decodeURIComponent(second);\n } catch {\n return void 0;\n }\n if (_Window.#segment(lobe) !== second) return void 0;\n step = { lobe };\n }\n const route = _Window.#routeOf(\n first === "~" ? step !== void 0 && "lobe" in step ? [step] : void 0 : step === void 0 ? [{ relation: first }] : [{ relation: first }, step]\n );\n return route !== void 0 && _Window.#text(route) === text ? route : void 0;\n }\n static #relationOf(route) {\n const relation = _Window.#at(route[0], "relation");\n return typeof relation === "string" ? relation : null;\n }\n static #lobeOf(route) {\n const lobe = _Window.#at(route.at(-1), "lobe");\n return typeof lobe === "string" ? lobe : null;\n }\n #lobeOfFarLobe(route) {\n return _Window.#lobeOf(route) !== null && this.#farLobe(_Window.#relationOf(route));\n }\n #walked() {\n return _Window.#routeOf(this.cells.get(["root"])) ?? [];\n }\n async open(args) {\n const foreign = this.#foreign();\n if (foreign !== null) return foreign;\n const [given, lobe] = [_Window.#at(args, "route"), _Window.#at(args, "lobe")];\n if (given === void 0 === (lobe === void 0)) return this.error("refused", "open names a route, or a lobe");\n const route = _Window.#routeOf(given === void 0 ? [{ lobe: lobe ?? null }] : given);\n if (route === void 0)\n return this.error("refused", "open names no route: a relation the window holds and a lobe");\n if (route.length === 0 || _Window.#relationOf(route) !== null) await this.#learn(route);\n if (this.#lobeOfFarLobe(route)) return this.error("refused", "a far lobe has no lobes");\n if (JSON.stringify(route) !== JSON.stringify(this.#walked())) this.#forgetLocals();\n this.cells.delete(_Window.#unmadeKey);\n this.cells.delete(_Window.#aboutKey);\n this.cells.set(["root"], route);\n await this.#walkDescribed(route);\n await this.#tell(route, _Window.#at(args, "told"));\n const walkedOver = _Window.#relationOf(route);\n if (this.#indexed(["reads"]).some((key) => Array.isArray(key) && key[1] === walkedOver)) this.#movedAt(walkedOver);\n await this.#stateKept(route);\n await this.#keptAgain(route);\n return { route, text: _Window.#text(route) };\n }\n async #tell(route, told) {\n const over = _Window.#relationOf(route);\n if (over === null || !this.#farLobe(over) || !_Window.#fields(told)) return;\n const { size, language, standard } = told;\n if (typeof size !== "string" || typeof language !== "string" || typeof standard !== "string") return;\n if (_Window.#at(_Window.#methodOf(this.#keptDescribed(over, over), "told"), "kind") !== "writing") return;\n const far = _Window.#at(this.cells.get(["far-lobe", over]), "far") ?? "";\n const kept = this.cells.get(["told", over]);\n const last = _Window.#at(kept, "told");\n const same = _Window.#at(kept, "far") === far && _Window.#at(last, "size") === size && _Window.#at(last, "language") === language && _Window.#at(last, "standard") === standard;\n if (same) return;\n const heard = await this.#through(over, over, "told", { size, language, standard });\n if ("result" in heard) this.cells.set(["told", over], { far, told: { size, language, standard } });\n }\n async #learn(walkedTo) {\n const walked = _Window.#relationOf(walkedTo);\n const read = await this.nerves.read();\n const held = "result" in read && Array.isArray(read.result) ? read.result : [];\n const unknown = held.flatMap((one) => {\n const [placeholder, far] = [_Window.#at(one, "placeholder"), _Window.#at(one, "termination")];\n const relation = typeof placeholder === "string" && typeof far === "string" && !_Window.#own.includes(placeholder) && _Window.#relationName.test(placeholder) && _Window.#at(one, "status") === "far";\n if (!relation || typeof placeholder !== "string" || typeof far !== "string") return [];\n const known = this.#farLobe(placeholder) || this.cells.get(["far-organism", placeholder]) === far;\n return known ? [] : [{ placeholder, far }];\n });\n const first = unknown.toSorted((one, other) => Number(other.placeholder === walked) - Number(one.placeholder === walked)).slice(0, _Window.#describing);\n const knocks = await Promise.all(\n first.map(({ placeholder }) => this.ask(placeholder, null, {}, _Window.#lobeWithin))\n );\n for (const [at, knocked] of knocks.entries()) {\n const { placeholder, far } = first[at] ?? { placeholder: "", far: "" };\n if ("result" in knocked) this.#keepKnocked(placeholder, far, knocked);\n }\n }\n #keepKnocked(placeholder, far, knocked) {\n const blueprint = "result" in knocked ? _Window.#at(knocked.result, "name") : void 0;\n if (blueprint === "nervur.brain") {\n this.cells.set(["far-organism", placeholder], far);\n return;\n }\n this.cells.delete(["far-organism", placeholder]);\n this.cells.set(["far-lobe", placeholder], { blueprint: typeof blueprint === "string" ? blueprint : "", far });\n this.#keepDescribed(placeholder, placeholder, _Window.#blueprintOf(knocked));\n }\n async #stateKept(route) {\n const over = _Window.#relationOf(route);\n if (over === null || this.#lobeReached(route) !== over || !this.#farLobe(over)) return;\n const declared = _Window.#methodOf(this.#keptDescribed(over, over), "state");\n if (!_Window.#reads(declared) || _Window.#asksArgs(declared)) return;\n const kept = this.#keptRead(over, over, "state");\n if (kept === void 0 || !this.#fresh(kept, over, null)) await this.#readKept(over, over, "state", null, {});\n }\n static #asksArgs(method) {\n const required = _Window.#at(_Window.#at(method, "args"), "required");\n return Array.isArray(required) && required.length > 0;\n }\n #keptDescribed(over, lobe) {\n const kept = this.cells.get(["described", over, lobe]);\n return _Window.#at(kept, "described");\n }\n #keepDescribed(over, lobe, heard) {\n const key = ["described", over, lobe];\n if (!("result" in heard)) {\n this.cells.delete(key);\n return;\n }\n const version = _Window.#at(heard.result, "version");\n this.cells.set(key, { version: typeof version === "string" ? version : null, described: heard.result });\n const named = JSON.stringify(key);\n const index = this.#indexed(["describes"]).filter((one) => JSON.stringify(one) !== named);\n const kept = _Window.#trimmed([...index, key], _Window.#mostRelations, (old) => {\n const gone = _Window.#keyed(old);\n if (gone !== void 0) this.cells.delete(gone);\n });\n this.cells.set(["describes"], [...kept]);\n }\n async #walkDescribed(route) {\n const over = _Window.#relationOf(route);\n const lobe = this.#lobeReached(route);\n if (over === null || lobe === null) return;\n this.#keepDescribed(over, lobe, await this.#through(over, lobe, null, {}));\n }\n root() {\n const foreign = this.#foreign();\n if (foreign !== null) return foreign;\n const route = this.#walked();\n return { route, text: _Window.#text(route) };\n }\n #heldBy(over, cells) {\n if (over === null || !this.#farLobe(over)) return cells;\n const far = _Window.#at(this.cells.get(["far-lobe", over]), "far");\n const moved = this.cells.get(["moved", over]);\n return `${_Window.#shown(far)}:${String(typeof moved === "number" ? moved : 0)}`;\n }\n #movedAt(over) {\n if (over === null || !this.#farLobe(over)) return;\n const moved = this.cells.get(["moved", over]);\n this.cells.set(["moved", over], (typeof moved === "number" ? moved : 0) + 1);\n }\n #fresh(kept, over, cells) {\n const held = this.#heldBy(over, cells);\n return held !== null && kept["cells"] === held;\n }\n async #keptAgain(route) {\n const over = _Window.#relationOf(route);\n if (over === null || !this.#farLobe(over)) return;\n for (const key of this.#indexed(["reads"])) {\n if (!Array.isArray(key) || key[1] !== over || typeof key[2] !== "string" || typeof key[3] !== "string") continue;\n const kept = this.#keptRead(over, key[2], key[3], false);\n if (kept === void 0 || this.#fresh(kept, over, null)) continue;\n await this.#readKept(over, key[2], key[3], null, _Window.#fields(kept["values"]) ? kept["values"] : {});\n }\n }\n static #readKey(over, lobe, method) {\n return ["read", over ?? "", lobe, method];\n }\n #keptRead(over, lobe, method, plain = true) {\n const kept = this.cells.get(_Window.#readKey(over, lobe, method));\n return _Window.#fields(kept) && (!plain || kept["values"] === void 0) ? kept : void 0;\n }\n static #shown(data) {\n return typeof data === "string" ? data : JSON.stringify(data ?? null);\n }\n static #isLook(described) {\n const name = _Window.#at(described, "name");\n return typeof name === "string" && name.endsWith("-look");\n }\n static #methodsOf(described) {\n const methods = _Window.#at(described, "methods");\n if (!_Window.#fields(methods)) return [];\n const listed = [];\n for (const [name, one] of Object.entries(methods)) if (_Window.#fields(one)) listed.push([name, one]);\n return listed;\n }\n static #heard(answer) {\n return "result" in answer ? { answer: answer.result } : { error: { code: answer.error.code, message: answer.error.message } };\n }\n async #describedAll(over, lobes) {\n const described = [];\n for (let at = 0; at < lobes.length; at += _Window.#describing) {\n const asked = lobes.slice(at, at + _Window.#describing).map((lobe) => this.#through(over, lobe, null, {}));\n for (const answer of await Promise.all(asked)) described.push("result" in answer ? answer.result : void 0);\n }\n return described;\n }\n async #notes() {\n const notes = new Map();\n let cursor = null;\n for (let page = 0; page < _Window.#mostRelationPages; page++) {\n const read = await this.ask("nerves", "relations", cursor === null ? {} : { cursor });\n if ("error" in read || !_Window.#fields(read.result)) break;\n const listed = read.result["relations"];\n for (const one of Array.isArray(listed) ? listed : []) {\n const placeholder = _Window.#at(one, "placeholder");\n const note = _Window.#at(one, "note");\n if (typeof placeholder === "string" && note !== void 0) notes.set(placeholder, note);\n }\n const next = read.result["cursor"];\n if (typeof next !== "string") break;\n cursor = next;\n }\n return notes;\n }\n async #nerves() {\n const read = await this.nerves.read();\n if ("error" in read) return { why: `the window\'s nerves are not read: ${read.error.message}` };\n const held = Array.isArray(read.result) ? read.result : [];\n let design = null;\n const far = [];\n for (const one of held) {\n const placeholder = _Window.#at(one, "placeholder");\n const termination = _Window.#at(one, "termination");\n if (typeof placeholder !== "string") continue;\n if (placeholder === "design") design = typeof termination === "string" ? termination : null;\n else if (!_Window.#own.includes(placeholder) && _Window.#relationName.test(placeholder) && _Window.#at(one, "status") === "far")\n far.push({ placeholder, termination, status: "far" });\n }\n const notes = far.length === 0 ? new Map() : await this.#notes();\n const relations = far.map(({ placeholder, termination, status }) => ({\n placeholder,\n far: termination ?? null,\n status,\n note: notes.get(placeholder) ?? null,\n ...this.#farLobe(placeholder) ? { place: true } : {},\n path: _Window.#text([{ relation: placeholder }])\n }));\n return { design, relations };\n }\n async #namedAll(over, lobes) {\n const named = [];\n for (let at = 0; at < lobes.length; at += _Window.#describing) {\n const asked = lobes.slice(at, at + _Window.#describing).map(\n (lobe) => lobe === void 0 ? Promise.resolve(void 0) : this.ask(\n over ?? "brain",\n "ask",\n { lobe, method: "state", args: {}, timeout: _Window.#nameWithin },\n _Window.#nameWithin\n )\n );\n for (const answer of await Promise.all(asked)) {\n const name = answer !== void 0 && "result" in answer ? _Window.#at(answer.result, "name") : void 0;\n named.push(typeof name === "string" && name !== "" ? name : void 0);\n }\n }\n return named;\n }\n async #lobesShown(over, nodes) {\n const lobes = (Array.isArray(nodes) ? nodes : []).flatMap((node) => {\n const id = _Window.#at(node, "id");\n return _Window.#at(node, "kind") === "lobe" && typeof id === "string" ? [{ id, blueprint: _Window.#at(node, "blueprint") }] : [];\n });\n const described = await this.#describedAll(\n over,\n lobes.map((one) => one.id)\n );\n const named = await this.#namedAll(\n over,\n described.map(\n (text, at) => text !== void 0 && _Window.#methodsOf(text).some(([method, one]) => method === "state" && one["kind"] === "reading") ? lobes[at]?.id : void 0\n )\n );\n return lobes.map((one, at) => {\n const text = described[at];\n if (text === void 0) return { id: one.id, name: one.blueprint ?? one.id, unavailable: true };\n const faculty = _Window.#at(text, "name") ?? one.id;\n return {\n id: one.id,\n name: named[at] ?? faculty,\n faculty,\n version: _Window.#at(text, "version") ?? "",\n description: _Window.#at(text, "description") ?? ""\n };\n });\n }\n async #organismPage(over, path, relations, cursor, name, faculties) {\n const state = await this.ask(\n over ?? "brain",\n "state",\n cursor === null ? {} : { cursor },\n _Window.#lobeWithin\n );\n const own = over === null ? relations : [];\n if ("error" in state)\n return {\n args: { name, state: { error: state.error.message }, organs: [], lobes: [], relations: own, path },\n warnings: [this.#word("organismSilentSay")]\n };\n const unmade = over === null ? this.cells.get(_Window.#unmadeKey) : void 0;\n const about = over === null ? this.cells.get(_Window.#aboutKey) : void 0;\n const shown = await this.#lobesShown(over, _Window.#at(state.result, "nodes"));\n const head = Object.fromEntries(\n Object.entries(_Window.#fields(state.result) ? state.result : {}).filter(\n ([key]) => !["nodes", "organs", "letters", "durables", "cursor"].includes(key)\n )\n );\n const next = _Window.#at(state.result, "cursor");\n return {\n args: {\n name,\n state: head,\n organs: _Window.#at(state.result, "organs") ?? [],\n lobes: shown,\n relations: own,\n path,\n ...faculties === void 0 ? {} : { faculties },\n ..._Window.#fields(about) ? { about } : {},\n ...typeof next === "string" ? { next } : {},\n ...cursor === null ? {} : { first: true }\n },\n warnings: typeof unmade === "string" ? [unmade] : []\n };\n }\n #writtenOf(over, lobe) {\n const id = this.cells.get(["last", over ?? "", lobe]);\n const press = typeof id === "string" ? this.cells.get(["press", id]) : void 0;\n if (!_Window.#fields(press) || !this.#stands(press)) return void 0;\n return _Window.#kept(press) ?? (press["sent"] === true ? { method: _Window.#shown(press["method"]), unknown: true } : void 0);\n }\n #standing(over) {\n if (over === null) return null;\n const far = _Window.#at(this.cells.get(["far-lobe", over]), "far") ?? this.cells.get(["far-organism", over]);\n return typeof far === "string" && far !== "" ? far : null;\n }\n #stands(press) {\n const far = press["far"];\n return typeof far !== "string" || far === this.#standing(typeof press["over"] === "string" ? press["over"] : null);\n }\n #pressDropped(id) {\n this.cells.delete(["press", id]);\n const presses = this.#indexed(["presses"]);\n if (presses.includes(id))\n this.cells.set(\n ["presses"],\n presses.filter((one) => one !== id)\n );\n }\n async #heardOf(over, lobe, method, cells) {\n const ask = async (values2) => _Window.#heard(await this.#through(over, lobe, method, values2));\n const kept = this.#keptRead(over, lobe, method, false);\n const keptState = this.#farLobe(over) && kept !== void 0 && this.#fresh(kept, over, cells);\n if (method === "state" && !keptState) return ask({});\n if (kept === void 0) return void 0;\n const values = _Window.#fields(kept["values"]) ? kept["values"] : {};\n return this.#fresh(kept, over, cells) ? kept : ask(values);\n }\n static #drawn(entry, seated) {\n return _Window.#seatOf(entry) !== void 0 || !seated && !_Window.#fields(_Window.#at(entry, "seat"));\n }\n async #methodsShown(over, lobe, described, cells) {\n const reading = [];\n const writing = [];\n const methods = _Window.#methodsOf(described);\n const seated = methods.some(([, one]) => _Window.#seatOf(one) !== void 0);\n for (const [method, one] of methods) {\n if (method === "draw" && _Window.#isLook(described) || !_Window.#drawn(one, seated)) continue;\n const description = _Window.#at(one, "description") ?? "";\n const worded = _Window.#worded(_Window.#at(_Window.#seatOf(one), "label"), this.#lang);\n const label = worded === "" ? {} : { label: worded };\n if (!_Window.#reads(one)) {\n writing.push({ method, description, args: _Window.#at(one, "args") ?? null, ...label });\n continue;\n }\n const heard = await this.#heardOf(over, lobe, method, cells);\n const kept = heard === void 0 ? {} : "error" in heard ? { error: heard["error"] ?? null } : { answer: heard["answer"] ?? null };\n const args = _Window.#at(one, "args");\n reading.push({ method, description, ...args === void 0 ? {} : { args }, ...label, ...kept });\n }\n return { reading, writing };\n }\n async #lobePage(over, lobe, described, path, cells) {\n const { reading, writing } = await this.#methodsShown(over, lobe, described, cells);\n const faculty = _Window.#at(described, "name");\n const own = reading.map((one) => _Window.#at(one, "method") === "state" ? _Window.#at(_Window.#at(one, "answer"), "name") : void 0).find((one) => typeof one === "string" && one !== "");\n const written = this.#writtenOf(over, lobe);\n return {\n id: lobe,\n name: typeof own === "string" ? own : faculty ?? lobe,\n faculty: faculty ?? lobe,\n version: _Window.#at(described, "version") ?? "",\n description: _Window.#at(described, "description") ?? "",\n reading,\n writing,\n path,\n ...written === void 0 ? {} : { written }\n };\n }\n async #surrounded(theme, around) {\n const args = {\n title: around.title,\n route: around.route,\n warnings: around.warnings,\n main: around.main,\n ...around.consent === void 0 ? {} : { consent: around.consent },\n ...around.back === null ? {} : { back: around.back }\n };\n return this.#draws({ component: "surround", args, theme });\n }\n async #organismPlaced(over, text, held, asked) {\n const title = over ?? this.#word("homeWord");\n const kept = over === null ? await this.#facultiesKept() : void 0;\n const page = await this.#organismPage(over, text, held.relations, asked.cursor, title, kept?.faculties);\n const args = { component: "organism", args: page.args, theme: asked.theme, lang: this.#lang };\n return {\n title,\n version: null,\n warnings: kept?.more === true ? [...page.warnings, this.#word("moreFacultiesSay")] : page.warnings,\n main: { lobe: held.design, over: null, args }\n };\n }\n async #lobeSeen(over, lobe, text, seen) {\n const { cells, theme, design } = seen;\n const described = await this.#describedOf(over, lobe);\n if (over !== null && "error" in described && described.error.code === "removed") return _Window.#goneOf(over);\n const says = "result" in described ? described.result : void 0;\n const name = _Window.#at(says, "name");\n const said = _Window.#at(says, "version");\n const version = typeof said === "string" ? said : null;\n const warnings = says === void 0 ? [this.#word("lobeSilentSay")] : [];\n if (_Window.#reads(_Window.#methodOf(says, "draw")) && !_Window.#isLook(says))\n return { title: typeof name === "string" ? name : lobe, version, warnings, main: { lobe, over, args: {} } };\n const page = await this.#lobePage(over, lobe, says ?? {}, text, cells);\n const label = page["name"];\n return {\n title: typeof label === "string" ? label : lobe,\n version,\n warnings,\n main: { lobe: design, over: null, args: { component: "lobe", args: page, theme, lang: this.#lang } },\n ...this.#channelOf(over, lobe)\n };\n }\n static #goneOf(over) {\n return { why: `the place ${over} has ended: its far side removed the standing` };\n }\n #answersSaid() {\n return { yesSay: this.#word("yesSay"), noSay: this.#word("noSay") };\n }\n #leaveAsked(over, lobe) {\n const state = lobe === null ? {} : this.#localOf(over, lobe, _Window.#consent);\n if (!this.#farLobe(over) || state["asking"] !== "leave") return void 0;\n return {\n say: this.#word("leavingSay"),\n yes: { method: "leave", args: { relation: over, consented: true } },\n no: { method: "local", args: { region: _Window.#consent, state: { asking: null } } },\n ...this.#answersSaid()\n };\n }\n static #consent = "#consent";\n #consentAt(on) {\n const route = this.#walked();\n const lobe = this.#lobeReached(route);\n const over = _Window.#relationOf(route);\n return lobe !== null && over === on.over ? { over, lobe } : on;\n }\n #consented(over, lobe, press) {\n const state = this.#consentOf(over, lobe, press);\n return state !== null && state["taken"] === void 0;\n }\n #consentOf(over, lobe, press) {\n const at = this.#consentAt({ over, lobe });\n const state = this.#localOf(at.over, at.lobe, _Window.#consent);\n return press["consented"] === true && state["asking"] === press["method"] && (state["lobe"] ?? at.lobe) === lobe ? state : null;\n }\n #consentTaken(on, id) {\n this.#localSet(this.#consentAt(on), _Window.#consent, { taken: id });\n }\n #consentSpent(on, id) {\n const at = this.#consentAt(on);\n if (id === void 0 || this.#localOf(at.over, at.lobe, _Window.#consent)["taken"] === id)\n this.cells.delete(["local", at.over ?? "", at.lobe, _Window.#consent]);\n }\n static #irreversible(declared) {\n const marked = _Window.#at(declared, "irreversible");\n return marked === true || typeof marked === "string";\n }\n static #waits(declared, over) {\n return _Window.#irreversible(declared) || over !== null && _Window.#unsaid(declared);\n }\n #heldBack(on, method, args, declared) {\n if (!_Window.#fields(args) && args !== null)\n return this.error("refused", "a press that waits for consent carries its args as fields");\n const label = _Window.#at(_Window.#seatOf(declared), "label");\n const set = this.#localSet(this.#consentAt(on), _Window.#consent, {\n asking: method,\n lobe: on.lobe,\n args: args ?? {},\n label: _Window.#fields(label) ? label : null,\n irreversible: _Window.#irreversible(declared) ? true : null,\n taken: null\n });\n return "code" in set ? set : { method, asking: true };\n }\n #heldAsked(over, lobe, path, lang) {\n if (lobe === null) return void 0;\n const { asking, args, label, lobe: asked, irreversible } = this.#localOf(over, lobe, _Window.#consent);\n if (typeof asking !== "string" || !_Window.#fields(args)) return void 0;\n const at = typeof asked === "string" && asked !== lobe ? _Window.#text([...over === null ? [] : [{ relation: over }], { lobe: asked }]) : path;\n const named = _Window.#worded(label, lang) || asking;\n return {\n say: `${named}: ${this.#word(irreversible === true ? "irreversibleSay" : "unsaidSay")}`,\n yes: { method: "ask", args: { path: at, method: asking, args, consented: true } },\n no: {\n method: "local",\n args: {\n region: _Window.#consent,\n state: { asking: null, lobe: null, args: null, label: null, irreversible: null }\n }\n },\n ...this.#answersSaid()\n };\n }\n #lobeReached(route) {\n const over = _Window.#relationOf(route);\n return _Window.#lobeOf(route) ?? (this.#farLobe(over) ? over : null);\n }\n async see(args) {\n const foreign = this.#foreign();\n if (foreign !== null) return foreign;\n const given = _Window.#at(args, "route");\n const route = given === void 0 ? this.#walked() : _Window.#routeOf(given);\n if (route === void 0) return this.error("refused", "see names no route: a relation the window holds and a lobe");\n if (this.#lobeOfFarLobe(route)) return this.error("refused", "a far lobe has no lobes");\n const options = _Window.#at(args, "args");\n const [cursor, cells] = [_Window.#at(options, "cursor"), _Window.#at(options, "cells")];\n const theme = _Window.#themed(_Window.#at(options, "theme"));\n const lang = _Window.#langOf(_Window.#at(options, "lang"));\n this.#lang = lang;\n const held = await this.#nerves();\n if ("why" in held) return this.error("unavailable", held.why);\n if (held.design === null) return this.error("unavailable", "the screen wears no design yet");\n const over = _Window.#relationOf(route);\n const text = _Window.#text(route);\n const lobe = this.#lobeReached(route);\n const crumbs = [{ label: this.#word("homeWord"), path: "/" }];\n if (over !== null && !this.#farLobe(over)) crumbs.push({ label: over, path: _Window.#text(route.slice(0, 1)) });\n const placed = lobe === null ? await this.#organismPlaced(\n over,\n text,\n { relations: held.relations, design: held.design },\n { cursor: typeof cursor === "string" ? cursor : null, theme }\n ) : await this.#lobeSeen(over, lobe, text, {\n cells: typeof cells === "string" ? cells : null,\n theme,\n design: held.design\n });\n if ("why" in placed) return this.error("refused", placed.why);\n const consent = this.#heldAsked(over, lobe, text, lang) ?? (over === null ? void 0 : this.#leaveAsked(over, lobe));\n const leave = over !== null && lobe === over ? this.#leaveOf(over).leave : void 0;\n return this.#pageSurrounded(consent === void 0 ? placed : { ...placed, consent }, {\n route,\n text,\n lobe,\n crumbs,\n theme,\n leave,\n design: held.design\n });\n }\n async #pageSurrounded(placed, on) {\n const { route, text, lobe, crumbs, theme, leave, design } = on;\n const { title, version, warnings, main, consent } = placed;\n const way = route.length === 0 ? {} : {\n way: {\n at: _Window.#wayAt,\n say: this.#word("wayOutSay"),\n ...leave === void 0 ? {} : { leave }\n }\n };\n const beside = { version, design, ...way, ...placed.channel === void 0 ? {} : { channel: placed.channel } };\n if (warnings.length === 0 && consent === void 0)\n return {\n route,\n text,\n tree: { t: "main", a: {}, c: [{ t: "slot", a: { placeholder: "main" }, args: main.args, c: [] }] },\n main,\n ...beside\n };\n if (lobe !== null) crumbs.push({ label: title, path: text });\n const back = route.length === 0 ? null : _Window.#text(route.slice(0, -1));\n const drawn = await this.#surrounded(theme, {\n title,\n route: crumbs,\n back,\n warnings,\n main: main.args,\n ...consent === void 0 ? {} : { consent }\n });\n if ("error" in drawn) return this.error("unavailable", `the design lobe draws no surround: ${drawn.error.message}`);\n return { route, text, tree: drawn.result, main, ...beside };\n }\n static #outside(css, has) {\n const quoted = /(url\\(\\s*|@import\\s+)("(?:\\\\.|[^"\\\\])*"|\'(?:\\\\.|[^\'\\\\])*\')|"(?:\\\\.|[^"\\\\])*"|\'(?:\\\\.|[^\'\\\\])*\'/gu;\n const text = css.replaceAll(/\\/\\*[\\s\\S]*?\\*\\//gu, " ").replaceAll(quoted, (whole, prefix) => prefix === void 0 ? \'""\' : whole);\n if (/@import\\b/iu.test(text)) return "@import";\n const addresses = [...text.matchAll(/url\\(\\s*(?:"([^"]*)"|\'([^\']*)\'|([^)\'"\\s]*))\\s*\\)/gu)].map(\n (one) => one[1] ?? one[2] ?? one[3] ?? ""\n );\n for (const set of text.matchAll(/image-set\\(([^)]*)\\)/gu))\n for (const one of (set[1] ?? "").matchAll(/"([^"]*)"|\'([^\']*)\'/gu)) addresses.push(one[1] ?? one[2] ?? "");\n for (const address of addresses) {\n if (/^data:/iu.test(address) || address.startsWith("#")) continue;\n const out = [];\n let climbs = false;\n if (!/^[A-Za-z][A-Za-z0-9+.-]*:|^[/\\\\]/u.test(address))\n for (const part of `skin/${address}`.split("/")) {\n if (part === "..") climbs = out.pop() === void 0 || climbs;\n else if (part !== "." && part !== "") out.push(part);\n }\n if (climbs || out.length === 0 || !has(out.join("/"))) return address;\n }\n return null;\n }\n static #fenced(items) {\n const files = new Map();\n for (const one of items) {\n const [path, text] = [_Window.#at(one, "path"), _Window.#at(one, "text")];\n if (typeof path === "string" && typeof text === "string") files.set(path, text);\n }\n const hold = (path) => items.some((one) => _Window.#at(one, "path") === path);\n let layers;\n try {\n layers = JSON.parse(files.get("skin/layers.json") ?? "null");\n } catch {\n return "skin/layers.json is no JSON";\n }\n for (const layer of ["lobes", "home"]) {\n const named = _Window.#at(layers, layer);\n for (const name of Array.isArray(named) ? named : []) {\n const found = typeof name === "string" ? _Window.#outside(files.get(`skin/${name}`) ?? "", hold) : null;\n if (found !== null) return `skin/${String(name)}: ${found} is outside its bundle`;\n }\n }\n return null;\n }\n async #fencedLobe(lobe) {\n const files = await this.#through(null, lobe, "files", {});\n if ("error" in files) return `the window reads not the files of ${lobe}: ${files.error.message}`;\n const items = _Window.#at(files.result, "files");\n if (!Array.isArray(items)) return `${lobe} answered no files`;\n const fenced = _Window.#fenced(items);\n return fenced === null ? null : `the design is refused: ${fenced}`;\n }\n #localOf(over, lobe, region) {\n const kept = this.cells.get(["local", over ?? "", lobe, region]);\n return _Window.#fields(kept) ? kept : {};\n }\n #forgetLocals() {\n for (const one of this.#indexed(["locals"])) {\n const gone = _Window.#keyed(one);\n if (gone !== void 0) this.cells.delete(gone);\n }\n this.cells.delete(["locals"]);\n }\n #localSet(on, region, state) {\n const { over, lobe } = on;\n const key = ["local", over ?? "", lobe, region];\n const merged = { ...this.#localOf(over, lobe, region) };\n for (const [field, value] of Object.entries(state)) {\n if (value === null) delete merged[field];\n else merged[field] = value;\n }\n if (JSON.stringify(merged).length > this.#mostState())\n return this.error("refused", "the local state is past the size the home keeps");\n this.cells.set(key, merged);\n const named = JSON.stringify(key);\n const index = this.#indexed(["locals"]).filter((one) => JSON.stringify(one) !== named);\n const kept = _Window.#trimmed([...index, key], this.#keptHalf(), (old) => {\n const gone = _Window.#keyed(old);\n if (gone !== void 0) this.cells.delete(gone);\n });\n this.cells.set(["locals"], [...kept]);\n return merged;\n }\n local(args) {\n const foreign = this.#foreign();\n if (foreign !== null) return foreign;\n const [region, state] = [_Window.#at(args, "region"), _Window.#at(args, "state")];\n const route = this.#walked();\n const lobe = this.#lobeReached(route);\n if (typeof region !== "string" || !_Window.#fields(state) || lobe === null)\n return this.error("refused", "a local state is a region\u2019s and an object, at the route of a lobe");\n if (region === _Window.#consent && Object.values(state).some((one) => one !== null))\n return this.error("refused", "the consent is set by the home alone, and a press only clears it");\n return this.#localSet({ over: _Window.#relationOf(route), lobe }, region, state);\n }\n static #seatOf(entry) {\n const seat = _Window.#at(entry, "seat");\n const people = _Window.#at(seat, "for");\n return _Window.#fields(seat) && (people === "person" || people === "both") ? seat : void 0;\n }\n static #https = /^https:\\/\\/([A-Za-z0-9.-]+)(?::[0-9]{1,5})?(?:[/?#]\\S*)?$/u;\n static #domainOf(link) {\n if (typeof link !== "string" || link.length > 2e3) return void 0;\n const found = _Window.#https.exec(link);\n const host = found?.[1];\n return host === void 0 || host.startsWith(".") || host.includes("..") ? void 0 : host.toLowerCase();\n }\n static #fileKinds = new Set(["avif", "gif", "jpg", "png", "webp", "mp3", "ogg", "wav"]);\n static #file(given, now, far) {\n const { url, expires, size, sha256, ext } = given;\n if (typeof size !== "number" || !Number.isInteger(size) || size < 0)\n return { why: "a file has a size, a whole number of bytes" };\n if (typeof sha256 !== "string" || !/^[0-9a-f]{64}$/u.test(sha256))\n return { why: "a file has its SHA-256, 64 hex characters" };\n if (typeof ext !== "string" || !_Window.#fileKinds.has(ext))\n return { why: `a file is a picture or a sound, of a kind a tree names: ${[..._Window.#fileKinds].join(", ")}` };\n if (url === void 0 && expires === void 0)\n return far ? { why: "a far place hands a file from an https address: the bytes it holds itself would cross Quo" } : { kind: "file", size, sha256, ext };\n const domain = _Window.#domainOf(url);\n if (domain === void 0 || typeof url !== "string" || url.includes("@"))\n return { why: "a file is fetched from an https address with no credentials" };\n if (typeof expires !== "number" || !Number.isInteger(expires) || expires <= now)\n return { why: "a file\u2019s address has an expiry still to come, in whole milliseconds" };\n return { kind: "file", url, domain, expires, size, sha256, ext };\n }\n static #channel(answer, now, files, far) {\n const given = _Window.#at(answer, "channel");\n if (!_Window.#fields(given)) return { why: "a channel answers {channel: {kind, \u2026}}" };\n const kind = given["kind"];\n if (kind === "upload") {\n const { url, expires } = given;\n const domain = _Window.#domainOf(url);\n if (domain === void 0 || typeof url !== "string" || url.includes("@"))\n return { why: "a file is sent to an https address with no credentials" };\n if (typeof expires !== "number" || !Number.isInteger(expires) || expires <= now)\n return { why: "an upload\u2019s address has an expiry still to come, in whole milliseconds" };\n const [file, ...more] = files;\n if (file === void 0 || more.length > 0)\n return { why: "an upload sends the one file its press carried, and this press carried none or more" };\n return { kind, url, domain, expires, ...file };\n }\n if (kind === "file") return _Window.#file(given, now, far);\n return { why: "a channel is a file or an upload" };\n }\n static #filesOf(values) {\n if (!_Window.#fields(values)) return [];\n return Object.values(values).filter((one) => {\n if (!_Window.#fields(one) || Object.keys(one).length !== 4) return false;\n const { name, type, size, sha256 } = one;\n return typeof name === "string" && typeof type === "string" && typeof size === "number" && Number.isInteger(size) && size >= 0 && typeof sha256 === "string" && /^[0-9a-f]{64}$/u.test(sha256);\n });\n }\n static #shaped(declared, heard, now, files, far) {\n if (_Window.#at(_Window.#seatOf(declared), "intent") !== "channel" || !("answer" in heard)) return heard;\n const kind = _Window.#at(_Window.#at(heard["answer"], "channel"), "kind");\n if (kind === "call" || kind === "stream")\n return {\n error: { code: "unavailable", message: `channel unavailable: no organ of this home carries a ${kind}` }\n };\n const checked = _Window.#channel(heard["answer"], now, files, far);\n if ("why" in checked && typeof checked.why === "string")\n return { error: { code: "refused", message: `channel refused: ${checked.why}` } };\n return { answer: { channel: checked } };\n }\n static #worded(words, lang) {\n if (!_Window.#fields(words)) return "";\n const wanted = words[lang] ?? words[_Window.#primary(lang)];\n if (typeof wanted === "string") return wanted;\n return Object.values(words).find((one) => typeof one === "string") ?? "";\n }\n #word(key, values = {}) {\n return _Window.words[key].replaceAll(\n /\\{([a-z]+)\\}/gu,\n (found, name) => Object.hasOwn(values, name) ? values[name] ?? found : found\n );\n }\n static #primary(lang) {\n return (lang.split(/[-_]/u)[0] ?? "").toLowerCase();\n }\n #channelOf(over, lobe) {\n const id = this.cells.get(["last", over ?? "", lobe]);\n const pressed = typeof id === "string" ? this.cells.get(["press", id]) : void 0;\n const channel = _Window.#at(_Window.#at(this.#writtenOf(over, lobe), "answer"), "channel");\n if (!_Window.#fields(channel) || _Window.#at(pressed, "channeled") !== true) return {};\n if (channel["kind"] !== "upload" && channel["kind"] !== "file") return { channel };\n return typeof id === "string" && _Window.#at(pressed, "landed") === void 0 ? { channel: { ...channel, press: id } } : {};\n }\n async landed(args) {\n const found = this.#pressOf(args);\n if ("code" in found) return found;\n const { id, press } = found;\n const channel = _Window.#at(_Window.#at(press, "answer"), "channel");\n const [landed, why] = [_Window.#at(args, "landed"), _Window.#at(args, "why")];\n const kind = _Window.#at(channel, "kind");\n if (kind !== "upload" && kind !== "file" || press["landed"] !== void 0)\n return this.error("refused", "the press answered no file or upload still to tell");\n if (typeof landed !== "boolean") return this.error("refused", "landed says whether the file landed");\n const [lobe, over, sha256] = [press["lobe"], press["over"], _Window.#at(channel, "sha256")];\n if (typeof lobe !== "string" || typeof sha256 !== "string") return this.error("refused", "the press names no lobe");\n const said = typeof why === "string" ? why.slice(0, 300) : "the file did not come";\n this.cells.set(\n ["press", id],\n landed ? { ...press, landed } : {\n ...Object.fromEntries(Object.entries(press).filter(([key]) => key !== "answer")),\n landed,\n error: { code: "refused", message: `${kind} refused: ${said}` }\n }\n );\n if (kind === "file") return { landed };\n const told = await this.#through(typeof over === "string" ? over : null, lobe, "landed", { sha256, landed });\n return { landed, ..._Window.#heard(told) };\n }\n async piece(args) {\n const found = this.#pressOf(args);\n if ("code" in found) return found;\n const { press } = found;\n const channel = _Window.#at(_Window.#at(press, "answer"), "channel");\n const [lobe, sha256, size, at] = [\n press["lobe"],\n _Window.#at(channel, "sha256"),\n _Window.#at(channel, "size"),\n _Window.#at(args, "at")\n ];\n if (_Window.#at(channel, "kind") !== "file" || _Window.#at(channel, "url") !== void 0 || typeof press["over"] === "string" || press["landed"] !== void 0 || typeof lobe !== "string" || typeof sha256 !== "string" || typeof size !== "number")\n return this.error("refused", "the press answered no file its lobe holds, still to tell");\n if (typeof at !== "number" || !Number.isInteger(at) || at < 0 || at >= size)\n return this.error("refused", `a piece starts at a byte of the file, below ${String(size)}`);\n const length = Math.min(size - at, Math.floor(this.memory / LOBE_SHARE));\n const heard = await this.#through(null, lobe, "piece", { sha256, at, length });\n if ("error" in heard) return this.error("refused", `${lobe} gave no piece: ${heard.error.message}`);\n const bytes = heard.result;\n return bytes instanceof Uint8Array && bytes.length === length ? bytes : this.error("refused", `${lobe} gave a piece that is not the ${String(length)} bytes from ${String(at)}`);\n }\n async show(args) {\n const foreign = this.#foreign();\n if (foreign !== null) return foreign;\n const lobe = _Window.#at(args, "lobe");\n if (typeof lobe !== "string") return this.error("refused", "show names a lobe");\n const over = _Window.#over(args);\n if (over === void 0) return this.error("refused", "over names a relation the window holds");\n const drawn = await this.#through(over, lobe, "draw", _Window.#at(args, "args") ?? null);\n if ("error" in drawn) return this.error(drawn.error.code, drawn.error.message);\n if (this.#farLobe(over)) return { tree: drawn.result, wires: {} };\n const wires = await this.#wiresOf(over, lobe);\n if ("why" in wires) return this.error("refused", wires.why);\n return { tree: drawn.result, wires: wires.wires };\n }\n static #ownPresses = ["wear", "create", "about", "leave"];\n async press(args) {\n const foreign = this.#foreign();\n if (foreign !== null) return foreign;\n const lobe = _Window.#at(args, "lobe");\n const method = _Window.#at(args, "method");\n if (typeof lobe !== "string" || typeof method !== "string")\n return this.error("refused", "a press names its lobe and its method");\n const over = _Window.#over(args);\n if (over === void 0) return this.error("refused", "over names a relation the window holds");\n const to = _Window.#at(args, "to");\n const given = _Window.#at(args, "args") ?? {};\n if (_Window.#ownPresses.includes(method) && over === null && to === void 0) {\n const held = await this.#nerves();\n if (!("why" in held) && held.design === lobe) {\n if (method === "wear") return this.#wearOrTell(given);\n if (method === "create") return this.#making(given);\n if (method === "about") return this.#about(given);\n return this.#leave(given);\n }\n }\n let asked = lobe;\n if (typeof to === "string") {\n if (this.#farLobe(over)) return this.error("refused", `${lobe} has nothing wired at ${to}`);\n const wires = await this.#wiresOf(over, lobe);\n if ("why" in wires) return this.error("refused", wires.why);\n const wired = wires.wires[to];\n if (wired === void 0) return this.error("refused", `${lobe} has nothing wired at ${to}`);\n asked = wired;\n }\n const described = await this.#describedOf(over, asked);\n if ("error" in described) return this.error("refused", `${asked} is not described: ${described.error.message}`);\n const declared = _Window.#methodOf(described.result, method);\n const carried = _Window.#carried(declared, _Window.#at(args, "args") ?? null, _Window.#at(args, "values"));\n if ("why" in carried) return this.error("refused", carried.why);\n if (_Window.#waits(declared, over)) return this.#heldBack({ over, lobe: asked }, method, carried.args, declared);\n const pressed = await this.#through(over, asked, method, carried.args);\n if (!_Window.#reads(declared)) this.#movedAt(over);\n return "result" in pressed ? pressed.result : this.error(pressed.error.code, pressed.error.message);\n }\n static #carried(declared, args, values) {\n if (!_Window.#fields(values) || Object.keys(values).length === 0) return { args };\n const fit = _Window.#fit(_Window.#at(declared, "args"), values);\n if ("why" in fit) return fit;\n const fields = _Window.#fields(fit.values) ? fit.values : {};\n if (Object.keys(fields).length === 0) return { args };\n if (!_Window.#fields(args) && args !== null) return { why: "a press whose args are no object carries no field" };\n return { args: { ...fields, ..._Window.#fields(args) ? args : {} } };\n }\n async #making(args) {\n const digest = _Window.#at(args, "faculty");\n if (typeof digest !== "string" || !/^[0-9a-f]{64}$/u.test(digest))\n return this.#unmade("create names a faculty by its digest");\n const kept = await this.#through(null, "library", "get", { digest });\n if ("error" in kept) return this.#unmade(`the library keeps no faculty ${digest}: ${kept.error.message}`);\n const wiring = await this.#coreWiring(_Window.#at(_Window.#at(kept.result, "blueprint"), "placeholders"));\n if ("why" in wiring) return this.#unmade(wiring.why);\n const made = await this.ask("brain", "create", { faculty: digest, wiring: wiring.wiring });\n if ("error" in made) return this.#unmade(`the brain makes no lobe of ${digest}: ${made.error.message}`);\n const id = _Window.#at(made.result, "id");\n if (typeof id !== "string") return this.#unmade("the brain named no lobe it made");\n this.cells.delete(_Window.#unmadeKey);\n this.cells.delete(_Window.#aboutKey);\n this.#forgetLocals();\n const route = [{ lobe: id }];\n this.cells.set(["root"], route);\n return { lobe: id, route, text: _Window.#text(route) };\n }\n async #about(args) {\n const digest = _Window.#at(args, "faculty");\n if (typeof digest !== "string" || !/^[0-9a-f]{64}$/u.test(digest))\n return this.#unmade("about names a faculty by its digest");\n const kept = await this.#through(null, "library", "get", { digest });\n const blueprint = "result" in kept ? _Window.#at(kept.result, "blueprint") : void 0;\n if (!_Window.#fields(blueprint)) return this.#unmade(`the library keeps no faculty ${digest}`);\n const held = await this.#nodesHeld();\n if ("why" in held) return this.#unmade(held.why);\n const organs = new Map();\n for (const node of held.nodes) {\n const [id, name] = [_Window.#at(node, "id"), _Window.#at(node, "blueprint")];\n if (_Window.#at(node, "kind") === "organ" && typeof id === "string" && typeof name === "string")\n organs.set(id, name);\n }\n const placeholders = _Window.#fields(blueprint["placeholders"]) ? blueprint["placeholders"] : {};\n const skins = Object.entries(placeholders).flatMap(\n ([placeholder, name]) => typeof name === "string" && organs.get(placeholder) === name ? [placeholder] : []\n );\n const about = {\n faculty: digest,\n name: blueprint["name"] ?? null,\n version: blueprint["version"] ?? null,\n placeholders: { ...placeholders },\n skins,\n world: skins.includes(_Window.#world)\n };\n this.cells.delete(_Window.#unmadeKey);\n this.cells.set(_Window.#aboutKey, about);\n return about;\n }\n #unmade(why) {\n this.cells.set(_Window.#unmadeKey, why);\n return { refused: why };\n }\n async #nodesHeld() {\n const nodes = [];\n let cursor = null;\n for (let page = 0; page < _Window.#mostListed; page += 1) {\n const state = await this.ask("brain", "state", cursor === null ? {} : { cursor });\n if ("error" in state) return { why: `the brain answers no state: ${state.error.message}` };\n const listed = _Window.#at(state.result, "nodes");\n if (Array.isArray(listed)) nodes.push(...listed);\n const next = _Window.#at(state.result, "cursor");\n cursor = typeof next === "string" ? next : null;\n if (cursor === null) break;\n }\n if (cursor !== null) return { why: _Window.#cutSay(_Window.#mostListed) };\n return { nodes };\n }\n static #cutSay(pages) {\n return `the organism holds more than the window reads, ${String(pages)} pages of its state: more stand than it shows`;\n }\n async #coreWiring(placeholders) {\n const expected = Object.entries(_Window.#fields(placeholders) ? placeholders : {}).filter(\n (entry) => typeof entry[1] === "string"\n );\n if (expected.length === 0) return { wiring: {} };\n const held = await this.#nodesHeld();\n if ("why" in held) return held;\n const core = new Map();\n for (const node of held.nodes) {\n const [id, blueprint, kind] = ["id", "blueprint", "kind"].map((key) => _Window.#at(node, key));\n if (typeof id === "string" && typeof blueprint === "string" && _Window.#at(node, "core") === true && kind !== "organ")\n core.set(blueprint, id);\n }\n return {\n wiring: Object.fromEntries(\n expected.flatMap(([placeholder, blueprint]) => {\n const id = core.get(blueprint);\n return id === void 0 ? [] : [[placeholder, id]];\n })\n )\n };\n }\n async #leave(args) {\n const relation = _Window.#at(args, "relation");\n const far = typeof relation === "string" ? _Window.#at(this.cells.get(["far-lobe", relation]), "far") : void 0;\n if (typeof relation !== "string" || typeof far !== "string" || far === "")\n return this.error(\n "refused",\n "the window leaves only a place it holds that is a far lobe: this one is left already, or is a standing of an owner, which is never left so"\n );\n if (!this.#consented(relation, relation, { method: "leave", consented: _Window.#at(args, "consented") ?? null })) {\n const set = this.#localSet({ over: relation, lobe: relation }, _Window.#consent, { asking: "leave" });\n return "error" in set ? set : { asking: "leave" };\n }\n const dropped = await this.#ends(far);\n if ("error" in dropped) return this.error(dropped.error.code, dropped.error.message);\n this.#consentSpent({ over: relation, lobe: relation });\n await this.left({ far });\n if (_Window.#relationOf(this.#walked()) === relation) {\n this.#forgetLocals();\n this.cells.set(["root"], []);\n }\n return { left: relation };\n }\n #leaveOf(over) {\n return over !== null && this.#farLobe(over) ? { leave: { press: { method: "leave", args: { relation: over } }, say: this.#word("leaveSay") } } : {};\n }\n async redeem(args) {\n const foreign = this.#foreign();\n if (foreign !== null) return foreign;\n const [card, reference] = [_Window.#at(args, "card"), _Window.#at(args, "reference")];\n if (!_Window.#fields(card) || typeof reference !== "string")\n return this.error("refused", "redeem names a card and a reference");\n const heard = await this.ask("mouth", "once", { card, method: _Window.#redeem, args: { reference } });\n if ("error" in heard) {\n if (heard.error.code === "unavailable") return this.error("refused", this.#word("redeemUnreachedSay"));\n if (heard.error.code === "timeout") return this.error("refused", this.#word("redeemTimeoutSay"));\n return this.error("refused", this.#word("redeemSpentSay"));\n }\n const given = _Window.#fields(heard.result) ? heard.result : {};\n const owed = Object.keys(given).length === 2 && ["text", "sig"].every((field) => typeof _Window.#at(given, field) === "string");\n return owed ? { invitation: JSON.stringify(given) } : this.error("refused", this.#word("redeemSpentSay"));\n }\n static #redeem = "#redeem";\n async offer(args) {\n const foreign = this.#foreign();\n if (foreign !== null) return foreign;\n const [card, reference] = [_Window.#at(args, "card"), _Window.#at(args, "reference")];\n if (!_Window.#fields(card) || typeof reference !== "string")\n return this.error("refused", "offer names a card and a reference");\n const heard = await this.ask("mouth", "once", { card, method: _Window.#offer, args: { reference } });\n if ("error" in heard)\n return heard.error.code === "unavailable" || heard.error.code === "timeout" ? { reached: false } : null;\n const offered = heard.result;\n if (!_Window.#fields(offered) || !Object.hasOwn(offered, "says")) return null;\n const [waits, lives] = [offered["waits"], offered["lives"]];\n return _Window.#spanned(waits) && _Window.#spanned(lives) ? { says: offered["says"] ?? null, waits, lives } : null;\n }\n static #offer = "#offer";\n static #spanned(span) {\n return span === null || typeof span === "number" && Number.isInteger(span) && span >= 0;\n }\n async #held() {\n const read = await this.nerves.read();\n if ("error" in read) return this.error("unavailable", `the window\'s nerves are not read: ${read.error.message}`);\n const held = [];\n for (const one of Array.isArray(read.result) ? read.result : []) {\n const placeholder = _Window.#at(one, "placeholder");\n if (typeof placeholder === "string") held.push(placeholder);\n }\n return held;\n }\n async standings() {\n const foreign = this.#foreign();\n if (foreign !== null) return foreign;\n const held = await this.#nerves();\n if ("why" in held) return this.error("refused", held.why);\n return {\n relations: held.relations.flatMap((one) => {\n const placeholder = _Window.#at(one, "placeholder");\n return typeof placeholder === "string" ? [\n {\n placeholder,\n note: _Window.#at(one, "note") ?? null,\n ..._Window.#at(one, "place") === true ? { place: true } : {}\n }\n ] : [];\n })\n };\n }\n async left(args) {\n const far = _Window.#at(args, "far");\n if (typeof far !== "string") return null;\n const ended = new Set();\n let cursor = null;\n do {\n const page = this.cells.range({ prefix: ["far-lobe"], ...cursor === null ? {} : { cursor } });\n for (const { key, value } of page.cells) if (_Window.#at(value, "far") === far) ended.add(String(key[1]));\n cursor = page.cursor;\n } while (cursor !== null);\n for (const { key, value } of this.cells.range({ prefix: ["far-organism"] }).cells)\n if (value === far) ended.add(String(key[1]));\n for (const relation of ended) this.#forget(relation);\n return null;\n }\n #forget(over) {\n for (const family of ["far-lobe", "far-organism", "moved", "told"]) this.cells.delete([family, over]);\n for (const family of ["described", "read", "last", "local"])\n for (const { key } of this.cells.range({ prefix: [family, over] }).cells) this.cells.delete(key);\n for (const index of ["describes", "reads", "locals"]) {\n const kept = this.#indexed([index]);\n const stays2 = kept.filter((one) => !Array.isArray(one) || one[1] !== over);\n if (stays2.length !== kept.length) this.cells.set([index], stays2);\n }\n const presses = this.#indexed(["presses"]);\n const stays = presses.filter((id) => {\n const gone = typeof id === "string" && _Window.#at(this.cells.get(["press", id]), "over") === over;\n if (gone) this.cells.delete(["press", id]);\n return !gone;\n });\n if (stays.length !== presses.length) this.cells.set(["presses"], stays);\n }\n async accept(args) {\n const foreign = this.#foreign();\n if (foreign !== null) return foreign;\n const [invitation, placeholder, note] = [\n _Window.#at(args, "invitation"),\n _Window.#at(args, "placeholder"),\n _Window.#at(args, "note")\n ];\n if (typeof invitation !== "string" || typeof placeholder !== "string" || !_Window.#relationName.test(placeholder))\n return this.error("refused", "accept names an invitation and a placeholder");\n const taken = `the window holds ${placeholder} already`;\n if (_Window.#own.includes(placeholder)) return this.error("refused", taken);\n const held = await this.#held();\n if (!Array.isArray(held)) return held;\n if (held.includes(placeholder)) return this.error("refused", taken);\n this.#forget(placeholder);\n const asked = { invitation, placeholder, note: note ?? null };\n const accepted = await this.ask("mouth", "accept", asked);\n if ("error" in accepted) return this.error(accepted.error.code, accepted.error.message);\n const knocked = await this.ask(placeholder, null, {});\n const far = _Window.#at(accepted.result, "far");\n if ("error" in knocked) {\n if (typeof far === "string") await this.#ends(far);\n return this.error(\n "refused",\n knocked.error.code === "unavailable" ? `nothing answered at the addresses the invitation names (${knocked.error.message}), so the window holds no ${placeholder}: its organism is down, or this side cannot reach it, as from behind a router. A relation takes one side the other reaches: the inviter\'s organism at a public address, or an invitation drawn through an organism always on that both reach (\\`through\\`).` : `the invitation was spent, ended or wrong, so the window holds no ${placeholder}: ${knocked.error.message}`\n );\n }\n this.#keepKnocked(placeholder, typeof far === "string" ? far : "", knocked);\n const route = [{ relation: placeholder }];\n return {\n far: typeof far === "string" ? far : "",\n route,\n text: _Window.#text(route)\n };\n }\n #lobeAt(path) {\n const route = _Window.#read(path);\n if (route === void 0) return void 0;\n const over = _Window.#relationOf(route);\n if (this.#lobeOfFarLobe(route)) return void 0;\n const lobe = this.#lobeReached(route);\n return lobe === null ? void 0 : { over, lobe };\n }\n static #methodOf(described, method) {\n const found = _Window.#at(_Window.#at(described, "methods"), method);\n return _Window.#fields(found) ? found : void 0;\n }\n static #reads(declared) {\n return _Window.#fields(declared) && declared["kind"] === "reading";\n }\n static #unsaid(declared) {\n const kind = _Window.#at(declared, "kind");\n return declared !== void 0 && kind !== "reading" && kind !== "writing";\n }\n async #describedOf(over, lobe) {\n const kept = over === null ? void 0 : this.#keptDescribed(over, lobe);\n return kept === void 0 ? this.#through(over, lobe, null, {}) : { result: kept };\n }\n static #trimmed(index, most, forget) {\n const cut = Math.max(0, index.length - most);\n for (const old of index.slice(0, cut)) forget(old);\n return index.slice(cut);\n }\n #indexed(key) {\n const held = this.cells.get(key);\n return Array.isArray(held) ? held : [];\n }\n static #keyed(entry) {\n return Array.isArray(entry) && entry.every((one) => typeof one === "string") ? entry.map(String) : void 0;\n }\n async read(args) {\n const foreign = this.#foreign();\n if (foreign !== null) return foreign;\n const at = this.#lobeAt(_Window.#at(args, "path"));\n const method = _Window.#at(args, "method");\n const cells = _Window.#at(args, "cells");\n const values = _Window.#at(args, "values") ?? {};\n if (at === void 0 || typeof method !== "string" || !_Window.#fields(values))\n return this.error("refused", "a read names a lobe by its path, and a method");\n const described = await this.#describedOf(at.over, at.lobe);\n if ("error" in described) return this.error("refused", `${at.lobe} is not described: ${described.error.message}`);\n const declared = _Window.#methodOf(described.result, method);\n if (!_Window.#reads(declared)) return this.error("refused", `${at.lobe} declares no reading method ${method}`);\n const schema = _Window.#at(declared, "args");\n const properties = _Window.#at(schema, "properties");\n const own = _Window.#fields(properties) ? Object.fromEntries(Object.entries(values).filter(([name]) => Object.hasOwn(properties, name))) : {};\n const fit = _Window.#fit(schema, own);\n if ("why" in fit) return this.error("refused", fit.why);\n const asked = _Window.#fields(fit.values) ? fit.values : {};\n const heard = await this.#readKept(at.over, at.lobe, method, typeof cells === "string" ? cells : null, asked);\n return { kept: "error" in heard ? "error" : "answer" };\n }\n async #readKept(over, lobe, method, cells, values) {\n const heard = _Window.#heard(await this.#through(over, lobe, method, values));\n const key = _Window.#readKey(over, lobe, method);\n this.cells.set(key, {\n cells: this.#heldBy(over, cells),\n ...heard,\n ...Object.keys(values).length === 0 ? {} : { values }\n });\n const named = JSON.stringify(key);\n const index = this.#indexed(["reads"]).filter((one) => JSON.stringify(one) !== named);\n const kept = _Window.#trimmed([...index, [...key]], this.#keptReads(), (old) => {\n const gone = _Window.#keyed(old);\n if (gone !== void 0) this.cells.delete(gone);\n });\n this.cells.set(["reads"], [...kept]);\n return heard;\n }\n write(args) {\n const foreign = this.#foreign();\n if (foreign !== null) return foreign;\n const at = this.#lobeAt(_Window.#at(args, "path"));\n const [id, method, values, seen] = [\n _Window.#at(args, "id"),\n _Window.#at(args, "method"),\n _Window.#at(args, "values"),\n _Window.#at(args, "seen")\n ];\n if (at === void 0 || typeof id !== "string" || typeof method !== "string" || !_Window.#fields(values))\n return this.error("refused", "a write names its id, a lobe by its path, a method and its values");\n if (this.cells.get(["press", id]) !== void 0) return { id };\n this.cells.set(["press", id], {\n over: at.over,\n lobe: at.lobe,\n method,\n values,\n seen: typeof seen === "string" ? seen : null,\n far: this.#standing(at.over),\n ..._Window.#at(args, "declared") === true ? { declared: true } : {},\n ..._Window.#at(args, "consented") === true ? { consented: true } : {}\n });\n const kept = _Window.#trimmed([...this.#indexed(["presses"]), id], this.#keptHalf(), (old) => {\n if (typeof old !== "string") return;\n const press = this.cells.get(["press", old]);\n const last = _Window.#fields(press) ? ["last", typeof press["over"] === "string" ? press["over"] : "", _Window.#shown(press["lobe"])] : null;\n if (last !== null && this.cells.get(last) === old) this.cells.delete(last);\n this.cells.delete(["press", old]);\n });\n this.cells.set(["presses"], [...kept]);\n return { id };\n }\n async back(args) {\n if (this.stamp.asker !== "brain") return this.error("refused", "only the brain says what came back");\n if (_Window.#at(args, "placeholder") === "screen") await this.#lay();\n return null;\n }\n async #given() {\n const read = await this.ask("nerves", "given", {});\n const design = "result" in read ? _Window.#at(read.result, "design") : void 0;\n const digest = _Window.#at(design, "digest");\n return typeof digest === "string" ? { digest, settings: _Window.#at(design, "settings") ?? null } : null;\n }\n async #lay() {\n const given = await this.#given();\n if (given === null) return;\n const held = await this.#nerves();\n if ("why" in held) return;\n const children = await this.ask("nerves", "children", {});\n const own = "result" in children && Array.isArray(children.result) ? children.result : [];\n const on = await this.ask("brain", "lobes", { faculty: given.digest });\n const ports = "result" in on && Array.isArray(on.result) ? on.result : [];\n if (held.design === null) {\n const stands = ports.find((one) => typeof one === "string" && own.includes(one));\n await (stands === void 0 ? this.#born(given) : this.#wornAgain(stands, given));\n return;\n }\n if (!own.includes(held.design) || this.cells.get(_Window.#chosen) === true) return;\n if (ports.includes(held.design)) return;\n const [worn, kept] = await Promise.all([\n this.ask("design", null, {}),\n this.#through(null, "library", "get", { digest: given.digest })\n ]);\n const name = "result" in kept ? _Window.#at(_Window.#at(kept.result, "blueprint"), "name") : void 0;\n if (typeof name === "string" && "result" in worn && _Window.#at(worn.result, "name") !== name) {\n if (await this.#born(given)) await this.ask("nerves", "tearDown", { lobe: held.design });\n return;\n }\n const moved = await this.ask("nerves", "version", { lobe: held.design, faculty: given.digest, settled: true });\n if ("error" in moved) return;\n await this.#tinted(given.settings);\n }\n async #born(given) {\n const kept = await this.#through(null, "library", "get", { digest: given.digest });\n if (this.#unwearable("result" in kept ? _Window.#at(kept.result, "blueprint") : void 0) !== null) return false;\n const created = await this.ask("nerves", "create", { faculty: given.digest, sealed: true });\n const id = "result" in created ? _Window.#at(created.result, "id") : void 0;\n if (typeof id !== "string") return false;\n const ordered = await this.nerves.order({ termination: id, placeholder: "design" });\n if ("error" in ordered) return false;\n this.cells.delete(_Window.#chosen);\n await this.#tinted(given.settings);\n return true;\n }\n async #wornAgain(lobe, given) {\n const ordered = await this.nerves.order({ termination: lobe, placeholder: "design" });\n if ("error" in ordered) return false;\n this.cells.delete(_Window.#chosen);\n await this.#tinted(given.settings);\n return true;\n }\n async #tinted(settings) {\n const tint = _Window.#at(settings, "tint");\n if (typeof tint === "string") await this.ask("design", "set", { tint });\n }\n async worn() {\n const foreign = this.#foreign();\n if (foreign !== null) return foreign;\n const files = await this.ask("design", "files", {});\n return "result" in files ? files.result : this.error(files.error.code, files.error.message);\n }\n async wear(args) {\n if (this.stamp.asker !== "brain" && this.stamp.asker !== _Window.#organ)\n return this.error("refused", "a design is worn by the screen or an owner\'s word through the brain");\n return this.#wearOrTell(args);\n }\n async #wearOrTell(args) {\n const worn = await this.#wearing(args);\n const why = "code" in worn ? worn["message"] : void 0;\n if (typeof why === "string") return this.#unmade(why);\n this.cells.delete(_Window.#unmadeKey);\n return worn;\n }\n async #wearing(args) {\n const design = _Window.#at(args, "design");\n if (typeof design !== "string" || !/^[0-9a-f]{64}$/u.test(design))\n return this.error("refused", "wear names a design by its look\u2019s digest");\n const held = await this.#nerves();\n if ("why" in held) return this.error("unavailable", held.why);\n const lobes = await this.ask("brain", "lobes", { faculty: design });\n if ("error" in lobes) return this.error(lobes.error.code, lobes.error.message);\n const designed = (Array.isArray(lobes.result) ? lobes.result : []).filter((one) => typeof one === "string");\n if (designed.some((one) => one === held.design)) return { design, lobe: held.design };\n const standing = designed[0];\n const unworn = typeof standing === "string" ? await this.#standingUnwearable(standing) : null;\n if (unworn !== null) return unworn;\n const made = typeof standing === "string" ? null : await this.#madeOn(design);\n if (made !== null && typeof made !== "string") return made;\n const lobe = typeof standing === "string" ? standing : made;\n if (typeof lobe !== "string") return this.error("refused", "the brain named no lobe on the look");\n const fenced = await this.#fencedLobe(lobe);\n if (fenced !== null) {\n if (made !== null) await this.ask("brain", "tearDown", { lobe });\n return this.error("refused", fenced);\n }\n const ordered = await this.nerves.order({ termination: lobe, placeholder: "design" });\n if ("error" in ordered) return this.error("refused", `the window wears no ${lobe}: ${ordered.error.message}`);\n const given = await this.#given();\n if (given !== null && given.digest === design) this.cells.delete(_Window.#chosen);\n else this.cells.set(_Window.#chosen, true);\n return { design, lobe };\n }\n static #listedBy(blueprint) {\n const draw = _Window.#at(_Window.#at(blueprint, "methods"), "draw");\n const component = _Window.#at(_Window.#at(_Window.#at(_Window.#at(draw, "args"), "properties"), "component"), "enum");\n return Array.isArray(component) ? component : [];\n }\n #unwearable(blueprint) {\n const drawn = _Window.#listedBy(blueprint);\n if (_Window.#components.every((one) => drawn.includes(one))) return null;\n return this.error(\n "refused",\n "the design draws not the surround, the organism and the lobe: the window cannot wear it"\n );\n }\n async #standingUnwearable(lobe) {\n const described = await this.#through(null, lobe, null, {});\n if ("error" in described)\n return this.error("refused", `the window reads not what ${lobe} draws: ${described.error.message}`);\n return this.#unwearable(described.result);\n }\n async #madeOn(look) {\n const kept = await this.#through(null, "library", "get", { digest: look });\n const blueprint = "result" in kept ? _Window.#at(kept.result, "blueprint") : void 0;\n if (blueprint === void 0) return this.error("refused", `the library keeps no look ${look}`);\n const unworn = this.#unwearable(blueprint);\n if (unworn !== null) return unworn;\n const created = await this.ask("brain", "create", { faculty: look, sealed: true });\n if ("error" in created)\n return this.error("refused", `the brain makes no lobe of ${look}: ${created.error.message}`);\n const id = _Window.#at(created.result, "id");\n return typeof id === "string" ? id : this.error("refused", "the brain named no lobe on the look");\n }\n async #facultiesKept() {\n const listed = await this.#through(null, "library", "list", { limit: _Window.#mostFaculties });\n if ("error" in listed) return void 0;\n const kept = _Window.#at(listed.result, "faculties");\n if (!Array.isArray(kept)) return void 0;\n const faculties = [];\n let more = typeof _Window.#at(listed.result, "cursor") === "string";\n for (const one of kept) {\n const [name, digest] = ["name", "digest"].map((key) => _Window.#at(one, key));\n if (typeof name !== "string" || typeof digest !== "string") continue;\n if (faculties.length < _Window.#mostFaculties)\n faculties.push({ name, label: _Window.#at(one, "label") ?? null, faculty: digest });\n else more = true;\n }\n return { faculties, more };\n }\n #pressOf(args) {\n const foreign = this.#foreign();\n if (foreign !== null) return foreign;\n const id = _Window.#at(args, "id");\n const press = typeof id === "string" ? this.cells.get(["press", id]) : void 0;\n return typeof id === "string" && _Window.#fields(press) ? { id, press } : this.error("refused", "the window kept no such press");\n }\n static #kept(press) {\n if (!("answer" in press || "error" in press)) return void 0;\n return {\n method: _Window.#shown(press["method"]),\n ..."error" in press ? { error: press["error"] } : { answer: press["answer"] ?? null }\n };\n }\n async send(args) {\n const found = this.#pressOf(args);\n if ("code" in found) return found;\n const { id, press } = found;\n const kept = _Window.#kept(press);\n if (kept !== void 0) return kept;\n const method = _Window.#shown(press["method"]);\n if (press["sent"] === true) return { method, unknown: true };\n const [over, lobe] = [typeof press["over"] === "string" ? press["over"] : null, _Window.#shown(press["lobe"])];\n if (this.#consentOf(over, lobe, press)?.["taken"] !== void 0) {\n this.#pressDropped(id);\n return { method, taken: true };\n }\n const consented = this.#consented(over, lobe, press);\n if (!consented) {\n const described = await this.#describedOf(over, lobe);\n const declared = "result" in described ? _Window.#methodOf(described.result, method) : void 0;\n if (_Window.#waits(declared, over)) {\n const fit = _Window.#fit(_Window.#at(declared, "args"), press["values"], press["declared"] === true);\n return this.#heldBack({ over, lobe }, method, "why" in fit ? press["values"] ?? null : fit.values, declared);\n }\n }\n if (!this.#stands(press)) {\n this.#pressDropped(id);\n return this.error("refused", "the place this press was made for is held no more");\n }\n this.cells.set(["press", id], { ...press, sent: true, ...consented ? { took: true } : {} });\n if (consented) this.#consentTaken({ over, lobe }, id);\n this.cells.set(["last", typeof press["over"] === "string" ? press["over"] : "", _Window.#shown(press["lobe"])], id);\n return { method, sending: true };\n }\n static #fitValue(name, schema, value, required) {\n if (typeof value !== "string") return { value };\n if (value === "" && !required) return { value: void 0 };\n const type = _Window.#at(schema, "type");\n if (Array.isArray(_Window.#at(schema, "enum"))) return { value };\n if (type === "string") return { value };\n if (type === "number" || type === "integer") {\n const number = Number(value);\n if (value.trim() === "" || !Number.isFinite(number)) return { why: `${name} is not a number` };\n return type === "integer" && !Number.isInteger(number) ? { why: `${name} is not a whole number` } : { value: number };\n }\n if (type === "boolean") return { value: value === "on" || value === "true" };\n return _Window.#json(name, value);\n }\n static #json(name, text) {\n try {\n const read = JSON.parse(text);\n return { value: read };\n } catch {\n return { why: `${name} is not JSON` };\n }\n }\n static #fit(schema, values, declared = false) {\n const given = _Window.#fields(values) ? values : {};\n const properties = _Window.#at(schema, "properties");\n if (!_Window.#fields(properties)) {\n const text = given["args"];\n if (typeof text !== "string") return { values: declared && _Window.#fields(values) ? values : {} };\n if (text.trim() === "") return { values: {} };\n const read = _Window.#json("args", text);\n return "why" in read ? read : { values: read.value };\n }\n const required = _Window.#at(schema, "required");\n const fitted = {};\n for (const [name, value] of Object.entries(given)) {\n if (!Object.hasOwn(properties, name)) continue;\n const one = _Window.#fitValue(name, properties[name], value, Array.isArray(required) && required.includes(name));\n if ("why" in one) return one;\n if (one.value !== void 0) fitted[name] = one.value;\n }\n return { values: fitted };\n }\n async #asked(far, lobe, method, declared, values, asked = false) {\n const fit = _Window.#unsaid(declared) ? { values: _Window.#fields(values) ? values : {} } : _Window.#fit(_Window.#at(declared, "args"), values, asked);\n if ("why" in fit) return { heard: { error: { code: "refused", message: fit.why } }, given: {} };\n return { heard: _Window.#heard(await this.#through(far, lobe, method, fit.values)), given: fit.values };\n }\n async deliver(args) {\n const found = this.#pressOf(args);\n if ("code" in found) return found;\n const { id, press } = found;\n const kept = _Window.#kept(press);\n if (kept !== void 0) return kept;\n const [lobe, method, over, seen] = [press["lobe"], press["method"], press["over"], press["seen"]];\n if (press["sent"] !== true || typeof lobe !== "string" || typeof method !== "string")\n return this.error("refused", "a press is delivered after it is sent");\n const far = typeof over === "string" ? over : null;\n const described = await this.#describedOf(far, lobe);\n let heard;\n const declared = "result" in described ? _Window.#methodOf(described.result, method) : void 0;\n const version = "result" in described ? _Window.#at(described.result, "version") : void 0;\n if ("error" in described)\n heard = { error: { code: "unavailable", message: `${lobe} did not answer: ${described.error.message}` } };\n else if (declared === void 0 || _Window.#reads(declared))\n heard = { error: { code: "refused", message: `${lobe} declares no writing method ${method}` } };\n else if (_Window.#waits(declared, far) && press["took"] !== true)\n heard = {\n error: {\n code: "refused",\n message: _Window.#irreversible(declared) ? `${method} cannot be undone: it is asked only with the person\'s consent, which the home asks first` : `${lobe} says nothing of what ${method} does: it is asked only with the person\'s consent, which the home asks first`\n }\n };\n else if (press["declared"] === true && _Window.#at(_Window.#at(declared, "seat"), "for") === "machine")\n heard = {\n error: { code: "refused", message: `${method} is declared for a machine: a declared press asks it not` }\n };\n else if (typeof seen === "string" && version !== seen)\n heard = {\n error: { code: "stale", message: `the screen showed version ${seen}, and ${_Window.#shown(version)} stands` }\n };\n else {\n const asked = await this.#asked(far, lobe, method, declared, press["values"], press["declared"] === true);\n heard = _Window.#shaped(declared, asked.heard, this.stamp.time, _Window.#filesOf(asked.given), far !== null);\n this.#movedAt(far);\n }\n if (press["took"] === true) this.#consentSpent({ over: far, lobe }, id);\n if (!this.#stands(press)) {\n this.#pressDropped(id);\n return { method, ...heard };\n }\n const channeled = "answer" in heard && _Window.#at(_Window.#seatOf(declared), "intent") === "channel";\n this.cells.set(["press", id], { ...press, ...heard, ...channeled ? { channeled: true } : {} });\n this.cells.set(["last", far ?? "", lobe], id);\n return { method, ...heard };\n }\n async #wiresOf(over, lobe) {\n let node;\n let cursor = null;\n for (let page = 0; page < _Window.#mostListed && node === void 0; page += 1) {\n const state = await this.ask(\n over ?? "brain",\n "state",\n cursor === null ? {} : { cursor },\n _Window.#lobeWithin\n );\n if ("error" in state) return { why: `the brain\'s state is not read: ${state.error.message}` };\n const nodes = _Window.#at(state.result, "nodes");\n node = Array.isArray(nodes) ? nodes.find((one) => _Window.#at(one, "id") === lobe) : void 0;\n const next = _Window.#at(state.result, "cursor");\n cursor = typeof next === "string" ? next : null;\n if (cursor === null) break;\n }\n if (node === void 0 && cursor !== null) return { why: _Window.#cutSay(_Window.#mostListed) };\n if (node === void 0) return { why: `the brain holds no ${lobe}` };\n const wires = {};\n const held = _Window.#at(node, "wires");\n for (const wire of Array.isArray(held) ? held : []) {\n const placeholder = _Window.#at(wire, "placeholder");\n const termination = _Window.#at(wire, "termination");\n if (typeof placeholder === "string" && typeof termination === "string") wires[placeholder] = termination;\n }\n return { wires };\n }\n static words = {\n homeWord: "Home",\n wayOutSay: "Home",\n leaveSay: "Leave this place",\n leavingSay: "Leave this place? You will no longer hold its standing, and it is given up with it.",\n yesSay: "Yes",\n noSay: "No",\n unsaidSay: "This place does not say what this ask does, and it may change something. Ask it?",\n irreversibleSay: "This cannot be undone. Ask it?",\n organismSilentSay: "This organism did not answer.",\n lobeSilentSay: "This lobe did not answer.",\n moreFacultiesSay: "The library keeps more faculties than this page shows.",\n redeemUnreachedSay: "the place this link leads to was not reached. The link is not spent: try again",\n redeemTimeoutSay: "no reply came in time. The link may be spent: try once more, and ask for a new link if it fails",\n redeemSpentSay: "the link is spent, ended or wrong: ask for a new one"\n };\n};\nexport {\n Window as default\n};\n';
28732
+ var WINDOW_SOURCE = 'var LOBE_SHARE = 4;\nvar LOBE_WAIT = 3500;\nvar NAME_WAIT = 1e3;\nvar DESCRIBING = 16;\nvar KEPT_ANSWER = 16384;\nvar KEPT_SHARE = 32;\nvar MOST_FACULTIES = 100;\nvar MOST_LISTED = 10;\nvar MOST_RELATIONS = 100;\nvar MOST_RELATION_PAGES = 20;\nvar STATE_SHARE = 256;\n\nimport { Faculty } from "nervur:faculty";\nvar Window = class _Window extends Faculty {\n #lang = "en";\n static #themed(given) {\n return given === "dark" ? "dark" : "light";\n }\n static #wayAt = "bottom-end";\n async #draws(asked) {\n return this.ask("design", "draw", { ...asked, lang: this.#lang });\n }\n static #langOf(given) {\n return typeof given === "string" ? given : "en";\n }\n #keptReads() {\n return Math.floor(this.memory / KEPT_SHARE / _Window.#keptAnswer);\n }\n #mostState() {\n return Math.floor(this.memory / KEPT_SHARE / STATE_SHARE);\n }\n #keptHalf() {\n return Math.floor(this.#keptReads() / 2);\n }\n static #organ = "screen";\n static #lobeWithin = LOBE_WAIT;\n static #nameWithin = NAME_WAIT;\n static #describing = DESCRIBING;\n static #keptAnswer = KEPT_ANSWER;\n static #mostFaculties = MOST_FACULTIES;\n static #unmadeKey = ["unmade"];\n static #aboutKey = ["about"];\n static #world = "network";\n static #mostListed = MOST_LISTED;\n static #mostRelations = MOST_RELATIONS;\n static #mostRelationPages = MOST_RELATION_PAGES;\n static #id = { type: "string", minLength: 1, maxLength: 64 };\n static #name = { type: "string", minLength: 1, maxLength: 200 };\n static #wires = { type: "object", additionalProperties: { type: "string" } };\n static #relation = { type: "string", pattern: "^[A-Za-z][A-Za-z0-9_-]{0,63}$", maxLength: 64 };\n static #own = ["screen", "brain", "design", "mouth", "ear", "cells", "nerves"];\n static #step = {\n anyOf: [\n {\n type: "object",\n properties: { relation: _Window.#relation },\n required: ["relation"],\n additionalProperties: false\n },\n { type: "object", properties: { lobe: _Window.#id }, required: ["lobe"], additionalProperties: false }\n ]\n };\n static #route = { type: "array", items: _Window.#step, maxItems: 2 };\n static #relationName = /^[A-Za-z][A-Za-z0-9_-]{0,63}$/u;\n static #theme = { enum: ["light", "dark"] };\n static #cursor = { anyOf: [{ type: "string", maxLength: 200 }, { type: "null" }] };\n static #cells = { anyOf: [{ type: "string", maxLength: 200 }, { type: "null" }] };\n static #digest = { type: "string", pattern: "^[0-9a-f]{64}$" };\n static #pressId = { type: "string", minLength: 1, maxLength: 64 };\n static #link = {\n type: "object",\n properties: {\n card: {\n type: "object",\n properties: {\n ward: { type: "string", pattern: "^[0-9a-f]{128}$" },\n at: { type: "array", items: { type: "string", minLength: 1 } }\n },\n required: ["ward", "at"],\n additionalProperties: false\n },\n reference: { type: "string", pattern: "^[a-z0-9]{1,64}$" }\n },\n required: ["card", "reference"],\n additionalProperties: false\n };\n static #span = { anyOf: [{ type: "integer", minimum: 0 }, { type: "null" }] };\n static #components = ["surround", "organism", "lobe"];\n static #chosen = ["chosen"];\n static #openWalk = "The person walks to a route: `route`, a path of at most a relation the window holds and a lobe, or `lobe` alone, the route `[{lobe}]` at home, `[]` the home. The screen shows it from now on.";\n static #openDescribe = "A walk to a route that reaches a lobe over a relation describes that lobe and keeps its describe in the cells (by the relation and the lobe, with the version it answers; a walk hears again the version that stands and keeps that one), and keeps what a far lobe answers its `state`, so a sight asks no describe.";\n static #openTold = "`told` `{size, language, standard}` is what the home tells a place of its screen: a far lobe the walk reaches that declares a writing method `told` is asked it with those three, the first time and again only where one moved.";\n static #seePage = "What the screen shows at a route (the one walked to where none is given): the page in the slot `main`, inside the home\'s surround, drawn by the design lobe the window wears, only where the home has something to say, a warning or a consent; else `tree` is the slot `main` alone. An organism\'s page holds its state, its lobes each as its describe says, and the relations the window holds at home, each with `place` where it is a far lobe; a lobe\'s (a far lobe\'s too, at `/<relation>`), its description, its state at once, the answers kept of its other reading methods, and its writing methods, unless the lobe draws itself, which then draws the page. Where any method of a lobe declares a seat for a person, only the methods whose seat is for a person or both are drawn, each with its seat\'s `label` in `args.lang`\'s words; a method whose seat is for a machine is never drawn. An ask the describe names and says nothing of (no `kind`) is among its writing methods, never read, kept or asked unpressed, and a lobe draws itself only by a `draw` it declares a reading. Over a relation the describe is the one the walk kept, asked again only by a walk. A far lobe tells no cells digest: an answer of its reading methods kept at a walk or by a `read` press is drawn by every sight and asked again only once a press that wrote landed or the person walked in again, the walk asking it once more and keeping it. Answers `{route, text, tree, main, version, design, way?, channel?}`: `main` names the lobe that draws the slot, over which relation, and with which args; `design` the design lobe the window wears, by which the host dresses the home. `args.cursor` is the place in a long list, `args.cells` the cells digest the screen holds of the lobe, `args.theme` the theme, `args.lang` the person\'s language, which every draw asked of the design carries as `lang`. The home\'s own words are English, whatever `args.lang` names; a seat\'s words are the place\'s, picked in `args.lang`. Where the last press of a place answered a file or an upload, the answer holds `channel`, the checked shape, for the host to follow.";\n static #seeLeave = "A place the window holds that is a far lobe is left by one press of the window\'s own, `leave {press, say}`, `press` `{method: \'leave\', args: {relation}}` and `say` the home\'s word: `see` answers it beside the way out as `way.leave`, in the region the host lays above the page outside every tree, and forces no surround. The surround is drawn while its consent is asked, as any consent is. A press `leave {relation}` on the lobe that drew the page is the window\'s own act, as `wear` is: unconsented, or carrying a consent the home\'s local state asks not for that relation, it sets the consent in the local state of the region `#consent`, which the surround then carries as `consent` whose `yes` is the same press with `consented: true`, and answers `{asking: \'leave\'}`; consented it ends the standing whole, by the brain\'s `drop` naming it, so no lobe keeps a place its person left, forgets what the window kept of it, walks the person home where the route stood on it, and answers `{left: relation}`. A relation that reaches a far organism is an owner\'s standing and is never left so: the press is refused.";\n static #seeHome = "At home the floor\'s page is the organism\'s describe page whole, titled and crumbed `Home`: its state, its organs, its lobes, its relations, the faculties the library keeps, of the first page of its `list`, and `about`. A far organism\'s page is its own, whole.";\n static #seeWay = "`way {at, say, leave?}` stands above every page but the home\'s own, for the host to lay outside every tree: `at` `bottom-end`, fixed in the window, `say` the way out home in the home\'s word, and `leave` a place\'s leave. Beside `way`, a window may hand `world {say, yes, no}`, the three words of the ask the screen puts above the page before a link of the world opens, in the language of its choice: `say` holds `{href}`, where the screen puts the address the link leads to; this window hands none, and the screen\'s English stands.";\n static #pressCarried = "A press, asked of the lobe that drew it, or of the lobe wired at its `to` among that lobe\'s placeholders, through the brain\'s `ask` or over `over`, with its `args` and of the `values` the person committed around it those its method declares in its args, by name, fitted as a form\'s are; a field it does not declare stays on the device. Answers what the lobe answered.";\n static #pressConsent = "The describe is read first (over a relation the one the walk kept, else asked; a press refused where none answers): a press on a method its describe declares `irreversible`, or, over a relation, on an ask the place says nothing of, asks nothing, sets the home\'s consent as `send` does with the args it carried, and answers `{method, asking: true}`; its `yes` is the declared ask.";\n static #pressKept = "A press over a far lobe on a method it declares no reading moves what was kept of its answers, asked again at the next sight.";\n static #pressAbout = "A press `about {faculty}` on the lobe that drew the home is the window\'s own act, as `create` is: the faculty the library keeps under that digest, before a lobe stands on it, answered and kept for the home\'s next page as `about {faculty, name, version, placeholders, skins, world}`, its placeholders each with what it expects, the organs of this organism it is a skin lobe of (each placeholder under an organ\'s fixed ID expecting that organ\'s blueprint name), and whether it talks to the world, a skin lobe of `network`; it shows and never locks, so `create` makes the lobe whether or not it was looked at. One the library keeps not is told as `create`\'s refusal is. The next walk or `create` forgets it.";\n static #sendMarked = "The second step: the press kept under `id` is marked sent, and the mark is committed by this ask\'s answer, before the ask of the lobe is made (by `deliver`), so a cut off ask never rolls it back to unsent. Answers `{method, sending: true}` once; a press already sent and not answered answers `{method, unknown: true}`, the outcome not known, and asks nothing; one answered answers what was kept. A yes sent takes the home\'s consent it answers, which stands drawn until its ask is answered: a yes that finds it taken answers `{method, taken: true}`, is kept no more and asks nothing.";\n static #sendDeclared = "A press on a method its describe declares `irreversible`, or on an ask its place names and says nothing of (its describe\'s entry names no `kind`, as a door of a kit that is no Nervur\'s describes every ask), is not sent: the home\'s consent is set in the local state of the region `#consent` (no method of a place is so named) where the route\'s surround reads it, `{asking, lobe, args, label?, irreversible?}`, `args` the values the press carried made to fit, and the surround is drawn with `consent {say, yes, no, yesSay, noSay}`, the home\'s words saying it cannot be undone, or that the place does not say what it does and that it may change something, `yes` the same ask (`ask`, with those args and `consented: true`), `no` clearing it; answers `{method, asking: true}` and nothing leaves. Only a press with that consent, while the home\'s own local state still asks it, is sent (a `local` press never sets it), and the consent is spent with the ask.";\n static #offerRead = "What a link offers, read before its reference is spent: the mouth\'s `once` asks `#offer` of the card\'s ward on its zero head, which spends nothing, and what is answered is `{says, waits, lives}`, what the invitation says (null for nothing) as the place\'s own word, the milliseconds left of its wait and those its relation lives, each null for none, the screen\'s to show in the consent; `{reached: false}` where the place was not reached or no reply came in time, nothing else in it, for the consent to say so before the yes; null where the place answered and gave no offer, a place of another kit among them, which still redeems: the consent is drawn without an offer.";\n static #offerRefused = "Only the screen asks it; it refuses only a link that names no card and reference.";\n static #acceptTaken = "The person\'s consent: the mouth accepts `invitation` under the placeholder `placeholder`, with `note` (kept by the brain beside the standing, never sent to the inviter; null where none), and the first ask over it is the knock, a describe; one never answered is ended whole, by the brain\'s `drop`, and refused; the describe the knock of a far lobe heard is kept as a walk keeps it.";\n static #acceptRefused = "Refused for one of the window\'s own placeholders (`screen`, `brain`, `design`, `mouth`) and one it holds already. Only the screen asks it.";\n static #acceptKnock = "Everything the window kept of a relation of that name before is forgotten first, so the new standing reads nothing of the last. A knock that answers a blueprint other than `nervur.brain` makes the relation a far lobe, kept in the cells until the window is asked `left` of it. Answers `{far, route, text}`: the organism or lobe now held, and the route and text that reach it at once.";\n static blueprint = {\n name: "nervur.window",\n version: "0.35.15",\n description: "The screen\'s present lobe: it keeps the route the person walked, draws the organism or the lobe at its end by the describe look of the design lobe it wears, inside the home\'s surround where the home has something to say, asks each lobe the screen draws its draw through the brain\'s `ask`, or through the far brain\'s over a relation it holds, and, over a relation that reaches a far lobe, directly over the placeholder, and carries each press: a press that reads keeps its answer, one that writes is kept before it leaves and asked once, one that binds the person waits for their yes. Presence is one person: it holds the relations its owners hold, wired under the placeholders the console holds them by, and its `design` is wired to the design lobe that dresses what it draws.",\n methods: {\n open: {\n description: [_Window.#openWalk, _Window.#openDescribe, _Window.#openTold].join(" "),\n kind: "writing",\n args: {\n type: "object",\n properties: {\n route: _Window.#route,\n lobe: _Window.#id,\n told: {\n type: "object",\n properties: {\n size: { enum: ["compact", "medium", "expanded"] },\n language: { type: "string", maxLength: 35 },\n standard: { type: "string", maxLength: 35 }\n },\n required: ["size", "language", "standard"],\n additionalProperties: false\n }\n },\n additionalProperties: false\n },\n result: _Window.#routed(),\n errors: ["refused"]\n },\n root: {\n description: "The route the person walked to, `[]` where they walked nowhere, the home, and its text.",\n kind: "reading",\n args: { type: "object", properties: {}, additionalProperties: false },\n result: _Window.#routed(),\n errors: ["refused"]\n },\n see: {\n description: [_Window.#seePage, _Window.#seeLeave, _Window.#seeHome, _Window.#seeWay].join(" "),\n kind: "reading",\n args: {\n type: "object",\n properties: {\n route: _Window.#route,\n args: {\n type: "object",\n properties: {\n cursor: _Window.#cursor,\n cells: _Window.#cells,\n theme: _Window.#theme,\n lang: { type: "string", pattern: "^[A-Za-z]{2,3}(-[A-Za-z0-9]{2,8})*$", maxLength: 35 }\n },\n additionalProperties: false\n }\n },\n additionalProperties: false\n },\n errors: ["refused"]\n },\n show: {\n description: "A lobe\'s draw, its args what its parent\'s slot gives it, asked through the brain\'s `ask`, or the far brain\'s over `over`: its tree, and the lobe wired at each of its placeholders, where the screen draws its slots. A draw\'s error is answered as heard.",\n kind: "reading",\n args: {\n type: "object",\n properties: { lobe: _Window.#id, args: {}, over: _Window.#relation },\n required: ["lobe", "args"],\n additionalProperties: false\n },\n result: {\n type: "object",\n properties: { tree: {}, wires: _Window.#wires },\n required: ["tree", "wires"],\n additionalProperties: false\n },\n errors: ["refused"]\n },\n press: {\n description: [_Window.#pressCarried, _Window.#pressConsent, _Window.#pressKept, _Window.#pressAbout].join(" "),\n kind: "writing",\n args: {\n type: "object",\n properties: {\n lobe: _Window.#id,\n method: _Window.#name,\n args: {},\n values: { type: "object" },\n to: _Window.#id,\n over: _Window.#relation\n },\n required: ["lobe", "method", "args"],\n additionalProperties: false\n },\n errors: ["refused"]\n },\n read: {\n description: "The press the look draws on a reading method: the lobe at `path`, a route\'s text, is asked the method, which must be one it declares a reading (an ask a door says nothing of is none), the describe over a relation the one its walk kept, with `values`, the fields the person filled of its args (none where it takes none), and its answer or error is kept in the cells under the lobe, the method and `cells`, the cells digest the screen holds of the lobe, with the values it was asked with, so each `see` shows it and asks again, with the same values, only once the cells moved. Answers whether an answer or an error was kept.",\n kind: "writing",\n args: {\n type: "object",\n properties: {\n path: { type: "string", maxLength: 300 },\n method: _Window.#name,\n cells: _Window.#cells,\n values: { type: "object" }\n },\n required: ["path", "method"],\n additionalProperties: false\n },\n errors: ["refused"]\n },\n write: {\n description: "The first half of the press the look draws on a writing method: it keeps the press in the cells, under `id`, naming the lobe at `path`, the method, the `values` the screen collected and `seen`, the version of the lobe the screen showed, before anything leaves. A press kept under an `id` is kept once. Answers the `id`.",\n kind: "writing",\n args: {\n type: "object",\n properties: {\n id: _Window.#pressId,\n path: { type: "string", maxLength: 300 },\n method: _Window.#name,\n values: { type: "object" },\n seen: { anyOf: [{ type: "string", maxLength: 200 }, { type: "null" }] },\n declared: { type: "boolean" },\n consented: { type: "boolean" }\n },\n required: ["id", "path", "method", "values", "seen"],\n additionalProperties: false\n },\n errors: ["refused"]\n },\n local: {\n description: "A change of the local state of a region of the page at the route walked: `state` is merged into the state the window keeps for `region` (a key set to null is dropped), bounded in size and keys, kept while the route stands and forgotten at the next walk; no lobe and no place hears it. `field` names the key of `state` that holds text a person typed, kept as any other. The region `#consent` is the home\u2019s: a `local` press may only clear it.",\n kind: "writing",\n args: {\n type: "object",\n properties: {\n region: { type: "string", minLength: 1, maxLength: 64 },\n state: { type: "object" },\n field: _Window.#name\n },\n required: ["region", "state"],\n additionalProperties: false\n },\n errors: ["refused"]\n },\n send: {\n description: [_Window.#sendMarked, _Window.#sendDeclared].join(" "),\n kind: "writing",\n args: {\n type: "object",\n properties: { id: _Window.#pressId },\n required: ["id"],\n additionalProperties: false\n },\n errors: ["refused"]\n },\n deliver: {\n description: "The third step, posted once after `send` answered `sending`: the lobe is described (over a relation, by the describe its walk kept, so the press reaches the place as its one ask) and asked the writing method once, a method that binds the person only with the consent `send` asked, if it still stands at the version seen (else `stale`, with the version that stands), and what it answered is kept beside the press, shown on the next `see` of that lobe. A press is kept with the standing it was made under: one whose standing ended while it was in flight is forgotten and its answer kept nowhere, so a place given again under that name never reads it. Cut off, it leaves the press sent with the outcome unknown, and nothing asks again.",\n kind: "writing",\n args: {\n type: "object",\n properties: { id: _Window.#pressId },\n required: ["id"],\n additionalProperties: false\n },\n errors: ["refused"]\n },\n piece: {\n description: "Asked by the host for a piece of a file the place\'s own lobe holds, which a press answered and the host has not told: `at` the byte it starts at, below the file\'s size. The lobe is asked its reading method `piece` with `{sha256, at, length}`, `length` the file\'s bytes left from `at` and at most a share of the window\'s memory, and the piece is answered as those bytes; a piece that is not exactly that many bytes, or that the lobe refuses, is refused in words, none handed on. A press that answered no such file, or one told already, is refused, and the lobe is asked nothing.",\n kind: "reading",\n args: {\n type: "object",\n properties: { id: _Window.#pressId, at: { type: "integer", minimum: 0 } },\n required: ["id", "at"],\n additionalProperties: false\n },\n errors: ["refused"]\n },\n landed: {\n description: "Posted by the host once it sent the file of an upload a press answered, or refused to, or refused a file it fetched for the page: `landed` whether it landed, `why` the words of a refusal. The press is marked told, so `see` hands the channel on no more and it is followed once; for an upload the lobe is asked `landed` with `{sha256, landed}`, never a byte; a file that did not land, either way, is kept as the press\'s refusal, said in words. Answers `{landed}`, for an upload with what the lobe answered; a press that answered no file or upload, or one told already, is refused.",\n kind: "writing",\n args: {\n type: "object",\n properties: {\n id: _Window.#pressId,\n landed: { type: "boolean" },\n why: { type: "string", maxLength: 300 }\n },\n required: ["id", "landed"],\n additionalProperties: false\n },\n errors: ["refused"]\n },\n worn: {\n description: "The design the window wears, for the screen to lay: the lobe wired at `design` is asked its `files`, and what it answered is answered, the design\u2019s parts with the lobe\u2019s settings laid over them; an error is answered as heard.",\n kind: "reading",\n args: { type: "object", properties: {}, additionalProperties: false },\n errors: ["refused"]\n },\n wear: {\n description: "An owner\'s word through the brain\'s `ask`, or the screen\'s: the window wears the design whose look has the faculty digest `design`, one the library keeps (refused where its look draws not `surround`, `organism` and `lobe`, or where a sheet of it loads outside its bundle): it finds a lobe on that look, or has the brain make one, and orders its own wire `design` to that lobe, which only the window orders; answers `{design, lobe}`, and changes nothing where that design is worn already. A design it cannot wear is told as `create`\'s refusal is: the answer `{refused: why}`, nothing changed, the why kept for the home\'s next page. A press `{method: \'wear\', args: {design}}` on the lobe wired at `design` is this ask; the floor\'s design draws none.",\n kind: "writing",\n askers: ["screen", "brain"],\n args: {\n type: "object",\n properties: { design: _Window.#digest },\n required: ["design"],\n additionalProperties: false\n },\n errors: ["refused"]\n },\n back: {\n description: "The brain\'s alone: where the placeholder that came back is `screen`, the window lays the design its port gave it by the name `design`: where its `design` is wired to nothing it creates its own child on that look, sealed, wires `design` to it and sets the tint the port named; where its own child stands on another digest it moves the child to the port\'s, unless the person chose another design. A connect that finds the design as it should be changes nothing.",\n kind: "writing",\n askers: ["brain"],\n args: {\n type: "object",\n properties: { placeholder: { type: "string", minLength: 1 } },\n additionalProperties: true\n },\n errors: ["refused"]\n },\n redeem: {\n description: "The link a person opened, `card` and `reference`, redeemed once: the mouth\'s `once` asks `#redeem` of the card\'s ward on its zero head, and what is answered is `{invitation}`, the invitation the reply\'s object is, the screen\'s to show for consent. Every failure is answered `refused`, in words that say whether to try again: a far side not reached, the link unspent; a reply that came not in time, the link maybe spent; silence, or an answer that is no invitation, the link spent, ended or wrong. Only the screen asks it.",\n kind: "writing",\n args: _Window.#link,\n result: {\n type: "object",\n properties: { invitation: { type: "string", minLength: 1 } },\n required: ["invitation"],\n additionalProperties: false\n },\n errors: ["refused"]\n },\n offer: {\n description: [_Window.#offerRead, _Window.#offerRefused].join(" "),\n kind: "reading",\n args: _Window.#link,\n result: {\n anyOf: [\n {\n type: "object",\n properties: {\n says: {},\n waits: _Window.#span,\n lives: _Window.#span\n },\n required: ["says", "waits", "lives"],\n additionalProperties: false\n },\n {\n type: "object",\n properties: { reached: { const: false } },\n required: ["reached"],\n additionalProperties: false\n },\n { type: "null" }\n ]\n },\n errors: ["refused"]\n },\n standings: {\n description: "Its screen\'s alone. The relations the window holds, read of its nerves and their notes, drawing nothing and asking no far organism: `{relations}`, each its `placeholder`, its `note` and `place` where it is a place, so a page of a site finds the standing it gave; `more` where the window holds more notes than it read, those past them answered `null`.",\n kind: "reading",\n args: { type: "object", properties: {}, additionalProperties: false },\n result: {\n type: "object",\n properties: {\n relations: {\n type: "array",\n items: {\n type: "object",\n properties: { placeholder: { type: "string" }, note: {}, place: { const: true } },\n required: ["placeholder", "note"],\n additionalProperties: false\n }\n },\n more: { const: true }\n },\n required: ["relations"],\n additionalProperties: false\n },\n errors: ["refused"]\n },\n left: {\n description: "The brain\u2019s alone: the standing of `far` ended; everything the window kept of the relation it was held at is forgotten, its far lobe or far organism, their describes, reads, presses and answers and local state; nothing else is asked or written.",\n kind: "writing",\n askers: ["brain"],\n args: {\n type: "object",\n properties: { far: { type: "string", minLength: 1 }, note: {} },\n required: ["far"],\n additionalProperties: false\n },\n result: { type: "null" }\n },\n accept: {\n description: [_Window.#acceptTaken, _Window.#acceptRefused, _Window.#acceptKnock].join(" "),\n kind: "writing",\n args: {\n type: "object",\n properties: {\n invitation: { type: "string", minLength: 1 },\n placeholder: _Window.#relation,\n note: {}\n },\n required: ["invitation", "placeholder"],\n additionalProperties: false\n },\n result: {\n type: "object",\n properties: {\n far: { type: "string", minLength: 1 },\n route: _Window.#route,\n text: { type: "string", maxLength: 300 }\n },\n required: ["far", "route", "text"],\n additionalProperties: false\n },\n errors: ["refused"]\n }\n },\n placeholders: {\n screen: "nervur.screen",\n brain: "nervur.brain",\n design: null,\n mouth: "nervur.mouth",\n ear: "nervur.ear"\n }\n };\n static #routed() {\n return {\n type: "object",\n properties: { route: _Window.#route, text: { type: "string", maxLength: 300 } },\n required: ["route", "text"],\n additionalProperties: false\n };\n }\n static #fields(data) {\n return typeof data === "object" && data !== null && !Array.isArray(data) && !(data instanceof Uint8Array);\n }\n static #at(data, key) {\n return _Window.#fields(data) ? data[key] : void 0;\n }\n #foreign() {\n return this.stamp.asker === _Window.#organ ? null : this.error("refused", "only the screen opens, draws and presses");\n }\n static #over(args) {\n const over = _Window.#at(args, "over");\n if (over === void 0 || over === null) return null;\n return typeof over === "string" && !_Window.#own.includes(over) ? over : void 0;\n }\n #farLobe(over) {\n return over !== null && _Window.#fields(this.cells.get(["far-lobe", over]));\n }\n async #through(over, lobe, method, args) {\n if (over !== null && this.#farLobe(over)) {\n const heard = await this.ask(over, method, args, _Window.#lobeWithin);\n if ("error" in heard && heard.error.code === "removed") await this.#ended(over);\n return method === null ? _Window.#blueprintOf(heard) : heard;\n }\n const asked = { lobe, method, args, timeout: _Window.#lobeWithin };\n return this.ask(over ?? "brain", "ask", asked, _Window.#lobeWithin);\n }\n async #ended(over) {\n const far = _Window.#at(this.cells.get(["far-lobe", over]), "far");\n if (typeof far === "string" && far !== "") await this.#ends(far);\n }\n async #ends(far) {\n return this.ask("brain", "drop", { far });\n }\n static #blueprintOf(heard) {\n if (!("result" in heard)) return heard;\n const asks = _Window.#at(heard.result, "asks");\n if (!Array.isArray(asks) || !_Window.#fields(heard.result)) return heard;\n const { asks: _, lang: __, ...about } = heard.result;\n const methods = {};\n for (const one of asks) {\n const method = _Window.#at(one, "method");\n if (typeof method !== "string" || !_Window.#fields(one)) continue;\n const { method: ___, ...entry } = one;\n methods[method] = entry;\n }\n return { result: { ...about, methods } };\n }\n static #lobeName(lobe) {\n return lobe.length >= 1 && lobe.length <= 64 && Array.from(lobe).every((one) => one.charCodeAt(0) > 31 && one.charCodeAt(0) !== 127);\n }\n static #routeOf(value) {\n if (!Array.isArray(value) || value.length > 2) return void 0;\n const steps = [];\n for (const step of value) {\n const relation = _Window.#at(step, "relation");\n const lobe = _Window.#at(step, "lobe");\n if (typeof relation === "string" && lobe === void 0 && _Window.#relationName.test(relation) && !_Window.#own.includes(relation))\n steps.push({ relation });\n else if (typeof lobe === "string" && relation === void 0 && _Window.#lobeName(lobe)) steps.push({ lobe });\n else return void 0;\n }\n const [first, second] = steps;\n if (second !== void 0 && (first === void 0 || !("relation" in first) || !("lobe" in second)))\n return void 0;\n return steps;\n }\n static #segment(id) {\n return encodeURIComponent(id).replaceAll(/[!\'()*]/gu, (one) => `%${one.charCodeAt(0).toString(16).toUpperCase()}`);\n }\n static #text(route) {\n const [first, second] = route;\n const relation = _Window.#at(first, "relation");\n const lobe = _Window.#at(second, "lobe") ?? _Window.#at(first, "lobe");\n if (typeof lobe !== "string") return typeof relation === "string" ? `/${relation}` : "/";\n return typeof relation === "string" ? `/${relation}/${_Window.#segment(lobe)}` : `/~/${_Window.#segment(lobe)}`;\n }\n static #read(text) {\n if (typeof text !== "string" || !text.startsWith("/")) return void 0;\n if (text === "/") return [];\n const [first = "", second, ...rest] = text.slice(1).split("/");\n if (rest.length > 0) return void 0;\n let step;\n if (second !== void 0) {\n let lobe;\n try {\n lobe = decodeURIComponent(second);\n } catch {\n return void 0;\n }\n if (_Window.#segment(lobe) !== second) return void 0;\n step = { lobe };\n }\n const route = _Window.#routeOf(\n first === "~" ? step !== void 0 && "lobe" in step ? [step] : void 0 : step === void 0 ? [{ relation: first }] : [{ relation: first }, step]\n );\n return route !== void 0 && _Window.#text(route) === text ? route : void 0;\n }\n static #relationOf(route) {\n const relation = _Window.#at(route[0], "relation");\n return typeof relation === "string" ? relation : null;\n }\n static #lobeOf(route) {\n const lobe = _Window.#at(route.at(-1), "lobe");\n return typeof lobe === "string" ? lobe : null;\n }\n #lobeOfFarLobe(route) {\n return _Window.#lobeOf(route) !== null && this.#farLobe(_Window.#relationOf(route));\n }\n #walked() {\n return _Window.#routeOf(this.cells.get(["root"])) ?? [];\n }\n async open(args) {\n const foreign = this.#foreign();\n if (foreign !== null) return foreign;\n const [given, lobe] = [_Window.#at(args, "route"), _Window.#at(args, "lobe")];\n if (given === void 0 === (lobe === void 0)) return this.error("refused", "open names a route, or a lobe");\n const route = _Window.#routeOf(given === void 0 ? [{ lobe: lobe ?? null }] : given);\n if (route === void 0)\n return this.error("refused", "open names no route: a relation the window holds and a lobe");\n if (route.length === 0 || _Window.#relationOf(route) !== null) await this.#learn(route);\n if (this.#lobeOfFarLobe(route)) return this.error("refused", "a far lobe has no lobes");\n if (JSON.stringify(route) !== JSON.stringify(this.#walked())) this.#forgetLocals();\n this.cells.delete(_Window.#unmadeKey);\n this.cells.delete(_Window.#aboutKey);\n this.cells.set(["root"], route);\n await this.#walkDescribed(route);\n await this.#tell(route, _Window.#at(args, "told"));\n const walkedOver = _Window.#relationOf(route);\n if (this.#indexed(["reads"]).some((key) => Array.isArray(key) && key[1] === walkedOver)) this.#movedAt(walkedOver);\n await this.#stateKept(route);\n await this.#keptAgain(route);\n return { route, text: _Window.#text(route) };\n }\n async #tell(route, told) {\n const over = _Window.#relationOf(route);\n if (over === null || !this.#farLobe(over) || !_Window.#fields(told)) return;\n const { size, language, standard } = told;\n if (typeof size !== "string" || typeof language !== "string" || typeof standard !== "string") return;\n if (_Window.#at(_Window.#methodOf(this.#keptDescribed(over, over), "told"), "kind") !== "writing") return;\n const far = _Window.#at(this.cells.get(["far-lobe", over]), "far") ?? "";\n const kept = this.cells.get(["told", over]);\n const last = _Window.#at(kept, "told");\n const same = _Window.#at(kept, "far") === far && _Window.#at(last, "size") === size && _Window.#at(last, "language") === language && _Window.#at(last, "standard") === standard;\n if (same) return;\n const heard = await this.#through(over, over, "told", { size, language, standard });\n if ("result" in heard) this.cells.set(["told", over], { far, told: { size, language, standard } });\n }\n async #learn(walkedTo) {\n const walked = _Window.#relationOf(walkedTo);\n const read = await this.nerves.read();\n const held = "result" in read && Array.isArray(read.result) ? read.result : [];\n const unknown = held.flatMap((one) => {\n const [placeholder, far] = [_Window.#at(one, "placeholder"), _Window.#at(one, "termination")];\n const relation = typeof placeholder === "string" && typeof far === "string" && !_Window.#own.includes(placeholder) && _Window.#relationName.test(placeholder) && _Window.#at(one, "status") === "far";\n if (!relation || typeof placeholder !== "string" || typeof far !== "string") return [];\n const known = this.#farLobe(placeholder) || this.cells.get(["far-organism", placeholder]) === far;\n return known ? [] : [{ placeholder, far }];\n });\n const first = unknown.toSorted((one, other) => Number(other.placeholder === walked) - Number(one.placeholder === walked)).slice(0, _Window.#describing);\n const knocks = await Promise.all(\n first.map(({ placeholder }) => this.ask(placeholder, null, {}, _Window.#lobeWithin))\n );\n for (const [at, knocked] of knocks.entries()) {\n const { placeholder, far } = first[at] ?? { placeholder: "", far: "" };\n if ("result" in knocked) this.#keepKnocked(placeholder, far, knocked);\n }\n }\n #keepKnocked(placeholder, far, knocked) {\n const blueprint = "result" in knocked ? _Window.#at(knocked.result, "name") : void 0;\n if (blueprint === "nervur.brain") {\n this.cells.set(["far-organism", placeholder], far);\n return;\n }\n this.cells.delete(["far-organism", placeholder]);\n this.cells.set(["far-lobe", placeholder], { blueprint: typeof blueprint === "string" ? blueprint : "", far });\n this.#keepDescribed(placeholder, placeholder, _Window.#blueprintOf(knocked));\n }\n async #stateKept(route) {\n const over = _Window.#relationOf(route);\n if (over === null || this.#lobeReached(route) !== over || !this.#farLobe(over)) return;\n const declared = _Window.#methodOf(this.#keptDescribed(over, over), "state");\n if (!_Window.#reads(declared) || _Window.#asksArgs(declared)) return;\n const kept = this.#keptRead(over, over, "state");\n if (kept === void 0 || !this.#fresh(kept, over, null)) await this.#readKept(over, over, "state", null, {});\n }\n static #asksArgs(method) {\n const required = _Window.#at(_Window.#at(method, "args"), "required");\n return Array.isArray(required) && required.length > 0;\n }\n #keptDescribed(over, lobe) {\n const kept = this.cells.get(["described", over, lobe]);\n return _Window.#at(kept, "described");\n }\n #keepDescribed(over, lobe, heard) {\n const key = ["described", over, lobe];\n if (!("result" in heard)) {\n this.cells.delete(key);\n return;\n }\n const version = _Window.#at(heard.result, "version");\n this.cells.set(key, { version: typeof version === "string" ? version : null, described: heard.result });\n const named = JSON.stringify(key);\n const index = this.#indexed(["describes"]).filter((one) => JSON.stringify(one) !== named);\n const kept = _Window.#trimmed([...index, key], _Window.#mostRelations, (old) => {\n const gone = _Window.#keyed(old);\n if (gone !== void 0) this.cells.delete(gone);\n });\n this.cells.set(["describes"], [...kept]);\n }\n async #walkDescribed(route) {\n const over = _Window.#relationOf(route);\n const lobe = this.#lobeReached(route);\n if (over === null || lobe === null) return;\n this.#keepDescribed(over, lobe, await this.#through(over, lobe, null, {}));\n }\n root() {\n const foreign = this.#foreign();\n if (foreign !== null) return foreign;\n const route = this.#walked();\n return { route, text: _Window.#text(route) };\n }\n #heldBy(over, cells) {\n if (over === null || !this.#farLobe(over)) return cells;\n const far = _Window.#at(this.cells.get(["far-lobe", over]), "far");\n const moved = this.cells.get(["moved", over]);\n return `${_Window.#shown(far)}:${String(typeof moved === "number" ? moved : 0)}`;\n }\n #movedAt(over) {\n if (over === null || !this.#farLobe(over)) return;\n const moved = this.cells.get(["moved", over]);\n this.cells.set(["moved", over], (typeof moved === "number" ? moved : 0) + 1);\n }\n #fresh(kept, over, cells) {\n const held = this.#heldBy(over, cells);\n return held !== null && kept["cells"] === held;\n }\n async #keptAgain(route) {\n const over = _Window.#relationOf(route);\n if (over === null || !this.#farLobe(over)) return;\n for (const key of this.#indexed(["reads"])) {\n if (!Array.isArray(key) || key[1] !== over || typeof key[2] !== "string" || typeof key[3] !== "string") continue;\n const kept = this.#keptRead(over, key[2], key[3], false);\n if (kept === void 0 || this.#fresh(kept, over, null)) continue;\n await this.#readKept(over, key[2], key[3], null, _Window.#fields(kept["values"]) ? kept["values"] : {});\n }\n }\n static #readKey(over, lobe, method) {\n return ["read", over ?? "", lobe, method];\n }\n #keptRead(over, lobe, method, plain = true) {\n const kept = this.cells.get(_Window.#readKey(over, lobe, method));\n return _Window.#fields(kept) && (!plain || kept["values"] === void 0) ? kept : void 0;\n }\n static #shown(data) {\n return typeof data === "string" ? data : JSON.stringify(data ?? null);\n }\n static #isLook(described) {\n const name = _Window.#at(described, "name");\n return typeof name === "string" && name.endsWith("-look");\n }\n static #methodsOf(described) {\n const methods = _Window.#at(described, "methods");\n if (!_Window.#fields(methods)) return [];\n const listed = [];\n for (const [name, one] of Object.entries(methods)) if (_Window.#fields(one)) listed.push([name, one]);\n return listed;\n }\n static #heard(answer) {\n return "result" in answer ? { answer: answer.result } : { error: { code: answer.error.code, message: answer.error.message } };\n }\n async #describedAll(over, lobes) {\n const described = [];\n for (let at = 0; at < lobes.length; at += _Window.#describing) {\n const asked = lobes.slice(at, at + _Window.#describing).map((lobe) => this.#through(over, lobe, null, {}));\n for (const answer of await Promise.all(asked)) described.push("result" in answer ? answer.result : void 0);\n }\n return described;\n }\n async #notes() {\n const notes = new Map();\n let cursor = null;\n for (let page = 0; page < _Window.#mostRelationPages; page++) {\n const read = await this.ask("nerves", "relations", cursor === null ? {} : { cursor });\n if ("error" in read || !_Window.#fields(read.result)) return { notes, more: false };\n const listed = read.result["relations"];\n for (const one of Array.isArray(listed) ? listed : []) {\n const placeholder = _Window.#at(one, "placeholder");\n const note = _Window.#at(one, "note");\n if (typeof placeholder === "string" && note !== void 0) notes.set(placeholder, note);\n }\n const next = read.result["cursor"];\n if (typeof next !== "string") return { notes, more: false };\n cursor = next;\n }\n return { notes, more: true };\n }\n async #nerves() {\n const read = await this.nerves.read();\n if ("error" in read) return { why: `the window\'s nerves are not read: ${read.error.message}` };\n const held = Array.isArray(read.result) ? read.result : [];\n let design = null;\n const far = [];\n for (const one of held) {\n const placeholder = _Window.#at(one, "placeholder");\n const termination = _Window.#at(one, "termination");\n if (typeof placeholder !== "string") continue;\n if (placeholder === "design") design = typeof termination === "string" ? termination : null;\n else if (!_Window.#own.includes(placeholder) && _Window.#relationName.test(placeholder) && _Window.#at(one, "status") === "far")\n far.push({ placeholder, termination, status: "far" });\n }\n const { notes, more } = far.length === 0 ? { notes: new Map(), more: false } : await this.#notes();\n const relations = far.map(({ placeholder, termination, status }) => ({\n placeholder,\n far: termination ?? null,\n status,\n note: notes.get(placeholder) ?? null,\n ...this.#farLobe(placeholder) ? { place: true } : {},\n path: _Window.#text([{ relation: placeholder }])\n }));\n return { design, relations, more };\n }\n async #namedAll(over, lobes) {\n const named = [];\n for (let at = 0; at < lobes.length; at += _Window.#describing) {\n const asked = lobes.slice(at, at + _Window.#describing).map(\n (lobe) => lobe === void 0 ? Promise.resolve(void 0) : this.ask(\n over ?? "brain",\n "ask",\n { lobe, method: "state", args: {}, timeout: _Window.#nameWithin },\n _Window.#nameWithin\n )\n );\n for (const answer of await Promise.all(asked)) {\n const name = answer !== void 0 && "result" in answer ? _Window.#at(answer.result, "name") : void 0;\n named.push(typeof name === "string" && name !== "" ? name : void 0);\n }\n }\n return named;\n }\n async #lobesShown(over, nodes) {\n const lobes = (Array.isArray(nodes) ? nodes : []).flatMap((node) => {\n const id = _Window.#at(node, "id");\n return _Window.#at(node, "kind") === "lobe" && typeof id === "string" ? [{ id, blueprint: _Window.#at(node, "blueprint") }] : [];\n });\n const described = await this.#describedAll(\n over,\n lobes.map((one) => one.id)\n );\n const named = await this.#namedAll(\n over,\n described.map(\n (text, at) => text !== void 0 && _Window.#methodsOf(text).some(([method, one]) => method === "state" && one["kind"] === "reading") ? lobes[at]?.id : void 0\n )\n );\n return lobes.map((one, at) => {\n const text = described[at];\n if (text === void 0) return { id: one.id, name: one.blueprint ?? one.id, unavailable: true };\n const faculty = _Window.#at(text, "name") ?? one.id;\n return {\n id: one.id,\n name: named[at] ?? faculty,\n faculty,\n version: _Window.#at(text, "version") ?? "",\n description: _Window.#at(text, "description") ?? ""\n };\n });\n }\n async #organismPage(over, path, relations, cursor, name, faculties) {\n const state = await this.ask(\n over ?? "brain",\n "state",\n cursor === null ? {} : { cursor },\n _Window.#lobeWithin\n );\n const own = over === null ? relations : [];\n if ("error" in state)\n return {\n args: { name, state: { error: state.error.message }, organs: [], lobes: [], relations: own, path },\n warnings: [this.#word("organismSilentSay")]\n };\n const unmade = over === null ? this.cells.get(_Window.#unmadeKey) : void 0;\n const about = over === null ? this.cells.get(_Window.#aboutKey) : void 0;\n const shown = await this.#lobesShown(over, _Window.#at(state.result, "nodes"));\n const head = Object.fromEntries(\n Object.entries(_Window.#fields(state.result) ? state.result : {}).filter(\n ([key]) => !["nodes", "organs", "letters", "durables", "cursor"].includes(key)\n )\n );\n const next = _Window.#at(state.result, "cursor");\n return {\n args: {\n name,\n state: head,\n organs: _Window.#at(state.result, "organs") ?? [],\n lobes: shown,\n relations: own,\n path,\n ...faculties === void 0 ? {} : { faculties },\n ..._Window.#fields(about) ? { about } : {},\n ...typeof next === "string" ? { next } : {},\n ...cursor === null ? {} : { first: true }\n },\n warnings: typeof unmade === "string" ? [unmade] : []\n };\n }\n #writtenOf(over, lobe) {\n const id = this.cells.get(["last", over ?? "", lobe]);\n const press = typeof id === "string" ? this.cells.get(["press", id]) : void 0;\n if (!_Window.#fields(press) || !this.#stands(press)) return void 0;\n return _Window.#kept(press) ?? (press["sent"] === true ? { method: _Window.#shown(press["method"]), unknown: true } : void 0);\n }\n #standing(over) {\n if (over === null) return null;\n const far = _Window.#at(this.cells.get(["far-lobe", over]), "far") ?? this.cells.get(["far-organism", over]);\n return typeof far === "string" && far !== "" ? far : null;\n }\n #stands(press) {\n const far = press["far"];\n return typeof far !== "string" || far === this.#standing(typeof press["over"] === "string" ? press["over"] : null);\n }\n #pressDropped(id) {\n this.cells.delete(["press", id]);\n const presses = this.#indexed(["presses"]);\n if (presses.includes(id))\n this.cells.set(\n ["presses"],\n presses.filter((one) => one !== id)\n );\n }\n async #heardOf(over, lobe, method, cells) {\n const ask = async (values2) => _Window.#heard(await this.#through(over, lobe, method, values2));\n const kept = this.#keptRead(over, lobe, method, false);\n const keptState = this.#farLobe(over) && kept !== void 0 && this.#fresh(kept, over, cells);\n if (method === "state" && !keptState) return ask({});\n if (kept === void 0) return void 0;\n const values = _Window.#fields(kept["values"]) ? kept["values"] : {};\n return this.#fresh(kept, over, cells) ? kept : ask(values);\n }\n static #drawn(entry, seated) {\n return _Window.#seatOf(entry) !== void 0 || !seated && !_Window.#fields(_Window.#at(entry, "seat"));\n }\n async #methodsShown(over, lobe, described, cells) {\n const reading = [];\n const writing = [];\n const methods = _Window.#methodsOf(described);\n const seated = methods.some(([, one]) => _Window.#seatOf(one) !== void 0);\n for (const [method, one] of methods) {\n if (method === "draw" && _Window.#isLook(described) || !_Window.#drawn(one, seated)) continue;\n const description = _Window.#at(one, "description") ?? "";\n const worded = _Window.#worded(_Window.#at(_Window.#seatOf(one), "label"), this.#lang);\n const label = worded === "" ? {} : { label: worded };\n if (!_Window.#reads(one)) {\n writing.push({ method, description, args: _Window.#at(one, "args") ?? null, ...label });\n continue;\n }\n const heard = await this.#heardOf(over, lobe, method, cells);\n const kept = heard === void 0 ? {} : "error" in heard ? { error: heard["error"] ?? null } : { answer: heard["answer"] ?? null };\n const args = _Window.#at(one, "args");\n reading.push({ method, description, ...args === void 0 ? {} : { args }, ...label, ...kept });\n }\n return { reading, writing };\n }\n async #lobePage(over, lobe, described, path, cells) {\n const { reading, writing } = await this.#methodsShown(over, lobe, described, cells);\n const faculty = _Window.#at(described, "name");\n const own = reading.map((one) => _Window.#at(one, "method") === "state" ? _Window.#at(_Window.#at(one, "answer"), "name") : void 0).find((one) => typeof one === "string" && one !== "");\n const written = this.#writtenOf(over, lobe);\n return {\n id: lobe,\n name: typeof own === "string" ? own : faculty ?? lobe,\n faculty: faculty ?? lobe,\n version: _Window.#at(described, "version") ?? "",\n description: _Window.#at(described, "description") ?? "",\n reading,\n writing,\n path,\n ...written === void 0 ? {} : { written }\n };\n }\n async #surrounded(theme, around) {\n const args = {\n title: around.title,\n route: around.route,\n warnings: around.warnings,\n main: around.main,\n ...around.consent === void 0 ? {} : { consent: around.consent },\n ...around.back === null ? {} : { back: around.back }\n };\n return this.#draws({ component: "surround", args, theme });\n }\n async #organismPlaced(over, text, held, asked) {\n const title = over ?? this.#word("homeWord");\n const kept = over === null ? await this.#facultiesKept() : void 0;\n const page = await this.#organismPage(over, text, held.relations, asked.cursor, title, kept?.faculties);\n const args = { component: "organism", args: page.args, theme: asked.theme, lang: this.#lang };\n const cut = [\n ...kept?.more === true ? [this.#word("moreFacultiesSay")] : [],\n ...over === null && held.more ? [this.#word("moreNotesSay")] : []\n ];\n return {\n title,\n version: null,\n warnings: [...page.warnings, ...cut],\n main: { lobe: held.design, over: null, args }\n };\n }\n async #lobeSeen(over, lobe, text, seen) {\n const { cells, theme, design } = seen;\n const described = await this.#describedOf(over, lobe);\n if (over !== null && "error" in described && described.error.code === "removed") return _Window.#goneOf(over);\n const says = "result" in described ? described.result : void 0;\n const name = _Window.#at(says, "name");\n const said = _Window.#at(says, "version");\n const version = typeof said === "string" ? said : null;\n const warnings = says === void 0 ? [this.#word("lobeSilentSay")] : [];\n if (_Window.#reads(_Window.#methodOf(says, "draw")) && !_Window.#isLook(says))\n return { title: typeof name === "string" ? name : lobe, version, warnings, main: { lobe, over, args: {} } };\n const page = await this.#lobePage(over, lobe, says ?? {}, text, cells);\n const label = page["name"];\n return {\n title: typeof label === "string" ? label : lobe,\n version,\n warnings,\n main: { lobe: design, over: null, args: { component: "lobe", args: page, theme, lang: this.#lang } },\n ...this.#channelOf(over, lobe)\n };\n }\n static #goneOf(over) {\n return { why: `the place ${over} has ended: its far side removed the standing` };\n }\n #answersSaid() {\n return { yesSay: this.#word("yesSay"), noSay: this.#word("noSay") };\n }\n #leaveAsked(over, lobe) {\n const state = lobe === null ? {} : this.#localOf(over, lobe, _Window.#consent);\n if (!this.#farLobe(over) || state["asking"] !== "leave") return void 0;\n return {\n say: this.#word("leavingSay"),\n yes: { method: "leave", args: { relation: over, consented: true } },\n no: { method: "local", args: { region: _Window.#consent, state: { asking: null } } },\n ...this.#answersSaid()\n };\n }\n static #consent = "#consent";\n #consentAt(on) {\n const route = this.#walked();\n const lobe = this.#lobeReached(route);\n const over = _Window.#relationOf(route);\n return lobe !== null && over === on.over ? { over, lobe } : on;\n }\n #consented(over, lobe, press) {\n const state = this.#consentOf(over, lobe, press);\n return state !== null && state["taken"] === void 0;\n }\n #consentOf(over, lobe, press) {\n const at = this.#consentAt({ over, lobe });\n const state = this.#localOf(at.over, at.lobe, _Window.#consent);\n return press["consented"] === true && state["asking"] === press["method"] && (state["lobe"] ?? at.lobe) === lobe ? state : null;\n }\n #consentTaken(on, id) {\n this.#localSet(this.#consentAt(on), _Window.#consent, { taken: id });\n }\n #consentSpent(on, id) {\n const at = this.#consentAt(on);\n if (id === void 0 || this.#localOf(at.over, at.lobe, _Window.#consent)["taken"] === id)\n this.cells.delete(["local", at.over ?? "", at.lobe, _Window.#consent]);\n }\n static #irreversible(declared) {\n const marked = _Window.#at(declared, "irreversible");\n return marked === true || typeof marked === "string";\n }\n static #waits(declared, over) {\n return _Window.#irreversible(declared) || over !== null && _Window.#unsaid(declared);\n }\n #heldBack(on, method, args, declared) {\n if (!_Window.#fields(args) && args !== null)\n return this.error("refused", "a press that waits for consent carries its args as fields");\n const label = _Window.#at(_Window.#seatOf(declared), "label");\n const set = this.#localSet(this.#consentAt(on), _Window.#consent, {\n asking: method,\n lobe: on.lobe,\n args: args ?? {},\n label: _Window.#fields(label) ? label : null,\n irreversible: _Window.#irreversible(declared) ? true : null,\n taken: null\n });\n return "code" in set ? set : { method, asking: true };\n }\n #heldAsked(over, lobe, path, lang) {\n if (lobe === null) return void 0;\n const { asking, args, label, lobe: asked, irreversible } = this.#localOf(over, lobe, _Window.#consent);\n if (typeof asking !== "string" || !_Window.#fields(args)) return void 0;\n const at = typeof asked === "string" && asked !== lobe ? _Window.#text([...over === null ? [] : [{ relation: over }], { lobe: asked }]) : path;\n const named = _Window.#worded(label, lang) || asking;\n return {\n say: `${named}: ${this.#word(irreversible === true ? "irreversibleSay" : "unsaidSay")}`,\n yes: { method: "ask", args: { path: at, method: asking, args, consented: true } },\n no: {\n method: "local",\n args: {\n region: _Window.#consent,\n state: { asking: null, lobe: null, args: null, label: null, irreversible: null }\n }\n },\n ...this.#answersSaid()\n };\n }\n #lobeReached(route) {\n const over = _Window.#relationOf(route);\n return _Window.#lobeOf(route) ?? (this.#farLobe(over) ? over : null);\n }\n async see(args) {\n const foreign = this.#foreign();\n if (foreign !== null) return foreign;\n const given = _Window.#at(args, "route");\n const route = given === void 0 ? this.#walked() : _Window.#routeOf(given);\n if (route === void 0) return this.error("refused", "see names no route: a relation the window holds and a lobe");\n if (this.#lobeOfFarLobe(route)) return this.error("refused", "a far lobe has no lobes");\n const options = _Window.#at(args, "args");\n const [cursor, cells] = [_Window.#at(options, "cursor"), _Window.#at(options, "cells")];\n const theme = _Window.#themed(_Window.#at(options, "theme"));\n const lang = _Window.#langOf(_Window.#at(options, "lang"));\n this.#lang = lang;\n const held = await this.#nerves();\n if ("why" in held) return this.error("unavailable", held.why);\n if (held.design === null) return this.error("unavailable", "the screen wears no design yet");\n const over = _Window.#relationOf(route);\n const text = _Window.#text(route);\n const lobe = this.#lobeReached(route);\n const crumbs = [{ label: this.#word("homeWord"), path: "/" }];\n if (over !== null && !this.#farLobe(over)) crumbs.push({ label: over, path: _Window.#text(route.slice(0, 1)) });\n const placed = lobe === null ? await this.#organismPlaced(\n over,\n text,\n { relations: held.relations, design: held.design, more: held.more },\n { cursor: typeof cursor === "string" ? cursor : null, theme }\n ) : await this.#lobeSeen(over, lobe, text, {\n cells: typeof cells === "string" ? cells : null,\n theme,\n design: held.design\n });\n if ("why" in placed) return this.error("refused", placed.why);\n const consent = this.#heldAsked(over, lobe, text, lang) ?? (over === null ? void 0 : this.#leaveAsked(over, lobe));\n const leave = over !== null && lobe === over ? this.#leaveOf(over).leave : void 0;\n return this.#pageSurrounded(consent === void 0 ? placed : { ...placed, consent }, {\n route,\n text,\n lobe,\n crumbs,\n theme,\n leave,\n design: held.design\n });\n }\n async #pageSurrounded(placed, on) {\n const { route, text, lobe, crumbs, theme, leave, design } = on;\n const { title, version, warnings, main, consent } = placed;\n const way = route.length === 0 ? {} : {\n way: {\n at: _Window.#wayAt,\n say: this.#word("wayOutSay"),\n ...leave === void 0 ? {} : { leave }\n }\n };\n const beside = { version, design, ...way, ...placed.channel === void 0 ? {} : { channel: placed.channel } };\n if (warnings.length === 0 && consent === void 0)\n return {\n route,\n text,\n tree: { t: "main", a: {}, c: [{ t: "slot", a: { placeholder: "main" }, args: main.args, c: [] }] },\n main,\n ...beside\n };\n if (lobe !== null) crumbs.push({ label: title, path: text });\n const back = route.length === 0 ? null : _Window.#text(route.slice(0, -1));\n const drawn = await this.#surrounded(theme, {\n title,\n route: crumbs,\n back,\n warnings,\n main: main.args,\n ...consent === void 0 ? {} : { consent }\n });\n if ("error" in drawn) return this.error("unavailable", `the design lobe draws no surround: ${drawn.error.message}`);\n return { route, text, tree: drawn.result, main, ...beside };\n }\n static #outside(css, has) {\n const quoted = /(url\\(\\s*|@import\\s+)("(?:\\\\.|[^"\\\\])*"|\'(?:\\\\.|[^\'\\\\])*\')|"(?:\\\\.|[^"\\\\])*"|\'(?:\\\\.|[^\'\\\\])*\'/gu;\n const text = css.replaceAll(/\\/\\*[\\s\\S]*?\\*\\//gu, " ").replaceAll(quoted, (whole, prefix) => prefix === void 0 ? \'""\' : whole);\n if (/@import\\b/iu.test(text)) return "@import";\n const addresses = [...text.matchAll(/url\\(\\s*(?:"([^"]*)"|\'([^\']*)\'|([^)\'"\\s]*))\\s*\\)/gu)].map(\n (one) => one[1] ?? one[2] ?? one[3] ?? ""\n );\n for (const set of text.matchAll(/image-set\\(([^)]*)\\)/gu))\n for (const one of (set[1] ?? "").matchAll(/"([^"]*)"|\'([^\']*)\'/gu)) addresses.push(one[1] ?? one[2] ?? "");\n for (const address of addresses) {\n if (/^data:/iu.test(address) || address.startsWith("#")) continue;\n const out = [];\n let climbs = false;\n if (!/^[A-Za-z][A-Za-z0-9+.-]*:|^[/\\\\]/u.test(address))\n for (const part of `skin/${address}`.split("/")) {\n if (part === "..") climbs = out.pop() === void 0 || climbs;\n else if (part !== "." && part !== "") out.push(part);\n }\n if (climbs || out.length === 0 || !has(out.join("/"))) return address;\n }\n return null;\n }\n static #fenced(items) {\n const files = new Map();\n for (const one of items) {\n const [path, text] = [_Window.#at(one, "path"), _Window.#at(one, "text")];\n if (typeof path === "string" && typeof text === "string") files.set(path, text);\n }\n const hold = (path) => items.some((one) => _Window.#at(one, "path") === path);\n let layers;\n try {\n layers = JSON.parse(files.get("skin/layers.json") ?? "null");\n } catch {\n return "skin/layers.json is no JSON";\n }\n for (const layer of ["lobes", "home"]) {\n const named = _Window.#at(layers, layer);\n for (const name of Array.isArray(named) ? named : []) {\n const found = typeof name === "string" ? _Window.#outside(files.get(`skin/${name}`) ?? "", hold) : null;\n if (found !== null) return `skin/${String(name)}: ${found} is outside its bundle`;\n }\n }\n return null;\n }\n async #fencedLobe(lobe) {\n const files = await this.#through(null, lobe, "files", {});\n if ("error" in files) return `the window reads not the files of ${lobe}: ${files.error.message}`;\n const items = _Window.#at(files.result, "files");\n if (!Array.isArray(items)) return `${lobe} answered no files`;\n const fenced = _Window.#fenced(items);\n return fenced === null ? null : `the design is refused: ${fenced}`;\n }\n #localOf(over, lobe, region) {\n const kept = this.cells.get(["local", over ?? "", lobe, region]);\n return _Window.#fields(kept) ? kept : {};\n }\n #forgetLocals() {\n for (const one of this.#indexed(["locals"])) {\n const gone = _Window.#keyed(one);\n if (gone !== void 0) this.cells.delete(gone);\n }\n this.cells.delete(["locals"]);\n }\n #localSet(on, region, state) {\n const { over, lobe } = on;\n const key = ["local", over ?? "", lobe, region];\n const merged = { ...this.#localOf(over, lobe, region) };\n for (const [field, value] of Object.entries(state)) {\n if (value === null) delete merged[field];\n else merged[field] = value;\n }\n if (JSON.stringify(merged).length > this.#mostState())\n return this.error("refused", "the local state is past the size the home keeps");\n this.cells.set(key, merged);\n const named = JSON.stringify(key);\n const index = this.#indexed(["locals"]).filter((one) => JSON.stringify(one) !== named);\n const kept = _Window.#trimmed([...index, key], this.#keptHalf(), (old) => {\n const gone = _Window.#keyed(old);\n if (gone !== void 0) this.cells.delete(gone);\n });\n this.cells.set(["locals"], [...kept]);\n return merged;\n }\n local(args) {\n const foreign = this.#foreign();\n if (foreign !== null) return foreign;\n const [region, state] = [_Window.#at(args, "region"), _Window.#at(args, "state")];\n const route = this.#walked();\n const lobe = this.#lobeReached(route);\n if (typeof region !== "string" || !_Window.#fields(state) || lobe === null)\n return this.error("refused", "a local state is a region\u2019s and an object, at the route of a lobe");\n if (region === _Window.#consent && Object.values(state).some((one) => one !== null))\n return this.error("refused", "the consent is set by the home alone, and a press only clears it");\n return this.#localSet({ over: _Window.#relationOf(route), lobe }, region, state);\n }\n static #seatOf(entry) {\n const seat = _Window.#at(entry, "seat");\n const people = _Window.#at(seat, "for");\n return _Window.#fields(seat) && (people === "person" || people === "both") ? seat : void 0;\n }\n static #https = /^https:\\/\\/([A-Za-z0-9.-]+)(?::[0-9]{1,5})?(?:[/?#]\\S*)?$/u;\n static #domainOf(link) {\n if (typeof link !== "string" || link.length > 2e3) return void 0;\n const found = _Window.#https.exec(link);\n const host = found?.[1];\n return host === void 0 || host.startsWith(".") || host.includes("..") ? void 0 : host.toLowerCase();\n }\n static #fileKinds = new Set(["avif", "gif", "jpg", "png", "webp", "mp3", "ogg", "wav"]);\n static #file(given, now, far) {\n const { url, expires, size, sha256, ext } = given;\n if (typeof size !== "number" || !Number.isInteger(size) || size < 0)\n return { why: "a file has a size, a whole number of bytes" };\n if (typeof sha256 !== "string" || !/^[0-9a-f]{64}$/u.test(sha256))\n return { why: "a file has its SHA-256, 64 hex characters" };\n if (typeof ext !== "string" || !_Window.#fileKinds.has(ext))\n return { why: `a file is a picture or a sound, of a kind a tree names: ${[..._Window.#fileKinds].join(", ")}` };\n if (url === void 0 && expires === void 0)\n return far ? { why: "a far place hands a file from an https address: the bytes it holds itself would cross Quo" } : { kind: "file", size, sha256, ext };\n const domain = _Window.#domainOf(url);\n if (domain === void 0 || typeof url !== "string" || url.includes("@"))\n return { why: "a file is fetched from an https address with no credentials" };\n if (typeof expires !== "number" || !Number.isInteger(expires) || expires <= now)\n return { why: "a file\u2019s address has an expiry still to come, in whole milliseconds" };\n return { kind: "file", url, domain, expires, size, sha256, ext };\n }\n static #channel(answer, now, files, far) {\n const given = _Window.#at(answer, "channel");\n if (!_Window.#fields(given)) return { why: "a channel answers {channel: {kind, \u2026}}" };\n const kind = given["kind"];\n if (kind === "upload") {\n const { url, expires } = given;\n const domain = _Window.#domainOf(url);\n if (domain === void 0 || typeof url !== "string" || url.includes("@"))\n return { why: "a file is sent to an https address with no credentials" };\n if (typeof expires !== "number" || !Number.isInteger(expires) || expires <= now)\n return { why: "an upload\u2019s address has an expiry still to come, in whole milliseconds" };\n const [file, ...more] = files;\n if (file === void 0 || more.length > 0)\n return { why: "an upload sends the one file its press carried, and this press carried none or more" };\n return { kind, url, domain, expires, ...file };\n }\n if (kind === "file") return _Window.#file(given, now, far);\n return { why: "a channel is a file or an upload" };\n }\n static #filesOf(values) {\n if (!_Window.#fields(values)) return [];\n return Object.values(values).filter((one) => {\n if (!_Window.#fields(one) || Object.keys(one).length !== 4) return false;\n const { name, type, size, sha256 } = one;\n return typeof name === "string" && typeof type === "string" && typeof size === "number" && Number.isInteger(size) && size >= 0 && typeof sha256 === "string" && /^[0-9a-f]{64}$/u.test(sha256);\n });\n }\n static #shaped(declared, heard, now, files, far) {\n if (_Window.#at(_Window.#seatOf(declared), "intent") !== "channel" || !("answer" in heard)) return heard;\n const kind = _Window.#at(_Window.#at(heard["answer"], "channel"), "kind");\n if (kind === "call" || kind === "stream")\n return {\n error: { code: "unavailable", message: `channel unavailable: no organ of this home carries a ${kind}` }\n };\n const checked = _Window.#channel(heard["answer"], now, files, far);\n if ("why" in checked && typeof checked.why === "string")\n return { error: { code: "refused", message: `channel refused: ${checked.why}` } };\n return { answer: { channel: checked } };\n }\n static #worded(words, lang) {\n if (!_Window.#fields(words)) return "";\n const wanted = words[lang] ?? words[_Window.#primary(lang)];\n if (typeof wanted === "string") return wanted;\n return Object.values(words).find((one) => typeof one === "string") ?? "";\n }\n #word(key, values = {}) {\n return _Window.words[key].replaceAll(\n /\\{([a-z]+)\\}/gu,\n (found, name) => Object.hasOwn(values, name) ? values[name] ?? found : found\n );\n }\n static #primary(lang) {\n return (lang.split(/[-_]/u)[0] ?? "").toLowerCase();\n }\n #channelOf(over, lobe) {\n const id = this.cells.get(["last", over ?? "", lobe]);\n const pressed = typeof id === "string" ? this.cells.get(["press", id]) : void 0;\n const channel = _Window.#at(_Window.#at(this.#writtenOf(over, lobe), "answer"), "channel");\n if (!_Window.#fields(channel) || _Window.#at(pressed, "channeled") !== true) return {};\n if (channel["kind"] !== "upload" && channel["kind"] !== "file") return { channel };\n return typeof id === "string" && _Window.#at(pressed, "landed") === void 0 ? { channel: { ...channel, press: id } } : {};\n }\n async landed(args) {\n const found = this.#pressOf(args);\n if ("code" in found) return found;\n const { id, press } = found;\n const channel = _Window.#at(_Window.#at(press, "answer"), "channel");\n const [landed, why] = [_Window.#at(args, "landed"), _Window.#at(args, "why")];\n const kind = _Window.#at(channel, "kind");\n if (kind !== "upload" && kind !== "file" || press["landed"] !== void 0)\n return this.error("refused", "the press answered no file or upload still to tell");\n if (typeof landed !== "boolean") return this.error("refused", "landed says whether the file landed");\n const [lobe, over, sha256] = [press["lobe"], press["over"], _Window.#at(channel, "sha256")];\n if (typeof lobe !== "string" || typeof sha256 !== "string") return this.error("refused", "the press names no lobe");\n const said = typeof why === "string" ? why.slice(0, 300) : "the file did not come";\n this.cells.set(\n ["press", id],\n landed ? { ...press, landed } : {\n ...Object.fromEntries(Object.entries(press).filter(([key]) => key !== "answer")),\n landed,\n error: { code: "refused", message: `${kind} refused: ${said}` }\n }\n );\n if (kind === "file") return { landed };\n const told = await this.#through(typeof over === "string" ? over : null, lobe, "landed", { sha256, landed });\n return { landed, ..._Window.#heard(told) };\n }\n async piece(args) {\n const found = this.#pressOf(args);\n if ("code" in found) return found;\n const { press } = found;\n const channel = _Window.#at(_Window.#at(press, "answer"), "channel");\n const [lobe, sha256, size, at] = [\n press["lobe"],\n _Window.#at(channel, "sha256"),\n _Window.#at(channel, "size"),\n _Window.#at(args, "at")\n ];\n if (_Window.#at(channel, "kind") !== "file" || _Window.#at(channel, "url") !== void 0 || typeof press["over"] === "string" || press["landed"] !== void 0 || typeof lobe !== "string" || typeof sha256 !== "string" || typeof size !== "number")\n return this.error("refused", "the press answered no file its lobe holds, still to tell");\n if (typeof at !== "number" || !Number.isInteger(at) || at < 0 || at >= size)\n return this.error("refused", `a piece starts at a byte of the file, below ${String(size)}`);\n const length = Math.min(size - at, Math.floor(this.memory / LOBE_SHARE));\n const heard = await this.#through(null, lobe, "piece", { sha256, at, length });\n if ("error" in heard) return this.error("refused", `${lobe} gave no piece: ${heard.error.message}`);\n const bytes = heard.result;\n return bytes instanceof Uint8Array && bytes.length === length ? bytes : this.error("refused", `${lobe} gave a piece that is not the ${String(length)} bytes from ${String(at)}`);\n }\n async show(args) {\n const foreign = this.#foreign();\n if (foreign !== null) return foreign;\n const lobe = _Window.#at(args, "lobe");\n if (typeof lobe !== "string") return this.error("refused", "show names a lobe");\n const over = _Window.#over(args);\n if (over === void 0) return this.error("refused", "over names a relation the window holds");\n const drawn = await this.#through(over, lobe, "draw", _Window.#at(args, "args") ?? null);\n if ("error" in drawn) return this.error(drawn.error.code, drawn.error.message);\n if (this.#farLobe(over)) return { tree: drawn.result, wires: {} };\n const wires = await this.#wiresOf(over, lobe);\n if ("why" in wires) return this.error("refused", wires.why);\n return { tree: drawn.result, wires: wires.wires };\n }\n static #ownPresses = ["wear", "create", "about", "leave"];\n async press(args) {\n const foreign = this.#foreign();\n if (foreign !== null) return foreign;\n const lobe = _Window.#at(args, "lobe");\n const method = _Window.#at(args, "method");\n if (typeof lobe !== "string" || typeof method !== "string")\n return this.error("refused", "a press names its lobe and its method");\n const over = _Window.#over(args);\n if (over === void 0) return this.error("refused", "over names a relation the window holds");\n const to = _Window.#at(args, "to");\n const given = _Window.#at(args, "args") ?? {};\n if (_Window.#ownPresses.includes(method) && over === null && to === void 0) {\n const held = await this.#nerves();\n if (!("why" in held) && held.design === lobe) {\n if (method === "wear") return this.#wearOrTell(given);\n if (method === "create") return this.#making(given);\n if (method === "about") return this.#about(given);\n return this.#leave(given);\n }\n }\n let asked = lobe;\n if (typeof to === "string") {\n if (this.#farLobe(over)) return this.error("refused", `${lobe} has nothing wired at ${to}`);\n const wires = await this.#wiresOf(over, lobe);\n if ("why" in wires) return this.error("refused", wires.why);\n const wired = wires.wires[to];\n if (wired === void 0) return this.error("refused", `${lobe} has nothing wired at ${to}`);\n asked = wired;\n }\n const described = await this.#describedOf(over, asked);\n if ("error" in described) return this.error("refused", `${asked} is not described: ${described.error.message}`);\n const declared = _Window.#methodOf(described.result, method);\n const carried = _Window.#carried(declared, _Window.#at(args, "args") ?? null, _Window.#at(args, "values"));\n if ("why" in carried) return this.error("refused", carried.why);\n if (_Window.#waits(declared, over)) return this.#heldBack({ over, lobe: asked }, method, carried.args, declared);\n const pressed = await this.#through(over, asked, method, carried.args);\n if (!_Window.#reads(declared)) this.#movedAt(over);\n return "result" in pressed ? pressed.result : this.error(pressed.error.code, pressed.error.message);\n }\n static #carried(declared, args, values) {\n if (!_Window.#fields(values) || Object.keys(values).length === 0) return { args };\n const fit = _Window.#fit(_Window.#at(declared, "args"), values);\n if ("why" in fit) return fit;\n const fields = _Window.#fields(fit.values) ? fit.values : {};\n if (Object.keys(fields).length === 0) return { args };\n if (!_Window.#fields(args) && args !== null) return { why: "a press whose args are no object carries no field" };\n return { args: { ...fields, ..._Window.#fields(args) ? args : {} } };\n }\n async #making(args) {\n const digest = _Window.#at(args, "faculty");\n if (typeof digest !== "string" || !/^[0-9a-f]{64}$/u.test(digest))\n return this.#unmade("create names a faculty by its digest");\n const kept = await this.#through(null, "library", "get", { digest });\n if ("error" in kept) return this.#unmade(`the library keeps no faculty ${digest}: ${kept.error.message}`);\n const wiring = await this.#coreWiring(_Window.#at(_Window.#at(kept.result, "blueprint"), "placeholders"));\n if ("why" in wiring) return this.#unmade(wiring.why);\n const made = await this.ask("brain", "create", { faculty: digest, wiring: wiring.wiring });\n if ("error" in made) return this.#unmade(`the brain makes no lobe of ${digest}: ${made.error.message}`);\n const id = _Window.#at(made.result, "id");\n if (typeof id !== "string") return this.#unmade("the brain named no lobe it made");\n this.cells.delete(_Window.#unmadeKey);\n this.cells.delete(_Window.#aboutKey);\n this.#forgetLocals();\n const route = [{ lobe: id }];\n this.cells.set(["root"], route);\n return { lobe: id, route, text: _Window.#text(route) };\n }\n async #about(args) {\n const digest = _Window.#at(args, "faculty");\n if (typeof digest !== "string" || !/^[0-9a-f]{64}$/u.test(digest))\n return this.#unmade("about names a faculty by its digest");\n const kept = await this.#through(null, "library", "get", { digest });\n const blueprint = "result" in kept ? _Window.#at(kept.result, "blueprint") : void 0;\n if (!_Window.#fields(blueprint)) return this.#unmade(`the library keeps no faculty ${digest}`);\n const held = await this.#nodesHeld();\n if ("why" in held) return this.#unmade(held.why);\n const organs = new Map();\n for (const node of held.nodes) {\n const [id, name] = [_Window.#at(node, "id"), _Window.#at(node, "blueprint")];\n if (_Window.#at(node, "kind") === "organ" && typeof id === "string" && typeof name === "string")\n organs.set(id, name);\n }\n const placeholders = _Window.#fields(blueprint["placeholders"]) ? blueprint["placeholders"] : {};\n const skins = Object.entries(placeholders).flatMap(\n ([placeholder, name]) => typeof name === "string" && organs.get(placeholder) === name ? [placeholder] : []\n );\n const about = {\n faculty: digest,\n name: blueprint["name"] ?? null,\n version: blueprint["version"] ?? null,\n placeholders: { ...placeholders },\n skins,\n world: skins.includes(_Window.#world)\n };\n this.cells.delete(_Window.#unmadeKey);\n this.cells.set(_Window.#aboutKey, about);\n return about;\n }\n #unmade(why) {\n this.cells.set(_Window.#unmadeKey, why);\n return { refused: why };\n }\n async #nodesHeld() {\n const nodes = [];\n let cursor = null;\n for (let page = 0; page < _Window.#mostListed; page += 1) {\n const state = await this.ask("brain", "state", cursor === null ? {} : { cursor });\n if ("error" in state) return { why: `the brain answers no state: ${state.error.message}` };\n const listed = _Window.#at(state.result, "nodes");\n if (Array.isArray(listed)) nodes.push(...listed);\n const next = _Window.#at(state.result, "cursor");\n cursor = typeof next === "string" ? next : null;\n if (cursor === null) break;\n }\n if (cursor !== null) return { why: _Window.#cutSay(_Window.#mostListed) };\n return { nodes };\n }\n static #cutSay(pages) {\n return `the organism holds more than the window reads, ${String(pages)} pages of its state: more stand than it shows`;\n }\n async #coreWiring(placeholders) {\n const expected = Object.entries(_Window.#fields(placeholders) ? placeholders : {}).filter(\n (entry) => typeof entry[1] === "string"\n );\n if (expected.length === 0) return { wiring: {} };\n const held = await this.#nodesHeld();\n if ("why" in held) return held;\n const core = new Map();\n for (const node of held.nodes) {\n const [id, blueprint, kind] = ["id", "blueprint", "kind"].map((key) => _Window.#at(node, key));\n if (typeof id === "string" && typeof blueprint === "string" && _Window.#at(node, "core") === true && kind !== "organ")\n core.set(blueprint, id);\n }\n return {\n wiring: Object.fromEntries(\n expected.flatMap(([placeholder, blueprint]) => {\n const id = core.get(blueprint);\n return id === void 0 ? [] : [[placeholder, id]];\n })\n )\n };\n }\n async #leave(args) {\n const relation = _Window.#at(args, "relation");\n const far = typeof relation === "string" ? _Window.#at(this.cells.get(["far-lobe", relation]), "far") : void 0;\n if (typeof relation !== "string" || typeof far !== "string" || far === "")\n return this.error(\n "refused",\n "the window leaves only a place it holds that is a far lobe: this one is left already, or is a standing of an owner, which is never left so"\n );\n if (!this.#consented(relation, relation, { method: "leave", consented: _Window.#at(args, "consented") ?? null })) {\n const set = this.#localSet({ over: relation, lobe: relation }, _Window.#consent, { asking: "leave" });\n return "error" in set ? set : { asking: "leave" };\n }\n const dropped = await this.#ends(far);\n if ("error" in dropped) return this.error(dropped.error.code, dropped.error.message);\n this.#consentSpent({ over: relation, lobe: relation });\n await this.left({ far });\n if (_Window.#relationOf(this.#walked()) === relation) {\n this.#forgetLocals();\n this.cells.set(["root"], []);\n }\n return { left: relation };\n }\n #leaveOf(over) {\n return over !== null && this.#farLobe(over) ? { leave: { press: { method: "leave", args: { relation: over } }, say: this.#word("leaveSay") } } : {};\n }\n async redeem(args) {\n const foreign = this.#foreign();\n if (foreign !== null) return foreign;\n const [card, reference] = [_Window.#at(args, "card"), _Window.#at(args, "reference")];\n if (!_Window.#fields(card) || typeof reference !== "string")\n return this.error("refused", "redeem names a card and a reference");\n const heard = await this.ask("mouth", "once", { card, method: _Window.#redeem, args: { reference } });\n if ("error" in heard) {\n if (heard.error.code === "unavailable") return this.error("refused", this.#word("redeemUnreachedSay"));\n if (heard.error.code === "timeout") return this.error("refused", this.#word("redeemTimeoutSay"));\n return this.error("refused", this.#word("redeemSpentSay"));\n }\n const given = _Window.#fields(heard.result) ? heard.result : {};\n const owed = Object.keys(given).length === 2 && ["text", "sig"].every((field) => typeof _Window.#at(given, field) === "string");\n return owed ? { invitation: JSON.stringify(given) } : this.error("refused", this.#word("redeemSpentSay"));\n }\n static #redeem = "#redeem";\n async offer(args) {\n const foreign = this.#foreign();\n if (foreign !== null) return foreign;\n const [card, reference] = [_Window.#at(args, "card"), _Window.#at(args, "reference")];\n if (!_Window.#fields(card) || typeof reference !== "string")\n return this.error("refused", "offer names a card and a reference");\n const heard = await this.ask("mouth", "once", { card, method: _Window.#offer, args: { reference } });\n if ("error" in heard)\n return heard.error.code === "unavailable" || heard.error.code === "timeout" ? { reached: false } : null;\n const offered = heard.result;\n if (!_Window.#fields(offered) || !Object.hasOwn(offered, "says")) return null;\n const [waits, lives] = [offered["waits"], offered["lives"]];\n return _Window.#spanned(waits) && _Window.#spanned(lives) ? { says: offered["says"] ?? null, waits, lives } : null;\n }\n static #offer = "#offer";\n static #spanned(span) {\n return span === null || typeof span === "number" && Number.isInteger(span) && span >= 0;\n }\n async #held() {\n const read = await this.nerves.read();\n if ("error" in read) return this.error("unavailable", `the window\'s nerves are not read: ${read.error.message}`);\n const held = [];\n for (const one of Array.isArray(read.result) ? read.result : []) {\n const placeholder = _Window.#at(one, "placeholder");\n if (typeof placeholder === "string") held.push(placeholder);\n }\n return held;\n }\n async standings() {\n const foreign = this.#foreign();\n if (foreign !== null) return foreign;\n const held = await this.#nerves();\n if ("why" in held) return this.error("refused", held.why);\n return {\n relations: held.relations.flatMap((one) => {\n const placeholder = _Window.#at(one, "placeholder");\n return typeof placeholder === "string" ? [\n {\n placeholder,\n note: _Window.#at(one, "note") ?? null,\n ..._Window.#at(one, "place") === true ? { place: true } : {}\n }\n ] : [];\n }),\n ...held.more ? { more: true } : {}\n };\n }\n async left(args) {\n const far = _Window.#at(args, "far");\n if (typeof far !== "string") return null;\n const ended = new Set();\n let cursor = null;\n do {\n const page = this.cells.range({ prefix: ["far-lobe"], ...cursor === null ? {} : { cursor } });\n for (const { key, value } of page.cells) if (_Window.#at(value, "far") === far) ended.add(String(key[1]));\n cursor = page.cursor;\n } while (cursor !== null);\n for (const { key, value } of this.cells.range({ prefix: ["far-organism"] }).cells)\n if (value === far) ended.add(String(key[1]));\n for (const relation of ended) this.#forget(relation);\n return null;\n }\n #forget(over) {\n for (const family of ["far-lobe", "far-organism", "moved", "told"]) this.cells.delete([family, over]);\n for (const family of ["described", "read", "last", "local"])\n for (const { key } of this.cells.range({ prefix: [family, over] }).cells) this.cells.delete(key);\n for (const index of ["describes", "reads", "locals"]) {\n const kept = this.#indexed([index]);\n const stays2 = kept.filter((one) => !Array.isArray(one) || one[1] !== over);\n if (stays2.length !== kept.length) this.cells.set([index], stays2);\n }\n const presses = this.#indexed(["presses"]);\n const stays = presses.filter((id) => {\n const gone = typeof id === "string" && _Window.#at(this.cells.get(["press", id]), "over") === over;\n if (gone) this.cells.delete(["press", id]);\n return !gone;\n });\n if (stays.length !== presses.length) this.cells.set(["presses"], stays);\n }\n async accept(args) {\n const foreign = this.#foreign();\n if (foreign !== null) return foreign;\n const [invitation, placeholder, note] = [\n _Window.#at(args, "invitation"),\n _Window.#at(args, "placeholder"),\n _Window.#at(args, "note")\n ];\n if (typeof invitation !== "string" || typeof placeholder !== "string" || !_Window.#relationName.test(placeholder))\n return this.error("refused", "accept names an invitation and a placeholder");\n const taken = `the window holds ${placeholder} already`;\n if (_Window.#own.includes(placeholder)) return this.error("refused", taken);\n const held = await this.#held();\n if (!Array.isArray(held)) return held;\n if (held.includes(placeholder)) return this.error("refused", taken);\n this.#forget(placeholder);\n const asked = { invitation, placeholder, note: note ?? null };\n const accepted = await this.ask("mouth", "accept", asked);\n if ("error" in accepted) return this.error(accepted.error.code, accepted.error.message);\n const knocked = await this.ask(placeholder, null, {});\n const far = _Window.#at(accepted.result, "far");\n if ("error" in knocked) {\n if (typeof far === "string") await this.#ends(far);\n return this.error(\n "refused",\n knocked.error.code === "unavailable" ? `nothing answered at the addresses the invitation names (${knocked.error.message}), so the window holds no ${placeholder}: its organism is down, or this side cannot reach it, as from behind a router. A relation takes one side the other reaches: the inviter\'s organism at a public address, or an invitation drawn through an organism always on that both reach (\\`through\\`).` : `the invitation was spent, ended or wrong, so the window holds no ${placeholder}: ${knocked.error.message}`\n );\n }\n this.#keepKnocked(placeholder, typeof far === "string" ? far : "", knocked);\n const route = [{ relation: placeholder }];\n return {\n far: typeof far === "string" ? far : "",\n route,\n text: _Window.#text(route)\n };\n }\n #lobeAt(path) {\n const route = _Window.#read(path);\n if (route === void 0) return void 0;\n const over = _Window.#relationOf(route);\n if (this.#lobeOfFarLobe(route)) return void 0;\n const lobe = this.#lobeReached(route);\n return lobe === null ? void 0 : { over, lobe };\n }\n static #methodOf(described, method) {\n const found = _Window.#at(_Window.#at(described, "methods"), method);\n return _Window.#fields(found) ? found : void 0;\n }\n static #reads(declared) {\n return _Window.#fields(declared) && declared["kind"] === "reading";\n }\n static #unsaid(declared) {\n const kind = _Window.#at(declared, "kind");\n return declared !== void 0 && kind !== "reading" && kind !== "writing";\n }\n async #describedOf(over, lobe) {\n const kept = over === null ? void 0 : this.#keptDescribed(over, lobe);\n return kept === void 0 ? this.#through(over, lobe, null, {}) : { result: kept };\n }\n static #trimmed(index, most, forget) {\n const cut = Math.max(0, index.length - most);\n for (const old of index.slice(0, cut)) forget(old);\n return index.slice(cut);\n }\n #indexed(key) {\n const held = this.cells.get(key);\n return Array.isArray(held) ? held : [];\n }\n static #keyed(entry) {\n return Array.isArray(entry) && entry.every((one) => typeof one === "string") ? entry.map(String) : void 0;\n }\n async read(args) {\n const foreign = this.#foreign();\n if (foreign !== null) return foreign;\n const at = this.#lobeAt(_Window.#at(args, "path"));\n const method = _Window.#at(args, "method");\n const cells = _Window.#at(args, "cells");\n const values = _Window.#at(args, "values") ?? {};\n if (at === void 0 || typeof method !== "string" || !_Window.#fields(values))\n return this.error("refused", "a read names a lobe by its path, and a method");\n const described = await this.#describedOf(at.over, at.lobe);\n if ("error" in described) return this.error("refused", `${at.lobe} is not described: ${described.error.message}`);\n const declared = _Window.#methodOf(described.result, method);\n if (!_Window.#reads(declared)) return this.error("refused", `${at.lobe} declares no reading method ${method}`);\n const schema = _Window.#at(declared, "args");\n const properties = _Window.#at(schema, "properties");\n const own = _Window.#fields(properties) ? Object.fromEntries(Object.entries(values).filter(([name]) => Object.hasOwn(properties, name))) : {};\n const fit = _Window.#fit(schema, own);\n if ("why" in fit) return this.error("refused", fit.why);\n const asked = _Window.#fields(fit.values) ? fit.values : {};\n const heard = await this.#readKept(at.over, at.lobe, method, typeof cells === "string" ? cells : null, asked);\n return { kept: "error" in heard ? "error" : "answer" };\n }\n async #readKept(over, lobe, method, cells, values) {\n const heard = _Window.#heard(await this.#through(over, lobe, method, values));\n const key = _Window.#readKey(over, lobe, method);\n this.cells.set(key, {\n cells: this.#heldBy(over, cells),\n ...heard,\n ...Object.keys(values).length === 0 ? {} : { values }\n });\n const named = JSON.stringify(key);\n const index = this.#indexed(["reads"]).filter((one) => JSON.stringify(one) !== named);\n const kept = _Window.#trimmed([...index, [...key]], this.#keptReads(), (old) => {\n const gone = _Window.#keyed(old);\n if (gone !== void 0) this.cells.delete(gone);\n });\n this.cells.set(["reads"], [...kept]);\n return heard;\n }\n write(args) {\n const foreign = this.#foreign();\n if (foreign !== null) return foreign;\n const at = this.#lobeAt(_Window.#at(args, "path"));\n const [id, method, values, seen] = [\n _Window.#at(args, "id"),\n _Window.#at(args, "method"),\n _Window.#at(args, "values"),\n _Window.#at(args, "seen")\n ];\n if (at === void 0 || typeof id !== "string" || typeof method !== "string" || !_Window.#fields(values))\n return this.error("refused", "a write names its id, a lobe by its path, a method and its values");\n if (this.cells.get(["press", id]) !== void 0) return { id };\n this.cells.set(["press", id], {\n over: at.over,\n lobe: at.lobe,\n method,\n values,\n seen: typeof seen === "string" ? seen : null,\n far: this.#standing(at.over),\n ..._Window.#at(args, "declared") === true ? { declared: true } : {},\n ..._Window.#at(args, "consented") === true ? { consented: true } : {}\n });\n const kept = _Window.#trimmed([...this.#indexed(["presses"]), id], this.#keptHalf(), (old) => {\n if (typeof old !== "string") return;\n const press = this.cells.get(["press", old]);\n const last = _Window.#fields(press) ? ["last", typeof press["over"] === "string" ? press["over"] : "", _Window.#shown(press["lobe"])] : null;\n if (last !== null && this.cells.get(last) === old) this.cells.delete(last);\n this.cells.delete(["press", old]);\n });\n this.cells.set(["presses"], [...kept]);\n return { id };\n }\n async back(args) {\n if (this.stamp.asker !== "brain") return this.error("refused", "only the brain says what came back");\n if (_Window.#at(args, "placeholder") === "screen") await this.#lay();\n return null;\n }\n async #given() {\n const read = await this.ask("nerves", "given", {});\n const design = "result" in read ? _Window.#at(read.result, "design") : void 0;\n const digest = _Window.#at(design, "digest");\n return typeof digest === "string" ? { digest, settings: _Window.#at(design, "settings") ?? null } : null;\n }\n async #lay() {\n const given = await this.#given();\n if (given === null) return;\n const held = await this.#nerves();\n if ("why" in held) return;\n const children = await this.ask("nerves", "children", {});\n const own = "result" in children && Array.isArray(children.result) ? children.result : [];\n const on = await this.ask("brain", "lobes", { faculty: given.digest });\n const ports = "result" in on && Array.isArray(on.result) ? on.result : [];\n if (held.design === null) {\n const stands = ports.find((one) => typeof one === "string" && own.includes(one));\n await (stands === void 0 ? this.#born(given) : this.#wornAgain(stands, given));\n return;\n }\n if (!own.includes(held.design) || this.cells.get(_Window.#chosen) === true) return;\n if (ports.includes(held.design)) return;\n const [worn, kept] = await Promise.all([\n this.ask("design", null, {}),\n this.#through(null, "library", "get", { digest: given.digest })\n ]);\n const name = "result" in kept ? _Window.#at(_Window.#at(kept.result, "blueprint"), "name") : void 0;\n if (typeof name === "string" && "result" in worn && _Window.#at(worn.result, "name") !== name) {\n if (await this.#born(given)) await this.ask("nerves", "tearDown", { lobe: held.design });\n return;\n }\n const moved = await this.ask("nerves", "version", { lobe: held.design, faculty: given.digest, settled: true });\n if ("error" in moved) return;\n await this.#tinted(given.settings);\n }\n async #born(given) {\n const kept = await this.#through(null, "library", "get", { digest: given.digest });\n if (this.#unwearable("result" in kept ? _Window.#at(kept.result, "blueprint") : void 0) !== null) return false;\n const created = await this.ask("nerves", "create", { faculty: given.digest, sealed: true });\n const id = "result" in created ? _Window.#at(created.result, "id") : void 0;\n if (typeof id !== "string") return false;\n const ordered = await this.nerves.order({ termination: id, placeholder: "design" });\n if ("error" in ordered) return false;\n this.cells.delete(_Window.#chosen);\n await this.#tinted(given.settings);\n return true;\n }\n async #wornAgain(lobe, given) {\n const ordered = await this.nerves.order({ termination: lobe, placeholder: "design" });\n if ("error" in ordered) return false;\n this.cells.delete(_Window.#chosen);\n await this.#tinted(given.settings);\n return true;\n }\n async #tinted(settings) {\n const tint = _Window.#at(settings, "tint");\n if (typeof tint === "string") await this.ask("design", "set", { tint });\n }\n async worn() {\n const foreign = this.#foreign();\n if (foreign !== null) return foreign;\n const files = await this.ask("design", "files", {});\n return "result" in files ? files.result : this.error(files.error.code, files.error.message);\n }\n async wear(args) {\n if (this.stamp.asker !== "brain" && this.stamp.asker !== _Window.#organ)\n return this.error("refused", "a design is worn by the screen or an owner\'s word through the brain");\n return this.#wearOrTell(args);\n }\n async #wearOrTell(args) {\n const worn = await this.#wearing(args);\n const why = "code" in worn ? worn["message"] : void 0;\n if (typeof why === "string") return this.#unmade(why);\n this.cells.delete(_Window.#unmadeKey);\n return worn;\n }\n async #wearing(args) {\n const design = _Window.#at(args, "design");\n if (typeof design !== "string" || !/^[0-9a-f]{64}$/u.test(design))\n return this.error("refused", "wear names a design by its look\u2019s digest");\n const held = await this.#nerves();\n if ("why" in held) return this.error("unavailable", held.why);\n const lobes = await this.ask("brain", "lobes", { faculty: design });\n if ("error" in lobes) return this.error(lobes.error.code, lobes.error.message);\n const designed = (Array.isArray(lobes.result) ? lobes.result : []).filter((one) => typeof one === "string");\n if (designed.some((one) => one === held.design)) return { design, lobe: held.design };\n const standing = designed[0];\n const unworn = typeof standing === "string" ? await this.#standingUnwearable(standing) : null;\n if (unworn !== null) return unworn;\n const made = typeof standing === "string" ? null : await this.#madeOn(design);\n if (made !== null && typeof made !== "string") return made;\n const lobe = typeof standing === "string" ? standing : made;\n if (typeof lobe !== "string") return this.error("refused", "the brain named no lobe on the look");\n const fenced = await this.#fencedLobe(lobe);\n if (fenced !== null) {\n if (made !== null) await this.ask("brain", "tearDown", { lobe });\n return this.error("refused", fenced);\n }\n const ordered = await this.nerves.order({ termination: lobe, placeholder: "design" });\n if ("error" in ordered) return this.error("refused", `the window wears no ${lobe}: ${ordered.error.message}`);\n const given = await this.#given();\n if (given !== null && given.digest === design) this.cells.delete(_Window.#chosen);\n else this.cells.set(_Window.#chosen, true);\n return { design, lobe };\n }\n static #listedBy(blueprint) {\n const draw = _Window.#at(_Window.#at(blueprint, "methods"), "draw");\n const component = _Window.#at(_Window.#at(_Window.#at(_Window.#at(draw, "args"), "properties"), "component"), "enum");\n return Array.isArray(component) ? component : [];\n }\n #unwearable(blueprint) {\n const drawn = _Window.#listedBy(blueprint);\n if (_Window.#components.every((one) => drawn.includes(one))) return null;\n return this.error(\n "refused",\n "the design draws not the surround, the organism and the lobe: the window cannot wear it"\n );\n }\n async #standingUnwearable(lobe) {\n const described = await this.#through(null, lobe, null, {});\n if ("error" in described)\n return this.error("refused", `the window reads not what ${lobe} draws: ${described.error.message}`);\n return this.#unwearable(described.result);\n }\n async #madeOn(look) {\n const kept = await this.#through(null, "library", "get", { digest: look });\n const blueprint = "result" in kept ? _Window.#at(kept.result, "blueprint") : void 0;\n if (blueprint === void 0) return this.error("refused", `the library keeps no look ${look}`);\n const unworn = this.#unwearable(blueprint);\n if (unworn !== null) return unworn;\n const created = await this.ask("brain", "create", { faculty: look, sealed: true });\n if ("error" in created)\n return this.error("refused", `the brain makes no lobe of ${look}: ${created.error.message}`);\n const id = _Window.#at(created.result, "id");\n return typeof id === "string" ? id : this.error("refused", "the brain named no lobe on the look");\n }\n async #facultiesKept() {\n const listed = await this.#through(null, "library", "list", { limit: _Window.#mostFaculties });\n if ("error" in listed) return void 0;\n const kept = _Window.#at(listed.result, "faculties");\n if (!Array.isArray(kept)) return void 0;\n const faculties = [];\n let more = typeof _Window.#at(listed.result, "cursor") === "string";\n for (const one of kept) {\n const [name, digest] = ["name", "digest"].map((key) => _Window.#at(one, key));\n if (typeof name !== "string" || typeof digest !== "string") continue;\n if (faculties.length < _Window.#mostFaculties)\n faculties.push({ name, label: _Window.#at(one, "label") ?? null, faculty: digest });\n else more = true;\n }\n return { faculties, more };\n }\n #pressOf(args) {\n const foreign = this.#foreign();\n if (foreign !== null) return foreign;\n const id = _Window.#at(args, "id");\n const press = typeof id === "string" ? this.cells.get(["press", id]) : void 0;\n return typeof id === "string" && _Window.#fields(press) ? { id, press } : this.error("refused", "the window kept no such press");\n }\n static #kept(press) {\n if (!("answer" in press || "error" in press)) return void 0;\n return {\n method: _Window.#shown(press["method"]),\n ..."error" in press ? { error: press["error"] } : { answer: press["answer"] ?? null }\n };\n }\n async send(args) {\n const found = this.#pressOf(args);\n if ("code" in found) return found;\n const { id, press } = found;\n const kept = _Window.#kept(press);\n if (kept !== void 0) return kept;\n const method = _Window.#shown(press["method"]);\n if (press["sent"] === true) return { method, unknown: true };\n const [over, lobe] = [typeof press["over"] === "string" ? press["over"] : null, _Window.#shown(press["lobe"])];\n if (this.#consentOf(over, lobe, press)?.["taken"] !== void 0) {\n this.#pressDropped(id);\n return { method, taken: true };\n }\n const consented = this.#consented(over, lobe, press);\n if (!consented) {\n const described = await this.#describedOf(over, lobe);\n const declared = "result" in described ? _Window.#methodOf(described.result, method) : void 0;\n if (_Window.#waits(declared, over)) {\n const fit = _Window.#fit(_Window.#at(declared, "args"), press["values"], press["declared"] === true);\n return this.#heldBack({ over, lobe }, method, "why" in fit ? press["values"] ?? null : fit.values, declared);\n }\n }\n if (!this.#stands(press)) {\n this.#pressDropped(id);\n return this.error("refused", "the place this press was made for is held no more");\n }\n this.cells.set(["press", id], { ...press, sent: true, ...consented ? { took: true } : {} });\n if (consented) this.#consentTaken({ over, lobe }, id);\n this.cells.set(["last", typeof press["over"] === "string" ? press["over"] : "", _Window.#shown(press["lobe"])], id);\n return { method, sending: true };\n }\n static #fitValue(name, schema, value, required) {\n if (typeof value !== "string") return { value };\n if (value === "" && !required) return { value: void 0 };\n const type = _Window.#at(schema, "type");\n if (Array.isArray(_Window.#at(schema, "enum"))) return { value };\n if (type === "string") return { value };\n if (type === "number" || type === "integer") {\n const number = Number(value);\n if (value.trim() === "" || !Number.isFinite(number)) return { why: `${name} is not a number` };\n return type === "integer" && !Number.isInteger(number) ? { why: `${name} is not a whole number` } : { value: number };\n }\n if (type === "boolean") return { value: value === "on" || value === "true" };\n return _Window.#json(name, value);\n }\n static #json(name, text) {\n try {\n const read = JSON.parse(text);\n return { value: read };\n } catch {\n return { why: `${name} is not JSON` };\n }\n }\n static #fit(schema, values, declared = false) {\n const given = _Window.#fields(values) ? values : {};\n const properties = _Window.#at(schema, "properties");\n if (!_Window.#fields(properties)) {\n const text = given["args"];\n if (typeof text !== "string") return { values: declared && _Window.#fields(values) ? values : {} };\n if (text.trim() === "") return { values: {} };\n const read = _Window.#json("args", text);\n return "why" in read ? read : { values: read.value };\n }\n const required = _Window.#at(schema, "required");\n const fitted = {};\n for (const [name, value] of Object.entries(given)) {\n if (!Object.hasOwn(properties, name)) continue;\n const one = _Window.#fitValue(name, properties[name], value, Array.isArray(required) && required.includes(name));\n if ("why" in one) return one;\n if (one.value !== void 0) fitted[name] = one.value;\n }\n return { values: fitted };\n }\n async #asked(far, lobe, method, declared, values, asked = false) {\n const fit = _Window.#unsaid(declared) ? { values: _Window.#fields(values) ? values : {} } : _Window.#fit(_Window.#at(declared, "args"), values, asked);\n if ("why" in fit) return { heard: { error: { code: "refused", message: fit.why } }, given: {} };\n return { heard: _Window.#heard(await this.#through(far, lobe, method, fit.values)), given: fit.values };\n }\n async deliver(args) {\n const found = this.#pressOf(args);\n if ("code" in found) return found;\n const { id, press } = found;\n const kept = _Window.#kept(press);\n if (kept !== void 0) return kept;\n const [lobe, method, over, seen] = [press["lobe"], press["method"], press["over"], press["seen"]];\n if (press["sent"] !== true || typeof lobe !== "string" || typeof method !== "string")\n return this.error("refused", "a press is delivered after it is sent");\n const far = typeof over === "string" ? over : null;\n const described = await this.#describedOf(far, lobe);\n let heard;\n const declared = "result" in described ? _Window.#methodOf(described.result, method) : void 0;\n const version = "result" in described ? _Window.#at(described.result, "version") : void 0;\n if ("error" in described)\n heard = { error: { code: "unavailable", message: `${lobe} did not answer: ${described.error.message}` } };\n else if (declared === void 0 || _Window.#reads(declared))\n heard = { error: { code: "refused", message: `${lobe} declares no writing method ${method}` } };\n else if (_Window.#waits(declared, far) && press["took"] !== true)\n heard = {\n error: {\n code: "refused",\n message: _Window.#irreversible(declared) ? `${method} cannot be undone: it is asked only with the person\'s consent, which the home asks first` : `${lobe} says nothing of what ${method} does: it is asked only with the person\'s consent, which the home asks first`\n }\n };\n else if (press["declared"] === true && _Window.#at(_Window.#at(declared, "seat"), "for") === "machine")\n heard = {\n error: { code: "refused", message: `${method} is declared for a machine: a declared press asks it not` }\n };\n else if (typeof seen === "string" && version !== seen)\n heard = {\n error: { code: "stale", message: `the screen showed version ${seen}, and ${_Window.#shown(version)} stands` }\n };\n else {\n const asked = await this.#asked(far, lobe, method, declared, press["values"], press["declared"] === true);\n heard = _Window.#shaped(declared, asked.heard, this.stamp.time, _Window.#filesOf(asked.given), far !== null);\n this.#movedAt(far);\n }\n if (press["took"] === true) this.#consentSpent({ over: far, lobe }, id);\n if (!this.#stands(press)) {\n this.#pressDropped(id);\n return { method, ...heard };\n }\n const channeled = "answer" in heard && _Window.#at(_Window.#seatOf(declared), "intent") === "channel";\n this.cells.set(["press", id], { ...press, ...heard, ...channeled ? { channeled: true } : {} });\n this.cells.set(["last", far ?? "", lobe], id);\n return { method, ...heard };\n }\n async #wiresOf(over, lobe) {\n let node;\n let cursor = null;\n for (let page = 0; page < _Window.#mostListed && node === void 0; page += 1) {\n const state = await this.ask(\n over ?? "brain",\n "state",\n cursor === null ? {} : { cursor },\n _Window.#lobeWithin\n );\n if ("error" in state) return { why: `the brain\'s state is not read: ${state.error.message}` };\n const nodes = _Window.#at(state.result, "nodes");\n node = Array.isArray(nodes) ? nodes.find((one) => _Window.#at(one, "id") === lobe) : void 0;\n const next = _Window.#at(state.result, "cursor");\n cursor = typeof next === "string" ? next : null;\n if (cursor === null) break;\n }\n if (node === void 0 && cursor !== null) return { why: _Window.#cutSay(_Window.#mostListed) };\n if (node === void 0) return { why: `the brain holds no ${lobe}` };\n const wires = {};\n const held = _Window.#at(node, "wires");\n for (const wire of Array.isArray(held) ? held : []) {\n const placeholder = _Window.#at(wire, "placeholder");\n const termination = _Window.#at(wire, "termination");\n if (typeof placeholder === "string" && typeof termination === "string") wires[placeholder] = termination;\n }\n return { wires };\n }\n static words = {\n homeWord: "Home",\n wayOutSay: "Home",\n leaveSay: "Leave this place",\n leavingSay: "Leave this place? You will no longer hold its standing, and it is given up with it.",\n yesSay: "Yes",\n noSay: "No",\n unsaidSay: "This place does not say what this ask does, and it may change something. Ask it?",\n irreversibleSay: "This cannot be undone. Ask it?",\n organismSilentSay: "This organism did not answer.",\n lobeSilentSay: "This lobe did not answer.",\n moreFacultiesSay: "The library keeps more faculties than this page shows.",\n moreNotesSay: "The window holds more relations than it read the notes of: those past them show none.",\n redeemUnreachedSay: "the place this link leads to was not reached. The link is not spent: try again",\n redeemTimeoutSay: "no reply came in time. The link may be spent: try once more, and ask for a new link if it fails",\n redeemSpentSay: "the link is spent, ended or wrong: ask for a new one"\n };\n};\nexport {\n Window as default\n};\n';
28733
28733
 
28734
28734
  var WINDOW2 = {
28735
28735
  faculty: WINDOW_SOURCE,
@@ -28740,7 +28740,7 @@ var WINDOW2 = {
28740
28740
 
28741
28741
  var LONGEST_TIMEOUT = 1e4;
28742
28742
 
28743
- var INSTALLER_VERSION = "0.37.11";
28743
+ var INSTALLER_VERSION = "0.37.12";
28744
28744
 
28745
28745
  var ROAD = `installers@${INSTALLER_VERSION}`;
28746
28746
  var SKIN = { ...WINDOW2, road: ROAD };