Office editor

Joshu opens and edits the Word, Excel, PowerPoint, and Markdown files of the owner with ONLYOFFICE inside the box, and this page explains the design.

Updated

Purpose

The office editor lets the owner open and edit the Word, Excel, PowerPoint, CSV, and Markdown files of the owner Desktop in a desktop window of the box, and saves each edit back to the same file. It is ONLYOFFICE Docs Community, unchanged, running inside the box container. The same editor also renders and converts files for the companion, so the companion can look at a deck before it delivers it.

How the owner uses the Office app is in office-arozos-app.md.

Motivation

These constraints shaped the design:

  • The companion makes .docx, .xlsx, and .pptx files, and mail brings more of them, but the box had no way to open them. The owner had to download each file.
  • A box runs as one container on an Agent37 sandbox under gVisor, with no Docker inside and no second container. The editor has to run as processes of the box.
  • Memory is the cost of a sandbox. The editor has to fit next to the rest of the box in 8 GB.
  • ONLYOFFICE Docs Community is AGPL v3. Running it unchanged asks only for the license notice and a link to the source. The Community edition has no multitenancy, no phone editing, and no white labeling; those are paid editions.
  • The Hermes office skill renders decks and documents with soffice (LibreOffice) to check them, and recalculates workbooks the same way. The box had no soffice, so the skill skipped these checks.

Architecture

Architecture diagram: the Office app in the desktop of the owner asks the Joshu API for a signed editor config through Caddy and loads the editor from the nginx of ONLYOFFICE under /onlyoffice/. docservice downloads the file from the Joshu API and posts the save callback to it on loopback, both signed with the office editor secret, and the Joshu API replaces the file on the owner Desktop. A Hermes worker converts and renders files through the Conversion API with the office convert command.

Source of the diagram: diagrams/office-editor.json.

The parts:

  • ONLYOFFICE package. The runtime stage of deploy/Dockerfile installs Debian package onlyoffice-documentserver at a pinned version and checksum. Version 10.0 depends on nginx, curl, openssl, iproute2, logrotate, xxd, and the Microsoft core fonts from Debian contrib, and needs no database, no RabbitMQ, and no supervisor. The build makes the font lists and theme images, because at first start they took about 10 minutes, and removes the example app.
  • Start function (scripts/lib/office-editor.sh). vps-start.sh runs office_editor_run with run_supervised office. The function writes local.json of ONLYOFFICE from the office editor secret and the loopback address of docservice (in ONLYOFFICE 10.0, docservice listens on all interfaces unless local.json names an address), sets the nginx of ONLYOFFICE to 127.0.0.1:8793 with 1024 connections and no access log, and starts docservice (127.0.0.1:8000), the converter, and nginx. When one of the three ends, it ends the other two, so the loop starts all three again. The log is <data root>/logs/office.log.
  • Office editor secret. JOSHU_OFFICE_JWT_SECRET in the instance config, 32 random bytes in hex. The start script adds it when the key is missing, before it loads the instance config, so the Joshu API and the office editor read the same value. It lives under the data root and stays across image updates.
  • Caddy route. handle_path /onlyoffice/* proxies to 127.0.0.1:8793 with X-Forwarded-Prefix: /onlyoffice, X-Forwarded-Proto: https, and X-Forwarded-Host. The office editor builds its own links from these headers.
  • Office routes (src/office/). GET /api/office/config answers the Office app with the editor config. GET /api/office/files answers the Office app with the list of files that it opens (src/office/fileList.ts). GET /api/office/file gives the office editor the bytes of the file. POST /api/office/callback takes the save callback. All tokens are HS256 with the office editor secret (jose).
  • Office app (apps/office/, arozos/subservice/office-app/). A static desktop app that reads the file that the owner opened, asks for the editor config, and starts DocsAPI.DocEditor. Opened from its desktop icon without a file, it shows the file list first. The desktop shortcut Office.shortcut comes from install_office_shortcuts in scripts/lib/arozos-desktop-shortcuts.sh.
  • Default app script (arozos/web-overlays-vanilla/aroz-office-defaults.js). Sets the Office app as the default app of the five file types with the session of the owner, and switches .md from jNotes one time, with a marker in the ArozOS user preferences.
  • Office convert command (scripts/office-convert.mjs, installed as /usr/local/bin/soffice). Takes the LibreOffice arguments that the Hermes office skill uses and converts with the Conversion API of the office editor.
  • Health (officeEditorHealth in src/office/officeEditor.ts). Component office of box health, with state up, down, or off. State up needs both the healthcheck of ONLYOFFICE and the editor script api.js on port 8793, because the healthcheck answers also when api.js was never built.

Theory of operation

Opening a file

  1. The owner double-clicks brief.docx. ArozOS opens the default app of .docx, the Office app, with the path of the file in the URL hash.
  2. The Office app sends GET /joshu/api/office/config?root=files&path=...&type=desktop with the session cookie of the desktop. On a phone it sends type=mobile.
  3. The office routes check the session with ArozOS, the path (it must resolve under the owner Desktop), and the file type. They build the editor config:
    • The document key is a hash of the path, the size, and the change time of the file. A new key starts a new editing session, so a file that the companion changed opens with the new content.
    • The file link and the callback link point to http://127.0.0.1:8788/joshu/api/office/.... Each carries a token with the root, the path, and an end time: 1 hour for the file link, 7 days for the callback link.
    • The whole config is signed into its field token. ONLYOFFICE takes each field from the token, so the browser cannot change the file link or the mode.
  4. The Office app loads /onlyoffice/web-apps/apps/api/documents/api.js and starts the editor with the config.
  5. docservice checks the token and downloads the file from the file link on loopback. The file route accepts only a direct localhost request with a valid file token.

Opening the Office app without a file

  1. The owner double-clicks the Office icon. ArozOS opens the Office app with no file in the URL hash.
  2. The Office app sends GET /joshu/api/office/files with the session cookie of the desktop. The route has the same session check as the editor config.
  3. The route walks the owner Desktop and its subfolders and answers the .docx, .xlsx, .pptx, .csv, and .md files, newest first. It looks at most 5 levels of subfolders deep, stops after 10,000 folder entries, skips hidden files, hidden folders, and symbolic links, and answers at most the 200 newest files, with a flag when a limit cut the list. A file under the folder of the companion files gets root files, as a double-click gives, so both ways of opening the file give the same document key.
  4. The Office app shows the name, the folder, and the change time of each file. When the owner clicks a file, the app writes the file into the URL hash, so that a reload opens the same file, and opens the file as in "Opening a file".

Saving a file

  1. When the owner closes the file (status 2) or clicks Save (status 6), docservice posts the save callback to the callback link, with a token of its own over the callback body.
  2. The callback route checks the link token and the body token. It downloads the edited file from the link in the body, after it changes a link under https://<host>/onlyoffice/ to the same path on 127.0.0.1:8793. It refuses a link that is neither under /onlyoffice/ nor on loopback.
  3. When the type of the edited file differs from the type of the owner file, as for a .csv or .md file that the editor hands back as .xlsx or .docx, the route asks the Conversion API to convert it back first.
  4. The route writes the bytes to a temporary file in the same folder and renames it over the file, so no reader sees a part of it. It answers {"error":0}. When the download, the conversion, or the write fails, it keeps the old file and answers {"error":1}, and the office editor keeps the edits and tries again.

Rendering for the companion

The Hermes office skill runs, for example, soffice --headless --convert-to pdf --outdir out deck.pptx, then pdftoppm to split the PDF into slide images, and then vision_analyze on each image. The office convert command serves deck.pptx on a random loopback port for the time of the call, sends a signed request to the Conversion API, downloads the result, and writes out/deck.pdf. It reads the office editor secret from its environment or from the instance config. When the office editor is off or down, it exits with a message and writes no file, and the skill reports that it could not render.

Design decisions

2026-11-29: one office editor in each box. Each box runs its own office editor with its own secret. Alternatives: one shared editor for the fleet on its own sandbox, which uses less memory in total. The Community edition has no multitenancy, so a shared editor would use one secret for all boxes, and any box could then sign a save callback that overwrites a file of another box; the multitenancy add-on is paid. Collabora Online was the other editor considered: it has phone editing, but production use needs a subscription build from a customer repository, which cannot go into the public image. The owner edits in a desktop browser first, so the Community edition is enough for now.

2026-11-29: the Debian package in the image. Alternatives: copy the installed folders out of the onlyoffice/documentserver image, which is built on another distribution with other libraries, or run that image as a second container, which a box in single-container mode does not have.

2026-11-29: three processes without supervisord. ONLYOFFICE normally runs its services with supervisord, but supervisord cannot make its control socket under gVisor and waits forever. The start script already has a loop that keeps a process alive, so it runs the three processes itself. Running supervisord with a TCP control port also works, but adds a second process manager to the box. Serving the static files and docservice directly from Caddy was rejected, because the nginx config of ONLYOFFICE has versioned cache paths and rewrites that Caddy would have to copy at each ONLYOFFICE update.

2026-11-29: 1024 nginx connections. The ONLYOFFICE start script sets worker_connections to the open file limit, which is 1,048,576 on Agent37. nginx reserves memory for each connection when it starts, about 450 MB. With 1024 the worker uses about 8 MB, and the whole office editor uses about 0.4 GB with one file open.

2026-11-29: the path /onlyoffice/. ArozOS ships its own office apps (Docs, Sheets, Slides) under /Office/, and the Caddy path matcher ignores case, so /office/ would take their requests. For the same reason the folder of the desktop app is office-app.

2026-11-29: links on loopback, signed. The office editor and the Joshu API run in the same container, so the file link and the callback link use 127.0.0.1, and the routes accept only direct localhost requests. This keeps the file and the save off the internet and off the Cloudflare Tunnel. The request filter of the office editor blocks private addresses by default, so local.json allows them, but not the meta addresses of the cloud. The tokens stay as a second check.

2026-11-29: the secret in the instance config. The office editor needs the secret before the Joshu API starts, so the start script owns it. A secret file that the Joshu API makes at first use, as for report links, would come too late.

2026-11-29: an soffice command for the Hermes office skill. The skill already has the loop of render, look, and fix, and its formatting rules do not depend on the renderer. A command with the name and arguments of LibreOffice lets the skill work unchanged. A new Hermes tool or skill would duplicate that loop. LibreOffice itself would add about 400 MB and a second engine whose output can differ from what the owner sees.

2026-11-29: the default app from the desktop. ArozOS keeps the default app of each file type per user in its database, and only a request with the session of the user can set it. A desktop script sets the Office app when the type has no default or its default is one of the ArozOS office apps, and keeps a default that the owner chose. Writing the ArozOS database from the start script was rejected, because ArozOS holds the database open and its format belongs to ArozOS.

2026-11-30: a one-time switch of .md from jNotes. After a test on a box, the Office app replaces jNotes as the default app of .md one time for each owner. Without a marker, the desktop script treats a jNotes default of .md as one that it replaces, sets the Office app, and then writes the marker joshu/office/md-default-switched into the user preferences of ArozOS (/system/file_system/preference). It writes the marker also when .md needs no change, so that a later choice of jNotes stays. With the marker, jNotes is a choice of the owner like any other app. ArozOS keeps the preference for each user in its database on the box, so the switch happens once in all browsers. The script writes the marker only after ArozOS confirms the new default, and it leaves .md alone when ArozOS does not answer the read of the marker. Alternatives: localStorage, which is kept for each browser, so a second browser would switch again after the owner set jNotes back; a marker file in the Joshu state folder through a new route, which adds a route and a file for a value that ArozOS already keeps for each user; and a switch at each desktop load, after which the owner could never keep jNotes.

2026-11-30: a desktop icon and a file list. After the same test, the Office app got a desktop icon like each other Joshu app, and the app opened from the icon lists the files that it opens. The icon is the Tango icon x-office-document, public domain like the other Joshu icons. The list comes from an office route that walks the Desktop on the box in one request, with fixed limits. Alternatives: the ArozOS route /system/file_system/listDir from the browser, which lists one folder for each request, so a walk of the subfolders would take one request for each folder; and a list of the top level of the Desktop only, which would miss the files that the companion writes into joshu's files/Projects/. The app still offers no new blank file.

Limits and failure modes

  • Phones. The Community edition opens a file for viewing only on a phone.
  • File list. The file list of the Office app shows at most the 200 newest files and looks at most 5 levels of subfolders deep. An older or deeper file opens with a double-click on the desktop.
  • Edits that are not saved. The office editor keeps an open file in its cache inside the container. A box restart while a file is open loses the edits since the last save.
  • Two writers. When the companion writes a file while the owner has it open, the next save of the owner replaces the write of the companion. The next open shows the newest file, because the document key changes.
  • CSV and Markdown. ONLYOFFICE edits them with loss: a .csv file keeps the values of the first sheet, and a .md file keeps only what Markdown can hold, so front matter and some layout can change.
  • Workbook formulas. The office convert command recalculates a workbook only if the Conversion API computes the formulas that openpyxl leaves empty.
  • Office editor down. Box health shows component office as down, the Office app shows an error, the save callback fails and the office editor tries again, and soffice exits with a message. The start loop starts the three processes again after 5 seconds.
  • Turned off. JOSHU_OFFICE_EDITOR=0 in the instance config: no office editor, component office is off, and soffice exits with a message.
  • Compose hosts. A box on a Compose host has no office editor. Its Caddy route answers 502.
  • License and brand. The editor shows the ONLYOFFICE name and logo. ONLYOFFICE sells a Developer edition for products that build the editor in, with white labeling, phone editing, and multitenancy.

This page comes from docs/technical-reference/office-editor.md in the open-source Joshu repo.