Skip to content

Commit 2f0964e

Browse files
hyperpolymathHoTT-stuffgithub-advanced-security[bot]
authored
feat(sillybot): add thin docs-pipeline adapter (#720)
* feat(sillybot): add thin docs-pipeline adapter Add the bots/sillybot slot as a thin adapter over the pinned docs pipeline tools: docudactyl docs-ingest and recon-silly-ation reconcile. - canon/pin.toml pins both tools to full commits. - `sillybot scan --path DIR [--base REV]` exports the tree with git archive, ingests head (and base), runs reconcile and maps findings to the fleet shape (SB-<class>, file, line, severity, blocking). - With a base and no changed prose files, the scan is not_run. - Exit codes follow the fleet contract: 0 ran, 1 blocking finding, 2 error, 3 not run. Report-only (ADR 0002). - Unit and integration tests use stub tools and temp git repos. Fleet driver wiring, BotId and the report-back stub come later (DP12). * Potential fix for pull request finding 'Scan for AI applications' Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> Signed-off-by: Jonathan D.A. Jewell <6759885+hyperpolymath@users.noreply.github.com> --------- Signed-off-by: Jonathan D.A. Jewell <6759885+hyperpolymath@users.noreply.github.com> Co-authored-by: CLAUDE <355856132+HoTT-stuff@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent 5d486d5 commit 2f0964e

10 files changed

Lines changed: 1503 additions & 0 deletions

File tree

‎bots/sillybot/Cargo.lock‎

Lines changed: 416 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎bots/sillybot/Cargo.toml‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# SPDX-License-Identifier: MPL-2.0
2+
[package]
3+
name = "sillybot"
4+
version = "0.1.0"
5+
edition = "2021"
6+
license = "MPL-2.0"
7+
authors = ["Jonathan D.A. Jewell <j.d.a.jewell@open.ac.uk>"]
8+
description = "Thin adapter running docudactyl docs-ingest and recon-silly-ation reconcile at pinned commits and reporting docs findings to gitbot-fleet"
9+
repository = "https://github.com/hyperpolymath/gitbot-fleet"
10+
keywords = ["documentation", "audit", "gitbot-fleet"]
11+
categories = ["development-tools"]
12+
13+
[lib]
14+
name = "sillybot"
15+
path = "src/lib.rs"
16+
17+
[[bin]]
18+
name = "sillybot"
19+
path = "src/main.rs"
20+
21+
[dependencies]
22+
clap = { version = "4.6.1", features = ["derive"] }
23+
serde = { version = "1.0.228", features = ["derive"] }
24+
serde_json = "1.0.150"
25+
tempfile = "3.27.0"
26+
toml = "1.1.2"

‎bots/sillybot/canon/pin.toml‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# SPDX-License-Identifier: MPL-2.0
2+
#
3+
# The ONE commit of each engine sillybot accepts. sillybot runs two external
4+
# tools and owns no checking logic (sillybot spec v0, owner ruling DP5):
5+
#
6+
# docudactyl `docs-ingest` repo tree -> reconcile-input/v0 bundle
7+
# recon-silly-ation `reconcile` bundles -> findings/v0
8+
#
9+
# Neither tool prints its own source commit yet, so sillybot cannot check the
10+
# binary against this pin at run time the way ponsbot does. The pin is what
11+
# the build step (fleet wiring, DP12) must build. Until a tool stamps its
12+
# commit, a drifted binary is a known gap, recorded here and in lib.rs.
13+
#
14+
# Provenance: docudactyl main after #96 and #97 (docs-ingest and its review
15+
# fixes); recon-silly-ation main after #83 (reconcile v0) and #85 (design).
16+
#
17+
# To re-pin: change a commit and `pinned`, rebuild that tool there, run
18+
# `cargo test` in bots/sillybot.
19+
20+
[ingest]
21+
repo = "hyperpolymath/docudactyl"
22+
commit = "f8ed65f0979b6bb12cd9e2258bed993e2d0e9d7c"
23+
pinned = "2026-11-27"
24+
25+
[reconcile]
26+
repo = "hyperpolymath/recon-silly-ation"
27+
commit = "6b306c6e3ef2825f685817a206951f204a1b75de"
28+
pinned = "2026-11-27"

‎bots/sillybot/src/cli.rs‎

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// SPDX-License-Identifier: MPL-2.0
2+
//! CLI: `sillybot [--format text|json] scan --path DIR [--base REV] [--repo OWNER/NAME]`.
3+
4+
use clap::{Parser, Subcommand};
5+
use std::path::PathBuf;
6+
7+
/// Sillybot: gitbot-fleet adapter for docs consistency checks.
8+
#[derive(Parser, Debug)]
9+
#[command(name = "sillybot", version)]
10+
#[command(
11+
about = "Runs docudactyl docs-ingest and recon-silly-ation reconcile at pinned commits and reports docs findings to gitbot-fleet"
12+
)]
13+
#[command(
14+
long_about = "Sillybot exports HEAD (and --base, if given) of a git repository into a \
15+
private temporary directory, runs docs-ingest and reconcile on it, and prints the \
16+
findings. It never writes into the scanned tree. Report-only. Exit codes: 0 ran, no \
17+
blocking finding; 1 ran, at least one blocking finding; 2 error; 3 not run (a tool is \
18+
not installed, or no prose file changed against --base). On 2 and 3 the JSON output is \
19+
an object {status, reason}, never a findings array. Tools are found through \
20+
SILLYBOT_DOCS_INGEST and SILLYBOT_RECONCILE, else on PATH as docs-ingest and reconcile."
21+
)]
22+
pub struct Cli {
23+
#[command(subcommand)]
24+
pub command: Command,
25+
26+
/// Output format (text, json).
27+
#[arg(short, long, default_value = "text", global = true)]
28+
pub format: OutputFormat,
29+
}
30+
31+
/// Output format for results.
32+
#[derive(Debug, Clone, Copy, PartialEq, Eq, clap::ValueEnum)]
33+
pub enum OutputFormat {
34+
Text,
35+
Json,
36+
}
37+
38+
#[derive(Subcommand, Debug)]
39+
pub enum Command {
40+
/// Scan a git repository's HEAD and print the docs findings.
41+
Scan {
42+
/// Repository directory to scan (a git work tree).
43+
#[arg(long, default_value = ".")]
44+
path: PathBuf,
45+
46+
/// Base revision. Findings already present at the base are reported
47+
/// as inherited (info), and the scan is skipped when no prose file
48+
/// changed.
49+
#[arg(long)]
50+
base: Option<String>,
51+
52+
/// Repository name OWNER/NAME. Defaults to the GitHub origin remote.
53+
#[arg(long)]
54+
repo: Option<String>,
55+
56+
/// Pull request number passed through to reconcile.
57+
#[arg(long, default_value_t = 0)]
58+
pr: u64,
59+
60+
/// Seconds the whole scan may run before sillybot reports an error.
61+
#[arg(long, default_value_t = 300)]
62+
timeout: u64,
63+
},
64+
}
65+
66+
#[cfg(test)]
67+
mod tests {
68+
use super::*;
69+
use clap::CommandFactory;
70+
71+
#[test]
72+
fn test_cli_parses() {
73+
Cli::command().debug_assert();
74+
}
75+
}

‎bots/sillybot/src/lib.rs‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// SPDX-License-Identifier: MPL-2.0
2+
//! Sillybot: a thin adapter that runs two pinned external tools and reports
3+
//! docs-consistency findings to the gitbot-fleet report-back driver.
4+
//!
5+
//! - docudactyl `docs-ingest` turns a repository revision into a
6+
//! reconcile-input/v0 bundle,
7+
//! - recon-silly-ation `reconcile` turns one or two bundles into findings/v0.
8+
//!
9+
//! Nothing of either tool's logic lives here (sillybot spec v0, owner ruling
10+
//! DP5). The adapter only
11+
//! - exports the revisions it scans into a private temporary directory with
12+
//! `git archive`, so it never reads a dirty work tree and never writes into
13+
//! the scanned tree ([`runner`]),
14+
//! - maps the tools' failures to a status that is never a pass,
15+
//! - maps findings/v0 to the fleet finding shape ([`translator`]).
16+
//!
17+
//! Known gap: neither tool stamps its source commit in its output, so the
18+
//! pins in `canon/pin.toml` cannot be checked at run time ([`pin`]).
19+
20+
pub mod cli;
21+
pub mod pin;
22+
pub mod runner;
23+
pub mod translator;

‎bots/sillybot/src/main.rs‎

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// SPDX-License-Identifier: MPL-2.0
2+
//! sillybot entry point. See `lib.rs` and `cli.rs`.
3+
//!
4+
//! Output contract for `--format json` (what the report-back driver reads):
5+
//! - ran: a JSON array of findings (possibly empty), exit 0 (no blocking
6+
//! finding) or 1 (at least one blocking finding),
7+
//! - error: `{"status":"error","reason":"..."}`, exit 2,
8+
//! - not run: `{"status":"not_run","reason":"..."}`, exit 3.
9+
//!
10+
//! Nothing here ever prints an empty array for a scan that did not run.
11+
12+
use clap::Parser;
13+
use sillybot::cli::{Cli, Command, OutputFormat};
14+
use sillybot::runner::{scan, Outcome, Request};
15+
use sillybot::{pin, translator};
16+
use std::process::ExitCode;
17+
use std::time::Duration;
18+
19+
fn main() -> ExitCode {
20+
let cli = Cli::parse();
21+
let Command::Scan {
22+
path,
23+
base,
24+
repo,
25+
pr,
26+
timeout,
27+
} = cli.command;
28+
if let Err(e) = pin::pinned() {
29+
return report_not_ran(
30+
"error",
31+
&format!("canon/pin.toml is malformed: {e}"),
32+
cli.format,
33+
2,
34+
);
35+
}
36+
let req = Request {
37+
path,
38+
base,
39+
repo,
40+
pr,
41+
timeout: Duration::from_secs(timeout.max(1)),
42+
};
43+
match scan(&req) {
44+
Outcome::Ran(doc) => match translator::translate_report(&doc) {
45+
Ok(findings) => print_findings(&findings, cli.format),
46+
Err(e) => report_not_ran(
47+
"error",
48+
&format!("reconcile output is unusable: {e}"),
49+
cli.format,
50+
2,
51+
),
52+
},
53+
Outcome::Error(reason) => report_not_ran("error", &reason, cli.format, 2),
54+
Outcome::NotRun(reason) => report_not_ran("not_run", &reason, cli.format, 3),
55+
}
56+
}
57+
58+
fn print_findings(findings: &[translator::Finding], format: OutputFormat) -> ExitCode {
59+
match format {
60+
OutputFormat::Json => match serde_json::to_string_pretty(findings) {
61+
Ok(s) => println!("{s}"),
62+
Err(e) => return report_not_ran("error", &e.to_string(), format, 2),
63+
},
64+
OutputFormat::Text => {
65+
if findings.is_empty() {
66+
println!("No docs findings.");
67+
}
68+
for f in findings {
69+
println!(
70+
"{}:{} [{}] {} {}",
71+
f.file, f.line, f.rule_id, f.severity, f.message
72+
);
73+
}
74+
}
75+
}
76+
if findings.iter().any(|f| f.blocking) {
77+
ExitCode::from(1)
78+
} else {
79+
ExitCode::SUCCESS
80+
}
81+
}
82+
83+
fn report_not_ran(status: &str, reason: &str, format: OutputFormat, code: u8) -> ExitCode {
84+
match format {
85+
OutputFormat::Json => {
86+
println!(
87+
"{}",
88+
serde_json::json!({ "status": status, "reason": reason })
89+
)
90+
}
91+
OutputFormat::Text => println!("sillybot: {status}: {reason}"),
92+
}
93+
eprintln!("sillybot: {status}: {reason}");
94+
ExitCode::from(code)
95+
}

‎bots/sillybot/src/pin.rs‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// SPDX-License-Identifier: MPL-2.0
2+
//! The pinned engine commits, compiled in from `canon/pin.toml`.
3+
4+
use serde::Deserialize;
5+
6+
const PIN_TOML: &str = include_str!("../canon/pin.toml");
7+
8+
/// Both pins.
9+
#[derive(Debug, Clone, Deserialize)]
10+
pub struct Pins {
11+
pub ingest: Source,
12+
pub reconcile: Source,
13+
}
14+
15+
/// One `[table]` of `canon/pin.toml`.
16+
#[derive(Debug, Clone, Deserialize)]
17+
pub struct Source {
18+
pub repo: String,
19+
pub commit: String,
20+
pub pinned: String,
21+
}
22+
23+
/// The pins, parsed from the compiled-in `canon/pin.toml`. A malformed file
24+
/// is reported as an error by the caller, never a panic.
25+
pub fn pinned() -> Result<Pins, toml::de::Error> {
26+
toml::from_str(PIN_TOML)
27+
}
28+
29+
/// True for a full 40-hex lowercase commit.
30+
pub fn is_full_commit(s: &str) -> bool {
31+
s.len() == 40 && s.bytes().all(|b| matches!(b, b'0'..=b'9' | b'a'..=b'f'))
32+
}
33+
34+
#[cfg(test)]
35+
mod tests {
36+
use super::*;
37+
38+
#[test]
39+
fn pins_are_full_commits() -> Result<(), toml::de::Error> {
40+
let p = pinned()?;
41+
assert!(is_full_commit(&p.ingest.commit));
42+
assert!(is_full_commit(&p.reconcile.commit));
43+
assert_eq!(p.ingest.repo, "hyperpolymath/docudactyl");
44+
assert_eq!(p.reconcile.repo, "hyperpolymath/recon-silly-ation");
45+
Ok(())
46+
}
47+
}

0 commit comments

Comments
 (0)