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
13 changes: 10 additions & 3 deletions R/host.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ mcp_host <- function() {
i <- i + 1L
}
)
the$i <- i
the$session <- i

schedule_handle_message_from_server()
}
Expand All @@ -77,7 +77,14 @@ handle_message_from_server <- function(msg) {

# cat("RECV :", msg, "\n", sep = "", file = stderr())
if (!nzchar(msg)) {
return(nanonext::send_aio(the$host_socket, describe_session(), pipe = pipe))
return(
nanonext::send_aio(
the$host_socket,
describe_session(),
mode = "raw",
pipe = pipe
)
)
}
data <- jsonlite::parse_json(msg)

Expand Down Expand Up @@ -153,7 +160,7 @@ drop_nulls <- function(x) {
# Enough information for the user to be able to identify which
# session is which when using `list_r_sessions()` (#18)
describe_session <- function() {
sprintf("%d: %s (%s)", the$i, basename(getwd()), infer_ide())
sprintf("%d: %s (%s)", the$session, basename(getwd()), infer_ide())
}

infer_ide <- function() {
Expand Down
21 changes: 14 additions & 7 deletions R/tools.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,21 @@ list_r_sessions <- function() {
monitor <- nanonext::monitor(sock, cv)
suppressWarnings(
for (i in seq_len(1024L)) {
nanonext::dial(
sock,
url = sprintf("%s%d", acquaint_socket, i),
autostart = NA
) &&
if (
nanonext::dial(
sock,
url = sprintf("%s%d", acquaint_socket, i),
autostart = NA
) && i > 8L
)
break
}
)
pipes <- nanonext::read_monitor(monitor)
res <- lapply(seq_along(pipes), function(x) nanonext::recv_aio(sock))
res <- lapply(
pipes,
function(x) nanonext::recv_aio(sock, mode = "string")
)
lapply(
pipes,
function(x) nanonext::send_aio(sock, "", mode = "raw", pipe = x)
Expand All @@ -31,6 +36,8 @@ list_r_sessions_tool <-
.description = paste(
"List the R sessions that are available to access.",
"R sessions which have run `acquaint::mcp_host()` will appear here.",
"In the output, start each session with 'Session #' and do NOT otherwise",
"prefix any index numbers to the output.",
"In general, do not use this tool unless asked to list or",
"select a specific R session.",
"Given the output of this tool, report the users to the user.",
Expand All @@ -40,7 +47,7 @@ list_r_sessions_tool <-
)

select_r_session <- function(i) {
lapply(the$server_socket[["dialer"]], nanonext::reap)
nanonext::reap(the$server_socket[["dialer"]][[1L]])
attr(the$server_socket, "dialer") <- NULL
nanonext::dial(
the$server_socket,
Expand Down