forked from vhaudiquet/rhema-claw
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
78fdec4f49 | ||
|
|
c65f7fe962 |
No files matched your search
@@ -126,6 +126,30 @@ fn interactive_dispatch() -> DispatcherConfig {
|
||||
}
|
||||
}
|
||||
|
||||
/// The forge dispatcher's timing: the library defaults, except the lease
|
||||
/// TTL.
|
||||
///
|
||||
/// A forge turn is not a chat step. The handler clones a repository,
|
||||
/// reads it, and may build and test a fix — tens of minutes of wall
|
||||
/// clock — and nothing renews the lease once the turn is under way:
|
||||
/// `SessionContext::poll_inbox` renews, and the handler calls it once, at
|
||||
/// the start; the commit hook that runs between tool calls *checkpoints*,
|
||||
/// which fails on a lapsed lease instead of extending one. So the TTL is
|
||||
/// a hard ceiling on a whole turn: cross it and the turn dies on its next
|
||||
/// tool call, after which the driver's own checkpoint and release both
|
||||
/// report `Expired` and the key ends with no outcome recorded — a silent
|
||||
/// kill, indistinguishable from a pass that found nothing.
|
||||
///
|
||||
/// `DispatcherConfig::default`'s ten minutes are the spec's example
|
||||
/// values, sized for a single agent step. An hour matches the
|
||||
/// interactive lane's choice for the same reason: the work is long.
|
||||
pub fn forge_dispatch() -> DispatcherConfig {
|
||||
DispatcherConfig {
|
||||
lease_ttl_millis: 3_600_000,
|
||||
..DispatcherConfig::default()
|
||||
}
|
||||
}
|
||||
|
||||
/// The resident daemon: the extension set's sources (the forge watches,
|
||||
/// the task scheduler, the coding jobs, the calendar reminders), the
|
||||
/// three drivers, and the HTTP surface.
|
||||
@@ -154,8 +178,8 @@ impl Daemon {
|
||||
/// Assembles the daemon over `config`: the shared SQLite store, one
|
||||
/// source per forge kind reading the watch table, the interactive
|
||||
/// dispatcher, and both handlers running `provider`. `dispatch` is
|
||||
/// the forge dispatcher's timing — the resident loop uses the
|
||||
/// defaults, `--once` zeroes the debounce.
|
||||
/// the forge dispatcher's timing — [`forge_dispatch`] in both shapes,
|
||||
/// with `--once` zeroing the debounce.
|
||||
pub fn build(
|
||||
config: &ClawConfig,
|
||||
backends: Arc<BackendRegistry>,
|
||||
@@ -580,7 +604,7 @@ pub async fn run_once(
|
||||
) -> Result<TickReport, ClawError> {
|
||||
let dispatch = DispatcherConfig {
|
||||
debounce_window_millis: 0,
|
||||
..DispatcherConfig::default()
|
||||
..forge_dispatch()
|
||||
};
|
||||
let daemon = Daemon::build(config, backends, dispatch)?;
|
||||
daemon.bootstrap().await?;
|
||||
@@ -591,6 +615,20 @@ pub async fn run_once(
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn the_forge_dispatcher_leases_for_a_turn_not_a_step() {
|
||||
let dispatch = forge_dispatch();
|
||||
assert_eq!(
|
||||
dispatch.lease_ttl_millis, 3_600_000,
|
||||
"an hour: a turn clones, reads, builds and tests"
|
||||
);
|
||||
assert_eq!(
|
||||
dispatch.debounce_window_millis,
|
||||
DispatcherConfig::default().debounce_window_millis,
|
||||
"the rest stays the library's defaults"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_interactive_dispatcher_dispatches_now_and_leases_long() {
|
||||
let dispatch = interactive_dispatch();
|
||||
|
||||
@@ -108,7 +108,7 @@ pub use bootstrap::{
|
||||
render_system,
|
||||
};
|
||||
pub use config::{ClawConfig, ConfigError};
|
||||
pub use daemon::{ClawError, Daemon, TickReport, run_once};
|
||||
pub use daemon::{ClawError, Daemon, TickReport, forge_dispatch, run_once};
|
||||
pub use environment::write_report;
|
||||
pub use extension::{ClawExtension, ExtensionDeps, Extensions, Lanes};
|
||||
pub use forge::ForgeSource;
|
||||
|
||||
@@ -8,8 +8,8 @@ use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
|
||||
use clap::Parser;
|
||||
use rhema_claw::{ClawConfig, ClawError, Daemon, run_once};
|
||||
use rhema_rsd::{DispatcherConfig, Outcome};
|
||||
use rhema_claw::{ClawConfig, ClawError, Daemon, forge_dispatch, run_once};
|
||||
use rhema_rsd::Outcome;
|
||||
|
||||
/// `rhema-claw` — the resident forge-watching agent daemon.
|
||||
#[derive(Debug, Parser)]
|
||||
@@ -135,7 +135,7 @@ async fn run(args: Args) -> Result<(), ClawError> {
|
||||
// reads it next to the config that turns it on.
|
||||
config.validate_surface()?;
|
||||
eprintln!("[claw] note: resident sessions run tool calls without approval prompts");
|
||||
let daemon = Daemon::build(&config, backends, DispatcherConfig::default())?;
|
||||
let daemon = Daemon::build(&config, backends, forge_dispatch())?;
|
||||
daemon.run().await
|
||||
}
|
||||
}
|
||||
|
||||
@@ -287,7 +287,9 @@ struct WireComment {
|
||||
/// One row of the account notifications feed.
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
struct WireNotification {
|
||||
#[serde(default)]
|
||||
/// GitHub sends this one as a JSON string, unlike every other id in
|
||||
/// this adapter; see [`lenient_id`].
|
||||
#[serde(default, deserialize_with = "lenient_id")]
|
||||
id: Option<i64>,
|
||||
#[serde(default)]
|
||||
reason: Option<String>,
|
||||
@@ -452,6 +454,32 @@ fn parent_number(url: &str) -> Option<u64> {
|
||||
url.trim_end_matches('/').rsplit('/').next()?.parse().ok()
|
||||
}
|
||||
|
||||
/// An id that arrives as either a JSON number or a JSON string.
|
||||
///
|
||||
/// GitHub's notifications feed is the odd one out: `id` there is a
|
||||
/// string (`"27210544329"`), while issues, comments and reviews send
|
||||
/// numbers. One row that refuses to decode fails the whole page, so the
|
||||
/// notification id is read leniently.
|
||||
fn lenient_id<'de, D>(deserializer: D) -> Result<Option<i64>, D::Error>
|
||||
where
|
||||
D: serde::Deserializer<'de>,
|
||||
{
|
||||
#[derive(Deserialize)]
|
||||
#[serde(untagged)]
|
||||
enum IdWire {
|
||||
Number(i64),
|
||||
Text(String),
|
||||
}
|
||||
|
||||
match Option::<IdWire>::deserialize(deserializer)? {
|
||||
None => Ok(None),
|
||||
Some(IdWire::Number(n)) => Ok(Some(n)),
|
||||
Some(IdWire::Text(text)) => text.trim().parse().map(Some).map_err(|_| {
|
||||
serde::de::Error::custom(format!("notification id is not a number: {text}"))
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
/// The notification a notifications row carries. GitHub's `reason` field
|
||||
/// is the row's whole why; the subject's API URL yields the thread.
|
||||
fn notification_event(row: &WireNotification) -> Result<Option<Notification>, ForgeError> {
|
||||
@@ -870,4 +898,61 @@ mod tests {
|
||||
assert_eq!(event.raw["node_id"], "MDU6SXNzdWUxMDA3");
|
||||
assert!(event.raw.get("title").is_none());
|
||||
}
|
||||
fn notification(json: &str) -> WireNotification {
|
||||
serde_json::from_str(json).expect("notification fixture parses")
|
||||
}
|
||||
|
||||
// Captured from the live feed on 2026-11-21: `id` there is a string,
|
||||
// and one such row used to fail the whole page's decode.
|
||||
#[test]
|
||||
fn a_notification_id_sent_as_a_string_decodes() {
|
||||
let row = notification(
|
||||
r#"{"id": "27210544329", "unread": true, "reason": "mention",
|
||||
"updated_at": "2026-11-21T22:33:00Z", "last_read_at": null,
|
||||
"subject": {"title": "Snap build failed for v2.5.1",
|
||||
"url": "https://api.github.com/repos/acme/widgets/issues/10",
|
||||
"latest_comment_url": "https://api.github.com/repos/acme/widgets/issues/comments/7070",
|
||||
"type": "Issue"},
|
||||
"repository": {"id": 1239653662, "full_name": "acme/widgets"},
|
||||
"url": "https://api.github.com/notifications/threads/27210544329"}"#,
|
||||
);
|
||||
let notification = notification_event(&row)
|
||||
.expect("maps")
|
||||
.expect("carries a notification");
|
||||
assert_eq!(notification.number, 10);
|
||||
assert_eq!(notification.repo, RepoRef::new("acme", "widgets"));
|
||||
assert_eq!(notification.reason, NotificationReason::Mention);
|
||||
assert!(!notification.is_pr);
|
||||
assert_eq!(
|
||||
notification.id,
|
||||
"github:notification:27210544329@2026-11-21T22:33:00Z"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_notification_id_sent_as_a_number_still_decodes() {
|
||||
let row = notification(
|
||||
r#"{"id": 42188, "reason": "review_requested",
|
||||
"updated_at": "2026-10-08T12:00:00Z",
|
||||
"subject": {"title": "tidy the parser", "type": "PullRequest",
|
||||
"url": "https://api.github.com/repos/acme/widgets/pulls/8"},
|
||||
"repository": {"full_name": "acme/widgets"}}"#,
|
||||
);
|
||||
let notification = notification_event(&row)
|
||||
.expect("maps")
|
||||
.expect("carries a notification");
|
||||
assert_eq!(notification.number, 8);
|
||||
assert!(notification.is_pr);
|
||||
assert_eq!(
|
||||
notification.id,
|
||||
"github:notification:42188@2026-10-08T12:00:00Z"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_notification_id_that_is_not_a_number_is_a_parse_error() {
|
||||
let err = serde_json::from_str::<WireNotification>(r#"{"id": "not-a-number"}"#)
|
||||
.expect_err("a junk id is loud, not silently dropped");
|
||||
assert!(err.to_string().contains("not-a-number"), "got: {err}");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user