@mthines/reaper-mcp 0.98.0 → 0.99.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -45
- package/bridge-ui/mcp_bridge.html +50 -48
- package/main.js +224 -208
- package/package.json +1 -1
- package/reaper/mcp_bridge.lua +76 -1
package/reaper/mcp_bridge.lua
CHANGED
|
@@ -4860,16 +4860,87 @@ local function update_log_tail(max)
|
|
|
4860
4860
|
return tail
|
|
4861
4861
|
end
|
|
4862
4862
|
|
|
4863
|
+
-- Installing the Python sidecar from the page: the same detached-job pattern as the update above, one job at a
|
|
4864
|
+
-- time, run as `node <cli> setup-sidecar --yes [part flag]` (the CLI an npm install or a built clone has).
|
|
4865
|
+
-- Actions: sidecar (core + aesthetics), sidecarsep (adds stem separation), sidecarchords (adds the chord model),
|
|
4866
|
+
-- sidecarlite (core only, without the 831 MB aesthetics model: what the voice preview needs).
|
|
4867
|
+
-- One table, not locals: this chunk is close to Lua's 200-locals limit.
|
|
4868
|
+
local sidecar_job = {
|
|
4869
|
+
log = bridge_dir .. "sidecar.log",
|
|
4870
|
+
exit = bridge_dir .. "sidecar.exit",
|
|
4871
|
+
flags = { sidecar = "", sidecarsep = " --with-separation", sidecarchords = " --with-chords", sidecarlite = " --without-aesthetics" },
|
|
4872
|
+
can = false, -- the CLI is known (set by refresh_update_config)
|
|
4873
|
+
state = nil, -- { kind, state = "running" | "done" | "failed", startedAt, log = { lines } }
|
|
4874
|
+
last_poll = 0,
|
|
4875
|
+
}
|
|
4876
|
+
|
|
4877
|
+
function sidecar_job.cli(conf)
|
|
4878
|
+
if conf.cli and conf.cli ~= "" then return file_exists(conf.cli) and conf.cli or nil end
|
|
4879
|
+
local built = conf.repo and (conf.repo .. "/dist/apps/reaper-mcp-server/main.js")
|
|
4880
|
+
return built and file_exists(built) and built or nil
|
|
4881
|
+
end
|
|
4882
|
+
|
|
4883
|
+
function sidecar_job.start(kind)
|
|
4884
|
+
local st = sidecar_job.state
|
|
4885
|
+
local flags = sidecar_job.flags[kind]
|
|
4886
|
+
if is_windows or flags == nil or (st and st.state == "running") then return end
|
|
4887
|
+
local conf = update_config()
|
|
4888
|
+
local cli = conf and sidecar_job.cli(conf)
|
|
4889
|
+
if not cli then return end
|
|
4890
|
+
os.remove(sidecar_job.log)
|
|
4891
|
+
os.remove(sidecar_job.exit)
|
|
4892
|
+
local node_dir = conf.node and conf.node:match("^(.*)/[^/]+$")
|
|
4893
|
+
local path = (node_dir and (shell_quote(node_dir) .. ":") or "") .. "/opt/homebrew/bin:/usr/local/bin:$PATH"
|
|
4894
|
+
local job = "PATH=" .. path .. " " .. shell_quote(conf.node or "node") .. " " .. shell_quote(cli) .. " setup-sidecar --yes" .. flags
|
|
4895
|
+
os.execute("( " .. job .. " < /dev/null > " .. shell_quote(sidecar_job.log)
|
|
4896
|
+
.. " 2>&1; echo $? > " .. shell_quote(sidecar_job.exit) .. " ) >/dev/null 2>&1 &")
|
|
4897
|
+
sidecar_job.state = { kind = kind, state = "running", startedAt = now_ms(), log = {} }
|
|
4898
|
+
log_event("bridge_sidecar_install_start", { kind = kind })
|
|
4899
|
+
status_dirty = true
|
|
4900
|
+
end
|
|
4901
|
+
|
|
4902
|
+
function sidecar_job.poll(now)
|
|
4903
|
+
local st = sidecar_job.state
|
|
4904
|
+
if not st or st.state ~= "running" or now - sidecar_job.last_poll < 1 then return end
|
|
4905
|
+
sidecar_job.last_poll = now
|
|
4906
|
+
local text = read_file(sidecar_job.log) or ""
|
|
4907
|
+
local lines = {}
|
|
4908
|
+
for line in text:gmatch("[^\n]+") do
|
|
4909
|
+
line = line:gsub("\27%[[%d;]*%a", ""):match("([^\r]*)\r*$") or ""
|
|
4910
|
+
if line:match("%S") then lines[#lines + 1] = line end
|
|
4911
|
+
end
|
|
4912
|
+
local tail = {}
|
|
4913
|
+
for i = math.max(1, #lines - 7), #lines do tail[#tail + 1] = lines[i] end
|
|
4914
|
+
if #tail ~= #st.log or tail[#tail] ~= st.log[#st.log] then
|
|
4915
|
+
st.log = tail
|
|
4916
|
+
status_dirty = true
|
|
4917
|
+
end
|
|
4918
|
+
local code = read_file(sidecar_job.exit)
|
|
4919
|
+
if not code then return end
|
|
4920
|
+
local n = tonumber(code:match("%d+")) -- the shell creates the file before `echo` fills it
|
|
4921
|
+
if not n then return end
|
|
4922
|
+
st.state = n == 0 and "done" or "failed"
|
|
4923
|
+
log_event("bridge_sidecar_install_end", { state = st.state })
|
|
4924
|
+
status_dirty = true
|
|
4925
|
+
end
|
|
4926
|
+
|
|
4863
4927
|
local function check_control(now)
|
|
4864
4928
|
local request = reaper.GetExtState(STATUS_SECTION, "request")
|
|
4865
4929
|
if request and request ~= "" then
|
|
4866
4930
|
reaper.DeleteExtState(STATUS_SECTION, "request", false)
|
|
4867
4931
|
local action, token = request:match("^(%a+)%-(%x+)$")
|
|
4868
4932
|
if token == control_token then
|
|
4869
|
-
|
|
4933
|
+
-- One job at a time: an update replaces the CLI and scripts a sidecar install is running from
|
|
4934
|
+
local sc, installing = sidecar_job.state, false
|
|
4935
|
+
installing = sc ~= nil and sc.state == "running"
|
|
4936
|
+
if action == "update" or action == "rebuild" then
|
|
4937
|
+
if not installing then start_update(action) end
|
|
4938
|
+
elseif sidecar_job.flags[action] then
|
|
4939
|
+
if not (update and update.state == "running") then sidecar_job.start(action) end
|
|
4870
4940
|
elseif action == "restart" and can_restart then restart_bridge() return end
|
|
4871
4941
|
end
|
|
4872
4942
|
end
|
|
4943
|
+
sidecar_job.poll(now)
|
|
4873
4944
|
if not update or update.state ~= "running" or now - last_update_poll < 1 then return end
|
|
4874
4945
|
last_update_poll = now
|
|
4875
4946
|
local log = update_log_tail(12)
|
|
@@ -4901,6 +4972,7 @@ local function refresh_update_config()
|
|
|
4901
4972
|
local conf = not is_windows and update_config() or nil
|
|
4902
4973
|
can_update, conf_dev = conf ~= nil, conf ~= nil and conf.dev == "1"
|
|
4903
4974
|
update_source = conf ~= nil and conf.mode == "npm" and "npm" or "clone"
|
|
4975
|
+
sidecar_job.can = conf ~= nil and sidecar_job.cli(conf) ~= nil
|
|
4904
4976
|
end
|
|
4905
4977
|
|
|
4906
4978
|
-- Developer mode: the page's toggle (cfg_dev "1"/"0") once chosen, else what setup detected (dev=1 in mcp_update.conf)
|
|
@@ -4947,6 +5019,9 @@ local function control_status()
|
|
|
4947
5019
|
-- Developer mode: source changed since the last install, so Rebuild & reload has something to do
|
|
4948
5020
|
changed = source_changed,
|
|
4949
5021
|
update = update,
|
|
5022
|
+
-- The page may install the Python sidecar (setup-sidecar run detached), and how that run is going
|
|
5023
|
+
canInstallSidecar = sidecar_job.can,
|
|
5024
|
+
sidecar = sidecar_job.state,
|
|
4950
5025
|
-- The page may list, restore and save snapshots (mcp_snapshots_ui_lib.lua)
|
|
4951
5026
|
snapshots = snaps_lib_ok,
|
|
4952
5027
|
-- The page keeps its LoreKit tokens in ~/.config/reaper-mcp (mcp_prefs_lib.lua)
|