code wiki / (root) / nx_office_serve.nx

nx_office_serve.nx

buildroot/runtime/nx_office_serve.nx

237163 B3769 linesdepth 8pulls 24 transitivereach 5 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 8 imports · 5 importers

nx_tool_run.nx nx_gate_verdict.nx nx_connect.nx nx_itoa_lib.nx nx_rebac.nx nx_http_client.nx nx_multipart.nx nx_sign_ceremony_lib.nx nx_office_serve.nx nx_office_closed_gate.nx nx_office_daemon.nx nx_office_gate.nx nx_office_import_sign_gate.nx nx_office_snapshot.nx

imports: nx_tool_run.nxnx_gate_verdict.nxnx_connect.nxnx_itoa_lib.nxnx_rebac.nxnx_http_client.nxnx_multipart.nxnx_sign_ceremony_lib.nx

imported by: nx_office_closed_gate.nxnx_office_daemon.nxnx_office_gate.nxnx_office_import_sign_gate.nxnx_office_snapshot.nx

structs

none

consts

28const OF_AUTHZ: *u8 = "officeauthz_"
29const OF_RELATE: *u8 = "knowledge/status/relate_"
304const OF_LOCK_EX: i64 = 2
305const OF_LOCK_UN: i64 = 8
306const OF_LOCKMODE: i64 = 420
2100const OF_IMPORT_MAXPARTS: i64 = 8 // an import form carries file + name (+ sess); 8 is the parser slot count, refused above
2101const OF_SPEC_CAP: i64 = 131072 // the spec ceiling of_save already enforces (sl > 131072 is refused there too)
2102const OF_CAPTURE_CAP: i64 = 262144 // capture of the format organ's spec dump = spec cap + marker lines + slack
2103const OF_HEADSZ: i64 = 32 // sha256 audit head (se_chain out32)
2104const OF_HEXSZ: i64 = 64 // its hex form
2105const OF_EID_CAP: i64 = 128 // "<name>-v<N>" envelope id
2106const OF_CERT_CAP: i64 = 2048 // canon_encode of the 5-key completion certificate
2107const OF_USEC_PER_SEC: i64 = 1000000
2108const OF_NAME_MAX: i64 = 40 // of_name_ok's own limit (a-z 0-9 dash, max 40)
2109const OF_IMPORT_DOCX: i64 = 1
2110const OF_IMPORT_ODT: i64 = 2
2111const OF_ODT_ELF: *u8 = "_offc/nx_odt.elf"

functions

31func p(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
34func pn(v: i64) -> i64 { nxi_out(v); return 0 }
called by 1: main calls 1: nxi_out
35func of_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
36func 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 }
37func of_catc(dst: *u8, off: i64, code: i64) -> i64 { dst[off] = code as u8; return off + 1 }
42func of_catn(dst: *u8, off: i64, v: i64) -> i64 { return nxi_buf(dst, off, v) }
43func of_seq(a: *u8, b: *u8) -> i64
49func 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 }
50func of_memhas(buf: *u8, n: i64, needle: *u8) -> i64
63func of_esc(dst: *u8, off: i64, s: *u8) -> i64
called by 1: of_page_top calls 1: of_cat
74func of_hexval(c: i64) -> i64
81func of_form_get(body: *u8, blen: i64, key: *u8, out: *u8, cap: i64) -> i64
112func of_write_all(fd: i64, buf: *u8, n: i64) -> i64
118func of_read_req(fd: i64, buf: *u8, cap: i64) -> i64
called by 1: main
166func of_read_file(path: *u8, buf: *u8, cap: i64) -> i64
174func of_write_file(path: *u8, buf: *u8, n: i64) -> i64
182func of_hdr_get(req: *u8, reqlen: i64, key: *u8, out: *u8, cap: i64) -> i64
208func of_atoi(s: *u8) -> i64
220func of_name_ok(name: *u8) -> i64
235func of_kind_idx(kind: *u8) -> i64
241func of_ext(k: i64) -> *u8
246func of_elf(k: i64) -> *u8
251func of_ct(k: i64) -> *u8
called by 1: of_serve
256func of_kind_name(k: i64) -> *u8
called by 1: of_handle_auth
262func of_manifest_count(root: *u8, name: *u8, kindout: *u8, kcap: i64) -> i64
282func of_vdir(root: *u8, name: *u8, vn: i64, out: *u8) -> i64
288func of_append_line(path: *u8, line: *u8, n: i64) -> i64
307func of_doc_lock(root: *u8, name: *u8) -> i64
321func of_doc_unlock(fd: i64) -> i64
331func of_save(root: *u8, base: *u8, name: *u8, kind: *u8, spec: *u8, sl: i64, auto: i64) -> i64
339func of_save_body(root: *u8, base: *u8, name: *u8, kind: *u8, spec: *u8, sl: i64, auto: i64) -> i64
404func of_css(out: *u8, off: i64) -> i64
478func of_esc_n(out: *u8, off: i64, src: *u8, a: i64, b: i64) -> i64
491func of_render_doc(out: *u8, off: i64, spec: *u8, sl: i64) -> i64
525func of_render_sheet(out: *u8, off: i64, spec: *u8, sl: i64) -> i64
545func of_render_deck(out: *u8, off: i64, spec: *u8, sl: i64) -> i64
570func of_toolbar(out: *u8, off: i64, ks: i64) -> i64
587func of_read_asset(name: *u8, buf: *u8, cap: i64) -> i64
599func of_serve_js(out: *u8, cap: i64) -> i64
613func of_serve_sw(out: *u8, cap: i64) -> i64
637func of_serve_manifest(out: *u8, base: *u8, cap: i64) -> i64
657func of_page_top(out: *u8, off: i64, title: *u8) -> i64
673func of_page_foot(out: *u8, off: i64) -> i64
680func of_shell_top(out: *u8, off: i64, title: *u8, base: *u8, q: *u8) -> i64
701func of_ago(out: *u8, off: i64, us: i64) -> i64
712func of_manifest_last_us(root: *u8, name: *u8) -> i64
732func of_manifest_is_auto(root: *u8, name: *u8, vn: i64) -> i64
771func of_thumb(out: *u8, off: i64, root: *u8, name: *u8, ks: i64, vc: i64) -> i64
863func of_lower(s: *u8) -> i64
869func of_chip(out: *u8, off: i64, base: *u8, q: *u8, tv: *u8, sv: *u8, label: *u8, on: i64) -> i64
885func of_findpos(buf: *u8, n: i64, needle: *u8) -> i64
906func of_side_path(root: *u8, name: *u8, leaf: *u8, out: *u8) -> i64
911func of_starred(root: *u8, name: *u8) -> i64
924func of_star_toggle(root: *u8, name: *u8) -> i64
935func of_folder_get(root: *u8, name: *u8, out: *u8, cap: i64) -> i64
951func of_folder_set(root: *u8, name: *u8, val: *u8) -> i64
959func of_tmpl(out: *u8, off: i64, base: *u8, k: i64, icon: *u8, title: *u8, blurb: *u8, spec: *u8) -> i64
977func of_form(out: *u8, off: i64, base: *u8, k: i64) -> i64
1005func of_home(root: *u8, base: *u8, qs: *u8, out: *u8, cap: i64, azprefix: *u8, me: *u8, authed: i64) -> i64
1214func of_lineeq(a: *u8, b: *u8) -> i64
1221func of_split_lines(buf: *u8, n: i64, lp: *i64, maxl: i64) -> i64
1233func of_read_version_spec(root: *u8, name: *u8, vn: i64, buf: *u8, cap: i64) -> i64
1243func of_render_diff(out: *u8, off: i64, bufa: *u8, na_bytes: i64, bufb: *u8, nb_bytes: i64) -> i64
1285func of_diffpage(root: *u8, base: *u8, name: *u8, va: i64, vb: i64, out: *u8, cap: i64) -> i64
1308func of_docpage(root: *u8, base: *u8, name: *u8, out: *u8, cap: i64) -> i64
1476func of_err(out: *u8, status: *u8, msg: *u8) -> i64
1494func of_extract_json_content(buf: *u8, n: i64, out: *u8, cap: i64) -> i64
1533func of_spec_to_text(spec: *u8, sl: i64, out: *u8, cap: i64) -> i64
1561func of_llm_complete_n(prompt: *u8, plen: i64, out: *u8, cap: i64, maxtok: i64) -> i64
1604func of_llm_complete(prompt: *u8, plen: i64, out: *u8, cap: i64) -> i64
1610func of_ai_prompt_sheet(ptext: *u8, out: *u8) -> i64
1617func of_ai_prompt_deck(ptext: *u8, out: *u8) -> i64
1643func of_agent_path(root: *u8, name: *u8, out: *u8) -> i64
1648func of_agent_read(root: *u8, name: *u8, buf: *u8, cap: i64) -> i64
1653func of_agent_write(root: *u8, name: *u8, buf: *u8, n: i64) -> i64
1659func of_agent_tagcount(buf: *u8, n: i64, tag: i64) -> i64
1671func of_agent_tagline(buf: *u8, n: i64, tag: i64, idx: i64, out: *u8, cap: i64) -> i64
1699func of_agent_done(buf: *u8, n: i64) -> i64
1708func of_agent_plan_parse(comp: *u8, cl: i64, out: *u8, cap: i64) -> i64
1780func of_cl_frame(out: *u8, n: i64, cap: i64) -> i64
1800func of_serve(root: *u8, name: *u8, vn: i64, mode: i64, out: *u8, cap: i64) -> i64
1834func of_parse_nv(path: *u8, pfxlen: i64, name: *u8, ncap: i64) -> i64
1858func 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 }
1859func 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 }
1860func 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 }
1862func 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 }
1864func of_tok_ok(s: *u8) -> i64
1881func of_sess_field(dst: *u8, off: i64, tok: *u8) -> i64
1887func of_deny_read(out: *u8) -> i64 { return of_err(out, "404 Not Found" as *u8, "no such file" as *u8) }
1888func 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) }
1889func 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 }
1895func of_relate_pfx(azprefix: *u8) -> *u8
1900func of_read_ok(azprefix: *u8, me: *u8, authed: i64, nm: *u8) -> i64
1906func of_write_ok(azprefix: *u8, me: *u8, authed: i64, nm: *u8) -> i64
1913func of_do_share(base: *u8, azprefix: *u8, me: *u8, handle: *u8, authed: i64, body: *u8, blen: i64, out: *u8, grant: i64) -> i64
1936func 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 }
1938func of_share_row(out: *u8, off: i64, base: *u8, nm: *u8, subref: *u8, rel: *u8, tok: *u8) -> i64
1962func of_managepage(base: *u8, azprefix: *u8, me: *u8, authed: i64, nm: *u8, tok: *u8, out: *u8, cap: i64) -> i64
1988func of_do_group(base: *u8, azprefix: *u8, me: *u8, handle: *u8, authed: i64, body: *u8, blen: i64, out: *u8, add: i64) -> i64
2008func of_groupspage(base: *u8, azprefix: *u8, me: *u8, authed: i64, tok: *u8, out: *u8, cap: i64) -> i64
2047func of_collect_docs(azprefix: *u8, sub: *u8, rel: *u8, out: *i64, n: i64, cap: i64) -> i64
2060func of_my_docs(azprefix: *u8, me: *u8, out: *i64, cap: i64) -> i64
2080func of_sharedpage(base: *u8, azprefix: *u8, me: *u8, authed: i64, out: *u8, cap: i64) -> i64
2114func of_ct_boundary(req: *u8, reqlen: i64, out: *u8, cap: i64) -> i64
2128func of_cd_extract(body: *u8, hoff: i64, hlen: i64, key: *u8, out: *u8, cap: i64) -> i64
2142func of_name_from_filename(fn: *u8, out: *u8) -> i64
2166func of_import_kind(fn: *u8, bytes: *u8, n: i64) -> i64
2187func of_import(root: *u8, base: *u8, name: *u8, fn: *u8, bytes: *u8, n: i64) -> i64
2195func of_import_body(root: *u8, base: *u8, name: *u8, fn: *u8, bytes: *u8, n: i64) -> i64
2268func of_serve_original(root: *u8, name: *u8, vn: i64, out: *u8, cap: i64) -> i64
2304func of_is_hex(c: i64) -> i64
2310func of_unhex32(hx: *u8, out32: *u8) -> i64
2322func of_count_lines(path: *u8) -> i64
2332func of_cert_exists(root: *u8, name: *u8, vn: i64) -> i64
2348func of_sign_version(root: *u8, name: *u8, vn: i64, signer: *u8, consent: *u8, out_cert_cid: *u8) -> i64
2355func of_sign_version_body(root: *u8, name: *u8, vn: i64, signer: *u8, consent: *u8, out_cert_cid: *u8) -> i64
2428func of_serve_cert(root: *u8, name: *u8, vn: i64, out: *u8, cap: i64) -> i64
2447func of_import_form(out: *u8, off: i64, base: *u8) -> i64
2454func of_sign_cell(out: *u8, off: i64, root: *u8, base: *u8, name: *u8, vn: i64) -> i64
2469func of_propagate_tok(out: *u8, n: i64, base: *u8, tok: *u8, cap: i64) -> i64
2521func of_fix_content_length(out: *u8, n: i64, cap: i64) -> i64
2549func of_handle(root: *u8, base: *u8, req: *u8, reqlen: i64, out: *u8, cap: i64) -> i64
2556func of_handle_auth(root: *u8, base: *u8, req: *u8, reqlen: i64, out: *u8, cap: i64, handle: *u8, azprefix: *u8, tok: *u8) -> i64
3133func of_ck(name: *u8, cond: i64, pass: *i64, fail: *i64) -> i64
3145func of_selftest_gv(root: *u8, c: *i64) -> i64
3149func of_selftest(root: *u8) -> i64