Agent skill

Doc Runtime Patterns

by simonliu-ai-product in simonliu-ai-product/open-doc

Implementation patterns for the @open-doc/core runtime — the split between the viewer and the published bundle, virtual modules, the flow pipeline, the ops layer, dev-only plugins, and the…

MITAuto-check passedDevelopment

Install Doc Runtime Patterns

skills CLI
$ npx skills add simonliu-ai-product/open-doc --skill doc-runtime-patterns -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install simonliu-ai-product/open-doc doc-runtime-patterns --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/simonliu-ai-product/open-doc.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.agents/skills/doc-runtime-patterns .claude/skills/doc-runtime-patterns && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
doc-runtime-patterns
GitHub stars
108
Token cost
~2.1k tokens
SKILL.md length
1,091 words
Files
1
Skills in repo
7
Repo updated
First seen
Licence
MIT

At a glance

Implementation patterns for the @open-doc/core runtime — the split between the viewer and the published bundle, virtual modules, the flow pipeline, the ops layer, dev-only plugins, and the…

  • Works in 8 steps: The two-copies rule (highest impact) → Discovery goes through virtual modules → The flow pipeline is three layers — keep… → …
  • Refactoring anything under packages/core/src
  • SKILL.md covers 1. The two-copies rule…, 2. Discovery goes through…, 3. The flow pipeline is three… and 4. Mutations live in src/ops/, plus 5 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md

What it does

Doc Runtime Patterns is an agent skill from simonliu-ai-product/open-doc. Implementation patterns for the @open-doc/core runtime — the split between the viewer and the published bundle, virtual modules, the flow pipeline, the ops layer, dev-only plugins, and the React/perf rules that matter when a page is measured offscreen before it is drawn. Use when writing or refactoring anything under packages/core/src, packages/mcp/src, or when reviewing a PR that touches them. Not for authoring documents under docs/ — that's the create-doc / doc-authoring skills.

Its SKILL.md is about 2.1k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in Development, covering Refactoring. It works with React and Model Context Protocol. The repository describes itself as: The document framework built for agents — write reports as React, get real A4 pages, an outline, page numbers, and a PDF. The licence is MIT.

When your agent uses it

  • Refactoring anything under packages/core/src
  • Packages/mcp/src
  • Reviewing a PR that touches them

Example prompts

  • “/doc-runtime-patterns”

Workflow steps

8 steps, taken from the step headings in SKILL.md.

  1. The two-copies rule (highest impact)
  2. Discovery goes through virtual modules
  3. The flow pipeline is three layers — keep them apart
  4. Mutations live in src/ops/
  5. Dev-only endpoints are a trust boundary
  6. React rules that actually bite here
  7. Composition over flags
  8. Export determinism

What it can do on your machine

Read from SKILL.md and the folder at commit af6095d. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md.

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Doc Runtime Patterns loads about 2.1k tokens when it runs. Until then it costs about 127 tokens; SKILL.md has 1,091 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~127
When it runs · the whole SKILL.md, loaded when a task matches
~2.1k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from simonliu-ai-product/open-doc at commit af6095d, republished under its MIT licence (© simonliu-ai-product). 1,091 words, ~2,098 tokens.

Download SKILL.mdSave it as .claude/skills/doc-runtime-patterns/SKILL.md (or your agent's skills folder).
name
doc-runtime-patterns
description
Implementation patterns for the @open-doc/core runtime — the split between the viewer and the published bundle, virtual modules, the flow pipeline, the ops layer, dev-only plugins, and the React/perf rules that matter when a page is measured offscreen before it is drawn. Use when writing or refactoring anything under packages/core/src, packages/mcp/src, or when reviewing a PR that touches them. Not for authoring documents under docs/ — that's the create-doc / doc-authoring skills.

open-doc runtime patterns

Rules for code that ships inside @open-doc/core (and the MCP server that sits on top of it). They exist because this runtime has two properties most React apps don't: it runs twice in the same tab, and it measures the DOM before it paints.

1. The two-copies rule (highest impact)

The viewer imports src/app/** directly. A user's document imports the built dist bundle through @open-doc/core. Both are alive in the same page.

  • Anything that must be shared across that boundary — React context, the outline store — is stashed on globalThis. See app/lib/page-context.tsx and app/lib/outline.ts.
  • A new shared singleton that uses a plain module-level let, a plain createContext, or a module-scoped Map will silently split in two: the viewer writes one copy, the document reads the other, and nothing throws.
  • Test for it the same way: a value set from the viewer side must be readable from a document component, not just from a unit test that imports one copy.
  • Public API changes are index.ts changes. If a document is supposed to call it, it must be exported there — not deep-imported from app/lib/*.

2. Discovery goes through virtual modules

vite/open-doc-plugin.ts globs docs/*/index.{tsx,jsx,ts,js} into virtual:open-doc/docs with a per-doc cache-bust token; themes-plugin.ts does the same for themes/*.md into virtual:open-doc/themes; folders land in virtual:open-doc/folders for static builds.

  • New content the framework discovers on disk gets a virtual module, not a runtime fetch of a JSON file. Dev and build then agree by construction.
  • Anything that must be live in dev and frozen at build gets both paths: a dev endpoint plus a snapshot baked into the virtual module. docs/.folders.json is the reference implementation.
  • Never widen the glob to walk the user's whole project. Discovery is scoped to docs/ (including each document's assets/) and themes/.

3. The flow pipeline is three layers — keep them apart

LayerFileRule
Pure packerapp/lib/flow.ts (paginateBlocks)No DOM. Takes BlockMetrics[] + available height, returns page assignments. Every pagination rule is unit-testable here.
Measurementapp/lib/flow-measure.tsOwns offscreen DOM measurement. Batches reads; never interleaves read/write.
Compositionapp/lib/use-doc-pages.tsJoins fixed pages + flow output into the rendered page list.

Everything downstream — viewer, thumbnails, export-pdf.ts, export-html.ts — consumes useDocPages. Reading doc.default directly is a bug, because it skips flow expansion and yields a different page count than the exporters.

Adding a break rule means: extend paginateBlocks, add a case to flow.test.ts, done. If the rule needs a measured value it doesn't have, add it to BlockMetrics — don't reach into the DOM from the packer.

4. Mutations live in src/ops/

vite/routes/docs.ts and the MCP tools are two transports over one implementation.

  • A validation rule, conflict check, or id-collision guard is written once, in ops/.
  • Errors are OpsError with the status the transport should report — a route never invents its own status text.
  • New mutating capability = a function in ops/ + a thin route + a thin MCP tool. Logic inline in a route is a review block: it ships to one caller and not the other.
  • @open-doc/mcp is resolved dynamically by vite/mcp-plugin.ts through a variable specifier. Core must never take a static import on it — the peer relationship points the other way. Missing install warns and disables /mcp; it is never fatal.

5. Dev-only endpoints are a trust boundary

api-plugin.ts and design-plugin.ts mount under apply: 'serve' only. They write to the user's disk.

  • Every mutating handler calls validateMutationRequest (http/request-guard.ts) first. No exceptions, including "internal" endpoints.
  • Path safety for anything user-named is centralized in files/assets.ts. Never path.join a user-supplied name onto a directory by hand, and never trust a name that round-tripped through the client.
  • Source-rewriting endpoints parse and replace a byte range — they never regenerate a file. design-plugin.ts accepts literal objects only and reports anything else back to the panel rather than overwriting it. editing/edit-ops.ts refuses any node that isn't a single text child. Widening either of those is an explicit product decision, not an implementation detail.
Show full SKILL.md (451 more words)Show less

6. React rules that actually bite here

The app targets React 18 — no use(), forwardRef is still required, and there is no compiler. Assume nothing is memoized for you.

  • Never measure in a loop that also writes. Read all block heights, then apply. Interleaving forces a layout per block and turns a 40-page document into a visible stall.
  • Derive during render, not in an effect. Page lists, outline entries, and geometry are derivations of props — an effect that recomputes them adds a frame of wrong output that the exporter can capture.
  • Keep transient values in refs. Scroll position, drag offsets, and measurement scratch state must not re-render the page list.
  • Memoize by content, not by identity. A page component re-created inline each render defeats every downstream memo and re-triggers measurement. Never define a component inside another component.
  • Subscribe to the narrowest thing. The sidebar should depend on the page count, not on the page array, or every re-measure repaints the rail.
  • content-visibility: auto is for the viewer only. It must never reach the export path — skipped rendering serializes as empty.

7. Composition over flags

The viewer's chrome is compound by design: routes/home-shell.tsx owns the left sidebar and hands folder state to routes through the outlet context; components/doc-sidebar.tsx owns the document rail; the design panel docks right.

  • A route never fetches the folders manifest itself. Take it from the outlet context.
  • Prefer an explicit variant component over another boolean prop. <DocSidebar mode="outline"> beats showOutline showThumbnails compact.
  • Prefer children over renderX props. Prefer lifting state into the provider that already owns it over threading a callback down three levels.

8. Export determinism

Both exporters build their own offscreen copy, scan the outline there, serialize, then restore the previous snapshot.

  • Before serializing: waitForFonts(), waitForImages(), waitForDataWaitfor() (app/lib/print-ready.ts).
  • Anything that paints asynchronously must expose data-waitfor="<selector>" — that is the only contract the exporter has for "not done yet".
  • Never call face.load() on unloaded font faces. document.fonts.ready already covers requested faces; forcing the rest ignores unicode-range and will hang the tab on a subsetted CJK family. (There's a comment in print-ready.ts saying so — don't undo it.)
  • An export change is verified by exporting, not by reading the viewer.

Review checklist

  • No new module-level state that crosses the viewer/bundle boundary without globalThis
  • New public surface exported from index.ts
  • Page data flows through useDocPages, not doc.default
  • Pagination logic in flow.ts with a test; measurement in flow-measure.ts
  • Mutations in ops/, OpsError for status, both transports reach the same function
  • validateMutationRequest on every mutating handler; user-named paths via files/assets.ts
  • No read/write interleaving in measurement; no components defined inside components
  • Export path re-verified (PDF and HTML) for anything affecting page composition
  • No new dependency in core without a reason that outweighs install size

© simonliu-ai-product, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in .agents/skills/doc-runtime-patterns of simonliu-ai-product/open-doc.

Open the folder on GitHubat commit af6095d

Compare with similar skills

Doc Runtime Patterns next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Doc Runtime Patterns compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Doc Runtime Patterns this skillsimonliu-ai-product/open-doc108—~2.1kAutomated safety check: PassMIT
Project Form PatternsAkaraChen/aghub272—~1.1kAutomated safety check: PassMIT
Claude Code Skillcodeaashu/claude-code3.4k1 repos~2.7kAutomated safety check: PassProprietary
ast-grep Structural Searchcode-yeongyu/oh-my-openagent70k—~3.3kAutomated safety check: PassMIT
Nuqstrycompai/crm11k1 repos~1.7kAutomated safety check: PassMIT
LangBot Core Developmentlangbot-app/LangBot18k—~1.4kAutomated safety check: NotesApache-2.0

Similar skills

  • Project Form Patterns

    AkaraChen/aghub

    Form implementation guidance for the aghub desktop app. An agent skill from AkaraChen/aghub.

    272 GitHub stars~1.1k tokensUpdated 2 days ago
    DevelopmentAuto-check passed
  • Claude Code Skill

    codeaashu/claude-code

    Development conventions and architecture guide for the Claude Code CLI repository.

    3.4k GitHub starsUsed in 1 repo~2.7k tokens
    DevelopmentAuto-check passed
  • ast-grep Structural Search

    code-yeongyu/oh-my-openagent

    Searches and rewrites code by syntax-tree shape across 25 languages with ast-grep, for codemods, structural queries and YAML lint rules, using a Python wrapper script.

    70k GitHub stars~3.3k tokensUpdated today
    DevelopmentAuto-check passed
  • Nuqs

    trycompai/crm

    nuqs (type-safe URL query state) best practices for Next.js and other React frameworks.

    11k GitHub starsUsed in 1 repo~1.7k tokens
    DevelopmentAuto-check passed
  • LangBot Core Development

    langbot-app/LangBot

    Covers developing the LangBot core backend and web UI: dev setup, repo layout, API auth types, adding endpoints, migrations and keeping the MCP server in step.

    18k GitHub stars~1.4k tokensUpdated today
    DevelopmentAuto-check: notes
  • Graph-Guided Safe Refactoring

    tirth8205/code-review-graph

    Plans a refactor from a code dependency graph, previews renames before applying them and checks that the final impact matches the plan.

    32k GitHub starsUsed in 1 repo~332 tokens
    DevelopmentAuto-check passed

More from simonliu-ai-product/open-doc

  • Apply Comments

    simonliu-ai-product/open-doc

    A skill your agent uses when the user asks to apply, process, or clear the comments they left in the open-doc inspector — phrases like "apply the comments", "apply my edits", "I left notes on the…

    108 GitHub stars~948 tokensUpdated yesterday
    Auto-check passed
  • Doc Authoring

    simonliu-ai-product/open-doc

    Technical reference for writing or editing open-doc pages — file contract, the A4/B4/A3 page canvas, print type scale, the vertical budget that decides where a page breaks, tables, charts, table of…

    108 GitHub stars~6.8k tokensUpdated yesterday
    Auto-check passed
  • Create Doc

    simonliu-ai-product/open-doc

    A skill your agent uses when the user wants to create, draft, author, or generate a new document, report, whitepaper, proposal, memo, or spec in this open-doc repo.

    108 GitHub stars~2.4k tokensUpdated yesterday
    Auto-check passed
  • Current Doc

    simonliu-ai-product/open-doc

    Resolve which document, page, and (optionally) selected element the user is currently viewing in the open-doc dev server.

    108 GitHub stars~1.8k tokensUpdated yesterday
    Auto-check passed
  • Print Layout Review

    simonliu-ai-product/open-doc

    Reviews page layout, typography, and pagination code in open-doc against a print craft bar — the sheet is the deliverable, not the screen.

    108 GitHub stars~2k tokensUpdated yesterday
    Auto-check passed
  • Viewer UI Guidelines

    simonliu-ai-product/open-doc

    Design and accessibility rules for the open-doc viewer chrome — the browser shell, sidebars, thumbnail rail, outline, assets and design panels, inspector overlay, and menus.

    108 GitHub stars~1.6k tokensUpdated yesterday
    Auto-check passed

Categories

Questions about Doc Runtime Patterns

What does Doc Runtime Patterns do?

Implementation patterns for the @open-doc/core runtime — the split between the viewer and the published bundle, virtual modules, the flow pipeline, the ops layer, dev-only plugins, and the…. Doc Runtime Patterns is an agent skill from simonliu-ai-product/open-doc. Implementation patterns for the @open-doc/core runtime — the split between the viewer and the published bundle, virtual modules, the flow pipeline, the ops layer, dev-only plugins, and the React/perf rules that matter when a page is measured offscreen before it is drawn.

When should I use Doc Runtime Patterns?

Doc Runtime Patterns fits situations like: refactoring anything under packages/core/src; packages/mcp/src; reviewing a PR that touches them.

How do I install Doc Runtime Patterns in Claude Code?

Run `npx skills add simonliu-ai-product/open-doc --skill doc-runtime-patterns -a claude-code`. Or copy the skill folder (.agents/skills/doc-runtime-patterns in simonliu-ai-product/open-doc) into .claude/skills/doc-runtime-patterns in your project. Claude Code loads it when a task matches its description.

How do I install Doc Runtime Patterns in Codex?

Run `npx skills add simonliu-ai-product/open-doc --skill doc-runtime-patterns -a codex`. Or copy the skill folder (.agents/skills/doc-runtime-patterns in simonliu-ai-product/open-doc) into .agents/skills/doc-runtime-patterns in your project. Codex loads it when a task matches its description.

Can I use Doc Runtime Patterns in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add simonliu-ai-product/open-doc --skill doc-runtime-patterns -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/doc-runtime-patterns, .gemini/skills/doc-runtime-patterns, .github/skills/doc-runtime-patterns and .opencode/skills/doc-runtime-patterns in your project.

What does Doc Runtime Patterns need to run?

SKILL.md names no scripts, command-line tools or credentials: Doc Runtime Patterns is instructions for the agent only.

Does Doc Runtime Patterns access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Doc Runtime Patterns safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Doc Runtime Patterns use?

Doc Runtime Patterns is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Doc Runtime Patterns use?

About 2.1k tokens (SKILL.md is roughly 8.4k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Doc Runtime Patterns?

Skills that share tags, products or a category with Doc Runtime Patterns: Project Form Patterns (AkaraChen/aghub, 272 stars), Claude Code Skill (codeaashu/claude-code, 3.4k stars), ast-grep Structural Search (code-yeongyu/oh-my-openagent, 70k stars) and Nuqs (trycompai/crm, 11k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Doc Runtime Patterns?

simonliu-ai-product (a GitHub organization) maintains it in simonliu-ai-product/open-doc, which has 108 GitHub stars. The repository holds 7 skills in this directory. The repository was last updated on October 7, 2026.

Source: simonliu-ai-product/open-doc on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.