nx_office_serve.nx
buildroot/runtime/nx_office_serve.nx
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
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
| 28 | const OF_AUTHZ: *u8 = "officeauthz_" |
| 29 | const OF_RELATE: *u8 = "knowledge/status/relate_" |
| 304 | const OF_LOCK_EX: i64 = 2 |
| 305 | const OF_LOCK_UN: i64 = 8 |
| 306 | const OF_LOCKMODE: i64 = 420 |
| 2100 | const OF_IMPORT_MAXPARTS: i64 = 8 // an import form carries file + name (+ sess); 8 is the parser slot count, refused above |
| 2101 | const OF_SPEC_CAP: i64 = 131072 // the spec ceiling of_save already enforces (sl > 131072 is refused there too) |
| 2102 | const OF_CAPTURE_CAP: i64 = 262144 // capture of the format organ's spec dump = spec cap + marker lines + slack |
| 2103 | const OF_HEADSZ: i64 = 32 // sha256 audit head (se_chain out32) |
| 2104 | const OF_HEXSZ: i64 = 64 // its hex form |
| 2105 | const OF_EID_CAP: i64 = 128 // "<name>-v<N>" envelope id |
| 2106 | const OF_CERT_CAP: i64 = 2048 // canon_encode of the 5-key completion certificate |
| 2107 | const OF_USEC_PER_SEC: i64 = 1000000 |
| 2108 | const OF_NAME_MAX: i64 = 40 // of_name_ok's own limit (a-z 0-9 dash, max 40) |
| 2109 | const OF_IMPORT_DOCX: i64 = 1 |
| 2110 | const OF_IMPORT_ODT: i64 = 2 |
| 2111 | const OF_ODT_ELF: *u8 = "_offc/nx_odt.elf" |
functions
| 31 | func p(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } |
| 34 | func pn(v: i64) -> i64 { nxi_out(v); return 0 } |
| 35 | func of_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } |
| 36 | func 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 } |
| 37 | func of_catc(dst: *u8, off: i64, code: i64) -> i64 { dst[off] = code as u8; return off + 1 } |
| 42 | func of_catn(dst: *u8, off: i64, v: i64) -> i64 { return nxi_buf(dst, off, v) } |
| 43 | func of_seq(a: *u8, b: *u8) -> i64 |
| 49 | func 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 } |
| 50 | func of_memhas(buf: *u8, n: i64, needle: *u8) -> i64 |
| 63 | func of_esc(dst: *u8, off: i64, s: *u8) -> i64 |
| 74 | func of_hexval(c: i64) -> i64 |
| 81 | func of_form_get(body: *u8, blen: i64, key: *u8, out: *u8, cap: i64) -> i64 |
| 112 | func of_write_all(fd: i64, buf: *u8, n: i64) -> i64 |
| 118 | func of_read_req(fd: i64, buf: *u8, cap: i64) -> i64 called by 1: main |
| 166 | func of_read_file(path: *u8, buf: *u8, cap: i64) -> i64 |
| 174 | func of_write_file(path: *u8, buf: *u8, n: i64) -> i64 called by 5: of_save_bodyof_agent_writeof_import_bodyof_sign_version_bodysn_dump calls 1: of_write_all |
| 182 | func of_hdr_get(req: *u8, reqlen: i64, key: *u8, out: *u8, cap: i64) -> i64 |
| 208 | func of_atoi(s: *u8) -> i64 |
| 220 | func of_name_ok(name: *u8) -> i64 |
| 235 | func of_kind_idx(kind: *u8) -> i64 |
| 241 | func of_ext(k: i64) -> *u8 |
| 246 | func of_elf(k: i64) -> *u8 |
| 251 | func of_ct(k: i64) -> *u8 called by 1: of_serve |
| 256 | func of_kind_name(k: i64) -> *u8 called by 1: of_handle_auth |
| 262 | func of_manifest_count(root: *u8, name: *u8, kindout: *u8, kcap: i64) -> i64 |
| 282 | func of_vdir(root: *u8, name: *u8, vn: i64, out: *u8) -> i64 called by 7: of_save_bodyof_serveof_import_bodyof_serve_originalof_cert_existsof_sign_version_body+1 calls 2: of_catof_catn |
| 288 | func of_append_line(path: *u8, line: *u8, n: i64) -> i64 |
| 307 | func of_doc_lock(root: *u8, name: *u8) -> i64 |
| 321 | func of_doc_unlock(fd: i64) -> i64 |
| 331 | func of_save(root: *u8, base: *u8, name: *u8, kind: *u8, spec: *u8, sl: i64, auto: i64) -> i64 |
| 339 | func of_save_body(root: *u8, base: *u8, name: *u8, kind: *u8, spec: *u8, sl: i64, auto: i64) -> i64 |
| 404 | func of_css(out: *u8, off: i64) -> i64 |
| 478 | func of_esc_n(out: *u8, off: i64, src: *u8, a: i64, b: i64) -> i64 |
| 491 | func of_render_doc(out: *u8, off: i64, spec: *u8, sl: i64) -> i64 |
| 525 | func of_render_sheet(out: *u8, off: i64, spec: *u8, sl: i64) -> i64 |
| 545 | func of_render_deck(out: *u8, off: i64, spec: *u8, sl: i64) -> i64 |
| 570 | func of_toolbar(out: *u8, off: i64, ks: i64) -> i64 |
| 587 | func of_read_asset(name: *u8, buf: *u8, cap: i64) -> i64 |
| 599 | func of_serve_js(out: *u8, cap: i64) -> i64 |
| 613 | func of_serve_sw(out: *u8, cap: i64) -> i64 |
| 637 | func of_serve_manifest(out: *u8, base: *u8, cap: i64) -> i64 |
| 657 | func of_page_top(out: *u8, off: i64, title: *u8) -> i64 |
| 673 | func of_page_foot(out: *u8, off: i64) -> i64 |
| 680 | func of_shell_top(out: *u8, off: i64, title: *u8, base: *u8, q: *u8) -> i64 |
| 701 | func of_ago(out: *u8, off: i64, us: i64) -> i64 |
| 712 | func of_manifest_last_us(root: *u8, name: *u8) -> i64 |
| 732 | func of_manifest_is_auto(root: *u8, name: *u8, vn: i64) -> i64 |
| 771 | func of_thumb(out: *u8, off: i64, root: *u8, name: *u8, ks: i64, vc: i64) -> i64 |
| 863 | func of_lower(s: *u8) -> i64 |
| 869 | func of_chip(out: *u8, off: i64, base: *u8, q: *u8, tv: *u8, sv: *u8, label: *u8, on: i64) -> i64 |
| 885 | func of_findpos(buf: *u8, n: i64, needle: *u8) -> i64 |
| 906 | func of_side_path(root: *u8, name: *u8, leaf: *u8, out: *u8) -> i64 |
| 911 | func of_starred(root: *u8, name: *u8) -> i64 |
| 924 | func of_star_toggle(root: *u8, name: *u8) -> i64 |
| 935 | func of_folder_get(root: *u8, name: *u8, out: *u8, cap: i64) -> i64 |
| 951 | func of_folder_set(root: *u8, name: *u8, val: *u8) -> i64 |
| 959 | func of_tmpl(out: *u8, off: i64, base: *u8, k: i64, icon: *u8, title: *u8, blurb: *u8, spec: *u8) -> i64 |
| 977 | func of_form(out: *u8, off: i64, base: *u8, k: i64) -> i64 |
| 1005 | func of_home(root: *u8, base: *u8, qs: *u8, out: *u8, cap: i64, azprefix: *u8, me: *u8, authed: i64) -> i64 |
| 1214 | func of_lineeq(a: *u8, b: *u8) -> i64 |
| 1221 | func of_split_lines(buf: *u8, n: i64, lp: *i64, maxl: i64) -> i64 |
| 1233 | func of_read_version_spec(root: *u8, name: *u8, vn: i64, buf: *u8, cap: i64) -> i64 |
| 1243 | func of_render_diff(out: *u8, off: i64, bufa: *u8, na_bytes: i64, bufb: *u8, nb_bytes: i64) -> i64 |
| 1285 | func of_diffpage(root: *u8, base: *u8, name: *u8, va: i64, vb: i64, out: *u8, cap: i64) -> i64 |
| 1308 | func of_docpage(root: *u8, base: *u8, name: *u8, out: *u8, cap: i64) -> i64 |
| 1476 | func of_err(out: *u8, status: *u8, msg: *u8) -> i64 |
| 1494 | func of_extract_json_content(buf: *u8, n: i64, out: *u8, cap: i64) -> i64 |
| 1533 | func of_spec_to_text(spec: *u8, sl: i64, out: *u8, cap: i64) -> i64 |
| 1561 | func of_llm_complete_n(prompt: *u8, plen: i64, out: *u8, cap: i64, maxtok: i64) -> i64 |
| 1604 | func of_llm_complete(prompt: *u8, plen: i64, out: *u8, cap: i64) -> i64 |
| 1610 | func of_ai_prompt_sheet(ptext: *u8, out: *u8) -> i64 |
| 1617 | func of_ai_prompt_deck(ptext: *u8, out: *u8) -> i64 |
| 1643 | func of_agent_path(root: *u8, name: *u8, out: *u8) -> i64 |
| 1648 | func of_agent_read(root: *u8, name: *u8, buf: *u8, cap: i64) -> i64 |
| 1653 | func of_agent_write(root: *u8, name: *u8, buf: *u8, n: i64) -> i64 |
| 1659 | func of_agent_tagcount(buf: *u8, n: i64, tag: i64) -> i64 |
| 1671 | func of_agent_tagline(buf: *u8, n: i64, tag: i64, idx: i64, out: *u8, cap: i64) -> i64 |
| 1699 | func of_agent_done(buf: *u8, n: i64) -> i64 |
| 1708 | func of_agent_plan_parse(comp: *u8, cl: i64, out: *u8, cap: i64) -> i64 |
| 1780 | func of_cl_frame(out: *u8, n: i64, cap: i64) -> i64 |
| 1800 | func of_serve(root: *u8, name: *u8, vn: i64, mode: i64, out: *u8, cap: i64) -> i64 |
| 1834 | func of_parse_nv(path: *u8, pfxlen: i64, name: *u8, ncap: i64) -> i64 |
| 1858 | func 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 } |
| 1859 | func 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 } |
| 1860 | func 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 } |
| 1862 | func 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 } |
| 1864 | func of_tok_ok(s: *u8) -> i64 |
| 1881 | func of_sess_field(dst: *u8, off: i64, tok: *u8) -> i64 |
| 1887 | func of_deny_read(out: *u8) -> i64 { return of_err(out, "404 Not Found" as *u8, "no such file" as *u8) } |
| 1888 | func 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) } |
| 1889 | func 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 } |
| 1895 | func of_relate_pfx(azprefix: *u8) -> *u8 |
| 1900 | func of_read_ok(azprefix: *u8, me: *u8, authed: i64, nm: *u8) -> i64 |
| 1906 | func of_write_ok(azprefix: *u8, me: *u8, authed: i64, nm: *u8) -> i64 |
| 1913 | func of_do_share(base: *u8, azprefix: *u8, me: *u8, handle: *u8, authed: i64, body: *u8, blen: i64, out: *u8, grant: i64) -> i64 |
| 1936 | func 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 } |
| 1938 | func of_share_row(out: *u8, off: i64, base: *u8, nm: *u8, subref: *u8, rel: *u8, tok: *u8) -> i64 |
| 1962 | func of_managepage(base: *u8, azprefix: *u8, me: *u8, authed: i64, nm: *u8, tok: *u8, out: *u8, cap: i64) -> i64 |
| 1988 | func of_do_group(base: *u8, azprefix: *u8, me: *u8, handle: *u8, authed: i64, body: *u8, blen: i64, out: *u8, add: i64) -> i64 |
| 2008 | func of_groupspage(base: *u8, azprefix: *u8, me: *u8, authed: i64, tok: *u8, out: *u8, cap: i64) -> i64 |
| 2047 | func of_collect_docs(azprefix: *u8, sub: *u8, rel: *u8, out: *i64, n: i64, cap: i64) -> i64 |
| 2060 | func of_my_docs(azprefix: *u8, me: *u8, out: *i64, cap: i64) -> i64 |
| 2080 | func of_sharedpage(base: *u8, azprefix: *u8, me: *u8, authed: i64, out: *u8, cap: i64) -> i64 |
| 2114 | func of_ct_boundary(req: *u8, reqlen: i64, out: *u8, cap: i64) -> i64 |
| 2128 | func of_cd_extract(body: *u8, hoff: i64, hlen: i64, key: *u8, out: *u8, cap: i64) -> i64 |
| 2142 | func of_name_from_filename(fn: *u8, out: *u8) -> i64 |
| 2166 | func of_import_kind(fn: *u8, bytes: *u8, n: i64) -> i64 |
| 2187 | func of_import(root: *u8, base: *u8, name: *u8, fn: *u8, bytes: *u8, n: i64) -> i64 |
| 2195 | func of_import_body(root: *u8, base: *u8, name: *u8, fn: *u8, bytes: *u8, n: i64) -> i64 |
| 2268 | func of_serve_original(root: *u8, name: *u8, vn: i64, out: *u8, cap: i64) -> i64 |
| 2304 | func of_is_hex(c: i64) -> i64 |
| 2310 | func of_unhex32(hx: *u8, out32: *u8) -> i64 |
| 2322 | func of_count_lines(path: *u8) -> i64 |
| 2332 | func of_cert_exists(root: *u8, name: *u8, vn: i64) -> i64 |
| 2348 | func of_sign_version(root: *u8, name: *u8, vn: i64, signer: *u8, consent: *u8, out_cert_cid: *u8) -> i64 |
| 2355 | func of_sign_version_body(root: *u8, name: *u8, vn: i64, signer: *u8, consent: *u8, out_cert_cid: *u8) -> i64 |
| 2428 | func of_serve_cert(root: *u8, name: *u8, vn: i64, out: *u8, cap: i64) -> i64 |
| 2447 | func of_import_form(out: *u8, off: i64, base: *u8) -> i64 |
| 2454 | func of_sign_cell(out: *u8, off: i64, root: *u8, base: *u8, name: *u8, vn: i64) -> i64 |
| 2469 | func of_propagate_tok(out: *u8, n: i64, base: *u8, tok: *u8, cap: i64) -> i64 |
| 2521 | func of_fix_content_length(out: *u8, n: i64, cap: i64) -> i64 |
| 2549 | func of_handle(root: *u8, base: *u8, req: *u8, reqlen: i64, out: *u8, cap: i64) -> i64 |
| 2556 | func of_handle_auth(root: *u8, base: *u8, req: *u8, reqlen: i64, out: *u8, cap: i64, handle: *u8, azprefix: *u8, tok: *u8) -> i64 |
| 3133 | func of_ck(name: *u8, cond: i64, pass: *i64, fail: *i64) -> i64 |
| 3145 | func of_selftest_gv(root: *u8, c: *i64) -> i64 |
| 3149 | func of_selftest(root: *u8) -> i64 |