M3.7: lutra CLI and single instance
- crates/control: rendezvous file (<data_dir>/instance.json, port + random token, atomic write, 0600 on Unix, stale detection), token-protected listener (start_with_token, app.auth first, constant-time compare, 10 s auth timeout), app.focus, and a blocking client (connect_live, request/execute/subscribe/next_event, open_folder/open_file/reveal) - lutra-desktop: a normal start forwards its path to a running instance and exits, otherwise claims the rendezvous; --control instances skip it unless LUTRA_RENDEZVOUS_DIR is set; non-Unicode args are usage errors - lutra-cli (binary lutra, now L6): path[:line[:column]] targets, folder -> project.open, file -> file.open (parent opened without a project, outside the project refused), editor.reveal, starts the desktop if needed, --wait until bufferClosed, --version/--help, exit codes 0/1/2 - tests: proptest target parsing, rendezvous read/write/stale, token check over TCP, forwarding against a test backend, --wait end to end - docs: architecture, G7, ROADMAP (agent automation 18% est.), roadmap, README Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
9ccfc1bf6a
commit
9b278099cf
26 changed files with 2162 additions and 37 deletions
|
|
@ -14,7 +14,8 @@ use serde_json::{Value, json};
|
|||
|
||||
use crate::Backend;
|
||||
use crate::methods::{
|
||||
APP_PING, ENGINE_EXECUTE, ENGINE_LIST_COMMANDS, EVENTS_SUBSCRIBE, UI_SCREENSHOT,
|
||||
APP_AUTH, APP_FOCUS, APP_PING, ENGINE_EXECUTE, ENGINE_LIST_COMMANDS, EVENTS_SUBSCRIBE,
|
||||
UI_SCREENSHOT,
|
||||
};
|
||||
|
||||
/// Largest accepted request line in bytes, newline excluded.
|
||||
|
|
@ -35,6 +36,10 @@ pub mod codes {
|
|||
pub const LINE_TOO_LONG: &str = "line_too_long";
|
||||
/// The screenshot could not be taken.
|
||||
pub const SCREENSHOT_FAILED: &str = "screenshot_failed";
|
||||
/// The connection has not authenticated with the right token.
|
||||
pub const UNAUTHORIZED: &str = "unauthorized";
|
||||
/// The window could not be brought to the front.
|
||||
pub const FOCUS_FAILED: &str = "focus_failed";
|
||||
}
|
||||
|
||||
/// A parsed request.
|
||||
|
|
@ -143,6 +148,14 @@ pub fn parse_request(line: &str) -> Result<Request, Response> {
|
|||
.map_err(|e| Response::err(echo, codes::INVALID_REQUEST, e.to_string()))
|
||||
}
|
||||
|
||||
/// Params of `app.auth`.
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct AuthParams {
|
||||
/// The token from the rendezvous file.
|
||||
pub token: String,
|
||||
}
|
||||
|
||||
/// Answers one request line. Never panics: a panic in the backend becomes an
|
||||
/// `internal` error response.
|
||||
pub fn handle_line(line: &str, backend: &dyn Backend) -> Response {
|
||||
|
|
@ -183,6 +196,11 @@ fn dispatch(request: Request, backend: &dyn Backend) -> Response {
|
|||
},
|
||||
Err(e) => Response::err(id, codes::INVALID_PARAMS, e.to_string()),
|
||||
},
|
||||
APP_AUTH => Response::ok(id, json!({ "authenticated": true })),
|
||||
APP_FOCUS => match backend.focus() {
|
||||
Ok(()) => Response::ok(id, json!({ "focused": true })),
|
||||
Err(message) => Response::err(id, codes::FOCUS_FAILED, message),
|
||||
},
|
||||
EVENTS_SUBSCRIBE => Response::err(
|
||||
id,
|
||||
codes::INVALID_REQUEST,
|
||||
|
|
@ -256,6 +274,14 @@ mod tests {
|
|||
assert_eq!(r.error.unwrap().code, "invalid_request");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn auth_and_focus_on_an_open_channel() {
|
||||
let r = call(r#"{"id":1,"method":"app.auth","params":{"token":"x"}}"#);
|
||||
assert_eq!(r.result.unwrap()["authenticated"], true);
|
||||
let r = call(r#"{"id":2,"method":"app.focus"}"#);
|
||||
assert_eq!(r.error.unwrap().code, "focus_failed");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ping() {
|
||||
let r = call(r#"{"id":1,"method":"app.ping"}"#);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue