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
3 changes: 2 additions & 1 deletion docs/UI_BEHAVIOR.md
Original file line number Diff line number Diff line change
Expand Up @@ -1234,11 +1234,12 @@ Its own wide layout is a list on the left and the highlighted row's detail on th
### What a query finds

A query finds an agent, project, checkout, device, issue or pull request by name, and an issue or pull request by `#number` (`#273`, or `273`); an exact number match lists first, as its own row, issue and pull request separately.
An agent is found by its title, by the name Herdr knows it by (`hide agent spawn --name`, `herdr agent rename`), by its place and by its state sentence; the core carries the Herdr name on the agent row (`herdr_name`), on this machine and on a device alike, and leaves it out when Herdr has none or has only a name Hide made up from a pane id (a task's `hide-claude-w9j-p52`, a wake's or a fork's), which would print the id the rule below keeps off every row.
A query holding `:`, as every pane's Herdr id does (`w9J:p52`, as Copy pane ID or `$HERDR_PANE_ID` gives it), lists first the agents whose id holds it in its case, on every device, the whole id before longer ones (`:p5` lists `w9J:p5`, then `w9J:p52`); without a `:` no id matches, and no row prints the id.
Only digits in the query match a number by substring on other rows.
The rows are `Issues`, `Pull requests`, `Agents`, `Projects`, `Checkouts` and `Devices` (while another device is registered), then `Commands` holding `에이전트 시작…` and `GitHub`; a group stands where its best result ranked and keeps its results in rank order, so grouping never moves the best match off the first row.
Search covers every connected device; a result not on the device in front carries that device's chip after its title, and choosing it brings that device forward with it.
An agent row is the agent's own mark, its title, and its place and state under it; an issue or pull request row carries its number, state and, for a pull request, its CI.
An agent row is the agent's own mark, its title, and under it its Herdr name, place and state (`observer-instant-pane-topology · herdr-ide › main · Working`); a Herdr name the title already reads as, ignoring case, or no name at all draws nothing for it; an issue or pull request row carries its number, state and, for a pull request, its CI.

`브라우저에서 URL 열기` is listed first while the query is a web address: one written with `http://` or `https://`, or a loopback host a dev server runs on (`localhost:5173`, `127.0.0.1:3000`), read by the same rule as the View address field (`addressUrl`); any other text is a name to search.
Enter opens the address as a browser display in the Workspace in front, in its active View area, as New tab does.
Expand Down
4 changes: 4 additions & 0 deletions herdr-core/src/agent_sleep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ impl SleepRecord {
.clone()
.unwrap_or_else(|| pane_id.to_owned()),
),
name: self.agent_name.clone(),
pane_id: Some(pane_id.to_owned()),
workspace_label: workspace_label.or_else(|| Some(self.workspace_label.clone())),
cwd: self.cwd.clone(),
Expand Down Expand Up @@ -518,6 +519,7 @@ mod tests {
fn agent(pane_id: &str) -> SidebarAgentSnapshot {
SidebarAgentSnapshot {
id: pane_id.to_owned(),
herdr_name: None,
pane_id: pane_id.to_owned(),
workspace_label: "Fixture".to_owned(),
identity_label: "Refactor the parser".to_owned(),
Expand Down Expand Up @@ -726,6 +728,7 @@ mod tests {
assert_eq!(
(
row.id.as_str(),
row.herdr_name.as_deref(),
row.pane_id.as_str(),
row.identity_label.as_str(),
row.session_id.as_deref(),
Expand All @@ -735,6 +738,7 @@ mod tests {
),
(
"reviewer",
Some("reviewer"),
"w1:p2",
"Refactor the parser",
Some("session-a"),
Expand Down
72 changes: 70 additions & 2 deletions herdr-core/src/fork.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub(crate) fn valid_agent_name(name: &str) -> bool {
/// keeps two forks of different panes apart after the truncation.
pub fn fork_name(parent_pane_id: &str, nonce: &str) -> String {
bounded_name(format!(
"fork-{}-{}",
"{FORK_PREFIX}{}-{}",
sanitize(parent_pane_id),
sanitize(nonce)
))
Expand All @@ -109,6 +109,43 @@ pub fn task_agent_name(kind: &str, pane_id: &str) -> String {
bounded_name(format!("hide-{}-{}", sanitize(kind), sanitize(pane_id)))
}

/// Every fork name's head, which `bounded_name` keeps.
const FORK_PREFIX: &str = "fork-";

/// Whether Hide made `name` up for the `kind` agent in `pane_id` rather than
/// someone giving it: that pane's task or wake name, or a fork's, which
/// spells its parent's pane and a sequence. Such a name only spells a pane
/// id, so ⌘K neither draws nor finds an agent by it.
pub(crate) fn hide_made_name(name: &str, kind: &str, pane_id: &str) -> bool {
name == task_agent_name(kind, pane_id) || name == wake_name(pane_id) || is_fork_name(name)
}

/// Whether `name` has the shape `fork_name` gives it: the parent's pane, the
/// fork's sequence and its time in milliseconds, or that cut by
/// `bounded_name` to the limit with a digest at its end. The fork's parent is
/// not known from the child's row, so the shape is all there is to compare;
/// a name someone gave that merely starts with `fork-` keeps its name.
fn is_fork_name(name: &str) -> bool {
let Some(rest) = name.strip_prefix(FORK_PREFIX) else {
return false;
};
let digits = |part: &str| !part.is_empty() && part.bytes().all(|byte| byte.is_ascii_digit());
let mut parts = rest.rsplitn(3, '-');
let whole = matches!(
(parts.next(), parts.next(), parts.next()),
(Some(millis), Some(sequence), Some(parent))
if digits(millis) && digits(sequence) && !parent.is_empty()
);
let cut = name.len() == MAX_NAME_CHARACTERS
&& name.rsplit_once('-').is_some_and(|(_, digest)| {
digest.len() == DIGEST_CHARACTERS
&& digest
.bytes()
.all(|byte| matches!(byte, b'0'..=b'9' | b'a'..=b'f'))
});
whole || cut
}

fn bounded_name(full: String) -> String {
if full.len() <= MAX_NAME_CHARACTERS {
return full;
Expand All @@ -118,14 +155,21 @@ fn bounded_name(full: String) -> String {
format!("{}-{}", &full[..head], digest)
}

/// How many hex characters `digest_of` writes.
const DIGEST_CHARACTERS: usize = 12;

/// Twelve hex characters of a hash of the whole name, so what truncation drops
/// still tells two names apart. `DefaultHasher::new` is seeded with fixed
/// keys, so the same name gives the same digest in every process.
fn digest_of(value: &str) -> String {
use std::hash::{Hash, Hasher};
let mut hasher = std::collections::hash_map::DefaultHasher::new();
value.hash(&mut hasher);
format!("{:012x}", hasher.finish() & 0xffff_ffff_ffff)
format!(
"{:0width$x}",
hasher.finish() & 0xffff_ffff_ffff,
width = DIGEST_CHARACTERS
)
}

fn sanitize(value: &str) -> String {
Expand Down Expand Up @@ -218,6 +262,30 @@ mod tests {
assert_eq!(fork_name("w1:p2", "abc"), "fork-w1-p2-abc");
}

/// ⌘K draws and finds an agent by a name someone gave it, never by one
/// Hide made up from a pane id.
#[test]
fn only_the_names_hide_made_from_a_pane_read_as_hide_made() {
let long_parent = "workspace-with-a-very-long-name:pane-42";
for made in [
task_agent_name("claude", "w4:p1"),
wake_name("w4:p1"),
fork_name("w2X:p2F", "2-1788624371518"),
fork_name(long_parent, "17-1788624371518"),
] {
assert!(hide_made_name(&made, "claude", "w4:p1"), "{made:?}");
}
for given in [
"observer-instant-pane-topology",
"fork-reviewer",
"fork-w1-p2-review",
"hide-claude-w8-p1",
"hide-codex-w4-p1",
] {
assert!(!hide_made_name(given, "claude", "w4:p1"), "{given:?}");
}
}

#[test]
fn two_tasks_running_one_provider_get_names_herdr_accepts_and_keeps_apart() {
let first = task_agent_name("claude", "w4:p1");
Expand Down
7 changes: 7 additions & 0 deletions herdr-core/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,13 @@ pub struct DeviceTestStageSnapshot {
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub struct SidebarAgentSnapshot {
pub id: String,
/// The name someone gave the agent in Herdr (`hide agent spawn --name`,
/// `herdr agent rename`), which ⌘K also finds it by; absent when it has
/// none or only one Hide made up from its pane (`fork::hide_made_name`).
/// `id` falls back to the pane id and a device's row replaces it, so it
/// cannot stand in for this.
#[serde(skip_serializing_if = "Option::is_none")]
pub herdr_name: Option<String>,
pub pane_id: String,
pub workspace_label: String,
/// The checkout the agent's pane is in, once the navigator has placed it.
Expand Down
1 change: 1 addition & 0 deletions herdr-core/src/pet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ mod tests {
};
SidebarAgentSnapshot {
id: pane_id.to_owned(),
herdr_name: None,
pane_id: pane_id.to_owned(),
workspace_label: "Fixture".to_owned(),
identity_label: "Fixture".to_owned(),
Expand Down
1 change: 1 addition & 0 deletions herdr-core/src/session_sync/projection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ impl ProjectionState {
.map(str::to_owned);
SessionAgentPayload {
id: agent.name.clone().or_else(|| Some(agent.pane_id.clone())),
name: agent.name.clone(),
pane_id: Some(agent.pane_id.clone()),
workspace_label,
cwd: agent.cwd.clone(),
Expand Down
51 changes: 51 additions & 0 deletions herdr-core/src/session_sync/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,57 @@ fn agent_projection_keeps_the_herdr_name_as_its_control_identifier() {
assert_eq!(replica.project().agents[0].id.as_deref(), Some("observer"));
}

/// ⌘K finds an agent by its Herdr name, so the snapshot's agent row carries
/// it, on this machine and on a device, whose row replaces `id`; an agent
/// given no name carries none rather than its pane id.
#[test]
fn the_snapshot_agent_row_carries_the_herdr_name_when_herdr_has_one() {
fn wire_rows(name: Option<&str>) -> (Value, Value) {
let mut replica = SessionReplica::from_snapshot(&snapshot()).expect("snapshot");
let mut agent = json!({
"pane_id": "w1:p1", "workspace_id": "w1", "tab_id": "w1:t1",
"terminal_id": "fixture-terminal", "focused": false, "revision": 1,
"agent": "claude", "agent_status": "working", "state_change_seq": 1, "tokens": {}
});
if let Some(name) = name {
agent["name"] = json!(name);
}
let agents = wire::agents_response(json!({"type": "agent_list", "agents": [agent]}))
.expect("an agent list");
replica.replace_agents(agents);
replica.refresh_published_state().expect("published");
let local = crate::sidebar::project_agents(replica.project()).agents;
let (remote, _) = replica
.project_remote("mini", replica.project())
.expect("remote projection");
(
serde_json::to_value(&local[0]).expect("local row"),
serde_json::to_value(&remote.agents[0]).expect("remote row"),
)
}

let (local, remote) = wire_rows(Some("observer-instant-pane-topology"));
assert_eq!(local["herdr_name"], json!("observer-instant-pane-topology"));
assert_eq!(
remote["herdr_name"],
json!("observer-instant-pane-topology")
);
assert_eq!(remote["pane_id"], json!("remote:mini:pane:w1:p1"));

// No name, and the names Hide makes up from a pane id (a task's, a
// wake's, a fork's), which would only spell the pane id.
for name in [
None,
Some(crate::fork::task_agent_name("claude", "w1:p1")),
Some(crate::fork::wake_name("w1:p1")),
Some(crate::fork::fork_name("w1:p9", "3-1788624371518")),
] {
let (local, remote) = wire_rows(name.as_deref());
assert!(local.get("herdr_name").is_none(), "{name:?}: {local}");
assert!(remote.get("herdr_name").is_none(), "{name:?}: {remote}");
}
}

/// B3, D-03. A remote device's project list follows the same activity
/// order the local list follows, not its own alphabetical one. The labels
/// here are deliberately in the opposite order to the activity, so a
Expand Down
7 changes: 7 additions & 0 deletions herdr-core/src/sidebar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ pub struct AgentLabel {
pub struct SessionAgentPayload {
#[serde(default)]
pub id: Option<String>,
/// The name Herdr knows the agent by (`agent.start --name`, `agent
/// rename`); absent when it was given none.
#[serde(default)]
pub name: Option<String>,
#[serde(default)]
pub pane_id: Option<String>,
#[serde(default)]
Expand Down Expand Up @@ -1496,6 +1500,9 @@ fn project_agent(agent: SessionAgentPayload) -> Result<SidebarAgentSnapshot, Str
.unwrap_or_else(|| provider_name(agent.agent.as_deref()));
let projected = SidebarAgentSnapshot {
id: agent.id.unwrap_or_else(|| pane_id.clone()),
herdr_name: non_empty(agent.name.as_deref())
.filter(|name| !crate::fork::hide_made_name(name, agent_kind, &pane_id))
.map(str::to_owned),
pane_id,
workspace_label,
checkout_label: None,
Expand Down
32 changes: 32 additions & 0 deletions web/src/search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,38 @@ describe("an agent by its pane's Herdr id", () => {
});
});

describe("an agent by its Herdr name", () => {
// Names as `hide agent spawn --name` and `herdr agent rename` give them; mini's agent is that device's own.
const named = (local: string | undefined, mini: string | undefined) => {
const rest = structuredClone(TWO_DEVICES);
rest.navigator!.agents = [{ ...REST.navigator!.agents![0]!, herdr_name: local }, REST.navigator!.agents![1]!];
rest.status!.remote![0]!.session!.agents![0]!.herdr_name = mini;
return searchEntries(rest, t);
};
const agentIds = (entries: SearchEntry[], query: string) => filterEntries(entries, query).flatMap((entry) => (entry.kind === "agent" ? [entry.id] : []));

it("finds an agent by its Herdr name on this Mac and on a device, and shows the name under the title", () => {
const entries = named("observer-instant-pane-topology", "nightly-watch");
expect(agentIds(entries, "observer-instant-pane-topology")).toEqual(["agent:p1"]);
expect(agentIds(entries, "nightly-watch")).toEqual(["agent:remote:mini:pane:1"]);
expect(entries.find((entry) => entry.id === "agent:p1")).toMatchObject({ title: "Agent one", subtitle: "observer-instant-pane-topology · fixture · Working" });
expect(entries.find((entry) => entry.id === "agent:remote:mini:pane:1")).toMatchObject({ title: "배치 감시", subtitle: "nightly-watch · web · Working" });
});

it("draws no name for an agent Herdr has none for, and finds nothing by one", () => {
const entries = named(undefined, undefined);
expect(agentIds(entries, "observer-instant-pane-topology")).toEqual([]);
expect(entries.find((entry) => entry.id === "agent:p1")).toMatchObject({ title: "Agent one", subtitle: "fixture · Working" });
expect(entries.find((entry) => entry.id === "agent:remote:mini:pane:1")).toMatchObject({ subtitle: "web · Working" });
});

it("does not repeat a name the title already reads as", () => {
const entries = named("agent one", undefined);
expect(entries.find((entry) => entry.id === "agent:p1")).toMatchObject({ title: "Agent one", subtitle: "fixture · Working" });
expect(agentIds(entries, "agent one")[0]).toBe("agent:p1");
});
});

describe("grouping (issue 154)", () => {
const agentsHere = { id: "agents:w1", label: "overview.agents" } as const;
const agentsThere = { id: "agents:w2", label: "overview.issues" } as const;
Expand Down
9 changes: 8 additions & 1 deletion web/src/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,19 @@ function agentStatus(agent: Pick<AgentRow, "demand" | "activity" | "emphasized"
return { tone, label: statusText(t, agent.status_code) };
}

/**
* An agent row: titled by the name every surface calls it, with its Herdr
* name (`agent start --name`, `agent rename`), its place and its state
* sentence under it, so a query finds it by any of them. A Herdr name the
* title already reads as is not drawn twice.
*/
export function agentEntry(scope: SearchDevice, agent: AgentRow, place: string | null, front: string, t: TFunction<"translation">): SearchEntry {
const sentence = agent.detail || statusText(t, agent.status_code);
const name = agent.herdr_name && agent.herdr_name.toLowerCase() !== agent.identity_label.toLowerCase() ? agent.herdr_name : null;
return {
id: `agent:${agent.pane_id}`,
title: agent.identity_label,
subtitle: place ? `${place} · ${sentence}` : sentence,
subtitle: [name, place, sentence].filter(Boolean).join(" · "),
place: place ?? undefined,
kind: "agent",
group: AGENTS_GROUP,
Expand Down
2 changes: 2 additions & 0 deletions web/src/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export type AgentRow = {
id: string;
pane_id: string;
identity_label: string;
/** The name Herdr knows the agent by (`agent start --name`, `agent rename`); absent when it was given none. */
herdr_name?: string;
agent_kind: string;
/** The checkout that physically owns this pane. */
checkout_label?: string | null;
Expand Down
Loading