@mthines/reaper-mcp 0.94.0 → 0.95.0
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 +48 -48
- package/main.js +3 -1
- package/package.json +1 -1
- package/reaper/CLAUDE.md +1 -1
- package/reaper/mcp_prefs_lib.lua +109 -1
package/main.js
CHANGED
|
@@ -10638,7 +10638,9 @@ async function evaluateDefinition(client, def, context = {}) {
|
|
|
10638
10638
|
// apps/reaper-mcp-server/src/flags.ts
|
|
10639
10639
|
var FLAGS_FILE = "flags.json";
|
|
10640
10640
|
var FLAGS_ENV = "REAPER_MCP_FLAGS";
|
|
10641
|
-
function defaultFlagsDir() {
|
|
10641
|
+
function defaultFlagsDir(env = process.env, platform7 = process.platform) {
|
|
10642
|
+
if (env.XDG_CONFIG_HOME) return join13(env.XDG_CONFIG_HOME, "reaper-mcp");
|
|
10643
|
+
if (platform7 === "win32" && env.APPDATA) return join13(env.APPDATA, "reaper-mcp");
|
|
10642
10644
|
return join13(homedir9(), ".config", "reaper-mcp");
|
|
10643
10645
|
}
|
|
10644
10646
|
function parseJson(raw) {
|
package/package.json
CHANGED
package/reaper/CLAUDE.md
CHANGED
|
@@ -20,7 +20,7 @@ Files installed INTO the REAPER DAW by the `setup` command. These run inside REA
|
|
|
20
20
|
| `mcp_midi_lib.lua` | Lua | Quantize, transform, MIDI file import, pitch-class profile for detect_key, bar/beat grid + per-segment profiles for detect_chords |
|
|
21
21
|
| `mcp_edit_views_lib.lua` | Lua | Status page results and before/after edit views |
|
|
22
22
|
| `mcp_snapshot_lib.lua` | Lua | Shared library for snapshot action scripts (path helpers, JSON, restore logic) |
|
|
23
|
-
| `mcp_prefs_lib.lua` | Lua | Keeps the page's read-only (lk_ro_) LoreKit token in `~/.config/reaper-mcp/lorekit.json` (mode 600) so every way of opening the page shares them; bridge holds it in `ext.prefs` (the bridge is at Lua's 200-locals limit: add no top-level local) |
|
|
23
|
+
| `mcp_prefs_lib.lua` | Lua | Keeps the page's read-only (lk_ro_) LoreKit token in `~/.config/reaper-mcp/lorekit.json` (mode 600) and the feature-flag overrides in `flags.json` (ExtState `flag_overrides` / `flags_req`, the same file the CLI and server read) so every way of opening the page shares them; bridge holds it in `ext.prefs` (the bridge is at Lua's 200-locals limit: add no top-level local) |
|
|
24
24
|
| `mcp_snapshots_ui_lib.lua` | Lua | Status page Snapshots view: lists the folder, runs page restore/save requests through the bridge's dispatcher |
|
|
25
25
|
| `mcp_snapshot_next.lua` | Lua | Action: restore next snapshot (bind to key for A/B testing) |
|
|
26
26
|
| `mcp_snapshot_prev.lua` | Lua | Action: restore previous snapshot (bind to key for A/B testing) |
|
package/reaper/mcp_prefs_lib.lua
CHANGED
|
@@ -16,7 +16,18 @@
|
|
|
16
16
|
-- Replaces the token (an empty hex removes it). The control token is
|
|
17
17
|
-- the bridge's per-run token, only readable from the status feed.
|
|
18
18
|
--
|
|
19
|
-
-- The
|
|
19
|
+
-- The same folder holds flags.json, the feature-flag overrides every surface shares (the CLI's
|
|
20
|
+
-- `reaper-mcp flags set`, the MCP server's evaluation, and the page's Developer drawer):
|
|
21
|
+
--
|
|
22
|
+
-- flag_overrides = {"v":1,"overrides":{"<flag>":"<variant>"},"req":…,"ok":…,"error":…,"writable":…}
|
|
23
|
+
-- Published on start, after every request and whenever the file changed on
|
|
24
|
+
-- disk (the CLI wrote it), checked about every two seconds. No secret in it.
|
|
25
|
+
-- flags_req = <id>-<control token>-<hex JSON of the whole overrides map>
|
|
26
|
+
-- Replaces flags.json. The map is validated here (kebab-case flag keys,
|
|
27
|
+
-- short plain-text variants, at most 100); the server drops anything that
|
|
28
|
+
-- names no real flag or variant when it reads the file.
|
|
29
|
+
--
|
|
30
|
+
-- The token file is JSON {"readToken":…}, created with mode 600 where chmod exists. A file that holds anything
|
|
20
31
|
-- else (an earlier version also kept a publishToken) is rewritten without it when the bridge starts.
|
|
21
32
|
-- Loaded by mcp_bridge.lua (keeps the bridge under Lua's 200-locals limit).
|
|
22
33
|
-- =============================================================================
|
|
@@ -28,6 +39,10 @@ local loaded = false
|
|
|
28
39
|
local state = { read = nil }
|
|
29
40
|
local TOKEN_MAX = 512
|
|
30
41
|
local FILE = "lorekit.json"
|
|
42
|
+
local FLAGS_FILE = "flags.json"
|
|
43
|
+
local FLAGS_MAX = 100
|
|
44
|
+
local FLAGS_CHECK_TICKS = 60 -- about every two seconds at the ~30 ms defer loop
|
|
45
|
+
local flags = { overrides = {}, text = nil, ticks = 0 }
|
|
31
46
|
|
|
32
47
|
-- The folder of the shared config: $XDG_CONFIG_HOME/reaper-mcp, else ~/.config/reaper-mcp (macOS and Linux),
|
|
33
48
|
-- %APPDATA%/reaper-mcp on Windows. getenv is injected so it can be tested.
|
|
@@ -109,6 +124,87 @@ local function handle(req)
|
|
|
109
124
|
publish(id, ok and true or false, err)
|
|
110
125
|
end
|
|
111
126
|
|
|
127
|
+
-- ---------------------------------------------------------------------------
|
|
128
|
+
-- Feature-flag overrides (flags.json)
|
|
129
|
+
-- ---------------------------------------------------------------------------
|
|
130
|
+
|
|
131
|
+
local function valid_flag_key(k)
|
|
132
|
+
return type(k) == "string" and #k <= 64 and k:match("^[a-z][a-z0-9%-]*$") ~= nil
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
local function valid_flag_variant(v)
|
|
136
|
+
return type(v) == "string" and #v >= 1 and #v <= 64 and not v:find("%c")
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
-- A sanitized copy of a decoded map, or nil when it is not a map of flag keys to variants
|
|
140
|
+
local function clean_flags(t)
|
|
141
|
+
if type(t) ~= "table" then return nil end
|
|
142
|
+
local out, n = {}, 0
|
|
143
|
+
for k, v in pairs(t) do
|
|
144
|
+
if not valid_flag_key(k) or not valid_flag_variant(v) then return nil end
|
|
145
|
+
n = n + 1
|
|
146
|
+
if n > FLAGS_MAX then return nil end
|
|
147
|
+
out[k] = v
|
|
148
|
+
end
|
|
149
|
+
return out
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
local function has_keys(t)
|
|
153
|
+
for _ in pairs(t) do return true end
|
|
154
|
+
return false
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
local function publish_flags(req, ok, err)
|
|
158
|
+
ctx.api.SetExtState(ctx.section, "flag_overrides", ctx.encode({
|
|
159
|
+
v = 1,
|
|
160
|
+
-- an empty Lua table would encode as a list: leave it out and the page reads "no overrides"
|
|
161
|
+
overrides = has_keys(flags.overrides) and flags.overrides or nil,
|
|
162
|
+
req = req, ok = ok, error = err,
|
|
163
|
+
writable = ctx.dir ~= nil,
|
|
164
|
+
}), false)
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
-- Reads flags.json; true when it changed since the last read. A missing or unreadable file means no overrides.
|
|
168
|
+
local function load_flags()
|
|
169
|
+
local text = ctx.dir and ctx.read_file(ctx.dir .. FLAGS_FILE) or ""
|
|
170
|
+
if text == flags.text then return false end
|
|
171
|
+
flags.text = text
|
|
172
|
+
local overrides = {}
|
|
173
|
+
if text ~= "" then
|
|
174
|
+
local ok, data = pcall(ctx.decode, text)
|
|
175
|
+
overrides = ok and clean_flags(data) or {}
|
|
176
|
+
end
|
|
177
|
+
flags.overrides = overrides
|
|
178
|
+
return true
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
local function save_flags()
|
|
182
|
+
if not ctx.dir then return nil, "No home folder to keep the flag overrides in" end
|
|
183
|
+
ctx.api.RecursiveCreateDirectory(ctx.dir, 0)
|
|
184
|
+
local f = io.open(ctx.dir .. FLAGS_FILE, "w")
|
|
185
|
+
if not f then return nil, "Can't write " .. ctx.dir .. FLAGS_FILE end
|
|
186
|
+
local text = has_keys(flags.overrides) and ctx.encode(flags.overrides) or "{}"
|
|
187
|
+
f:write(text .. "\n")
|
|
188
|
+
f:close()
|
|
189
|
+
flags.text = text .. "\n"
|
|
190
|
+
return true
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
local function handle_flags(req)
|
|
194
|
+
local id, token, json_hex = req:match("^([%w_]+)%-(%w+)%-(%x*)$")
|
|
195
|
+
if not id or token ~= ctx.token() then return end
|
|
196
|
+
local json = unhex(json_hex)
|
|
197
|
+
local ok, data = false, nil
|
|
198
|
+
if json and json ~= "" then ok, data = pcall(ctx.decode, json) end
|
|
199
|
+
local next_overrides = ok and clean_flags(data) or nil
|
|
200
|
+
if not next_overrides then return publish_flags(id, false, "Malformed flag overrides") end
|
|
201
|
+
local before = flags.overrides
|
|
202
|
+
flags.overrides = next_overrides
|
|
203
|
+
local saved, err = save_flags()
|
|
204
|
+
if not saved then flags.overrides = before end
|
|
205
|
+
publish_flags(id, saved and true or false, err)
|
|
206
|
+
end
|
|
207
|
+
|
|
112
208
|
-- Called every defer tick
|
|
113
209
|
function M.poll()
|
|
114
210
|
if not loaded then
|
|
@@ -116,6 +212,18 @@ function M.poll()
|
|
|
116
212
|
-- An older file also kept the write token: take it out
|
|
117
213
|
if load() then save() end
|
|
118
214
|
publish(nil, true)
|
|
215
|
+
load_flags()
|
|
216
|
+
publish_flags(nil, true)
|
|
217
|
+
end
|
|
218
|
+
flags.ticks = flags.ticks + 1
|
|
219
|
+
if flags.ticks >= FLAGS_CHECK_TICKS then
|
|
220
|
+
flags.ticks = 0
|
|
221
|
+
if load_flags() then publish_flags(nil, true) end
|
|
222
|
+
end
|
|
223
|
+
local freq = ctx.api.GetExtState(ctx.section, "flags_req")
|
|
224
|
+
if freq ~= "" then
|
|
225
|
+
ctx.api.DeleteExtState(ctx.section, "flags_req", false)
|
|
226
|
+
handle_flags(freq)
|
|
119
227
|
end
|
|
120
228
|
local req = ctx.api.GetExtState(ctx.section, "tokens_req")
|
|
121
229
|
if req ~= "" then
|