From 54a2fc52c5a4a660647f64ecf317de6eef079d71 Mon Sep 17 00:00:00 2001 From: repo-worker-tmp-code-b Date: Tue, 17 Nov 2026 05:21:06 -0600 Subject: [PATCH 1/2] id: add the #5873 flow verbs to the shared world_line grammar (#7616 part 1) --- pkgs/id/crates/id-cli/src/commands/world.rs | 19 +- pkgs/id/crates/id-worlds/src/world_line.rs | 253 +++++++++++++++++++- pkgs/id/crates/id-worlds/src/world_ssh.rs | 57 ++++- 3 files changed, 326 insertions(+), 3 deletions(-) diff --git a/pkgs/id/crates/id-cli/src/commands/world.rs b/pkgs/id/crates/id-cli/src/commands/world.rs index 2382b01f63..67631ebf53 100644 --- a/pkgs/id/crates/id-cli/src/commands/world.rs +++ b/pkgs/id/crates/id-cli/src/commands/world.rs @@ -2208,7 +2208,7 @@ enum PumpLine { Quit, } -const PUMP_HELP: &str = "Commands: a line is chat; /input , /records [prefix], /stats, /caps, /logs, /help, /quit. Server frames print to stdout as JSON lines."; +const PUMP_HELP: &str = "Commands: a line is chat; /input , /records [prefix], /stats, /caps, /logs, /anchor [type], /anchor confirm , /anchor list, /talk , /anchors , /resolve [into ], /queue, /flush, /help, /quit. Server frames print to stdout as JSON lines."; /// Stable JSONL record for a response that the join client handles locally. fn local_transcript_record(level: &str, message: &str) -> serde_json::Value { @@ -2244,6 +2244,23 @@ fn pump_command(line: &str, capability: &str) -> PumpLine { message: "events already print live here as JSON lines; use `id world logs` for a bounded tail".to_owned(), }; } + WorldLine::Anchor { .. } + | WorldLine::AnchorConfirm { .. } + | WorldLine::AnchorList + | WorldLine::Talk { .. } + | WorldLine::Anchors { .. } + | WorldLine::Resolve { .. } + | WorldLine::Queue + | WorldLine::Flush => { + // The flow verbs parse identically on every surface (#5873 + // section 3), but their operations (chat.anchor.v1, talk + // bindings, the outbox) are not wired into the join pump yet; + // say so rather than sending a frame the host cannot mean. + return PumpLine::Say { + level: "error", + message: "that command is recognised, but its operation is not available in `id world join` yet".to_owned(), + }; + } WorldLine::Help => { return PumpLine::Say { level: "info", diff --git a/pkgs/id/crates/id-worlds/src/world_line.rs b/pkgs/id/crates/id-worlds/src/world_line.rs index 6e6e31494a..5ea62214a3 100644 --- a/pkgs/id/crates/id-worlds/src/world_line.rs +++ b/pkgs/id/crates/id-worlds/src/world_line.rs @@ -2,7 +2,8 @@ //! //! The SSH command mode (`cmd:` login), the `id world join` stdin pump, and //! the `id world` CLI subcommands all speak the same verbs: chat, records, -//! stats, logs, caps and quit. This module is the single parser that maps one +//! stats, logs, caps, the object-discussion flow verbs of #5873 (anchor, +//! talk, anchors, resolve, queue, flush) and quit. This module is the single parser that maps one //! line to one [`WorldLine`] action, so a sentence works identically as an SSH //! command, a piped script line, and a CLI one-off. @@ -29,6 +30,47 @@ pub enum WorldLine { Logs { seconds: Option }, /// `/caps`: the world's capability report. Caps, + /// `/anchor [type]`: anchor the current conversation to an + /// object (#5873 section 3). The target is an `id://` reference or a + /// friendly-name phrase; the optional type is the anchor relation + /// (about, anchored-to-part, derived-from, talk-for), taken from the + /// final word when it names one. + Anchor { + /// The object the conversation anchors to. + target: String, + /// The anchor relation, when the line named one. + relation: Option, + }, + /// `/anchor confirm `: confirm the proposed anchor numbered `n` + /// (#5873 sections 3 and 5.4). + AnchorConfirm { + /// The proposal number, as listed by `/anchor list`. + proposal: u64, + }, + /// `/anchor list`: list this conversation's anchors and their state. + AnchorList, + /// `/talk `: open (or create, per #5871) the object's talk page. + Talk { + /// The object whose talk page opens. + target: String, + }, + /// `/anchors `: list conversations anchored to an object. + Anchors { + /// The object whose anchored conversations are listed. + target: String, + }, + /// `/resolve [into ]`: resolve a thread, optionally + /// into an edit of the target (#5874's mechanics). + Resolve { + /// The thread being resolved. + thread: String, + /// The edit target, when the line named one after `into`. + into: Option, + }, + /// `/queue`: inspect the offline outbox (#5873 section 6). + Queue, + /// `/flush`: drain the offline outbox (#5873 section 6). + Flush, /// `/help`: list the commands. Help, /// `/quit`: end the session. @@ -59,6 +101,8 @@ pub fn parse_line(line: &str) -> Option { Some("/quit") => return Some(WorldLine::Quit), Some("/stats") => return Some(WorldLine::Stats), Some("/caps") => return Some(WorldLine::Caps), + Some("/queue") => return Some(WorldLine::Queue), + Some("/flush") => return Some(WorldLine::Flush), _ => {} } if line == "/records" || line.starts_with("/records ") { @@ -105,6 +149,101 @@ pub fn parse_line(line: &str) -> Option { } return Some(WorldLine::Message("usage: /logs [seconds]".to_owned())); } + // The object-discussion flow verbs (#5873 section 3). /anchors is + // checked before /anchor: the names share a prefix, and the verb + // boundary rule (exact, or verb + space + argument) is what keeps + // /anchors from parsing as /anchor with a glued argument. + if line == "/anchors" { + return Some(WorldLine::Message("usage: /anchors ".to_owned())); + } + if let Some(rest) = line.strip_prefix("/anchors ") { + let target = rest.trim(); + if !target.is_empty() { + return Some(WorldLine::Anchors { + target: target.to_owned(), + }); + } + return Some(WorldLine::Message("usage: /anchors ".to_owned())); + } + if line == "/anchor" { + return Some(WorldLine::Message( + "usage: /anchor [type] | /anchor confirm | /anchor list".to_owned(), + )); + } + if let Some(rest) = line.strip_prefix("/anchor ") { + let rest = rest.trim(); + if rest == "list" { + return Some(WorldLine::AnchorList); + } + if rest == "confirm" { + return Some(WorldLine::Message("usage: /anchor confirm ".to_owned())); + } + if let Some(number) = rest.strip_prefix("confirm ") { + if let Ok(proposal) = number.trim().parse::() { + return Some(WorldLine::AnchorConfirm { proposal }); + } + return Some(WorldLine::Message("usage: /anchor confirm ".to_owned())); + } + // The optional [type] is the anchor relation, and it is the final + // word when it names one; a friendly-name target keeps its spaces + // otherwise, exactly as /document names do. + const RELATIONS: [&str; 4] = ["about", "anchored-to-part", "derived-from", "talk-for"]; + if let Some((head, last)) = rest.rsplit_once(' ') { + let head = head.trim(); + if !head.is_empty() && RELATIONS.contains(&last) { + return Some(WorldLine::Anchor { + target: head.to_owned(), + relation: Some(last.to_owned()), + }); + } + } + return Some(WorldLine::Anchor { + target: rest.to_owned(), + relation: None, + }); + } + if line == "/talk" { + return Some(WorldLine::Message("usage: /talk ".to_owned())); + } + if let Some(rest) = line.strip_prefix("/talk ") { + let target = rest.trim(); + if !target.is_empty() { + return Some(WorldLine::Talk { + target: target.to_owned(), + }); + } + return Some(WorldLine::Message("usage: /talk ".to_owned())); + } + if line == "/resolve" { + return Some(WorldLine::Message( + "usage: /resolve [into ]".to_owned(), + )); + } + if let Some(rest) = line.strip_prefix("/resolve ") { + let rest = rest.trim(); + if let Some((thread, target)) = rest.split_once(" into ") { + let thread = thread.trim(); + let target = target.trim(); + if !thread.is_empty() && !target.is_empty() { + return Some(WorldLine::Resolve { + thread: thread.to_owned(), + into: Some(target.to_owned()), + }); + } + return Some(WorldLine::Message( + "usage: /resolve [into ]".to_owned(), + )); + } + if !rest.is_empty() { + return Some(WorldLine::Resolve { + thread: rest.to_owned(), + into: None, + }); + } + return Some(WorldLine::Message( + "usage: /resolve [into ]".to_owned(), + )); + } if line == "/input" { return Some(WorldLine::Message("usage: /input ".to_owned())); } @@ -289,6 +428,118 @@ mod tests { ); } + #[test] + fn the_flow_verbs_parse() { + // #5873 section 3: the object-discussion verbs, in the shared + // grammar every surface consumes. + assert_eq!( + parse_line("/anchor id://abc"), + Some(WorldLine::Anchor { + target: "id://abc".into(), + relation: None + }) + ); + assert_eq!( + parse_line("/anchor id://abc#pa1~b~r1~p~blk anchored-to-part"), + Some(WorldLine::Anchor { + target: "id://abc#pa1~b~r1~p~blk".into(), + relation: Some("anchored-to-part".into()) + }) + ); + // A friendly-name target keeps its spaces; a trailing relation + // word is the type, and only then. + assert_eq!( + parse_line("/anchor the design doc about"), + Some(WorldLine::Anchor { + target: "the design doc".into(), + relation: Some("about".into()) + }) + ); + assert_eq!( + parse_line("/anchor the design doc"), + Some(WorldLine::Anchor { + target: "the design doc".into(), + relation: None + }) + ); + assert_eq!( + parse_line("/anchor confirm 2"), + Some(WorldLine::AnchorConfirm { proposal: 2 }) + ); + assert_eq!(parse_line("/anchor list"), Some(WorldLine::AnchorList)); + assert_eq!( + parse_line("/talk id://abc"), + Some(WorldLine::Talk { + target: "id://abc".into() + }) + ); + assert_eq!( + parse_line("/anchors the design doc"), + Some(WorldLine::Anchors { + target: "the design doc".into() + }) + ); + assert_eq!( + parse_line("/resolve thread-9"), + Some(WorldLine::Resolve { + thread: "thread-9".into(), + into: None + }) + ); + assert_eq!( + parse_line("/resolve thread-9 into id://abc"), + Some(WorldLine::Resolve { + thread: "thread-9".into(), + into: Some("id://abc".into()) + }) + ); + assert_eq!(parse_line("/queue"), Some(WorldLine::Queue)); + assert_eq!(parse_line("/flush"), Some(WorldLine::Flush)); + } + + #[test] + fn the_flow_verbs_keep_the_verb_boundary() { + // /anchors is not /anchor with a glued argument, and a tab is not + // a separator for the new verbs either (#4492's one boundary rule). + assert_eq!( + parse_line("/anchorx id://abc"), + Some(WorldLine::Message("unknown command; type /help".into())) + ); + assert_eq!( + parse_line("/talk\tid://abc"), + Some(WorldLine::Message("unknown command; type /help".into())) + ); + assert_eq!( + parse_line("/queue\tnow"), + Some(WorldLine::Message("unknown command; type /help".into())) + ); + // Bare argument verbs answer with their usage, like /document. + assert_eq!( + parse_line("/anchor"), + Some(WorldLine::Message( + "usage: /anchor [type] | /anchor confirm | /anchor list".into() + )) + ); + assert_eq!( + parse_line("/anchor confirm later"), + Some(WorldLine::Message("usage: /anchor confirm ".into())) + ); + assert_eq!( + parse_line("/anchors"), + Some(WorldLine::Message("usage: /anchors ".into())) + ); + assert_eq!( + parse_line("/talk"), + Some(WorldLine::Message("usage: /talk ".into())) + ); + assert_eq!( + parse_line("/resolve"), + Some(WorldLine::Message( + "usage: /resolve [into ]".into() + )) + ); + } + #[test] fn unknown_and_malformed_commands_become_messages() { assert_eq!( diff --git a/pkgs/id/crates/id-worlds/src/world_ssh.rs b/pkgs/id/crates/id-worlds/src/world_ssh.rs index 20f058861f..11c742b48c 100644 --- a/pkgs/id/crates/id-worlds/src/world_ssh.rs +++ b/pkgs/id/crates/id-worlds/src/world_ssh.rs @@ -705,6 +705,14 @@ fn command_frame(command: &WorldCommand, capability: &str) -> Option { WorldCommand::Stats => json!({ "type": "info", "capability": capability }), WorldCommand::Caps => json!({ "type": "caps", "capability": capability }), WorldCommand::Logs { .. } + | WorldCommand::Anchor { .. } + | WorldCommand::AnchorConfirm { .. } + | WorldCommand::AnchorList + | WorldCommand::Talk { .. } + | WorldCommand::Anchors { .. } + | WorldCommand::Resolve { .. } + | WorldCommand::Queue + | WorldCommand::Flush | WorldCommand::Help | WorldCommand::Message(_) | WorldCommand::Quit => return None, @@ -1200,7 +1208,7 @@ impl SessionIo for SshIo { // Everything else is answered by the shell itself. match command { WorldCommand::Help => { - let help = "World chat: type a line to chat. Commands: /input , /records [prefix], /stats, /logs, /caps, /documents [prefix], /document , /help, /quit\r\nworld> "; + let help = "World chat: type a line to chat. Commands: /input , /records [prefix], /stats, /logs, /caps, /documents [prefix], /document , /anchor [type], /anchor confirm , /anchor list, /talk , /anchors , /resolve [into ], /queue, /flush, /help, /quit\r\nworld> "; if self.handle.data(self.channel, help).await.is_err() { return Inbound::Closed; } @@ -1231,6 +1239,25 @@ impl SessionIo for SshIo { return Inbound::Closed; } } + WorldCommand::Anchor { .. } + | WorldCommand::AnchorConfirm { .. } + | WorldCommand::AnchorList + | WorldCommand::Talk { .. } + | WorldCommand::Anchors { .. } + | WorldCommand::Resolve { .. } + | WorldCommand::Queue + | WorldCommand::Flush => { + // The flow verbs parse identically on every + // surface (#5873 section 3), but their + // operations (chat.anchor.v1, talk bindings, + // the outbox) are not wired into the SSH + // session yet; say so rather than forwarding + // a frame the world program cannot mean. + let text = "that command is recognised, but its operation is not available in this session yet\r\nworld> "; + if self.handle.data(self.channel, text).await.is_err() { + return Inbound::Closed; + } + } WorldCommand::Quit => return Inbound::Closed, WorldCommand::Chat(_) | WorldCommand::Input(_) @@ -1832,6 +1859,26 @@ enum WorldCommand { seconds: Option, }, Caps, + Anchor { + target: String, + relation: Option, + }, + AnchorConfirm { + proposal: u64, + }, + AnchorList, + Talk { + target: String, + }, + Anchors { + target: String, + }, + Resolve { + thread: String, + into: Option, + }, + Queue, + Flush, Help, Message(String), Quit, @@ -1848,6 +1895,14 @@ fn world_command(line: &str) -> Option { WorldLine::Stats => WorldCommand::Stats, WorldLine::Logs { seconds } => WorldCommand::Logs { seconds }, WorldLine::Caps => WorldCommand::Caps, + WorldLine::Anchor { target, relation } => WorldCommand::Anchor { target, relation }, + WorldLine::AnchorConfirm { proposal } => WorldCommand::AnchorConfirm { proposal }, + WorldLine::AnchorList => WorldCommand::AnchorList, + WorldLine::Talk { target } => WorldCommand::Talk { target }, + WorldLine::Anchors { target } => WorldCommand::Anchors { target }, + WorldLine::Resolve { thread, into } => WorldCommand::Resolve { thread, into }, + WorldLine::Queue => WorldCommand::Queue, + WorldLine::Flush => WorldCommand::Flush, WorldLine::Help => WorldCommand::Help, WorldLine::Quit => WorldCommand::Quit, WorldLine::Message(message) => WorldCommand::Message(message), From ba21c2e5233a1b74b789021673373eb422ea282c Mon Sep 17 00:00:00 2001 From: repo-worker-tmp-code-b Date: Tue, 17 Nov 2026 07:58:36 -0600 Subject: [PATCH 2/2] test(id): assert #7616 flow verbs map identically on ssh and join-pump surfaces The parser already carried the #5873 section 3 verbs; this pins the acceptance property that the SSH command mode and the id world join pump consume exactly the same shared parse, that no flow verb is forwarded to the world program as a frame, and that the pump answers them locally instead of sending a frame the host cannot mean. --- pkgs/id/crates/id-cli/src/commands/world.rs | 23 +++++++++++ pkgs/id/crates/id-worlds/src/world_ssh.rs | 44 +++++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/pkgs/id/crates/id-cli/src/commands/world.rs b/pkgs/id/crates/id-cli/src/commands/world.rs index ac0166de7e..7abb0f30ea 100644 --- a/pkgs/id/crates/id-cli/src/commands/world.rs +++ b/pkgs/id/crates/id-cli/src/commands/world.rs @@ -2506,6 +2506,29 @@ mod tests { "{line}" ); } + // #7616 / #5873 section 3: the flow verbs are recognised on the pump + // too, and they answer locally rather than sending a frame the host + // cannot mean — identical grammar, surface-appropriate answer. + for line in [ + "/anchor id://abc", + "/anchor id://abc about", + "/anchor confirm 1", + "/anchor list", + "/talk id://abc", + "/anchors the design doc", + "/resolve thread-9", + "/resolve thread-9 into id://abc", + "/queue", + "/flush", + ] { + assert!( + matches!( + pump_command(line, "cap"), + PumpLine::Say { level: "error", .. } + ), + "{line}" + ); + } assert_eq!(pump_command("/quit", "cap"), PumpLine::Quit); } diff --git a/pkgs/id/crates/id-worlds/src/world_ssh.rs b/pkgs/id/crates/id-worlds/src/world_ssh.rs index 11c742b48c..de606309f7 100644 --- a/pkgs/id/crates/id-worlds/src/world_ssh.rs +++ b/pkgs/id/crates/id-worlds/src/world_ssh.rs @@ -4289,6 +4289,50 @@ mod tests { ); } + /// #5873 section 3 / #7616 acceptance: the flow verbs reach every surface + /// through the same shared parser, so the SSH command mode sees exactly + /// the actions the parser produced — and none of them is emitted as a + /// chat message or a shell frame the world program cannot mean. + #[test] + fn the_flow_verbs_map_identically_on_the_ssh_surface() { + use crate::world_line::parse_line; + for line in [ + "/anchor id://abc", + "/anchor id://abc anchored-to-part", + "/anchor confirm 2", + "/anchor list", + "/talk id://abc", + "/anchors the design doc", + "/resolve thread-9", + "/resolve thread-9 into id://abc", + "/queue", + "/flush", + ] { + let command = world_command(line).unwrap_or_else(|| panic!("{line}: no command")); + // The surface is a faithful mirror of the shared parse. + let expected = match parse_line(line).unwrap() { + crate::world_line::WorldLine::Anchor { target, relation } => { + WorldCommand::Anchor { target, relation } + } + crate::world_line::WorldLine::AnchorConfirm { proposal } => { + WorldCommand::AnchorConfirm { proposal } + } + crate::world_line::WorldLine::AnchorList => WorldCommand::AnchorList, + crate::world_line::WorldLine::Talk { target } => WorldCommand::Talk { target }, + crate::world_line::WorldLine::Anchors { target } => WorldCommand::Anchors { target }, + crate::world_line::WorldLine::Resolve { thread, into } => { + WorldCommand::Resolve { thread, into } + } + crate::world_line::WorldLine::Queue => WorldCommand::Queue, + crate::world_line::WorldLine::Flush => WorldCommand::Flush, + other => panic!("{line}: parser produced {other:?}"), + }; + assert_eq!(command, expected, "{line}"); + // And no flow verb is forwarded to the world program as a frame. + assert_eq!(command_frame(&command, "cap"), None, "{line}"); + } + } + #[test] fn world_line_buffer_discards_overlong_line_until_newline() { let mut input = WorldLineBuffer::default();