code wiki / (root) / nx_office_serve.nx

nx_office_serve.nx

buildroot/runtime/nx_office_serve.nx

197925 B3109 linesdepth 7pulls 15 transitivereach 3 importersview sourcekind librarytopic office
docsdependenciesstructsconstsfunctions

about

nx_office_serve.nx -- NISHI OFFICE v1, the PRODUCT surface over the gated format organs (operator 2026-07-09: "we need to build our own nishi office"). Until now the suite was organs + scattered sample pages; THIS organ is the office: a zero-JS web app where a family member CREATES, EDITS, VERSIONS, PREVIEWS and DOWNLOADS real documents / spreadsheets / decks. Every save = a NEW version (v1,v2,...) -- nothing is ever overwritten; that additive never-lose history is the suite's one measured exceed, now surfaced as the product spine. Engines (forked ELFs, the gated organs): doc = _offc/nx_docx.elf writerich (H/B/I/P + T pipe-cells) ? sheet = _offc/nx_xlsx.elf fromtsv (TSV grid, =SUM/AVERAGE/MIN/MAX/COUNT formulas) ? deck = _offc/nx_pptx.elf fromspec (S title / B bullet). Preview = each organ's own html mode. Honest v1 scope: SPEC editors (plain textarea round-trip), NOT WYSIWYG -- that is the named next rung, along with co-edit (CRDT) and in-app AI. Layout under <root>/: index.txt (append-only name\tkind registry) + <name>/manifest.txt (append-only v<N>\t<kind>\t<usec> lines) + <name>/v<N>/{spec.txt, file.<ext>, preview.html}. PURE CORE (no main): of_handle (request -> response), of_read_req/of_write_all (fd shells), of_selftest (the offline gate body). Consumers: _hdl_build/nx_office_gate (offline gate) + _hdl_build/nx_office_daemon (accept loop, port 8030). Same discipline as nx_relate_serve. license_tier: ORIGINAL

dependencies 5 imports · 3 importers

nx_tool_run.nx nx_connect.nx nx_itoa_lib.nx nx_rebac.nx nx_http_client.nx nx_office_serve.nx nx_office_daemon.nx nx_office_gate.nx nx_office_snapshot.nx

imports: nx_tool_run.nxnx_connect.nxnx_itoa_lib.nxnx_rebac.nxnx_http_client.nx

imported by: nx_office_daemon.nxnx_office_gate.nxnx_office_snapshot.nx

structs

none

consts

25const OF_AUTHZ: *u8 = "officeauthz_"
26const OF_RELATE: *u8 = "knowledge/status/relate_"

functions

28func p(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
31func pn(v: i64) -> i64 { nxi_out(v); return 0 }
calls 1: nxi_out
32func of_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
33func of_cat(dst: *u8, off: i64, s: *u8) -> i64 { var i: i64 = 0; while s[i] != (0 as u8) { dst[off+i] = s[i]; i = i + 1 } return off + i }
34func of_catc(dst: *u8, off: i64, code: i64) -> i64 { dst[off] = code as u8; return off + 1 }
39func of_catn(dst: *u8, off: i64, v: i64) -> i64 { return nxi_buf(dst, off, v) }
40func of_seq(a: *u8, b: *u8) -> i64
46func of_starts(s: *u8, pfx: *u8) -> i64 { var i: i64 = 0; while pfx[i] != (0 as u8) { if s[i] != pfx[i] { return 0 } i = i + 1 } return 1 }
47func of_memhas(buf: *u8, n: i64, needle: *u8) -> i64
60func of_esc(dst: *u8, off: i64, s: *u8) -> i64
called by 1: of_page_top calls 1: of_cat
71func of_hexval(c: i64) -> i64
called by 1: of_form_get
78func of_form_get(body: *u8, blen: i64, key: *u8, out: *u8, cap: i64) -> i64
109func of_write_all(fd: i64, buf: *u8, n: i64) -> i64
115func of_read_req(fd: i64, buf: *u8, cap: i64) -> i64
calls 1: sys_read
163func of_read_file(path: *u8, buf: *u8, cap: i64) -> i64
171func of_write_file(path: *u8, buf: *u8, n: i64) -> i64
179func of_hdr_get(req: *u8, reqlen: i64, key: *u8, out: *u8, cap: i64) -> i64
called by 1: of_handle_auth calls 1: of_slen
205func of_atoi(s: *u8) -> i64
217func of_name_ok(name: *u8) -> i64
232func of_kind_idx(kind: *u8) -> i64
238func of_ext(k: i64) -> *u8
called by 2: of_saveof_serve
243func of_elf(k: i64) -> *u8
called by 1: of_save
248func of_ct(k: i64) -> *u8
called by 1: of_serve
253func of_kind_name(k: i64) -> *u8
259func of_manifest_count(root: *u8, name: *u8, kindout: *u8, kcap: i64) -> i64
279func of_vdir(root: *u8, name: *u8, vn: i64, out: *u8) -> i64
called by 2: of_saveof_serve calls 2: of_catof_catn
285func of_append_line(path: *u8, line: *u8, n: i64) -> i64
296func of_save(root: *u8, base: *u8, name: *u8, kind: *u8, spec: *u8, sl: i64, auto: i64) -> i64
361func of_css(out: *u8, off: i64) -> i64
calls 1: of_cat
435func of_esc_n(out: *u8, off: i64, src: *u8, a: i64, b: i64) -> i64
448func of_render_doc(out: *u8, off: i64, spec: *u8, sl: i64) -> i64
482func of_render_sheet(out: *u8, off: i64, spec: *u8, sl: i64) -> i64
502func of_render_deck(out: *u8, off: i64, spec: *u8, sl: i64) -> i64
527func of_toolbar(out: *u8, off: i64, ks: i64) -> i64
544func of_read_asset(name: *u8, buf: *u8, cap: i64) -> i64
556func of_serve_js(out: *u8, cap: i64) -> i64
570func of_serve_sw(out: *u8, cap: i64) -> i64
594func of_serve_manifest(out: *u8, base: *u8, cap: i64) -> i64
614func of_page_top(out: *u8, off: i64, title: *u8) -> i64
630func of_page_foot(out: *u8, off: i64) -> i64
637func of_shell_top(out: *u8, off: i64, title: *u8, base: *u8, q: *u8) -> i64
called by 1: of_handle_auth
658func of_ago(out: *u8, off: i64, us: i64) -> i64
669func of_manifest_last_us(root: *u8, name: *u8) -> i64
689func of_manifest_is_auto(root: *u8, name: *u8, vn: i64) -> i64
728func of_thumb(out: *u8, off: i64, root: *u8, name: *u8, ks: i64, vc: i64) -> i64
820func of_lower(s: *u8) -> i64
826func of_chip(out: *u8, off: i64, base: *u8, q: *u8, tv: *u8, sv: *u8, label: *u8, on: i64) -> i64
842func of_findpos(buf: *u8, n: i64, needle: *u8) -> i64
863func of_side_path(root: *u8, name: *u8, leaf: *u8, out: *u8) -> i64
868func of_starred(root: *u8, name: *u8) -> i64
881func of_star_toggle(root: *u8, name: *u8) -> i64
892func of_folder_get(root: *u8, name: *u8, out: *u8, cap: i64) -> i64
908func of_folder_set(root: *u8, name: *u8, val: *u8) -> i64
916func of_tmpl(out: *u8, off: i64, base: *u8, k: i64, icon: *u8, title: *u8, blurb: *u8, spec: *u8) -> i64
934func of_form(out: *u8, off: i64, base: *u8, k: i64) -> i64
962func of_home(root: *u8, base: *u8, qs: *u8, out: *u8, cap: i64, azprefix: *u8, me: *u8, authed: i64) -> i64
1169func of_lineeq(a: *u8, b: *u8) -> i64
1176func of_split_lines(buf: *u8, n: i64, lp: *i64, maxl: i64) -> i64
1188func of_read_version_spec(root: *u8, name: *u8, vn: i64, buf: *u8, cap: i64) -> i64
1198func of_render_diff(out: *u8, off: i64, bufa: *u8, na_bytes: i64, bufb: *u8, nb_bytes: i64) -> i64
1240func of_diffpage(root: *u8, base: *u8, name: *u8, va: i64, vb: i64, out: *u8, cap: i64) -> i64
1263func of_docpage(root: *u8, base: *u8, name: *u8, out: *u8, cap: i64) -> i64
1429func of_err(out: *u8, status: *u8, msg: *u8) -> i64
1447func of_extract_json_content(buf: *u8, n: i64, out: *u8, cap: i64) -> i64
1486func of_spec_to_text(spec: *u8, sl: i64, out: *u8, cap: i64) -> i64
1514func of_llm_complete_n(prompt: *u8, plen: i64, out: *u8, cap: i64, maxtok: i64) -> i64
1557func of_llm_complete(prompt: *u8, plen: i64, out: *u8, cap: i64) -> i64
1563func of_ai_prompt_sheet(ptext: *u8, out: *u8) -> i64
1570func of_ai_prompt_deck(ptext: *u8, out: *u8) -> i64
1596func of_agent_path(root: *u8, name: *u8, out: *u8) -> i64
1601func of_agent_read(root: *u8, name: *u8, buf: *u8, cap: i64) -> i64
1606func of_agent_write(root: *u8, name: *u8, buf: *u8, n: i64) -> i64
1612func of_agent_tagcount(buf: *u8, n: i64, tag: i64) -> i64
1624func of_agent_tagline(buf: *u8, n: i64, tag: i64, idx: i64, out: *u8, cap: i64) -> i64
1652func of_agent_done(buf: *u8, n: i64) -> i64
1661func of_agent_plan_parse(comp: *u8, cl: i64, out: *u8, cap: i64) -> i64
1733func of_cl_frame(out: *u8, n: i64, cap: i64) -> i64
1753func of_serve(root: *u8, name: *u8, vn: i64, mode: i64, out: *u8, cap: i64) -> i64
1787func of_parse_nv(path: *u8, pfxlen: i64, name: *u8, ncap: i64) -> i64
1811func of_docref(out: *u8, name: *u8) -> i64 { var o: i64 = of_cat(out, 0, "doc:" as *u8); o = of_cat(out, o, name); out[o] = 0 as u8; return o }
1812func of_meref(out: *u8, handle: *u8) -> i64 { var o: i64 = of_cat(out, 0, "user:" as *u8); o = of_cat(out, o, handle); out[o] = 0 as u8; return o }
1813func of_grpref(out: *u8, gname: *u8) -> i64 { var o: i64 = of_cat(out, 0, "group:" as *u8); o = of_cat(out, o, gname); out[o] = 0 as u8; return o }
1815func of_grpmemberref(out: *u8, gname: *u8) -> i64 { var o: i64 = of_grpref(out, gname); o = of_cat(out, o, "#member" as *u8); out[o] = 0 as u8; return o }
1817func of_tok_ok(s: *u8) -> i64
1834func of_sess_field(dst: *u8, off: i64, tok: *u8) -> i64
1840func of_deny_read(out: *u8) -> i64 { return of_err(out, "404 Not Found" as *u8, "no such file" as *u8) }
1841func of_deny_write(out: *u8) -> i64 { return of_err(out, "403 Forbidden" as *u8, "this document is owned; you need edit access (ask the owner to share it)" as *u8) }
1842func of_after_colon(s: *u8) -> *u8 { var i: i64 = 0; while s[i] != (0 as u8) { if (s[i] as i64) == 58 { return (s as i64 + i + 1) as *u8 } i = i + 1 } return s }
1844func of_read_ok(azprefix: *u8, me: *u8, authed: i64, nm: *u8) -> i64
1850func of_write_ok(azprefix: *u8, me: *u8, authed: i64, nm: *u8) -> i64
1857func of_do_share(base: *u8, azprefix: *u8, me: *u8, handle: *u8, authed: i64, body: *u8, blen: i64, out: *u8, grant: i64) -> i64
1880func of_before_hash(dst: *u8, s: *u8) -> i64 { var i: i64 = 0; while s[i] != (0 as u8) { if (s[i] as i64) == 35 { dst[i] = 0 as u8; return i } dst[i] = s[i]; i = i + 1 } dst[i] = 0 as u8; return i }
1882func of_share_row(out: *u8, off: i64, base: *u8, nm: *u8, subref: *u8, rel: *u8, tok: *u8) -> i64
1906func of_managepage(base: *u8, azprefix: *u8, me: *u8, authed: i64, nm: *u8, tok: *u8, out: *u8, cap: i64) -> i64
1932func of_do_group(base: *u8, azprefix: *u8, me: *u8, handle: *u8, authed: i64, body: *u8, blen: i64, out: *u8, add: i64) -> i64
1952func of_groupspage(base: *u8, azprefix: *u8, me: *u8, authed: i64, tok: *u8, out: *u8, cap: i64) -> i64
1991func of_collect_docs(azprefix: *u8, sub: *u8, rel: *u8, out: *i64, n: i64, cap: i64) -> i64
2004func of_my_docs(azprefix: *u8, me: *u8, out: *i64, cap: i64) -> i64
2024func of_sharedpage(base: *u8, azprefix: *u8, me: *u8, authed: i64, out: *u8, cap: i64) -> i64
2043func of_handle(root: *u8, base: *u8, req: *u8, reqlen: i64, out: *u8, cap: i64) -> i64
2050func of_handle_auth(root: *u8, base: *u8, req: *u8, reqlen: i64, out: *u8, cap: i64, handle: *u8, azprefix: *u8, tok: *u8) -> i64
2513func of_ck(name: *u8, cond: i64, pass: *i64, fail: *i64) -> i64
2518func of_selftest(root: *u8) -> i64