Repository navigation
feat(sillybot): add thin docs-pipeline adapter #720
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f2e73e2
feat(sillybot): add thin docs-pipeline adapter
HoTT-stuff 0ee862a
Merge branch 'main' into docs-pipeline/sillybot-adapter
hyperpolymath 1c29143
Merge branch 'main' into docs-pipeline/sillybot-adapter
hyperpolymath 41c9e5e
Merge branch 'main' into docs-pipeline/sillybot-adapter
hyperpolymath 4939e15
Merge branch 'main' into docs-pipeline/sillybot-adapter
hyperpolymath 269a785
Potential fix for pull request finding 'Scan for AI applications'
hyperpolymath 365a9f3
Merge branch 'main' into docs-pipeline/sillybot-adapter
hyperpolymath File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| # SPDX-License-Identifier: MPL-2.0 | ||
| [package] | ||
| name = "sillybot" | ||
| version = "0.1.0" | ||
| edition = "2021" | ||
| license = "MPL-2.0" | ||
| authors = ["Jonathan D.A. Jewell <j.d.a.jewell@open.ac.uk>"] | ||
| description = "Thin adapter running docudactyl docs-ingest and recon-silly-ation reconcile at pinned commits and reporting docs findings to gitbot-fleet" | ||
| repository = "https://github.com/hyperpolymath/gitbot-fleet" | ||
| keywords = ["documentation", "audit", "gitbot-fleet"] | ||
| categories = ["development-tools"] | ||
|
|
||
| [lib] | ||
| name = "sillybot" | ||
| path = "src/lib.rs" | ||
|
|
||
| [[bin]] | ||
| name = "sillybot" | ||
| path = "src/main.rs" | ||
|
|
||
| [dependencies] | ||
| clap = { version = "4.6.1", features = ["derive"] } | ||
| serde = { version = "1.0.228", features = ["derive"] } | ||
| serde_json = "1.0.150" | ||
| tempfile = "3.27.0" | ||
| toml = "1.1.2" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # SPDX-License-Identifier: MPL-2.0 | ||
| # | ||
| # The ONE commit of each engine sillybot accepts. sillybot runs two external | ||
| # tools and owns no checking logic (sillybot spec v0, owner ruling DP5): | ||
| # | ||
| # docudactyl `docs-ingest` repo tree -> reconcile-input/v0 bundle | ||
| # recon-silly-ation `reconcile` bundles -> findings/v0 | ||
| # | ||
| # Neither tool prints its own source commit yet, so sillybot cannot check the | ||
| # binary against this pin at run time the way ponsbot does. The pin is what | ||
| # the build step (fleet wiring, DP12) must build. Until a tool stamps its | ||
| # commit, a drifted binary is a known gap, recorded here and in lib.rs. | ||
| # | ||
| # Provenance: docudactyl main after #96 and #97 (docs-ingest and its review | ||
| # fixes); recon-silly-ation main after #83 (reconcile v0) and #85 (design). | ||
| # | ||
| # To re-pin: change a commit and `pinned`, rebuild that tool there, run | ||
| # `cargo test` in bots/sillybot. | ||
|
|
||
| [ingest] | ||
| repo = "hyperpolymath/docudactyl" | ||
| commit = "f8ed65f0979b6bb12cd9e2258bed993e2d0e9d7c" | ||
| pinned = "2026-11-27" | ||
|
|
||
| [reconcile] | ||
| repo = "hyperpolymath/recon-silly-ation" | ||
| commit = "6b306c6e3ef2825f685817a206951f204a1b75de" | ||
| pinned = "2026-11-27" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| // SPDX-License-Identifier: MPL-2.0 | ||
| //! CLI: `sillybot [--format text|json] scan --path DIR [--base REV] [--repo OWNER/NAME]`. | ||
|
|
||
| use clap::{Parser, Subcommand}; | ||
| use std::path::PathBuf; | ||
|
|
||
| /// Sillybot: gitbot-fleet adapter for docs consistency checks. | ||
| #[derive(Parser, Debug)] | ||
| #[command(name = "sillybot", version)] | ||
| #[command( | ||
| about = "Runs docudactyl docs-ingest and recon-silly-ation reconcile at pinned commits and reports docs findings to gitbot-fleet" | ||
| )] | ||
| #[command( | ||
| long_about = "Sillybot exports HEAD (and --base, if given) of a git repository into a \ | ||
| private temporary directory, runs docs-ingest and reconcile on it, and prints the \ | ||
| findings. It never writes into the scanned tree. Report-only. Exit codes: 0 ran, no \ | ||
| blocking finding; 1 ran, at least one blocking finding; 2 error; 3 not run (a tool is \ | ||
| not installed, or no prose file changed against --base). On 2 and 3 the JSON output is \ | ||
| an object {status, reason}, never a findings array. Tools are found through \ | ||
| SILLYBOT_DOCS_INGEST and SILLYBOT_RECONCILE, else on PATH as docs-ingest and reconcile." | ||
| )] | ||
| pub struct Cli { | ||
| #[command(subcommand)] | ||
| pub command: Command, | ||
|
|
||
| /// Output format (text, json). | ||
| #[arg(short, long, default_value = "text", global = true)] | ||
| pub format: OutputFormat, | ||
| } | ||
|
|
||
| /// Output format for results. | ||
| #[derive(Debug, Clone, Copy, PartialEq, Eq, clap::ValueEnum)] | ||
| pub enum OutputFormat { | ||
| Text, | ||
| Json, | ||
| } | ||
|
|
||
| #[derive(Subcommand, Debug)] | ||
| pub enum Command { | ||
| /// Scan a git repository's HEAD and print the docs findings. | ||
| Scan { | ||
| /// Repository directory to scan (a git work tree). | ||
| #[arg(long, default_value = ".")] | ||
| path: PathBuf, | ||
|
|
||
| /// Base revision. Findings already present at the base are reported | ||
| /// as inherited (info), and the scan is skipped when no prose file | ||
| /// changed. | ||
| #[arg(long)] | ||
| base: Option<String>, | ||
|
|
||
| /// Repository name OWNER/NAME. Defaults to the GitHub origin remote. | ||
| #[arg(long)] | ||
| repo: Option<String>, | ||
|
|
||
| /// Pull request number passed through to reconcile. | ||
| #[arg(long, default_value_t = 0)] | ||
| pr: u64, | ||
|
|
||
| /// Seconds the whole scan may run before sillybot reports an error. | ||
| #[arg(long, default_value_t = 300)] | ||
| timeout: u64, | ||
| }, | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
| use clap::CommandFactory; | ||
|
|
||
| #[test] | ||
| fn test_cli_parses() { | ||
| Cli::command().debug_assert(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| // SPDX-License-Identifier: MPL-2.0 | ||
| //! Sillybot: a thin adapter that runs two pinned external tools and reports | ||
| //! docs-consistency findings to the gitbot-fleet report-back driver. | ||
| //! | ||
| //! - docudactyl `docs-ingest` turns a repository revision into a | ||
| //! reconcile-input/v0 bundle, | ||
| //! - recon-silly-ation `reconcile` turns one or two bundles into findings/v0. | ||
| //! | ||
| //! Nothing of either tool's logic lives here (sillybot spec v0, owner ruling | ||
| //! DP5). The adapter only | ||
| //! - exports the revisions it scans into a private temporary directory with | ||
| //! `git archive`, so it never reads a dirty work tree and never writes into | ||
| //! the scanned tree ([`runner`]), | ||
| //! - maps the tools' failures to a status that is never a pass, | ||
| //! - maps findings/v0 to the fleet finding shape ([`translator`]). | ||
| //! | ||
| //! Known gap: neither tool stamps its source commit in its output, so the | ||
| //! pins in `canon/pin.toml` cannot be checked at run time ([`pin`]). | ||
|
|
||
| pub mod cli; | ||
| pub mod pin; | ||
| pub mod runner; | ||
| pub mod translator; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| // SPDX-License-Identifier: MPL-2.0 | ||
| //! sillybot entry point. See `lib.rs` and `cli.rs`. | ||
| //! | ||
| //! Output contract for `--format json` (what the report-back driver reads): | ||
| //! - ran: a JSON array of findings (possibly empty), exit 0 (no blocking | ||
| //! finding) or 1 (at least one blocking finding), | ||
| //! - error: `{"status":"error","reason":"..."}`, exit 2, | ||
| //! - not run: `{"status":"not_run","reason":"..."}`, exit 3. | ||
| //! | ||
| //! Nothing here ever prints an empty array for a scan that did not run. | ||
|
|
||
| use clap::Parser; | ||
| use sillybot::cli::{Cli, Command, OutputFormat}; | ||
| use sillybot::runner::{scan, Outcome, Request}; | ||
| use sillybot::{pin, translator}; | ||
| use std::process::ExitCode; | ||
| use std::time::Duration; | ||
|
|
||
| fn main() -> ExitCode { | ||
| let cli = Cli::parse(); | ||
| let Command::Scan { | ||
| path, | ||
| base, | ||
| repo, | ||
| pr, | ||
| timeout, | ||
| } = cli.command; | ||
| if let Err(e) = pin::pinned() { | ||
| return report_not_ran( | ||
| "error", | ||
| &format!("canon/pin.toml is malformed: {e}"), | ||
| cli.format, | ||
| 2, | ||
| ); | ||
| } | ||
| let req = Request { | ||
| path, | ||
| base, | ||
| repo, | ||
| pr, | ||
| timeout: Duration::from_secs(timeout.max(1)), | ||
| }; | ||
| match scan(&req) { | ||
| Outcome::Ran(doc) => match translator::translate_report(&doc) { | ||
| Ok(findings) => print_findings(&findings, cli.format), | ||
| Err(e) => report_not_ran( | ||
| "error", | ||
| &format!("reconcile output is unusable: {e}"), | ||
| cli.format, | ||
| 2, | ||
| ), | ||
| }, | ||
| Outcome::Error(reason) => report_not_ran("error", &reason, cli.format, 2), | ||
| Outcome::NotRun(reason) => report_not_ran("not_run", &reason, cli.format, 3), | ||
| } | ||
| } | ||
|
|
||
| fn print_findings(findings: &[translator::Finding], format: OutputFormat) -> ExitCode { | ||
| match format { | ||
| OutputFormat::Json => match serde_json::to_string_pretty(findings) { | ||
| Ok(s) => println!("{s}"), | ||
| Err(e) => return report_not_ran("error", &e.to_string(), format, 2), | ||
| }, | ||
| OutputFormat::Text => { | ||
| if findings.is_empty() { | ||
| println!("No docs findings."); | ||
| } | ||
| for f in findings { | ||
| println!( | ||
| "{}:{} [{}] {} {}", | ||
| f.file, f.line, f.rule_id, f.severity, f.message | ||
| ); | ||
| } | ||
| } | ||
| } | ||
| if findings.iter().any(|f| f.blocking) { | ||
| ExitCode::from(1) | ||
| } else { | ||
| ExitCode::SUCCESS | ||
| } | ||
| } | ||
|
|
||
| fn report_not_ran(status: &str, reason: &str, format: OutputFormat, code: u8) -> ExitCode { | ||
| match format { | ||
| OutputFormat::Json => { | ||
| println!( | ||
| "{}", | ||
| serde_json::json!({ "status": status, "reason": reason }) | ||
| ) | ||
| } | ||
| OutputFormat::Text => println!("sillybot: {status}: {reason}"), | ||
| } | ||
| eprintln!("sillybot: {status}: {reason}"); | ||
| ExitCode::from(code) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| // SPDX-License-Identifier: MPL-2.0 | ||
| //! The pinned engine commits, compiled in from `canon/pin.toml`. | ||
|
|
||
| use serde::Deserialize; | ||
|
|
||
| const PIN_TOML: &str = include_str!("../canon/pin.toml"); | ||
|
|
||
| /// Both pins. | ||
| #[derive(Debug, Clone, Deserialize)] | ||
| pub struct Pins { | ||
| pub ingest: Source, | ||
| pub reconcile: Source, | ||
| } | ||
|
|
||
| /// One `[table]` of `canon/pin.toml`. | ||
| #[derive(Debug, Clone, Deserialize)] | ||
| pub struct Source { | ||
| pub repo: String, | ||
| pub commit: String, | ||
| pub pinned: String, | ||
| } | ||
|
|
||
| /// The pins, parsed from the compiled-in `canon/pin.toml`. A malformed file | ||
| /// is reported as an error by the caller, never a panic. | ||
| pub fn pinned() -> Result<Pins, toml::de::Error> { | ||
| toml::from_str(PIN_TOML) | ||
| } | ||
|
|
||
| /// True for a full 40-hex lowercase commit. | ||
| pub fn is_full_commit(s: &str) -> bool { | ||
| s.len() == 40 && s.bytes().all(|b| matches!(b, b'0'..=b'9' | b'a'..=b'f')) | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn pins_are_full_commits() -> Result<(), toml::de::Error> { | ||
| let p = pinned()?; | ||
| assert!(is_full_commit(&p.ingest.commit)); | ||
| assert!(is_full_commit(&p.reconcile.commit)); | ||
| assert_eq!(p.ingest.repo, "hyperpolymath/docudactyl"); | ||
| assert_eq!(p.reconcile.repo, "hyperpolymath/recon-silly-ation"); | ||
| Ok(()) | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.