docmd icon indicating copy to clipboard operation
docmd copied to clipboard

[Feature]: production `docmd serve` and live threads (comments kept in the markdown)

Open svallory opened this issue 1 month ago • 3 comments

Is your feature request related to a problem?

docmd has no production server, and plugins that write cannot work on a deployed site.

  • The official Docker image runs docmd dev --host 0.0.0.0 as its default command, so laptop-only behaviour runs in production (#156 is one result).
  • --host itself is dropped by the argument parser, so that command binds loopback and the container is unreachable.
  • Plugins can declare requiresLiveServer and register actions, but only docmd dev hosts them. The threads plugin, or any plugin that writes, stops at the laptop.

Describe the solution you'd like

Goal: a self-hosted docs site that people (and agents) can comment on, with the comments stored in the markdown itself: no database, no SaaS. That fits docmd's "no database" pitch, and threads already keeps comments in the markdown.

Two parts. The first is generic: a production docmd serve. The second, threads v2, builds on it.

docmd serve is the production counterpart of dev, like preview in Vite and Astro, start in Next, or serve in Docusaurus:

  • a production build on a fixed port, with no browser auto-open, no port+1 fallback and no fs.watch;
  • opt-in plugin actions over WebSocket, with an origin allowlist; writes are refused unless a trusted identity source is configured (fail safe);
  • opt-in MCP over HTTP.

dev stays the laptop tool, unchanged.

Threads v2 turns threads into reviews:

  • A review is one person's group of comments across pages. Drafts are private and saved on the server as you type.
  • Publishing a review writes its comments into the markdown as one git commit, authored by the commenter. It happens on click, or automatically N seconds after the last edit.
  • The person who started a review, or an admin, can discard it as one commit.
  • A reviews panel lists reviews by author and date. Threads whose anchor text is gone are kept in an Orphaned group.
  • Commenters are identified from a configurable trusted header set by an auth proxy. Write limits protect against a runaway agent.
  • An optional git sync pulls the remote on an interval and pushes with a skip-deploy marker, so bot commits don't trigger redeploy loops.

Steps

Each step is a small PR that can be reviewed and merged on its own, sent in this order. The two fixes stand alone and are useful whatever you decide about the rest.

Fixes (independent)

  1. [x] MCP read_doc returns only markdown inside the docs source directory (today read_doc {route: ".env"} returns the file): #268
  2. [x] --host is parsed and honoured by docmd dev and workspace dev, so the Docker image's dev --host 0.0.0.0 is reachable: #269

docmd serve

  1. [x] Plugin actions receive a context (who is calling, from where) from the action dispatcher: #272
  2. [x] docmd serve: production static server: #273
  3. [x] Plugin actions under serve over WebSocket (origin allowlist, writes need a trusted identity): #277
  4. [x] Opt-in MCP over HTTP under serve: #278
  5. [x] Docker image defaults to serve, plus docs: #279 (docs: docmd-io/docs#23)

Threads v2 (on top of serve)

  1. [ ] Threads file format v2 and config validation errors: #287
  2. [ ] Server-side drafts and reviews: #290
  3. [ ] Publish a review into the markdown in one atomic write (the git commit comes with step 15): #291
  4. [ ] Publish widget: collect mode and auto-publish: #292
  5. [ ] Identity from a trusted header; permissions (edit and delete your own comments, configurable resolve, admins)
  6. [ ] Discard a review
  7. [ ] Reviews panel and orphaned threads
  8. [ ] Git sync: batched commits and push with a skip-deploy marker; pull on an interval and rebuild
  9. [ ] Write limits

Everything above already runs in my fork (svallory/docmd), where it serves an internal docs site behind an SSO proxy. I'd rather agree on the direction here before sending steps 3 onward. In particular: do you want serve in docmd itself?

Describe alternatives you've considered

  • Keep running dev in production. It has the problems above, and its WebSocket origin guard is loopback-only, so plugin actions cannot work behind a proxy anyway.
  • A separate server package outside docmd. It would duplicate the build and plugin-action plumbing, and the Docker image would still have no production mode.
  • Storing comments in a database or a SaaS service. That goes against docmd's no-database model, and agents can't read the comments next to the text.

svallory avatar Nov 04 '26 18:11 svallory

Hi @svallory,

Thank you for putting together such a clear, well-structured proposal! We have officially merged both PR #268 and PR #269 into main.

We are completely aligned with this vision and all-in on the roadmap you've laid out. Keeping comments and collaborative reviews in plain Markdown with zero database dependencies fits docmd's philosophy perfectly.

A few thoughts from our side:

  1. docmd serve in core: Yes, having a dedicated production server mode in docmd makes complete sense alongside dev. It fills an important missing link for production and containerized deployments.
  2. Modular PRs: Your approach of sending focused, self-contained PRs with test contracts worked wonderfully for #268 and #269. We'd love to continue with that pattern so we can review, test, and merge each step quickly.
  3. Collaboration: We're actively building towards the 0.9.10 release cycle. As you build along, feel free to tag us if you'd like to collaborate, test against edge cases, or bounce architecture ideas off each other. We would love to build and test along with you!

Keeping this issue open as our tracking home for Steps 3 onward. Really excited to see Threads v2 come to life!

mgks avatar Nov 08 '26 10:11 mgks

Hey @svallory, quick update: both #272 (action context & shared host) and #273 (docmd serve) are now tested and merged into main!

All contracts passed cleanly. Looking forward to Steps 5–7 when you're ready.

mgks avatar Nov 11 '26 19:11 mgks

Merged #277, #278 and #279, completing the docmd serve implementation. We've also released docmd 0.10.0, which includes these features along with the new MDX Lite feature.

Further development of Threads V2 will now build on top of 0.10.0, using docmd serve as the foundation.

You can start with further development. Cheers! ✌🏼

mgks avatar Nov 14 '26 09:11 mgks