gitoria
All repositories: gitoria
13.5 KB
// hl:core/AST — WHAT A FILE READS AND WHAT IT WRITES, from the compiler's own AST.//// The language has always been able to hand a caller the SYNTAX of a node// (`hlSyntax`) and the list of members a file declares (`hlMembers`). What it// never answered is what that syntax DOES with names: which members an// expression reads, which members a handler writes. Every consumer that needed// it wrote its own walk — hl:web's tree builder decides per tag what counts as// a read, and its browser half rediscovers the same set at runtime by walking// the DOM against the tree and JSON-comparing state afterwards (FRAMEWORK_AUDIT// §3). Two copies of one answer drift, and neither could see a write at all.//// The answer is the language's, so it lives here. `query(file)` is a table of// one file's (and, recursively, its project's) members, derivations, handlers// and methods, each with the names it reads and the names it writes, every node// carrying a stable site id `file:line:col`.//// NOTHING HERE KNOWS WHAT A VIEW IS. There is no attr, text, region, key or// component vocabulary in this file and none in the runtime rule beneath it: a// member is a member. A caller that wants one member's answer — hl:web wants// `View`'s — passes that member's NAME as the filter. That is the only way to// narrow the query, and it is a name, not a concept.//// import { query } from 'hl:core/AST'// let q = query('components/home.hl') // recursive, every member// let v = query('components/home.hl', true, 'View')//// THE GENERATION. Reflection reads a parse that is valid until the next// analysis; this package runs one of its own (`hlProject()`) the first time it// is asked and keeps the handle. `refresh()` runs a new one — a dev reload, or// a caller that changed a file. A static cannot be reassigned, so the handle// lives in a static hybrid, which can.static state = { gen = 0; graph = null; }// The live analysis generation, started on first use.static analysis = () => {if (state.gen == 0) {let g = hlProject()state.graph = gstate.gen = g.analysisGen}return state.gen}// A NEW ANALYSIS: the parses this package answers from are replaced, and every// handle a caller still holds from the old one is refused by the language.static refresh = () => {let g = hlProject()state.graph = gstate.gen = g.analysisGenreturn state.gen}// …of a project this run did not boot: a directory, a manifest, or an entry// file. The keys every answer below is filed under are that project's.static analyseFrom = (path) => {let g = hlProject(path)state.graph = gstate.gen = g.analysisGenreturn state.gen}// The project graph the generation belongs to (`hlProject()`'s answer).static project = () => {analysis()return state.graph}// ---- the reflection surface, without the generation argument ------------------// `hlSyntax` and `hlMembers` are the ambient names the framework still calls;// here they are statics of a package, which is where they belong.static syntax = (file, node) => { return hlSyntax(analysis(), file, node) }static members = (file) => { return hlMembers(analysis(), file) }static methods = (file) => { return hlMethods(analysis(), file) }static handlers = (file) => { return hlEvents(analysis(), file).handles }static denotes = (file, name) => { return hlDenotes(analysis(), file, name) }static file = (file) => { return hlFile(analysis(), file) }// ---- the syntax of one node, as a tree ----------------------------------------// Every node carries its tag, its site id and the two answers the language gives// for it: the free names it READS and the names it WRITES. The shape below is// the shape `hlSyntax` returns, followed one child at a time — there is no// interpretation of any tag, only its children.//// AN `on` HANDLER IS A LEAF HERE ON PURPOSE. Its body is not evaluated by the// literal that carries it, so the names inside are the HANDLER's reads and// writes, not the literal's; the node answers for them and the walk stops.static tree = (file, node) => {let n = hlSyntax(analysis(), file, node)if (n == null) { return null }let out = { tag = n.tag; site = n.site; line = n.line; col = n.col; reads = n.reads; writes = n.writes; }if (n.tag == 'object_expression') {let kids = []for (h of n.entries) { kids.push(tree(file, h)) }out.entries = kids} else if (n.tag == 'object_property') {out.key = n.keyout.value = tree(file, n.value)} else if (n.tag == 'view_for') {// A `for` ENTRY NAMES ITS LIST AND ITS ROW VARIABLE. The list is read in// the scope standing around the `for`; the row variable is bound inside// the body and every read of it there resolves as kind 'row'.out.row = n.varNameout.list = tree(file, n.list)out.body = tree(file, n.body)} else if (n.tag == 'view_if') {out.condition = tree(file, n.condition)out.consequent = tree(file, n.consequent)out.alternate = tree(file, n.alternate)} else if (n.tag == 'on_statement') {out.event = n.eventout.scope = n.scopeout.realm = n.realmout.handler = n.handler} else if (n.tag == 'identifier' || n.tag == 'new_expression') {out.name = n.name} else if (n.tag == 'literal') {out.kind = n.kindout.text = n.text} else if (n.tag == 'member_expression') {out.object = tree(file, n.object)out.property = tree(file, n.property)out.computed = n.computed} else if (n.tag == 'call_expression') {out.callee = tree(file, n.callee)let args = []for (h of n.args) { args.push(tree(file, h)) }out.args = args} else if (n.tag == 'binary_expression') {out.operator = n.operatorout.left = tree(file, n.left)out.right = tree(file, n.right)} else if (n.tag == 'unary_expression') {out.operator = n.operatorout.operand = tree(file, n.operand)} else if (n.tag == 'conditional_expression') {out.condition = tree(file, n.condition)out.consequent = tree(file, n.consequent)out.alternate = tree(file, n.alternate)} else if (n.tag == 'array_expression') {let els = []for (h of n.elements) { els.push(tree(file, h)) }out.elements = els}return out}// ---- names ---------------------------------------------------------------------// A read or a write is `{ name, kind, isStatic, path?, key? }`. `kind` is the// language's own resolution of the bare name: 'member', 'method', 'handler',// 'class' (a default import), 'import' (a braced one), 'plugin', 'row' (bound by// an enclosing `for` entry), 'local' (a lambda, handler or method parameter, or// a `let`), 'none' (nothing this file declares — an ambient or a typo).// the names of a read/write list, as plain stringsstatic namesOf = (list) => {let out = []for (r of list) { if (!out.includes(r.name)) { out.push(r.name) } }return out}// the subset of a read/write list that resolves to a member of the file itselfstatic membersOf = (list) => {let out = []for (r of list) {if (r.kind == 'member' && !r.isStatic && !out.includes(r.name)) { out.push(r.name) }}return out}// ---- one file's answer ---------------------------------------------------------// every `on` node inside a member's syntax tree, flattened, each at its sitestatic nestedHandlers = (member, node, &into) => {if (node == null) { return into }if (node.tag == 'on_statement') {into.push({ member = member; event = node.event; scope = node.scope; realm = node.realm; site = node.site; reads = node.reads; writes = node.writes; nested = true; })return into}if (node.entries != null) { for (c of node.entries) { nestedHandlers(member, c, into) } }if (node.args != null) { for (c of node.args) { nestedHandlers(member, c, into) } }if (node.elements != null) { for (c of node.elements) { nestedHandlers(member, c, into) } }if (node.value != null) { nestedHandlers(member, node.value, into) }if (node.list != null) { nestedHandlers(member, node.list, into) }if (node.body != null) { nestedHandlers(member, node.body, into) }if (node.condition != null) { nestedHandlers(member, node.condition, into) }if (node.consequent != null) { nestedHandlers(member, node.consequent, into) }if (node.alternate != null) { nestedHandlers(member, node.alternate, into) }if (node.object != null) { nestedHandlers(member, node.object, into) }if (node.property != null) { nestedHandlers(member, node.property, into) }if (node.callee != null) { nestedHandlers(member, node.callee, into) }if (node.left != null) { nestedHandlers(member, node.left, into) }if (node.right != null) { nestedHandlers(member, node.right, into) }if (node.operand != null) { nestedHandlers(member, node.operand, into) }return into}static one = (key, member) => {let gen = analysis()let f = hlFile(gen, key)let out = { key = key; class = f.class; members = []; derivations = []; handlers = []; methods = []; reaches = []; }for (m of hlMembers(gen, key)) {// (Hybriel has no `continue`: the body is guarded instead.)if (member == null || m.name == member) {let entry = { name = m.name; type = m.type; mandatory = m.mandatory; isStatic = m.isStatic; site = key + ':' + m.line + ':' + m.col; default = null; reads = []; writes = []; syntax = null; }if (m.hasValue) {let n = hlSyntax(gen, key, m.node)entry.default = n.siteentry.reads = n.readsentry.writes = n.writesentry.syntax = tree(key, m.node)// A DERIVATION IS AN INITIALIZER READ THE OTHER WAY: the same table,// listed by the names the value depends on.out.derivations.push({ name = m.name; site = n.site; reads = n.reads; })nestedHandlers(m.name, entry.syntax, out.handlers)for (r of n.reads) {if (r.kind == 'class' && r.key != null && !out.reaches.includes(r.key)) { out.reaches.push(r.key) }}}out.members.push(entry)}}// The DECLARED handlers and methods answer for their whole body. A member// filter narrows the member table only — a handler is not a member, and// hiding the writes would make the filtered answer a lie about the file.for (h of hlEvents(gen, key).handles) {let n = hlSyntax(gen, key, h.node)out.handlers.push({ member = null; event = h.event; scope = h.scope; realm = h.realm; params = h.params; site = n.site; reads = n.reads; writes = n.writes; nested = false; })}for (mm of hlMethods(gen, key)) {// A literal's inline `on` is hoisted as a method over the SAME body// (parser `inlineHandlerEntry`); it already answered at its site above.if (!mm.inlineHandler) {let n = hlSyntax(gen, key, mm.node)out.methods.push({ name = mm.name; params = mm.params; site = n.site; reads = n.reads; writes = n.writes; })}}// WHAT THIS FILE REACHES: every import the language resolved to another file// of the project, and every composed reference a member's syntax read.if (state.graph.files[key] != null) {for (imp of state.graph.files[key].imports) {if (imp.key != null && !out.reaches.includes(imp.key)) { out.reaches.push(imp.key) }}}if (f.wrapper != null && !out.reaches.includes(f.wrapper)) { out.reaches.push(f.wrapper) }for (k of f.inherits) { if (!out.reaches.includes(k)) { out.reaches.push(k) } }return out}// ---- the query -----------------------------------------------------------------// `query(file, recursive = true, member = null)`:// files — one answer per file reached, keyed by the analysis key// order — the keys in the order they were reached, `file` first// Recursive follows what each file reaches (its imports, its wrapper, what it// inherits, and the composed references its members read), each file once.static query = (file, recursive, member) => {let rec = recursive == null ? true : recursivelet want = member == null ? null : memberanalysis()let out = { root = file; files = {}; order = []; }let queue = [file]let seen = {}while (queue.length > 0) {let key = queue.shift()if (seen[key] == null) {seen[key] = true// A key the analysis does not hold is not this package's to parse —// the root is answered regardless, because the caller named it.if (state.graph.files[key] != null || key == file) {let answer = one(key, want)out.files[key] = answerout.order.push(key)if (rec) {for (k of answer.reaches) { if (seen[k] == null) { queue.push(k) } }}}}}return out}// EVERY FILE THE ANALYSIS HOLDS, once. A project's root reaches nearly all of// them; this reaches the rest too, which is what a whole-project report wants.static queryAll = (member) => {analysis()let out = { root = null; files = {}; order = []; }for (k of state.graph.files.keys()) {out.files[k] = one(k, member)out.order.push(k)}return out}// ---- what `hybriel --graph` carries, per file -----------------------------------// THE ONE DOCUMENT ASKS THIS PACKAGE (creator, 2026-09-14: the language scans// EVERYTHING by default and a filter only narrows). `--graph` prints the// language graph, and every file record in it carries the four tables below —// the same objects `query()` puts in `files[key]`, handed to the writer as they// are. There is no second walk and no second rendering: a person reads that// JSON, and a program imports `query` and gets the same answer as values.// `trees == false` (`--graph --no-ast`) leaves each member's syntax tree out —// `syntax` is null, every other field is the same bytes. null or true keeps it.static tables = (path, member, trees) => {if (path == null) { analysis() } else { analyseFrom(path) }let q = queryAll(member)let out = {}for (k of q.order) {let f = q.files[k]if (trees == false) { for (m of f.members) { m.syntax = null } }out[k] = { members = f.members; derivations = f.derivations; methods = f.methods; handlers = f.handlers; }}return out}
Branches
- f1-broken-json
- f2-api-bugs
- gp-gate-ports
- heap-revert
- hl25-records
- ident-chooser-selector
- mainmain branch
- p51-public-pr-reads
- records-1112
- s25-no-session-on-login-error
- v59
- w52-person-approval
- w52b-approval-followup
- w52c-header-phone
- w53-pulls-speed-pr
- w54-repo-rename-pr
- w55-rename-org
- w56-owner-members
- w62-pr-close
- w63-force-push
- w64-org-slash
Latest commits
- a0727ca3ident#31: the selector's sign-in returns to the page the user started on (return attribute = the login callback with next), gate checkmre
- a06975f9gitoria: a gap between your name and Log out in the phone header (they touched); gate checks itmre
- 32ba9d59gitoria: leave the host-only cookie experiment out of the browser gate (gitoria#24 is a separate mission)mre
- 43ad2bcfgitoria header: the selector alone plus your name and Log out as before the theme missions; tests follow (WIP: host-only cookie experiment fails)mre
- ac2c4e3fident selector back in the header (creator 2026-10-24): selector top right signed in and out on phone and desktop, no second Log in button, new gate checks (WIP: gates not re-run after the last edits)mre
- b279f536theme: sync from layouts 4994037 (list rows stack, td word-keep, heading code, edited tap target)mre
- 2b01515ctests/ticketskit: a failed start kills the tickets server (own process group); stop() kills the groupmre
- 109cfc5ctests/ticketskit: keep the rotated session cookie of the tickets login (tickets ST2 session rotation)mre
- 7eb6be27sessions last 99 years (creator 2026-10-23: logins never expire; only sign out ends them)mre
- b3911918reports/MG-mobile.md: 404 fixed, rebased gatesMG
- 9da65b42tests/browser.mjs: 404 checks (host, no hydration wait)MG
- 00517fafgitoria: shell 404 page for unknown paths (catch-all route, status 404, JSON 404 under /api), 390 gate checksMG
- d9e977f0reports/MG-mobile.md, LOGMG
- 2f2725actests/browser.mjs: commit-row check (one row, centred date)MG
- 4df1ea01tests/browser.mjs: MG phone checks (list first, no dead strip, one branch heading, tab grid, commit rows, PR title row, ticket columns, wrapping commands)MG
- c52424e9gitoria mobile: repo list before the forms, 3x2 tab grid, no duplicate branch heading, ordered commit rows, aligned ticket rows, pull title on its own row, wrapping clone commands, no dead strip under formsMG
- 3a95252dG3: cache parsed README blocks by sha256 of the text (bounded LRU), reportmre
- 570138cddeploy: security gate (tests/security.mjs)mre
- da6b20fcgitoria SG: security audit fixes (uploadMax 0, Secure cookie on https, session rotation at login, nosniff on function routes, no identity in page data) + tests/security.mjs gate + reportmre
- f98c981fgitoria B1: report wordingmre