Skip to content
Merged
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
7 changes: 5 additions & 2 deletions doc/agents/onboarding-an-agent.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ fleet agent enroll --kind <kind> --name <name> # once per seat
fleet agent next # each time you want work
```

- `<name>` is the agent's own stable name, the one the queue uses as worker
and lane: lowercase letters, digits, `.`, `_`, `-`.
- `<name>` is the agent's stable worker identity: lowercase letters,
digits, `.`, `_`, `-`. The queue uses that name as the worker. Unless
`--lane` is supplied, a queue-compatible lane name stays as-is; other
names get an unfiltered `any-<name-slug><stable alphabetic digest>` lane. For a designated
filtered lane, pass both its `--lane` and its assigned `--filter` expression.
- Enrolment registers your mailbox, tells you which intake rungs work from
your seat, and saves a profile so later verbs know who is asking.
- `fleet agent next` returns one task and the commands to run when it is
Expand Down
1 change: 1 addition & 0 deletions pkgs/fleet/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkgs/fleet/crates/fleet-agent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ description = "The fleet agent domain: one front door for any agent. Enrol a nam

[dependencies]
fleet-config = { workspace = true }
sha2 = { workspace = true }
# preserve_order: every verb prints JSON, and the key order is the shape.
serde_json = { version = "1", features = ["preserve_order"] }

Expand Down
46 changes: 44 additions & 2 deletions pkgs/fleet/crates/fleet-agent/src/next.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
//! of FDR-0012 keep an issue out.

use serde_json::{Value, json};
use sha2::{Digest, Sha256};

use crate::shortlist::{self, Entry, rank_of};
use crate::{
Expand Down Expand Up @@ -340,6 +341,47 @@ fn tried(list: &mut Vec<Value>, rung: &str, result: &str, why: impl Into<String>
list.push(json!({"rung": rung, "result": result, "why": why.into()}));
}

/// The queue validates lane IDs as a known family plus a lowercase
/// alphabetic suffix. Preserve a full lane ID supplied as the agent
/// name; otherwise give a standalone agent an unfiltered `any-*` lane.
pub(super) fn default_lane(agent: &str) -> String {
let families = [
"code",
"any",
"not-code",
"opencode",
"openchamber",
"nix",
"darwin-nix",
];
let is_lane = agent.rsplit_once('-').is_some_and(|(family, suffix)| {
families.contains(&family)
&& !suffix.is_empty()
&& suffix.bytes().all(|b| b.is_ascii_lowercase())
});
if is_lane {
return agent.to_string();
}
// Lane rows are bound to their first worker, so two worker names
// that normalize to the same slug must still get different lanes.
// Keep 128 digest bits encoded as letters (two a-p letters per byte).
let digest = Sha256::digest(agent.as_bytes());
let digest_suffix: String = digest[..16]
.iter()
.flat_map(|byte| [b'a' + (byte >> 4), b'a' + (byte & 0x0f)])
.map(char::from)
.collect();
let slug: String = agent
.chars()
.filter(|c| c.is_ascii_lowercase())
.take(20)
.collect();
format!(
"any-{}{digest_suffix}",
if slug.is_empty() { "agent" } else { &slug }
)
}

/// How many listed entries in a row may turn out stale in one run
/// before the shortlist rung gives way to the priority rung.
const MAX_STALE_ENTRIES: usize = 5;
Expand Down Expand Up @@ -384,7 +426,7 @@ pub fn next(world: &dyn World, args: &[String]) -> R<(Value, i32)> {
let agent = check_name("--agent", &agent)?;
let lane = match a.last("--lane") {
Some(l) => check_name("--lane", &l)?,
None => agent.clone(),
None => default_lane(&agent),
};
let repo = check_repo(&a.last("--repo").unwrap_or_else(|| DEFAULT_REPO.to_string()))?;
let low_water = a
Expand All @@ -399,7 +441,7 @@ pub fn next(world: &dyn World, args: &[String]) -> R<(Value, i32)> {
carried.push_str(&format!(" {flag} {}", crate::shell::sh_quote(&value)));
}
}
let again = format!("fleet agent next --agent {agent}{carried}");
let again = format!("fleet agent next --agent {agent} --lane {lane}{carried}");
let mut log: Vec<Value> = Vec::new();
let answer = |rung: &str, task: Value, then: Vec<String>, log: Vec<Value>| {
(
Expand Down
37 changes: 35 additions & 2 deletions pkgs/fleet/crates/fleet-agent/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,35 @@ fn an_empty_mailbox_falls_to_a_queue_claim() {
));
}

#[test]
fn standalone_agent_gets_a_queue_compatible_unfiltered_default_lane() {
let fake = Fake::new();
fake.on(INBOX, vec![empty_inbox()]).on(
CLAIM,
vec![ok(
json!({"id": 10812, "queue": "fleet", "status": "claimed", "title": "Next task"}),
)],
);
let (out, code) = run(&fake, &["next", "--agent", "shed"]);
assert_eq!(code, EXIT_OK);
assert_eq!(out["rung"], "queue");
assert!(fake.called("fleet queue claim --worker shed --lane any-shed"));
assert!(out["then"][0].as_str().unwrap().contains("--lane any-shed"));
assert!(out["then"][1].as_str().unwrap().contains("--lane any-shed"));
}

#[test]
fn a_known_lane_agent_name_keeps_its_lane_identity() {
assert_eq!(crate::next::default_lane("code-b"), "code-b");
let muse_three = crate::next::default_lane("muse-3");
let muse_four = crate::next::default_lane("muse-4");
assert!(muse_three.starts_with("any-muse"));
assert!(muse_four.starts_with("any-muse"));
assert_ne!(muse_three, muse_four);
assert_eq!(muse_three, crate::next::default_lane("muse-3"));
assert!(crate::next::default_lane("oc-go-1").starts_with("any-ocgo"));
}

#[test]
fn legs_that_are_down_are_named_and_the_shortlist_answers() {
let fake = Fake::new();
Expand Down Expand Up @@ -1593,6 +1622,7 @@ fn follow_up_commands_carry_the_list_repo_and_profile_the_caller_chose() {
);
assert_eq!(out["rung"], "refill");
let quoted = shell::sh_quote(&list_text);
let lane = crate::next::default_lane("muse-3");
assert!(quoted.starts_with('\''), "a path with a space is quoted");
let then: Vec<String> = out["then"]
.as_array()
Expand All @@ -1614,7 +1644,7 @@ fn follow_up_commands_carry_the_list_repo_and_profile_the_caller_chose() {
assert_eq!(
then[2],
format!(
"fleet agent next --agent muse-3 --repo developing-today/opencode --shortlist {quoted}"
"fleet agent next --agent muse-3 --lane {lane} --repo developing-today/opencode --shortlist {quoted}"
)
);
// The marker went into the chosen file, not the default one.
Expand All @@ -1627,7 +1657,10 @@ fn follow_up_commands_carry_the_list_repo_and_profile_the_caller_chose() {
.on(CLAIM, vec![no_claim()])
.on("gh api", vec![ok(json!([]))]);
let (out, _) = run(&plain, &["next", "--agent", "muse-3"]);
assert_eq!(out["then"][2], "fleet agent next --agent muse-3");
assert_eq!(
out["then"][2],
format!("fleet agent next --agent muse-3 --lane {lane}")
);
}

#[test]
Expand Down