@nervur.org/floor 0.37.10 → 0.37.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- var TERMINAL_SOURCE = 'var BYTES = "$bytes";\n\nvar ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";\nvar NONE = 64;\nvar VALUES = new Uint8Array(256).fill(NONE);\nfor (let at = 0; at < ALPHABET.length; at += 1) VALUES[ALPHABET.charCodeAt(at)] = at;\n\nvar utf8Bytes = (text) => {\n if (!text.isWellFormed()) throw new TypeError("a text with a lone surrogate has no UTF-8 bytes");\n const ascii = new Uint8Array(text.length);\n let start = 0;\n for (; start < text.length; start++) {\n const unit = text.charCodeAt(start);\n if (unit >= 128) break;\n ascii[start] = unit;\n }\n if (start === text.length) return ascii;\n const out = new Uint8Array(text.length * 3);\n out.set(ascii.subarray(0, start));\n let length = start;\n for (let at = start; at < text.length; at++) {\n const unit = text.charCodeAt(at);\n if (unit < 128) {\n out[length++] = unit;\n continue;\n }\n const code2 = text.codePointAt(at) ?? 0;\n if (code2 < 2048) {\n out[length++] = 192 | code2 >> 6;\n out[length++] = 128 | code2 & 63;\n } else if (code2 < 65536) {\n out[length++] = 224 | code2 >> 12;\n out[length++] = 128 | code2 >> 6 & 63;\n out[length++] = 128 | code2 & 63;\n } else {\n out[length++] = 240 | code2 >> 18;\n out[length++] = 128 | code2 >> 12 & 63;\n out[length++] = 128 | code2 >> 6 & 63;\n out[length++] = 128 | code2 & 63;\n at++;\n }\n }\n return out.slice(0, length);\n};\n\nvar DIGITS = "0123456789abcdef";\nvar PAIRS = Array.from(\n { length: 256 },\n (_, byte) => `${DIGITS[byte >> 4] ?? ""}${DIGITS[byte & 15] ?? ""}`\n);\nvar HIGH = Array.from({ length: 256 }, (_, byte) => DIGITS.charCodeAt(byte >> 4));\nvar LOW = Array.from({ length: 256 }, (_, byte) => DIGITS.charCodeAt(byte & 15));\nvar VALUES2 = Int8Array.from({ length: 256 }, (_, unit) => DIGITS.indexOf(String.fromCharCode(unit)));\n\nvar OPEN = utf8Bytes(`{"${BYTES}":"`);\nvar CLOSE = utf8Bytes(\'"}\');\n\nvar GENOME_CODES = [\n "timeout",\n "unavailable",\n "busy",\n "fault",\n "silent",\n "removed",\n "repeated"\n];\nvar GENOME = new Set(GENOME_CODES);\n\nvar PATTERN_STATES = 1e4;\nvar NAMES = "L Ll Lm Lo Lt Lu M Mc Me Mn N Nd Nl No P Pc Pd Pe Pf Pi Po Ps Z Zl Zp Zs S Sc Sk Sm So";\nvar CATEGORIES = new Set(`${NAMES} C Cc Cf Cn Co`.split(" "));\nvar ESCAPED = new Set("()*+-.?[\\\\]^{|}");\nvar code = (char) => char.codePointAt(0) ?? -1;\nvar [BACKSLASH, DASH, CARET, DOLLAR, BAR, COMMA] = ["\\\\", "-", "^", "$", "|", ","].map(code);\nvar [OPEN2, CLOSE2, SQUARE_OPEN, SQUARE_CLOSE] = ["(", ")", "[", "]"].map(code);\nvar [BRACE_OPEN, BRACE_CLOSE, DOT_CHAR] = ["{", "}", "."].map(code);\nvar single = (point) => ({\n ranges: [{ low: point, high: point }],\n categories: [],\n negated: false\n});\nvar DOT = {\n ranges: [...single(10).ranges, ...single(13).ranges],\n categories: [],\n negated: true\n};\n\nvar OF_CATEGORY = new Map(\n [...CATEGORIES].map((name) => [name, new RegExp(`^\\\\p{${name}}$`, "u")])\n);\n\nvar REFUSED = { why: `it compiles past ${PATTERN_STATES} states` };\n\nvar DIGEST = { type: "string", pattern: "^[0-9a-f]{64}$" };\nvar ROADS = ["genome", "installer", "owners", "other"];\nvar MOVED_LOBE = {\n type: "object",\n properties: {\n faculty: DIGEST,\n cells: DIGEST,\n wires: { type: "object", additionalProperties: { type: "string", minLength: 1 } },\n road: { enum: [...ROADS] }\n },\n required: ["faculty", "cells", "wires", "road"],\n additionalProperties: false\n};\n\nvar INPUTS = new Set(\n "text search number range checkbox radio date time email tel color file".split(" ")\n);\nvar NUMBER = "number";\nvar FLAG = "flag";\nvar pairs = (names, form) => names.split(" ").map((name) => [name, form]);\nvar CAPS = { one: ["butt", "round", "square"] };\nvar JOINS = { one: ["miter", "round", "bevel"] };\nvar ANCHORS = { one: ["start", "middle", "end"] };\nvar BASELINES = {\n one: ["auto", "middle", "hanging", "central", "text-before-edge", "text-after-edge"]\n};\nvar UNITS = { one: ["userSpaceOnUse", "objectBoundingBox"] };\nvar PAINT = new Map([\n ["transform", "transform"],\n ["fill", "paint"],\n ["stroke", "paint"],\n ["stroke-width", NUMBER],\n ["stroke-linecap", CAPS],\n ["stroke-linejoin", JOINS],\n ["stroke-dasharray", "numbers"],\n ["opacity", NUMBER],\n ["fill-opacity", NUMBER],\n ["stroke-opacity", NUMBER],\n ["clip-path", "ref"]\n]);\nvar TEXT_LOOK = new Map([\n ["text-anchor", ANCHORS],\n ["dominant-baseline", BASELINES],\n ["font-size", NUMBER]\n]);\nvar drawn = (own, ...more) => new Map([...own, ...more.flatMap((one) => [...one])]);\nvar SVG = new Set(\n "svg g path circle ellipse rect line polyline polygon text tspan title desc defs clipPath linearGradient radialGradient stop".split(\n " "\n )\n);\nfunction svgElements() {\n const shape = (names, form = NUMBER) => new Map(pairs(names, form));\n return [\n [\n "svg",\n drawn(\n shape("width height"),\n new Map([\n ["viewBox", "viewbox"],\n ["preserveAspectRatio", "aspect"]\n ]),\n PAINT\n )\n ],\n ["g", drawn(PAINT, TEXT_LOOK)],\n ["path", drawn(shape("d", "pathdata"), PAINT)],\n ["circle", drawn(shape("cx cy r"), PAINT)],\n ["ellipse", drawn(shape("cx cy rx ry"), PAINT)],\n ["rect", drawn(shape("x y width height rx ry"), PAINT)],\n ["line", drawn(shape("x1 y1 x2 y2"), PAINT)],\n ["polyline", drawn(shape("points", "numbers"), PAINT)],\n ["polygon", drawn(shape("points", "numbers"), PAINT)],\n ["text", drawn(shape("x y"), PAINT, TEXT_LOOK)],\n ["tspan", drawn(shape("x y"), PAINT, TEXT_LOOK)],\n ["title", new Map()],\n ["desc", new Map()],\n ["defs", new Map()],\n ["clipPath", new Map()],\n ["linearGradient", drawn(shape("x1 y1 x2 y2"), shape("gradientUnits", UNITS))],\n ["radialGradient", drawn(shape("cx cy r"), shape("gradientUnits", UNITS))],\n ["stop", drawn(shape("offset"), shape("stop-color", "color"))]\n ];\n}\nvar GLOBAL = new Map([\n ["class", "classes"],\n ["id", "name"],\n ["title", "text"],\n ["lang", "name"],\n ["dir", { one: ["ltr", "rtl", "auto"] }],\n ["hidden", FLAG],\n ["role", "name"],\n ["aria-label", "text"],\n ["aria-hidden", { one: ["true", "false"] }],\n ["aria-current", { one: ["page", "step", "true", "false"] }],\n ["aria-live", { one: ["off", "polite"] }],\n ["aria-pressed", { one: ["true", "false", "mixed"] }],\n ["aria-expanded", { one: ["true", "false"] }],\n ["aria-invalid", { one: ["true", "false"] }],\n ["aria-describedby", "name"],\n ["aria-busy", { one: ["true", "false"] }],\n ...pairs("swipe-left swipe-right swipe-up swipe-down hold drag", "name"),\n ["drop", "text"],\n ["morph", "name"],\n ["opens", FLAG]\n]);\nvar TYPING = [\n ["autocorrect", { one: ["on", "off"] }],\n ["autocapitalize", { one: ["off", "none", "on", "sentences", "words", "characters"] }],\n ["spellcheck", { one: ["true", "false"] }],\n ["inputmode", { one: ["none", "text", "decimal", "numeric", "tel", "search", "email", "url"] }],\n ["enterkeyhint", { one: ["enter", "done", "go", "next", "previous", "search", "send"] }]\n];\nvar PLAIN = "div span p h1 h2 h3 h4 header footer main nav aside section article ul dl dt dd strong em small mark s sub sup abbr q blockquote br hr figure figcaption legend table caption thead tbody tfoot tr summary";\nvar ELEMENTS = new Map([\n ...PLAIN.split(" ").map((name) => [name, new Map()]),\n ["ol", new Map(pairs("start", NUMBER))],\n ["li", new Map(pairs("value", NUMBER))],\n ["img", new Map([["src", "asset"], ["alt", "text"], ...pairs("width height", NUMBER)])],\n ["audio", new Map([["src", "sound"], ...pairs("controls", FLAG)])],\n [\n "time",\n new Map([...pairs("datetime", "text"), ["deadline", "instant"], ["shows", { one: ["day", "time"] }]])\n ],\n ["data", new Map([...pairs("value ref", "text"), ...pairs("field", "name")])],\n ["a", new Map(pairs("href", "link"))],\n ["pre", new Map()],\n ["code", new Map()],\n ["meter", new Map(pairs("value min max low high", NUMBER))],\n ["progress", new Map(pairs("value max", NUMBER))],\n ["button", new Map([...pairs("disabled", FLAG), ["copies", "name"]])],\n ["label", new Map(pairs("for", "name"))],\n [\n "input",\n new Map([\n ["type", "input"],\n ...pairs("name autocomplete", "name"),\n ...pairs("value placeholder", "text"),\n ...pairs("min max step maxlength minlength", NUMBER),\n ...pairs("checked disabled required readonly", FLAG),\n ...TYPING,\n ["enter", "name"]\n ])\n ],\n [\n "textarea",\n new Map([\n ...pairs("name autocomplete", "name"),\n ...pairs("placeholder", "text"),\n ...pairs("rows maxlength minlength", NUMBER),\n ...pairs("disabled required readonly", FLAG),\n ...TYPING\n ])\n ],\n ["select", new Map([...pairs("name", "name"), ...pairs("disabled", FLAG)])],\n ["option", new Map([...pairs("value", "text"), ...pairs("selected", FLAG)])],\n ["fieldset", new Map(pairs("disabled", FLAG))],\n ["th", new Map([["scope", { one: ["row", "col"] }], ...pairs("colspan", NUMBER)])],\n ["td", new Map(pairs("colspan", NUMBER))],\n ["details", new Map(pairs("open", FLAG))],\n ["slot", new Map(pairs("placeholder", "name"))],\n ...svgElements()\n]);\n\nvar set = (names) => new Set(names.split(" "));\nvar PARENTS = new Map([\n ["li", set("ul ol")],\n ["dt", set("dl")],\n ["dd", set("dl")],\n ["option", set("select")],\n ["summary", set("details")],\n ["caption", set("table")],\n ["thead", set("table")],\n ["tbody", set("table")],\n ["tfoot", set("table")],\n ["tr", set("thead tbody tfoot")],\n ["th", set("tr")],\n ["td", set("tr")]\n]);\nvar HOLDS = new Map([\n ["table", set("caption thead tbody tfoot")],\n ["thead", set("tr")],\n ["tbody", set("tr")],\n ["tfoot", set("tr")],\n ["tr", set("th td")],\n ["select", set("option")],\n ["option", new Set()]\n]);\nvar TEXTS = set("option");\nvar EMPTY = set("textarea slot audio");\nvar BLOCK = "div p h1 h2 h3 h4 header footer main nav aside section article ul ol dl dt dd li blockquote pre figure figcaption table hr details summary fieldset";\nvar HEADINGS = "h1 h2 h3 h4";\nvar HEADING = set(HEADINGS);\nvar NOT_WITHIN = new Map([\n ...BLOCK.split(" ").map((name) => [\n name,\n set(HEADING.has(name) ? `p ${HEADINGS}` : "p")\n ]),\n ["a", set("a")],\n ["button", set("button")]\n]);\nvar ENCLOSING = set(`p a button ${HEADINGS}`);\n\nvar NUM = String.raw`-?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(?:[eE][-+]?\\d+)?`;\nvar NUMBERS = new RegExp(`^${NUM}(?:[ ,]+${NUM})*$`, "u");\nvar VIEWBOX = new RegExp(`^${NUM}(?:[ ,]+${NUM}){3}$`, "u");\nvar TRANSFORM = new RegExp(\n `^(?:(?:translate|scale|rotate|skewX|skewY|matrix)\\\\( ?${NUM}(?:[ ,]+${NUM})* ?\\\\) ?)+$`,\n "u"\n);\nvar COLOR = new RegExp(\n `^(?:currentColor|transparent|[a-z]{3,20}|#(?:[0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})|(?:rgb|rgba|hsl|hsla)\\\\( ?${NUM}%?(?:[ ,]+${NUM}%?){2,3} ?\\\\))$`,\n "u"\n);\n\nvar GESTURES = new Map([\n ...["swipe-left", "swipe-right", "swipe-up", "swipe-down", "hold"].map((name) => [\n name,\n new Set(["button", "summary"])\n ]),\n ["drag", new Set(["select"])]\n]);\n\nvar LOBE_SHARE = 4;\nvar ITEM_SIZE = 1024;\nvar AS_LONG_AS_IT_MAY = 9007199254740991;\n\nimport { Faculty } from "nervur:faculty";\nvar Terminal = class _Terminal extends Faculty {\n static #organ = "console";\n static #asLongAsItMay = AS_LONG_AS_IT_MAY;\n static #own = ["brain", "mouth", "console"];\n static #world = "network";\n static blueprint = {\n name: "nervur.terminal",\n version: "0.32.3",\n description: "The console\'s present lobe: the owner\'s terminal, turning each line typed into asks, and holding the relations to the organisms its owners own from afar.",\n methods: {\n line: {\n description: "A line typed at the console, as its words: `ask <placeholder> [method] [args]`, `lobe <lobe> [method] [args]`, `accept <placeholder> <invitation> [note]`, `forget <placeholder>` or `relations`, args and a note one word, the data\'s one text, and no method a describe. An accept\'s note, null where none is typed, is kept by the brain beside the standing and never sent to the inviter. `forget` ends the relation through the mouth, whose brain sends the far side `#leave` and forgets it whatever answers, and answers null; an anchor\'s it forgets only once the far brain answered its owner\'s `drop`, and one the mouth does not end it keeps, answering the mouth\'s error. `ask brain create <args>` reads, before the lobe stands, the faculty `args.faculty` names as the library keeps it, and answers beside what the brain answered `shown {name, version, placeholders, skins, world}`: its placeholders, each with what it expects, the organs 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 a faculty it cannot read is shown not and the brain is asked as ever. It answers what was heard.",\n kind: "writing",\n askers: ["console"],\n args: {\n type: "object",\n properties: {\n words: { type: "array", items: { type: "string" }, minItems: 1, maxItems: 4 }\n },\n required: ["words"],\n additionalProperties: false\n },\n errors: ["refused", "unknown"]\n }\n },\n placeholders: {\n console: "nervur.console",\n brain: "nervur.brain",\n mouth: "nervur.mouth"\n }\n };\n static #fields(data) {\n return typeof data === "object" && data !== null && !Array.isArray(data) && !(data instanceof Uint8Array);\n }\n static #words(args) {\n const words = _Terminal.#fields(args) ? args["words"] : void 0;\n if (!Array.isArray(words) || words.length === 0) return null;\n const texts = words.filter((word) => typeof word === "string");\n return texts.length === words.length ? texts : null;\n }\n async line(args) {\n if (this.stamp.asker !== _Terminal.#organ) return this.error("refused", "only the console types a line");\n const words = _Terminal.#words(args);\n if (words === null) return this.error("refused", "a line is one word or more");\n const [verb, first, second, third] = words;\n const over = first !== void 0 && words.length <= 4;\n const method = second ?? null;\n if (verb === "ask" && first === "brain" && method === "create" && words.length <= 4) return this.#create(third);\n if (verb === "ask" && over) return this.#heard(await this.#word(first, method, third));\n if (verb === "lobe" && over) return this.#heard(await this.#lobe(first, method, third));\n if (verb === "accept" && over && second !== void 0 && words.length >= 3)\n return this.#accept(first, second, third);\n if (verb === "forget" && first !== void 0 && words.length === 2) return this.#forget(first);\n if (verb === "relations" && words.length === 1) return this.#relations();\n return this.error("unknown", `the console knows no line ${words.join(" ")}`);\n }\n #args(text) {\n return text === void 0 ? { data: {} } : this.codec.read(text);\n }\n async #word(placeholder, method, text) {\n const args = this.#args(text);\n if ("why" in args) return { error: { code: "refused", message: args.why } };\n return this.ask(placeholder, method, args.data);\n }\n async #create(text) {\n const args = this.#args(text);\n if ("why" in args) return this.error("refused", args.why);\n const faculty = _Terminal.#fields(args.data) ? args.data["faculty"] : void 0;\n const shown = typeof faculty === "string" ? await this.#shown(faculty) : null;\n const made = await this.ask("brain", "create", args.data);\n if ("error" in made || shown === null || !_Terminal.#fields(made.result)) return this.#heard(made);\n return { ...made.result, shown };\n }\n async #shown(digest) {\n const asked = { lobe: "library", method: "get", args: { digest }, timeout: _Terminal.#asLongAsItMay };\n const kept = await this.ask("brain", "ask", asked);\n const blueprint = "result" in kept && _Terminal.#fields(kept.result) ? kept.result["blueprint"] : void 0;\n if (!_Terminal.#fields(blueprint)) return null;\n const placeholders = _Terminal.#fields(blueprint["placeholders"]) ? blueprint["placeholders"] : {};\n const expected = Object.entries(placeholders).filter((one) => typeof one[1] === "string");\n const organs = expected.length === 0 ? new Map() : await this.#organs();\n const skins = expected.flatMap(([placeholder, name]) => organs.get(placeholder) === name ? [placeholder] : []);\n return {\n name: blueprint["name"] ?? null,\n version: blueprint["version"] ?? null,\n placeholders: { ...placeholders },\n skins,\n world: skins.includes(_Terminal.#world)\n };\n }\n async #organs() {\n const organs = new Map();\n const most = Math.floor(this.memory / LOBE_SHARE / ITEM_SIZE);\n let cursor = null;\n for (let read = 0; read < most; ) {\n const page = await this.ask("brain", "state", cursor === null ? {} : { cursor });\n if ("error" in page || !_Terminal.#fields(page.result)) break;\n const nodes = Array.isArray(page.result["nodes"]) ? page.result["nodes"] : [];\n for (const node of nodes) {\n if (!_Terminal.#fields(node) || node["kind"] !== "organ") continue;\n const { id, blueprint } = node;\n if (typeof id === "string" && typeof blueprint === "string") organs.set(id, blueprint);\n }\n read += Math.max(1, nodes.length);\n cursor = typeof page.result["cursor"] === "string" ? page.result["cursor"] : null;\n if (cursor === null) break;\n }\n return organs;\n }\n async #lobe(lobe, method, text) {\n const args = this.#args(text);\n if ("why" in args) return { error: { code: "refused", message: args.why } };\n const asked = { lobe, method, args: args.data, timeout: _Terminal.#asLongAsItMay };\n return this.ask("brain", "ask", asked);\n }\n async #accept(placeholder, invitation, text) {\n if (_Terminal.#own.includes(placeholder)) return this.error("refused", `the console holds ${placeholder} already`);\n const note = text === void 0 ? { data: null } : this.codec.read(text);\n if ("why" in note) return this.error("refused", `the note is no data: ${note.why}`);\n const standings = await this.#standings();\n if ("failed" in standings) return standings.failed;\n if (standings.held.some((one) => one.placeholder === placeholder))\n return this.error("refused", `the console holds ${placeholder} already`);\n const asked = { invitation, placeholder, note: note.data };\n const accepted = await this.ask("mouth", "accept", asked);\n if ("error" in accepted) return this.#heard(accepted);\n const knocked = await this.ask(placeholder, null, {});\n const far = _Terminal.#fields(accepted.result) ? accepted.result["far"] : void 0;\n if ("error" in knocked) {\n if (typeof far === "string") await this.ask("mouth", "drop", { 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 console 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 console holds no ${placeholder}: ${knocked.error.message}`\n );\n }\n return accepted.result;\n }\n async #forget(placeholder) {\n const standings = await this.#standings();\n if ("failed" in standings) return standings.failed;\n const far = standings.held.find((one) => one.placeholder === placeholder)?.far;\n if (far === void 0) return this.error("refused", `the console holds no ${placeholder}`);\n const dropped = await this.ask("mouth", "drop", { far });\n return "error" in dropped ? this.#heard(dropped) : null;\n }\n async #standings() {\n const found = [];\n let cursor = null;\n const most = Math.floor(this.memory / LOBE_SHARE / ITEM_SIZE);\n while (found.length < most) {\n const page = await this.ask("nerves", "relations", cursor === null ? {} : { cursor });\n if ("error" in page) return { failed: this.error(page.error.code, page.error.message) };\n const read = _Terminal.#fields(page.result) ? page.result : {};\n const relations = Array.isArray(read["relations"]) ? read["relations"] : [];\n for (const one of relations) {\n if (!_Terminal.#fields(one) || one["side"] !== "standing") continue;\n const { placeholder, far } = one;\n if (typeof placeholder === "string" && typeof far === "string" && found.length < most)\n found.push({ placeholder, far, status: one["status"] ?? null, note: one["note"] ?? null });\n }\n cursor = typeof read["cursor"] === "string" ? read["cursor"] : null;\n if (cursor === null) break;\n }\n return { held: found };\n }\n async #relations() {\n const standings = await this.#standings();\n return "failed" in standings ? standings.failed : standings.held.map((one) => ({ ...one }));\n }\n #heard(answer) {\n return "result" in answer ? answer.result : this.error(answer.error.code, answer.error.message);\n }\n};\nexport {\n Terminal as default\n};\n';
1
+ var TERMINAL_SOURCE = 'var LOBE_SHARE = 4;\nvar ITEM_SIZE = 1024;\nvar AS_LONG_AS_IT_MAY = 9007199254740991;\n\nimport { Faculty } from "nervur:faculty";\nvar Terminal = class _Terminal extends Faculty {\n static #organ = "console";\n static #asLongAsItMay = AS_LONG_AS_IT_MAY;\n static #own = ["brain", "mouth", "console"];\n static #world = "network";\n static blueprint = {\n name: "nervur.terminal",\n version: "0.32.4",\n description: "The console\'s present lobe: the owner\'s terminal, turning each line typed into asks, and holding the relations to the organisms its owners own from afar.",\n methods: {\n line: {\n description: "A line typed at the console, as its words: `ask <placeholder> [method] [args]`, `lobe <lobe> [method] [args]`, `accept <placeholder> <invitation> [note]`, `forget <placeholder>` or `relations`, args and a note one word, the data\'s one text, and no method a describe. An accept\'s note, null where none is typed, is kept by the brain beside the standing and never sent to the inviter. `forget` ends the relation through the mouth, whose brain sends the far side `#leave` and forgets it whatever answers, and answers null; an anchor\'s it forgets only once the far brain answered its owner\'s `drop`, and one the mouth does not end it keeps, answering the mouth\'s error. `ask brain create <args>` reads, before the lobe stands, the faculty `args.faculty` names as the library keeps it, and answers beside what the brain answered `shown {name, version, placeholders, skins, world}`: its placeholders, each with what it expects, the organs 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 a faculty it cannot read is shown not and the brain is asked as ever. It answers what was heard.",\n kind: "writing",\n askers: ["console"],\n args: {\n type: "object",\n properties: {\n words: { type: "array", items: { type: "string" }, minItems: 1, maxItems: 4 }\n },\n required: ["words"],\n additionalProperties: false\n },\n errors: ["refused", "unknown"]\n }\n },\n placeholders: {\n console: "nervur.console",\n brain: "nervur.brain",\n mouth: "nervur.mouth"\n }\n };\n static #fields(data) {\n return typeof data === "object" && data !== null && !Array.isArray(data) && !(data instanceof Uint8Array);\n }\n static #words(args) {\n const words = _Terminal.#fields(args) ? args["words"] : void 0;\n if (!Array.isArray(words) || words.length === 0) return null;\n const texts = words.filter((word) => typeof word === "string");\n return texts.length === words.length ? texts : null;\n }\n async line(args) {\n if (this.stamp.asker !== _Terminal.#organ) return this.error("refused", "only the console types a line");\n const words = _Terminal.#words(args);\n if (words === null) return this.error("refused", "a line is one word or more");\n const [verb, first, second, third] = words;\n const over = first !== void 0 && words.length <= 4;\n const method = second ?? null;\n if (verb === "ask" && first === "brain" && method === "create" && words.length <= 4) return this.#create(third);\n if (verb === "ask" && over) return this.#heard(await this.#word(first, method, third));\n if (verb === "lobe" && over) return this.#heard(await this.#lobe(first, method, third));\n if (verb === "accept" && over && second !== void 0 && words.length >= 3)\n return this.#accept(first, second, third);\n if (verb === "forget" && first !== void 0 && words.length === 2) return this.#forget(first);\n if (verb === "relations" && words.length === 1) return this.#relations();\n return this.error("unknown", `the console knows no line ${words.join(" ")}`);\n }\n #args(text) {\n return text === void 0 ? { data: {} } : this.codec.read(text);\n }\n async #word(placeholder, method, text) {\n const args = this.#args(text);\n if ("why" in args) return { error: { code: "refused", message: args.why } };\n return this.ask(placeholder, method, args.data);\n }\n async #create(text) {\n const args = this.#args(text);\n if ("why" in args) return this.error("refused", args.why);\n const faculty = _Terminal.#fields(args.data) ? args.data["faculty"] : void 0;\n const shown = typeof faculty === "string" ? await this.#shown(faculty) : null;\n const made = await this.ask("brain", "create", args.data);\n if ("error" in made || shown === null || !_Terminal.#fields(made.result)) return this.#heard(made);\n return { ...made.result, shown };\n }\n async #shown(digest) {\n const asked = { lobe: "library", method: "get", args: { digest }, timeout: _Terminal.#asLongAsItMay };\n const kept = await this.ask("brain", "ask", asked);\n const blueprint = "result" in kept && _Terminal.#fields(kept.result) ? kept.result["blueprint"] : void 0;\n if (!_Terminal.#fields(blueprint)) return null;\n const placeholders = _Terminal.#fields(blueprint["placeholders"]) ? blueprint["placeholders"] : {};\n const expected = Object.entries(placeholders).filter((one) => typeof one[1] === "string");\n const organs = expected.length === 0 ? new Map() : await this.#organs();\n const skins = expected.flatMap(([placeholder, name]) => organs.get(placeholder) === name ? [placeholder] : []);\n return {\n name: blueprint["name"] ?? null,\n version: blueprint["version"] ?? null,\n placeholders: { ...placeholders },\n skins,\n world: skins.includes(_Terminal.#world)\n };\n }\n async #organs() {\n const organs = new Map();\n const most = Math.floor(this.memory / LOBE_SHARE / ITEM_SIZE);\n let cursor = null;\n for (let read = 0; read < most; ) {\n const page = await this.ask("brain", "state", cursor === null ? {} : { cursor });\n if ("error" in page || !_Terminal.#fields(page.result)) break;\n const nodes = Array.isArray(page.result["nodes"]) ? page.result["nodes"] : [];\n for (const node of nodes) {\n if (!_Terminal.#fields(node) || node["kind"] !== "organ") continue;\n const { id, blueprint } = node;\n if (typeof id === "string" && typeof blueprint === "string") organs.set(id, blueprint);\n }\n read += Math.max(1, nodes.length);\n cursor = typeof page.result["cursor"] === "string" ? page.result["cursor"] : null;\n if (cursor === null) break;\n }\n return organs;\n }\n async #lobe(lobe, method, text) {\n const args = this.#args(text);\n if ("why" in args) return { error: { code: "refused", message: args.why } };\n const asked = { lobe, method, args: args.data, timeout: _Terminal.#asLongAsItMay };\n return this.ask("brain", "ask", asked);\n }\n async #accept(placeholder, invitation, text) {\n if (_Terminal.#own.includes(placeholder)) return this.error("refused", `the console holds ${placeholder} already`);\n const note = text === void 0 ? { data: null } : this.codec.read(text);\n if ("why" in note) return this.error("refused", `the note is no data: ${note.why}`);\n const standings = await this.#standings();\n if ("failed" in standings) return standings.failed;\n if (standings.held.some((one) => one.placeholder === placeholder))\n return this.error("refused", `the console holds ${placeholder} already`);\n const asked = { invitation, placeholder, note: note.data };\n const accepted = await this.ask("mouth", "accept", asked);\n if ("error" in accepted) return this.#heard(accepted);\n const knocked = await this.ask(placeholder, null, {});\n const far = _Terminal.#fields(accepted.result) ? accepted.result["far"] : void 0;\n if ("error" in knocked) {\n if (typeof far === "string") await this.ask("mouth", "drop", { 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 console 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 console holds no ${placeholder}: ${knocked.error.message}`\n );\n }\n return accepted.result;\n }\n async #forget(placeholder) {\n const standings = await this.#standings();\n if ("failed" in standings) return standings.failed;\n const far = standings.held.find((one) => one.placeholder === placeholder)?.far;\n if (far === void 0) return this.error("refused", `the console holds no ${placeholder}`);\n const dropped = await this.ask("mouth", "drop", { far });\n return "error" in dropped ? this.#heard(dropped) : null;\n }\n async #standings() {\n const found = [];\n let cursor = null;\n const most = Math.floor(this.memory / LOBE_SHARE / ITEM_SIZE);\n while (found.length < most) {\n const page = await this.ask("nerves", "relations", cursor === null ? {} : { cursor });\n if ("error" in page) return { failed: this.error(page.error.code, page.error.message) };\n const read = _Terminal.#fields(page.result) ? page.result : {};\n const relations = Array.isArray(read["relations"]) ? read["relations"] : [];\n for (const one of relations) {\n if (!_Terminal.#fields(one) || one["side"] !== "standing") continue;\n const { placeholder, far } = one;\n if (typeof placeholder === "string" && typeof far === "string" && found.length < most)\n found.push({ placeholder, far, status: one["status"] ?? null, note: one["note"] ?? null });\n }\n cursor = typeof read["cursor"] === "string" ? read["cursor"] : null;\n if (cursor === null) break;\n }\n return { held: found };\n }\n async #relations() {\n const standings = await this.#standings();\n return "failed" in standings ? standings.failed : standings.held.map((one) => ({ ...one }));\n }\n #heard(answer) {\n return "result" in answer ? answer.result : this.error(answer.error.code, answer.error.message);\n }\n};\nexport {\n Terminal as default\n};\n';
2
2
 
3
3
  var TERMINAL = { faculty: TERMINAL_SOURCE, label: "console", wiring: { mouth: "mouth" } };
4
4
 
@@ -7,7 +7,7 @@ var FLOOR_FILES = [
7
7
  "design.json",
8
8
  `{
9
9
  "name": "floor",
10
- "version": "0.37.10",
10
+ "version": "0.37.11",
11
11
  "publisher": "nervur",
12
12
  "description": "The genome's one design: plain, clean and accessible, host-agnostic, given away with the packages. Its look is the describe look.",
13
13
  "languages": [
@@ -140,7 +140,7 @@ var FLOOR_FILES = [
140
140
 
141
141
  var FLOOR_LOOK_SOURCE = `import { Faculty } from 'nervur:faculty';
142
142
  export default class FloorLook extends Faculty {
143
- static #identity = {"design":"floor","name":"nervur.floor-look","version":"0.37.10","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"]};
143
+ 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"]};
144
144
  static #components = (() => {
145
145
  const $m = {};
146
146
  $m["_tree.ts"] = (() => {
@@ -605,8 +605,8 @@ return { "lobe": $m["lobe.ts"].default, "organism": $m["organism.ts"].default, "
605
605
 
606
606
  static blueprint = {
607
607
  name: "nervur.floor-look",
608
- version: "0.37.10",
609
- assets: "2975681b6c7270d11b1f8a1431f5c38cb7f1a5ed717d197e21a4f6b3f840c3b2",
608
+ version: "0.37.11",
609
+ assets: "e9ff5479b6724f7b5803989330fae021c32047dbeb0c262ee86a258ee2331952",
610
610
  ...FloorLook.#rest(),
611
611
  };
612
612
 
@@ -1227,7 +1227,7 @@ var FLOOR_DESIGN = {
1227
1227
  assets: FLOOR_FILES
1228
1228
  };
1229
1229
 
1230
- var WINDOW_SOURCE = 'var BYTES = "$bytes";\n\nvar ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";\nvar NONE = 64;\nvar VALUES = new Uint8Array(256).fill(NONE);\nfor (let at = 0; at < ALPHABET.length; at += 1) VALUES[ALPHABET.charCodeAt(at)] = at;\n\nvar utf8Bytes = (text) => {\n if (!text.isWellFormed()) throw new TypeError("a text with a lone surrogate has no UTF-8 bytes");\n const ascii = new Uint8Array(text.length);\n let start = 0;\n for (; start < text.length; start++) {\n const unit = text.charCodeAt(start);\n if (unit >= 128) break;\n ascii[start] = unit;\n }\n if (start === text.length) return ascii;\n const out = new Uint8Array(text.length * 3);\n out.set(ascii.subarray(0, start));\n let length = start;\n for (let at = start; at < text.length; at++) {\n const unit = text.charCodeAt(at);\n if (unit < 128) {\n out[length++] = unit;\n continue;\n }\n const code2 = text.codePointAt(at) ?? 0;\n if (code2 < 2048) {\n out[length++] = 192 | code2 >> 6;\n out[length++] = 128 | code2 & 63;\n } else if (code2 < 65536) {\n out[length++] = 224 | code2 >> 12;\n out[length++] = 128 | code2 >> 6 & 63;\n out[length++] = 128 | code2 & 63;\n } else {\n out[length++] = 240 | code2 >> 18;\n out[length++] = 128 | code2 >> 12 & 63;\n out[length++] = 128 | code2 >> 6 & 63;\n out[length++] = 128 | code2 & 63;\n at++;\n }\n }\n return out.slice(0, length);\n};\n\nvar DIGITS = "0123456789abcdef";\nvar PAIRS = Array.from(\n { length: 256 },\n (_, byte) => `${DIGITS[byte >> 4] ?? ""}${DIGITS[byte & 15] ?? ""}`\n);\nvar HIGH = Array.from({ length: 256 }, (_, byte) => DIGITS.charCodeAt(byte >> 4));\nvar LOW = Array.from({ length: 256 }, (_, byte) => DIGITS.charCodeAt(byte & 15));\nvar VALUES2 = Int8Array.from({ length: 256 }, (_, unit) => DIGITS.indexOf(String.fromCharCode(unit)));\n\nvar OPEN = utf8Bytes(`{"${BYTES}":"`);\nvar CLOSE = utf8Bytes(\'"}\');\n\nvar GENOME_CODES = [\n "timeout",\n "unavailable",\n "busy",\n "fault",\n "silent",\n "removed",\n "repeated"\n];\nvar GENOME = new Set(GENOME_CODES);\n\nvar PATTERN_STATES = 1e4;\nvar NAMES = "L Ll Lm Lo Lt Lu M Mc Me Mn N Nd Nl No P Pc Pd Pe Pf Pi Po Ps Z Zl Zp Zs S Sc Sk Sm So";\nvar CATEGORIES = new Set(`${NAMES} C Cc Cf Cn Co`.split(" "));\nvar ESCAPED = new Set("()*+-.?[\\\\]^{|}");\nvar code = (char) => char.codePointAt(0) ?? -1;\nvar [BACKSLASH, DASH, CARET, DOLLAR, BAR, COMMA] = ["\\\\", "-", "^", "$", "|", ","].map(code);\nvar [OPEN2, CLOSE2, SQUARE_OPEN, SQUARE_CLOSE] = ["(", ")", "[", "]"].map(code);\nvar [BRACE_OPEN, BRACE_CLOSE, DOT_CHAR] = ["{", "}", "."].map(code);\nvar single = (point) => ({\n ranges: [{ low: point, high: point }],\n categories: [],\n negated: false\n});\nvar DOT = {\n ranges: [...single(10).ranges, ...single(13).ranges],\n categories: [],\n negated: true\n};\n\nvar OF_CATEGORY = new Map(\n [...CATEGORIES].map((name) => [name, new RegExp(`^\\\\p{${name}}$`, "u")])\n);\n\nvar REFUSED = { why: `it compiles past ${PATTERN_STATES} states` };\n\nvar DIGEST = { type: "string", pattern: "^[0-9a-f]{64}$" };\nvar ROADS = ["genome", "installer", "owners", "other"];\nvar MOVED_LOBE = {\n type: "object",\n properties: {\n faculty: DIGEST,\n cells: DIGEST,\n wires: { type: "object", additionalProperties: { type: "string", minLength: 1 } },\n road: { enum: [...ROADS] }\n },\n required: ["faculty", "cells", "wires", "road"],\n additionalProperties: false\n};\n\nvar INPUTS = new Set(\n "text search number range checkbox radio date time email tel color file".split(" ")\n);\nvar NUMBER = "number";\nvar FLAG = "flag";\nvar pairs = (names, form) => names.split(" ").map((name) => [name, form]);\nvar CAPS = { one: ["butt", "round", "square"] };\nvar JOINS = { one: ["miter", "round", "bevel"] };\nvar ANCHORS = { one: ["start", "middle", "end"] };\nvar BASELINES = {\n one: ["auto", "middle", "hanging", "central", "text-before-edge", "text-after-edge"]\n};\nvar UNITS = { one: ["userSpaceOnUse", "objectBoundingBox"] };\nvar PAINT = new Map([\n ["transform", "transform"],\n ["fill", "paint"],\n ["stroke", "paint"],\n ["stroke-width", NUMBER],\n ["stroke-linecap", CAPS],\n ["stroke-linejoin", JOINS],\n ["stroke-dasharray", "numbers"],\n ["opacity", NUMBER],\n ["fill-opacity", NUMBER],\n ["stroke-opacity", NUMBER],\n ["clip-path", "ref"]\n]);\nvar TEXT_LOOK = new Map([\n ["text-anchor", ANCHORS],\n ["dominant-baseline", BASELINES],\n ["font-size", NUMBER]\n]);\nvar drawn = (own, ...more) => new Map([...own, ...more.flatMap((one) => [...one])]);\nvar SVG = new Set(\n "svg g path circle ellipse rect line polyline polygon text tspan title desc defs clipPath linearGradient radialGradient stop".split(\n " "\n )\n);\nfunction svgElements() {\n const shape = (names, form = NUMBER) => new Map(pairs(names, form));\n return [\n [\n "svg",\n drawn(\n shape("width height"),\n new Map([\n ["viewBox", "viewbox"],\n ["preserveAspectRatio", "aspect"]\n ]),\n PAINT\n )\n ],\n ["g", drawn(PAINT, TEXT_LOOK)],\n ["path", drawn(shape("d", "pathdata"), PAINT)],\n ["circle", drawn(shape("cx cy r"), PAINT)],\n ["ellipse", drawn(shape("cx cy rx ry"), PAINT)],\n ["rect", drawn(shape("x y width height rx ry"), PAINT)],\n ["line", drawn(shape("x1 y1 x2 y2"), PAINT)],\n ["polyline", drawn(shape("points", "numbers"), PAINT)],\n ["polygon", drawn(shape("points", "numbers"), PAINT)],\n ["text", drawn(shape("x y"), PAINT, TEXT_LOOK)],\n ["tspan", drawn(shape("x y"), PAINT, TEXT_LOOK)],\n ["title", new Map()],\n ["desc", new Map()],\n ["defs", new Map()],\n ["clipPath", new Map()],\n ["linearGradient", drawn(shape("x1 y1 x2 y2"), shape("gradientUnits", UNITS))],\n ["radialGradient", drawn(shape("cx cy r"), shape("gradientUnits", UNITS))],\n ["stop", drawn(shape("offset"), shape("stop-color", "color"))]\n ];\n}\nvar GLOBAL = new Map([\n ["class", "classes"],\n ["id", "name"],\n ["title", "text"],\n ["lang", "name"],\n ["dir", { one: ["ltr", "rtl", "auto"] }],\n ["hidden", FLAG],\n ["role", "name"],\n ["aria-label", "text"],\n ["aria-hidden", { one: ["true", "false"] }],\n ["aria-current", { one: ["page", "step", "true", "false"] }],\n ["aria-live", { one: ["off", "polite"] }],\n ["aria-pressed", { one: ["true", "false", "mixed"] }],\n ["aria-expanded", { one: ["true", "false"] }],\n ["aria-invalid", { one: ["true", "false"] }],\n ["aria-describedby", "name"],\n ["aria-busy", { one: ["true", "false"] }],\n ...pairs("swipe-left swipe-right swipe-up swipe-down hold drag", "name"),\n ["drop", "text"],\n ["morph", "name"],\n ["opens", FLAG]\n]);\nvar TYPING = [\n ["autocorrect", { one: ["on", "off"] }],\n ["autocapitalize", { one: ["off", "none", "on", "sentences", "words", "characters"] }],\n ["spellcheck", { one: ["true", "false"] }],\n ["inputmode", { one: ["none", "text", "decimal", "numeric", "tel", "search", "email", "url"] }],\n ["enterkeyhint", { one: ["enter", "done", "go", "next", "previous", "search", "send"] }]\n];\nvar PLAIN = "div span p h1 h2 h3 h4 header footer main nav aside section article ul dl dt dd strong em small mark s sub sup abbr q blockquote br hr figure figcaption legend table caption thead tbody tfoot tr summary";\nvar ELEMENTS = new Map([\n ...PLAIN.split(" ").map((name) => [name, new Map()]),\n ["ol", new Map(pairs("start", NUMBER))],\n ["li", new Map(pairs("value", NUMBER))],\n ["img", new Map([["src", "asset"], ["alt", "text"], ...pairs("width height", NUMBER)])],\n ["audio", new Map([["src", "sound"], ...pairs("controls", FLAG)])],\n [\n "time",\n new Map([...pairs("datetime", "text"), ["deadline", "instant"], ["shows", { one: ["day", "time"] }]])\n ],\n ["data", new Map([...pairs("value ref", "text"), ...pairs("field", "name")])],\n ["a", new Map(pairs("href", "link"))],\n ["pre", new Map()],\n ["code", new Map()],\n ["meter", new Map(pairs("value min max low high", NUMBER))],\n ["progress", new Map(pairs("value max", NUMBER))],\n ["button", new Map([...pairs("disabled", FLAG), ["copies", "name"]])],\n ["label", new Map(pairs("for", "name"))],\n [\n "input",\n new Map([\n ["type", "input"],\n ...pairs("name autocomplete", "name"),\n ...pairs("value placeholder", "text"),\n ...pairs("min max step maxlength minlength", NUMBER),\n ...pairs("checked disabled required readonly", FLAG),\n ...TYPING,\n ["enter", "name"]\n ])\n ],\n [\n "textarea",\n new Map([\n ...pairs("name autocomplete", "name"),\n ...pairs("placeholder", "text"),\n ...pairs("rows maxlength minlength", NUMBER),\n ...pairs("disabled required readonly", FLAG),\n ...TYPING\n ])\n ],\n ["select", new Map([...pairs("name", "name"), ...pairs("disabled", FLAG)])],\n ["option", new Map([...pairs("value", "text"), ...pairs("selected", FLAG)])],\n ["fieldset", new Map(pairs("disabled", FLAG))],\n ["th", new Map([["scope", { one: ["row", "col"] }], ...pairs("colspan", NUMBER)])],\n ["td", new Map(pairs("colspan", NUMBER))],\n ["details", new Map(pairs("open", FLAG))],\n ["slot", new Map(pairs("placeholder", "name"))],\n ...svgElements()\n]);\n\nvar set = (names) => new Set(names.split(" "));\nvar PARENTS = new Map([\n ["li", set("ul ol")],\n ["dt", set("dl")],\n ["dd", set("dl")],\n ["option", set("select")],\n ["summary", set("details")],\n ["caption", set("table")],\n ["thead", set("table")],\n ["tbody", set("table")],\n ["tfoot", set("table")],\n ["tr", set("thead tbody tfoot")],\n ["th", set("tr")],\n ["td", set("tr")]\n]);\nvar HOLDS = new Map([\n ["table", set("caption thead tbody tfoot")],\n ["thead", set("tr")],\n ["tbody", set("tr")],\n ["tfoot", set("tr")],\n ["tr", set("th td")],\n ["select", set("option")],\n ["option", new Set()]\n]);\nvar TEXTS = set("option");\nvar EMPTY = set("textarea slot audio");\nvar BLOCK = "div p h1 h2 h3 h4 header footer main nav aside section article ul ol dl dt dd li blockquote pre figure figcaption table hr details summary fieldset";\nvar HEADINGS = "h1 h2 h3 h4";\nvar HEADING = set(HEADINGS);\nvar NOT_WITHIN = new Map([\n ...BLOCK.split(" ").map((name) => [\n name,\n set(HEADING.has(name) ? `p ${HEADINGS}` : "p")\n ]),\n ["a", set("a")],\n ["button", set("button")]\n]);\nvar ENCLOSING = set(`p a button ${HEADINGS}`);\n\nvar NUM = String.raw`-?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(?:[eE][-+]?\\d+)?`;\nvar NUMBERS = new RegExp(`^${NUM}(?:[ ,]+${NUM})*$`, "u");\nvar VIEWBOX = new RegExp(`^${NUM}(?:[ ,]+${NUM}){3}$`, "u");\nvar TRANSFORM = new RegExp(\n `^(?:(?:translate|scale|rotate|skewX|skewY|matrix)\\\\( ?${NUM}(?:[ ,]+${NUM})* ?\\\\) ?)+$`,\n "u"\n);\nvar COLOR = new RegExp(\n `^(?:currentColor|transparent|[a-z]{3,20}|#(?:[0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})|(?:rgb|rgba|hsl|hsla)\\\\( ?${NUM}%?(?:[ ,]+${NUM}%?){2,3} ?\\\\))$`,\n "u"\n);\n\nvar GESTURES = new Map([\n ...["swipe-left", "swipe-right", "swipe-up", "swipe-down", "hold"].map((name) => [\n name,\n new Set(["button", "summary"])\n ]),\n ["drag", new Set(["select"])]\n]);\n\nvar 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.13",\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’s: 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’s parts with the lobe’s 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’s 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 page = await this.#organismPage(\n over,\n text,\n held.relations,\n asked.cursor,\n title,\n over === null ? await this.#facultiesKept() : void 0\n );\n const args = { component: "organism", args: page.args, theme: asked.theme, lang: this.#lang };\n return {\n title,\n version: null,\n warnings: 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 set2 = 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 set2 ? set2 : { 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 drawn2 = 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 drawn2) return this.error("unavailable", `the design lobe draws no surround: ${drawn2.error.message}`);\n return { route, text, tree: drawn2.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 set2 of text.matchAll(/image-set\\(([^)]*)\\)/gu))\n for (const one of (set2[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’s 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’s 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, …}}" };\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’s 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 drawn2 = await this.#through(over, lobe, "draw", _Window.#at(args, "args") ?? null);\n if ("error" in drawn2) return this.error(drawn2.error.code, drawn2.error.message);\n if (this.#farLobe(over)) return { tree: drawn2.result, wires: {} };\n const wires = await this.#wiresOf(over, lobe);\n if ("why" in wires) return this.error("refused", wires.why);\n return { tree: drawn2.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 return { nodes };\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 set2 = this.#localSet({ over: relation, lobe: relation }, _Window.#consent, { asking: "leave" });\n return "error" in set2 ? set2 : { 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’s 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 drawn2 = _Window.#listedBy(blueprint);\n if (_Window.#components.every((one) => drawn2.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 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 }\n return faculties;\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) 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 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';
1230
+ 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’s: 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’s parts with the lobe’s 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’s 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’s 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’s 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, …}}" };\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’s 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’s 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';
1231
1231
 
1232
1232
  var WINDOW = {
1233
1233
  faculty: WINDOW_SOURCE,
@@ -1236,11 +1236,11 @@ var WINDOW = {
1236
1236
  given: { design: FLOOR_DESIGN }
1237
1237
  };
1238
1238
 
1239
- var REPOS_SOURCE = 'import { Faculty } from "nervur:faculty";\n\nvar BOX = 1048576;\nvar LETTER_LIVES = 864e5;\nvar LOBE_SHARE = 4;\nvar ITEM_SIZE = 1024;\nvar CELLS_RANGE = 1e3;\nvar LOGS = 20;\nvar ARG_LONGEST = 4096;\nvar ARGS_MOST = 64;\nvar SCOPE_MOST = 16;\n\nvar ReposSkin = class _ReposSkin extends Faculty {\n static #owner = "brain";\n static #lost = "the shell runs it no more: it was lost, as to a restart of the organ";\n static #box = BOX;\n static #lives = LETTER_LIVES;\n static #logs = LOGS;\n static #repos = "repos";\n static #transfers = "transfers";\n static #marker = "nervur-marker";\n static #env = ".env";\n static #folderName = /^[a-z](?:[a-z0-9-]|\\.(?=[a-z0-9-])){0,63}$/;\n static #name = /^(?!\\.{1,2}$)(?!\\.git$)[^/\\\\\\0]+$/i;\n static #script = /^[A-Za-z0-9][A-Za-z0-9:._-]{0,63}$/;\n static #key = /^[A-Za-z_][A-Za-z0-9_]{0,63}$/;\n static #line = /^[^\\n\\r\\0]*$/;\n static #hash = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/;\n static #sha = /^[0-9a-f]{64}$/;\n static #kept = "kept";\n static #organ = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;\n static #as = /^(?:push|pull|(?:out|in)-[A-Za-z0-9-]{1,64})$/;\n static #tag = /^v(?:0|[1-9][0-9]*)\\.(?:0|[1-9][0-9]*)\\.(?:0|[1-9][0-9]*)$/;\n static #segment = /^[A-Za-z0-9._-]+$/;\n static #design = /^[a-z][a-z0-9]*(?:[.-][a-z0-9]+)*$/;\n static #marked = `IFS= read -r m; [ "$(cat nervur-marker)" = "$m" ] || { echo "the disk\'s folder is not $1" >&2; exit 1; }; rm nervur-marker`;\n static #exact(path, under, name) {\n return `{ [ -d "${path}" ] && [ ! -L "${path}" ] && ls -1A "${under}" | grep -qxF -- "${name}"; } || { echo "the folder ${name} stands not as named under repos" >&2; exit 1; }\n`;\n }\n static #ident = "export GIT_AUTHOR_NAME=Nervur GIT_AUTHOR_EMAIL=nervur@invalid GIT_COMMITTER_NAME=Nervur GIT_COMMITTER_EMAIL=nervur@invalid\\n";\n static #lend(dir) {\n return `if [ -n "\\${NERVUR_GENOME+x}" ]; then { [ -d "$NERVUR_GENOME" ] && [ -r "$NERVUR_GENOME" ] && [ -x "$NERVUR_GENOME" ]; } || { echo "NERVUR_GENOME $NERVUR_GENOME is no folder this account can read" >&2; exit 1; }; mkdir -p "${dir}/node_modules/@nervur.org" && ln -sfn "$NERVUR_GENOME" "${dir}/node_modules/@nervur.org/genome" || exit 1; fi\n`;\n }\n static #in = `${_ReposSkin.#exact("$1", "${1%/*}", "${1##*/}")}cd "$1" || exit 1\nexport GIT_CEILING_DIRECTORIES="\\${1%/*}"\n${_ReposSkin.#ident}`;\n static #keep = `k="$2"; c="$(printf \'\\\\t\')"\n[ -n "$k" ] || { echo "a scan names where it keeps" >&2; exit 1; }\nmkdir -p "$k/.t" "$k/.o" || exit 1\ngit tag --list \'v*\' | grep -E \'^v[0-9]+\\\\.[0-9]+\\\\.[0-9]+$\' | while IFS= read -r g; do [ -e "$k/.t/$g" ] && continue; git -c core.quotePath=false ls-tree -r "$g" -- designs faculties | while IFS="$c" read -r m p; do case "$p" in designs/*|faculties/*/assets/*) ;; *) continue ;; esac; o=\\${m##* }; [ "\\${m#* }" = "blob $o" ] || continue; [ -s "$k/.o/$o" ] && continue; git cat-file blob "$o" | perl -0777 -pe \'s/\\\\r\\\\n?/\\\\n/g unless /\\\\0/\' >"$k/.w" || exit 1; s=$({ sha256sum 2>/dev/null || shasum -a 256; } <"$k/.w" | cut -d " " -f 1); mv -f "$k/.w" "$k/$s" && echo "$s" >"$k/.o/$o" || exit 1; done || exit 1; : >"$k/.t/$g" || exit 1; done || exit 1\n`;\n static #untag = `git for-each-ref --format=\'delete %(refname)\' "$r-tags/" | git update-ref --stdin`;\n static #fetched = `${_ReposSkin.#in}trap \'rm -rf "$2"\' EXIT\nr="refs/nervur/$4"\ngit update-ref -d "$r" 2>/dev/null; git update-ref -d "$r-main" 2>/dev/null; ${_ReposSkin.#untag}\ncd "$2" || exit 1\ni=0; while [ "$i" -lt "$3" ]; do cat "q$i" || exit 1; i=$((i + 1)); done > b || exit 1\ncd "$1" || exit 1\ngit fetch --quiet --no-tags "$2/b" "+main:$r" || exit 1\n`;\n static #tagged = `git fetch --quiet --no-tags "$2/b" "+refs/tags/v*:$r-tags/v*" || exit 1\nw=$(git for-each-ref --format=\'%(objecttype) %(objectname) %(refname)\' "$r-tags/" | while read -r y o n; do n=\\${n#"$r-tags/"}; if [ "$y" != commit ] || ! git merge-base --is-ancestor "$o" "$r" 2>/dev/null; then echo "the tag $n names no commit it brings"; elif e=$(git rev-parse -q --verify "refs/tags/$n^{commit}") && [ "$e" != "$o" ]; then echo "this lobe holds the tag $n on another commit: a version names one commit for ever"; fi; done)\nif [ -n "$w" ]; then git update-ref -d "$r"; ${_ReposSkin.#untag}; echo "$w" >&2; exit 1; fi\n`;\n static #bring = `${_ReposSkin.#fetched}${_ReposSkin.#tagged}c=$(git rev-parse "$r") || exit 1\nif ! h=$(git rev-parse -q --verify HEAD); then m=new\nelif git merge-base --is-ancestor "$c" "$h"; then git update-ref -d "$r"; ${_ReposSkin.#untag}; echo "$h"; echo held; exit 0\nelif git merge-base --is-ancestor "$h" "$c"; then m=forward\nelse t=$(mktemp -d) || exit 1\ngit worktree add --quiet --detach "$t/w" "$h" >/dev/null 2>&1 || exit 1\nif git -C "$t/w" merge --quiet --no-edit "$c" >/dev/null 2>&1; then c=$(git -C "$t/w" rev-parse HEAD); m=merge; else m=; fi\ngit worktree remove --force "$t/w"; rm -rf "$t"\n[ -n "$m" ] || { git update-ref -d "$r"; ${_ReposSkin.#untag}; echo "it meets a conflict with main: merge it where it is authored, and send it again" >&2; exit 1; }\nfi\ngit update-ref "$r-main" "$c" && echo "$c" && echo "$m"`;\n static #cutting = [\n \'const { execFileSync } = require("node:child_process"); const fs = require("node:fs"); const os = require("node:os"); const path = require("node:path");\',\n \'const [as = "", ...scope] = process.argv.slice(1);\',\n \'const git = (args, input, env) => execFileSync("git", args, { input: input === undefined ? "" : input, env: env === undefined ? process.env : env, maxBuffer: 1073741824, stdio: ["pipe", "pipe", "pipe"] });\',\n \'const line = (args) => git(args).toString("utf8").trim();\',\n \'const maybe = (args) => { try { return line(args); } catch { return ""; } };\',\n "const holds = (args) => { try { git(args); return true; } catch { return false; } };",\n \'const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "nervur-cut-")); process.on("exit", () => fs.rmSync(tmp, { recursive: true, force: true }));\',\n \'const index = path.join(tmp, "index");\',\n \'const within = (p) => scope.some((s) => p.startsWith(s + "/"));\',\n \'const entries = (args) => git(["ls-tree", "-r", "-z", ...args]).toString("latin1").split("\\\\0").filter((e) => e !== "");\',\n \'const named = (e) => e.slice(e.indexOf("\\\\t") + 1);\',\n \'const treeOf = (all) => { fs.rmSync(index, { force: true }); const env = { ...process.env, GIT_INDEX_FILE: index }; if (all.length > 0) git(["update-index", "-z", "--index-info"], Buffer.from(all.map((e) => e + "\\\\0").join(""), "latin1"), env); return git(["write-tree"], "", env).toString("utf8").trim(); };\',\n \'const who = (header, role) => { const m = new RegExp("^" + role + " (.*) <([^>\\\\\\\\n]*)> ([0-9]+) ([-+][0-9]{4})$", "m").exec(header); if (m === null) throw new Error("its " + role + " is not as git writes it"); return m; };\',\n \'const kept = (c, tree, parent) => { const raw = git(["cat-file", "commit", c]); const at = raw.indexOf("\\\\n\\\\n"); const header = raw.subarray(0, at < 0 ? raw.length : at).toString("utf8"); const message = at < 0 ? Buffer.alloc(0) : raw.subarray(at + 2); const a = who(header, "author"); const k = who(header, "committer"); const env = { ...process.env, GIT_AUTHOR_NAME: a[1], GIT_AUTHOR_EMAIL: a[2], GIT_AUTHOR_DATE: "@" + a[3] + " " + a[4], GIT_COMMITTER_NAME: k[1], GIT_COMMITTER_EMAIL: k[2], GIT_COMMITTER_DATE: "@" + k[3] + " " + k[4] }; return git(["commit-tree", "--no-gpg-sign", tree, ...(parent === "" ? [] : ["-p", parent])], message, env).toString("utf8").trim(); };\',\n \'const walk = (commits, from) => { const seen = commits.length === 0 ? [] : git(["cat-file", "--batch-check=%(objecttype) %(objectname)"], commits.flatMap((c) => scope.map((s) => c + ":" + s)).join("\\\\n") + "\\\\n").toString("utf8").split("\\\\n"); let { head, last } = from; commits.forEach((c, i) => { const oids = scope.map((s, j) => { const [type = "", oid = ""] = (seen[i * scope.length + j] ?? "").split(" "); return type === "tree" ? oid : "-"; }); const key = oids.join(" "); if (key === last) return; last = key; const trees = scope.filter((s, j) => oids[j] !== "-"); head = kept(c, treeOf(trees.length === 0 ? [] : entries([c, "--", ...trees])), head); }); return { head, last }; };\',\n \'const main = maybe(["rev-parse", "-q", "--verify", "refs/heads/main^{commit}"]);\',\n \'const tag = process.env.NERVUR_CUT_TAG === undefined ? "" : process.env.NERVUR_CUT_TAG;\',\n \'const tagged = tag === "" ? "" : maybe(["rev-parse", "-q", "--verify", "refs/tags/" + tag + "^{commit}"]);\',\n \'if (tag !== "" && tagged === "") { process.stderr.write("this lobe holds no tag " + tag + "\\\\n"); process.exit(1); }\',\n \'const upto = tagged === "" ? null : new Set(line(["rev-list", tagged]).split("\\\\n"));\',\n \'const firsts = (main === "" ? [] : line(["rev-list", "--first-parent", "--reverse", main]).split("\\\\n").filter((c) => c !== "")).filter((c) => upto === null || upto.has(c));\',\n \'const cut = walk(firsts, { head: "", last: scope.map(() => "-").join(" ") });\'\n ].join("\\n");\n static #cut = `${_ReposSkin.#in}a=$2; t=$3; shift 3\nNERVUR_CUT_TAG="$t" node -e \'${_ReposSkin.#cutting}\nif (cut.head === "") maybe(["update-ref", "-d", "refs/nervur/cut-" + as]); else git(["update-ref", "refs/nervur/cut-" + as, cut.head]);\nprocess.stdout.write(cut.head + "\\\\n");\' -- "$a" "$@"`;\n static #graft = `${_ReposSkin.#fetched}a=$4; shift 4\nNERVUR_CUT_TAG= node -e \'${[\n _ReposSkin.#cutting,\n \'const r = "refs/nervur/" + as; const refused = (why) => { maybe(["update-ref", "-d", r]); process.stderr.write(why + "\\\\n"); process.exit(1); };\',\n \'const tip = line(["rev-parse", r]);\',\n \'if (cut.head !== "" && tip === cut.head) { maybe(["update-ref", "-d", r]); process.stdout.write(tip + "\\\\nheld\\\\n"); process.exit(0); }\',\n \'if (cut.head !== "" && !holds(["merge-base", "--is-ancestor", cut.head, tip])) refused("behind the scope\\\\u0027s head; pull first");\',\n \'const pushed = line(["rev-list", "--reverse", "--parents", cut.head === "" ? tip : cut.head + ".." + tip]).split("\\\\n").filter((l) => l !== "").map((l) => l.split(" "));\',\n "let before = cut.head;",\n \'for (const [c = "", ...parents] of pushed) { if (parents.length > 1 || (parents[0] ?? "") !== before) refused("a push into a scope is linear on its head, and " + c + " is not"); const changed = git(["diff-tree", "-r", "-z", "--name-only", "--no-commit-id", ...(before === "" ? ["--root", c] : [before, c])]).toString("latin1").split("\\\\0").filter((p) => p !== ""); const outside = changed.find((p) => !within(p)); if (outside !== undefined) refused(c + " changes " + outside + ", outside the scope"); if (changed.length === 0) refused(c + " changes nothing within the scope"); before = c; }\',\n \'const outside = main === "" ? [] : entries([main]).filter((e) => !within(named(e)));\',\n \'let grafted = main; const graft = pushed.map(([c = ""]) => { grafted = kept(c, treeOf([...outside, ...entries([c]).filter((e) => within(named(e)))]), grafted); return grafted; });\',\n \'if (walk(graft, cut).head !== tip) refused("the scope cut again answers not the commits pushed: one carries what a cut drops, as a signature");\',\n \'git(["update-ref", r + "-main", grafted]); process.stdout.write(grafted + "\\\\ngraft\\\\n" + tip + "\\\\n");\'\n ].join("\\n")}\' -- "$a" "$@"`;\n static #mask = \'const { spawn } = require("node:child_process"); const fs = require("node:fs"); const env = { ...process.env }; const values = []; let held = ""; try { held = fs.readFileSync(process.argv[1], "utf8"); } catch {} for (const line of held.split("\\\\n")) { const at = line.indexOf("="); if (at < 1 || !/^[A-Za-z_][A-Za-z0-9_]*$/.test(line.slice(0, at))) continue; env[line.slice(0, at)] = line.slice(at + 1); if (at + 1 < line.length) values.push(line.slice(at + 1)); } const shown = values.sort((a, b) => b.length - a.length || (a < b ? -1 : a > b ? 1 : 0)); const mask = (t) => shown.reduce((s, v) => s.split(v).join("[secret]"), t); const c = spawn(process.argv[2], process.argv.slice(3), { env, stdio: ["ignore", "pipe", "pipe"] }); const pass = (from, to) => { let kept = ""; from.setEncoding("utf8"); from.on("data", (d) => { kept += d; const i = kept.lastIndexOf("\\\\n") + 1; if (i > 0) { to.write(mask(kept.slice(0, i))); kept = kept.slice(i); } }); from.on("end", () => to.write(mask(kept))); }; pass(c.stdout, process.stdout); pass(c.stderr, process.stderr); for (const s of ["SIGTERM", "SIGINT", "SIGHUP"]) process.on(s, () => c.kill(s)); c.on("error", (e) => { process.stderr.write(e.message + "\\\\n"); process.exitCode = 127; }); c.on("close", (code) => { process.exitCode = code ?? 1; });\';\n static #masked = `node -e \'${_ReposSkin.#mask}\' -- "$1/${_ReposSkin.#env}"`;\n static #scripted = `node -e \'process.exit(require("./package.json").scripts?.[process.argv[1]] ? 0 : 3)\' "$2" 2>/dev/null || { echo "the repo holds no script $2" >&2; exit 3; }\n`;\n static #queued = `q="\\${1%/*}/.gates"; mkdir -p "$q" || exit 1\nlive() { find "$q" -type f -empty -mmin +1 -exec rm -f {} + 2>/dev/null; for gt in "$q"/*; do [ -e "$gt" ] || [ -L "$gt" ] || continue; [ -f "$gt" ] && [ ! -L "$gt" ] || { rm -f "$gt"; continue; }; [ -s "$gt" ] || continue; gp=$(sed -n 1p "$gt"); gs=$(sed -n 2p "$gt"); [ -n "$gp" ] && [ "$(ps -o lstart= -p "$gp" 2>/dev/null)" = "$gs" ] || rm -f "$gt"; done; }\nwhile :; do while :; do live; n=$(ls -1 "$q" | tail -1 | sed \'s/^0*//\'); me=$(printf \'%012d\' $(( \\${n:-0} + 1 ))); ( set -C; printf \'%s\\\\n%s\\\\n\' "$$" "$(ps -o lstart= -p $$)" > "$q/$me" ) 2>/dev/null && break; done; while [ -f "$q/$me" ]; do live; [ "$(ls -1 "$q" | head -1)" = "$me" ] && break 2; sleep 0.2; done; done\n`;\n static #unpack = \'const fs = require("node:fs"); let s = ""; process.stdin.setEncoding("utf8"); process.stdin.on("data", (d) => { s += d; }); process.stdin.on("end", () => { const given = JSON.parse(s); for (const [name, file] of [["parts", "parts.mjs"], ["message", "message"], ["conform", "chosen"]]) if (typeof given[name] === "string") fs.writeFileSync(process.argv[1] + "/" + file, given[name]); if (Array.isArray(given.executable)) fs.writeFileSync(process.argv[1] + "/executable", given.executable.map((path) => path + "\\\\0").join("")); if (Array.isArray(given.paths)) fs.writeFileSync(process.argv[1] + "/paths", given.paths.map((path) => path + "\\\\0").join("")); if (given.scoped === true) fs.writeFileSync(process.argv[1] + "/scoped", ""); if (!fs.existsSync(process.argv[1] + "/parts.mjs")) { process.stderr.write("no check of the parts was given\\\\n"); process.exit(1); } });\';\n static #handing = [\n \'const fs = require("node:fs"); const { execFileSync } = require("node:child_process");\',\n \'const held = (args) => { try { return execFileSync("git", args, { stdio: ["ignore", "pipe", "ignore"], maxBuffer: 268435456 }).toString("utf8"); } catch { return null; } };\',\n \'const tag = held(["describe", "--tags", "--abbrev=0", "--match", "v*", "HEAD"]);\',\n "if (tag === null) process.exit(0);",\n "const told = {};",\n \'for (const path of (held(["ls-tree", "-r", "--name-only", tag.trim()]) ?? "").split("\\\\n")) {\',\n "if (!/^(faculties|designs)\\\\/[^/]+\\\\/versions\\\\.json$/.test(path)) continue;",\n \'const text = held(["show", tag.trim() + ":" + path]); if (text !== null) told[path] = text;\',\n "}",\n \'fs.writeFileSync(process.argv[1], JSON.stringify(told)); process.stdout.write(process.argv[1] + "\\\\n");\'\n ].join("\\n");\n static #checks = `told=$(node -e \'${_ReposSkin.#handing}\' -- "$t/told.json") || exit 1\nnode "$t/parts.mjs" "$w" \\${told:+"$told"} || exit 1\nif [ -f "$t/scoped" ]; then echo "conform: skipped: a lobe holding a scope is checked by the lobe it pushes to"\nelif [ ! -f "$t/chosen" ]; then echo "conform: skipped: no conform is chosen: the check of the parts alone"\nelse k=$(cat "$t/chosen")\ngit cat-file -e "$k^{commit}" 2>/dev/null || { echo "the commit whose conform is chosen, $k, the repo holds not"; exit 1; }\nif git show "$k:tools/conform.mjs" > "$t/conform.mjs" 2>/dev/null; then node "$t/conform.mjs" "$w" || exit 1; else echo "conform: skipped: the commit chosen, $k, holds no tools/conform.mjs"; fi\nfi\n`;\n static #versioning = [\n \'const fs = require("node:fs"); const { execFileSync } = require("node:child_process");\',\n \'const of = (text) => { try { const v = JSON.parse(text).version; return typeof v === "string" ? v : null; } catch { return null; } };\',\n \'const held = (args) => { try { return execFileSync("git", args, { stdio: ["ignore", "pipe", "ignore"] }).toString("utf8"); } catch { return null; } };\',\n \'let read = null; try { read = fs.readFileSync(process.argv[1], "utf8"); } catch {}\',\n \'const now = read === null ? null : of(read); const parent = held(["show", "HEAD:package.json"]); const was = parent === null ? null : of(parent);\',\n "if (now === was) process.exit(0);",\n \'const refused = (why) => { process.stderr.write(why +"\\\\n"); process.exit(1); };\',\n "const three = /^(0|[1-9][0-9]*)\\\\.(0|[1-9][0-9]*)\\\\.(0|[1-9][0-9]*)$/;",\n \'if (now === null || !three.test(now)) refused("the root version " + (now === null ? "none" : now) + " is not three whole numbers");\',\n \'const parts = (v) => v.split(".").map((n) => BigInt(n));\',\n \'if (was !== null && three.test(was)) { const [a, b] = [parts(now), parts(was)]; const at = a.findIndex((n, i) => n !== b[i]); if (at >= 0 && a[at] < b[at]) refused("the root version " + now + " is lower than " + was + ": a version is only raised"); }\',\n \'const tag = "v" + now;\',\n \'if (held(["rev-parse", "-q", "--verify", "refs/tags/" + tag]) !== null) refused("this lobe holds the tag " + tag + " already: a version names one commit for ever");\',\n \'process.stdout.write(tag + "\\\\n");\'\n ].join("\\n");\n static #versioned = `v=\nif [ ! -f "$t/scoped" ]; then v=$(node -e \'${_ReposSkin.#versioning}\' -- "$w/package.json") || exit 1; fi\n`;\n static #unsecret = `if [ -e ${_ReposSkin.#env} ] && ! git check-ignore -q -- ${_ReposSkin.#env}; then echo "${_ReposSkin.#env} is a secret file .gitignore keeps not out: no commit holds it"; exit 1; fi\n`;\n static #staged = `if [ -f "$t/paths" ]; then\nxargs -0 git --literal-pathspecs ls-files -z --cached --others --exclude-standard -- <"$t/paths" >"$t/present" || exit 1\ncp "$t/present" "$t/changed" || exit 1\nif git rev-parse -q --verify HEAD >/dev/null; then xargs -0 git --literal-pathspecs ls-tree -r -z --name-only HEAD -- <"$t/paths" >>"$t/changed" || exit 1; fi\nb=$(git rev-parse -q --verify HEAD || git hash-object -t tree /dev/null) || exit 1\nGIT_INDEX_FILE="$t/index" git read-tree "$b" || exit 1\n[ ! -s "$t/changed" ] || GIT_INDEX_FILE="$t/index" git --literal-pathspecs add --all --pathspec-from-file="$t/changed" --pathspec-file-nul || exit 1\nGIT_INDEX_FILE="$t/index" git diff-index --cached --quiet "$b" -- && { echo "none of the paths named holds a change"; exit 1; }\nelse\ncp -p "$(git rev-parse --git-path index)" "$t/index" 2>/dev/null\nGIT_INDEX_FILE="$t/index" git add --all || exit 1\nfi\nmkdir "$t/w" && GIT_INDEX_FILE="$t/index" git checkout-index --all --prefix="$t/w/" || exit 1\nw="$t/w"\n`;\n static #taken = `if [ -f "$t/paths" ]; then { [ ! -s "$t/present" ] || git --literal-pathspecs add --all --pathspec-from-file="$t/present" --pathspec-file-nul; } && git --literal-pathspecs commit --quiet --file="$t/message" --pathspec-from-file="$t/changed" --pathspec-file-nul || exit 1\nelse git add --all && { [ ! -s "$t/executable" ] || git update-index --chmod=+x -z --stdin <"$t/executable"; } && git commit --quiet --file="$t/message" || exit 1\nfi\n`;\n static #whole = \'const fs = require("node:fs"); let s = ""; process.stdin.setEncoding("utf8"); process.stdin.on("data", (d) => { s += d; }); process.stdin.on("end", () => { const { set = {} } = JSON.parse(s || "{}"); const f = process.argv[1]; const keys = Object.keys(set).sort(); if (keys.length === 0) { fs.rmSync(f, { force: true }); return; } fs.writeFileSync(f, keys.map((key) => key + "=" + set[key] + "\\\\n").join(""), { mode: 0o600 }); fs.chmodSync(f, 0o600); });\';\n static #scripts = {\n setup: `cd "$1/repos" || exit 1\n${_ReposSkin.#marked}`,\n init: `${_ReposSkin.#exact("$1/repos/$2", "$1/repos", "$2")}cd "$1/repos/$2" || exit 1\nexport GIT_CEILING_DIRECTORIES="$1/repos"\n${_ReposSkin.#ident}${_ReposSkin.#marked}\n[ -e .git ] && { echo "the folder holds a repo already" >&2; exit 1; }\n[ -z "$(ls -A)" ] || { echo "the folder holds files: a repo is born in an empty folder" >&2; exit 1; }\ngit init --quiet -b main`,\n stand: `${_ReposSkin.#in}[ -d .git ] && [ ! -L .git ] && [ "$(git rev-parse --show-toplevel 2>/dev/null)" = "$(pwd -P)" ] || { echo "the folder holds no repo to stand on" >&2; exit 1; }\n[ "$(git branch --show-current)" = main ] || { echo "the repo is not on main" >&2; exit 1; }\nc=$(git rev-parse -q --verify refs/heads/main) || { echo "main holds no commit: a repo with none is born by init alone" >&2; exit 1; }\nt=$(mktemp -d) || exit 1\ntrap \'git -C "$1" worktree remove --force "$t/w" 2>/dev/null; rm -rf "$t"; git -C "$1" worktree prune\' EXIT\nnode -e \'${_ReposSkin.#unpack}\' -- "$t" || exit 1\ngit worktree add --quiet --detach "$t/w" "$c" >/dev/null 2>&1 || exit 1\nw="$t/w"\nprintf %s "$c" > "$t/chosen"\n{\n${_ReposSkin.#lend("$t")}${_ReposSkin.#checks}} >&2\necho "conform $c"\necho "$c"`,\n head: `${_ReposSkin.#in}git rev-parse --git-dir >/dev/null 2>&1 || { echo "the folder holds no repo" >&2; exit 1; }\ngit rev-parse -q --verify HEAD || echo\n[ -n "$2" ] || exit 0\nif git merge-base --is-ancestor "$2" HEAD 2>/dev/null; then echo holds; else echo lacks; fi`,\n status: `${_ReposSkin.#in}exec git status --porcelain=v1 --branch`,\n commit: `${_ReposSkin.#in}[ "$(git branch --show-current)" = main ] || { echo "the repo is not on main" >&2; exit 1; }\nt=$(mktemp -d) || exit 1\ntrap \'rm -rf "$t"\' EXIT\nnode -e \'${_ReposSkin.#unpack}\' -- "$t" || exit 1\n{\n${_ReposSkin.#unsecret}${_ReposSkin.#staged}${_ReposSkin.#checks}${_ReposSkin.#versioned}} >&2\n${_ReposSkin.#taken}[ ! -s "$t/executable" ] || git checkout-index -f -z --stdin <"$t/executable" || exit 1\nif [ -n "$v" ]; then git tag "$v" || exit 1; echo "$v"; fi\nh=$(git rev-parse HEAD) || exit 1\n[ "$(git rev-parse -q --verify HEAD:tools/conform.mjs)" = "$(git rev-parse -q --verify HEAD~:tools/conform.mjs)" ] || echo "conform $h"\necho "$h"`,\n discard: `${_ReposSkin.#in}git restore --source=HEAD --staged --worktree -- . && exec git clean -fdq`,\n log: `${_ReposSkin.#in}exec git log --max-count="$2" --format=%H%x09%an%x09%aI%x09%s`,\n bundle: `${_ReposSkin.#in}rm -rf "$2" && mkdir -p "$2" || exit 1\nif [ -n "$5" ]; then u=$(git rev-parse -q --verify "refs/tags/$5^{commit}") || { echo "this lobe holds no tag $5" >&2; exit 1; }\nif [ -n "$3" ] && git merge-base --is-ancestor "$u" "$3" 2>/dev/null; then echo 0; echo "$u"; exit 0; fi\nt=$(mktemp -d) || exit 1\ntrap \'rm -rf "$t"\' EXIT\ngit init --quiet --bare --object-format="$(git rev-parse --show-object-format)" "$t/c" >/dev/null || exit 1\ngit rev-parse --path-format=absolute --git-path objects > "$t/c/objects/info/alternates" || exit 1\ngit --git-dir="$t/c" update-ref refs/heads/main "$u" || exit 1\nfor n in $(git tag --merged "$u" --list \'v*\'); do git --git-dir="$t/c" update-ref "refs/tags/$n" "$(git rev-parse "refs/tags/$n")" || exit 1; done\ncd "$t/c" && export GIT_DIR="$t/c" || exit 1\nelif [ -n "$4" ]; then if [ -n "$3" ] && u=$(git rev-parse -q --verify "$4") && git merge-base --is-ancestor "$u" "$3" 2>/dev/null; then git update-ref -d "$4"; echo 0; echo "$u"; exit 0; fi\nt=$(mktemp -d) || exit 1\ntrap \'rm -rf "$t"\' EXIT\ngit init --quiet --bare --object-format="$(git rev-parse --show-object-format)" "$t/c" >/dev/null || exit 1\nif git rev-parse -q --verify "$4" >/dev/null; then git --git-dir="$t/c" fetch --quiet --no-tags "$1" "+$4:refs/heads/main" || exit 1; fi\ngit update-ref -d "$4" 2>/dev/null; cd "$t/c" && export GIT_DIR="$t/c" || exit 1\nfi\nh=$(git rev-parse -q --verify main) || { echo 0; exit 0; }\n[ "$3" = "$h" ] && { echo 0; echo "$h"; exit 0; }\nif [ -n "$3" ] && git cat-file -e "$3^{commit}" 2>/dev/null; then x="^$3"; g=$(git for-each-ref --format=\'%(refname)\' --merged main --no-merged "$3" \'refs/tags/v*\'); else x=; g=$(git for-each-ref --format=\'%(refname)\' --merged main \'refs/tags/v*\'); fi\ngit bundle create --quiet "$2/b" main $g $x || exit 1\ncd "$2" || exit 1\np="\\${6:-${_ReposSkin.#box}}"\nn=$(( ($(wc -c < b) + p - 1) / p ))\ni=0; while [ "$i" -lt "$n" ]; do dd if=b of="q$i" bs="$p" skip="$i" count=1 2>/dev/null || exit 1; i=$((i + 1)); done\nrm b || exit 1\necho "$n"; echo "$h"`,\n bring: _ReposSkin.#bring,\n cut: _ReposSkin.#cut,\n graft: _ReposSkin.#graft,\n land: `${_ReposSkin.#in}r="refs/nervur/$2"\nc=$(git rev-parse -q --verify "$r-main") || { echo "nothing waits to land as $2" >&2; exit 1; }\ngit update-ref -d "$r"; git update-ref -d "$r-main"\nk=$(git for-each-ref --format=\'%(objectname) %(refname)\' "$r-tags/"); ${_ReposSkin.#untag}\nw=$(echo "$k" | while read -r o n; do [ -n "$n" ] || continue; n=\\${n#"$r-tags/"}; if e=$(git rev-parse -q --verify "refs/tags/$n^{commit}"); then [ "$e" = "$o" ] || echo "this lobe holds the tag $n on another commit: a version names one commit for ever"; fi; done)\n[ -z "$w" ] || { echo "$w" >&2; exit 1; }\nif git rev-parse -q --verify HEAD >/dev/null; then git merge --quiet --ff-only "$c" || { echo "main moved while what came was checked: send it again" >&2; exit 1; }; else git checkout --quiet -B main "$c" || exit 1; fi\necho "$k" | while read -r o n; do [ -n "$n" ] || continue; n=\\${n#"$r-tags/"}; git rev-parse -q --verify "refs/tags/$n" >/dev/null || echo "create refs/tags/$n $o"; done | git update-ref --stdin || exit 1\ngit rev-parse HEAD`,\n conform: `${_ReposSkin.#in}c=$(git rev-parse -q --verify "refs/nervur/$2-main") || { echo "nothing waits as $2" >&2; exit 1; }\n[ "$c" = "$3" ] || { echo "what waits as $2 is $c, not $3" >&2; exit 1; }\nt=$(mktemp -d) || exit 1\ntrap \'git -C "$1" worktree remove --force "$t/w" 2>/dev/null; rm -rf "$t"; git -C "$1" worktree prune\' EXIT\nnode -e \'${_ReposSkin.#unpack}\' -- "$t" || exit 1\ngit worktree add --quiet --detach "$t/w" "$c" >/dev/null 2>&1 || exit 1\nw="$t/w"\n${_ReposSkin.#lend("$t")}${_ReposSkin.#checks}[ -n "$4" ] || exit 0\ncd "$t/w" || exit 1\nnode -e \'process.exit(require("./package.json").scripts?.[process.argv[1]] ? 0 : 3)\' "$4" 2>/dev/null || { echo "gate: skipped: the repo holds no script $4"; exit 0; }\n${_ReposSkin.#queued}${_ReposSkin.#masked} sh -c \'if [ -f package-lock.json ]; then npm ci || exit 1; fi; exec npm run "$1"\' gate "$4"`,\n run: `${_ReposSkin.#in}${_ReposSkin.#lend("${1%/*}")}${_ReposSkin.#scripted}d="$1"; s="$2"; i="$3"; g="$4"\n[ -z "$g" ] || { ${_ReposSkin.#queued}}\nshift 4\nexec node -e \'${_ReposSkin.#mask}\' -- "$d/${_ReposSkin.#env}" sh -c \'if [ "$2" = install ] && [ -f package-lock.json ]; then npm ci || exit 1; fi; s="$1"; shift 2; exec npm run "$s" -- "$@"\' run "$s" "$i" "$@"`,\n secrets: `${_ReposSkin.#in}git rev-parse --git-dir >/dev/null 2>&1 || { echo "the folder holds no repo" >&2; exit 1; }\ngit check-ignore -q -- ${_ReposSkin.#env} || { echo "${_ReposSkin.#env} is not kept out by .gitignore: no secret file is written where git would take it" >&2; exit 1; }\numask 077\nexec node -e \'${_ReposSkin.#whole}\' -- "./${_ReposSkin.#env}"`,\n remove: `for n in "$2" "\\${3-x}"; do case "$n" in .*|*/*) echo "remove reaches one folder of repos/ alone" >&2; exit 1 ;; esac; done\n[ -n "$2" ] || { echo "remove names its folder" >&2; exit 1; }\ncd "$1/repos" || exit 1\nif [ -e "$2" ] || [ -L "$2" ]; then { [ -d "$2" ] && [ ! -L "$2" ] && ls -1A . | grep -qxF -- "$2"; } || { echo "the folder $2 stands not as named under repos" >&2; exit 1; }; rm -rf -- "$2" || exit 1; fi\n[ ! -e "$2" ] || { echo "the folder $2 stands still" >&2; exit 1; }\n[ -z "$3" ] || rm -rf -- "$1/transfers/$3"`,\n clear: `cd "$1/transfers" 2>/dev/null || exit 0\nfor n in "$2" "\\${3-x}"; do case "$n" in \'\'|.*|*/*) echo "clear reaches a lobe\'s pieces alone" >&2; exit 1 ;; esac; done\nexec rm -rf -- "$2\\${3:+/$3}"`,\n scan: `${_ReposSkin.#in}${_ReposSkin.#lend("${1%/*}")}h=$(git rev-parse -q --verify HEAD) || { echo; exit 0; }\necho "$h"\ngit tag --points-at HEAD --list \'v*\' | sed \'s/^/g /\'\ngit ls-files -- \':(glob)faculties/*/faculty.js\' \':(glob)faculties/*/versions.json\' \':(glob)organs/*/graph.json\' \':(glob)organs/*/host/build\' \':(glob)designs/*/design.json\' \':(glob)designs/*/versions.json\' | sed \'s/^/t /\'\n{ git diff --name-only HEAD -- faculties organs designs; git ls-files --others --exclude-standard -- faculties organs designs; } | sed \'s/^/c /\'\ngit -c core.quotePath=false ls-files -- designs \':(glob)faculties/*/assets/**\' | while IFS= read -r p; do { [ -f "$p" ] && [ ! -L "$p" ]; } || { echo "u $p"; continue; }; s=$(perl -0777 -pe \'s/\\\\r\\\\n?/\\\\n/g unless /\\\\0/\' -- "$p" | { sha256sum 2>/dev/null || shasum -a 256; } | cut -d " " -f 1); echo "d $s $p"; done\n${_ReposSkin.#keep}t=$(git describe --tags --abbrev=0 --match \'v*\' HEAD 2>/dev/null) || exit 0\necho "@ $t"\ngit ls-tree -r --name-only "$t" -- faculties organs | grep -E \'^(faculties/[^/]+/(faculty\\\\.js|versions\\\\.json)|organs/[^/]+/(graph\\\\.json|host/build))$\' | while IFS= read -r p; do echo "T $p"; case "$p" in */host/build) continue ;; esac; git diff --quiet "$t" -- "$p" 2>/dev/null && continue; printf \'B %s \' "$p"; git show "$t:$p" | node -e \'let s="";process.stdin.setEncoding("utf8").on("data",(d)=>{s+=d}).on("end",()=>process.stdout.write(JSON.stringify(s)))\'; echo; done\ngit -c core.quotePath=false ls-tree -r "$t" -- faculties | while IFS="$c" read -r m p; do case "$p" in faculties/*/assets/*) ;; *) continue ;; esac; o=\\${m##* }; if [ -s "$k/.o/$o" ]; then echo "A $(cat "$k/.o/$o") $p"; else echo "U $p"; fi; done`,\n build: `${_ReposSkin.#in}${_ReposSkin.#lend("${1%/*}")}o="organs/$2/host"\n[ -x "$o/build" ] || { echo "organs/$2 holds no executable host/build" >&2; exit 1; }\n(cd "$o" && ./build) >&2 || exit 1\n[ -f "$o/half" ] || { echo "the build left no host/half" >&2; exit 1; }\nd=$({ sha256sum "$o/half" 2>/dev/null || shasum -a 256 "$o/half"; } | cut -d " " -f 1)\nr="\\${1%/*}"; h="\\${r%/*}/halves"\nmkdir -p "$h" && chmod 755 "$h" && cp "$o/half" "$h/$d.writing" && chmod 755 "$h/$d.writing" && mv -f "$h/$d.writing" "$h/$d" || { echo "the half is not laid in $h" >&2; exit 1; }\nprintf \'%s\\\\n\' "$d"`,\n look: `${_ReposSkin.#in}${_ReposSkin.#lend("${1%/*}")}d="designs/$2"\n{ [ -d "$d" ] && [ ! -L "$d" ] && ls -1A designs | grep -qxF -- "$2"; } || { echo "the repo holds no design $2" >&2; exit 1; }\nnode -e \'process.exit(require("./package.json").scripts?.design ? 0 : 3)\' 2>/dev/null || { echo "the repo holds no script design" >&2; exit 3; }\nt=$(mktemp) || exit 1\ntrap \'rm -f "$t"\' EXIT\nnpm run --silent design -- "$d" --look "$t" >&2 || exit 1\ncat "$t"`\n };\n static #sh(kind) {\n return ["sh", "-c", _ReposSkin.#scripts[kind], kind];\n }\n static programs = {\n setup: _ReposSkin.#sh("setup"),\n init: _ReposSkin.#sh("init"),\n stand: _ReposSkin.#sh("stand"),\n head: _ReposSkin.#sh("head"),\n status: _ReposSkin.#sh("status"),\n commit: _ReposSkin.#sh("commit"),\n discard: _ReposSkin.#sh("discard"),\n log: _ReposSkin.#sh("log"),\n bundle: _ReposSkin.#sh("bundle"),\n bring: _ReposSkin.#sh("bring"),\n cut: _ReposSkin.#sh("cut"),\n graft: _ReposSkin.#sh("graft"),\n land: _ReposSkin.#sh("land"),\n conform: _ReposSkin.#sh("conform"),\n run: _ReposSkin.#sh("run"),\n secrets: _ReposSkin.#sh("secrets"),\n clear: _ReposSkin.#sh("clear"),\n remove: _ReposSkin.#sh("remove"),\n scan: _ReposSkin.#sh("scan"),\n build: _ReposSkin.#sh("build"),\n look: _ReposSkin.#sh("look")\n };\n static #unready = { ready: false, doing: null, failed: null };\n static #plain = { type: "string" };\n static #some = { type: "string", minLength: 1 };\n static #maybe = { anyOf: [{ type: "string", minLength: 1 }, { type: "null" }] };\n static #place = { type: "integer", minimum: 0 };\n static #one = { type: "integer", minimum: 1 };\n static #named = { type: "string", pattern: "^[a-z][a-z0-9.-]{0,63}$" };\n static #jobSchema = {\n type: "object",\n properties: { job: _ReposSkin.#some },\n required: ["job"],\n additionalProperties: false\n };\n static #scopeSchema = { type: "array", items: _ReposSkin.#some, minItems: 1, maxItems: SCOPE_MOST };\n static #many = { type: "array", items: _ReposSkin.#some, minItems: 1 };\n static #files = {\n type: "array",\n items: {\n type: "object",\n properties: { path: _ReposSkin.#some, text: _ReposSkin.#plain, absent: { type: "boolean" } },\n required: ["path"],\n additionalProperties: false\n }\n };\n static #object(properties, required = Object.keys(properties)) {\n return { type: "object", properties, required, additionalProperties: false };\n }\n static #says = {\n setup: "An owner, once: the disk\'s folder stands at `at` on the host, proven by a marker the disk writes and the shell reads back.",\n delegate: "An owner: the lobe `lobe` a delegate, which grants folders of its own as an owner does and removes those alone, as a keeper raising repo lobes as its children does; with `given` false, a delegate no more, the folders it granted standing.",\n grant: "An owner, or a delegate a folder it granted, a new one, or one no lobe holds, a lobe torn down having left it, which is the delegate’s from then on: the folder `folder`, `repos/<folder>`, is the repo lobe `lobe`’s, whatever lobe it names, its one folder and no other’s, so a wired lobe reaches it only through its repo lobe; its wire back is ordered as its first job starts; a name an entry of `repos/` holds in another case is refused; where `lobe` is null, it is granted to none; a lobe that loses it has its pieces cleared.",\n folders: "An owner, every folder; a delegate, those it granted and those no lobe holds, which it may take: each with the repo lobe it is granted to, whether a repo stands in it, the job going, and the secret files written in it, by their paths.",\n remove: "An owner, or a delegate the folder it granted: forgets the folder `folder` and its grant, its bytes left on disk, and its lobe’s pieces are cleared; with `erase` true, a job, answered `{ job }`, deletes them too: its grant forgotten at once, so its repo lobe reaches it no more, then the folder `repos/<folder>`, checked to stand under the disk’s `repos/` by that exact name and no link, deleted with every byte it holds, and the pieces of the lobe granted it, `transfers/<lobe>/`; the folder forgotten once the job ended, its bytes gone, read by `job`; one that failed stands, granted to none. One running a job is refused.",\n state: "An owner: the disk\'s folder as set up. A repo lobe: its folder on the host, whether a repo stands in it, read on the disk where one was made, and the job going.",\n read: "A repo lobe: a file\'s text, its first lines where `first` names how many, and how many lines it holds; or `paths` alone, `{ files }` in one answer, each `{ path, text }` or `{ path, absent: true }` in the order named, the whole refused where a path climbs or hides, a text is no UTF-8 or the texts weigh past what one answer carries.",\n bytes: "A repo lobe: the bytes of a file a tag of its repo holds in a design\'s folder or a faculty\'s `assets/`, as a design\'s font, which no text holds, by the SHA-256 `sha` its scan kept them under, a text\'s with LF line ends; `absent` where none is kept.",\n write: "A repo lobe: writes a file\'s text whole, as a commit\'s files.",\n erase: "A repo lobe: removes a file, or a folder that holds nothing, of its repo, as a refused commit\'s files are put back as they were; the one removal a repo lobe has this jailer make of a repo\'s bytes.",\n list: "A repo lobe: the names in a folder of its repo, its top where no path is named.",\n piece: "A repo lobe: the piece `at` of the bundle that waits as `as`",\n put: "A repo lobe: writes the piece `at` of `pieces` of a bundle that waits as `as`.",\n init: "A job: makes the repo on `main` in its folder, which holds nothing, empty, laying no file; never over a repo that stands.",\n stand: "A job: the repo its folder holds already, handed in place to the lobe granted it: refused where none stands there, or `main` holds no commit or is not checked out; else its `main` checked out apart and checked by the check of the parts `parts`, Nervur’s, and `tools/conform.mjs` as `main` holds it, on its errors, then `conform <head>`, the conform it chooses, and its head answered. Nothing is laid or moved. Its checks go on the input.",\n head: "A job: the HEAD, and whether it holds the commit `contains` where one is named.",\n status: "A job: `git status`.",\n commit: "A job: refused while `.env` stands where `.gitignore` keeps it not out; then the check of the parts `parts`, Nervur’s, and the repo’s `tools/conform.mjs` as the commit `conform` holds it, the one its owner chose, none where it names none, each over what it would commit, laid out apart as a clone would hold it, so a file `.gitignore` keeps out counts as absent; then its root `package.json` `version` read against `HEAD`’s: refused where it changed and is not three whole numbers, is lower by semver, or its tag `v<version>` stands already; then every change committed on `main`, or with `paths` the changes of those paths alone, each a file or a folder of the repo and the rest of the folder left as it stands, refused where they hold none, with `message`, each path `executable` names landing executable, and tagged `v<version>`, a git tag, where it raised the version, none in a lobe holding a scope; answering the tag where it made one, `conform <head>` where it changed `tools/conform.mjs`, the conform it chooses, then its HEAD. Its message and its checks go on the input.",\n discard: "A job: every change since the last commit undone.",\n log: "A job: the last commits, `most` of them, twenty where none is named.",\n run: "A job: the script `script` of the repo\'s `package.json`, by `npm run <script> -- <args…>`, each of `args` one argument, never read by a shell, its environment the repo\'s `.env`, each line as written, its values masked in its output; with `install`, `npm ci` first where a lockfile stands, in the same job; with `gate`, after the gates asked before it, one at a time across the organism; a script the repo lacks ends 3.",\n secrets: "A job: `.env` written whole, only where `.gitignore` keeps it out: each name of `set` a line `KEY=value`, readable by the owner of the files alone, and removed where it sets none. Its values go on the input, never kept nor read back.",\n clear: "A repo lobe\'s job beside its folder\'s, told to no one: the pieces of its bundle waiting as `as` removed; while they go, none is made, written or read under that name.",\n check: "A repo lobe: its job and its clears checked against the runs the shell names going; each it runs no more, lost to a restart, ended at once, failed, its lobe told. Answers the job going, those ended lost, and `last`, the end it last told that lobe, `{ job, kind, code, out, err }`, as its letter tells it, kept for that lobe alone until its next end, or null.",\n bundle: "A job: the commits on `main` after `since`, as a bundle in pieces waiting as `as`; answers how many and the HEAD. With `cut`, the commits of the cut of `as` after `since` instead, read from its own bare repo as `main`, so nothing of `main` leaves, not even a name; the cut’s ref then cleared, and no tag carried. The bundle carries every tag `v*` naming a commit after `since`; with `tag`, `v` and three whole numbers, `main` ends at the commit that tag names, refused where this lobe holds no such tag, and none where `since` holds that commit already; a cut is bundled by no tag, since its tag was named to the cut: with `cut`, none is made either where `since` holds the cut’s head already.",\n cut: "A job: `main` cut to the scope `scope`, folders none inside another: by first parent, each commit that changes a path within the scope rewritten to one whose tree holds those paths alone, its parent the last one cut, its author, committer, their times and its message kept exactly, signed by no one, so the same `main` is cut to the same commits every time; with `tag`, `v` and three whole numbers, only up to the commit that tag names, the beginning of the cut to the head, the very commits in the very order, refused where this lobe holds no such tag, and the tag’s name never in the cut; left at `refs/nervur/cut-<as>`, its head answered, or an empty line where the cut is empty.",\n bring: "A job: a pull\'s or a push\'s `pieces` waiting as `as` brought apart from `main`, and what `main` would become kept beside it, itself or a merge made apart; answers that head and `forward`, `merge` or `new`, or `main`\'s HEAD and `held` where `main` holds it already; a conflict refused. With `scope`, a scoped writer’s push, grafted: refused unless its commits are linear on the scope’s head as `main` is cut now, none where the cut is empty, else as behind, and where one changes a path outside the scope, naming it, or nothing within it; each commit then grafted on `main`’s tip, its tree `main`’s with every path within the scope taken from it, its author, committer, their times and its message kept, so the scope cut again answers the very commits pushed, else refused; answers that head, `graft` and the head pushed, or the head pushed and `held`. The tags `v*` the bundle carries, a scoped writer\'s none, fetched apart as `refs/nervur/<as>-tags/`, and the whole refused, nothing kept, where one names no commit it brings or this lobe holds a tag of that name on another commit.",\n land: "A job: what was brought as `as` brought into `main`, which it builds on; refused where `main` moved meanwhile. The tags brought with it laid once `main` moved, never before, one held on the same commit no change, and the whole refused, `main` unmoved, where one meets a tag of that name on another commit. Answers the HEAD.",\n conform: "A job: what was brought as `as`, at `head`, checked out apart and checked by the check of the parts `parts`, Nervur’s, then by `tools/conform.mjs` as the commit `conform` holds it, the one the lobe’s owner chose, never as what came holds it, said skipped where it names none or that commit holds none; with `script`, that gate then run there too, with the repo’s `.env`, masked in its output, after the gates asked before it, one at a time across the organism. Its checks go on the input.",\n scan: "A job: the HEAD, each tag `v*` it carries as `g <tag>`, each file of `faculties/` and `organs/` git tracks, each design\'s `design.json` and `versions.json`, each it shows changed, and each file of `designs/` and of each faculty\'s `assets/` with its SHA-256, a text\'s read with LF line ends; then the newest tag `v*` reachable from the HEAD as `@ <tag>`, each faculty\'s and organ\'s file its commit holds as `T <path>`, the text of each that differs from the folder as `B <path> <JSON string>`, and each file of each faculty\'s `assets/` there as `A <SHA-256> <path>`, or `U <path>` where none is kept. Between them, each file a tag `v*` holds in `designs/` or a faculty\'s `assets/` kept by its SHA-256, a text\'s with LF line ends, for `bytes` to read, each tag kept once.",\n build: "A job: the organ `organ`\'s `host/build` run, answering the SHA-256 of the `host/half` it leaves.",\n look: "A job: the design `design`\'s look built by the repo\'s own script `design`, given `designs/<design>` and `--look` with the file to write it to, answering that file alone, the look\'s source; it is built, never committed.",\n stop: "A repo lobe\'s own job, or an owner\'s of the folder `folder`, stopped through the shell; one the shell runs no more, lost to a restart of the organ, ends at once, failed.",\n ended: "The shell\'s alone: a job\'s program ended.",\n back: "The brain\'s alone: the shell\'s half connected, at its start or after it restarted, an update\'s among them: each job going that the shell names going no more ends, lost, its lobe told.",\n jobs: "The asker\'s jobs, an owner\'s every one, each with its code once ended; a job keeps no input and no output.",\n job: "One of the asker\'s jobs, `job`, as the jailer keeps it; an owner reads any, and one not the asker\'s is absent."\n };\n static #reading(method, args, result) {\n const typed = { ...args === void 0 ? {} : { args }, ...result ? { result } : {} };\n const description = _ReposSkin.#says[method] ?? method;\n return { description, kind: "reading", ...typed, errors: ["refused", "absent"] };\n }\n static #writing(method, args, result) {\n return { ..._ReposSkin.#reading(method, args, result), kind: "writing" };\n }\n static #jobOf(method, args) {\n return _ReposSkin.#writing(method, args, _ReposSkin.#jobSchema);\n }\n static #none = _ReposSkin.#object({});\n static blueprint = {\n name: "nervur.repos",\n version: "0.1.118",\n description: "The jailer: keeps the bytes of the organism\'s repos at `repos/<name>` under the disk\'s folder, on `main`, a skin lobe of `shell` and `disk`. An owner sets the folder up and grants each repo\'s folder to one repo lobe, through which the lobes wired to it reach it; the repo lobe reaches its own and never names it: its files read and written as UTF-8 text through the disk, the pieces of its bundles beside them, and its jobs run through the shell, one at a time for each folder, each answered at once and asked back `done` by a letter. It holds no relation and no secret: `.env` is written whole from a job\'s input, only where `.gitignore` keeps it out, readable by the owner of the files alone, and read back by the names that stand alone; a commit is refused while one stands that git would take, and checked over what it would commit laid out apart; and every run of a repo\'s script loads `.env` into its environment, each line as written, masked in its output by its program; a job keeps neither its input nor its output, but the end last told each lobe, kept for that lobe alone until its next. It removes no repo\'s bytes but a refused commit\'s own files, which its repo lobe has it `erase`, and a folder an owner removes with `erase`: a plain `remove` forgets a folder and leaves its bytes.",\n methods: {\n setup: _ReposSkin.#jobOf("setup", _ReposSkin.#object({ at: _ReposSkin.#some })),\n delegate: _ReposSkin.#writing(\n "delegate",\n _ReposSkin.#object({ lobe: _ReposSkin.#some, given: { type: "boolean" } }, ["lobe"])\n ),\n grant: _ReposSkin.#writing("grant", _ReposSkin.#object({ folder: _ReposSkin.#named, lobe: _ReposSkin.#maybe })),\n folders: _ReposSkin.#reading("folders"),\n remove: {\n ..._ReposSkin.#writing(\n "remove",\n _ReposSkin.#object({ folder: _ReposSkin.#named, erase: { type: "boolean" } }, ["folder"])\n ),\n irreversible: true\n },\n state: _ReposSkin.#reading("state", _ReposSkin.#none),\n read: _ReposSkin.#reading(\n "read",\n _ReposSkin.#object({ path: _ReposSkin.#some, first: _ReposSkin.#one, paths: _ReposSkin.#many }, []),\n _ReposSkin.#object({ text: _ReposSkin.#plain, lines: { type: "integer" }, files: _ReposSkin.#files }, [])\n ),\n bytes: _ReposSkin.#reading("bytes", _ReposSkin.#object({ sha: _ReposSkin.#some }), _ReposSkin.#object({ bytes: {} })),\n write: _ReposSkin.#writing("write", _ReposSkin.#object({ path: _ReposSkin.#some, text: _ReposSkin.#plain })),\n erase: { ..._ReposSkin.#writing("erase", _ReposSkin.#object({ path: _ReposSkin.#some })), irreversible: true },\n list: _ReposSkin.#reading(\n "list",\n _ReposSkin.#object({ path: _ReposSkin.#plain }, []),\n _ReposSkin.#object({ names: { type: "array", items: _ReposSkin.#plain } })\n ),\n piece: _ReposSkin.#reading(\n "piece",\n _ReposSkin.#object({ at: _ReposSkin.#place, as: _ReposSkin.#some }, ["at", "as"])\n ),\n put: _ReposSkin.#writing(\n "put",\n _ReposSkin.#object({\n at: _ReposSkin.#place,\n pieces: _ReposSkin.#one,\n bytes: {},\n as: _ReposSkin.#some\n })\n ),\n init: _ReposSkin.#jobOf("init", _ReposSkin.#none),\n stand: _ReposSkin.#jobOf(\n "stand",\n _ReposSkin.#object({ parts: _ReposSkin.#some, scoped: { type: "boolean" } }, ["parts"])\n ),\n head: _ReposSkin.#jobOf("head", _ReposSkin.#object({ contains: _ReposSkin.#some }, [])),\n status: _ReposSkin.#jobOf("status", _ReposSkin.#none),\n commit: _ReposSkin.#jobOf(\n "commit",\n _ReposSkin.#object(\n {\n message: _ReposSkin.#some,\n parts: _ReposSkin.#some,\n scoped: { type: "boolean" },\n executable: { type: "array", items: _ReposSkin.#some },\n paths: { type: "array", items: _ReposSkin.#some, minItems: 1 }\n },\n ["message", "parts"]\n )\n ),\n discard: { ..._ReposSkin.#jobOf("discard", _ReposSkin.#none), irreversible: true },\n log: _ReposSkin.#jobOf("log", _ReposSkin.#object({ most: { type: "integer", minimum: 1 } }, [])),\n run: _ReposSkin.#jobOf(\n "run",\n _ReposSkin.#object(\n {\n script: _ReposSkin.#some,\n args: { type: "array", items: _ReposSkin.#plain, maxItems: ARGS_MOST },\n install: { type: "boolean" },\n gate: { type: "boolean" }\n },\n ["script"]\n )\n ),\n secrets: _ReposSkin.#jobOf(\n "secrets",\n _ReposSkin.#object({ set: { type: "object", additionalProperties: _ReposSkin.#plain } })\n ),\n bundle: _ReposSkin.#jobOf(\n "bundle",\n _ReposSkin.#object(\n {\n since: _ReposSkin.#maybe,\n as: _ReposSkin.#some,\n cut: { type: "boolean" },\n tag: _ReposSkin.#some,\n piece: _ReposSkin.#one\n },\n ["since", "as"]\n )\n ),\n bring: _ReposSkin.#jobOf(\n "bring",\n _ReposSkin.#object({ as: _ReposSkin.#some, pieces: _ReposSkin.#one, scope: _ReposSkin.#scopeSchema }, [\n "as",\n "pieces"\n ])\n ),\n cut: _ReposSkin.#jobOf(\n "cut",\n _ReposSkin.#object({ as: _ReposSkin.#some, scope: _ReposSkin.#scopeSchema, tag: _ReposSkin.#some })\n ),\n land: _ReposSkin.#jobOf("land", _ReposSkin.#object({ as: _ReposSkin.#some })),\n conform: _ReposSkin.#jobOf(\n "conform",\n _ReposSkin.#object(\n {\n as: _ReposSkin.#some,\n head: _ReposSkin.#some,\n parts: _ReposSkin.#some,\n scoped: { type: "boolean" },\n script: _ReposSkin.#some\n },\n ["as", "head", "parts"]\n )\n ),\n clear: _ReposSkin.#jobOf("clear", _ReposSkin.#object({ as: _ReposSkin.#some })),\n check: _ReposSkin.#writing(\n "check",\n _ReposSkin.#none,\n _ReposSkin.#object({\n doing: _ReposSkin.#maybe,\n lost: { type: "array", items: _ReposSkin.#some }\n })\n ),\n scan: _ReposSkin.#jobOf("scan", _ReposSkin.#none),\n build: _ReposSkin.#jobOf("build", _ReposSkin.#object({ organ: _ReposSkin.#some })),\n look: _ReposSkin.#jobOf("look", _ReposSkin.#object({ design: _ReposSkin.#some })),\n stop: _ReposSkin.#writing("stop", _ReposSkin.#object({ folder: _ReposSkin.#named }, [])),\n ended: { ..._ReposSkin.#writing("ended"), askers: ["shell"] },\n back: { ..._ReposSkin.#writing("back"), askers: ["brain"] },\n jobs: _ReposSkin.#reading("jobs"),\n job: _ReposSkin.#reading("job", _ReposSkin.#jobSchema)\n },\n placeholders: { shell: "nervur.shell", disk: "nervur.disk" }\n };\n static #fields(data) {\n return !!data && typeof data === "object" && !Array.isArray(data) && !ArrayBuffer.isView(data);\n }\n static #text(data) {\n return typeof data === "string" && data !== "";\n }\n static #count(data, most) {\n return typeof data === "number" && Number.isSafeInteger(data) && data >= 1 && data <= most;\n }\n static #arg(args, key) {\n return _ReposSkin.#fields(args) ? args[key] : void 0;\n }\n static #names(path) {\n if (path === void 0 || path === "") return [];\n if (typeof path !== "string") return null;\n const names = path.split("/");\n return names.every((name) => _ReposSkin.#name.test(name)) ? names : null;\n }\n static #paths(paths) {\n return Array.isArray(paths) && paths.length >= 1 && paths.every((path) => typeof path === "string" && path !== "" && _ReposSkin.#names(path) !== null);\n }\n static #scopeOf(scope) {\n if (!Array.isArray(scope) || scope.length < 1 || scope.length > SCOPE_MOST) return null;\n const folders = scope.flatMap((one) => typeof one === "string" ? [one] : []);\n const fit = (one) => one.split("/").every((name) => _ReposSkin.#segment.test(name) && ![".", "..", ".git"].includes(name));\n if (folders.length !== scope.length || !folders.every(fit)) return null;\n const sorted = folders.toSorted();\n const nested = sorted.some(\n (one, at) => sorted.some((other, by) => by !== at && (one === other || one.startsWith(`${other}/`)))\n );\n return nested ? null : sorted;\n }\n static #lone = /[\\uD800-\\uDBFF](?![\\uDC00-\\uDFFF])|(?<![\\uD800-\\uDBFF])[\\uDC00-\\uDFFF]/g;\n #bytes(text) {\n const encoded = this.codec.utf8(text.replace(_ReposSkin.#lone, "�"));\n return "bytes" in encoded ? encoded.bytes : null;\n }\n #textOf(bytes) {\n const decoded = this.codec.utf8Text(bytes);\n return "text" in decoded ? decoded.text : null;\n }\n #linesOf(set) {\n if (!_ReposSkin.#fields(set)) return null;\n const entries = Object.entries(set);\n if (entries.length > this.#most()) return null;\n for (const [key, value] of entries)\n if (!_ReposSkin.#key.test(key) || typeof value !== "string" || !_ReposSkin.#line.test(value)) return null;\n return set;\n }\n static #argsOf(args) {\n if (args === void 0) return [];\n if (!Array.isArray(args) || args.length > ARGS_MOST) return null;\n const all = args.flatMap(\n (one) => typeof one === "string" && one.length <= ARG_LONGEST && !one.includes("\\0") ? [one] : []\n );\n return all.length === args.length ? all : null;\n }\n #heard(answer) {\n return "error" in answer ? this.error(answer.error.code, answer.error.message) : null;\n }\n #nonce() {\n return Array.from(this.stamp.seed.slice(0, 16), (byte) => byte.toString(16).padStart(2, "0")).join("");\n }\n #at() {\n const setup = this.cells.get(["setup"]);\n if (!_ReposSkin.#fields(setup) || setup["ready"] !== true) return null;\n return _ReposSkin.#text(setup["at"]) ? setup["at"] : null;\n }\n #most() {\n return Math.min(CELLS_RANGE, Math.floor(this.memory / LOBE_SHARE / ITEM_SIZE));\n }\n #all(prefix) {\n return this.cells.range({ prefix, limit: this.#most() }).cells;\n }\n async setup(args) {\n if (this.stamp.asker !== _ReposSkin.#owner) return this.error("refused", "setup is an owner\'s");\n const at = _ReposSkin.#arg(args, "at");\n if (!_ReposSkin.#text(at) || !at.startsWith("/"))\n return this.error("refused", "at is where the disk\'s folder stands, from the root");\n const held = await this.#unstuck(["setup"]);\n if (_ReposSkin.#fields(held) && _ReposSkin.#text(held["doing"]))\n return this.error("refused", "the setup runs already");\n const nonce = this.#nonce();\n const path = [_ReposSkin.#repos, _ReposSkin.#marker];\n const wrote = await this.ask("disk", "write", { path, bytes: this.#bytes(nonce) });\n if ("error" in wrote) return this.#heard(wrote);\n this.cells.set(["setup"], { at, ..._ReposSkin.#unready });\n return this.#begin("setup", null, [at], `${nonce}\n`);\n }\n async grant(args) {\n const delegate = this.#delegate();\n if (this.stamp.asker !== _ReposSkin.#owner && delegate === null)\n return this.error("refused", "grant is an owner\'s or a delegate\'s");\n const folder = _ReposSkin.#arg(args, "folder");\n const lobe = _ReposSkin.#arg(args, "lobe");\n if (!_ReposSkin.#text(folder) || !_ReposSkin.#folderName.test(folder))\n return this.error("refused", "a folder is a repo’s name, lowercase, a letter first");\n if (this.#at() === null) return this.error("refused", "the disk\'s folder is not set up");\n const held = this.cells.get(["folder", folder]);\n const free = _ReposSkin.#fields(held) && !_ReposSkin.#text(held["lobe"]);\n if (delegate !== null && _ReposSkin.#fields(held) && held["by"] !== delegate && (!free || lobe === null))\n return this.error("refused", `the folder ${folder} is none the delegate granted, and a lobe holds it`);\n const kept = _ReposSkin.#fields(held) ? { ...held, ...delegate === null ? {} : { by: delegate } } : { lobe: null, doing: null, made: false, ...delegate === null ? {} : { by: delegate } };\n if (lobe === null) {\n if (!_ReposSkin.#fields(held)) return this.error("absent", `no folder ${folder}`);\n this.cells.set(["folder", folder], { ...held, lobe: null });\n if (_ReposSkin.#text(held["lobe"])) await this.#release(held["lobe"], folder);\n return null;\n }\n if (!_ReposSkin.#text(lobe) || [_ReposSkin.#owner, "shell", "disk"].includes(lobe))\n return this.error("refused", "a grant names a repo lobe, or null for none");\n const holds = this.cells.get(["lobe", lobe]);\n if (typeof holds === "string" && holds !== folder)\n return this.error("refused", `the lobe ${lobe} holds the folder ${holds} already`);\n const met = _ReposSkin.#fields(held) ? null : await this.#folded(folder);\n if (met !== null) return met;\n const was = _ReposSkin.#fields(held) ? held["lobe"] : null;\n this.cells.set(["lobe", lobe], folder);\n this.cells.set(["folder", folder], { ...kept, lobe });\n if (_ReposSkin.#text(was) && was !== lobe) await this.#release(was, folder);\n return null;\n }\n async delegate(args) {\n if (this.stamp.asker !== _ReposSkin.#owner) return this.error("refused", "delegate is an owner\'s");\n const lobe = _ReposSkin.#arg(args, "lobe");\n if (!_ReposSkin.#text(lobe) || [_ReposSkin.#owner, "shell", "disk"].includes(lobe))\n return this.error("refused", "a delegate is a lobe");\n if (_ReposSkin.#arg(args, "given") === false) this.cells.delete(["delegate", lobe]);\n else this.cells.set(["delegate", lobe], true);\n return null;\n }\n #delegate() {\n const { asker } = this.stamp;\n return asker !== _ReposSkin.#owner && this.cells.get(["delegate", asker]) === true ? asker : null;\n }\n async #release(lobe, folder) {\n this.cells.delete(["lobe", lobe]);\n const at = this.#at();\n if (at === null) return;\n const program = [..._ReposSkin.programs.clear, at, lobe];\n const begun = await this.ask("shell", "run", { program, input: "" });\n const run = "result" in begun ? _ReposSkin.#arg(begun.result, "run") : void 0;\n if (!_ReposSkin.#text(run)) return;\n const { asker } = this.stamp;\n this.cells.set(["job", run], { job: run, kind: "clear", asker, folder, ended: null });\n this.cells.set(["by", asker, run], null);\n this.cells.set(["clearing", lobe, "*"], { run });\n }\n static #ends(read) {\n const all = _ReposSkin.#fields(read) && Array.isArray(read["result"]) ? read["result"] : [];\n return new Set(all.map((wire) => _ReposSkin.#arg(wire, "termination")));\n }\n async #torn(read) {\n const ends = _ReposSkin.#ends(read);\n for (const { key, value } of this.#all(["lobe"])) {\n const lobe = key[1];\n if (!_ReposSkin.#text(lobe) || ends.has(lobe) || !_ReposSkin.#text(value)) continue;\n if (this.#all(["by", lobe]).length === 0) continue;\n const held = this.cells.get(["folder", value]);\n if (_ReposSkin.#fields(held) && held["lobe"] === lobe) this.cells.set(["folder", value], { ...held, lobe: null });\n this.cells.delete(["last", lobe]);\n await this.#release(lobe, value);\n }\n }\n async #lostOf(jobs) {\n const asked = await this.ask("shell", "going", {});\n const named = "result" in asked ? _ReposSkin.#arg(asked.result, "runs") : void 0;\n if (!Array.isArray(named)) return null;\n const going = new Set(named);\n return jobs.filter((job) => !going.has(job));\n }\n async #unstuck(key) {\n const record = this.cells.get([...key]);\n const doing = _ReposSkin.#arg(record ?? null, "doing");\n if (!_ReposSkin.#text(doing)) return record;\n const lost = await this.#lostOf([doing]);\n if (lost === null || lost.length === 0) return record;\n await this.#end(doing, -1, "", _ReposSkin.#lost);\n return this.cells.get([...key]);\n }\n async check() {\n const own = this.#own();\n if (!("folder" in own)) return own;\n const doing = own.held["doing"];\n const clears = this.#all(["clearing", this.stamp.asker]).flatMap(({ value }) => {\n const run = _ReposSkin.#arg(value, "run");\n return _ReposSkin.#text(run) ? [run] : [];\n });\n const runs = [..._ReposSkin.#text(doing) ? [doing] : [], ...clears];\n const lost = runs.length === 0 ? [] : await this.#lostOf(runs) ?? [];\n for (const run of lost) await this.#end(run, -1, "", _ReposSkin.#lost);\n const after = this.cells.get(["folder", own.folder]);\n const last = this.cells.get(["last", this.stamp.asker]) ?? null;\n return { doing: _ReposSkin.#arg(after ?? null, "doing") ?? null, lost: [...lost], last };\n }\n async #folded(folder) {\n const listed = await this.ask("disk", "list", { path: [_ReposSkin.#repos] });\n if ("error" in listed)\n return listed.error.code === "absent" ? null : this.error("refused", `repos/ is not listed: ${listed.error.message}`);\n const names = _ReposSkin.#arg(listed.result, "names");\n const lower = folder.toLowerCase();\n const met = Array.isArray(names) ? names.find((name) => typeof name === "string" && name !== folder && name.toLowerCase() === lower) : void 0;\n return typeof met === "string" ? this.error("refused", `the folder ${folder} meets ${met}, which repos/ holds in another case`) : null;\n }\n folders() {\n const delegate = this.#delegate();\n if (this.stamp.asker !== _ReposSkin.#owner && delegate === null)\n return this.error("refused", "folders is an owner\'s or a delegate\'s");\n const seen = this.#all(["folder"]).filter(\n ({ value }) => delegate === null || _ReposSkin.#fields(value) && (value["by"] === delegate || !_ReposSkin.#text(value["lobe"]))\n );\n return seen.map(({ key, value }) => ({\n folder: key[1] ?? null,\n ..._ReposSkin.#fields(value) ? value : {}\n }));\n }\n async remove(args) {\n const delegate = this.#delegate();\n if (this.stamp.asker !== _ReposSkin.#owner && delegate === null)\n return this.error("refused", "remove is an owner\'s or a delegate\'s");\n const folder = _ReposSkin.#arg(args, "folder");\n const erase = _ReposSkin.#arg(args, "erase") ?? false;\n if (typeof erase !== "boolean") return this.error("refused", "erase is true or false");\n if (!_ReposSkin.#text(folder) || !_ReposSkin.#fields(this.cells.get(["folder", folder])))\n return this.error("absent", "no such folder");\n const held = await this.#unstuck(["folder", folder]);\n if (!_ReposSkin.#fields(held)) return this.error("absent", "no such folder");\n if (delegate !== null && held["by"] !== delegate)\n return this.error("refused", `the folder ${folder} is none the delegate granted`);\n const doing = held["doing"];\n if (_ReposSkin.#text(doing)) return this.error("refused", `the folder ${folder} runs ${doing}: wait for it to end`);\n if (erase) return this.#erasing(folder, held);\n this.cells.delete(["folder", folder]);\n if (_ReposSkin.#text(held["lobe"])) await this.#release(held["lobe"], folder);\n return null;\n }\n async #erasing(folder, held) {\n const at = this.#at();\n if (at === null) return this.error("refused", "the disk\'s folder is not set up");\n if (!_ReposSkin.#folderName.test(folder)) return this.error("refused", "a folder is a repo’s name");\n const lobe = _ReposSkin.#text(held["lobe"]) ? held["lobe"] : "";\n if (lobe !== "") this.cells.delete(["lobe", lobe]);\n this.cells.set(["folder", folder], { ...held, lobe: null });\n return this.#begin("remove", folder, [at, folder, lobe], "");\n }\n async state() {\n if (this.stamp.asker === _ReposSkin.#owner) return this.cells.get(["setup"]) ?? null;\n const own = this.#own();\n if (!("folder" in own)) return own;\n const at = this.#at();\n const listed = own.held["made"] === true ? await this.ask("disk", "list", { path: [_ReposSkin.#repos] }) : null;\n const names = listed !== null && "result" in listed ? _ReposSkin.#arg(listed.result, "names") : void 0;\n const made = Array.isArray(names) && names.includes(own.folder);\n return {\n folder: at === null ? null : `${at}/${_ReposSkin.#repos}/${own.folder}`,\n made,\n doing: own.held["doing"] ?? null\n };\n }\n #own() {\n const { asker } = this.stamp;\n const folder = this.cells.get(["lobe", asker]);\n const held = typeof folder === "string" ? this.cells.get(["folder", folder]) : void 0;\n if (typeof folder !== "string" || !_ReposSkin.#fields(held))\n return this.error("refused", `the lobe ${asker} is granted no folder`);\n return { folder, held };\n }\n async #readMany(args, paths) {\n if (_ReposSkin.#arg(args, "path") !== void 0 || _ReposSkin.#arg(args, "first") !== void 0)\n return this.error("refused", "paths come alone, without path or first");\n if (!Array.isArray(paths) || paths.length === 0) return this.error("refused", "paths are one file or more");\n const named = paths.flatMap((one) => _ReposSkin.#text(one) && _ReposSkin.#names(one) !== null ? [one] : []);\n if (named.length !== paths.length)\n return this.error("refused", "a path is names under the repo, none empty, climbing or reaching .git");\n const reads = await Promise.all(named.map((path) => this.#disk("read", path)));\n const files = [];\n let weight = 0;\n for (const [at, read] of reads.entries()) {\n const path = named[at] ?? "";\n if (!("result" in read)) {\n if ("code" in read && read.code === "absent") files.push({ path, absent: true });\n else return read;\n continue;\n }\n const bytes = _ReposSkin.#arg(read.result, "bytes");\n const text = bytes instanceof Uint8Array ? this.#textOf(bytes) : null;\n if (!(bytes instanceof Uint8Array) || text === null) return this.error("refused", `${path} is not UTF-8 text`);\n weight += bytes.length;\n if (weight > this.memory / LOBE_SHARE)\n return this.error(\n "refused",\n `the files weigh past ${Math.floor(this.memory / LOBE_SHARE)} bytes, what one answer of this lobe carries`\n );\n files.push({ path, text });\n }\n return { files };\n }\n async read(args) {\n const paths = _ReposSkin.#arg(args, "paths");\n if (paths !== void 0) return this.#readMany(args, paths);\n const first = _ReposSkin.#arg(args, "first");\n if (first !== void 0 && !_ReposSkin.#count(first, Number.MAX_SAFE_INTEGER))\n return this.error("refused", "first is how many lines, one or more");\n const read = await this.#disk("read", _ReposSkin.#arg(args, "path"));\n if (!("result" in read)) return read;\n const bytes = _ReposSkin.#arg(read.result, "bytes");\n const text = bytes instanceof Uint8Array ? this.#textOf(bytes) : null;\n if (text === null) return this.error("refused", "the file is not UTF-8 text");\n const lines = text.split("\\n");\n return {\n text: first === void 0 ? text : lines.slice(0, first).join("\\n"),\n lines: lines.length\n };\n }\n async bytes(args) {\n const own = this.#own();\n if (!("folder" in own)) return own;\n const sha = _ReposSkin.#arg(args, "sha");\n if (!_ReposSkin.#text(sha) || !_ReposSkin.#sha.test(sha))\n return this.error("refused", "a kept file is named by its SHA-256, in lowercase hex");\n const read = await this.ask("disk", "read", {\n path: [_ReposSkin.#transfers, this.stamp.asker, _ReposSkin.#kept, sha]\n });\n if ("error" in read) return this.error(read.error.code, read.error.message);\n const bytes = _ReposSkin.#arg(read.result, "bytes");\n return bytes instanceof Uint8Array ? { bytes } : this.error("refused", "the disk answered no bytes");\n }\n async write(args) {\n const text = _ReposSkin.#arg(args, "text");\n if (typeof text !== "string") return this.error("refused", "a write holds its text");\n const bytes = this.#bytes(text);\n if (bytes === null) return this.error("refused", "the text has no UTF-8");\n const wrote = await this.#disk("write", _ReposSkin.#arg(args, "path"), bytes);\n return "result" in wrote ? wrote.result : wrote;\n }\n async erase(args) {\n const erased = await this.#disk("remove", _ReposSkin.#arg(args, "path"));\n return "result" in erased ? erased.result : erased;\n }\n async list(args) {\n const path = _ReposSkin.#arg(args, "path");\n const listed = await this.#disk("list", path);\n const root = _ReposSkin.#names(path)?.length === 0;\n if (root && "code" in listed && listed.code === "absent") return { names: [] };\n return "result" in listed ? listed.result : listed;\n }\n async #disk(method, path, bytes) {\n const own = this.#own();\n if (!("folder" in own)) return own;\n const names = _ReposSkin.#names(path);\n if (names === null || names.length === 0 && method !== "list")\n return this.error("refused", "a path is names under the repo, none empty, climbing or reaching .git");\n if (method !== "list" && names.join("/").toLowerCase() === _ReposSkin.#env)\n return this.error("refused", `${names.join("/")} is a secret file, written by secrets alone and read by no one`);\n const at = [_ReposSkin.#repos, own.folder, ...names];\n const answer = await this.ask("disk", method, bytes === void 0 ? { path: at } : { path: at, bytes });\n return "error" in answer ? this.error(answer.error.code, answer.error.message) : answer;\n }\n async piece(args) {\n const path = await this.#piecePath(args);\n if (!Array.isArray(path)) return path;\n const read = await this.ask("disk", "read", { path });\n if ("error" in read) return this.#heard(read);\n return { bytes: _ReposSkin.#arg(read.result, "bytes") ?? null };\n }\n async put(args) {\n const path = await this.#piecePath(args);\n if (!Array.isArray(path)) return path;\n const pieces = _ReposSkin.#arg(args, "pieces");\n const at = _ReposSkin.#arg(args, "at");\n const bytes = _ReposSkin.#arg(args, "bytes");\n if (typeof pieces !== "number" || typeof at !== "number" || at >= pieces)\n return this.error("refused", "a piece stands before the count of its pieces");\n if (!(bytes instanceof Uint8Array)) return this.error("refused", "a piece holds its bytes");\n const wrote = await this.ask("disk", "write", { path, bytes });\n return this.#heard(wrote);\n }\n async #piecePath(args) {\n const own = this.#own();\n if (!("folder" in own)) return own;\n const at = _ReposSkin.#arg(args, "at");\n const as = _ReposSkin.#arg(args, "as");\n if (typeof at !== "number" || !Number.isSafeInteger(at) || at < 0)\n return this.error("refused", "a piece stands at a place, from 0");\n if (!_ReposSkin.#text(as) || !_ReposSkin.#as.test(as))\n return this.error("refused", "a bundle waits as push, pull, out-<far> or in-<far>");\n const clearing = await this.#clearing(as);\n if (clearing !== null) return clearing;\n return [_ReposSkin.#transfers, this.stamp.asker, as, `q${at}`];\n }\n async #clearing(as) {\n const runs = [as, "*"].flatMap((name) => {\n const run = _ReposSkin.#arg(this.cells.get(["clearing", this.stamp.asker, name]) ?? null, "run");\n return _ReposSkin.#text(run) ? [run] : [];\n });\n if (runs.length === 0) return null;\n const lost = await this.#lostOf(runs) ?? [];\n for (const run of lost) await this.#end(run, -1, "", _ReposSkin.#lost);\n return runs.every((run) => lost.includes(run)) ? null : this.error("refused", `the pieces of ${as} are being cleared`);\n }\n async clear(args) {\n const as = _ReposSkin.#arg(args, "as");\n if (!_ReposSkin.#text(as) || !_ReposSkin.#as.test(as))\n return this.error("refused", "a bundle waits as push, pull, out-<far> or in-<far>");\n const own = this.#own();\n if (!("folder" in own)) return own;\n const at = this.#at();\n if (at === null) return this.error("refused", "the disk\'s folder is not set up");\n const { asker } = this.stamp;\n const clearing = await this.#clearing(as);\n if (clearing !== null) return clearing;\n const program = [..._ReposSkin.programs.clear, at, asker, as];\n const begun = await this.ask("shell", "run", { program, input: "" });\n if ("error" in begun) return this.error(begun.error.code, begun.error.message);\n const run = _ReposSkin.#arg(begun.result, "run");\n if (!_ReposSkin.#text(run)) return this.error("refused", "the shell named no run");\n this.cells.set(["job", run], {\n job: run,\n kind: "clear",\n asker,\n folder: own.folder,\n ended: null\n });\n this.cells.set(["by", asker, run], null);\n this.cells.set(["clearing", asker, as], { run });\n return { job: run };\n }\n #transfer(as) {\n return `${this.#at() ?? ""}/${_ReposSkin.#transfers}/${this.stamp.asker}/${as}`;\n }\n async init(args) {\n const unchecked = this.checked("init", args);\n if (unchecked !== void 0) return unchecked;\n const own = this.#own();\n const at = this.#at();\n if (!("folder" in own)) return own;\n if (at === null) return this.error("refused", "the disk\'s folder is not set up");\n const held = await this.#unstuck(["folder", own.folder]);\n const doing = _ReposSkin.#arg(held ?? null, "doing");\n if (_ReposSkin.#text(doing)) return this.error("refused", `${own.folder} runs ${doing} already`);\n const nonce = this.#nonce();\n const path = [_ReposSkin.#repos, own.folder, _ReposSkin.#marker];\n const wrote = await this.ask("disk", "write", { path, bytes: this.#bytes(nonce) });\n if ("error" in wrote) return this.#heard(wrote);\n return this.#begin("init", own.folder, [at, own.folder], `${nonce}\n`);\n }\n stand(args) {\n const checks = _ReposSkin.#checksOf(args);\n if (checks === null) return Promise.resolve(this.error("refused", "a stand names the check of the parts"));\n return this.#job("stand", [], JSON.stringify(checks));\n }\n head(args) {\n const contains = _ReposSkin.#arg(args, "contains");\n if (contains !== void 0 && !(_ReposSkin.#text(contains) && _ReposSkin.#hash.test(contains)))\n return Promise.resolve(this.error("refused", "contains is a commit"));\n return this.#job("head", typeof contains === "string" ? [contains] : [], "");\n }\n status() {\n return this.#job("status", [], "");\n }\n commit(args) {\n const message = _ReposSkin.#arg(args, "message");\n if (!_ReposSkin.#text(message)) return Promise.resolve(this.error("refused", "a commit holds its message"));\n const checks = _ReposSkin.#checksOf(args);\n if (checks === null) return Promise.resolve(this.error("refused", "a commit names the check of the parts"));\n const own = this.#own();\n if (!("folder" in own)) return Promise.resolve(own);\n const executable = _ReposSkin.#arg(args, "executable");\n const paths = _ReposSkin.#arg(args, "paths");\n if (paths !== void 0 && !_ReposSkin.#paths(paths))\n return Promise.resolve(\n this.error("refused", "a commit takes paths of the repo, each a file or a folder under it")\n );\n const input = JSON.stringify({\n ...checks,\n message,\n ...executable === void 0 ? {} : { executable },\n ...paths === void 0 ? {} : { paths }\n });\n return this.#job("commit", [], input);\n }\n static #checksOf(args) {\n const { parts, conform, scoped } = _ReposSkin.#fields(args) ? args : {};\n if (!_ReposSkin.#text(parts)) return null;\n if (conform !== void 0 && !(_ReposSkin.#text(conform) && _ReposSkin.#hash.test(conform))) return null;\n if (scoped !== void 0 && typeof scoped !== "boolean") return null;\n return { parts, ...conform === void 0 ? {} : { conform }, ...scoped === true ? { scoped } : {} };\n }\n discard() {\n return this.#job("discard", [], "");\n }\n log(args) {\n const most = _ReposSkin.#arg(args, "most") ?? _ReposSkin.#logs;\n if (!_ReposSkin.#count(most, this.#most()))\n return Promise.resolve(this.error("refused", `most is how many commits, one to ${this.#most()}`));\n return this.#job("log", [String(most)], "");\n }\n run(args) {\n const script = _ReposSkin.#arg(args, "script");\n const install = _ReposSkin.#arg(args, "install") ?? false;\n const words = _ReposSkin.#argsOf(_ReposSkin.#arg(args, "args"));\n if (!_ReposSkin.#text(script) || !_ReposSkin.#script.test(script))\n return Promise.resolve(this.error("refused", "a run names a script of the repo\'s package"));\n if (typeof install !== "boolean") return Promise.resolve(this.error("refused", "install is true or false"));\n const gate = _ReposSkin.#arg(args, "gate") ?? false;\n if (typeof gate !== "boolean") return Promise.resolve(this.error("refused", "gate is true or false"));\n if (words === null)\n return Promise.resolve(this.error("refused", `a run\'s args are texts, at most ${ARGS_MOST}, none holding a NUL`));\n return this.#job("run", [script, install ? "install" : "", gate ? "gate" : "", ...words], "");\n }\n secrets(args) {\n const set = this.#linesOf(_ReposSkin.#arg(args, "set"));\n if (set === null)\n return Promise.resolve(\n this.error("refused", "a secret file\'s lines are each an environment variable\'s name and a value of one line")\n );\n const own = this.#own();\n if (!("folder" in own)) return Promise.resolve(own);\n return this.#job("secrets", [], JSON.stringify({ set }));\n }\n async bundle(args) {\n const since = _ReposSkin.#arg(args, "since") ?? null;\n const as = _ReposSkin.#arg(args, "as");\n if (since !== null && !(_ReposSkin.#text(since) && _ReposSkin.#hash.test(since)))\n return this.error("refused", "since is a commit, or null");\n if (!_ReposSkin.#text(as) || !_ReposSkin.#as.test(as))\n return this.error("refused", "a bundle waits as push, pull, out-<far> or in-<far>");\n const cut = _ReposSkin.#arg(args, "cut") ?? false;\n if (typeof cut !== "boolean") return this.error("refused", "cut is true or false");\n const tag = _ReposSkin.#arg(args, "tag");\n if (tag !== void 0 && !(_ReposSkin.#text(tag) && _ReposSkin.#tag.test(tag)))\n return this.error("refused", "a tag is v and three whole numbers");\n if (cut && tag !== void 0) return this.error("refused", "a cut is bundled by no tag");\n const clearing = await this.#clearing(as);\n if (clearing !== null) return clearing;\n const most = Math.floor(this.memory / LOBE_SHARE);\n const piece = _ReposSkin.#arg(args, "piece") ?? _ReposSkin.#box;\n if (!_ReposSkin.#count(piece, most))\n return this.error("refused", `a piece is a whole number of bytes, one to ${most}`);\n const words = [cut ? `refs/nervur/cut-${as}` : "", typeof tag === "string" ? tag : "", String(piece)];\n return this.#job("bundle", [this.#transfer(as), since ?? "", ...words], "");\n }\n cut(args) {\n const as = _ReposSkin.#arg(args, "as");\n const tag = _ReposSkin.#arg(args, "tag");\n if (tag !== void 0 && !(_ReposSkin.#text(tag) && _ReposSkin.#tag.test(tag)))\n return Promise.resolve(this.error("refused", "a tag is v and three whole numbers"));\n const scope = _ReposSkin.#scopeOf(_ReposSkin.#arg(args, "scope"));\n if (!_ReposSkin.#text(as) || !_ReposSkin.#as.test(as))\n return Promise.resolve(this.error("refused", "a cut is named as push, pull, out-<far> or in-<far>"));\n if (scope === null)\n return Promise.resolve(\n this.error("refused", `a scope is 1 to ${SCOPE_MOST} folders of the repo, none inside another`)\n );\n return this.#job("cut", [as, typeof tag === "string" ? tag : "", ...scope], "");\n }\n async bring(args) {\n const as = _ReposSkin.#arg(args, "as");\n const pieces = _ReposSkin.#arg(args, "pieces");\n if (!_ReposSkin.#text(as) || !_ReposSkin.#as.test(as) || !_ReposSkin.#count(pieces, Number.MAX_SAFE_INTEGER))\n return this.error("refused", "a bundle names where it waits and its pieces");\n const scoped = _ReposSkin.#arg(args, "scope");\n const scope = scoped === void 0 ? [] : _ReposSkin.#scopeOf(scoped);\n if (scope === null)\n return this.error("refused", `a scope is 1 to ${SCOPE_MOST} folders of the repo, none inside another`);\n const clearing = await this.#clearing(as);\n if (clearing !== null) return clearing;\n return this.#job(scope.length === 0 ? "bring" : "graft", [this.#transfer(as), String(pieces), as, ...scope], "");\n }\n land(args) {\n const as = _ReposSkin.#arg(args, "as");\n if (!_ReposSkin.#text(as) || !_ReposSkin.#as.test(as))\n return Promise.resolve(this.error("refused", "a landing names what waits, as push, pull, out-<far> or in-<far>"));\n return this.#job("land", [as], "");\n }\n conform(args) {\n const { as, head, script } = _ReposSkin.#fields(args) ? args : {};\n if (!_ReposSkin.#text(as) || !_ReposSkin.#as.test(as) || !_ReposSkin.#text(head) || !_ReposSkin.#hash.test(head))\n return Promise.resolve(\n this.error("refused", "a conform names what waits, as push, pull, out-<far> or in-<far>, and its head")\n );\n if (script !== void 0 && !(_ReposSkin.#text(script) && _ReposSkin.#script.test(script)))\n return Promise.resolve(this.error("refused", "a gate is a script of the repo\'s package"));\n const checks = _ReposSkin.#checksOf(args);\n if (checks === null) return Promise.resolve(this.error("refused", "a conform names the check of the parts"));\n const words = typeof script === "string" ? [as, head, script] : [as, head];\n return this.#job("conform", words, JSON.stringify(checks));\n }\n scan() {\n return this.#job("scan", [this.#transfer(_ReposSkin.#kept)], "");\n }\n build(args) {\n const organ = _ReposSkin.#arg(args, "organ");\n if (!_ReposSkin.#text(organ) || organ.length > 64 || !_ReposSkin.#organ.test(organ))\n return Promise.resolve(this.error("refused", "an organ is named by its fixed ID"));\n return this.#job("build", [organ], "");\n }\n look(args) {\n const design = _ReposSkin.#arg(args, "design");\n if (!_ReposSkin.#text(design) || design.length > 59 || !_ReposSkin.#design.test(design))\n return Promise.resolve(this.error("refused", "a design is named by its folder"));\n return this.#job("look", [design], "");\n }\n async stop(args) {\n const named = _ReposSkin.#arg(args, "folder");\n const owner = this.stamp.asker === _ReposSkin.#owner;\n if (!owner && named !== void 0) return this.error("refused", "a repo lobe reaches its own folder alone");\n const folder = owner ? named : this.cells.get(["lobe", this.stamp.asker]);\n const held = _ReposSkin.#text(folder) ? this.cells.get(["folder", folder]) : void 0;\n if (!_ReposSkin.#text(folder) || !_ReposSkin.#fields(held)) return this.error("refused", "no such folder");\n const doing = held["doing"];\n if (!_ReposSkin.#text(doing)) return this.error("refused", `the folder ${folder} runs nothing`);\n const asker = _ReposSkin.#arg(this.cells.get(["job", doing]) ?? null, "asker");\n if (!owner && asker !== this.stamp.asker)\n return this.error("refused", `the folder ${folder} runs another lobe\'s job`);\n const stopped = await this.ask("shell", "stop", { run: doing });\n if (!("error" in stopped)) return null;\n if (stopped.error.code !== "refused") return this.#heard(stopped);\n return this.#end(doing, -1, "", _ReposSkin.#lost);\n }\n async back(args) {\n if (this.stamp.asker !== _ReposSkin.#owner || _ReposSkin.#arg(args, "placeholder") !== "shell") return null;\n const going = [\n ...[this.cells.get(["setup"]), ...this.#all(["folder"]).map(({ value }) => value)].map(\n (held) => _ReposSkin.#arg(held ?? null, "doing")\n ),\n ...this.#all(["clearing"]).map(({ value }) => _ReposSkin.#arg(value, "run"))\n ].filter((run) => _ReposSkin.#text(run));\n const lost = going.length === 0 ? [] : await this.#lostOf(going) ?? [];\n for (const run of lost) await this.#end(run, -1, "", _ReposSkin.#lost);\n return null;\n }\n async ended(args) {\n const read = await this.nerves.read();\n await this.#torn(read);\n const { run, code, out, err } = _ReposSkin.#fields(args) ? args : {};\n const whole = typeof out === "string" && typeof err === "string" && typeof code === "number";\n if (!whole || !_ReposSkin.#text(run))\n return this.error("refused", "an end names its run, its exit code and its output");\n return this.#end(run, code, out, err, read);\n }\n async #end(job, code, out, err, read) {\n const run = job;\n const held = this.cells.get(["job", run]);\n if (!_ReposSkin.#fields(held) || held["ended"] !== null) return this.error("refused", "no such job going");\n this.cells.set(["job", run], { ...held, ended: { code } });\n const { asker, kind, folder } = held;\n if (kind === "clear") return this.#cleared(run);\n this.#settled(kind, folder, code);\n if (!_ReposSkin.#text(asker) || asker === _ReposSkin.#owner) return null;\n if (!_ReposSkin.#ends(read ?? await this.nerves.read()).has(asker)) return null;\n const told = { job: run, kind: kind ?? null, code, out, err };\n this.cells.set(["last", asker], told);\n const letter = { lives: _ReposSkin.#lives };\n return this.#heard(await this.ask(asker, "done", told, void 0, { letter }));\n }\n #cleared(run) {\n for (const { key, value } of this.#all(["clearing"]))\n if (_ReposSkin.#arg(value, "run") === run) this.cells.delete(key);\n return null;\n }\n #settled(kind, folder, code) {\n if (kind === "setup") {\n const setup = this.cells.get(["setup"]);\n const failed = code === 0 ? null : "the marker was not read back";\n if (_ReposSkin.#fields(setup)) this.cells.set(["setup"], { ...setup, ready: code === 0, failed, doing: null });\n return;\n }\n const held = _ReposSkin.#text(folder) ? this.cells.get(["folder", folder]) : void 0;\n if (!_ReposSkin.#text(folder) || !_ReposSkin.#fields(held)) return;\n if (kind === "remove" && code === 0) {\n this.cells.delete(["folder", folder]);\n return;\n }\n const proven = (kind === "init" || kind === "stand" || kind === "head") && code === 0 ? { made: true } : {};\n this.cells.set(["folder", folder], { ...held, ...proven, doing: null });\n }\n jobs() {\n const { asker } = this.stamp;\n if (asker === _ReposSkin.#owner) return this.#all(["job"]).map(({ value }) => value);\n return this.#all(["by", asker]).map(({ key }) => this.cells.get(["job", key[2] ?? ""]) ?? null);\n }\n job(args) {\n const run = _ReposSkin.#arg(args, "job");\n if (!_ReposSkin.#text(run)) return this.error("refused", "a job is named by its id");\n const { asker } = this.stamp;\n const held = this.cells.get(["job", run]);\n const owns = asker === _ReposSkin.#owner || this.cells.get(["by", asker, run]) !== void 0;\n if (!owns || !_ReposSkin.#fields(held)) return this.error("absent", "no such job");\n return held;\n }\n async #back(folder) {\n const { asker } = this.stamp;\n if (this.cells.get(["lobe", asker]) !== folder || _ReposSkin.#ends(await this.nerves.read()).has(asker)) return null;\n const ordered = await this.nerves.order({ termination: asker });\n return "error" in ordered ? this.error("refused", `no wire back: ${ordered.error.message}`) : null;\n }\n #job(kind, more, input) {\n const own = this.#own();\n if (!("folder" in own)) return Promise.resolve(own);\n const at = this.#at();\n if (at === null) return Promise.resolve(this.error("refused", "the disk\'s folder is not set up"));\n const dir = `${at}/${_ReposSkin.#repos}/${own.folder}`;\n return this.#begin(kind, own.folder, [dir, ...more], input);\n }\n async #begin(kind, folder, words, input) {\n const record = await this.#unstuck(folder === null ? ["setup"] : ["folder", folder]);\n if (!_ReposSkin.#fields(record)) return this.error("refused", "no such folder");\n if (_ReposSkin.#text(record["doing"]))\n return this.error("refused", `${folder ?? "the setup"} runs ${record["doing"]} already`);\n const { asker } = this.stamp;\n const back = folder === null ? null : await this.#back(folder);\n if (back !== null) return back;\n const program = [..._ReposSkin.programs[kind], ...words];\n const begun = await this.ask("shell", "run", { program, input });\n if ("error" in begun) return this.error(begun.error.code, begun.error.message);\n const run = _ReposSkin.#arg(begun.result, "run");\n if (!_ReposSkin.#text(run)) return this.error("refused", "the shell named no run");\n this.cells.set(["job", run], { job: run, kind, asker, folder, ended: null });\n this.cells.set(["by", asker, run], null);\n this.cells.set(folder === null ? ["setup"] : ["folder", folder], { ...record, doing: run });\n return { job: run };\n }\n};\nexport {\n ReposSkin as default\n};\n';
1239
+ var REPOS_SOURCE = 'import { Faculty } from "nervur:faculty";\n\nvar BOX = 1048576;\nvar LETTER_LIVES = 864e5;\nvar LOBE_SHARE = 4;\nvar ITEM_SIZE = 1024;\nvar CELLS_RANGE = 1e3;\nvar LOGS = 20;\nvar ARG_LONGEST = 4096;\nvar ARGS_MOST = 64;\nvar SCOPE_MOST = 16;\n\nvar ReposSkin = class _ReposSkin extends Faculty {\n static #owner = "brain";\n static #lost = "the shell runs it no more: it was lost, as to a restart of the organ";\n static #box = BOX;\n static #lives = LETTER_LIVES;\n static #logs = LOGS;\n static #repos = "repos";\n static #transfers = "transfers";\n static #marker = "nervur-marker";\n static #env = ".env";\n static #folderName = /^[a-z](?:[a-z0-9-]|\\.(?=[a-z0-9-])){0,63}$/;\n static #name = /^(?!\\.{1,2}$)(?!\\.git$)[^/\\\\\\0]+$/i;\n static #script = /^[A-Za-z0-9][A-Za-z0-9:._-]{0,63}$/;\n static #key = /^[A-Za-z_][A-Za-z0-9_]{0,63}$/;\n static #line = /^[^\\n\\r\\0]*$/;\n static #hash = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/;\n static #sha = /^[0-9a-f]{64}$/;\n static #kept = "kept";\n static #organ = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;\n static #as = /^(?:push|pull|(?:out|in)-[A-Za-z0-9-]{1,64})$/;\n static #tag = /^v(?:0|[1-9][0-9]*)\\.(?:0|[1-9][0-9]*)\\.(?:0|[1-9][0-9]*)$/;\n static #segment = /^[A-Za-z0-9._-]+$/;\n static #design = /^[a-z][a-z0-9]*(?:[.-][a-z0-9]+)*$/;\n static #marked = `IFS= read -r m; [ "$(cat nervur-marker)" = "$m" ] || { echo "the disk\'s folder is not $1" >&2; exit 1; }; rm nervur-marker`;\n static #exact(path, under, name) {\n return `{ [ -d "${path}" ] && [ ! -L "${path}" ] && ls -1A "${under}" | grep -qxF -- "${name}"; } || { echo "the folder ${name} stands not as named under repos" >&2; exit 1; }\n`;\n }\n static #ident = "export GIT_AUTHOR_NAME=Nervur GIT_AUTHOR_EMAIL=nervur@invalid GIT_COMMITTER_NAME=Nervur GIT_COMMITTER_EMAIL=nervur@invalid\\n";\n static #lend(dir) {\n return `if [ -n "\\${NERVUR_GENOME+x}" ]; then { [ -d "$NERVUR_GENOME" ] && [ -r "$NERVUR_GENOME" ] && [ -x "$NERVUR_GENOME" ]; } || { echo "NERVUR_GENOME $NERVUR_GENOME is no folder this account can read" >&2; exit 1; }; mkdir -p "${dir}/node_modules/@nervur.org" && ln -sfn "$NERVUR_GENOME" "${dir}/node_modules/@nervur.org/genome" || exit 1; fi\n`;\n }\n static #in = `${_ReposSkin.#exact("$1", "${1%/*}", "${1##*/}")}cd "$1" || exit 1\nexport GIT_CEILING_DIRECTORIES="\\${1%/*}"\n${_ReposSkin.#ident}`;\n static #keep = `k="$2"; c="$(printf \'\\\\t\')"\n[ -n "$k" ] || { echo "a scan names where it keeps" >&2; exit 1; }\nmkdir -p "$k/.t" "$k/.o" || exit 1\ngit tag --list \'v*\' | grep -E \'^v[0-9]+\\\\.[0-9]+\\\\.[0-9]+$\' | while IFS= read -r g; do [ -e "$k/.t/$g" ] && continue; git -c core.quotePath=false ls-tree -r "$g" -- designs faculties | while IFS="$c" read -r m p; do case "$p" in designs/*|faculties/*/assets/*) ;; *) continue ;; esac; o=\\${m##* }; [ "\\${m#* }" = "blob $o" ] || continue; [ -s "$k/.o/$o" ] && continue; git cat-file blob "$o" | perl -0777 -pe \'s/\\\\r\\\\n?/\\\\n/g unless /\\\\0/\' >"$k/.w" || exit 1; s=$({ sha256sum 2>/dev/null || shasum -a 256; } <"$k/.w" | cut -d " " -f 1); mv -f "$k/.w" "$k/$s" && echo "$s" >"$k/.o/$o" || exit 1; done || exit 1; : >"$k/.t/$g" || exit 1; done || exit 1\n`;\n static #untag = `git for-each-ref --format=\'delete %(refname)\' "$r-tags/" | git update-ref --stdin`;\n static #fetched = `${_ReposSkin.#in}trap \'rm -rf "$2"\' EXIT\nr="refs/nervur/$4"\ngit update-ref -d "$r" 2>/dev/null; git update-ref -d "$r-main" 2>/dev/null; ${_ReposSkin.#untag}\ncd "$2" || exit 1\ni=0; while [ "$i" -lt "$3" ]; do cat "q$i" || exit 1; i=$((i + 1)); done > b || exit 1\ncd "$1" || exit 1\ngit fetch --quiet --no-tags "$2/b" "+main:$r" || exit 1\n`;\n static #tagged = `git fetch --quiet --no-tags "$2/b" "+refs/tags/v*:$r-tags/v*" || exit 1\nw=$(git for-each-ref --format=\'%(objecttype) %(objectname) %(refname)\' "$r-tags/" | while read -r y o n; do n=\\${n#"$r-tags/"}; if [ "$y" != commit ] || ! git merge-base --is-ancestor "$o" "$r" 2>/dev/null; then echo "the tag $n names no commit it brings"; elif e=$(git rev-parse -q --verify "refs/tags/$n^{commit}") && [ "$e" != "$o" ]; then echo "this lobe holds the tag $n on another commit: a version names one commit for ever"; fi; done)\nif [ -n "$w" ]; then git update-ref -d "$r"; ${_ReposSkin.#untag}; echo "$w" >&2; exit 1; fi\n`;\n static #bring = `${_ReposSkin.#fetched}${_ReposSkin.#tagged}c=$(git rev-parse "$r") || exit 1\nif ! h=$(git rev-parse -q --verify HEAD); then m=new\nelif git merge-base --is-ancestor "$c" "$h"; then git update-ref -d "$r"; ${_ReposSkin.#untag}; echo "$h"; echo held; exit 0\nelif git merge-base --is-ancestor "$h" "$c"; then m=forward\nelse t=$(mktemp -d) || exit 1\ngit worktree add --quiet --detach "$t/w" "$h" >/dev/null 2>&1 || exit 1\nif git -C "$t/w" merge --quiet --no-edit "$c" >/dev/null 2>&1; then c=$(git -C "$t/w" rev-parse HEAD); m=merge; else m=; fi\ngit worktree remove --force "$t/w"; rm -rf "$t"\n[ -n "$m" ] || { git update-ref -d "$r"; ${_ReposSkin.#untag}; echo "it meets a conflict with main: merge it where it is authored, and send it again" >&2; exit 1; }\nfi\ngit update-ref "$r-main" "$c" && echo "$c" && echo "$m"`;\n static #cutting = [\n \'const { execFileSync } = require("node:child_process"); const fs = require("node:fs"); const os = require("node:os"); const path = require("node:path");\',\n \'const [as = "", ...scope] = process.argv.slice(1);\',\n \'const git = (args, input, env) => execFileSync("git", args, { input: input === undefined ? "" : input, env: env === undefined ? process.env : env, maxBuffer: 1073741824, stdio: ["pipe", "pipe", "pipe"] });\',\n \'const line = (args) => git(args).toString("utf8").trim();\',\n \'const maybe = (args) => { try { return line(args); } catch { return ""; } };\',\n "const holds = (args) => { try { git(args); return true; } catch { return false; } };",\n \'const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "nervur-cut-")); process.on("exit", () => fs.rmSync(tmp, { recursive: true, force: true }));\',\n \'const index = path.join(tmp, "index");\',\n \'const within = (p) => scope.some((s) => p.startsWith(s + "/"));\',\n \'const entries = (args) => git(["ls-tree", "-r", "-z", ...args]).toString("latin1").split("\\\\0").filter((e) => e !== "");\',\n \'const named = (e) => e.slice(e.indexOf("\\\\t") + 1);\',\n \'const treeOf = (all) => { fs.rmSync(index, { force: true }); const env = { ...process.env, GIT_INDEX_FILE: index }; if (all.length > 0) git(["update-index", "-z", "--index-info"], Buffer.from(all.map((e) => e + "\\\\0").join(""), "latin1"), env); return git(["write-tree"], "", env).toString("utf8").trim(); };\',\n \'const who = (header, role) => { const m = new RegExp("^" + role + " (.*) <([^>\\\\\\\\n]*)> ([0-9]+) ([-+][0-9]{4})$", "m").exec(header); if (m === null) throw new Error("its " + role + " is not as git writes it"); return m; };\',\n \'const kept = (c, tree, parent) => { const raw = git(["cat-file", "commit", c]); const at = raw.indexOf("\\\\n\\\\n"); const header = raw.subarray(0, at < 0 ? raw.length : at).toString("utf8"); const message = at < 0 ? Buffer.alloc(0) : raw.subarray(at + 2); const a = who(header, "author"); const k = who(header, "committer"); const env = { ...process.env, GIT_AUTHOR_NAME: a[1], GIT_AUTHOR_EMAIL: a[2], GIT_AUTHOR_DATE: "@" + a[3] + " " + a[4], GIT_COMMITTER_NAME: k[1], GIT_COMMITTER_EMAIL: k[2], GIT_COMMITTER_DATE: "@" + k[3] + " " + k[4] }; return git(["commit-tree", "--no-gpg-sign", tree, ...(parent === "" ? [] : ["-p", parent])], message, env).toString("utf8").trim(); };\',\n \'const walk = (commits, from) => { const seen = commits.length === 0 ? [] : git(["cat-file", "--batch-check=%(objecttype) %(objectname)"], commits.flatMap((c) => scope.map((s) => c + ":" + s)).join("\\\\n") + "\\\\n").toString("utf8").split("\\\\n"); let { head, last } = from; commits.forEach((c, i) => { const oids = scope.map((s, j) => { const [type = "", oid = ""] = (seen[i * scope.length + j] ?? "").split(" "); return type === "tree" ? oid : "-"; }); const key = oids.join(" "); if (key === last) return; last = key; const trees = scope.filter((s, j) => oids[j] !== "-"); head = kept(c, treeOf(trees.length === 0 ? [] : entries([c, "--", ...trees])), head); }); return { head, last }; };\',\n \'const main = maybe(["rev-parse", "-q", "--verify", "refs/heads/main^{commit}"]);\',\n \'const tag = process.env.NERVUR_CUT_TAG === undefined ? "" : process.env.NERVUR_CUT_TAG;\',\n \'const tagged = tag === "" ? "" : maybe(["rev-parse", "-q", "--verify", "refs/tags/" + tag + "^{commit}"]);\',\n \'if (tag !== "" && tagged === "") { process.stderr.write("this lobe holds no tag " + tag + "\\\\n"); process.exit(1); }\',\n \'const upto = tagged === "" ? null : new Set(line(["rev-list", tagged]).split("\\\\n"));\',\n \'const firsts = (main === "" ? [] : line(["rev-list", "--first-parent", "--reverse", main]).split("\\\\n").filter((c) => c !== "")).filter((c) => upto === null || upto.has(c));\',\n \'const cut = walk(firsts, { head: "", last: scope.map(() => "-").join(" ") });\'\n ].join("\\n");\n static #cut = `${_ReposSkin.#in}a=$2; t=$3; shift 3\nNERVUR_CUT_TAG="$t" node -e \'${_ReposSkin.#cutting}\nif (cut.head === "") maybe(["update-ref", "-d", "refs/nervur/cut-" + as]); else git(["update-ref", "refs/nervur/cut-" + as, cut.head]);\nprocess.stdout.write(cut.head + "\\\\n");\' -- "$a" "$@"`;\n static #graft = `${_ReposSkin.#fetched}a=$4; shift 4\nNERVUR_CUT_TAG= node -e \'${[\n _ReposSkin.#cutting,\n \'const r = "refs/nervur/" + as; const refused = (why) => { maybe(["update-ref", "-d", r]); process.stderr.write(why + "\\\\n"); process.exit(1); };\',\n \'const tip = line(["rev-parse", r]);\',\n \'if (cut.head !== "" && tip === cut.head) { maybe(["update-ref", "-d", r]); process.stdout.write(tip + "\\\\nheld\\\\n"); process.exit(0); }\',\n \'if (cut.head !== "" && !holds(["merge-base", "--is-ancestor", cut.head, tip])) refused("behind the scope\\\\u0027s head; pull first");\',\n \'const pushed = line(["rev-list", "--reverse", "--parents", cut.head === "" ? tip : cut.head + ".." + tip]).split("\\\\n").filter((l) => l !== "").map((l) => l.split(" "));\',\n "let before = cut.head;",\n \'for (const [c = "", ...parents] of pushed) { if (parents.length > 1 || (parents[0] ?? "") !== before) refused("a push into a scope is linear on its head, and " + c + " is not"); const changed = git(["diff-tree", "-r", "-z", "--name-only", "--no-commit-id", ...(before === "" ? ["--root", c] : [before, c])]).toString("latin1").split("\\\\0").filter((p) => p !== ""); const outside = changed.find((p) => !within(p)); if (outside !== undefined) refused(c + " changes " + outside + ", outside the scope"); if (changed.length === 0) refused(c + " changes nothing within the scope"); before = c; }\',\n \'const outside = main === "" ? [] : entries([main]).filter((e) => !within(named(e)));\',\n \'let grafted = main; const graft = pushed.map(([c = ""]) => { grafted = kept(c, treeOf([...outside, ...entries([c]).filter((e) => within(named(e)))]), grafted); return grafted; });\',\n \'if (walk(graft, cut).head !== tip) refused("the scope cut again answers not the commits pushed: one carries what a cut drops, as a signature");\',\n \'git(["update-ref", r + "-main", grafted]); process.stdout.write(grafted + "\\\\ngraft\\\\n" + tip + "\\\\n");\'\n ].join("\\n")}\' -- "$a" "$@"`;\n static #mask = \'const { spawn } = require("node:child_process"); const fs = require("node:fs"); const env = { ...process.env }; const values = []; let held = ""; try { held = fs.readFileSync(process.argv[1], "utf8"); } catch {} for (const line of held.split("\\\\n")) { const at = line.indexOf("="); if (at < 1 || !/^[A-Za-z_][A-Za-z0-9_]*$/.test(line.slice(0, at))) continue; env[line.slice(0, at)] = line.slice(at + 1); if (at + 1 < line.length) values.push(line.slice(at + 1)); } const shown = values.sort((a, b) => b.length - a.length || (a < b ? -1 : a > b ? 1 : 0)); const mask = (t) => shown.reduce((s, v) => s.split(v).join("[secret]"), t); const c = spawn(process.argv[2], process.argv.slice(3), { env, stdio: ["ignore", "pipe", "pipe"] }); const pass = (from, to) => { let kept = ""; from.setEncoding("utf8"); from.on("data", (d) => { kept += d; const i = kept.lastIndexOf("\\\\n") + 1; if (i > 0) { to.write(mask(kept.slice(0, i))); kept = kept.slice(i); } }); from.on("end", () => to.write(mask(kept))); }; pass(c.stdout, process.stdout); pass(c.stderr, process.stderr); for (const s of ["SIGTERM", "SIGINT", "SIGHUP"]) process.on(s, () => c.kill(s)); c.on("error", (e) => { process.stderr.write(e.message + "\\\\n"); process.exitCode = 127; }); c.on("close", (code) => { process.exitCode = code ?? 1; });\';\n static #masked = `node -e \'${_ReposSkin.#mask}\' -- "$1/${_ReposSkin.#env}"`;\n static #scripted = `node -e \'process.exit(require("./package.json").scripts?.[process.argv[1]] ? 0 : 3)\' "$2" 2>/dev/null || { echo "the repo holds no script $2" >&2; exit 3; }\n`;\n static #queued = `q="\\${1%/*}/.gates"; mkdir -p "$q" || exit 1\nlive() { find "$q" -type f -empty -mmin +1 -exec rm -f {} + 2>/dev/null; for gt in "$q"/*; do [ -e "$gt" ] || [ -L "$gt" ] || continue; [ -f "$gt" ] && [ ! -L "$gt" ] || { rm -f "$gt"; continue; }; [ -s "$gt" ] || continue; gp=$(sed -n 1p "$gt"); gs=$(sed -n 2p "$gt"); [ -n "$gp" ] && [ "$(ps -o lstart= -p "$gp" 2>/dev/null)" = "$gs" ] || rm -f "$gt"; done; }\nwhile :; do while :; do live; n=$(ls -1 "$q" | tail -1 | sed \'s/^0*//\'); me=$(printf \'%012d\' $(( \\${n:-0} + 1 ))); ( set -C; printf \'%s\\\\n%s\\\\n\' "$$" "$(ps -o lstart= -p $$)" > "$q/$me" ) 2>/dev/null && break; done; while [ -f "$q/$me" ]; do live; [ "$(ls -1 "$q" | head -1)" = "$me" ] && break 2; sleep 0.2; done; done\n`;\n static #unpack = \'const fs = require("node:fs"); let s = ""; process.stdin.setEncoding("utf8"); process.stdin.on("data", (d) => { s += d; }); process.stdin.on("end", () => { const given = JSON.parse(s); for (const [name, file] of [["parts", "parts.mjs"], ["message", "message"], ["conform", "chosen"]]) if (typeof given[name] === "string") fs.writeFileSync(process.argv[1] + "/" + file, given[name]); if (Array.isArray(given.executable)) fs.writeFileSync(process.argv[1] + "/executable", given.executable.map((path) => path + "\\\\0").join("")); if (Array.isArray(given.paths)) fs.writeFileSync(process.argv[1] + "/paths", given.paths.map((path) => path + "\\\\0").join("")); if (given.scoped === true) fs.writeFileSync(process.argv[1] + "/scoped", ""); if (!fs.existsSync(process.argv[1] + "/parts.mjs")) { process.stderr.write("no check of the parts was given\\\\n"); process.exit(1); } });\';\n static #handing = [\n \'const fs = require("node:fs"); const { execFileSync } = require("node:child_process");\',\n \'const held = (args) => { try { return execFileSync("git", args, { stdio: ["ignore", "pipe", "ignore"], maxBuffer: 268435456 }).toString("utf8"); } catch { return null; } };\',\n \'const tag = held(["describe", "--tags", "--abbrev=0", "--match", "v*", "HEAD"]);\',\n "if (tag === null) process.exit(0);",\n "const told = {};",\n \'for (const path of (held(["ls-tree", "-r", "--name-only", tag.trim()]) ?? "").split("\\\\n")) {\',\n "if (!/^(faculties|designs)\\\\/[^/]+\\\\/versions\\\\.json$/.test(path)) continue;",\n \'const text = held(["show", tag.trim() + ":" + path]); if (text !== null) told[path] = text;\',\n "}",\n \'fs.writeFileSync(process.argv[1], JSON.stringify(told)); process.stdout.write(process.argv[1] + "\\\\n");\'\n ].join("\\n");\n static #checks = `told=$(node -e \'${_ReposSkin.#handing}\' -- "$t/told.json") || exit 1\nnode "$t/parts.mjs" "$w" \\${told:+"$told"} || exit 1\nif [ -f "$t/scoped" ]; then echo "conform: skipped: a lobe holding a scope is checked by the lobe it pushes to"\nelif [ ! -f "$t/chosen" ]; then echo "conform: skipped: no conform is chosen: the check of the parts alone"\nelse k=$(cat "$t/chosen")\ngit cat-file -e "$k^{commit}" 2>/dev/null || { echo "the commit whose conform is chosen, $k, the repo holds not"; exit 1; }\nif git show "$k:tools/conform.mjs" > "$t/conform.mjs" 2>/dev/null; then node "$t/conform.mjs" "$w" || exit 1; else echo "conform: skipped: the commit chosen, $k, holds no tools/conform.mjs"; fi\nfi\n`;\n static #versioning = [\n \'const fs = require("node:fs"); const { execFileSync } = require("node:child_process");\',\n \'const of = (text) => { try { const v = JSON.parse(text).version; return typeof v === "string" ? v : null; } catch { return null; } };\',\n \'const held = (args) => { try { return execFileSync("git", args, { stdio: ["ignore", "pipe", "ignore"] }).toString("utf8"); } catch { return null; } };\',\n \'let read = null; try { read = fs.readFileSync(process.argv[1], "utf8"); } catch {}\',\n \'const now = read === null ? null : of(read); const parent = held(["show", "HEAD:package.json"]); const was = parent === null ? null : of(parent);\',\n "if (now === was) process.exit(0);",\n \'const refused = (why) => { process.stderr.write(why +"\\\\n"); process.exit(1); };\',\n "const three = /^(0|[1-9][0-9]*)\\\\.(0|[1-9][0-9]*)\\\\.(0|[1-9][0-9]*)$/;",\n \'if (now === null || !three.test(now)) refused("the root version " + (now === null ? "none" : now) + " is not three whole numbers");\',\n \'const parts = (v) => v.split(".").map((n) => BigInt(n));\',\n \'if (was !== null && three.test(was)) { const [a, b] = [parts(now), parts(was)]; const at = a.findIndex((n, i) => n !== b[i]); if (at >= 0 && a[at] < b[at]) refused("the root version " + now + " is lower than " + was + ": a version is only raised"); }\',\n \'const tag = "v" + now;\',\n \'if (held(["rev-parse", "-q", "--verify", "refs/tags/" + tag]) !== null) refused("this lobe holds the tag " + tag + " already: a version names one commit for ever");\',\n \'process.stdout.write(tag + "\\\\n");\'\n ].join("\\n");\n static #versioned = `v=\nif [ ! -f "$t/scoped" ]; then v=$(node -e \'${_ReposSkin.#versioning}\' -- "$w/package.json") || exit 1; fi\n`;\n static #unsecret = `if [ -e ${_ReposSkin.#env} ] && ! git check-ignore -q -- ${_ReposSkin.#env}; then echo "${_ReposSkin.#env} is a secret file .gitignore keeps not out: no commit holds it"; exit 1; fi\n`;\n static #staged = `if [ -f "$t/paths" ]; then\nxargs -0 git --literal-pathspecs ls-files -z --cached --others --exclude-standard -- <"$t/paths" >"$t/present" || exit 1\ncp "$t/present" "$t/changed" || exit 1\nif git rev-parse -q --verify HEAD >/dev/null; then xargs -0 git --literal-pathspecs ls-tree -r -z --name-only HEAD -- <"$t/paths" >>"$t/changed" || exit 1; fi\nb=$(git rev-parse -q --verify HEAD || git hash-object -t tree /dev/null) || exit 1\nGIT_INDEX_FILE="$t/index" git read-tree "$b" || exit 1\n[ ! -s "$t/changed" ] || GIT_INDEX_FILE="$t/index" git --literal-pathspecs add --all --pathspec-from-file="$t/changed" --pathspec-file-nul || exit 1\nGIT_INDEX_FILE="$t/index" git diff-index --cached --quiet "$b" -- && { echo "none of the paths named holds a change"; exit 1; }\nelse\ncp -p "$(git rev-parse --git-path index)" "$t/index" 2>/dev/null\nGIT_INDEX_FILE="$t/index" git add --all || exit 1\nfi\nmkdir "$t/w" && GIT_INDEX_FILE="$t/index" git checkout-index --all --prefix="$t/w/" || exit 1\nw="$t/w"\n`;\n static #taken = `if [ -f "$t/paths" ]; then { [ ! -s "$t/present" ] || git --literal-pathspecs add --all --pathspec-from-file="$t/present" --pathspec-file-nul; } && git --literal-pathspecs commit --quiet --file="$t/message" --pathspec-from-file="$t/changed" --pathspec-file-nul || exit 1\nelse git add --all && { [ ! -s "$t/executable" ] || git update-index --chmod=+x -z --stdin <"$t/executable"; } && git commit --quiet --file="$t/message" || exit 1\nfi\n`;\n static #whole = \'const fs = require("node:fs"); let s = ""; process.stdin.setEncoding("utf8"); process.stdin.on("data", (d) => { s += d; }); process.stdin.on("end", () => { const { set = {} } = JSON.parse(s || "{}"); const f = process.argv[1]; const keys = Object.keys(set).sort(); if (keys.length === 0) { fs.rmSync(f, { force: true }); return; } fs.writeFileSync(f, keys.map((key) => key + "=" + set[key] + "\\\\n").join(""), { mode: 0o600 }); fs.chmodSync(f, 0o600); });\';\n static #scripts = {\n setup: `cd "$1/repos" || exit 1\n${_ReposSkin.#marked}`,\n init: `${_ReposSkin.#exact("$1/repos/$2", "$1/repos", "$2")}cd "$1/repos/$2" || exit 1\nexport GIT_CEILING_DIRECTORIES="$1/repos"\n${_ReposSkin.#ident}${_ReposSkin.#marked}\n[ -e .git ] && { echo "the folder holds a repo already" >&2; exit 1; }\n[ -z "$(ls -A)" ] || { echo "the folder holds files: a repo is born in an empty folder" >&2; exit 1; }\ngit init --quiet -b main`,\n stand: `${_ReposSkin.#in}[ -d .git ] && [ ! -L .git ] && [ "$(git rev-parse --show-toplevel 2>/dev/null)" = "$(pwd -P)" ] || { echo "the folder holds no repo to stand on" >&2; exit 1; }\n[ "$(git branch --show-current)" = main ] || { echo "the repo is not on main" >&2; exit 1; }\nc=$(git rev-parse -q --verify refs/heads/main) || { echo "main holds no commit: a repo with none is born by init alone" >&2; exit 1; }\nt=$(mktemp -d) || exit 1\ntrap \'git -C "$1" worktree remove --force "$t/w" 2>/dev/null; rm -rf "$t"; git -C "$1" worktree prune\' EXIT\nnode -e \'${_ReposSkin.#unpack}\' -- "$t" || exit 1\ngit worktree add --quiet --detach "$t/w" "$c" >/dev/null 2>&1 || exit 1\nw="$t/w"\nprintf %s "$c" > "$t/chosen"\n{\n${_ReposSkin.#lend("$t")}${_ReposSkin.#checks}} >&2\necho "conform $c"\necho "$c"`,\n head: `${_ReposSkin.#in}git rev-parse --git-dir >/dev/null 2>&1 || { echo "the folder holds no repo" >&2; exit 1; }\ngit rev-parse -q --verify HEAD || echo\n[ -n "$2" ] || exit 0\nif git merge-base --is-ancestor "$2" HEAD 2>/dev/null; then echo holds; else echo lacks; fi`,\n status: `${_ReposSkin.#in}exec git status --porcelain=v1 --branch`,\n commit: `${_ReposSkin.#in}[ "$(git branch --show-current)" = main ] || { echo "the repo is not on main" >&2; exit 1; }\nt=$(mktemp -d) || exit 1\ntrap \'rm -rf "$t"\' EXIT\nnode -e \'${_ReposSkin.#unpack}\' -- "$t" || exit 1\n{\n${_ReposSkin.#unsecret}${_ReposSkin.#staged}${_ReposSkin.#checks}${_ReposSkin.#versioned}} >&2\n${_ReposSkin.#taken}[ ! -s "$t/executable" ] || git checkout-index -f -z --stdin <"$t/executable" || exit 1\nif [ -n "$v" ]; then git tag "$v" || exit 1; echo "$v"; fi\nh=$(git rev-parse HEAD) || exit 1\n[ "$(git rev-parse -q --verify HEAD:tools/conform.mjs)" = "$(git rev-parse -q --verify HEAD~:tools/conform.mjs)" ] || echo "conform $h"\necho "$h"`,\n discard: `${_ReposSkin.#in}git restore --source=HEAD --staged --worktree -- . && exec git clean -fdq`,\n log: `${_ReposSkin.#in}exec git log --max-count="$2" --format=%H%x09%an%x09%aI%x09%s`,\n bundle: `${_ReposSkin.#in}rm -rf "$2" && mkdir -p "$2" || exit 1\nif [ -n "$5" ]; then u=$(git rev-parse -q --verify "refs/tags/$5^{commit}") || { echo "this lobe holds no tag $5" >&2; exit 1; }\nif [ -n "$3" ] && git merge-base --is-ancestor "$u" "$3" 2>/dev/null; then echo 0; echo "$u"; exit 0; fi\nt=$(mktemp -d) || exit 1\ntrap \'rm -rf "$t"\' EXIT\ngit init --quiet --bare --object-format="$(git rev-parse --show-object-format)" "$t/c" >/dev/null || exit 1\ngit rev-parse --path-format=absolute --git-path objects > "$t/c/objects/info/alternates" || exit 1\ngit --git-dir="$t/c" update-ref refs/heads/main "$u" || exit 1\nfor n in $(git tag --merged "$u" --list \'v*\'); do git --git-dir="$t/c" update-ref "refs/tags/$n" "$(git rev-parse "refs/tags/$n")" || exit 1; done\ncd "$t/c" && export GIT_DIR="$t/c" || exit 1\nelif [ -n "$4" ]; then if [ -n "$3" ] && u=$(git rev-parse -q --verify "$4") && git merge-base --is-ancestor "$u" "$3" 2>/dev/null; then git update-ref -d "$4"; echo 0; echo "$u"; exit 0; fi\nt=$(mktemp -d) || exit 1\ntrap \'rm -rf "$t"\' EXIT\ngit init --quiet --bare --object-format="$(git rev-parse --show-object-format)" "$t/c" >/dev/null || exit 1\nif git rev-parse -q --verify "$4" >/dev/null; then git --git-dir="$t/c" fetch --quiet --no-tags "$1" "+$4:refs/heads/main" || exit 1; fi\ngit update-ref -d "$4" 2>/dev/null; cd "$t/c" && export GIT_DIR="$t/c" || exit 1\nfi\nh=$(git rev-parse -q --verify main) || { echo 0; exit 0; }\n[ "$3" = "$h" ] && { echo 0; echo "$h"; exit 0; }\nif [ -n "$3" ] && git cat-file -e "$3^{commit}" 2>/dev/null; then x="^$3"; g=$(git for-each-ref --format=\'%(refname)\' --merged main --no-merged "$3" \'refs/tags/v*\'); else x=; g=$(git for-each-ref --format=\'%(refname)\' --merged main \'refs/tags/v*\'); fi\ngit bundle create --quiet "$2/b" main $g $x || exit 1\ncd "$2" || exit 1\np="\\${6:-${_ReposSkin.#box}}"\nn=$(( ($(wc -c < b) + p - 1) / p ))\ni=0; while [ "$i" -lt "$n" ]; do dd if=b of="q$i" bs="$p" skip="$i" count=1 2>/dev/null || exit 1; i=$((i + 1)); done\nrm b || exit 1\necho "$n"; echo "$h"`,\n bring: _ReposSkin.#bring,\n cut: _ReposSkin.#cut,\n graft: _ReposSkin.#graft,\n land: `${_ReposSkin.#in}r="refs/nervur/$2"\nc=$(git rev-parse -q --verify "$r-main") || { echo "nothing waits to land as $2" >&2; exit 1; }\ngit update-ref -d "$r"; git update-ref -d "$r-main"\nk=$(git for-each-ref --format=\'%(objectname) %(refname)\' "$r-tags/"); ${_ReposSkin.#untag}\nw=$(echo "$k" | while read -r o n; do [ -n "$n" ] || continue; n=\\${n#"$r-tags/"}; if e=$(git rev-parse -q --verify "refs/tags/$n^{commit}"); then [ "$e" = "$o" ] || echo "this lobe holds the tag $n on another commit: a version names one commit for ever"; fi; done)\n[ -z "$w" ] || { echo "$w" >&2; exit 1; }\nif git rev-parse -q --verify HEAD >/dev/null; then git merge --quiet --ff-only "$c" || { echo "main moved while what came was checked: send it again" >&2; exit 1; }; else git checkout --quiet -B main "$c" || exit 1; fi\necho "$k" | while read -r o n; do [ -n "$n" ] || continue; n=\\${n#"$r-tags/"}; git rev-parse -q --verify "refs/tags/$n" >/dev/null || echo "create refs/tags/$n $o"; done | git update-ref --stdin || exit 1\ngit rev-parse HEAD`,\n conform: `${_ReposSkin.#in}c=$(git rev-parse -q --verify "refs/nervur/$2-main") || { echo "nothing waits as $2" >&2; exit 1; }\n[ "$c" = "$3" ] || { echo "what waits as $2 is $c, not $3" >&2; exit 1; }\nt=$(mktemp -d) || exit 1\ntrap \'git -C "$1" worktree remove --force "$t/w" 2>/dev/null; rm -rf "$t"; git -C "$1" worktree prune\' EXIT\nnode -e \'${_ReposSkin.#unpack}\' -- "$t" || exit 1\ngit worktree add --quiet --detach "$t/w" "$c" >/dev/null 2>&1 || exit 1\nw="$t/w"\n${_ReposSkin.#lend("$t")}${_ReposSkin.#checks}[ -n "$4" ] || exit 0\ncd "$t/w" || exit 1\nnode -e \'process.exit(require("./package.json").scripts?.[process.argv[1]] ? 0 : 3)\' "$4" 2>/dev/null || { echo "gate: skipped: the repo holds no script $4"; exit 0; }\n${_ReposSkin.#queued}${_ReposSkin.#masked} sh -c \'if [ -f package-lock.json ]; then npm ci || exit 1; fi; exec npm run "$1"\' gate "$4"`,\n run: `${_ReposSkin.#in}${_ReposSkin.#lend("${1%/*}")}${_ReposSkin.#scripted}d="$1"; s="$2"; i="$3"; g="$4"\n[ -z "$g" ] || { ${_ReposSkin.#queued}}\nshift 4\nexec node -e \'${_ReposSkin.#mask}\' -- "$d/${_ReposSkin.#env}" sh -c \'if [ "$2" = install ] && [ -f package-lock.json ]; then npm ci || exit 1; fi; s="$1"; shift 2; exec npm run "$s" -- "$@"\' run "$s" "$i" "$@"`,\n secrets: `${_ReposSkin.#in}git rev-parse --git-dir >/dev/null 2>&1 || { echo "the folder holds no repo" >&2; exit 1; }\ngit check-ignore -q -- ${_ReposSkin.#env} || { echo "${_ReposSkin.#env} is not kept out by .gitignore: no secret file is written where git would take it" >&2; exit 1; }\numask 077\nexec node -e \'${_ReposSkin.#whole}\' -- "./${_ReposSkin.#env}"`,\n remove: `for n in "$2" "\\${3-x}"; do case "$n" in .*|*/*) echo "remove reaches one folder of repos/ alone" >&2; exit 1 ;; esac; done\n[ -n "$2" ] || { echo "remove names its folder" >&2; exit 1; }\ncd "$1/repos" || exit 1\nif [ -e "$2" ] || [ -L "$2" ]; then { [ -d "$2" ] && [ ! -L "$2" ] && ls -1A . | grep -qxF -- "$2"; } || { echo "the folder $2 stands not as named under repos" >&2; exit 1; }; rm -rf -- "$2" || exit 1; fi\n[ ! -e "$2" ] || { echo "the folder $2 stands still" >&2; exit 1; }\n[ -z "$3" ] || rm -rf -- "$1/transfers/$3"`,\n clear: `cd "$1/transfers" 2>/dev/null || exit 0\nfor n in "$2" "\\${3-x}"; do case "$n" in \'\'|.*|*/*) echo "clear reaches a lobe\'s pieces alone" >&2; exit 1 ;; esac; done\nexec rm -rf -- "$2\\${3:+/$3}"`,\n scan: `${_ReposSkin.#in}${_ReposSkin.#lend("${1%/*}")}h=$(git rev-parse -q --verify HEAD) || { echo; exit 0; }\necho "$h"\ngit tag --points-at HEAD --list \'v*\' | sed \'s/^/g /\'\ngit ls-files -- \':(glob)faculties/*/faculty.js\' \':(glob)faculties/*/versions.json\' \':(glob)organs/*/graph.json\' \':(glob)organs/*/host/build\' \':(glob)designs/*/design.json\' \':(glob)designs/*/versions.json\' | sed \'s/^/t /\'\n{ git diff --name-only HEAD -- faculties organs designs; git ls-files --others --exclude-standard -- faculties organs designs; } | sed \'s/^/c /\'\ngit -c core.quotePath=false ls-files -- designs \':(glob)faculties/*/assets/**\' | while IFS= read -r p; do { [ -f "$p" ] && [ ! -L "$p" ]; } || { echo "u $p"; continue; }; s=$(perl -0777 -pe \'s/\\\\r\\\\n?/\\\\n/g unless /\\\\0/\' -- "$p" | { sha256sum 2>/dev/null || shasum -a 256; } | cut -d " " -f 1); echo "d $s $p"; done\n${_ReposSkin.#keep}t=$(git describe --tags --abbrev=0 --match \'v*\' HEAD 2>/dev/null) || exit 0\necho "@ $t"\ngit ls-tree -r --name-only "$t" -- faculties organs | grep -E \'^(faculties/[^/]+/(faculty\\\\.js|versions\\\\.json)|organs/[^/]+/(graph\\\\.json|host/build))$\' | while IFS= read -r p; do echo "T $p"; case "$p" in */host/build) continue ;; esac; git diff --quiet "$t" -- "$p" 2>/dev/null && continue; printf \'B %s \' "$p"; git show "$t:$p" | node -e \'let s="";process.stdin.setEncoding("utf8").on("data",(d)=>{s+=d}).on("end",()=>process.stdout.write(JSON.stringify(s)))\'; echo; done\ngit -c core.quotePath=false ls-tree -r "$t" -- faculties | while IFS="$c" read -r m p; do case "$p" in faculties/*/assets/*) ;; *) continue ;; esac; o=\\${m##* }; if [ -s "$k/.o/$o" ]; then echo "A $(cat "$k/.o/$o") $p"; else echo "U $p"; fi; done`,\n build: `${_ReposSkin.#in}${_ReposSkin.#lend("${1%/*}")}o="organs/$2/host"\n[ -x "$o/build" ] || { echo "organs/$2 holds no executable host/build" >&2; exit 1; }\n(cd "$o" && ./build) >&2 || exit 1\n[ -f "$o/half" ] || { echo "the build left no host/half" >&2; exit 1; }\nd=$({ sha256sum "$o/half" 2>/dev/null || shasum -a 256 "$o/half"; } | cut -d " " -f 1)\nr="\\${1%/*}"; h="\\${r%/*}/halves"\nmkdir -p "$h" && chmod 755 "$h" && cp "$o/half" "$h/$d.writing" && chmod 755 "$h/$d.writing" && mv -f "$h/$d.writing" "$h/$d" || { echo "the half is not laid in $h" >&2; exit 1; }\nprintf \'%s\\\\n\' "$d"`,\n look: `${_ReposSkin.#in}${_ReposSkin.#lend("${1%/*}")}d="designs/$2"\n{ [ -d "$d" ] && [ ! -L "$d" ] && ls -1A designs | grep -qxF -- "$2"; } || { echo "the repo holds no design $2" >&2; exit 1; }\nnode -e \'process.exit(require("./package.json").scripts?.design ? 0 : 3)\' 2>/dev/null || { echo "the repo holds no script design" >&2; exit 3; }\nt=$(mktemp) || exit 1\ntrap \'rm -f "$t"\' EXIT\nnpm run --silent design -- "$d" --look "$t" >&2 || exit 1\ncat "$t"`\n };\n static #sh(kind) {\n return ["sh", "-c", _ReposSkin.#scripts[kind], kind];\n }\n static programs = {\n setup: _ReposSkin.#sh("setup"),\n init: _ReposSkin.#sh("init"),\n stand: _ReposSkin.#sh("stand"),\n head: _ReposSkin.#sh("head"),\n status: _ReposSkin.#sh("status"),\n commit: _ReposSkin.#sh("commit"),\n discard: _ReposSkin.#sh("discard"),\n log: _ReposSkin.#sh("log"),\n bundle: _ReposSkin.#sh("bundle"),\n bring: _ReposSkin.#sh("bring"),\n cut: _ReposSkin.#sh("cut"),\n graft: _ReposSkin.#sh("graft"),\n land: _ReposSkin.#sh("land"),\n conform: _ReposSkin.#sh("conform"),\n run: _ReposSkin.#sh("run"),\n secrets: _ReposSkin.#sh("secrets"),\n clear: _ReposSkin.#sh("clear"),\n remove: _ReposSkin.#sh("remove"),\n scan: _ReposSkin.#sh("scan"),\n build: _ReposSkin.#sh("build"),\n look: _ReposSkin.#sh("look")\n };\n static #unready = { ready: false, doing: null, failed: null };\n static #plain = { type: "string" };\n static #some = { type: "string", minLength: 1 };\n static #maybe = { anyOf: [{ type: "string", minLength: 1 }, { type: "null" }] };\n static #place = { type: "integer", minimum: 0 };\n static #one = { type: "integer", minimum: 1 };\n static #named = { type: "string", pattern: "^[a-z][a-z0-9.-]{0,63}$" };\n static #jobSchema = {\n type: "object",\n properties: { job: _ReposSkin.#some },\n required: ["job"],\n additionalProperties: false\n };\n static #paging = {\n type: "object",\n properties: { cursor: _ReposSkin.#maybe },\n additionalProperties: false\n };\n static #scopeSchema = { type: "array", items: _ReposSkin.#some, minItems: 1, maxItems: SCOPE_MOST };\n static #many = { type: "array", items: _ReposSkin.#some, minItems: 1 };\n static #files = {\n type: "array",\n items: {\n type: "object",\n properties: { path: _ReposSkin.#some, text: _ReposSkin.#plain, absent: { type: "boolean" } },\n required: ["path"],\n additionalProperties: false\n }\n };\n static #object(properties, required = Object.keys(properties)) {\n return { type: "object", properties, required, additionalProperties: false };\n }\n static #says = {\n setup: "An owner, once: the disk\'s folder stands at `at` on the host, proven by a marker the disk writes and the shell reads back.",\n delegate: "An owner: the lobe `lobe` a delegate, which grants folders of its own as an owner does and removes those alone, as a keeper raising repo lobes as its children does; with `given` false, a delegate no more, the folders it granted standing.",\n grant: "An owner, or a delegate a folder it granted, a new one, or one no lobe holds, a lobe torn down having left it, which is the delegate’s from then on: the folder `folder`, `repos/<folder>`, is the repo lobe `lobe`’s, whatever lobe it names, its one folder and no other’s, so a wired lobe reaches it only through its repo lobe; its wire back is ordered as its first job starts; a name an entry of `repos/` holds in another case is refused; where `lobe` is null, it is granted to none; a lobe that loses it has its pieces cleared.",\n folders: "An owner, every folder; a delegate, those it granted and those no lobe holds, which it may take: each with the repo lobe it is granted to, whether a repo stands in it, the job going, and the secret files written in it, by their paths. A page, `{ folders, cursor }`, `cursor` null at the list’s end, else handed back to read on.",\n remove: "An owner, or a delegate the folder it granted: forgets the folder `folder` and its grant, its bytes left on disk, and its lobe’s pieces are cleared; with `erase` true, a job, answered `{ job }`, deletes them too: its grant forgotten at once, so its repo lobe reaches it no more, then the folder `repos/<folder>`, checked to stand under the disk’s `repos/` by that exact name and no link, deleted with every byte it holds, and the pieces of the lobe granted it, `transfers/<lobe>/`; the folder forgotten once the job ended, its bytes gone, read by `job`; one that failed stands, granted to none. One running a job is refused.",\n state: "An owner: the disk\'s folder as set up. A repo lobe: its folder on the host, whether a repo stands in it, read on the disk where one was made, and the job going.",\n read: "A repo lobe: a file\'s text, its first lines where `first` names how many, and how many lines it holds; or `paths` alone, `{ files }` in one answer, each `{ path, text }` or `{ path, absent: true }` in the order named, the whole refused where a path climbs or hides, a text is no UTF-8 or the texts weigh past what one answer carries.",\n bytes: "A repo lobe: the bytes of a file a tag of its repo holds in a design\'s folder or a faculty\'s `assets/`, as a design\'s font, which no text holds, by the SHA-256 `sha` its scan kept them under, a text\'s with LF line ends; `absent` where none is kept.",\n write: "A repo lobe: writes a file\'s text whole, as a commit\'s files.",\n erase: "A repo lobe: removes a file, or a folder that holds nothing, of its repo, as a refused commit\'s files are put back as they were; the one removal a repo lobe has this jailer make of a repo\'s bytes.",\n list: "A repo lobe: the names in a folder of its repo, its top where no path is named.",\n piece: "A repo lobe: the piece `at` of the bundle that waits as `as`",\n put: "A repo lobe: writes the piece `at` of `pieces` of a bundle that waits as `as`.",\n init: "A job: makes the repo on `main` in its folder, which holds nothing, empty, laying no file; never over a repo that stands.",\n stand: "A job: the repo its folder holds already, handed in place to the lobe granted it: refused where none stands there, or `main` holds no commit or is not checked out; else its `main` checked out apart and checked by the check of the parts `parts`, Nervur’s, and `tools/conform.mjs` as `main` holds it, on its errors, then `conform <head>`, the conform it chooses, and its head answered. Nothing is laid or moved. Its checks go on the input.",\n head: "A job: the HEAD, and whether it holds the commit `contains` where one is named.",\n status: "A job: `git status`.",\n commit: "A job: refused while `.env` stands where `.gitignore` keeps it not out; then the check of the parts `parts`, Nervur’s, and the repo’s `tools/conform.mjs` as the commit `conform` holds it, the one its owner chose, none where it names none, each over what it would commit, laid out apart as a clone would hold it, so a file `.gitignore` keeps out counts as absent; then its root `package.json` `version` read against `HEAD`’s: refused where it changed and is not three whole numbers, is lower by semver, or its tag `v<version>` stands already; then every change committed on `main`, or with `paths` the changes of those paths alone, each a file or a folder of the repo and the rest of the folder left as it stands, refused where they hold none, with `message`, each path `executable` names landing executable, and tagged `v<version>`, a git tag, where it raised the version, none in a lobe holding a scope; answering the tag where it made one, `conform <head>` where it changed `tools/conform.mjs`, the conform it chooses, then its HEAD. Its message and its checks go on the input.",\n discard: "A job: every change since the last commit undone.",\n log: "A job: the last commits, `most` of them, twenty where none is named.",\n run: "A job: the script `script` of the repo\'s `package.json`, by `npm run <script> -- <args…>`, each of `args` one argument, never read by a shell, its environment the repo\'s `.env`, each line as written, its values masked in its output; with `install`, `npm ci` first where a lockfile stands, in the same job; with `gate`, after the gates asked before it, one at a time across the organism; a script the repo lacks ends 3.",\n secrets: "A job: `.env` written whole, only where `.gitignore` keeps it out: each name of `set` a line `KEY=value`, readable by the owner of the files alone, and removed where it sets none. Its values go on the input, never kept nor read back.",\n clear: "A repo lobe\'s job beside its folder\'s, told to no one: the pieces of its bundle waiting as `as` removed; while they go, none is made, written or read under that name.",\n check: "A repo lobe: its job and its clears checked against the runs the shell names going; each it runs no more, lost to a restart, ended at once, failed, its lobe told. Answers the job going, those ended lost, and `last`, the end it last told that lobe, `{ job, kind, code, out, err }`, as its letter tells it, kept for that lobe alone until its next end, or null.",\n bundle: "A job: the commits on `main` after `since`, as a bundle in pieces waiting as `as`; answers how many and the HEAD. With `cut`, the commits of the cut of `as` after `since` instead, read from its own bare repo as `main`, so nothing of `main` leaves, not even a name; the cut’s ref then cleared, and no tag carried. The bundle carries every tag `v*` naming a commit after `since`; with `tag`, `v` and three whole numbers, `main` ends at the commit that tag names, refused where this lobe holds no such tag, and none where `since` holds that commit already; a cut is bundled by no tag, since its tag was named to the cut: with `cut`, none is made either where `since` holds the cut’s head already.",\n cut: "A job: `main` cut to the scope `scope`, folders none inside another: by first parent, each commit that changes a path within the scope rewritten to one whose tree holds those paths alone, its parent the last one cut, its author, committer, their times and its message kept exactly, signed by no one, so the same `main` is cut to the same commits every time; with `tag`, `v` and three whole numbers, only up to the commit that tag names, the beginning of the cut to the head, the very commits in the very order, refused where this lobe holds no such tag, and the tag’s name never in the cut; left at `refs/nervur/cut-<as>`, its head answered, or an empty line where the cut is empty.",\n bring: "A job: a pull\'s or a push\'s `pieces` waiting as `as` brought apart from `main`, and what `main` would become kept beside it, itself or a merge made apart; answers that head and `forward`, `merge` or `new`, or `main`\'s HEAD and `held` where `main` holds it already; a conflict refused. With `scope`, a scoped writer’s push, grafted: refused unless its commits are linear on the scope’s head as `main` is cut now, none where the cut is empty, else as behind, and where one changes a path outside the scope, naming it, or nothing within it; each commit then grafted on `main`’s tip, its tree `main`’s with every path within the scope taken from it, its author, committer, their times and its message kept, so the scope cut again answers the very commits pushed, else refused; answers that head, `graft` and the head pushed, or the head pushed and `held`. The tags `v*` the bundle carries, a scoped writer\'s none, fetched apart as `refs/nervur/<as>-tags/`, and the whole refused, nothing kept, where one names no commit it brings or this lobe holds a tag of that name on another commit.",\n land: "A job: what was brought as `as` brought into `main`, which it builds on; refused where `main` moved meanwhile. The tags brought with it laid once `main` moved, never before, one held on the same commit no change, and the whole refused, `main` unmoved, where one meets a tag of that name on another commit. Answers the HEAD.",\n conform: "A job: what was brought as `as`, at `head`, checked out apart and checked by the check of the parts `parts`, Nervur’s, then by `tools/conform.mjs` as the commit `conform` holds it, the one the lobe’s owner chose, never as what came holds it, said skipped where it names none or that commit holds none; with `script`, that gate then run there too, with the repo’s `.env`, masked in its output, after the gates asked before it, one at a time across the organism. Its checks go on the input.",\n scan: "A job: the HEAD, each tag `v*` it carries as `g <tag>`, each file of `faculties/` and `organs/` git tracks, each design\'s `design.json` and `versions.json`, each it shows changed, and each file of `designs/` and of each faculty\'s `assets/` with its SHA-256, a text\'s read with LF line ends; then the newest tag `v*` reachable from the HEAD as `@ <tag>`, each faculty\'s and organ\'s file its commit holds as `T <path>`, the text of each that differs from the folder as `B <path> <JSON string>`, and each file of each faculty\'s `assets/` there as `A <SHA-256> <path>`, or `U <path>` where none is kept. Between them, each file a tag `v*` holds in `designs/` or a faculty\'s `assets/` kept by its SHA-256, a text\'s with LF line ends, for `bytes` to read, each tag kept once.",\n build: "A job: the organ `organ`\'s `host/build` run, answering the SHA-256 of the `host/half` it leaves.",\n look: "A job: the design `design`\'s look built by the repo\'s own script `design`, given `designs/<design>` and `--look` with the file to write it to, answering that file alone, the look\'s source; it is built, never committed.",\n stop: "A repo lobe\'s own job, or an owner\'s of the folder `folder`, stopped through the shell; one the shell runs no more, lost to a restart of the organ, ends at once, failed.",\n ended: "The shell\'s alone: a job\'s program ended.",\n back: "The brain\'s alone: the shell\'s half connected, at its start or after it restarted, an update\'s among them: each job going that the shell names going no more ends, lost, its lobe told.",\n migrate: "The brain\'s alone, at a move to this version: every job ended before the jailer bounded its keep forgotten, each end a lobe never took kept apart; the jobs that run stay.",\n jobs: "The asker\'s jobs, an owner\'s every one, each with its code once ended; a job keeps no input and no output. Of each asker the jailer keeps every job that runs and its newest ended, as many as one read holds, a clear forgotten once ended. A page, `{ jobs, cursor }`, `cursor` null at the list\'s end, else handed back to read on.",\n job: "One of the asker\'s jobs, `job`, as the jailer keeps it; an owner reads any, and one not the asker\'s, or one gone past the newest kept, is absent."\n };\n static #reading(method, args, result) {\n const typed = { ...args === void 0 ? {} : { args }, ...result ? { result } : {} };\n const description = _ReposSkin.#says[method] ?? method;\n return { description, kind: "reading", ...typed, errors: ["refused", "absent"] };\n }\n static #writing(method, args, result) {\n return { ..._ReposSkin.#reading(method, args, result), kind: "writing" };\n }\n static #jobOf(method, args) {\n return _ReposSkin.#writing(method, args, _ReposSkin.#jobSchema);\n }\n static #none = _ReposSkin.#object({});\n static blueprint = {\n name: "nervur.repos",\n version: "0.1.119",\n description: "The jailer: keeps the bytes of the organism\'s repos at `repos/<name>` under the disk\'s folder, on `main`, a skin lobe of `shell` and `disk`. An owner sets the folder up and grants each repo\'s folder to one repo lobe, through which the lobes wired to it reach it; the repo lobe reaches its own and never names it: its files read and written as UTF-8 text through the disk, the pieces of its bundles beside them, and its jobs run through the shell, one at a time for each folder, each answered at once and asked back `done` by a letter. It holds no relation and no secret: `.env` is written whole from a job\'s input, only where `.gitignore` keeps it out, readable by the owner of the files alone, and read back by the names that stand alone; a commit is refused while one stands that git would take, and checked over what it would commit laid out apart; and every run of a repo\'s script loads `.env` into its environment, each line as written, masked in its output by its program; a job keeps neither its input nor its output, but the end last told each lobe, kept for that lobe alone until its next. It removes no repo\'s bytes but a refused commit\'s own files, which its repo lobe has it `erase`, and a folder an owner removes with `erase`: a plain `remove` forgets a folder and leaves its bytes.",\n methods: {\n setup: _ReposSkin.#jobOf("setup", _ReposSkin.#object({ at: _ReposSkin.#some })),\n delegate: _ReposSkin.#writing(\n "delegate",\n _ReposSkin.#object({ lobe: _ReposSkin.#some, given: { type: "boolean" } }, ["lobe"])\n ),\n grant: _ReposSkin.#writing("grant", _ReposSkin.#object({ folder: _ReposSkin.#named, lobe: _ReposSkin.#maybe })),\n folders: _ReposSkin.#reading("folders", _ReposSkin.#paging),\n remove: {\n ..._ReposSkin.#writing(\n "remove",\n _ReposSkin.#object({ folder: _ReposSkin.#named, erase: { type: "boolean" } }, ["folder"])\n ),\n irreversible: true\n },\n state: _ReposSkin.#reading("state", _ReposSkin.#none),\n read: _ReposSkin.#reading(\n "read",\n _ReposSkin.#object({ path: _ReposSkin.#some, first: _ReposSkin.#one, paths: _ReposSkin.#many }, []),\n _ReposSkin.#object({ text: _ReposSkin.#plain, lines: { type: "integer" }, files: _ReposSkin.#files }, [])\n ),\n bytes: _ReposSkin.#reading("bytes", _ReposSkin.#object({ sha: _ReposSkin.#some }), _ReposSkin.#object({ bytes: {} })),\n write: _ReposSkin.#writing("write", _ReposSkin.#object({ path: _ReposSkin.#some, text: _ReposSkin.#plain })),\n erase: { ..._ReposSkin.#writing("erase", _ReposSkin.#object({ path: _ReposSkin.#some })), irreversible: true },\n list: _ReposSkin.#reading(\n "list",\n _ReposSkin.#object({ path: _ReposSkin.#plain }, []),\n _ReposSkin.#object({ names: { type: "array", items: _ReposSkin.#plain } })\n ),\n piece: _ReposSkin.#reading(\n "piece",\n _ReposSkin.#object({ at: _ReposSkin.#place, as: _ReposSkin.#some }, ["at", "as"])\n ),\n put: _ReposSkin.#writing(\n "put",\n _ReposSkin.#object({\n at: _ReposSkin.#place,\n pieces: _ReposSkin.#one,\n bytes: {},\n as: _ReposSkin.#some\n })\n ),\n init: _ReposSkin.#jobOf("init", _ReposSkin.#none),\n stand: _ReposSkin.#jobOf(\n "stand",\n _ReposSkin.#object({ parts: _ReposSkin.#some, scoped: { type: "boolean" } }, ["parts"])\n ),\n head: _ReposSkin.#jobOf("head", _ReposSkin.#object({ contains: _ReposSkin.#some }, [])),\n status: _ReposSkin.#jobOf("status", _ReposSkin.#none),\n commit: _ReposSkin.#jobOf(\n "commit",\n _ReposSkin.#object(\n {\n message: _ReposSkin.#some,\n parts: _ReposSkin.#some,\n scoped: { type: "boolean" },\n executable: { type: "array", items: _ReposSkin.#some },\n paths: { type: "array", items: _ReposSkin.#some, minItems: 1 }\n },\n ["message", "parts"]\n )\n ),\n discard: { ..._ReposSkin.#jobOf("discard", _ReposSkin.#none), irreversible: true },\n log: _ReposSkin.#jobOf("log", _ReposSkin.#object({ most: { type: "integer", minimum: 1 } }, [])),\n run: _ReposSkin.#jobOf(\n "run",\n _ReposSkin.#object(\n {\n script: _ReposSkin.#some,\n args: { type: "array", items: _ReposSkin.#plain, maxItems: ARGS_MOST },\n install: { type: "boolean" },\n gate: { type: "boolean" }\n },\n ["script"]\n )\n ),\n secrets: _ReposSkin.#jobOf(\n "secrets",\n _ReposSkin.#object({ set: { type: "object", additionalProperties: _ReposSkin.#plain } })\n ),\n bundle: _ReposSkin.#jobOf(\n "bundle",\n _ReposSkin.#object(\n {\n since: _ReposSkin.#maybe,\n as: _ReposSkin.#some,\n cut: { type: "boolean" },\n tag: _ReposSkin.#some,\n piece: _ReposSkin.#one\n },\n ["since", "as"]\n )\n ),\n bring: _ReposSkin.#jobOf(\n "bring",\n _ReposSkin.#object({ as: _ReposSkin.#some, pieces: _ReposSkin.#one, scope: _ReposSkin.#scopeSchema }, [\n "as",\n "pieces"\n ])\n ),\n cut: _ReposSkin.#jobOf(\n "cut",\n _ReposSkin.#object({ as: _ReposSkin.#some, scope: _ReposSkin.#scopeSchema, tag: _ReposSkin.#some })\n ),\n land: _ReposSkin.#jobOf("land", _ReposSkin.#object({ as: _ReposSkin.#some })),\n conform: _ReposSkin.#jobOf(\n "conform",\n _ReposSkin.#object(\n {\n as: _ReposSkin.#some,\n head: _ReposSkin.#some,\n parts: _ReposSkin.#some,\n scoped: { type: "boolean" },\n script: _ReposSkin.#some\n },\n ["as", "head", "parts"]\n )\n ),\n clear: _ReposSkin.#jobOf("clear", _ReposSkin.#object({ as: _ReposSkin.#some })),\n check: _ReposSkin.#writing(\n "check",\n _ReposSkin.#none,\n _ReposSkin.#object({\n doing: _ReposSkin.#maybe,\n lost: { type: "array", items: _ReposSkin.#some }\n })\n ),\n scan: _ReposSkin.#jobOf("scan", _ReposSkin.#none),\n build: _ReposSkin.#jobOf("build", _ReposSkin.#object({ organ: _ReposSkin.#some })),\n look: _ReposSkin.#jobOf("look", _ReposSkin.#object({ design: _ReposSkin.#some })),\n stop: _ReposSkin.#writing("stop", _ReposSkin.#object({ folder: _ReposSkin.#named }, [])),\n ended: { ..._ReposSkin.#writing("ended"), askers: ["shell"] },\n back: { ..._ReposSkin.#writing("back"), askers: ["brain"] },\n migrate: { ..._ReposSkin.#writing("migrate"), askers: ["brain"] },\n jobs: _ReposSkin.#reading("jobs", _ReposSkin.#paging),\n job: _ReposSkin.#reading("job", _ReposSkin.#jobSchema)\n },\n placeholders: { shell: "nervur.shell", disk: "nervur.disk" }\n };\n static #fields(data) {\n return !!data && typeof data === "object" && !Array.isArray(data) && !ArrayBuffer.isView(data);\n }\n static #text(data) {\n return typeof data === "string" && data !== "";\n }\n static #count(data, most) {\n return typeof data === "number" && Number.isSafeInteger(data) && data >= 1 && data <= most;\n }\n static #arg(args, key) {\n return _ReposSkin.#fields(args) ? args[key] : void 0;\n }\n static #names(path) {\n if (path === void 0 || path === "") return [];\n if (typeof path !== "string") return null;\n const names = path.split("/");\n return names.every((name) => _ReposSkin.#name.test(name)) ? names : null;\n }\n static #paths(paths) {\n return Array.isArray(paths) && paths.length >= 1 && paths.every((path) => typeof path === "string" && path !== "" && _ReposSkin.#names(path) !== null);\n }\n static #scopeOf(scope) {\n if (!Array.isArray(scope) || scope.length < 1 || scope.length > SCOPE_MOST) return null;\n const folders = scope.flatMap((one) => typeof one === "string" ? [one] : []);\n const fit = (one) => one.split("/").every((name) => _ReposSkin.#segment.test(name) && ![".", "..", ".git"].includes(name));\n if (folders.length !== scope.length || !folders.every(fit)) return null;\n const sorted = folders.toSorted();\n const nested = sorted.some(\n (one, at) => sorted.some((other, by) => by !== at && (one === other || one.startsWith(`${other}/`)))\n );\n return nested ? null : sorted;\n }\n static #lone = /[\\uD800-\\uDBFF](?![\\uDC00-\\uDFFF])|(?<![\\uD800-\\uDBFF])[\\uDC00-\\uDFFF]/g;\n #bytes(text) {\n const encoded = this.codec.utf8(text.replace(_ReposSkin.#lone, "�"));\n return "bytes" in encoded ? encoded.bytes : null;\n }\n #textOf(bytes) {\n const decoded = this.codec.utf8Text(bytes);\n return "text" in decoded ? decoded.text : null;\n }\n #linesOf(set) {\n if (!_ReposSkin.#fields(set)) return null;\n const entries = Object.entries(set);\n if (entries.length > this.#most()) return null;\n for (const [key, value] of entries)\n if (!_ReposSkin.#key.test(key) || typeof value !== "string" || !_ReposSkin.#line.test(value)) return null;\n return set;\n }\n static #argsOf(args) {\n if (args === void 0) return [];\n if (!Array.isArray(args) || args.length > ARGS_MOST) return null;\n const all = args.flatMap(\n (one) => typeof one === "string" && one.length <= ARG_LONGEST && !one.includes("\\0") ? [one] : []\n );\n return all.length === args.length ? all : null;\n }\n #heard(answer) {\n return "error" in answer ? this.error(answer.error.code, answer.error.message) : null;\n }\n #nonce() {\n return Array.from(this.stamp.seed.slice(0, 16), (byte) => byte.toString(16).padStart(2, "0")).join("");\n }\n #at() {\n const setup = this.cells.get(["setup"]);\n if (!_ReposSkin.#fields(setup) || setup["ready"] !== true) return null;\n return _ReposSkin.#text(setup["at"]) ? setup["at"] : null;\n }\n #most() {\n return Math.min(CELLS_RANGE, Math.floor(this.memory / LOBE_SHARE / ITEM_SIZE));\n }\n #all(prefix) {\n return this.cells.range({ prefix, limit: this.#most() }).cells;\n }\n #page(prefix, args) {\n const cursor = _ReposSkin.#arg(args, "cursor") ?? null;\n if (cursor !== null && !_ReposSkin.#text(cursor))\n return this.error("refused", "a cursor is the one a page answered");\n try {\n return this.cells.range({ prefix, limit: this.#most(), ...cursor === null ? {} : { cursor } });\n } catch {\n return this.error("refused", "a cursor is the one a page answered");\n }\n }\n async setup(args) {\n if (this.stamp.asker !== _ReposSkin.#owner) return this.error("refused", "setup is an owner\'s");\n const at = _ReposSkin.#arg(args, "at");\n if (!_ReposSkin.#text(at) || !at.startsWith("/"))\n return this.error("refused", "at is where the disk\'s folder stands, from the root");\n const held = await this.#unstuck(["setup"]);\n if (_ReposSkin.#fields(held) && _ReposSkin.#text(held["doing"]))\n return this.error("refused", "the setup runs already");\n const nonce = this.#nonce();\n const path = [_ReposSkin.#repos, _ReposSkin.#marker];\n const wrote = await this.ask("disk", "write", { path, bytes: this.#bytes(nonce) });\n if ("error" in wrote) return this.#heard(wrote);\n this.cells.set(["setup"], { at, ..._ReposSkin.#unready });\n return this.#begin("setup", null, [at], `${nonce}\n`);\n }\n async grant(args) {\n const delegate = this.#delegate();\n if (this.stamp.asker !== _ReposSkin.#owner && delegate === null)\n return this.error("refused", "grant is an owner\'s or a delegate\'s");\n const folder = _ReposSkin.#arg(args, "folder");\n const lobe = _ReposSkin.#arg(args, "lobe");\n if (!_ReposSkin.#text(folder) || !_ReposSkin.#folderName.test(folder))\n return this.error("refused", "a folder is a repo’s name, lowercase, a letter first");\n if (this.#at() === null) return this.error("refused", "the disk\'s folder is not set up");\n const held = this.cells.get(["folder", folder]);\n const free = _ReposSkin.#fields(held) && !_ReposSkin.#text(held["lobe"]);\n if (delegate !== null && _ReposSkin.#fields(held) && held["by"] !== delegate && (!free || lobe === null))\n return this.error("refused", `the folder ${folder} is none the delegate granted, and a lobe holds it`);\n const kept = _ReposSkin.#fields(held) ? { ...held, ...delegate === null ? {} : { by: delegate } } : { lobe: null, doing: null, made: false, ...delegate === null ? {} : { by: delegate } };\n if (lobe === null) {\n if (!_ReposSkin.#fields(held)) return this.error("absent", `no folder ${folder}`);\n this.cells.set(["folder", folder], { ...held, lobe: null });\n if (_ReposSkin.#text(held["lobe"])) await this.#release(held["lobe"], folder);\n return null;\n }\n if (!_ReposSkin.#text(lobe) || [_ReposSkin.#owner, "shell", "disk"].includes(lobe))\n return this.error("refused", "a grant names a repo lobe, or null for none");\n const holds = this.cells.get(["lobe", lobe]);\n if (typeof holds === "string" && holds !== folder)\n return this.error("refused", `the lobe ${lobe} holds the folder ${holds} already`);\n const met = _ReposSkin.#fields(held) ? null : await this.#folded(folder);\n if (met !== null) return met;\n const was = _ReposSkin.#fields(held) ? held["lobe"] : null;\n this.cells.set(["lobe", lobe], folder);\n this.cells.set(["folder", folder], { ...kept, lobe });\n if (_ReposSkin.#text(was) && was !== lobe) await this.#release(was, folder);\n return null;\n }\n async delegate(args) {\n if (this.stamp.asker !== _ReposSkin.#owner) return this.error("refused", "delegate is an owner\'s");\n const lobe = _ReposSkin.#arg(args, "lobe");\n if (!_ReposSkin.#text(lobe) || [_ReposSkin.#owner, "shell", "disk"].includes(lobe))\n return this.error("refused", "a delegate is a lobe");\n if (_ReposSkin.#arg(args, "given") === false) this.cells.delete(["delegate", lobe]);\n else this.cells.set(["delegate", lobe], true);\n return null;\n }\n #delegate() {\n const { asker } = this.stamp;\n return asker !== _ReposSkin.#owner && this.cells.get(["delegate", asker]) === true ? asker : null;\n }\n async #release(lobe, folder) {\n this.cells.delete(["lobe", lobe]);\n const at = this.#at();\n if (at === null) return;\n const program = [..._ReposSkin.programs.clear, at, lobe];\n const begun = await this.ask("shell", "run", { program, input: "" });\n const run = "result" in begun ? _ReposSkin.#arg(begun.result, "run") : void 0;\n if (!_ReposSkin.#text(run)) return;\n const { asker } = this.stamp;\n this.cells.set(["job", run], { job: run, kind: "clear", asker, folder, ended: null });\n this.cells.set(["by", asker, run], null);\n this.cells.set(["clearing", lobe, "*"], { run });\n }\n static #ends(read) {\n const all = _ReposSkin.#fields(read) && Array.isArray(read["result"]) ? read["result"] : [];\n return new Set(all.map((wire) => _ReposSkin.#arg(wire, "termination")));\n }\n async #torn(read) {\n const ends = _ReposSkin.#ends(read);\n for (const { key, value } of this.#all(["lobe"])) {\n const lobe = key[1];\n if (!_ReposSkin.#text(lobe) || ends.has(lobe) || !_ReposSkin.#text(value)) continue;\n if (this.cells.range({ prefix: ["by", lobe], limit: 1 }).cells.length === 0) continue;\n const held = this.cells.get(["folder", value]);\n if (_ReposSkin.#fields(held) && held["lobe"] === lobe) this.cells.set(["folder", value], { ...held, lobe: null });\n this.cells.delete(["last", lobe]);\n await this.#release(lobe, value);\n }\n }\n async #lostOf(jobs) {\n const asked = await this.ask("shell", "going", {});\n const named = "result" in asked ? _ReposSkin.#arg(asked.result, "runs") : void 0;\n if (!Array.isArray(named)) return null;\n const going = new Set(named);\n return jobs.filter((job) => !going.has(job));\n }\n async #unstuck(key) {\n const record = this.cells.get([...key]);\n const doing = _ReposSkin.#arg(record ?? null, "doing");\n if (!_ReposSkin.#text(doing)) return record;\n const lost = await this.#lostOf([doing]);\n if (lost === null || lost.length === 0) return record;\n await this.#end(doing, -1, "", _ReposSkin.#lost);\n return this.cells.get([...key]);\n }\n async check() {\n const own = this.#own();\n if (!("folder" in own)) return own;\n const doing = own.held["doing"];\n const clears = this.#all(["clearing", this.stamp.asker]).flatMap(({ value }) => {\n const run = _ReposSkin.#arg(value, "run");\n return _ReposSkin.#text(run) ? [run] : [];\n });\n const runs = [..._ReposSkin.#text(doing) ? [doing] : [], ...clears];\n const lost = runs.length === 0 ? [] : await this.#lostOf(runs) ?? [];\n for (const run of lost) await this.#end(run, -1, "", _ReposSkin.#lost);\n const after = this.cells.get(["folder", own.folder]);\n const last = this.cells.get(["last", this.stamp.asker]) ?? null;\n return { doing: _ReposSkin.#arg(after ?? null, "doing") ?? null, lost: [...lost], last };\n }\n async #folded(folder) {\n const listed = await this.ask("disk", "list", { path: [_ReposSkin.#repos] });\n if ("error" in listed)\n return listed.error.code === "absent" ? null : this.error("refused", `repos/ is not listed: ${listed.error.message}`);\n const names = _ReposSkin.#arg(listed.result, "names");\n const lower = folder.toLowerCase();\n const met = Array.isArray(names) ? names.find((name) => typeof name === "string" && name !== folder && name.toLowerCase() === lower) : void 0;\n return typeof met === "string" ? this.error("refused", `the folder ${folder} meets ${met}, which repos/ holds in another case`) : null;\n }\n folders(args) {\n const delegate = this.#delegate();\n if (this.stamp.asker !== _ReposSkin.#owner && delegate === null)\n return this.error("refused", "folders is an owner\'s or a delegate\'s");\n const page = this.#page(["folder"], args);\n if (!("cells" in page)) return page;\n const seen = page.cells.filter(\n ({ value }) => delegate === null || _ReposSkin.#fields(value) && (value["by"] === delegate || !_ReposSkin.#text(value["lobe"]))\n );\n const folders = seen.map(({ key, value }) => ({\n folder: key[1] ?? null,\n ..._ReposSkin.#fields(value) ? value : {}\n }));\n return { folders, cursor: page.cursor };\n }\n async remove(args) {\n const delegate = this.#delegate();\n if (this.stamp.asker !== _ReposSkin.#owner && delegate === null)\n return this.error("refused", "remove is an owner\'s or a delegate\'s");\n const folder = _ReposSkin.#arg(args, "folder");\n const erase = _ReposSkin.#arg(args, "erase") ?? false;\n if (typeof erase !== "boolean") return this.error("refused", "erase is true or false");\n if (!_ReposSkin.#text(folder) || !_ReposSkin.#fields(this.cells.get(["folder", folder])))\n return this.error("absent", "no such folder");\n const held = await this.#unstuck(["folder", folder]);\n if (!_ReposSkin.#fields(held)) return this.error("absent", "no such folder");\n if (delegate !== null && held["by"] !== delegate)\n return this.error("refused", `the folder ${folder} is none the delegate granted`);\n const doing = held["doing"];\n if (_ReposSkin.#text(doing)) return this.error("refused", `the folder ${folder} runs ${doing}: wait for it to end`);\n if (erase) return this.#erasing(folder, held);\n this.cells.delete(["folder", folder]);\n if (_ReposSkin.#text(held["lobe"])) await this.#release(held["lobe"], folder);\n return null;\n }\n async #erasing(folder, held) {\n const at = this.#at();\n if (at === null) return this.error("refused", "the disk\'s folder is not set up");\n if (!_ReposSkin.#folderName.test(folder)) return this.error("refused", "a folder is a repo’s name");\n const lobe = _ReposSkin.#text(held["lobe"]) ? held["lobe"] : "";\n if (lobe !== "") this.cells.delete(["lobe", lobe]);\n this.cells.set(["folder", folder], { ...held, lobe: null });\n return this.#begin("remove", folder, [at, folder, lobe], "");\n }\n async state() {\n if (this.stamp.asker === _ReposSkin.#owner) return this.cells.get(["setup"]) ?? null;\n const own = this.#own();\n if (!("folder" in own)) return own;\n const at = this.#at();\n const listed = own.held["made"] === true ? await this.ask("disk", "list", { path: [_ReposSkin.#repos] }) : null;\n const names = listed !== null && "result" in listed ? _ReposSkin.#arg(listed.result, "names") : void 0;\n const made = Array.isArray(names) && names.includes(own.folder);\n return {\n folder: at === null ? null : `${at}/${_ReposSkin.#repos}/${own.folder}`,\n made,\n doing: own.held["doing"] ?? null\n };\n }\n #own() {\n const { asker } = this.stamp;\n const folder = this.cells.get(["lobe", asker]);\n const held = typeof folder === "string" ? this.cells.get(["folder", folder]) : void 0;\n if (typeof folder !== "string" || !_ReposSkin.#fields(held))\n return this.error("refused", `the lobe ${asker} is granted no folder`);\n return { folder, held };\n }\n async #readMany(args, paths) {\n if (_ReposSkin.#arg(args, "path") !== void 0 || _ReposSkin.#arg(args, "first") !== void 0)\n return this.error("refused", "paths come alone, without path or first");\n if (!Array.isArray(paths) || paths.length === 0) return this.error("refused", "paths are one file or more");\n const named = paths.flatMap((one) => _ReposSkin.#text(one) && _ReposSkin.#names(one) !== null ? [one] : []);\n if (named.length !== paths.length)\n return this.error("refused", "a path is names under the repo, none empty, climbing or reaching .git");\n const reads = await Promise.all(named.map((path) => this.#disk("read", path)));\n const files = [];\n let weight = 0;\n for (const [at, read] of reads.entries()) {\n const path = named[at] ?? "";\n if (!("result" in read)) {\n if ("code" in read && read.code === "absent") files.push({ path, absent: true });\n else return read;\n continue;\n }\n const bytes = _ReposSkin.#arg(read.result, "bytes");\n const text = bytes instanceof Uint8Array ? this.#textOf(bytes) : null;\n if (!(bytes instanceof Uint8Array) || text === null) return this.error("refused", `${path} is not UTF-8 text`);\n weight += bytes.length;\n if (weight > this.memory / LOBE_SHARE)\n return this.error(\n "refused",\n `the files weigh past ${Math.floor(this.memory / LOBE_SHARE)} bytes, what one answer of this lobe carries`\n );\n files.push({ path, text });\n }\n return { files };\n }\n async read(args) {\n const paths = _ReposSkin.#arg(args, "paths");\n if (paths !== void 0) return this.#readMany(args, paths);\n const first = _ReposSkin.#arg(args, "first");\n if (first !== void 0 && !_ReposSkin.#count(first, Number.MAX_SAFE_INTEGER))\n return this.error("refused", "first is how many lines, one or more");\n const read = await this.#disk("read", _ReposSkin.#arg(args, "path"));\n if (!("result" in read)) return read;\n const bytes = _ReposSkin.#arg(read.result, "bytes");\n const text = bytes instanceof Uint8Array ? this.#textOf(bytes) : null;\n if (text === null) return this.error("refused", "the file is not UTF-8 text");\n const lines = text.split("\\n");\n return {\n text: first === void 0 ? text : lines.slice(0, first).join("\\n"),\n lines: lines.length\n };\n }\n async bytes(args) {\n const own = this.#own();\n if (!("folder" in own)) return own;\n const sha = _ReposSkin.#arg(args, "sha");\n if (!_ReposSkin.#text(sha) || !_ReposSkin.#sha.test(sha))\n return this.error("refused", "a kept file is named by its SHA-256, in lowercase hex");\n const read = await this.ask("disk", "read", {\n path: [_ReposSkin.#transfers, this.stamp.asker, _ReposSkin.#kept, sha]\n });\n if ("error" in read) return this.error(read.error.code, read.error.message);\n const bytes = _ReposSkin.#arg(read.result, "bytes");\n return bytes instanceof Uint8Array ? { bytes } : this.error("refused", "the disk answered no bytes");\n }\n async write(args) {\n const text = _ReposSkin.#arg(args, "text");\n if (typeof text !== "string") return this.error("refused", "a write holds its text");\n const bytes = this.#bytes(text);\n if (bytes === null) return this.error("refused", "the text has no UTF-8");\n const wrote = await this.#disk("write", _ReposSkin.#arg(args, "path"), bytes);\n return "result" in wrote ? wrote.result : wrote;\n }\n async erase(args) {\n const erased = await this.#disk("remove", _ReposSkin.#arg(args, "path"));\n return "result" in erased ? erased.result : erased;\n }\n async list(args) {\n const path = _ReposSkin.#arg(args, "path");\n const listed = await this.#disk("list", path);\n const root = _ReposSkin.#names(path)?.length === 0;\n if (root && "code" in listed && listed.code === "absent") return { names: [] };\n return "result" in listed ? listed.result : listed;\n }\n async #disk(method, path, bytes) {\n const own = this.#own();\n if (!("folder" in own)) return own;\n const names = _ReposSkin.#names(path);\n if (names === null || names.length === 0 && method !== "list")\n return this.error("refused", "a path is names under the repo, none empty, climbing or reaching .git");\n if (method !== "list" && names.join("/").toLowerCase() === _ReposSkin.#env)\n return this.error("refused", `${names.join("/")} is a secret file, written by secrets alone and read by no one`);\n const at = [_ReposSkin.#repos, own.folder, ...names];\n const answer = await this.ask("disk", method, bytes === void 0 ? { path: at } : { path: at, bytes });\n return "error" in answer ? this.error(answer.error.code, answer.error.message) : answer;\n }\n async piece(args) {\n const path = await this.#piecePath(args);\n if (!Array.isArray(path)) return path;\n const read = await this.ask("disk", "read", { path });\n if ("error" in read) return this.#heard(read);\n return { bytes: _ReposSkin.#arg(read.result, "bytes") ?? null };\n }\n async put(args) {\n const path = await this.#piecePath(args);\n if (!Array.isArray(path)) return path;\n const pieces = _ReposSkin.#arg(args, "pieces");\n const at = _ReposSkin.#arg(args, "at");\n const bytes = _ReposSkin.#arg(args, "bytes");\n if (typeof pieces !== "number" || typeof at !== "number" || at >= pieces)\n return this.error("refused", "a piece stands before the count of its pieces");\n if (!(bytes instanceof Uint8Array)) return this.error("refused", "a piece holds its bytes");\n const wrote = await this.ask("disk", "write", { path, bytes });\n return this.#heard(wrote);\n }\n async #piecePath(args) {\n const own = this.#own();\n if (!("folder" in own)) return own;\n const at = _ReposSkin.#arg(args, "at");\n const as = _ReposSkin.#arg(args, "as");\n if (typeof at !== "number" || !Number.isSafeInteger(at) || at < 0)\n return this.error("refused", "a piece stands at a place, from 0");\n if (!_ReposSkin.#text(as) || !_ReposSkin.#as.test(as))\n return this.error("refused", "a bundle waits as push, pull, out-<far> or in-<far>");\n const clearing = await this.#clearing(as);\n if (clearing !== null) return clearing;\n return [_ReposSkin.#transfers, this.stamp.asker, as, `q${at}`];\n }\n async #clearing(as) {\n const runs = [as, "*"].flatMap((name) => {\n const run = _ReposSkin.#arg(this.cells.get(["clearing", this.stamp.asker, name]) ?? null, "run");\n return _ReposSkin.#text(run) ? [run] : [];\n });\n if (runs.length === 0) return null;\n const lost = await this.#lostOf(runs) ?? [];\n for (const run of lost) await this.#end(run, -1, "", _ReposSkin.#lost);\n return runs.every((run) => lost.includes(run)) ? null : this.error("refused", `the pieces of ${as} are being cleared`);\n }\n async clear(args) {\n const as = _ReposSkin.#arg(args, "as");\n if (!_ReposSkin.#text(as) || !_ReposSkin.#as.test(as))\n return this.error("refused", "a bundle waits as push, pull, out-<far> or in-<far>");\n const own = this.#own();\n if (!("folder" in own)) return own;\n const at = this.#at();\n if (at === null) return this.error("refused", "the disk\'s folder is not set up");\n const { asker } = this.stamp;\n const clearing = await this.#clearing(as);\n if (clearing !== null) return clearing;\n const program = [..._ReposSkin.programs.clear, at, asker, as];\n const begun = await this.ask("shell", "run", { program, input: "" });\n if ("error" in begun) return this.error(begun.error.code, begun.error.message);\n const run = _ReposSkin.#arg(begun.result, "run");\n if (!_ReposSkin.#text(run)) return this.error("refused", "the shell named no run");\n this.cells.set(["job", run], {\n job: run,\n kind: "clear",\n asker,\n folder: own.folder,\n ended: null\n });\n this.cells.set(["by", asker, run], null);\n this.cells.set(["clearing", asker, as], { run });\n return { job: run };\n }\n #transfer(as) {\n return `${this.#at() ?? ""}/${_ReposSkin.#transfers}/${this.stamp.asker}/${as}`;\n }\n async init(args) {\n const unchecked = this.checked("init", args);\n if (unchecked !== void 0) return unchecked;\n const own = this.#own();\n const at = this.#at();\n if (!("folder" in own)) return own;\n if (at === null) return this.error("refused", "the disk\'s folder is not set up");\n const held = await this.#unstuck(["folder", own.folder]);\n const doing = _ReposSkin.#arg(held ?? null, "doing");\n if (_ReposSkin.#text(doing)) return this.error("refused", `${own.folder} runs ${doing} already`);\n const nonce = this.#nonce();\n const path = [_ReposSkin.#repos, own.folder, _ReposSkin.#marker];\n const wrote = await this.ask("disk", "write", { path, bytes: this.#bytes(nonce) });\n if ("error" in wrote) return this.#heard(wrote);\n return this.#begin("init", own.folder, [at, own.folder], `${nonce}\n`);\n }\n stand(args) {\n const checks = _ReposSkin.#checksOf(args);\n if (checks === null) return Promise.resolve(this.error("refused", "a stand names the check of the parts"));\n return this.#job("stand", [], JSON.stringify(checks));\n }\n head(args) {\n const contains = _ReposSkin.#arg(args, "contains");\n if (contains !== void 0 && !(_ReposSkin.#text(contains) && _ReposSkin.#hash.test(contains)))\n return Promise.resolve(this.error("refused", "contains is a commit"));\n return this.#job("head", typeof contains === "string" ? [contains] : [], "");\n }\n status() {\n return this.#job("status", [], "");\n }\n commit(args) {\n const message = _ReposSkin.#arg(args, "message");\n if (!_ReposSkin.#text(message)) return Promise.resolve(this.error("refused", "a commit holds its message"));\n const checks = _ReposSkin.#checksOf(args);\n if (checks === null) return Promise.resolve(this.error("refused", "a commit names the check of the parts"));\n const own = this.#own();\n if (!("folder" in own)) return Promise.resolve(own);\n const executable = _ReposSkin.#arg(args, "executable");\n const paths = _ReposSkin.#arg(args, "paths");\n if (paths !== void 0 && !_ReposSkin.#paths(paths))\n return Promise.resolve(\n this.error("refused", "a commit takes paths of the repo, each a file or a folder under it")\n );\n const input = JSON.stringify({\n ...checks,\n message,\n ...executable === void 0 ? {} : { executable },\n ...paths === void 0 ? {} : { paths }\n });\n return this.#job("commit", [], input);\n }\n static #checksOf(args) {\n const { parts, conform, scoped } = _ReposSkin.#fields(args) ? args : {};\n if (!_ReposSkin.#text(parts)) return null;\n if (conform !== void 0 && !(_ReposSkin.#text(conform) && _ReposSkin.#hash.test(conform))) return null;\n if (scoped !== void 0 && typeof scoped !== "boolean") return null;\n return { parts, ...conform === void 0 ? {} : { conform }, ...scoped === true ? { scoped } : {} };\n }\n discard() {\n return this.#job("discard", [], "");\n }\n log(args) {\n const most = _ReposSkin.#arg(args, "most") ?? _ReposSkin.#logs;\n if (!_ReposSkin.#count(most, this.#most()))\n return Promise.resolve(this.error("refused", `most is how many commits, one to ${this.#most()}`));\n return this.#job("log", [String(most)], "");\n }\n run(args) {\n const script = _ReposSkin.#arg(args, "script");\n const install = _ReposSkin.#arg(args, "install") ?? false;\n const words = _ReposSkin.#argsOf(_ReposSkin.#arg(args, "args"));\n if (!_ReposSkin.#text(script) || !_ReposSkin.#script.test(script))\n return Promise.resolve(this.error("refused", "a run names a script of the repo\'s package"));\n if (typeof install !== "boolean") return Promise.resolve(this.error("refused", "install is true or false"));\n const gate = _ReposSkin.#arg(args, "gate") ?? false;\n if (typeof gate !== "boolean") return Promise.resolve(this.error("refused", "gate is true or false"));\n if (words === null)\n return Promise.resolve(this.error("refused", `a run\'s args are texts, at most ${ARGS_MOST}, none holding a NUL`));\n return this.#job("run", [script, install ? "install" : "", gate ? "gate" : "", ...words], "");\n }\n secrets(args) {\n const set = this.#linesOf(_ReposSkin.#arg(args, "set"));\n if (set === null)\n return Promise.resolve(\n this.error("refused", "a secret file\'s lines are each an environment variable\'s name and a value of one line")\n );\n const own = this.#own();\n if (!("folder" in own)) return Promise.resolve(own);\n return this.#job("secrets", [], JSON.stringify({ set }));\n }\n async bundle(args) {\n const since = _ReposSkin.#arg(args, "since") ?? null;\n const as = _ReposSkin.#arg(args, "as");\n if (since !== null && !(_ReposSkin.#text(since) && _ReposSkin.#hash.test(since)))\n return this.error("refused", "since is a commit, or null");\n if (!_ReposSkin.#text(as) || !_ReposSkin.#as.test(as))\n return this.error("refused", "a bundle waits as push, pull, out-<far> or in-<far>");\n const cut = _ReposSkin.#arg(args, "cut") ?? false;\n if (typeof cut !== "boolean") return this.error("refused", "cut is true or false");\n const tag = _ReposSkin.#arg(args, "tag");\n if (tag !== void 0 && !(_ReposSkin.#text(tag) && _ReposSkin.#tag.test(tag)))\n return this.error("refused", "a tag is v and three whole numbers");\n if (cut && tag !== void 0) return this.error("refused", "a cut is bundled by no tag");\n const clearing = await this.#clearing(as);\n if (clearing !== null) return clearing;\n const most = Math.floor(this.memory / LOBE_SHARE);\n const piece = _ReposSkin.#arg(args, "piece") ?? _ReposSkin.#box;\n if (!_ReposSkin.#count(piece, most))\n return this.error("refused", `a piece is a whole number of bytes, one to ${most}`);\n const words = [cut ? `refs/nervur/cut-${as}` : "", typeof tag === "string" ? tag : "", String(piece)];\n return this.#job("bundle", [this.#transfer(as), since ?? "", ...words], "");\n }\n cut(args) {\n const as = _ReposSkin.#arg(args, "as");\n const tag = _ReposSkin.#arg(args, "tag");\n if (tag !== void 0 && !(_ReposSkin.#text(tag) && _ReposSkin.#tag.test(tag)))\n return Promise.resolve(this.error("refused", "a tag is v and three whole numbers"));\n const scope = _ReposSkin.#scopeOf(_ReposSkin.#arg(args, "scope"));\n if (!_ReposSkin.#text(as) || !_ReposSkin.#as.test(as))\n return Promise.resolve(this.error("refused", "a cut is named as push, pull, out-<far> or in-<far>"));\n if (scope === null)\n return Promise.resolve(\n this.error("refused", `a scope is 1 to ${SCOPE_MOST} folders of the repo, none inside another`)\n );\n return this.#job("cut", [as, typeof tag === "string" ? tag : "", ...scope], "");\n }\n async bring(args) {\n const as = _ReposSkin.#arg(args, "as");\n const pieces = _ReposSkin.#arg(args, "pieces");\n if (!_ReposSkin.#text(as) || !_ReposSkin.#as.test(as) || !_ReposSkin.#count(pieces, Number.MAX_SAFE_INTEGER))\n return this.error("refused", "a bundle names where it waits and its pieces");\n const scoped = _ReposSkin.#arg(args, "scope");\n const scope = scoped === void 0 ? [] : _ReposSkin.#scopeOf(scoped);\n if (scope === null)\n return this.error("refused", `a scope is 1 to ${SCOPE_MOST} folders of the repo, none inside another`);\n const clearing = await this.#clearing(as);\n if (clearing !== null) return clearing;\n return this.#job(scope.length === 0 ? "bring" : "graft", [this.#transfer(as), String(pieces), as, ...scope], "");\n }\n land(args) {\n const as = _ReposSkin.#arg(args, "as");\n if (!_ReposSkin.#text(as) || !_ReposSkin.#as.test(as))\n return Promise.resolve(this.error("refused", "a landing names what waits, as push, pull, out-<far> or in-<far>"));\n return this.#job("land", [as], "");\n }\n conform(args) {\n const { as, head, script } = _ReposSkin.#fields(args) ? args : {};\n if (!_ReposSkin.#text(as) || !_ReposSkin.#as.test(as) || !_ReposSkin.#text(head) || !_ReposSkin.#hash.test(head))\n return Promise.resolve(\n this.error("refused", "a conform names what waits, as push, pull, out-<far> or in-<far>, and its head")\n );\n if (script !== void 0 && !(_ReposSkin.#text(script) && _ReposSkin.#script.test(script)))\n return Promise.resolve(this.error("refused", "a gate is a script of the repo\'s package"));\n const checks = _ReposSkin.#checksOf(args);\n if (checks === null) return Promise.resolve(this.error("refused", "a conform names the check of the parts"));\n const words = typeof script === "string" ? [as, head, script] : [as, head];\n return this.#job("conform", words, JSON.stringify(checks));\n }\n scan() {\n return this.#job("scan", [this.#transfer(_ReposSkin.#kept)], "");\n }\n build(args) {\n const organ = _ReposSkin.#arg(args, "organ");\n if (!_ReposSkin.#text(organ) || organ.length > 64 || !_ReposSkin.#organ.test(organ))\n return Promise.resolve(this.error("refused", "an organ is named by its fixed ID"));\n return this.#job("build", [organ], "");\n }\n look(args) {\n const design = _ReposSkin.#arg(args, "design");\n if (!_ReposSkin.#text(design) || design.length > 59 || !_ReposSkin.#design.test(design))\n return Promise.resolve(this.error("refused", "a design is named by its folder"));\n return this.#job("look", [design], "");\n }\n async stop(args) {\n const named = _ReposSkin.#arg(args, "folder");\n const owner = this.stamp.asker === _ReposSkin.#owner;\n if (!owner && named !== void 0) return this.error("refused", "a repo lobe reaches its own folder alone");\n const folder = owner ? named : this.cells.get(["lobe", this.stamp.asker]);\n const held = _ReposSkin.#text(folder) ? this.cells.get(["folder", folder]) : void 0;\n if (!_ReposSkin.#text(folder) || !_ReposSkin.#fields(held)) return this.error("refused", "no such folder");\n const doing = held["doing"];\n if (!_ReposSkin.#text(doing)) return this.error("refused", `the folder ${folder} runs nothing`);\n const asker = _ReposSkin.#arg(this.cells.get(["job", doing]) ?? null, "asker");\n if (!owner && asker !== this.stamp.asker)\n return this.error("refused", `the folder ${folder} runs another lobe\'s job`);\n const stopped = await this.ask("shell", "stop", { run: doing });\n if (!("error" in stopped)) return null;\n if (stopped.error.code !== "refused") return this.#heard(stopped);\n return this.#end(doing, -1, "", _ReposSkin.#lost);\n }\n async back(args) {\n if (this.stamp.asker !== _ReposSkin.#owner || _ReposSkin.#arg(args, "placeholder") !== "shell") return null;\n const going = [\n ...[this.cells.get(["setup"]), ...this.#all(["folder"]).map(({ value }) => value)].map(\n (held) => _ReposSkin.#arg(held ?? null, "doing")\n ),\n ...this.#all(["clearing"]).map(({ value }) => _ReposSkin.#arg(value, "run"))\n ].filter((run) => _ReposSkin.#text(run));\n const lost = going.length === 0 ? [] : await this.#lostOf(going) ?? [];\n for (const run of lost) await this.#end(run, -1, "", _ReposSkin.#lost);\n return null;\n }\n async ended(args) {\n const read = await this.nerves.read();\n await this.#torn(read);\n const { run, code, out, err } = _ReposSkin.#fields(args) ? args : {};\n const whole = typeof out === "string" && typeof err === "string" && typeof code === "number";\n if (!whole || !_ReposSkin.#text(run))\n return this.error("refused", "an end names its run, its exit code and its output");\n return this.#end(run, code, out, err, read);\n }\n async #end(job, code, out, err, read) {\n const run = job;\n const held = this.cells.get(["job", run]);\n if (!_ReposSkin.#fields(held) || held["ended"] !== null) return this.error("refused", "no such job going");\n const { asker, kind, folder } = held;\n if (kind === "clear") return this.#cleared(run, asker);\n this.cells.set(["job", run], { ...held, ended: { code } });\n if (_ReposSkin.#text(asker)) this.#endKept(asker, run);\n this.#settled(kind, folder, code);\n if (!_ReposSkin.#text(asker) || asker === _ReposSkin.#owner) return null;\n if (!_ReposSkin.#ends(read ?? await this.nerves.read()).has(asker)) return null;\n const told = { job: run, kind: kind ?? null, code, out, err };\n this.cells.set(["last", asker], told);\n const letter = { lives: _ReposSkin.#lives };\n return this.#heard(await this.ask(asker, "done", told, void 0, { letter }));\n }\n #cleared(run, asker) {\n for (const { key, value } of this.#all(["clearing"]))\n if (_ReposSkin.#arg(value, "run") === run) this.cells.delete(key);\n this.cells.delete(["job", run]);\n if (_ReposSkin.#text(asker)) this.cells.delete(["by", asker, run]);\n return null;\n }\n migrate() {\n if (this.stamp.asker !== _ReposSkin.#owner) return null;\n let cursor = null;\n do {\n const page = this.cells.range({ prefix: ["job"], limit: this.#most(), ...cursor === null ? {} : { cursor } });\n for (const { key, value } of page.cells) {\n if (!_ReposSkin.#fields(value) || value["ended"] === null) continue;\n this.cells.delete(key);\n if (_ReposSkin.#text(value["asker"]) && _ReposSkin.#text(key[1]))\n this.cells.delete(["by", value["asker"], key[1]]);\n }\n ({ cursor } = page);\n } while (cursor !== null);\n return null;\n }\n #endKept(asker, run) {\n const ends = this.cells.get(["ended", asker]);\n let first = Number(_ReposSkin.#arg(ends ?? null, "first") ?? 0);\n const next = Number(_ReposSkin.#arg(ends ?? null, "next") ?? 0);\n for (; next - first >= Math.max(1, this.#most()); first += 1) {\n const oldest = this.cells.get(["ended", asker, String(first)]);\n if (_ReposSkin.#text(oldest)) {\n this.cells.delete(["job", oldest]);\n this.cells.delete(["by", asker, oldest]);\n }\n this.cells.delete(["ended", asker, String(first)]);\n }\n this.cells.set(["ended", asker, String(next)], run);\n this.cells.set(["ended", asker], { first, next: next + 1 });\n }\n #settled(kind, folder, code) {\n if (kind === "setup") {\n const setup = this.cells.get(["setup"]);\n const failed = code === 0 ? null : "the marker was not read back";\n if (_ReposSkin.#fields(setup)) this.cells.set(["setup"], { ...setup, ready: code === 0, failed, doing: null });\n return;\n }\n const held = _ReposSkin.#text(folder) ? this.cells.get(["folder", folder]) : void 0;\n if (!_ReposSkin.#text(folder) || !_ReposSkin.#fields(held)) return;\n if (kind === "remove" && code === 0) {\n this.cells.delete(["folder", folder]);\n return;\n }\n const proven = (kind === "init" || kind === "stand" || kind === "head") && code === 0 ? { made: true } : {};\n this.cells.set(["folder", folder], { ...held, ...proven, doing: null });\n }\n jobs(args) {\n const { asker } = this.stamp;\n const page = this.#page(asker === _ReposSkin.#owner ? ["job"] : ["by", asker], args);\n if (!("cells" in page)) return page;\n const jobs = asker === _ReposSkin.#owner ? page.cells.map(({ value }) => value) : page.cells.map(({ key }) => this.cells.get(["job", key[2] ?? ""]) ?? null);\n return { jobs, cursor: page.cursor };\n }\n job(args) {\n const run = _ReposSkin.#arg(args, "job");\n if (!_ReposSkin.#text(run)) return this.error("refused", "a job is named by its id");\n const { asker } = this.stamp;\n const held = this.cells.get(["job", run]);\n const owns = asker === _ReposSkin.#owner || this.cells.get(["by", asker, run]) !== void 0;\n if (!owns || !_ReposSkin.#fields(held)) return this.error("absent", "no such job");\n return held;\n }\n async #back(folder) {\n const { asker } = this.stamp;\n if (this.cells.get(["lobe", asker]) !== folder || _ReposSkin.#ends(await this.nerves.read()).has(asker)) return null;\n const ordered = await this.nerves.order({ termination: asker });\n return "error" in ordered ? this.error("refused", `no wire back: ${ordered.error.message}`) : null;\n }\n #job(kind, more, input) {\n const own = this.#own();\n if (!("folder" in own)) return Promise.resolve(own);\n const at = this.#at();\n if (at === null) return Promise.resolve(this.error("refused", "the disk\'s folder is not set up"));\n const dir = `${at}/${_ReposSkin.#repos}/${own.folder}`;\n return this.#begin(kind, own.folder, [dir, ...more], input);\n }\n async #begin(kind, folder, words, input) {\n const record = await this.#unstuck(folder === null ? ["setup"] : ["folder", folder]);\n if (!_ReposSkin.#fields(record)) return this.error("refused", "no such folder");\n if (_ReposSkin.#text(record["doing"]))\n return this.error("refused", `${folder ?? "the setup"} runs ${record["doing"]} already`);\n const { asker } = this.stamp;\n const back = folder === null ? null : await this.#back(folder);\n if (back !== null) return back;\n const program = [..._ReposSkin.programs[kind], ...words];\n const begun = await this.ask("shell", "run", { program, input });\n if ("error" in begun) return this.error(begun.error.code, begun.error.message);\n const run = _ReposSkin.#arg(begun.result, "run");\n if (!_ReposSkin.#text(run)) return this.error("refused", "the shell named no run");\n this.cells.set(["job", run], { job: run, kind, asker, folder, ended: null });\n this.cells.set(["by", asker, run], null);\n this.cells.set(folder === null ? ["setup"] : ["folder", folder], { ...record, doing: run });\n return { job: run };\n }\n};\nexport {\n ReposSkin as default\n};\n';
1240
1240
 
1241
1241
  var REPOS = { faculty: REPOS_SOURCE, label: "repos" };
1242
1242
 
1243
- var REPO_SOURCE = 'import { Faculty } from "nervur:faculty";\n\nvar LETTER_LIVES = 864e5;\nvar LOBE_SHARE = 4;\nvar ITEM_SIZE = 1024;\nvar CELLS_RANGE = 1e3;\nvar ARG_LONGEST = 4096;\nvar ARGS_MOST = 64;\nvar RING_PAUSE = 1e3;\nvar TAIL = 4096;\nvar SCOPE_MOST = 16;\nvar STILL = 36e5;\nvar SPELL = 5e3;\nvar WITHIN = 36e5;\nvar MINUTE = 6e4;\n\nvar RepoLobe = class _RepoLobe extends Faculty {\n static #owner = "brain";\n static #library = "library";\n static #lives = LETTER_LIVES;\n static #every = RING_PAUSE;\n static #tail = TAIL;\n static #repoName = /^[a-z](?:[a-z0-9-]|\\.(?=[a-z0-9-])){0,63}$/;\n static #script = /^[A-Za-z0-9][A-Za-z0-9:._-]{0,63}$/;\n static #key = /^[A-Za-z_][A-Za-z0-9_]{0,63}$/;\n static #issued = /^(?=.{1,40}$)[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)*$/;\n static #spell = SPELL;\n static #issuerWithin = WITHIN;\n static #minute = MINUTE;\n static #argsMost = ARGS_MOST;\n static #argLongest = ARG_LONGEST;\n static #hash = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/;\n static #digest = /^[0-9a-f]{64}$/;\n static #version = /^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)$/;\n static #label = /^[a-z][a-z0-9]*(?:[.-][a-z0-9]+)*$/;\n static #id = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;\n static #tag = /^v(?:0|[1-9][0-9]*)\\.(?:0|[1-9][0-9]*)\\.(?:0|[1-9][0-9]*)$/;\n static #hashed = /^d ([0-9a-f]{64}) ((?:designs|faculties)\\/[^/]+)\\/(.+)$/;\n static #standings = ["reader", "writer", "library", "runner"];\n static #segment = /^[A-Za-z0-9._-]+$/;\n static #scopeMost = SCOPE_MOST;\n static #entry = /^(?!\\.{1,2}$)(?!\\.git$)[^/\\\\\\0]+$/i;\n static #lobe = "lobe";\n static #teller = "teller";\n static #tells = "tells";\n static #hears = "library";\n static #waits = ["timeout", "unavailable", "busy"];\n static #still = STILL;\n static #lifted = Math.floor(Number.MAX_SAFE_INTEGER / 2);\n static #onCommit = ["off", "on", "mandatory"];\n static #onPush = ["off", "on"];\n static #moves = ["init", "land", "commit"];\n static #writes = ["owner", "near"];\n static #offers = ["owner", "near", "library"];\n static #runs = ["owner", "near", "runner"];\n static #pulls = ["reader", "pusher"];\n static #who = {\n init: ["owner"],\n accept: ["owner"],\n relink: ["owner"],\n invite: ["owner"],\n drop: ["owner"],\n occupants: ["owner"],\n migrate: ["owner"],\n gate: ["owner"],\n gates: ["owner"],\n conform: ["owner"],\n author: ["owner"],\n remove: ["owner"],\n rebuild: ["owner"],\n state: ["owner", "near", "library"],\n jobs: _RepoLobe.#runs,\n job: _RepoLobe.#runs,\n pull: _RepoLobe.#writes,\n push: _RepoLobe.#writes,\n build: _RepoLobe.#writes,\n commit: _RepoLobe.#writes,\n status: _RepoLobe.#writes,\n log: _RepoLobe.#writes,\n discard: ["owner"],\n read: _RepoLobe.#writes,\n list: _RepoLobe.#writes,\n run: _RepoLobe.#runs,\n setToken: ["owner"],\n credential: ["owner"],\n stop: _RepoLobe.#writes,\n faculties: _RepoLobe.#offers,\n organs: _RepoLobe.#offers,\n designs: _RepoLobe.#offers,\n get: _RepoLobe.#offers,\n told: _RepoLobe.#offers,\n head: _RepoLobe.#pulls,\n give: _RepoLobe.#pulls,\n piece: _RepoLobe.#pulls,\n take: ["pusher"],\n taken: ["pusher"],\n done: ["jailer", "teller"]\n };\n static #some = { type: "string", minLength: 1 };\n static #maybe = { anyOf: [{ type: "string", minLength: 1 }, { type: "null" }] };\n static #place = { type: "integer", minimum: 0 };\n static #one = { type: "integer", minimum: 1 };\n static #span = { anyOf: [{ type: "integer", minimum: 0 }, { type: "null" }] };\n static #plain = { type: "string" };\n static #none = { type: "object", additionalProperties: false };\n static #named = { type: "string", pattern: "^[a-z][a-z0-9.-]{0,63}$" };\n static #fixed = { type: "string", maxLength: 64, pattern: "^[a-z][a-z0-9]*(-[a-z0-9]+)*$" };\n static #jobSchema = {\n type: "object",\n properties: { job: _RepoLobe.#some },\n required: ["job"],\n additionalProperties: false\n };\n static #object(properties, required = Object.keys(properties)) {\n return { type: "object", properties, required, additionalProperties: false };\n }\n static #over(properties, required = Object.keys(properties)) {\n return _RepoLobe.#object({ ...properties, name: _RepoLobe.#named }, required);\n }\n static #says = {\n init: "An owner: with `starter` true, the repo `name` born and its first commit the repo lobe\'s one small starter, a step of the same job; else the repo `name` born empty and ready in the folder the jailer grants, which holds nothing: it holds no commit, may give invitations, and what it begins with is laid by the first commit of its owner or the first push of the lobe that stands on it, whole, each checked as any. Never born again, since a folder holding a repo refuses it. With `standing` true: handed in place the repo the granted folder holds already, a lobe torn down having kept it, ready on its head and tags as they stand once its `main` passes the two checks, its `conform` as `main` holds it, which it chooses, nothing laid or moved, refused where no repo stands there. An init that failed may be asked again.",\n accept: "An owner: the repo `name` laid again from the lobe an invitation names, as a lost lobe is: made empty, standing on that lobe, and pulled whole from it, the pull a step of its one job, which ends on the pull’s code and check once it landed and was scanned. The mouth keeps `note` beside the standing the organism holds, the owner’s, else `{ repo, on }`, the repo and the placeholder it stands on by; it never travels. A lobe born of a scoped lobe notes the scope on that standing, and keeps that its bytes are cut beside its head.",\n relink: "An owner: stands on the lobe of the repo an invitation names, beside those it stands on, under a placeholder of its own, which it answers: `placeholder`, a name this lobe holds for nothing else; else, with `instead`, the name of the standing it replaces; else the next free `lobe-<n>`. With `instead`, the lobe it stood on under that placeholder is asked to `drop` this one\'s standing, and the relation ends: once the new one stands, or first where the new one takes its name, since a placeholder has one wire. The mouth keeps `note` beside the standing, the owner\'s, else `{ repo, on }`. Refused to a lobe born of a scope, which stands on no other.",\n setToken: "An owner: the key `name`, any environment variable\'s name, of this lobe, set to `value`, or removed where `value` is null; kept in this lobe\'s cells, never answered, masked in all it tells, and in `.env` from the next run.",\n credential: "An owner: takes the credential of an issuer\'s standing the organism holds, as the key `secret`. With `invitation`, the organism accepts it, the mouth keeping `note`, the owner\'s, beside the standing; with `placeholder`, a placeholder of this lobe an owner wired to a standing the organism holds already, refused where it reaches no standing or one this lobe keeps another key over. Either way this lobe writes its own note on the standing, `{ credential: secret }`, asks the issuer `credential`, again at the `ready` it answers while it makes it, and a few seconds on while it is silent, for as long as `within` names in milliseconds: the cap where it names none, and never more, an hour or an owner’s word over `within`, read in its nerves as it begins, a span past it refused; then failing, saying why, and keeps its `value`, masked and never answered; where it `expires`, it is asked again before then, by a tenth of its life, a renewal that fails keeping the value, asked again at half what is left and never within a minute, and told in `state`; answers `{ secret }`, with `pending` while the issuer makes it. Asked again with its `secret` alone it asks the issuer for a fresh one.",\n invite: "An owner: an invitation for one far organism, a `reader`, a `writer` or a `library`, kept by the ear for `waits` and its relation for `lives`, reached down a line to the address `through` where one is named. This lobe’s own note on the occupant, kept by the brain, is the owner’s `note`, if any, and `{ repo, standing }`, the repo and the kind of standing its far holds, and `scope` where one is named; this lobe reads the kind and the scope back from the stamp of each ask of that far, and keeps no cell of them; the note never travels with the invitation. A reader’s or a writer’s `scope`, 1 to 16 folders of the repo, each of names of letters, digits, `.`, `_` and `-`, none `.`, `..` nor `.git`, none inside another, kept sorted in that note and never in the invitation, so the standing reaches those folders alone; a library’s is refused, and a lobe born of a scope gives no occupant, for life.",\n drop: "An owner: ends the far organism `far`\'s relation and its standing, or this lobe\'s standing on the lobe it holds as `on`. A holder ends its own standing by its mouth\'s `drop`.",\n occupants: "An owner: each occupant of this lobe, its far organism and its role, a reader, a writer, a library or a runner, with its scope where it holds one, read from this lobe’s notes through its `nerves`.",\n left: "The brain\'s: an end this lobe gave or is granted ended, `far` with its `note`; whatever this lobe kept by that far, its pull and push pieces, forgotten; a pull or a push over a standing it was granted that ended ends. The repo\'s files and history stay as they stand.",\n migrate: "The brain, at a move to this version: each wired lobe whose wire back is gone, torn down, forgotten, its lines, where it held any, taken out at the next job’s end; a pull or a push standing is rung again: a fresh `chain` kept in it and its `tick` set by a letter, the old chain dying at its next ring; and a scan of the repo owed, so every tag’s files are kept before a version told is asked: begun where the repo has a head and runs nothing, no job and no pull or push, else at the first instant it does, found by a job’s end or a pull’s or a push’s or by an alarm of its own, and owed until a scan ends whole.",\n remove: "An owner: forgets the repo, once no far standing holds it and nothing runs; its bytes stay in the folder, for the jailer’s owner.",\n rebuild: "An owner, after a move or a restore: the repo made again empty, its head unanswered until it holds the head it kept, pulled whole from a lobe it stands on, a step of its one job, which ends once that pull ended, else pushed whole by one that stands on it, that push in once the head is proven.",\n state: "The repo: its name, head, whether it is ready, not where its folder holds no repo, `absent` then saying so and that `rebuild` fills it again, the job going, how its last pull or push ended, the lobes it stands on, how many far writers push to it, its folder on the host, its wired lobes, its gate and its settings, the commit whose `conform` its owner chose, and its author, the ends read from its `nerves`; `scopes`, each scoped occupant and its scope, and `scoped`, each lobe it stands on by a scope and that scope, where there are any; to the library, its name alone.",\n gate: "An owner: the script of the repo\'s package the gate runs, or null for none; `gate` where none was set.",\n gates: "An owner: the settings of the gate, `commit` and `push`, each only where named, answering both. On commit, `on` by default: a commit first runs the gate, with the repo’s `.env`, and is refused, with the gate’s tail, where it is red; `off` commits at once; `mandatory` is `on` and no commit skips it. On push, `off` by default: `on` runs the gate after the two checks on each push this lobe takes, and a red gate refuses it.",\n conform: "An owner: with `take` true, the repo’s `conform` as `main` holds it now chosen, the one that judges each commit, push and pull from then on, whoever changed it; with `take` false, none, what enters guarded by the check of the parts alone; answering the commit whose conform is chosen, or null. A commit of this lobe’s own that changes it chooses it too, and an `init` standing on a repo in place; nothing a writer pushes or a pull brings does.",\n author: "An owner: beside a lobe far writers push to, the one wired lobe whose commit it takes, as the spec’s wired lobe files a proposal, or null for none; no other commits there, an owner neither.",\n commit: "An owner\'s or a wired lobe\'s: `files`, each a path under the repo and its text, `executable` naming those of them that land executable, written first, then, where its setting on commit says so, the gate, with the repo\'s `.env`; then, in its own job, refused while a secret file stands that git would take, the check of the parts, handed what the latest tag told of each `versions.json` (a version told changed is refused), and the repo\'s `conform` as its owner chose it, none where it chose none, each over what it would commit laid out apart as a clone would hold it, so a file `.gitignore` keeps out counts as absent, and its root `package.json` `version` read against `HEAD`\'s, refused where it changed and is not three whole numbers, is lower by semver, or its tag stands already; then every change committed on `main` with `message`, tagged `v<version>` in the same job where it raised the version, a lobe holding a scope tagging none, its head taken and `main` scanned, the job\'s last step (`job`). `gate` false skips the gate, refused where the setting is `mandatory`; `gate` true asks it once where the setting is `off`. A red gate or a broken rule refuses it, saying why, and every file it wrote is put back as it was before the ask (removed where it stood not, its old text written where it did), in the same job, the refusal saying so; a commit without `files` is its owner\'s, of what the folder holds, and puts nothing back. With `paths`, each a file or a folder of the repo, no `files` beside them, it takes the changes of those paths alone, added, changed or removed, and leaves the rest of the folder as it stands; the gate still runs on the folder as it stands, the checks over `main` as the commit would leave it, and `paths` that hold no change refuse it, committing nothing. Beside a lobe far writers push to, its author\'s alone.",\n status: "A job: `git status` of the folder.",\n log: "A job: the last commits, `most` of them, twenty where none is named.",\n discard: "An owner: a job undoing every change since the last commit.",\n read: "A file\'s text, its first lines where `first` names how many, and how many lines it holds; or `paths` (one or more) alone, many files in one answer, as many as a quarter of what the jailer\'s lobe holds takes, `{ files }`, each `{ path, text }` or `{ path, absent: true }` in the order named, read in one ask of the jailer; the whole refused, saying why, where a path climbs or hides, a text is no UTF-8 or the texts weigh past what one answer carries.",\n list: "The names in a folder of the repo, its top where no path is named.",\n run: "A job, an owner\'s, a wired lobe\'s or a runner\'s, a runner\'s among the scripts its invitation names alone: the script `script` of the repo\'s `package.json` with `args`, each one argument after `--`, never read by a shell, with this lobe\'s keys, `.env` written whole first where it keeps any or wrote it before, its values masked in its output; a script without its key fails by its own words. With `install`, `npm ci` first where a lockfile stands, in the same job. Its end is told back by a letter to a wired lobe; an owner and a runner read it by `job`.",\n stop: "The asker\'s pull or push standing, an owner\'s any, ended failed, saying it was stopped, its job of the jailer\'s ending by itself unheeded, refused while it lands; else the asker\'s job going stopped through the jailer, an owner\'s any; one the shell runs no more ends at once, failed.",\n jobs: "The asker\'s jobs of this lobe\'s own, a build, an init, an owner\'s every one, each with `began`, the stamp time it began, and how it ended, `{ run, code, at }`, `at` the stamp time it ended, or null while it runs.",\n job: "One of the asker\'s jobs, `job`, whole, with `began` and `ended.at`, the stamp times it began and ended; an owner reads any, and one not the asker\'s is absent. A job that moved `main` ends once its last step, the scan of `main`, ended, the repo then running nothing, `ended.scan` the scan\'s `code` and the tail of why it failed, `err`, which fails no work.",\n pull: "A job: the commits of the lobe it stands on as `on`, the one it stands on where it names none, after its own HEAD, as a bundle in pieces over the relation, each of the bytes `piece` names, Quo\'s box where it names none, brought apart, checked by this lobe\'s two checks, the check of the parts and `conform` as its owner chose it, never as what came holds it, then brought into `main`, merged where it must, with the tags `v*` of the commits it brings, laid once `main` moved; a conflict, a rule broken or a tag this lobe holds on another commit refuses it, saying which. With `tag`, `v` and three whole numbers, `main` is brought up to the commit that tag names and no further, refused where the lobe pulled from holds no such tag, and nothing brought where `main` holds that commit already; a lobe holding a scope pulls by a tag too, the lobe pulled from cutting `main` to the scope up to that commit, and the tag’s name never enters the scoped lobe. `still` names how long it may stand still, in milliseconds, nothing taken and no stage moved, before it ends failed: the cap where it names none, and never more, an hour or an owner’s word over `still`.",\n push: "A job: its commits after the HEAD of the lobe it stands on as `on`, the one it stands on where it names none, sent in pieces, which that lobe checks by its own rules and brings into its `main`, or refuses, saying why; it carries the tags `v*` of the commits it sends, which that lobe lays once its `main` moved, or refuses the whole where it holds one on another commit; once its last piece is in it asks that lobe its end, `taken`, each ring, and ends with what it heard. With `tells`, the asker’s word that this organism can be dialed, its first piece gives that lobe a standing back, drawn fresh, the one before ended, over which that lobe tells its end, `done`, so the push asks nothing once its last piece is in and ends with what it was told. `piece` names the bytes of each piece, Quo’s box where it names none, what one lobe holds bounding it on either side. `still` names how long it may stand still, in milliseconds, nothing taken and no stage moved, before it ends failed: the cap where it names none, and never more, an hour or an owner’s word over `still`.",\n faculties: "Each faculty `main` holds, its label, version and digest, and its assets where its `assets/` holds any, each `[path, SHA-256]`, or why it is not told; absent where `faculties/` is not.",\n organs: "Each organ `main` holds, its ID, version and digests, or why it is not told; absent where `organs/` is not.",\n designs: "Each design `main` holds, its name, version and the digests of its data and its look, or why it is not told, a design told as its look, the faculty `<name>.look` with its assets; absent where `designs/` is not.",\n get: "A faculty\'s `{ source, digest }`, with `assets` where its `assets/` holds any, each `[path, SHA-256]`, its evidence among them; an organ\'s `{ blueprint, half }`; or a design\'s look, the faculty `<name>.look` at the design\'s version, once built, `{ source, digest, assets }`, its assets the design\'s data; at a version told, its bytes checked, and served as told whatever `main` holds after, its assets read from what the jailer kept of every tag by SHA-256, `absent` where a scan keeps them not yet, saying whether it is being kept, a scan running, or waits, a scan owed that begins once the repo runs nothing; with `path`, an asset of a faculty or a look `{ path, digest, bytes }`, its canonical bytes whole, whose SHA-256 is `digest`; with `version` null, a faculty or an organ as the folder holds it, to an owner or a writer alone.",\n build: "A job building the organ `organ`\'s host half at a version told, keeping the built half\'s digest; or the design `design`\'s look, by the repo\'s script `design`, keeping its source where it is the look `versions.json` told; either refused while `main` holds not that version, as the last scan found it.",\n told: "The versions the repo told, each with its digests; a version is told once a commit tagged `v<version>` holds it, and a scan of a head no tag names tells none. A far library may name `tells`, the invitation to a standing back on it, taken under `library-<far>`, the one before ended, over which this lobe tells it each version it tells after, `changed`, by an ask; it ends with that library’s standing.",\n head: "A far reader or writer: this lobe\'s HEAD, null while it rebuilds, and null to a scoped one, which pushes its scope whole.",\n give: "A far reader or writer: the commits after `since`, as a bundle in pieces once it is made, each of the bytes `piece` names, Quo’s box where it names none, with the tags `v*` naming commits among them; until then, not ready. With `tag`, `v` and three whole numbers, up to the commit that tag names and no further, refused where this lobe holds no such tag, and none where `since` holds that commit already; to a scoped one, `main` is cut to its scope up to the commit that tag names, which is the beginning of the cut to the head, and the bundle holds that cut’s commits after `since`, never a tag. A bundle that failed is refused once, then made again. To a scoped one, `main` is cut to its scope first, the same every time, and the bundle holds the cut’s commits after `since`, read against the cut, nothing of `main` outside the scope, no tag; its answer carries `scope`, which the lobe that pulls keeps, and from then gives no occupant.",\n piece: "A far reader or writer: the bundle\'s piece `at`.",\n take: "A far writer: the piece `at` of `pieces` of the push its writer names `push`, in order. The first may name `tells`, the invitation of the standing back its writer gives, which this lobe accepts under `tells-<far>`, the one it held of that writer before ended; once the push is in `main` or refused, a writer that gave one is told `done { job, kind, code, out, err, check }` over it by an ask, once. The same piece of the same push sent again, the same bytes, is answered as it was; a push named anew, from its first piece, is a new one, brought and checked anew by the rules as they stand, whatever came before; any other piece is refused as out of order. The last has this lobe bring it apart and check it by its two checks, and its gate where its setting on push is `on`; the tags it carries brought apart, the whole refused where one names no commit it brings or this lobe holds a tag of that name on another commit, and laid once `main` moved. A scoped writer\'s is grafted first, its tags not taken: refused unless it is linear on the scope\'s head as `main` is cut now, else as behind, and where a commit changes a path outside the scope; each commit grafted on `main`\'s tip, its tree `main`\'s with the scope\'s paths taken from it, its author, committer, times and message kept, and what `main` would become checked whole.",\n taken: "A far writer: the end of its last push, `{ job, kind, code, out, err, check }`, as `done` tells it, or `{ ready: false }` until it is in `main` or refused, with `waits`, what it waits on, where its last piece is in and the repo runs another job first: that job checked with the jailer, so one whose end was lost holds it not, and the push brought once the repo runs nothing. A scoped writer hears the head it pushed and its check\'s code alone.",\n renew: "The scheduler\'s alone: each credential waited on whose time came asked again, each due to be renewed renewed.",\n keep: "The scheduler\'s alone: a scan owed begins where the repo has a head and runs nothing, by the `chain` its alarm carries, the one the lobe keeps; where the repo runs a job, the jailer is asked of it first, so a job whose end was lost ends; answers `{ again }`, a minute on, while the scan is owed, begun or not, and null once it is no more owed; a ring of any other chain answers null and writes nothing.",\n tick: "The scheduler\'s alone: a pull or a push takes its next step, by the `chain` its alarm carries, the one the sync keeps; a tick of any other chain, or where no sync stands, answers null at once and writes nothing; each ring making one far ask at most, within the time the ring is given: a push\'s piece read through the jailer and taken, a pull\'s got and put through the jailer, one piece a ring; a ring that moved the work rings the next at once, as a job of the jailer ending does; one waiting on a job of the jailer is rung at once by that job\'s end or its loss, told at the shell\'s `back`, and meanwhile a minute on, each ring checking the job with the jailer, so one whose end was lost holds it not; one whose far answered not yet a second on; a push whose last piece is in asks its end, `taken`, a second on each ring, or, where it gave a standing back, asks nothing, since the lobe it went to tells its end, and rings again only to end it once it stood still for as long as it may; an ask timed out, unavailable or busy is asked again at the next ring, kept as `waits { why, since }`, any other far error ends it; one that moved not for as long as it may stand still, `still`, nothing taken and no stage changed, ends failed, naming what stood still, as data.",\n done: "The jailer\'s, a job ended; or, the lobe a push went to, over the standing back that push gave it: the push ended, `{ job, kind, code, out, err, check }`, landed with code 0 and the HEAD it left, or refused, saying why in `err`, and the push this lobe waits on ends with it. To a scoped writer, the head it pushed and its check’s code alone, a refusal telling that its check is red and no more."\n };\n static #reading(method, args) {\n const description = _RepoLobe.#says[method] ?? method;\n const typed = args === void 0 ? {} : { args };\n return { description, kind: "reading", ...typed, errors: ["refused", "absent"] };\n }\n static #writing(method, args) {\n return { ..._RepoLobe.#reading(method, args), kind: "writing" };\n }\n static #own = _RepoLobe.#over({}, []);\n static #which = _RepoLobe.#over(\n {\n kind: { enum: ["faculty", "organ"] },\n label: _RepoLobe.#some,\n version: _RepoLobe.#maybe,\n path: _RepoLobe.#some\n },\n ["kind", "label", "version"]\n );\n static #stillFor = { type: "integer", minimum: 1 };\n static #syncing = _RepoLobe.#over(\n { on: _RepoLobe.#some, piece: _RepoLobe.#one, still: _RepoLobe.#stillFor, tells: { const: true } },\n []\n );\n static #ringing = _RepoLobe.#over({ chain: _RepoLobe.#some }, ["chain"]);\n static #pulling = _RepoLobe.#over(\n { on: _RepoLobe.#some, tag: _RepoLobe.#some, piece: _RepoLobe.#one, still: _RepoLobe.#stillFor },\n []\n );\n static blueprint = {\n name: "nervur.repo",\n version: "0.2.67",\n description: "A repo lobe: one for each repo on each organism that holds it, its bytes kept by the jailer, `repos`, through which it reaches them alone. It keeps what the repo is there: its head; its gate and its settings; its wired lobes; and the versions of its faculties, organs and designs it told the library, `changed`, never told again with other bytes. A repo is born one of two ways: by its `init`, empty, filled by the first commit of its owner or a first push whole; or by its `accept` of an invitation, pulled whole. It commits, at an owner’s ask or a wired lobe’s, its gate first where its settings say; it guards its own `main` before anything enters it, a commit, a push, a pull, by Nervur’s check of the parts, which it holds, and the repo’s `conform` as its owner chose it, each over that tree checked out apart; it serves its wired lobes, each work a job, its end told back, and composes each secret file from their sets, keeping which names each holds by digest, never a value; it pulls and pushes, serves its readers, writers and libraries, and holds no secret. The lobes of the repo it stands on, any number, and its far standings, readers, writers and libraries, are the brain’s, each with this lobe’s own note: it keeps no record of them.",\n methods: {\n init: _RepoLobe.#writing(\n "init",\n _RepoLobe.#object({ name: _RepoLobe.#named, standing: { const: true }, starter: { const: true } }, ["name"])\n ),\n accept: _RepoLobe.#writing(\n "accept",\n _RepoLobe.#object({ name: _RepoLobe.#named, invitation: _RepoLobe.#some, note: {} }, ["name", "invitation"])\n ),\n relink: _RepoLobe.#writing(\n "relink",\n _RepoLobe.#object(\n { invitation: _RepoLobe.#some, instead: _RepoLobe.#some, placeholder: _RepoLobe.#fixed, note: {} },\n ["invitation"]\n )\n ),\n invite: _RepoLobe.#writing(\n "invite",\n _RepoLobe.#object(\n {\n standing: { enum: _RepoLobe.#standings },\n waits: _RepoLobe.#span,\n lives: _RepoLobe.#span,\n note: {},\n through: _RepoLobe.#some,\n scope: { type: "array", items: _RepoLobe.#some, minItems: 1, maxItems: SCOPE_MOST },\n scripts: { type: "array", items: _RepoLobe.#some, minItems: 1 }\n },\n ["standing"]\n )\n ),\n drop: {\n ..._RepoLobe.#writing("drop", _RepoLobe.#object({ far: _RepoLobe.#some, on: _RepoLobe.#some }, [])),\n irreversible: true\n },\n occupants: _RepoLobe.#reading("occupants"),\n left: _RepoLobe.#writing("left", _RepoLobe.#object({ far: _RepoLobe.#some, note: {} }, ["far"])),\n migrate: _RepoLobe.#writing("migrate"),\n remove: { ..._RepoLobe.#writing("remove", _RepoLobe.#own), irreversible: true },\n rebuild: _RepoLobe.#writing("rebuild", _RepoLobe.#own),\n state: _RepoLobe.#reading("state", _RepoLobe.#own),\n gate: _RepoLobe.#writing("gate", _RepoLobe.#object({ script: _RepoLobe.#maybe })),\n gates: _RepoLobe.#writing(\n "gates",\n _RepoLobe.#object({ commit: { enum: _RepoLobe.#onCommit }, push: { enum: _RepoLobe.#onPush } }, [])\n ),\n conform: _RepoLobe.#writing("conform", _RepoLobe.#object({ take: { type: "boolean" } })),\n author: _RepoLobe.#writing("author", _RepoLobe.#object({ lobe: _RepoLobe.#maybe })),\n commit: _RepoLobe.#writing(\n "commit",\n _RepoLobe.#object(\n {\n message: _RepoLobe.#some,\n files: { type: "object", additionalProperties: _RepoLobe.#plain },\n executable: { type: "array", items: _RepoLobe.#some },\n paths: { type: "array", items: _RepoLobe.#some, minItems: 1 },\n gate: { type: "boolean" }\n },\n ["message"]\n )\n ),\n status: _RepoLobe.#writing("status", _RepoLobe.#none),\n log: _RepoLobe.#writing("log", _RepoLobe.#object({ most: { type: "integer", minimum: 1 } }, [])),\n discard: { ..._RepoLobe.#writing("discard", _RepoLobe.#none), irreversible: true },\n read: _RepoLobe.#reading(\n "read",\n _RepoLobe.#object(\n {\n path: _RepoLobe.#some,\n first: _RepoLobe.#one,\n paths: { type: "array", items: _RepoLobe.#some, minItems: 1 }\n },\n []\n )\n ),\n list: _RepoLobe.#reading("list", _RepoLobe.#object({ path: _RepoLobe.#plain }, [])),\n run: _RepoLobe.#writing(\n "run",\n _RepoLobe.#object(\n {\n script: _RepoLobe.#some,\n args: { type: "array", items: _RepoLobe.#plain, maxItems: ARGS_MOST },\n install: { type: "boolean" }\n },\n ["script"]\n )\n ),\n setToken: _RepoLobe.#writing("setToken", _RepoLobe.#object({ name: _RepoLobe.#some, value: _RepoLobe.#maybe })),\n credential: _RepoLobe.#writing(\n "credential",\n _RepoLobe.#object(\n {\n invitation: _RepoLobe.#some,\n placeholder: _RepoLobe.#some,\n secret: _RepoLobe.#some,\n note: {},\n within: { type: "integer", minimum: 1 }\n },\n ["secret"]\n )\n ),\n stop: _RepoLobe.#writing("stop", _RepoLobe.#none),\n jobs: _RepoLobe.#reading("jobs"),\n job: _RepoLobe.#reading("job", _RepoLobe.#jobSchema),\n pull: _RepoLobe.#writing("pull", _RepoLobe.#pulling),\n push: _RepoLobe.#writing("push", _RepoLobe.#syncing),\n faculties: _RepoLobe.#reading("faculties"),\n organs: _RepoLobe.#reading("organs"),\n designs: _RepoLobe.#reading("designs"),\n get: _RepoLobe.#reading("get", _RepoLobe.#which),\n build: _RepoLobe.#writing(\n "build",\n _RepoLobe.#over({ organ: _RepoLobe.#some, design: _RepoLobe.#some, version: _RepoLobe.#some }, ["version"])\n ),\n told: _RepoLobe.#writing("told", _RepoLobe.#object({ tells: { type: "string", minLength: 1 } }, [])),\n head: _RepoLobe.#reading("head"),\n give: _RepoLobe.#writing(\n "give",\n _RepoLobe.#object({ since: _RepoLobe.#maybe, tag: _RepoLobe.#some, piece: _RepoLobe.#one }, ["since"])\n ),\n piece: _RepoLobe.#reading("piece", _RepoLobe.#object({ at: _RepoLobe.#place })),\n take: _RepoLobe.#writing(\n "take",\n _RepoLobe.#object(\n { push: _RepoLobe.#some, at: _RepoLobe.#place, pieces: _RepoLobe.#one, bytes: {}, tells: _RepoLobe.#some },\n ["push", "at", "pieces", "bytes"]\n )\n ),\n taken: _RepoLobe.#writing("taken", _RepoLobe.#none),\n tick: { ..._RepoLobe.#writing("tick", _RepoLobe.#ringing), askers: ["scheduler"] },\n keep: { ..._RepoLobe.#writing("keep", _RepoLobe.#ringing), askers: ["scheduler"] },\n renew: { ..._RepoLobe.#writing("renew"), askers: ["scheduler"] },\n done: _RepoLobe.#writing("done")\n },\n placeholders: {\n repos: "nervur.repos",\n ear: "nervur.ear",\n mouth: "nervur.mouth",\n scheduler: "nervur.scheduler",\n library: "nervur.library"\n }\n };\n static parts = `// SPDX-License-Identifier: FSL-1.1-ALv2\nimport { createHash } from \'node:crypto\';\nimport { existsSync, lstatSync, readFileSync, readdirSync } from \'node:fs\';\nimport { join, resolve } from \'node:path\';\n\nconst root = resolve(process.argv[2] ?? \'.\');\nconst LABEL = /^[a-z][a-z0-9]*(?:[.-][a-z0-9]+)*$/;\nconst ID = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;\nconst VERSION = /^(?:0|[1-9][0-9]*)\\\\.(?:0|[1-9][0-9]*)\\\\.(?:0|[1-9][0-9]*)$/;\nconst broken = [];\nconst say = (why) => {\n broken.push(why);\n};\nconst isFolder = (path) => existsSync(path) && lstatSync(path).isDirectory();\nconst isFile = (path) => existsSync(path) && lstatSync(path).isFile();\nconst fieldsAt = (path) => {\n try {\n const read = JSON.parse(readFileSync(path, \'utf8\'));\n return read !== null && typeof read === \'object\' && !Array.isArray(read) ? read : null;\n } catch {\n return null;\n }\n};\n\nconst partsOf = (convention, pattern, what, by) => {\n const at = join(root, convention);\n if (!existsSync(at)) return [];\n if (!isFolder(at)) {\n say(convention + \' is no folder: it holds a folder for each \' + what);\n return [];\n }\n return readdirSync(at)\n .filter((name) => !name.startsWith(\'.\'))\n .toSorted()\n .flatMap((name) => {\n if (!isFolder(join(at, name))) {\n say(convention + \'/\' + name + \' is no folder: \' + convention + \'/ holds a folder for each \' + what);\n return [];\n }\n if (!pattern.test(name)) {\n say(convention + \'/\' + name + \' is no \' + what + "\'s name: a " + what + \' is named by \' + by);\n return [];\n }\n return [name];\n });\n};\n\nconst sha = (bytes) => createHash(\'sha256\').update(bytes).digest(\'hex\');\nconst canonical = (bytes) =>\n bytes.includes(0) ? bytes : Buffer.from(bytes.toString(\'latin1\').replace(/\\\\r\\\\n?/g, \'\\\\n\'), \'latin1\');\nconst assetsOf = (at, below = \'\') =>\n readdirSync(join(at, below), { withFileTypes: true })\n .filter((entry) => !entry.name.startsWith(\'.\'))\n .flatMap((entry) => {\n const path = below === \'\' ? entry.name : below + \'/\' + entry.name;\n if (entry.isDirectory()) return assetsOf(at, path);\n return entry.isFile() ? [[path, sha(canonical(readFileSync(join(at, path))))]] : [];\n })\n .toSorted((one, other) => (one[0] < other[0] ? -1 : 1));\n\nfor (const label of partsOf(\'faculties\', LABEL, \'faculty\', \'its label, in lowercase\')) {\n const at = \'faculties/\' + label;\n const path = join(root, at, \'faculty.js\');\n if (!isFile(path)) {\n say(at + \' holds no faculty.js: a faculty is one module of JavaScript\');\n continue;\n }\n const bytes = readFileSync(path);\n const text = bytes.toString(\'utf8\');\n const named =\n /\\\\b([A-Za-z_$][\\\\w$]*)\\\\s*=\\\\s*class(?:\\\\s+[A-Za-z_$][\\\\w$]*)?\\\\s+extends\\\\s+Faculty\\\\b/.exec(text) ??\n /\\\\bclass\\\\s+([A-Za-z_$][\\\\w$]*)\\\\s+extends\\\\s+Faculty\\\\b/.exec(text);\n const exported =\n /\\\\bexport\\\\s+default\\\\s+class\\\\b[^{]*\\\\bextends\\\\s+Faculty\\\\b/.test(text) ||\n (named !== null &&\n (new RegExp(\'\\\\\\\\bexport\\\\\\\\s+default\\\\\\\\s+\' + named[1] + \'\\\\\\\\b\').test(text) ||\n new RegExp(\'\\\\\\\\bexport\\\\\\\\s*\\\\\\\\{\\\\\\\\s*\' + named[1] + \'\\\\\\\\s+as\\\\\\\\s+default\\\\\\\\s*\\\\\\\\}\').test(text)));\n if (!/\\\\bimport\\\\s*\\\\{[^}]*\\\\bFaculty\\\\b[^}]*\\\\}\\\\s*from\\\\s*[\'"]nervur:faculty[\'"]/.test(text) || !exported)\n say(at + \'/faculty.js exports as its default no class extending Faculty from nervur:faculty\');\n const from = text.search(/\\\\bstatic\\\\s+blueprint\\\\s*=/);\n const blueprint = from < 0 ? \'\' : text.slice(from);\n const name = /\\\\bname\\\\s*:\\\\s*[\'"]([^\'"\\\\n]+)[\'"]/.exec(blueprint)?.[1];\n const version = /\\\\bversion\\\\s*:\\\\s*[\'"]([^\'"\\\\n]+)[\'"]/.exec(blueprint)?.[1];\n if (name === undefined || version === undefined || !VERSION.test(version)) {\n say(at + \'/faculty.js holds no blueprint naming its name and its version\');\n continue;\n }\n const versions = fieldsAt(join(root, at, \'versions.json\'));\n const digest = createHash(\'sha256\').update(bytes).digest(\'hex\');\n if (versions === null) say(at + \' holds no versions.json naming each version by its digest\');\n else if (versions[version] !== digest) say(at + \'/faculty.js is not the text its versions.json names at \' + version);\n const digested = /\\\\bassets\\\\s*:\\\\s*[\'"]([0-9a-f]{64})[\'"]/.exec(blueprint)?.[1];\n const held = isFolder(join(root, at, \'assets\')) ? assetsOf(join(root, at, \'assets\')) : [];\n if (digested === undefined && held.length > 0)\n say(at + \'/assets holds files its blueprint names no assets digest for\');\n else if (digested !== undefined && sha(JSON.stringify(held)) !== digested)\n say(at + \'/assets is not the digest its blueprint names as assets, \' + digested);\n}\n\nfor (const id of partsOf(\'organs\', ID, \'organ\', \'its fixed ID, in lowercase\')) {\n const at = \'organs/\' + id;\n const graph = fieldsAt(join(root, at, \'graph.json\'));\n const version = graph === null ? undefined : (graph.version ?? graph.blueprint?.version);\n if (graph === null || typeof version !== \'string\' || !VERSION.test(version))\n say(at + \' holds no graph.json, its blueprint with its version\');\n if (!isFile(join(root, at, \'host/build\'))) say(at + \' holds no host/build, which builds its host half\');\n}\n\nconst sheetsIn = (at, below = \'\') =>\n readdirSync(join(at, below), { withFileTypes: true }).flatMap((entry) => {\n const path = below === \'\' ? entry.name : below + \'/\' + entry.name;\n if (entry.isDirectory()) return sheetsIn(at, path);\n return path === \'layers.json\' ? [] : [path];\n });\n\nfor (const name of partsOf(\'designs\', LABEL, \'design\', \'its name, in lowercase\')) {\n const at = \'designs/\' + name;\n const design = fieldsAt(join(root, at, \'design.json\'));\n if (design === null || design.name !== name || typeof design.version !== \'string\' || !VERSION.test(design.version))\n say(at + \' holds no design.json naming it and its version\');\n const tokens = {};\n for (const file of [\'light\', \'dark\', \'tints\']) {\n tokens[file] = fieldsAt(join(root, at, \'tokens\', file + \'.json\'));\n if (tokens[file] === null) say(at + \' holds no tokens/\' + file + \'.json\');\n }\n if (design !== null) {\n const where = at + \'/design.json\';\n if (typeof design.publisher !== \'string\' || design.publisher === \'\') say(where + \' names no publisher\');\n const themes = Array.isArray(design.themes) ? design.themes : [];\n if (!themes.includes(\'light\') || !themes.includes(\'dark\')) say(where + \' names no themes light and dark\');\n if (!Array.isArray(design.tints)) say(where + \' names its tints as no list\');\n else if (tokens.tints !== null)\n for (const tint of design.tints)\n if (typeof tint !== \'string\' || !Object.hasOwn(tokens.tints, tint))\n say(where + \' names the tint \' + String(tint) + \', which tokens/tints.json holds not\');\n }\n const layers = fieldsAt(join(root, at, \'skin/layers.json\'));\n if (layers === null) say(at + \' holds no skin/layers.json\');\n else {\n const where = at + \'/skin/layers.json\';\n const named = [];\n for (const layer of [\'lobes\', \'home\']) {\n const sheets = Array.isArray(layers[layer]) ? layers[layer] : [];\n for (const sheet of sheets) {\n if (typeof sheet !== \'string\' || sheet === \'\') say(where + \' names a sheet that is no name in \' + layer);\n else if (named.includes(sheet)) say(where + \' names \' + sheet + \' more than once\');\n else if (!isFile(join(root, at, \'skin\', sheet))) say(where + \' names \' + sheet + \', which skin/ holds not\');\n named.push(sheet);\n }\n }\n for (const sheet of sheetsIn(join(root, at, \'skin\')).toSorted())\n if (!named.includes(sheet)) say(at + \'/skin/\' + sheet + \' is named by no layer of skin/layers.json\');\n }\n if (isFolder(join(root, at, \'fonts\'))) {\n const where = at + \'/fonts/fonts.json\';\n const manifest = fieldsAt(join(root, where));\n const faces = manifest !== null && Array.isArray(manifest.faces) ? manifest.faces : null;\n if (faces === null) say(at + \' holds no fonts/fonts.json naming its faces\');\n else\n for (const face of faces) {\n const file = face !== null && typeof face === \'object\' ? face.file : undefined;\n const licence = face !== null && typeof face === \'object\' ? face.licence : undefined;\n if (typeof file !== \'string\' || file === \'\') say(where + \' names a face with no file\');\n else {\n if (!isFile(join(root, at, \'fonts\', file))) say(where + \' names \' + file + \', which fonts/ holds not\');\n if (typeof licence !== \'string\' || licence === \'\')\n say(where + \' names the face \' + file + \' with no licence\');\n }\n if (typeof licence === \'string\' && licence !== \'\' && !isFile(join(root, at, \'fonts\', licence)))\n say(where + \' names the licence \' + licence + \', which fonts/ holds not\');\n }\n }\n if (fieldsAt(join(root, at, \'versions.json\')) === null) say(at + \' holds no versions.json\');\n}\n\nconst sorted = (value) =>\n value !== null && typeof value === \'object\' && !Array.isArray(value)\n ? Object.fromEntries(\n Object.keys(value)\n .toSorted()\n .map((key) => [key, sorted(value[key])]),\n )\n : value;\nconst same = (one, other) => JSON.stringify(sorted(one)) === JSON.stringify(sorted(other));\nconst told = process.argv[3] === undefined ? null : fieldsAt(resolve(process.argv[3]));\nif (told !== null)\n for (const path of Object.keys(told).toSorted()) {\n if (!/^(?:faculties|designs)\\\\/[^/]+\\\\/versions\\\\.json$/.test(path) || typeof told[path] !== \'string\') continue;\n let was = null;\n try {\n was = JSON.parse(told[path]);\n } catch {}\n if (was === null || typeof was !== \'object\' || Array.isArray(was)) continue;\n if (!isFolder(join(root, path, \'..\'))) continue;\n const now = fieldsAt(join(root, path));\n for (const version of Object.keys(was).toSorted())\n if (now === null || !Object.hasOwn(now, version) || !same(now[version], was[version]))\n say(path + \' no longer holds \' + version + \' as the tag told it\');\n }\n\nconst rootManifest = fieldsAt(join(root, \'package.json\'));\nfor (const field of [\'dependencies\', \'devDependencies\', \'peerDependencies\', \'optionalDependencies\']) {\n const held = rootManifest?.[field];\n if (held !== null && typeof held === \'object\' && \'@nervur.org/genome\' in held)\n say(\n \'package.json names @nervur.org/genome in \' +\n field +\n \': the organism lends the genome it runs, a repo names none\',\n );\n}\n\nif (existsSync(join(root, \'.env\')))\n say(\'.env would enter main: .gitignore keeps it not out, and a secret file is never committed\');\n\nif (broken.length > 0) {\n console.log(broken.join(\'\\\\n\'));\n process.exit(1);\n}\nconsole.log(\'parts: each part stands as its folder says\');\n`;\n static #order(a, b) {\n return a < b ? -1 : a > b ? 1 : 0;\n }\n static #fields(data) {\n return !!data && typeof data === "object" && !Array.isArray(data) && !ArrayBuffer.isView(data);\n }\n static #text(data) {\n return typeof data === "string" && data !== "";\n }\n static #texts(data) {\n return Array.isArray(data) ? data.flatMap((one) => _RepoLobe.#text(one) ? [one] : []) : [];\n }\n static #arg(args, key) {\n return _RepoLobe.#fields(args) ? args[key] : void 0;\n }\n static #shown(data) {\n return typeof data === "string" ? data : "none";\n }\n static #lastLine(text) {\n return text.trim().split("\\n").pop() ?? "";\n }\n static #headOf(out) {\n const last = _RepoLobe.#lastLine(out);\n return _RepoLobe.#hash.test(last) ? last : null;\n }\n static #lone = /[\\uD800-\\uDBFF](?![\\uDC00-\\uDFFF])|(?<![\\uD800-\\uDBFF])[\\uDC00-\\uDFFF]/g;\n #bytes(text) {\n const encoded = this.codec.utf8(text.replace(_RepoLobe.#lone, "�"));\n return "bytes" in encoded ? encoded.bytes : null;\n }\n static #json(text) {\n try {\n const read = JSON.parse(text);\n return _RepoLobe.#fields(read) ? read : null;\n } catch {\n return null;\n }\n }\n static #holds(read, placeholder) {\n const all = "result" in read && Array.isArray(read.result) ? read.result : [];\n return all.some((one) => _RepoLobe.#fields(one) && one["placeholder"] === placeholder);\n }\n static #wiredTo(read, placeholder) {\n const all = "result" in read && Array.isArray(read.result) ? read.result : [];\n const wire = all.find((one) => _RepoLobe.#fields(one) && one["placeholder"] === placeholder);\n return _RepoLobe.#fields(wire) ? wire["termination"] ?? null : null;\n }\n #alarm(args) {\n return this.ask("scheduler", "set", args, void 0, { letter: { lives: _RepoLobe.#lives } });\n }\n #heard(answer) {\n return "error" in answer ? this.error(answer.error.code, answer.error.message) : null;\n }\n #result(answer) {\n return "error" in answer ? this.error(answer.error.code, answer.error.message) : answer.result;\n }\n #digestOf(text) {\n const bytes = this.#bytes(text);\n return bytes === null ? "" : this.#shaOf(bytes);\n }\n #shaOf(bytes) {\n const hash = this.crypto.sha256(bytes);\n return hash instanceof Uint8Array ? Array.from(hash, (byte) => byte.toString(16).padStart(2, "0")).join("") : "";\n }\n static #canonical(bytes) {\n if (bytes.includes(0)) return bytes;\n const out = [];\n for (let at = 0; at < bytes.length; at += 1) {\n const byte = bytes[at] ?? 0;\n out.push(byte === 13 ? 10 : byte);\n if (byte === 13 && bytes[at + 1] === 10) at += 1;\n }\n return Uint8Array.from(out);\n }\n #nonce() {\n return Array.from(this.stamp.seed.slice(0, 6), (byte) => byte.toString(16).padStart(2, "0")).join("");\n }\n #most() {\n return Math.min(CELLS_RANGE, Math.floor(this.memory / LOBE_SHARE / ITEM_SIZE));\n }\n #all(prefix) {\n return this.cells.range({ prefix: [...prefix], limit: this.#most() }).cells;\n }\n static #relation(data) {\n if (!_RepoLobe.#fields(data)) return null;\n const { far, side, placeholder, note } = data;\n if (!_RepoLobe.#text(far) || side !== "occupant" && side !== "standing") return null;\n return { far, side, placeholder: _RepoLobe.#text(placeholder) ? placeholder : null, note: note ?? null };\n }\n async #relations() {\n const all = [];\n let cursor = null;\n for (const seen = new Set(); ; ) {\n const read = await this.ask("nerves", "relations", cursor === null ? {} : { cursor });\n const result = "result" in read ? read.result : null;\n const found = _RepoLobe.#arg(result, "relations");\n for (const one of Array.isArray(found) ? found : []) {\n const relation = _RepoLobe.#relation(one);\n if (relation !== null) all.push(relation);\n }\n const next = _RepoLobe.#arg(result, "cursor");\n if (!_RepoLobe.#text(next) || seen.has(next)) break;\n seen.add(next);\n cursor = next;\n }\n return all;\n }\n async #endOfFar(far) {\n const read = await this.ask("nerves", "relation", { far });\n return "result" in read ? _RepoLobe.#relation(read.result) : null;\n }\n async #held() {\n const all = await this.#relations();\n return all.filter((one) => one.side === "standing" && !_RepoLobe.#tellsOn(one)).toSorted((a, b) => _RepoLobe.#order(a.placeholder ?? "", b.placeholder ?? ""));\n }\n async #given() {\n return (await this.#relations()).filter(\n (one) => one.side === "occupant" && _RepoLobe.#kindOf(one.note) !== _RepoLobe.#teller\n );\n }\n static #backUnder(prefix, far) {\n return `${prefix}-${far.toLowerCase()}`;\n }\n static #tellsOn(one) {\n return _RepoLobe.#text(_RepoLobe.#arg(one.note, "credential")) || [_RepoLobe.#tells, _RepoLobe.#hears].some((prefix) => one.placeholder?.startsWith(`${prefix}-`) === true);\n }\n async #untell(on) {\n for (const one of await this.#relations())\n if (one.side === "occupant" && _RepoLobe.#kindOf(one.note) === _RepoLobe.#teller && _RepoLobe.#arg(one.note, "on") === on)\n await this.ask("ear", "drop", { far: one.far });\n }\n static #kindOf(note) {\n const kind = _RepoLobe.#arg(note, "standing");\n return typeof kind === "string" && (_RepoLobe.#standings.includes(kind) || kind === _RepoLobe.#teller) ? kind : null;\n }\n static #scopeIn(note) {\n const scope = _RepoLobe.#arg(note, "scope");\n return Array.isArray(scope) ? _RepoLobe.#texts(scope) : null;\n }\n async #noted(far, note) {\n const wrote = await this.ask("nerves", "note", { far, note });\n return "error" in wrote ? wrote.error.message : null;\n }\n #repo() {\n const repo = this.cells.get(["repo"]);\n return _RepoLobe.#fields(repo) ? repo : null;\n }\n #role() {\n const { asker } = this.stamp;\n if (asker === _RepoLobe.#owner) return "owner";\n if (asker === _RepoLobe.#library) return "library";\n const occupant = this.stamp.occupant;\n if (occupant !== null && occupant.far === asker) {\n const kind = _RepoLobe.#arg(occupant.note, "standing");\n if (kind === "writer") return "pusher";\n if (kind === _RepoLobe.#teller) return "teller";\n if (kind === "reader" || kind === "library" || kind === "runner") return kind;\n return "stood";\n }\n const repo = this.#repo();\n if (repo !== null && repo["jailer"] === asker) return "jailer";\n return "near";\n }\n #refusal(method, args) {\n if (!(_RepoLobe.#who[method] ?? []).includes(this.#role()))\n return this.error("refused", `${method} is not the asker\'s to ask`);\n const repo = this.#repo();\n const named = _RepoLobe.#arg(args, "name");\n if (repo !== null && named !== void 0 && !["init", "accept"].includes(method) && named !== repo["name"])\n return this.error(\n "refused",\n `this lobe keeps the repo ${_RepoLobe.#shown(repo["name"])}, not ${_RepoLobe.#shown(named)}`\n );\n return null;\n }\n #ready() {\n const repo = this.#repo();\n if (repo === null || repo["ready"] !== true || !_RepoLobe.#text(repo["name"]))\n return this.error("refused", "the repo is not ready");\n return { name: repo["name"], repo };\n }\n async #jailer() {\n const jailer = _RepoLobe.#wiredTo(await this.nerves.read(), "repos");\n return _RepoLobe.#text(jailer) ? jailer : this.error("refused", "the lobe is wired to no repos");\n }\n #unmade(name) {\n if (!_RepoLobe.#text(name) || !_RepoLobe.#repoName.test(name))\n return this.error("refused", "a repo is named in lowercase, a letter first");\n const repo = this.#repo();\n const failed = repo !== null && repo["ready"] !== true && repo["head"] === null && repo["rebuilds"] === null && !_RepoLobe.#text(repo["doing"]) && _RepoLobe.#text(repo["failed"]);\n if (repo !== null && !failed)\n return this.error("refused", `the lobe keeps the repo ${_RepoLobe.#shown(repo["name"])} already`);\n return name;\n }\n static #fresh(name, jailer) {\n return {\n name,\n head: null,\n ready: false,\n failed: null,\n doing: null,\n synced: null,\n jailer,\n rebuilds: null\n };\n }\n async init(args) {\n const refused = this.#refusal("init", args);\n if (refused !== null) return refused;\n const name = this.#unmade(_RepoLobe.#arg(args, "name"));\n if (typeof name !== "string") return name;\n const unchecked = this.checked("init", args);\n if (unchecked !== void 0) return unchecked;\n const standing = _RepoLobe.#arg(args, "standing") === true;\n const starter = _RepoLobe.#arg(args, "starter") === true;\n if (standing && starter)\n return this.error("refused", "a repo handed in place keeps what it holds, and takes no starter");\n const jailer = await this.#jailer();\n if (typeof jailer !== "string") return jailer;\n this.cells.set(["repo"], _RepoLobe.#fresh(name, jailer));\n if (standing) return this.#begin("init", this.#checks(), null, { method: "stand" });\n return this.#begin("init", {}, null, starter ? { more: { starter: true } } : {});\n }\n #starterOf(name) {\n const version = "0.1.0";\n const label = `com.example.${name}`;\n const source = `import { Faculty } from \'nervur:faculty\';\n\nexport default class extends Faculty {\n static blueprint = { name: \'${label}\', version: \'${version}\', placeholders: {}, methods: { hello: { kind: \'reading\' } } };\n hello() { return \'hello from ${name}\'; }\n}\n`;\n const conform = `// This repo\'s own rules, run over what would enter its main. A rule broken prints why and exits 1.\nconsole.log(\'conform: no rule of this repo is broken\');\n`;\n const scripts = { gate: "node tools/conform.mjs", conform: "node tools/conform.mjs" };\n return {\n ".gitignore": ".env\\nnode_modules/\\ndist/\\n",\n "package.json": `${JSON.stringify({ name, version, private: true, scripts }, null, 2)}\n`,\n "tools/conform.mjs": conform,\n [`faculties/${label}/faculty.js`]: source,\n [`faculties/${label}/versions.json`]: `${JSON.stringify({ [version]: this.#digestOf(source) }, null, 2)}\n`\n };\n }\n async #layStarter(run, asker) {\n const name = _RepoLobe.#shown(this.#repo()?.["name"]);\n for (const [path, text] of Object.entries(this.#starterOf(name))) {\n const wrote = await this.ask("repos", "write", { path, text });\n if ("error" in wrote) return `${path}: ${wrote.error.message}`;\n }\n const begun = await this.#begin(\n "commit",\n { message: "the starter", ...this.#checks() },\n { commit: run },\n { asker }\n );\n return "job" in begun ? null : begun.message;\n }\n async #link(invitation, placeholder, name, note) {\n if (!_RepoLobe.#text(invitation)) return this.error("refused", "an invitation is named");\n const held = note === void 0 ? { repo: name ?? null, on: placeholder } : note;\n const accepted = await this.ask("mouth", "accept", { invitation, placeholder, note: held });\n if ("error" in accepted) return this.error(accepted.error.code, accepted.error.message);\n const far = _RepoLobe.#arg(accepted.result, "far");\n if (!_RepoLobe.#text(far)) return this.error("refused", "the mouth named no far organism");\n return { placeholder, far };\n }\n async #free() {\n const held = new Set((await this.#held()).map((one) => one.placeholder));\n let at = 1;\n while (held.has(`${_RepoLobe.#lobe}-${at}`)) at += 1;\n return `${_RepoLobe.#lobe}-${at}`;\n }\n async #standingOn(on) {\n const all = await this.#held();\n if (on !== void 0) {\n const one = all.find((held) => held.placeholder === on);\n return one === void 0 || one.placeholder === null ? this.error("absent", `this lobe stands on no lobe as ${_RepoLobe.#shown(on)}`) : { placeholder: one.placeholder, far: one.far };\n }\n const [only] = all;\n if (only === void 0 || only.placeholder === null)\n return this.error("refused", "this lobe stands on no other: relink it");\n if (all.length > 1) return this.error("refused", "this lobe stands on several: name the one, `on`");\n return { placeholder: only.placeholder, far: only.far };\n }\n async accept(args) {\n const refused = this.#refusal("accept", args);\n if (refused !== null) return refused;\n const name = this.#unmade(_RepoLobe.#arg(args, "name"));\n if (typeof name !== "string") return name;\n const jailer = await this.#jailer();\n if (typeof jailer !== "string") return jailer;\n const placeholder = await this.#free();\n const linked = await this.#link(_RepoLobe.#arg(args, "invitation"), placeholder, name, _RepoLobe.#arg(args, "note"));\n if (!("far" in linked)) return linked;\n this.cells.set(["repo"], _RepoLobe.#fresh(name, jailer));\n return this.#begin("init", {}, null, { more: { pulls: placeholder } });\n }\n async relink(args) {\n const refused = this.#refusal("relink", args);\n if (refused !== null) return refused;\n if (this.#holdsScope()) return this.error("refused", "a lobe born of a scope stands on no other");\n if (this.cells.get(["sync"]) !== void 0)\n return this.error("refused", "the repo pulls or pushes: wait for it to end");\n const instead = _RepoLobe.#arg(args, "instead");\n const was = instead === void 0 ? null : await this.#standingOn(instead);\n if (was !== null && !("far" in was)) return was;\n const replaced = was === null ? null : was["placeholder"];\n const named = _RepoLobe.#arg(args, "placeholder");\n if (typeof named === "string" && named !== replaced && _RepoLobe.#holds(await this.nerves.read(), named))\n return this.error("refused", `this lobe holds ${named} already`);\n const placeholder = typeof named === "string" ? named : _RepoLobe.#text(replaced) ? replaced : await this.#free();\n const taken = was !== null && placeholder === replaced;\n if (taken) await this.#unlink(was);\n const name = this.#repo()?.["name"];\n const linked = await this.#link(_RepoLobe.#arg(args, "invitation"), placeholder, name, _RepoLobe.#arg(args, "note"));\n if (!("far" in linked)) return linked;\n if (was !== null && !taken) await this.#unlink(was);\n return { on: placeholder, far: linked["far"] ?? null };\n }\n async #unlink(was) {\n const placeholder = was["placeholder"];\n if (!_RepoLobe.#text(placeholder)) return;\n if (!placeholder.startsWith(`${_RepoLobe.#tells}-`)) await this.#untell(placeholder);\n if (_RepoLobe.#text(was["far"])) await this.ask("mouth", "drop", { far: was["far"] });\n await this.nerves.unwire(placeholder);\n }\n async invite(args) {\n const refused = this.#refusal("invite", args);\n if (refused !== null) return refused;\n const ready = this.#ready();\n if (!("name" in ready)) return ready;\n if (this.#holdsScope()) return this.error("refused", "a lobe holding a scope gives no occupant");\n const standing = _RepoLobe.#arg(args, "standing");\n if (typeof standing !== "string" || !_RepoLobe.#standings.includes(standing))\n return this.error("refused", "a standing is a reader, a writer, a library or a runner");\n const scripts = _RepoLobe.#arg(args, "scripts");\n const named = Array.isArray(scripts) ? scripts : [];\n if (standing === "runner" && (named.length === 0 || !named.every((one) => _RepoLobe.#text(one) && _RepoLobe.#script.test(one))))\n return this.error("refused", "a runner runs scripts of the repo\'s package, one or more");\n if (standing !== "runner" && scripts !== void 0)\n return this.error("refused", "scripts are a runner’s alone");\n const asked = _RepoLobe.#arg(args, "scope");\n const scope = asked === void 0 ? null : _RepoLobe.#scopeOf(asked);\n if (asked !== void 0 && (standing === "library" || standing === "runner"))\n return this.error("refused", `a ${standing}\'s standing is never scoped`);\n if (asked !== void 0 && scope === null)\n return this.error(\n "refused",\n `a scope is 1 to ${_RepoLobe.#scopeMost} folders of the repo, each of names of letters, digits, ., _ and -, none ., .. nor .git, none inside another`\n );\n const waits = _RepoLobe.#arg(args, "waits") ?? null;\n const lives = _RepoLobe.#arg(args, "lives") ?? null;\n const owned = _RepoLobe.#arg(args, "note");\n const base = owned === void 0 || owned === null ? {} : _RepoLobe.#fields(owned) ? owned : { note: owned };\n const note = {\n ...base,\n repo: ready.name,\n standing,\n ...scope === null ? {} : { scope },\n ...standing === "runner" ? { scripts: named } : {}\n };\n const through = _RepoLobe.#arg(args, "through");\n const line = through === void 0 ? {} : { through };\n const invited = await this.ask("ear", "invite", { waits, lives, note, ...line });\n if ("error" in invited) return this.#heard(invited);\n const far = _RepoLobe.#arg(invited.result, "far");\n if (!_RepoLobe.#text(far)) return this.error("refused", "the ear named no far organism");\n return invited.result;\n }\n static #scopeOf(scope) {\n if (!Array.isArray(scope) || scope.length < 1 || scope.length > _RepoLobe.#scopeMost) return null;\n const folders = scope.flatMap((one) => typeof one === "string" ? [one] : []);\n const fit = (one) => one.split("/").every((name) => _RepoLobe.#segment.test(name) && ![".", "..", ".git"].includes(name));\n if (folders.length !== scope.length || !folders.every(fit)) return null;\n const sorted = folders.toSorted();\n const nested = sorted.some(\n (one, at) => sorted.some((other, by) => by !== at && (one === other || one.startsWith(`${other}/`)))\n );\n return nested ? null : sorted;\n }\n #scopeOfAsker() {\n const occupant = this.stamp.occupant;\n return occupant === null ? null : _RepoLobe.#scopeIn(occupant.note);\n }\n async #scopeFor(far) {\n if (this.stamp.occupant?.far === far) return this.#scopeOfAsker();\n const found = await this.#endOfFar(far);\n return found === null ? null : _RepoLobe.#scopeIn(found.note);\n }\n #holdsScope() {\n return this.#repo()?.["cut"] === true;\n }\n async drop(args) {\n const refused = this.#refusal("drop", args);\n if (refused !== null) return refused;\n const [named, on] = [_RepoLobe.#arg(args, "far"), _RepoLobe.#arg(args, "on")];\n if (on !== void 0) {\n const held = await this.#standingOn(on);\n if (!("far" in held)) return held;\n if (_RepoLobe.#arg(this.cells.get(["sync"]), "on") === on)\n return this.error("refused", "the repo pulls or pushes over it: wait for it to end");\n await this.#unlink(held);\n return null;\n }\n const secret = _RepoLobe.#arg(args, "secret");\n if (secret !== void 0) {\n const issued = (await this.#credentials()).find((one) => one.secret === secret);\n if (issued === void 0) return this.error("absent", "no credential is kept by that secret");\n return this.#forgo(issued);\n }\n const far = named;\n const given = _RepoLobe.#text(far) ? await this.#endOfFar(far) : null;\n if (!_RepoLobe.#text(far) || given === null || given.side !== "occupant")\n return this.error("absent", "no standing is held by that far organism");\n const dropped = await this.ask("ear", "drop", { far });\n if ("error" in dropped) return this.#heard(dropped);\n await this.#forgetFar(far, given.note);\n return null;\n }\n async left(args) {\n const far = _RepoLobe.#arg(args, "far");\n if (_RepoLobe.#text(far)) await this.#forgetFar(far, _RepoLobe.#arg(args, "note") ?? null);\n if (_RepoLobe.#text(far)) {\n this.cells.delete(["token", far]);\n this.cells.delete(["credential", far]);\n }\n const on = _RepoLobe.#arg(_RepoLobe.#arg(args, "note"), "on");\n if (_RepoLobe.#text(on) && !(await this.#held()).some((one) => one.placeholder === on)) await this.#untell(on);\n const sync = this.cells.get(["sync"]);\n if (_RepoLobe.#fields(sync) && !(await this.#held()).some((one) => one.placeholder === sync["on"]))\n await this.#finish(sync, 1, "the lobe stands on that lobe no more");\n return null;\n }\n async #forgetFar(far, note) {\n if (_RepoLobe.#kindOf(note) === "writer") await this.#untold(far);\n if (_RepoLobe.#kindOf(note) === "library") await this.#untold(far, _RepoLobe.#hears);\n for (const kept of ["out", "in"]) {\n if (this.cells.get([kept, far]) === void 0) continue;\n this.cells.delete([kept, far]);\n await this.#clear(`${kept}-${far}`);\n }\n }\n async occupants(args) {\n const refused = this.#refusal("occupants", args);\n if (refused !== null) return refused;\n return (await this.#given()).map(({ far, note }) => {\n const scope = _RepoLobe.#scopeIn(note);\n return { far, role: _RepoLobe.#kindOf(note), ...scope === null ? {} : { scope } };\n });\n }\n async migrate(args) {\n const refused = this.#refusal("migrate", args);\n if (refused !== null) return refused;\n const rearmed = await this.#rearm();\n if (this.#repo() !== null) {\n this.cells.set(["owed"], true);\n await this.#owing();\n await this.#awaiting();\n }\n return rearmed;\n }\n async #owing() {\n if (this.cells.get(["owed"]) !== true) return;\n const repo = this.#repo();\n const idle = !_RepoLobe.#text(repo?.["doing"]) && !_RepoLobe.#fields(this.cells.get(["sync"]));\n if (_RepoLobe.#text(repo?.["head"]) && idle && "name" in this.#ready())\n await this.#begin("scan", {}, { scan: null }, { asker: _RepoLobe.#owner });\n }\n async #awaiting() {\n if (this.cells.get(["owed"]) !== true || this.cells.get(["owes"]) !== void 0) return;\n const chain = this.#nonce();\n const set = await this.#alarm({ at: this.stamp.time + MINUTE, method: "keep", args: { chain } });\n if (!("error" in set)) this.cells.set(["owes"], chain);\n }\n async keep(args) {\n const owes = this.cells.get(["owes"]);\n if (typeof owes !== "string" || owes !== _RepoLobe.#arg(args, "chain")) return null;\n await this.#check();\n await this.#owing();\n if (this.cells.get(["owed"]) === true) return { again: this.stamp.time + MINUTE };\n this.cells.delete(["owes"]);\n return null;\n }\n #scanning() {\n const doing = this.#repo()?.["doing"];\n return _RepoLobe.#text(doing) && _RepoLobe.#arg(this.cells.get(["job", doing]), "kind") === "scan";\n }\n async #rearm() {\n const sync = this.cells.get(["sync"]);\n if (!_RepoLobe.#fields(sync)) return null;\n const chain = this.#nonce();\n this.cells.set(["sync"], { ...sync, chain });\n const set = await this.#alarm({ at: this.stamp.time + _RepoLobe.#every, method: "tick", args: { chain } });\n return "error" in set ? this.error(set.error.code, set.error.message) : null;\n }\n gate(args) {\n const refused = this.#refusal("gate", args);\n if (refused !== null) return refused;\n const script = _RepoLobe.#arg(args, "script");\n if (script !== null && !(_RepoLobe.#text(script) && _RepoLobe.#script.test(script)))\n return this.error("refused", "a gate is a script of the repo\'s package, or null");\n this.cells.set(["gate"], script ?? null);\n return null;\n }\n #gateScript() {\n const held = this.cells.get(["gate"]);\n return held === void 0 ? "gate" : held;\n }\n #gates() {\n const held = this.cells.get(["gates"]);\n const [commit, push] = [_RepoLobe.#arg(held, "commit"), _RepoLobe.#arg(held, "push")];\n return {\n commit: typeof commit === "string" && _RepoLobe.#onCommit.includes(commit) ? commit : "on",\n push: push === "on" ? "on" : "off"\n };\n }\n gates(args) {\n const refused = this.#refusal("gates", args);\n if (refused !== null) return refused;\n const [commit, push] = [_RepoLobe.#arg(args, "commit"), _RepoLobe.#arg(args, "push")];\n if (commit !== void 0 && !(typeof commit === "string" && _RepoLobe.#onCommit.includes(commit)))\n return this.error("refused", "on commit, the gate is off, on or mandatory");\n if (push !== void 0 && !(typeof push === "string" && _RepoLobe.#onPush.includes(push)))\n return this.error("refused", "on push, the gate is off or on");\n const now = this.#gates();\n const set = {\n commit: typeof commit === "string" ? commit : now.commit,\n push: typeof push === "string" ? push : now.push\n };\n this.cells.set(["gates"], set);\n return set;\n }\n conform(args) {\n const refused = this.#refusal("conform", args);\n if (refused !== null) return refused;\n const take = _RepoLobe.#arg(args, "take");\n if (typeof take !== "boolean") return this.error("refused", "take is true or false");\n const ready = this.#ready();\n if (!("name" in ready)) return ready;\n if (!take) {\n this.cells.delete(["conform"]);\n return null;\n }\n const head = ready.repo["head"];\n if (!_RepoLobe.#text(head)) return this.error("refused", "main holds no commit to take its conform from");\n this.cells.set(["conform"], head);\n return head;\n }\n author(args) {\n const refused = this.#refusal("author", args);\n if (refused !== null) return refused;\n const lobe = _RepoLobe.#arg(args, "lobe");\n if (lobe === null) {\n this.cells.delete(["author"]);\n return null;\n }\n if (!_RepoLobe.#text(lobe) || lobe === _RepoLobe.#owner)\n return this.error("refused", "an author is a wired lobe, named by its ID");\n this.cells.set(["author"], lobe);\n return null;\n }\n async remove(args) {\n const refused = this.#refusal("remove", args);\n if (refused !== null) return refused;\n const repo = this.#repo();\n if (repo === null) return this.error("absent", "the lobe keeps no repo");\n if ((await this.#given()).length > 0) return this.error("refused", "far standings hold the repo: drop them first");\n if (_RepoLobe.#text(repo["doing"]) || this.cells.get(["sync"]) !== void 0)\n return this.error("refused", "the repo runs a job: wait for it to end");\n for (const kept of [\n "told",\n "built",\n "look",\n "parts",\n "job",\n "by",\n "out",\n "in",\n "back",\n "secret",\n "token",\n "credential"\n ])\n for (const { key } of this.#all([kept])) this.cells.delete(key);\n for (const kept of ["repo", "gate", "gates", "conform", "author", "scanned", "owed", "owes", "env", "renews"])\n this.cells.delete([kept]);\n return null;\n }\n async rebuild(args) {\n const refused = this.#refusal("rebuild", args);\n if (refused !== null) return refused;\n const repo = this.#repo();\n if (repo === null) return this.error("refused", "the lobe keeps no repo");\n if (_RepoLobe.#text(repo["doing"]) || this.cells.get(["sync"]) !== void 0)\n return this.error("refused", "the repo runs a job: wait for it to end");\n const rebuilds = repo["rebuilds"] ?? repo["head"] ?? null;\n this.cells.set(["repo"], { ...repo, ready: false, head: null, rebuilds });\n return this.#begin("init", {}, { rebuild: true });\n }\n async state(args) {\n const refused = this.#refusal("state", args);\n if (refused !== null) return refused;\n const repo = this.#repo();\n if (repo === null) return null;\n if (this.#role() === "library") return { name: repo["name"] ?? null };\n const held = this.#result(await this.ask("repos", "state", {}));\n const folder = _RepoLobe.#arg(held, "folder") ?? null;\n const relations = await this.#relations();\n const stood = relations.filter((one) => one.side === "standing" && !_RepoLobe.#text(_RepoLobe.#arg(one.note, "credential"))).toSorted((a, b) => _RepoLobe.#order(a.placeholder ?? "", b.placeholder ?? ""));\n const given = relations.filter((one) => one.side === "occupant");\n const on = stood.map(({ placeholder, far }) => ({ placeholder, far }));\n const writers = given.filter(({ note }) => _RepoLobe.#kindOf(note) === "writer").length;\n const author = this.cells.get(["author"]);\n const conform = this.cells.get(["conform"]);\n const sync = this.cells.get(["sync"]) ?? null;\n const syncing = _RepoLobe.#fields(sync) ? Object.fromEntries(Object.entries(sync).filter(([key]) => key !== "tells")) : sync;\n const scopes = given.flatMap(({ far, note }) => {\n const scope = _RepoLobe.#scopeIn(note);\n return scope === null ? [] : [{ far, scope }];\n });\n const scoped = stood.flatMap(({ placeholder, note }) => {\n const scope = _RepoLobe.#scopeIn(note);\n return scope === null ? [] : [{ on: placeholder, scope }];\n });\n const { cut: _, ...whole } = repo;\n const lost = repo["ready"] === true && _RepoLobe.#arg(held, "made") === false;\n return {\n ...whole,\n ...lost ? {\n ready: false,\n absent: "its folder holds no repo: a backup carries no repo\'s bytes; rebuild fills it again, pulled whole from a lobe it stands on or pushed whole by one that stands on it"\n } : {},\n on,\n writers,\n folder,\n syncing,\n gate: this.#gateScript(),\n gates: this.#gates(),\n ..._RepoLobe.#text(conform) ? { conform } : {},\n ..._RepoLobe.#text(author) ? { author } : {},\n ...scopes.length > 0 ? { scopes } : {},\n ...scoped.length > 0 ? { scoped } : {},\n ...this.#role() === "library" ? {} : await this.#keysShown()\n };\n }\n async #keysShown() {\n const issued = await this.#credentials();\n const credentials = issued.map(({ secret, far }) => {\n const cell = this.cells.get(["credential", far]);\n const url = _RepoLobe.#arg(cell, "url");\n const failed = _RepoLobe.#arg(cell, "failed");\n const expires = _RepoLobe.#arg(cell, "expires");\n const renews = _RepoLobe.#arg(cell, "renews");\n return {\n secret,\n far,\n pending: _RepoLobe.#arg(cell, "pending") === true,\n ..._RepoLobe.#text(url) ? { url } : {},\n ..._RepoLobe.#text(failed) ? { failed } : {},\n ...typeof expires === "number" && typeof renews === "number" ? { expires, renews } : {}\n };\n });\n const secrets = Object.keys(await this.#keys()).toSorted();\n return { ...secrets.length > 0 ? { secrets } : {}, ...credentials.length > 0 ? { credentials } : {} };\n }\n jobs(args) {\n const refused = this.#refusal("jobs", args);\n if (refused !== null) return refused;\n const { asker } = this.stamp;\n const held = asker === _RepoLobe.#owner ? this.#all(["job"]).map(({ value }) => value) : this.#all(["by", asker]).map(({ key }) => this.cells.get(["job", key[2] ?? ""]) ?? null);\n return held.map((one) => _RepoLobe.#brief(one));\n }\n static #brief(held) {\n if (!_RepoLobe.#fields(held) || !_RepoLobe.#fields(held["ended"])) return held;\n const { run, code, at } = held["ended"];\n return { ...held, ended: { run: run ?? null, code: code ?? null, at: at ?? null } };\n }\n job(args) {\n const refused = this.#refusal("job", args);\n if (refused !== null) return refused;\n const run = _RepoLobe.#arg(args, "job");\n if (!_RepoLobe.#text(run)) return this.error("refused", "a job is named by its id");\n const { asker } = this.stamp;\n const held = this.cells.get(["job", run]);\n const owns = asker === _RepoLobe.#owner || this.cells.get(["by", asker, run]) !== void 0;\n if (owns && _RepoLobe.#fields(held)) return held;\n const sync = this.cells.get(["sync"]);\n const last = this.#repo()?.["synced"];\n for (const one of [sync, last]) {\n if (!_RepoLobe.#fields(one) || one["job"] !== run) continue;\n if (asker !== _RepoLobe.#owner && one["asker"] !== asker) break;\n const ended = one === sync ? null : { code: one["code"] ?? null, err: one["err"] ?? null };\n return { job: run, kind: one["kind"] ?? null, stage: one === sync ? one["stage"] ?? null : null, ended };\n }\n return this.error("absent", "no such job");\n }\n async #begin(kind, given, step, { more = {}, asker = this.stamp.asker, method = kind } = {}) {\n const repo = this.#repo();\n if (repo === null) return this.error("refused", "the lobe keeps no repo");\n if (!_RepoLobe.#text(repo["doing"])) await this.#unclear();\n if (_RepoLobe.#text(repo["doing"])) {\n await this.#check();\n return this.error("refused", `the repo runs ${repo["doing"]} already`);\n }\n const back = step === null && this.#role() !== "runner" ? await this.#back(asker) : null;\n if (back !== null) return back;\n const begun = await this.ask("repos", method, given);\n if ("error" in begun) return this.error(begun.error.code, begun.error.message);\n const run = _RepoLobe.#arg(begun.result, "job");\n if (!_RepoLobe.#text(run)) return this.error("refused", "the jailer named no job");\n const owing = kind === "scan" && this.cells.get(["owed"]) === true;\n const of = step === null ? {} : { step: owing ? { ...step, owed: true } : step };\n this.cells.set(["job", run], {\n job: run,\n kind,\n asker,\n repo: repo["name"] ?? null,\n ...of,\n ...more,\n began: this.stamp.time,\n ended: null\n });\n if (step === null) this.cells.set(["by", asker, run], null);\n this.cells.set(["repo"], { ...repo, doing: run });\n return { job: run };\n }\n async #back(asker) {\n if (asker === _RepoLobe.#owner || this.cells.get(["back", asker]) !== void 0) return null;\n const ordered = await this.nerves.order({ termination: asker });\n if ("error" in ordered) return this.error("refused", `no wire back: ${ordered.error.message}`);\n this.cells.set(["back", asker], true);\n return null;\n }\n async done(args) {\n if (this.#role() === "teller") return this.#told(args);\n const read = await this.nerves.read();\n if (_RepoLobe.#wiredTo(read, "repos") !== this.stamp.asker)\n return this.error("refused", "only the jailer tells a job ended");\n const { job: run, code: ended, out: said, err: wrote } = _RepoLobe.#fields(args) ? args : {};\n const whole = typeof said === "string" && typeof wrote === "string" && typeof ended === "number";\n const held = _RepoLobe.#text(run) ? this.cells.get(["job", run]) : void 0;\n if (!whole || !_RepoLobe.#text(run) || !_RepoLobe.#fields(held) || held["ended"] !== null)\n return this.error("refused", "no such job going");\n return this.#jobEnded(read, run, held, ended, said, wrote);\n }\n async #jobEnded(read, run, held, ended, said, wrote) {\n this.#torn(read);\n const [out, err] = [this.#masked(said), this.#masked(wrote)];\n if (_RepoLobe.#text(held["gating"])) return this.#gated(held, run, ended, out, err);\n if (_RepoLobe.#fields(held["running"])) return this.#writtenThen(held, run, ended, err);\n const filed = held["kind"] !== "commit" ? err : ended === 0 ? err : await this.#undone(err);\n if (held["kind"] === "commit" && ended === 0) this.cells.delete(["undo"]);\n const [code, told] = this.#halfKept(held, ended, out, filed);\n this.#settled(held, code, out, told);\n const before = this.cells.get(["sync"]);\n const more = await this.#further(run, held, code, out, told);\n if (more !== null) await this.#closed(run, held, code, out, told, more);\n await this.#rung(before);\n await this.#tellEnds();\n await this.#receiveWaiting();\n const step = held["step"];\n const tried = _RepoLobe.#fields(step) && step["owed"] === true || more !== null && more["scan"] !== void 0;\n if (!tried) await this.#owing();\n return null;\n }\n async #further(run, held, code, out, err) {\n const asker = _RepoLobe.#text(held["asker"]) ? held["asker"] : _RepoLobe.#owner;\n const pulls = held["pulls"];\n if (held["kind"] === "init" && code === 0 && _RepoLobe.#text(pulls))\n return this.#pulled(run, held, out, pulls, asker);\n if (_RepoLobe.#fields(held["step"]) && held["step"]["rebuild"] === true) {\n const first = await this.#rebuilt(code === 0 ? null : _RepoLobe.#lastLine(err) || `the job ended ${code}`);\n return _RepoLobe.#text(first) ? this.#pulled(run, held, out, first, _RepoLobe.#owner) : {};\n }\n if (held["kind"] === "init" && code === 0 && held["starter"] === true) {\n const why = await this.#layStarter(run, asker);\n return why === null ? null : { starter: why };\n }\n const moved = code === 0 && typeof held["kind"] === "string" && _RepoLobe.#moves.includes(held["kind"]);\n if (!moved || !_RepoLobe.#text(this.#repo()?.["head"])) return {};\n const begun = await this.#begin("scan", {}, { scan: run, code, out, err }, { asker });\n if ("job" in begun) return null;\n this.cells.set(["owed"], true);\n await this.#awaiting();\n return { scan: { code: 1, err: `the scan did not begin: ${begun.message}` } };\n }\n async #pulled(run, held, out, on, asker) {\n const begun = await this.#start("pull", asker, on, { of: run });\n if (_RepoLobe.#text(_RepoLobe.#arg(begun, "job"))) return null;\n await this.#closed(\n run,\n held,\n 1,\n out,\n `the pull did not begin: ${_RepoLobe.#shown(_RepoLobe.#arg(begun, "message"))}`,\n {}\n );\n return null;\n }\n async #closed(run, held, code, out, err, more) {\n this.cells.set(["job", run], { ...held, ended: { run, code, out, err, ...more, at: this.stamp.time } });\n const step = held["step"];\n if (_RepoLobe.#fields(step)) await this.#stepped(step, held, code, out, err, more);\n else await this.#ended(held, code, out, err, more);\n }\n async #scannedThen(step, code, err) {\n const run = step["scan"];\n const held = _RepoLobe.#text(run) ? this.cells.get(["job", run]) : void 0;\n if (!_RepoLobe.#text(run) || !_RepoLobe.#fields(held) || held["ended"] !== null) return;\n const [ended, out, said] = [step["code"], step["out"], step["err"]];\n const scan = { code, err: code === 0 ? "" : _RepoLobe.#last(err) || `the scan ended ${code}` };\n const whole = typeof ended === "number" && typeof out === "string" && typeof said === "string";\n if (whole) await this.#closed(run, held, ended, out, said, { scan });\n }\n #halfKept(held, code, out, err) {\n const built = held["built"];\n if (held["kind"] !== "build" || code !== 0 || !_RepoLobe.#fields(built)) return [code, err];\n if (_RepoLobe.#text(built["design"])) return [code, err];\n const [organ, version] = [_RepoLobe.#shown(built["organ"]), _RepoLobe.#shown(built["version"])];\n const kept = this.cells.get(["built", organ, version]);\n const digest = out.trim();\n if (typeof kept !== "string" || kept === digest) return [code, err];\n return [\n 1,\n `the host half of ${organ} ${version} was built as ${kept}, and this build gives ${digest}: a version is never told with other bytes, so raise its version`\n ];\n }\n #settled(held, code, out, err) {\n const repo = this.#repo();\n if (repo === null) return;\n const { kind } = held;\n const failed = code === 0 ? null : _RepoLobe.#lastLine(err);\n const made = kind === "init" ? { ready: code === 0, failed } : {};\n const moved = code === 0 && typeof kind === "string" && _RepoLobe.#moves.includes(kind);\n const now = moved ? _RepoLobe.#headOf(out) : null;\n const head = moved ? { head: now } : {};\n this.cells.set(["repo"], { ...repo, ...made, ...head, doing: null });\n if (now !== null && kind !== "land" && out.split("\\n").includes(`conform ${now}`)) this.cells.set(["conform"], now);\n }\n async #ended(held, code, out, err, more = {}) {\n const { asker, kind, job: run } = held;\n const built = held["built"];\n const digest = out.trim();\n if (kind === "build" && code === 0 && _RepoLobe.#fields(built)) {\n if (_RepoLobe.#text(built["design"])) this.#looked(built, out);\n else if (_RepoLobe.#digest.test(digest))\n this.cells.set(["built", _RepoLobe.#shown(built["organ"]), _RepoLobe.#shown(built["version"])], digest);\n }\n if (!_RepoLobe.#text(asker) || this.cells.get(["back", asker]) === void 0) return;\n const told = { job: run ?? null, kind: kind ?? null, code, out, err, ...more };\n await this.ask(asker, "done", told, void 0, { letter: { lives: _RepoLobe.#lives } });\n }\n #looked(built, source) {\n const [name, version] = [_RepoLobe.#shown(built["design"]), _RepoLobe.#shown(built["version"])];\n const told = _RepoLobe.#arg(this.cells.get(["told", "faculty", `${name}.look`, version]), "digest");\n const digest = this.#digestOf(source);\n if (digest === told) {\n this.cells.set(["look", name, version], { source });\n return;\n }\n if (_RepoLobe.#text(_RepoLobe.#arg(this.cells.get(["look", name, version]), "source"))) return;\n const why = `the look built is ${digest}, not the ${_RepoLobe.#shown(told)} versions.json told`;\n this.cells.set(["look", name, version], { why });\n }\n async #stepped(step, held, code, out, err, more) {\n const why = code === 0 ? null : _RepoLobe.#lastLine(err) || `the job ended ${code}`;\n if (_RepoLobe.#text(step["commit"])) {\n await this.#commitEnded(step["commit"], code, out, err, more);\n return void 0;\n }\n if (_RepoLobe.#text(step["ran"])) {\n const kind = _RepoLobe.#text(held["kind"]) ? held["kind"] : "run";\n return this.#workEnded(step["ran"], kind, code, out, err);\n }\n if (_RepoLobe.#text(step["check"])) return this.#checked(step["check"], { code, out, err });\n if (step["scan"] !== void 0) {\n if (code === 0) await this.#scanned(out);\n if (code === 0 && step["owed"] === true) this.cells.delete(["owed"]);\n else if (step["owed"] === true) await this.#awaiting();\n return this.#scannedThen(step, code, err);\n }\n if (_RepoLobe.#text(step["for"])) return this.#served(step["for"], held["kind"], why, out);\n const sync = this.cells.get(["sync"]);\n if (step["sync"] !== true || !_RepoLobe.#fields(sync)) return;\n if (held["kind"] === "bring") return this.#broughtPull(sync, why, out);\n if (held["kind"] === "land") return this.#landed(sync, why);\n if (sync["stage"] === "proving") return this.#proven(sync, code, why, out);\n if (why !== null) return this.#finish(sync, code, why);\n const pieces = Number(out.trim().split("\\n")[0]);\n if (pieces === 0) return this.#finish(sync, 0, "");\n this.cells.set(["sync"], { ...sync, stage: "sending", at: 0, pieces });\n return void 0;\n }\n async #broughtPull(sync, why, out) {\n if (why !== null) return this.#finish(sync, 1, why);\n const [head = "", how = ""] = out.trim().split("\\n");\n if (how === "held" || !_RepoLobe.#hash.test(head)) return this.#finish(sync, 0, "");\n const check = await this.#conform("pull", head, false, _RepoLobe.#askerOf(sync));\n const checking = { ...sync, stage: "checking", theirs: head, check };\n this.cells.set(["sync"], checking);\n if ("code" in check) await this.#checkedPull(checking, check);\n return void 0;\n }\n async #checkedPull(sync, check) {\n if (check["code"] !== 0) return this.#finish(sync, 1, _RepoLobe.#refusalOf(check), check);\n const begun = await this.#begin("land", { as: "pull" }, { sync: true }, _RepoLobe.#of(sync));\n if ("job" in begun) this.cells.set(["sync"], { ...sync, stage: "landing" });\n else await this.#finish(sync, 1, begun.message, check);\n return void 0;\n }\n async #landed(sync, why) {\n const check = sync["check"] ?? null;\n if (why !== null) return this.#finish(sync, 1, why, check);\n const rebuilds = this.#repo()?.["rebuilds"];\n if (!_RepoLobe.#text(rebuilds)) return this.#finish(sync, 0, "", check);\n const begun = await this.#begin("head", { contains: rebuilds }, { sync: true }, _RepoLobe.#of(sync));\n if ("job" in begun) this.cells.set(["sync"], { ...sync, stage: "proving" });\n else await this.#finish(sync, 1, begun.message, check);\n return void 0;\n }\n async #proven(sync, code, why, out) {\n const repo = this.#repo();\n const holds = code === 0 && out.trim().split("\\n")[1] === "holds";\n if (repo !== null && holds) this.cells.set(["repo"], { ...repo, rebuilds: null });\n const lacks = "the lobe pulled holds not the head this one kept: it waits for a whole push";\n return this.#finish(sync, holds ? 0 : 1, holds ? "" : why ?? lacks, sync["check"] ?? null);\n }\n async #rebuilt(why) {\n const repo = this.#repo();\n if (repo === null) return null;\n this.cells.set(["repo"], { ...repo, head: null, ready: why === null, failed: why });\n const first = why === null ? (await this.#held())[0]?.placeholder : null;\n return _RepoLobe.#text(first) ? first : null;\n }\n async #scanned(out) {\n const [shown = "", toldBlock = ""] = out.trim().split("\\n@ ");\n const [head = "", ...lines] = shown.split("\\n");\n const tracked = new Set(lines.filter((line) => line.startsWith("t ")).map((line) => line.slice(2)));\n const changed = new Set(lines.filter((line) => line.startsWith("c ")).map((line) => line.slice(2)));\n const tagged = lines.some((line) => line.startsWith("g "));\n const named = (pattern) => [...tracked].flatMap((path) => pattern.exec(path)?.[1] ?? []).toSorted().slice(0, this.#most());\n const files = _RepoLobe.#hashedFiles(lines);\n const faculties = [];\n for (const label of named(/^faculties\\/([^/]+)\\/faculty\\.js$/))\n faculties.push(await this.#faculty(label, tracked, changed, files, tagged));\n const organs = [];\n for (const id of named(/^organs\\/([^/]+)\\/graph\\.json$/))\n organs.push(await this.#organ(id, tracked, changed, tagged));\n const designs = [];\n for (const name of named(/^designs\\/([^/]+)\\/design\\.json$/))\n designs.push(await this.#design(name, tracked, changed, files, tagged));\n this.cells.set(["scanned"], {\n head,\n faculties,\n organs,\n designs\n });\n const repo = this.#repo();\n if (repo !== null && _RepoLobe.#text(repo["head"]) && _RepoLobe.#text(head) && repo["head"] !== head)\n this.cells.set(["repo"], { ...repo, head });\n if (!tagged) return this.#tell(await this.#toldAt(toldBlock));\n await this.#tell([\n ...faculties.flatMap((one) => _RepoLobe.#found("faculty", one)),\n ...organs.flatMap((one) => _RepoLobe.#found("organ", one)),\n ...designs.flatMap((one) => _RepoLobe.#lookFound(one))\n ]);\n }\n async #toldAt(block) {\n if (block === "") return [];\n const lines = block.split("\\n").slice(1);\n const files = _RepoLobe.#hashedFiles(\n lines.flatMap(\n (line) => line.startsWith("A ") ? [`d ${line.slice(2)}`] : line.startsWith("U ") ? [`u ${line.slice(2)}`] : []\n )\n );\n const tracked = new Set(lines.filter((line) => line.startsWith("T ")).map((line) => line.slice(2)));\n const carried = new Map(\n lines.flatMap((line) => {\n const [, path, text] = /^B (\\S+) (".*")$/u.exec(line) ?? [];\n return path === void 0 || text === void 0 ? [] : [[path, text]];\n })\n );\n const read = async (path) => {\n const text = carried.get(path);\n if (text === void 0) return this.#file(path);\n try {\n const one = JSON.parse(text);\n return typeof one === "string" ? one : null;\n } catch {\n return null;\n }\n };\n const named = (pattern) => [...tracked].flatMap((path) => pattern.exec(path)?.[1] ?? []).toSorted().slice(0, this.#most());\n const none = new Set();\n const found = [];\n for (const label of named(/^faculties\\/([^/]+)\\/faculty\\.js$/))\n found.push(..._RepoLobe.#found("faculty", await this.#faculty(label, tracked, none, files, true, read)));\n for (const id of named(/^organs\\/([^/]+)\\/graph\\.json$/))\n found.push(..._RepoLobe.#found("organ", await this.#organ(id, tracked, none, true, read)));\n return found;\n }\n static #hashedFiles(lines) {\n const files = new Map();\n for (const line of lines) {\n if (!line.startsWith("d ") && !line.startsWith("u ")) continue;\n const hashed = _RepoLobe.#hashed.exec(line);\n const folder = hashed?.[2] ?? /^. (?:\\S* )?((?:designs|faculties)\\/[^/]+)\\//.exec(line)?.[1];\n if (folder === void 0) continue;\n const held = files.get(folder) ?? { parts: [], unread: false };\n const [sha, path] = [hashed?.[1], hashed?.[3]];\n const part = path === void 0 ? void 0 : _RepoLobe.#partOf(folder, path);\n if (sha === void 0 || path === void 0) held.unread = true;\n else if (part !== void 0) held.parts.push([part, sha]);\n files.set(folder, held);\n }\n return files;\n }\n static #partOf(folder, path) {\n if (folder.startsWith("designs/")) return _RepoLobe.#isData(path) ? path : void 0;\n const asset = path.startsWith("assets/") ? path.slice("assets/".length) : "";\n return asset !== "" && !asset.split("/").some((name) => name.startsWith(".")) ? asset : void 0;\n }\n static #isData(path) {\n if (path === "DESIGN.md" || path === "versions.json") return false;\n if (path.startsWith("components/") || path.startsWith("words/")) return false;\n return !path.split("/").some((name) => name.startsWith("."));\n }\n #dataOf(parts) {\n return this.#digestOf(JSON.stringify(_RepoLobe.#byPath(parts)));\n }\n static #byPath(parts) {\n return parts.map((part) => [...part]).toSorted((one, other) => (one[0] ?? "") < (other[0] ?? "") ? -1 : 1);\n }\n async #design(name, tracked, changed, files, tagged) {\n const root = `designs/${name}/`;\n if (!_RepoLobe.#label.test(name)) return { name, why: "its folder is no name" };\n if (!tracked.has(`${root}versions.json`)) return { name, why: "it holds no versions.json committed" };\n if ([...changed].some((path) => path.startsWith(root)))\n return { name, why: "its files hold changes not committed" };\n const held = files.get(`designs/${name}`) ?? { parts: [], unread: true };\n const design = await this.#file(`${root}design.json`);\n const kept = await this.#file(`${root}versions.json`);\n if (held.unread || design === null || kept === null) return { name, why: "its files are not all read" };\n const read = _RepoLobe.#json(design);\n const version = _RepoLobe.#arg(read, "version");\n if (_RepoLobe.#arg(read, "name") !== name) return { name, why: "its design.json names another name" };\n if (!_RepoLobe.#text(version) || !_RepoLobe.#version.test(version))\n return { name, why: "its design.json names no version" };\n const data = this.#dataOf(held.parts);\n const named = _RepoLobe.#arg(_RepoLobe.#json(kept), version);\n const look = _RepoLobe.#arg(named, "look");\n if (_RepoLobe.#arg(named, "data") !== data)\n return {\n name,\n version,\n data,\n why: "versions.json names another data digest for its version"\n };\n if (!_RepoLobe.#text(look) || !_RepoLobe.#digest.test(look))\n return { name, version, data, why: "versions.json names no look for its version" };\n const told = this.#record(\n "faculty",\n `${name}.look`,\n version,\n { digest: look, assets: _RepoLobe.#byPath(held.parts) },\n tagged\n );\n const why = _RepoLobe.#arg(told, "why");\n return { name, version, data, look, ...why === void 0 ? {} : { why } };\n }\n static #lookFound(one) {\n const [name, version] = [_RepoLobe.#arg(one, "name"), _RepoLobe.#arg(one, "version")];\n if (!_RepoLobe.#text(name) || !_RepoLobe.#text(version) || _RepoLobe.#arg(one, "why") !== void 0) return [];\n return [{ kind: "faculty", label: `${name}.look`, version }];\n }\n static #found(kind, one) {\n const label = _RepoLobe.#arg(one, _RepoLobe.#keyOf(kind));\n const version = _RepoLobe.#arg(one, "version");\n if (!_RepoLobe.#text(label) || !_RepoLobe.#text(version) || _RepoLobe.#arg(one, "why") !== void 0) return [];\n return [{ kind, label, version }];\n }\n async #faculty(label, tracked, changed, files, tagged, reader = (path) => this.#file(path)) {\n const [code, versions] = [`faculties/${label}/faculty.js`, `faculties/${label}/versions.json`];\n if (!_RepoLobe.#label.test(label)) return { label, why: "its folder is no label" };\n if (!tracked.has(versions)) return { label, why: "it holds no versions.json committed" };\n if (changed.has(code) || changed.has(versions))\n return { label, why: "its faculty.js or versions.json holds changes not committed" };\n const assets = `faculties/${label}/assets/`;\n if ([...changed].some((path) => path.startsWith(assets)))\n return { label, why: "its assets hold changes not committed" };\n const hashed = files.get(`faculties/${label}`) ?? {\n parts: [],\n unread: false\n };\n if (hashed.unread) return { label, why: "its assets are not all read" };\n const [source, kept] = [await reader(code), await reader(versions)];\n if (source === null || kept === null) return { label, why: "its files are not read" };\n const digest = this.#digestOf(source);\n const held = _RepoLobe.#json(kept);\n const version = _RepoLobe.#fields(held) ? Object.keys(held).find((one) => held[one] === digest) : void 0;\n if (version === void 0 || !_RepoLobe.#version.test(version))\n return { label, digest, why: "versions.json names no version for its digest" };\n const carried = hashed.parts.length === 0 ? {} : { assets: _RepoLobe.#byPath(hashed.parts) };\n return this.#record("faculty", label, version, { digest, ...carried }, tagged, source);\n }\n async #organ(id, tracked, changed, tagged, reader = (path) => this.#file(path)) {\n const [graph, build] = [`organs/${id}/graph.json`, `organs/${id}/host/build`];\n if (!_RepoLobe.#id.test(id)) return { id, why: "its folder is no fixed ID" };\n if (!tracked.has(build)) return { id, why: "it holds no host/build" };\n if ([graph, build].some((file) => changed.has(file))) return { id, why: "its files hold changes not committed" };\n const blueprint = tracked.has(graph) ? await reader(graph) : null;\n const read = blueprint === null ? null : _RepoLobe.#json(blueprint);\n const inner = _RepoLobe.#arg(read, "blueprint");\n const version = _RepoLobe.#arg(read, "version") ?? _RepoLobe.#arg(inner, "version");\n if (blueprint === null || typeof version !== "string" || !_RepoLobe.#version.test(version))\n return { id, why: "its graph.json names no version" };\n return this.#record("organ", id, version, { digest: this.#digestOf(blueprint) }, tagged, blueprint);\n }\n static #keyOf(kind) {\n return kind === "faculty" ? "label" : "id";\n }\n #record(kind, label, version, bytes, tagged, text = null) {\n const named = { [_RepoLobe.#keyOf(kind)]: label };\n const held = this.cells.get(["told", kind, label, version]);\n if (!_RepoLobe.#fields(held)) {\n if (tagged) {\n this.cells.set(["told", kind, label, version], {\n ...bytes,\n heard: false,\n at: this.stamp.time\n });\n if (text !== null) this.cells.set(["text", kind, label, version], text);\n }\n return { ...named, version, ...bytes };\n }\n const same = Object.keys(bytes).every((key) => JSON.stringify(held[key]) === JSON.stringify(bytes[key]));\n if (same) return { ...named, version, ...bytes };\n return {\n ...named,\n version,\n ...bytes,\n why: `version ${version} was told with other bytes: raise its version`\n };\n }\n async #file(path) {\n const read = await this.ask("repos", "read", { path });\n const text = "result" in read ? _RepoLobe.#arg(read.result, "text") : void 0;\n return typeof text === "string" ? text : null;\n }\n async #tell(found) {\n await this.#tellFar(found);\n const unheard = found.flatMap(({ kind, label, version }) => {\n const held = this.cells.get(["told", kind, label, version]);\n return _RepoLobe.#fields(held) && held["heard"] !== true ? [{ kind, label, version, held }] : [];\n });\n if (unheard.length === 0) return;\n const described = await this.ask("library", null, null);\n const methods = "result" in described ? _RepoLobe.#arg(described.result, "methods") : void 0;\n const offered = _RepoLobe.#kinds(_RepoLobe.#arg(methods, "changed"));\n for (const { kind, label, version, held } of unheard) {\n if (!offered.includes(kind)) continue;\n const changed = { kind, label, version, digest: held["digest"] ?? null };\n const letter = { lives: _RepoLobe.#lives };\n const sent = await this.ask("library", "changed", changed, void 0, { letter });\n if (!("error" in sent)) this.cells.set(["told", kind, label, version], { ...held, heard: true });\n }\n }\n async #tellFar(found) {\n const fresh = found.flatMap(({ kind, label, version }) => {\n const held = this.cells.get(["told", kind, label, version]);\n return _RepoLobe.#fields(held) && held["far"] !== true && (kind === "faculty" || kind === "organ") ? [{ kind, label, version, held }] : [];\n });\n if (fresh.length === 0) return;\n const backs = (await this.#relations()).filter(\n (one) => one.side === "standing" && one.placeholder?.startsWith(`${_RepoLobe.#hears}-`) === true\n );\n if (backs.length === 0) return;\n for (const { kind, label, version, held } of fresh) {\n const changed = { kind, label, version, digest: held["digest"] ?? null };\n for (const { placeholder } of backs) {\n const heard = _RepoLobe.#text(placeholder) ? await this.ask(placeholder, "changed", changed) : null;\n if (heard !== null && "error" in heard) return;\n }\n this.cells.set(["told", kind, label, version], { ...held, far: true });\n }\n }\n static #kinds(changed) {\n const kind = _RepoLobe.#arg(_RepoLobe.#arg(_RepoLobe.#arg(changed, "args"), "properties"), "kind");\n const named = _RepoLobe.#arg(kind, "enum");\n return Array.isArray(named) ? named : [];\n }\n faculties(args) {\n return this.#offered("faculties", args);\n }\n organs(args) {\n return this.#offered("organs", args);\n }\n designs(args) {\n return this.#offered("designs", args);\n }\n #offered(method, args) {\n const refused = this.#refusal(method, args);\n if (refused !== null) return refused;\n const found = _RepoLobe.#arg(this.cells.get(["scanned"]), method);\n if (!Array.isArray(found) || found.length === 0) return this.error("absent", `the repo holds no ${method}/`);\n return found;\n }\n async get(args) {\n const refused = this.#refusal("get", args);\n if (refused !== null) return refused;\n const { kind, label, version, path } = _RepoLobe.#fields(args) ? args : {};\n if (kind !== "faculty" && kind !== "organ" || !_RepoLobe.#text(label) || !_RepoLobe.#label.test(label))\n return this.error("refused", "a get names a faculty or an organ by its label");\n if (path !== void 0 && (kind !== "faculty" || !_RepoLobe.#text(path)))\n return this.error("refused", "a path names a faculty\'s asset");\n const near = ["owner", "near"].includes(this.#role());\n if (version === null && !near) return this.error("refused", "a version told is read from afar");\n const told = _RepoLobe.#text(version) ? this.cells.get(["told", kind, label, version]) : null;\n const at = _RepoLobe.#shown(version);\n if (told !== null && !_RepoLobe.#fields(told)) return this.error("absent", `no version ${at} of ${label} was told`);\n if (kind === "faculty" && told !== null && told["assets"] !== void 0 && this.#isLook(label))\n return this.#getLook(label, at, told, path);\n if (path !== void 0 && (told === null || told["assets"] === void 0))\n return this.error("refused", `${label} ${at} carries no assets`);\n if (path !== void 0 && told !== null) return this.#getAsset(label, told, path);\n const kept = _RepoLobe.#text(version) ? this.cells.get(["text", kind, label, version]) : void 0;\n if (told !== null && typeof kept === "string") {\n if (kind === "faculty")\n return {\n source: kept,\n digest: told["digest"] ?? null,\n ..._RepoLobe.#carried(told)\n };\n return { blueprint: kept, half: this.cells.get(["built", label, at]) ?? null };\n }\n if (kind === "faculty") return this.#getFaculty(label, told);\n return this.#getOrgan(label, at, told);\n }\n #isLook(label) {\n const designs = _RepoLobe.#arg(this.cells.get(["scanned"]), "designs");\n const name = label.endsWith(".look") ? label.slice(0, -".look".length) : null;\n return Array.isArray(designs) && designs.some((one) => _RepoLobe.#arg(one, "name") === name);\n }\n static #carried(told) {\n const parts = _RepoLobe.#partsOf(told["assets"]);\n return parts === null ? {} : { assets: parts };\n }\n async #getAsset(label, told, path) {\n const part = _RepoLobe.#partsOf(told["assets"])?.find((one) => one[0] === path);\n if (part === void 0) return this.error("absent", `${label} holds no asset ${_RepoLobe.#shown(path)}`);\n return this.#asset(part);\n }\n async #asset(part) {\n const read = await this.ask("repos", "bytes", { sha: part[1] ?? null });\n if ("error" in read)\n return read.error.code === "absent" ? this.error("absent", this.#unkept(_RepoLobe.#shown(part[0]))) : this.#result(read);\n const bytes = _RepoLobe.#arg(read.result, "bytes");\n const whole = bytes instanceof Uint8Array ? _RepoLobe.#canonical(bytes) : null;\n if (whole === null || this.#shaOf(whole) !== part[1])\n return this.error("refused", "the asset kept is not the version told");\n return { path: part[0] ?? null, digest: part[1] ?? null, bytes: whole };\n }\n #unkept(shown) {\n if (this.#scanning()) return `${shown} is being kept: a scan of the repo is running, ask again once it ends`;\n if (this.cells.get(["owed"]) === true)\n return `${shown} is not kept yet: a scan of the repo is owed and begins once the repo runs nothing, ask again then`;\n return `${shown} is not kept yet: a scan of the repo keeps it`;\n }\n static #partsOf(data) {\n if (!Array.isArray(data)) return null;\n const parts = [];\n for (const one of data) {\n const [path, sha] = Array.isArray(one) && one.length === 2 ? one : [];\n if (!_RepoLobe.#text(path) || !_RepoLobe.#text(sha) || !_RepoLobe.#digest.test(sha)) return null;\n parts.push([path, sha]);\n }\n return parts;\n }\n async #getLook(label, version, told, path) {\n const name = label.slice(0, -".look".length);\n const parts = _RepoLobe.#partsOf(told["assets"]);\n if (parts === null) return this.error("refused", `the look ${label} ${version} names no assets whole`);\n if (path === void 0) {\n const built = this.cells.get(["look", name, version]);\n const source = _RepoLobe.#arg(built, "source");\n if (typeof source === "string" && this.#digestOf(source) === told["digest"])\n return { source, digest: told["digest"], assets: parts };\n const why = _RepoLobe.#arg(built, "why");\n return this.error("refused", _RepoLobe.#text(why) ? why : `the look of ${name} ${version} is not built: build it`);\n }\n const part = parts.find((one) => one[0] === path);\n if (part === void 0) return this.error("absent", `the look ${label} holds no asset ${_RepoLobe.#shown(path)}`);\n return this.#asset(part);\n }\n async #getFaculty(label, told) {\n const source = await this.#file(`faculties/${label}/faculty.js`);\n if (source === null) return this.error("absent", `the repo holds no faculties/${label}/faculty.js`);\n const digest = this.#digestOf(source);\n if (told !== null && told["digest"] !== digest)\n return this.error("refused", "the faculty.js the repo holds is not the version told");\n return {\n source,\n digest,\n ...told === null ? {} : _RepoLobe.#carried(told)\n };\n }\n async #getOrgan(id, version, told) {\n const blueprint = await this.#file(`organs/${id}/graph.json`);\n if (blueprint === null) return this.error("absent", `the repo holds no organ ${id} whole`);\n if (told !== null && told["digest"] !== this.#digestOf(blueprint))\n return this.error("refused", "the organ the repo holds is not the version told");\n const half = told === null ? null : this.cells.get(["built", id, version]) ?? null;\n return { blueprint, half };\n }\n build(args) {\n const refused = this.#refusal("build", args);\n if (refused !== null) return Promise.resolve(refused);\n const [organ, design] = [_RepoLobe.#arg(args, "organ"), _RepoLobe.#arg(args, "design")];\n const version = _RepoLobe.#arg(args, "version");\n if (organ === void 0 === (design === void 0))\n return Promise.resolve(this.error("refused", "a build names an organ or a design"));\n const [kind, named] = organ === void 0 ? ["design", design] : ["organ", organ];\n const told = _RepoLobe.#text(named) && _RepoLobe.#text(version) ? this.cells.get(\n kind === "design" ? ["told", "faculty", `${named}.look`, version] : ["told", "organ", named, version]\n ) : void 0;\n if (!_RepoLobe.#fields(told))\n return Promise.resolve(this.error("absent", `no such ${kind} was told at that version`));\n if (!("name" in this.#ready())) return Promise.resolve(this.error("refused", "the repo is not ready"));\n if (!this.#mainHolds(kind, _RepoLobe.#shown(named), _RepoLobe.#shown(version), told["digest"]))\n return Promise.resolve(\n this.error(\n "refused",\n `main holds not ${_RepoLobe.#shown(named)} ${_RepoLobe.#shown(version)}: a version is built while main holds it`\n )\n );\n const built = { [kind]: named ?? null, version: version ?? null };\n const method = kind === "design" ? "look" : "build";\n return this.#begin("build", { [kind]: named ?? null }, null, { more: { built }, method });\n }\n #mainHolds(kind, named, version, digest) {\n const [list, key, by] = kind === "design" ? ["designs", "name", "look"] : ["organs", "id", "digest"];\n const found = _RepoLobe.#arg(this.cells.get(["scanned"]), list);\n const now = Array.isArray(found) ? found.find((one) => _RepoLobe.#arg(one, key) === named) : void 0;\n return _RepoLobe.#arg(now, "version") === version && _RepoLobe.#arg(now, by) === digest && _RepoLobe.#arg(now, "why") === void 0;\n }\n async told(args) {\n const refused = this.#refusal("told", args);\n if (refused !== null) return refused;\n const tells = _RepoLobe.#arg(args, "tells");\n if (this.#role() === "library" && this.stamp.occupant !== null) {\n if (_RepoLobe.#text(tells)) {\n const far = this.stamp.asker;\n await this.#untold(far, _RepoLobe.#hears);\n const note = { repo: this.#repo()?.["name"] ?? null, library: far };\n const accepted = await this.ask("mouth", "accept", {\n invitation: tells,\n placeholder: _RepoLobe.#backUnder(_RepoLobe.#hears, far),\n note\n });\n if ("error" in accepted)\n return this.error(accepted.error.code, `the standing back was not taken: ${accepted.error.message}`);\n }\n } else if (tells !== void 0) return this.error("refused", "tells is a far library’s alone");\n return this.#all(["told"]).flatMap(({ key, value }) => {\n if (!_RepoLobe.#fields(value)) return [];\n const [, kind, label, version] = key;\n return [{ kind: kind ?? null, label: label ?? null, version: version ?? null, ...value }];\n });\n }\n head(args) {\n const refused = this.#serving("head", args);\n if (refused !== null) return refused;\n const repo = this.#repo() ?? {};\n if (this.#scopeOfAsker() !== null) return { head: null };\n return { head: _RepoLobe.#text(repo["rebuilds"]) ? null : repo["head"] ?? null };\n }\n async give(args) {\n const refused = this.#serving("give", args);\n if (refused !== null) return refused;\n const repo = this.#repo() ?? {};\n const since = _RepoLobe.#arg(args, "since") ?? null;\n const tag = _RepoLobe.#arg(args, "tag") ?? null;\n const far = this.stamp.asker;\n const scope = this.#scopeOfAsker();\n if (tag !== null && !(_RepoLobe.#text(tag) && _RepoLobe.#tag.test(tag)))\n return this.error("refused", "a tag is v and three whole numbers");\n const out = this.cells.get(["out", far]);\n const current = _RepoLobe.#fields(out) && (out["of"] ?? null) === (repo["head"] ?? null);\n const piece = _RepoLobe.#arg(args, "piece") ?? null;\n const same = _RepoLobe.#fields(out) && out["since"] === since && (out["tag"] ?? null) === tag && (out["piece"] ?? null) === piece;\n if (_RepoLobe.#fields(out) && current && same && _RepoLobe.#text(out["run"])) {\n if (_RepoLobe.#text(out["failed"])) {\n this.cells.delete(["out", far]);\n return this.error("refused", out["failed"]);\n }\n if (typeof out["pieces"] !== "number") return { ready: false };\n const ready = { pieces: out["pieces"], head: out["head"] ?? null };\n return scope === null ? ready : { ...ready, scope };\n }\n if (_RepoLobe.#text(repo["doing"])) {\n await this.#check();\n return { ready: false };\n }\n const as = `out-${far}`;\n const named = { ...typeof tag === "string" ? { tag } : {}, ...typeof piece === "number" ? { piece } : {} };\n const tagged = typeof tag === "string" ? { tag } : {};\n const begun = scope === null ? await this.#begin("bundle", { since, as, ...named }, { for: far }) : await this.#begin("cut", { as, scope, ...tagged }, { for: far });\n if (!("job" in begun)) return begun;\n const of = repo["head"] ?? null;\n this.cells.set(["out", far], { since, ...named, of, run: begun.job, pieces: null, head: null, failed: null });\n return { ready: false };\n }\n #serving(method, args) {\n const refused = this.#refusal(method, args);\n if (refused !== null) return refused;\n if (!("name" in this.#ready())) return this.error("refused", "the repo is not ready");\n if (method === "give" && _RepoLobe.#text(this.#repo()?.["rebuilds"]))\n return this.error("refused", "the lobe rebuilds: it is pushed whole first");\n return null;\n }\n async piece(args) {\n const refused = this.#serving("piece", args);\n if (refused !== null) return refused;\n const at = _RepoLobe.#arg(args, "at");\n const out = this.cells.get(["out", this.stamp.asker]);\n const pieces = _RepoLobe.#arg(out, "pieces");\n if (typeof at !== "number" || typeof pieces !== "number" || at < 0 || at >= pieces)\n return this.error("refused", "no such piece is ready");\n return this.#result(await this.ask("repos", "piece", { at, as: `out-${this.stamp.asker}` }));\n }\n async take(args) {\n const refused = this.#serving("take", args);\n if (refused !== null) return refused;\n const { push, at, pieces, bytes } = _RepoLobe.#fields(args) ? args : {};\n if (!_RepoLobe.#text(push) || typeof at !== "number" || typeof pieces !== "number" || !(bytes instanceof Uint8Array))\n return this.error("refused", "a piece names its push, where it stands, of how many, and its bytes");\n const far = this.stamp.asker;\n const last = this.#shaOf(bytes);\n const held = this.cells.get(["in", far]);\n const same = _RepoLobe.#fields(held) && held["push"] === push && held["pieces"] === pieces ? held : null;\n if (same !== null && same["got"] === at + 1 && same["last"] === last) return this.#receive(far);\n const named = _RepoLobe.#fields(held) && held["push"] === push;\n const fresh = {\n push,\n pieces,\n got: 0,\n run: null,\n head: null,\n failed: null,\n check: null,\n landing: null,\n landed: false\n };\n const begins = !named && at === 0;\n const given = _RepoLobe.#arg(args, "tells");\n const kept = begins ? { ...fresh, ...given === void 0 ? { told: true } : {} } : same !== null && same["got"] === at ? same : null;\n if (kept === null) return this.error("refused", "the pieces of a push come in order");\n const back = begins ? await this.#tellsBy(far, given) : null;\n if (back !== null && typeof back !== "string") return back;\n const put = await this.ask("repos", "put", { at, pieces, bytes, as: `in-${far}` });\n if ("error" in put) return this.#heard(put);\n this.cells.set(["in", far], { ...kept, got: at + 1, last });\n return this.#receive(far);\n }\n async taken(args) {\n const refused = this.#serving("taken", args);\n if (refused !== null) return refused;\n const far = this.stamp.asker;\n const kept = this.cells.get(["in", far]);\n if (!_RepoLobe.#fields(kept)) return this.error("refused", "no push is coming");\n const ended = await this.#endOf(far, kept);\n if (ended !== null) return ended;\n await this.#check();\n await this.#receive(far);\n const now = this.cells.get(["in", far]);\n const doing = this.#repo()?.["doing"];\n const job = _RepoLobe.#text(doing) ? this.cells.get(["job", doing]) : void 0;\n const waiting = _RepoLobe.#fields(now) && now["run"] === null && now["got"] === now["pieces"];\n const waits = waiting && _RepoLobe.#fields(job) ? { waits: `the repo runs a ${_RepoLobe.#shown(job["kind"])} first` } : {};\n return { ready: false, ...waits };\n }\n async #receiveWaiting() {\n for (const { key } of this.#all(["in"])) {\n const far = key[1];\n if (_RepoLobe.#text(far)) await this.#receive(far);\n }\n }\n async #clear(as) {\n const asked = await this.ask("repos", "clear", { as });\n if ("error" in asked && asked.error.code === "busy") this.cells.set(["uncleared", as], null);\n else if (this.cells.get(["uncleared", as]) !== void 0) this.cells.delete(["uncleared", as]);\n }\n async #unclear() {\n for (const { key } of this.#all(["uncleared"])) {\n const as = key[1];\n if (_RepoLobe.#text(as)) await this.#clear(as);\n }\n }\n async #check() {\n await this.#unclear();\n const doing = this.#repo()?.["doing"];\n if (!_RepoLobe.#text(doing)) return;\n const checked = await this.ask("repos", "check", {});\n if ("error" in checked || !_RepoLobe.#fields(checked.result)) return;\n const { doing: running, lost, last } = checked.result;\n const held = this.cells.get(["job", doing]);\n if (running === doing || !_RepoLobe.#fields(held) || held["ended"] !== null) return;\n if (_RepoLobe.#fields(last) && last["job"] === doing) {\n const { code, out, err } = last;\n if (typeof code === "number" && typeof out === "string" && typeof err === "string") {\n await this.#jobEnded(await this.nerves.read(), doing, held, code, out, err);\n return;\n }\n }\n if (Array.isArray(lost) && lost.includes(doing)) return;\n const kept = await this.ask("repos", "job", { job: doing });\n const ended = "result" in kept ? _RepoLobe.#arg(_RepoLobe.#arg(kept.result, "ended") ?? null, "code") : void 0;\n if ("result" in kept && typeof ended !== "number") return;\n const whole = ended === 0;\n if (whole) {\n this.cells.delete(["undo"]);\n this.cells.set(["owed"], true);\n }\n const why = whole ? "the jailer ended this job whole, and its word of the end never came: its output is lost" : "the jailer runs this job no more, and its word of the end never came";\n await this.#jobEnded(await this.nerves.read(), doing, held, -1, "", why);\n await this.#awaiting();\n }\n async #tellsBy(far, invitation) {\n await this.#untold(far);\n if (!_RepoLobe.#text(invitation)) return null;\n const placeholder = _RepoLobe.#backUnder(_RepoLobe.#tells, far);\n const note = { repo: this.#repo()?.["name"] ?? null, tells: far };\n const accepted = await this.ask("mouth", "accept", { invitation, placeholder, note });\n if ("error" in accepted)\n return this.error(accepted.error.code, `the standing back was not taken: ${accepted.error.message}`);\n return placeholder;\n }\n async #untold(far, prefix = _RepoLobe.#tells) {\n const placeholder = _RepoLobe.#backUnder(prefix, far);\n const held = (await this.#relations()).find((one) => one.side === "standing" && one.placeholder === placeholder);\n if (held !== void 0) await this.#unlink({ placeholder, far: held.far });\n }\n async #tellEnds() {\n for (const { key, value } of this.#all(["in"])) {\n const far = key[1];\n if (typeof far !== "string" || !_RepoLobe.#fields(value) || value["told"] === true) continue;\n const told = await this.#endOf(far, value);\n if (told === null) continue;\n this.cells.set(key, { ...value, told: true });\n await this.ask(_RepoLobe.#backUnder(_RepoLobe.#tells, far), "done", told);\n }\n }\n async #endOf(far, kept) {\n const landed = kept["landed"] === true;\n const failed = kept["failed"];\n if (!landed && !_RepoLobe.#text(failed)) return null;\n const checked = kept["check"] ?? null;\n const scoped = checked !== null && await this.#scopeFor(far) !== null;\n const check = scoped ? { code: _RepoLobe.#arg(checked, "code") ?? null } : checked;\n const head = kept["head"];\n const ended = landed ? { code: 0, out: _RepoLobe.#text(head) ? `${head}\n` : "", err: "" } : { code: 1, out: "", err: _RepoLobe.#shown(failed) };\n return { job: kept["push"] ?? null, kind: "push", ...ended, check };\n }\n async #receive(far) {\n const kept = this.cells.get(["in", far]);\n const repo = this.#repo();\n if (!_RepoLobe.#fields(kept) || kept["got"] !== kept["pieces"] || kept["run"] !== null) return null;\n if (repo === null || _RepoLobe.#text(repo["doing"])) return null;\n const scope = await this.#scopeFor(far);\n const given = { as: `in-${far}`, pieces: kept["pieces"] ?? 1, ...scope === null ? {} : { scope } };\n const begun = await this.#begin("bring", given, { for: far }, { asker: far });\n if ("job" in begun) this.cells.set(["in", far], { ...kept, run: begun.job });\n return null;\n }\n async #served(far, kind, why, out) {\n const key = kind === "bundle" || kind === "cut" ? ["out", far] : ["in", far];\n const kept = this.cells.get(key);\n if (!_RepoLobe.#fields(kept)) return;\n const [first = "", second = "", third = ""] = out.trim().split("\\n");\n if (kind === "cut") return this.#cutGiven(far, kept, why);\n if (kind === "bundle") {\n this.cells.set(key, {\n ...kept,\n pieces: why === null ? Number(first) : null,\n head: second || null,\n failed: why\n });\n return;\n }\n if (kind === "bring") return this.#pushBrought(far, kept, why, first, second, third);\n if (kind === "land") return this.#pushLanded(far, kept, why, out);\n const repo = this.#repo();\n if (kind !== "head") return void 0;\n if (why === null && second === "holds" && repo !== null) this.cells.set(["repo"], { ...repo, rebuilds: null });\n this.cells.set(key, { ...kept, landed: true });\n return void 0;\n }\n async #cutGiven(far, kept, why) {\n if (why !== null) {\n this.cells.set(["out", far], { ...kept, failed: why });\n return;\n }\n const piece = typeof kept["piece"] === "number" ? { piece: kept["piece"] } : {};\n const given = { since: kept["since"] ?? null, as: `out-${far}`, cut: true, ...piece };\n const begun = await this.#begin("bundle", given, { for: far }, { asker: far });\n this.cells.set(["out", far], "job" in begun ? { ...kept, run: begun.job } : { ...kept, failed: begun.message });\n }\n async #pushBrought(far, kept, why, head, how, tip) {\n const key = ["in", far];\n if (why !== null) {\n this.cells.set(key, { ...kept, failed: why });\n return;\n }\n if (how === "held") {\n this.cells.set(key, { ...kept, head, landed: true });\n return;\n }\n const check = await this.#conform(`in-${far}`, head, true, far);\n this.cells.set(key, { ...kept, head, check, ...how === "graft" && _RepoLobe.#text(tip) ? { tip } : {} });\n if ("code" in check) await this.#verdict(far);\n }\n async #pushLanded(far, kept, why, out) {\n const tip = kept["tip"];\n const head = _RepoLobe.#text(tip) ? tip : _RepoLobe.#headOf(out);\n const rebuilds = this.#repo()?.["rebuilds"];\n const proving = why === null && _RepoLobe.#text(rebuilds) && "job" in await this.#begin("head", { contains: rebuilds }, { for: far }, { asker: far });\n const landed = why !== null ? { failed: why } : proving ? { head } : { head, landed: true };\n this.cells.set(["in", far], { ...kept, ...landed });\n }\n async #conform(as, head, push, asker) {\n const script = this.#gateScript();\n const gated = push && this.#gates().push === "on" && _RepoLobe.#text(script);\n const given = {\n as,\n head,\n ...this.#checks(),\n ...gated ? { script } : {}\n };\n const begun = await this.#begin("check", given, { check: as }, { asker, method: "conform" });\n if ("job" in begun) return { job: begun.job };\n return { code: 1, out: "", err: `the check did not begin: ${begun.message}` };\n }\n #checks() {\n if (this.#holdsScope()) return { parts: _RepoLobe.parts, scoped: true };\n const conform = this.cells.get(["conform"]);\n return { parts: _RepoLobe.parts, ..._RepoLobe.#text(conform) ? { conform } : {} };\n }\n async #checked(as, check) {\n const tail = {\n ...check,\n out: _RepoLobe.#last(_RepoLobe.#shown(check["out"])),\n err: _RepoLobe.#last(_RepoLobe.#shown(check["err"]))\n };\n if (as === "pull") {\n const sync = this.cells.get(["sync"]);\n if (!_RepoLobe.#fields(sync) || sync["stage"] !== "checking") return;\n const checked = { ...sync, check: tail };\n this.cells.set(["sync"], checked);\n return this.#checkedPull(checked, tail);\n }\n const far = as.startsWith("in-") ? as.slice(3) : "";\n const kept = this.cells.get(["in", far]);\n if (!_RepoLobe.#fields(kept)) return;\n this.cells.set(["in", far], { ...kept, check: tail });\n return this.#verdict(far);\n }\n static #last(text) {\n const last = text.slice(-_RepoLobe.#tail);\n return /^[\\uDC00-\\uDFFF]/.test(last) ? last.slice(1) : last;\n }\n async #verdict(far) {\n const kept = this.cells.get(["in", far]);\n const check = _RepoLobe.#arg(kept, "check");\n if (!_RepoLobe.#fields(kept) || !_RepoLobe.#fields(check) || !("code" in check)) return;\n if (check["code"] !== 0) {\n this.cells.set(["in", far], {\n ...kept,\n failed: _RepoLobe.#refusalOf(check, await this.#scopeFor(far) !== null)\n });\n return;\n }\n if (_RepoLobe.#text(kept["landing"]) || _RepoLobe.#text(this.#repo()?.["doing"])) return;\n const as = `in-${far}`;\n const begun = await this.#begin("land", { as }, { for: far }, { asker: far });\n if ("job" in begun) this.cells.set(["in", far], { ...kept, landing: begun.job });\n }\n static #refusalOf(check, bare = false) {\n if (bare) return "its check is red";\n const said = `${_RepoLobe.#shown(check["out"])}\n${_RepoLobe.#shown(check["err"])}`.trim();\n const tail = said.slice(-_RepoLobe.#tail);\n return `its check is red:\n${tail || `it ended ${typeof check["code"] === "number" ? check["code"] : "unread"}`}`;\n }\n async #authoring(repo) {\n const writers = (await this.#given()).some(({ note }) => _RepoLobe.#kindOf(note) === "writer");\n if (!writers) return null;\n if (this.cells.get(["author"]) !== this.stamp.asker)\n return this.error("refused", "far writers push to this lobe: only its author commits beside it");\n if (_RepoLobe.#text(repo["rebuilds"])) return this.error("refused", "the lobe rebuilds: it is pushed whole first");\n return null;\n }\n #filesOf(files) {\n if (files === void 0) return {};\n if (!_RepoLobe.#fields(files)) return null;\n const all = Object.entries(files);\n if (all.length > this.#most() || all.some(([path, text]) => path === "" || typeof text !== "string")) return null;\n return files;\n }\n #pathsOf(paths) {\n if (paths === void 0) return [];\n if (!Array.isArray(paths) || paths.length < 1 || paths.length > this.#most()) return null;\n const named = paths.flatMap((one) => typeof one === "string" ? [one] : []);\n const fit = (one) => one.split("/").every((name) => _RepoLobe.#entry.test(name));\n return named.length === paths.length && named.every(fit) ? named : null;\n }\n async commit(args) {\n const refused = this.#refusal("commit", args);\n if (refused !== null) return refused;\n const message = _RepoLobe.#arg(args, "message");\n const files = this.#filesOf(_RepoLobe.#arg(args, "files"));\n if (!_RepoLobe.#text(message)) return this.error("refused", "a commit holds its message");\n if (files === null)\n return this.error("refused", `a commit\'s files are each a path and its text, ${this.#most()} at most`);\n const paths = this.#pathsOf(_RepoLobe.#arg(args, "paths"));\n if (paths === null)\n return this.error("refused", `a commit\'s paths are each a file or a folder of the repo, ${this.#most()} at most`);\n if (paths.length > 0 && Object.keys(files).length > 0)\n return this.error("refused", "a commit writes files or takes paths, not both");\n const executable = _RepoLobe.#arg(args, "executable") ?? [];\n if (!Array.isArray(executable) || executable.some((path) => typeof path !== "string" || !Object.hasOwn(files, path)))\n return this.error("refused", "what a commit makes executable are paths among its files");\n const ready = this.#ready();\n if (!("name" in ready)) return ready;\n const unauthored = await this.#authoring(ready.repo);\n if (unauthored !== null) return unauthored;\n const gating = this.#commitGate(args);\n if (typeof gating !== "boolean") return gating;\n if (_RepoLobe.#text(ready.repo["doing"])) {\n await this.#check();\n return this.error("refused", `the repo runs ${ready.repo["doing"]} already`);\n }\n const written = Object.keys(files);\n const before = written.length === 0 ? null : await this.#before(written);\n if (before !== null && "code" in before) return before;\n if (before !== null) this.cells.set(["undo"], executable.length === 0 ? before : { ...before, executable });\n else if (paths.length > 0) this.cells.set(["undo"], { files: [], dirs: [], paths });\n for (const [path, text] of Object.entries(files)) {\n const wrote = await this.ask("repos", "write", { path, text: text ?? "" });\n if ("error" in wrote) return this.error(wrote.error.code, await this.#undone(`${path}: ${wrote.error.message}`));\n }\n const script = this.#gateScript();\n const begun = !gating || !_RepoLobe.#text(script) ? await this.#begin("commit", this.#committing(message), null) : (\n await this.#gating(message, { script, install: true, gate: true })\n );\n if ("job" in begun) return begun;\n return this.error(begun.code, await this.#undone(begun.message));\n }\n #committing(message) {\n const kept = this.cells.get(["undo"]) ?? null;\n const [executable, paths] = [_RepoLobe.#arg(kept, "executable"), _RepoLobe.#arg(kept, "paths")];\n return {\n message,\n ...executable === void 0 ? {} : { executable },\n ...paths === void 0 ? {} : { paths },\n ...this.#checks()\n };\n }\n async #gating(message, gate) {\n if (!this.#keyed()) return this.#begin("commit", gate, null, { method: "run", more: { gating: message } });\n const more = { running: gate, commits: message };\n return this.#begin("commit", { set: await this.#keys() }, null, { method: "secrets", more });\n }\n async #before(paths) {\n const files = [];\n const stands = new Map();\n const dirs = [];\n for (const path of paths) {\n const read = await this.ask("repos", "read", { path });\n if ("error" in read) {\n if (read.error.code !== "absent") return this.error(read.error.code, `${path}: ${read.error.message}`);\n files.push({ path, was: null });\n } else {\n const was = _RepoLobe.#arg(read.result, "text");\n if (typeof was !== "string") return this.error("refused", `${path}: it holds no text`);\n files.push({ path, was });\n }\n const names = path.split("/");\n for (let at = 1; at < names.length; at += 1) {\n const dir = names.slice(0, at).join("/");\n if (!stands.has(dir)) {\n const parent = at === 1 ? true : stands.get(names.slice(0, at - 1).join("/"));\n const listed = parent ? await this.ask("repos", "list", { path: dir }) : null;\n stands.set(dir, listed !== null && !("error" in listed));\n }\n if (stands.get(dir) === false && !dirs.includes(dir)) dirs.push(dir);\n }\n }\n return { files, dirs };\n }\n async #undone(why) {\n const undo = this.cells.get(["undo"]);\n if (!_RepoLobe.#fields(undo)) return why;\n const [files, dirs] = [undo["files"], undo["dirs"]];\n const lost = [];\n for (const one of Array.isArray(files) ? files : []) {\n const path = _RepoLobe.#arg(one, "path");\n const was = _RepoLobe.#arg(one, "was");\n if (typeof path !== "string") continue;\n const put = typeof was === "string" ? await this.ask("repos", "write", { path, text: was }) : await this.ask("repos", "erase", { path });\n if ("error" in put && !(was === null && put.error.code === "absent")) lost.push(path);\n }\n const made = Array.isArray(dirs) ? dirs.filter((dir) => typeof dir === "string") : [];\n for (const path of made.toReversed()) await this.ask("repos", "erase", { path });\n this.cells.delete(["undo"]);\n if (!Array.isArray(files) || files.length === 0) return why;\n return lost.length === 0 ? `${why.trimEnd()}\nthe files it wrote are put back as they were before the ask` : `${why.trimEnd()}\nthe files it wrote could not all be put back: ${lost.join(", ")}`;\n }\n #commitGate(args) {\n const asked = _RepoLobe.#arg(args, "gate");\n const { commit } = this.#gates();\n if (asked === false && commit === "mandatory")\n return this.error("refused", "the setting on commit is mandatory: no commit skips the gate");\n return asked === true || commit !== "off" && asked !== false;\n }\n async #gated(held, run, code, out, err) {\n const repo = this.#repo();\n if (repo !== null) this.cells.set(["repo"], { ...repo, doing: null });\n const message = _RepoLobe.#shown(held["gating"]);\n const asker = _RepoLobe.#text(held["asker"]) ? held["asker"] : _RepoLobe.#owner;\n const first = _RepoLobe.#arg(held["step"] ?? null, "ran");\n const holds = _RepoLobe.#text(first) ? first : run;\n if (holds !== run) {\n const { gating: _, ...step } = held;\n this.cells.set(["job", run], { ...step, ended: { run, code, out, err, at: this.stamp.time } });\n }\n if (code === 0 || code === 3 && err.includes("holds no script")) {\n const begun = await this.#begin("commit", this.#committing(message), { commit: holds }, { asker });\n if ("job" in begun) return null;\n return this.#commitEnded(holds, 1, "", await this.#undone(`the commit is refused: ${begun.message}`));\n }\n const why = await this.#undone(`the commit is refused: the gate is red\n${_RepoLobe.#last(err)}`);\n await this.#commitEnded(holds, code, _RepoLobe.#last(out), why);\n return null;\n }\n async #commitEnded(run, code, out, err, more = {}) {\n const first = this.cells.get(["job", run]);\n if (!_RepoLobe.#fields(first)) return null;\n const { gating: _, running: __, commits: ___, ...kept } = first;\n this.cells.set(["job", run], { ...kept, ended: { run, code, out, err, ...more, at: this.stamp.time } });\n await this.#ended(kept, code, out, err, more);\n return null;\n }\n status(args) {\n return this.#work("status", args, {});\n }\n log(args) {\n const most = _RepoLobe.#arg(args, "most");\n return this.#work("log", args, most === void 0 ? {} : { most });\n }\n discard(args) {\n return this.#work("discard", args, {});\n }\n async run(args) {\n const script = _RepoLobe.#arg(args, "script");\n const install = _RepoLobe.#arg(args, "install") ?? false;\n const words = _RepoLobe.#argsOf(_RepoLobe.#arg(args, "args"));\n if (!_RepoLobe.#text(script) || !_RepoLobe.#script.test(script))\n return this.error("refused", "a run names a script of the repo\'s package");\n if (typeof install !== "boolean") return this.error("refused", "install is true or false");\n if (words === null)\n return this.error("refused", `a run\'s args are texts, at most ${_RepoLobe.#argsMost}, none holding a NUL`);\n const gate = script === this.#gateScript() ? { gate: true } : {};\n const given = { script, ...words.length === 0 ? {} : { args: words }, install, ...gate };\n const scripts = _RepoLobe.#arg(this.stamp.occupant?.note, "scripts");\n if (this.#role() === "runner" && !(Array.isArray(scripts) && scripts.includes(script)))\n return this.error("refused", `the runner runs ${script} not`);\n return this.#keyed() ? this.#keysFirst("run", args, given) : this.#work("run", args, given);\n }\n static #argsOf(args) {\n if (args === void 0) return [];\n if (!Array.isArray(args) || args.length > _RepoLobe.#argsMost) return null;\n const all = args.flatMap(\n (one) => typeof one === "string" && one.length <= _RepoLobe.#argLongest && !one.includes("\\0") ? [one] : []\n );\n return all.length === args.length ? all : null;\n }\n async #writtenThen(held, run, code, err) {\n const repo = this.#repo();\n if (repo !== null) this.cells.set(["repo"], { ...repo, doing: null });\n const asker = _RepoLobe.#text(held["asker"]) ? held["asker"] : _RepoLobe.#owner;\n const kind = "run";\n const commits = held["kind"] === "commit";\n if (code !== 0) {\n const why = `its secret file was not written: ${err}`;\n if (commits) await this.#commitEnded(run, code, "", await this.#undone(`the commit is refused: ${why}`));\n else await this.#workEnded(run, kind, code, "", why);\n return null;\n }\n if (Object.keys(await this.#keys()).length > 0) this.cells.set(["env"], true);\n else this.cells.delete(["env"]);\n const running = _RepoLobe.#fields(held["running"]) ? held["running"] : {};\n if (commits) {\n const more = { gating: _RepoLobe.#shown(held["commits"]) };\n const gate = await this.#begin("commit", running, { ran: run }, { asker, method: "run", more });\n if ("job" in gate) return null;\n await this.#commitEnded(run, 1, "", await this.#undone(`the commit is refused: ${gate.message}`));\n return null;\n }\n const begun = await this.#begin(kind, running, { ran: run }, { asker });\n if ("job" in begun) return null;\n await this.#workEnded(run, kind, 1, "", `the ${kind} did not begin: ${begun.message}`);\n return null;\n }\n async #workEnded(run, kind, code, out, err, more = {}) {\n const first = this.cells.get(["job", run]);\n if (!_RepoLobe.#fields(first)) return;\n const { running: _, ...kept } = first;\n this.cells.set(["job", run], { ...kept, ended: { run, code, out, err, ...more, at: this.stamp.time } });\n await this.#ended({ ...kept, kind }, code, out, err, more);\n }\n #torn(read) {\n const all = "result" in read && Array.isArray(read.result) ? read.result : [];\n const ends = new Set(all.map((wire) => _RepoLobe.#arg(wire, "termination")));\n for (const { key } of this.#all(["back"])) if (!ends.has(key[1])) this.cells.delete(key);\n }\n async #credentials() {\n if (this.#all(["credential"]).length === 0 && this.#all(["token"]).length === 0) return [];\n const kept = (await this.#relations()).flatMap((one) => {\n const secret = _RepoLobe.#arg(one.note, "credential");\n return one.side === "standing" && _RepoLobe.#text(secret) ? [{ secret, far: one.far, placeholder: one.placeholder }] : [];\n });\n return kept.toSorted((a, b) => _RepoLobe.#order(a.secret, b.secret));\n }\n async setToken(args) {\n const refused = this.#refusal("setToken", {});\n if (refused !== null) return refused;\n const name = _RepoLobe.#arg(args, "name");\n const value = _RepoLobe.#arg(args, "value");\n if (!_RepoLobe.#text(name) || !_RepoLobe.#key.test(name))\n return this.error("refused", "a token\'s name is an environment variable\'s name");\n if (value !== null && (typeof value !== "string" || /[\\n\\r\\0]/.test(value)))\n return this.error("refused", "a token is one line of text, or null to remove it");\n if ((await this.#credentials()).some((one) => one.secret === name))\n return this.error("refused", "a credential keeps that name: drop it");\n if (value !== null && this.cells.get(["secret", name]) === void 0 && this.#all(["secret"]).length >= this.#most())\n return this.error("refused", `a copy keeps ${this.#most()} keys at most`);\n if (value === null) this.cells.delete(["secret", name]);\n else this.cells.set(["secret", name], value);\n return null;\n }\n async #forgo(held) {\n await this.#giveUp(held);\n this.cells.delete(["token", held.far]);\n this.cells.delete(["credential", held.far]);\n return null;\n }\n async #giveUp(held) {\n await this.ask("mouth", "drop", { far: held.far });\n if (_RepoLobe.#text(held.placeholder)) await this.nerves.unwire(held.placeholder);\n }\n async credential(args) {\n const refused = this.#refusal("credential", args);\n if (refused !== null) return refused;\n const secret = _RepoLobe.#arg(args, "secret");\n const invitation = _RepoLobe.#arg(args, "invitation");\n const wired = _RepoLobe.#arg(args, "placeholder");\n if (!_RepoLobe.#text(secret) || !_RepoLobe.#issued.test(secret))\n return this.error(\n "refused",\n "a credential\'s secret is an environment variable\'s name in capitals, its words joined by single underscores"\n );\n const cap = await this.#cap("within", _RepoLobe.#issuerWithin);\n if (typeof cap !== "number") return cap;\n const named = _RepoLobe.#arg(args, "within");\n if (typeof named === "number" && named > cap)\n return this.error(\n "refused",\n `an issuer may keep a credential waiting ${cap} ms at most, a cap an owner\'s word moves`\n );\n const within = typeof named === "number" ? named : cap;\n const held = (await this.#credentials()).find((one) => one.secret === secret);\n if (held !== void 0) {\n if (invitation !== void 0 || wired !== void 0)\n return this.error(\n "refused",\n "a standing keeps that secret already: drop it, or ask again with no invitation and no placeholder"\n );\n return this.#askIssuer(secret, held.far, held.placeholder, "kept", within);\n }\n if (invitation !== void 0 && wired !== void 0)\n return this.error("refused", "a credential is taken by an invitation or by a placeholder, not both");\n if (this.cells.get(["secret", secret]) !== void 0)\n return this.error("refused", "a token keeps that name: remove it by setToken");\n if (_RepoLobe.#text(wired)) return this.#takenOver(secret, wired, within);\n if (!_RepoLobe.#text(invitation)) return this.error("refused", "an invitation or a placeholder is named");\n const placeholder = `credential-${secret.toLowerCase().replaceAll("_", "-")}`;\n const given = _RepoLobe.#arg(args, "note");\n const note = given ?? { repo: this.#repo()?.["name"] ?? null, credential: secret };\n const accepted = await this.ask("mouth", "accept", { invitation, placeholder, note });\n if ("error" in accepted) return this.#result(accepted);\n const far = _RepoLobe.#arg(accepted.result, "far");\n if (!_RepoLobe.#text(far)) return this.error("refused", "the mouth named no far organism");\n const noted = await this.#noted(far, { credential: secret });\n if (noted !== null) {\n await this.#giveUp({ far, placeholder });\n return this.error("refused", noted);\n }\n return this.#askIssuer(secret, far, placeholder, "accepted", within);\n }\n async #takenOver(secret, placeholder, within) {\n const standing = (await this.#relations()).find(\n (one) => one.side === "standing" && one.placeholder === placeholder\n );\n if (standing === void 0) return this.error("refused", `the placeholder ${placeholder} is wired to no standing`);\n if (_RepoLobe.#text(_RepoLobe.#arg(standing.note, "credential")))\n return this.error("refused", "that standing keeps another secret already");\n const noted = await this.#noted(standing.far, { credential: secret });\n if (noted !== null) return this.error("refused", noted);\n return this.#askIssuer(secret, standing.far, placeholder, "wired", within);\n }\n #askAgain(asked, since, within, silent = false) {\n const ready = "result" in asked ? _RepoLobe.#arg(asked.result, "ready") : void 0;\n silent &&= "error" in asked && _RepoLobe.#waits.includes(asked.error.code);\n if (!silent && !(typeof ready === "number" && Number.isSafeInteger(ready))) return null;\n const soonest = this.stamp.time + _RepoLobe.#spell;\n const next = typeof ready === "number" ? Math.max(ready, soonest) : soonest;\n return next <= since + within ? next : null;\n }\n #keptToken(far, cell, result) {\n const value = _RepoLobe.#arg(result, "value");\n const url = _RepoLobe.#arg(result, "url");\n if (!_RepoLobe.#text(value) || /[\\n\\r\\0]/.test(value)) return false;\n this.cells.set(["token", far], value);\n const { failed: _, next: __, expires: ___, renews: ____, since: _____, within: ______, ...rest } = cell;\n const where = _RepoLobe.#text(url) ? { url } : {};\n const expires = _RepoLobe.#arg(result, "expires");\n const life = typeof expires === "number" && Number.isInteger(expires) ? expires - this.stamp.time : 0;\n const ends = life > 0 ? { expires: Number(expires), renews: Number(expires) - Math.floor(life / 10) } : {};\n this.cells.set(["credential", far], { ...rest, pending: false, ...where, ...ends });\n return true;\n }\n #renewedAgain(expires) {\n const left = typeof expires === "number" ? Math.floor((expires - this.stamp.time) / 2) : 0;\n return this.stamp.time + Math.max(_RepoLobe.#minute, left);\n }\n async #renewAt(at, ringing) {\n const set = this.cells.get(["renews"]);\n if (typeof set === "number" && set > this.stamp.time && set <= at) return false;\n this.cells.set(["renews"], at);\n const when = Math.max(at, this.stamp.time + _RepoLobe.#spell);\n if (!ringing) await this.#alarm({ at: when, method: "renew", args: {} });\n return true;\n }\n #nextRenewal() {\n let next = null;\n for (const { value } of this.#all(["credential"])) {\n const renews = _RepoLobe.#arg(value, "renews");\n if (typeof renews !== "number" || _RepoLobe.#arg(value, "pending") === true) continue;\n if (next === null || renews < next) next = renews;\n }\n return next;\n }\n async #askIssuer(secret, far, placeholder, how, within) {\n if (!_RepoLobe.#text(placeholder)) return this.error("refused", "the standing has no relation");\n const cell = this.cells.get(["credential", far]);\n const before = _RepoLobe.#fields(cell) ? cell : {};\n const asked = await this.ask(placeholder, "credential", {});\n const next = this.#askAgain(asked, this.stamp.time, within);\n if (next !== null) {\n this.cells.set(["credential", far], { ...before, pending: true, since: this.stamp.time, within, next });\n const set = await this.#alarm({ at: next, method: "renew", args: {} });\n return "error" in set ? this.#result(set) : { secret, pending: true };\n }\n if (!("error" in asked) && this.#keptToken(far, before, asked.result)) {\n const renews = this.#nextRenewal();\n if (renews !== null) await this.#renewAt(renews, false);\n return { secret };\n }\n if (how === "accepted") await this.#giveUp({ far, placeholder });\n if (how === "wired") await this.#noted(far, null);\n return "error" in asked ? this.error(asked.error.code, asked.error.message) : this.error("refused", "the issuer gave no secret of one line");\n }\n async #renewOne(far, value) {\n const placeholder = (await this.#endOfFar(far))?.placeholder;\n const asked = _RepoLobe.#text(placeholder) ? await this.ask(placeholder, "credential", {}) : { error: { code: "refused", message: "the standing has no relation" } };\n if ("result" in asked && this.#keptToken(far, value, asked.result)) return "given";\n const ready = "result" in asked ? _RepoLobe.#arg(asked.result, "ready") : void 0;\n const cap = typeof ready === "number" ? await this.#cap("within", _RepoLobe.#issuerWithin) : _RepoLobe.#issuerWithin;\n const within = typeof cap === "number" ? cap : _RepoLobe.#issuerWithin;\n const next = this.#askAgain(asked, this.stamp.time, within);\n if (next !== null) {\n this.cells.set(["credential", far], { ...value, pending: true, since: this.stamp.time, within, next });\n return "pending";\n }\n const why = "error" in asked ? asked.error.message : "it gave no secret of one line";\n const failed = `the issuer renewed no secret: ${why}`;\n this.cells.set(["credential", far], { ...value, failed, renews: this.#renewedAgain(value["expires"]) });\n return "failed";\n }\n async #issuedAgain(far, value) {\n const since = typeof value["since"] === "number" ? value["since"] : this.stamp.time;\n const within = typeof value["within"] === "number" ? value["within"] : _RepoLobe.#issuerWithin;\n const placeholder = (await this.#endOfFar(far))?.placeholder;\n const asked = _RepoLobe.#text(placeholder) ? await this.ask(placeholder, "credential", {}) : { error: { code: "refused", message: "the standing has no relation" } };\n const { next: _, ...rest } = value;\n if ("result" in asked && this.#keptToken(far, rest, asked.result)) return "given";\n const next = this.#askAgain(asked, since, within, true);\n if (next !== null) {\n this.cells.set(["credential", far], { ...rest, next });\n return "pending";\n }\n const ready = "result" in asked ? _RepoLobe.#arg(asked.result, "ready") : void 0;\n const why = "error" in asked ? asked.error.message : typeof ready === "number" ? "it is made only after then" : "it gave no secret of one line";\n const failed = `the issuer gave no secret in ${within} ms: ${why}`;\n const again = typeof rest["expires"] === "number" ? { renews: this.#renewedAgain(rest["expires"]) } : {};\n const { since: ___, within: ____, ...left } = rest;\n this.cells.set(["credential", far], { ...left, pending: false, failed, ...again });\n return "failed";\n }\n async renew() {\n let soonest = null;\n const waiting = (far) => {\n const next = _RepoLobe.#arg(this.cells.get(["credential", far]) ?? null, "next");\n if (typeof next === "number" && (soonest === null || next < soonest)) soonest = next;\n };\n for (const { key, value } of this.#all(["credential"])) {\n const far = key[1];\n if (typeof far !== "string" || !_RepoLobe.#fields(value)) continue;\n if (value["pending"] !== true) {\n const renews2 = value["renews"];\n if (typeof renews2 !== "number" || this.stamp.time < renews2) continue;\n if (await this.#renewOne(far, value) === "pending") waiting(far);\n continue;\n }\n if (typeof value["next"] === "number" && this.stamp.time < value["next"]) {\n waiting(far);\n continue;\n }\n if (await this.#issuedAgain(far, value) === "pending") waiting(far);\n }\n if (soonest !== null) return { again: soonest };\n const renews = this.#nextRenewal();\n if (renews === null || !await this.#renewAt(renews, true)) return null;\n return { again: Math.max(renews, this.stamp.time + _RepoLobe.#spell) };\n }\n async #keys() {\n const values = {};\n for (const { key, value } of this.#all(["secret"]))\n if (typeof key[1] === "string" && typeof value === "string") values[key[1]] = value;\n for (const { secret, far } of await this.#credentials()) {\n const token = this.cells.get(["token", far]);\n if (typeof token === "string") values[secret] = token;\n }\n return values;\n }\n #keyed() {\n return this.cells.get(["env"]) !== void 0 || this.#all(["secret"]).length > 0 || this.#all(["token"]).length > 0;\n }\n #masked(text) {\n let shown = text;\n for (const { value } of [...this.#all(["secret"]), ...this.#all(["token"])])\n if (typeof value === "string" && value.length > 0) shown = shown.split(value).join("[secret]");\n return shown;\n }\n async #keysFirst(kind, args, given) {\n const refused = this.#refusal(kind, args);\n if (refused !== null) return refused;\n const ready = this.#ready();\n if (!("name" in ready)) return ready;\n return this.#begin(kind, { set: await this.#keys() }, null, { method: "secrets", more: { running: given } });\n }\n async #work(kind, args, given, begun = {}) {\n const refused = this.#refusal(kind, args);\n if (refused !== null) return refused;\n const ready = this.#ready();\n if (!("name" in ready)) return ready;\n return this.#begin(kind, given, null, begun);\n }\n async read(args) {\n const refused = this.#refusal("read", args);\n if (refused !== null) return refused;\n const paths = _RepoLobe.#arg(args, "paths");\n if (paths !== void 0) {\n const lone = _RepoLobe.#arg(args, "path") === void 0 && _RepoLobe.#arg(args, "first") === void 0;\n if (!lone || !Array.isArray(paths) || paths.length < 1)\n return this.error("refused", "paths are one file or more, without path or first");\n return this.#result(await this.ask("repos", "read", { paths }));\n }\n const first = _RepoLobe.#arg(args, "first");\n const path = _RepoLobe.#arg(args, "path") ?? null;\n return this.#result(await this.ask("repos", "read", first === void 0 ? { path } : { path, first }));\n }\n async list(args) {\n const refused = this.#refusal("list", args);\n if (refused !== null) return refused;\n const path = _RepoLobe.#arg(args, "path");\n return this.#result(await this.ask("repos", "list", path === void 0 ? {} : { path }));\n }\n async stop(args) {\n const refused = this.#refusal("stop", args);\n if (refused !== null) return refused;\n const doing = this.#repo()?.["doing"];\n const held = _RepoLobe.#text(doing) ? this.cells.get(["job", doing]) : void 0;\n const sync = this.cells.get(["sync"]);\n if (_RepoLobe.#fields(sync)) {\n const kind = _RepoLobe.#shown(sync["kind"]);\n if (this.stamp.asker !== _RepoLobe.#owner && sync["asker"] !== this.stamp.asker)\n return this.error("refused", `the repo runs another\'s ${kind}`);\n const step = _RepoLobe.#arg(held ?? null, "step");\n const own = _RepoLobe.#arg(step ?? null, "sync") === true;\n if (own && _RepoLobe.#arg(held ?? null, "kind") === "land")\n return this.error("refused", `the ${kind} lands already: it ends once landed`);\n if (own && _RepoLobe.#text(doing) && _RepoLobe.#fields(held))\n this.cells.set(["job", doing], { ...held, step: { stopped: true } });\n await this.#finish(sync, 1, `the ${kind} was stopped`);\n return null;\n }\n if (!_RepoLobe.#text(doing)) return this.error("refused", "the repo runs nothing");\n const asker = _RepoLobe.#arg(held, "asker");\n if (this.stamp.asker !== _RepoLobe.#owner && asker !== this.stamp.asker)\n return this.error("refused", "the repo runs another\'s job");\n return this.#heard(await this.ask("repos", "stop", {}));\n }\n pull(args) {\n return this.#sync("pull", args);\n }\n push(args) {\n return this.#sync("push", args);\n }\n async #sync(kind, args) {\n const refused = this.#refusal(kind, args);\n if (refused !== null) return refused;\n const ready = this.#ready();\n if (!("name" in ready)) return ready;\n const tag = _RepoLobe.#arg(args, "tag");\n if (tag !== void 0 && !(kind === "pull" && _RepoLobe.#text(tag) && _RepoLobe.#tag.test(tag)))\n return this.error("refused", "a pull names a tag, v and three whole numbers; a push names none");\n if (this.cells.get(["sync"]) !== void 0 && !await this.#stalled())\n return this.error("refused", "the repo pulls or pushes already");\n const on = await this.#standingOn(_RepoLobe.#arg(args, "on"));\n if (!("far" in on)) return on;\n const piece = _RepoLobe.#arg(args, "piece");\n const still = _RepoLobe.#arg(args, "still");\n return this.#start(kind, this.stamp.asker, _RepoLobe.#shown(on["placeholder"]), {\n ...typeof tag === "string" ? { tag } : {},\n ...typeof piece === "number" ? { piece } : {},\n ...typeof still === "number" ? { still } : {},\n ..._RepoLobe.#arg(args, "tells") === true ? { tells: true } : {}\n });\n }\n async #stalled() {\n const sync = this.cells.get(["sync"]);\n return _RepoLobe.#fields(sync) && [..._RepoLobe.#syncFar, "headed"].includes(_RepoLobe.#shown(sync["stage"])) && await this.#stood(sync);\n }\n async #start(kind, asker, on, named = {}) {\n const cap = await this.#cap("still", _RepoLobe.#still);\n if (typeof cap !== "number") return cap;\n const still = named["still"];\n if (typeof still === "number" && still > cap)\n return this.error("refused", `a ${kind} may stand still ${cap} ms at most, a cap an owner\'s word moves`);\n const capped = still === void 0 && cap !== _RepoLobe.#still ? { still: cap } : {};\n const back = await this.#back(asker);\n if (back !== null) return back;\n const job = `${kind}-${this.#nonce()}`;\n const stage = kind === "pull" ? "asking" : "heading";\n const chain = this.#nonce();\n const sync = { job, kind, chain, asker, on, stage, at: 0, pieces: null, moved: this.stamp.time };\n this.cells.set(["sync"], { ...sync, ...named, ...capped });\n const set = await this.#alarm({ at: this.stamp.time, method: "tick", args: { chain } });\n return "error" in set ? this.error(set.error.code, set.error.message) : { job };\n }\n async #cap(name, otherwise) {\n const word = await this.ask("nerves", "limit", { name });\n if ("error" in word) return this.error(word.error.code, word.error.message);\n return typeof word.result === "number" ? Math.min(word.result, _RepoLobe.#lifted) : otherwise;\n }\n async #rung(before) {\n const sync = this.cells.get(["sync"]);\n if (!_RepoLobe.#fields(sync) || !_RepoLobe.#fields(before) || !_RepoLobe.#moved(before, sync)) return;\n const chain = this.#nonce();\n const set = await this.#alarm({ at: this.stamp.time, method: "tick", args: { chain } });\n this.cells.set(["sync"], { ...sync, moved: this.stamp.time, ..."error" in set ? {} : { chain } });\n }\n static #moved(before, after) {\n return after["stage"] !== before["stage"] || after["at"] !== before["at"];\n }\n static #askerOf(sync) {\n return _RepoLobe.#text(sync["asker"]) ? sync["asker"] : _RepoLobe.#owner;\n }\n static #of(sync) {\n return { asker: _RepoLobe.#askerOf(sync) };\n }\n async tick(args) {\n const sync = this.cells.get(["sync"]);\n if (!_RepoLobe.#fields(sync) || sync["chain"] !== _RepoLobe.#arg(args, "chain")) return null;\n const over = sync["on"];\n if (!_RepoLobe.#text(over)) {\n await this.#finish(sync, 1, "the lobe stands on that lobe no more");\n return null;\n }\n const far = _RepoLobe.#syncFar.includes(_RepoLobe.#shown(sync["stage"]));\n if (far && await this.#stood(sync)) return null;\n if (sync["stage"] === "waiting" && _RepoLobe.#text(sync["tells"])) return { again: _RepoLobe.#stillEnds(sync) };\n if (far) await this.#step(sync, over);\n else if (sync["stage"] === "headed") await this.#bundling(sync);\n else await this.#check();\n const kept = this.cells.get(["sync"]);\n if (!_RepoLobe.#fields(kept)) return null;\n if (_RepoLobe.#moved(sync, kept)) return { again: this.stamp.time };\n return { again: this.stamp.time + (far || kept["stage"] === "headed" ? _RepoLobe.#every : MINUTE) };\n }\n static #syncFar = ["asking", "getting", "heading", "sending", "waiting"];\n async #step(sync, over) {\n const { stage } = sync;\n if (stage === "asking") await this.#asking(sync, over);\n else if (stage === "getting") await this.#getting(sync, over);\n else if (stage === "heading") await this.#heading(sync, over);\n else if (stage === "sending") await this.#sending(sync, over);\n else if (stage === "waiting") await this.#waiting(sync, over);\n }\n #synced(next) {\n const { waits: _, ...rest } = next;\n this.cells.set(["sync"], { ...rest, moved: this.stamp.time });\n }\n async #asking(sync, over) {\n const repo = this.#repo() ?? {};\n const tag = _RepoLobe.#text(sync["tag"]) ? { tag: sync["tag"] } : {};\n const piece = typeof sync["piece"] === "number" ? { piece: sync["piece"] } : {};\n const asked = await this.ask(over, "give", { since: repo["head"] ?? null, ...tag, ...piece });\n if ("error" in asked) return this.#failedOr(sync, "give", asked.error);\n const { pieces, head, scope } = _RepoLobe.#fields(asked.result) ? asked.result : {};\n if (typeof pieces !== "number") return this.#heardOf(sync);\n if (Array.isArray(scope) && !this.#holdsScope()) {\n if (!_RepoLobe.#text(repo["head"]) && !_RepoLobe.#text(repo["rebuilds"])) {\n const standing = (await this.#held()).find((one) => one.placeholder === sync["on"]);\n const noted = standing === void 0 ? null : await this.#noted(standing.far, { scope: _RepoLobe.#texts(scope) });\n if (noted !== null) return this.#finish(sync, 1, `the scope was not noted: ${noted}`);\n this.cells.set(["repo"], { ...repo, cut: true });\n } else\n return this.#finish(sync, 1, "a scope is held from a lobe’s birth alone, and this lobe holds the repo whole");\n }\n if (pieces === 0) return this.#finish(sync, 0, "");\n this.#synced({ ...sync, stage: "getting", at: 0, pieces, theirs: head ?? null });\n return void 0;\n }\n async #getting(sync, over) {\n const { at, pieces } = sync;\n if (typeof at !== "number" || typeof pieces !== "number") return;\n const asked = await this.ask(over, "piece", { at });\n if ("error" in asked) return this.#failedOr(sync, "piece", asked.error);\n const bytes = _RepoLobe.#arg(asked.result, "bytes");\n if (!(bytes instanceof Uint8Array)) return;\n const put = await this.ask("repos", "put", { at, pieces, bytes, as: "pull" });\n if ("error" in put) return;\n if (at + 1 < pieces) return this.#synced({ ...sync, at: at + 1 });\n const begun = await this.#begin("bring", { as: "pull", pieces }, { sync: true }, _RepoLobe.#of(sync));\n if ("job" in begun) this.#synced({ ...sync, at: pieces, stage: "bringing" });\n else if (!_RepoLobe.#transient(begun.message)) await this.#finish(sync, 1, begun.message);\n }\n async #heading(sync, over) {\n const asked = await this.ask(over, "head", {});\n if ("error" in asked) return this.#failedOr(sync, "head", asked.error);\n const theirs = _RepoLobe.#arg(asked.result, "head") ?? null;\n this.#synced({ ...sync, stage: "headed", theirs: typeof theirs === "string" ? theirs : null });\n }\n async #bundling(sync) {\n const theirs = sync["theirs"];\n const since = typeof theirs === "string" ? theirs : null;\n const piece = typeof sync["piece"] === "number" ? { piece: sync["piece"] } : {};\n const begun = await this.#begin("bundle", { since, as: "push", ...piece }, { sync: true }, _RepoLobe.#of(sync));\n if ("job" in begun) this.#synced({ ...sync, stage: "bundling", theirs: since });\n else if (_RepoLobe.#transient(begun.message) || begun.code === "timeout") this.#heardOf(sync);\n else\n await this.#finish(\n sync,\n 1,\n since === null ? begun.message : `the lobe pushed to holds commits this one does not (${since}): pull first; the jailer said: ${begun.message}`\n );\n }\n async #backOf(sync) {\n const on = _RepoLobe.#shown(sync["on"]);\n await this.#untell(on);\n const waits = typeof sync["still"] === "number" ? sync["still"] : _RepoLobe.#still;\n const note = { repo: this.#repo()?.["name"] ?? null, standing: _RepoLobe.#teller, on };\n const invited = await this.ask("ear", "invite", { waits, lives: null, note });\n if ("error" in invited)\n return this.error(invited.error.code, `no standing back was drawn: ${invited.error.message}`);\n const invitation = _RepoLobe.#arg(invited.result, "invitation");\n return _RepoLobe.#text(invitation) ? invitation : this.error("refused", "the ear drew no invitation back");\n }\n static #transient(message) {\n return message.endsWith(" being cleared") || /^the repo runs .* already$/.test(message) || message === "the lobe keeps no repo";\n }\n async #sending(sync, over) {\n const { job, at, pieces } = sync;\n if (!_RepoLobe.#text(job) || typeof at !== "number" || typeof pieces !== "number") return;\n const sending = at === 0 && sync["tells"] === true ? await this.#drawn(sync) : sync;\n if (sending === null) return;\n const read = await this.ask("repos", "piece", { at, as: "push" });\n const bytes = "result" in read ? _RepoLobe.#arg(read.result, "bytes") : void 0;\n if (!(bytes instanceof Uint8Array)) return;\n const tells = at === 0 && _RepoLobe.#text(sending["tells"]) ? { tells: sending["tells"] } : {};\n const asked = await this.ask(over, "take", { push: job, at, pieces, bytes, ...tells });\n if ("error" in asked) return this.#failedOr(sending, "take", asked.error);\n this.#synced({ ...sending, at: at + 1, ...at + 1 === pieces ? { stage: "waiting" } : {} });\n }\n async #drawn(sync) {\n const tells = await this.#backOf(sync);\n if (typeof tells !== "string") {\n await this.#finish(sync, 1, tells.message);\n return null;\n }\n const drawn = { ...sync, tells };\n this.cells.set(["sync"], drawn);\n return drawn;\n }\n async #told(args) {\n const sync = this.cells.get(["sync"]);\n const on = _RepoLobe.#arg(this.stamp.occupant?.note ?? null, "on");\n const { job, code, err } = _RepoLobe.#fields(args) ? args : {};\n if (!_RepoLobe.#fields(sync) || sync["kind"] !== "push" || sync["stage"] !== "waiting" || sync["on"] !== on || sync["job"] !== job || typeof code !== "number" || typeof err !== "string")\n return this.error("refused", "no such push waits on its end");\n await this.#endHeard(sync, code, err, _RepoLobe.#arg(args, "check") ?? null);\n return null;\n }\n async #endHeard(sync, code, err, check) {\n await this.#finish(sync, code === 0 ? 0 : 1, code === 0 ? "" : err, check === null ? void 0 : check);\n }\n async #waiting(sync, over) {\n const asked = await this.ask(over, "taken", {});\n if ("error" in asked) return this.#failedOr(sync, "taken", asked.error);\n const { code, err, check } = _RepoLobe.#fields(asked.result) ? asked.result : {};\n if (typeof code !== "number" || typeof err !== "string") return this.#heardOf(sync);\n return this.#endHeard(sync, code, err, check ?? null);\n }\n #heardOf(sync) {\n if (sync["waits"] === void 0) return;\n const { waits: _, ...rest } = sync;\n this.cells.set(["sync"], rest);\n }\n async #failedOr(sync, method, error) {\n if (_RepoLobe.#waits.includes(error.code)) return this.#waited(method, error, sync);\n await this.#finish(sync, 1, error.message);\n }\n static #left(kind, stage) {\n if (kind === "push") return stage === "heading" || stage === "headed" ? null : "push";\n return kind === "pull" && stage === "getting" ? "pull" : null;\n }\n async #finish(sync, code, err, check) {\n await this.#finished(sync, code, err, check);\n await this.#owing();\n }\n async #finished(sync, code, err, check) {\n this.cells.delete(["sync"]);\n const { asker, job, kind } = sync;\n const left = _RepoLobe.#left(kind, sync["stage"]);\n if (left !== null) await this.#clear(left);\n const repo = this.#repo();\n const checked = check === void 0 ? {} : { check };\n const synced = { job: job ?? null, kind: kind ?? null, asker: asker ?? null, code, err, ...checked };\n if (repo !== null) this.cells.set(["repo"], { ...repo, synced });\n const out = repo !== null && _RepoLobe.#text(repo["head"]) ? `${repo["head"]}\n` : "";\n const of = sync["of"];\n const init = _RepoLobe.#text(of) ? this.cells.get(["job", of]) : void 0;\n if (_RepoLobe.#text(of) && _RepoLobe.#fields(init) && init["ended"] === null)\n return this.#closed(of, init, code, out, err, checked);\n if (!_RepoLobe.#text(asker) || asker === _RepoLobe.#owner) return;\n const told = { job: job ?? null, kind: kind ?? null, code, out, err, ...checked };\n await this.ask(asker, "done", told, void 0, { letter: { lives: _RepoLobe.#lives } });\n }\n #waited(method, error, next) {\n const kept = this.cells.get(["sync"]);\n const why = `${method}: ${error.code}: ${error.message}`;\n const since = _RepoLobe.#arg(_RepoLobe.#arg(kept, "waits"), "since");\n const waits = { why, since: typeof since === "number" ? since : this.stamp.time };\n this.cells.set(["sync"], { ...next, waits });\n }\n static #stillOn(held) {\n return `its stage ${_RepoLobe.#shown(held["stage"])}, piece ${JSON.stringify(held["at"] ?? null)} of ${JSON.stringify(held["pieces"] ?? null)}`;\n }\n static #stillEnds(held) {\n const moved = typeof held["moved"] === "number" ? held["moved"] : 0;\n return moved + (typeof held["still"] === "number" ? held["still"] : _RepoLobe.#still) + 1;\n }\n async #stood(held) {\n const moved = held["moved"];\n const span = typeof held["still"] === "number" ? held["still"] : _RepoLobe.#still;\n if (typeof moved !== "number" || this.stamp.time - moved <= span) return false;\n if (held["stage"] === "waiting" && _RepoLobe.#text(held["tells"]) && _RepoLobe.#text(held["on"])) {\n await this.#waiting(held, held["on"]);\n if (this.cells.get(["sync"]) === void 0) return true;\n }\n const why = _RepoLobe.#arg(held["waits"], "why");\n const last = _RepoLobe.#text(why) ? `; its last ask ${why}` : "";\n const still = `moved not for ${span} ms: ${_RepoLobe.#stillOn(held)}${last}`;\n await this.#finish(held, 1, `the ${_RepoLobe.#shown(held["kind"])} ${still}`);\n return true;\n }\n};\nexport {\n RepoLobe as default\n};\n';
1243
+ var REPO_SOURCE = 'import { Faculty } from "nervur:faculty";\n\nvar LETTER_LIVES = 864e5;\nvar LOBE_SHARE = 4;\nvar ITEM_SIZE = 1024;\nvar CELLS_RANGE = 1e3;\nvar ARG_LONGEST = 4096;\nvar ARGS_MOST = 64;\nvar RING_PAUSE = 1e3;\nvar TAIL = 4096;\nvar SCOPE_MOST = 16;\nvar STILL = 36e5;\nvar SPELL = 5e3;\nvar WITHIN = 36e5;\nvar MINUTE = 6e4;\n\nvar RepoLobe = class _RepoLobe extends Faculty {\n static #owner = "brain";\n static #library = "library";\n static #lives = LETTER_LIVES;\n static #every = RING_PAUSE;\n static #tail = TAIL;\n static #repoName = /^[a-z](?:[a-z0-9-]|\\.(?=[a-z0-9-])){0,63}$/;\n static #script = /^[A-Za-z0-9][A-Za-z0-9:._-]{0,63}$/;\n static #key = /^[A-Za-z_][A-Za-z0-9_]{0,63}$/;\n static #issued = /^(?=.{1,40}$)[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)*$/;\n static #spell = SPELL;\n static #issuerWithin = WITHIN;\n static #minute = MINUTE;\n static #argsMost = ARGS_MOST;\n static #argLongest = ARG_LONGEST;\n static #hash = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/;\n static #digest = /^[0-9a-f]{64}$/;\n static #version = /^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)$/;\n static #label = /^[a-z][a-z0-9]*(?:[.-][a-z0-9]+)*$/;\n static #id = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;\n static #tag = /^v(?:0|[1-9][0-9]*)\\.(?:0|[1-9][0-9]*)\\.(?:0|[1-9][0-9]*)$/;\n static #hashed = /^d ([0-9a-f]{64}) ((?:designs|faculties)\\/[^/]+)\\/(.+)$/;\n static #standings = ["reader", "writer", "library", "runner"];\n static #segment = /^[A-Za-z0-9._-]+$/;\n static #scopeMost = SCOPE_MOST;\n static #entry = /^(?!\\.{1,2}$)(?!\\.git$)[^/\\\\\\0]+$/i;\n static #lobe = "lobe";\n static #teller = "teller";\n static #tells = "tells";\n static #hears = "library";\n static #waits = ["timeout", "unavailable", "busy"];\n static #still = STILL;\n static #lifted = Math.floor(Number.MAX_SAFE_INTEGER / 2);\n static #onCommit = ["off", "on", "mandatory"];\n static #onPush = ["off", "on"];\n static #moves = ["init", "land", "commit"];\n static #writes = ["owner", "near"];\n static #offers = ["owner", "near", "library"];\n static #runs = ["owner", "near", "runner"];\n static #pulls = ["reader", "pusher"];\n static #who = {\n init: ["owner"],\n accept: ["owner"],\n relink: ["owner"],\n invite: ["owner"],\n drop: ["owner"],\n occupants: ["owner"],\n migrate: ["owner"],\n gate: ["owner"],\n gates: ["owner"],\n conform: ["owner"],\n author: ["owner"],\n remove: ["owner"],\n rebuild: ["owner"],\n state: ["owner", "near", "library"],\n jobs: _RepoLobe.#runs,\n job: _RepoLobe.#runs,\n pull: _RepoLobe.#writes,\n push: _RepoLobe.#writes,\n build: _RepoLobe.#writes,\n commit: _RepoLobe.#writes,\n status: _RepoLobe.#writes,\n log: _RepoLobe.#writes,\n discard: ["owner"],\n read: _RepoLobe.#writes,\n list: _RepoLobe.#writes,\n run: _RepoLobe.#runs,\n setToken: ["owner"],\n credential: ["owner"],\n stop: _RepoLobe.#writes,\n faculties: _RepoLobe.#offers,\n organs: _RepoLobe.#offers,\n designs: _RepoLobe.#offers,\n get: _RepoLobe.#offers,\n told: _RepoLobe.#offers,\n head: _RepoLobe.#pulls,\n give: _RepoLobe.#pulls,\n piece: _RepoLobe.#pulls,\n take: ["pusher"],\n taken: ["pusher"],\n done: ["jailer", "teller"]\n };\n static #some = { type: "string", minLength: 1 };\n static #maybe = { anyOf: [{ type: "string", minLength: 1 }, { type: "null" }] };\n static #place = { type: "integer", minimum: 0 };\n static #one = { type: "integer", minimum: 1 };\n static #span = { anyOf: [{ type: "integer", minimum: 0 }, { type: "null" }] };\n static #plain = { type: "string" };\n static #none = { type: "object", additionalProperties: false };\n static #named = { type: "string", pattern: "^[a-z][a-z0-9.-]{0,63}$" };\n static #fixed = { type: "string", maxLength: 64, pattern: "^[a-z][a-z0-9]*(-[a-z0-9]+)*$" };\n static #jobSchema = {\n type: "object",\n properties: { job: _RepoLobe.#some },\n required: ["job"],\n additionalProperties: false\n };\n static #object(properties, required = Object.keys(properties)) {\n return { type: "object", properties, required, additionalProperties: false };\n }\n static #over(properties, required = Object.keys(properties)) {\n return _RepoLobe.#object({ ...properties, name: _RepoLobe.#named }, required);\n }\n static #says = {\n init: "An owner: with `starter` true, the repo `name` born and its first commit the repo lobe\'s one small starter, a step of the same job; else the repo `name` born empty and ready in the folder the jailer grants, which holds nothing: it holds no commit, may give invitations, and what it begins with is laid by the first commit of its owner or the first push of the lobe that stands on it, whole, each checked as any. Never born again, since a folder holding a repo refuses it. With `standing` true: handed in place the repo the granted folder holds already, a lobe torn down having kept it, ready on its head and tags as they stand once its `main` passes the two checks, its `conform` as `main` holds it, which it chooses, nothing laid or moved, refused where no repo stands there. An init that failed may be asked again.",\n accept: "An owner: the repo `name` laid again from the lobe an invitation names, as a lost lobe is: made empty, standing on that lobe, and pulled whole from it, the pull a step of its one job, which ends on the pull’s code and check once it landed and was scanned. The mouth keeps `note` beside the standing the organism holds, the owner’s, else `{ repo, on }`, the repo and the placeholder it stands on by; it never travels. A lobe born of a scoped lobe notes the scope on that standing, and keeps that its bytes are cut beside its head.",\n relink: "An owner: stands on the lobe of the repo an invitation names, beside those it stands on, under a placeholder of its own, which it answers: `placeholder`, a name this lobe holds for nothing else; else, with `instead`, the name of the standing it replaces; else the next free `lobe-<n>`. With `instead`, the lobe it stood on under that placeholder is asked to `drop` this one\'s standing, and the relation ends: once the new one stands, or first where the new one takes its name, since a placeholder has one wire. The mouth keeps `note` beside the standing, the owner\'s, else `{ repo, on }`. Refused to a lobe born of a scope, which stands on no other.",\n setToken: "An owner: the key `name`, any environment variable\'s name, of this lobe, set to `value`, or removed where `value` is null; kept in this lobe\'s cells, never answered, masked in all it tells, and in `.env` from the next run.",\n credential: "An owner: takes the credential of an issuer\'s standing the organism holds, as the key `secret`. With `invitation`, the organism accepts it, the mouth keeping `note`, the owner\'s, beside the standing; with `placeholder`, a placeholder of this lobe an owner wired to a standing the organism holds already, refused where it reaches no standing or one this lobe keeps another key over. Either way this lobe writes its own note on the standing, `{ credential: secret }`, asks the issuer `credential`, again at the `ready` it answers while it makes it, and a few seconds on while it is silent, for as long as `within` names in milliseconds: the cap where it names none, and never more, an hour or an owner’s word over `within`, read in its nerves as it begins, a span past it refused; then failing, saying why, and keeps its `value`, masked and never answered; where it `expires`, it is asked again before then, by a tenth of its life, a renewal that fails keeping the value, asked again at half what is left and never within a minute, and told in `state`; answers `{ secret }`, with `pending` while the issuer makes it. Asked again with its `secret` alone it asks the issuer for a fresh one.",\n invite: "An owner: an invitation for one far organism, a `reader`, a `writer` or a `library`, kept by the ear for `waits` and its relation for `lives`, reached down a line to the address `through` where one is named. This lobe’s own note on the occupant, kept by the brain, is the owner’s `note`, if any, and `{ repo, standing }`, the repo and the kind of standing its far holds, and `scope` where one is named; this lobe reads the kind and the scope back from the stamp of each ask of that far, and keeps no cell of them; the note never travels with the invitation. A reader’s or a writer’s `scope`, 1 to 16 folders of the repo, each of names of letters, digits, `.`, `_` and `-`, none `.`, `..` nor `.git`, none inside another, kept sorted in that note and never in the invitation, so the standing reaches those folders alone; a library’s is refused, and a lobe born of a scope gives no occupant, for life.",\n drop: "An owner: ends the far organism `far`\'s relation and its standing, or this lobe\'s standing on the lobe it holds as `on`. A holder ends its own standing by its mouth\'s `drop`.",\n occupants: "An owner: each occupant of this lobe, its far organism and its role, a reader, a writer, a library or a runner, with its scope where it holds one, read from this lobe’s notes through its `nerves`.",\n left: "The brain\'s: an end this lobe gave or is granted ended, `far` with its `note`; whatever this lobe kept by that far, its pull and push pieces, forgotten; a pull or a push over a standing it was granted that ended ends. The repo\'s files and history stay as they stand.",\n migrate: "The brain, at a move to this version: each wired lobe whose wire back is gone, torn down, forgotten, its lines, where it held any, taken out at the next job’s end; a pull or a push standing is rung again: a fresh `chain` kept in it and its `tick` set by a letter, the old chain dying at its next ring; and a scan of the repo owed, so every tag’s files are kept before a version told is asked: begun where the repo has a head and runs nothing, no job and no pull or push, else at the first instant it does, found by a job’s end or a pull’s or a push’s or by an alarm of its own, and owed until a scan ends whole.",\n remove: "An owner: forgets the repo, once no far standing holds it and nothing runs; its bytes stay in the folder, for the jailer’s owner.",\n rebuild: "An owner, after a move or a restore: the repo made again empty, its head unanswered until it holds the head it kept, pulled whole from a lobe it stands on, a step of its one job, which ends once that pull ended, else pushed whole by one that stands on it, that push in once the head is proven.",\n state: "The repo: its name, head, whether it is ready, not where its folder holds no repo, `absent` then saying so and that `rebuild` fills it again, the job going, how its last pull or push ended, the lobes it stands on, how many far writers push to it, its folder on the host, its wired lobes, its gate and its settings, the commit whose `conform` its owner chose, and its author, the ends read from its `nerves`; `scopes`, each scoped occupant and its scope, and `scoped`, each lobe it stands on by a scope and that scope, where there are any; `cut`, each kind of part the last scan listed past one read’s most and how many it left unlisted, where it cut any; to the library, its name alone.",\n gate: "An owner: the script of the repo\'s package the gate runs, or null for none; `gate` where none was set.",\n gates: "An owner: the settings of the gate, `commit` and `push`, each only where named, answering both. On commit, `on` by default: a commit first runs the gate, with the repo’s `.env`, and is refused, with the gate’s tail, where it is red; `off` commits at once; `mandatory` is `on` and no commit skips it. On push, `off` by default: `on` runs the gate after the two checks on each push this lobe takes, and a red gate refuses it.",\n conform: "An owner: with `take` true, the repo’s `conform` as `main` holds it now chosen, the one that judges each commit, push and pull from then on, whoever changed it; with `take` false, none, what enters guarded by the check of the parts alone; answering the commit whose conform is chosen, or null. A commit of this lobe’s own that changes it chooses it too, and an `init` standing on a repo in place; nothing a writer pushes or a pull brings does.",\n author: "An owner: beside a lobe far writers push to, the one wired lobe whose commit it takes, as the spec’s wired lobe files a proposal, or null for none; no other commits there, an owner neither.",\n commit: "An owner\'s or a wired lobe\'s: `files`, each a path under the repo and its text, `executable` naming those of them that land executable, written first, then, where its setting on commit says so, the gate, with the repo\'s `.env`; then, in its own job, refused while a secret file stands that git would take, the check of the parts, handed what the latest tag told of each `versions.json` (a version told changed is refused), and the repo\'s `conform` as its owner chose it, none where it chose none, each over what it would commit laid out apart as a clone would hold it, so a file `.gitignore` keeps out counts as absent, and its root `package.json` `version` read against `HEAD`\'s, refused where it changed and is not three whole numbers, is lower by semver, or its tag stands already; then every change committed on `main` with `message`, tagged `v<version>` in the same job where it raised the version, a lobe holding a scope tagging none, its head taken and `main` scanned, the job\'s last step (`job`). `gate` false skips the gate, refused where the setting is `mandatory`; `gate` true asks it once where the setting is `off`. A red gate or a broken rule refuses it, saying why, and every file it wrote is put back as it was before the ask (removed where it stood not, its old text written where it did), in the same job, the refusal saying so; a commit without `files` is its owner\'s, of what the folder holds, and puts nothing back. With `paths`, each a file or a folder of the repo, no `files` beside them, it takes the changes of those paths alone, added, changed or removed, and leaves the rest of the folder as it stands; the gate still runs on the folder as it stands, the checks over `main` as the commit would leave it, and `paths` that hold no change refuse it, committing nothing. Beside a lobe far writers push to, its author\'s alone.",\n status: "A job: `git status` of the folder.",\n log: "A job: the last commits, `most` of them, twenty where none is named.",\n discard: "An owner: a job undoing every change since the last commit.",\n read: "A file\'s text, its first lines where `first` names how many, and how many lines it holds; or `paths` (one or more) alone, many files in one answer, as many as a quarter of what the jailer\'s lobe holds takes, `{ files }`, each `{ path, text }` or `{ path, absent: true }` in the order named, read in one ask of the jailer; the whole refused, saying why, where a path climbs or hides, a text is no UTF-8 or the texts weigh past what one answer carries.",\n list: "The names in a folder of the repo, its top where no path is named.",\n run: "A job, an owner\'s, a wired lobe\'s or a runner\'s, a runner\'s among the scripts its invitation names alone: the script `script` of the repo\'s `package.json` with `args`, each one argument after `--`, never read by a shell, with this lobe\'s keys, `.env` written whole first where it keeps any or wrote it before, its values masked in its output; a script without its key fails by its own words. With `install`, `npm ci` first where a lockfile stands, in the same job. Its end is told back by a letter to a wired lobe; an owner and a runner read it by `job`.",\n stop: "The asker\'s pull or push standing, an owner\'s any, ended failed, saying it was stopped, its job of the jailer\'s ending by itself unheeded, refused while it lands; else the asker\'s job going stopped through the jailer, an owner\'s any; one the shell runs no more ends at once, failed.",\n jobs: "The asker\'s jobs of this lobe\'s own, a build, an init, an owner\'s every one, each with `began`, the stamp time it began, and how it ended, `{ run, code, at }`, `at` the stamp time it ended, or null while it runs. Of each asker the lobe keeps every job that runs and its newest ended, as many as one read holds; a step of another\'s work is forgotten once it moved that work on. A page, `{ jobs, cursor }`, `cursor` null at the list\'s end, else handed back to read on.",\n job: "One of the asker\'s jobs, `job`, whole, with `began` and `ended.at`, the stamp times it began and ended; an owner reads any, and one not the asker\'s is absent. A job that moved `main` ends once its last step, the scan of `main`, ended, the repo then running nothing, `ended.scan` the scan\'s `code` and the tail of why it failed, `err`, which fails no work.",\n pull: "A job: the commits of the lobe it stands on as `on`, the one it stands on where it names none, after its own HEAD, as a bundle in pieces over the relation, each of the bytes `piece` names, Quo\'s box where it names none, brought apart, checked by this lobe\'s two checks, the check of the parts and `conform` as its owner chose it, never as what came holds it, then brought into `main`, merged where it must, with the tags `v*` of the commits it brings, laid once `main` moved; a conflict, a rule broken or a tag this lobe holds on another commit refuses it, saying which. With `tag`, `v` and three whole numbers, `main` is brought up to the commit that tag names and no further, refused where the lobe pulled from holds no such tag, and nothing brought where `main` holds that commit already; a lobe holding a scope pulls by a tag too, the lobe pulled from cutting `main` to the scope up to that commit, and the tag’s name never enters the scoped lobe. `still` names how long it may stand still, in milliseconds, nothing taken and no stage moved, before it ends failed: the cap where it names none, and never more, an hour or an owner’s word over `still`.",\n push: "A job: its commits after the HEAD of the lobe it stands on as `on`, the one it stands on where it names none, sent in pieces, which that lobe checks by its own rules and brings into its `main`, or refuses, saying why; it carries the tags `v*` of the commits it sends, which that lobe lays once its `main` moved, or refuses the whole where it holds one on another commit; once its last piece is in it asks that lobe its end, `taken`, each ring, and ends with what it heard. With `tells`, the asker’s word that this organism can be dialed, its first piece gives that lobe a standing back, drawn fresh, the one before ended, over which that lobe tells its end, `done`, so the push asks nothing once its last piece is in and ends with what it was told. `piece` names the bytes of each piece, Quo’s box where it names none, what one lobe holds bounding it on either side. `still` names how long it may stand still, in milliseconds, nothing taken and no stage moved, before it ends failed: the cap where it names none, and never more, an hour or an owner’s word over `still`.",\n faculties: "Each faculty `main` holds, its label, version and digest, and its assets where its `assets/` holds any, each `[path, SHA-256]`, or why it is not told; absent where `faculties/` is not.",\n organs: "Each organ `main` holds, its ID, version and digests, or why it is not told; absent where `organs/` is not.",\n designs: "Each design `main` holds, its name, version and the digests of its data and its look, or why it is not told, a design told as its look, the faculty `<name>.look` with its assets; absent where `designs/` is not.",\n get: "A faculty\'s `{ source, digest }`, with `assets` where its `assets/` holds any, each `[path, SHA-256]`, its evidence among them; an organ\'s `{ blueprint, half }`; or a design\'s look, the faculty `<name>.look` at the design\'s version, once built, `{ source, digest, assets }`, its assets the design\'s data; at a version told, its bytes checked, and served as told whatever `main` holds after, its assets read from what the jailer kept of every tag by SHA-256, `absent` where a scan keeps them not yet, saying whether it is being kept, a scan running, or waits, a scan owed that begins once the repo runs nothing; with `path`, an asset of a faculty or a look `{ path, digest, bytes }`, its canonical bytes whole, whose SHA-256 is `digest`; with `version` null, a faculty or an organ as the folder holds it, to an owner or a writer alone.",\n build: "A job building the organ `organ`\'s host half at a version told, keeping the built half\'s digest; or the design `design`\'s look, by the repo\'s script `design`, keeping its source where it is the look `versions.json` told; either refused while `main` holds not that version, as the last scan found it.",\n told: "The versions the repo told, each with its digests; a version is told once a commit tagged `v<version>` holds it, and a scan of a head no tag names tells none. A far library may name `tells`, the invitation to a standing back on it, taken under `library-<far>`, the one before ended, over which this lobe tells it each version it tells after, `changed`, by an ask; it ends with that library’s standing. A page, `{ told, cursor }`, of the versions from the first told, the newest last, `cursor` null at the list’s end, else handed back to read on.",\n head: "A far reader or writer: this lobe\'s HEAD, null while it rebuilds, and null to a scoped one, which pushes its scope whole.",\n give: "A far reader or writer: the commits after `since`, as a bundle in pieces once it is made, each of the bytes `piece` names, Quo’s box where it names none, with the tags `v*` naming commits among them; until then, not ready. With `tag`, `v` and three whole numbers, up to the commit that tag names and no further, refused where this lobe holds no such tag, and none where `since` holds that commit already; to a scoped one, `main` is cut to its scope up to the commit that tag names, which is the beginning of the cut to the head, and the bundle holds that cut’s commits after `since`, never a tag. A bundle that failed is refused once, then made again. To a scoped one, `main` is cut to its scope first, the same every time, and the bundle holds the cut’s commits after `since`, read against the cut, nothing of `main` outside the scope, no tag; its answer carries `scope`, which the lobe that pulls keeps, and from then gives no occupant.",\n piece: "A far reader or writer: the bundle\'s piece `at`.",\n take: "A far writer: the piece `at` of `pieces` of the push its writer names `push`, in order. The first may name `tells`, the invitation of the standing back its writer gives, which this lobe accepts under `tells-<far>`, the one it held of that writer before ended; once the push is in `main` or refused, a writer that gave one is told `done { job, kind, code, out, err, check }` over it by an ask, once. The same piece of the same push sent again, the same bytes, is answered as it was; a push named anew, from its first piece, is a new one, brought and checked anew by the rules as they stand, whatever came before; any other piece is refused as out of order. The last has this lobe bring it apart and check it by its two checks, and its gate where its setting on push is `on`; the tags it carries brought apart, the whole refused where one names no commit it brings or this lobe holds a tag of that name on another commit, and laid once `main` moved. A scoped writer\'s is grafted first, its tags not taken: refused unless it is linear on the scope\'s head as `main` is cut now, else as behind, and where a commit changes a path outside the scope; each commit grafted on `main`\'s tip, its tree `main`\'s with the scope\'s paths taken from it, its author, committer, times and message kept, and what `main` would become checked whole.",\n taken: "A far writer: the end of its last push, `{ job, kind, code, out, err, check }`, as `done` tells it, or `{ ready: false }` until it is in `main` or refused, with `waits`, what it waits on, where its last piece is in and the repo runs another job first: that job checked with the jailer, so one whose end was lost holds it not, and the push brought once the repo runs nothing. A scoped writer hears the head it pushed and its check\'s code alone.",\n renew: "The scheduler\'s alone: each credential waited on whose time came asked again, each due to be renewed renewed.",\n keep: "The scheduler\'s alone: a scan owed begins where the repo has a head and runs nothing, by the `chain` its alarm carries, the one the lobe keeps; where the repo runs a job, the jailer is asked of it first, so a job whose end was lost ends; answers `{ again }`, a minute on, while the scan is owed, begun or not, and null once it is no more owed; a ring of any other chain answers null and writes nothing.",\n tick: "The scheduler\'s alone: a pull or a push takes its next step, by the `chain` its alarm carries, the one the sync keeps; a tick of any other chain, or where no sync stands, answers null at once and writes nothing; each ring making one far ask at most, within the time the ring is given: a push\'s piece read through the jailer and taken, a pull\'s got and put through the jailer, one piece a ring; a ring that moved the work rings the next at once, as a job of the jailer ending does; one waiting on a job of the jailer is rung at once by that job\'s end or its loss, told at the shell\'s `back`, and meanwhile a minute on, each ring checking the job with the jailer, so one whose end was lost holds it not; one whose far answered not yet a second on; a push whose last piece is in asks its end, `taken`, a second on each ring, or, where it gave a standing back, asks nothing, since the lobe it went to tells its end, and rings again only to end it once it stood still for as long as it may; an ask timed out, unavailable or busy is asked again at the next ring, kept as `waits { why, since }`, any other far error ends it; one that moved not for as long as it may stand still, `still`, nothing taken and no stage changed, ends failed, naming what stood still, as data.",\n done: "The jailer\'s, a job ended; or, the lobe a push went to, over the standing back that push gave it: the push ended, `{ job, kind, code, out, err, check }`, landed with code 0 and the HEAD it left, or refused, saying why in `err`, and the push this lobe waits on ends with it. To a scoped writer, the head it pushed and its check’s code alone, a refusal telling that its check is red and no more."\n };\n static #reading(method, args) {\n const description = _RepoLobe.#says[method] ?? method;\n const typed = args === void 0 ? {} : { args };\n return { description, kind: "reading", ...typed, errors: ["refused", "absent"] };\n }\n static #writing(method, args) {\n return { ..._RepoLobe.#reading(method, args), kind: "writing" };\n }\n static #own = _RepoLobe.#over({}, []);\n static #which = _RepoLobe.#over(\n {\n kind: { enum: ["faculty", "organ"] },\n label: _RepoLobe.#some,\n version: _RepoLobe.#maybe,\n path: _RepoLobe.#some\n },\n ["kind", "label", "version"]\n );\n static #stillFor = { type: "integer", minimum: 1 };\n static #syncing = _RepoLobe.#over(\n { on: _RepoLobe.#some, piece: _RepoLobe.#one, still: _RepoLobe.#stillFor, tells: { const: true } },\n []\n );\n static #ringing = _RepoLobe.#over({ chain: _RepoLobe.#some }, ["chain"]);\n static #pulling = _RepoLobe.#over(\n { on: _RepoLobe.#some, tag: _RepoLobe.#some, piece: _RepoLobe.#one, still: _RepoLobe.#stillFor },\n []\n );\n static blueprint = {\n name: "nervur.repo",\n version: "0.2.68",\n description: "A repo lobe: one for each repo on each organism that holds it, its bytes kept by the jailer, `repos`, through which it reaches them alone. It keeps what the repo is there: its head; its gate and its settings; its wired lobes; and the versions of its faculties, organs and designs it told the library, `changed`, never told again with other bytes. A repo is born one of two ways: by its `init`, empty, filled by the first commit of its owner or a first push whole; or by its `accept` of an invitation, pulled whole. It commits, at an owner’s ask or a wired lobe’s, its gate first where its settings say; it guards its own `main` before anything enters it, a commit, a push, a pull, by Nervur’s check of the parts, which it holds, and the repo’s `conform` as its owner chose it, each over that tree checked out apart; it serves its wired lobes, each work a job, its end told back, and composes each secret file from their sets, keeping which names each holds by digest, never a value; it pulls and pushes, serves its readers, writers and libraries, and holds no secret. The lobes of the repo it stands on, any number, and its far standings, readers, writers and libraries, are the brain’s, each with this lobe’s own note: it keeps no record of them.",\n methods: {\n init: _RepoLobe.#writing(\n "init",\n _RepoLobe.#object({ name: _RepoLobe.#named, standing: { const: true }, starter: { const: true } }, ["name"])\n ),\n accept: _RepoLobe.#writing(\n "accept",\n _RepoLobe.#object({ name: _RepoLobe.#named, invitation: _RepoLobe.#some, note: {} }, ["name", "invitation"])\n ),\n relink: _RepoLobe.#writing(\n "relink",\n _RepoLobe.#object(\n { invitation: _RepoLobe.#some, instead: _RepoLobe.#some, placeholder: _RepoLobe.#fixed, note: {} },\n ["invitation"]\n )\n ),\n invite: _RepoLobe.#writing(\n "invite",\n _RepoLobe.#object(\n {\n standing: { enum: _RepoLobe.#standings },\n waits: _RepoLobe.#span,\n lives: _RepoLobe.#span,\n note: {},\n through: _RepoLobe.#some,\n scope: { type: "array", items: _RepoLobe.#some, minItems: 1, maxItems: SCOPE_MOST },\n scripts: { type: "array", items: _RepoLobe.#some, minItems: 1 }\n },\n ["standing"]\n )\n ),\n drop: {\n ..._RepoLobe.#writing("drop", _RepoLobe.#object({ far: _RepoLobe.#some, on: _RepoLobe.#some }, [])),\n irreversible: true\n },\n occupants: _RepoLobe.#reading("occupants"),\n left: _RepoLobe.#writing("left", _RepoLobe.#object({ far: _RepoLobe.#some, note: {} }, ["far"])),\n migrate: _RepoLobe.#writing("migrate"),\n remove: { ..._RepoLobe.#writing("remove", _RepoLobe.#own), irreversible: true },\n rebuild: _RepoLobe.#writing("rebuild", _RepoLobe.#own),\n state: _RepoLobe.#reading("state", _RepoLobe.#own),\n gate: _RepoLobe.#writing("gate", _RepoLobe.#object({ script: _RepoLobe.#maybe })),\n gates: _RepoLobe.#writing(\n "gates",\n _RepoLobe.#object({ commit: { enum: _RepoLobe.#onCommit }, push: { enum: _RepoLobe.#onPush } }, [])\n ),\n conform: _RepoLobe.#writing("conform", _RepoLobe.#object({ take: { type: "boolean" } })),\n author: _RepoLobe.#writing("author", _RepoLobe.#object({ lobe: _RepoLobe.#maybe })),\n commit: _RepoLobe.#writing(\n "commit",\n _RepoLobe.#object(\n {\n message: _RepoLobe.#some,\n files: { type: "object", additionalProperties: _RepoLobe.#plain },\n executable: { type: "array", items: _RepoLobe.#some },\n paths: { type: "array", items: _RepoLobe.#some, minItems: 1 },\n gate: { type: "boolean" }\n },\n ["message"]\n )\n ),\n status: _RepoLobe.#writing("status", _RepoLobe.#none),\n log: _RepoLobe.#writing("log", _RepoLobe.#object({ most: { type: "integer", minimum: 1 } }, [])),\n discard: { ..._RepoLobe.#writing("discard", _RepoLobe.#none), irreversible: true },\n read: _RepoLobe.#reading(\n "read",\n _RepoLobe.#object(\n {\n path: _RepoLobe.#some,\n first: _RepoLobe.#one,\n paths: { type: "array", items: _RepoLobe.#some, minItems: 1 }\n },\n []\n )\n ),\n list: _RepoLobe.#reading("list", _RepoLobe.#object({ path: _RepoLobe.#plain }, [])),\n run: _RepoLobe.#writing(\n "run",\n _RepoLobe.#object(\n {\n script: _RepoLobe.#some,\n args: { type: "array", items: _RepoLobe.#plain, maxItems: ARGS_MOST },\n install: { type: "boolean" }\n },\n ["script"]\n )\n ),\n setToken: _RepoLobe.#writing("setToken", _RepoLobe.#object({ name: _RepoLobe.#some, value: _RepoLobe.#maybe })),\n credential: _RepoLobe.#writing(\n "credential",\n _RepoLobe.#object(\n {\n invitation: _RepoLobe.#some,\n placeholder: _RepoLobe.#some,\n secret: _RepoLobe.#some,\n note: {},\n within: { type: "integer", minimum: 1 }\n },\n ["secret"]\n )\n ),\n stop: _RepoLobe.#writing("stop", _RepoLobe.#none),\n jobs: _RepoLobe.#reading("jobs", _RepoLobe.#object({ cursor: _RepoLobe.#maybe }, [])),\n job: _RepoLobe.#reading("job", _RepoLobe.#jobSchema),\n pull: _RepoLobe.#writing("pull", _RepoLobe.#pulling),\n push: _RepoLobe.#writing("push", _RepoLobe.#syncing),\n faculties: _RepoLobe.#reading("faculties"),\n organs: _RepoLobe.#reading("organs"),\n designs: _RepoLobe.#reading("designs"),\n get: _RepoLobe.#reading("get", _RepoLobe.#which),\n build: _RepoLobe.#writing(\n "build",\n _RepoLobe.#over({ organ: _RepoLobe.#some, design: _RepoLobe.#some, version: _RepoLobe.#some }, ["version"])\n ),\n told: _RepoLobe.#writing(\n "told",\n _RepoLobe.#object({ tells: { type: "string", minLength: 1 }, cursor: _RepoLobe.#maybe }, [])\n ),\n head: _RepoLobe.#reading("head"),\n give: _RepoLobe.#writing(\n "give",\n _RepoLobe.#object({ since: _RepoLobe.#maybe, tag: _RepoLobe.#some, piece: _RepoLobe.#one }, ["since"])\n ),\n piece: _RepoLobe.#reading("piece", _RepoLobe.#object({ at: _RepoLobe.#place })),\n take: _RepoLobe.#writing(\n "take",\n _RepoLobe.#object(\n { push: _RepoLobe.#some, at: _RepoLobe.#place, pieces: _RepoLobe.#one, bytes: {}, tells: _RepoLobe.#some },\n ["push", "at", "pieces", "bytes"]\n )\n ),\n taken: _RepoLobe.#writing("taken", _RepoLobe.#none),\n tick: { ..._RepoLobe.#writing("tick", _RepoLobe.#ringing), askers: ["scheduler"] },\n keep: { ..._RepoLobe.#writing("keep", _RepoLobe.#ringing), askers: ["scheduler"] },\n renew: { ..._RepoLobe.#writing("renew"), askers: ["scheduler"] },\n done: _RepoLobe.#writing("done")\n },\n placeholders: {\n repos: "nervur.repos",\n ear: "nervur.ear",\n mouth: "nervur.mouth",\n scheduler: "nervur.scheduler",\n library: "nervur.library"\n }\n };\n static parts = `// SPDX-License-Identifier: FSL-1.1-ALv2\nimport { createHash } from \'node:crypto\';\nimport { existsSync, lstatSync, readFileSync, readdirSync } from \'node:fs\';\nimport { join, resolve } from \'node:path\';\n\nconst root = resolve(process.argv[2] ?? \'.\');\nconst LABEL = /^[a-z][a-z0-9]*(?:[.-][a-z0-9]+)*$/;\nconst ID = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;\nconst VERSION = /^(?:0|[1-9][0-9]*)\\\\.(?:0|[1-9][0-9]*)\\\\.(?:0|[1-9][0-9]*)$/;\nconst broken = [];\nconst say = (why) => {\n broken.push(why);\n};\nconst isFolder = (path) => existsSync(path) && lstatSync(path).isDirectory();\nconst isFile = (path) => existsSync(path) && lstatSync(path).isFile();\nconst fieldsAt = (path) => {\n try {\n const read = JSON.parse(readFileSync(path, \'utf8\'));\n return read !== null && typeof read === \'object\' && !Array.isArray(read) ? read : null;\n } catch {\n return null;\n }\n};\n\nconst partsOf = (convention, pattern, what, by) => {\n const at = join(root, convention);\n if (!existsSync(at)) return [];\n if (!isFolder(at)) {\n say(convention + \' is no folder: it holds a folder for each \' + what);\n return [];\n }\n return readdirSync(at)\n .filter((name) => !name.startsWith(\'.\'))\n .toSorted()\n .flatMap((name) => {\n if (!isFolder(join(at, name))) {\n say(convention + \'/\' + name + \' is no folder: \' + convention + \'/ holds a folder for each \' + what);\n return [];\n }\n if (!pattern.test(name)) {\n say(convention + \'/\' + name + \' is no \' + what + "\'s name: a " + what + \' is named by \' + by);\n return [];\n }\n return [name];\n });\n};\n\nconst sha = (bytes) => createHash(\'sha256\').update(bytes).digest(\'hex\');\nconst canonical = (bytes) =>\n bytes.includes(0) ? bytes : Buffer.from(bytes.toString(\'latin1\').replace(/\\\\r\\\\n?/g, \'\\\\n\'), \'latin1\');\nconst assetsOf = (at, below = \'\') =>\n readdirSync(join(at, below), { withFileTypes: true })\n .filter((entry) => !entry.name.startsWith(\'.\'))\n .flatMap((entry) => {\n const path = below === \'\' ? entry.name : below + \'/\' + entry.name;\n if (entry.isDirectory()) return assetsOf(at, path);\n return entry.isFile() ? [[path, sha(canonical(readFileSync(join(at, path))))]] : [];\n })\n .toSorted((one, other) => (one[0] < other[0] ? -1 : 1));\n\nfor (const label of partsOf(\'faculties\', LABEL, \'faculty\', \'its label, in lowercase\')) {\n const at = \'faculties/\' + label;\n const path = join(root, at, \'faculty.js\');\n if (!isFile(path)) {\n say(at + \' holds no faculty.js: a faculty is one module of JavaScript\');\n continue;\n }\n const bytes = readFileSync(path);\n const text = bytes.toString(\'utf8\');\n const named =\n /\\\\b([A-Za-z_$][\\\\w$]*)\\\\s*=\\\\s*class(?:\\\\s+[A-Za-z_$][\\\\w$]*)?\\\\s+extends\\\\s+Faculty\\\\b/.exec(text) ??\n /\\\\bclass\\\\s+([A-Za-z_$][\\\\w$]*)\\\\s+extends\\\\s+Faculty\\\\b/.exec(text);\n const exported =\n /\\\\bexport\\\\s+default\\\\s+class\\\\b[^{]*\\\\bextends\\\\s+Faculty\\\\b/.test(text) ||\n (named !== null &&\n (new RegExp(\'\\\\\\\\bexport\\\\\\\\s+default\\\\\\\\s+\' + named[1] + \'\\\\\\\\b\').test(text) ||\n new RegExp(\'\\\\\\\\bexport\\\\\\\\s*\\\\\\\\{\\\\\\\\s*\' + named[1] + \'\\\\\\\\s+as\\\\\\\\s+default\\\\\\\\s*\\\\\\\\}\').test(text)));\n if (!/\\\\bimport\\\\s*\\\\{[^}]*\\\\bFaculty\\\\b[^}]*\\\\}\\\\s*from\\\\s*[\'"]nervur:faculty[\'"]/.test(text) || !exported)\n say(at + \'/faculty.js exports as its default no class extending Faculty from nervur:faculty\');\n const from = text.search(/\\\\bstatic\\\\s+blueprint\\\\s*=/);\n const blueprint = from < 0 ? \'\' : text.slice(from);\n const name = /\\\\bname\\\\s*:\\\\s*[\'"]([^\'"\\\\n]+)[\'"]/.exec(blueprint)?.[1];\n const version = /\\\\bversion\\\\s*:\\\\s*[\'"]([^\'"\\\\n]+)[\'"]/.exec(blueprint)?.[1];\n if (name === undefined || version === undefined || !VERSION.test(version)) {\n say(at + \'/faculty.js holds no blueprint naming its name and its version\');\n continue;\n }\n const versions = fieldsAt(join(root, at, \'versions.json\'));\n const digest = createHash(\'sha256\').update(bytes).digest(\'hex\');\n if (versions === null) say(at + \' holds no versions.json naming each version by its digest\');\n else if (versions[version] !== digest) say(at + \'/faculty.js is not the text its versions.json names at \' + version);\n const digested = /\\\\bassets\\\\s*:\\\\s*[\'"]([0-9a-f]{64})[\'"]/.exec(blueprint)?.[1];\n const held = isFolder(join(root, at, \'assets\')) ? assetsOf(join(root, at, \'assets\')) : [];\n if (digested === undefined && held.length > 0)\n say(at + \'/assets holds files its blueprint names no assets digest for\');\n else if (digested !== undefined && sha(JSON.stringify(held)) !== digested)\n say(at + \'/assets is not the digest its blueprint names as assets, \' + digested);\n}\n\nfor (const id of partsOf(\'organs\', ID, \'organ\', \'its fixed ID, in lowercase\')) {\n const at = \'organs/\' + id;\n const graph = fieldsAt(join(root, at, \'graph.json\'));\n const version = graph === null ? undefined : (graph.version ?? graph.blueprint?.version);\n if (graph === null || typeof version !== \'string\' || !VERSION.test(version))\n say(at + \' holds no graph.json, its blueprint with its version\');\n if (!isFile(join(root, at, \'host/build\'))) say(at + \' holds no host/build, which builds its host half\');\n}\n\nconst sheetsIn = (at, below = \'\') =>\n readdirSync(join(at, below), { withFileTypes: true }).flatMap((entry) => {\n const path = below === \'\' ? entry.name : below + \'/\' + entry.name;\n if (entry.isDirectory()) return sheetsIn(at, path);\n return path === \'layers.json\' ? [] : [path];\n });\n\nfor (const name of partsOf(\'designs\', LABEL, \'design\', \'its name, in lowercase\')) {\n const at = \'designs/\' + name;\n const design = fieldsAt(join(root, at, \'design.json\'));\n if (design === null || design.name !== name || typeof design.version !== \'string\' || !VERSION.test(design.version))\n say(at + \' holds no design.json naming it and its version\');\n const tokens = {};\n for (const file of [\'light\', \'dark\', \'tints\']) {\n tokens[file] = fieldsAt(join(root, at, \'tokens\', file + \'.json\'));\n if (tokens[file] === null) say(at + \' holds no tokens/\' + file + \'.json\');\n }\n if (design !== null) {\n const where = at + \'/design.json\';\n if (typeof design.publisher !== \'string\' || design.publisher === \'\') say(where + \' names no publisher\');\n const themes = Array.isArray(design.themes) ? design.themes : [];\n if (!themes.includes(\'light\') || !themes.includes(\'dark\')) say(where + \' names no themes light and dark\');\n if (!Array.isArray(design.tints)) say(where + \' names its tints as no list\');\n else if (tokens.tints !== null)\n for (const tint of design.tints)\n if (typeof tint !== \'string\' || !Object.hasOwn(tokens.tints, tint))\n say(where + \' names the tint \' + String(tint) + \', which tokens/tints.json holds not\');\n }\n const layers = fieldsAt(join(root, at, \'skin/layers.json\'));\n if (layers === null) say(at + \' holds no skin/layers.json\');\n else {\n const where = at + \'/skin/layers.json\';\n const named = [];\n for (const layer of [\'lobes\', \'home\']) {\n const sheets = Array.isArray(layers[layer]) ? layers[layer] : [];\n for (const sheet of sheets) {\n if (typeof sheet !== \'string\' || sheet === \'\') say(where + \' names a sheet that is no name in \' + layer);\n else if (named.includes(sheet)) say(where + \' names \' + sheet + \' more than once\');\n else if (!isFile(join(root, at, \'skin\', sheet))) say(where + \' names \' + sheet + \', which skin/ holds not\');\n named.push(sheet);\n }\n }\n for (const sheet of sheetsIn(join(root, at, \'skin\')).toSorted())\n if (!named.includes(sheet)) say(at + \'/skin/\' + sheet + \' is named by no layer of skin/layers.json\');\n }\n if (isFolder(join(root, at, \'fonts\'))) {\n const where = at + \'/fonts/fonts.json\';\n const manifest = fieldsAt(join(root, where));\n const faces = manifest !== null && Array.isArray(manifest.faces) ? manifest.faces : null;\n if (faces === null) say(at + \' holds no fonts/fonts.json naming its faces\');\n else\n for (const face of faces) {\n const file = face !== null && typeof face === \'object\' ? face.file : undefined;\n const licence = face !== null && typeof face === \'object\' ? face.licence : undefined;\n if (typeof file !== \'string\' || file === \'\') say(where + \' names a face with no file\');\n else {\n if (!isFile(join(root, at, \'fonts\', file))) say(where + \' names \' + file + \', which fonts/ holds not\');\n if (typeof licence !== \'string\' || licence === \'\')\n say(where + \' names the face \' + file + \' with no licence\');\n }\n if (typeof licence === \'string\' && licence !== \'\' && !isFile(join(root, at, \'fonts\', licence)))\n say(where + \' names the licence \' + licence + \', which fonts/ holds not\');\n }\n }\n if (fieldsAt(join(root, at, \'versions.json\')) === null) say(at + \' holds no versions.json\');\n}\n\nconst sorted = (value) =>\n value !== null && typeof value === \'object\' && !Array.isArray(value)\n ? Object.fromEntries(\n Object.keys(value)\n .toSorted()\n .map((key) => [key, sorted(value[key])]),\n )\n : value;\nconst same = (one, other) => JSON.stringify(sorted(one)) === JSON.stringify(sorted(other));\nconst told = process.argv[3] === undefined ? null : fieldsAt(resolve(process.argv[3]));\nif (told !== null)\n for (const path of Object.keys(told).toSorted()) {\n if (!/^(?:faculties|designs)\\\\/[^/]+\\\\/versions\\\\.json$/.test(path) || typeof told[path] !== \'string\') continue;\n let was = null;\n try {\n was = JSON.parse(told[path]);\n } catch {}\n if (was === null || typeof was !== \'object\' || Array.isArray(was)) continue;\n if (!isFolder(join(root, path, \'..\'))) continue;\n const now = fieldsAt(join(root, path));\n for (const version of Object.keys(was).toSorted())\n if (now === null || !Object.hasOwn(now, version) || !same(now[version], was[version]))\n say(path + \' no longer holds \' + version + \' as the tag told it\');\n }\n\nconst rootManifest = fieldsAt(join(root, \'package.json\'));\nfor (const field of [\'dependencies\', \'devDependencies\', \'peerDependencies\', \'optionalDependencies\']) {\n const held = rootManifest?.[field];\n if (held !== null && typeof held === \'object\' && \'@nervur.org/genome\' in held)\n say(\n \'package.json names @nervur.org/genome in \' +\n field +\n \': the organism lends the genome it runs, a repo names none\',\n );\n}\n\nif (existsSync(join(root, \'.env\')))\n say(\'.env would enter main: .gitignore keeps it not out, and a secret file is never committed\');\n\nif (broken.length > 0) {\n console.log(broken.join(\'\\\\n\'));\n process.exit(1);\n}\nconsole.log(\'parts: each part stands as its folder says\');\n`;\n static #order(a, b) {\n return a < b ? -1 : a > b ? 1 : 0;\n }\n static #fields(data) {\n return !!data && typeof data === "object" && !Array.isArray(data) && !ArrayBuffer.isView(data);\n }\n static #text(data) {\n return typeof data === "string" && data !== "";\n }\n static #texts(data) {\n return Array.isArray(data) ? data.flatMap((one) => _RepoLobe.#text(one) ? [one] : []) : [];\n }\n static #arg(args, key) {\n return _RepoLobe.#fields(args) ? args[key] : void 0;\n }\n static #shown(data) {\n return typeof data === "string" ? data : "none";\n }\n static #lastLine(text) {\n return text.trim().split("\\n").pop() ?? "";\n }\n static #headOf(out) {\n const last = _RepoLobe.#lastLine(out);\n return _RepoLobe.#hash.test(last) ? last : null;\n }\n static #lone = /[\\uD800-\\uDBFF](?![\\uDC00-\\uDFFF])|(?<![\\uD800-\\uDBFF])[\\uDC00-\\uDFFF]/g;\n #bytes(text) {\n const encoded = this.codec.utf8(text.replace(_RepoLobe.#lone, "�"));\n return "bytes" in encoded ? encoded.bytes : null;\n }\n static #json(text) {\n try {\n const read = JSON.parse(text);\n return _RepoLobe.#fields(read) ? read : null;\n } catch {\n return null;\n }\n }\n static #holds(read, placeholder) {\n const all = "result" in read && Array.isArray(read.result) ? read.result : [];\n return all.some((one) => _RepoLobe.#fields(one) && one["placeholder"] === placeholder);\n }\n static #wiredTo(read, placeholder) {\n const all = "result" in read && Array.isArray(read.result) ? read.result : [];\n const wire = all.find((one) => _RepoLobe.#fields(one) && one["placeholder"] === placeholder);\n return _RepoLobe.#fields(wire) ? wire["termination"] ?? null : null;\n }\n #alarm(args) {\n return this.ask("scheduler", "set", args, void 0, { letter: { lives: _RepoLobe.#lives } });\n }\n #heard(answer) {\n return "error" in answer ? this.error(answer.error.code, answer.error.message) : null;\n }\n #result(answer) {\n return "error" in answer ? this.error(answer.error.code, answer.error.message) : answer.result;\n }\n #digestOf(text) {\n const bytes = this.#bytes(text);\n return bytes === null ? "" : this.#shaOf(bytes);\n }\n #shaOf(bytes) {\n const hash = this.crypto.sha256(bytes);\n return hash instanceof Uint8Array ? Array.from(hash, (byte) => byte.toString(16).padStart(2, "0")).join("") : "";\n }\n static #canonical(bytes) {\n if (bytes.includes(0)) return bytes;\n const out = new Uint8Array(bytes.length);\n let length = 0;\n for (let at = 0; at < bytes.length; at += 1) {\n const byte = bytes[at] ?? 0;\n out[length] = byte === 13 ? 10 : byte;\n length += 1;\n if (byte === 13 && bytes[at + 1] === 10) at += 1;\n }\n return out.subarray(0, length);\n }\n #nonce() {\n return Array.from(this.stamp.seed.slice(0, 6), (byte) => byte.toString(16).padStart(2, "0")).join("");\n }\n #most() {\n return Math.min(CELLS_RANGE, Math.floor(this.memory / LOBE_SHARE / ITEM_SIZE));\n }\n #all(prefix) {\n return this.cells.range({ prefix: [...prefix], limit: this.#most() }).cells;\n }\n static #relation(data) {\n if (!_RepoLobe.#fields(data)) return null;\n const { far, side, placeholder, note } = data;\n if (!_RepoLobe.#text(far) || side !== "occupant" && side !== "standing") return null;\n return { far, side, placeholder: _RepoLobe.#text(placeholder) ? placeholder : null, note: note ?? null };\n }\n async #relations() {\n const all = [];\n let cursor = null;\n for (const seen = new Set(); ; ) {\n const read = await this.ask("nerves", "relations", cursor === null ? {} : { cursor });\n const result = "result" in read ? read.result : null;\n const found = _RepoLobe.#arg(result, "relations");\n for (const one of Array.isArray(found) ? found : []) {\n const relation = _RepoLobe.#relation(one);\n if (relation !== null) all.push(relation);\n }\n const next = _RepoLobe.#arg(result, "cursor");\n if (!_RepoLobe.#text(next) || seen.has(next)) break;\n seen.add(next);\n cursor = next;\n }\n return all;\n }\n async #endOfFar(far) {\n const read = await this.ask("nerves", "relation", { far });\n return "result" in read ? _RepoLobe.#relation(read.result) : null;\n }\n async #held() {\n const all = await this.#relations();\n return all.filter((one) => one.side === "standing" && !_RepoLobe.#tellsOn(one)).toSorted((a, b) => _RepoLobe.#order(a.placeholder ?? "", b.placeholder ?? ""));\n }\n async #given() {\n return (await this.#relations()).filter(\n (one) => one.side === "occupant" && _RepoLobe.#kindOf(one.note) !== _RepoLobe.#teller\n );\n }\n static #backUnder(prefix, far) {\n return `${prefix}-${far.toLowerCase()}`;\n }\n static #tellsOn(one) {\n return _RepoLobe.#text(_RepoLobe.#arg(one.note, "credential")) || [_RepoLobe.#tells, _RepoLobe.#hears].some((prefix) => one.placeholder?.startsWith(`${prefix}-`) === true);\n }\n async #untell(on) {\n for (const one of await this.#relations())\n if (one.side === "occupant" && _RepoLobe.#kindOf(one.note) === _RepoLobe.#teller && _RepoLobe.#arg(one.note, "on") === on)\n await this.ask("ear", "drop", { far: one.far });\n }\n static #kindOf(note) {\n const kind = _RepoLobe.#arg(note, "standing");\n return typeof kind === "string" && (_RepoLobe.#standings.includes(kind) || kind === _RepoLobe.#teller) ? kind : null;\n }\n static #scopeIn(note) {\n const scope = _RepoLobe.#arg(note, "scope");\n return Array.isArray(scope) ? _RepoLobe.#texts(scope) : null;\n }\n async #noted(far, note) {\n const wrote = await this.ask("nerves", "note", { far, note });\n return "error" in wrote ? wrote.error.message : null;\n }\n #repo() {\n const repo = this.cells.get(["repo"]);\n return _RepoLobe.#fields(repo) ? repo : null;\n }\n #role() {\n const { asker } = this.stamp;\n if (asker === _RepoLobe.#owner) return "owner";\n if (asker === _RepoLobe.#library) return "library";\n const occupant = this.stamp.occupant;\n if (occupant !== null && occupant.far === asker) {\n const kind = _RepoLobe.#arg(occupant.note, "standing");\n if (kind === "writer") return "pusher";\n if (kind === _RepoLobe.#teller) return "teller";\n if (kind === "reader" || kind === "library" || kind === "runner") return kind;\n return "stood";\n }\n const repo = this.#repo();\n if (repo !== null && repo["jailer"] === asker) return "jailer";\n return "near";\n }\n #refusal(method, args) {\n if (!(_RepoLobe.#who[method] ?? []).includes(this.#role()))\n return this.error("refused", `${method} is not the asker\'s to ask`);\n const repo = this.#repo();\n const named = _RepoLobe.#arg(args, "name");\n if (repo !== null && named !== void 0 && !["init", "accept"].includes(method) && named !== repo["name"])\n return this.error(\n "refused",\n `this lobe keeps the repo ${_RepoLobe.#shown(repo["name"])}, not ${_RepoLobe.#shown(named)}`\n );\n return null;\n }\n #ready() {\n const repo = this.#repo();\n if (repo === null || repo["ready"] !== true || !_RepoLobe.#text(repo["name"]))\n return this.error("refused", "the repo is not ready");\n return { name: repo["name"], repo };\n }\n async #jailer() {\n const jailer = _RepoLobe.#wiredTo(await this.nerves.read(), "repos");\n return _RepoLobe.#text(jailer) ? jailer : this.error("refused", "the lobe is wired to no repos");\n }\n #unmade(name) {\n if (!_RepoLobe.#text(name) || !_RepoLobe.#repoName.test(name))\n return this.error("refused", "a repo is named in lowercase, a letter first");\n const repo = this.#repo();\n const failed = repo !== null && repo["ready"] !== true && repo["head"] === null && repo["rebuilds"] === null && !_RepoLobe.#text(repo["doing"]) && _RepoLobe.#text(repo["failed"]);\n if (repo !== null && !failed)\n return this.error("refused", `the lobe keeps the repo ${_RepoLobe.#shown(repo["name"])} already`);\n return name;\n }\n static #fresh(name, jailer) {\n return {\n name,\n head: null,\n ready: false,\n failed: null,\n doing: null,\n synced: null,\n jailer,\n rebuilds: null\n };\n }\n async init(args) {\n const refused = this.#refusal("init", args);\n if (refused !== null) return refused;\n const name = this.#unmade(_RepoLobe.#arg(args, "name"));\n if (typeof name !== "string") return name;\n const unchecked = this.checked("init", args);\n if (unchecked !== void 0) return unchecked;\n const standing = _RepoLobe.#arg(args, "standing") === true;\n const starter = _RepoLobe.#arg(args, "starter") === true;\n if (standing && starter)\n return this.error("refused", "a repo handed in place keeps what it holds, and takes no starter");\n const jailer = await this.#jailer();\n if (typeof jailer !== "string") return jailer;\n this.cells.set(["repo"], _RepoLobe.#fresh(name, jailer));\n if (standing) return this.#begin("init", this.#checks(), null, { method: "stand" });\n return this.#begin("init", {}, null, starter ? { more: { starter: true } } : {});\n }\n #starterOf(name) {\n const version = "0.1.0";\n const label = `com.example.${name}`;\n const source = `import { Faculty } from \'nervur:faculty\';\n\nexport default class extends Faculty {\n static blueprint = { name: \'${label}\', version: \'${version}\', placeholders: {}, methods: { hello: { kind: \'reading\' } } };\n hello() { return \'hello from ${name}\'; }\n}\n`;\n const conform = `// This repo\'s own rules, run over what would enter its main. A rule broken prints why and exits 1.\nconsole.log(\'conform: no rule of this repo is broken\');\n`;\n const scripts = { gate: "node tools/conform.mjs", conform: "node tools/conform.mjs" };\n return {\n ".gitignore": ".env\\nnode_modules/\\ndist/\\n",\n "package.json": `${JSON.stringify({ name, version, private: true, scripts }, null, 2)}\n`,\n "tools/conform.mjs": conform,\n [`faculties/${label}/faculty.js`]: source,\n [`faculties/${label}/versions.json`]: `${JSON.stringify({ [version]: this.#digestOf(source) }, null, 2)}\n`\n };\n }\n async #layStarter(run, asker) {\n const name = _RepoLobe.#shown(this.#repo()?.["name"]);\n for (const [path, text] of Object.entries(this.#starterOf(name))) {\n const wrote = await this.ask("repos", "write", { path, text });\n if ("error" in wrote) return `${path}: ${wrote.error.message}`;\n }\n const begun = await this.#begin(\n "commit",\n { message: "the starter", ...this.#checks() },\n { commit: run },\n { asker }\n );\n return "job" in begun ? null : begun.message;\n }\n async #link(invitation, placeholder, name, note) {\n if (!_RepoLobe.#text(invitation)) return this.error("refused", "an invitation is named");\n const held = note === void 0 ? { repo: name ?? null, on: placeholder } : note;\n const accepted = await this.ask("mouth", "accept", { invitation, placeholder, note: held });\n if ("error" in accepted) return this.error(accepted.error.code, accepted.error.message);\n const far = _RepoLobe.#arg(accepted.result, "far");\n if (!_RepoLobe.#text(far)) return this.error("refused", "the mouth named no far organism");\n return { placeholder, far };\n }\n async #free() {\n const held = new Set((await this.#held()).map((one) => one.placeholder));\n let at = 1;\n while (held.has(`${_RepoLobe.#lobe}-${at}`)) at += 1;\n return `${_RepoLobe.#lobe}-${at}`;\n }\n async #standingOn(on) {\n const all = await this.#held();\n if (on !== void 0) {\n const one = all.find((held) => held.placeholder === on);\n return one === void 0 || one.placeholder === null ? this.error("absent", `this lobe stands on no lobe as ${_RepoLobe.#shown(on)}`) : { placeholder: one.placeholder, far: one.far };\n }\n const [only] = all;\n if (only === void 0 || only.placeholder === null)\n return this.error("refused", "this lobe stands on no other: relink it");\n if (all.length > 1) return this.error("refused", "this lobe stands on several: name the one, `on`");\n return { placeholder: only.placeholder, far: only.far };\n }\n async accept(args) {\n const refused = this.#refusal("accept", args);\n if (refused !== null) return refused;\n const name = this.#unmade(_RepoLobe.#arg(args, "name"));\n if (typeof name !== "string") return name;\n const jailer = await this.#jailer();\n if (typeof jailer !== "string") return jailer;\n const placeholder = await this.#free();\n const linked = await this.#link(_RepoLobe.#arg(args, "invitation"), placeholder, name, _RepoLobe.#arg(args, "note"));\n if (!("far" in linked)) return linked;\n this.cells.set(["repo"], _RepoLobe.#fresh(name, jailer));\n return this.#begin("init", {}, null, { more: { pulls: placeholder } });\n }\n async relink(args) {\n const refused = this.#refusal("relink", args);\n if (refused !== null) return refused;\n if (this.#holdsScope()) return this.error("refused", "a lobe born of a scope stands on no other");\n if (this.cells.get(["sync"]) !== void 0)\n return this.error("refused", "the repo pulls or pushes: wait for it to end");\n const instead = _RepoLobe.#arg(args, "instead");\n const was = instead === void 0 ? null : await this.#standingOn(instead);\n if (was !== null && !("far" in was)) return was;\n const replaced = was === null ? null : was["placeholder"];\n const named = _RepoLobe.#arg(args, "placeholder");\n if (typeof named === "string" && named !== replaced && _RepoLobe.#holds(await this.nerves.read(), named))\n return this.error("refused", `this lobe holds ${named} already`);\n const placeholder = typeof named === "string" ? named : _RepoLobe.#text(replaced) ? replaced : await this.#free();\n const taken = was !== null && placeholder === replaced;\n if (taken) await this.#unlink(was);\n const name = this.#repo()?.["name"];\n const linked = await this.#link(_RepoLobe.#arg(args, "invitation"), placeholder, name, _RepoLobe.#arg(args, "note"));\n if (!("far" in linked)) return linked;\n if (was !== null && !taken) await this.#unlink(was);\n return { on: placeholder, far: linked["far"] ?? null };\n }\n async #unlink(was) {\n const placeholder = was["placeholder"];\n if (!_RepoLobe.#text(placeholder)) return;\n if (!placeholder.startsWith(`${_RepoLobe.#tells}-`)) await this.#untell(placeholder);\n if (_RepoLobe.#text(was["far"])) await this.ask("mouth", "drop", { far: was["far"] });\n await this.nerves.unwire(placeholder);\n }\n async invite(args) {\n const refused = this.#refusal("invite", args);\n if (refused !== null) return refused;\n const ready = this.#ready();\n if (!("name" in ready)) return ready;\n if (this.#holdsScope()) return this.error("refused", "a lobe holding a scope gives no occupant");\n const standing = _RepoLobe.#arg(args, "standing");\n if (typeof standing !== "string" || !_RepoLobe.#standings.includes(standing))\n return this.error("refused", "a standing is a reader, a writer, a library or a runner");\n const scripts = _RepoLobe.#arg(args, "scripts");\n const named = Array.isArray(scripts) ? scripts : [];\n if (standing === "runner" && (named.length === 0 || !named.every((one) => _RepoLobe.#text(one) && _RepoLobe.#script.test(one))))\n return this.error("refused", "a runner runs scripts of the repo\'s package, one or more");\n if (standing !== "runner" && scripts !== void 0)\n return this.error("refused", "scripts are a runner’s alone");\n const asked = _RepoLobe.#arg(args, "scope");\n const scope = asked === void 0 ? null : _RepoLobe.#scopeOf(asked);\n if (asked !== void 0 && (standing === "library" || standing === "runner"))\n return this.error("refused", `a ${standing}\'s standing is never scoped`);\n if (asked !== void 0 && scope === null)\n return this.error(\n "refused",\n `a scope is 1 to ${_RepoLobe.#scopeMost} folders of the repo, each of names of letters, digits, ., _ and -, none ., .. nor .git, none inside another`\n );\n const waits = _RepoLobe.#arg(args, "waits") ?? null;\n const lives = _RepoLobe.#arg(args, "lives") ?? null;\n const owned = _RepoLobe.#arg(args, "note");\n const base = owned === void 0 || owned === null ? {} : _RepoLobe.#fields(owned) ? owned : { note: owned };\n const note = {\n ...base,\n repo: ready.name,\n standing,\n ...scope === null ? {} : { scope },\n ...standing === "runner" ? { scripts: named } : {}\n };\n const through = _RepoLobe.#arg(args, "through");\n const line = through === void 0 ? {} : { through };\n const invited = await this.ask("ear", "invite", { waits, lives, note, ...line });\n if ("error" in invited) return this.#heard(invited);\n const far = _RepoLobe.#arg(invited.result, "far");\n if (!_RepoLobe.#text(far)) return this.error("refused", "the ear named no far organism");\n return invited.result;\n }\n static #scopeOf(scope) {\n if (!Array.isArray(scope) || scope.length < 1 || scope.length > _RepoLobe.#scopeMost) return null;\n const folders = scope.flatMap((one) => typeof one === "string" ? [one] : []);\n const fit = (one) => one.split("/").every((name) => _RepoLobe.#segment.test(name) && ![".", "..", ".git"].includes(name));\n if (folders.length !== scope.length || !folders.every(fit)) return null;\n const sorted = folders.toSorted();\n const nested = sorted.some(\n (one, at) => sorted.some((other, by) => by !== at && (one === other || one.startsWith(`${other}/`)))\n );\n return nested ? null : sorted;\n }\n #scopeOfAsker() {\n const occupant = this.stamp.occupant;\n return occupant === null ? null : _RepoLobe.#scopeIn(occupant.note);\n }\n async #scopeFor(far) {\n if (this.stamp.occupant?.far === far) return this.#scopeOfAsker();\n const found = await this.#endOfFar(far);\n return found === null ? null : _RepoLobe.#scopeIn(found.note);\n }\n #holdsScope() {\n return this.#repo()?.["cut"] === true;\n }\n async drop(args) {\n const refused = this.#refusal("drop", args);\n if (refused !== null) return refused;\n const [named, on] = [_RepoLobe.#arg(args, "far"), _RepoLobe.#arg(args, "on")];\n if (on !== void 0) {\n const held = await this.#standingOn(on);\n if (!("far" in held)) return held;\n if (_RepoLobe.#arg(this.cells.get(["sync"]), "on") === on)\n return this.error("refused", "the repo pulls or pushes over it: wait for it to end");\n await this.#unlink(held);\n return null;\n }\n const secret = _RepoLobe.#arg(args, "secret");\n if (secret !== void 0) {\n const issued = (await this.#credentials()).find((one) => one.secret === secret);\n if (issued === void 0) return this.error("absent", "no credential is kept by that secret");\n return this.#forgo(issued);\n }\n const far = named;\n const given = _RepoLobe.#text(far) ? await this.#endOfFar(far) : null;\n if (!_RepoLobe.#text(far) || given === null || given.side !== "occupant")\n return this.error("absent", "no standing is held by that far organism");\n const dropped = await this.ask("ear", "drop", { far });\n if ("error" in dropped) return this.#heard(dropped);\n await this.#forgetFar(far, given.note);\n return null;\n }\n async left(args) {\n const far = _RepoLobe.#arg(args, "far");\n if (_RepoLobe.#text(far)) await this.#forgetFar(far, _RepoLobe.#arg(args, "note") ?? null);\n if (_RepoLobe.#text(far)) {\n this.cells.delete(["token", far]);\n this.cells.delete(["credential", far]);\n }\n const on = _RepoLobe.#arg(_RepoLobe.#arg(args, "note"), "on");\n if (_RepoLobe.#text(on) && !(await this.#held()).some((one) => one.placeholder === on)) await this.#untell(on);\n const sync = this.cells.get(["sync"]);\n if (_RepoLobe.#fields(sync) && !(await this.#held()).some((one) => one.placeholder === sync["on"]))\n await this.#finish(sync, 1, "the lobe stands on that lobe no more");\n return null;\n }\n async #forgetFar(far, note) {\n if (_RepoLobe.#kindOf(note) === "writer") await this.#untold(far);\n if (_RepoLobe.#kindOf(note) === "library") await this.#untold(far, _RepoLobe.#hears);\n for (const kept of ["out", "in"]) {\n if (this.cells.get([kept, far]) === void 0) continue;\n this.cells.delete([kept, far]);\n await this.#clear(`${kept}-${far}`);\n }\n }\n async occupants(args) {\n const refused = this.#refusal("occupants", args);\n if (refused !== null) return refused;\n return (await this.#given()).map(({ far, note }) => {\n const scope = _RepoLobe.#scopeIn(note);\n return { far, role: _RepoLobe.#kindOf(note), ...scope === null ? {} : { scope } };\n });\n }\n async migrate(args) {\n const refused = this.#refusal("migrate", args);\n if (refused !== null) return refused;\n const rearmed = await this.#rearm();\n this.#bridged();\n if (this.#repo() !== null) {\n this.cells.set(["owed"], true);\n await this.#owing();\n await this.#awaiting();\n }\n return rearmed;\n }\n #bridged() {\n const walk = (prefix, each) => {\n let cursor = null;\n do {\n const page = this.cells.range({\n prefix: [prefix],\n limit: this.#most(),\n ...cursor === null ? {} : { cursor }\n });\n for (const cell of page.cells) each(cell);\n ({ cursor } = page);\n } while (cursor !== null);\n };\n walk("job", ({ key, value }) => {\n if (!_RepoLobe.#fields(value) || value["ended"] === null || value["ended"] === void 0) return;\n this.cells.delete([...key]);\n if (_RepoLobe.#text(value["asker"]) && _RepoLobe.#text(key[1])) this.cells.delete(["by", value["asker"], key[1]]);\n });\n if (this.cells.get(["toldNext"]) !== void 0) return;\n const told = [];\n walk("told", ({ key, value }) => {\n const named = key.slice(1).map((part) => typeof part === "string" ? part : "");\n told.push({ at: Number(_RepoLobe.#arg(value, "at") ?? 0), named });\n });\n const order = (one, other) => one.at - other.at || (one.named.join("\\0") < other.named.join("\\0") ? -1 : 1);\n for (const { named } of told.toSorted(order)) this.#toldInOrder(named);\n }\n async #owing() {\n if (this.cells.get(["owed"]) !== true) return;\n const repo = this.#repo();\n const idle = !_RepoLobe.#text(repo?.["doing"]) && !_RepoLobe.#fields(this.cells.get(["sync"]));\n if (_RepoLobe.#text(repo?.["head"]) && idle && "name" in this.#ready())\n await this.#begin("scan", {}, { scan: null }, { asker: _RepoLobe.#owner });\n }\n async #awaiting() {\n if (this.cells.get(["owed"]) !== true || this.cells.get(["owes"]) !== void 0) return;\n const chain = this.#nonce();\n const set = await this.#alarm({ at: this.stamp.time + MINUTE, method: "keep", args: { chain } });\n if (!("error" in set)) this.cells.set(["owes"], chain);\n }\n async keep(args) {\n const owes = this.cells.get(["owes"]);\n if (typeof owes !== "string" || owes !== _RepoLobe.#arg(args, "chain")) return null;\n await this.#check();\n await this.#owing();\n if (this.cells.get(["owed"]) === true) return { again: this.stamp.time + MINUTE };\n this.cells.delete(["owes"]);\n return null;\n }\n #scanning() {\n const doing = this.#repo()?.["doing"];\n return _RepoLobe.#text(doing) && _RepoLobe.#arg(this.cells.get(["job", doing]), "kind") === "scan";\n }\n async #rearm() {\n const sync = this.cells.get(["sync"]);\n if (!_RepoLobe.#fields(sync)) return null;\n const chain = this.#nonce();\n this.cells.set(["sync"], { ...sync, chain });\n const set = await this.#alarm({ at: this.stamp.time + _RepoLobe.#every, method: "tick", args: { chain } });\n return "error" in set ? this.error(set.error.code, set.error.message) : null;\n }\n gate(args) {\n const refused = this.#refusal("gate", args);\n if (refused !== null) return refused;\n const script = _RepoLobe.#arg(args, "script");\n if (script !== null && !(_RepoLobe.#text(script) && _RepoLobe.#script.test(script)))\n return this.error("refused", "a gate is a script of the repo\'s package, or null");\n this.cells.set(["gate"], script ?? null);\n return null;\n }\n #gateScript() {\n const held = this.cells.get(["gate"]);\n return held === void 0 ? "gate" : held;\n }\n #gates() {\n const held = this.cells.get(["gates"]);\n const [commit, push] = [_RepoLobe.#arg(held, "commit"), _RepoLobe.#arg(held, "push")];\n return {\n commit: typeof commit === "string" && _RepoLobe.#onCommit.includes(commit) ? commit : "on",\n push: push === "on" ? "on" : "off"\n };\n }\n gates(args) {\n const refused = this.#refusal("gates", args);\n if (refused !== null) return refused;\n const [commit, push] = [_RepoLobe.#arg(args, "commit"), _RepoLobe.#arg(args, "push")];\n if (commit !== void 0 && !(typeof commit === "string" && _RepoLobe.#onCommit.includes(commit)))\n return this.error("refused", "on commit, the gate is off, on or mandatory");\n if (push !== void 0 && !(typeof push === "string" && _RepoLobe.#onPush.includes(push)))\n return this.error("refused", "on push, the gate is off or on");\n const now = this.#gates();\n const set = {\n commit: typeof commit === "string" ? commit : now.commit,\n push: typeof push === "string" ? push : now.push\n };\n this.cells.set(["gates"], set);\n return set;\n }\n conform(args) {\n const refused = this.#refusal("conform", args);\n if (refused !== null) return refused;\n const take = _RepoLobe.#arg(args, "take");\n if (typeof take !== "boolean") return this.error("refused", "take is true or false");\n const ready = this.#ready();\n if (!("name" in ready)) return ready;\n if (!take) {\n this.cells.delete(["conform"]);\n return null;\n }\n const head = ready.repo["head"];\n if (!_RepoLobe.#text(head)) return this.error("refused", "main holds no commit to take its conform from");\n this.cells.set(["conform"], head);\n return head;\n }\n author(args) {\n const refused = this.#refusal("author", args);\n if (refused !== null) return refused;\n const lobe = _RepoLobe.#arg(args, "lobe");\n if (lobe === null) {\n this.cells.delete(["author"]);\n return null;\n }\n if (!_RepoLobe.#text(lobe) || lobe === _RepoLobe.#owner)\n return this.error("refused", "an author is a wired lobe, named by its ID");\n this.cells.set(["author"], lobe);\n return null;\n }\n async remove(args) {\n const refused = this.#refusal("remove", args);\n if (refused !== null) return refused;\n const repo = this.#repo();\n if (repo === null) return this.error("absent", "the lobe keeps no repo");\n if ((await this.#given()).length > 0) return this.error("refused", "far standings hold the repo: drop them first");\n if (_RepoLobe.#text(repo["doing"]) || this.cells.get(["sync"]) !== void 0)\n return this.error("refused", "the repo runs a job: wait for it to end");\n for (const kept of [\n "told",\n "built",\n "look",\n "parts",\n "job",\n "by",\n "out",\n "in",\n "back",\n "secret",\n "token",\n "credential"\n ])\n for (const { key } of this.#all([kept])) this.cells.delete(key);\n for (const kept of ["repo", "gate", "gates", "conform", "author", "scanned", "owed", "owes", "env", "renews"])\n this.cells.delete([kept]);\n return null;\n }\n async rebuild(args) {\n const refused = this.#refusal("rebuild", args);\n if (refused !== null) return refused;\n const repo = this.#repo();\n if (repo === null) return this.error("refused", "the lobe keeps no repo");\n if (_RepoLobe.#text(repo["doing"]) || this.cells.get(["sync"]) !== void 0)\n return this.error("refused", "the repo runs a job: wait for it to end");\n const rebuilds = repo["rebuilds"] ?? repo["head"] ?? null;\n this.cells.set(["repo"], { ...repo, ready: false, head: null, rebuilds });\n return this.#begin("init", {}, { rebuild: true });\n }\n async state(args) {\n const refused = this.#refusal("state", args);\n if (refused !== null) return refused;\n const repo = this.#repo();\n if (repo === null) return null;\n if (this.#role() === "library") return { name: repo["name"] ?? null };\n const held = this.#result(await this.ask("repos", "state", {}));\n const folder = _RepoLobe.#arg(held, "folder") ?? null;\n const relations = await this.#relations();\n const stood = relations.filter((one) => one.side === "standing" && !_RepoLobe.#text(_RepoLobe.#arg(one.note, "credential"))).toSorted((a, b) => _RepoLobe.#order(a.placeholder ?? "", b.placeholder ?? ""));\n const given = relations.filter((one) => one.side === "occupant");\n const on = stood.map(({ placeholder, far }) => ({ placeholder, far }));\n const writers = given.filter(({ note }) => _RepoLobe.#kindOf(note) === "writer").length;\n const author = this.cells.get(["author"]);\n const conform = this.cells.get(["conform"]);\n const sync = this.cells.get(["sync"]) ?? null;\n const syncing = _RepoLobe.#fields(sync) ? Object.fromEntries(Object.entries(sync).filter(([key]) => key !== "tells")) : sync;\n const scopes = given.flatMap(({ far, note }) => {\n const scope = _RepoLobe.#scopeIn(note);\n return scope === null ? [] : [{ far, scope }];\n });\n const scoped = stood.flatMap(({ placeholder, note }) => {\n const scope = _RepoLobe.#scopeIn(note);\n return scope === null ? [] : [{ on: placeholder, scope }];\n });\n const { cut: _, ...whole } = repo;\n const lost = repo["ready"] === true && _RepoLobe.#arg(held, "made") === false;\n return {\n ...whole,\n ...lost ? {\n ready: false,\n absent: "its folder holds no repo: a backup carries no repo\'s bytes; rebuild fills it again, pulled whole from a lobe it stands on or pushed whole by one that stands on it"\n } : {},\n on,\n writers,\n folder,\n syncing,\n gate: this.#gateScript(),\n gates: this.#gates(),\n ..._RepoLobe.#text(conform) ? { conform } : {},\n ..._RepoLobe.#text(author) ? { author } : {},\n ...scopes.length > 0 ? { scopes } : {},\n ...scoped.length > 0 ? { scoped } : {},\n ..._RepoLobe.#fields(_RepoLobe.#arg(this.cells.get(["scanned"]), "cut")) ? { cut: _RepoLobe.#arg(this.cells.get(["scanned"]), "cut") ?? null } : {},\n ...this.#role() === "library" ? {} : await this.#keysShown()\n };\n }\n async #keysShown() {\n const issued = await this.#credentials();\n const credentials = issued.map(({ secret, far }) => {\n const cell = this.cells.get(["credential", far]);\n const url = _RepoLobe.#arg(cell, "url");\n const failed = _RepoLobe.#arg(cell, "failed");\n const expires = _RepoLobe.#arg(cell, "expires");\n const renews = _RepoLobe.#arg(cell, "renews");\n return {\n secret,\n far,\n pending: _RepoLobe.#arg(cell, "pending") === true,\n ..._RepoLobe.#text(url) ? { url } : {},\n ..._RepoLobe.#text(failed) ? { failed } : {},\n ...typeof expires === "number" && typeof renews === "number" ? { expires, renews } : {}\n };\n });\n const secrets = Object.keys(await this.#keys()).toSorted();\n return { ...secrets.length > 0 ? { secrets } : {}, ...credentials.length > 0 ? { credentials } : {} };\n }\n jobs(args) {\n const refused = this.#refusal("jobs", args);\n if (refused !== null) return refused;\n const { asker } = this.stamp;\n const page = this.#page(asker === _RepoLobe.#owner ? ["job"] : ["by", asker], args);\n if (!("cells" in page)) return page;\n const held = asker === _RepoLobe.#owner ? page.cells.map(({ value }) => value) : page.cells.map(({ key }) => this.cells.get(["job", key[2] ?? ""]) ?? null);\n return { jobs: held.map((one) => _RepoLobe.#brief(one)), cursor: page.cursor };\n }\n #page(prefix, args) {\n const cursor = _RepoLobe.#arg(args, "cursor") ?? null;\n if (cursor !== null && !_RepoLobe.#text(cursor)) return this.error("refused", "a cursor is the one a page answered");\n try {\n return this.cells.range({ prefix: [...prefix], limit: this.#most(), ...cursor === null ? {} : { cursor } });\n } catch {\n return this.error("refused", "a cursor is the one a page answered");\n }\n }\n static #brief(held) {\n if (!_RepoLobe.#fields(held) || !_RepoLobe.#fields(held["ended"])) return held;\n const { run, code, at } = held["ended"];\n return { ...held, ended: { run: run ?? null, code: code ?? null, at: at ?? null } };\n }\n job(args) {\n const refused = this.#refusal("job", args);\n if (refused !== null) return refused;\n const run = _RepoLobe.#arg(args, "job");\n if (!_RepoLobe.#text(run)) return this.error("refused", "a job is named by its id");\n const { asker } = this.stamp;\n const held = this.cells.get(["job", run]);\n const owns = asker === _RepoLobe.#owner || this.cells.get(["by", asker, run]) !== void 0;\n if (owns && _RepoLobe.#fields(held)) return held;\n const sync = this.cells.get(["sync"]);\n const last = this.#repo()?.["synced"];\n for (const one of [sync, last]) {\n if (!_RepoLobe.#fields(one) || one["job"] !== run) continue;\n if (asker !== _RepoLobe.#owner && one["asker"] !== asker) break;\n const ended = one === sync ? null : { code: one["code"] ?? null, err: one["err"] ?? null };\n return { job: run, kind: one["kind"] ?? null, stage: one === sync ? one["stage"] ?? null : null, ended };\n }\n return this.error("absent", "no such job");\n }\n async #begin(kind, given, step, { more = {}, asker = this.stamp.asker, method = kind } = {}) {\n const repo = this.#repo();\n if (repo === null) return this.error("refused", "the lobe keeps no repo");\n if (!_RepoLobe.#text(repo["doing"])) await this.#unclear();\n if (_RepoLobe.#text(repo["doing"])) {\n await this.#check();\n return this.error("refused", `the repo runs ${repo["doing"]} already`);\n }\n const back = step === null && this.#role() !== "runner" ? await this.#back(asker) : null;\n if (back !== null) return back;\n const begun = await this.ask("repos", method, given);\n if ("error" in begun) return this.error(begun.error.code, begun.error.message);\n const run = _RepoLobe.#arg(begun.result, "job");\n if (!_RepoLobe.#text(run)) return this.error("refused", "the jailer named no job");\n const owing = kind === "scan" && this.cells.get(["owed"]) === true;\n const of = step === null ? {} : { step: owing ? { ...step, owed: true } : step };\n this.cells.set(["job", run], {\n job: run,\n kind,\n asker,\n repo: repo["name"] ?? null,\n ...of,\n ...more,\n began: this.stamp.time,\n ended: null\n });\n if (step === null) this.cells.set(["by", asker, run], null);\n this.cells.set(["repo"], { ...repo, doing: run });\n return { job: run };\n }\n async #back(asker) {\n if (asker === _RepoLobe.#owner || this.cells.get(["back", asker]) !== void 0) return null;\n const ordered = await this.nerves.order({ termination: asker });\n if ("error" in ordered) return this.error("refused", `no wire back: ${ordered.error.message}`);\n this.cells.set(["back", asker], true);\n return null;\n }\n async done(args) {\n if (this.#role() === "teller") return this.#told(args);\n const read = await this.nerves.read();\n if (_RepoLobe.#wiredTo(read, "repos") !== this.stamp.asker)\n return this.error("refused", "only the jailer tells a job ended");\n const { job: run, code: ended, out: said, err: wrote } = _RepoLobe.#fields(args) ? args : {};\n const whole = typeof said === "string" && typeof wrote === "string" && typeof ended === "number";\n const held = _RepoLobe.#text(run) ? this.cells.get(["job", run]) : void 0;\n if (!whole || !_RepoLobe.#text(run) || !_RepoLobe.#fields(held) || held["ended"] !== null)\n return this.error("refused", "no such job going");\n return this.#jobEnded(read, run, held, ended, said, wrote);\n }\n async #jobEnded(read, run, held, ended, said, wrote) {\n this.#torn(read);\n const [out, err] = [this.#masked(said), this.#masked(wrote)];\n if (_RepoLobe.#text(held["gating"])) return this.#gated(held, run, ended, out, err);\n if (_RepoLobe.#fields(held["running"])) return this.#writtenThen(held, run, ended, err);\n const filed = held["kind"] !== "commit" ? err : ended === 0 ? err : await this.#undone(err);\n if (held["kind"] === "commit" && ended === 0) this.cells.delete(["undo"]);\n const [code, told] = this.#halfKept(held, ended, out, filed);\n this.#settled(held, code, out, told);\n const before = this.cells.get(["sync"]);\n const more = await this.#further(run, held, code, out, told);\n if (more !== null) await this.#closed(run, held, code, out, told, more);\n await this.#rung(before);\n await this.#tellEnds();\n await this.#receiveWaiting();\n const step = held["step"];\n const tried = _RepoLobe.#fields(step) && step["owed"] === true || more !== null && more["scan"] !== void 0;\n if (!tried) await this.#owing();\n return null;\n }\n async #further(run, held, code, out, err) {\n const asker = _RepoLobe.#text(held["asker"]) ? held["asker"] : _RepoLobe.#owner;\n const pulls = held["pulls"];\n if (held["kind"] === "init" && code === 0 && _RepoLobe.#text(pulls))\n return this.#pulled(run, held, out, pulls, asker);\n if (_RepoLobe.#fields(held["step"]) && held["step"]["rebuild"] === true) {\n const first = await this.#rebuilt(code === 0 ? null : _RepoLobe.#lastLine(err) || `the job ended ${code}`);\n return _RepoLobe.#text(first) ? this.#pulled(run, held, out, first, _RepoLobe.#owner) : {};\n }\n if (held["kind"] === "init" && code === 0 && held["starter"] === true) {\n const why = await this.#layStarter(run, asker);\n return why === null ? null : { starter: why };\n }\n const moved = code === 0 && typeof held["kind"] === "string" && _RepoLobe.#moves.includes(held["kind"]);\n if (!moved || !_RepoLobe.#text(this.#repo()?.["head"])) return {};\n const begun = await this.#begin("scan", {}, { scan: run, code, out, err }, { asker });\n if ("job" in begun) return null;\n this.cells.set(["owed"], true);\n await this.#awaiting();\n return { scan: { code: 1, err: `the scan did not begin: ${begun.message}` } };\n }\n async #pulled(run, held, out, on, asker) {\n const begun = await this.#start("pull", asker, on, { of: run });\n if (_RepoLobe.#text(_RepoLobe.#arg(begun, "job"))) return null;\n await this.#closed(\n run,\n held,\n 1,\n out,\n `the pull did not begin: ${_RepoLobe.#shown(_RepoLobe.#arg(begun, "message"))}`,\n {}\n );\n return null;\n }\n async #closed(run, held, code, out, err, more) {\n this.cells.set(["job", run], { ...held, ended: { run, code, out, err, ...more, at: this.stamp.time } });\n const step = held["step"];\n if (!_RepoLobe.#fields(step)) return this.#ended(held, code, out, err, more);\n await this.#stepped(step, held, code, out, err, more);\n if (step["rebuild"] !== true) this.cells.delete(["job", run]);\n }\n async #scannedThen(step, code, err) {\n const run = step["scan"];\n const held = _RepoLobe.#text(run) ? this.cells.get(["job", run]) : void 0;\n if (!_RepoLobe.#text(run) || !_RepoLobe.#fields(held) || held["ended"] !== null) return;\n const [ended, out, said] = [step["code"], step["out"], step["err"]];\n const scan = { code, err: code === 0 ? "" : _RepoLobe.#last(err) || `the scan ended ${code}` };\n const whole = typeof ended === "number" && typeof out === "string" && typeof said === "string";\n if (whole) await this.#closed(run, held, ended, out, said, { scan });\n }\n #halfKept(held, code, out, err) {\n const built = held["built"];\n if (held["kind"] !== "build" || code !== 0 || !_RepoLobe.#fields(built)) return [code, err];\n if (_RepoLobe.#text(built["design"])) return [code, err];\n const [organ, version] = [_RepoLobe.#shown(built["organ"]), _RepoLobe.#shown(built["version"])];\n const kept = this.cells.get(["built", organ, version]);\n const digest = out.trim();\n if (typeof kept !== "string" || kept === digest) return [code, err];\n return [\n 1,\n `the host half of ${organ} ${version} was built as ${kept}, and this build gives ${digest}: a version is never told with other bytes, so raise its version`\n ];\n }\n #settled(held, code, out, err) {\n const repo = this.#repo();\n if (repo === null) return;\n const { kind } = held;\n const failed = code === 0 ? null : _RepoLobe.#lastLine(err);\n const made = kind === "init" ? { ready: code === 0, failed } : {};\n const moved = code === 0 && typeof kind === "string" && _RepoLobe.#moves.includes(kind);\n const now = moved ? _RepoLobe.#headOf(out) : null;\n const head = moved ? { head: now } : {};\n this.cells.set(["repo"], { ...repo, ...made, ...head, doing: null });\n if (now !== null && kind !== "land" && out.split("\\n").includes(`conform ${now}`)) this.cells.set(["conform"], now);\n }\n async #ended(held, code, out, err, more = {}) {\n const { asker, kind, job: run } = held;\n if (_RepoLobe.#text(asker) && _RepoLobe.#text(run) && this.cells.get(["by", asker, run]) !== void 0)\n this.#endKept(asker, run);\n const built = held["built"];\n const digest = out.trim();\n if (kind === "build" && code === 0 && _RepoLobe.#fields(built)) {\n if (_RepoLobe.#text(built["design"])) this.#looked(built, out);\n else if (_RepoLobe.#digest.test(digest))\n this.cells.set(["built", _RepoLobe.#shown(built["organ"]), _RepoLobe.#shown(built["version"])], digest);\n }\n if (!_RepoLobe.#text(asker) || this.cells.get(["back", asker]) === void 0) return;\n const told = { job: run ?? null, kind: kind ?? null, code, out, err, ...more };\n await this.ask(asker, "done", told, void 0, { letter: { lives: _RepoLobe.#lives } });\n }\n #endKept(asker, run) {\n const ends = this.cells.get(["ended", asker]);\n let first = Number(_RepoLobe.#arg(ends ?? null, "first") ?? 0);\n const next = Number(_RepoLobe.#arg(ends ?? null, "next") ?? 0);\n for (; next - first >= Math.max(1, this.#most()); first += 1) {\n const oldest = this.cells.get(["ended", asker, String(first)]);\n if (_RepoLobe.#text(oldest)) {\n this.cells.delete(["job", oldest]);\n this.cells.delete(["by", asker, oldest]);\n }\n this.cells.delete(["ended", asker, String(first)]);\n }\n this.cells.set(["ended", asker, String(next)], run);\n this.cells.set(["ended", asker], { first, next: next + 1 });\n }\n #looked(built, source) {\n const [name, version] = [_RepoLobe.#shown(built["design"]), _RepoLobe.#shown(built["version"])];\n const told = _RepoLobe.#arg(this.cells.get(["told", "faculty", `${name}.look`, version]), "digest");\n const digest = this.#digestOf(source);\n if (digest === told) {\n this.cells.set(["look", name, version], { source });\n return;\n }\n if (_RepoLobe.#text(_RepoLobe.#arg(this.cells.get(["look", name, version]), "source"))) return;\n const why = `the look built is ${digest}, not the ${_RepoLobe.#shown(told)} versions.json told`;\n this.cells.set(["look", name, version], { why });\n }\n async #stepped(step, held, code, out, err, more) {\n const why = code === 0 ? null : _RepoLobe.#lastLine(err) || `the job ended ${code}`;\n if (_RepoLobe.#text(step["commit"])) {\n await this.#commitEnded(step["commit"], code, out, err, more);\n return void 0;\n }\n if (_RepoLobe.#text(step["ran"])) {\n const kind = _RepoLobe.#text(held["kind"]) ? held["kind"] : "run";\n return this.#workEnded(step["ran"], kind, code, out, err);\n }\n if (_RepoLobe.#text(step["check"])) return this.#checked(step["check"], { code, out, err });\n if (step["scan"] !== void 0) {\n if (code === 0) await this.#scanned(out);\n if (code === 0 && step["owed"] === true) this.cells.delete(["owed"]);\n else if (step["owed"] === true) await this.#awaiting();\n return this.#scannedThen(step, code, err);\n }\n if (_RepoLobe.#text(step["for"])) return this.#served(step["for"], held["kind"], why, out);\n const sync = this.cells.get(["sync"]);\n if (step["sync"] !== true || !_RepoLobe.#fields(sync)) return;\n if (held["kind"] === "bring") return this.#broughtPull(sync, why, out);\n if (held["kind"] === "land") return this.#landed(sync, why);\n if (sync["stage"] === "proving") return this.#proven(sync, code, why, out);\n if (why !== null) return this.#finish(sync, code, why);\n const pieces = Number(out.trim().split("\\n")[0]);\n if (pieces === 0) return this.#finish(sync, 0, "");\n this.cells.set(["sync"], { ...sync, stage: "sending", at: 0, pieces });\n return void 0;\n }\n async #broughtPull(sync, why, out) {\n if (why !== null) return this.#finish(sync, 1, why);\n const [head = "", how = ""] = out.trim().split("\\n");\n if (how === "held" || !_RepoLobe.#hash.test(head)) return this.#finish(sync, 0, "");\n const check = await this.#conform("pull", head, false, _RepoLobe.#askerOf(sync));\n const checking = { ...sync, stage: "checking", theirs: head, check };\n this.cells.set(["sync"], checking);\n if ("code" in check) await this.#checkedPull(checking, check);\n return void 0;\n }\n async #checkedPull(sync, check) {\n if (check["code"] !== 0) return this.#finish(sync, 1, _RepoLobe.#refusalOf(check), check);\n const begun = await this.#begin("land", { as: "pull" }, { sync: true }, _RepoLobe.#of(sync));\n if ("job" in begun) this.cells.set(["sync"], { ...sync, stage: "landing" });\n else await this.#finish(sync, 1, begun.message, check);\n return void 0;\n }\n async #landed(sync, why) {\n const check = sync["check"] ?? null;\n if (why !== null) return this.#finish(sync, 1, why, check);\n const rebuilds = this.#repo()?.["rebuilds"];\n if (!_RepoLobe.#text(rebuilds)) return this.#finish(sync, 0, "", check);\n const begun = await this.#begin("head", { contains: rebuilds }, { sync: true }, _RepoLobe.#of(sync));\n if ("job" in begun) this.cells.set(["sync"], { ...sync, stage: "proving" });\n else await this.#finish(sync, 1, begun.message, check);\n return void 0;\n }\n async #proven(sync, code, why, out) {\n const repo = this.#repo();\n const holds = code === 0 && out.trim().split("\\n")[1] === "holds";\n if (repo !== null && holds) this.cells.set(["repo"], { ...repo, rebuilds: null });\n const lacks = "the lobe pulled holds not the head this one kept: it waits for a whole push";\n return this.#finish(sync, holds ? 0 : 1, holds ? "" : why ?? lacks, sync["check"] ?? null);\n }\n async #rebuilt(why) {\n const repo = this.#repo();\n if (repo === null) return null;\n this.cells.set(["repo"], { ...repo, head: null, ready: why === null, failed: why });\n const first = why === null ? (await this.#held())[0]?.placeholder : null;\n return _RepoLobe.#text(first) ? first : null;\n }\n async #scanned(out) {\n const [shown = "", toldBlock = ""] = out.trim().split("\\n@ ");\n const [head = "", ...lines] = shown.split("\\n");\n const tracked = new Set(lines.filter((line) => line.startsWith("t ")).map((line) => line.slice(2)));\n const changed = new Set(lines.filter((line) => line.startsWith("c ")).map((line) => line.slice(2)));\n const tagged = lines.some((line) => line.startsWith("g "));\n const cut = {};\n const named = (kind, pattern) => {\n const all = [...tracked].flatMap((path) => pattern.exec(path)?.[1] ?? []).toSorted();\n if (all.length > this.#most()) cut[kind] = all.length - this.#most();\n return all.slice(0, this.#most());\n };\n const files = _RepoLobe.#hashedFiles(lines);\n const faculties = [];\n for (const label of named("faculties", /^faculties\\/([^/]+)\\/faculty\\.js$/))\n faculties.push(await this.#faculty(label, tracked, changed, files, tagged));\n const organs = [];\n for (const id of named("organs", /^organs\\/([^/]+)\\/graph\\.json$/))\n organs.push(await this.#organ(id, tracked, changed, tagged));\n const designs = [];\n for (const name of named("designs", /^designs\\/([^/]+)\\/design\\.json$/))\n designs.push(await this.#design(name, tracked, changed, files, tagged));\n this.cells.set(["scanned"], {\n head,\n faculties,\n organs,\n designs,\n ...Object.keys(cut).length > 0 ? { cut } : {}\n });\n const repo = this.#repo();\n if (repo !== null && _RepoLobe.#text(repo["head"]) && _RepoLobe.#text(head) && repo["head"] !== head)\n this.cells.set(["repo"], { ...repo, head });\n if (!tagged) return this.#tell(await this.#toldAt(toldBlock));\n await this.#tell([\n ...faculties.flatMap((one) => _RepoLobe.#found("faculty", one)),\n ...organs.flatMap((one) => _RepoLobe.#found("organ", one)),\n ...designs.flatMap((one) => _RepoLobe.#lookFound(one))\n ]);\n }\n async #toldAt(block) {\n if (block === "") return [];\n const lines = block.split("\\n").slice(1);\n const files = _RepoLobe.#hashedFiles(\n lines.flatMap(\n (line) => line.startsWith("A ") ? [`d ${line.slice(2)}`] : line.startsWith("U ") ? [`u ${line.slice(2)}`] : []\n )\n );\n const tracked = new Set(lines.filter((line) => line.startsWith("T ")).map((line) => line.slice(2)));\n const carried = new Map(\n lines.flatMap((line) => {\n const [, path, text] = /^B (\\S+) (".*")$/u.exec(line) ?? [];\n return path === void 0 || text === void 0 ? [] : [[path, text]];\n })\n );\n const read = async (path) => {\n const text = carried.get(path);\n if (text === void 0) return this.#file(path);\n try {\n const one = JSON.parse(text);\n return typeof one === "string" ? one : null;\n } catch {\n return null;\n }\n };\n const named = (pattern) => [...tracked].flatMap((path) => pattern.exec(path)?.[1] ?? []).toSorted().slice(0, this.#most());\n const none = new Set();\n const found = [];\n for (const label of named(/^faculties\\/([^/]+)\\/faculty\\.js$/))\n found.push(..._RepoLobe.#found("faculty", await this.#faculty(label, tracked, none, files, true, read)));\n for (const id of named(/^organs\\/([^/]+)\\/graph\\.json$/))\n found.push(..._RepoLobe.#found("organ", await this.#organ(id, tracked, none, true, read)));\n return found;\n }\n static #hashedFiles(lines) {\n const files = new Map();\n for (const line of lines) {\n if (!line.startsWith("d ") && !line.startsWith("u ")) continue;\n const hashed = _RepoLobe.#hashed.exec(line);\n const folder = hashed?.[2] ?? /^. (?:\\S* )?((?:designs|faculties)\\/[^/]+)\\//.exec(line)?.[1];\n if (folder === void 0) continue;\n const held = files.get(folder) ?? { parts: [], unread: false };\n const [sha, path] = [hashed?.[1], hashed?.[3]];\n const part = path === void 0 ? void 0 : _RepoLobe.#partOf(folder, path);\n if (sha === void 0 || path === void 0) held.unread = true;\n else if (part !== void 0) held.parts.push([part, sha]);\n files.set(folder, held);\n }\n return files;\n }\n static #partOf(folder, path) {\n if (folder.startsWith("designs/")) return _RepoLobe.#isData(path) ? path : void 0;\n const asset = path.startsWith("assets/") ? path.slice("assets/".length) : "";\n return asset !== "" && !asset.split("/").some((name) => name.startsWith(".")) ? asset : void 0;\n }\n static #isData(path) {\n if (path === "DESIGN.md" || path === "versions.json") return false;\n if (path.startsWith("components/") || path.startsWith("words/")) return false;\n return !path.split("/").some((name) => name.startsWith("."));\n }\n #dataOf(parts) {\n return this.#digestOf(JSON.stringify(_RepoLobe.#byPath(parts)));\n }\n static #byPath(parts) {\n return parts.map((part) => [...part]).toSorted((one, other) => (one[0] ?? "") < (other[0] ?? "") ? -1 : 1);\n }\n async #design(name, tracked, changed, files, tagged) {\n const root = `designs/${name}/`;\n if (!_RepoLobe.#label.test(name)) return { name, why: "its folder is no name" };\n if (!tracked.has(`${root}versions.json`)) return { name, why: "it holds no versions.json committed" };\n if ([...changed].some((path) => path.startsWith(root)))\n return { name, why: "its files hold changes not committed" };\n const held = files.get(`designs/${name}`) ?? { parts: [], unread: true };\n const design = await this.#file(`${root}design.json`);\n const kept = await this.#file(`${root}versions.json`);\n if (held.unread || design === null || kept === null) return { name, why: "its files are not all read" };\n const read = _RepoLobe.#json(design);\n const version = _RepoLobe.#arg(read, "version");\n if (_RepoLobe.#arg(read, "name") !== name) return { name, why: "its design.json names another name" };\n if (!_RepoLobe.#text(version) || !_RepoLobe.#version.test(version))\n return { name, why: "its design.json names no version" };\n const data = this.#dataOf(held.parts);\n const named = _RepoLobe.#arg(_RepoLobe.#json(kept), version);\n const look = _RepoLobe.#arg(named, "look");\n if (_RepoLobe.#arg(named, "data") !== data)\n return {\n name,\n version,\n data,\n why: "versions.json names another data digest for its version"\n };\n if (!_RepoLobe.#text(look) || !_RepoLobe.#digest.test(look))\n return { name, version, data, why: "versions.json names no look for its version" };\n const told = this.#record(\n "faculty",\n `${name}.look`,\n version,\n { digest: look, assets: _RepoLobe.#byPath(held.parts) },\n tagged\n );\n const why = _RepoLobe.#arg(told, "why");\n return { name, version, data, look, ...why === void 0 ? {} : { why } };\n }\n static #lookFound(one) {\n const [name, version] = [_RepoLobe.#arg(one, "name"), _RepoLobe.#arg(one, "version")];\n if (!_RepoLobe.#text(name) || !_RepoLobe.#text(version) || _RepoLobe.#arg(one, "why") !== void 0) return [];\n return [{ kind: "faculty", label: `${name}.look`, version }];\n }\n static #found(kind, one) {\n const label = _RepoLobe.#arg(one, _RepoLobe.#keyOf(kind));\n const version = _RepoLobe.#arg(one, "version");\n if (!_RepoLobe.#text(label) || !_RepoLobe.#text(version) || _RepoLobe.#arg(one, "why") !== void 0) return [];\n return [{ kind, label, version }];\n }\n async #faculty(label, tracked, changed, files, tagged, reader = (path) => this.#file(path)) {\n const [code, versions] = [`faculties/${label}/faculty.js`, `faculties/${label}/versions.json`];\n if (!_RepoLobe.#label.test(label)) return { label, why: "its folder is no label" };\n if (!tracked.has(versions)) return { label, why: "it holds no versions.json committed" };\n if (changed.has(code) || changed.has(versions))\n return { label, why: "its faculty.js or versions.json holds changes not committed" };\n const assets = `faculties/${label}/assets/`;\n if ([...changed].some((path) => path.startsWith(assets)))\n return { label, why: "its assets hold changes not committed" };\n const hashed = files.get(`faculties/${label}`) ?? {\n parts: [],\n unread: false\n };\n if (hashed.unread) return { label, why: "its assets are not all read" };\n const [source, kept] = [await reader(code), await reader(versions)];\n if (source === null || kept === null) return { label, why: "its files are not read" };\n const digest = this.#digestOf(source);\n const held = _RepoLobe.#json(kept);\n const version = _RepoLobe.#fields(held) ? Object.keys(held).find((one) => held[one] === digest) : void 0;\n if (version === void 0 || !_RepoLobe.#version.test(version))\n return { label, digest, why: "versions.json names no version for its digest" };\n const carried = hashed.parts.length === 0 ? {} : { assets: _RepoLobe.#byPath(hashed.parts) };\n return this.#record("faculty", label, version, { digest, ...carried }, tagged, source);\n }\n async #organ(id, tracked, changed, tagged, reader = (path) => this.#file(path)) {\n const [graph, build] = [`organs/${id}/graph.json`, `organs/${id}/host/build`];\n if (!_RepoLobe.#id.test(id)) return { id, why: "its folder is no fixed ID" };\n if (!tracked.has(build)) return { id, why: "it holds no host/build" };\n if ([graph, build].some((file) => changed.has(file))) return { id, why: "its files hold changes not committed" };\n const blueprint = tracked.has(graph) ? await reader(graph) : null;\n const read = blueprint === null ? null : _RepoLobe.#json(blueprint);\n const inner = _RepoLobe.#arg(read, "blueprint");\n const version = _RepoLobe.#arg(read, "version") ?? _RepoLobe.#arg(inner, "version");\n if (blueprint === null || typeof version !== "string" || !_RepoLobe.#version.test(version))\n return { id, why: "its graph.json names no version" };\n return this.#record("organ", id, version, { digest: this.#digestOf(blueprint) }, tagged, blueprint);\n }\n static #keyOf(kind) {\n return kind === "faculty" ? "label" : "id";\n }\n #record(kind, label, version, bytes, tagged, text = null) {\n const named = { [_RepoLobe.#keyOf(kind)]: label };\n const held = this.cells.get(["told", kind, label, version]);\n if (!_RepoLobe.#fields(held)) {\n if (tagged) {\n this.cells.set(["told", kind, label, version], {\n ...bytes,\n heard: false,\n at: this.stamp.time\n });\n this.#toldInOrder([kind, label, version]);\n if (text !== null) this.cells.set(["text", kind, label, version], text);\n }\n return { ...named, version, ...bytes };\n }\n const same = Object.keys(bytes).every((key) => JSON.stringify(held[key]) === JSON.stringify(bytes[key]));\n if (same) return { ...named, version, ...bytes };\n return {\n ...named,\n version,\n ...bytes,\n why: `version ${version} was told with other bytes: raise its version`\n };\n }\n #toldInOrder(named) {\n const next = Number(this.cells.get(["toldNext"]) ?? 0);\n this.cells.set(["toldAt", next], [...named]);\n this.cells.set(["toldNext"], next + 1);\n }\n async #file(path) {\n const read = await this.ask("repos", "read", { path });\n const text = "result" in read ? _RepoLobe.#arg(read.result, "text") : void 0;\n return typeof text === "string" ? text : null;\n }\n async #tell(found) {\n await this.#tellFar(found);\n const unheard = found.flatMap(({ kind, label, version }) => {\n const held = this.cells.get(["told", kind, label, version]);\n return _RepoLobe.#fields(held) && held["heard"] !== true ? [{ kind, label, version, held }] : [];\n });\n if (unheard.length === 0) return;\n const described = await this.ask("library", null, null);\n const methods = "result" in described ? _RepoLobe.#arg(described.result, "methods") : void 0;\n const offered = _RepoLobe.#kinds(_RepoLobe.#arg(methods, "changed"));\n for (const { kind, label, version, held } of unheard) {\n if (!offered.includes(kind)) continue;\n const changed = { kind, label, version, digest: held["digest"] ?? null };\n const letter = { lives: _RepoLobe.#lives };\n const sent = await this.ask("library", "changed", changed, void 0, { letter });\n if (!("error" in sent)) this.cells.set(["told", kind, label, version], { ...held, heard: true });\n }\n }\n async #tellFar(found) {\n const fresh = found.flatMap(({ kind, label, version }) => {\n const held = this.cells.get(["told", kind, label, version]);\n return _RepoLobe.#fields(held) && held["far"] !== true && (kind === "faculty" || kind === "organ") ? [{ kind, label, version, held }] : [];\n });\n if (fresh.length === 0) return;\n const backs = (await this.#relations()).filter(\n (one) => one.side === "standing" && one.placeholder?.startsWith(`${_RepoLobe.#hears}-`) === true\n );\n if (backs.length === 0) return;\n for (const { kind, label, version, held } of fresh) {\n const changed = { kind, label, version, digest: held["digest"] ?? null };\n const before = held["farHeard"];\n const heard = new Set(Array.isArray(before) ? before.filter((one) => _RepoLobe.#text(one)) : []);\n for (const { placeholder } of backs) {\n if (!_RepoLobe.#text(placeholder) || heard.has(placeholder)) continue;\n if (!("error" in await this.ask(placeholder, "changed", changed))) heard.add(placeholder);\n }\n const { farHeard: _, ...rest } = held;\n const all = backs.every(({ placeholder }) => !_RepoLobe.#text(placeholder) || heard.has(placeholder));\n this.cells.set(["told", kind, label, version], all ? { ...rest, far: true } : { ...rest, farHeard: [...heard] });\n }\n }\n static #kinds(changed) {\n const kind = _RepoLobe.#arg(_RepoLobe.#arg(_RepoLobe.#arg(changed, "args"), "properties"), "kind");\n const named = _RepoLobe.#arg(kind, "enum");\n return Array.isArray(named) ? named : [];\n }\n faculties(args) {\n return this.#offered("faculties", args);\n }\n organs(args) {\n return this.#offered("organs", args);\n }\n designs(args) {\n return this.#offered("designs", args);\n }\n #offered(method, args) {\n const refused = this.#refusal(method, args);\n if (refused !== null) return refused;\n const found = _RepoLobe.#arg(this.cells.get(["scanned"]), method);\n if (!Array.isArray(found) || found.length === 0) return this.error("absent", `the repo holds no ${method}/`);\n return found;\n }\n async get(args) {\n const refused = this.#refusal("get", args);\n if (refused !== null) return refused;\n const { kind, label, version, path } = _RepoLobe.#fields(args) ? args : {};\n if (kind !== "faculty" && kind !== "organ" || !_RepoLobe.#text(label) || !_RepoLobe.#label.test(label))\n return this.error("refused", "a get names a faculty or an organ by its label");\n if (path !== void 0 && (kind !== "faculty" || !_RepoLobe.#text(path)))\n return this.error("refused", "a path names a faculty\'s asset");\n const near = ["owner", "near"].includes(this.#role());\n if (version === null && !near) return this.error("refused", "a version told is read from afar");\n const told = _RepoLobe.#text(version) ? this.cells.get(["told", kind, label, version]) : null;\n const at = _RepoLobe.#shown(version);\n if (told !== null && !_RepoLobe.#fields(told)) return this.error("absent", `no version ${at} of ${label} was told`);\n if (kind === "faculty" && told !== null && told["assets"] !== void 0 && this.#isLook(label))\n return this.#getLook(label, at, told, path);\n if (path !== void 0 && (told === null || told["assets"] === void 0))\n return this.error("refused", `${label} ${at} carries no assets`);\n if (path !== void 0 && told !== null) return this.#getAsset(label, told, path);\n const kept = _RepoLobe.#text(version) ? this.cells.get(["text", kind, label, version]) : void 0;\n if (told !== null && typeof kept === "string") {\n if (kind === "faculty")\n return {\n source: kept,\n digest: told["digest"] ?? null,\n ..._RepoLobe.#carried(told)\n };\n return { blueprint: kept, half: this.cells.get(["built", label, at]) ?? null };\n }\n if (kind === "faculty") return this.#getFaculty(label, told);\n return this.#getOrgan(label, at, told);\n }\n #isLook(label) {\n const designs = _RepoLobe.#arg(this.cells.get(["scanned"]), "designs");\n const name = label.endsWith(".look") ? label.slice(0, -".look".length) : null;\n return Array.isArray(designs) && designs.some((one) => _RepoLobe.#arg(one, "name") === name);\n }\n static #carried(told) {\n const parts = _RepoLobe.#partsOf(told["assets"]);\n return parts === null ? {} : { assets: parts };\n }\n async #getAsset(label, told, path) {\n const part = _RepoLobe.#partsOf(told["assets"])?.find((one) => one[0] === path);\n if (part === void 0) return this.error("absent", `${label} holds no asset ${_RepoLobe.#shown(path)}`);\n return this.#asset(part);\n }\n async #asset(part) {\n const read = await this.ask("repos", "bytes", { sha: part[1] ?? null });\n if ("error" in read)\n return read.error.code === "absent" ? this.error("absent", this.#unkept(_RepoLobe.#shown(part[0]))) : this.#result(read);\n const bytes = _RepoLobe.#arg(read.result, "bytes");\n const whole = bytes instanceof Uint8Array ? _RepoLobe.#canonical(bytes) : null;\n if (whole === null || this.#shaOf(whole) !== part[1])\n return this.error("refused", "the asset kept is not the version told");\n return { path: part[0] ?? null, digest: part[1] ?? null, bytes: whole };\n }\n #unkept(shown) {\n if (this.#scanning()) return `${shown} is being kept: a scan of the repo is running, ask again once it ends`;\n if (this.cells.get(["owed"]) === true)\n return `${shown} is not kept yet: a scan of the repo is owed and begins once the repo runs nothing, ask again then`;\n return `${shown} is not kept yet: a scan of the repo keeps it`;\n }\n static #partsOf(data) {\n if (!Array.isArray(data)) return null;\n const parts = [];\n for (const one of data) {\n const [path, sha] = Array.isArray(one) && one.length === 2 ? one : [];\n if (!_RepoLobe.#text(path) || !_RepoLobe.#text(sha) || !_RepoLobe.#digest.test(sha)) return null;\n parts.push([path, sha]);\n }\n return parts;\n }\n async #getLook(label, version, told, path) {\n const name = label.slice(0, -".look".length);\n const parts = _RepoLobe.#partsOf(told["assets"]);\n if (parts === null) return this.error("refused", `the look ${label} ${version} names no assets whole`);\n if (path === void 0) {\n const built = this.cells.get(["look", name, version]);\n const source = _RepoLobe.#arg(built, "source");\n if (typeof source === "string" && this.#digestOf(source) === told["digest"])\n return { source, digest: told["digest"], assets: parts };\n const why = _RepoLobe.#arg(built, "why");\n return this.error("refused", _RepoLobe.#text(why) ? why : `the look of ${name} ${version} is not built: build it`);\n }\n const part = parts.find((one) => one[0] === path);\n if (part === void 0) return this.error("absent", `the look ${label} holds no asset ${_RepoLobe.#shown(path)}`);\n return this.#asset(part);\n }\n async #getFaculty(label, told) {\n const source = await this.#file(`faculties/${label}/faculty.js`);\n if (source === null) return this.error("absent", `the repo holds no faculties/${label}/faculty.js`);\n const digest = this.#digestOf(source);\n if (told !== null && told["digest"] !== digest)\n return this.error("refused", "the faculty.js the repo holds is not the version told");\n return {\n source,\n digest,\n ...told === null ? {} : _RepoLobe.#carried(told)\n };\n }\n async #getOrgan(id, version, told) {\n const blueprint = await this.#file(`organs/${id}/graph.json`);\n if (blueprint === null) return this.error("absent", `the repo holds no organ ${id} whole`);\n if (told !== null && told["digest"] !== this.#digestOf(blueprint))\n return this.error("refused", "the organ the repo holds is not the version told");\n const half = told === null ? null : this.cells.get(["built", id, version]) ?? null;\n return { blueprint, half };\n }\n build(args) {\n const refused = this.#refusal("build", args);\n if (refused !== null) return Promise.resolve(refused);\n const [organ, design] = [_RepoLobe.#arg(args, "organ"), _RepoLobe.#arg(args, "design")];\n const version = _RepoLobe.#arg(args, "version");\n if (organ === void 0 === (design === void 0))\n return Promise.resolve(this.error("refused", "a build names an organ or a design"));\n const [kind, named] = organ === void 0 ? ["design", design] : ["organ", organ];\n const told = _RepoLobe.#text(named) && _RepoLobe.#text(version) ? this.cells.get(\n kind === "design" ? ["told", "faculty", `${named}.look`, version] : ["told", "organ", named, version]\n ) : void 0;\n if (!_RepoLobe.#fields(told))\n return Promise.resolve(this.error("absent", `no such ${kind} was told at that version`));\n if (!("name" in this.#ready())) return Promise.resolve(this.error("refused", "the repo is not ready"));\n if (!this.#mainHolds(kind, _RepoLobe.#shown(named), _RepoLobe.#shown(version), told["digest"]))\n return Promise.resolve(\n this.error(\n "refused",\n `main holds not ${_RepoLobe.#shown(named)} ${_RepoLobe.#shown(version)}: a version is built while main holds it`\n )\n );\n const built = { [kind]: named ?? null, version: version ?? null };\n const method = kind === "design" ? "look" : "build";\n return this.#begin("build", { [kind]: named ?? null }, null, { more: { built }, method });\n }\n #mainHolds(kind, named, version, digest) {\n const [list, key, by] = kind === "design" ? ["designs", "name", "look"] : ["organs", "id", "digest"];\n const found = _RepoLobe.#arg(this.cells.get(["scanned"]), list);\n const now = Array.isArray(found) ? found.find((one) => _RepoLobe.#arg(one, key) === named) : void 0;\n return _RepoLobe.#arg(now, "version") === version && _RepoLobe.#arg(now, by) === digest && _RepoLobe.#arg(now, "why") === void 0;\n }\n async told(args) {\n const refused = this.#refusal("told", args);\n if (refused !== null) return refused;\n const tells = _RepoLobe.#arg(args, "tells");\n if (this.#role() === "library" && this.stamp.occupant !== null) {\n if (_RepoLobe.#text(tells)) {\n const far = this.stamp.asker;\n await this.#untold(far, _RepoLobe.#hears);\n const note = { repo: this.#repo()?.["name"] ?? null, library: far };\n const accepted = await this.ask("mouth", "accept", {\n invitation: tells,\n placeholder: _RepoLobe.#backUnder(_RepoLobe.#hears, far),\n note\n });\n if ("error" in accepted)\n return this.error(accepted.error.code, `the standing back was not taken: ${accepted.error.message}`);\n }\n } else if (tells !== void 0) return this.error("refused", "tells is a far library’s alone");\n const page = this.#page(["toldAt"], args);\n if (!("cells" in page)) return page;\n const told = page.cells.flatMap(({ value }) => {\n if (!Array.isArray(value)) return [];\n const [kind, label, version] = value.map((part) => typeof part === "string" ? part : "");\n const held = this.cells.get(["told", kind ?? "", label ?? "", version ?? ""]);\n if (!_RepoLobe.#fields(held)) return [];\n return [{ kind: kind ?? null, label: label ?? null, version: version ?? null, ...held }];\n });\n return { told, cursor: page.cursor };\n }\n head(args) {\n const refused = this.#serving("head", args);\n if (refused !== null) return refused;\n const repo = this.#repo() ?? {};\n if (this.#scopeOfAsker() !== null) return { head: null };\n return { head: _RepoLobe.#text(repo["rebuilds"]) ? null : repo["head"] ?? null };\n }\n async give(args) {\n const refused = this.#serving("give", args);\n if (refused !== null) return refused;\n const repo = this.#repo() ?? {};\n const since = _RepoLobe.#arg(args, "since") ?? null;\n const tag = _RepoLobe.#arg(args, "tag") ?? null;\n const far = this.stamp.asker;\n const scope = this.#scopeOfAsker();\n if (tag !== null && !(_RepoLobe.#text(tag) && _RepoLobe.#tag.test(tag)))\n return this.error("refused", "a tag is v and three whole numbers");\n const out = this.cells.get(["out", far]);\n const current = _RepoLobe.#fields(out) && (out["of"] ?? null) === (repo["head"] ?? null);\n const piece = _RepoLobe.#arg(args, "piece") ?? null;\n const same = _RepoLobe.#fields(out) && out["since"] === since && (out["tag"] ?? null) === tag && (out["piece"] ?? null) === piece;\n if (_RepoLobe.#fields(out) && current && same && _RepoLobe.#text(out["run"])) {\n if (_RepoLobe.#text(out["failed"])) {\n this.cells.delete(["out", far]);\n return this.error("refused", out["failed"]);\n }\n if (typeof out["pieces"] !== "number") return { ready: false };\n const ready = { pieces: out["pieces"], head: out["head"] ?? null };\n return scope === null ? ready : { ...ready, scope };\n }\n if (_RepoLobe.#text(repo["doing"])) {\n await this.#check();\n return { ready: false };\n }\n const as = `out-${far}`;\n const named = { ...typeof tag === "string" ? { tag } : {}, ...typeof piece === "number" ? { piece } : {} };\n const tagged = typeof tag === "string" ? { tag } : {};\n const begun = scope === null ? await this.#begin("bundle", { since, as, ...named }, { for: far }) : await this.#begin("cut", { as, scope, ...tagged }, { for: far });\n if (!("job" in begun)) return begun;\n const of = repo["head"] ?? null;\n this.cells.set(["out", far], { since, ...named, of, run: begun.job, pieces: null, head: null, failed: null });\n return { ready: false };\n }\n #serving(method, args) {\n const refused = this.#refusal(method, args);\n if (refused !== null) return refused;\n if (!("name" in this.#ready())) return this.error("refused", "the repo is not ready");\n if (method === "give" && _RepoLobe.#text(this.#repo()?.["rebuilds"]))\n return this.error("refused", "the lobe rebuilds: it is pushed whole first");\n return null;\n }\n async piece(args) {\n const refused = this.#serving("piece", args);\n if (refused !== null) return refused;\n const at = _RepoLobe.#arg(args, "at");\n const out = this.cells.get(["out", this.stamp.asker]);\n const pieces = _RepoLobe.#arg(out, "pieces");\n if (typeof at !== "number" || typeof pieces !== "number" || at < 0 || at >= pieces)\n return this.error("refused", "no such piece is ready");\n return this.#result(await this.ask("repos", "piece", { at, as: `out-${this.stamp.asker}` }));\n }\n async take(args) {\n const refused = this.#serving("take", args);\n if (refused !== null) return refused;\n const { push, at, pieces, bytes } = _RepoLobe.#fields(args) ? args : {};\n if (!_RepoLobe.#text(push) || typeof at !== "number" || typeof pieces !== "number" || !(bytes instanceof Uint8Array))\n return this.error("refused", "a piece names its push, where it stands, of how many, and its bytes");\n const far = this.stamp.asker;\n const last = this.#shaOf(bytes);\n const held = this.cells.get(["in", far]);\n const same = _RepoLobe.#fields(held) && held["push"] === push && held["pieces"] === pieces ? held : null;\n if (same !== null && same["got"] === at + 1 && same["last"] === last) return this.#receive(far);\n const named = _RepoLobe.#fields(held) && held["push"] === push;\n const fresh = {\n push,\n pieces,\n got: 0,\n run: null,\n head: null,\n failed: null,\n check: null,\n landing: null,\n landed: false\n };\n const begins = !named && at === 0;\n const given = _RepoLobe.#arg(args, "tells");\n const kept = begins ? { ...fresh, ...given === void 0 ? { told: true } : {} } : same !== null && same["got"] === at ? same : null;\n if (kept === null) return this.error("refused", "the pieces of a push come in order");\n const back = begins ? await this.#tellsBy(far, given) : null;\n if (back !== null && typeof back !== "string") return back;\n const put = await this.ask("repos", "put", { at, pieces, bytes, as: `in-${far}` });\n if ("error" in put) return this.#heard(put);\n this.cells.set(["in", far], { ...kept, got: at + 1, last });\n return this.#receive(far);\n }\n async taken(args) {\n const refused = this.#serving("taken", args);\n if (refused !== null) return refused;\n const far = this.stamp.asker;\n const kept = this.cells.get(["in", far]);\n if (!_RepoLobe.#fields(kept)) return this.error("refused", "no push is coming");\n const ended = await this.#endOf(far, kept);\n if (ended !== null) return ended;\n await this.#check();\n await this.#receive(far);\n const now = this.cells.get(["in", far]);\n const doing = this.#repo()?.["doing"];\n const job = _RepoLobe.#text(doing) ? this.cells.get(["job", doing]) : void 0;\n const waiting = _RepoLobe.#fields(now) && now["run"] === null && now["got"] === now["pieces"];\n const waits = waiting && _RepoLobe.#fields(job) ? { waits: `the repo runs a ${_RepoLobe.#shown(job["kind"])} first` } : {};\n return { ready: false, ...waits };\n }\n async #receiveWaiting() {\n for (const { key } of this.#all(["in"])) {\n const far = key[1];\n if (_RepoLobe.#text(far)) await this.#receive(far);\n }\n }\n async #clear(as) {\n const asked = await this.ask("repos", "clear", { as });\n if ("error" in asked && asked.error.code === "busy") this.cells.set(["uncleared", as], null);\n else if (this.cells.get(["uncleared", as]) !== void 0) this.cells.delete(["uncleared", as]);\n }\n async #unclear() {\n for (const { key } of this.#all(["uncleared"])) {\n const as = key[1];\n if (_RepoLobe.#text(as)) await this.#clear(as);\n }\n }\n async #check() {\n await this.#unclear();\n const doing = this.#repo()?.["doing"];\n if (!_RepoLobe.#text(doing)) return;\n const checked = await this.ask("repos", "check", {});\n if ("error" in checked || !_RepoLobe.#fields(checked.result)) return;\n const { doing: running, lost, last } = checked.result;\n const held = this.cells.get(["job", doing]);\n if (running === doing || !_RepoLobe.#fields(held) || held["ended"] !== null) return;\n if (_RepoLobe.#fields(last) && last["job"] === doing) {\n const { code, out, err } = last;\n if (typeof code === "number" && typeof out === "string" && typeof err === "string") {\n await this.#jobEnded(await this.nerves.read(), doing, held, code, out, err);\n return;\n }\n }\n if (Array.isArray(lost) && lost.includes(doing)) return;\n const kept = await this.ask("repos", "job", { job: doing });\n const ended = "result" in kept ? _RepoLobe.#arg(_RepoLobe.#arg(kept.result, "ended") ?? null, "code") : void 0;\n if ("result" in kept && typeof ended !== "number") return;\n const whole = ended === 0;\n if (whole) {\n this.cells.delete(["undo"]);\n this.cells.set(["owed"], true);\n }\n const why = whole ? "the jailer ended this job whole, and its word of the end never came: its output is lost" : "the jailer runs this job no more, and its word of the end never came";\n await this.#jobEnded(await this.nerves.read(), doing, held, -1, "", why);\n await this.#awaiting();\n }\n async #tellsBy(far, invitation) {\n await this.#untold(far);\n if (!_RepoLobe.#text(invitation)) return null;\n const placeholder = _RepoLobe.#backUnder(_RepoLobe.#tells, far);\n const note = { repo: this.#repo()?.["name"] ?? null, tells: far };\n const accepted = await this.ask("mouth", "accept", { invitation, placeholder, note });\n if ("error" in accepted)\n return this.error(accepted.error.code, `the standing back was not taken: ${accepted.error.message}`);\n return placeholder;\n }\n async #untold(far, prefix = _RepoLobe.#tells) {\n const placeholder = _RepoLobe.#backUnder(prefix, far);\n const held = (await this.#relations()).find((one) => one.side === "standing" && one.placeholder === placeholder);\n if (held !== void 0) await this.#unlink({ placeholder, far: held.far });\n }\n async #tellEnds() {\n for (const { key, value } of this.#all(["in"])) {\n const far = key[1];\n if (typeof far !== "string" || !_RepoLobe.#fields(value) || value["told"] === true) continue;\n const told = await this.#endOf(far, value);\n if (told === null) continue;\n this.cells.set(key, { ...value, told: true });\n await this.ask(_RepoLobe.#backUnder(_RepoLobe.#tells, far), "done", told);\n }\n }\n async #endOf(far, kept) {\n const landed = kept["landed"] === true;\n const failed = kept["failed"];\n if (!landed && !_RepoLobe.#text(failed)) return null;\n const checked = kept["check"] ?? null;\n const scoped = checked !== null && await this.#scopeFor(far) !== null;\n const check = scoped ? { code: _RepoLobe.#arg(checked, "code") ?? null } : checked;\n const head = kept["head"];\n const ended = landed ? { code: 0, out: _RepoLobe.#text(head) ? `${head}\n` : "", err: "" } : { code: 1, out: "", err: _RepoLobe.#shown(failed) };\n return { job: kept["push"] ?? null, kind: "push", ...ended, check };\n }\n async #receive(far) {\n const kept = this.cells.get(["in", far]);\n const repo = this.#repo();\n if (!_RepoLobe.#fields(kept) || kept["got"] !== kept["pieces"] || kept["run"] !== null) return null;\n if (repo === null || _RepoLobe.#text(repo["doing"])) return null;\n const scope = await this.#scopeFor(far);\n const given = { as: `in-${far}`, pieces: kept["pieces"] ?? 1, ...scope === null ? {} : { scope } };\n const begun = await this.#begin("bring", given, { for: far }, { asker: far });\n if ("job" in begun) this.cells.set(["in", far], { ...kept, run: begun.job });\n return null;\n }\n async #served(far, kind, why, out) {\n const key = kind === "bundle" || kind === "cut" ? ["out", far] : ["in", far];\n const kept = this.cells.get(key);\n if (!_RepoLobe.#fields(kept)) return;\n const [first = "", second = "", third = ""] = out.trim().split("\\n");\n if (kind === "cut") return this.#cutGiven(far, kept, why);\n if (kind === "bundle") {\n this.cells.set(key, {\n ...kept,\n pieces: why === null ? Number(first) : null,\n head: second || null,\n failed: why\n });\n return;\n }\n if (kind === "bring") return this.#pushBrought(far, kept, why, first, second, third);\n if (kind === "land") return this.#pushLanded(far, kept, why, out);\n const repo = this.#repo();\n if (kind !== "head") return void 0;\n if (why === null && second === "holds" && repo !== null) this.cells.set(["repo"], { ...repo, rebuilds: null });\n this.cells.set(key, { ...kept, landed: true });\n return void 0;\n }\n async #cutGiven(far, kept, why) {\n if (why !== null) {\n this.cells.set(["out", far], { ...kept, failed: why });\n return;\n }\n const piece = typeof kept["piece"] === "number" ? { piece: kept["piece"] } : {};\n const given = { since: kept["since"] ?? null, as: `out-${far}`, cut: true, ...piece };\n const begun = await this.#begin("bundle", given, { for: far }, { asker: far });\n this.cells.set(["out", far], "job" in begun ? { ...kept, run: begun.job } : { ...kept, failed: begun.message });\n }\n async #pushBrought(far, kept, why, head, how, tip) {\n const key = ["in", far];\n if (why !== null) {\n this.cells.set(key, { ...kept, failed: why });\n return;\n }\n if (how === "held") {\n this.cells.set(key, { ...kept, head, landed: true });\n return;\n }\n const check = await this.#conform(`in-${far}`, head, true, far);\n this.cells.set(key, { ...kept, head, check, ...how === "graft" && _RepoLobe.#text(tip) ? { tip } : {} });\n if ("code" in check) await this.#verdict(far);\n }\n async #pushLanded(far, kept, why, out) {\n const tip = kept["tip"];\n const head = _RepoLobe.#text(tip) ? tip : _RepoLobe.#headOf(out);\n const rebuilds = this.#repo()?.["rebuilds"];\n const proving = why === null && _RepoLobe.#text(rebuilds) && "job" in await this.#begin("head", { contains: rebuilds }, { for: far }, { asker: far });\n const landed = why !== null ? { failed: why } : proving ? { head } : { head, landed: true };\n this.cells.set(["in", far], { ...kept, ...landed });\n }\n async #conform(as, head, push, asker) {\n const script = this.#gateScript();\n const gated = push && this.#gates().push === "on" && _RepoLobe.#text(script);\n const given = {\n as,\n head,\n ...this.#checks(),\n ...gated ? { script } : {}\n };\n const begun = await this.#begin("check", given, { check: as }, { asker, method: "conform" });\n if ("job" in begun) return { job: begun.job };\n return { code: 1, out: "", err: `the check did not begin: ${begun.message}` };\n }\n #checks() {\n if (this.#holdsScope()) return { parts: _RepoLobe.parts, scoped: true };\n const conform = this.cells.get(["conform"]);\n return { parts: _RepoLobe.parts, ..._RepoLobe.#text(conform) ? { conform } : {} };\n }\n async #checked(as, check) {\n const tail = {\n ...check,\n out: _RepoLobe.#last(_RepoLobe.#shown(check["out"])),\n err: _RepoLobe.#last(_RepoLobe.#shown(check["err"]))\n };\n if (as === "pull") {\n const sync = this.cells.get(["sync"]);\n if (!_RepoLobe.#fields(sync) || sync["stage"] !== "checking") return;\n const checked = { ...sync, check: tail };\n this.cells.set(["sync"], checked);\n return this.#checkedPull(checked, tail);\n }\n const far = as.startsWith("in-") ? as.slice(3) : "";\n const kept = this.cells.get(["in", far]);\n if (!_RepoLobe.#fields(kept)) return;\n this.cells.set(["in", far], { ...kept, check: tail });\n return this.#verdict(far);\n }\n static #last(text) {\n const last = text.slice(-_RepoLobe.#tail);\n return /^[\\uDC00-\\uDFFF]/.test(last) ? last.slice(1) : last;\n }\n async #verdict(far) {\n const kept = this.cells.get(["in", far]);\n const check = _RepoLobe.#arg(kept, "check");\n if (!_RepoLobe.#fields(kept) || !_RepoLobe.#fields(check) || !("code" in check)) return;\n if (check["code"] !== 0) {\n this.cells.set(["in", far], {\n ...kept,\n failed: _RepoLobe.#refusalOf(check, await this.#scopeFor(far) !== null)\n });\n return;\n }\n if (_RepoLobe.#text(kept["landing"]) || _RepoLobe.#text(this.#repo()?.["doing"])) return;\n const as = `in-${far}`;\n const begun = await this.#begin("land", { as }, { for: far }, { asker: far });\n if ("job" in begun) this.cells.set(["in", far], { ...kept, landing: begun.job });\n }\n static #refusalOf(check, bare = false) {\n if (bare) return "its check is red";\n const said = `${_RepoLobe.#shown(check["out"])}\n${_RepoLobe.#shown(check["err"])}`.trim();\n const tail = said.slice(-_RepoLobe.#tail);\n return `its check is red:\n${tail || `it ended ${typeof check["code"] === "number" ? check["code"] : "unread"}`}`;\n }\n async #authoring(repo) {\n const writers = (await this.#given()).some(({ note }) => _RepoLobe.#kindOf(note) === "writer");\n if (!writers) return null;\n if (this.cells.get(["author"]) !== this.stamp.asker)\n return this.error("refused", "far writers push to this lobe: only its author commits beside it");\n if (_RepoLobe.#text(repo["rebuilds"])) return this.error("refused", "the lobe rebuilds: it is pushed whole first");\n return null;\n }\n #filesOf(files) {\n if (files === void 0) return {};\n if (!_RepoLobe.#fields(files)) return null;\n const all = Object.entries(files);\n if (all.length > this.#most() || all.some(([path, text]) => path === "" || typeof text !== "string")) return null;\n return files;\n }\n #pathsOf(paths) {\n if (paths === void 0) return [];\n if (!Array.isArray(paths) || paths.length < 1 || paths.length > this.#most()) return null;\n const named = paths.flatMap((one) => typeof one === "string" ? [one] : []);\n const fit = (one) => one.split("/").every((name) => _RepoLobe.#entry.test(name));\n return named.length === paths.length && named.every(fit) ? named : null;\n }\n async commit(args) {\n const refused = this.#refusal("commit", args);\n if (refused !== null) return refused;\n const message = _RepoLobe.#arg(args, "message");\n const files = this.#filesOf(_RepoLobe.#arg(args, "files"));\n if (!_RepoLobe.#text(message)) return this.error("refused", "a commit holds its message");\n if (files === null)\n return this.error("refused", `a commit\'s files are each a path and its text, ${this.#most()} at most`);\n const paths = this.#pathsOf(_RepoLobe.#arg(args, "paths"));\n if (paths === null)\n return this.error("refused", `a commit\'s paths are each a file or a folder of the repo, ${this.#most()} at most`);\n if (paths.length > 0 && Object.keys(files).length > 0)\n return this.error("refused", "a commit writes files or takes paths, not both");\n const executable = _RepoLobe.#arg(args, "executable") ?? [];\n if (!Array.isArray(executable) || executable.some((path) => typeof path !== "string" || !Object.hasOwn(files, path)))\n return this.error("refused", "what a commit makes executable are paths among its files");\n const ready = this.#ready();\n if (!("name" in ready)) return ready;\n const unauthored = await this.#authoring(ready.repo);\n if (unauthored !== null) return unauthored;\n const gating = this.#commitGate(args);\n if (typeof gating !== "boolean") return gating;\n if (_RepoLobe.#text(ready.repo["doing"])) {\n await this.#check();\n return this.error("refused", `the repo runs ${ready.repo["doing"]} already`);\n }\n const written = Object.keys(files);\n const before = written.length === 0 ? null : await this.#before(written);\n if (before !== null && "code" in before) return before;\n if (before !== null) this.cells.set(["undo"], executable.length === 0 ? before : { ...before, executable });\n else if (paths.length > 0) this.cells.set(["undo"], { files: [], dirs: [], paths });\n for (const [path, text] of Object.entries(files)) {\n const wrote = await this.ask("repos", "write", { path, text: text ?? "" });\n if ("error" in wrote) return this.error(wrote.error.code, await this.#undone(`${path}: ${wrote.error.message}`));\n }\n const script = this.#gateScript();\n const begun = !gating || !_RepoLobe.#text(script) ? await this.#begin("commit", this.#committing(message), null) : (\n await this.#gating(message, { script, install: true, gate: true })\n );\n if ("job" in begun) return begun;\n return this.error(begun.code, await this.#undone(begun.message));\n }\n #committing(message) {\n const kept = this.cells.get(["undo"]) ?? null;\n const [executable, paths] = [_RepoLobe.#arg(kept, "executable"), _RepoLobe.#arg(kept, "paths")];\n return {\n message,\n ...executable === void 0 ? {} : { executable },\n ...paths === void 0 ? {} : { paths },\n ...this.#checks()\n };\n }\n async #gating(message, gate) {\n if (!this.#keyed()) return this.#begin("commit", gate, null, { method: "run", more: { gating: message } });\n const more = { running: gate, commits: message };\n return this.#begin("commit", { set: await this.#keys() }, null, { method: "secrets", more });\n }\n async #before(paths) {\n const files = [];\n const stands = new Map();\n const dirs = [];\n for (const path of paths) {\n const read = await this.ask("repos", "read", { path });\n if ("error" in read) {\n if (read.error.code !== "absent") return this.error(read.error.code, `${path}: ${read.error.message}`);\n files.push({ path, was: null });\n } else {\n const was = _RepoLobe.#arg(read.result, "text");\n if (typeof was !== "string") return this.error("refused", `${path}: it holds no text`);\n files.push({ path, was });\n }\n const names = path.split("/");\n for (let at = 1; at < names.length; at += 1) {\n const dir = names.slice(0, at).join("/");\n if (!stands.has(dir)) {\n const parent = at === 1 ? true : stands.get(names.slice(0, at - 1).join("/"));\n const listed = parent ? await this.ask("repos", "list", { path: dir }) : null;\n stands.set(dir, listed !== null && !("error" in listed));\n }\n if (stands.get(dir) === false && !dirs.includes(dir)) dirs.push(dir);\n }\n }\n return { files, dirs };\n }\n async #undone(why) {\n const undo = this.cells.get(["undo"]);\n if (!_RepoLobe.#fields(undo)) return why;\n const [files, dirs] = [undo["files"], undo["dirs"]];\n const lost = [];\n for (const one of Array.isArray(files) ? files : []) {\n const path = _RepoLobe.#arg(one, "path");\n const was = _RepoLobe.#arg(one, "was");\n if (typeof path !== "string") continue;\n const put = typeof was === "string" ? await this.ask("repos", "write", { path, text: was }) : await this.ask("repos", "erase", { path });\n if ("error" in put && !(was === null && put.error.code === "absent")) lost.push(path);\n }\n const made = Array.isArray(dirs) ? dirs.filter((dir) => typeof dir === "string") : [];\n for (const path of made.toReversed()) await this.ask("repos", "erase", { path });\n this.cells.delete(["undo"]);\n if (!Array.isArray(files) || files.length === 0) return why;\n return lost.length === 0 ? `${why.trimEnd()}\nthe files it wrote are put back as they were before the ask` : `${why.trimEnd()}\nthe files it wrote could not all be put back: ${lost.join(", ")}`;\n }\n #commitGate(args) {\n const asked = _RepoLobe.#arg(args, "gate");\n const { commit } = this.#gates();\n if (asked === false && commit === "mandatory")\n return this.error("refused", "the setting on commit is mandatory: no commit skips the gate");\n return asked === true || commit !== "off" && asked !== false;\n }\n async #gated(held, run, code, out, err) {\n const repo = this.#repo();\n if (repo !== null) this.cells.set(["repo"], { ...repo, doing: null });\n const message = _RepoLobe.#shown(held["gating"]);\n const asker = _RepoLobe.#text(held["asker"]) ? held["asker"] : _RepoLobe.#owner;\n const first = _RepoLobe.#arg(held["step"] ?? null, "ran");\n const holds = _RepoLobe.#text(first) ? first : run;\n if (holds !== run) this.cells.delete(["job", run]);\n if (code === 0 || code === 3 && err.includes("holds no script")) {\n const begun = await this.#begin("commit", this.#committing(message), { commit: holds }, { asker });\n if ("job" in begun) return null;\n return this.#commitEnded(holds, 1, "", await this.#undone(`the commit is refused: ${begun.message}`));\n }\n const why = await this.#undone(`the commit is refused: the gate is red\n${_RepoLobe.#last(err)}`);\n await this.#commitEnded(holds, code, _RepoLobe.#last(out), why);\n return null;\n }\n async #commitEnded(run, code, out, err, more = {}) {\n const first = this.cells.get(["job", run]);\n if (!_RepoLobe.#fields(first)) return null;\n const { gating: _, running: __, commits: ___, ...kept } = first;\n this.cells.set(["job", run], { ...kept, ended: { run, code, out, err, ...more, at: this.stamp.time } });\n await this.#ended(kept, code, out, err, more);\n return null;\n }\n status(args) {\n return this.#work("status", args, {});\n }\n log(args) {\n const most = _RepoLobe.#arg(args, "most");\n return this.#work("log", args, most === void 0 ? {} : { most });\n }\n discard(args) {\n return this.#work("discard", args, {});\n }\n async run(args) {\n const script = _RepoLobe.#arg(args, "script");\n const install = _RepoLobe.#arg(args, "install") ?? false;\n const words = _RepoLobe.#argsOf(_RepoLobe.#arg(args, "args"));\n if (!_RepoLobe.#text(script) || !_RepoLobe.#script.test(script))\n return this.error("refused", "a run names a script of the repo\'s package");\n if (typeof install !== "boolean") return this.error("refused", "install is true or false");\n if (words === null)\n return this.error("refused", `a run\'s args are texts, at most ${_RepoLobe.#argsMost}, none holding a NUL`);\n const gate = script === this.#gateScript() ? { gate: true } : {};\n const given = { script, ...words.length === 0 ? {} : { args: words }, install, ...gate };\n const scripts = _RepoLobe.#arg(this.stamp.occupant?.note, "scripts");\n if (this.#role() === "runner" && !(Array.isArray(scripts) && scripts.includes(script)))\n return this.error("refused", `the runner runs ${script} not`);\n return this.#keyed() ? this.#keysFirst("run", args, given) : this.#work("run", args, given);\n }\n static #argsOf(args) {\n if (args === void 0) return [];\n if (!Array.isArray(args) || args.length > _RepoLobe.#argsMost) return null;\n const all = args.flatMap(\n (one) => typeof one === "string" && one.length <= _RepoLobe.#argLongest && !one.includes("\\0") ? [one] : []\n );\n return all.length === args.length ? all : null;\n }\n async #writtenThen(held, run, code, err) {\n const repo = this.#repo();\n if (repo !== null) this.cells.set(["repo"], { ...repo, doing: null });\n const asker = _RepoLobe.#text(held["asker"]) ? held["asker"] : _RepoLobe.#owner;\n const kind = "run";\n const commits = held["kind"] === "commit";\n if (code !== 0) {\n const why = `its secret file was not written: ${err}`;\n if (commits) await this.#commitEnded(run, code, "", await this.#undone(`the commit is refused: ${why}`));\n else await this.#workEnded(run, kind, code, "", why);\n return null;\n }\n if (Object.keys(await this.#keys()).length > 0) this.cells.set(["env"], true);\n else this.cells.delete(["env"]);\n const running = _RepoLobe.#fields(held["running"]) ? held["running"] : {};\n if (commits) {\n const more = { gating: _RepoLobe.#shown(held["commits"]) };\n const gate = await this.#begin("commit", running, { ran: run }, { asker, method: "run", more });\n if ("job" in gate) return null;\n await this.#commitEnded(run, 1, "", await this.#undone(`the commit is refused: ${gate.message}`));\n return null;\n }\n const begun = await this.#begin(kind, running, { ran: run }, { asker });\n if ("job" in begun) return null;\n await this.#workEnded(run, kind, 1, "", `the ${kind} did not begin: ${begun.message}`);\n return null;\n }\n async #workEnded(run, kind, code, out, err, more = {}) {\n const first = this.cells.get(["job", run]);\n if (!_RepoLobe.#fields(first)) return;\n const { running: _, ...kept } = first;\n this.cells.set(["job", run], { ...kept, ended: { run, code, out, err, ...more, at: this.stamp.time } });\n await this.#ended({ ...kept, kind }, code, out, err, more);\n }\n #torn(read) {\n const all = "result" in read && Array.isArray(read.result) ? read.result : [];\n const ends = new Set(all.map((wire) => _RepoLobe.#arg(wire, "termination")));\n for (const { key } of this.#all(["back"])) if (!ends.has(key[1])) this.cells.delete(key);\n }\n async #credentials() {\n if (this.#all(["credential"]).length === 0 && this.#all(["token"]).length === 0) return [];\n const kept = (await this.#relations()).flatMap((one) => {\n const secret = _RepoLobe.#arg(one.note, "credential");\n return one.side === "standing" && _RepoLobe.#text(secret) ? [{ secret, far: one.far, placeholder: one.placeholder }] : [];\n });\n return kept.toSorted((a, b) => _RepoLobe.#order(a.secret, b.secret));\n }\n async setToken(args) {\n const refused = this.#refusal("setToken", {});\n if (refused !== null) return refused;\n const name = _RepoLobe.#arg(args, "name");\n const value = _RepoLobe.#arg(args, "value");\n if (!_RepoLobe.#text(name) || !_RepoLobe.#key.test(name))\n return this.error("refused", "a token\'s name is an environment variable\'s name");\n if (value !== null && (typeof value !== "string" || /[\\n\\r\\0]/.test(value)))\n return this.error("refused", "a token is one line of text, or null to remove it");\n if ((await this.#credentials()).some((one) => one.secret === name))\n return this.error("refused", "a credential keeps that name: drop it");\n if (value !== null && this.cells.get(["secret", name]) === void 0 && this.#all(["secret"]).length >= this.#most())\n return this.error("refused", `a copy keeps ${this.#most()} keys at most`);\n if (value === null) this.cells.delete(["secret", name]);\n else this.cells.set(["secret", name], value);\n return null;\n }\n async #forgo(held) {\n await this.#giveUp(held);\n this.cells.delete(["token", held.far]);\n this.cells.delete(["credential", held.far]);\n return null;\n }\n async #giveUp(held) {\n await this.ask("mouth", "drop", { far: held.far });\n if (_RepoLobe.#text(held.placeholder)) await this.nerves.unwire(held.placeholder);\n }\n async credential(args) {\n const refused = this.#refusal("credential", args);\n if (refused !== null) return refused;\n const secret = _RepoLobe.#arg(args, "secret");\n const invitation = _RepoLobe.#arg(args, "invitation");\n const wired = _RepoLobe.#arg(args, "placeholder");\n if (!_RepoLobe.#text(secret) || !_RepoLobe.#issued.test(secret))\n return this.error(\n "refused",\n "a credential\'s secret is an environment variable\'s name in capitals, its words joined by single underscores"\n );\n const cap = await this.#cap("within", _RepoLobe.#issuerWithin);\n if (typeof cap !== "number") return cap;\n const named = _RepoLobe.#arg(args, "within");\n if (typeof named === "number" && named > cap)\n return this.error(\n "refused",\n `an issuer may keep a credential waiting ${cap} ms at most, a cap an owner\'s word moves`\n );\n const within = typeof named === "number" ? named : cap;\n const held = (await this.#credentials()).find((one) => one.secret === secret);\n if (held !== void 0) {\n if (invitation !== void 0 || wired !== void 0)\n return this.error(\n "refused",\n "a standing keeps that secret already: drop it, or ask again with no invitation and no placeholder"\n );\n return this.#askIssuer(secret, held.far, held.placeholder, "kept", within);\n }\n if (invitation !== void 0 && wired !== void 0)\n return this.error("refused", "a credential is taken by an invitation or by a placeholder, not both");\n if (this.cells.get(["secret", secret]) !== void 0)\n return this.error("refused", "a token keeps that name: remove it by setToken");\n if (_RepoLobe.#text(wired)) return this.#takenOver(secret, wired, within);\n if (!_RepoLobe.#text(invitation)) return this.error("refused", "an invitation or a placeholder is named");\n const placeholder = `credential-${secret.toLowerCase().replaceAll("_", "-")}`;\n const given = _RepoLobe.#arg(args, "note");\n const note = given ?? { repo: this.#repo()?.["name"] ?? null, credential: secret };\n const accepted = await this.ask("mouth", "accept", { invitation, placeholder, note });\n if ("error" in accepted) return this.#result(accepted);\n const far = _RepoLobe.#arg(accepted.result, "far");\n if (!_RepoLobe.#text(far)) return this.error("refused", "the mouth named no far organism");\n const noted = await this.#noted(far, { credential: secret });\n if (noted !== null) {\n await this.#giveUp({ far, placeholder });\n return this.error("refused", noted);\n }\n return this.#askIssuer(secret, far, placeholder, "accepted", within);\n }\n async #takenOver(secret, placeholder, within) {\n const standing = (await this.#relations()).find(\n (one) => one.side === "standing" && one.placeholder === placeholder\n );\n if (standing === void 0) return this.error("refused", `the placeholder ${placeholder} is wired to no standing`);\n if (_RepoLobe.#text(_RepoLobe.#arg(standing.note, "credential")))\n return this.error("refused", "that standing keeps another secret already");\n const noted = await this.#noted(standing.far, { credential: secret });\n if (noted !== null) return this.error("refused", noted);\n return this.#askIssuer(secret, standing.far, placeholder, "wired", within);\n }\n #askAgain(asked, since, within, silent = false) {\n const ready = "result" in asked ? _RepoLobe.#arg(asked.result, "ready") : void 0;\n silent &&= "error" in asked && _RepoLobe.#waits.includes(asked.error.code);\n if (!silent && !(typeof ready === "number" && Number.isSafeInteger(ready))) return null;\n const soonest = this.stamp.time + _RepoLobe.#spell;\n const next = typeof ready === "number" ? Math.max(ready, soonest) : soonest;\n return next <= since + within ? next : null;\n }\n #keptToken(far, cell, result) {\n const value = _RepoLobe.#arg(result, "value");\n const url = _RepoLobe.#arg(result, "url");\n if (!_RepoLobe.#text(value) || /[\\n\\r\\0]/.test(value)) return false;\n this.cells.set(["token", far], value);\n const { failed: _, next: __, expires: ___, renews: ____, since: _____, within: ______, ...rest } = cell;\n const where = _RepoLobe.#text(url) ? { url } : {};\n const expires = _RepoLobe.#arg(result, "expires");\n const life = typeof expires === "number" && Number.isInteger(expires) ? expires - this.stamp.time : 0;\n const ends = life > 0 ? { expires: Number(expires), renews: Number(expires) - Math.floor(life / 10) } : {};\n this.cells.set(["credential", far], { ...rest, pending: false, ...where, ...ends });\n return true;\n }\n #renewedAgain(expires) {\n const left = typeof expires === "number" ? Math.floor((expires - this.stamp.time) / 2) : 0;\n return this.stamp.time + Math.max(_RepoLobe.#minute, left);\n }\n async #renewAt(at, ringing) {\n const set = this.cells.get(["renews"]);\n if (typeof set === "number" && set > this.stamp.time && set <= at) return false;\n this.cells.set(["renews"], at);\n const when = Math.max(at, this.stamp.time + _RepoLobe.#spell);\n if (!ringing) await this.#alarm({ at: when, method: "renew", args: {} });\n return true;\n }\n #nextRenewal() {\n let next = null;\n for (const { value } of this.#all(["credential"])) {\n const renews = _RepoLobe.#arg(value, "renews");\n if (typeof renews !== "number" || _RepoLobe.#arg(value, "pending") === true) continue;\n if (next === null || renews < next) next = renews;\n }\n return next;\n }\n async #askIssuer(secret, far, placeholder, how, within) {\n if (!_RepoLobe.#text(placeholder)) return this.error("refused", "the standing has no relation");\n const cell = this.cells.get(["credential", far]);\n const before = _RepoLobe.#fields(cell) ? cell : {};\n const asked = await this.ask(placeholder, "credential", {});\n const next = this.#askAgain(asked, this.stamp.time, within);\n if (next !== null) {\n this.cells.set(["credential", far], { ...before, pending: true, since: this.stamp.time, within, next });\n const set = await this.#alarm({ at: next, method: "renew", args: {} });\n return "error" in set ? this.#result(set) : { secret, pending: true };\n }\n if (!("error" in asked) && this.#keptToken(far, before, asked.result)) {\n const renews = this.#nextRenewal();\n if (renews !== null) await this.#renewAt(renews, false);\n return { secret };\n }\n if (how === "accepted") await this.#giveUp({ far, placeholder });\n if (how === "wired") await this.#noted(far, null);\n return "error" in asked ? this.error(asked.error.code, asked.error.message) : this.error("refused", "the issuer gave no secret of one line");\n }\n async #renewOne(far, value) {\n const placeholder = (await this.#endOfFar(far))?.placeholder;\n const asked = _RepoLobe.#text(placeholder) ? await this.ask(placeholder, "credential", {}) : { error: { code: "refused", message: "the standing has no relation" } };\n if ("result" in asked && this.#keptToken(far, value, asked.result)) return "given";\n const ready = "result" in asked ? _RepoLobe.#arg(asked.result, "ready") : void 0;\n const cap = typeof ready === "number" ? await this.#cap("within", _RepoLobe.#issuerWithin) : _RepoLobe.#issuerWithin;\n const within = typeof cap === "number" ? cap : _RepoLobe.#issuerWithin;\n const next = this.#askAgain(asked, this.stamp.time, within);\n if (next !== null) {\n this.cells.set(["credential", far], { ...value, pending: true, since: this.stamp.time, within, next });\n return "pending";\n }\n const why = "error" in asked ? asked.error.message : "it gave no secret of one line";\n const failed = `the issuer renewed no secret: ${why}`;\n this.cells.set(["credential", far], { ...value, failed, renews: this.#renewedAgain(value["expires"]) });\n return "failed";\n }\n async #issuedAgain(far, value) {\n const since = typeof value["since"] === "number" ? value["since"] : this.stamp.time;\n const within = typeof value["within"] === "number" ? value["within"] : _RepoLobe.#issuerWithin;\n const placeholder = (await this.#endOfFar(far))?.placeholder;\n const asked = _RepoLobe.#text(placeholder) ? await this.ask(placeholder, "credential", {}) : { error: { code: "refused", message: "the standing has no relation" } };\n const { next: _, ...rest } = value;\n if ("result" in asked && this.#keptToken(far, rest, asked.result)) return "given";\n const next = this.#askAgain(asked, since, within, true);\n if (next !== null) {\n this.cells.set(["credential", far], { ...rest, next });\n return "pending";\n }\n const ready = "result" in asked ? _RepoLobe.#arg(asked.result, "ready") : void 0;\n const why = "error" in asked ? asked.error.message : typeof ready === "number" ? "it is made only after then" : "it gave no secret of one line";\n const failed = `the issuer gave no secret in ${within} ms: ${why}`;\n const again = typeof rest["expires"] === "number" ? { renews: this.#renewedAgain(rest["expires"]) } : {};\n const { since: ___, within: ____, ...left } = rest;\n this.cells.set(["credential", far], { ...left, pending: false, failed, ...again });\n return "failed";\n }\n async renew() {\n let soonest = null;\n const waiting = (far) => {\n const next = _RepoLobe.#arg(this.cells.get(["credential", far]) ?? null, "next");\n if (typeof next === "number" && (soonest === null || next < soonest)) soonest = next;\n };\n for (const { key, value } of this.#all(["credential"])) {\n const far = key[1];\n if (typeof far !== "string" || !_RepoLobe.#fields(value)) continue;\n if (value["pending"] !== true) {\n const renews2 = value["renews"];\n if (typeof renews2 !== "number" || this.stamp.time < renews2) continue;\n if (await this.#renewOne(far, value) === "pending") waiting(far);\n continue;\n }\n if (typeof value["next"] === "number" && this.stamp.time < value["next"]) {\n waiting(far);\n continue;\n }\n if (await this.#issuedAgain(far, value) === "pending") waiting(far);\n }\n if (soonest !== null) return { again: soonest };\n const renews = this.#nextRenewal();\n if (renews === null || !await this.#renewAt(renews, true)) return null;\n return { again: Math.max(renews, this.stamp.time + _RepoLobe.#spell) };\n }\n async #keys() {\n const values = {};\n for (const { key, value } of this.#all(["secret"]))\n if (typeof key[1] === "string" && typeof value === "string") values[key[1]] = value;\n for (const { secret, far } of await this.#credentials()) {\n const token = this.cells.get(["token", far]);\n if (typeof token === "string") values[secret] = token;\n }\n return values;\n }\n #keyed() {\n return this.cells.get(["env"]) !== void 0 || this.#all(["secret"]).length > 0 || this.#all(["token"]).length > 0;\n }\n #masked(text) {\n let shown = text;\n for (const { value } of [...this.#all(["secret"]), ...this.#all(["token"])])\n if (typeof value === "string" && value.length > 0) shown = shown.split(value).join("[secret]");\n return shown;\n }\n async #keysFirst(kind, args, given) {\n const refused = this.#refusal(kind, args);\n if (refused !== null) return refused;\n const ready = this.#ready();\n if (!("name" in ready)) return ready;\n return this.#begin(kind, { set: await this.#keys() }, null, { method: "secrets", more: { running: given } });\n }\n async #work(kind, args, given, begun = {}) {\n const refused = this.#refusal(kind, args);\n if (refused !== null) return refused;\n const ready = this.#ready();\n if (!("name" in ready)) return ready;\n return this.#begin(kind, given, null, begun);\n }\n async read(args) {\n const refused = this.#refusal("read", args);\n if (refused !== null) return refused;\n const paths = _RepoLobe.#arg(args, "paths");\n if (paths !== void 0) {\n const lone = _RepoLobe.#arg(args, "path") === void 0 && _RepoLobe.#arg(args, "first") === void 0;\n if (!lone || !Array.isArray(paths) || paths.length < 1)\n return this.error("refused", "paths are one file or more, without path or first");\n return this.#result(await this.ask("repos", "read", { paths }));\n }\n const first = _RepoLobe.#arg(args, "first");\n const path = _RepoLobe.#arg(args, "path") ?? null;\n return this.#result(await this.ask("repos", "read", first === void 0 ? { path } : { path, first }));\n }\n async list(args) {\n const refused = this.#refusal("list", args);\n if (refused !== null) return refused;\n const path = _RepoLobe.#arg(args, "path");\n return this.#result(await this.ask("repos", "list", path === void 0 ? {} : { path }));\n }\n async stop(args) {\n const refused = this.#refusal("stop", args);\n if (refused !== null) return refused;\n const doing = this.#repo()?.["doing"];\n const held = _RepoLobe.#text(doing) ? this.cells.get(["job", doing]) : void 0;\n const sync = this.cells.get(["sync"]);\n if (_RepoLobe.#fields(sync)) {\n const kind = _RepoLobe.#shown(sync["kind"]);\n if (this.stamp.asker !== _RepoLobe.#owner && sync["asker"] !== this.stamp.asker)\n return this.error("refused", `the repo runs another\'s ${kind}`);\n const step = _RepoLobe.#arg(held ?? null, "step");\n const own = _RepoLobe.#arg(step ?? null, "sync") === true;\n if (own && _RepoLobe.#arg(held ?? null, "kind") === "land")\n return this.error("refused", `the ${kind} lands already: it ends once landed`);\n if (own && _RepoLobe.#text(doing) && _RepoLobe.#fields(held))\n this.cells.set(["job", doing], { ...held, step: { stopped: true } });\n await this.#finish(sync, 1, `the ${kind} was stopped`);\n return null;\n }\n if (!_RepoLobe.#text(doing)) return this.error("refused", "the repo runs nothing");\n const asker = _RepoLobe.#arg(held, "asker");\n if (this.stamp.asker !== _RepoLobe.#owner && asker !== this.stamp.asker)\n return this.error("refused", "the repo runs another\'s job");\n return this.#heard(await this.ask("repos", "stop", {}));\n }\n pull(args) {\n return this.#sync("pull", args);\n }\n push(args) {\n return this.#sync("push", args);\n }\n async #sync(kind, args) {\n const refused = this.#refusal(kind, args);\n if (refused !== null) return refused;\n const ready = this.#ready();\n if (!("name" in ready)) return ready;\n const tag = _RepoLobe.#arg(args, "tag");\n if (tag !== void 0 && !(kind === "pull" && _RepoLobe.#text(tag) && _RepoLobe.#tag.test(tag)))\n return this.error("refused", "a pull names a tag, v and three whole numbers; a push names none");\n if (this.cells.get(["sync"]) !== void 0 && !await this.#stalled())\n return this.error("refused", "the repo pulls or pushes already");\n const on = await this.#standingOn(_RepoLobe.#arg(args, "on"));\n if (!("far" in on)) return on;\n const piece = _RepoLobe.#arg(args, "piece");\n const still = _RepoLobe.#arg(args, "still");\n return this.#start(kind, this.stamp.asker, _RepoLobe.#shown(on["placeholder"]), {\n ...typeof tag === "string" ? { tag } : {},\n ...typeof piece === "number" ? { piece } : {},\n ...typeof still === "number" ? { still } : {},\n ..._RepoLobe.#arg(args, "tells") === true ? { tells: true } : {}\n });\n }\n async #stalled() {\n const sync = this.cells.get(["sync"]);\n return _RepoLobe.#fields(sync) && [..._RepoLobe.#syncFar, "headed"].includes(_RepoLobe.#shown(sync["stage"])) && await this.#stood(sync);\n }\n async #start(kind, asker, on, named = {}) {\n const cap = await this.#cap("still", _RepoLobe.#still);\n if (typeof cap !== "number") return cap;\n const still = named["still"];\n if (typeof still === "number" && still > cap)\n return this.error("refused", `a ${kind} may stand still ${cap} ms at most, a cap an owner\'s word moves`);\n const capped = still === void 0 && cap !== _RepoLobe.#still ? { still: cap } : {};\n const back = await this.#back(asker);\n if (back !== null) return back;\n const job = `${kind}-${this.#nonce()}`;\n const stage = kind === "pull" ? "asking" : "heading";\n const chain = this.#nonce();\n const sync = { job, kind, chain, asker, on, stage, at: 0, pieces: null, moved: this.stamp.time };\n this.cells.set(["sync"], { ...sync, ...named, ...capped });\n const set = await this.#alarm({ at: this.stamp.time, method: "tick", args: { chain } });\n return "error" in set ? this.error(set.error.code, set.error.message) : { job };\n }\n async #cap(name, otherwise) {\n const word = await this.ask("nerves", "limit", { name });\n if ("error" in word) return this.error(word.error.code, word.error.message);\n return typeof word.result === "number" ? Math.min(word.result, _RepoLobe.#lifted) : otherwise;\n }\n async #rung(before) {\n const sync = this.cells.get(["sync"]);\n if (!_RepoLobe.#fields(sync) || !_RepoLobe.#fields(before) || !_RepoLobe.#moved(before, sync)) return;\n const chain = this.#nonce();\n const set = await this.#alarm({ at: this.stamp.time, method: "tick", args: { chain } });\n this.cells.set(["sync"], { ...sync, moved: this.stamp.time, ..."error" in set ? {} : { chain } });\n }\n static #moved(before, after) {\n return after["stage"] !== before["stage"] || after["at"] !== before["at"];\n }\n static #askerOf(sync) {\n return _RepoLobe.#text(sync["asker"]) ? sync["asker"] : _RepoLobe.#owner;\n }\n static #of(sync) {\n return { asker: _RepoLobe.#askerOf(sync) };\n }\n async tick(args) {\n const sync = this.cells.get(["sync"]);\n if (!_RepoLobe.#fields(sync) || sync["chain"] !== _RepoLobe.#arg(args, "chain")) return null;\n const over = sync["on"];\n if (!_RepoLobe.#text(over)) {\n await this.#finish(sync, 1, "the lobe stands on that lobe no more");\n return null;\n }\n const far = _RepoLobe.#syncFar.includes(_RepoLobe.#shown(sync["stage"]));\n if (far && await this.#stood(sync)) return null;\n if (sync["stage"] === "waiting" && _RepoLobe.#text(sync["tells"])) return { again: _RepoLobe.#stillEnds(sync) };\n if (far) await this.#step(sync, over);\n else if (sync["stage"] === "headed") await this.#bundling(sync);\n else await this.#check();\n const kept = this.cells.get(["sync"]);\n if (!_RepoLobe.#fields(kept)) return null;\n if (_RepoLobe.#moved(sync, kept)) return { again: this.stamp.time };\n return { again: this.stamp.time + (far || kept["stage"] === "headed" ? _RepoLobe.#every : MINUTE) };\n }\n static #syncFar = ["asking", "getting", "heading", "sending", "waiting"];\n async #step(sync, over) {\n const { stage } = sync;\n if (stage === "asking") await this.#asking(sync, over);\n else if (stage === "getting") await this.#getting(sync, over);\n else if (stage === "heading") await this.#heading(sync, over);\n else if (stage === "sending") await this.#sending(sync, over);\n else if (stage === "waiting") await this.#waiting(sync, over);\n }\n #synced(next) {\n const { waits: _, ...rest } = next;\n this.cells.set(["sync"], { ...rest, moved: this.stamp.time });\n }\n async #asking(sync, over) {\n const repo = this.#repo() ?? {};\n const tag = _RepoLobe.#text(sync["tag"]) ? { tag: sync["tag"] } : {};\n const piece = typeof sync["piece"] === "number" ? { piece: sync["piece"] } : {};\n const asked = await this.ask(over, "give", { since: repo["head"] ?? null, ...tag, ...piece });\n if ("error" in asked) return this.#failedOr(sync, "give", asked.error);\n const { pieces, head, scope } = _RepoLobe.#fields(asked.result) ? asked.result : {};\n if (typeof pieces !== "number") return this.#heardOf(sync);\n if (Array.isArray(scope) && !this.#holdsScope()) {\n if (!_RepoLobe.#text(repo["head"]) && !_RepoLobe.#text(repo["rebuilds"])) {\n const standing = (await this.#held()).find((one) => one.placeholder === sync["on"]);\n const noted = standing === void 0 ? null : await this.#noted(standing.far, { scope: _RepoLobe.#texts(scope) });\n if (noted !== null) return this.#finish(sync, 1, `the scope was not noted: ${noted}`);\n this.cells.set(["repo"], { ...repo, cut: true });\n } else\n return this.#finish(sync, 1, "a scope is held from a lobe’s birth alone, and this lobe holds the repo whole");\n }\n if (pieces === 0) return this.#finish(sync, 0, "");\n this.#synced({ ...sync, stage: "getting", at: 0, pieces, theirs: head ?? null });\n return void 0;\n }\n async #getting(sync, over) {\n const { at, pieces } = sync;\n if (typeof at !== "number" || typeof pieces !== "number") return;\n const asked = await this.ask(over, "piece", { at });\n if ("error" in asked) return this.#failedOr(sync, "piece", asked.error);\n const bytes = _RepoLobe.#arg(asked.result, "bytes");\n if (!(bytes instanceof Uint8Array)) return;\n const put = await this.ask("repos", "put", { at, pieces, bytes, as: "pull" });\n if ("error" in put) return;\n if (at + 1 < pieces) return this.#synced({ ...sync, at: at + 1 });\n const begun = await this.#begin("bring", { as: "pull", pieces }, { sync: true }, _RepoLobe.#of(sync));\n if ("job" in begun) this.#synced({ ...sync, at: pieces, stage: "bringing" });\n else if (!_RepoLobe.#transient(begun.message)) await this.#finish(sync, 1, begun.message);\n }\n async #heading(sync, over) {\n const asked = await this.ask(over, "head", {});\n if ("error" in asked) return this.#failedOr(sync, "head", asked.error);\n const theirs = _RepoLobe.#arg(asked.result, "head") ?? null;\n this.#synced({ ...sync, stage: "headed", theirs: typeof theirs === "string" ? theirs : null });\n }\n async #bundling(sync) {\n const theirs = sync["theirs"];\n const since = typeof theirs === "string" ? theirs : null;\n const piece = typeof sync["piece"] === "number" ? { piece: sync["piece"] } : {};\n const begun = await this.#begin("bundle", { since, as: "push", ...piece }, { sync: true }, _RepoLobe.#of(sync));\n if ("job" in begun) this.#synced({ ...sync, stage: "bundling", theirs: since });\n else if (_RepoLobe.#transient(begun.message) || begun.code === "timeout") this.#heardOf(sync);\n else\n await this.#finish(\n sync,\n 1,\n since === null ? begun.message : `the lobe pushed to holds commits this one does not (${since}): pull first; the jailer said: ${begun.message}`\n );\n }\n async #backOf(sync) {\n const on = _RepoLobe.#shown(sync["on"]);\n await this.#untell(on);\n const waits = typeof sync["still"] === "number" ? sync["still"] : _RepoLobe.#still;\n const note = { repo: this.#repo()?.["name"] ?? null, standing: _RepoLobe.#teller, on };\n const invited = await this.ask("ear", "invite", { waits, lives: null, note });\n if ("error" in invited)\n return this.error(invited.error.code, `no standing back was drawn: ${invited.error.message}`);\n const invitation = _RepoLobe.#arg(invited.result, "invitation");\n return _RepoLobe.#text(invitation) ? invitation : this.error("refused", "the ear drew no invitation back");\n }\n static #transient(message) {\n return message.endsWith(" being cleared") || /^the repo runs .* already$/.test(message) || message === "the lobe keeps no repo";\n }\n async #sending(sync, over) {\n const { job, at, pieces } = sync;\n if (!_RepoLobe.#text(job) || typeof at !== "number" || typeof pieces !== "number") return;\n const sending = at === 0 && sync["tells"] === true ? await this.#drawn(sync) : sync;\n if (sending === null) return;\n const read = await this.ask("repos", "piece", { at, as: "push" });\n const bytes = "result" in read ? _RepoLobe.#arg(read.result, "bytes") : void 0;\n if (!(bytes instanceof Uint8Array)) return;\n const tells = at === 0 && _RepoLobe.#text(sending["tells"]) ? { tells: sending["tells"] } : {};\n const asked = await this.ask(over, "take", { push: job, at, pieces, bytes, ...tells });\n if ("error" in asked) return this.#failedOr(sending, "take", asked.error);\n this.#synced({ ...sending, at: at + 1, ...at + 1 === pieces ? { stage: "waiting" } : {} });\n }\n async #drawn(sync) {\n const tells = await this.#backOf(sync);\n if (typeof tells !== "string") {\n await this.#finish(sync, 1, tells.message);\n return null;\n }\n const drawn = { ...sync, tells };\n this.cells.set(["sync"], drawn);\n return drawn;\n }\n async #told(args) {\n const sync = this.cells.get(["sync"]);\n const on = _RepoLobe.#arg(this.stamp.occupant?.note ?? null, "on");\n const { job, code, err } = _RepoLobe.#fields(args) ? args : {};\n if (!_RepoLobe.#fields(sync) || sync["kind"] !== "push" || sync["stage"] !== "waiting" || sync["on"] !== on || sync["job"] !== job || typeof code !== "number" || typeof err !== "string")\n return this.error("refused", "no such push waits on its end");\n await this.#endHeard(sync, code, err, _RepoLobe.#arg(args, "check") ?? null);\n return null;\n }\n async #endHeard(sync, code, err, check) {\n await this.#finish(sync, code === 0 ? 0 : 1, code === 0 ? "" : err, check === null ? void 0 : check);\n }\n async #waiting(sync, over) {\n const asked = await this.ask(over, "taken", {});\n if ("error" in asked) return this.#failedOr(sync, "taken", asked.error);\n const { code, err, check } = _RepoLobe.#fields(asked.result) ? asked.result : {};\n if (typeof code !== "number" || typeof err !== "string") return this.#heardOf(sync);\n return this.#endHeard(sync, code, err, check ?? null);\n }\n #heardOf(sync) {\n if (sync["waits"] === void 0) return;\n const { waits: _, ...rest } = sync;\n this.cells.set(["sync"], rest);\n }\n async #failedOr(sync, method, error) {\n if (_RepoLobe.#waits.includes(error.code)) return this.#waited(method, error, sync);\n await this.#finish(sync, 1, error.message);\n }\n static #left(kind, stage) {\n if (kind === "push") return stage === "heading" || stage === "headed" ? null : "push";\n return kind === "pull" && stage === "getting" ? "pull" : null;\n }\n async #finish(sync, code, err, check) {\n await this.#finished(sync, code, err, check);\n await this.#owing();\n }\n async #finished(sync, code, err, check) {\n this.cells.delete(["sync"]);\n const { asker, job, kind } = sync;\n const left = _RepoLobe.#left(kind, sync["stage"]);\n if (left !== null) await this.#clear(left);\n const repo = this.#repo();\n const checked = check === void 0 ? {} : { check };\n const synced = { job: job ?? null, kind: kind ?? null, asker: asker ?? null, code, err, ...checked };\n if (repo !== null) this.cells.set(["repo"], { ...repo, synced });\n const out = repo !== null && _RepoLobe.#text(repo["head"]) ? `${repo["head"]}\n` : "";\n const of = sync["of"];\n const init = _RepoLobe.#text(of) ? this.cells.get(["job", of]) : void 0;\n if (_RepoLobe.#text(of) && _RepoLobe.#fields(init) && init["ended"] === null)\n return this.#closed(of, init, code, out, err, checked);\n if (!_RepoLobe.#text(asker) || asker === _RepoLobe.#owner) return;\n const told = { job: job ?? null, kind: kind ?? null, code, out, err, ...checked };\n await this.ask(asker, "done", told, void 0, { letter: { lives: _RepoLobe.#lives } });\n }\n #waited(method, error, next) {\n const kept = this.cells.get(["sync"]);\n const why = `${method}: ${error.code}: ${error.message}`;\n const since = _RepoLobe.#arg(_RepoLobe.#arg(kept, "waits"), "since");\n const waits = { why, since: typeof since === "number" ? since : this.stamp.time };\n this.cells.set(["sync"], { ...next, waits });\n }\n static #stillOn(held) {\n return `its stage ${_RepoLobe.#shown(held["stage"])}, piece ${JSON.stringify(held["at"] ?? null)} of ${JSON.stringify(held["pieces"] ?? null)}`;\n }\n static #stillEnds(held) {\n const moved = typeof held["moved"] === "number" ? held["moved"] : 0;\n return moved + (typeof held["still"] === "number" ? held["still"] : _RepoLobe.#still) + 1;\n }\n async #stood(held) {\n const moved = held["moved"];\n const span = typeof held["still"] === "number" ? held["still"] : _RepoLobe.#still;\n if (typeof moved !== "number" || this.stamp.time - moved <= span) return false;\n if (held["stage"] === "waiting" && _RepoLobe.#text(held["tells"]) && _RepoLobe.#text(held["on"])) {\n await this.#waiting(held, held["on"]);\n if (this.cells.get(["sync"]) === void 0) return true;\n }\n const why = _RepoLobe.#arg(held["waits"], "why");\n const last = _RepoLobe.#text(why) ? `; its last ask ${why}` : "";\n const still = `moved not for ${span} ms: ${_RepoLobe.#stillOn(held)}${last}`;\n await this.#finish(held, 1, `the ${_RepoLobe.#shown(held["kind"])} ${still}`);\n return true;\n }\n};\nexport {\n RepoLobe as default\n};\n';
1244
1244
 
1245
1245
  var REPO = { faculty: REPO_SOURCE, label: "repo" };
1246
1246
  export {