feat(host,gui): the command that reaches a company's books is made in one place
The Connect page of P15 unit A4 shows an assistant the exact command it must run to reach a company (`<this program> mcp --book ID`, with --root when a root was named). `connect` already built that command, so it is now one function (`bridge_serve_args`/`command_line`) used by both, and the step `connect` does first (the company's default key exists and its copy is in the token file) is `ensure_key`, which the page offers by itself for assistants it has no button for. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
016f1b2afc
commit
1d1a2a5a88
3 files changed
+64
-40
No files matched your search
@@ -155,8 +155,12 @@ impl ledger_gui::owner::Owner for ViewerOwner {
|
|||||||
self.server.revoke_token(book, name)
|
self.server.revoke_token(book, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bridge_command(&self, book: &str) -> Result<String, String> {
|
fn command_line(&self, words: &[&str]) -> Result<String, String> {
|
||||||
ledger_host::commands::bridge_command_line(&self.common, book)
|
ledger_host::commands::command_line(&self.common, words)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn make_key(&self, book: &str) -> Result<bool, String> {
|
||||||
|
ledger_host::commands::ensure_key(&self.common, book)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn close_books(&self) -> Result<String, String> {
|
fn close_books(&self) -> Result<String, String> {
|
||||||
|
|||||||
@@ -267,10 +267,16 @@ pub trait Owner: Send + Sync {
|
|||||||
fn serve_revoke(&self, _book: &str, _name: &str) -> Result<String, String> {
|
fn serve_revoke(&self, _book: &str, _name: &str) -> Result<String, String> {
|
||||||
Err("not here".into())
|
Err("not here".into())
|
||||||
}
|
}
|
||||||
/// The command an assistant runs to reach the company `book`, as text
|
/// This program run with `words`, as a line to type in a terminal (the
|
||||||
/// to type (the program and `mcp --book ID`, quoted for a terminal):
|
/// program's own path, the words, the data root if one was named): what
|
||||||
/// what the Connect page shows for an assistant it has no button for.
|
/// the Connect page shows for an assistant it has no button for.
|
||||||
fn bridge_command(&self, _book: &str) -> Result<String, String> {
|
fn command_line(&self, _words: &[&str]) -> Result<String, String> {
|
||||||
|
Err("not here".into())
|
||||||
|
}
|
||||||
|
/// The key an assistant needs to reach the company `book` exists (made
|
||||||
|
/// now if it did not): `Ok(true)` when it was made now. What `connect`
|
||||||
|
/// does first, for an assistant set up by hand. Blocks.
|
||||||
|
fn make_key(&self, _book: &str) -> Result<bool, String> {
|
||||||
Err("not here".into())
|
Err("not here".into())
|
||||||
}
|
}
|
||||||
/// Close the books: everything holding them lets go.
|
/// Close the books: everything holding them lets go.
|
||||||
|
|||||||
@@ -1402,42 +1402,43 @@ pub fn connect(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The command an assistant runs to reach the books `book`: this program's
|
/// This program's own executable followed by `words`, then `--root` when
|
||||||
/// own executable and `mcp --book <book>`, with `--root` when the data root
|
/// the data root was named and the knobs this run was given: what an
|
||||||
/// was named and the knobs this run was given. The one place it is made:
|
/// assistant, or a person at a terminal, runs to reach these books. The one
|
||||||
/// `connect_agent` registers it, and the window's Connect page shows it to
|
/// place it is made.
|
||||||
/// be typed into an assistant that has no `connect` of its own.
|
fn program_args(common: &Common, words: &[&str]) -> Result<Vec<std::ffi::OsString>, String> {
|
||||||
pub fn bridge_serve_args(common: &Common, book: &str) -> Result<Vec<std::ffi::OsString>, String> {
|
|
||||||
let book = ledger_store::root::BookId::parse(book)
|
|
||||||
.map_err(|e| e.to_string())?
|
|
||||||
.to_string();
|
|
||||||
// A translocated macOS app's path (P11a step 6) is not a place to point
|
// A translocated macOS app's path (P11a step 6) is not a place to point
|
||||||
// an agent: the copy goes away with the app.
|
// an agent: the copy goes away with the app.
|
||||||
let exe = crate::start::this_executable()?;
|
let exe = crate::start::this_executable()?;
|
||||||
if let Some(why) = crate::start::translocation_refusal(&exe) {
|
if let Some(why) = crate::start::translocation_refusal(&exe) {
|
||||||
return Err(why.to_string());
|
return Err(why.to_string());
|
||||||
}
|
}
|
||||||
let mut serve: Vec<std::ffi::OsString> = vec![
|
let mut args: Vec<std::ffi::OsString> = vec![exe.into_os_string()];
|
||||||
exe.into_os_string(),
|
args.extend(words.iter().map(std::ffi::OsString::from));
|
||||||
"mcp".into(),
|
|
||||||
"--book".into(),
|
|
||||||
book.into(),
|
|
||||||
];
|
|
||||||
if common.root.is_some() {
|
if common.root.is_some() {
|
||||||
let found =
|
let found =
|
||||||
ledger_store::root::Root::find(common.root.as_deref()).map_err(|e| e.to_string())?;
|
ledger_store::root::Root::find(common.root.as_deref()).map_err(|e| e.to_string())?;
|
||||||
serve.push("--root".into());
|
args.push("--root".into());
|
||||||
serve.push(found.path().as_os_str().to_os_string());
|
args.push(found.path().as_os_str().to_os_string());
|
||||||
}
|
}
|
||||||
serve.extend(common.knobs.args().into_iter().map(Into::into));
|
args.extend(common.knobs.args().into_iter().map(Into::into));
|
||||||
Ok(serve)
|
Ok(args)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// [`bridge_serve_args`] as text, for an assistant that is set up by hand:
|
/// The command an assistant runs to reach the books `book`: this program
|
||||||
/// a part with a space in it is quoted for a terminal.
|
/// and `mcp --book <book>`. `connect_agent` registers it, and the window's
|
||||||
pub fn bridge_command_line(common: &Common, book: &str) -> Result<String, String> {
|
/// Connect page shows it for an assistant that has no `connect` of its own.
|
||||||
let args = bridge_serve_args(common, book)?;
|
pub fn bridge_serve_args(common: &Common, book: &str) -> Result<Vec<std::ffi::OsString>, String> {
|
||||||
Ok(args
|
let book = ledger_store::root::BookId::parse(book)
|
||||||
|
.map_err(|e| e.to_string())?
|
||||||
|
.to_string();
|
||||||
|
program_args(common, &["mcp", "--book", &book])
|
||||||
|
}
|
||||||
|
|
||||||
|
/// This program run with `words`, as a line to type in a terminal: a part
|
||||||
|
/// with a space in it is quoted.
|
||||||
|
pub fn command_line(common: &Common, words: &[&str]) -> Result<String, String> {
|
||||||
|
Ok(program_args(common, words)?
|
||||||
.iter()
|
.iter()
|
||||||
.map(|a| {
|
.map(|a| {
|
||||||
let a = a.to_string_lossy();
|
let a = a.to_string_lossy();
|
||||||
@@ -1451,6 +1452,28 @@ pub fn bridge_command_line(common: &Common, book: &str) -> Result<String, String
|
|||||||
.join(" "))
|
.join(" "))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The default token of the books `book` exists and its copy is in the token
|
||||||
|
/// file (made now if it is not): what `connect` does first. `Ok(true)` when
|
||||||
|
/// it was made now.
|
||||||
|
pub fn ensure_key(common: &Common, book: &str) -> Result<bool, String> {
|
||||||
|
let book = ledger_store::root::BookId::parse(book)
|
||||||
|
.map_err(|e| e.to_string())?
|
||||||
|
.to_string();
|
||||||
|
let found =
|
||||||
|
ledger_store::root::Root::find(common.root.as_deref()).map_err(|e| e.to_string())?;
|
||||||
|
let run = found.run_dir().map_err(|e| e.to_string())?;
|
||||||
|
let account = crate::tokens::Account::new(found.path(), &book, crate::tokens::DEFAULT_NAME);
|
||||||
|
if crate::tokens::keeper(&run).get(&account)?.is_some() {
|
||||||
|
return Ok(false);
|
||||||
|
}
|
||||||
|
let scopes = ledger_store::auth::Scope::ALL
|
||||||
|
.iter()
|
||||||
|
.map(|s| s.as_str().to_string())
|
||||||
|
.collect();
|
||||||
|
make_token(common, &book, crate::tokens::DEFAULT_NAME, scopes, true)?;
|
||||||
|
Ok(true)
|
||||||
|
}
|
||||||
|
|
||||||
/// A revoked token's copy in the token file goes with it (what `token
|
/// A revoked token's copy in the token file goes with it (what `token
|
||||||
/// revoke` does after the server has ended the token). `run_dir` is the
|
/// revoke` does after the server has ended the token). `run_dir` is the
|
||||||
/// root's `run/` folder.
|
/// root's `run/` folder.
|
||||||
@@ -1483,16 +1506,7 @@ pub fn connect_agent(common: &Common, agent: &str, book: &str) -> Result<Vec<Str
|
|||||||
let serve = bridge_serve_args(common, &book)?;
|
let serve = bridge_serve_args(common, &book)?;
|
||||||
let mut lines = Vec::new();
|
let mut lines = Vec::new();
|
||||||
// The token: kept in its file, or made now.
|
// The token: kept in its file, or made now.
|
||||||
let found =
|
if ensure_key(common, &book)? {
|
||||||
ledger_store::root::Root::find(common.root.as_deref()).map_err(|e| e.to_string())?;
|
|
||||||
let run = found.run_dir().map_err(|e| e.to_string())?;
|
|
||||||
let account = crate::tokens::Account::new(found.path(), &book, crate::tokens::DEFAULT_NAME);
|
|
||||||
if crate::tokens::keeper(&run).get(&account)?.is_none() {
|
|
||||||
let scopes = ledger_store::auth::Scope::ALL
|
|
||||||
.iter()
|
|
||||||
.map(|s| s.as_str().to_string())
|
|
||||||
.collect();
|
|
||||||
make_token(common, &book, crate::tokens::DEFAULT_NAME, scopes, true)?;
|
|
||||||
lines.push(format!(
|
lines.push(format!(
|
||||||
"Made the agent token of the books {book}, kept in a token file in the data root."
|
"Made the agent token of the books {book}, kept in a token file in the data root."
|
||||||
));
|
));
|
||||||
|
|||||||
Reference in new issue
Block a user