refactor(PR-02): protocol/reader architecture, /api/documents and reader IA
- migrate crate to RFC-0002 §5.3 Reader layout: src/protocol/{analysis_v2,
trace_v2,tool_v1}.rs, src/reader/{source,markdown,model,assemble,render,
assets}.rs, src/config.rs; lib.rs is the composition root; delete app/project/
semantic/trace/document/presentation/source_map/render/assets top-level files
- split presentation into model (types) and assemble (merge/stale/DocumentService)
- merge controlled project root/path boundary and UTF-8 byte spans into
reader/source.rs; move view.json config to config.rs
- replace GET /api/document with read-only GET /api/documents (documents list +
current outline/function/analysis summary) and add contract tests
- reading UI: drop variable/memory placeholder actions, keep one explicit
unsupported explanation, add simple dark theme toggle over the single token
layer; assert via rendering test
- reorganize tests into Cargo [[test]] suites tests/contract and
tests/integration; record docs/evidence/PR-02
- unit 41 + contract 41 + integration 33 all pass; clippy clean
This commit is contained in:
1 parent
5a61788bc9
commit
5c9a313424
43 files changed
+1222
-936
No files matched your search
+53
-19
@@ -1,38 +1,72 @@
|
||||
//! marqdo-view library: a single package with one presentation pipeline.
|
||||
//! marqdo-view library: one package, one presentation pipeline, one renderer.
|
||||
//!
|
||||
//! Layer direction (RFC-VIEW-0001 §6.1):
|
||||
//! `CLI/Server → Application → Domain → ProtocolAdapter`, and
|
||||
//! `Application → Presentation → Renderer → Assets`.
|
||||
//! `main.rs` is only a dispatcher; integration tests and future server code use
|
||||
//! this library so there is never a second renderer or a second parser.
|
||||
//! Dependency direction (RFC-VIEW-0002 §5.1/§5.4):
|
||||
//! `CLI/Server → Reader(assemble) → Protocol(Analysis/Trace) + CoreClient`,
|
||||
//! and `Reader(model) → Renderer → Assets`. `Execution` may only be reached
|
||||
//! from an explicit `POST /api/runs` handler; page loads and export never form
|
||||
//! an execution edge.
|
||||
|
||||
pub mod app;
|
||||
pub mod assets;
|
||||
pub mod cli;
|
||||
pub mod config;
|
||||
pub mod core_client;
|
||||
pub mod document;
|
||||
pub mod error;
|
||||
pub mod export;
|
||||
pub mod presentation;
|
||||
pub mod project;
|
||||
pub mod render;
|
||||
pub mod semantic;
|
||||
pub mod protocol;
|
||||
pub mod reader;
|
||||
pub mod server;
|
||||
pub mod source_map;
|
||||
pub mod trace;
|
||||
pub mod version;
|
||||
|
||||
pub use cli::Cli;
|
||||
pub use error::{ViewError, ViewResult};
|
||||
|
||||
use cli::{ExportArgs, RuntimeOpts};
|
||||
use export::ExportOptions;
|
||||
use reader::assemble::DocumentService;
|
||||
|
||||
/// Dispatch a parsed CLI invocation. Returns the process exit code.
|
||||
pub fn run(cli: Cli) -> ViewResult<i32> {
|
||||
let opts = cli.runtime();
|
||||
cli::validate_bind(&opts.host, opts.unsafe_expose)
|
||||
.map_err(|detail| ViewError::BindDenied { detail })?;
|
||||
match cli.command {
|
||||
Some(cli::Command::Verify(args)) => app::verify(&opts, &args),
|
||||
Some(cli::Command::Export(args)) => app::export(&opts, &args),
|
||||
None => app::browse(&opts),
|
||||
Some(cli::Command::Verify(args)) => core_client::verify_command(&opts, &args),
|
||||
Some(cli::Command::Export(args)) => export_command(&opts, &args),
|
||||
None => browse_command(&opts),
|
||||
}
|
||||
}
|
||||
|
||||
/// `marqdo view [PATH]`: open the read-only Live reader. Never executes.
|
||||
fn browse_command(opts: &RuntimeOpts) -> ViewResult<i32> {
|
||||
let path = opts
|
||||
.path
|
||||
.clone()
|
||||
.unwrap_or_else(|| std::path::PathBuf::from("."));
|
||||
let service = DocumentService::open(&path, opts.marqdo_bin.as_deref())?;
|
||||
crate::server::serve(service, opts)
|
||||
}
|
||||
|
||||
/// `marqdo view export PATH --out DIR`: static export through the same Reader
|
||||
/// model. The export path has no execution capability by type (RFC §5.4).
|
||||
fn export_command(opts: &RuntimeOpts, args: &ExportArgs) -> ViewResult<i32> {
|
||||
let path = args
|
||||
.path
|
||||
.clone()
|
||||
.or_else(|| opts.path.clone())
|
||||
.unwrap_or_else(|| std::path::PathBuf::from("."));
|
||||
let service = DocumentService::open(&path, opts.marqdo_bin.as_deref())?;
|
||||
let summary = export::export(
|
||||
&service,
|
||||
&ExportOptions {
|
||||
out: args.out.clone(),
|
||||
no_annotations: args.no_annotations,
|
||||
},
|
||||
)?;
|
||||
println!(
|
||||
"marqdo view export: {} page(s), {} file(s) → {}",
|
||||
summary.pages,
|
||||
summary.files,
|
||||
summary.out.display()
|
||||
);
|
||||
println!("manifest: sha256:{}", summary.manifest_sha256);
|
||||
println!("executed: false (纯静态导出,未运行任何文档)");
|
||||
Ok(0)
|
||||
}
|
||||
Reference in new issue
Block a user