tmux-ide 2.9.20 → 2.9.22
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/bin/cli.js +16998 -4283
- package/package.json +3 -2
- package/packages/contracts/src/command-catalog.ts +116 -0
- package/packages/contracts/src/commands.ts +5 -4
- package/packages/contracts/src/daemon-events.ts +2 -1
- package/packages/contracts/src/index.ts +3 -0
- package/packages/contracts/src/pane-reader.ts +121 -0
- package/packages/contracts/src/pane-stream.ts +18 -0
- package/packages/contracts/src/plain-text.ts +61 -0
- package/packages/contracts/src/visual-theme-presets.ts +58 -2
- package/packages/daemon/dist/command-center/command-catalog-routes.js +78 -0
- package/packages/daemon/dist/command-center/plugin-routes.js +84 -0
- package/packages/daemon/dist/command-center/server.js +13 -0
- package/packages/daemon/dist/command-center/tmux-server-reader.js +41 -0
- package/packages/daemon/dist/command-center/tmux-servers.js +6 -0
- package/packages/daemon/dist/doctor.js +106 -43
- package/packages/daemon/dist/lib/cli-action-bridge.js +15 -0
- package/packages/daemon/dist/lib/cli-command.js +13 -0
- package/packages/daemon/dist/lib/daemon-embed.js +39 -1
- package/packages/daemon/dist/lib/headless-daemon.js +1 -0
- package/packages/daemon/dist/lib/pane-reader-files.js +226 -0
- package/packages/daemon/dist/lib/remote-tmux-command.js +8 -5
- package/packages/daemon/dist/lib/tmux-client-execution.js +73 -7
- package/packages/daemon/dist/lib/tmux-pane-reader.js +105 -0
- package/packages/daemon/dist/lib/tmux-server-features.js +38 -0
- package/packages/daemon/dist/lib/tmux-server-owner.js +9 -0
- package/packages/daemon/dist/lib/worktree.js +18 -0
- package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/Info.plist +2 -2
- package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/MacOS/tmux-ide-notifier +0 -0
- package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/Resources/Assets.car +0 -0
- package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/_CodeSignature/CodeResources +2 -2
- package/packages/daemon/dist/open-browser.js +26 -12
- package/packages/daemon/dist/open-reader.js +84 -0
- package/packages/daemon/dist/plugins/action-catalog.js +129 -0
- package/packages/daemon/dist/plugins/action-cli.js +212 -0
- package/packages/daemon/dist/plugins/api-table.js +303 -0
- package/packages/daemon/dist/plugins/cli.js +556 -0
- package/packages/daemon/dist/plugins/consent.js +107 -0
- package/packages/daemon/dist/plugins/daemon-plugins.js +124 -0
- package/packages/daemon/dist/plugins/discovery.js +142 -0
- package/packages/daemon/dist/plugins/examples/worktree-tasks.js +115 -0
- package/packages/daemon/dist/plugins/exec-sandbox.js +202 -0
- package/packages/daemon/dist/plugins/host/actions-prelude.js +279 -0
- package/packages/daemon/dist/plugins/host/entry.js +4 -0
- package/packages/daemon/dist/plugins/host/host-api-prelude.js +232 -0
- package/packages/daemon/dist/plugins/host/lua-state.js +493 -0
- package/packages/daemon/dist/plugins/host/main.js +322 -0
- package/packages/daemon/dist/plugins/host/sandbox.js +299 -0
- package/packages/daemon/dist/plugins/host-calls.js +279 -0
- package/packages/daemon/dist/plugins/manifest.js +69 -0
- package/packages/daemon/dist/plugins/plugin-exec.js +261 -0
- package/packages/daemon/dist/plugins/plugin-log.js +54 -0
- package/packages/daemon/dist/plugins/plugin-store.js +74 -0
- package/packages/daemon/dist/plugins/protocol.js +252 -0
- package/packages/daemon/dist/plugins/safe-files.js +97 -0
- package/packages/daemon/dist/plugins/supervisor.js +790 -0
- package/packages/daemon/dist/plugins/worktree-calls.js +154 -0
- package/packages/daemon/dist/restore.js +57 -40
- package/packages/daemon/dist/terminal/mirror/session-channel.js +4 -1
- package/packages/daemon/dist/terminal/pane-stream/pane-stream-websocket.js +12 -3
- package/packages/daemon/dist/terminal/protocol/reader-option.js +66 -0
- package/packages/daemon/dist/terminal/protocol/session-descriptor-discovery.js +7 -2
- package/packages/daemon/dist/tmux-upgrade/cli.js +106 -0
- package/packages/daemon/dist/tmux-upgrade/io.js +540 -0
- package/packages/daemon/dist/tmux-upgrade/plan.js +238 -0
- package/packages/daemon/dist/tmux-upgrade/run.js +199 -0
- package/packages/daemon/dist/tui/chrome/snapshot.js +3 -4
- package/packages/daemon/dist/tui/mirror/runtime/application-home-agent-navigation.js +64 -4
- package/packages/daemon/dist/tui/mirror/runtime/application-home-agents-owner.js +62 -5
- package/packages/daemon/dist/tui/mirror/runtime/application-home-experience.js +2 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-machine-agent-navigation.js +12 -8
- package/packages/daemon/dist/tui/mirror/runtime/application-palette-command-owner.js +30 -2
- package/packages/daemon/dist/tui/mirror/runtime/application-plugin-commands.js +152 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-plugin-form.js +251 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-terminal-interaction-controller.js +125 -111
- package/packages/daemon/dist/tui/mirror/workspace/application-command-description.js +14 -0
- package/packages/daemon/dist/tui/mirror/workspace/palette-list-layout.js +5 -0
- package/packages/daemon/src/command-center/command-catalog-routes.ts +116 -0
- package/packages/daemon/src/command-center/plugin-routes.ts +110 -0
- package/packages/daemon/src/command-center/server.ts +15 -0
- package/packages/daemon/src/command-center/tmux-server-reader.ts +62 -0
- package/packages/daemon/src/command-center/tmux-servers.ts +6 -0
- package/packages/daemon/src/doctor.ts +118 -45
- package/packages/daemon/src/lib/cli-action-bridge.ts +19 -0
- package/packages/daemon/src/lib/cli-command.ts +16 -0
- package/packages/daemon/src/lib/daemon-embed.ts +59 -0
- package/packages/daemon/src/lib/headless-daemon.ts +1 -0
- package/packages/daemon/src/lib/pane-reader-files.ts +294 -0
- package/packages/daemon/src/lib/remote-tmux-command.ts +13 -6
- package/packages/daemon/src/lib/tmux-client-execution.ts +79 -7
- package/packages/daemon/src/lib/tmux-pane-reader.ts +144 -0
- package/packages/daemon/src/lib/tmux-server-features.ts +43 -0
- package/packages/daemon/src/lib/tmux-server-owner.ts +9 -0
- package/packages/daemon/src/lib/worktree.ts +16 -0
- package/packages/daemon/src/open-browser.ts +59 -18
- package/packages/daemon/src/open-reader.ts +148 -0
- package/packages/daemon/src/plugins/action-catalog.ts +141 -0
- package/packages/daemon/src/plugins/action-cli.ts +248 -0
- package/packages/daemon/src/plugins/api-table.ts +346 -0
- package/packages/daemon/src/plugins/cli.ts +630 -0
- package/packages/daemon/src/plugins/consent.ts +125 -0
- package/packages/daemon/src/plugins/daemon-plugins.ts +172 -0
- package/packages/daemon/src/plugins/discovery.ts +176 -0
- package/packages/daemon/src/plugins/examples/worktree-tasks.ts +120 -0
- package/packages/daemon/src/plugins/exec-sandbox.ts +264 -0
- package/packages/daemon/src/plugins/host/actions-prelude.ts +280 -0
- package/packages/daemon/src/plugins/host/entry.ts +5 -0
- package/packages/daemon/src/plugins/host/host-api-prelude.ts +233 -0
- package/packages/daemon/src/plugins/host/lua-state.ts +557 -0
- package/packages/daemon/src/plugins/host/main.ts +359 -0
- package/packages/daemon/src/plugins/host/sandbox.ts +301 -0
- package/packages/daemon/src/plugins/host-calls.ts +343 -0
- package/packages/daemon/src/plugins/manifest.ts +74 -0
- package/packages/daemon/src/plugins/plugin-exec.ts +326 -0
- package/packages/daemon/src/plugins/plugin-log.ts +63 -0
- package/packages/daemon/src/plugins/plugin-store.ts +80 -0
- package/packages/daemon/src/plugins/protocol.ts +275 -0
- package/packages/daemon/src/plugins/safe-files.ts +105 -0
- package/packages/daemon/src/plugins/supervisor.ts +954 -0
- package/packages/daemon/src/plugins/worktree-calls.ts +183 -0
- package/packages/daemon/src/restore.ts +80 -44
- package/packages/daemon/src/terminal/mirror/events.ts +2 -0
- package/packages/daemon/src/terminal/mirror/session-channel.ts +6 -1
- package/packages/daemon/src/terminal/pane-stream/pane-stream-websocket.ts +15 -2
- package/packages/daemon/src/terminal/protocol/reader-option.ts +77 -0
- package/packages/daemon/src/terminal/protocol/session-descriptor-discovery.ts +10 -1
- package/packages/daemon/src/tmux-upgrade/cli.ts +118 -0
- package/packages/daemon/src/tmux-upgrade/io.ts +596 -0
- package/packages/daemon/src/tmux-upgrade/plan.ts +353 -0
- package/packages/daemon/src/tmux-upgrade/run.ts +325 -0
- package/packages/daemon/src/tui/chrome/snapshot.ts +3 -4
- package/packages/daemon/src/tui/mirror/runtime/application-fleet-switcher.tsx +3 -1
- package/packages/daemon/src/tui/mirror/runtime/application-home-agent-navigation.ts +110 -10
- package/packages/daemon/src/tui/mirror/runtime/application-home-agents-owner.ts +90 -6
- package/packages/daemon/src/tui/mirror/runtime/application-home-experience.ts +2 -0
- package/packages/daemon/src/tui/mirror/runtime/application-machine-agent-navigation.ts +20 -9
- package/packages/daemon/src/tui/mirror/runtime/application-palette-command-owner.ts +42 -2
- package/packages/daemon/src/tui/mirror/runtime/application-palette-preview.tsx +7 -1
- package/packages/daemon/src/tui/mirror/runtime/application-plugin-commands.ts +229 -0
- package/packages/daemon/src/tui/mirror/runtime/application-plugin-form.ts +312 -0
- package/packages/daemon/src/tui/mirror/runtime/application-root-v2.tsx +2 -2
- package/packages/daemon/src/tui/mirror/runtime/application-terminal-interaction-controller.ts +149 -128
- package/packages/daemon/src/tui/mirror/workspace/application-command-description.ts +44 -2
- package/packages/daemon/src/tui/mirror/workspace/palette-list-layout.ts +4 -0
- package/packages/tmux-bridge/src/runner.ts +3 -1
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `ide.action`: named functions a plugin offers to the command palette, key
|
|
3
|
+
* bindings and `tmux-ide action run`. Runs after SANDBOX_PRELUDE and reaches
|
|
4
|
+
* it only through `__ide_internal`.
|
|
5
|
+
*
|
|
6
|
+
* The plugin keeps its callbacks; the host learns only plain descriptors. A
|
|
7
|
+
* change calls `__ide_actions_changed()`, and when the callback finishes the
|
|
8
|
+
* host reads the list once through `__ide_internal.actions_json()`.
|
|
9
|
+
* Arguments are checked here, in Lua, so `pattern` is a Lua pattern.
|
|
10
|
+
*/
|
|
11
|
+
export const MAX_ACTIONS_PER_PLUGIN = 200;
|
|
12
|
+
export const MAX_PARAMS_PER_ACTION = 32;
|
|
13
|
+
/** Local action id length, so `plugin.<name>.<id>` fits the catalog's 160. */
|
|
14
|
+
export const MAX_LOCAL_ACTION_ID = 80;
|
|
15
|
+
export const ACTIONS_PRELUDE = String.raw `
|
|
16
|
+
local internal = __ide_internal
|
|
17
|
+
local mark_dirty = __ide_actions_changed
|
|
18
|
+
__ide_actions_changed = nil
|
|
19
|
+
|
|
20
|
+
local arm, runners, ide, json_encode = internal.arm, internal.runners, internal.ide, internal.json_encode
|
|
21
|
+
local raw_error, raw_type, raw_pairs, raw_ipairs, raw_tostring =
|
|
22
|
+
error, type, pairs, ipairs, tostring
|
|
23
|
+
local s_match, s_find = string.match, string.find
|
|
24
|
+
local co_running = coroutine.running
|
|
25
|
+
local MAX_ACTIONS = ${MAX_ACTIONS_PER_PLUGIN}
|
|
26
|
+
local MAX_PARAMS = ${MAX_PARAMS_PER_ACTION}
|
|
27
|
+
local MAX_ID = ${MAX_LOCAL_ACTION_ID}
|
|
28
|
+
|
|
29
|
+
local actions = {}
|
|
30
|
+
local order = {}
|
|
31
|
+
|
|
32
|
+
local PARAM_TYPES = { string = true, text = true, number = true, boolean = true, choice = true }
|
|
33
|
+
|
|
34
|
+
local function fail(message) raw_error("E_INVALID: " .. message, 3) end
|
|
35
|
+
|
|
36
|
+
-- Plain text only: no C0/DEL controls, C1 controls, bidi or zero-width
|
|
37
|
+
-- format characters, U+FEFF, soft hyphens or U+2028/U+2029; the catalog
|
|
38
|
+
-- schema refuses the rarer format characters at publish. They
|
|
39
|
+
-- would reach terminals that show this text.
|
|
40
|
+
local function unsafe(text)
|
|
41
|
+
return s_find(text, "[%c\127]") ~= nil
|
|
42
|
+
or s_find(text, "\194[\128-\159]") ~= nil
|
|
43
|
+
or s_find(text, "\216\156") ~= nil
|
|
44
|
+
or s_find(text, "\226\128[\139-\143\168-\174]") ~= nil
|
|
45
|
+
or s_find(text, "\226\129[\160-\164\166-\175]") ~= nil
|
|
46
|
+
or s_find(text, "\239\187\191") ~= nil
|
|
47
|
+
or s_find(text, "\194\173") ~= nil
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
local function check_string(value, what, max, optional)
|
|
51
|
+
if value == nil and optional then return nil end
|
|
52
|
+
if raw_type(value) ~= "string" or #value == 0 or #value > max then
|
|
53
|
+
fail(what .. " must be a string of 1 to " .. max .. " characters")
|
|
54
|
+
end
|
|
55
|
+
if unsafe(value) then fail(what .. " must be plain text: no control characters or newlines") end
|
|
56
|
+
return value
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
local function normalize_choices(list, where)
|
|
60
|
+
if raw_type(list) ~= "table" then fail(where .. " must return a list") end
|
|
61
|
+
local out = {}
|
|
62
|
+
for i, item in raw_ipairs(list) do
|
|
63
|
+
if i > 500 then fail(where .. " has more than 500 choices") end
|
|
64
|
+
if raw_type(item) == "string" then
|
|
65
|
+
out[i] = { value = item, label = item }
|
|
66
|
+
elseif raw_type(item) == "table" and raw_type(item.value) == "string" then
|
|
67
|
+
out[i] = { value = item.value, label = raw_type(item.label) == "string" and item.label or item.value }
|
|
68
|
+
else
|
|
69
|
+
out[i] = false
|
|
70
|
+
end
|
|
71
|
+
if not out[i] or unsafe(out[i].value) or unsafe(out[i].label) or #out[i].label == 0 then
|
|
72
|
+
fail(where .. " entries must be strings or { value, label } tables")
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
return out
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
local function normalize_param(param, index)
|
|
79
|
+
if raw_type(param) ~= "table" then fail("params[" .. index .. "] must be a table") end
|
|
80
|
+
local name = param.name
|
|
81
|
+
if raw_type(name) ~= "string" or not s_match(name, "^[a-z_][a-z0-9_]*$") or #name > 64 then
|
|
82
|
+
fail("params[" .. index .. "].name must be lowercase letters, digits and _")
|
|
83
|
+
end
|
|
84
|
+
local kind = param.type or "string"
|
|
85
|
+
if not PARAM_TYPES[kind] then fail("param '" .. name .. "' has unknown type '" .. raw_tostring(kind) .. "'") end
|
|
86
|
+
if param.pattern ~= nil and raw_type(param.pattern) ~= "string" then
|
|
87
|
+
fail("param '" .. name .. "'.pattern must be a Lua pattern string")
|
|
88
|
+
end
|
|
89
|
+
local static_choices, dynamic_choices = nil, false
|
|
90
|
+
if raw_type(param.choices) == "function" then
|
|
91
|
+
dynamic_choices = true
|
|
92
|
+
elseif param.choices ~= nil then
|
|
93
|
+
static_choices = normalize_choices(param.choices, "param '" .. name .. "'.choices")
|
|
94
|
+
end
|
|
95
|
+
if kind == "choice" and not static_choices and not dynamic_choices then
|
|
96
|
+
fail("choice param '" .. name .. "' needs choices")
|
|
97
|
+
end
|
|
98
|
+
local static_default, dynamic_default = nil, false
|
|
99
|
+
if raw_type(param.default) == "function" then
|
|
100
|
+
dynamic_default = true
|
|
101
|
+
elseif param.default ~= nil then
|
|
102
|
+
local t = raw_type(param.default)
|
|
103
|
+
if t ~= "string" and t ~= "number" and t ~= "boolean" then
|
|
104
|
+
fail("param '" .. name .. "'.default must be a string, number, boolean or function")
|
|
105
|
+
end
|
|
106
|
+
if t == "string" and unsafe(param.default) then
|
|
107
|
+
fail("param '" .. name .. "'.default must be plain text: no control characters or newlines")
|
|
108
|
+
end
|
|
109
|
+
static_default = param.default
|
|
110
|
+
end
|
|
111
|
+
return {
|
|
112
|
+
name = name,
|
|
113
|
+
type = kind,
|
|
114
|
+
label = check_string(param.label, "param '" .. name .. "'.label", 120, true) or name,
|
|
115
|
+
description = check_string(param.description, "param '" .. name .. "'.description", 500, true),
|
|
116
|
+
required = param.optional ~= true,
|
|
117
|
+
default = static_default,
|
|
118
|
+
dynamicDefault = dynamic_default,
|
|
119
|
+
choices = static_choices,
|
|
120
|
+
dynamicChoices = dynamic_choices,
|
|
121
|
+
-- Kept for checking only; never published.
|
|
122
|
+
pattern = param.pattern,
|
|
123
|
+
choices_fn = dynamic_choices and param.choices or nil,
|
|
124
|
+
default_fn = dynamic_default and param.default or nil,
|
|
125
|
+
}
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
local function valid_id(id)
|
|
129
|
+
if raw_type(id) ~= "string" or #id == 0 or #id > MAX_ID then return false end
|
|
130
|
+
if not s_match(id, "^[a-z]") or s_find(id, "..", 1, true) or s_match(id, "%.$") then return false end
|
|
131
|
+
return s_match(id, "^[a-z0-9.-]+$") ~= nil
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
-- The host asks for the list once a callback finishes, so registering many
|
|
135
|
+
-- actions in one load costs one encoding, not one per action.
|
|
136
|
+
local function actions_json()
|
|
137
|
+
local list = {}
|
|
138
|
+
for i, id in raw_ipairs(order) do
|
|
139
|
+
local action = actions[id]
|
|
140
|
+
local params = {}
|
|
141
|
+
for j, p in raw_ipairs(action.params) do
|
|
142
|
+
params[j] = {
|
|
143
|
+
name = p.name, type = p.type, label = p.label, description = p.description,
|
|
144
|
+
required = p.required, default = p.default, dynamicDefault = p.dynamicDefault,
|
|
145
|
+
choices = p.choices, dynamicChoices = p.dynamicChoices,
|
|
146
|
+
}
|
|
147
|
+
end
|
|
148
|
+
list[i] = {
|
|
149
|
+
id = id, title = action.title, category = action.category,
|
|
150
|
+
description = action.description, dangerous = action.dangerous, params = params,
|
|
151
|
+
}
|
|
152
|
+
end
|
|
153
|
+
return json_encode(list)
|
|
154
|
+
end
|
|
155
|
+
internal.actions_json = actions_json
|
|
156
|
+
|
|
157
|
+
ide.action = {
|
|
158
|
+
register = function(spec)
|
|
159
|
+
if raw_type(spec) ~= "table" then fail("ide.action.register expects a table") end
|
|
160
|
+
local id = spec.id
|
|
161
|
+
if not valid_id(id) then
|
|
162
|
+
fail("action id must be dot-separated parts of lowercase letters, digits and dashes, like 'tasks.new'")
|
|
163
|
+
end
|
|
164
|
+
if raw_type(spec.run) ~= "function" then fail("action '" .. id .. "' needs a run function") end
|
|
165
|
+
local params = {}
|
|
166
|
+
local seen = {}
|
|
167
|
+
if spec.params ~= nil then
|
|
168
|
+
if raw_type(spec.params) ~= "table" then fail("params must be a list") end
|
|
169
|
+
for i, param in raw_ipairs(spec.params) do
|
|
170
|
+
if i > MAX_PARAMS then fail("an action may have at most " .. MAX_PARAMS .. " params") end
|
|
171
|
+
local p = normalize_param(param, i)
|
|
172
|
+
if seen[p.name] then fail("param '" .. p.name .. "' is declared twice") end
|
|
173
|
+
seen[p.name] = true
|
|
174
|
+
params[i] = p
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
-- Validate everything before changing anything.
|
|
178
|
+
local record = {
|
|
179
|
+
title = check_string(spec.title, "action '" .. id .. "'.title", 160),
|
|
180
|
+
category = check_string(spec.category, "action '" .. id .. "'.category", 80, true) or "Plugins",
|
|
181
|
+
description = check_string(spec.description, "action '" .. id .. "'.description", 500, true),
|
|
182
|
+
dangerous = spec.dangerous == true,
|
|
183
|
+
params = params,
|
|
184
|
+
run = spec.run,
|
|
185
|
+
}
|
|
186
|
+
if actions[id] == nil then
|
|
187
|
+
if #order >= MAX_ACTIONS then fail("a plugin may register at most " .. MAX_ACTIONS .. " actions") end
|
|
188
|
+
order[#order + 1] = id
|
|
189
|
+
end
|
|
190
|
+
actions[id] = record
|
|
191
|
+
mark_dirty()
|
|
192
|
+
end,
|
|
193
|
+
unregister = function(id)
|
|
194
|
+
if actions[id] == nil then return false end
|
|
195
|
+
actions[id] = nil
|
|
196
|
+
for i, existing in raw_ipairs(order) do
|
|
197
|
+
if existing == id then table.remove(order, i) break end
|
|
198
|
+
end
|
|
199
|
+
mark_dirty()
|
|
200
|
+
return true
|
|
201
|
+
end,
|
|
202
|
+
}
|
|
203
|
+
internal.features.actions = true
|
|
204
|
+
|
|
205
|
+
local function check_args(action, args)
|
|
206
|
+
if raw_type(args) ~= "table" then args = {} end
|
|
207
|
+
local known = {}
|
|
208
|
+
for _, p in raw_ipairs(action.params) do known[p.name] = p end
|
|
209
|
+
for name in raw_pairs(args) do
|
|
210
|
+
if not known[name] then raw_error("E_INVALID: unknown argument '" .. raw_tostring(name) .. "'", 0) end
|
|
211
|
+
end
|
|
212
|
+
local clean = {}
|
|
213
|
+
for _, p in raw_ipairs(action.params) do
|
|
214
|
+
local value = args[p.name]
|
|
215
|
+
if value == nil then value = p.default end
|
|
216
|
+
if value == nil then
|
|
217
|
+
if p.required then raw_error("E_INVALID: '" .. p.label .. "' is required", 0) end
|
|
218
|
+
else
|
|
219
|
+
local t = raw_type(value)
|
|
220
|
+
if (p.type == "number" and t ~= "number")
|
|
221
|
+
or (p.type == "boolean" and t ~= "boolean")
|
|
222
|
+
or ((p.type == "string" or p.type == "text" or p.type == "choice") and t ~= "string") then
|
|
223
|
+
raw_error("E_INVALID: '" .. p.label .. "' must be a " .. p.type, 0)
|
|
224
|
+
end
|
|
225
|
+
if p.pattern and not s_match(value, p.pattern) then
|
|
226
|
+
raw_error("E_INVALID: '" .. p.label .. "' does not match " .. p.pattern, 0)
|
|
227
|
+
end
|
|
228
|
+
if p.type == "choice" and p.choices then
|
|
229
|
+
local ok = false
|
|
230
|
+
for _, c in raw_ipairs(p.choices) do if c.value == value then ok = true break end end
|
|
231
|
+
if not ok then raw_error("E_INVALID: '" .. p.label .. "' must be one of its choices", 0) end
|
|
232
|
+
end
|
|
233
|
+
clean[p.name] = value
|
|
234
|
+
end
|
|
235
|
+
end
|
|
236
|
+
return clean
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
local function find(id)
|
|
240
|
+
local action = actions[id]
|
|
241
|
+
if not action then raw_error("E_NOT_FOUND: no action '" .. raw_tostring(id) .. "'", 0) end
|
|
242
|
+
return action
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
internal.invoke_action = function(id, args, context)
|
|
246
|
+
runners[co_running()] = true
|
|
247
|
+
arm()
|
|
248
|
+
local action = find(id)
|
|
249
|
+
local clean = check_args(action, args)
|
|
250
|
+
return json_encode({ action.run(context or {}, clean) })
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
internal.param_options = function(id, name, context)
|
|
254
|
+
runners[co_running()] = true
|
|
255
|
+
arm()
|
|
256
|
+
local action = find(id)
|
|
257
|
+
for _, p in raw_ipairs(action.params) do
|
|
258
|
+
if p.name == name then
|
|
259
|
+
local result = { choices = p.choices, default = p.default }
|
|
260
|
+
if p.choices_fn then
|
|
261
|
+
result.choices = normalize_choices(p.choices_fn(context or {}), "choices for '" .. name .. "'")
|
|
262
|
+
end
|
|
263
|
+
if p.default_fn then
|
|
264
|
+
local value = p.default_fn(context or {})
|
|
265
|
+
local t = raw_type(value)
|
|
266
|
+
if value ~= nil and t ~= "string" and t ~= "number" and t ~= "boolean" then
|
|
267
|
+
raw_error("E_INVALID: default for '" .. name .. "' must be a string, number or boolean", 0)
|
|
268
|
+
end
|
|
269
|
+
if t == "string" and unsafe(value) then
|
|
270
|
+
raw_error("E_INVALID: default for '" .. name .. "' must be plain text", 0)
|
|
271
|
+
end
|
|
272
|
+
result.default = value
|
|
273
|
+
end
|
|
274
|
+
return json_encode(result)
|
|
275
|
+
end
|
|
276
|
+
end
|
|
277
|
+
raw_error("E_NOT_FOUND: action '" .. id .. "' has no param '" .. raw_tostring(name) .. "'", 0)
|
|
278
|
+
end
|
|
279
|
+
`;
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The rest of the `ide` API: exec, panes, sessions, timers, json, store and
|
|
3
|
+
* notify. Runs after SANDBOX_PRELUDE and ACTIONS_PRELUDE and reaches them
|
|
4
|
+
* only through `__ide_internal`. Daemon-side work goes through the private
|
|
5
|
+
* host functions in `__ide_internal.host` (see ../host-calls.ts).
|
|
6
|
+
*/
|
|
7
|
+
export const MAX_TIMERS_PER_PLUGIN = 64;
|
|
8
|
+
export const MIN_REPEAT_MS = 250;
|
|
9
|
+
export const HOST_API_PRELUDE = String.raw `
|
|
10
|
+
local internal = __ide_internal
|
|
11
|
+
local timer_start, timer_cancel, json_decode_raw = __ide_timer_start, __ide_timer_cancel, __ide_json_decode
|
|
12
|
+
__ide_timer_start, __ide_timer_cancel, __ide_json_decode = nil, nil, nil
|
|
13
|
+
|
|
14
|
+
local ide, host, arm, runners = internal.ide, internal.host, internal.arm, internal.runners
|
|
15
|
+
local json_encode = internal.json_encode
|
|
16
|
+
local raw_error, raw_type, raw_pairs, raw_ipairs, raw_tostring, raw_setmetatable =
|
|
17
|
+
error, type, pairs, ipairs, tostring, setmetatable
|
|
18
|
+
local m_type = math.type
|
|
19
|
+
local co_running = coroutine.running
|
|
20
|
+
local MAX_TIMERS, MIN_REPEAT = ${MAX_TIMERS_PER_PLUGIN}, ${MIN_REPEAT_MS}
|
|
21
|
+
|
|
22
|
+
local function fail(message) raw_error("E_INVALID: " .. message, 3) end
|
|
23
|
+
local function call(name, ...)
|
|
24
|
+
local fn = host[name]
|
|
25
|
+
if not fn then raw_error("E_UNAVAILABLE: this tmux-ide has no " .. name, 3) end
|
|
26
|
+
return fn(...)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
----------------------------------------------------------------------- exec
|
|
30
|
+
|
|
31
|
+
ide.exec = function(spec)
|
|
32
|
+
if raw_type(spec) ~= "table" then fail("ide.exec expects a table like { cmd = 'git', args = {...} }") end
|
|
33
|
+
local request = {}
|
|
34
|
+
for _, key in raw_ipairs({ "cmd", "cwd", "stdin", "timeout_ms", "context", "shell" }) do
|
|
35
|
+
request[key] = spec[key]
|
|
36
|
+
end
|
|
37
|
+
if spec.args ~= nil then
|
|
38
|
+
if raw_type(spec.args) ~= "table" then fail("ide.exec args must be a list of strings") end
|
|
39
|
+
local args = {}
|
|
40
|
+
for i, value in raw_ipairs(spec.args) do args[i] = raw_tostring(value) end
|
|
41
|
+
request.args = args
|
|
42
|
+
end
|
|
43
|
+
if spec.env ~= nil then
|
|
44
|
+
if raw_type(spec.env) ~= "table" then fail("ide.exec env must be a table of strings") end
|
|
45
|
+
local env = {}
|
|
46
|
+
for key, value in raw_pairs(spec.env) do env[raw_tostring(key)] = raw_tostring(value) end
|
|
47
|
+
request.env = env
|
|
48
|
+
end
|
|
49
|
+
return call("_exec", request)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
------------------------------------------------------------------ worktree
|
|
53
|
+
|
|
54
|
+
local function worktree_call(op)
|
|
55
|
+
return function(spec)
|
|
56
|
+
if raw_type(spec) ~= "table" then
|
|
57
|
+
fail("ide.worktree." .. op .. " expects a table like { session = ctx.session, branch = 'fix-login' }")
|
|
58
|
+
end
|
|
59
|
+
return call("_worktree", op, { session = spec.session, branch = spec.branch, from = spec.from })
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
ide.worktree = {
|
|
64
|
+
list = worktree_call("list"),
|
|
65
|
+
create = worktree_call("create"),
|
|
66
|
+
open = worktree_call("open"),
|
|
67
|
+
remove = worktree_call("remove"),
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
-------------------------------------------------------------------- notify
|
|
71
|
+
|
|
72
|
+
ide.notify = function(text, opts)
|
|
73
|
+
local level = raw_type(opts) == "table" and opts.level or nil
|
|
74
|
+
return call("_notify", raw_tostring(text), level)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
---------------------------------------------------------------------- json
|
|
78
|
+
|
|
79
|
+
ide.json = {
|
|
80
|
+
encode = function(value) return json_encode(value) end,
|
|
81
|
+
decode = function(text)
|
|
82
|
+
if raw_type(text) ~= "string" then fail("ide.json.decode expects a string") end
|
|
83
|
+
return json_decode_raw(text)
|
|
84
|
+
end,
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
--------------------------------------------------------------------- store
|
|
88
|
+
|
|
89
|
+
ide.store = {
|
|
90
|
+
get = function(key) return call("_store_get", key) end,
|
|
91
|
+
set = function(key, value) return call("_store_set", key, value) end,
|
|
92
|
+
delete = function(key) return call("_store_set", key, nil) end,
|
|
93
|
+
keys = function() return call("_store_keys") end,
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
-------------------------------------------------------------------- timers
|
|
97
|
+
|
|
98
|
+
local timers = {}
|
|
99
|
+
local timer_count = 0
|
|
100
|
+
local next_timer = 0
|
|
101
|
+
|
|
102
|
+
local function cancel(id)
|
|
103
|
+
if timers[id] == nil then return false end
|
|
104
|
+
timers[id] = nil
|
|
105
|
+
timer_count = timer_count - 1
|
|
106
|
+
timer_cancel(id)
|
|
107
|
+
return true
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
local function start(ms, fn, repeating)
|
|
111
|
+
if raw_type(fn) ~= "function" then fail("timer callback must be a function") end
|
|
112
|
+
if raw_type(ms) ~= "number" or ms ~= ms or ms < 0 or ms > 86400000 then
|
|
113
|
+
fail("timer delay must be a number of milliseconds")
|
|
114
|
+
end
|
|
115
|
+
if repeating and ms < MIN_REPEAT then fail("ide.timer.every needs at least " .. MIN_REPEAT .. " ms") end
|
|
116
|
+
if timer_count >= MAX_TIMERS then fail("a plugin may have at most " .. MAX_TIMERS .. " timers") end
|
|
117
|
+
next_timer = next_timer + 1
|
|
118
|
+
local id = next_timer
|
|
119
|
+
timers[id] = { fn = fn, repeating = repeating }
|
|
120
|
+
timer_count = timer_count + 1
|
|
121
|
+
timer_start(id, math.floor(ms), repeating)
|
|
122
|
+
return { id = id, cancel = function() return cancel(id) end }
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
ide.timer = {
|
|
126
|
+
after = function(ms, fn) return start(ms, fn, false) end,
|
|
127
|
+
every = function(ms, fn) return start(ms, fn, true) end,
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
internal.run_timer = function(id)
|
|
131
|
+
runners[co_running()] = true
|
|
132
|
+
arm()
|
|
133
|
+
local timer = timers[id]
|
|
134
|
+
if not timer then return "[]" end
|
|
135
|
+
if not timer.repeating then
|
|
136
|
+
timers[id] = nil
|
|
137
|
+
timer_count = timer_count - 1
|
|
138
|
+
end
|
|
139
|
+
timer.fn()
|
|
140
|
+
return "[]"
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
-------------------------------------------------- panes, windows, sessions
|
|
144
|
+
|
|
145
|
+
local Pane = {}
|
|
146
|
+
Pane.__index = Pane
|
|
147
|
+
|
|
148
|
+
local function pane_object(raw)
|
|
149
|
+
local endpoint = raw.endpoint
|
|
150
|
+
return raw_setmetatable({
|
|
151
|
+
id = endpoint.semanticPaneId,
|
|
152
|
+
workspace = endpoint.workspaceName,
|
|
153
|
+
session = raw.session,
|
|
154
|
+
title = raw.title,
|
|
155
|
+
endpoint = endpoint,
|
|
156
|
+
}, Pane)
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
local function action(name, input) return call("_action", name, input) end
|
|
160
|
+
|
|
161
|
+
function Pane:read() return call("_pane_read", self.endpoint) end
|
|
162
|
+
function Pane:send(text, opts)
|
|
163
|
+
if raw_type(text) ~= "string" or #text == 0 then fail("pane:send expects text") end
|
|
164
|
+
local enter = not (raw_type(opts) == "table" and opts.enter == false)
|
|
165
|
+
return call("_pane_send", self.endpoint, text, enter)
|
|
166
|
+
end
|
|
167
|
+
function Pane:split(opts)
|
|
168
|
+
opts = opts or {}
|
|
169
|
+
local direction = opts.dir or "right"
|
|
170
|
+
if direction ~= "right" and direction ~= "down" then fail("pane:split dir must be 'right' or 'down'") end
|
|
171
|
+
return action("workspace.window.split", {
|
|
172
|
+
workspaceName = self.workspace, semanticPaneId = self.id,
|
|
173
|
+
direction = direction, displayTitle = opts.title,
|
|
174
|
+
})
|
|
175
|
+
end
|
|
176
|
+
function Pane:zoom(on)
|
|
177
|
+
local desired = on == nil and "toggle" or (on and "zoomed" or "unzoomed")
|
|
178
|
+
return action("workspace.pane.zoom.toggle", {
|
|
179
|
+
workspaceName = self.workspace, semanticPaneId = self.id, desired = desired,
|
|
180
|
+
})
|
|
181
|
+
end
|
|
182
|
+
function Pane:focus()
|
|
183
|
+
return action("workspace.pane.select", { workspaceName = self.workspace, semanticPaneId = self.id })
|
|
184
|
+
end
|
|
185
|
+
function Pane:rename(name)
|
|
186
|
+
return action("workspace.rename", {
|
|
187
|
+
workspaceName = self.workspace, scope = "pane", semanticPaneId = self.id, name = name,
|
|
188
|
+
})
|
|
189
|
+
end
|
|
190
|
+
function Pane:kill()
|
|
191
|
+
return action("workspace.pane.kill", { workspaceName = self.workspace, semanticPaneId = self.id })
|
|
192
|
+
end
|
|
193
|
+
function Pane:rename_window(name)
|
|
194
|
+
return action("workspace.rename", {
|
|
195
|
+
workspaceName = self.workspace, scope = "window",
|
|
196
|
+
target = { by = "pane", semanticPaneId = self.id }, name = name,
|
|
197
|
+
})
|
|
198
|
+
end
|
|
199
|
+
function Pane:kill_window()
|
|
200
|
+
return action("workspace.window.kill", {
|
|
201
|
+
workspaceName = self.workspace, target = { by = "pane", semanticPaneId = self.id },
|
|
202
|
+
})
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
ide.panes = function(filter)
|
|
206
|
+
local out = {}
|
|
207
|
+
for _, raw in raw_ipairs(call("_panes")) do
|
|
208
|
+
local pane = pane_object(raw)
|
|
209
|
+
if raw_type(filter) ~= "table"
|
|
210
|
+
or ((filter.session == nil or filter.session == pane.session)
|
|
211
|
+
and (filter.workspace == nil or filter.workspace == pane.workspace)) then
|
|
212
|
+
out[#out + 1] = pane
|
|
213
|
+
end
|
|
214
|
+
end
|
|
215
|
+
return out
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
ide.session = function(workspace)
|
|
219
|
+
if raw_type(workspace) ~= "string" or #workspace == 0 then fail("ide.session expects a workspace name") end
|
|
220
|
+
return {
|
|
221
|
+
workspace = workspace,
|
|
222
|
+
rename = function(_, name)
|
|
223
|
+
return action("workspace.rename", { workspaceName = workspace, scope = "session", name = name })
|
|
224
|
+
end,
|
|
225
|
+
kill = function() return action("workspace.session.kill", { workspaceName = workspace }) end,
|
|
226
|
+
}
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
for _, feature in raw_ipairs({ "exec", "panes", "timers", "json", "store", "notify" }) do
|
|
230
|
+
internal.features[feature] = true
|
|
231
|
+
end
|
|
232
|
+
`;
|