Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,7 @@ docs/phd/frontmatter/*.aux
docs/phd/frontmatter/*.blg
docs/phd/quarantine/
.lia.cache

# Article runner node deps (renderer is .mjs source; deps install via npm install).
docs/articles/_runner/node_modules/
docs/articles/_runner/package-lock.json
66 changes: 66 additions & 0 deletions crates/tri-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ enum Commands {
Stop,
/// Show status
Status,
/// Article build / QA service (docs/articles/<slug>/).
///
/// Thin wrapper around the repo-native Node runner at
/// docs/articles/_runner/src/main.mjs. The Rust binary preserves the
/// `tri article ...` command surface declared in
/// docs/articles/<slug>/README.md and forwards all positional and
/// flag arguments verbatim to the runner.
Article {
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
}

const TRIOS_SERVER: &str = "trios-server";
Expand Down Expand Up @@ -113,6 +124,60 @@ async fn wait_for_server(mut server: Child) -> Result<()> {
Ok(())
}

/// Locate the repo-native Node article runner.
///
/// The runner lives at `docs/articles/_runner/src/main.mjs` relative to
/// the repository root. We walk up from the manifest dir (cargo sets
/// `CARGO_MANIFEST_DIR` to `crates/tri-cli`) until we find it; we also
/// honour `TRIOS_ARTICLE_RUNNER` for ad-hoc overrides.
fn locate_article_runner() -> Result<std::path::PathBuf> {
use std::path::PathBuf;
if let Ok(p) = std::env::var("TRIOS_ARTICLE_RUNNER") {
let pb = PathBuf::from(p);
if pb.exists() {
return Ok(pb);
}
}
// Manifest dir → repo root is two `..` up.
let manifest = std::env::var("CARGO_MANIFEST_DIR").unwrap_or_else(|_| ".".into());
let mut here = PathBuf::from(manifest);
for _ in 0..6 {
let candidate = here.join("docs/articles/_runner/src/main.mjs");
if candidate.exists() {
return Ok(candidate);
}
if !here.pop() {
break;
}
}
// Fall back to cwd-based lookup.
let cwd = std::env::current_dir()?;
let candidate = cwd.join("docs/articles/_runner/src/main.mjs");
if candidate.exists() {
return Ok(candidate);
}
anyhow::bail!(
"article runner not found at docs/articles/_runner/src/main.mjs (set TRIOS_ARTICLE_RUNNER to override)"
)
}

async fn run_article(args: Vec<String>) -> Result<()> {
let runner = locate_article_runner()?;
let status = Command::new("node")
.arg(&runner)
.args(&args)
.stdout(std::process::Stdio::inherit())
.stderr(std::process::Stdio::inherit())
.status()?;
if !status.success() {
anyhow::bail!(
"tri article: runner exited with {}",
status.code().map(|c| c.to_string()).unwrap_or_else(|| "signal".into())
);
}
Ok(())
}

#[tokio::main]
async fn main() -> Result<()> {
let cli = Cli::parse();
Expand All @@ -130,6 +195,7 @@ async fn main() -> Result<()> {
Commands::Start { port } => start_server_and_tunnel(port).await,
Commands::Stop => stop_all().await,
Commands::Status => show_status().await,
Commands::Article { args } => run_article(args).await,
}
} => {
if let Err(e) = result {
Expand Down
2 changes: 1 addition & 1 deletion docs/articles/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ in `<slug>/article.toml`.

| Slug | Description |
|---|---|
| `pellis-trinity-full` | Pellis-Trinity PhD-Style Atlas, v21 style-safe edition |
| `pellis-trinity-full` | *Vasilev-Pellis Constants* (Trinity S³AI DNA brand), v21 style-safe edition |

## Canonical commands

Expand Down
58 changes: 58 additions & 0 deletions docs/articles/_runner/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# `docs/articles/_runner/`

Repo-native build + QA runner for `docs/articles/<slug>/` article sources.

This runner is the working backend for the `tri article` subcommand
(`crates/tri-cli`). The Rust subcommand exec's into this Node runner so
that the same renderer is used whether invoked as `tri article ...`,
`cargo run -p tri-cli -- article ...`, or directly as
`node docs/articles/_runner/src/main.mjs ...`.

## Why a Node runner instead of pure Rust

The article pipeline needs Markdown → HTML → PDF with WCAG-AA labels,
real PDF text, and CSS-grade typography. The mature options on the
build host are WeasyPrint (Python) and headless Chromium. Both are
exec'd as external tools; the runner itself is small and only handles:

1. Parsing `article.toml` + the preset TOML.
2. Concatenating `body/*.md` in lexical order and rendering through
`markdown-it`.
3. Wrapping in a single house-style HTML template that carries the
`[render.header]` strings (`Vasilev-Pellis Constants` /
`Trinity S³AI DNA`) on every page.
4. Spawning `weasyprint` to produce the PDF.
5. Running QA gates from `qa/<slug>.qa.toml` over the rendered HTML +
PDF (forbidden / required phrases, `qpdf --check`, `/Annots` audit).

## Commands

```bash
node docs/articles/_runner/src/main.mjs list
node docs/articles/_runner/src/main.mjs presets
node docs/articles/_runner/src/main.mjs build pellis-trinity-full --pdf
node docs/articles/_runner/src/main.mjs build pellis-trinity-full --html
node docs/articles/_runner/src/main.mjs qa pellis-trinity-full
```

The Rust subcommand mirrors this surface:

```bash
cargo run -p tri-cli -- article list
cargo run -p tri-cli -- article presets
cargo run -p tri-cli -- article build pellis-trinity-full --pdf
cargo run -p tri-cli -- article build pellis-trinity-full --html
cargo run -p tri-cli -- article qa pellis-trinity-full
```

## Required system tools

- `node` ≥ 18
- `weasyprint` (for `--pdf`)
- `qpdf` (for QA `qpdf --check`)
- `pdftotext` from poppler (for QA grep of PDF body text)

## L1 compliance

This runner is TypeScript-style ESM JavaScript (`.mjs`). No `.sh`
files are introduced (Constitutional L1).
14 changes: 14 additions & 0 deletions docs/articles/_runner/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "@trios/article-runner",
"version": "0.1.0",
"description": "Repo-native article build/qa runner for docs/articles/<slug>/. Invoked by `tri article` and directly by `node docs/articles/_runner/src/main.mjs`.",
"private": true,
"type": "module",
"bin": {
"article-runner": "src/main.mjs"
},
"dependencies": {
"@iarna/toml": "^2.2.5",
"markdown-it": "^14.1.1"
}
}
Loading
Loading